quickbase-js 0.1.0-beta.7

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 (123) hide show
  1. package/CHANGELOG.md +129 -0
  2. package/LICENSE +21 -0
  3. package/README.md +204 -0
  4. package/build-common.js +131 -0
  5. package/build-esm.js +71 -0
  6. package/build-umd.js +69 -0
  7. package/dist/esm/quickbase.d.ts +7594 -0
  8. package/dist/esm/quickbase.js +9752 -0
  9. package/dist/esm/quickbase.js.map +1 -0
  10. package/dist/esm/quickbase.min.js +2 -0
  11. package/dist/esm/quickbase.min.js.map +1 -0
  12. package/dist/umd/quickbase.umd.js +10502 -0
  13. package/dist/umd/quickbase.umd.js.map +1 -0
  14. package/dist/umd/quickbase.umd.min.js +2 -0
  15. package/dist/umd/quickbase.umd.min.js.map +1 -0
  16. package/examples/quicbase-jsCDN.html +36 -0
  17. package/examples/react.js +48 -0
  18. package/examples/vanillajs.html +47 -0
  19. package/notes.txt +158 -0
  20. package/open-api/fix-spec-main.ts +96 -0
  21. package/open-api/generate-unified-interface.ts +277 -0
  22. package/open-api/output/override-report.json +58 -0
  23. package/open-api/output/quickbase-fixed.json +10610 -0
  24. package/open-api/regenerate-client.ts +116 -0
  25. package/open-api/schema/enhance-general.ts +100 -0
  26. package/open-api/schema/fix-arrays.ts +69 -0
  27. package/open-api/schema/tags/apps.ts +90 -0
  28. package/open-api/schema/tags/fields.ts +156 -0
  29. package/open-api/schema/tags/groups.ts +51 -0
  30. package/open-api/schema/tags/index.ts +68 -0
  31. package/open-api/schema/tags/records.ts +115 -0
  32. package/open-api/schema/tags/tables.ts +211 -0
  33. package/open-api/schema/tags/users.ts +47 -0
  34. package/open-api/types/spec.ts +41 -0
  35. package/open-api/utils/infer-schema.ts +40 -0
  36. package/open-api/utils/naming.ts +10 -0
  37. package/package.json +91 -0
  38. package/playwright.config.ts +37 -0
  39. package/rollup.config.js +114 -0
  40. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +46878 -0
  41. package/specs/split/apps.json +1315 -0
  42. package/specs/split/auth.json +191 -0
  43. package/specs/split/fields.json +3869 -0
  44. package/specs/split/records.json +754 -0
  45. package/specs/split/reports.json +619 -0
  46. package/specs/split/tables.json +1605 -0
  47. package/src/generated-unified/QuickbaseClient.ts +359 -0
  48. package/src/generated-unified/missing-types-report.json +3 -0
  49. package/src/index.ts +1 -0
  50. package/src/quickbaseClient.ts +402 -0
  51. package/src/tokenCache.ts +51 -0
  52. package/src/utils.ts +7 -0
  53. package/test-esm.js +1 -0
  54. package/test-results.json +2050 -0
  55. package/test-umd.js +1 -0
  56. package/test.ts +1 -0
  57. package/tests/playwright/qb/auth/cacheSwitching.test.ts +159 -0
  58. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +219 -0
  59. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +162 -0
  60. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +153 -0
  61. package/tests/playwright/qb/auth/getTempToken.test.ts +152 -0
  62. package/tests/playwright/qb/auth/tokenPrefetch.test.ts +179 -0
  63. package/tests/playwright/qb/auth/tokenRenewal.test.ts +133 -0
  64. package/tests/setup.ts +51 -0
  65. package/tests/vitest/qb/apps/copyApp.test.ts +76 -0
  66. package/tests/vitest/qb/apps/createApp.test.ts +64 -0
  67. package/tests/vitest/qb/apps/deleteApp.test.ts +76 -0
  68. package/tests/vitest/qb/apps/getApp.test.ts +40 -0
  69. package/tests/vitest/qb/fields/createField.test.ts +78 -0
  70. package/tests/vitest/qb/fields/deleteFields.test.ts +89 -0
  71. package/tests/vitest/qb/fields/getField.test.ts +85 -0
  72. package/tests/vitest/qb/fields/getFieldUsage.test.ts +174 -0
  73. package/tests/vitest/qb/fields/getFields.test.ts +232 -0
  74. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +77 -0
  75. package/tests/vitest/qb/index.ts +28 -0
  76. package/tests/vitest/qb/records/deleteRecords.test.ts +110 -0
  77. package/tests/vitest/qb/records/runQuery.test.ts +146 -0
  78. package/tests/vitest/qb/records/upsert.test.ts +102 -0
  79. package/tests/vitest/qb/tables/createTable.test.ts +55 -0
  80. package/tests/vitest/qb/tables/deleteTable.test.ts +50 -0
  81. package/tests/vitest/qb/tables/getAppTables.test.ts +46 -0
  82. package/tests/vitest/qb/tables/getRelationships.test.ts +80 -0
  83. package/tests/vitest/qb/tables/getTable.test.ts +26 -0
  84. package/tests/vitest/qb/tables/updateTable.test.ts +48 -0
  85. package/tests/vitest/unit/apps/copyApp.test.ts +488 -0
  86. package/tests/vitest/unit/apps/createApp.test.ts +186 -0
  87. package/tests/vitest/unit/apps/deleteApp.test.ts +216 -0
  88. package/tests/vitest/unit/apps/getApp.test.ts +128 -0
  89. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +82 -0
  90. package/tests/vitest/unit/auth/getTempToken.test.ts +95 -0
  91. package/tests/vitest/unit/auth/retryOn401.test.ts +116 -0
  92. package/tests/vitest/unit/auth/two401s.test.ts +86 -0
  93. package/tests/vitest/unit/fields/createField.test.ts +391 -0
  94. package/tests/vitest/unit/fields/deleteFields.test.ts +141 -0
  95. package/tests/vitest/unit/fields/getField.test.ts +189 -0
  96. package/tests/vitest/unit/fields/getFieldUsage.test.ts +147 -0
  97. package/tests/vitest/unit/fields/getFields.test.ts +122 -0
  98. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +160 -0
  99. package/tests/vitest/unit/index.ts +33 -0
  100. package/tests/vitest/unit/records/deleteRecords.test.ts +112 -0
  101. package/tests/vitest/unit/records/runQuery.test.ts +102 -0
  102. package/tests/vitest/unit/records/upsert.test.ts +234 -0
  103. package/tests/vitest/unit/tables/createTable.test.ts +70 -0
  104. package/tests/vitest/unit/tables/deleteTable.test.ts +77 -0
  105. package/tests/vitest/unit/tables/getAppTables.test.ts +85 -0
  106. package/tests/vitest/unit/tables/getRelationships.test.ts +259 -0
  107. package/tests/vitest/unit/tables/getTable.test.ts +233 -0
  108. package/tests/vitest/unit/tables/updateTable.test.ts +80 -0
  109. package/tests/vitest/unit/umd.test.ts +8 -0
  110. package/text.txt +104 -0
  111. package/tools/generate-types.ts +29 -0
  112. package/tools/log-gen.ts +231 -0
  113. package/tools/log-gen.yaml +3826 -0
  114. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  115. package/tools/openapi-schema-validator.ts +38 -0
  116. package/tools/spec-analyzer.ts +163 -0
  117. package/tools/split-spec.ts +148 -0
  118. package/tools/test-import.ts +3 -0
  119. package/tools/validate-spec.ts +40 -0
  120. package/tsconfig.build.json +17 -0
  121. package/tsconfig.json +29 -0
  122. package/versionrc.json +9 -0
  123. package/vitest.config.ts +27 -0
@@ -0,0 +1,259 @@
1
+ // tests/vitest/unit/relationships/getRelationships.test.ts
2
+ import { describe, it, expect, beforeEach } from "vitest";
3
+ import {
4
+ createClient,
5
+ mockFetch,
6
+ QB_REALM,
7
+ QB_USER_TOKEN,
8
+ QB_TABLE_ID_1,
9
+ QB_TABLE_ID_2,
10
+ } from "@tests/setup.ts";
11
+ import { GetRelationships200Response } from "/home/drew/Projects/quickbase-js/src/generated/models";
12
+
13
+ describe("QuickbaseClient Unit - getRelationships", () => {
14
+ let client: ReturnType<typeof createClient>;
15
+
16
+ beforeEach(() => {
17
+ mockFetch.mockClear();
18
+ client = createClient(mockFetch, { debug: true }); // Consistent with output
19
+ });
20
+
21
+ it("initializes without errors", () => {
22
+ expect(client).toBeDefined();
23
+ });
24
+
25
+ it("has getRelationships method", () => {
26
+ expect(typeof client.getRelationships).toBe("function");
27
+ });
28
+
29
+ it("sends correct GET request and handles successful response", async () => {
30
+ const mockResponse: GetRelationships200Response = {
31
+ metadata: {
32
+ numRelationships: 1,
33
+ skip: 0,
34
+ totalRelationships: 1,
35
+ },
36
+ relationships: [
37
+ {
38
+ id: 6,
39
+ parentTableId: QB_TABLE_ID_1, // Parent table
40
+ childTableId: QB_TABLE_ID_2, // Child table
41
+ foreignKeyField: {
42
+ id: 6,
43
+ label: "Related record",
44
+ type: "numeric",
45
+ },
46
+ isCrossApp: false,
47
+ lookupFields: [
48
+ {
49
+ id: 3,
50
+ label: "Name",
51
+ type: "text",
52
+ },
53
+ ],
54
+ summaryFields: [
55
+ {
56
+ id: 8,
57
+ label: "my summary field",
58
+ type: "numeric",
59
+ },
60
+ ],
61
+ },
62
+ ],
63
+ };
64
+
65
+ mockFetch.mockResolvedValueOnce({
66
+ ok: true,
67
+ status: 200,
68
+ json: () => Promise.resolve(mockResponse),
69
+ });
70
+
71
+ const result = await client.getRelationships({
72
+ tableId: QB_TABLE_ID_2,
73
+ skip: 0,
74
+ });
75
+
76
+ expect(mockFetch).toHaveBeenCalledWith(
77
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationships?skip=0`,
78
+ expect.objectContaining({
79
+ method: "GET",
80
+ headers: expect.objectContaining({
81
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
82
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
83
+ "Content-Type": "application/json",
84
+ }),
85
+ })
86
+ );
87
+
88
+ expect(result).toEqual(mockResponse);
89
+ expect(result.metadata.numRelationships).toBe(1);
90
+ expect(result.relationships).toHaveLength(1);
91
+ expect(result.relationships[0].id).toBe(6);
92
+ expect(result.relationships[0].foreignKeyField.label).toBe(
93
+ "Related record"
94
+ );
95
+ });
96
+
97
+ it("handles request without skip parameter", async () => {
98
+ const mockResponse: GetRelationships200Response = {
99
+ metadata: {
100
+ numRelationships: 1,
101
+ skip: 0,
102
+ totalRelationships: 1,
103
+ },
104
+ relationships: [
105
+ {
106
+ id: 6,
107
+ parentTableId: QB_TABLE_ID_1,
108
+ childTableId: QB_TABLE_ID_2,
109
+ foreignKeyField: {
110
+ id: 6,
111
+ label: "Related record",
112
+ type: "numeric",
113
+ },
114
+ isCrossApp: false,
115
+ lookupFields: [],
116
+ summaryFields: [],
117
+ },
118
+ ],
119
+ };
120
+
121
+ mockFetch.mockResolvedValueOnce({
122
+ ok: true,
123
+ status: 200,
124
+ json: () => Promise.resolve(mockResponse),
125
+ });
126
+
127
+ const result = await client.getRelationships({
128
+ tableId: QB_TABLE_ID_2, // Corrected from QB_TABLE_ID_1
129
+ });
130
+
131
+ expect(mockFetch).toHaveBeenCalledWith(
132
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationships`,
133
+ expect.objectContaining({
134
+ method: "GET",
135
+ headers: expect.objectContaining({
136
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
137
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
138
+ "Content-Type": "application/json",
139
+ }),
140
+ })
141
+ );
142
+
143
+ expect(result).toEqual(mockResponse);
144
+ });
145
+
146
+ it("handles API error response", async () => {
147
+ mockFetch.mockResolvedValueOnce({
148
+ ok: false,
149
+ status: 404,
150
+ json: () => Promise.resolve({ message: "Table not found" }),
151
+ });
152
+
153
+ await expect(
154
+ client.getRelationships({
155
+ tableId: QB_TABLE_ID_2, // Corrected from QB_TABLE_ID_1
156
+ skip: 0,
157
+ })
158
+ ).rejects.toThrow("API Error: Table not found (Status: 404)");
159
+
160
+ expect(mockFetch).toHaveBeenCalledWith(
161
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationships?skip=0`,
162
+ expect.objectContaining({
163
+ method: "GET",
164
+ headers: expect.objectContaining({
165
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
166
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
167
+ "Content-Type": "application/json",
168
+ }),
169
+ })
170
+ );
171
+ });
172
+
173
+ it("retries with temp token after 401", async () => {
174
+ const mockResponse: GetRelationships200Response = {
175
+ metadata: {
176
+ numRelationships: 1,
177
+ skip: 0,
178
+ totalRelationships: 1,
179
+ },
180
+ relationships: [
181
+ {
182
+ id: 6,
183
+ parentTableId: QB_TABLE_ID_1,
184
+ childTableId: QB_TABLE_ID_2,
185
+ foreignKeyField: {
186
+ id: 6,
187
+ label: "Related record",
188
+ type: "numeric",
189
+ },
190
+ isCrossApp: false,
191
+ },
192
+ ],
193
+ };
194
+
195
+ mockFetch
196
+ .mockResolvedValueOnce({
197
+ ok: true,
198
+ status: 200,
199
+ json: () =>
200
+ Promise.resolve({ temporaryAuthorization: "initial_token" }),
201
+ })
202
+ .mockResolvedValueOnce({
203
+ ok: false,
204
+ status: 401,
205
+ json: () => Promise.resolve({ message: "Unauthorized" }),
206
+ })
207
+ .mockResolvedValueOnce({
208
+ ok: true,
209
+ status: 200,
210
+ json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
211
+ })
212
+ .mockResolvedValueOnce({
213
+ ok: true,
214
+ status: 200,
215
+ json: () => Promise.resolve(mockResponse),
216
+ });
217
+
218
+ const tempClient = createClient(mockFetch, {
219
+ useTempTokens: true,
220
+ debug: true,
221
+ });
222
+ const result = await tempClient.getRelationships({
223
+ tableId: QB_TABLE_ID_2,
224
+ skip: 0,
225
+ });
226
+
227
+ expect(mockFetch).toHaveBeenCalledTimes(4);
228
+ expect(mockFetch).toHaveBeenNthCalledWith(
229
+ 1,
230
+ `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_2}`,
231
+ expect.any(Object)
232
+ );
233
+ expect(mockFetch).toHaveBeenNthCalledWith(
234
+ 2,
235
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationships?skip=0`,
236
+ expect.objectContaining({
237
+ headers: expect.objectContaining({
238
+ Authorization: "QB-TEMP-TOKEN initial_token",
239
+ }),
240
+ })
241
+ );
242
+ expect(mockFetch).toHaveBeenNthCalledWith(
243
+ 3,
244
+ `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_2}`,
245
+ expect.any(Object)
246
+ );
247
+ expect(mockFetch).toHaveBeenNthCalledWith(
248
+ 4,
249
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_2}/relationships?skip=0`,
250
+ expect.objectContaining({
251
+ headers: expect.objectContaining({
252
+ Authorization: "QB-TEMP-TOKEN new_token",
253
+ }),
254
+ })
255
+ );
256
+
257
+ expect(result).toEqual(mockResponse);
258
+ });
259
+ });
@@ -0,0 +1,233 @@
1
+ // tests/vitest/unit/tables/getTable.test.ts
2
+ import { describe, it, expect, beforeEach } from "vitest";
3
+ import {
4
+ createClient,
5
+ mockFetch,
6
+ QB_APP_ID,
7
+ QB_TABLE_ID_1,
8
+ QB_REALM,
9
+ QB_USER_TOKEN,
10
+ } from "@tests/setup.ts";
11
+
12
+ describe("QuickbaseClient Unit - getTable", () => {
13
+ let client: ReturnType<typeof createClient>;
14
+
15
+ beforeEach(() => {
16
+ mockFetch.mockClear();
17
+ });
18
+
19
+ it("calls getTable successfully with user token", async () => {
20
+ client = createClient(mockFetch, { debug: true });
21
+
22
+ const mockResponse = {
23
+ id: QB_TABLE_ID_1,
24
+ name: "Root",
25
+ alias: "_DBID_ROOT",
26
+ description: "",
27
+ created: new Date("2025-02-13T18:22:33.000Z"),
28
+ updated: new Date("2025-02-13T18:22:34.000Z"),
29
+ nextRecordId: 1,
30
+ nextFieldId: 6,
31
+ defaultSortFieldId: 2,
32
+ defaultSortOrder: "DESC",
33
+ keyFieldId: 3,
34
+ singleRecordName: "Root",
35
+ pluralRecordName: "Roots",
36
+ sizeLimit: "500 MB",
37
+ spaceUsed: "0 KB",
38
+ spaceRemaining: "500 MB",
39
+ };
40
+
41
+ mockFetch.mockResolvedValueOnce({
42
+ ok: true,
43
+ status: 200,
44
+ json: () => Promise.resolve(mockResponse),
45
+ });
46
+
47
+ const response = await client.getTable({
48
+ tableId: QB_TABLE_ID_1,
49
+ appId: QB_APP_ID,
50
+ });
51
+ expect(response).toEqual(mockResponse);
52
+ expect(mockFetch).toHaveBeenCalledWith(
53
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
54
+ expect.objectContaining({
55
+ method: "GET",
56
+ headers: expect.objectContaining({
57
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
58
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
59
+ }),
60
+ })
61
+ );
62
+ });
63
+
64
+ it("calls getTable successfully with temp token", async () => {
65
+ client = createClient(mockFetch, { debug: true, useTempTokens: true });
66
+
67
+ const mockResponse = {
68
+ id: QB_TABLE_ID_1,
69
+ name: "Root",
70
+ alias: "_DBID_ROOT",
71
+ description: "",
72
+ created: new Date("2025-02-13T18:22:33.000Z"),
73
+ updated: new Date("2025-02-13T18:22:34.000Z"),
74
+ nextRecordId: 1,
75
+ nextFieldId: 6,
76
+ defaultSortFieldId: 2,
77
+ defaultSortOrder: "DESC",
78
+ keyFieldId: 3,
79
+ singleRecordName: "Root",
80
+ pluralRecordName: "Roots",
81
+ sizeLimit: "500 MB",
82
+ spaceUsed: "0 KB",
83
+ spaceRemaining: "500 MB",
84
+ };
85
+
86
+ mockFetch
87
+ .mockResolvedValueOnce({
88
+ ok: true,
89
+ status: 200,
90
+ json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
91
+ })
92
+ .mockResolvedValueOnce({
93
+ ok: true,
94
+ status: 200,
95
+ json: () => Promise.resolve(mockResponse),
96
+ });
97
+
98
+ const response = await client.getTable({
99
+ tableId: QB_TABLE_ID_1,
100
+ appId: QB_APP_ID,
101
+ });
102
+ expect(response).toEqual(mockResponse);
103
+ expect(mockFetch).toHaveBeenCalledTimes(2);
104
+ expect(mockFetch).toHaveBeenCalledWith(
105
+ `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
106
+ expect.any(Object)
107
+ );
108
+ expect(mockFetch).toHaveBeenCalledWith(
109
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
110
+ expect.objectContaining({
111
+ headers: expect.objectContaining({
112
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
113
+ Authorization: "QB-TEMP-TOKEN temp_token",
114
+ }),
115
+ })
116
+ );
117
+ });
118
+
119
+ it("retries successfully after 401 with temp token", async () => {
120
+ client = createClient(mockFetch, { debug: true, useTempTokens: true });
121
+
122
+ const mockResponse = {
123
+ id: QB_TABLE_ID_1,
124
+ name: "Root",
125
+ alias: "_DBID_ROOT",
126
+ description: "",
127
+ created: new Date("2025-02-13T18:22:33.000Z"),
128
+ updated: new Date("2025-02-13T18:22:34.000Z"),
129
+ nextRecordId: 1,
130
+ nextFieldId: 6,
131
+ defaultSortFieldId: 2,
132
+ defaultSortOrder: "DESC",
133
+ keyFieldId: 3,
134
+ singleRecordName: "Root",
135
+ pluralRecordName: "Roots",
136
+ sizeLimit: "500 MB",
137
+ spaceUsed: "0 KB",
138
+ spaceRemaining: "500 MB",
139
+ };
140
+
141
+ mockFetch
142
+ .mockResolvedValueOnce({
143
+ ok: true,
144
+ status: 200,
145
+ json: () =>
146
+ Promise.resolve({ temporaryAuthorization: "initial_token" }),
147
+ })
148
+ .mockResolvedValueOnce({
149
+ ok: false,
150
+ status: 401,
151
+ json: () => Promise.resolve({ message: "Unauthorized" }),
152
+ })
153
+ .mockResolvedValueOnce({
154
+ ok: true,
155
+ status: 200,
156
+ json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
157
+ })
158
+ .mockResolvedValueOnce({
159
+ ok: true,
160
+ status: 200,
161
+ json: () => Promise.resolve(mockResponse),
162
+ });
163
+
164
+ const response = await client.getTable({
165
+ tableId: QB_TABLE_ID_1,
166
+ appId: QB_APP_ID,
167
+ });
168
+ expect(response).toEqual(mockResponse);
169
+ expect(mockFetch).toHaveBeenCalledTimes(4);
170
+ expect(mockFetch).toHaveBeenCalledWith(
171
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
172
+ expect.objectContaining({
173
+ headers: expect.objectContaining({
174
+ Authorization: "QB-TEMP-TOKEN new_token",
175
+ }),
176
+ })
177
+ );
178
+ });
179
+
180
+ it("handles 401 with failed temp token retry", async () => {
181
+ client = createClient(mockFetch, { debug: true, useTempTokens: true });
182
+
183
+ mockFetch
184
+ .mockResolvedValueOnce({
185
+ ok: true,
186
+ status: 200,
187
+ json: () =>
188
+ Promise.resolve({ temporaryAuthorization: "initial_token" }),
189
+ })
190
+ .mockResolvedValueOnce({
191
+ ok: false,
192
+ status: 401,
193
+ json: () => Promise.resolve({ message: "Unauthorized" }),
194
+ })
195
+ .mockResolvedValueOnce({
196
+ ok: false,
197
+ status: 401,
198
+ json: () =>
199
+ Promise.resolve({ message: "Unauthorized in fetchTempToken" }),
200
+ });
201
+
202
+ await expect(
203
+ client.getTable({ tableId: QB_TABLE_ID_1, appId: QB_APP_ID })
204
+ ).rejects.toThrow(
205
+ "API Error: Unauthorized in fetchTempToken (Status: 401)"
206
+ );
207
+ expect(mockFetch).toHaveBeenCalledTimes(3);
208
+ });
209
+
210
+ it("handles 404 Not Found", async () => {
211
+ client = createClient(mockFetch, { debug: true });
212
+
213
+ mockFetch.mockResolvedValueOnce({
214
+ ok: false,
215
+ status: 404,
216
+ json: () => Promise.resolve({ message: "Table not found" }),
217
+ });
218
+
219
+ await expect(
220
+ client.getTable({ tableId: QB_TABLE_ID_1, appId: QB_APP_ID })
221
+ ).rejects.toThrow("API Error: Table not found (Status: 404)");
222
+ expect(mockFetch).toHaveBeenCalledWith(
223
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
224
+ expect.objectContaining({
225
+ method: "GET",
226
+ headers: expect.objectContaining({
227
+ "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
228
+ Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
229
+ }),
230
+ })
231
+ );
232
+ });
233
+ });
@@ -0,0 +1,80 @@
1
+ // tests/vitest/unit/records/updateTable.test.ts
2
+ import { describe, it, expect, beforeEach } from "vitest";
3
+ import {
4
+ createClient,
5
+ mockFetch,
6
+ QB_APP_ID,
7
+ QB_TABLE_ID_1,
8
+ } from "@tests/setup.ts";
9
+
10
+ describe("QuickbaseClient Unit - updateTable", () => {
11
+ let client: ReturnType<typeof createClient>;
12
+
13
+ beforeEach(() => {
14
+ mockFetch.mockClear();
15
+ client = createClient(mockFetch, { debug: true });
16
+ });
17
+
18
+ it("calls updateTable successfully with temp token", async () => {
19
+ client = createClient(mockFetch, { debug: true, useTempTokens: true });
20
+
21
+ const mockBody = {
22
+ name: "Updated Root",
23
+ description: "Updated description",
24
+ };
25
+ const mockResponse = {
26
+ id: QB_TABLE_ID_1,
27
+ name: "Updated Root",
28
+ alias: "_DBID_ROOT",
29
+ description: "Updated description",
30
+ created: new Date("2025-02-13T18:22:33.000Z"),
31
+ updated: new Date("2025-03-10T12:00:00.000Z"),
32
+ nextRecordId: 1,
33
+ nextFieldId: 6,
34
+ defaultSortFieldId: 2,
35
+ defaultSortOrder: "DESC",
36
+ keyFieldId: 3,
37
+ singleRecordName: "Root",
38
+ pluralRecordName: "Roots",
39
+ sizeLimit: "500 MB",
40
+ spaceUsed: "0 KB",
41
+ spaceRemaining: "500 MB",
42
+ };
43
+
44
+ mockFetch
45
+ .mockResolvedValueOnce({
46
+ ok: true,
47
+ status: 200,
48
+ json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
49
+ })
50
+ .mockResolvedValueOnce({
51
+ ok: true,
52
+ status: 200,
53
+ json: () => Promise.resolve(mockResponse),
54
+ });
55
+
56
+ const response = await client.updateTable({
57
+ tableId: QB_TABLE_ID_1,
58
+ appId: QB_APP_ID,
59
+ body: mockBody,
60
+ });
61
+ expect(response).toEqual(mockResponse);
62
+ expect(mockFetch).toHaveBeenCalledTimes(2);
63
+ expect(mockFetch).toHaveBeenCalledWith(
64
+ `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
65
+ expect.any(Object)
66
+ );
67
+ expect(mockFetch).toHaveBeenCalledWith(
68
+ `https://api.quickbase.com/v1/tables/${QB_TABLE_ID_1}?appId=${QB_APP_ID}`,
69
+ expect.objectContaining({
70
+ method: "POST",
71
+ headers: expect.objectContaining({
72
+ "QB-Realm-Hostname": `${process.env.QB_REALM}.quickbase.com`,
73
+ Authorization: "QB-TEMP-TOKEN temp_token",
74
+ "Content-Type": "application/json",
75
+ }),
76
+ body: JSON.stringify(mockBody),
77
+ })
78
+ );
79
+ });
80
+ });
@@ -0,0 +1,8 @@
1
+ // tests/vitest/unit/umd.test.ts
2
+ import { test, expect } from "vitest";
3
+ const quickbaseUMD = require("../../dist/umd/quickbase.umd.js");
4
+ const { quickbase: quickbaseESM } = await import("../../dist/esm/quickbase.js");
5
+ test("UMD and ESM builds work in Node.js", () => {
6
+ expect(quickbaseUMD).toBeDefined();
7
+ expect(quickbaseESM).toBeDefined();
8
+ });
package/text.txt ADDED
@@ -0,0 +1,104 @@
1
+ What I’m Trying to Do
2
+ My approach is to ensure AppsApi.ts is generated with getAppById so QuickbaseClient.ts can map it to client.getApp. Steps include:
3
+ Fix fix-spec.ts:
4
+ Add tags: ["Apps"] to /apps/* endpoints to group them into AppsApi.ts.
5
+
6
+ Ensure all endpoints and models are correctly defined and typed.
7
+
8
+ Debug regenerate-client.ts:
9
+ Enhance logging to catch why AppsApi.ts isn’t generated.
10
+
11
+ Test if getAppById appears in another file (e.g., DefaultApi.ts).
12
+
13
+ Update QuickbaseClient.ts:
14
+ Adjust imports to use the correct API class once generated.
15
+
16
+ Test and Iterate:
17
+ Run npm run fix-spec, npm run regenerate, and npm run test to verify AppsApi.ts exists and test.ts works.
18
+
19
+ The latest fix-spec.ts with tags aims to force the generator to create AppsApi.ts, addressing the missing file issue.
20
+ Relevant Project Files
21
+ Here’s a list of files that would help understand and resolve this problem, along with their roles:
22
+ src/code-generation/fix-spec.ts:
23
+ Role: Modifies the original QuickBase spec (e.g., QuickBase_RESTful_*.json) to create quickbase-fixed.json with required endpoints (e.g., /apps/{appId}).
24
+
25
+ Relevance: Defines the spec fed to the generator; errors here affect generation.
26
+
27
+ src/code-generation/quickbase-fixed.json:
28
+ Role: The processed OpenAPI spec used by regenerate-client.ts to generate code.
29
+
30
+ Relevance: Confirms if /apps/{appId} is correctly structured with operationId: "getAppById".
31
+
32
+ src/code-generation/regenerate-client.ts:
33
+ Role: Runs OpenAPI Generator to produce src/generated/ files (APIs and models) and fixes .ts extensions with ts-morph.
34
+
35
+ Relevance: Controls the generation process; logs reveal why AppsApi.ts is missing.
36
+
37
+ src/generated/apis/AppsApi.ts (if exists):
38
+ Role: Should contain getAppById method for /apps/{appId} GET.
39
+
40
+ Relevance: Missing file is the core issue; its absence breaks QuickbaseClient.ts.
41
+
42
+ src/generated/apis/DefaultApi.ts:
43
+ Role: Default API class for untagged operations.
44
+
45
+ Relevance: Might contain getAppById if tags are misconfigured.
46
+
47
+ src/QuickbaseClient.ts:
48
+ Role: Wraps generated API classes (e.g., AppsApi) in a Proxy for ergonomic calls (e.g., client.getApp).
49
+
50
+ Relevance: Fails to import AppsApi.ts, causing the runtime error.
51
+
52
+ src/test.ts:
53
+ Role: Test script calling client.getApp({ appId }).
54
+
55
+ Relevance: Final validation point; shows if the fix works.
56
+
57
+ .env.development:
58
+ Role: Stores QB_REALM, QB_USER_TOKEN, QB_APP_ID for API authentication.
59
+
60
+ Relevance: Ensures the API call has valid credentials (not the current issue, but critical for success).
61
+
62
+ src/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json (or similar):
63
+ Role: Original QuickBase API spec before fix-spec.ts processing.
64
+
65
+ Relevance: Shows how /apps/{appId} was originally defined, helping identify conflicts.
66
+
67
+ package.json:
68
+ Role: Defines scripts (fix-spec, regenerate, test) and dependencies (e.g., ts-node, openapi-generator-cli).
69
+
70
+ Relevance: Confirms script commands and versions align with our process.
71
+
72
+
73
+
74
+
75
+ What We Achieved
76
+ Goal Met: You can now call client.getApp({ appId: "buwai2zpe" }) and get the app details { id: 'buwai2zpe', name: 'qb-copy' }.
77
+
78
+ Fixes Applied:
79
+ Added tags: ["Apps"] in fix-spec.ts to ensure AppsApi.ts is generated with getAppById.
80
+
81
+ Updated QuickbaseClient.ts to:
82
+ Use prototype methods via Object.getOwnPropertyNames.
83
+
84
+ Bind methods to preserve context with .bind(api).
85
+
86
+ Handle getAppById’s direct JSON return instead of a Response object.
87
+
88
+ Result: The ergonomic API you wanted (client.getApp) works seamlessly with the generated AppsApi.ts.
89
+
90
+ Why It Works Now
91
+ fix-spec.ts:
92
+ Correctly defined /apps/{appId} with operationId: "getAppById" and tags: ["Apps"], ensuring AppsApi.ts generation.
93
+
94
+ regenerate-client.ts:
95
+ Successfully ran OpenAPI Generator to produce AppsApi.ts with getAppById.
96
+
97
+ QuickbaseClient.ts:
98
+ buildMethodMap now captures getAppById and maps it to getApp.
99
+
100
+ invokeMethod passes { appId: 'buwai2zpe' } as requestParameters and handles the JSON response directly.
101
+
102
+ test.ts:
103
+ Calls client.getApp and logs the result, proving the end-to-end flow.
104
+