@sanity/runtime-cli 17.12.0 → 17.13.0-next.g06897b0
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 +21 -21
- package/dist/actions/blueprints/assets.d.ts +23 -20
- package/dist/actions/blueprints/assets.js +18 -87
- package/dist/actions/blueprints/logs-polling.d.ts +3 -5
- package/dist/actions/blueprints/logs-polling.js +4 -9
- package/dist/actions/blueprints/logs.d.ts +1 -2
- package/dist/actions/blueprints/logs.js +1 -3
- package/dist/actions/blueprints/operations-state.d.ts +10 -0
- package/dist/actions/blueprints/operations-state.js +42 -0
- package/dist/actions/blueprints/operations.d.ts +2 -9
- package/dist/actions/blueprints/operations.js +1 -15
- package/dist/actions/blueprints/pre-deploy.d.ts +19 -11
- package/dist/actions/blueprints/pre-deploy.js +95 -27
- package/dist/actions/blueprints/process-assets.d.ts +13 -11
- package/dist/actions/blueprints/process-assets.js +9 -7
- package/dist/actions/blueprints/stacks.d.ts +4 -4
- package/dist/actions/blueprints/stacks.js +2 -4
- package/dist/actions/blueprints/wait-for-operation.d.ts +1 -10
- package/dist/actions/blueprints/wait-for-operation.js +56 -101
- package/dist/baseCommands.js +6 -1
- package/dist/commands/blueprints/deploy.js +2 -0
- package/dist/commands/functions/dev.js +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.js +6 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/cores/blueprints/config.js +1 -1
- package/dist/cores/blueprints/deploy.d.ts +2 -0
- package/dist/cores/blueprints/deploy.js +38 -7
- package/dist/cores/blueprints/destroy.js +4 -2
- package/dist/cores/blueprints/doctor.js +2 -2
- package/dist/cores/blueprints/init.js +3 -1
- package/dist/cores/blueprints/logs.js +11 -5
- package/dist/cores/blueprints/mint-deploy-token.js +2 -1
- package/dist/cores/functions/build.js +4 -5
- package/dist/cores/functions/test.js +3 -1
- package/dist/cores/index.js +3 -1
- package/dist/server/app.d.ts +2 -1
- package/dist/server/app.js +4 -1
- package/dist/server/handlers/invoke.js +1 -1
- package/dist/server/static/vendor/vendor.bundle.js +21791 -25197
- package/dist/server/static/web-socket.js +4 -2
- package/dist/utils/blueprints/deploy-metadata.d.ts +10 -0
- package/dist/utils/blueprints/deploy-metadata.js +17 -0
- package/dist/utils/blueprints/resolve-deployed-resources.d.ts +2 -3
- package/dist/utils/blueprints/resolve-deployed-resources.js +2 -2
- package/dist/utils/blueprints/wait-for.d.ts +60 -0
- package/dist/utils/blueprints/wait-for.js +115 -0
- package/dist/utils/display/blueprints-formatting.d.ts +1 -0
- package/dist/utils/display/blueprints-formatting.js +17 -3
- package/dist/utils/display/dates.d.ts +0 -2
- package/dist/utils/display/dates.js +0 -25
- package/dist/utils/display/functions-formatting.js +1 -1
- package/dist/utils/display/prompt.js +5 -2
- package/dist/utils/display/resources-formatting.d.ts +6 -0
- package/dist/utils/display/resources-formatting.js +17 -0
- package/dist/utils/functions/child-runtime/durable.js +2 -2
- package/dist/utils/functions/dependency-info.d.ts +30 -0
- package/dist/utils/functions/dependency-info.js +57 -0
- package/dist/utils/functions/invoke/assert-console.d.ts +5 -0
- package/dist/utils/functions/invoke/assert-console.js +60 -0
- package/dist/utils/functions/invoke/local.js +9 -0
- package/dist/utils/functions/is-folder-larger-than.d.ts +5 -0
- package/dist/utils/functions/is-folder-larger-than.js +38 -0
- package/dist/utils/functions/prepare-asset.d.ts +2 -0
- package/dist/utils/functions/prepare-asset.js +59 -23
- package/dist/utils/studios/prepare-asset.js +36 -9
- package/dist/utils/types.d.ts +35 -4
- package/dist/utils/types.js +0 -3
- package/oclif.manifest.json +2 -2
- package/package.json +17 -19
- package/skills/functions-dev.md +1 -1
- package/dist/utils/functions/get-folder-size.d.ts +0 -5
- package/dist/utils/functions/get-folder-size.js +0 -24
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.
|
|
93
|
+
_See code: [src/commands/blueprints/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
130
|
+
_See code: [src/commands/blueprints/config.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
186
|
+
_See code: [src/commands/blueprints/deploy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
224
|
+
_See code: [src/commands/blueprints/destroy.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
256
|
+
_See code: [src/commands/blueprints/doctor.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
294
|
+
_See code: [src/commands/blueprints/info.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
358
|
+
_See code: [src/commands/blueprints/init.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
404
|
+
_See code: [src/commands/blueprints/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
449
|
+
_See code: [src/commands/blueprints/mint-deploy-token.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
482
|
+
_See code: [src/commands/blueprints/plan.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
518
|
+
_See code: [src/commands/blueprints/promote.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
559
|
+
_See code: [src/commands/blueprints/stacks.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
611
|
+
_See code: [src/commands/functions/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/src/commands/functions/add.ts)_
|
|
612
612
|
|
|
613
613
|
## `sanity-run functions dev`
|
|
614
614
|
|
|
@@ -632,8 +632,8 @@ DESCRIPTION
|
|
|
632
632
|
|
|
633
633
|
Open the emulator in your browser to interactively test your functions with the payload editor.
|
|
634
634
|
|
|
635
|
-
Optionally, set the host and port with the --host and --port flags.
|
|
636
|
-
|
|
635
|
+
Optionally, set the host and port with the --host and --port flags. The live-reload WebSocket server shares this host
|
|
636
|
+
and port. Function timeout can be configured with the --timeout flag.
|
|
637
637
|
|
|
638
638
|
To invoke a function with the CLI, use 'functions test'.
|
|
639
639
|
|
|
@@ -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.
|
|
646
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
679
|
+
_See code: [src/commands/functions/env/add.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
709
|
+
_See code: [src/commands/functions/env/list.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
741
|
+
_See code: [src/commands/functions/env/remove.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
781
|
+
_See code: [src/commands/functions/logs.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/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.
|
|
839
|
+
_See code: [src/commands/functions/test.ts](https://github.com/sanity-io/runtime-cli/blob/v17.13.0-next.g06897b0/src/commands/functions/test.ts)_
|
|
840
840
|
|
|
841
841
|
## `sanity-run help [COMMAND]`
|
|
842
842
|
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
import type { AssetResource, AuthParams, InstallerType } from '../../utils/types.js';
|
|
1
|
+
import type { BlueprintResource } from '@sanity/blueprints';
|
|
2
|
+
import type { AuthParams, InstallerType, PrepAssetFn } from '../../utils/types.js';
|
|
4
3
|
export declare const assetCheckUrl: string;
|
|
5
4
|
export declare const assetStashUrl: string;
|
|
6
|
-
export
|
|
7
|
-
|
|
5
|
+
export type StashAssetResult = {
|
|
6
|
+
success: true;
|
|
7
|
+
/** The id of the asset that was found or stashed */
|
|
8
|
+
assetId: string;
|
|
9
|
+
/** The parameter where the asset id should be stored in the resource */
|
|
10
|
+
assetParameter: string;
|
|
11
|
+
/** Whether the asset was already in the stash */
|
|
12
|
+
exists: boolean;
|
|
13
|
+
/** The asset hash for later lookup */
|
|
14
|
+
hash: string;
|
|
15
|
+
/** Facts learned about the resource while preparing its asset */
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
} | {
|
|
18
|
+
success: false;
|
|
19
|
+
error: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function stashAsset<R extends BlueprintResource>({ resource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }: {
|
|
22
|
+
resource: R;
|
|
23
|
+
prepAsset: PrepAssetFn<R>;
|
|
8
24
|
auth: AuthParams;
|
|
9
25
|
blueprintFileDir: string;
|
|
10
|
-
|
|
26
|
+
fetchFn: typeof fetch;
|
|
11
27
|
installer?: InstallerType;
|
|
12
|
-
}): Promise<
|
|
13
|
-
success: boolean;
|
|
14
|
-
assetId?: string;
|
|
15
|
-
exists?: boolean;
|
|
16
|
-
hash?: string;
|
|
17
|
-
error?: string;
|
|
18
|
-
}>;
|
|
28
|
+
}): Promise<StashAssetResult>;
|
|
19
29
|
export declare function hashBuffer(buffer: Buffer): string;
|
|
20
|
-
export declare function pathToZip(path: string): Promise<AdmZip>;
|
|
21
|
-
export declare function pathToB64ZipHash(path: string): Promise<{
|
|
22
|
-
b64: string;
|
|
23
|
-
buffer: Buffer;
|
|
24
|
-
hash: string;
|
|
25
|
-
zip: AdmZip;
|
|
26
|
-
}>;
|
|
@@ -1,67 +1,34 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { readFile } from 'node:fs/promises';
|
|
4
|
-
import AdmZip from 'adm-zip';
|
|
5
2
|
import { blueprintsUrl } from '../../config.js';
|
|
6
|
-
import { CONVERT_BYTES_TO_MB, MAX_ASSET_SIZE } from '../../constants.js';
|
|
7
|
-
import { prepareAsset as prepareFunctionAsset } from '../../utils/functions/prepare-asset.js';
|
|
8
3
|
import getHeaders from '../../utils/get-headers.js';
|
|
9
|
-
import { prepareStudioAsset } from '../../utils/studios/prepare-asset.js';
|
|
10
|
-
import { createTracedFetch } from '../../utils/traced-fetch.js';
|
|
11
|
-
import { isLocalFunctionResource, isStudioResource } from '../../utils/types.js';
|
|
12
4
|
const assetsUrl = blueprintsUrl('assets');
|
|
13
5
|
export const assetCheckUrl = `${assetsUrl}/check`;
|
|
14
6
|
export const assetStashUrl = `${assetsUrl}/stash`;
|
|
15
|
-
export async function stashAsset({ resource, auth, blueprintFileDir,
|
|
7
|
+
export async function stashAsset({ resource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }) {
|
|
16
8
|
let cleanup = async () => { };
|
|
17
9
|
try {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (isLocalFunctionResource(resource)) {
|
|
22
|
-
const prepResult = await prepareFunctionAsset({ resource, blueprintFileDir, installer });
|
|
23
|
-
if (prepResult.success === false) {
|
|
24
|
-
await prepResult.cleanup();
|
|
25
|
-
return {
|
|
26
|
-
success: false,
|
|
27
|
-
error: prepResult.error,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
cleanup = prepResult.cleanup;
|
|
31
|
-
const zipResult = await pathToB64ZipHash(prepResult.outputPath);
|
|
32
|
-
b64 = zipResult.b64;
|
|
33
|
-
hash = zipResult.hash;
|
|
34
|
-
extension = 'zip';
|
|
35
|
-
}
|
|
36
|
-
else if (isStudioResource(resource)) {
|
|
37
|
-
const prepResult = await prepareStudioAsset({ resource, blueprintFileDir });
|
|
38
|
-
if (prepResult.success === false) {
|
|
39
|
-
await prepResult.cleanup();
|
|
40
|
-
return {
|
|
41
|
-
success: false,
|
|
42
|
-
error: prepResult.error,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
cleanup = prepResult.cleanup;
|
|
46
|
-
const buffer = await readFile(prepResult.outputPath);
|
|
47
|
-
b64 = buffer.toString('base64');
|
|
48
|
-
hash = hashBuffer(buffer);
|
|
49
|
-
extension = 'tar.gz';
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
10
|
+
const prepResult = await prepAsset({ resource, blueprintFileDir, installer });
|
|
11
|
+
if (prepResult.success === false) {
|
|
12
|
+
await prepResult.cleanup();
|
|
52
13
|
return {
|
|
53
14
|
success: false,
|
|
54
|
-
error:
|
|
15
|
+
error: prepResult.error,
|
|
55
16
|
};
|
|
56
17
|
}
|
|
18
|
+
cleanup = prepResult.cleanup;
|
|
19
|
+
const b64 = prepResult.outputBuffer.toString('base64');
|
|
20
|
+
const hash = hashBuffer(prepResult.outputBuffer);
|
|
21
|
+
const extension = prepResult.fileExtension;
|
|
57
22
|
return await stashSingleAsset({
|
|
58
23
|
b64,
|
|
59
24
|
hash,
|
|
60
25
|
extension,
|
|
26
|
+
assetParameter: prepResult.assetParameter,
|
|
27
|
+
metadata: prepResult.metadata,
|
|
61
28
|
cleanup,
|
|
62
|
-
resource,
|
|
29
|
+
resourceName: resource.name,
|
|
63
30
|
auth,
|
|
64
|
-
|
|
31
|
+
fetchFn,
|
|
65
32
|
});
|
|
66
33
|
}
|
|
67
34
|
catch (err) {
|
|
@@ -74,8 +41,7 @@ export async function stashAsset({ resource, auth, blueprintFileDir, logger, ins
|
|
|
74
41
|
return { success: false, error: err instanceof Error ? err.message : `${err}` };
|
|
75
42
|
}
|
|
76
43
|
}
|
|
77
|
-
async function stashSingleAsset({ b64, hash, cleanup,
|
|
78
|
-
const fetchFn = createTracedFetch(logger);
|
|
44
|
+
async function stashSingleAsset({ b64, hash, cleanup, resourceName, auth, fetchFn, extension, assetParameter, metadata, }) {
|
|
79
45
|
try {
|
|
80
46
|
try {
|
|
81
47
|
const checkResponse = await fetchFn(`${assetCheckUrl}/${hash}`, {
|
|
@@ -84,7 +50,7 @@ async function stashSingleAsset({ b64, hash, cleanup, resource, auth, logger, ex
|
|
|
84
50
|
});
|
|
85
51
|
const checkJson = await checkResponse.json();
|
|
86
52
|
if (checkResponse.ok && checkJson.exists && checkJson.id) {
|
|
87
|
-
return { success: true, assetId: checkJson.id, exists: true, hash };
|
|
53
|
+
return { success: true, assetId: checkJson.id, assetParameter, exists: true, hash, metadata };
|
|
88
54
|
}
|
|
89
55
|
}
|
|
90
56
|
catch { } // Continue to stash the Asset
|
|
@@ -94,16 +60,16 @@ async function stashSingleAsset({ b64, hash, cleanup, resource, auth, logger, ex
|
|
|
94
60
|
headers: getHeaders(auth),
|
|
95
61
|
body: JSON.stringify({
|
|
96
62
|
file: b64,
|
|
97
|
-
filename: `${
|
|
63
|
+
filename: `${resourceName}.${extension}`,
|
|
98
64
|
}),
|
|
99
65
|
});
|
|
100
66
|
const assetJson = await assetResponse.json();
|
|
101
67
|
if (assetResponse.ok) {
|
|
102
|
-
return { success: true, assetId: assetJson.id, exists: false, hash };
|
|
68
|
+
return { success: true, assetId: assetJson.id, assetParameter, exists: false, hash, metadata };
|
|
103
69
|
}
|
|
104
70
|
return {
|
|
105
71
|
success: false,
|
|
106
|
-
error: `Failed to stash asset for ${
|
|
72
|
+
error: `Failed to stash asset for ${resourceName}: ${assetJson.message || 'Unknown error'}`,
|
|
107
73
|
};
|
|
108
74
|
}
|
|
109
75
|
catch (err) {
|
|
@@ -121,38 +87,3 @@ export function hashBuffer(buffer) {
|
|
|
121
87
|
hash.update(buffer);
|
|
122
88
|
return hash.digest('hex');
|
|
123
89
|
}
|
|
124
|
-
export async function pathToZip(path) {
|
|
125
|
-
const stats = await fs.promises.stat(path);
|
|
126
|
-
const zip = new AdmZip(undefined, {
|
|
127
|
-
fs: {
|
|
128
|
-
...fs,
|
|
129
|
-
// @ts-expect-error monkey patching to return matching mtime for builds
|
|
130
|
-
statSync(path, options) {
|
|
131
|
-
const s = fs.statSync(path, options);
|
|
132
|
-
if (s)
|
|
133
|
-
s.mtime = new Date(0);
|
|
134
|
-
return s;
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
if (stats.isDirectory())
|
|
139
|
-
zip.addLocalFolder(path);
|
|
140
|
-
else
|
|
141
|
-
zip.addLocalFile(path, '', 'index.js');
|
|
142
|
-
return zip;
|
|
143
|
-
}
|
|
144
|
-
export async function pathToB64ZipHash(path) {
|
|
145
|
-
const zip = await pathToZip(path);
|
|
146
|
-
// Add up the uncompressed sizes of all entries to get a more accurate size of the asset being uploaded
|
|
147
|
-
const size = zip
|
|
148
|
-
.getEntries()
|
|
149
|
-
.map((entry) => entry.header.size)
|
|
150
|
-
.reduce((a, b) => a + b, 0);
|
|
151
|
-
if (size > MAX_ASSET_SIZE) {
|
|
152
|
-
throw new Error(`Asset size of ${(size / CONVERT_BYTES_TO_MB).toFixed(2)} MB exceeds the maximum allowed size of 200 MB.`);
|
|
153
|
-
}
|
|
154
|
-
const buffer = zip.toBuffer();
|
|
155
|
-
const b64 = buffer.toString('base64');
|
|
156
|
-
const hash = hashBuffer(buffer);
|
|
157
|
-
return { b64, buffer, hash, zip };
|
|
158
|
-
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Logger } from '../../utils/logger.js';
|
|
2
1
|
import type { AuthParams, BlueprintLog } from '../../utils/types.js';
|
|
3
2
|
export declare const LOG_POLL_INTERVAL_MS = 725;
|
|
4
3
|
export interface LogPollingConfig {
|
|
@@ -6,11 +5,10 @@ export interface LogPollingConfig {
|
|
|
6
5
|
operationId?: string;
|
|
7
6
|
knownIds?: string[];
|
|
8
7
|
auth: AuthParams;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
log: Logger;
|
|
8
|
+
fetchFn: typeof fetch;
|
|
9
|
+
onShowBanner?: () => void;
|
|
12
10
|
onActivity?: () => void;
|
|
13
|
-
onLogEntry?: (
|
|
11
|
+
onLogEntry?: (logEntry: BlueprintLog, previousLog: BlueprintLog | undefined) => void;
|
|
14
12
|
}
|
|
15
13
|
/**
|
|
16
14
|
* Polls the logs list endpoint at a fixed interval and displays new entries.
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { formatLogEntry } from '../../utils/display/logs-formatting.js';
|
|
2
|
-
import { styleText } from '../../utils/style-text.js';
|
|
3
1
|
import { getLogs } from './logs.js';
|
|
4
2
|
export const LOG_POLL_INTERVAL_MS = 725;
|
|
5
3
|
/**
|
|
@@ -8,19 +6,17 @@ export const LOG_POLL_INTERVAL_MS = 725;
|
|
|
8
6
|
* @returns A cleanup function that stops polling
|
|
9
7
|
*/
|
|
10
8
|
export function setupLogPolling(config) {
|
|
11
|
-
const { stackId, operationId, auth,
|
|
9
|
+
const { stackId, operationId, auth, fetchFn } = config;
|
|
12
10
|
const seenIds = new Set(config.knownIds);
|
|
13
11
|
let previousLog;
|
|
14
12
|
let stopped = false;
|
|
15
|
-
|
|
16
|
-
log(`Watching logs... ${styleText('bold', 'ctrl+c')} to cancel`);
|
|
17
|
-
}
|
|
13
|
+
config.onShowBanner?.();
|
|
18
14
|
const fetchAndProcessLogs = async () => {
|
|
19
15
|
if (stopped)
|
|
20
16
|
return;
|
|
21
17
|
try {
|
|
22
18
|
const params = operationId ? { operationId } : { stackId };
|
|
23
|
-
const { ok, logs } = await getLogs(params, auth,
|
|
19
|
+
const { ok, logs } = await getLogs(params, auth, fetchFn);
|
|
24
20
|
if (!ok || stopped)
|
|
25
21
|
return;
|
|
26
22
|
// API returns newest first; reverse so we display in chronological order
|
|
@@ -28,8 +24,7 @@ export function setupLogPolling(config) {
|
|
|
28
24
|
for (const logEntry of newLogs) {
|
|
29
25
|
seenIds.add(logEntry.id);
|
|
30
26
|
config.onActivity?.();
|
|
31
|
-
config.onLogEntry?.(logEntry);
|
|
32
|
-
log(formatLogEntry(logEntry, verbose, previousLog));
|
|
27
|
+
config.onLogEntry?.(logEntry, previousLog);
|
|
33
28
|
previousLog = logEntry;
|
|
34
29
|
}
|
|
35
30
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Logger } from '../../utils/logger.js';
|
|
2
1
|
import type { ActionResponse, AuthParams, BlueprintLog } from '../../utils/types.js';
|
|
3
2
|
export declare const logsUrl: string;
|
|
4
3
|
export interface GetLogsParams {
|
|
@@ -8,7 +7,7 @@ export interface GetLogsParams {
|
|
|
8
7
|
before?: string;
|
|
9
8
|
after?: string;
|
|
10
9
|
}
|
|
11
|
-
export declare function getLogs(params: GetLogsParams, auth: AuthParams,
|
|
10
|
+
export declare function getLogs(params: GetLogsParams, auth: AuthParams, fetchFn: typeof fetch): Promise<ActionResponse & {
|
|
12
11
|
logs: BlueprintLog[];
|
|
13
12
|
hasMore: boolean;
|
|
14
13
|
}>;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { blueprintsUrl } from '../../config.js';
|
|
2
2
|
import getHeaders from '../../utils/get-headers.js';
|
|
3
|
-
import { createTracedFetch } from '../../utils/traced-fetch.js';
|
|
4
3
|
export const logsUrl = blueprintsUrl('logs');
|
|
5
|
-
export async function getLogs(params, auth,
|
|
6
|
-
const fetchFn = createTracedFetch(logger);
|
|
4
|
+
export async function getLogs(params, auth, fetchFn) {
|
|
7
5
|
const url = new URL(logsUrl);
|
|
8
6
|
if (params.stackId)
|
|
9
7
|
url.searchParams.append('stackId', params.stackId);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StateInfo } from '../../utils/blueprints/wait-for.js';
|
|
2
|
+
import type { AuthParams } from '../../utils/types.js';
|
|
3
|
+
export declare function getOperationStateInfo(options: {
|
|
4
|
+
stackId: string;
|
|
5
|
+
operationId: string;
|
|
6
|
+
auth: AuthParams;
|
|
7
|
+
fetchFn: typeof fetch;
|
|
8
|
+
includeDestroyed: boolean;
|
|
9
|
+
progressNoun: string;
|
|
10
|
+
}): Promise<StateInfo>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { classifyOperationPoll, getOperation } from './operations.js';
|
|
2
|
+
export async function getOperationStateInfo(options) {
|
|
3
|
+
const { stackId, operationId, auth, fetchFn, includeDestroyed, progressNoun } = options;
|
|
4
|
+
const { ok, error, operation, response } = await getOperation({
|
|
5
|
+
stackId,
|
|
6
|
+
operationId,
|
|
7
|
+
auth,
|
|
8
|
+
fetchFn,
|
|
9
|
+
includeDestroyed,
|
|
10
|
+
});
|
|
11
|
+
const httpStatus = response?.status;
|
|
12
|
+
const state = classifyOperationPoll({ ok, httpStatus, operation });
|
|
13
|
+
switch (state) {
|
|
14
|
+
case 'completed':
|
|
15
|
+
case 'failed':
|
|
16
|
+
return {
|
|
17
|
+
state,
|
|
18
|
+
};
|
|
19
|
+
case 'error':
|
|
20
|
+
return {
|
|
21
|
+
state,
|
|
22
|
+
error,
|
|
23
|
+
verboseError: `Could not read ${progressNoun} status (HTTP ${httpStatus ?? 'unknown'}${error ? `: ${error}` : ''})`,
|
|
24
|
+
};
|
|
25
|
+
case 'pending':
|
|
26
|
+
if (httpStatus === 404 || !operation) {
|
|
27
|
+
return {
|
|
28
|
+
state: 'not_found',
|
|
29
|
+
verboseError: `Waiting for ${progressNoun} status (HTTP 404); retrying.`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return {
|
|
34
|
+
state,
|
|
35
|
+
latestStatus: operation.status,
|
|
36
|
+
verboseMessage: `${progressNoun} operation status: ${operation.status}.`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
default:
|
|
40
|
+
throw new Error(`Unexpected poll state: ${state}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import type { Logger } from '../../utils/logger.js';
|
|
2
1
|
import type { ActionResponse, AuthParams, StackOperation } from '../../utils/types.js';
|
|
3
|
-
/** Delay before the first operation poll. Override with SANITY_OPERATION_POLL_INITIAL_DELAY_MS. */
|
|
4
|
-
export declare const OPERATION_POLL_INITIAL_DELAY_MS: number;
|
|
5
|
-
/** Interval between operation status polls. Override with SANITY_OPERATION_POLL_INTERVAL_MS. */
|
|
6
|
-
export declare const OPERATION_POLL_INTERVAL_MS: number;
|
|
7
|
-
/** Consecutive failed polls tolerated before giving up on confirming status. */
|
|
8
|
-
export declare const OPERATION_POLL_MAX_CONSECUTIVE_ERRORS = 5;
|
|
9
2
|
/**
|
|
10
3
|
* Classify a single poll. Terminal status -> 'completed'/'failed'. 404 ->
|
|
11
4
|
* 'pending' (read-replica lag). Other failed responses -> 'error'. The caller
|
|
@@ -20,11 +13,11 @@ interface GetOperationResponse extends ActionResponse {
|
|
|
20
13
|
operation?: StackOperation;
|
|
21
14
|
response?: Response;
|
|
22
15
|
}
|
|
23
|
-
export declare function getOperation({ stackId, operationId, auth,
|
|
16
|
+
export declare function getOperation({ stackId, operationId, auth, fetchFn, includeDestroyed, }: {
|
|
24
17
|
stackId: string;
|
|
25
18
|
operationId: string;
|
|
26
19
|
auth: AuthParams;
|
|
27
|
-
|
|
20
|
+
fetchFn: typeof fetch;
|
|
28
21
|
includeDestroyed?: boolean;
|
|
29
22
|
}): Promise<GetOperationResponse>;
|
|
30
23
|
export {};
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import getHeaders from '../../utils/get-headers.js';
|
|
2
|
-
import { createTracedFetch } from '../../utils/traced-fetch.js';
|
|
3
2
|
import { stacksUrl } from './stacks.js';
|
|
4
|
-
const envMs = (value, fallback) => {
|
|
5
|
-
if (!value)
|
|
6
|
-
return fallback;
|
|
7
|
-
const parsed = Number(value);
|
|
8
|
-
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
9
|
-
};
|
|
10
|
-
/** Delay before the first operation poll. Override with SANITY_OPERATION_POLL_INITIAL_DELAY_MS. */
|
|
11
|
-
export const OPERATION_POLL_INITIAL_DELAY_MS = envMs(process.env.SANITY_OPERATION_POLL_INITIAL_DELAY_MS, 1000);
|
|
12
|
-
/** Interval between operation status polls. Override with SANITY_OPERATION_POLL_INTERVAL_MS. */
|
|
13
|
-
export const OPERATION_POLL_INTERVAL_MS = envMs(process.env.SANITY_OPERATION_POLL_INTERVAL_MS, 1500);
|
|
14
|
-
/** Consecutive failed polls tolerated before giving up on confirming status. */
|
|
15
|
-
export const OPERATION_POLL_MAX_CONSECUTIVE_ERRORS = 5;
|
|
16
3
|
/**
|
|
17
4
|
* Classify a single poll. Terminal status -> 'completed'/'failed'. 404 ->
|
|
18
5
|
* 'pending' (read-replica lag). Other failed responses -> 'error'. The caller
|
|
@@ -31,8 +18,7 @@ export function classifyOperationPoll(options) {
|
|
|
31
18
|
return 'pending';
|
|
32
19
|
return 'error';
|
|
33
20
|
}
|
|
34
|
-
export async function getOperation({ stackId, operationId, auth,
|
|
35
|
-
const fetchFn = createTracedFetch(logger);
|
|
21
|
+
export async function getOperation({ stackId, operationId, auth, fetchFn, includeDestroyed, }) {
|
|
36
22
|
const url = new URL(`${stacksUrl}/${stackId}/operations/${operationId}`);
|
|
37
23
|
if (includeDestroyed)
|
|
38
24
|
url.searchParams.append('includeDestroyed', 'true');
|
|
@@ -1,38 +1,46 @@
|
|
|
1
1
|
import type { BlueprintResource } from '@sanity/blueprints';
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
2
|
+
import type { WaitForFn } from '../../utils/blueprints/wait-for.js';
|
|
3
|
+
import type { AuthParams, InstallerType, ResourceMetadata, ScopeType } from '../../utils/types.js';
|
|
4
4
|
import { type ProcessAssetsProgress, type ProcessedAsset } from './process-assets.js';
|
|
5
|
-
type
|
|
5
|
+
type PreDeployFailure = {
|
|
6
6
|
success: false;
|
|
7
7
|
error: string;
|
|
8
8
|
code?: string;
|
|
9
9
|
exitCode?: number;
|
|
10
10
|
suggestions?: string[];
|
|
11
|
-
}
|
|
11
|
+
};
|
|
12
|
+
export type PreDeployResult = PreDeployFailure | {
|
|
12
13
|
success: true;
|
|
14
|
+
/** One entry per prepared asset, for the deploy metadata */
|
|
15
|
+
resourceMetadata: ResourceMetadata[];
|
|
13
16
|
};
|
|
14
|
-
export type PreDeployAssetEvent = {
|
|
17
|
+
export type PreDeployAssetEvent<R extends BlueprintResource> = {
|
|
15
18
|
type: 'progress';
|
|
16
19
|
progress: ProcessAssetsProgress;
|
|
17
20
|
} | {
|
|
18
21
|
type: 'complete';
|
|
19
22
|
} | {
|
|
20
23
|
type: 'result';
|
|
21
|
-
result: ProcessedAsset
|
|
24
|
+
result: ProcessedAsset<R>;
|
|
22
25
|
};
|
|
23
|
-
type PreDeployOptions = {
|
|
26
|
+
type PreDeployOptions<R extends BlueprintResource> = {
|
|
24
27
|
scopeType: ScopeType;
|
|
25
28
|
scopeId: string;
|
|
26
29
|
resources: BlueprintResource[];
|
|
27
30
|
stackId: string;
|
|
28
31
|
stackName: string;
|
|
29
32
|
bin: string;
|
|
30
|
-
verbose: boolean | undefined;
|
|
31
33
|
auth: AuthParams;
|
|
32
34
|
blueprintFileDir: string;
|
|
33
35
|
installer: InstallerType;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
fetchFn: typeof fetch;
|
|
37
|
+
waitForFn: WaitForFn;
|
|
38
|
+
onAssetEvent?: (event: PreDeployAssetEvent<R>) => void;
|
|
39
|
+
onPreDeployStackStart?: () => void;
|
|
40
|
+
onPreDeployStackFail?: () => void;
|
|
41
|
+
onPreDeployStackDone?: () => void;
|
|
42
|
+
onPreDeployOperationStart?: () => void;
|
|
43
|
+
onPreDeployOperationDone?: () => void;
|
|
36
44
|
};
|
|
37
|
-
export declare function preDeploy(options: PreDeployOptions): Promise<PreDeployResult>;
|
|
45
|
+
export declare function preDeploy<R extends BlueprintResource>(options: PreDeployOptions<R>): Promise<PreDeployResult>;
|
|
38
46
|
export {};
|