quickbase-js 1.0.1-beta.0 → 1.1.0-beta.0
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/CHANGELOG.md +24 -0
- package/dist/{quickbaseClient.d.ts → quickbase.d.ts} +344 -339
- package/dist/{quickbaseClient.js → quickbase.js} +350 -266
- package/dist/quickbase.js.map +1 -0
- package/log-gen.yaml +3565 -0
- package/package.json +11 -7
- package/rollup.config.js +2 -2
- package/src/code-generation/fix-spec-definitions.ts +417 -68
- package/src/code-generation/fix-spec-paths.ts +207 -2
- package/src/code-generation/output/quickbase-fixed.json +646 -1122
- package/src/generated-unified/QuickbaseClient.ts +9 -8
- package/src/log-gen.ts +82 -35
- package/src/quickbaseClient.ts +39 -42
- package/test-artifacts/test-results.json +173 -1145
- package/tests/playwright/qb/auth/cacheSwitching.test.ts +2 -2
- package/tests/playwright/qb/auth/fetchTempToken401.test.ts +2 -2
- package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +2 -2
- package/tests/playwright/qb/auth/getTempToken.test.ts +2 -2
- package/tests/playwright/qb/auth/tokenPrefetch.test.ts +2 -2
- package/tests/playwright/qb/auth/tokenRenewal.test.ts +2 -2
- package/tests/setup.ts +16 -8
- package/tests/vitest/qb/apps/getApp.test.ts +37 -43
- package/tests/vitest/qb/records/deleteRecords.test.ts +78 -0
- package/tests/vitest/qb/records/upsert.test.ts +72 -0
- package/tests/vitest/qb/tables/createTable.test.ts +55 -0
- package/tests/vitest/qb/tables/deleteTable.test.ts +50 -0
- package/tests/vitest/qb/tables/getAppTables.test.ts +43 -64
- package/tests/vitest/qb/tables/getTable.test.ts +26 -0
- package/tests/vitest/qb/tables/updateTable.test.ts +48 -0
- package/tests/vitest/unit/apps/getApp.test.ts +1 -1
- package/tests/vitest/unit/auth/fetchTempToken401.test.ts +4 -3
- package/tests/vitest/unit/auth/getTempToken.test.ts +8 -9
- package/tests/vitest/unit/auth/retryOn401.test.ts +1 -1
- package/tests/vitest/unit/auth/two401s.test.ts +1 -1
- package/tests/vitest/unit/fields/getFields.test.ts +1 -1
- package/tests/vitest/unit/records/deleteRecords.test.ts +118 -0
- package/tests/vitest/unit/records/upsert.test.ts +228 -0
- package/tests/vitest/unit/tables/createTable.test.ts +62 -0
- package/tests/vitest/unit/tables/deleteTable.test.ts +68 -0
- package/tests/vitest/unit/tables/getAppTables.test.ts +1 -1
- package/tests/vitest/unit/tables/getTable.test.ts +212 -0
- package/tests/vitest/unit/tables/updateTable.test.ts +74 -0
- package/tsconfig.json +3 -2
- package/vitest.config.ts +3 -2
- package/dist/quickbaseClient.js.map +0 -1
- package/logGen.yaml +0 -1820
- package/src/utils.ts +0 -5
package/log-gen.yaml
ADDED
|
@@ -0,0 +1,3565 @@
|
|
|
1
|
+
project: quickbase-js
|
|
2
|
+
date: 3/10/2025
|
|
3
|
+
root: /home/drew/Projects/quickbase-js
|
|
4
|
+
goals:
|
|
5
|
+
- A library for interacting with the QuickBase RESTful API.
|
|
6
|
+
- Use OpenAPI to generate types and methods using a proxy. Validate with tests.
|
|
7
|
+
- Provide robust and intuitive temporary token support for browser environments.
|
|
8
|
+
- User Tokens support both Node.js and browser environments.
|
|
9
|
+
- 'Use case: JS frameworks like React, Vue, and Angular hosted in QuickBase code pages.'
|
|
10
|
+
- Enable a flexible or native fetch in the browser.
|
|
11
|
+
- Enable a flexible fetch framework in Node.js.
|
|
12
|
+
- '#'
|
|
13
|
+
- No manual updating methods when the QuickBase API changes.
|
|
14
|
+
- The proxy magic dynamically maps generated methods and types.
|
|
15
|
+
- '#'
|
|
16
|
+
- TokenCache is defined per quickbaseClient call, so each instance has its own isolated TokenCache.
|
|
17
|
+
- Each quickbase client instance has an isolated and individual token cache.
|
|
18
|
+
pipelineOverview:
|
|
19
|
+
- 'fix-spec-main.ts: Input: Reads the latest QuickBase_RESTful*.json file from the specs/ folder and applies fixes to the parameters and paths.'
|
|
20
|
+
- filters out the QB-Realm-Hostname, Authorization, and User-Agent parameters.
|
|
21
|
+
- Converts parameter names to camelCase.
|
|
22
|
+
- Fixes array schemas and applies custom paths.
|
|
23
|
+
- Merges paths from fix-spec-paths.ts and definitions from fix-spec-definitions.ts.
|
|
24
|
+
- 'Output: writes quickbase-fixed.json to src/code-generation/output/.'
|
|
25
|
+
- 'Key Behavior: The merge (spec.paths = { ...spec.paths, ...paths }) preserves all origional endpoints, only overriding those defined in fix-spec-paths.ts.'
|
|
26
|
+
- '#'
|
|
27
|
+
- 'regenerate-client.ts: Uses quickbase-fixed.json to generate raw TypeScript-fetch files (src/generated/). including models and APIs.'
|
|
28
|
+
- '#'
|
|
29
|
+
- 'generate-unified-interface.ts: Uses quickbase-fixed.json to generate a unified QuickbaseClient.ts interface in src/generated-unified/.'
|
|
30
|
+
- QuickbaseClient.ts includes all endpoints from src/code-generation/output/quickbase-fixed, and types from src/generated.
|
|
31
|
+
- '#'
|
|
32
|
+
- /specs/QuickBase_RESTful_API_*.json is over 46k lines of JSON, so it's not included in the snapshot, its too large to give to an AI.
|
|
33
|
+
- which creates difficulties in understanding the structure of the API.
|
|
34
|
+
- It makes it difficult to model the src/code-generation/fix-spec-*.ts files in the snapshot.
|
|
35
|
+
- '#'
|
|
36
|
+
- vitest unit and integration tests. Integration tests use the real QuickBase API with user token auth.
|
|
37
|
+
- playwright is used to test the real QuickBase API in a browser enviornment with temporary token auth.
|
|
38
|
+
- temp tokens can only be generated in a browser enviornment and can not be fetched with a user token.
|
|
39
|
+
- '#'
|
|
40
|
+
- getTempTokenDBID() method is wrapped to enhance temporary token generation reuse interacting with a token cache.
|
|
41
|
+
- '#'
|
|
42
|
+
- 'npm run fix-spec: Generates quickbase-fixed.json from the latest QuickBase_RESTful*.json file.'
|
|
43
|
+
- 'npm run regenerate: Generates raw TypeScript-fetch files in src/generated/.'
|
|
44
|
+
- 'npm run generate-unified: Generates a unified QuickbaseClient.ts interface in src/generated-unified/.'
|
|
45
|
+
tree:
|
|
46
|
+
name: .
|
|
47
|
+
type: directory
|
|
48
|
+
children:
|
|
49
|
+
- name: .env
|
|
50
|
+
type: file
|
|
51
|
+
- name: .gitignore
|
|
52
|
+
type: file
|
|
53
|
+
- name: CHANGELOG.md
|
|
54
|
+
type: file
|
|
55
|
+
- name: LICENSE
|
|
56
|
+
type: file
|
|
57
|
+
- name: README.md
|
|
58
|
+
type: file
|
|
59
|
+
- name: build.js
|
|
60
|
+
type: file
|
|
61
|
+
- name: dist
|
|
62
|
+
type: directory
|
|
63
|
+
children:
|
|
64
|
+
- name: quickbase.d.ts
|
|
65
|
+
type: file
|
|
66
|
+
- name: quickbase.js
|
|
67
|
+
type: file
|
|
68
|
+
- name: quickbase.js.map
|
|
69
|
+
type: file
|
|
70
|
+
- name: examples
|
|
71
|
+
type: directory
|
|
72
|
+
children:
|
|
73
|
+
- name: react.js
|
|
74
|
+
type: file
|
|
75
|
+
- name: vanillajs.html
|
|
76
|
+
type: file
|
|
77
|
+
- name: log-gen.yaml
|
|
78
|
+
type: file
|
|
79
|
+
- name: openapitools.json
|
|
80
|
+
type: file
|
|
81
|
+
- name: package-lock.json
|
|
82
|
+
type: file
|
|
83
|
+
- name: package.json
|
|
84
|
+
type: file
|
|
85
|
+
- name: playwright.config.ts
|
|
86
|
+
type: file
|
|
87
|
+
- name: rollup.config.js
|
|
88
|
+
type: file
|
|
89
|
+
- name: src
|
|
90
|
+
type: directory
|
|
91
|
+
children:
|
|
92
|
+
- name: code-generation
|
|
93
|
+
type: directory
|
|
94
|
+
children:
|
|
95
|
+
- name: fix-spec-definitions.ts
|
|
96
|
+
type: file
|
|
97
|
+
- name: fix-spec-main.ts
|
|
98
|
+
type: file
|
|
99
|
+
- name: fix-spec-paths.ts
|
|
100
|
+
type: file
|
|
101
|
+
- name: generate-unified-interface.ts
|
|
102
|
+
type: file
|
|
103
|
+
- name: output
|
|
104
|
+
type: directory
|
|
105
|
+
children:
|
|
106
|
+
- name: quickbase-fixed.json
|
|
107
|
+
type: file
|
|
108
|
+
- name: regenerate-client.ts
|
|
109
|
+
type: file
|
|
110
|
+
- name: generated
|
|
111
|
+
type: directory
|
|
112
|
+
children:
|
|
113
|
+
- name: .openapi-generator
|
|
114
|
+
type: directory
|
|
115
|
+
children:
|
|
116
|
+
- name: FILES
|
|
117
|
+
type: file
|
|
118
|
+
- name: VERSION
|
|
119
|
+
type: file
|
|
120
|
+
- name: .openapi-generator-ignore
|
|
121
|
+
type: file
|
|
122
|
+
- name: apis
|
|
123
|
+
type: directory
|
|
124
|
+
children:
|
|
125
|
+
- name: AppsApi.ts
|
|
126
|
+
type: file
|
|
127
|
+
- name: AuditApi.ts
|
|
128
|
+
type: file
|
|
129
|
+
- name: AuthApi.ts
|
|
130
|
+
type: file
|
|
131
|
+
- name: DocumentTemplatesApi.ts
|
|
132
|
+
type: file
|
|
133
|
+
- name: FieldsApi.ts
|
|
134
|
+
type: file
|
|
135
|
+
- name: FilesApi.ts
|
|
136
|
+
type: file
|
|
137
|
+
- name: FormulasApi.ts
|
|
138
|
+
type: file
|
|
139
|
+
- name: PlatformAnalyticsApi.ts
|
|
140
|
+
type: file
|
|
141
|
+
- name: RecordsApi.ts
|
|
142
|
+
type: file
|
|
143
|
+
- name: ReportsApi.ts
|
|
144
|
+
type: file
|
|
145
|
+
- name: SolutionsApi.ts
|
|
146
|
+
type: file
|
|
147
|
+
- name: TablesApi.ts
|
|
148
|
+
type: file
|
|
149
|
+
- name: UserTokenApi.ts
|
|
150
|
+
type: file
|
|
151
|
+
- name: UsersApi.ts
|
|
152
|
+
type: file
|
|
153
|
+
- name: index.ts
|
|
154
|
+
type: file
|
|
155
|
+
- name: index.ts
|
|
156
|
+
type: file
|
|
157
|
+
- name: models
|
|
158
|
+
type: directory
|
|
159
|
+
children:
|
|
160
|
+
- name: AddMembersToGroup200Response.ts
|
|
161
|
+
type: file
|
|
162
|
+
- name: AddSubgroupsToGroup200Response.ts
|
|
163
|
+
type: file
|
|
164
|
+
- name: App.ts
|
|
165
|
+
type: file
|
|
166
|
+
- name: AppMemoryInfo.ts
|
|
167
|
+
type: file
|
|
168
|
+
- name: AppSecurityProperties.ts
|
|
169
|
+
type: file
|
|
170
|
+
- name: Audit200Response.ts
|
|
171
|
+
type: file
|
|
172
|
+
- name: Audit202Response.ts
|
|
173
|
+
type: file
|
|
174
|
+
- name: AuditRequest.ts
|
|
175
|
+
type: file
|
|
176
|
+
- name: CloneUserToken200Response.ts
|
|
177
|
+
type: file
|
|
178
|
+
- name: CloneUserTokenRequest.ts
|
|
179
|
+
type: file
|
|
180
|
+
- name: CopyApp200Response.ts
|
|
181
|
+
type: file
|
|
182
|
+
- name: CopyAppRequest.ts
|
|
183
|
+
type: file
|
|
184
|
+
- name: CreateApp200Response.ts
|
|
185
|
+
type: file
|
|
186
|
+
- name: CreateAppRequest.ts
|
|
187
|
+
type: file
|
|
188
|
+
- name: CreateAppRequestVariablesInner.ts
|
|
189
|
+
type: file
|
|
190
|
+
- name: CreateRelationship200Response.ts
|
|
191
|
+
type: file
|
|
192
|
+
- name: CreateRelationshipRequest.ts
|
|
193
|
+
type: file
|
|
194
|
+
- name: CreateTableRequest.ts
|
|
195
|
+
type: file
|
|
196
|
+
- name: DeactivateUserToken200Response.ts
|
|
197
|
+
type: file
|
|
198
|
+
- name: DeleteFile200Response.ts
|
|
199
|
+
type: file
|
|
200
|
+
- name: DeleteRecords200Response.ts
|
|
201
|
+
type: file
|
|
202
|
+
- name: DeleteRecordsRequest.ts
|
|
203
|
+
type: file
|
|
204
|
+
- name: DeleteRelationship200Response.ts
|
|
205
|
+
type: file
|
|
206
|
+
- name: DeleteTableResponse.ts
|
|
207
|
+
type: file
|
|
208
|
+
- name: DenyUsers200Response.ts
|
|
209
|
+
type: file
|
|
210
|
+
- name: ExchangeSsoToken200Response.ts
|
|
211
|
+
type: file
|
|
212
|
+
- name: ExchangeSsoTokenRequest.ts
|
|
213
|
+
type: file
|
|
214
|
+
- name: Field.ts
|
|
215
|
+
type: file
|
|
216
|
+
- name: FieldPermissionsInner.ts
|
|
217
|
+
type: file
|
|
218
|
+
- name: FieldProperties.ts
|
|
219
|
+
type: file
|
|
220
|
+
- name: GenerateDocument200Response.ts
|
|
221
|
+
type: file
|
|
222
|
+
- name: GetField200Response.ts
|
|
223
|
+
type: file
|
|
224
|
+
- name: GetRelationships200Response.ts
|
|
225
|
+
type: file
|
|
226
|
+
- name: GetReport200Response.ts
|
|
227
|
+
type: file
|
|
228
|
+
- name: GetTempTokenDBID200Response.ts
|
|
229
|
+
type: file
|
|
230
|
+
- name: GetUsers200Response.ts
|
|
231
|
+
type: file
|
|
232
|
+
- name: GetUsersRequest.ts
|
|
233
|
+
type: file
|
|
234
|
+
- name: PlatformAnalyticEventSummaries200Response.ts
|
|
235
|
+
type: file
|
|
236
|
+
- name: PlatformAnalyticEventSummaries200ResponseMetadata.ts
|
|
237
|
+
type: file
|
|
238
|
+
- name: PlatformAnalyticEventSummaries200ResponseResultsInner.ts
|
|
239
|
+
type: file
|
|
240
|
+
- name: PlatformAnalyticEventSummaries200ResponseResultsInnerEventTypesInner.ts
|
|
241
|
+
type: file
|
|
242
|
+
- name: PlatformAnalyticEventSummaries200ResponseResultsInnerTotals.ts
|
|
243
|
+
type: file
|
|
244
|
+
- name: PlatformAnalyticEventSummaries200ResponseTotals.ts
|
|
245
|
+
type: file
|
|
246
|
+
- name: PlatformAnalyticEventSummaries200ResponseWhereInner.ts
|
|
247
|
+
type: file
|
|
248
|
+
- name: PlatformAnalyticEventSummariesRequest.ts
|
|
249
|
+
type: file
|
|
250
|
+
- name: PlatformAnalyticEventSummariesRequestWhereInner.ts
|
|
251
|
+
type: file
|
|
252
|
+
- name: PlatformAnalyticReads200Response.ts
|
|
253
|
+
type: file
|
|
254
|
+
- name: Record.ts
|
|
255
|
+
type: file
|
|
256
|
+
- name: RemoveMembersFromGroup200Response.ts
|
|
257
|
+
type: file
|
|
258
|
+
- name: RemoveSubgroupsFromGroup200Response.ts
|
|
259
|
+
type: file
|
|
260
|
+
- name: ReportRunResponse.ts
|
|
261
|
+
type: file
|
|
262
|
+
- name: RunFormula200Response.ts
|
|
263
|
+
type: file
|
|
264
|
+
- name: RunFormulaRequest.ts
|
|
265
|
+
type: file
|
|
266
|
+
- name: Table.ts
|
|
267
|
+
type: file
|
|
268
|
+
- name: TransferUserToken200Response.ts
|
|
269
|
+
type: file
|
|
270
|
+
- name: TransferUserTokenRequest.ts
|
|
271
|
+
type: file
|
|
272
|
+
- name: UndenyUsers200Response.ts
|
|
273
|
+
type: file
|
|
274
|
+
- name: UpdateFieldRequest.ts
|
|
275
|
+
type: file
|
|
276
|
+
- name: UpdateRelationshipRequest.ts
|
|
277
|
+
type: file
|
|
278
|
+
- name: UpdateTableRequest.ts
|
|
279
|
+
type: file
|
|
280
|
+
- name: Upsert200Response.ts
|
|
281
|
+
type: file
|
|
282
|
+
- name: Upsert200ResponseMetadata.ts
|
|
283
|
+
type: file
|
|
284
|
+
- name: Upsert207Response.ts
|
|
285
|
+
type: file
|
|
286
|
+
- name: Upsert207ResponseMetadata.ts
|
|
287
|
+
type: file
|
|
288
|
+
- name: UpsertRequest.ts
|
|
289
|
+
type: file
|
|
290
|
+
- name: index.ts
|
|
291
|
+
type: file
|
|
292
|
+
- name: runtime.ts
|
|
293
|
+
type: file
|
|
294
|
+
- name: generated-old
|
|
295
|
+
type: directory
|
|
296
|
+
children:
|
|
297
|
+
- name: .openapi-generator
|
|
298
|
+
type: directory
|
|
299
|
+
children:
|
|
300
|
+
- name: FILES
|
|
301
|
+
type: file
|
|
302
|
+
- name: VERSION
|
|
303
|
+
type: file
|
|
304
|
+
- name: .openapi-generator-ignore
|
|
305
|
+
type: file
|
|
306
|
+
- name: apis
|
|
307
|
+
type: directory
|
|
308
|
+
children:
|
|
309
|
+
- name: AppsApi.ts
|
|
310
|
+
type: file
|
|
311
|
+
- name: AuditApi.ts
|
|
312
|
+
type: file
|
|
313
|
+
- name: AuthApi.ts
|
|
314
|
+
type: file
|
|
315
|
+
- name: DocumentTemplatesApi.ts
|
|
316
|
+
type: file
|
|
317
|
+
- name: FieldsApi.ts
|
|
318
|
+
type: file
|
|
319
|
+
- name: FilesApi.ts
|
|
320
|
+
type: file
|
|
321
|
+
- name: FormulasApi.ts
|
|
322
|
+
type: file
|
|
323
|
+
- name: PlatformAnalyticsApi.ts
|
|
324
|
+
type: file
|
|
325
|
+
- name: RecordsApi.ts
|
|
326
|
+
type: file
|
|
327
|
+
- name: ReportsApi.ts
|
|
328
|
+
type: file
|
|
329
|
+
- name: SolutionsApi.ts
|
|
330
|
+
type: file
|
|
331
|
+
- name: TablesApi.ts
|
|
332
|
+
type: file
|
|
333
|
+
- name: UserTokenApi.ts
|
|
334
|
+
type: file
|
|
335
|
+
- name: UsersApi.ts
|
|
336
|
+
type: file
|
|
337
|
+
- name: index.ts
|
|
338
|
+
type: file
|
|
339
|
+
- name: index.ts
|
|
340
|
+
type: file
|
|
341
|
+
- name: models
|
|
342
|
+
type: directory
|
|
343
|
+
children:
|
|
344
|
+
- name: AddMembersToGroup200Response.ts
|
|
345
|
+
type: file
|
|
346
|
+
- name: AddSubgroupsToGroup200Response.ts
|
|
347
|
+
type: file
|
|
348
|
+
- name: App.ts
|
|
349
|
+
type: file
|
|
350
|
+
- name: AppMemoryInfo.ts
|
|
351
|
+
type: file
|
|
352
|
+
- name: AppSecurityProperties.ts
|
|
353
|
+
type: file
|
|
354
|
+
- name: Audit200Response.ts
|
|
355
|
+
type: file
|
|
356
|
+
- name: Audit202Response.ts
|
|
357
|
+
type: file
|
|
358
|
+
- name: AuditRequest.ts
|
|
359
|
+
type: file
|
|
360
|
+
- name: CloneUserToken200Response.ts
|
|
361
|
+
type: file
|
|
362
|
+
- name: CloneUserTokenRequest.ts
|
|
363
|
+
type: file
|
|
364
|
+
- name: CopyApp200Response.ts
|
|
365
|
+
type: file
|
|
366
|
+
- name: CopyAppRequest.ts
|
|
367
|
+
type: file
|
|
368
|
+
- name: CreateApp200Response.ts
|
|
369
|
+
type: file
|
|
370
|
+
- name: CreateAppRequest.ts
|
|
371
|
+
type: file
|
|
372
|
+
- name: CreateField200Response.ts
|
|
373
|
+
type: file
|
|
374
|
+
- name: CreateRelationship200Response.ts
|
|
375
|
+
type: file
|
|
376
|
+
- name: CreateRelationshipRequest.ts
|
|
377
|
+
type: file
|
|
378
|
+
- name: DeactivateUserToken200Response.ts
|
|
379
|
+
type: file
|
|
380
|
+
- name: DeleteApp200Response.ts
|
|
381
|
+
type: file
|
|
382
|
+
- name: DeleteAppRequest.ts
|
|
383
|
+
type: file
|
|
384
|
+
- name: DeleteFields200Response.ts
|
|
385
|
+
type: file
|
|
386
|
+
- name: DeleteFile200Response.ts
|
|
387
|
+
type: file
|
|
388
|
+
- name: DeleteRelationship200Response.ts
|
|
389
|
+
type: file
|
|
390
|
+
- name: DenyUsers200Response.ts
|
|
391
|
+
type: file
|
|
392
|
+
- name: ExchangeSsoToken200Response.ts
|
|
393
|
+
type: file
|
|
394
|
+
- name: ExchangeSsoTokenRequest.ts
|
|
395
|
+
type: file
|
|
396
|
+
- name: Field.ts
|
|
397
|
+
type: file
|
|
398
|
+
- name: FieldPermissionsInner.ts
|
|
399
|
+
type: file
|
|
400
|
+
- name: FieldProperties.ts
|
|
401
|
+
type: file
|
|
402
|
+
- name: GenerateDocument200Response.ts
|
|
403
|
+
type: file
|
|
404
|
+
- name: GetField200Response.ts
|
|
405
|
+
type: file
|
|
406
|
+
- name: GetRelationships200Response.ts
|
|
407
|
+
type: file
|
|
408
|
+
- name: GetReport200Response.ts
|
|
409
|
+
type: file
|
|
410
|
+
- name: GetTempTokenDBID200Response.ts
|
|
411
|
+
type: file
|
|
412
|
+
- name: GetUsers200Response.ts
|
|
413
|
+
type: file
|
|
414
|
+
- name: GetUsersRequest.ts
|
|
415
|
+
type: file
|
|
416
|
+
- name: PlatformAnalyticEventSummaries200Response.ts
|
|
417
|
+
type: file
|
|
418
|
+
- name: PlatformAnalyticEventSummaries200ResponseMetadata.ts
|
|
419
|
+
type: file
|
|
420
|
+
- name: PlatformAnalyticEventSummaries200ResponseResultsInner.ts
|
|
421
|
+
type: file
|
|
422
|
+
- name: PlatformAnalyticEventSummaries200ResponseResultsInnerEventTypesInner.ts
|
|
423
|
+
type: file
|
|
424
|
+
- name: PlatformAnalyticEventSummaries200ResponseResultsInnerTotals.ts
|
|
425
|
+
type: file
|
|
426
|
+
- name: PlatformAnalyticEventSummaries200ResponseTotals.ts
|
|
427
|
+
type: file
|
|
428
|
+
- name: PlatformAnalyticEventSummaries200ResponseWhereInner.ts
|
|
429
|
+
type: file
|
|
430
|
+
- name: PlatformAnalyticEventSummariesRequest.ts
|
|
431
|
+
type: file
|
|
432
|
+
- name: PlatformAnalyticEventSummariesRequestWhereInner.ts
|
|
433
|
+
type: file
|
|
434
|
+
- name: PlatformAnalyticReads200Response.ts
|
|
435
|
+
type: file
|
|
436
|
+
- name: RemoveMembersFromGroup200Response.ts
|
|
437
|
+
type: file
|
|
438
|
+
- name: RemoveSubgroupsFromGroup200Response.ts
|
|
439
|
+
type: file
|
|
440
|
+
- name: RunFormula200Response.ts
|
|
441
|
+
type: file
|
|
442
|
+
- name: RunFormulaRequest.ts
|
|
443
|
+
type: file
|
|
444
|
+
- name: RunQuery200Response.ts
|
|
445
|
+
type: file
|
|
446
|
+
- name: RunQueryRequest.ts
|
|
447
|
+
type: file
|
|
448
|
+
- name: RunReport200Response.ts
|
|
449
|
+
type: file
|
|
450
|
+
- name: Table.ts
|
|
451
|
+
type: file
|
|
452
|
+
- name: TransferUserToken200Response.ts
|
|
453
|
+
type: file
|
|
454
|
+
- name: TransferUserTokenRequest.ts
|
|
455
|
+
type: file
|
|
456
|
+
- name: UndenyUsers200Response.ts
|
|
457
|
+
type: file
|
|
458
|
+
- name: UpdateApp200Response.ts
|
|
459
|
+
type: file
|
|
460
|
+
- name: UpdateAppRequest.ts
|
|
461
|
+
type: file
|
|
462
|
+
- name: UpdateFieldRequest.ts
|
|
463
|
+
type: file
|
|
464
|
+
- name: UpdateRelationshipRequest.ts
|
|
465
|
+
type: file
|
|
466
|
+
- name: Upsert200Response.ts
|
|
467
|
+
type: file
|
|
468
|
+
- name: index.ts
|
|
469
|
+
type: file
|
|
470
|
+
- name: runtime.ts
|
|
471
|
+
type: file
|
|
472
|
+
- name: generated-unified
|
|
473
|
+
type: directory
|
|
474
|
+
children:
|
|
475
|
+
- name: QuickbaseClient.ts
|
|
476
|
+
type: file
|
|
477
|
+
- name: index.ts
|
|
478
|
+
type: file
|
|
479
|
+
- name: log-gen.ts
|
|
480
|
+
type: file
|
|
481
|
+
- name: openapi-jars
|
|
482
|
+
type: directory
|
|
483
|
+
children:
|
|
484
|
+
- name: openapi-generator-cli-7.12.0.jar
|
|
485
|
+
type: file
|
|
486
|
+
- name: quickbaseClient.ts
|
|
487
|
+
type: file
|
|
488
|
+
- name: tokenCache.ts
|
|
489
|
+
type: file
|
|
490
|
+
- name: test-artifacts
|
|
491
|
+
type: directory
|
|
492
|
+
children:
|
|
493
|
+
- name: .last-run.json
|
|
494
|
+
type: file
|
|
495
|
+
- name: test-results.json
|
|
496
|
+
type: file
|
|
497
|
+
- name: test-results.json
|
|
498
|
+
type: file
|
|
499
|
+
- name: tests
|
|
500
|
+
type: directory
|
|
501
|
+
children:
|
|
502
|
+
- name: playwright
|
|
503
|
+
type: directory
|
|
504
|
+
children:
|
|
505
|
+
- name: qb
|
|
506
|
+
type: directory
|
|
507
|
+
children:
|
|
508
|
+
- name: auth
|
|
509
|
+
type: directory
|
|
510
|
+
children:
|
|
511
|
+
- name: cacheSwitching.test.ts
|
|
512
|
+
type: file
|
|
513
|
+
contents: |
|
|
514
|
+
// tests/playwright/qb/auth/cacheSwitching.test.ts
|
|
515
|
+
import { test, expect } from "@playwright/test";
|
|
516
|
+
import { quickbase } from "../../../../src/quickbaseClient.ts";
|
|
517
|
+
import fetch from "node-fetch";
|
|
518
|
+
import dotenv from "dotenv";
|
|
519
|
+
|
|
520
|
+
dotenv.config();
|
|
521
|
+
|
|
522
|
+
const loginToQuickbase = async (
|
|
523
|
+
page: import("@playwright/test").Page,
|
|
524
|
+
quickbaseUrl: string,
|
|
525
|
+
username: string,
|
|
526
|
+
password: string
|
|
527
|
+
): Promise<boolean> => {
|
|
528
|
+
console.log("Logging in to QuickBase");
|
|
529
|
+
let loginSuccess = false;
|
|
530
|
+
const maxLoginAttempts = 3;
|
|
531
|
+
let loginAttempt = 0;
|
|
532
|
+
|
|
533
|
+
while (!loginSuccess && loginAttempt < maxLoginAttempts) {
|
|
534
|
+
try {
|
|
535
|
+
loginAttempt++;
|
|
536
|
+
if (loginAttempt > 1) console.log(`Login attempt ${loginAttempt}`);
|
|
537
|
+
|
|
538
|
+
console.log("Navigating to login page");
|
|
539
|
+
await page.goto(quickbaseUrl, { timeout: 30000 });
|
|
540
|
+
console.log("Waiting for loginid selector");
|
|
541
|
+
await page.waitForSelector("input[name='loginid']", { timeout: 30000 });
|
|
542
|
+
await page.fill("input[name='loginid']", username);
|
|
543
|
+
await page.fill("input[name='password']", password);
|
|
544
|
+
console.log("Clicking signin");
|
|
545
|
+
await page.click("#signin");
|
|
546
|
+
console.log("Waiting for navigation");
|
|
547
|
+
await page.waitForURL(`https://*.quickbase.com/**`, {
|
|
548
|
+
waitUntil: "networkidle",
|
|
549
|
+
timeout: 30000,
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
const loginError = await page.$(".login-error");
|
|
553
|
+
if (loginError) {
|
|
554
|
+
throw new Error("Login failed. Please check your credentials.");
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
console.log("Signed In to QuickBase.");
|
|
558
|
+
loginSuccess = true;
|
|
559
|
+
} catch (error) {
|
|
560
|
+
console.error(
|
|
561
|
+
`Login attempt ${loginAttempt} failed: ${(error as Error).message}`
|
|
562
|
+
);
|
|
563
|
+
if (loginAttempt >= maxLoginAttempts) {
|
|
564
|
+
console.error("Max login attempts reached. Exiting.");
|
|
565
|
+
await page.context().browser()!.close();
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return loginSuccess;
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
test.describe("QuickbaseClient Integration - Cache Switching with Temp Tokens", () => {
|
|
575
|
+
// Removed test.use({ context: ... })
|
|
576
|
+
|
|
577
|
+
test("caches and switches tokens for different DBIDs with getApp → getFields → getApp sequence", async ({
|
|
578
|
+
page,
|
|
579
|
+
}) => {
|
|
580
|
+
console.log("Starting cacheSwitching test");
|
|
581
|
+
const realm = process.env.QB_REALM;
|
|
582
|
+
const appId = process.env.QB_APP_ID;
|
|
583
|
+
const tableId = process.env.QB_TABLE_ID;
|
|
584
|
+
const username = process.env.QB_USERNAME;
|
|
585
|
+
const password = process.env.QB_PASSWORD;
|
|
586
|
+
|
|
587
|
+
if (!realm) throw new Error("QB_REALM is not defined in .env");
|
|
588
|
+
if (!appId) throw new Error("QB_APP_ID is not defined in .env");
|
|
589
|
+
if (!tableId) throw new Error("QB_TABLE_ID is not defined in .env");
|
|
590
|
+
if (!username) throw new Error("QB_USERNAME is not defined in .env");
|
|
591
|
+
if (!password) throw new Error("QB_PASSWORD is not defined in .env");
|
|
592
|
+
|
|
593
|
+
const quickbaseUrl = `https://${realm}.quickbase.com/db/main?a=SignIn`;
|
|
594
|
+
const loginSuccess = await loginToQuickbase(
|
|
595
|
+
page,
|
|
596
|
+
quickbaseUrl,
|
|
597
|
+
username,
|
|
598
|
+
password
|
|
599
|
+
);
|
|
600
|
+
if (!loginSuccess) {
|
|
601
|
+
throw new Error("Failed to log in to QuickBase after max attempts.");
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
await page.goto(`https://${realm}.quickbase.com/db/${appId}`, {
|
|
605
|
+
waitUntil: "networkidle",
|
|
606
|
+
timeout: 30000,
|
|
607
|
+
});
|
|
608
|
+
console.log("Post-login URL after app navigation:", page.url());
|
|
609
|
+
|
|
610
|
+
const browserFetch = async (url: string, init?: RequestInit) => {
|
|
611
|
+
const response = await page.evaluate(
|
|
612
|
+
async ([fetchUrl, fetchInit]) => {
|
|
613
|
+
const res = await fetch(fetchUrl, {
|
|
614
|
+
...fetchInit,
|
|
615
|
+
credentials: "include",
|
|
616
|
+
});
|
|
617
|
+
const body = await res.text();
|
|
618
|
+
return {
|
|
619
|
+
ok: res.ok,
|
|
620
|
+
status: res.status,
|
|
621
|
+
statusText: res.statusText,
|
|
622
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
623
|
+
body,
|
|
624
|
+
};
|
|
625
|
+
},
|
|
626
|
+
[url, init] as [string, RequestInit]
|
|
627
|
+
);
|
|
628
|
+
|
|
629
|
+
console.log(`Raw response from ${url}:`, {
|
|
630
|
+
status: response.status,
|
|
631
|
+
statusText: response.statusText,
|
|
632
|
+
body: response.body,
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
const fetchResponse = new Response(response.body || null, {
|
|
636
|
+
status: response.status,
|
|
637
|
+
statusText: response.statusText,
|
|
638
|
+
headers: response.headers,
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
fetchResponse.json = async () => {
|
|
642
|
+
if (!response.body) throw new Error("Empty response body from API");
|
|
643
|
+
try {
|
|
644
|
+
return JSON.parse(response.body);
|
|
645
|
+
} catch (e) {
|
|
646
|
+
throw new SyntaxError(`Invalid JSON response: ${response.body}`);
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
return fetchResponse;
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
const client = quickbase({
|
|
654
|
+
realm,
|
|
655
|
+
useTempTokens: true,
|
|
656
|
+
debug: true,
|
|
657
|
+
fetchApi: async (url, init) => {
|
|
658
|
+
if (url.includes("/auth/temporary/")) {
|
|
659
|
+
return browserFetch(url, init);
|
|
660
|
+
}
|
|
661
|
+
console.log(`Fetching ${url} with init:`, init);
|
|
662
|
+
const response = await fetch(url, init as RequestInit);
|
|
663
|
+
const body = await response.text();
|
|
664
|
+
|
|
665
|
+
console.log(`Raw response from ${url}:`, {
|
|
666
|
+
status: response.status,
|
|
667
|
+
statusText: response.statusText,
|
|
668
|
+
body,
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
const fetchResponse = new Response(body || null, {
|
|
672
|
+
status: response.status,
|
|
673
|
+
statusText: response.statusText,
|
|
674
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
fetchResponse.json = async () => {
|
|
678
|
+
if (!body) throw new Error("Empty response body from API");
|
|
679
|
+
try {
|
|
680
|
+
return JSON.parse(body);
|
|
681
|
+
} catch (e) {
|
|
682
|
+
throw new SyntaxError(`Invalid JSON response: ${body}`);
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
return fetchResponse;
|
|
687
|
+
},
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
const appResult1 = await client.getApp({ appId });
|
|
691
|
+
console.log("First getApp response:", appResult1);
|
|
692
|
+
expect(appResult1.id).toBe(appId);
|
|
693
|
+
|
|
694
|
+
const fieldsResult = await client.getFields({ tableId });
|
|
695
|
+
console.log("getFields response:", fieldsResult);
|
|
696
|
+
expect(fieldsResult.length).toBeGreaterThan(0);
|
|
697
|
+
|
|
698
|
+
const appResult2 = await client.getApp({ appId });
|
|
699
|
+
console.log("Second getApp response:", appResult2);
|
|
700
|
+
expect(appResult2.id).toBe(appId);
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
- name: fetchTempToken401.test.ts
|
|
704
|
+
type: file
|
|
705
|
+
contents: |
|
|
706
|
+
// tests/playwright/qb/auth/tokenInvalidation.test.ts
|
|
707
|
+
import { test, expect } from "@playwright/test";
|
|
708
|
+
import { quickbase } from "../../../../src/quickbaseClient.ts";
|
|
709
|
+
import fetch from "node-fetch";
|
|
710
|
+
import dotenv from "dotenv";
|
|
711
|
+
|
|
712
|
+
dotenv.config();
|
|
713
|
+
|
|
714
|
+
const loginToQuickbase = async (
|
|
715
|
+
page: import("@playwright/test").Page,
|
|
716
|
+
quickbaseUrl: string,
|
|
717
|
+
username: string,
|
|
718
|
+
password: string
|
|
719
|
+
): Promise<boolean> => {
|
|
720
|
+
console.log("Logging in to QuickBase");
|
|
721
|
+
let loginSuccess = false;
|
|
722
|
+
const maxLoginAttempts = 3;
|
|
723
|
+
let loginAttempt = 0;
|
|
724
|
+
|
|
725
|
+
while (!loginSuccess && loginAttempt < maxLoginAttempts) {
|
|
726
|
+
try {
|
|
727
|
+
loginAttempt++;
|
|
728
|
+
if (loginAttempt > 1) console.log(`Login attempt ${loginAttempt}`);
|
|
729
|
+
|
|
730
|
+
await page.goto(quickbaseUrl, { timeout: 60000 });
|
|
731
|
+
await page.waitForSelector("input[name='loginid']", { timeout: 60000 });
|
|
732
|
+
await page.fill("input[name='loginid']", username);
|
|
733
|
+
await page.fill("input[name='password']", password);
|
|
734
|
+
await page.click("#signin");
|
|
735
|
+
await page.waitForURL(`https://*.quickbase.com/**`, {
|
|
736
|
+
waitUntil: "networkidle",
|
|
737
|
+
timeout: 60000,
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
const loginError = await page.$(".login-error");
|
|
741
|
+
if (loginError) {
|
|
742
|
+
throw new Error("Login failed. Please check your credentials.");
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
console.log("Signed In to QuickBase.");
|
|
746
|
+
loginSuccess = true;
|
|
747
|
+
} catch (error) {
|
|
748
|
+
console.error(
|
|
749
|
+
`Login attempt ${loginAttempt} failed: ${(error as Error).message}`
|
|
750
|
+
);
|
|
751
|
+
if (loginAttempt >= maxLoginAttempts) {
|
|
752
|
+
console.error("Max login attempts reached. Exiting.");
|
|
753
|
+
await page.context().browser()!.close();
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return loginSuccess;
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
test.describe("QuickbaseClient Integration - Token Invalidation with Cached Token", () => {
|
|
763
|
+
test("retries with new token when cached token is unexpectedly invalidated", async ({
|
|
764
|
+
page,
|
|
765
|
+
}) => {
|
|
766
|
+
const realm = process.env.QB_REALM;
|
|
767
|
+
const appId = process.env.QB_APP_ID;
|
|
768
|
+
const username = process.env.QB_USERNAME;
|
|
769
|
+
const password = process.env.QB_PASSWORD;
|
|
770
|
+
|
|
771
|
+
if (!realm) throw new Error("QB_REALM is not defined in .env");
|
|
772
|
+
if (!appId) throw new Error("QB_APP_ID is not defined in .env");
|
|
773
|
+
if (!username) throw new Error("QB_USERNAME is not defined in .env");
|
|
774
|
+
if (!password) throw new Error("QB_PASSWORD is not defined in .env");
|
|
775
|
+
|
|
776
|
+
// Login to QuickBase
|
|
777
|
+
const quickbaseUrl = `https://${realm}.quickbase.com/db/main?a=SignIn`;
|
|
778
|
+
const loginSuccess = await loginToQuickbase(
|
|
779
|
+
page,
|
|
780
|
+
quickbaseUrl,
|
|
781
|
+
username,
|
|
782
|
+
password
|
|
783
|
+
);
|
|
784
|
+
if (!loginSuccess) {
|
|
785
|
+
throw new Error("Failed to log in to QuickBase after max attempts.");
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// Navigate to the app page to ensure session context
|
|
789
|
+
await page.goto(`https://${realm}.quickbase.com/db/${appId}`, {
|
|
790
|
+
waitUntil: "networkidle",
|
|
791
|
+
timeout: 60000,
|
|
792
|
+
});
|
|
793
|
+
console.log("Post-login URL after app navigation:", page.url());
|
|
794
|
+
|
|
795
|
+
// Track tokens and call counts
|
|
796
|
+
let callCount = 0;
|
|
797
|
+
let getAppCallCount = 0;
|
|
798
|
+
let initialToken: string | null = null;
|
|
799
|
+
let retryToken: string | null = null;
|
|
800
|
+
|
|
801
|
+
const browserFetch = async (url: string, init?: RequestInit) => {
|
|
802
|
+
console.log(`browserFetch called for ${url}, callCount: ${callCount}`);
|
|
803
|
+
const response = await page.evaluate(
|
|
804
|
+
async ([fetchUrl, fetchInit]) => {
|
|
805
|
+
const res = await fetch(fetchUrl, {
|
|
806
|
+
...fetchInit,
|
|
807
|
+
credentials: "include",
|
|
808
|
+
});
|
|
809
|
+
const body = await res.text();
|
|
810
|
+
return {
|
|
811
|
+
ok: res.ok,
|
|
812
|
+
status: res.status,
|
|
813
|
+
statusText: res.statusText,
|
|
814
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
815
|
+
body,
|
|
816
|
+
};
|
|
817
|
+
},
|
|
818
|
+
[url, init] as [string, RequestInit]
|
|
819
|
+
);
|
|
820
|
+
|
|
821
|
+
console.log(`Raw response from ${url}:`, {
|
|
822
|
+
status: response.status,
|
|
823
|
+
statusText: response.statusText,
|
|
824
|
+
body: response.body,
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
const fetchResponse = new Response(response.body || null, {
|
|
828
|
+
status: response.status,
|
|
829
|
+
statusText: response.statusText,
|
|
830
|
+
headers: response.headers,
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// Capture token from response
|
|
834
|
+
if (url.includes("/auth/temporary/")) {
|
|
835
|
+
const json = await fetchResponse.clone().json();
|
|
836
|
+
const token = json.temporaryAuthorization;
|
|
837
|
+
if (!initialToken) {
|
|
838
|
+
initialToken = token;
|
|
839
|
+
console.log(`Captured initial token: ${initialToken}`);
|
|
840
|
+
} else if (!retryToken) {
|
|
841
|
+
retryToken = token;
|
|
842
|
+
console.log(`Captured retry token: ${retryToken}`);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
return fetchResponse;
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
const client = quickbase({
|
|
850
|
+
realm,
|
|
851
|
+
useTempTokens: true,
|
|
852
|
+
debug: true,
|
|
853
|
+
fetchApi: async (url, init) => {
|
|
854
|
+
callCount++;
|
|
855
|
+
console.log(`fetchApi called for ${url}, callCount: ${callCount}`);
|
|
856
|
+
|
|
857
|
+
if (url.includes("/auth/temporary/")) {
|
|
858
|
+
return browserFetch(url, init); // Use browser fetch for temp tokens
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
if (url.includes(`/apps/${appId}`)) {
|
|
862
|
+
getAppCallCount++;
|
|
863
|
+
console.log(`getApp call count: ${getAppCallCount}`);
|
|
864
|
+
// Simulate 401 on the first getApp call to trigger retry
|
|
865
|
+
if (getAppCallCount === 1) {
|
|
866
|
+
console.log("Simulating 401 Unauthorized for first getApp call");
|
|
867
|
+
return new Response(JSON.stringify({ message: "Unauthorized" }), {
|
|
868
|
+
status: 401,
|
|
869
|
+
statusText: "Unauthorized",
|
|
870
|
+
headers: { "Content-Type": "application/json" },
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// Use node-fetch for subsequent calls (including retries)
|
|
876
|
+
console.log(`Fetching ${url} with init:`, init);
|
|
877
|
+
const response = await fetch(url, init as RequestInit);
|
|
878
|
+
const body = await response.text();
|
|
879
|
+
|
|
880
|
+
console.log(`Raw response from ${url}:`, {
|
|
881
|
+
status: response.status,
|
|
882
|
+
statusText: response.statusText,
|
|
883
|
+
body,
|
|
884
|
+
});
|
|
885
|
+
|
|
886
|
+
return new Response(body || null, {
|
|
887
|
+
status: response.status,
|
|
888
|
+
statusText: response.statusText,
|
|
889
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
890
|
+
});
|
|
891
|
+
},
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
// Pre-fetch token to simulate cached token
|
|
895
|
+
console.log("Pre-fetching initial token...");
|
|
896
|
+
const preFetchResult = await client.getTempTokenDBID({ dbid: appId });
|
|
897
|
+
console.log("Initial token pre-fetched and cached:", preFetchResult);
|
|
898
|
+
|
|
899
|
+
// Call getApp, expecting a 401 followed by a retry with a new token
|
|
900
|
+
const appResult = await client.getApp({ appId });
|
|
901
|
+
console.log("App response after token invalidation and retry:", appResult);
|
|
902
|
+
|
|
903
|
+
// Validate the app response
|
|
904
|
+
expect(appResult).toHaveProperty("id", appId);
|
|
905
|
+
expect(appResult).toHaveProperty("name");
|
|
906
|
+
|
|
907
|
+
// Verify call counts and token behavior
|
|
908
|
+
console.log(
|
|
909
|
+
`Final callCount: ${callCount}, Final getAppCallCount: ${getAppCallCount}`
|
|
910
|
+
);
|
|
911
|
+
expect(callCount).toBe(4); // Pre-fetch, 401, token retry, getApp success
|
|
912
|
+
expect(getAppCallCount).toBe(2); // Initial 401, retry success
|
|
913
|
+
|
|
914
|
+
// Validate pre-fetch and retry tokens
|
|
915
|
+
console.log(`Initial token: ${initialToken}`);
|
|
916
|
+
console.log(`Retry token: ${retryToken}`);
|
|
917
|
+
expect(initialToken).toBeDefined();
|
|
918
|
+
expect(initialToken).toBe(preFetchResult.temporaryAuthorization); // Confirm pre-fetch token was used
|
|
919
|
+
expect(retryToken).toBeDefined();
|
|
920
|
+
expect(initialToken).not.toBe(retryToken); // Confirm retry used a new token
|
|
921
|
+
});
|
|
922
|
+
});
|
|
923
|
+
- name: getAppWithUserToken.test.ts
|
|
924
|
+
type: file
|
|
925
|
+
contents: |
|
|
926
|
+
// tests/integration/auth/getAppWithUserToken.test.ts
|
|
927
|
+
import { test, expect } from "@playwright/test";
|
|
928
|
+
import { quickbase } from "../../../../src/quickbaseClient.ts";
|
|
929
|
+
import dotenv from "dotenv";
|
|
930
|
+
|
|
931
|
+
dotenv.config();
|
|
932
|
+
|
|
933
|
+
const loginToQuickbase = async (
|
|
934
|
+
page: import("@playwright/test").Page,
|
|
935
|
+
quickbaseUrl: string,
|
|
936
|
+
username: string,
|
|
937
|
+
password: string
|
|
938
|
+
): Promise<boolean> => {
|
|
939
|
+
console.log("Logging in to QuickBase");
|
|
940
|
+
let loginSuccess = false;
|
|
941
|
+
const maxLoginAttempts = 3;
|
|
942
|
+
let loginAttempt = 0;
|
|
943
|
+
|
|
944
|
+
while (!loginSuccess && loginAttempt < maxLoginAttempts) {
|
|
945
|
+
try {
|
|
946
|
+
loginAttempt++;
|
|
947
|
+
if (loginAttempt > 1) console.log(`Login attempt ${loginAttempt}`);
|
|
948
|
+
|
|
949
|
+
await page.goto(quickbaseUrl, { timeout: 60000 });
|
|
950
|
+
await page.waitForSelector("input[name='loginid']", { timeout: 60000 });
|
|
951
|
+
await page.fill("input[name='loginid']", username);
|
|
952
|
+
await page.fill("input[name='password']", password);
|
|
953
|
+
await page.click("#signin");
|
|
954
|
+
await page.waitForURL(`https://*.quickbase.com/**`, {
|
|
955
|
+
waitUntil: "networkidle",
|
|
956
|
+
timeout: 60000,
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
const loginError = await page.$(".login-error");
|
|
960
|
+
if (loginError) {
|
|
961
|
+
throw new Error("Login failed. Please check your credentials.");
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
console.log("Signed In to QuickBase.");
|
|
965
|
+
loginSuccess = true;
|
|
966
|
+
} catch (error) {
|
|
967
|
+
console.error(
|
|
968
|
+
`Login attempt ${loginAttempt} failed: ${(error as Error).message}`
|
|
969
|
+
);
|
|
970
|
+
if (loginAttempt >= maxLoginAttempts) {
|
|
971
|
+
console.error("Max login attempts reached. Exiting.");
|
|
972
|
+
await page.context().browser()!.close();
|
|
973
|
+
return false;
|
|
974
|
+
}
|
|
975
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return loginSuccess;
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
test.describe("QuickbaseClient Integration - getApp with User Token", () => {
|
|
982
|
+
test("uses user token for getApp in browser", async ({ page }) => {
|
|
983
|
+
const realm = process.env.QB_REALM;
|
|
984
|
+
const appId = process.env.QB_APP_ID;
|
|
985
|
+
const username = process.env.QB_USERNAME;
|
|
986
|
+
const password = process.env.QB_PASSWORD;
|
|
987
|
+
const userToken = process.env.QB_USER_TOKEN;
|
|
988
|
+
|
|
989
|
+
if (!realm) throw new Error("QB_REALM is not defined in .env");
|
|
990
|
+
if (!appId) throw new Error("QB_APP_ID is not defined in .env");
|
|
991
|
+
if (!username) throw new Error("QB_USERNAME is not defined in .env");
|
|
992
|
+
if (!password) throw new Error("QB_PASSWORD is not defined in .env");
|
|
993
|
+
if (!userToken) throw new Error("QB_USER_TOKEN is not defined in .env");
|
|
994
|
+
|
|
995
|
+
// Login to Quickbase (optional, to mimic code page context)
|
|
996
|
+
const quickbaseUrl = `https://${realm}.quickbase.com/db/main?a=SignIn`;
|
|
997
|
+
const loginSuccess = await loginToQuickbase(
|
|
998
|
+
page,
|
|
999
|
+
quickbaseUrl,
|
|
1000
|
+
username,
|
|
1001
|
+
password
|
|
1002
|
+
);
|
|
1003
|
+
if (!loginSuccess) {
|
|
1004
|
+
throw new Error("Failed to log in to QuickBase after max attempts.");
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// Navigate to the app page to ensure session context (optional)
|
|
1008
|
+
await page.goto(`https://${realm}.quickbase.com/db/${appId}`, {
|
|
1009
|
+
waitUntil: "networkidle",
|
|
1010
|
+
timeout: 60000,
|
|
1011
|
+
});
|
|
1012
|
+
|
|
1013
|
+
const currentUrl = page.url();
|
|
1014
|
+
console.log("Post-login URL after app navigation:", currentUrl);
|
|
1015
|
+
|
|
1016
|
+
// Create Quickbase client with user token
|
|
1017
|
+
const client = quickbase({
|
|
1018
|
+
realm,
|
|
1019
|
+
userToken, // Use user token instead of temp tokens
|
|
1020
|
+
debug: true,
|
|
1021
|
+
fetchApi: async (url, init) => {
|
|
1022
|
+
console.log(`Fetching ${url} with init:`, init);
|
|
1023
|
+
const response = await page.evaluate(
|
|
1024
|
+
async ([fetchUrl, fetchInit]) => {
|
|
1025
|
+
const res = await fetch(fetchUrl, {
|
|
1026
|
+
...fetchInit,
|
|
1027
|
+
credentials: "omit", // No cookies needed with user token
|
|
1028
|
+
});
|
|
1029
|
+
const body = await res.text();
|
|
1030
|
+
return {
|
|
1031
|
+
ok: res.ok,
|
|
1032
|
+
status: res.status,
|
|
1033
|
+
statusText: res.statusText,
|
|
1034
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
1035
|
+
body,
|
|
1036
|
+
};
|
|
1037
|
+
},
|
|
1038
|
+
[url, init] as [string, RequestInit]
|
|
1039
|
+
);
|
|
1040
|
+
|
|
1041
|
+
console.log(`Raw response from ${url}:`, {
|
|
1042
|
+
status: response.status,
|
|
1043
|
+
statusText: response.statusText,
|
|
1044
|
+
body: response.body,
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
const fetchResponse = new Response(response.body || null, {
|
|
1048
|
+
status: response.status,
|
|
1049
|
+
statusText: response.statusText,
|
|
1050
|
+
headers: response.headers,
|
|
1051
|
+
});
|
|
1052
|
+
|
|
1053
|
+
fetchResponse.json = async () => {
|
|
1054
|
+
if (!response.body) {
|
|
1055
|
+
throw new Error("Empty response body from API");
|
|
1056
|
+
}
|
|
1057
|
+
try {
|
|
1058
|
+
return JSON.parse(response.body);
|
|
1059
|
+
} catch (e) {
|
|
1060
|
+
throw new SyntaxError(`Invalid JSON response: ${response.body}`);
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
return fetchResponse;
|
|
1065
|
+
},
|
|
1066
|
+
});
|
|
1067
|
+
|
|
1068
|
+
// Call getApp directly
|
|
1069
|
+
const appResult = await client.getApp({ appId });
|
|
1070
|
+
console.log("App response using user token:", appResult);
|
|
1071
|
+
|
|
1072
|
+
// Validate the app response
|
|
1073
|
+
expect(appResult).toHaveProperty("id", appId);
|
|
1074
|
+
expect(appResult).toHaveProperty("name");
|
|
1075
|
+
});
|
|
1076
|
+
});
|
|
1077
|
+
- name: getTempToken.test.ts
|
|
1078
|
+
type: file
|
|
1079
|
+
contents: |
|
|
1080
|
+
// tests/integration/auth/getTempToken.test.ts
|
|
1081
|
+
import { test, expect } from "@playwright/test";
|
|
1082
|
+
import { quickbase } from "../../../../src/quickbaseClient.ts";
|
|
1083
|
+
import fetch from "node-fetch";
|
|
1084
|
+
import dotenv from "dotenv";
|
|
1085
|
+
|
|
1086
|
+
dotenv.config();
|
|
1087
|
+
|
|
1088
|
+
const loginToQuickbase = async (
|
|
1089
|
+
page: import("@playwright/test").Page,
|
|
1090
|
+
quickbaseUrl: string,
|
|
1091
|
+
username: string,
|
|
1092
|
+
password: string
|
|
1093
|
+
): Promise<boolean> => {
|
|
1094
|
+
console.log("Logging in to QuickBase");
|
|
1095
|
+
let loginSuccess = false;
|
|
1096
|
+
const maxLoginAttempts = 3;
|
|
1097
|
+
let loginAttempt = 0;
|
|
1098
|
+
|
|
1099
|
+
while (!loginSuccess && loginAttempt < maxLoginAttempts) {
|
|
1100
|
+
try {
|
|
1101
|
+
loginAttempt++;
|
|
1102
|
+
if (loginAttempt > 1) console.log(`Login attempt ${loginAttempt}`);
|
|
1103
|
+
|
|
1104
|
+
await page.goto(quickbaseUrl, { timeout: 60000 });
|
|
1105
|
+
await page.waitForSelector("input[name='loginid']", { timeout: 60000 });
|
|
1106
|
+
await page.fill("input[name='loginid']", username);
|
|
1107
|
+
await page.fill("input[name='password']", password);
|
|
1108
|
+
await page.click("#signin");
|
|
1109
|
+
await page.waitForURL(`https://*.quickbase.com/**`, {
|
|
1110
|
+
waitUntil: "networkidle",
|
|
1111
|
+
timeout: 60000,
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
const loginError = await page.$(".login-error");
|
|
1115
|
+
if (loginError) {
|
|
1116
|
+
throw new Error("Login failed. Please check your credentials.");
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
console.log("Signed In to QuickBase.");
|
|
1120
|
+
loginSuccess = true;
|
|
1121
|
+
} catch (error) {
|
|
1122
|
+
console.error(
|
|
1123
|
+
`Login attempt ${loginAttempt} failed: ${(error as Error).message}`
|
|
1124
|
+
);
|
|
1125
|
+
if (loginAttempt >= maxLoginAttempts) {
|
|
1126
|
+
console.error("Max login attempts reached. Exiting.");
|
|
1127
|
+
await page.context().browser()!.close();
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return loginSuccess;
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
test.describe("QuickbaseClient Integration - getApp with Temp Tokens", () => {
|
|
1137
|
+
test("uses temp tokens automatically for getApp in browser", async ({
|
|
1138
|
+
page,
|
|
1139
|
+
}) => {
|
|
1140
|
+
const realm = process.env.QB_REALM;
|
|
1141
|
+
const appId = process.env.QB_APP_ID;
|
|
1142
|
+
const username = process.env.QB_USERNAME;
|
|
1143
|
+
const password = process.env.QB_PASSWORD;
|
|
1144
|
+
|
|
1145
|
+
if (!realm) throw new Error("QB_REALM is not defined in .env");
|
|
1146
|
+
if (!appId) throw new Error("QB_APP_ID is not defined in .env");
|
|
1147
|
+
if (!username) throw new Error("QB_USERNAME is not defined in .env");
|
|
1148
|
+
if (!password) throw new Error("QB_PASSWORD is not defined in .env");
|
|
1149
|
+
|
|
1150
|
+
// Login to QuickBase
|
|
1151
|
+
const quickbaseUrl = `https://${realm}.quickbase.com/db/main?a=SignIn`;
|
|
1152
|
+
const loginSuccess = await loginToQuickbase(
|
|
1153
|
+
page,
|
|
1154
|
+
quickbaseUrl,
|
|
1155
|
+
username,
|
|
1156
|
+
password
|
|
1157
|
+
);
|
|
1158
|
+
if (!loginSuccess) {
|
|
1159
|
+
throw new Error("Failed to log in to QuickBase after max attempts.");
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
// Navigate to the app page to ensure session context
|
|
1163
|
+
await page.goto(`https://${realm}.quickbase.com/db/${appId}`, {
|
|
1164
|
+
waitUntil: "networkidle",
|
|
1165
|
+
timeout: 60000,
|
|
1166
|
+
});
|
|
1167
|
+
console.log("Post-login URL after app navigation:", page.url());
|
|
1168
|
+
|
|
1169
|
+
// Define browser fetch function
|
|
1170
|
+
const browserFetch = async (url: string, init?: RequestInit) => {
|
|
1171
|
+
const response = await page.evaluate(
|
|
1172
|
+
async ([fetchUrl, fetchInit]) => {
|
|
1173
|
+
const res = await fetch(fetchUrl, {
|
|
1174
|
+
...fetchInit,
|
|
1175
|
+
credentials: "include",
|
|
1176
|
+
});
|
|
1177
|
+
const body = await res.text();
|
|
1178
|
+
return {
|
|
1179
|
+
ok: res.ok,
|
|
1180
|
+
status: res.status,
|
|
1181
|
+
statusText: res.statusText,
|
|
1182
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
1183
|
+
body,
|
|
1184
|
+
};
|
|
1185
|
+
},
|
|
1186
|
+
[url, init] as [string, RequestInit]
|
|
1187
|
+
);
|
|
1188
|
+
|
|
1189
|
+
console.log(`Raw response from ${url}:`, {
|
|
1190
|
+
status: response.status,
|
|
1191
|
+
statusText: response.statusText,
|
|
1192
|
+
body: response.body,
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1195
|
+
const fetchResponse = new Response(response.body || null, {
|
|
1196
|
+
status: response.status,
|
|
1197
|
+
statusText: response.statusText,
|
|
1198
|
+
headers: response.headers,
|
|
1199
|
+
});
|
|
1200
|
+
|
|
1201
|
+
fetchResponse.json = async () => {
|
|
1202
|
+
if (!response.body) throw new Error("Empty response body from API");
|
|
1203
|
+
try {
|
|
1204
|
+
return JSON.parse(response.body);
|
|
1205
|
+
} catch (e) {
|
|
1206
|
+
throw new SyntaxError(`Invalid JSON response: ${response.body}`);
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
return fetchResponse;
|
|
1211
|
+
};
|
|
1212
|
+
|
|
1213
|
+
// Single client with conditional fetch
|
|
1214
|
+
const client = quickbase({
|
|
1215
|
+
realm,
|
|
1216
|
+
useTempTokens: true,
|
|
1217
|
+
debug: true,
|
|
1218
|
+
fetchApi: async (url, init) => {
|
|
1219
|
+
if (url.includes("/auth/temporary/")) {
|
|
1220
|
+
return browserFetch(url, init); // Use browser context for temp token
|
|
1221
|
+
}
|
|
1222
|
+
console.log(`Fetching ${url} with init:`, init);
|
|
1223
|
+
const response = await fetch(url, init as RequestInit); // Node-fetch for API calls
|
|
1224
|
+
const body = await response.text();
|
|
1225
|
+
|
|
1226
|
+
console.log(`Raw response from ${url}:`, {
|
|
1227
|
+
status: response.status,
|
|
1228
|
+
statusText: response.statusText,
|
|
1229
|
+
body,
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1232
|
+
const fetchResponse = new Response(body || null, {
|
|
1233
|
+
status: response.status,
|
|
1234
|
+
statusText: response.statusText,
|
|
1235
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
1236
|
+
});
|
|
1237
|
+
|
|
1238
|
+
fetchResponse.json = async () => {
|
|
1239
|
+
if (!body) throw new Error("Empty response body from API");
|
|
1240
|
+
try {
|
|
1241
|
+
return JSON.parse(body);
|
|
1242
|
+
} catch (e) {
|
|
1243
|
+
throw new SyntaxError(`Invalid JSON response: ${body}`);
|
|
1244
|
+
}
|
|
1245
|
+
};
|
|
1246
|
+
|
|
1247
|
+
return fetchResponse;
|
|
1248
|
+
},
|
|
1249
|
+
});
|
|
1250
|
+
|
|
1251
|
+
// Call getApp directly, letting the library handle temp token logic
|
|
1252
|
+
const appResult = await client.getApp({ appId });
|
|
1253
|
+
console.log("App response using auto-fetched temp token:", appResult);
|
|
1254
|
+
|
|
1255
|
+
// Validate the app response
|
|
1256
|
+
expect(appResult).toHaveProperty("id", appId);
|
|
1257
|
+
expect(appResult).toHaveProperty("name");
|
|
1258
|
+
});
|
|
1259
|
+
});
|
|
1260
|
+
- name: tokenPrefetch.test.ts
|
|
1261
|
+
type: file
|
|
1262
|
+
contents: |
|
|
1263
|
+
// tests/playwright/qb/auth/tokenPrefetch.test.ts
|
|
1264
|
+
import { test, expect } from "@playwright/test";
|
|
1265
|
+
import { quickbase } from "../../../../src/quickbaseClient.ts";
|
|
1266
|
+
import fetch from "node-fetch";
|
|
1267
|
+
import dotenv from "dotenv";
|
|
1268
|
+
|
|
1269
|
+
dotenv.config();
|
|
1270
|
+
|
|
1271
|
+
const loginToQuickbase = async (
|
|
1272
|
+
page: import("@playwright/test").Page,
|
|
1273
|
+
quickbaseUrl: string,
|
|
1274
|
+
username: string,
|
|
1275
|
+
password: string
|
|
1276
|
+
): Promise<boolean> => {
|
|
1277
|
+
console.log("Logging in to QuickBase");
|
|
1278
|
+
let loginSuccess = false;
|
|
1279
|
+
const maxLoginAttempts = 3;
|
|
1280
|
+
let loginAttempt = 0;
|
|
1281
|
+
|
|
1282
|
+
while (!loginSuccess && loginAttempt < maxLoginAttempts) {
|
|
1283
|
+
try {
|
|
1284
|
+
loginAttempt++;
|
|
1285
|
+
if (loginAttempt > 1) console.log(`Login attempt ${loginAttempt}`);
|
|
1286
|
+
|
|
1287
|
+
await page.goto(quickbaseUrl, { timeout: 60000 });
|
|
1288
|
+
await page.waitForSelector("input[name='loginid']", { timeout: 60000 });
|
|
1289
|
+
await page.fill("input[name='loginid']", username);
|
|
1290
|
+
await page.fill("input[name='password']", password);
|
|
1291
|
+
await page.click("#signin");
|
|
1292
|
+
await page.waitForURL(`https://*.quickbase.com/**`, {
|
|
1293
|
+
waitUntil: "networkidle",
|
|
1294
|
+
timeout: 60000,
|
|
1295
|
+
});
|
|
1296
|
+
|
|
1297
|
+
const loginError = await page.$(".login-error");
|
|
1298
|
+
if (loginError) {
|
|
1299
|
+
throw new Error("Login failed. Please check your credentials.");
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
console.log("Signed In to QuickBase.");
|
|
1303
|
+
loginSuccess = true;
|
|
1304
|
+
} catch (error) {
|
|
1305
|
+
console.error(
|
|
1306
|
+
`Login attempt ${loginAttempt} failed: ${(error as Error).message}`
|
|
1307
|
+
);
|
|
1308
|
+
if (loginAttempt >= maxLoginAttempts) {
|
|
1309
|
+
console.error("Max login attempts reached. Exiting.");
|
|
1310
|
+
await page.context().browser()!.close();
|
|
1311
|
+
return false;
|
|
1312
|
+
}
|
|
1313
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
return loginSuccess;
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
test.describe("QuickbaseClient Integration - Token Pre-Fetch and Cache Reuse", () => {
|
|
1320
|
+
test("pre-fetches token and reuses it for subsequent API calls", async ({
|
|
1321
|
+
page,
|
|
1322
|
+
}) => {
|
|
1323
|
+
const realm = process.env.QB_REALM;
|
|
1324
|
+
const appId = process.env.QB_APP_ID;
|
|
1325
|
+
const username = process.env.QB_USERNAME;
|
|
1326
|
+
const password = process.env.QB_PASSWORD;
|
|
1327
|
+
|
|
1328
|
+
if (!realm) throw new Error("QB_REALM is not defined in .env");
|
|
1329
|
+
if (!appId) throw new Error("QB_APP_ID is not defined in .env");
|
|
1330
|
+
if (!username) throw new Error("QB_USERNAME is not defined in .env");
|
|
1331
|
+
if (!password) throw new Error("QB_PASSWORD is not defined in .env");
|
|
1332
|
+
|
|
1333
|
+
// Login to QuickBase
|
|
1334
|
+
const quickbaseUrl = `https://${realm}.quickbase.com/db/main?a=SignIn`;
|
|
1335
|
+
const loginSuccess = await loginToQuickbase(
|
|
1336
|
+
page,
|
|
1337
|
+
quickbaseUrl,
|
|
1338
|
+
username,
|
|
1339
|
+
password
|
|
1340
|
+
);
|
|
1341
|
+
if (!loginSuccess) {
|
|
1342
|
+
throw new Error("Failed to log in to QuickBase after max attempts.");
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// Navigate to the app page to ensure session context
|
|
1346
|
+
await page.goto(`https://${realm}.quickbase.com/db/${appId}`, {
|
|
1347
|
+
waitUntil: "networkidle",
|
|
1348
|
+
timeout: 60000,
|
|
1349
|
+
});
|
|
1350
|
+
console.log("Post-login URL after app navigation:", page.url());
|
|
1351
|
+
|
|
1352
|
+
// Track tokens and call counts
|
|
1353
|
+
let callCount = 0;
|
|
1354
|
+
let cachedToken: string | null = null;
|
|
1355
|
+
|
|
1356
|
+
const browserFetch = async (url: string, init?: RequestInit) => {
|
|
1357
|
+
console.log(`browserFetch called for ${url}, callCount: ${callCount}`);
|
|
1358
|
+
const response = await page.evaluate(
|
|
1359
|
+
async ([fetchUrl, fetchInit]) => {
|
|
1360
|
+
const res = await fetch(fetchUrl, {
|
|
1361
|
+
...fetchInit,
|
|
1362
|
+
credentials: "include",
|
|
1363
|
+
});
|
|
1364
|
+
const body = await res.text();
|
|
1365
|
+
return {
|
|
1366
|
+
ok: res.ok,
|
|
1367
|
+
status: res.status,
|
|
1368
|
+
statusText: res.statusText,
|
|
1369
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
1370
|
+
body,
|
|
1371
|
+
};
|
|
1372
|
+
},
|
|
1373
|
+
[url, init] as [string, RequestInit]
|
|
1374
|
+
);
|
|
1375
|
+
|
|
1376
|
+
console.log(`Raw response from ${url}:`, {
|
|
1377
|
+
status: response.status,
|
|
1378
|
+
statusText: response.statusText,
|
|
1379
|
+
body: response.body,
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1382
|
+
const fetchResponse = new Response(response.body || null, {
|
|
1383
|
+
status: response.status,
|
|
1384
|
+
statusText: response.statusText,
|
|
1385
|
+
headers: response.headers,
|
|
1386
|
+
});
|
|
1387
|
+
|
|
1388
|
+
// Capture token from response
|
|
1389
|
+
if (url.includes("/auth/temporary/")) {
|
|
1390
|
+
const json = await fetchResponse.clone().json();
|
|
1391
|
+
const token = json.temporaryAuthorization;
|
|
1392
|
+
cachedToken = token; // Store the pre-fetched token
|
|
1393
|
+
console.log(`Captured pre-fetched token: ${cachedToken}`);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
return fetchResponse;
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
const client = quickbase({
|
|
1400
|
+
realm,
|
|
1401
|
+
useTempTokens: true,
|
|
1402
|
+
debug: true,
|
|
1403
|
+
fetchApi: async (url, init) => {
|
|
1404
|
+
callCount++;
|
|
1405
|
+
console.log(`fetchApi called for ${url}, callCount: ${callCount}`);
|
|
1406
|
+
|
|
1407
|
+
if (url.includes("/auth/temporary/")) {
|
|
1408
|
+
return browserFetch(url, init); // Use browser fetch for temp tokens
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
// Use node-fetch for app calls, ensuring we track reuse
|
|
1412
|
+
console.log(`Fetching ${url} with init:`, init);
|
|
1413
|
+
const response = await fetch(url, init as RequestInit);
|
|
1414
|
+
const body = await response.text();
|
|
1415
|
+
|
|
1416
|
+
console.log(`Raw response from ${url}:`, {
|
|
1417
|
+
status: response.status,
|
|
1418
|
+
statusText: response.statusText,
|
|
1419
|
+
body,
|
|
1420
|
+
});
|
|
1421
|
+
|
|
1422
|
+
return new Response(body || null, {
|
|
1423
|
+
status: response.status,
|
|
1424
|
+
statusText: response.statusText,
|
|
1425
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
1426
|
+
});
|
|
1427
|
+
},
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1430
|
+
// Step 1: Pre-fetch token
|
|
1431
|
+
console.log("Pre-fetching token...");
|
|
1432
|
+
const tokenResult = await client.getTempTokenDBID({ dbid: appId });
|
|
1433
|
+
console.log("Pre-fetched token result:", tokenResult);
|
|
1434
|
+
expect(tokenResult).toHaveProperty("temporaryAuthorization");
|
|
1435
|
+
expect(cachedToken).toBe(tokenResult.temporaryAuthorization);
|
|
1436
|
+
|
|
1437
|
+
// Step 2: Call getApp, expecting it to reuse the cached token
|
|
1438
|
+
console.log("Calling getApp with pre-fetched token...");
|
|
1439
|
+
const appResult = await client.getApp({ appId });
|
|
1440
|
+
console.log("App response:", appResult);
|
|
1441
|
+
|
|
1442
|
+
// Validate the app response
|
|
1443
|
+
expect(appResult).toHaveProperty("id", appId);
|
|
1444
|
+
expect(appResult).toHaveProperty("name");
|
|
1445
|
+
|
|
1446
|
+
// Verify call count and token reuse
|
|
1447
|
+
console.log(`Final callCount: ${callCount}`);
|
|
1448
|
+
expect(callCount).toBe(2); // One for pre-fetch, one for getApp
|
|
1449
|
+
expect(cachedToken).toBeDefined();
|
|
1450
|
+
|
|
1451
|
+
// Check that getApp reused the token by inspecting logs manually or adding a header check if needed
|
|
1452
|
+
console.log(`Pre-fetched token: ${cachedToken}`);
|
|
1453
|
+
});
|
|
1454
|
+
});
|
|
1455
|
+
- name: tokenRenewal.test.ts
|
|
1456
|
+
type: file
|
|
1457
|
+
contents: |
|
|
1458
|
+
// tests/playwright/qb/auth/tokenRenewal.test.ts
|
|
1459
|
+
import { test, expect } from "@playwright/test";
|
|
1460
|
+
import { quickbase } from "../../../../src/quickbaseClient.ts";
|
|
1461
|
+
import dotenv from "dotenv";
|
|
1462
|
+
|
|
1463
|
+
dotenv.config();
|
|
1464
|
+
|
|
1465
|
+
const loginToQuickbase = async (
|
|
1466
|
+
page,
|
|
1467
|
+
quickbaseUrl,
|
|
1468
|
+
username,
|
|
1469
|
+
password,
|
|
1470
|
+
appUrl
|
|
1471
|
+
) => {
|
|
1472
|
+
console.log("Logging in to QuickBase");
|
|
1473
|
+
await page.goto(quickbaseUrl, { timeout: 60000 });
|
|
1474
|
+
await page.waitForSelector("input[name='loginid']", { timeout: 60000 });
|
|
1475
|
+
await page.fill("input[name='loginid']", username);
|
|
1476
|
+
await page.fill("input[name='password']", password);
|
|
1477
|
+
await page.click("#signin");
|
|
1478
|
+
await page.waitForURL(`https://*.quickbase.com/**`, {
|
|
1479
|
+
waitUntil: "networkidle",
|
|
1480
|
+
timeout: 60000,
|
|
1481
|
+
});
|
|
1482
|
+
console.log("Signed In to QuickBase.");
|
|
1483
|
+
await page.goto(appUrl, { waitUntil: "networkidle", timeout: 60000 });
|
|
1484
|
+
console.log("Navigated to app URL:", page.url());
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
test.describe("QuickbaseClient Integration - Temp Token Renewal", () => {
|
|
1488
|
+
test("renews temp token after 5 minutes with getApp → wait → getApp sequence", async ({
|
|
1489
|
+
page,
|
|
1490
|
+
}) => {
|
|
1491
|
+
const realm = process.env.QB_REALM!;
|
|
1492
|
+
const appId = process.env.QB_APP_ID!;
|
|
1493
|
+
const username = process.env.QB_USERNAME!;
|
|
1494
|
+
const password = process.env.QB_PASSWORD!;
|
|
1495
|
+
const quickbaseUrl = `https://${realm}.quickbase.com/db/main?a=SignIn`;
|
|
1496
|
+
const appUrl = `https://${realm}.quickbase.com/db/${appId}`;
|
|
1497
|
+
|
|
1498
|
+
await loginToQuickbase(page, quickbaseUrl, username, password, appUrl);
|
|
1499
|
+
|
|
1500
|
+
const browserFetch = async (
|
|
1501
|
+
url: string,
|
|
1502
|
+
init: RequestInit
|
|
1503
|
+
): Promise<Response> => {
|
|
1504
|
+
const response = await page.request.fetch(url, {
|
|
1505
|
+
method: init.method || "GET",
|
|
1506
|
+
headers: {
|
|
1507
|
+
...init.headers,
|
|
1508
|
+
Referer: `https://${realm}.quickbase.com/db/${appId}`,
|
|
1509
|
+
Origin: `https://${realm}.quickbase.com`,
|
|
1510
|
+
},
|
|
1511
|
+
data: init.body,
|
|
1512
|
+
credentials: "include",
|
|
1513
|
+
});
|
|
1514
|
+
const body = await response.text();
|
|
1515
|
+
console.log(
|
|
1516
|
+
"Response from:",
|
|
1517
|
+
url,
|
|
1518
|
+
"status:",
|
|
1519
|
+
response.status(),
|
|
1520
|
+
"body:",
|
|
1521
|
+
body
|
|
1522
|
+
);
|
|
1523
|
+
return new Response(body, {
|
|
1524
|
+
status: response.status(),
|
|
1525
|
+
statusText: response.statusText(),
|
|
1526
|
+
headers: response.headers(),
|
|
1527
|
+
});
|
|
1528
|
+
};
|
|
1529
|
+
|
|
1530
|
+
const client = quickbase({
|
|
1531
|
+
realm,
|
|
1532
|
+
useTempTokens: true,
|
|
1533
|
+
debug: true,
|
|
1534
|
+
fetchApi: browserFetch,
|
|
1535
|
+
});
|
|
1536
|
+
|
|
1537
|
+
console.log("Checking session state before getApp...");
|
|
1538
|
+
const cookies = await page.context().cookies();
|
|
1539
|
+
const sessionCookie = cookies.find(
|
|
1540
|
+
(c) => c.name === "TICKET" || c.name.startsWith("TICKET_")
|
|
1541
|
+
);
|
|
1542
|
+
console.log(
|
|
1543
|
+
"Session cookie present:",
|
|
1544
|
+
!!sessionCookie,
|
|
1545
|
+
"Cookies:",
|
|
1546
|
+
cookies
|
|
1547
|
+
);
|
|
1548
|
+
if (!sessionCookie) throw new Error("TICKET session cookie not found");
|
|
1549
|
+
|
|
1550
|
+
await page.waitForTimeout(5000); // Debug delay
|
|
1551
|
+
console.log("Cookies after delay:", await page.context().cookies());
|
|
1552
|
+
|
|
1553
|
+
const appResult1 = await client.getApp({ appId });
|
|
1554
|
+
console.log("First getApp response:", appResult1);
|
|
1555
|
+
expect(appResult1.id).toBe(appId);
|
|
1556
|
+
|
|
1557
|
+
console.log("Waiting 5 minutes to test token expiration...");
|
|
1558
|
+
await new Promise((resolve) => setTimeout(resolve, 5 * 60 * 1000));
|
|
1559
|
+
|
|
1560
|
+
await page.reload({ waitUntil: "load", timeout: 60000 });
|
|
1561
|
+
console.log("Refreshed page after 5 minutes, URL:", page.url());
|
|
1562
|
+
|
|
1563
|
+
const appResult2 = await client.getApp({ appId });
|
|
1564
|
+
console.log("Second getApp response:", appResult2);
|
|
1565
|
+
expect(appResult2.id).toBe(appId);
|
|
1566
|
+
});
|
|
1567
|
+
});
|
|
1568
|
+
- name: setup.ts
|
|
1569
|
+
type: file
|
|
1570
|
+
contents: |
|
|
1571
|
+
// @tests/setup.ts
|
|
1572
|
+
import { vi } from "vitest";
|
|
1573
|
+
import { quickbase } from "../src/quickbaseClient.ts";
|
|
1574
|
+
import type { QuickbaseConfig } from "../src/quickbaseClient.ts";
|
|
1575
|
+
|
|
1576
|
+
export const mockFetch = vi.fn();
|
|
1577
|
+
|
|
1578
|
+
export const createClient = (
|
|
1579
|
+
fetchApi?: any,
|
|
1580
|
+
config: Partial<QuickbaseConfig> = {}
|
|
1581
|
+
) => {
|
|
1582
|
+
const client = quickbase({
|
|
1583
|
+
realm: process.env.QB_REALM || "test-realm", // Match upsert.test.ts
|
|
1584
|
+
userToken: process.env.QB_USER_TOKEN || "test-token", // Match upsert.test.ts
|
|
1585
|
+
debug: true,
|
|
1586
|
+
fetchApi,
|
|
1587
|
+
...config,
|
|
1588
|
+
});
|
|
1589
|
+
console.log("[createClient] Config:", config); // Debug config
|
|
1590
|
+
console.log("[createClient] Returning:", client); // Debug client
|
|
1591
|
+
return client;
|
|
1592
|
+
};
|
|
1593
|
+
|
|
1594
|
+
// Mock env variables for consistency
|
|
1595
|
+
vi.stubEnv("QB_REALM", "builderprogram-dbradford6815");
|
|
1596
|
+
vi.stubEnv("QB_USER_TOKEN", "b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3");
|
|
1597
|
+
vi.stubEnv("QB_APP_ID", "buwai2zpe");
|
|
1598
|
+
- name: vitest
|
|
1599
|
+
type: directory
|
|
1600
|
+
children:
|
|
1601
|
+
- name: qb
|
|
1602
|
+
type: directory
|
|
1603
|
+
children:
|
|
1604
|
+
- name: apps
|
|
1605
|
+
type: directory
|
|
1606
|
+
children:
|
|
1607
|
+
- name: getApp.test.ts
|
|
1608
|
+
type: file
|
|
1609
|
+
contents: |
|
|
1610
|
+
import { test, expect } from "vitest";
|
|
1611
|
+
import { quickbase } from "../../../../src/quickbaseClient";
|
|
1612
|
+
|
|
1613
|
+
test(
|
|
1614
|
+
"QuickbaseClient Integration - getApp > fetches real app data from QuickBase",
|
|
1615
|
+
{ timeout: 10000 },
|
|
1616
|
+
async () => {
|
|
1617
|
+
const config = {
|
|
1618
|
+
realm: process.env.QB_REALM || "",
|
|
1619
|
+
userToken: process.env.QB_USER_TOKEN || "",
|
|
1620
|
+
debug: true,
|
|
1621
|
+
};
|
|
1622
|
+
const client = quickbase(config);
|
|
1623
|
+
const getAppId = "buwai2zpe";
|
|
1624
|
+
|
|
1625
|
+
console.log("Config used:", config);
|
|
1626
|
+
const result = await client.getApp({ appId: getAppId });
|
|
1627
|
+
console.log("Real API response:", result);
|
|
1628
|
+
|
|
1629
|
+
expect(result).toEqual({
|
|
1630
|
+
id: getAppId,
|
|
1631
|
+
name: "qb-copy",
|
|
1632
|
+
created: expect.any(Date), // Matches Date object from client
|
|
1633
|
+
updated: expect.any(Date), // Matches Date object from client
|
|
1634
|
+
description: "",
|
|
1635
|
+
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
1636
|
+
dateFormat: "MM-DD-YYYY",
|
|
1637
|
+
hasEveryoneOnTheInternet: false,
|
|
1638
|
+
memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
|
|
1639
|
+
securityProperties: {
|
|
1640
|
+
allowClone: false,
|
|
1641
|
+
allowExport: true,
|
|
1642
|
+
enableAppTokens: true,
|
|
1643
|
+
hideFromPublic: false,
|
|
1644
|
+
mustBeRealmApproved: false,
|
|
1645
|
+
useIPFilter: false,
|
|
1646
|
+
},
|
|
1647
|
+
});
|
|
1648
|
+
}
|
|
1649
|
+
);
|
|
1650
|
+
- name: fields
|
|
1651
|
+
type: directory
|
|
1652
|
+
children:
|
|
1653
|
+
- name: getFields.test.ts
|
|
1654
|
+
type: file
|
|
1655
|
+
contents: |
|
|
1656
|
+
import { describe, it, expect } from "vitest";
|
|
1657
|
+
import { createClient } from "../../../setup.ts";
|
|
1658
|
+
|
|
1659
|
+
describe("QuickbaseClient Integration - getFields", () => {
|
|
1660
|
+
const client = createClient();
|
|
1661
|
+
|
|
1662
|
+
it(
|
|
1663
|
+
"fetches real field data from QuickBase",
|
|
1664
|
+
async () => {
|
|
1665
|
+
const tableId = "buwai2z3s";
|
|
1666
|
+
if (!tableId) throw new Error("Table ID is not defined");
|
|
1667
|
+
if (!process.env.QB_REALM)
|
|
1668
|
+
throw new Error("QB_REALM is not defined in .env");
|
|
1669
|
+
if (!process.env.QB_USER_TOKEN)
|
|
1670
|
+
throw new Error("QB_USER_TOKEN is not defined in .env");
|
|
1671
|
+
|
|
1672
|
+
console.log("Config used:", {
|
|
1673
|
+
realm: process.env.QB_REALM,
|
|
1674
|
+
userToken: process.env.QB_USER_TOKEN,
|
|
1675
|
+
tableId,
|
|
1676
|
+
});
|
|
1677
|
+
const result = await client.getFields({
|
|
1678
|
+
tableId,
|
|
1679
|
+
includeFieldPerms: true,
|
|
1680
|
+
});
|
|
1681
|
+
console.log("Real API response:", result);
|
|
1682
|
+
expect(result).toEqual(
|
|
1683
|
+
expect.arrayContaining([
|
|
1684
|
+
expect.objectContaining({
|
|
1685
|
+
id: 1,
|
|
1686
|
+
label: "Date Created",
|
|
1687
|
+
fieldType: "timestamp",
|
|
1688
|
+
noWrap: true,
|
|
1689
|
+
bold: false,
|
|
1690
|
+
required: false,
|
|
1691
|
+
appearsByDefault: false,
|
|
1692
|
+
findEnabled: false,
|
|
1693
|
+
unique: false,
|
|
1694
|
+
doesDataCopy: false,
|
|
1695
|
+
fieldHelp: "",
|
|
1696
|
+
audited: false,
|
|
1697
|
+
properties: expect.objectContaining({
|
|
1698
|
+
primaryKey: false,
|
|
1699
|
+
foreignKey: false,
|
|
1700
|
+
sortAsGiven: true,
|
|
1701
|
+
carryChoices: true,
|
|
1702
|
+
allowNewChoices: false,
|
|
1703
|
+
formula: "",
|
|
1704
|
+
defaultValue: "",
|
|
1705
|
+
}),
|
|
1706
|
+
permissions: expect.arrayContaining([
|
|
1707
|
+
expect.objectContaining({
|
|
1708
|
+
permissionType: "Modify",
|
|
1709
|
+
role: "Viewer",
|
|
1710
|
+
roleId: 10,
|
|
1711
|
+
}),
|
|
1712
|
+
expect.objectContaining({
|
|
1713
|
+
permissionType: "Modify",
|
|
1714
|
+
role: "Participant",
|
|
1715
|
+
roleId: 11,
|
|
1716
|
+
}),
|
|
1717
|
+
expect.objectContaining({
|
|
1718
|
+
permissionType: "Modify",
|
|
1719
|
+
role: "Administrator",
|
|
1720
|
+
roleId: 12,
|
|
1721
|
+
}),
|
|
1722
|
+
]),
|
|
1723
|
+
}),
|
|
1724
|
+
expect.objectContaining({
|
|
1725
|
+
id: 2,
|
|
1726
|
+
label: "Date Modified",
|
|
1727
|
+
fieldType: "timestamp",
|
|
1728
|
+
noWrap: true,
|
|
1729
|
+
bold: false,
|
|
1730
|
+
required: false,
|
|
1731
|
+
appearsByDefault: false,
|
|
1732
|
+
findEnabled: false,
|
|
1733
|
+
unique: false,
|
|
1734
|
+
doesDataCopy: false,
|
|
1735
|
+
fieldHelp: "",
|
|
1736
|
+
audited: false,
|
|
1737
|
+
properties: expect.objectContaining({
|
|
1738
|
+
primaryKey: false,
|
|
1739
|
+
foreignKey: false,
|
|
1740
|
+
sortAsGiven: true,
|
|
1741
|
+
carryChoices: true,
|
|
1742
|
+
allowNewChoices: false,
|
|
1743
|
+
formula: "",
|
|
1744
|
+
defaultValue: "",
|
|
1745
|
+
}),
|
|
1746
|
+
permissions: expect.arrayContaining([
|
|
1747
|
+
expect.objectContaining({
|
|
1748
|
+
permissionType: "Modify",
|
|
1749
|
+
role: "Viewer",
|
|
1750
|
+
roleId: 10,
|
|
1751
|
+
}),
|
|
1752
|
+
expect.objectContaining({
|
|
1753
|
+
permissionType: "Modify",
|
|
1754
|
+
role: "Participant",
|
|
1755
|
+
roleId: 11,
|
|
1756
|
+
}),
|
|
1757
|
+
expect.objectContaining({
|
|
1758
|
+
permissionType: "Modify",
|
|
1759
|
+
role: "Administrator",
|
|
1760
|
+
roleId: 12,
|
|
1761
|
+
}),
|
|
1762
|
+
]),
|
|
1763
|
+
}),
|
|
1764
|
+
expect.objectContaining({
|
|
1765
|
+
id: 3,
|
|
1766
|
+
label: "Record ID#",
|
|
1767
|
+
fieldType: "recordid",
|
|
1768
|
+
noWrap: true,
|
|
1769
|
+
bold: false,
|
|
1770
|
+
required: false,
|
|
1771
|
+
appearsByDefault: false,
|
|
1772
|
+
findEnabled: false,
|
|
1773
|
+
unique: true,
|
|
1774
|
+
doesDataCopy: false,
|
|
1775
|
+
fieldHelp: "",
|
|
1776
|
+
audited: false,
|
|
1777
|
+
properties: expect.objectContaining({
|
|
1778
|
+
primaryKey: true,
|
|
1779
|
+
foreignKey: false,
|
|
1780
|
+
sortAsGiven: true,
|
|
1781
|
+
carryChoices: true,
|
|
1782
|
+
allowNewChoices: false,
|
|
1783
|
+
formula: "",
|
|
1784
|
+
defaultValue: "",
|
|
1785
|
+
}),
|
|
1786
|
+
permissions: expect.arrayContaining([
|
|
1787
|
+
expect.objectContaining({
|
|
1788
|
+
permissionType: "Modify",
|
|
1789
|
+
role: "Viewer",
|
|
1790
|
+
roleId: 10,
|
|
1791
|
+
}),
|
|
1792
|
+
expect.objectContaining({
|
|
1793
|
+
permissionType: "Modify",
|
|
1794
|
+
role: "Participant",
|
|
1795
|
+
roleId: 11,
|
|
1796
|
+
}),
|
|
1797
|
+
expect.objectContaining({
|
|
1798
|
+
permissionType: "Modify",
|
|
1799
|
+
role: "Administrator",
|
|
1800
|
+
roleId: 12,
|
|
1801
|
+
}),
|
|
1802
|
+
]),
|
|
1803
|
+
}),
|
|
1804
|
+
expect.objectContaining({
|
|
1805
|
+
id: 4,
|
|
1806
|
+
label: "Record Owner",
|
|
1807
|
+
fieldType: "user",
|
|
1808
|
+
noWrap: true,
|
|
1809
|
+
bold: false,
|
|
1810
|
+
required: false,
|
|
1811
|
+
appearsByDefault: false,
|
|
1812
|
+
findEnabled: true,
|
|
1813
|
+
unique: false,
|
|
1814
|
+
doesDataCopy: false,
|
|
1815
|
+
fieldHelp: "",
|
|
1816
|
+
audited: false,
|
|
1817
|
+
properties: expect.objectContaining({
|
|
1818
|
+
primaryKey: false,
|
|
1819
|
+
foreignKey: false,
|
|
1820
|
+
sortAsGiven: true,
|
|
1821
|
+
carryChoices: true,
|
|
1822
|
+
allowNewChoices: true,
|
|
1823
|
+
formula: "",
|
|
1824
|
+
defaultValue: "",
|
|
1825
|
+
}),
|
|
1826
|
+
permissions: expect.arrayContaining([
|
|
1827
|
+
expect.objectContaining({
|
|
1828
|
+
permissionType: "Modify",
|
|
1829
|
+
role: "Viewer",
|
|
1830
|
+
roleId: 10,
|
|
1831
|
+
}),
|
|
1832
|
+
expect.objectContaining({
|
|
1833
|
+
permissionType: "Modify",
|
|
1834
|
+
role: "Participant",
|
|
1835
|
+
roleId: 11,
|
|
1836
|
+
}),
|
|
1837
|
+
expect.objectContaining({
|
|
1838
|
+
permissionType: "Modify",
|
|
1839
|
+
role: "Administrator",
|
|
1840
|
+
roleId: 12,
|
|
1841
|
+
}),
|
|
1842
|
+
]),
|
|
1843
|
+
}),
|
|
1844
|
+
expect.objectContaining({
|
|
1845
|
+
id: 5,
|
|
1846
|
+
label: "Last Modified By",
|
|
1847
|
+
fieldType: "user",
|
|
1848
|
+
noWrap: true,
|
|
1849
|
+
bold: false,
|
|
1850
|
+
required: false,
|
|
1851
|
+
appearsByDefault: false,
|
|
1852
|
+
findEnabled: true,
|
|
1853
|
+
unique: false,
|
|
1854
|
+
doesDataCopy: false,
|
|
1855
|
+
fieldHelp: "",
|
|
1856
|
+
audited: false,
|
|
1857
|
+
properties: expect.objectContaining({
|
|
1858
|
+
primaryKey: false,
|
|
1859
|
+
foreignKey: false,
|
|
1860
|
+
sortAsGiven: true,
|
|
1861
|
+
carryChoices: true,
|
|
1862
|
+
allowNewChoices: true,
|
|
1863
|
+
formula: "",
|
|
1864
|
+
defaultValue: "",
|
|
1865
|
+
}),
|
|
1866
|
+
permissions: expect.arrayContaining([
|
|
1867
|
+
expect.objectContaining({
|
|
1868
|
+
permissionType: "Modify",
|
|
1869
|
+
role: "Viewer",
|
|
1870
|
+
roleId: 10,
|
|
1871
|
+
}),
|
|
1872
|
+
expect.objectContaining({
|
|
1873
|
+
permissionType: "Modify",
|
|
1874
|
+
role: "Participant",
|
|
1875
|
+
roleId: 11,
|
|
1876
|
+
}),
|
|
1877
|
+
expect.objectContaining({
|
|
1878
|
+
permissionType: "Modify",
|
|
1879
|
+
role: "Administrator",
|
|
1880
|
+
roleId: 12,
|
|
1881
|
+
}),
|
|
1882
|
+
]),
|
|
1883
|
+
}),
|
|
1884
|
+
])
|
|
1885
|
+
);
|
|
1886
|
+
},
|
|
1887
|
+
{ timeout: 10000 }
|
|
1888
|
+
);
|
|
1889
|
+
});
|
|
1890
|
+
- name: index.ts
|
|
1891
|
+
type: file
|
|
1892
|
+
contents: |
|
|
1893
|
+
// Optional: Only add if you need to export tests
|
|
1894
|
+
export * from "./apps/getApp.test.ts";
|
|
1895
|
+
export * from "./fields/getFields.test.ts";
|
|
1896
|
+
export * from "./tables/getAppTables.test.ts";
|
|
1897
|
+
- name: records
|
|
1898
|
+
type: directory
|
|
1899
|
+
children:
|
|
1900
|
+
- name: deleteRecords.test.ts
|
|
1901
|
+
type: file
|
|
1902
|
+
contents: |
|
|
1903
|
+
// tests/vitest/qb/records/deleteRecords.test.ts
|
|
1904
|
+
import { describe, test, expect } from "vitest";
|
|
1905
|
+
import { quickbase } from "@/quickbaseClient.ts";
|
|
1906
|
+
|
|
1907
|
+
// Temporarily skip this suite due to timeout issues possibly related to upsert
|
|
1908
|
+
describe.skip("deleteRecords", () => {
|
|
1909
|
+
const qb = quickbase({
|
|
1910
|
+
realm: "builderprogram-dbradford6815",
|
|
1911
|
+
userToken: process.env.QB_USER_TOKEN,
|
|
1912
|
+
debug: true,
|
|
1913
|
+
});
|
|
1914
|
+
|
|
1915
|
+
test("deletes records matching query", async () => {
|
|
1916
|
+
const upsertResponse = await qb.upsert({
|
|
1917
|
+
body: { to: "buwai2zws", data: [{}] },
|
|
1918
|
+
});
|
|
1919
|
+
const recordId = upsertResponse.metadata.createdRecordIds[0];
|
|
1920
|
+
|
|
1921
|
+
const deleteResponse = await qb.deleteRecords({
|
|
1922
|
+
body: { from: "buwai2zws", where: `{3.EX.${recordId}}` },
|
|
1923
|
+
});
|
|
1924
|
+
|
|
1925
|
+
expect(deleteResponse).toEqual({ numberDeleted: 1 });
|
|
1926
|
+
});
|
|
1927
|
+
|
|
1928
|
+
test("handles empty result", async () => {
|
|
1929
|
+
const response = await qb.deleteRecords({
|
|
1930
|
+
body: { from: "buwai2zws", where: "{3.EX.'999999'}" },
|
|
1931
|
+
});
|
|
1932
|
+
expect(response).toEqual({ numberDeleted: 0 });
|
|
1933
|
+
});
|
|
1934
|
+
});
|
|
1935
|
+
- name: tables
|
|
1936
|
+
type: directory
|
|
1937
|
+
children:
|
|
1938
|
+
- name: createTable.test.ts
|
|
1939
|
+
type: file
|
|
1940
|
+
contents: |
|
|
1941
|
+
import { test, expect } from "vitest";
|
|
1942
|
+
import { quickbase } from "../../../../src/quickbaseClient";
|
|
1943
|
+
|
|
1944
|
+
test(
|
|
1945
|
+
"QuickbaseClient Integration - createTable > creates a new table in QuickBase",
|
|
1946
|
+
{ timeout: 10000 },
|
|
1947
|
+
async () => {
|
|
1948
|
+
const config = {
|
|
1949
|
+
realm: process.env.QB_REALM || "",
|
|
1950
|
+
userToken: process.env.QB_USER_TOKEN || "",
|
|
1951
|
+
debug: true,
|
|
1952
|
+
};
|
|
1953
|
+
const client = quickbase(config);
|
|
1954
|
+
const appId = "buwai2zpe";
|
|
1955
|
+
|
|
1956
|
+
const tableName = `TestTable_${Date.now()}`;
|
|
1957
|
+
const createBody = {
|
|
1958
|
+
name: tableName,
|
|
1959
|
+
description: "Test table creation",
|
|
1960
|
+
singleRecordName: "TestRecord",
|
|
1961
|
+
pluralRecordName: "TestRecords",
|
|
1962
|
+
};
|
|
1963
|
+
|
|
1964
|
+
console.log("Config used:", config);
|
|
1965
|
+
console.log("Creating table with:", createBody);
|
|
1966
|
+
const response = await client.createTable({ appId, body: createBody });
|
|
1967
|
+
|
|
1968
|
+
expect(response).toBeDefined();
|
|
1969
|
+
expect(response.id).toBeDefined();
|
|
1970
|
+
expect(response.name).toBe(tableName);
|
|
1971
|
+
expect(response.description).toBe(createBody.description);
|
|
1972
|
+
expect(response.singleRecordName).toBe(createBody.singleRecordName);
|
|
1973
|
+
expect(response.pluralRecordName).toBe(createBody.pluralRecordName);
|
|
1974
|
+
expect(response.alias).toMatch(/^_DBID_/);
|
|
1975
|
+
expect(response.created).toBeInstanceOf(Date);
|
|
1976
|
+
expect(response.updated).toBeInstanceOf(Date);
|
|
1977
|
+
expect(response.nextRecordId).toBeGreaterThanOrEqual(1);
|
|
1978
|
+
expect(response.nextFieldId).toBeGreaterThanOrEqual(1);
|
|
1979
|
+
expect(response.defaultSortFieldId).toBeGreaterThanOrEqual(0);
|
|
1980
|
+
expect(response.keyFieldId).toBeGreaterThanOrEqual(1);
|
|
1981
|
+
expect(response.sizeLimit).toMatch(/^\d+\sMB$/); // e.g., "500 MB"
|
|
1982
|
+
expect(response.spaceUsed).toMatch(/^\d+\s(KB|MB)$/); // e.g., "0 KB"
|
|
1983
|
+
expect(response.spaceRemaining).toMatch(/^\d+\sMB$/); // e.g., "500 MB"
|
|
1984
|
+
|
|
1985
|
+
console.log("Real API response:", response);
|
|
1986
|
+
|
|
1987
|
+
// Cleanup: Delete the table to avoid clutter
|
|
1988
|
+
const deleteResponse = await client.deleteTable({
|
|
1989
|
+
tableId: response.id,
|
|
1990
|
+
appId,
|
|
1991
|
+
});
|
|
1992
|
+
expect(deleteResponse.deletedTableId).toBe(response.id);
|
|
1993
|
+
console.log("Cleanup - Deleted table:", deleteResponse);
|
|
1994
|
+
}
|
|
1995
|
+
);
|
|
1996
|
+
- name: deleteTable.test.ts
|
|
1997
|
+
type: file
|
|
1998
|
+
contents: |
|
|
1999
|
+
import { test, expect } from "vitest";
|
|
2000
|
+
import { quickbase } from "../../../../src/quickbaseClient";
|
|
2001
|
+
|
|
2002
|
+
test(
|
|
2003
|
+
"QuickbaseClient Integration - deleteTable > deletes a table in QuickBase",
|
|
2004
|
+
{ timeout: 20000 },
|
|
2005
|
+
async () => {
|
|
2006
|
+
const config = {
|
|
2007
|
+
realm: process.env.QB_REALM || "",
|
|
2008
|
+
userToken: process.env.QB_USER_TOKEN || "",
|
|
2009
|
+
debug: true,
|
|
2010
|
+
};
|
|
2011
|
+
const client = quickbase(config);
|
|
2012
|
+
const appId = "buwai2zpe";
|
|
2013
|
+
|
|
2014
|
+
// Step 1: Create a temporary table to delete
|
|
2015
|
+
const tableName = `DeleteTest_${Date.now()}`;
|
|
2016
|
+
const createBody = {
|
|
2017
|
+
name: tableName,
|
|
2018
|
+
description: "Temporary table for delete test",
|
|
2019
|
+
singleRecordName: "DeleteTest",
|
|
2020
|
+
pluralRecordName: "DeleteTests",
|
|
2021
|
+
};
|
|
2022
|
+
console.log("Creating temporary table with:", createBody);
|
|
2023
|
+
const createResponse = await client.createTable({
|
|
2024
|
+
appId,
|
|
2025
|
+
body: createBody,
|
|
2026
|
+
});
|
|
2027
|
+
expect(createResponse.id).toBeDefined();
|
|
2028
|
+
expect(createResponse.name).toBe(tableName);
|
|
2029
|
+
console.log("Created table:", createResponse);
|
|
2030
|
+
const tableId = createResponse.id;
|
|
2031
|
+
|
|
2032
|
+
// Step 2: Delete the table
|
|
2033
|
+
console.log("Deleting table:", { tableId, appId });
|
|
2034
|
+
const deleteResponse = await client.deleteTable({ tableId, appId });
|
|
2035
|
+
expect(deleteResponse).toBeDefined();
|
|
2036
|
+
expect(deleteResponse.deletedTableId).toBe(tableId);
|
|
2037
|
+
console.log("Delete API response:", deleteResponse);
|
|
2038
|
+
|
|
2039
|
+
// Step 3: Verify the table is gone
|
|
2040
|
+
try {
|
|
2041
|
+
await client.getTable({ tableId, appId });
|
|
2042
|
+
throw new Error("Table should not exist after deletion");
|
|
2043
|
+
} catch (error) {
|
|
2044
|
+
expect(error.message).toMatch(/404|not found/i); // Expect a 404 error
|
|
2045
|
+
console.log("Verified table deletion:", error.message);
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
);
|
|
2049
|
+
- name: getAppTables.test.ts
|
|
2050
|
+
type: file
|
|
2051
|
+
contents: |
|
|
2052
|
+
import { test, expect } from "vitest";
|
|
2053
|
+
import { quickbase } from "../../../../src/quickbaseClient";
|
|
2054
|
+
|
|
2055
|
+
test(
|
|
2056
|
+
"QuickbaseClient Integration - getAppTables > fetches real table data from QuickBase",
|
|
2057
|
+
{ timeout: 10000 },
|
|
2058
|
+
async () => {
|
|
2059
|
+
const config = {
|
|
2060
|
+
realm: process.env.QB_REALM || "",
|
|
2061
|
+
userToken: process.env.QB_USER_TOKEN || "",
|
|
2062
|
+
debug: true,
|
|
2063
|
+
};
|
|
2064
|
+
const client = quickbase(config);
|
|
2065
|
+
const tablesAppId = "buwai2zpe";
|
|
2066
|
+
|
|
2067
|
+
console.log("Config used:", config);
|
|
2068
|
+
const result = await client.getAppTables({ appId: tablesAppId });
|
|
2069
|
+
console.log("Real API response:", result);
|
|
2070
|
+
|
|
2071
|
+
expect(result).toBeDefined();
|
|
2072
|
+
expect(result).toBeInstanceOf(Array);
|
|
2073
|
+
expect(result.length).toBeGreaterThan(0);
|
|
2074
|
+
expect(result).toEqual(
|
|
2075
|
+
expect.arrayContaining([
|
|
2076
|
+
expect.objectContaining({
|
|
2077
|
+
id: "buwai2zr4",
|
|
2078
|
+
alias: "_DBID_ROOT",
|
|
2079
|
+
name: expect.any(String), // Allow dynamic name due to updateTable
|
|
2080
|
+
description: expect.any(String), // Allow dynamic description
|
|
2081
|
+
created: expect.any(Date),
|
|
2082
|
+
updated: expect.any(Date), // Allow varying timestamps
|
|
2083
|
+
nextRecordId: expect.any(Number),
|
|
2084
|
+
nextFieldId: expect.any(Number),
|
|
2085
|
+
defaultSortFieldId: expect.any(Number),
|
|
2086
|
+
defaultSortOrder: "DESC",
|
|
2087
|
+
keyFieldId: expect.any(Number),
|
|
2088
|
+
singleRecordName: "Root",
|
|
2089
|
+
pluralRecordName: "Roots",
|
|
2090
|
+
sizeLimit: "500 MB",
|
|
2091
|
+
spaceUsed: expect.any(String),
|
|
2092
|
+
spaceRemaining: "500 MB",
|
|
2093
|
+
}),
|
|
2094
|
+
])
|
|
2095
|
+
);
|
|
2096
|
+
}
|
|
2097
|
+
);
|
|
2098
|
+
- name: getTable.test.ts
|
|
2099
|
+
type: file
|
|
2100
|
+
contents: |
|
|
2101
|
+
import { test, expect } from "vitest";
|
|
2102
|
+
import { quickbase } from "../../../../src/quickbaseClient";
|
|
2103
|
+
|
|
2104
|
+
test(
|
|
2105
|
+
"QuickbaseClient Integration - getTable > fetches real table data from QuickBase",
|
|
2106
|
+
{ timeout: 10000 },
|
|
2107
|
+
async () => {
|
|
2108
|
+
const config = {
|
|
2109
|
+
realm: process.env.QB_REALM || "",
|
|
2110
|
+
userToken: process.env.QB_USER_TOKEN || "",
|
|
2111
|
+
debug: true,
|
|
2112
|
+
};
|
|
2113
|
+
const client = quickbase(config);
|
|
2114
|
+
const tableId = "buwai2zr4";
|
|
2115
|
+
const appId = "buwai2zpe";
|
|
2116
|
+
|
|
2117
|
+
console.log("Config used:", config);
|
|
2118
|
+
const response = await client.getTable({ tableId, appId });
|
|
2119
|
+
expect(response).toBeDefined();
|
|
2120
|
+
expect(response.id).toBe(tableId);
|
|
2121
|
+
expect(response.name).toBe("Root"); // Expect original name
|
|
2122
|
+
expect(response.alias).toBe("_DBID_ROOT");
|
|
2123
|
+
expect(response.created).toBeInstanceOf(Date);
|
|
2124
|
+
console.log("Real API response:", response);
|
|
2125
|
+
}
|
|
2126
|
+
);
|
|
2127
|
+
- name: updateTable.test.ts
|
|
2128
|
+
type: file
|
|
2129
|
+
contents: |
|
|
2130
|
+
import { test, expect } from "vitest";
|
|
2131
|
+
import { quickbase } from "../../../../src/quickbaseClient";
|
|
2132
|
+
|
|
2133
|
+
test(
|
|
2134
|
+
"QuickbaseClient Integration - updateTable > updates real table data in QuickBase",
|
|
2135
|
+
{ timeout: 10000 },
|
|
2136
|
+
async () => {
|
|
2137
|
+
const config = {
|
|
2138
|
+
realm: process.env.QB_REALM || "",
|
|
2139
|
+
userToken: process.env.QB_USER_TOKEN || "",
|
|
2140
|
+
debug: true,
|
|
2141
|
+
};
|
|
2142
|
+
const client = quickbase(config);
|
|
2143
|
+
const appId = "buwai2zpe";
|
|
2144
|
+
const tableId = "buwai2zr4";
|
|
2145
|
+
const updatedBody = {
|
|
2146
|
+
name: "Root Updated " + Date.now(),
|
|
2147
|
+
description: "Integration test update",
|
|
2148
|
+
};
|
|
2149
|
+
const originalBody = {
|
|
2150
|
+
name: "Root",
|
|
2151
|
+
description: "",
|
|
2152
|
+
};
|
|
2153
|
+
|
|
2154
|
+
console.log("Config used:", config);
|
|
2155
|
+
// Update the table
|
|
2156
|
+
const response = await client.updateTable({
|
|
2157
|
+
tableId,
|
|
2158
|
+
appId,
|
|
2159
|
+
body: updatedBody,
|
|
2160
|
+
});
|
|
2161
|
+
expect(response).toBeDefined();
|
|
2162
|
+
expect(response.id).toBe(tableId);
|
|
2163
|
+
expect(response.name).toBe(updatedBody.name);
|
|
2164
|
+
expect(response.description).toBe(updatedBody.description);
|
|
2165
|
+
console.log("Real API response:", response);
|
|
2166
|
+
|
|
2167
|
+
// Cleanup: Revert the table to original state
|
|
2168
|
+
const cleanupResponse = await client.updateTable({
|
|
2169
|
+
tableId,
|
|
2170
|
+
appId,
|
|
2171
|
+
body: originalBody,
|
|
2172
|
+
});
|
|
2173
|
+
expect(cleanupResponse.name).toBe(originalBody.name);
|
|
2174
|
+
expect(cleanupResponse.description).toBe(originalBody.description);
|
|
2175
|
+
console.log("Cleanup API response:", cleanupResponse);
|
|
2176
|
+
}
|
|
2177
|
+
);
|
|
2178
|
+
- name: unit
|
|
2179
|
+
type: directory
|
|
2180
|
+
children:
|
|
2181
|
+
- name: apps
|
|
2182
|
+
type: directory
|
|
2183
|
+
children:
|
|
2184
|
+
- name: getApp.test.ts
|
|
2185
|
+
type: file
|
|
2186
|
+
contents: |
|
|
2187
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2188
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
2189
|
+
|
|
2190
|
+
describe("QuickbaseClient - getApp (Unit)", () => {
|
|
2191
|
+
const client = createClient(mockFetch);
|
|
2192
|
+
|
|
2193
|
+
beforeEach(() => {
|
|
2194
|
+
mockFetch.mockClear();
|
|
2195
|
+
});
|
|
2196
|
+
|
|
2197
|
+
it("initializes without errors", () => {
|
|
2198
|
+
expect(client).toBeDefined();
|
|
2199
|
+
});
|
|
2200
|
+
|
|
2201
|
+
it("has getApp method", () => {
|
|
2202
|
+
expect(typeof client.getApp).toBe("function");
|
|
2203
|
+
});
|
|
2204
|
+
|
|
2205
|
+
it("calls getApp successfully", async () => {
|
|
2206
|
+
mockFetch.mockImplementation((url: string, options: any) => {
|
|
2207
|
+
console.log("Mock fetch:", url, options);
|
|
2208
|
+
return Promise.resolve({
|
|
2209
|
+
ok: true,
|
|
2210
|
+
status: 200,
|
|
2211
|
+
json: () =>
|
|
2212
|
+
Promise.resolve({
|
|
2213
|
+
id: process.env.QB_APP_ID,
|
|
2214
|
+
name: "qb-copy",
|
|
2215
|
+
created: "2025-02-13T18:22:33Z",
|
|
2216
|
+
updated: "2025-03-04T04:25:51Z",
|
|
2217
|
+
description: "",
|
|
2218
|
+
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
2219
|
+
dateFormat: "MM-DD-YYYY",
|
|
2220
|
+
hasEveryoneOnTheInternet: false,
|
|
2221
|
+
memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
|
|
2222
|
+
securityProperties: {
|
|
2223
|
+
allowClone: false,
|
|
2224
|
+
allowExport: true,
|
|
2225
|
+
enableAppTokens: true,
|
|
2226
|
+
hideFromPublic: false,
|
|
2227
|
+
mustBeRealmApproved: false,
|
|
2228
|
+
useIPFilter: false,
|
|
2229
|
+
},
|
|
2230
|
+
}),
|
|
2231
|
+
} as Response);
|
|
2232
|
+
});
|
|
2233
|
+
|
|
2234
|
+
const getAppId = process.env.QB_APP_ID;
|
|
2235
|
+
if (!getAppId) throw new Error("QB_APP_ID is not defined in .env");
|
|
2236
|
+
console.log("Test appId:", getAppId);
|
|
2237
|
+
const result = await client.getApp({ appId: getAppId });
|
|
2238
|
+
expect(result).toEqual({
|
|
2239
|
+
id: getAppId,
|
|
2240
|
+
name: "qb-copy",
|
|
2241
|
+
created: new Date("2025-02-13T18:22:33Z"),
|
|
2242
|
+
updated: new Date("2025-03-04T04:25:51Z"),
|
|
2243
|
+
description: "",
|
|
2244
|
+
timeZone: "(UTC-08:00) Pacific Time (US & Canada)",
|
|
2245
|
+
dateFormat: "MM-DD-YYYY",
|
|
2246
|
+
hasEveryoneOnTheInternet: false,
|
|
2247
|
+
memoryInfo: { estMemory: 0, estMemoryInclDependentApps: 0 },
|
|
2248
|
+
securityProperties: {
|
|
2249
|
+
allowClone: false,
|
|
2250
|
+
allowExport: true,
|
|
2251
|
+
enableAppTokens: true,
|
|
2252
|
+
hideFromPublic: false,
|
|
2253
|
+
mustBeRealmApproved: false,
|
|
2254
|
+
useIPFilter: false,
|
|
2255
|
+
},
|
|
2256
|
+
});
|
|
2257
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
2258
|
+
`https://api.quickbase.com/v1/apps/${getAppId}`,
|
|
2259
|
+
expect.objectContaining({
|
|
2260
|
+
headers: expect.objectContaining({
|
|
2261
|
+
Authorization: `QB-USER-TOKEN ${process.env.QB_USER_TOKEN}`,
|
|
2262
|
+
"QB-Realm-Hostname": `${process.env.QB_REALM}.quickbase.com`,
|
|
2263
|
+
}),
|
|
2264
|
+
})
|
|
2265
|
+
);
|
|
2266
|
+
});
|
|
2267
|
+
});
|
|
2268
|
+
- name: auth
|
|
2269
|
+
type: directory
|
|
2270
|
+
children:
|
|
2271
|
+
- name: fetchTempToken401.test.ts
|
|
2272
|
+
type: file
|
|
2273
|
+
contents: |
|
|
2274
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2275
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
2276
|
+
|
|
2277
|
+
describe("QuickbaseClient - 401 with fetchTempToken 401", () => {
|
|
2278
|
+
let client: ReturnType<typeof createClient>;
|
|
2279
|
+
|
|
2280
|
+
beforeEach(() => {
|
|
2281
|
+
mockFetch.mockClear();
|
|
2282
|
+
client = createClient(mockFetch, { useTempTokens: true, debug: true });
|
|
2283
|
+
});
|
|
2284
|
+
|
|
2285
|
+
it("fails without infinite loop when fetchTempToken returns 401 after initial 401", async () => {
|
|
2286
|
+
const mockDbid = "mockDbid123";
|
|
2287
|
+
let callCount = 0;
|
|
2288
|
+
|
|
2289
|
+
mockFetch.mockImplementation((url) => {
|
|
2290
|
+
callCount++;
|
|
2291
|
+
console.log(`Mock fetch call ${callCount}: ${url}`);
|
|
2292
|
+
if (url.includes("auth/temporary") && callCount === 1) {
|
|
2293
|
+
return Promise.resolve({
|
|
2294
|
+
ok: true,
|
|
2295
|
+
status: 200,
|
|
2296
|
+
json: () =>
|
|
2297
|
+
Promise.resolve({ temporaryAuthorization: "initial_token" }),
|
|
2298
|
+
});
|
|
2299
|
+
}
|
|
2300
|
+
if (url.includes("fields") && callCount === 2) {
|
|
2301
|
+
return Promise.resolve({
|
|
2302
|
+
ok: false,
|
|
2303
|
+
status: 401,
|
|
2304
|
+
json: () => Promise.resolve({ message: "Unauthorized" }),
|
|
2305
|
+
});
|
|
2306
|
+
}
|
|
2307
|
+
if (url.includes("auth/temporary") && callCount === 3) {
|
|
2308
|
+
return Promise.resolve({
|
|
2309
|
+
ok: false,
|
|
2310
|
+
status: 401,
|
|
2311
|
+
json: () =>
|
|
2312
|
+
Promise.resolve({ message: "Unauthorized in fetchTempToken" }),
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
return Promise.reject(new Error(`Unexpected fetch call: ${url}`));
|
|
2316
|
+
});
|
|
2317
|
+
|
|
2318
|
+
const consoleSpy = vi.spyOn(console, "log");
|
|
2319
|
+
await expect(client.getFields({ tableId: mockDbid })).rejects.toThrow(
|
|
2320
|
+
"API Error: Unauthorized in fetchTempToken (Status: 401)"
|
|
2321
|
+
);
|
|
2322
|
+
|
|
2323
|
+
expect(mockFetch).toHaveBeenCalledTimes(3);
|
|
2324
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
2325
|
+
"Authorization error for getFields, refreshing token:",
|
|
2326
|
+
expect.any(String)
|
|
2327
|
+
);
|
|
2328
|
+
expect(consoleSpy).not.toHaveBeenCalledWith(
|
|
2329
|
+
"Retrying getFields with new token"
|
|
2330
|
+
);
|
|
2331
|
+
consoleSpy.mockRestore();
|
|
2332
|
+
});
|
|
2333
|
+
});
|
|
2334
|
+
- name: getTempToken.test.ts
|
|
2335
|
+
type: file
|
|
2336
|
+
contents: |
|
|
2337
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2338
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
2339
|
+
|
|
2340
|
+
describe("QuickbaseClient - getTempTokenDBID (Unit)", () => {
|
|
2341
|
+
let client: ReturnType<typeof createClient>;
|
|
2342
|
+
|
|
2343
|
+
beforeEach(() => {
|
|
2344
|
+
mockFetch.mockClear();
|
|
2345
|
+
client = createClient(mockFetch, { useTempTokens: true, debug: false });
|
|
2346
|
+
});
|
|
2347
|
+
|
|
2348
|
+
it("initializes without errors", () => {
|
|
2349
|
+
expect(client).toBeDefined();
|
|
2350
|
+
});
|
|
2351
|
+
|
|
2352
|
+
it("has getTempTokenDBID method", () => {
|
|
2353
|
+
expect(typeof client.getTempTokenDBID).toBe("function");
|
|
2354
|
+
});
|
|
2355
|
+
|
|
2356
|
+
it("fetches and caches temp token on first call", async () => {
|
|
2357
|
+
const mockDbid = "mockDbid123";
|
|
2358
|
+
const mockToken = "b123xyz_temp_token";
|
|
2359
|
+
|
|
2360
|
+
mockFetch.mockResolvedValueOnce({
|
|
2361
|
+
ok: true,
|
|
2362
|
+
status: 200,
|
|
2363
|
+
json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
|
|
2364
|
+
});
|
|
2365
|
+
|
|
2366
|
+
const result = await client.getTempTokenDBID({ dbid: mockDbid });
|
|
2367
|
+
expect(result).toEqual({ temporaryAuthorization: mockToken });
|
|
2368
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
2369
|
+
`https://api.quickbase.com/v1/auth/temporary/${mockDbid}`,
|
|
2370
|
+
expect.objectContaining({
|
|
2371
|
+
method: "GET",
|
|
2372
|
+
headers: expect.objectContaining({
|
|
2373
|
+
"QB-Realm-Hostname": `${process.env.QB_REALM}.quickbase.com`,
|
|
2374
|
+
"Content-Type": "application/json",
|
|
2375
|
+
}),
|
|
2376
|
+
credentials: "include",
|
|
2377
|
+
})
|
|
2378
|
+
);
|
|
2379
|
+
});
|
|
2380
|
+
|
|
2381
|
+
it("reuses cached temp token on second call", async () => {
|
|
2382
|
+
const mockDbid = "mockDbid123";
|
|
2383
|
+
const mockToken = "b123xyz_temp_token";
|
|
2384
|
+
|
|
2385
|
+
mockFetch.mockResolvedValueOnce({
|
|
2386
|
+
ok: true,
|
|
2387
|
+
status: 200,
|
|
2388
|
+
json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
|
|
2389
|
+
});
|
|
2390
|
+
|
|
2391
|
+
const firstResult = await client.getTempTokenDBID({ dbid: mockDbid });
|
|
2392
|
+
expect(firstResult).toEqual({ temporaryAuthorization: mockToken });
|
|
2393
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
2394
|
+
|
|
2395
|
+
mockFetch.mockClear();
|
|
2396
|
+
const secondResult = await client.getTempTokenDBID({ dbid: mockDbid });
|
|
2397
|
+
expect(secondResult).toEqual({ temporaryAuthorization: mockToken });
|
|
2398
|
+
expect(mockFetch).not.toHaveBeenCalled();
|
|
2399
|
+
});
|
|
2400
|
+
|
|
2401
|
+
it("handles API error", async () => {
|
|
2402
|
+
const mockDbid = "mockDbid123";
|
|
2403
|
+
|
|
2404
|
+
mockFetch.mockResolvedValueOnce({
|
|
2405
|
+
ok: false,
|
|
2406
|
+
status: 401,
|
|
2407
|
+
json: () => Promise.resolve({ message: "Unauthorized" }),
|
|
2408
|
+
});
|
|
2409
|
+
|
|
2410
|
+
await expect(client.getTempTokenDBID({ dbid: mockDbid })).rejects.toSatisfy(
|
|
2411
|
+
(error: Error) => {
|
|
2412
|
+
expect(error).toBeInstanceOf(Error);
|
|
2413
|
+
expect(error.message).toBe("API Error: Unauthorized (Status: 401)");
|
|
2414
|
+
return true;
|
|
2415
|
+
}
|
|
2416
|
+
);
|
|
2417
|
+
});
|
|
2418
|
+
});
|
|
2419
|
+
- name: retryOn401.test.ts
|
|
2420
|
+
type: file
|
|
2421
|
+
contents: |
|
|
2422
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2423
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
2424
|
+
|
|
2425
|
+
describe("QuickbaseClient - 401 Retry Creates New Token", () => {
|
|
2426
|
+
let client: ReturnType<typeof createClient>;
|
|
2427
|
+
|
|
2428
|
+
beforeEach(() => {
|
|
2429
|
+
mockFetch.mockClear();
|
|
2430
|
+
client = createClient(mockFetch, { useTempTokens: true, debug: true });
|
|
2431
|
+
});
|
|
2432
|
+
|
|
2433
|
+
it("creates a new token on 401 and retries successfully", async () => {
|
|
2434
|
+
const mockDbid = "mockDbid123";
|
|
2435
|
+
const mockToken = "new_token_456";
|
|
2436
|
+
const mockFields = [{ id: 1, label: "Field1" }];
|
|
2437
|
+
let callCount = 0;
|
|
2438
|
+
|
|
2439
|
+
mockFetch.mockImplementation((url) => {
|
|
2440
|
+
callCount++;
|
|
2441
|
+
console.log(`Mock fetch call ${callCount}: ${url}`);
|
|
2442
|
+
if (url.includes("auth/temporary") && callCount === 1) {
|
|
2443
|
+
return Promise.resolve({
|
|
2444
|
+
ok: true,
|
|
2445
|
+
status: 200,
|
|
2446
|
+
json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
if (url.includes("fields") && callCount === 2) {
|
|
2450
|
+
return Promise.resolve({
|
|
2451
|
+
ok: false,
|
|
2452
|
+
status: 401,
|
|
2453
|
+
text: () => Promise.resolve("Unauthorized"),
|
|
2454
|
+
});
|
|
2455
|
+
}
|
|
2456
|
+
if (url.includes("auth/temporary") && callCount === 3) {
|
|
2457
|
+
return Promise.resolve({
|
|
2458
|
+
ok: true,
|
|
2459
|
+
status: 200,
|
|
2460
|
+
json: () =>
|
|
2461
|
+
Promise.resolve({ temporaryAuthorization: mockToken + "_retry" }),
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
if (url.includes("fields") && callCount === 4) {
|
|
2465
|
+
return Promise.resolve({
|
|
2466
|
+
ok: true,
|
|
2467
|
+
status: 200,
|
|
2468
|
+
json: () => Promise.resolve(mockFields),
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
return Promise.reject(new Error(`Unexpected fetch call: ${url}`));
|
|
2472
|
+
});
|
|
2473
|
+
|
|
2474
|
+
const consoleSpy = vi.spyOn(console, "log");
|
|
2475
|
+
const result = await client.getFields({ tableId: mockDbid });
|
|
2476
|
+
|
|
2477
|
+
expect(result).toEqual(mockFields);
|
|
2478
|
+
expect(mockFetch).toHaveBeenCalledTimes(4);
|
|
2479
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
2480
|
+
"Authorization error for getFields, refreshing token:",
|
|
2481
|
+
expect.any(String)
|
|
2482
|
+
);
|
|
2483
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
2484
|
+
"Fetched and cached new token for dbid: mockDbid123",
|
|
2485
|
+
mockToken + "_retry",
|
|
2486
|
+
expect.any(String)
|
|
2487
|
+
);
|
|
2488
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
2489
|
+
"Retrying getFields with new token"
|
|
2490
|
+
);
|
|
2491
|
+
consoleSpy.mockRestore();
|
|
2492
|
+
});
|
|
2493
|
+
});
|
|
2494
|
+
- name: two401s.test.ts
|
|
2495
|
+
type: file
|
|
2496
|
+
contents: |
|
|
2497
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
2498
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
2499
|
+
|
|
2500
|
+
describe("QuickbaseClient - Two 401s in a Row", () => {
|
|
2501
|
+
let client: ReturnType<typeof createClient>;
|
|
2502
|
+
|
|
2503
|
+
beforeEach(() => {
|
|
2504
|
+
mockFetch.mockClear();
|
|
2505
|
+
client = createClient(mockFetch, { useTempTokens: true, debug: true });
|
|
2506
|
+
});
|
|
2507
|
+
|
|
2508
|
+
it("logs an error after two 401s in a row", async () => {
|
|
2509
|
+
const mockDbid = "mockDbid123";
|
|
2510
|
+
const mockToken = "new_token_456";
|
|
2511
|
+
let callCount = 0;
|
|
2512
|
+
|
|
2513
|
+
mockFetch.mockImplementation((url) => {
|
|
2514
|
+
callCount++;
|
|
2515
|
+
console.log(`Mock fetch call ${callCount}: ${url}`);
|
|
2516
|
+
if (url.includes("auth/temporary") && callCount === 1) {
|
|
2517
|
+
return Promise.resolve({
|
|
2518
|
+
ok: true,
|
|
2519
|
+
status: 200,
|
|
2520
|
+
json: () => Promise.resolve({ temporaryAuthorization: mockToken }),
|
|
2521
|
+
});
|
|
2522
|
+
}
|
|
2523
|
+
if (url.includes("fields") && callCount === 2) {
|
|
2524
|
+
return Promise.resolve({
|
|
2525
|
+
ok: false,
|
|
2526
|
+
status: 401,
|
|
2527
|
+
text: () => Promise.resolve("Unauthorized"),
|
|
2528
|
+
});
|
|
2529
|
+
}
|
|
2530
|
+
if (url.includes("auth/temporary") && callCount === 3) {
|
|
2531
|
+
return Promise.resolve({
|
|
2532
|
+
ok: true,
|
|
2533
|
+
status: 200,
|
|
2534
|
+
json: () =>
|
|
2535
|
+
Promise.resolve({ temporaryAuthorization: mockToken + "_retry" }),
|
|
2536
|
+
});
|
|
2537
|
+
}
|
|
2538
|
+
if (url.includes("fields") && callCount === 4) {
|
|
2539
|
+
return Promise.resolve({
|
|
2540
|
+
ok: false,
|
|
2541
|
+
status: 401,
|
|
2542
|
+
json: () => Promise.resolve({ message: "Unauthorized again" }), // Changed to json()
|
|
2543
|
+
text: () => Promise.resolve("Unauthorized again"), // Keep text() for fallback
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2546
|
+
return Promise.reject(new Error(`Unexpected fetch call: ${url}`));
|
|
2547
|
+
});
|
|
2548
|
+
|
|
2549
|
+
const consoleSpy = vi.spyOn(console, "log");
|
|
2550
|
+
await expect(client.getFields({ tableId: mockDbid })).rejects.toThrow(
|
|
2551
|
+
"API Error: Unauthorized again (Status: 401)"
|
|
2552
|
+
);
|
|
2553
|
+
|
|
2554
|
+
expect(mockFetch).toHaveBeenCalledTimes(4);
|
|
2555
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
2556
|
+
"Authorization error for getFields, refreshing token:",
|
|
2557
|
+
expect.any(String)
|
|
2558
|
+
);
|
|
2559
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
2560
|
+
"Fetched and cached new token for dbid: mockDbid123",
|
|
2561
|
+
mockToken + "_retry",
|
|
2562
|
+
expect.any(String)
|
|
2563
|
+
);
|
|
2564
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
2565
|
+
"Retrying getFields with new token"
|
|
2566
|
+
);
|
|
2567
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
2568
|
+
"Error response body for getFields:",
|
|
2569
|
+
{ message: "Unauthorized again" }
|
|
2570
|
+
);
|
|
2571
|
+
consoleSpy.mockRestore();
|
|
2572
|
+
});
|
|
2573
|
+
});
|
|
2574
|
+
- name: fields
|
|
2575
|
+
type: directory
|
|
2576
|
+
children:
|
|
2577
|
+
- name: getFields.test.ts
|
|
2578
|
+
type: file
|
|
2579
|
+
contents: |
|
|
2580
|
+
import { describe, it, expect } from "vitest";
|
|
2581
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
2582
|
+
|
|
2583
|
+
describe("QuickbaseClient - getFields (Unit)", () => {
|
|
2584
|
+
it("calls getFields successfully", async () => {
|
|
2585
|
+
mockFetch.mockImplementation((url: string, options: any) => {
|
|
2586
|
+
console.log("Mock fetch for getFields:", url, options);
|
|
2587
|
+
return Promise.resolve({
|
|
2588
|
+
ok: true,
|
|
2589
|
+
status: 200,
|
|
2590
|
+
json: () =>
|
|
2591
|
+
Promise.resolve([
|
|
2592
|
+
{
|
|
2593
|
+
id: 1,
|
|
2594
|
+
label: "Field1",
|
|
2595
|
+
fieldType: "text",
|
|
2596
|
+
noWrap: false,
|
|
2597
|
+
bold: false,
|
|
2598
|
+
required: false,
|
|
2599
|
+
appearsByDefault: false,
|
|
2600
|
+
findEnabled: false,
|
|
2601
|
+
unique: false,
|
|
2602
|
+
doesDataCopy: false,
|
|
2603
|
+
fieldHelp: "field help",
|
|
2604
|
+
audited: false,
|
|
2605
|
+
properties: {
|
|
2606
|
+
primaryKey: false,
|
|
2607
|
+
foreignKey: false,
|
|
2608
|
+
numLines: 1,
|
|
2609
|
+
maxLength: 0,
|
|
2610
|
+
appendOnly: false,
|
|
2611
|
+
allowHTML: false,
|
|
2612
|
+
allowMentions: false,
|
|
2613
|
+
sortAsGiven: false,
|
|
2614
|
+
carryChoices: true,
|
|
2615
|
+
allowNewChoices: false,
|
|
2616
|
+
formula: "",
|
|
2617
|
+
defaultValue: "",
|
|
2618
|
+
},
|
|
2619
|
+
permissions: [
|
|
2620
|
+
{ permissionType: "View", role: "Viewer", roleId: 10 },
|
|
2621
|
+
{ permissionType: "None", role: "Participant", roleId: 11 },
|
|
2622
|
+
{ permissionType: "Modify", role: "Administrator", roleId: 12 },
|
|
2623
|
+
],
|
|
2624
|
+
},
|
|
2625
|
+
]),
|
|
2626
|
+
} as Response);
|
|
2627
|
+
});
|
|
2628
|
+
|
|
2629
|
+
const client = createClient(mockFetch);
|
|
2630
|
+
const result = await client.getFields({
|
|
2631
|
+
tableId: "dummyTableId",
|
|
2632
|
+
includeFieldPerms: true,
|
|
2633
|
+
});
|
|
2634
|
+
console.log("getFields response:", result);
|
|
2635
|
+
expect(result).toEqual(
|
|
2636
|
+
expect.arrayContaining([
|
|
2637
|
+
expect.objectContaining({
|
|
2638
|
+
id: 1,
|
|
2639
|
+
label: "Field1",
|
|
2640
|
+
fieldType: "text",
|
|
2641
|
+
noWrap: false,
|
|
2642
|
+
bold: false,
|
|
2643
|
+
required: false,
|
|
2644
|
+
appearsByDefault: false,
|
|
2645
|
+
findEnabled: false,
|
|
2646
|
+
unique: false,
|
|
2647
|
+
doesDataCopy: false,
|
|
2648
|
+
fieldHelp: "field help",
|
|
2649
|
+
audited: false,
|
|
2650
|
+
properties: expect.objectContaining({
|
|
2651
|
+
primaryKey: false,
|
|
2652
|
+
foreignKey: false,
|
|
2653
|
+
numLines: 1,
|
|
2654
|
+
maxLength: 0,
|
|
2655
|
+
appendOnly: false,
|
|
2656
|
+
allowHTML: false,
|
|
2657
|
+
allowMentions: false,
|
|
2658
|
+
sortAsGiven: false,
|
|
2659
|
+
carryChoices: true,
|
|
2660
|
+
allowNewChoices: false,
|
|
2661
|
+
formula: "",
|
|
2662
|
+
defaultValue: "",
|
|
2663
|
+
}),
|
|
2664
|
+
permissions: expect.arrayContaining([
|
|
2665
|
+
expect.objectContaining({
|
|
2666
|
+
permissionType: "View",
|
|
2667
|
+
role: "Viewer",
|
|
2668
|
+
roleId: 10,
|
|
2669
|
+
}),
|
|
2670
|
+
expect.objectContaining({
|
|
2671
|
+
permissionType: "None",
|
|
2672
|
+
role: "Participant",
|
|
2673
|
+
roleId: 11,
|
|
2674
|
+
}),
|
|
2675
|
+
expect.objectContaining({
|
|
2676
|
+
permissionType: "Modify",
|
|
2677
|
+
role: "Administrator",
|
|
2678
|
+
roleId: 12,
|
|
2679
|
+
}),
|
|
2680
|
+
]),
|
|
2681
|
+
}),
|
|
2682
|
+
])
|
|
2683
|
+
);
|
|
2684
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
2685
|
+
`https://api.quickbase.com/v1/fields?tableId=dummyTableId&includeFieldPerms=true`,
|
|
2686
|
+
expect.objectContaining({
|
|
2687
|
+
headers: expect.objectContaining({
|
|
2688
|
+
Authorization: `QB-USER-TOKEN ${process.env.QB_USER_TOKEN}`,
|
|
2689
|
+
"QB-Realm-Hostname": `${process.env.QB_REALM}.quickbase.com`,
|
|
2690
|
+
}),
|
|
2691
|
+
})
|
|
2692
|
+
);
|
|
2693
|
+
});
|
|
2694
|
+
});
|
|
2695
|
+
- name: index.ts
|
|
2696
|
+
type: file
|
|
2697
|
+
contents: |
|
|
2698
|
+
// tests/unit/index.ts
|
|
2699
|
+
export * from "./apps/getApp.test.ts";
|
|
2700
|
+
export * from "./fields/getFields.test.ts";
|
|
2701
|
+
export * from "./tables/getAppTables.test.ts";
|
|
2702
|
+
- name: records
|
|
2703
|
+
type: directory
|
|
2704
|
+
children:
|
|
2705
|
+
- name: deleteRecords.test.ts
|
|
2706
|
+
type: file
|
|
2707
|
+
contents: |
|
|
2708
|
+
// tests/vitest/unit/records/deleteRecords.test.ts
|
|
2709
|
+
import { describe, expect, test, beforeEach } from "vitest"; // Added 'describe'
|
|
2710
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
2711
|
+
|
|
2712
|
+
describe("QuickbaseClient - deleteRecords (Unit)", () => {
|
|
2713
|
+
beforeEach(() => {
|
|
2714
|
+
mockFetch.mockClear(); // Clear mock state between tests
|
|
2715
|
+
});
|
|
2716
|
+
|
|
2717
|
+
test("deleteRecords - sends correct DELETE request and handles success", async () => {
|
|
2718
|
+
const qb = createClient(mockFetch, {
|
|
2719
|
+
realm: "test-realm",
|
|
2720
|
+
userToken: "test-token",
|
|
2721
|
+
});
|
|
2722
|
+
|
|
2723
|
+
mockFetch.mockResolvedValueOnce({
|
|
2724
|
+
ok: true,
|
|
2725
|
+
status: 200,
|
|
2726
|
+
json: () => Promise.resolve({ numberDeleted: 1 }),
|
|
2727
|
+
});
|
|
2728
|
+
|
|
2729
|
+
const result = await qb.deleteRecords({
|
|
2730
|
+
body: {
|
|
2731
|
+
from: "test-table-id",
|
|
2732
|
+
where: "{3.EX.'5'}", // Simulate deleting Record ID 5
|
|
2733
|
+
},
|
|
2734
|
+
});
|
|
2735
|
+
|
|
2736
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
2737
|
+
"https://api.quickbase.com/v1/records",
|
|
2738
|
+
expect.objectContaining({
|
|
2739
|
+
method: "DELETE",
|
|
2740
|
+
headers: expect.objectContaining({
|
|
2741
|
+
"QB-Realm-Hostname": "test-realm.quickbase.com",
|
|
2742
|
+
Authorization: "QB-USER-TOKEN test-token",
|
|
2743
|
+
"Content-Type": "application/json",
|
|
2744
|
+
}),
|
|
2745
|
+
body: JSON.stringify({ from: "test-table-id", where: "{3.EX.'5'}" }),
|
|
2746
|
+
})
|
|
2747
|
+
);
|
|
2748
|
+
expect(result).toEqual({ numberDeleted: 1 });
|
|
2749
|
+
});
|
|
2750
|
+
|
|
2751
|
+
test("deleteRecords - handles no records deleted", async () => {
|
|
2752
|
+
const qb = createClient(mockFetch, {
|
|
2753
|
+
realm: "test-realm",
|
|
2754
|
+
userToken: "test-token",
|
|
2755
|
+
});
|
|
2756
|
+
|
|
2757
|
+
mockFetch.mockResolvedValueOnce({
|
|
2758
|
+
ok: true,
|
|
2759
|
+
status: 200,
|
|
2760
|
+
json: () => Promise.resolve({ numberDeleted: 0 }),
|
|
2761
|
+
});
|
|
2762
|
+
|
|
2763
|
+
const result = await qb.deleteRecords({
|
|
2764
|
+
body: {
|
|
2765
|
+
from: "test-table-id",
|
|
2766
|
+
where: "{3.EX.'999999'}", // Non-existent Record ID
|
|
2767
|
+
},
|
|
2768
|
+
});
|
|
2769
|
+
|
|
2770
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
2771
|
+
"https://api.quickbase.com/v1/records",
|
|
2772
|
+
expect.objectContaining({
|
|
2773
|
+
method: "DELETE",
|
|
2774
|
+
headers: expect.objectContaining({
|
|
2775
|
+
"QB-Realm-Hostname": "test-realm.quickbase.com",
|
|
2776
|
+
Authorization: "QB-USER-TOKEN test-token",
|
|
2777
|
+
"Content-Type": "application/json",
|
|
2778
|
+
}),
|
|
2779
|
+
body: JSON.stringify({
|
|
2780
|
+
from: "test-table-id",
|
|
2781
|
+
where: "{3.EX.'999999'}",
|
|
2782
|
+
}),
|
|
2783
|
+
})
|
|
2784
|
+
);
|
|
2785
|
+
expect(result).toEqual({ numberDeleted: 0 });
|
|
2786
|
+
});
|
|
2787
|
+
|
|
2788
|
+
test("deleteRecords - throws error on API failure", async () => {
|
|
2789
|
+
const qb = createClient(mockFetch, {
|
|
2790
|
+
realm: "test-realm",
|
|
2791
|
+
userToken: "test-token",
|
|
2792
|
+
});
|
|
2793
|
+
|
|
2794
|
+
mockFetch.mockResolvedValueOnce({
|
|
2795
|
+
ok: false,
|
|
2796
|
+
status: 400,
|
|
2797
|
+
json: () => Promise.resolve({ message: "Invalid query" }),
|
|
2798
|
+
});
|
|
2799
|
+
|
|
2800
|
+
await expect(() =>
|
|
2801
|
+
qb.deleteRecords({
|
|
2802
|
+
body: {
|
|
2803
|
+
from: "test-table-id",
|
|
2804
|
+
where: "{3.EX.'invalid'}",
|
|
2805
|
+
},
|
|
2806
|
+
})
|
|
2807
|
+
).rejects.toThrow("API Error: Invalid query (Status: 400)");
|
|
2808
|
+
|
|
2809
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
2810
|
+
"https://api.quickbase.com/v1/records",
|
|
2811
|
+
expect.objectContaining({
|
|
2812
|
+
method: "DELETE",
|
|
2813
|
+
headers: expect.objectContaining({
|
|
2814
|
+
"QB-Realm-Hostname": "test-realm.quickbase.com",
|
|
2815
|
+
Authorization: "QB-USER-TOKEN test-token",
|
|
2816
|
+
"Content-Type": "application/json",
|
|
2817
|
+
}),
|
|
2818
|
+
body: JSON.stringify({
|
|
2819
|
+
from: "test-table-id",
|
|
2820
|
+
where: "{3.EX.'invalid'}",
|
|
2821
|
+
}),
|
|
2822
|
+
})
|
|
2823
|
+
);
|
|
2824
|
+
});
|
|
2825
|
+
});
|
|
2826
|
+
- name: upsert.test.ts
|
|
2827
|
+
type: file
|
|
2828
|
+
contents: |
|
|
2829
|
+
// tests/vitest/unit/records/upsert.test.ts
|
|
2830
|
+
import { describe, expect, test, beforeEach } from "vitest";
|
|
2831
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
2832
|
+
import { vi } from "vitest";
|
|
2833
|
+
|
|
2834
|
+
describe("QuickbaseClient - upsert (Unit)", () => {
|
|
2835
|
+
beforeEach(() => {
|
|
2836
|
+
vi.resetModules(); // Reset module cache
|
|
2837
|
+
mockFetch.mockClear();
|
|
2838
|
+
});
|
|
2839
|
+
|
|
2840
|
+
test("sends correct POST request and handles successful upsert", async () => {
|
|
2841
|
+
const qb = createClient(mockFetch, {
|
|
2842
|
+
realm: "test-realm",
|
|
2843
|
+
userToken: "test-token",
|
|
2844
|
+
debug: true,
|
|
2845
|
+
});
|
|
2846
|
+
|
|
2847
|
+
mockFetch.mockResolvedValueOnce({
|
|
2848
|
+
ok: true,
|
|
2849
|
+
status: 200,
|
|
2850
|
+
json: () =>
|
|
2851
|
+
Promise.resolve({
|
|
2852
|
+
data: [{ id: 1, "6": { value: "value1" } }],
|
|
2853
|
+
metadata: {
|
|
2854
|
+
createdRecordIds: [1],
|
|
2855
|
+
updatedRecordIds: [],
|
|
2856
|
+
unchangedRecordIds: [],
|
|
2857
|
+
totalNumberOfRecordsProcessed: 1,
|
|
2858
|
+
},
|
|
2859
|
+
}),
|
|
2860
|
+
});
|
|
2861
|
+
|
|
2862
|
+
console.log("[Test] Calling qb.upsert with:", {
|
|
2863
|
+
body: { to: "test-table-id", data: [{ "6": { value: "value1" } }] },
|
|
2864
|
+
});
|
|
2865
|
+
const result = await qb.upsert({
|
|
2866
|
+
body: { to: "test-table-id", data: [{ "6": { value: "value1" } }] },
|
|
2867
|
+
});
|
|
2868
|
+
|
|
2869
|
+
console.log("[Test] mockFetch calls:", mockFetch.mock.calls);
|
|
2870
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
2871
|
+
"https://api.quickbase.com/v1/records",
|
|
2872
|
+
expect.objectContaining({
|
|
2873
|
+
method: "POST",
|
|
2874
|
+
headers: expect.objectContaining({
|
|
2875
|
+
"QB-Realm-Hostname": "test-realm.quickbase.com",
|
|
2876
|
+
Authorization: "QB-USER-TOKEN test-token",
|
|
2877
|
+
"Content-Type": "application/json",
|
|
2878
|
+
}),
|
|
2879
|
+
body: JSON.stringify({
|
|
2880
|
+
to: "test-table-id",
|
|
2881
|
+
data: [{ "6": { value: "value1" } }],
|
|
2882
|
+
}),
|
|
2883
|
+
})
|
|
2884
|
+
);
|
|
2885
|
+
|
|
2886
|
+
expect(result).toEqual({
|
|
2887
|
+
data: [{ id: 1, "6": { value: "value1" } }],
|
|
2888
|
+
metadata: {
|
|
2889
|
+
createdRecordIds: [1],
|
|
2890
|
+
updatedRecordIds: [],
|
|
2891
|
+
unchangedRecordIds: [],
|
|
2892
|
+
totalNumberOfRecordsProcessed: 1,
|
|
2893
|
+
},
|
|
2894
|
+
});
|
|
2895
|
+
});
|
|
2896
|
+
|
|
2897
|
+
test("handles API error with invalid data", async () => {
|
|
2898
|
+
const qb = createClient(mockFetch, {
|
|
2899
|
+
realm: "test-realm",
|
|
2900
|
+
userToken: "test-token",
|
|
2901
|
+
debug: true,
|
|
2902
|
+
});
|
|
2903
|
+
|
|
2904
|
+
mockFetch.mockResolvedValueOnce({
|
|
2905
|
+
ok: false,
|
|
2906
|
+
status: 400,
|
|
2907
|
+
json: () => Promise.resolve({ message: "Invalid data format" }),
|
|
2908
|
+
});
|
|
2909
|
+
|
|
2910
|
+
await expect(
|
|
2911
|
+
qb.upsert({
|
|
2912
|
+
body: { to: "test-table-id", data: [{ "999": { value: "invalid" } }] },
|
|
2913
|
+
})
|
|
2914
|
+
).rejects.toThrow("API Error: Invalid data format (Status: 400)");
|
|
2915
|
+
|
|
2916
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
2917
|
+
"https://api.quickbase.com/v1/records",
|
|
2918
|
+
expect.objectContaining({
|
|
2919
|
+
method: "POST",
|
|
2920
|
+
headers: expect.objectContaining({
|
|
2921
|
+
"QB-Realm-Hostname": "test-realm.quickbase.com",
|
|
2922
|
+
Authorization: "QB-USER-TOKEN test-token",
|
|
2923
|
+
"Content-Type": "application/json",
|
|
2924
|
+
}),
|
|
2925
|
+
body: JSON.stringify({
|
|
2926
|
+
to: "test-table-id",
|
|
2927
|
+
data: [{ "999": { value: "invalid" } }],
|
|
2928
|
+
}),
|
|
2929
|
+
})
|
|
2930
|
+
);
|
|
2931
|
+
});
|
|
2932
|
+
|
|
2933
|
+
test("handles upsert with temp token", async () => {
|
|
2934
|
+
const qb = createClient(mockFetch, {
|
|
2935
|
+
realm: "test-realm",
|
|
2936
|
+
useTempTokens: true,
|
|
2937
|
+
debug: true,
|
|
2938
|
+
});
|
|
2939
|
+
|
|
2940
|
+
mockFetch
|
|
2941
|
+
.mockResolvedValueOnce({
|
|
2942
|
+
ok: true,
|
|
2943
|
+
status: 200,
|
|
2944
|
+
json: () => Promise.resolve({ temporaryAuthorization: "temp-token" }),
|
|
2945
|
+
})
|
|
2946
|
+
.mockResolvedValueOnce({
|
|
2947
|
+
ok: true,
|
|
2948
|
+
status: 200,
|
|
2949
|
+
json: () =>
|
|
2950
|
+
Promise.resolve({
|
|
2951
|
+
data: [{ id: 2, "7": { value: "value2" } }],
|
|
2952
|
+
metadata: {
|
|
2953
|
+
createdRecordIds: [2],
|
|
2954
|
+
updatedRecordIds: [],
|
|
2955
|
+
unchangedRecordIds: [],
|
|
2956
|
+
totalNumberOfRecordsProcessed: 1,
|
|
2957
|
+
},
|
|
2958
|
+
}),
|
|
2959
|
+
});
|
|
2960
|
+
|
|
2961
|
+
const result = await qb.upsert({
|
|
2962
|
+
body: { to: "test-table-id", data: [{ "7": { value: "value2" } }] },
|
|
2963
|
+
dbid: "test-dbid",
|
|
2964
|
+
});
|
|
2965
|
+
|
|
2966
|
+
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
2967
|
+
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
2968
|
+
1,
|
|
2969
|
+
"https://api.quickbase.com/v1/auth/temporary/test-dbid",
|
|
2970
|
+
expect.objectContaining({
|
|
2971
|
+
method: "GET",
|
|
2972
|
+
headers: expect.objectContaining({
|
|
2973
|
+
"QB-Realm-Hostname": "test-realm.quickbase.com",
|
|
2974
|
+
"Content-Type": "application/json",
|
|
2975
|
+
}),
|
|
2976
|
+
credentials: "include",
|
|
2977
|
+
})
|
|
2978
|
+
);
|
|
2979
|
+
expect(mockFetch).toHaveBeenNthCalledWith(
|
|
2980
|
+
2,
|
|
2981
|
+
"https://api.quickbase.com/v1/records",
|
|
2982
|
+
expect.objectContaining({
|
|
2983
|
+
method: "POST",
|
|
2984
|
+
headers: expect.objectContaining({
|
|
2985
|
+
"QB-Realm-Hostname": "test-realm.quickbase.com",
|
|
2986
|
+
Authorization: "QB-TEMP-TOKEN temp-token",
|
|
2987
|
+
"Content-Type": "application/json",
|
|
2988
|
+
}),
|
|
2989
|
+
body: JSON.stringify({
|
|
2990
|
+
to: "test-table-id",
|
|
2991
|
+
data: [{ "7": { value: "value2" } }],
|
|
2992
|
+
}),
|
|
2993
|
+
})
|
|
2994
|
+
);
|
|
2995
|
+
|
|
2996
|
+
expect(result).toEqual({
|
|
2997
|
+
data: [{ id: 2, "7": { value: "value2" } }],
|
|
2998
|
+
metadata: {
|
|
2999
|
+
createdRecordIds: [2],
|
|
3000
|
+
updatedRecordIds: [],
|
|
3001
|
+
unchangedRecordIds: [],
|
|
3002
|
+
totalNumberOfRecordsProcessed: 1,
|
|
3003
|
+
},
|
|
3004
|
+
});
|
|
3005
|
+
});
|
|
3006
|
+
|
|
3007
|
+
test("sends correct POST request with data fields", async () => {
|
|
3008
|
+
const qb = createClient(mockFetch, {
|
|
3009
|
+
realm: "test-realm",
|
|
3010
|
+
userToken: "test-token",
|
|
3011
|
+
debug: true,
|
|
3012
|
+
});
|
|
3013
|
+
|
|
3014
|
+
mockFetch.mockResolvedValueOnce({
|
|
3015
|
+
ok: true,
|
|
3016
|
+
status: 200,
|
|
3017
|
+
json: () =>
|
|
3018
|
+
Promise.resolve({
|
|
3019
|
+
data: [{ id: 1, "6": { value: "value1" } }],
|
|
3020
|
+
metadata: {
|
|
3021
|
+
createdRecordIds: [1],
|
|
3022
|
+
updatedRecordIds: [],
|
|
3023
|
+
unchangedRecordIds: [],
|
|
3024
|
+
totalNumberOfRecordsProcessed: 1,
|
|
3025
|
+
},
|
|
3026
|
+
}),
|
|
3027
|
+
});
|
|
3028
|
+
|
|
3029
|
+
const result = await qb.upsert({
|
|
3030
|
+
body: { to: "test-table-id", data: [{ "6": { value: "value1" } }] },
|
|
3031
|
+
});
|
|
3032
|
+
|
|
3033
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3034
|
+
"https://api.quickbase.com/v1/records",
|
|
3035
|
+
expect.objectContaining({
|
|
3036
|
+
method: "POST",
|
|
3037
|
+
headers: expect.objectContaining({
|
|
3038
|
+
"QB-Realm-Hostname": "test-realm.quickbase.com",
|
|
3039
|
+
Authorization: "QB-USER-TOKEN test-token",
|
|
3040
|
+
"Content-Type": "application/json",
|
|
3041
|
+
}),
|
|
3042
|
+
body: JSON.stringify({
|
|
3043
|
+
to: "test-table-id",
|
|
3044
|
+
data: [{ "6": { value: "value1" } }],
|
|
3045
|
+
}),
|
|
3046
|
+
})
|
|
3047
|
+
);
|
|
3048
|
+
|
|
3049
|
+
expect(result.data[0]["6"].value).toBe("value1");
|
|
3050
|
+
});
|
|
3051
|
+
});
|
|
3052
|
+
- name: tables
|
|
3053
|
+
type: directory
|
|
3054
|
+
children:
|
|
3055
|
+
- name: createTable.test.ts
|
|
3056
|
+
type: file
|
|
3057
|
+
contents: |
|
|
3058
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
3059
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
3060
|
+
|
|
3061
|
+
describe("QuickbaseClient - createTable (Unit)", () => {
|
|
3062
|
+
let client: ReturnType<typeof createClient>;
|
|
3063
|
+
|
|
3064
|
+
beforeEach(() => {
|
|
3065
|
+
mockFetch.mockClear();
|
|
3066
|
+
client = createClient(mockFetch, { debug: true });
|
|
3067
|
+
});
|
|
3068
|
+
|
|
3069
|
+
it("calls createTable successfully with user token", async () => {
|
|
3070
|
+
const appId = "buwai2zpe";
|
|
3071
|
+
const mockBody = {
|
|
3072
|
+
name: "TestTable",
|
|
3073
|
+
description: "Unit test table",
|
|
3074
|
+
singleRecordName: "Test",
|
|
3075
|
+
pluralRecordName: "Tests",
|
|
3076
|
+
};
|
|
3077
|
+
const mockResponse = {
|
|
3078
|
+
id: "buya8h9iz",
|
|
3079
|
+
name: "TestTable",
|
|
3080
|
+
alias: "_DBID_TESTTABLE",
|
|
3081
|
+
description: "Unit test table",
|
|
3082
|
+
created: new Date("2025-03-10T21:00:00.000Z"),
|
|
3083
|
+
updated: new Date("2025-03-10T21:00:00.000Z"),
|
|
3084
|
+
nextRecordId: 1,
|
|
3085
|
+
nextFieldId: 6,
|
|
3086
|
+
defaultSortFieldId: 2,
|
|
3087
|
+
defaultSortOrder: "DESC",
|
|
3088
|
+
keyFieldId: 3,
|
|
3089
|
+
singleRecordName: "Test",
|
|
3090
|
+
pluralRecordName: "Tests",
|
|
3091
|
+
sizeLimit: "500 MB",
|
|
3092
|
+
spaceUsed: "0 KB",
|
|
3093
|
+
spaceRemaining: "500 MB",
|
|
3094
|
+
};
|
|
3095
|
+
|
|
3096
|
+
mockFetch.mockResolvedValueOnce({
|
|
3097
|
+
ok: true,
|
|
3098
|
+
status: 200,
|
|
3099
|
+
json: () => Promise.resolve(mockResponse),
|
|
3100
|
+
});
|
|
3101
|
+
|
|
3102
|
+
const response = await client.createTable({ appId, body: mockBody });
|
|
3103
|
+
expect(response).toEqual(mockResponse);
|
|
3104
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
3105
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3106
|
+
`https://api.quickbase.com/v1/tables?appId=${appId}`,
|
|
3107
|
+
expect.objectContaining({
|
|
3108
|
+
method: "POST",
|
|
3109
|
+
headers: expect.objectContaining({
|
|
3110
|
+
"Content-Type": "application/json",
|
|
3111
|
+
"QB-Realm-Hostname": "builderprogram-dbradford6815.quickbase.com",
|
|
3112
|
+
Authorization:
|
|
3113
|
+
"QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
|
|
3114
|
+
}),
|
|
3115
|
+
body: JSON.stringify(mockBody),
|
|
3116
|
+
})
|
|
3117
|
+
);
|
|
3118
|
+
});
|
|
3119
|
+
});
|
|
3120
|
+
- name: deleteTable.test.ts
|
|
3121
|
+
type: file
|
|
3122
|
+
contents: |
|
|
3123
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
3124
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
3125
|
+
|
|
3126
|
+
describe("QuickbaseClient - deleteTable (Unit)", () => {
|
|
3127
|
+
let client: ReturnType<typeof createClient>;
|
|
3128
|
+
|
|
3129
|
+
beforeEach(() => {
|
|
3130
|
+
mockFetch.mockClear();
|
|
3131
|
+
client = createClient(mockFetch, { debug: true });
|
|
3132
|
+
});
|
|
3133
|
+
|
|
3134
|
+
it("calls deleteTable successfully with user token", async () => {
|
|
3135
|
+
const appId = "buwai2zpe";
|
|
3136
|
+
const tableId = "buya8h9iz";
|
|
3137
|
+
const mockResponse = {
|
|
3138
|
+
deletedTableId: tableId,
|
|
3139
|
+
};
|
|
3140
|
+
|
|
3141
|
+
mockFetch.mockResolvedValueOnce({
|
|
3142
|
+
ok: true,
|
|
3143
|
+
status: 200,
|
|
3144
|
+
json: () => Promise.resolve(mockResponse),
|
|
3145
|
+
});
|
|
3146
|
+
|
|
3147
|
+
const response = await client.deleteTable({ tableId, appId });
|
|
3148
|
+
expect(response).toEqual(mockResponse);
|
|
3149
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
3150
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3151
|
+
`https://api.quickbase.com/v1/tables/${tableId}?appId=${appId}`,
|
|
3152
|
+
expect.objectContaining({
|
|
3153
|
+
method: "DELETE",
|
|
3154
|
+
headers: expect.objectContaining({
|
|
3155
|
+
"Content-Type": "application/json",
|
|
3156
|
+
"QB-Realm-Hostname": "builderprogram-dbradford6815.quickbase.com",
|
|
3157
|
+
Authorization:
|
|
3158
|
+
"QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
|
|
3159
|
+
}),
|
|
3160
|
+
})
|
|
3161
|
+
);
|
|
3162
|
+
});
|
|
3163
|
+
|
|
3164
|
+
it("handles 404 error for non-existent table", async () => {
|
|
3165
|
+
const appId = "buwai2zpe";
|
|
3166
|
+
const tableId = "nonexistent";
|
|
3167
|
+
|
|
3168
|
+
mockFetch.mockResolvedValueOnce({
|
|
3169
|
+
ok: false,
|
|
3170
|
+
status: 404,
|
|
3171
|
+
json: () =>
|
|
3172
|
+
Promise.resolve({
|
|
3173
|
+
message: "Invalid DBID",
|
|
3174
|
+
description: "Table not found in app.",
|
|
3175
|
+
}),
|
|
3176
|
+
});
|
|
3177
|
+
|
|
3178
|
+
await expect(client.deleteTable({ tableId, appId })).rejects.toThrow(
|
|
3179
|
+
"API Error: Invalid DBID (Status: 404)"
|
|
3180
|
+
);
|
|
3181
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
3182
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3183
|
+
`https://api.quickbase.com/v1/tables/${tableId}?appId=${appId}`,
|
|
3184
|
+
expect.objectContaining({
|
|
3185
|
+
method: "DELETE",
|
|
3186
|
+
headers: expect.any(Object),
|
|
3187
|
+
})
|
|
3188
|
+
);
|
|
3189
|
+
});
|
|
3190
|
+
});
|
|
3191
|
+
- name: getAppTables.test.ts
|
|
3192
|
+
type: file
|
|
3193
|
+
contents: |
|
|
3194
|
+
import { describe, it, expect } from "vitest";
|
|
3195
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
3196
|
+
|
|
3197
|
+
describe("QuickbaseClient - getAppTables (Unit)", () => {
|
|
3198
|
+
it("calls getAppTables successfully", async () => {
|
|
3199
|
+
mockFetch.mockImplementation((url: string, options: any) => {
|
|
3200
|
+
console.log("Mock fetch for getAppTables:", url, options);
|
|
3201
|
+
return Promise.resolve({
|
|
3202
|
+
ok: true,
|
|
3203
|
+
status: 200,
|
|
3204
|
+
json: () =>
|
|
3205
|
+
Promise.resolve([
|
|
3206
|
+
{
|
|
3207
|
+
alias: "_DBID_ROOT",
|
|
3208
|
+
created: "2025-02-13T18:22:33Z",
|
|
3209
|
+
defaultSortFieldId: 2,
|
|
3210
|
+
defaultSortOrder: "DESC",
|
|
3211
|
+
description: "",
|
|
3212
|
+
id: "buwai2zr4",
|
|
3213
|
+
keyFieldId: 3,
|
|
3214
|
+
name: "Root",
|
|
3215
|
+
nextFieldId: 6,
|
|
3216
|
+
nextRecordId: 1,
|
|
3217
|
+
pluralRecordName: "Roots",
|
|
3218
|
+
singleRecordName: "Root",
|
|
3219
|
+
sizeLimit: "500 MB",
|
|
3220
|
+
spaceRemaining: "500 MB",
|
|
3221
|
+
spaceUsed: "0 KB",
|
|
3222
|
+
updated: "2025-02-13T18:22:34Z",
|
|
3223
|
+
},
|
|
3224
|
+
]),
|
|
3225
|
+
} as Response);
|
|
3226
|
+
});
|
|
3227
|
+
|
|
3228
|
+
const client = createClient(mockFetch);
|
|
3229
|
+
const tablesAppId = process.env.QB_APP_ID;
|
|
3230
|
+
if (!tablesAppId) throw new Error("QB_APP_ID is not defined in .env");
|
|
3231
|
+
const result = await client.getAppTables({ appId: tablesAppId });
|
|
3232
|
+
console.log("getAppTables response:", result);
|
|
3233
|
+
expect(result).toEqual(
|
|
3234
|
+
expect.arrayContaining([
|
|
3235
|
+
expect.objectContaining({
|
|
3236
|
+
alias: "_DBID_ROOT",
|
|
3237
|
+
created: new Date("2025-02-13T18:22:33Z"),
|
|
3238
|
+
defaultSortFieldId: 2,
|
|
3239
|
+
defaultSortOrder: "DESC",
|
|
3240
|
+
description: "",
|
|
3241
|
+
id: "buwai2zr4",
|
|
3242
|
+
keyFieldId: 3,
|
|
3243
|
+
name: "Root",
|
|
3244
|
+
nextFieldId: 6,
|
|
3245
|
+
nextRecordId: 1,
|
|
3246
|
+
pluralRecordName: "Roots",
|
|
3247
|
+
singleRecordName: "Root",
|
|
3248
|
+
sizeLimit: "500 MB",
|
|
3249
|
+
spaceRemaining: "500 MB",
|
|
3250
|
+
spaceUsed: "0 KB",
|
|
3251
|
+
updated: new Date("2025-02-13T18:22:34Z"),
|
|
3252
|
+
}),
|
|
3253
|
+
])
|
|
3254
|
+
);
|
|
3255
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3256
|
+
`https://api.quickbase.com/v1/tables?appId=${tablesAppId}`,
|
|
3257
|
+
expect.objectContaining({
|
|
3258
|
+
headers: expect.objectContaining({
|
|
3259
|
+
Authorization: `QB-USER-TOKEN ${process.env.QB_USER_TOKEN}`,
|
|
3260
|
+
"QB-Realm-Hostname": `${process.env.QB_REALM}.quickbase.com`,
|
|
3261
|
+
}),
|
|
3262
|
+
})
|
|
3263
|
+
);
|
|
3264
|
+
});
|
|
3265
|
+
});
|
|
3266
|
+
- name: getTable.test.ts
|
|
3267
|
+
type: file
|
|
3268
|
+
contents: |
|
|
3269
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
3270
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
3271
|
+
|
|
3272
|
+
describe("QuickbaseClient - getTable (Unit)", () => {
|
|
3273
|
+
let client: ReturnType<typeof createClient>;
|
|
3274
|
+
|
|
3275
|
+
beforeEach(() => {
|
|
3276
|
+
mockFetch.mockClear();
|
|
3277
|
+
client = createClient(mockFetch, { debug: true });
|
|
3278
|
+
});
|
|
3279
|
+
|
|
3280
|
+
it("calls getTable successfully with user token", async () => {
|
|
3281
|
+
const mockAppId = "buwai2zpe";
|
|
3282
|
+
const mockTableId = "buwai2zr4";
|
|
3283
|
+
const mockResponse = {
|
|
3284
|
+
id: mockTableId,
|
|
3285
|
+
name: "Root",
|
|
3286
|
+
alias: "_DBID_ROOT",
|
|
3287
|
+
description: "",
|
|
3288
|
+
created: new Date("2025-02-13T18:22:33.000Z"),
|
|
3289
|
+
updated: new Date("2025-02-13T18:22:34.000Z"),
|
|
3290
|
+
nextRecordId: 1,
|
|
3291
|
+
nextFieldId: 6,
|
|
3292
|
+
defaultSortFieldId: 2,
|
|
3293
|
+
defaultSortOrder: "DESC",
|
|
3294
|
+
keyFieldId: 3,
|
|
3295
|
+
singleRecordName: "Root",
|
|
3296
|
+
pluralRecordName: "Roots",
|
|
3297
|
+
sizeLimit: "500 MB",
|
|
3298
|
+
spaceUsed: "0 KB",
|
|
3299
|
+
spaceRemaining: "500 MB",
|
|
3300
|
+
};
|
|
3301
|
+
|
|
3302
|
+
mockFetch.mockResolvedValueOnce({
|
|
3303
|
+
ok: true,
|
|
3304
|
+
status: 200,
|
|
3305
|
+
json: () => Promise.resolve(mockResponse),
|
|
3306
|
+
});
|
|
3307
|
+
|
|
3308
|
+
const response = await client.getTable({
|
|
3309
|
+
tableId: mockTableId,
|
|
3310
|
+
appId: mockAppId,
|
|
3311
|
+
});
|
|
3312
|
+
expect(response).toEqual(mockResponse);
|
|
3313
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3314
|
+
`https://api.quickbase.com/v1/tables/${mockTableId}?appId=${mockAppId}`,
|
|
3315
|
+
expect.objectContaining({
|
|
3316
|
+
method: "GET",
|
|
3317
|
+
headers: expect.objectContaining({
|
|
3318
|
+
Authorization:
|
|
3319
|
+
"QB-USER-TOKEN b9f3pk_q4jd_0_b4qu5eebyvuix3xs57ysd7zn3",
|
|
3320
|
+
}),
|
|
3321
|
+
})
|
|
3322
|
+
);
|
|
3323
|
+
});
|
|
3324
|
+
|
|
3325
|
+
it("calls getTable successfully with temp token", async () => {
|
|
3326
|
+
client = createClient(mockFetch, { debug: true, useTempTokens: true });
|
|
3327
|
+
const mockAppId = "buwai2zpe";
|
|
3328
|
+
const mockTableId = "buwai2zr4";
|
|
3329
|
+
const mockResponse = {
|
|
3330
|
+
id: mockTableId,
|
|
3331
|
+
name: "Root",
|
|
3332
|
+
alias: "_DBID_ROOT",
|
|
3333
|
+
description: "",
|
|
3334
|
+
created: new Date("2025-02-13T18:22:33.000Z"),
|
|
3335
|
+
updated: new Date("2025-02-13T18:22:34.000Z"),
|
|
3336
|
+
nextRecordId: 1,
|
|
3337
|
+
nextFieldId: 6,
|
|
3338
|
+
defaultSortFieldId: 2,
|
|
3339
|
+
defaultSortOrder: "DESC",
|
|
3340
|
+
keyFieldId: 3,
|
|
3341
|
+
singleRecordName: "Root",
|
|
3342
|
+
pluralRecordName: "Roots",
|
|
3343
|
+
sizeLimit: "500 MB",
|
|
3344
|
+
spaceUsed: "0 KB",
|
|
3345
|
+
spaceRemaining: "500 MB",
|
|
3346
|
+
};
|
|
3347
|
+
|
|
3348
|
+
mockFetch
|
|
3349
|
+
.mockResolvedValueOnce({
|
|
3350
|
+
ok: true,
|
|
3351
|
+
status: 200,
|
|
3352
|
+
json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
|
|
3353
|
+
})
|
|
3354
|
+
.mockResolvedValueOnce({
|
|
3355
|
+
ok: true,
|
|
3356
|
+
status: 200,
|
|
3357
|
+
json: () => Promise.resolve(mockResponse),
|
|
3358
|
+
});
|
|
3359
|
+
|
|
3360
|
+
const response = await client.getTable({
|
|
3361
|
+
tableId: mockTableId,
|
|
3362
|
+
appId: mockAppId,
|
|
3363
|
+
});
|
|
3364
|
+
expect(response).toEqual(mockResponse);
|
|
3365
|
+
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
3366
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3367
|
+
`https://api.quickbase.com/v1/auth/temporary/${mockTableId}`,
|
|
3368
|
+
expect.any(Object)
|
|
3369
|
+
);
|
|
3370
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3371
|
+
`https://api.quickbase.com/v1/tables/${mockTableId}?appId=${mockAppId}`,
|
|
3372
|
+
expect.objectContaining({
|
|
3373
|
+
headers: expect.objectContaining({
|
|
3374
|
+
Authorization: "QB-TEMP-TOKEN temp_token",
|
|
3375
|
+
}),
|
|
3376
|
+
})
|
|
3377
|
+
);
|
|
3378
|
+
});
|
|
3379
|
+
|
|
3380
|
+
it("retries successfully after 401 with temp token", async () => {
|
|
3381
|
+
client = createClient(mockFetch, { debug: true, useTempTokens: true });
|
|
3382
|
+
const mockAppId = "buwai2zpe";
|
|
3383
|
+
const mockTableId = "buwai2zr4";
|
|
3384
|
+
const mockResponse = {
|
|
3385
|
+
id: mockTableId,
|
|
3386
|
+
name: "Root",
|
|
3387
|
+
alias: "_DBID_ROOT",
|
|
3388
|
+
description: "",
|
|
3389
|
+
created: new Date("2025-02-13T18:22:33.000Z"),
|
|
3390
|
+
updated: new Date("2025-02-13T18:22:34.000Z"),
|
|
3391
|
+
nextRecordId: 1,
|
|
3392
|
+
nextFieldId: 6,
|
|
3393
|
+
defaultSortFieldId: 2,
|
|
3394
|
+
defaultSortOrder: "DESC",
|
|
3395
|
+
keyFieldId: 3,
|
|
3396
|
+
singleRecordName: "Root",
|
|
3397
|
+
pluralRecordName: "Roots",
|
|
3398
|
+
sizeLimit: "500 MB",
|
|
3399
|
+
spaceUsed: "0 KB",
|
|
3400
|
+
spaceRemaining: "500 MB",
|
|
3401
|
+
};
|
|
3402
|
+
|
|
3403
|
+
mockFetch
|
|
3404
|
+
.mockResolvedValueOnce({
|
|
3405
|
+
ok: true,
|
|
3406
|
+
status: 200,
|
|
3407
|
+
json: () =>
|
|
3408
|
+
Promise.resolve({ temporaryAuthorization: "initial_token" }),
|
|
3409
|
+
})
|
|
3410
|
+
.mockResolvedValueOnce({
|
|
3411
|
+
ok: false,
|
|
3412
|
+
status: 401,
|
|
3413
|
+
json: () => Promise.resolve({ message: "Unauthorized" }),
|
|
3414
|
+
})
|
|
3415
|
+
.mockResolvedValueOnce({
|
|
3416
|
+
ok: true,
|
|
3417
|
+
status: 200,
|
|
3418
|
+
json: () => Promise.resolve({ temporaryAuthorization: "new_token" }),
|
|
3419
|
+
})
|
|
3420
|
+
.mockResolvedValueOnce({
|
|
3421
|
+
ok: true,
|
|
3422
|
+
status: 200,
|
|
3423
|
+
json: () => Promise.resolve(mockResponse),
|
|
3424
|
+
});
|
|
3425
|
+
|
|
3426
|
+
const response = await client.getTable({
|
|
3427
|
+
tableId: mockTableId,
|
|
3428
|
+
appId: mockAppId,
|
|
3429
|
+
});
|
|
3430
|
+
expect(response).toEqual(mockResponse);
|
|
3431
|
+
expect(mockFetch).toHaveBeenCalledTimes(4); // Initial token, 401, retry token, success
|
|
3432
|
+
});
|
|
3433
|
+
|
|
3434
|
+
it("handles 401 with failed temp token retry", async () => {
|
|
3435
|
+
client = createClient(mockFetch, { debug: true, useTempTokens: true });
|
|
3436
|
+
const mockAppId = "buwai2zpe";
|
|
3437
|
+
const mockTableId = "buwai2zr4";
|
|
3438
|
+
|
|
3439
|
+
mockFetch
|
|
3440
|
+
.mockResolvedValueOnce({
|
|
3441
|
+
ok: true,
|
|
3442
|
+
status: 200,
|
|
3443
|
+
json: () =>
|
|
3444
|
+
Promise.resolve({ temporaryAuthorization: "initial_token" }),
|
|
3445
|
+
})
|
|
3446
|
+
.mockResolvedValueOnce({
|
|
3447
|
+
ok: false,
|
|
3448
|
+
status: 401,
|
|
3449
|
+
json: () => Promise.resolve({ message: "Unauthorized" }),
|
|
3450
|
+
})
|
|
3451
|
+
.mockResolvedValueOnce({
|
|
3452
|
+
ok: false,
|
|
3453
|
+
status: 401,
|
|
3454
|
+
json: () =>
|
|
3455
|
+
Promise.resolve({ message: "Unauthorized in fetchTempToken" }),
|
|
3456
|
+
});
|
|
3457
|
+
|
|
3458
|
+
await expect(
|
|
3459
|
+
client.getTable({ tableId: mockTableId, appId: mockAppId })
|
|
3460
|
+
).rejects.toThrow(
|
|
3461
|
+
"API Error: Unauthorized in fetchTempToken (Status: 401)"
|
|
3462
|
+
);
|
|
3463
|
+
expect(mockFetch).toHaveBeenCalledTimes(3);
|
|
3464
|
+
});
|
|
3465
|
+
|
|
3466
|
+
it("handles 404 Not Found", async () => {
|
|
3467
|
+
const mockAppId = "buwai2zpe";
|
|
3468
|
+
const mockTableId = "invalidTableId";
|
|
3469
|
+
|
|
3470
|
+
mockFetch.mockResolvedValueOnce({
|
|
3471
|
+
ok: false,
|
|
3472
|
+
status: 404,
|
|
3473
|
+
json: () => Promise.resolve({ message: "Table not found" }),
|
|
3474
|
+
});
|
|
3475
|
+
|
|
3476
|
+
await expect(
|
|
3477
|
+
client.getTable({ tableId: mockTableId, appId: mockAppId })
|
|
3478
|
+
).rejects.toThrow("API Error: Table not found (Status: 404)");
|
|
3479
|
+
});
|
|
3480
|
+
});
|
|
3481
|
+
- name: updateTable.test.ts
|
|
3482
|
+
type: file
|
|
3483
|
+
contents: |
|
|
3484
|
+
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
3485
|
+
import { createClient, mockFetch } from "@tests/setup.ts";
|
|
3486
|
+
|
|
3487
|
+
describe("QuickbaseClient - updateTable (Unit)", () => {
|
|
3488
|
+
let client: ReturnType<typeof createClient>;
|
|
3489
|
+
|
|
3490
|
+
beforeEach(() => {
|
|
3491
|
+
mockFetch.mockClear();
|
|
3492
|
+
client = createClient(mockFetch, { debug: true });
|
|
3493
|
+
});
|
|
3494
|
+
|
|
3495
|
+
it("calls updateTable successfully with temp token", async () => {
|
|
3496
|
+
client = createClient(mockFetch, { debug: true, useTempTokens: true });
|
|
3497
|
+
const mockAppId = "buwai2zpe";
|
|
3498
|
+
const mockTableId = "buwai2zr4";
|
|
3499
|
+
const mockBody = {
|
|
3500
|
+
name: "Updated Root",
|
|
3501
|
+
description: "Updated description",
|
|
3502
|
+
};
|
|
3503
|
+
const mockResponse = {
|
|
3504
|
+
id: mockTableId,
|
|
3505
|
+
name: "Updated Root",
|
|
3506
|
+
alias: "_DBID_ROOT",
|
|
3507
|
+
description: "Updated description",
|
|
3508
|
+
created: new Date("2025-02-13T18:22:33.000Z"),
|
|
3509
|
+
updated: new Date("2025-03-10T12:00:00.000Z"),
|
|
3510
|
+
nextRecordId: 1,
|
|
3511
|
+
nextFieldId: 6,
|
|
3512
|
+
defaultSortFieldId: 2,
|
|
3513
|
+
defaultSortOrder: "DESC",
|
|
3514
|
+
keyFieldId: 3,
|
|
3515
|
+
singleRecordName: "Root",
|
|
3516
|
+
pluralRecordName: "Roots",
|
|
3517
|
+
sizeLimit: "500 MB",
|
|
3518
|
+
spaceUsed: "0 KB",
|
|
3519
|
+
spaceRemaining: "500 MB",
|
|
3520
|
+
};
|
|
3521
|
+
|
|
3522
|
+
mockFetch
|
|
3523
|
+
.mockResolvedValueOnce({
|
|
3524
|
+
ok: true,
|
|
3525
|
+
status: 200,
|
|
3526
|
+
json: () => Promise.resolve({ temporaryAuthorization: "temp_token" }),
|
|
3527
|
+
})
|
|
3528
|
+
.mockResolvedValueOnce({
|
|
3529
|
+
ok: true,
|
|
3530
|
+
status: 200,
|
|
3531
|
+
json: () => Promise.resolve(mockResponse),
|
|
3532
|
+
});
|
|
3533
|
+
|
|
3534
|
+
const response = await client.updateTable({
|
|
3535
|
+
tableId: mockTableId,
|
|
3536
|
+
appId: mockAppId,
|
|
3537
|
+
body: mockBody,
|
|
3538
|
+
});
|
|
3539
|
+
expect(response).toEqual(mockResponse);
|
|
3540
|
+
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
3541
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3542
|
+
`https://api.quickbase.com/v1/auth/temporary/${mockTableId}`,
|
|
3543
|
+
expect.any(Object)
|
|
3544
|
+
);
|
|
3545
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
3546
|
+
`https://api.quickbase.com/v1/tables/${mockTableId}?appId=${mockAppId}`,
|
|
3547
|
+
expect.objectContaining({
|
|
3548
|
+
method: "POST", // Updated to match QuickBase API spec
|
|
3549
|
+
headers: expect.objectContaining({
|
|
3550
|
+
Authorization: "QB-TEMP-TOKEN temp_token",
|
|
3551
|
+
"Content-Type": "application/json",
|
|
3552
|
+
}),
|
|
3553
|
+
body: JSON.stringify(mockBody),
|
|
3554
|
+
})
|
|
3555
|
+
);
|
|
3556
|
+
});
|
|
3557
|
+
});
|
|
3558
|
+
- name: text.txt
|
|
3559
|
+
type: file
|
|
3560
|
+
- name: tsconfig.json
|
|
3561
|
+
type: file
|
|
3562
|
+
- name: versionrc.json
|
|
3563
|
+
type: file
|
|
3564
|
+
- name: vitest.config.ts
|
|
3565
|
+
type: file
|