@sanity/runtime-cli 17.16.0-app-functions.ge0a25ea → 17.16.0-app-functions.gab0267c

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
@@ -90,7 +90,7 @@ EXAMPLES
90
90
  $ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
91
91
  ```
92
92
 
93
- _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/add.ts)_
93
+ _See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/add.ts)_
94
94
 
95
95
  ## `sanity-run blueprints config`
96
96
 
@@ -127,7 +127,7 @@ EXAMPLES
127
127
  $ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
128
128
  ```
129
129
 
130
- _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/config.ts)_
130
+ _See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/config.ts)_
131
131
 
132
132
  ## `sanity-run blueprints deploy`
133
133
 
@@ -183,7 +183,7 @@ EXAMPLES
183
183
  $ sanity-run blueprints deploy --new-stack-name <new-name>
184
184
  ```
185
185
 
186
- _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/deploy.ts)_
186
+ _See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/deploy.ts)_
187
187
 
188
188
  ## `sanity-run blueprints destroy`
189
189
 
@@ -221,7 +221,7 @@ EXAMPLES
221
221
  $ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
222
222
  ```
223
223
 
224
- _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/destroy.ts)_
224
+ _See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/destroy.ts)_
225
225
 
226
226
  ## `sanity-run blueprints doctor`
227
227
 
@@ -253,7 +253,7 @@ EXAMPLES
253
253
  $ sanity-run blueprints doctor --fix
254
254
  ```
255
255
 
256
- _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/doctor.ts)_
256
+ _See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/doctor.ts)_
257
257
 
258
258
  ## `sanity-run blueprints info`
259
259
 
@@ -291,7 +291,7 @@ EXAMPLES
291
291
  $ sanity-run blueprints info --organization-id <orgId> --stack <name-or-id>
292
292
  ```
293
293
 
294
- _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/info.ts)_
294
+ _See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/info.ts)_
295
295
 
296
296
  ## `sanity-run blueprints init [DIR]`
297
297
 
@@ -355,7 +355,7 @@ EXAMPLES
355
355
  $ sanity-run blueprints init old-stack --type <json|js|ts> --project-id <projectId> --stack-id <existingStackId>
356
356
  ```
357
357
 
358
- _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/init.ts)_
358
+ _See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/init.ts)_
359
359
 
360
360
  ## `sanity-run blueprints logs`
361
361
 
@@ -401,7 +401,7 @@ EXAMPLES
401
401
  $ sanity-run blueprints logs --before 2026-05-01T00:00:00Z
402
402
  ```
403
403
 
404
- _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/logs.ts)_
404
+ _See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/logs.ts)_
405
405
 
406
406
  ## `sanity-run blueprints mint-deploy-token`
407
407
 
@@ -446,7 +446,7 @@ EXAMPLES
446
446
  $ sanity-run blueprints mint-deploy-token --organization-id <orgId>
447
447
  ```
448
448
 
449
- _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/mint-deploy-token.ts)_
449
+ _See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/mint-deploy-token.ts)_
450
450
 
451
451
  ## `sanity-run blueprints plan`
452
452
 
@@ -479,7 +479,7 @@ EXAMPLES
479
479
  $ sanity-run blueprints plan --organization-id <orgId> --stack <name-or-id>
480
480
  ```
481
481
 
482
- _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/plan.ts)_
482
+ _See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/plan.ts)_
483
483
 
484
484
  ## `sanity-run blueprints promote`
485
485
 
@@ -515,7 +515,7 @@ EXAMPLES
515
515
  $ sanity-run blueprints promote --new-stack-name <new-name>
516
516
  ```
517
517
 
518
- _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/promote.ts)_
518
+ _See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/promote.ts)_
519
519
 
520
520
  ## `sanity-run blueprints stacks`
521
521
 
@@ -556,7 +556,7 @@ EXAMPLES
556
556
  $ sanity-run blueprints stacks --organization-id <organizationId> --include-projects
557
557
  ```
558
558
 
559
- _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/blueprints/stacks.ts)_
559
+ _See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/blueprints/stacks.ts)_
560
560
 
561
561
  ## `sanity-run functions add`
562
562
 
@@ -608,7 +608,7 @@ EXAMPLES
608
608
  $ sanity-run functions add --name my-function --type document-create --type document-update --lang js
609
609
  ```
610
610
 
611
- _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/functions/add.ts)_
611
+ _See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/functions/add.ts)_
612
612
 
613
613
  ## `sanity-run functions dev`
614
614
 
@@ -643,7 +643,7 @@ EXAMPLES
643
643
  $ sanity-run functions dev --timeout 60
644
644
  ```
645
645
 
646
- _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/functions/dev.ts)_
646
+ _See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/functions/dev.ts)_
647
647
 
648
648
  ## `sanity-run functions env add NAME KEY VALUE`
649
649
 
@@ -676,7 +676,7 @@ EXAMPLES
676
676
  $ sanity-run functions env add --stack <name-or-id> MyFunction API_URL https://api.example.com/
677
677
  ```
678
678
 
679
- _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/functions/env/add.ts)_
679
+ _See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/functions/env/add.ts)_
680
680
 
681
681
  ## `sanity-run functions env list NAME`
682
682
 
@@ -706,7 +706,7 @@ EXAMPLES
706
706
  $ sanity-run functions env list --stack <name-or-id> MyFunction
707
707
  ```
708
708
 
709
- _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/functions/env/list.ts)_
709
+ _See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/functions/env/list.ts)_
710
710
 
711
711
  ## `sanity-run functions env remove NAME KEY`
712
712
 
@@ -738,7 +738,7 @@ EXAMPLES
738
738
  $ sanity-run functions env remove --stack <name-or-id> MyFunction API_URL
739
739
  ```
740
740
 
741
- _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/functions/env/remove.ts)_
741
+ _See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/functions/env/remove.ts)_
742
742
 
743
743
  ## `sanity-run functions logs [NAME]`
744
744
 
@@ -778,7 +778,7 @@ EXAMPLES
778
778
  $ sanity-run functions logs <name> --delete
779
779
  ```
780
780
 
781
- _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/functions/logs.ts)_
781
+ _See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/functions/logs.ts)_
782
782
 
783
783
  ## `sanity-run functions test [NAME]`
784
784
 
@@ -836,7 +836,7 @@ EXAMPLES
836
836
  $ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
837
837
  ```
838
838
 
839
- _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.ge0a25ea/src/commands/functions/test.ts)_
839
+ _See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.16.0-app-functions.gab0267c/src/commands/functions/test.ts)_
840
840
 
841
841
  ## `sanity-run help [COMMAND]`
842
842
 
@@ -138,9 +138,10 @@ export declare function promoteStack({ stackId, auth, logger, name, }: {
138
138
  name?: string;
139
139
  }): Promise<PromoteStackResponse>;
140
140
  type DestroyStackResponse = UpdateStackResponse;
141
- export declare function destroyStack({ stackId, auth, logger, }: {
141
+ export declare function destroyStack({ stackId, auth, logger, fetchFn, }: {
142
142
  stackId: string;
143
143
  auth: AuthParams;
144
144
  logger: Logger;
145
+ fetchFn?: typeof fetch;
145
146
  }): Promise<DestroyStackResponse>;
146
147
  export {};
@@ -198,8 +198,7 @@ export async function promoteStack({ stackId, auth, logger, name, }) {
198
198
  };
199
199
  }
200
200
  }
201
- export async function destroyStack({ stackId, auth, logger, }) {
202
- const fetchFn = createTracedFetch(logger);
201
+ export async function destroyStack({ stackId, auth, logger, fetchFn = createTracedFetch(logger), }) {
203
202
  try {
204
203
  const response = await fetchFn(`${stacksUrl}/${stackId}`, {
205
204
  method: 'DELETE',
@@ -1,5 +1,5 @@
1
1
  import { type LocatedBlueprintsConfig } from '../../actions/blueprints/config.js';
2
- import type { ScopeType } from '../../utils/types.js';
2
+ import type { AuthParams, ScopeType } from '../../utils/types.js';
3
3
  import type { CoreConfig, CoreResult } from '../index.js';
4
4
  export interface BlueprintDestroyOptions extends CoreConfig {
5
5
  token: string;
@@ -20,3 +20,16 @@ export interface BlueprintDestroyOptions extends CoreConfig {
20
20
  };
21
21
  }
22
22
  export declare function blueprintDestroyCore(options: BlueprintDestroyOptions): Promise<CoreResult>;
23
+ type WaitForDestructionOptions = {
24
+ stackId: string;
25
+ stackName: string;
26
+ operationId: string;
27
+ requestId?: string;
28
+ auth: AuthParams;
29
+ log: CoreConfig['log'];
30
+ bin: string;
31
+ verbose?: boolean;
32
+ fetchFn?: typeof fetch;
33
+ };
34
+ export declare function waitForDestruction(options: WaitForDestructionOptions): Promise<CoreResult>;
35
+ export {};
@@ -150,7 +150,7 @@ function afterDestroyAccepted(options) {
150
150
  }
151
151
  return waitForDestruction(options);
152
152
  }
153
- async function waitForDestruction(options) {
153
+ export async function waitForDestruction(options) {
154
154
  const { stackId, stackName, operationId, requestId, auth, log, bin, verbose = false } = options;
155
155
  log(styleText('dim', 'Stack destruction progress:'));
156
156
  log('');
@@ -163,6 +163,7 @@ async function waitForDestruction(options) {
163
163
  verbose,
164
164
  includeDestroyed: true,
165
165
  progressNoun: 'destruction',
166
+ fetchFn: options.fetchFn,
166
167
  });
167
168
  if (outcome.type === 'completed') {
168
169
  log(styleText(['bold', 'magenta'], 'Stack destruction completed!'));
@@ -1,3 +1,4 @@
1
+ import type { CoreResult } from '../cores/index.js';
1
2
  import type { Stack, StackSummary } from '../utils/types.js';
2
3
  interface AppFunctionIdentity {
3
4
  appId: string;
@@ -16,3 +17,21 @@ export declare function ensureFunctionStack(options: AppFunctionIdentity & {
16
17
  id: string;
17
18
  } | null>;
18
19
  export { BLUEPRINTS_API_VERSION } from '../config.js';
20
+ /** Scope and transport for looking up an app's function stack. */
21
+ export interface FunctionStackOptions extends AppFunctionIdentity {
22
+ token: string;
23
+ fetchFn: typeof fetch;
24
+ stackId?: string;
25
+ }
26
+ /** Read-only stack metadata for an undeploy plan. */
27
+ export interface FunctionStackInfo {
28
+ id: string;
29
+ functions: string[];
30
+ }
31
+ /** Find an app-owned stack without creating one, and verify all resources are app functions. */
32
+ export declare function inspectFunctionStack(options: FunctionStackOptions): Promise<FunctionStackInfo | null>;
33
+ /** Destroy an app's stack using Blueprint deletion and operation polling. Missing stacks are already clean. */
34
+ export declare function destroyFunctionStack(options: FunctionStackOptions & {
35
+ stackId: string;
36
+ log: (message: string) => void;
37
+ }): Promise<CoreResult>;
@@ -1,4 +1,5 @@
1
- import { createStack, getStack, listStacks } from '../actions/blueprints/stacks.js';
1
+ import { createStack, destroyStack, getStack, listStacks } from '../actions/blueprints/stacks.js';
2
+ import { waitForDestruction } from '../cores/blueprints/destroy.js';
2
3
  import { Logger } from '../utils/logger.js';
3
4
  /** Shared ownership check for provisioning and deploying an app's function stack. */
4
5
  export function assertAppFunctionStack(stack, { appId, organizationId }) {
@@ -82,3 +83,66 @@ function stackRequestError(result) {
82
83
  return new Error(`Blueprint stack request failed${status}: ${result.error || result.response?.statusText || 'Unknown error'}`);
83
84
  }
84
85
  export { BLUEPRINTS_API_VERSION } from '../config.js';
86
+ /** Find an app-owned stack without creating one, and verify all resources are app functions. */
87
+ export async function inspectFunctionStack(options) {
88
+ const found = await ensureFunctionStack({ ...options, dryRun: true });
89
+ if (!found)
90
+ return null;
91
+ const stack = await readOwnedFunctionStack({ ...options, stackId: found.id });
92
+ return stack ? { id: stack.id, functions: stack.resources.map((resource) => resource.name) } : null;
93
+ }
94
+ /** Destroy an app's stack using Blueprint deletion and operation polling. Missing stacks are already clean. */
95
+ export async function destroyFunctionStack(options) {
96
+ try {
97
+ const stack = await readOwnedFunctionStack(options);
98
+ if (!stack)
99
+ return { success: true };
100
+ const log = Logger(options.log, { json: true });
101
+ const auth = {
102
+ token: options.token,
103
+ scopeType: 'organization',
104
+ scopeId: options.organizationId,
105
+ };
106
+ const result = await destroyStack({
107
+ stackId: stack.id,
108
+ auth,
109
+ logger: log,
110
+ fetchFn: options.fetchFn,
111
+ });
112
+ if (!result.ok) {
113
+ if (result.response?.status === 404)
114
+ return { success: true };
115
+ return { success: false, error: result.error, requestId: result.requestId };
116
+ }
117
+ return await waitForDestruction({
118
+ stackId: stack.id,
119
+ stackName: stack.name,
120
+ operationId: result.stack.operationId,
121
+ requestId: result.requestId,
122
+ auth,
123
+ log,
124
+ bin: 'sanity',
125
+ fetchFn: options.fetchFn,
126
+ });
127
+ }
128
+ catch (error) {
129
+ return { success: false, error: error instanceof Error ? error.message : String(error) };
130
+ }
131
+ }
132
+ async function readOwnedFunctionStack(options) {
133
+ const auth = {
134
+ token: options.token,
135
+ scopeType: 'organization',
136
+ scopeId: options.organizationId,
137
+ };
138
+ const result = await getStack({ stackId: options.stackId, auth, fetchFn: options.fetchFn });
139
+ if (!result.ok) {
140
+ if (result.response?.status === 404)
141
+ return null;
142
+ throw stackRequestError(result);
143
+ }
144
+ assertAppFunctionStack(result.stack, options);
145
+ if (result.stack.resources.some((resource) => resource.type !== 'sanity.function.pubsub'))
146
+ throw new Error('The app function stack contains other resource types. Manage it with sanity blueprints instead.');
147
+ return result.stack;
148
+ }
@@ -3148,5 +3148,5 @@
3148
3148
  ]
3149
3149
  }
3150
3150
  },
3151
- "version": "17.16.0-app-functions.ge0a25ea"
3151
+ "version": "17.16.0-app-functions.gab0267c"
3152
3152
  }
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": "17.16.0-app-functions.ge0a25ea",
4
+ "version": "17.16.0-app-functions.gab0267c",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",