quickbase-js 0.1.0-beta.12 → 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 (168) hide show
  1. package/README.md +48 -18
  2. package/dist/esm/quickbase.d.ts +13 -3
  3. package/dist/esm/quickbase.js +416 -49
  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 +416 -49
  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 +11 -4
  12. package/CHANGELOG.md +0 -227
  13. package/build-common.js +0 -131
  14. package/build-esm.js +0 -71
  15. package/build-umd.js +0 -69
  16. package/docs/.vitepress/cache/deps/@theme_index.js +0 -275
  17. package/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
  18. package/docs/.vitepress/cache/deps/_metadata.json +0 -40
  19. package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js +0 -12542
  20. package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js.map +0 -7
  21. package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js +0 -9719
  22. package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js.map +0 -7
  23. package/docs/.vitepress/cache/deps/package.json +0 -3
  24. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4504
  25. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  26. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -583
  27. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  28. package/docs/.vitepress/cache/deps/vue.js +0 -343
  29. package/docs/.vitepress/cache/deps/vue.js.map +0 -7
  30. package/docs/.vitepress/config.mts +0 -26
  31. package/docs/api-examples.md +0 -49
  32. package/docs/index.md +0 -59
  33. package/docs/markdown-examples.md +0 -85
  34. package/docs-data/api-docs.json +0 -4143
  35. package/examples/quicbase-jsCDN.html +0 -36
  36. package/examples/react.js +0 -48
  37. package/examples/vanillajs.html +0 -47
  38. package/index.md +0 -25
  39. package/open-api/fix-spec-main.ts +0 -133
  40. package/open-api/generate-unified-interface.ts +0 -104
  41. package/open-api/generateDocsJson.ts +0 -24
  42. package/open-api/output/quickbase-fixed.json +0 -11191
  43. package/open-api/post-process-generated.ts +0 -226
  44. package/open-api/regenerate-client.ts +0 -117
  45. package/open-api/schema/enhance-general.ts +0 -111
  46. package/open-api/schema/fix-arrays.ts +0 -68
  47. package/open-api/schema/tags/apps.ts +0 -90
  48. package/open-api/schema/tags/fields.ts +0 -471
  49. package/open-api/schema/tags/groups.ts +0 -51
  50. package/open-api/schema/tags/index.ts +0 -66
  51. package/open-api/schema/tags/records.ts +0 -115
  52. package/open-api/schema/tags/tables.ts +0 -211
  53. package/open-api/schema/tags/users.ts +0 -47
  54. package/open-api/types/spec.ts +0 -42
  55. package/open-api/utils/common.ts +0 -29
  56. package/open-api/utils/generateJsDoc.ts +0 -74
  57. package/open-api/utils/infer-schema.ts +0 -40
  58. package/open-api/utils/naming.ts +0 -10
  59. package/open-api/utils/sharedUtils.ts +0 -352
  60. package/playwright.config.ts +0 -37
  61. package/rollup.config.js +0 -114
  62. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  63. package/specs/split/apps.json +0 -1315
  64. package/specs/split/auth.json +0 -191
  65. package/specs/split/fields.json +0 -3869
  66. package/specs/split/records.json +0 -754
  67. package/specs/split/reports.json +0 -619
  68. package/specs/split/tables.json +0 -1605
  69. package/src/RateLimitError.ts +0 -12
  70. package/src/ThrottleBucket.ts +0 -77
  71. package/src/authorizationStrategy.ts +0 -310
  72. package/src/generated-unified/QuickbaseClient.ts +0 -1135
  73. package/src/generated-unified/missing-types-report.json +0 -3
  74. package/src/index.ts +0 -1
  75. package/src/invokeMethod.ts +0 -212
  76. package/src/quickbaseClient.ts +0 -199
  77. package/src/rateLimiter.ts +0 -30
  78. package/src/tokenCache.ts +0 -39
  79. package/src/utils.ts +0 -50
  80. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  81. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  82. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  83. package/tests/playwright/qb/auth/getAppWithTempTokenConcurrency.test.ts +0 -208
  84. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  85. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  86. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  87. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  88. package/tests/setup.ts +0 -53
  89. package/tests/vitest/qb/ThrottleBucket.test.ts +0 -77
  90. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  91. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  92. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  93. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  94. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  95. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  96. package/tests/vitest/qb/auth/mockQuickbaseServer.ts +0 -60
  97. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -73
  98. package/tests/vitest/qb/auth/ssoTokenConcurrency.test.ts +0 -68
  99. package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +0 -65
  100. package/tests/vitest/qb/auth/userTokenConcurrency.test.ts +0 -63
  101. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  102. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  103. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  104. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -82
  105. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  106. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  107. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  108. package/tests/vitest/qb/formulas/runFormula.test.ts +0 -96
  109. package/tests/vitest/qb/index.ts +0 -29
  110. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  111. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  112. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  113. package/tests/vitest/qb/tables/createRelationship.test.ts +0 -102
  114. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  115. package/tests/vitest/qb/tables/deleteRelationship.test.ts +0 -143
  116. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  117. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  118. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  119. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  120. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -250
  121. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  122. package/tests/vitest/unit/ThrottleBucket.test.ts +0 -101
  123. package/tests/vitest/unit/apps/copyApp.test.ts +0 -581
  124. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  125. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  126. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  127. package/tests/vitest/unit/apps/getAppConcurrency.test.ts +0 -151
  128. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  129. package/tests/vitest/unit/apps/updateApp.test.ts +0 -412
  130. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -81
  131. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -119
  132. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -95
  133. package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +0 -206
  134. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -69
  135. package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +0 -325
  136. package/tests/vitest/unit/auth/userTokenConcurrency.test.ts +0 -62
  137. package/tests/vitest/unit/fields/createField.test.ts +0 -451
  138. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  139. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  140. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -180
  141. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  142. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  143. package/tests/vitest/unit/fields/updateField.test.ts +0 -285
  144. package/tests/vitest/unit/formulas/runFormula.test.ts +0 -205
  145. package/tests/vitest/unit/index.ts +0 -34
  146. package/tests/vitest/unit/quickbaseClientHttpMethods.test.ts +0 -139
  147. package/tests/vitest/unit/rateLimit.test.ts +0 -191
  148. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  149. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  150. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  151. package/tests/vitest/unit/tables/createRelationship.test.ts +0 -212
  152. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  153. package/tests/vitest/unit/tables/deleteRelationship.test.ts +0 -97
  154. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  155. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  156. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  157. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  158. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -307
  159. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  160. package/tests/vitest/unit/tokenLifespan.test.ts +0 -204
  161. package/tests/vitest/unit/umd.test.ts +0 -8
  162. package/tools/log-gen.ts +0 -251
  163. package/tools/log-gen.yaml +0 -4829
  164. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  165. package/tsconfig.build.json +0 -17
  166. package/tsconfig.json +0 -32
  167. package/versionrc.json +0 -9
  168. package/vitest.config.ts +0 -27
@@ -1,307 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import {
3
- createClient,
4
- mockFetch,
5
- QB_REALM,
6
- QB_USER_TOKEN,
7
- QB_TABLE_ID_1,
8
- } from "@tests/setup.ts";
9
- import {
10
- UpdateRelationshipRequest,
11
- UpdateRelationship200Response,
12
- } from "@/generated/models";
13
-
14
- describe("QuickbaseClient Unit - updateRelationship", () => {
15
- let client: ReturnType<typeof createClient>;
16
-
17
- beforeEach(() => {
18
- mockFetch.mockClear();
19
- });
20
-
21
- it("initializes without errors and has updateRelationship method", () => {
22
- client = createClient(mockFetch, { debug: true });
23
- expect(client).toBeDefined();
24
- expect(typeof client.updateRelationship).toBe("function");
25
- });
26
-
27
- it("updates relationship successfully with user token", async () => {
28
- client = createClient(mockFetch, { debug: true });
29
-
30
- const tableId = QB_TABLE_ID_1;
31
- const relationshipId = 6;
32
-
33
- const request: UpdateRelationshipRequest = {
34
- lookupFieldIds: [4, 5, 6],
35
- summaryFields: [
36
- {
37
- summaryFid: 3,
38
- label: "my summary field",
39
- accumulationType: "COUNT",
40
- where: "{'3'.EX.'1'}",
41
- },
42
- ],
43
- };
44
-
45
- const mockResponse: UpdateRelationship200Response = {
46
- id: relationshipId,
47
- parentTableId: "bck7gp3q2",
48
- childTableId: tableId,
49
- foreignKeyField: {
50
- id: relationshipId,
51
- label: "Related record",
52
- type: "numeric",
53
- },
54
- isCrossApp: false,
55
- lookupFields: [
56
- { id: 4, label: "Field 4", type: "text" },
57
- { id: 5, label: "Field 5", type: "numeric" },
58
- { id: 6, label: "Field 6", type: "date" },
59
- ],
60
- summaryFields: [{ id: 8, label: "my summary field", type: "numeric" }],
61
- };
62
-
63
- mockFetch.mockResolvedValueOnce({
64
- ok: true,
65
- status: 200,
66
- json: () => Promise.resolve(mockResponse),
67
- });
68
-
69
- const result = await client.updateRelationship({
70
- tableId,
71
- relationshipId,
72
- body: request,
73
- });
74
-
75
- expect(result).toEqual(mockResponse);
76
- expect(mockFetch).toHaveBeenCalledWith(
77
- `https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`,
78
- expect.objectContaining({
79
- method: "POST",
80
- headers: expect.objectContaining({
81
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
82
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
83
- "Content-Type": "application/json",
84
- }),
85
- body: JSON.stringify(request),
86
- credentials: "omit",
87
- })
88
- );
89
- });
90
-
91
- it("updates relationship successfully with temp token", async () => {
92
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
93
-
94
- const tableId = QB_TABLE_ID_1;
95
- const relationshipId = 6;
96
-
97
- const request: UpdateRelationshipRequest = {
98
- lookupFieldIds: [7],
99
- summaryFields: [
100
- {
101
- summaryFid: 0,
102
- label: "Count of Records",
103
- accumulationType: "COUNT",
104
- where: "{'3'.GT.0}",
105
- },
106
- ],
107
- };
108
-
109
- const mockResponse: UpdateRelationship200Response = {
110
- id: relationshipId,
111
- parentTableId: "bck7gp3q2",
112
- childTableId: tableId,
113
- foreignKeyField: {
114
- id: relationshipId,
115
- label: "Related record",
116
- type: "numeric",
117
- },
118
- isCrossApp: false,
119
- lookupFields: [{ id: 7, label: "record - text field", type: "text" }],
120
- summaryFields: [{ id: 9, label: "Count of Records", type: "numeric" }],
121
- };
122
-
123
- mockFetch
124
- .mockResolvedValueOnce({
125
- ok: true,
126
- status: 200,
127
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
128
- })
129
- .mockResolvedValueOnce({
130
- ok: true,
131
- status: 200,
132
- json: () => Promise.resolve(mockResponse),
133
- });
134
-
135
- const result = await client.updateRelationship({
136
- tableId,
137
- relationshipId,
138
- body: request,
139
- });
140
-
141
- expect(result).toEqual(mockResponse);
142
- expect(mockFetch).toHaveBeenCalledTimes(2);
143
- expect(mockFetch).toHaveBeenNthCalledWith(
144
- 1,
145
- `https://api.quickbase.com/v1/auth/temporary/${tableId}`,
146
- expect.objectContaining({
147
- method: "GET",
148
- headers: expect.objectContaining({
149
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
150
- "Content-Type": "application/json",
151
- }),
152
- credentials: "include",
153
- })
154
- );
155
- expect(mockFetch).toHaveBeenNthCalledWith(
156
- 2,
157
- `https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`,
158
- expect.objectContaining({
159
- method: "POST",
160
- headers: expect.objectContaining({
161
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
162
- Authorization: "QB-TEMP-TOKEN temp_token",
163
- "Content-Type": "application/json",
164
- }),
165
- body: JSON.stringify(request),
166
- credentials: "omit",
167
- })
168
- );
169
- });
170
-
171
- it("retries successfully after 401 with temp token", async () => {
172
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
173
-
174
- const tableId = QB_TABLE_ID_1;
175
- const relationshipId = 6;
176
-
177
- const request: UpdateRelationshipRequest = {
178
- lookupFieldIds: [4],
179
- };
180
-
181
- const mockResponse: UpdateRelationship200Response = {
182
- id: relationshipId,
183
- parentTableId: "bck7gp3q2",
184
- childTableId: tableId,
185
- foreignKeyField: {
186
- id: relationshipId,
187
- label: "Related record",
188
- type: "numeric",
189
- },
190
- isCrossApp: false,
191
- lookupFields: [{ id: 4, label: "Field 4", type: "text" }],
192
- summaryFields: [],
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.updateRelationship({
220
- tableId,
221
- relationshipId,
222
- body: request,
223
- });
224
-
225
- expect(result).toEqual(mockResponse);
226
- expect(mockFetch).toHaveBeenCalledTimes(4);
227
- expect(mockFetch).toHaveBeenNthCalledWith(
228
- 1,
229
- `https://api.quickbase.com/v1/auth/temporary/${tableId}`,
230
- expect.any(Object)
231
- );
232
- expect(mockFetch).toHaveBeenNthCalledWith(
233
- 2,
234
- `https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`,
235
- expect.objectContaining({
236
- headers: expect.objectContaining({
237
- Authorization: "QB-TEMP-TOKEN initial_token",
238
- }),
239
- })
240
- );
241
- expect(mockFetch).toHaveBeenNthCalledWith(
242
- 3,
243
- `https://api.quickbase.com/v1/auth/temporary/${tableId}`,
244
- expect.any(Object)
245
- );
246
- expect(mockFetch).toHaveBeenNthCalledWith(
247
- 4,
248
- `https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`,
249
- expect.objectContaining({
250
- headers: expect.objectContaining({
251
- Authorization: "QB-TEMP-TOKEN new_token",
252
- }),
253
- })
254
- );
255
-
256
- // Updated log expectations
257
- expect(consoleSpy).toHaveBeenCalledWith(
258
- "Authorization error for updateRelationship (temp token), refreshing token:"
259
- );
260
- expect(consoleSpy).toHaveBeenCalledWith(
261
- expect.stringContaining(
262
- "[updateRelationship] Retrying with token: new_tok"
263
- )
264
- );
265
-
266
- consoleSpy.mockRestore();
267
- });
268
-
269
- it("handles 400 error for invalid request", async () => {
270
- client = createClient(mockFetch, { debug: true });
271
-
272
- const tableId = QB_TABLE_ID_1;
273
- const relationshipId = 6;
274
-
275
- const request: UpdateRelationshipRequest = {
276
- lookupFieldIds: [-1],
277
- };
278
-
279
- mockFetch.mockResolvedValueOnce({
280
- ok: false,
281
- status: 400,
282
- json: () => Promise.resolve({ message: "Invalid field ID" }),
283
- });
284
-
285
- await expect(
286
- client.updateRelationship({
287
- tableId,
288
- relationshipId,
289
- body: request,
290
- })
291
- ).rejects.toThrow("API Error: Invalid field ID (Status: 400)");
292
-
293
- expect(mockFetch).toHaveBeenCalledWith(
294
- `https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`,
295
- expect.objectContaining({
296
- method: "POST",
297
- headers: expect.objectContaining({
298
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
299
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
300
- "Content-Type": "application/json",
301
- }),
302
- body: JSON.stringify(request),
303
- credentials: "omit",
304
- })
305
- );
306
- });
307
- });
@@ -1,80 +0,0 @@
1
- // tests/vitest/unit/records/updateTable.test.ts
2
- import { describe, it, expect, beforeEach } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_APP_ID,
7
- QB_TABLE_ID_1,
8
- } from "@tests/setup.ts";
9
-
10
- describe("QuickbaseClient Unit - updateTable", () => {
11
- let client: ReturnType<typeof createClient>;
12
-
13
- beforeEach(() => {
14
- mockFetch.mockClear();
15
- client = createClient(mockFetch, { debug: true });
16
- });
17
-
18
- it("calls updateTable successfully with temp token", async () => {
19
- client = createClient(mockFetch, { debug: true, useTempTokens: true });
20
-
21
- const mockBody = {
22
- name: "Updated Root",
23
- description: "Updated description",
24
- };
25
- const mockResponse = {
26
- id: QB_TABLE_ID_1,
27
- name: "Updated Root",
28
- alias: "_DBID_ROOT",
29
- description: "Updated description",
30
- created: new Date("2025-02-13T18:22:33.000Z"),
31
- updated: new Date("2025-03-10T12:00:00.000Z"),
32
- nextRecordId: 1,
33
- nextFieldId: 6,
34
- defaultSortFieldId: 2,
35
- defaultSortOrder: "DESC",
36
- keyFieldId: 3,
37
- singleRecordName: "Root",
38
- pluralRecordName: "Roots",
39
- sizeLimit: "500 MB",
40
- spaceUsed: "0 KB",
41
- spaceRemaining: "500 MB",
42
- };
43
-
44
- mockFetch
45
- .mockResolvedValueOnce({
46
- ok: true,
47
- status: 200,
48
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
49
- })
50
- .mockResolvedValueOnce({
51
- ok: true,
52
- status: 200,
53
- json: () => Promise.resolve(mockResponse),
54
- });
55
-
56
- const response = await client.updateTable({
57
- tableId: QB_TABLE_ID_1,
58
- appId: QB_APP_ID,
59
- body: mockBody,
60
- });
61
- expect(response).toEqual(mockResponse);
62
- expect(mockFetch).toHaveBeenCalledTimes(2);
63
- expect(mockFetch).toHaveBeenCalledWith(
64
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
65
- expect.any(Object)
66
- );
67
- expect(mockFetch).toHaveBeenCalledWith(
68
- `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
69
- expect.objectContaining({
70
- method: "POST",
71
- headers: expect.objectContaining({
72
- "QB-Realm-Hostname": `${process.env.QB_REALM}.quickbase.com`,
73
- Authorization: "QB-TEMP-TOKEN temp_token",
74
- "Content-Type": "application/json",
75
- }),
76
- body: JSON.stringify(mockBody),
77
- })
78
- );
79
- });
80
- });
@@ -1,204 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
2
- import { createClient, mockFetch, QB_APP_ID, QB_REALM } from "@tests/setup.ts";
3
- import { UpdateAppRequest, UpdateApp200Response } from "@/generated/models";
4
-
5
- describe("QuickbaseClient Unit - Token Lifespan", () => {
6
- let client: ReturnType<typeof createClient>;
7
- const request: UpdateAppRequest = { name: "Test App" };
8
- const mockResponse: UpdateApp200Response = {
9
- id: QB_APP_ID,
10
- name: "Test App",
11
- description: "",
12
- created: new Date("2020-01-01T00:00:00Z"), // Match deserialized Date object
13
- updated: new Date("2020-01-01T00:00:00Z"),
14
- dateFormat: "MM-DD-YYYY",
15
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
16
- hasEveryoneOnTheInternet: false,
17
- ancestorId: undefined,
18
- variables: [],
19
- securityProperties: {},
20
- memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
21
- dataClassification: "None",
22
- };
23
-
24
- beforeEach(() => {
25
- mockFetch.mockClear();
26
- vi.useFakeTimers();
27
- console.log("[beforeEach] mockFetch cleared and fake timers enabled");
28
- });
29
-
30
- afterEach(() => {
31
- vi.useRealTimers();
32
- });
33
-
34
- const setupMocks = (token: string) => {
35
- mockFetch
36
- .mockResolvedValueOnce({
37
- ok: true,
38
- status: 200,
39
- json: () => Promise.resolve({ temporaryAuthorization: token }),
40
- })
41
- .mockResolvedValueOnce({
42
- ok: true,
43
- status: 200,
44
- json: () => Promise.resolve(mockResponse),
45
- });
46
- };
47
-
48
- it("reuses token within custom lifespan and refetches after expiration", async () => {
49
- client = createClient(mockFetch, {
50
- realm: QB_REALM,
51
- useTempTokens: true,
52
- tempTokenLifespan: 500,
53
- debug: true,
54
- });
55
-
56
- setupMocks("token1");
57
- await client.updateApp({ appId: QB_APP_ID, body: request });
58
- expect(mockFetch).toHaveBeenCalledTimes(2);
59
- expect(mockFetch.mock.calls[1][1].headers.Authorization).toBe(
60
- "QB-TEMP-TOKEN token1"
61
- );
62
-
63
- mockFetch.mockResolvedValueOnce({
64
- ok: true,
65
- status: 200,
66
- json: () => Promise.resolve(mockResponse),
67
- });
68
- await client.updateApp({ appId: QB_APP_ID, body: request });
69
- expect(mockFetch).toHaveBeenCalledTimes(3);
70
- expect(mockFetch.mock.calls[2][1].headers.Authorization).toBe(
71
- "QB-TEMP-TOKEN token1"
72
- );
73
-
74
- vi.advanceTimersByTime(500);
75
- console.log("[Test 1] Token expired after 500ms");
76
-
77
- setupMocks("token2");
78
- await client.updateApp({ appId: QB_APP_ID, body: request });
79
- expect(mockFetch).toHaveBeenCalledTimes(5);
80
- expect(mockFetch.mock.calls[4][1].headers.Authorization).toBe(
81
- "QB-TEMP-TOKEN token2"
82
- );
83
- });
84
-
85
- it("reuses token within default lifespan of 4m50s", async () => {
86
- client = createClient(mockFetch, {
87
- realm: QB_REALM,
88
- useTempTokens: true,
89
- debug: true,
90
- });
91
-
92
- setupMocks("default_token");
93
- await client.updateApp({ appId: QB_APP_ID, body: request });
94
- expect(mockFetch).toHaveBeenCalledTimes(2);
95
- expect(mockFetch.mock.calls[1][1].headers.Authorization).toBe(
96
- "QB-TEMP-TOKEN default_token"
97
- );
98
-
99
- vi.advanceTimersByTime(1000);
100
- console.log(
101
- "[Test 2] Advanced time by 1000ms, still within default lifespan"
102
- );
103
-
104
- mockFetch.mockResolvedValueOnce({
105
- ok: true,
106
- status: 200,
107
- json: () => Promise.resolve(mockResponse),
108
- });
109
- await client.updateApp({ appId: QB_APP_ID, body: request });
110
- expect(mockFetch).toHaveBeenCalledTimes(3);
111
- expect(mockFetch.mock.calls[2][1].headers.Authorization).toBe(
112
- "QB-TEMP-TOKEN default_token"
113
- );
114
- });
115
-
116
- it("handles token fetch failure gracefully", async () => {
117
- client = createClient(mockFetch, {
118
- realm: QB_REALM,
119
- useTempTokens: true,
120
- tempTokenLifespan: 500,
121
- });
122
-
123
- mockFetch.mockResolvedValueOnce({
124
- ok: false,
125
- status: 500,
126
- json: () => Promise.resolve({ message: "Network error" }),
127
- });
128
- await expect(
129
- client.updateApp({ appId: QB_APP_ID, body: request })
130
- ).rejects.toThrow("API Error: Network error (Status: 500)");
131
- expect(mockFetch).toHaveBeenCalledTimes(1);
132
- });
133
-
134
- it("fetches new token every call with zero lifespan", async () => {
135
- client = createClient(mockFetch, {
136
- realm: QB_REALM,
137
- useTempTokens: true,
138
- tempTokenLifespan: 0,
139
- });
140
-
141
- setupMocks("token1");
142
- await client.updateApp({ appId: QB_APP_ID, body: request });
143
- expect(mockFetch).toHaveBeenCalledTimes(2);
144
-
145
- setupMocks("token2");
146
- await client.updateApp({ appId: QB_APP_ID, body: request });
147
- expect(mockFetch).toHaveBeenCalledTimes(4);
148
- expect(mockFetch.mock.calls[3][1].headers.Authorization).toBe(
149
- "QB-TEMP-TOKEN token2"
150
- );
151
- });
152
-
153
- it("reuses token across concurrent calls within lifespan", async () => {
154
- client = createClient(mockFetch, {
155
- realm: QB_REALM,
156
- useTempTokens: true,
157
- tempTokenLifespan: 500,
158
- debug: true,
159
- });
160
-
161
- // Pre-fetch token to ensure it’s cached
162
- mockFetch.mockResolvedValueOnce({
163
- ok: true,
164
- status: 200,
165
- json: () => Promise.resolve({ temporaryAuthorization: "token1" }),
166
- });
167
- mockFetch.mockResolvedValueOnce({
168
- ok: true,
169
- status: 200,
170
- json: () => Promise.resolve(mockResponse),
171
- });
172
- await client.updateApp({ appId: QB_APP_ID, body: request }); // Cache token1
173
- vi.advanceTimersByTime(1);
174
-
175
- // Reset mocks and set up API responses
176
- mockFetch.mockClear();
177
- mockFetch
178
- .mockResolvedValueOnce({
179
- ok: true,
180
- status: 200,
181
- json: () => Promise.resolve(mockResponse),
182
- })
183
- .mockResolvedValueOnce({
184
- ok: true,
185
- status: 200,
186
- json: () => Promise.resolve(mockResponse),
187
- });
188
-
189
- const [call1, call2] = await Promise.all([
190
- client.updateApp({ appId: QB_APP_ID, body: request }),
191
- client.updateApp({ appId: QB_APP_ID, body: request }),
192
- ]);
193
-
194
- expect(mockFetch).toHaveBeenCalledTimes(2);
195
- expect(mockFetch.mock.calls[0][1].headers.Authorization).toBe(
196
- "QB-TEMP-TOKEN token1"
197
- );
198
- expect(mockFetch.mock.calls[1][1].headers.Authorization).toBe(
199
- "QB-TEMP-TOKEN token1"
200
- );
201
- expect(call1).toEqual(mockResponse);
202
- expect(call2).toEqual(mockResponse);
203
- });
204
- });
@@ -1,8 +0,0 @@
1
- // tests/vitest/unit/umd.test.ts
2
- import { test, expect } from "vitest";
3
- const quickbaseUMD = require("../../dist/umd/quickbase.umd.js");
4
- const { quickbase: quickbaseESM } = await import("../../dist/esm/quickbase.js");
5
- test("UMD and ESM builds work in Node.js", () => {
6
- expect(quickbaseUMD).toBeDefined();
7
- expect(quickbaseESM).toBeDefined();
8
- });