@sanity/runtime-cli 14.3.0 → 14.5.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 +31 -27
- package/dist/actions/blueprints/assets.d.ts +3 -2
- package/dist/actions/blueprints/assets.js +14 -3
- package/dist/actions/blueprints/blueprint.js +2 -2
- package/dist/actions/blueprints/resources.js +2 -1
- package/dist/actions/functions/logs.d.ts +0 -1
- package/dist/actions/functions/logs.js +0 -1
- package/dist/commands/blueprints/add.js +2 -1
- package/dist/commands/blueprints/deploy.d.ts +1 -0
- package/dist/commands/blueprints/deploy.js +10 -0
- package/dist/commands/functions/add.js +2 -1
- package/dist/commands/functions/build.d.ts +1 -0
- package/dist/commands/functions/build.js +7 -0
- package/dist/constants.d.ts +18 -1
- package/dist/constants.js +26 -9
- package/dist/cores/blueprints/deploy.d.ts +1 -0
- package/dist/cores/blueprints/deploy.js +2 -1
- package/dist/cores/functions/add.js +13 -13
- package/dist/cores/functions/build.d.ts +1 -0
- package/dist/cores/functions/build.js +2 -1
- package/dist/cores/functions/logs.js +3 -5
- package/dist/cores/functions/test.js +1 -1
- package/dist/server/app.js +6 -4
- package/dist/server/static/components/api-base.js +1 -1
- package/dist/server/static/components/filters.js +1 -1
- package/dist/server/static/components/function-list.js +2 -2
- package/dist/server/static/components/payload-panel.js +1 -1
- package/dist/server/static/components/run-panel.js +2 -2
- package/dist/utils/display/blueprints-formatting.js +12 -5
- package/dist/utils/find-function.js +4 -3
- package/dist/utils/functions/detect-native-modules.d.ts +7 -1
- package/dist/utils/functions/detect-native-modules.js +69 -1
- package/dist/utils/functions/prepare-asset.d.ts +3 -1
- package/dist/utils/functions/prepare-asset.js +28 -3
- package/dist/utils/functions/resolve-dependencies.d.ts +5 -2
- package/dist/utils/functions/resolve-dependencies.js +19 -12
- package/dist/utils/invoke-local.js +1 -1
- package/dist/utils/pnpm.d.ts +1 -0
- package/dist/utils/pnpm.js +9 -0
- package/dist/utils/transpile/transpile-function.d.ts +4 -2
- package/dist/utils/transpile/transpile-function.js +5 -8
- package/dist/utils/types.d.ts +8 -5
- package/dist/utils/types.js +8 -4
- package/dist/utils/validate/index.js +7 -4
- package/dist/utils/validate/resource.js +3 -2
- package/oclif.manifest.json +42 -7
- package/package.json +5 -4
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.5.0 linux-x64 node-v24.14.0
|
|
24
24
|
$ sanity-run --help [COMMAND]
|
|
25
25
|
USAGE
|
|
26
26
|
$ sanity-run COMMAND
|
|
@@ -55,9 +55,9 @@ Add a function resource to a Blueprint
|
|
|
55
55
|
```
|
|
56
56
|
USAGE
|
|
57
57
|
$ sanity-run blueprints add TYPE [--example <value> | -n <value> | --fn-type
|
|
58
|
-
document-publish|document-create|document-
|
|
59
|
-
te|media-library-asset-delete|
|
|
60
|
-
skip|npm|pnpm|yarn] [-i | ]
|
|
58
|
+
document-publish|document-create|document-update|document-delete|media-library-asset-create|media-library-asset-upda
|
|
59
|
+
te|media-library-asset-delete|scheduled-function... | --language ts|js | --javascript | --fn-helpers |
|
|
60
|
+
--fn-installer skip|npm|pnpm|yarn] [-i | ]
|
|
61
61
|
|
|
62
62
|
ARGUMENTS
|
|
63
63
|
TYPE (function) Type of resource to add (only "function" is supported)
|
|
@@ -72,8 +72,8 @@ FLAGS
|
|
|
72
72
|
<options: skip|npm|pnpm|yarn>
|
|
73
73
|
--fn-type=<option>... Document change event(s) that should trigger the function; you can specify multiple
|
|
74
74
|
events by specifying this flag multiple times
|
|
75
|
-
<options: document-publish|document-create|document-
|
|
76
|
-
asset-create|media-library-asset-update|media-library-asset-delete|
|
|
75
|
+
<options: document-publish|document-create|document-update|document-delete|media-library-
|
|
76
|
+
asset-create|media-library-asset-update|media-library-asset-delete|scheduled-function>
|
|
77
77
|
--javascript Use JavaScript instead of TypeScript
|
|
78
78
|
--language=<option> [default: ts] Language of the new function
|
|
79
79
|
<options: ts|js>
|
|
@@ -98,7 +98,7 @@ EXAMPLES
|
|
|
98
98
|
$ sanity-run blueprints add function --name my-function --fn-type document-create --fn-type document-update --lang js
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
101
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/add.ts)_
|
|
102
102
|
|
|
103
103
|
## `sanity-run blueprints config`
|
|
104
104
|
|
|
@@ -133,7 +133,7 @@ EXAMPLES
|
|
|
133
133
|
$ sanity-run blueprints config --edit --project-id <projectId> --stack <name-or-id>
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
136
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/config.ts)_
|
|
137
137
|
|
|
138
138
|
## `sanity-run blueprints deploy`
|
|
139
139
|
|
|
@@ -158,15 +158,19 @@ DESCRIPTION
|
|
|
158
158
|
|
|
159
159
|
Use --no-wait to queue the deployment and return immediately without waiting for completion.
|
|
160
160
|
|
|
161
|
+
Use --fn-installer to force which package manager to use when deploying functions.
|
|
162
|
+
|
|
161
163
|
Set SANITY_ASSET_TIMEOUT (seconds) to override the 60-second timeout for processing resource assets.
|
|
162
164
|
|
|
163
165
|
EXAMPLES
|
|
164
166
|
$ sanity-run blueprints deploy
|
|
165
167
|
|
|
166
168
|
$ sanity-run blueprints deploy --no-wait
|
|
169
|
+
|
|
170
|
+
$ sanity-run blueprints deploy --fn-installer npm
|
|
167
171
|
```
|
|
168
172
|
|
|
169
|
-
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
173
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/deploy.ts)_
|
|
170
174
|
|
|
171
175
|
## `sanity-run blueprints destroy`
|
|
172
176
|
|
|
@@ -198,7 +202,7 @@ EXAMPLES
|
|
|
198
202
|
$ sanity-run blueprints destroy --stack <name-or-id> --project-id <projectId> --force --no-wait
|
|
199
203
|
```
|
|
200
204
|
|
|
201
|
-
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
205
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/destroy.ts)_
|
|
202
206
|
|
|
203
207
|
## `sanity-run blueprints doctor`
|
|
204
208
|
|
|
@@ -224,7 +228,7 @@ DESCRIPTION
|
|
|
224
228
|
issues.
|
|
225
229
|
```
|
|
226
230
|
|
|
227
|
-
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
231
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/doctor.ts)_
|
|
228
232
|
|
|
229
233
|
## `sanity-run blueprints info`
|
|
230
234
|
|
|
@@ -254,7 +258,7 @@ EXAMPLES
|
|
|
254
258
|
$ sanity-run blueprints info --stack <name-or-id>
|
|
255
259
|
```
|
|
256
260
|
|
|
257
|
-
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
261
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/info.ts)_
|
|
258
262
|
|
|
259
263
|
## `sanity-run blueprints init [DIR]`
|
|
260
264
|
|
|
@@ -304,7 +308,7 @@ EXAMPLES
|
|
|
304
308
|
$ sanity-run blueprints init --blueprint-type <json|js|ts> --stack-name <stackName>
|
|
305
309
|
```
|
|
306
310
|
|
|
307
|
-
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
311
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/init.ts)_
|
|
308
312
|
|
|
309
313
|
## `sanity-run blueprints logs`
|
|
310
314
|
|
|
@@ -333,7 +337,7 @@ EXAMPLES
|
|
|
333
337
|
$ sanity-run blueprints logs --watch
|
|
334
338
|
```
|
|
335
339
|
|
|
336
|
-
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
340
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/logs.ts)_
|
|
337
341
|
|
|
338
342
|
## `sanity-run blueprints plan`
|
|
339
343
|
|
|
@@ -359,7 +363,7 @@ EXAMPLES
|
|
|
359
363
|
$ sanity-run blueprints plan
|
|
360
364
|
```
|
|
361
365
|
|
|
362
|
-
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
366
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/plan.ts)_
|
|
363
367
|
|
|
364
368
|
## `sanity-run blueprints stacks`
|
|
365
369
|
|
|
@@ -388,7 +392,7 @@ EXAMPLES
|
|
|
388
392
|
$ sanity-run blueprints stacks --organization-id <organizationId>
|
|
389
393
|
```
|
|
390
394
|
|
|
391
|
-
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
395
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/blueprints/stacks.ts)_
|
|
392
396
|
|
|
393
397
|
## `sanity-run functions add`
|
|
394
398
|
|
|
@@ -397,8 +401,8 @@ Add a Function to your Blueprint
|
|
|
397
401
|
```
|
|
398
402
|
USAGE
|
|
399
403
|
$ sanity-run functions add [--example <value> | -n <value> | | --language ts|js | --javascript | | ] [--type
|
|
400
|
-
document-publish|document-create|document-
|
|
401
|
-
te|media-library-asset-delete|
|
|
404
|
+
document-publish|document-create|document-update|document-delete|media-library-asset-create|media-library-asset-upda
|
|
405
|
+
te|media-library-asset-delete|scheduled-function... ] [--helpers] [--installer skip|npm|pnpm|yarn] [-i | ]
|
|
402
406
|
|
|
403
407
|
FLAGS
|
|
404
408
|
-i, --install Shortcut for --fn-installer npm
|
|
@@ -412,8 +416,8 @@ FLAGS
|
|
|
412
416
|
<options: ts|js>
|
|
413
417
|
--type=<option>... Document change event(s) that should trigger the function; you can specify multiple events
|
|
414
418
|
by specifying this flag multiple times
|
|
415
|
-
<options: document-publish|document-create|document-
|
|
416
|
-
et-create|media-library-asset-update|media-library-asset-delete|
|
|
419
|
+
<options: document-publish|document-create|document-update|document-delete|media-library-ass
|
|
420
|
+
et-create|media-library-asset-update|media-library-asset-delete|scheduled-function>
|
|
417
421
|
|
|
418
422
|
DESCRIPTION
|
|
419
423
|
Add a Function to your Blueprint
|
|
@@ -437,7 +441,7 @@ EXAMPLES
|
|
|
437
441
|
$ sanity-run functions add --name my-function --type document-create --type document-update --lang js
|
|
438
442
|
```
|
|
439
443
|
|
|
440
|
-
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
444
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/functions/add.ts)_
|
|
441
445
|
|
|
442
446
|
## `sanity-run functions dev`
|
|
443
447
|
|
|
@@ -471,7 +475,7 @@ EXAMPLES
|
|
|
471
475
|
$ sanity-run functions dev --timeout 60
|
|
472
476
|
```
|
|
473
477
|
|
|
474
|
-
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
478
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/functions/dev.ts)_
|
|
475
479
|
|
|
476
480
|
## `sanity-run functions env add NAME KEY VALUE`
|
|
477
481
|
|
|
@@ -498,7 +502,7 @@ EXAMPLES
|
|
|
498
502
|
$ sanity-run functions env add MyFunction API_URL https://api.example.com/
|
|
499
503
|
```
|
|
500
504
|
|
|
501
|
-
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
505
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/functions/env/add.ts)_
|
|
502
506
|
|
|
503
507
|
## `sanity-run functions env list NAME`
|
|
504
508
|
|
|
@@ -522,7 +526,7 @@ EXAMPLES
|
|
|
522
526
|
$ sanity-run functions env list MyFunction
|
|
523
527
|
```
|
|
524
528
|
|
|
525
|
-
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
529
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/functions/env/list.ts)_
|
|
526
530
|
|
|
527
531
|
## `sanity-run functions env remove NAME KEY`
|
|
528
532
|
|
|
@@ -548,7 +552,7 @@ EXAMPLES
|
|
|
548
552
|
$ sanity-run functions env remove MyFunction API_URL
|
|
549
553
|
```
|
|
550
554
|
|
|
551
|
-
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
555
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/functions/env/remove.ts)_
|
|
552
556
|
|
|
553
557
|
## `sanity-run functions logs [NAME]`
|
|
554
558
|
|
|
@@ -588,7 +592,7 @@ EXAMPLES
|
|
|
588
592
|
$ sanity-run functions logs <name> --delete
|
|
589
593
|
```
|
|
590
594
|
|
|
591
|
-
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
595
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/functions/logs.ts)_
|
|
592
596
|
|
|
593
597
|
## `sanity-run functions test [NAME]`
|
|
594
598
|
|
|
@@ -642,7 +646,7 @@ EXAMPLES
|
|
|
642
646
|
$ sanity-run functions test <name> --event update --data-before '{ "title": "before" }' --data-after '{ "title": "after" }'
|
|
643
647
|
```
|
|
644
648
|
|
|
645
|
-
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.
|
|
649
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v14.5.0/src/commands/functions/test.ts)_
|
|
646
650
|
|
|
647
651
|
## `sanity-run help [COMMAND]`
|
|
648
652
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import AdmZip from 'adm-zip';
|
|
2
2
|
import type { Logger } from '../../utils/logger.js';
|
|
3
|
-
import type { AuthParams, CollectionFunction, FunctionResource } from '../../utils/types.js';
|
|
3
|
+
import type { AuthParams, CollectionFunction, FunctionResource, InstallerType } from '../../utils/types.js';
|
|
4
4
|
export declare const ASSET_CHECK_URL: string;
|
|
5
5
|
export declare const ASSET_STASH_URL: string;
|
|
6
|
-
export declare function stashAsset({ resource, auth, logger, }: {
|
|
6
|
+
export declare function stashAsset({ resource, auth, logger, installer, }: {
|
|
7
7
|
resource: FunctionResource | CollectionFunction;
|
|
8
8
|
auth: AuthParams;
|
|
9
9
|
logger: ReturnType<typeof Logger>;
|
|
10
|
+
installer?: InstallerType;
|
|
10
11
|
}): Promise<{
|
|
11
12
|
success: boolean;
|
|
12
13
|
assetId?: string;
|
|
@@ -14,14 +14,14 @@ const { apiUrl } = config;
|
|
|
14
14
|
const ASSETS_URL = `${apiUrl}vX/blueprints/assets`;
|
|
15
15
|
export const ASSET_CHECK_URL = `${ASSETS_URL}/check`;
|
|
16
16
|
export const ASSET_STASH_URL = `${ASSETS_URL}/stash`;
|
|
17
|
-
export async function stashAsset({ resource, auth, logger, }) {
|
|
17
|
+
export async function stashAsset({ resource, auth, logger, installer, }) {
|
|
18
18
|
const isCollection = isLocalFunctionCollection(resource);
|
|
19
19
|
const functions = isCollection ? resource.functions : [resource];
|
|
20
20
|
const combinedAsset = [];
|
|
21
21
|
const prepareErrors = [];
|
|
22
22
|
try {
|
|
23
23
|
for (const func of functions) {
|
|
24
|
-
const prepResult = await prepareAsset({ resource: func });
|
|
24
|
+
const prepResult = await prepareAsset({ resource: func }, { installer });
|
|
25
25
|
if (prepResult.success && prepResult.outputPath && prepResult.cleanup) {
|
|
26
26
|
combinedAsset.push({
|
|
27
27
|
name: func.name,
|
|
@@ -175,7 +175,18 @@ export function hashBuffer(buffer) {
|
|
|
175
175
|
}
|
|
176
176
|
export async function pathToZip(path) {
|
|
177
177
|
const stats = await fs.promises.stat(path);
|
|
178
|
-
const zip = new AdmZip(
|
|
178
|
+
const zip = new AdmZip(undefined, {
|
|
179
|
+
fs: {
|
|
180
|
+
...fs,
|
|
181
|
+
// @ts-expect-error monkey patching to return matching mtime for builds
|
|
182
|
+
statSync(path, options) {
|
|
183
|
+
const s = fs.statSync(path, options);
|
|
184
|
+
if (s)
|
|
185
|
+
s.mtime = new Date(0);
|
|
186
|
+
return s;
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
});
|
|
179
190
|
if (stats.isDirectory())
|
|
180
191
|
zip.addLocalFolder(path);
|
|
181
192
|
else
|
|
@@ -5,7 +5,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
5
5
|
import blueprintParserValidator from '@sanity/blueprints-parser';
|
|
6
6
|
import * as find from 'empathic/find';
|
|
7
7
|
import { createJiti } from 'jiti';
|
|
8
|
-
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
8
|
+
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULED, } from '../../constants.js';
|
|
9
9
|
import { isLocalFunctionResource, } from '../../utils/types.js';
|
|
10
10
|
import { validateResources } from '../../utils/validate/index.js';
|
|
11
11
|
import { validateFunctionResource } from '../../utils/validate/resource.js';
|
|
@@ -218,7 +218,7 @@ export async function readLocalBlueprint(logger, validate, blueprintPath) {
|
|
|
218
218
|
invalidReferenceTypes: [
|
|
219
219
|
SANITY_FUNCTION_DOCUMENT,
|
|
220
220
|
SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
221
|
-
|
|
221
|
+
SANITY_FUNCTION_SCHEDULED,
|
|
222
222
|
],
|
|
223
223
|
});
|
|
224
224
|
const parsedBlueprint = parserResult.result === 'valid' ? parserResult.blueprint : undefined;
|
|
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { cwd } from 'node:process';
|
|
5
|
+
import { SANITY_FUNCTION_PREFIX } from '../../constants.js';
|
|
5
6
|
import { styleText } from '../../utils/style-text.js';
|
|
6
7
|
import { writeOrUpdateNodeDependency } from '../node.js';
|
|
7
8
|
import { addResourceToBlueprint } from './blueprint.js';
|
|
@@ -63,7 +64,7 @@ export async function createFunctionResource(options, logger) {
|
|
|
63
64
|
const resourceJson = {
|
|
64
65
|
name,
|
|
65
66
|
src: `functions/${name}`,
|
|
66
|
-
type:
|
|
67
|
+
type: `${SANITY_FUNCTION_PREFIX}${typeName}`,
|
|
67
68
|
event: {
|
|
68
69
|
on: eventsOn,
|
|
69
70
|
},
|
|
@@ -8,7 +8,6 @@ export declare function logs(id: string, options: LoggingOptions, auth: AuthPara
|
|
|
8
8
|
ok: boolean;
|
|
9
9
|
error: any;
|
|
10
10
|
logs: any;
|
|
11
|
-
total: any;
|
|
12
11
|
}>;
|
|
13
12
|
export declare function deleteLogs(id: string, auth: AuthParams, logger: ReturnType<typeof Logger>): Promise<{
|
|
14
13
|
ok: boolean;
|
|
@@ -15,7 +15,6 @@ export async function logs(id, options, auth, logger) {
|
|
|
15
15
|
ok: response.ok,
|
|
16
16
|
error: response.ok ? null : json?.error?.message,
|
|
17
17
|
logs: response.ok ? json.logs : [],
|
|
18
|
-
total: response.ok ? json.total : 0,
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
export async function deleteLogs(id, auth, logger) {
|
|
@@ -8,6 +8,7 @@ import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
|
8
8
|
import { FUNCTION_TYPES } from '../../constants.js';
|
|
9
9
|
import { functionAddCore } from '../../cores/functions/index.js';
|
|
10
10
|
import { Logger } from '../../utils/logger.js';
|
|
11
|
+
import { INSTALLER_OPTIONS } from '../../utils/types.js';
|
|
11
12
|
// import {warn} from '../../utils/display/presenters.js'
|
|
12
13
|
export default class AddCommand extends LocalBlueprintCommand {
|
|
13
14
|
// static state = 'deprecated'
|
|
@@ -69,7 +70,7 @@ After adding a function, use 'functions dev' to test locally, then 'blueprints d
|
|
|
69
70
|
'fn-installer': Flags.string({
|
|
70
71
|
description: 'Which package manager to use when installing the @sanity/functions helpers',
|
|
71
72
|
aliases: ['function-installer', 'installer'],
|
|
72
|
-
options: ['skip',
|
|
73
|
+
options: ['skip', ...INSTALLER_OPTIONS],
|
|
73
74
|
}),
|
|
74
75
|
install: Flags.boolean({
|
|
75
76
|
description: 'Shortcut for --fn-installer npm',
|
|
@@ -5,6 +5,7 @@ export default class DeployCommand extends DeployedStackCommand<typeof DeployCom
|
|
|
5
5
|
static examples: string[];
|
|
6
6
|
static flags: {
|
|
7
7
|
stack: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
'fn-installer': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
9
|
'no-wait': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
9
10
|
'new-stack-name': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
11
|
};
|
|
@@ -2,6 +2,7 @@ import { Flags } from '@oclif/core';
|
|
|
2
2
|
import { DeployedStackCommand, stackFlag, unhide } from '../../baseCommands.js';
|
|
3
3
|
import { blueprintDeployCore } from '../../cores/blueprints/deploy.js';
|
|
4
4
|
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
import { INSTALLER_OPTIONS } from '../../utils/types.js';
|
|
5
6
|
export default class DeployCommand extends DeployedStackCommand {
|
|
6
7
|
static summary = 'Deploy the local Blueprint to the remote Stack';
|
|
7
8
|
static description = `Pushes your local Blueprint configuration to the remote Stack; provisioning, updating, or destroying resources as needed. This is the primary command for applying infrastructure changes.
|
|
@@ -10,13 +11,22 @@ Before deploying, run 'blueprints plan' to preview changes. After deployment, us
|
|
|
10
11
|
|
|
11
12
|
Use --no-wait to queue the deployment and return immediately without waiting for completion.
|
|
12
13
|
|
|
14
|
+
Use --fn-installer to force which package manager to use when deploying functions.
|
|
15
|
+
|
|
13
16
|
Set SANITY_ASSET_TIMEOUT (seconds) to override the 60-second timeout for processing resource assets.`;
|
|
14
17
|
static examples = [
|
|
15
18
|
'<%= config.bin %> <%= command.id %>',
|
|
16
19
|
'<%= config.bin %> <%= command.id %> --no-wait',
|
|
20
|
+
'<%= config.bin %> <%= command.id %> --fn-installer npm',
|
|
17
21
|
];
|
|
18
22
|
static flags = {
|
|
19
23
|
stack: unhide(stackFlag),
|
|
24
|
+
'fn-installer': Flags.string({
|
|
25
|
+
description: 'Which package manager to use when installing Function dependencies',
|
|
26
|
+
aliases: ['function-installer', 'installer'],
|
|
27
|
+
options: [...INSTALLER_OPTIONS],
|
|
28
|
+
hidden: true,
|
|
29
|
+
}),
|
|
20
30
|
'no-wait': Flags.boolean({
|
|
21
31
|
description: 'Do not wait for Stack deployment to complete',
|
|
22
32
|
default: false,
|
|
@@ -3,6 +3,7 @@ import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
|
3
3
|
import { FUNCTION_TYPES } from '../../constants.js';
|
|
4
4
|
import { functionAddCore } from '../../cores/functions/index.js';
|
|
5
5
|
import { Logger } from '../../utils/logger.js';
|
|
6
|
+
import { INSTALLER_OPTIONS } from '../../utils/types.js';
|
|
6
7
|
export default class AddCommand extends LocalBlueprintCommand {
|
|
7
8
|
static summary = 'Add a Function to your Blueprint';
|
|
8
9
|
static description = `Scaffolds a new Function in the functions/ folder and templates a resource for your Blueprint manifest.
|
|
@@ -51,7 +52,7 @@ After adding, use 'functions dev' to test locally, then 'blueprints deploy' to p
|
|
|
51
52
|
}),
|
|
52
53
|
installer: Flags.string({
|
|
53
54
|
description: 'How to install the @sanity/functions helpers',
|
|
54
|
-
options: ['skip',
|
|
55
|
+
options: ['skip', ...INSTALLER_OPTIONS],
|
|
55
56
|
}),
|
|
56
57
|
install: Flags.boolean({
|
|
57
58
|
description: 'Shortcut for --fn-installer npm',
|
|
@@ -6,6 +6,7 @@ export default class BuildCommand extends LocalBlueprintCommand<typeof BuildComm
|
|
|
6
6
|
name: import("@oclif/core/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
7
7
|
};
|
|
8
8
|
static flags: {
|
|
9
|
+
'fn-installer': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
10
|
'out-dir': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
11
|
};
|
|
11
12
|
run(): Promise<void>;
|
|
@@ -2,6 +2,7 @@ import { Args, Flags } from '@oclif/core';
|
|
|
2
2
|
import { LocalBlueprintCommand } from '../../baseCommands.js';
|
|
3
3
|
import { functionBuildCore } from '../../cores/functions/build.js';
|
|
4
4
|
import { Logger } from '../../utils/logger.js';
|
|
5
|
+
import { INSTALLER_OPTIONS } from '../../utils/types.js';
|
|
5
6
|
export default class BuildCommand extends LocalBlueprintCommand {
|
|
6
7
|
static summary = 'Build Sanity Function(s) to zip archives';
|
|
7
8
|
static hidden = true;
|
|
@@ -9,6 +10,12 @@ export default class BuildCommand extends LocalBlueprintCommand {
|
|
|
9
10
|
name: Args.string({ description: 'The name of the Sanity Function', required: false }),
|
|
10
11
|
};
|
|
11
12
|
static flags = {
|
|
13
|
+
'fn-installer': Flags.string({
|
|
14
|
+
description: 'Which package manager to use when building Functions',
|
|
15
|
+
aliases: ['function-installer', 'installer'],
|
|
16
|
+
options: [...INSTALLER_OPTIONS],
|
|
17
|
+
hidden: true,
|
|
18
|
+
}),
|
|
12
19
|
'out-dir': Flags.string({ char: 'o', description: 'Output directory for zip files' }),
|
|
13
20
|
};
|
|
14
21
|
async run() {
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
export declare const SANITY_ACCESS_ROLE = "sanity.access.role";
|
|
2
2
|
export declare const SANITY_ACCESS_ROBOT = "sanity.access.robot";
|
|
3
|
+
export declare const SANITY_FUNCTION_PREFIX = "sanity.function.";
|
|
3
4
|
export declare const SANITY_FUNCTION_DOCUMENT = "sanity.function.document";
|
|
4
5
|
export declare const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = "sanity.function.media-library.asset";
|
|
5
|
-
export declare const
|
|
6
|
+
export declare const SANITY_FUNCTION_SCHEDULED = "sanity.function.cron";
|
|
7
|
+
export declare const SANITY_PROJECT = "sanity.project";
|
|
6
8
|
export declare const SANITY_PROJECT_CORS = "sanity.project.cors";
|
|
7
9
|
export declare const SANITY_PROJECT_DATASET = "sanity.project.dataset";
|
|
8
10
|
export declare const SANITY_PROJECT_WEBHOOK = "sanity.project.webhook";
|
|
11
|
+
export declare const EVENT_DOCUMENT_PUBLISH = "document-publish";
|
|
12
|
+
export declare const EVENT_DOCUMENT_CREATE = "document-create";
|
|
13
|
+
export declare const EVENT_DOCUMENT_UPDATE = "document-update";
|
|
14
|
+
export declare const EVENT_DOCUMENT_DELETE = "document-delete";
|
|
15
|
+
export declare const EVENT_MEDIA_LIBRARY_ASSET_CREATE = "media-library-asset-create";
|
|
16
|
+
export declare const EVENT_MEDIA_LIBRARY_ASSET_UPDATE = "media-library-asset-update";
|
|
17
|
+
export declare const EVENT_MEDIA_LIBRARY_ASSET_DELETE = "media-library-asset-delete";
|
|
18
|
+
export declare const EVENT_SCHEDULED = "scheduled-function";
|
|
9
19
|
export declare const FUNCTION_TYPES: string[];
|
|
10
20
|
export declare const MAX_ASSET_SIZE = 209715200;
|
|
11
21
|
export declare const CONVERT_BYTES_TO_MB = 1048576;
|
|
22
|
+
export declare const LABEL_DOCUMENT_CREATE = "Document Create";
|
|
23
|
+
export declare const LABEL_DOCUMENT_UPDATE = "Document Update";
|
|
24
|
+
export declare const LABEL_DOCUMENT_DELETE = "Document Delete";
|
|
25
|
+
export declare const LABEL_MEDIA_LIBRARY_ASSET_CREATE = "Media Library Asset Create";
|
|
26
|
+
export declare const LABEL_MEDIA_LIBRARY_ASSET_UPDATE = "Media Library Asset Update";
|
|
27
|
+
export declare const LABEL_MEDIA_LIBRARY_ASSET_DELETE = "Media Library Asset Delete";
|
|
28
|
+
export declare const LABEL_SCHEDULED = "Scheduled";
|
package/dist/constants.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
export const SANITY_ACCESS_ROLE = 'sanity.access.role';
|
|
2
2
|
export const SANITY_ACCESS_ROBOT = 'sanity.access.robot';
|
|
3
|
+
export const SANITY_FUNCTION_PREFIX = 'sanity.function.';
|
|
3
4
|
export const SANITY_FUNCTION_DOCUMENT = 'sanity.function.document';
|
|
4
5
|
export const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = 'sanity.function.media-library.asset';
|
|
5
|
-
export const
|
|
6
|
+
export const SANITY_FUNCTION_SCHEDULED = 'sanity.function.cron';
|
|
7
|
+
export const SANITY_PROJECT = 'sanity.project';
|
|
6
8
|
export const SANITY_PROJECT_CORS = 'sanity.project.cors';
|
|
7
9
|
export const SANITY_PROJECT_DATASET = 'sanity.project.dataset';
|
|
8
10
|
export const SANITY_PROJECT_WEBHOOK = 'sanity.project.webhook';
|
|
11
|
+
export const EVENT_DOCUMENT_PUBLISH = 'document-publish';
|
|
12
|
+
export const EVENT_DOCUMENT_CREATE = 'document-create';
|
|
13
|
+
export const EVENT_DOCUMENT_UPDATE = 'document-update';
|
|
14
|
+
export const EVENT_DOCUMENT_DELETE = 'document-delete';
|
|
15
|
+
export const EVENT_MEDIA_LIBRARY_ASSET_CREATE = 'media-library-asset-create';
|
|
16
|
+
export const EVENT_MEDIA_LIBRARY_ASSET_UPDATE = 'media-library-asset-update';
|
|
17
|
+
export const EVENT_MEDIA_LIBRARY_ASSET_DELETE = 'media-library-asset-delete';
|
|
18
|
+
export const EVENT_SCHEDULED = 'scheduled-function';
|
|
9
19
|
export const FUNCTION_TYPES = [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
EVENT_DOCUMENT_PUBLISH,
|
|
21
|
+
EVENT_DOCUMENT_CREATE,
|
|
22
|
+
EVENT_DOCUMENT_UPDATE,
|
|
23
|
+
EVENT_DOCUMENT_DELETE,
|
|
24
|
+
EVENT_MEDIA_LIBRARY_ASSET_CREATE,
|
|
25
|
+
EVENT_MEDIA_LIBRARY_ASSET_UPDATE,
|
|
26
|
+
EVENT_MEDIA_LIBRARY_ASSET_DELETE,
|
|
27
|
+
EVENT_SCHEDULED,
|
|
18
28
|
];
|
|
19
29
|
export const MAX_ASSET_SIZE = 209_715_200; // 200 MB in bytes
|
|
20
30
|
export const CONVERT_BYTES_TO_MB = 1_048_576; // Used to convert bytes to megabytes (1024 * 1024)
|
|
31
|
+
export const LABEL_DOCUMENT_CREATE = 'Document Create';
|
|
32
|
+
export const LABEL_DOCUMENT_UPDATE = 'Document Update';
|
|
33
|
+
export const LABEL_DOCUMENT_DELETE = 'Document Delete';
|
|
34
|
+
export const LABEL_MEDIA_LIBRARY_ASSET_CREATE = 'Media Library Asset Create';
|
|
35
|
+
export const LABEL_MEDIA_LIBRARY_ASSET_UPDATE = 'Media Library Asset Update';
|
|
36
|
+
export const LABEL_MEDIA_LIBRARY_ASSET_DELETE = 'Media Library Asset Delete';
|
|
37
|
+
export const LABEL_SCHEDULED = 'Scheduled';
|
|
@@ -14,6 +14,7 @@ export async function blueprintDeployCore(options) {
|
|
|
14
14
|
const { verbose } = flags;
|
|
15
15
|
const noWait = flags['no-wait'] || false;
|
|
16
16
|
const stackName = flags['new-stack-name'] ?? deployedStack.name;
|
|
17
|
+
const installer = flags['fn-installer'] || undefined;
|
|
17
18
|
log(`Deploying "${stackName}" ${niceId(deployedStack.id)}...`);
|
|
18
19
|
try {
|
|
19
20
|
const { ok: checkOk, stack: currentStack } = await getStack({ stackId, auth, logger: log });
|
|
@@ -44,7 +45,7 @@ export async function blueprintDeployCore(options) {
|
|
|
44
45
|
let result;
|
|
45
46
|
try {
|
|
46
47
|
result = await Promise.race([
|
|
47
|
-
stashAsset({ resource, auth, logger: log }),
|
|
48
|
+
stashAsset({ resource, auth, logger: log, installer }),
|
|
48
49
|
new Promise((_, reject) => {
|
|
49
50
|
assetTimeoutTimer = setTimeout(() => {
|
|
50
51
|
reject(new Error(`Processing ${resource.name} timed out after ${assetTimeoutS}s`));
|
|
@@ -5,7 +5,7 @@ import { checkbox, confirm, input, select } from '@inquirer/prompts';
|
|
|
5
5
|
import { highlight } from 'cardinal';
|
|
6
6
|
import { createFunctionResource } from '../../actions/blueprints/resources.js';
|
|
7
7
|
import { verifyExampleExists, writeExample } from '../../actions/sanity/examples.js';
|
|
8
|
-
import { FUNCTION_TYPES, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
8
|
+
import { EVENT_DOCUMENT_CREATE, EVENT_DOCUMENT_DELETE, EVENT_DOCUMENT_UPDATE, EVENT_MEDIA_LIBRARY_ASSET_CREATE, EVENT_MEDIA_LIBRARY_ASSET_DELETE, EVENT_MEDIA_LIBRARY_ASSET_UPDATE, EVENT_SCHEDULED, FUNCTION_TYPES, LABEL_DOCUMENT_CREATE, LABEL_DOCUMENT_DELETE, LABEL_DOCUMENT_UPDATE, LABEL_MEDIA_LIBRARY_ASSET_CREATE, LABEL_MEDIA_LIBRARY_ASSET_DELETE, LABEL_MEDIA_LIBRARY_ASSET_UPDATE, LABEL_SCHEDULED, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULED, } from '../../constants.js';
|
|
9
9
|
import { check, indent, warn } from '../../utils/display/presenters.js';
|
|
10
10
|
import { styleText } from '../../utils/style-text.js';
|
|
11
11
|
import { validateFunctionName } from '../../utils/validate/resource.js';
|
|
@@ -20,7 +20,7 @@ const generateFunctionBlueprintResourceTemplate = (fnName, eventNames) => {
|
|
|
20
20
|
case 'media':
|
|
21
21
|
definer = `defineMediaLibraryAssetFunction({name: '${fnName}', event: {on: [${eventOns.join(', ')}], resource: {type: 'media-library', id: 'my-media-library-id'}}}), // ← add this line`;
|
|
22
22
|
break;
|
|
23
|
-
case '
|
|
23
|
+
case 'scheduled':
|
|
24
24
|
definer = `defineScheduleFunction({name: '${fnName}', event: {expression: '0 0 * * *'}}), // ← add this line`;
|
|
25
25
|
break;
|
|
26
26
|
}
|
|
@@ -86,8 +86,8 @@ export async function functionAddCore(options) {
|
|
|
86
86
|
case SANITY_FUNCTION_MEDIA_LIBRARY_ASSET:
|
|
87
87
|
type = 'MediaLibraryAsset';
|
|
88
88
|
break;
|
|
89
|
-
case
|
|
90
|
-
type =
|
|
89
|
+
case SANITY_FUNCTION_SCHEDULED:
|
|
90
|
+
type = LABEL_SCHEDULED;
|
|
91
91
|
break;
|
|
92
92
|
default:
|
|
93
93
|
}
|
|
@@ -230,13 +230,13 @@ async function promptForFunctionType() {
|
|
|
230
230
|
const functionTypes = await checkbox({
|
|
231
231
|
message: 'Choose events to trigger your function:',
|
|
232
232
|
choices: [
|
|
233
|
-
{ name:
|
|
234
|
-
{ name:
|
|
235
|
-
{ name:
|
|
236
|
-
{ name:
|
|
237
|
-
{ name:
|
|
238
|
-
{ name:
|
|
239
|
-
{ name:
|
|
233
|
+
{ name: LABEL_DOCUMENT_CREATE, value: EVENT_DOCUMENT_CREATE, checked: true },
|
|
234
|
+
{ name: LABEL_DOCUMENT_UPDATE, value: EVENT_DOCUMENT_UPDATE, checked: true },
|
|
235
|
+
{ name: LABEL_DOCUMENT_DELETE, value: EVENT_DOCUMENT_DELETE },
|
|
236
|
+
{ name: LABEL_MEDIA_LIBRARY_ASSET_CREATE, value: EVENT_MEDIA_LIBRARY_ASSET_CREATE },
|
|
237
|
+
{ name: LABEL_MEDIA_LIBRARY_ASSET_UPDATE, value: EVENT_MEDIA_LIBRARY_ASSET_UPDATE },
|
|
238
|
+
{ name: LABEL_MEDIA_LIBRARY_ASSET_DELETE, value: EVENT_MEDIA_LIBRARY_ASSET_DELETE },
|
|
239
|
+
{ name: LABEL_SCHEDULED, value: EVENT_SCHEDULED },
|
|
240
240
|
],
|
|
241
241
|
validate(choices) {
|
|
242
242
|
if (choices.length === 0) {
|
|
@@ -244,9 +244,9 @@ async function promptForFunctionType() {
|
|
|
244
244
|
}
|
|
245
245
|
const hasMedia = choices.some((c) => String(c.value).startsWith('media-library'));
|
|
246
246
|
const hasDocument = choices.some((c) => String(c.value).startsWith('document'));
|
|
247
|
-
const hasSchedule = choices.some((c) => String(c.value).startsWith('
|
|
247
|
+
const hasSchedule = choices.some((c) => String(c.value).startsWith('scheduled'));
|
|
248
248
|
if ((hasMedia && hasDocument) || (hasMedia && hasSchedule) || (hasDocument && hasSchedule)) {
|
|
249
|
-
return 'You cannot mix Document, Media Library Asset, and
|
|
249
|
+
return 'You cannot mix Document, Media Library Asset, and Scheduled events together in one Function';
|
|
250
250
|
}
|
|
251
251
|
return true;
|
|
252
252
|
},
|
|
@@ -20,13 +20,14 @@ export async function functionBuildCore(options) {
|
|
|
20
20
|
else {
|
|
21
21
|
functions = allFunctions;
|
|
22
22
|
}
|
|
23
|
+
const installer = flags['fn-installer'] || undefined;
|
|
23
24
|
const outDir = flags['out-dir'] || path.join(path.dirname(blueprint.fileInfo.blueprintFilePath), '.build');
|
|
24
25
|
await fs.promises.mkdir(outDir, { recursive: true });
|
|
25
26
|
const errors = [];
|
|
26
27
|
const built = [];
|
|
27
28
|
for (const resource of functions) {
|
|
28
29
|
const spinner = log.ora(`Building ${resource.name}...`).start();
|
|
29
|
-
const prepResult = await prepareAsset({ resource });
|
|
30
|
+
const prepResult = await prepareAsset({ resource }, { installer });
|
|
30
31
|
if (!prepResult.success || !prepResult.outputPath) {
|
|
31
32
|
spinner.fail(`Failed to build ${resource.name}`);
|
|
32
33
|
errors.push({ name: resource.name, error: prepResult.error ?? 'Unknown error' });
|