quickbase-js 0.1.0-beta.13 → 0.1.0-beta.14
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 +1 -1
- package/dist/esm/quickbase.d.ts +2 -1
- package/package.json +9 -4
- package/CHANGELOG.md +0 -239
- package/build-common.js +0 -131
- package/build-esm.js +0 -71
- package/build-umd.js +0 -69
- package/docs/.vitepress/cache/deps/@theme_index.js +0 -275
- package/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
- package/docs/.vitepress/cache/deps/_metadata.json +0 -40
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js +0 -12542
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js.map +0 -7
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js +0 -9719
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js.map +0 -7
- package/docs/.vitepress/cache/deps/package.json +0 -3
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4504
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -583
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
- package/docs/.vitepress/cache/deps/vue.js +0 -343
- package/docs/.vitepress/cache/deps/vue.js.map +0 -7
- package/docs/.vitepress/config.mts +0 -26
- package/docs/api-examples.md +0 -49
- package/docs/index.md +0 -59
- package/docs/markdown-examples.md +0 -85
- package/docs-data/api-docs.json +0 -4143
- package/examples/quicbase-jsCDN.html +0 -36
- package/examples/react.js +0 -48
- package/examples/vanillajs.html +0 -47
- package/index.md +0 -25
- package/open-api/fix-spec-main.ts +0 -133
- package/open-api/generate-unified-interface.ts +0 -104
- package/open-api/generateDocsJson.ts +0 -24
- package/open-api/output/quickbase-fixed.json +0 -11191
- package/open-api/post-process-generated.ts +0 -226
- package/open-api/regenerate-client.ts +0 -117
- package/open-api/schema/enhance-general.ts +0 -111
- package/open-api/schema/fix-arrays.ts +0 -68
- package/open-api/schema/tags/apps.ts +0 -90
- package/open-api/schema/tags/fields.ts +0 -471
- package/open-api/schema/tags/groups.ts +0 -51
- package/open-api/schema/tags/index.ts +0 -66
- package/open-api/schema/tags/records.ts +0 -115
- package/open-api/schema/tags/tables.ts +0 -211
- package/open-api/schema/tags/users.ts +0 -47
- package/open-api/types/spec.ts +0 -42
- package/open-api/utils/common.ts +0 -29
- package/open-api/utils/generateJsDoc.ts +0 -74
- package/open-api/utils/infer-schema.ts +0 -40
- package/open-api/utils/naming.ts +0 -10
- package/open-api/utils/sharedUtils.ts +0 -352
- package/playwright.config.ts +0 -37
- package/rollup.config.js +0 -114
- package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
- package/specs/split/apps.json +0 -1315
- package/specs/split/auth.json +0 -191
- package/specs/split/fields.json +0 -3869
- package/specs/split/records.json +0 -754
- package/specs/split/reports.json +0 -619
- package/specs/split/tables.json +0 -1605
- package/src/BurstAwareThrottleBucket.ts +0 -57
- package/src/FlowThrottleBucket.ts +0 -47
- package/src/RateLimitError.ts +0 -12
- package/src/RateThrottleBucket.ts +0 -5
- package/src/Semaphore.ts +0 -33
- package/src/authorizationStrategy.ts +0 -321
- package/src/generated-unified/QuickbaseClient.ts +0 -1135
- package/src/generated-unified/missing-types-report.json +0 -3
- package/src/index.ts +0 -1
- package/src/invokeMethod.ts +0 -290
- package/src/pagination.ts +0 -429
- package/src/quickbaseClient.ts +0 -227
- package/src/rateLimiter.ts +0 -30
- package/src/tokenCache.ts +0 -39
- package/src/utils.ts +0 -50
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
- package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
- package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
- package/tests/playwright/qb/auth/getAppWithTempTokenConcurrency.test.ts +0 -208
- package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
- package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
- package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
- package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
- package/tests/setup.ts +0 -53
- package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
- package/tests/vitest/qb/apps/createApp.test.ts +0 -64
- package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
- package/tests/vitest/qb/apps/getApp.test.ts +0 -44
- package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
- package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
- package/tests/vitest/qb/auth/mockQuickbaseServer.ts +0 -60
- package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -73
- package/tests/vitest/qb/auth/ssoTokenConcurrency.test.ts +0 -68
- package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +0 -65
- package/tests/vitest/qb/auth/userTokenConcurrency.test.ts +0 -63
- package/tests/vitest/qb/fields/createField.test.ts +0 -77
- package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
- package/tests/vitest/qb/fields/getField.test.ts +0 -85
- package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -82
- package/tests/vitest/qb/fields/getFields.test.ts +0 -232
- package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
- package/tests/vitest/qb/fields/updateField.test.ts +0 -93
- package/tests/vitest/qb/formulas/runFormula.test.ts +0 -96
- package/tests/vitest/qb/index.ts +0 -29
- package/tests/vitest/qb/quickbase-js/BurstAwareThrottleBucket.test.ts +0 -125
- package/tests/vitest/qb/quickbase-js/FlowBucket.test.ts +0 -77
- package/tests/vitest/qb/quickbase-js/paginationSkip.test.ts +0 -111
- package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
- package/tests/vitest/qb/records/runQuery.test.ts +0 -145
- package/tests/vitest/qb/records/upsert.test.ts +0 -102
- package/tests/vitest/qb/tables/createRelationship.test.ts +0 -102
- package/tests/vitest/qb/tables/createTable.test.ts +0 -55
- package/tests/vitest/qb/tables/deleteRelationship.test.ts +0 -143
- package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
- package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
- package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
- package/tests/vitest/qb/tables/getTable.test.ts +0 -26
- package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -250
- package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
- package/tests/vitest/unit/apps/copyApp.test.ts +0 -581
- package/tests/vitest/unit/apps/createApp.test.ts +0 -186
- package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
- package/tests/vitest/unit/apps/getApp.test.ts +0 -128
- package/tests/vitest/unit/apps/getAppConcurrency.test.ts +0 -151
- package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
- package/tests/vitest/unit/apps/updateApp.test.ts +0 -412
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -81
- package/tests/vitest/unit/auth/getTempToken.test.ts +0 -119
- package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -95
- package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +0 -206
- package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -66
- package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +0 -325
- package/tests/vitest/unit/auth/userTokenConcurrency.test.ts +0 -62
- package/tests/vitest/unit/fields/createField.test.ts +0 -451
- package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
- package/tests/vitest/unit/fields/getField.test.ts +0 -189
- package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -180
- package/tests/vitest/unit/fields/getFields.test.ts +0 -122
- package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
- package/tests/vitest/unit/fields/updateField.test.ts +0 -285
- package/tests/vitest/unit/formulas/runFormula.test.ts +0 -205
- package/tests/vitest/unit/index.ts +0 -34
- package/tests/vitest/unit/quickbase-js/BurstAwareThrottleBucket.test.ts +0 -108
- package/tests/vitest/unit/quickbase-js/FlowBucket.test.ts +0 -101
- package/tests/vitest/unit/quickbase-js/pagination.test.ts +0 -251
- package/tests/vitest/unit/quickbase-js/quickbaseClientHttpMethods.test.ts +0 -141
- package/tests/vitest/unit/quickbase-js/rateLimit.test.ts +0 -191
- package/tests/vitest/unit/quickbase-js/tokenLifespan.test.ts +0 -204
- package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
- package/tests/vitest/unit/records/runQuery.test.ts +0 -101
- package/tests/vitest/unit/records/upsert.test.ts +0 -234
- package/tests/vitest/unit/tables/createRelationship.test.ts +0 -212
- package/tests/vitest/unit/tables/createTable.test.ts +0 -70
- package/tests/vitest/unit/tables/deleteRelationship.test.ts +0 -97
- package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
- package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
- package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
- package/tests/vitest/unit/tables/getTable.test.ts +0 -233
- package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -307
- package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
- package/tools/log-gen.ts +0 -251
- package/tools/log-gen.yaml +0 -4829
- package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
- package/tsconfig.build.json +0 -17
- package/tsconfig.json +0 -32
- package/versionrc.json +0 -9
- package/vitest.config.ts +0 -27
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./quickbaseClient.ts";
|
package/src/invokeMethod.ts
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import { AuthorizationStrategy, extractDbid } from "./authorizationStrategy";
|
|
2
|
-
import { RateLimiter } from "./rateLimiter";
|
|
3
|
-
import { RateLimitError } from "./RateLimitError";
|
|
4
|
-
import { ResponseError } from "./generated/runtime";
|
|
5
|
-
import { QuickbaseClient } from "./quickbaseClient";
|
|
6
|
-
import { paginateRecords, isPaginatable } from "./pagination";
|
|
7
|
-
|
|
8
|
-
export type ApiMethod<K extends keyof QuickbaseClient> = (
|
|
9
|
-
requestParameters: Parameters<QuickbaseClient[K]>[0],
|
|
10
|
-
initOverrides?: RequestInit
|
|
11
|
-
) => Promise<ReturnType<QuickbaseClient[K]>>;
|
|
12
|
-
|
|
13
|
-
export interface MethodInfo<K extends keyof QuickbaseClient> {
|
|
14
|
-
api: any;
|
|
15
|
-
method: ApiMethod<K>;
|
|
16
|
-
paramMap: string[];
|
|
17
|
-
httpMethod: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Invokes a Quick Base API method with the specified parameters, handling authentication, rate limiting, and pagination.
|
|
22
|
-
* @template K - The method name keyof QuickbaseClient.
|
|
23
|
-
* @param methodName - The API method to invoke (e.g., "runQuery", "changesetSolution").
|
|
24
|
-
* @param params - Parameters for the API method, potentially including skip, top, or a body.
|
|
25
|
-
* @param methodMap - Mapping of method names to their implementation details.
|
|
26
|
-
* @param baseHeaders - Base HTTP headers for API requests.
|
|
27
|
-
* @param authStrategy - Strategy for handling authentication tokens.
|
|
28
|
-
* @param rateLimiter - Rate limiting mechanism to respect API limits.
|
|
29
|
-
* @param transformDates - Function to transform date strings in the response.
|
|
30
|
-
* @param debug - If true, logs detailed invocation information.
|
|
31
|
-
* @param convertDates - If true, converts date strings to Date objects in the response.
|
|
32
|
-
* @param autoPaginate - If true, automatically paginates multi-page responses (default: true).
|
|
33
|
-
* @param attempt - Current retry attempt (default: 0).
|
|
34
|
-
* @param maxAttempts - Maximum number of retry attempts (default: rateLimiter.maxRetries + 1).
|
|
35
|
-
* @param isPaginating - Indicates if this call is part of an ongoing pagination (default: false).
|
|
36
|
-
* @returns A promise resolving to the API method's response.
|
|
37
|
-
* @throws {Error} If the method is not found or retries are exhausted.
|
|
38
|
-
*/
|
|
39
|
-
export async function invokeMethod<K extends keyof QuickbaseClient>(
|
|
40
|
-
methodName: K,
|
|
41
|
-
params: Parameters<QuickbaseClient[K]>[0] & {
|
|
42
|
-
dbid?: string;
|
|
43
|
-
tableId?: string;
|
|
44
|
-
appId?: string;
|
|
45
|
-
startTime?: number;
|
|
46
|
-
skip?: number;
|
|
47
|
-
top?: number;
|
|
48
|
-
},
|
|
49
|
-
methodMap: { [P in keyof QuickbaseClient]: MethodInfo<P> },
|
|
50
|
-
baseHeaders: Record<string, string>,
|
|
51
|
-
authStrategy: AuthorizationStrategy,
|
|
52
|
-
rateLimiter: RateLimiter,
|
|
53
|
-
transformDates: (obj: any, convertStringsToDates: boolean) => any,
|
|
54
|
-
debug: boolean | undefined,
|
|
55
|
-
convertDates: boolean,
|
|
56
|
-
autoPaginate: boolean = true,
|
|
57
|
-
attempt: number = 0,
|
|
58
|
-
maxAttempts: number = rateLimiter.maxRetries + 1,
|
|
59
|
-
isPaginating: boolean = false
|
|
60
|
-
): Promise<ReturnType<QuickbaseClient[K]>> {
|
|
61
|
-
const methodInfo = methodMap[methodName];
|
|
62
|
-
if (!methodInfo) throw new Error(`Method ${methodName} not found`);
|
|
63
|
-
|
|
64
|
-
const hasBody = "body" in params && params.body !== undefined;
|
|
65
|
-
const body = hasBody ? params.body : undefined;
|
|
66
|
-
// Safely check for options only if body is an object
|
|
67
|
-
const options =
|
|
68
|
-
hasBody && body && typeof body === "object" && "options" in body
|
|
69
|
-
? (body as any).options
|
|
70
|
-
: undefined;
|
|
71
|
-
const adjustedParams = {
|
|
72
|
-
...params,
|
|
73
|
-
skip:
|
|
74
|
-
params.skip ?? (options && "skip" in options ? options.skip : undefined),
|
|
75
|
-
top: params.top ?? (options && "top" in options ? options.top : undefined),
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const restParams: any = hasBody
|
|
79
|
-
? Object.fromEntries(
|
|
80
|
-
Object.entries(adjustedParams).filter(
|
|
81
|
-
([key]) => key !== "body" && key !== "startTime"
|
|
82
|
-
)
|
|
83
|
-
)
|
|
84
|
-
: { ...adjustedParams, startTime: undefined };
|
|
85
|
-
const requestParameters: any = {
|
|
86
|
-
...restParams,
|
|
87
|
-
...(hasBody ? { generated: body } : {}),
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
if (debug)
|
|
91
|
-
console.log(
|
|
92
|
-
"[invokeMethod] Adjusted params for pagination:",
|
|
93
|
-
adjustedParams
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
const requestOptions: RequestInit = {
|
|
97
|
-
credentials: methodName === "getTempTokenDBID" ? "include" : "omit",
|
|
98
|
-
method: methodInfo.httpMethod,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
let dbid: string | undefined = extractDbid(params);
|
|
102
|
-
let token = dbid
|
|
103
|
-
? await authStrategy.getToken(dbid)
|
|
104
|
-
: await authStrategy.getToken("");
|
|
105
|
-
|
|
106
|
-
if (token) {
|
|
107
|
-
authStrategy.applyHeaders(baseHeaders, token);
|
|
108
|
-
requestOptions.headers = { ...baseHeaders };
|
|
109
|
-
if (methodName === "getTempTokenDBID") {
|
|
110
|
-
return { temporaryAuthorization: token } as ReturnType<
|
|
111
|
-
QuickbaseClient[K]
|
|
112
|
-
>;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async function processResponse(
|
|
117
|
-
rawResponse: any
|
|
118
|
-
): Promise<ReturnType<QuickbaseClient[K]>> {
|
|
119
|
-
if (rawResponse instanceof Response) {
|
|
120
|
-
const contentType = rawResponse.headers
|
|
121
|
-
.get("Content-Type")
|
|
122
|
-
?.toLowerCase();
|
|
123
|
-
if (contentType?.includes("application/json")) {
|
|
124
|
-
const jsonResponse = await rawResponse.json();
|
|
125
|
-
if (autoPaginate && !isPaginating && isPaginatable(jsonResponse)) {
|
|
126
|
-
if (debug)
|
|
127
|
-
console.log(
|
|
128
|
-
"[invokeMethod] Entering pagination with params:",
|
|
129
|
-
adjustedParams
|
|
130
|
-
);
|
|
131
|
-
return paginateRecords(
|
|
132
|
-
methodName,
|
|
133
|
-
adjustedParams,
|
|
134
|
-
methodMap,
|
|
135
|
-
baseHeaders,
|
|
136
|
-
authStrategy,
|
|
137
|
-
rateLimiter,
|
|
138
|
-
transformDates,
|
|
139
|
-
debug,
|
|
140
|
-
convertDates,
|
|
141
|
-
jsonResponse
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
return transformDates(jsonResponse, convertDates) as ReturnType<
|
|
145
|
-
QuickbaseClient[K]
|
|
146
|
-
>;
|
|
147
|
-
}
|
|
148
|
-
return rawResponse as ReturnType<QuickbaseClient[K]>;
|
|
149
|
-
}
|
|
150
|
-
if (rawResponse && typeof rawResponse.value === "function") {
|
|
151
|
-
const response = await rawResponse.value();
|
|
152
|
-
if (autoPaginate && !isPaginating && isPaginatable(response)) {
|
|
153
|
-
if (debug)
|
|
154
|
-
console.log(
|
|
155
|
-
"[invokeMethod] Entering pagination with params:",
|
|
156
|
-
adjustedParams
|
|
157
|
-
);
|
|
158
|
-
return paginateRecords(
|
|
159
|
-
methodName,
|
|
160
|
-
adjustedParams,
|
|
161
|
-
methodMap,
|
|
162
|
-
baseHeaders,
|
|
163
|
-
authStrategy,
|
|
164
|
-
rateLimiter,
|
|
165
|
-
transformDates,
|
|
166
|
-
debug,
|
|
167
|
-
convertDates,
|
|
168
|
-
response
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
return transformDates(response, convertDates) as ReturnType<
|
|
172
|
-
QuickbaseClient[K]
|
|
173
|
-
>;
|
|
174
|
-
}
|
|
175
|
-
return transformDates(rawResponse, convertDates) as ReturnType<
|
|
176
|
-
QuickbaseClient[K]
|
|
177
|
-
>;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async function parseErrorResponse(
|
|
181
|
-
response: Response
|
|
182
|
-
): Promise<{ message: string; status: number }> {
|
|
183
|
-
let message = "Unknown error";
|
|
184
|
-
let status = response.status || 500;
|
|
185
|
-
try {
|
|
186
|
-
const contentType =
|
|
187
|
-
response.headers?.get("Content-Type")?.toLowerCase() ||
|
|
188
|
-
"application/json";
|
|
189
|
-
if (
|
|
190
|
-
contentType.includes("application/json") &&
|
|
191
|
-
typeof response.json === "function"
|
|
192
|
-
) {
|
|
193
|
-
const errorBody = await response.json();
|
|
194
|
-
if (
|
|
195
|
-
errorBody &&
|
|
196
|
-
typeof errorBody === "object" &&
|
|
197
|
-
"message" in errorBody
|
|
198
|
-
) {
|
|
199
|
-
message = errorBody.message;
|
|
200
|
-
} else {
|
|
201
|
-
message = "Invalid error response format";
|
|
202
|
-
}
|
|
203
|
-
} else if (typeof response.text === "function") {
|
|
204
|
-
message = (await response.text()) || message;
|
|
205
|
-
}
|
|
206
|
-
} catch (e) {
|
|
207
|
-
message = "Failed to parse error response";
|
|
208
|
-
}
|
|
209
|
-
return { message, status };
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
while (attempt < maxAttempts) {
|
|
213
|
-
let acquired = false;
|
|
214
|
-
try {
|
|
215
|
-
await rateLimiter.throttle();
|
|
216
|
-
acquired = true;
|
|
217
|
-
const postThrottleTime = Date.now();
|
|
218
|
-
if (params.startTime !== undefined) params.startTime = postThrottleTime;
|
|
219
|
-
const headers = { ...baseHeaders };
|
|
220
|
-
const finalRequest = { ...requestParameters, headers };
|
|
221
|
-
if (debug) console.log("[invokeMethod] Sending request:", finalRequest);
|
|
222
|
-
const responsePromise = methodInfo.method(finalRequest, {
|
|
223
|
-
...requestOptions,
|
|
224
|
-
headers,
|
|
225
|
-
});
|
|
226
|
-
rateLimiter.release();
|
|
227
|
-
const response = await responsePromise;
|
|
228
|
-
return await processResponse(response);
|
|
229
|
-
} catch (error: unknown) {
|
|
230
|
-
if (acquired) rateLimiter.release();
|
|
231
|
-
let status: number;
|
|
232
|
-
let message: string;
|
|
233
|
-
let response: Response | undefined;
|
|
234
|
-
|
|
235
|
-
if (error instanceof ResponseError && error.response) {
|
|
236
|
-
response = error.response;
|
|
237
|
-
({ message, status } = await parseErrorResponse(response));
|
|
238
|
-
} else if (error instanceof Response) {
|
|
239
|
-
response = error;
|
|
240
|
-
({ message, status } = await parseErrorResponse(response));
|
|
241
|
-
} else {
|
|
242
|
-
throw error;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (status === 429) {
|
|
246
|
-
if (!(error instanceof ResponseError)) {
|
|
247
|
-
throw new Error("Expected ResponseError for 429 handling");
|
|
248
|
-
}
|
|
249
|
-
const delay = await rateLimiter.handle429(error, attempt + 1);
|
|
250
|
-
if (attempt + 1 === maxAttempts) {
|
|
251
|
-
throw new RateLimitError(
|
|
252
|
-
`API Error: ${message} (Status: ${status})`,
|
|
253
|
-
status,
|
|
254
|
-
response?.headers.get("Retry-After")
|
|
255
|
-
? parseInt(response.headers.get("Retry-After")!, 10)
|
|
256
|
-
: undefined
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
260
|
-
attempt++;
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
let newToken: string | null;
|
|
265
|
-
try {
|
|
266
|
-
newToken = await authStrategy.handleError(
|
|
267
|
-
status,
|
|
268
|
-
params,
|
|
269
|
-
attempt,
|
|
270
|
-
maxAttempts,
|
|
271
|
-
debug,
|
|
272
|
-
methodName
|
|
273
|
-
);
|
|
274
|
-
} catch (authError) {
|
|
275
|
-
throw authError;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (newToken !== null) {
|
|
279
|
-
token = newToken;
|
|
280
|
-
authStrategy.applyHeaders(baseHeaders, token);
|
|
281
|
-
requestOptions.headers = { ...baseHeaders };
|
|
282
|
-
attempt++;
|
|
283
|
-
continue;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
throw new Error(`API Error: ${message} (Status: ${status})`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
throw new Error(`API Error: Exhausted retries after ${maxAttempts} attempts`);
|
|
290
|
-
}
|