@jinshuju/cli 0.22.0 → 0.24.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 -5
- package/dist/commands/entry.js +80 -2
- package/dist/commands/form.js +286 -2
- package/dist/commands/message.js +42 -2
- package/dist/commands/sms.js +5 -22
- package/dist/commands/upload.d.ts +20 -3
- package/dist/commands/upload.js +34 -7
- package/dist/errors.d.ts +10 -2
- package/dist/errors.js +2 -1
- package/dist/generated/operations.d.ts +1 -1
- package/dist/generated/operations.js +470 -50
- package/dist/http.js +47 -23
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { type OperationId } from '../spec.js';
|
|
|
4
4
|
* What the CLI uploads a form image as. A test holds the list to the spec's
|
|
5
5
|
* `image_type`, which is where it would otherwise drift.
|
|
6
6
|
*/
|
|
7
|
-
export declare const FORM_IMAGE_TYPES: readonly ["description", "header", "wallpaper", "opensearch_header"];
|
|
7
|
+
export declare const FORM_IMAGE_TYPES: readonly ["description", "header", "wallpaper", "opensearch_header", "wheel_fortune_prize"];
|
|
8
8
|
export type FormImageType = (typeof FORM_IMAGE_TYPES)[number];
|
|
9
9
|
/**
|
|
10
10
|
* A file on disk, as multipart. The three endpoints that take one authenticate
|
|
@@ -13,7 +13,24 @@ export type FormImageType = (typeof FORM_IMAGE_TYPES)[number];
|
|
|
13
13
|
*/
|
|
14
14
|
export declare function upload(id: OperationId, path: Record<string, string>, file: string, extra?: Record<string, string>): HttpRequest;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* The size of a file about to go up, once it is found to be a file this
|
|
17
|
+
* process may read. A bare stat passes a directory and an unreadable file, and
|
|
18
|
+
* a command uploading several would then fail only after the first went up.
|
|
19
|
+
*/
|
|
20
|
+
export declare function readableSize(file: string): number;
|
|
21
|
+
/** One file to upload, and the key of the id the answer gives it. */
|
|
22
|
+
interface Upload {
|
|
23
|
+
id: OperationId;
|
|
24
|
+
path?: Record<string, string>;
|
|
25
|
+
file: string;
|
|
26
|
+
extra?: Record<string, string>;
|
|
27
|
+
key: string;
|
|
28
|
+
}
|
|
29
|
+
/** A file uploaded with a progress line while it goes, answered by its id. */
|
|
30
|
+
export declare function uploadedId(client: HttpClient, { id, path, file, extra, key }: Upload): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* An image that a form's theme, one of its public queries or a prize of its lucky wheel
|
|
33
|
+
* refers to by id, uploaded with `imageType` saying which.
|
|
18
34
|
*/
|
|
19
35
|
export declare function uploadFormImage(client: HttpClient, file: string, imageType: FormImageType): Promise<string>;
|
|
36
|
+
export {};
|
package/dist/commands/upload.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UsageError } from '../options.js';
|
|
2
2
|
import { progress } from '../progress.js';
|
|
3
3
|
import { call } from '../spec.js';
|
|
4
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { accessSync, constants, readFileSync, statSync } from 'node:fs';
|
|
5
5
|
import { basename, extname } from 'node:path';
|
|
6
6
|
/**
|
|
7
7
|
* The media type of an upload, by extension. The server stores the type the
|
|
@@ -25,7 +25,13 @@ const UPLOAD_TYPES = {
|
|
|
25
25
|
* What the CLI uploads a form image as. A test holds the list to the spec's
|
|
26
26
|
* `image_type`, which is where it would otherwise drift.
|
|
27
27
|
*/
|
|
28
|
-
export const FORM_IMAGE_TYPES = [
|
|
28
|
+
export const FORM_IMAGE_TYPES = [
|
|
29
|
+
'description',
|
|
30
|
+
'header',
|
|
31
|
+
'wallpaper',
|
|
32
|
+
'opensearch_header',
|
|
33
|
+
'wheel_fortune_prize'
|
|
34
|
+
];
|
|
29
35
|
/**
|
|
30
36
|
* A file on disk, as multipart. The three endpoints that take one authenticate
|
|
31
37
|
* like every other request, so there is no ticket to fetch first: the file goes
|
|
@@ -47,17 +53,38 @@ export function upload(id, path, file, extra = {}) {
|
|
|
47
53
|
return call(id, { path, form });
|
|
48
54
|
}
|
|
49
55
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
56
|
+
* The size of a file about to go up, once it is found to be a file this
|
|
57
|
+
* process may read. A bare stat passes a directory and an unreadable file, and
|
|
58
|
+
* a command uploading several would then fail only after the first went up.
|
|
52
59
|
*/
|
|
53
|
-
export
|
|
60
|
+
export function readableSize(file) {
|
|
61
|
+
try {
|
|
62
|
+
accessSync(file, constants.R_OK);
|
|
63
|
+
const stats = statSync(file);
|
|
64
|
+
if (stats.isFile())
|
|
65
|
+
return stats.size;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new UsageError(`could not read ${file}: ${error.message}`);
|
|
69
|
+
}
|
|
70
|
+
throw new UsageError(`could not read ${file}: not a file`);
|
|
71
|
+
}
|
|
72
|
+
/** A file uploaded with a progress line while it goes, answered by its id. */
|
|
73
|
+
export async function uploadedId(client, { id, path = {}, file, extra, key }) {
|
|
54
74
|
const watching = progress();
|
|
55
75
|
watching.step(`uploading ${basename(file)}…`);
|
|
56
76
|
try {
|
|
57
|
-
const
|
|
58
|
-
return
|
|
77
|
+
const answer = await client.request(upload(id, path, file, extra));
|
|
78
|
+
return answer[key];
|
|
59
79
|
}
|
|
60
80
|
finally {
|
|
61
81
|
watching.done();
|
|
62
82
|
}
|
|
63
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* An image that a form's theme, one of its public queries or a prize of its lucky wheel
|
|
86
|
+
* refers to by id, uploaded with `imageType` saying which.
|
|
87
|
+
*/
|
|
88
|
+
export function uploadFormImage(client, file, imageType) {
|
|
89
|
+
return uploadedId(client, { id: 'uploadFormImage', file, extra: { image_type: imageType }, key: 'attachment_id' });
|
|
90
|
+
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ export interface Refusal {
|
|
|
7
7
|
readonly pointer: string;
|
|
8
8
|
readonly message: string;
|
|
9
9
|
}
|
|
10
|
+
/** A reason as API v1's 400 gives it in errors[]: every place it occurs, as JSON Pointers. */
|
|
11
|
+
export interface Reason {
|
|
12
|
+
readonly pointers: readonly string[];
|
|
13
|
+
readonly message: string;
|
|
14
|
+
}
|
|
10
15
|
/**
|
|
11
16
|
* A body refused here, before it was sent, by the openapi.yaml this CLI
|
|
12
17
|
* shipped with (src/preflight.ts). Usage, like any input the CLI could not
|
|
@@ -61,8 +66,11 @@ export type ClassifiedError = {
|
|
|
61
66
|
body?: unknown;
|
|
62
67
|
/** Seconds the server asked for before trying again, when it said. */
|
|
63
68
|
retry_after?: number;
|
|
64
|
-
/**
|
|
65
|
-
|
|
69
|
+
/**
|
|
70
|
+
* What a body was refused for before it was sent, in the shape of a server's
|
|
71
|
+
* 400 so a caller reads both the same way.
|
|
72
|
+
*/
|
|
73
|
+
errors?: readonly Reason[];
|
|
66
74
|
};
|
|
67
75
|
/**
|
|
68
76
|
* Sorts a failure into its kind. An error that wraps another — "the form was
|
package/dist/errors.js
CHANGED
|
@@ -94,7 +94,8 @@ function retryAfterIn(body) {
|
|
|
94
94
|
export function classify(error) {
|
|
95
95
|
const message = error instanceof Error ? error.message : String(error);
|
|
96
96
|
if (error instanceof PreflightError) {
|
|
97
|
-
|
|
97
|
+
const errors = error.errors.map(({ pointer, message }) => ({ pointers: [pointer], message }));
|
|
98
|
+
return { kind: 'usage', exitCode: EXIT_CODES.usage, message, errors };
|
|
98
99
|
}
|
|
99
100
|
if (error instanceof UsageError)
|
|
100
101
|
return { kind: 'usage', exitCode: EXIT_CODES.usage, message };
|
|
@@ -3,7 +3,7 @@ import type { Operation, Schema } from '../spec.js';
|
|
|
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
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';
|
|
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' | 'exportRemainingVouchers' | 'getBillingAccount' | 'getCheckinCampaign' | 'getCurrentUser' | 'getEmailTask' | 'getEntry' | 'getEntryImport' | 'getEntryStateFlow' | 'getEntryStats' | 'getEvaluationSetting' | 'getExamSetting' | 'getFieldType' | 'getFillFormPage' | 'getFillViewPage' | 'getFolder' | 'getForm' | 'getFormSetting' | 'getFormView' | 'getManuallyCloseRule' | 'getMemory' | 'getMessage' | 'getMessageChannel' | 'getNotificationRule' | 'getOpensearchQuery' | 'getPublishedArtifact' | 'getQuickpaySetting' | 'getRoutine' | 'getSmsTask' | 'getTable' | 'getTableEntry' | 'getTableView' | 'getTradeMerchant' | 'getWheelFortune' | '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' | 'prepareGoodsDeliverableAttachmentUpload' | 'prepareImportFileUpload' | 'previewFormFieldTypeChange' | 'previewTableFieldTypeChange' | 'replaceEntry' | 'replaceTableEntry' | 'resendEmailTask' | 'resendSmsTask' | 'resumeRoutine' | 'runRoutine' | 'searchEntriesAcrossForms' | 'searchMySubmittedEntries' | 'sendMessage' | 'sendSmsTask' | 'summarizeEntries' | 'summarizeFormViewEntries' | 'summarizeTableEntries' | 'summarizeTableViewEntries' | 'updateAccessPolicy' | 'updateCheckinCampaign' | 'updateEntry' | 'updateEntryComment' | 'updateEntryStateFlow' | 'updateEntryViaPost' | 'updateEvaluationSetting' | 'updateExamSetting' | 'updateForm' | 'updateFormSetting' | 'updateFormTheme' | 'updateFormView' | 'updateManuallyCloseRule' | 'updateMemoryNote' | 'updateNotificationRule' | 'updateOpensearchQuery' | 'updatePublishedArtifact' | 'updateQuickpaySetting' | 'updateRoutine' | 'updateSmsSignature' | 'updateSmsTask' | 'updateSmsTemplate' | 'updateTable' | 'updateTableEntry' | 'updateTableEntryComment' | 'updateTableEntryViaPost' | 'updateTableView' | 'updateWheelFortune' | 'uploadEntryAttachment' | 'uploadFormImage' | 'uploadGoodsDeliverableAttachment' | 'uploadImportFile' | 'uploadUserLicenseAttachment' | 'verifyRedirectParams';
|
|
7
7
|
export declare const OPERATIONS: {
|
|
8
8
|
readonly [id in OperationId]: Operation;
|
|
9
9
|
};
|