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.

  2. Display the parameters in the package.

  1. Observe how the identity action in the package inherits these parameters from the package.

  2. Invoke the identity action without any parameters to verify that the action indeed inherits the parameters.

  3. Invoke the identity action with some parameters.

Last updated

Was this helpful?