quickbase-js 0.1.0-beta.10
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 +211 -0
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/api-examples.md +49 -0
- package/build-common.js +131 -0
- package/build-esm.js +71 -0
- package/build-umd.js +69 -0
- package/dist/esm/quickbase.d.ts +8081 -0
- package/dist/esm/quickbase.js +7928 -0
- package/dist/esm/quickbase.js.map +1 -0
- package/dist/esm/quickbase.min.js +2 -0
- package/dist/esm/quickbase.min.js.map +1 -0
- package/dist/umd/quickbase.umd.js +8504 -0
- package/dist/umd/quickbase.umd.js.map +1 -0
- package/dist/umd/quickbase.umd.min.js +2 -0
- package/dist/umd/quickbase.umd.min.js.map +1 -0
- package/docs/.vitepress/cache/deps/@theme_index.js +275 -0
- package/docs/.vitepress/cache/deps/@theme_index.js.map +7 -0
- package/docs/.vitepress/cache/deps/_metadata.json +40 -0
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js +12542 -0
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js.map +7 -0
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js +9719 -0
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js.map +7 -0
- package/docs/.vitepress/cache/deps/package.json +3 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4504 -0
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +583 -0
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
- package/docs/.vitepress/cache/deps/vue.js +343 -0
- package/docs/.vitepress/cache/deps/vue.js.map +7 -0
- package/docs/.vitepress/config.mts +26 -0
- package/docs/api-examples.md +49 -0
- package/docs/index.md +59 -0
- package/docs/markdown-examples.md +85 -0
- package/docs-data/api-docs.json +4143 -0
- package/examples/quicbase-jsCDN.html +36 -0
- package/examples/react.js +48 -0
- package/examples/vanillajs.html +47 -0
- package/index.md +25 -0
- package/markdown-examples.md +85 -0
- package/open-api/fix-spec-main.ts +133 -0
- package/open-api/generate-unified-interface.ts +104 -0
- package/open-api/generateDocsJson.ts +24 -0
- package/open-api/output/quickbase-fixed.json +11191 -0
- package/open-api/post-process-generated.ts +226 -0
- package/open-api/regenerate-client.ts +117 -0
- package/open-api/schema/enhance-general.ts +111 -0
- package/open-api/schema/fix-arrays.ts +68 -0
- package/open-api/schema/tags/apps.ts +90 -0
- package/open-api/schema/tags/fields.ts +471 -0
- package/open-api/schema/tags/groups.ts +51 -0
- package/open-api/schema/tags/index.ts +66 -0
- package/open-api/schema/tags/records.ts +115 -0
- package/open-api/schema/tags/tables.ts +211 -0
- package/open-api/schema/tags/users.ts +47 -0
- package/open-api/types/spec.ts +42 -0
- package/open-api/utils/common.ts +29 -0
- package/open-api/utils/generateJsDoc.ts +74 -0
- package/open-api/utils/infer-schema.ts +40 -0
- package/open-api/utils/naming.ts +10 -0
- package/open-api/utils/sharedUtils.ts +352 -0
- package/package.json +96 -0
- package/playwright.config.ts +37 -0
- package/rollup.config.js +114 -0
- package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +46878 -0
- package/specs/split/apps.json +1315 -0
- package/specs/split/auth.json +191 -0
- package/specs/split/fields.json +3869 -0
- package/specs/split/records.json +754 -0
- package/specs/split/reports.json +619 -0
- package/specs/split/tables.json +1605 -0
- package/src/RateLimitError.ts +12 -0
- package/src/ThrottleBucket.ts +41 -0
- package/src/authorizationStrategy.ts +283 -0
- package/src/generated-unified/QuickbaseClient.ts +1135 -0
- package/src/generated-unified/missing-types-report.json +3 -0
- package/src/index.ts +1 -0
- package/src/invokeMethod.ts +245 -0
- package/src/quickbaseClient.ts +194 -0
- package/src/rateLimiter.ts +25 -0
- package/src/tokenCache.ts +35 -0
- package/src/utils.ts +50 -0
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +159 -0
- package/tests/playwright/qb/auth/fetchTempToken401.test.ts +219 -0
- package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +162 -0
- package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +153 -0
- package/tests/playwright/qb/auth/getTempToken.test.ts +152 -0
- package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +179 -0
- package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +133 -0
- package/tests/setup.ts +53 -0
- 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/apps/getApp.test.ts +44 -0
- package/tests/vitest/qb/apps/getAppEvents.test.ts +67 -0
- package/tests/vitest/qb/apps/updateApp.test.ts +58 -0
- package/tests/vitest/qb/auth/mockQuickbaseServer.ts +60 -0
- package/tests/vitest/qb/auth/retryUserToken401.test.ts +73 -0
- package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +65 -0
- package/tests/vitest/qb/fields/createField.test.ts +77 -0
- package/tests/vitest/qb/fields/deleteFields.test.ts +83 -0
- package/tests/vitest/qb/fields/getField.test.ts +85 -0
- package/tests/vitest/qb/fields/getFieldUsage.test.ts +82 -0
- package/tests/vitest/qb/fields/getFields.test.ts +232 -0
- package/tests/vitest/qb/fields/getFieldsUsage.test.ts +77 -0
- package/tests/vitest/qb/fields/updateField.test.ts +93 -0
- package/tests/vitest/qb/formulas/runFormula.test.ts +96 -0
- package/tests/vitest/qb/index.ts +29 -0
- package/tests/vitest/qb/records/deleteRecords.test.ts +110 -0
- package/tests/vitest/qb/records/runQuery.test.ts +146 -0
- package/tests/vitest/qb/records/upsert.test.ts +102 -0
- package/tests/vitest/qb/tables/createRelationship.test.ts +102 -0
- package/tests/vitest/qb/tables/createTable.test.ts +55 -0
- package/tests/vitest/qb/tables/deleteRelationship.test.ts +143 -0
- package/tests/vitest/qb/tables/deleteTable.test.ts +50 -0
- package/tests/vitest/qb/tables/getAppTables.test.ts +46 -0
- package/tests/vitest/qb/tables/getRelationships.test.ts +80 -0
- package/tests/vitest/qb/tables/getTable.test.ts +26 -0
- package/tests/vitest/qb/tables/updateRelationship.test.ts +250 -0
- package/tests/vitest/qb/tables/updateTable.test.ts +48 -0
- package/tests/vitest/unit/ThrottleBucket.test.ts +95 -0
- package/tests/vitest/unit/apps/copyApp.test.ts +581 -0
- package/tests/vitest/unit/apps/createApp.test.ts +186 -0
- package/tests/vitest/unit/apps/deleteApp.test.ts +216 -0
- package/tests/vitest/unit/apps/getApp.test.ts +128 -0
- package/tests/vitest/unit/apps/getAppEvents.test.ts +193 -0
- package/tests/vitest/unit/apps/updateApp.test.ts +412 -0
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +63 -0
- package/tests/vitest/unit/auth/getTempToken.test.ts +119 -0
- package/tests/vitest/unit/auth/retryTempToken401.test.ts +95 -0
- package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +206 -0
- package/tests/vitest/unit/auth/retryUserToken401.test.ts +69 -0
- package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +325 -0
- package/tests/vitest/unit/fields/createField.test.ts +451 -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 +180 -0
- package/tests/vitest/unit/fields/getFields.test.ts +122 -0
- package/tests/vitest/unit/fields/getFieldsUsage.test.ts +160 -0
- package/tests/vitest/unit/fields/updateField.test.ts +285 -0
- package/tests/vitest/unit/formulas/runFormula.test.ts +205 -0
- package/tests/vitest/unit/index.ts +34 -0
- package/tests/vitest/unit/quickbaseClientHttpMethods.test.ts +139 -0
- package/tests/vitest/unit/rateLimit.test.ts +191 -0
- package/tests/vitest/unit/records/deleteRecords.test.ts +112 -0
- package/tests/vitest/unit/records/runQuery.test.ts +102 -0
- package/tests/vitest/unit/records/upsert.test.ts +234 -0
- package/tests/vitest/unit/tables/createRelationship.test.ts +212 -0
- package/tests/vitest/unit/tables/createTable.test.ts +70 -0
- package/tests/vitest/unit/tables/deleteRelationship.test.ts +97 -0
- package/tests/vitest/unit/tables/deleteTable.test.ts +77 -0
- package/tests/vitest/unit/tables/getAppTables.test.ts +85 -0
- package/tests/vitest/unit/tables/getRelationships.test.ts +259 -0
- package/tests/vitest/unit/tables/getTable.test.ts +233 -0
- package/tests/vitest/unit/tables/updateRelationship.test.ts +307 -0
- package/tests/vitest/unit/tables/updateTable.test.ts +80 -0
- package/tests/vitest/unit/tokenLifespan.test.ts +204 -0
- package/tests/vitest/unit/umd.test.ts +8 -0
- package/tools/log-gen.ts +251 -0
- package/tools/log-gen.yaml +4777 -0
- package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
- package/tsconfig.build.json +17 -0
- package/tsconfig.json +32 -0
- package/versionrc.json +9 -0
- package/vitest.config.ts +27 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/RateLimitError.ts
|
|
2
|
+
export class RateLimitError extends Error {
|
|
3
|
+
public readonly status: number;
|
|
4
|
+
public readonly retryAfter?: number;
|
|
5
|
+
|
|
6
|
+
constructor(message: string, status: number, retryAfter?: number) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "RateLimitError";
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.retryAfter = retryAfter; // Seconds from Retry-After header, if present
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/ThrottleBucket.ts
|
|
2
|
+
export class ThrottleBucket {
|
|
3
|
+
private tokens: number;
|
|
4
|
+
private maxTokens: number;
|
|
5
|
+
private refillRate: number; // Tokens per second
|
|
6
|
+
private lastRefill: number;
|
|
7
|
+
private pending: Promise<void> = Promise.resolve(); // Queue for sequential execution
|
|
8
|
+
|
|
9
|
+
constructor(rate: number, burst: number) {
|
|
10
|
+
this.tokens = burst;
|
|
11
|
+
this.maxTokens = burst;
|
|
12
|
+
this.refillRate = rate;
|
|
13
|
+
this.lastRefill = Date.now();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private refill(): void {
|
|
17
|
+
const now = Date.now();
|
|
18
|
+
const elapsed = (now - this.lastRefill) / 1000; // Seconds elapsed
|
|
19
|
+
const newTokens = elapsed * this.refillRate;
|
|
20
|
+
this.tokens = Math.min(this.maxTokens, this.tokens + newTokens);
|
|
21
|
+
this.lastRefill = now;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async acquire(): Promise<void> {
|
|
25
|
+
// Chain the new acquisition onto the pending queue
|
|
26
|
+
const previous = this.pending;
|
|
27
|
+
this.pending = (async () => {
|
|
28
|
+
await previous; // Wait for prior calls to complete
|
|
29
|
+
this.refill();
|
|
30
|
+
if (this.tokens >= 1) {
|
|
31
|
+
this.tokens -= 1;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const waitTime = ((1 - this.tokens) / this.refillRate) * 1000; // ms until next token
|
|
35
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
36
|
+
this.refill();
|
|
37
|
+
this.tokens -= 1;
|
|
38
|
+
})();
|
|
39
|
+
await this.pending;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
// src/authorizationStrategy.ts
|
|
2
|
+
|
|
3
|
+
import { TokenCache } from "./tokenCache";
|
|
4
|
+
|
|
5
|
+
export interface AuthorizationStrategy {
|
|
6
|
+
getToken(dbid: string): Promise<string | undefined>;
|
|
7
|
+
applyHeaders(headers: Record<string, string>, token: string): void;
|
|
8
|
+
handleError(
|
|
9
|
+
status: number,
|
|
10
|
+
params: any,
|
|
11
|
+
attempt: number,
|
|
12
|
+
maxAttempts: number,
|
|
13
|
+
debug?: boolean,
|
|
14
|
+
methodName?: string
|
|
15
|
+
): Promise<string | null>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/authorizationStrategy.ts (partial update)
|
|
19
|
+
|
|
20
|
+
export class TempTokenStrategy implements AuthorizationStrategy {
|
|
21
|
+
constructor(
|
|
22
|
+
private tokenCache: TokenCache,
|
|
23
|
+
private initialTempToken: string | undefined,
|
|
24
|
+
private fetchApi: typeof fetch,
|
|
25
|
+
private realm: string,
|
|
26
|
+
private baseUrl: string = "https://api.quickbase.com/v1"
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
async fetchTempToken(dbid: string): Promise<string> {
|
|
30
|
+
const headers = {
|
|
31
|
+
"QB-Realm-Hostname": `${this.realm}.quickbase.com`,
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
};
|
|
34
|
+
const response = await this.fetchApi(
|
|
35
|
+
`${this.baseUrl}/auth/temporary/${dbid}`,
|
|
36
|
+
{
|
|
37
|
+
method: "GET",
|
|
38
|
+
headers,
|
|
39
|
+
credentials: "include",
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
45
|
+
const message = errorBody.message || "Unknown error";
|
|
46
|
+
throw new Error(`API Error: ${message} (Status: ${response.status})`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const tokenResult = await response.json();
|
|
50
|
+
const token = tokenResult.temporaryAuthorization;
|
|
51
|
+
if (!token) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
"API Error: No temporary token returned from API (Status: 200)"
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
this.tokenCache.set(dbid, token);
|
|
57
|
+
console.log(`Fetched and cached new token for dbid: ${dbid}`, token);
|
|
58
|
+
return token;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async getToken(dbid: string): Promise<string | undefined> {
|
|
62
|
+
let token = this.tokenCache.get(dbid) || this.initialTempToken;
|
|
63
|
+
if (!token && dbid) {
|
|
64
|
+
token = await this.fetchTempToken(dbid);
|
|
65
|
+
}
|
|
66
|
+
return token;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
applyHeaders(headers: Record<string, string>, token: string): void {
|
|
70
|
+
headers["Authorization"] = `QB-TEMP-TOKEN ${token}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async handleError(
|
|
74
|
+
status: number,
|
|
75
|
+
params: any,
|
|
76
|
+
attempt: number,
|
|
77
|
+
maxAttempts: number,
|
|
78
|
+
debug?: boolean,
|
|
79
|
+
methodName?: string
|
|
80
|
+
): Promise<string | null> {
|
|
81
|
+
if (status !== 401 || attempt >= maxAttempts - 1) return null;
|
|
82
|
+
if (debug)
|
|
83
|
+
console.log(
|
|
84
|
+
`Authorization error for ${
|
|
85
|
+
methodName || "method"
|
|
86
|
+
} (temp token), refreshing token:`
|
|
87
|
+
);
|
|
88
|
+
const dbid = extractDbid(params);
|
|
89
|
+
if (!dbid) {
|
|
90
|
+
if (debug)
|
|
91
|
+
console.log(
|
|
92
|
+
`No dbid available for ${
|
|
93
|
+
methodName || "method"
|
|
94
|
+
}, skipping token refresh`
|
|
95
|
+
);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (debug) console.log(`Refreshing temp token for dbid: ${dbid}`);
|
|
99
|
+
const newToken = await this.fetchTempToken(dbid);
|
|
100
|
+
this.tokenCache.set(dbid, newToken);
|
|
101
|
+
return newToken;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export class UserTokenStrategy implements AuthorizationStrategy {
|
|
106
|
+
constructor(private userToken: string) {}
|
|
107
|
+
|
|
108
|
+
async getToken(_dbid: string): Promise<string> {
|
|
109
|
+
return this.userToken;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
applyHeaders(headers: Record<string, string>, token: string): void {
|
|
113
|
+
headers["Authorization"] = `QB-USER-TOKEN ${token}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async handleError(
|
|
117
|
+
status: number,
|
|
118
|
+
_params: any,
|
|
119
|
+
attempt: number,
|
|
120
|
+
maxAttempts: number,
|
|
121
|
+
debug?: boolean,
|
|
122
|
+
methodName?: string
|
|
123
|
+
): Promise<string | null> {
|
|
124
|
+
if (status !== 401 || attempt >= maxAttempts - 1) return null;
|
|
125
|
+
if (debug)
|
|
126
|
+
console.log(
|
|
127
|
+
`Retrying ${
|
|
128
|
+
methodName || "method"
|
|
129
|
+
} with existing user token: ${this.userToken.substring(0, 10)}...`
|
|
130
|
+
);
|
|
131
|
+
return this.userToken;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export class SsoTokenStrategy implements AuthorizationStrategy {
|
|
136
|
+
private currentToken: string | undefined;
|
|
137
|
+
|
|
138
|
+
constructor(
|
|
139
|
+
private samlToken: string,
|
|
140
|
+
private realm: string,
|
|
141
|
+
private fetchApi: typeof fetch,
|
|
142
|
+
private debug: boolean = false
|
|
143
|
+
) {}
|
|
144
|
+
|
|
145
|
+
async getToken(_dbid: string): Promise<string | undefined> {
|
|
146
|
+
if (!this.currentToken) {
|
|
147
|
+
this.currentToken = await this.fetchSsoToken({
|
|
148
|
+
grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
|
|
149
|
+
requested_token_type:
|
|
150
|
+
"urn:quickbase:params:oauth:token-type:temp_token",
|
|
151
|
+
subject_token: this.samlToken,
|
|
152
|
+
subject_token_type: "urn:ietf:params:oauth:token-type:saml2",
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
return this.currentToken;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
applyHeaders(headers: Record<string, string>, token: string): void {
|
|
159
|
+
headers["Authorization"] = `QB-TEMP-TOKEN ${token}`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async handleError(
|
|
163
|
+
status: number,
|
|
164
|
+
_params: any,
|
|
165
|
+
attempt: number,
|
|
166
|
+
maxAttempts: number,
|
|
167
|
+
debug?: boolean,
|
|
168
|
+
methodName?: string
|
|
169
|
+
): Promise<string | null> {
|
|
170
|
+
if (status !== 401 || attempt >= maxAttempts - 1) return null;
|
|
171
|
+
|
|
172
|
+
if (debug || this.debug) {
|
|
173
|
+
console.log(
|
|
174
|
+
`Authorization error for ${
|
|
175
|
+
methodName || "method"
|
|
176
|
+
} (SSO), refreshing token`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const newToken = await this.refreshSsoToken(debug || this.debug);
|
|
181
|
+
if (newToken) {
|
|
182
|
+
this.currentToken = newToken;
|
|
183
|
+
return newToken;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private async refreshSsoToken(debug: boolean = false): Promise<string> {
|
|
189
|
+
const payload = {
|
|
190
|
+
grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
|
|
191
|
+
requested_token_type: "urn:quickbase:params:oauth:token-type:temp_token",
|
|
192
|
+
subject_token: this.samlToken,
|
|
193
|
+
subject_token_type: "urn:ietf:params:oauth:token-type:saml2",
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const response = await this.fetchApi(
|
|
197
|
+
`https://api.quickbase.com/v1/auth/oauth/token`,
|
|
198
|
+
{
|
|
199
|
+
method: "POST",
|
|
200
|
+
headers: {
|
|
201
|
+
"QB-Realm-Hostname": `${this.realm}.quickbase.com`,
|
|
202
|
+
"Content-Type": "application/json",
|
|
203
|
+
},
|
|
204
|
+
body: JSON.stringify(payload),
|
|
205
|
+
credentials: "omit",
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
if (!response.ok) {
|
|
210
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
211
|
+
if (debug) {
|
|
212
|
+
console.log(`[SSO Refresh] Failed: ${response.status}`, errorBody);
|
|
213
|
+
}
|
|
214
|
+
throw new Error(
|
|
215
|
+
`SSO token refresh failed: ${errorBody.message || "Unknown error"}`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const result = await response.json();
|
|
220
|
+
const newToken = result.access_token;
|
|
221
|
+
if (!newToken) {
|
|
222
|
+
throw new Error("No access token returned from SSO token exchange");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (debug) {
|
|
226
|
+
console.log(`[SSO Refresh] New token: ${newToken.substring(0, 10)}...`);
|
|
227
|
+
}
|
|
228
|
+
return newToken;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private async fetchSsoToken(params: {
|
|
232
|
+
grant_type: string;
|
|
233
|
+
requested_token_type: string;
|
|
234
|
+
subject_token: string;
|
|
235
|
+
subject_token_type: string;
|
|
236
|
+
}): Promise<string> {
|
|
237
|
+
const response = await this.fetchApi(
|
|
238
|
+
`https://api.quickbase.com/v1/auth/oauth/token`,
|
|
239
|
+
{
|
|
240
|
+
method: "POST",
|
|
241
|
+
headers: {
|
|
242
|
+
"QB-Realm-Hostname": `${this.realm}.quickbase.com`,
|
|
243
|
+
"Content-Type": "application/json",
|
|
244
|
+
},
|
|
245
|
+
body: JSON.stringify(params),
|
|
246
|
+
credentials: "omit",
|
|
247
|
+
}
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
if (!response.ok) {
|
|
251
|
+
const errorBody = await response.json().catch(() => ({}));
|
|
252
|
+
if (this.debug) {
|
|
253
|
+
console.log(`[fetchSsoToken] Failed: ${response.status}`, errorBody);
|
|
254
|
+
}
|
|
255
|
+
throw new Error(
|
|
256
|
+
`SSO token fetch failed: ${errorBody.message || "Unknown error"}`
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const result = await response.json();
|
|
261
|
+
const newToken = result.access_token;
|
|
262
|
+
if (!newToken) {
|
|
263
|
+
throw new Error("No access token returned from SSO token exchange");
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (this.debug) {
|
|
267
|
+
console.log(
|
|
268
|
+
`[fetchSsoToken] Fetched token: ${newToken.substring(0, 10)}...`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return newToken;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function extractDbid(params: any): string | undefined {
|
|
276
|
+
return (
|
|
277
|
+
params.dbid ||
|
|
278
|
+
params.tableId ||
|
|
279
|
+
params.appId ||
|
|
280
|
+
params.body?.from ||
|
|
281
|
+
params.body?.to
|
|
282
|
+
);
|
|
283
|
+
}
|