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.
- package/README.md +48 -18
- package/dist/esm/quickbase.d.ts +13 -3
- package/dist/esm/quickbase.js +416 -49
- package/dist/esm/quickbase.js.map +1 -1
- package/dist/esm/quickbase.min.js +1 -1
- package/dist/esm/quickbase.min.js.map +1 -1
- package/dist/umd/quickbase.umd.js +416 -49
- package/dist/umd/quickbase.umd.js.map +1 -1
- package/dist/umd/quickbase.umd.min.js +1 -1
- package/dist/umd/quickbase.umd.min.js.map +1 -1
- package/package.json +11 -4
- package/CHANGELOG.md +0 -227
- package/build-common.js +0 -131
- package/build-esm.js +0 -71
- package/build-umd.js +0 -69
- package/docs/.vitepress/cache/deps/@theme_index.js +0 -275
- package/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
- package/docs/.vitepress/cache/deps/_metadata.json +0 -40
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js +0 -12542
- package/docs/.vitepress/cache/deps/chunk-5A67QEFC.js.map +0 -7
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js +0 -9719
- package/docs/.vitepress/cache/deps/chunk-7D4P4MMP.js.map +0 -7
- package/docs/.vitepress/cache/deps/package.json +0 -3
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4504
- package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -583
- package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
- package/docs/.vitepress/cache/deps/vue.js +0 -343
- package/docs/.vitepress/cache/deps/vue.js.map +0 -7
- package/docs/.vitepress/config.mts +0 -26
- package/docs/api-examples.md +0 -49
- package/docs/index.md +0 -59
- package/docs/markdown-examples.md +0 -85
- package/docs-data/api-docs.json +0 -4143
- package/examples/quicbase-jsCDN.html +0 -36
- package/examples/react.js +0 -48
- package/examples/vanillajs.html +0 -47
- package/index.md +0 -25
- package/open-api/fix-spec-main.ts +0 -133
- package/open-api/generate-unified-interface.ts +0 -104
- package/open-api/generateDocsJson.ts +0 -24
- package/open-api/output/quickbase-fixed.json +0 -11191
- package/open-api/post-process-generated.ts +0 -226
- package/open-api/regenerate-client.ts +0 -117
- package/open-api/schema/enhance-general.ts +0 -111
- package/open-api/schema/fix-arrays.ts +0 -68
- package/open-api/schema/tags/apps.ts +0 -90
- package/open-api/schema/tags/fields.ts +0 -471
- package/open-api/schema/tags/groups.ts +0 -51
- package/open-api/schema/tags/index.ts +0 -66
- package/open-api/schema/tags/records.ts +0 -115
- package/open-api/schema/tags/tables.ts +0 -211
- package/open-api/schema/tags/users.ts +0 -47
- package/open-api/types/spec.ts +0 -42
- package/open-api/utils/common.ts +0 -29
- package/open-api/utils/generateJsDoc.ts +0 -74
- package/open-api/utils/infer-schema.ts +0 -40
- package/open-api/utils/naming.ts +0 -10
- package/open-api/utils/sharedUtils.ts +0 -352
- package/playwright.config.ts +0 -37
- package/rollup.config.js +0 -114
- package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
- package/specs/split/apps.json +0 -1315
- package/specs/split/auth.json +0 -191
- package/specs/split/fields.json +0 -3869
- package/specs/split/records.json +0 -754
- package/specs/split/reports.json +0 -619
- package/specs/split/tables.json +0 -1605
- package/src/RateLimitError.ts +0 -12
- package/src/ThrottleBucket.ts +0 -77
- package/src/authorizationStrategy.ts +0 -310
- package/src/generated-unified/QuickbaseClient.ts +0 -1135
- package/src/generated-unified/missing-types-report.json +0 -3
- package/src/index.ts +0 -1
- package/src/invokeMethod.ts +0 -212
- package/src/quickbaseClient.ts +0 -199
- package/src/rateLimiter.ts +0 -30
- package/src/tokenCache.ts +0 -39
- package/src/utils.ts +0 -50
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
- package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
- package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
- package/tests/playwright/qb/auth/getAppWithTempTokenConcurrency.test.ts +0 -208
- package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
- package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
- package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
- package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
- package/tests/setup.ts +0 -53
- package/tests/vitest/qb/ThrottleBucket.test.ts +0 -77
- package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
- package/tests/vitest/qb/apps/createApp.test.ts +0 -64
- package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
- package/tests/vitest/qb/apps/getApp.test.ts +0 -44
- package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
- package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
- package/tests/vitest/qb/auth/mockQuickbaseServer.ts +0 -60
- package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -73
- package/tests/vitest/qb/auth/ssoTokenConcurrency.test.ts +0 -68
- package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +0 -65
- package/tests/vitest/qb/auth/userTokenConcurrency.test.ts +0 -63
- package/tests/vitest/qb/fields/createField.test.ts +0 -77
- package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
- package/tests/vitest/qb/fields/getField.test.ts +0 -85
- package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -82
- package/tests/vitest/qb/fields/getFields.test.ts +0 -232
- package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
- package/tests/vitest/qb/fields/updateField.test.ts +0 -93
- package/tests/vitest/qb/formulas/runFormula.test.ts +0 -96
- package/tests/vitest/qb/index.ts +0 -29
- package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
- package/tests/vitest/qb/records/runQuery.test.ts +0 -146
- package/tests/vitest/qb/records/upsert.test.ts +0 -102
- package/tests/vitest/qb/tables/createRelationship.test.ts +0 -102
- package/tests/vitest/qb/tables/createTable.test.ts +0 -55
- package/tests/vitest/qb/tables/deleteRelationship.test.ts +0 -143
- package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
- package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
- package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
- package/tests/vitest/qb/tables/getTable.test.ts +0 -26
- package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -250
- package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
- package/tests/vitest/unit/ThrottleBucket.test.ts +0 -101
- package/tests/vitest/unit/apps/copyApp.test.ts +0 -581
- package/tests/vitest/unit/apps/createApp.test.ts +0 -186
- package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
- package/tests/vitest/unit/apps/getApp.test.ts +0 -128
- package/tests/vitest/unit/apps/getAppConcurrency.test.ts +0 -151
- package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
- package/tests/vitest/unit/apps/updateApp.test.ts +0 -412
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -81
- package/tests/vitest/unit/auth/getTempToken.test.ts +0 -119
- package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -95
- package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +0 -206
- package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -69
- package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +0 -325
- package/tests/vitest/unit/auth/userTokenConcurrency.test.ts +0 -62
- package/tests/vitest/unit/fields/createField.test.ts +0 -451
- package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
- package/tests/vitest/unit/fields/getField.test.ts +0 -189
- package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -180
- package/tests/vitest/unit/fields/getFields.test.ts +0 -122
- package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
- package/tests/vitest/unit/fields/updateField.test.ts +0 -285
- package/tests/vitest/unit/formulas/runFormula.test.ts +0 -205
- package/tests/vitest/unit/index.ts +0 -34
- package/tests/vitest/unit/quickbaseClientHttpMethods.test.ts +0 -139
- package/tests/vitest/unit/rateLimit.test.ts +0 -191
- package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
- package/tests/vitest/unit/records/runQuery.test.ts +0 -102
- package/tests/vitest/unit/records/upsert.test.ts +0 -234
- package/tests/vitest/unit/tables/createRelationship.test.ts +0 -212
- package/tests/vitest/unit/tables/createTable.test.ts +0 -70
- package/tests/vitest/unit/tables/deleteRelationship.test.ts +0 -97
- package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
- package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
- package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
- package/tests/vitest/unit/tables/getTable.test.ts +0 -233
- package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -307
- package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
- package/tests/vitest/unit/tokenLifespan.test.ts +0 -204
- package/tests/vitest/unit/umd.test.ts +0 -8
- package/tools/log-gen.ts +0 -251
- package/tools/log-gen.yaml +0 -4829
- package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
- package/tsconfig.build.json +0 -17
- package/tsconfig.json +0 -32
- package/versionrc.json +0 -9
- 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,69 +0,0 @@
|
|
|
1
|
-
// tests/vitest/unit/auth/retryUserToken401.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 - User Token Retry on 401", () => {
|
|
12
|
-
it("retries with the same user token on 401 and succeeds", async () => {
|
|
13
|
-
const userToken = "b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3";
|
|
14
|
-
mockFetch
|
|
15
|
-
.mockResolvedValueOnce(
|
|
16
|
-
new Response(JSON.stringify({ message: "Unauthorized" }), {
|
|
17
|
-
status: 401,
|
|
18
|
-
})
|
|
19
|
-
)
|
|
20
|
-
.mockResolvedValueOnce(
|
|
21
|
-
new Response(JSON.stringify([{ id: 1, label: "Field1" }]), {
|
|
22
|
-
status: 200,
|
|
23
|
-
})
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
const consoleSpy = vi.spyOn(console, "log");
|
|
27
|
-
const client = createClient(mockFetch, {
|
|
28
|
-
realm: QB_REALM,
|
|
29
|
-
userToken,
|
|
30
|
-
useTempTokens: false,
|
|
31
|
-
debug: true,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const result = await client.getFields({ tableId: QB_TABLE_ID_1 });
|
|
35
|
-
|
|
36
|
-
expect(result).toEqual([{ id: 1, label: "Field1" }]);
|
|
37
|
-
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
38
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
39
|
-
1,
|
|
40
|
-
`https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
|
|
41
|
-
expect.objectContaining({
|
|
42
|
-
method: "GET",
|
|
43
|
-
headers: expect.objectContaining({
|
|
44
|
-
Authorization: `QB-USER-TOKEN ${userToken}`,
|
|
45
|
-
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
46
|
-
"Content-Type": "application/json",
|
|
47
|
-
}),
|
|
48
|
-
})
|
|
49
|
-
);
|
|
50
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
51
|
-
2,
|
|
52
|
-
`https://api.quickbase.com/v1/fields?tableId=${QB_TABLE_ID_1}`,
|
|
53
|
-
expect.objectContaining({
|
|
54
|
-
method: "GET",
|
|
55
|
-
headers: expect.objectContaining({
|
|
56
|
-
Authorization: `QB-USER-TOKEN ${userToken}`,
|
|
57
|
-
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
58
|
-
"Content-Type": "application/json",
|
|
59
|
-
}),
|
|
60
|
-
})
|
|
61
|
-
);
|
|
62
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
63
|
-
`Retrying getFields with existing user token: b9f3pk_q4j...`
|
|
64
|
-
);
|
|
65
|
-
expect(consoleSpy).toHaveBeenCalledWith(
|
|
66
|
-
"[getFields] Retrying with token: b9f3pk_q4j..."
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
});
|