@mondaydotcomorg/z2h-cli 0.25.3 → 0.25.7
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/auth.d.ts +2 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +2 -1
- package/dist/commands/__tests__/build.test.d.ts +2 -0
- package/dist/commands/__tests__/build.test.d.ts.map +1 -0
- package/dist/commands/backend.d.ts.map +1 -1
- package/dist/commands/backend.js +7 -1
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +10 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +42 -19
- package/dist/commands/grant.d.ts.map +1 -1
- package/dist/commands/grant.js +8 -7
- package/dist/esm/auth.d.ts +2 -1
- package/dist/esm/auth.d.ts.map +1 -1
- package/dist/esm/auth.mjs +2 -1
- package/dist/esm/commands/__tests__/build.test.d.ts +2 -0
- package/dist/esm/commands/__tests__/build.test.d.ts.map +1 -0
- package/dist/esm/commands/backend.d.ts.map +1 -1
- package/dist/esm/commands/backend.mjs +7 -1
- package/dist/esm/commands/build.d.ts.map +1 -1
- package/dist/esm/commands/build.mjs +10 -0
- package/dist/esm/commands/deploy.d.ts.map +1 -1
- package/dist/esm/commands/deploy.mjs +43 -20
- package/dist/esm/commands/grant.d.ts.map +1 -1
- package/dist/esm/commands/grant.mjs +8 -7
- package/dist/esm/index.mjs +41 -140
- package/dist/esm/types.d.ts +23 -0
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/util/__tests__/errors.test.d.ts +2 -0
- package/dist/esm/util/__tests__/errors.test.d.ts.map +1 -0
- package/dist/esm/util/__tests__/run-command.test.d.ts +2 -0
- package/dist/esm/util/__tests__/run-command.test.d.ts.map +1 -0
- package/dist/esm/util/auth/auth-store.d.ts +0 -4
- package/dist/esm/util/auth/auth-store.d.ts.map +1 -1
- package/dist/esm/util/auth/auth-store.mjs +2 -9
- package/dist/esm/util/auth/broker-credential-provider.d.ts.map +1 -1
- package/dist/esm/util/auth/broker-credential-provider.mjs +16 -16
- package/dist/esm/util/broker/app.d.ts.map +1 -1
- package/dist/esm/util/broker/app.mjs +17 -9
- package/dist/esm/util/errors.d.ts +48 -0
- package/dist/esm/util/errors.d.ts.map +1 -0
- package/dist/esm/util/errors.mjs +91 -0
- package/dist/esm/util/git/repo.d.ts +0 -3
- package/dist/esm/util/git/repo.d.ts.map +1 -1
- package/dist/esm/util/git/repo.mjs +4 -9
- package/dist/esm/util/logger.d.ts +4 -1
- package/dist/esm/util/logger.d.ts.map +1 -1
- package/dist/esm/util/logger.mjs +11 -3
- package/dist/esm/util/run-command.d.ts +16 -0
- package/dist/esm/util/run-command.d.ts.map +1 -0
- package/dist/esm/util/run-command.mjs +47 -0
- package/dist/esm/util/s3/upload.d.ts.map +1 -1
- package/dist/esm/util/s3/upload.mjs +22 -16
- package/dist/esm/util/tracker.d.ts +9 -2
- package/dist/esm/util/tracker.d.ts.map +1 -1
- package/dist/esm/util/tracker.mjs +18 -15
- package/dist/index.js +40 -139
- package/dist/types.d.ts +23 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/util/__tests__/errors.test.d.ts +2 -0
- package/dist/util/__tests__/errors.test.d.ts.map +1 -0
- package/dist/util/__tests__/run-command.test.d.ts +2 -0
- package/dist/util/__tests__/run-command.test.d.ts.map +1 -0
- package/dist/util/auth/auth-store.d.ts +0 -4
- package/dist/util/auth/auth-store.d.ts.map +1 -1
- package/dist/util/auth/auth-store.js +2 -10
- package/dist/util/auth/broker-credential-provider.d.ts.map +1 -1
- package/dist/util/auth/broker-credential-provider.js +16 -16
- package/dist/util/broker/app.d.ts.map +1 -1
- package/dist/util/broker/app.js +17 -9
- package/dist/util/errors.d.ts +48 -0
- package/dist/util/errors.d.ts.map +1 -0
- package/dist/util/errors.js +102 -0
- package/dist/util/git/repo.d.ts +0 -3
- package/dist/util/git/repo.d.ts.map +1 -1
- package/dist/util/git/repo.js +4 -10
- package/dist/util/logger.d.ts +4 -1
- package/dist/util/logger.d.ts.map +1 -1
- package/dist/util/logger.js +11 -3
- package/dist/util/run-command.d.ts +16 -0
- package/dist/util/run-command.d.ts.map +1 -0
- package/dist/util/run-command.js +49 -0
- package/dist/util/s3/upload.d.ts.map +1 -1
- package/dist/util/s3/upload.js +22 -16
- package/dist/util/tracker.d.ts +9 -2
- package/dist/util/tracker.d.ts.map +1 -1
- package/dist/util/tracker.js +19 -14
- package/handler-api/backend-runner/channels/llm-channel/llm.channel.ts +3 -2
- package/handler-api/backend-runner/channels/snowflake-channel/run-query.ts +7 -6
- package/handler-api/backend-runner/channels/snowflake-channel/snowflake.channel.ts +1 -1
- package/handler-api/backend-runner/channels/snowflake-channel/stateless-part-b.ts +1 -4
- package/package.json +2 -2
- package/src/auth.ts +2 -1
- package/src/commands/__tests__/backend-deploy.test.ts +18 -0
- package/src/commands/__tests__/build.test.ts +83 -0
- package/src/commands/__tests__/deploy.test.ts +107 -0
- package/src/commands/backend.ts +6 -1
- package/src/commands/build.ts +10 -0
- package/src/commands/deploy.ts +42 -20
- package/src/commands/grant.ts +8 -7
- package/src/index.ts +84 -133
- package/src/types.ts +47 -0
- package/src/util/__tests__/errors.test.ts +90 -0
- package/src/util/__tests__/run-command.test.ts +98 -0
- package/src/util/auth/__tests__/auth-store.test.ts +2 -1
- package/src/util/auth/__tests__/broker-credential-provider.test.ts +44 -8
- package/src/util/auth/auth-store.ts +1 -7
- package/src/util/auth/broker-credential-provider.ts +18 -16
- package/src/util/broker/__tests__/app.test.ts +23 -20
- package/src/util/broker/app.ts +16 -9
- package/src/util/errors.ts +98 -0
- package/src/util/git/__tests__/repo.test.ts +5 -3
- package/src/util/git/repo.ts +3 -9
- package/src/util/logger.ts +16 -3
- package/src/util/run-command.ts +59 -0
- package/src/util/s3/upload.ts +27 -22
- package/src/util/tracker.ts +19 -19
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const commands_edit = require('./commands/edit.js');
|
|
|
18
18
|
const commands_backend = require('./commands/backend.js');
|
|
19
19
|
const commands_doctor = require('./commands/doctor.js');
|
|
20
20
|
const util_logger = require('./util/logger.js');
|
|
21
|
+
const util_runCommand = require('./util/run-command.js');
|
|
21
22
|
const util_tracker = require('./util/tracker.js');
|
|
22
23
|
const util_appName = require('./util/app-name.js');
|
|
23
24
|
|
|
@@ -27,7 +28,7 @@ const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
|
27
28
|
const os__default = /*#__PURE__*/_interopDefault(os);
|
|
28
29
|
const path__default = /*#__PURE__*/_interopDefault(path);
|
|
29
30
|
|
|
30
|
-
const { version } = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)))('
|
|
31
|
+
const { version } = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)))('@mondaydotcomorg/z2h-cli/package.json');
|
|
31
32
|
const UPDATE_SCRIPT = path__default.default.join(os__default.default.homedir(), 'Development', 'bigbrain-z2h', 'z2h', 'setup', 'update.sh');
|
|
32
33
|
function selfUpdate() {
|
|
33
34
|
try {
|
|
@@ -50,6 +51,7 @@ function stripConflictingEnvVars() {
|
|
|
50
51
|
function collectTag(value, previous) {
|
|
51
52
|
return previous.concat(value);
|
|
52
53
|
}
|
|
54
|
+
const cwdApp = () => ({ app_name: util_appName.getCwdAppName() });
|
|
53
55
|
async function main() {
|
|
54
56
|
stripConflictingEnvVars();
|
|
55
57
|
const program = new commander.Command();
|
|
@@ -77,165 +79,86 @@ async function main() {
|
|
|
77
79
|
program
|
|
78
80
|
.command('build')
|
|
79
81
|
.description('Build the consumer into its .zth/ shadow and copy artifacts to ./build/')
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
await util_logger.fail(`build failed: ${err.message}`, { command: 'build' }, 2);
|
|
86
|
-
}
|
|
87
|
-
});
|
|
82
|
+
// A standalone build failure is the consumer's own code, not a CLI/infra problem — don't
|
|
83
|
+
// track it. buildCommand still tags the reason on its thrown error, since deploy's own
|
|
84
|
+
// (tracked) failure event benefits from knowing when a build broke it.
|
|
85
|
+
.action(util_runCommand.runCommand({ track: false, data: cwdApp, exitCode: 2 }, () => commands_build.buildCommand()));
|
|
88
86
|
program
|
|
89
87
|
.command('clean')
|
|
90
88
|
.description('Delete <consumer>/.zth/ and <consumer>/build/')
|
|
91
|
-
.action(
|
|
92
|
-
try {
|
|
93
|
-
await commands_clean.cleanCommand();
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
await util_logger.fail(`clean failed: ${err.message}`, { command: 'clean' }, 2);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
89
|
+
.action(util_runCommand.runCommand({ track: false, exitCode: 2 }, () => commands_clean.cleanCommand()));
|
|
99
90
|
program
|
|
100
91
|
.command('deploy')
|
|
101
92
|
.description('Build, upload to S3, and register the app with the Z2H backend')
|
|
102
93
|
.option('--dry-run', 'print what would happen without uploading anything')
|
|
103
94
|
.option('--preview', 'build an ephemeral, shareable preview instead of deploying — no git required, no deploy lock, never touches the live version; reuses the same preview URL across runs (stable link)')
|
|
104
95
|
.option('--open', 'open the resulting app/preview URL in the browser on success')
|
|
105
|
-
.option('--remote <type>', 'First deploy only: source control remote to initialise — s3 (shared storage) or github (your repo). Error if the app already has a git remote.')
|
|
96
|
+
.option('--remote <type>', 'First deploy only: source control remote to initialise — s3 (shared storage, recommended, auto-backed-up) or github (manage it yourself in your own repo). Error if the app already has a git remote.')
|
|
106
97
|
.option('--repo-url <url>', 'First deploy only: GitHub repo URL — required when --remote=github. Error if the app already has a git remote.')
|
|
107
98
|
.option('--description <text>', 'short (<=200 char) description of the app')
|
|
108
|
-
.action(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
await util_logger.fail(`${label} failed: ${err.message}`, { command: label }, 2);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
99
|
+
.action(util_runCommand.runCommand({
|
|
100
|
+
// A preview is a real deploy for observability, tracked as its own event since
|
|
101
|
+
// the command name alone (`deploy`) can't distinguish it from a live deploy.
|
|
102
|
+
event: ([opts]) => util_tracker.successEvent(opts.preview ? 'preview' : 'deploy'),
|
|
103
|
+
label: ([opts]) => (opts.preview ? 'preview' : 'deploy'),
|
|
104
|
+
data: cwdApp,
|
|
105
|
+
exitCode: 2,
|
|
106
|
+
}, (opts) => commands_deploy.deployCommand(opts)));
|
|
119
107
|
program
|
|
120
108
|
.command('tag [app-name]')
|
|
121
109
|
.description("Set an app's category tags — app type & team (interactive unless --tag or --json is given)")
|
|
122
110
|
.option('--tag <tag>', 'set a tag (repeatable); full-replaces the tag set non-interactively', collectTag, [])
|
|
123
|
-
.action(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
app_name: appName ?? util_appName.getCwdAppName(),
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
catch (err) {
|
|
130
|
-
await util_logger.fail(`tag failed: ${err.message}`, { command: 'tag' }, 1);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
111
|
+
.action(util_runCommand.runCommand({
|
|
112
|
+
data: ([appName]) => ({ app_name: appName ?? util_appName.getCwdAppName() }),
|
|
113
|
+
}, (appName, opts) => commands_tag.tagCommand(appName, opts)));
|
|
133
114
|
program
|
|
134
115
|
.command('create-workspace')
|
|
135
116
|
.description(`Bootstrap the ${util_workspace.getWorkspaceHome()}/ yarn workspace (one-time setup)`)
|
|
136
|
-
.action(
|
|
137
|
-
try {
|
|
138
|
-
await commands_createWorkspace.createWorkspaceCommand();
|
|
139
|
-
}
|
|
140
|
-
catch (err) {
|
|
141
|
-
await util_logger.fail(`create-workspace failed: ${err.message}`, { command: 'create-workspace' }, 1);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
117
|
+
.action(util_runCommand.runCommand({ track: false }, () => commands_createWorkspace.createWorkspaceCommand()));
|
|
144
118
|
program
|
|
145
119
|
.command('generate-z2h-token')
|
|
146
120
|
.description('Open the bigbrain.me token page, capture the token via a loopback callback, and persist it to ~/.zth/auth.json')
|
|
147
121
|
.option('--no-browser', "don't auto-open the browser; print the URL and prompt for manual paste")
|
|
148
122
|
.option('--url <url>', 'Override the token page URL (e.g. for staging)')
|
|
149
|
-
.action(
|
|
150
|
-
try {
|
|
151
|
-
await commands_generateZ2hToken.generateZ2HTokenCommand(opts);
|
|
152
|
-
}
|
|
153
|
-
catch (err) {
|
|
154
|
-
await util_logger.fail(`generate-z2h-token failed: ${err.message}`, { command: 'generate-z2h-token' }, 1);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
123
|
+
.action(util_runCommand.runCommand({}, (opts) => commands_generateZ2hToken.generateZ2HTokenCommand(opts)));
|
|
157
124
|
program
|
|
158
125
|
.command('create <app-name>')
|
|
159
126
|
.description(`Scaffold a new Z2H consumer app inside ${util_workspace.getWorkspaceHome()}/`)
|
|
160
127
|
.option('--template <name>', 'Template name (default | html-embed)')
|
|
161
128
|
.option('--html-file <path>', 'Path to an HTML file to embed (implies --template html-embed)')
|
|
162
|
-
.option('--remote <type>', 'Source control remote: s3 (shared storage) or github (your repo)')
|
|
129
|
+
.option('--remote <type>', 'Source control remote: s3 (shared storage, recommended, auto-backed-up) or github (manage it yourself in your own repo)')
|
|
163
130
|
.option('--repo-url <url>', 'GitHub repo URL — required when --remote=github')
|
|
164
|
-
.action(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
catch (err) {
|
|
173
|
-
await util_logger.fail(`create failed: ${err.message}`, { command: 'create' }, 1);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
131
|
+
.action(util_runCommand.runCommand({
|
|
132
|
+
data: ([appName, opts]) => ({
|
|
133
|
+
app_name: appName,
|
|
134
|
+
template: opts.template ?? 'default',
|
|
135
|
+
remote: opts.remote ?? 'unknown',
|
|
136
|
+
}),
|
|
137
|
+
}, (appName, opts) => commands_create.createCommand(appName, opts)));
|
|
176
138
|
program
|
|
177
139
|
.command('edit <app-name>')
|
|
178
140
|
.description(`Pull the latest version of an app into ${util_workspace.getWorkspaceHome()}/<app-name>, cloning it first if needed`)
|
|
179
|
-
.action(
|
|
180
|
-
try {
|
|
181
|
-
await util_tracker.trackDuration('z2h_app_edit_pulled', () => commands_edit.editCommand(appName), {
|
|
182
|
-
app_name: appName,
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
catch (err) {
|
|
186
|
-
await util_logger.fail(`edit failed: ${err.message}`, { command: 'edit' }, 1);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
141
|
+
.action(util_runCommand.runCommand({ data: ([appName]) => ({ app_name: appName }) }, (appName) => commands_edit.editCommand(appName)));
|
|
189
142
|
program
|
|
190
143
|
.command('grant [email]')
|
|
191
144
|
.description('Grant access to the current app (email, --public, or both)')
|
|
192
145
|
.option('--public', 'make the app visible to all monday.com employees')
|
|
193
146
|
.option('--level <level>', 'access level for user grants: owner, editor, or viewer (default: viewer)')
|
|
194
|
-
.action(
|
|
195
|
-
try {
|
|
196
|
-
await commands_grant.grantCommand(email, opts);
|
|
197
|
-
}
|
|
198
|
-
catch (err) {
|
|
199
|
-
await util_logger.fail(`grant failed: ${err.message}`, { command: 'grant' }, 1);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
147
|
+
.action(util_runCommand.runCommand({}, (email, opts) => commands_grant.grantCommand(email, opts)));
|
|
202
148
|
program
|
|
203
149
|
.command('revoke [email]')
|
|
204
150
|
.description('Revoke access to the current app (email or --public; owners/admins only)')
|
|
205
151
|
.option('--public', 'remove the public grant, making the app visible to owners/admins only')
|
|
206
|
-
.action(
|
|
207
|
-
try {
|
|
208
|
-
await commands_grant.revokeCommand(email, opts);
|
|
209
|
-
}
|
|
210
|
-
catch (err) {
|
|
211
|
-
await util_logger.fail(`revoke failed: ${err.message}`, { command: 'revoke' }, 1);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
152
|
+
.action(util_runCommand.runCommand({}, (email, opts) => commands_grant.revokeCommand(email, opts)));
|
|
214
153
|
program
|
|
215
154
|
.command('transfer-owner [email]')
|
|
216
155
|
.description('Transfer ownership of the current app to another monday.com user')
|
|
217
|
-
.action(
|
|
218
|
-
try {
|
|
219
|
-
await commands_grant.transferOwnerCommand(email);
|
|
220
|
-
}
|
|
221
|
-
catch (err) {
|
|
222
|
-
await util_logger.fail(`transfer-owner failed: ${err.message}`, { command: 'transfer-owner' }, 1);
|
|
223
|
-
}
|
|
224
|
-
});
|
|
156
|
+
.action(util_runCommand.runCommand({}, (email) => commands_grant.transferOwnerCommand(email)));
|
|
225
157
|
program
|
|
226
158
|
.command('delete')
|
|
227
159
|
.description('Permanently delete the current app and take it offline (owners/admins only)')
|
|
228
160
|
.option('--yes', 'skip the confirmation prompt (required for --json / non-interactive)')
|
|
229
|
-
.action(
|
|
230
|
-
try {
|
|
231
|
-
await util_tracker.trackDuration('z2h_app_delete_success', () => commands_delete.deleteCommand(opts), {
|
|
232
|
-
app_name: util_appName.getCwdAppName(),
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
catch (err) {
|
|
236
|
-
await util_logger.fail(`delete failed: ${err.message}`, { command: 'delete' }, 1);
|
|
237
|
-
}
|
|
238
|
-
});
|
|
161
|
+
.action(util_runCommand.runCommand({ data: cwdApp }, (opts) => commands_delete.deleteCommand(opts)));
|
|
239
162
|
const backend = program
|
|
240
163
|
.command('backend')
|
|
241
164
|
.description("Inspect the app's backend: invoke a deployed handler by name");
|
|
@@ -243,40 +166,18 @@ async function main() {
|
|
|
243
166
|
.command('invoke <handlerName>')
|
|
244
167
|
.description('Invoke a deployed backend handler by name (the filename without .ts) — mainly for testing a handler without going through the frontend')
|
|
245
168
|
.option('--input <json>', 'JSON payload passed as ctx.input')
|
|
246
|
-
.action(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
app_name: util_appName.getCwdAppName(),
|
|
250
|
-
handler: handlerName,
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
catch (err) {
|
|
254
|
-
await util_logger.fail(`backend invoke failed: ${err.message}`, { command: 'backend invoke' }, 1);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
169
|
+
.action(util_runCommand.runCommand({
|
|
170
|
+
data: ([handlerName]) => ({ app_name: util_appName.getCwdAppName(), handler: handlerName }),
|
|
171
|
+
}, (handlerName, opts) => commands_backend.backendInvokeCommand(handlerName, opts)));
|
|
257
172
|
program
|
|
258
173
|
.command('migrate')
|
|
259
174
|
.description('Run pending workspace migrations')
|
|
260
175
|
.option('--dry-run', 'show pending migrations without applying any changes')
|
|
261
|
-
.action(
|
|
262
|
-
try {
|
|
263
|
-
await commands_migrate.migrateCommand(version, opts);
|
|
264
|
-
}
|
|
265
|
-
catch (err) {
|
|
266
|
-
await util_logger.fail(`migrate failed: ${err.message}`, { command: 'migrate' }, 1);
|
|
267
|
-
}
|
|
268
|
-
});
|
|
176
|
+
.action(util_runCommand.runCommand({}, (opts) => commands_migrate.migrateCommand(version, opts)));
|
|
269
177
|
program
|
|
270
178
|
.command('doctor')
|
|
271
179
|
.description('Check that all Z2H tools, auth, workspace, and plugins are correctly set up')
|
|
272
|
-
.action(
|
|
273
|
-
try {
|
|
274
|
-
await commands_doctor.doctorCommand();
|
|
275
|
-
}
|
|
276
|
-
catch (err) {
|
|
277
|
-
await util_logger.fail(`doctor failed: ${err.message}`, { command: 'doctor' }, 1);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
180
|
+
.action(util_runCommand.runCommand({ track: false }, () => commands_doctor.doctorCommand()));
|
|
280
181
|
await program.parseAsync(process.argv);
|
|
281
182
|
}
|
|
282
183
|
void main()
|
package/dist/types.d.ts
CHANGED
|
@@ -50,4 +50,27 @@ export interface PreparedShadow {
|
|
|
50
50
|
port: number;
|
|
51
51
|
paths: ConsumerPaths;
|
|
52
52
|
}
|
|
53
|
+
export type DeployFailureReason = 'read_auth_token' | 'broker_auth' | 'broker_error' | 'lock_timeout' | 'build_error' | 'git_error' | 's3_error' | 'deploy_backend_error' | 'register_error' | 'push_error' | 'interrupted' | 'unknown';
|
|
54
|
+
export type GrantFailureReason = 'validation' | 'auth' | 'forbidden' | 'not_found' | 'server_error' | 'unknown';
|
|
55
|
+
/**
|
|
56
|
+
* A spec value that is either a constant or a function of the command's own arguments.
|
|
57
|
+
* Callbacks take the args as one tuple rather than a spread, so a callback that reads only
|
|
58
|
+
* the first arg still typechecks. Destructure what you need.
|
|
59
|
+
*/
|
|
60
|
+
export type PerArgs<A extends unknown[], T> = T | ((args: A) => T);
|
|
61
|
+
export interface CommandSpec<A extends unknown[]> {
|
|
62
|
+
/**
|
|
63
|
+
* Opt out of telemetry entirely — both the success event and the error event. Default `true`.
|
|
64
|
+
* Set `false` for a purely local command with no product-usage signal worth a round-trip.
|
|
65
|
+
*/
|
|
66
|
+
track?: PerArgs<A, boolean>;
|
|
67
|
+
/** Success-event name when it depends on args (e.g. `deploy --preview`); defaults to `successEvent(<command>)`. */
|
|
68
|
+
event?: PerArgs<A, string>;
|
|
69
|
+
/** Prefix in the error message and the `action` dimension. Defaults to the command's own name. */
|
|
70
|
+
label?: PerArgs<A, string>;
|
|
71
|
+
/** Extra dimensions sent with both the success and the error event. */
|
|
72
|
+
data?: (args: A) => Record<string, unknown>;
|
|
73
|
+
/** Overrides the failing error's own exitCode. */
|
|
74
|
+
exitCode?: number;
|
|
75
|
+
}
|
|
53
76
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GA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AAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAC5B,mHAAmH;IACnH,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC3B,kGAAkG;IAClG,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC3B,uEAAuE;IACvE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../../../src/util/__tests__/errors.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-command.test.d.ts","sourceRoot":"","sources":["../../../src/util/__tests__/run-command.test.ts"],"names":[],"mappings":""}
|
|
@@ -3,10 +3,6 @@ export declare const Z2H_AUTH_FILE: string;
|
|
|
3
3
|
export interface ZthAuth {
|
|
4
4
|
token: string;
|
|
5
5
|
}
|
|
6
|
-
export declare class Z2hAuthMissingError extends Error {
|
|
7
|
-
readonly authFilePath: string;
|
|
8
|
-
constructor(authFilePath: string);
|
|
9
|
-
}
|
|
10
6
|
export declare function readZthAuth(): Promise<ZthAuth>;
|
|
11
7
|
/**
|
|
12
8
|
* Synchronous, never-throws read of the z2h JWT from `~/.zth/auth.json`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-store.d.ts","sourceRoot":"","sources":["../../../src/util/auth/auth-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth-store.d.ts","sourceRoot":"","sources":["../../../src/util/auth/auth-store.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,YAAY,QAAkC,CAAC;AAC5D,eAAO,MAAM,aAAa,QAAuC,CAAC;AAElE,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC,CAkBpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,IAAI,CAUpD"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const path = require('node:path');
|
|
4
4
|
const os = require('node:os');
|
|
5
5
|
const fs = require('fs-extra');
|
|
6
|
+
const util_errors = require('../errors.js');
|
|
6
7
|
|
|
7
8
|
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
8
9
|
|
|
@@ -14,14 +15,6 @@ const os__default = /*#__PURE__*/_interopDefault(os);
|
|
|
14
15
|
// stage it.
|
|
15
16
|
const Z2H_AUTH_DIR = path__default.default.join(os__default.default.homedir(), '.zth');
|
|
16
17
|
const Z2H_AUTH_FILE = path__default.default.join(Z2H_AUTH_DIR, 'auth.json');
|
|
17
|
-
class Z2hAuthMissingError extends Error {
|
|
18
|
-
authFilePath;
|
|
19
|
-
constructor(authFilePath) {
|
|
20
|
-
super(`No Z2H deploy token found at ${authFilePath}. Please run 'z2h-cli generate-z2h-token' command.`);
|
|
21
|
-
this.authFilePath = authFilePath;
|
|
22
|
-
this.name = 'Z2hAuthMissingError';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
18
|
async function readZthAuth() {
|
|
26
19
|
if (process.env.Z2H_AUTH_TOKEN) {
|
|
27
20
|
const token = process.env.Z2H_AUTH_TOKEN;
|
|
@@ -31,7 +24,7 @@ async function readZthAuth() {
|
|
|
31
24
|
return { token };
|
|
32
25
|
}
|
|
33
26
|
if (!(await fs.pathExists(Z2H_AUTH_FILE))) {
|
|
34
|
-
throw new Z2hAuthMissingError(Z2H_AUTH_FILE);
|
|
27
|
+
throw new util_errors.Z2hAuthMissingError(Z2H_AUTH_FILE);
|
|
35
28
|
}
|
|
36
29
|
const parsed = (await fs.readJson(Z2H_AUTH_FILE));
|
|
37
30
|
if (!parsed.token) {
|
|
@@ -63,6 +56,5 @@ function tryReadAuthTokenSync() {
|
|
|
63
56
|
|
|
64
57
|
exports.Z2H_AUTH_DIR = Z2H_AUTH_DIR;
|
|
65
58
|
exports.Z2H_AUTH_FILE = Z2H_AUTH_FILE;
|
|
66
|
-
exports.Z2hAuthMissingError = Z2hAuthMissingError;
|
|
67
59
|
exports.readZthAuth = readZthAuth;
|
|
68
60
|
exports.tryReadAuthTokenSync = tryReadAuthTokenSync;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broker-credential-provider.d.ts","sourceRoot":"","sources":["../../../src/util/auth/broker-credential-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"broker-credential-provider.d.ts","sourceRoot":"","sources":["../../../src/util/auth/broker-credential-provider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAyB,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAE3F,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAC1D,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AA0D3D;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMzE;AAwDD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,OAAO,EACP,SAAS,GACV,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,6BAA6B,CAIhC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const constants = require('../../constants.js');
|
|
4
|
+
const util_errors = require('../errors.js');
|
|
4
5
|
const util_auth_authStore = require('./auth-store.js');
|
|
5
6
|
|
|
6
7
|
const STS_BROKER_PATH = '/z2h-cli/sts/credentials';
|
|
@@ -23,16 +24,23 @@ async function postToBroker(path, body) {
|
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
catch (err) {
|
|
26
|
-
|
|
27
|
-
throw new Error(`Z2H deploy broker request failed: ${message}`);
|
|
27
|
+
throw new util_errors.DeployError('broker_error', `Z2H deploy broker request failed: ${util_errors.messageOf(err)}`);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Classifies a broker response: 401/403 are `broker_auth` (the user can fix them), any
|
|
32
|
+
* other non-ok status is `broker_error` (the broker or the network, not the user).
|
|
33
|
+
*/
|
|
34
|
+
async function assertBrokerOk(res, errorLabel) {
|
|
31
35
|
if (res.status === 401) {
|
|
32
|
-
throw new
|
|
36
|
+
throw new util_errors.DeployError('broker_auth', `Z2H deploy token rejected by the broker (401). Refresh user token by running 'z2h-cli generate-z2h-token'.`);
|
|
33
37
|
}
|
|
34
38
|
if (res.status === 403) {
|
|
35
|
-
throw new
|
|
39
|
+
throw new util_errors.DeployError('broker_auth', `Access denied (403). You do not have editor access to this app. Ask the app owner to grant you access via 'z2h-cli grant'.`);
|
|
40
|
+
}
|
|
41
|
+
if (!res.ok) {
|
|
42
|
+
const text = await res.text();
|
|
43
|
+
throw new util_errors.DeployError('broker_error', `Z2H ${errorLabel} broker returned ${res.status}: ${text.slice(0, 1024)}`);
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
46
|
/**
|
|
@@ -42,27 +50,19 @@ function assertBrokerOk(res) {
|
|
|
42
50
|
*/
|
|
43
51
|
async function fetchDeployVersion(appName) {
|
|
44
52
|
const res = await postToBroker(DEPLOY_VERSION_PATH, { appName });
|
|
45
|
-
assertBrokerOk(res);
|
|
46
|
-
if (!res.ok) {
|
|
47
|
-
const text = await res.text();
|
|
48
|
-
throw new Error(`Z2H deploy broker returned ${res.status}: ${text.slice(0, 1024)}`);
|
|
49
|
-
}
|
|
53
|
+
await assertBrokerOk(res, 'deploy');
|
|
50
54
|
const body = (await res.json());
|
|
51
55
|
return body.version ?? 0;
|
|
52
56
|
}
|
|
53
57
|
async function requestSts(path, body, errorLabel) {
|
|
54
58
|
const res = await postToBroker(path, body);
|
|
55
|
-
assertBrokerOk(res);
|
|
56
|
-
if (!res.ok) {
|
|
57
|
-
const text = await res.text();
|
|
58
|
-
throw new Error(`Z2H ${errorLabel} broker returned ${res.status}: ${text.slice(0, 1024)}`);
|
|
59
|
-
}
|
|
59
|
+
await assertBrokerOk(res, errorLabel);
|
|
60
60
|
const responseBody = (await res.json());
|
|
61
61
|
if (!responseBody.accessKeyId ||
|
|
62
62
|
!responseBody.secretAccessKey ||
|
|
63
63
|
!responseBody.sessionToken ||
|
|
64
64
|
!responseBody.expiration) {
|
|
65
|
-
throw new
|
|
65
|
+
throw new util_errors.DeployError('broker_error', `Z2H ${errorLabel} broker response missing required credential fields`);
|
|
66
66
|
}
|
|
67
67
|
return {
|
|
68
68
|
accessKeyId: responseBody.accessKeyId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/util/broker/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/util/broker/app.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAsBvE;AA4CD,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBtF"}
|
package/dist/util/broker/app.js
CHANGED
|
@@ -4,6 +4,7 @@ const constants = require('../../constants.js');
|
|
|
4
4
|
const util_auth_authStore = require('../auth/auth-store.js');
|
|
5
5
|
const util_logger = require('../logger.js');
|
|
6
6
|
const util_promptVisibility = require('../prompt-visibility.js');
|
|
7
|
+
const util_errors = require('../errors.js');
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Fetches a single app's current state from the broker.
|
|
@@ -38,7 +39,7 @@ async function registerApp(appName, token, version, entry, visibility, gitRemote
|
|
|
38
39
|
});
|
|
39
40
|
if (!res.ok) {
|
|
40
41
|
const text = await res.text();
|
|
41
|
-
throw new
|
|
42
|
+
throw new util_errors.DeployError('register_error', `App registration failed (${res.status}): ${text.slice(0, 1024)}`);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
/** Releases a new version onto an app that already exists. */
|
|
@@ -50,7 +51,7 @@ async function updateApp(appName, token, version, entry, gitRemote, integrations
|
|
|
50
51
|
});
|
|
51
52
|
if (!res.ok) {
|
|
52
53
|
const text = await res.text();
|
|
53
|
-
throw new
|
|
54
|
+
throw new util_errors.DeployError('register_error', `App update failed (${res.status}): ${text.slice(0, 1024)}`);
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
@@ -61,14 +62,21 @@ async function updateApp(appName, token, version, entry, gitRemote, integrations
|
|
|
61
62
|
*/
|
|
62
63
|
async function registerOrUpdateApp(opts) {
|
|
63
64
|
const { appName, token, nextVersion, entry, gitRemote, integrations, description } = opts;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
try {
|
|
66
|
+
if (nextVersion === 1) {
|
|
67
|
+
const visibility = await util_promptVisibility.resolveAppVisibility(appName);
|
|
68
|
+
util_logger.info(`registering "${appName}" → v${nextVersion} (${visibility})`);
|
|
69
|
+
await registerApp(appName, token, nextVersion, entry, visibility, gitRemote, integrations, description);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
util_logger.info(`updating "${appName}" → v${nextVersion}`);
|
|
73
|
+
await updateApp(appName, token, nextVersion, entry, gitRemote, integrations, description);
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
catch (err) {
|
|
77
|
+
// registerApp/updateApp already tag the non-ok-response case; this catches anything
|
|
78
|
+
// else (a network throw, a resolveAppVisibility failure) under the same reason.
|
|
79
|
+
throw util_errors.tagDeployError('register_error', err);
|
|
72
80
|
}
|
|
73
81
|
}
|
|
74
82
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DeployFailureReason, GrantFailureReason } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Base for every error the CLI classifies. runCommand in ./run-command.ts reads `reason`
|
|
4
|
+
* and `data` straight off the error, so the throw site is the only place that needs to know
|
|
5
|
+
* why it failed. Nothing re-derives it from the error type at the top level.
|
|
6
|
+
*
|
|
7
|
+
* `exitCode` lets a throw site override the CLI's --help contract, 1 for user-resolvable
|
|
8
|
+
* and 2 for system failures, per error instead of per command. Nothing sets it yet. The
|
|
9
|
+
* command table still pins exit codes, which keeps today's behavior.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Z2hError extends Error {
|
|
12
|
+
readonly reason: string;
|
|
13
|
+
readonly data?: Record<string, unknown> | undefined;
|
|
14
|
+
readonly exitCode: number;
|
|
15
|
+
constructor(message: string, reason: string, data?: Record<string, unknown> | undefined, exitCode?: number);
|
|
16
|
+
}
|
|
17
|
+
/** Tags a deploy/preview stage failure with a bounded reason code instead of a freeform message. */
|
|
18
|
+
export declare class DeployError extends Z2hError {
|
|
19
|
+
readonly reason: DeployFailureReason;
|
|
20
|
+
constructor(reason: DeployFailureReason, message: string, data?: Record<string, unknown>);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Tags a grant/revoke/transfer-owner failure with a bounded reason code instead of a freeform message.
|
|
24
|
+
* `reason` also accepts a raw HTTP status, which gets mapped to a bounded reason internally.
|
|
25
|
+
*/
|
|
26
|
+
export declare class GrantError extends Z2hError {
|
|
27
|
+
constructor(reason: GrantFailureReason | number, message: string, data?: Record<string, unknown>);
|
|
28
|
+
}
|
|
29
|
+
/** No z2h JWT found — see auth-store.ts for the discovery order (env var, then ~/.zth/auth.json). */
|
|
30
|
+
export declare class Z2hAuthMissingError extends Z2hError {
|
|
31
|
+
readonly authFilePath: string;
|
|
32
|
+
constructor(authFilePath: string);
|
|
33
|
+
}
|
|
34
|
+
/** A git pull diverged or a push was rejected; `reason` distinguishes which stage hit it. */
|
|
35
|
+
export declare class GitConflictError extends Z2hError {
|
|
36
|
+
constructor(message: string, reason?: DeployFailureReason);
|
|
37
|
+
}
|
|
38
|
+
/** Maps an HTTP status to a bounded grant/revoke/transfer-owner failure reason. */
|
|
39
|
+
export declare function grantReasonForStatus(status: number): GrantFailureReason;
|
|
40
|
+
/** Tags a failure with `reason`, unless `err` is already classified; `signal` overrides `reason` for a killed child process. */
|
|
41
|
+
export declare function tagDeployError(reason: DeployFailureReason, err: unknown): Z2hError;
|
|
42
|
+
/** Reads the bounded reason off a classified error; anything unclassified is `unknown`. */
|
|
43
|
+
export declare function reasonOf(err: unknown): string;
|
|
44
|
+
/** Extra telemetry dimensions the throw site attached, if any. */
|
|
45
|
+
export declare function dataOf(err: unknown): Record<string, unknown>;
|
|
46
|
+
/** Safe message for any thrown value. A non-Error throw must not break the error path. */
|
|
47
|
+
export declare function messageOf(err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