@sanity/runtime-cli 17.21.3-app-functions.g1a9a040 → 17.21.3-next.gfaa10cb
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 +19 -19
- package/dist/actions/blueprints/stacks.d.ts +3 -9
- package/dist/actions/blueprints/stacks.js +8 -11
- package/dist/actions/blueprints/wait-for-operation.d.ts +0 -1
- package/dist/actions/blueprints/wait-for-operation.js +1 -1
- package/dist/cores/blueprints/deploy.d.ts +0 -8
- package/dist/cores/blueprints/deploy.js +4 -12
- package/dist/cores/blueprints/destroy.d.ts +1 -14
- package/dist/cores/blueprints/destroy.js +1 -2
- package/dist/utils/functions/transpile/function.d.ts +1 -7
- package/dist/utils/functions/transpile/function.js +9 -15
- package/oclif.manifest.json +1003 -1003
- package/package.json +1 -22
- package/dist/functions/artifacts.d.ts +0 -13
- package/dist/functions/artifacts.js +0 -26
- package/dist/functions/build.d.ts +0 -15
- package/dist/functions/build.js +0 -30
- package/dist/functions/contractPlugin.d.ts +0 -7
- package/dist/functions/contractPlugin.js +0 -32
- package/dist/functions/contracts/schema.d.ts +0 -22
- package/dist/functions/contracts/schema.js +0 -99
- package/dist/functions/contracts/validation.d.ts +0 -3
- package/dist/functions/contracts/validation.js +0 -66
- package/dist/functions/contracts.d.ts +0 -33
- package/dist/functions/contracts.js +0 -162
- package/dist/functions/deploy.d.ts +0 -16
- package/dist/functions/deploy.js +0 -69
- package/dist/functions/schedule.d.ts +0 -21
- package/dist/functions/schedule.js +0 -34
- package/dist/functions/stack.d.ts +0 -41
- package/dist/functions/stack.js +0 -153
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { type BlueprintScheduledFunctionConfigEvent, type BlueprintScheduledFunctionResource, type BlueprintScheduledFunctionResourceEvent } from '@sanity/blueprints';
|
|
2
|
-
/** IANA timezone names accepted by Blueprint scheduled functions. */
|
|
3
|
-
export type ScheduleTimezone = NonNullable<BlueprintScheduledFunctionResource['timezone']>;
|
|
4
|
-
/** Explicit cron fields stored for a scheduled app function. */
|
|
5
|
-
export type ScheduledFunctionEvent = BlueprintScheduledFunctionResourceEvent;
|
|
6
|
-
/** How Sanity invokes an app function. */
|
|
7
|
-
export type FunctionTrigger = {
|
|
8
|
-
type: 'pubsub';
|
|
9
|
-
} | {
|
|
10
|
-
type: 'cron';
|
|
11
|
-
event: ScheduledFunctionEvent;
|
|
12
|
-
timezone?: string;
|
|
13
|
-
};
|
|
14
|
-
export declare const scheduleFields: readonly ['minute', 'hour', 'dayOfMonth', 'month', 'dayOfWeek'];
|
|
15
|
-
/**
|
|
16
|
-
* Validate a schedule with the Blueprint rules and normalize natural language or cron
|
|
17
|
-
* expressions to explicit fields, so build output and deploys agree on the same schedule.
|
|
18
|
-
*/
|
|
19
|
-
export declare function scheduledTrigger(name: string, event: BlueprintScheduledFunctionConfigEvent, timezone?: string): Extract<FunctionTrigger, {
|
|
20
|
-
type: 'cron';
|
|
21
|
-
}>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { defineScheduledFunction, validateScheduledFunction, } from '@sanity/blueprints';
|
|
2
|
-
export const scheduleFields = ['minute', 'hour', 'dayOfMonth', 'month', 'dayOfWeek'];
|
|
3
|
-
/**
|
|
4
|
-
* Validate a schedule with the Blueprint rules and normalize natural language or cron
|
|
5
|
-
* expressions to explicit fields, so build output and deploys agree on the same schedule.
|
|
6
|
-
*/
|
|
7
|
-
export function scheduledTrigger(name, event, timezone) {
|
|
8
|
-
try {
|
|
9
|
-
// Blueprints only exposes its expression parser through the definer. The definer records
|
|
10
|
-
// validation errors for blueprint files instead of throwing, so validate separately.
|
|
11
|
-
const parsed = 'expression' in event
|
|
12
|
-
? defineScheduledFunction({ name, event: { expression: event.expression } }).event
|
|
13
|
-
: event;
|
|
14
|
-
const { minute, hour, dayOfMonth, month, dayOfWeek } = parsed;
|
|
15
|
-
const trigger = {
|
|
16
|
-
type: 'cron',
|
|
17
|
-
event: { minute, hour, dayOfMonth, month, dayOfWeek },
|
|
18
|
-
...(timezone === undefined ? {} : { timezone }),
|
|
19
|
-
};
|
|
20
|
-
const errors = validateScheduledFunction({
|
|
21
|
-
name,
|
|
22
|
-
type: 'sanity.function.cron',
|
|
23
|
-
event: trigger.event,
|
|
24
|
-
...(timezone === undefined ? {} : { timezone: timezone }),
|
|
25
|
-
});
|
|
26
|
-
if (errors.length)
|
|
27
|
-
throw new Error(errors.map((error) => error.message).join(' '));
|
|
28
|
-
return trigger;
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
32
|
-
throw new Error(`Function "${name}" has an invalid schedule: ${message}`, { cause: error });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { CoreResult } from '../cores/index.js';
|
|
2
|
-
import type { Stack, StackSummary } from '../utils/types.js';
|
|
3
|
-
interface AppFunctionIdentity {
|
|
4
|
-
appId: string;
|
|
5
|
-
organizationId: string;
|
|
6
|
-
}
|
|
7
|
-
/** Shared ownership check for provisioning and deploying an app's function stack. */
|
|
8
|
-
export declare function assertAppFunctionStack(stack: Stack | StackSummary, { appId, organizationId }: AppFunctionIdentity): void;
|
|
9
|
-
/** Resolve or create a dedicated app stack using the Blueprint stack operations. */
|
|
10
|
-
export declare function ensureFunctionStack(options: AppFunctionIdentity & {
|
|
11
|
-
token: string;
|
|
12
|
-
fetchFn: typeof fetch;
|
|
13
|
-
stackId?: string;
|
|
14
|
-
dryRun?: boolean;
|
|
15
|
-
}): Promise<{
|
|
16
|
-
created: boolean;
|
|
17
|
-
id: string;
|
|
18
|
-
} | null>;
|
|
19
|
-
/** App stacks hold only the function types the CLI deploys, so other resources are never replaced. */
|
|
20
|
-
export declare function isAppFunctionResource(resource: {
|
|
21
|
-
type: string;
|
|
22
|
-
}): boolean;
|
|
23
|
-
export { BLUEPRINTS_API_VERSION } from '../config.js';
|
|
24
|
-
/** Scope and transport for looking up an app's function stack. */
|
|
25
|
-
export interface FunctionStackOptions extends AppFunctionIdentity {
|
|
26
|
-
token: string;
|
|
27
|
-
fetchFn: typeof fetch;
|
|
28
|
-
stackId?: string;
|
|
29
|
-
}
|
|
30
|
-
/** Read-only stack metadata for an undeploy plan. */
|
|
31
|
-
export interface FunctionStackInfo {
|
|
32
|
-
id: string;
|
|
33
|
-
functions: string[];
|
|
34
|
-
}
|
|
35
|
-
/** Find an app-owned stack without creating one, and verify all resources are app functions. */
|
|
36
|
-
export declare function inspectFunctionStack(options: FunctionStackOptions): Promise<FunctionStackInfo | null>;
|
|
37
|
-
/** Destroy an app's stack using Blueprint deletion and operation polling. Missing stacks are already clean. */
|
|
38
|
-
export declare function destroyFunctionStack(options: FunctionStackOptions & {
|
|
39
|
-
stackId: string;
|
|
40
|
-
log: (message: string) => void;
|
|
41
|
-
}): Promise<CoreResult>;
|
package/dist/functions/stack.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { createStack, destroyStack, getStack, listStacks } from '../actions/blueprints/stacks.js';
|
|
2
|
-
import { waitForDestruction } from '../cores/blueprints/destroy.js';
|
|
3
|
-
import { Logger } from '../utils/logger.js';
|
|
4
|
-
/** Shared ownership check for provisioning and deploying an app's function stack. */
|
|
5
|
-
export function assertAppFunctionStack(stack, { appId, organizationId }) {
|
|
6
|
-
if (!stack ||
|
|
7
|
-
typeof stack.id !== 'string' ||
|
|
8
|
-
!stack.id ||
|
|
9
|
-
stack.name !== appFunctionStackName(appId) ||
|
|
10
|
-
stack.scopeType !== 'organization' ||
|
|
11
|
-
stack.scopeId !== organizationId) {
|
|
12
|
-
throw new Error(`The function stack does not belong to app "${appId}" in organization "${organizationId}". Check .sanity/app-functions.json.`);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/** Resolve or create a dedicated app stack using the Blueprint stack operations. */
|
|
16
|
-
export async function ensureFunctionStack(options) {
|
|
17
|
-
const { appId, organizationId, token, fetchFn, stackId, dryRun = false } = options;
|
|
18
|
-
const auth = { token, scopeType: 'organization', scopeId: organizationId };
|
|
19
|
-
const name = appFunctionStackName(appId);
|
|
20
|
-
const logger = Logger(() => { }, { json: true });
|
|
21
|
-
const resolved = (stack, created) => {
|
|
22
|
-
assertAppFunctionStack(stack, options);
|
|
23
|
-
return { created, id: stack.id };
|
|
24
|
-
};
|
|
25
|
-
if (stackId) {
|
|
26
|
-
const result = await getStack({ stackId, auth, fetchFn });
|
|
27
|
-
if (result.ok)
|
|
28
|
-
return resolved(result.stack, false);
|
|
29
|
-
if (result.response?.status !== 404)
|
|
30
|
-
throw stackRequestError(result);
|
|
31
|
-
}
|
|
32
|
-
async function findStack() {
|
|
33
|
-
let cursor;
|
|
34
|
-
const cursors = new Set();
|
|
35
|
-
do {
|
|
36
|
-
const result = await listStacks(auth, logger, { fetchFn, cursor, limit: 500 });
|
|
37
|
-
if (!result.ok)
|
|
38
|
-
throw stackRequestError(result);
|
|
39
|
-
if (!Array.isArray(result.stacks))
|
|
40
|
-
throw new Error('Invalid Blueprint stack list response.');
|
|
41
|
-
const stack = result.stacks.find((item) => item?.name === name);
|
|
42
|
-
if (stack)
|
|
43
|
-
return stack;
|
|
44
|
-
if (result.response?.headers.get('x-has-more') !== 'true')
|
|
45
|
-
return undefined;
|
|
46
|
-
cursor = result.response.headers.get('x-cursor') ?? undefined;
|
|
47
|
-
if (!cursor || cursors.has(cursor))
|
|
48
|
-
throw new Error('Cannot read the next page of Blueprint stacks. Try again.');
|
|
49
|
-
cursors.add(cursor);
|
|
50
|
-
} while (cursor);
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
const existing = await findStack();
|
|
54
|
-
if (existing)
|
|
55
|
-
return resolved(existing, false);
|
|
56
|
-
if (dryRun)
|
|
57
|
-
return null;
|
|
58
|
-
const result = await createStack({
|
|
59
|
-
auth,
|
|
60
|
-
logger,
|
|
61
|
-
fetchFn,
|
|
62
|
-
stackMutation: {
|
|
63
|
-
name,
|
|
64
|
-
scopeType: auth.scopeType,
|
|
65
|
-
scopeId: auth.scopeId,
|
|
66
|
-
document: { resources: [] },
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
if (result.ok)
|
|
70
|
-
return resolved(result.stack, true);
|
|
71
|
-
if (result.response?.status === 409) {
|
|
72
|
-
const concurrent = await findStack();
|
|
73
|
-
if (concurrent)
|
|
74
|
-
return resolved(concurrent, false);
|
|
75
|
-
}
|
|
76
|
-
throw stackRequestError(result);
|
|
77
|
-
}
|
|
78
|
-
const appFunctionResourceTypes = new Set(['sanity.function.pubsub', 'sanity.function.cron']);
|
|
79
|
-
/** App stacks hold only the function types the CLI deploys, so other resources are never replaced. */
|
|
80
|
-
export function isAppFunctionResource(resource) {
|
|
81
|
-
return appFunctionResourceTypes.has(resource.type);
|
|
82
|
-
}
|
|
83
|
-
function appFunctionStackName(appId) {
|
|
84
|
-
return `app-${appId}`;
|
|
85
|
-
}
|
|
86
|
-
function stackRequestError(result) {
|
|
87
|
-
const status = result.response ? ` (${result.response.status})` : '';
|
|
88
|
-
return new Error(`Blueprint stack request failed${status}: ${result.error || result.response?.statusText || 'Unknown error'}`);
|
|
89
|
-
}
|
|
90
|
-
export { BLUEPRINTS_API_VERSION } from '../config.js';
|
|
91
|
-
/** Find an app-owned stack without creating one, and verify all resources are app functions. */
|
|
92
|
-
export async function inspectFunctionStack(options) {
|
|
93
|
-
const found = await ensureFunctionStack({ ...options, dryRun: true });
|
|
94
|
-
if (!found)
|
|
95
|
-
return null;
|
|
96
|
-
const stack = await readOwnedFunctionStack({ ...options, stackId: found.id });
|
|
97
|
-
return stack ? { id: stack.id, functions: stack.resources.map((resource) => resource.name) } : null;
|
|
98
|
-
}
|
|
99
|
-
/** Destroy an app's stack using Blueprint deletion and operation polling. Missing stacks are already clean. */
|
|
100
|
-
export async function destroyFunctionStack(options) {
|
|
101
|
-
try {
|
|
102
|
-
const stack = await readOwnedFunctionStack(options);
|
|
103
|
-
if (!stack)
|
|
104
|
-
return { success: true };
|
|
105
|
-
const log = Logger(options.log, { json: true });
|
|
106
|
-
const auth = {
|
|
107
|
-
token: options.token,
|
|
108
|
-
scopeType: 'organization',
|
|
109
|
-
scopeId: options.organizationId,
|
|
110
|
-
};
|
|
111
|
-
const result = await destroyStack({
|
|
112
|
-
stackId: stack.id,
|
|
113
|
-
auth,
|
|
114
|
-
logger: log,
|
|
115
|
-
fetchFn: options.fetchFn,
|
|
116
|
-
});
|
|
117
|
-
if (!result.ok) {
|
|
118
|
-
if (result.response?.status === 404)
|
|
119
|
-
return { success: true };
|
|
120
|
-
return { success: false, error: result.error, requestId: result.requestId };
|
|
121
|
-
}
|
|
122
|
-
return await waitForDestruction({
|
|
123
|
-
stackId: stack.id,
|
|
124
|
-
stackName: stack.name,
|
|
125
|
-
operationId: result.stack.operationId,
|
|
126
|
-
requestId: result.requestId,
|
|
127
|
-
auth,
|
|
128
|
-
log,
|
|
129
|
-
bin: 'sanity',
|
|
130
|
-
fetchFn: options.fetchFn,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
async function readOwnedFunctionStack(options) {
|
|
138
|
-
const auth = {
|
|
139
|
-
token: options.token,
|
|
140
|
-
scopeType: 'organization',
|
|
141
|
-
scopeId: options.organizationId,
|
|
142
|
-
};
|
|
143
|
-
const result = await getStack({ stackId: options.stackId, auth, fetchFn: options.fetchFn });
|
|
144
|
-
if (!result.ok) {
|
|
145
|
-
if (result.response?.status === 404)
|
|
146
|
-
return null;
|
|
147
|
-
throw stackRequestError(result);
|
|
148
|
-
}
|
|
149
|
-
assertAppFunctionStack(result.stack, options);
|
|
150
|
-
if (!result.stack.resources.every(isAppFunctionResource))
|
|
151
|
-
throw new Error('The app function stack contains other resource types. Manage it with sanity blueprints instead.');
|
|
152
|
-
return result.stack;
|
|
153
|
-
}
|