@sanity/runtime-cli 17.19.0 → 17.20.0-next.g79e3313
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/assets.js +1 -1
- package/dist/actions/blueprints/pre-deploy.js +12 -1
- package/dist/actions/functions/env/list.d.ts +5 -1
- package/dist/actions/functions/env/list.js +5 -5
- package/dist/actions/functions/env/remove.d.ts +1 -1
- package/dist/actions/functions/env/remove.js +2 -2
- package/dist/actions/functions/env/update.d.ts +1 -1
- package/dist/actions/functions/env/update.js +2 -2
- package/dist/actions/functions/list.js +3 -6
- package/dist/actions/functions/logs.d.ts +6 -2
- package/dist/actions/functions/logs.js +6 -7
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +1 -0
- package/dist/utils/agents/build-package.d.ts +22 -0
- package/dist/utils/agents/build-package.js +61 -0
- package/dist/utils/agents/prepare-asset.d.ts +12 -0
- package/dist/utils/agents/prepare-asset.js +54 -0
- package/dist/utils/functions/api-error.d.ts +6 -0
- package/dist/utils/functions/api-error.js +25 -0
- package/dist/utils/types.d.ts +14 -0
- package/dist/utils/types.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.
|
|
646
|
+
_See code: [src/commands/functions/dev.ts](https://github.com/sanity-io/runtime-cli/blob/v17.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/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.20.0-next.g79e3313/src/commands/functions/test.ts)_
|
|
840
840
|
|
|
841
841
|
## `sanity-run help [COMMAND]`
|
|
842
842
|
|
|
@@ -7,7 +7,7 @@ export const assetStashUrl = `${assetsUrl}/stash`;
|
|
|
7
7
|
export async function stashAsset({ resolvedResource, prepAsset, auth, blueprintFileDir, fetchFn, installer, }) {
|
|
8
8
|
let cleanup = async () => { };
|
|
9
9
|
try {
|
|
10
|
-
const prepResult = await prepAsset({ resolvedResource, blueprintFileDir, installer });
|
|
10
|
+
const prepResult = await prepAsset({ resolvedResource, blueprintFileDir, installer, auth });
|
|
11
11
|
if (prepResult.success === false) {
|
|
12
12
|
await prepResult.cleanup();
|
|
13
13
|
return {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { SANITY_FUNCTION_PREFIX } from '../../constants.js';
|
|
1
|
+
import { SANITY_AGENT_TYPE, SANITY_FUNCTION_PREFIX } from '../../constants.js';
|
|
2
|
+
import { prepareAsset as prepareAgentAsset } from '../../utils/agents/prepare-asset.js';
|
|
2
3
|
import { resolveDeployedResources } from '../../utils/blueprints/resolve-deployed-resources.js';
|
|
3
4
|
import { BUNDLE_SPECS, prepareBundleAsset, } from '../../utils/bundles/prepare-asset.js';
|
|
4
5
|
import { stampConfigVersion } from '../../utils/bundles/stamp-config-version.js';
|
|
@@ -39,6 +40,16 @@ const preDeployConfigs = [
|
|
|
39
40
|
await extractDurableConfig(options.resource, options.blueprintFileDir);
|
|
40
41
|
},
|
|
41
42
|
},
|
|
43
|
+
{
|
|
44
|
+
resourceType: SANITY_AGENT_TYPE,
|
|
45
|
+
async prepareAsset(options) {
|
|
46
|
+
return prepareAgentAsset({
|
|
47
|
+
resource: options.resolvedResource.resource,
|
|
48
|
+
blueprintFileDir: options.blueprintFileDir,
|
|
49
|
+
auth: options.auth,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
},
|
|
42
53
|
];
|
|
43
54
|
function hasPreDeployResources(resources) {
|
|
44
55
|
return resources.some((r) => {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { Logger } from '../../../utils/logger.js';
|
|
2
2
|
import type { AuthParams } from '../../../utils/types.js';
|
|
3
3
|
export declare function list(id: string, auth: AuthParams, logger: Logger): Promise<{
|
|
4
|
+
ok: boolean;
|
|
5
|
+
envvars: never[];
|
|
6
|
+
error: string;
|
|
7
|
+
} | {
|
|
4
8
|
ok: boolean;
|
|
5
9
|
envvars: any;
|
|
6
|
-
error:
|
|
10
|
+
error: null;
|
|
7
11
|
}>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import config from '../../../config.js';
|
|
2
|
+
import { extractFunctionsApiErrorMessage } from '../../../utils/functions/api-error.js';
|
|
2
3
|
import getHeaders from '../../../utils/get-headers.js';
|
|
3
4
|
import { createTracedFetch } from '../../../utils/traced-fetch.js';
|
|
4
5
|
const { apiUrl } = config;
|
|
@@ -8,10 +9,9 @@ export async function list(id, auth, logger) {
|
|
|
8
9
|
headers: getHeaders(auth),
|
|
9
10
|
method: 'GET',
|
|
10
11
|
});
|
|
12
|
+
if (!response.ok) {
|
|
13
|
+
return { ok: false, envvars: [], error: await extractFunctionsApiErrorMessage(response) };
|
|
14
|
+
}
|
|
11
15
|
const json = await response.json();
|
|
12
|
-
return {
|
|
13
|
-
ok: response.ok,
|
|
14
|
-
envvars: json.envvars,
|
|
15
|
-
error: response.ok ? null : json?.error?.message,
|
|
16
|
-
};
|
|
16
|
+
return { ok: true, envvars: json.envvars, error: null };
|
|
17
17
|
}
|
|
@@ -2,5 +2,5 @@ import type { Logger } from '../../../utils/logger.js';
|
|
|
2
2
|
import type { AuthParams } from '../../../utils/types.js';
|
|
3
3
|
export declare function remove(id: string, key: string, auth: AuthParams, logger: Logger): Promise<{
|
|
4
4
|
ok: boolean;
|
|
5
|
-
error:
|
|
5
|
+
error: string | null;
|
|
6
6
|
}>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import config from '../../../config.js';
|
|
2
|
+
import { extractFunctionsApiErrorMessage } from '../../../utils/functions/api-error.js';
|
|
2
3
|
import getHeaders from '../../../utils/get-headers.js';
|
|
3
4
|
import { createTracedFetch } from '../../../utils/traced-fetch.js';
|
|
4
5
|
const { apiUrl } = config;
|
|
@@ -8,9 +9,8 @@ export async function remove(id, key, auth, logger) {
|
|
|
8
9
|
headers: getHeaders(auth),
|
|
9
10
|
method: 'DELETE',
|
|
10
11
|
});
|
|
11
|
-
const json = response.ok ? undefined : await response.json();
|
|
12
12
|
return {
|
|
13
13
|
ok: response.ok,
|
|
14
|
-
error: response.ok ? null :
|
|
14
|
+
error: response.ok ? null : await extractFunctionsApiErrorMessage(response),
|
|
15
15
|
};
|
|
16
16
|
}
|
|
@@ -2,5 +2,5 @@ import type { Logger } from '../../../utils/logger.js';
|
|
|
2
2
|
import type { AuthParams } from '../../../utils/types.js';
|
|
3
3
|
export declare function update(id: string, key: string, value: string, auth: AuthParams, logger: Logger): Promise<{
|
|
4
4
|
ok: boolean;
|
|
5
|
-
error:
|
|
5
|
+
error: string | null;
|
|
6
6
|
}>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import config from '../../../config.js';
|
|
2
|
+
import { extractFunctionsApiErrorMessage } from '../../../utils/functions/api-error.js';
|
|
2
3
|
import getHeaders from '../../../utils/get-headers.js';
|
|
3
4
|
import { createTracedFetch } from '../../../utils/traced-fetch.js';
|
|
4
5
|
const { apiUrl } = config;
|
|
@@ -9,9 +10,8 @@ export async function update(id, key, value, auth, logger) {
|
|
|
9
10
|
headers: getHeaders(auth),
|
|
10
11
|
method: 'PUT',
|
|
11
12
|
});
|
|
12
|
-
const json = response.ok ? undefined : await response.json();
|
|
13
13
|
return {
|
|
14
14
|
ok: response.ok,
|
|
15
|
-
error: response.ok ? null :
|
|
15
|
+
error: response.ok ? null : await extractFunctionsApiErrorMessage(response),
|
|
16
16
|
};
|
|
17
17
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import config from '../../config.js';
|
|
2
|
+
import { extractFunctionsApiErrorMessage } from '../../utils/functions/api-error.js';
|
|
2
3
|
import getHeaders from '../../utils/get-headers.js';
|
|
3
4
|
import { createTracedFetch } from '../../utils/traced-fetch.js';
|
|
4
5
|
const { apiUrl } = config;
|
|
@@ -9,14 +10,10 @@ export async function listFunctions(auth, logger) {
|
|
|
9
10
|
headers: getHeaders(auth),
|
|
10
11
|
method: 'GET',
|
|
11
12
|
});
|
|
12
|
-
const payload = (await response.json());
|
|
13
13
|
if (!response.ok) {
|
|
14
|
-
return {
|
|
15
|
-
ok: false,
|
|
16
|
-
error: payload.error?.message ?? payload.message ?? 'Failed to list functions',
|
|
17
|
-
functions: [],
|
|
18
|
-
};
|
|
14
|
+
return { ok: false, error: await extractFunctionsApiErrorMessage(response), functions: [] };
|
|
19
15
|
}
|
|
16
|
+
const payload = (await response.json());
|
|
20
17
|
return {
|
|
21
18
|
ok: true,
|
|
22
19
|
error: null,
|
|
@@ -6,11 +6,15 @@ export interface LoggingOptions {
|
|
|
6
6
|
}
|
|
7
7
|
export declare function logs(id: string, options: LoggingOptions, auth: AuthParams, logger: Logger): Promise<{
|
|
8
8
|
ok: boolean;
|
|
9
|
-
error:
|
|
9
|
+
error: string;
|
|
10
|
+
logs: never[];
|
|
11
|
+
} | {
|
|
12
|
+
ok: boolean;
|
|
13
|
+
error: null;
|
|
10
14
|
logs: any;
|
|
11
15
|
}>;
|
|
12
16
|
export declare function deleteLogs(id: string, auth: AuthParams, logger: Logger): Promise<{
|
|
13
17
|
ok: boolean;
|
|
14
|
-
error:
|
|
18
|
+
error: string | null;
|
|
15
19
|
}>;
|
|
16
20
|
export declare function streamLogs(id: string, auth: AuthParams, onLog: (log: FunctionLog) => void, onOpen: () => void, onError: (error: string) => void, logger: Logger): () => void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EventSource } from 'eventsource';
|
|
2
2
|
import config from '../../config.js';
|
|
3
|
+
import { extractFunctionsApiErrorMessage } from '../../utils/functions/api-error.js';
|
|
3
4
|
import getHeaders from '../../utils/get-headers.js';
|
|
4
5
|
import { createTracedFetch } from '../../utils/traced-fetch.js';
|
|
5
6
|
const { apiUrl } = config;
|
|
@@ -10,12 +11,11 @@ export async function logs(id, options, auth, logger) {
|
|
|
10
11
|
headers: getHeaders(auth),
|
|
11
12
|
method: 'GET',
|
|
12
13
|
});
|
|
14
|
+
if (!response.ok) {
|
|
15
|
+
return { ok: false, error: await extractFunctionsApiErrorMessage(response), logs: [] };
|
|
16
|
+
}
|
|
13
17
|
const json = await response.json();
|
|
14
|
-
return {
|
|
15
|
-
ok: response.ok,
|
|
16
|
-
error: response.ok ? null : json?.error?.message,
|
|
17
|
-
logs: response.ok ? json.logs : [],
|
|
18
|
-
};
|
|
18
|
+
return { ok: true, error: null, logs: json.logs };
|
|
19
19
|
}
|
|
20
20
|
export async function deleteLogs(id, auth, logger) {
|
|
21
21
|
const fetchFn = createTracedFetch(logger);
|
|
@@ -23,10 +23,9 @@ export async function deleteLogs(id, auth, logger) {
|
|
|
23
23
|
headers: getHeaders(auth),
|
|
24
24
|
method: 'DELETE',
|
|
25
25
|
});
|
|
26
|
-
const json = response.ok ? null : await response.json();
|
|
27
26
|
return {
|
|
28
27
|
ok: response.ok,
|
|
29
|
-
error: response.ok ? null :
|
|
28
|
+
error: response.ok ? null : await extractFunctionsApiErrorMessage(response),
|
|
30
29
|
};
|
|
31
30
|
}
|
|
32
31
|
// Create streaming logs connection
|
package/dist/constants.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { DurableStepPhase } from './utils/types.js';
|
|
|
2
2
|
export declare const SANITY_ACCESS_ROLE = "sanity.access.role";
|
|
3
3
|
export declare const SANITY_ACCESS_ROBOT = "sanity.access.robot";
|
|
4
4
|
export declare const SANITY_FUNCTION_PREFIX = "sanity.function.";
|
|
5
|
+
export declare const SANITY_AGENT_TYPE = "sanity.agent";
|
|
5
6
|
export declare const SANITY_FUNCTION_DOCUMENT = "sanity.function.document";
|
|
6
7
|
export declare const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = "sanity.function.media-library.asset";
|
|
7
8
|
export declare const SANITY_FUNCTION_PUBSUB = "sanity.function.pubsub";
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const SANITY_ACCESS_ROLE = 'sanity.access.role';
|
|
2
2
|
export const SANITY_ACCESS_ROBOT = 'sanity.access.robot';
|
|
3
3
|
export const SANITY_FUNCTION_PREFIX = 'sanity.function.';
|
|
4
|
+
export const SANITY_AGENT_TYPE = 'sanity.agent';
|
|
4
5
|
export const SANITY_FUNCTION_DOCUMENT = 'sanity.function.document';
|
|
5
6
|
export const SANITY_FUNCTION_MEDIA_LIBRARY_ASSET = 'sanity.function.media-library.asset';
|
|
6
7
|
export const SANITY_FUNCTION_PUBSUB = 'sanity.function.pubsub';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import AdmZip from 'adm-zip';
|
|
2
|
+
import type { AgentResource } from '../types.js';
|
|
3
|
+
/** `sanityID` must be exactly 36 characters because the platform manifest gate requires it. */
|
|
4
|
+
export declare const SANITY_ID_LENGTH = 36;
|
|
5
|
+
/** The manifest written to `package.json` at the bundle root. */
|
|
6
|
+
export interface AgentManifest {
|
|
7
|
+
sanityID: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
region: string;
|
|
11
|
+
}
|
|
12
|
+
/** Derive the 36-character `sanityID` from the project scope id, as a UUID-shaped hash so it is stable across redeploys. */
|
|
13
|
+
export declare function deriveSanityId(scopeId: string): string;
|
|
14
|
+
/** Build the manifest from the resource and project scope. */
|
|
15
|
+
export declare function buildAgentManifest(resource: AgentResource, scopeId: string): AgentManifest;
|
|
16
|
+
/**
|
|
17
|
+
* Assemble the full bundle for a `sanity.agent` resource: the `package.json`
|
|
18
|
+
* manifest, the authored source under `agent/`, the `www/index.ts` app entry, a
|
|
19
|
+
* `public/` folder, and a `Dockerfile`. Asset prep is the only bundle producer;
|
|
20
|
+
* the Provider just reads the bytes, so the layout must be complete here.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildAgentPackage(agentPath: string, manifest: AgentManifest): AdmZip;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import AdmZip from 'adm-zip';
|
|
3
|
+
/** `sanityID` must be exactly 36 characters because the platform manifest gate requires it. */
|
|
4
|
+
export const SANITY_ID_LENGTH = 36;
|
|
5
|
+
/** Derive the 36-character `sanityID` from the project scope id, as a UUID-shaped hash so it is stable across redeploys. */
|
|
6
|
+
export function deriveSanityId(scopeId) {
|
|
7
|
+
const hex = crypto.createHash('sha256').update(scopeId).digest('hex');
|
|
8
|
+
return [
|
|
9
|
+
hex.slice(0, 8),
|
|
10
|
+
hex.slice(8, 12),
|
|
11
|
+
hex.slice(12, 16),
|
|
12
|
+
hex.slice(16, 20),
|
|
13
|
+
hex.slice(20, 32),
|
|
14
|
+
].join('-');
|
|
15
|
+
}
|
|
16
|
+
/** Build the manifest from the resource and project scope. */
|
|
17
|
+
export function buildAgentManifest(resource, scopeId) {
|
|
18
|
+
const manifest = {
|
|
19
|
+
sanityID: deriveSanityId(scopeId),
|
|
20
|
+
name: resource.name,
|
|
21
|
+
region: resource.region,
|
|
22
|
+
};
|
|
23
|
+
if (typeof resource.description === 'string' && resource.description.length > 0) {
|
|
24
|
+
manifest.description = resource.description;
|
|
25
|
+
}
|
|
26
|
+
return manifest;
|
|
27
|
+
}
|
|
28
|
+
/** The `www/index.{js,ts}` app entry the platform layout gate requires. */
|
|
29
|
+
const WWW_INDEX_TS = `// Generated by the sanity.agent asset prep. The app entry the platform build
|
|
30
|
+
// mounts: it re-exports the authored eve agent under agent/.
|
|
31
|
+
export {default} from '../agent/agent.js'
|
|
32
|
+
`;
|
|
33
|
+
/** The `Dockerfile` build context the platform layout gate requires. */
|
|
34
|
+
const DOCKERFILE = `# Generated by the sanity.agent asset prep.
|
|
35
|
+
FROM node:22-slim
|
|
36
|
+
WORKDIR /app
|
|
37
|
+
COPY . .
|
|
38
|
+
RUN npm install --omit=dev
|
|
39
|
+
EXPOSE 3000
|
|
40
|
+
CMD ["node", "www/index.js"]
|
|
41
|
+
`;
|
|
42
|
+
/** Keep file so the required `public/` folder exists even with no static assets. */
|
|
43
|
+
const PUBLIC_KEEP = '';
|
|
44
|
+
/**
|
|
45
|
+
* Assemble the full bundle for a `sanity.agent` resource: the `package.json`
|
|
46
|
+
* manifest, the authored source under `agent/`, the `www/index.ts` app entry, a
|
|
47
|
+
* `public/` folder, and a `Dockerfile`. Asset prep is the only bundle producer;
|
|
48
|
+
* the Provider just reads the bytes, so the layout must be complete here.
|
|
49
|
+
*/
|
|
50
|
+
export function buildAgentPackage(agentPath, manifest) {
|
|
51
|
+
const zip = new AdmZip();
|
|
52
|
+
zip.addFile('package.json', Buffer.from(JSON.stringify(manifest, null, 2), 'utf8'));
|
|
53
|
+
zip.addLocalFolder(agentPath, 'agent');
|
|
54
|
+
zip.addFile('www/index.ts', Buffer.from(WWW_INDEX_TS, 'utf8'));
|
|
55
|
+
zip.addFile('public/.gitkeep', Buffer.from(PUBLIC_KEEP, 'utf8'));
|
|
56
|
+
zip.addFile('Dockerfile', Buffer.from(DOCKERFILE, 'utf8'));
|
|
57
|
+
// Fixed entry times so the same input gives the same bytes, and the same asset id
|
|
58
|
+
for (const entry of zip.getEntries())
|
|
59
|
+
entry.header.time = new Date(0);
|
|
60
|
+
return zip;
|
|
61
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AgentResource, AssetPrepResult, AuthParams } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build the full bundle for a `sanity.agent` resource from its `src` source
|
|
4
|
+
* path, with the manifest inside the zip. Asset prep is the only bundle
|
|
5
|
+
* producer; the Provider just reads the prepared bytes. A failure returns
|
|
6
|
+
* `{success: false}`, failing the prep step before the Blueprints API is called.
|
|
7
|
+
*/
|
|
8
|
+
export declare function prepareAsset({ blueprintFileDir, resource, auth, }: {
|
|
9
|
+
blueprintFileDir: string;
|
|
10
|
+
resource: AgentResource;
|
|
11
|
+
auth?: AuthParams;
|
|
12
|
+
}): Promise<AssetPrepResult>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { CONVERT_BYTES_TO_MB, MAX_ASSET_SIZE } from '../../constants.js';
|
|
4
|
+
import { isFolderLargerThan } from '../functions/is-folder-larger-than.js';
|
|
5
|
+
import { buildAgentManifest, buildAgentPackage } from './build-package.js';
|
|
6
|
+
/**
|
|
7
|
+
* Build the full bundle for a `sanity.agent` resource from its `src` source
|
|
8
|
+
* path, with the manifest inside the zip. Asset prep is the only bundle
|
|
9
|
+
* producer; the Provider just reads the prepared bytes. A failure returns
|
|
10
|
+
* `{success: false}`, failing the prep step before the Blueprints API is called.
|
|
11
|
+
*/
|
|
12
|
+
export async function prepareAsset({ blueprintFileDir, resource, auth, }) {
|
|
13
|
+
if (!resource.src)
|
|
14
|
+
throw new Error('Resource src is required');
|
|
15
|
+
const cleanup = async () => { };
|
|
16
|
+
const agentPath = path.resolve(blueprintFileDir, resource.src);
|
|
17
|
+
try {
|
|
18
|
+
if (!auth?.scopeId) {
|
|
19
|
+
throw new Error('A project scope is required to build the agent package manifest.');
|
|
20
|
+
}
|
|
21
|
+
if (!resource.region) {
|
|
22
|
+
throw new Error('Resource region is required to build the agent package manifest.');
|
|
23
|
+
}
|
|
24
|
+
if (!existsSync(agentPath)) {
|
|
25
|
+
throw new Error(`Agent source path not found: ${agentPath}`);
|
|
26
|
+
}
|
|
27
|
+
if (isFolderLargerThan(agentPath, MAX_ASSET_SIZE)) {
|
|
28
|
+
throw new Error('Resource is larger than max asset size of 200 MB.');
|
|
29
|
+
}
|
|
30
|
+
const manifest = buildAgentManifest(resource, auth.scopeId);
|
|
31
|
+
const zip = buildAgentPackage(agentPath, manifest);
|
|
32
|
+
// Sum uncompressed entry sizes so the limit check reflects on-disk size.
|
|
33
|
+
const zipEntrySize = zip
|
|
34
|
+
.getEntries()
|
|
35
|
+
.map((entry) => entry.header.size)
|
|
36
|
+
.reduce((a, b) => a + b, 0);
|
|
37
|
+
if (zipEntrySize > MAX_ASSET_SIZE) {
|
|
38
|
+
throw new Error(`Asset size of ${(zipEntrySize / CONVERT_BYTES_TO_MB).toFixed(2)} MB exceeds the maximum allowed size of 200 MB.`);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
success: true,
|
|
42
|
+
outputBuffer: await zip.toBufferPromise(),
|
|
43
|
+
fileExtension: 'zip',
|
|
44
|
+
assetParameter: 'src',
|
|
45
|
+
cleanup,
|
|
46
|
+
metadata: {
|
|
47
|
+
assetBytes: zipEntrySize,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
return { success: false, cleanup, error: err instanceof Error ? err.message : `${err}` };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts a human-readable error message from a failed Functions HTTP API response.
|
|
3
|
+
* Specific to the Functions API, whose error bodies are produced by its `src/util/response.js` `errorResponse` helper:
|
|
4
|
+
* { error: 'INVALID_INPUT', message: 'Validation error: ...', details?: { errors: [{ message }] } }
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractFunctionsApiErrorMessage(response: Response): Promise<string>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isRecord } from '../is-record.js';
|
|
2
|
+
import { parseJsonObject } from '../parse-json-object.js';
|
|
3
|
+
/**
|
|
4
|
+
* Extracts a human-readable error message from a failed Functions HTTP API response.
|
|
5
|
+
* Specific to the Functions API, whose error bodies are produced by its `src/util/response.js` `errorResponse` helper:
|
|
6
|
+
* { error: 'INVALID_INPUT', message: 'Validation error: ...', details?: { errors: [{ message }] } }
|
|
7
|
+
*/
|
|
8
|
+
export async function extractFunctionsApiErrorMessage(response) {
|
|
9
|
+
const body = parseJsonObject(await response.text().catch(() => ''));
|
|
10
|
+
if (typeof body?.message === 'string' && body.message)
|
|
11
|
+
return body.message;
|
|
12
|
+
const detailMessages = getDetailErrorMessages(body?.details);
|
|
13
|
+
if (detailMessages.length > 0)
|
|
14
|
+
return detailMessages.join('\n');
|
|
15
|
+
if (typeof body?.error === 'string' && body.error)
|
|
16
|
+
return body.error;
|
|
17
|
+
return `HTTP ${response.status} ${response.statusText}`.trim();
|
|
18
|
+
}
|
|
19
|
+
function getDetailErrorMessages(details) {
|
|
20
|
+
if (!isRecord(details) || !Array.isArray(details.errors))
|
|
21
|
+
return [];
|
|
22
|
+
return details.errors
|
|
23
|
+
.map((e) => (isRecord(e) ? e.message : e))
|
|
24
|
+
.filter((m) => typeof m === 'string' && m.length > 0);
|
|
25
|
+
}
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type BlueprintCorsOriginResource, type BlueprintDatasetResource, type BlueprintDocumentFunctionResource, type BlueprintDocumentWebhookResource, type BlueprintDurableFunctionResource, type BlueprintMediaLibraryAssetFunctionResource, type BlueprintProjectResource, type BlueprintPubSubFunctionResource, type BlueprintResource, type BlueprintRobotResource, type BlueprintRoleResource, type BlueprintScheduledFunctionResource, type BlueprintStudioResource, type BlueprintSyncTagInvalidateFunctionResource } from '@sanity/blueprints';
|
|
2
|
+
import { type SANITY_AGENT_TYPE } from '../constants.js';
|
|
2
3
|
export type ScopeType = 'organization' | 'project';
|
|
3
4
|
/** Result utility type */
|
|
4
5
|
export type Result<T, E = string> = {
|
|
@@ -46,6 +47,17 @@ export interface ResolvedResource<R extends BlueprintResource> {
|
|
|
46
47
|
externalId?: string;
|
|
47
48
|
}
|
|
48
49
|
export declare function isLocalFunctionResource(r: BlueprintResource): r is FunctionResource;
|
|
50
|
+
/**
|
|
51
|
+
* A `sanity.agent` resource. Declared here because `@sanity/blueprints` does not
|
|
52
|
+
* yet export the type; `name`, `description`, and `region` become the manifest.
|
|
53
|
+
*/
|
|
54
|
+
export interface AgentResource extends BlueprintResource {
|
|
55
|
+
type: typeof SANITY_AGENT_TYPE;
|
|
56
|
+
src: string;
|
|
57
|
+
/** Region name from the platform allowlist (e.g. `virginia`). */
|
|
58
|
+
region: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
}
|
|
49
61
|
export declare function hasEventSource(r: FunctionResource): r is EventFunctionResource;
|
|
50
62
|
export declare function isScheduleEvent(e: unknown): e is BlueprintScheduledFunctionResource['event'];
|
|
51
63
|
export declare function isCorsOriginResource(r: unknown): r is BlueprintCorsOriginResource;
|
|
@@ -345,6 +357,8 @@ export type PrepAssetFn<R extends BlueprintResource> = (options: {
|
|
|
345
357
|
resolvedResource: ResolvedResource<R>;
|
|
346
358
|
blueprintFileDir: string;
|
|
347
359
|
installer?: InstallerType;
|
|
360
|
+
/** Deploy auth; the agent prep uses `auth.scopeId` for the manifest `sanityID`. */
|
|
361
|
+
auth?: AuthParams;
|
|
348
362
|
}) => Promise<AssetPrepResult>;
|
|
349
363
|
export type PrepResourceFn<R extends BlueprintResource> = (options: {
|
|
350
364
|
resource: R;
|
package/dist/utils/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validateCorsOrigin, validateDataset, validateDocumentWebhook, validateDurableFunction, validateProject, validateRobot, validateRole, } from '@sanity/blueprints';
|
|
2
|
-
import { SANITY_FUNCTION_PREFIX, SANITY_FUNCTION_PUBSUB, SANITY_STUDIO } from '../constants.js';
|
|
2
|
+
import { SANITY_FUNCTION_PREFIX, SANITY_FUNCTION_PUBSUB, SANITY_STUDIO, } from '../constants.js';
|
|
3
3
|
export function isLocalFunctionResource(r) {
|
|
4
4
|
return r.type.startsWith(SANITY_FUNCTION_PREFIX);
|
|
5
5
|
}
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED