Assets

Package buckets, functions, dashboards and other resources into installable assets, with configurable values, previews and exports.

An asset is a package of resources, such as buckets, functions, dashboards, preferences and API keys, that can be installed into a Spica instance as a unit. Assets are useful for reusable features ("contact form", "newsletter"), starter kits and moving a feature between instances.

Anatomy

JSON
{
  "name": "Newsletter",
  "description": "Subscribers bucket and a double opt-in function",
  "icon": "mail",
  "url": "https://example.com/assets/newsletter.zip",
  "resources": [
    {"module": "bucket", "contents": {"schema": {"title": "Subscribers", "description": "Newsletter subscribers", "properties": {}}}},
    {"module": "function", "contents": {"schema": {}, "index": "export default function () {}", "package": {}}}
  ],
  "configs": [
    {
      "title": "Confirmation path",
      "module": "function",
      "resource_id": "<functionId>",
      "submodule": "schema",
      "property": "triggers.confirm.options.path",
      "type": "string",
      "value": "/newsletter/confirm"
    }
  ]
}

configs are the values the installer can change before installing. Each config points at a property of a resource, using dot notation.

Lifecycle

EndpointActionPurpose
POST /assetRegister an asset.
GET /asset, GET /asset/:idasset:index, asset:showList and inspect assets.
POST /asset/:id?preview=trueasset:installSee what installing would change, without changing anything.
POST /asset/:idasset:installInstall the asset with the given configs.
DELETE /asset/:idasset:deleteRemove an asset.
POST /asset/exportasset:exportExport existing resources as a downloadable asset.

Export resources as an asset

Terminal
curl -X POST https://api.example.com/api/asset/export \
  -H "Authorization: IDENTITY <token>" -H "Content-Type: application/json" \
  -d '{
    "name": "Blog",
    "description": "Posts and authors",
    "resources": {"bucket": ["<postsId>", "<authorsId>"], "function": ["<functionId>"]},
    "configs": []
  }' -o blog-asset.zip

Assets with the CLI

A folder with an asset.yaml and one sub-folder per resource can be uploaded with the CLI:

Text
newsletter/
├── asset.yaml
├── bucket/<id>/schema.yaml
├── function/<id>/schema.yaml
├── function/<id>/index.ts
├── function/<id>/package.json
└── dashboard/<id>/schema.yaml
Terminal
spica asset apply --path ./newsletter --dry-run
spica asset apply --path ./newsletter
spica asset delete --path ./newsletter --type soft

See CLI → Assets.