quickbase-js 1.1.0-beta.6 → 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 (111) hide show
  1. package/README.md +253 -135
  2. package/dist/esm/quickbase.d.ts +5614 -2861
  3. package/dist/esm/quickbase.js +3204 -2116
  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 +3533 -2325
  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 -93
  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/examples/vanillatest.html +0 -49
  18. package/log-gen.yaml +0 -1372
  19. package/open-api/definitions/apps.ts +0 -274
  20. package/open-api/definitions/auth.ts +0 -10
  21. package/open-api/definitions/fields.ts +0 -751
  22. package/open-api/definitions/index.ts +0 -18
  23. package/open-api/definitions/records.ts +0 -269
  24. package/open-api/definitions/relationships.ts +0 -90
  25. package/open-api/definitions/reports.ts +0 -10
  26. package/open-api/definitions/tables.ts +0 -112
  27. package/open-api/fix-spec-main.ts +0 -176
  28. package/open-api/generate-unified-interface.ts +0 -170
  29. package/open-api/output/quickbase-fixed.json +0 -6760
  30. package/open-api/paths/apps.ts +0 -100
  31. package/open-api/paths/auth.ts +0 -25
  32. package/open-api/paths/fields.ts +0 -207
  33. package/open-api/paths/index.ts +0 -17
  34. package/open-api/paths/records.ts +0 -68
  35. package/open-api/paths/relationships.ts +0 -32
  36. package/open-api/paths/reports.ts +0 -34
  37. package/open-api/paths/tables.ts +0 -162
  38. package/open-api/regenerate-client.ts +0 -110
  39. package/playwright-results.txt/.last-run.json +0 -4
  40. package/playwright.config.ts +0 -37
  41. package/rollup.config.mjs +0 -114
  42. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  43. package/src/generated-unified/QuickbaseClient.ts +0 -62
  44. package/src/index.ts +0 -1
  45. package/src/quickbaseClient.ts +0 -313
  46. package/src/tokenCache.ts +0 -51
  47. package/test-artifacts/.last-run.json +0 -6
  48. package/test-esm.js +0 -1
  49. package/test-results.json +0 -2050
  50. package/test-umd.js +0 -1
  51. package/test.ts +0 -1
  52. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -189
  53. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -217
  54. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -151
  55. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -180
  56. package/tests/playwright/qb/auth/tokenPrefetch.test.ts +0 -192
  57. package/tests/playwright/qb/auth/tokenRenewal.test.ts +0 -110
  58. package/tests/playwright/qb/auth/umd.test.ts +0 -10
  59. package/tests/setup.ts +0 -51
  60. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  61. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  62. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  63. package/tests/vitest/qb/apps/getApp.test.ts +0 -40
  64. package/tests/vitest/qb/fields/createField.test.ts +0 -78
  65. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -89
  66. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  67. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -174
  68. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  69. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  70. package/tests/vitest/qb/index.ts +0 -28
  71. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  72. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  73. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  74. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  75. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  76. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  77. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  78. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  79. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  80. package/tests/vitest/unit/apps/copyApp.test.ts +0 -282
  81. package/tests/vitest/unit/apps/createApp.test.ts +0 -125
  82. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -215
  83. package/tests/vitest/unit/apps/getApp.test.ts +0 -86
  84. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -85
  85. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -95
  86. package/tests/vitest/unit/auth/retryOn401.test.ts +0 -106
  87. package/tests/vitest/unit/auth/two401s.test.ts +0 -77
  88. package/tests/vitest/unit/fields/createField.test.ts +0 -391
  89. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  90. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  91. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -147
  92. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  93. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  94. package/tests/vitest/unit/index.ts +0 -33
  95. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  96. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  97. package/tests/vitest/unit/records/upsert.test.ts +0 -218
  98. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  99. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  100. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  101. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  102. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  103. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  104. package/tests/vitest/unit/umd.test.ts +0 -8
  105. package/text.txt +0 -104
  106. package/tools/log-gen.ts +0 -175
  107. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  108. package/tsconfig.build.json +0 -17
  109. package/tsconfig.json +0 -29
  110. package/versionrc.json +0 -9
  111. 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,313 +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: "omit", // Default to "omit" for all requests
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", // Explicitly include credentials for token fetch
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
- credentials: "omit", // Explicitly set to "omit" for API calls
214
- };
215
-
216
- const selectedToken =
217
- initialTempToken || (userToken && !useTempTokens ? userToken : undefined);
218
-
219
- if (methodName === "getTempTokenDBID" && useTempTokens) {
220
- const dbid = extractDbid(params, "No dbid provided for getTempTokenDBID");
221
- const cachedToken = tokenCache.get(dbid);
222
- if (cachedToken) {
223
- return { temporaryAuthorization: cachedToken } as ReturnType<
224
- QuickbaseClient[K]
225
- >;
226
- }
227
- }
228
-
229
- let authorizationToken = selectedToken;
230
- if (useTempTokens && !authorizationToken) {
231
- const dbid = extractDbid(
232
- params,
233
- `No dbid found in params for ${methodName} to fetch temp token`
234
- );
235
- const cachedToken = tokenCache.get(dbid);
236
- authorizationToken = cachedToken || (await fetchTempToken(dbid));
237
- if (methodName === "getTempTokenDBID") {
238
- return { temporaryAuthorization: authorizationToken } as ReturnType<
239
- QuickbaseClient[K]
240
- >;
241
- }
242
- requestOptions.headers = {
243
- ...baseHeaders,
244
- Authorization: `QB-TEMP-TOKEN ${authorizationToken}`,
245
- };
246
- } else if (authorizationToken) {
247
- requestOptions.headers = {
248
- ...baseHeaders,
249
- Authorization: `QB-USER-TOKEN ${authorizationToken}`,
250
- };
251
- }
252
-
253
- try {
254
- return await methodInfo.method(requestParameters, requestOptions);
255
- } catch (error) {
256
- if (
257
- error instanceof ResponseError &&
258
- error.response.status === 401 &&
259
- retryCount < 1 &&
260
- useTempTokens
261
- ) {
262
- if (debug) {
263
- console.log(
264
- `Authorization error for ${methodName}, refreshing token:`,
265
- error.message
266
- );
267
- }
268
- const dbid = extractDbid(
269
- params,
270
- `No dbid to refresh token after authorization error`
271
- );
272
- authorizationToken = await fetchTempToken(dbid);
273
- requestOptions.headers = {
274
- ...baseHeaders,
275
- Authorization: `QB-TEMP-TOKEN ${authorizationToken}`,
276
- };
277
- if (debug) {
278
- console.log(`Retrying ${methodName} with new token`);
279
- }
280
- return invokeMethod(methodName, params, retryCount + 1);
281
- }
282
- if (error instanceof ResponseError) {
283
- let errorMessage = error.message;
284
- try {
285
- const errorBody: { message?: string } = await error.response.json();
286
- if (debug) {
287
- console.log(`Error response body for ${methodName}:`, errorBody);
288
- }
289
- errorMessage = errorBody.message || errorMessage;
290
- } catch (e) {
291
- // Silent fail on parse error
292
- }
293
- throw new Error(
294
- `API Error: ${errorMessage} (Status: ${error.response.status})`
295
- );
296
- }
297
- throw error;
298
- }
299
- }
300
-
301
- const proxy = new Proxy<QuickbaseClient>({} as QuickbaseClient, {
302
- get: (_, prop: string): ((params: any) => Promise<any>) | undefined => {
303
- if (prop in methodMap) {
304
- const methodName = prop as keyof QuickbaseClient;
305
- return (params: Parameters<QuickbaseClient[typeof methodName]>[0]) =>
306
- invokeMethod(methodName, params);
307
- }
308
- return undefined;
309
- },
310
- });
311
-
312
- return proxy;
313
- }
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);