@sanity/runtime-cli 13.0.2 → 13.1.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 +32 -38
- package/dist/actions/blueprints/blueprint.js +2 -1
- package/dist/actions/git.d.ts +4 -1
- package/dist/actions/git.js +3 -3
- package/dist/commands/blueprints/config.js +1 -0
- package/dist/commands/blueprints/destroy.js +1 -0
- package/dist/commands/blueprints/init.js +1 -0
- package/dist/commands/blueprints/stacks.js +1 -0
- package/dist/commands/functions/test.js +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/cores/blueprints/init.d.ts +2 -0
- package/dist/cores/blueprints/init.js +38 -8
- package/dist/cores/functions/add.js +12 -1
- package/dist/server/static/vendor/vendor.bundle.js +18 -9
- package/dist/utils/child-process-wrapper.js +3 -2
- package/dist/utils/display/blueprints-formatting.d.ts +2 -2
- package/dist/utils/display/blueprints-formatting.js +10 -3
- package/dist/utils/display/prompt.js +22 -15
- package/dist/utils/display/resources-formatting.d.ts +2 -1
- package/dist/utils/display/resources-formatting.js +31 -0
- package/dist/utils/find-function.js +6 -1
- package/dist/utils/types.d.ts +10 -4
- package/dist/utils/types.js +4 -1
- package/oclif.manifest.json +6 -1
- package/package.json +16 -17
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/13.0
|
|
23
|
+
@sanity/runtime-cli/13.1.0 linux-x64 node-v24.13.0
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -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/v13.0
|
|
101
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/add.ts)_
|
|
102
102
|
|
|
103
103
|
## `sanity-run blueprints config`
|
|
104
104
|
|
|
@@ -106,13 +106,12 @@ View or edit the local Blueprint configuration
|
|
|
106
106
|
|
|
107
107
|
```
|
|
108
108
|
USAGE
|
|
109
|
-
$ sanity-run blueprints config [--project-id <value> -e] [--
|
|
109
|
+
$ sanity-run blueprints config [--project-id <value> -e] [--stack-id <value> ]
|
|
110
110
|
|
|
111
111
|
FLAGS
|
|
112
|
-
-e, --edit
|
|
113
|
-
--
|
|
114
|
-
--
|
|
115
|
-
--stack-id=<value> Directly set the Stack ID in the configuration. Requires --edit flag
|
|
112
|
+
-e, --edit Modify the configuration interactively, or directly when combined with ID flags.
|
|
113
|
+
--project-id=<value> Directly set the project ID in the configuration. Requires --edit flag
|
|
114
|
+
--stack-id=<value> Directly set the Stack ID in the configuration. Requires --edit flag
|
|
116
115
|
|
|
117
116
|
DESCRIPTION
|
|
118
117
|
View or edit the local Blueprint configuration
|
|
@@ -134,7 +133,7 @@ EXAMPLES
|
|
|
134
133
|
$ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
|
|
135
134
|
```
|
|
136
135
|
|
|
137
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
136
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/config.ts)_
|
|
138
137
|
|
|
139
138
|
## `sanity-run blueprints deploy`
|
|
140
139
|
|
|
@@ -164,7 +163,7 @@ EXAMPLES
|
|
|
164
163
|
$ sanity-run blueprints deploy --no-wait
|
|
165
164
|
```
|
|
166
165
|
|
|
167
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
166
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/deploy.ts)_
|
|
168
167
|
|
|
169
168
|
## `sanity-run blueprints destroy`
|
|
170
169
|
|
|
@@ -172,15 +171,13 @@ Destroy the remote Stack deployment and its resources (will not delete local fil
|
|
|
172
171
|
|
|
173
172
|
```
|
|
174
173
|
USAGE
|
|
175
|
-
$ sanity-run blueprints destroy [--project-id <value> --stack-id <value> --force] [--
|
|
176
|
-
[--no-wait]
|
|
174
|
+
$ sanity-run blueprints destroy [--project-id <value> --stack-id <value> --force] [--no-wait]
|
|
177
175
|
|
|
178
176
|
FLAGS
|
|
179
|
-
--force
|
|
180
|
-
--no-wait
|
|
181
|
-
--
|
|
182
|
-
--
|
|
183
|
-
--stack-id=<value> Stack ID to destroy (defaults to current Stack)
|
|
177
|
+
--force Force Stack destruction (skip confirmation)
|
|
178
|
+
--no-wait Do not wait for Stack destruction to complete
|
|
179
|
+
--project-id=<value> Project associated with the Stack
|
|
180
|
+
--stack-id=<value> Stack ID to destroy (defaults to current Stack)
|
|
184
181
|
|
|
185
182
|
DESCRIPTION
|
|
186
183
|
Destroy the remote Stack deployment and its resources (will not delete local files)
|
|
@@ -198,7 +195,7 @@ EXAMPLES
|
|
|
198
195
|
$ sanity-run blueprints destroy --stack-id <stackId> --project-id <projectId> --force --no-wait
|
|
199
196
|
```
|
|
200
197
|
|
|
201
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
198
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/destroy.ts)_
|
|
202
199
|
|
|
203
200
|
## `sanity-run blueprints doctor`
|
|
204
201
|
|
|
@@ -224,7 +221,7 @@ DESCRIPTION
|
|
|
224
221
|
issues.
|
|
225
222
|
```
|
|
226
223
|
|
|
227
|
-
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
224
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/doctor.ts)_
|
|
228
225
|
|
|
229
226
|
## `sanity-run blueprints info`
|
|
230
227
|
|
|
@@ -254,7 +251,7 @@ EXAMPLES
|
|
|
254
251
|
$ sanity-run blueprints info --id <stackId>
|
|
255
252
|
```
|
|
256
253
|
|
|
257
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
254
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/info.ts)_
|
|
258
255
|
|
|
259
256
|
## `sanity-run blueprints init [DIR]`
|
|
260
257
|
|
|
@@ -263,7 +260,7 @@ Initialize a local Blueprint and optionally provision a remote Stack deployment
|
|
|
263
260
|
```
|
|
264
261
|
USAGE
|
|
265
262
|
$ sanity-run blueprints init [DIR] [--verbose] [--dir <value>] [--example <value> | --blueprint-type json|js|ts |
|
|
266
|
-
--stack-id <value> | --stack-name <value>] [--project-id <value>]
|
|
263
|
+
--stack-id <value> | --stack-name <value>] [--project-id <value>]
|
|
267
264
|
|
|
268
265
|
ARGUMENTS
|
|
269
266
|
[DIR] Directory to create the local Blueprint in
|
|
@@ -273,7 +270,6 @@ FLAGS
|
|
|
273
270
|
<options: json|js|ts>
|
|
274
271
|
--dir=<value> Directory to create the local Blueprint in
|
|
275
272
|
--example=<value> Example to use for the local Blueprint
|
|
276
|
-
--organization-id=<value> Sanity organization ID used to scope local Blueprint and remote Stack
|
|
277
273
|
--project-id=<value> Sanity project ID used to scope local Blueprint and remote Stack
|
|
278
274
|
--stack-id=<value> Existing Stack ID used to scope local Blueprint
|
|
279
275
|
--stack-name=<value> Name to use for a new Stack provisioned during initialization
|
|
@@ -305,7 +301,7 @@ EXAMPLES
|
|
|
305
301
|
$ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
|
|
306
302
|
```
|
|
307
303
|
|
|
308
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
304
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/init.ts)_
|
|
309
305
|
|
|
310
306
|
## `sanity-run blueprints logs`
|
|
311
307
|
|
|
@@ -333,7 +329,7 @@ EXAMPLES
|
|
|
333
329
|
$ sanity-run blueprints logs --watch
|
|
334
330
|
```
|
|
335
331
|
|
|
336
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
332
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/logs.ts)_
|
|
337
333
|
|
|
338
334
|
## `sanity-run blueprints plan`
|
|
339
335
|
|
|
@@ -356,7 +352,7 @@ EXAMPLES
|
|
|
356
352
|
$ sanity-run blueprints plan
|
|
357
353
|
```
|
|
358
354
|
|
|
359
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
355
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/plan.ts)_
|
|
360
356
|
|
|
361
357
|
## `sanity-run blueprints stacks`
|
|
362
358
|
|
|
@@ -364,11 +360,10 @@ List all remote Stack deployments (defaults to the current Blueprint's project s
|
|
|
364
360
|
|
|
365
361
|
```
|
|
366
362
|
USAGE
|
|
367
|
-
$ sanity-run blueprints stacks [--project-id <value> |
|
|
363
|
+
$ sanity-run blueprints stacks [--project-id <value> | ]
|
|
368
364
|
|
|
369
365
|
FLAGS
|
|
370
|
-
--
|
|
371
|
-
--project-id=<value> Project ID to show Stack deployments for
|
|
366
|
+
--project-id=<value> Project ID to show Stack deployments for
|
|
372
367
|
|
|
373
368
|
DESCRIPTION
|
|
374
369
|
List all remote Stack deployments (defaults to the current Blueprint's project scope)
|
|
@@ -386,7 +381,7 @@ EXAMPLES
|
|
|
386
381
|
$ sanity-run blueprints stacks --organization-id <organizationId>
|
|
387
382
|
```
|
|
388
383
|
|
|
389
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
384
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/blueprints/stacks.ts)_
|
|
390
385
|
|
|
391
386
|
## `sanity-run functions add`
|
|
392
387
|
|
|
@@ -435,7 +430,7 @@ EXAMPLES
|
|
|
435
430
|
$ sanity-run functions add --name my-function --type document-create --type document-update --lang js
|
|
436
431
|
```
|
|
437
432
|
|
|
438
|
-
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
433
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/functions/add.ts)_
|
|
439
434
|
|
|
440
435
|
## `sanity-run functions dev`
|
|
441
436
|
|
|
@@ -469,7 +464,7 @@ EXAMPLES
|
|
|
469
464
|
$ sanity-run functions dev --timeout 60
|
|
470
465
|
```
|
|
471
466
|
|
|
472
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
467
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/functions/dev.ts)_
|
|
473
468
|
|
|
474
469
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
475
470
|
|
|
@@ -496,7 +491,7 @@ EXAMPLES
|
|
|
496
491
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
497
492
|
```
|
|
498
493
|
|
|
499
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
494
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/functions/env/add.ts)_
|
|
500
495
|
|
|
501
496
|
## `sanity-run functions env list NAME`
|
|
502
497
|
|
|
@@ -520,7 +515,7 @@ EXAMPLES
|
|
|
520
515
|
$ sanity-run functions env list MyFunction
|
|
521
516
|
```
|
|
522
517
|
|
|
523
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
518
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/functions/env/list.ts)_
|
|
524
519
|
|
|
525
520
|
## `sanity-run functions env remove NAME KEY`
|
|
526
521
|
|
|
@@ -546,7 +541,7 @@ EXAMPLES
|
|
|
546
541
|
$ sanity-run functions env remove MyFunction API_URL
|
|
547
542
|
```
|
|
548
543
|
|
|
549
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
544
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/functions/env/remove.ts)_
|
|
550
545
|
|
|
551
546
|
## `sanity-run functions logs [NAME]`
|
|
552
547
|
|
|
@@ -585,7 +580,7 @@ EXAMPLES
|
|
|
585
580
|
$ sanity-run functions logs <name> --delete
|
|
586
581
|
```
|
|
587
582
|
|
|
588
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
583
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/functions/logs.ts)_
|
|
589
584
|
|
|
590
585
|
## `sanity-run functions test [NAME]`
|
|
591
586
|
|
|
@@ -595,8 +590,8 @@ Invoke a local Sanity Function
|
|
|
595
590
|
USAGE
|
|
596
591
|
$ sanity-run functions test [NAME] [--data-before <value> | [-d <value> | -f <value> | --document-id <value>] | |
|
|
597
592
|
| --file-before <value> | --file-after <value> | --document-id-before <value> | --document-id-after <value>]
|
|
598
|
-
[--data-after <value> | | | | | | | ] [-e create|update|delete] [-t <value>] [-a <value>] [--
|
|
599
|
-
|
|
593
|
+
[--data-after <value> | | | | | | | ] [-e create|update|delete] [-t <value>] [-a <value>] [--with-user-token]
|
|
594
|
+
[--media-library-id <value> | --project-id <value> | --dataset <value>]
|
|
600
595
|
|
|
601
596
|
ARGUMENTS
|
|
602
597
|
[NAME] The name of the Sanity Function
|
|
@@ -617,7 +612,6 @@ FLAGS
|
|
|
617
612
|
--file-after=<value> Current document
|
|
618
613
|
--file-before=<value> Original document
|
|
619
614
|
--media-library-id=<value> Sanity Media Library ID to use
|
|
620
|
-
--organization-id=<value> Sanity Organization ID to use
|
|
621
615
|
--project-id=<value> Sanity Project ID to use
|
|
622
616
|
--with-user-token Prime access token from CLI config
|
|
623
617
|
|
|
@@ -640,7 +634,7 @@ EXAMPLES
|
|
|
640
634
|
$ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
|
|
641
635
|
```
|
|
642
636
|
|
|
643
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v13.0
|
|
637
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v13.1.0/src/commands/functions/test.ts)_
|
|
644
638
|
|
|
645
639
|
## `sanity-run help [COMMAND]`
|
|
646
640
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { basename, dirname, extname } from 'node:path';
|
|
3
3
|
import { cwd, env } from 'node:process';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
4
5
|
import blueprintParserValidator from '@sanity/blueprints-parser';
|
|
5
6
|
import { findUpSync } from 'find-up';
|
|
6
7
|
import { createJiti } from 'jiti';
|
|
@@ -89,7 +90,7 @@ export async function readLocalBlueprint(logger, blueprintPath) {
|
|
|
89
90
|
}
|
|
90
91
|
case '.ts': {
|
|
91
92
|
const jiti = createJiti(dirname(foundFilePath));
|
|
92
|
-
const modDefault = await jiti.import(
|
|
93
|
+
const modDefault = await jiti.import(pathToFileURL(foundFilePath).href, { default: true });
|
|
93
94
|
blueprintModule = modDefault;
|
|
94
95
|
break;
|
|
95
96
|
}
|
package/dist/actions/git.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export declare const GITIGNORE_FOR_FUNCTIONS = "\n# Sanity Functions\nfunctions/**/.env*\nfunctions/**/.build/\nfunctions/**/node_modules/\n";
|
|
2
2
|
export declare const GITIGNORE_TEMPLATE = "node_modules\n.env\n\n# Sanity Functions\nfunctions/**/.env*\nfunctions/**/.build/\nfunctions/**/node_modules/\n\n";
|
|
3
|
-
export
|
|
3
|
+
export type GitignoreResult = {
|
|
4
|
+
action: 'created' | 'updated' | 'unchanged';
|
|
5
|
+
};
|
|
6
|
+
export declare function writeGitignoreFile(nearFilePath: string): GitignoreResult;
|
package/dist/actions/git.js
CHANGED
|
@@ -20,9 +20,9 @@ export function writeGitignoreFile(nearFilePath) {
|
|
|
20
20
|
// append GITIGNORE_FOR_FUNCTIONS to existing .gitignore
|
|
21
21
|
const existingContent = readFileSync(gitignorePath, 'utf8').toString();
|
|
22
22
|
if (existingContent.includes(GITIGNORE_FOR_FUNCTIONS))
|
|
23
|
-
return
|
|
24
|
-
content = `${existingContent}\n${GITIGNORE_FOR_FUNCTIONS}`;
|
|
23
|
+
return { action: 'unchanged' };
|
|
24
|
+
content = `${existingContent.trimEnd()}\n${GITIGNORE_FOR_FUNCTIONS}`;
|
|
25
25
|
}
|
|
26
26
|
writeFileSync(gitignorePath, content);
|
|
27
|
-
return
|
|
27
|
+
return { action: gitignoreExists ? 'updated' : 'created' };
|
|
28
28
|
}
|
|
@@ -30,6 +30,7 @@ If you need to switch your Blueprint to a different Stack, use --edit --stack-id
|
|
|
30
30
|
description: 'Directly set the organization ID in the configuration. Requires --edit flag',
|
|
31
31
|
aliases: ['organization', 'organizationId', 'org'],
|
|
32
32
|
dependsOn: ['edit'],
|
|
33
|
+
hidden: true,
|
|
33
34
|
}),
|
|
34
35
|
'stack-id': Flags.string({
|
|
35
36
|
description: 'Directly set the Stack ID in the configuration. Requires --edit flag',
|
|
@@ -30,6 +30,7 @@ Use this to clean up test environments or decommission a Stack you no longer nee
|
|
|
30
30
|
aliases: ['organizationId', 'organization', 'org'],
|
|
31
31
|
dependsOn: ['stack-id', 'force'],
|
|
32
32
|
exclusive: ['project-id'],
|
|
33
|
+
hidden: true,
|
|
33
34
|
}),
|
|
34
35
|
'stack-id': Flags.string({
|
|
35
36
|
description: 'Stack ID to destroy (defaults to current Stack)',
|
|
@@ -45,6 +45,7 @@ After initialization, use 'blueprints plan' to preview changes, then 'blueprints
|
|
|
45
45
|
'organization-id': Flags.string({
|
|
46
46
|
description: 'Sanity organization ID used to scope local Blueprint and remote Stack',
|
|
47
47
|
aliases: ['organization', 'organizationId', 'org'],
|
|
48
|
+
hidden: true,
|
|
48
49
|
}),
|
|
49
50
|
'stack-id': Flags.string({
|
|
50
51
|
description: 'Existing Stack ID used to scope local Blueprint',
|
|
@@ -22,6 +22,7 @@ Use this to discover existing Stacks you can scope a local Blueprint to (using '
|
|
|
22
22
|
description: 'Organization ID to show Stack deployments for',
|
|
23
23
|
aliases: ['organizationId', 'organization', 'org'],
|
|
24
24
|
exclusive: ['project-id'],
|
|
25
|
+
hidden: true,
|
|
25
26
|
}),
|
|
26
27
|
};
|
|
27
28
|
async run() {
|
|
@@ -110,6 +110,7 @@ Provide test data via --data (inline JSON), --file (JSON file), or --document-id
|
|
|
110
110
|
description: 'Sanity Organization ID to use',
|
|
111
111
|
aliases: ['organization', 'organizationId', 'org'],
|
|
112
112
|
required: false,
|
|
113
|
+
hidden: true,
|
|
113
114
|
}),
|
|
114
115
|
'document-id': Flags.string({
|
|
115
116
|
description: 'Document to fetch and send to function',
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const SANITY_ACCESS_ROLE = "sanity.access.role";
|
|
2
|
+
export declare const SANITY_ACCESS_ROBOT = "sanity.access.robot";
|
|
2
3
|
export declare const SANITY_FUNCTION_DOCUMENT = "sanity.function.document";
|
|
3
4
|
export declare const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = "sanity.function.media-library.asset";
|
|
4
5
|
export declare const SANITY_FUNCTION_SCHEDULE = "sanity.function.cron";
|
package/dist/constants.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const SANITY_ACCESS_ROLE = 'sanity.access.role';
|
|
2
|
+
export const SANITY_ACCESS_ROBOT = 'sanity.access.robot';
|
|
2
3
|
export const SANITY_FUNCTION_DOCUMENT = 'sanity.function.document';
|
|
3
4
|
export const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = 'sanity.function.media-library.asset';
|
|
4
5
|
export const SANITY_FUNCTION_SCHEDULE = 'sanity.function.cron';
|
|
@@ -2,6 +2,7 @@ import type { ScopeType } from '../../utils/types.js';
|
|
|
2
2
|
import type { CoreConfig, CoreResult } from '../index.js';
|
|
3
3
|
export interface BlueprintInitOptions extends CoreConfig {
|
|
4
4
|
token: string;
|
|
5
|
+
knownProjectId?: string;
|
|
5
6
|
args: {
|
|
6
7
|
dir?: string;
|
|
7
8
|
};
|
|
@@ -33,6 +34,7 @@ export declare function resolveScopeAndStack(params: {
|
|
|
33
34
|
organizationId: string | undefined;
|
|
34
35
|
stackId: string | undefined;
|
|
35
36
|
stackName: string | undefined;
|
|
37
|
+
knownProjectId?: string;
|
|
36
38
|
log: CoreConfig['log'];
|
|
37
39
|
token: string;
|
|
38
40
|
}): Promise<ResolvedScope>;
|
|
@@ -8,6 +8,7 @@ import { createEmptyStack } from '../../actions/blueprints/stacks.js';
|
|
|
8
8
|
import { writeGitignoreFile } from '../../actions/git.js';
|
|
9
9
|
import { writeOrUpdateNodeDependency } from '../../actions/node.js';
|
|
10
10
|
import { verifyExampleExists, writeExample } from '../../actions/sanity/examples.js';
|
|
11
|
+
import { getProject } from '../../actions/sanity/projects.js';
|
|
11
12
|
import { BLUEPRINT_CONFIG_DIR, BLUEPRINT_CONFIG_FILE } from '../../config.js';
|
|
12
13
|
import { check, filePathRelativeToCwd, labeledId, warn } from '../../utils/display/presenters.js';
|
|
13
14
|
import { promptForBlueprintType, promptForProject, promptForStack, } from '../../utils/display/prompt.js';
|
|
@@ -15,7 +16,7 @@ import { blueprintConfigCore } from './config.js';
|
|
|
15
16
|
const SCOPE_PROJECT = 'project';
|
|
16
17
|
const SCOPE_ORGANIZATION = 'organization';
|
|
17
18
|
export async function blueprintInitCore(options) {
|
|
18
|
-
const { bin = 'sanity', log, token, args, flags } = options;
|
|
19
|
+
const { bin = 'sanity', log, token, knownProjectId, args, flags } = options;
|
|
19
20
|
const { dir: flagDir, example: flagExample, 'blueprint-type': flagBlueprintType, 'project-id': flagProjectId, 'organization-id': flagOrganizationId, 'stack-id': flagStackId, 'stack-name': flagStackName, verbose: v = false, } = flags;
|
|
20
21
|
const { dir: argDir } = args;
|
|
21
22
|
const userProvidedDirName = argDir || flagDir;
|
|
@@ -84,6 +85,7 @@ export async function blueprintInitCore(options) {
|
|
|
84
85
|
organizationId: flagOrganizationId,
|
|
85
86
|
stackId: flagStackId,
|
|
86
87
|
stackName: flagStackName,
|
|
88
|
+
knownProjectId,
|
|
87
89
|
log,
|
|
88
90
|
token,
|
|
89
91
|
});
|
|
@@ -169,7 +171,7 @@ async function handleExampleInitialization(options) {
|
|
|
169
171
|
return { success: true };
|
|
170
172
|
}
|
|
171
173
|
export async function resolveScopeAndStack(params) {
|
|
172
|
-
const { projectId, organizationId, stackId, stackName, log, token } = params;
|
|
174
|
+
const { projectId, organizationId, stackId, stackName, knownProjectId, log, token } = params;
|
|
173
175
|
let scopeType = SCOPE_PROJECT;
|
|
174
176
|
let scopeId;
|
|
175
177
|
if (projectId) {
|
|
@@ -195,10 +197,33 @@ export async function resolveScopeAndStack(params) {
|
|
|
195
197
|
resolvedStackId = stack.id;
|
|
196
198
|
}
|
|
197
199
|
if (!scopeId) {
|
|
198
|
-
log('\nBlueprints are associated with a Sanity
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
log('\nBlueprints are associated with a Sanity project.');
|
|
201
|
+
// If we have a CLI project ID, offer it as a suggestion
|
|
202
|
+
if (knownProjectId) {
|
|
203
|
+
const { ok, project } = await getProject({
|
|
204
|
+
token,
|
|
205
|
+
scopeId: knownProjectId,
|
|
206
|
+
scopeType: 'project',
|
|
207
|
+
logger: log,
|
|
208
|
+
});
|
|
209
|
+
if (ok && project) {
|
|
210
|
+
const useCliProject = await confirm({
|
|
211
|
+
message: `The CLI is configured to use "${project.displayName}" (${knownProjectId}). Use this for the blueprint?`,
|
|
212
|
+
default: true,
|
|
213
|
+
});
|
|
214
|
+
if (useCliProject) {
|
|
215
|
+
scopeType = SCOPE_PROJECT;
|
|
216
|
+
scopeId = knownProjectId;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// If still no scope (no knownProjectId, lookup failed, or user declined), prompt for selection
|
|
221
|
+
if (!scopeId) {
|
|
222
|
+
log('Select a project:');
|
|
223
|
+
const pickedProject = await promptForProject({ token, logger: log });
|
|
224
|
+
scopeType = SCOPE_PROJECT;
|
|
225
|
+
scopeId = pickedProject.projectId;
|
|
226
|
+
}
|
|
202
227
|
}
|
|
203
228
|
if (!resolvedStackId) {
|
|
204
229
|
log('\nBlueprints are deployed to a "Stack".');
|
|
@@ -254,8 +279,13 @@ export async function createBlueprintFiles(params) {
|
|
|
254
279
|
...(scopeType === SCOPE_ORGANIZATION ? { organizationId: scopeId } : { projectId: scopeId }),
|
|
255
280
|
});
|
|
256
281
|
log(check(`${chalk.bold('Added configuration:')} ${displayPath}/${BLUEPRINT_CONFIG_DIR}/${BLUEPRINT_CONFIG_FILE}`));
|
|
257
|
-
writeGitignoreFile(blueprintFilePath);
|
|
258
|
-
|
|
282
|
+
const gitignoreResult = writeGitignoreFile(blueprintFilePath);
|
|
283
|
+
if (gitignoreResult.action === 'created') {
|
|
284
|
+
log(check(`${chalk.bold('Added .gitignore:')} ${displayPath}/.gitignore`));
|
|
285
|
+
}
|
|
286
|
+
else if (gitignoreResult.action === 'updated') {
|
|
287
|
+
log(check(`${chalk.bold('Updated .gitignore:')} ${displayPath}/.gitignore`));
|
|
288
|
+
}
|
|
259
289
|
if (blueprintExtension !== 'json') {
|
|
260
290
|
const blueprintsPackage = '@sanity/blueprints';
|
|
261
291
|
try {
|
|
@@ -6,6 +6,7 @@ import { highlight } from 'cardinal';
|
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
import { createFunctionResource } from '../../actions/blueprints/resources.js';
|
|
8
8
|
import { verifyExampleExists, writeExample } from '../../actions/sanity/examples.js';
|
|
9
|
+
import { SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULE } from '../../constants.js';
|
|
9
10
|
import { check, indent, warn } from '../../utils/display/presenters.js';
|
|
10
11
|
import { validateFunctionName } from '../../utils/validate/resource.js';
|
|
11
12
|
const generateFunctionBlueprintResourceTemplate = (fnName, eventNames) => {
|
|
@@ -71,7 +72,17 @@ export async function functionAddCore(options) {
|
|
|
71
72
|
}
|
|
72
73
|
else {
|
|
73
74
|
const objectLiteral = configString.replace(/^(\s*)"([a-zA-Z_$][a-zA-Z0-9_$]*)":/gm, '$1$2:');
|
|
74
|
-
|
|
75
|
+
let type = 'Document';
|
|
76
|
+
switch (functionConfig.type) {
|
|
77
|
+
case SANITY_FUNCTION_MEDIA_LIBRARY_ASSET:
|
|
78
|
+
type = 'MediaLibraryAsset';
|
|
79
|
+
break;
|
|
80
|
+
case SANITY_FUNCTION_SCHEDULE:
|
|
81
|
+
type = 'Schedule';
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
}
|
|
85
|
+
log(indent(highlight(`define${type}Function(${objectLiteral})`)));
|
|
75
86
|
}
|
|
76
87
|
}
|
|
77
88
|
else {
|
|
@@ -5849,7 +5849,7 @@ class SelectionRange {
|
|
|
5849
5849
|
Compare this range to another range.
|
|
5850
5850
|
*/
|
|
5851
5851
|
eq(other, includeAssoc = false) {
|
|
5852
|
-
return this.anchor == other.anchor && this.head == other.head &&
|
|
5852
|
+
return this.anchor == other.anchor && this.head == other.head && this.goalColumn == other.goalColumn &&
|
|
5853
5853
|
(!includeAssoc || !this.empty || this.assoc == other.assoc);
|
|
5854
5854
|
}
|
|
5855
5855
|
/**
|
|
@@ -7338,7 +7338,8 @@ class EditorState {
|
|
|
7338
7338
|
- Other (anything else)
|
|
7339
7339
|
*/
|
|
7340
7340
|
charCategorizer(at) {
|
|
7341
|
-
|
|
7341
|
+
let chars = this.languageDataAt("wordChars", at);
|
|
7342
|
+
return makeCategorizer(chars.length ? chars[0] : "");
|
|
7342
7343
|
}
|
|
7343
7344
|
/**
|
|
7344
7345
|
Find the word at the given position, meaning the range
|
|
@@ -7524,6 +7525,9 @@ class RangeValue {
|
|
|
7524
7525
|
RangeValue.prototype.startSide = RangeValue.prototype.endSide = 0;
|
|
7525
7526
|
RangeValue.prototype.point = false;
|
|
7526
7527
|
RangeValue.prototype.mapMode = MapMode.TrackDel;
|
|
7528
|
+
function cmpVal(a, b) {
|
|
7529
|
+
return a == b || a.constructor == b.constructor && a.eq(b);
|
|
7530
|
+
}
|
|
7527
7531
|
/**
|
|
7528
7532
|
A range associates a value with a range of positions.
|
|
7529
7533
|
*/
|
|
@@ -7830,7 +7834,7 @@ class RangeSet {
|
|
|
7830
7834
|
for (;;) {
|
|
7831
7835
|
if (sideA.to != sideB.to ||
|
|
7832
7836
|
!sameValues(sideA.active, sideB.active) ||
|
|
7833
|
-
sideA.point && (!sideB.point || !sideA.point
|
|
7837
|
+
sideA.point && (!sideB.point || !cmpVal(sideA.point, sideB.point)))
|
|
7834
7838
|
return false;
|
|
7835
7839
|
if (sideA.to > to)
|
|
7836
7840
|
return true;
|
|
@@ -8305,22 +8309,27 @@ function compare(a, startA, b, startB, length, comparator) {
|
|
|
8305
8309
|
b.goto(startB);
|
|
8306
8310
|
let endB = startB + length;
|
|
8307
8311
|
let pos = startB, dPos = startB - startA;
|
|
8308
|
-
|
|
8312
|
+
let bounds = !!comparator.boundChange;
|
|
8313
|
+
for (let boundChange = false;;) {
|
|
8309
8314
|
let dEnd = (a.to + dPos) - b.to, diff = dEnd || a.endSide - b.endSide;
|
|
8310
8315
|
let end = diff < 0 ? a.to + dPos : b.to, clipEnd = Math.min(end, endB);
|
|
8311
|
-
|
|
8312
|
-
|
|
8316
|
+
let point = a.point || b.point;
|
|
8317
|
+
if (point) {
|
|
8318
|
+
if (!(a.point && b.point && cmpVal(a.point, b.point) &&
|
|
8313
8319
|
sameValues(a.activeForPoint(a.to), b.activeForPoint(b.to))))
|
|
8314
8320
|
comparator.comparePoint(pos, clipEnd, a.point, b.point);
|
|
8321
|
+
boundChange = false;
|
|
8315
8322
|
}
|
|
8316
8323
|
else {
|
|
8324
|
+
if (boundChange)
|
|
8325
|
+
comparator.boundChange(pos);
|
|
8317
8326
|
if (clipEnd > pos && !sameValues(a.active, b.active))
|
|
8318
8327
|
comparator.compareRange(pos, clipEnd, a.active, b.active);
|
|
8328
|
+
if (bounds && clipEnd < endB && (dEnd || a.openEnd(end) != b.openEnd(end)))
|
|
8329
|
+
boundChange = true;
|
|
8319
8330
|
}
|
|
8320
8331
|
if (end > endB)
|
|
8321
8332
|
break;
|
|
8322
|
-
if ((dEnd || a.openEnd != b.openEnd) && comparator.boundChange)
|
|
8323
|
-
comparator.boundChange(end);
|
|
8324
8333
|
pos = end;
|
|
8325
8334
|
if (diff <= 0)
|
|
8326
8335
|
a.next();
|
|
@@ -8332,7 +8341,7 @@ function sameValues(a, b) {
|
|
|
8332
8341
|
if (a.length != b.length)
|
|
8333
8342
|
return false;
|
|
8334
8343
|
for (let i = 0; i < a.length; i++)
|
|
8335
|
-
if (a[i] != b[i] && !a[i]
|
|
8344
|
+
if (a[i] != b[i] && !cmpVal(a[i], b[i]))
|
|
8336
8345
|
return false;
|
|
8337
8346
|
return true;
|
|
8338
8347
|
}
|
|
@@ -2,6 +2,7 @@ import {table as renderTable} from 'node:console'
|
|
|
2
2
|
import {existsSync, statSync} from 'node:fs'
|
|
3
3
|
import {isAbsolute, join} from 'node:path'
|
|
4
4
|
import process from 'node:process'
|
|
5
|
+
import {pathToFileURL} from 'node:url'
|
|
5
6
|
import {inspect} from 'node:util'
|
|
6
7
|
|
|
7
8
|
export function getFunctionSource(src) {
|
|
@@ -12,9 +13,9 @@ export function getFunctionSource(src) {
|
|
|
12
13
|
if (!existsSync(indexPath)) {
|
|
13
14
|
throw Error(`Function directory ${pathToCheck} has no index.js`)
|
|
14
15
|
}
|
|
15
|
-
return
|
|
16
|
+
return pathToFileURL(indexPath).href
|
|
16
17
|
}
|
|
17
|
-
return
|
|
18
|
+
return pathToFileURL(pathToCheck).href
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
// Monkey patch console menthods to have logs match server log format
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Blueprint, Resource } from '@sanity/blueprints-parser';
|
|
2
|
-
import { type
|
|
2
|
+
import { type BlueprintResourceRecord, type Stack } from '../types.js';
|
|
3
3
|
export declare function formatTitle(title: string, name: string): string;
|
|
4
|
-
export declare function formatDeployedResourceTree(resources:
|
|
4
|
+
export declare function formatDeployedResourceTree(resources: BlueprintResourceRecord[] | undefined, verbose?: boolean): string;
|
|
5
5
|
export declare function formatResourceTree(resources: Resource[] | undefined, verbose?: boolean): string;
|
|
6
6
|
export declare function formatStackInfo(stack: Stack | Blueprint, isCurrentStack?: boolean): string;
|
|
7
7
|
export declare function formatStacksListing(stacks: Stack[], currentStackId?: string): string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { treeify } from 'array-treeify';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import { SANITY_ACCESS_ROLE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULE, SANITY_PROJECT_CORS, SANITY_PROJECT_DATASET, SANITY_PROJECT_WEBHOOK, } from '../../constants.js';
|
|
4
|
-
import { isCorsOriginResource, isDatasetResource, isRoleResource, isWebhookResource, } from '../types.js';
|
|
3
|
+
import { SANITY_ACCESS_ROBOT, SANITY_ACCESS_ROLE, SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULE, SANITY_PROJECT_CORS, SANITY_PROJECT_DATASET, SANITY_PROJECT_WEBHOOK, } from '../../constants.js';
|
|
4
|
+
import { isCorsOriginResource, isDatasetResource, isRobotResource, isRoleResource, isWebhookResource, } from '../types.js';
|
|
5
5
|
import { formatDate, formatDuration } from './dates.js';
|
|
6
6
|
import { niceId } from './presenters.js';
|
|
7
|
-
import { arrayifyCors, arrayifyDataset, arrayifyFunction, arrayifyRole, arrayifyWebhook, } from './resources-formatting.js';
|
|
7
|
+
import { arrayifyCors, arrayifyDataset, arrayifyFunction, arrayifyRobot, arrayifyRole, arrayifyWebhook, } from './resources-formatting.js';
|
|
8
8
|
const functionCategory = {
|
|
9
9
|
label: 'Functions',
|
|
10
10
|
displayNameAttribute: 'displayName',
|
|
@@ -18,6 +18,13 @@ const RESOURCE_CATEGORIES = {
|
|
|
18
18
|
return isRoleResource(res) ? arrayifyRole(res) : [];
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
|
+
[SANITY_ACCESS_ROBOT]: {
|
|
22
|
+
label: 'Robots',
|
|
23
|
+
displayNameAttribute: 'label',
|
|
24
|
+
formatDetails(res) {
|
|
25
|
+
return isRobotResource(res) ? arrayifyRobot(res) : [];
|
|
26
|
+
},
|
|
27
|
+
},
|
|
21
28
|
[SANITY_FUNCTION_DOCUMENT]: functionCategory,
|
|
22
29
|
[SANITY_FUNCTION_MEDIA_LIBRARY_ASSET]: functionCategory,
|
|
23
30
|
[SANITY_FUNCTION_SCHEDULE]: functionCategory,
|
|
@@ -32,24 +32,25 @@ export async function promptForProject({ token, knownOrganizationId, knownProjec
|
|
|
32
32
|
if (organizations.length > 1) {
|
|
33
33
|
const orgChoices = organizations.map(({ organization, projects }) => ({
|
|
34
34
|
name: `"${organization.name}" ${niceId(organization.id)}`,
|
|
35
|
-
value:
|
|
35
|
+
value: organization.id,
|
|
36
36
|
disabled: !projects || projects.length === 0 ? '(0 Projects)' : false,
|
|
37
37
|
}));
|
|
38
|
-
const
|
|
38
|
+
const pickedOrgId = await select({
|
|
39
39
|
message: 'Which Organization would you like to use?',
|
|
40
40
|
choices: orgChoices,
|
|
41
41
|
default: knownOrganizationId,
|
|
42
42
|
});
|
|
43
|
-
|
|
43
|
+
const pickedOrg = organizations.find((o) => o.organization.id === pickedOrgId);
|
|
44
|
+
projects = pickedOrg?.projects;
|
|
44
45
|
}
|
|
45
46
|
else {
|
|
46
47
|
projects = organizations[0].projects;
|
|
47
48
|
}
|
|
48
49
|
const projectChoices = projects.map(({ displayName, id: projectId }) => ({
|
|
49
50
|
name: `"${displayName}" ${niceId(projectId)}`,
|
|
50
|
-
value:
|
|
51
|
+
value: projectId,
|
|
51
52
|
}));
|
|
52
|
-
let
|
|
53
|
+
let pickedProjectId;
|
|
53
54
|
if (projectChoices.length === 1) {
|
|
54
55
|
const onlyProject = projectChoices[0];
|
|
55
56
|
const confirmed = await confirm({
|
|
@@ -57,18 +58,21 @@ export async function promptForProject({ token, knownOrganizationId, knownProjec
|
|
|
57
58
|
default: true,
|
|
58
59
|
});
|
|
59
60
|
if (confirmed)
|
|
60
|
-
|
|
61
|
+
pickedProjectId = onlyProject.value;
|
|
61
62
|
else
|
|
62
63
|
throw new Error('No project selected');
|
|
63
64
|
}
|
|
64
65
|
else {
|
|
65
|
-
|
|
66
|
+
pickedProjectId = await select({
|
|
66
67
|
message: 'Choose a Sanity Project:',
|
|
67
68
|
choices: projectChoices,
|
|
68
69
|
default: knownProjectId,
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
+
const pickedProject = projects.find((p) => p.id === pickedProjectId);
|
|
73
|
+
if (!pickedProject)
|
|
74
|
+
throw new Error('Project not found');
|
|
75
|
+
return { projectId: pickedProject.id, displayName: pickedProject.displayName };
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
74
78
|
* Prompt the user for a Stack ID after selecting a Project.
|
|
@@ -83,24 +87,24 @@ export async function promptForStack({ projectId, token, logger, }) {
|
|
|
83
87
|
if (!stacksOk) {
|
|
84
88
|
throw new Error(stacksErr || 'Failed to list Stacks');
|
|
85
89
|
}
|
|
86
|
-
const
|
|
87
|
-
let pickedStackId =
|
|
90
|
+
const NEW_STACK_ID = 'new';
|
|
91
|
+
let pickedStackId = NEW_STACK_ID;
|
|
88
92
|
if (stacks.length > 0) {
|
|
89
93
|
const stackChoices = [];
|
|
90
94
|
stackChoices.push(new Separator(chalk.underline('Create a new Stack:')));
|
|
91
|
-
stackChoices.push({ name: chalk.bold('New Stack ✨'), value:
|
|
95
|
+
stackChoices.push({ name: chalk.bold('New Stack ✨'), value: NEW_STACK_ID });
|
|
92
96
|
stackChoices.push(new Separator(chalk.underline('Use an existing Stack:')));
|
|
93
97
|
stackChoices.push(...stacks.map((s) => ({
|
|
94
98
|
name: `"${s.name}" ${niceId(s.id)} ${chalk.dim(`(${s.resources.length} res)`)}`,
|
|
95
|
-
value:
|
|
99
|
+
value: s.id,
|
|
96
100
|
})));
|
|
97
101
|
pickedStackId = await select({
|
|
98
102
|
message: 'Select a deployment Stack:',
|
|
99
103
|
choices: stackChoices,
|
|
100
|
-
default:
|
|
104
|
+
default: NEW_STACK_ID,
|
|
101
105
|
});
|
|
102
106
|
}
|
|
103
|
-
if (pickedStackId
|
|
107
|
+
if (pickedStackId === NEW_STACK_ID) {
|
|
104
108
|
const stackName = await input({
|
|
105
109
|
message: 'Enter a name for your new Stack:',
|
|
106
110
|
validate: (input) => input.length > 0 || 'Stack name is required',
|
|
@@ -114,5 +118,8 @@ export async function promptForStack({ projectId, token, logger, }) {
|
|
|
114
118
|
});
|
|
115
119
|
return { stackId: stack.id, name: stackName };
|
|
116
120
|
}
|
|
117
|
-
|
|
121
|
+
const pickedStack = stacks.find((s) => s.id === pickedStackId);
|
|
122
|
+
if (!pickedStack)
|
|
123
|
+
throw new Error('Stack not found');
|
|
124
|
+
return { stackId: pickedStack.id, name: pickedStack.name };
|
|
118
125
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { BlueprintCorsOriginResource, BlueprintDatasetResource, BlueprintDocumentWebhookResource, BlueprintRoleResource } from '@sanity/blueprints';
|
|
1
|
+
import type { BlueprintCorsOriginResource, BlueprintDatasetResource, BlueprintDocumentWebhookResource, BlueprintRobotResource, BlueprintRoleResource } from '@sanity/blueprints';
|
|
2
2
|
import type { TreeInput } from 'array-treeify';
|
|
3
3
|
import { type FunctionResourceBase } from '../../utils/types.js';
|
|
4
4
|
export declare function arrayifyFunction(fn: FunctionResourceBase): TreeInput;
|
|
5
5
|
export declare function arrayifyCors(resource: BlueprintCorsOriginResource): TreeInput;
|
|
6
|
+
export declare function arrayifyRobot(resource: BlueprintRobotResource): TreeInput;
|
|
6
7
|
export declare function arrayifyRole(resource: BlueprintRoleResource): TreeInput;
|
|
7
8
|
export declare function arrayifyDataset(resource: BlueprintDatasetResource): TreeInput;
|
|
8
9
|
export declare function arrayifyWebhook(resource: BlueprintDocumentWebhookResource): TreeInput;
|
|
@@ -49,6 +49,37 @@ export function arrayifyFunction(fn) {
|
|
|
49
49
|
export function arrayifyCors(resource) {
|
|
50
50
|
return [formatLabeledValue('origin', resource.origin)];
|
|
51
51
|
}
|
|
52
|
+
export function arrayifyRobot(resource) {
|
|
53
|
+
const details = [formatLabeledValue('label', resource.label)];
|
|
54
|
+
if (resource.memberships.length > 0) {
|
|
55
|
+
details.push(formatLabel('memberships'));
|
|
56
|
+
const memberships = [];
|
|
57
|
+
resource.memberships.forEach((m, i) => {
|
|
58
|
+
const membership = [];
|
|
59
|
+
membership.push(formatLabeledValue('resourceType', m.resourceType));
|
|
60
|
+
membership.push(formatLabeledValue('resourceId', m.resourceId));
|
|
61
|
+
if (m.roleNames.length > 0) {
|
|
62
|
+
membership.push(formatLabeledValue('roleNames', m.roleNames.join(', ')));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
membership.push(formatLabeledValue('roleNames', '[]'));
|
|
66
|
+
}
|
|
67
|
+
memberships.push(formatLabel(i.toString()));
|
|
68
|
+
memberships.push(membership);
|
|
69
|
+
});
|
|
70
|
+
details.push(memberships);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
details.push(formatLabeledValue('memberships', '[]'));
|
|
74
|
+
}
|
|
75
|
+
if (resource.resourceType) {
|
|
76
|
+
details.push(formatLabeledValue('resourceType', resource.resourceType));
|
|
77
|
+
}
|
|
78
|
+
if (resource.resourceId) {
|
|
79
|
+
details.push(formatLabeledValue('resourceId', resource.resourceId));
|
|
80
|
+
}
|
|
81
|
+
return details;
|
|
82
|
+
}
|
|
52
83
|
export function arrayifyRole(resource) {
|
|
53
84
|
const details = [];
|
|
54
85
|
if (resource.description)
|
|
@@ -13,7 +13,12 @@ export function findFunctionInBlueprint(blueprint, name) {
|
|
|
13
13
|
export function findFunctionInStack(stack, name) {
|
|
14
14
|
const func = stack?.resources?.find((r) => r?.type?.startsWith('sanity.function.') && r.name === name);
|
|
15
15
|
if (!func)
|
|
16
|
-
throw Error(`Unable to find function ${name}`);
|
|
16
|
+
throw Error(`Unable to find function: "${name}"`);
|
|
17
|
+
if (!isDeployedResource(func))
|
|
18
|
+
throw Error(`Unable to find deployed function: "${name}"`);
|
|
17
19
|
// return the deployed resource
|
|
18
20
|
return func;
|
|
19
21
|
}
|
|
22
|
+
function isDeployedResource(r) {
|
|
23
|
+
return 'externalId' in r && typeof r.externalId === 'string';
|
|
24
|
+
}
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type BlueprintCorsOriginResource, type BlueprintDatasetResource, type BlueprintDocumentWebhookResource, type BlueprintResource, type BlueprintRoleResource } from '@sanity/blueprints';
|
|
1
|
+
import { type BlueprintCorsOriginResource, type BlueprintDatasetResource, type BlueprintDocumentWebhookResource, type BlueprintResource, type BlueprintRobotResource, type BlueprintRoleResource } from '@sanity/blueprints';
|
|
2
2
|
import type { Blueprint } from '@sanity/blueprints-parser';
|
|
3
3
|
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULE } from '../constants.js';
|
|
4
4
|
export type ScopeType = 'organization' | 'project';
|
|
@@ -48,11 +48,16 @@ interface FunctionResourceScheduleExpressionEvent {
|
|
|
48
48
|
expression: string;
|
|
49
49
|
}
|
|
50
50
|
type FunctionResourceScheduleEvent = FunctionResourceScheduleExplicitEvent | FunctionResourceScheduleExpressionEvent;
|
|
51
|
-
|
|
51
|
+
/** The Blueprint resource as represented in the Blueprints API database */
|
|
52
|
+
export interface BlueprintResourceRecord extends BlueprintResource {
|
|
52
53
|
id: string;
|
|
53
|
-
externalId
|
|
54
|
+
externalId?: string | null;
|
|
54
55
|
parameters: Record<string, unknown>;
|
|
55
56
|
}
|
|
57
|
+
/** The deployed resource; complete with external ID */
|
|
58
|
+
export interface DeployedResource extends BlueprintResourceRecord {
|
|
59
|
+
externalId: string;
|
|
60
|
+
}
|
|
56
61
|
export declare function isLocalFunctionResource(r: BlueprintResource): r is FunctionResourceBase;
|
|
57
62
|
export declare function isDocumentFunctionResource<T extends BlueprintResource>(r: T): r is T & FunctionResourceDocument;
|
|
58
63
|
export declare function isMediaLibraryAssetFunctionResource<T extends BlueprintResource>(r: T): r is T & FunctionResourceMediaLibraryAsset;
|
|
@@ -60,6 +65,7 @@ export declare function isScheduleFunctionResource<T extends BlueprintResource>(
|
|
|
60
65
|
export declare function isLocalFunctionCollection<T extends BlueprintResource>(r: T): r is T & FunctionsCollection;
|
|
61
66
|
export declare function isScheduleEvent(e: unknown): e is FunctionResourceScheduleEvent;
|
|
62
67
|
export declare function isCorsOriginResource(r: unknown): r is BlueprintCorsOriginResource;
|
|
68
|
+
export declare function isRobotResource(r: unknown): r is BlueprintRobotResource;
|
|
63
69
|
export declare function isRoleResource(r: unknown): r is BlueprintRoleResource;
|
|
64
70
|
export declare function isDatasetResource(r: unknown): r is BlueprintDatasetResource;
|
|
65
71
|
export declare function isWebhookResource(r: unknown): r is BlueprintDocumentWebhookResource;
|
|
@@ -114,7 +120,7 @@ export interface Stack {
|
|
|
114
120
|
displayName: string;
|
|
115
121
|
scopeType: ScopeType;
|
|
116
122
|
scopeId: string;
|
|
117
|
-
resources: Array<
|
|
123
|
+
resources: Array<BlueprintResourceRecord>;
|
|
118
124
|
createdAt?: string;
|
|
119
125
|
updatedAt?: string;
|
|
120
126
|
recentOperation?: StackOperation;
|
package/dist/utils/types.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { validateCorsOrigin, validateDataset, validateDocumentWebhook, validateRole, } from '@sanity/blueprints';
|
|
1
|
+
import { validateCorsOrigin, validateDataset, validateDocumentWebhook, validateRobot, validateRole, } from '@sanity/blueprints';
|
|
2
2
|
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULE, } from '../constants.js';
|
|
3
3
|
// type narrowing with predicate functions
|
|
4
4
|
export function isLocalFunctionResource(r) {
|
|
@@ -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 isRobotResource(r) {
|
|
26
|
+
return validateRobot(r).length === 0;
|
|
27
|
+
}
|
|
25
28
|
export function isRoleResource(r) {
|
|
26
29
|
return validateRole(r).length === 0;
|
|
27
30
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -253,6 +253,7 @@
|
|
|
253
253
|
"edit"
|
|
254
254
|
],
|
|
255
255
|
"description": "Directly set the organization ID in the configuration. Requires --edit flag",
|
|
256
|
+
"hidden": true,
|
|
256
257
|
"name": "organization-id",
|
|
257
258
|
"hasDynamicHelp": false,
|
|
258
259
|
"multiple": false,
|
|
@@ -431,6 +432,7 @@
|
|
|
431
432
|
"exclusive": [
|
|
432
433
|
"project-id"
|
|
433
434
|
],
|
|
435
|
+
"hidden": true,
|
|
434
436
|
"name": "organization-id",
|
|
435
437
|
"hasDynamicHelp": false,
|
|
436
438
|
"multiple": false,
|
|
@@ -694,6 +696,7 @@
|
|
|
694
696
|
"org"
|
|
695
697
|
],
|
|
696
698
|
"description": "Sanity organization ID used to scope local Blueprint and remote Stack",
|
|
699
|
+
"hidden": true,
|
|
697
700
|
"name": "organization-id",
|
|
698
701
|
"hasDynamicHelp": false,
|
|
699
702
|
"multiple": false,
|
|
@@ -931,6 +934,7 @@
|
|
|
931
934
|
"exclusive": [
|
|
932
935
|
"project-id"
|
|
933
936
|
],
|
|
937
|
+
"hidden": true,
|
|
934
938
|
"name": "organization-id",
|
|
935
939
|
"hasDynamicHelp": false,
|
|
936
940
|
"multiple": false,
|
|
@@ -1512,6 +1516,7 @@
|
|
|
1512
1516
|
"org"
|
|
1513
1517
|
],
|
|
1514
1518
|
"description": "Sanity Organization ID to use",
|
|
1519
|
+
"hidden": true,
|
|
1515
1520
|
"name": "organization-id",
|
|
1516
1521
|
"required": false,
|
|
1517
1522
|
"hasDynamicHelp": false,
|
|
@@ -1809,5 +1814,5 @@
|
|
|
1809
1814
|
]
|
|
1810
1815
|
}
|
|
1811
1816
|
},
|
|
1812
|
-
"version": "13.0
|
|
1817
|
+
"version": "13.1.0"
|
|
1813
1818
|
}
|
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": "13.0
|
|
4
|
+
"version": "13.1.0",
|
|
5
5
|
"author": "Sanity Runtime Team",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
@@ -98,12 +98,12 @@
|
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"@architect/hydrate": "^5.0.1",
|
|
100
100
|
"@architect/inventory": "^5.0.0",
|
|
101
|
-
"@inquirer/prompts": "^8.0
|
|
101
|
+
"@inquirer/prompts": "^8.2.0",
|
|
102
102
|
"@oclif/core": "^4.8.0",
|
|
103
103
|
"@oclif/plugin-help": "^6.2.36",
|
|
104
|
-
"@sanity/blueprints": "^0.
|
|
104
|
+
"@sanity/blueprints": "^0.8.0",
|
|
105
105
|
"@sanity/blueprints-parser": "^0.3.0",
|
|
106
|
-
"@sanity/client": "^7.
|
|
106
|
+
"@sanity/client": "^7.14.0",
|
|
107
107
|
"adm-zip": "^0.5.16",
|
|
108
108
|
"array-treeify": "^0.1.5",
|
|
109
109
|
"cardinal": "^2.1.1",
|
|
@@ -111,25 +111,24 @@
|
|
|
111
111
|
"eventsource": "^4.1.0",
|
|
112
112
|
"find-up": "^8.0.0",
|
|
113
113
|
"get-folder-size": "^5.0.0",
|
|
114
|
-
"groq-js": "^1.
|
|
115
|
-
"inquirer": "^12.11.1",
|
|
114
|
+
"groq-js": "^1.25.0",
|
|
116
115
|
"jiti": "^2.6.1",
|
|
117
116
|
"mime-types": "^3.0.2",
|
|
118
|
-
"ora": "^9.
|
|
117
|
+
"ora": "^9.1.0",
|
|
119
118
|
"tar-stream": "^3.1.7",
|
|
120
|
-
"vite": "^7.
|
|
121
|
-
"vite-tsconfig-paths": "^
|
|
122
|
-
"ws": "^8.
|
|
119
|
+
"vite": "^7.3.1",
|
|
120
|
+
"vite-tsconfig-paths": "^6.0.4",
|
|
121
|
+
"ws": "^8.19.0",
|
|
123
122
|
"xdg-basedir": "^5.1.0"
|
|
124
123
|
},
|
|
125
124
|
"devDependencies": {
|
|
126
|
-
"@biomejs/biome": "2.3.
|
|
125
|
+
"@biomejs/biome": "2.3.11",
|
|
127
126
|
"@codemirror/lang-json": "^6.0.2",
|
|
128
|
-
"@codemirror/state": "^6.5.
|
|
127
|
+
"@codemirror/state": "^6.5.4",
|
|
129
128
|
"@enhance/store": "^1.0.2",
|
|
130
129
|
"@lezer/highlight": "^1.2.3",
|
|
131
130
|
"@oclif/test": "^4.1.15",
|
|
132
|
-
"@playwright/test": "^1.
|
|
131
|
+
"@playwright/test": "^1.57.0",
|
|
133
132
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
134
133
|
"@sanity/functions": "^1.1.0",
|
|
135
134
|
"@types/adm-zip": "^0.5.7",
|
|
@@ -139,15 +138,15 @@
|
|
|
139
138
|
"@types/tar-stream": "^3.1.4",
|
|
140
139
|
"@types/ws": "^8.18.1",
|
|
141
140
|
"codemirror": "^6.0.2",
|
|
142
|
-
"mentoss": "^0.
|
|
143
|
-
"oclif": "^4.22.
|
|
141
|
+
"mentoss": "^0.13.0",
|
|
142
|
+
"oclif": "^4.22.67",
|
|
144
143
|
"pretty-bytes": "^7.1.0",
|
|
145
144
|
"pretty-ms": "^9.3.0",
|
|
146
|
-
"rollup": "^4.
|
|
145
|
+
"rollup": "^4.55.3",
|
|
147
146
|
"shx": "^0.4.0",
|
|
148
147
|
"ts-node": "^10.9.2",
|
|
149
148
|
"typescript": "^5.9.3",
|
|
150
|
-
"vitest": "4.0.
|
|
149
|
+
"vitest": "4.0.17"
|
|
151
150
|
},
|
|
152
151
|
"oclif": {
|
|
153
152
|
"bin": "sanity-run",
|