quickbase-js 0.1.0-beta.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +270 -60
  2. package/dist/esm/quickbase.d.ts +2553 -3220
  3. package/dist/esm/quickbase.js +1545 -3443
  4. package/dist/esm/quickbase.js.map +1 -1
  5. package/dist/esm/quickbase.min.js +1 -1
  6. package/dist/esm/quickbase.min.js.map +1 -1
  7. package/dist/umd/quickbase.umd.js +1544 -3625
  8. package/dist/umd/quickbase.umd.js.map +1 -1
  9. package/dist/umd/quickbase.umd.min.js +1 -1
  10. package/dist/umd/quickbase.umd.min.js.map +1 -1
  11. package/package.json +25 -12
  12. package/CHANGELOG.md +0 -184
  13. package/build-common.js +0 -131
  14. package/build-esm.js +0 -71
  15. package/build-umd.js +0 -69
  16. package/examples/quicbase-jsCDN.html +0 -36
  17. package/examples/react.js +0 -48
  18. package/examples/vanillajs.html +0 -47
  19. package/open-api/fix-spec-main.ts +0 -97
  20. package/open-api/generate-override-report.ts +0 -214
  21. package/open-api/generate-unified-interface.ts +0 -336
  22. package/open-api/output/override-report.html +0 -11
  23. package/open-api/output/override-report.json +0 -14395
  24. package/open-api/output/quickbase-fixed.json +0 -11191
  25. package/open-api/regenerate-client.ts +0 -116
  26. package/open-api/schema/enhance-general.ts +0 -100
  27. package/open-api/schema/fix-arrays.ts +0 -69
  28. package/open-api/schema/tags/apps.ts +0 -90
  29. package/open-api/schema/tags/fields.ts +0 -471
  30. package/open-api/schema/tags/groups.ts +0 -51
  31. package/open-api/schema/tags/index.ts +0 -66
  32. package/open-api/schema/tags/records.ts +0 -115
  33. package/open-api/schema/tags/tables.ts +0 -211
  34. package/open-api/schema/tags/users.ts +0 -47
  35. package/open-api/types/spec.ts +0 -42
  36. package/open-api/utils/generateJsDoc.ts +0 -96
  37. package/open-api/utils/infer-schema.ts +0 -40
  38. package/open-api/utils/naming.ts +0 -10
  39. package/playwright.config.ts +0 -37
  40. package/rollup.config.js +0 -114
  41. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  42. package/specs/split/apps.json +0 -1315
  43. package/specs/split/auth.json +0 -191
  44. package/specs/split/fields.json +0 -3869
  45. package/specs/split/records.json +0 -754
  46. package/specs/split/reports.json +0 -619
  47. package/specs/split/tables.json +0 -1605
  48. package/src/RateLimitError.ts +0 -12
  49. package/src/ThrottleBucket.ts +0 -41
  50. package/src/authorizationStrategy.ts +0 -246
  51. package/src/generated-unified/QuickbaseClient.ts +0 -1049
  52. package/src/generated-unified/missing-types-report.json +0 -3
  53. package/src/index.ts +0 -1
  54. package/src/invokeMethod.ts +0 -242
  55. package/src/quickbaseClient.ts +0 -271
  56. package/src/rateLimiter.ts +0 -25
  57. package/src/tokenCache.ts +0 -35
  58. package/src/utils.ts +0 -7
  59. package/test-esm.js +0 -1
  60. package/test-results.json +0 -2050
  61. package/test-umd.js +0 -1
  62. package/test.ts +0 -1
  63. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  64. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  65. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  66. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  67. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  68. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  69. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  70. package/tests/setup.ts +0 -53
  71. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  72. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  73. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  74. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  75. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  76. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  77. package/tests/vitest/qb/auth/mockQuickbaseServer.ts +0 -60
  78. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -73
  79. package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +0 -65
  80. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  81. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  82. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  83. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -82
  84. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  85. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  86. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  87. package/tests/vitest/qb/formulas/runFormula.test.ts +0 -96
  88. package/tests/vitest/qb/index.ts +0 -29
  89. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  90. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  91. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  92. package/tests/vitest/qb/tables/createRelationship.test.ts +0 -102
  93. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  94. package/tests/vitest/qb/tables/deleteRelationship.test.ts +0 -143
  95. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  96. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  97. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  98. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  99. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -250
  100. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  101. package/tests/vitest/unit/ThrottleBucket.test.ts +0 -95
  102. package/tests/vitest/unit/apps/copyApp.test.ts +0 -581
  103. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  104. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  105. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  106. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  107. package/tests/vitest/unit/apps/updateApp.test.ts +0 -412
  108. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -63
  109. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -119
  110. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -95
  111. package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +0 -235
  112. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -69
  113. package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +0 -325
  114. package/tests/vitest/unit/fields/createField.test.ts +0 -451
  115. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  116. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  117. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -180
  118. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  119. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  120. package/tests/vitest/unit/fields/updateField.test.ts +0 -285
  121. package/tests/vitest/unit/formulas/runFormula.test.ts +0 -205
  122. package/tests/vitest/unit/index.ts +0 -34
  123. package/tests/vitest/unit/inferHttpMethod.test.ts +0 -131
  124. package/tests/vitest/unit/rateLimit.test.ts +0 -191
  125. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  126. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  127. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  128. package/tests/vitest/unit/tables/createRelationship.test.ts +0 -212
  129. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  130. package/tests/vitest/unit/tables/deleteRelationship.test.ts +0 -97
  131. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  132. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  133. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  134. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  135. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -307
  136. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  137. package/tests/vitest/unit/tokenLifespan.test.ts +0 -204
  138. package/tests/vitest/unit/umd.test.ts +0 -8
  139. package/text.txt +0 -104
  140. package/tools/log-gen.ts +0 -244
  141. package/tools/log-gen.yaml +0 -5424
  142. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  143. package/tsconfig.build.json +0 -17
  144. package/tsconfig.json +0 -32
  145. package/versionrc.json +0 -9
  146. package/vitest.config.ts +0 -27
@@ -1,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,63 +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
- return Promise.reject(new Error(`Unexpected fetch call: ${url}`));
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
-
56
- // Updated to match the single-argument log from handleError
57
- expect(consoleSpy).toHaveBeenCalledWith(
58
- "Authorization error for getFields (temp token), refreshing token:"
59
- );
60
-
61
- consoleSpy.mockRestore();
62
- });
63
- });