quickbase-js 1.0.1-beta.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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +102 -0
- package/build.js +66 -0
- package/dist/quickbaseClient.d.ts +3888 -0
- package/dist/quickbaseClient.js +5812 -0
- package/dist/quickbaseClient.js.map +1 -0
- package/examples/react.js +22 -0
- package/examples/vanillajs.html +23 -0
- package/logGen.yaml +1820 -0
- package/package.json +72 -0
- package/playwright.config.ts +37 -0
- package/rollup.config.js +70 -0
- package/src/code-generation/fix-spec-definitions.ts +136 -0
- package/src/code-generation/fix-spec-main.ts +176 -0
- package/src/code-generation/fix-spec-paths.ts +163 -0
- package/src/code-generation/generate-unified-interface.ts +152 -0
- package/src/code-generation/output/quickbase-fixed.json +8435 -0
- package/src/code-generation/regenerate-client.ts +110 -0
- package/src/generated-unified/QuickbaseClient.ts +59 -0
- package/src/index.ts +1 -0
- package/src/log-gen.ts +122 -0
- package/src/quickbaseClient.ts +320 -0
- package/src/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +46878 -0
- package/src/tokenCache.ts +51 -0
- package/src/utils.ts +5 -0
- package/test-artifacts/.last-run.json +4 -0
- package/test-artifacts/test-results.json +1801 -0
- package/test-results.json +2050 -0
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +189 -0
- package/tests/playwright/qb/auth/fetchTempToken401.test.ts +217 -0
- package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +151 -0
- package/tests/playwright/qb/auth/getTempToken.test.ts +180 -0
- package/tests/playwright/qb/auth/tokenPrefetch.test.ts +192 -0
- package/tests/playwright/qb/auth/tokenRenewal.test.ts +110 -0
- package/tests/setup.ts +19 -0
- package/tests/vitest/qb/apps/getApp.test.ts +46 -0
- package/tests/vitest/qb/fields/getFields.test.ts +234 -0
- package/tests/vitest/qb/index.ts +4 -0
- package/tests/vitest/qb/tables/getAppTables.test.ts +67 -0
- package/tests/vitest/unit/apps/getApp.test.ts +81 -0
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +59 -0
- package/tests/vitest/unit/auth/getTempToken.test.ts +83 -0
- package/tests/vitest/unit/auth/retryOn401.test.ts +72 -0
- package/tests/vitest/unit/auth/two401s.test.ts +77 -0
- package/tests/vitest/unit/fields/getFields.test.ts +115 -0
- package/tests/vitest/unit/index.ts +4 -0
- package/tests/vitest/unit/tables/getAppTables.test.ts +72 -0
- package/text.txt +104 -0
- package/tsconfig.json +28 -0
- package/versionrc.json +9 -0
- package/vitest.config.ts +21 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { createClient, mockFetch } from "@/tests/setup.ts";
|
|
3
|
+
|
|
4
|
+
describe("QuickbaseClient - getFields (Unit)", () => {
|
|
5
|
+
it("calls getFields successfully", async () => {
|
|
6
|
+
mockFetch.mockImplementation((url: string, options: any) => {
|
|
7
|
+
console.log("Mock fetch for getFields:", url, options);
|
|
8
|
+
return Promise.resolve({
|
|
9
|
+
ok: true,
|
|
10
|
+
status: 200,
|
|
11
|
+
json: () =>
|
|
12
|
+
Promise.resolve([
|
|
13
|
+
{
|
|
14
|
+
id: 1,
|
|
15
|
+
label: "Field1",
|
|
16
|
+
fieldType: "text",
|
|
17
|
+
noWrap: false,
|
|
18
|
+
bold: false,
|
|
19
|
+
required: false,
|
|
20
|
+
appearsByDefault: false,
|
|
21
|
+
findEnabled: false,
|
|
22
|
+
unique: false,
|
|
23
|
+
doesDataCopy: false,
|
|
24
|
+
fieldHelp: "field help",
|
|
25
|
+
audited: false,
|
|
26
|
+
properties: {
|
|
27
|
+
primaryKey: false,
|
|
28
|
+
foreignKey: false,
|
|
29
|
+
numLines: 1,
|
|
30
|
+
maxLength: 0,
|
|
31
|
+
appendOnly: false,
|
|
32
|
+
allowHTML: false,
|
|
33
|
+
allowMentions: false,
|
|
34
|
+
sortAsGiven: false,
|
|
35
|
+
carryChoices: true,
|
|
36
|
+
allowNewChoices: false,
|
|
37
|
+
formula: "",
|
|
38
|
+
defaultValue: "",
|
|
39
|
+
},
|
|
40
|
+
permissions: [
|
|
41
|
+
{ permissionType: "View", role: "Viewer", roleId: 10 },
|
|
42
|
+
{ permissionType: "None", role: "Participant", roleId: 11 },
|
|
43
|
+
{ permissionType: "Modify", role: "Administrator", roleId: 12 },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
]),
|
|
47
|
+
} as Response);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const client = createClient(mockFetch);
|
|
51
|
+
const result = await client.getFields({
|
|
52
|
+
tableId: "dummyTableId",
|
|
53
|
+
includeFieldPerms: true,
|
|
54
|
+
});
|
|
55
|
+
console.log("getFields response:", result);
|
|
56
|
+
expect(result).toEqual(
|
|
57
|
+
expect.arrayContaining([
|
|
58
|
+
expect.objectContaining({
|
|
59
|
+
id: 1,
|
|
60
|
+
label: "Field1",
|
|
61
|
+
fieldType: "text",
|
|
62
|
+
noWrap: false,
|
|
63
|
+
bold: false,
|
|
64
|
+
required: false,
|
|
65
|
+
appearsByDefault: false,
|
|
66
|
+
findEnabled: false,
|
|
67
|
+
unique: false,
|
|
68
|
+
doesDataCopy: false,
|
|
69
|
+
fieldHelp: "field help",
|
|
70
|
+
audited: false,
|
|
71
|
+
properties: expect.objectContaining({
|
|
72
|
+
primaryKey: false,
|
|
73
|
+
foreignKey: false,
|
|
74
|
+
numLines: 1,
|
|
75
|
+
maxLength: 0,
|
|
76
|
+
appendOnly: false,
|
|
77
|
+
allowHTML: false,
|
|
78
|
+
allowMentions: false,
|
|
79
|
+
sortAsGiven: false,
|
|
80
|
+
carryChoices: true,
|
|
81
|
+
allowNewChoices: false,
|
|
82
|
+
formula: "",
|
|
83
|
+
defaultValue: "",
|
|
84
|
+
}),
|
|
85
|
+
permissions: expect.arrayContaining([
|
|
86
|
+
expect.objectContaining({
|
|
87
|
+
permissionType: "View",
|
|
88
|
+
role: "Viewer",
|
|
89
|
+
roleId: 10,
|
|
90
|
+
}),
|
|
91
|
+
expect.objectContaining({
|
|
92
|
+
permissionType: "None",
|
|
93
|
+
role: "Participant",
|
|
94
|
+
roleId: 11,
|
|
95
|
+
}),
|
|
96
|
+
expect.objectContaining({
|
|
97
|
+
permissionType: "Modify",
|
|
98
|
+
role: "Administrator",
|
|
99
|
+
roleId: 12,
|
|
100
|
+
}),
|
|
101
|
+
]),
|
|
102
|
+
}),
|
|
103
|
+
])
|
|
104
|
+
);
|
|
105
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
106
|
+
`https://api.quickbase.com/v1/fields?tableId=dummyTableId&includeFieldPerms=true`,
|
|
107
|
+
expect.objectContaining({
|
|
108
|
+
headers: expect.objectContaining({
|
|
109
|
+
Authorization: `QB-USER-TOKEN ${process.env.QB_USER_TOKEN}`,
|
|
110
|
+
"QB-Realm-Hostname": `${process.env.QB_REALM}.quickbase.com`,
|
|
111
|
+
}),
|
|
112
|
+
})
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { createClient, mockFetch } from "@/tests/setup.ts";
|
|
3
|
+
|
|
4
|
+
describe("QuickbaseClient - getAppTables (Unit)", () => {
|
|
5
|
+
it("calls getAppTables successfully", async () => {
|
|
6
|
+
mockFetch.mockImplementation((url: string, options: any) => {
|
|
7
|
+
console.log("Mock fetch for getAppTables:", url, options);
|
|
8
|
+
return Promise.resolve({
|
|
9
|
+
ok: true,
|
|
10
|
+
status: 200,
|
|
11
|
+
json: () =>
|
|
12
|
+
Promise.resolve([
|
|
13
|
+
{
|
|
14
|
+
alias: "_DBID_ROOT",
|
|
15
|
+
created: "2025-02-13T18:22:33Z",
|
|
16
|
+
defaultSortFieldId: 2,
|
|
17
|
+
defaultSortOrder: "DESC",
|
|
18
|
+
description: "",
|
|
19
|
+
id: "buwai2zr4",
|
|
20
|
+
keyFieldId: 3,
|
|
21
|
+
name: "Root",
|
|
22
|
+
nextFieldId: 6,
|
|
23
|
+
nextRecordId: 1,
|
|
24
|
+
pluralRecordName: "Roots",
|
|
25
|
+
singleRecordName: "Root",
|
|
26
|
+
sizeLimit: "500 MB",
|
|
27
|
+
spaceRemaining: "500 MB",
|
|
28
|
+
spaceUsed: "0 KB",
|
|
29
|
+
updated: "2025-02-13T18:22:34Z",
|
|
30
|
+
},
|
|
31
|
+
]),
|
|
32
|
+
} as Response);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const client = createClient(mockFetch);
|
|
36
|
+
const tablesAppId = process.env.QB_APP_ID;
|
|
37
|
+
if (!tablesAppId) throw new Error("QB_APP_ID is not defined in .env");
|
|
38
|
+
const result = await client.getAppTables({ appId: tablesAppId });
|
|
39
|
+
console.log("getAppTables response:", result);
|
|
40
|
+
expect(result).toEqual(
|
|
41
|
+
expect.arrayContaining([
|
|
42
|
+
expect.objectContaining({
|
|
43
|
+
alias: "_DBID_ROOT",
|
|
44
|
+
created: new Date("2025-02-13T18:22:33Z"),
|
|
45
|
+
defaultSortFieldId: 2,
|
|
46
|
+
defaultSortOrder: "DESC",
|
|
47
|
+
description: "",
|
|
48
|
+
id: "buwai2zr4",
|
|
49
|
+
keyFieldId: 3,
|
|
50
|
+
name: "Root",
|
|
51
|
+
nextFieldId: 6,
|
|
52
|
+
nextRecordId: 1,
|
|
53
|
+
pluralRecordName: "Roots",
|
|
54
|
+
singleRecordName: "Root",
|
|
55
|
+
sizeLimit: "500 MB",
|
|
56
|
+
spaceRemaining: "500 MB",
|
|
57
|
+
spaceUsed: "0 KB",
|
|
58
|
+
updated: new Date("2025-02-13T18:22:34Z"),
|
|
59
|
+
}),
|
|
60
|
+
])
|
|
61
|
+
);
|
|
62
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
63
|
+
`https://api.quickbase.com/v1/tables?appId=${tablesAppId}`,
|
|
64
|
+
expect.objectContaining({
|
|
65
|
+
headers: expect.objectContaining({
|
|
66
|
+
Authorization: `QB-USER-TOKEN ${process.env.QB_USER_TOKEN}`,
|
|
67
|
+
"QB-Realm-Hostname": `${process.env.QB_REALM}.quickbase.com`,
|
|
68
|
+
}),
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
});
|
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
|
+
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"lib": ["ES2015", "ESNext", "DOM"], // Explicitly include ES2015 for Record
|
|
8
|
+
"types": ["node", "playwright/test"],
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"resolveJsonModule": true,
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
"rootDir": ".",
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"sourceMap": true,
|
|
17
|
+
"baseUrl": ".",
|
|
18
|
+
"paths": {
|
|
19
|
+
"@/*": ["./*"]
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"include": ["src/**/*", "tests/**/*"],
|
|
23
|
+
"exclude": ["node_modules", "dist", "src/generated-old"],
|
|
24
|
+
"ts-node": {
|
|
25
|
+
"esm": true,
|
|
26
|
+
"transpileOnly": true
|
|
27
|
+
}
|
|
28
|
+
}
|
package/versionrc.json
ADDED
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
environment: "jsdom",
|
|
7
|
+
include: ["tests/vitest/**/**/*.test.ts"],
|
|
8
|
+
setupFiles: ["tests/setup.ts"],
|
|
9
|
+
pool: "forks",
|
|
10
|
+
poolOptions: {
|
|
11
|
+
forks: {
|
|
12
|
+
singleFork: true, // Run tests sequentially
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
resolve: {
|
|
17
|
+
alias: {
|
|
18
|
+
"@": path.resolve(__dirname, "./"),
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|