quickbase-js 0.1.0-beta.8 → 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 (132) hide show
  1. package/README.md +252 -126
  2. package/dist/esm/quickbase.d.ts +2725 -2689
  3. package/dist/esm/quickbase.js +1763 -3524
  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 +1762 -3706
  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 +27 -12
  12. package/CHANGELOG.md +0 -155
  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 -256
  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/infer-schema.ts +0 -40
  37. package/open-api/utils/naming.ts +0 -10
  38. package/playwright.config.ts +0 -37
  39. package/rollup.config.js +0 -114
  40. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  41. package/specs/split/apps.json +0 -1315
  42. package/specs/split/auth.json +0 -191
  43. package/specs/split/fields.json +0 -3869
  44. package/specs/split/records.json +0 -754
  45. package/specs/split/reports.json +0 -619
  46. package/specs/split/tables.json +0 -1605
  47. package/src/RateLimitError.ts +0 -12
  48. package/src/ThrottleBucket.ts +0 -36
  49. package/src/generated-unified/QuickbaseClient.ts +0 -359
  50. package/src/generated-unified/missing-types-report.json +0 -3
  51. package/src/index.ts +0 -1
  52. package/src/invokeMethod.ts +0 -357
  53. package/src/quickbaseClient.ts +0 -244
  54. package/src/tokenCache.ts +0 -51
  55. package/src/utils.ts +0 -7
  56. package/test-esm.js +0 -1
  57. package/test-results.json +0 -2050
  58. package/test-umd.js +0 -1
  59. package/test.ts +0 -1
  60. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  61. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  62. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  63. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  64. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  65. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  66. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  67. package/tests/setup.ts +0 -53
  68. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  69. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  70. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  71. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  72. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  73. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  74. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -56
  75. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  76. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  77. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  78. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -174
  79. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  80. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  81. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  82. package/tests/vitest/qb/index.ts +0 -29
  83. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  84. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  85. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  86. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  87. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  88. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  89. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  90. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  91. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -277
  92. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  93. package/tests/vitest/unit/apps/copyApp.test.ts +0 -488
  94. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  95. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  96. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  97. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  98. package/tests/vitest/unit/apps/updateApp.test.ts +0 -381
  99. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -62
  100. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -95
  101. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -113
  102. package/tests/vitest/unit/auth/retryTempTokenTwo401.test.ts +0 -81
  103. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -56
  104. package/tests/vitest/unit/fields/createField.test.ts +0 -387
  105. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  106. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  107. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -166
  108. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  109. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  110. package/tests/vitest/unit/fields/updateField.test.ts +0 -280
  111. package/tests/vitest/unit/index.ts +0 -33
  112. package/tests/vitest/unit/rateLimit.test.ts +0 -189
  113. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  114. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  115. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  116. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  117. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  118. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  119. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  120. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  121. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -305
  122. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  123. package/tests/vitest/unit/tokenLifespan.test.ts +0 -138
  124. package/tests/vitest/unit/umd.test.ts +0 -8
  125. package/text.txt +0 -104
  126. package/tools/log-gen.ts +0 -235
  127. package/tools/log-gen.yaml +0 -4982
  128. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  129. package/tsconfig.build.json +0 -17
  130. package/tsconfig.json +0 -32
  131. package/versionrc.json +0 -9
  132. package/vitest.config.ts +0 -27
@@ -1,280 +0,0 @@
1
- // tests/vitest/unit/fields/updateField.test.ts
2
- import { describe, it, expect, beforeEach } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_APP_ID,
7
- QB_REALM,
8
- QB_USER_TOKEN,
9
- QB_TABLE_ID_1,
10
- } from "@tests/setup.ts";
11
- import { UpdateFieldRequest, UpdateField200Response } from "@/generated/models";
12
-
13
- describe("QuickbaseClient Unit - updateField", () => {
14
- let client: ReturnType<typeof createClient>;
15
-
16
- beforeEach(() => {
17
- mockFetch.mockClear();
18
- });
19
-
20
- it("initializes and has updateField method", () => {
21
- client = createClient(mockFetch, { debug: true });
22
- expect(client).toBeDefined();
23
- expect(typeof client.updateField).toBe("function");
24
- });
25
-
26
- it("updates field successfully with user token", async () => {
27
- client = createClient(mockFetch, {
28
- realm: QB_REALM,
29
- userToken: QB_USER_TOKEN,
30
- debug: true,
31
- });
32
-
33
- const tableId = QB_TABLE_ID_1;
34
- const fieldId = 123;
35
-
36
- const request: UpdateFieldRequest = {
37
- label: "Field1",
38
- // fieldType omitted as it’s not allowed in updates
39
- noWrap: false,
40
- bold: false,
41
- required: true,
42
- appearsByDefault: false,
43
- findEnabled: false,
44
- unique: true,
45
- fieldHelp: "field help",
46
- addToForms: true,
47
- properties: {
48
- numLines: 1,
49
- maxLength: 50,
50
- appendOnly: true,
51
- sortAsGiven: false,
52
- allowMentions: false,
53
- comments: "Updated field settings",
54
- doesTotal: false,
55
- defaultValue: "Initial text",
56
- choices: ["Option1", "Option2"], // Still valid for properties
57
- },
58
- permissions: [
59
- { role: "Viewer", permissionType: "View", roleId: 10 },
60
- { role: "Participant", permissionType: "None", roleId: 11 },
61
- { role: "Administrator", permissionType: "Modify", roleId: 12 },
62
- ],
63
- };
64
-
65
- const mockResponse: UpdateField200Response = {
66
- id: fieldId,
67
- label: "Field1",
68
- fieldType: "text", // Returned by API, not updated
69
- mode: "",
70
- noWrap: false,
71
- bold: false,
72
- required: true,
73
- appearsByDefault: false,
74
- findEnabled: false,
75
- unique: true,
76
- doesDataCopy: false,
77
- fieldHelp: "field help",
78
- audited: false,
79
- properties: {
80
- numLines: 1,
81
- maxLength: 50,
82
- appendOnly: true,
83
- sortAsGiven: false,
84
- allowMentions: false,
85
- comments: "Updated field settings",
86
- doesTotal: false,
87
- defaultValue: "Initial text",
88
- choices: ["Option1", "Option2"],
89
- allowHTML: false,
90
- carryChoices: true,
91
- allowNewChoices: false,
92
- formula: "",
93
- },
94
- permissions: [
95
- { permissionType: "View", role: "Viewer", roleId: 10 },
96
- { permissionType: "None", role: "Participant", roleId: 11 },
97
- { permissionType: "Modify", role: "Administrator", roleId: 12 },
98
- ],
99
- };
100
-
101
- mockFetch.mockResolvedValueOnce({
102
- ok: true,
103
- status: 200,
104
- json: () => Promise.resolve(mockResponse),
105
- });
106
-
107
- const result = await client.updateField({
108
- fieldId,
109
- tableId,
110
- body: request,
111
- });
112
-
113
- expect(result).toEqual(mockResponse);
114
- expect(mockFetch).toHaveBeenCalledWith(
115
- `https://api.quickbase.com/v1/fields/${fieldId}?tableId=${tableId}`,
116
- expect.objectContaining({
117
- method: "POST",
118
- headers: expect.objectContaining({
119
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
120
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
121
- "Content-Type": "application/json",
122
- }),
123
- body: JSON.stringify(request),
124
- credentials: "omit",
125
- })
126
- );
127
- });
128
-
129
- it("updates field successfully with temp token", async () => {
130
- client = createClient(mockFetch, {
131
- realm: QB_REALM,
132
- useTempTokens: true,
133
- debug: true,
134
- });
135
-
136
- const tableId = QB_TABLE_ID_1;
137
- const fieldId = 123;
138
-
139
- const request: UpdateFieldRequest = {
140
- label: "Field1",
141
- // fieldType omitted as it’s not allowed in updates
142
- required: true,
143
- unique: true,
144
- properties: {
145
- numLines: 1,
146
- maxLength: 0,
147
- choices: ["Yes", "No"],
148
- allowNewChoices: true,
149
- defaultValue: "No",
150
- },
151
- };
152
-
153
- const mockResponse: UpdateField200Response = {
154
- id: fieldId,
155
- label: "Field1",
156
- fieldType: "text-multiple-choice", // Returned by API, not updated
157
- mode: "",
158
- noWrap: false,
159
- bold: false,
160
- required: true,
161
- appearsByDefault: false,
162
- findEnabled: false,
163
- unique: true,
164
- doesDataCopy: false,
165
- fieldHelp: "",
166
- audited: false,
167
- properties: {
168
- numLines: 1,
169
- maxLength: 0,
170
- choices: ["Yes", "No"],
171
- allowNewChoices: true,
172
- defaultValue: "No",
173
- appendOnly: false,
174
- allowHTML: false,
175
- allowMentions: false,
176
- sortAsGiven: false,
177
- carryChoices: true,
178
- formula: "",
179
- },
180
- permissions: [
181
- { permissionType: "View", role: "Viewer", roleId: 10 },
182
- { permissionType: "None", role: "Participant", roleId: 11 },
183
- { permissionType: "Modify", role: "Administrator", roleId: 12 },
184
- ],
185
- };
186
-
187
- mockFetch
188
- .mockResolvedValueOnce({
189
- ok: true,
190
- status: 200,
191
- json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
192
- })
193
- .mockResolvedValueOnce({
194
- ok: true,
195
- status: 200,
196
- json: () => Promise.resolve(mockResponse),
197
- });
198
-
199
- const result = await client.updateField({
200
- fieldId,
201
- tableId,
202
- body: request,
203
- });
204
-
205
- expect(result).toEqual(mockResponse);
206
- expect(mockFetch).toHaveBeenCalledTimes(2);
207
- expect(mockFetch).toHaveBeenNthCalledWith(
208
- 1,
209
- `https://api.quickbase.com/v1/auth/temporary/${tableId}`,
210
- expect.objectContaining({
211
- method: "GET",
212
- headers: expect.objectContaining({
213
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
214
- "Content-Type": "application/json",
215
- }),
216
- credentials: "include",
217
- })
218
- );
219
- expect(mockFetch).toHaveBeenNthCalledWith(
220
- 2,
221
- `https://api.quickbase.com/v1/fields/${fieldId}?tableId=${tableId}`,
222
- expect.objectContaining({
223
- method: "POST",
224
- headers: expect.objectContaining({
225
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
226
- Authorization: "QB-TEMP-TOKEN temp_token",
227
- "Content-Type": "application/json",
228
- }),
229
- body: JSON.stringify(request),
230
- credentials: "omit",
231
- })
232
- );
233
- });
234
-
235
- it("handles 400 error for invalid field update", async () => {
236
- client = createClient(mockFetch, {
237
- realm: QB_REALM,
238
- userToken: QB_USER_TOKEN,
239
- debug: true,
240
- });
241
-
242
- const tableId = QB_TABLE_ID_1;
243
- const fieldId = 999;
244
-
245
- const request: UpdateFieldRequest = {
246
- label: "InvalidField",
247
- // fieldType omitted as it’s not allowed in updates
248
- required: true,
249
- properties: {
250
- numLines: 1,
251
- decimalPlaces: 2,
252
- currencySymbol: "$",
253
- },
254
- };
255
-
256
- mockFetch.mockResolvedValueOnce({
257
- ok: false,
258
- status: 400,
259
- json: () => Promise.resolve({ message: "Invalid field ID" }),
260
- });
261
-
262
- await expect(
263
- client.updateField({ fieldId, tableId, body: request })
264
- ).rejects.toThrow("API Error: Invalid field ID (Status: 400)");
265
-
266
- expect(mockFetch).toHaveBeenCalledWith(
267
- `https://api.quickbase.com/v1/fields/${fieldId}?tableId=${tableId}`,
268
- expect.objectContaining({
269
- method: "POST",
270
- headers: expect.objectContaining({
271
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
272
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
273
- "Content-Type": "application/json",
274
- }),
275
- body: JSON.stringify(request),
276
- credentials: "omit",
277
- })
278
- );
279
- });
280
- });
@@ -1,33 +0,0 @@
1
- // tests/vitest/unit/index.ts
2
- // Apps
3
- export * from "./apps/copyApp.test.ts";
4
- export * from "./apps/createApp.test.ts";
5
- export * from "./apps/deleteApp.test.ts";
6
- export * from "./apps/getApp.test.ts";
7
-
8
- // Auth
9
- export * from "./auth/fetchTempToken401.test.ts";
10
- export * from "./auth/getTempToken.test.ts";
11
- export * from "./auth/retryOn401.test.ts";
12
- export * from "./auth/two401s.test.ts";
13
-
14
- // Fields
15
- export * from "./fields/getFields.test.ts";
16
- export * from "./fields/getField.test.ts";
17
- export * from "./fields/createField.test.ts";
18
- export * from "./fields/deleteFields.test.ts";
19
- export * from "./fields/getFieldsUsage.test.ts";
20
- export * from "./fields/getFieldUsage.test.ts";
21
-
22
- // Records
23
- export * from "./records/deleteRecords.test.ts";
24
- export * from "./records/runQuery.test.ts";
25
- export * from "./records/upsert.test.ts";
26
-
27
- // Tables
28
- export * from "./tables/createTable.test.ts";
29
- export * from "./tables/deleteTable.test.ts";
30
- export * from "./tables/getAppTables.test.ts";
31
- export * from "./tables/getRelationships.test.ts";
32
- export * from "./tables/getTable.test.ts";
33
- export * from "./tables/updateTable.test.ts";
@@ -1,189 +0,0 @@
1
- // tests/vitest/unit/rateLimit.test.ts
2
- import { describe, it, expect, beforeEach } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_APP_ID,
7
- QB_REALM,
8
- QB_USER_TOKEN,
9
- } from "@tests/setup.ts";
10
- import { RateLimitError } from "@/RateLimitError";
11
- import { GetApp200Response } from "@/generated/models";
12
-
13
- describe("QuickbaseClient Unit - Rate Limit Handling", () => {
14
- let client: ReturnType<typeof createClient>;
15
-
16
- beforeEach(() => {
17
- mockFetch.mockClear();
18
- });
19
-
20
- it("succeeds after retrying on 429 Too Many Requests", async () => {
21
- client = createClient(mockFetch, {
22
- realm: QB_REALM,
23
- userToken: QB_USER_TOKEN,
24
- debug: true,
25
- maxRetries: 2,
26
- retryDelay: 100,
27
- throttle: { rate: 10, burst: 10 },
28
- });
29
-
30
- const appId = QB_APP_ID;
31
-
32
- const mockResponse: GetApp200Response = {
33
- id: appId,
34
- name: "TestApp",
35
- created: "2025-01-01T00:00:00Z",
36
- updated: "2025-01-02T00:00:00Z",
37
- description: "Test app",
38
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
39
- dateFormat: "MM-DD-YYYY",
40
- hasEveryoneOnTheInternet: false,
41
- memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
42
- securityProperties: {
43
- allowClone: false,
44
- allowExport: true,
45
- enableAppTokens: true,
46
- hideFromPublic: false,
47
- mustBeRealmApproved: false,
48
- useIPFilter: false,
49
- },
50
- };
51
-
52
- mockFetch
53
- .mockResolvedValueOnce({
54
- ok: false,
55
- status: 429,
56
- headers: new Headers({ "Retry-After": "1" }),
57
- json: () => Promise.resolve({ message: "Too Many Requests" }),
58
- })
59
- .mockResolvedValueOnce({
60
- ok: true,
61
- status: 200,
62
- json: () => Promise.resolve(mockResponse),
63
- });
64
-
65
- const result = await client.getApp({ appId });
66
-
67
- expect(result).toEqual({
68
- ...mockResponse,
69
- created: new Date("2025-01-01T00:00:00Z"),
70
- updated: new Date("2025-01-02T00:00:00Z"),
71
- });
72
- expect(mockFetch).toHaveBeenCalledTimes(2);
73
- expect(mockFetch).toHaveBeenNthCalledWith(
74
- 1,
75
- `https://api.quickbase.com/v1/apps/${appId}`,
76
- expect.objectContaining({
77
- method: "GET",
78
- headers: expect.objectContaining({
79
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
80
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
81
- "Content-Type": "application/json",
82
- }),
83
- credentials: "omit",
84
- })
85
- );
86
- expect(mockFetch).toHaveBeenNthCalledWith(
87
- 2,
88
- `https://api.quickbase.com/v1/apps/${appId}`,
89
- expect.objectContaining({
90
- method: "GET",
91
- headers: expect.objectContaining({
92
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
93
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
94
- "Content-Type": "application/json",
95
- }),
96
- credentials: "omit",
97
- })
98
- );
99
- });
100
-
101
- it("throws RateLimitError after max retries on 429", async () => {
102
- client = createClient(mockFetch, {
103
- realm: QB_REALM,
104
- userToken: QB_USER_TOKEN,
105
- debug: true,
106
- maxRetries: 1,
107
- retryDelay: 100,
108
- throttle: { rate: 10, burst: 10 },
109
- });
110
-
111
- const appId = QB_APP_ID;
112
-
113
- mockFetch
114
- .mockResolvedValueOnce({
115
- ok: false,
116
- status: 429,
117
- headers: new Headers({ "Retry-After": "1" }),
118
- json: () => Promise.resolve({ message: "Too Many Requests" }),
119
- })
120
- .mockResolvedValueOnce({
121
- ok: false,
122
- status: 429,
123
- headers: new Headers({ "Retry-After": "1" }),
124
- json: () => Promise.resolve({ message: "Too Many Requests" }),
125
- });
126
-
127
- await expect(client.getApp({ appId })).rejects.toMatchObject({
128
- name: "RateLimitError",
129
- message: "API Error: Too Many Requests (Status: 429)",
130
- status: 429,
131
- retryAfter: 1,
132
- });
133
-
134
- expect(mockFetch).toHaveBeenCalledTimes(2);
135
- });
136
-
137
- it("respects throttle limits without exceeding rate", async () => {
138
- client = createClient(mockFetch, {
139
- realm: QB_REALM,
140
- userToken: QB_USER_TOKEN,
141
- debug: true,
142
- throttle: { rate: 5, burst: 5 },
143
- });
144
-
145
- const appId = QB_APP_ID;
146
-
147
- const mockResponse: GetApp200Response = {
148
- id: appId,
149
- name: "TestApp",
150
- created: "2025-01-01T00:00:00Z",
151
- updated: "2025-01-02T00:00:00Z",
152
- description: "Test app",
153
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
154
- dateFormat: "MM-DD-YYYY",
155
- hasEveryoneOnTheInternet: false,
156
- memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
157
- securityProperties: {
158
- allowClone: false,
159
- allowExport: true,
160
- enableAppTokens: true,
161
- hideFromPublic: false,
162
- mustBeRealmApproved: false,
163
- useIPFilter: false,
164
- },
165
- };
166
-
167
- mockFetch.mockResolvedValue({
168
- ok: true,
169
- status: 200,
170
- json: () => Promise.resolve(mockResponse),
171
- });
172
-
173
- const startTime = Date.now();
174
- await Promise.all([
175
- client.getApp({ appId }),
176
- client.getApp({ appId }),
177
- client.getApp({ appId }),
178
- client.getApp({ appId }),
179
- client.getApp({ appId }),
180
- client.getApp({ appId }), // 6th call triggers throttle
181
- ]);
182
- const endTime = Date.now();
183
- const durationMs = endTime - startTime;
184
-
185
- expect(mockFetch).toHaveBeenCalledTimes(6);
186
- expect(durationMs).toBeGreaterThanOrEqual(200);
187
- expect(durationMs).toBeLessThan(1000);
188
- });
189
- });
@@ -1,112 +0,0 @@
1
- // tests/vitest/unit/records/deleteRecords.test.ts
2
- import { describe, expect, test, beforeEach } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_REALM,
7
- QB_USER_TOKEN,
8
- QB_TABLE_ID_1,
9
- } from "@tests/setup.ts";
10
-
11
- describe("QuickbaseClient Unit - deleteRecords", () => {
12
- let qb: ReturnType<typeof createClient>;
13
-
14
- beforeEach(() => {
15
- mockFetch.mockClear();
16
- qb = createClient(mockFetch, { debug: true }); // Use debug: true for consistency with other tests
17
- });
18
-
19
- test("sends correct DELETE request and handles success", async () => {
20
- mockFetch.mockResolvedValueOnce({
21
- ok: true,
22
- status: 200,
23
- json: () => Promise.resolve({ numberDeleted: 1 }),
24
- });
25
-
26
- const result = await qb.deleteRecords({
27
- body: {
28
- from: QB_TABLE_ID_1,
29
- where: "{3.EX.'5'}", // Simulate deleting Record ID 5
30
- },
31
- });
32
-
33
- expect(mockFetch).toHaveBeenCalledWith(
34
- "https://api.quickbase.com/v1/records",
35
- expect.objectContaining({
36
- method: "DELETE",
37
- headers: expect.objectContaining({
38
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
39
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
40
- "Content-Type": "application/json",
41
- }),
42
- body: JSON.stringify({ from: QB_TABLE_ID_1, where: "{3.EX.'5'}" }),
43
- })
44
- );
45
- expect(result).toEqual({ numberDeleted: 1 });
46
- });
47
-
48
- test("handles no records deleted", async () => {
49
- mockFetch.mockResolvedValueOnce({
50
- ok: true,
51
- status: 200,
52
- json: () => Promise.resolve({ numberDeleted: 0 }),
53
- });
54
-
55
- const result = await qb.deleteRecords({
56
- body: {
57
- from: QB_TABLE_ID_1,
58
- where: "{3.EX.'999999'}", // Non-existent Record ID
59
- },
60
- });
61
-
62
- expect(mockFetch).toHaveBeenCalledWith(
63
- "https://api.quickbase.com/v1/records",
64
- expect.objectContaining({
65
- method: "DELETE",
66
- headers: expect.objectContaining({
67
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
68
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
69
- "Content-Type": "application/json",
70
- }),
71
- body: JSON.stringify({
72
- from: QB_TABLE_ID_1,
73
- where: "{3.EX.'999999'}",
74
- }),
75
- })
76
- );
77
- expect(result).toEqual({ numberDeleted: 0 });
78
- });
79
-
80
- test("throws error on API failure", async () => {
81
- mockFetch.mockResolvedValueOnce({
82
- ok: false,
83
- status: 400,
84
- json: () => Promise.resolve({ message: "Invalid query" }),
85
- });
86
-
87
- await expect(() =>
88
- qb.deleteRecords({
89
- body: {
90
- from: QB_TABLE_ID_1,
91
- where: "{3.EX.'invalid'}",
92
- },
93
- })
94
- ).rejects.toThrow("API Error: Invalid query (Status: 400)");
95
-
96
- expect(mockFetch).toHaveBeenCalledWith(
97
- "https://api.quickbase.com/v1/records",
98
- expect.objectContaining({
99
- method: "DELETE",
100
- headers: expect.objectContaining({
101
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
102
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
103
- "Content-Type": "application/json",
104
- }),
105
- body: JSON.stringify({
106
- from: QB_TABLE_ID_1,
107
- where: "{3.EX.'invalid'}",
108
- }),
109
- })
110
- );
111
- });
112
- });