@wats/graph 0.3.1
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.js +392 -0
- package/dist/createFetchTransport.d.ts +6 -0
- package/dist/createFetchTransport.js +46 -0
- package/dist/createMockTransport.d.ts +20 -0
- package/dist/createMockTransport.js +120 -0
- package/dist/endpoint.d.ts +26 -0
- package/dist/endpoint.js +223 -0
- package/dist/endpoints/businessManagement.d.ts +157 -0
- package/dist/endpoints/businessManagement.js +277 -0
- package/dist/endpoints/calling.d.ts +65 -0
- package/dist/endpoints/calling.js +284 -0
- package/dist/endpoints/flows/callables.d.ts +90 -0
- package/dist/endpoints/flows/callables.js +97 -0
- package/dist/endpoints/flows/dataExchange.d.ts +4 -0
- package/dist/endpoints/flows/dataExchange.js +40 -0
- package/dist/endpoints/flows/flowJson.d.ts +18 -0
- package/dist/endpoints/flows/flowJson.js +214 -0
- package/dist/endpoints/flows/index.d.ts +6 -0
- package/dist/endpoints/flows/index.js +26 -0
- package/dist/endpoints/flows/shared.d.ts +17 -0
- package/dist/endpoints/flows/shared.js +113 -0
- package/dist/endpoints/flows/types.d.ts +105 -0
- package/dist/endpoints/flows/types.js +0 -0
- package/dist/endpoints/flows.d.ts +2 -0
- package/dist/endpoints/flows.js +23 -0
- package/dist/endpoints/media.d.ts +123 -0
- package/dist/endpoints/media.js +976 -0
- package/dist/endpoints/messages.d.ts +375 -0
- package/dist/endpoints/messages.js +675 -0
- package/dist/endpoints/templates/builders.d.ts +9 -0
- package/dist/endpoints/templates/builders.js +101 -0
- package/dist/endpoints/templates/callables.d.ts +54 -0
- package/dist/endpoints/templates/callables.js +98 -0
- package/dist/endpoints/templates/index.d.ts +5 -0
- package/dist/endpoints/templates/index.js +16 -0
- package/dist/endpoints/templates/shared.d.ts +21 -0
- package/dist/endpoints/templates/shared.js +203 -0
- package/dist/endpoints/templates/types.d.ts +135 -0
- package/dist/endpoints/templates/types.js +0 -0
- package/dist/endpoints/templates/validation.d.ts +2 -0
- package/dist/endpoints/templates/validation.js +113 -0
- package/dist/endpoints/templates.d.ts +2 -0
- package/dist/endpoints/templates.js +14 -0
- package/dist/endpoints/waba/index.d.ts +4 -0
- package/dist/endpoints/waba/index.js +1 -0
- package/dist/endpoints/waba/phoneNumbers.d.ts +25 -0
- package/dist/endpoints/waba/phoneNumbers.js +23 -0
- package/dist/endpoints/waba/types.d.ts +8 -0
- package/dist/endpoints/waba/types.js +0 -0
- package/dist/endpoints/wabaEndpoints.d.ts +6 -0
- package/dist/endpoints/wabaEndpoints.js +38 -0
- package/dist/errorRegistry.d.ts +45 -0
- package/dist/errorRegistry.js +68 -0
- package/dist/errorSubclasses.d.ts +277 -0
- package/dist/errorSubclasses.js +613 -0
- package/dist/errors.d.ts +92 -0
- package/dist/errors.js +250 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +48 -0
- package/dist/internal/validation/arrays.d.ts +19 -0
- package/dist/internal/validation/arrays.js +102 -0
- package/dist/internal/validation/errors.d.ts +3 -0
- package/dist/internal/validation/errors.js +13 -0
- package/dist/internal/validation/headers.d.ts +15 -0
- package/dist/internal/validation/headers.js +77 -0
- package/dist/internal/validation/index.d.ts +8 -0
- package/dist/internal/validation/index.js +8 -0
- package/dist/internal/validation/json.d.ts +10 -0
- package/dist/internal/validation/json.js +79 -0
- package/dist/internal/validation/options.d.ts +5 -0
- package/dist/internal/validation/options.js +36 -0
- package/dist/internal/validation/paths.d.ts +8 -0
- package/dist/internal/validation/paths.js +37 -0
- package/dist/internal/validation/records.d.ts +20 -0
- package/dist/internal/validation/records.js +69 -0
- package/dist/internal/validation/strings.d.ts +12 -0
- package/dist/internal/validation/strings.js +46 -0
- package/dist/pagination.d.ts +35 -0
- package/dist/pagination.js +160 -0
- package/dist/subclients/phoneNumberClient.d.ts +60 -0
- package/dist/subclients/phoneNumberClient.js +194 -0
- package/dist/subclients/wabaClient.d.ts +66 -0
- package/dist/subclients/wabaClient.js +180 -0
- package/dist/transport.d.ts +32 -0
- package/dist/transport.js +5 -0
- package/package.json +70 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { TemplateParamCountMismatchError } from "../../errorSubclasses";
|
|
2
|
+
import {
|
|
3
|
+
TEMPLATE_MAX_ARRAY,
|
|
4
|
+
TEMPLATE_MAX_COMPONENTS,
|
|
5
|
+
assertArray,
|
|
6
|
+
assertPlainRecord,
|
|
7
|
+
assertString,
|
|
8
|
+
hasControlChar,
|
|
9
|
+
isPlainObject,
|
|
10
|
+
safeJsonClone,
|
|
11
|
+
validationError
|
|
12
|
+
} from "./shared";
|
|
13
|
+
function mismatchError(message) {
|
|
14
|
+
return new TemplateParamCountMismatchError({
|
|
15
|
+
status: 400,
|
|
16
|
+
payload: { message, type: "ValidationError", code: 132000 },
|
|
17
|
+
headers: new Headers,
|
|
18
|
+
requestUrl: "wats://local/template-parameter-validation"
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function componentText(component) {
|
|
22
|
+
if (!isPlainObject(component))
|
|
23
|
+
return;
|
|
24
|
+
const safe = safeJsonClone(component, "validateTemplateParameterCounts", "definition.component");
|
|
25
|
+
if (!isPlainObject(safe))
|
|
26
|
+
return;
|
|
27
|
+
const type = typeof safe.type === "string" ? safe.type.toUpperCase() : "";
|
|
28
|
+
if (type !== "HEADER" && type !== "BODY")
|
|
29
|
+
return;
|
|
30
|
+
return typeof safe.text === "string" ? safe.text : undefined;
|
|
31
|
+
}
|
|
32
|
+
function placeholders(text, format) {
|
|
33
|
+
const found = [];
|
|
34
|
+
const rx = /\{\{\s*([^{}\s]+)\s*\}\}/g;
|
|
35
|
+
let match;
|
|
36
|
+
while ((match = rx.exec(text)) !== null) {
|
|
37
|
+
const token = match[1] ?? "";
|
|
38
|
+
if (format === "POSITIONAL" && /^\d+$/.test(token))
|
|
39
|
+
found.push(token);
|
|
40
|
+
else if (format === "NAMED" && !/^\d+$/.test(token))
|
|
41
|
+
found.push(token);
|
|
42
|
+
}
|
|
43
|
+
return Array.from(new Set(found));
|
|
44
|
+
}
|
|
45
|
+
function getComponentKind(component) {
|
|
46
|
+
if (!isPlainObject(component))
|
|
47
|
+
return;
|
|
48
|
+
const safe = safeJsonClone(component, "validateTemplateParameterCounts", "definition.component");
|
|
49
|
+
if (!isPlainObject(safe) || typeof safe.type !== "string")
|
|
50
|
+
return;
|
|
51
|
+
return safe.type.toUpperCase();
|
|
52
|
+
}
|
|
53
|
+
function getSendParameterNames(component, helperName) {
|
|
54
|
+
const safeComponent = safeJsonClone(component, helperName, "sendComponent");
|
|
55
|
+
if (!isPlainObject(safeComponent)) {
|
|
56
|
+
throw validationError(`Invalid ${helperName} input: sendComponent must be an object.`);
|
|
57
|
+
}
|
|
58
|
+
const params = safeComponent.parameters;
|
|
59
|
+
if (params === undefined)
|
|
60
|
+
return [];
|
|
61
|
+
const arr = assertArray(params, "component.parameters", 0, TEMPLATE_MAX_ARRAY, helperName);
|
|
62
|
+
const names = [];
|
|
63
|
+
for (let index = 0;index < arr.length; index += 1) {
|
|
64
|
+
const entry = arr[index];
|
|
65
|
+
if (!isPlainObject(entry))
|
|
66
|
+
continue;
|
|
67
|
+
const value = entry.parameter_name;
|
|
68
|
+
if (value === undefined)
|
|
69
|
+
continue;
|
|
70
|
+
if (typeof value !== "string" || value.length === 0 || hasControlChar(value)) {
|
|
71
|
+
throw validationError(`Invalid ${helperName} input: component.parameters[${index}].parameter_name must be a safe string.`);
|
|
72
|
+
}
|
|
73
|
+
names.push(value);
|
|
74
|
+
}
|
|
75
|
+
return names;
|
|
76
|
+
}
|
|
77
|
+
export function validateTemplateParameterCounts(definition, sendComponents) {
|
|
78
|
+
const helperName = "validateTemplateParameterCounts";
|
|
79
|
+
const defRecord = assertPlainRecord(definition, "validateTemplateParameterCounts", "definition");
|
|
80
|
+
const formatRaw = defRecord.parameterFormat ?? defRecord.parameter_format ?? "POSITIONAL";
|
|
81
|
+
const format = assertString(formatRaw, "parameterFormat", "validateTemplateParameterCounts", 32).toUpperCase();
|
|
82
|
+
if (format !== "POSITIONAL" && format !== "NAMED")
|
|
83
|
+
throw validationError("Invalid validateTemplateParameterCounts input: parameterFormat must be POSITIONAL or NAMED.");
|
|
84
|
+
const defComponents = assertArray(defRecord.components, "definition.components", 0, TEMPLATE_MAX_COMPONENTS, "validateTemplateParameterCounts");
|
|
85
|
+
const sendArr = assertArray(sendComponents, "sendComponents", 0, TEMPLATE_MAX_COMPONENTS, "validateTemplateParameterCounts");
|
|
86
|
+
const byType = new Map;
|
|
87
|
+
for (const entry of sendArr) {
|
|
88
|
+
const safeEntry = safeJsonClone(entry, "validateTemplateParameterCounts", "sendComponent");
|
|
89
|
+
const rec = assertPlainRecord(safeEntry, "validateTemplateParameterCounts", "sendComponent");
|
|
90
|
+
const kind = assertString(rec.type, "sendComponent.type", "validateTemplateParameterCounts", 32).toUpperCase();
|
|
91
|
+
if (kind === "HEADER" || kind === "BODY")
|
|
92
|
+
byType.set(kind, rec);
|
|
93
|
+
}
|
|
94
|
+
for (const defComponent of defComponents) {
|
|
95
|
+
const kind = getComponentKind(defComponent);
|
|
96
|
+
const text = componentText(defComponent);
|
|
97
|
+
if (kind !== "HEADER" && kind !== "BODY" || text === undefined)
|
|
98
|
+
continue;
|
|
99
|
+
const expectedTokens = placeholders(text, format);
|
|
100
|
+
const sendComponent = byType.get(kind);
|
|
101
|
+
const actual = sendComponent?.parameters === undefined ? [] : assertArray(sendComponent.parameters, "component.parameters", 0, TEMPLATE_MAX_ARRAY, "validateTemplateParameterCounts");
|
|
102
|
+
if (format === "NAMED") {
|
|
103
|
+
const names = getSendParameterNames(sendComponent ?? { type: kind, parameters: [] }, "validateTemplateParameterCounts");
|
|
104
|
+
const missing = expectedTokens.filter((token) => !names.includes(token));
|
|
105
|
+
const extra = names.filter((name) => !expectedTokens.includes(name));
|
|
106
|
+
if (missing.length > 0 || extra.length > 0 || names.length !== expectedTokens.length) {
|
|
107
|
+
throw mismatchError(`Template ${kind} named parameters mismatch: expected [${expectedTokens.join(",")}] got [${names.join(",")}].`);
|
|
108
|
+
}
|
|
109
|
+
} else if (actual.length !== expectedTokens.length) {
|
|
110
|
+
throw mismatchError(`Template ${kind} parameter count mismatch: expected ${expectedTokens.length}, got ${actual.length}.`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { buildCreateMessageTemplateBody, buildUpdateMessageTemplateBody, buildTemplateBodyComponent, buildTemplateButtonComponent, buildTemplateFooterComponent, buildTemplateHeaderComponent, createMessageTemplate, deleteMessageTemplate, getMessageTemplate, listMessageTemplates, updateMessageTemplate, validateTemplateParameterCounts } from "./templates/index";
|
|
2
|
+
export type { CreateMessageTemplateBody, DeleteMessageTemplateInput, GetMessageTemplateInput, GraphPaging, ListMessageTemplatesInput, SendTemplateComponentForValidation, TemplateBodyComponentInput, TemplateButtonInput, TemplateButtonsComponentInput, TemplateButtonType, TemplateCategory, TemplateComponent, TemplateDefinitionForValidation, TemplateDetails, TemplateFooterComponentInput, TemplateHeaderComponentInput, TemplateHeaderFormat, TemplateLanguageCode, TemplateListResponse, TemplateMutationResponse, TemplateParameterFormat, TemplateQualityScore, TemplateStatus, UpdateMessageTemplateBody } from "./templates/index";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export {
|
|
2
|
+
buildCreateMessageTemplateBody,
|
|
3
|
+
buildUpdateMessageTemplateBody,
|
|
4
|
+
buildTemplateBodyComponent,
|
|
5
|
+
buildTemplateButtonComponent,
|
|
6
|
+
buildTemplateFooterComponent,
|
|
7
|
+
buildTemplateHeaderComponent,
|
|
8
|
+
createMessageTemplate,
|
|
9
|
+
deleteMessageTemplate,
|
|
10
|
+
getMessageTemplate,
|
|
11
|
+
listMessageTemplates,
|
|
12
|
+
updateMessageTemplate,
|
|
13
|
+
validateTemplateParameterCounts
|
|
14
|
+
} from "./templates/index";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { listPhoneNumbers } from "./phoneNumbers";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { EndpointInvokeOptions } from "../../endpoint";
|
|
2
|
+
import { type ListPhoneNumbersInput } from "../businessManagement";
|
|
3
|
+
import type { GraphPaging } from "./types";
|
|
4
|
+
export interface PhoneNumberListEntry {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly display_phone_number?: string;
|
|
7
|
+
readonly verified_name?: string;
|
|
8
|
+
readonly quality_rating?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PhoneNumberListResponse {
|
|
11
|
+
readonly data?: readonly PhoneNumberListEntry[];
|
|
12
|
+
readonly paging?: GraphPaging;
|
|
13
|
+
}
|
|
14
|
+
declare const listPhoneNumbersRaw: import("../..").EndpointCallable<{
|
|
15
|
+
wabaId: string;
|
|
16
|
+
fields?: string;
|
|
17
|
+
limit?: string;
|
|
18
|
+
after?: string;
|
|
19
|
+
before?: string;
|
|
20
|
+
}, never, PhoneNumberListResponse>;
|
|
21
|
+
export declare const listPhoneNumbers: {
|
|
22
|
+
(client: Parameters<typeof listPhoneNumbersRaw>[0], params: ListPhoneNumbersInput, body?: never, opts?: EndpointInvokeOptions): Promise<PhoneNumberListResponse>;
|
|
23
|
+
readonly definition: typeof listPhoneNumbersRaw.definition;
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineEndpoint } from "../../endpoint";
|
|
2
|
+
import { GraphRequestValidationError } from "../../errors";
|
|
3
|
+
import {
|
|
4
|
+
normalizeListPhoneNumbersParams,
|
|
5
|
+
sanitizeBusinessManagementOptions
|
|
6
|
+
} from "../businessManagement";
|
|
7
|
+
const listPhoneNumbersRaw = defineEndpoint({
|
|
8
|
+
method: "GET",
|
|
9
|
+
pathTemplate: "/{wabaId}/phone_numbers",
|
|
10
|
+
params: {
|
|
11
|
+
wabaId: { in: "path", required: true },
|
|
12
|
+
fields: { in: "query" },
|
|
13
|
+
limit: { in: "query" },
|
|
14
|
+
after: { in: "query" },
|
|
15
|
+
before: { in: "query" }
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
export const listPhoneNumbers = Object.assign(async function listPhoneNumbers(client, params, body, opts) {
|
|
19
|
+
if (body !== undefined) {
|
|
20
|
+
throw new GraphRequestValidationError("Invalid listPhoneNumbers input: GET endpoints do not accept a body.");
|
|
21
|
+
}
|
|
22
|
+
return listPhoneNumbersRaw(client, normalizeListPhoneNumbersParams(params), undefined, sanitizeBusinessManagementOptions(opts, "listPhoneNumbers"));
|
|
23
|
+
}, { definition: listPhoneNumbersRaw.definition });
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { listPhoneNumbers } from "./waba/index";
|
|
2
|
+
export type { GraphPaging, PhoneNumberListEntry, PhoneNumberListResponse } from "./waba/index";
|
|
3
|
+
export { buildCreateMessageTemplateBody, buildUpdateMessageTemplateBody, buildTemplateBodyComponent, buildTemplateButtonComponent, buildTemplateFooterComponent, buildTemplateHeaderComponent, createMessageTemplate, deleteMessageTemplate, getMessageTemplate, listMessageTemplates, updateMessageTemplate, validateTemplateParameterCounts } from "./templates/index";
|
|
4
|
+
export type { CreateMessageTemplateBody, DeleteMessageTemplateInput, GetMessageTemplateInput, ListMessageTemplatesInput, SendTemplateComponentForValidation, TemplateBodyComponentInput, TemplateButtonInput, TemplateButtonsComponentInput, TemplateButtonType, TemplateCategory, TemplateComponent, TemplateDefinitionForValidation, TemplateDetails, TemplateFooterComponentInput, TemplateHeaderComponentInput, TemplateHeaderFormat, TemplateLanguageCode, TemplateListResponse, TemplateMutationResponse, TemplateParameterFormat, TemplateQualityScore, TemplateStatus, UpdateMessageTemplateBody } from "./templates/index";
|
|
5
|
+
export { FLOW_JSON_MAX_ARRAY_LENGTH, FLOW_JSON_MAX_BYTES, FLOW_JSON_MAX_COMPONENTS, FLOW_JSON_MAX_DEPTH, FLOW_JSON_MAX_SCREENS, FLOW_JSON_MAX_STRING_LENGTH, FLOW_MAX_CATEGORIES, buildFlowCloseResponse, buildFlowErrorResponse, buildFlowJson, buildFlowScreenResponse, createFlow, deleteFlow, deprecateFlow, getFlow, getFlowAssets, listFlows, publishFlow, updateFlowJson, updateFlowMetadata, validateFlowJson } from "./flows/index";
|
|
6
|
+
export type { CreateFlowBody, FlowAssetDetails, FlowAssetsResponse, FlowCategory, FlowCloseResponse, FlowCloseResponseInput, FlowDetails, FlowErrorResponse, FlowErrorResponseInput, FlowJson, FlowListResponse, FlowMutationResponse, FlowScreenResponse, FlowScreenResponseInput, FlowStatus, GetFlowAssetsInput, GetFlowInput, ListFlowsInput, UpdateFlowJsonBody, UpdateFlowMetadataBody } from "./flows/index";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export { listPhoneNumbers } from "./waba/index";
|
|
2
|
+
export {
|
|
3
|
+
buildCreateMessageTemplateBody,
|
|
4
|
+
buildUpdateMessageTemplateBody,
|
|
5
|
+
buildTemplateBodyComponent,
|
|
6
|
+
buildTemplateButtonComponent,
|
|
7
|
+
buildTemplateFooterComponent,
|
|
8
|
+
buildTemplateHeaderComponent,
|
|
9
|
+
createMessageTemplate,
|
|
10
|
+
deleteMessageTemplate,
|
|
11
|
+
getMessageTemplate,
|
|
12
|
+
listMessageTemplates,
|
|
13
|
+
updateMessageTemplate,
|
|
14
|
+
validateTemplateParameterCounts
|
|
15
|
+
} from "./templates/index";
|
|
16
|
+
export {
|
|
17
|
+
FLOW_JSON_MAX_ARRAY_LENGTH,
|
|
18
|
+
FLOW_JSON_MAX_BYTES,
|
|
19
|
+
FLOW_JSON_MAX_COMPONENTS,
|
|
20
|
+
FLOW_JSON_MAX_DEPTH,
|
|
21
|
+
FLOW_JSON_MAX_SCREENS,
|
|
22
|
+
FLOW_JSON_MAX_STRING_LENGTH,
|
|
23
|
+
FLOW_MAX_CATEGORIES,
|
|
24
|
+
buildFlowCloseResponse,
|
|
25
|
+
buildFlowErrorResponse,
|
|
26
|
+
buildFlowJson,
|
|
27
|
+
buildFlowScreenResponse,
|
|
28
|
+
createFlow,
|
|
29
|
+
deleteFlow,
|
|
30
|
+
deprecateFlow,
|
|
31
|
+
getFlow,
|
|
32
|
+
getFlowAssets,
|
|
33
|
+
listFlows,
|
|
34
|
+
publishFlow,
|
|
35
|
+
updateFlowJson,
|
|
36
|
+
updateFlowMetadata,
|
|
37
|
+
validateFlowJson
|
|
38
|
+
} from "./flows/index";
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { GraphApiError, GraphApiErrorPayload } from "./errors";
|
|
2
|
+
export interface GraphErrorFactoryContext {
|
|
3
|
+
readonly payload: GraphApiErrorPayload | undefined;
|
|
4
|
+
readonly status: number;
|
|
5
|
+
readonly headers: Headers;
|
|
6
|
+
readonly requestUrl: string;
|
|
7
|
+
}
|
|
8
|
+
export interface GraphErrorRegistryEntry {
|
|
9
|
+
readonly code: number;
|
|
10
|
+
readonly subcode?: number;
|
|
11
|
+
readonly errorName: string;
|
|
12
|
+
readonly factory: (context: GraphErrorFactoryContext) => GraphApiError;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Register (or replace) an entry for (code, subcode?). Last-writer-wins:
|
|
16
|
+
* re-registering the same (code, subcode?) key replaces the prior entry.
|
|
17
|
+
* This is intentional so consumers can layer overrides on top of the
|
|
18
|
+
* built-in seeds without an explicit deregister step.
|
|
19
|
+
*/
|
|
20
|
+
export declare function registerErrorCode(entry: GraphErrorRegistryEntry): void;
|
|
21
|
+
/**
|
|
22
|
+
* Reset the registry. Also clears the built-in-seeding guard so a
|
|
23
|
+
* subsequent `registerBuiltInErrorCodes()` call re-seeds cleanly. This
|
|
24
|
+
* is the ONLY public reset hook — the previous `clearErrorRegistryForTesting()`
|
|
25
|
+
* has been removed; this function is now both the public entry point
|
|
26
|
+
* AND the test-only re-seed hook.
|
|
27
|
+
*/
|
|
28
|
+
export declare function clearErrorRegistry(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the narrowest registered entry for (code, subcode).
|
|
31
|
+
* Order:
|
|
32
|
+
* 1. exact `(code, subcode)` when subcode provided;
|
|
33
|
+
* 2. fall back to `(code, undefined)`;
|
|
34
|
+
* 3. undefined when no entry matches.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveRegisteredError(code: number, subcode: number | undefined): GraphErrorRegistryEntry | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Read-only view of every currently registered entry. Primarily for
|
|
39
|
+
* diagnostics and docs generation.
|
|
40
|
+
*/
|
|
41
|
+
export declare function listRegisteredErrors(): readonly GraphErrorRegistryEntry[];
|
|
42
|
+
/** @internal — used by errorSubclasses' top-level seeding block. */
|
|
43
|
+
export declare function isBuiltInRegistered(): boolean;
|
|
44
|
+
/** @internal — set by errorSubclasses after seeding completes. */
|
|
45
|
+
export declare function markBuiltInRegistered(): void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const entries = new Map;
|
|
2
|
+
let builtInRegistered = false;
|
|
3
|
+
function keyFor(code, subcode) {
|
|
4
|
+
return subcode === undefined ? `${code}:` : `${code}:${subcode}`;
|
|
5
|
+
}
|
|
6
|
+
function validateEntry(entry) {
|
|
7
|
+
if (typeof entry !== "object" || entry === null) {
|
|
8
|
+
throw new TypeError("registerErrorCode: entry must be an object");
|
|
9
|
+
}
|
|
10
|
+
if (typeof entry.code !== "number") {
|
|
11
|
+
throw new TypeError("registerErrorCode: entry.code must be a number");
|
|
12
|
+
}
|
|
13
|
+
if (!Number.isFinite(entry.code)) {
|
|
14
|
+
throw new RangeError("registerErrorCode: entry.code must be a finite number");
|
|
15
|
+
}
|
|
16
|
+
if (!Number.isInteger(entry.code)) {
|
|
17
|
+
throw new RangeError("registerErrorCode: entry.code must be an integer");
|
|
18
|
+
}
|
|
19
|
+
if (entry.code < 0) {
|
|
20
|
+
throw new RangeError("registerErrorCode: entry.code must be non-negative");
|
|
21
|
+
}
|
|
22
|
+
if (entry.subcode !== undefined) {
|
|
23
|
+
if (typeof entry.subcode !== "number") {
|
|
24
|
+
throw new TypeError("registerErrorCode: entry.subcode must be a number when provided");
|
|
25
|
+
}
|
|
26
|
+
if (!Number.isFinite(entry.subcode)) {
|
|
27
|
+
throw new RangeError("registerErrorCode: entry.subcode must be a finite number");
|
|
28
|
+
}
|
|
29
|
+
if (!Number.isInteger(entry.subcode)) {
|
|
30
|
+
throw new RangeError("registerErrorCode: entry.subcode must be an integer when provided");
|
|
31
|
+
}
|
|
32
|
+
if (entry.subcode < 0) {
|
|
33
|
+
throw new RangeError("registerErrorCode: entry.subcode must be non-negative when provided");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (typeof entry.errorName !== "string" || entry.errorName.length === 0) {
|
|
37
|
+
throw new TypeError("registerErrorCode: entry.errorName must be a non-empty string");
|
|
38
|
+
}
|
|
39
|
+
if (typeof entry.factory !== "function") {
|
|
40
|
+
throw new TypeError("registerErrorCode: entry.factory must be a function");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function registerErrorCode(entry) {
|
|
44
|
+
validateEntry(entry);
|
|
45
|
+
entries.set(keyFor(entry.code, entry.subcode), entry);
|
|
46
|
+
}
|
|
47
|
+
export function clearErrorRegistry() {
|
|
48
|
+
entries.clear();
|
|
49
|
+
builtInRegistered = false;
|
|
50
|
+
}
|
|
51
|
+
export function resolveRegisteredError(code, subcode) {
|
|
52
|
+
if (subcode !== undefined) {
|
|
53
|
+
const specific = entries.get(keyFor(code, subcode));
|
|
54
|
+
if (specific !== undefined) {
|
|
55
|
+
return specific;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return entries.get(keyFor(code, undefined));
|
|
59
|
+
}
|
|
60
|
+
export function listRegisteredErrors() {
|
|
61
|
+
return Array.from(entries.values());
|
|
62
|
+
}
|
|
63
|
+
export function isBuiltInRegistered() {
|
|
64
|
+
return builtInRegistered;
|
|
65
|
+
}
|
|
66
|
+
export function markBuiltInRegistered() {
|
|
67
|
+
builtInRegistered = true;
|
|
68
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { GraphApiError, GraphAuthError, GraphRateLimitError } from "./errors";
|
|
2
|
+
import { type GraphErrorFactoryContext } from "./errorRegistry";
|
|
3
|
+
export declare class AuthException extends GraphAuthError {
|
|
4
|
+
static readonly errorCode: 0;
|
|
5
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
6
|
+
}
|
|
7
|
+
export declare class APIMethodError extends GraphAuthError {
|
|
8
|
+
static readonly errorCode: 3;
|
|
9
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
10
|
+
}
|
|
11
|
+
export declare class PermissionDeniedError extends GraphAuthError {
|
|
12
|
+
static readonly errorCode: 10;
|
|
13
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
14
|
+
}
|
|
15
|
+
export declare class ExpiredAccessTokenError extends GraphAuthError {
|
|
16
|
+
static readonly errorCode: 190;
|
|
17
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* pywa declares `APIPermission` as `__error_codes__ = range(200, 300)`.
|
|
21
|
+
* WATS registers the representative code 200 only; any of 201..299 falls
|
|
22
|
+
* through to the generic classifier and surfaces as `GraphAuthError` by
|
|
23
|
+
* HTTP status. See docs/reference/errors.md §"Ranges in pywa vs
|
|
24
|
+
* discrete registration".
|
|
25
|
+
*/
|
|
26
|
+
export declare class APIPermissionError extends GraphAuthError {
|
|
27
|
+
static readonly errorCode: 200;
|
|
28
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
29
|
+
}
|
|
30
|
+
export declare class ToManyAPICallsError extends GraphRateLimitError {
|
|
31
|
+
static readonly errorCode: 4;
|
|
32
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
33
|
+
}
|
|
34
|
+
export declare class RateLimitIssuesError extends GraphRateLimitError {
|
|
35
|
+
static readonly errorCode: 80007;
|
|
36
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
37
|
+
}
|
|
38
|
+
export declare class RateLimitHitError extends GraphRateLimitError {
|
|
39
|
+
static readonly errorCode: 130429;
|
|
40
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
41
|
+
}
|
|
42
|
+
export declare class SpamRateLimitHitError extends GraphRateLimitError {
|
|
43
|
+
static readonly errorCode: 131048;
|
|
44
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
45
|
+
}
|
|
46
|
+
export declare class TooManyMessagesError extends GraphRateLimitError {
|
|
47
|
+
static readonly errorCode: 131056;
|
|
48
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
49
|
+
}
|
|
50
|
+
export declare class TemporarilyBlockedError extends GraphApiError {
|
|
51
|
+
static readonly errorCode: 368;
|
|
52
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
53
|
+
}
|
|
54
|
+
export declare class AccountLockedError extends GraphApiError {
|
|
55
|
+
static readonly errorCode: 131031;
|
|
56
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
57
|
+
}
|
|
58
|
+
export declare class AccountRestrictedFromCountryError extends GraphApiError {
|
|
59
|
+
static readonly errorCode: 130497;
|
|
60
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
61
|
+
}
|
|
62
|
+
export declare class UserIsInExperimentGroupError extends GraphApiError {
|
|
63
|
+
static readonly errorCode: 130472;
|
|
64
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
65
|
+
}
|
|
66
|
+
export declare class MessageUndeliverableError extends GraphApiError {
|
|
67
|
+
static readonly errorCode: 131026;
|
|
68
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
69
|
+
}
|
|
70
|
+
export declare class ReEngagementMessageError extends GraphApiError {
|
|
71
|
+
static readonly errorCode: 131047;
|
|
72
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
73
|
+
}
|
|
74
|
+
export declare class UnsupportedMessageTypeError extends GraphApiError {
|
|
75
|
+
static readonly errorCode: 131051;
|
|
76
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
77
|
+
}
|
|
78
|
+
export declare class MediaDownloadError extends GraphApiError {
|
|
79
|
+
static readonly errorCode: 131052;
|
|
80
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
81
|
+
}
|
|
82
|
+
export declare class MediaUploadError extends GraphApiError {
|
|
83
|
+
static readonly errorCode: 131053;
|
|
84
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
85
|
+
}
|
|
86
|
+
export declare class RecipientNotInAllowedListError extends GraphApiError {
|
|
87
|
+
static readonly errorCode: 131030;
|
|
88
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Code 131009 is pywa's canonical `InvalidParameter`. Code 100 is a
|
|
92
|
+
* Meta-published platform-level "Invalid parameter" code that pywa does
|
|
93
|
+
* not register; WATS augments the seed with code 100 → `InvalidParameterError`
|
|
94
|
+
* for convenience (consumers expect `instanceof InvalidParameterError`
|
|
95
|
+
* on both codes).
|
|
96
|
+
*/
|
|
97
|
+
export declare class InvalidParameterError extends GraphApiError {
|
|
98
|
+
static readonly errorCode: 131009;
|
|
99
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
100
|
+
}
|
|
101
|
+
export declare class MissingRequiredParameterError extends GraphApiError {
|
|
102
|
+
static readonly errorCode: 131008;
|
|
103
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
104
|
+
}
|
|
105
|
+
export declare class TemplateParamCountMismatchError extends GraphApiError {
|
|
106
|
+
static readonly errorCode: 132000;
|
|
107
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
108
|
+
}
|
|
109
|
+
export declare class TemplateNotExistsError extends GraphApiError {
|
|
110
|
+
static readonly errorCode: 132001;
|
|
111
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
112
|
+
}
|
|
113
|
+
export declare class TemplateTextTooLongError extends GraphApiError {
|
|
114
|
+
static readonly errorCode: 132005;
|
|
115
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
116
|
+
}
|
|
117
|
+
export declare class TemplateContentPolicyViolationError extends GraphApiError {
|
|
118
|
+
static readonly errorCode: 132007;
|
|
119
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
120
|
+
}
|
|
121
|
+
export declare class TemplateParamValueInvalidError extends GraphApiError {
|
|
122
|
+
static readonly errorCode: 132008;
|
|
123
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
124
|
+
}
|
|
125
|
+
export declare class TemplateParamFormatMismatchError extends GraphApiError {
|
|
126
|
+
static readonly errorCode: 132012;
|
|
127
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
128
|
+
}
|
|
129
|
+
export declare class TemplatePausedError extends GraphApiError {
|
|
130
|
+
static readonly errorCode: 132015;
|
|
131
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
132
|
+
}
|
|
133
|
+
export declare class TemplateDisabledError extends GraphApiError {
|
|
134
|
+
static readonly errorCode: 132016;
|
|
135
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
136
|
+
}
|
|
137
|
+
export declare class FlowBlockedError extends GraphApiError {
|
|
138
|
+
static readonly errorCode: 132068;
|
|
139
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
140
|
+
}
|
|
141
|
+
export declare class FlowThrottledError extends GraphApiError {
|
|
142
|
+
static readonly errorCode: 132069;
|
|
143
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
144
|
+
}
|
|
145
|
+
export declare class GenericError extends GraphApiError {
|
|
146
|
+
static readonly errorCode: 135000;
|
|
147
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
148
|
+
}
|
|
149
|
+
export declare class UnknownError extends GraphApiError {
|
|
150
|
+
static readonly errorCode: 131000;
|
|
151
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
152
|
+
}
|
|
153
|
+
export declare class AccessDeniedError extends GraphApiError {
|
|
154
|
+
static readonly errorCode: 131005;
|
|
155
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
156
|
+
}
|
|
157
|
+
export declare class ServiceUnavailableError extends GraphApiError {
|
|
158
|
+
static readonly errorCode: 131016;
|
|
159
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
160
|
+
}
|
|
161
|
+
export declare class RecipientCannotBeSenderError extends GraphApiError {
|
|
162
|
+
static readonly errorCode: 131021;
|
|
163
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
164
|
+
}
|
|
165
|
+
/** pywa maps both 131042 and 131044 (the calling variant) to the same class. */
|
|
166
|
+
export declare class BusinessPaymentIssueError extends GraphApiError {
|
|
167
|
+
static readonly errorCode: 131042;
|
|
168
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
169
|
+
}
|
|
170
|
+
export declare class IncorrectCertificateError extends GraphApiError {
|
|
171
|
+
static readonly errorCode: 131045;
|
|
172
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
173
|
+
}
|
|
174
|
+
export declare class AccountInMaintenanceModeError extends GraphApiError {
|
|
175
|
+
static readonly errorCode: 131057;
|
|
176
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
177
|
+
}
|
|
178
|
+
export declare class UserStoppedMarketingMessagesError extends GraphApiError {
|
|
179
|
+
static readonly errorCode: 131050;
|
|
180
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
181
|
+
}
|
|
182
|
+
export declare class RecipientIdentityKeyMismatchError extends GraphApiError {
|
|
183
|
+
static readonly errorCode: 137000;
|
|
184
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
185
|
+
}
|
|
186
|
+
export declare class FlowBlockedByIntegrityError extends GraphApiError {
|
|
187
|
+
static readonly errorCode: 139000;
|
|
188
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
189
|
+
}
|
|
190
|
+
export declare class FlowUpdatingError extends GraphApiError {
|
|
191
|
+
static readonly errorCode: 139001;
|
|
192
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
193
|
+
}
|
|
194
|
+
export declare class FlowPublishingError extends GraphApiError {
|
|
195
|
+
static readonly errorCode: 139002;
|
|
196
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
197
|
+
}
|
|
198
|
+
export declare class FlowDeprecatingError extends GraphApiError {
|
|
199
|
+
static readonly errorCode: 139003;
|
|
200
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
201
|
+
}
|
|
202
|
+
export declare class FlowDeletingError extends GraphApiError {
|
|
203
|
+
static readonly errorCode: 139004;
|
|
204
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
205
|
+
}
|
|
206
|
+
export declare class BulkBlockingFailedError extends GraphApiError {
|
|
207
|
+
static readonly errorCode: 139100;
|
|
208
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
209
|
+
}
|
|
210
|
+
export declare class BlockListLimitReachedError extends GraphApiError {
|
|
211
|
+
static readonly errorCode: 139101;
|
|
212
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
213
|
+
}
|
|
214
|
+
export declare class BlockListConcurrentUpdateError extends GraphApiError {
|
|
215
|
+
static readonly errorCode: 139102;
|
|
216
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
217
|
+
}
|
|
218
|
+
export declare class BlockUserInternalError extends GraphApiError {
|
|
219
|
+
static readonly errorCode: 139103;
|
|
220
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
221
|
+
}
|
|
222
|
+
export declare class CallingNotEnabledError extends GraphApiError {
|
|
223
|
+
static readonly errorCode: 138000;
|
|
224
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
225
|
+
}
|
|
226
|
+
export declare class CallingCannotBeEnabledError extends GraphApiError {
|
|
227
|
+
static readonly errorCode: 138018;
|
|
228
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
229
|
+
}
|
|
230
|
+
export declare class ReceiverUncallableError extends GraphApiError {
|
|
231
|
+
static readonly errorCode: 138001;
|
|
232
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
233
|
+
}
|
|
234
|
+
export declare class ConcurrentCallsLimitError extends GraphApiError {
|
|
235
|
+
static readonly errorCode: 138002;
|
|
236
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
237
|
+
}
|
|
238
|
+
export declare class DuplicateCallError extends GraphApiError {
|
|
239
|
+
static readonly errorCode: 138003;
|
|
240
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
241
|
+
}
|
|
242
|
+
export declare class CallConnectionError extends GraphApiError {
|
|
243
|
+
static readonly errorCode: 138004;
|
|
244
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
245
|
+
}
|
|
246
|
+
export declare class CallRateLimitExceededError extends GraphApiError {
|
|
247
|
+
static readonly errorCode: 138005;
|
|
248
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
249
|
+
}
|
|
250
|
+
export declare class CallPermissionNotFoundError extends GraphApiError {
|
|
251
|
+
static readonly errorCode: 138006;
|
|
252
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
253
|
+
}
|
|
254
|
+
export declare class CallConnectionTimeoutError extends GraphApiError {
|
|
255
|
+
static readonly errorCode: 138007;
|
|
256
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
257
|
+
}
|
|
258
|
+
export declare class CallPermissionRequestLimitHitError extends GraphApiError {
|
|
259
|
+
static readonly errorCode: 138009;
|
|
260
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
261
|
+
}
|
|
262
|
+
export declare class BusinessInitiatedCallsLimitHitError extends GraphApiError {
|
|
263
|
+
static readonly errorCode: 138012;
|
|
264
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* pywa maps this class to two codes (138013 and 613). Note pywa places
|
|
268
|
+
* 613 under `CallingError`, NOT `ThrottlingError` — we follow pywa, so
|
|
269
|
+
* 613 no longer appears in `RATE_LIMIT_CODES`. (Historical: WATS
|
|
270
|
+
* previously seeded 613 as `CallsLimitError extends GraphRateLimitError`;
|
|
271
|
+
* that was a WATS fabrication and has been removed.)
|
|
272
|
+
*/
|
|
273
|
+
export declare class FetchCallPermissionLimitHitError extends GraphApiError {
|
|
274
|
+
static readonly errorCode: 138013;
|
|
275
|
+
constructor(ctx: GraphErrorFactoryContext);
|
|
276
|
+
}
|
|
277
|
+
export declare function registerBuiltInErrorCodes(): void;
|