@jinshuju/cli 0.2.0 → 0.4.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
@@ -93,6 +93,28 @@ The settings block is always sent first. It is the half that can be rejected —
93
93
  "this is not an exam form" — and sending it first is what guarantees a rejection
94
94
  leaves every other change unsent.
95
95
 
96
+ ### When the form takes entries
97
+
98
+ `setting` travels as is, on create and on edit. Its close rules decide when the
99
+ form is open; they coexist, and `form get` reads them back in the shape they
100
+ were written. On edit a rule replaces what was there (`time_periods` is the
101
+ whole list) and `{"enabled": false}` removes it.
102
+
103
+ ```bash
104
+ # between two instants; either end may be left out
105
+ jinshuju form edit Kp7mQ2 --json '{"setting":{"by_time_range_close_rule":{"start_time":"2026-10-01T09:00:00+08:00","end_time":"2026-10-07T18:00:00+08:00"}}}'
106
+ # 11:00-12:40 and 17:00-18:30, every day
107
+ jinshuju form edit Kp7mQ2 --json '{"setting":{"daily_repeat_close_rule":{"time_periods":[
108
+ {"start_time":{"hour":11,"minute":0},"end_time":{"hour":12,"minute":40}},
109
+ {"start_time":{"hour":17,"minute":0},"end_time":{"hour":18,"minute":30}}]}}}'
110
+ jinshuju form edit Kp7mQ2 --json '{"setting":{"daily_repeat_close_rule":{"enabled":false}}}'
111
+ jinshuju form edit Kp7mQ2 --json '{"setting":{"by_entries_close_rule":{"limit":100}}}' # closes after 100 entries
112
+ jinshuju form edit Kp7mQ2 --json '{"setting":{"manually_close_rule":{"closed":true}}}' # stops it now
113
+ ```
114
+
115
+ `show_form_before_open` and `show_close_count_down` only hold with a time-range
116
+ or daily rule; without one the save resets them to false.
117
+
96
118
  ## Reading data
97
119
 
98
120
  `entry`, `view`, `field` and `comment` are all top-level resources; the
@@ -164,6 +186,10 @@ jinshuju entry create --form Kp7mQ2 --json @entry.json
164
186
  cat entry.json | jinshuju entry create --form Kp7mQ2 --json -
165
187
  ```
166
188
 
189
+ Creating, updating or getting one entry answers with a `url`: where that entry
190
+ opens in the Jinshuju data page, for whoever wrote it to check it there. A
191
+ `--batch` write answers without one.
192
+
167
193
  ## Writing
168
194
 
169
195
  Apart from the settings-block dispatch described above, every write command
@@ -6,10 +6,50 @@ export const ACCOUNT = [
6
6
  summary: 'Show the current account, plan and quota',
7
7
  request: () => ({ method: 'GET', path: `${API}/billing_account` })
8
8
  },
9
+ {
10
+ path: ['account', 'me'],
11
+ summary: 'Show who is signed in: name, email, mobile and role in the account',
12
+ request: () => ({ method: 'GET', path: `${API}/me` })
13
+ },
9
14
  {
10
15
  path: ['account', 'member', 'list'],
11
16
  summary: 'List account members',
12
17
  options: [LIMIT_OPTION],
13
18
  request: (input) => ({ method: 'GET', path: `${API}/billing_account/users`, query: paging(input) })
19
+ },
20
+ {
21
+ path: ['account', 'invoice', 'list'],
22
+ summary: 'List e-invoices, and the amount not invoiced yet',
23
+ description: 'Account admins only, as in the web app; a member is refused with 403.',
24
+ request: () => ({ method: 'GET', path: `${API}/billing_account/invoices` })
25
+ },
26
+ {
27
+ path: ['account', 'payment', 'list'],
28
+ summary: 'List what the account spent or topped up on 金数据: SMS, AI points, plans, recharges',
29
+ description: 'Not what its payment forms collected from customers: that is transaction list. Newest first. ' +
30
+ 'Account admins only, as in the web app; a member is refused with 403.',
31
+ options: [
32
+ { name: '--from', type: 'string', placeholder: '<YYYY-MM-DD>', description: 'First day' },
33
+ { name: '--to', type: 'string', placeholder: '<YYYY-MM-DD>', description: 'Last day, inclusive' },
34
+ {
35
+ name: '--verb',
36
+ type: 'string',
37
+ placeholder: '<verb>',
38
+ description: 'Only this kind of record, e.g. sms_charge'
39
+ },
40
+ { ...LIMIT_OPTION, description: 'Records to return (default 50, up to 1000)' },
41
+ { name: '--with-balance', type: 'boolean', description: 'Also return the current balance and quotas' }
42
+ ],
43
+ request: (input) => ({
44
+ method: 'GET',
45
+ path: `${API}/billing_account/payment_histories`,
46
+ query: {
47
+ start_date: input.options.from,
48
+ end_date: input.options.to,
49
+ verb: input.options.verb,
50
+ limit: input.options.limit === undefined ? undefined : String(input.options.limit),
51
+ include_balance: input.options.with_balance ? 'true' : undefined
52
+ }
53
+ })
14
54
  }
15
55
  ];
@@ -15,6 +15,12 @@ function list(value) {
15
15
  function labels(input) {
16
16
  return input.options.labels ? 'true' : undefined;
17
17
  }
18
+ /**
19
+ * The web host is not the API host on every environment, so the link is the
20
+ * server's to spell; all a command can do is say it is there and what it is for.
21
+ */
22
+ const DETAIL_URL = 'One entry comes back with `url`, where it opens in the Jinshuju data page: hand it to the user ' +
23
+ 'so they can check it.';
18
24
  const LABELS_OPTION = {
19
25
  name: '--labels',
20
26
  type: 'boolean',
@@ -90,6 +96,12 @@ const ATTACH_OPTION = {
90
96
  description: 'Upload a file into this attachment field, repeatable. A subtable column names the row it fills: field_5.0.field_2=<file>'
91
97
  };
92
98
  const ATTACH_SHAPE = "--attach must be '<api-code>=<file>', or '<api-code>.<row>.<sub>=<file>' for a subtable column";
99
+ // The write answers success for a value its field could not read and keeps
100
+ // nothing of it, so the only warning a caller gets is the one written here.
101
+ const VALUE_SHAPES = 'Each type takes a value of its own shape — some choices only by code, a time as ' +
102
+ '{hour, minute} — and `field types <Type>` shows it under `value`. A value in a shape its ' +
103
+ 'field cannot read is dropped without an error, as is a key naming no field, so read the ' +
104
+ 'entry back when it matters.';
93
105
  /**
94
106
  * `field_5=/path/a.png`, or `field_5.0.field_2=/path/a.png` for one row of a
95
107
  * subtable column.
@@ -531,7 +543,10 @@ export const ENTRY = [
531
543
  path: ['entry', 'create'],
532
544
  summary: 'Create entries',
533
545
  description: 'The payload is keyed by field api_code, not by field label. --batch takes a list of them and ' +
534
- 'writes them in one request.',
546
+ 'writes them in one request, and answers without a `url` for each. ' +
547
+ DETAIL_URL +
548
+ ' ' +
549
+ VALUE_SHAPES,
535
550
  options: [...CONTAINER_OPTIONS, JSON_OPTION, BATCH_OPTION, ATTACH_OPTION],
536
551
  run: async (input, client) => {
537
552
  const attached = attachments(input);
@@ -558,7 +573,10 @@ export const ENTRY = [
558
573
  summary: 'Update entries',
559
574
  description: 'The payload merges onto the entry, leaving the fields it does not name alone; --replace ' +
560
575
  'writes the entry as given, clearing the rest. --batch takes [{serial_number, entry}] and ' +
561
- 'always merges.',
576
+ 'always merges. ' +
577
+ DETAIL_URL +
578
+ ' ' +
579
+ VALUE_SHAPES,
562
580
  args: [{ name: 'serial', required: false, description: 'Entry serial number; leave out with --batch' }],
563
581
  options: [
564
582
  ...CONTAINER_OPTIONS,
@@ -700,6 +718,7 @@ export const ENTRY = [
700
718
  {
701
719
  path: ['entry', 'get'],
702
720
  summary: 'Show one entry',
721
+ description: DETAIL_URL,
703
722
  args: [{ name: 'serial', required: true, description: 'Entry serial number' }],
704
723
  options: [
705
724
  ...CONTAINER_OPTIONS,
@@ -92,7 +92,9 @@ export const FIELD = [
92
92
  "a cascade's nesting. `settings` are the flat keys beside them, `flags` the booleans, and " +
93
93
  '`read_as` the name the same field answers with when read back — which is not the name you ' +
94
94
  'write. Name one type to see its structure described in full. A table holds far fewer types ' +
95
- 'than a form, and a scorable question type only belongs to a form that scores answers.',
95
+ 'than a form, and a scorable question type only belongs to a form that scores answers. ' +
96
+ '`value` is what an entry writes into the type: `example` is a value it takes, exact under ' +
97
+ '--output json, and `note` what the example cannot show.',
96
98
  args: [{ name: 'type', required: false, description: 'One type name, e.g. RadioButton' }],
97
99
  options: [
98
100
  KIND_OPTION,
@@ -18,12 +18,28 @@ const FORM_PAYLOAD = [
18
18
  ' { "type": "TextField", "label": "Name", "required": true },',
19
19
  ' { "type": "RadioButton", "label": "Ticket", "choices": [',
20
20
  ' { "name": "Standard" }, { "name": "VIP" } ] }',
21
- ' ]',
21
+ ' ],',
22
+ ' "setting": {',
23
+ ' "by_time_range_close_rule": { "start_time": "2026-10-01T09:00:00+08:00",',
24
+ ' "end_time": "2026-10-07T18:00:00+08:00" },',
25
+ ' "daily_repeat_close_rule": { "time_periods": [',
26
+ ' { "start_time": { "hour": 11, "minute": 0 }, "end_time": { "hour": 12, "minute": 40 } } ] },',
27
+ ' "show_close_count_down": true',
28
+ ' }',
22
29
  '}',
23
30
  '',
24
31
  'A choice carries "name". The "value" it reads back with is the code the',
25
32
  'backend assigns, not what you sent.',
26
33
  '',
34
+ '"setting" is optional and travels as is. When the form takes entries is its',
35
+ 'close rules: by_time_range_close_rule opens it between two instants (either',
36
+ 'may be left out), daily_repeat_close_rule opens it inside time-of-day periods',
37
+ 'every day, by_entries_close_rule {"limit": 100} closes it after that many',
38
+ 'entries, and manually_close_rule {"closed": true} stops it now. The rules',
39
+ 'coexist. show_form_before_open and show_close_count_down only hold with a',
40
+ 'time-range or daily rule. The same keys go in a `form edit` payload, where',
41
+ 'time_periods replaces the list and {"enabled": false} removes a rule.',
42
+ '',
27
43
  'Reading a form back does not give you something you can send again: a field',
28
44
  'written as "TextField" reads as "single_line_text". `field types` lists the',
29
45
  'names to write, and `field types <Type>` describes one.',
@@ -264,7 +280,8 @@ export const FORM = [
264
280
  path: ['form', 'edit'],
265
281
  summary: 'Edit a form',
266
282
  description: 'The payload carries the operations to apply: name, description, setting, and fields as ' +
267
- '{add, update, update_choices, remove}. Only what is named changes.',
283
+ '{add, update, update_choices, remove}. Only what is named changes. `form create --help` ' +
284
+ 'shows what setting takes, the close rules among it.',
268
285
  args: [{ name: 'form', required: true, description: 'Form token' }],
269
286
  options: [JSON_OPTION],
270
287
  run: async (input, client) => {
@@ -297,6 +314,7 @@ export const FORM = [
297
314
  },
298
315
  examples: [
299
316
  'jinshuju form edit Kp7mQ2 --json \'{"name":"2026 活动报名"}\'',
317
+ 'jinshuju form edit Kp7mQ2 --json \'{"setting":{"daily_repeat_close_rule":{"time_periods":[{"start_time":{"hour":11,"minute":0},"end_time":{"hour":12,"minute":40}}]}}}\'',
300
318
  'jinshuju form edit Kp7mQ2 --json \'{"exam_setting":{"total_score":100}}\''
301
319
  ]
302
320
  },
@@ -15,7 +15,9 @@ import { FOLDER } from './folder.js';
15
15
  import { FORM } from './form.js';
16
16
  import { LOCAL } from './local.js';
17
17
  import { OPENSEARCH } from './opensearch.js';
18
+ import { SMS } from './sms.js';
18
19
  import { TABLE } from './table.js';
20
+ import { TRADE } from './trade.js';
19
21
  import { VIEW } from './view.js';
20
22
  /** Resource order in the root help, and the one-liner each gets. */
21
23
  export const RESOURCES = [
@@ -25,7 +27,7 @@ export const RESOURCES = [
25
27
  note: 'login is the browser flow. To use a token instead: `jinshuju config set access_token <token>`, ' +
26
28
  'or set JINSHUJU_ACCESS_TOKEN. `auth status --verify` says which account the credential belongs to.'
27
29
  },
28
- { name: 'account', summary: 'Account and members' },
30
+ { name: 'account', summary: 'Account, members, invoices and what the account paid' },
29
31
  { name: 'folder', summary: 'Manage folders' },
30
32
  {
31
33
  name: 'form',
@@ -39,6 +41,11 @@ export const RESOURCES = [
39
41
  { name: 'entry', summary: 'Manage entries' },
40
42
  { name: 'comment', summary: 'Manage entry comments' },
41
43
  { name: 'opensearch', summary: 'Manage public queries' },
44
+ { name: 'merchant', summary: '小金商户: onboarding, balance and settlement' },
45
+ { name: 'transaction', summary: 'Payment orders placed on payment forms' },
46
+ { name: 'refund', summary: 'Refunds of payment orders' },
47
+ { name: 'payout', summary: 'Payouts to the settlement account' },
48
+ { name: 'sms', summary: 'SMS signature and template review' },
42
49
  { name: 'config', summary: 'Manage CLI configuration' }
43
50
  ];
44
51
  export const COMMANDS = [
@@ -51,7 +58,9 @@ export const COMMANDS = [
51
58
  ...VIEW,
52
59
  ...ENTRY,
53
60
  ...COMMENT,
54
- ...OPENSEARCH
61
+ ...OPENSEARCH,
62
+ ...TRADE,
63
+ ...SMS
55
64
  ];
56
65
  /** The command whose path the words begin with, longest match first. */
57
66
  export function findCommand(words, commands = COMMANDS) {
@@ -0,0 +1,2 @@
1
+ import type { Command } from './types.js';
2
+ export declare const SMS: readonly Command[];
@@ -0,0 +1,9 @@
1
+ import { API } from './shared.js';
2
+ export const SMS = [
3
+ {
4
+ path: ['sms', 'status'],
5
+ 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: () => ({ method: 'GET', path: `${API}/sms/audit_statuses` })
8
+ }
9
+ ];
@@ -0,0 +1,2 @@
1
+ import type { Command } from './types.js';
2
+ export declare const TRADE: readonly Command[];
@@ -0,0 +1,185 @@
1
+ import { PAGINATION_OPTIONS } from '../options.js';
2
+ import { API, paging } from './shared.js';
3
+ /**
4
+ * The account's 小金商户: what its payment forms collected, refunded and paid
5
+ * out. An account collecting through its own bound WeChat / Alipay merchant
6
+ * (直连) has none of this in 金数据, and the reads below say so rather than
7
+ * answering with zeroes.
8
+ */
9
+ const PAID_STATUSES = ['paid', 'unpaid', 'refunded', 'refunding', 'partial_refunded'];
10
+ const RECORD_STATUSES = ['processing', 'success', 'error'];
11
+ const DATE_OPTIONS = [
12
+ {
13
+ name: '--from',
14
+ type: 'string',
15
+ placeholder: '<YYYY-MM-DD>',
16
+ description: 'First day, Asia/Shanghai; give it with --to'
17
+ },
18
+ { name: '--to', type: 'string', placeholder: '<YYYY-MM-DD>', description: 'Last day, inclusive; give it with --from' }
19
+ ];
20
+ /** The CLI spells a dimension as its flag is spelled; the API names it by its parameter. */
21
+ const GROUP_BY = { time: 'time', 'paid-status': 'paid_status', channel: 'payment_channel' };
22
+ const ORDER_FILTER_OPTIONS = [
23
+ {
24
+ name: '--status',
25
+ type: 'string',
26
+ repeatable: true,
27
+ choices: PAID_STATUSES,
28
+ placeholder: '<status>',
29
+ description: 'Keep only these payment statuses, repeatable. Omitted, every status, unpaid included'
30
+ },
31
+ {
32
+ name: '--channel',
33
+ type: 'string',
34
+ choices: ['wxpay', 'alipay'],
35
+ placeholder: '<channel>',
36
+ description: 'Keep only orders paid through this channel: wxpay (微信) or alipay (支付宝)'
37
+ },
38
+ { name: '--form', type: 'string', placeholder: '<token>', description: 'Keep only orders of this payment form' }
39
+ ];
40
+ const INCLUDE_OPTION = {
41
+ name: '--include',
42
+ type: 'string',
43
+ choices: ['both', 'stats', 'records'],
44
+ placeholder: '<what>',
45
+ description: 'both (default), stats for the statistics alone, or records for the rows alone'
46
+ };
47
+ const DETAIL_LIMITS = 'Rows are capped at 90 days and 200 matching records per query; past either, no rows come back, ' +
48
+ 'only detail_limit and the stats for the whole range. Narrow the range rather than splitting it.';
49
+ function dates(input) {
50
+ return {
51
+ start_date: input.options.from,
52
+ end_date: input.options.to
53
+ };
54
+ }
55
+ function orderFilters(input) {
56
+ const statuses = input.options.status ?? [];
57
+ return {
58
+ paid_status: statuses.length > 0 ? statuses : undefined,
59
+ payment_channel: input.options.channel,
60
+ form_token: input.options.form
61
+ };
62
+ }
63
+ export const TRADE = [
64
+ {
65
+ path: ['merchant', 'get'],
66
+ summary: 'Show the 小金商户: where onboarding stands, balance, rate and settlement account',
67
+ description: 'Answers without a merchant too: merchant_stage says where the application stands. Bank card, phone, ' +
68
+ 'email and ID numbers come back masked, as the product shows them.',
69
+ request: () => ({ method: 'GET', path: `${API}/trade/merchant` })
70
+ },
71
+ {
72
+ path: ['transaction', 'list'],
73
+ summary: 'List payment orders customers placed on payment forms',
74
+ description: 'Defaults to the last 90 days; --order-no alone searches all time. ' +
75
+ DETAIL_LIMITS +
76
+ ' For totals or a breakdown, use transaction aggregate instead of adding up rows.',
77
+ options: [
78
+ ...DATE_OPTIONS,
79
+ ...ORDER_FILTER_OPTIONS,
80
+ {
81
+ name: '--order-no',
82
+ type: 'string',
83
+ placeholder: '<no>',
84
+ description: 'Exact match on 交易单号, 商户订单号 or 金数据单号'
85
+ },
86
+ ...PAGINATION_OPTIONS
87
+ ],
88
+ request: (input) => ({
89
+ method: 'GET',
90
+ path: `${API}/trade/transactions`,
91
+ query: {
92
+ ...dates(input),
93
+ ...orderFilters(input),
94
+ order_no: input.options.order_no,
95
+ ...paging(input)
96
+ }
97
+ }),
98
+ paginate: { items: 'transactions', cursor: 'next' },
99
+ examples: [
100
+ 'jinshuju transaction list --from 2026-09-01 --to 2026-09-28',
101
+ 'jinshuju transaction list --order-no 1234567890',
102
+ 'jinshuju transaction list --form Kp7mQ2 --status refunded --status partial_refunded --all'
103
+ ]
104
+ },
105
+ {
106
+ path: ['transaction', 'aggregate'],
107
+ summary: 'Total the payment orders: amount, paid count and order count, optionally grouped',
108
+ description: 'Defaults to the last 30 days, up to 366. The totals cover the whole range whatever the paging of a listing.',
109
+ options: [
110
+ ...DATE_OPTIONS,
111
+ {
112
+ name: '--group-by',
113
+ type: 'string',
114
+ choices: Object.keys(GROUP_BY),
115
+ placeholder: '<dimension>',
116
+ description: 'Break the totals down by one dimension; time picks day, week or month from the span'
117
+ },
118
+ ...ORDER_FILTER_OPTIONS
119
+ ],
120
+ request: (input) => ({
121
+ method: 'GET',
122
+ path: `${API}/trade/transactions/aggregate`,
123
+ query: { ...dates(input), group_by: GROUP_BY[input.options.group_by], ...orderFilters(input) }
124
+ }),
125
+ examples: ['jinshuju transaction aggregate --from 2026-09-01 --to 2026-09-28 --group-by channel']
126
+ },
127
+ {
128
+ path: ['refund', 'list'],
129
+ summary: 'List refunds, with their statistics',
130
+ description: 'Defaults to the last 90 days; --refund-no alone searches all time. ' + DETAIL_LIMITS,
131
+ options: [
132
+ ...DATE_OPTIONS,
133
+ {
134
+ name: '--status',
135
+ type: 'string',
136
+ choices: RECORD_STATUSES,
137
+ placeholder: '<status>',
138
+ description: 'Keep only refunds in this state'
139
+ },
140
+ { name: '--refund-no', type: 'string', placeholder: '<no>', description: 'Exact match on 退款流水号' },
141
+ INCLUDE_OPTION,
142
+ ...PAGINATION_OPTIONS
143
+ ],
144
+ request: (input) => ({
145
+ method: 'GET',
146
+ path: `${API}/trade/refunds`,
147
+ query: {
148
+ ...dates(input),
149
+ status: input.options.status,
150
+ refund_no: input.options.refund_no,
151
+ include: input.options.include,
152
+ ...paging(input)
153
+ }
154
+ }),
155
+ paginate: { items: 'refunds', cursor: 'next' }
156
+ },
157
+ {
158
+ path: ['payout', 'list'],
159
+ summary: 'List payouts (提现) to the settlement account, with their statistics',
160
+ description: 'Defaults to the last 90 days. ' + DETAIL_LIMITS,
161
+ options: [
162
+ ...DATE_OPTIONS,
163
+ {
164
+ name: '--status',
165
+ type: 'string',
166
+ choices: RECORD_STATUSES,
167
+ placeholder: '<status>',
168
+ description: 'Keep only payouts in this state'
169
+ },
170
+ INCLUDE_OPTION,
171
+ ...PAGINATION_OPTIONS
172
+ ],
173
+ request: (input) => ({
174
+ method: 'GET',
175
+ path: `${API}/trade/payouts`,
176
+ query: {
177
+ ...dates(input),
178
+ status: input.options.status,
179
+ include: input.options.include,
180
+ ...paging(input)
181
+ }
182
+ }),
183
+ paginate: { items: 'payouts', cursor: 'next' }
184
+ }
185
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jinshuju/cli",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Command line interface for Jinshuju Open API v1",
5
5
  "homepage": "https://github.com/jinshuju/cli#readme",
6
6
  "bugs": {