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,581 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
createClient,
|
|
4
|
-
mockFetch,
|
|
5
|
-
QB_APP_ID,
|
|
6
|
-
QB_REALM,
|
|
7
|
-
QB_USER_TOKEN,
|
|
8
|
-
} from "@tests/setup.ts";
|
|
9
|
-
import { CopyAppRequest, CopyApp200Response } from "@/generated/models";
|
|
10
|
-
|
|
11
|
-
describe("QuickbaseClient Unit - copyApp", () => {
|
|
12
|
-
let client: ReturnType<typeof createClient>;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
mockFetch.mockClear();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("initializes without errors", () => {
|
|
19
|
-
client = createClient(mockFetch, { debug: true });
|
|
20
|
-
expect(client).toBeDefined();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("has copyApp method", () => {
|
|
24
|
-
client = createClient(mockFetch, { debug: true });
|
|
25
|
-
expect(typeof client.copyApp).toBe("function");
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("calls copyApp successfully with user token and dates as Date objects", async () => {
|
|
29
|
-
client = createClient(mockFetch, { debug: true }); // convertDates defaults to true
|
|
30
|
-
|
|
31
|
-
const request: CopyAppRequest = {
|
|
32
|
-
name: "Copied App",
|
|
33
|
-
description: "A copy of the original app",
|
|
34
|
-
properties: {
|
|
35
|
-
keepData: false,
|
|
36
|
-
excludeFiles: true,
|
|
37
|
-
usersAndRoles: false,
|
|
38
|
-
assignUserToken: true,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const mockResponse: CopyApp200Response = {
|
|
43
|
-
id: "bpqe82s1",
|
|
44
|
-
name: "Copied App",
|
|
45
|
-
description: "A copy of the original app",
|
|
46
|
-
created: new Date("2025-03-11T10:00:00Z"),
|
|
47
|
-
updated: new Date("2025-03-11T10:00:00Z"),
|
|
48
|
-
dateFormat: "MM-DD-YYYY",
|
|
49
|
-
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
50
|
-
hasEveryoneOnTheInternet: false,
|
|
51
|
-
ancestorId: "buwai2zpe",
|
|
52
|
-
dataClassification: "None",
|
|
53
|
-
variables: [],
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
mockFetch.mockResolvedValueOnce({
|
|
57
|
-
ok: true,
|
|
58
|
-
status: 200,
|
|
59
|
-
json: () => Promise.resolve(mockResponse),
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const result = await client.copyApp({ appId: QB_APP_ID, body: request });
|
|
63
|
-
|
|
64
|
-
expect(result).toEqual(mockResponse);
|
|
65
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
66
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
67
|
-
expect.objectContaining({
|
|
68
|
-
method: "POST",
|
|
69
|
-
headers: expect.objectContaining({
|
|
70
|
-
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
71
|
-
Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
|
|
72
|
-
"Content-Type": "application/json",
|
|
73
|
-
}),
|
|
74
|
-
credentials: "omit",
|
|
75
|
-
body: JSON.stringify(request),
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("calls copyApp successfully with user token and dates as strings", async () => {
|
|
81
|
-
client = createClient(mockFetch, { debug: true, convertDates: false });
|
|
82
|
-
|
|
83
|
-
const request: CopyAppRequest = {
|
|
84
|
-
name: "Copied App",
|
|
85
|
-
description: "A copy of the original app",
|
|
86
|
-
properties: {
|
|
87
|
-
keepData: false,
|
|
88
|
-
excludeFiles: true,
|
|
89
|
-
usersAndRoles: false,
|
|
90
|
-
assignUserToken: true,
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const mockResponse = {
|
|
95
|
-
id: "bpqe82s1",
|
|
96
|
-
name: "Copied App",
|
|
97
|
-
description: "A copy of the original app",
|
|
98
|
-
created: "2025-03-11T10:00:00Z",
|
|
99
|
-
updated: "2025-03-11T10:00:00Z",
|
|
100
|
-
dateFormat: "MM-DD-YYYY",
|
|
101
|
-
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
102
|
-
hasEveryoneOnTheInternet: false,
|
|
103
|
-
ancestorId: "buwai2zpe",
|
|
104
|
-
dataClassification: "None",
|
|
105
|
-
variables: [],
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
mockFetch.mockResolvedValueOnce({
|
|
109
|
-
ok: true,
|
|
110
|
-
status: 200,
|
|
111
|
-
json: () => Promise.resolve(mockResponse),
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const result = await client.copyApp({ appId: QB_APP_ID, body: request });
|
|
115
|
-
|
|
116
|
-
expect(result).toEqual(mockResponse);
|
|
117
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
118
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
119
|
-
expect.objectContaining({
|
|
120
|
-
method: "POST",
|
|
121
|
-
headers: expect.objectContaining({
|
|
122
|
-
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
123
|
-
Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
|
|
124
|
-
"Content-Type": "application/json",
|
|
125
|
-
}),
|
|
126
|
-
credentials: "omit",
|
|
127
|
-
body: JSON.stringify(request),
|
|
128
|
-
})
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("calls copyApp successfully with temp token and dates as Date objects", async () => {
|
|
133
|
-
client = createClient(mockFetch, { useTempTokens: true, debug: true });
|
|
134
|
-
|
|
135
|
-
const request: CopyAppRequest = {
|
|
136
|
-
name: "Copied App with Temp Token",
|
|
137
|
-
description: "A copy using temp token",
|
|
138
|
-
properties: {
|
|
139
|
-
keepData: true,
|
|
140
|
-
excludeFiles: false,
|
|
141
|
-
usersAndRoles: true,
|
|
142
|
-
assignUserToken: false,
|
|
143
|
-
},
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const mockResponse: CopyApp200Response = {
|
|
147
|
-
id: "bpqe82s2",
|
|
148
|
-
name: "Copied App with Temp Token",
|
|
149
|
-
description: "A copy using temp token",
|
|
150
|
-
created: new Date("2025-03-11T11:00:00Z"),
|
|
151
|
-
updated: new Date("2025-03-11T11:00:00Z"),
|
|
152
|
-
dateFormat: "MM-DD-YYYY",
|
|
153
|
-
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
154
|
-
hasEveryoneOnTheInternet: true,
|
|
155
|
-
ancestorId: QB_APP_ID,
|
|
156
|
-
dataClassification: "None",
|
|
157
|
-
variables: [],
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
mockFetch
|
|
161
|
-
.mockResolvedValueOnce({
|
|
162
|
-
ok: true,
|
|
163
|
-
status: 200,
|
|
164
|
-
json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
|
|
165
|
-
})
|
|
166
|
-
.mockResolvedValueOnce({
|
|
167
|
-
ok: true,
|
|
168
|
-
status: 200,
|
|
169
|
-
json: () => Promise.resolve(mockResponse),
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const result = await client.copyApp({ appId: QB_APP_ID, body: request });
|
|
173
|
-
|
|
174
|
-
expect(result).toEqual(mockResponse);
|
|
175
|
-
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
176
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
177
|
-
1,
|
|
178
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
179
|
-
expect.any(Object)
|
|
180
|
-
);
|
|
181
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
182
|
-
2,
|
|
183
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
184
|
-
expect.objectContaining({
|
|
185
|
-
headers: expect.objectContaining({
|
|
186
|
-
Authorization: "QB-TEMP-TOKEN temp_token",
|
|
187
|
-
}),
|
|
188
|
-
})
|
|
189
|
-
);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("calls copyApp successfully with temp token and dates as strings", async () => {
|
|
193
|
-
client = createClient(mockFetch, {
|
|
194
|
-
useTempTokens: true,
|
|
195
|
-
debug: true,
|
|
196
|
-
convertDates: false,
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
const request: CopyAppRequest = {
|
|
200
|
-
name: "Copied App with Temp Token",
|
|
201
|
-
description: "A copy using temp token",
|
|
202
|
-
properties: {
|
|
203
|
-
keepData: true,
|
|
204
|
-
excludeFiles: false,
|
|
205
|
-
usersAndRoles: true,
|
|
206
|
-
assignUserToken: false,
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const mockResponse = {
|
|
211
|
-
id: "bpqe82s2",
|
|
212
|
-
name: "Copied App with Temp Token",
|
|
213
|
-
description: "A copy using temp token",
|
|
214
|
-
created: "2025-03-11T11:00:00Z",
|
|
215
|
-
updated: "2025-03-11T11:00:00Z",
|
|
216
|
-
dateFormat: "MM-DD-YYYY",
|
|
217
|
-
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
218
|
-
hasEveryoneOnTheInternet: true,
|
|
219
|
-
ancestorId: QB_APP_ID,
|
|
220
|
-
dataClassification: "None",
|
|
221
|
-
variables: [],
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
mockFetch
|
|
225
|
-
.mockResolvedValueOnce({
|
|
226
|
-
ok: true,
|
|
227
|
-
status: 200,
|
|
228
|
-
json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
|
|
229
|
-
})
|
|
230
|
-
.mockResolvedValueOnce({
|
|
231
|
-
ok: true,
|
|
232
|
-
status: 200,
|
|
233
|
-
json: () => Promise.resolve(mockResponse),
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
const result = await client.copyApp({ appId: QB_APP_ID, body: request });
|
|
237
|
-
|
|
238
|
-
expect(result).toEqual(mockResponse);
|
|
239
|
-
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
240
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
241
|
-
1,
|
|
242
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
243
|
-
expect.any(Object)
|
|
244
|
-
);
|
|
245
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
246
|
-
2,
|
|
247
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
248
|
-
expect.objectContaining({
|
|
249
|
-
headers: expect.objectContaining({
|
|
250
|
-
Authorization: "QB-TEMP-TOKEN temp_token",
|
|
251
|
-
}),
|
|
252
|
-
})
|
|
253
|
-
);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it("retries successfully after 401 with temp token and dates as Date objects", async () => {
|
|
257
|
-
client = createClient(mockFetch, { useTempTokens: true, debug: true });
|
|
258
|
-
|
|
259
|
-
const request: CopyAppRequest = {
|
|
260
|
-
name: "Retry Copied App",
|
|
261
|
-
description: "Retry after 401",
|
|
262
|
-
properties: {
|
|
263
|
-
keepData: false,
|
|
264
|
-
excludeFiles: true,
|
|
265
|
-
usersAndRoles: false,
|
|
266
|
-
assignUserToken: true,
|
|
267
|
-
},
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
const mockResponse: CopyApp200Response = {
|
|
271
|
-
id: "bpqe82s3",
|
|
272
|
-
name: "Retry Copied App",
|
|
273
|
-
description: "Retry after 401",
|
|
274
|
-
created: new Date("2025-03-11T12:00:00Z"),
|
|
275
|
-
updated: new Date("2025-03-11T12:00:00Z"),
|
|
276
|
-
dateFormat: "MM-DD-YYYY",
|
|
277
|
-
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
278
|
-
hasEveryoneOnTheInternet: false,
|
|
279
|
-
ancestorId: QB_APP_ID,
|
|
280
|
-
dataClassification: "None",
|
|
281
|
-
variables: [],
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
mockFetch
|
|
285
|
-
.mockResolvedValueOnce({
|
|
286
|
-
ok: true,
|
|
287
|
-
status: 200,
|
|
288
|
-
json: () =>
|
|
289
|
-
Promise.resolve({ temporaryAuthorization: "initial_token" }),
|
|
290
|
-
})
|
|
291
|
-
.mockResolvedValueOnce({
|
|
292
|
-
ok: false,
|
|
293
|
-
status: 401,
|
|
294
|
-
json: () => Promise.resolve({ message: "Unauthorized" }),
|
|
295
|
-
})
|
|
296
|
-
.mockResolvedValueOnce({
|
|
297
|
-
ok: true,
|
|
298
|
-
status: 200,
|
|
299
|
-
json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
|
|
300
|
-
})
|
|
301
|
-
.mockResolvedValueOnce({
|
|
302
|
-
ok: true,
|
|
303
|
-
status: 200,
|
|
304
|
-
json: () => Promise.resolve(mockResponse),
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
const result = await client.copyApp({ appId: QB_APP_ID, body: request });
|
|
308
|
-
|
|
309
|
-
expect(result).toEqual(mockResponse);
|
|
310
|
-
expect(mockFetch).toHaveBeenCalledTimes(4);
|
|
311
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
312
|
-
1,
|
|
313
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
314
|
-
expect.any(Object)
|
|
315
|
-
);
|
|
316
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
317
|
-
2,
|
|
318
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
319
|
-
expect.objectContaining({
|
|
320
|
-
headers: expect.objectContaining({
|
|
321
|
-
Authorization: "QB-TEMP-TOKEN initial_token",
|
|
322
|
-
}),
|
|
323
|
-
})
|
|
324
|
-
);
|
|
325
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
326
|
-
3,
|
|
327
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
328
|
-
expect.any(Object)
|
|
329
|
-
);
|
|
330
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
331
|
-
4,
|
|
332
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
333
|
-
expect.objectContaining({
|
|
334
|
-
headers: expect.objectContaining({
|
|
335
|
-
Authorization: "QB-TEMP-TOKEN new_token",
|
|
336
|
-
}),
|
|
337
|
-
})
|
|
338
|
-
);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it("retries successfully after 401 with temp token and dates as strings", async () => {
|
|
342
|
-
client = createClient(mockFetch, {
|
|
343
|
-
useTempTokens: true,
|
|
344
|
-
debug: true,
|
|
345
|
-
convertDates: false,
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
const request: CopyAppRequest = {
|
|
349
|
-
name: "Retry Copied App",
|
|
350
|
-
description: "Retry after 401",
|
|
351
|
-
properties: {
|
|
352
|
-
keepData: false,
|
|
353
|
-
excludeFiles: true,
|
|
354
|
-
usersAndRoles: false,
|
|
355
|
-
assignUserToken: true,
|
|
356
|
-
},
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
const mockResponse = {
|
|
360
|
-
id: "bpqe82s3",
|
|
361
|
-
name: "Retry Copied App",
|
|
362
|
-
description: "Retry after 401",
|
|
363
|
-
created: "2025-03-11T12:00:00Z",
|
|
364
|
-
updated: "2025-03-11T12:00:00Z",
|
|
365
|
-
dateFormat: "MM-DD-YYYY",
|
|
366
|
-
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
367
|
-
hasEveryoneOnTheInternet: false,
|
|
368
|
-
ancestorId: QB_APP_ID,
|
|
369
|
-
dataClassification: "None",
|
|
370
|
-
variables: [],
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
mockFetch
|
|
374
|
-
.mockResolvedValueOnce({
|
|
375
|
-
ok: true,
|
|
376
|
-
status: 200,
|
|
377
|
-
json: () =>
|
|
378
|
-
Promise.resolve({ temporaryAuthorization: "initial_token" }),
|
|
379
|
-
})
|
|
380
|
-
.mockResolvedValueOnce({
|
|
381
|
-
ok: false,
|
|
382
|
-
status: 401,
|
|
383
|
-
json: () => Promise.resolve({ message: "Unauthorized" }),
|
|
384
|
-
})
|
|
385
|
-
.mockResolvedValueOnce({
|
|
386
|
-
ok: true,
|
|
387
|
-
status: 200,
|
|
388
|
-
json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
|
|
389
|
-
})
|
|
390
|
-
.mockResolvedValueOnce({
|
|
391
|
-
ok: true,
|
|
392
|
-
status: 200,
|
|
393
|
-
json: () => Promise.resolve(mockResponse),
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
const result = await client.copyApp({ appId: QB_APP_ID, body: request });
|
|
397
|
-
|
|
398
|
-
expect(result).toEqual(mockResponse);
|
|
399
|
-
expect(mockFetch).toHaveBeenCalledTimes(4);
|
|
400
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
401
|
-
1,
|
|
402
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
403
|
-
expect.any(Object)
|
|
404
|
-
);
|
|
405
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
406
|
-
2,
|
|
407
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
408
|
-
expect.objectContaining({
|
|
409
|
-
headers: expect.objectContaining({
|
|
410
|
-
Authorization: "QB-TEMP-TOKEN initial_token",
|
|
411
|
-
}),
|
|
412
|
-
})
|
|
413
|
-
);
|
|
414
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
415
|
-
3,
|
|
416
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
417
|
-
expect.any(Object)
|
|
418
|
-
);
|
|
419
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
420
|
-
4,
|
|
421
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
422
|
-
expect.objectContaining({
|
|
423
|
-
headers: expect.objectContaining({
|
|
424
|
-
Authorization: "QB-TEMP-TOKEN new_token",
|
|
425
|
-
}),
|
|
426
|
-
})
|
|
427
|
-
);
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
it("handles 400 error for invalid request", async () => {
|
|
431
|
-
client = createClient(mockFetch, { debug: true });
|
|
432
|
-
|
|
433
|
-
const request: CopyAppRequest = {
|
|
434
|
-
name: "",
|
|
435
|
-
description: "Invalid request",
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
mockFetch.mockResolvedValueOnce({
|
|
439
|
-
ok: false,
|
|
440
|
-
status: 400,
|
|
441
|
-
json: () => Promise.resolve({ message: "Name is required" }),
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
await expect(
|
|
445
|
-
client.copyApp({ appId: QB_APP_ID, body: request })
|
|
446
|
-
).rejects.toThrow("API Error: Name is required (Status: 400)");
|
|
447
|
-
|
|
448
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
449
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
450
|
-
expect.objectContaining({
|
|
451
|
-
method: "POST",
|
|
452
|
-
headers: expect.objectContaining({
|
|
453
|
-
"QB-Realm-Hostname": `${QB_REALM}.quickbase.com`,
|
|
454
|
-
Authorization: `QB-USER-TOKEN ${QB_USER_TOKEN}`,
|
|
455
|
-
"Content-Type": "application/json",
|
|
456
|
-
}),
|
|
457
|
-
credentials: "omit",
|
|
458
|
-
body: JSON.stringify(request),
|
|
459
|
-
})
|
|
460
|
-
);
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
it("exhausts default maxRetries (3) with temp token and throws error", async () => {
|
|
464
|
-
client = createClient(mockFetch, { useTempTokens: true, debug: true }); // No explicit maxRetries, uses default 3
|
|
465
|
-
|
|
466
|
-
const request: CopyAppRequest = {
|
|
467
|
-
name: "Fail App",
|
|
468
|
-
description: "Test retry limit",
|
|
469
|
-
properties: {
|
|
470
|
-
keepData: false,
|
|
471
|
-
excludeFiles: true,
|
|
472
|
-
usersAndRoles: false,
|
|
473
|
-
assignUserToken: true,
|
|
474
|
-
},
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
mockFetch
|
|
478
|
-
.mockResolvedValueOnce({
|
|
479
|
-
ok: true,
|
|
480
|
-
status: 200,
|
|
481
|
-
json: () => Promise.resolve({ temporaryAuthorization: "token_1" }),
|
|
482
|
-
})
|
|
483
|
-
.mockResolvedValueOnce({
|
|
484
|
-
ok: false,
|
|
485
|
-
status: 401,
|
|
486
|
-
json: () => Promise.resolve({ message: "Unauthorized 1" }),
|
|
487
|
-
})
|
|
488
|
-
.mockResolvedValueOnce({
|
|
489
|
-
ok: true,
|
|
490
|
-
status: 200,
|
|
491
|
-
json: () => Promise.resolve({ temporaryAuthorization: "token_2" }),
|
|
492
|
-
})
|
|
493
|
-
.mockResolvedValueOnce({
|
|
494
|
-
ok: false,
|
|
495
|
-
status: 401,
|
|
496
|
-
json: () => Promise.resolve({ message: "Unauthorized 2" }),
|
|
497
|
-
})
|
|
498
|
-
.mockResolvedValueOnce({
|
|
499
|
-
ok: true,
|
|
500
|
-
status: 200,
|
|
501
|
-
json: () => Promise.resolve({ temporaryAuthorization: "token_3" }),
|
|
502
|
-
})
|
|
503
|
-
.mockResolvedValueOnce({
|
|
504
|
-
ok: false,
|
|
505
|
-
status: 401,
|
|
506
|
-
json: () => Promise.resolve({ message: "Unauthorized 3" }),
|
|
507
|
-
})
|
|
508
|
-
.mockResolvedValueOnce({
|
|
509
|
-
ok: true,
|
|
510
|
-
status: 200,
|
|
511
|
-
json: () => Promise.resolve({ temporaryAuthorization: "token_4" }),
|
|
512
|
-
})
|
|
513
|
-
.mockResolvedValueOnce({
|
|
514
|
-
ok: false,
|
|
515
|
-
status: 401,
|
|
516
|
-
json: () => Promise.resolve({ message: "Unauthorized 4" }),
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
await expect(
|
|
520
|
-
client.copyApp({ appId: QB_APP_ID, body: request })
|
|
521
|
-
).rejects.toThrow("API Error: Unauthorized 4 (Status: 401)");
|
|
522
|
-
|
|
523
|
-
expect(mockFetch).toHaveBeenCalledTimes(8); // 4 token fetches + 4 API attempts
|
|
524
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
525
|
-
1,
|
|
526
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
527
|
-
expect.any(Object)
|
|
528
|
-
);
|
|
529
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
530
|
-
2,
|
|
531
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
532
|
-
expect.objectContaining({
|
|
533
|
-
headers: expect.objectContaining({
|
|
534
|
-
Authorization: "QB-TEMP-TOKEN token_1",
|
|
535
|
-
}),
|
|
536
|
-
})
|
|
537
|
-
);
|
|
538
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
539
|
-
3,
|
|
540
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
541
|
-
expect.any(Object)
|
|
542
|
-
);
|
|
543
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
544
|
-
4,
|
|
545
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
546
|
-
expect.objectContaining({
|
|
547
|
-
headers: expect.objectContaining({
|
|
548
|
-
Authorization: "QB-TEMP-TOKEN token_2",
|
|
549
|
-
}),
|
|
550
|
-
})
|
|
551
|
-
);
|
|
552
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
553
|
-
5,
|
|
554
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
555
|
-
expect.any(Object)
|
|
556
|
-
);
|
|
557
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
558
|
-
6,
|
|
559
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
560
|
-
expect.objectContaining({
|
|
561
|
-
headers: expect.objectContaining({
|
|
562
|
-
Authorization: "QB-TEMP-TOKEN token_3",
|
|
563
|
-
}),
|
|
564
|
-
})
|
|
565
|
-
);
|
|
566
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
567
|
-
7,
|
|
568
|
-
`https://api.quickbase.com/v1/auth/temporary/${QB_APP_ID}`,
|
|
569
|
-
expect.any(Object)
|
|
570
|
-
);
|
|
571
|
-
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
572
|
-
8,
|
|
573
|
-
`https://api.quickbase.com/v1/apps/${QB_APP_ID}/copy`,
|
|
574
|
-
expect.objectContaining({
|
|
575
|
-
headers: expect.objectContaining({
|
|
576
|
-
Authorization: "QB-TEMP-TOKEN token_4",
|
|
577
|
-
}),
|
|
578
|
-
})
|
|
579
|
-
);
|
|
580
|
-
});
|
|
581
|
-
});
|