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
| Endpoint | Action | Purpose |
|---|---|---|
POST /asset | Register an asset. | |
GET /asset, GET /asset/:id | asset:index, asset:show | List and inspect assets. |
POST /asset/:id?preview=true | asset:install | See what installing would change, without changing anything. |
POST /asset/:id | asset:install | Install the asset with the given configs. |
DELETE /asset/:id | asset:delete | Remove an asset. |
POST /asset/export | asset:export | Export 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.zipAssets 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.yamlTerminal
spica asset apply --path ./newsletter --dry-run
spica asset apply --path ./newsletter
spica asset delete --path ./newsletter --type softSee CLI → Assets.