@jinshuju/cli 0.23.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 +12 -2
- package/dist/commands/entry.js +80 -2
- package/dist/commands/form.js +286 -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 +466 -49
- package/dist/http.js +47 -23
- package/package.json +1 -1
package/dist/http.js
CHANGED
|
@@ -79,12 +79,28 @@ function describeFailure(response, text, parsed) {
|
|
|
79
79
|
const stated = body.message ?? body.error_description;
|
|
80
80
|
if (typeof stated === 'string' && stated.trim()) {
|
|
81
81
|
const reasons = everyReason(body, stated);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const said = reasons
|
|
83
|
+
? [withCode(reasons.head, body.error), ...reasons.rest.map((line) => ` ${line}`)]
|
|
84
|
+
: [withCode(stated, body.error)];
|
|
85
|
+
return [...said, ...restOf(body)].join('\n');
|
|
85
86
|
}
|
|
86
87
|
return rowErrors(body) ?? `${status}: ${snippet(JSON.stringify(parsed.value))}`;
|
|
87
88
|
}
|
|
89
|
+
/** What a refusal's lines above already say: the reason, the code and every reason in errors[]. */
|
|
90
|
+
const SAID = new Set(['message', 'error_description', 'error', 'errors']);
|
|
91
|
+
/**
|
|
92
|
+
* What a refusal carries besides its reason, a line a field under it: the paid
|
|
93
|
+
* features and the plan a plan refusal names, the balance a short VAS leaves. A
|
|
94
|
+
* caller reading text output, as Jiri does, passes these on as much as it acts
|
|
95
|
+
* on the code; `--output json` has them already, in `body`. Anything but a
|
|
96
|
+
* string is JSON, not a table: a table keeps the scalar columns, and each paid
|
|
97
|
+
* feature's lowest_plan would not reach the caller.
|
|
98
|
+
*/
|
|
99
|
+
function restOf(body) {
|
|
100
|
+
return Object.entries(body)
|
|
101
|
+
.filter(([key]) => !SAID.has(key))
|
|
102
|
+
.map(([key, value]) => ` ${key}: ${typeof value === 'string' ? value : JSON.stringify(value)}`);
|
|
103
|
+
}
|
|
88
104
|
function withCode(reason, code) {
|
|
89
105
|
if (typeof code !== 'string' || !code.trim() || reason.includes(code))
|
|
90
106
|
return reason;
|
|
@@ -101,43 +117,39 @@ const MAX_REASONS = 20;
|
|
|
101
117
|
* three of what may be a hundred and counts the rest. A caller shown the
|
|
102
118
|
* description alone corrects what it was told, sends again, and learns the
|
|
103
119
|
* next. So every reason is a line of its own, under whatever the description
|
|
104
|
-
* said ahead of the first ("Request body invalid:"). One line per
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
120
|
+
* said ahead of the first ("Request body invalid:"). One line per entry of
|
|
121
|
+
* errors[]: API v1 already says a mistake made in several places once, its
|
|
122
|
+
* `pointers` naming them all and its message the first five, so splitting an
|
|
123
|
+
* entry by place would print it again for each, and two reasons at one place
|
|
124
|
+
* (a field that may be one of several shapes) are two things to fix. The
|
|
125
|
+
* places go in front of a line only when its message names none of them; an
|
|
126
|
+
* older server's single `pointer` counts as one place. A list too long to read
|
|
127
|
+
* is cut, and says how many it kept back.
|
|
109
128
|
*/
|
|
110
129
|
function everyReason(body, stated) {
|
|
111
130
|
const errors = body.errors;
|
|
112
131
|
if (!Array.isArray(errors) || errors.length === 0)
|
|
113
132
|
return undefined;
|
|
114
|
-
|
|
115
|
-
const said = new Map();
|
|
133
|
+
const lines = [];
|
|
116
134
|
let first;
|
|
117
|
-
let count = 0;
|
|
118
135
|
for (const item of errors) {
|
|
119
136
|
if (item === null || typeof item !== 'object')
|
|
120
137
|
continue;
|
|
121
|
-
const {
|
|
138
|
+
const { message } = item;
|
|
122
139
|
if (typeof message !== 'string' || !message.trim())
|
|
123
140
|
continue;
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
141
|
+
const places = placesOf(item);
|
|
142
|
+
const unplaced = places.length > 0 && !places.some((place) => message.includes(place));
|
|
143
|
+
const line = unplaced ? `${placeList(places)}: ${message}` : message;
|
|
144
|
+
if (lines.includes(line))
|
|
127
145
|
continue;
|
|
128
|
-
|
|
129
|
-
said.set(at ?? message, entry);
|
|
146
|
+
lines.push(line);
|
|
130
147
|
first ??= message;
|
|
131
|
-
count += 1;
|
|
132
148
|
}
|
|
133
149
|
if (first === undefined)
|
|
134
150
|
return undefined;
|
|
135
|
-
if (
|
|
151
|
+
if (lines.length === 1 && stated.includes(first))
|
|
136
152
|
return undefined;
|
|
137
|
-
const lines = [...said.values()].map(({ at, messages }) => {
|
|
138
|
-
const text = messages.join('; ');
|
|
139
|
-
return at && !messages.some((message) => message.includes(at)) ? `${at}: ${text}` : text;
|
|
140
|
-
});
|
|
141
153
|
const kept = lines.slice(0, MAX_REASONS);
|
|
142
154
|
if (lines.length > kept.length)
|
|
143
155
|
kept.push(`… and ${lines.length - kept.length} more; --output json carries them all`);
|
|
@@ -149,6 +161,18 @@ function everyReason(body, stated) {
|
|
|
149
161
|
return { head: heading, rest: kept };
|
|
150
162
|
return { head: kept[0], rest: kept.slice(1) };
|
|
151
163
|
}
|
|
164
|
+
/** The JSON Pointers an entry of errors[] names: API v1's `pointers`, or an older server's `pointer`. */
|
|
165
|
+
function placesOf(item) {
|
|
166
|
+
const { pointers, pointer } = item;
|
|
167
|
+
const named = Array.isArray(pointers) ? pointers : [pointer];
|
|
168
|
+
return named.filter((place) => typeof place === 'string' && place !== '');
|
|
169
|
+
}
|
|
170
|
+
/** The most places put in front of one line, as many as API v1 names in a message. */
|
|
171
|
+
const MAX_PLACES = 5;
|
|
172
|
+
function placeList(places) {
|
|
173
|
+
const named = places.slice(0, MAX_PLACES).join(', ');
|
|
174
|
+
return places.length > MAX_PLACES ? `${named} and ${places.length - MAX_PLACES} more` : named;
|
|
175
|
+
}
|
|
152
176
|
/**
|
|
153
177
|
* A batch write answers per row: `{errors: [{index, reason}]}`. The index is the
|
|
154
178
|
* caller's own array position, and is left as the server gave it so it lines up
|