quickbase-js 0.1.0-beta.8 → 1.0.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 (132) hide show
  1. package/README.md +252 -126
  2. package/dist/esm/quickbase.d.ts +2725 -2689
  3. package/dist/esm/quickbase.js +1763 -3524
  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 +1762 -3706
  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 +27 -12
  12. package/CHANGELOG.md +0 -155
  13. package/build-common.js +0 -131
  14. package/build-esm.js +0 -71
  15. package/build-umd.js +0 -69
  16. package/examples/quicbase-jsCDN.html +0 -36
  17. package/examples/react.js +0 -48
  18. package/examples/vanillajs.html +0 -47
  19. package/open-api/fix-spec-main.ts +0 -97
  20. package/open-api/generate-override-report.ts +0 -214
  21. package/open-api/generate-unified-interface.ts +0 -256
  22. package/open-api/output/override-report.html +0 -11
  23. package/open-api/output/override-report.json +0 -14395
  24. package/open-api/output/quickbase-fixed.json +0 -11191
  25. package/open-api/regenerate-client.ts +0 -116
  26. package/open-api/schema/enhance-general.ts +0 -100
  27. package/open-api/schema/fix-arrays.ts +0 -69
  28. package/open-api/schema/tags/apps.ts +0 -90
  29. package/open-api/schema/tags/fields.ts +0 -471
  30. package/open-api/schema/tags/groups.ts +0 -51
  31. package/open-api/schema/tags/index.ts +0 -66
  32. package/open-api/schema/tags/records.ts +0 -115
  33. package/open-api/schema/tags/tables.ts +0 -211
  34. package/open-api/schema/tags/users.ts +0 -47
  35. package/open-api/types/spec.ts +0 -42
  36. package/open-api/utils/infer-schema.ts +0 -40
  37. package/open-api/utils/naming.ts +0 -10
  38. package/playwright.config.ts +0 -37
  39. package/rollup.config.js +0 -114
  40. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  41. package/specs/split/apps.json +0 -1315
  42. package/specs/split/auth.json +0 -191
  43. package/specs/split/fields.json +0 -3869
  44. package/specs/split/records.json +0 -754
  45. package/specs/split/reports.json +0 -619
  46. package/specs/split/tables.json +0 -1605
  47. package/src/RateLimitError.ts +0 -12
  48. package/src/ThrottleBucket.ts +0 -36
  49. package/src/generated-unified/QuickbaseClient.ts +0 -359
  50. package/src/generated-unified/missing-types-report.json +0 -3
  51. package/src/index.ts +0 -1
  52. package/src/invokeMethod.ts +0 -357
  53. package/src/quickbaseClient.ts +0 -244
  54. package/src/tokenCache.ts +0 -51
  55. package/src/utils.ts +0 -7
  56. package/test-esm.js +0 -1
  57. package/test-results.json +0 -2050
  58. package/test-umd.js +0 -1
  59. package/test.ts +0 -1
  60. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  61. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  62. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  63. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  64. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  65. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  66. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  67. package/tests/setup.ts +0 -53
  68. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  69. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  70. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  71. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  72. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  73. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  74. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -56
  75. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  76. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  77. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  78. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -174
  79. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  80. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  81. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  82. package/tests/vitest/qb/index.ts +0 -29
  83. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  84. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  85. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  86. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  87. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  88. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  89. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  90. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  91. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -277
  92. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  93. package/tests/vitest/unit/apps/copyApp.test.ts +0 -488
  94. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  95. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  96. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  97. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  98. package/tests/vitest/unit/apps/updateApp.test.ts +0 -381
  99. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -62
  100. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -95
  101. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -113
  102. package/tests/vitest/unit/auth/retryTempTokenTwo401.test.ts +0 -81
  103. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -56
  104. package/tests/vitest/unit/fields/createField.test.ts +0 -387
  105. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  106. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  107. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -166
  108. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  109. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  110. package/tests/vitest/unit/fields/updateField.test.ts +0 -280
  111. package/tests/vitest/unit/index.ts +0 -33
  112. package/tests/vitest/unit/rateLimit.test.ts +0 -189
  113. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  114. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  115. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  116. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  117. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  118. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  119. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  120. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  121. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -305
  122. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  123. package/tests/vitest/unit/tokenLifespan.test.ts +0 -138
  124. package/tests/vitest/unit/umd.test.ts +0 -8
  125. package/text.txt +0 -104
  126. package/tools/log-gen.ts +0 -235
  127. package/tools/log-gen.yaml +0 -4982
  128. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  129. package/tsconfig.build.json +0 -17
  130. package/tsconfig.json +0 -32
  131. package/versionrc.json +0 -9
  132. package/vitest.config.ts +0 -27
@@ -1,381 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import {
3
- createClient,
4
- mockFetch,
5
- QB_APP_ID,
6
- QB_REALM,
7
- QB_USER_TOKEN,
8
- } from "@tests/setup.ts";
9
- import { UpdateAppRequest, UpdateApp200Response } from "@/generated/models";
10
-
11
- describe("QuickbaseClient Unit - updateApp", () => {
12
- let client: ReturnType<typeof createClient>;
13
-
14
- beforeEach(() => {
15
- mockFetch.mockClear();
16
- });
17
-
18
- it("initializes without errors and has updateApp method", () => {
19
- client = createClient(mockFetch, { debug: true });
20
- expect(client).toBeDefined();
21
- expect(typeof client.updateApp).toBe("function");
22
- });
23
-
24
- it("updates app successfully with user token and dates as Date objects", async () => {
25
- client = createClient(mockFetch, { debug: true });
26
-
27
- const request: UpdateAppRequest = {
28
- name: "Updated Testing App",
29
- description: "Updated description",
30
- variables: [
31
- { name: "Project End Date", value: "7-16-2025" },
32
- { name: "Project Manager Email", value: "p.diaz@company.com" },
33
- ],
34
- securityProperties: {
35
- allowClone: true,
36
- allowExport: true,
37
- enableAppTokens: true,
38
- hideFromPublic: true,
39
- mustBeRealmApproved: false,
40
- useIPFilter: false,
41
- },
42
- };
43
-
44
- const mockResponse: UpdateApp200Response = {
45
- id: QB_APP_ID,
46
- name: "Updated Testing App",
47
- description: "Updated description",
48
- created: new Date("2020-03-27T18:34:12Z"),
49
- updated: new Date("2025-03-17T12:00:00Z"),
50
- dateFormat: "MM-DD-YYYY",
51
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
52
- hasEveryoneOnTheInternet: true,
53
- ancestorId: "bqhskthaq",
54
- variables: request.variables,
55
- securityProperties: request.securityProperties,
56
- memoryInfo: { estMemory: 1, estMemoryInclDependentApps: 2 },
57
- dataClassification: "Confidential",
58
- };
59
-
60
- mockFetch.mockResolvedValueOnce({
61
- ok: true,
62
- status: 200,
63
- json: () => Promise.resolve(mockResponse),
64
- });
65
-
66
- const result = await client.updateApp({ appId: QB_APP_ID, body: request });
67
-
68
- expect(result).toEqual(mockResponse);
69
- expect(mockFetch).toHaveBeenCalledWith(
70
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
71
- expect.objectContaining({
72
- method: "POST",
73
- headers: expect.objectContaining({
74
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
75
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
76
- "Content-Type": "application/json",
77
- }),
78
- body: JSON.stringify(request),
79
- credentials: "omit",
80
- })
81
- );
82
- });
83
-
84
- it("updates app successfully with temp token and dates as strings", async () => {
85
- client = createClient(mockFetch, {
86
- useTempTokens: true,
87
- debug: true,
88
- convertDates: false,
89
- });
90
-
91
- const request: UpdateAppRequest = {
92
- name: "Updated Temp App",
93
- description: "Temp token update",
94
- variables: [{ name: "Var1", value: "Value1" }],
95
- };
96
-
97
- const mockResponse = {
98
- id: QB_APP_ID,
99
- name: "Updated Temp App",
100
- description: "Temp token update",
101
- created: "2020-03-27T18:34:12Z",
102
- updated: "2025-03-17T12:00:00Z",
103
- dateFormat: "MM-DD-YYYY",
104
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
105
- hasEveryoneOnTheInternet: false,
106
- ancestorId: "bqhskthaq",
107
- variables: request.variables,
108
- securityProperties: {
109
- allowClone: false,
110
- allowExport: false,
111
- enableAppTokens: false,
112
- hideFromPublic: false,
113
- mustBeRealmApproved: true,
114
- useIPFilter: true,
115
- },
116
- memoryInfo: { estMemory: 1, estMemoryInclDependentApps: 2 },
117
- dataClassification: "None",
118
- };
119
-
120
- mockFetch
121
- .mockResolvedValueOnce({
122
- ok: true,
123
- status: 200,
124
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
125
- })
126
- .mockResolvedValueOnce({
127
- ok: true,
128
- status: 200,
129
- json: () => Promise.resolve(mockResponse),
130
- });
131
-
132
- const result = await client.updateApp({ appId: QB_APP_ID, body: request });
133
-
134
- expect(result).toEqual(mockResponse);
135
- expect(mockFetch).toHaveBeenCalledTimes(2);
136
- expect(mockFetch).toHaveBeenNthCalledWith(
137
- 1,
138
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
139
- expect.objectContaining({
140
- method: "GET",
141
- headers: expect.objectContaining({
142
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
143
- "Content-Type": "application/json",
144
- }),
145
- credentials: "include",
146
- })
147
- );
148
- expect(mockFetch).toHaveBeenNthCalledWith(
149
- 2,
150
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
151
- expect.objectContaining({
152
- method: "POST",
153
- headers: expect.objectContaining({
154
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
155
- Authorization: "QB-TEMP-TOKEN temp_token",
156
- "Content-Type": "application/json",
157
- }),
158
- body: JSON.stringify(request),
159
- credentials: "omit",
160
- })
161
- );
162
- });
163
-
164
- it("retries successfully after 401 with temp token", async () => {
165
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
166
-
167
- const request: UpdateAppRequest = {
168
- name: "Retry Update App",
169
- description: "Retry after 401",
170
- };
171
-
172
- const mockResponse: UpdateApp200Response = {
173
- id: QB_APP_ID,
174
- name: "Retry Update App",
175
- description: "Retry after 401",
176
- created: new Date("2020-03-27T18:34:12Z"),
177
- updated: new Date("2025-03-17T12:00:00Z"),
178
- dateFormat: "MM-DD-YYYY",
179
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
180
- hasEveryoneOnTheInternet: false,
181
- ancestorId: "bqhskthaq",
182
- variables: [],
183
- securityProperties: {
184
- allowClone: false,
185
- allowExport: false,
186
- enableAppTokens: false,
187
- hideFromPublic: false,
188
- mustBeRealmApproved: true,
189
- useIPFilter: true,
190
- },
191
- memoryInfo: { estMemory: 1, estMemoryInclDependentApps: 2 },
192
- dataClassification: "Confidential",
193
- };
194
-
195
- mockFetch
196
- .mockResolvedValueOnce({
197
- ok: true,
198
- status: 200,
199
- json: () =>
200
- Promise.resolve({ temporaryAuthorization: "initial_token" }),
201
- })
202
- .mockResolvedValueOnce({
203
- ok: false,
204
- status: 401,
205
- json: () => Promise.resolve({ message: "Unauthorized" }),
206
- })
207
- .mockResolvedValueOnce({
208
- ok: true,
209
- status: 200,
210
- json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
211
- })
212
- .mockResolvedValueOnce({
213
- ok: true,
214
- status: 200,
215
- json: () => Promise.resolve(mockResponse),
216
- });
217
-
218
- const consoleSpy = vi.spyOn(console, "log");
219
- const result = await client.updateApp({ appId: QB_APP_ID, body: request });
220
-
221
- expect(result).toEqual(mockResponse);
222
- expect(mockFetch).toHaveBeenCalledTimes(4);
223
- expect(mockFetch).toHaveBeenNthCalledWith(
224
- 1,
225
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
226
- expect.any(Object)
227
- );
228
- expect(mockFetch).toHaveBeenNthCalledWith(
229
- 2,
230
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
231
- expect.objectContaining({
232
- method: "POST",
233
- headers: expect.objectContaining({
234
- Authorization: "QB-TEMP-TOKEN initial_token",
235
- }),
236
- body: JSON.stringify(request),
237
- })
238
- );
239
- expect(mockFetch).toHaveBeenNthCalledWith(
240
- 3,
241
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
242
- expect.any(Object)
243
- );
244
- expect(mockFetch).toHaveBeenNthCalledWith(
245
- 4,
246
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
247
- expect.objectContaining({
248
- method: "POST",
249
- headers: expect.objectContaining({
250
- Authorization: "QB-TEMP-TOKEN new_token",
251
- }),
252
- body: JSON.stringify(request),
253
- })
254
- );
255
- expect(consoleSpy).toHaveBeenCalledWith(
256
- "Authorization error for updateApp (temp token), refreshing token:",
257
- expect.any(String)
258
- );
259
- expect(consoleSpy).toHaveBeenCalledWith(
260
- "Retrying updateApp with temp token"
261
- );
262
- consoleSpy.mockRestore();
263
- });
264
-
265
- it("handles 400 error for invalid request", async () => {
266
- client = createClient(mockFetch, { debug: true });
267
-
268
- const request: UpdateAppRequest = {
269
- name: "", // Invalid: empty name
270
- };
271
-
272
- mockFetch.mockResolvedValueOnce({
273
- ok: false,
274
- status: 400,
275
- json: () => Promise.resolve({ message: "Name is required" }),
276
- });
277
-
278
- await expect(
279
- client.updateApp({ appId: QB_APP_ID, body: request })
280
- ).rejects.toThrow("API Error: Name is required (Status: 400)");
281
-
282
- expect(mockFetch).toHaveBeenCalledWith(
283
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
284
- expect.objectContaining({
285
- method: "POST",
286
- headers: expect.objectContaining({
287
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
288
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
289
- "Content-Type": "application/json",
290
- }),
291
- body: JSON.stringify(request),
292
- credentials: "omit",
293
- })
294
- );
295
- });
296
-
297
- it("handles edge case with more than 10 variables", async () => {
298
- client = createClient(mockFetch, { debug: true });
299
-
300
- const tooManyVariables = Array(11)
301
- .fill(null)
302
- .map((_, i) => ({ name: `Var${i}`, value: `Value${i}` }));
303
- const request: UpdateAppRequest = {
304
- name: "Test App",
305
- variables: tooManyVariables,
306
- };
307
-
308
- mockFetch.mockResolvedValueOnce({
309
- ok: false,
310
- status: 400,
311
- json: () =>
312
- Promise.resolve({ message: "Maximum of 10 variables allowed" }),
313
- });
314
-
315
- await expect(
316
- client.updateApp({ appId: QB_APP_ID, body: request })
317
- ).rejects.toThrow(
318
- "API Error: Maximum of 10 variables allowed (Status: 400)"
319
- );
320
-
321
- expect(mockFetch).toHaveBeenCalledWith(
322
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
323
- expect.objectContaining({
324
- method: "POST",
325
- body: JSON.stringify(request),
326
- })
327
- );
328
- });
329
-
330
- it("handles empty variables and security properties", async () => {
331
- client = createClient(mockFetch, { debug: true });
332
-
333
- const request: UpdateAppRequest = {
334
- name: "Empty Test App",
335
- variables: [],
336
- securityProperties: {},
337
- };
338
-
339
- const mockResponse: UpdateApp200Response = {
340
- id: QB_APP_ID,
341
- name: "Empty Test App",
342
- description: "",
343
- created: new Date("2020-03-27T18:34:12Z"),
344
- updated: new Date("2025-03-17T12:00:00Z"),
345
- dateFormat: "MM-DD-YYYY",
346
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
347
- hasEveryoneOnTheInternet: true,
348
- ancestorId: "bqhskthaq",
349
- variables: [],
350
- securityProperties: {
351
- allowClone: false,
352
- allowExport: false,
353
- enableAppTokens: false,
354
- hideFromPublic: false,
355
- mustBeRealmApproved: true,
356
- useIPFilter: true,
357
- },
358
- memoryInfo: { estMemory: 1, estMemoryInclDependentApps: 2 },
359
- dataClassification: "Confidential",
360
- };
361
-
362
- mockFetch.mockResolvedValueOnce({
363
- ok: true,
364
- status: 200,
365
- json: () => Promise.resolve(mockResponse),
366
- });
367
-
368
- const result = await client.updateApp({ appId: QB_APP_ID, body: request });
369
-
370
- expect(result).toEqual(mockResponse);
371
- expect(result.variables).toEqual([]);
372
- expect(result.securityProperties).toBeDefined();
373
- expect(mockFetch).toHaveBeenCalledWith(
374
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
375
- expect.objectContaining({
376
- method: "POST",
377
- body: JSON.stringify(request),
378
- })
379
- );
380
- });
381
- });
@@ -1,62 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import {
3
- createClient,
4
- mockFetch,
5
- QB_REALM,
6
- QB_TABLE_ID_1,
7
- } from "@tests/setup.ts";
8
-
9
- describe("QuickbaseClient Unit - 401 with fetchTempToken 401", () => {
10
- let client: ReturnType<typeof createClient>;
11
-
12
- beforeEach(() => {
13
- mockFetch.mockClear();
14
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
15
- });
16
-
17
- it("fails without infinite loop when fetchTempToken returns 401 after initial 401", async () => {
18
- const mockToken = "initial_token";
19
- let callCount = 0;
20
-
21
- mockFetch.mockImplementation((url) => {
22
- callCount++;
23
- if (url.includes("auth/temporary") && callCount === 1) {
24
- return Promise.resolve({
25
- ok: true,
26
- status: 200,
27
- json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
28
- });
29
- }
30
- if (url.includes("fields") && callCount === 2) {
31
- return Promise.resolve({
32
- ok: false,
33
- status: 401,
34
- json: () => Promise.resolve({ message: "Unauthorized" }),
35
- });
36
- }
37
- if (url.includes("auth/temporary") && callCount === 3) {
38
- return Promise.resolve({
39
- ok: false,
40
- status: 401,
41
- json: () => Promise.resolve({ message: "Temp token fetch failed" }),
42
- });
43
- }
44
- return Promise.reject(new Error(`Unexpected fetch call: ${url}`));
45
- });
46
-
47
- const consoleSpy = vi.spyOn(console, "log");
48
-
49
- await expect(client.getFields({ tableId: QB_TABLE_ID_1 })).rejects.toThrow(
50
- "API Error: Temp token fetch failed (Status: 401)"
51
- );
52
-
53
- expect(mockFetch).toHaveBeenCalledTimes(3);
54
-
55
- expect(consoleSpy).toHaveBeenCalledWith(
56
- "Authorization error for getFields (temp token), refreshing token:",
57
- expect.any(String)
58
- );
59
-
60
- consoleSpy.mockRestore();
61
- });
62
- });
@@ -1,95 +0,0 @@
1
- // tests/vitest/unit/auth/getTempTokenDBID.test.ts
2
- import { describe, it, expect, beforeEach } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_REALM,
7
- QB_TABLE_ID_1,
8
- } from "@tests/setup.ts";
9
-
10
- describe("QuickbaseClient Unit - getTempTokenDBID", () => {
11
- let client: ReturnType<typeof createClient>;
12
-
13
- beforeEach(() => {
14
- mockFetch.mockClear();
15
- client = createClient(mockFetch, { useTempTokens: true, debug: false });
16
- });
17
-
18
- it("initializes without errors", () => {
19
- expect(client).toBeDefined();
20
- });
21
-
22
- it("has getTempTokenDBID method", () => {
23
- expect(typeof client.getTempTokenDBID).toBe("function");
24
- });
25
-
26
- it("fetches and caches temp token on first call", async () => {
27
- const mockToken = "b123xyz_temp_token";
28
-
29
- mockFetch.mockResolvedValueOnce({
30
- ok: true,
31
- status: 200,
32
- json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
33
- });
34
-
35
- const result = await client.getTempTokenDBID({ dbid: QB_TABLE_ID_1 });
36
- expect(result).toEqual({ temporaryAuthorization: mockToken });
37
- expect(mockFetch).toHaveBeenCalledWith(
38
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
39
- expect.objectContaining({
40
- method: "GET",
41
- headers: expect.objectContaining({
42
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
43
- "Content-Type": "application/json",
44
- }),
45
- credentials: "include",
46
- })
47
- );
48
- });
49
-
50
- it("reuses cached temp token on second call", async () => {
51
- const mockToken = "b123xyz_temp_token";
52
-
53
- mockFetch.mockResolvedValueOnce({
54
- ok: true,
55
- status: 200,
56
- json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
57
- });
58
-
59
- const firstResult = await client.getTempTokenDBID({ dbid: QB_TABLE_ID_1 });
60
- expect(firstResult).toEqual({ temporaryAuthorization: mockToken });
61
- expect(mockFetch).toHaveBeenCalledTimes(1);
62
-
63
- mockFetch.mockClear();
64
- const secondResult = await client.getTempTokenDBID({ dbid: QB_TABLE_ID_1 });
65
- expect(secondResult).toEqual({ temporaryAuthorization: mockToken });
66
- expect(mockFetch).not.toHaveBeenCalled();
67
- });
68
-
69
- it("handles API error", async () => {
70
- mockFetch.mockResolvedValueOnce({
71
- ok: false,
72
- status: 401,
73
- json: () => Promise.resolve({ message: "Unauthorized" }),
74
- });
75
-
76
- await expect(
77
- client.getTempTokenDBID({ dbid: QB_TABLE_ID_1 })
78
- ).rejects.toSatisfy((error: Error) => {
79
- expect(error).toBeInstanceOf(Error);
80
- expect(error.message).toBe("API Error: Unauthorized (Status: 401)");
81
- return true;
82
- });
83
- expect(mockFetch).toHaveBeenCalledWith(
84
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
85
- expect.objectContaining({
86
- method: "GET",
87
- headers: expect.objectContaining({
88
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
89
- "Content-Type": "application/json",
90
- }),
91
- credentials: "include",
92
- })
93
- );
94
- });
95
- });
@@ -1,113 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import {
3
- createClient,
4
- mockFetch,
5
- QB_REALM,
6
- QB_TABLE_ID_1,
7
- } from "@tests/setup.ts";
8
-
9
- describe("QuickbaseClient Unit - Temp Token Retry on 401", () => {
10
- let client: ReturnType<typeof createClient>;
11
-
12
- beforeEach(() => {
13
- mockFetch.mockClear();
14
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
15
- });
16
-
17
- it("creates a new token on 401 and retries successfully", async () => {
18
- const mockToken = "new_token_456";
19
- const mockFields = [{ id: 1, label: "Field1" }];
20
- let callCount = 0;
21
-
22
- mockFetch.mockImplementation((url) => {
23
- callCount++;
24
- if (url.includes("auth/temporary") && callCount === 1) {
25
- return Promise.resolve({
26
- ok: true,
27
- status: 200,
28
- json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
29
- });
30
- }
31
- if (url.includes("fields") && callCount === 2) {
32
- return Promise.resolve({
33
- ok: false,
34
- status: 401,
35
- json: () => Promise.resolve({ message: "Unauthorized" }),
36
- });
37
- }
38
- if (url.includes("auth/temporary") && callCount === 3) {
39
- return Promise.resolve({
40
- ok: true,
41
- status: 200,
42
- json: () =>
43
- Promise.resolve({ temporaryAuthorization: mockToken + "_retry" }),
44
- });
45
- }
46
- if (url.includes("fields") && callCount === 4) {
47
- return Promise.resolve({
48
- ok: true,
49
- status: 200,
50
- json: () => Promise.resolve(mockFields),
51
- });
52
- }
53
- return Promise.reject(new Error(`Unexpected fetch call: ${url}`));
54
- });
55
-
56
- const consoleSpy = vi.spyOn(console, "log");
57
-
58
- const result = await client.getFields({ tableId: QB_TABLE_ID_1 });
59
-
60
- expect(result).toEqual(mockFields);
61
- expect(mockFetch).toHaveBeenCalledTimes(4);
62
- expect(mockFetch).toHaveBeenNthCalledWith(
63
- 1,
64
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
65
- expect.any(Object)
66
- );
67
- expect(mockFetch).toHaveBeenNthCalledWith(
68
- 2,
69
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
70
- expect.objectContaining({
71
- headers: expect.objectContaining({
72
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
73
- }),
74
- })
75
- );
76
- expect(mockFetch).toHaveBeenNthCalledWith(
77
- 3,
78
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
79
- expect.any(Object)
80
- );
81
- expect(mockFetch).toHaveBeenNthCalledWith(
82
- 4,
83
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
84
- expect.objectContaining({
85
- headers: expect.objectContaining({
86
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
87
- }),
88
- })
89
- );
90
-
91
- const tokenLogs = consoleSpy.mock.calls.filter((call) =>
92
- call[0].includes("Fetched and cached new token")
93
- );
94
- expect(tokenLogs).toContainEqual([
95
- `Fetched and cached new token for dbid: ${QB_TABLE_ID_1}`,
96
- mockToken,
97
- ]);
98
- expect(tokenLogs).toContainEqual([
99
- `Fetched and cached new token for dbid: ${QB_TABLE_ID_1}`,
100
- mockToken + "_retry",
101
- ]);
102
-
103
- expect(consoleSpy).toHaveBeenCalledWith(
104
- "Authorization error for getFields (temp token), refreshing token:",
105
- expect.any(String)
106
- );
107
- expect(consoleSpy).toHaveBeenCalledWith(
108
- "Retrying getFields with temp token"
109
- );
110
-
111
- consoleSpy.mockRestore();
112
- });
113
- });