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,119 +0,0 @@
1
- // tests/vitest/unit/auth/getTempToken.test.ts
2
- import { describe, it, expect, beforeEach, vi } from "vitest";
3
- import {
4
- createClient,
5
- mockFetch,
6
- QB_REALM,
7
- QB_TABLE_ID_1,
8
- } from "@tests/setup.ts";
9
- import { TokenCache } from "../../../../src/tokenCache"; // Corrected path
10
- import { AuthApi } from "../../../../src/generated/apis/AuthApi";
11
-
12
- describe("QuickbaseClient Unit - getTempTokenDBID", () => {
13
- let client: ReturnType<typeof createClient>;
14
- let tokenCache: TokenCache;
15
- let authApi: AuthApi;
16
-
17
- beforeEach(() => {
18
- mockFetch.mockClear();
19
- tokenCache = new TokenCache();
20
- client = createClient(mockFetch, {
21
- useTempTokens: true,
22
- debug: true,
23
- tokenCache,
24
- });
25
- authApi = new AuthApi(client["configuration"]);
26
- vi.spyOn(authApi, "getTempTokenDBIDRaw").mockImplementation(
27
- async (params) => {
28
- const mockToken = "b123xyz_temp_token";
29
- if (params.dbid === QB_TABLE_ID_1) {
30
- return {
31
- value: () => Promise.resolve({ temporaryAuthorization: mockToken }),
32
- } as any;
33
- }
34
- throw new Error("Unexpected dbid");
35
- }
36
- );
37
- });
38
-
39
- it("initializes without errors", () => {
40
- expect(client).toBeDefined();
41
- });
42
-
43
- it("has getTempTokenDBID method", () => {
44
- expect(typeof client.getTempTokenDBID).toBe("function");
45
- });
46
-
47
- it("fetches and caches temp token on first call", async () => {
48
- const mockToken = "b123xyz_temp_token";
49
-
50
- mockFetch.mockResolvedValueOnce(
51
- new Response(JSON.stringify({ temporaryAuthorization: mockToken }), {
52
- status: 200,
53
- headers: { "Content-Type": "application/json" },
54
- })
55
- );
56
-
57
- const result = await client.getTempTokenDBID({ dbid: QB_TABLE_ID_1 });
58
- expect(result).toEqual({ temporaryAuthorization: mockToken });
59
- expect(mockFetch).toHaveBeenCalledWith(
60
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
61
- expect.objectContaining({
62
- method: "GET",
63
- headers: expect.objectContaining({
64
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
65
- "Content-Type": "application/json",
66
- }),
67
- credentials: "include",
68
- })
69
- );
70
- });
71
-
72
- it("reuses cached temp token on second call", async () => {
73
- const mockToken = "b123xyz_temp_token";
74
-
75
- mockFetch.mockResolvedValueOnce(
76
- new Response(JSON.stringify({ temporaryAuthorization: mockToken }), {
77
- status: 200,
78
- headers: { "Content-Type": "application/json" },
79
- })
80
- );
81
-
82
- const firstResult = await client.getTempTokenDBID({ dbid: QB_TABLE_ID_1 });
83
- expect(firstResult).toEqual({ temporaryAuthorization: mockToken });
84
- expect(mockFetch).toHaveBeenCalledTimes(1);
85
-
86
- mockFetch.mockClear();
87
- const secondResult = await client.getTempTokenDBID({ dbid: QB_TABLE_ID_1 });
88
- expect(secondResult).toEqual({ temporaryAuthorization: mockToken });
89
- expect(mockFetch).not.toHaveBeenCalled();
90
- });
91
-
92
- it("handles API error", async () => {
93
- mockFetch.mockResolvedValueOnce(
94
- new Response(JSON.stringify({ message: "Unauthorized" }), {
95
- status: 401,
96
- headers: { "Content-Type": "application/json" },
97
- })
98
- );
99
-
100
- await expect(
101
- client.getTempTokenDBID({ dbid: QB_TABLE_ID_1 })
102
- ).rejects.toSatisfy((error: Error) => {
103
- expect(error).toBeInstanceOf(Error);
104
- expect(error.message).toBe("API Error: Unauthorized (Status: 401)");
105
- return true;
106
- });
107
- expect(mockFetch).toHaveBeenCalledWith(
108
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
109
- expect.objectContaining({
110
- method: "GET",
111
- headers: expect.objectContaining({
112
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
113
- "Content-Type": "application/json",
114
- }),
115
- credentials: "include",
116
- })
117
- );
118
- });
119
- });
@@ -1,95 +0,0 @@
1
- // tests/vitest/unit/auth/retryTempToken401.test.ts
2
-
3
- import { describe, it, expect, vi } from "vitest";
4
- import {
5
- createClient,
6
- mockFetch,
7
- QB_REALM,
8
- QB_TABLE_ID_1,
9
- } from "@tests/setup.ts";
10
-
11
- describe("QuickbaseClient Unit - Temp Token Retry on 401", () => {
12
- it("creates a new token on 401 and retries successfully", async () => {
13
- mockFetch
14
- .mockResolvedValueOnce(
15
- new Response(
16
- JSON.stringify({ temporaryAuthorization: "initial_token" }),
17
- { status: 200 }
18
- )
19
- )
20
- .mockResolvedValueOnce(
21
- new Response(JSON.stringify({ message: "Unauthorized" }), {
22
- status: 401,
23
- })
24
- )
25
- .mockResolvedValueOnce(
26
- new Response(
27
- JSON.stringify({ temporaryAuthorization: "new_token_456" }),
28
- { status: 200 }
29
- )
30
- )
31
- .mockResolvedValueOnce(
32
- new Response(JSON.stringify([{ id: 1, label: "Field1" }]), {
33
- status: 200,
34
- })
35
- );
36
-
37
- const consoleSpy = vi.spyOn(console, "log");
38
- const client = createClient(mockFetch, {
39
- realm: QB_REALM,
40
- useTempTokens: true,
41
- debug: true,
42
- });
43
-
44
- const result = await client.getFields({ tableId: QB_TABLE_ID_1 });
45
-
46
- expect(result).toEqual([{ id: 1, label: "Field1" }]);
47
- expect(mockFetch).toHaveBeenCalledTimes(4);
48
- expect(mockFetch).toHaveBeenNthCalledWith(
49
- 1,
50
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
51
- expect.objectContaining({
52
- credentials: "include",
53
- method: "GET",
54
- })
55
- );
56
- expect(mockFetch).toHaveBeenNthCalledWith(
57
- 2,
58
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
59
- expect.objectContaining({
60
- method: "GET",
61
- headers: expect.objectContaining({
62
- Authorization: "QB-TEMP-TOKEN initial_token",
63
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
64
- "Content-Type": "application/json",
65
- }),
66
- })
67
- );
68
- expect(mockFetch).toHaveBeenNthCalledWith(
69
- 3,
70
- `https://api.quickbase.com/v1/auth/temporary/${QB_TABLE_ID_1}`,
71
- expect.objectContaining({
72
- credentials: "include",
73
- method: "GET",
74
- })
75
- );
76
- expect(mockFetch).toHaveBeenNthCalledWith(
77
- 4,
78
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
79
- expect.objectContaining({
80
- method: "GET",
81
- headers: expect.objectContaining({
82
- Authorization: "QB-TEMP-TOKEN new_token_456",
83
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
84
- "Content-Type": "application/json",
85
- }),
86
- })
87
- );
88
- expect(consoleSpy).toHaveBeenCalledWith(
89
- "Authorization error for getFields (temp token), refreshing token:"
90
- );
91
- expect(consoleSpy).toHaveBeenCalledWith(
92
- "[getFields] Retrying with token: new_token_..."
93
- );
94
- });
95
- });
@@ -1,206 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi } from "vitest";
2
- import { createClient, mockFetch } from "@tests/setup.ts";
3
-
4
- describe("QuickbaseClient - Temp Token Retry Limit", () => {
5
- let client: ReturnType<typeof createClient>;
6
-
7
- beforeEach(() => {
8
- mockFetch.mockClear();
9
- });
10
-
11
- it("exhausts retries after maxRetries (3) and throws an error", async () => {
12
- client = createClient(mockFetch, {
13
- useTempTokens: true,
14
- debug: true,
15
- maxRetries: 3,
16
- });
17
-
18
- const mockDbid = "mockDbid123";
19
- let callCount = 0;
20
-
21
- mockFetch.mockImplementation((url) => {
22
- callCount++;
23
- if (url.includes("auth/temporary") && callCount === 1) {
24
- return Promise.resolve({
25
- ok: true,
26
- status: 200,
27
- headers: new Headers({ "Content-Type": "application/json" }),
28
- json: () => Promise.resolve({ temporaryAuthorization: "token_1" }),
29
- });
30
- }
31
- if (url.includes("fields") && callCount === 2) {
32
- return Promise.resolve({
33
- ok: false,
34
- status: 401,
35
- headers: new Headers({ "Content-Type": "application/json" }),
36
- json: () => Promise.resolve({ message: "Unauthorized 1" }),
37
- });
38
- }
39
- if (url.includes("auth/temporary") && callCount === 3) {
40
- return Promise.resolve({
41
- ok: true,
42
- status: 200,
43
- headers: new Headers({ "Content-Type": "application/json" }),
44
- json: () => Promise.resolve({ temporaryAuthorization: "token_2" }),
45
- });
46
- }
47
- if (url.includes("fields") && callCount === 4) {
48
- return Promise.resolve({
49
- ok: false,
50
- status: 401,
51
- headers: new Headers({ "Content-Type": "application/json" }),
52
- json: () => Promise.resolve({ message: "Unauthorized 2" }),
53
- });
54
- }
55
- if (url.includes("auth/temporary") && callCount === 5) {
56
- return Promise.resolve({
57
- ok: true,
58
- status: 200,
59
- headers: new Headers({ "Content-Type": "application/json" }),
60
- json: () => Promise.resolve({ temporaryAuthorization: "token_3" }),
61
- });
62
- }
63
- if (url.includes("fields") && callCount === 6) {
64
- return Promise.resolve({
65
- ok: false,
66
- status: 401,
67
- headers: new Headers({ "Content-Type": "application/json" }),
68
- json: () => Promise.resolve({ message: "Unauthorized 3" }),
69
- });
70
- }
71
- if (url.includes("auth/temporary") && callCount === 7) {
72
- return Promise.resolve({
73
- ok: true,
74
- status: 200,
75
- headers: new Headers({ "Content-Type": "application/json" }),
76
- json: () => Promise.resolve({ temporaryAuthorization: "token_4" }),
77
- });
78
- }
79
- if (url.includes("fields") && callCount === 8) {
80
- return Promise.resolve({
81
- ok: false,
82
- status: 401,
83
- headers: new Headers({ "Content-Type": "application/json" }),
84
- json: () => Promise.resolve({ message: "Unauthorized 4" }),
85
- });
86
- }
87
- console.log(
88
- `[mockFetch] Unexpected call: ${url}, callCount: ${callCount}`
89
- );
90
- return Promise.reject(new Error(`Unexpected fetch call: ${url}`));
91
- });
92
-
93
- const consoleSpy = vi.spyOn(console, "log");
94
-
95
- await expect(client.getFields({ tableId: mockDbid })).rejects.toThrow(
96
- "API Error: Unauthorized 4 (Status: 401)"
97
- );
98
-
99
- expect(mockFetch).toHaveBeenCalledTimes(8);
100
- // Rest of assertions...
101
- });
102
-
103
- it("exhausts retries after maxRetries (2) and throws an error", async () => {
104
- client = createClient(mockFetch, {
105
- useTempTokens: true,
106
- debug: true,
107
- maxRetries: 2,
108
- });
109
-
110
- const mockDbid = "mockDbid123";
111
- let callCount = 0;
112
-
113
- mockFetch.mockImplementation((url) => {
114
- callCount++;
115
- if (url.includes("auth/temporary") && callCount === 1) {
116
- return Promise.resolve({
117
- ok: true,
118
- status: 200,
119
- headers: new Headers({ "Content-Type": "application/json" }),
120
- json: () => Promise.resolve({ temporaryAuthorization: "token_1" }),
121
- });
122
- }
123
- if (url.includes("fields") && callCount === 2) {
124
- return Promise.resolve({
125
- ok: false,
126
- status: 401,
127
- headers: new Headers({ "Content-Type": "application/json" }),
128
- json: () => Promise.resolve({ message: "Unauthorized 1" }),
129
- });
130
- }
131
- if (url.includes("auth/temporary") && callCount === 3) {
132
- return Promise.resolve({
133
- ok: true,
134
- status: 200,
135
- headers: new Headers({ "Content-Type": "application/json" }),
136
- json: () => Promise.resolve({ temporaryAuthorization: "token_2" }),
137
- });
138
- }
139
- if (url.includes("fields") && callCount === 4) {
140
- return Promise.resolve({
141
- ok: false,
142
- status: 401,
143
- headers: new Headers({ "Content-Type": "application/json" }),
144
- json: () => Promise.resolve({ message: "Unauthorized 2" }),
145
- });
146
- }
147
- if (url.includes("auth/temporary") && callCount === 5) {
148
- return Promise.resolve({
149
- ok: true,
150
- status: 200,
151
- headers: new Headers({ "Content-Type": "application/json" }),
152
- json: () => Promise.resolve({ temporaryAuthorization: "token_3" }),
153
- });
154
- }
155
- if (url.includes("fields") && callCount === 6) {
156
- return Promise.resolve({
157
- ok: false,
158
- status: 401,
159
- headers: new Headers({ "Content-Type": "application/json" }),
160
- json: () => Promise.resolve({ message: "Unauthorized 3" }),
161
- });
162
- }
163
- console.log(
164
- `[mockFetch] Unexpected call: ${url}, callCount: ${callCount}`
165
- );
166
- return Promise.reject(new Error(`Unexpected fetch call: ${url}`));
167
- });
168
-
169
- const consoleSpy = vi.spyOn(console, "log");
170
-
171
- await expect(client.getFields({ tableId: mockDbid })).rejects.toThrow(
172
- "API Error: Unauthorized 3 (Status: 401)"
173
- );
174
-
175
- expect(mockFetch).toHaveBeenCalledTimes(6);
176
-
177
- const tokenLogs = consoleSpy.mock.calls.filter((call) =>
178
- call[0].includes("Fetched and cached new token")
179
- );
180
- expect(tokenLogs).toHaveLength(3);
181
- expect(tokenLogs).toContainEqual([
182
- "Fetched and cached new token for dbid: mockDbid123",
183
- "token_1",
184
- ]);
185
- expect(tokenLogs).toContainEqual([
186
- "Fetched and cached new token for dbid: mockDbid123",
187
- "token_2",
188
- ]);
189
- expect(tokenLogs).toContainEqual([
190
- "Fetched and cached new token for dbid: mockDbid123",
191
- "token_3",
192
- ]);
193
-
194
- expect(consoleSpy).toHaveBeenCalledWith(
195
- "Authorization error for getFields (temp token), refreshing token:"
196
- );
197
- expect(consoleSpy).toHaveBeenCalledWith(
198
- "[getFields] Retrying with token: token_2..."
199
- );
200
- expect(consoleSpy).toHaveBeenCalledWith(
201
- "[getFields] Retrying with token: token_3..."
202
- );
203
-
204
- consoleSpy.mockRestore();
205
- });
206
- });
@@ -1,66 +0,0 @@
1
- import { describe, it, expect, vi } from "vitest";
2
- import {
3
- createClient,
4
- mockFetch,
5
- QB_REALM,
6
- QB_TABLE_ID_1,
7
- } from "@tests/setup.ts";
8
-
9
- describe("QuickbaseClient Unit - User Token Retry on 401", () => {
10
- it("retries with the same user token on 401 and succeeds", async () => {
11
- mockFetch
12
- .mockResolvedValueOnce(
13
- new Response(JSON.stringify({ message: "Unauthorized" }), {
14
- status: 401,
15
- })
16
- )
17
- .mockResolvedValueOnce(
18
- new Response(JSON.stringify([{ id: 1, label: "Field1" }]), {
19
- status: 200,
20
- })
21
- );
22
-
23
- const consoleSpy = vi.spyOn(console, "log");
24
- const client = createClient(mockFetch, {
25
- realm: QB_REALM,
26
- userToken: "b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
27
- useTempTokens: false,
28
- debug: true,
29
- });
30
-
31
- const result = await client.getFields({ tableId: QB_TABLE_ID_1 });
32
-
33
- expect(result).toEqual([{ id: 1, label: "Field1" }]);
34
- expect(mockFetch).toHaveBeenCalledTimes(2);
35
- expect(mockFetch).toHaveBeenNthCalledWith(
36
- 1,
37
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
38
- expect.objectContaining({
39
- method: "GET",
40
- headers: expect.objectContaining({
41
- Authorization:
42
- "QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
43
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
44
- "Content-Type": "application/json",
45
- }),
46
- })
47
- );
48
- expect(mockFetch).toHaveBeenNthCalledWith(
49
- 2,
50
- `https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
51
- expect.objectContaining({
52
- method: "GET",
53
- headers: expect.objectContaining({
54
- Authorization:
55
- "QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
56
- "QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
57
- "Content-Type": "application/json",
58
- }),
59
- })
60
- );
61
- expect(consoleSpy).toHaveBeenCalledWith(
62
- "Retrying getFields with existing user token: b9f3pk_q4j..."
63
- );
64
- consoleSpy.mockRestore();
65
- });
66
- });