@jinshuju/cli 0.10.0 → 0.12.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 +10 -1
- package/dist/commands/account.js +9 -10
- package/dist/commands/checkin.d.ts +2 -0
- package/dist/commands/checkin.js +117 -0
- package/dist/commands/comment.js +10 -11
- package/dist/commands/entry.js +89 -87
- package/dist/commands/field.js +18 -26
- package/dist/commands/fill.d.ts +1 -3
- package/dist/commands/fill.js +17 -9
- package/dist/commands/folder.js +5 -8
- package/dist/commands/form.js +52 -65
- package/dist/commands/index.js +17 -0
- package/dist/commands/opensearch.js +8 -13
- package/dist/commands/shared.d.ts +13 -4
- package/dist/commands/shared.js +12 -8
- package/dist/commands/sms.js +2 -2
- package/dist/commands/table.js +17 -27
- package/dist/commands/trade.js +48 -43
- package/dist/commands/upload.d.ts +9 -2
- package/dist/commands/upload.js +9 -4
- package/dist/commands/view.js +9 -13
- package/dist/generated/operations.d.ts +11 -0
- package/dist/generated/operations.js +4003 -0
- package/dist/options.d.ts +7 -2
- package/dist/options.js +7 -5
- package/dist/spec.d.ts +105 -0
- package/dist/spec.js +201 -0
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -229,6 +229,8 @@ jinshuju entry delete --form Kp7mQ2 12 --yes
|
|
|
229
229
|
jinshuju view create --form Kp7mQ2 "High scores" --filter 'field_3 gte 80' --sort created_at:desc
|
|
230
230
|
jinshuju comment create --form Kp7mQ2 --entry 12 "Contacted, awaiting reply"
|
|
231
231
|
jinshuju opensearch edit Qy7nR3 --disable
|
|
232
|
+
jinshuju checkin create --form Kp7mQ2 # needs the check-in plugin enabled for the account
|
|
233
|
+
jinshuju checkin edit 42 --disable
|
|
232
234
|
```
|
|
233
235
|
|
|
234
236
|
Deletion always requires `--yes`. This CLI is non-interactive — stdin belongs to
|
|
@@ -287,7 +289,7 @@ needs the `submit_entries` scope for these.
|
|
|
287
289
|
|
|
288
290
|
## Working with files
|
|
289
291
|
|
|
290
|
-
|
|
292
|
+
Five commands take a file. The CLI uploads with its own credential; there is no
|
|
291
293
|
ticket to fetch first.
|
|
292
294
|
|
|
293
295
|
```bash
|
|
@@ -297,6 +299,7 @@ jinshuju entry import --table Vn4xR8 ./rows.csv --map field_1=1 --map field_2=2
|
|
|
297
299
|
jinshuju entry create --form Kp7mQ2 --json '{"field_1":"Alice"}' --attach field_5=./id-card.jpg
|
|
298
300
|
jinshuju form theme set Kp7mQ2 --wallpaper ./bg.png
|
|
299
301
|
jinshuju opensearch edit Qy7nR3 --header ./banner.png
|
|
302
|
+
jinshuju form image upload ./venue-map.png # answers with a url for an <img> in a form or field description
|
|
300
303
|
```
|
|
301
304
|
|
|
302
305
|
```bash
|
|
@@ -414,4 +417,10 @@ npm install
|
|
|
414
417
|
npm test
|
|
415
418
|
npm run check # typecheck + oxlint + oxfmt --check, what CI runs
|
|
416
419
|
npm run fmt # format in place with oxfmt
|
|
420
|
+
npm run generate # src/generated from spec/openapi.yaml
|
|
421
|
+
npm run spec:update # fetch the published openapi.yaml, then generate
|
|
417
422
|
```
|
|
423
|
+
|
|
424
|
+
What a request may carry — paths, parameters, the values a flag takes — follows
|
|
425
|
+
`spec/openapi.yaml`, a copy of the published API v1 spec. A daily workflow
|
|
426
|
+
fetches it and opens a pull request when it changes.
|
package/dist/commands/account.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import { LIMIT_OPTION } from '../options.js';
|
|
2
|
-
import {
|
|
2
|
+
import { call } from '../spec.js';
|
|
3
|
+
import { paging } from './shared.js';
|
|
3
4
|
export const ACCOUNT = [
|
|
4
5
|
{
|
|
5
6
|
path: ['account', 'get'],
|
|
6
7
|
summary: 'Show the current account, plan and quota',
|
|
7
|
-
request: () => (
|
|
8
|
+
request: () => call('getBillingAccount')
|
|
8
9
|
},
|
|
9
10
|
{
|
|
10
11
|
path: ['account', 'me'],
|
|
11
12
|
summary: 'Show who is signed in: name, email, mobile and role in the account',
|
|
12
|
-
request: () => (
|
|
13
|
+
request: () => call('getCurrentUser')
|
|
13
14
|
},
|
|
14
15
|
{
|
|
15
16
|
path: ['account', 'member', 'list'],
|
|
16
17
|
summary: 'List account members',
|
|
17
18
|
options: [LIMIT_OPTION],
|
|
18
|
-
request: (input) => (
|
|
19
|
+
request: (input) => call('listBillingAccountUsers', { query: paging(input) })
|
|
19
20
|
},
|
|
20
21
|
{
|
|
21
22
|
path: ['account', 'invoice', 'list'],
|
|
22
23
|
summary: 'List e-invoices, and the amount not invoiced yet',
|
|
23
24
|
description: 'Account admins only, as in the web app; a member is refused with 403.',
|
|
24
|
-
request: () => (
|
|
25
|
+
request: () => call('listBillingAccountInvoices')
|
|
25
26
|
},
|
|
26
27
|
{
|
|
27
28
|
path: ['account', 'payment', 'list'],
|
|
@@ -40,15 +41,13 @@ export const ACCOUNT = [
|
|
|
40
41
|
{ ...LIMIT_OPTION, description: 'Records to return (default 50, up to 1000)' },
|
|
41
42
|
{ name: '--with-balance', type: 'boolean', description: 'Also return the current balance and quotas' }
|
|
42
43
|
],
|
|
43
|
-
request: (input) => ({
|
|
44
|
-
method: 'GET',
|
|
45
|
-
path: `${API}/billing_account/payment_histories`,
|
|
44
|
+
request: (input) => call('listBillingAccountPaymentHistories', {
|
|
46
45
|
query: {
|
|
47
46
|
start_date: input.options.from,
|
|
48
47
|
end_date: input.options.to,
|
|
49
48
|
verb: input.options.verb,
|
|
50
|
-
limit: input.options.limit
|
|
51
|
-
include_balance: input.options.with_balance ?
|
|
49
|
+
limit: input.options.limit,
|
|
50
|
+
include_balance: input.options.with_balance ? true : undefined
|
|
52
51
|
}
|
|
53
52
|
})
|
|
54
53
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { JSON_OPTION, LIMIT_OPTION, UsageError } from '../options.js';
|
|
2
|
+
import { call } from '../spec.js';
|
|
3
|
+
import { YES_OPTION, confirmed, overriding, paging, requiredOption } from './shared.js';
|
|
4
|
+
const CAMPAIGN_ARG = { name: 'campaign', required: true, description: 'Check-in campaign id' };
|
|
5
|
+
const NAME_OPTION = { name: '--name', type: 'string', placeholder: '<name>', description: 'Campaign name' };
|
|
6
|
+
const DISPLAY_FIELD_OPTION = {
|
|
7
|
+
name: '--display-field',
|
|
8
|
+
type: 'string',
|
|
9
|
+
placeholder: '<api-code>',
|
|
10
|
+
description: 'Field shown to staff when they verify a check-in, usually the name'
|
|
11
|
+
};
|
|
12
|
+
const TIMES_EXAMPLE = 'jinshuju checkin edit 42 --json \'{"date_settings":[{"start_date":"2026-10-20","end_date":"2026-10-21",' +
|
|
13
|
+
'"periods":["Tuesday"],"durations":[{"start":"09:00","end":"12:00"}]}]}\'';
|
|
14
|
+
function rest(input) {
|
|
15
|
+
return input.options.json ?? {};
|
|
16
|
+
}
|
|
17
|
+
export const CHECKIN = [
|
|
18
|
+
{
|
|
19
|
+
path: ['checkin', 'list'],
|
|
20
|
+
summary: 'List your check-in campaigns',
|
|
21
|
+
options: [
|
|
22
|
+
{ name: '--form', type: 'string', placeholder: '<token>', description: 'Only the campaigns of this form' },
|
|
23
|
+
LIMIT_OPTION
|
|
24
|
+
],
|
|
25
|
+
request: (input) => call('listCheckinCampaigns', {
|
|
26
|
+
query: { limit: paging(input).limit, form_token: input.options.form }
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
path: ['checkin', 'get'],
|
|
31
|
+
summary: 'Show a check-in campaign and its links',
|
|
32
|
+
args: [CAMPAIGN_ARG],
|
|
33
|
+
request: (input) => call('getCheckinCampaign', { path: { id: input.args.campaign } })
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
path: ['checkin', 'create'],
|
|
37
|
+
summary: 'Turn on check-in for a form',
|
|
38
|
+
description: 'Registrants check in with the field given by --check-in-field, the first mobile field when left out. ' +
|
|
39
|
+
'It cannot be changed afterwards. With a check-in code (the default) the form shows the code after ' +
|
|
40
|
+
'submitting, which takes over its after-submit redirect; --no-check-in-code leaves that alone. ' +
|
|
41
|
+
'Times and a location limit go through --json.',
|
|
42
|
+
options: [
|
|
43
|
+
{ name: '--form', type: 'string', placeholder: '<token>', description: 'Form to check in against' },
|
|
44
|
+
NAME_OPTION,
|
|
45
|
+
{
|
|
46
|
+
name: '--check-in-field',
|
|
47
|
+
type: 'string',
|
|
48
|
+
placeholder: '<api-code>',
|
|
49
|
+
description: 'Field registrants check in with (default: first mobile field, then first name field)'
|
|
50
|
+
},
|
|
51
|
+
DISPLAY_FIELD_OPTION,
|
|
52
|
+
{ name: '--no-check-in-code', type: 'boolean', description: 'Do not show a check-in code after submitting' },
|
|
53
|
+
{
|
|
54
|
+
name: '--unique-check-in-field',
|
|
55
|
+
type: 'boolean',
|
|
56
|
+
description: 'Also make the check-in field required and unique, so every registrant can be found'
|
|
57
|
+
},
|
|
58
|
+
JSON_OPTION
|
|
59
|
+
],
|
|
60
|
+
request: (input) => call('createCheckinCampaign', {
|
|
61
|
+
body: overriding(rest(input), {
|
|
62
|
+
form_token: requiredOption(input, 'form'),
|
|
63
|
+
name: input.options.name,
|
|
64
|
+
checkin_field_api_code: input.options.check_in_field,
|
|
65
|
+
display_field_api_code: input.options.display_field,
|
|
66
|
+
enable_checkin_code: input.options.no_check_in_code ? false : undefined,
|
|
67
|
+
checkin_field_required_unique: input.options.unique_check_in_field || undefined
|
|
68
|
+
})
|
|
69
|
+
}),
|
|
70
|
+
examples: [
|
|
71
|
+
'jinshuju checkin create --form Kp7mQ2',
|
|
72
|
+
'jinshuju checkin create --form Kp7mQ2 --name 年会签到 --json \'{"geo_location":{"longitude":108.9,"latitude":34.2,"range":500}}\''
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
path: ['checkin', 'edit'],
|
|
77
|
+
summary: 'Edit a check-in campaign, or pause and resume it',
|
|
78
|
+
description: 'Only what is named changes. date_settings in --json replaces the times as a whole; an empty list lifts the limit.',
|
|
79
|
+
args: [CAMPAIGN_ARG],
|
|
80
|
+
options: [
|
|
81
|
+
NAME_OPTION,
|
|
82
|
+
DISPLAY_FIELD_OPTION,
|
|
83
|
+
{ name: '--enable', type: 'boolean', description: 'Resume check-in' },
|
|
84
|
+
{ name: '--disable', type: 'boolean', description: 'Pause check-in; records are kept' },
|
|
85
|
+
JSON_OPTION
|
|
86
|
+
],
|
|
87
|
+
request: (input) => {
|
|
88
|
+
if (input.options.enable && input.options.disable) {
|
|
89
|
+
throw new UsageError('--enable and --disable are opposites, pass one');
|
|
90
|
+
}
|
|
91
|
+
return call('updateCheckinCampaign', {
|
|
92
|
+
path: { id: input.args.campaign },
|
|
93
|
+
body: overriding(rest(input), {
|
|
94
|
+
name: input.options.name,
|
|
95
|
+
display_field_api_code: input.options.display_field,
|
|
96
|
+
enabled: input.options.enable ? true : input.options.disable ? false : undefined
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
examples: [
|
|
101
|
+
'jinshuju checkin edit 42 --disable',
|
|
102
|
+
TIMES_EXAMPLE,
|
|
103
|
+
'jinshuju checkin edit 42 --json \'{"geo_location":null}\''
|
|
104
|
+
]
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
path: ['checkin', 'delete'],
|
|
108
|
+
summary: 'Delete a check-in campaign',
|
|
109
|
+
description: 'Its check-in records go with it. To stop check-in for now, use `checkin edit --disable`.',
|
|
110
|
+
args: [CAMPAIGN_ARG],
|
|
111
|
+
options: [YES_OPTION],
|
|
112
|
+
request: (input) => {
|
|
113
|
+
confirmed(input, `Deleting check-in campaign ${input.args.campaign}`);
|
|
114
|
+
return call('deleteCheckinCampaign', { path: { id: input.args.campaign } });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
];
|
package/dist/commands/comment.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CONTAINER_OPTIONS, UsageError } from '../options.js';
|
|
2
|
-
import { YES_OPTION, confirmed,
|
|
2
|
+
import { YES_OPTION, confirmed, given, onContainer } from './shared.js';
|
|
3
3
|
/** A comment lives under its entry, so every verb needs the entry as well. */
|
|
4
4
|
const ENTRY_OPTION = {
|
|
5
5
|
name: '--entry',
|
|
@@ -7,11 +7,11 @@ const ENTRY_OPTION = {
|
|
|
7
7
|
placeholder: '<serial>',
|
|
8
8
|
description: 'Entry serial number'
|
|
9
9
|
};
|
|
10
|
-
function
|
|
10
|
+
function onEntry(input, form, table, parts = {}) {
|
|
11
11
|
const serial = input.options.entry;
|
|
12
12
|
if (!serial)
|
|
13
13
|
throw new UsageError('--entry <serial> is required');
|
|
14
|
-
return
|
|
14
|
+
return onContainer(input, form, table, { ...parts, path: { ...parts.path, serial_number: serial } });
|
|
15
15
|
}
|
|
16
16
|
export const COMMENT = [
|
|
17
17
|
{
|
|
@@ -21,7 +21,7 @@ export const COMMENT = [
|
|
|
21
21
|
...CONTAINER_OPTIONS,
|
|
22
22
|
{ name: '--entry', type: 'string', placeholder: '<serial>', description: 'Entry serial number' }
|
|
23
23
|
],
|
|
24
|
-
request: (input) => (
|
|
24
|
+
request: (input) => onEntry(input, 'listEntryComments', 'listTableEntryComments')
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
path: ['comment', 'create'],
|
|
@@ -32,9 +32,7 @@ export const COMMENT = [
|
|
|
32
32
|
ENTRY_OPTION,
|
|
33
33
|
{ name: '--reply-to', type: 'string', placeholder: '<comment-id>', description: 'Reply under this comment' }
|
|
34
34
|
],
|
|
35
|
-
request: (input) => ({
|
|
36
|
-
method: 'POST',
|
|
37
|
-
path: `${commentsPath(input)}`,
|
|
35
|
+
request: (input) => onEntry(input, 'createEntryComment', 'createTableEntryComment', {
|
|
38
36
|
body: given({ content: input.args.content, parent_id: input.options.reply_to })
|
|
39
37
|
}),
|
|
40
38
|
examples: ['jinshuju comment create --form Kp7mQ2 --entry 12 "已联系,等回复"']
|
|
@@ -47,9 +45,8 @@ export const COMMENT = [
|
|
|
47
45
|
{ name: 'content', required: true, description: 'New comment text' }
|
|
48
46
|
],
|
|
49
47
|
options: [...CONTAINER_OPTIONS, ENTRY_OPTION],
|
|
50
|
-
request: (input) => ({
|
|
51
|
-
|
|
52
|
-
path: `${commentsPath(input)}/${input.args.comment}`,
|
|
48
|
+
request: (input) => onEntry(input, 'updateEntryComment', 'updateTableEntryComment', {
|
|
49
|
+
path: { comment_id: input.args.comment },
|
|
53
50
|
body: { content: input.args.content }
|
|
54
51
|
})
|
|
55
52
|
},
|
|
@@ -60,7 +57,9 @@ export const COMMENT = [
|
|
|
60
57
|
options: [...CONTAINER_OPTIONS, ENTRY_OPTION, YES_OPTION],
|
|
61
58
|
request: (input) => {
|
|
62
59
|
confirmed(input, `Deleting comment ${input.args.comment}`);
|
|
63
|
-
return
|
|
60
|
+
return onEntry(input, 'deleteEntryComment', 'deleteTableEntryComment', {
|
|
61
|
+
path: { comment_id: input.args.comment }
|
|
62
|
+
});
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
];
|
package/dist/commands/entry.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { CONTAINER_LIST_OPTIONS, CONTAINER_OPTIONS, FILTER_OPTION, FILTERS_OPTION, JSON_OPTION, MINE_OPTION, PAGINATION_OPTIONS, SORT_OPTION, TIME_BUCKETS, UsageError, parseDimension, parseFilter, parseMetric, namedContainers, resolveContainer, resolveContainers } from '../options.js';
|
|
2
|
-
import {
|
|
2
|
+
import { LISTING, YES_OPTION, confirmed, filters, given, onContainer, paging, payload, refuseWithMine, requiredOption, sort } from './shared.js';
|
|
3
3
|
import { RefusedError } from '../errors.js';
|
|
4
4
|
import { progress } from '../progress.js';
|
|
5
5
|
import { TransportError } from '../http.js';
|
|
6
|
+
import { call, choices } from '../spec.js';
|
|
6
7
|
import { isRecord } from '../values.js';
|
|
7
8
|
import { basename } from 'node:path';
|
|
8
9
|
import { upload } from './upload.js';
|
|
9
|
-
/** What the batch count endpoint accepts, and what the design document states. */
|
|
10
|
-
const MAX_COUNTED_CONTAINERS = 10;
|
|
11
10
|
function list(value) {
|
|
12
11
|
const values = value;
|
|
13
12
|
return values && values.length > 0 ? values.join(',') : undefined;
|
|
14
13
|
}
|
|
15
14
|
function labels(input) {
|
|
16
|
-
return input.options.labels ?
|
|
15
|
+
return input.options.labels ? true : undefined;
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* The web host is not the API host on every environment, so the link is the
|
|
@@ -160,10 +159,7 @@ export async function awaitImport(client, token, jobId, watching) {
|
|
|
160
159
|
for (;;) {
|
|
161
160
|
let job;
|
|
162
161
|
try {
|
|
163
|
-
job = await client.request({
|
|
164
|
-
method: 'GET',
|
|
165
|
-
path: `${API}/forms/${token}/entry_imports/${jobId}`
|
|
166
|
-
});
|
|
162
|
+
job = await client.request(call('getEntryImport', { path: { form_token: token, id: jobId } }));
|
|
167
163
|
}
|
|
168
164
|
catch (error) {
|
|
169
165
|
throw recoverable(`the import started, but asking how it is going failed: ${error.message}`, error);
|
|
@@ -202,7 +198,7 @@ async function withUploads(input, client, attached) {
|
|
|
202
198
|
try {
|
|
203
199
|
for (const { field, row, dimension, file } of attached) {
|
|
204
200
|
watching.step(`uploading ${basename(file)}…`);
|
|
205
|
-
const uploaded = await client.request(upload(
|
|
201
|
+
const uploaded = await client.request(upload('uploadEntryAttachment', { form_token: token }, file, dimension === undefined ? { field_api_code: field } : { field_api_code: field, dimension_api_code: dimension }));
|
|
206
202
|
// A field holds a list of attachments, so each upload appends rather
|
|
207
203
|
// than replacing what an earlier --attach for the same field put there.
|
|
208
204
|
if (dimension === undefined) {
|
|
@@ -250,18 +246,38 @@ const ANALYSIS_VIEW_OPTION = {
|
|
|
250
246
|
placeholder: '<view>',
|
|
251
247
|
description: 'Only the entries this view shows; a filter narrows them further'
|
|
252
248
|
};
|
|
249
|
+
const COUNT = {
|
|
250
|
+
form: 'countEntries',
|
|
251
|
+
table: 'countTableEntries',
|
|
252
|
+
formView: 'countFormViewEntries',
|
|
253
|
+
tableView: 'countTableViewEntries'
|
|
254
|
+
};
|
|
255
|
+
const AGGREGATE = {
|
|
256
|
+
form: 'aggregateEntries',
|
|
257
|
+
table: 'aggregateTableEntries',
|
|
258
|
+
formView: 'aggregateFormViewEntries',
|
|
259
|
+
tableView: 'aggregateTableViewEntries'
|
|
260
|
+
};
|
|
261
|
+
const SUMMARY = {
|
|
262
|
+
form: 'summarizeEntries',
|
|
263
|
+
table: 'summarizeTableEntries',
|
|
264
|
+
formView: 'summarizeFormViewEntries',
|
|
265
|
+
tableView: 'summarizeTableViewEntries'
|
|
266
|
+
};
|
|
253
267
|
/** Through a view, an analysis covers only the entries that view shows. */
|
|
254
|
-
function
|
|
268
|
+
function analysis(input, ops, query) {
|
|
255
269
|
const view = input.options.view;
|
|
256
|
-
return
|
|
270
|
+
return view
|
|
271
|
+
? onContainer(input, ops.formView, ops.tableView, { path: { view_token: view }, query })
|
|
272
|
+
: onContainer(input, ops.form, ops.table, { query });
|
|
257
273
|
}
|
|
258
274
|
/**
|
|
259
275
|
* Batch writes are served under the forms path alone, and it takes a table's
|
|
260
|
-
* token just as well, so a table batches through the same
|
|
276
|
+
* token just as well, so a table batches through the same operation.
|
|
261
277
|
*/
|
|
262
|
-
function
|
|
278
|
+
function batch(input, id, entries) {
|
|
263
279
|
const { token } = resolveContainer(input.options);
|
|
264
|
-
return
|
|
280
|
+
return call(id, { path: { form_token: token }, body: { entries } });
|
|
265
281
|
}
|
|
266
282
|
export const ENTRY = [
|
|
267
283
|
{
|
|
@@ -284,9 +300,8 @@ export const ENTRY = [
|
|
|
284
300
|
if (input.options.mine) {
|
|
285
301
|
refuseWithMine(input, ['view', 'sort']);
|
|
286
302
|
const { token } = resolveContainer(input.options);
|
|
287
|
-
return {
|
|
288
|
-
|
|
289
|
-
path: `${API}/my/forms/${token}/entries`,
|
|
303
|
+
return call('listMySubmittedEntries', {
|
|
304
|
+
path: { form_token: token },
|
|
290
305
|
query: {
|
|
291
306
|
filters: filters(input),
|
|
292
307
|
keyword: input.options.keyword,
|
|
@@ -294,7 +309,7 @@ export const ENTRY = [
|
|
|
294
309
|
include_labels: labels(input),
|
|
295
310
|
...paging(input)
|
|
296
311
|
}
|
|
297
|
-
};
|
|
312
|
+
});
|
|
298
313
|
}
|
|
299
314
|
const view = input.options.view;
|
|
300
315
|
if (view) {
|
|
@@ -311,15 +326,16 @@ export const ENTRY = [
|
|
|
311
326
|
throw new UsageError('--fields cannot be combined with --view: the view decides its own columns. ' +
|
|
312
327
|
'Change them with `view edit --columns`, or read the form without --view.');
|
|
313
328
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
329
|
+
// A view is read fifty rows a page, and the API takes no page size for it.
|
|
330
|
+
if (input.options.limit !== undefined) {
|
|
331
|
+
throw new UsageError('--limit cannot be combined with --view: a view is read 50 rows a page');
|
|
332
|
+
}
|
|
333
|
+
return onContainer(input, 'listFormViewEntries', 'listTableViewEntries', {
|
|
334
|
+
path: { view_token: view },
|
|
335
|
+
query: { include_labels: labels(input), next: input.options.next }
|
|
336
|
+
});
|
|
319
337
|
}
|
|
320
|
-
return {
|
|
321
|
-
method: 'GET',
|
|
322
|
-
path: `${containerPath(input)}/entries`,
|
|
338
|
+
return onContainer(input, 'listEntries', 'listTableEntries', {
|
|
323
339
|
query: {
|
|
324
340
|
filters: filters(input),
|
|
325
341
|
keyword: input.options.keyword,
|
|
@@ -328,7 +344,7 @@ export const ENTRY = [
|
|
|
328
344
|
sort: sort(input, 'api_code'),
|
|
329
345
|
...paging(input)
|
|
330
346
|
}
|
|
331
|
-
};
|
|
347
|
+
});
|
|
332
348
|
},
|
|
333
349
|
paginate: LISTING,
|
|
334
350
|
examples: [
|
|
@@ -352,14 +368,17 @@ export const ENTRY = [
|
|
|
352
368
|
FILTERS_OPTION
|
|
353
369
|
],
|
|
354
370
|
request: (input) => {
|
|
355
|
-
const { tokens } = resolveContainers(input.options
|
|
356
|
-
const
|
|
371
|
+
const { tokens } = resolveContainers(input.options);
|
|
372
|
+
const keyword = input.options.keyword;
|
|
357
373
|
if (tokens.length === 1)
|
|
358
|
-
return
|
|
374
|
+
return analysis(input, COUNT, { filters: filters(input), keyword });
|
|
359
375
|
if (input.options.view !== undefined) {
|
|
360
376
|
throw new UsageError('--view belongs to one form or table, so it counts one container, not several');
|
|
361
377
|
}
|
|
362
|
-
|
|
378
|
+
if (keyword !== undefined) {
|
|
379
|
+
throw new UsageError('--keyword searches the fields of one form or table, so it counts one container, not several');
|
|
380
|
+
}
|
|
381
|
+
return call('countEntriesAcrossForms', { query: { filters: filters(input), form_tokens: tokens.join(',') } });
|
|
363
382
|
},
|
|
364
383
|
examples: [
|
|
365
384
|
"jinshuju entry count --form Kp7mQ2 --filter 'field_3 gte 80'",
|
|
@@ -393,25 +412,21 @@ export const ENTRY = [
|
|
|
393
412
|
const { tokens } = namedContainers(input.options);
|
|
394
413
|
if (input.options.mine) {
|
|
395
414
|
refuseWithMine(input, ['table', 'scope_filter']);
|
|
396
|
-
return {
|
|
397
|
-
method: 'GET',
|
|
398
|
-
path: `${API}/my/search`,
|
|
415
|
+
return call('searchMySubmittedEntries', {
|
|
399
416
|
query: {
|
|
400
417
|
keyword: input.args.keyword,
|
|
401
418
|
form_tokens: tokens.length > 0 ? tokens.join(',') : undefined
|
|
402
419
|
}
|
|
403
|
-
};
|
|
420
|
+
});
|
|
404
421
|
}
|
|
405
422
|
const scope = input.options.scope_filter ?? [];
|
|
406
|
-
return {
|
|
407
|
-
method: 'GET',
|
|
408
|
-
path: `${API}/entries/search`,
|
|
423
|
+
return call('searchEntriesAcrossForms', {
|
|
409
424
|
query: {
|
|
410
425
|
keyword: input.args.keyword,
|
|
411
426
|
form_tokens: tokens.length > 0 ? tokens.join(',') : undefined,
|
|
412
427
|
filters: scope.length > 0 ? JSON.stringify(scope.map(parseFilter)) : undefined
|
|
413
428
|
}
|
|
414
|
-
};
|
|
429
|
+
});
|
|
415
430
|
},
|
|
416
431
|
examples: [
|
|
417
432
|
'jinshuju entry search 某某公司',
|
|
@@ -441,7 +456,7 @@ export const ENTRY = [
|
|
|
441
456
|
{
|
|
442
457
|
name: '--kind',
|
|
443
458
|
type: 'string',
|
|
444
|
-
choices:
|
|
459
|
+
choices: choices('getEntryStats', 'kind'),
|
|
445
460
|
placeholder: '<kind>',
|
|
446
461
|
description: 'Count only forms, or only tables'
|
|
447
462
|
},
|
|
@@ -454,21 +469,19 @@ export const ENTRY = [
|
|
|
454
469
|
{
|
|
455
470
|
name: '--by',
|
|
456
471
|
type: 'string',
|
|
457
|
-
choices:
|
|
472
|
+
choices: choices('getEntryStats', 'by'),
|
|
458
473
|
placeholder: '<unit>',
|
|
459
474
|
description: 'Also split the range into buckets: every one, empty ones with total 0, --limit per bucket. ' +
|
|
460
475
|
'Weeks start on Monday; the first and last are clipped to the range. ' +
|
|
461
476
|
'At most 92 days, 53 weeks or 24 months'
|
|
462
477
|
}
|
|
463
478
|
],
|
|
464
|
-
request: (input) => ({
|
|
465
|
-
method: 'GET',
|
|
466
|
-
path: `${API}/entries/stats`,
|
|
479
|
+
request: (input) => call('getEntryStats', {
|
|
467
480
|
query: {
|
|
468
481
|
from: requiredOption(input, 'from'),
|
|
469
482
|
to: input.options.to,
|
|
470
483
|
kind: input.options.kind,
|
|
471
|
-
limit: input.options.limit
|
|
484
|
+
limit: input.options.limit,
|
|
472
485
|
by: input.options.by
|
|
473
486
|
}
|
|
474
487
|
}),
|
|
@@ -515,16 +528,12 @@ export const ENTRY = [
|
|
|
515
528
|
if (metrics.length === 0)
|
|
516
529
|
throw new UsageError('--metric <func>:<field> is required, up to 20');
|
|
517
530
|
const dimensions = input.options.by ?? [];
|
|
518
|
-
return {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
limit: input.options.limit === undefined ? undefined : String(input.options.limit),
|
|
525
|
-
filters: filters(input)
|
|
526
|
-
}
|
|
527
|
-
};
|
|
531
|
+
return analysis(input, AGGREGATE, {
|
|
532
|
+
metrics: JSON.stringify(metrics.map(parseMetric)),
|
|
533
|
+
dimensions: dimensions.length > 0 ? JSON.stringify(dimensions.map(parseDimension)) : undefined,
|
|
534
|
+
limit: input.options.limit,
|
|
535
|
+
filters: filters(input)
|
|
536
|
+
});
|
|
528
537
|
},
|
|
529
538
|
render: aggregateTable,
|
|
530
539
|
examples: [
|
|
@@ -554,14 +563,10 @@ export const ENTRY = [
|
|
|
554
563
|
FILTER_OPTION,
|
|
555
564
|
FILTERS_OPTION
|
|
556
565
|
],
|
|
557
|
-
request: (input) => ({
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
fields: list(input.options.fields),
|
|
562
|
-
include_overview: input.options.no_overview ? 'false' : undefined,
|
|
563
|
-
filters: filters(input)
|
|
564
|
-
}
|
|
566
|
+
request: (input) => analysis(input, SUMMARY, {
|
|
567
|
+
fields: list(input.options.fields),
|
|
568
|
+
include_overview: input.options.no_overview ? false : undefined,
|
|
569
|
+
filters: filters(input)
|
|
565
570
|
}),
|
|
566
571
|
examples: [
|
|
567
572
|
'jinshuju entry summary --form Kp7mQ2',
|
|
@@ -580,16 +585,16 @@ export const ENTRY = [
|
|
|
580
585
|
options: [...CONTAINER_OPTIONS, JSON_OPTION, BATCH_OPTION, ATTACH_OPTION],
|
|
581
586
|
run: async (input, client) => {
|
|
582
587
|
const attached = attachments(input);
|
|
583
|
-
const
|
|
588
|
+
const rows = batchRows(input);
|
|
584
589
|
if (attached.length === 0) {
|
|
585
|
-
if (
|
|
586
|
-
return client.request(
|
|
587
|
-
return client.request(
|
|
590
|
+
if (rows)
|
|
591
|
+
return client.request(batch(input, 'createEntriesBatch', rows));
|
|
592
|
+
return client.request(onContainer(input, 'createEntry', 'createTableEntry', { body: payload(input) }));
|
|
588
593
|
}
|
|
589
|
-
if (
|
|
594
|
+
if (rows !== undefined)
|
|
590
595
|
throw new UsageError('--attach cannot be combined with --batch');
|
|
591
596
|
const body = await withUploads(input, client, attached);
|
|
592
|
-
return await client.request(
|
|
597
|
+
return await client.request(onContainer(input, 'createEntry', 'createTableEntry', { body }));
|
|
593
598
|
},
|
|
594
599
|
examples: [
|
|
595
600
|
'jinshuju entry create --form Kp7mQ2 --json \'{"field_1":"张三"}\'',
|
|
@@ -623,16 +628,16 @@ export const ENTRY = [
|
|
|
623
628
|
// that arrived without one had no way to gain one. The upload happens first
|
|
624
629
|
// and its id joins the patch, exactly as it does on create.
|
|
625
630
|
run: async (input, client) => {
|
|
626
|
-
const
|
|
631
|
+
const rows = batchRows(input);
|
|
627
632
|
const attached = attachments(input);
|
|
628
|
-
if (
|
|
633
|
+
if (rows) {
|
|
629
634
|
if (input.args.serial)
|
|
630
635
|
throw new UsageError('--batch carries its own serial numbers, so <serial> is not taken');
|
|
631
636
|
if (input.options.replace)
|
|
632
637
|
throw new UsageError('--replace cannot be combined with --batch');
|
|
633
638
|
if (attached.length > 0)
|
|
634
639
|
throw new UsageError('--attach cannot be combined with --batch');
|
|
635
|
-
return client.request(
|
|
640
|
+
return client.request(batch(input, 'patchEntriesBatch', rows));
|
|
636
641
|
}
|
|
637
642
|
if (!input.args.serial) {
|
|
638
643
|
throw new UsageError(attached.length > 0
|
|
@@ -640,11 +645,10 @@ export const ENTRY = [
|
|
|
640
645
|
: '<serial> is required, or pass --batch');
|
|
641
646
|
}
|
|
642
647
|
const body = attached.length > 0 ? await withUploads(input, client, attached) : payload(input);
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
body
|
|
647
|
-
});
|
|
648
|
+
const path = { serial_number: input.args.serial };
|
|
649
|
+
return client.request(input.options.replace
|
|
650
|
+
? onContainer(input, 'replaceEntry', 'replaceTableEntry', { path, body })
|
|
651
|
+
: onContainer(input, 'updateEntry', 'updateTableEntry', { path, body }));
|
|
648
652
|
},
|
|
649
653
|
examples: [
|
|
650
654
|
'jinshuju entry update --form Kp7mQ2 12 --json \'{"field_1":"李四"}\'',
|
|
@@ -695,18 +699,17 @@ export const ENTRY = [
|
|
|
695
699
|
const watching = progress();
|
|
696
700
|
try {
|
|
697
701
|
watching.step(`uploading ${basename(input.args.file)}…`);
|
|
698
|
-
const uploaded = await client.request(upload(
|
|
702
|
+
const uploaded = await client.request(upload('uploadImportFile', { form_token: token }, input.args.file));
|
|
699
703
|
watching.step('starting the import…');
|
|
700
|
-
const started = await client.request({
|
|
701
|
-
|
|
702
|
-
path: `${API}/forms/${token}/entry_imports`,
|
|
704
|
+
const started = await client.request(call('createEntryImport', {
|
|
705
|
+
path: { form_token: token },
|
|
703
706
|
body: given({
|
|
704
707
|
attachment_id: uploaded.id,
|
|
705
708
|
columns: mappings.map(parseColumnMapping),
|
|
706
709
|
header_row_index: input.options.header_row,
|
|
707
710
|
unique_field_code: input.options.unique
|
|
708
711
|
})
|
|
709
|
-
});
|
|
712
|
+
}));
|
|
710
713
|
if (!input.options.wait)
|
|
711
714
|
return started;
|
|
712
715
|
return await awaitImport(client, token, started.job_id, watching);
|
|
@@ -730,7 +733,7 @@ export const ENTRY = [
|
|
|
730
733
|
options: [...CONTAINER_OPTIONS],
|
|
731
734
|
request: (input) => {
|
|
732
735
|
const { token } = resolveContainer(input.options);
|
|
733
|
-
return
|
|
736
|
+
return call('getEntryImport', { path: { form_token: token, id: input.args.job } });
|
|
734
737
|
},
|
|
735
738
|
examples: ['jinshuju entry import-status --form Kp7mQ2 6ab12edb3134316548d106a9']
|
|
736
739
|
},
|
|
@@ -741,7 +744,7 @@ export const ENTRY = [
|
|
|
741
744
|
options: [...CONTAINER_OPTIONS, YES_OPTION],
|
|
742
745
|
request: (input) => {
|
|
743
746
|
confirmed(input, `Deleting entry ${input.args.serial}`);
|
|
744
|
-
return
|
|
747
|
+
return onContainer(input, 'deleteEntry', 'deleteTableEntry', { path: { serial_number: input.args.serial } });
|
|
745
748
|
},
|
|
746
749
|
examples: ['jinshuju entry delete --form Kp7mQ2 12 --yes']
|
|
747
750
|
},
|
|
@@ -755,9 +758,8 @@ export const ENTRY = [
|
|
|
755
758
|
{ name: '--fields', type: 'list', placeholder: '<api-code,...>', description: 'Return only these fields' },
|
|
756
759
|
LABELS_OPTION
|
|
757
760
|
],
|
|
758
|
-
request: (input) => ({
|
|
759
|
-
|
|
760
|
-
path: `${containerPath(input)}/entries/${input.args.serial}`,
|
|
761
|
+
request: (input) => onContainer(input, 'getEntry', 'getTableEntry', {
|
|
762
|
+
path: { serial_number: input.args.serial },
|
|
761
763
|
query: { fields: list(input.options.fields), include_labels: labels(input) }
|
|
762
764
|
})
|
|
763
765
|
}
|