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…
Create a package called "custom".
ic fn package create custom
ok: created package custom
Get a summary of the package.
ic fn package get --summary custom
package /myNamespace/custom (parameters: none defined)
Notice that the package is empty.
Create a file called
identity.js
that contains the following action code. This action returns all input parameters.function main(args) { return args; }
Create an
identity
action in thecustom
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.
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.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:
Update the
custom
package with two parameters:city
andcountry
.ic fn package update custom --param city Austin --param country USA
ok: updated package custom
Display the parameters in the package.
ic fn package get custom
ok: got package custom
...
"parameters": [
{
"key": "city",
"value": "Austin"
},
{
"key": "country",
"value": "USA"
}
]
...
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" } ] ...
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" }
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?