@jinshuju/cli 0.11.0 → 0.13.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 +24 -0
- package/dist/auth.d.ts +31 -1
- package/dist/auth.js +159 -4
- 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 +42 -65
- package/dist/commands/index.js +17 -0
- package/dist/commands/local.js +16 -5
- 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/config.d.ts +29 -1
- package/dist/config.js +28 -4
- package/dist/errors.d.ts +8 -1
- package/dist/errors.js +12 -1
- package/dist/generated/operations.d.ts +11 -0
- package/dist/generated/operations.js +4003 -0
- package/dist/help.js +1 -1
- package/dist/local.d.ts +4 -0
- package/dist/local.js +64 -7
- package/dist/options.d.ts +7 -2
- package/dist/options.js +24 -5
- package/dist/spec.d.ts +105 -0
- package/dist/spec.js +201 -0
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -34,9 +34,25 @@ and an access token (personal or account). Both go in through `auth login`:
|
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
36
|
jinshuju auth login # browser login
|
|
37
|
+
jinshuju auth login --device # approve a short code on any other device
|
|
37
38
|
jinshuju auth login --access-token xxx # access token, checked before it is stored
|
|
38
39
|
```
|
|
39
40
|
|
|
41
|
+
On a machine without a browser — a server over SSH, a container, an agent's
|
|
42
|
+
sandbox — `--device` prints a link and a short code. Open the link on any
|
|
43
|
+
device, a phone will do, check the code matches and approve; the CLI is
|
|
44
|
+
polling and finishes on its own. Nothing has to reach back into the machine.
|
|
45
|
+
Over SSH, or on Linux without a display, `auth login` does this by itself.
|
|
46
|
+
Someone without an account can sign up on that page and come back to approve.
|
|
47
|
+
|
|
48
|
+
An agent whose commands are cut off after a minute or two can split it in
|
|
49
|
+
two:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
jinshuju auth login --no-wait --output json # prints verification_uri_complete and user_code, then exits
|
|
53
|
+
jinshuju auth login --resume --timeout 60 # waits up to 60s; exit code 9 means still pending
|
|
54
|
+
```
|
|
55
|
+
|
|
40
56
|
Either one is written to the config file (`~/.jinshuju/config.json`, mode 600)
|
|
41
57
|
and replaces whatever credential was stored before. `jinshuju auth logout`
|
|
42
58
|
forgets it (revoking it first, for a browser session).
|
|
@@ -229,6 +245,8 @@ jinshuju entry delete --form Kp7mQ2 12 --yes
|
|
|
229
245
|
jinshuju view create --form Kp7mQ2 "High scores" --filter 'field_3 gte 80' --sort created_at:desc
|
|
230
246
|
jinshuju comment create --form Kp7mQ2 --entry 12 "Contacted, awaiting reply"
|
|
231
247
|
jinshuju opensearch edit Qy7nR3 --disable
|
|
248
|
+
jinshuju checkin create --form Kp7mQ2 # needs the check-in plugin enabled for the account
|
|
249
|
+
jinshuju checkin edit 42 --disable
|
|
232
250
|
```
|
|
233
251
|
|
|
234
252
|
Deletion always requires `--yes`. This CLI is non-interactive — stdin belongs to
|
|
@@ -415,4 +433,10 @@ npm install
|
|
|
415
433
|
npm test
|
|
416
434
|
npm run check # typecheck + oxlint + oxfmt --check, what CI runs
|
|
417
435
|
npm run fmt # format in place with oxfmt
|
|
436
|
+
npm run generate # src/generated from spec/openapi.yaml
|
|
437
|
+
npm run spec:update # fetch the published openapi.yaml, then generate
|
|
418
438
|
```
|
|
439
|
+
|
|
440
|
+
What a request may carry — paths, parameters, the values a flag takes — follows
|
|
441
|
+
`spec/openapi.yaml`, a copy of the published API v1 spec. A daily workflow
|
|
442
|
+
fetches it and opens a pull request when it changes.
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type LoadConfigOptions, type LoadedConfig, type OAuthConfig } from './config.js';
|
|
1
|
+
import { type LoadConfigOptions, type LoadedConfig, type OAuthConfig, type PendingDeviceLogin } from './config.js';
|
|
2
2
|
export type TokenResponse = {
|
|
3
3
|
access_token: string;
|
|
4
4
|
refresh_token?: string;
|
|
@@ -33,6 +33,35 @@ export declare function buildAuthorizationUrl(params: {
|
|
|
33
33
|
codeChallenge: string;
|
|
34
34
|
}): string;
|
|
35
35
|
export declare function loginWithOAuth(options?: OAuthLoginOptions, opener?: BrowserOpener): Promise<OAuthLoginResult>;
|
|
36
|
+
export declare const DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
37
|
+
export type DeviceLoginOptions = LoginTarget & {
|
|
38
|
+
/** How to wait between polls; a test passes one that does not. */
|
|
39
|
+
sleep?: (ms: number) => Promise<void>;
|
|
40
|
+
};
|
|
41
|
+
type LoginTarget = LoadConfigOptions & {
|
|
42
|
+
host?: string;
|
|
43
|
+
authHost?: string;
|
|
44
|
+
clientId?: string;
|
|
45
|
+
scopes?: string;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* RFC 8628. The CLI only ever calls out: it asks for a code, a person enters
|
|
49
|
+
* it on whatever device has a browser — a phone will do — and the CLI polls
|
|
50
|
+
* until they have approved it. Nothing has to reach back into this machine,
|
|
51
|
+
* which is what a server over SSH or an agent's sandbox cannot offer the
|
|
52
|
+
* loopback login.
|
|
53
|
+
*/
|
|
54
|
+
export declare function loginWithDevice(options: DeviceLoginOptions, onCode: (pending: PendingDeviceLogin) => void): Promise<OAuthConfig>;
|
|
55
|
+
/**
|
|
56
|
+
* The first half of a device login, for a caller that cannot wait: an agent
|
|
57
|
+
* whose commands are cut off after a minute or two. The code is stored, the
|
|
58
|
+
* person is sent to approve it, and `resumeDeviceLogin` collects the session.
|
|
59
|
+
*/
|
|
60
|
+
export declare function startDeviceLogin(options: LoginTarget): Promise<PendingDeviceLogin>;
|
|
61
|
+
/** Waits up to `waitMs` for the stored device login to be approved; still waiting after that is a PendingError. */
|
|
62
|
+
export declare function resumeDeviceLogin(options: DeviceLoginOptions & {
|
|
63
|
+
waitMs?: number;
|
|
64
|
+
}): Promise<OAuthConfig>;
|
|
36
65
|
export declare function refreshOAuthToken(config: LoadedConfig): Promise<OAuthConfig>;
|
|
37
66
|
/**
|
|
38
67
|
* Revokes a stored OAuth session, then forgets whatever credential is stored.
|
|
@@ -40,3 +69,4 @@ export declare function refreshOAuthToken(config: LoadedConfig): Promise<OAuthCo
|
|
|
40
69
|
*/
|
|
41
70
|
export declare function logout(config: LoadedConfig): Promise<void>;
|
|
42
71
|
export declare function shouldRefresh(auth: OAuthConfig, skewMs?: number): boolean;
|
|
72
|
+
export {};
|
package/dist/auth.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
2
|
import { createServer } from 'node:http';
|
|
3
3
|
import { execFile } from 'node:child_process';
|
|
4
|
-
import { AuthError } from './errors.js';
|
|
5
|
-
import { clearCredential, defaultScopes, loadConfig, saveOAuthConfig } from './config.js';
|
|
4
|
+
import { AuthError, PendingError, UsageError } from './errors.js';
|
|
5
|
+
import { clearCredential, defaultScopes, loadConfig, loadPendingDeviceLogin, saveOAuthConfig, saveOAuthLogin, savePendingDeviceLogin } from './config.js';
|
|
6
6
|
function base64Url(bytes) {
|
|
7
7
|
return bytes.toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
|
|
8
8
|
}
|
|
@@ -51,9 +51,156 @@ export async function loginWithOAuth(options = {}, opener = openUrl) {
|
|
|
51
51
|
const code = await callback.code;
|
|
52
52
|
const token = await exchangeAuthorizationCode(config.authHost, clientId, callback.redirectUri, code, verifier);
|
|
53
53
|
const auth = toOAuthConfig(config, clientId, token);
|
|
54
|
-
|
|
54
|
+
saveOAuthLogin(config.configPath, auth);
|
|
55
55
|
return { authorizeUrl, callbackUrl: callback.redirectUri, token: auth };
|
|
56
56
|
}
|
|
57
|
+
export const DEVICE_CODE_GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:device_code';
|
|
58
|
+
/**
|
|
59
|
+
* RFC 8628. The CLI only ever calls out: it asks for a code, a person enters
|
|
60
|
+
* it on whatever device has a browser — a phone will do — and the CLI polls
|
|
61
|
+
* until they have approved it. Nothing has to reach back into this machine,
|
|
62
|
+
* which is what a server over SSH or an agent's sandbox cannot offer the
|
|
63
|
+
* loopback login.
|
|
64
|
+
*/
|
|
65
|
+
export async function loginWithDevice(options, onCode) {
|
|
66
|
+
const { config, pending } = await requestDeviceCode(options);
|
|
67
|
+
onCode(pending);
|
|
68
|
+
return await finishDeviceLogin(config, pending, Date.parse(pending.expires_at), options.sleep);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The first half of a device login, for a caller that cannot wait: an agent
|
|
72
|
+
* whose commands are cut off after a minute or two. The code is stored, the
|
|
73
|
+
* person is sent to approve it, and `resumeDeviceLogin` collects the session.
|
|
74
|
+
*/
|
|
75
|
+
export async function startDeviceLogin(options) {
|
|
76
|
+
const { config, pending } = await requestDeviceCode(options);
|
|
77
|
+
savePendingDeviceLogin(config.configPath, pending);
|
|
78
|
+
return pending;
|
|
79
|
+
}
|
|
80
|
+
/** Waits up to `waitMs` for the stored device login to be approved; still waiting after that is a PendingError. */
|
|
81
|
+
export async function resumeDeviceLogin(options) {
|
|
82
|
+
const config = loadConfig({ configPath: options.configPath, env: options.env });
|
|
83
|
+
const pending = loadPendingDeviceLogin(config.configPath);
|
|
84
|
+
if (!pending)
|
|
85
|
+
throw new UsageError('No device login is waiting. Start one with `jinshuju auth login --no-wait`.');
|
|
86
|
+
const deadline = Math.min(Date.parse(pending.expires_at), Date.now() + (options.waitMs ?? 60_000));
|
|
87
|
+
return await finishDeviceLogin(config, pending, deadline, options.sleep);
|
|
88
|
+
}
|
|
89
|
+
async function requestDeviceCode(options) {
|
|
90
|
+
const config = loadConfig({
|
|
91
|
+
configPath: options.configPath,
|
|
92
|
+
env: options.env,
|
|
93
|
+
cli: { host: options.host, authHost: options.authHost, clientId: options.clientId }
|
|
94
|
+
});
|
|
95
|
+
const clientId = options.clientId ?? config.clientId;
|
|
96
|
+
if (!clientId)
|
|
97
|
+
throw new AuthError('Missing OAuth client id. Set JINSHUJU_OAUTH_CLIENT_ID or config client_id.');
|
|
98
|
+
const response = await fetch(new URL('/oauth/device_authorization', config.authHost), {
|
|
99
|
+
method: 'POST',
|
|
100
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
|
|
101
|
+
body: new URLSearchParams({ client_id: clientId, scope: options.scopes ?? defaultScopes }),
|
|
102
|
+
signal: AbortSignal.timeout(config.timeoutMs ?? TOKEN_TIMEOUT_MS)
|
|
103
|
+
});
|
|
104
|
+
const body = parseTokenBody(await response.text(), response);
|
|
105
|
+
if (!response.ok || !body?.device_code || !body.user_code || !body.verification_uri) {
|
|
106
|
+
throw new AuthError(body?.error_description ??
|
|
107
|
+
body?.error ??
|
|
108
|
+
`${response.status} ${response.statusText} from the device authorization endpoint`.trim());
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
config,
|
|
112
|
+
pending: {
|
|
113
|
+
auth_host: config.authHost,
|
|
114
|
+
client_id: clientId,
|
|
115
|
+
device_code: body.device_code,
|
|
116
|
+
user_code: body.user_code,
|
|
117
|
+
verification_uri: body.verification_uri,
|
|
118
|
+
verification_uri_complete: body.verification_uri_complete,
|
|
119
|
+
interval: body.interval ?? 5,
|
|
120
|
+
expires_at: new Date(Date.now() + (body.expires_in ?? 900) * 1000).toISOString()
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Polls at the interval the server asked for, five seconds slower each time it
|
|
126
|
+
* says `slow_down`, as RFC 8628 has it. A refusal or an expired code ends the
|
|
127
|
+
* login; running out of `deadline` while the code is still good does not, it
|
|
128
|
+
* only stops this wait.
|
|
129
|
+
*/
|
|
130
|
+
async function finishDeviceLogin(config, pending, deadline, sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) {
|
|
131
|
+
let interval = pending.interval;
|
|
132
|
+
const outOfTime = () => {
|
|
133
|
+
if (deadline >= Date.parse(pending.expires_at))
|
|
134
|
+
return new AuthError('The login code expired before it was approved. Start a new login.');
|
|
135
|
+
return new PendingError(`Still waiting for the code ${pending.user_code} to be approved at ` +
|
|
136
|
+
`${pending.verification_uri_complete ?? pending.verification_uri}. Run \`jinshuju auth login --resume\` again.`);
|
|
137
|
+
};
|
|
138
|
+
// The first poll is always made, so `--timeout 0` asks once rather than not at all.
|
|
139
|
+
let first = true;
|
|
140
|
+
for (;;) {
|
|
141
|
+
const remaining = deadline - Date.now();
|
|
142
|
+
const answer = await pollDeviceToken(pending, config.timeoutMs ?? TOKEN_TIMEOUT_MS, first && remaining <= 0 ? Number.POSITIVE_INFINITY : remaining);
|
|
143
|
+
first = false;
|
|
144
|
+
if ('outOfTime' in answer)
|
|
145
|
+
throw outOfTime();
|
|
146
|
+
if ('token' in answer) {
|
|
147
|
+
const auth = toOAuthConfig({ ...config, authHost: pending.auth_host }, pending.client_id, answer.token);
|
|
148
|
+
saveOAuthLogin(config.configPath, auth);
|
|
149
|
+
return auth;
|
|
150
|
+
}
|
|
151
|
+
if (answer.error === 'slow_down')
|
|
152
|
+
interval += 5;
|
|
153
|
+
else if (answer.error === 'access_denied')
|
|
154
|
+
throw new AuthError('The login was refused on the authorization page.');
|
|
155
|
+
else if (answer.error === 'expired_token' || answer.error === 'invalid_grant')
|
|
156
|
+
throw new AuthError('The login code expired before it was approved. Start a new login.');
|
|
157
|
+
else if (answer.error !== 'authorization_pending')
|
|
158
|
+
throw new AuthError(answer.description ?? answer.error);
|
|
159
|
+
if (Date.now() + interval * 1000 >= deadline)
|
|
160
|
+
throw outOfTime();
|
|
161
|
+
await sleep(interval * 1000);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* One poll, held to the time the login has left as well as to its own
|
|
166
|
+
* timeout: a request still in flight when the --timeout runs out is abandoned,
|
|
167
|
+
* as `outOfTime`, rather than holding the command past what its caller allowed.
|
|
168
|
+
*/
|
|
169
|
+
async function pollDeviceToken(pending, timeoutMs, remainingMs) {
|
|
170
|
+
if (remainingMs <= 0)
|
|
171
|
+
return { outOfTime: true };
|
|
172
|
+
// fetch settles on the headers; the body can still be on its way when time
|
|
173
|
+
// runs out, and an abort there surfaces as a different error. Both halves are
|
|
174
|
+
// under the one signal, and whether it fired is what decides.
|
|
175
|
+
const signal = AbortSignal.timeout(Math.min(timeoutMs, remainingMs));
|
|
176
|
+
let response;
|
|
177
|
+
let text;
|
|
178
|
+
try {
|
|
179
|
+
response = await fetch(new URL('/oauth/token', pending.auth_host), {
|
|
180
|
+
method: 'POST',
|
|
181
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
|
|
182
|
+
body: new URLSearchParams({
|
|
183
|
+
grant_type: DEVICE_CODE_GRANT_TYPE,
|
|
184
|
+
client_id: pending.client_id,
|
|
185
|
+
device_code: pending.device_code
|
|
186
|
+
}),
|
|
187
|
+
signal
|
|
188
|
+
});
|
|
189
|
+
text = await response.text();
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
if (signal.aborted && remainingMs <= timeoutMs)
|
|
193
|
+
return { outOfTime: true };
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
const body = parseTokenBody(text, response);
|
|
197
|
+
if (response.ok && body?.access_token)
|
|
198
|
+
return { token: body };
|
|
199
|
+
return {
|
|
200
|
+
error: body?.error ?? `${response.status} ${response.statusText}`.trim(),
|
|
201
|
+
description: body?.error_description
|
|
202
|
+
};
|
|
203
|
+
}
|
|
57
204
|
export async function refreshOAuthToken(config) {
|
|
58
205
|
if (!config.auth?.refresh_token)
|
|
59
206
|
throw new AuthError('No OAuth refresh token. Run `jinshuju auth login` again.');
|
|
@@ -212,8 +359,16 @@ function safeEqual(a, b) {
|
|
|
212
359
|
const bBuffer = Buffer.from(b);
|
|
213
360
|
return aBuffer.length === bBuffer.length && timingSafeEqual(aBuffer, bBuffer);
|
|
214
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* A browser that cannot be opened — no xdg-open on a server, no display —
|
|
364
|
+
* says so with the URL, rather than leaving the login to wait out its timeout
|
|
365
|
+
* in silence for a page nobody will ever see.
|
|
366
|
+
*/
|
|
215
367
|
async function openUrl(url) {
|
|
216
368
|
const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
217
369
|
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
|
|
218
|
-
await new Promise((resolve) => execFile(command, args, (error) => (error
|
|
370
|
+
const opened = await new Promise((resolve) => execFile(command, args, (error) => resolve(!error)));
|
|
371
|
+
if (!opened)
|
|
372
|
+
process.stderr.write(`Could not open a browser. Open this URL to log in:\n${url}\n` +
|
|
373
|
+
'Without a browser on this machine, `jinshuju auth login --device` logs in from another device instead.\n');
|
|
219
374
|
}
|
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
|
];
|