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.
- package/README.md +252 -126
- package/dist/esm/quickbase.d.ts +2725 -2689
- package/dist/esm/quickbase.js +1763 -3524
- package/dist/esm/quickbase.js.map +1 -1
- package/dist/esm/quickbase.min.js +1 -1
- package/dist/esm/quickbase.min.js.map +1 -1
- package/dist/umd/quickbase.umd.js +1762 -3706
- package/dist/umd/quickbase.umd.js.map +1 -1
- package/dist/umd/quickbase.umd.min.js +1 -1
- package/dist/umd/quickbase.umd.min.js.map +1 -1
- package/package.json +27 -12
- package/CHANGELOG.md +0 -155
- package/build-common.js +0 -131
- package/build-esm.js +0 -71
- package/build-umd.js +0 -69
- package/examples/quicbase-jsCDN.html +0 -36
- package/examples/react.js +0 -48
- package/examples/vanillajs.html +0 -47
- package/open-api/fix-spec-main.ts +0 -97
- package/open-api/generate-override-report.ts +0 -214
- package/open-api/generate-unified-interface.ts +0 -256
- package/open-api/output/override-report.html +0 -11
- package/open-api/output/override-report.json +0 -14395
- package/open-api/output/quickbase-fixed.json +0 -11191
- package/open-api/regenerate-client.ts +0 -116
- package/open-api/schema/enhance-general.ts +0 -100
- package/open-api/schema/fix-arrays.ts +0 -69
- package/open-api/schema/tags/apps.ts +0 -90
- package/open-api/schema/tags/fields.ts +0 -471
- package/open-api/schema/tags/groups.ts +0 -51
- package/open-api/schema/tags/index.ts +0 -66
- package/open-api/schema/tags/records.ts +0 -115
- package/open-api/schema/tags/tables.ts +0 -211
- package/open-api/schema/tags/users.ts +0 -47
- package/open-api/types/spec.ts +0 -42
- package/open-api/utils/infer-schema.ts +0 -40
- package/open-api/utils/naming.ts +0 -10
- package/playwright.config.ts +0 -37
- package/rollup.config.js +0 -114
- package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
- package/specs/split/apps.json +0 -1315
- package/specs/split/auth.json +0 -191
- package/specs/split/fields.json +0 -3869
- package/specs/split/records.json +0 -754
- package/specs/split/reports.json +0 -619
- package/specs/split/tables.json +0 -1605
- package/src/RateLimitError.ts +0 -12
- package/src/ThrottleBucket.ts +0 -36
- package/src/generated-unified/QuickbaseClient.ts +0 -359
- package/src/generated-unified/missing-types-report.json +0 -3
- package/src/index.ts +0 -1
- package/src/invokeMethod.ts +0 -357
- package/src/quickbaseClient.ts +0 -244
- package/src/tokenCache.ts +0 -51
- package/src/utils.ts +0 -7
- package/test-esm.js +0 -1
- package/test-results.json +0 -2050
- package/test-umd.js +0 -1
- package/test.ts +0 -1
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
- package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
- package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
- package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
- package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
- package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
- package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
- package/tests/setup.ts +0 -53
- package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
- package/tests/vitest/qb/apps/createApp.test.ts +0 -64
- package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
- package/tests/vitest/qb/apps/getApp.test.ts +0 -44
- package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
- package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
- package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -56
- package/tests/vitest/qb/fields/createField.test.ts +0 -77
- package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
- package/tests/vitest/qb/fields/getField.test.ts +0 -85
- package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -174
- package/tests/vitest/qb/fields/getFields.test.ts +0 -232
- package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
- package/tests/vitest/qb/fields/updateField.test.ts +0 -93
- package/tests/vitest/qb/index.ts +0 -29
- package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
- package/tests/vitest/qb/records/runQuery.test.ts +0 -146
- package/tests/vitest/qb/records/upsert.test.ts +0 -102
- package/tests/vitest/qb/tables/createTable.test.ts +0 -55
- package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
- package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
- package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
- package/tests/vitest/qb/tables/getTable.test.ts +0 -26
- package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -277
- package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
- package/tests/vitest/unit/apps/copyApp.test.ts +0 -488
- package/tests/vitest/unit/apps/createApp.test.ts +0 -186
- package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
- package/tests/vitest/unit/apps/getApp.test.ts +0 -128
- package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
- package/tests/vitest/unit/apps/updateApp.test.ts +0 -381
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -62
- package/tests/vitest/unit/auth/getTempToken.test.ts +0 -95
- package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -113
- package/tests/vitest/unit/auth/retryTempTokenTwo401.test.ts +0 -81
- package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -56
- package/tests/vitest/unit/fields/createField.test.ts +0 -387
- package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
- package/tests/vitest/unit/fields/getField.test.ts +0 -189
- package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -166
- package/tests/vitest/unit/fields/getFields.test.ts +0 -122
- package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
- package/tests/vitest/unit/fields/updateField.test.ts +0 -280
- package/tests/vitest/unit/index.ts +0 -33
- package/tests/vitest/unit/rateLimit.test.ts +0 -189
- package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
- package/tests/vitest/unit/records/runQuery.test.ts +0 -102
- package/tests/vitest/unit/records/upsert.test.ts +0 -234
- package/tests/vitest/unit/tables/createTable.test.ts +0 -70
- package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
- package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
- package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
- package/tests/vitest/unit/tables/getTable.test.ts +0 -233
- package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -305
- package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
- package/tests/vitest/unit/tokenLifespan.test.ts +0 -138
- package/tests/vitest/unit/umd.test.ts +0 -8
- package/text.txt +0 -104
- package/tools/log-gen.ts +0 -235
- package/tools/log-gen.yaml +0 -4982
- package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
- package/tsconfig.build.json +0 -17
- package/tsconfig.json +0 -32
- package/versionrc.json +0 -9
- package/vitest.config.ts +0 -27
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
// tests/vitest/unit/tables/updateRelationship.test.ts
|
|
2
|
-
|
|
3
|
-
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
4
|
-
import {
|
|
5
|
-
createClient,
|
|
6
|
-
mockFetch,
|
|
7
|
-
QB_REALM,
|
|
8
|
-
QB_USER_TOKEN,
|
|
9
|
-
QB_TABLE_ID_1,
|
|
10
|
-
} from "@tests/setup.ts";
|
|
11
|
-
import {
|
|
12
|
-
UpdateRelationshipRequest,
|
|
13
|
-
UpdateRelationship200Response,
|
|
14
|
-
} from "@/generated/models";
|
|
15
|
-
|
|
16
|
-
describe("QuickbaseClient Unit - updateRelationship", () => {
|
|
17
|
-
let client: ReturnType<typeof createClient>;
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
mockFetch.mockClear();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("initializes without errors and has updateRelationship method", () => {
|
|
24
|
-
client = createClient(mockFetch, { debug: true });
|
|
25
|
-
expect(client).toBeDefined();
|
|
26
|
-
expect(typeof client.updateRelationship).toBe("function");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("updates relationship successfully with user token", async () => {
|
|
30
|
-
client = createClient(mockFetch, { debug: true });
|
|
31
|
-
|
|
32
|
-
const tableId = QB_TABLE_ID_1;
|
|
33
|
-
const relationshipId = 6;
|
|
34
|
-
|
|
35
|
-
const request: UpdateRelationshipRequest = {
|
|
36
|
-
lookupFieldIds: [4, 5, 6],
|
|
37
|
-
summaryFields: [
|
|
38
|
-
{
|
|
39
|
-
summaryFid: 3,
|
|
40
|
-
label: "my summary field",
|
|
41
|
-
accumulationType: "COUNT",
|
|
42
|
-
where: "{'3'.EX.'1'}",
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const mockResponse: UpdateRelationship200Response = {
|
|
48
|
-
id: relationshipId,
|
|
49
|
-
parentTableId: "bck7gp3q2",
|
|
50
|
-
childTableId: tableId,
|
|
51
|
-
foreignKeyField: {
|
|
52
|
-
id: relationshipId,
|
|
53
|
-
label: "Related record",
|
|
54
|
-
type: "numeric",
|
|
55
|
-
},
|
|
56
|
-
isCrossApp: false,
|
|
57
|
-
lookupFields: [
|
|
58
|
-
{ id: 4, label: "Field 4", type: "text" },
|
|
59
|
-
{ id: 5, label: "Field 5", type: "numeric" },
|
|
60
|
-
{ id: 6, label: "Field 6", type: "date" },
|
|
61
|
-
],
|
|
62
|
-
summaryFields: [{ id: 8, label: "my summary field", type: "numeric" }],
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
mockFetch.mockResolvedValueOnce({
|
|
66
|
-
ok: true,
|
|
67
|
-
status: 200,
|
|
68
|
-
json: () => Promise.resolve(mockResponse),
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const result = await client.updateRelationship({
|
|
72
|
-
tableId,
|
|
73
|
-
relationshipId,
|
|
74
|
-
body: request,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
expect(result).toEqual(mockResponse);
|
|
78
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
79
|
-
`https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`, // Changed to singular
|
|
80
|
-
expect.objectContaining({
|
|
81
|
-
method: "POST",
|
|
82
|
-
headers: expect.objectContaining({
|
|
83
|
-
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
84
|
-
Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
|
|
85
|
-
"Content-Type": "application/json",
|
|
86
|
-
}),
|
|
87
|
-
body: JSON.stringify(request),
|
|
88
|
-
credentials: "omit",
|
|
89
|
-
})
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("updates relationship successfully with temp token", async () => {
|
|
94
|
-
client = createClient(mockFetch, { useTempTokens: true, debug: true });
|
|
95
|
-
|
|
96
|
-
const tableId = QB_TABLE_ID_1;
|
|
97
|
-
const relationshipId = 6;
|
|
98
|
-
|
|
99
|
-
const request: UpdateRelationshipRequest = {
|
|
100
|
-
lookupFieldIds: [7],
|
|
101
|
-
summaryFields: [
|
|
102
|
-
{
|
|
103
|
-
summaryFid: 0,
|
|
104
|
-
label: "Count of Records",
|
|
105
|
-
accumulationType: "COUNT",
|
|
106
|
-
where: "{'3'.GT.0}",
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const mockResponse: UpdateRelationship200Response = {
|
|
112
|
-
id: relationshipId,
|
|
113
|
-
parentTableId: "bck7gp3q2",
|
|
114
|
-
childTableId: tableId,
|
|
115
|
-
foreignKeyField: {
|
|
116
|
-
id: relationshipId,
|
|
117
|
-
label: "Related record",
|
|
118
|
-
type: "numeric",
|
|
119
|
-
},
|
|
120
|
-
isCrossApp: false,
|
|
121
|
-
lookupFields: [{ id: 7, label: "record - text field", type: "text" }],
|
|
122
|
-
summaryFields: [{ id: 9, label: "Count of Records", type: "numeric" }],
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
mockFetch
|
|
126
|
-
.mockResolvedValueOnce({
|
|
127
|
-
ok: true,
|
|
128
|
-
status: 200,
|
|
129
|
-
json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
|
|
130
|
-
})
|
|
131
|
-
.mockResolvedValueOnce({
|
|
132
|
-
ok: true,
|
|
133
|
-
status: 200,
|
|
134
|
-
json: () => Promise.resolve(mockResponse),
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const result = await client.updateRelationship({
|
|
138
|
-
tableId,
|
|
139
|
-
relationshipId,
|
|
140
|
-
body: request,
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
expect(result).toEqual(mockResponse);
|
|
144
|
-
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
145
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
146
|
-
1,
|
|
147
|
-
`https://api.quickbase.com/v1/auth/temporary/${tableId}`,
|
|
148
|
-
expect.objectContaining({
|
|
149
|
-
method: "GET",
|
|
150
|
-
headers: expect.objectContaining({
|
|
151
|
-
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
152
|
-
"Content-Type": "application/json",
|
|
153
|
-
}),
|
|
154
|
-
credentials: "include",
|
|
155
|
-
})
|
|
156
|
-
);
|
|
157
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
158
|
-
2,
|
|
159
|
-
`https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`, // Changed to singular
|
|
160
|
-
expect.objectContaining({
|
|
161
|
-
method: "POST",
|
|
162
|
-
headers: expect.objectContaining({
|
|
163
|
-
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
164
|
-
Authorization: "QB-TEMP-TOKEN temp_token",
|
|
165
|
-
"Content-Type": "application/json",
|
|
166
|
-
}),
|
|
167
|
-
body: JSON.stringify(request),
|
|
168
|
-
credentials: "omit",
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("retries successfully after 401 with temp token", async () => {
|
|
174
|
-
client = createClient(mockFetch, { useTempTokens: true, debug: true });
|
|
175
|
-
|
|
176
|
-
const tableId = QB_TABLE_ID_1;
|
|
177
|
-
const relationshipId = 6;
|
|
178
|
-
|
|
179
|
-
const request: UpdateRelationshipRequest = {
|
|
180
|
-
lookupFieldIds: [4],
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
const mockResponse: UpdateRelationship200Response = {
|
|
184
|
-
id: relationshipId,
|
|
185
|
-
parentTableId: "bck7gp3q2",
|
|
186
|
-
childTableId: tableId,
|
|
187
|
-
foreignKeyField: {
|
|
188
|
-
id: relationshipId,
|
|
189
|
-
label: "Related record",
|
|
190
|
-
type: "numeric",
|
|
191
|
-
},
|
|
192
|
-
isCrossApp: false,
|
|
193
|
-
lookupFields: [{ id: 4, label: "Field 4", type: "text" }],
|
|
194
|
-
summaryFields: [],
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
mockFetch
|
|
198
|
-
.mockResolvedValueOnce({
|
|
199
|
-
ok: true,
|
|
200
|
-
status: 200,
|
|
201
|
-
json: () =>
|
|
202
|
-
Promise.resolve({ temporaryAuthorization: "initial_token" }),
|
|
203
|
-
})
|
|
204
|
-
.mockResolvedValueOnce({
|
|
205
|
-
ok: false,
|
|
206
|
-
status: 401,
|
|
207
|
-
json: () => Promise.resolve({ message: "Unauthorized" }),
|
|
208
|
-
})
|
|
209
|
-
.mockResolvedValueOnce({
|
|
210
|
-
ok: true,
|
|
211
|
-
status: 200,
|
|
212
|
-
json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
|
|
213
|
-
})
|
|
214
|
-
.mockResolvedValueOnce({
|
|
215
|
-
ok: true,
|
|
216
|
-
status: 200,
|
|
217
|
-
json: () => Promise.resolve(mockResponse),
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
const consoleSpy = vi.spyOn(console, "log");
|
|
221
|
-
const result = await client.updateRelationship({
|
|
222
|
-
tableId,
|
|
223
|
-
relationshipId,
|
|
224
|
-
body: request,
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
expect(result).toEqual(mockResponse);
|
|
228
|
-
expect(mockFetch).toHaveBeenCalledTimes(4);
|
|
229
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
230
|
-
1,
|
|
231
|
-
`https://api.quickbase.com/v1/auth/temporary/${tableId}`,
|
|
232
|
-
expect.any(Object)
|
|
233
|
-
);
|
|
234
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
235
|
-
2,
|
|
236
|
-
`https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`, // Changed to singular
|
|
237
|
-
expect.objectContaining({
|
|
238
|
-
headers: expect.objectContaining({
|
|
239
|
-
Authorization: "QB-TEMP-TOKEN initial_token",
|
|
240
|
-
}),
|
|
241
|
-
})
|
|
242
|
-
);
|
|
243
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
244
|
-
3,
|
|
245
|
-
`https://api.quickbase.com/v1/auth/temporary/${tableId}`,
|
|
246
|
-
expect.any(Object)
|
|
247
|
-
);
|
|
248
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
249
|
-
4,
|
|
250
|
-
`https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`, // Changed to singular
|
|
251
|
-
expect.objectContaining({
|
|
252
|
-
headers: expect.objectContaining({
|
|
253
|
-
Authorization: "QB-TEMP-TOKEN new_token",
|
|
254
|
-
}),
|
|
255
|
-
})
|
|
256
|
-
);
|
|
257
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
258
|
-
"Authorization error for updateRelationship (temp token), refreshing token:",
|
|
259
|
-
expect.any(String)
|
|
260
|
-
);
|
|
261
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
262
|
-
"Retrying updateRelationship with temp token"
|
|
263
|
-
);
|
|
264
|
-
consoleSpy.mockRestore();
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it("handles 400 error for invalid request", async () => {
|
|
268
|
-
client = createClient(mockFetch, { debug: true });
|
|
269
|
-
|
|
270
|
-
const tableId = QB_TABLE_ID_1;
|
|
271
|
-
const relationshipId = 6;
|
|
272
|
-
|
|
273
|
-
const request: UpdateRelationshipRequest = {
|
|
274
|
-
lookupFieldIds: [-1],
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
mockFetch.mockResolvedValueOnce({
|
|
278
|
-
ok: false,
|
|
279
|
-
status: 400,
|
|
280
|
-
json: () => Promise.resolve({ message: "Invalid field ID" }),
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
await expect(
|
|
284
|
-
client.updateRelationship({
|
|
285
|
-
tableId,
|
|
286
|
-
relationshipId,
|
|
287
|
-
body: request,
|
|
288
|
-
})
|
|
289
|
-
).rejects.toThrow("API Error: Invalid field ID (Status: 400)");
|
|
290
|
-
|
|
291
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
292
|
-
`https://api.quickbase.com/v1/tables/${tableId}/relationship/${relationshipId}`, // Changed to singular
|
|
293
|
-
expect.objectContaining({
|
|
294
|
-
method: "POST",
|
|
295
|
-
headers: expect.objectContaining({
|
|
296
|
-
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
297
|
-
Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
|
|
298
|
-
"Content-Type": "application/json",
|
|
299
|
-
}),
|
|
300
|
-
body: JSON.stringify(request),
|
|
301
|
-
credentials: "omit",
|
|
302
|
-
})
|
|
303
|
-
);
|
|
304
|
-
});
|
|
305
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2
|
-
import { createClient, mockFetch, QB_APP_ID, QB_REALM } from "@tests/setup.ts";
|
|
3
|
-
import { UpdateAppRequest, UpdateApp200Response } from "@/generated/models";
|
|
4
|
-
|
|
5
|
-
describe("QuickbaseClient Unit - Token Lifespan", () => {
|
|
6
|
-
let client: ReturnType<typeof createClient>;
|
|
7
|
-
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
mockFetch.mockClear();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("reuses token within lifespan and fetches new token after expiration", async () => {
|
|
13
|
-
// Set a short lifespan of 500ms for testing
|
|
14
|
-
client = createClient(mockFetch, {
|
|
15
|
-
realm: QB_REALM,
|
|
16
|
-
useTempTokens: true,
|
|
17
|
-
tokenLifespan: 500, // 0.5 seconds
|
|
18
|
-
debug: true,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const request: UpdateAppRequest = {
|
|
22
|
-
name: "Test App",
|
|
23
|
-
};
|
|
24
|
-
const mockResponse: UpdateApp200Response = {
|
|
25
|
-
id: QB_APP_ID,
|
|
26
|
-
name: "Test App",
|
|
27
|
-
description: "",
|
|
28
|
-
created: new Date("2020-01-01T00:00:00Z"),
|
|
29
|
-
updated: new Date("2020-01-01T00:00:00Z"),
|
|
30
|
-
dateFormat: "MM-DD-YYYY",
|
|
31
|
-
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
32
|
-
hasEveryoneOnTheInternet: false,
|
|
33
|
-
ancestorId: null,
|
|
34
|
-
variables: [],
|
|
35
|
-
securityProperties: {},
|
|
36
|
-
memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
|
|
37
|
-
dataClassification: "None",
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// First call: Fetch a new token
|
|
41
|
-
mockFetch
|
|
42
|
-
.mockResolvedValueOnce({
|
|
43
|
-
ok: true,
|
|
44
|
-
status: 200,
|
|
45
|
-
json: () => Promise.resolve({ temporaryAuthorization: "token1" }),
|
|
46
|
-
})
|
|
47
|
-
.mockResolvedValueOnce({
|
|
48
|
-
ok: true,
|
|
49
|
-
status: 200,
|
|
50
|
-
json: () => Promise.resolve(mockResponse),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
await client.updateApp({ appId: QB_APP_ID, body: request });
|
|
54
|
-
expect(mockFetch).toHaveBeenCalledTimes(2); // Token fetch + API call
|
|
55
|
-
|
|
56
|
-
// Second call within lifespan: Should reuse token1
|
|
57
|
-
mockFetch.mockResolvedValueOnce({
|
|
58
|
-
ok: true,
|
|
59
|
-
status: 200,
|
|
60
|
-
json: () => Promise.resolve(mockResponse),
|
|
61
|
-
});
|
|
62
|
-
await client.updateApp({ appId: QB_APP_ID, body: request });
|
|
63
|
-
expect(mockFetch).toHaveBeenCalledTimes(3); // Only API call, no new token fetch
|
|
64
|
-
|
|
65
|
-
// Wait for token to expire (500ms + buffer)
|
|
66
|
-
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
67
|
-
|
|
68
|
-
// Third call after expiration: Should fetch a new token
|
|
69
|
-
mockFetch
|
|
70
|
-
.mockResolvedValueOnce({
|
|
71
|
-
ok: true,
|
|
72
|
-
status: 200,
|
|
73
|
-
json: () => Promise.resolve({ temporaryAuthorization: "token2" }),
|
|
74
|
-
})
|
|
75
|
-
.mockResolvedValueOnce({
|
|
76
|
-
ok: true,
|
|
77
|
-
status: 200,
|
|
78
|
-
json: () => Promise.resolve(mockResponse),
|
|
79
|
-
});
|
|
80
|
-
await client.updateApp({ appId: QB_APP_ID, body: request });
|
|
81
|
-
expect(mockFetch).toHaveBeenCalledTimes(5); // New token fetch + API call
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("uses default lifespan when not specified", async () => {
|
|
85
|
-
// No tokenLifespan provided, should use default (4:50 = 290,000ms)
|
|
86
|
-
client = createClient(mockFetch, {
|
|
87
|
-
realm: QB_REALM,
|
|
88
|
-
useTempTokens: true,
|
|
89
|
-
debug: true,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const request: UpdateAppRequest = {
|
|
93
|
-
name: "Default Lifespan Test",
|
|
94
|
-
};
|
|
95
|
-
const mockResponse: UpdateApp200Response = {
|
|
96
|
-
id: QB_APP_ID,
|
|
97
|
-
name: "Default Lifespan Test",
|
|
98
|
-
description: "",
|
|
99
|
-
created: new Date("2020-01-01T00:00:00Z"),
|
|
100
|
-
updated: new Date("2020-01-01T00:00:00Z"),
|
|
101
|
-
dateFormat: "MM-DD-YYYY",
|
|
102
|
-
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
103
|
-
hasEveryoneOnTheInternet: false,
|
|
104
|
-
ancestorId: null,
|
|
105
|
-
variables: [],
|
|
106
|
-
securityProperties: {},
|
|
107
|
-
memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
|
|
108
|
-
dataClassification: "None",
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// First call: Fetch a new token
|
|
112
|
-
mockFetch
|
|
113
|
-
.mockResolvedValueOnce({
|
|
114
|
-
ok: true,
|
|
115
|
-
status: 200,
|
|
116
|
-
json: () =>
|
|
117
|
-
Promise.resolve({ temporaryAuthorization: "default_token" }),
|
|
118
|
-
})
|
|
119
|
-
.mockResolvedValueOnce({
|
|
120
|
-
ok: true,
|
|
121
|
-
status: 200,
|
|
122
|
-
json: () => Promise.resolve(mockResponse),
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
await client.updateApp({ appId: QB_APP_ID, body: request });
|
|
126
|
-
expect(mockFetch).toHaveBeenCalledTimes(2); // Token fetch + API call
|
|
127
|
-
|
|
128
|
-
// Second call within default lifespan (e.g., after 1 second, well below 4:50)
|
|
129
|
-
mockFetch.mockResolvedValueOnce({
|
|
130
|
-
ok: true,
|
|
131
|
-
status: 200,
|
|
132
|
-
json: () => Promise.resolve(mockResponse),
|
|
133
|
-
});
|
|
134
|
-
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait 1 second
|
|
135
|
-
await client.updateApp({ appId: QB_APP_ID, body: request });
|
|
136
|
-
expect(mockFetch).toHaveBeenCalledTimes(3); // No new token fetch, still within 4:50
|
|
137
|
-
});
|
|
138
|
-
});
|
|
@@ -1,8 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
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
|
-
|