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,191 +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
- maxRetries: 0, // Prevent retries for this test
144
- });
145
-
146
- const appId = QB_APP_ID;
147
-
148
- const mockResponse: GetApp200Response = {
149
- id: appId,
150
- name: "TestApp",
151
- created: "2025-01-01T00:00:00Z",
152
- updated: "2025-01-02T00:00:00Z",
153
- description: "Test app",
154
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
155
- dateFormat: "MM-DD-YYYY",
156
- hasEveryoneOnTheInternet: false,
157
- memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
158
- securityProperties: {
159
- allowClone: false,
160
- allowExport: true,
161
- enableAppTokens: true,
162
- hideFromPublic: false,
163
- mustBeRealmApproved: false,
164
- useIPFilter: false,
165
- },
166
- };
167
-
168
- mockFetch.mockResolvedValue({
169
- ok: true,
170
- status: 200,
171
- json: () => Promise.resolve(mockResponse),
172
- });
173
-
174
- const startTime = Date.now();
175
- await Promise.all([
176
- client.getApp({ appId }),
177
- client.getApp({ appId }),
178
- client.getApp({ appId }),
179
- client.getApp({ appId }),
180
- client.getApp({ appId }),
181
- client.getApp({ appId }), // 6th call should be throttled
182
- ]);
183
- const endTime = Date.now();
184
- const durationMs = endTime - startTime;
185
-
186
- console.log(`[Test Debug] mockFetch calls: ${mockFetch.mock.calls.length}`);
187
- expect(mockFetch).toHaveBeenCalledTimes(6);
188
- expect(durationMs).toBeGreaterThanOrEqual(200); // 1/5 sec for 6th call
189
- expect(durationMs).toBeLessThan(1000);
190
- });
191
- });
@@ -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
- });
@@ -1,102 +0,0 @@
1
- // tests/vitest/unit/records/runQuery.test.ts
2
- import { describe, test, expect, 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
- import { RunQueryRequest, RunQueryResponse } from "@/generated";
11
-
12
- describe("QuickbaseClient Unit - runQuery", () => {
13
- let client: ReturnType<typeof createClient>;
14
-
15
- beforeEach(() => {
16
- mockFetch.mockClear();
17
- client = createClient(mockFetch, { debug: true });
18
- });
19
-
20
- test("sends correct POST request and handles successful query response", async () => {
21
- const queryRequest: RunQueryRequest = {
22
- from: QB_TABLE_ID_1,
23
- select: [3, 6, 7],
24
- where: "{6.EX.'Task 1'}",
25
- sortBy: [{ fieldId: 6, order: "ASC" }],
26
- groupBy: [{ fieldId: 7, grouping: "equal-values" }],
27
- options: { skip: 0, top: 100, compareWithAppLocalTime: false },
28
- };
29
-
30
- const mockResponse: RunQueryResponse = {
31
- data: [
32
- { "3": { value: 1 }, "6": { value: "Task 1" }, "7": { value: "High" } },
33
- ],
34
- fields: [
35
- { id: 3, label: "Record ID#", type: "recordid" },
36
- { id: 6, label: "Task Name", type: "text" },
37
- { id: 7, label: "Priority", type: "text" },
38
- ],
39
- metadata: {
40
- numFields: 3,
41
- numRecords: 1,
42
- skip: 0,
43
- top: 100,
44
- totalRecords: 1,
45
- },
46
- };
47
-
48
- mockFetch.mockResolvedValueOnce({
49
- ok: true,
50
- status: 200,
51
- json: () => Promise.resolve(mockResponse),
52
- });
53
-
54
- const result = await client.runQuery({ body: queryRequest });
55
-
56
- expect(mockFetch).toHaveBeenCalledWith(
57
- "https://api.quickbase.com/v1/records/query",
58
- expect.objectContaining({
59
- method: "POST",
60
- headers: expect.objectContaining({
61
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
62
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
63
- "Content-Type": "application/json",
64
- }),
65
- body: JSON.stringify(queryRequest),
66
- })
67
- );
68
-
69
- expect(result).toEqual(mockResponse);
70
- });
71
-
72
- test("handles API error with invalid query", async () => {
73
- const invalidQueryRequest: RunQueryRequest = {
74
- from: QB_TABLE_ID_1,
75
- select: [3],
76
- where: "{999.EX.'Invalid'}",
77
- };
78
-
79
- mockFetch.mockResolvedValueOnce({
80
- ok: false,
81
- status: 400,
82
- json: () => Promise.resolve({ message: "Invalid query" }),
83
- });
84
-
85
- await expect(
86
- client.runQuery({ body: invalidQueryRequest })
87
- ).rejects.toThrow("API Error: Invalid query (Status: 400)");
88
-
89
- expect(mockFetch).toHaveBeenCalledWith(
90
- "https://api.quickbase.com/v1/records/query",
91
- expect.objectContaining({
92
- method: "POST",
93
- headers: expect.objectContaining({
94
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
95
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
96
- "Content-Type": "application/json",
97
- }),
98
- body: JSON.stringify(invalidQueryRequest),
99
- })
100
- );
101
- });
102
- });
@@ -1,234 +0,0 @@
1
- // tests/vitest/unit/records/upsert.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
- import { vi } from "vitest";
11
-
12
- // Note: Type augmentation moved to src/types.d.ts
13
- describe("QuickbaseClient Unit - upsert", () => {
14
- beforeEach(() => {
15
- vi.resetModules(); // Reset module cache
16
- mockFetch.mockClear();
17
- });
18
-
19
- test("sends correct POST request and handles successful upsert", async () => {
20
- const qb = createClient(mockFetch, { debug: true });
21
-
22
- mockFetch.mockResolvedValueOnce({
23
- ok: true,
24
- status: 200,
25
- json: () =>
26
- Promise.resolve({
27
- data: [{ id: 1, "6": { value: "value1" } }],
28
- metadata: {
29
- createdRecordIds: [1],
30
- updatedRecordIds: [],
31
- unchangedRecordIds: [],
32
- totalNumberOfRecordsProcessed: 1,
33
- },
34
- }),
35
- });
36
-
37
- console.log("[Test] Calling qb.upsert with:", {
38
- body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
39
- });
40
- const result = await qb.upsert({
41
- body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
42
- });
43
-
44
- console.log("[Test] mockFetch calls:", mockFetch.mock.calls);
45
- expect(mockFetch).toHaveBeenCalledWith(
46
- "https://api.quickbase.com/v1/records",
47
- expect.objectContaining({
48
- method: "POST",
49
- headers: expect.objectContaining({
50
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
51
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
52
- "Content-Type": "application/json",
53
- }),
54
- body: expect.any(String), // Allow any string, check content below
55
- credentials: "omit",
56
- })
57
- );
58
- const callArgs = mockFetch.mock.calls[0];
59
- const receivedBody = JSON.parse(callArgs[1].body as string);
60
- expect(receivedBody).toEqual({
61
- to: QB_TABLE_ID_1,
62
- data: [{ "6": { value: "value1" } }],
63
- });
64
-
65
- expect(result).toEqual({
66
- data: [{ id: 1, "6": { value: "value1" } }],
67
- metadata: {
68
- createdRecordIds: [1],
69
- updatedRecordIds: [],
70
- unchangedRecordIds: [],
71
- totalNumberOfRecordsProcessed: 1,
72
- },
73
- });
74
- });
75
-
76
- test("handles API error with invalid data", async () => {
77
- const qb = createClient(mockFetch, { debug: true });
78
-
79
- mockFetch.mockResolvedValueOnce({
80
- ok: false,
81
- status: 400,
82
- json: () => Promise.resolve({ message: "Invalid data format" }),
83
- });
84
-
85
- await expect(
86
- qb.upsert({
87
- body: { to: QB_TABLE_ID_1, data: [{ "999": { value: "invalid" } }] },
88
- })
89
- ).rejects.toThrow("API Error: Invalid data format (Status: 400)");
90
-
91
- expect(mockFetch).toHaveBeenCalledWith(
92
- "https://api.quickbase.com/v1/records",
93
- expect.objectContaining({
94
- method: "POST",
95
- headers: expect.objectContaining({
96
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
97
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
98
- "Content-Type": "application/json",
99
- }),
100
- body: expect.any(String),
101
- credentials: "omit",
102
- })
103
- );
104
- const callArgs = mockFetch.mock.calls[0];
105
- const receivedBody = JSON.parse(callArgs[1].body as string);
106
- expect(receivedBody).toEqual({
107
- to: QB_TABLE_ID_1,
108
- data: [{ "999": { value: "invalid" } }],
109
- });
110
- });
111
-
112
- test("handles upsert with temp token", async () => {
113
- const qb = createClient(mockFetch, { useTempTokens: true, debug: true });
114
-
115
- mockFetch
116
- .mockResolvedValueOnce({
117
- ok: true,
118
- status: 200,
119
- json: () => Promise.resolve({ temporaryAuthorization: "temp-token" }),
120
- })
121
- .mockResolvedValueOnce({
122
- ok: true,
123
- status: 200,
124
- json: () =>
125
- Promise.resolve({
126
- data: [{ id: 2, "7": { value: "value2" } }],
127
- metadata: {
128
- createdRecordIds: [2],
129
- updatedRecordIds: [],
130
- unchangedRecordIds: [],
131
- totalNumberOfRecordsProcessed: 1,
132
- },
133
- }),
134
- });
135
-
136
- const result = await qb.upsert({
137
- body: { to: QB_TABLE_ID_1, data: [{ "7": { value: "value2" } }] },
138
- dbid: QB_TABLE_ID_1, // Use QB_TABLE_ID_1 as dbid for temp token
139
- } as any); // Temporary type assertion until types.d.ts is applied
140
-
141
- expect(mockFetch).toHaveBeenCalledTimes(2);
142
- expect(mockFetch).toHaveBeenNthCalledWith(
143
- 1,
144
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
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/records",
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),
165
- credentials: "omit",
166
- })
167
- );
168
- const callArgs = mockFetch.mock.calls[1];
169
- const receivedBody = JSON.parse(callArgs[1].body as string);
170
- expect(receivedBody).toEqual({
171
- to: QB_TABLE_ID_1,
172
- data: [{ "7": { value: "value2" } }],
173
- });
174
-
175
- expect(result).toEqual({
176
- data: [{ id: 2, "7": { value: "value2" } }],
177
- metadata: {
178
- createdRecordIds: [2],
179
- updatedRecordIds: [],
180
- unchangedRecordIds: [],
181
- totalNumberOfRecordsProcessed: 1,
182
- },
183
- });
184
- });
185
-
186
- test("sends correct POST request with data fields", async () => {
187
- const qb = createClient(mockFetch, { debug: true });
188
-
189
- mockFetch.mockResolvedValueOnce({
190
- ok: true,
191
- status: 200,
192
- json: () =>
193
- Promise.resolve({
194
- data: [{ id: 1, "6": { value: "value1" } }],
195
- metadata: {
196
- createdRecordIds: [1],
197
- updatedRecordIds: [],
198
- unchangedRecordIds: [],
199
- totalNumberOfRecordsProcessed: 1,
200
- },
201
- }),
202
- });
203
-
204
- const result = await qb.upsert({
205
- body: { to: QB_TABLE_ID_1, data: [{ "6": { value: "value1" } }] },
206
- });
207
-
208
- expect(mockFetch).toHaveBeenCalledWith(
209
- "https://api.quickbase.com/v1/records",
210
- expect.objectContaining({
211
- method: "POST",
212
- headers: expect.objectContaining({
213
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
214
- Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
215
- "Content-Type": "application/json",
216
- }),
217
- body: expect.any(String),
218
- credentials: "omit",
219
- })
220
- );
221
- const callArgs = mockFetch.mock.calls[0];
222
- const receivedBody = JSON.parse(callArgs[1].body as string);
223
- expect(receivedBody).toEqual({
224
- to: QB_TABLE_ID_1,
225
- data: [{ "6": { value: "value1" } }],
226
- });
227
-
228
- if (result.data && result.data.length > 0) {
229
- expect((result.data[0]["6"] as { value: any }).value).toBe("value1");
230
- } else {
231
- throw new Error("Expected data array to have at least one element");
232
- }
233
- });
234
- });