quickbase-js 0.1.0-beta.12 → 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 (168) hide show
  1. package/README.md +48 -18
  2. package/dist/esm/quickbase.d.ts +13 -3
  3. package/dist/esm/quickbase.js +416 -49
  4. package/dist/esm/quickbase.js.map +1 -1
  5. package/dist/esm/quickbase.min.js +1 -1
  6. package/dist/esm/quickbase.min.js.map +1 -1
  7. package/dist/umd/quickbase.umd.js +416 -49
  8. package/dist/umd/quickbase.umd.js.map +1 -1
  9. package/dist/umd/quickbase.umd.min.js +1 -1
  10. package/dist/umd/quickbase.umd.min.js.map +1 -1
  11. package/package.json +11 -4
  12. package/CHANGELOG.md +0 -227
  13. package/build-common.js +0 -131
  14. package/build-esm.js +0 -71
  15. package/build-umd.js +0 -69
  16. package/docs/.vitepress/cache/deps/@theme_index.js +0 -275
  17. package/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
  18. package/docs/.vitepress/cache/deps/_metadata.json +0 -40
  19. package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js +0 -12542
  20. package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js.map +0 -7
  21. package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js +0 -9719
  22. package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js.map +0 -7
  23. package/docs/.vitepress/cache/deps/package.json +0 -3
  24. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4504
  25. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  26. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -583
  27. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  28. package/docs/.vitepress/cache/deps/vue.js +0 -343
  29. package/docs/.vitepress/cache/deps/vue.js.map +0 -7
  30. package/docs/.vitepress/config.mts +0 -26
  31. package/docs/api-examples.md +0 -49
  32. package/docs/index.md +0 -59
  33. package/docs/markdown-examples.md +0 -85
  34. package/docs-data/api-docs.json +0 -4143
  35. package/examples/quicbase-jsCDN.html +0 -36
  36. package/examples/react.js +0 -48
  37. package/examples/vanillajs.html +0 -47
  38. package/index.md +0 -25
  39. package/open-api/fix-spec-main.ts +0 -133
  40. package/open-api/generate-unified-interface.ts +0 -104
  41. package/open-api/generateDocsJson.ts +0 -24
  42. package/open-api/output/quickbase-fixed.json +0 -11191
  43. package/open-api/post-process-generated.ts +0 -226
  44. package/open-api/regenerate-client.ts +0 -117
  45. package/open-api/schema/enhance-general.ts +0 -111
  46. package/open-api/schema/fix-arrays.ts +0 -68
  47. package/open-api/schema/tags/apps.ts +0 -90
  48. package/open-api/schema/tags/fields.ts +0 -471
  49. package/open-api/schema/tags/groups.ts +0 -51
  50. package/open-api/schema/tags/index.ts +0 -66
  51. package/open-api/schema/tags/records.ts +0 -115
  52. package/open-api/schema/tags/tables.ts +0 -211
  53. package/open-api/schema/tags/users.ts +0 -47
  54. package/open-api/types/spec.ts +0 -42
  55. package/open-api/utils/common.ts +0 -29
  56. package/open-api/utils/generateJsDoc.ts +0 -74
  57. package/open-api/utils/infer-schema.ts +0 -40
  58. package/open-api/utils/naming.ts +0 -10
  59. package/open-api/utils/sharedUtils.ts +0 -352
  60. package/playwright.config.ts +0 -37
  61. package/rollup.config.js +0 -114
  62. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  63. package/specs/split/apps.json +0 -1315
  64. package/specs/split/auth.json +0 -191
  65. package/specs/split/fields.json +0 -3869
  66. package/specs/split/records.json +0 -754
  67. package/specs/split/reports.json +0 -619
  68. package/specs/split/tables.json +0 -1605
  69. package/src/RateLimitError.ts +0 -12
  70. package/src/ThrottleBucket.ts +0 -77
  71. package/src/authorizationStrategy.ts +0 -310
  72. package/src/generated-unified/QuickbaseClient.ts +0 -1135
  73. package/src/generated-unified/missing-types-report.json +0 -3
  74. package/src/index.ts +0 -1
  75. package/src/invokeMethod.ts +0 -212
  76. package/src/quickbaseClient.ts +0 -199
  77. package/src/rateLimiter.ts +0 -30
  78. package/src/tokenCache.ts +0 -39
  79. package/src/utils.ts +0 -50
  80. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  81. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  82. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  83. package/tests/playwright/qb/auth/getAppWithTempTokenConcurrency.test.ts +0 -208
  84. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  85. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  86. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  87. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  88. package/tests/setup.ts +0 -53
  89. package/tests/vitest/qb/ThrottleBucket.test.ts +0 -77
  90. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  91. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  92. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  93. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  94. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  95. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  96. package/tests/vitest/qb/auth/mockQuickbaseServer.ts +0 -60
  97. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -73
  98. package/tests/vitest/qb/auth/ssoTokenConcurrency.test.ts +0 -68
  99. package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +0 -65
  100. package/tests/vitest/qb/auth/userTokenConcurrency.test.ts +0 -63
  101. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  102. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  103. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  104. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -82
  105. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  106. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  107. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  108. package/tests/vitest/qb/formulas/runFormula.test.ts +0 -96
  109. package/tests/vitest/qb/index.ts +0 -29
  110. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  111. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  112. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  113. package/tests/vitest/qb/tables/createRelationship.test.ts +0 -102
  114. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  115. package/tests/vitest/qb/tables/deleteRelationship.test.ts +0 -143
  116. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  117. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  118. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  119. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  120. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -250
  121. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  122. package/tests/vitest/unit/ThrottleBucket.test.ts +0 -101
  123. package/tests/vitest/unit/apps/copyApp.test.ts +0 -581
  124. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  125. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  126. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  127. package/tests/vitest/unit/apps/getAppConcurrency.test.ts +0 -151
  128. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  129. package/tests/vitest/unit/apps/updateApp.test.ts +0 -412
  130. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -81
  131. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -119
  132. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -95
  133. package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +0 -206
  134. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -69
  135. package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +0 -325
  136. package/tests/vitest/unit/auth/userTokenConcurrency.test.ts +0 -62
  137. package/tests/vitest/unit/fields/createField.test.ts +0 -451
  138. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  139. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  140. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -180
  141. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  142. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  143. package/tests/vitest/unit/fields/updateField.test.ts +0 -285
  144. package/tests/vitest/unit/formulas/runFormula.test.ts +0 -205
  145. package/tests/vitest/unit/index.ts +0 -34
  146. package/tests/vitest/unit/quickbaseClientHttpMethods.test.ts +0 -139
  147. package/tests/vitest/unit/rateLimit.test.ts +0 -191
  148. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  149. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  150. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  151. package/tests/vitest/unit/tables/createRelationship.test.ts +0 -212
  152. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  153. package/tests/vitest/unit/tables/deleteRelationship.test.ts +0 -97
  154. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  155. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  156. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  157. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  158. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -307
  159. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  160. package/tests/vitest/unit/tokenLifespan.test.ts +0 -204
  161. package/tests/vitest/unit/umd.test.ts +0 -8
  162. package/tools/log-gen.ts +0 -251
  163. package/tools/log-gen.yaml +0 -4829
  164. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  165. package/tsconfig.build.json +0 -17
  166. package/tsconfig.json +0 -32
  167. package/versionrc.json +0 -9
  168. package/vitest.config.ts +0 -27
@@ -1,219 +0,0 @@
1
- import { test, expect } from "@playwright/test";
2
- import { quickbase, QuickbaseClient } from "../../../../src/quickbaseClient.ts";
3
- import dotenv from "dotenv";
4
-
5
- dotenv.config();
6
-
7
- const loginToQuickbase = async (
8
- page: import("@playwright/test").Page,
9
- quickbaseUrl: string,
10
- username: string,
11
- password: string
12
- ): Promise<boolean> => {
13
- console.log("Logging in to QuickBase");
14
- let loginSuccess = false;
15
- const maxLoginAttempts = 3;
16
- let loginAttempt = 0;
17
-
18
- while (!loginSuccess && loginAttempt < maxLoginAttempts) {
19
- try {
20
- loginAttempt++;
21
- if (loginAttempt > 1) console.log(`Login attempt ${loginAttempt}`);
22
-
23
- await page.goto(quickbaseUrl, { timeout: 60000 });
24
- await page.waitForSelector("input[name='loginid']", { timeout: 60000 });
25
- await page.fill("input[name='loginid']", username);
26
- await page.fill("input[name='password']", password);
27
- await page.click("#signin");
28
- await page.waitForURL(`https://*.quickbase.com/**`, {
29
- waitUntil: "networkidle",
30
- timeout: 60000,
31
- });
32
-
33
- const loginError = await page.$(".login-error");
34
- if (loginError) {
35
- throw new Error("Login failed. Please check your credentials.");
36
- }
37
-
38
- console.log("Signed In to QuickBase.");
39
- loginSuccess = true;
40
- } catch (error) {
41
- console.error(
42
- `Login attempt ${loginAttempt} failed: ${(error as Error).message}`
43
- );
44
- if (loginAttempt >= maxLoginAttempts) {
45
- console.error("Max login attempts reached. Exiting.");
46
- await page.context().browser()!.close();
47
- return false;
48
- }
49
- await new Promise((resolve) => setTimeout(resolve, 5000));
50
- }
51
- }
52
- return loginSuccess;
53
- };
54
-
55
- test.describe("QuickbaseClient Integration - Token Invalidation with Cached Token", () => {
56
- test("retries with new token when cached token is unexpectedly invalidated", async ({
57
- page,
58
- }) => {
59
- // Type-safe environment variables
60
- const realm = process.env.QB_REALM ?? "";
61
- const appId = process.env.QB_APP_ID ?? "";
62
- const username = process.env.QB_USERNAME ?? "";
63
- const password = process.env.QB_PASSWORD ?? "";
64
-
65
- if (!realm || !appId || !username || !password) {
66
- throw new Error(
67
- "Required QuickBase environment variables are not defined"
68
- );
69
- }
70
-
71
- // Login to QuickBase
72
- const quickbaseUrl = `https://${realm}.quickbase.com/db/main?a=SignIn`;
73
- const loginSuccess = await loginToQuickbase(
74
- page,
75
- quickbaseUrl,
76
- username,
77
- password
78
- );
79
- if (!loginSuccess) {
80
- throw new Error("Failed to log in to QuickBase after max attempts.");
81
- }
82
-
83
- // Navigate to the app page to ensure session context
84
- await page.goto(`https://${realm}.quickbase.com/db/${appId}`, {
85
- waitUntil: "networkidle",
86
- timeout: 60000,
87
- });
88
- console.log("Post-login URL after app navigation:", page.url());
89
-
90
- // Track tokens and call counts
91
- let callCount = 0;
92
- let getAppCallCount = 0;
93
- let initialToken: string | null = null;
94
- let retryToken: string | null = null;
95
- const fetchInits: { url: string; init: RequestInit }[] = [];
96
-
97
- const client = quickbase({
98
- realm,
99
- useTempTokens: true,
100
- debug: true,
101
- fetchApi: async (input: RequestInfo | URL, init?: RequestInit) => {
102
- const url = input.toString();
103
- callCount++;
104
- console.log(`fetchApi called for ${url}, callCount: ${callCount}`);
105
-
106
- const effectiveInit = init || {};
107
- fetchInits.push({ url, init: effectiveInit });
108
-
109
- const response = await page.evaluate(
110
- async ([fetchUrl, fetchInit]: [string, RequestInit]) => {
111
- const res = await fetch(fetchUrl, fetchInit);
112
- const body = await res.text();
113
- const headersObj: Record<string, string> = {};
114
- res.headers.forEach((value, key) => {
115
- headersObj[key] = value;
116
- });
117
- return {
118
- ok: res.ok,
119
- status: res.status,
120
- statusText: res.statusText,
121
- headers: headersObj,
122
- body,
123
- };
124
- },
125
- [url, effectiveInit] as [string, RequestInit]
126
- );
127
-
128
- // Simulate 401 for the first getApp call
129
- if (url.includes(`/apps/${appId}`)) {
130
- getAppCallCount++;
131
- console.log(`getApp call count: ${getAppCallCount}`);
132
- if (getAppCallCount === 1) {
133
- console.log("Simulating 401 Unauthorized for first getApp call");
134
- return new Response(JSON.stringify({ message: "Unauthorized" }), {
135
- status: 401,
136
- statusText: "Unauthorized",
137
- headers: { "Content-Type": "application/json" },
138
- });
139
- }
140
- }
141
-
142
- const fetchResponse = new Response(response.body || null, {
143
- status: response.status,
144
- statusText: response.statusText,
145
- headers: new Headers(response.headers),
146
- });
147
-
148
- // Override json() to parse the body correctly
149
- fetchResponse.json = async () => {
150
- if (!response.body) {
151
- throw new Error("Empty response body from API");
152
- }
153
- try {
154
- return JSON.parse(response.body);
155
- } catch (e) {
156
- throw new SyntaxError(`Invalid JSON response: ${response.body}`);
157
- }
158
- };
159
-
160
- // Capture tokens for validation
161
- if (url.includes("/auth/temporary/")) {
162
- try {
163
- const json = await fetchResponse.clone().json();
164
- const token = json.temporaryAuthorization;
165
- if (!initialToken) {
166
- initialToken = token;
167
- console.log(`Captured initial token: ${initialToken}`);
168
- } else if (!retryToken) {
169
- retryToken = token;
170
- console.log(`Captured retry token: ${retryToken}`);
171
- }
172
- } catch (error) {
173
- console.error("Failed to parse token response:", error);
174
- }
175
- }
176
-
177
- console.log(`Raw response from ${url}:`, {
178
- status: response.status,
179
- statusText: response.statusText,
180
- body: response.body,
181
- });
182
-
183
- return fetchResponse;
184
- },
185
- }) as QuickbaseClient;
186
-
187
- // Pre-fetch token to simulate cached token
188
- console.log("Pre-fetching initial token...");
189
- const preFetchResult = await client.getTempTokenDBID({ dbid: appId });
190
- console.log("Initial token pre-fetched and cached:", preFetchResult);
191
-
192
- // Call getApp, expecting a 401 followed by a retry with a new token
193
- const appPromise = client.getApp({ appId });
194
- await page.waitForResponse(`https://api.quickbase.com/v1/apps/${appId}`, {
195
- timeout: 30000,
196
- });
197
- const appResult = await appPromise;
198
- console.log("App response after token invalidation and retry:", appResult);
199
-
200
- // Validate the app response
201
- expect(appResult).toHaveProperty("id", appId);
202
- expect(appResult).toHaveProperty("name");
203
-
204
- // Verify call counts and token behavior
205
- console.log(
206
- `Final callCount: ${callCount}, Final getAppCallCount: ${getAppCallCount}`
207
- );
208
- expect(callCount).toBe(4); // Pre-fetch, 401, token retry, getApp success
209
- expect(getAppCallCount).toBe(2); // Initial 401, retry success
210
-
211
- // Validate pre-fetch and retry tokens
212
- console.log(`Initial token: ${initialToken}`);
213
- console.log(`Retry token: ${retryToken}`);
214
- expect(initialToken).toBeDefined();
215
- expect(initialToken).toBe(preFetchResult.temporaryAuthorization); // Confirm pre-fetch token was used
216
- expect(retryToken).toBeDefined();
217
- expect(initialToken).not.toBe(retryToken); // Confirm retry used a new token
218
- });
219
- });
@@ -1,162 +0,0 @@
1
- // tests/playwright/qb/auth/getAppWithTempToken.test.ts
2
- import { test, expect } from "@playwright/test";
3
- import { quickbase } from "../../../../src/quickbaseClient.ts"; // Keep .ts for now
4
- import dotenv from "dotenv";
5
-
6
- dotenv.config();
7
-
8
- const loginToQuickbase = async (
9
- page: import("@playwright/test").Page,
10
- quickbaseUrl: string,
11
- username: string,
12
- password: string
13
- ): Promise<boolean> => {
14
- let loginSuccess = false;
15
- const maxLoginAttempts = 3;
16
- let loginAttempt = 0;
17
-
18
- while (!loginSuccess && loginAttempt < maxLoginAttempts) {
19
- try {
20
- loginAttempt++;
21
- if (loginAttempt > 1) console.log(`Login attempt ${loginAttempt}`);
22
-
23
- await page.goto(quickbaseUrl, { timeout: 60000 });
24
- await page.waitForSelector("input[name='loginid']", { timeout: 60000 });
25
- await page.fill("input[name='loginid']", username);
26
- await page.fill("input[name='password']", password);
27
- await page.click("#signin");
28
- await page.waitForURL(`https://*.quickbase.com/**`, {
29
- waitUntil: "networkidle",
30
- timeout: 60000,
31
- });
32
-
33
- const loginError = await page.$(".login-error");
34
- if (loginError) {
35
- throw new Error("Login failed. Please check your credentials.");
36
- }
37
-
38
- console.log("Signed In to QuickBase.");
39
- loginSuccess = true;
40
- } catch (error) {
41
- console.error(
42
- `Login attempt ${loginAttempt} failed: ${(error as Error).message}`
43
- );
44
- if (loginAttempt >= maxLoginAttempts) {
45
- console.error("Max login attempts reached. Exiting.");
46
- await page.context().browser()!.close();
47
- return false;
48
- }
49
- await new Promise((resolve) => setTimeout(resolve, 5000));
50
- }
51
- }
52
- return loginSuccess;
53
- };
54
-
55
- test.describe("QuickbaseClient Integration - getApp with Temporary Token", () => {
56
- test("uses temporary token with correct credentials settings in browser", async ({
57
- page,
58
- }) => {
59
- const realm = process.env.QB_REALM;
60
- const appId = process.env.QB_APP_ID;
61
- const username = process.env.QB_USERNAME;
62
- const password = process.env.QB_PASSWORD;
63
-
64
- if (!realm) throw new Error("QB_REALM is not defined in .env");
65
- if (!appId) throw new Error("QB_APP_ID is not defined in .env");
66
- if (!username) throw new Error("QB_USERNAME is not defined in .env");
67
- if (!password) throw new Error("QB_PASSWORD is not defined in .env");
68
-
69
- const fetchInits: { url: string; init: RequestInit }[] = [];
70
-
71
- const quickbaseUrl = `https://${realm}.quickbase.com/db/main?a=SignIn`;
72
- const loginSuccess = await loginToQuickbase(
73
- page,
74
- quickbaseUrl,
75
- username,
76
- password
77
- );
78
- if (!loginSuccess) {
79
- throw new Error("Failed to log in to QuickBase after max attempts.");
80
- }
81
-
82
- await page.goto(`https://${realm}.quickbase.com/db/${appId}`, {
83
- waitUntil: "networkidle",
84
- timeout: 60000,
85
- });
86
-
87
- const client = quickbase({
88
- realm,
89
- useTempTokens: true,
90
- fetchApi: async (url: RequestInfo | URL, init?: RequestInit) => {
91
- // Use optional init and provide default empty object if undefined
92
- const effectiveInit = init || {};
93
- fetchInits.push({ url: String(url), init: effectiveInit });
94
- const response = await page.evaluate(
95
- async (args: [string, RequestInit]) => {
96
- const [fetchUrl, fetchInit] = args;
97
- const res = await fetch(fetchUrl, fetchInit);
98
- const body = await res.text();
99
- const headersObj: Record<string, string> = {};
100
- res.headers.forEach((value, key) => {
101
- headersObj[key] = value;
102
- });
103
- return {
104
- ok: res.ok,
105
- status: res.status,
106
- statusText: res.statusText,
107
- headers: headersObj,
108
- body,
109
- };
110
- },
111
- [String(url), effectiveInit] as [string, RequestInit]
112
- );
113
-
114
- const fetchResponse = new Response(response.body || null, {
115
- status: response.status,
116
- statusText: response.statusText,
117
- headers: new Headers(response.headers),
118
- });
119
-
120
- fetchResponse.json = async () => {
121
- if (!response.body) {
122
- throw new Error("Empty response body from API");
123
- }
124
- try {
125
- return JSON.parse(response.body);
126
- } catch (e) {
127
- throw new SyntaxError(`Invalid JSON response: ${response.body}`);
128
- }
129
- };
130
-
131
- return fetchResponse;
132
- },
133
- });
134
-
135
- const appPromise = client.getApp({ appId });
136
- await page.waitForResponse(`https://api.quickbase.com/v1/apps/${appId}`, {
137
- timeout: 30000,
138
- });
139
- const appResult = await appPromise;
140
-
141
- expect(appResult).toHaveProperty("id", appId);
142
- expect(appResult).toHaveProperty("name");
143
-
144
- const tokenFetchInit = fetchInits.find((entry) =>
145
- entry.url.includes(`/auth/temporary/${appId}`)
146
- );
147
- expect(
148
- tokenFetchInit,
149
- "No fetch init captured for token request"
150
- ).toBeDefined();
151
- expect(tokenFetchInit!.init.credentials).toBe("include");
152
-
153
- const appFetchInit = fetchInits.find((entry) =>
154
- entry.url.includes(`/apps/${appId}`)
155
- );
156
- expect(
157
- appFetchInit,
158
- "No fetch init captured for getApp request"
159
- ).toBeDefined();
160
- expect(appFetchInit!.init.credentials).toBe("omit");
161
- });
162
- });
@@ -1,208 +0,0 @@
1
- // tests/playwright/qb/auth/getAppWithTempTokenConcurrency.test.ts
2
- import { test, expect } from "@playwright/test";
3
- import { quickbase } from "../../../../src/quickbaseClient.ts"; // Keep .ts for now
4
- import dotenv from "dotenv";
5
-
6
- dotenv.config();
7
-
8
- const loginToQuickbase = async (
9
- page: import("@playwright/test").Page,
10
- quickbaseUrl: string,
11
- username: string,
12
- password: string
13
- ): Promise<boolean> => {
14
- let loginSuccess = false;
15
- const maxLoginAttempts = 3;
16
- let loginAttempt = 0;
17
-
18
- while (!loginSuccess && loginAttempt < maxLoginAttempts) {
19
- try {
20
- loginAttempt++;
21
- if (loginAttempt > 1) console.log(`Login attempt ${loginAttempt}`);
22
-
23
- await page.goto(quickbaseUrl, { timeout: 60000 });
24
- await page.waitForSelector("input[name='loginid']", { timeout: 60000 });
25
- await page.fill("input[name='loginid']", username);
26
- await page.fill("input[name='password']", password);
27
- await page.click("#signin");
28
- await page.waitForURL(`https://*.quickbase.com/**`, {
29
- waitUntil: "networkidle",
30
- timeout: 60000,
31
- });
32
-
33
- const loginError = await page.$(".login-error");
34
- if (loginError) {
35
- throw new Error("Login failed. Please check your credentials.");
36
- }
37
-
38
- console.log("Signed In to QuickBase.");
39
- loginSuccess = true;
40
- } catch (error) {
41
- console.error(
42
- `Login attempt ${loginAttempt} failed: ${(error as Error).message}`
43
- );
44
- if (loginAttempt >= maxLoginAttempts) {
45
- console.error("Max login attempts reached. Exiting.");
46
- await page.context().browser()!.close();
47
- return false;
48
- }
49
- await new Promise((resolve) => setTimeout(resolve, 5000));
50
- }
51
- }
52
- return loginSuccess;
53
- };
54
-
55
- test.describe("QuickbaseClient Integration - getApp with Temporary Token Concurrency", () => {
56
- test("handles concurrent getApp requests with a single token fetch", async ({
57
- page,
58
- }) => {
59
- const realm = process.env.QB_REALM;
60
- const appId = process.env.QB_APP_ID;
61
- const username = process.env.QB_USERNAME;
62
- const password = process.env.QB_PASSWORD;
63
-
64
- if (!realm) throw new Error("QB_REALM is not defined in .env");
65
- if (!appId) throw new Error("QB_APP_ID is not defined in .env");
66
- if (!username) throw new Error("QB_USERNAME is not defined in .env");
67
- if (!password) throw new Error("QB_PASSWORD is not defined in .env");
68
-
69
- const fetchInits: { url: string; init: RequestInit }[] = [];
70
-
71
- const quickbaseUrl = `https://${realm}.quickbase.com/db/main?a=SignIn`;
72
- const loginSuccess = await loginToQuickbase(
73
- page,
74
- quickbaseUrl,
75
- username,
76
- password
77
- );
78
- if (!loginSuccess) {
79
- throw new Error("Failed to log in to QuickBase after max attempts.");
80
- }
81
-
82
- await page.goto(`https://${realm}.quickbase.com/db/${appId}`, {
83
- waitUntil: "networkidle",
84
- timeout: 60000,
85
- });
86
-
87
- const client = quickbase({
88
- realm,
89
- useTempTokens: true,
90
- debug: true, // Enable debug logs to verify concurrency behavior
91
- fetchApi: async (url: RequestInfo | URL, init?: RequestInit) => {
92
- const effectiveInit = init || {};
93
- fetchInits.push({ url: String(url), init: effectiveInit });
94
- const response = await page.evaluate(
95
- async (args: [string, RequestInit]) => {
96
- const [fetchUrl, fetchInit] = args;
97
- const res = await fetch(fetchUrl, fetchInit);
98
- const body = await res.text();
99
- const headersObj: Record<string, string> = {};
100
- res.headers.forEach((value, key) => {
101
- headersObj[key] = value;
102
- });
103
- return {
104
- ok: res.ok,
105
- status: res.status,
106
- statusText: res.statusText,
107
- headers: headersObj,
108
- body,
109
- };
110
- },
111
- [String(url), effectiveInit] as [string, RequestInit]
112
- );
113
-
114
- const fetchResponse = new Response(response.body || null, {
115
- status: response.status,
116
- statusText: response.statusText,
117
- headers: new Headers(response.headers),
118
- });
119
-
120
- fetchResponse.json = async () => {
121
- if (!response.body) {
122
- throw new Error("Empty response body from API");
123
- }
124
- try {
125
- return JSON.parse(response.body);
126
- } catch (e) {
127
- throw new SyntaxError(`Invalid JSON response: ${response.body}`);
128
- }
129
- };
130
-
131
- return fetchResponse;
132
- },
133
- });
134
-
135
- // Make three concurrent getApp requests
136
- const concurrentRequests = [
137
- client.getApp({ appId }),
138
- client.getApp({ appId }),
139
- client.getApp({ appId }),
140
- ];
141
-
142
- // Wait for all responses to complete
143
- await Promise.all([
144
- page.waitForResponse(`https://api.quickbase.com/v1/apps/${appId}`, {
145
- timeout: 30000,
146
- }),
147
- page.waitForResponse(`https://api.quickbase.com/v1/apps/${appId}`, {
148
- timeout: 30000,
149
- }),
150
- page.waitForResponse(`https://api.quickbase.com/v1/apps/${appId}`, {
151
- timeout: 30000,
152
- }),
153
- ]);
154
-
155
- const results = await Promise.all(concurrentRequests);
156
-
157
- // Expected app data (based on your previous test)
158
- const expectedAppData = {
159
- id: appId,
160
- name: "qb-copy",
161
- created: expect.any(Date),
162
- updated: expect.any(Date),
163
- description: "",
164
- timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
165
- dateFormat: "MM-DD-YYYY",
166
- hasEveryoneOnTheInternet: false,
167
- memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
168
- securityProperties: {
169
- allowClone: false,
170
- allowExport: true,
171
- enableAppTokens: true,
172
- hideFromPublic: false,
173
- mustBeRealmApproved: false,
174
- useIPFilter: false,
175
- },
176
- ancestorId: undefined,
177
- dataClassification: undefined,
178
- variables: [{ name: "TestVar", value: "TestValue" }],
179
- };
180
-
181
- // Assert all results match the expected data
182
- expect(results).toHaveLength(3);
183
- results.forEach((result) => {
184
- expect(result).toEqual(expectedAppData);
185
- });
186
-
187
- // Verify token fetch behavior
188
- const tokenFetchInits = fetchInits.filter((entry) =>
189
- entry.url.includes(`/auth/temporary/${appId}`)
190
- );
191
- expect(tokenFetchInits).toHaveLength(1); // Only one token fetch should occur
192
- expect(tokenFetchInits[0].init.credentials).toBe("include");
193
-
194
- const appFetchInits = fetchInits.filter((entry) =>
195
- entry.url.includes(`/apps/${appId}`)
196
- );
197
- expect(appFetchInits).toHaveLength(3); // Three getApp requests
198
- appFetchInits.forEach((init) => {
199
- expect(init.init.credentials).toBe("omit");
200
- expect(init.init.headers).toHaveProperty("Authorization");
201
- expect(
202
- (init.init.headers as Record<string, string>)["Authorization"]
203
- ).toMatch(/^QB-TEMP-TOKEN .+$/);
204
- });
205
-
206
- console.log("Test completed. Check debug logs for concurrency details.");
207
- });
208
- });