@sanity/runtime-cli 10.11.1 → 10.11.3

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 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/10.11.1 linux-x64 node-v22.20.0
23
+ @sanity/runtime-cli/10.11.3 linux-x64 node-v22.20.0
24
24
  $ sanity-run --help [COMMAND]
25
25
  USAGE
26
26
  $ sanity-run COMMAND
@@ -89,7 +89,7 @@ EXAMPLES
89
89
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
90
90
  ```
91
91
 
92
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/add.ts)_
92
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/add.ts)_
93
93
 
94
94
  ## `sanity-run blueprints config`
95
95
 
@@ -120,7 +120,7 @@ EXAMPLES
120
120
  $ sanity-run blueprints config --edit --project-id <projectId> --stack-id <stackId>
121
121
  ```
122
122
 
123
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/config.ts)_
123
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/config.ts)_
124
124
 
125
125
  ## `sanity-run blueprints deploy`
126
126
 
@@ -142,7 +142,7 @@ EXAMPLES
142
142
  $ sanity-run blueprints deploy --no-wait
143
143
  ```
144
144
 
145
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/deploy.ts)_
145
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/deploy.ts)_
146
146
 
147
147
  ## `sanity-run blueprints destroy`
148
148
 
@@ -167,7 +167,7 @@ EXAMPLES
167
167
  $ sanity-run blueprints destroy --stack-id <stackId> --project-id <projectId> --force --no-wait
168
168
  ```
169
169
 
170
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/destroy.ts)_
170
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/destroy.ts)_
171
171
 
172
172
  ## `sanity-run blueprints doctor`
173
173
 
@@ -185,7 +185,7 @@ DESCRIPTION
185
185
  Diagnose potential issues with Blueprint configuration
186
186
  ```
187
187
 
188
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/doctor.ts)_
188
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/doctor.ts)_
189
189
 
190
190
  ## `sanity-run blueprints info`
191
191
 
@@ -207,7 +207,7 @@ EXAMPLES
207
207
  $ sanity-run blueprints info --stack-id <stackId>
208
208
  ```
209
209
 
210
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/info.ts)_
210
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/info.ts)_
211
211
 
212
212
  ## `sanity-run blueprints init [DIR]`
213
213
 
@@ -245,7 +245,7 @@ EXAMPLES
245
245
  $ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
246
246
  ```
247
247
 
248
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/init.ts)_
248
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/init.ts)_
249
249
 
250
250
  ## `sanity-run blueprints logs`
251
251
 
@@ -267,7 +267,7 @@ EXAMPLES
267
267
  $ sanity-run blueprints logs --watch
268
268
  ```
269
269
 
270
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/logs.ts)_
270
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/logs.ts)_
271
271
 
272
272
  ## `sanity-run blueprints plan`
273
273
 
@@ -284,7 +284,7 @@ EXAMPLES
284
284
  $ sanity-run blueprints plan
285
285
  ```
286
286
 
287
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/plan.ts)_
287
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/plan.ts)_
288
288
 
289
289
  ## `sanity-run blueprints stacks`
290
290
 
@@ -306,7 +306,7 @@ EXAMPLES
306
306
  $ sanity-run blueprints stacks --project-id <projectId>
307
307
  ```
308
308
 
309
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/blueprints/stacks.ts)_
309
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/blueprints/stacks.ts)_
310
310
 
311
311
  ## `sanity-run functions dev`
312
312
 
@@ -328,7 +328,7 @@ EXAMPLES
328
328
  $ sanity-run functions dev --port 8974
329
329
  ```
330
330
 
331
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/functions/dev.ts)_
331
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/functions/dev.ts)_
332
332
 
333
333
  ## `sanity-run functions env add NAME KEY VALUE`
334
334
 
@@ -350,7 +350,7 @@ EXAMPLES
350
350
  $ sanity-run functions env add MyFunction API_URL https://api.example.com/
351
351
  ```
352
352
 
353
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/functions/env/add.ts)_
353
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/functions/env/add.ts)_
354
354
 
355
355
  ## `sanity-run functions env list NAME`
356
356
 
@@ -370,7 +370,7 @@ EXAMPLES
370
370
  $ sanity-run functions env list MyFunction
371
371
  ```
372
372
 
373
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/functions/env/list.ts)_
373
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/functions/env/list.ts)_
374
374
 
375
375
  ## `sanity-run functions env remove NAME KEY`
376
376
 
@@ -391,7 +391,7 @@ EXAMPLES
391
391
  $ sanity-run functions env remove MyFunction API_URL
392
392
  ```
393
393
 
394
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/functions/env/remove.ts)_
394
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/functions/env/remove.ts)_
395
395
 
396
396
  ## `sanity-run functions logs NAME`
397
397
 
@@ -425,7 +425,7 @@ EXAMPLES
425
425
  $ sanity-run functions logs <name> --delete
426
426
  ```
427
427
 
428
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/functions/logs.ts)_
428
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/functions/logs.ts)_
429
429
 
430
430
  ## `sanity-run functions test NAME`
431
431
 
@@ -472,7 +472,7 @@ EXAMPLES
472
472
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
473
473
  ```
474
474
 
475
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.1/src/commands/functions/test.ts)_
475
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v10.11.3/src/commands/functions/test.ts)_
476
476
 
477
477
  ## `sanity-run help [COMMAND]`
478
478
 
@@ -6,7 +6,7 @@ import { findUpSync } from 'find-up';
6
6
  import { createJiti } from 'jiti';
7
7
  import { isLocalFunctionResource } from '../../utils/types.js';
8
8
  import { validateFunctionResource } from '../../utils/validate/resource.js';
9
- import { readConfigFile } from './config.js';
9
+ import { backfillOrganizationId, readConfigFile } from './config.js';
10
10
  const SUPPORTED_FILE_EXTENSIONS = ['.json', '.js', '.mjs', '.ts'];
11
11
  let SUPPORTED_FILE_NAMES = SUPPORTED_FILE_EXTENSIONS.map((ext) => `blueprint${ext}`);
12
12
  SUPPORTED_FILE_NAMES = [
@@ -132,6 +132,16 @@ export async function readLocalBlueprint(blueprintPath) {
132
132
  const { SANITY_ORGANIZATION_ID: envOrganizationId, SANITY_PROJECT_ID: envProjectId, SANITY_BLUEPRINT_STACK_ID: envStackId, } = env;
133
133
  const configIds = readConfigFile(foundFilePath);
134
134
  const configPath = configIds?.configPath;
135
+ // passively heal config on disk by getting organizationId from projectId
136
+ if (configIds && !configIds.organizationId && configIds.projectId) {
137
+ try {
138
+ await backfillOrganizationId({
139
+ projectId: configIds.projectId,
140
+ blueprintFilePath: foundFilePath,
141
+ });
142
+ }
143
+ catch { }
144
+ }
135
145
  let organizationId;
136
146
  if (envOrganizationId)
137
147
  organizationId = envOrganizationId;
@@ -10,8 +10,17 @@ export declare function writeConfigFile({ blueprintFilePath, organizationId, pro
10
10
  stackId?: string;
11
11
  } & ({
12
12
  organizationId: string;
13
- projectId?: never;
13
+ projectId?: string;
14
14
  } | {
15
15
  projectId: string;
16
- organizationId?: never;
16
+ organizationId?: string;
17
17
  })): void;
18
+ /**
19
+ * Find and write an organizationId to the config file by getting it from the projectId
20
+ * @throws {Error} if unable to fetch project
21
+ * @returns {Promise<string>} the discovered organizationId
22
+ */
23
+ export declare function backfillOrganizationId({ blueprintFilePath, projectId, }: {
24
+ blueprintFilePath: string;
25
+ projectId: string;
26
+ }): Promise<string>;
@@ -1,7 +1,8 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
3
  import { cwd } from 'node:process';
4
- import { BLUEPRINT_CONFIG_FILE, BLUEPRINT_CONFIG_VERSION, BLUEPRINT_DIR } from '../../config.js';
4
+ import config, { BLUEPRINT_CONFIG_FILE, BLUEPRINT_CONFIG_VERSION, BLUEPRINT_DIR, } from '../../config.js';
5
+ import { getProject } from '../sanity/projects.js';
5
6
  export function readConfigFile(blueprintFilePath) {
6
7
  const blueprintDir = blueprintFilePath ? dirname(blueprintFilePath) : cwd();
7
8
  const configPath = join(blueprintDir, BLUEPRINT_DIR, BLUEPRINT_CONFIG_FILE);
@@ -32,10 +33,39 @@ export function writeConfigFile({ blueprintFilePath, organizationId, projectId,
32
33
  // config broken, start fresh
33
34
  }
34
35
  }
35
- config.organizationId = organizationId;
36
- config.projectId = projectId;
37
- config.stackId = stackId;
36
+ if (organizationId)
37
+ config.organizationId = organizationId;
38
+ if (projectId)
39
+ config.projectId = projectId;
40
+ if (stackId)
41
+ config.stackId = stackId;
38
42
  config.blueprintConfigVersion = BLUEPRINT_CONFIG_VERSION;
39
43
  config.updatedAt = Date.now();
40
44
  writeFileSync(configPath, JSON.stringify(config, null, 2));
41
45
  }
46
+ /**
47
+ * Find and write an organizationId to the config file by getting it from the projectId
48
+ * @throws {Error} if unable to fetch project
49
+ * @returns {Promise<string>} the discovered organizationId
50
+ */
51
+ export async function backfillOrganizationId({ blueprintFilePath, projectId, }) {
52
+ const token = config.token;
53
+ if (!token)
54
+ throw new Error('No token found');
55
+ let organizationId;
56
+ try {
57
+ const response = await getProject({ token, scopeType: 'project', scopeId: projectId });
58
+ if (!response.ok)
59
+ throw new Error('Failed to get project');
60
+ if (!response.project)
61
+ throw new Error('No project found');
62
+ organizationId = response.project.organizationId;
63
+ }
64
+ catch (error) {
65
+ throw new Error('Failed to backfill organizationId', { cause: error });
66
+ }
67
+ if (!organizationId)
68
+ throw new Error('No organizationId found');
69
+ writeConfigFile({ blueprintFilePath, organizationId });
70
+ return organizationId;
71
+ }
@@ -16,6 +16,7 @@ export default class ConfigCommand extends BlueprintCommand {
16
16
  aliases: ['test', 'validate'],
17
17
  description: 'Validate the configuration',
18
18
  default: false,
19
+ deprecated: true,
19
20
  }),
20
21
  edit: Flags.boolean({
21
22
  char: 'e',
@@ -33,6 +33,10 @@ export async function blueprintConfigCore(options) {
33
33
  // no edit or test: return success
34
34
  if (!editConfig && !testConfig)
35
35
  return { success: true };
36
+ // warn about deprecated test-config flag
37
+ if (testConfig) {
38
+ log(warn(`The "test" flag is deprecated. Use "${bin} blueprints doctor" instead.`));
39
+ }
36
40
  // testing without editing
37
41
  if (testConfig && !editConfig) {
38
42
  if (configStackId && configProjectId) {
@@ -181,6 +181,7 @@
181
181
  "validate"
182
182
  ],
183
183
  "char": "t",
184
+ "deprecated": true,
184
185
  "description": "Validate the configuration",
185
186
  "name": "test-config",
186
187
  "allowNo": false,
@@ -1177,5 +1178,5 @@
1177
1178
  ]
1178
1179
  }
1179
1180
  },
1180
- "version": "10.11.1"
1181
+ "version": "10.11.3"
1181
1182
  }
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": "10.11.1",
4
+ "version": "10.11.3",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",