Custom packages

Creating new custom packages

Custom packages can be used to group your own actions, manage default parameters and share entities with other users.

Let's demonstrate how to do this now using the ic fn CLI tool…

  1. Create a package called "custom".

    ic fn package create custom
    ok: created package custom
  2. Get a summary of the package.

    ic fn package get --summary custom
    package /myNamespace/custom
       (parameters: none defined)

    Notice that the package is empty.

  3. Create a file called identity.js that contains the following action code. This action returns all input parameters.

    function main(args) { return args; }
  4. Create an identity action in the custom package.

    ic fn action create custom/identity identity.js
    ok: created action custom/identity

    Creating an action in a package requires that you prefix the action name with a package name.

  5. Get a summary of the package again.

    ic fn package get --summary custom
    package /myNamespace/custom
       (parameters: none defined)
    action /myNamespace/custom/identity
       (parameters: none defined)

    You can see the custom/identity action in your namespace now.

  6. Invoke the action in the package.

    ic fn action invoke --result custom/identity
    {}

Setting default package parameters

You can set default parameters for all the entities in a package. You do this by setting package-level parameters that are inherited by all actions in the package.

To see how this works, try the following example:

  1. Update the custom package with two parameters: city and country.

    ic fn package update custom --param city Austin --param country USA
    ok: updated package custom
  2. Display the parameters in the package.

   ic fn package get custom
   ok: got package custom
   ...
   "parameters": [
      {
          "key": "city",
          "value": "Austin"
      },
      {
          "key": "country",
          "value": "USA"
      }
   ]
   ...
  1. Observe how the identity action in the package inherits these parameters from the package.

    ic fn action get custom/identity
    ok: got action custom/identity
    ...
    "parameters": [
       {
           "key": "city",
           "value": "Austin"
       },
       {
           "key": "country",
           "value": "USA"
       }
    ]
    ...
  2. Invoke the identity action without any parameters to verify that the action indeed inherits the parameters.

    ic fn action invoke --result custom/identity
    {
       "city": "Austin",
       "country": "USA"
    }
  3. Invoke the identity action with some parameters.

    ic fn action invoke --result custom/identity --param city Dallas --param state Texas
    {
       "city": "Dallas",
       "country": "USA",
       "state": "Texas"
    }

Last updated

Was this helpful?