@sanity/runtime-cli 10.10.0 → 10.11.1

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.
Files changed (46) hide show
  1. package/README.md +35 -16
  2. package/dist/actions/blueprints/config.d.ts +1 -1
  3. package/dist/actions/blueprints/config.js +2 -11
  4. package/dist/actions/blueprints/index.js +14 -5
  5. package/dist/actions/blueprints/stacks.d.ts +5 -3
  6. package/dist/actions/blueprints/stacks.js +11 -4
  7. package/dist/actions/sanity/projects.d.ts +4 -2
  8. package/dist/actions/sanity/projects.js +5 -2
  9. package/dist/commands/blueprints/doctor.d.ts +10 -0
  10. package/dist/commands/blueprints/doctor.js +28 -0
  11. package/dist/cores/blueprints/config.js +11 -4
  12. package/dist/cores/blueprints/deploy.js +10 -6
  13. package/dist/cores/blueprints/destroy.js +2 -2
  14. package/dist/cores/blueprints/doctor.d.ts +9 -0
  15. package/dist/cores/blueprints/doctor.js +188 -0
  16. package/dist/cores/blueprints/init.js +17 -8
  17. package/dist/cores/blueprints/plan.js +4 -1
  18. package/dist/cores/blueprints/stacks.js +1 -1
  19. package/dist/cores/index.d.ts +4 -1
  20. package/dist/cores/index.js +1 -1
  21. package/dist/utils/display/prompt.js +3 -2
  22. package/dist/utils/get-headers.d.ts +2 -2
  23. package/dist/utils/get-headers.js +5 -13
  24. package/dist/utils/types.d.ts +6 -3
  25. package/dist/utils/validate/resource.js +3 -3
  26. package/oclif.manifest.json +37 -1
  27. package/package.json +2 -1
  28. package/dist/server/static/api.d.ts +0 -24
  29. package/dist/server/static/components/api-base.d.ts +0 -20
  30. package/dist/server/static/components/clear-button.d.ts +0 -6
  31. package/dist/server/static/components/codemirror-theme.d.ts +0 -6
  32. package/dist/server/static/components/console-panel.d.ts +0 -1
  33. package/dist/server/static/components/fetch-button.d.ts +0 -7
  34. package/dist/server/static/components/filters.d.ts +0 -1
  35. package/dist/server/static/components/function-list.d.ts +0 -1
  36. package/dist/server/static/components/help-button.d.ts +0 -3
  37. package/dist/server/static/components/network-spinner.d.ts +0 -1
  38. package/dist/server/static/components/payload-panel.d.ts +0 -1
  39. package/dist/server/static/components/response-panel.d.ts +0 -1
  40. package/dist/server/static/components/rule-panel.d.ts +0 -1
  41. package/dist/server/static/components/run-panel.d.ts +0 -1
  42. package/dist/server/static/components/select-dropdown.d.ts +0 -1
  43. package/dist/server/static/components/toggle-switch.d.ts +0 -11
  44. package/dist/server/static/hot-reload.d.ts +0 -1
  45. package/dist/server/static/vendor/vendor.bundle.d.ts +0 -2008
  46. package/dist/utils/child-process-wrapper.d.ts +0 -1
@@ -38,7 +38,8 @@ export async function blueprintInitCore(options) {
38
38
  // * 3. create empty stack with name from example name
39
39
  const stack = await createEmptyStack({
40
40
  token,
41
- projectId,
41
+ scopeType: 'project',
42
+ scopeId: projectId,
42
43
  name: `example-${flagExample}`,
43
44
  projectBased: false,
44
45
  });
@@ -106,17 +107,17 @@ export async function blueprintInitCore(options) {
106
107
  // using --stack-name gets around "LAUNCH LIMIT: 1 Stack per Project"
107
108
  const stack = await createEmptyStack({
108
109
  token,
109
- projectId,
110
+ scopeType: 'project',
111
+ scopeId: projectId,
110
112
  name: flagStackName,
111
113
  projectBased: false,
112
114
  });
113
115
  stackId = stack.id;
114
116
  }
115
- const auth = { token: token, projectId };
116
117
  if (!stackId) {
117
118
  // LAUNCH LIMIT: 1 Stack per Project - do not prompt for Stack, just create one
118
119
  if (LAUNCH_LIMIT_STACK_PER_PROJECT) {
119
- await createProjectBasedStack(auth, token, log);
120
+ await createProjectBasedStack({ token, scopeType: 'project', scopeId: projectId }, log);
120
121
  // do not set stackId, to avoid saving it to the config file
121
122
  }
122
123
  else {
@@ -175,10 +176,17 @@ async function promptForBlueprintType() {
175
176
  return pickedBlueprintsType;
176
177
  }
177
178
  // LAUNCH LIMIT: 1 Stack per Project - create exclusive stack for project
178
- async function createProjectBasedStack(auth, token, log) {
179
- const { projectId } = auth;
179
+ async function createProjectBasedStack(auth, log) {
180
+ if (auth.scopeType !== 'project') {
181
+ throw new Error('Auth must be for a project');
182
+ }
183
+ const { scopeId: projectId, token } = auth;
180
184
  // get project
181
- const { ok: projectOk, project } = await getProject(auth);
185
+ const { ok: projectOk, project } = await getProject({
186
+ token: auth.token,
187
+ scopeType: 'project',
188
+ scopeId: projectId,
189
+ });
182
190
  if (!projectOk) {
183
191
  throw new Error('Failed to find Project while creating Stack');
184
192
  }
@@ -196,7 +204,8 @@ async function createProjectBasedStack(auth, token, log) {
196
204
  // if not, create a stack
197
205
  const stack = await createEmptyStack({
198
206
  token,
199
- projectId,
207
+ scopeType: 'project',
208
+ scopeId: projectId,
200
209
  name: projectDisplayName,
201
210
  });
202
211
  return stack;
@@ -7,7 +7,10 @@ export async function blueprintPlanCore(options) {
7
7
  log(`${chalk.bold.blueBright('Blueprint Deployment Plan')} ${chalk.dim(`(${fileInfo.fileName})`)}`);
8
8
  log(formatResourceTree(parsedBlueprint.resources));
9
9
  if (token && projectId && stackId) {
10
- const stackResponse = await getStack({ stackId, auth: { token, projectId } });
10
+ const stackResponse = await getStack({
11
+ auth: { token, scopeType: 'project', scopeId: projectId },
12
+ stackId,
13
+ });
11
14
  if (!stackResponse.ok) {
12
15
  log(chalk.dim('Unable to retrieve live deployment for comparison'));
13
16
  }
@@ -11,7 +11,7 @@ export async function blueprintStacksCore(options) {
11
11
  return { success: false, error: 'No Project ID provided' };
12
12
  }
13
13
  try {
14
- const { ok, stacks, error } = await listStacks({ token, projectId });
14
+ const { ok, stacks, error } = await listStacks({ token, scopeType: 'project', scopeId: projectId });
15
15
  if (!ok)
16
16
  return { success: false, error: error || 'Failed to list stacks' };
17
17
  if (!stacks || stacks.length === 0) {
@@ -19,6 +19,9 @@ export interface DeployedBlueprintConfig extends BlueprintConfig {
19
19
  deployedStack: Stack;
20
20
  }
21
21
  export type CoreResult = {
22
+ /** Arbitrary data for isolated testing */
23
+ data?: Record<string, unknown>;
24
+ } & ({
22
25
  /** Something went wrong. */
23
26
  success: false;
24
27
  /** The error message, if the operation failed. */
@@ -30,7 +33,7 @@ export type CoreResult = {
30
33
  /** The streaming function, if the operation is streaming. */
31
34
  streaming?: Promise<void>;
32
35
  error?: never;
33
- };
36
+ });
34
37
  type InitBlueprintConfigParams = {
35
38
  bin: string;
36
39
  log: (msg: string) => void;
@@ -48,7 +48,7 @@ export async function initDeployedBlueprintConfig(config) {
48
48
  if (!stackId)
49
49
  return { ok: false, error: 'Missing deployment configuration for Blueprint' };
50
50
  }
51
- const auth = { token: config.token, projectId };
51
+ const auth = { token: config.token, scopeType: 'project', scopeId: projectId };
52
52
  const stackResponse = await getStack({ stackId, auth });
53
53
  if (!stackResponse.ok) {
54
54
  config.log(`Could not retrieve deployment info for ${niceId(stackId)}. Was it destroyed?`);
@@ -54,7 +54,7 @@ export async function promptForProject({ token, knownOrganizationId, knownProjec
54
54
  return pickedProject;
55
55
  }
56
56
  export async function promptForStackId({ projectId, token, }) {
57
- const { ok: stacksOk, error: stacksErr, stacks } = await listStacks({ token, projectId });
57
+ const { ok: stacksOk, error: stacksErr, stacks, } = await listStacks({ token, scopeType: 'project', scopeId: projectId });
58
58
  if (!stacksOk) {
59
59
  throw new Error(stacksErr || 'Failed to list Stacks');
60
60
  }
@@ -87,7 +87,8 @@ export async function promptForStackId({ projectId, token, }) {
87
87
  ]);
88
88
  const stack = await createEmptyStack({
89
89
  token,
90
- projectId,
90
+ scopeType: 'project',
91
+ scopeId: projectId,
91
92
  name: stackName,
92
93
  });
93
94
  return stack.id;
@@ -1,9 +1,9 @@
1
1
  import type { AuthParams } from './types.js';
2
- export default function getHeaders({ token, projectId }: AuthParams): {
2
+ export default function getHeaders({ token, scopeId, scopeType }: AuthParams): {
3
3
  Accept: string;
4
4
  'Content-Type': string;
5
5
  Authorization: string;
6
- 'X-Sanity-Scope-Type': string;
6
+ 'X-Sanity-Scope-Type': import("./types.js").ScopeType;
7
7
  'X-Sanity-Scope-Id': string;
8
8
  'User-Agent': string;
9
9
  };
@@ -1,20 +1,12 @@
1
- const userAgent = await getUserAgent();
2
- async function getUserAgent() {
3
- try {
4
- const pkg = await (await import('../../package.json', { with: { type: 'json' } })).default;
5
- return `${pkg.name}@${pkg.version}`;
6
- }
7
- catch {
8
- return 'unknown@0.0.0';
9
- }
10
- }
11
- export default function getHeaders({ token, projectId }) {
1
+ import pkg from '../../package.json' with { type: 'json' };
2
+ const userAgent = `${pkg.name}@${pkg.version}`;
3
+ export default function getHeaders({ token, scopeId, scopeType }) {
12
4
  return {
13
5
  Accept: 'application/json',
14
6
  'Content-Type': 'application/json',
15
7
  Authorization: `Bearer ${token}`,
16
- 'X-Sanity-Scope-Type': 'project',
17
- 'X-Sanity-Scope-Id': projectId,
8
+ 'X-Sanity-Scope-Type': scopeType,
9
+ 'X-Sanity-Scope-Id': scopeId,
18
10
  'User-Agent': userAgent,
19
11
  };
20
12
  }
@@ -11,7 +11,8 @@ export type Result<T, E = string> = {
11
11
  /** @internal */
12
12
  export interface AuthParams {
13
13
  token: string;
14
- projectId: string;
14
+ scopeType: ScopeType;
15
+ scopeId: string;
15
16
  }
16
17
  /** @internal */
17
18
  export interface GroqRule {
@@ -55,7 +56,8 @@ export interface Stack {
55
56
  id: string;
56
57
  name: string;
57
58
  displayName: string;
58
- projectId: string;
59
+ scopeType: ScopeType;
60
+ scopeId: string;
59
61
  resources: Array<DeployedResource>;
60
62
  createdAt?: string;
61
63
  updatedAt?: string;
@@ -71,7 +73,8 @@ export interface StackOperation {
71
73
  /** @internal */
72
74
  export interface StackMutation {
73
75
  name: string;
74
- projectId: string;
76
+ scopeType: ScopeType;
77
+ scopeId: string;
75
78
  document: Blueprint;
76
79
  useProjectBasedId?: boolean;
77
80
  }
@@ -1,7 +1,7 @@
1
1
  import { BlueprintParserErrorType } from '../types.js';
2
2
  export function validateFunctionName(name) {
3
- // must be 6+ characters, no special characters, no spaces, allow _ and -
4
- return /^[a-zA-Z0-9][a-zA-Z0-9_-]{5,}$/.test(name);
3
+ // must be 3+ characters, no special characters, no spaces, allow _ and -
4
+ return /^[a-zA-Z0-9][a-zA-Z0-9_-]{2,}$/.test(name);
5
5
  }
6
6
  const validFunctionEventNames = ['publish', 'create', 'update', 'delete'];
7
7
  export function validateFunctionResource(resource) {
@@ -10,7 +10,7 @@ export function validateFunctionResource(resource) {
10
10
  const errors = [];
11
11
  if (!validateFunctionName(resource.name)) {
12
12
  errors.push({
13
- message: `${msgPrefix} Function name must be at least 6 characters, start with a letter or number, and only contain letters, numbers, _ or -`,
13
+ message: `${msgPrefix} Function name must be at least 3 characters, start with a letter or number, and only contain letters, numbers, _ or -`,
14
14
  type: BlueprintParserErrorType.InvalidProperty,
15
15
  });
16
16
  }
@@ -351,6 +351,42 @@
351
351
  "destroy.js"
352
352
  ]
353
353
  },
354
+ "blueprints:doctor": {
355
+ "aliases": [],
356
+ "args": {},
357
+ "description": "Diagnose potential issues with Blueprint configuration",
358
+ "examples": [],
359
+ "flags": {
360
+ "verbose": {
361
+ "description": "Provide detailed information about issues",
362
+ "name": "verbose",
363
+ "allowNo": false,
364
+ "type": "boolean"
365
+ },
366
+ "path": {
367
+ "description": "Path to the Blueprint configuration file",
368
+ "name": "path",
369
+ "hasDynamicHelp": false,
370
+ "multiple": false,
371
+ "type": "option"
372
+ }
373
+ },
374
+ "hasDynamicHelp": false,
375
+ "hiddenAliases": [],
376
+ "id": "blueprints:doctor",
377
+ "pluginAlias": "@sanity/runtime-cli",
378
+ "pluginName": "@sanity/runtime-cli",
379
+ "pluginType": "core",
380
+ "strict": true,
381
+ "enableJsonFlag": false,
382
+ "isESM": true,
383
+ "relativePath": [
384
+ "dist",
385
+ "commands",
386
+ "blueprints",
387
+ "doctor.js"
388
+ ]
389
+ },
354
390
  "blueprints:info": {
355
391
  "aliases": [],
356
392
  "args": {},
@@ -1141,5 +1177,5 @@
1141
1177
  ]
1142
1178
  }
1143
1179
  },
1144
- "version": "10.10.0"
1180
+ "version": "10.11.1"
1145
1181
  }
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.10.0",
4
+ "version": "10.11.1",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -71,6 +71,7 @@
71
71
  "test": "vitest run",
72
72
  "test:depmgmt": "vitest run --config ./test-depmgmt/vitest.config.ts",
73
73
  "test:integration": "cd test/integration && npm run typecheck",
74
+ "typecheck": "tsc --project tsconfig.typecheck.json",
74
75
  "posttest": "npm run lint",
75
76
  "test:watch": "vitest",
76
77
  "watch": "tsc --watch"
@@ -1,24 +0,0 @@
1
- export default function API(): {
2
- blueprint: typeof blueprint;
3
- document: typeof document;
4
- invoke: typeof invoke;
5
- projects: typeof projects;
6
- datasets: typeof datasets;
7
- store: any;
8
- subscribe: any;
9
- unsubscribe: any;
10
- };
11
- declare function blueprint(): void;
12
- declare function document({ projectId, dataset, docId }: {
13
- projectId: any;
14
- dataset: any;
15
- docId: any;
16
- }): Promise<void>;
17
- declare function invoke({ context, event, metadata }: {
18
- context: any;
19
- event: any;
20
- metadata: any;
21
- }): void;
22
- declare function projects(): void;
23
- declare function datasets(selectedProject: any): void;
24
- export {};
@@ -1,20 +0,0 @@
1
- export class ApiBaseElement extends HTMLElement {
2
- api: {
3
- blueprint: () => void;
4
- document: ({ projectId, dataset, docId }: {
5
- projectId: any;
6
- dataset: any;
7
- docId: any;
8
- }) => Promise<void>;
9
- invoke: ({ context, event, metadata }: {
10
- context: any;
11
- event: any;
12
- metadata: any;
13
- }) => void;
14
- projects: () => void;
15
- datasets: (selectedProject: any) => void;
16
- store: any;
17
- subscribe: any;
18
- unsubscribe: any;
19
- };
20
- }
@@ -1,6 +0,0 @@
1
- export class ClearButton extends ApiBaseElement {
2
- connectedCallback(): void;
3
- disconnectedCallback(): void;
4
- clear: () => void;
5
- }
6
- import { ApiBaseElement } from './api-base.js';
@@ -1,6 +0,0 @@
1
- export const sanityHighlightStyle: HighlightStyle;
2
- export const sanityCodeMirrorTheme: {
3
- inner: any;
4
- prec: any;
5
- }[][];
6
- import { HighlightStyle } from '../vendor/vendor.bundle.js';
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- export class FetchButton extends ApiBaseElement {
2
- connectedCallback(): void;
3
- button: HTMLButtonElement | null | undefined;
4
- disconnectedCallback(): void;
5
- fetchDoc: () => Promise<void>;
6
- }
7
- import { ApiBaseElement } from './api-base.js';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- export class HelpButton extends ApiBaseElement {
2
- }
3
- import { ApiBaseElement } from './api-base.js';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- export class ToggleSwitch extends ApiBaseElement {
2
- static get observedAttributes(): string[];
3
- connectedCallback(): void;
4
- toggleKey: string | null | undefined;
5
- disconnectedCallback(): void;
6
- attributeChangedCallback(name: any): void;
7
- set checked(value: boolean);
8
- get checked(): boolean;
9
- toggle: () => void;
10
- }
11
- import { ApiBaseElement } from './api-base.js';
@@ -1 +0,0 @@
1
- export {};