@sanity/runtime-cli 14.7.2 → 14.8.1
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 +150 -99
- package/dist/actions/blueprints/assets.d.ts +4 -3
- package/dist/actions/blueprints/assets.js +69 -101
- package/dist/actions/blueprints/blueprint.d.ts +2 -2
- package/dist/actions/blueprints/blueprint.js +1 -8
- package/dist/actions/blueprints/config.d.ts +2 -2
- package/dist/actions/blueprints/logs-streaming.d.ts +2 -2
- package/dist/actions/blueprints/logs.d.ts +2 -4
- package/dist/actions/blueprints/resources.d.ts +3 -3
- package/dist/actions/blueprints/resources.js +30 -10
- package/dist/actions/blueprints/stacks.d.ts +15 -25
- package/dist/actions/functions/dev.d.ts +1 -1
- package/dist/actions/functions/env/list.d.ts +1 -1
- package/dist/actions/functions/env/remove.d.ts +1 -1
- package/dist/actions/functions/env/update.d.ts +1 -1
- package/dist/actions/functions/logs.d.ts +3 -3
- package/dist/actions/node.d.ts +1 -1
- package/dist/actions/sanity/examples.d.ts +2 -2
- package/dist/actions/sanity/projects.d.ts +7 -13
- package/dist/baseCommands.d.ts +8 -0
- package/dist/baseCommands.js +10 -4
- package/dist/commands/blueprints/config.d.ts +1 -1
- package/dist/commands/blueprints/config.js +5 -13
- package/dist/commands/blueprints/deploy.d.ts +1 -1
- package/dist/commands/blueprints/deploy.js +2 -1
- package/dist/commands/blueprints/destroy.d.ts +1 -1
- package/dist/commands/blueprints/destroy.js +5 -7
- package/dist/commands/blueprints/doctor.js +2 -2
- package/dist/commands/blueprints/info.d.ts +1 -1
- package/dist/commands/blueprints/info.js +2 -1
- package/dist/commands/blueprints/init.js +3 -11
- package/dist/commands/blueprints/plan.d.ts +1 -1
- package/dist/commands/blueprints/plan.js +2 -1
- package/dist/commands/blueprints/promote.d.ts +0 -1
- package/dist/commands/blueprints/promote.js +2 -6
- package/dist/commands/blueprints/stacks.d.ts +1 -1
- package/dist/commands/blueprints/stacks.js +5 -13
- package/dist/commands/functions/build.d.ts +1 -1
- package/dist/commands/functions/build.js +2 -1
- package/dist/commands/functions/env/add.d.ts +1 -1
- package/dist/commands/functions/env/add.js +2 -1
- package/dist/commands/functions/env/list.d.ts +1 -1
- package/dist/commands/functions/env/list.js +2 -1
- package/dist/commands/functions/env/remove.d.ts +1 -1
- package/dist/commands/functions/env/remove.js +2 -1
- package/dist/commands/functions/logs.d.ts +0 -1
- package/dist/commands/functions/logs.js +0 -5
- package/dist/commands/functions/test.d.ts +1 -1
- package/dist/commands/functions/test.js +5 -13
- package/dist/constants.d.ts +2 -1
- package/dist/cores/blueprints/config.js +11 -7
- package/dist/cores/blueprints/deploy.js +62 -74
- package/dist/cores/blueprints/destroy.js +3 -3
- package/dist/cores/blueprints/doctor.js +5 -1
- package/dist/cores/blueprints/info.js +1 -1
- package/dist/cores/blueprints/init.d.ts +4 -3
- package/dist/cores/blueprints/plan.js +7 -1
- package/dist/cores/blueprints/promote.d.ts +0 -1
- package/dist/cores/blueprints/promote.js +4 -4
- package/dist/cores/blueprints/stacks.js +6 -2
- package/dist/cores/functions/add.d.ts +1 -0
- package/dist/cores/functions/add.js +2 -2
- package/dist/cores/functions/build.js +2 -2
- package/dist/cores/functions/env/add.js +1 -1
- package/dist/cores/functions/env/list.js +1 -1
- package/dist/cores/functions/env/remove.js +1 -1
- package/dist/cores/functions/test.js +4 -4
- package/dist/cores/index.d.ts +9 -2
- package/dist/cores/index.js +3 -2
- package/dist/server/app.d.ts +1 -1
- package/dist/server/handlers/invoke.d.ts +1 -1
- package/dist/utils/display/prompt.d.ts +2 -2
- package/dist/utils/display/prompt.js +1 -1
- package/dist/utils/display/resources-formatting.d.ts +2 -2
- package/dist/utils/display/resources-formatting.js +1 -1
- package/dist/utils/functions/fetch-document.d.ts +2 -2
- package/dist/utils/functions/prepare-asset.d.ts +3 -8
- package/dist/utils/functions/prepare-asset.js +2 -2
- package/dist/utils/functions/should-auto-resolve-deps.js +1 -1
- package/dist/utils/functions/should-transpile.js +1 -1
- package/dist/utils/invoke-local.d.ts +1 -7
- package/dist/utils/invoke-local.js +5 -24
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/logger.js +2 -0
- package/dist/utils/other/github.d.ts +1 -1
- package/dist/utils/other/npmjs.d.ts +1 -1
- package/dist/utils/traced-fetch.d.ts +1 -1
- package/dist/utils/types.d.ts +21 -80
- package/dist/utils/types.js +6 -14
- package/dist/utils/validate/resource.d.ts +0 -3
- package/dist/utils/validate/resource.js +0 -270
- package/dist/utils/validated-token.d.ts +2 -2
- package/oclif.manifest.json +36 -90
- package/package.json +2 -2
|
@@ -1,131 +1,102 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
3
|
import AdmZip from 'adm-zip';
|
|
6
4
|
import config from '../../config.js';
|
|
7
5
|
import { CONVERT_BYTES_TO_MB, MAX_ASSET_SIZE } from '../../constants.js';
|
|
8
6
|
import { detectNativeModules } from '../../utils/functions/detect-native-modules.js';
|
|
9
|
-
import { prepareAsset } from '../../utils/functions/prepare-asset.js';
|
|
7
|
+
import { prepareAsset as prepareFunctionAsset } from '../../utils/functions/prepare-asset.js';
|
|
10
8
|
import getHeaders from '../../utils/get-headers.js';
|
|
11
9
|
import { createTracedFetch } from '../../utils/traced-fetch.js';
|
|
12
|
-
import {
|
|
10
|
+
import { isLocalFunctionResource, isStudioResource } from '../../utils/types.js';
|
|
13
11
|
const { apiUrl } = config;
|
|
14
12
|
const ASSETS_URL = `${apiUrl}vX/blueprints/assets`;
|
|
15
13
|
export const ASSET_CHECK_URL = `${ASSETS_URL}/check`;
|
|
16
14
|
export const ASSET_STASH_URL = `${ASSETS_URL}/stash`;
|
|
17
15
|
export async function stashAsset({ resource, auth, logger, installer, }) {
|
|
18
|
-
const isCollection = isLocalFunctionCollection(resource);
|
|
19
|
-
const functions = isCollection ? resource.functions : [resource];
|
|
20
|
-
const combinedAsset = [];
|
|
21
|
-
const prepareErrors = [];
|
|
22
16
|
try {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
let b64;
|
|
18
|
+
let hash;
|
|
19
|
+
let extension;
|
|
20
|
+
let cleanup;
|
|
21
|
+
if (isLocalFunctionResource(resource)) {
|
|
22
|
+
const prepResult = await prepareFunctionAsset({ resource }, { installer });
|
|
23
|
+
if (prepResult.success === false) {
|
|
24
|
+
return {
|
|
25
|
+
success: false,
|
|
26
|
+
error: prepResult.error,
|
|
27
|
+
};
|
|
30
28
|
}
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const zipResult = await pathToB64ZipHash(prepResult.outputPath);
|
|
30
|
+
b64 = zipResult.b64;
|
|
31
|
+
hash = zipResult.hash;
|
|
32
|
+
extension = 'zip';
|
|
33
|
+
cleanup = prepResult.cleanup;
|
|
34
|
+
}
|
|
35
|
+
else if (isStudioResource(resource)) {
|
|
36
|
+
const prepResult = await prepareStudioAsset({ resource });
|
|
37
|
+
if (prepResult.success === false) {
|
|
38
|
+
return {
|
|
39
|
+
success: false,
|
|
40
|
+
error: prepResult.error,
|
|
41
|
+
};
|
|
33
42
|
}
|
|
43
|
+
const buffer = await fs.promises.readFile(prepResult.outputPath);
|
|
44
|
+
b64 = buffer.toString('base64');
|
|
45
|
+
hash = hashBuffer(buffer);
|
|
46
|
+
extension = 'tar.gz';
|
|
47
|
+
cleanup = prepResult.cleanup;
|
|
34
48
|
}
|
|
35
|
-
|
|
36
|
-
const processedNames = new Set(combinedAsset.map((asset) => asset.name));
|
|
37
|
-
const failedFunctions = functions.filter((func) => !processedNames.has(func.name));
|
|
38
|
-
const failedNames = failedFunctions.map((f) => f.name).join(', ');
|
|
39
|
-
const errorDetails = prepareErrors.map((e) => `${e.name}: ${e.error}`).join('; ');
|
|
49
|
+
else {
|
|
40
50
|
return {
|
|
41
51
|
success: false,
|
|
42
|
-
error: `
|
|
52
|
+
error: `Invalid resource type ${resource.type} for asset processing`,
|
|
43
53
|
};
|
|
44
54
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
logger,
|
|
55
|
-
collectionInfo: {
|
|
56
|
-
name: resource.name,
|
|
57
|
-
functionCount: resource.functions.length,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else if (combinedResult.error) {
|
|
62
|
-
result = { success: false, error: combinedResult.error };
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
result = await stashSingleAsset({
|
|
67
|
-
outputPath: combinedAsset[0].partAsset.outputPath,
|
|
68
|
-
cleanup: combinedAsset[0].partAsset.cleanup,
|
|
69
|
-
resource: resource,
|
|
70
|
-
auth,
|
|
71
|
-
logger,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
55
|
+
return await stashSingleAsset({
|
|
56
|
+
b64,
|
|
57
|
+
hash,
|
|
58
|
+
extension,
|
|
59
|
+
cleanup,
|
|
60
|
+
resource,
|
|
61
|
+
auth,
|
|
62
|
+
logger,
|
|
63
|
+
});
|
|
75
64
|
}
|
|
76
65
|
catch (err) {
|
|
77
66
|
return { success: false, error: err instanceof Error ? err.message : `${err}` };
|
|
78
67
|
}
|
|
79
68
|
}
|
|
80
|
-
async function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
recursive: true,
|
|
89
|
-
});
|
|
90
|
-
await asset.partAsset.cleanup();
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
// Clean up any partial work
|
|
94
|
-
try {
|
|
95
|
-
await fs.promises.rm(combinedPath, { recursive: true, force: true });
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
// Ignore cleanup errors
|
|
99
|
-
}
|
|
100
|
-
// Clean up remaining individual assets
|
|
101
|
-
await Promise.allSettled(allAssets.map((a) => a.partAsset.cleanup()));
|
|
102
|
-
return {
|
|
103
|
-
error: `Failed to combine asset for function '${asset.name}': ${err instanceof Error ? err.message : String(err)}`,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const cleanupCombined = async () => {
|
|
108
|
-
await fs.promises.rm(combinedPath, { recursive: true, force: true });
|
|
69
|
+
async function prepareStudioAsset({ resource }) {
|
|
70
|
+
if (!('src' in resource) || typeof resource.src !== 'string') {
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
async cleanup() {
|
|
74
|
+
// no op
|
|
75
|
+
},
|
|
76
|
+
error: `Resource of type '${resource.type}' must have a 'src' property`,
|
|
109
77
|
};
|
|
110
|
-
return { combinedPath, cleanup: cleanupCombined };
|
|
111
78
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
// Clean up individual assets that were successfully prepared
|
|
121
|
-
await Promise.allSettled(allAssets.map((asset) => asset.partAsset.cleanup()));
|
|
122
|
-
return { error: err instanceof Error ? err.message : `${err}` };
|
|
79
|
+
else if (!fs.existsSync(resource.src)) {
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
async cleanup() {
|
|
83
|
+
// no op
|
|
84
|
+
},
|
|
85
|
+
error: `Property 'src' on resource with type '${resource.type}' must be a directory`,
|
|
86
|
+
};
|
|
123
87
|
}
|
|
88
|
+
return {
|
|
89
|
+
success: true,
|
|
90
|
+
async cleanup() {
|
|
91
|
+
// no op
|
|
92
|
+
},
|
|
93
|
+
// studio must be pre built (e.g. with `npm run build`) and tarred/gzipped
|
|
94
|
+
outputPath: resource.src,
|
|
95
|
+
};
|
|
124
96
|
}
|
|
125
|
-
async function stashSingleAsset({
|
|
97
|
+
async function stashSingleAsset({ b64, hash, cleanup, resource, auth, logger, extension = 'zip', }) {
|
|
126
98
|
const fetchFn = createTracedFetch(logger);
|
|
127
99
|
try {
|
|
128
|
-
const { b64, hash } = await pathToB64ZipHash(outputPath);
|
|
129
100
|
try {
|
|
130
101
|
const checkResponse = await fetchFn(`${ASSET_CHECK_URL}/${hash}`, {
|
|
131
102
|
method: 'GET',
|
|
@@ -143,19 +114,16 @@ async function stashSingleAsset({ outputPath, cleanup, resource, auth, logger, c
|
|
|
143
114
|
headers: getHeaders(auth),
|
|
144
115
|
body: JSON.stringify({
|
|
145
116
|
file: b64,
|
|
146
|
-
filename: `${resource.name}
|
|
117
|
+
filename: `${resource.name}.${extension}`,
|
|
147
118
|
}),
|
|
148
119
|
});
|
|
149
120
|
const assetJson = await assetResponse.json();
|
|
150
121
|
if (assetResponse.ok) {
|
|
151
122
|
return { success: true, assetId: assetJson.id, exists: false, hash };
|
|
152
123
|
}
|
|
153
|
-
const contextMsg = collectionInfo
|
|
154
|
-
? ` (part of collection '${collectionInfo.name}' with ${collectionInfo.functionCount} functions)`
|
|
155
|
-
: '';
|
|
156
124
|
return {
|
|
157
125
|
success: false,
|
|
158
|
-
error: `Failed to stash asset for ${resource.name}
|
|
126
|
+
error: `Failed to stash asset for ${resource.name}: ${assetJson.message || 'Unknown error'}`,
|
|
159
127
|
};
|
|
160
128
|
}
|
|
161
129
|
catch (err) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BlueprintResource } from '@sanity/blueprints';
|
|
2
2
|
import { type Blueprint } from '@sanity/blueprints-parser';
|
|
3
3
|
import type { Logger } from '../../utils/logger.js';
|
|
4
|
-
import {
|
|
4
|
+
import type { BlueprintParserError, ScopeType } from '../../utils/types.js';
|
|
5
5
|
import { type LocatedBlueprintsConfig } from './config.js';
|
|
6
6
|
declare const SUPPORTED_FILE_EXTENSIONS: readonly [".json", ".js", ".mjs", ".ts"];
|
|
7
7
|
type BlueprintFileExtension = (typeof SUPPORTED_FILE_EXTENSIONS)[number];
|
|
@@ -65,7 +65,7 @@ export interface ReadBlueprintResult {
|
|
|
65
65
|
* @param blueprintPath - The path of the blueprint file or directory- will search up the directory tree!
|
|
66
66
|
* @returns Known information about the Blueprint, config, and Stack
|
|
67
67
|
*/
|
|
68
|
-
export declare function readLocalBlueprint(logger:
|
|
68
|
+
export declare function readLocalBlueprint(logger: Logger, validate: {
|
|
69
69
|
resources: boolean;
|
|
70
70
|
}, blueprintPath?: string): Promise<ReadBlueprintResult>;
|
|
71
71
|
export declare function writeBlueprintToDisk({ blueprintFilePath, jsonContent, }: {
|
|
@@ -6,9 +6,7 @@ import blueprintParserValidator from '@sanity/blueprints-parser';
|
|
|
6
6
|
import * as find from 'empathic/find';
|
|
7
7
|
import { createJiti } from 'jiti';
|
|
8
8
|
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET, SANITY_FUNCTION_SCHEDULED, } from '../../constants.js';
|
|
9
|
-
import { isLocalFunctionResource, } from '../../utils/types.js';
|
|
10
9
|
import { validateResources } from '../../utils/validate/index.js';
|
|
11
|
-
import { validateFunctionResource } from '../../utils/validate/resource.js';
|
|
12
10
|
import { backfillOrganizationId, backfillProjectBasedStackId, readConfigFile, } from './config.js';
|
|
13
11
|
const SUPPORTED_FILE_EXTENSIONS = ['.json', '.js', '.mjs', '.ts'];
|
|
14
12
|
let SUPPORTED_FILE_NAMES = SUPPORTED_FILE_EXTENSIONS.map((ext) => `blueprint${ext}`);
|
|
@@ -215,6 +213,7 @@ export async function readLocalBlueprint(logger, validate, blueprintPath) {
|
|
|
215
213
|
scopeId = organizationId;
|
|
216
214
|
}
|
|
217
215
|
const parserResult = blueprintParserValidator(rawBlueprint, {
|
|
216
|
+
// Prevents the following resources from being referenced.
|
|
218
217
|
invalidReferenceTypes: [
|
|
219
218
|
SANITY_FUNCTION_DOCUMENT,
|
|
220
219
|
SANITY_FUNCTION_MEDIA_LIBRARY_ASSET,
|
|
@@ -229,12 +228,6 @@ export async function readLocalBlueprint(logger, validate, blueprintPath) {
|
|
|
229
228
|
// validate function resources
|
|
230
229
|
errors.push(...validateResources(parsedBlueprint.resources));
|
|
231
230
|
}
|
|
232
|
-
else {
|
|
233
|
-
// backwards compat: fallback to the previous validation if validation was not explicitly enabled
|
|
234
|
-
const functionResources = parsedBlueprint.resources.filter(isLocalFunctionResource);
|
|
235
|
-
const fnErrors = functionResources.map((r) => validateFunctionResource(r));
|
|
236
|
-
errors.push(...fnErrors.flat());
|
|
237
|
-
}
|
|
238
231
|
}
|
|
239
232
|
return {
|
|
240
233
|
fileInfo: { blueprintFilePath: foundFilePath, fileName, extension },
|
|
@@ -53,10 +53,10 @@ export declare function patchConfigFile(blueprintFilePath: string, updateablePro
|
|
|
53
53
|
export declare function backfillOrganizationId({ blueprintFilePath, projectId, logger, }: {
|
|
54
54
|
blueprintFilePath: string;
|
|
55
55
|
projectId: string;
|
|
56
|
-
logger:
|
|
56
|
+
logger: Logger;
|
|
57
57
|
}): Promise<string>;
|
|
58
58
|
export declare function backfillProjectBasedStackId({ blueprintFilePath, projectId, logger, }: {
|
|
59
59
|
blueprintFilePath: string;
|
|
60
60
|
projectId: string;
|
|
61
|
-
logger:
|
|
61
|
+
logger: Logger;
|
|
62
62
|
}): Promise<string | undefined>;
|
|
@@ -6,7 +6,7 @@ export interface LogStreamingConfig {
|
|
|
6
6
|
auth: AuthParams;
|
|
7
7
|
showBanner?: boolean;
|
|
8
8
|
verbose?: boolean;
|
|
9
|
-
log:
|
|
9
|
+
log: Logger;
|
|
10
10
|
onActivity?: () => void;
|
|
11
11
|
}
|
|
12
12
|
export interface StreamLogsOptions {
|
|
@@ -16,7 +16,7 @@ export interface StreamLogsOptions {
|
|
|
16
16
|
onLog: (log: BlueprintLog) => void;
|
|
17
17
|
onOpen: () => void;
|
|
18
18
|
onError: (error: string) => void;
|
|
19
|
-
logger:
|
|
19
|
+
logger: Logger;
|
|
20
20
|
}
|
|
21
21
|
export declare function streamLogs({ stackId, after, auth, onLog, onOpen, onError, logger, }: StreamLogsOptions): () => void;
|
|
22
22
|
/** Check if a log is newer than a given timestamp */
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Logger } from '../../utils/logger.js';
|
|
2
|
-
import type { AuthParams, BlueprintLog } from '../../utils/types.js';
|
|
2
|
+
import type { ActionResponse, AuthParams, BlueprintLog } from '../../utils/types.js';
|
|
3
3
|
export declare const logsUrl: string;
|
|
4
|
-
export declare function getLogs(stackId: string, auth: AuthParams, logger:
|
|
4
|
+
export declare function getLogs(stackId: string, auth: AuthParams, logger: Logger): Promise<ActionResponse & {
|
|
5
5
|
logs: BlueprintLog[];
|
|
6
|
-
ok: boolean;
|
|
7
|
-
error: string | null;
|
|
8
6
|
}>;
|
|
9
7
|
export declare function getRecentLogs(logs: BlueprintLog[], limit?: number): BlueprintLog[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Logger } from '../../utils/logger.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FunctionResource } from '../../utils/types.js';
|
|
3
3
|
interface FunctionResourceOptions {
|
|
4
4
|
name: string;
|
|
5
5
|
type: string[];
|
|
@@ -11,9 +11,9 @@ interface FunctionResourceOptions {
|
|
|
11
11
|
/**
|
|
12
12
|
* Creates a new function resource file and adds it to the blueprint
|
|
13
13
|
*/
|
|
14
|
-
export declare function createFunctionResource(options: FunctionResourceOptions, logger:
|
|
14
|
+
export declare function createFunctionResource(options: FunctionResourceOptions, logger: Logger): Promise<{
|
|
15
15
|
filePath: string;
|
|
16
16
|
resourceAdded: boolean;
|
|
17
|
-
resource:
|
|
17
|
+
resource: FunctionResource;
|
|
18
18
|
}>;
|
|
19
19
|
export {};
|
|
@@ -2,7 +2,6 @@ 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';
|
|
6
5
|
import { styleText } from '../../utils/style-text.js';
|
|
7
6
|
import { writeOrUpdateNodeDependency } from '../node.js';
|
|
8
7
|
import { addResourceToBlueprint } from './blueprint.js';
|
|
@@ -57,18 +56,39 @@ export async function createFunctionResource(options, logger) {
|
|
|
57
56
|
throw new Error(`Failed to install dependencies using \`${installCommand}\``);
|
|
58
57
|
}
|
|
59
58
|
}
|
|
60
|
-
// type looks like 'document-publish'
|
|
59
|
+
// type looks like 'document-publish', 'media-library-asset-delete' or 'scheduled-function'
|
|
60
|
+
// and we are guaranteed to have the same leading words (typeName below) for all provided type strings (via guards in the call site for this method).
|
|
61
61
|
const typeName = type[0].substring(0, type[0].lastIndexOf('-'));
|
|
62
62
|
const eventsOn = type.map((t) => t.substring(t.lastIndexOf('-') + 1));
|
|
63
63
|
// Create resource definition
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
let resourceJson;
|
|
65
|
+
switch (typeName) {
|
|
66
|
+
case 'document':
|
|
67
|
+
resourceJson = {
|
|
68
|
+
name,
|
|
69
|
+
src: `functions/${name}`,
|
|
70
|
+
type: 'sanity.function.document',
|
|
71
|
+
event: {
|
|
72
|
+
on: eventsOn,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
break;
|
|
76
|
+
case 'media-library-asset':
|
|
77
|
+
resourceJson = {
|
|
78
|
+
name,
|
|
79
|
+
src: `functions/${name}`,
|
|
80
|
+
type: 'sanity.function.media-library.asset',
|
|
81
|
+
event: {
|
|
82
|
+
on: eventsOn,
|
|
83
|
+
resource: { type: 'media-library', id: 'my-media-library-id' },
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
break;
|
|
87
|
+
// TODO: add scheduled and sync tag invalidate funx
|
|
88
|
+
}
|
|
89
|
+
if (!resourceJson) {
|
|
90
|
+
throw new Error('Could not create function resource based on selections');
|
|
91
|
+
}
|
|
72
92
|
// Add to blueprint or return for manual addition
|
|
73
93
|
const resource = addResourceToBlueprint({ blueprintFilePath, resource: resourceJson });
|
|
74
94
|
return {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Blueprint } from '@sanity/blueprints-parser';
|
|
2
2
|
import type { Logger } from '../../utils/logger.js';
|
|
3
|
-
import type { AuthParams, ScopeType, Stack, StackMutation, StackSummary } from '../../utils/types.js';
|
|
3
|
+
import type { ActionResponse, AuthParams, ScopeType, Stack, StackMutation, StackSummary } from '../../utils/types.js';
|
|
4
4
|
export declare const stacksUrl: string;
|
|
5
5
|
type ListStacksResponse = {
|
|
6
6
|
ok: true;
|
|
@@ -11,45 +11,39 @@ type ListStacksResponse = {
|
|
|
11
11
|
error: string;
|
|
12
12
|
stacks: unknown;
|
|
13
13
|
};
|
|
14
|
-
export declare function listStacks(auth: AuthParams, logger:
|
|
15
|
-
interface GetStackResponse {
|
|
16
|
-
ok: boolean;
|
|
17
|
-
error: string | null;
|
|
14
|
+
export declare function listStacks(auth: AuthParams, logger: Logger): Promise<ListStacksResponse>;
|
|
15
|
+
interface GetStackResponse extends ActionResponse {
|
|
18
16
|
stack: Stack;
|
|
19
17
|
response?: Response;
|
|
20
18
|
}
|
|
21
19
|
export declare function getStack({ stackId, auth, logger, }: {
|
|
22
20
|
stackId: string;
|
|
23
21
|
auth: AuthParams;
|
|
24
|
-
logger:
|
|
22
|
+
logger: Logger;
|
|
25
23
|
}): Promise<GetStackResponse>;
|
|
26
|
-
interface CreateStackResponse {
|
|
27
|
-
ok: boolean;
|
|
28
|
-
error: string | null;
|
|
24
|
+
interface CreateStackResponse extends ActionResponse {
|
|
29
25
|
stack: Stack;
|
|
30
26
|
}
|
|
31
27
|
export declare function createStack({ stackMutation, auth, logger, }: {
|
|
32
28
|
stackMutation: StackMutation;
|
|
33
29
|
auth: AuthParams;
|
|
34
|
-
logger:
|
|
30
|
+
logger: Logger;
|
|
35
31
|
}): Promise<CreateStackResponse>;
|
|
36
32
|
export declare function createEmptyStack({ token, scopeType, scopeId, name, logger, }: {
|
|
37
33
|
token: string;
|
|
38
34
|
scopeType: ScopeType;
|
|
39
35
|
scopeId: string;
|
|
40
36
|
name: string;
|
|
41
|
-
logger:
|
|
37
|
+
logger: Logger;
|
|
42
38
|
}): Promise<Stack>;
|
|
43
|
-
interface UpdateStackResponse {
|
|
44
|
-
ok: boolean;
|
|
45
|
-
error: string | null;
|
|
39
|
+
interface UpdateStackResponse extends ActionResponse {
|
|
46
40
|
stack: Stack;
|
|
47
41
|
}
|
|
48
42
|
export declare function updateStack({ stackId, stackMutation, auth, logger, }: {
|
|
49
43
|
stackId: string;
|
|
50
44
|
stackMutation: StackMutation;
|
|
51
45
|
auth: AuthParams;
|
|
52
|
-
logger:
|
|
46
|
+
logger: Logger;
|
|
53
47
|
}): Promise<UpdateStackResponse>;
|
|
54
48
|
interface PlanResourceSnapshot {
|
|
55
49
|
name: string;
|
|
@@ -99,17 +93,13 @@ export declare function planStack({ stackId, document, auth, logger, }: {
|
|
|
99
93
|
stackId: string;
|
|
100
94
|
document: Blueprint;
|
|
101
95
|
auth: AuthParams;
|
|
102
|
-
logger:
|
|
96
|
+
logger: Logger;
|
|
103
97
|
}): Promise<PlanStackResponse>;
|
|
104
|
-
interface DestroyStackResponse {
|
|
105
|
-
ok: boolean;
|
|
106
|
-
error: string | null;
|
|
98
|
+
interface DestroyStackResponse extends ActionResponse {
|
|
107
99
|
stack: Stack;
|
|
108
100
|
}
|
|
109
|
-
export declare function resolveStackIdByNameOrId(value: string, auth: AuthParams, logger:
|
|
110
|
-
interface PromoteStackResponse {
|
|
111
|
-
ok: boolean;
|
|
112
|
-
error: string | null;
|
|
101
|
+
export declare function resolveStackIdByNameOrId(value: string, auth: AuthParams, logger: Logger): Promise<string>;
|
|
102
|
+
interface PromoteStackResponse extends ActionResponse {
|
|
113
103
|
stack: Stack & {
|
|
114
104
|
alreadyPromoted: boolean;
|
|
115
105
|
};
|
|
@@ -117,11 +107,11 @@ interface PromoteStackResponse {
|
|
|
117
107
|
export declare function promoteStack({ stackId, auth, logger, }: {
|
|
118
108
|
stackId: string;
|
|
119
109
|
auth: AuthParams;
|
|
120
|
-
logger:
|
|
110
|
+
logger: Logger;
|
|
121
111
|
}): Promise<PromoteStackResponse>;
|
|
122
112
|
export declare function destroyStack({ stackId, auth, logger, }: {
|
|
123
113
|
stackId: string;
|
|
124
114
|
auth: AuthParams;
|
|
125
|
-
logger:
|
|
115
|
+
logger: Logger;
|
|
126
116
|
}): Promise<DestroyStackResponse>;
|
|
127
117
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Logger } from '../../utils/logger.js';
|
|
2
2
|
import type { InvokeExecutionOptions } from '../../utils/types.js';
|
|
3
|
-
export declare function dev(host: string, port: number, logger:
|
|
3
|
+
export declare function dev(host: string, port: number, logger: Logger, validateResources: boolean, executionOptions?: Partial<InvokeExecutionOptions>): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '../../../utils/logger.js';
|
|
2
2
|
import type { AuthParams } from '../../../utils/types.js';
|
|
3
|
-
export declare function list(id: string, auth: AuthParams, logger:
|
|
3
|
+
export declare function list(id: string, auth: AuthParams, logger: Logger): Promise<{
|
|
4
4
|
ok: boolean;
|
|
5
5
|
envvars: any;
|
|
6
6
|
error: any;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '../../../utils/logger.js';
|
|
2
2
|
import type { AuthParams } from '../../../utils/types.js';
|
|
3
|
-
export declare function remove(id: string, key: string, auth: AuthParams, logger:
|
|
3
|
+
export declare function remove(id: string, key: string, auth: AuthParams, logger: Logger): Promise<{
|
|
4
4
|
ok: boolean;
|
|
5
5
|
error: any;
|
|
6
6
|
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Logger } from '../../../utils/logger.js';
|
|
2
2
|
import type { AuthParams } from '../../../utils/types.js';
|
|
3
|
-
export declare function update(id: string, key: string, value: string, auth: AuthParams, logger:
|
|
3
|
+
export declare function update(id: string, key: string, value: string, auth: AuthParams, logger: Logger): Promise<{
|
|
4
4
|
ok: boolean;
|
|
5
5
|
error: any;
|
|
6
6
|
}>;
|
|
@@ -4,13 +4,13 @@ import type { AuthParams, FunctionLog } from '../../utils/types.js';
|
|
|
4
4
|
export interface LoggingOptions {
|
|
5
5
|
limit: number;
|
|
6
6
|
}
|
|
7
|
-
export declare function logs(id: string, options: LoggingOptions, auth: AuthParams, logger:
|
|
7
|
+
export declare function logs(id: string, options: LoggingOptions, auth: AuthParams, logger: Logger): Promise<{
|
|
8
8
|
ok: boolean;
|
|
9
9
|
error: any;
|
|
10
10
|
logs: any;
|
|
11
11
|
}>;
|
|
12
|
-
export declare function deleteLogs(id: string, auth: AuthParams, logger:
|
|
12
|
+
export declare function deleteLogs(id: string, auth: AuthParams, logger: Logger): Promise<{
|
|
13
13
|
ok: boolean;
|
|
14
14
|
error: any;
|
|
15
15
|
}>;
|
|
16
|
-
export declare function streamLogs(id: string, auth: AuthParams, onLog: (log: FunctionLog) => void, onOpen: () => void, onError: (error: string) => void, logger:
|
|
16
|
+
export declare function streamLogs(id: string, auth: AuthParams, onLog: (log: FunctionLog) => void, onOpen: () => void, onError: (error: string) => void, logger: Logger): () => void;
|
package/dist/actions/node.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Logger } from '../utils/logger.js';
|
|
2
|
-
export declare function writeOrUpdateNodeDependency(nearFilePath: string, dependency: string, logger:
|
|
2
|
+
export declare function writeOrUpdateNodeDependency(nearFilePath: string, dependency: string, logger: Logger): Promise<void>;
|
|
@@ -7,7 +7,7 @@ declare const EXAMPLE_TYPES: {
|
|
|
7
7
|
export declare function verifyExampleExists({ type, name, logger, }: {
|
|
8
8
|
type: keyof typeof EXAMPLE_TYPES;
|
|
9
9
|
name: string;
|
|
10
|
-
logger:
|
|
10
|
+
logger: Logger;
|
|
11
11
|
}): Promise<boolean>;
|
|
12
12
|
/**
|
|
13
13
|
* Downloads an example from the examples repo and writes it to disk.
|
|
@@ -19,7 +19,7 @@ export declare function writeExample({ ownerRepo, exampleType, exampleName, dir,
|
|
|
19
19
|
exampleType: keyof typeof EXAMPLE_TYPES;
|
|
20
20
|
exampleName: string;
|
|
21
21
|
dir?: string;
|
|
22
|
-
logger:
|
|
22
|
+
logger: Logger;
|
|
23
23
|
}): Promise<false | {
|
|
24
24
|
files: Record<string, string>;
|
|
25
25
|
dir: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Logger } from '../../utils/logger.js';
|
|
2
|
-
import type { ScopeType } from '../../utils/types.js';
|
|
2
|
+
import type { ActionResponse, ScopeType } from '../../utils/types.js';
|
|
3
3
|
export declare const projectsApiPath: string;
|
|
4
4
|
export declare const orgsApiPath: string;
|
|
5
5
|
export interface Project {
|
|
@@ -14,18 +14,14 @@ export interface Project {
|
|
|
14
14
|
createdAt: string;
|
|
15
15
|
updatedAt: string;
|
|
16
16
|
}
|
|
17
|
-
interface ListProjectsResponse {
|
|
18
|
-
ok: boolean;
|
|
19
|
-
error: string | null;
|
|
17
|
+
interface ListProjectsResponse extends ActionResponse {
|
|
20
18
|
projects: Project[];
|
|
21
19
|
}
|
|
22
20
|
export declare function listProjects({ token, logger, }: {
|
|
23
21
|
token: string;
|
|
24
|
-
logger:
|
|
22
|
+
logger: Logger;
|
|
25
23
|
}): Promise<ListProjectsResponse>;
|
|
26
|
-
interface GroupedProjectsByOrganizationResponse {
|
|
27
|
-
ok: boolean;
|
|
28
|
-
error: string | null;
|
|
24
|
+
interface GroupedProjectsByOrganizationResponse extends ActionResponse {
|
|
29
25
|
organizations: GroupedProjects[];
|
|
30
26
|
}
|
|
31
27
|
interface GroupedProjects {
|
|
@@ -37,17 +33,15 @@ interface GroupedProjects {
|
|
|
37
33
|
}
|
|
38
34
|
export declare function groupProjectsByOrganization({ token, logger, }: {
|
|
39
35
|
token: string;
|
|
40
|
-
logger:
|
|
36
|
+
logger: Logger;
|
|
41
37
|
}): Promise<GroupedProjectsByOrganizationResponse>;
|
|
42
|
-
interface GetProjectResponse {
|
|
43
|
-
ok: boolean;
|
|
44
|
-
error: string | null;
|
|
38
|
+
interface GetProjectResponse extends ActionResponse {
|
|
45
39
|
project: Project;
|
|
46
40
|
}
|
|
47
41
|
export declare function getProject({ token, scopeId, scopeType, logger, }: {
|
|
48
42
|
token: string;
|
|
49
43
|
scopeId: string;
|
|
50
44
|
scopeType: ScopeType;
|
|
51
|
-
logger:
|
|
45
|
+
logger: Logger;
|
|
52
46
|
}): Promise<GetProjectResponse>;
|
|
53
47
|
export {};
|
package/dist/baseCommands.d.ts
CHANGED
|
@@ -12,6 +12,14 @@ export declare const baseFlags: {
|
|
|
12
12
|
verbose: Interfaces.BooleanFlag<boolean>;
|
|
13
13
|
};
|
|
14
14
|
export declare const stackFlag: Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
|
|
15
|
+
export declare const projectIdFlagConfig: {
|
|
16
|
+
description: string;
|
|
17
|
+
aliases: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare const organizationIdFlagConfig: {
|
|
20
|
+
description: string;
|
|
21
|
+
aliases: string[];
|
|
22
|
+
};
|
|
15
23
|
/**
|
|
16
24
|
* @description Unhides a flag by setting its hidden property to false
|
|
17
25
|
* Also makes oclif's types happy when destructuring the flag
|