quickbase-js 0.1.0-beta.9 → 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 (146) hide show
  1. package/README.md +270 -60
  2. package/dist/esm/quickbase.d.ts +2553 -3220
  3. package/dist/esm/quickbase.js +1545 -3443
  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 +1544 -3625
  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 +25 -12
  12. package/CHANGELOG.md +0 -184
  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 -336
  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/generateJsDoc.ts +0 -96
  37. package/open-api/utils/infer-schema.ts +0 -40
  38. package/open-api/utils/naming.ts +0 -10
  39. package/playwright.config.ts +0 -37
  40. package/rollup.config.js +0 -114
  41. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  42. package/specs/split/apps.json +0 -1315
  43. package/specs/split/auth.json +0 -191
  44. package/specs/split/fields.json +0 -3869
  45. package/specs/split/records.json +0 -754
  46. package/specs/split/reports.json +0 -619
  47. package/specs/split/tables.json +0 -1605
  48. package/src/RateLimitError.ts +0 -12
  49. package/src/ThrottleBucket.ts +0 -41
  50. package/src/authorizationStrategy.ts +0 -246
  51. package/src/generated-unified/QuickbaseClient.ts +0 -1049
  52. package/src/generated-unified/missing-types-report.json +0 -3
  53. package/src/index.ts +0 -1
  54. package/src/invokeMethod.ts +0 -242
  55. package/src/quickbaseClient.ts +0 -271
  56. package/src/rateLimiter.ts +0 -25
  57. package/src/tokenCache.ts +0 -35
  58. package/src/utils.ts +0 -7
  59. package/test-esm.js +0 -1
  60. package/test-results.json +0 -2050
  61. package/test-umd.js +0 -1
  62. package/test.ts +0 -1
  63. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  64. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  65. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  66. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  67. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  68. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  69. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  70. package/tests/setup.ts +0 -53
  71. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  72. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  73. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  74. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  75. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  76. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  77. package/tests/vitest/qb/auth/mockQuickbaseServer.ts +0 -60
  78. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -73
  79. package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +0 -65
  80. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  81. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  82. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  83. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -82
  84. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  85. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  86. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  87. package/tests/vitest/qb/formulas/runFormula.test.ts +0 -96
  88. package/tests/vitest/qb/index.ts +0 -29
  89. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  90. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  91. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  92. package/tests/vitest/qb/tables/createRelationship.test.ts +0 -102
  93. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  94. package/tests/vitest/qb/tables/deleteRelationship.test.ts +0 -143
  95. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  96. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  97. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  98. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  99. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -250
  100. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  101. package/tests/vitest/unit/ThrottleBucket.test.ts +0 -95
  102. package/tests/vitest/unit/apps/copyApp.test.ts +0 -581
  103. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  104. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  105. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  106. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  107. package/tests/vitest/unit/apps/updateApp.test.ts +0 -412
  108. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -63
  109. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -119
  110. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -95
  111. package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +0 -235
  112. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -69
  113. package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +0 -325
  114. package/tests/vitest/unit/fields/createField.test.ts +0 -451
  115. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  116. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  117. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -180
  118. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  119. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  120. package/tests/vitest/unit/fields/updateField.test.ts +0 -285
  121. package/tests/vitest/unit/formulas/runFormula.test.ts +0 -205
  122. package/tests/vitest/unit/index.ts +0 -34
  123. package/tests/vitest/unit/inferHttpMethod.test.ts +0 -131
  124. package/tests/vitest/unit/rateLimit.test.ts +0 -191
  125. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  126. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  127. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  128. package/tests/vitest/unit/tables/createRelationship.test.ts +0 -212
  129. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  130. package/tests/vitest/unit/tables/deleteRelationship.test.ts +0 -97
  131. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  132. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  133. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  134. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  135. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -307
  136. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  137. package/tests/vitest/unit/tokenLifespan.test.ts +0 -204
  138. package/tests/vitest/unit/umd.test.ts +0 -8
  139. package/text.txt +0 -104
  140. package/tools/log-gen.ts +0 -244
  141. package/tools/log-gen.yaml +0 -5424
  142. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  143. package/tsconfig.build.json +0 -17
  144. package/tsconfig.json +0 -32
  145. package/versionrc.json +0 -9
  146. package/vitest.config.ts +0 -27
@@ -1,581 +0,0 @@
1
- import { describe, it, expect, beforeEach } 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 { CopyAppRequest, CopyApp200Response } from "@/generated/models";
10
-
11
- describe("QuickbaseClient Unit - copyApp", () => {
12
- let client: ReturnType<typeof createClient>;
13
-
14
- beforeEach(() => {
15
- mockFetch.mockClear();
16
- });
17
-
18
- it("initializes without errors", () => {
19
- client = createClient(mockFetch, { debug: true });
20
- expect(client).toBeDefined();
21
- });
22
-
23
- it("has copyApp method", () => {
24
- client = createClient(mockFetch, { debug: true });
25
- expect(typeof client.copyApp).toBe("function");
26
- });
27
-
28
- it("calls copyApp successfully with user token and dates as Date objects", async () => {
29
- client = createClient(mockFetch, { debug: true }); // convertDates defaults to true
30
-
31
- const request: CopyAppRequest = {
32
- name: "Copied App",
33
- description: "A copy of the original app",
34
- properties: {
35
- keepData: false,
36
- excludeFiles: true,
37
- usersAndRoles: false,
38
- assignUserToken: true,
39
- },
40
- };
41
-
42
- const mockResponse: CopyApp200Response = {
43
- id: "bpqe82s1",
44
- name: "Copied App",
45
- description: "A copy of the original app",
46
- created: new Date("2025-03-11T10:00:00Z"),
47
- updated: new Date("2025-03-11T10:00:00Z"),
48
- dateFormat: "MM-DD-YYYY",
49
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
50
- hasEveryoneOnTheInternet: false,
51
- ancestorId: "buwai2zpe",
52
- dataClassification: "None",
53
- variables: [],
54
- };
55
-
56
- mockFetch.mockResolvedValueOnce({
57
- ok: true,
58
- status: 200,
59
- json: () => Promise.resolve(mockResponse),
60
- });
61
-
62
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
63
-
64
- expect(result).toEqual(mockResponse);
65
- expect(mockFetch).toHaveBeenCalledWith(
66
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
67
- expect.objectContaining({
68
- method: "POST",
69
- headers: expect.objectContaining({
70
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
71
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
72
- "Content-Type": "application/json",
73
- }),
74
- credentials: "omit",
75
- body: JSON.stringify(request),
76
- })
77
- );
78
- });
79
-
80
- it("calls copyApp successfully with user token and dates as strings", async () => {
81
- client = createClient(mockFetch, { debug: true, convertDates: false });
82
-
83
- const request: CopyAppRequest = {
84
- name: "Copied App",
85
- description: "A copy of the original app",
86
- properties: {
87
- keepData: false,
88
- excludeFiles: true,
89
- usersAndRoles: false,
90
- assignUserToken: true,
91
- },
92
- };
93
-
94
- const mockResponse = {
95
- id: "bpqe82s1",
96
- name: "Copied App",
97
- description: "A copy of the original app",
98
- created: "2025-03-11T10:00:00Z",
99
- updated: "2025-03-11T10:00:00Z",
100
- dateFormat: "MM-DD-YYYY",
101
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
102
- hasEveryoneOnTheInternet: false,
103
- ancestorId: "buwai2zpe",
104
- dataClassification: "None",
105
- variables: [],
106
- };
107
-
108
- mockFetch.mockResolvedValueOnce({
109
- ok: true,
110
- status: 200,
111
- json: () => Promise.resolve(mockResponse),
112
- });
113
-
114
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
115
-
116
- expect(result).toEqual(mockResponse);
117
- expect(mockFetch).toHaveBeenCalledWith(
118
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
119
- expect.objectContaining({
120
- method: "POST",
121
- headers: expect.objectContaining({
122
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
123
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
124
- "Content-Type": "application/json",
125
- }),
126
- credentials: "omit",
127
- body: JSON.stringify(request),
128
- })
129
- );
130
- });
131
-
132
- it("calls copyApp successfully with temp token and dates as Date objects", async () => {
133
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
134
-
135
- const request: CopyAppRequest = {
136
- name: "Copied App with Temp Token",
137
- description: "A copy using temp token",
138
- properties: {
139
- keepData: true,
140
- excludeFiles: false,
141
- usersAndRoles: true,
142
- assignUserToken: false,
143
- },
144
- };
145
-
146
- const mockResponse: CopyApp200Response = {
147
- id: "bpqe82s2",
148
- name: "Copied App with Temp Token",
149
- description: "A copy using temp token",
150
- created: new Date("2025-03-11T11:00:00Z"),
151
- updated: new Date("2025-03-11T11:00:00Z"),
152
- dateFormat: "MM-DD-YYYY",
153
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
154
- hasEveryoneOnTheInternet: true,
155
- ancestorId: QB_APP_ID,
156
- dataClassification: "None",
157
- variables: [],
158
- };
159
-
160
- mockFetch
161
- .mockResolvedValueOnce({
162
- ok: true,
163
- status: 200,
164
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
165
- })
166
- .mockResolvedValueOnce({
167
- ok: true,
168
- status: 200,
169
- json: () => Promise.resolve(mockResponse),
170
- });
171
-
172
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
173
-
174
- expect(result).toEqual(mockResponse);
175
- expect(mockFetch).toHaveBeenCalledTimes(2);
176
- expect(mockFetch).toHaveBeenNthCalledWith(
177
- 1,
178
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
179
- expect.any(Object)
180
- );
181
- expect(mockFetch).toHaveBeenNthCalledWith(
182
- 2,
183
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
184
- expect.objectContaining({
185
- headers: expect.objectContaining({
186
- Authorization: "QB-TEMP-TOKEN temp_token",
187
- }),
188
- })
189
- );
190
- });
191
-
192
- it("calls copyApp successfully with temp token and dates as strings", async () => {
193
- client = createClient(mockFetch, {
194
- useTempTokens: true,
195
- debug: true,
196
- convertDates: false,
197
- });
198
-
199
- const request: CopyAppRequest = {
200
- name: "Copied App with Temp Token",
201
- description: "A copy using temp token",
202
- properties: {
203
- keepData: true,
204
- excludeFiles: false,
205
- usersAndRoles: true,
206
- assignUserToken: false,
207
- },
208
- };
209
-
210
- const mockResponse = {
211
- id: "bpqe82s2",
212
- name: "Copied App with Temp Token",
213
- description: "A copy using temp token",
214
- created: "2025-03-11T11:00:00Z",
215
- updated: "2025-03-11T11:00:00Z",
216
- dateFormat: "MM-DD-YYYY",
217
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
218
- hasEveryoneOnTheInternet: true,
219
- ancestorId: QB_APP_ID,
220
- dataClassification: "None",
221
- variables: [],
222
- };
223
-
224
- mockFetch
225
- .mockResolvedValueOnce({
226
- ok: true,
227
- status: 200,
228
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
229
- })
230
- .mockResolvedValueOnce({
231
- ok: true,
232
- status: 200,
233
- json: () => Promise.resolve(mockResponse),
234
- });
235
-
236
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
237
-
238
- expect(result).toEqual(mockResponse);
239
- expect(mockFetch).toHaveBeenCalledTimes(2);
240
- expect(mockFetch).toHaveBeenNthCalledWith(
241
- 1,
242
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
243
- expect.any(Object)
244
- );
245
- expect(mockFetch).toHaveBeenNthCalledWith(
246
- 2,
247
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
248
- expect.objectContaining({
249
- headers: expect.objectContaining({
250
- Authorization: "QB-TEMP-TOKEN temp_token",
251
- }),
252
- })
253
- );
254
- });
255
-
256
- it("retries successfully after 401 with temp token and dates as Date objects", async () => {
257
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
258
-
259
- const request: CopyAppRequest = {
260
- name: "Retry Copied App",
261
- description: "Retry after 401",
262
- properties: {
263
- keepData: false,
264
- excludeFiles: true,
265
- usersAndRoles: false,
266
- assignUserToken: true,
267
- },
268
- };
269
-
270
- const mockResponse: CopyApp200Response = {
271
- id: "bpqe82s3",
272
- name: "Retry Copied App",
273
- description: "Retry after 401",
274
- created: new Date("2025-03-11T12:00:00Z"),
275
- updated: new Date("2025-03-11T12:00:00Z"),
276
- dateFormat: "MM-DD-YYYY",
277
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
278
- hasEveryoneOnTheInternet: false,
279
- ancestorId: QB_APP_ID,
280
- dataClassification: "None",
281
- variables: [],
282
- };
283
-
284
- mockFetch
285
- .mockResolvedValueOnce({
286
- ok: true,
287
- status: 200,
288
- json: () =>
289
- Promise.resolve({ temporaryAuthorization: "initial_token" }),
290
- })
291
- .mockResolvedValueOnce({
292
- ok: false,
293
- status: 401,
294
- json: () => Promise.resolve({ message: "Unauthorized" }),
295
- })
296
- .mockResolvedValueOnce({
297
- ok: true,
298
- status: 200,
299
- json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
300
- })
301
- .mockResolvedValueOnce({
302
- ok: true,
303
- status: 200,
304
- json: () => Promise.resolve(mockResponse),
305
- });
306
-
307
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
308
-
309
- expect(result).toEqual(mockResponse);
310
- expect(mockFetch).toHaveBeenCalledTimes(4);
311
- expect(mockFetch).toHaveBeenNthCalledWith(
312
- 1,
313
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
314
- expect.any(Object)
315
- );
316
- expect(mockFetch).toHaveBeenNthCalledWith(
317
- 2,
318
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
319
- expect.objectContaining({
320
- headers: expect.objectContaining({
321
- Authorization: "QB-TEMP-TOKEN initial_token",
322
- }),
323
- })
324
- );
325
- expect(mockFetch).toHaveBeenNthCalledWith(
326
- 3,
327
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
328
- expect.any(Object)
329
- );
330
- expect(mockFetch).toHaveBeenNthCalledWith(
331
- 4,
332
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
333
- expect.objectContaining({
334
- headers: expect.objectContaining({
335
- Authorization: "QB-TEMP-TOKEN new_token",
336
- }),
337
- })
338
- );
339
- });
340
-
341
- it("retries successfully after 401 with temp token and dates as strings", async () => {
342
- client = createClient(mockFetch, {
343
- useTempTokens: true,
344
- debug: true,
345
- convertDates: false,
346
- });
347
-
348
- const request: CopyAppRequest = {
349
- name: "Retry Copied App",
350
- description: "Retry after 401",
351
- properties: {
352
- keepData: false,
353
- excludeFiles: true,
354
- usersAndRoles: false,
355
- assignUserToken: true,
356
- },
357
- };
358
-
359
- const mockResponse = {
360
- id: "bpqe82s3",
361
- name: "Retry Copied App",
362
- description: "Retry after 401",
363
- created: "2025-03-11T12:00:00Z",
364
- updated: "2025-03-11T12:00:00Z",
365
- dateFormat: "MM-DD-YYYY",
366
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
367
- hasEveryoneOnTheInternet: false,
368
- ancestorId: QB_APP_ID,
369
- dataClassification: "None",
370
- variables: [],
371
- };
372
-
373
- mockFetch
374
- .mockResolvedValueOnce({
375
- ok: true,
376
- status: 200,
377
- json: () =>
378
- Promise.resolve({ temporaryAuthorization: "initial_token" }),
379
- })
380
- .mockResolvedValueOnce({
381
- ok: false,
382
- status: 401,
383
- json: () => Promise.resolve({ message: "Unauthorized" }),
384
- })
385
- .mockResolvedValueOnce({
386
- ok: true,
387
- status: 200,
388
- json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
389
- })
390
- .mockResolvedValueOnce({
391
- ok: true,
392
- status: 200,
393
- json: () => Promise.resolve(mockResponse),
394
- });
395
-
396
- const result = await client.copyApp({ appId: QB_APP_ID, body: request });
397
-
398
- expect(result).toEqual(mockResponse);
399
- expect(mockFetch).toHaveBeenCalledTimes(4);
400
- expect(mockFetch).toHaveBeenNthCalledWith(
401
- 1,
402
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
403
- expect.any(Object)
404
- );
405
- expect(mockFetch).toHaveBeenNthCalledWith(
406
- 2,
407
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
408
- expect.objectContaining({
409
- headers: expect.objectContaining({
410
- Authorization: "QB-TEMP-TOKEN initial_token",
411
- }),
412
- })
413
- );
414
- expect(mockFetch).toHaveBeenNthCalledWith(
415
- 3,
416
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
417
- expect.any(Object)
418
- );
419
- expect(mockFetch).toHaveBeenNthCalledWith(
420
- 4,
421
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
422
- expect.objectContaining({
423
- headers: expect.objectContaining({
424
- Authorization: "QB-TEMP-TOKEN new_token",
425
- }),
426
- })
427
- );
428
- });
429
-
430
- it("handles 400 error for invalid request", async () => {
431
- client = createClient(mockFetch, { debug: true });
432
-
433
- const request: CopyAppRequest = {
434
- name: "",
435
- description: "Invalid request",
436
- };
437
-
438
- mockFetch.mockResolvedValueOnce({
439
- ok: false,
440
- status: 400,
441
- json: () => Promise.resolve({ message: "Name is required" }),
442
- });
443
-
444
- await expect(
445
- client.copyApp({ appId: QB_APP_ID, body: request })
446
- ).rejects.toThrow("API Error: Name is required (Status: 400)");
447
-
448
- expect(mockFetch).toHaveBeenCalledWith(
449
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
450
- expect.objectContaining({
451
- method: "POST",
452
- headers: expect.objectContaining({
453
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
454
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
455
- "Content-Type": "application/json",
456
- }),
457
- credentials: "omit",
458
- body: JSON.stringify(request),
459
- })
460
- );
461
- });
462
-
463
- it("exhausts default maxRetries (3) with temp token and throws error", async () => {
464
- client = createClient(mockFetch, { useTempTokens: true, debug: true }); // No explicit maxRetries, uses default 3
465
-
466
- const request: CopyAppRequest = {
467
- name: "Fail App",
468
- description: "Test retry limit",
469
- properties: {
470
- keepData: false,
471
- excludeFiles: true,
472
- usersAndRoles: false,
473
- assignUserToken: true,
474
- },
475
- };
476
-
477
- mockFetch
478
- .mockResolvedValueOnce({
479
- ok: true,
480
- status: 200,
481
- json: () => Promise.resolve({ temporaryAuthorization: "token_1" }),
482
- })
483
- .mockResolvedValueOnce({
484
- ok: false,
485
- status: 401,
486
- json: () => Promise.resolve({ message: "Unauthorized 1" }),
487
- })
488
- .mockResolvedValueOnce({
489
- ok: true,
490
- status: 200,
491
- json: () => Promise.resolve({ temporaryAuthorization: "token_2" }),
492
- })
493
- .mockResolvedValueOnce({
494
- ok: false,
495
- status: 401,
496
- json: () => Promise.resolve({ message: "Unauthorized 2" }),
497
- })
498
- .mockResolvedValueOnce({
499
- ok: true,
500
- status: 200,
501
- json: () => Promise.resolve({ temporaryAuthorization: "token_3" }),
502
- })
503
- .mockResolvedValueOnce({
504
- ok: false,
505
- status: 401,
506
- json: () => Promise.resolve({ message: "Unauthorized 3" }),
507
- })
508
- .mockResolvedValueOnce({
509
- ok: true,
510
- status: 200,
511
- json: () => Promise.resolve({ temporaryAuthorization: "token_4" }),
512
- })
513
- .mockResolvedValueOnce({
514
- ok: false,
515
- status: 401,
516
- json: () => Promise.resolve({ message: "Unauthorized 4" }),
517
- });
518
-
519
- await expect(
520
- client.copyApp({ appId: QB_APP_ID, body: request })
521
- ).rejects.toThrow("API Error: Unauthorized 4 (Status: 401)");
522
-
523
- expect(mockFetch).toHaveBeenCalledTimes(8); // 4 token fetches + 4 API attempts
524
- expect(mockFetch).toHaveBeenNthCalledWith(
525
- 1,
526
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
527
- expect.any(Object)
528
- );
529
- expect(mockFetch).toHaveBeenNthCalledWith(
530
- 2,
531
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
532
- expect.objectContaining({
533
- headers: expect.objectContaining({
534
- Authorization: "QB-TEMP-TOKEN token_1",
535
- }),
536
- })
537
- );
538
- expect(mockFetch).toHaveBeenNthCalledWith(
539
- 3,
540
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
541
- expect.any(Object)
542
- );
543
- expect(mockFetch).toHaveBeenNthCalledWith(
544
- 4,
545
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
546
- expect.objectContaining({
547
- headers: expect.objectContaining({
548
- Authorization: "QB-TEMP-TOKEN token_2",
549
- }),
550
- })
551
- );
552
- expect(mockFetch).toHaveBeenNthCalledWith(
553
- 5,
554
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
555
- expect.any(Object)
556
- );
557
- expect(mockFetch).toHaveBeenNthCalledWith(
558
- 6,
559
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
560
- expect.objectContaining({
561
- headers: expect.objectContaining({
562
- Authorization: "QB-TEMP-TOKEN token_3",
563
- }),
564
- })
565
- );
566
- expect(mockFetch).toHaveBeenNthCalledWith(
567
- 7,
568
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
569
- expect.any(Object)
570
- );
571
- expect(mockFetch).toHaveBeenNthCalledWith(
572
- 8,
573
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
574
- expect.objectContaining({
575
- headers: expect.objectContaining({
576
- Authorization: "QB-TEMP-TOKEN token_4",
577
- }),
578
- })
579
- );
580
- });
581
- });