@jinshuju/cli 0.8.0 → 0.10.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 +18 -0
- package/dist/commands/entry.js +24 -9
- package/dist/commands/fill.d.ts +4 -0
- package/dist/commands/fill.js +70 -0
- package/dist/commands/index.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -160,6 +160,8 @@ jinshuju entry aggregate --form Kp7mQ2 --metric count:field_1 --by created_at:mo
|
|
|
160
160
|
|
|
161
161
|
jinshuju entry summary --form Kp7mQ2
|
|
162
162
|
jinshuju entry summary --form Kp7mQ2 --fields field_3,field_7 --no-overview
|
|
163
|
+
|
|
164
|
+
jinshuju entry count --form Kp7mQ2 --view aB3dE9 --filter 'field_3 gte 80' # only what the view shows
|
|
163
165
|
```
|
|
164
166
|
|
|
165
167
|
`--metric <func>:<field>` is repeatable, 1–20 of them; `--by <field>[:day|week|month]`
|
|
@@ -267,6 +269,22 @@ you need no permission on the form itself. Flags that only make sense from an
|
|
|
267
269
|
owner's point of view (`--sort`, `--view`, `--scope-filter` and the like) are
|
|
268
270
|
rejected when combined with `--mine`.
|
|
269
271
|
|
|
272
|
+
## Filling in someone else's form
|
|
273
|
+
|
|
274
|
+
A fill link — `…/f/<token>` for a form, `…/v/<token>` for a table's form view —
|
|
275
|
+
can be filled from the CLI the way anyone with the link fills it in a browser:
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
jinshuju fill get https://acme.jinshuju.net/v/aB3dE9 # what it asks for, and whether you can submit
|
|
279
|
+
jinshuju fill submit https://acme.jinshuju.net/v/aB3dE9 --json '{"field_1":"Ada"}'
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
No role on the form is needed, and only what the page shows its fillers comes
|
|
283
|
+
back. The entry is recorded as yours. A page that asks for something only the
|
|
284
|
+
person at it can do — a captcha, an SMS code, WeChat, a payment — lists it under
|
|
285
|
+
`blockers`, and is refused until it is filled in a browser. An OAuth session
|
|
286
|
+
needs the `submit_entries` scope for these.
|
|
287
|
+
|
|
270
288
|
## Working with files
|
|
271
289
|
|
|
272
290
|
Four commands take a file. The CLI uploads with its own credential; there is no
|
package/dist/commands/entry.js
CHANGED
|
@@ -244,6 +244,17 @@ function batchRows(input) {
|
|
|
244
244
|
throw new UsageError('--batch must be a list');
|
|
245
245
|
return rows;
|
|
246
246
|
}
|
|
247
|
+
const ANALYSIS_VIEW_OPTION = {
|
|
248
|
+
name: '--view',
|
|
249
|
+
type: 'string',
|
|
250
|
+
placeholder: '<view>',
|
|
251
|
+
description: 'Only the entries this view shows; a filter narrows them further'
|
|
252
|
+
};
|
|
253
|
+
/** Through a view, an analysis covers only the entries that view shows. */
|
|
254
|
+
function analysisPath(input, read) {
|
|
255
|
+
const view = input.options.view;
|
|
256
|
+
return `${containerPath(input)}${view ? `/views/${view}` : ''}/entries/${read}`;
|
|
257
|
+
}
|
|
247
258
|
/**
|
|
248
259
|
* Batch writes are served under the forms path alone, and it takes a table's
|
|
249
260
|
* token just as well, so a table batches through the same URL.
|
|
@@ -336,23 +347,23 @@ export const ENTRY = [
|
|
|
336
347
|
options: [
|
|
337
348
|
...CONTAINER_LIST_OPTIONS,
|
|
338
349
|
{ name: '--keyword', type: 'string', placeholder: '<kw>', description: 'Search every searchable field at once' },
|
|
350
|
+
ANALYSIS_VIEW_OPTION,
|
|
339
351
|
FILTER_OPTION,
|
|
340
352
|
FILTERS_OPTION
|
|
341
353
|
],
|
|
342
354
|
request: (input) => {
|
|
343
|
-
const { tokens
|
|
355
|
+
const { tokens } = resolveContainers(input.options, MAX_COUNTED_CONTAINERS);
|
|
344
356
|
const query = { filters: filters(input), keyword: input.options.keyword };
|
|
345
|
-
if (tokens.length === 1)
|
|
346
|
-
return {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
query
|
|
350
|
-
};
|
|
357
|
+
if (tokens.length === 1)
|
|
358
|
+
return { method: 'GET', path: analysisPath(input, 'count'), query };
|
|
359
|
+
if (input.options.view !== undefined) {
|
|
360
|
+
throw new UsageError('--view belongs to one form or table, so it counts one container, not several');
|
|
351
361
|
}
|
|
352
362
|
return { method: 'GET', path: `${API}/entries/count`, query: { ...query, form_tokens: tokens.join(',') } };
|
|
353
363
|
},
|
|
354
364
|
examples: [
|
|
355
365
|
"jinshuju entry count --form Kp7mQ2 --filter 'field_3 gte 80'",
|
|
366
|
+
'jinshuju entry count --form Kp7mQ2 --view aB3dE9',
|
|
356
367
|
'jinshuju entry count --form Kp7mQ2 --form Vn4xR8 --form aB3dE9'
|
|
357
368
|
]
|
|
358
369
|
},
|
|
@@ -495,6 +506,7 @@ export const ENTRY = [
|
|
|
495
506
|
placeholder: '<n>',
|
|
496
507
|
description: 'How many groups, ranked by the first metric (default 20, max 200)'
|
|
497
508
|
},
|
|
509
|
+
ANALYSIS_VIEW_OPTION,
|
|
498
510
|
FILTER_OPTION,
|
|
499
511
|
FILTERS_OPTION
|
|
500
512
|
],
|
|
@@ -505,7 +517,7 @@ export const ENTRY = [
|
|
|
505
517
|
const dimensions = input.options.by ?? [];
|
|
506
518
|
return {
|
|
507
519
|
method: 'GET',
|
|
508
|
-
path:
|
|
520
|
+
path: analysisPath(input, 'aggregate'),
|
|
509
521
|
query: {
|
|
510
522
|
metrics: JSON.stringify(metrics.map(parseMetric)),
|
|
511
523
|
dimensions: dimensions.length > 0 ? JSON.stringify(dimensions.map(parseDimension)) : undefined,
|
|
@@ -518,6 +530,7 @@ export const ENTRY = [
|
|
|
518
530
|
examples: [
|
|
519
531
|
'jinshuju entry aggregate --form Kp7mQ2 --metric avg:field_3',
|
|
520
532
|
'jinshuju entry aggregate --form Kp7mQ2 --metric count:field_1 --by created_at:month',
|
|
533
|
+
'jinshuju entry aggregate --form Kp7mQ2 --view aB3dE9 --metric sum:field_5',
|
|
521
534
|
"jinshuju entry aggregate --form Kp7mQ2 --metric sum:field_5 --by field_7 --limit 5 --filter 'created_at within_last 30d'"
|
|
522
535
|
]
|
|
523
536
|
},
|
|
@@ -537,12 +550,13 @@ export const ENTRY = [
|
|
|
537
550
|
description: 'Profile only these fields, at most 60'
|
|
538
551
|
},
|
|
539
552
|
{ name: '--no-overview', type: 'boolean', description: 'Leave out the form-level totals' },
|
|
553
|
+
ANALYSIS_VIEW_OPTION,
|
|
540
554
|
FILTER_OPTION,
|
|
541
555
|
FILTERS_OPTION
|
|
542
556
|
],
|
|
543
557
|
request: (input) => ({
|
|
544
558
|
method: 'GET',
|
|
545
|
-
path:
|
|
559
|
+
path: analysisPath(input, 'summary'),
|
|
546
560
|
query: {
|
|
547
561
|
fields: list(input.options.fields),
|
|
548
562
|
include_overview: input.options.no_overview ? 'false' : undefined,
|
|
@@ -551,6 +565,7 @@ export const ENTRY = [
|
|
|
551
565
|
}),
|
|
552
566
|
examples: [
|
|
553
567
|
'jinshuju entry summary --form Kp7mQ2',
|
|
568
|
+
'jinshuju entry summary --form Kp7mQ2 --view aB3dE9',
|
|
554
569
|
'jinshuju entry summary --form Kp7mQ2 --fields field_3,field_7 --no-overview'
|
|
555
570
|
]
|
|
556
571
|
},
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { UsageError } from '../errors.js';
|
|
2
|
+
import { JSON_OPTION } from '../options.js';
|
|
3
|
+
// The two kinds of fill page: `/f/<token>` for a form, `/v/<token>` for a
|
|
4
|
+
// table's form view. The API path mirrors them, so a link is all it takes.
|
|
5
|
+
const ROUTES = ['f', 'v'];
|
|
6
|
+
const PAGE_ARG = {
|
|
7
|
+
name: 'page',
|
|
8
|
+
required: true,
|
|
9
|
+
description: 'The fill link as shared, e.g. https://example.jinshuju.net/v/aB3dE9, or just its path: v/aB3dE9'
|
|
10
|
+
};
|
|
11
|
+
/** `/api/v1/fill/<route>/<token>` for a fill link, or for the `f/…` / `v/…` path of one. */
|
|
12
|
+
export function fillPagePath(input) {
|
|
13
|
+
const page = input.args.page.trim();
|
|
14
|
+
let path = page;
|
|
15
|
+
if (/^https?:\/\//i.test(page)) {
|
|
16
|
+
try {
|
|
17
|
+
path = new URL(page).pathname;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new UsageError(`Not a link: ${page}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const [route, token] = path.split('/').filter(Boolean);
|
|
24
|
+
if (route === undefined || !ROUTES.includes(route) || !token) {
|
|
25
|
+
throw new UsageError(`Not a fill link: ${page}. A fill link ends in /f/<token> or /v/<token>.`);
|
|
26
|
+
}
|
|
27
|
+
return `/api/v1/fill/${route}/${encodeURIComponent(token)}`;
|
|
28
|
+
}
|
|
29
|
+
export const FILL = [
|
|
30
|
+
{
|
|
31
|
+
path: ['fill', 'get'],
|
|
32
|
+
summary: 'Show what a fill page asks for, and whether you can submit to it',
|
|
33
|
+
description: 'Reads the page as anyone with its link would: no role on the form or table is needed, and only what ' +
|
|
34
|
+
'the page shows its fillers comes back. `status.key` is `open` when you can submit. `blockers` lists ' +
|
|
35
|
+
'what only the person at the page can do — a captcha, an SMS code, WeChat, a payment — and while it is ' +
|
|
36
|
+
'not empty the page has to be filled in a browser. `manageable` appears only when you could already ' +
|
|
37
|
+
'read the form or table behind the page.',
|
|
38
|
+
args: [PAGE_ARG],
|
|
39
|
+
request: (input) => ({ method: 'GET', path: fillPagePath(input) }),
|
|
40
|
+
examples: ['jinshuju fill get https://example.jinshuju.net/v/aB3dE9', 'jinshuju fill get f/Kp7mQ2']
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
path: ['fill', 'submit'],
|
|
44
|
+
summary: 'Submit an entry through a fill page',
|
|
45
|
+
description: 'Submits as you, the way the page’s submit button does: only the fields the page shows are taken, the ' +
|
|
46
|
+
'page’s required set applies, and the entry is recorded as yours. The payload is keyed by field ' +
|
|
47
|
+
'api_code, as `fill get` lists them.',
|
|
48
|
+
args: [PAGE_ARG],
|
|
49
|
+
options: [
|
|
50
|
+
JSON_OPTION,
|
|
51
|
+
{ name: '--password', type: 'string', placeholder: '<password>', description: 'The page’s access password' }
|
|
52
|
+
],
|
|
53
|
+
payload: [
|
|
54
|
+
'{ "field_1": "张三", "field_2": "Abc1" }',
|
|
55
|
+
'',
|
|
56
|
+
'Each type takes a value of its own shape — a choice by its code, as `fill get` lists them —',
|
|
57
|
+
'and `jinshuju field types <Type>` shows it under `value`.'
|
|
58
|
+
],
|
|
59
|
+
request: (input) => {
|
|
60
|
+
const entry = input.options.json;
|
|
61
|
+
if (entry === undefined)
|
|
62
|
+
throw new UsageError('--json is required: the values to submit, keyed by api_code');
|
|
63
|
+
const body = { entry };
|
|
64
|
+
if (input.options.password !== undefined)
|
|
65
|
+
body.password = input.options.password;
|
|
66
|
+
return { method: 'POST', path: `${fillPagePath(input)}/entries`, body };
|
|
67
|
+
},
|
|
68
|
+
examples: ['jinshuju fill submit https://example.jinshuju.net/v/aB3dE9 --json \'{"field_1":"张三"}\'']
|
|
69
|
+
}
|
|
70
|
+
];
|
package/dist/commands/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { ACCOUNT } from './account.js';
|
|
|
11
11
|
import { COMMENT } from './comment.js';
|
|
12
12
|
import { ENTRY } from './entry.js';
|
|
13
13
|
import { FIELD } from './field.js';
|
|
14
|
+
import { FILL } from './fill.js';
|
|
14
15
|
import { FOLDER } from './folder.js';
|
|
15
16
|
import { FORM } from './form.js';
|
|
16
17
|
import { LOCAL } from './local.js';
|
|
@@ -41,6 +42,12 @@ export const RESOURCES = [
|
|
|
41
42
|
{ name: 'entry', summary: 'Manage entries' },
|
|
42
43
|
{ name: 'comment', summary: 'Manage entry comments' },
|
|
43
44
|
{ name: 'opensearch', summary: 'Manage public queries' },
|
|
45
|
+
{
|
|
46
|
+
name: 'fill',
|
|
47
|
+
summary: 'Fill in a form through its fill link',
|
|
48
|
+
note: 'For a form or a table’s form view you were sent a link to, rather than one you manage. ' +
|
|
49
|
+
'OAuth sessions need the submit_entries scope: `jinshuju auth login --scopes "… submit_entries"`.'
|
|
50
|
+
},
|
|
44
51
|
{ name: 'merchant', summary: '小金商户: onboarding, balance and settlement' },
|
|
45
52
|
{ name: 'transaction', summary: 'Payment orders placed on payment forms' },
|
|
46
53
|
{ name: 'refund', summary: 'Refunds of payment orders' },
|
|
@@ -59,6 +66,7 @@ export const COMMANDS = [
|
|
|
59
66
|
...ENTRY,
|
|
60
67
|
...COMMENT,
|
|
61
68
|
...OPENSEARCH,
|
|
69
|
+
...FILL,
|
|
62
70
|
...TRADE,
|
|
63
71
|
...SMS
|
|
64
72
|
];
|