@jinshuju/cli 0.8.0 → 0.9.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 +16 -0
- 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
|
@@ -267,6 +267,22 @@ you need no permission on the form itself. Flags that only make sense from an
|
|
|
267
267
|
owner's point of view (`--sort`, `--view`, `--scope-filter` and the like) are
|
|
268
268
|
rejected when combined with `--mine`.
|
|
269
269
|
|
|
270
|
+
## Filling in someone else's form
|
|
271
|
+
|
|
272
|
+
A fill link — `…/f/<token>` for a form, `…/v/<token>` for a table's form view —
|
|
273
|
+
can be filled from the CLI the way anyone with the link fills it in a browser:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
jinshuju fill get https://acme.jinshuju.net/v/aB3dE9 # what it asks for, and whether you can submit
|
|
277
|
+
jinshuju fill submit https://acme.jinshuju.net/v/aB3dE9 --json '{"field_1":"Ada"}'
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
No role on the form is needed, and only what the page shows its fillers comes
|
|
281
|
+
back. The entry is recorded as yours. A page that asks for something only the
|
|
282
|
+
person at it can do — a captcha, an SMS code, WeChat, a payment — lists it under
|
|
283
|
+
`blockers`, and is refused until it is filled in a browser. An OAuth session
|
|
284
|
+
needs the `submit_entries` scope for these.
|
|
285
|
+
|
|
270
286
|
## Working with files
|
|
271
287
|
|
|
272
288
|
Four commands take a file. The CLI uploads with its own credential; there is no
|
|
@@ -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
|
];
|