quickbase-js 0.1.0-beta.9 → 1.0.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.
Files changed (146) hide show
  1. package/README.md +270 -60
  2. package/dist/esm/quickbase.d.ts +2553 -3220
  3. package/dist/esm/quickbase.js +1545 -3443
  4. package/dist/esm/quickbase.js.map +1 -1
  5. package/dist/esm/quickbase.min.js +1 -1
  6. package/dist/esm/quickbase.min.js.map +1 -1
  7. package/dist/umd/quickbase.umd.js +1544 -3625
  8. package/dist/umd/quickbase.umd.js.map +1 -1
  9. package/dist/umd/quickbase.umd.min.js +1 -1
  10. package/dist/umd/quickbase.umd.min.js.map +1 -1
  11. package/package.json +25 -12
  12. package/CHANGELOG.md +0 -184
  13. package/build-common.js +0 -131
  14. package/build-esm.js +0 -71
  15. package/build-umd.js +0 -69
  16. package/examples/quicbase-jsCDN.html +0 -36
  17. package/examples/react.js +0 -48
  18. package/examples/vanillajs.html +0 -47
  19. package/open-api/fix-spec-main.ts +0 -97
  20. package/open-api/generate-override-report.ts +0 -214
  21. package/open-api/generate-unified-interface.ts +0 -336
  22. package/open-api/output/override-report.html +0 -11
  23. package/open-api/output/override-report.json +0 -14395
  24. package/open-api/output/quickbase-fixed.json +0 -11191
  25. package/open-api/regenerate-client.ts +0 -116
  26. package/open-api/schema/enhance-general.ts +0 -100
  27. package/open-api/schema/fix-arrays.ts +0 -69
  28. package/open-api/schema/tags/apps.ts +0 -90
  29. package/open-api/schema/tags/fields.ts +0 -471
  30. package/open-api/schema/tags/groups.ts +0 -51
  31. package/open-api/schema/tags/index.ts +0 -66
  32. package/open-api/schema/tags/records.ts +0 -115
  33. package/open-api/schema/tags/tables.ts +0 -211
  34. package/open-api/schema/tags/users.ts +0 -47
  35. package/open-api/types/spec.ts +0 -42
  36. package/open-api/utils/generateJsDoc.ts +0 -96
  37. package/open-api/utils/infer-schema.ts +0 -40
  38. package/open-api/utils/naming.ts +0 -10
  39. package/playwright.config.ts +0 -37
  40. package/rollup.config.js +0 -114
  41. package/specs/QuickBase_RESTful_API_2025-03-04T06_22_39.725Z.json +0 -46878
  42. package/specs/split/apps.json +0 -1315
  43. package/specs/split/auth.json +0 -191
  44. package/specs/split/fields.json +0 -3869
  45. package/specs/split/records.json +0 -754
  46. package/specs/split/reports.json +0 -619
  47. package/specs/split/tables.json +0 -1605
  48. package/src/RateLimitError.ts +0 -12
  49. package/src/ThrottleBucket.ts +0 -41
  50. package/src/authorizationStrategy.ts +0 -246
  51. package/src/generated-unified/QuickbaseClient.ts +0 -1049
  52. package/src/generated-unified/missing-types-report.json +0 -3
  53. package/src/index.ts +0 -1
  54. package/src/invokeMethod.ts +0 -242
  55. package/src/quickbaseClient.ts +0 -271
  56. package/src/rateLimiter.ts +0 -25
  57. package/src/tokenCache.ts +0 -35
  58. package/src/utils.ts +0 -7
  59. package/test-esm.js +0 -1
  60. package/test-results.json +0 -2050
  61. package/test-umd.js +0 -1
  62. package/test.ts +0 -1
  63. package/tests/playwright/qb/auth/cacheSwitching.test.ts +0 -159
  64. package/tests/playwright/qb/auth/fetchTempToken401.test.ts +0 -219
  65. package/tests/playwright/qb/auth/getAppWithTempToken.test.ts +0 -162
  66. package/tests/playwright/qb/auth/getAppWithUserToken.test.ts +0 -153
  67. package/tests/playwright/qb/auth/getTempToken.test.ts +0 -152
  68. package/tests/playwright/qb/auth/tempTokenPrefetch.test.ts +0 -179
  69. package/tests/playwright/qb/auth/tempTokenRenewal.test.ts +0 -133
  70. package/tests/setup.ts +0 -53
  71. package/tests/vitest/qb/apps/copyApp.test.ts +0 -76
  72. package/tests/vitest/qb/apps/createApp.test.ts +0 -64
  73. package/tests/vitest/qb/apps/deleteApp.test.ts +0 -76
  74. package/tests/vitest/qb/apps/getApp.test.ts +0 -44
  75. package/tests/vitest/qb/apps/getAppEvents.test.ts +0 -67
  76. package/tests/vitest/qb/apps/updateApp.test.ts +0 -58
  77. package/tests/vitest/qb/auth/mockQuickbaseServer.ts +0 -60
  78. package/tests/vitest/qb/auth/retryUserToken401.test.ts +0 -73
  79. package/tests/vitest/qb/auth/ssoTokenIntegrationWithServer.test.ts +0 -65
  80. package/tests/vitest/qb/fields/createField.test.ts +0 -77
  81. package/tests/vitest/qb/fields/deleteFields.test.ts +0 -83
  82. package/tests/vitest/qb/fields/getField.test.ts +0 -85
  83. package/tests/vitest/qb/fields/getFieldUsage.test.ts +0 -82
  84. package/tests/vitest/qb/fields/getFields.test.ts +0 -232
  85. package/tests/vitest/qb/fields/getFieldsUsage.test.ts +0 -77
  86. package/tests/vitest/qb/fields/updateField.test.ts +0 -93
  87. package/tests/vitest/qb/formulas/runFormula.test.ts +0 -96
  88. package/tests/vitest/qb/index.ts +0 -29
  89. package/tests/vitest/qb/records/deleteRecords.test.ts +0 -110
  90. package/tests/vitest/qb/records/runQuery.test.ts +0 -146
  91. package/tests/vitest/qb/records/upsert.test.ts +0 -102
  92. package/tests/vitest/qb/tables/createRelationship.test.ts +0 -102
  93. package/tests/vitest/qb/tables/createTable.test.ts +0 -55
  94. package/tests/vitest/qb/tables/deleteRelationship.test.ts +0 -143
  95. package/tests/vitest/qb/tables/deleteTable.test.ts +0 -50
  96. package/tests/vitest/qb/tables/getAppTables.test.ts +0 -46
  97. package/tests/vitest/qb/tables/getRelationships.test.ts +0 -80
  98. package/tests/vitest/qb/tables/getTable.test.ts +0 -26
  99. package/tests/vitest/qb/tables/updateRelationship.test.ts +0 -250
  100. package/tests/vitest/qb/tables/updateTable.test.ts +0 -48
  101. package/tests/vitest/unit/ThrottleBucket.test.ts +0 -95
  102. package/tests/vitest/unit/apps/copyApp.test.ts +0 -581
  103. package/tests/vitest/unit/apps/createApp.test.ts +0 -186
  104. package/tests/vitest/unit/apps/deleteApp.test.ts +0 -216
  105. package/tests/vitest/unit/apps/getApp.test.ts +0 -128
  106. package/tests/vitest/unit/apps/getAppEvents.test.ts +0 -193
  107. package/tests/vitest/unit/apps/updateApp.test.ts +0 -412
  108. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +0 -63
  109. package/tests/vitest/unit/auth/getTempToken.test.ts +0 -119
  110. package/tests/vitest/unit/auth/retryTempToken401.test.ts +0 -95
  111. package/tests/vitest/unit/auth/retryTempTokenMaxRetries.test.ts +0 -235
  112. package/tests/vitest/unit/auth/retryUserToken401.test.ts +0 -69
  113. package/tests/vitest/unit/auth/ssoTokenRefresh.test.ts +0 -325
  114. package/tests/vitest/unit/fields/createField.test.ts +0 -451
  115. package/tests/vitest/unit/fields/deleteFields.test.ts +0 -141
  116. package/tests/vitest/unit/fields/getField.test.ts +0 -189
  117. package/tests/vitest/unit/fields/getFieldUsage.test.ts +0 -180
  118. package/tests/vitest/unit/fields/getFields.test.ts +0 -122
  119. package/tests/vitest/unit/fields/getFieldsUsage.test.ts +0 -160
  120. package/tests/vitest/unit/fields/updateField.test.ts +0 -285
  121. package/tests/vitest/unit/formulas/runFormula.test.ts +0 -205
  122. package/tests/vitest/unit/index.ts +0 -34
  123. package/tests/vitest/unit/inferHttpMethod.test.ts +0 -131
  124. package/tests/vitest/unit/rateLimit.test.ts +0 -191
  125. package/tests/vitest/unit/records/deleteRecords.test.ts +0 -112
  126. package/tests/vitest/unit/records/runQuery.test.ts +0 -102
  127. package/tests/vitest/unit/records/upsert.test.ts +0 -234
  128. package/tests/vitest/unit/tables/createRelationship.test.ts +0 -212
  129. package/tests/vitest/unit/tables/createTable.test.ts +0 -70
  130. package/tests/vitest/unit/tables/deleteRelationship.test.ts +0 -97
  131. package/tests/vitest/unit/tables/deleteTable.test.ts +0 -77
  132. package/tests/vitest/unit/tables/getAppTables.test.ts +0 -85
  133. package/tests/vitest/unit/tables/getRelationships.test.ts +0 -259
  134. package/tests/vitest/unit/tables/getTable.test.ts +0 -233
  135. package/tests/vitest/unit/tables/updateRelationship.test.ts +0 -307
  136. package/tests/vitest/unit/tables/updateTable.test.ts +0 -80
  137. package/tests/vitest/unit/tokenLifespan.test.ts +0 -204
  138. package/tests/vitest/unit/umd.test.ts +0 -8
  139. package/text.txt +0 -104
  140. package/tools/log-gen.ts +0 -244
  141. package/tools/log-gen.yaml +0 -5424
  142. package/tools/openapi-jars/openapi-generator-cli-7.12.0.jar +0 -0
  143. package/tsconfig.build.json +0 -17
  144. package/tsconfig.json +0 -32
  145. package/versionrc.json +0 -9
  146. package/vitest.config.ts +0 -27
package/README.md CHANGED
@@ -1,91 +1,304 @@
1
1
  # quickbase-js
2
2
 
3
- This is a Typescript library using the QuickBase OpenAPI spec and the typescipt-fetch generator. This library is designed for both browser and Node.js environments. Code pages have first class support.
3
+ A Typescript API client for the [Quickbase JSON RESTful API](https://developer.quickbase.com/).
4
4
 
5
- Authentication methods: `Temporary Tokens`, `User Tokens`, `SSO`.
5
+ Support for various authentication types (`user token`, `temporary tokens`, `SSO token`), `concurrent rate limiting strategies`, `auto pagination`, `js date conversion`, `429` (rate limit) and `401` (auth) error handling retries. It uses a Proxy to dynamically invoke API methods derived from the OpenAPI specification.
6
6
 
7
- # Installation
7
+ Browser and Node.js support. ESM and UMD builds are available.
8
+
9
+ Authentication and throttle methods are opinionated. See configuration options for details and available settings.
10
+
11
+ ## API Documentation
12
+
13
+ <a href="https://quickbase-js.netlify.app/" target="_blank"> Documentation</a> for quickbase-js.
14
+
15
+ ## Installation
16
+
17
+ #### Node.js install
8
18
 
9
19
  ```bash
10
20
  npm install --save quickbase-js
11
21
  ```
12
22
 
13
- ## Examples
23
+ #### CDN install.
24
+
25
+ Find and select the latest version. UMD is recommended for code pages.
14
26
 
15
- ### CDN Code Page
27
+ <a href="https://www.jsdelivr.com/package/npm/quickbase-js?tab=files" target="_blank">CDN Files</a> for quickbase-js
16
28
 
17
29
  ```html
18
30
  <!DOCTYPE html>
19
31
  <html>
20
32
  <head>
21
33
  <title>Quickbase</title>
22
- <script src="https://cdn.jsdelivr.net/npm/quickbase-js@1.1.0-beta.6/dist/umd/quickbase.umd.min.js"></script>
34
+ <!-- Replace xx.xx.xx with the latest version from CDN Files-->
35
+ <script src="https://cdn.jsdelivr.net/npm/quickbase-js@xx.xx.xx/dist/umd/quickbase.umd.min.js"></script>
23
36
  </head>
24
-
25
37
  <body>
26
- <div>
27
- <h1>Quickbase-js CDN Example</h1>
28
- <p id="result">Loading...</p>
29
- </div>
30
38
  <script>
31
- var realm = "xxxxxxxxxxxxxxxxxxxx"; // replace with your realm
32
- var appId = "xxxxxxxxxxxxxxxxxxxx"; // replace with your app ID
33
- if (typeof QuickbaseJS === "undefined") {
34
- document.getElementById("result").textContent =
35
- "Error: Failed to load QuickbaseJS library.";
36
- } else {
37
- var qbClient = QuickbaseJS.quickbase({
38
- realm,
39
- useTempTokens: true,
40
- });
41
-
42
- qbClient
43
- .getApp({ appId })
44
- .then(function (app) {
45
- document.getElementById("result").textContent =
46
- "App Name: " + app.name;
47
- })
48
- .catch(function (err) {
49
- document.getElementById("result").textContent =
50
- "Error: " + (err.message || "Failed to load app");
51
- });
52
- }
39
+ const realm = ""; // Replace with your realm
40
+ const appId = ""; // Replace with your app ID
41
+
42
+ const qb = QuickbaseJS.quickbase({
43
+ realm,
44
+ useTempTokens: true,
45
+ });
46
+
47
+ qb.getApp({ appId })
48
+ .then((app) => console.log(app.name))
49
+ .catch((err) => console.log(err.message));
53
50
  </script>
54
51
  </body>
55
52
  </html>
56
53
  ```
57
54
 
55
+ ## Authentication Examples
56
+
57
+ ### User Token
58
+
59
+ ```javascript
60
+ import { quickbase } from "quickbase-js"; // Adjust the import path as needed
61
+
62
+ // QuickBase config variables
63
+ const QB_REALM = ""; // Your QuickBase realm (e.g., 'mycompany')
64
+ const QB_USER_TOKEN = ""; // Your QuickBase user token (e.g., 'b12345_abcde...')
65
+ const QB_APP_ID = ""; // Your app ID (e.g., 'bxyz789')
66
+
67
+ const qb = quickbase({
68
+ realm: QB_REALM,
69
+ userToken: QB_USER_TOKEN,
70
+ });
71
+
72
+ const getAppDetails = async () => {
73
+ try {
74
+ const response = await qb.getApp({
75
+ appId: QB_APP_ID,
76
+ });
77
+ console.log("App Details:", response);
78
+ } catch (error) {
79
+ console.error("Error fetching app:", error.message);
80
+ }
81
+ };
82
+
83
+ getAppDetails();
84
+ ```
85
+
86
+ ### Temporary Tokens (Code Pages)
87
+
88
+ ```javascript
89
+ import { quickbase } from "quickbase-js"; // Adjust the import path as needed
90
+
91
+ // QuickBase config variables
92
+ const QB_REALM = ""; // Your QuickBase realm (e.g., 'mycompany')
93
+ const QB_APP_ID = ""; // Your app ID (e.g., 'bxyz789')
94
+
95
+ const qb = quickbase({
96
+ realm: QB_REALM,
97
+ useTempTokens: true,
98
+ });
99
+
100
+ const getAppDetails = async () => {
101
+ try {
102
+ const response = await qb.getApp({
103
+ appId: QB_APP_ID,
104
+ });
105
+ console.log("App Details:", response);
106
+ } catch (error) {
107
+ console.error("Error fetching app:", error.message);
108
+ }
109
+ };
110
+
111
+ getAppDetails();
112
+ ```
113
+
114
+ ### SSO Token
115
+
116
+ ```javascript
117
+ import { quickbase } from "quickbase-js"; // Adjust the import path as needed
118
+
119
+ // QuickBase config variables
120
+ const QB_REALM = ""; // Your QuickBase realm (e.g., 'mycompany')
121
+ const QB_SAML_TOKEN = ""; // Your SAML token (e.g., 'saml_xyz789...')
122
+ const QB_APP_ID = ""; // Your app ID (e.g., 'bxyz789')
123
+
124
+ const qb = quickbase({
125
+ realm: QB_REALM,
126
+ samlToken: QB_SAML_TOKEN,
127
+ useSso: true,
128
+ });
129
+
130
+ const getAppDetails = async () => {
131
+ try {
132
+ const response = await qb.getApp({
133
+ appId: QB_APP_ID,
134
+ });
135
+ console.log("App Details:", response);
136
+ } catch (error) {
137
+ console.error("Error fetching app:", error.message);
138
+ }
139
+ };
140
+
141
+ getAppDetails();
142
+ ```
143
+
58
144
  ## Configuration
59
145
 
60
146
  The `quickbase` function accepts a `QuickbaseConfig` object with the following options:
61
147
 
148
+ ### User Options
149
+
62
150
  - **`realm`** (`string`): Your QuickBase realm (e.g., "company"). This is required and has no default value.
151
+
63
152
  - **`userToken`** (`string`, optional): A QuickBase user token for authentication. No default is provided.
153
+
64
154
  - **`useTempTokens`** (`boolean`, optional): Enables temporary token authentication. Defaults to `false`.
155
+
65
156
  - **`useSso`** (`boolean`, optional): Enables SSO authentication. Defaults to `false`.
157
+
66
158
  - **`samlToken`** (`string`, optional): A SAML token for SSO authentication. No default is provided.
67
159
 
68
- ---
160
+ ### Advanced User Options
161
+
162
+ - **`throttle`** (`{ type?: 'flow' | 'burst-aware';` `rate?: number;` `burst?: number;` `windowSeconds?: number }`, optional): Configures concurrent rate limiting to manage API request throughput. Defaults to `{ type: 'flow', rate: 5, burst: 50 }`.
163
+
164
+ - **`type`** (`string`): Throttle strategy. _Setting type without rate or burst enables default settings for that throttle type._
165
+
166
+ - `'flow'` (default): Uses `FlowThrottleBucket` for a QuickBase-agnostic burst-then-rate flow. Ideal for steady request pacing.
167
+
168
+ - `'burst-aware'`: Uses `BurstAwareThrottleBucket` for QuickBase-specific burst throttling with a sliding window (e.g., 100 requests per 10 seconds). Ideal for when you need to use nearly all your allotted API calls immediately, for example on page load.
169
+
170
+ _Set rate and burst if changing defaults._
171
+
172
+ - **`rate`** (`number`): Requests per second after the initial burst (for `'flow'` only). Default is `5`. Meaning 5 request tokens get created each second.
173
+
174
+ - **`burst`** (`number`): Maximum concurrent requests:
175
+ - For `'flow'`: Initial concurrent burst size (default: 50), followed by `rate`/sec.
176
+ - For `'burst-aware'`: Concurrent burst cap per window (default: 100), waits for window reset if exceeded.
177
+ - **`windowSeconds`** (`number`, `'burst-aware'` only): Sliding window duration in seconds (default: 10). Caps total requests (e.g., 100 requests available every 10s).
69
178
 
70
- _Optional advanced options:_
179
+ - **Examples**:
180
+ - `{ type: 'flow', rate: 5, burst: 50 }`: **~10s for 100 requests**, (50 instant, and 1 every 200ms. In other words, 50 at 10/sec).
181
+ - `{ type: 'burst-aware', burst: 100, windowSeconds: 10 }`: **~10s for 100 requests**, (100 instant, refreshing every 10s for next burst).
182
+
183
+ - **`maxRetries`** (`number`, optional): Maximum retries for failed requests. Defaults to `3`.
184
+
185
+ - **`retryDelay`** (`number`, optional): Base delay (in milliseconds) between retries, increases exponentially. Defaults to `1000`.
186
+
187
+ - **`tempTokenLifespan`** (`number`, optional): Lifespan (in milliseconds) of temporary tokens in the cache. Defaults to 4 minutes 50 seconds (290000 ms).
71
188
 
72
- - **`tempTokenLifespan`** (`number`, optional): The lifespan (in milliseconds) of temporary tokens in the cache. Defaults to `290000` (290 seconds).
73
- - **`throttle`** (`{ rate: number; burst: number }`, optional): Configures rate limiting, where `rate` is requests per second and `burst` is the maximum burst of requests. Defaults to `{ rate: 10, burst: 10 }`.
74
- - **`maxRetries`** (`number`, optional): The maximum number of retries for failed requests. Defaults to `3`.
75
- - **`retryDelay`** (`number`, optional): The base delay (in milliseconds) between retries, which increases exponentially. Defaults to `1000`.
76
189
  - **`convertDates`** (`boolean`, optional): Converts ISO date strings to `Date` objects in responses. Defaults to `true`.
77
- - **`baseUrl`** (`string`, optional): The base URL for the QuickBase API. Defaults to `"https://api.quickbase.com/v1"`.
78
- - **`tempToken`** (`string`, optional): A temporary token for authentication. No default is provided.
79
- - **`tokenCache`** (`TokenCache`, optional): A custom token cache instance. Defaults to a new `TokenCache` instance created with `tempTokenLifespan`.
80
- - **`fetchApi`** (`typeof fetch`, optional): A custom fetch implementation (e.g., for Node.js). Defaults to the browser’s `fetch` if available, or the provided implementation.
190
+
191
+ - **`autoPaginate`** (`boolean`, optional): Enables automatic pagination of multi-page API responses. Defaults to `true`.
192
+
193
+ ### Overrides and Development Options
194
+
195
+ - **`fetchApi`** (`typeof fetch`, optional): Defaults to built-in `fetch` in browsers and Node.js >= 18. In older Node.js versions, node-fetch or another compatible library via fetchApi is required.
196
+
197
+ - **`baseUrl`** (`string`, optional): Base URL for the QuickBase API. Defaults to `"https://api.quickbase.com/v1"`.
198
+
81
199
  - **`debug`** (`boolean`, optional): Enables debug logging to the console. Defaults to `false`.
82
200
 
83
- ### Configuration Notes
201
+ - **`tempToken`** (`string`, optional): Overrides default tempToken behavior by providing your own token.
202
+
203
+ - **`tokenCache`** (`TokenCache`, optional): Allows use of a custom token cache instance.
204
+
205
+ ---
206
+
207
+ #### Configuration Notes
208
+
209
+ - **Authentication**: Three mutually exclusive methods: `userToken`, `useTempTokens`, and `useSso` with `samlToken`. Only one may be active at a time.
210
+ - **`tokenCache`**: Temporary tokens are cached here with their `dbid` and `tempTokenLifespan` when `useTempTokens` is enabled.
211
+
212
+ ---
213
+
214
+ ### Pagination Control
215
+
216
+ The library supports automatic pagination for methods like `runQuery` when `autoPaginate` is enabled (default: `true`). To temporarily disable or constrain pagination for a specific operation without altering the global configuration, use the `withPaginationDisabled()` or `withPaginationLimit()` methods.
217
+
218
+ #### `withPaginationDisabled(callback)`
219
+
220
+ - **Description**: Executes an asynchronous callback with pagination temporarily disabled, restoring the original `autoPaginate` setting afterward. Useful for fetching only the initial page of results without modifying method signatures or global settings.
221
+ - **Parameters**:
222
+ - `callback`: `() => Promise<T>` - An async function containing the API call(s) to execute without pagination.
223
+ - **Returns**: `Promise<T>` - The result of the callback.
224
+ - **Example**:
225
+
226
+ ```javascript
227
+ import { quickbase } from "quickbase-js"; // Adjust the import path as needed
228
+
229
+ const QB_REALM = ""; // Your QuickBase realm (e.g., 'mycompany')
230
+ const QB_USER_TOKEN = ""; // Your QuickBase user token (e.g., 'b12345_abcde...')
231
+ const QB_TABLE_ID = ""; // Your table ID (e.g., 'bxyz789')
232
+
233
+ const qb = quickbase({
234
+ realm: QB_REALM,
235
+ userToken: QB_USER_TOKEN,
236
+ autoPaginate: true, // Pagination enabled by default
237
+ });
84
238
 
85
- - **Authentication**: Use `userToken` for standard auth, `tempToken` with `useTempTokens` for temporary tokens, or `samlToken` with `useSso` for SSO. Only one auth method is active at a time.
86
- - **`throttle`**: Controls API request pacing to avoid hitting rate limits. For example, `{ rate: 5, burst: 20 }` allows 5 requests per second with a burst capacity of 20.
87
- - **`tokenCache`**: If not provided, a new cache is initialized automatically, storing temporary tokens for the specified `tempTokenLifespan`.
88
- - **`fetchApi`**: In Node.js, you must provide a fetch implementation (e.g., `node-fetch`), as there’s no built-in `fetch` like in browsers.
239
+ const runLimitedQuery = async () => {
240
+ try {
241
+ const result = await qb.withPaginationDisabled(async () => {
242
+ return qb.runQuery({
243
+ body: {
244
+ from: QB_TABLE_ID,
245
+ select: [3], // Example field ID
246
+ options: { top: 2 }, // Fetch only 2 records
247
+ },
248
+ });
249
+ });
250
+ console.log("Fetched records:", result.data.length); // Outputs: 2
251
+ } catch (error) {
252
+ console.error("Error running query:", error.message);
253
+ }
254
+ };
255
+
256
+ runLimitedQuery();
257
+ ```
258
+
259
+ #### `withPaginationLimit(limit, callback)`
260
+
261
+ - **Description**: Executes an asynchronous callback with pagination enabled but limited to a specified number of records, restoring the original `autoPaginate` setting afterward. Useful for fetching a precise number of records (e.g., 100) from a larger dataset, stopping pagination once the limit is reached, without modifying method signatures or global settings.
262
+ - **Parameters**:
263
+ - `limit`: `number` - The maximum number of records to fetch across all pages.
264
+ - `callback`: `() => Promise<T>` - An async function containing the API call(s) to execute with the pagination limit.
265
+ - **Returns**: `Promise<T>` - The result of the callback, containing up to `limit` records.
266
+ - **Example**:
267
+
268
+ ```javascript
269
+ import { quickbase } from "quickbase-js"; // Adjust the import path as needed
270
+
271
+ const QB_REALM = ""; // Your QuickBase realm (e.g., 'mycompany')
272
+ const QB_USER_TOKEN = ""; // Your QuickBase user token (e.g., 'b12345_abcde...')
273
+ const QB_TABLE_ID = ""; // Your table ID (e.g., 'bxyz789')
274
+
275
+ const qb = quickbase({
276
+ realm: QB_REALM,
277
+ userToken: QB_USER_TOKEN,
278
+ autoPaginate: true, // Pagination enabled by default
279
+ });
280
+
281
+ const runCappedQuery = async () => {
282
+ try {
283
+ const result = await qb.withPaginationLimit(100, async () => {
284
+ return qb.runQuery({
285
+ body: {
286
+ from: QB_TABLE_ID,
287
+ select: [3], // Example field ID
288
+ options: { top: 25 }, // Fetch 25 records per page
289
+ },
290
+ });
291
+ });
292
+ console.log("Fetched records:", result.data.length); // Outputs: 100
293
+ } catch (error) {
294
+ console.error("Error running query:", error.message);
295
+ }
296
+ };
297
+
298
+ runCappedQuery();
299
+ ```
300
+
301
+ ---
89
302
 
90
303
  ### Development workflow
91
304
 
@@ -95,26 +308,23 @@ npm run build
95
308
  npm run test:all
96
309
  ```
97
310
 
98
- ### Prerequisites
311
+ ---
99
312
 
100
- Node.js >= 18
313
+ ### Prerequisites
101
314
 
102
- npm >= 8
315
+ - Node.js version >= 18
316
+ - A Quickbase account. [Free tier available](https://www.quickbase.com/builder-program).
103
317
 
104
- A Quickbase app with a table and a user token. A free builder account works with must API calls.
318
+ ---
105
319
 
106
320
  ### Contributing
107
321
 
108
- 1. Fork the repository.
109
-
110
- 2. Create a feature branch (git checkout -b feature/your-feature).
322
+ If you would like to contribute to this project, please fork the repository and submit a pull request.
111
323
 
112
- 3. Commit changes (git commit -m "Add your feature").
113
-
114
- 4. Push to your branch (git push origin feature/your-feature).
115
-
116
- 5. Open a pull request.
324
+ ---
117
325
 
118
326
  ### License
119
327
 
120
328
  MIT License - see LICENSE for details.
329
+
330
+ ---