quickbase-js 1.1.0-beta.2 → 1.1.0-beta.4
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/CHANGELOG.md +53 -22
- package/README.md +61 -5
- package/dist/quickbase.d.ts +1711 -613
- package/dist/quickbase.js +1469 -468
- package/dist/quickbase.js.map +1 -1
- package/examples/react.js +12 -12
- package/examples/vanillajs.html +12 -12
- package/log-gen.yaml +3558 -528
- package/package.json +12 -14
- package/playwright-results.txt/.last-run.json +4 -0
- package/playwright.config.ts +1 -1
- package/src/code-generation/definitions/apps.ts +274 -0
- package/src/code-generation/definitions/auth.ts +10 -0
- package/src/code-generation/definitions/fields.ts +751 -0
- package/src/code-generation/definitions/index.ts +18 -0
- package/src/code-generation/definitions/records.ts +269 -0
- package/src/code-generation/definitions/relationships.ts +90 -0
- package/src/code-generation/definitions/reports.ts +10 -0
- package/src/code-generation/definitions/tables.ts +112 -0
- package/src/code-generation/fix-spec-main.ts +2 -2
- package/src/code-generation/output/quickbase-fixed.json +1724 -3044
- package/src/code-generation/paths/apps.ts +100 -0
- package/src/code-generation/paths/auth.ts +25 -0
- package/src/code-generation/paths/fields.ts +207 -0
- package/src/code-generation/paths/index.ts +17 -0
- package/src/code-generation/paths/records.ts +68 -0
- package/src/code-generation/paths/relationships.ts +32 -0
- package/src/code-generation/paths/reports.ts +34 -0
- package/src/code-generation/paths/tables.ts +162 -0
- package/src/generated-unified/QuickbaseClient.ts +10 -8
- package/src/log-gen.ts +6 -2
- package/src/quickbaseClient.ts +35 -41
- package/tests/setup.ts +5 -1
- package/tests/vitest/qb/apps/copyApp.test.ts +76 -0
- package/tests/vitest/qb/apps/createApp.test.ts +64 -0
- package/tests/vitest/qb/apps/deleteApp.test.ts +76 -0
- package/tests/vitest/qb/fields/createField.test.ts +78 -0
- package/tests/vitest/qb/fields/deleteFields.test.ts +89 -0
- package/tests/vitest/qb/fields/getField.test.ts +85 -0
- package/tests/vitest/qb/fields/getFieldUsage.test.ts +174 -0
- package/tests/vitest/qb/fields/getFieldsUsage.test.ts +77 -0
- package/tests/vitest/qb/index.ts +25 -1
- package/tests/vitest/qb/records/deleteRecords.test.ts +42 -10
- package/tests/vitest/qb/records/runQuery.test.ts +81 -17
- package/tests/vitest/qb/records/upsert.test.ts +33 -3
- package/tests/vitest/qb/tables/getRelationships.test.ts +80 -0
- package/tests/vitest/unit/apps/copyApp.test.ts +282 -0
- package/tests/vitest/unit/apps/createApp.test.ts +125 -0
- package/tests/vitest/unit/apps/deleteApp.test.ts +215 -0
- package/tests/vitest/unit/fields/createField.test.ts +391 -0
- package/tests/vitest/unit/fields/deleteFields.test.ts +141 -0
- package/tests/vitest/unit/fields/getField.test.ts +189 -0
- package/tests/vitest/unit/fields/getFieldUsage.test.ts +147 -0
- package/tests/vitest/unit/fields/getFieldsUsage.test.ts +160 -0
- package/tests/vitest/unit/index.ts +30 -1
- package/tests/vitest/unit/tables/getRelationships.test.ts +259 -0
- package/src/code-generation/fix-spec-definitions.ts +0 -543
- package/src/code-generation/fix-spec-paths.ts +0 -355
- package/test-artifacts/test-results.json +0 -829
package/src/log-gen.ts
CHANGED
|
@@ -13,11 +13,15 @@ const excludeDirs: string[] = ["node_modules", ".git", "specs"];
|
|
|
13
13
|
// prettier-ignore
|
|
14
14
|
const includeFolders: string[] = [
|
|
15
15
|
// "src/code-generation",
|
|
16
|
+
// "src/code-generation/definitions",
|
|
17
|
+
// "src/code-generation/paths",
|
|
16
18
|
];
|
|
17
19
|
|
|
18
20
|
// prettier-ignore
|
|
19
21
|
const includeRecursiveFolders: string[] = [
|
|
20
22
|
"tests",
|
|
23
|
+
"tests/vitest/unit",
|
|
24
|
+
"tests/vitest/qb"
|
|
21
25
|
];
|
|
22
26
|
|
|
23
27
|
// prettier-ignore
|
|
@@ -73,8 +77,8 @@ const pipelineOverview: string[] = [
|
|
|
73
77
|
"getTempTokenDBID() method is wrapped to enhance temporary token generation reuse interacting with a token cache.",
|
|
74
78
|
"#",
|
|
75
79
|
"npm run fix-spec: Generates quickbase-fixed.json from the latest QuickBase_RESTful*.json file.",
|
|
76
|
-
"npm run regenerate: Generates raw TypeScript-fetch files in src/generated/.",
|
|
77
|
-
"npm run generate
|
|
80
|
+
"npm run regenerate:openapi Generates raw TypeScript-fetch files in src/generated/.",
|
|
81
|
+
"npm run generate:unified: Generates a unified QuickbaseClient.ts interface in src/generated-unified/.",
|
|
78
82
|
];
|
|
79
83
|
|
|
80
84
|
interface TreeNode {
|
package/src/quickbaseClient.ts
CHANGED
|
@@ -79,15 +79,15 @@ export function quickbase(config: QuickbaseConfig): QuickbaseClient {
|
|
|
79
79
|
|
|
80
80
|
const tokenCache = new TokenCache();
|
|
81
81
|
|
|
82
|
-
const
|
|
82
|
+
const baseHeaders: HTTPHeaders = {
|
|
83
83
|
"QB-Realm-Hostname": `${realm}.quickbase.com`,
|
|
84
84
|
"Content-Type": "application/json",
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
if (initialTempToken) {
|
|
88
|
-
|
|
88
|
+
baseHeaders["Authorization"] = `QB-TEMP-TOKEN ${initialTempToken}`;
|
|
89
89
|
} else if (userToken && !useTempTokens) {
|
|
90
|
-
|
|
90
|
+
baseHeaders["Authorization"] = `QB-USER-TOKEN ${userToken}`;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
const defaultFetch: typeof fetch | undefined =
|
|
@@ -96,7 +96,7 @@ export function quickbase(config: QuickbaseConfig): QuickbaseClient {
|
|
|
96
96
|
: undefined;
|
|
97
97
|
const configuration = new Configuration({
|
|
98
98
|
basePath: baseUrl,
|
|
99
|
-
headers: { ...
|
|
99
|
+
headers: { ...baseHeaders },
|
|
100
100
|
fetchApi: fetchApi || defaultFetch,
|
|
101
101
|
credentials: useTempTokens ? "include" : "omit",
|
|
102
102
|
});
|
|
@@ -162,7 +162,7 @@ export function quickbase(config: QuickbaseConfig): QuickbaseClient {
|
|
|
162
162
|
`https://api.quickbase.com/v1/auth/temporary/${dbid}`,
|
|
163
163
|
{
|
|
164
164
|
method: "GET",
|
|
165
|
-
headers: { ...
|
|
165
|
+
headers: { ...baseHeaders },
|
|
166
166
|
credentials: "include",
|
|
167
167
|
}
|
|
168
168
|
);
|
|
@@ -194,23 +194,24 @@ export function quickbase(config: QuickbaseConfig): QuickbaseClient {
|
|
|
194
194
|
return token;
|
|
195
195
|
};
|
|
196
196
|
|
|
197
|
-
|
|
197
|
+
async function invokeMethod<K extends keyof QuickbaseClient>(
|
|
198
198
|
methodName: K,
|
|
199
199
|
params: Parameters<QuickbaseClient[K]>[0] & Partial<TempTokenParams>,
|
|
200
200
|
retryCount: number = 0
|
|
201
|
-
): Promise<ReturnType<QuickbaseClient[K]>>
|
|
201
|
+
): Promise<ReturnType<QuickbaseClient[K]>> {
|
|
202
202
|
const methodInfo = methodMap[methodName];
|
|
203
203
|
if (!methodInfo) {
|
|
204
204
|
throw new Error(`Method ${methodName} not found`);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
const
|
|
207
|
+
const requestParameters =
|
|
208
208
|
methodInfo.paramMap.length === 1 &&
|
|
209
209
|
methodInfo.paramMap[0] === "requestParameters"
|
|
210
|
-
?
|
|
211
|
-
:
|
|
210
|
+
? { requestParameters: params }
|
|
211
|
+
: params;
|
|
212
|
+
let requestOptions: RequestInit = {};
|
|
212
213
|
|
|
213
|
-
|
|
214
|
+
const selectedToken =
|
|
214
215
|
initialTempToken || (userToken && !useTempTokens ? userToken : undefined);
|
|
215
216
|
|
|
216
217
|
if (methodName === "getTempTokenDBID" && useTempTokens) {
|
|
@@ -223,43 +224,38 @@ export function quickbase(config: QuickbaseConfig): QuickbaseClient {
|
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
|
|
226
|
-
|
|
227
|
+
let authorizationToken = selectedToken;
|
|
228
|
+
if (useTempTokens && !authorizationToken) {
|
|
227
229
|
const dbid = extractDbid(
|
|
228
230
|
params,
|
|
229
231
|
`No dbid found in params for ${methodName} to fetch temp token`
|
|
230
232
|
);
|
|
231
233
|
const cachedToken = tokenCache.get(dbid);
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
"Temporary tokens require a browser environment or a custom fetchApi with browser-like session support"
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
token = await fetchTempToken(dbid);
|
|
241
|
-
if (methodName === "getTempTokenDBID") {
|
|
242
|
-
return { temporaryAuthorization: token } as ReturnType<
|
|
243
|
-
QuickbaseClient[K]
|
|
244
|
-
>;
|
|
245
|
-
}
|
|
234
|
+
authorizationToken = cachedToken || (await fetchTempToken(dbid));
|
|
235
|
+
if (methodName === "getTempTokenDBID") {
|
|
236
|
+
return { temporaryAuthorization: authorizationToken } as ReturnType<
|
|
237
|
+
QuickbaseClient[K]
|
|
238
|
+
>;
|
|
246
239
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
240
|
+
requestOptions.headers = {
|
|
241
|
+
...baseHeaders,
|
|
242
|
+
Authorization: `QB-TEMP-TOKEN ${authorizationToken}`,
|
|
243
|
+
};
|
|
244
|
+
} else if (authorizationToken) {
|
|
245
|
+
requestOptions.headers = {
|
|
246
|
+
...baseHeaders,
|
|
247
|
+
Authorization: `QB-USER-TOKEN ${authorizationToken}`,
|
|
252
248
|
};
|
|
253
249
|
}
|
|
254
250
|
|
|
255
251
|
try {
|
|
256
|
-
|
|
257
|
-
return response;
|
|
252
|
+
return await methodInfo.method(requestParameters, requestOptions);
|
|
258
253
|
} catch (error) {
|
|
259
254
|
if (
|
|
260
255
|
error instanceof ResponseError &&
|
|
261
256
|
error.response.status === 401 &&
|
|
262
|
-
retryCount < 1
|
|
257
|
+
retryCount < 1 &&
|
|
258
|
+
useTempTokens
|
|
263
259
|
) {
|
|
264
260
|
if (debug) {
|
|
265
261
|
console.log(
|
|
@@ -271,12 +267,10 @@ export function quickbase(config: QuickbaseConfig): QuickbaseClient {
|
|
|
271
267
|
params,
|
|
272
268
|
`No dbid to refresh token after authorization error`
|
|
273
269
|
);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
Authorization: `QB-TEMP-TOKEN ${token}`,
|
|
279
|
-
},
|
|
270
|
+
authorizationToken = await fetchTempToken(dbid);
|
|
271
|
+
requestOptions.headers = {
|
|
272
|
+
...baseHeaders,
|
|
273
|
+
Authorization: `QB-TEMP-TOKEN ${authorizationToken}`,
|
|
280
274
|
};
|
|
281
275
|
if (debug) {
|
|
282
276
|
console.log(`Retrying ${methodName} with new token`);
|
|
@@ -300,7 +294,7 @@ export function quickbase(config: QuickbaseConfig): QuickbaseClient {
|
|
|
300
294
|
}
|
|
301
295
|
throw error;
|
|
302
296
|
}
|
|
303
|
-
}
|
|
297
|
+
}
|
|
304
298
|
|
|
305
299
|
const proxy = new Proxy<QuickbaseClient>({} as QuickbaseClient, {
|
|
306
300
|
get: (_, prop: string): ((params: any) => Promise<any>) | undefined => {
|
package/tests/setup.ts
CHANGED
|
@@ -13,13 +13,17 @@ export const QB_REALM = process.env.QB_REALM || "test-realm";
|
|
|
13
13
|
export const QB_USER_TOKEN =
|
|
14
14
|
process.env.QB_USER_TOKEN || "user-token-1234567890";
|
|
15
15
|
export const QB_APP_ID = process.env.QB_APP_ID || "app-id-1234567890";
|
|
16
|
-
export const QB_TABLE_ID_1 =
|
|
16
|
+
export const QB_TABLE_ID_1 =
|
|
17
|
+
process.env.QB_TABLE_ID_1 || "table-id-1-1234567890";
|
|
18
|
+
export const QB_TABLE_ID_2 =
|
|
19
|
+
process.env.QB_TABLE_ID_2 || "table-id-2-1234567890";
|
|
17
20
|
|
|
18
21
|
// Mock env variables for consistency, using .env values if available
|
|
19
22
|
vi.stubEnv("QB_REALM", QB_REALM);
|
|
20
23
|
vi.stubEnv("QB_USER_TOKEN", QB_USER_TOKEN);
|
|
21
24
|
vi.stubEnv("QB_APP_ID", QB_APP_ID);
|
|
22
25
|
vi.stubEnv("QB_TABLE_ID_1", QB_TABLE_ID_1);
|
|
26
|
+
vi.stubEnv("QB_TABLE_ID_2", QB_TABLE_ID_2);
|
|
23
27
|
|
|
24
28
|
export const createClient = (
|
|
25
29
|
fetchApi?: any,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// tests/vitest/qb/apps/copyApp.test.ts
|
|
2
|
+
import { test, expect } from "vitest";
|
|
3
|
+
import { quickbase } from "../../../../src/quickbaseClient";
|
|
4
|
+
|
|
5
|
+
test(
|
|
6
|
+
"QuickbaseClient Integration - copyApp > creates a new copied app in QuickBase",
|
|
7
|
+
{ timeout: 30000 }, // Increased to 30 seconds
|
|
8
|
+
async () => {
|
|
9
|
+
const config = {
|
|
10
|
+
realm: process.env.QB_REALM || "",
|
|
11
|
+
userToken: process.env.QB_USER_TOKEN || "",
|
|
12
|
+
debug: true,
|
|
13
|
+
};
|
|
14
|
+
const client = quickbase(config);
|
|
15
|
+
const appId = process.env.QB_APP_ID || ""; // The source app ID to copy from
|
|
16
|
+
|
|
17
|
+
const copyAppName = `CopiedApp_${Date.now()}`; // Unique name to avoid conflicts
|
|
18
|
+
const copyBody = {
|
|
19
|
+
name: copyAppName,
|
|
20
|
+
description: "Test copied app",
|
|
21
|
+
properties: {
|
|
22
|
+
keepData: false,
|
|
23
|
+
excludeFiles: true,
|
|
24
|
+
usersAndRoles: false,
|
|
25
|
+
assignUserToken: true,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
console.log("Config used:", {
|
|
30
|
+
...config,
|
|
31
|
+
userToken: config.userToken ? "[REDACTED]" : "", // Avoid logging sensitive token
|
|
32
|
+
});
|
|
33
|
+
console.log("Copying app with:", copyBody);
|
|
34
|
+
const startTime = Date.now();
|
|
35
|
+
let response;
|
|
36
|
+
try {
|
|
37
|
+
response = await client.copyApp({ appId, body: copyBody });
|
|
38
|
+
const duration = Date.now() - startTime;
|
|
39
|
+
console.log(`copyApp completed in ${duration}ms`);
|
|
40
|
+
console.log("Real API response:", response);
|
|
41
|
+
|
|
42
|
+
expect(response).toBeDefined();
|
|
43
|
+
expect(response.id).toBeDefined();
|
|
44
|
+
expect(response.name).toBe(copyAppName);
|
|
45
|
+
expect(response.description).toBe(copyBody.description);
|
|
46
|
+
expect(response.created).toBeInstanceOf(Date);
|
|
47
|
+
expect(response.updated).toBeInstanceOf(Date);
|
|
48
|
+
expect(response.dateFormat).toMatch(/^\w{2}-\w{2}-\w{4}$/); // e.g., "MM-DD-YYYY"
|
|
49
|
+
expect(typeof response.timeZone).toBe("string"); // Simplified check
|
|
50
|
+
expect(typeof response.hasEveryoneOnTheInternet).toBe("boolean");
|
|
51
|
+
expect(response.ancestorId).toBe(appId); // Should match the source app ID
|
|
52
|
+
expect(
|
|
53
|
+
response.dataClassification === undefined ||
|
|
54
|
+
typeof response.dataClassification === "string"
|
|
55
|
+
).toBe(true); // Allow undefined or string
|
|
56
|
+
expect(
|
|
57
|
+
response.variables === undefined || Array.isArray(response.variables)
|
|
58
|
+
).toBe(true); // Allow undefined or array
|
|
59
|
+
} catch (error) {
|
|
60
|
+
const duration = Date.now() - startTime;
|
|
61
|
+
console.error(`copyApp failed after ${duration}ms:`, error);
|
|
62
|
+
throw error; // Re-throw to fail the test
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Cleanup: Delete the copied app using deleteApp
|
|
66
|
+
const deleteStartTime = Date.now();
|
|
67
|
+
const deleteResponse = await client.deleteApp({
|
|
68
|
+
appId: response.id,
|
|
69
|
+
body: { name: copyAppName },
|
|
70
|
+
});
|
|
71
|
+
const deleteDuration = Date.now() - deleteStartTime;
|
|
72
|
+
console.log(`deleteApp completed in ${deleteDuration}ms`);
|
|
73
|
+
console.log("Cleanup - Deleted app:", deleteResponse);
|
|
74
|
+
expect(deleteResponse.deletedAppId).toBe(response.id);
|
|
75
|
+
}
|
|
76
|
+
);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// tests/vitest/qb/apps/createApp.test.ts
|
|
2
|
+
import { test, expect } from "vitest";
|
|
3
|
+
import { quickbase } from "../../../../src/quickbaseClient";
|
|
4
|
+
|
|
5
|
+
test(
|
|
6
|
+
"QuickbaseClient Integration - createApp > creates a new app in QuickBase",
|
|
7
|
+
{ timeout: 30000 },
|
|
8
|
+
async () => {
|
|
9
|
+
const config = {
|
|
10
|
+
realm: process.env.QB_REALM || "",
|
|
11
|
+
userToken: process.env.QB_USER_TOKEN || "",
|
|
12
|
+
debug: true,
|
|
13
|
+
useTempTokens: false,
|
|
14
|
+
};
|
|
15
|
+
const client = quickbase(config);
|
|
16
|
+
|
|
17
|
+
const appName = `TestApp_${Date.now()}`;
|
|
18
|
+
const createBody = {
|
|
19
|
+
name: appName,
|
|
20
|
+
description: "Test app creation",
|
|
21
|
+
assignToken: true,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
console.log("Config used:", {
|
|
25
|
+
...config,
|
|
26
|
+
userToken: config.userToken ? "[REDACTED]" : "",
|
|
27
|
+
});
|
|
28
|
+
console.log("Creating app with:", createBody);
|
|
29
|
+
const createStartTime = Date.now();
|
|
30
|
+
let response;
|
|
31
|
+
try {
|
|
32
|
+
response = await client.createApp({ body: createBody });
|
|
33
|
+
const createDuration = Date.now() - createStartTime;
|
|
34
|
+
console.log(`createApp completed in ${createDuration}ms`);
|
|
35
|
+
console.log("Real API response:", response);
|
|
36
|
+
|
|
37
|
+
expect(response).toBeDefined();
|
|
38
|
+
expect(response.id).toBeDefined();
|
|
39
|
+
expect(response.name).toBe(appName);
|
|
40
|
+
expect(response.description).toBe(createBody.description);
|
|
41
|
+
expect(response.created).toBeInstanceOf(Date);
|
|
42
|
+
expect(response.updated).toBeInstanceOf(Date);
|
|
43
|
+
expect(response.dateFormat).toMatch(/^\w{2}-\w{2}-\w{4}$/);
|
|
44
|
+
expect(typeof response.timeZone).toBe("string");
|
|
45
|
+
expect(typeof response.hasEveryoneOnTheInternet).toBe("boolean");
|
|
46
|
+
expect(
|
|
47
|
+
response.dataClassification === undefined ||
|
|
48
|
+
typeof response.dataClassification === "string"
|
|
49
|
+
).toBe(true);
|
|
50
|
+
expect(
|
|
51
|
+
response.variables === undefined || Array.isArray(response.variables)
|
|
52
|
+
).toBe(true);
|
|
53
|
+
|
|
54
|
+
// Cleanup: Delete the app after assertions
|
|
55
|
+
const deleteBody = { name: appName };
|
|
56
|
+
await client.deleteApp({ appId: response.id, body: deleteBody });
|
|
57
|
+
console.log("Cleanup: App deleted:", response.id);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
const createDuration = Date.now() - createStartTime;
|
|
60
|
+
console.error(`createApp failed after ${createDuration}ms:`, error);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// tests/vitest/qb/apps/deleteApp.test.ts
|
|
2
|
+
import { test, expect } from "vitest";
|
|
3
|
+
import { quickbase } from "../../../../src/quickbaseClient";
|
|
4
|
+
|
|
5
|
+
test(
|
|
6
|
+
"QuickbaseClient Integration - deleteApp > deletes an app in QuickBase",
|
|
7
|
+
{ timeout: 30000 },
|
|
8
|
+
async () => {
|
|
9
|
+
const config = {
|
|
10
|
+
realm: process.env.QB_REALM || "",
|
|
11
|
+
userToken: process.env.QB_USER_TOKEN || "",
|
|
12
|
+
debug: true,
|
|
13
|
+
useTempTokens: false,
|
|
14
|
+
};
|
|
15
|
+
const client = quickbase(config);
|
|
16
|
+
|
|
17
|
+
const appName = `TempApp_${Date.now()}`;
|
|
18
|
+
const createBody = {
|
|
19
|
+
name: appName,
|
|
20
|
+
description: "Temporary app for deleteApp test",
|
|
21
|
+
assignToken: true, // Match createApp.test.ts
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
console.log("Config used:", {
|
|
25
|
+
...config,
|
|
26
|
+
userToken: config.userToken ? "[REDACTED]" : "",
|
|
27
|
+
});
|
|
28
|
+
console.log("Creating temporary app with:", createBody);
|
|
29
|
+
const createStartTime = Date.now();
|
|
30
|
+
let createResponse;
|
|
31
|
+
try {
|
|
32
|
+
createResponse = await client.createApp({ body: createBody });
|
|
33
|
+
const createDuration = Date.now() - createStartTime;
|
|
34
|
+
console.log(`createApp completed in ${createDuration}ms`);
|
|
35
|
+
console.log("Created app response:", createResponse);
|
|
36
|
+
|
|
37
|
+
expect(createResponse).toBeDefined();
|
|
38
|
+
expect(createResponse.id).toBeDefined();
|
|
39
|
+
expect(createResponse.name).toBe(appName);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
const createDuration = Date.now() - createStartTime;
|
|
42
|
+
console.error(`createApp failed after ${createDuration}ms:`, error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const deleteBody = {
|
|
47
|
+
name: appName,
|
|
48
|
+
};
|
|
49
|
+
console.log("Deleting app with:", deleteBody);
|
|
50
|
+
const deleteStartTime = Date.now();
|
|
51
|
+
try {
|
|
52
|
+
const deleteResponse = await client.deleteApp({
|
|
53
|
+
appId: createResponse.id,
|
|
54
|
+
body: deleteBody,
|
|
55
|
+
});
|
|
56
|
+
const deleteDuration = Date.now() - deleteStartTime;
|
|
57
|
+
console.log(`deleteApp completed in ${deleteDuration}ms`);
|
|
58
|
+
console.log("Delete app response:", deleteResponse);
|
|
59
|
+
|
|
60
|
+
expect(deleteResponse).toBeDefined();
|
|
61
|
+
expect(deleteResponse.deletedAppId).toBe(createResponse.id);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
const deleteDuration = Date.now() - deleteStartTime;
|
|
64
|
+
console.error(`deleteApp failed after ${deleteDuration}ms:`, error);
|
|
65
|
+
if (error instanceof Error && "response" in error) {
|
|
66
|
+
try {
|
|
67
|
+
const errorBody = await (error as any).response.json();
|
|
68
|
+
console.error("Full deleteApp error response:", errorBody);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
console.error("Could not parse error response:", e);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// tests/vitest/qb/fields/createField.test.ts (updated)
|
|
2
|
+
import { describe, it, expect, afterAll } from "vitest";
|
|
3
|
+
import { createClient, QB_TABLE_ID_1 } from "../../../setup.ts";
|
|
4
|
+
|
|
5
|
+
describe("QuickbaseClient Integration - createField", () => {
|
|
6
|
+
const client = createClient();
|
|
7
|
+
|
|
8
|
+
const createdFieldIds: number[] = [];
|
|
9
|
+
|
|
10
|
+
afterAll(async () => {
|
|
11
|
+
if (createdFieldIds.length > 0) {
|
|
12
|
+
try {
|
|
13
|
+
const response = await client.deleteFields({
|
|
14
|
+
tableId: QB_TABLE_ID_1,
|
|
15
|
+
body: { fieldIds: createdFieldIds },
|
|
16
|
+
});
|
|
17
|
+
console.log(
|
|
18
|
+
`Cleaned up fields: ${JSON.stringify(response.deletedFieldIds)}`,
|
|
19
|
+
response.errors && response.errors.length > 0
|
|
20
|
+
? `Errors: ${response.errors}`
|
|
21
|
+
: ""
|
|
22
|
+
);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error("Cleanup failed:", error);
|
|
25
|
+
console.log(`Fields left in table: ${createdFieldIds}`);
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
console.log("No fields to clean up.");
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("creates a field with user token", async () => {
|
|
33
|
+
const uniqueLabel = `TestField_${Date.now()}`;
|
|
34
|
+
const response = await client.createField({
|
|
35
|
+
tableId: QB_TABLE_ID_1,
|
|
36
|
+
body: {
|
|
37
|
+
label: uniqueLabel,
|
|
38
|
+
fieldType: "text",
|
|
39
|
+
fieldHelp: "Created via integration test",
|
|
40
|
+
addToForms: true,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
expect(response.id).toBeDefined();
|
|
45
|
+
expect(response.label).toBe(uniqueLabel);
|
|
46
|
+
expect(response.fieldType).toBe("text");
|
|
47
|
+
expect(response.fieldHelp).toBe("Created via integration test");
|
|
48
|
+
|
|
49
|
+
createdFieldIds.push(response.id);
|
|
50
|
+
console.log(`Created field ${uniqueLabel} with ID ${response.id}`);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("fails with invalid field type", async () => {
|
|
54
|
+
const uniqueLabel = `InvalidField_${Date.now()}`;
|
|
55
|
+
await expect(
|
|
56
|
+
client.createField({
|
|
57
|
+
tableId: QB_TABLE_ID_1,
|
|
58
|
+
body: {
|
|
59
|
+
label: uniqueLabel,
|
|
60
|
+
fieldType: "invalid_type" as "text", // Type assertion to bypass compile-time check
|
|
61
|
+
fieldHelp: "Should fail",
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
).rejects.toThrow("API Error: Bad Request (Status: 400)");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("fails with missing label", async () => {
|
|
68
|
+
await expect(
|
|
69
|
+
client.createField({
|
|
70
|
+
tableId: QB_TABLE_ID_1,
|
|
71
|
+
body: {
|
|
72
|
+
label: "",
|
|
73
|
+
fieldType: "text",
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
).rejects.toThrow("API Error: Invalid input (Status: 400)");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// tests/vitest/qb/fields/deleteFields.test.ts
|
|
2
|
+
import { describe, it, expect, beforeAll } from "vitest";
|
|
3
|
+
import { createClient, QB_TABLE_ID_1 } from "../../../setup.ts";
|
|
4
|
+
|
|
5
|
+
describe("QuickbaseClient Integration - deleteFields", () => {
|
|
6
|
+
const client = createClient();
|
|
7
|
+
|
|
8
|
+
let fieldIdsToDelete: number[] = [];
|
|
9
|
+
|
|
10
|
+
beforeAll(async () => {
|
|
11
|
+
try {
|
|
12
|
+
// Create test fields to delete
|
|
13
|
+
const fieldLabels = ["DeleteTest1", "DeleteTest2"];
|
|
14
|
+
for (const label of fieldLabels) {
|
|
15
|
+
const response = await client.createField({
|
|
16
|
+
tableId: QB_TABLE_ID_1,
|
|
17
|
+
body: {
|
|
18
|
+
label,
|
|
19
|
+
fieldType: "text",
|
|
20
|
+
fieldHelp: "Test field for deletion",
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
fieldIdsToDelete.push(response.id);
|
|
24
|
+
console.log(`Created field ${label} with ID ${response.id}`);
|
|
25
|
+
}
|
|
26
|
+
if (fieldIdsToDelete.length !== 2) {
|
|
27
|
+
throw new Error("Failed to create all test fields");
|
|
28
|
+
}
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error("beforeAll failed:", error);
|
|
31
|
+
throw error; // Fail the suite if setup fails
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("deletes fields successfully with user token", async () => {
|
|
36
|
+
try {
|
|
37
|
+
const response = await client.deleteFields({
|
|
38
|
+
tableId: QB_TABLE_ID_1,
|
|
39
|
+
body: {
|
|
40
|
+
fieldIds: fieldIdsToDelete,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
console.log("deleteFields response:", JSON.stringify(response, null, 2));
|
|
45
|
+
|
|
46
|
+
expect(response).toBeDefined();
|
|
47
|
+
expect(response.deletedFieldIds).toEqual(
|
|
48
|
+
expect.arrayContaining(fieldIdsToDelete)
|
|
49
|
+
);
|
|
50
|
+
expect(response.errors ?? []).toHaveLength(0); // Handle undefined errors
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("deleteFields failed:", error);
|
|
53
|
+
throw error; // Re-throw to fail the test with details
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("handles partial success with errors", async () => {
|
|
58
|
+
const newField = await client.createField({
|
|
59
|
+
tableId: QB_TABLE_ID_1,
|
|
60
|
+
body: {
|
|
61
|
+
label: "DeleteTest3",
|
|
62
|
+
fieldType: "text",
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
console.log(`Created field DeleteTest3 with ID ${newField.id}`);
|
|
66
|
+
|
|
67
|
+
const invalidFieldId = 999999; // Assume this ID doesn’t exist
|
|
68
|
+
const fieldIds = [newField.id, invalidFieldId];
|
|
69
|
+
|
|
70
|
+
const response = await client.deleteFields({
|
|
71
|
+
tableId: QB_TABLE_ID_1,
|
|
72
|
+
body: { fieldIds },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(response.deletedFieldIds).toContain(newField.id);
|
|
76
|
+
expect(response.deletedFieldIds).not.toContain(invalidFieldId);
|
|
77
|
+
expect(response.errors).toHaveLength(1);
|
|
78
|
+
expect(response.errors[0]).toMatch(/Field: 999999 was not found/i);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("fails with invalid request (empty fieldIds)", async () => {
|
|
82
|
+
await expect(
|
|
83
|
+
client.deleteFields({
|
|
84
|
+
tableId: QB_TABLE_ID_1,
|
|
85
|
+
body: { fieldIds: [] },
|
|
86
|
+
})
|
|
87
|
+
).rejects.toThrow("API Error: Bad Request (Status: 400)");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// tests/vitest/qb/fields/getField.test.ts
|
|
2
|
+
import { describe, it, expect } from "vitest";
|
|
3
|
+
import { createClient, QB_TABLE_ID_1 } from "../../../setup.ts";
|
|
4
|
+
|
|
5
|
+
describe("QuickbaseClient Integration - getField", () => {
|
|
6
|
+
const client = createClient();
|
|
7
|
+
|
|
8
|
+
it("retrieves an existing field with user token", async () => {
|
|
9
|
+
// Create a field to ensure we have a known field ID to retrieve
|
|
10
|
+
const uniqueLabel = `TestField_${Date.now()}`;
|
|
11
|
+
const createResponse = await client.createField({
|
|
12
|
+
tableId: QB_TABLE_ID_1,
|
|
13
|
+
body: {
|
|
14
|
+
label: uniqueLabel,
|
|
15
|
+
fieldType: "text",
|
|
16
|
+
fieldHelp: "Created for getField integration test",
|
|
17
|
+
addToForms: true,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(createResponse.id).toBeDefined();
|
|
22
|
+
const fieldId = createResponse.id;
|
|
23
|
+
console.log(`Created field ${uniqueLabel} with ID ${fieldId} for testing`);
|
|
24
|
+
|
|
25
|
+
// Test getField with the created field
|
|
26
|
+
const response = await client.getField({
|
|
27
|
+
fieldId: fieldId,
|
|
28
|
+
tableId: QB_TABLE_ID_1,
|
|
29
|
+
includeFieldPerms: true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(response.id).toBe(fieldId);
|
|
33
|
+
expect(response.label).toBe(uniqueLabel);
|
|
34
|
+
expect(response.fieldType).toBe("text");
|
|
35
|
+
expect(response.fieldHelp).toBe("Created for getField integration test");
|
|
36
|
+
expect(response.permissions).toBeDefined();
|
|
37
|
+
expect(Array.isArray(response.permissions)).toBe(true);
|
|
38
|
+
console.log(`Retrieved field ${response.label} with ID ${response.id}`);
|
|
39
|
+
|
|
40
|
+
// Clean up the created field
|
|
41
|
+
try {
|
|
42
|
+
const deleteResponse = await client.deleteFields({
|
|
43
|
+
tableId: QB_TABLE_ID_1,
|
|
44
|
+
body: { fieldIds: [fieldId] },
|
|
45
|
+
});
|
|
46
|
+
console.log(
|
|
47
|
+
`Cleaned up field ${fieldId}: ${JSON.stringify(deleteResponse)}`
|
|
48
|
+
);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(`Failed to clean up field ${fieldId}:`, error);
|
|
51
|
+
}
|
|
52
|
+
}, 10000); // Increase timeout to 10 seconds
|
|
53
|
+
|
|
54
|
+
it("fails with non-existent field ID", async () => {
|
|
55
|
+
const nonExistentFieldId = 999999; // Assuming this ID doesn’t exist
|
|
56
|
+
await expect(
|
|
57
|
+
client.getField({
|
|
58
|
+
fieldId: nonExistentFieldId,
|
|
59
|
+
tableId: QB_TABLE_ID_1,
|
|
60
|
+
})
|
|
61
|
+
).rejects.toMatchObject({
|
|
62
|
+
message: expect.stringContaining(
|
|
63
|
+
"API Error: No such field (Status: 404)"
|
|
64
|
+
),
|
|
65
|
+
});
|
|
66
|
+
console.log(
|
|
67
|
+
`Confirmed 404 for non-existent field ID ${nonExistentFieldId}`
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("fails with invalid table ID", async () => {
|
|
72
|
+
const invalidTableId = "invalid_dbid";
|
|
73
|
+
await expect(
|
|
74
|
+
client.getField({
|
|
75
|
+
fieldId: 1, // Arbitrary field ID
|
|
76
|
+
tableId: invalidTableId,
|
|
77
|
+
})
|
|
78
|
+
).rejects.toMatchObject({
|
|
79
|
+
message: expect.stringContaining(
|
|
80
|
+
"API Error: Invalid request (Status: 400)"
|
|
81
|
+
),
|
|
82
|
+
});
|
|
83
|
+
console.log(`Confirmed 400 for invalid table ID ${invalidTableId}`);
|
|
84
|
+
});
|
|
85
|
+
});
|