@diagonal-hq/cli 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -1
- package/dist/cli.mjs +825 -205
- package/dist/fields.generated.d.ts +7 -1
- package/dist/index.d.ts +79 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@ This package is the authoring SDK for file-based workspaces. A workspace reposit
|
|
|
6
6
|
- Types for the helpers, `WorkflowConfig`, and the `Sdk` and `React` globals.
|
|
7
7
|
- Editor types for the workflow script SDK: `@diagonal/workflow`, `@diagonal/workflow/testing`, and `@diagonal/workflow/workspace`.
|
|
8
8
|
- The `diagonal check` command. It runs the same build and checks that a platform deploy runs, including the workflow tests. It also writes `generated/resources.ts` and the missing definition uids.
|
|
9
|
+
- The `diagonal assets upload` and `diagonal assets list` commands. They upload Application Assets, update `assets.ts`, and list immutable references.
|
|
9
10
|
- The `diagonal workflows` and `diagonal run` commands. They list the deployed workflows and run a manual workflow by its file path.
|
|
10
11
|
|
|
11
12
|
## Check a workspace
|
|
@@ -26,6 +27,10 @@ diagonal check [dir] [--json]
|
|
|
26
27
|
|
|
27
28
|
Each diagnostic prints as `path:line:column severity message`. The command exits with 1 when an error exists, with 2 for a usage error, and with 0 otherwise.
|
|
28
29
|
|
|
30
|
+
## Workspace API credentials
|
|
31
|
+
|
|
32
|
+
The API commands read `DIAGONAL_URL` and `DIAGONAL_API_KEY`. Workflow commands require `manage_workflows`. Asset commands require `manage_workspace_settings`. A System Administrator has both permissions. Keep API keys out of the repository.
|
|
33
|
+
|
|
29
34
|
## Run a deployed workflow
|
|
30
35
|
|
|
31
36
|
`diagonal workflows` and `diagonal run` call the runtime API of a deployed workspace. Set two environment variables first:
|
|
@@ -325,11 +330,80 @@ export default defineResource({
|
|
|
325
330
|
- Provisioning can create a field, for example `accounting_entity`. The files cannot declare a field with the same key later. The deploy refuses it until you delete the field in the resource builder or use another key.
|
|
326
331
|
- A capability change in the resource builder is drift. The next deploy reports it and restores the capability from the files.
|
|
327
332
|
|
|
333
|
+
## Policies
|
|
334
|
+
|
|
335
|
+
A policy grants access to the records of its resource. Each policy option maps to one option of a stored policy:
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
import { Resources } from '@app/generated/resources';
|
|
339
|
+
|
|
340
|
+
export default defineResource({
|
|
341
|
+
name: 'Posts',
|
|
342
|
+
singularName: 'Post',
|
|
343
|
+
fields: {
|
|
344
|
+
title: field.text({ required: true }),
|
|
345
|
+
body: field.text(),
|
|
346
|
+
author: field.relation({ resource: Resources.Members.slug, type: 'belongs_to' })
|
|
347
|
+
},
|
|
348
|
+
policies: [
|
|
349
|
+
{
|
|
350
|
+
name: 'Visitors read titles',
|
|
351
|
+
scope: ['index', 'show'],
|
|
352
|
+
access: 'public',
|
|
353
|
+
fields: ['id', 'title']
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
name: 'Authors edit their posts',
|
|
357
|
+
scope: ['update', 'destroy'],
|
|
358
|
+
resource: Resources.Members.slug,
|
|
359
|
+
filter: {
|
|
360
|
+
operator: 'and',
|
|
361
|
+
conditions: [
|
|
362
|
+
{
|
|
363
|
+
field: 'author.id',
|
|
364
|
+
operator: '=',
|
|
365
|
+
value: { $type: 'user.current', $value: { key: 'id' } }
|
|
366
|
+
}
|
|
367
|
+
]
|
|
368
|
+
},
|
|
369
|
+
fields: ['title', 'body']
|
|
370
|
+
}
|
|
371
|
+
]
|
|
372
|
+
});
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
- `scope` is `'all'` or a list of operations: `index`, `show`, `count`, `aggregate`, `store`, `storeMany`, `update`, `destroy`, `restore`, and `validate`.
|
|
376
|
+
- `access` is `'public'` or `'protected'`. The default is `'protected'`. A public policy grants access to every visitor, and it cannot set `resource` or `authorizer`.
|
|
377
|
+
- `resource` is the resource that members sign in as, as `Resources.<Name>.slug`. The resource must have the `authenticatable` capability. A protected policy without `resource` grants access only to system administrators.
|
|
378
|
+
- `authorizer` is a filter tree that the member's own record must match, for example `{ operator: 'and', conditions: [{ field: 'permission_slugs', operator: 'in', value: ['moderate'] }] }`.
|
|
379
|
+
- `filter` is a filter tree that limits the records that the policy covers. Compare a relation to the signed-in member with `<relation>.id` and the resolver `{ $type: 'user.current', $value: { key: 'id' } }`.
|
|
380
|
+
- `fields` is an allow-list of field keys. A key can be a relation path, such as `author.name`. An item can also be `{ key, condition }`, where `condition` is a resolver that returns true when the field shows. A field that the list leaves out is hidden from reads and refused on writes. Without `fields`, the policy covers every field.
|
|
381
|
+
- `enabled: false` keeps the policy but grants nothing. The default is `true`.
|
|
382
|
+
|
|
383
|
+
A filter tree has the shape of a record search filter: `{ operator: 'and' | 'or' | 'nor', conditions }`. Each condition is `{ field, operator, value, case_insensitive }` or a nested group. The policy id comes from the resource and the policy name, so each policy of a resource has a different name.
|
|
384
|
+
|
|
385
|
+
The build checks the shape of each option, the filter operators, and the resource that members sign in as. The deploy checks each policy with the rules of the policy API against the deployed schema: the filter paths, the authorizer paths, the field keys, and the field conditions. A policy that fails rejects the deploy, and the previous deployment keeps serving. A field that capability provisioning creates, such as the roles relation of an Authenticatable resource, exists only after the first deploy of that capability.
|
|
386
|
+
|
|
328
387
|
A workflow script reads the capabilities of each resource from `@diagonal/workflow/workspace`. An input that needs a capability, such as the `resource` of `notification.setConsent`, accepts only a resource that declares it.
|
|
329
388
|
|
|
330
389
|
## Application asset references
|
|
331
390
|
|
|
332
|
-
|
|
391
|
+
Run the upload command in the workspace root, the folder with `diagonal.config.ts`:
|
|
392
|
+
|
|
393
|
+
```text
|
|
394
|
+
diagonal assets upload <file> [--key <key>] [--no-write] [--json]
|
|
395
|
+
diagonal assets list [--search <text>] [--versions] [--json]
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
`diagonal assets upload hero.png --key hero` creates or updates the `hero` entry in `assets.ts`. An existing key adds a version to the asset that owns its current reference. A new key creates an asset whose display name defaults to the file name. Identical bytes for an existing key reuse its latest version. The command preserves source comments and formatting.
|
|
399
|
+
|
|
400
|
+
`--key` is required unless `--no-write` is given. `--no-write` writes nothing and prints only the version reference. It can run outside a workspace root. With an existing key in a valid `assets.ts`, it still adds a version to that key's asset. `--json` prints `{ key, written, asset, version }`.
|
|
401
|
+
|
|
402
|
+
`diagonal assets list` reads every index page and prints each asset with its latest version. `--search` filters by display name or latest filename. `--versions` also fetches each asset's newest 100 versions and reports when older versions are omitted. `--json` prints `{ data: [...] }`, with `versions` added when requested.
|
|
403
|
+
|
|
404
|
+
Both commands exit with 0 on success, 1 for a request failure or a refused `assets.ts`, and 2 for a usage error or missing environment variables. Manifest errors use the same `assets.ts:line:column error message` format as `diagonal check`. Uploads require a file-based workspace and `manage_workspace_settings`. The command checks access before it sends file bytes.
|
|
405
|
+
|
|
406
|
+
Other API clients can upload in two steps. `POST /api/files/uploads` with a multipart `file` returns `{key}`. `POST /api/application-assets` with `{"upload_key": "<key>"}` returns the asset and its immutable version `reference`. To replace an existing key, resolve its reference with `GET /api/application-asset-versions/{reference}`, then use `POST /api/application-assets/{asset}/versions`. The CLI writes the optional root `assets.ts` in this form:
|
|
333
407
|
|
|
334
408
|
```ts
|
|
335
409
|
import { defineAssets, asset } from '@diagonal-hq/cli';
|