quickbase-js 0.1.0-beta.13 → 0.1.0-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/README.md +1 -1
  2. package/dist/esm/quickbase.d.ts +2 -1
  3. package/package.json +9 -4
  4. package/CHANGELOG.md +0 -239
  5. package/build-common.js +0 -131
  6. package/build-esm.js +0 -71
  7. package/build-umd.js +0 -69
  8. package/docs/.vitepress/cache/deps/@theme_index.js +0 -275
  9. package/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
  10. package/docs/.vitepress/cache/deps/_metadata.json +0 -40
  11. package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js +0 -12542
  12. package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js.map +0 -7
  13. package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js +0 -9719
  14. package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js.map +0 -7
  15. package/docs/.vitepress/cache/deps/package.json +0 -3
  16. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4504
  17. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  18. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -583
  19. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  20. package/docs/.vitepress/cache/deps/vue.js +0 -343
  21. package/docs/.vitepress/cache/deps/vue.js.map +0 -7
  22. package/docs/.vitepress/config.mts +0 -26
  23. package/docs/api-examples.md +0 -49
  24. package/docs/index.md +0 -59
  25. package/docs/markdown-examples.md +0 -85
  26. package/docs-data/api-docs.json +0 -4143
  27. package/examples/quicbase-jsCDN.html +0 -36
  28. package/examples/react.js +0 -48
  29. package/examples/vanillajs.html +0 -47
  30. package/index.md +0 -25
  31. package/open-api/fix-spec-main.ts +0 -133
  32. package/open-api/generate-unified-interface.ts +0 -104
  33. package/open-api/generateDocsJson.ts +0 -24
  34. package/open-api/output/quickbase-fixed.json +0 -11191
  35. package/open-api/post-process-generated.ts +0 -226
  36. package/open-api/regenerate-client.ts +0 -117
  37. package/open-api/schema/enhance-general.ts +0 -111
  38. package/open-api/schema/fix-arrays.ts +0 -68
  39. package/open-api/schema/tags/apps.ts +0 -90
  40. package/open-api/schema/tags/fields.ts +0 -471
  41. package/open-api/schema/tags/groups.ts +0 -51
  42. package/open-api/schema/tags/index.ts +0 -66
  43. package/open-api/schema/tags/records.ts +0 -115
  44. package/open-api/schema/tags/tables.ts +0 -211
  45. package/open-api/schema/tags/users.ts +0 -47
  46. package/open-api/types/spec.ts +0 -42
  47. package/open-api/utils/common.ts +0 -29
  48. package/open-api/utils/generateJsDoc.ts +0 -74
  49. package/open-api/utils/infer-schema.ts +0 -40
  50. package/open-api/utils/naming.ts +0 -10
  51. package/open-api/utils/sharedUtils.ts +0 -352
  52. package/playwright.config.ts +0 -37
  53. package/rollup.config.js +0 -114
  54. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  55. package/specs/split/apps.json +0 -1315
  56. package/specs/split/auth.json +0 -191
  57. package/specs/split/fields.json +0 -3869
  58. package/specs/split/records.json +0 -754
  59. package/specs/split/reports.json +0 -619
  60. package/specs/split/tables.json +0 -1605
  61. package/src/BurstAwareThrottleBucket.ts +0 -57
  62. package/src/FlowThrottleBucket.ts +0 -47
  63. package/src/RateLimitError.ts +0 -12
  64. package/src/RateThrottleBucket.ts +0 -5
  65. package/src/Semaphore.ts +0 -33
  66. package/src/authorizationStrategy.ts +0 -321
  67. package/src/generated-unified/QuickbaseClient.ts +0 -1135
  68. package/src/generated-unified/missing-types-report.json +0 -3
  69. package/src/index.ts +0 -1
  70. package/src/invokeMethod.ts +0 -290
  71. package/src/pagination.ts +0 -429
  72. package/src/quickbaseClient.ts +0 -227
  73. package/src/rateLimiter.ts +0 -30
  74. package/src/tokenCache.ts +0 -39
  75. package/src/utils.ts +0 -50
  76. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  77. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  78. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  79. package/tests/playwright/qb/auth/getAppWithTempTokenConcurrency.test.ts +0 -208
  80. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  81. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  82. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  83. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  84. package/tests/setup.ts +0 -53
  85. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  86. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  87. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  88. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  89. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  90. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  91. package/tests/vitest/qb/auth/mockQuickbaseServer.ts +0 -60
  92. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -73
  93. package/tests/vitest/qb/auth/ssoTokenConcurrency.test.ts +0 -68
  94. package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +0 -65
  95. package/tests/vitest/qb/auth/userTokenConcurrency.test.ts +0 -63
  96. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  97. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  98. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  99. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -82
  100. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  101. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  102. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  103. package/tests/vitest/qb/formulas/runFormula.test.ts +0 -96
  104. package/tests/vitest/qb/index.ts +0 -29
  105. package/tests/vitest/qb/quickbase-js/BurstAwareThrottleBucket.test.ts +0 -125
  106. package/tests/vitest/qb/quickbase-js/FlowBucket.test.ts +0 -77
  107. package/tests/vitest/qb/quickbase-js/paginationSkip.test.ts +0 -111
  108. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  109. package/tests/vitest/qb/records/runQuery.test.ts +0 -145
  110. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  111. package/tests/vitest/qb/tables/createRelationship.test.ts +0 -102
  112. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  113. package/tests/vitest/qb/tables/deleteRelationship.test.ts +0 -143
  114. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  115. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  116. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  117. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  118. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -250
  119. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  120. package/tests/vitest/unit/apps/copyApp.test.ts +0 -581
  121. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  122. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  123. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  124. package/tests/vitest/unit/apps/getAppConcurrency.test.ts +0 -151
  125. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  126. package/tests/vitest/unit/apps/updateApp.test.ts +0 -412
  127. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -81
  128. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -119
  129. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -95
  130. package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +0 -206
  131. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -66
  132. package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +0 -325
  133. package/tests/vitest/unit/auth/userTokenConcurrency.test.ts +0 -62
  134. package/tests/vitest/unit/fields/createField.test.ts +0 -451
  135. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  136. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  137. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -180
  138. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  139. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  140. package/tests/vitest/unit/fields/updateField.test.ts +0 -285
  141. package/tests/vitest/unit/formulas/runFormula.test.ts +0 -205
  142. package/tests/vitest/unit/index.ts +0 -34
  143. package/tests/vitest/unit/quickbase-js/BurstAwareThrottleBucket.test.ts +0 -108
  144. package/tests/vitest/unit/quickbase-js/FlowBucket.test.ts +0 -101
  145. package/tests/vitest/unit/quickbase-js/pagination.test.ts +0 -251
  146. package/tests/vitest/unit/quickbase-js/quickbaseClientHttpMethods.test.ts +0 -141
  147. package/tests/vitest/unit/quickbase-js/rateLimit.test.ts +0 -191
  148. package/tests/vitest/unit/quickbase-js/tokenLifespan.test.ts +0 -204
  149. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  150. package/tests/vitest/unit/records/runQuery.test.ts +0 -101
  151. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  152. package/tests/vitest/unit/tables/createRelationship.test.ts +0 -212
  153. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  154. package/tests/vitest/unit/tables/deleteRelationship.test.ts +0 -97
  155. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  156. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  157. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  158. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  159. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -307
  160. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  161. package/tools/log-gen.ts +0 -251
  162. package/tools/log-gen.yaml +0 -4829
  163. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  164. package/tsconfig.build.json +0 -17
  165. package/tsconfig.json +0 -32
  166. package/versionrc.json +0 -9
  167. package/vitest.config.ts +0 -27
@@ -1,48 +0,0 @@
1
- import { test, expect } from "vitest";
2
- import { quickbase } from "../../../../src/quickbaseClient";
3
-
4
- test(
5
- "QuickbaseClient Integration - updateTable > updates real table data in QuickBase",
6
- { timeout: 10000 },
7
- async () => {
8
- const config = {
9
- realm: process.env.QB_REALM || "",
10
- userToken: process.env.QB_USER_TOKEN || "",
11
- debug: true,
12
- };
13
- const client = quickbase(config);
14
- const appId = "buwai2zpe";
15
- const tableId = "buwai2zr4";
16
- const updatedBody = {
17
- name: "Root Updated " + Date.now(),
18
- description: "Integration test update",
19
- };
20
- const originalBody = {
21
- name: "Root",
22
- description: "",
23
- };
24
-
25
- console.log("Config used:", config);
26
- // Update the table
27
- const response = await client.updateTable({
28
- tableId,
29
- appId,
30
- body: updatedBody,
31
- });
32
- expect(response).toBeDefined();
33
- expect(response.id).toBe(tableId);
34
- expect(response.name).toBe(updatedBody.name);
35
- expect(response.description).toBe(updatedBody.description);
36
- console.log("Real API response:", response);
37
-
38
- // Cleanup: Revert the table to original state
39
- const cleanupResponse = await client.updateTable({
40
- tableId,
41
- appId,
42
- body: originalBody,
43
- });
44
- expect(cleanupResponse.name).toBe(originalBody.name);
45
- expect(cleanupResponse.description).toBe(originalBody.description);
46
- console.log("Cleanup API response:", cleanupResponse);
47
- }
48
- );
@@ -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
- });