@workover/cli 0.26.0 → 0.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/bin/workover.mjs +2312 -5
- package/contacts.mjs +1561 -0
- package/domains.mjs +417 -0
- package/email-studio.mjs +829 -0
- package/feedback-board.mjs +321 -0
- package/journeys.mjs +409 -0
- package/lib.mjs +56 -0
- package/package.json +20 -1
- package/support-agent-tests.mjs +424 -0
- package/support-config.mjs +302 -0
- package/support-email.mjs +458 -0
- package/support-fields.mjs +294 -0
- package/support-freshdesk.mjs +176 -0
- package/support-inbox.mjs +313 -0
- package/support-label-rules.mjs +136 -0
- package/support-labels.mjs +244 -0
- package/support-outcomes.mjs +276 -0
- package/support-outside-bot.mjs +145 -0
- package/support-setup.mjs +660 -0
- package/support-signatures.mjs +156 -0
- package/support-sources.mjs +233 -0
- package/support-walter.mjs +310 -0
package/bin/workover.mjs
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// The Workover CLI. `login` / `logout` / `whoami` authenticate through the device-authorization
|
|
3
3
|
// flow (RFC 8628); everything else works on documents with the stored token: `projects`, `doc`
|
|
4
|
-
// (list/read/create/propose/write/search/tabs/images/image/status), `rules`, `comments`, `draft`,
|
|
4
|
+
// (list/read/create/propose/write/search/tabs/images/image/status), `media` (list/replace), `rules`, `comments`, `draft`,
|
|
5
|
+
// `draft-set`, `eval`,
|
|
5
6
|
// and on hosted Help Centers: `project create` and `site` (create/import/domain/check/publish/status),
|
|
6
|
-
// which need `login --site
|
|
7
|
+
// which need `login --site`; and Support setup: `support` (status/setup/step/install/secret/test/thread/config),
|
|
8
|
+
// which needs `login --support`; and `contacts`, `domains` and `email` (blocks/render/preview of
|
|
9
|
+
// emails designed in blocks), which need `login --contacts`.
|
|
7
10
|
//
|
|
8
11
|
// This header used to say "auth only for now", left over from the first version and never updated
|
|
9
12
|
// as the commands landed. On 2026-09-09 an agent read it, concluded the CLI could not edit
|
|
@@ -20,7 +23,7 @@ import {
|
|
|
20
23
|
statSync,
|
|
21
24
|
} from 'fs';
|
|
22
25
|
import { homedir } from 'os';
|
|
23
|
-
import { dirname, join } from 'path';
|
|
26
|
+
import { basename, dirname, join } from 'path';
|
|
24
27
|
import { spawn } from 'child_process';
|
|
25
28
|
import { fileURLToPath } from 'url';
|
|
26
29
|
import {
|
|
@@ -39,6 +42,8 @@ import {
|
|
|
39
42
|
docRef,
|
|
40
43
|
environmentMismatch,
|
|
41
44
|
imagesInHtml,
|
|
45
|
+
mediaListQuery,
|
|
46
|
+
formatMediaList,
|
|
42
47
|
signInHelp,
|
|
43
48
|
jsonObjectFlag,
|
|
44
49
|
vetImageUpload,
|
|
@@ -90,7 +95,247 @@ import {
|
|
|
90
95
|
renderUnpublish,
|
|
91
96
|
} from '../site-setup.mjs';
|
|
92
97
|
import { writeRecipe } from '../site-proxy.mjs';
|
|
98
|
+
import {
|
|
99
|
+
SUPPORT_LOGIN,
|
|
100
|
+
FRAMEWORKS,
|
|
101
|
+
detectFramework,
|
|
102
|
+
parseHours,
|
|
103
|
+
renderInstall,
|
|
104
|
+
renderSupportSetup,
|
|
105
|
+
renderSupportStatus,
|
|
106
|
+
renderSupportNotifications,
|
|
107
|
+
renderSupportTest,
|
|
108
|
+
parseSwitches,
|
|
109
|
+
reportStep,
|
|
110
|
+
sendTest,
|
|
111
|
+
supportNotifications,
|
|
112
|
+
supportScopeHelp,
|
|
113
|
+
supportSetup,
|
|
114
|
+
supportStatus,
|
|
115
|
+
HOME_SLOTS,
|
|
116
|
+
imageTypeFor,
|
|
117
|
+
renderSupportHome,
|
|
118
|
+
supportHome,
|
|
119
|
+
supportHomeImage,
|
|
120
|
+
supportThread,
|
|
121
|
+
renderSupportThread,
|
|
122
|
+
writeIdentitySecret,
|
|
123
|
+
} from '../support-setup.mjs';
|
|
124
|
+
import {
|
|
125
|
+
addPdf,
|
|
126
|
+
addSource,
|
|
127
|
+
listSources,
|
|
128
|
+
removeSource,
|
|
129
|
+
renderSourceAdded,
|
|
130
|
+
renderSourceLine,
|
|
131
|
+
renderSourceRemoved,
|
|
132
|
+
renderSources,
|
|
133
|
+
syncSource,
|
|
134
|
+
updateSource,
|
|
135
|
+
} from '../support-sources.mjs';
|
|
136
|
+
import {
|
|
137
|
+
configDiscard,
|
|
138
|
+
configGet,
|
|
139
|
+
configPublish,
|
|
140
|
+
configSet,
|
|
141
|
+
renderConfig,
|
|
142
|
+
renderStyleImport,
|
|
143
|
+
styleImport,
|
|
144
|
+
} from '../support-config.mjs';
|
|
145
|
+
import {
|
|
146
|
+
renderChangelog as renderWalterChangelog,
|
|
147
|
+
renderPreview as renderWalterPreview,
|
|
148
|
+
renderWalter,
|
|
149
|
+
walterChangelog,
|
|
150
|
+
walterDiscard,
|
|
151
|
+
walterGet,
|
|
152
|
+
walterPreview,
|
|
153
|
+
walterPublish,
|
|
154
|
+
walterSet,
|
|
155
|
+
} from '../support-walter.mjs';
|
|
156
|
+
import {
|
|
157
|
+
addTests,
|
|
158
|
+
generateTests,
|
|
159
|
+
getRun,
|
|
160
|
+
listReleases,
|
|
161
|
+
listTests,
|
|
162
|
+
rateResult,
|
|
163
|
+
removeTest,
|
|
164
|
+
renderAdded,
|
|
165
|
+
renderRated,
|
|
166
|
+
renderReleases,
|
|
167
|
+
renderRemoved,
|
|
168
|
+
renderRollback,
|
|
169
|
+
renderRun,
|
|
170
|
+
renderRunStarted,
|
|
171
|
+
renderSetLive,
|
|
172
|
+
renderTests,
|
|
173
|
+
rollback,
|
|
174
|
+
runTests,
|
|
175
|
+
setLive,
|
|
176
|
+
} from '../support-agent-tests.mjs';
|
|
177
|
+
import {
|
|
178
|
+
createLabel,
|
|
179
|
+
listLabels,
|
|
180
|
+
mergeLabels,
|
|
181
|
+
renderLabelMerged,
|
|
182
|
+
renderLabelSaved,
|
|
183
|
+
renderLabels,
|
|
184
|
+
updateLabel,
|
|
185
|
+
} from '../support-labels.mjs';
|
|
186
|
+
import {
|
|
187
|
+
createPost as createFeedbackPost,
|
|
188
|
+
getPost as getFeedbackPost,
|
|
189
|
+
listPosts as listFeedbackPosts,
|
|
190
|
+
renderPost as renderFeedbackPost,
|
|
191
|
+
renderPosts as renderFeedbackPosts,
|
|
192
|
+
renderPreview as renderFeedbackPreview,
|
|
193
|
+
setStatus as setFeedbackStatus,
|
|
194
|
+
votePost as voteFeedbackPost,
|
|
195
|
+
} from '../feedback-board.mjs';
|
|
196
|
+
import {
|
|
197
|
+
contactEvents,
|
|
198
|
+
contactsFromFile,
|
|
199
|
+
contactsScopeHelp,
|
|
200
|
+
eventsFromFile,
|
|
201
|
+
listEventNames,
|
|
202
|
+
renderContactEvents,
|
|
203
|
+
renderEventNameSaved,
|
|
204
|
+
renderEventNames,
|
|
205
|
+
renderTracked,
|
|
206
|
+
trackEvents,
|
|
207
|
+
updateEventName,
|
|
208
|
+
createKey as createContactsKey,
|
|
209
|
+
defineAttribute as defineContactAttribute,
|
|
210
|
+
getContact,
|
|
211
|
+
identifyContacts,
|
|
212
|
+
listAttributes as listContactAttributes,
|
|
213
|
+
listContacts,
|
|
214
|
+
listKeys as listContactsKeys,
|
|
215
|
+
renderAttributeSaved as renderContactAttributeSaved,
|
|
216
|
+
renderAttributes as renderContactAttributes,
|
|
217
|
+
renderContact,
|
|
218
|
+
renderContacts,
|
|
219
|
+
renderIdentified as renderContactsIdentified,
|
|
220
|
+
renderKeyCreated as renderContactsKeyCreated,
|
|
221
|
+
renderKeyRevoked as renderContactsKeyRevoked,
|
|
222
|
+
renderKeys as renderContactsKeys,
|
|
223
|
+
revokeKey as revokeContactsKey,
|
|
224
|
+
updateAttribute as updateContactAttribute,
|
|
225
|
+
changeSegmentMembers,
|
|
226
|
+
createSegment,
|
|
227
|
+
definitionFromFile,
|
|
228
|
+
exportContacts,
|
|
229
|
+
getSegment,
|
|
230
|
+
listSegments,
|
|
231
|
+
previewSegment,
|
|
232
|
+
renderExported,
|
|
233
|
+
renderSegment,
|
|
234
|
+
renderSegmentMembers,
|
|
235
|
+
renderSegmentMembersChanged,
|
|
236
|
+
renderSegmentPreview,
|
|
237
|
+
renderSegmentSaved,
|
|
238
|
+
renderSegments,
|
|
239
|
+
segmentMembers,
|
|
240
|
+
updateSegment,
|
|
241
|
+
contactConsent,
|
|
242
|
+
createTopic,
|
|
243
|
+
getSubscriptions,
|
|
244
|
+
listTopics,
|
|
245
|
+
preferencesLink,
|
|
246
|
+
renderConsent,
|
|
247
|
+
renderLinksReset,
|
|
248
|
+
renderPreferencesLink,
|
|
249
|
+
renderSubscriptions,
|
|
250
|
+
renderTopicSaved,
|
|
251
|
+
renderTopics,
|
|
252
|
+
reorderTopics,
|
|
253
|
+
resetPreferenceLinks,
|
|
254
|
+
setSubscriptions,
|
|
255
|
+
topicChoices,
|
|
256
|
+
updateTopic,
|
|
257
|
+
} from '../contacts.mjs';
|
|
258
|
+
// One namespace: several names (renderDomain, renderRemoved) are the Help Center's here too.
|
|
259
|
+
import * as sending from '../domains.mjs';
|
|
260
|
+
import * as studio from '../email-studio.mjs';
|
|
261
|
+
import * as journeys from '../journeys.mjs';
|
|
262
|
+
import {
|
|
263
|
+
conversationFields,
|
|
264
|
+
listFields,
|
|
265
|
+
orderFields,
|
|
266
|
+
removeField,
|
|
267
|
+
renderConversationFields,
|
|
268
|
+
renderFieldRemoved,
|
|
269
|
+
renderFieldSaved,
|
|
270
|
+
renderFields,
|
|
271
|
+
setConversationFields,
|
|
272
|
+
setField,
|
|
273
|
+
} from '../support-fields.mjs';
|
|
274
|
+
import {
|
|
275
|
+
renderAssignment,
|
|
276
|
+
renderAvailability,
|
|
277
|
+
renderSla,
|
|
278
|
+
supportAssignment,
|
|
279
|
+
supportAvailability,
|
|
280
|
+
supportSla,
|
|
281
|
+
} from '../support-inbox.mjs';
|
|
282
|
+
import {
|
|
283
|
+
listLabelRules,
|
|
284
|
+
removeLabelRule,
|
|
285
|
+
renderLabelRuleRemoved,
|
|
286
|
+
renderLabelRules,
|
|
287
|
+
renderLabelRuleSet,
|
|
288
|
+
setLabelRule,
|
|
289
|
+
} from '../support-label-rules.mjs';
|
|
290
|
+
import {
|
|
291
|
+
checkOutsideBot,
|
|
292
|
+
getOutsideBot,
|
|
293
|
+
renderOutsideBot,
|
|
294
|
+
renderOutsideBotCheck,
|
|
295
|
+
setOutsideBot,
|
|
296
|
+
} from '../support-outside-bot.mjs';
|
|
297
|
+
import {
|
|
298
|
+
clearOutcome,
|
|
299
|
+
getOutcomeUsage,
|
|
300
|
+
listOutcomes,
|
|
301
|
+
markOutcome,
|
|
302
|
+
outcomesCsv,
|
|
303
|
+
renderOutcomeMark,
|
|
304
|
+
renderOutcomes,
|
|
305
|
+
renderOutcomeUsage,
|
|
306
|
+
} from '../support-outcomes.mjs';
|
|
307
|
+
import {
|
|
308
|
+
checkFreshdesk,
|
|
309
|
+
getFreshdesk,
|
|
310
|
+
removeFreshdesk,
|
|
311
|
+
renderFreshdesk,
|
|
312
|
+
renderFreshdeskCheck,
|
|
313
|
+
renderFreshdeskRemoved,
|
|
314
|
+
setFreshdesk,
|
|
315
|
+
} from '../support-freshdesk.mjs';
|
|
93
316
|
import { renderFeedbackResult, submitFeedback } from '../feedback.mjs';
|
|
317
|
+
import {
|
|
318
|
+
getSignatures,
|
|
319
|
+
previewSignature,
|
|
320
|
+
renderSignaturePreview,
|
|
321
|
+
renderSignatures,
|
|
322
|
+
renderSignatureSaved,
|
|
323
|
+
setSignature,
|
|
324
|
+
} from '../support-signatures.mjs';
|
|
325
|
+
import {
|
|
326
|
+
doNotEmail,
|
|
327
|
+
domainAction,
|
|
328
|
+
listDomains,
|
|
329
|
+
renderDoNotEmail,
|
|
330
|
+
renderDomainAction,
|
|
331
|
+
renderDomains,
|
|
332
|
+
renderEmail,
|
|
333
|
+
renderEmailSaved,
|
|
334
|
+
renderTestEmail,
|
|
335
|
+
sendTestEmail,
|
|
336
|
+
setEmail,
|
|
337
|
+
setNewEmailsDefault,
|
|
338
|
+
} from '../support-email.mjs';
|
|
94
339
|
import {
|
|
95
340
|
addApiReference,
|
|
96
341
|
addRedirects,
|
|
@@ -223,6 +468,8 @@ async function login() {
|
|
|
223
468
|
if (process.argv.includes('--write')) scopes.push('write');
|
|
224
469
|
if (process.argv.includes('--rules')) scopes.push('rules');
|
|
225
470
|
if (process.argv.includes('--site')) scopes.push('site');
|
|
471
|
+
if (process.argv.includes('--support')) scopes.push('support');
|
|
472
|
+
if (process.argv.includes('--contacts')) scopes.push('contacts');
|
|
226
473
|
// `--no-wait --json` prints the JSON and nothing else, so an agent can parse what it gets.
|
|
227
474
|
const jsonOnly = process.argv.includes('--no-wait') && process.argv.includes('--json');
|
|
228
475
|
|
|
@@ -2084,7 +2331,8 @@ async function status() {
|
|
|
2084
2331
|
* or throws an Error with the HTTP status and the api's own sentence, so each command can say what
|
|
2085
2332
|
* to do next instead of exiting from deep inside a helper.
|
|
2086
2333
|
*/
|
|
2087
|
-
|
|
2334
|
+
/** `raw: true` resolves the body as text (a CSV export) rather than parsing it as JSON. */
|
|
2335
|
+
const siteCall = (cfg) => async (path, { method, body, raw } = {}) => {
|
|
2088
2336
|
let res;
|
|
2089
2337
|
try {
|
|
2090
2338
|
res = await fetch(`${cfg.api}${path}`, {
|
|
@@ -2111,7 +2359,7 @@ const siteCall = (cfg) => async (path, { method, body } = {}) => {
|
|
|
2111
2359
|
if (res.status === 401) throw apiError(401, 'This sign-in no longer works. Run `workover login --site` again.');
|
|
2112
2360
|
throw apiError(res.status, typeof m === 'string' && m ? m : text.slice(0, 300) || `HTTP ${res.status}`);
|
|
2113
2361
|
}
|
|
2114
|
-
return parsed;
|
|
2362
|
+
return raw ? text : parsed;
|
|
2115
2363
|
};
|
|
2116
2364
|
|
|
2117
2365
|
/** Print a refusal the way an agent can act on it, and exit. */
|
|
@@ -2143,6 +2391,67 @@ const PROJECT_USAGE = [
|
|
|
2143
2391
|
'',
|
|
2144
2392
|
].join('\n');
|
|
2145
2393
|
|
|
2394
|
+
const MEDIA_USAGE = [
|
|
2395
|
+
'',
|
|
2396
|
+
' Usage: workover media <command>',
|
|
2397
|
+
'',
|
|
2398
|
+
' list <project> [--filter <f>] [--source workover|wordpress]',
|
|
2399
|
+
' [--search "<q>"] [--cursor <n>] [--json]',
|
|
2400
|
+
' the project\u2019s Media library: every image its documents use',
|
|
2401
|
+
' and every WordPress attachment, with usage, alt text and',
|
|
2402
|
+
' problems. <f> is all, in_use, unused, attention, missing_alt,',
|
|
2403
|
+
' oversized, broken, stale or deleted',
|
|
2404
|
+
' replace <project> <assetId> <replacementAssetId> [--json]',
|
|
2405
|
+
' raise ONE reviewed fix that swaps the image for the other in',
|
|
2406
|
+
' every document using it; accepting it in Health is what',
|
|
2407
|
+
' changes them. Needs `login --write`',
|
|
2408
|
+
'',
|
|
2409
|
+
' Asset ids are the #numbers `media list` prints; project ids come from',
|
|
2410
|
+
' `workover projects`.',
|
|
2411
|
+
'',
|
|
2412
|
+
].join('\n');
|
|
2413
|
+
|
|
2414
|
+
/** `workover media`: the project Media library (WO-1811), as workover_list_media and _replace_media. */
|
|
2415
|
+
async function mediaCommand() {
|
|
2416
|
+
const sub = process.argv[3];
|
|
2417
|
+
if (sub !== 'list' && sub !== 'replace') {
|
|
2418
|
+
console.log(MEDIA_USAGE);
|
|
2419
|
+
process.exit(sub ? 1 : 0);
|
|
2420
|
+
}
|
|
2421
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json'] });
|
|
2422
|
+
const projectId = rowId(positionals[0] ?? '');
|
|
2423
|
+
if (projectId === null) {
|
|
2424
|
+
console.log(MEDIA_USAGE);
|
|
2425
|
+
process.exit(1);
|
|
2426
|
+
}
|
|
2427
|
+
const cfg = requireSignIn();
|
|
2428
|
+
if (sub === 'list') {
|
|
2429
|
+
const res = await authedCall(cfg, `/project/${projectId}/media?${mediaListQuery(flags)}`);
|
|
2430
|
+
if (flags.json === true) return console.log(JSON.stringify(res, null, 2));
|
|
2431
|
+
const out = formatMediaList(projectId, res);
|
|
2432
|
+
return console.log(`\n${out.replace(/^(?=.)/gm, ' ')}\n`);
|
|
2433
|
+
}
|
|
2434
|
+
const assetId = rowId(positionals[1] ?? '');
|
|
2435
|
+
const replacementAssetId = rowId(positionals[2] ?? '');
|
|
2436
|
+
if (assetId === null || replacementAssetId === null || assetId === replacementAssetId) {
|
|
2437
|
+
console.error(
|
|
2438
|
+
'\n Name the image to replace and a different one to put in its place: ' +
|
|
2439
|
+
'workover media replace <project> <assetId> <replacementAssetId>\n',
|
|
2440
|
+
);
|
|
2441
|
+
process.exit(1);
|
|
2442
|
+
}
|
|
2443
|
+
const res = await authedCall(cfg, `/project/${projectId}/media/${assetId}/replace`, {
|
|
2444
|
+
replacementAssetId,
|
|
2445
|
+
});
|
|
2446
|
+
if (flags.json === true) return console.log(JSON.stringify(res, null, 2));
|
|
2447
|
+
console.log(
|
|
2448
|
+
`\n Raised a fix to replace #${assetId} with #${replacementAssetId} in every document that uses it` +
|
|
2449
|
+
`${res?.suggestionId ? ` (fix #${res.suggestionId})` : ''}.\n` +
|
|
2450
|
+
' Nothing has changed yet: accepting it in the project’s Health page rewrites the documents. The old image\n' +
|
|
2451
|
+
' stays in the library.\n',
|
|
2452
|
+
);
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2146
2455
|
async function projectCommand() {
|
|
2147
2456
|
const sub = process.argv[3];
|
|
2148
2457
|
if (sub !== 'create') {
|
|
@@ -2477,6 +2786,1979 @@ const cliVersion = () => {
|
|
|
2477
2786
|
}
|
|
2478
2787
|
};
|
|
2479
2788
|
|
|
2789
|
+
// ------------------------------------------------------------------ requests (Feedback's posts)
|
|
2790
|
+
|
|
2791
|
+
const REQUESTS_USAGE = [
|
|
2792
|
+
'',
|
|
2793
|
+
' Usage: workover requests [list] [--board <id|name>] [--status <status>] [--sort top|new|weighted|trending]',
|
|
2794
|
+
' [--q "<words>"] [--offset N]',
|
|
2795
|
+
' workover requests get <post>',
|
|
2796
|
+
' workover requests add "<title>" [--board <id|name>] [--body "<details>"]',
|
|
2797
|
+
' workover requests vote <post> [--remove]',
|
|
2798
|
+
' workover requests status <post> <under_review|planned|in_progress|shipped>',
|
|
2799
|
+
' [--preview] [--no-notify] [--note "<under the update>"]',
|
|
2800
|
+
' Every command takes [--workspace <slug|id>] [--json].',
|
|
2801
|
+
'',
|
|
2802
|
+
' The workspace\'s Feedback board of feature requests. Moving a post to Planned, In progress or',
|
|
2803
|
+
' Shipped tells its voters (customers by Messenger and email, teammates in the app), once per',
|
|
2804
|
+
' status; --preview shows who would be told and the words without moving it.',
|
|
2805
|
+
'',
|
|
2806
|
+
].join('\n');
|
|
2807
|
+
|
|
2808
|
+
/** `workover requests ...`: Feedback's posts (feedback-board.mjs, WO-1752 round 3). */
|
|
2809
|
+
async function requestsCommand() {
|
|
2810
|
+
const { flags, positionals } = parseArgs(process.argv.slice(3), {
|
|
2811
|
+
booleans: ['json', 'remove', 'preview', 'no-notify'],
|
|
2812
|
+
});
|
|
2813
|
+
const action = positionals[0] || 'list';
|
|
2814
|
+
if (!['list', 'get', 'add', 'vote', 'status'].includes(action)) {
|
|
2815
|
+
console.log(REQUESTS_USAGE);
|
|
2816
|
+
process.exit(1);
|
|
2817
|
+
}
|
|
2818
|
+
const cfg = requireSignIn();
|
|
2819
|
+
const call = siteCall(cfg);
|
|
2820
|
+
const json = flags.json === true;
|
|
2821
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
2822
|
+
const str = (v) => (typeof v === 'string' ? v : undefined);
|
|
2823
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
2824
|
+
try {
|
|
2825
|
+
if (action === 'list') {
|
|
2826
|
+
const res = await listFeedbackPosts(call, {
|
|
2827
|
+
workspace,
|
|
2828
|
+
board: str(flags.board),
|
|
2829
|
+
status: str(flags.status),
|
|
2830
|
+
sort: str(flags.sort),
|
|
2831
|
+
q: str(flags.q),
|
|
2832
|
+
offset: flags.offset === undefined ? undefined : Number(flags.offset),
|
|
2833
|
+
});
|
|
2834
|
+
return out(res, renderFeedbackPosts(res));
|
|
2835
|
+
}
|
|
2836
|
+
if (action === 'get') {
|
|
2837
|
+
const res = await getFeedbackPost(call, { workspace, post: positionals[1] });
|
|
2838
|
+
return out(res, renderFeedbackPost(res.post));
|
|
2839
|
+
}
|
|
2840
|
+
if (action === 'add') {
|
|
2841
|
+
const res = await createFeedbackPost(call, {
|
|
2842
|
+
workspace,
|
|
2843
|
+
board: str(flags.board),
|
|
2844
|
+
title: positionals[1],
|
|
2845
|
+
body: str(flags.body),
|
|
2846
|
+
});
|
|
2847
|
+
return out(res, ['', ` ✓ Posted #${res.post.id}: ${res.post.title}`, '']);
|
|
2848
|
+
}
|
|
2849
|
+
if (action === 'vote') {
|
|
2850
|
+
const res = await voteFeedbackPost(call, { workspace, post: positionals[1], remove: flags.remove === true });
|
|
2851
|
+
return out(res, ['', ` ✓ ${flags.remove === true ? 'Vote taken back' : 'Voted'}. It has ${res.voteCount} vote${res.voteCount === 1 ? '' : 's'}.`, '']);
|
|
2852
|
+
}
|
|
2853
|
+
const res = await setFeedbackStatus(call, {
|
|
2854
|
+
workspace,
|
|
2855
|
+
post: positionals[1],
|
|
2856
|
+
status: positionals[2],
|
|
2857
|
+
notify: flags['no-notify'] !== true,
|
|
2858
|
+
note: str(flags.note),
|
|
2859
|
+
preview: flags.preview === true,
|
|
2860
|
+
});
|
|
2861
|
+
if (res.preview) return out(res, renderFeedbackPreview(res.preview));
|
|
2862
|
+
return out(res, ['', ` ✓ #${res.post.id} moved.${flags['no-notify'] === true ? ' Nobody was told.' : ' Its voters are being told.'}`, '']);
|
|
2863
|
+
} catch (e) {
|
|
2864
|
+
if (e.status === 401) e.message = 'This sign-in no longer works. Run `workover login` again.';
|
|
2865
|
+
siteFail(e);
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
const CONTACTS_USAGE = [
|
|
2870
|
+
'',
|
|
2871
|
+
' Usage: workover contacts [list] [--q "<name, email or external id>"] [--segment <id | name>] [--offset N] [--limit N]',
|
|
2872
|
+
' workover contacts get <id | email | x:<external id> | c:<id>>',
|
|
2873
|
+
' workover contacts identify --file people.csv|people.json',
|
|
2874
|
+
' workover contacts identify --email ada@example.com [--external-id u_1] [--name "Ada"]',
|
|
2875
|
+
' [--attr plan=pro --attr seats=12 ...] [--anonymous-id a_1]',
|
|
2876
|
+
' workover contacts attrs [list]',
|
|
2877
|
+
' workover contacts attrs add <key> <string|number|boolean|date> [--label "<label>"]',
|
|
2878
|
+
' workover contacts attrs rename <key> "<label>"',
|
|
2879
|
+
' workover contacts attrs archive|restore <key>',
|
|
2880
|
+
' workover contacts keys [list]',
|
|
2881
|
+
' workover contacts keys create --name "Production server"',
|
|
2882
|
+
' workover contacts keys revoke <id | wsk_prefix | name>',
|
|
2883
|
+
' workover contacts track --file events.csv|events.json',
|
|
2884
|
+
' workover contacts track <name> --external-id u_1 | --email ada@example.com | --anonymous-id a_1',
|
|
2885
|
+
' [--prop total=30 --prop plan=pro ...] [--timestamp <ISO>] [--id <event id>]',
|
|
2886
|
+
' workover contacts events <id | email | x:<external id>> [--name <event>] [--offset N] [--limit N]',
|
|
2887
|
+
' workover contacts event-names [list]',
|
|
2888
|
+
' workover contacts event-names rename <name> "<label>"',
|
|
2889
|
+
' workover contacts event-names archive|restore <name>',
|
|
2890
|
+
' workover contacts segments [list] [--archived]',
|
|
2891
|
+
' workover contacts segments show <id | name>',
|
|
2892
|
+
' workover contacts segments preview --file def.json [--segment <id | name>]',
|
|
2893
|
+
' workover contacts segments create --name "Pro users" --file def.json | --manual',
|
|
2894
|
+
' workover contacts segments update <id | name> [--name "<new name>"] [--file def.json]',
|
|
2895
|
+
' workover contacts segments archive|restore <id | name>',
|
|
2896
|
+
' workover contacts segments members <id | name> [--offset N] [--limit N]',
|
|
2897
|
+
' workover contacts segments add|remove <id | name> <id | email | x:<external id>> ...',
|
|
2898
|
+
' workover contacts segments export <id | name> [--out file.csv]',
|
|
2899
|
+
' workover contacts export [--segment <id | name>] [--out file.csv]',
|
|
2900
|
+
' workover contacts topics [list]',
|
|
2901
|
+
' workover contacts topics create <key> --name "Newsletter" --default opt_in|opt_out [--description "..."]',
|
|
2902
|
+
' workover contacts topics update <key> [--name "<name>"] [--description "..."] [--default opt_in|opt_out]',
|
|
2903
|
+
' workover contacts topics archive|restore <key>',
|
|
2904
|
+
' workover contacts topics reorder <key> <key> ...',
|
|
2905
|
+
' workover contacts topics reset-links',
|
|
2906
|
+
' workover contacts subscriptions <id | email | x:<external id>> [--set newsletter=on --set promo=off ...]',
|
|
2907
|
+
' [--unsubscribe-all | --resubscribe-all]',
|
|
2908
|
+
' workover contacts consent <id | email | x:<external id>> [--offset N] [--limit N]',
|
|
2909
|
+
' workover contacts preferences-link <id | email | x:<external id>> [--topic <key>]',
|
|
2910
|
+
' workover contacts journeys [list] [--archived]',
|
|
2911
|
+
' workover contacts journeys show <id | name>',
|
|
2912
|
+
' workover contacts journeys create --file journey.json',
|
|
2913
|
+
' workover contacts journeys update <id | name> [--name "<new name>"] [--file changes.json]',
|
|
2914
|
+
' workover contacts journeys publish <id | name> [--everyone-now] [--yes]',
|
|
2915
|
+
' workover contacts journeys pause|resume|archive <id | name>',
|
|
2916
|
+
' workover contacts journeys test <id | name> [--step N] [--contact <id | email | x:<external id>>]',
|
|
2917
|
+
' workover contacts journeys report <id | name>',
|
|
2918
|
+
' workover contacts journeys runs <id | name> [--status waiting|...] [--offset N] [--limit N]',
|
|
2919
|
+
' Every command takes [--workspace <slug|id>] [--json]. Needs `workover login --contacts`.',
|
|
2920
|
+
'',
|
|
2921
|
+
' Contacts are the people your workspace keeps, by external id (your own user id) and email, with',
|
|
2922
|
+
' typed attributes. Identifying is safe to repeat; a new attribute key is defined by its first value.',
|
|
2923
|
+
' A CSV has a header row: external_id, email, name, then one column per attribute. A file of more',
|
|
2924
|
+
' than 100 is sent in batches of 100. Writes, attributes and keys are for owners and admins.',
|
|
2925
|
+
' Your servers identify contacts with a key: POST /v1/contacts/identify, Authorization: Bearer wsk_...',
|
|
2926
|
+
'',
|
|
2927
|
+
' Events are what a person did (order.completed). One for someone not yet a contact is kept',
|
|
2928
|
+
' anonymous for 30 days and attached when they are identified (identify takes --anonymous-id too).',
|
|
2929
|
+
' A CSV of events has a header row: name, external_id, email, anonymous_id, timestamp, id, then one',
|
|
2930
|
+
' column per property. An id makes sending the same event twice record it once. Servers send to',
|
|
2931
|
+
' POST /v1/events with the same key.',
|
|
2932
|
+
'',
|
|
2933
|
+
' Segments group contacts. A dynamic one is a definition in JSON that Workover keeps current:',
|
|
2934
|
+
' {"match": "all", "filters": [{"type": "attribute", "key": "plan", "op": "is", "value": "pro"},',
|
|
2935
|
+
' {"type": "event", "name": "logged_in", "op": "did", "withinDays": 7}]}. Preview it first: the',
|
|
2936
|
+
' count is what the segment will hold. A manual one (--manual) is a list you add people to. A',
|
|
2937
|
+
' definition file may also hold "name". Exports are CSV for owners and admins; without --out the',
|
|
2938
|
+
' CSV is printed. Servers read segments at GET /v1/segments and change manual ones, but keys do',
|
|
2939
|
+
' not create segments.',
|
|
2940
|
+
'',
|
|
2941
|
+
' Topics are what you email people about. opt_in topics reach only people who said yes; opt_out',
|
|
2942
|
+
' topics reach everyone until they say no. A person can unsubscribe from one topic or from all on',
|
|
2943
|
+
' their own preference page, and every change is kept in an append-only consent log. A',
|
|
2944
|
+
' preference link is that person\u2019s credential: send it only to them. reset-links makes every',
|
|
2945
|
+
' link already sent stop working. Servers read GET /v1/topics and set subscriptions with PUT',
|
|
2946
|
+
' /v1/contacts/<ref>/subscriptions or identify\u2019s "subscriptions"; an opt-in through the API',
|
|
2947
|
+
' needs "consent". Nothing here sends email.',
|
|
2948
|
+
'',
|
|
2949
|
+
' Journeys move people through waits and emails after a trigger: entering a segment, an event,',
|
|
2950
|
+
' or an attribute change. A journey file is JSON (see `show --json` of one for the shape). A',
|
|
2951
|
+
' draft does nothing. publish without --yes prints the impact only; with --yes it goes live, for',
|
|
2952
|
+
' people who meet the trigger from now on, or with --everyone-now for those who match now too.',
|
|
2953
|
+
' A live journey changes only its name until it is paused. test sends one email step to you,',
|
|
2954
|
+
' marked [Test]. Nothing sends until SES is live; locally email is captured to files.',
|
|
2955
|
+
'',
|
|
2956
|
+
].join('\n');
|
|
2957
|
+
|
|
2958
|
+
/** `--attr k=v` flags as attributes; a value reading as a number or true/false is sent as one. */
|
|
2959
|
+
function attrFlags(argv, flag = '--attr') {
|
|
2960
|
+
const out = {};
|
|
2961
|
+
for (let i = 0; i < argv.length; i++) {
|
|
2962
|
+
const a = argv[i];
|
|
2963
|
+
const raw = a === flag ? argv[++i] : a.startsWith(`${flag}=`) ? a.slice(flag.length + 1) : null;
|
|
2964
|
+
if (raw === null || raw === undefined) continue;
|
|
2965
|
+
const at = raw.indexOf('=');
|
|
2966
|
+
if (at < 1) throw Object.assign(new Error(`${flag} takes key=value, not "${raw}".`), { status: 400 });
|
|
2967
|
+
const k = raw.slice(0, at).trim();
|
|
2968
|
+
const v = raw.slice(at + 1);
|
|
2969
|
+
out[k] =
|
|
2970
|
+
v === '' ? null : /^(true|false)$/i.test(v) ? v.toLowerCase() === 'true' : /^-?\d+(\.\d+)?$/.test(v) && !/^-?0\d/.test(v) ? Number(v) : v;
|
|
2971
|
+
}
|
|
2972
|
+
return out;
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
/** `workover contacts ...`: stored contacts, attributes and server keys (contacts.mjs, WO-1752). */
|
|
2976
|
+
const DOMAINS_USAGE = `
|
|
2977
|
+
workover domains: the domains your workspace sends email from (needs \`workover login --contacts\`)
|
|
2978
|
+
|
|
2979
|
+
workover domains [list]
|
|
2980
|
+
workover domains add <domain> [--mail-from <sub>|--no-mail-from] [--dkim branded|easy]
|
|
2981
|
+
prints every DNS record to add, each already looked up once
|
|
2982
|
+
workover domains show <domain> status, each record and what the last check found
|
|
2983
|
+
workover domains check <domain> look every record up now (Workover also checks by itself
|
|
2984
|
+
every 15 minutes for 72 hours, then hourly, up to 7 days)
|
|
2985
|
+
workover domains records <domain> [--format bind|json|text]
|
|
2986
|
+
the records to import at a DNS host or send to whoever runs it
|
|
2987
|
+
workover domains share <domain> [--reset]
|
|
2988
|
+
a read-only records page for a DNS admin without an account
|
|
2989
|
+
workover domains remove <domain>
|
|
2990
|
+
|
|
2991
|
+
workover domains addresses [list]
|
|
2992
|
+
workover domains addresses add <email> --name "Acme" [--reply-to <email>] [--default]
|
|
2993
|
+
workover domains addresses update <email> [--name "..."] [--reply-to <email>]
|
|
2994
|
+
workover domains addresses default <email>
|
|
2995
|
+
workover domains addresses remove <email>
|
|
2996
|
+
|
|
2997
|
+
--workspace <slug|id> when the account has more than one · --json for the raw answer
|
|
2998
|
+
`;
|
|
2999
|
+
|
|
3000
|
+
async function domainsCommand() {
|
|
3001
|
+
const { flags, positionals } = parseArgs(process.argv.slice(3), {
|
|
3002
|
+
booleans: ['json', 'reset', 'default', 'no-mail-from'],
|
|
3003
|
+
});
|
|
3004
|
+
const group = positionals[0] === 'addresses' ? 'addresses' : null;
|
|
3005
|
+
const action = group ? positionals[1] || 'list' : positionals[0] || 'list';
|
|
3006
|
+
const target = group ? positionals[2] : positionals[1];
|
|
3007
|
+
const known = {
|
|
3008
|
+
addresses: ['list', 'add', 'update', 'default', 'remove'],
|
|
3009
|
+
null: ['list', 'add', 'show', 'get', 'check', 'records', 'share', 'remove'],
|
|
3010
|
+
};
|
|
3011
|
+
if (!known[group].includes(action) || (action !== 'list' && !target)) {
|
|
3012
|
+
console.log(DOMAINS_USAGE);
|
|
3013
|
+
process.exit(1);
|
|
3014
|
+
}
|
|
3015
|
+
const format = typeof flags.format === 'string' ? flags.format : 'text';
|
|
3016
|
+
if (action === 'records' && !sending.RECORD_FORMATS.includes(format)) {
|
|
3017
|
+
console.log(DOMAINS_USAGE);
|
|
3018
|
+
process.exit(1);
|
|
3019
|
+
}
|
|
3020
|
+
const cfg = requireSignIn();
|
|
3021
|
+
const call = siteCall(cfg);
|
|
3022
|
+
const json = flags.json === true;
|
|
3023
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
3024
|
+
const str = (v) => (typeof v === 'string' ? v : undefined);
|
|
3025
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
3026
|
+
try {
|
|
3027
|
+
if (group === 'addresses') {
|
|
3028
|
+
if (action === 'list') {
|
|
3029
|
+
const res = await sending.listAddresses(call, { workspace });
|
|
3030
|
+
return out(res, sending.renderAddresses(res));
|
|
3031
|
+
}
|
|
3032
|
+
if (action === 'add') {
|
|
3033
|
+
const res = await sending.addAddress(call, {
|
|
3034
|
+
workspace,
|
|
3035
|
+
email: target,
|
|
3036
|
+
name: str(flags.name),
|
|
3037
|
+
replyTo: str(flags['reply-to']),
|
|
3038
|
+
isDefault: flags.default === true,
|
|
3039
|
+
});
|
|
3040
|
+
return out(res, sending.renderAddressSaved(res));
|
|
3041
|
+
}
|
|
3042
|
+
if (action === 'update') {
|
|
3043
|
+
const res = await sending.updateAddress(call, {
|
|
3044
|
+
workspace,
|
|
3045
|
+
email: target,
|
|
3046
|
+
name: str(flags.name),
|
|
3047
|
+
replyTo: str(flags['reply-to']),
|
|
3048
|
+
});
|
|
3049
|
+
return out(res, sending.renderAddressSaved(res));
|
|
3050
|
+
}
|
|
3051
|
+
const res =
|
|
3052
|
+
action === 'default'
|
|
3053
|
+
? await sending.defaultAddress(call, { workspace, email: target })
|
|
3054
|
+
: await sending.removeAddress(call, { workspace, email: target });
|
|
3055
|
+
return out(res, sending.renderAddresses(res));
|
|
3056
|
+
}
|
|
3057
|
+
if (action === 'list') {
|
|
3058
|
+
const res = await sending.listDomains(call, { workspace });
|
|
3059
|
+
return out(res, sending.renderDomains(res));
|
|
3060
|
+
}
|
|
3061
|
+
if (action === 'add') {
|
|
3062
|
+
const mailFrom = flags['no-mail-from'] === true ? false : str(flags['mail-from']);
|
|
3063
|
+
const res = await sending.addDomain(call, { workspace, domain: target, mailFrom, dkim: str(flags.dkim) });
|
|
3064
|
+
return out(res, sending.renderDomain(res.domain, { created: res.created }));
|
|
3065
|
+
}
|
|
3066
|
+
if (action === 'show' || action === 'get') {
|
|
3067
|
+
const res = await sending.getDomain(call, { workspace, domain: target });
|
|
3068
|
+
return out(res, sending.renderDomain(res.domain));
|
|
3069
|
+
}
|
|
3070
|
+
if (action === 'check') {
|
|
3071
|
+
const res = await sending.checkDomain(call, { workspace, domain: target });
|
|
3072
|
+
return out(res, sending.renderDomain(res.domain));
|
|
3073
|
+
}
|
|
3074
|
+
if (action === 'records') {
|
|
3075
|
+
const res = await sending.domainRecords(call, { workspace, domain: target, format });
|
|
3076
|
+
// The records alone, so `> zone.txt` or a pipe gets exactly them.
|
|
3077
|
+
return console.log(json || format === 'json' ? JSON.stringify(res.records ?? res, null, 2) : res.text);
|
|
3078
|
+
}
|
|
3079
|
+
if (action === 'share') {
|
|
3080
|
+
const res = await sending.shareDomain(call, { workspace, domain: target, reset: flags.reset === true });
|
|
3081
|
+
return out(res, sending.renderShared(res));
|
|
3082
|
+
}
|
|
3083
|
+
const res = await sending.removeDomain(call, { workspace, domain: target });
|
|
3084
|
+
return out(res, sending.renderRemoved(res));
|
|
3085
|
+
} catch (e) {
|
|
3086
|
+
siteFail(e);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
|
|
3090
|
+
const EMAIL_USAGE = `
|
|
3091
|
+
workover email: emails designed in blocks (needs \`workover login --contacts\`)
|
|
3092
|
+
|
|
3093
|
+
workover email blocks [<type>] every block, or one with its properties and an example
|
|
3094
|
+
(--json: the catalog with the JSON Schema of a whole email)
|
|
3095
|
+
workover email render --file email.json [--out email.html]
|
|
3096
|
+
compile to the HTML and text stored for sending, Liquid intact
|
|
3097
|
+
workover email preview --file email.json [--subject "..."] [--preheader "..."]
|
|
3098
|
+
[--contact <id | email | x:<external id>>] [--data data.json]
|
|
3099
|
+
[--out email.html]
|
|
3100
|
+
[--images-blocked]
|
|
3101
|
+
fill it for one person (the sample contact by default); a
|
|
3102
|
+
merge tag nothing fills is refused with its JSON pointer
|
|
3103
|
+
workover email check --file email.json [--subject "..."] [--contact ...] [--data data.json]
|
|
3104
|
+
is it ready to send: each QA check, and a readiness score
|
|
3105
|
+
workover email test --file email.json [--subject "..."] [--contact ...] [--from <address id>]
|
|
3106
|
+
send it to yourself, filled for a contact (owners and admins)
|
|
3107
|
+
|
|
3108
|
+
workover email import --source email.ds-source.html [--global-styles styles.json]
|
|
3109
|
+
[--node node.json] [--name "..."] [--customerio-template <id>]
|
|
3110
|
+
[--dry-run] [--no-link]
|
|
3111
|
+
workover email import --body email.html [--layout layout.html] [--layout-name "..."]
|
|
3112
|
+
[--text body_plain.txt] [--customerio-layout <id>] [--name "..."]
|
|
3113
|
+
bring a Customer.io email across as a NEW draft; the report
|
|
3114
|
+
lists what did not map one to one (nothing is dropped)
|
|
3115
|
+
workover email templates [<id>] [--out email.json]
|
|
3116
|
+
the workspace's emails, or one (--out writes its draft)
|
|
3117
|
+
workover email new --name "..." [--file email.json]
|
|
3118
|
+
workover email save <id> --file email.json [--revision <n>]
|
|
3119
|
+
save the draft (the revision read comes from the file)
|
|
3120
|
+
workover email publish <id> [--revision <n>] [--note "..."] [--ignore-checks]
|
|
3121
|
+
publish the draft as the next version once its check passes
|
|
3122
|
+
workover email layouts [<id>] [--out layout.html]
|
|
3123
|
+
the workspace's layouts, or one with what uses it
|
|
3124
|
+
workover email layout new --name "..." --file layout.html
|
|
3125
|
+
workover email layout save <id> --file layout.html --revision <n> [--name "..."]
|
|
3126
|
+
workover email layout delete <id> a layout nothing uses
|
|
3127
|
+
workover email versions <id> · workover email restore <id> <version>
|
|
3128
|
+
the published versions; copy one back into the draft
|
|
3129
|
+
workover email brand-kit [--out kit.json]
|
|
3130
|
+
workover email brand-kit --file kit.json [--kit-version <n>] [--dry-run]
|
|
3131
|
+
the brand kit every email is drawn with: read it, or save the
|
|
3132
|
+
whole kit (a removed token is frozen into the emails using it)
|
|
3133
|
+
|
|
3134
|
+
The file holds {"version": 1, "blocks": [...]} or {"subject", "preheader", "blocks": {...}}.
|
|
3135
|
+
A journey's email step takes the same document as "blocks" in place of "body".
|
|
3136
|
+
--workspace <slug|id> when the account has more than one · --json for the raw answer
|
|
3137
|
+
`;
|
|
3138
|
+
|
|
3139
|
+
async function emailCommand() {
|
|
3140
|
+
const { flags, positionals } = parseArgs(process.argv.slice(3), { booleans: ['json', 'dry-run', 'no-link', 'images-blocked', 'ignore-checks'] });
|
|
3141
|
+
const action = positionals[0];
|
|
3142
|
+
const str = (v) => (typeof v === 'string' ? v : undefined);
|
|
3143
|
+
const noFile = ['blocks', 'import', 'templates', 'brand-kit', 'new', 'publish', 'versions', 'restore', 'layouts', 'layout'];
|
|
3144
|
+
if (!['blocks', 'render', 'preview', 'check', 'test', 'import', 'templates', 'brand-kit', 'new', 'save', 'publish', 'versions', 'restore', 'layouts', 'layout'].includes(action) || (!noFile.includes(action) && !str(flags.file))) {
|
|
3145
|
+
console.log(EMAIL_USAGE);
|
|
3146
|
+
process.exit(1);
|
|
3147
|
+
}
|
|
3148
|
+
const cfg = requireSignIn();
|
|
3149
|
+
const call = siteCall(cfg);
|
|
3150
|
+
const json = flags.json === true;
|
|
3151
|
+
const workspace = str(flags.workspace);
|
|
3152
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
3153
|
+
const write = (html) => {
|
|
3154
|
+
if (!str(flags.out)) return [];
|
|
3155
|
+
writeFileSync(flags.out, html);
|
|
3156
|
+
return [` Wrote ${flags.out}.`, ''];
|
|
3157
|
+
};
|
|
3158
|
+
try {
|
|
3159
|
+
if (action === 'blocks') {
|
|
3160
|
+
const res = await studio.listBlocks(call, { workspace });
|
|
3161
|
+
return out(res, studio.renderBlocks(res, { type: positionals[1] }));
|
|
3162
|
+
}
|
|
3163
|
+
if (action === 'import') {
|
|
3164
|
+
const body = studio.importFromFiles({
|
|
3165
|
+
source: str(flags.source),
|
|
3166
|
+
body: str(flags.body),
|
|
3167
|
+
layout: str(flags.layout),
|
|
3168
|
+
layoutName: str(flags['layout-name']),
|
|
3169
|
+
layoutId: str(flags['customerio-layout']),
|
|
3170
|
+
text: str(flags.text),
|
|
3171
|
+
globalStyles: str(flags['global-styles']),
|
|
3172
|
+
node: str(flags.node),
|
|
3173
|
+
name: str(flags.name),
|
|
3174
|
+
templateId: str(flags['customerio-template']),
|
|
3175
|
+
dryRun: flags['dry-run'] === true,
|
|
3176
|
+
noLink: flags['no-link'] === true,
|
|
3177
|
+
});
|
|
3178
|
+
const res = await studio.importEmail(call, { workspace, ...body });
|
|
3179
|
+
return out(res, studio.renderImported(res));
|
|
3180
|
+
}
|
|
3181
|
+
if (action === 'brand-kit') {
|
|
3182
|
+
if (!str(flags.file)) {
|
|
3183
|
+
const res = await studio.getBrandKit(call, { workspace });
|
|
3184
|
+
const lines = studio.renderBrandKit(res);
|
|
3185
|
+
if (str(flags.out)) {
|
|
3186
|
+
writeFileSync(flags.out, JSON.stringify({ kit: res.kit, version: res.version }, null, 2));
|
|
3187
|
+
lines.push(` Wrote ${flags.out}. Edit it, then save it with --file ${flags.out}.`, '');
|
|
3188
|
+
}
|
|
3189
|
+
return out(res, lines);
|
|
3190
|
+
}
|
|
3191
|
+
const { kit, version } = studio.brandKitFromFile(flags.file, str(flags['kit-version']));
|
|
3192
|
+
const res = await studio.saveBrandKit(call, { workspace, kit, version, dryRun: flags['dry-run'] === true });
|
|
3193
|
+
return out(res, studio.renderBrandKitSaved(res));
|
|
3194
|
+
}
|
|
3195
|
+
const num = (v) => (v === undefined ? undefined : Number(v));
|
|
3196
|
+
if (action === 'layouts') {
|
|
3197
|
+
if (!positionals[1]) {
|
|
3198
|
+
const res = await studio.listLayouts(call, { workspace });
|
|
3199
|
+
return out(res, studio.renderLayouts(res));
|
|
3200
|
+
}
|
|
3201
|
+
const res = await studio.getLayout(call, { workspace, id: positionals[1] });
|
|
3202
|
+
const lines = studio.renderLayout(res);
|
|
3203
|
+
if (str(flags.out)) {
|
|
3204
|
+
writeFileSync(flags.out, res.layout.html);
|
|
3205
|
+
lines.push(` Wrote ${flags.out}. Edit it, then: workover email layout save ${res.layout.id} --file ${flags.out} --revision ${res.layout.revision}`, '');
|
|
3206
|
+
}
|
|
3207
|
+
return out(res, lines);
|
|
3208
|
+
}
|
|
3209
|
+
if (action === 'layout') {
|
|
3210
|
+
const verb = positionals[1];
|
|
3211
|
+
const html = () => {
|
|
3212
|
+
if (!str(flags.file)) throw apiError(400, 'Give the layout as --file layout.html (HTML with {{ content }} once).');
|
|
3213
|
+
return readFileSync(flags.file, 'utf8');
|
|
3214
|
+
};
|
|
3215
|
+
if (verb === 'new') {
|
|
3216
|
+
const res = await studio.createLayout(call, { workspace, name: str(flags.name), html: html() });
|
|
3217
|
+
return out(res, studio.renderLayout(res, 'Created'));
|
|
3218
|
+
}
|
|
3219
|
+
if (verb === 'save') {
|
|
3220
|
+
const res = await studio.saveLayout(call, {
|
|
3221
|
+
workspace,
|
|
3222
|
+
id: positionals[2],
|
|
3223
|
+
revision: num(str(flags.revision)),
|
|
3224
|
+
name: str(flags.name),
|
|
3225
|
+
html: str(flags.file) ? html() : undefined,
|
|
3226
|
+
});
|
|
3227
|
+
return out(res, studio.renderLayout(res, 'Saved'));
|
|
3228
|
+
}
|
|
3229
|
+
if (verb === 'delete') {
|
|
3230
|
+
const res = await studio.deleteLayout(call, { workspace, id: positionals[2] });
|
|
3231
|
+
return out(res, ['', ` ✓ Deleted layout #${res.deleted}.`, '']);
|
|
3232
|
+
}
|
|
3233
|
+
throw apiError(400, 'workover email layout new|save|delete; `workover email layouts` lists them.');
|
|
3234
|
+
}
|
|
3235
|
+
if (action === 'new') {
|
|
3236
|
+
const email = str(flags.file) ? studio.emailFromFile(flags.file) : {};
|
|
3237
|
+
const res = await studio.createTemplate(call, {
|
|
3238
|
+
workspace,
|
|
3239
|
+
name: str(flags.name) ?? email.name,
|
|
3240
|
+
...(email.blocks ? { blocks: email.blocks } : {}),
|
|
3241
|
+
...((str(flags.subject) ?? email.subject) !== undefined ? { subject: str(flags.subject) ?? email.subject } : {}),
|
|
3242
|
+
...((str(flags.preheader) ?? email.preheader) !== undefined ? { preheader: str(flags.preheader) ?? email.preheader } : {}),
|
|
3243
|
+
});
|
|
3244
|
+
return out(res, studio.renderSavedTemplate(res, 'Created'));
|
|
3245
|
+
}
|
|
3246
|
+
if (action === 'save') {
|
|
3247
|
+
const email = studio.emailFromFile(flags.file);
|
|
3248
|
+
const { revision, ...fields } = email;
|
|
3249
|
+
const res = await studio.saveTemplate(call, {
|
|
3250
|
+
workspace,
|
|
3251
|
+
id: positionals[1],
|
|
3252
|
+
...fields,
|
|
3253
|
+
revision: num(str(flags.revision)) ?? revision,
|
|
3254
|
+
});
|
|
3255
|
+
return out(res, studio.renderSavedTemplate(res));
|
|
3256
|
+
}
|
|
3257
|
+
if (action === 'publish' || action === 'restore') {
|
|
3258
|
+
// The revision read: given, or the email's current one (the check happens on the server).
|
|
3259
|
+
let revision = num(str(flags.revision));
|
|
3260
|
+
if (revision === undefined) revision = (await studio.getTemplate(call, { workspace, id: positionals[1] })).template.revision;
|
|
3261
|
+
if (action === 'publish') {
|
|
3262
|
+
const res = await studio.publishTemplate(call, {
|
|
3263
|
+
workspace,
|
|
3264
|
+
id: positionals[1],
|
|
3265
|
+
revision,
|
|
3266
|
+
note: str(flags.note),
|
|
3267
|
+
ignoreChecks: flags['ignore-checks'] === true,
|
|
3268
|
+
});
|
|
3269
|
+
return out(res, studio.renderPublished(res));
|
|
3270
|
+
}
|
|
3271
|
+
const res = await studio.restoreVersion(call, { workspace, id: positionals[1], version: positionals[2], revision });
|
|
3272
|
+
return out(res, studio.renderSavedTemplate(res, `Restored version ${res.restored} into`));
|
|
3273
|
+
}
|
|
3274
|
+
if (action === 'versions') {
|
|
3275
|
+
const res = await studio.listVersions(call, { workspace, id: positionals[1] });
|
|
3276
|
+
return out(res, studio.renderVersions(res));
|
|
3277
|
+
}
|
|
3278
|
+
if (action === 'templates') {
|
|
3279
|
+
if (!positionals[1]) {
|
|
3280
|
+
const res = await studio.listTemplates(call, { workspace });
|
|
3281
|
+
return out(res, studio.renderTemplates(res));
|
|
3282
|
+
}
|
|
3283
|
+
const res = await studio.getTemplate(call, { workspace, id: positionals[1] });
|
|
3284
|
+
const lines = studio.renderTemplate(res);
|
|
3285
|
+
if (str(flags.out)) {
|
|
3286
|
+
writeFileSync(flags.out, JSON.stringify(studio.draftFile(res.template), null, 2));
|
|
3287
|
+
lines.push(` Wrote ${flags.out}.`, '');
|
|
3288
|
+
}
|
|
3289
|
+
return out(res, lines);
|
|
3290
|
+
}
|
|
3291
|
+
const email = studio.emailFromFile(flags.file);
|
|
3292
|
+
if (action === 'render') {
|
|
3293
|
+
const res = await studio.renderEmail(call, { workspace, email });
|
|
3294
|
+
return out(res, [...studio.renderRendered(res), ...write(res.html)]);
|
|
3295
|
+
}
|
|
3296
|
+
let data;
|
|
3297
|
+
if (str(flags.data)) {
|
|
3298
|
+
try {
|
|
3299
|
+
data = JSON.parse(readFileSync(flags.data, 'utf8'));
|
|
3300
|
+
} catch {
|
|
3301
|
+
throw Object.assign(new Error(`${flags.data} is not a JSON file.`), { status: 400 });
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
const person = {
|
|
3305
|
+
workspace,
|
|
3306
|
+
email,
|
|
3307
|
+
subject: str(flags.subject),
|
|
3308
|
+
preheader: str(flags.preheader),
|
|
3309
|
+
contact: str(flags.contact),
|
|
3310
|
+
data,
|
|
3311
|
+
};
|
|
3312
|
+
if (action === 'check') {
|
|
3313
|
+
const res = await studio.checkEmail(call, person);
|
|
3314
|
+
return out(res, studio.renderChecked(res));
|
|
3315
|
+
}
|
|
3316
|
+
if (action === 'test') {
|
|
3317
|
+
const res = await studio.testEmail(call, { ...person, fromAddressId: str(flags.from) });
|
|
3318
|
+
return out(res, studio.renderTested(res));
|
|
3319
|
+
}
|
|
3320
|
+
const res = await studio.previewEmail(call, { ...person, imagesBlocked: flags['images-blocked'] === true });
|
|
3321
|
+
return out(res, [...studio.renderPreview(res), ...write(res.html)]);
|
|
3322
|
+
} catch (e) {
|
|
3323
|
+
siteFail(e);
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
|
|
3327
|
+
async function contactsCommand() {
|
|
3328
|
+
const argv = process.argv.slice(3);
|
|
3329
|
+
const repeated = ['--attr', '--prop', '--set'];
|
|
3330
|
+
const { flags, positionals } = parseArgs(
|
|
3331
|
+
argv.filter(
|
|
3332
|
+
(a, i) => !repeated.includes(a) && !repeated.includes(argv[i - 1]) && !repeated.some((f) => a.startsWith(`${f}=`)),
|
|
3333
|
+
),
|
|
3334
|
+
{ booleans: ['json', 'archived', 'manual', 'unsubscribe-all', 'resubscribe-all', 'everyone-now', 'yes'] },
|
|
3335
|
+
);
|
|
3336
|
+
const group = ['attrs', 'keys', 'event-names', 'segments', 'topics', 'journeys'].includes(positionals[0]) ? positionals[0] : null;
|
|
3337
|
+
const action = group ? positionals[1] || 'list' : positionals[0] || 'list';
|
|
3338
|
+
const rest = group ? positionals.slice(2) : positionals.slice(1);
|
|
3339
|
+
const known = {
|
|
3340
|
+
attrs: ['list', 'add', 'rename', 'archive', 'restore'],
|
|
3341
|
+
keys: ['list', 'create', 'revoke'],
|
|
3342
|
+
'event-names': ['list', 'rename', 'archive', 'restore'],
|
|
3343
|
+
segments: ['list', 'show', 'preview', 'create', 'update', 'archive', 'restore', 'members', 'add', 'remove', 'export'],
|
|
3344
|
+
topics: ['list', 'create', 'update', 'archive', 'restore', 'reorder', 'reset-links'],
|
|
3345
|
+
journeys: ['list', 'show', 'create', 'update', 'publish', 'pause', 'resume', 'archive', 'test', 'report', 'runs'],
|
|
3346
|
+
null: ['list', 'get', 'identify', 'track', 'events', 'export', 'subscriptions', 'consent', 'preferences-link'],
|
|
3347
|
+
};
|
|
3348
|
+
if (!known[group].includes(action)) {
|
|
3349
|
+
console.log(CONTACTS_USAGE);
|
|
3350
|
+
process.exit(1);
|
|
3351
|
+
}
|
|
3352
|
+
const cfg = requireSignIn();
|
|
3353
|
+
const call = siteCall(cfg);
|
|
3354
|
+
const json = flags.json === true;
|
|
3355
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
3356
|
+
const str = (v) => (typeof v === 'string' ? v : undefined);
|
|
3357
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
3358
|
+
try {
|
|
3359
|
+
if (group === 'attrs') {
|
|
3360
|
+
if (action === 'list') {
|
|
3361
|
+
const res = await listContactAttributes(call, { workspace });
|
|
3362
|
+
return out(res, renderContactAttributes(res));
|
|
3363
|
+
}
|
|
3364
|
+
if (action === 'add') {
|
|
3365
|
+
const res = await defineContactAttribute(call, { workspace, key: rest[0], type: rest[1], label: str(flags.label) });
|
|
3366
|
+
return out(res, renderContactAttributeSaved(res));
|
|
3367
|
+
}
|
|
3368
|
+
const res = await updateContactAttribute(call, {
|
|
3369
|
+
workspace,
|
|
3370
|
+
key: rest[0],
|
|
3371
|
+
...(action === 'rename' ? { label: rest[1] } : { archived: action === 'archive' }),
|
|
3372
|
+
});
|
|
3373
|
+
return out(res, renderContactAttributeSaved(res));
|
|
3374
|
+
}
|
|
3375
|
+
if (group === 'segments') {
|
|
3376
|
+
const num = (v) => (v === undefined ? undefined : Number(v));
|
|
3377
|
+
if (action === 'list') {
|
|
3378
|
+
const res = await listSegments(call, { workspace, archived: flags.archived === true });
|
|
3379
|
+
return out(res, renderSegments(res));
|
|
3380
|
+
}
|
|
3381
|
+
if (action === 'show') {
|
|
3382
|
+
const res = await getSegment(call, { workspace, segment: rest[0] });
|
|
3383
|
+
return out(res, renderSegment(res));
|
|
3384
|
+
}
|
|
3385
|
+
// A file holds the definition, or {name, kind, definition}.
|
|
3386
|
+
const file = str(flags.file) ? definitionFromFile(flags.file) : undefined;
|
|
3387
|
+
const definition = file && (file.definition !== undefined || file.name !== undefined) ? file.definition : file;
|
|
3388
|
+
if (action === 'preview') {
|
|
3389
|
+
const res = await previewSegment(call, { workspace, definition, segment: str(flags.segment) });
|
|
3390
|
+
return out(res, renderSegmentPreview(res));
|
|
3391
|
+
}
|
|
3392
|
+
if (action === 'create') {
|
|
3393
|
+
const res = await createSegment(call, {
|
|
3394
|
+
workspace,
|
|
3395
|
+
name: str(flags.name) ?? file?.name ?? rest[0],
|
|
3396
|
+
kind: flags.manual === true ? 'manual' : file?.kind,
|
|
3397
|
+
definition: flags.manual === true ? undefined : definition,
|
|
3398
|
+
});
|
|
3399
|
+
return out(res, renderSegmentSaved(res));
|
|
3400
|
+
}
|
|
3401
|
+
if (action === 'update' || action === 'archive' || action === 'restore') {
|
|
3402
|
+
const res = await updateSegment(call, {
|
|
3403
|
+
workspace,
|
|
3404
|
+
segment: rest[0],
|
|
3405
|
+
...(action === 'update'
|
|
3406
|
+
? { name: str(flags.name), definition }
|
|
3407
|
+
: { archived: action === 'archive' }),
|
|
3408
|
+
});
|
|
3409
|
+
return out(res, renderSegmentSaved(res));
|
|
3410
|
+
}
|
|
3411
|
+
if (action === 'members') {
|
|
3412
|
+
const res = await segmentMembers(call, {
|
|
3413
|
+
workspace,
|
|
3414
|
+
segment: rest[0],
|
|
3415
|
+
offset: num(flags.offset),
|
|
3416
|
+
limit: num(flags.limit),
|
|
3417
|
+
});
|
|
3418
|
+
return out(res, renderSegmentMembers(res));
|
|
3419
|
+
}
|
|
3420
|
+
if (action === 'add' || action === 'remove') {
|
|
3421
|
+
const res = await changeSegmentMembers(call, {
|
|
3422
|
+
workspace,
|
|
3423
|
+
segment: rest[0],
|
|
3424
|
+
contacts: rest.slice(1),
|
|
3425
|
+
remove: action === 'remove',
|
|
3426
|
+
});
|
|
3427
|
+
out(res, renderSegmentMembersChanged(res));
|
|
3428
|
+
if (res.notFound.length) process.exit(1);
|
|
3429
|
+
return;
|
|
3430
|
+
}
|
|
3431
|
+
const res = await exportContacts(call, { workspace, segment: rest[0], out: str(flags.out) });
|
|
3432
|
+
if (!res.file && !json) return process.stdout.write(res.csv);
|
|
3433
|
+
return out(res, renderExported(res));
|
|
3434
|
+
}
|
|
3435
|
+
if (action === 'export') {
|
|
3436
|
+
const res = await exportContacts(call, { workspace, segment: str(flags.segment), out: str(flags.out) });
|
|
3437
|
+
if (!res.file && !json) return process.stdout.write(res.csv);
|
|
3438
|
+
return out(res, renderExported(res));
|
|
3439
|
+
}
|
|
3440
|
+
if (group === 'event-names') {
|
|
3441
|
+
if (action === 'list') {
|
|
3442
|
+
const res = await listEventNames(call, { workspace });
|
|
3443
|
+
return out(res, renderEventNames(res));
|
|
3444
|
+
}
|
|
3445
|
+
const res = await updateEventName(call, {
|
|
3446
|
+
workspace,
|
|
3447
|
+
name: rest[0],
|
|
3448
|
+
...(action === 'rename' ? { label: rest[1] } : { archived: action === 'archive' }),
|
|
3449
|
+
});
|
|
3450
|
+
return out(res, renderEventNameSaved(res));
|
|
3451
|
+
}
|
|
3452
|
+
if (action === 'events') {
|
|
3453
|
+
const res = await contactEvents(call, {
|
|
3454
|
+
workspace,
|
|
3455
|
+
contact: rest[0],
|
|
3456
|
+
name: str(flags.name),
|
|
3457
|
+
offset: flags.offset === undefined ? undefined : Number(flags.offset),
|
|
3458
|
+
limit: flags.limit === undefined ? undefined : Number(flags.limit),
|
|
3459
|
+
});
|
|
3460
|
+
return out(res, renderContactEvents(res));
|
|
3461
|
+
}
|
|
3462
|
+
if (action === 'track') {
|
|
3463
|
+
let events;
|
|
3464
|
+
if (str(flags.file)) events = eventsFromFile(flags.file);
|
|
3465
|
+
else {
|
|
3466
|
+
const one = { name: rest[0] ?? str(flags.name) };
|
|
3467
|
+
if (str(flags['external-id'])) one.externalId = flags['external-id'];
|
|
3468
|
+
if (str(flags.email)) one.email = flags.email;
|
|
3469
|
+
if (str(flags['anonymous-id'])) one.anonymousId = flags['anonymous-id'];
|
|
3470
|
+
if (str(flags.timestamp)) one.timestamp = flags.timestamp;
|
|
3471
|
+
if (str(flags.id)) one.id = flags.id;
|
|
3472
|
+
const properties = attrFlags(argv, '--prop');
|
|
3473
|
+
if (Object.keys(properties).length) one.properties = properties;
|
|
3474
|
+
events = [one];
|
|
3475
|
+
}
|
|
3476
|
+
const res = await trackEvents(call, { workspace, events });
|
|
3477
|
+
out(res, renderTracked(res));
|
|
3478
|
+
if (res.failed) process.exit(1);
|
|
3479
|
+
return;
|
|
3480
|
+
}
|
|
3481
|
+
if (group === 'journeys') {
|
|
3482
|
+
const journey = rest[0];
|
|
3483
|
+
if (action !== 'list' && action !== 'create' && !journey) {
|
|
3484
|
+
console.log(CONTACTS_USAGE);
|
|
3485
|
+
process.exit(1);
|
|
3486
|
+
}
|
|
3487
|
+
if (action === 'list') {
|
|
3488
|
+
const res = await journeys.listJourneys(call, { workspace, archived: flags.archived === true });
|
|
3489
|
+
return out(res, journeys.renderJourneys(res));
|
|
3490
|
+
}
|
|
3491
|
+
if (action === 'show') {
|
|
3492
|
+
const res = await journeys.getJourney(call, { workspace, journey });
|
|
3493
|
+
return out(res, journeys.renderJourney(res));
|
|
3494
|
+
}
|
|
3495
|
+
if (action === 'create' || action === 'update') {
|
|
3496
|
+
const body = str(flags.file) ? journeys.journeyFromFile(flags.file) : {};
|
|
3497
|
+
if (str(flags.name)) body.name = flags.name;
|
|
3498
|
+
const res =
|
|
3499
|
+
action === 'create'
|
|
3500
|
+
? await journeys.createJourney(call, { workspace, body })
|
|
3501
|
+
: await journeys.updateJourney(call, { workspace, journey, body });
|
|
3502
|
+
return out(res, journeys.renderJourneySaved(res));
|
|
3503
|
+
}
|
|
3504
|
+
if (action === 'publish') {
|
|
3505
|
+
const res = await journeys.publishJourney(call, {
|
|
3506
|
+
workspace,
|
|
3507
|
+
journey,
|
|
3508
|
+
everyoneNow: flags['everyone-now'] === true,
|
|
3509
|
+
confirm: flags.yes === true,
|
|
3510
|
+
});
|
|
3511
|
+
return out(res, journeys.renderPublish(res));
|
|
3512
|
+
}
|
|
3513
|
+
if (action === 'test') {
|
|
3514
|
+
const res = await journeys.testJourney(call, { workspace, journey, step: str(flags.step), contact: str(flags.contact) });
|
|
3515
|
+
return out(res, journeys.renderTest(res));
|
|
3516
|
+
}
|
|
3517
|
+
if (action === 'report') {
|
|
3518
|
+
const res = await journeys.journeyReport(call, { workspace, journey });
|
|
3519
|
+
return out(res, journeys.renderReport(res));
|
|
3520
|
+
}
|
|
3521
|
+
if (action === 'runs') {
|
|
3522
|
+
const res = await journeys.journeyRuns(call, {
|
|
3523
|
+
workspace,
|
|
3524
|
+
journey,
|
|
3525
|
+
status: str(flags.status),
|
|
3526
|
+
offset: str(flags.offset),
|
|
3527
|
+
limit: str(flags.limit),
|
|
3528
|
+
});
|
|
3529
|
+
return out(res, journeys.renderRuns(res));
|
|
3530
|
+
}
|
|
3531
|
+
const res = await journeys.setJourneyState(call, { workspace, journey, action });
|
|
3532
|
+
return out(res, journeys.renderJourneyState(res));
|
|
3533
|
+
}
|
|
3534
|
+
if (group === 'topics') {
|
|
3535
|
+
if (action === 'list') {
|
|
3536
|
+
const res = await listTopics(call, { workspace });
|
|
3537
|
+
return out(res, renderTopics(res));
|
|
3538
|
+
}
|
|
3539
|
+
if (action === 'create') {
|
|
3540
|
+
const res = await createTopic(call, {
|
|
3541
|
+
workspace,
|
|
3542
|
+
key: rest[0],
|
|
3543
|
+
name: str(flags.name),
|
|
3544
|
+
description: str(flags.description),
|
|
3545
|
+
default: str(flags.default),
|
|
3546
|
+
});
|
|
3547
|
+
return out(res, renderTopicSaved(res));
|
|
3548
|
+
}
|
|
3549
|
+
if (action === 'reorder') {
|
|
3550
|
+
const res = await reorderTopics(call, { workspace, keys: rest });
|
|
3551
|
+
return out(res, renderTopics(res));
|
|
3552
|
+
}
|
|
3553
|
+
if (action === 'reset-links') {
|
|
3554
|
+
const res = await resetPreferenceLinks(call, { workspace });
|
|
3555
|
+
return out(res, renderLinksReset(res));
|
|
3556
|
+
}
|
|
3557
|
+
const res = await updateTopic(call, {
|
|
3558
|
+
workspace,
|
|
3559
|
+
key: rest[0],
|
|
3560
|
+
...(action === 'update'
|
|
3561
|
+
? { name: str(flags.name), description: str(flags.description), default: str(flags.default) }
|
|
3562
|
+
: { archived: action === 'archive' }),
|
|
3563
|
+
});
|
|
3564
|
+
return out(res, renderTopicSaved(res));
|
|
3565
|
+
}
|
|
3566
|
+
if (action === 'subscriptions') {
|
|
3567
|
+
const sets = [];
|
|
3568
|
+
for (let i = 0; i < argv.length; i++) {
|
|
3569
|
+
if (argv[i] === '--set') sets.push(argv[++i]);
|
|
3570
|
+
else if (argv[i].startsWith('--set=')) sets.push(argv[i].slice(6));
|
|
3571
|
+
}
|
|
3572
|
+
if (flags['unsubscribe-all'] === true && flags['resubscribe-all'] === true)
|
|
3573
|
+
throw Object.assign(new Error('Give --unsubscribe-all or --resubscribe-all, not both.'), { status: 400 });
|
|
3574
|
+
const all = flags['unsubscribe-all'] === true ? true : flags['resubscribe-all'] === true ? false : undefined;
|
|
3575
|
+
const res =
|
|
3576
|
+
sets.length || all !== undefined
|
|
3577
|
+
? await setSubscriptions(call, { workspace, contact: rest[0], topics: topicChoices(sets), unsubscribedAll: all })
|
|
3578
|
+
: await getSubscriptions(call, { workspace, contact: rest[0] });
|
|
3579
|
+
return out(res, renderSubscriptions(res));
|
|
3580
|
+
}
|
|
3581
|
+
if (action === 'consent') {
|
|
3582
|
+
const res = await contactConsent(call, {
|
|
3583
|
+
workspace,
|
|
3584
|
+
contact: rest[0],
|
|
3585
|
+
offset: flags.offset === undefined ? undefined : Number(flags.offset),
|
|
3586
|
+
limit: flags.limit === undefined ? undefined : Number(flags.limit),
|
|
3587
|
+
});
|
|
3588
|
+
return out(res, renderConsent(res));
|
|
3589
|
+
}
|
|
3590
|
+
if (action === 'preferences-link') {
|
|
3591
|
+
const res = await preferencesLink(call, { workspace, contact: rest[0], topic: str(flags.topic) });
|
|
3592
|
+
return out(res, renderPreferencesLink(res));
|
|
3593
|
+
}
|
|
3594
|
+
if (group === 'keys') {
|
|
3595
|
+
if (action === 'list') {
|
|
3596
|
+
const res = await listContactsKeys(call, { workspace });
|
|
3597
|
+
return out(res, renderContactsKeys(res));
|
|
3598
|
+
}
|
|
3599
|
+
if (action === 'create') {
|
|
3600
|
+
const res = await createContactsKey(call, { workspace, name: str(flags.name) ?? rest[0] });
|
|
3601
|
+
return out(res, renderContactsKeyCreated(res));
|
|
3602
|
+
}
|
|
3603
|
+
const res = await revokeContactsKey(call, { workspace, key: rest[0] });
|
|
3604
|
+
return out(res, renderContactsKeyRevoked(res));
|
|
3605
|
+
}
|
|
3606
|
+
if (action === 'list') {
|
|
3607
|
+
const res = await listContacts(call, {
|
|
3608
|
+
workspace,
|
|
3609
|
+
q: str(flags.q),
|
|
3610
|
+
segment: str(flags.segment),
|
|
3611
|
+
offset: flags.offset === undefined ? undefined : Number(flags.offset),
|
|
3612
|
+
limit: flags.limit === undefined ? undefined : Number(flags.limit),
|
|
3613
|
+
});
|
|
3614
|
+
return out(res, renderContacts(res));
|
|
3615
|
+
}
|
|
3616
|
+
if (action === 'get') {
|
|
3617
|
+
const res = await getContact(call, { workspace, contact: rest[0] });
|
|
3618
|
+
return out(res, renderContact(res));
|
|
3619
|
+
}
|
|
3620
|
+
let contacts;
|
|
3621
|
+
if (str(flags.file)) contacts = contactsFromFile(flags.file);
|
|
3622
|
+
else {
|
|
3623
|
+
const one = {};
|
|
3624
|
+
if (str(flags.email)) one.email = flags.email;
|
|
3625
|
+
if (str(flags['external-id'])) one.externalId = flags['external-id'];
|
|
3626
|
+
if (str(flags.name)) one.name = flags.name;
|
|
3627
|
+
if (str(flags['anonymous-id'])) one.anonymousId = flags['anonymous-id'];
|
|
3628
|
+
const attributes = attrFlags(argv);
|
|
3629
|
+
if (Object.keys(attributes).length) one.attributes = attributes;
|
|
3630
|
+
contacts = [one];
|
|
3631
|
+
}
|
|
3632
|
+
const res = await identifyContacts(call, { workspace, contacts });
|
|
3633
|
+
out(res, renderContactsIdentified(res));
|
|
3634
|
+
if (res.failed) process.exit(1);
|
|
3635
|
+
} catch (e) {
|
|
3636
|
+
if (e.status === 401) e.message = 'This sign-in no longer works. Run `workover login --contacts` again.';
|
|
3637
|
+
const help = e.status === 403 ? contactsScopeHelp(e.message) : null;
|
|
3638
|
+
if (help) e.message = `${e.message}\n ${help}`;
|
|
3639
|
+
siteFail(e);
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
|
|
3643
|
+
// ------------------------------------------------------------------ Support setup
|
|
3644
|
+
|
|
3645
|
+
const SUPPORT_USAGE = [
|
|
3646
|
+
'',
|
|
3647
|
+
' Usage: workover support <command> [--workspace <slug|id>] [--json]',
|
|
3648
|
+
'',
|
|
3649
|
+
' status the setup checklist: each step, who did it,',
|
|
3650
|
+
' and the next one to run',
|
|
3651
|
+
' setup [--name "<name>"] turn Support on and configure it. Safe to run',
|
|
3652
|
+
' [--color <#hex>] again: only what differs changes. --origins,',
|
|
3653
|
+
' [--origins <url,url>] --topics and --docs ADD to what is there and',
|
|
3654
|
+
' [--topics "<a>,<b>"] never remove (removing stays in Settings).',
|
|
3655
|
+
' [--docs <projectId,id>] --hours "mon-fri 9:00-17:00" with --tz.',
|
|
3656
|
+
' [--hours "<spec>" --tz <zone>] --agent on|off: answer from the docs.',
|
|
3657
|
+
' [--greeting "<text>"] --live switches the Messenger on for the',
|
|
3658
|
+
' [--agent on|off] [--live] sites (ask the person first); --off',
|
|
3659
|
+
' [--off] switches it off again',
|
|
3660
|
+
' step <analyze_app|install_snippet> tell Workover a step only you can see:',
|
|
3661
|
+
' [--detail "<what>"] [--failed] what the app is built with, where the',
|
|
3662
|
+
' snippet went',
|
|
3663
|
+
' install [--dir <app>] [--framework <name>] the snippet for the app in --dir',
|
|
3664
|
+
' (default: here), found from its files, or',
|
|
3665
|
+
` --framework: ${FRAMEWORKS.join(', ')};`,
|
|
3666
|
+
' and the server code that signs who is signed in',
|
|
3667
|
+
' secret --env-file <file> [--var <NAME>] [--rotate]',
|
|
3668
|
+
' create the identity secret and write it into',
|
|
3669
|
+
' the env file. Never printed. An existing one',
|
|
3670
|
+
' is kept unless --rotate',
|
|
3671
|
+
' test send a test conversation and confirm it',
|
|
3672
|
+
' reaches the inbox',
|
|
3673
|
+
' notifications [--set "email=off,slack=on"] your own Support notification switches, in',
|
|
3674
|
+
' every workspace: events (newConversation,',
|
|
3675
|
+
' handoff, assigned, mention) and channels',
|
|
3676
|
+
' (inApp, email, slack, push). Safe to repeat',
|
|
3677
|
+
' sources [list] what the AI agent answers from beyond the',
|
|
3678
|
+
' linked docs, with each source id',
|
|
3679
|
+
' sources add <url> [--sitemap] [--resync <0|6|24|168>]',
|
|
3680
|
+
' read a web page or sitemap into hidden docs',
|
|
3681
|
+
' sources add --project <id> answer from a private docs project',
|
|
3682
|
+
' sources pdf <file> a PDF the agent cites by name (3.5 MB)',
|
|
3683
|
+
' sources set <id> [--on|--off] [--resync <hours>]',
|
|
3684
|
+
' sources sync <id> read a web source again now',
|
|
3685
|
+
' sources remove <id> its hidden docs go to the trash',
|
|
3686
|
+
' releases [list] which version of the AI agent visitors get,',
|
|
3687
|
+
' and what the draft would change',
|
|
3688
|
+
' releases set-live [--note "<what>"] make the draft the next live version (ask',
|
|
3689
|
+
' the person first). Safe to repeat',
|
|
3690
|
+
' releases rollback <version> make an older version live again, as a new one',
|
|
3691
|
+
' tests [list] the batch test: questions and the newest run',
|
|
3692
|
+
' tests add "<question>" [--expect "<words>"]',
|
|
3693
|
+
' a question; --expect: words the answer must',
|
|
3694
|
+
' contain. Already there: skipped',
|
|
3695
|
+
' tests add --file <file> one question per line, or a CSV with a',
|
|
3696
|
+
' question,expect header (50 at most)',
|
|
3697
|
+
' tests generate up to 50 questions from the inbox',
|
|
3698
|
+
' tests remove <id> take a question out of the set',
|
|
3699
|
+
' tests run [--live] [--wait] ask every question against the draft (or',
|
|
3700
|
+
' --live); nothing is sent to anyone',
|
|
3701
|
+
' tests show <run> one run with every answer and its check',
|
|
3702
|
+
' tests rate <result> good|bad|clear [--note "<why>"]',
|
|
3703
|
+
' labels [list] every label with its id and conversation count,',
|
|
3704
|
+
' and labels carried but not in the catalog',
|
|
3705
|
+
' labels add <name> [--inside <label>] [--color <c>]',
|
|
3706
|
+
' add a label, optionally nested; any teammate',
|
|
3707
|
+
' labels set <label> [--name "<n>"] [--color <c>] [--archive|--restore]',
|
|
3708
|
+
' rename, recolor, archive or restore (by id or',
|
|
3709
|
+
' full name); owners and admins',
|
|
3710
|
+
' labels merge <into> --from "<a>,<b>" fold labels into one, each conversation once',
|
|
3711
|
+
' fields [list] custom conversation fields: key, type, options, use',
|
|
3712
|
+
' fields set "<label>" [--type text|number|date|choice] [--options "a,b"] [--key <k>]',
|
|
3713
|
+
' create or change one (15 at most); owners and',
|
|
3714
|
+
' admins. Safe to run again',
|
|
3715
|
+
' fields remove <field> remove one; values stay on conversations, hidden',
|
|
3716
|
+
' fields order <a>,<b>,... every field once, in its new order',
|
|
3717
|
+
' fields show <conversation> a conversation\'s fields and values',
|
|
3718
|
+
' fields fill <conversation> <key>=<value> ... set values (empty clears); any teammate',
|
|
3719
|
+
' label-rules [list] when the AI adds each label to a conversation',
|
|
3720
|
+
' label-rules set "<label>" --when "<rule>" [--on|--off]',
|
|
3721
|
+
' the AI adds the label when the rule applies',
|
|
3722
|
+
' (checked on handoff and on a summary). Safe to',
|
|
3723
|
+
' run again: it replaces the label\'s rule',
|
|
3724
|
+
' label-rules remove "<label>" the AI stops adding that label',
|
|
3725
|
+
' signatures [list] the brand\'s email signature, your own, and what',
|
|
3726
|
+
' your replies in Support emails end with',
|
|
3727
|
+
' signatures set brand|mine (--html "<text or html>" | --file <path> | --clear)',
|
|
3728
|
+
' set one; text is one line per line, HTML keeps',
|
|
3729
|
+
' links, https pictures and tables. Variables:',
|
|
3730
|
+
' {{agent.firstName|fallback}} and the rest.',
|
|
3731
|
+
' brand: owners and admins. Safe to repeat',
|
|
3732
|
+
' signatures preview (--html "<...>" | --file <path>)',
|
|
3733
|
+
' how it would arrive from you; saves nothing',
|
|
3734
|
+
' email [--on|--off] [--wait 5m|30|2h] [--verified-only|--any-email]',
|
|
3735
|
+
' [--from-name "<name>"] [--reply-to <address>] [--ask-email away|first|never]',
|
|
3736
|
+
' email follow-ups: Support emails a visitor the',
|
|
3737
|
+
' replies they missed. No flag reads; flags set',
|
|
3738
|
+
' only what they name ("" resets a name or',
|
|
3739
|
+
' address). --ask-email: when the Messenger asks',
|
|
3740
|
+
' for their email (away: at hand-off, or while',
|
|
3741
|
+
' you are away). Owners and admins. Safe to repeat',
|
|
3742
|
+
' email do-not-email <address> [--remove]',
|
|
3743
|
+
' never email that address (or allow it again)',
|
|
3744
|
+
' email test send a sample follow-up to your own address',
|
|
3745
|
+
' email [--sent-from <domain>|default] [--address <local>] [--new-emails off|support|default]',
|
|
3746
|
+
' this brand: the sending domain it emails from,',
|
|
3747
|
+
' the address there, and whether a new email to',
|
|
3748
|
+
' its mailbox starts a conversation',
|
|
3749
|
+
' email domains the sending domains: DNS records (looked up now),',
|
|
3750
|
+
' DKIM, SPF, DMARC, setup steps, forwarding, test',
|
|
3751
|
+
' email domain add <domain> connect a sending domain; prints the records',
|
|
3752
|
+
' email domain check|test|remove <domain>',
|
|
3753
|
+
' check verification and DNS now; send yourself a test',
|
|
3754
|
+
' email (reply to it); or remove the domain',
|
|
3755
|
+
' email domain forward <domain> <local>|--stop',
|
|
3756
|
+
' customers reply to <local>@<domain>; prints the',
|
|
3757
|
+
' address to forward that mailbox to',
|
|
3758
|
+
' email domain receives <domain> --on|--off',
|
|
3759
|
+
' replies at reply.<domain> by its own DNS record',
|
|
3760
|
+
' email domain bounce <domain> --on|--off',
|
|
3761
|
+
' optional: a custom bounce domain at bounce.<domain>',
|
|
3762
|
+
' so SPF aligns as well as DKIM',
|
|
3763
|
+
' email new-emails off|support "New emails by default" for every brand',
|
|
3764
|
+
' outside-bot [show] the outside bot (RC Brain) that answers first',
|
|
3765
|
+
' outside-bot set [--url <https url>] [--key-env <VAR>] [--key-header <name>]',
|
|
3766
|
+
' [--name <name>] [--persona presale|support|onboarding]',
|
|
3767
|
+
' [--when always|away] [--min <0-1>] [--per-minute <n>] [--burst <n>]',
|
|
3768
|
+
' [--on|--off] [--remove-key] safe to run again; the key is read from the',
|
|
3769
|
+
' named environment variable, never typed',
|
|
3770
|
+
' outside-bot check ask it one test question and show the result',
|
|
3771
|
+
' outcomes [list] [--outcome <o>] [--from <date>] [--to <date>] [--cursor <c>] [--csv]',
|
|
3772
|
+
' what became of each conversation Walter AI',
|
|
3773
|
+
' took, with the confirmed and resolution rates;',
|
|
3774
|
+
' --csv prints every matching row as CSV',
|
|
3775
|
+
' outcomes mark <conversation> --reason "<why>"',
|
|
3776
|
+
' mark it not resolved; owners and admins.',
|
|
3777
|
+
' Safe to repeat',
|
|
3778
|
+
' outcomes clear <conversation> remove the mark',
|
|
3779
|
+
' outcomes usage this month against the fair-use cap',
|
|
3780
|
+
' freshdesk [show] Freshdesk escalation: address, mode, priority, group,',
|
|
3781
|
+
' tags, close-after and the last key check',
|
|
3782
|
+
' freshdesk set [--domain <name>.freshdesk.com] [--key-file <file>] [--mode test|live]',
|
|
3783
|
+
' [--priority low|medium|high|urgent] [--group <id|none>] [--tags "a,b"]',
|
|
3784
|
+
' [--close-after on|off] the key is read from the file (or FRESHDESK_API_KEY),',
|
|
3785
|
+
' sealed and never shown. Starts in test mode; owners',
|
|
3786
|
+
' and admins. Safe to run again',
|
|
3787
|
+
' freshdesk check reads whose key it is from Freshdesk, writes nothing',
|
|
3788
|
+
' freshdesk remove forget the key; tickets already made stay',
|
|
3789
|
+
' home [--logo-url <https url|none>] the chat\'s Home look: read it, or set what',
|
|
3790
|
+
' [--agent-picture-url <url|none>] is given. --faces \'<json>\' replaces the',
|
|
3791
|
+
' [--typing-intro on|off] team faces: [{"name":"Ana","photoUrl":"https://.."}],',
|
|
3792
|
+
' [--show-faces on|off] or {"name","photoId"} to keep an uploaded photo.',
|
|
3793
|
+
' [--faces \'<json>\'] --upload <file> --slot <slot> [--name "<face>"]',
|
|
3794
|
+
' [--upload <file> --slot <s>] puts a picture in a slot (face-N one past the',
|
|
3795
|
+
' [--remove <slot>] last adds a face); --remove clears one',
|
|
3796
|
+
' thread [--closed-stays-closed on|off] how closed conversations behave: on, a',
|
|
3797
|
+
' visitor writing again starts a new one; off',
|
|
3798
|
+
' (the default), it reopens. No flag: show it',
|
|
3799
|
+
' config [get] the Messenger editor\'s unsaved changes:',
|
|
3800
|
+
' what is pending, live value and draft value',
|
|
3801
|
+
' config set [--name <text>] [--color <hex>] [--greeting <text>] [--intro <text>]',
|
|
3802
|
+
' [--theme auto|light|dark] [--position right|left] [--enabled on|off]',
|
|
3803
|
+
' [--origins a,b] [--allow-link on|off] [--set \'<json>\'] [--publish]',
|
|
3804
|
+
' change the draft; visitors see nothing until',
|
|
3805
|
+
' publish (or --publish). Safe to repeat',
|
|
3806
|
+
' config publish set the draft live, all in one change',
|
|
3807
|
+
' config discard throw the draft away',
|
|
3808
|
+
' style import <url> [--apply] read a site\'s brand color, dark theme color,',
|
|
3809
|
+
' font and logo; --apply adds them to the draft',
|
|
3810
|
+
' (publish sets them live). Safe to repeat',
|
|
3811
|
+
' walter [get] Walter AI: its tone and answer length, the',
|
|
3812
|
+
' draft, and the Deploy checklist (done or to do)',
|
|
3813
|
+
' walter set [--tone <tone>] [--length concise|standard|thorough]',
|
|
3814
|
+
' [--add-guidance "<line>"] [--set \'<json>\'] [--publish]',
|
|
3815
|
+
' change the draft; visitors see nothing until',
|
|
3816
|
+
' publish (or --publish). Safe to repeat',
|
|
3817
|
+
' walter preview "<question>" ask the draft as a visitor would; stores nothing',
|
|
3818
|
+
' walter publish | discard set the draft live, or throw it away',
|
|
3819
|
+
' walter changelog [--cursor <id>] who changed Walter, and when',
|
|
3820
|
+
' sla [--first <minutes|none>] reply targets in business minutes (office',
|
|
3821
|
+
' [--next <minutes|none>] hours only, holidays skipped), and how many',
|
|
3822
|
+
' [--holidays <day,day|none>] conversations are overdue. --holidays',
|
|
3823
|
+
' [--warnings on|off] replaces the list (YYYY-MM-DD); --tiers',
|
|
3824
|
+
' [--tiers \'<json>\'] replaces the tiers: [{"name":"VIP",',
|
|
3825
|
+
' "label":"VIP","first":15,"next":null}]',
|
|
3826
|
+
' assignment [--mode off|load|round_robin] who new conversations go to: by load or',
|
|
3827
|
+
' [--capacity <n>] in turn, never to anyone away or at',
|
|
3828
|
+
' [--pool <id,id|everyone>] capacity. No flag: show it and the team',
|
|
3829
|
+
' [--claim on|off] whoever replies or notes first takes it',
|
|
3830
|
+
' away [on|off] your own availability. No argument: show',
|
|
3831
|
+
' yours and the team\'s',
|
|
3832
|
+
'',
|
|
3833
|
+
' Every command takes --json. They need a sign-in from',
|
|
3834
|
+
` \`${SUPPORT_LOGIN}\`: the person approves "Set up Workover Support" in the browser.`,
|
|
3835
|
+
' --workspace is needed only when the account has more than one (`workover whoami`).',
|
|
3836
|
+
'',
|
|
3837
|
+
].join('\n');
|
|
3838
|
+
|
|
3839
|
+
/** `a,b , c` → ['a', 'b', 'c']; undefined when the flag was not given. */
|
|
3840
|
+
const listFlag = (v) =>
|
|
3841
|
+
typeof v === 'string'
|
|
3842
|
+
? v
|
|
3843
|
+
.split(',')
|
|
3844
|
+
.map((x) => x.trim())
|
|
3845
|
+
.filter(Boolean)
|
|
3846
|
+
: undefined;
|
|
3847
|
+
|
|
3848
|
+
/** `on`/`off` → boolean; undefined when the flag was not given. */
|
|
3849
|
+
const onOffFlag = (v, name) => {
|
|
3850
|
+
if (v === undefined) return undefined;
|
|
3851
|
+
if (v !== 'on' && v !== 'off') throw apiError(400, `--${name} is on or off.`);
|
|
3852
|
+
return v === 'on';
|
|
3853
|
+
};
|
|
3854
|
+
|
|
3855
|
+
/** `support home`: a picture uploaded or removed, or the plain settings set (or read). */
|
|
3856
|
+
async function homeSubcommand(call, workspace, flags) {
|
|
3857
|
+
if (typeof flags.remove === 'string') return supportHomeImage(call, { workspace, slot: flags.remove, remove: true });
|
|
3858
|
+
if (typeof flags.upload === 'string') {
|
|
3859
|
+
if (typeof flags.slot !== 'string') throw apiError(400, `Name the --slot: ${HOME_SLOTS.join(', ')}.`);
|
|
3860
|
+
let bytes;
|
|
3861
|
+
try {
|
|
3862
|
+
bytes = readFileSync(flags.upload);
|
|
3863
|
+
} catch {
|
|
3864
|
+
throw apiError(400, `Couldn't read ${flags.upload}.`);
|
|
3865
|
+
}
|
|
3866
|
+
return supportHomeImage(call, {
|
|
3867
|
+
workspace,
|
|
3868
|
+
slot: flags.slot,
|
|
3869
|
+
name: typeof flags.name === 'string' ? flags.name : undefined,
|
|
3870
|
+
file: { bytes, filename: basename(flags.upload), type: imageTypeFor(flags.upload) },
|
|
3871
|
+
});
|
|
3872
|
+
}
|
|
3873
|
+
const url = (v) => (typeof v !== 'string' ? undefined : v === 'none' ? null : v);
|
|
3874
|
+
let faces;
|
|
3875
|
+
if (typeof flags.faces === 'string') {
|
|
3876
|
+
try {
|
|
3877
|
+
faces = JSON.parse(flags.faces);
|
|
3878
|
+
} catch {
|
|
3879
|
+
throw apiError(400, `--faces is a JSON list, such as '[{"name":"Ana","photoUrl":"https://..."}]'.`);
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3882
|
+
return supportHome(call, {
|
|
3883
|
+
workspace,
|
|
3884
|
+
logoUrl: url(flags['logo-url']),
|
|
3885
|
+
botAvatarUrl: url(flags['agent-picture-url']),
|
|
3886
|
+
typingIntro: onOffFlag(flags['typing-intro'], 'typing-intro'),
|
|
3887
|
+
showFaces: onOffFlag(flags['show-faces'], 'show-faces'),
|
|
3888
|
+
faces,
|
|
3889
|
+
});
|
|
3890
|
+
}
|
|
3891
|
+
|
|
3892
|
+
const supportFail = (e) => {
|
|
3893
|
+
// siteCall's 401 names `login --site`; this sign-in is the Support one.
|
|
3894
|
+
const message = e.status === 401 ? `This sign-in no longer works. Run \`${SUPPORT_LOGIN}\` again.` : e.message;
|
|
3895
|
+
console.error(`\n ✗ ${message}`);
|
|
3896
|
+
const help = supportScopeHelp(message);
|
|
3897
|
+
if (help) console.error(` ${help}`);
|
|
3898
|
+
console.error('');
|
|
3899
|
+
process.exit(1);
|
|
3900
|
+
};
|
|
3901
|
+
|
|
3902
|
+
async function supportCommand() {
|
|
3903
|
+
const sub = process.argv[3];
|
|
3904
|
+
if (sub === 'sources') return supportSourcesCommand();
|
|
3905
|
+
if (sub === 'releases') return supportReleasesCommand();
|
|
3906
|
+
if (sub === 'tests') return supportTestsCommand();
|
|
3907
|
+
if (sub === 'config') return supportConfigCommand();
|
|
3908
|
+
if (sub === 'style') return supportStyleCommand();
|
|
3909
|
+
if (sub === 'walter') return supportWalterCommand();
|
|
3910
|
+
if (sub === 'labels') return supportLabelsCommand();
|
|
3911
|
+
if (sub === 'fields') return supportFieldsCommand();
|
|
3912
|
+
if (sub === 'sla' || sub === 'assignment' || sub === 'away') return supportInboxCommand(sub);
|
|
3913
|
+
if (sub === 'label-rules') return supportLabelRulesCommand();
|
|
3914
|
+
if (sub === 'signatures') return supportSignaturesCommand();
|
|
3915
|
+
if (sub === 'email') return supportEmailCommand();
|
|
3916
|
+
if (sub === 'outside-bot') return supportOutsideBotCommand();
|
|
3917
|
+
if (sub === 'outcomes') return supportOutcomesCommand();
|
|
3918
|
+
if (sub === 'freshdesk') return supportFreshdeskCommand();
|
|
3919
|
+
if (!['status', 'setup', 'step', 'install', 'secret', 'test', 'notifications', 'home', 'thread'].includes(sub)) {
|
|
3920
|
+
console.log(SUPPORT_USAGE);
|
|
3921
|
+
process.exit(sub ? 1 : 0);
|
|
3922
|
+
}
|
|
3923
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), {
|
|
3924
|
+
booleans: ['json', 'live', 'off', 'failed', 'rotate'],
|
|
3925
|
+
});
|
|
3926
|
+
const cfg = requireSignIn();
|
|
3927
|
+
const call = siteCall(cfg);
|
|
3928
|
+
const json = flags.json === true;
|
|
3929
|
+
const web = webForApi(cfg.api);
|
|
3930
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
3931
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
3932
|
+
try {
|
|
3933
|
+
if (sub === 'notifications') {
|
|
3934
|
+
if (flags.set !== undefined && typeof flags.set !== 'string')
|
|
3935
|
+
throw apiError(400, 'Give --set a value, such as "email=off,slack=on".');
|
|
3936
|
+
const set = typeof flags.set === 'string' ? parseSwitches(flags.set) : undefined;
|
|
3937
|
+
const res = await supportNotifications(call, { set });
|
|
3938
|
+
return out(res, renderSupportNotifications(res));
|
|
3939
|
+
}
|
|
3940
|
+
if (sub === 'status') {
|
|
3941
|
+
const res = await supportStatus(call, { workspace });
|
|
3942
|
+
return out(res, renderSupportStatus(res, { web }));
|
|
3943
|
+
}
|
|
3944
|
+
if (sub === 'setup') {
|
|
3945
|
+
if (flags.live === true && flags.off === true) throw apiError(400, 'Pass --live or --off, not both.');
|
|
3946
|
+
const agent = flags.agent;
|
|
3947
|
+
if (agent !== undefined && agent !== 'on' && agent !== 'off') throw apiError(400, '--agent is on or off.');
|
|
3948
|
+
if (flags.hours !== undefined && typeof flags.hours !== 'string') throw apiError(400, 'Give --hours a value, such as "mon-fri 9:00-17:00".');
|
|
3949
|
+
const res = await supportSetup(call, {
|
|
3950
|
+
workspace,
|
|
3951
|
+
name: typeof flags.name === 'string' ? flags.name : undefined,
|
|
3952
|
+
color: typeof flags.color === 'string' ? flags.color : undefined,
|
|
3953
|
+
greeting: typeof flags.greeting === 'string' ? flags.greeting : undefined,
|
|
3954
|
+
hours: typeof flags.hours === 'string' ? parseHours(flags.hours, flags.tz) : undefined,
|
|
3955
|
+
agentEnabled: agent === undefined ? undefined : agent === 'on',
|
|
3956
|
+
enabled: flags.live === true ? true : flags.off === true ? false : undefined,
|
|
3957
|
+
origins: listFlag(flags.origins),
|
|
3958
|
+
topics: listFlag(flags.topics),
|
|
3959
|
+
projectIds: listFlag(flags.docs),
|
|
3960
|
+
});
|
|
3961
|
+
return out(res, renderSupportSetup(res, { web }));
|
|
3962
|
+
}
|
|
3963
|
+
if (sub === 'step') {
|
|
3964
|
+
const res = await reportStep(call, {
|
|
3965
|
+
workspace,
|
|
3966
|
+
step: positionals[0],
|
|
3967
|
+
state: flags.failed === true ? 'failed' : 'done',
|
|
3968
|
+
detail: typeof flags.detail === 'string' ? flags.detail : undefined,
|
|
3969
|
+
});
|
|
3970
|
+
return out(res, renderSupportStatus(res, { web }));
|
|
3971
|
+
}
|
|
3972
|
+
if (sub === 'install') {
|
|
3973
|
+
const framework = typeof flags.framework === 'string' ? flags.framework.toLowerCase() : null;
|
|
3974
|
+
if (framework && !FRAMEWORKS.includes(framework))
|
|
3975
|
+
throw apiError(400, `No snippet for "${framework}". One of: ${FRAMEWORKS.join(', ')}.`);
|
|
3976
|
+
const status = await supportStatus(call, { workspace });
|
|
3977
|
+
const dir = typeof flags.dir === 'string' ? flags.dir : process.cwd();
|
|
3978
|
+
const detected = framework ? null : detectFramework({ exists: existsSync, read: (p) => readFileSync(p, 'utf8') }, dir);
|
|
3979
|
+
const res = { framework: framework || detected?.framework || null, detected, install: status.install };
|
|
3980
|
+
return out(res, renderInstall({ status, detected, framework }));
|
|
3981
|
+
}
|
|
3982
|
+
if (sub === 'secret') {
|
|
3983
|
+
const res = await writeIdentitySecret(
|
|
3984
|
+
call,
|
|
3985
|
+
{ read: (p) => readFileSync(p, 'utf8'), write: (p, text) => writePrivateFile(p, text) },
|
|
3986
|
+
{
|
|
3987
|
+
workspace,
|
|
3988
|
+
envFile: typeof flags['env-file'] === 'string' ? flags['env-file'] : undefined,
|
|
3989
|
+
varName: typeof flags.var === 'string' ? flags.var : undefined,
|
|
3990
|
+
rotate: flags.rotate === true,
|
|
3991
|
+
},
|
|
3992
|
+
);
|
|
3993
|
+
return out(res, [
|
|
3994
|
+
'',
|
|
3995
|
+
` ✓ ${res.rotated ? 'Rotated' : 'Created'} the identity secret and wrote it to ${res.envFile} as ${res.varName}.`,
|
|
3996
|
+
' It is not printed. Keep that file out of version control and out of the browser bundle.',
|
|
3997
|
+
'',
|
|
3998
|
+
]);
|
|
3999
|
+
}
|
|
4000
|
+
if (sub === 'home') {
|
|
4001
|
+
const res = await homeSubcommand(call, workspace, flags);
|
|
4002
|
+
return out(res, renderSupportHome(res));
|
|
4003
|
+
}
|
|
4004
|
+
if (sub === 'thread') {
|
|
4005
|
+
const v = flags['closed-stays-closed'];
|
|
4006
|
+
if (v !== undefined && v !== 'on' && v !== 'off') throw apiError(400, '--closed-stays-closed is on or off.');
|
|
4007
|
+
const res = await supportThread(call, { workspace, closedStaysClosed: v === undefined ? undefined : v === 'on' });
|
|
4008
|
+
return out(res, renderSupportThread(res));
|
|
4009
|
+
}
|
|
4010
|
+
// test
|
|
4011
|
+
const res = await sendTest(call, { workspace });
|
|
4012
|
+
return out(res, renderSupportTest(res, { web }));
|
|
4013
|
+
} catch (e) {
|
|
4014
|
+
supportFail(e);
|
|
4015
|
+
}
|
|
4016
|
+
}
|
|
4017
|
+
|
|
4018
|
+
/**
|
|
4019
|
+
* `workover support config [get|set|publish|discard]`: the Messenger's settings through the editor's
|
|
4020
|
+
* one draft (support-config.mjs, WO-1752, S46).
|
|
4021
|
+
*/
|
|
4022
|
+
async function supportConfigCommand() {
|
|
4023
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json', 'publish'] });
|
|
4024
|
+
const action = positionals[0] || 'get';
|
|
4025
|
+
if (!['get', 'set', 'publish', 'discard'].includes(action)) {
|
|
4026
|
+
console.log(SUPPORT_USAGE);
|
|
4027
|
+
process.exit(1);
|
|
4028
|
+
}
|
|
4029
|
+
const cfg = requireSignIn();
|
|
4030
|
+
const call = siteCall(cfg);
|
|
4031
|
+
const json = flags.json === true;
|
|
4032
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4033
|
+
const out = (res) => console.log(json ? JSON.stringify(res, null, 2) : renderConfig(res).join('\n'));
|
|
4034
|
+
try {
|
|
4035
|
+
if (action === 'get') return out(await configGet(call, { workspace }));
|
|
4036
|
+
if (action === 'publish') return out(await configPublish(call, { workspace }));
|
|
4037
|
+
if (action === 'discard') return out(await configDiscard(call, { workspace }));
|
|
4038
|
+
let changes = {};
|
|
4039
|
+
if (flags.set !== undefined) {
|
|
4040
|
+
if (typeof flags.set !== 'string') throw apiError(400, `Give --set a JSON object, such as '{"color":"#3e63dd"}'.`);
|
|
4041
|
+
try {
|
|
4042
|
+
changes = JSON.parse(flags.set);
|
|
4043
|
+
} catch {
|
|
4044
|
+
throw apiError(400, `--set is a JSON object, such as '{"color":"#3e63dd"}'.`);
|
|
4045
|
+
}
|
|
4046
|
+
}
|
|
4047
|
+
const text = (name) => (typeof flags[name] === 'string' ? flags[name] : undefined);
|
|
4048
|
+
changes = {
|
|
4049
|
+
...changes,
|
|
4050
|
+
name: text('name') ?? changes.name,
|
|
4051
|
+
color: text('color') ?? changes.color,
|
|
4052
|
+
greeting: text('greeting') ?? changes.greeting,
|
|
4053
|
+
intro: text('intro') ?? changes.intro,
|
|
4054
|
+
theme: text('theme') ?? changes.theme,
|
|
4055
|
+
position: text('position') ?? changes.position,
|
|
4056
|
+
origins: listFlag(flags.origins) ?? changes.origins,
|
|
4057
|
+
enabled: onOffFlag(flags.enabled, 'enabled') ?? changes.enabled,
|
|
4058
|
+
allowLink: onOffFlag(flags['allow-link'], 'allow-link') ?? changes.allowLink,
|
|
4059
|
+
};
|
|
4060
|
+
return out(await configSet(call, { workspace, changes, publish: flags.publish === true }));
|
|
4061
|
+
} catch (e) {
|
|
4062
|
+
supportFail(e);
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
|
|
4066
|
+
/**
|
|
4067
|
+
* `workover support style import <url> [--apply]`: "Import your style" for the Messenger, into the
|
|
4068
|
+
* editor's draft with --apply (support-config.mjs, WO-1752, S44).
|
|
4069
|
+
*/
|
|
4070
|
+
async function supportStyleCommand() {
|
|
4071
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json', 'apply'] });
|
|
4072
|
+
if (positionals[0] !== 'import' || !positionals[1]) {
|
|
4073
|
+
console.log(SUPPORT_USAGE);
|
|
4074
|
+
process.exit(1);
|
|
4075
|
+
}
|
|
4076
|
+
const cfg = requireSignIn();
|
|
4077
|
+
const call = siteCall(cfg);
|
|
4078
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4079
|
+
try {
|
|
4080
|
+
const res = await styleImport(call, { workspace, url: positionals[1], apply: flags.apply === true });
|
|
4081
|
+
console.log(flags.json === true ? JSON.stringify(res, null, 2) : renderStyleImport(res).join('\n'));
|
|
4082
|
+
} catch (e) {
|
|
4083
|
+
supportFail(e);
|
|
4084
|
+
}
|
|
4085
|
+
}
|
|
4086
|
+
|
|
4087
|
+
/**
|
|
4088
|
+
* `workover support walter [get|set|preview|publish|discard|changelog]`: Walter AI's Guidance Basics,
|
|
4089
|
+
* its draft, the preview and the Deploy checklist (support-walter.mjs, WO-1752, S57).
|
|
4090
|
+
*/
|
|
4091
|
+
async function supportWalterCommand() {
|
|
4092
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json', 'publish'] });
|
|
4093
|
+
const action = positionals[0] || 'get';
|
|
4094
|
+
if (!['get', 'set', 'preview', 'publish', 'discard', 'changelog'].includes(action)) {
|
|
4095
|
+
console.log(SUPPORT_USAGE);
|
|
4096
|
+
process.exit(1);
|
|
4097
|
+
}
|
|
4098
|
+
const cfg = requireSignIn();
|
|
4099
|
+
const call = siteCall(cfg);
|
|
4100
|
+
const json = flags.json === true;
|
|
4101
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4102
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4103
|
+
try {
|
|
4104
|
+
if (action === 'get') {
|
|
4105
|
+
const res = await walterGet(call, { workspace });
|
|
4106
|
+
return out(res, renderWalter(res));
|
|
4107
|
+
}
|
|
4108
|
+
if (action === 'publish') {
|
|
4109
|
+
const res = await walterPublish(call, { workspace });
|
|
4110
|
+
return out(res, renderWalter(res));
|
|
4111
|
+
}
|
|
4112
|
+
if (action === 'discard') {
|
|
4113
|
+
const res = await walterDiscard(call, { workspace });
|
|
4114
|
+
return out(res, renderWalter(res));
|
|
4115
|
+
}
|
|
4116
|
+
if (action === 'changelog') {
|
|
4117
|
+
const cursor = typeof flags.cursor === 'string' ? flags.cursor : undefined;
|
|
4118
|
+
const res = await walterChangelog(call, { workspace, cursor });
|
|
4119
|
+
return out(res, renderWalterChangelog(res));
|
|
4120
|
+
}
|
|
4121
|
+
if (action === 'preview') {
|
|
4122
|
+
const res = await walterPreview(call, { workspace, question: positionals.slice(1).join(' ') });
|
|
4123
|
+
return out(res, renderWalterPreview(res));
|
|
4124
|
+
}
|
|
4125
|
+
let changes = {};
|
|
4126
|
+
if (flags.set !== undefined) {
|
|
4127
|
+
if (typeof flags.set !== 'string') throw apiError(400, `Give --set a JSON object, such as '{"tone":"friendly"}'.`);
|
|
4128
|
+
try {
|
|
4129
|
+
changes = JSON.parse(flags.set);
|
|
4130
|
+
} catch {
|
|
4131
|
+
throw apiError(400, `--set is a JSON object, such as '{"tone":"friendly"}'.`);
|
|
4132
|
+
}
|
|
4133
|
+
}
|
|
4134
|
+
if (typeof flags.tone === 'string') changes.tone = flags.tone === 'none' ? null : flags.tone;
|
|
4135
|
+
if (typeof flags.length === 'string') changes.answerLength = flags.length === 'none' ? null : flags.length;
|
|
4136
|
+
const add = typeof flags['add-guidance'] === 'string' ? [flags['add-guidance']] : undefined;
|
|
4137
|
+
const res = await walterSet(call, { workspace, changes, addGuidance: add, publish: flags.publish === true });
|
|
4138
|
+
return out(res, renderWalter(res));
|
|
4139
|
+
} catch (e) {
|
|
4140
|
+
supportFail(e);
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
|
|
4144
|
+
/** `workover support sources ...`: Walter AI's sources (support-sources.mjs, WO-1752, S06b). */
|
|
4145
|
+
async function supportSourcesCommand() {
|
|
4146
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), {
|
|
4147
|
+
booleans: ['json', 'sitemap', 'on', 'off'],
|
|
4148
|
+
});
|
|
4149
|
+
const action = positionals[0] || 'list';
|
|
4150
|
+
if (!['list', 'add', 'pdf', 'set', 'sync', 'remove'].includes(action)) {
|
|
4151
|
+
console.log(SUPPORT_USAGE);
|
|
4152
|
+
process.exit(1);
|
|
4153
|
+
}
|
|
4154
|
+
const cfg = requireSignIn();
|
|
4155
|
+
const call = siteCall(cfg);
|
|
4156
|
+
const json = flags.json === true;
|
|
4157
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4158
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4159
|
+
const id = positionals[1];
|
|
4160
|
+
try {
|
|
4161
|
+
if (action === 'list') {
|
|
4162
|
+
const res = await listSources(call, { workspace });
|
|
4163
|
+
return out(res, renderSources(res));
|
|
4164
|
+
}
|
|
4165
|
+
if (action === 'add') {
|
|
4166
|
+
const project = flags.project;
|
|
4167
|
+
const res = await addSource(call, {
|
|
4168
|
+
workspace,
|
|
4169
|
+
kind: project !== undefined ? 'project' : flags.sitemap === true ? 'sitemap' : 'url',
|
|
4170
|
+
projectId: project,
|
|
4171
|
+
url: id,
|
|
4172
|
+
resyncHours: flags.resync,
|
|
4173
|
+
});
|
|
4174
|
+
return out(res, renderSourceAdded(res));
|
|
4175
|
+
}
|
|
4176
|
+
if (action === 'pdf') {
|
|
4177
|
+
if (!id) throw apiError(400, 'Give the PDF to upload: `workover support sources pdf <file>`.');
|
|
4178
|
+
let bytes;
|
|
4179
|
+
try {
|
|
4180
|
+
bytes = readFileSync(id);
|
|
4181
|
+
} catch {
|
|
4182
|
+
throw apiError(400, `Could not read ${id}.`);
|
|
4183
|
+
}
|
|
4184
|
+
const res = await addPdf(call, { workspace, name: id.split(/[\\/]/).pop(), bytes });
|
|
4185
|
+
return out(res, renderSourceAdded(res));
|
|
4186
|
+
}
|
|
4187
|
+
if (action === 'set') {
|
|
4188
|
+
if (flags.on === true && flags.off === true) throw apiError(400, 'Pass --on or --off, not both.');
|
|
4189
|
+
const res = await updateSource(call, {
|
|
4190
|
+
workspace,
|
|
4191
|
+
sourceId: id,
|
|
4192
|
+
enabled: flags.on === true ? true : flags.off === true ? false : undefined,
|
|
4193
|
+
resyncHours: flags.resync,
|
|
4194
|
+
});
|
|
4195
|
+
return out(res, ['', ' ✓ Saved.', ...renderSourceLine(res.source), '']);
|
|
4196
|
+
}
|
|
4197
|
+
if (action === 'sync') {
|
|
4198
|
+
const res = await syncSource(call, { workspace, sourceId: id });
|
|
4199
|
+
return out(res, [
|
|
4200
|
+
'',
|
|
4201
|
+
' ✓ Reading it again now. Run `workover support sources` for ready or failed.',
|
|
4202
|
+
...renderSourceLine(res.source),
|
|
4203
|
+
'',
|
|
4204
|
+
]);
|
|
4205
|
+
}
|
|
4206
|
+
const res = await removeSource(call, { workspace, sourceId: id });
|
|
4207
|
+
return out(res, renderSourceRemoved(res));
|
|
4208
|
+
} catch (e) {
|
|
4209
|
+
supportFail(e);
|
|
4210
|
+
}
|
|
4211
|
+
}
|
|
4212
|
+
|
|
4213
|
+
/** `workover support releases ...`: Walter AI's live version and Set live (support-agent-tests.mjs, WO-1752, S06c). */
|
|
4214
|
+
async function supportReleasesCommand() {
|
|
4215
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json'] });
|
|
4216
|
+
const action = positionals[0] || 'list';
|
|
4217
|
+
if (!['list', 'set-live', 'rollback'].includes(action)) {
|
|
4218
|
+
console.log(SUPPORT_USAGE);
|
|
4219
|
+
process.exit(1);
|
|
4220
|
+
}
|
|
4221
|
+
const cfg = requireSignIn();
|
|
4222
|
+
const call = siteCall(cfg);
|
|
4223
|
+
const json = flags.json === true;
|
|
4224
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4225
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4226
|
+
try {
|
|
4227
|
+
if (action === 'list') {
|
|
4228
|
+
const res = await listReleases(call, { workspace });
|
|
4229
|
+
return out(res, renderReleases(res));
|
|
4230
|
+
}
|
|
4231
|
+
if (action === 'set-live') {
|
|
4232
|
+
const res = await setLive(call, { workspace, note: typeof flags.note === 'string' ? flags.note : undefined });
|
|
4233
|
+
return out(res, renderSetLive(res));
|
|
4234
|
+
}
|
|
4235
|
+
const res = await rollback(call, { workspace, version: positionals[1] });
|
|
4236
|
+
return out(res, renderRollback(res));
|
|
4237
|
+
} catch (e) {
|
|
4238
|
+
supportFail(e);
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
4241
|
+
|
|
4242
|
+
/** `workover support tests ...`: Walter AI's batch test (support-agent-tests.mjs, WO-1752, S06c). */
|
|
4243
|
+
async function supportTestsCommand() {
|
|
4244
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json', 'live', 'wait'] });
|
|
4245
|
+
const action = positionals[0] || 'list';
|
|
4246
|
+
if (!['list', 'add', 'generate', 'remove', 'run', 'show', 'rate'].includes(action)) {
|
|
4247
|
+
console.log(SUPPORT_USAGE);
|
|
4248
|
+
process.exit(1);
|
|
4249
|
+
}
|
|
4250
|
+
const cfg = requireSignIn();
|
|
4251
|
+
const call = siteCall(cfg);
|
|
4252
|
+
const json = flags.json === true;
|
|
4253
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4254
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4255
|
+
const arg = positionals[1];
|
|
4256
|
+
try {
|
|
4257
|
+
if (action === 'list') {
|
|
4258
|
+
const res = await listTests(call, { workspace });
|
|
4259
|
+
return out(res, renderTests(res));
|
|
4260
|
+
}
|
|
4261
|
+
if (action === 'add') {
|
|
4262
|
+
let res;
|
|
4263
|
+
if (typeof flags.file === 'string') {
|
|
4264
|
+
let text;
|
|
4265
|
+
try {
|
|
4266
|
+
text = readFileSync(flags.file, 'utf8');
|
|
4267
|
+
} catch {
|
|
4268
|
+
throw apiError(400, `Could not read ${flags.file}.`);
|
|
4269
|
+
}
|
|
4270
|
+
res = await addTests(call, { workspace, text });
|
|
4271
|
+
} else {
|
|
4272
|
+
res = await addTests(call, {
|
|
4273
|
+
workspace,
|
|
4274
|
+
question: arg,
|
|
4275
|
+
expect: typeof flags.expect === 'string' ? flags.expect : undefined,
|
|
4276
|
+
});
|
|
4277
|
+
}
|
|
4278
|
+
return out(res, renderAdded(res));
|
|
4279
|
+
}
|
|
4280
|
+
if (action === 'generate') {
|
|
4281
|
+
const res = await generateTests(call, { workspace });
|
|
4282
|
+
return out(res, renderAdded(res));
|
|
4283
|
+
}
|
|
4284
|
+
if (action === 'remove') {
|
|
4285
|
+
const res = await removeTest(call, { workspace, testId: arg });
|
|
4286
|
+
return out(res, renderRemoved(res));
|
|
4287
|
+
}
|
|
4288
|
+
if (action === 'run') {
|
|
4289
|
+
const res = await runTests(call, {
|
|
4290
|
+
workspace,
|
|
4291
|
+
target: flags.live === true ? 'live' : 'draft',
|
|
4292
|
+
wait: flags.wait === true,
|
|
4293
|
+
waitMs: 600_000,
|
|
4294
|
+
});
|
|
4295
|
+
return out(res, renderRunStarted(res));
|
|
4296
|
+
}
|
|
4297
|
+
if (action === 'show') {
|
|
4298
|
+
const res = await getRun(call, { workspace, runId: arg });
|
|
4299
|
+
return out(res, ['', ...renderRun(res.run), '']);
|
|
4300
|
+
}
|
|
4301
|
+
const res = await rateResult(call, {
|
|
4302
|
+
workspace,
|
|
4303
|
+
resultId: arg,
|
|
4304
|
+
rating: positionals[2],
|
|
4305
|
+
note: typeof flags.note === 'string' ? flags.note : undefined,
|
|
4306
|
+
});
|
|
4307
|
+
return out(res, renderRated(res));
|
|
4308
|
+
} catch (e) {
|
|
4309
|
+
supportFail(e);
|
|
4310
|
+
}
|
|
4311
|
+
}
|
|
4312
|
+
|
|
4313
|
+
/** `workover support labels ...`: Support settings > Labels (support-labels.mjs, WO-1752, S63). */
|
|
4314
|
+
async function supportLabelsCommand() {
|
|
4315
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), {
|
|
4316
|
+
booleans: ['json', 'archive', 'restore'],
|
|
4317
|
+
});
|
|
4318
|
+
const action = positionals[0] || 'list';
|
|
4319
|
+
if (!['list', 'add', 'set', 'merge'].includes(action)) {
|
|
4320
|
+
console.log(SUPPORT_USAGE);
|
|
4321
|
+
process.exit(1);
|
|
4322
|
+
}
|
|
4323
|
+
const cfg = requireSignIn();
|
|
4324
|
+
const call = siteCall(cfg);
|
|
4325
|
+
const json = flags.json === true;
|
|
4326
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4327
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4328
|
+
try {
|
|
4329
|
+
if (action === 'list') {
|
|
4330
|
+
const res = await listLabels(call, { workspace });
|
|
4331
|
+
return out(res, renderLabels(res));
|
|
4332
|
+
}
|
|
4333
|
+
if (action === 'add') {
|
|
4334
|
+
const res = await createLabel(call, {
|
|
4335
|
+
workspace,
|
|
4336
|
+
name: positionals[1],
|
|
4337
|
+
inside: typeof flags.inside === 'string' ? flags.inside : undefined,
|
|
4338
|
+
color: typeof flags.color === 'string' ? flags.color : undefined,
|
|
4339
|
+
});
|
|
4340
|
+
return out(res, renderLabelSaved(res.label, res.created ? 'Added' : 'Already there'));
|
|
4341
|
+
}
|
|
4342
|
+
if (action === 'set') {
|
|
4343
|
+
if (flags.archive === true && flags.restore === true) throw apiError(400, 'Pass --archive or --restore, not both.');
|
|
4344
|
+
const res = await updateLabel(call, {
|
|
4345
|
+
workspace,
|
|
4346
|
+
label: positionals[1],
|
|
4347
|
+
name: typeof flags.name === 'string' ? flags.name : undefined,
|
|
4348
|
+
color: typeof flags.color === 'string' ? flags.color : undefined,
|
|
4349
|
+
archived: flags.archive === true ? true : flags.restore === true ? false : undefined,
|
|
4350
|
+
});
|
|
4351
|
+
return out(res, renderLabelSaved(res.label));
|
|
4352
|
+
}
|
|
4353
|
+
const res = await mergeLabels(call, { workspace, into: positionals[1], from: listFlag(flags.from) });
|
|
4354
|
+
return out(res, renderLabelMerged(res));
|
|
4355
|
+
} catch (e) {
|
|
4356
|
+
supportFail(e);
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
|
|
4360
|
+
/** `workover support fields ...`: Support settings > Conversation fields (support-fields.mjs, WO-1752, S38). */
|
|
4361
|
+
async function supportFieldsCommand() {
|
|
4362
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json'] });
|
|
4363
|
+
const action = positionals[0] || 'list';
|
|
4364
|
+
if (!['list', 'set', 'remove', 'order', 'show', 'fill'].includes(action)) {
|
|
4365
|
+
console.log(SUPPORT_USAGE);
|
|
4366
|
+
process.exit(1);
|
|
4367
|
+
}
|
|
4368
|
+
const cfg = requireSignIn();
|
|
4369
|
+
const call = siteCall(cfg);
|
|
4370
|
+
const json = flags.json === true;
|
|
4371
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4372
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4373
|
+
try {
|
|
4374
|
+
if (action === 'list') {
|
|
4375
|
+
const res = await listFields(call, { workspace });
|
|
4376
|
+
return out(res, renderFields(res));
|
|
4377
|
+
}
|
|
4378
|
+
if (action === 'set') {
|
|
4379
|
+
const res = await setField(call, {
|
|
4380
|
+
workspace,
|
|
4381
|
+
label: positionals[1],
|
|
4382
|
+
type: typeof flags.type === 'string' ? flags.type : 'text',
|
|
4383
|
+
options: typeof flags.options === 'string' ? flags.options : undefined,
|
|
4384
|
+
key: typeof flags.key === 'string' ? flags.key : undefined,
|
|
4385
|
+
position: typeof flags.position === 'string' ? flags.position : undefined,
|
|
4386
|
+
});
|
|
4387
|
+
return out(res, renderFieldSaved(res));
|
|
4388
|
+
}
|
|
4389
|
+
if (action === 'remove') {
|
|
4390
|
+
const res = await removeField(call, { workspace, field: positionals[1] });
|
|
4391
|
+
return out(res, renderFieldRemoved(res));
|
|
4392
|
+
}
|
|
4393
|
+
if (action === 'order') {
|
|
4394
|
+
const res = await orderFields(call, { workspace, fields: positionals.slice(1).join(',') });
|
|
4395
|
+
return out(res, renderFields(res));
|
|
4396
|
+
}
|
|
4397
|
+
if (action === 'show') {
|
|
4398
|
+
const res = await conversationFields(call, { conversation: positionals[1] });
|
|
4399
|
+
return out(res, renderConversationFields(res));
|
|
4400
|
+
}
|
|
4401
|
+
const res = await setConversationFields(call, { conversation: positionals[1], values: positionals.slice(2) });
|
|
4402
|
+
return out(res, renderConversationFields(res));
|
|
4403
|
+
} catch (e) {
|
|
4404
|
+
supportFail(e);
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
|
|
4408
|
+
/**
|
|
4409
|
+
* `workover support signatures ...`: Support settings > Email > Email signatures
|
|
4410
|
+
* (support-signatures.mjs, WO-1752, S10b).
|
|
4411
|
+
*/
|
|
4412
|
+
async function supportSignaturesCommand() {
|
|
4413
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json', 'clear'] });
|
|
4414
|
+
const action = positionals[0] || 'list';
|
|
4415
|
+
if (!['list', 'set', 'preview'].includes(action)) {
|
|
4416
|
+
console.log(SUPPORT_USAGE);
|
|
4417
|
+
process.exit(1);
|
|
4418
|
+
}
|
|
4419
|
+
const cfg = requireSignIn();
|
|
4420
|
+
const call = siteCall(cfg);
|
|
4421
|
+
const json = flags.json === true;
|
|
4422
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4423
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4424
|
+
const html = () => {
|
|
4425
|
+
if (flags.clear === true) return '';
|
|
4426
|
+
if (typeof flags.file === 'string') return readFileSync(flags.file, 'utf8');
|
|
4427
|
+
if (typeof flags.html === 'string') return flags.html;
|
|
4428
|
+
throw apiError(400, 'Give the signature with --html "<text or html>" or --file <path> (or --clear to remove it).');
|
|
4429
|
+
};
|
|
4430
|
+
try {
|
|
4431
|
+
if (action === 'list') {
|
|
4432
|
+
const res = await getSignatures(call, { workspace });
|
|
4433
|
+
return out(res, renderSignatures(res));
|
|
4434
|
+
}
|
|
4435
|
+
if (action === 'set') {
|
|
4436
|
+
const res = await setSignature(call, { workspace, which: positionals[1], html: html() });
|
|
4437
|
+
return out(res, renderSignatureSaved(res));
|
|
4438
|
+
}
|
|
4439
|
+
const res = await previewSignature(call, { workspace, html: html() });
|
|
4440
|
+
return out(res, renderSignaturePreview(res));
|
|
4441
|
+
} catch (e) {
|
|
4442
|
+
supportFail(e);
|
|
4443
|
+
}
|
|
4444
|
+
}
|
|
4445
|
+
|
|
4446
|
+
/**
|
|
4447
|
+
* `workover support email ...`: Support settings > Email, the follow-ups (support-email.mjs,
|
|
4448
|
+
* WO-1752, admin walk at real widths, M3). No flag reads; flags set only what they name.
|
|
4449
|
+
*/
|
|
4450
|
+
/** The `support email` lines of SUPPORT_USAGE, for `workover support email --help`. */
|
|
4451
|
+
function supportEmailUsage() {
|
|
4452
|
+
const lines = [];
|
|
4453
|
+
let inEmail = false;
|
|
4454
|
+
for (const line of SUPPORT_USAGE.split('\n')) {
|
|
4455
|
+
if (/^ \S/.test(line)) inEmail = /^ email /.test(line);
|
|
4456
|
+
if (inEmail) lines.push(line);
|
|
4457
|
+
}
|
|
4458
|
+
return ['', ' Usage: workover support email [--workspace <slug|id>] [--json]', '', ...lines, ''].join('\n');
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
async function supportEmailCommand() {
|
|
4462
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), {
|
|
4463
|
+
booleans: ['json', 'on', 'off', 'verified-only', 'any-email', 'remove', 'help', 'stop'],
|
|
4464
|
+
});
|
|
4465
|
+
const action = positionals[0] || 'settings';
|
|
4466
|
+
// `--help` / `help` prints this command's usage without needing a workspace (journey "Visitor
|
|
4467
|
+
// gets an answer" r2, m12: it answered "Which workspace?").
|
|
4468
|
+
if (flags.help === true || action === 'help') {
|
|
4469
|
+
console.log(supportEmailUsage());
|
|
4470
|
+
process.exit(0);
|
|
4471
|
+
}
|
|
4472
|
+
if (!['settings', 'do-not-email', 'test', 'domains', 'domain', 'new-emails'].includes(action)) {
|
|
4473
|
+
console.log(SUPPORT_USAGE);
|
|
4474
|
+
process.exit(1);
|
|
4475
|
+
}
|
|
4476
|
+
const cfg = requireSignIn();
|
|
4477
|
+
const call = siteCall(cfg);
|
|
4478
|
+
const json = flags.json === true;
|
|
4479
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4480
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4481
|
+
try {
|
|
4482
|
+
if (action === 'test') {
|
|
4483
|
+
const res = await sendTestEmail(call, { workspace });
|
|
4484
|
+
return out(res, renderTestEmail(res));
|
|
4485
|
+
}
|
|
4486
|
+
if (action === 'domains') {
|
|
4487
|
+
const res = await listDomains(call, { workspace });
|
|
4488
|
+
return out(res, renderDomains(res));
|
|
4489
|
+
}
|
|
4490
|
+
if (action === 'domain') {
|
|
4491
|
+
const verb = positionals[1];
|
|
4492
|
+
if ((verb === 'receives' || verb === 'bounce') && flags.on === true && flags.off === true)
|
|
4493
|
+
throw apiError(400, 'Choose one: --on or --off.');
|
|
4494
|
+
const res = await domainAction(call, {
|
|
4495
|
+
workspace,
|
|
4496
|
+
action: verb,
|
|
4497
|
+
domain: positionals[2],
|
|
4498
|
+
local: verb === 'forward' ? (flags.stop === true ? null : positionals[3]) : undefined,
|
|
4499
|
+
on: flags.on === true ? true : flags.off === true ? false : undefined,
|
|
4500
|
+
});
|
|
4501
|
+
return out(res, renderDomainAction(res));
|
|
4502
|
+
}
|
|
4503
|
+
if (action === 'new-emails') {
|
|
4504
|
+
const res = await setNewEmailsDefault(call, { workspace, newEmails: positionals[1] });
|
|
4505
|
+
return out(res, ['', ` ✓ New emails by default: ${res.newEmailsDefault === 'support' ? 'Into Support' : 'Not taken'}.`, '']);
|
|
4506
|
+
}
|
|
4507
|
+
if (action === 'do-not-email') {
|
|
4508
|
+
const res = await doNotEmail(call, { workspace, email: positionals[1], remove: flags.remove === true });
|
|
4509
|
+
return out(res, renderDoNotEmail(res));
|
|
4510
|
+
}
|
|
4511
|
+
if (flags.on === true && flags.off === true) throw apiError(400, 'Choose one: --on or --off.');
|
|
4512
|
+
if (flags['verified-only'] === true && flags['any-email'] === true)
|
|
4513
|
+
throw apiError(400, 'Choose one: --verified-only or --any-email.');
|
|
4514
|
+
const text = (v) => (v === true ? '' : typeof v === 'string' ? v : undefined);
|
|
4515
|
+
const res = await setEmail(call, {
|
|
4516
|
+
workspace,
|
|
4517
|
+
enabled: flags.on === true ? true : flags.off === true ? false : undefined,
|
|
4518
|
+
wait: typeof flags.wait === 'string' ? flags.wait : undefined,
|
|
4519
|
+
onlyVerified: flags['verified-only'] === true ? true : flags['any-email'] === true ? false : undefined,
|
|
4520
|
+
fromName: text(flags['from-name']),
|
|
4521
|
+
replyTo: text(flags['reply-to']),
|
|
4522
|
+
askEmail: typeof flags['ask-email'] === 'string' ? flags['ask-email'] : undefined,
|
|
4523
|
+
sentFrom: typeof flags['sent-from'] === 'string' ? flags['sent-from'] : undefined,
|
|
4524
|
+
address: typeof flags.address === 'string' ? flags.address : undefined,
|
|
4525
|
+
newEmails: typeof flags['new-emails'] === 'string' ? flags['new-emails'] : undefined,
|
|
4526
|
+
});
|
|
4527
|
+
return out(res, res.changed ? renderEmailSaved(res) : renderEmail(res));
|
|
4528
|
+
} catch (e) {
|
|
4529
|
+
supportFail(e);
|
|
4530
|
+
}
|
|
4531
|
+
}
|
|
4532
|
+
|
|
4533
|
+
/**
|
|
4534
|
+
* `workover support sla | assignment | away`: reply targets, auto-assignment and your own
|
|
4535
|
+
* availability (support-inbox.mjs, WO-1752, S08). No flag reads; flags set only what they name.
|
|
4536
|
+
*/
|
|
4537
|
+
async function supportInboxCommand(sub) {
|
|
4538
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json'] });
|
|
4539
|
+
const cfg = requireSignIn();
|
|
4540
|
+
const call = siteCall(cfg);
|
|
4541
|
+
const json = flags.json === true;
|
|
4542
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4543
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4544
|
+
try {
|
|
4545
|
+
if (sub === 'sla') {
|
|
4546
|
+
const holidays = flags.holidays === 'none' ? [] : flags.holidays;
|
|
4547
|
+
const res = await supportSla(call, {
|
|
4548
|
+
workspace,
|
|
4549
|
+
firstTarget: flags.first,
|
|
4550
|
+
nextTarget: flags.next,
|
|
4551
|
+
holidays,
|
|
4552
|
+
tiers: flags.tiers,
|
|
4553
|
+
breachWarnings: flags.warnings,
|
|
4554
|
+
});
|
|
4555
|
+
return out(res, renderSla(res));
|
|
4556
|
+
}
|
|
4557
|
+
if (sub === 'assignment') {
|
|
4558
|
+
const res = await supportAssignment(call, {
|
|
4559
|
+
workspace,
|
|
4560
|
+
autoAssign: flags.mode,
|
|
4561
|
+
capacity: flags.capacity,
|
|
4562
|
+
pool: flags.pool,
|
|
4563
|
+
claimOnWrite: flags.claim,
|
|
4564
|
+
});
|
|
4565
|
+
return out(res, renderAssignment(res));
|
|
4566
|
+
}
|
|
4567
|
+
const res = await supportAvailability(call, { workspace, away: positionals[0] });
|
|
4568
|
+
return out(res, renderAvailability(res));
|
|
4569
|
+
} catch (e) {
|
|
4570
|
+
supportFail(e);
|
|
4571
|
+
}
|
|
4572
|
+
}
|
|
4573
|
+
|
|
4574
|
+
/** `workover support label-rules ...`: when the AI adds each label (support-label-rules.mjs, WO-1752, S09). */
|
|
4575
|
+
async function supportLabelRulesCommand() {
|
|
4576
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json', 'on', 'off'] });
|
|
4577
|
+
const action = positionals[0] || 'list';
|
|
4578
|
+
if (!['list', 'set', 'remove'].includes(action)) {
|
|
4579
|
+
console.log(SUPPORT_USAGE);
|
|
4580
|
+
process.exit(1);
|
|
4581
|
+
}
|
|
4582
|
+
const cfg = requireSignIn();
|
|
4583
|
+
const call = siteCall(cfg);
|
|
4584
|
+
const json = flags.json === true;
|
|
4585
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4586
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4587
|
+
const label = positionals[1];
|
|
4588
|
+
try {
|
|
4589
|
+
if (action === 'list') {
|
|
4590
|
+
const res = await listLabelRules(call, { workspace });
|
|
4591
|
+
return out(res, renderLabelRules(res));
|
|
4592
|
+
}
|
|
4593
|
+
if (action === 'set') {
|
|
4594
|
+
if (flags.on === true && flags.off === true) throw apiError(400, 'Pass --on or --off, not both.');
|
|
4595
|
+
const res = await setLabelRule(call, {
|
|
4596
|
+
workspace,
|
|
4597
|
+
label,
|
|
4598
|
+
instruction: typeof flags.when === 'string' ? flags.when : undefined,
|
|
4599
|
+
enabled: flags.on === true ? true : flags.off === true ? false : undefined,
|
|
4600
|
+
});
|
|
4601
|
+
return out(res, renderLabelRuleSet(res));
|
|
4602
|
+
}
|
|
4603
|
+
const res = await removeLabelRule(call, { workspace, label });
|
|
4604
|
+
return out(res, renderLabelRuleRemoved(res));
|
|
4605
|
+
} catch (e) {
|
|
4606
|
+
supportFail(e);
|
|
4607
|
+
}
|
|
4608
|
+
}
|
|
4609
|
+
|
|
4610
|
+
/** `workover support outside-bot ...`: the outside bot that answers first (support-outside-bot.mjs, WO-1752, S14). */
|
|
4611
|
+
async function supportOutsideBotCommand() {
|
|
4612
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json', 'on', 'off', 'remove-key'] });
|
|
4613
|
+
const action = positionals[0] || 'show';
|
|
4614
|
+
if (!['show', 'set', 'check'].includes(action)) {
|
|
4615
|
+
console.log(SUPPORT_USAGE);
|
|
4616
|
+
process.exit(1);
|
|
4617
|
+
}
|
|
4618
|
+
const cfg = requireSignIn();
|
|
4619
|
+
const call = siteCall(cfg);
|
|
4620
|
+
const json = flags.json === true;
|
|
4621
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4622
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4623
|
+
const text = (k) => (typeof flags[k] === 'string' ? flags[k] : undefined);
|
|
4624
|
+
const num = (k) => {
|
|
4625
|
+
const v = text(k);
|
|
4626
|
+
if (v === undefined) return undefined;
|
|
4627
|
+
const n = Number(v);
|
|
4628
|
+
if (!Number.isFinite(n)) throw apiError(400, `--${k} takes a number.`);
|
|
4629
|
+
return n;
|
|
4630
|
+
};
|
|
4631
|
+
try {
|
|
4632
|
+
if (action === 'show') {
|
|
4633
|
+
const res = await getOutsideBot(call, { workspace });
|
|
4634
|
+
return out(res, renderOutsideBot(res));
|
|
4635
|
+
}
|
|
4636
|
+
if (action === 'check') {
|
|
4637
|
+
const res = await checkOutsideBot(call, { workspace });
|
|
4638
|
+
out(res, renderOutsideBotCheck(res));
|
|
4639
|
+
if (!res.ok) process.exit(1);
|
|
4640
|
+
return;
|
|
4641
|
+
}
|
|
4642
|
+
if (flags.on === true && flags.off === true) throw apiError(400, 'Pass --on or --off, not both.');
|
|
4643
|
+
let key;
|
|
4644
|
+
if (flags['remove-key'] === true) key = null;
|
|
4645
|
+
else if (text('key-env')) {
|
|
4646
|
+
key = process.env[text('key-env')];
|
|
4647
|
+
if (!key) throw apiError(400, `The environment variable ${text('key-env')} is empty.`);
|
|
4648
|
+
} else if (text('key')) throw apiError(400, 'Pass the key with --key-env <VAR>, so it stays out of your shell history.');
|
|
4649
|
+
const res = await setOutsideBot(call, {
|
|
4650
|
+
workspace,
|
|
4651
|
+
key,
|
|
4652
|
+
url: text('url'),
|
|
4653
|
+
keyHeader: text('key-header'),
|
|
4654
|
+
name: text('name'),
|
|
4655
|
+
persona: text('persona'),
|
|
4656
|
+
when: text('when'),
|
|
4657
|
+
minConfidence: num('min'),
|
|
4658
|
+
perMinute: num('per-minute'),
|
|
4659
|
+
burst: num('burst'),
|
|
4660
|
+
enabled: flags.on === true ? true : flags.off === true ? false : undefined,
|
|
4661
|
+
});
|
|
4662
|
+
return out(res, renderOutsideBot(res));
|
|
4663
|
+
} catch (e) {
|
|
4664
|
+
supportFail(e);
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
|
|
4668
|
+
/** `workover support outcomes ...`: Walter AI's outcome ledger (support-outcomes.mjs, WO-1752, S65). */
|
|
4669
|
+
async function supportOutcomesCommand() {
|
|
4670
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json', 'csv'] });
|
|
4671
|
+
const action = positionals[0] || 'list';
|
|
4672
|
+
if (!['list', 'mark', 'clear', 'usage'].includes(action)) {
|
|
4673
|
+
console.log(SUPPORT_USAGE);
|
|
4674
|
+
process.exit(1);
|
|
4675
|
+
}
|
|
4676
|
+
const cfg = requireSignIn();
|
|
4677
|
+
const call = siteCall(cfg);
|
|
4678
|
+
const json = flags.json === true;
|
|
4679
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4680
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4681
|
+
const text = (k) => (typeof flags[k] === 'string' ? flags[k] : undefined);
|
|
4682
|
+
try {
|
|
4683
|
+
if (action === 'usage') {
|
|
4684
|
+
const res = await getOutcomeUsage(call, { workspace });
|
|
4685
|
+
return out(res, renderOutcomeUsage(res));
|
|
4686
|
+
}
|
|
4687
|
+
if (action === 'mark') {
|
|
4688
|
+
const res = await markOutcome(call, { workspace, conversation: positionals[1], reason: text('reason') });
|
|
4689
|
+
return out(res, renderOutcomeMark(res));
|
|
4690
|
+
}
|
|
4691
|
+
if (action === 'clear') {
|
|
4692
|
+
const res = await clearOutcome(call, { workspace, conversation: positionals[1] });
|
|
4693
|
+
return out(res, renderOutcomeMark(res));
|
|
4694
|
+
}
|
|
4695
|
+
const filters = { workspace, outcome: text('outcome'), from: text('from'), to: text('to') };
|
|
4696
|
+
if (flags.csv === true) {
|
|
4697
|
+
const res = await listOutcomes(call, { ...filters, all: true });
|
|
4698
|
+
process.stdout.write(outcomesCsv(res.rows));
|
|
4699
|
+
if (res.truncated) console.error(' Only the first 10,000 rows: narrow it with --from and --to.');
|
|
4700
|
+
return;
|
|
4701
|
+
}
|
|
4702
|
+
const res = await listOutcomes(call, { ...filters, cursor: text('cursor') });
|
|
4703
|
+
return out(res, renderOutcomes(res));
|
|
4704
|
+
} catch (e) {
|
|
4705
|
+
supportFail(e);
|
|
4706
|
+
}
|
|
4707
|
+
}
|
|
4708
|
+
|
|
4709
|
+
/** `workover support freshdesk ...`: Freshdesk escalation setup (support-freshdesk.mjs, WO-1752, S18). */
|
|
4710
|
+
async function supportFreshdeskCommand() {
|
|
4711
|
+
const { flags, positionals } = parseArgs(process.argv.slice(4), { booleans: ['json'] });
|
|
4712
|
+
const action = positionals[0] || 'show';
|
|
4713
|
+
if (!['show', 'set', 'check', 'remove'].includes(action)) {
|
|
4714
|
+
console.log(SUPPORT_USAGE);
|
|
4715
|
+
process.exit(1);
|
|
4716
|
+
}
|
|
4717
|
+
const cfg = requireSignIn();
|
|
4718
|
+
const call = siteCall(cfg);
|
|
4719
|
+
const json = flags.json === true;
|
|
4720
|
+
const workspace = typeof flags.workspace === 'string' ? flags.workspace : undefined;
|
|
4721
|
+
const out = (res, lines) => console.log(json ? JSON.stringify(res, null, 2) : lines.join('\n'));
|
|
4722
|
+
const onOff = (v, name) => {
|
|
4723
|
+
if (v === undefined) return undefined;
|
|
4724
|
+
if (v === 'on') return true;
|
|
4725
|
+
if (v === 'off') return false;
|
|
4726
|
+
throw apiError(400, `--${name} is on or off.`);
|
|
4727
|
+
};
|
|
4728
|
+
try {
|
|
4729
|
+
if (action === 'show') {
|
|
4730
|
+
const res = await getFreshdesk(call, { workspace });
|
|
4731
|
+
return out(res, renderFreshdesk(res));
|
|
4732
|
+
}
|
|
4733
|
+
if (action === 'check') {
|
|
4734
|
+
const res = await checkFreshdesk(call, { workspace });
|
|
4735
|
+
return out(res, renderFreshdeskCheck(res));
|
|
4736
|
+
}
|
|
4737
|
+
if (action === 'remove') {
|
|
4738
|
+
const res = await removeFreshdesk(call, { workspace });
|
|
4739
|
+
return out(res, renderFreshdeskRemoved(res));
|
|
4740
|
+
}
|
|
4741
|
+
// The key never goes on the command line, where shell history and `ps` would keep it.
|
|
4742
|
+
if (flags.key !== undefined) throw apiError(400, 'Pass the key with --key-file <file> or FRESHDESK_API_KEY, never on the command line.');
|
|
4743
|
+
let apiKey;
|
|
4744
|
+
if (typeof flags['key-file'] === 'string') apiKey = readFileSync(flags['key-file'], 'utf8').trim();
|
|
4745
|
+
else if (process.env.FRESHDESK_API_KEY) apiKey = process.env.FRESHDESK_API_KEY.trim();
|
|
4746
|
+
const res = await setFreshdesk(call, {
|
|
4747
|
+
workspace,
|
|
4748
|
+
domain: typeof flags.domain === 'string' ? flags.domain : undefined,
|
|
4749
|
+
apiKey,
|
|
4750
|
+
mode: typeof flags.mode === 'string' ? flags.mode : undefined,
|
|
4751
|
+
priority: typeof flags.priority === 'string' ? flags.priority : undefined,
|
|
4752
|
+
groupId: typeof flags.group === 'string' ? flags.group : undefined,
|
|
4753
|
+
tags: typeof flags.tags === 'string' ? flags.tags : undefined,
|
|
4754
|
+
closeAfter: onOff(typeof flags['close-after'] === 'string' ? flags['close-after'] : undefined, 'close-after'),
|
|
4755
|
+
});
|
|
4756
|
+
return out(res, renderFreshdesk(res));
|
|
4757
|
+
} catch (e) {
|
|
4758
|
+
supportFail(e);
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4761
|
+
|
|
2480
4762
|
async function feedbackCommand() {
|
|
2481
4763
|
const { flags } = parseArgs(process.argv.slice(3), { booleans: ['json'] });
|
|
2482
4764
|
if (!['summary', 'intent', 'problem'].every((k) => typeof flags[k] === 'string' && flags[k].trim())) {
|
|
@@ -2543,8 +4825,14 @@ else if (cmd === 'comments') await commentsCommand();
|
|
|
2543
4825
|
else if (cmd === 'projects') await projects();
|
|
2544
4826
|
else if (cmd === 'status') await status();
|
|
2545
4827
|
else if (cmd === 'project') await projectCommand();
|
|
4828
|
+
else if (cmd === 'media') await mediaCommand();
|
|
2546
4829
|
else if (cmd === 'site') await siteCommand();
|
|
4830
|
+
else if (cmd === 'support') await supportCommand();
|
|
2547
4831
|
else if (cmd === 'feedback') await feedbackCommand();
|
|
4832
|
+
else if (cmd === 'requests') await requestsCommand();
|
|
4833
|
+
else if (cmd === 'contacts') await contactsCommand();
|
|
4834
|
+
else if (cmd === 'domains') await domainsCommand();
|
|
4835
|
+
else if (cmd === 'email') await emailCommand();
|
|
2548
4836
|
else if (cmd === 'install-claude') installClaude();
|
|
2549
4837
|
else {
|
|
2550
4838
|
console.log('\n Workover CLI\n');
|
|
@@ -2555,6 +4843,8 @@ else {
|
|
|
2555
4843
|
console.log(' --write also allow direct edits (no suggestions to review)');
|
|
2556
4844
|
console.log(' --rules also allow changing the style guide');
|
|
2557
4845
|
console.log(' --site also allow setting up and publishing a Help Center');
|
|
4846
|
+
console.log(' --support also allow setting up Workover Support and its Messenger');
|
|
4847
|
+
console.log(' --contacts also allow reading and updating contacts and their server keys');
|
|
2558
4848
|
console.log(' --client "<name>" what to call this token in your history');
|
|
2559
4849
|
console.log(' --no-wait print the code and link and return at once (for agents);');
|
|
2560
4850
|
console.log(' finish with `workover login --resume` once it is approved');
|
|
@@ -2573,6 +4863,8 @@ else {
|
|
|
2573
4863
|
console.log(' rules The style guide agents should write by: list, export, add');
|
|
2574
4864
|
console.log(' workover rules export --project 11 >> AGENTS.md');
|
|
2575
4865
|
console.log(' projects List the projects you can reach, with their ids and workspaces');
|
|
4866
|
+
console.log(' media A project\u2019s Media library: list (usage, alt, problems), replace');
|
|
4867
|
+
console.log(' workover media list 11 --filter missing_alt');
|
|
2576
4868
|
console.log(' status Where a project’s setup has got to, and what is left to do');
|
|
2577
4869
|
console.log(' workover status 11 [--json]');
|
|
2578
4870
|
console.log(' project create: a new project that publishes to a Workover Help Center');
|
|
@@ -2580,6 +4872,10 @@ else {
|
|
|
2580
4872
|
console.log(' site Set up a Help Center: create, import, domain, check, publish, status');
|
|
2581
4873
|
console.log(' workover site domain --project 11 --set docs.example.com');
|
|
2582
4874
|
console.log(' (project and site need `workover login --site`)');
|
|
4875
|
+
console.log(' support Set up Support: status, setup, step, install, secret, test, notifications,');
|
|
4876
|
+
console.log(' home, thread, sources, releases, tests, config');
|
|
4877
|
+
console.log(' workover support setup --origins https://example.com');
|
|
4878
|
+
console.log(' (needs `workover login --support`)');
|
|
2583
4879
|
console.log(' draft Queue a draft in Workover and wait for it');
|
|
2584
4880
|
console.log(' --type tutorial|how-to|reference|explanation');
|
|
2585
4881
|
console.log(' draft-set Plan a feature’s whole documentation set, then draft each article');
|
|
@@ -2587,6 +4883,17 @@ else {
|
|
|
2587
4883
|
console.log(' --org <id> --project <id> [--limit N] [--json]');
|
|
2588
4884
|
console.log(' feedback Tell the Workover team a command or tool fell short (files an issue)');
|
|
2589
4885
|
console.log(' workover feedback --summary "..." --intent "..." --problem "..." --fix "..."');
|
|
4886
|
+
console.log(' requests The Feedback board: list, get, add, vote, status (tells voters)');
|
|
4887
|
+
console.log(' workover requests status 12 shipped --preview');
|
|
4888
|
+
console.log(' contacts The people your workspace keeps: list, get, identify (one, or a JSON/CSV file),');
|
|
4889
|
+
console.log(' attrs (list, add, rename, archive, restore), keys (list, create, revoke),');
|
|
4890
|
+
console.log(' track (one event, or a JSON/CSV file), events <contact>, event-names');
|
|
4891
|
+
console.log(' workover contacts identify --file people.csv (needs `workover login --contacts`)');
|
|
4892
|
+
console.log(' domains The domains your workspace sends email from: list, add (prints the DNS records),');
|
|
4893
|
+
console.log(' show, check, records (--format bind|json|text), share, remove, and addresses');
|
|
4894
|
+
console.log(' workover domains add acme.com (needs `workover login --contacts`)');
|
|
4895
|
+
console.log(' email Emails designed in blocks: blocks (what each takes), render, preview');
|
|
4896
|
+
console.log(' workover email preview --file email.json --contact x:42 (needs `workover login --contacts`)');
|
|
2590
4897
|
console.log(' logout Sign out and revoke this device’s token');
|
|
2591
4898
|
console.log(' whoami Show who is signed in, where, and their workspaces [--json]');
|
|
2592
4899
|
console.log(' install-claude Teach Claude Code to open Workover links (installs a skill)\n');
|