@sanity/runtime-cli 12.3.0 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -76
- package/dist/actions/blueprints/assets.d.ts +3 -1
- package/dist/actions/blueprints/assets.js +15 -5
- package/dist/actions/blueprints/blueprint.d.ts +2 -1
- package/dist/actions/blueprints/blueprint.js +3 -1
- package/dist/actions/blueprints/config.d.ts +5 -2
- package/dist/actions/blueprints/config.js +4 -4
- package/dist/actions/blueprints/logs-streaming.d.ts +4 -2
- package/dist/actions/blueprints/logs-streaming.js +5 -2
- package/dist/actions/blueprints/logs.d.ts +2 -1
- package/dist/actions/blueprints/logs.js +4 -2
- package/dist/actions/blueprints/resources.d.ts +2 -1
- package/dist/actions/blueprints/resources.js +2 -2
- package/dist/actions/blueprints/stacks.d.ts +12 -6
- package/dist/actions/blueprints/stacks.js +18 -11
- package/dist/actions/functions/dev.d.ts +2 -1
- package/dist/actions/functions/dev.js +2 -2
- package/dist/actions/functions/env/list.d.ts +2 -1
- package/dist/actions/functions/env/list.js +4 -2
- package/dist/actions/functions/env/remove.d.ts +2 -1
- package/dist/actions/functions/env/remove.js +4 -2
- package/dist/actions/functions/env/update.d.ts +2 -1
- package/dist/actions/functions/env/update.js +4 -2
- package/dist/actions/functions/logs.d.ts +4 -3
- package/dist/actions/functions/logs.js +10 -6
- package/dist/actions/node.d.ts +2 -1
- package/dist/actions/node.js +2 -2
- package/dist/actions/sanity/examples.d.ts +5 -2
- package/dist/actions/sanity/examples.js +6 -6
- package/dist/actions/sanity/projects.d.ts +7 -3
- package/dist/actions/sanity/projects.js +11 -7
- package/dist/baseCommands.d.ts +47 -7
- package/dist/baseCommands.js +90 -12
- package/dist/commands/blueprints/add.d.ts +3 -2
- package/dist/commands/blueprints/add.js +14 -10
- package/dist/commands/blueprints/config.d.ts +3 -2
- package/dist/commands/blueprints/config.js +12 -6
- package/dist/commands/blueprints/deploy.d.ts +3 -2
- package/dist/commands/blueprints/deploy.js +10 -4
- package/dist/commands/blueprints/destroy.d.ts +3 -2
- package/dist/commands/blueprints/destroy.js +10 -4
- package/dist/commands/blueprints/doctor.d.ts +6 -4
- package/dist/commands/blueprints/doctor.js +17 -14
- package/dist/commands/blueprints/info.d.ts +3 -2
- package/dist/commands/blueprints/info.js +11 -5
- package/dist/commands/blueprints/init.d.ts +3 -2
- package/dist/commands/blueprints/init.js +26 -20
- package/dist/commands/blueprints/logs.d.ts +3 -2
- package/dist/commands/blueprints/logs.js +10 -4
- package/dist/commands/blueprints/plan.d.ts +3 -2
- package/dist/commands/blueprints/plan.js +8 -4
- package/dist/commands/blueprints/stacks.d.ts +3 -2
- package/dist/commands/blueprints/stacks.js +10 -6
- package/dist/commands/functions/add.d.ts +3 -2
- package/dist/commands/functions/add.js +10 -4
- package/dist/commands/functions/dev.d.ts +3 -2
- package/dist/commands/functions/dev.js +16 -5
- package/dist/commands/functions/env/add.d.ts +4 -3
- package/dist/commands/functions/env/add.js +8 -4
- package/dist/commands/functions/env/list.d.ts +4 -3
- package/dist/commands/functions/env/list.js +8 -4
- package/dist/commands/functions/env/remove.d.ts +4 -3
- package/dist/commands/functions/env/remove.js +8 -4
- package/dist/commands/functions/logs.d.ts +5 -4
- package/dist/commands/functions/logs.js +11 -5
- package/dist/commands/functions/test.d.ts +5 -4
- package/dist/commands/functions/test.js +13 -6
- package/dist/cores/blueprints/config.d.ts +2 -5
- package/dist/cores/blueprints/config.js +9 -9
- package/dist/cores/blueprints/deploy.js +14 -17
- package/dist/cores/blueprints/destroy.d.ts +2 -5
- package/dist/cores/blueprints/destroy.js +6 -6
- package/dist/cores/blueprints/doctor.js +32 -29
- package/dist/cores/blueprints/info.js +5 -5
- package/dist/cores/blueprints/init.d.ts +3 -3
- package/dist/cores/blueprints/init.js +15 -8
- package/dist/cores/blueprints/logs.js +6 -7
- package/dist/cores/blueprints/plan.js +1 -0
- package/dist/cores/blueprints/stacks.d.ts +2 -5
- package/dist/cores/blueprints/stacks.js +4 -4
- package/dist/cores/functions/add.js +8 -3
- package/dist/cores/functions/dev.js +2 -2
- package/dist/cores/functions/env/add.js +3 -4
- package/dist/cores/functions/env/list.js +3 -4
- package/dist/cores/functions/env/remove.js +3 -4
- package/dist/cores/functions/index.d.ts +3 -9
- package/dist/cores/functions/logs.d.ts +3 -1
- package/dist/cores/functions/logs.js +19 -11
- package/dist/cores/functions/test.d.ts +3 -1
- package/dist/cores/functions/test.js +18 -10
- package/dist/cores/index.d.ts +4 -7
- package/dist/cores/index.js +3 -3
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/server/app.d.ts +2 -1
- package/dist/server/app.js +4 -4
- package/dist/server/handlers/invoke.d.ts +2 -1
- package/dist/server/handlers/invoke.js +2 -2
- package/dist/server/static/components/app.css +0 -116
- package/dist/server/static/components/clear-button.js +1 -1
- package/dist/server/static/components/console-panel.js +27 -6
- package/dist/server/static/components/fetch-button.js +1 -1
- package/dist/server/static/components/filter-api-version.js +39 -3
- package/dist/server/static/components/filter-document-id.js +39 -3
- package/dist/server/static/components/filter-with-token.js +27 -4
- package/dist/server/static/components/filters.js +127 -62
- package/dist/server/static/components/function-list.js +33 -13
- package/dist/server/static/components/network-spinner.js +6 -4
- package/dist/server/static/components/payload-panel.js +46 -24
- package/dist/server/static/components/response-panel.js +33 -6
- package/dist/server/static/components/rule-panel.js +13 -4
- package/dist/server/static/components/run-panel.js +14 -7
- package/dist/server/static/components/select-dropdown.js +34 -5
- package/dist/server/static/components/shared-styles.js +31 -0
- package/dist/server/static/components/toggle-switch.js +11 -2
- package/dist/utils/display/blueprints-formatting.d.ts +2 -2
- package/dist/utils/display/blueprints-formatting.js +31 -26
- package/dist/utils/display/prompt.d.ts +5 -2
- package/dist/utils/display/prompt.js +5 -4
- package/dist/utils/find-function.d.ts +4 -0
- package/dist/utils/find-function.js +6 -0
- package/dist/utils/functions/fetch-document.d.ts +3 -2
- package/dist/utils/functions/fetch-document.js +7 -6
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.js +61 -0
- package/dist/utils/other/github.d.ts +2 -1
- package/dist/utils/other/github.js +4 -2
- package/dist/utils/other/npmjs.d.ts +2 -1
- package/dist/utils/other/npmjs.js +4 -2
- package/dist/utils/traced-fetch.d.ts +35 -0
- package/dist/utils/traced-fetch.js +238 -0
- package/dist/utils/validated-token.d.ts +3 -2
- package/dist/utils/validated-token.js +6 -4
- package/oclif.manifest.json +455 -75
- package/package.json +14 -6
|
@@ -2,17 +2,11 @@ export type { FunctionAddOptions } from './add.js';
|
|
|
2
2
|
export { functionAddCore } from './add.js';
|
|
3
3
|
export type { FunctionDevOptions } from './dev.js';
|
|
4
4
|
export { functionDevCore } from './dev.js';
|
|
5
|
-
export type { FunctionEnvAddOptions
|
|
6
|
-
/** @deprecated Use `FunctionEnvAddOptions` instead. */
|
|
7
|
-
FunctionEnvAddOptions as EnvAddOptions, } from './env/add.js';
|
|
5
|
+
export type { FunctionEnvAddOptions } from './env/add.js';
|
|
8
6
|
export { functionEnvAddCore } from './env/add.js';
|
|
9
|
-
export type { FunctionEnvListOptions
|
|
10
|
-
/** @deprecated Use `FunctionEnvListOptions` instead. */
|
|
11
|
-
FunctionEnvListOptions as EnvListOptions, } from './env/list.js';
|
|
7
|
+
export type { FunctionEnvListOptions } from './env/list.js';
|
|
12
8
|
export { functionEnvListCore } from './env/list.js';
|
|
13
|
-
export type { FunctionEnvRemoveOptions
|
|
14
|
-
/** @deprecated Use `FunctionEnvRemoveOptions` instead. */
|
|
15
|
-
FunctionEnvRemoveOptions as EnvRemoveOptions, } from './env/remove.js';
|
|
9
|
+
export type { FunctionEnvRemoveOptions } from './env/remove.js';
|
|
16
10
|
export { functionEnvRemoveCore } from './env/remove.js';
|
|
17
11
|
export type { FunctionLogsOptions } from './logs.js';
|
|
18
12
|
export { functionLogsCore } from './logs.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CoreResult, DeployedBlueprintConfig } from '../index.js';
|
|
2
2
|
export interface FunctionLogsOptions extends DeployedBlueprintConfig {
|
|
3
3
|
args: {
|
|
4
|
-
name: string;
|
|
4
|
+
name: string | undefined;
|
|
5
5
|
};
|
|
6
6
|
flags: {
|
|
7
7
|
limit: number;
|
|
@@ -11,5 +11,7 @@ export interface FunctionLogsOptions extends DeployedBlueprintConfig {
|
|
|
11
11
|
force?: boolean;
|
|
12
12
|
watch?: boolean;
|
|
13
13
|
};
|
|
14
|
+
error: (message: string, options: object) => void;
|
|
15
|
+
helpText: string;
|
|
14
16
|
}
|
|
15
17
|
export declare function functionLogsCore(options: FunctionLogsOptions): Promise<CoreResult>;
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { confirm } from '@inquirer/prompts';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import ora from 'ora';
|
|
4
3
|
import { deleteLogs as deleteLogsAction, logs as getLogsAction, streamLogs as streamLogsAction, } from '../../actions/functions/logs.js';
|
|
5
4
|
import { formatTitle } from '../../utils/display/blueprints-formatting.js';
|
|
6
5
|
import { niceId } from '../../utils/display/presenters.js';
|
|
7
|
-
import { findFunctionInStack } from '../../utils/find-function.js';
|
|
6
|
+
import { findFunctionInStack, getFunctionNames } from '../../utils/find-function.js';
|
|
8
7
|
export async function functionLogsCore(options) {
|
|
9
|
-
const { args, flags, log, auth, deployedStack } = options;
|
|
8
|
+
const { args, flags, log, error, auth, deployedStack, blueprint, helpText } = options;
|
|
10
9
|
const { name } = args;
|
|
11
10
|
const { delete: shouldDelete, watch: shouldWatch, force, limit, json, utc } = flags;
|
|
11
|
+
if (!name) {
|
|
12
|
+
const functionNames = getFunctionNames(blueprint.parsedBlueprint.resources);
|
|
13
|
+
const validNames = functionNames.length > 0
|
|
14
|
+
? `Valid names are: ${functionNames.join(', ')}`
|
|
15
|
+
: 'No functions are defined in the blueprint.';
|
|
16
|
+
error(`Missing required argument: name\n${validNames}\n`, { exit: false });
|
|
17
|
+
log(helpText);
|
|
18
|
+
return { success: true };
|
|
19
|
+
}
|
|
12
20
|
const { externalId } = findFunctionInStack(deployedStack, name); // throws if not found
|
|
13
21
|
if (shouldDelete)
|
|
14
22
|
return deleteLogs({ name, externalId, auth, force, log });
|
|
@@ -16,7 +24,7 @@ export async function functionLogsCore(options) {
|
|
|
16
24
|
return streamLogs({ name, externalId, auth, json, utc, log });
|
|
17
25
|
return getLogs({ name, externalId, auth, limit, json, utc, log });
|
|
18
26
|
}
|
|
19
|
-
async function deleteLogs({ name, externalId, auth, force, }) {
|
|
27
|
+
async function deleteLogs({ name, externalId, auth, force, log, }) {
|
|
20
28
|
if (!force) {
|
|
21
29
|
const certain = await confirm({
|
|
22
30
|
message: `Are you sure you want to delete ${chalk.bold('all')} logs for function ${chalk.yellow(name)}?`,
|
|
@@ -25,8 +33,8 @@ async function deleteLogs({ name, externalId, auth, force, }) {
|
|
|
25
33
|
if (!certain)
|
|
26
34
|
return { success: true };
|
|
27
35
|
}
|
|
28
|
-
const spinner = ora(`Deleting logs for function ${chalk.yellow(name)}`).start();
|
|
29
|
-
const { ok, error } = await deleteLogsAction(externalId, auth);
|
|
36
|
+
const spinner = log.ora(`Deleting logs for function ${chalk.yellow(name)}`).start();
|
|
37
|
+
const { ok, error } = await deleteLogsAction(externalId, auth, log);
|
|
30
38
|
if (!ok) {
|
|
31
39
|
spinner.fail(`${chalk.red('Failed')} to delete logs`);
|
|
32
40
|
return { success: false, error: error || 'Unknown error' };
|
|
@@ -35,7 +43,7 @@ async function deleteLogs({ name, externalId, auth, force, }) {
|
|
|
35
43
|
return { success: true };
|
|
36
44
|
}
|
|
37
45
|
async function streamLogs({ name, externalId, auth, log, }) {
|
|
38
|
-
const spinner = ora(`Setting up streaming logs session for function ${niceId(name)}`).start();
|
|
46
|
+
const spinner = log.ora(`Setting up streaming logs session for function ${niceId(name)}`).start();
|
|
39
47
|
try {
|
|
40
48
|
spinner.stop();
|
|
41
49
|
log(`Streaming log session for function ${niceId(name)}`);
|
|
@@ -50,7 +58,7 @@ async function streamLogs({ name, externalId, auth, log, }) {
|
|
|
50
58
|
const { time, level, message } = logEntry;
|
|
51
59
|
log(formatLog(time, level, message, true));
|
|
52
60
|
};
|
|
53
|
-
streamLogsAction(externalId, auth, renderLog, onOpen, (error) => log(`${chalk.red('Error:')} ${error}`));
|
|
61
|
+
streamLogsAction(externalId, auth, renderLog, onOpen, (error) => log.error(`${chalk.red('Error:')} ${error}`), log);
|
|
54
62
|
// Return a special key for streaming mode
|
|
55
63
|
return {
|
|
56
64
|
success: true,
|
|
@@ -60,13 +68,13 @@ async function streamLogs({ name, externalId, auth, log, }) {
|
|
|
60
68
|
catch (err) {
|
|
61
69
|
spinner.fail('Failed to retrieve logs');
|
|
62
70
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
63
|
-
log(`Error: ${errorMessage}`);
|
|
71
|
+
log.error(`Error: ${errorMessage}`);
|
|
64
72
|
return { success: false, error: errorMessage };
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
async function getLogs({ name, externalId, auth, limit, json, utc, log, }) {
|
|
68
|
-
const spinner = ora(`Finding logs for function "${name}"`).start();
|
|
69
|
-
const { ok, error, logs, total } = await getLogsAction(externalId, { limit }, auth);
|
|
76
|
+
const spinner = log.ora(`Finding logs for function "${name}"`).start();
|
|
77
|
+
const { ok, error, logs, total } = await getLogsAction(externalId, { limit }, auth, log);
|
|
70
78
|
if (!ok) {
|
|
71
79
|
spinner.fail(`${chalk.red('Failed')} to retrieve logs`);
|
|
72
80
|
return { success: false, error: error || 'Unknown error' };
|
|
@@ -3,7 +3,7 @@ import type { CoreConfig, CoreResult } from '../index.js';
|
|
|
3
3
|
export interface FunctionTestOptions extends CoreConfig {
|
|
4
4
|
blueprint: ReadBlueprintResult;
|
|
5
5
|
args: {
|
|
6
|
-
name: string;
|
|
6
|
+
name: string | undefined;
|
|
7
7
|
};
|
|
8
8
|
flags: {
|
|
9
9
|
data?: string;
|
|
@@ -24,5 +24,7 @@ export interface FunctionTestOptions extends CoreConfig {
|
|
|
24
24
|
'document-id-after'?: string;
|
|
25
25
|
'media-library-id'?: string;
|
|
26
26
|
};
|
|
27
|
+
error: (message: string, options: object) => void;
|
|
28
|
+
helpText: string;
|
|
27
29
|
}
|
|
28
30
|
export declare function functionTestCore(options: FunctionTestOptions): Promise<CoreResult>;
|
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { cwd } from 'node:process';
|
|
4
|
-
import ora from 'ora';
|
|
5
4
|
import { testAction } from '../../actions/functions/test.js';
|
|
6
5
|
import config from '../../config.js';
|
|
7
6
|
import { SANITY_FUNCTION_DOCUMENT, SANITY_FUNCTION_MEDIA_LIBRARY_ASSET } from '../../constants.js';
|
|
8
7
|
import buildPayload from '../../utils/build-payload.js';
|
|
9
|
-
import { findFunctionInBlueprint } from '../../utils/find-function.js';
|
|
8
|
+
import { findFunctionInBlueprint, getFunctionNames } from '../../utils/find-function.js';
|
|
10
9
|
import { fetchAsset, fetchDocument } from '../../utils/functions/fetch-document.js';
|
|
11
10
|
import { parseJsonObject } from '../../utils/parse-json-object.js';
|
|
12
11
|
import { isEventType, isGroqContextOptions, } from '../../utils/types.js';
|
|
13
12
|
export async function functionTestCore(options) {
|
|
14
|
-
const { blueprint, log, args, flags } = options;
|
|
13
|
+
const { blueprint, log, error, args, flags, helpText } = options;
|
|
15
14
|
const { name: fnName } = args;
|
|
16
15
|
const { data, event, file, timeout, api, dataset, 'document-id': documentId, 'with-user-token': withUserToken, 'data-before': dataBefore, 'data-after': dataAfter, 'file-before': fileBefore, 'file-after': fileAfter, 'document-id-before': documentIdBefore, 'document-id-after': documentIdAfter, 'media-library-id': mediaLibraryId, } = flags;
|
|
17
16
|
const { parsedBlueprint } = blueprint;
|
|
18
17
|
const { 'project-id': projectId = blueprint?.projectId, 'organization-id': organizationId = blueprint?.organizationId, } = flags;
|
|
18
|
+
if (!fnName) {
|
|
19
|
+
const functionNames = getFunctionNames(blueprint.parsedBlueprint.resources);
|
|
20
|
+
const validNames = functionNames.length > 0
|
|
21
|
+
? `Valid names are: ${functionNames.join(', ')}`
|
|
22
|
+
: 'No functions are defined in the blueprint.';
|
|
23
|
+
error(`Missing required argument: name\n${validNames}\n`, { exit: false });
|
|
24
|
+
log(helpText);
|
|
25
|
+
return { success: true };
|
|
26
|
+
}
|
|
19
27
|
let eventType;
|
|
20
28
|
if (!event) {
|
|
21
29
|
eventType = 'create';
|
|
@@ -70,14 +78,14 @@ export async function functionTestCore(options) {
|
|
|
70
78
|
apiVersion: api,
|
|
71
79
|
apiHost: config.apiUrl,
|
|
72
80
|
token: config.token || undefined,
|
|
73
|
-
});
|
|
81
|
+
}, log);
|
|
74
82
|
after = await fetchDocument(documentIdAfter, {
|
|
75
83
|
projectId,
|
|
76
84
|
dataset,
|
|
77
85
|
apiVersion: api,
|
|
78
86
|
apiHost: config.apiUrl,
|
|
79
87
|
token: config.token || undefined,
|
|
80
|
-
});
|
|
88
|
+
}, log);
|
|
81
89
|
}
|
|
82
90
|
else if (documentIdBefore && documentIdAfter) {
|
|
83
91
|
before = await fetchAsset(documentIdBefore, {
|
|
@@ -85,13 +93,13 @@ export async function functionTestCore(options) {
|
|
|
85
93
|
apiVersion: api,
|
|
86
94
|
apiHost: config.apiUrl,
|
|
87
95
|
token: config.token || undefined,
|
|
88
|
-
});
|
|
96
|
+
}, log);
|
|
89
97
|
after = await fetchAsset(documentIdAfter, {
|
|
90
98
|
mediaLibraryId,
|
|
91
99
|
apiVersion: api,
|
|
92
100
|
apiHost: config.apiUrl,
|
|
93
101
|
token: config.token || undefined,
|
|
94
|
-
});
|
|
102
|
+
}, log);
|
|
95
103
|
}
|
|
96
104
|
let payload;
|
|
97
105
|
if (after) {
|
|
@@ -105,7 +113,7 @@ export async function functionTestCore(options) {
|
|
|
105
113
|
apiVersion: api,
|
|
106
114
|
apiHost: config.apiUrl,
|
|
107
115
|
token: config.token || undefined,
|
|
108
|
-
});
|
|
116
|
+
}, log);
|
|
109
117
|
}
|
|
110
118
|
else if (documentId) {
|
|
111
119
|
payload = await fetchAsset(documentId, {
|
|
@@ -113,7 +121,7 @@ export async function functionTestCore(options) {
|
|
|
113
121
|
apiVersion: api,
|
|
114
122
|
apiHost: config.apiUrl,
|
|
115
123
|
token: config.token || undefined,
|
|
116
|
-
});
|
|
124
|
+
}, log);
|
|
117
125
|
}
|
|
118
126
|
else {
|
|
119
127
|
payload = buildPayload({ data, file });
|
|
@@ -129,7 +137,7 @@ export async function functionTestCore(options) {
|
|
|
129
137
|
: {
|
|
130
138
|
event: 'schedule',
|
|
131
139
|
};
|
|
132
|
-
const spinner = ora('Executing function...').start();
|
|
140
|
+
const spinner = log.ora('Executing function...').start();
|
|
133
141
|
const { json, logs, error } = await testAction(resource, invokeOptions, contextOptions, {
|
|
134
142
|
timeout: timeout ? timeout : resource.timeout,
|
|
135
143
|
});
|
package/dist/cores/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type ReadBlueprintResult } from '../actions/blueprints/blueprint.js';
|
|
2
|
+
import type { Logger } from '../utils/logger.js';
|
|
2
3
|
import type { AuthParams, Result, ScopeType, Stack } from '../utils/types.js';
|
|
3
4
|
export * as blueprintsCores from './blueprints/index.js';
|
|
4
5
|
export * as functionsCores from './functions/index.js';
|
|
@@ -6,7 +7,7 @@ export interface CoreConfig {
|
|
|
6
7
|
/** The CLI binary name. */
|
|
7
8
|
bin: string;
|
|
8
9
|
/** The log output function. */
|
|
9
|
-
log:
|
|
10
|
+
log: ReturnType<typeof Logger>;
|
|
10
11
|
}
|
|
11
12
|
export interface BlueprintConfig extends CoreConfig {
|
|
12
13
|
token: string;
|
|
@@ -35,17 +36,13 @@ export type CoreResult = {
|
|
|
35
36
|
streaming?: Promise<void>;
|
|
36
37
|
error?: never;
|
|
37
38
|
});
|
|
38
|
-
type InitBlueprintConfigParams = {
|
|
39
|
-
bin: string;
|
|
40
|
-
log: (msg: string) => void;
|
|
39
|
+
type InitBlueprintConfigParams = CoreConfig & ({
|
|
41
40
|
validateToken: true;
|
|
42
41
|
token: string;
|
|
43
42
|
} | {
|
|
44
|
-
bin: string;
|
|
45
|
-
log: (msg: string) => void;
|
|
46
43
|
validateToken?: false;
|
|
47
44
|
token?: string;
|
|
48
|
-
};
|
|
45
|
+
});
|
|
49
46
|
export declare function initBlueprintConfig({ bin, log, token, validateToken, }: InitBlueprintConfigParams): Promise<Result<BlueprintConfig>>;
|
|
50
47
|
export declare function initDeployedBlueprintConfig(config: Partial<BlueprintConfig> & Pick<BlueprintConfig, 'bin' | 'log' | 'token'> & {
|
|
51
48
|
validateToken?: boolean;
|
package/dist/cores/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export * as functionsCores from './functions/index.js';
|
|
|
8
8
|
export async function initBlueprintConfig({ bin, log, token, validateToken = true, }) {
|
|
9
9
|
let checkedToken = token;
|
|
10
10
|
if (!token || (token && validateToken)) {
|
|
11
|
-
const tokenCheck = await validTokenOrErrorMessage(token);
|
|
11
|
+
const tokenCheck = await validTokenOrErrorMessage(log, token);
|
|
12
12
|
if (!tokenCheck.ok) {
|
|
13
13
|
return { ok: false, error: tokenCheck.error.message };
|
|
14
14
|
}
|
|
@@ -17,7 +17,7 @@ export async function initBlueprintConfig({ bin, log, token, validateToken = tru
|
|
|
17
17
|
if (!checkedToken) {
|
|
18
18
|
return { ok: false, error: 'A valid token is required but was not provided.' };
|
|
19
19
|
}
|
|
20
|
-
const blueprint = await readLocalBlueprint();
|
|
20
|
+
const blueprint = await readLocalBlueprint(log);
|
|
21
21
|
if (blueprint.errors.length > 0) {
|
|
22
22
|
log(presentBlueprintParserErrors(blueprint.errors));
|
|
23
23
|
return { ok: false, error: 'Blueprint file contains errors.' };
|
|
@@ -49,7 +49,7 @@ export async function initDeployedBlueprintConfig(config) {
|
|
|
49
49
|
return { ok: false, error: 'Missing Stack deployment configuration for Blueprint' };
|
|
50
50
|
}
|
|
51
51
|
const auth = { token: config.token, scopeType, scopeId };
|
|
52
|
-
const stackResponse = await getStack({ stackId, auth });
|
|
52
|
+
const stackResponse = await getStack({ stackId, auth, logger: config.log });
|
|
53
53
|
if (!stackResponse.ok) {
|
|
54
54
|
config.log(`Could not retrieve Stack deployment info for ${niceId(stackId)}.`);
|
|
55
55
|
config.log(`Run \`${config.bin} blueprints doctor\` for diagnostics.`);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { run };
|
|
1
|
+
export { run } from '@oclif/core';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { run };
|
|
1
|
+
export { run } from '@oclif/core';
|
package/dist/server/app.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Logger } from '../utils/logger.js';
|
|
1
2
|
import { type InvokeExecutionOptions } from '../utils/types.js';
|
|
2
|
-
declare const app: (host: string, port: number, executionOptions?: Partial<InvokeExecutionOptions>) => void;
|
|
3
|
+
declare const app: (host: string, port: number, logger: ReturnType<typeof Logger>, executionOptions?: Partial<InvokeExecutionOptions>) => void;
|
|
3
4
|
declare function parseDocumentUrl(url: string): {
|
|
4
5
|
projectId: string;
|
|
5
6
|
dataset: string;
|
package/dist/server/app.js
CHANGED
|
@@ -7,13 +7,13 @@ import config from '../config.js';
|
|
|
7
7
|
import { isRecord } from '../utils/is-record.js';
|
|
8
8
|
import { isEventType, isGroqContextOptions, } from '../utils/types.js';
|
|
9
9
|
import { handleInvokeRequest } from './handlers/invoke.js';
|
|
10
|
-
const app = (host, port, executionOptions) => {
|
|
10
|
+
const app = (host, port, logger, executionOptions) => {
|
|
11
11
|
const requestListener = async (req, res) => {
|
|
12
12
|
res.setHeader('Content-Type', 'application/json');
|
|
13
13
|
switch (true) {
|
|
14
14
|
case req.url === '/blueprint': {
|
|
15
15
|
try {
|
|
16
|
-
const { parsedBlueprint, projectId, organizationId } = await readLocalBlueprint();
|
|
16
|
+
const { parsedBlueprint, projectId, organizationId } = await readLocalBlueprint(logger);
|
|
17
17
|
res.setHeader('Content-Type', 'application/json');
|
|
18
18
|
res.writeHead(200);
|
|
19
19
|
res.end(JSON.stringify({ parsedBlueprint, projectId, organizationId })); // Use blueprint directly
|
|
@@ -42,7 +42,7 @@ const app = (host, port, executionOptions) => {
|
|
|
42
42
|
delete context.clientOptions.token;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
const result = await handleInvokeRequest(functionName, event, metadata, context, executionOptions);
|
|
45
|
+
const result = await handleInvokeRequest(functionName, event, metadata, context, logger, executionOptions);
|
|
46
46
|
// Add Server-Timing header
|
|
47
47
|
const timingHeaders = [];
|
|
48
48
|
for (const [key, value] of Object.entries(result.timings)) {
|
|
@@ -230,7 +230,7 @@ const app = (host, port, executionOptions) => {
|
|
|
230
230
|
const wss = new WebSocketServer({ port: 8974 });
|
|
231
231
|
wss.on('connection', async function connection(ws) {
|
|
232
232
|
ws.on('error', console.error);
|
|
233
|
-
const { fileInfo } = await readLocalBlueprint();
|
|
233
|
+
const { fileInfo } = await readLocalBlueprint(logger);
|
|
234
234
|
watchFile(fileInfo.blueprintFilePath, { interval: 2007 }, async () => {
|
|
235
235
|
ws.send('reload-blueprint');
|
|
236
236
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { Logger } from '../../utils/logger.js';
|
|
1
2
|
import type { InvocationResponse, InvokeContextOptions, InvokeExecutionOptions, InvokePayloadMetadata } from '../../utils/types.js';
|
|
2
|
-
export declare function handleInvokeRequest(functionName: string, event: Record<string, unknown>, metadata: InvokePayloadMetadata, context: InvokeContextOptions, executionOptions?: Partial<InvokeExecutionOptions>): Promise<InvocationResponse & {
|
|
3
|
+
export declare function handleInvokeRequest(functionName: string, event: Record<string, unknown>, metadata: InvokePayloadMetadata, context: InvokeContextOptions, logger: ReturnType<typeof Logger>, executionOptions?: Partial<InvokeExecutionOptions>): Promise<InvocationResponse & {
|
|
3
4
|
timings: Record<string, number>;
|
|
4
5
|
}>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { readLocalBlueprint } from '../../actions/blueprints/blueprint.js';
|
|
2
2
|
import { findFunctionInBlueprint } from '../../utils/find-function.js';
|
|
3
3
|
import invoke from '../../utils/invoke-local.js';
|
|
4
|
-
export async function handleInvokeRequest(functionName, event, metadata, context, executionOptions) {
|
|
4
|
+
export async function handleInvokeRequest(functionName, event, metadata, context, logger, executionOptions) {
|
|
5
5
|
const start = performance.now();
|
|
6
|
-
const { parsedBlueprint } = await readLocalBlueprint();
|
|
6
|
+
const { parsedBlueprint } = await readLocalBlueprint(logger);
|
|
7
7
|
const resource = findFunctionInBlueprint(parsedBlueprint, functionName);
|
|
8
8
|
const readBlueprintTime = performance.now() - start;
|
|
9
9
|
const payload = {
|
|
@@ -747,9 +747,6 @@ body {
|
|
|
747
747
|
header {
|
|
748
748
|
grid-area: header;
|
|
749
749
|
}
|
|
750
|
-
filters-component {
|
|
751
|
-
grid-area: filters;
|
|
752
|
-
}
|
|
753
750
|
nav {
|
|
754
751
|
grid-area: left-sidebar;
|
|
755
752
|
}
|
|
@@ -763,36 +760,6 @@ footer {
|
|
|
763
760
|
grid-area: footer;
|
|
764
761
|
}
|
|
765
762
|
|
|
766
|
-
/* Add styles for filters-component form */
|
|
767
|
-
/* Default (Mobile) Styles */
|
|
768
|
-
filters-component form {
|
|
769
|
-
display: block; /* Stack direct children */
|
|
770
|
-
padding: var(--m-space-3); /* Consistent padding */
|
|
771
|
-
border-bottom: 1px solid var(--card-border-color);
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
filters-component form > * {
|
|
775
|
-
/* Target direct children: dropdowns, fieldset */
|
|
776
|
-
display: block; /* Ensure they are block level */
|
|
777
|
-
width: 100%; /* Make them take full width */
|
|
778
|
-
margin-bottom: var(--m-space-3); /* Add space below each item when stacked */
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
filters-component form > *:last-child {
|
|
782
|
-
margin-bottom: 0; /* Remove margin from the last stacked item */
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
filters-component form label {
|
|
786
|
-
display: block; /* Ensure label stacks above input if needed */
|
|
787
|
-
margin-bottom: var(--m-space-1); /* Small space between label and input */
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
filters-component form input {
|
|
791
|
-
width: 100%; /* Make input fill its container */
|
|
792
|
-
box-sizing: border-box; /* Include padding/border in width calculation */
|
|
793
|
-
}
|
|
794
|
-
/* End of Mobile Styles */
|
|
795
|
-
|
|
796
763
|
/* Apply grid styles to main#main-content */
|
|
797
764
|
#main-content {
|
|
798
765
|
display: grid;
|
|
@@ -808,26 +775,6 @@ filters-component form input {
|
|
|
808
775
|
min-height: 0; /* Important for nested overflow/height */
|
|
809
776
|
}
|
|
810
777
|
|
|
811
|
-
payload-panel {
|
|
812
|
-
grid-area: payload;
|
|
813
|
-
max-height: 100%; /* Fit within allocated grid row space */
|
|
814
|
-
overflow: hidden; /* Let internal elements scroll */
|
|
815
|
-
min-height: 0; /* Allow shrinking */
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
response-panel {
|
|
819
|
-
grid-area: response;
|
|
820
|
-
max-height: 100%;
|
|
821
|
-
overflow: hidden;
|
|
822
|
-
min-height: 0;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
/* Target console-panel for grid area and height constraints */
|
|
826
|
-
console-panel {
|
|
827
|
-
grid-area: console;
|
|
828
|
-
overflow: hidden; /* The inner div handles scrolling */
|
|
829
|
-
}
|
|
830
|
-
|
|
831
778
|
@media (max-width: 40rem) {
|
|
832
779
|
/* Mobile layout: stack elements vertically */
|
|
833
780
|
#main-content {
|
|
@@ -843,20 +790,6 @@ console-panel {
|
|
|
843
790
|
overflow-y: auto; /* Allow scrolling for the whole main area */
|
|
844
791
|
}
|
|
845
792
|
|
|
846
|
-
/* Reset max-heights on mobile if they cause layout issues */
|
|
847
|
-
payload-panel,
|
|
848
|
-
response-panel,
|
|
849
|
-
console-panel {
|
|
850
|
-
max-height: none;
|
|
851
|
-
min-height: 200px; /* Give some minimum space on mobile */
|
|
852
|
-
overflow: auto; /* Allow individual scrolling if content is large */
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
/* Ensure console has reasonable height on mobile */
|
|
856
|
-
console-panel {
|
|
857
|
-
max-height: 400px; /* Allow more console height on mobile maybe */
|
|
858
|
-
}
|
|
859
|
-
|
|
860
793
|
.block-lg {
|
|
861
794
|
display: block !important;
|
|
862
795
|
}
|
|
@@ -878,27 +811,6 @@ console-panel {
|
|
|
878
811
|
.border-top-none-l {
|
|
879
812
|
border-top: 0;
|
|
880
813
|
}
|
|
881
|
-
|
|
882
|
-
/* Revert filters-component form to horizontal layout on larger screens */
|
|
883
|
-
filters-component form {
|
|
884
|
-
display: flex;
|
|
885
|
-
flex-direction: row;
|
|
886
|
-
align-items: flex-end; /* Align form elements along their bottom edge */
|
|
887
|
-
gap: var(--m-space-3); /* Space between elements */
|
|
888
|
-
padding-left: var(--m-space-3);
|
|
889
|
-
padding-bottom: var(--m-space-3);
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
filters-component form > * {
|
|
893
|
-
width: auto; /* Allow elements to size based on content/flex rules */
|
|
894
|
-
margin-bottom: 0; /* Remove stacking margin */
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
/* Optional: Give API version input a specific width or allow growth */
|
|
898
|
-
filters-component form fieldset {
|
|
899
|
-
min-width: 150px; /* Example minimum width */
|
|
900
|
-
/* flex-grow: 1; */ /* Uncomment to allow it to fill space */
|
|
901
|
-
}
|
|
902
814
|
}
|
|
903
815
|
|
|
904
816
|
header {
|
|
@@ -1088,34 +1000,6 @@ time {
|
|
|
1088
1000
|
font-family: var(--font-family-mono);
|
|
1089
1001
|
}
|
|
1090
1002
|
|
|
1091
|
-
response-panel,
|
|
1092
|
-
payload-panel {
|
|
1093
|
-
max-height: 100%;
|
|
1094
|
-
height: 100%;
|
|
1095
|
-
overflow: hidden;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
toggle-switch {
|
|
1099
|
-
display: inline-block;
|
|
1100
|
-
cursor: pointer;
|
|
1101
|
-
}
|
|
1102
|
-
|
|
1103
|
-
toggle-switch::part(track) {
|
|
1104
|
-
padding: 0.125em;
|
|
1105
|
-
border-radius: 1em;
|
|
1106
|
-
background-color: hsl(0, 0%, 67%);
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
toggle-switch::part(slider) {
|
|
1110
|
-
border-radius: 1em;
|
|
1111
|
-
background-color: hsl(0, 0%, 100%);
|
|
1112
|
-
box-shadow: 0.0625em 0.0625em 0.125em hsla(0, 0%, 0%, 0.25);
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
toggle-switch[checked]::part(track) {
|
|
1116
|
-
background-color: var(--color-interactive-primary-active-bg);
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
1003
|
/* Default sidebar */
|
|
1120
1004
|
#sidebar {
|
|
1121
1005
|
transition:
|
|
@@ -36,10 +36,10 @@ export class ClearButton extends ApiBaseElement {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
clear = () => {
|
|
39
|
-
// this.api.store.result = {logs: '', timings: {bundle: 0, execute: 0}}
|
|
40
39
|
this.dispatchEvent(
|
|
41
40
|
new CustomEvent('clear-console', {
|
|
42
41
|
bubbles: true,
|
|
42
|
+
composed: true,
|
|
43
43
|
}),
|
|
44
44
|
)
|
|
45
45
|
}
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
/* globals customElements document */
|
|
2
2
|
import {ApiBaseElement} from './api-base.js'
|
|
3
|
+
import {getSharedStyleSheets} from './shared-styles.js'
|
|
3
4
|
|
|
4
5
|
// Template for the console panel
|
|
5
|
-
const template =
|
|
6
|
+
const template = document.createElement('template')
|
|
7
|
+
template.innerHTML = `
|
|
8
|
+
<style>
|
|
9
|
+
:host {
|
|
10
|
+
grid-area: console;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@media (max-width: 40rem) {
|
|
15
|
+
:host {
|
|
16
|
+
max-height: 400px;
|
|
17
|
+
min-height: 200px;
|
|
18
|
+
overflow: auto;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
6
22
|
<div id="console-container" class="relative y-scroll h-100 max-h-100 bg-base pad-t-0 pad-r-3 pad-b-7 pad-l-5 border-top">
|
|
7
23
|
<div class="sticky top-0 left-0 right-0 mar-t-0 mar-b-0">
|
|
8
24
|
<h3 class="config-label mar-t-0 mar-b-0 pad-t-3 bg-base z-32">
|
|
@@ -17,10 +33,13 @@ const template = `
|
|
|
17
33
|
</div>
|
|
18
34
|
<pre id="console-output" class="pad-0 mar-t-0 mar-r-0 mar-b-5 mar-l-0 pre-wrap break-word"></pre>
|
|
19
35
|
</div>
|
|
20
|
-
|
|
21
36
|
`
|
|
22
37
|
|
|
23
38
|
class ConsolePanel extends ApiBaseElement {
|
|
39
|
+
constructor() {
|
|
40
|
+
super()
|
|
41
|
+
this.attachShadow({mode: 'open'}).appendChild(template.content.cloneNode(true))
|
|
42
|
+
}
|
|
24
43
|
updateConsole = ({result}) => {
|
|
25
44
|
// Guard against element not being ready or API not injected yet
|
|
26
45
|
if (!this.consoleOutput || !result) return
|
|
@@ -45,13 +64,15 @@ class ConsolePanel extends ApiBaseElement {
|
|
|
45
64
|
clear = () => {
|
|
46
65
|
const backUp = this.api.store.preserveLog
|
|
47
66
|
this.api.store.result = {logs: undefined, error: undefined}
|
|
48
|
-
this.
|
|
67
|
+
this.consoleOutput.innerText = ''
|
|
49
68
|
this.api.store.preserveLog = backUp
|
|
50
69
|
}
|
|
51
70
|
|
|
52
|
-
connectedCallback() {
|
|
53
|
-
|
|
54
|
-
this.
|
|
71
|
+
async connectedCallback() {
|
|
72
|
+
const sheets = await getSharedStyleSheets()
|
|
73
|
+
this.shadowRoot.adoptedStyleSheets = sheets
|
|
74
|
+
|
|
75
|
+
this.consoleOutput = this.shadowRoot.querySelector('#console-output')
|
|
55
76
|
this.addEventListener('clear-console', this.clear)
|
|
56
77
|
|
|
57
78
|
// Subscribe to changes in the result state to update the console
|
|
@@ -56,7 +56,7 @@ export class FetchButton extends ApiBaseElement {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
fetchDoc = async () => {
|
|
59
|
-
const docId =
|
|
59
|
+
const docId = this.api.store.docId.trim()
|
|
60
60
|
|
|
61
61
|
if (docId) {
|
|
62
62
|
const originalContent = this.button.innerHTML
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {ApiBaseElement} from './api-base.js'
|
|
2
|
+
|
|
3
|
+
import {getSharedStyleSheets} from './shared-styles.js'
|
|
4
|
+
|
|
5
|
+
const template = document.createElement('template')
|
|
6
|
+
template.innerHTML = `
|
|
4
7
|
<fieldset class="mar-t-2">
|
|
5
8
|
<label class="slab-text">
|
|
6
9
|
<span class="block mar-b-1">API Version</span>
|
|
@@ -8,6 +11,39 @@ class ApiVersionComponent extends HTMLElement {
|
|
|
8
11
|
</label>
|
|
9
12
|
</fieldset>
|
|
10
13
|
`
|
|
14
|
+
|
|
15
|
+
class ApiVersionComponent extends ApiBaseElement {
|
|
16
|
+
constructor() {
|
|
17
|
+
super()
|
|
18
|
+
this.attachShadow({mode: 'open'}).appendChild(template.content.cloneNode(true))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async connectedCallback() {
|
|
22
|
+
const sheets = await getSharedStyleSheets()
|
|
23
|
+
|
|
24
|
+
// Create a component-specific stylesheet that will be applied after shared styles
|
|
25
|
+
const componentSheet = new CSSStyleSheet()
|
|
26
|
+
await componentSheet.replace(`
|
|
27
|
+
:host {
|
|
28
|
+
align-self: flex-end;
|
|
29
|
+
}
|
|
30
|
+
fieldset {
|
|
31
|
+
margin-top: 0 !important;
|
|
32
|
+
}
|
|
33
|
+
input {
|
|
34
|
+
background: transparent !important;
|
|
35
|
+
color: light-dark(var(--gray-950), var(--gray-300)) !important;
|
|
36
|
+
}
|
|
37
|
+
`)
|
|
38
|
+
|
|
39
|
+
this.shadowRoot.adoptedStyleSheets = [...sheets, componentSheet]
|
|
40
|
+
|
|
41
|
+
this.input = this.shadowRoot.querySelector('input')
|
|
42
|
+
this.input.addEventListener('input', this.updateApiVersion)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
updateApiVersion = (event) => {
|
|
46
|
+
this.api.store.apiVersion = event.target.value
|
|
11
47
|
}
|
|
12
48
|
}
|
|
13
49
|
|