@jinshuju/cli 0.18.0 → 0.19.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/README.md CHANGED
@@ -482,10 +482,17 @@ with it.
482
482
  While your own are under review, `sms template list --scope official` lists the official
483
483
  templates, which are approved already and can be sent right away.
484
484
 
485
+ A template's variables are written `$(var_1)`, `$(var_2)` and so on, each once,
486
+ and each is declared with a `--variable <label>:<type>:<example>`;
487
+ the reviewer sees the examples, which take 6 characters or more. A notification or `sms send --placeholder` then
488
+ fills them from form fields in the order the content uses them.
489
+
485
490
  ```bash
486
491
  jinshuju sms signature create 小金培训 --license ./license.jpg --company-name 小金培训有限公司 --company-id 91110000MA00000000 \
487
492
  --id-card-front ./front.jpg --id-card-back ./back.jpg --id-card-name 张三 --id-card-number 110101199001011234 --mobile 13800000000
488
493
  jinshuju sms template create --signature 小金培训 --content "你报名的课程明天上午 9 点开课,请准时参加。"
494
+ jinshuju sms template create --signature 小金培训 --content '$(var_1),你好,套餐 $(var_2) 到期。' \
495
+ --variable 姓名:name:姓名,示例:张三 --variable 到期日期:time:2026-10-25
489
496
  jinshuju sms status
490
497
  jinshuju sms signature list --status FAIL
491
498
  jinshuju sms template list --keyword 开课 --scope owned
@@ -55,6 +55,23 @@ const TEMPLATE_DESCRIPTION_OPTION = {
55
55
  placeholder: '<text>',
56
56
  description: 'What the SMS is for, shown to the reviewer'
57
57
  };
58
+ const TEMPLATE_VARIABLE_OPTION = {
59
+ name: '--variable',
60
+ type: 'string',
61
+ repeatable: true,
62
+ placeholder: '<label>:<type>:<example>',
63
+ description: 'Declare the next of $(var_1), $(var_2)... the content uses, repeatable in that order; type is one of ' +
64
+ 'code, nickname, name, address, amount, link, time, other, e.g. 姓名:name:姓名,示例:张三; the example takes 6 characters or more'
65
+ };
66
+ const VARIABLE_SHAPE = "--variable must be '<label>:<type>:<example>'";
67
+ /** `姓名:name:姓名,示例:张三`; the example keeps any further `:`, as a time or a link has. */
68
+ function parseVariable(input) {
69
+ const [label, type, ...rest] = input.split(':');
70
+ const example = rest.join(':');
71
+ if (!label || !type || !example)
72
+ throw new UsageError(`${VARIABLE_SHAPE}, got ${JSON.stringify(input)}`);
73
+ return { label, type, example };
74
+ }
58
75
  function requiredOption(input, key, flag) {
59
76
  const value = input.options[key];
60
77
  if (!value)
@@ -175,6 +192,9 @@ function templateBody(input) {
175
192
  body.content = input.options.content;
176
193
  if (input.options.description !== undefined)
177
194
  body.apply_description = input.options.description;
195
+ const variables = input.options.variable;
196
+ if (variables?.length)
197
+ body.variables = variables.map(parseVariable);
178
198
  return body;
179
199
  }
180
200
  /**
@@ -362,7 +382,8 @@ export const SMS = [
362
382
  path: ['sms', 'template', 'create'],
363
383
  summary: 'Submit an SMS template for review',
364
384
  description: 'The signature must have been applied for, though it need not be approved yet. Review takes a while: ' +
365
- 'follow it with `sms status`. Once approved, the template id is what a notification sends.',
385
+ 'follow it with `sms status`. Once approved, the template id is what a notification sends. Variables are ' +
386
+ 'written $(var_1), $(var_2)... in the content, each once, and each declared with --variable.',
366
387
  options: [
367
388
  { name: '--signature', type: 'string', placeholder: '<signature>', description: 'Signature to send it under' },
368
389
  {
@@ -371,7 +392,8 @@ export const SMS = [
371
392
  placeholder: '<text>',
372
393
  description: 'Template content, without the signature'
373
394
  },
374
- TEMPLATE_DESCRIPTION_OPTION
395
+ TEMPLATE_DESCRIPTION_OPTION,
396
+ TEMPLATE_VARIABLE_OPTION
375
397
  ],
376
398
  request: (input) => {
377
399
  requiredOption(input, 'signature', '--signature <signature>');
@@ -379,14 +401,18 @@ export const SMS = [
379
401
  return call('createSmsTemplate', { body: templateBody(input) });
380
402
  },
381
403
  examples: [
382
- 'jinshuju sms template create --signature 小金培训 --content "你报名的课程明天上午 9 点开课,请准时参加。"'
404
+ 'jinshuju sms template create --signature 小金培训 --content "你报名的课程明天上午 9 点开课,请准时参加。"',
405
+ "jinshuju sms template create --signature 小金培训 --content '$(var_1),你好,套餐 $(var_2) 到期。' " +
406
+ '--variable 姓名:name:姓名,示例:张三 --variable 到期日期:time:2026-10-25'
383
407
  ]
384
408
  },
385
409
  {
386
410
  path: ['sms', 'template', 'update'],
387
411
  summary: 'Change an SMS template and submit it for review again',
388
412
  description: 'Not while it is under review. Only the flags given change; with none, it is submitted again as it is. ' +
389
- 'An approved template goes back to review and cannot be sent until approved again.',
413
+ 'An approved template goes back to review and cannot be sent until approved again. Changing the variables ' +
414
+ 'of the content takes a --variable for each; while a notification or an SMS task sends the template, only ' +
415
+ 'the text around them can change.',
390
416
  args: [{ name: 'id', required: true, description: 'Template id, from `sms template list`' }],
391
417
  options: [
392
418
  {
@@ -396,7 +422,8 @@ export const SMS = [
396
422
  description: 'Send it under this signature instead'
397
423
  },
398
424
  { name: '--content', type: 'string', placeholder: '<text>', description: 'New content, without the signature' },
399
- TEMPLATE_DESCRIPTION_OPTION
425
+ TEMPLATE_DESCRIPTION_OPTION,
426
+ TEMPLATE_VARIABLE_OPTION
400
427
  ],
401
428
  request: (input) => call('updateSmsTemplate', { path: { id: input.args.id }, body: templateBody(input) }),
402
429
  examples: ['jinshuju sms template update 6512a1c2d3e4f5a6b7c8d9e0 --content "你报名的课程后天上午 9 点开课。"']
@@ -4539,7 +4539,8 @@ export const SCHEMAS = {
4539
4539
  properties: {
4540
4540
  signature: { type: 'string' },
4541
4541
  content: { type: 'string' },
4542
- apply_description: { type: 'string', maxLength: 200 }
4542
+ apply_description: { type: 'string', maxLength: 200 },
4543
+ variables: { type: 'array', minItems: 1, items: { $ref: 'SMSTemplateVariableInput' } }
4543
4544
  },
4544
4545
  additionalProperties: false
4545
4546
  },
@@ -4548,7 +4549,18 @@ export const SCHEMAS = {
4548
4549
  properties: {
4549
4550
  signature: { type: 'string' },
4550
4551
  content: { type: 'string' },
4551
- apply_description: { type: 'string', maxLength: 200 }
4552
+ apply_description: { type: 'string', maxLength: 200 },
4553
+ variables: { type: 'array', minItems: 1, items: { $ref: 'SMSTemplateVariableInput' } }
4554
+ },
4555
+ additionalProperties: false
4556
+ },
4557
+ SMSTemplateVariableInput: {
4558
+ type: 'object',
4559
+ required: ['label', 'type', 'example'],
4560
+ properties: {
4561
+ label: { type: 'string', pattern: '\\S' },
4562
+ type: { type: 'string', enum: ['code', 'nickname', 'name', 'address', 'amount', 'link', 'time', 'other'] },
4563
+ example: { type: 'string', minLength: 6, pattern: '\\S' }
4552
4564
  },
4553
4565
  additionalProperties: false
4554
4566
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jinshuju/cli",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Command line interface for Jinshuju Open API v1",
5
5
  "homepage": "https://github.com/jinshuju/cli#readme",
6
6
  "bugs": {