@zapier/kitcore 0.13.0 → 0.15.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 +55 -0
- package/dist/index.cjs +519 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +497 -7
- package/dist/index.d.ts +497 -7
- package/dist/index.mjs +498 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -89,6 +89,28 @@ function openEnum(values, description) {
|
|
|
89
89
|
return z.union([z.enum(values), z.string()]).describe(description);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
// src/utils/stability.ts
|
|
93
|
+
var STABILITY_LEVELS = ["stable", "beta", "experimental"];
|
|
94
|
+
var STABILITY_TITLES = {
|
|
95
|
+
stable: "Stable",
|
|
96
|
+
beta: "Beta",
|
|
97
|
+
experimental: "Experimental"
|
|
98
|
+
};
|
|
99
|
+
function normalizeStability(meta) {
|
|
100
|
+
if (meta.stability !== void 0) {
|
|
101
|
+
return STABILITY_LEVELS.includes(meta.stability) ? meta.stability : "experimental";
|
|
102
|
+
}
|
|
103
|
+
return meta.experimental ? "experimental" : "stable";
|
|
104
|
+
}
|
|
105
|
+
function applyStabilityLabel({
|
|
106
|
+
description,
|
|
107
|
+
stability,
|
|
108
|
+
placement = "suffix"
|
|
109
|
+
}) {
|
|
110
|
+
if (stability === void 0 || stability === "stable") return description;
|
|
111
|
+
return placement === "prefix" ? `[${STABILITY_TITLES[stability]}] ${description}` : `${description} (${stability})`;
|
|
112
|
+
}
|
|
113
|
+
|
|
92
114
|
// src/registry.ts
|
|
93
115
|
function resolveCategoryDefinition(ref) {
|
|
94
116
|
const def = typeof ref === "string" ? { key: ref } : ref;
|
|
@@ -133,6 +155,7 @@ function buildRegistry({
|
|
|
133
155
|
return typeof rootProperty === "object" && rootProperty !== null;
|
|
134
156
|
}).map((key) => {
|
|
135
157
|
const m = meta[key];
|
|
158
|
+
const stability = normalizeStability(m);
|
|
136
159
|
return {
|
|
137
160
|
name: key,
|
|
138
161
|
description: m.description,
|
|
@@ -148,7 +171,11 @@ function buildRegistry({
|
|
|
148
171
|
),
|
|
149
172
|
resolvers: resolvers?.[key],
|
|
150
173
|
formatter: formatters?.[key],
|
|
151
|
-
|
|
174
|
+
stability,
|
|
175
|
+
// Deprecated derived read, literal by name: only the experimental
|
|
176
|
+
// tier reads true. Beta reads false — the "not stable" warning duty
|
|
177
|
+
// lives in `stability` and the runtime notice, not this boolean.
|
|
178
|
+
experimental: stability === "experimental",
|
|
152
179
|
packages: m.packages,
|
|
153
180
|
confirm: m.confirm ?? (m.type === "delete" ? "delete" : void 0),
|
|
154
181
|
deprecation: m.deprecation,
|
|
@@ -237,6 +264,20 @@ function createDeprecationLogger(tag) {
|
|
|
237
264
|
};
|
|
238
265
|
}
|
|
239
266
|
var { logDeprecation, resetDeprecationWarnings } = createDeprecationLogger("core");
|
|
267
|
+
function createStabilityNoticeLogger(tag) {
|
|
268
|
+
const loggedNotices = /* @__PURE__ */ new Set();
|
|
269
|
+
return {
|
|
270
|
+
logStabilityNotice(message) {
|
|
271
|
+
if (loggedNotices.has(message)) return;
|
|
272
|
+
loggedNotices.add(message);
|
|
273
|
+
console.warn(`[${tag}] ${message}`);
|
|
274
|
+
},
|
|
275
|
+
resetStabilityNotices() {
|
|
276
|
+
loggedNotices.clear();
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
var { logStabilityNotice, resetStabilityNotices } = createStabilityNoticeLogger("core");
|
|
240
281
|
|
|
241
282
|
// src/types/errors.ts
|
|
242
283
|
var CORE_ERROR_SYMBOL = Symbol.for("kitcore.error");
|
|
@@ -721,6 +762,19 @@ function defaultLogDeprecation({
|
|
|
721
762
|
}) {
|
|
722
763
|
logDeprecation(`${methodName}() is deprecated. ${deprecation.message}`);
|
|
723
764
|
}
|
|
765
|
+
var STABILITY_NOTICE_DETAILS = {
|
|
766
|
+
beta: "Its API shape is settled, but it is not yet covered by stable-tier guarantees.",
|
|
767
|
+
experimental: "It may change shape or disappear without notice."
|
|
768
|
+
};
|
|
769
|
+
function defaultLogStabilityNotice({
|
|
770
|
+
methodName,
|
|
771
|
+
stability
|
|
772
|
+
}) {
|
|
773
|
+
if (stability === "stable") return;
|
|
774
|
+
logStabilityNotice(
|
|
775
|
+
`${methodName}() is a ${stability} API. ${STABILITY_NOTICE_DETAILS[stability]}`
|
|
776
|
+
);
|
|
777
|
+
}
|
|
724
778
|
var CORE_OPTIONS_ID = "kitcore/coreOptions";
|
|
725
779
|
|
|
726
780
|
// src/utils/function-utils.ts
|
|
@@ -769,6 +823,18 @@ function signalDeprecation(context, methodName, getDeprecation) {
|
|
|
769
823
|
const handler = resolveCoreOptions(context)?.logDeprecation ?? defaultLogDeprecation;
|
|
770
824
|
runIsolatedObserver(() => handler(warning));
|
|
771
825
|
}
|
|
826
|
+
function signalStability(context, methodName, getStability) {
|
|
827
|
+
if (isInsideObserver()) return;
|
|
828
|
+
const stability = getStability?.();
|
|
829
|
+
if (!stability || stability === "stable") return;
|
|
830
|
+
const notice = {
|
|
831
|
+
type: "stability",
|
|
832
|
+
methodName,
|
|
833
|
+
stability
|
|
834
|
+
};
|
|
835
|
+
const handler = resolveCoreOptions(context)?.logStabilityNotice ?? defaultLogStabilityNotice;
|
|
836
|
+
runIsolatedObserver(() => handler(notice));
|
|
837
|
+
}
|
|
772
838
|
function normalizeError(error, adaptError) {
|
|
773
839
|
if (error instanceof Error) return error;
|
|
774
840
|
const message = typeof error === "object" && error !== null && "message" in error && typeof error.message === "string" ? error.message : String(error);
|
|
@@ -782,7 +848,7 @@ function normalizeError(error, adaptError) {
|
|
|
782
848
|
);
|
|
783
849
|
}
|
|
784
850
|
function createFunction(coreFn, options) {
|
|
785
|
-
const { sdk, schema, name, annotator, getDeprecation } = options;
|
|
851
|
+
const { sdk, schema, name, annotator, getDeprecation, getStability } = options;
|
|
786
852
|
const functionName = name || coreFn.name;
|
|
787
853
|
const namedFunctions = {
|
|
788
854
|
[functionName]: async function(callOptions) {
|
|
@@ -790,6 +856,7 @@ function createFunction(coreFn, options) {
|
|
|
790
856
|
const context = resolveCallContext(internal);
|
|
791
857
|
if (!isCallContext(internal) && internal !== INTERNAL_CALL) {
|
|
792
858
|
signalDeprecation(sdk.context, functionName, getDeprecation);
|
|
859
|
+
signalStability(sdk.context, functionName, getStability);
|
|
793
860
|
}
|
|
794
861
|
return runInMethodScope(async () => {
|
|
795
862
|
const startTime = Date.now();
|
|
@@ -856,12 +923,21 @@ function createFunction(coreFn, options) {
|
|
|
856
923
|
return namedFunctions[functionName];
|
|
857
924
|
}
|
|
858
925
|
function createRawFunction(coreFn, options) {
|
|
859
|
-
const {
|
|
926
|
+
const {
|
|
927
|
+
sdk,
|
|
928
|
+
name,
|
|
929
|
+
schema,
|
|
930
|
+
positional,
|
|
931
|
+
annotator,
|
|
932
|
+
getDeprecation,
|
|
933
|
+
getStability
|
|
934
|
+
} = options;
|
|
860
935
|
return function(rawInput) {
|
|
861
936
|
const internal = arguments[1];
|
|
862
937
|
const context = resolveCallContext(internal);
|
|
863
938
|
if (!isCallContext(internal) && internal !== INTERNAL_CALL) {
|
|
864
939
|
signalDeprecation(sdk.context, name, getDeprecation);
|
|
940
|
+
signalStability(sdk.context, name, getStability);
|
|
865
941
|
}
|
|
866
942
|
return runInMethodScope(() => {
|
|
867
943
|
const startTime = Date.now();
|
|
@@ -967,7 +1043,8 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
967
1043
|
adaptPage,
|
|
968
1044
|
annotator,
|
|
969
1045
|
finalizePage,
|
|
970
|
-
getDeprecation
|
|
1046
|
+
getDeprecation,
|
|
1047
|
+
getStability
|
|
971
1048
|
} = options;
|
|
972
1049
|
const pageFunction = createPageFunction(coreFn, {
|
|
973
1050
|
sdk,
|
|
@@ -981,6 +1058,7 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
981
1058
|
const context = resolveCallContext(internal);
|
|
982
1059
|
if (!isCallContext(internal) && internal !== INTERNAL_CALL) {
|
|
983
1060
|
signalDeprecation(sdk.context, functionName, getDeprecation);
|
|
1061
|
+
signalStability(sdk.context, functionName, getStability);
|
|
984
1062
|
}
|
|
985
1063
|
return runInMethodScope(() => {
|
|
986
1064
|
const startTime = Date.now();
|
|
@@ -1425,6 +1503,7 @@ var LEAF_META_KEYS = [
|
|
|
1425
1503
|
"returnType",
|
|
1426
1504
|
"outputSchema",
|
|
1427
1505
|
"packages",
|
|
1506
|
+
"stability",
|
|
1428
1507
|
"experimental",
|
|
1429
1508
|
"confirm",
|
|
1430
1509
|
"deprecation",
|
|
@@ -2692,7 +2771,8 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2692
2771
|
// (item mode's sibling); dropped paths surface as `[].x` in the page's
|
|
2693
2772
|
// `meta`, unioned across items.
|
|
2694
2773
|
finalizePage: (page) => applyListOutputPolicy(page, outputPolicy()),
|
|
2695
|
-
getDeprecation: () => entry.meta?.deprecation
|
|
2774
|
+
getDeprecation: () => entry.meta?.deprecation,
|
|
2775
|
+
getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
|
|
2696
2776
|
}
|
|
2697
2777
|
);
|
|
2698
2778
|
} else if (out.type === "item") {
|
|
@@ -2704,7 +2784,8 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2704
2784
|
schema: descriptor.inputSchema,
|
|
2705
2785
|
name: descriptor.name,
|
|
2706
2786
|
annotator: boundAnnotator,
|
|
2707
|
-
getDeprecation: () => entry.meta?.deprecation
|
|
2787
|
+
getDeprecation: () => entry.meta?.deprecation,
|
|
2788
|
+
getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
|
|
2708
2789
|
}
|
|
2709
2790
|
);
|
|
2710
2791
|
} else {
|
|
@@ -2718,8 +2799,10 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2718
2799
|
annotator: boundAnnotator,
|
|
2719
2800
|
// The boundary reads the deprecation LIVE off the entry, so a
|
|
2720
2801
|
// deprecation merged after build (defineMethodOverride, addPlugin)
|
|
2721
|
-
// fires too.
|
|
2722
|
-
|
|
2802
|
+
// fires too. Same for the stability level, normalized from the
|
|
2803
|
+
// entry meta (declared level or legacy `experimental` boolean).
|
|
2804
|
+
getDeprecation: () => entry.meta?.deprecation,
|
|
2805
|
+
getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
|
|
2723
2806
|
}
|
|
2724
2807
|
);
|
|
2725
2808
|
}
|
|
@@ -4382,6 +4465,392 @@ function createCorePlugin(options) {
|
|
|
4382
4465
|
}
|
|
4383
4466
|
});
|
|
4384
4467
|
}
|
|
4468
|
+
|
|
4469
|
+
// src/transport/attempt-http-request.ts
|
|
4470
|
+
import { z as z9 } from "zod";
|
|
4471
|
+
|
|
4472
|
+
// src/transport/authorize-http-request.ts
|
|
4473
|
+
import { z as z5 } from "zod";
|
|
4474
|
+
function describeUnclaimedConnection(connection) {
|
|
4475
|
+
const delimiterIndex = connection.indexOf(":");
|
|
4476
|
+
if (delimiterIndex === -1) {
|
|
4477
|
+
return 'no auth provider claimed this connection, and it carries no "scheme:" prefix';
|
|
4478
|
+
}
|
|
4479
|
+
return `no auth provider claimed the "${connection.slice(0, delimiterIndex)}" connection scheme`;
|
|
4480
|
+
}
|
|
4481
|
+
var authorizeHttpRequestPlugin = defineMethod({
|
|
4482
|
+
name: "authorizeHttpRequest",
|
|
4483
|
+
namespace: "kitcore",
|
|
4484
|
+
inputSchema: z5.custom(),
|
|
4485
|
+
skipInputValidation: true,
|
|
4486
|
+
run: async ({ input }) => {
|
|
4487
|
+
const { connection } = input.request;
|
|
4488
|
+
if (connection != null) {
|
|
4489
|
+
throw createCoreError({
|
|
4490
|
+
code: CoreErrorCode.Unknown,
|
|
4491
|
+
message: `authorizeHttpRequest: ${describeUnclaimedConnection(connection)}, so the request was not sent.`
|
|
4492
|
+
});
|
|
4493
|
+
}
|
|
4494
|
+
return input.request;
|
|
4495
|
+
}
|
|
4496
|
+
});
|
|
4497
|
+
|
|
4498
|
+
// src/transport/dispatch-http-request.ts
|
|
4499
|
+
import { z as z6 } from "zod";
|
|
4500
|
+
function toFetchInput(request) {
|
|
4501
|
+
const init = { ...request };
|
|
4502
|
+
const { url } = request;
|
|
4503
|
+
delete init.url;
|
|
4504
|
+
delete init.connection;
|
|
4505
|
+
return { url, init };
|
|
4506
|
+
}
|
|
4507
|
+
var dispatchHttpRequestPlugin = defineMethod({
|
|
4508
|
+
name: "dispatchHttpRequest",
|
|
4509
|
+
namespace: "kitcore",
|
|
4510
|
+
inputSchema: z6.custom(),
|
|
4511
|
+
skipInputValidation: true,
|
|
4512
|
+
run: async ({ input }) => {
|
|
4513
|
+
const { url, init } = toFetchInput(input.request);
|
|
4514
|
+
return fetch(url, init);
|
|
4515
|
+
}
|
|
4516
|
+
});
|
|
4517
|
+
|
|
4518
|
+
// src/transport/prepare-http-request.ts
|
|
4519
|
+
import { z as z7 } from "zod";
|
|
4520
|
+
var prepareHttpRequestPlugin = defineMethod({
|
|
4521
|
+
name: "prepareHttpRequest",
|
|
4522
|
+
namespace: "kitcore",
|
|
4523
|
+
inputSchema: z7.custom(),
|
|
4524
|
+
skipInputValidation: true,
|
|
4525
|
+
run: async ({ input }) => input.request
|
|
4526
|
+
});
|
|
4527
|
+
|
|
4528
|
+
// src/transport/receive-http-response.ts
|
|
4529
|
+
import { z as z8 } from "zod";
|
|
4530
|
+
var receiveHttpResponsePlugin = defineMethod({
|
|
4531
|
+
name: "receiveHttpResponse",
|
|
4532
|
+
namespace: "kitcore",
|
|
4533
|
+
inputSchema: z8.custom(),
|
|
4534
|
+
skipInputValidation: true,
|
|
4535
|
+
run: async ({ input }) => input.response
|
|
4536
|
+
});
|
|
4537
|
+
|
|
4538
|
+
// src/transport/attempt-http-request.ts
|
|
4539
|
+
var attemptHttpRequestPlugin = defineMethod({
|
|
4540
|
+
name: "attemptHttpRequest",
|
|
4541
|
+
namespace: "kitcore",
|
|
4542
|
+
imports: [
|
|
4543
|
+
declareDefault({ plugin: prepareHttpRequestPlugin }),
|
|
4544
|
+
declareDefault({ plugin: authorizeHttpRequestPlugin }),
|
|
4545
|
+
declareDefault({ plugin: dispatchHttpRequestPlugin }),
|
|
4546
|
+
declareDefault({ plugin: receiveHttpResponsePlugin })
|
|
4547
|
+
],
|
|
4548
|
+
inputSchema: z9.custom(),
|
|
4549
|
+
skipInputValidation: true,
|
|
4550
|
+
run: async ({ input, imports }) => {
|
|
4551
|
+
const { attempt } = input;
|
|
4552
|
+
const preparedRequest = await imports.prepareHttpRequest({
|
|
4553
|
+
request: input.request,
|
|
4554
|
+
attempt
|
|
4555
|
+
});
|
|
4556
|
+
const authorizedRequest = await imports.authorizeHttpRequest({
|
|
4557
|
+
request: preparedRequest,
|
|
4558
|
+
attempt
|
|
4559
|
+
});
|
|
4560
|
+
const response = await imports.dispatchHttpRequest({
|
|
4561
|
+
request: authorizedRequest,
|
|
4562
|
+
attempt
|
|
4563
|
+
});
|
|
4564
|
+
return imports.receiveHttpResponse({
|
|
4565
|
+
request: authorizedRequest,
|
|
4566
|
+
response,
|
|
4567
|
+
attempt
|
|
4568
|
+
});
|
|
4569
|
+
}
|
|
4570
|
+
});
|
|
4571
|
+
|
|
4572
|
+
// src/transport/initialize-http-request.ts
|
|
4573
|
+
import { z as z10 } from "zod";
|
|
4574
|
+
function isReplayableBody(body) {
|
|
4575
|
+
if (body == null || typeof body !== "object") return true;
|
|
4576
|
+
return typeof Blob !== "undefined" && body instanceof Blob || // File extends Blob
|
|
4577
|
+
typeof FormData !== "undefined" && body instanceof FormData || typeof URLSearchParams !== "undefined" && body instanceof URLSearchParams || body instanceof ArrayBuffer || ArrayBuffer.isView(body);
|
|
4578
|
+
}
|
|
4579
|
+
function withStringUrl(request) {
|
|
4580
|
+
return typeof request.url === "string" ? request : { ...request, url: String(request.url) };
|
|
4581
|
+
}
|
|
4582
|
+
var initializeHttpRequestPlugin = defineMethod({
|
|
4583
|
+
name: "initializeHttpRequest",
|
|
4584
|
+
namespace: "kitcore",
|
|
4585
|
+
inputSchema: z10.custom(),
|
|
4586
|
+
skipInputValidation: true,
|
|
4587
|
+
run: async ({ input }) => {
|
|
4588
|
+
const request = withStringUrl(input.request);
|
|
4589
|
+
return {
|
|
4590
|
+
...input.operation,
|
|
4591
|
+
request,
|
|
4592
|
+
replayable: isReplayableBody(request.body)
|
|
4593
|
+
};
|
|
4594
|
+
}
|
|
4595
|
+
});
|
|
4596
|
+
|
|
4597
|
+
// src/transport/retry-http-request.ts
|
|
4598
|
+
var RETRY_HTTP_REQUEST_OPTIONS_ID = "kitcore/retryHttpRequestOptions";
|
|
4599
|
+
var retryHttpRequestOptionsPluginRef = declareOptionalProperty({ id: RETRY_HTTP_REQUEST_OPTIONS_ID });
|
|
4600
|
+
var DEFAULT_MAX_ATTEMPTS = 3;
|
|
4601
|
+
var DEFAULT_MAX_DELAY_MILLISECONDS = 6e4;
|
|
4602
|
+
var DEFAULT_RETRY_STATUSES = [429, 500, 502, 503, 504];
|
|
4603
|
+
var DEFAULT_NON_IDEMPOTENT_RETRY_STATUSES = [429];
|
|
4604
|
+
var DEFAULT_IDEMPOTENT_METHODS = [
|
|
4605
|
+
"GET",
|
|
4606
|
+
"HEAD",
|
|
4607
|
+
"PUT",
|
|
4608
|
+
"DELETE",
|
|
4609
|
+
"OPTIONS",
|
|
4610
|
+
"TRACE"
|
|
4611
|
+
];
|
|
4612
|
+
var BASE_BACKOFF_MILLISECONDS = 1e3;
|
|
4613
|
+
var JITTER_FACTOR = 0.5;
|
|
4614
|
+
function directedDelayMilliseconds(response) {
|
|
4615
|
+
const retryAfter = response.headers.get("retry-after");
|
|
4616
|
+
if (retryAfter) {
|
|
4617
|
+
const seconds = Number.parseInt(retryAfter, 10);
|
|
4618
|
+
if (!Number.isNaN(seconds)) return Math.max(0, seconds * 1e3);
|
|
4619
|
+
const date = Date.parse(retryAfter);
|
|
4620
|
+
if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
|
|
4621
|
+
}
|
|
4622
|
+
const reset = response.headers.get("x-ratelimit-reset");
|
|
4623
|
+
if (reset) {
|
|
4624
|
+
const resetSeconds = Number.parseInt(reset, 10);
|
|
4625
|
+
if (!Number.isNaN(resetSeconds)) {
|
|
4626
|
+
return Math.max(0, resetSeconds * 1e3 - Date.now());
|
|
4627
|
+
}
|
|
4628
|
+
}
|
|
4629
|
+
return void 0;
|
|
4630
|
+
}
|
|
4631
|
+
function backoffMilliseconds(attemptNumber) {
|
|
4632
|
+
const base = BASE_BACKOFF_MILLISECONDS * 2 ** (attemptNumber - 1);
|
|
4633
|
+
return base + Math.random() * JITTER_FACTOR * base;
|
|
4634
|
+
}
|
|
4635
|
+
function abortReason(signal) {
|
|
4636
|
+
const reason = signal?.reason;
|
|
4637
|
+
return reason ?? new Error("The request was aborted.");
|
|
4638
|
+
}
|
|
4639
|
+
function sleep(milliseconds, signal) {
|
|
4640
|
+
return new Promise((resolve, reject) => {
|
|
4641
|
+
const timer = setTimeout(finish, milliseconds);
|
|
4642
|
+
function finish() {
|
|
4643
|
+
clearTimeout(timer);
|
|
4644
|
+
signal?.removeEventListener("abort", cancel);
|
|
4645
|
+
resolve();
|
|
4646
|
+
}
|
|
4647
|
+
function cancel() {
|
|
4648
|
+
clearTimeout(timer);
|
|
4649
|
+
reject(abortReason(signal));
|
|
4650
|
+
}
|
|
4651
|
+
if (signal?.aborted) return cancel();
|
|
4652
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
4653
|
+
});
|
|
4654
|
+
}
|
|
4655
|
+
function isIdempotent(request, idempotentMethods) {
|
|
4656
|
+
const method = (request.method ?? "GET").toUpperCase();
|
|
4657
|
+
return idempotentMethods.includes(method);
|
|
4658
|
+
}
|
|
4659
|
+
var retryHttpRequestPlugin = defineHook({
|
|
4660
|
+
name: "retryHttpRequest",
|
|
4661
|
+
imports: [attemptHttpRequestPlugin, retryHttpRequestOptionsPluginRef],
|
|
4662
|
+
wrap: {
|
|
4663
|
+
attemptHttpRequest: async ({ input, imports, next }) => {
|
|
4664
|
+
const options = imports.retryHttpRequestOptions ?? {};
|
|
4665
|
+
const maxAttempts = options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
4666
|
+
const maxDelayMilliseconds = options.maxDelayMilliseconds ?? DEFAULT_MAX_DELAY_MILLISECONDS;
|
|
4667
|
+
const idempotentMethods = options.idempotentMethods ?? DEFAULT_IDEMPOTENT_METHODS;
|
|
4668
|
+
const statuses = isIdempotent(input.request, idempotentMethods) ? options.retryStatuses ?? DEFAULT_RETRY_STATUSES : options.nonIdempotentRetryStatuses ?? DEFAULT_NON_IDEMPOTENT_RETRY_STATUSES;
|
|
4669
|
+
for (let attemptNumber = 1; ; attemptNumber++) {
|
|
4670
|
+
const attempt = {
|
|
4671
|
+
...input.attempt,
|
|
4672
|
+
attemptNumber,
|
|
4673
|
+
// Per-attempt scratch: a cross-stage handoff from a previous attempt
|
|
4674
|
+
// describes a request that is no longer in flight. `operation` rides
|
|
4675
|
+
// through unchanged, so the id and the caller's original request are
|
|
4676
|
+
// the same for every attempt.
|
|
4677
|
+
state: {}
|
|
4678
|
+
};
|
|
4679
|
+
let response;
|
|
4680
|
+
try {
|
|
4681
|
+
response = await next({ ...input, attempt });
|
|
4682
|
+
} catch (error) {
|
|
4683
|
+
if (!options.retryOnError || !canRetry(
|
|
4684
|
+
attemptNumber,
|
|
4685
|
+
maxAttempts,
|
|
4686
|
+
input.attempt.operation.replayable
|
|
4687
|
+
)) {
|
|
4688
|
+
throw error;
|
|
4689
|
+
}
|
|
4690
|
+
await sleep(
|
|
4691
|
+
Math.min(backoffMilliseconds(attemptNumber), maxDelayMilliseconds),
|
|
4692
|
+
attempt.signal
|
|
4693
|
+
);
|
|
4694
|
+
continue;
|
|
4695
|
+
}
|
|
4696
|
+
if (!statuses.includes(response.status) || !canRetry(
|
|
4697
|
+
attemptNumber,
|
|
4698
|
+
maxAttempts,
|
|
4699
|
+
input.attempt.operation.replayable
|
|
4700
|
+
)) {
|
|
4701
|
+
return response;
|
|
4702
|
+
}
|
|
4703
|
+
const directed = directedDelayMilliseconds(response);
|
|
4704
|
+
if (directed != null && directed > maxDelayMilliseconds)
|
|
4705
|
+
return response;
|
|
4706
|
+
const delay = Math.min(
|
|
4707
|
+
directed ?? backoffMilliseconds(attemptNumber),
|
|
4708
|
+
maxDelayMilliseconds
|
|
4709
|
+
);
|
|
4710
|
+
await response.body?.cancel().catch(() => {
|
|
4711
|
+
});
|
|
4712
|
+
await sleep(delay, attempt.signal);
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
});
|
|
4717
|
+
function canRetry(attemptNumber, maxAttempts, replayable) {
|
|
4718
|
+
return attemptNumber < maxAttempts && replayable;
|
|
4719
|
+
}
|
|
4720
|
+
|
|
4721
|
+
// src/transport/send-http-request.ts
|
|
4722
|
+
import { z as z11 } from "zod";
|
|
4723
|
+
function createOperationId() {
|
|
4724
|
+
return globalThis.crypto?.randomUUID?.() ?? `http-${Date.now()}`;
|
|
4725
|
+
}
|
|
4726
|
+
var sendHttpRequestPlugin = defineMethod({
|
|
4727
|
+
name: "sendHttpRequest",
|
|
4728
|
+
namespace: "kitcore",
|
|
4729
|
+
imports: [
|
|
4730
|
+
declareDefault({ plugin: initializeHttpRequestPlugin }),
|
|
4731
|
+
declareDefault({ plugin: attemptHttpRequestPlugin })
|
|
4732
|
+
],
|
|
4733
|
+
inputSchema: z11.custom(),
|
|
4734
|
+
skipInputValidation: true,
|
|
4735
|
+
run: async ({ input, imports }) => {
|
|
4736
|
+
const start2 = {
|
|
4737
|
+
operationId: createOperationId(),
|
|
4738
|
+
signal: input.signal
|
|
4739
|
+
};
|
|
4740
|
+
const operation = await imports.initializeHttpRequest({
|
|
4741
|
+
request: input,
|
|
4742
|
+
operation: start2
|
|
4743
|
+
});
|
|
4744
|
+
return imports.attemptHttpRequest({
|
|
4745
|
+
request: operation.request,
|
|
4746
|
+
attempt: {
|
|
4747
|
+
attemptNumber: 1,
|
|
4748
|
+
operation,
|
|
4749
|
+
signal: operation.signal,
|
|
4750
|
+
state: {}
|
|
4751
|
+
}
|
|
4752
|
+
});
|
|
4753
|
+
}
|
|
4754
|
+
});
|
|
4755
|
+
|
|
4756
|
+
// src/transport/fetch.ts
|
|
4757
|
+
import { z as z12 } from "zod";
|
|
4758
|
+
var fetchPlugin = defineMethod({
|
|
4759
|
+
name: "fetch",
|
|
4760
|
+
namespace: "kitcore",
|
|
4761
|
+
imports: [declareDefault({ plugin: sendHttpRequestPlugin })],
|
|
4762
|
+
positional: ["url", "init"],
|
|
4763
|
+
inputSchema: z12.custom(),
|
|
4764
|
+
skipInputValidation: true,
|
|
4765
|
+
run: ({ input, imports }) => {
|
|
4766
|
+
const { url, init } = input;
|
|
4767
|
+
return imports.sendHttpRequest({ url, ...init });
|
|
4768
|
+
}
|
|
4769
|
+
});
|
|
4770
|
+
|
|
4771
|
+
// src/transport/redact.ts
|
|
4772
|
+
var CREDENTIAL_HEADERS = ["authorization", "x-api-key"];
|
|
4773
|
+
function maskSecret(secret) {
|
|
4774
|
+
if (secret.length > 12) {
|
|
4775
|
+
return `${secret.slice(0, 4)}...${secret.slice(-4)}`;
|
|
4776
|
+
}
|
|
4777
|
+
return `${secret.charAt(0)}...`;
|
|
4778
|
+
}
|
|
4779
|
+
function maskCredentialHeader(value) {
|
|
4780
|
+
const spaceIndex = value.indexOf(" ");
|
|
4781
|
+
if (spaceIndex > 0 && spaceIndex < value.length - 1) {
|
|
4782
|
+
return `${value.slice(0, spaceIndex + 1)}${maskSecret(value.slice(spaceIndex + 1))}`;
|
|
4783
|
+
}
|
|
4784
|
+
return maskSecret(value);
|
|
4785
|
+
}
|
|
4786
|
+
function redactHeaders(headers) {
|
|
4787
|
+
if (!headers) return headers;
|
|
4788
|
+
const normalized = new Headers(headers);
|
|
4789
|
+
for (const [name, value] of normalized.entries()) {
|
|
4790
|
+
if (CREDENTIAL_HEADERS.includes(name.toLowerCase())) {
|
|
4791
|
+
normalized.set(name, maskCredentialHeader(value));
|
|
4792
|
+
}
|
|
4793
|
+
}
|
|
4794
|
+
return Object.fromEntries(normalized);
|
|
4795
|
+
}
|
|
4796
|
+
function redactHttpRequest(request) {
|
|
4797
|
+
const redacted = { ...request };
|
|
4798
|
+
if (request.headers) redacted.headers = redactHeaders(request.headers);
|
|
4799
|
+
if (request.connection != null) {
|
|
4800
|
+
redacted.connection = maskSecret(request.connection);
|
|
4801
|
+
}
|
|
4802
|
+
return redacted;
|
|
4803
|
+
}
|
|
4804
|
+
|
|
4805
|
+
// src/connections/default-connection-scheme.ts
|
|
4806
|
+
import { z as z13 } from "zod";
|
|
4807
|
+
var defaultConnectionSchemePlugin = defineMethod({
|
|
4808
|
+
name: "defaultConnectionScheme",
|
|
4809
|
+
namespace: "kitcore",
|
|
4810
|
+
inputSchema: z13.custom(),
|
|
4811
|
+
skipInputValidation: true,
|
|
4812
|
+
run: () => void 0
|
|
4813
|
+
});
|
|
4814
|
+
|
|
4815
|
+
// src/connections/normalize-connection.ts
|
|
4816
|
+
import { z as z14 } from "zod";
|
|
4817
|
+
var normalizeConnectionPlugin = defineMethod({
|
|
4818
|
+
name: "normalizeConnection",
|
|
4819
|
+
namespace: "kitcore",
|
|
4820
|
+
imports: [declareDefault({ plugin: defaultConnectionSchemePlugin })],
|
|
4821
|
+
inputSchema: z14.custom(),
|
|
4822
|
+
skipInputValidation: true,
|
|
4823
|
+
run: ({ input, imports }) => {
|
|
4824
|
+
const { connection } = input;
|
|
4825
|
+
if (connection == null) {
|
|
4826
|
+
return void 0;
|
|
4827
|
+
}
|
|
4828
|
+
const delimiterIndex = connection.indexOf(":");
|
|
4829
|
+
if (delimiterIndex !== -1) {
|
|
4830
|
+
return {
|
|
4831
|
+
connection,
|
|
4832
|
+
scheme: connection.slice(0, delimiterIndex),
|
|
4833
|
+
value: connection.slice(delimiterIndex + 1)
|
|
4834
|
+
};
|
|
4835
|
+
}
|
|
4836
|
+
const scheme = imports.defaultConnectionScheme({ connection });
|
|
4837
|
+
return {
|
|
4838
|
+
connection,
|
|
4839
|
+
scheme,
|
|
4840
|
+
value: connection
|
|
4841
|
+
};
|
|
4842
|
+
}
|
|
4843
|
+
});
|
|
4844
|
+
|
|
4845
|
+
// src/connections/resolve-connection.ts
|
|
4846
|
+
import { z as z15 } from "zod";
|
|
4847
|
+
var resolveConnectionPlugin = defineMethod({
|
|
4848
|
+
name: "resolveConnection",
|
|
4849
|
+
namespace: "kitcore",
|
|
4850
|
+
inputSchema: z15.custom(),
|
|
4851
|
+
skipInputValidation: true,
|
|
4852
|
+
run: ({ input }) => input.connection
|
|
4853
|
+
});
|
|
4385
4854
|
export {
|
|
4386
4855
|
CONTEXT,
|
|
4387
4856
|
CORE_ERROR_SYMBOL,
|
|
@@ -4392,7 +4861,13 @@ export {
|
|
|
4392
4861
|
CoreError,
|
|
4393
4862
|
CoreErrorCode,
|
|
4394
4863
|
CoreSignal,
|
|
4864
|
+
RETRY_HTTP_REQUEST_OPTIONS_ID,
|
|
4865
|
+
STABILITY_LEVELS,
|
|
4866
|
+
STABILITY_TITLES,
|
|
4395
4867
|
addPlugin,
|
|
4868
|
+
applyStabilityLabel,
|
|
4869
|
+
attemptHttpRequestPlugin,
|
|
4870
|
+
authorizeHttpRequestPlugin,
|
|
4396
4871
|
canonicalInputSchema,
|
|
4397
4872
|
composePlugins,
|
|
4398
4873
|
concatLists,
|
|
@@ -4410,6 +4885,7 @@ export {
|
|
|
4410
4885
|
createPluginStack,
|
|
4411
4886
|
createPrefixedCursor,
|
|
4412
4887
|
createSdk,
|
|
4888
|
+
createStabilityNoticeLogger,
|
|
4413
4889
|
createValidator,
|
|
4414
4890
|
dangerousContextPlugin,
|
|
4415
4891
|
declareDefault,
|
|
@@ -4419,6 +4895,7 @@ export {
|
|
|
4419
4895
|
declarePlugin,
|
|
4420
4896
|
declareProperty,
|
|
4421
4897
|
decodeIncomingCursor,
|
|
4898
|
+
defaultConnectionSchemePlugin,
|
|
4422
4899
|
defaultLogDeprecation,
|
|
4423
4900
|
defineFormatter,
|
|
4424
4901
|
defineHook,
|
|
@@ -4428,7 +4905,9 @@ export {
|
|
|
4428
4905
|
definePlugin,
|
|
4429
4906
|
defineProperty,
|
|
4430
4907
|
defineResolver,
|
|
4908
|
+
dispatchHttpRequestPlugin,
|
|
4431
4909
|
disposeSdk,
|
|
4910
|
+
fetchPlugin,
|
|
4432
4911
|
fromFunctionPlugin,
|
|
4433
4912
|
getContext,
|
|
4434
4913
|
getCoreErrorCause,
|
|
@@ -4440,21 +4919,32 @@ export {
|
|
|
4440
4919
|
getOutputSchema,
|
|
4441
4920
|
getRegistryPlugin,
|
|
4442
4921
|
getSchemaDescription,
|
|
4922
|
+
initializeHttpRequestPlugin,
|
|
4443
4923
|
isCoreCancelledSignal,
|
|
4444
4924
|
isCoreError,
|
|
4445
4925
|
isCoreSignal,
|
|
4446
4926
|
isNestedMethodCall,
|
|
4447
4927
|
isPositional,
|
|
4448
4928
|
isTelemetryNested,
|
|
4929
|
+
normalizeConnectionPlugin,
|
|
4930
|
+
normalizeStability,
|
|
4449
4931
|
omitExports,
|
|
4450
4932
|
openEnum,
|
|
4451
4933
|
paginate,
|
|
4452
4934
|
paginateBuffered,
|
|
4453
4935
|
paginateMaxItems,
|
|
4936
|
+
prepareHttpRequestPlugin,
|
|
4937
|
+
receiveHttpResponsePlugin,
|
|
4938
|
+
redactHeaders,
|
|
4939
|
+
redactHttpRequest,
|
|
4940
|
+
resolveConnectionPlugin,
|
|
4454
4941
|
resolvePlugin,
|
|
4942
|
+
retryHttpRequestOptionsPluginRef,
|
|
4943
|
+
retryHttpRequestPlugin,
|
|
4455
4944
|
runInMethodScope,
|
|
4456
4945
|
runWithTelemetryContext,
|
|
4457
4946
|
selectExports,
|
|
4947
|
+
sendHttpRequestPlugin,
|
|
4458
4948
|
splitPrefixedCursor,
|
|
4459
4949
|
toIterable,
|
|
4460
4950
|
toSnakeCase,
|