@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/dist/commands/trade.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { PAGINATION_OPTIONS } from '../options.js';
|
|
2
|
-
import {
|
|
2
|
+
import { call, choices } from '../spec.js';
|
|
3
|
+
import { paging } from './shared.js';
|
|
3
4
|
/**
|
|
4
5
|
* The account's 小金商户: what its payment forms collected, refunded and paid
|
|
5
6
|
* out. An account collecting through its own bound WeChat / Alipay merchant
|
|
6
7
|
* (直连) has none of this in 金数据, and the reads below say so rather than
|
|
7
8
|
* answering with zeroes.
|
|
8
9
|
*/
|
|
9
|
-
const PAID_STATUSES = ['paid', 'unpaid', 'refunded', 'refunding', 'partial_refunded'];
|
|
10
|
-
const RECORD_STATUSES = ['processing', 'success', 'error'];
|
|
11
10
|
const DATE_OPTIONS = [
|
|
12
11
|
{
|
|
13
12
|
name: '--from',
|
|
@@ -17,33 +16,53 @@ const DATE_OPTIONS = [
|
|
|
17
16
|
},
|
|
18
17
|
{ name: '--to', type: 'string', placeholder: '<YYYY-MM-DD>', description: 'Last day, inclusive; give it with --from' }
|
|
19
18
|
];
|
|
20
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* The CLI spells a dimension as its flag is spelled; the API names it by its
|
|
21
|
+
* parameter, and the spec says which of those it groups by.
|
|
22
|
+
*/
|
|
21
23
|
const GROUP_BY = { time: 'time', 'paid-status': 'paid_status', channel: 'payment_channel' };
|
|
22
24
|
const ORDER_FILTER_OPTIONS = [
|
|
23
25
|
{
|
|
24
26
|
name: '--status',
|
|
25
27
|
type: 'string',
|
|
26
28
|
repeatable: true,
|
|
27
|
-
choices:
|
|
29
|
+
choices: choices('listTradeTransactions', 'paid_status'),
|
|
28
30
|
placeholder: '<status>',
|
|
29
31
|
description: 'Keep only these payment statuses, repeatable. Omitted, every status, unpaid included'
|
|
30
32
|
},
|
|
31
33
|
{
|
|
32
34
|
name: '--channel',
|
|
33
35
|
type: 'string',
|
|
34
|
-
choices:
|
|
36
|
+
choices: choices('listTradeTransactions', 'payment_channel'),
|
|
35
37
|
placeholder: '<channel>',
|
|
36
|
-
description: 'Keep only orders paid through this channel: wxpay (
|
|
38
|
+
description: 'Keep only orders paid through this channel: wxpay (WeChat Pay) or alipay (Alipay)'
|
|
37
39
|
},
|
|
38
40
|
{ name: '--form', type: 'string', placeholder: '<token>', description: 'Keep only orders of this payment form' }
|
|
39
41
|
];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
/**
|
|
43
|
+
* What a refund or payout listing carries, as the operation behind it allows.
|
|
44
|
+
* The lookup is spelled out at each call, because scripts/spec-diff.mjs reads
|
|
45
|
+
* it off the source to tell whether a spec change moved what a flag offers.
|
|
46
|
+
*/
|
|
47
|
+
function includeOption(values) {
|
|
48
|
+
return {
|
|
49
|
+
name: '--include',
|
|
50
|
+
type: 'string',
|
|
51
|
+
choices: values,
|
|
52
|
+
placeholder: '<what>',
|
|
53
|
+
description: 'both (default), stats for the statistics alone, or records for the rows alone'
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Which state a refund or a payout is in, as the operation behind it names them. */
|
|
57
|
+
function recordStatusOption(values, what) {
|
|
58
|
+
return {
|
|
59
|
+
name: '--status',
|
|
60
|
+
type: 'string',
|
|
61
|
+
choices: values,
|
|
62
|
+
placeholder: '<status>',
|
|
63
|
+
description: `Keep only ${what} in this state`
|
|
64
|
+
};
|
|
65
|
+
}
|
|
47
66
|
const DETAIL_LIMITS = 'Rows are capped at 90 days and 200 matching records per query; past either, no rows come back, ' +
|
|
48
67
|
'only detail_limit and the stats for the whole range. Narrow the range rather than splitting it.';
|
|
49
68
|
function dates(input) {
|
|
@@ -66,7 +85,7 @@ export const TRADE = [
|
|
|
66
85
|
summary: 'Show the 小金商户: where onboarding stands, balance, rate and settlement account',
|
|
67
86
|
description: 'Answers without a merchant too: merchant_stage says where the application stands. Bank card, phone, ' +
|
|
68
87
|
'email and ID numbers come back masked, as the product shows them.',
|
|
69
|
-
request: () => (
|
|
88
|
+
request: () => call('getTradeMerchant')
|
|
70
89
|
},
|
|
71
90
|
{
|
|
72
91
|
path: ['transaction', 'list'],
|
|
@@ -81,13 +100,12 @@ export const TRADE = [
|
|
|
81
100
|
name: '--order-no',
|
|
82
101
|
type: 'string',
|
|
83
102
|
placeholder: '<no>',
|
|
84
|
-
description: 'Exact match on
|
|
103
|
+
description: 'Exact match on the transaction number (trade_no), the merchant order number ' +
|
|
104
|
+
'(merchant_out_trade_no) or the Jinshuju order number (out_trade_no)'
|
|
85
105
|
},
|
|
86
106
|
...PAGINATION_OPTIONS
|
|
87
107
|
],
|
|
88
|
-
request: (input) => ({
|
|
89
|
-
method: 'GET',
|
|
90
|
-
path: `${API}/trade/transactions`,
|
|
108
|
+
request: (input) => call('listTradeTransactions', {
|
|
91
109
|
query: {
|
|
92
110
|
...dates(input),
|
|
93
111
|
...orderFilters(input),
|
|
@@ -117,9 +135,7 @@ export const TRADE = [
|
|
|
117
135
|
},
|
|
118
136
|
...ORDER_FILTER_OPTIONS
|
|
119
137
|
],
|
|
120
|
-
request: (input) => ({
|
|
121
|
-
method: 'GET',
|
|
122
|
-
path: `${API}/trade/transactions/aggregate`,
|
|
138
|
+
request: (input) => call('aggregateTradeTransactions', {
|
|
123
139
|
query: { ...dates(input), group_by: GROUP_BY[input.options.group_by], ...orderFilters(input) }
|
|
124
140
|
}),
|
|
125
141
|
examples: ['jinshuju transaction aggregate --from 2026-09-01 --to 2026-09-28 --group-by channel']
|
|
@@ -130,20 +146,17 @@ export const TRADE = [
|
|
|
130
146
|
description: 'Defaults to the last 90 days; --refund-no alone searches all time. ' + DETAIL_LIMITS,
|
|
131
147
|
options: [
|
|
132
148
|
...DATE_OPTIONS,
|
|
149
|
+
recordStatusOption(choices('listTradeRefunds', 'status'), 'refunds'),
|
|
133
150
|
{
|
|
134
|
-
name: '--
|
|
151
|
+
name: '--refund-no',
|
|
135
152
|
type: 'string',
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
description: 'Keep only refunds in this state'
|
|
153
|
+
placeholder: '<no>',
|
|
154
|
+
description: 'Exact match on the refund number (refund_no)'
|
|
139
155
|
},
|
|
140
|
-
|
|
141
|
-
INCLUDE_OPTION,
|
|
156
|
+
includeOption(choices('listTradeRefunds', 'include')),
|
|
142
157
|
...PAGINATION_OPTIONS
|
|
143
158
|
],
|
|
144
|
-
request: (input) => ({
|
|
145
|
-
method: 'GET',
|
|
146
|
-
path: `${API}/trade/refunds`,
|
|
159
|
+
request: (input) => call('listTradeRefunds', {
|
|
147
160
|
query: {
|
|
148
161
|
...dates(input),
|
|
149
162
|
status: input.options.status,
|
|
@@ -156,23 +169,15 @@ export const TRADE = [
|
|
|
156
169
|
},
|
|
157
170
|
{
|
|
158
171
|
path: ['payout', 'list'],
|
|
159
|
-
summary: 'List payouts
|
|
172
|
+
summary: 'List payouts to the settlement account, with their statistics',
|
|
160
173
|
description: 'Defaults to the last 90 days. ' + DETAIL_LIMITS,
|
|
161
174
|
options: [
|
|
162
175
|
...DATE_OPTIONS,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
type: 'string',
|
|
166
|
-
choices: RECORD_STATUSES,
|
|
167
|
-
placeholder: '<status>',
|
|
168
|
-
description: 'Keep only payouts in this state'
|
|
169
|
-
},
|
|
170
|
-
INCLUDE_OPTION,
|
|
176
|
+
recordStatusOption(choices('listTradePayouts', 'status'), 'payouts'),
|
|
177
|
+
includeOption(choices('listTradePayouts', 'include')),
|
|
171
178
|
...PAGINATION_OPTIONS
|
|
172
179
|
],
|
|
173
|
-
request: (input) => ({
|
|
174
|
-
method: 'GET',
|
|
175
|
-
path: `${API}/trade/payouts`,
|
|
180
|
+
request: (input) => call('listTradePayouts', {
|
|
176
181
|
query: {
|
|
177
182
|
...dates(input),
|
|
178
183
|
status: input.options.status,
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import type { HttpClient, HttpRequest } from '../http.js';
|
|
2
|
+
import { type OperationId } from '../spec.js';
|
|
3
|
+
/**
|
|
4
|
+
* What the CLI uploads a form image as. A test holds the list to the spec's
|
|
5
|
+
* `image_type`, which is where it would otherwise drift.
|
|
6
|
+
*/
|
|
7
|
+
export declare const FORM_IMAGE_TYPES: readonly ["description", "header", "wallpaper", "opensearch_header"];
|
|
8
|
+
export type FormImageType = (typeof FORM_IMAGE_TYPES)[number];
|
|
2
9
|
/**
|
|
3
10
|
* A file on disk, as multipart. The three endpoints that take one authenticate
|
|
4
11
|
* like every other request, so there is no ticket to fetch first: the file goes
|
|
5
12
|
* up in one call and comes back with an id to refer to it by.
|
|
6
13
|
*/
|
|
7
|
-
export declare function upload(path: string, file: string, extra?: Record<string, string>): HttpRequest;
|
|
14
|
+
export declare function upload(id: OperationId, path: Record<string, string>, file: string, extra?: Record<string, string>): HttpRequest;
|
|
8
15
|
/**
|
|
9
16
|
* An image that a form's theme or one of its public queries refers to by id, uploaded
|
|
10
17
|
* with `imageType` saying which (header, wallpaper, opensearch_header).
|
|
11
18
|
*/
|
|
12
|
-
export declare function uploadFormImage(client: HttpClient, file: string, imageType:
|
|
19
|
+
export declare function uploadFormImage(client: HttpClient, file: string, imageType: FormImageType): Promise<string>;
|
package/dist/commands/upload.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UsageError } from '../options.js';
|
|
2
2
|
import { progress } from '../progress.js';
|
|
3
|
-
import {
|
|
3
|
+
import { call } from '../spec.js';
|
|
4
4
|
import { readFileSync } from 'node:fs';
|
|
5
5
|
import { basename, extname } from 'node:path';
|
|
6
6
|
/**
|
|
@@ -20,12 +20,17 @@ const UPLOAD_TYPES = {
|
|
|
20
20
|
'.webp': 'image/webp',
|
|
21
21
|
'.pdf': 'application/pdf'
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* What the CLI uploads a form image as. A test holds the list to the spec's
|
|
25
|
+
* `image_type`, which is where it would otherwise drift.
|
|
26
|
+
*/
|
|
27
|
+
export const FORM_IMAGE_TYPES = ['description', 'header', 'wallpaper', 'opensearch_header'];
|
|
23
28
|
/**
|
|
24
29
|
* A file on disk, as multipart. The three endpoints that take one authenticate
|
|
25
30
|
* like every other request, so there is no ticket to fetch first: the file goes
|
|
26
31
|
* up in one call and comes back with an id to refer to it by.
|
|
27
32
|
*/
|
|
28
|
-
export function upload(path, file, extra = {}) {
|
|
33
|
+
export function upload(id, path, file, extra = {}) {
|
|
29
34
|
const form = new FormData();
|
|
30
35
|
let bytes;
|
|
31
36
|
try {
|
|
@@ -38,7 +43,7 @@ export function upload(path, file, extra = {}) {
|
|
|
38
43
|
form.append('file', new Blob([new Uint8Array(bytes)], type ? { type } : undefined), basename(file));
|
|
39
44
|
for (const [name, value] of Object.entries(extra))
|
|
40
45
|
form.append(name, value);
|
|
41
|
-
return {
|
|
46
|
+
return call(id, { path, form });
|
|
42
47
|
}
|
|
43
48
|
/**
|
|
44
49
|
* An image that a form's theme or one of its public queries refers to by id, uploaded
|
|
@@ -48,7 +53,7 @@ export async function uploadFormImage(client, file, imageType) {
|
|
|
48
53
|
const watching = progress();
|
|
49
54
|
watching.step(`uploading ${basename(file)}…`);
|
|
50
55
|
try {
|
|
51
|
-
const uploaded = await client.request(upload(
|
|
56
|
+
const uploaded = await client.request(upload('uploadFormImage', {}, file, { image_type: imageType }));
|
|
52
57
|
return uploaded.attachment_id;
|
|
53
58
|
}
|
|
54
59
|
finally {
|
package/dist/commands/view.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CONTAINER_OPTIONS, FILTER_OPTION, FILTERS_OPTION, JSON_OPTION, SORT_OPTION } from '../options.js';
|
|
2
|
-
import {
|
|
2
|
+
import { bodyChoices } from '../spec.js';
|
|
3
|
+
import { YES_OPTION, confirmed, filterConditions, onContainer, overriding, sortRules } from './shared.js';
|
|
3
4
|
/** What `view create` and `view edit` both take, beyond the name. */
|
|
4
5
|
const VIEW_OPTIONS = [
|
|
5
6
|
{
|
|
6
7
|
name: '--type',
|
|
7
8
|
type: 'string',
|
|
8
|
-
choices:
|
|
9
|
+
choices: bodyChoices('createFormView', 'view_type'),
|
|
9
10
|
placeholder: '<type>',
|
|
10
11
|
description: 'View type'
|
|
11
12
|
},
|
|
@@ -29,14 +30,14 @@ export const VIEW = [
|
|
|
29
30
|
path: ['view', 'list'],
|
|
30
31
|
summary: 'List the views of a form or table',
|
|
31
32
|
options: [...CONTAINER_OPTIONS],
|
|
32
|
-
request: (input) => (
|
|
33
|
+
request: (input) => onContainer(input, 'listFormViews', 'listTableViews')
|
|
33
34
|
},
|
|
34
35
|
{
|
|
35
36
|
path: ['view', 'get'],
|
|
36
37
|
summary: 'Show a view',
|
|
37
38
|
args: [{ name: 'view', required: true, description: 'View token, six letters and digits, e.g. aB3dE9' }],
|
|
38
39
|
options: [...CONTAINER_OPTIONS],
|
|
39
|
-
request: (input) => (
|
|
40
|
+
request: (input) => onContainer(input, 'getFormView', 'getTableView', { path: { view_token: input.args.view } })
|
|
40
41
|
},
|
|
41
42
|
{
|
|
42
43
|
path: ['view', 'create'],
|
|
@@ -45,11 +46,7 @@ export const VIEW = [
|
|
|
45
46
|
'Anything without a flag of its own — kanban grouping, visibility — goes through --json.',
|
|
46
47
|
args: [{ name: 'name', required: true, description: 'View name' }],
|
|
47
48
|
options: [...CONTAINER_OPTIONS, ...VIEW_OPTIONS],
|
|
48
|
-
request: (input) => ({
|
|
49
|
-
method: 'POST',
|
|
50
|
-
path: `${containerPath(input)}/views`,
|
|
51
|
-
body: { ...viewBody(input), name: input.args.name }
|
|
52
|
-
}),
|
|
49
|
+
request: (input) => onContainer(input, 'createFormView', 'createTableView', { body: { ...viewBody(input), name: input.args.name } }),
|
|
53
50
|
examples: ["jinshuju view create --form Kp7mQ2 高分 --filter 'field_3 gte 80' --sort created_at:desc"]
|
|
54
51
|
},
|
|
55
52
|
{
|
|
@@ -62,9 +59,8 @@ export const VIEW = [
|
|
|
62
59
|
{ name: '--name', type: 'string', placeholder: '<name>', description: 'Rename the view' },
|
|
63
60
|
...VIEW_OPTIONS
|
|
64
61
|
],
|
|
65
|
-
request: (input) => ({
|
|
66
|
-
|
|
67
|
-
path: `${containerPath(input)}/views/${input.args.view}`,
|
|
62
|
+
request: (input) => onContainer(input, 'updateFormView', 'updateTableView', {
|
|
63
|
+
path: { view_token: input.args.view },
|
|
68
64
|
body: overriding(viewBody(input), { name: input.options.name })
|
|
69
65
|
})
|
|
70
66
|
},
|
|
@@ -75,7 +71,7 @@ export const VIEW = [
|
|
|
75
71
|
options: [...CONTAINER_OPTIONS, YES_OPTION],
|
|
76
72
|
request: (input) => {
|
|
77
73
|
confirmed(input, `Deleting view ${input.args.view}`);
|
|
78
|
-
return
|
|
74
|
+
return onContainer(input, 'deleteFormView', 'deleteTableView', { path: { view_token: input.args.view } });
|
|
79
75
|
}
|
|
80
76
|
}
|
|
81
77
|
];
|
package/dist/config.d.ts
CHANGED
|
@@ -14,6 +14,21 @@ export type TokenConfig = {
|
|
|
14
14
|
type: 'access_token';
|
|
15
15
|
access_token: string;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* A device login `auth login --no-wait` started and `auth login --resume`
|
|
19
|
+
* finishes: the code a person is entering on another device, and the device
|
|
20
|
+
* code that turns into a session once they have.
|
|
21
|
+
*/
|
|
22
|
+
export type PendingDeviceLogin = {
|
|
23
|
+
auth_host: string;
|
|
24
|
+
client_id: string;
|
|
25
|
+
device_code: string;
|
|
26
|
+
user_code: string;
|
|
27
|
+
verification_uri: string;
|
|
28
|
+
verification_uri_complete?: string;
|
|
29
|
+
interval: number;
|
|
30
|
+
expires_at: string;
|
|
31
|
+
};
|
|
17
32
|
export type LoadedConfig = {
|
|
18
33
|
/**
|
|
19
34
|
* A personal or account access token, sent as a bearer: JINSHUJU_ACCESS_TOKEN,
|
|
@@ -55,13 +70,26 @@ export declare const defaultScopes = "public forms read_entries write_entries fo
|
|
|
55
70
|
*/
|
|
56
71
|
export type RawConfig = Partial<Record<ConfigKey, string>> & {
|
|
57
72
|
auth?: OAuthConfig | TokenConfig;
|
|
73
|
+
pending_device?: PendingDeviceLogin;
|
|
58
74
|
};
|
|
59
75
|
export declare function loadConfig(options?: LoadConfigOptions): LoadedConfig;
|
|
60
76
|
export declare function setConfigValue(configPath: string, key: ConfigKey, value: string): void;
|
|
61
77
|
export declare function unsetConfigValue(configPath: string, key: ConfigKey): void;
|
|
78
|
+
/**
|
|
79
|
+
* Stores a renewed session. A refresh is not a login: a device login started
|
|
80
|
+
* with --no-wait while the old session was still in use keeps waiting.
|
|
81
|
+
*/
|
|
62
82
|
export declare function saveOAuthConfig(configPath: string, auth: OAuthConfig): void;
|
|
83
|
+
/** A login of either kind settles any device login still waiting: what it was waiting for is decided. */
|
|
84
|
+
export declare function saveOAuthLogin(configPath: string, auth: OAuthConfig): void;
|
|
63
85
|
export declare function saveAccessToken(configPath: string, accessToken: string): void;
|
|
64
|
-
|
|
86
|
+
export declare function savePendingDeviceLogin(configPath: string, pending: PendingDeviceLogin): void;
|
|
87
|
+
export declare function loadPendingDeviceLogin(configPath: string): PendingDeviceLogin | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* Forgets the stored credential, whichever kind it is, and any device login
|
|
90
|
+
* still waiting: after a logout, approving that code in a browser must not
|
|
91
|
+
* log this machine back in.
|
|
92
|
+
*/
|
|
65
93
|
export declare function clearCredential(configPath: string): void;
|
|
66
94
|
export declare function getConfig(configPath: string): RawConfig;
|
|
67
95
|
/** Every key the config file holds, in the order help should list them. */
|
package/dist/config.js
CHANGED
|
@@ -96,22 +96,46 @@ export function unsetConfigValue(configPath, key) {
|
|
|
96
96
|
delete config[key];
|
|
97
97
|
writeConfigFile(configPath, config);
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Stores a renewed session. A refresh is not a login: a device login started
|
|
101
|
+
* with --no-wait while the old session was still in use keeps waiting.
|
|
102
|
+
*/
|
|
99
103
|
export function saveOAuthConfig(configPath, auth) {
|
|
100
104
|
const config = readConfigFile(configPath);
|
|
101
|
-
config
|
|
102
|
-
|
|
103
|
-
|
|
105
|
+
writeConfigFile(configPath, withOAuth(config, auth));
|
|
106
|
+
}
|
|
107
|
+
/** A login of either kind settles any device login still waiting: what it was waiting for is decided. */
|
|
108
|
+
export function saveOAuthLogin(configPath, auth) {
|
|
109
|
+
const config = withOAuth(readConfigFile(configPath), auth);
|
|
110
|
+
delete config.pending_device;
|
|
104
111
|
writeConfigFile(configPath, config);
|
|
105
112
|
}
|
|
113
|
+
function withOAuth(config, auth) {
|
|
114
|
+
return { ...config, auth, auth_host: auth.auth_host, client_id: auth.client_id };
|
|
115
|
+
}
|
|
106
116
|
export function saveAccessToken(configPath, accessToken) {
|
|
107
117
|
const config = readConfigFile(configPath);
|
|
108
118
|
config.auth = { type: 'access_token', access_token: accessToken };
|
|
119
|
+
delete config.pending_device;
|
|
120
|
+
writeConfigFile(configPath, config);
|
|
121
|
+
}
|
|
122
|
+
export function savePendingDeviceLogin(configPath, pending) {
|
|
123
|
+
const config = readConfigFile(configPath);
|
|
124
|
+
config.pending_device = pending;
|
|
109
125
|
writeConfigFile(configPath, config);
|
|
110
126
|
}
|
|
111
|
-
|
|
127
|
+
export function loadPendingDeviceLogin(configPath) {
|
|
128
|
+
return readConfigFile(configPath).pending_device;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Forgets the stored credential, whichever kind it is, and any device login
|
|
132
|
+
* still waiting: after a logout, approving that code in a browser must not
|
|
133
|
+
* log this machine back in.
|
|
134
|
+
*/
|
|
112
135
|
export function clearCredential(configPath) {
|
|
113
136
|
const config = readConfigFile(configPath);
|
|
114
137
|
delete config.auth;
|
|
138
|
+
delete config.pending_device;
|
|
115
139
|
writeConfigFile(configPath, config);
|
|
116
140
|
}
|
|
117
141
|
export function getConfig(configPath) {
|
package/dist/errors.d.ts
CHANGED
|
@@ -24,12 +24,19 @@ export declare class TransportError extends Error {
|
|
|
24
24
|
export declare class RefusedError extends Error {
|
|
25
25
|
name: string;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Nothing went wrong yet, but the thing waited for has not happened: a device
|
|
29
|
+
* login nobody has approved. Running the same command again is the remedy.
|
|
30
|
+
*/
|
|
31
|
+
export declare class PendingError extends Error {
|
|
32
|
+
name: string;
|
|
33
|
+
}
|
|
27
34
|
/**
|
|
28
35
|
* What kind of failure it was, which is what a script branches on. The exit
|
|
29
36
|
* code says it without parsing anything; `--output json` also says it in
|
|
30
37
|
* words, alongside the status and body the server answered with.
|
|
31
38
|
*/
|
|
32
|
-
export type ErrorKind = 'unexpected' | 'usage' | 'auth' | 'not_found' | 'refused' | 'server' | 'transport' | 'rate_limited';
|
|
39
|
+
export type ErrorKind = 'unexpected' | 'usage' | 'auth' | 'not_found' | 'refused' | 'server' | 'transport' | 'rate_limited' | 'pending';
|
|
33
40
|
export declare const EXIT_CODES: Readonly<Record<ErrorKind, number>>;
|
|
34
41
|
export type ClassifiedError = {
|
|
35
42
|
kind: ErrorKind;
|
package/dist/errors.js
CHANGED
|
@@ -33,6 +33,13 @@ export class TransportError extends Error {
|
|
|
33
33
|
export class RefusedError extends Error {
|
|
34
34
|
name = 'RefusedError';
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Nothing went wrong yet, but the thing waited for has not happened: a device
|
|
38
|
+
* login nobody has approved. Running the same command again is the remedy.
|
|
39
|
+
*/
|
|
40
|
+
export class PendingError extends Error {
|
|
41
|
+
name = 'PendingError';
|
|
42
|
+
}
|
|
36
43
|
export const EXIT_CODES = {
|
|
37
44
|
unexpected: 1,
|
|
38
45
|
usage: 2,
|
|
@@ -42,7 +49,9 @@ export const EXIT_CODES = {
|
|
|
42
49
|
server: 6,
|
|
43
50
|
transport: 7,
|
|
44
51
|
// Neither the caller's fault nor permanent: it wants waiting, not a corrected request.
|
|
45
|
-
rate_limited: 8
|
|
52
|
+
rate_limited: 8,
|
|
53
|
+
// Not a failure of anything: a device login still waits for someone to approve it.
|
|
54
|
+
pending: 9
|
|
46
55
|
};
|
|
47
56
|
function kindOfStatus(status) {
|
|
48
57
|
if (status === 429)
|
|
@@ -78,6 +87,8 @@ export function classify(error) {
|
|
|
78
87
|
return { kind: 'refused', exitCode: EXIT_CODES.refused, message };
|
|
79
88
|
if (error instanceof TransportError)
|
|
80
89
|
return { kind: 'transport', exitCode: EXIT_CODES.transport, message };
|
|
90
|
+
if (error instanceof PendingError)
|
|
91
|
+
return { kind: 'pending', exitCode: EXIT_CODES.pending, message };
|
|
81
92
|
if (error instanceof HttpError) {
|
|
82
93
|
const kind = kindOfStatus(error.status);
|
|
83
94
|
const retry_after = retryAfterIn(error.body);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Operation, Schema } from '../spec.js';
|
|
2
|
+
/** The path every operation's path is relative to, from `servers`. */
|
|
3
|
+
export declare const BASE_PATH = "/api/v1";
|
|
4
|
+
export type OperationId = 'aggregateEntries' | 'aggregateFormViewEntries' | 'aggregateTableEntries' | 'aggregateTableViewEntries' | 'aggregateTradeTransactions' | 'checkFormFieldData' | 'checkTableFieldData' | 'copyForm' | 'countEntries' | 'countEntriesAcrossForms' | 'countFormViewEntries' | 'countTableEntries' | 'countTableViewEntries' | 'createCheckinCampaign' | 'createEntriesBatch' | 'createEntry' | 'createEntryComment' | 'createEntryImport' | 'createEntryLegacy' | 'createFillFormEntry' | 'createFillViewEntry' | 'createFolder' | 'createForm' | 'createFormView' | 'createFormWebhook' | 'createOpensearchQuery' | 'createPredefinedChoicesSet' | 'createTable' | 'createTableEntry' | 'createTableEntryComment' | 'createTableView' | 'createTemplateUsage' | 'createWeixinOauthSession' | 'deleteCheckinCampaign' | 'deleteEntry' | 'deleteEntryComment' | 'deleteFormView' | 'deleteFormWebhook' | 'deletePredefinedChoicesSet' | 'deleteTable' | 'deleteTableEntry' | 'deleteTableEntryComment' | 'deleteTableView' | 'getBillingAccount' | 'getCheckinCampaign' | 'getCurrentUser' | 'getEntry' | 'getEntryImport' | 'getEntryStats' | 'getEvaluationSetting' | 'getExamSetting' | 'getFieldType' | 'getFillFormPage' | 'getFillViewPage' | 'getForm' | 'getFormSetting' | 'getFormView' | 'getManuallyCloseRule' | 'getOpensearchQuery' | 'getTable' | 'getTableEntry' | 'getTableView' | 'getTradeMerchant' | 'listBillingAccountInvoices' | 'listBillingAccountPaymentHistories' | 'listBillingAccountUsers' | 'listCheckinCampaigns' | 'listContacts' | 'listEntries' | 'listEntryComments' | 'listExtendedAttributes' | 'listFieldRules' | 'listFieldTypes' | 'listFolders' | 'listFormCooperators' | 'listFormViewEntries' | 'listFormViews' | 'listForms' | 'listMyFilledForms' | 'listMySubmittedEntries' | 'listOpensearchQueries' | 'listOpensearchQuerySuggestions' | 'listPredefinedChoicesSets' | 'listSmsAuditStatuses' | 'listTableEntries' | 'listTableEntryComments' | 'listTableViewEntries' | 'listTableViews' | 'listTables' | 'listTradePayouts' | 'listTradeRefunds' | 'listTradeTransactions' | 'moveFormToFolder' | 'moveTableToFolder' | 'patchEntriesBatch' | 'previewFormFieldTypeChange' | 'previewTableFieldTypeChange' | 'replaceEntry' | 'replaceTableEntry' | 'searchEntriesAcrossForms' | 'searchMySubmittedEntries' | 'summarizeEntries' | 'summarizeFormViewEntries' | 'summarizeTableEntries' | 'summarizeTableViewEntries' | 'updateAccessPolicy' | 'updateCheckinCampaign' | 'updateEntry' | 'updateEntryComment' | 'updateEntryViaPost' | 'updateEvaluationSetting' | 'updateExamSetting' | 'updateForm' | 'updateFormSetting' | 'updateFormTheme' | 'updateFormView' | 'updateManuallyCloseRule' | 'updateOpensearchQuery' | 'updatePredefinedChoicesSet' | 'updateTable' | 'updateTableEntry' | 'updateTableEntryComment' | 'updateTableEntryViaPost' | 'updateTableView' | 'uploadEntryAttachment' | 'uploadFormImage' | 'uploadImportFile' | 'verifyRedirectParams';
|
|
5
|
+
export declare const OPERATIONS: {
|
|
6
|
+
readonly [id in OperationId]: Operation;
|
|
7
|
+
};
|
|
8
|
+
/** The named schemas a parameter or a request body refers to. */
|
|
9
|
+
export declare const SCHEMAS: {
|
|
10
|
+
readonly [name: string]: Schema;
|
|
11
|
+
};
|