quickbase-js 0.1.0-beta.7 → 0.1.0-beta.8

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 (60) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/esm/quickbase.d.ts +589 -125
  3. package/dist/esm/quickbase.js +484 -145
  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 +492 -144
  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/open-api/fix-spec-main.ts +69 -68
  12. package/open-api/generate-override-report.ts +214 -0
  13. package/open-api/generate-unified-interface.ts +73 -94
  14. package/open-api/output/override-report.html +11 -0
  15. package/open-api/output/override-report.json +14395 -58
  16. package/open-api/output/quickbase-fixed.json +583 -2
  17. package/open-api/schema/tags/fields.ts +331 -16
  18. package/open-api/schema/tags/index.ts +2 -4
  19. package/open-api/types/spec.ts +2 -1
  20. package/package.json +31 -33
  21. package/src/RateLimitError.ts +12 -0
  22. package/src/ThrottleBucket.ts +36 -0
  23. package/src/generated-unified/QuickbaseClient.ts +119 -119
  24. package/src/invokeMethod.ts +357 -0
  25. package/src/quickbaseClient.ts +51 -209
  26. package/tests/setup.ts +2 -0
  27. package/tests/vitest/qb/apps/getApp.test.ts +6 -2
  28. package/tests/vitest/qb/apps/getAppEvents.test.ts +67 -0
  29. package/tests/vitest/qb/apps/updateApp.test.ts +58 -0
  30. package/tests/vitest/qb/auth/retryUserToken401.test.ts +56 -0
  31. package/tests/vitest/qb/fields/createField.test.ts +1 -2
  32. package/tests/vitest/qb/fields/deleteFields.test.ts +10 -16
  33. package/tests/vitest/qb/fields/updateField.test.ts +93 -0
  34. package/tests/vitest/qb/index.ts +1 -0
  35. package/tests/vitest/qb/tables/updateRelationship.test.ts +277 -0
  36. package/tests/vitest/unit/apps/getAppEvents.test.ts +193 -0
  37. package/tests/vitest/unit/apps/updateApp.test.ts +381 -0
  38. package/tests/vitest/unit/auth/fetchTempToken401.test.ts +6 -26
  39. package/tests/vitest/unit/auth/{retryOn401.test.ts → retryTempToken401.test.ts} +3 -6
  40. package/tests/vitest/unit/auth/{two401s.test.ts → retryTempTokenTwo401.test.ts} +4 -9
  41. package/tests/vitest/unit/auth/retryUserToken401.test.ts +56 -0
  42. package/tests/vitest/unit/fields/createField.test.ts +8 -12
  43. package/tests/vitest/unit/fields/getFieldUsage.test.ts +33 -14
  44. package/tests/vitest/unit/fields/updateField.test.ts +280 -0
  45. package/tests/vitest/unit/rateLimit.test.ts +189 -0
  46. package/tests/vitest/unit/tables/updateRelationship.test.ts +305 -0
  47. package/tests/vitest/unit/tokenLifespan.test.ts +138 -0
  48. package/tools/log-gen.ts +8 -4
  49. package/tools/log-gen.yaml +3004 -1848
  50. package/tsconfig.json +5 -2
  51. package/vitest.config.ts +2 -2
  52. package/notes.txt +0 -158
  53. package/tools/generate-types.ts +0 -29
  54. package/tools/openapi-schema-validator.ts +0 -38
  55. package/tools/spec-analyzer.ts +0 -163
  56. package/tools/split-spec.ts +0 -148
  57. package/tools/test-import.ts +0 -3
  58. package/tools/validate-spec.ts +0 -40
  59. /package/tests/playwright/qb/auth/{tokenPrefetch.test.ts → tempTokenPrefetch.test.ts} +0 -0
  60. /package/tests/playwright/qb/auth/{tokenRenewal.test.ts → tempTokenRenewal.test.ts} +0 -0
@@ -1673,6 +1673,209 @@
1673
1673
  };
1674
1674
  }
1675
1675
 
1676
+ /* tslint:disable */
1677
+ /* eslint-disable */
1678
+ /**
1679
+ * Quick Base API
1680
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
1681
+ *
1682
+ * The version of the OpenAPI document: 1.0.0
1683
+ *
1684
+ *
1685
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
1686
+ * https://openapi-generator.tech
1687
+ * Do not edit the class manually.
1688
+ */
1689
+ /**
1690
+ * @export
1691
+ */
1692
+ const CreateFieldRequestPropertiesOpenTargetInEnum = {
1693
+ SameWindow: 'sameWindow',
1694
+ NewWindow: 'newWindow',
1695
+ Popup: 'popup'
1696
+ };
1697
+ /**
1698
+ * @export
1699
+ */
1700
+ const CreateFieldRequestPropertiesSummaryFunctionEnum = {
1701
+ Avg: 'AVG',
1702
+ Sum: 'SUM',
1703
+ Max: 'MAX',
1704
+ Min: 'MIN',
1705
+ StdDev: 'STD-DEV',
1706
+ Count: 'COUNT',
1707
+ CombinedText: 'COMBINED-TEXT',
1708
+ CombinedUser: 'COMBINED-USER',
1709
+ DistinctCount: 'DISTINCT-COUNT'
1710
+ };
1711
+ /**
1712
+ * @export
1713
+ */
1714
+ const CreateFieldRequestPropertiesCurrencyFormatEnum = {
1715
+ Left: 'left',
1716
+ Right: 'right',
1717
+ Middle: 'middle'
1718
+ };
1719
+ /**
1720
+ * @export
1721
+ */
1722
+ const CreateFieldRequestPropertiesVersionModeEnum = {
1723
+ Keepallversions: 'keepallversions',
1724
+ Keeplastversions: 'keeplastversions'
1725
+ };
1726
+ /**
1727
+ * Check if a given object implements the CreateFieldRequestProperties interface.
1728
+ */
1729
+ function instanceOfCreateFieldRequestProperties(value) {
1730
+ return true;
1731
+ }
1732
+ function CreateFieldRequestPropertiesFromJSON(json) {
1733
+ return CreateFieldRequestPropertiesFromJSONTyped(json);
1734
+ }
1735
+ function CreateFieldRequestPropertiesFromJSONTyped(json, ignoreDiscriminator) {
1736
+ if (json == null) {
1737
+ return json;
1738
+ }
1739
+ return {
1740
+ 'numLines': json['numLines'] == null ? undefined : json['numLines'],
1741
+ 'maxLength': json['maxLength'] == null ? undefined : json['maxLength'],
1742
+ 'appendOnly': json['appendOnly'] == null ? undefined : json['appendOnly'],
1743
+ 'sortAsGiven': json['sortAsGiven'] == null ? undefined : json['sortAsGiven'],
1744
+ 'allowMentions': json['allowMentions'] == null ? undefined : json['allowMentions'],
1745
+ 'comments': json['comments'] == null ? undefined : json['comments'],
1746
+ 'doesTotal': json['doesTotal'] == null ? undefined : json['doesTotal'],
1747
+ 'autoSave': json['autoSave'] == null ? undefined : json['autoSave'],
1748
+ 'defaultValueLuid': json['defaultValueLuid'] == null ? undefined : json['defaultValueLuid'],
1749
+ 'useI18NFormat': json['useI18NFormat'] == null ? undefined : json['useI18NFormat'],
1750
+ 'maxVersions': json['maxVersions'] == null ? undefined : json['maxVersions'],
1751
+ 'format': json['format'] == null ? undefined : json['format'],
1752
+ 'carryChoices': json['carryChoices'] == null ? undefined : json['carryChoices'],
1753
+ 'linkText': json['linkText'] == null ? undefined : json['linkText'],
1754
+ 'parentFieldId': json['parentFieldId'] == null ? undefined : json['parentFieldId'],
1755
+ 'displayTimezone': json['displayTimezone'] == null ? undefined : json['displayTimezone'],
1756
+ 'summaryTargetFieldId': json['summaryTargetFieldId'] == null ? undefined : json['summaryTargetFieldId'],
1757
+ 'allowNewChoices': json['allowNewChoices'] == null ? undefined : json['allowNewChoices'],
1758
+ 'defaultToday': json['defaultToday'] == null ? undefined : json['defaultToday'],
1759
+ 'units': json['units'] == null ? undefined : json['units'],
1760
+ 'openTargetIn': json['openTargetIn'] == null ? undefined : json['openTargetIn'],
1761
+ 'lookupTargetFieldId': json['lookupTargetFieldId'] == null ? undefined : json['lookupTargetFieldId'],
1762
+ 'summaryFunction': json['summaryFunction'] == null ? undefined : json['summaryFunction'],
1763
+ 'sourceFieldId': json['sourceFieldId'] == null ? undefined : json['sourceFieldId'],
1764
+ 'doesAverage': json['doesAverage'] == null ? undefined : json['doesAverage'],
1765
+ 'formula': json['formula'] == null ? undefined : json['formula'],
1766
+ 'decimalPlaces': json['decimalPlaces'] == null ? undefined : json['decimalPlaces'],
1767
+ 'defaultCountryCode': json['defaultCountryCode'] == null ? undefined : json['defaultCountryCode'],
1768
+ 'displayMonth': json['displayMonth'] == null ? undefined : json['displayMonth'],
1769
+ 'seeVersions': json['seeVersions'] == null ? undefined : json['seeVersions'],
1770
+ 'defaultKind': json['defaultKind'] == null ? undefined : json['defaultKind'],
1771
+ 'displayEmail': json['displayEmail'] == null ? undefined : json['displayEmail'],
1772
+ 'coverText': json['coverText'] == null ? undefined : json['coverText'],
1773
+ 'currencySymbol': json['currencySymbol'] == null ? undefined : json['currencySymbol'],
1774
+ 'summaryQuery': json['summaryQuery'] == null ? undefined : json['summaryQuery'],
1775
+ 'targetFieldId': json['targetFieldId'] == null ? undefined : json['targetFieldId'],
1776
+ 'displayUser': json['displayUser'] == null ? undefined : json['displayUser'],
1777
+ 'blankIsZero': json['blankIsZero'] == null ? undefined : json['blankIsZero'],
1778
+ 'exact': json['exact'] == null ? undefined : json['exact'],
1779
+ 'defaultDomain': json['defaultDomain'] == null ? undefined : json['defaultDomain'],
1780
+ 'defaultValue': json['defaultValue'] == null ? undefined : json['defaultValue'],
1781
+ 'abbreviate': json['abbreviate'] == null ? undefined : json['abbreviate'],
1782
+ 'numberFormat': json['numberFormat'] == null ? undefined : json['numberFormat'],
1783
+ 'targetTableName': json['targetTableName'] == null ? undefined : json['targetTableName'],
1784
+ 'appearsAs': json['appearsAs'] == null ? undefined : json['appearsAs'],
1785
+ 'width': json['width'] == null ? undefined : json['width'],
1786
+ 'currencyFormat': json['currencyFormat'] == null ? undefined : json['currencyFormat'],
1787
+ 'displayDayOfWeek': json['displayDayOfWeek'] == null ? undefined : json['displayDayOfWeek'],
1788
+ 'summaryReferenceFieldId': json['summaryReferenceFieldId'] == null ? undefined : json['summaryReferenceFieldId'],
1789
+ 'commaStart': json['commaStart'] == null ? undefined : json['commaStart'],
1790
+ 'choices': json['choices'] == null ? undefined : json['choices'],
1791
+ 'targetTableId': json['targetTableId'] == null ? undefined : json['targetTableId'],
1792
+ 'displayRelative': json['displayRelative'] == null ? undefined : json['displayRelative'],
1793
+ 'compositeFields': json['compositeFields'] == null ? undefined : json['compositeFields'],
1794
+ 'displayCheckboxAsText': json['displayCheckboxAsText'] == null ? undefined : json['displayCheckboxAsText'],
1795
+ 'versionMode': json['versionMode'] == null ? undefined : json['versionMode'],
1796
+ 'snapFieldId': json['snapFieldId'] == null ? undefined : json['snapFieldId'],
1797
+ 'hours24': json['hours24'] == null ? undefined : json['hours24'],
1798
+ 'sortAlpha': json['sortAlpha'] == null ? undefined : json['sortAlpha'],
1799
+ 'hasExtension': json['hasExtension'] == null ? undefined : json['hasExtension'],
1800
+ 'useNewWindow': json['useNewWindow'] == null ? undefined : json['useNewWindow'],
1801
+ 'displayAsLink': json['displayAsLink'] == null ? undefined : json['displayAsLink'],
1802
+ 'lookupReferenceFieldId': json['lookupReferenceFieldId'] == null ? undefined : json['lookupReferenceFieldId'],
1803
+ };
1804
+ }
1805
+ function CreateFieldRequestPropertiesToJSON(json) {
1806
+ return CreateFieldRequestPropertiesToJSONTyped(json, false);
1807
+ }
1808
+ function CreateFieldRequestPropertiesToJSONTyped(value, ignoreDiscriminator = false) {
1809
+ if (value == null) {
1810
+ return value;
1811
+ }
1812
+ return {
1813
+ 'numLines': value['numLines'],
1814
+ 'maxLength': value['maxLength'],
1815
+ 'appendOnly': value['appendOnly'],
1816
+ 'sortAsGiven': value['sortAsGiven'],
1817
+ 'allowMentions': value['allowMentions'],
1818
+ 'comments': value['comments'],
1819
+ 'doesTotal': value['doesTotal'],
1820
+ 'autoSave': value['autoSave'],
1821
+ 'defaultValueLuid': value['defaultValueLuid'],
1822
+ 'useI18NFormat': value['useI18NFormat'],
1823
+ 'maxVersions': value['maxVersions'],
1824
+ 'format': value['format'],
1825
+ 'carryChoices': value['carryChoices'],
1826
+ 'linkText': value['linkText'],
1827
+ 'parentFieldId': value['parentFieldId'],
1828
+ 'displayTimezone': value['displayTimezone'],
1829
+ 'summaryTargetFieldId': value['summaryTargetFieldId'],
1830
+ 'allowNewChoices': value['allowNewChoices'],
1831
+ 'defaultToday': value['defaultToday'],
1832
+ 'units': value['units'],
1833
+ 'openTargetIn': value['openTargetIn'],
1834
+ 'lookupTargetFieldId': value['lookupTargetFieldId'],
1835
+ 'summaryFunction': value['summaryFunction'],
1836
+ 'sourceFieldId': value['sourceFieldId'],
1837
+ 'doesAverage': value['doesAverage'],
1838
+ 'formula': value['formula'],
1839
+ 'decimalPlaces': value['decimalPlaces'],
1840
+ 'defaultCountryCode': value['defaultCountryCode'],
1841
+ 'displayMonth': value['displayMonth'],
1842
+ 'seeVersions': value['seeVersions'],
1843
+ 'defaultKind': value['defaultKind'],
1844
+ 'displayEmail': value['displayEmail'],
1845
+ 'coverText': value['coverText'],
1846
+ 'currencySymbol': value['currencySymbol'],
1847
+ 'summaryQuery': value['summaryQuery'],
1848
+ 'targetFieldId': value['targetFieldId'],
1849
+ 'displayUser': value['displayUser'],
1850
+ 'blankIsZero': value['blankIsZero'],
1851
+ 'exact': value['exact'],
1852
+ 'defaultDomain': value['defaultDomain'],
1853
+ 'defaultValue': value['defaultValue'],
1854
+ 'abbreviate': value['abbreviate'],
1855
+ 'numberFormat': value['numberFormat'],
1856
+ 'targetTableName': value['targetTableName'],
1857
+ 'appearsAs': value['appearsAs'],
1858
+ 'width': value['width'],
1859
+ 'currencyFormat': value['currencyFormat'],
1860
+ 'displayDayOfWeek': value['displayDayOfWeek'],
1861
+ 'summaryReferenceFieldId': value['summaryReferenceFieldId'],
1862
+ 'commaStart': value['commaStart'],
1863
+ 'choices': value['choices'],
1864
+ 'targetTableId': value['targetTableId'],
1865
+ 'displayRelative': value['displayRelative'],
1866
+ 'compositeFields': value['compositeFields'],
1867
+ 'displayCheckboxAsText': value['displayCheckboxAsText'],
1868
+ 'versionMode': value['versionMode'],
1869
+ 'snapFieldId': value['snapFieldId'],
1870
+ 'hours24': value['hours24'],
1871
+ 'sortAlpha': value['sortAlpha'],
1872
+ 'hasExtension': value['hasExtension'],
1873
+ 'useNewWindow': value['useNewWindow'],
1874
+ 'displayAsLink': value['displayAsLink'],
1875
+ 'lookupReferenceFieldId': value['lookupReferenceFieldId'],
1876
+ };
1877
+ }
1878
+
1676
1879
  /* tslint:disable */
1677
1880
  /* eslint-disable */
1678
1881
  /**
@@ -1743,6 +1946,7 @@
1743
1946
  'findEnabled': json['findEnabled'] == null ? undefined : json['findEnabled'],
1744
1947
  'doesDataCopy': json['doesDataCopy'] == null ? undefined : json['doesDataCopy'],
1745
1948
  'audited': json['audited'] == null ? undefined : json['audited'],
1949
+ 'properties': json['properties'] == null ? undefined : CreateFieldRequestPropertiesFromJSON(json['properties']),
1746
1950
  };
1747
1951
  }
1748
1952
  function CreateFieldRequestToJSON(json) {
@@ -1766,6 +1970,7 @@
1766
1970
  'findEnabled': value['findEnabled'],
1767
1971
  'doesDataCopy': value['doesDataCopy'],
1768
1972
  'audited': value['audited'],
1973
+ 'properties': CreateFieldRequestPropertiesToJSON(value['properties']),
1769
1974
  };
1770
1975
  }
1771
1976
 
@@ -6361,8 +6566,6 @@
6361
6566
  function instanceOfUpdateFieldRequest(value) {
6362
6567
  if (!('label' in value) || value['label'] === undefined)
6363
6568
  return false;
6364
- if (!('fieldType' in value) || value['fieldType'] === undefined)
6365
- return false;
6366
6569
  return true;
6367
6570
  }
6368
6571
  function UpdateFieldRequestFromJSON(json) {
@@ -6374,7 +6577,7 @@
6374
6577
  }
6375
6578
  return {
6376
6579
  'label': json['label'],
6377
- 'fieldType': json['fieldType'],
6580
+ 'fieldType': json['fieldType'] == null ? undefined : json['fieldType'],
6378
6581
  'fieldHelp': json['fieldHelp'] == null ? undefined : json['fieldHelp'],
6379
6582
  'addToForms': json['addToForms'] == null ? undefined : json['addToForms'],
6380
6583
  'permissions': json['permissions'] == null ? undefined : json['permissions'],
@@ -6386,6 +6589,7 @@
6386
6589
  'findEnabled': json['findEnabled'] == null ? undefined : json['findEnabled'],
6387
6590
  'doesDataCopy': json['doesDataCopy'] == null ? undefined : json['doesDataCopy'],
6388
6591
  'audited': json['audited'] == null ? undefined : json['audited'],
6592
+ 'properties': json['properties'] == null ? undefined : CreateFieldRequestPropertiesFromJSON(json['properties']),
6389
6593
  };
6390
6594
  }
6391
6595
  function UpdateFieldRequestToJSON(json) {
@@ -6409,6 +6613,7 @@
6409
6613
  'findEnabled': value['findEnabled'],
6410
6614
  'doesDataCopy': value['doesDataCopy'],
6411
6615
  'audited': value['audited'],
6616
+ 'properties': CreateFieldRequestPropertiesToJSON(value['properties']),
6412
6617
  };
6413
6618
  }
6414
6619
 
@@ -9493,20 +9698,270 @@
9493
9698
  .replace(/^(\w)/, (_, c) => c.toLowerCase());
9494
9699
  }
9495
9700
 
9701
+ async function invokeMethod(methodName, params, methodMap, baseHeaders, tokenCache, fetchTempToken, transformDates, initialTempToken, userToken, useTempTokens, debug, convertDates, retryCount = 0, throttleBucket = null, maxRetries = 3, retryDelay = 1000) {
9702
+ const methodInfo = methodMap[methodName];
9703
+ if (!methodInfo)
9704
+ throw new Error(`Method ${methodName} not found`);
9705
+ const hasBody = "body" in params && params.body !== undefined;
9706
+ const body = hasBody ? params.body : undefined;
9707
+ const restParams = hasBody
9708
+ ? Object.fromEntries(Object.entries(params).filter(([key]) => key !== "body"))
9709
+ : { ...params };
9710
+ const requestParameters = {
9711
+ ...restParams,
9712
+ ...(hasBody ? { generated: body } : {}),
9713
+ };
9714
+ let requestOptions = {
9715
+ credentials: "omit",
9716
+ method: methodInfo.httpMethod,
9717
+ ...(hasBody ? { body } : {}),
9718
+ };
9719
+ const selectedToken = initialTempToken || (userToken && !useTempTokens ? userToken : undefined);
9720
+ let authorizationToken = selectedToken;
9721
+ if (methodName === "getTempTokenDBID" && useTempTokens) {
9722
+ const dbid = extractDbid(params, "No dbid provided for getTempTokenDBID");
9723
+ const cachedToken = tokenCache.get(dbid);
9724
+ if (cachedToken) {
9725
+ return Promise.resolve({
9726
+ temporaryAuthorization: cachedToken,
9727
+ });
9728
+ }
9729
+ }
9730
+ if (useTempTokens && !authorizationToken) {
9731
+ const dbid = extractDbid(params, `No dbid found in params for ${methodName} to fetch temp token`);
9732
+ const cachedToken = tokenCache.get(dbid);
9733
+ authorizationToken = cachedToken || (await fetchTempToken(dbid));
9734
+ if (methodName === "getTempTokenDBID") {
9735
+ return Promise.resolve({
9736
+ temporaryAuthorization: authorizationToken,
9737
+ });
9738
+ }
9739
+ }
9740
+ requestOptions.headers = authorizationToken
9741
+ ? {
9742
+ ...baseHeaders,
9743
+ Authorization: useTempTokens
9744
+ ? `QB-TEMP-TOKEN ${authorizationToken}`
9745
+ : `QB-USER-TOKEN ${authorizationToken}`,
9746
+ }
9747
+ : baseHeaders;
9748
+ if (debug) {
9749
+ console.log(`[${methodName}] requestParameters:`, requestParameters);
9750
+ console.log(`[${methodName}] requestOptions:`, requestOptions);
9751
+ }
9752
+ async function processResponse(rawResponse) {
9753
+ if (debug)
9754
+ console.log(`[${methodName}] rawResponse:`, rawResponse);
9755
+ if (rawResponse instanceof Response) {
9756
+ const contentType = rawResponse.headers
9757
+ .get("Content-Type")
9758
+ ?.toLowerCase();
9759
+ if (debug)
9760
+ console.log(`[${methodName}] contentType:`, contentType);
9761
+ if (contentType?.includes("application/octet-stream")) {
9762
+ return (await rawResponse.arrayBuffer());
9763
+ }
9764
+ if (contentType?.includes("application/x-yaml") ||
9765
+ contentType?.includes("text/yaml")) {
9766
+ return (await rawResponse.text());
9767
+ }
9768
+ if (contentType?.includes("application/json")) {
9769
+ const jsonResponse = await rawResponse.json();
9770
+ return transformDates(jsonResponse, convertDates);
9771
+ }
9772
+ return rawResponse;
9773
+ }
9774
+ if (rawResponse && typeof rawResponse.value === "function") {
9775
+ const response = await rawResponse.value();
9776
+ if (debug)
9777
+ console.log(`[${methodName}] Resolved JSONApiResponse:`, response);
9778
+ return transformDates(response, convertDates);
9779
+ }
9780
+ const transformed = transformDates(rawResponse, convertDates);
9781
+ if (debug)
9782
+ console.log(`[${methodName}] Transformed non-Response:`, transformed);
9783
+ return transformed;
9784
+ }
9785
+ async function withRetries(fn, options) {
9786
+ let attempt = 0;
9787
+ while (true) {
9788
+ try {
9789
+ if (throttleBucket) {
9790
+ if (debug)
9791
+ console.log(`[${methodName}] Awaiting throttle bucket`);
9792
+ await throttleBucket.acquire();
9793
+ if (debug)
9794
+ console.log(`[${methodName}] Throttle bucket acquired`);
9795
+ }
9796
+ return await fn();
9797
+ }
9798
+ catch (error) {
9799
+ console.log(`[${methodName}] Caught error:`, error);
9800
+ console.log(`[${methodName}] instanceof ResponseError:`, error instanceof ResponseError);
9801
+ console.log(`[${methodName}] Response status:`, error.response?.status);
9802
+ const effectiveError = error instanceof Object &&
9803
+ "cause" in error &&
9804
+ error.cause instanceof ResponseError
9805
+ ? error.cause
9806
+ : error instanceof ResponseError
9807
+ ? error
9808
+ : error;
9809
+ console.log(`[${methodName}] Effective error:`, effectiveError);
9810
+ console.log(`[${methodName}] Effective instanceof ResponseError:`, effectiveError instanceof ResponseError);
9811
+ console.log(`[${methodName}] Effective response status:`, effectiveError.response?.status);
9812
+ attempt++;
9813
+ if (!options.shouldRetry(effectiveError) ||
9814
+ attempt >= options.maxAttempts) {
9815
+ let errorMessage = effectiveError instanceof ResponseError
9816
+ ? effectiveError.message
9817
+ : String(error);
9818
+ console.log(`[${methodName}] No retry, throwing:`, errorMessage);
9819
+ if (effectiveError instanceof ResponseError &&
9820
+ effectiveError.response) {
9821
+ try {
9822
+ const errorBody = await effectiveError.response.json();
9823
+ if (debug)
9824
+ console.log(`[${methodName}] Error response body:`, errorBody);
9825
+ errorMessage = errorBody?.message || errorMessage;
9826
+ }
9827
+ catch (e) {
9828
+ if (debug)
9829
+ console.log(`[${methodName}] Failed to parse error body:`, e);
9830
+ }
9831
+ throw new Error(`API Error: ${errorMessage} (Status: ${effectiveError.response.status})`);
9832
+ }
9833
+ throw new Error(`API Error: ${errorMessage} (Status: unknown)`);
9834
+ }
9835
+ if (options.onRetry) {
9836
+ console.log(`[${methodName}] Retrying, attempt:`, attempt);
9837
+ await options.onRetry(effectiveError, attempt);
9838
+ }
9839
+ const delayMs = options.delay
9840
+ ? options.delay(attempt, effectiveError)
9841
+ : retryDelay * Math.pow(2, attempt - 1);
9842
+ if (debug)
9843
+ console.log(`[${methodName}] Retrying after ${delayMs}ms (attempt ${attempt}/${options.maxAttempts - 1})`);
9844
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
9845
+ }
9846
+ }
9847
+ }
9848
+ const mainPromise = withRetries(() => methodInfo
9849
+ .method(requestParameters, requestOptions)
9850
+ .then(processResponse), {
9851
+ maxAttempts: (useTempTokens ?? false) || userToken ? 2 : 1,
9852
+ shouldRetry: (error) => error instanceof ResponseError &&
9853
+ error.response?.status === 401 &&
9854
+ ((useTempTokens ?? false) ||
9855
+ (!!userToken && !(useTempTokens ?? false))),
9856
+ onRetry: async (error) => {
9857
+ if (error instanceof ResponseError && error.response?.status === 401) {
9858
+ if (useTempTokens ?? false) {
9859
+ if (debug)
9860
+ console.log(`Authorization error for ${methodName} (temp token), refreshing token:`, error.message);
9861
+ const dbid = extractDbid(params, `No dbid to refresh token after authorization error`);
9862
+ try {
9863
+ authorizationToken = await fetchTempToken(dbid);
9864
+ }
9865
+ catch (fetchError) {
9866
+ const fetchErrorMessage = fetchError instanceof ResponseError && fetchError.response
9867
+ ? (await fetchError.response.json())?.message ||
9868
+ "Unauthorized"
9869
+ : String(fetchError);
9870
+ throw new Error(`API Error: ${fetchErrorMessage} (Status: ${fetchError instanceof ResponseError &&
9871
+ fetchError.response?.status
9872
+ ? fetchError.response.status
9873
+ : "unknown"})`);
9874
+ }
9875
+ requestOptions.headers = {
9876
+ ...baseHeaders,
9877
+ Authorization: `QB-TEMP-TOKEN ${authorizationToken}`,
9878
+ };
9879
+ }
9880
+ else if (userToken) {
9881
+ if (debug)
9882
+ console.log(`Authorization error for ${methodName} (user token), retrying with same token:`, error.message);
9883
+ }
9884
+ if (debug)
9885
+ console.log(`Retrying ${methodName} with ${useTempTokens ? "temp" : "user"} token`);
9886
+ }
9887
+ },
9888
+ });
9889
+ return mainPromise.catch((error) => {
9890
+ let effectiveError = error;
9891
+ if (error instanceof Object &&
9892
+ "cause" in error &&
9893
+ error.cause instanceof ResponseError) {
9894
+ effectiveError = error.cause;
9895
+ }
9896
+ else if (error instanceof ResponseError) {
9897
+ effectiveError = error;
9898
+ }
9899
+ if (effectiveError instanceof ResponseError &&
9900
+ effectiveError.response?.status === 429) {
9901
+ return withRetries(() => Promise.reject(error), {
9902
+ maxAttempts: maxRetries + 1,
9903
+ shouldRetry: (err) => err instanceof ResponseError && err.response?.status === 429,
9904
+ delay: (attempt, err) => {
9905
+ const headers = err instanceof ResponseError && err.response
9906
+ ? err.response.headers
9907
+ : new Headers();
9908
+ const retryAfter = headers.get("Retry-After");
9909
+ return retryAfter
9910
+ ? parseInt(retryAfter, 10) * 1000
9911
+ : retryDelay * Math.pow(2, attempt - 1);
9912
+ },
9913
+ });
9914
+ }
9915
+ throw effectiveError;
9916
+ });
9917
+ }
9918
+ function extractDbid(params, errorMessage) {
9919
+ const dbid = params.dbid || params.tableId || params.appId;
9920
+ if (!dbid)
9921
+ throw new Error(errorMessage);
9922
+ return dbid;
9923
+ }
9924
+
9925
+ // src/TokenBucket.ts
9926
+ class ThrottleBucket {
9927
+ tokens;
9928
+ maxTokens;
9929
+ refillRate; // Tokens per second
9930
+ lastRefill;
9931
+ constructor(rate, burst) {
9932
+ this.tokens = burst; // Start with full burst capacity
9933
+ this.maxTokens = burst;
9934
+ this.refillRate = rate;
9935
+ this.lastRefill = Date.now();
9936
+ }
9937
+ // Refill tokens based on elapsed time
9938
+ refill() {
9939
+ const now = Date.now();
9940
+ const elapsed = (now - this.lastRefill) / 1000; // Seconds elapsed
9941
+ const newTokens = elapsed * this.refillRate;
9942
+ this.tokens = Math.min(this.maxTokens, this.tokens + newTokens);
9943
+ this.lastRefill = now;
9944
+ }
9945
+ // Acquire a token, waiting if necessary
9946
+ async acquire() {
9947
+ this.refill();
9948
+ if (this.tokens >= 1) {
9949
+ this.tokens -= 1;
9950
+ return;
9951
+ }
9952
+ const waitTime = ((1 - this.tokens) / this.refillRate) * 1000; // ms until next token
9953
+ await new Promise((resolve) => setTimeout(resolve, waitTime));
9954
+ this.refill();
9955
+ this.tokens -= 1;
9956
+ }
9957
+ }
9958
+
9496
9959
  const getParamNames = (fn) => fn
9497
9960
  .toString()
9498
9961
  .slice(fn.toString().indexOf("(") + 1, fn.toString().indexOf(")"))
9499
9962
  .split(",")
9500
9963
  .map((p) => p.trim().split("=")[0]?.trim())
9501
9964
  .filter((p) => p && !p.match(/^\{/) && p !== "options");
9502
- const extractDbid = (params, errorMessage) => {
9503
- const dbid = params.dbid || params.tableId || params.appId;
9504
- if (!dbid) {
9505
- throw new Error(errorMessage);
9506
- }
9507
- return dbid;
9508
- };
9509
- // Utility to convert ISO date strings to Date objects recursively, with optional conversion
9510
9965
  function transformDates(obj, convertStringsToDates = true) {
9511
9966
  if (obj === null || obj === undefined)
9512
9967
  return obj;
@@ -9528,11 +9983,18 @@
9528
9983
  }
9529
9984
  return obj;
9530
9985
  }
9986
+ function inferHttpMethod(methodSource, debug) {
9987
+ const methodMatch = methodSource.match(/method:\s*['"]?(\w+)['"]?/i);
9988
+ const method = methodMatch ? methodMatch[1].toUpperCase() : "GET";
9989
+ return method;
9990
+ }
9531
9991
  function quickbase(config) {
9532
- const { realm, userToken, tempToken: initialTempToken, useTempTokens, fetchApi, debug, convertDates = true, // Default to true for backward compatibility
9533
- } = config;
9992
+ const { realm, userToken, tempToken: initialTempToken, useTempTokens, fetchApi, debug, convertDates = true, tokenLifespan, throttle = { rate: 10, burst: 10 }, maxRetries = 3, retryDelay = 1000, } = config;
9534
9993
  const baseUrl = `https://api.quickbase.com/v1`;
9535
- const tokenCache = new TokenCache();
9994
+ const tokenCache = new TokenCache(tokenLifespan);
9995
+ const throttleBucket = throttle
9996
+ ? new ThrottleBucket(throttle.rate, throttle.burst)
9997
+ : null;
9536
9998
  const baseHeaders = {
9537
9999
  "QB-Realm-Hostname": `${realm}.quickbase.com`,
9538
10000
  "Content-Type": "application/json",
@@ -9573,13 +10035,16 @@
9573
10035
  typeof api[name] === "function")
9574
10036
  .forEach((rawMethodName) => {
9575
10037
  const simplifiedName = simplifyName(rawMethodName);
9576
- const method = api[rawMethodName];
10038
+ const rawMethodKey = `${rawMethodName}Raw`;
10039
+ const method = api[rawMethodKey] || api[rawMethodName];
9577
10040
  const boundMethod = method.bind(api);
9578
10041
  if (typeof boundMethod === "function" && boundMethod.length <= 2) {
10042
+ const methodSource = method.toString();
9579
10043
  methodMap[simplifiedName] = {
9580
10044
  api,
9581
- method: boundMethod,
10045
+ method: boundMethod, // Adjust typing as needed
9582
10046
  paramMap: getParamNames(method),
10047
+ httpMethod: inferHttpMethod(methodSource),
9583
10048
  };
9584
10049
  }
9585
10050
  });
@@ -9611,138 +10076,12 @@
9611
10076
  }
9612
10077
  return token;
9613
10078
  };
9614
- async function invokeMethod(methodName, params, retryCount = 0) {
9615
- const methodInfo = methodMap[methodName];
9616
- if (!methodInfo) {
9617
- throw new Error(`Method ${methodName} not found`);
9618
- }
9619
- // Safely handle body extraction
9620
- const hasBody = "body" in params && params.body !== undefined;
9621
- const body = hasBody ? params.body : undefined;
9622
- const restParams = hasBody
9623
- ? Object.fromEntries(Object.entries(params).filter(([key]) => key !== "body"))
9624
- : { ...params };
9625
- // Construct requestParameters with 'generated' for body
9626
- const requestParameters = {
9627
- ...restParams,
9628
- ...(body ? { generated: { ...body } } : {}),
9629
- };
9630
- let requestOptions = {
9631
- credentials: "omit",
9632
- };
9633
- const selectedToken = initialTempToken || (userToken && !useTempTokens ? userToken : undefined);
9634
- if (methodName === "getTempTokenDBID" && useTempTokens) {
9635
- const dbid = extractDbid(params, "No dbid provided for getTempTokenDBID");
9636
- const cachedToken = tokenCache.get(dbid);
9637
- if (cachedToken) {
9638
- return { temporaryAuthorization: cachedToken };
9639
- }
9640
- }
9641
- let authorizationToken = selectedToken;
9642
- if (useTempTokens && !authorizationToken) {
9643
- const dbid = extractDbid(params, `No dbid found in params for ${methodName} to fetch temp token`);
9644
- const cachedToken = tokenCache.get(dbid);
9645
- authorizationToken = cachedToken || (await fetchTempToken(dbid));
9646
- if (methodName === "getTempTokenDBID") {
9647
- return { temporaryAuthorization: authorizationToken };
9648
- }
9649
- requestOptions.headers = {
9650
- ...baseHeaders,
9651
- Authorization: `QB-TEMP-TOKEN ${authorizationToken}`,
9652
- };
9653
- }
9654
- else if (authorizationToken) {
9655
- requestOptions.headers = {
9656
- ...baseHeaders,
9657
- Authorization: `QB-USER-TOKEN ${authorizationToken}`,
9658
- };
9659
- }
9660
- if (debug) {
9661
- console.log(`[${methodName}] requestParameters:`, requestParameters);
9662
- console.log(`[${methodName}] requestOptions:`, requestOptions);
9663
- }
9664
- try {
9665
- const response = await methodInfo.method(requestParameters, requestOptions);
9666
- if (debug) {
9667
- console.log(`[${methodName}] rawResponse:`, response);
9668
- }
9669
- if (response instanceof Response) {
9670
- const contentType = response.headers.get("Content-Type")?.toLowerCase();
9671
- if (debug) {
9672
- console.log(`[${methodName}] contentType:`, contentType);
9673
- }
9674
- if (contentType?.includes("application/octet-stream")) {
9675
- return (await response.arrayBuffer());
9676
- }
9677
- else if (contentType?.includes("application/x-yaml") ||
9678
- contentType?.includes("text/yaml")) {
9679
- return (await response.text());
9680
- }
9681
- else if (contentType?.includes("application/json")) {
9682
- const jsonResponse = await response.json();
9683
- if (debug) {
9684
- console.log(`[${methodName}] jsonResponse:`, jsonResponse);
9685
- }
9686
- const transformedResponse = transformDates(jsonResponse, convertDates);
9687
- if (debug) {
9688
- console.log(`[${methodName}] transformedResponse:`, transformedResponse);
9689
- }
9690
- return transformedResponse;
9691
- }
9692
- return response;
9693
- }
9694
- else {
9695
- if (debug) {
9696
- console.log(`[${methodName}] non-Response return, applying transform:`, response);
9697
- }
9698
- const transformedResponse = transformDates(response, convertDates);
9699
- if (debug) {
9700
- console.log(`[${methodName}] transformedNonResponse:`, transformedResponse);
9701
- }
9702
- return transformedResponse;
9703
- }
9704
- }
9705
- catch (error) {
9706
- if (error instanceof ResponseError &&
9707
- error.response.status === 401 &&
9708
- retryCount < 1 &&
9709
- useTempTokens) {
9710
- if (debug) {
9711
- console.log(`Authorization error for ${methodName}, refreshing token:`, error.message);
9712
- }
9713
- const dbid = extractDbid(params, `No dbid to refresh token after authorization error`);
9714
- authorizationToken = await fetchTempToken(dbid);
9715
- requestOptions.headers = {
9716
- ...baseHeaders,
9717
- Authorization: `QB-TEMP-TOKEN ${authorizationToken}`,
9718
- };
9719
- if (debug) {
9720
- console.log(`Retrying ${methodName} with new token`);
9721
- }
9722
- return invokeMethod(methodName, params, retryCount + 1);
9723
- }
9724
- if (error instanceof ResponseError) {
9725
- let errorMessage = error.message;
9726
- try {
9727
- const errorBody = await error.response.json();
9728
- if (debug) {
9729
- console.log(`Error response body for ${methodName}:`, errorBody);
9730
- }
9731
- errorMessage = errorBody.message || errorMessage;
9732
- }
9733
- catch (e) {
9734
- // Silent fail on parse error
9735
- }
9736
- throw new Error(`API Error: ${errorMessage} (Status: ${error.response.status})`);
9737
- }
9738
- throw error;
9739
- }
9740
- }
9741
10079
  const proxy = new Proxy({}, {
9742
10080
  get: (_, prop) => {
9743
10081
  if (prop in methodMap) {
9744
10082
  const methodName = prop;
9745
- return (params) => invokeMethod(methodName, params);
10083
+ return (params) => invokeMethod(methodName, params, methodMap, baseHeaders, tokenCache, fetchTempToken, transformDates, initialTempToken, userToken, useTempTokens, debug, convertDates, 0, // retryCount
10084
+ throttleBucket, maxRetries, retryDelay);
9746
10085
  }
9747
10086
  return undefined;
9748
10087
  },
@@ -9873,6 +10212,14 @@
9873
10212
  exports.CreateFieldRequestFieldTypeEnum = CreateFieldRequestFieldTypeEnum;
9874
10213
  exports.CreateFieldRequestFromJSON = CreateFieldRequestFromJSON;
9875
10214
  exports.CreateFieldRequestFromJSONTyped = CreateFieldRequestFromJSONTyped;
10215
+ exports.CreateFieldRequestPropertiesCurrencyFormatEnum = CreateFieldRequestPropertiesCurrencyFormatEnum;
10216
+ exports.CreateFieldRequestPropertiesFromJSON = CreateFieldRequestPropertiesFromJSON;
10217
+ exports.CreateFieldRequestPropertiesFromJSONTyped = CreateFieldRequestPropertiesFromJSONTyped;
10218
+ exports.CreateFieldRequestPropertiesOpenTargetInEnum = CreateFieldRequestPropertiesOpenTargetInEnum;
10219
+ exports.CreateFieldRequestPropertiesSummaryFunctionEnum = CreateFieldRequestPropertiesSummaryFunctionEnum;
10220
+ exports.CreateFieldRequestPropertiesToJSON = CreateFieldRequestPropertiesToJSON;
10221
+ exports.CreateFieldRequestPropertiesToJSONTyped = CreateFieldRequestPropertiesToJSONTyped;
10222
+ exports.CreateFieldRequestPropertiesVersionModeEnum = CreateFieldRequestPropertiesVersionModeEnum;
9876
10223
  exports.CreateFieldRequestToJSON = CreateFieldRequestToJSON;
9877
10224
  exports.CreateFieldRequestToJSONTyped = CreateFieldRequestToJSONTyped;
9878
10225
  exports.CreateRelationship200ResponseFromJSON = CreateRelationship200ResponseFromJSON;
@@ -10381,6 +10728,7 @@
10381
10728
  exports.instanceOfCreateAppRequest = instanceOfCreateAppRequest;
10382
10729
  exports.instanceOfCreateField200Response = instanceOfCreateField200Response;
10383
10730
  exports.instanceOfCreateFieldRequest = instanceOfCreateFieldRequest;
10731
+ exports.instanceOfCreateFieldRequestProperties = instanceOfCreateFieldRequestProperties;
10384
10732
  exports.instanceOfCreateRelationship200Response = instanceOfCreateRelationship200Response;
10385
10733
  exports.instanceOfCreateRelationshipRequest = instanceOfCreateRelationshipRequest;
10386
10734
  exports.instanceOfCreateSolution200Response = instanceOfCreateSolution200Response;