Functions:Commands - bettyblocks/cli GitHub Wiki

Getting started

The bb functions namespace supports several commands.

  • init [identifier] initialize functions project
  • new [function-name] Initialize a new function
  • validate validate functions of current working directory
  • publish publish functions of current working directory
  • bump bump the version of existing functions

bb functions init

New projects can be initialised with: bb functions init <your-app-identifier>

Given an application cli-wiki.bettyblocks.com, the identifier will be cli-wiki.

Example:

$ bb functions init cli-wiki

Initialized app functions project in /Users/bettyblocks/application-functions/cli-wiki.
You can use "bb functions" to publish it:

    cd cli-wiki
    bb functions publish

Each new project comes with one example function that can be found in <path/to/project>/functions/say-hello/.

If you want to create a wasm functions project you have to add the --type wasm flag to the init command: bb functions init <your-app-identifier> --type wasm

This project will come with an example wasm function in Rust.


bb functions publish

Once you've got your function implemented and the function.json finished, you're ready to publish your function. All your functions will automatically be validated on publish.

Publishing can be done with: bb functions publish

Note: The first time you publish your functions for your application, you will be asked for your application's ID. See this post on how to find your application-id

Example:

$ cd /Users/bettyblocks/application-functions/cli-wiki
$ bb functions publish

Validating functions in /Users/bettyblocks/application-functions/cli-wiki/functions
✔ Validate: authenticateUser
✔ Validate: http
Publishing to https://cli-wiki.bettyblocks.com ...
✔ Please supply the ID for your application (cli-wiki) … 1234567890abcdef1234567890abcdef
✔ Fill in your e-mail address … [email protected]
✔ Fill in your password … ********
✔ Fill in your 2FA code … 000000
✔ Create sayGoodbye.
✔ Create sayHello.
Done.

Your function is now ready to be used in the IDE!

Publish "Say Hello" function


bb functions new

You can create a new function from the root of your project with: bb functions new <function name>

Example:

$ cd /Users/bettyblocks/application-functions/cli-wiki
$ bb functions new say-goodbye

functions/say-goodbye created

This will create two new files

  • cli-wiki/functions/say-goodbye/function.json
  • cli-wiki/functions/say-goodbye/index.js

The function.json describes the function following the JSON Schema. While the index.js implements the actual function. Checkout these functions that are predefined for each application.

When running the bb functions new command in a wasm functions project, it will create the same example function but now in Rust.


bb functions validate

You can validate the function.json of your function with: bb functions validate <function-name>

Example:

$ cd /Users/bettyblocks/application-functions/cli-wiki
$ bb functions validate say-goodbye

✔ Validate: sayGoodbye

It is also possible to validate all the functions in your project by omitting the function name. Example:

$ cd /Users/bettyblocks/application-functions/cli-wiki
$ bb functions validate

✔ Validate: sayGoodbye
✔ Validate: sayHello

When running this command in a wasm functions project, it will validate the function.json and also check if the compiled .wasm file is present on each function.

Debugging invalid function.json

A possible validation message of invalid function.json files may be:

bb functions validate say-goodbye

✖ Validate: sayGoodbye
	instance.options[0] requires property "label",instance requires property "category"

In this instance, the function.json appears to be missing a "category" key in the root of the json. It also appears to have a list of options of which the first instance ([0]) seems to be missing a "label" key.


bb functions bump

You can bump versions of existing functions from the root of your project with: bb functions bump

Example:

$ bb functions bump

? Which function do you want to bump?
    Authenticate User
    Condition
❯   Create Record
    Delete Record
    HTTP(S)
    Log Message
    Loop
    Update Record
✔ Which function do you want to bump? › Create Record

? To which version do you want to bump your function? › 1.1 / 2.0
✔ Version bumped to create/2.0