@wats/graph 0.3.23 → 0.3.25
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.js +4 -2
- package/dist/endpoints/templates/builders.js +10 -0
- package/dist/endpoints/templates/types.d.ts +2 -0
- package/dist/errorSubclasses.js +16 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +24 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -87,14 +87,16 @@ export class GraphClient {
|
|
|
87
87
|
throw createGraphApiError({
|
|
88
88
|
status: response.status,
|
|
89
89
|
payload: parsedBody.error,
|
|
90
|
-
fallbackMessage: getFallbackErrorMessage(response.status)
|
|
90
|
+
fallbackMessage: getFallbackErrorMessage(response.status),
|
|
91
|
+
headers: response.headers
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
94
|
const fallbackPayload = this.extractFallbackGraphPayload(parsedBody);
|
|
94
95
|
const params = {
|
|
95
96
|
status: response.status,
|
|
96
97
|
fallbackMessage: getFallbackErrorMessage(response.status),
|
|
97
|
-
classify: false
|
|
98
|
+
classify: false,
|
|
99
|
+
headers: response.headers
|
|
98
100
|
};
|
|
99
101
|
if (fallbackPayload !== undefined) {
|
|
100
102
|
params.payload = fallbackPayload;
|
|
@@ -61,6 +61,12 @@ function normalizeSupportedApps(value) {
|
|
|
61
61
|
};
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
+
function assertBoolean(value, fieldName, helperName) {
|
|
65
|
+
if (typeof value !== "boolean") {
|
|
66
|
+
throw validationError(`Invalid ${helperName} input: ${fieldName} must be a boolean.`);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
64
70
|
function normalizeButton(input, index) {
|
|
65
71
|
const record = assertPlainRecord(input, "buildTemplateButtonComponent", `buttons[${index}]`);
|
|
66
72
|
const type = assertString(record.type, "button.type", "buildTemplateButtonComponent", 32).toUpperCase();
|
|
@@ -102,6 +108,10 @@ function normalizeButton(input, index) {
|
|
|
102
108
|
out.otp_type = assertString(record.otpType, "button.otpType", "buildTemplateButtonComponent", 32).toUpperCase();
|
|
103
109
|
if (record.text !== undefined)
|
|
104
110
|
out.text = assertString(record.text, "button.text", "buildTemplateButtonComponent", TEMPLATE_SHORT_TEXT_MAX_LENGTH);
|
|
111
|
+
if (record.autofillText !== undefined)
|
|
112
|
+
out.autofill_text = assertString(record.autofillText, "button.autofillText", "buildTemplateButtonComponent", TEMPLATE_SHORT_TEXT_MAX_LENGTH);
|
|
113
|
+
if (record.zeroTapTermsAccepted !== undefined)
|
|
114
|
+
out.zero_tap_terms_accepted = assertBoolean(record.zeroTapTermsAccepted, "button.zeroTapTermsAccepted", "buildTemplateButtonComponent");
|
|
105
115
|
if (out.otp_type === "ONE_TAP" || out.otp_type === "ZERO_TAP") {
|
|
106
116
|
out.supported_apps = normalizeSupportedApps(record.supportedApps);
|
|
107
117
|
} else if (record.supportedApps !== undefined) {
|
|
@@ -126,6 +126,8 @@ export type TemplateButtonInput = {
|
|
|
126
126
|
readonly type: "OTP";
|
|
127
127
|
readonly otpType: TemplateOtpType;
|
|
128
128
|
readonly text?: string;
|
|
129
|
+
readonly autofillText?: string;
|
|
130
|
+
readonly zeroTapTermsAccepted?: boolean;
|
|
129
131
|
readonly supportedApps?: readonly TemplateSupportedAppInput[];
|
|
130
132
|
readonly [key: string]: unknown;
|
|
131
133
|
};
|
package/dist/errorSubclasses.js
CHANGED
|
@@ -23,8 +23,24 @@ function coreParams(ctx, fallback) {
|
|
|
23
23
|
if (ctx.payload !== undefined) {
|
|
24
24
|
out.payload = ctx.payload;
|
|
25
25
|
}
|
|
26
|
+
const retryAfter = retryAfterFromContext(ctx);
|
|
27
|
+
if (retryAfter !== undefined) {
|
|
28
|
+
out.retryAfter = retryAfter;
|
|
29
|
+
}
|
|
26
30
|
return out;
|
|
27
31
|
}
|
|
32
|
+
function retryAfterFromContext(ctx) {
|
|
33
|
+
let raw;
|
|
34
|
+
try {
|
|
35
|
+
raw = ctx.headers.get("retry-after");
|
|
36
|
+
} catch {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (typeof raw !== "string")
|
|
40
|
+
return;
|
|
41
|
+
const trimmed = raw.trim();
|
|
42
|
+
return trimmed.length === 0 ? undefined : trimmed;
|
|
43
|
+
}
|
|
28
44
|
|
|
29
45
|
export class AuthException extends GraphAuthError {
|
|
30
46
|
static errorCode = 0;
|
package/dist/errors.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ export declare class GraphApiError extends Error {
|
|
|
17
17
|
readonly errorSubcode?: number;
|
|
18
18
|
readonly fbtraceId?: string;
|
|
19
19
|
readonly payload?: GraphApiErrorPayload;
|
|
20
|
+
/**
|
|
21
|
+
* Raw `Retry-After` response header value when Meta supplied one on a
|
|
22
|
+
* throttled request, preserved verbatim so an HTTP-facing layer can echo
|
|
23
|
+
* it back to its own caller. Only populated when the originating Graph
|
|
24
|
+
* response carried the header; otherwise undefined. WATS-130 R1.2.
|
|
25
|
+
*/
|
|
26
|
+
readonly retryAfter?: string;
|
|
20
27
|
/**
|
|
21
28
|
* Broad HTTP-status-driven classification:
|
|
22
29
|
* 4xx → "ClientError"
|
|
@@ -33,6 +40,7 @@ export declare class GraphApiError extends Error {
|
|
|
33
40
|
message: string;
|
|
34
41
|
status: number;
|
|
35
42
|
payload?: GraphApiErrorPayload;
|
|
43
|
+
retryAfter?: string;
|
|
36
44
|
});
|
|
37
45
|
}
|
|
38
46
|
export declare class GraphAuthError extends GraphApiError {
|
|
@@ -40,6 +48,7 @@ export declare class GraphAuthError extends GraphApiError {
|
|
|
40
48
|
message: string;
|
|
41
49
|
status: number;
|
|
42
50
|
payload?: GraphApiErrorPayload;
|
|
51
|
+
retryAfter?: string;
|
|
43
52
|
});
|
|
44
53
|
}
|
|
45
54
|
export declare class GraphRateLimitError extends GraphApiError {
|
|
@@ -47,6 +56,7 @@ export declare class GraphRateLimitError extends GraphApiError {
|
|
|
47
56
|
message: string;
|
|
48
57
|
status: number;
|
|
49
58
|
payload?: GraphApiErrorPayload;
|
|
59
|
+
retryAfter?: string;
|
|
50
60
|
});
|
|
51
61
|
}
|
|
52
62
|
export declare class GraphNetworkError extends Error {
|
package/dist/errors.js
CHANGED
|
@@ -5,12 +5,16 @@ export class GraphApiError extends Error {
|
|
|
5
5
|
errorSubcode;
|
|
6
6
|
fbtraceId;
|
|
7
7
|
payload;
|
|
8
|
+
retryAfter;
|
|
8
9
|
classification;
|
|
9
10
|
constructor(params) {
|
|
10
11
|
super(params.message);
|
|
11
12
|
this.name = "GraphApiError";
|
|
12
13
|
this.status = params.status;
|
|
13
14
|
this.classification = classifyStatus(params.status);
|
|
15
|
+
if (params.retryAfter !== undefined) {
|
|
16
|
+
this.retryAfter = params.retryAfter;
|
|
17
|
+
}
|
|
14
18
|
if (params.payload !== undefined) {
|
|
15
19
|
this.payload = params.payload;
|
|
16
20
|
if (params.payload.type !== undefined) {
|
|
@@ -37,6 +41,22 @@ function classifyStatus(status) {
|
|
|
37
41
|
}
|
|
38
42
|
return "Unknown";
|
|
39
43
|
}
|
|
44
|
+
function readRetryAfterHeader(headers) {
|
|
45
|
+
if (headers === undefined) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
let raw;
|
|
49
|
+
try {
|
|
50
|
+
raw = headers.get("retry-after");
|
|
51
|
+
} catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (typeof raw !== "string") {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const trimmed = raw.trim();
|
|
58
|
+
return trimmed.length === 0 ? undefined : trimmed;
|
|
59
|
+
}
|
|
40
60
|
|
|
41
61
|
export class GraphAuthError extends GraphApiError {
|
|
42
62
|
constructor(params) {
|
|
@@ -205,6 +225,7 @@ export function scrubErrorCause(err) {
|
|
|
205
225
|
export function createGraphApiError(params) {
|
|
206
226
|
const message = params.payload?.message ?? params.fallbackMessage ?? "Graph API request failed";
|
|
207
227
|
const shouldClassify = params.classify ?? true;
|
|
228
|
+
const retryAfter = readRetryAfterHeader(params.headers);
|
|
208
229
|
const ctorParams = {
|
|
209
230
|
message,
|
|
210
231
|
status: params.status
|
|
@@ -212,6 +233,9 @@ export function createGraphApiError(params) {
|
|
|
212
233
|
if (params.payload !== undefined) {
|
|
213
234
|
ctorParams.payload = params.payload;
|
|
214
235
|
}
|
|
236
|
+
if (retryAfter !== undefined) {
|
|
237
|
+
ctorParams.retryAfter = retryAfter;
|
|
238
|
+
}
|
|
215
239
|
if (!shouldClassify) {
|
|
216
240
|
return new GraphApiError(ctorParams);
|
|
217
241
|
}
|