@jinshuju/cli 0.14.0 → 0.16.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.
@@ -1,9 +1,576 @@
1
- import { call } from '../spec.js';
1
+ import { PAGINATION_OPTIONS, UsageError } from '../options.js';
2
+ import { progress } from '../progress.js';
3
+ import { bodyChoices, call, choices } from '../spec.js';
4
+ import { confirmed, ESTIMATE_OPTION, estimating, FORM_OPTION, given, LISTING, NARROWING_OPTIONS, narrowingBody, narrowingQuery, paging, requiredOption as required, SELECT_ALL_OPTION, selectAll, SEND_OPTION, sendingConfirmed, YES_OPTION } from './shared.js';
5
+ import { upload } from './upload.js';
6
+ import { basename } from 'node:path';
7
+ /**
8
+ * A signature is applied for with license images, which go up first as the
9
+ * caller's own uploads and are then referred to by id. The review takes a
10
+ * business license and both sides of the ID card of whoever is in charge.
11
+ */
12
+ const SIGNATURE_OPTIONS = [
13
+ {
14
+ name: '--license',
15
+ type: 'string',
16
+ repeatable: true,
17
+ placeholder: '<file>',
18
+ description: 'Business license image (jpg, png or bmp, up to 5 MB), repeatable'
19
+ },
20
+ { name: '--company-name', type: 'string', placeholder: '<name>', description: 'Company name, as on the license' },
21
+ {
22
+ name: '--company-id',
23
+ type: 'string',
24
+ placeholder: '<code>',
25
+ description: 'Unified social credit code, as on the license'
26
+ },
27
+ {
28
+ name: '--id-card-front',
29
+ type: 'string',
30
+ placeholder: '<file>',
31
+ description: 'ID card front (the national emblem side)'
32
+ },
33
+ { name: '--id-card-back', type: 'string', placeholder: '<file>', description: 'ID card back (the portrait side)' },
34
+ { name: '--id-card-name', type: 'string', placeholder: '<name>', description: 'Name on the ID card' },
35
+ { name: '--id-card-number', type: 'string', placeholder: '<number>', description: 'ID card number' },
36
+ { name: '--mobile', type: 'string', placeholder: '<mobile>', description: 'Mobile number of the ID card holder' }
37
+ ];
38
+ /** The flags that go as they are, by the key the API takes each by. */
39
+ const SIGNATURE_TEXT = [
40
+ { key: 'company_name', option: 'company_name', flag: '--company-name <name>' },
41
+ { key: 'company_id', option: 'company_id', flag: '--company-id <code>' },
42
+ { key: 'id_card_name', option: 'id_card_name', flag: '--id-card-name <name>' },
43
+ { key: 'id_card_number', option: 'id_card_number', flag: '--id-card-number <number>' },
44
+ { key: 'identity_mobile', option: 'mobile', flag: '--mobile <mobile>' }
45
+ ];
46
+ /** The flags that name a file, uploaded and then sent by the id it gets. */
47
+ const SIGNATURE_FILES = [
48
+ { key: 'id_card_front_attachment_id', option: 'id_card_front', flag: '--id-card-front <file>' },
49
+ { key: 'id_card_back_attachment_id', option: 'id_card_back', flag: '--id-card-back <file>' }
50
+ ];
51
+ const TEMPLATE_DESCRIPTION_OPTION = {
52
+ name: '--description',
53
+ type: 'string',
54
+ placeholder: '<text>',
55
+ description: 'What the SMS is for, shown to the reviewer'
56
+ };
57
+ function requiredOption(input, key, flag) {
58
+ const value = input.options[key];
59
+ if (!value)
60
+ throw new UsageError(`${flag} is required`);
61
+ return value;
62
+ }
63
+ function licensesOf(input) {
64
+ return input.options.license ?? [];
65
+ }
66
+ async function uploadLicense(client, file) {
67
+ const watching = progress();
68
+ watching.step(`uploading ${basename(file)}…`);
69
+ try {
70
+ const uploaded = await client.request(upload('uploadUserLicenseAttachment', {}, file));
71
+ return uploaded.attachment_id;
72
+ }
73
+ finally {
74
+ watching.done();
75
+ }
76
+ }
77
+ /**
78
+ * The materials the flags give, with their files uploaded. Only the flags that
79
+ * were given are in it, which is what an update needs: what is left out stays.
80
+ */
81
+ async function signatureMaterials(input, client) {
82
+ const body = {};
83
+ for (const { key, option } of SIGNATURE_TEXT) {
84
+ if (input.options[option] !== undefined)
85
+ body[key] = input.options[option];
86
+ }
87
+ const licenses = licensesOf(input);
88
+ if (licenses.length > 0) {
89
+ const ids = [];
90
+ for (const license of licenses)
91
+ ids.push(await uploadLicense(client, license));
92
+ body.license_attachment_ids = ids;
93
+ }
94
+ for (const { key, option } of SIGNATURE_FILES) {
95
+ const file = input.options[option];
96
+ if (file)
97
+ body[key] = await uploadLicense(client, file);
98
+ }
99
+ return body;
100
+ }
101
+ const MOBILE_FIELD_OPTION = {
102
+ name: '--field',
103
+ type: 'string',
104
+ placeholder: '<api_code>',
105
+ description: 'Mobile field to send to; a table column as <table api_code>.<column api_code>'
106
+ };
107
+ const TEMPLATE_ID_OPTION = {
108
+ name: '--template-id',
109
+ type: 'string',
110
+ placeholder: '<id>',
111
+ description: 'Template to send, from `sms template list`'
112
+ };
113
+ const TIMING_OPTIONS = [
114
+ {
115
+ name: '--placeholder',
116
+ type: 'string',
117
+ repeatable: true,
118
+ placeholder: '<api_code>',
119
+ description: 'Field filling the next template variable, repeatable in variable order; a variable without one takes the ' +
120
+ 'field whose api_code is its name'
121
+ },
122
+ {
123
+ name: '--send-at',
124
+ type: 'string',
125
+ placeholder: '<time>',
126
+ description: 'Send at this future time, ISO 8601 with a time zone offset, e.g. 2026-10-24T09:00:00+08:00'
127
+ },
128
+ { name: '--manual', type: 'boolean', description: 'Wait to be sent with `sms task send` once it passes review' }
129
+ ];
130
+ const TASK_ARG = [{ name: 'id', required: true, description: 'Task id, from `sms task list`' }];
131
+ function placeholders(input) {
132
+ const keys = input.options.placeholder ?? [];
133
+ return keys.length > 0 ? keys : undefined;
134
+ }
135
+ /** When and how it sends, only as far as the flags say. */
136
+ function timing(input) {
137
+ return {
138
+ placeholder_keys: placeholders(input),
139
+ send_at: input.options.send_at,
140
+ auto_send: input.options.manual ? false : undefined
141
+ };
142
+ }
143
+ /** Only the keys whose flags were given, so an update leaves the rest as it was. */
144
+ function templateBody(input) {
145
+ const body = {};
146
+ if (input.options.signature !== undefined)
147
+ body.signature = input.options.signature;
148
+ if (input.options.content !== undefined)
149
+ body.content = input.options.content;
150
+ if (input.options.description !== undefined)
151
+ body.apply_description = input.options.description;
152
+ return body;
153
+ }
154
+ /**
155
+ * One row per template, carrying its signature, so the template id a
156
+ * notification rule sends with is on the screen. A signature without
157
+ * templates still gets a row, for its own review status.
158
+ */
159
+ function templatesForReading(body) {
160
+ const signatures = body.signatures ?? [];
161
+ const data = signatures.flatMap((signature) => {
162
+ const own = {
163
+ signature: signature.signature,
164
+ signature_status: signature.status,
165
+ signature_reason: signature.reason
166
+ };
167
+ const templates = signature.templates ?? [];
168
+ if (templates.length === 0)
169
+ return [own];
170
+ return templates.map((template) => ({
171
+ template_id: template.id,
172
+ ...own,
173
+ template_status: template.status,
174
+ template_reason: template.reason,
175
+ content: template.content
176
+ }));
177
+ });
178
+ return { data };
179
+ }
2
180
  export const SMS = [
3
181
  {
4
182
  path: ['sms', 'status'],
5
183
  summary: 'List SMS signatures and templates with their review status and why a review failed',
6
- description: 'Your own signatures and templates, not those of the rest of the account.',
7
- request: () => call('listSmsAuditStatuses')
184
+ description: 'Your own signatures and templates, not those of the rest of the account. ' +
185
+ 'template_id is what `notification create --sms-template` takes.',
186
+ request: () => call('listSmsAuditStatuses'),
187
+ render: templatesForReading
188
+ },
189
+ {
190
+ path: ['sms', 'signature', 'list'],
191
+ summary: "List the account's SMS signatures",
192
+ description: 'Every signature of the account, whoever applied for it, with the ids `sms signature update` and ' +
193
+ '`sms signature delete` take. type says what each signs: notification, SMS sent from templates (channel ' +
194
+ 'normal or marketing), or verification, the verification codes of mobile fields only. Templates can only be ' +
195
+ 'created under a notification one whose channel is normal.',
196
+ options: [
197
+ {
198
+ name: '--status',
199
+ type: 'string',
200
+ choices: choices('listSmsSignatures', 'status'),
201
+ placeholder: '<status>',
202
+ description: 'Only those in this review status, e.g. FAIL for the ones that can be changed or deleted'
203
+ },
204
+ ...PAGINATION_OPTIONS
205
+ ],
206
+ request: (input) => call('listSmsSignatures', { query: { status: input.options.status, ...paging(input) } }),
207
+ paginate: LISTING,
208
+ examples: ['jinshuju sms signature list', 'jinshuju sms signature list --status FAIL']
209
+ },
210
+ {
211
+ path: ['sms', 'signature', 'create'],
212
+ summary: 'Apply for an SMS signature and submit it for review',
213
+ description: 'Uploads the license images and applies with them in one command. Review takes a while: follow it with ' +
214
+ '`sms signature list`. A signature the account already has under review or approved is answered as it is. ' +
215
+ 'For SMS notifications leave --type out. --type verification applies for a signature that only replaces ' +
216
+ 'the default 金数据 signature on the verification-code SMS of mobile fields: it cannot send notifications or ' +
217
+ 'have templates, and verification codes already work without one.',
218
+ args: [{ name: 'signature', required: true, description: 'Signature text, without 【】' }],
219
+ options: [
220
+ {
221
+ name: '--type',
222
+ type: 'string',
223
+ choices: bodyChoices('createSmsSignature', 'type'),
224
+ placeholder: '<type>',
225
+ description: 'notification (SMS notifications, the default) or verification (verification codes of mobile fields only)'
226
+ },
227
+ ...SIGNATURE_OPTIONS
228
+ ],
229
+ run: async (input, client) => {
230
+ if (licensesOf(input).length === 0)
231
+ throw new UsageError('--license <file> is required');
232
+ for (const { option, flag } of [...SIGNATURE_TEXT, ...SIGNATURE_FILES])
233
+ requiredOption(input, option, flag);
234
+ const body = {
235
+ signature: input.args.signature,
236
+ ...(await signatureMaterials(input, client))
237
+ };
238
+ if (input.options.type !== undefined)
239
+ body.type = input.options.type;
240
+ return client.request(call('createSmsSignature', { body }));
241
+ },
242
+ examples: [
243
+ 'jinshuju sms signature create 小金培训 --license ./license.jpg --company-name 小金培训有限公司 ' +
244
+ '--company-id 91110000MA00000000 --id-card-front ./front.jpg --id-card-back ./back.jpg ' +
245
+ '--id-card-name 张三 --id-card-number 110101199001011234 --mobile 13800000000'
246
+ ]
247
+ },
248
+ {
249
+ path: ['sms', 'signature', 'update'],
250
+ summary: 'Change a rejected SMS signature and submit it for review again',
251
+ description: 'Only a rejected signature can be changed. Only the flags given change; with none, it is submitted again ' +
252
+ 'as it is. Its templates go back to review with it, unless --signature changes the text: then each ' +
253
+ 'stays under the old text until `sms template update` sends it again.',
254
+ args: [{ name: 'id', required: true, description: 'Signature id, from `sms signature list`' }],
255
+ options: [
256
+ { name: '--signature', type: 'string', placeholder: '<text>', description: 'New signature text, without 【】' },
257
+ ...SIGNATURE_OPTIONS
258
+ ],
259
+ run: async (input, client) => {
260
+ const body = await signatureMaterials(input, client);
261
+ if (input.options.signature !== undefined)
262
+ body.signature = input.options.signature;
263
+ return client.request(call('updateSmsSignature', { path: { id: input.args.id }, body }));
264
+ },
265
+ examples: ['jinshuju sms signature update 6512a1c2d3e4f5a6b7c8d9d3 --license ./license-clear.jpg']
266
+ },
267
+ {
268
+ path: ['sms', 'signature', 'delete'],
269
+ summary: 'Delete a rejected SMS signature, and every template under it',
270
+ description: 'Only a rejected signature can be deleted. Its templates go with it.',
271
+ args: [{ name: 'id', required: true, description: 'Signature id, from `sms signature list`' }],
272
+ options: [YES_OPTION],
273
+ request: (input) => {
274
+ confirmed(input, `Deleting signature ${input.args.id} and its templates`);
275
+ return call('deleteSmsSignature', { path: { id: input.args.id } });
276
+ },
277
+ examples: ['jinshuju sms signature delete 6512a1c2d3e4f5a6b7c8d9d3 --yes']
278
+ },
279
+ {
280
+ path: ['sms', 'template', 'list'],
281
+ summary: 'List your SMS templates and the ones the account shares',
282
+ description: 'scope owned is yours and can be changed or deleted with the ids it carries; scope shared is shared by ' +
283
+ 'another member and can only be sent.',
284
+ options: [
285
+ {
286
+ name: '--keyword',
287
+ type: 'string',
288
+ placeholder: '<kw>',
289
+ description: 'Match the content or the signature, case-insensitive and partial'
290
+ },
291
+ {
292
+ name: '--scope',
293
+ type: 'string',
294
+ choices: choices('listSmsTemplates', 'scope'),
295
+ placeholder: '<scope>',
296
+ description: 'owned (yours) or shared (shared by another member); both when omitted'
297
+ },
298
+ {
299
+ name: '--signature-id',
300
+ type: 'string',
301
+ placeholder: '<id>',
302
+ description: 'Only templates under this signature, from `sms signature list`'
303
+ },
304
+ {
305
+ name: '--status',
306
+ type: 'string',
307
+ choices: choices('listSmsTemplates', 'status'),
308
+ placeholder: '<status>',
309
+ description: 'Only those in this review status'
310
+ },
311
+ ...PAGINATION_OPTIONS
312
+ ],
313
+ request: (input) => call('listSmsTemplates', {
314
+ query: {
315
+ q: input.options.keyword,
316
+ scope: input.options.scope,
317
+ signature_id: input.options.signature_id,
318
+ status: input.options.status,
319
+ ...paging(input)
320
+ }
321
+ }),
322
+ paginate: LISTING,
323
+ examples: ['jinshuju sms template list --keyword 开课', 'jinshuju sms template list --scope owned --status FAIL']
324
+ },
325
+ {
326
+ path: ['sms', 'template', 'create'],
327
+ summary: 'Submit an SMS template for review',
328
+ description: 'The signature must have been applied for, though it need not be approved yet. Review takes a while: ' +
329
+ 'follow it with `sms status`. Once approved, the template id is what a notification sends.',
330
+ options: [
331
+ { name: '--signature', type: 'string', placeholder: '<signature>', description: 'Signature to send it under' },
332
+ {
333
+ name: '--content',
334
+ type: 'string',
335
+ placeholder: '<text>',
336
+ description: 'Template content, without the signature'
337
+ },
338
+ TEMPLATE_DESCRIPTION_OPTION
339
+ ],
340
+ request: (input) => {
341
+ requiredOption(input, 'signature', '--signature <signature>');
342
+ requiredOption(input, 'content', '--content <text>');
343
+ return call('createSmsTemplate', { body: templateBody(input) });
344
+ },
345
+ examples: [
346
+ 'jinshuju sms template create --signature 小金培训 --content "你报名的课程明天上午 9 点开课,请准时参加。"'
347
+ ]
348
+ },
349
+ {
350
+ path: ['sms', 'template', 'update'],
351
+ summary: 'Change an SMS template and submit it for review again',
352
+ description: 'Not while it is under review. Only the flags given change; with none, it is submitted again as it is. ' +
353
+ 'An approved template goes back to review and cannot be sent until approved again.',
354
+ args: [{ name: 'id', required: true, description: 'Template id, from `sms template list`' }],
355
+ options: [
356
+ {
357
+ name: '--signature',
358
+ type: 'string',
359
+ placeholder: '<signature>',
360
+ description: 'Send it under this signature instead'
361
+ },
362
+ { name: '--content', type: 'string', placeholder: '<text>', description: 'New content, without the signature' },
363
+ TEMPLATE_DESCRIPTION_OPTION
364
+ ],
365
+ request: (input) => call('updateSmsTemplate', { path: { id: input.args.id }, body: templateBody(input) }),
366
+ examples: ['jinshuju sms template update 6512a1c2d3e4f5a6b7c8d9e0 --content "你报名的课程后天上午 9 点开课。"']
367
+ },
368
+ {
369
+ path: ['sms', 'template', 'delete'],
370
+ summary: 'Delete an SMS template',
371
+ description: 'Not while it is under review or being sent. A notification sending it stops sending SMS once it is gone.',
372
+ args: [{ name: 'id', required: true, description: 'Template id, from `sms template list`' }],
373
+ options: [YES_OPTION],
374
+ request: (input) => {
375
+ confirmed(input, `Deleting template ${input.args.id}`);
376
+ return call('deleteSmsTemplate', { path: { id: input.args.id } });
377
+ },
378
+ examples: ['jinshuju sms template delete 6512a1c2d3e4f5a6b7c8d9e0 --yes']
379
+ },
380
+ {
381
+ path: ['sms', 'send'],
382
+ summary: 'Send an SMS template to the entries of a form',
383
+ description: 'Picks the entries the way `entry count` narrows them, or the whole form with --select-all, and sends to the ' +
384
+ 'mobile field --field names. --estimate answers how many entries and numbers it reaches, how many are missing ' +
385
+ 'a number, the SMS it bills and whether the quota covers them, and sends nothing; --yes sends. The entries are ' +
386
+ 'picked again when it sends, so a change in between changes what goes out. A template still under review is ' +
387
+ 'taken, and the task waits for it.',
388
+ options: [
389
+ FORM_OPTION,
390
+ MOBILE_FIELD_OPTION,
391
+ TEMPLATE_ID_OPTION,
392
+ ...TIMING_OPTIONS,
393
+ ...NARROWING_OPTIONS,
394
+ SELECT_ALL_OPTION,
395
+ ESTIMATE_OPTION,
396
+ SEND_OPTION
397
+ ],
398
+ request: (input) => {
399
+ const path = { form_token: required(input, 'form') };
400
+ const entry_field = required(input, 'field');
401
+ const sms_template_id = required(input, 'template_id');
402
+ if (estimating(input, 'Sending SMS')) {
403
+ return call('estimateSmsTask', {
404
+ path,
405
+ query: {
406
+ entry_field,
407
+ ...narrowingQuery(input),
408
+ select_all: selectAll(input),
409
+ sms_template_id,
410
+ placeholder_keys: placeholders(input)
411
+ }
412
+ });
413
+ }
414
+ return call('createSmsTask', {
415
+ path,
416
+ body: given({
417
+ entry_field,
418
+ ...narrowingBody(input),
419
+ select_all: selectAll(input),
420
+ sms_template_id,
421
+ ...timing(input)
422
+ })
423
+ });
424
+ },
425
+ examples: [
426
+ "jinshuju sms send --form Kp7mQ2 --field field_2 --template-id 6512a1c2d3e4f5a6b7c8d9e0 --filter 'field_5 eq 已报名' --estimate",
427
+ "jinshuju sms send --form Kp7mQ2 --field field_2 --template-id 6512a1c2d3e4f5a6b7c8d9e0 --filter 'field_5 eq 已报名' --yes",
428
+ 'jinshuju sms send --form Kp7mQ2 --field field_2 --template-id 6512a1c2d3e4f5a6b7c8d9e0 --select-all ' +
429
+ '--send-at 2026-10-24T09:00:00+08:00 --yes'
430
+ ]
431
+ },
432
+ {
433
+ path: ['sms', 'task', 'list'],
434
+ summary: "List a form's SMS tasks, newest first",
435
+ description: 'Without how many numbers succeeded or failed: `sms task get` has those.',
436
+ options: [
437
+ FORM_OPTION,
438
+ {
439
+ name: '--status',
440
+ type: 'string',
441
+ choices: choices('listSmsTasks', 'status'),
442
+ placeholder: '<status>',
443
+ description: 'Only the tasks in this status'
444
+ },
445
+ ...PAGINATION_OPTIONS
446
+ ],
447
+ request: (input) => call('listSmsTasks', {
448
+ path: { form_token: required(input, 'form') },
449
+ query: { status: input.options.status, ...paging(input) }
450
+ }),
451
+ paginate: LISTING,
452
+ examples: ['jinshuju sms task list --form Kp7mQ2', 'jinshuju sms task list --form Kp7mQ2 --status template_fail']
453
+ },
454
+ {
455
+ path: ['sms', 'task', 'get'],
456
+ summary: 'Show an SMS task and how many numbers succeeded or failed so far',
457
+ args: TASK_ARG,
458
+ options: [FORM_OPTION],
459
+ request: (input) => call('getSmsTask', { path: { form_token: required(input, 'form'), id: input.args.id } }),
460
+ examples: ['jinshuju sms task get 6716f2a8c1d2e3f4a5b6c7d9 --form Kp7mQ2']
461
+ },
462
+ {
463
+ path: ['sms', 'task', 'activities'],
464
+ summary: 'List the sending result of each number an SMS task sent to',
465
+ args: TASK_ARG,
466
+ options: [
467
+ FORM_OPTION,
468
+ {
469
+ name: '--status',
470
+ type: 'string',
471
+ choices: choices('listSmsTaskActivities', 'status'),
472
+ placeholder: '<status>',
473
+ description: 'Only the numbers with this result; both when omitted'
474
+ },
475
+ { name: '--mobile', type: 'string', placeholder: '<mobile>', description: 'Only this number' },
476
+ ...PAGINATION_OPTIONS
477
+ ],
478
+ request: (input) => call('listSmsTaskActivities', {
479
+ path: { form_token: required(input, 'form'), id: input.args.id },
480
+ query: {
481
+ status: input.options.status,
482
+ mobile: input.options.mobile,
483
+ ...paging(input)
484
+ }
485
+ }),
486
+ paginate: LISTING,
487
+ examples: ['jinshuju sms task activities 6716f2a8c1d2e3f4a5b6c7d9 --form Kp7mQ2 --status FAILED']
488
+ },
489
+ {
490
+ path: ['sms', 'task', 'revoke'],
491
+ summary: 'Revoke an SMS task waiting to send or under content review, so it never sends',
492
+ args: TASK_ARG,
493
+ options: [FORM_OPTION],
494
+ request: (input) => call('updateSmsTask', {
495
+ path: { form_token: required(input, 'form'), id: input.args.id },
496
+ body: { revoked: true }
497
+ }),
498
+ examples: ['jinshuju sms task revoke 6716f2a8c1d2e3f4a5b6c7d9 --form Kp7mQ2']
499
+ },
500
+ {
501
+ path: ['sms', 'task', 'change'],
502
+ summary: 'Change an SMS task whose template failed review, and send it again',
503
+ description: 'Only a task in template_fail. It keeps its entries and its id; --field and --placeholder left out keep what ' +
504
+ 'the task has. --estimate answers what it would bill with the new template and sends nothing; --yes sends.',
505
+ args: TASK_ARG,
506
+ options: [
507
+ FORM_OPTION,
508
+ TEMPLATE_ID_OPTION,
509
+ { ...MOBILE_FIELD_OPTION, description: `${MOBILE_FIELD_OPTION.description}; the task's own when omitted` },
510
+ ...TIMING_OPTIONS,
511
+ ESTIMATE_OPTION,
512
+ SEND_OPTION
513
+ ],
514
+ request: (input) => {
515
+ const path = { form_token: required(input, 'form'), id: input.args.id };
516
+ const sms_template_id = required(input, 'template_id');
517
+ const entry_field = input.options.field;
518
+ if (estimating(input, `Sending task ${input.args.id} again`)) {
519
+ return call('estimateSmsTaskChange', {
520
+ path,
521
+ query: { entry_field, sms_template_id, placeholder_keys: placeholders(input) }
522
+ });
523
+ }
524
+ return call('updateSmsTask', { path, body: given({ entry_field, sms_template_id, ...timing(input) }) });
525
+ },
526
+ examples: [
527
+ 'jinshuju sms task change 6716f2a8c1d2e3f4a5b6c7d9 --form Kp7mQ2 --template-id 6512a1c2d3e4f5a6b7c8d9e1 --estimate',
528
+ 'jinshuju sms task change 6716f2a8c1d2e3f4a5b6c7d9 --form Kp7mQ2 --template-id 6512a1c2d3e4f5a6b7c8d9e1 --yes'
529
+ ]
530
+ },
531
+ {
532
+ path: ['sms', 'task', 'send'],
533
+ summary: 'Send an SMS task created with --manual',
534
+ description: 'Once it has passed review. A task given a send time waits until then.',
535
+ args: TASK_ARG,
536
+ options: [FORM_OPTION, SEND_OPTION],
537
+ request: (input) => {
538
+ sendingConfirmed(input, `Sending task ${input.args.id}`);
539
+ return call('sendSmsTask', { path: { form_token: required(input, 'form'), id: input.args.id } });
540
+ },
541
+ examples: ['jinshuju sms task send 6716f2a8c1d2e3f4a5b6c7d9 --form Kp7mQ2 --yes']
542
+ },
543
+ {
544
+ path: ['sms', 'task', 'resend'],
545
+ summary: 'Send an SMS task again to the entries that got a result',
546
+ description: 'A new task, with the same template and variables, to the entries of this one that got --status: FAILED, ' +
547
+ 'SUCCESS or ALL. A filter, keyword or view narrows them further, and a serial_number none_in condition leaves ' +
548
+ 'some out. It sends at once. --estimate answers what it would send and bill and sends nothing; --yes sends.',
549
+ args: TASK_ARG,
550
+ options: [
551
+ FORM_OPTION,
552
+ {
553
+ name: '--status',
554
+ type: 'string',
555
+ choices: bodyChoices('resendSmsTask', 'status'),
556
+ placeholder: '<status>',
557
+ description: 'Send again to the entries with this result; ALL for every one the task sent to'
558
+ },
559
+ ...NARROWING_OPTIONS,
560
+ ESTIMATE_OPTION,
561
+ SEND_OPTION
562
+ ],
563
+ request: (input) => {
564
+ const path = { form_token: required(input, 'form'), id: input.args.id };
565
+ const status = required(input, 'status');
566
+ if (estimating(input, `Sending task ${input.args.id} again`)) {
567
+ return call('estimateSmsTaskResend', { path, query: { status, ...narrowingQuery(input) } });
568
+ }
569
+ return call('resendSmsTask', { path, body: given({ status, ...narrowingBody(input) }) });
570
+ },
571
+ examples: [
572
+ 'jinshuju sms task resend 6716f2a8c1d2e3f4a5b6c7d9 --form Kp7mQ2 --status FAILED --estimate',
573
+ "jinshuju sms task resend 6716f2a8c1d2e3f4a5b6c7d9 --form Kp7mQ2 --status FAILED --filter 'serial_number none_in 3,8' --yes"
574
+ ]
8
575
  }
9
576
  ];
package/dist/config.d.ts CHANGED
@@ -63,7 +63,7 @@ export declare const defaultConfigPath: string;
63
63
  export declare const defaultHost = "https://jinshuju.net";
64
64
  export declare const defaultAuthHost = "https://account.jinshuju.net";
65
65
  export declare const defaultOAuthClientId = "jinshuju_cli_public";
66
- export declare const defaultScopes = "public forms read_entries write_entries form_setting read_contacts users";
66
+ export declare const defaultScopes = "public forms read_entries write_entries form_setting read_contacts users routines";
67
67
  /**
68
68
  * One credential at a time: a login of either kind replaces whatever the last
69
69
  * one stored, so the file never holds two that disagree about who is calling.
package/dist/config.js CHANGED
@@ -6,7 +6,7 @@ export const defaultConfigPath = join(homedir(), '.jinshuju', 'config.json');
6
6
  export const defaultHost = 'https://jinshuju.net';
7
7
  export const defaultAuthHost = 'https://account.jinshuju.net';
8
8
  export const defaultOAuthClientId = 'jinshuju_cli_public';
9
- export const defaultScopes = 'public forms read_entries write_entries form_setting read_contacts users';
9
+ export const defaultScopes = 'public forms read_entries write_entries form_setting read_contacts users routines';
10
10
  function readConfigFile(configPath) {
11
11
  if (!existsSync(configPath))
12
12
  return {};
@@ -1,7 +1,7 @@
1
1
  import type { Operation, Schema } from '../spec.js';
2
2
  /** The path every operation's path is relative to, from `servers`. */
3
3
  export declare const BASE_PATH = "/api/v1";
4
- export type OperationId = 'aggregateEntries' | 'aggregateFormViewEntries' | 'aggregateTableEntries' | 'aggregateTableViewEntries' | 'aggregateTradeTransactions' | 'checkFormFieldData' | 'checkTableFieldData' | 'copyForm' | 'countEntries' | 'countEntriesAcrossForms' | 'countFormViewEntries' | 'countTableEntries' | 'countTableViewEntries' | 'createCheckinCampaign' | 'createEntriesBatch' | 'createEntry' | 'createEntryComment' | 'createEntryImport' | 'createEntryLegacy' | 'createFillFormEntry' | 'createFillViewEntry' | 'createFolder' | 'createForm' | 'createFormView' | 'createFormWebhook' | 'createOpensearchQuery' | 'createPredefinedChoicesSet' | 'createTable' | 'createTableEntry' | 'createTableEntryComment' | 'createTableView' | 'createTemplateUsage' | 'createWeixinOauthSession' | 'deleteCheckinCampaign' | 'deleteEntry' | 'deleteEntryComment' | 'deleteFormView' | 'deleteFormWebhook' | 'deletePredefinedChoicesSet' | 'deleteTable' | 'deleteTableEntry' | 'deleteTableEntryComment' | 'deleteTableView' | 'getBillingAccount' | 'getCheckinCampaign' | 'getCurrentUser' | 'getEntry' | 'getEntryImport' | 'getEntryStats' | 'getEvaluationSetting' | 'getExamSetting' | 'getFieldType' | 'getFillFormPage' | 'getFillViewPage' | 'getForm' | 'getFormSetting' | 'getFormView' | 'getManuallyCloseRule' | 'getOpensearchQuery' | 'getTable' | 'getTableEntry' | 'getTableView' | 'getTradeMerchant' | 'listBillingAccountInvoices' | 'listBillingAccountPaymentHistories' | 'listBillingAccountUsers' | 'listCheckinCampaigns' | 'listContacts' | 'listEntries' | 'listEntryComments' | 'listExtendedAttributes' | 'listFieldRules' | 'listFieldTypes' | 'listFolders' | 'listFormCooperators' | 'listFormViewEntries' | 'listFormViews' | 'listForms' | 'listMyFilledForms' | 'listMySubmittedEntries' | 'listOpensearchQueries' | 'listOpensearchQuerySuggestions' | 'listPredefinedChoicesSets' | 'listSmsAuditStatuses' | 'listTableEntries' | 'listTableEntryComments' | 'listTableViewEntries' | 'listTableViews' | 'listTables' | 'listTradePayouts' | 'listTradeRefunds' | 'listTradeTransactions' | 'moveFormToFolder' | 'moveTableToFolder' | 'patchEntriesBatch' | 'previewFormFieldTypeChange' | 'previewTableFieldTypeChange' | 'replaceEntry' | 'replaceTableEntry' | 'searchEntriesAcrossForms' | 'searchMySubmittedEntries' | 'summarizeEntries' | 'summarizeFormViewEntries' | 'summarizeTableEntries' | 'summarizeTableViewEntries' | 'updateAccessPolicy' | 'updateCheckinCampaign' | 'updateEntry' | 'updateEntryComment' | 'updateEntryViaPost' | 'updateEvaluationSetting' | 'updateExamSetting' | 'updateForm' | 'updateFormSetting' | 'updateFormTheme' | 'updateFormView' | 'updateManuallyCloseRule' | 'updateOpensearchQuery' | 'updatePredefinedChoicesSet' | 'updateTable' | 'updateTableEntry' | 'updateTableEntryComment' | 'updateTableEntryViaPost' | 'updateTableView' | 'uploadEntryAttachment' | 'uploadFormImage' | 'uploadImportFile' | 'verifyRedirectParams';
4
+ export type OperationId = 'aggregateEntries' | 'aggregateFormViewEntries' | 'aggregateTableEntries' | 'aggregateTableViewEntries' | 'aggregateTradeTransactions' | 'checkFormFieldData' | 'checkTableFieldData' | 'copyForm' | 'countEntries' | 'countEntriesAcrossForms' | 'countFormViewEntries' | 'countTableEntries' | 'countTableViewEntries' | 'createCheckinCampaign' | 'createEmailTask' | 'createEntriesBatch' | 'createEntry' | 'createEntryComment' | 'createEntryImport' | 'createEntryLegacy' | 'createFillFormEntry' | 'createFillViewEntry' | 'createFolder' | 'createForm' | 'createFormView' | 'createFormWebhook' | 'createNotificationRule' | 'createOpensearchQuery' | 'createPredefinedChoicesSet' | 'createRoutine' | 'createSmsSignature' | 'createSmsTask' | 'createSmsTemplate' | 'createTable' | 'createTableEntry' | 'createTableEntryComment' | 'createTableView' | 'createTemplateUsage' | 'createWeixinOauthSession' | 'deleteCheckinCampaign' | 'deleteEntry' | 'deleteEntryComment' | 'deleteForm' | 'deleteFormView' | 'deleteFormWebhook' | 'deleteNotificationRule' | 'deletePredefinedChoicesSet' | 'deleteRoutine' | 'deleteSmsSignature' | 'deleteSmsTemplate' | 'deleteTable' | 'deleteTableEntry' | 'deleteTableEntryComment' | 'deleteTableView' | 'estimateEmailTask' | 'estimateEmailTaskResend' | 'estimateSmsTask' | 'estimateSmsTaskChange' | 'estimateSmsTaskResend' | 'getBillingAccount' | 'getCheckinCampaign' | 'getCurrentUser' | 'getEmailTask' | 'getEntry' | 'getEntryImport' | 'getEntryStats' | 'getEvaluationSetting' | 'getExamSetting' | 'getFieldType' | 'getFillFormPage' | 'getFillViewPage' | 'getFolder' | 'getForm' | 'getFormSetting' | 'getFormView' | 'getManuallyCloseRule' | 'getNotificationRule' | 'getOpensearchQuery' | 'getRoutine' | 'getSmsTask' | 'getTable' | 'getTableEntry' | 'getTableView' | 'getTradeMerchant' | 'listBillingAccountInvoices' | 'listBillingAccountPaidFeatures' | 'listBillingAccountPaymentHistories' | 'listBillingAccountUsers' | 'listCheckinCampaigns' | 'listContacts' | 'listEmailTaskActivities' | 'listEmailTasks' | 'listEntries' | 'listEntryComments' | 'listExtendedAttributes' | 'listFieldRules' | 'listFieldTypes' | 'listFolders' | 'listFormCooperators' | 'listFormViewEntries' | 'listFormViews' | 'listForms' | 'listMyFilledForms' | 'listMySubmittedEntries' | 'listNotificationRules' | 'listOpensearchQueries' | 'listOpensearchQuerySuggestions' | 'listPredefinedChoicesSets' | 'listRoutineRuns' | 'listRoutines' | 'listSmsAuditStatuses' | 'listSmsSignatures' | 'listSmsTaskActivities' | 'listSmsTasks' | 'listSmsTemplates' | 'listSmtpAccounts' | 'listTableEntries' | 'listTableEntryComments' | 'listTableViewEntries' | 'listTableViews' | 'listTables' | 'listTradePayouts' | 'listTradeRefunds' | 'listTradeTransactions' | 'moveFormToFolder' | 'moveTableToFolder' | 'patchEntriesBatch' | 'pauseRoutine' | 'previewFormFieldTypeChange' | 'previewTableFieldTypeChange' | 'replaceEntry' | 'replaceTableEntry' | 'resendEmailTask' | 'resendSmsTask' | 'resumeRoutine' | 'runRoutine' | 'searchEntriesAcrossForms' | 'searchMySubmittedEntries' | 'sendSmsTask' | 'summarizeEntries' | 'summarizeFormViewEntries' | 'summarizeTableEntries' | 'summarizeTableViewEntries' | 'updateAccessPolicy' | 'updateCheckinCampaign' | 'updateEntry' | 'updateEntryComment' | 'updateEntryViaPost' | 'updateEvaluationSetting' | 'updateExamSetting' | 'updateForm' | 'updateFormSetting' | 'updateFormTheme' | 'updateFormView' | 'updateManuallyCloseRule' | 'updateNotificationRule' | 'updateOpensearchQuery' | 'updatePredefinedChoicesSet' | 'updateRoutine' | 'updateSmsSignature' | 'updateSmsTask' | 'updateSmsTemplate' | 'updateTable' | 'updateTableEntry' | 'updateTableEntryComment' | 'updateTableEntryViaPost' | 'updateTableView' | 'uploadEntryAttachment' | 'uploadFormImage' | 'uploadImportFile' | 'uploadUserLicenseAttachment' | 'verifyRedirectParams';
5
5
  export declare const OPERATIONS: {
6
6
  readonly [id in OperationId]: Operation;
7
7
  };