@solidactions/cli 3.25.0 → 3.27.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.
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.out = out;
4
+ exports.err = err;
5
+ const connect_link_1 = require("./connect-link");
6
+ /**
7
+ * stdout: strip control bytes with plainText, then apply the optional style.
8
+ * The style runs after stripping so plainText never eats the style's own
9
+ * escape codes. This is the only stdout path the connection commands use.
10
+ */
11
+ function out(text, style) {
12
+ const clean = (0, connect_link_1.plainText)(text);
13
+ console.log(style ? style(clean) : clean);
14
+ }
15
+ /**
16
+ * stderr: strip control bytes with plainText, then apply the optional style.
17
+ * This is the only stderr path the connection commands use.
18
+ */
19
+ function err(text, style) {
20
+ const clean = (0, connect_link_1.plainText)(text);
21
+ console.error(style ? style(clean) : clean);
22
+ }
@@ -0,0 +1,83 @@
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.listCodePages = listCodePages;
7
+ exports.readPageBodies = readPageBodies;
8
+ exports.buildPagesSyncPayload = buildPagesSyncPayload;
9
+ exports.formatPagesSummary = formatPagesSummary;
10
+ exports.pagesSyncOutcome = pagesSyncOutcome;
11
+ exports.formatPagesSyncFailure = formatPagesSyncFailure;
12
+ exports.terminalExitCode = terminalExitCode;
13
+ exports.syncPages = syncPages;
14
+ const fs_1 = __importDefault(require("fs"));
15
+ const path_1 = __importDefault(require("path"));
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const api_1 = require("./api");
18
+ const validate_items_1 = require("./validate-items");
19
+ function listCodePages(config) {
20
+ return (config.pages ?? []).filter(page => !(0, validate_items_1.isPagePointer)(page)).map(page => ({
21
+ slug: page.id,
22
+ name: page.name,
23
+ path: page.file,
24
+ kind: page.file.endsWith('.html') ? 'visual' : 'dashboard',
25
+ home: page.home ?? false,
26
+ ...(page.sources === undefined ? {} : { sources: page.sources }),
27
+ }));
28
+ }
29
+ function readPageBodies(sourceDir, pages) {
30
+ return new Map(pages.map(page => [page.slug, fs_1.default.readFileSync(path_1.default.join(sourceDir, page.path), 'utf8')]));
31
+ }
32
+ function buildPagesSyncPayload(pages, bodies, deploymentId, codeRef) {
33
+ return { deployment_id: deploymentId, code_ref: codeRef, pages: pages.map(page => ({ ...page, body: bodies.get(page.slug) })) };
34
+ }
35
+ function formatPagesSummary(rows, trashed, trashErrors) {
36
+ return [
37
+ ...rows.map(row => row.status === 'live'
38
+ ? `page ${row.slug}: live${row.url === null ? '' : ` ${row.url}`}`
39
+ : `page ${row.slug}: error ${row.error.code}: ${row.error.message}`),
40
+ ...trashed.map(row => `page ${row.slug}: moved to trash (id ${row.id})`),
41
+ ...trashErrors.map(row => `page ${row.slug}: could not move to trash: ${row.error.code}: ${row.error.message}`),
42
+ ];
43
+ }
44
+ function pagesSyncOutcome(input) {
45
+ if (input.transportError)
46
+ return 'failed';
47
+ if (input.httpStatus === 404 && input.sentPageCount === 0)
48
+ return 'skipped-old-server';
49
+ if (input.httpStatus === null || input.httpStatus < 200 || input.httpStatus >= 300)
50
+ return 'failed';
51
+ return input.stamp === 'superseded' || input.stamp === 'failed' || input.rows.some(row => row.status === 'error') || input.trashErrors.length > 0 ? 'failed' : 'ok';
52
+ }
53
+ function formatPagesSyncFailure(input) {
54
+ if (input.transportError)
55
+ return 'pages sync failed: could not reach the server';
56
+ if (input.httpStatus !== null && input.httpStatus >= 200 && input.httpStatus < 300) {
57
+ if (input.body !== null && typeof input.body === 'object' && 'stamp' in input.body) {
58
+ if (input.body.stamp === 'superseded')
59
+ return 'pages sync superseded: a newer deploy of this project took over';
60
+ if (input.body.stamp === 'failed')
61
+ return 'pages sync failed: pages finished but completion could not be recorded; cleanup may be incomplete: deploy again';
62
+ }
63
+ return null;
64
+ }
65
+ if (input.httpStatus === 404)
66
+ return input.sentPageCount === 0 ? null : 'This server does not support pages: yet; upgrade the platform';
67
+ 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') {
68
+ return `pages sync failed (${input.httpStatus} ${input.body.code}): ${input.body.message}`;
69
+ }
70
+ return `pages sync failed (HTTP ${input.httpStatus})`;
71
+ }
72
+ function terminalExitCode(input) {
73
+ return input.buildFailed || input.yamlSyncFailed || input.outcome === 'failed' ? 1 : 0;
74
+ }
75
+ async function syncPages(config, projectSlug, payload) {
76
+ try {
77
+ const response = await axios_1.default.put(`${config.host}/api/v1/projects/${encodeURIComponent(projectSlug)}/pages/sync`, payload, { headers: (0, api_1.getApiHeaders)(config, 'application/json') });
78
+ return { httpStatus: response.status, transportError: false, body: response.data };
79
+ }
80
+ catch (error) {
81
+ return { httpStatus: error.response?.status ?? null, transportError: !error.response, body: error.response?.data ?? null };
82
+ }
83
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTerminalGate = createTerminalGate;
4
+ function createTerminalGate() {
5
+ let claimed = false;
6
+ return {
7
+ claim: () => {
8
+ if (claimed)
9
+ return false;
10
+ claimed = true;
11
+ return true;
12
+ },
13
+ };
14
+ }
@@ -0,0 +1,164 @@
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.isPagePointer = isPagePointer;
7
+ exports.validateItems = validateItems;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const slug_1 = require("./slug");
11
+ function isPagePointer(e) {
12
+ return e.owner === 'editor';
13
+ }
14
+ const SLUG_RE = /^[a-z0-9][a-z0-9-]{0,62}$/;
15
+ const MAX_PAGES = 50;
16
+ const MAX_FUNCTIONS = 50;
17
+ const MAX_PAGE_FILE_BYTES = 1024 * 1024;
18
+ const MAX_FUNCTION_FILE_BYTES = 256 * 1024;
19
+ const PAGE_EXTENSIONS = ['.html', '.tsx'];
20
+ const WEBHOOK_AUTHS = ['hmac', 'basic', 'header', 'none'];
21
+ function label(kind, id, index) {
22
+ return `${kind}[${String(id ?? index)}]`;
23
+ }
24
+ function describeReceived(value) {
25
+ return JSON.stringify(value) ?? typeof value;
26
+ }
27
+ function isEditorOwned(entry) {
28
+ return entry.owner === 'editor';
29
+ }
30
+ function checkFile(sourceDir, kind, entryLabel, file, allowedExtensions, maxBytes, limitName) {
31
+ const noun = kind === 'pages' ? 'page file' : 'function file';
32
+ if (typeof file !== 'string' || file === '') {
33
+ return [{ entry: entryLabel, field: 'file', message: `${entryLabel}.file: ${noun} is required.` }];
34
+ }
35
+ if (!allowedExtensions.includes(path_1.default.extname(file))) {
36
+ return [{ entry: entryLabel, field: 'file', message: `${entryLabel}.file: ${noun} "${file}" must end in ${allowedExtensions.join(' or ')}.` }];
37
+ }
38
+ let stat;
39
+ try {
40
+ stat = fs_1.default.statSync(path_1.default.join(sourceDir, file));
41
+ }
42
+ catch {
43
+ return [{ entry: entryLabel, field: 'file', message: `${entryLabel}.file: ${noun} "${file}" not found.` }];
44
+ }
45
+ if (!stat.isFile()) {
46
+ return [{ entry: entryLabel, field: 'file', message: `${entryLabel}.file: ${noun} "${file}" is not a file.` }];
47
+ }
48
+ if (stat.size > maxBytes) {
49
+ return [{ entry: entryLabel, field: 'file', message: `${entryLabel}.file: ${noun} "${file}" is ${stat.size} bytes, over the ${limitName} limit.` }];
50
+ }
51
+ return [];
52
+ }
53
+ function validateItems(config, sourceDir) {
54
+ const errors = [];
55
+ if (config.pages !== undefined && !Array.isArray(config.pages)) {
56
+ errors.push({ entry: 'pages', field: 'pages', message: 'pages: pages must be a list.' });
57
+ }
58
+ if (config.functions !== undefined && !Array.isArray(config.functions)) {
59
+ errors.push({ entry: 'functions', field: 'functions', message: 'functions: functions must be a list.' });
60
+ }
61
+ const pages = Array.isArray(config.pages) ? config.pages : [];
62
+ const functions = Array.isArray(config.functions) ? config.functions : [];
63
+ if (pages.length > MAX_PAGES) {
64
+ errors.push({ entry: 'pages', field: 'pages', message: `pages: at most 50 pages per project (got ${pages.length}).` });
65
+ }
66
+ if (functions.length > MAX_FUNCTIONS) {
67
+ errors.push({ entry: 'functions', field: 'functions', message: `functions: at most 50 functions per project (got ${functions.length}).` });
68
+ }
69
+ const seenPageSlugs = new Map();
70
+ let firstHomeLabel = null;
71
+ pages.forEach((entry, index) => {
72
+ if (typeof entry !== 'object' || entry === null) {
73
+ const entryLabel = label('pages', undefined, index);
74
+ errors.push({ entry: entryLabel, field: 'pages', message: `${entryLabel}.pages: page entry must be an object (got ${describeReceived(entry)}).` });
75
+ return;
76
+ }
77
+ const rawId = entry.id;
78
+ const entryLabel = label('pages', rawId, index);
79
+ if (isEditorOwned(entry)) {
80
+ const file = entry.file;
81
+ if (file !== undefined) {
82
+ errors.push({ entry: entryLabel, field: 'file', message: `${entryLabel}.file: a page made in the app (owner: editor) can't have a file: "${String(file)}".` });
83
+ }
84
+ return;
85
+ }
86
+ if (typeof rawId !== 'string' || !SLUG_RE.test(rawId)) {
87
+ errors.push({ entry: entryLabel, field: 'id', message: `${entryLabel}.id: invalid slug "${String(rawId)}" — slugs must match [a-z0-9][a-z0-9-]{0,62}.` });
88
+ }
89
+ else if (seenPageSlugs.has(rawId)) {
90
+ errors.push({ entry: entryLabel, field: 'id', message: `${entryLabel}.id: duplicate page slug "${rawId}" (already used by ${seenPageSlugs.get(rawId)}).` });
91
+ }
92
+ else {
93
+ seenPageSlugs.set(rawId, entryLabel);
94
+ }
95
+ if (entry.home === true) {
96
+ if (firstHomeLabel === null) {
97
+ firstHomeLabel = entryLabel;
98
+ }
99
+ else {
100
+ errors.push({ entry: entryLabel, field: 'home', message: `${entryLabel}.home: at most one page may have home: true (already set on ${firstHomeLabel}).` });
101
+ }
102
+ }
103
+ errors.push(...checkFile(sourceDir, 'pages', entryLabel, entry.file, PAGE_EXTENSIONS, MAX_PAGE_FILE_BYTES, '1 MB'));
104
+ });
105
+ const workflows = Array.isArray(config.workflows) ? config.workflows : [];
106
+ const workflowSlugs = new Set();
107
+ for (const [index, wf] of workflows.entries()) {
108
+ if (typeof wf !== 'object' || wf === null) {
109
+ const entryLabel = label('workflows', undefined, index);
110
+ errors.push({ entry: entryLabel, field: 'workflows', message: `${entryLabel}.workflows: workflow entry must be an object (got ${describeReceived(wf)}).` });
111
+ continue;
112
+ }
113
+ if (typeof wf.id === 'string' && wf.id !== '') {
114
+ workflowSlugs.add(wf.id);
115
+ }
116
+ if (typeof wf.name === 'string' && wf.name !== '') {
117
+ const slug = (0, slug_1.slugifyName)(wf.name);
118
+ if (slug !== '') {
119
+ workflowSlugs.add(slug);
120
+ }
121
+ }
122
+ }
123
+ const seenFunctionSlugs = new Map();
124
+ functions.forEach((entry, index) => {
125
+ if (typeof entry !== 'object' || entry === null) {
126
+ const entryLabel = label('functions', undefined, index);
127
+ errors.push({ entry: entryLabel, field: 'functions', message: `${entryLabel}.functions: function entry must be an object (got ${describeReceived(entry)}).` });
128
+ return;
129
+ }
130
+ const rawId = entry.id;
131
+ const entryLabel = label('functions', rawId, index);
132
+ if (isEditorOwned(entry)) {
133
+ const file = entry.file;
134
+ if (file !== undefined) {
135
+ errors.push({ entry: entryLabel, field: 'file', message: `${entryLabel}.file: a function made in the app (owner: editor) can't have a file: "${String(file)}".` });
136
+ }
137
+ return;
138
+ }
139
+ if (typeof rawId !== 'string' || !SLUG_RE.test(rawId)) {
140
+ errors.push({ entry: entryLabel, field: 'id', message: `${entryLabel}.id: invalid slug "${String(rawId)}" — slugs must match [a-z0-9][a-z0-9-]{0,62}.` });
141
+ }
142
+ else {
143
+ if (seenFunctionSlugs.has(rawId)) {
144
+ errors.push({ entry: entryLabel, field: 'id', message: `${entryLabel}.id: duplicate function slug "${rawId}" (already used by ${seenFunctionSlugs.get(rawId)}).` });
145
+ }
146
+ else {
147
+ seenFunctionSlugs.set(rawId, entryLabel);
148
+ }
149
+ if (workflowSlugs.has(rawId)) {
150
+ errors.push({ entry: entryLabel, field: 'id', message: `${entryLabel}.id: function slug "${rawId}" is already used by a workflow.` });
151
+ }
152
+ }
153
+ errors.push(...checkFile(sourceDir, 'functions', entryLabel, entry.file, ['.ts'], MAX_FUNCTION_FILE_BYTES, '256 KB'));
154
+ const timeout = entry.timeout;
155
+ if (timeout !== undefined && (typeof timeout !== 'number' || Number.isNaN(timeout) || timeout < 1 || timeout > 30)) {
156
+ errors.push({ entry: entryLabel, field: 'timeout', message: `${entryLabel}.timeout: timeout must be between 1 and 30 seconds (got ${JSON.stringify(timeout)}).` });
157
+ }
158
+ const webhookAuth = entry.webhook_auth;
159
+ if (webhookAuth !== undefined && (typeof webhookAuth !== 'string' || !WEBHOOK_AUTHS.includes(webhookAuth))) {
160
+ errors.push({ entry: entryLabel, field: 'webhook_auth', message: `${entryLabel}.webhook_auth: webhook_auth must be one of hmac, basic, header, none (got ${JSON.stringify(webhookAuth)}).` });
161
+ }
162
+ });
163
+ return errors;
164
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidactions/cli",
3
- "version": "3.25.0",
3
+ "version": "3.27.0",
4
4
  "description": "SolidActions CLI - Deploy and manage workflow automation",
5
5
  "main": "dist/index.js",
6
6
  "bin": {