@sanity/runtime-cli 14.3.0 → 14.4.0
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 +27 -27
- package/dist/actions/blueprints/blueprint.js +2 -2
- package/dist/actions/blueprints/resources.js +2 -1
- package/dist/actions/functions/logs.d.ts +0 -1
- package/dist/actions/functions/logs.js +0 -1
- package/dist/constants.d.ts +18 -1
- package/dist/constants.js +26 -9
- package/dist/cores/functions/add.js +13 -13
- package/dist/cores/functions/logs.js +3 -5
- package/dist/cores/functions/test.js +1 -1
- package/dist/server/app.js +6 -4
- package/dist/server/static/components/api-base.js +1 -1
- package/dist/server/static/components/filters.js +1 -1
- package/dist/server/static/components/function-list.js +2 -2
- package/dist/server/static/components/payload-panel.js +1 -1
- package/dist/server/static/components/run-panel.js +2 -2
- package/dist/utils/display/blueprints-formatting.js +11 -4
- package/dist/utils/find-function.js +4 -3
- package/dist/utils/types.d.ts +6 -5
- package/dist/utils/types.js +7 -4
- package/dist/utils/validate/index.js +7 -4
- package/dist/utils/validate/resource.js +3 -2
- package/oclif.manifest.json +5 -5
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ $ npm install -g @sanity/runtime-cli
|
|
|
20
20
|
$ sanity-run COMMAND
|
|
21
21
|
running command...
|
|
22
22
|
$ sanity-run (--version)
|
|
23
|
-
@sanity/runtime-cli/14.
|
|
23
|
+
@sanity/runtime-cli/14.4.0 linux-x64 node-v24.14.0
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -55,9 +55,9 @@ Add a function resource to a Blueprint
|
|
|
55
55
|
```
|
|
56
56
|
USAGE
|
|
57
57
|
$ sanity-run blueprints add TYPE [--example <value> | -n <value> | --fn-type
|
|
58
|
-
document-publish|document-create|document-
|
|
59
|
-
te|media-library-asset-delete|
|
|
60
|
-
skip|npm|pnpm|yarn] [-i | ]
|
|
58
|
+
document-publish|document-create|document-update|document-delete|media-library-asset-create|media-library-asset-upda
|
|
59
|
+
te|media-library-asset-delete|scheduled-function... | --language ts|js | --javascript | --fn-helpers |
|
|
60
|
+
--fn-installer skip|npm|pnpm|yarn] [-i | ]
|
|
61
61
|
|
|
62
62
|
ARGUMENTS
|
|
63
63
|
TYPE (function) Type of resource to add (only "function" is supported)
|
|
@@ -72,8 +72,8 @@ FLAGS
|
|
|
72
72
|
<options: skip|npm|pnpm|yarn>
|
|
73
73
|
--fn-type=<option>... Document change event(s) that should trigger the function; you can specify multiple
|
|
74
74
|
events by specifying this flag multiple times
|
|
75
|
-
<options: document-publish|document-create|document-
|
|
76
|
-
asset-create|media-library-asset-update|media-library-asset-delete|
|
|
75
|
+
<options: document-publish|document-create|document-update|document-delete|media-library-
|
|
76
|
+
asset-create|media-library-asset-update|media-library-asset-delete|scheduled-function>
|
|
77
77
|
--javascript Use JavaScript instead of TypeScript
|
|
78
78
|
--language=<option> [default: ts] Language of the new function
|
|
79
79
|
<options: ts|js>
|
|
@@ -98,7 +98,7 @@ EXAMPLES
|
|
|
98
98
|
$ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
101
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/add.ts)_
|
|
102
102
|
|
|
103
103
|
## `sanity-run blueprints config`
|
|
104
104
|
|
|
@@ -133,7 +133,7 @@ EXAMPLES
|
|
|
133
133
|
$ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
136
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/config.ts)_
|
|
137
137
|
|
|
138
138
|
## `sanity-run blueprints deploy`
|
|
139
139
|
|
|
@@ -166,7 +166,7 @@ EXAMPLES
|
|
|
166
166
|
$ sanity-run blueprints deploy --no-wait
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
169
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/deploy.ts)_
|
|
170
170
|
|
|
171
171
|
## `sanity-run blueprints destroy`
|
|
172
172
|
|
|
@@ -198,7 +198,7 @@ EXAMPLES
|
|
|
198
198
|
$ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
201
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/destroy.ts)_
|
|
202
202
|
|
|
203
203
|
## `sanity-run blueprints doctor`
|
|
204
204
|
|
|
@@ -224,7 +224,7 @@ DESCRIPTION
|
|
|
224
224
|
issues.
|
|
225
225
|
```
|
|
226
226
|
|
|
227
|
-
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
227
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/doctor.ts)_
|
|
228
228
|
|
|
229
229
|
## `sanity-run blueprints info`
|
|
230
230
|
|
|
@@ -254,7 +254,7 @@ EXAMPLES
|
|
|
254
254
|
$ sanity-run blueprints info --stack <name-or-id>
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
257
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/info.ts)_
|
|
258
258
|
|
|
259
259
|
## `sanity-run blueprints init [DIR]`
|
|
260
260
|
|
|
@@ -304,7 +304,7 @@ EXAMPLES
|
|
|
304
304
|
$ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
307
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/init.ts)_
|
|
308
308
|
|
|
309
309
|
## `sanity-run blueprints logs`
|
|
310
310
|
|
|
@@ -333,7 +333,7 @@ EXAMPLES
|
|
|
333
333
|
$ sanity-run blueprints logs --watch
|
|
334
334
|
```
|
|
335
335
|
|
|
336
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
336
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/logs.ts)_
|
|
337
337
|
|
|
338
338
|
## `sanity-run blueprints plan`
|
|
339
339
|
|
|
@@ -359,7 +359,7 @@ EXAMPLES
|
|
|
359
359
|
$ sanity-run blueprints plan
|
|
360
360
|
```
|
|
361
361
|
|
|
362
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
362
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/plan.ts)_
|
|
363
363
|
|
|
364
364
|
## `sanity-run blueprints stacks`
|
|
365
365
|
|
|
@@ -388,7 +388,7 @@ EXAMPLES
|
|
|
388
388
|
$ sanity-run blueprints stacks --organization-id <organizationId>
|
|
389
389
|
```
|
|
390
390
|
|
|
391
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
391
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/blueprints/stacks.ts)_
|
|
392
392
|
|
|
393
393
|
## `sanity-run functions add`
|
|
394
394
|
|
|
@@ -397,8 +397,8 @@ Add a Function to your Blueprint
|
|
|
397
397
|
```
|
|
398
398
|
USAGE
|
|
399
399
|
$ sanity-run functions add [--example <value> | -n <value> | | --language ts|js | --javascript | | ] [--type
|
|
400
|
-
document-publish|document-create|document-
|
|
401
|
-
te|media-library-asset-delete|
|
|
400
|
+
document-publish|document-create|document-update|document-delete|media-library-asset-create|media-library-asset-upda
|
|
401
|
+
te|media-library-asset-delete|scheduled-function... ] [--helpers] [--installer skip|npm|pnpm|yarn] [-i | ]
|
|
402
402
|
|
|
403
403
|
FLAGS
|
|
404
404
|
-i, --install Shortcut for --fn-installer npm
|
|
@@ -412,8 +412,8 @@ FLAGS
|
|
|
412
412
|
<options: ts|js>
|
|
413
413
|
--type=<option>... Document change event(s) that should trigger the function; you can specify multiple events
|
|
414
414
|
by specifying this flag multiple times
|
|
415
|
-
<options: document-publish|document-create|document-
|
|
416
|
-
et-create|media-library-asset-update|media-library-asset-delete|
|
|
415
|
+
<options: document-publish|document-create|document-update|document-delete|media-library-ass
|
|
416
|
+
et-create|media-library-asset-update|media-library-asset-delete|scheduled-function>
|
|
417
417
|
|
|
418
418
|
DESCRIPTION
|
|
419
419
|
Add a Function to your Blueprint
|
|
@@ -437,7 +437,7 @@ EXAMPLES
|
|
|
437
437
|
$ sanity-run functions add --name my-function --type document-create --type document-update --lang js
|
|
438
438
|
```
|
|
439
439
|
|
|
440
|
-
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
440
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/functions/add.ts)_
|
|
441
441
|
|
|
442
442
|
## `sanity-run functions dev`
|
|
443
443
|
|
|
@@ -471,7 +471,7 @@ EXAMPLES
|
|
|
471
471
|
$ sanity-run functions dev --timeout 60
|
|
472
472
|
```
|
|
473
473
|
|
|
474
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
474
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/functions/dev.ts)_
|
|
475
475
|
|
|
476
476
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
477
477
|
|
|
@@ -498,7 +498,7 @@ EXAMPLES
|
|
|
498
498
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
499
499
|
```
|
|
500
500
|
|
|
501
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
501
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/functions/env/add.ts)_
|
|
502
502
|
|
|
503
503
|
## `sanity-run functions env list NAME`
|
|
504
504
|
|
|
@@ -522,7 +522,7 @@ EXAMPLES
|
|
|
522
522
|
$ sanity-run functions env list MyFunction
|
|
523
523
|
```
|
|
524
524
|
|
|
525
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
525
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/functions/env/list.ts)_
|
|
526
526
|
|
|
527
527
|
## `sanity-run functions env remove NAME KEY`
|
|
528
528
|
|
|
@@ -548,7 +548,7 @@ EXAMPLES
|
|
|
548
548
|
$ sanity-run functions env remove MyFunction API_URL
|
|
549
549
|
```
|
|
550
550
|
|
|
551
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
551
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/functions/env/remove.ts)_
|
|
552
552
|
|
|
553
553
|
## `sanity-run functions logs [NAME]`
|
|
554
554
|
|
|
@@ -588,7 +588,7 @@ EXAMPLES
|
|
|
588
588
|
$ sanity-run functions logs <name> --delete
|
|
589
589
|
```
|
|
590
590
|
|
|
591
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
591
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/functions/logs.ts)_
|
|
592
592
|
|
|
593
593
|
## `sanity-run functions test [NAME]`
|
|
594
594
|
|
|
@@ -642,7 +642,7 @@ EXAMPLES
|
|
|
642
642
|
$ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
|
|
643
643
|
```
|
|
644
644
|
|
|
645
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
645
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.4.0/src/commands/functions/test.ts)_
|
|
646
646
|
|
|
647
647
|
## `sanity-run help [COMMAND]`
|
|
648
648
|
|
|
@@ -5,7 +5,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
5
5
|
import blueprintParserValidator from '@sanity/blueprints-parser';
|
|
6
6
|
import * as find from 'empathic/find';
|
|
7
7
|
import { createJiti } from 'jiti';
|
|
8
|
-
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
8
|
+
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULED, } from '../../constants.js';
|
|
9
9
|
import { isLocalFunctionResource, } from '../../utils/types.js';
|
|
10
10
|
import { validateResources } from '../../utils/validate/index.js';
|
|
11
11
|
import { validateFunctionResource } from '../../utils/validate/resource.js';
|
|
@@ -218,7 +218,7 @@ export async function readLocalBlueprint(logger, validate, blueprintPath) {
|
|
|
218
218
|
invalidReferenceTypes: [
|
|
219
219
|
SANITY_FUNCTION_DOCUMENT,
|
|
220
220
|
SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
221
|
-
|
|
221
|
+
SANITY_FUNCTION_SCHEDULED,
|
|
222
222
|
],
|
|
223
223
|
});
|
|
224
224
|
const parsedBlueprint = parserResult.result === 'valid' ? parserResult.blueprint : undefined;
|
|
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { cwd } from 'node:process';
|
|
5
|
+
import { SANITY_FUNCTION_PREFIX } from '../../constants.js';
|
|
5
6
|
import { styleText } from '../../utils/style-text.js';
|
|
6
7
|
import { writeOrUpdateNodeDependency } from '../node.js';
|
|
7
8
|
import { addResourceToBlueprint } from './blueprint.js';
|
|
@@ -63,7 +64,7 @@ export async function createFunctionResource(options, logger) {
|
|
|
63
64
|
const resourceJson = {
|
|
64
65
|
name,
|
|
65
66
|
src: `functions/${name}`,
|
|
66
|
-
type:
|
|
67
|
+
type: `${SANITY_FUNCTION_PREFIX}${typeName}`,
|
|
67
68
|
event: {
|
|
68
69
|
on: eventsOn,
|
|
69
70
|
},
|
|
@@ -8,7 +8,6 @@ export declare function logs(id: string, options: LoggingOptions, auth: AuthPara
|
|
|
8
8
|
ok: boolean;
|
|
9
9
|
error: any;
|
|
10
10
|
logs: any;
|
|
11
|
-
total: any;
|
|
12
11
|
}>;
|
|
13
12
|
export declare function deleteLogs(id: string, auth: AuthParams, logger: ReturnType<typeof Logger>): Promise<{
|
|
14
13
|
ok: boolean;
|
|
@@ -15,7 +15,6 @@ export async function logs(id, options, auth, logger) {
|
|
|
15
15
|
ok: response.ok,
|
|
16
16
|
error: response.ok ? null : json?.error?.message,
|
|
17
17
|
logs: response.ok ? json.logs : [],
|
|
18
|
-
total: response.ok ? json.total : 0,
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
export async function deleteLogs(id, auth, logger) {
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
export declare const SANITY_ACCESS_ROLE = "sanity.access.role";
|
|
2
2
|
export declare const SANITY_ACCESS_ROBOT = "sanity.access.robot";
|
|
3
|
+
export declare const SANITY_FUNCTION_PREFIX = "sanity.function.";
|
|
3
4
|
export declare const SANITY_FUNCTION_DOCUMENT = "sanity.function.document";
|
|
4
5
|
export declare const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = "sanity.function.media-library.asset";
|
|
5
|
-
export declare const
|
|
6
|
+
export declare const SANITY_FUNCTION_SCHEDULED = "sanity.function.cron";
|
|
7
|
+
export declare const SANITY_PROJECT = "sanity.project";
|
|
6
8
|
export declare const SANITY_PROJECT_CORS = "sanity.project.cors";
|
|
7
9
|
export declare const SANITY_PROJECT_DATASET = "sanity.project.dataset";
|
|
8
10
|
export declare const SANITY_PROJECT_WEBHOOK = "sanity.project.webhook";
|
|
11
|
+
export declare const EVENT_DOCUMENT_PUBLISH = "document-publish";
|
|
12
|
+
export declare const EVENT_DOCUMENT_CREATE = "document-create";
|
|
13
|
+
export declare const EVENT_DOCUMENT_UPDATE = "document-update";
|
|
14
|
+
export declare const EVENT_DOCUMENT_DELETE = "document-delete";
|
|
15
|
+
export declare const EVENT_MEDIA_LIBRARY_ASSET_CREATE = "media-library-asset-create";
|
|
16
|
+
export declare const EVENT_MEDIA_LIBRARY_ASSET_UPDATE = "media-library-asset-update";
|
|
17
|
+
export declare const EVENT_MEDIA_LIBRARY_ASSET_DELETE = "media-library-asset-delete";
|
|
18
|
+
export declare const EVENT_SCHEDULED = "scheduled-function";
|
|
9
19
|
export declare const FUNCTION_TYPES: string[];
|
|
10
20
|
export declare const MAX_ASSET_SIZE = 209715200;
|
|
11
21
|
export declare const CONVERT_BYTES_TO_MB = 1048576;
|
|
22
|
+
export declare const LABEL_DOCUMENT_CREATE = "Document Create";
|
|
23
|
+
export declare const LABEL_DOCUMENT_UPDATE = "Document Update";
|
|
24
|
+
export declare const LABEL_DOCUMENT_DELETE = "Document Delete";
|
|
25
|
+
export declare const LABEL_MEDIA_LIBRARY_ASSET_CREATE = "Media Library Asset Create";
|
|
26
|
+
export declare const LABEL_MEDIA_LIBRARY_ASSET_UPDATE = "Media Library Asset Update";
|
|
27
|
+
export declare const LABEL_MEDIA_LIBRARY_ASSET_DELETE = "Media Library Asset Delete";
|
|
28
|
+
export declare const LABEL_SCHEDULED = "Scheduled";
|
package/dist/constants.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
export const SANITY_ACCESS_ROLE = 'sanity.access.role';
|
|
2
2
|
export const SANITY_ACCESS_ROBOT = 'sanity.access.robot';
|
|
3
|
+
export const SANITY_FUNCTION_PREFIX = 'sanity.function.';
|
|
3
4
|
export const SANITY_FUNCTION_DOCUMENT = 'sanity.function.document';
|
|
4
5
|
export const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = 'sanity.function.media-library.asset';
|
|
5
|
-
export const
|
|
6
|
+
export const SANITY_FUNCTION_SCHEDULED = 'sanity.function.cron';
|
|
7
|
+
export const SANITY_PROJECT = 'sanity.project';
|
|
6
8
|
export const SANITY_PROJECT_CORS = 'sanity.project.cors';
|
|
7
9
|
export const SANITY_PROJECT_DATASET = 'sanity.project.dataset';
|
|
8
10
|
export const SANITY_PROJECT_WEBHOOK = 'sanity.project.webhook';
|
|
11
|
+
export const EVENT_DOCUMENT_PUBLISH = 'document-publish';
|
|
12
|
+
export const EVENT_DOCUMENT_CREATE = 'document-create';
|
|
13
|
+
export const EVENT_DOCUMENT_UPDATE = 'document-update';
|
|
14
|
+
export const EVENT_DOCUMENT_DELETE = 'document-delete';
|
|
15
|
+
export const EVENT_MEDIA_LIBRARY_ASSET_CREATE = 'media-library-asset-create';
|
|
16
|
+
export const EVENT_MEDIA_LIBRARY_ASSET_UPDATE = 'media-library-asset-update';
|
|
17
|
+
export const EVENT_MEDIA_LIBRARY_ASSET_DELETE = 'media-library-asset-delete';
|
|
18
|
+
export const EVENT_SCHEDULED = 'scheduled-function';
|
|
9
19
|
export const FUNCTION_TYPES = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
EVENT_DOCUMENT_PUBLISH,
|
|
21
|
+
EVENT_DOCUMENT_CREATE,
|
|
22
|
+
EVENT_DOCUMENT_UPDATE,
|
|
23
|
+
EVENT_DOCUMENT_DELETE,
|
|
24
|
+
EVENT_MEDIA_LIBRARY_ASSET_CREATE,
|
|
25
|
+
EVENT_MEDIA_LIBRARY_ASSET_UPDATE,
|
|
26
|
+
EVENT_MEDIA_LIBRARY_ASSET_DELETE,
|
|
27
|
+
EVENT_SCHEDULED,
|
|
18
28
|
];
|
|
19
29
|
export const MAX_ASSET_SIZE = 209_715_200; // 200 MB in bytes
|
|
20
30
|
export const CONVERT_BYTES_TO_MB = 1_048_576; // Used to convert bytes to megabytes (1024 * 1024)
|
|
31
|
+
export const LABEL_DOCUMENT_CREATE = 'Document Create';
|
|
32
|
+
export const LABEL_DOCUMENT_UPDATE = 'Document Update';
|
|
33
|
+
export const LABEL_DOCUMENT_DELETE = 'Document Delete';
|
|
34
|
+
export const LABEL_MEDIA_LIBRARY_ASSET_CREATE = 'Media Library Asset Create';
|
|
35
|
+
export const LABEL_MEDIA_LIBRARY_ASSET_UPDATE = 'Media Library Asset Update';
|
|
36
|
+
export const LABEL_MEDIA_LIBRARY_ASSET_DELETE = 'Media Library Asset Delete';
|
|
37
|
+
export const LABEL_SCHEDULED = 'Scheduled';
|
|
@@ -5,7 +5,7 @@ import { checkbox, confirm, input, select } from '@inquirer/prompts';
|
|
|
5
5
|
import { highlight } from 'cardinal';
|
|
6
6
|
import { createFunctionResource } from '../../actions/blueprints/resources.js';
|
|
7
7
|
import { verifyExampleExists, writeExample } from '../../actions/sanity/examples.js';
|
|
8
|
-
import { FUNCTION_TYPES, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
8
|
+
import { EVENT_DOCUMENT_CREATE, EVENT_DOCUMENT_DELETE, EVENT_DOCUMENT_UPDATE, EVENT_MEDIA_LIBRARY_ASSET_CREATE, EVENT_MEDIA_LIBRARY_ASSET_DELETE, EVENT_MEDIA_LIBRARY_ASSET_UPDATE, EVENT_SCHEDULED, FUNCTION_TYPES, LABEL_DOCUMENT_CREATE, LABEL_DOCUMENT_DELETE, LABEL_DOCUMENT_UPDATE, LABEL_MEDIA_LIBRARY_ASSET_CREATE, LABEL_MEDIA_LIBRARY_ASSET_DELETE, LABEL_MEDIA_LIBRARY_ASSET_UPDATE, LABEL_SCHEDULED, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULED, } from '../../constants.js';
|
|
9
9
|
import { check, indent, warn } from '../../utils/display/presenters.js';
|
|
10
10
|
import { styleText } from '../../utils/style-text.js';
|
|
11
11
|
import { validateFunctionName } from '../../utils/validate/resource.js';
|
|
@@ -20,7 +20,7 @@ const generateFunctionBlueprintResourceTemplate = (fnName, eventNames) => {
|
|
|
20
20
|
case 'media':
|
|
21
21
|
definer = `defineMediaLibraryAssetFunction({name: '${fnName}', event: {on: [${eventOns.join(', ')}], resource: {type: 'media-library', id: 'my-media-library-id'}}}), // ← add this line`;
|
|
22
22
|
break;
|
|
23
|
-
case '
|
|
23
|
+
case 'scheduled':
|
|
24
24
|
definer = `defineScheduleFunction({name: '${fnName}', event: {expression: '0 0 * * *'}}), // ← add this line`;
|
|
25
25
|
break;
|
|
26
26
|
}
|
|
@@ -86,8 +86,8 @@ export async function functionAddCore(options) {
|
|
|
86
86
|
case SANITY_FUNCTION_MEDIA_LIBRARY_ASSET:
|
|
87
87
|
type = 'MediaLibraryAsset';
|
|
88
88
|
break;
|
|
89
|
-
case
|
|
90
|
-
type =
|
|
89
|
+
case SANITY_FUNCTION_SCHEDULED:
|
|
90
|
+
type = LABEL_SCHEDULED;
|
|
91
91
|
break;
|
|
92
92
|
default:
|
|
93
93
|
}
|
|
@@ -230,13 +230,13 @@ async function promptForFunctionType() {
|
|
|
230
230
|
const functionTypes = await checkbox({
|
|
231
231
|
message: 'Choose events to trigger your function:',
|
|
232
232
|
choices: [
|
|
233
|
-
{ name:
|
|
234
|
-
{ name:
|
|
235
|
-
{ name:
|
|
236
|
-
{ name:
|
|
237
|
-
{ name:
|
|
238
|
-
{ name:
|
|
239
|
-
{ name:
|
|
233
|
+
{ name: LABEL_DOCUMENT_CREATE, value: EVENT_DOCUMENT_CREATE, checked: true },
|
|
234
|
+
{ name: LABEL_DOCUMENT_UPDATE, value: EVENT_DOCUMENT_UPDATE, checked: true },
|
|
235
|
+
{ name: LABEL_DOCUMENT_DELETE, value: EVENT_DOCUMENT_DELETE },
|
|
236
|
+
{ name: LABEL_MEDIA_LIBRARY_ASSET_CREATE, value: EVENT_MEDIA_LIBRARY_ASSET_CREATE },
|
|
237
|
+
{ name: LABEL_MEDIA_LIBRARY_ASSET_UPDATE, value: EVENT_MEDIA_LIBRARY_ASSET_UPDATE },
|
|
238
|
+
{ name: LABEL_MEDIA_LIBRARY_ASSET_DELETE, value: EVENT_MEDIA_LIBRARY_ASSET_DELETE },
|
|
239
|
+
{ name: LABEL_SCHEDULED, value: EVENT_SCHEDULED },
|
|
240
240
|
],
|
|
241
241
|
validate(choices) {
|
|
242
242
|
if (choices.length === 0) {
|
|
@@ -244,9 +244,9 @@ async function promptForFunctionType() {
|
|
|
244
244
|
}
|
|
245
245
|
const hasMedia = choices.some((c) => String(c.value).startsWith('media-library'));
|
|
246
246
|
const hasDocument = choices.some((c) => String(c.value).startsWith('document'));
|
|
247
|
-
const hasSchedule = choices.some((c) => String(c.value).startsWith('
|
|
247
|
+
const hasSchedule = choices.some((c) => String(c.value).startsWith('scheduled'));
|
|
248
248
|
if ((hasMedia && hasDocument) || (hasMedia && hasSchedule) || (hasDocument && hasSchedule)) {
|
|
249
|
-
return 'You cannot mix Document, Media Library Asset, and
|
|
249
|
+
return 'You cannot mix Document, Media Library Asset, and Scheduled events together in one Function';
|
|
250
250
|
}
|
|
251
251
|
return true;
|
|
252
252
|
},
|
|
@@ -74,7 +74,7 @@ async function streamLogs({ name, externalId, auth, log, }) {
|
|
|
74
74
|
}
|
|
75
75
|
async function getLogs({ name, externalId, auth, limit, json, utc, log, }) {
|
|
76
76
|
const spinner = log.ora(`Finding logs for function "${name}"`).start();
|
|
77
|
-
const { ok, error, logs
|
|
77
|
+
const { ok, error, logs } = await getLogsAction(externalId, { limit }, auth, log);
|
|
78
78
|
if (!ok) {
|
|
79
79
|
spinner.fail(`${styleText('red', 'Failed')} to retrieve logs`);
|
|
80
80
|
return { success: false, error: error || 'Unknown error' };
|
|
@@ -86,10 +86,8 @@ async function getLogs({ name, externalId, auth, limit, json, utc, log, }) {
|
|
|
86
86
|
}
|
|
87
87
|
spinner.succeed(`${formatTitle('Function', name)} Logs`);
|
|
88
88
|
if (!json) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
log(`Here are the last ${styleText('bold', filteredLogs.length.toString())} entries`);
|
|
92
|
-
}
|
|
89
|
+
const logLength = filteredLogs.length;
|
|
90
|
+
log(`Found ${styleText('bold', logLength.toString())} log ${logLength === 1 ? 'entry' : 'entries'} for function ${styleText('yellow', name)}`);
|
|
93
91
|
log('\n');
|
|
94
92
|
for (const { time, level, message } of filteredLogs) {
|
|
95
93
|
log(formatLog(time, level, message, utc));
|
|
@@ -135,7 +135,7 @@ export async function functionTestCore(options) {
|
|
|
135
135
|
after,
|
|
136
136
|
}
|
|
137
137
|
: {
|
|
138
|
-
event: '
|
|
138
|
+
event: 'scheduled',
|
|
139
139
|
};
|
|
140
140
|
const spinner = log.ora('Executing function...').start();
|
|
141
141
|
const { json, logs, error } = await testAction(resource, invokeOptions, contextOptions, {
|
package/dist/server/app.js
CHANGED
|
@@ -329,13 +329,13 @@ function parseInvokeRequest(body) {
|
|
|
329
329
|
}
|
|
330
330
|
const metadataEvent = metadata.event;
|
|
331
331
|
if (typeof metadataEvent !== 'string' ||
|
|
332
|
-
(!isEventType(metadataEvent) && metadataEvent !== '
|
|
333
|
-
throw new Error('Request body is not valid, `metadata.event` field is not one of `create`, `update`, `delete`, or `
|
|
332
|
+
(!isEventType(metadataEvent) && metadataEvent !== 'scheduled')) {
|
|
333
|
+
throw new Error('Request body is not valid, `metadata.event` field is not one of `create`, `update`, `delete`, or `scheduled`');
|
|
334
334
|
}
|
|
335
335
|
let before = null;
|
|
336
336
|
let after = null;
|
|
337
337
|
// Only GROQ-based events (create, update, delete) have before and after fields
|
|
338
|
-
if (metadataEvent !== '
|
|
338
|
+
if (metadataEvent !== 'scheduled') {
|
|
339
339
|
if (!('before' in metadata)) {
|
|
340
340
|
throw new Error('Request body is not valid, `metadata.before` field is missing');
|
|
341
341
|
}
|
|
@@ -374,7 +374,9 @@ function parseInvokeRequest(body) {
|
|
|
374
374
|
},
|
|
375
375
|
event,
|
|
376
376
|
},
|
|
377
|
-
metadata: metadataEvent === '
|
|
377
|
+
metadata: metadataEvent === 'scheduled'
|
|
378
|
+
? { event: metadataEvent }
|
|
379
|
+
: { event: metadataEvent, before, after },
|
|
378
380
|
};
|
|
379
381
|
}
|
|
380
382
|
export { app, buildApiUrl, parseDocumentUrl };
|
|
@@ -9,6 +9,6 @@ export class ApiBaseElement extends HTMLElement {
|
|
|
9
9
|
this.api = api
|
|
10
10
|
this.SANITY_FUNCTION_DOCUMENT = 'sanity.function.document'
|
|
11
11
|
this.SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = 'sanity.function.media-library.asset'
|
|
12
|
-
this.
|
|
12
|
+
this.SANITY_FUNCTION_SCHEDULED = 'sanity.function.cron'
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -79,7 +79,7 @@ class FiltersComponent extends ApiBaseElement {
|
|
|
79
79
|
const mediaFunction = this.api.store.selectedFunctionType?.startsWith(
|
|
80
80
|
this.SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
81
81
|
)
|
|
82
|
-
const scheduleFunction = this.api.store.selectedFunctionType === this.
|
|
82
|
+
const scheduleFunction = this.api.store.selectedFunctionType === this.SANITY_FUNCTION_SCHEDULED
|
|
83
83
|
|
|
84
84
|
const container = this.shadowRoot.querySelector('fieldset')
|
|
85
85
|
container.innerHTML = this.buildFilters(docFunction, mediaFunction, scheduleFunction)
|
|
@@ -58,8 +58,8 @@ class FunctionList extends ApiBaseElement {
|
|
|
58
58
|
return 'Document'
|
|
59
59
|
case this.SANITY_FUNCTION_MEDIA_LIBRARY_ASSET:
|
|
60
60
|
return 'Media Library'
|
|
61
|
-
case this.
|
|
62
|
-
return '
|
|
61
|
+
case this.SANITY_FUNCTION_SCHEDULED:
|
|
62
|
+
return 'Scheduled'
|
|
63
63
|
default:
|
|
64
64
|
return type.split('.').pop().replaceAll('-', ' ')
|
|
65
65
|
}
|
|
@@ -79,7 +79,7 @@ class PayloadPanel extends ApiBaseElement {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
updateCodeMirror = ({selectedFunctionType}) => {
|
|
82
|
-
if (selectedFunctionType === this.
|
|
82
|
+
if (selectedFunctionType === this.SANITY_FUNCTION_SCHEDULED) {
|
|
83
83
|
this.api.store.beforePayload.dispatch({
|
|
84
84
|
effects: editableCompartment.reconfigure(EditorView.editable.of(false)),
|
|
85
85
|
})
|
|
@@ -25,7 +25,7 @@ class RunPanel extends ApiBaseElement {
|
|
|
25
25
|
const docFunction = this.api.store.selectedFunctionType === this.SANITY_FUNCTION_DOCUMENT
|
|
26
26
|
const mediaFunction =
|
|
27
27
|
this.api.store.selectedFunctionType === this.SANITY_FUNCTION_MEDIA_LIBRARY_ASSET
|
|
28
|
-
const scheduleFunction = this.api.store.selectedFunctionType === this.
|
|
28
|
+
const scheduleFunction = this.api.store.selectedFunctionType === this.SANITY_FUNCTION_SCHEDULED
|
|
29
29
|
const docOrScheduleFunction = docFunction || scheduleFunction
|
|
30
30
|
|
|
31
31
|
this.api.store.result = {logs: '', time: 0}
|
|
@@ -58,7 +58,7 @@ class RunPanel extends ApiBaseElement {
|
|
|
58
58
|
token: this.api.store.withToken,
|
|
59
59
|
},
|
|
60
60
|
eventResourceType: scheduleFunction
|
|
61
|
-
? '
|
|
61
|
+
? 'scheduled'
|
|
62
62
|
: mediaFunction
|
|
63
63
|
? 'media-library'
|
|
64
64
|
: 'dataset',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { treeify } from 'array-treeify';
|
|
2
|
-
import { SANITY_ACCESS_ROBOT, SANITY_ACCESS_ROLE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
2
|
+
import { SANITY_ACCESS_ROBOT, SANITY_ACCESS_ROLE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULED, SANITY_PROJECT, SANITY_PROJECT_CORS, SANITY_PROJECT_DATASET, SANITY_PROJECT_WEBHOOK, } from '../../constants.js';
|
|
3
3
|
import { styleText } from '../style-text.js';
|
|
4
4
|
import { isCorsOriginResource, isDatasetResource, isRobotResource, isRoleResource, isWebhookResource, } from '../types.js';
|
|
5
5
|
import { formatDate, formatDuration } from './dates.js';
|
|
@@ -27,7 +27,14 @@ const RESOURCE_CATEGORIES = {
|
|
|
27
27
|
},
|
|
28
28
|
[SANITY_FUNCTION_DOCUMENT]: functionCategory,
|
|
29
29
|
[SANITY_FUNCTION_MEDIA_LIBRARY_ASSET]: functionCategory,
|
|
30
|
-
[
|
|
30
|
+
[SANITY_FUNCTION_SCHEDULED]: functionCategory,
|
|
31
|
+
[SANITY_PROJECT]: {
|
|
32
|
+
label: 'Projects',
|
|
33
|
+
displayNameAttribute: 'displayName',
|
|
34
|
+
formatDetails(_res) {
|
|
35
|
+
return [];
|
|
36
|
+
},
|
|
37
|
+
},
|
|
31
38
|
[SANITY_PROJECT_CORS]: {
|
|
32
39
|
label: 'CORS Origins',
|
|
33
40
|
formatDetails(res) {
|
|
@@ -212,12 +219,12 @@ export function formatStacksListing(stacks, currentStackId) {
|
|
|
212
219
|
const IGNORED_PARAMS = {
|
|
213
220
|
[SANITY_FUNCTION_DOCUMENT]: new Set(['src']),
|
|
214
221
|
[SANITY_FUNCTION_MEDIA_LIBRARY_ASSET]: new Set(['src']),
|
|
215
|
-
[
|
|
222
|
+
[SANITY_FUNCTION_SCHEDULED]: new Set(['src']),
|
|
216
223
|
};
|
|
217
224
|
const ASSET_RESOURCE_TYPES = new Set([
|
|
218
225
|
SANITY_FUNCTION_DOCUMENT,
|
|
219
226
|
SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
220
|
-
|
|
227
|
+
SANITY_FUNCTION_SCHEDULED,
|
|
221
228
|
]);
|
|
222
229
|
function stringifyUnknown(val) {
|
|
223
230
|
if (val === null || val === undefined)
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import { SANITY_FUNCTION_PREFIX } from '../constants.js';
|
|
1
2
|
export function getFunctionNames(resources) {
|
|
2
3
|
return (resources
|
|
3
|
-
?.filter((r) => r?.type?.startsWith(
|
|
4
|
+
?.filter((r) => r?.type?.startsWith(SANITY_FUNCTION_PREFIX))
|
|
4
5
|
.map((r) => r.name)
|
|
5
6
|
.filter((name) => typeof name === 'string') ?? []);
|
|
6
7
|
}
|
|
7
8
|
export function findFunctionInBlueprint(blueprint, name) {
|
|
8
|
-
const func = blueprint?.resources?.find((r) => r?.type?.startsWith(
|
|
9
|
+
const func = blueprint?.resources?.find((r) => r?.type?.startsWith(SANITY_FUNCTION_PREFIX) && r.name === name);
|
|
9
10
|
if (!func)
|
|
10
11
|
throw Error(`Unable to find function ${name}`);
|
|
11
12
|
return func;
|
|
12
13
|
}
|
|
13
14
|
export function findFunctionInStack(stack, name) {
|
|
14
|
-
const func = stack?.resources?.find((r) => r?.type?.startsWith(
|
|
15
|
+
const func = stack?.resources?.find((r) => r?.type?.startsWith(SANITY_FUNCTION_PREFIX) && r.name === name);
|
|
15
16
|
if (!func)
|
|
16
17
|
throw Error(`Unable to find function: "${name}"`);
|
|
17
18
|
if (!isDeployedResource(func))
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type BlueprintCorsOriginResource, type BlueprintDatasetResource, type BlueprintDocumentWebhookResource, type BlueprintResource, type BlueprintRobotResource, type BlueprintRoleResource } from '@sanity/blueprints';
|
|
1
|
+
import { type BlueprintCorsOriginResource, type BlueprintDatasetResource, type BlueprintDocumentWebhookResource, type BlueprintProjectResource, type BlueprintResource, type BlueprintRobotResource, type BlueprintRoleResource } from '@sanity/blueprints';
|
|
2
2
|
import type { Blueprint } from '@sanity/blueprints-parser';
|
|
3
|
-
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
3
|
+
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULED } from '../constants.js';
|
|
4
4
|
export type ScopeType = 'organization' | 'project';
|
|
5
5
|
/** Result utility type */
|
|
6
6
|
export type Result<T, E = string> = {
|
|
@@ -65,6 +65,7 @@ export declare function isScheduleFunctionResource<T extends BlueprintResource>(
|
|
|
65
65
|
export declare function isLocalFunctionCollection<T extends BlueprintResource>(r: T): r is T & FunctionsCollection;
|
|
66
66
|
export declare function isScheduleEvent(e: unknown): e is FunctionResourceScheduleEvent;
|
|
67
67
|
export declare function isCorsOriginResource(r: unknown): r is BlueprintCorsOriginResource;
|
|
68
|
+
export declare function isProjectResource(r: unknown): r is BlueprintProjectResource;
|
|
68
69
|
export declare function isRobotResource(r: unknown): r is BlueprintRobotResource;
|
|
69
70
|
export declare function isRoleResource(r: unknown): r is BlueprintRoleResource;
|
|
70
71
|
export declare function isDatasetResource(r: unknown): r is BlueprintDatasetResource;
|
|
@@ -91,11 +92,11 @@ interface FunctionResourceMediaLibraryAsset extends FunctionResourceBase {
|
|
|
91
92
|
event: GroqRuleMediaLibraryFunction;
|
|
92
93
|
}
|
|
93
94
|
interface FunctionResourceSchedule extends FunctionResourceBase {
|
|
94
|
-
type: typeof
|
|
95
|
+
type: typeof SANITY_FUNCTION_SCHEDULED;
|
|
95
96
|
event: FunctionResourceScheduleEvent;
|
|
96
97
|
}
|
|
97
98
|
export interface CollectionFunction {
|
|
98
|
-
type: typeof SANITY_FUNCTION_DOCUMENT | typeof
|
|
99
|
+
type: typeof SANITY_FUNCTION_DOCUMENT | typeof SANITY_FUNCTION_SCHEDULED | typeof SANITY_FUNCTION_MEDIA_LIBRARY_ASSET;
|
|
99
100
|
src: string;
|
|
100
101
|
name: string;
|
|
101
102
|
displayName?: string;
|
|
@@ -159,7 +160,7 @@ export interface InvokeGroqPayloadOptions {
|
|
|
159
160
|
}
|
|
160
161
|
export interface InvokeSchedulePayloadOptions {
|
|
161
162
|
payload?: Record<string, unknown>;
|
|
162
|
-
event: '
|
|
163
|
+
event: 'scheduled';
|
|
163
164
|
}
|
|
164
165
|
export type InvokePayloadOptions = InvokeGroqPayloadOptions | InvokeSchedulePayloadOptions;
|
|
165
166
|
export type InvokePayloadMetadata = Pick<InvokeGroqPayloadOptions, 'event' | 'before' | 'after'> | Pick<InvokeSchedulePayloadOptions, 'event'>;
|
package/dist/utils/types.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { validateCorsOrigin, validateDataset, validateDocumentWebhook, validateRobot, validateRole, } from '@sanity/blueprints';
|
|
2
|
-
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
1
|
+
import { validateCorsOrigin, validateDataset, validateDocumentWebhook, validateProject, validateRobot, validateRole, } from '@sanity/blueprints';
|
|
2
|
+
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_PREFIX, SANITY_FUNCTION_SCHEDULED, } from '../constants.js';
|
|
3
3
|
// type narrowing with predicate functions
|
|
4
4
|
export function isLocalFunctionResource(r) {
|
|
5
|
-
return r.type.startsWith(
|
|
5
|
+
return r.type.startsWith(SANITY_FUNCTION_PREFIX);
|
|
6
6
|
}
|
|
7
7
|
export function isDocumentFunctionResource(r) {
|
|
8
8
|
return r.type === SANITY_FUNCTION_DOCUMENT;
|
|
@@ -11,7 +11,7 @@ export function isMediaLibraryAssetFunctionResource(r) {
|
|
|
11
11
|
return r.type === SANITY_FUNCTION_MEDIA_LIBRARY_ASSET;
|
|
12
12
|
}
|
|
13
13
|
export function isScheduleFunctionResource(r) {
|
|
14
|
-
return r.type ===
|
|
14
|
+
return r.type === SANITY_FUNCTION_SCHEDULED;
|
|
15
15
|
}
|
|
16
16
|
export function isLocalFunctionCollection(r) {
|
|
17
17
|
return r.type === 'sanity.experimental.functions-collection';
|
|
@@ -22,6 +22,9 @@ export function isScheduleEvent(e) {
|
|
|
22
22
|
export function isCorsOriginResource(r) {
|
|
23
23
|
return validateCorsOrigin(r).length === 0;
|
|
24
24
|
}
|
|
25
|
+
export function isProjectResource(r) {
|
|
26
|
+
return validateProject(r).length === 0;
|
|
27
|
+
}
|
|
25
28
|
export function isRobotResource(r) {
|
|
26
29
|
return validateRobot(r).length === 0;
|
|
27
30
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { validateCorsOrigin, validateDataset, validateDocumentFunction, validateDocumentWebhook, validateMediaLibraryAssetFunction, validateRole,
|
|
2
|
-
import { SANITY_ACCESS_ROLE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
1
|
+
import { validateCorsOrigin, validateDataset, validateDocumentFunction, validateDocumentWebhook, validateMediaLibraryAssetFunction, validateProject, validateRole, validateScheduledFunction, } from '@sanity/blueprints';
|
|
2
|
+
import { SANITY_ACCESS_ROLE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULED, SANITY_PROJECT, SANITY_PROJECT_CORS, SANITY_PROJECT_DATASET, SANITY_PROJECT_WEBHOOK, } from '../../constants.js';
|
|
3
3
|
export * as validate from './resource.js';
|
|
4
4
|
const RESOURCE_VALIDATORS = {
|
|
5
5
|
[SANITY_ACCESS_ROLE]: {
|
|
@@ -11,8 +11,11 @@ const RESOURCE_VALIDATORS = {
|
|
|
11
11
|
[SANITY_FUNCTION_MEDIA_LIBRARY_ASSET]: {
|
|
12
12
|
validate: validateMediaLibraryAssetFunction,
|
|
13
13
|
},
|
|
14
|
-
[
|
|
15
|
-
validate:
|
|
14
|
+
[SANITY_FUNCTION_SCHEDULED]: {
|
|
15
|
+
validate: validateScheduledFunction,
|
|
16
|
+
},
|
|
17
|
+
[SANITY_PROJECT]: {
|
|
18
|
+
validate: validateProject,
|
|
16
19
|
},
|
|
17
20
|
[SANITY_PROJECT_CORS]: {
|
|
18
21
|
validate: validateCorsOrigin,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SANITY_FUNCTION_PREFIX } from '../../constants.js';
|
|
1
2
|
import { BlueprintParserErrorType, isDocumentFunctionResource, isMediaLibraryAssetFunctionResource, isScheduleEvent, } from '../types.js';
|
|
2
3
|
export function validateFunctionName(name) {
|
|
3
4
|
// must be 3+ characters, no special characters, no spaces, allow _ and -
|
|
@@ -14,9 +15,9 @@ export function validateFunctionResource(resource) {
|
|
|
14
15
|
type: BlueprintParserErrorType.InvalidProperty,
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
|
-
if (!resource.type.startsWith(
|
|
18
|
+
if (!resource.type.startsWith(SANITY_FUNCTION_PREFIX)) {
|
|
18
19
|
errors.push({
|
|
19
|
-
message: `${msgPrefix} Resource type must start with "
|
|
20
|
+
message: `${msgPrefix} Resource type must start with "${SANITY_FUNCTION_PREFIX}"`,
|
|
20
21
|
type: BlueprintParserErrorType.InvalidType,
|
|
21
22
|
});
|
|
22
23
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -102,12 +102,12 @@
|
|
|
102
102
|
"options": [
|
|
103
103
|
"document-publish",
|
|
104
104
|
"document-create",
|
|
105
|
-
"document-delete",
|
|
106
105
|
"document-update",
|
|
106
|
+
"document-delete",
|
|
107
107
|
"media-library-asset-create",
|
|
108
108
|
"media-library-asset-update",
|
|
109
109
|
"media-library-asset-delete",
|
|
110
|
-
"
|
|
110
|
+
"scheduled-function"
|
|
111
111
|
],
|
|
112
112
|
"type": "option"
|
|
113
113
|
},
|
|
@@ -1202,12 +1202,12 @@
|
|
|
1202
1202
|
"options": [
|
|
1203
1203
|
"document-publish",
|
|
1204
1204
|
"document-create",
|
|
1205
|
-
"document-delete",
|
|
1206
1205
|
"document-update",
|
|
1206
|
+
"document-delete",
|
|
1207
1207
|
"media-library-asset-create",
|
|
1208
1208
|
"media-library-asset-update",
|
|
1209
1209
|
"media-library-asset-delete",
|
|
1210
|
-
"
|
|
1210
|
+
"scheduled-function"
|
|
1211
1211
|
],
|
|
1212
1212
|
"type": "option"
|
|
1213
1213
|
},
|
|
@@ -2163,5 +2163,5 @@
|
|
|
2163
2163
|
]
|
|
2164
2164
|
}
|
|
2165
2165
|
},
|
|
2166
|
-
"version": "14.
|
|
2166
|
+
"version": "14.4.0"
|
|
2167
2167
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/runtime-cli",
|
|
3
3
|
"description": "Sanity's Runtime CLI for Blueprints and Functions",
|
|
4
|
-
"version": "14.
|
|
4
|
+
"version": "14.4.0",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"@inquirer/prompts": "^8.2.1",
|
|
103
103
|
"@oclif/core": "^4.8.0",
|
|
104
104
|
"@oclif/plugin-help": "^6.2.37",
|
|
105
|
-
"@sanity/blueprints": "^0.
|
|
105
|
+
"@sanity/blueprints": "^0.13.1",
|
|
106
106
|
"@sanity/blueprints-parser": "^0.4.0",
|
|
107
107
|
"@sanity/client": "^7.15.0",
|
|
108
108
|
"adm-zip": "^0.5.16",
|