@solidactions/cli 3.27.0 → 3.29.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/dist/command-manifest.json +1 -1
- package/dist/commands/deploy.js +45 -8
- package/dist/commands/dev.js +6 -0
- package/dist/commands/env-list.js +5 -0
- package/dist/utils/env.js +12 -5
- package/dist/utils/functions-sync.js +104 -0
- package/package.json +2 -2
package/dist/commands/deploy.js
CHANGED
|
@@ -29,6 +29,7 @@ const prompts_1 = __importDefault(require("prompts"));
|
|
|
29
29
|
const env_1 = require("../utils/env");
|
|
30
30
|
const validate_items_1 = require("../utils/validate-items");
|
|
31
31
|
const pages_sync_1 = require("../utils/pages-sync");
|
|
32
|
+
const functions_sync_1 = require("../utils/functions-sync");
|
|
32
33
|
const api_1 = require("../utils/api");
|
|
33
34
|
const host_display_1 = require("../utils/host-display");
|
|
34
35
|
const deploy_ignore_1 = require("../utils/deploy-ignore");
|
|
@@ -265,6 +266,12 @@ function formatSyncYamlWarnings(warnings) {
|
|
|
265
266
|
return `${envName} → no workspace database named "${target}"`;
|
|
266
267
|
}
|
|
267
268
|
}
|
|
269
|
+
// Docs warnings carry their own full sentence; print it as is.
|
|
270
|
+
if ((warning?.reason === 'docs_path_not_found' || warning?.reason === 'docs_not_granted')
|
|
271
|
+
&& typeof warning.message === 'string'
|
|
272
|
+
&& warning.message !== '') {
|
|
273
|
+
return warning.message;
|
|
274
|
+
}
|
|
268
275
|
return `${envName} → unresolved (${warning?.reason ?? 'unknown reason'})`;
|
|
269
276
|
});
|
|
270
277
|
}
|
|
@@ -288,6 +295,7 @@ async function pushYamlDeclarations(config, projectSlug, yamlConfig) {
|
|
|
288
295
|
yaml_default_global_key: v.mappedTo,
|
|
289
296
|
yaml_default_oauth_name: v.oauthName,
|
|
290
297
|
yaml_default_database_name: v.databaseName,
|
|
298
|
+
yaml_default_docs_path: v.docsPath,
|
|
291
299
|
source: 'yaml',
|
|
292
300
|
}));
|
|
293
301
|
const response = await axios_1.default.post(`${config.host}/api/v1/projects/${projectSlug}/variable-mappings/sync-yaml`, { declarations }, {
|
|
@@ -310,7 +318,11 @@ async function pushYamlDeclarations(config, projectSlug, yamlConfig) {
|
|
|
310
318
|
for (const warning of warnings) {
|
|
311
319
|
console.log(chalk_1.default.yellow(` ⚠ ${warning}`));
|
|
312
320
|
}
|
|
313
|
-
|
|
321
|
+
// A docs warning does not hold the variable back (it still arrives, with
|
|
322
|
+
// level "none"), so the footer is only true when some warning is not a docs one.
|
|
323
|
+
const hasNonDocsWarning = Array.isArray(rawWarnings)
|
|
324
|
+
&& rawWarnings.some((w) => w?.reason !== 'docs_path_not_found' && w?.reason !== 'docs_not_granted');
|
|
325
|
+
if (hasNonDocsWarning) {
|
|
314
326
|
console.log(chalk_1.default.yellow(" These variables won't get a value from this declaration until the named resource exists (a value set in the dashboard still applies)."));
|
|
315
327
|
}
|
|
316
328
|
}
|
|
@@ -616,6 +628,36 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
616
628
|
console.error(chalk_1.default.red(`Failed to read page: ${error.message}`));
|
|
617
629
|
process.exit(1);
|
|
618
630
|
}
|
|
631
|
+
const codeRef = sourceMetadata ? {
|
|
632
|
+
branch: sourceMetadata.branch,
|
|
633
|
+
short_sha: sourceMetadata.short_sha,
|
|
634
|
+
commit_sha: sourceMetadata.commit_sha,
|
|
635
|
+
dirty: sourceMetadata.dirty,
|
|
636
|
+
} : null;
|
|
637
|
+
// Functions sync runs before the workflow archive build (spec 3.1): the
|
|
638
|
+
// server compiles and uploads each code function on its own. Editor
|
|
639
|
+
// pointers are never sent (listCodeFunctions skips them).
|
|
640
|
+
const functionFiles = (0, functions_sync_1.listCodeFunctions)(yamlConfig ?? {});
|
|
641
|
+
let functionSources;
|
|
642
|
+
try {
|
|
643
|
+
functionSources = (0, functions_sync_1.readFunctionSources)(sourceDir, functionFiles);
|
|
644
|
+
}
|
|
645
|
+
catch (error) {
|
|
646
|
+
console.error(chalk_1.default.red(`Failed to read function: ${error.message}`));
|
|
647
|
+
process.exit(1);
|
|
648
|
+
}
|
|
649
|
+
const functionsPayload = (0, functions_sync_1.buildFunctionsSyncPayload)(functionFiles, functionSources, codeRef);
|
|
650
|
+
const functionsResult = await (0, functions_sync_1.syncFunctions)(config, projectSlug, functionsPayload);
|
|
651
|
+
const functionRows = functionsResult.body?.functions ?? [];
|
|
652
|
+
const retiredFunctions = functionsResult.body?.retired ?? [];
|
|
653
|
+
const retireErrors = functionsResult.body?.retire_errors ?? [];
|
|
654
|
+
const functionsInput = { httpStatus: functionsResult.httpStatus, transportError: functionsResult.transportError, sentFunctionCount: functionFiles.length };
|
|
655
|
+
const functionsFailure = (0, functions_sync_1.formatFunctionsSyncFailure)({ ...functionsInput, body: functionsResult.body });
|
|
656
|
+
for (const line of (0, functions_sync_1.formatFunctionsSummary)(functionRows, retiredFunctions, retireErrors))
|
|
657
|
+
console.log(line);
|
|
658
|
+
if (functionsFailure)
|
|
659
|
+
console.error(chalk_1.default.red(functionsFailure));
|
|
660
|
+
const functionsOutcome = (0, functions_sync_1.functionsSyncOutcome)({ ...functionsInput, body: functionsResult.body, rows: functionRows, retireErrors });
|
|
619
661
|
const finishDeploy = async ({ deploymentId, buildFailed }) => {
|
|
620
662
|
let yamlSyncFailed = false;
|
|
621
663
|
if (yamlConfig) {
|
|
@@ -632,12 +674,6 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
632
674
|
}
|
|
633
675
|
}
|
|
634
676
|
}
|
|
635
|
-
const codeRef = sourceMetadata ? {
|
|
636
|
-
branch: sourceMetadata.branch,
|
|
637
|
-
short_sha: sourceMetadata.short_sha,
|
|
638
|
-
commit_sha: sourceMetadata.commit_sha,
|
|
639
|
-
dirty: sourceMetadata.dirty,
|
|
640
|
-
} : null;
|
|
641
677
|
const payload = (0, pages_sync_1.buildPagesSyncPayload)(pageFiles, pageBodies, deploymentId, codeRef);
|
|
642
678
|
const result = await (0, pages_sync_1.syncPages)(config, projectSlug, payload);
|
|
643
679
|
const rows = result.body?.pages ?? [];
|
|
@@ -649,7 +685,8 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
649
685
|
console.log(line);
|
|
650
686
|
if (failure)
|
|
651
687
|
console.error(chalk_1.default.red(failure));
|
|
652
|
-
const
|
|
688
|
+
const pagesOutcome = (0, pages_sync_1.pagesSyncOutcome)({ ...input, rows, trashErrors, stamp: result.body?.stamp });
|
|
689
|
+
const outcome = (0, functions_sync_1.joinSyncOutcomes)(functionsOutcome, pagesOutcome);
|
|
653
690
|
process.exit((0, pages_sync_1.terminalExitCode)({ buildFailed, yamlSyncFailed, outcome }));
|
|
654
691
|
};
|
|
655
692
|
if (!yamlConfig?.workflows) {
|
package/dist/commands/dev.js
CHANGED
|
@@ -516,6 +516,12 @@ async function runDev(opts) {
|
|
|
516
516
|
// mapping as "had no value in this env and was skipped" (#140).
|
|
517
517
|
databaseMappings.push(pv);
|
|
518
518
|
}
|
|
519
|
+
else if (pv.source_type === 'docs_node' && pv.resolved_value != null) {
|
|
520
|
+
// A docs binding arrives as the run-env JSON ({path, kind, id, level}),
|
|
521
|
+
// the same string a deployed run reads; pass it through, never count
|
|
522
|
+
// it as dropped.
|
|
523
|
+
vars[pv.env_name] = pv.resolved_value;
|
|
524
|
+
}
|
|
519
525
|
else if (pv.resolved_value != null) {
|
|
520
526
|
vars[pv.env_name] = pv.resolved_value;
|
|
521
527
|
}
|
|
@@ -76,6 +76,11 @@ async function envList(projectName, options = {}) {
|
|
|
76
76
|
|| 'Database';
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
+
else if (mapping.source_type === 'docs_node') {
|
|
80
|
+
value = '-';
|
|
81
|
+
type = 'docs';
|
|
82
|
+
source = mapping.yaml_default_docs_path || 'Docs';
|
|
83
|
+
}
|
|
79
84
|
else if (mapping.global_variable_key) {
|
|
80
85
|
type = 'global';
|
|
81
86
|
source = mapping.global_variable_key;
|
package/dist/utils/env.js
CHANGED
|
@@ -52,6 +52,7 @@ function parseEnvFile(filePath) {
|
|
|
52
52
|
* - VAR_NAME: GLOBAL -> { key: "VAR_NAME", mappedTo: "GLOBAL" }
|
|
53
53
|
* - VAR_NAME:\n oauth: "Name" -> { key: "VAR_NAME", oauthName: "Name" }
|
|
54
54
|
* - VAR_NAME:\n database: "Name" -> { key: "VAR_NAME", databaseName: "Name" }
|
|
55
|
+
* - VAR_NAME:\n docs: "Folder/Path" -> { key: "VAR_NAME", docsPath: "Folder/Path" }
|
|
55
56
|
*/
|
|
56
57
|
function parseYamlEnvVars(config) {
|
|
57
58
|
const parsedVars = [];
|
|
@@ -61,11 +62,11 @@ function parseYamlEnvVars(config) {
|
|
|
61
62
|
for (const item of config.env) {
|
|
62
63
|
if (typeof item === 'string') {
|
|
63
64
|
// Simple string: - VAR_NAME (declared only, needs configuration)
|
|
64
|
-
parsedVars.push({ key: item, mappedTo: null, oauthName: null, databaseName: null });
|
|
65
|
+
parsedVars.push({ key: item, mappedTo: null, oauthName: null, databaseName: null, docsPath: null });
|
|
65
66
|
}
|
|
66
67
|
else if (typeof item === 'object' && item !== null) {
|
|
67
68
|
// Object: - VAR_NAME: GLOBAL_NAME, - VAR_NAME: { oauth: connection-name },
|
|
68
|
-
//
|
|
69
|
+
// - VAR_NAME: { database: database-name }, or - VAR_NAME: { docs: folder/or/doc/path }
|
|
69
70
|
const keys = Object.keys(item);
|
|
70
71
|
if (keys.length === 1) {
|
|
71
72
|
const key = keys[0];
|
|
@@ -74,16 +75,22 @@ function parseYamlEnvVars(config) {
|
|
|
74
75
|
if (typeof value.oauth !== 'string' || !value.oauth) {
|
|
75
76
|
throw new Error(`Invalid env config for ${key}: 'oauth' must be a non-empty string`);
|
|
76
77
|
}
|
|
77
|
-
parsedVars.push({ key, mappedTo: null, oauthName: value.oauth, databaseName: null });
|
|
78
|
+
parsedVars.push({ key, mappedTo: null, oauthName: value.oauth, databaseName: null, docsPath: null });
|
|
78
79
|
}
|
|
79
80
|
else if (typeof value === 'object' && value !== null && 'database' in value) {
|
|
80
81
|
if (typeof value.database !== 'string' || !value.database) {
|
|
81
82
|
throw new Error(`Invalid env config for ${key}: 'database' must be a non-empty string`);
|
|
82
83
|
}
|
|
83
|
-
parsedVars.push({ key, mappedTo: null, oauthName: null, databaseName: value.database });
|
|
84
|
+
parsedVars.push({ key, mappedTo: null, oauthName: null, databaseName: value.database, docsPath: null });
|
|
85
|
+
}
|
|
86
|
+
else if (typeof value === 'object' && value !== null && 'docs' in value) {
|
|
87
|
+
if (typeof value.docs !== 'string' || !value.docs.trim()) {
|
|
88
|
+
throw new Error(`Invalid env config for ${key}: 'docs' must be a non-empty string`);
|
|
89
|
+
}
|
|
90
|
+
parsedVars.push({ key, mappedTo: null, oauthName: null, databaseName: null, docsPath: value.docs });
|
|
84
91
|
}
|
|
85
92
|
else {
|
|
86
|
-
parsedVars.push({ key, mappedTo: value || null, oauthName: null, databaseName: null });
|
|
93
|
+
parsedVars.push({ key, mappedTo: value || null, oauthName: null, databaseName: null, docsPath: null });
|
|
87
94
|
}
|
|
88
95
|
}
|
|
89
96
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FUNCTIONS_SYNC_TIMEOUT_MS = void 0;
|
|
7
|
+
exports.listCodeFunctions = listCodeFunctions;
|
|
8
|
+
exports.readFunctionSources = readFunctionSources;
|
|
9
|
+
exports.buildFunctionsSyncPayload = buildFunctionsSyncPayload;
|
|
10
|
+
exports.formatFunctionsSummary = formatFunctionsSummary;
|
|
11
|
+
exports.functionsSyncOutcome = functionsSyncOutcome;
|
|
12
|
+
exports.joinSyncOutcomes = joinSyncOutcomes;
|
|
13
|
+
exports.formatFunctionsSyncFailure = formatFunctionsSyncFailure;
|
|
14
|
+
exports.syncFunctions = syncFunctions;
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const api_1 = require("./api");
|
|
19
|
+
function listCodeFunctions(config) {
|
|
20
|
+
return (config.functions ?? []).filter(entry => typeof entry === 'object' && entry !== null && entry.owner !== 'editor').map(entry => {
|
|
21
|
+
const fn = entry;
|
|
22
|
+
return {
|
|
23
|
+
id: fn.id,
|
|
24
|
+
name: fn.name,
|
|
25
|
+
file: fn.file,
|
|
26
|
+
...(fn.description === undefined ? {} : { description: fn.description }),
|
|
27
|
+
...(fn.webhook === undefined ? {} : { webhook: fn.webhook }),
|
|
28
|
+
...(fn.webhook_auth === undefined ? {} : { webhook_auth: fn.webhook_auth }),
|
|
29
|
+
...(fn.mcp === undefined ? {} : { mcp: fn.mcp }),
|
|
30
|
+
...(fn.mcp_tool_name === undefined ? {} : { mcp_tool_name: fn.mcp_tool_name }),
|
|
31
|
+
...(fn.timeout === undefined ? {} : { timeout: fn.timeout }),
|
|
32
|
+
...(fn.confirm === undefined ? {} : { confirm: fn.confirm }),
|
|
33
|
+
...(fn.input_schema === undefined ? {} : { input_schema: fn.input_schema }),
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function readFunctionSources(sourceDir, functions) {
|
|
38
|
+
return new Map(functions.map(fn => [fn.id, fs_1.default.readFileSync(path_1.default.join(sourceDir, fn.file), 'utf8')]));
|
|
39
|
+
}
|
|
40
|
+
function buildFunctionsSyncPayload(functions, sources, codeRef) {
|
|
41
|
+
return { code_ref: codeRef, functions: functions.map(fn => ({ ...fn, source: sources.get(fn.id) })) };
|
|
42
|
+
}
|
|
43
|
+
function formatFunctionsSummary(rows, retired, retireErrors) {
|
|
44
|
+
return [
|
|
45
|
+
...rows.map(row => row.status === 'error'
|
|
46
|
+
? `function ${row.id}: error ${row.error.code}: ${row.error.message}`
|
|
47
|
+
: `function ${row.id}: ${row.status}${row.webhook_url === null ? '' : ` ${row.webhook_url}`}`),
|
|
48
|
+
...retired.map(row => `function ${row.id}: retired`),
|
|
49
|
+
...retireErrors.map(row => `function ${row.id}: retired, its script delete failed and will retry: ${row.error.message}`),
|
|
50
|
+
];
|
|
51
|
+
}
|
|
52
|
+
function responseBodyCode(body) {
|
|
53
|
+
if (body !== null && typeof body === 'object' && 'code' in body && typeof body.code === 'string')
|
|
54
|
+
return body.code;
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
function functionsSyncOutcome(input) {
|
|
58
|
+
if (input.transportError)
|
|
59
|
+
return 'failed';
|
|
60
|
+
if (input.httpStatus === 404 && input.sentFunctionCount === 0)
|
|
61
|
+
return 'skipped-old-server';
|
|
62
|
+
if (input.httpStatus === 503 && input.sentFunctionCount === 0 && responseBodyCode(input.body) === 'functions_disabled')
|
|
63
|
+
return 'skipped-old-server';
|
|
64
|
+
if (input.httpStatus === null || input.httpStatus < 200 || input.httpStatus >= 300)
|
|
65
|
+
return 'failed';
|
|
66
|
+
return input.rows.some(row => row.status === 'error') ? 'failed' : 'ok';
|
|
67
|
+
}
|
|
68
|
+
/** Joins the functions and pages outcomes for the deploy exit code. */
|
|
69
|
+
function joinSyncOutcomes(functionsOutcome, pagesOutcome) {
|
|
70
|
+
if (functionsOutcome === 'failed' || pagesOutcome === 'failed')
|
|
71
|
+
return 'failed';
|
|
72
|
+
if (functionsOutcome === 'ok' || pagesOutcome === 'ok')
|
|
73
|
+
return 'ok';
|
|
74
|
+
return 'skipped-old-server';
|
|
75
|
+
}
|
|
76
|
+
function formatFunctionsSyncFailure(input) {
|
|
77
|
+
if (input.transportError)
|
|
78
|
+
return 'functions sync failed: could not reach the server';
|
|
79
|
+
if (input.httpStatus !== null && input.httpStatus >= 200 && input.httpStatus < 300)
|
|
80
|
+
return null;
|
|
81
|
+
if (input.httpStatus === 404)
|
|
82
|
+
return input.sentFunctionCount === 0 ? null : 'This server does not support functions yet; upgrade the platform';
|
|
83
|
+
if (input.httpStatus === 503 && input.sentFunctionCount === 0 && responseBodyCode(input.body) === 'functions_disabled')
|
|
84
|
+
return null;
|
|
85
|
+
if (input.body !== null && typeof input.body === 'object' && 'code' in input.body && 'message' in input.body && typeof input.body.code === 'string' && typeof input.body.message === 'string') {
|
|
86
|
+
return `functions sync failed (${input.httpStatus} ${input.body.code}): ${input.body.message}`;
|
|
87
|
+
}
|
|
88
|
+
// Laravel's own validation 422 carries `message` and `errors` but no `code`.
|
|
89
|
+
if (input.body !== null && typeof input.body === 'object' && 'message' in input.body && typeof input.body.message === 'string') {
|
|
90
|
+
return `functions sync failed (HTTP ${input.httpStatus}): ${input.body.message}`;
|
|
91
|
+
}
|
|
92
|
+
return `functions sync failed (HTTP ${input.httpStatus})`;
|
|
93
|
+
}
|
|
94
|
+
/** HTTP client timeout for the functions/sync call (P7: the server holds the request up to 180 s). */
|
|
95
|
+
exports.FUNCTIONS_SYNC_TIMEOUT_MS = 210_000;
|
|
96
|
+
async function syncFunctions(config, projectSlug, payload) {
|
|
97
|
+
try {
|
|
98
|
+
const response = await axios_1.default.put(`${config.host}/api/v1/projects/${encodeURIComponent(projectSlug)}/functions/sync`, payload, { headers: (0, api_1.getApiHeaders)(config, 'application/json'), timeout: exports.FUNCTIONS_SYNC_TIMEOUT_MS });
|
|
99
|
+
return { httpStatus: response.status, transportError: false, body: response.data };
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return { httpStatus: error.response?.status ?? null, transportError: !error.response, body: error.response?.data ?? null };
|
|
103
|
+
}
|
|
104
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidactions/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.29.0",
|
|
4
4
|
"description": "SolidActions CLI - Deploy and manage workflow automation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"tar": "^7.5.22"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@solidactions/sdk": "^0.
|
|
57
|
+
"@solidactions/sdk": "^0.10.0",
|
|
58
58
|
"@types/archiver": "^8.0.0",
|
|
59
59
|
"@types/fs-extra": "^11.0.0",
|
|
60
60
|
"@types/js-yaml": "^4.0.9",
|