quickbase-js 1.1.0-beta.5 → 1.1.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.
Files changed (110) hide show
  1. package/README.md +253 -135
  2. package/dist/esm/quickbase.d.ts +5614 -2861
  3. package/dist/esm/quickbase.js +3203 -2113
  4. package/dist/esm/quickbase.js.map +1 -1
  5. package/dist/esm/quickbase.min.js +1 -1
  6. package/dist/esm/quickbase.min.js.map +1 -1
  7. package/dist/umd/quickbase.umd.js +3532 -2322
  8. package/dist/umd/quickbase.umd.js.map +1 -1
  9. package/dist/umd/quickbase.umd.min.js +1 -1
  10. package/dist/umd/quickbase.umd.min.js.map +1 -1
  11. package/package.json +49 -32
  12. package/CHANGELOG.md +0 -86
  13. package/build.js +0 -186
  14. package/dist/umd/quickbase.umd.d.ts +0 -5341
  15. package/examples/react.js +0 -48
  16. package/examples/vanillajs.html +0 -47
  17. package/log-gen.yaml +0 -1301
  18. package/open-api/definitions/apps.ts +0 -274
  19. package/open-api/definitions/auth.ts +0 -10
  20. package/open-api/definitions/fields.ts +0 -751
  21. package/open-api/definitions/index.ts +0 -18
  22. package/open-api/definitions/records.ts +0 -269
  23. package/open-api/definitions/relationships.ts +0 -90
  24. package/open-api/definitions/reports.ts +0 -10
  25. package/open-api/definitions/tables.ts +0 -112
  26. package/open-api/fix-spec-main.ts +0 -176
  27. package/open-api/generate-unified-interface.ts +0 -170
  28. package/open-api/output/quickbase-fixed.json +0 -6760
  29. package/open-api/paths/apps.ts +0 -100
  30. package/open-api/paths/auth.ts +0 -25
  31. package/open-api/paths/fields.ts +0 -207
  32. package/open-api/paths/index.ts +0 -17
  33. package/open-api/paths/records.ts +0 -68
  34. package/open-api/paths/relationships.ts +0 -32
  35. package/open-api/paths/reports.ts +0 -34
  36. package/open-api/paths/tables.ts +0 -162
  37. package/open-api/regenerate-client.ts +0 -110
  38. package/playwright-results.txt/.last-run.json +0 -4
  39. package/playwright.config.ts +0 -37
  40. package/rollup.config.mjs +0 -114
  41. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  42. package/src/generated-unified/QuickbaseClient.ts +0 -62
  43. package/src/index.ts +0 -1
  44. package/src/quickbaseClient.ts +0 -311
  45. package/src/tokenCache.ts +0 -51
  46. package/test-artifacts/.last-run.json +0 -6
  47. package/test-esm.js +0 -1
  48. package/test-results.json +0 -2050
  49. package/test-umd.js +0 -1
  50. package/test.ts +0 -1
  51. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -189
  52. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -217
  53. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -151
  54. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -180
  55. package/tests/playwright/qb/auth/tokenPrefetch.test.ts +0 -192
  56. package/tests/playwright/qb/auth/tokenRenewal.test.ts +0 -110
  57. package/tests/playwright/qb/auth/umd.test.ts +0 -10
  58. package/tests/setup.ts +0 -51
  59. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  60. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  61. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  62. package/tests/vitest/qb/apps/getApp.test.ts +0 -40
  63. package/tests/vitest/qb/fields/createField.test.ts +0 -78
  64. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -89
  65. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  66. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -174
  67. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  68. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  69. package/tests/vitest/qb/index.ts +0 -28
  70. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  71. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  72. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  73. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  74. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  75. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  76. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  77. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  78. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  79. package/tests/vitest/unit/apps/copyApp.test.ts +0 -282
  80. package/tests/vitest/unit/apps/createApp.test.ts +0 -125
  81. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -215
  82. package/tests/vitest/unit/apps/getApp.test.ts +0 -86
  83. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -85
  84. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -95
  85. package/tests/vitest/unit/auth/retryOn401.test.ts +0 -106
  86. package/tests/vitest/unit/auth/two401s.test.ts +0 -77
  87. package/tests/vitest/unit/fields/createField.test.ts +0 -391
  88. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  89. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  90. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -147
  91. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  92. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  93. package/tests/vitest/unit/index.ts +0 -33
  94. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  95. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  96. package/tests/vitest/unit/records/upsert.test.ts +0 -218
  97. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  98. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  99. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  100. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  101. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  102. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  103. package/tests/vitest/unit/umd.test.ts +0 -8
  104. package/text.txt +0 -104
  105. package/tools/log-gen.ts +0 -175
  106. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  107. package/tsconfig.build.json +0 -17
  108. package/tsconfig.json +0 -29
  109. package/versionrc.json +0 -9
  110. package/vitest.config.ts +0 -27
@@ -1,62 +0,0 @@
1
- // Generated on 2025-03-12T19:20:50.952Z
2
- import { App, CopyApp200Response, CopyAppRequest, CreateApp200Response, CreateAppRequest, CreateField200Response, CreateFieldRequest, DeleteApp200Response, DeleteAppRequest, DeleteFields200Response, DeleteFieldsRequest, DeleteRecords200Response, DeleteRecordsRequest, DeleteTableResponse, Field, FieldUsage, GetRelationships200Response, GetTempTokenDBID200Response, ReportRunResponse, RunQueryRequest, RunQueryResponse, Table, UpdateTableRequest, Upsert200Response, Upsert207Response, UpsertRequest } from "../generated/models";
3
-
4
- export interface QuickbaseClient {
5
- createApp: (params: { body: CreateAppRequest }) => Promise<CreateApp200Response>;
6
- getApp: (params: { appId: string }) => Promise<App>;
7
- deleteApp: (params: { appId: string; body: DeleteAppRequest }) => Promise<DeleteApp200Response>;
8
- getAppEvents: (params: { appId: string }) => Promise<any[]>;
9
- copyApp: (params: { appId: string; body: CopyAppRequest }) => Promise<CopyApp200Response>;
10
- getAppTables: (params: { appId: string }) => Promise<Table[]>;
11
- createTable: (params: { appId: string; body: any }) => Promise<Table>;
12
- getTable: (params: { tableId: string; appId: string }) => Promise<Table>;
13
- updateTable: (params: { tableId: string; appId: string; body: UpdateTableRequest }) => Promise<Table>;
14
- deleteTable: (params: { tableId: string; appId: string }) => Promise<DeleteTableResponse>;
15
- getRelationships: (params: { tableId: string; skip?: number }) => Promise<GetRelationships200Response>;
16
- createRelationship: (params: { tableId: string; generated?: any }) => Promise<{ [key: string]: any }>;
17
- updateRelationship: (params: { tableId: string; relationshipId: any; generated?: any }) => Promise<{ [key: string]: any }>;
18
- deleteRelationship: (params: { tableId: string; relationshipId: any }) => Promise<{ [key: string]: any }>;
19
- getTableReports: (params: { tableId: string }) => Promise<any[]>;
20
- getReport: (params: { tableId: string; reportId: string }) => Promise<{ [key: string]: any }>;
21
- runReport: (params: { reportId: string; generated: any }) => Promise<ReportRunResponse[]>;
22
- getFields: (params: { tableId: string; includeFieldPerms?: boolean }) => Promise<Field[]>;
23
- createField: (params: { tableId: string; body: CreateFieldRequest }) => Promise<CreateField200Response>;
24
- deleteFields: (params: { tableId: string; body: DeleteFieldsRequest }) => Promise<DeleteFields200Response>;
25
- getField: (params: { fieldId: number; tableId: string; includeFieldPerms?: boolean }) => Promise<Field>;
26
- getFieldsUsage: (params: { tableId: string; skip?: number; top?: number }) => Promise<FieldUsage[]>;
27
- getFieldUsage: (params: { fieldId: number; tableId: string }) => Promise<FieldUsage[]>;
28
- runFormula: (params: { generated?: any }) => Promise<{ [key: string]: any }>;
29
- upsert: (params: { body: UpsertRequest }) => Promise<Upsert200Response | Upsert207Response>;
30
- deleteRecords: (params: { body: DeleteRecordsRequest }) => Promise<DeleteRecords200Response>;
31
- runQuery: (params: { body: RunQueryRequest }) => Promise<RunQueryResponse>;
32
- getTempTokenDBID: (params: { dbid: string }) => Promise<GetTempTokenDBID200Response>;
33
- exchangeSsoToken: (params: { generated?: any }) => Promise<{ [key: string]: any }>;
34
- cloneUserToken: (params: { generated?: any }) => Promise<{ [key: string]: any }>;
35
- transferUserToken: (params: { generated?: any }) => Promise<{ [key: string]: any }>;
36
- deactivateUserToken: (params: { }) => Promise<{ [key: string]: any }>;
37
- deleteUserToken: (params: { }) => Promise<{ [key: string]: any }>;
38
- downloadFile: (params: { tableId: string; recordId: number; fieldId: number; versionNumber: number }) => Promise<any>;
39
- deleteFile: (params: { tableId: string; recordId: number; fieldId: number; versionNumber: number }) => Promise<{ [key: string]: any }>;
40
- getUsers: (params: { accountId?: any; generated?: { [key: string]: any } }) => Promise<{ [key: string]: any }>;
41
- denyUsers: (params: { accountId?: any; generated?: string[] }) => Promise<{ [key: string]: any }>;
42
- denyUsersAndGroups: (params: { accountId?: any; shouldDeleteFromGroups: boolean; generated?: string[] }) => Promise<{ [key: string]: any }>;
43
- undenyUsers: (params: { accountId?: any; generated?: string[] }) => Promise<{ [key: string]: any }>;
44
- addMembersToGroup: (params: { gid: any; generated?: string[] }) => Promise<{ [key: string]: any }>;
45
- removeMembersFromGroup: (params: { gid: any; generated?: string[] }) => Promise<{ [key: string]: any }>;
46
- addManagersToGroup: (params: { gid: any; generated?: string[] }) => Promise<{ [key: string]: any }>;
47
- removeManagersFromGroup: (params: { gid: any; generated?: string[] }) => Promise<{ [key: string]: any }>;
48
- addSubgroupsToGroup: (params: { gid: any; generated?: string[] }) => Promise<{ [key: string]: any }>;
49
- removeSubgroupsFromGroup: (params: { gid: any; generated?: string[] }) => Promise<{ [key: string]: any }>;
50
- audit: (params: { generated?: any }) => Promise<{ [key: string]: any }>;
51
- platformAnalyticReads: (params: { day?: string }) => Promise<{ [key: string]: any }>;
52
- platformAnalyticEventSummaries: (params: { accountId?: any; generated?: any }) => Promise<any>;
53
- exportSolution: (params: { solutionId: string; qBLVersion?: string }) => Promise<any>;
54
- updateSolution: (params: { solutionId: string; generated?: any; xQBLErrorsAsSuccess?: boolean }) => Promise<any>;
55
- createSolution: (params: { generated?: any; xQBLErrorsAsSuccess?: boolean }) => Promise<any>;
56
- exportSolutionToRecord: (params: { solutionId: string; tableId: string; fieldId: number; xQBLErrorsAsSuccess?: boolean; qBLVersion?: string }) => Promise<any>;
57
- createSolutionFromRecord: (params: { tableId: string; fieldId: number; recordId: number; xQBLErrorsAsSuccess?: boolean }) => Promise<any>;
58
- updateSolutionToRecord: (params: { solutionId: string; tableId: string; fieldId: number; recordId: number; xQBLErrorsAsSuccess?: boolean }) => Promise<any>;
59
- changesetSolution: (params: { solutionId: string; generated?: any; xQBLErrorsAsSuccess?: boolean }) => Promise<any>;
60
- changesetSolutionFromRecord: (params: { solutionId: string; tableId: string; fieldId: number; recordId: number; xQBLErrorsAsSuccess?: boolean }) => Promise<any>;
61
- generateDocument: (params: { templateId: any; tableId: string; recordId?: any; filename: string; accept?: string; format?: string; margin?: string; unit?: string; pageSize?: string; orientation?: string; realm?: string }) => Promise<{ [key: string]: any }>;
62
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./quickbaseClient.ts";
@@ -1,311 +0,0 @@
1
- // src/quickbaseClient.ts
2
- import { QuickbaseClient as IQuickbaseClient } from "./generated-unified/QuickbaseClient.ts";
3
- import {
4
- Configuration,
5
- HTTPHeaders,
6
- ResponseError,
7
- } from "./generated/runtime.ts";
8
- import * as apis from "./generated/apis/index.ts";
9
- import { TokenCache } from "./tokenCache.ts";
10
-
11
- // Re-export all model types from generated/models
12
- export * from "./generated/models";
13
-
14
- const simplifyName = (name: string): string =>
15
- name
16
- .replace(/ById$/, "")
17
- .replace(/Api$/, "")
18
- .replace(/^(\w)/, (_, c) => c.toLowerCase());
19
-
20
- export interface QuickbaseClient extends IQuickbaseClient {}
21
-
22
- export interface QuickbaseConfig {
23
- realm: string;
24
- userToken?: string;
25
- tempToken?: string;
26
- useTempTokens?: boolean;
27
- debug?: boolean;
28
- fetchApi?: typeof fetch;
29
- }
30
-
31
- export interface TempTokenParams {
32
- appId?: string;
33
- tableId?: string;
34
- dbid?: string;
35
- }
36
-
37
- type ApiMethod<K extends keyof QuickbaseClient> = (
38
- requestParameters: Parameters<QuickbaseClient[K]>[0],
39
- initOverrides?: RequestInit
40
- ) => Promise<ReturnType<QuickbaseClient[K]>>;
41
-
42
- interface MethodInfo<K extends keyof QuickbaseClient> {
43
- api: any;
44
- method: ApiMethod<K>;
45
- paramMap: string[];
46
- }
47
-
48
- type MethodMap = { [K in keyof QuickbaseClient]: MethodInfo<K> };
49
-
50
- const getParamNames = (fn: (...args: any[]) => any): string[] =>
51
- fn
52
- .toString()
53
- .slice(fn.toString().indexOf("(") + 1, fn.toString().indexOf(")"))
54
- .split(",")
55
- .map((p) => p.trim().split("=")[0].trim())
56
- .filter((p) => p && !p.match(/^\{/) && p !== "options");
57
-
58
- const extractDbid = (
59
- params: Partial<TempTokenParams>,
60
- errorMessage: string
61
- ): string => {
62
- const dbid = params.dbid || params.tableId || params.appId;
63
- if (!dbid) {
64
- throw new Error(errorMessage);
65
- }
66
- return dbid;
67
- };
68
-
69
- export function quickbase(config: QuickbaseConfig): QuickbaseClient {
70
- const {
71
- realm,
72
- userToken,
73
- tempToken: initialTempToken,
74
- useTempTokens,
75
- fetchApi,
76
- debug,
77
- } = config;
78
- const baseUrl = `https://api.quickbase.com/v1`;
79
-
80
- const tokenCache = new TokenCache();
81
-
82
- const baseHeaders: HTTPHeaders = {
83
- "QB-Realm-Hostname": `${realm}.quickbase.com`,
84
- "Content-Type": "application/json",
85
- };
86
-
87
- if (initialTempToken) {
88
- baseHeaders["Authorization"] = `QB-TEMP-TOKEN ${initialTempToken}`;
89
- } else if (userToken && !useTempTokens) {
90
- baseHeaders["Authorization"] = `QB-USER-TOKEN ${userToken}`;
91
- }
92
-
93
- const defaultFetch: typeof fetch | undefined =
94
- typeof globalThis.window !== "undefined"
95
- ? globalThis.window.fetch.bind(globalThis.window)
96
- : undefined;
97
- const configuration = new Configuration({
98
- basePath: baseUrl,
99
- headers: { ...baseHeaders },
100
- fetchApi: fetchApi || defaultFetch,
101
- credentials: useTempTokens ? "include" : "omit",
102
- });
103
-
104
- if (!configuration.fetchApi && typeof globalThis.window === "undefined") {
105
- throw new Error(
106
- "fetchApi must be provided in non-browser environments (e.g., Node.js)"
107
- );
108
- }
109
-
110
- const apiInstances = Object.fromEntries(
111
- Object.entries(apis)
112
- .filter(([name]) => name.endsWith("Api"))
113
- .map(([name, ApiClass]) => [
114
- name.replace("Api", "").toLowerCase(),
115
- new ApiClass(configuration),
116
- ])
117
- );
118
-
119
- const methodMap = buildMethodMap();
120
-
121
- function buildMethodMap(): MethodMap {
122
- const methodMap: Partial<MethodMap> = {};
123
- const isValidMethod = (name: string) =>
124
- !name.startsWith("_") &&
125
- name !== "constructor" &&
126
- !["Middleware", "Pre", "Post", "Raw"].some((s) => name.includes(s));
127
-
128
- for (const [apiName, api] of Object.entries(apiInstances)) {
129
- Object.getOwnPropertyNames(Object.getPrototypeOf(api))
130
- .filter(
131
- (name) =>
132
- isValidMethod(name) &&
133
- typeof api[name as keyof typeof api] === "function"
134
- )
135
- .forEach((rawMethodName) => {
136
- const simplifiedName = simplifyName(
137
- rawMethodName
138
- ) as keyof QuickbaseClient;
139
- const method = api[rawMethodName as keyof typeof api];
140
- const boundMethod = method.bind(api as any) as unknown;
141
- if (typeof boundMethod === "function" && boundMethod.length <= 2) {
142
- methodMap[simplifiedName] = {
143
- api,
144
- method: boundMethod as ApiMethod<typeof simplifiedName>,
145
- paramMap: getParamNames(method),
146
- };
147
- }
148
- });
149
- }
150
- return methodMap as MethodMap;
151
- }
152
-
153
- const fetchTempToken = async (dbid: string): Promise<string> => {
154
- const effectiveFetch = fetchApi || defaultFetch;
155
- if (!effectiveFetch) {
156
- throw new Error(
157
- "No fetch implementation available for fetching temp token"
158
- );
159
- }
160
-
161
- const response = await effectiveFetch(
162
- `https://api.quickbase.com/v1/auth/temporary/${dbid}`,
163
- {
164
- method: "GET",
165
- headers: { ...baseHeaders },
166
- credentials: "include",
167
- }
168
- );
169
-
170
- if (!response.ok) {
171
- const errorBody: { message?: string } = await response.json();
172
- throw new Error(
173
- `API Error: ${errorBody.message || "Unknown error"} (Status: ${
174
- response.status
175
- })`
176
- );
177
- }
178
-
179
- const tokenResult = await response.json();
180
- const token = tokenResult.temporaryAuthorization;
181
- if (!token) {
182
- throw new Error("No temporary token returned from API");
183
- }
184
- tokenCache.set(dbid, token);
185
- if (debug) {
186
- console.log(
187
- `Fetched and cached new token for dbid: ${dbid}`,
188
- token,
189
- `Expires at: ${new Date(
190
- Date.now() + (4 * 60 + 50) * 1000
191
- ).toISOString()}`
192
- );
193
- }
194
- return token;
195
- };
196
-
197
- async function invokeMethod<K extends keyof QuickbaseClient>(
198
- methodName: K,
199
- params: Parameters<QuickbaseClient[K]>[0] & Partial<TempTokenParams>,
200
- retryCount: number = 0
201
- ): Promise<ReturnType<QuickbaseClient[K]>> {
202
- const methodInfo = methodMap[methodName];
203
- if (!methodInfo) {
204
- throw new Error(`Method ${methodName} not found`);
205
- }
206
-
207
- const requestParameters =
208
- methodInfo.paramMap.length === 1 &&
209
- methodInfo.paramMap[0] === "requestParameters"
210
- ? { requestParameters: params }
211
- : params;
212
- let requestOptions: RequestInit = {};
213
-
214
- const selectedToken =
215
- initialTempToken || (userToken && !useTempTokens ? userToken : undefined);
216
-
217
- if (methodName === "getTempTokenDBID" && useTempTokens) {
218
- const dbid = extractDbid(params, "No dbid provided for getTempTokenDBID");
219
- const cachedToken = tokenCache.get(dbid);
220
- if (cachedToken) {
221
- return { temporaryAuthorization: cachedToken } as ReturnType<
222
- QuickbaseClient[K]
223
- >;
224
- }
225
- }
226
-
227
- let authorizationToken = selectedToken;
228
- if (useTempTokens && !authorizationToken) {
229
- const dbid = extractDbid(
230
- params,
231
- `No dbid found in params for ${methodName} to fetch temp token`
232
- );
233
- const cachedToken = tokenCache.get(dbid);
234
- authorizationToken = cachedToken || (await fetchTempToken(dbid));
235
- if (methodName === "getTempTokenDBID") {
236
- return { temporaryAuthorization: authorizationToken } as ReturnType<
237
- QuickbaseClient[K]
238
- >;
239
- }
240
- requestOptions.headers = {
241
- ...baseHeaders,
242
- Authorization: `QB-TEMP-TOKEN ${authorizationToken}`,
243
- };
244
- } else if (authorizationToken) {
245
- requestOptions.headers = {
246
- ...baseHeaders,
247
- Authorization: `QB-USER-TOKEN ${authorizationToken}`,
248
- };
249
- }
250
-
251
- try {
252
- return await methodInfo.method(requestParameters, requestOptions);
253
- } catch (error) {
254
- if (
255
- error instanceof ResponseError &&
256
- error.response.status === 401 &&
257
- retryCount < 1 &&
258
- useTempTokens
259
- ) {
260
- if (debug) {
261
- console.log(
262
- `Authorization error for ${methodName}, refreshing token:`,
263
- error.message
264
- );
265
- }
266
- const dbid = extractDbid(
267
- params,
268
- `No dbid to refresh token after authorization error`
269
- );
270
- authorizationToken = await fetchTempToken(dbid);
271
- requestOptions.headers = {
272
- ...baseHeaders,
273
- Authorization: `QB-TEMP-TOKEN ${authorizationToken}`,
274
- };
275
- if (debug) {
276
- console.log(`Retrying ${methodName} with new token`);
277
- }
278
- return invokeMethod(methodName, params, retryCount + 1);
279
- }
280
- if (error instanceof ResponseError) {
281
- let errorMessage = error.message;
282
- try {
283
- const errorBody: { message?: string } = await error.response.json();
284
- if (debug) {
285
- console.log(`Error response body for ${methodName}:`, errorBody);
286
- }
287
- errorMessage = errorBody.message || errorMessage;
288
- } catch (e) {
289
- // Silent fail on parse error
290
- }
291
- throw new Error(
292
- `API Error: ${errorMessage} (Status: ${error.response.status})`
293
- );
294
- }
295
- throw error;
296
- }
297
- }
298
-
299
- const proxy = new Proxy<QuickbaseClient>({} as QuickbaseClient, {
300
- get: (_, prop: string): ((params: any) => Promise<any>) | undefined => {
301
- if (prop in methodMap) {
302
- const methodName = prop as keyof QuickbaseClient;
303
- return (params: Parameters<QuickbaseClient[typeof methodName]>[0]) =>
304
- invokeMethod(methodName, params);
305
- }
306
- return undefined;
307
- },
308
- });
309
-
310
- return proxy;
311
- }
package/src/tokenCache.ts DELETED
@@ -1,51 +0,0 @@
1
- interface CachedToken {
2
- token: string;
3
- expiresAt: number; // Timestamp in milliseconds
4
- }
5
-
6
- export class TokenCache {
7
- private cache: Map<string, CachedToken>;
8
- private readonly lifespan: number; // Token lifespan in milliseconds
9
-
10
- constructor(lifespan: number = 4 * 60 * 1000 + 50 * 1000) {
11
- // Default 4:50
12
- this.cache = new Map<string, CachedToken>();
13
- this.lifespan = lifespan;
14
- }
15
-
16
- get(dbid: string): string | undefined {
17
- const entry = this.cache.get(dbid);
18
- const now = Date.now();
19
- if (entry && entry.expiresAt > now) {
20
- return entry.token;
21
- }
22
- return undefined; // Expired or not found
23
- }
24
-
25
- // New method to get full entry
26
- getEntry(dbid: string): CachedToken | undefined {
27
- const entry = this.cache.get(dbid);
28
- const now = Date.now();
29
- if (entry && entry.expiresAt > now) {
30
- return entry;
31
- }
32
- return undefined; // Expired or not found
33
- }
34
-
35
- set(dbid: string, token: string): void {
36
- const now = Date.now();
37
- this.cache.set(dbid, {
38
- token,
39
- expiresAt: now + this.lifespan,
40
- });
41
- }
42
-
43
- dump(): [string, CachedToken][] {
44
- return Array.from(this.cache.entries());
45
- }
46
-
47
- // New method to clear the cache
48
- clear(): void {
49
- this.cache.clear();
50
- }
51
- }
@@ -1,6 +0,0 @@
1
- {
2
- "status": "failed",
3
- "failedTests": [
4
- "07fa1d68e36f7ff08da6-e567a262e6a662a8edf4"
5
- ]
6
- }
package/test-esm.js DELETED
@@ -1 +0,0 @@
1
- import { quickbase } from './dist/esm/quickbase.js'; const qb = quickbase({ realm: 'example', userToken: 'your-token' }); console.log(qb);