quickbase-js 1.1.0-beta.3 → 1.1.0-beta.5

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 (69) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +115 -5
  3. package/build.js +175 -55
  4. package/dist/{quickbase.d.ts → esm/quickbase.d.ts} +1108 -349
  5. package/dist/{quickbase.js → esm/quickbase.js} +828 -263
  6. package/dist/esm/quickbase.js.map +1 -0
  7. package/dist/esm/quickbase.min.js +2 -0
  8. package/dist/esm/quickbase.min.js.map +1 -0
  9. package/dist/umd/quickbase.umd.d.ts +5341 -0
  10. package/dist/umd/quickbase.umd.js +7696 -0
  11. package/dist/umd/quickbase.umd.js.map +1 -0
  12. package/dist/umd/quickbase.umd.min.js +2 -0
  13. package/dist/umd/quickbase.umd.min.js.map +1 -0
  14. package/examples/react.js +12 -12
  15. package/examples/vanillajs.html +12 -12
  16. package/log-gen.yaml +536 -1915
  17. package/open-api/definitions/apps.ts +274 -0
  18. package/open-api/definitions/auth.ts +10 -0
  19. package/open-api/definitions/fields.ts +751 -0
  20. package/open-api/definitions/index.ts +18 -0
  21. package/open-api/definitions/records.ts +269 -0
  22. package/open-api/definitions/relationships.ts +90 -0
  23. package/open-api/definitions/reports.ts +10 -0
  24. package/open-api/definitions/tables.ts +112 -0
  25. package/{src/code-generation → open-api}/fix-spec-main.ts +3 -3
  26. package/{src/code-generation → open-api}/generate-unified-interface.ts +42 -17
  27. package/{src/code-generation → open-api}/output/quickbase-fixed.json +3244 -4586
  28. package/open-api/paths/apps.ts +100 -0
  29. package/open-api/paths/auth.ts +25 -0
  30. package/open-api/paths/fields.ts +207 -0
  31. package/open-api/paths/index.ts +17 -0
  32. package/open-api/paths/records.ts +68 -0
  33. package/open-api/paths/relationships.ts +32 -0
  34. package/open-api/paths/reports.ts +34 -0
  35. package/open-api/paths/tables.ts +162 -0
  36. package/{src/code-generation → open-api}/regenerate-client.ts +4 -4
  37. package/package.json +34 -25
  38. package/playwright-results.txt/.last-run.json +4 -0
  39. package/playwright.config.ts +1 -1
  40. package/rollup.config.mjs +114 -0
  41. package/src/generated-unified/QuickbaseClient.ts +7 -6
  42. package/test-artifacts/.last-run.json +4 -2
  43. package/test-esm.js +1 -0
  44. package/test-umd.js +1 -0
  45. package/test.ts +1 -0
  46. package/tests/playwright/qb/auth/umd.test.ts +10 -0
  47. package/tests/vitest/qb/fields/createField.test.ts +78 -0
  48. package/tests/vitest/qb/fields/deleteFields.test.ts +89 -0
  49. package/tests/vitest/qb/fields/getField.test.ts +85 -0
  50. package/tests/vitest/qb/fields/getFieldUsage.test.ts +174 -0
  51. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +77 -0
  52. package/tests/vitest/qb/index.ts +25 -1
  53. package/tests/vitest/unit/fields/createField.test.ts +391 -0
  54. package/tests/vitest/unit/fields/deleteFields.test.ts +141 -0
  55. package/tests/vitest/unit/fields/getField.test.ts +189 -0
  56. package/tests/vitest/unit/fields/getFieldUsage.test.ts +147 -0
  57. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +160 -0
  58. package/tests/vitest/unit/index.ts +30 -1
  59. package/tests/vitest/unit/umd.test.ts +8 -0
  60. package/{src → tools}/log-gen.ts +14 -10
  61. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  62. package/tsconfig.build.json +17 -0
  63. package/tsconfig.json +5 -5
  64. package/dist/quickbase.js.map +0 -1
  65. package/rollup.config.js +0 -70
  66. package/src/code-generation/fix-spec-definitions.ts +0 -809
  67. package/src/code-generation/fix-spec-paths.ts +0 -439
  68. package/test-artifacts/test-results.json +0 -829
  69. /package/{src/specs → specs}/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -0
package/package.json CHANGED
@@ -1,18 +1,26 @@
1
1
  {
2
2
  "name": "quickbase-js",
3
- "main": "dist/quickbase.js",
4
- "types": "dist/quickbase.d.ts",
5
- "version": "1.1.0-beta.3",
3
+ "version": "1.1.0-beta.5",
4
+ "description": "QuickBase JavaScript client for frameworks and vanilla JS",
5
+ "type": "module",
6
+ "main": "dist/esm/quickbase.js",
7
+ "module": "dist/esm/quickbase.js",
8
+ "types": "dist/esm/quickbase.d.ts",
6
9
  "publishConfig": {
7
10
  "access": "public"
8
11
  },
9
- "description": "QuickBase JavaScript client for frameworks and vanilla JS",
10
- "module": "dist/quickbase.js",
11
- "type": "module",
12
12
  "exports": {
13
13
  ".": {
14
- "import": "./dist/quickbase.js",
15
- "types": "./dist/quickbase.d.ts"
14
+ "import": {
15
+ "minified": "./dist/esm/quickbase.min.js",
16
+ "default": "./dist/esm/quickbase.js"
17
+ },
18
+ "require": {
19
+ "minified": "./dist/umd/quickbase.umd.min.js",
20
+ "default": "./dist/umd/quickbase.umd.js"
21
+ },
22
+ "types": "./dist/esm/quickbase.d.ts",
23
+ "umd:types": "./dist/umd/quickbase.umd.d.ts"
16
24
  }
17
25
  },
18
26
  "scripts": {
@@ -21,13 +29,15 @@
21
29
  "release:alpha": "standard-version --prerelease alpha",
22
30
  "release:push": "npm run release:beta && git push --follow-tags origin main",
23
31
  "release:publish": "npm run release:push && npm publish --tag beta",
24
- "fix-spec": "node --loader ts-node/esm src/code-generation/fix-spec-main.ts",
25
- "regenerate": "rimraf src/generated && node --loader ts-node/esm src/code-generation/regenerate-client.ts",
26
- "regenerate-unified": "node --loader ts-node/esm src/code-generation/generate-unified-interface.ts",
27
- "regenerate-all": "npm run fix-spec && npm run regenerate && npm run regenerate-unified",
28
- "log-gen": "node --loader ts-node/esm src/log-gen.ts",
29
- "build": "rimraf dist && rollup -c",
30
- "build:prod": "rm -rf dist/* && NODE_ENV=production rollup -c",
32
+ "release:stable": "standard-version && git push --follow-tags origin main && npm publish",
33
+ "fix-spec": "node --loader ts-node/esm open-api/fix-spec-main.ts",
34
+ "regenerate:openapi": "rimraf src/generated && node --loader ts-node/esm open-api/regenerate-client.ts",
35
+ "regenerate:unified": "node --loader ts-node/esm open-api/generate-unified-interface.ts",
36
+ "regenerate:all": "npm run fix-spec && npm run regenerate:openapi && npm run regenerate:unified",
37
+ "log-gen": "node --loader ts-node/esm tools/log-gen.ts",
38
+ "build": "rimraf dist && node --loader ts-node/esm build.js",
39
+ "build:prod": "rimraf dist && NODE_ENV=production node --loader ts-node/esm build.js",
40
+ "test:all": "vitest run tests/vitest/**/**/*.test.ts --reporter=basic && playwright test tests/playwright/qb --config playwright.config.ts --reporter=dot --quiet",
31
41
  "test:pw:qb:all": "playwright test tests/playwright/qb --config playwright.config.ts",
32
42
  "test:vitest:all": "vitest run tests/vitest/**/**/*.test.ts",
33
43
  "test:vitest:qb": "vitest run tests/vitest/qb/**/*.test.ts",
@@ -35,17 +45,14 @@
35
45
  "test:vitest:qb:apps": "vitest run tests/vitest/qb/apps/**/*.test.ts",
36
46
  "test:vitest:qb:auth": "vitest run tests/vitest/qb/auth/**/*.test.ts",
37
47
  "test:vitest:qb:fields": "vitest run tests/vitest/qb/fields/**/*.test.ts",
48
+ "test:vitest:qb:records": "vitest run tests/vitest/qb/records/**/*.test.ts",
38
49
  "test:vitest:qb:tables": "vitest run tests/vitest/qb/tables/**/*.test.ts",
39
- "test:pw:qb:auth": "playwright test tests/playwright/qb/auth",
40
- "test::pw:qb:auth:temptoken": "playwright test tests/playwright/qb/auth/getTempToken.test.ts",
41
- "test:pw:qb:auth:renewal": "playwright test tests/playwright/qb/auth/tokenRenewal.test.ts",
42
- "test:pw:qb:auth:cache": "playwright test tests/playwright/qb/auth/cacheSwitching.test.ts",
43
- "test:pw:qb:auth:temp401": "playwright test tests/playwright/qb/auth/fetchTempToken401.test.ts",
44
- "test:pw:qb:auth:prefetch": "playwright test tests/playwright/qb/auth/tokenPrefetch.test.ts",
45
- "test:pw:qb:auth:debug": "playwright test tests/playwright/qb/auth --headed --debug",
46
- "test:pw:qb:auth:temp:debug": "playwright test tests/playwright/qb/auth/getTempToken.test.ts --headed --debug",
47
- "test:pw:qb:auth:renewal:debug": "playwright test tests/playwright/qb/auth/tokenRenewal.test.ts --headed --debug --config=playwright.config.ts",
48
- "test:pw:qb:auth:cache:debug": "playwright test tests/playwright/qb/auth/cacheSwitching.test.ts --headed --debug"
50
+ "test:vitest:unit:apps": "vitest run tests/vitest/unit/apps/**/*.test.ts",
51
+ "test:vitest:unit:auth": "vitest run tests/vitest/unit/auth/**/*.test.ts",
52
+ "test:vitest:unit:fields": "vitest run tests/vitest/unit/fields/**/*.test.ts",
53
+ "test:vitest:unit:records": "vitest run tests/vitest/unit/records/**/*.test.ts",
54
+ "test:vitest:unit:tables": "vitest run tests/vitest/unit/tables/**/*.test.ts",
55
+ "test:pw:qb:auth": "playwright test tests/playwright/qb/auth"
49
56
  },
50
57
  "dependencies": {
51
58
  "typescript": "^5.8.2"
@@ -57,6 +64,7 @@
57
64
  "@rollup/plugin-node-resolve": "^16.0.0",
58
65
  "@rollup/plugin-terser": "^0.4.4",
59
66
  "@rollup/plugin-typescript": "^12.1.2",
67
+ "@types/js-yaml": "^4.0.9",
60
68
  "@types/node": "^22.13.10",
61
69
  "dotenv": "^16.4.7",
62
70
  "glob": "^11.0.1",
@@ -71,6 +79,7 @@
71
79
  "ts-morph": "^25.0.1",
72
80
  "ts-node": "^10.9.2",
73
81
  "tslib": "^2.8.1",
82
+ "undici-types": "^7.5.0",
74
83
  "vitest": "^3.0.8"
75
84
  }
76
85
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "passed",
3
+ "failedTests": []
4
+ }
@@ -29,7 +29,7 @@ const config = defineConfig({
29
29
  });
30
30
 
31
31
  console.log(
32
- `Loading Playwright config with timeout: ${config.timeout}ms, workers: ${
32
+ `Loading Playwright: Testing temp token authorization in browser. Be patient, this should take at least 5min. Workers: ${
33
33
  config.workers || "default (half CPU cores)"
34
34
  }`
35
35
  );
@@ -0,0 +1,114 @@
1
+ import terser from "@rollup/plugin-terser";
2
+ import nodeResolve from "@rollup/plugin-node-resolve";
3
+ import commonjs from "@rollup/plugin-commonjs";
4
+ import dts from "rollup-plugin-dts";
5
+ import typescript from "@rollup/plugin-typescript";
6
+
7
+ const isProd = process.env.NODE_ENV === "production";
8
+
9
+ // External dependencies for both ESM and UMD builds
10
+ const external = [
11
+ "node:http",
12
+ "node:https",
13
+ "node:zlib",
14
+ "node:stream",
15
+ "node:buffer",
16
+ "node:util",
17
+ "node:url",
18
+ "node:net",
19
+ "node:fs",
20
+ "node:path",
21
+ "node-fetch",
22
+ ];
23
+
24
+ // Global mappings for UMD (browser) build
25
+ const globals = {
26
+ "node-fetch": "fetch", // Map node-fetch to window.fetch in browsers
27
+ };
28
+
29
+ export default [
30
+ // ESM Build
31
+ {
32
+ input: "src/quickbaseClient.ts",
33
+ output: {
34
+ dir: "dist/esm",
35
+ format: "esm",
36
+ sourcemap: true,
37
+ entryFileNames: "quickbase.js",
38
+ },
39
+ external,
40
+ plugins: [
41
+ nodeResolve({ preferBuiltins: true }), // Node.js resolution
42
+ commonjs(), // Convert CommonJS to ESM
43
+ typescript({
44
+ tsconfig: "./tsconfig.json",
45
+ noEmitOnError: true, // Fail on TypeScript errors
46
+ // Use Rollup to emit JavaScript, overriding noEmit for this build
47
+ }),
48
+ isProd && terser(), // Minification for production
49
+ ],
50
+ },
51
+ // UMD Build
52
+ {
53
+ input: "src/quickbaseClient.ts",
54
+ output: {
55
+ file: "dist/umd/quickbase.umd.js",
56
+ format: "umd",
57
+ name: "QuickbaseJS", // Global name for browser
58
+ sourcemap: true,
59
+ globals,
60
+ },
61
+ external,
62
+ plugins: [
63
+ nodeResolve({ preferBuiltins: true, browser: true }), // Browser-first resolution
64
+ commonjs(), // Convert CommonJS to UMD
65
+ typescript({
66
+ tsconfig: "./tsconfig.json",
67
+ noEmitOnError: true, // Fail on TypeScript errors
68
+ // Use Rollup to emit JavaScript, overriding noEmit for this build
69
+ }),
70
+ isProd && terser(), // Minification for production
71
+ ],
72
+ },
73
+ // ESM Declarations
74
+ {
75
+ input: "src/quickbaseClient.ts",
76
+ output: {
77
+ file: "dist/esm/quickbase.d.ts",
78
+ format: "esm",
79
+ },
80
+ plugins: [
81
+ dts({
82
+ tsconfig: "./tsconfig.json",
83
+ respectExternal: true, // Include external dependencies in declarations
84
+ }),
85
+ ],
86
+ },
87
+ // UMD Declarations
88
+ {
89
+ input: "src/quickbaseClient.ts",
90
+ output: {
91
+ file: "dist/umd/quickbase.umd.d.ts",
92
+ format: "umd",
93
+ },
94
+ plugins: [
95
+ dts({
96
+ tsconfig: "./tsconfig.json",
97
+ respectExternal: true, // Include external dependencies in declarations
98
+ }),
99
+ ],
100
+ },
101
+ ].map((config) => ({
102
+ ...config,
103
+ onwarn(warning, warn) {
104
+ // Suppress TypeScript plugin warnings
105
+ if (
106
+ warning.code === "PLUGIN_WARNING" &&
107
+ warning.plugin === "typescript" &&
108
+ warning.message.includes("TS5096")
109
+ ) {
110
+ return;
111
+ }
112
+ warn(warning);
113
+ },
114
+ }));
@@ -1,5 +1,5 @@
1
- // Generated on 2025-03-11T21:50:08.483Z
2
- import { App, CopyApp200Response, CopyAppRequest, CreateApp200Response, CreateAppRequest, DeleteApp200Response, DeleteAppRequest, DeleteRecords200Response, DeleteRecordsRequest, DeleteTableResponse, Field, GetRelationships200Response, GetTempTokenDBID200Response, ReportRunResponse, RunQueryRequest, RunQueryResponse, Table, UpdateTableRequest, Upsert200Response, Upsert207Response, UpsertRequest } from "../generated/models";
1
+ // Generated on 2025-03-12T19:20:50.952Z
2
+ import { App, CopyApp200Response, CopyAppRequest, CreateApp200Response, CreateAppRequest, CreateField200Response, CreateFieldRequest, DeleteApp200Response, DeleteAppRequest, DeleteFields200Response, DeleteFieldsRequest, DeleteRecords200Response, DeleteRecordsRequest, DeleteTableResponse, Field, FieldUsage, GetRelationships200Response, GetTempTokenDBID200Response, ReportRunResponse, RunQueryRequest, RunQueryResponse, Table, UpdateTableRequest, Upsert200Response, Upsert207Response, UpsertRequest } from "../generated/models";
3
3
 
4
4
  export interface QuickbaseClient {
5
5
  createApp: (params: { body: CreateAppRequest }) => Promise<CreateApp200Response>;
@@ -20,10 +20,11 @@ export interface QuickbaseClient {
20
20
  getReport: (params: { tableId: string; reportId: string }) => Promise<{ [key: string]: any }>;
21
21
  runReport: (params: { reportId: string; generated: any }) => Promise<ReportRunResponse[]>;
22
22
  getFields: (params: { tableId: string; includeFieldPerms?: boolean }) => Promise<Field[]>;
23
- getField: (params: { tableId: string; includeFieldPerms?: boolean; fieldId: number }) => Promise<{ [key: string]: any }>;
24
- updateField: (params: { tableId: string; fieldId: number; generated?: any }) => Promise<{ [key: string]: any }>;
25
- getFieldsUsage: (params: { tableId: string; skip?: number; top?: number }) => Promise<any[]>;
26
- getFieldUsage: (params: { tableId: string; fieldId: number }) => Promise<any[]>;
23
+ createField: (params: { tableId: string; body: CreateFieldRequest }) => Promise<CreateField200Response>;
24
+ deleteFields: (params: { tableId: string; body: DeleteFieldsRequest }) => Promise<DeleteFields200Response>;
25
+ getField: (params: { fieldId: number; tableId: string; includeFieldPerms?: boolean }) => Promise<Field>;
26
+ getFieldsUsage: (params: { tableId: string; skip?: number; top?: number }) => Promise<FieldUsage[]>;
27
+ getFieldUsage: (params: { fieldId: number; tableId: string }) => Promise<FieldUsage[]>;
27
28
  runFormula: (params: { generated?: any }) => Promise<{ [key: string]: any }>;
28
29
  upsert: (params: { body: UpsertRequest }) => Promise<Upsert200Response | Upsert207Response>;
29
30
  deleteRecords: (params: { body: DeleteRecordsRequest }) => Promise<DeleteRecords200Response>;
@@ -1,4 +1,6 @@
1
1
  {
2
- "status": "passed",
3
- "failedTests": []
2
+ "status": "failed",
3
+ "failedTests": [
4
+ "07fa1d68e36f7ff08da6-e567a262e6a662a8edf4"
5
+ ]
4
6
  }
package/test-esm.js ADDED
@@ -0,0 +1 @@
1
+ import { quickbase } from './dist/esm/quickbase.js'; const qb = quickbase({ realm: 'example', userToken: 'your-token' }); console.log(qb);
package/test-umd.js ADDED
@@ -0,0 +1 @@
1
+ const quickbase = require('./dist/umd/quickbase.umd.js'); const qb = quickbase({ realm: 'example', userToken: 'your-token' }); console.log(qb);
package/test.ts ADDED
@@ -0,0 +1 @@
1
+ console.log('Hello from TypeScript');
@@ -0,0 +1,10 @@
1
+ // tests/playwright/qb/auth/umd.test.ts
2
+ import { test, expect } from "@playwright/test";
3
+ test("UMD build works in browser", async ({ page }) => {
4
+ await page.goto("http://localhost:3000/test-umd.html");
5
+ const result = await page.evaluate(() => {
6
+ const qb = new QuickbaseJS({ realm: "example", useTempTokens: true });
7
+ return qb.getTempTokenDBID({ dbid: "test-dbid" });
8
+ });
9
+ expect(result).toBeTruthy();
10
+ });
@@ -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
+ });