@zapier/kitcore 0.17.1 → 0.18.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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # @zapier/kitcore
2
2
 
3
+ ## 0.18.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2c8ea56: **Added `httpFetchPluginRef` (`kitcore/httpFetch`), the function
8
+ `dispatchHttpRequest` calls to reach the network.** Provide it and the default
9
+ dispatch stage calls that function instead of the ambient `fetch` — a
10
+ debug-wrapped fetch, a test double, a polyfill. Provide nothing and the stage
11
+ behaves as before.
12
+
13
+ ```ts
14
+ const httpFetch = defineProperty({
15
+ namespace: "kitcore",
16
+ name: "httpFetch",
17
+ value: myFetch,
18
+ });
19
+
20
+ // Or supply it by id, with no plugin of your own:
21
+ createSdk(root, { configuration: { [HTTP_FETCH_ID]: myFetch } });
22
+ ```
23
+
24
+ It is a value rather than a wrap, so the `dispatchHttpRequest` wrap slot stays
25
+ free for a host that replaces the stage outright.
26
+
27
+ ## 0.17.2
28
+
29
+ ### Patch Changes
30
+
31
+ - 173df80: `retryHttpRequestPlugin` now reads `X-RateLimit-Reset` values under 1e9 as seconds until the window resets (the IETF draft convention, sent by rate limiters like `@fastify/rate-limit` and Envoy) instead of always as an epoch timestamp. Previously a delta value was read as a date in 1970, the computed wait clamped to zero, and every remaining attempt resent immediately. Now the retry waits as directed, and a delta beyond `maxDelayMilliseconds` gives up and returns the 429 instead of hammering. Epoch-style values (1e9 and above, e.g. GitHub's) behave as before.
32
+
33
+ `X-RateLimit-Reset` now directs the delay only on a 429. Rate limiters attach `x-ratelimit-*` headers to every response passing through them, so on a 5xx the value describes the quota window rather than the outage; those retries now use `Retry-After` when present or exponential backoff.
34
+
3
35
  ## 0.17.1
4
36
 
5
37
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -29,6 +29,7 @@ __export(index_exports, {
29
29
  CoreError: () => CoreError,
30
30
  CoreErrorCode: () => CoreErrorCode,
31
31
  CoreSignal: () => CoreSignal,
32
+ HTTP_FETCH_ID: () => HTTP_FETCH_ID,
32
33
  RETRY_HTTP_REQUEST_OPTIONS_ID: () => RETRY_HTTP_REQUEST_OPTIONS_ID,
33
34
  STABILITY_LEVELS: () => STABILITY_LEVELS,
34
35
  STABILITY_TITLES: () => STABILITY_TITLES,
@@ -89,6 +90,7 @@ __export(index_exports, {
89
90
  getRegistry: () => getRegistry,
90
91
  getRegistryPlugin: () => getRegistryPlugin,
91
92
  getSchemaDescription: () => getSchemaDescription,
93
+ httpFetchPluginRef: () => httpFetchPluginRef,
92
94
  initializeHttpRequestPlugin: () => initializeHttpRequestPlugin,
93
95
  isCoreCancelledSignal: () => isCoreCancelledSignal,
94
96
  isCoreError: () => isCoreError,
@@ -4944,6 +4946,8 @@ var authorizeHttpRequestPlugin = defineMethod({
4944
4946
 
4945
4947
  // src/transport/dispatch-http-request.ts
4946
4948
  var import_zod7 = require("zod");
4949
+ var HTTP_FETCH_ID = "kitcore/httpFetch";
4950
+ var httpFetchPluginRef = declareOptionalProperty({ id: HTTP_FETCH_ID });
4947
4951
  function toFetchInput(request) {
4948
4952
  const init = { ...request };
4949
4953
  const { url } = request;
@@ -4954,11 +4958,12 @@ function toFetchInput(request) {
4954
4958
  var dispatchHttpRequestPlugin = defineMethod({
4955
4959
  name: "dispatchHttpRequest",
4956
4960
  namespace: "kitcore",
4961
+ imports: [httpFetchPluginRef],
4957
4962
  inputSchema: import_zod7.z.custom(),
4958
4963
  skipInputValidation: true,
4959
- run: async ({ input }) => {
4964
+ run: async ({ input, imports }) => {
4960
4965
  const { url, init } = toFetchInput(input.request);
4961
- return fetch(url, init);
4966
+ return (imports.httpFetch ?? fetch)(url, init);
4962
4967
  }
4963
4968
  });
4964
4969
 
@@ -5058,6 +5063,7 @@ var DEFAULT_IDEMPOTENT_METHODS = [
5058
5063
  ];
5059
5064
  var BASE_BACKOFF_MILLISECONDS = 1e3;
5060
5065
  var JITTER_FACTOR = 0.5;
5066
+ var EPOCH_THRESHOLD_SECONDS = 1e9;
5061
5067
  function directedDelayMilliseconds(response) {
5062
5068
  const retryAfter = response.headers.get("retry-after");
5063
5069
  if (retryAfter) {
@@ -5066,11 +5072,12 @@ function directedDelayMilliseconds(response) {
5066
5072
  const date = Date.parse(retryAfter);
5067
5073
  if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
5068
5074
  }
5075
+ if (response.status !== 429) return void 0;
5069
5076
  const reset = response.headers.get("x-ratelimit-reset");
5070
5077
  if (reset) {
5071
- const resetSeconds = Number.parseInt(reset, 10);
5072
- if (!Number.isNaN(resetSeconds)) {
5073
- return Math.max(0, resetSeconds * 1e3 - Date.now());
5078
+ const resetValue = Number.parseInt(reset, 10);
5079
+ if (!Number.isNaN(resetValue)) {
5080
+ return resetValue >= EPOCH_THRESHOLD_SECONDS ? Math.max(0, resetValue * 1e3 - Date.now()) : Math.max(0, resetValue * 1e3);
5074
5081
  }
5075
5082
  }
5076
5083
  return void 0;
@@ -5309,6 +5316,7 @@ var resolveConnectionPlugin = defineMethod({
5309
5316
  CoreError,
5310
5317
  CoreErrorCode,
5311
5318
  CoreSignal,
5319
+ HTTP_FETCH_ID,
5312
5320
  RETRY_HTTP_REQUEST_OPTIONS_ID,
5313
5321
  STABILITY_LEVELS,
5314
5322
  STABILITY_TITLES,
@@ -5369,6 +5377,7 @@ var resolveConnectionPlugin = defineMethod({
5369
5377
  getRegistry,
5370
5378
  getRegistryPlugin,
5371
5379
  getSchemaDescription,
5380
+ httpFetchPluginRef,
5372
5381
  initializeHttpRequestPlugin,
5373
5382
  isCoreCancelledSignal,
5374
5383
  isCoreError,