quickbase-js 0.1.0-beta.7 → 0.1.0-beta.8

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 (60) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/esm/quickbase.d.ts +589 -125
  3. package/dist/esm/quickbase.js +484 -145
  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 +492 -144
  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/open-api/fix-spec-main.ts +69 -68
  12. package/open-api/generate-override-report.ts +214 -0
  13. package/open-api/generate-unified-interface.ts +73 -94
  14. package/open-api/output/override-report.html +11 -0
  15. package/open-api/output/override-report.json +14395 -58
  16. package/open-api/output/quickbase-fixed.json +583 -2
  17. package/open-api/schema/tags/fields.ts +331 -16
  18. package/open-api/schema/tags/index.ts +2 -4
  19. package/open-api/types/spec.ts +2 -1
  20. package/package.json +31 -33
  21. package/src/RateLimitError.ts +12 -0
  22. package/src/ThrottleBucket.ts +36 -0
  23. package/src/generated-unified/QuickbaseClient.ts +119 -119
  24. package/src/invokeMethod.ts +357 -0
  25. package/src/quickbaseClient.ts +51 -209
  26. package/tests/setup.ts +2 -0
  27. package/tests/vitest/qb/apps/getApp.test.ts +6 -2
  28. package/tests/vitest/qb/apps/getAppEvents.test.ts +67 -0
  29. package/tests/vitest/qb/apps/updateApp.test.ts +58 -0
  30. package/tests/vitest/qb/auth/retryUserToken401.test.ts +56 -0
  31. package/tests/vitest/qb/fields/createField.test.ts +1 -2
  32. package/tests/vitest/qb/fields/deleteFields.test.ts +10 -16
  33. package/tests/vitest/qb/fields/updateField.test.ts +93 -0
  34. package/tests/vitest/qb/index.ts +1 -0
  35. package/tests/vitest/qb/tables/updateRelationship.test.ts +277 -0
  36. package/tests/vitest/unit/apps/getAppEvents.test.ts +193 -0
  37. package/tests/vitest/unit/apps/updateApp.test.ts +381 -0
  38. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +6 -26
  39. package/tests/vitest/unit/auth/{retryOn401.test.ts → retryTempToken401.test.ts} +3 -6
  40. package/tests/vitest/unit/auth/{two401s.test.ts → retryTempTokenTwo401.test.ts} +4 -9
  41. package/tests/vitest/unit/auth/retryUserToken401.test.ts +56 -0
  42. package/tests/vitest/unit/fields/createField.test.ts +8 -12
  43. package/tests/vitest/unit/fields/getFieldUsage.test.ts +33 -14
  44. package/tests/vitest/unit/fields/updateField.test.ts +280 -0
  45. package/tests/vitest/unit/rateLimit.test.ts +189 -0
  46. package/tests/vitest/unit/tables/updateRelationship.test.ts +305 -0
  47. package/tests/vitest/unit/tokenLifespan.test.ts +138 -0
  48. package/tools/log-gen.ts +8 -4
  49. package/tools/log-gen.yaml +3004 -1848
  50. package/tsconfig.json +5 -2
  51. package/vitest.config.ts +2 -2
  52. package/notes.txt +0 -158
  53. package/tools/generate-types.ts +0 -29
  54. package/tools/openapi-schema-validator.ts +0 -38
  55. package/tools/spec-analyzer.ts +0 -163
  56. package/tools/split-spec.ts +0 -148
  57. package/tools/test-import.ts +0 -3
  58. package/tools/validate-spec.ts +0 -40
  59. /package/tests/playwright/qb/auth/{tokenPrefetch.test.ts → tempTokenPrefetch.test.ts} +0 -0
  60. /package/tests/playwright/qb/auth/{tokenRenewal.test.ts → tempTokenRenewal.test.ts} +0 -0
@@ -0,0 +1,193 @@
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 { GetAppEvents200Response } from "@/generated/models";
10
+
11
+ describe("QuickbaseClient Unit - getAppEvents", () => {
12
+ let client: ReturnType<typeof createClient>;
13
+
14
+ beforeEach(() => {
15
+ mockFetch.mockClear();
16
+ });
17
+
18
+ it("initializes and has getAppEvents method", () => {
19
+ client = createClient(mockFetch, { debug: true });
20
+ expect(client).toBeDefined();
21
+ expect(typeof client.getAppEvents).toBe("function");
22
+ });
23
+
24
+ it("fetches app events successfully with user token", async () => {
25
+ client = createClient(mockFetch, {
26
+ realm: QB_REALM,
27
+ userToken: QB_USER_TOKEN,
28
+ debug: true,
29
+ });
30
+
31
+ const mockResponse: GetAppEvents200Response = [
32
+ {
33
+ type: "qb-action",
34
+ owner: {
35
+ email: "jsmith@quickbase.com",
36
+ id: "123456.ab1s",
37
+ name: "Juliet Smith",
38
+ userName: "jsmith",
39
+ },
40
+ isActive: true,
41
+ tableId: "bqwriv8bw",
42
+ name: "Quick Base Action",
43
+ },
44
+ {
45
+ type: "webhook",
46
+ owner: {
47
+ email: "tanderson@quickbase.com",
48
+ id: "654321.ab1s",
49
+ name: "Thomas A. Anderson",
50
+ userName: "tanderson",
51
+ },
52
+ isActive: false,
53
+ tableId: "bqwriv8bw",
54
+ name: "Webhook",
55
+ },
56
+ {
57
+ type: "email-notification",
58
+ owner: {
59
+ email: "jsmith@quickbase.com",
60
+ id: "123456.ab1s",
61
+ name: "Juliet Smith",
62
+ userName: "jsmith",
63
+ },
64
+ isActive: false,
65
+ tableId: "bqwriv8bw",
66
+ name: "Notification",
67
+ },
68
+ {
69
+ type: "subscription",
70
+ owner: {
71
+ email: "tanderson@quickbase.com",
72
+ id: "654321.ab1s",
73
+ name: "Thomas A. Anderson",
74
+ userName: "tanderson",
75
+ },
76
+ isActive: true,
77
+ tableId: "bqwriv8bw",
78
+ name: "Subscription",
79
+ },
80
+ {
81
+ type: "reminder",
82
+ owner: {
83
+ email: "jsmith@quickbase.com",
84
+ id: "123456.ab1s",
85
+ name: "Juliet Smith",
86
+ userName: "jsmith",
87
+ },
88
+ isActive: true,
89
+ tableId: "bqwriv8bw",
90
+ name: "Reminder",
91
+ },
92
+ {
93
+ type: "automation",
94
+ owner: {
95
+ email: "tanderson@quickbase.com",
96
+ id: "654321.ab1s",
97
+ name: "Thomas A. Anderson",
98
+ userName: "tanderson",
99
+ },
100
+ isActive: true,
101
+ tableId: "bqwriv8bw",
102
+ url: "https://realm.quickbase.com/ui/automation/qb/db/bqwria893/automations/70eecab9-634f-42d9-9037-9340a1a9e8ce",
103
+ },
104
+ ];
105
+
106
+ mockFetch.mockResolvedValueOnce({
107
+ ok: true,
108
+ status: 200,
109
+ json: () => Promise.resolve(mockResponse),
110
+ });
111
+
112
+ const result = await client.getAppEvents({ appId: QB_APP_ID });
113
+
114
+ expect(result).toEqual(mockResponse);
115
+ expect(mockFetch).toHaveBeenCalledWith(
116
+ `https://api.quickbase.com/v1/apps/${QB_APP_ID}/events`,
117
+ expect.objectContaining({
118
+ method: "GET",
119
+ headers: expect.objectContaining({
120
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
121
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
122
+ "Content-Type": "application/json",
123
+ }),
124
+ credentials: "omit",
125
+ })
126
+ );
127
+ });
128
+
129
+ it("fetches app events successfully with temp token", async () => {
130
+ client = createClient(mockFetch, {
131
+ realm: QB_REALM,
132
+ useTempTokens: true,
133
+ debug: true,
134
+ });
135
+
136
+ const mockResponse: GetAppEvents200Response = [
137
+ {
138
+ type: "webhook",
139
+ owner: {
140
+ email: "tanderson@quickbase.com",
141
+ id: "654321.ab1s",
142
+ name: "Thomas A. Anderson",
143
+ userName: "tanderson",
144
+ },
145
+ isActive: false,
146
+ tableId: "bqwriv8bw",
147
+ name: "Webhook",
148
+ },
149
+ ];
150
+
151
+ mockFetch
152
+ .mockResolvedValueOnce({
153
+ ok: true,
154
+ status: 200,
155
+ json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
156
+ })
157
+ .mockResolvedValueOnce({
158
+ ok: true,
159
+ status: 200,
160
+ json: () => Promise.resolve(mockResponse),
161
+ });
162
+
163
+ const result = await client.getAppEvents({ appId: QB_APP_ID });
164
+
165
+ expect(result).toEqual(mockResponse);
166
+ expect(mockFetch).toHaveBeenCalledTimes(2);
167
+ expect(mockFetch).toHaveBeenNthCalledWith(
168
+ 1,
169
+ `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
170
+ expect.objectContaining({
171
+ method: "GET",
172
+ headers: expect.objectContaining({
173
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
174
+ "Content-Type": "application/json",
175
+ }),
176
+ credentials: "include",
177
+ })
178
+ );
179
+ expect(mockFetch).toHaveBeenNthCalledWith(
180
+ 2,
181
+ `https://api.quickbase.com/v1/apps/${QB_APP_ID}/events`,
182
+ expect.objectContaining({
183
+ method: "GET",
184
+ headers: expect.objectContaining({
185
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
186
+ Authorization: "QB-TEMP-TOKEN temp_token",
187
+ "Content-Type": "application/json",
188
+ }),
189
+ credentials: "omit",
190
+ })
191
+ );
192
+ });
193
+ });
@@ -0,0 +1,381 @@
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,4 +1,3 @@
1
- // tests/vitest/unit/auth/fetchTempToken401.test.ts
2
1
  import { describe, it, expect, beforeEach, vi } from "vitest";
3
2
  import {
4
3
  createClient,
@@ -16,6 +15,7 @@ describe("QuickbaseClient Unit - 401 with fetchTempToken 401", () => {
16
15
  });
17
16
 
18
17
  it("fails without infinite loop when fetchTempToken returns 401 after initial 401", async () => {
18
+ const mockToken = "initial_token";
19
19
  let callCount = 0;
20
20
 
21
21
  mockFetch.mockImplementation((url) => {
@@ -24,8 +24,7 @@ describe("QuickbaseClient Unit - 401 with fetchTempToken 401", () => {
24
24
  return Promise.resolve({
25
25
  ok: true,
26
26
  status: 200,
27
- json: () =>
28
- Promise.resolve({ temporaryAuthorization: "initial_token" }),
27
+ json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
29
28
  });
30
29
  }
31
30
  if (url.includes("fields") && callCount === 2) {
@@ -39,8 +38,7 @@ describe("QuickbaseClient Unit - 401 with fetchTempToken 401", () => {
39
38
  return Promise.resolve({
40
39
  ok: false,
41
40
  status: 401,
42
- json: () =>
43
- Promise.resolve({ message: "Unauthorized in fetchTempToken" }),
41
+ json: () => Promise.resolve({ message: "Temp token fetch failed" }),
44
42
  });
45
43
  }
46
44
  return Promise.reject(new Error(`Unexpected fetch call: ${url}`));
@@ -49,34 +47,16 @@ describe("QuickbaseClient Unit - 401 with fetchTempToken 401", () => {
49
47
  const consoleSpy = vi.spyOn(console, "log");
50
48
 
51
49
  await expect(client.getFields({ tableId: QB_TABLE_ID_1 })).rejects.toThrow(
52
- "API Error: Unauthorized in fetchTempToken (Status: 401)"
50
+ "API Error: Temp token fetch failed (Status: 401)"
53
51
  );
54
52
 
55
53
  expect(mockFetch).toHaveBeenCalledTimes(3);
56
- expect(mockFetch).toHaveBeenNthCalledWith(
57
- 1,
58
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
59
- expect.any(Object)
60
- );
61
- expect(mockFetch).toHaveBeenNthCalledWith(
62
- 2,
63
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
64
- expect.objectContaining({
65
- headers: expect.objectContaining({
66
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
67
- }),
68
- })
69
- );
70
- expect(mockFetch).toHaveBeenNthCalledWith(
71
- 3,
72
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
73
- expect.any(Object)
74
- );
75
54
 
76
55
  expect(consoleSpy).toHaveBeenCalledWith(
77
- "Authorization error for getFields, refreshing token:",
56
+ "Authorization error for getFields (temp token), refreshing token:",
78
57
  expect.any(String)
79
58
  );
59
+
80
60
  consoleSpy.mockRestore();
81
61
  });
82
62
  });
@@ -1,4 +1,3 @@
1
- // tests/vitest/unit/auth/retryOn401.test.ts
2
1
  import { describe, it, expect, beforeEach, vi } from "vitest";
3
2
  import {
4
3
  createClient,
@@ -7,7 +6,7 @@ import {
7
6
  QB_TABLE_ID_1,
8
7
  } from "@tests/setup.ts";
9
8
 
10
- describe("QuickbaseClient Unit - 401 Retry Creates New Token", () => {
9
+ describe("QuickbaseClient Unit - Temp Token Retry on 401", () => {
11
10
  let client: ReturnType<typeof createClient>;
12
11
 
13
12
  beforeEach(() => {
@@ -20,7 +19,6 @@ describe("QuickbaseClient Unit - 401 Retry Creates New Token", () => {
20
19
  const mockFields = [{ id: 1, label: "Field1" }];
21
20
  let callCount = 0;
22
21
 
23
- // Mock fetch without console.log interference
24
22
  mockFetch.mockImplementation((url) => {
25
23
  callCount++;
26
24
  if (url.includes("auth/temporary") && callCount === 1) {
@@ -90,7 +88,6 @@ describe("QuickbaseClient Unit - 401 Retry Creates New Token", () => {
90
88
  })
91
89
  );
92
90
 
93
- // Filter console logs to only those we care about
94
91
  const tokenLogs = consoleSpy.mock.calls.filter((call) =>
95
92
  call[0].includes("Fetched and cached new token")
96
93
  );
@@ -104,11 +101,11 @@ describe("QuickbaseClient Unit - 401 Retry Creates New Token", () => {
104
101
  ]);
105
102
 
106
103
  expect(consoleSpy).toHaveBeenCalledWith(
107
- "Authorization error for getFields, refreshing token:",
104
+ "Authorization error for getFields (temp token), refreshing token:",
108
105
  expect.any(String)
109
106
  );
110
107
  expect(consoleSpy).toHaveBeenCalledWith(
111
- "Retrying getFields with new token"
108
+ "Retrying getFields with temp token"
112
109
  );
113
110
 
114
111
  consoleSpy.mockRestore();