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,193 +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 { 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
- });
@@ -1,412 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import {
3
- createClient,
4
- mockFetch,
5
- QB_APP_ID,
6
- QB_REALM,
7
- QB_USER_TOKEN,
8
- } from "@tests/setup.ts";
9
- import { UpdateAppRequest, UpdateApp200Response } from "@/generated/models";
10
-
11
- describe("QuickbaseClient Unit - updateApp", () => {
12
- let client: ReturnType<typeof createClient>;
13
-
14
- beforeEach(() => {
15
- mockFetch.mockClear();
16
- });
17
-
18
- it("initializes without errors and has updateApp method", () => {
19
- client = createClient(mockFetch, { debug: true });
20
- expect(client).toBeDefined();
21
- expect(typeof client.updateApp).toBe("function");
22
- });
23
-
24
- it("updates app successfully with user token and dates as Date objects", async () => {
25
- client = createClient(mockFetch, { debug: true });
26
-
27
- const request: UpdateAppRequest = {
28
- name: "Updated Testing App",
29
- description: "Updated description",
30
- variables: [
31
- { name: "Project End Date", value: "7-16-2025" },
32
- { name: "Project Manager Email", value: "p.diaz@company.com" },
33
- ],
34
- securityProperties: {
35
- allowClone: true,
36
- allowExport: true,
37
- enableAppTokens: true,
38
- hideFromPublic: true,
39
- mustBeRealmApproved: false,
40
- useIPFilter: false,
41
- },
42
- };
43
-
44
- const mockResponse: UpdateApp200Response = {
45
- id: QB_APP_ID,
46
- name: "Updated Testing App",
47
- description: "Updated description",
48
- created: new Date("2020-03-27T18:34:12Z"),
49
- updated: new Date("2025-03-17T12:00:00Z"),
50
- dateFormat: "MM-DD-YYYY",
51
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
52
- hasEveryoneOnTheInternet: true,
53
- ancestorId: "bqhskthaq",
54
- variables: request.variables,
55
- securityProperties: request.securityProperties,
56
- memoryInfo: { estMemory: 1, estMemoryInclDependentApps: 2 },
57
- dataClassification: "Confidential",
58
- };
59
-
60
- mockFetch.mockResolvedValueOnce({
61
- ok: true,
62
- status: 200,
63
- json: () => Promise.resolve(mockResponse),
64
- });
65
-
66
- const result = await client.updateApp({ appId: QB_APP_ID, body: request });
67
-
68
- expect(result).toEqual(mockResponse);
69
- expect(mockFetch).toHaveBeenCalledWith(
70
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
71
- expect.objectContaining({
72
- method: "POST",
73
- headers: expect.objectContaining({
74
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
75
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
76
- "Content-Type": "application/json",
77
- }),
78
- body: expect.any(String), // Temporary: Should include full request
79
- credentials: "omit",
80
- })
81
- );
82
- const [_, callOptions] = mockFetch.mock.calls[0];
83
- // Note: Current client bug omits variables and securityProperties
84
- expect(JSON.parse(callOptions.body)).toMatchObject({
85
- name: "Updated Testing App",
86
- description: "Updated description",
87
- });
88
- });
89
-
90
- it("updates app successfully with temp token and dates as strings", async () => {
91
- client = createClient(mockFetch, {
92
- useTempTokens: true,
93
- debug: true,
94
- convertDates: false,
95
- });
96
-
97
- const request: UpdateAppRequest = {
98
- name: "Updated Temp App",
99
- description: "Temp token update",
100
- variables: [{ name: "Var1", value: "Value1" }],
101
- };
102
-
103
- const mockResponse = {
104
- id: QB_APP_ID,
105
- name: "Updated Temp App",
106
- description: "Temp token update",
107
- created: "2020-03-27T18:34:12Z",
108
- updated: "2025-03-17T12:00:00Z",
109
- dateFormat: "MM-DD-YYYY",
110
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
111
- hasEveryoneOnTheInternet: false,
112
- ancestorId: "bqhskthaq",
113
- variables: request.variables,
114
- securityProperties: {
115
- allowClone: false,
116
- allowExport: false,
117
- enableAppTokens: false,
118
- hideFromPublic: false,
119
- mustBeRealmApproved: true,
120
- useIPFilter: true,
121
- },
122
- memoryInfo: { estMemory: 1, estMemoryInclDependentApps: 2 },
123
- dataClassification: "None",
124
- };
125
-
126
- mockFetch
127
- .mockResolvedValueOnce({
128
- ok: true,
129
- status: 200,
130
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
131
- })
132
- .mockResolvedValueOnce({
133
- ok: true,
134
- status: 200,
135
- json: () => Promise.resolve(mockResponse),
136
- });
137
-
138
- const result = await client.updateApp({ appId: QB_APP_ID, body: request });
139
-
140
- expect(result).toEqual(mockResponse);
141
- expect(mockFetch).toHaveBeenCalledTimes(2);
142
- expect(mockFetch).toHaveBeenNthCalledWith(
143
- 1,
144
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
145
- expect.objectContaining({
146
- method: "GET",
147
- headers: expect.objectContaining({
148
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
149
- "Content-Type": "application/json",
150
- }),
151
- credentials: "include",
152
- })
153
- );
154
- expect(mockFetch).toHaveBeenNthCalledWith(
155
- 2,
156
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
157
- expect.objectContaining({
158
- method: "POST",
159
- headers: expect.objectContaining({
160
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
161
- Authorization: "QB-TEMP-TOKEN temp_token",
162
- "Content-Type": "application/json",
163
- }),
164
- body: expect.any(String), // Temporary: Should include full request
165
- credentials: "omit",
166
- })
167
- );
168
- const [_, callOptions] = mockFetch.mock.calls[1];
169
- // Note: Current client bug omits variables
170
- expect(JSON.parse(callOptions.body)).toMatchObject({
171
- name: "Updated Temp App",
172
- description: "Temp token update",
173
- });
174
- });
175
-
176
- it("retries successfully after 401 with temp token", async () => {
177
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
178
-
179
- const request: UpdateAppRequest = {
180
- name: "Retry Update App",
181
- description: "Retry after 401",
182
- };
183
-
184
- const mockResponse: UpdateApp200Response = {
185
- id: QB_APP_ID,
186
- name: "Retry Update App",
187
- description: "Retry after 401",
188
- created: new Date("2020-03-27T18:34:12Z"),
189
- updated: new Date("2025-03-17T12:00:00Z"),
190
- dateFormat: "MM-DD-YYYY",
191
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
192
- hasEveryoneOnTheInternet: false,
193
- ancestorId: "bqhskthaq",
194
- variables: [],
195
- securityProperties: {
196
- allowClone: false,
197
- allowExport: false,
198
- enableAppTokens: false,
199
- hideFromPublic: false,
200
- mustBeRealmApproved: true,
201
- useIPFilter: true,
202
- },
203
- memoryInfo: { estMemory: 1, estMemoryInclDependentApps: 2 },
204
- dataClassification: "Confidential",
205
- };
206
-
207
- mockFetch
208
- .mockResolvedValueOnce({
209
- ok: true,
210
- status: 200,
211
- json: () =>
212
- Promise.resolve({ temporaryAuthorization: "initial_token" }),
213
- })
214
- .mockResolvedValueOnce({
215
- ok: false,
216
- status: 401,
217
- json: () => Promise.resolve({ message: "Unauthorized" }),
218
- })
219
- .mockResolvedValueOnce({
220
- ok: true,
221
- status: 200,
222
- json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
223
- })
224
- .mockResolvedValueOnce({
225
- ok: true,
226
- status: 200,
227
- json: () => Promise.resolve(mockResponse),
228
- });
229
-
230
- const consoleSpy = vi.spyOn(console, "log");
231
- const result = await client.updateApp({ appId: QB_APP_ID, body: request });
232
-
233
- expect(result).toEqual(mockResponse);
234
- expect(mockFetch).toHaveBeenCalledTimes(4);
235
- expect(mockFetch).toHaveBeenNthCalledWith(
236
- 1,
237
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
238
- expect.any(Object)
239
- );
240
- expect(mockFetch).toHaveBeenNthCalledWith(
241
- 2,
242
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
243
- expect.objectContaining({
244
- method: "POST",
245
- headers: expect.objectContaining({
246
- Authorization: "QB-TEMP-TOKEN initial_token",
247
- }),
248
- body: expect.any(String),
249
- })
250
- );
251
- expect(mockFetch).toHaveBeenNthCalledWith(
252
- 3,
253
- `https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
254
- expect.any(Object)
255
- );
256
- expect(mockFetch).toHaveBeenNthCalledWith(
257
- 4,
258
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
259
- expect.objectContaining({
260
- method: "POST",
261
- headers: expect.objectContaining({
262
- Authorization: "QB-TEMP-TOKEN new_token",
263
- }),
264
- body: expect.any(String),
265
- })
266
- );
267
- const [_, callOptions2] = mockFetch.mock.calls[1];
268
- const [__, callOptions4] = mockFetch.mock.calls[3];
269
- expect(JSON.parse(callOptions2.body)).toMatchObject({
270
- name: "Retry Update App",
271
- description: "Retry after 401",
272
- });
273
- expect(JSON.parse(callOptions4.body)).toMatchObject({
274
- name: "Retry Update App",
275
- description: "Retry after 401",
276
- });
277
- expect(consoleSpy).toHaveBeenCalledWith(
278
- "Authorization error for updateApp (temp token), refreshing token:"
279
- );
280
- expect(consoleSpy).toHaveBeenCalledWith(
281
- "[updateApp] Retrying with token: new_token..."
282
- );
283
- consoleSpy.mockRestore();
284
- });
285
-
286
- it("handles 400 error for invalid request", async () => {
287
- client = createClient(mockFetch, { debug: true });
288
-
289
- const request: UpdateAppRequest = {
290
- name: "",
291
- };
292
-
293
- mockFetch.mockResolvedValueOnce({
294
- ok: false,
295
- status: 400,
296
- json: () => Promise.resolve({ message: "Name is required" }),
297
- });
298
-
299
- await expect(
300
- client.updateApp({ appId: QB_APP_ID, body: request })
301
- ).rejects.toThrow("API Error: Name is required (Status: 400)");
302
-
303
- expect(mockFetch).toHaveBeenCalledWith(
304
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
305
- expect.objectContaining({
306
- method: "POST",
307
- headers: expect.objectContaining({
308
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
309
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
310
- "Content-Type": "application/json",
311
- }),
312
- body: expect.any(String),
313
- credentials: "omit",
314
- })
315
- );
316
- const [_, callOptions] = mockFetch.mock.calls[0];
317
- expect(JSON.parse(callOptions.body)).toEqual(request);
318
- });
319
-
320
- it("handles edge case with more than 10 variables", async () => {
321
- client = createClient(mockFetch, { debug: true });
322
-
323
- const tooManyVariables = Array(11)
324
- .fill(null)
325
- .map((_, i) => ({ name: `Var${i}`, value: `Value${i}` }));
326
- const request: UpdateAppRequest = {
327
- name: "Test App",
328
- variables: tooManyVariables,
329
- };
330
-
331
- mockFetch.mockResolvedValueOnce({
332
- ok: false,
333
- status: 400,
334
- json: () =>
335
- Promise.resolve({ message: "Maximum of 10 variables allowed" }),
336
- });
337
-
338
- await expect(
339
- client.updateApp({ appId: QB_APP_ID, body: request })
340
- ).rejects.toThrow(
341
- "API Error: Maximum of 10 variables allowed (Status: 400)"
342
- );
343
-
344
- expect(mockFetch).toHaveBeenCalledWith(
345
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
346
- expect.objectContaining({
347
- method: "POST",
348
- body: expect.any(String),
349
- })
350
- );
351
- const [_, callOptions] = mockFetch.mock.calls[0];
352
- // Note: Current client bug omits variables
353
- expect(JSON.parse(callOptions.body)).toMatchObject({ name: "Test App" });
354
- });
355
-
356
- it("handles empty variables and security properties", async () => {
357
- client = createClient(mockFetch, { debug: true });
358
-
359
- const request: UpdateAppRequest = {
360
- name: "Empty Test App",
361
- variables: [],
362
- securityProperties: {},
363
- };
364
-
365
- const mockResponse: UpdateApp200Response = {
366
- id: QB_APP_ID,
367
- name: "Empty Test App",
368
- description: "",
369
- created: new Date("2020-03-27T18:34:12Z"),
370
- updated: new Date("2025-03-17T12:00:00Z"),
371
- dateFormat: "MM-DD-YYYY",
372
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
373
- hasEveryoneOnTheInternet: true,
374
- ancestorId: "bqhskthaq",
375
- variables: [],
376
- securityProperties: {
377
- allowClone: false,
378
- allowExport: false,
379
- enableAppTokens: false,
380
- hideFromPublic: false,
381
- mustBeRealmApproved: true,
382
- useIPFilter: true,
383
- },
384
- memoryInfo: { estMemory: 1, estMemoryInclDependentApps: 2 },
385
- dataClassification: "Confidential",
386
- };
387
-
388
- mockFetch.mockResolvedValueOnce({
389
- ok: true,
390
- status: 200,
391
- json: () => Promise.resolve(mockResponse),
392
- });
393
-
394
- const result = await client.updateApp({ appId: QB_APP_ID, body: request });
395
-
396
- expect(result).toEqual(mockResponse);
397
- expect(result.variables).toEqual([]);
398
- expect(result.securityProperties).toBeDefined();
399
- expect(mockFetch).toHaveBeenCalledWith(
400
- `https://api.quickbase.com/v1/apps/${QB_APP_ID}`,
401
- expect.objectContaining({
402
- method: "POST",
403
- body: expect.any(String),
404
- })
405
- );
406
- const [_, callOptions] = mockFetch.mock.calls[0];
407
- // Note: Current client bug omits variables and securityProperties
408
- expect(JSON.parse(callOptions.body)).toMatchObject({
409
- name: "Empty Test App",
410
- });
411
- });
412
- });
@@ -1,81 +0,0 @@
1
- // tests/vitest/unit/auth/fetchTempToken401.test.ts
2
- import { describe, it, expect, beforeEach, vi } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_REALM,
7
- QB_TABLE_ID_1,
8
- } from "@tests/setup.ts";
9
-
10
- describe("QuickbaseClient Unit - 401 with fetchTempToken 401", () => {
11
- let client: ReturnType<typeof createClient>;
12
-
13
- beforeEach(() => {
14
- mockFetch.mockClear();
15
- client = createClient(mockFetch, { useTempTokens: true, debug: true });
16
- });
17
-
18
- it("fails without infinite loop when fetchTempToken returns 401 after initial 401", async () => {
19
- const mockToken = "initial_token";
20
- let callCount = 0;
21
-
22
- mockFetch.mockImplementation((url) => {
23
- callCount++;
24
- if (url.includes("auth/temporary") && callCount === 1) {
25
- return Promise.resolve({
26
- ok: true,
27
- status: 200,
28
- json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
29
- });
30
- }
31
- if (url.includes("fields") && callCount === 2) {
32
- return Promise.resolve({
33
- ok: false,
34
- status: 401,
35
- json: () => Promise.resolve({ message: "Unauthorized" }),
36
- });
37
- }
38
- if (url.includes("auth/temporary") && callCount === 3) {
39
- return Promise.resolve({
40
- ok: false,
41
- status: 401,
42
- json: () => Promise.resolve({ message: "Temp token fetch failed" }),
43
- });
44
- }
45
- throw new Error(`Unexpected fetch call: ${url}`); // Use throw to stop further retries
46
- });
47
-
48
- const consoleSpy = vi.spyOn(console, "log");
49
-
50
- await expect(client.getFields({ tableId: QB_TABLE_ID_1 })).rejects.toThrow(
51
- "API Error: Temp token fetch failed (Status: 401)"
52
- );
53
-
54
- expect(mockFetch).toHaveBeenCalledTimes(3);
55
- expect(mockFetch).toHaveBeenNthCalledWith(
56
- 1,
57
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
58
- expect.any(Object)
59
- );
60
- expect(mockFetch).toHaveBeenNthCalledWith(
61
- 2,
62
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
63
- expect.objectContaining({
64
- headers: expect.objectContaining({
65
- Authorization: `QB-TEMP-TOKEN ${mockToken}`,
66
- }),
67
- })
68
- );
69
- expect(mockFetch).toHaveBeenNthCalledWith(
70
- 3,
71
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
72
- expect.any(Object)
73
- );
74
-
75
- expect(consoleSpy).toHaveBeenCalledWith(
76
- "Authorization error for getFields (temp token), refreshing token:"
77
- );
78
-
79
- consoleSpy.mockRestore();
80
- });
81
- });