@sanity/runtime-cli 14.12.0 → 14.13.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 +26 -21
- package/dist/actions/blueprints/blueprint.d.ts +17 -0
- package/dist/actions/blueprints/blueprint.js +24 -20
- package/dist/actions/blueprints/resolve.d.ts +11 -6
- package/dist/actions/blueprints/resolve.js +14 -4
- package/dist/actions/functions/dev.d.ts +1 -2
- package/dist/actions/functions/dev.js +2 -2
- package/dist/actions/sanity/projects.d.ts +2 -1
- package/dist/actions/sanity/projects.js +5 -2
- package/dist/baseCommands.d.ts +10 -23
- package/dist/baseCommands.js +26 -75
- package/dist/commands/blueprints/add.d.ts +3 -2
- package/dist/commands/blueprints/add.js +3 -2
- package/dist/commands/blueprints/config.d.ts +3 -2
- package/dist/commands/blueprints/config.js +3 -2
- package/dist/commands/blueprints/deploy.d.ts +3 -2
- package/dist/commands/blueprints/deploy.js +4 -3
- package/dist/commands/blueprints/destroy.d.ts +3 -2
- package/dist/commands/blueprints/destroy.js +3 -2
- package/dist/commands/blueprints/doctor.d.ts +0 -1
- package/dist/commands/blueprints/doctor.js +2 -3
- package/dist/commands/blueprints/init.d.ts +0 -1
- package/dist/commands/blueprints/init.js +1 -2
- package/dist/commands/blueprints/logs.d.ts +3 -2
- package/dist/commands/blueprints/logs.js +4 -3
- package/dist/commands/blueprints/plan.d.ts +3 -2
- package/dist/commands/blueprints/plan.js +5 -3
- package/dist/commands/blueprints/promote.d.ts +3 -2
- package/dist/commands/blueprints/promote.js +3 -2
- package/dist/commands/blueprints/stacks.d.ts +4 -2
- package/dist/commands/blueprints/stacks.js +15 -4
- package/dist/commands/functions/add.d.ts +3 -2
- package/dist/commands/functions/add.js +3 -2
- package/dist/commands/functions/build.d.ts +3 -2
- package/dist/commands/functions/build.js +3 -2
- package/dist/commands/functions/dev.d.ts +3 -2
- package/dist/commands/functions/dev.js +3 -2
- package/dist/commands/functions/env/add.d.ts +3 -2
- package/dist/commands/functions/env/add.js +3 -2
- package/dist/commands/functions/env/list.d.ts +3 -2
- package/dist/commands/functions/env/list.js +3 -2
- package/dist/commands/functions/env/remove.d.ts +3 -2
- package/dist/commands/functions/env/remove.js +3 -2
- package/dist/commands/functions/logs.d.ts +3 -2
- package/dist/commands/functions/logs.js +4 -3
- package/dist/commands/functions/test.d.ts +3 -2
- package/dist/commands/functions/test.js +3 -2
- package/dist/cores/blueprints/config.js +9 -4
- package/dist/cores/blueprints/destroy.js +78 -56
- package/dist/cores/blueprints/doctor.js +19 -5
- package/dist/cores/blueprints/init.js +2 -2
- package/dist/cores/blueprints/stacks.d.ts +1 -0
- package/dist/cores/blueprints/stacks.js +73 -2
- package/dist/cores/functions/dev.js +1 -1
- package/dist/server/app.d.ts +1 -2
- package/dist/server/app.js +16 -8
- package/dist/server/handlers/invoke.d.ts +1 -2
- package/dist/server/handlers/invoke.js +4 -4
- package/oclif.manifest.json +17 -18
- package/package.json +1 -1
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.13.0 linux-x64 node-v24.14.1
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -101,7 +101,7 @@ EXAMPLES
|
|
|
101
101
|
$ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
104
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/add.ts)_
|
|
105
105
|
|
|
106
106
|
## `sanity-run blueprints config`
|
|
107
107
|
|
|
@@ -140,7 +140,7 @@ EXAMPLES
|
|
|
140
140
|
$ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
143
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/config.ts)_
|
|
144
144
|
|
|
145
145
|
## `sanity-run blueprints deploy`
|
|
146
146
|
|
|
@@ -182,7 +182,7 @@ EXAMPLES
|
|
|
182
182
|
$ sanity-run blueprints deploy --fn-installer npm
|
|
183
183
|
```
|
|
184
184
|
|
|
185
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
185
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/deploy.ts)_
|
|
186
186
|
|
|
187
187
|
## `sanity-run blueprints destroy`
|
|
188
188
|
|
|
@@ -218,7 +218,7 @@ EXAMPLES
|
|
|
218
218
|
$ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
|
|
219
219
|
```
|
|
220
220
|
|
|
221
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
221
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/destroy.ts)_
|
|
222
222
|
|
|
223
223
|
## `sanity-run blueprints doctor`
|
|
224
224
|
|
|
@@ -250,7 +250,7 @@ EXAMPLES
|
|
|
250
250
|
$ sanity-run blueprints doctor --fix
|
|
251
251
|
```
|
|
252
252
|
|
|
253
|
-
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
253
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/doctor.ts)_
|
|
254
254
|
|
|
255
255
|
## `sanity-run blueprints info`
|
|
256
256
|
|
|
@@ -285,7 +285,7 @@ EXAMPLES
|
|
|
285
285
|
$ sanity-run blueprints info --project-id <id> --stack <name-or-id>
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
288
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/info.ts)_
|
|
289
289
|
|
|
290
290
|
## `sanity-run blueprints init [DIR]`
|
|
291
291
|
|
|
@@ -293,7 +293,7 @@ Initialize a Blueprint and create a remote Stack
|
|
|
293
293
|
|
|
294
294
|
```
|
|
295
295
|
USAGE
|
|
296
|
-
$ sanity-run blueprints init [DIR] [--json] [--validate-resources] [--
|
|
296
|
+
$ sanity-run blueprints init [DIR] [--json] [--validate-resources] [--dir <value>] [--example <value> |
|
|
297
297
|
--blueprint-type json|js|ts | --stack-id <value> | --stack-name <value>] [--project-id <value>] [--organization-id
|
|
298
298
|
<value>]
|
|
299
299
|
|
|
@@ -311,7 +311,6 @@ FLAGS
|
|
|
311
311
|
--stack-id=<value> Existing Stack ID used to scope local Blueprint
|
|
312
312
|
--stack-name=<value> Name to use for a new Stack provisioned during initialization
|
|
313
313
|
--[no-]validate-resources Validate resources
|
|
314
|
-
--verbose Verbose output
|
|
315
314
|
|
|
316
315
|
DESCRIPTION
|
|
317
316
|
Initialize a Blueprint and create a remote Stack
|
|
@@ -339,7 +338,7 @@ EXAMPLES
|
|
|
339
338
|
$ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
|
|
340
339
|
```
|
|
341
340
|
|
|
342
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
341
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/init.ts)_
|
|
343
342
|
|
|
344
343
|
## `sanity-run blueprints logs`
|
|
345
344
|
|
|
@@ -370,7 +369,7 @@ EXAMPLES
|
|
|
370
369
|
$ sanity-run blueprints logs --watch
|
|
371
370
|
```
|
|
372
371
|
|
|
373
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
372
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/logs.ts)_
|
|
374
373
|
|
|
375
374
|
## `sanity-run blueprints plan`
|
|
376
375
|
|
|
@@ -398,7 +397,7 @@ EXAMPLES
|
|
|
398
397
|
$ sanity-run blueprints plan
|
|
399
398
|
```
|
|
400
399
|
|
|
401
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
400
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/plan.ts)_
|
|
402
401
|
|
|
403
402
|
## `sanity-run blueprints stacks`
|
|
404
403
|
|
|
@@ -406,9 +405,11 @@ List remote Stack deployments for your project or organization
|
|
|
406
405
|
|
|
407
406
|
```
|
|
408
407
|
USAGE
|
|
409
|
-
$ sanity-run blueprints stacks [--json] [--validate-resources] [--project-id <value> | --organization-id <value>
|
|
408
|
+
$ sanity-run blueprints stacks [--json] [--validate-resources] [--project-id <value> | --organization-id <value> |
|
|
409
|
+
--include-projects]
|
|
410
410
|
|
|
411
411
|
FLAGS
|
|
412
|
+
--include-projects Include Stacks from all projects within the organization. Requires --organization-id.
|
|
412
413
|
--json Format output as json
|
|
413
414
|
--organization-id=<value> Sanity organization ID used to scope Blueprint and Stack
|
|
414
415
|
--project-id=<value> Sanity project ID used to scope Blueprint and Stack
|
|
@@ -422,15 +423,19 @@ DESCRIPTION
|
|
|
422
423
|
Use this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to
|
|
423
424
|
audit what's deployed across your project.
|
|
424
425
|
|
|
426
|
+
Use --include-projects with --organization-id to also list Stacks from all projects within the organization.
|
|
427
|
+
|
|
425
428
|
EXAMPLES
|
|
426
429
|
$ sanity-run blueprints stacks
|
|
427
430
|
|
|
428
431
|
$ sanity-run blueprints stacks --project-id <projectId>
|
|
429
432
|
|
|
430
433
|
$ sanity-run blueprints stacks --organization-id <organizationId>
|
|
434
|
+
|
|
435
|
+
$ sanity-run blueprints stacks --organization-id <organizationId> --include-projects
|
|
431
436
|
```
|
|
432
437
|
|
|
433
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
438
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/blueprints/stacks.ts)_
|
|
434
439
|
|
|
435
440
|
## `sanity-run functions add`
|
|
436
441
|
|
|
@@ -483,7 +488,7 @@ EXAMPLES
|
|
|
483
488
|
$ sanity-run functions add --name my-function --type document-create --type document-update --lang js
|
|
484
489
|
```
|
|
485
490
|
|
|
486
|
-
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
491
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/add.ts)_
|
|
487
492
|
|
|
488
493
|
## `sanity-run functions dev`
|
|
489
494
|
|
|
@@ -519,7 +524,7 @@ EXAMPLES
|
|
|
519
524
|
$ sanity-run functions dev --timeout 60
|
|
520
525
|
```
|
|
521
526
|
|
|
522
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
527
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/dev.ts)_
|
|
523
528
|
|
|
524
529
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
525
530
|
|
|
@@ -550,7 +555,7 @@ EXAMPLES
|
|
|
550
555
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
551
556
|
```
|
|
552
557
|
|
|
553
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
558
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/env/add.ts)_
|
|
554
559
|
|
|
555
560
|
## `sanity-run functions env list NAME`
|
|
556
561
|
|
|
@@ -578,7 +583,7 @@ EXAMPLES
|
|
|
578
583
|
$ sanity-run functions env list MyFunction
|
|
579
584
|
```
|
|
580
585
|
|
|
581
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
586
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/env/list.ts)_
|
|
582
587
|
|
|
583
588
|
## `sanity-run functions env remove NAME KEY`
|
|
584
589
|
|
|
@@ -608,7 +613,7 @@ EXAMPLES
|
|
|
608
613
|
$ sanity-run functions env remove MyFunction API_URL
|
|
609
614
|
```
|
|
610
615
|
|
|
611
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
616
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/env/remove.ts)_
|
|
612
617
|
|
|
613
618
|
## `sanity-run functions logs [NAME]`
|
|
614
619
|
|
|
@@ -650,7 +655,7 @@ EXAMPLES
|
|
|
650
655
|
$ sanity-run functions logs <name> --delete
|
|
651
656
|
```
|
|
652
657
|
|
|
653
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
658
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/logs.ts)_
|
|
654
659
|
|
|
655
660
|
## `sanity-run functions test [NAME]`
|
|
656
661
|
|
|
@@ -708,7 +713,7 @@ EXAMPLES
|
|
|
708
713
|
$ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
|
|
709
714
|
```
|
|
710
715
|
|
|
711
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
716
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.13.0/src/commands/functions/test.ts)_
|
|
712
717
|
|
|
713
718
|
## `sanity-run help [COMMAND]`
|
|
714
719
|
|
|
@@ -78,6 +78,23 @@ export declare function loadBlueprintFile(fileInfo: FileInfo): Promise<LoadedBlu
|
|
|
78
78
|
export declare function parseBlueprintContent(rawBlueprint: Record<string, unknown>, options: {
|
|
79
79
|
validateResources: boolean;
|
|
80
80
|
}): ParsedBlueprintContent;
|
|
81
|
+
/** Result of finding, loading, and parsing a blueprint file. */
|
|
82
|
+
export interface LocalBlueprint extends ParsedBlueprintContent {
|
|
83
|
+
fileInfo: FileInfo;
|
|
84
|
+
rawBlueprint: Record<string, unknown>;
|
|
85
|
+
module?: BlueprintModule;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Find, load, and parse a local blueprint file in one step.
|
|
89
|
+
* Does not read the config file or resolve IDs -- callers that need
|
|
90
|
+
* scope/stack information should use `readConfigFile` + `resolveIds` separately.
|
|
91
|
+
*
|
|
92
|
+
* @param blueprintPath Path to a blueprint file or directory containing one
|
|
93
|
+
* @param options.validateResources Whether to validate function resources
|
|
94
|
+
*/
|
|
95
|
+
export declare function loadAndParseBlueprint(blueprintPath?: string, options?: {
|
|
96
|
+
validateResources: boolean;
|
|
97
|
+
}): Promise<LocalBlueprint>;
|
|
81
98
|
/**
|
|
82
99
|
* Reads the blueprint file from disk and parses it.
|
|
83
100
|
* Resolves IDs from environment > blueprint module > config file.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { basename, dirname, extname } from 'node:path';
|
|
3
|
-
import { cwd
|
|
3
|
+
import { cwd } from 'node:process';
|
|
4
4
|
import { pathToFileURL } from 'node:url';
|
|
5
5
|
import blueprintParserValidator from '@sanity/blueprints-parser';
|
|
6
6
|
import * as find from 'empathic/find';
|
|
@@ -138,6 +138,27 @@ export function parseBlueprintContent(rawBlueprint, options) {
|
|
|
138
138
|
resources,
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Find, load, and parse a local blueprint file in one step.
|
|
143
|
+
* Does not read the config file or resolve IDs -- callers that need
|
|
144
|
+
* scope/stack information should use `readConfigFile` + `resolveIds` separately.
|
|
145
|
+
*
|
|
146
|
+
* @param blueprintPath Path to a blueprint file or directory containing one
|
|
147
|
+
* @param options.validateResources Whether to validate function resources
|
|
148
|
+
*/
|
|
149
|
+
export async function loadAndParseBlueprint(blueprintPath, options = { validateResources: true }) {
|
|
150
|
+
const fileInfo = findBlueprintFile(blueprintPath);
|
|
151
|
+
if (!fileInfo)
|
|
152
|
+
throw Error('Could not find Blueprint file! Use the `blueprints init` command.');
|
|
153
|
+
const loaded = await loadBlueprintFile(fileInfo);
|
|
154
|
+
const parsed = parseBlueprintContent(loaded.rawBlueprint, options);
|
|
155
|
+
return {
|
|
156
|
+
fileInfo,
|
|
157
|
+
rawBlueprint: loaded.rawBlueprint,
|
|
158
|
+
module: loaded.module,
|
|
159
|
+
...parsed,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
141
162
|
/**
|
|
142
163
|
* Reads the blueprint file from disk and parses it.
|
|
143
164
|
* Resolves IDs from environment > blueprint module > config file.
|
|
@@ -157,25 +178,8 @@ export async function readLocalBlueprint(logger, validate, blueprintPath) {
|
|
|
157
178
|
const blueprintConfig = readConfigFile(fileInfo.blueprintFilePath);
|
|
158
179
|
// 3. Resolve IDs: env > module > config
|
|
159
180
|
const resolved = resolveIds({
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
projectId: env.SANITY_PROJECT_ID,
|
|
163
|
-
stackId: env.SANITY_BLUEPRINT_STACK_ID,
|
|
164
|
-
},
|
|
165
|
-
module: loaded.module
|
|
166
|
-
? {
|
|
167
|
-
organizationId: loaded.module.organizationId,
|
|
168
|
-
projectId: loaded.module.projectId,
|
|
169
|
-
stackId: loaded.module.stackId,
|
|
170
|
-
}
|
|
171
|
-
: undefined,
|
|
172
|
-
config: blueprintConfig
|
|
173
|
-
? {
|
|
174
|
-
organizationId: blueprintConfig.organizationId,
|
|
175
|
-
projectId: blueprintConfig.projectId,
|
|
176
|
-
stackId: blueprintConfig.stackId,
|
|
177
|
-
}
|
|
178
|
-
: undefined,
|
|
181
|
+
module: loaded.module,
|
|
182
|
+
config: blueprintConfig,
|
|
179
183
|
});
|
|
180
184
|
// 4. Legacy stack ID inference: ST-<projectId>
|
|
181
185
|
let { stackId } = resolved;
|
|
@@ -17,12 +17,15 @@ export interface IdValues {
|
|
|
17
17
|
/**
|
|
18
18
|
* Sources to resolve IDs from, in descending priority.
|
|
19
19
|
* Each key maps to a source; the first non-empty value wins.
|
|
20
|
+
*
|
|
21
|
+
* - `env` defaults to reading SANITY_* process.env vars
|
|
22
|
+
* - `module` and `config` accept any object with `{organizationId?, projectId?, stackId?}`
|
|
20
23
|
*/
|
|
21
24
|
export interface IdSources {
|
|
22
|
-
flags?: IdValues;
|
|
23
|
-
env?: IdValues;
|
|
24
|
-
module?: IdValues;
|
|
25
|
-
config?: IdValues;
|
|
25
|
+
flags?: IdValues | null;
|
|
26
|
+
env?: IdValues | null;
|
|
27
|
+
module?: IdValues | null;
|
|
28
|
+
config?: IdValues | null;
|
|
26
29
|
}
|
|
27
30
|
export interface ResolvedIds {
|
|
28
31
|
organizationId?: string;
|
|
@@ -41,6 +44,8 @@ export interface ResolvedIds {
|
|
|
41
44
|
* Precedence: flags > env > module > config.
|
|
42
45
|
* Derives scopeType/scopeId from the resolved IDs (project > organization).
|
|
43
46
|
*
|
|
44
|
-
*
|
|
47
|
+
* Env vars are read from process.env by default (SANITY_ORGANIZATION_ID,
|
|
48
|
+
* SANITY_PROJECT_ID, SANITY_BLUEPRINT_STACK_ID). Pass `env` explicitly to
|
|
49
|
+
* override, or `null` to skip.
|
|
45
50
|
*/
|
|
46
|
-
export declare function resolveIds(sources
|
|
51
|
+
export declare function resolveIds(sources?: IdSources): ResolvedIds;
|
|
@@ -1,20 +1,30 @@
|
|
|
1
|
+
import { env as processEnv } from 'node:process';
|
|
1
2
|
/**
|
|
2
3
|
* Resolve organization, project, and stack IDs from a prioritized set of sources.
|
|
3
4
|
* Precedence: flags > env > module > config.
|
|
4
5
|
* Derives scopeType/scopeId from the resolved IDs (project > organization).
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
+
* Env vars are read from process.env by default (SANITY_ORGANIZATION_ID,
|
|
8
|
+
* SANITY_PROJECT_ID, SANITY_BLUEPRINT_STACK_ID). Pass `env` explicitly to
|
|
9
|
+
* override, or `null` to skip.
|
|
7
10
|
*/
|
|
8
|
-
export function resolveIds(sources) {
|
|
11
|
+
export function resolveIds(sources = {}) {
|
|
12
|
+
const envValues = sources.env !== undefined
|
|
13
|
+
? sources.env
|
|
14
|
+
: {
|
|
15
|
+
organizationId: processEnv.SANITY_ORGANIZATION_ID,
|
|
16
|
+
projectId: processEnv.SANITY_PROJECT_ID,
|
|
17
|
+
stackId: processEnv.SANITY_BLUEPRINT_STACK_ID,
|
|
18
|
+
};
|
|
9
19
|
const ordered = [
|
|
10
20
|
{ source: 'flags', values: sources.flags },
|
|
11
|
-
{ source: 'env', values:
|
|
21
|
+
{ source: 'env', values: envValues },
|
|
12
22
|
{ source: 'module', values: sources.module },
|
|
13
23
|
{ source: 'config', values: sources.config },
|
|
14
24
|
];
|
|
15
25
|
const result = { sources: {} };
|
|
16
26
|
for (const { source, values } of ordered) {
|
|
17
|
-
if (
|
|
27
|
+
if (values === null || values === undefined)
|
|
18
28
|
continue;
|
|
19
29
|
if (!result.organizationId && values.organizationId) {
|
|
20
30
|
result.organizationId = values.organizationId;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { Logger } from '../../utils/logger.js';
|
|
2
1
|
import type { InvokeExecutionOptions } from '../../utils/types.js';
|
|
3
|
-
export declare function dev(host: string, port: number,
|
|
2
|
+
export declare function dev(host: string, port: number, validateResources: boolean, executionOptions?: Partial<InvokeExecutionOptions>): Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { app } from '../../server/app.js';
|
|
2
|
-
export async function dev(host, port,
|
|
3
|
-
app(host, Number(port),
|
|
2
|
+
export async function dev(host, port, validateResources, executionOptions) {
|
|
3
|
+
app(host, Number(port), validateResources, executionOptions);
|
|
4
4
|
}
|
|
@@ -17,8 +17,9 @@ export interface Project {
|
|
|
17
17
|
interface ListProjectsResponse extends ActionResponse {
|
|
18
18
|
projects: Project[];
|
|
19
19
|
}
|
|
20
|
-
export declare function listProjects({ token, logger, }: {
|
|
20
|
+
export declare function listProjects({ token, organizationId, logger, }: {
|
|
21
21
|
token: string;
|
|
22
|
+
organizationId?: string;
|
|
22
23
|
logger: Logger;
|
|
23
24
|
}): Promise<ListProjectsResponse>;
|
|
24
25
|
interface GroupedProjectsByOrganizationResponse extends ActionResponse {
|
|
@@ -3,9 +3,12 @@ import { createTracedFetch } from '../../utils/traced-fetch.js';
|
|
|
3
3
|
const { populusApiUrl } = config;
|
|
4
4
|
export const projectsApiPath = `${populusApiUrl}v2021-06-07/projects`;
|
|
5
5
|
export const orgsApiPath = `${populusApiUrl}v2021-06-07/organizations`;
|
|
6
|
-
export async function listProjects({ token, logger, }) {
|
|
6
|
+
export async function listProjects({ token, organizationId, logger, }) {
|
|
7
7
|
const fetchFn = createTracedFetch(logger);
|
|
8
|
-
const
|
|
8
|
+
const url = organizationId
|
|
9
|
+
? `${projectsApiPath}?organizationId=${encodeURIComponent(organizationId)}`
|
|
10
|
+
: projectsApiPath;
|
|
11
|
+
const projectsFetch = await fetchFn(url, {
|
|
9
12
|
method: 'GET',
|
|
10
13
|
headers: {
|
|
11
14
|
Authorization: `Bearer ${token}`,
|
package/dist/baseCommands.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ import type { CoreResult } from './cores/index.js';
|
|
|
5
5
|
import type { AuthParams, ScopeType, Stack } from './utils/types.js';
|
|
6
6
|
export type Flags<T extends typeof Command> = Interfaces.InferredFlags<(typeof RuntimeCommand)['baseFlags'] & T['flags']>;
|
|
7
7
|
export type Args<T extends typeof Command> = Interfaces.InferredArgs<T['args']>;
|
|
8
|
+
export declare const pathFlagConfig: {
|
|
9
|
+
description: string;
|
|
10
|
+
env: string;
|
|
11
|
+
aliases: string[];
|
|
12
|
+
char: "p";
|
|
13
|
+
};
|
|
8
14
|
export declare const baseFlags: {
|
|
9
15
|
json: Interfaces.BooleanFlag<boolean>;
|
|
10
16
|
path: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
|
|
@@ -12,7 +18,9 @@ export declare const baseFlags: {
|
|
|
12
18
|
'validate-resources': Interfaces.BooleanFlag<boolean>;
|
|
13
19
|
verbose: Interfaces.BooleanFlag<boolean>;
|
|
14
20
|
};
|
|
15
|
-
export declare const
|
|
21
|
+
export declare const stackFlagConfig: {
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
16
24
|
export declare const projectIdFlagConfig: {
|
|
17
25
|
description: string;
|
|
18
26
|
aliases: string[];
|
|
@@ -21,11 +29,6 @@ export declare const organizationIdFlagConfig: {
|
|
|
21
29
|
description: string;
|
|
22
30
|
aliases: string[];
|
|
23
31
|
};
|
|
24
|
-
/**
|
|
25
|
-
* Unhides a flag by setting its hidden property to false
|
|
26
|
-
* Also makes oclif's types happy when destructuring the flag
|
|
27
|
-
*/
|
|
28
|
-
export declare function unhide<T>(flag: T): T;
|
|
29
32
|
/**
|
|
30
33
|
* Guarantees flags and args.
|
|
31
34
|
* Also centralizes baseFlags and enables oclif's built-in --json for all subclasses.
|
|
@@ -111,7 +114,7 @@ export declare abstract class ResolvedCommand<T extends typeof Command> extends
|
|
|
111
114
|
'validate-resources': Interfaces.BooleanFlag<boolean>;
|
|
112
115
|
verbose: Interfaces.BooleanFlag<boolean>;
|
|
113
116
|
};
|
|
114
|
-
protected
|
|
117
|
+
protected sanityToken: string;
|
|
115
118
|
protected blueprint: ReadBlueprintResult;
|
|
116
119
|
protected scopeType: ScopeType;
|
|
117
120
|
protected scopeId: string;
|
|
@@ -120,19 +123,3 @@ export declare abstract class ResolvedCommand<T extends typeof Command> extends
|
|
|
120
123
|
protected deployedStack: Stack;
|
|
121
124
|
init(): Promise<void>;
|
|
122
125
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Guarantees token and blueprint.
|
|
125
|
-
* @extends ResolvedCommand
|
|
126
|
-
*/
|
|
127
|
-
export declare abstract class LocalBlueprintCommand<T extends typeof Command> extends ResolvedCommand<T> {
|
|
128
|
-
static needs: Need[];
|
|
129
|
-
/** @deprecated Use `this.token` instead. */
|
|
130
|
-
protected get sanityToken(): string;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Guarantees token, scope, stackId, deployedStack, and blueprint.
|
|
134
|
-
* @extends LocalBlueprintCommand
|
|
135
|
-
*/
|
|
136
|
-
export declare abstract class DeployedStackCommand<T extends typeof Command> extends LocalBlueprintCommand<T> {
|
|
137
|
-
static needs: Need[];
|
|
138
|
-
}
|
package/dist/baseCommands.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// * https://oclif.io/docs/base_class
|
|
2
|
-
import { env } from 'node:process';
|
|
3
2
|
import { Command, CommandHelp, Flags as OclifFlags } from '@oclif/core';
|
|
4
3
|
import { findBlueprintFile, loadBlueprintFile, parseBlueprintContent, } from './actions/blueprints/blueprint.js';
|
|
5
4
|
import { backfillProjectBasedStackId, readConfigFile } from './actions/blueprints/config.js';
|
|
@@ -17,23 +16,25 @@ const CATCH_HINT_PATTERNS = [
|
|
|
17
16
|
// Add patterns here as needed, for example:
|
|
18
17
|
// [/scope/i, (bin) => [`Run \`npx ${bin} blueprints promote\` to change the Stack scope.`]],
|
|
19
18
|
];
|
|
20
|
-
const
|
|
19
|
+
export const pathFlagConfig = {
|
|
20
|
+
description: 'Path to a Blueprint file or directory containing one',
|
|
21
|
+
env: 'SANITY_BLUEPRINT_PATH',
|
|
22
|
+
aliases: ['blueprint-path'],
|
|
23
|
+
char: 'p',
|
|
24
|
+
};
|
|
21
25
|
export const baseFlags = {
|
|
22
26
|
json: OclifFlags.boolean({
|
|
23
27
|
// override defaults from oclif's built-in --json flag
|
|
24
28
|
description: 'Format output as json',
|
|
25
29
|
}),
|
|
26
30
|
path: OclifFlags.string({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
aliases: ['blueprint-path'],
|
|
30
|
-
char: 'p',
|
|
31
|
-
hidden,
|
|
31
|
+
...pathFlagConfig,
|
|
32
|
+
hidden: true,
|
|
32
33
|
}),
|
|
33
34
|
trace: OclifFlags.boolean({
|
|
34
35
|
description: 'Trace output',
|
|
35
36
|
default: false,
|
|
36
|
-
hidden,
|
|
37
|
+
hidden: true,
|
|
37
38
|
}),
|
|
38
39
|
'validate-resources': OclifFlags.boolean({
|
|
39
40
|
description: 'Validate resources',
|
|
@@ -43,13 +44,12 @@ export const baseFlags = {
|
|
|
43
44
|
verbose: OclifFlags.boolean({
|
|
44
45
|
description: 'Verbose output',
|
|
45
46
|
default: false,
|
|
46
|
-
hidden,
|
|
47
|
+
hidden: true,
|
|
47
48
|
}),
|
|
48
49
|
};
|
|
49
|
-
export const
|
|
50
|
+
export const stackFlagConfig = {
|
|
50
51
|
description: 'Stack name or ID to use instead of the locally configured Stack',
|
|
51
|
-
|
|
52
|
-
});
|
|
52
|
+
};
|
|
53
53
|
export const projectIdFlagConfig = {
|
|
54
54
|
description: 'Sanity project ID used to scope Blueprint and Stack',
|
|
55
55
|
aliases: ['project', 'projectId'],
|
|
@@ -58,13 +58,6 @@ export const organizationIdFlagConfig = {
|
|
|
58
58
|
description: 'Sanity organization ID used to scope Blueprint and Stack',
|
|
59
59
|
aliases: ['organization', 'organizationId', 'org'],
|
|
60
60
|
};
|
|
61
|
-
/**
|
|
62
|
-
* Unhides a flag by setting its hidden property to false
|
|
63
|
-
* Also makes oclif's types happy when destructuring the flag
|
|
64
|
-
*/
|
|
65
|
-
export function unhide(flag) {
|
|
66
|
-
return { ...flag, hidden: false };
|
|
67
|
-
}
|
|
68
61
|
/**
|
|
69
62
|
* Guarantees flags and args.
|
|
70
63
|
* Also centralizes baseFlags and enables oclif's built-in --json for all subclasses.
|
|
@@ -182,12 +175,12 @@ export class ResolvedCommand extends RuntimeCommand {
|
|
|
182
175
|
static needs = [];
|
|
183
176
|
static baseFlags = {
|
|
184
177
|
...baseFlags,
|
|
185
|
-
stack:
|
|
178
|
+
stack: OclifFlags.string({ ...stackFlagConfig, hidden: true }),
|
|
186
179
|
'project-id': OclifFlags.string({ ...projectIdFlagConfig, hidden: true }),
|
|
187
180
|
'organization-id': OclifFlags.string({ ...organizationIdFlagConfig, hidden: true }),
|
|
188
181
|
};
|
|
189
182
|
// Populated by init() according to `needs`
|
|
190
|
-
|
|
183
|
+
sanityToken;
|
|
191
184
|
blueprint;
|
|
192
185
|
scopeType;
|
|
193
186
|
scopeId;
|
|
@@ -213,31 +206,14 @@ export class ResolvedCommand extends RuntimeCommand {
|
|
|
213
206
|
suggestions: ['Run `npx @sanity/cli login` to authenticate.'],
|
|
214
207
|
});
|
|
215
208
|
}
|
|
216
|
-
this.
|
|
209
|
+
this.sanityToken = check.value;
|
|
217
210
|
}
|
|
218
|
-
// 2.
|
|
219
|
-
const flagIds = {
|
|
220
|
-
projectId: this.flags['project-id'],
|
|
221
|
-
organizationId: this.flags['organization-id'],
|
|
222
|
-
};
|
|
223
|
-
const envIds = {
|
|
224
|
-
organizationId: env.SANITY_ORGANIZATION_ID,
|
|
225
|
-
projectId: env.SANITY_PROJECT_ID,
|
|
226
|
-
stackId: env.SANITY_BLUEPRINT_STACK_ID,
|
|
227
|
-
};
|
|
228
|
-
// Try to read the config file (cheap single-file JSON read).
|
|
211
|
+
// 2. Read config file (cheap single-file JSON read).
|
|
229
212
|
// Anchor to --path flag or the blueprint file location if found, else cwd.
|
|
230
213
|
const blueprintFileInfo = findBlueprintFile(this.flags.path);
|
|
231
214
|
const blueprintConfig = readConfigFile(blueprintFileInfo?.blueprintFilePath);
|
|
232
|
-
const configIds = blueprintConfig
|
|
233
|
-
? {
|
|
234
|
-
organizationId: blueprintConfig.organizationId,
|
|
235
|
-
projectId: blueprintConfig.projectId,
|
|
236
|
-
stackId: blueprintConfig.stackId,
|
|
237
|
-
}
|
|
238
|
-
: undefined;
|
|
239
215
|
// 3. Blueprint (if needed)
|
|
240
|
-
let
|
|
216
|
+
let blueprintModule;
|
|
241
217
|
if (needsBlueprint) {
|
|
242
218
|
if (!blueprintFileInfo) {
|
|
243
219
|
this.error('Could not find Blueprint file! Use the `blueprints init` command.', {
|
|
@@ -260,13 +236,7 @@ export class ResolvedCommand extends RuntimeCommand {
|
|
|
260
236
|
],
|
|
261
237
|
});
|
|
262
238
|
}
|
|
263
|
-
|
|
264
|
-
moduleIds = {
|
|
265
|
-
organizationId: loaded.module.organizationId,
|
|
266
|
-
projectId: loaded.module.projectId,
|
|
267
|
-
stackId: loaded.module.stackId,
|
|
268
|
-
};
|
|
269
|
-
}
|
|
239
|
+
blueprintModule = loaded.module;
|
|
270
240
|
// Assemble the full ReadBlueprintResult -- will be completed with resolved IDs below
|
|
271
241
|
this.blueprint = {
|
|
272
242
|
fileInfo: blueprintFileInfo,
|
|
@@ -277,10 +247,12 @@ export class ResolvedCommand extends RuntimeCommand {
|
|
|
277
247
|
}
|
|
278
248
|
// 4. Resolve IDs
|
|
279
249
|
const resolved = resolveIds({
|
|
280
|
-
flags:
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
250
|
+
flags: {
|
|
251
|
+
projectId: this.flags['project-id'],
|
|
252
|
+
organizationId: this.flags['organization-id'],
|
|
253
|
+
},
|
|
254
|
+
module: blueprintModule,
|
|
255
|
+
config: blueprintConfig,
|
|
284
256
|
});
|
|
285
257
|
// Legacy stack ID inference (only when we have a blueprint file path for the write side-effect)
|
|
286
258
|
if (!resolved.stackId && resolved.projectId && blueprintFileInfo) {
|
|
@@ -328,7 +300,7 @@ export class ResolvedCommand extends RuntimeCommand {
|
|
|
328
300
|
const stackOverride = this.flags.stack;
|
|
329
301
|
if (stackOverride) {
|
|
330
302
|
const auth = {
|
|
331
|
-
token: this.
|
|
303
|
+
token: this.sanityToken,
|
|
332
304
|
scopeType: this.scopeType,
|
|
333
305
|
scopeId: this.scopeId,
|
|
334
306
|
};
|
|
@@ -345,7 +317,7 @@ export class ResolvedCommand extends RuntimeCommand {
|
|
|
345
317
|
}
|
|
346
318
|
// 7. Auth
|
|
347
319
|
if (needsScope) {
|
|
348
|
-
this.auth = { token: this.
|
|
320
|
+
this.auth = { token: this.sanityToken, scopeType: this.scopeType, scopeId: this.scopeId };
|
|
349
321
|
}
|
|
350
322
|
// 8. Deployed Stack
|
|
351
323
|
if (needsDeployedStack) {
|
|
@@ -364,24 +336,3 @@ export class ResolvedCommand extends RuntimeCommand {
|
|
|
364
336
|
}
|
|
365
337
|
}
|
|
366
338
|
}
|
|
367
|
-
// ---------------------------------------------------------------------------
|
|
368
|
-
// Legacy base classes -- thin wrappers around ResolvedCommand
|
|
369
|
-
// ---------------------------------------------------------------------------
|
|
370
|
-
/**
|
|
371
|
-
* Guarantees token and blueprint.
|
|
372
|
-
* @extends ResolvedCommand
|
|
373
|
-
*/
|
|
374
|
-
export class LocalBlueprintCommand extends ResolvedCommand {
|
|
375
|
-
static needs = ['token', 'blueprint'];
|
|
376
|
-
/** @deprecated Use `this.token` instead. */
|
|
377
|
-
get sanityToken() {
|
|
378
|
-
return this.token;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* Guarantees token, scope, stackId, deployedStack, and blueprint.
|
|
383
|
-
* @extends LocalBlueprintCommand
|
|
384
|
-
*/
|
|
385
|
-
export class DeployedStackCommand extends LocalBlueprintCommand {
|
|
386
|
-
static needs = ['deployedStack', 'blueprint'];
|
|
387
|
-
}
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* @deprecated Use `functions add` instead.
|
|
4
4
|
* We're in the process of deprecating the `blueprints add` command.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
export default class AddCommand extends
|
|
6
|
+
import { ResolvedCommand } from '../../baseCommands.js';
|
|
7
|
+
export default class AddCommand extends ResolvedCommand<typeof AddCommand> {
|
|
8
|
+
static needs: readonly ["blueprint"];
|
|
8
9
|
static summary: string;
|
|
9
10
|
static description: string;
|
|
10
11
|
static examples: string[];
|