@myapihq/sdk 2.27.1 → 2.27.3
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/dist/client.d.ts +9 -1
- package/dist/client.js +19 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -3,6 +3,14 @@ export declare class MyApiError extends Error {
|
|
|
3
3
|
status: number;
|
|
4
4
|
detail?: string | undefined;
|
|
5
5
|
body?: Record<string, unknown> | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* The platform's id for the failed request, from `meta.request_id`.
|
|
8
|
+
*
|
|
9
|
+
* The server returns one on every response and this discarded it, so a
|
|
10
|
+
* customer hitting `internal_error` had a bare code, nothing to quote and
|
|
11
|
+
* nothing support could trace. It is the only useful thing about a 500.
|
|
12
|
+
*/
|
|
13
|
+
requestId?: string;
|
|
6
14
|
constructor(code: string, status: number, detail?: string | undefined, body?: Record<string, unknown> | undefined);
|
|
7
15
|
}
|
|
8
16
|
/**
|
|
@@ -34,7 +42,7 @@ export interface RequestOptions {
|
|
|
34
42
|
*/
|
|
35
43
|
onReplay?: () => void;
|
|
36
44
|
}
|
|
37
|
-
export declare function toError(err: any, status: number): MyApiError;
|
|
45
|
+
export declare function toError(err: any, status: number, requestId?: string): MyApiError;
|
|
38
46
|
export declare function request<T>(method: string, url: string, apiKey?: string, body?: unknown, extraHeaders?: Record<string, string>, opts?: RequestOptions): Promise<T>;
|
|
39
47
|
export interface Page<T> {
|
|
40
48
|
data: T[];
|
package/dist/client.js
CHANGED
|
@@ -15,6 +15,14 @@ class MyApiError extends Error {
|
|
|
15
15
|
// `body` is the full error object as returned by the backend — preserved so
|
|
16
16
|
// callers can read service-specific fields the SDK doesn't otherwise model
|
|
17
17
|
// (e.g. CF_API_ERROR carries `cf_message` / `cf_status`).
|
|
18
|
+
/**
|
|
19
|
+
* The platform's id for the failed request, from `meta.request_id`.
|
|
20
|
+
*
|
|
21
|
+
* The server returns one on every response and this discarded it, so a
|
|
22
|
+
* customer hitting `internal_error` had a bare code, nothing to quote and
|
|
23
|
+
* nothing support could trace. It is the only useful thing about a 500.
|
|
24
|
+
*/
|
|
25
|
+
requestId;
|
|
18
26
|
constructor(code, status, detail, body) {
|
|
19
27
|
// Surface the detail in the message so console.error / err.message
|
|
20
28
|
// shows useful info without callers having to look at err.detail.
|
|
@@ -248,7 +256,7 @@ async function parseResponse(method, url, response) {
|
|
|
248
256
|
throw new MyApiError('invalid_json_response', response.status, `${method} ${url} returned non-JSON (status ${response.status}): ${snippet}\n${diagnoseNonJson(response.status, raw)}`);
|
|
249
257
|
}
|
|
250
258
|
if (!response.ok) {
|
|
251
|
-
throw toError(result?.error, response.status);
|
|
259
|
+
throw toError(result?.error, response.status, pickRequestId(result));
|
|
252
260
|
}
|
|
253
261
|
// A few routes answer 2xx with a BARE object — no {success, data, error,
|
|
254
262
|
// meta} envelope. `pixel identity` and `pixel events` are the two we have
|
|
@@ -288,12 +296,20 @@ async function parseResponse(method, url, response) {
|
|
|
288
296
|
// object for callers that want both. Exported because three call sites
|
|
289
297
|
// (here, function.uploadBundle, storage.uploadAsset) each hand-rolled this
|
|
290
298
|
// and each had the same bug.
|
|
291
|
-
|
|
299
|
+
/** `meta.request_id` if the envelope carries one. */
|
|
300
|
+
function pickRequestId(result) {
|
|
301
|
+
const meta = result?.meta;
|
|
302
|
+
return typeof meta?.request_id === 'string' && meta.request_id ? meta.request_id : undefined;
|
|
303
|
+
}
|
|
304
|
+
function toError(err, status, requestId) {
|
|
292
305
|
const obj = typeof err === 'object' && err !== null ? err : undefined;
|
|
293
306
|
const code = obj ? (obj.code || 'unknown_error') : (err || 'unknown_error');
|
|
294
307
|
const pick = (v) => (typeof v === 'string' && v.trim() !== '' ? v : undefined);
|
|
295
308
|
const detail = obj ? (pick(obj.detail) ?? pick(obj.message)) : undefined;
|
|
296
|
-
|
|
309
|
+
const e = new MyApiError(code, status, detail, obj);
|
|
310
|
+
if (requestId)
|
|
311
|
+
e.requestId = requestId;
|
|
312
|
+
return e;
|
|
297
313
|
}
|
|
298
314
|
// Returns the unwrapped `data` payload — the common case.
|
|
299
315
|
async function request(method, url, apiKey, body, extraHeaders, opts) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.27.
|
|
1
|
+
export declare const SDK_VERSION = "2.27.3";
|
package/dist/version.js
CHANGED
|
@@ -8,4 +8,4 @@ exports.SDK_VERSION = void 0;
|
|
|
8
8
|
// Why a constant and not a package.json read: the SDK runs inside edge
|
|
9
9
|
// functions (Cloudflare Workers), so it must not import node:fs. A literal
|
|
10
10
|
// is the only version source that works in every runtime we ship to.
|
|
11
|
-
exports.SDK_VERSION = '2.27.
|
|
11
|
+
exports.SDK_VERSION = '2.27.3';
|