quickbase-js 0.1.0-beta.13 → 0.1.0-beta.14

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