@jinshuju/cli 0.20.0 → 0.21.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 +21 -3
- package/dist/cli.js +5 -2
- package/dist/commands/field.js +14 -2
- package/dist/commands/form.js +21 -4
- package/dist/errors.d.ts +17 -0
- package/dist/errors.js +17 -0
- package/dist/generated/operations.d.ts +3 -1
- package/dist/generated/operations.js +616 -29
- package/dist/http.d.ts +6 -0
- package/dist/http.js +58 -11
- package/dist/options.js +116 -4
- package/dist/preflight.d.ts +32 -0
- package/dist/preflight.js +156 -0
- package/dist/schema.d.ts +39 -0
- package/dist/schema.js +239 -0
- package/dist/spec.d.ts +19 -0
- package/dist/spec.js +23 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -85,6 +85,7 @@ field — the server assigns it.
|
|
|
85
85
|
jinshuju form create --json @form.json --scene registry --layout card --folder Fd2xK8
|
|
86
86
|
jinshuju form create --json @exam.json --type exam # the payload may carry exam_setting
|
|
87
87
|
jinshuju form edit Kp7mQ2 --json '{"exam_setting":{"limited_time":45}}'
|
|
88
|
+
jinshuju form get Kp7mQ2 --include exam_setting # reads it back with the form
|
|
88
89
|
|
|
89
90
|
jinshuju form create --json '{
|
|
90
91
|
"name": "Event signup",
|
|
@@ -163,9 +164,13 @@ maximum (50 in most cases), and anything larger is capped.
|
|
|
163
164
|
`--all` reads at most 200 pages. Past that it stops with an error naming the
|
|
164
165
|
cursor; pass it to `--next` (with `--all` again) to read on.
|
|
165
166
|
|
|
166
|
-
`--filter` is repeatable
|
|
167
|
-
|
|
168
|
-
the
|
|
167
|
+
`--filter` is repeatable, one condition per flag, and the conditions are
|
|
168
|
+
AND-combined. An operator written otherwise (`=`, `in`, `not_empty`) is refused
|
|
169
|
+
with the one meant, one the CLI's copy of the spec does not list goes through
|
|
170
|
+
for the API to judge, two conditions in one flag are refused with the way to
|
|
171
|
+
write them, and a value in quotes is taken whole, without them. For conditions
|
|
172
|
+
it cannot express, use `--filters <json|@file>`. Cursors are opaque strings —
|
|
173
|
+
pass the `next` value from the previous response back verbatim.
|
|
169
174
|
|
|
170
175
|
## Analysis
|
|
171
176
|
|
|
@@ -240,6 +245,14 @@ jinshuju field update-choices --form Kp7mQ2 field_7 --json '{"add":[{"label":"Th
|
|
|
240
245
|
jinshuju field remove --form Kp7mQ2 field_9 --yes
|
|
241
246
|
```
|
|
242
247
|
|
|
248
|
+
A payload is looked at once before it is sent, against the openapi.yaml the
|
|
249
|
+
CLI shipped with, and refused only for what a newer API could not have made
|
|
250
|
+
right: a required key missing, a value of the wrong type, `null` for a key
|
|
251
|
+
that cannot be null, a field's `validation` written back as `form get` returned
|
|
252
|
+
it. A key or a value that copy does not list is sent for the API to judge, since
|
|
253
|
+
the API may have learned it since. A refusal names the day the copy was
|
|
254
|
+
fetched, and `--as-is` sends the payload anyway.
|
|
255
|
+
|
|
243
256
|
Data and views:
|
|
244
257
|
|
|
245
258
|
```bash
|
|
@@ -430,6 +443,11 @@ parsing anything:
|
|
|
430
443
|
| 7 | transport: the connection failed or timed out |
|
|
431
444
|
| 8 | rate limited: wait and retry; the message and `retry_after` say how long |
|
|
432
445
|
|
|
446
|
+
A refusal with several reasons lists every one of them, one line each, even
|
|
447
|
+
when the server's own description repeats only the first three: a request body
|
|
448
|
+
that is wrong in five places is corrected in one go rather than in five. A list
|
|
449
|
+
longer than twenty is cut, and says how many it kept back.
|
|
450
|
+
|
|
433
451
|
With `--output json`, stderr carries the same as JSON, plus the status and body
|
|
434
452
|
the server answered with:
|
|
435
453
|
|
package/dist/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { helpFor, rootHelp } from './help.js';
|
|
|
5
5
|
import { HttpError, JinshujuHttpClient } from './http.js';
|
|
6
6
|
import { runLocal } from './local.js';
|
|
7
7
|
import { GLOBAL_OPTIONS, LOCAL_OPTIONS, UsageError } from './options.js';
|
|
8
|
+
import { checked } from './preflight.js';
|
|
8
9
|
import { progress } from './progress.js';
|
|
9
10
|
import { format, terminalWidth } from './render.js';
|
|
10
11
|
import { fail, ok, outputOf, unknown } from './result.js';
|
|
@@ -43,12 +44,14 @@ async function runRemote(command, words, flags, runtime, stdin) {
|
|
|
43
44
|
const input = { ...bindArgs(command, words), options };
|
|
44
45
|
const output = options.output ?? 'text';
|
|
45
46
|
const width = runtime.width ?? terminalWidth();
|
|
46
|
-
|
|
47
|
+
// Every request leaves through the preflight, a test's mock client's too:
|
|
48
|
+
// a body is looked at once, on its way to the wire, whichever command built it.
|
|
49
|
+
const client = checked(runtime.client ??
|
|
47
50
|
new JinshujuHttpClient(loadConfig({
|
|
48
51
|
configPath: options.config ?? defaultConfigPath,
|
|
49
52
|
env: runtime.env,
|
|
50
53
|
cli: { host: options.host }
|
|
51
|
-
}));
|
|
54
|
+
})), options.as_is === true);
|
|
52
55
|
// A command that needs more than one round trip, or has to decide how many,
|
|
53
56
|
// runs itself and answers with what should be printed.
|
|
54
57
|
const hints = { list: command.text?.list ?? command.paginate?.items, essentialLists: command.text?.essentialLists };
|
package/dist/commands/field.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { CONTAINER_OPTIONS, JSON_OPTION, UsageError } from '../options.js';
|
|
2
2
|
import { call, choices } from '../spec.js';
|
|
3
3
|
import { YES_OPTION, confirmed, onContainer, one, payload, requiredOption } from './shared.js';
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* One field, or a list of them — the same objects `fields` holds above. And
|
|
6
|
+
* what a field read back is not: what the CLI's callers were most often
|
|
7
|
+
* refused for was a field written back as `form get` returned it.
|
|
8
|
+
*/
|
|
5
9
|
const FIELD_PAYLOAD = [
|
|
6
10
|
'{ "type": "TextField", "label": "Notes", "required": false }',
|
|
7
11
|
'',
|
|
12
|
+
'A field as `form get` or `field list` returns it is not a field to write back:',
|
|
13
|
+
' validation: {required, unique, minimum_length, …} is written flat on the field',
|
|
14
|
+
' choices are changed with `field update-choices`; `field update` takes them only on a',
|
|
15
|
+
' CascadeDropDown, or with a `type` that turns a text field into a choice field',
|
|
16
|
+
' a key read as null is left out, not written as null',
|
|
17
|
+
'',
|
|
8
18
|
'Field types: jinshuju field types'
|
|
9
19
|
];
|
|
10
20
|
/**
|
|
@@ -227,9 +237,11 @@ export const FIELD = [
|
|
|
227
237
|
{
|
|
228
238
|
path: ['field', 'update'],
|
|
229
239
|
summary: 'Update one field',
|
|
230
|
-
description: 'The patch is merged onto the field; the api_code comes from the argument, not the payload.'
|
|
240
|
+
description: 'The patch is merged onto the field; the api_code comes from the argument, not the payload. ' +
|
|
241
|
+
'Write only the keys to change, flat on the field, as the payload below says.',
|
|
231
242
|
args: [{ name: 'api-code', required: true, description: 'Field api_code, e.g. field_3' }],
|
|
232
243
|
options: [...CONTAINER_OPTIONS, JSON_OPTION],
|
|
244
|
+
payload: FIELD_PAYLOAD,
|
|
233
245
|
request: (input) => onContainer(input, 'updateForm', 'updateTable', {
|
|
234
246
|
body: {
|
|
235
247
|
fields: { update: [{ ...payload(input), api_code: input.args['api-code'] }] }
|
package/dist/commands/form.js
CHANGED
|
@@ -61,7 +61,13 @@ const FORM_INCLUDES = {
|
|
|
61
61
|
rules: 'include_field_rules',
|
|
62
62
|
extended: 'include_extended_attributes',
|
|
63
63
|
transactions: 'include_transactions',
|
|
64
|
-
analytics: 'include_analytics'
|
|
64
|
+
analytics: 'include_analytics',
|
|
65
|
+
// An exam form's exam settings, under the key `form edit` writes them by;
|
|
66
|
+
// any other form carries nothing for it. The one name here that is the key
|
|
67
|
+
// itself: `exam` alone reads as the scene, and this list already has
|
|
68
|
+
// `setting`, which it sits beside. An OAuth token needs the form_setting
|
|
69
|
+
// scope, which the CLI's own login asks for.
|
|
70
|
+
exam_setting: 'include_exam_setting'
|
|
65
71
|
};
|
|
66
72
|
const INCLUDE_OPTION = {
|
|
67
73
|
name: '--include',
|
|
@@ -188,13 +194,18 @@ export const FORM = [
|
|
|
188
194
|
summary: 'Show a form: fields, types, choices',
|
|
189
195
|
description: 'The form carries its setting already. --include adds the blocks that are separate reads ' +
|
|
190
196
|
'otherwise, so asking for a form and its rules is one round trip. analytics says which ' +
|
|
191
|
-
'statistics each field takes, which is what the analysis reads validate against.
|
|
197
|
+
'statistics each field takes, which is what the analysis reads validate against. ' +
|
|
198
|
+
"exam_setting is an exam form's, read back in the shape `form edit` writes it. `fields` " +
|
|
192
199
|
'comes back as a list of one-key objects keyed by api_code, not a flat list — `field list` ' +
|
|
193
200
|
'answers the same fields flattened, with api_code on each.',
|
|
194
201
|
args: [{ name: 'form', required: true, description: 'Form token, six letters and digits, e.g. Kp7mQ2' }],
|
|
195
202
|
options: [INCLUDE_OPTION],
|
|
196
203
|
request: (input) => call('getForm', { path: { form_token: input.args.form }, query: includes(input) }),
|
|
197
|
-
examples: [
|
|
204
|
+
examples: [
|
|
205
|
+
'jinshuju form get Kp7mQ2',
|
|
206
|
+
'jinshuju form get Kp7mQ2 --include theme,rules,analytics',
|
|
207
|
+
'jinshuju form get Kp7mQ2 --include exam_setting'
|
|
208
|
+
]
|
|
198
209
|
},
|
|
199
210
|
{
|
|
200
211
|
path: ['form', 'create'],
|
|
@@ -233,6 +244,9 @@ export const FORM = [
|
|
|
233
244
|
const { body, settings } = createFormBody(input);
|
|
234
245
|
if (!settings)
|
|
235
246
|
return client.request(call('createForm', { body }));
|
|
247
|
+
// The settings can only be sent to a form that exists, but what they
|
|
248
|
+
// would be refused for here can be said before one is made.
|
|
249
|
+
client.check?.(saveSettings('new', settings));
|
|
236
250
|
const form = await client.request(call('createForm', { body }));
|
|
237
251
|
try {
|
|
238
252
|
await client.request(saveSettings(form.token, settings));
|
|
@@ -268,7 +282,10 @@ export const FORM = [
|
|
|
268
282
|
delete body[settings.key];
|
|
269
283
|
// The settings go first: they are the half that can be refused for what
|
|
270
284
|
// the form is, so leading with them is what keeps a refusal from landing
|
|
271
|
-
// after the rest was already written.
|
|
285
|
+
// after the rest was already written. What the rest would be refused for
|
|
286
|
+
// here is said before either goes.
|
|
287
|
+
if (Object.keys(body).length > 0)
|
|
288
|
+
client.check?.(call('updateForm', { path: { form_token: form }, body }));
|
|
272
289
|
await client.request(saveSettings(form, settings));
|
|
273
290
|
if (Object.keys(body).length === 0)
|
|
274
291
|
return client.request(call('getForm', { path: { form_token: form } }));
|
package/dist/errors.d.ts
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
2
2
|
export declare class UsageError extends Error {
|
|
3
3
|
name: string;
|
|
4
4
|
}
|
|
5
|
+
/** One thing a body was refused for before it was sent, at the value a JSON Pointer names. */
|
|
6
|
+
export interface Refusal {
|
|
7
|
+
readonly pointer: string;
|
|
8
|
+
readonly message: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A body refused here, before it was sent, by the openapi.yaml this CLI
|
|
12
|
+
* shipped with (src/preflight.ts). Usage, like any input the CLI could not
|
|
13
|
+
* take, and the reasons are kept apart from the words so `--output json`
|
|
14
|
+
* can carry them the way a server's 400 carries its errors[].
|
|
15
|
+
*/
|
|
16
|
+
export declare class PreflightError extends UsageError {
|
|
17
|
+
readonly errors: readonly Refusal[];
|
|
18
|
+
constructor(message: string, errors: readonly Refusal[]);
|
|
19
|
+
}
|
|
5
20
|
/** No credential, or one the server would not take. */
|
|
6
21
|
export declare class AuthError extends Error {
|
|
7
22
|
name: string;
|
|
@@ -46,6 +61,8 @@ export type ClassifiedError = {
|
|
|
46
61
|
body?: unknown;
|
|
47
62
|
/** Seconds the server asked for before trying again, when it said. */
|
|
48
63
|
retry_after?: number;
|
|
64
|
+
/** What a body was refused for before it was sent, each at its pointer. */
|
|
65
|
+
errors?: readonly Refusal[];
|
|
49
66
|
};
|
|
50
67
|
/**
|
|
51
68
|
* Sorts a failure into its kind. An error that wraps another — "the form was
|
package/dist/errors.js
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
export class UsageError extends Error {
|
|
3
3
|
name = 'UsageError';
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* A body refused here, before it was sent, by the openapi.yaml this CLI
|
|
7
|
+
* shipped with (src/preflight.ts). Usage, like any input the CLI could not
|
|
8
|
+
* take, and the reasons are kept apart from the words so `--output json`
|
|
9
|
+
* can carry them the way a server's 400 carries its errors[].
|
|
10
|
+
*/
|
|
11
|
+
export class PreflightError extends UsageError {
|
|
12
|
+
errors;
|
|
13
|
+
constructor(message, errors) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.errors = errors;
|
|
16
|
+
this.name = 'PreflightError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
5
19
|
/** No credential, or one the server would not take. */
|
|
6
20
|
export class AuthError extends Error {
|
|
7
21
|
name = 'AuthError';
|
|
@@ -79,6 +93,9 @@ function retryAfterIn(body) {
|
|
|
79
93
|
*/
|
|
80
94
|
export function classify(error) {
|
|
81
95
|
const message = error instanceof Error ? error.message : String(error);
|
|
96
|
+
if (error instanceof PreflightError) {
|
|
97
|
+
return { kind: 'usage', exitCode: EXIT_CODES.usage, message, errors: error.errors };
|
|
98
|
+
}
|
|
82
99
|
if (error instanceof UsageError)
|
|
83
100
|
return { kind: 'usage', exitCode: EXIT_CODES.usage, message };
|
|
84
101
|
if (error instanceof AuthError)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Operation, Schema } from '../spec.js';
|
|
2
2
|
/** The path every operation's path is relative to, from `servers`. */
|
|
3
3
|
export declare const BASE_PATH = "/api/v1";
|
|
4
|
-
|
|
4
|
+
/** The day spec/openapi.yaml was fetched from the API, when scripts/fetch-spec.mjs recorded it. */
|
|
5
|
+
export declare const SPEC_DATE: string | undefined;
|
|
6
|
+
export type OperationId = 'aggregateEntries' | 'aggregateFormViewEntries' | 'aggregateTableEntries' | 'aggregateTableViewEntries' | 'aggregateTradeTransactions' | 'checkFormFieldData' | 'checkTableFieldData' | 'copyForm' | 'countEntries' | 'countEntriesAcrossForms' | 'countFormViewEntries' | 'countTableEntries' | 'countTableViewEntries' | 'createCheckinCampaign' | 'createEmailTask' | 'createEntriesBatch' | 'createEntry' | 'createEntryComment' | 'createEntryImport' | 'createEntryLegacy' | 'createFillFormEntry' | 'createFillViewEntry' | 'createFolder' | 'createForm' | 'createFormView' | 'createFormWebhook' | 'createMemoryNote' | 'createMessageChannel' | 'createNotificationRule' | 'createOpensearchQuery' | 'createRoutine' | 'createSmsSignature' | 'createSmsTask' | 'createSmsTemplate' | 'createTable' | 'createTableEntry' | 'createTableEntryComment' | 'createTableView' | 'createTemplateUsage' | 'createWeixinOauthSession' | 'deleteCheckinCampaign' | 'deleteEntry' | 'deleteEntryComment' | 'deleteForm' | 'deleteFormView' | 'deleteFormWebhook' | 'deleteMemoryNotes' | 'deleteMessageChannel' | 'deleteNotificationRule' | 'deleteRoutine' | 'deleteSmsSignature' | 'deleteSmsTemplate' | 'deleteTable' | 'deleteTableEntry' | 'deleteTableEntryComment' | 'deleteTableView' | 'estimateEmailTask' | 'estimateEmailTaskResend' | 'estimateMessage' | 'estimateSmsTask' | 'estimateSmsTaskChange' | 'estimateSmsTaskResend' | 'getBillingAccount' | 'getCheckinCampaign' | 'getCurrentUser' | 'getEmailTask' | 'getEntry' | 'getEntryImport' | 'getEntryStats' | 'getEvaluationSetting' | 'getExamSetting' | 'getFieldType' | 'getFillFormPage' | 'getFillViewPage' | 'getFolder' | 'getForm' | 'getFormSetting' | 'getFormView' | 'getManuallyCloseRule' | 'getMemory' | 'getMessage' | 'getMessageChannel' | 'getNotificationRule' | 'getOpensearchQuery' | 'getPublishedArtifact' | 'getRoutine' | 'getSmsTask' | 'getTable' | 'getTableEntry' | 'getTableView' | 'getTradeMerchant' | 'listArtifacts' | 'listBillingAccountInvoices' | 'listBillingAccountPaidFeatures' | 'listBillingAccountPaymentHistories' | 'listBillingAccountUsers' | 'listCheckinCampaigns' | 'listContacts' | 'listEmailTaskActivities' | 'listEmailTasks' | 'listEntries' | 'listEntryComments' | 'listExtendedAttributes' | 'listFieldRules' | 'listFieldTypes' | 'listFolders' | 'listFormConditionTriggerableFields' | 'listFormCooperators' | 'listFormViewEntries' | 'listFormViews' | 'listForms' | 'listMessageChannels' | 'listMessages' | 'listMyFilledForms' | 'listMySubmittedEntries' | 'listNotificationRuleNotifications' | 'listNotificationRules' | 'listOpensearchQueries' | 'listOpensearchQuerySuggestions' | 'listRoutineRuns' | 'listRoutines' | 'listSmsAuditStatuses' | 'listSmsSignatures' | 'listSmsTaskActivities' | 'listSmsTasks' | 'listSmsTemplates' | 'listSmtpAccounts' | 'listTableConditionTriggerableFields' | 'listTableEntries' | 'listTableEntryComments' | 'listTableViewEntries' | 'listTableViews' | 'listTables' | 'listTradePayouts' | 'listTradeRefunds' | 'listTradeTransactions' | 'moveFormToFolder' | 'moveTableToFolder' | 'patchEntriesBatch' | 'pauseRoutine' | 'prepareEntryAttachmentUpload' | 'prepareFormImageUpload' | 'prepareImportFileUpload' | 'previewFormFieldTypeChange' | 'previewTableFieldTypeChange' | 'replaceEntry' | 'replaceTableEntry' | 'resendEmailTask' | 'resendSmsTask' | 'resumeRoutine' | 'runRoutine' | 'searchEntriesAcrossForms' | 'searchMySubmittedEntries' | 'sendMessage' | 'sendSmsTask' | 'summarizeEntries' | 'summarizeFormViewEntries' | 'summarizeTableEntries' | 'summarizeTableViewEntries' | 'updateAccessPolicy' | 'updateCheckinCampaign' | 'updateEntry' | 'updateEntryComment' | 'updateEntryViaPost' | 'updateEvaluationSetting' | 'updateExamSetting' | 'updateForm' | 'updateFormSetting' | 'updateFormTheme' | 'updateFormView' | 'updateManuallyCloseRule' | 'updateMemoryNote' | 'updateNotificationRule' | 'updateOpensearchQuery' | 'updatePublishedArtifact' | 'updateRoutine' | 'updateSmsSignature' | 'updateSmsTask' | 'updateSmsTemplate' | 'updateTable' | 'updateTableEntry' | 'updateTableEntryComment' | 'updateTableEntryViaPost' | 'updateTableView' | 'uploadEntryAttachment' | 'uploadFormImage' | 'uploadImportFile' | 'uploadUserLicenseAttachment' | 'verifyRedirectParams';
|
|
5
7
|
export declare const OPERATIONS: {
|
|
6
8
|
readonly [id in OperationId]: Operation;
|
|
7
9
|
};
|