@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.cjs
CHANGED
|
@@ -29,7 +29,13 @@ __export(index_exports, {
|
|
|
29
29
|
CoreError: () => CoreError,
|
|
30
30
|
CoreErrorCode: () => CoreErrorCode,
|
|
31
31
|
CoreSignal: () => CoreSignal,
|
|
32
|
+
RETRY_HTTP_REQUEST_OPTIONS_ID: () => RETRY_HTTP_REQUEST_OPTIONS_ID,
|
|
33
|
+
STABILITY_LEVELS: () => STABILITY_LEVELS,
|
|
34
|
+
STABILITY_TITLES: () => STABILITY_TITLES,
|
|
32
35
|
addPlugin: () => addPlugin,
|
|
36
|
+
applyStabilityLabel: () => applyStabilityLabel,
|
|
37
|
+
attemptHttpRequestPlugin: () => attemptHttpRequestPlugin,
|
|
38
|
+
authorizeHttpRequestPlugin: () => authorizeHttpRequestPlugin,
|
|
33
39
|
canonicalInputSchema: () => canonicalInputSchema,
|
|
34
40
|
composePlugins: () => composePlugins,
|
|
35
41
|
concatLists: () => concatLists,
|
|
@@ -47,6 +53,7 @@ __export(index_exports, {
|
|
|
47
53
|
createPluginStack: () => createPluginStack,
|
|
48
54
|
createPrefixedCursor: () => createPrefixedCursor,
|
|
49
55
|
createSdk: () => createSdk,
|
|
56
|
+
createStabilityNoticeLogger: () => createStabilityNoticeLogger,
|
|
50
57
|
createValidator: () => createValidator,
|
|
51
58
|
dangerousContextPlugin: () => dangerousContextPlugin,
|
|
52
59
|
declareDefault: () => declareDefault,
|
|
@@ -56,6 +63,7 @@ __export(index_exports, {
|
|
|
56
63
|
declarePlugin: () => declarePlugin,
|
|
57
64
|
declareProperty: () => declareProperty,
|
|
58
65
|
decodeIncomingCursor: () => decodeIncomingCursor,
|
|
66
|
+
defaultConnectionSchemePlugin: () => defaultConnectionSchemePlugin,
|
|
59
67
|
defaultLogDeprecation: () => defaultLogDeprecation,
|
|
60
68
|
defineFormatter: () => defineFormatter,
|
|
61
69
|
defineHook: () => defineHook,
|
|
@@ -65,7 +73,9 @@ __export(index_exports, {
|
|
|
65
73
|
definePlugin: () => definePlugin,
|
|
66
74
|
defineProperty: () => defineProperty,
|
|
67
75
|
defineResolver: () => defineResolver,
|
|
76
|
+
dispatchHttpRequestPlugin: () => dispatchHttpRequestPlugin,
|
|
68
77
|
disposeSdk: () => disposeSdk,
|
|
78
|
+
fetchPlugin: () => fetchPlugin,
|
|
69
79
|
fromFunctionPlugin: () => fromFunctionPlugin,
|
|
70
80
|
getContext: () => getContext,
|
|
71
81
|
getCoreErrorCause: () => getCoreErrorCause,
|
|
@@ -77,21 +87,32 @@ __export(index_exports, {
|
|
|
77
87
|
getOutputSchema: () => getOutputSchema,
|
|
78
88
|
getRegistryPlugin: () => getRegistryPlugin,
|
|
79
89
|
getSchemaDescription: () => getSchemaDescription,
|
|
90
|
+
initializeHttpRequestPlugin: () => initializeHttpRequestPlugin,
|
|
80
91
|
isCoreCancelledSignal: () => isCoreCancelledSignal,
|
|
81
92
|
isCoreError: () => isCoreError,
|
|
82
93
|
isCoreSignal: () => isCoreSignal,
|
|
83
94
|
isNestedMethodCall: () => isNestedMethodCall,
|
|
84
95
|
isPositional: () => isPositional,
|
|
85
96
|
isTelemetryNested: () => isTelemetryNested,
|
|
97
|
+
normalizeConnectionPlugin: () => normalizeConnectionPlugin,
|
|
98
|
+
normalizeStability: () => normalizeStability,
|
|
86
99
|
omitExports: () => omitExports,
|
|
87
100
|
openEnum: () => openEnum,
|
|
88
101
|
paginate: () => paginate,
|
|
89
102
|
paginateBuffered: () => paginateBuffered,
|
|
90
103
|
paginateMaxItems: () => paginateMaxItems,
|
|
104
|
+
prepareHttpRequestPlugin: () => prepareHttpRequestPlugin,
|
|
105
|
+
receiveHttpResponsePlugin: () => receiveHttpResponsePlugin,
|
|
106
|
+
redactHeaders: () => redactHeaders,
|
|
107
|
+
redactHttpRequest: () => redactHttpRequest,
|
|
108
|
+
resolveConnectionPlugin: () => resolveConnectionPlugin,
|
|
91
109
|
resolvePlugin: () => resolvePlugin,
|
|
110
|
+
retryHttpRequestOptionsPluginRef: () => retryHttpRequestOptionsPluginRef,
|
|
111
|
+
retryHttpRequestPlugin: () => retryHttpRequestPlugin,
|
|
92
112
|
runInMethodScope: () => runInMethodScope,
|
|
93
113
|
runWithTelemetryContext: () => runWithTelemetryContext,
|
|
94
114
|
selectExports: () => selectExports,
|
|
115
|
+
sendHttpRequestPlugin: () => sendHttpRequestPlugin,
|
|
95
116
|
splitPrefixedCursor: () => splitPrefixedCursor,
|
|
96
117
|
toIterable: () => toIterable,
|
|
97
118
|
toSnakeCase: () => toSnakeCase,
|
|
@@ -194,6 +215,28 @@ function openEnum(values, description) {
|
|
|
194
215
|
return import_zod.z.union([import_zod.z.enum(values), import_zod.z.string()]).describe(description);
|
|
195
216
|
}
|
|
196
217
|
|
|
218
|
+
// src/utils/stability.ts
|
|
219
|
+
var STABILITY_LEVELS = ["stable", "beta", "experimental"];
|
|
220
|
+
var STABILITY_TITLES = {
|
|
221
|
+
stable: "Stable",
|
|
222
|
+
beta: "Beta",
|
|
223
|
+
experimental: "Experimental"
|
|
224
|
+
};
|
|
225
|
+
function normalizeStability(meta) {
|
|
226
|
+
if (meta.stability !== void 0) {
|
|
227
|
+
return STABILITY_LEVELS.includes(meta.stability) ? meta.stability : "experimental";
|
|
228
|
+
}
|
|
229
|
+
return meta.experimental ? "experimental" : "stable";
|
|
230
|
+
}
|
|
231
|
+
function applyStabilityLabel({
|
|
232
|
+
description,
|
|
233
|
+
stability,
|
|
234
|
+
placement = "suffix"
|
|
235
|
+
}) {
|
|
236
|
+
if (stability === void 0 || stability === "stable") return description;
|
|
237
|
+
return placement === "prefix" ? `[${STABILITY_TITLES[stability]}] ${description}` : `${description} (${stability})`;
|
|
238
|
+
}
|
|
239
|
+
|
|
197
240
|
// src/registry.ts
|
|
198
241
|
function resolveCategoryDefinition(ref) {
|
|
199
242
|
const def = typeof ref === "string" ? { key: ref } : ref;
|
|
@@ -238,6 +281,7 @@ function buildRegistry({
|
|
|
238
281
|
return typeof rootProperty === "object" && rootProperty !== null;
|
|
239
282
|
}).map((key) => {
|
|
240
283
|
const m = meta[key];
|
|
284
|
+
const stability = normalizeStability(m);
|
|
241
285
|
return {
|
|
242
286
|
name: key,
|
|
243
287
|
description: m.description,
|
|
@@ -253,7 +297,11 @@ function buildRegistry({
|
|
|
253
297
|
),
|
|
254
298
|
resolvers: resolvers?.[key],
|
|
255
299
|
formatter: formatters?.[key],
|
|
256
|
-
|
|
300
|
+
stability,
|
|
301
|
+
// Deprecated derived read, literal by name: only the experimental
|
|
302
|
+
// tier reads true. Beta reads false — the "not stable" warning duty
|
|
303
|
+
// lives in `stability` and the runtime notice, not this boolean.
|
|
304
|
+
experimental: stability === "experimental",
|
|
257
305
|
packages: m.packages,
|
|
258
306
|
confirm: m.confirm ?? (m.type === "delete" ? "delete" : void 0),
|
|
259
307
|
deprecation: m.deprecation,
|
|
@@ -342,6 +390,20 @@ function createDeprecationLogger(tag) {
|
|
|
342
390
|
};
|
|
343
391
|
}
|
|
344
392
|
var { logDeprecation, resetDeprecationWarnings } = createDeprecationLogger("core");
|
|
393
|
+
function createStabilityNoticeLogger(tag) {
|
|
394
|
+
const loggedNotices = /* @__PURE__ */ new Set();
|
|
395
|
+
return {
|
|
396
|
+
logStabilityNotice(message) {
|
|
397
|
+
if (loggedNotices.has(message)) return;
|
|
398
|
+
loggedNotices.add(message);
|
|
399
|
+
console.warn(`[${tag}] ${message}`);
|
|
400
|
+
},
|
|
401
|
+
resetStabilityNotices() {
|
|
402
|
+
loggedNotices.clear();
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
var { logStabilityNotice, resetStabilityNotices } = createStabilityNoticeLogger("core");
|
|
345
407
|
|
|
346
408
|
// src/types/errors.ts
|
|
347
409
|
var CORE_ERROR_SYMBOL = Symbol.for("kitcore.error");
|
|
@@ -824,6 +886,19 @@ function defaultLogDeprecation({
|
|
|
824
886
|
}) {
|
|
825
887
|
logDeprecation(`${methodName}() is deprecated. ${deprecation.message}`);
|
|
826
888
|
}
|
|
889
|
+
var STABILITY_NOTICE_DETAILS = {
|
|
890
|
+
beta: "Its API shape is settled, but it is not yet covered by stable-tier guarantees.",
|
|
891
|
+
experimental: "It may change shape or disappear without notice."
|
|
892
|
+
};
|
|
893
|
+
function defaultLogStabilityNotice({
|
|
894
|
+
methodName,
|
|
895
|
+
stability
|
|
896
|
+
}) {
|
|
897
|
+
if (stability === "stable") return;
|
|
898
|
+
logStabilityNotice(
|
|
899
|
+
`${methodName}() is a ${stability} API. ${STABILITY_NOTICE_DETAILS[stability]}`
|
|
900
|
+
);
|
|
901
|
+
}
|
|
827
902
|
var CORE_OPTIONS_ID = "kitcore/coreOptions";
|
|
828
903
|
|
|
829
904
|
// src/utils/function-utils.ts
|
|
@@ -872,6 +947,18 @@ function signalDeprecation(context, methodName, getDeprecation) {
|
|
|
872
947
|
const handler = resolveCoreOptions(context)?.logDeprecation ?? defaultLogDeprecation;
|
|
873
948
|
runIsolatedObserver(() => handler(warning));
|
|
874
949
|
}
|
|
950
|
+
function signalStability(context, methodName, getStability) {
|
|
951
|
+
if (isInsideObserver()) return;
|
|
952
|
+
const stability = getStability?.();
|
|
953
|
+
if (!stability || stability === "stable") return;
|
|
954
|
+
const notice = {
|
|
955
|
+
type: "stability",
|
|
956
|
+
methodName,
|
|
957
|
+
stability
|
|
958
|
+
};
|
|
959
|
+
const handler = resolveCoreOptions(context)?.logStabilityNotice ?? defaultLogStabilityNotice;
|
|
960
|
+
runIsolatedObserver(() => handler(notice));
|
|
961
|
+
}
|
|
875
962
|
function normalizeError(error, adaptError) {
|
|
876
963
|
if (error instanceof Error) return error;
|
|
877
964
|
const message = typeof error === "object" && error !== null && "message" in error && typeof error.message === "string" ? error.message : String(error);
|
|
@@ -885,7 +972,7 @@ function normalizeError(error, adaptError) {
|
|
|
885
972
|
);
|
|
886
973
|
}
|
|
887
974
|
function createFunction(coreFn, options) {
|
|
888
|
-
const { sdk, schema, name, annotator, getDeprecation } = options;
|
|
975
|
+
const { sdk, schema, name, annotator, getDeprecation, getStability } = options;
|
|
889
976
|
const functionName = name || coreFn.name;
|
|
890
977
|
const namedFunctions = {
|
|
891
978
|
[functionName]: async function(callOptions) {
|
|
@@ -893,6 +980,7 @@ function createFunction(coreFn, options) {
|
|
|
893
980
|
const context = resolveCallContext(internal);
|
|
894
981
|
if (!isCallContext(internal) && internal !== INTERNAL_CALL) {
|
|
895
982
|
signalDeprecation(sdk.context, functionName, getDeprecation);
|
|
983
|
+
signalStability(sdk.context, functionName, getStability);
|
|
896
984
|
}
|
|
897
985
|
return runInMethodScope(async () => {
|
|
898
986
|
const startTime = Date.now();
|
|
@@ -959,12 +1047,21 @@ function createFunction(coreFn, options) {
|
|
|
959
1047
|
return namedFunctions[functionName];
|
|
960
1048
|
}
|
|
961
1049
|
function createRawFunction(coreFn, options) {
|
|
962
|
-
const {
|
|
1050
|
+
const {
|
|
1051
|
+
sdk,
|
|
1052
|
+
name,
|
|
1053
|
+
schema,
|
|
1054
|
+
positional,
|
|
1055
|
+
annotator,
|
|
1056
|
+
getDeprecation,
|
|
1057
|
+
getStability
|
|
1058
|
+
} = options;
|
|
963
1059
|
return function(rawInput) {
|
|
964
1060
|
const internal = arguments[1];
|
|
965
1061
|
const context = resolveCallContext(internal);
|
|
966
1062
|
if (!isCallContext(internal) && internal !== INTERNAL_CALL) {
|
|
967
1063
|
signalDeprecation(sdk.context, name, getDeprecation);
|
|
1064
|
+
signalStability(sdk.context, name, getStability);
|
|
968
1065
|
}
|
|
969
1066
|
return runInMethodScope(() => {
|
|
970
1067
|
const startTime = Date.now();
|
|
@@ -1070,7 +1167,8 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
1070
1167
|
adaptPage,
|
|
1071
1168
|
annotator,
|
|
1072
1169
|
finalizePage,
|
|
1073
|
-
getDeprecation
|
|
1170
|
+
getDeprecation,
|
|
1171
|
+
getStability
|
|
1074
1172
|
} = options;
|
|
1075
1173
|
const pageFunction = createPageFunction(coreFn, {
|
|
1076
1174
|
sdk,
|
|
@@ -1084,6 +1182,7 @@ function createPaginatedFunction(coreFn, options) {
|
|
|
1084
1182
|
const context = resolveCallContext(internal);
|
|
1085
1183
|
if (!isCallContext(internal) && internal !== INTERNAL_CALL) {
|
|
1086
1184
|
signalDeprecation(sdk.context, functionName, getDeprecation);
|
|
1185
|
+
signalStability(sdk.context, functionName, getStability);
|
|
1087
1186
|
}
|
|
1088
1187
|
return runInMethodScope(() => {
|
|
1089
1188
|
const startTime = Date.now();
|
|
@@ -1528,6 +1627,7 @@ var LEAF_META_KEYS = [
|
|
|
1528
1627
|
"returnType",
|
|
1529
1628
|
"outputSchema",
|
|
1530
1629
|
"packages",
|
|
1630
|
+
"stability",
|
|
1531
1631
|
"experimental",
|
|
1532
1632
|
"confirm",
|
|
1533
1633
|
"deprecation",
|
|
@@ -2795,7 +2895,8 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2795
2895
|
// (item mode's sibling); dropped paths surface as `[].x` in the page's
|
|
2796
2896
|
// `meta`, unioned across items.
|
|
2797
2897
|
finalizePage: (page) => applyListOutputPolicy(page, outputPolicy()),
|
|
2798
|
-
getDeprecation: () => entry.meta?.deprecation
|
|
2898
|
+
getDeprecation: () => entry.meta?.deprecation,
|
|
2899
|
+
getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
|
|
2799
2900
|
}
|
|
2800
2901
|
);
|
|
2801
2902
|
} else if (out.type === "item") {
|
|
@@ -2807,7 +2908,8 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2807
2908
|
schema: descriptor.inputSchema,
|
|
2808
2909
|
name: descriptor.name,
|
|
2809
2910
|
annotator: boundAnnotator,
|
|
2810
|
-
getDeprecation: () => entry.meta?.deprecation
|
|
2911
|
+
getDeprecation: () => entry.meta?.deprecation,
|
|
2912
|
+
getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
|
|
2811
2913
|
}
|
|
2812
2914
|
);
|
|
2813
2915
|
} else {
|
|
@@ -2821,8 +2923,10 @@ function buildMethodEntries(descriptors, context, states) {
|
|
|
2821
2923
|
annotator: boundAnnotator,
|
|
2822
2924
|
// The boundary reads the deprecation LIVE off the entry, so a
|
|
2823
2925
|
// deprecation merged after build (defineMethodOverride, addPlugin)
|
|
2824
|
-
// fires too.
|
|
2825
|
-
|
|
2926
|
+
// fires too. Same for the stability level, normalized from the
|
|
2927
|
+
// entry meta (declared level or legacy `experimental` boolean).
|
|
2928
|
+
getDeprecation: () => entry.meta?.deprecation,
|
|
2929
|
+
getStability: () => entry.meta ? normalizeStability(entry.meta) : void 0
|
|
2826
2930
|
}
|
|
2827
2931
|
);
|
|
2828
2932
|
}
|
|
@@ -4485,6 +4589,392 @@ function createCorePlugin(options) {
|
|
|
4485
4589
|
}
|
|
4486
4590
|
});
|
|
4487
4591
|
}
|
|
4592
|
+
|
|
4593
|
+
// src/transport/attempt-http-request.ts
|
|
4594
|
+
var import_zod9 = require("zod");
|
|
4595
|
+
|
|
4596
|
+
// src/transport/authorize-http-request.ts
|
|
4597
|
+
var import_zod5 = require("zod");
|
|
4598
|
+
function describeUnclaimedConnection(connection) {
|
|
4599
|
+
const delimiterIndex = connection.indexOf(":");
|
|
4600
|
+
if (delimiterIndex === -1) {
|
|
4601
|
+
return 'no auth provider claimed this connection, and it carries no "scheme:" prefix';
|
|
4602
|
+
}
|
|
4603
|
+
return `no auth provider claimed the "${connection.slice(0, delimiterIndex)}" connection scheme`;
|
|
4604
|
+
}
|
|
4605
|
+
var authorizeHttpRequestPlugin = defineMethod({
|
|
4606
|
+
name: "authorizeHttpRequest",
|
|
4607
|
+
namespace: "kitcore",
|
|
4608
|
+
inputSchema: import_zod5.z.custom(),
|
|
4609
|
+
skipInputValidation: true,
|
|
4610
|
+
run: async ({ input }) => {
|
|
4611
|
+
const { connection } = input.request;
|
|
4612
|
+
if (connection != null) {
|
|
4613
|
+
throw createCoreError({
|
|
4614
|
+
code: CoreErrorCode.Unknown,
|
|
4615
|
+
message: `authorizeHttpRequest: ${describeUnclaimedConnection(connection)}, so the request was not sent.`
|
|
4616
|
+
});
|
|
4617
|
+
}
|
|
4618
|
+
return input.request;
|
|
4619
|
+
}
|
|
4620
|
+
});
|
|
4621
|
+
|
|
4622
|
+
// src/transport/dispatch-http-request.ts
|
|
4623
|
+
var import_zod6 = require("zod");
|
|
4624
|
+
function toFetchInput(request) {
|
|
4625
|
+
const init = { ...request };
|
|
4626
|
+
const { url } = request;
|
|
4627
|
+
delete init.url;
|
|
4628
|
+
delete init.connection;
|
|
4629
|
+
return { url, init };
|
|
4630
|
+
}
|
|
4631
|
+
var dispatchHttpRequestPlugin = defineMethod({
|
|
4632
|
+
name: "dispatchHttpRequest",
|
|
4633
|
+
namespace: "kitcore",
|
|
4634
|
+
inputSchema: import_zod6.z.custom(),
|
|
4635
|
+
skipInputValidation: true,
|
|
4636
|
+
run: async ({ input }) => {
|
|
4637
|
+
const { url, init } = toFetchInput(input.request);
|
|
4638
|
+
return fetch(url, init);
|
|
4639
|
+
}
|
|
4640
|
+
});
|
|
4641
|
+
|
|
4642
|
+
// src/transport/prepare-http-request.ts
|
|
4643
|
+
var import_zod7 = require("zod");
|
|
4644
|
+
var prepareHttpRequestPlugin = defineMethod({
|
|
4645
|
+
name: "prepareHttpRequest",
|
|
4646
|
+
namespace: "kitcore",
|
|
4647
|
+
inputSchema: import_zod7.z.custom(),
|
|
4648
|
+
skipInputValidation: true,
|
|
4649
|
+
run: async ({ input }) => input.request
|
|
4650
|
+
});
|
|
4651
|
+
|
|
4652
|
+
// src/transport/receive-http-response.ts
|
|
4653
|
+
var import_zod8 = require("zod");
|
|
4654
|
+
var receiveHttpResponsePlugin = defineMethod({
|
|
4655
|
+
name: "receiveHttpResponse",
|
|
4656
|
+
namespace: "kitcore",
|
|
4657
|
+
inputSchema: import_zod8.z.custom(),
|
|
4658
|
+
skipInputValidation: true,
|
|
4659
|
+
run: async ({ input }) => input.response
|
|
4660
|
+
});
|
|
4661
|
+
|
|
4662
|
+
// src/transport/attempt-http-request.ts
|
|
4663
|
+
var attemptHttpRequestPlugin = defineMethod({
|
|
4664
|
+
name: "attemptHttpRequest",
|
|
4665
|
+
namespace: "kitcore",
|
|
4666
|
+
imports: [
|
|
4667
|
+
declareDefault({ plugin: prepareHttpRequestPlugin }),
|
|
4668
|
+
declareDefault({ plugin: authorizeHttpRequestPlugin }),
|
|
4669
|
+
declareDefault({ plugin: dispatchHttpRequestPlugin }),
|
|
4670
|
+
declareDefault({ plugin: receiveHttpResponsePlugin })
|
|
4671
|
+
],
|
|
4672
|
+
inputSchema: import_zod9.z.custom(),
|
|
4673
|
+
skipInputValidation: true,
|
|
4674
|
+
run: async ({ input, imports }) => {
|
|
4675
|
+
const { attempt } = input;
|
|
4676
|
+
const preparedRequest = await imports.prepareHttpRequest({
|
|
4677
|
+
request: input.request,
|
|
4678
|
+
attempt
|
|
4679
|
+
});
|
|
4680
|
+
const authorizedRequest = await imports.authorizeHttpRequest({
|
|
4681
|
+
request: preparedRequest,
|
|
4682
|
+
attempt
|
|
4683
|
+
});
|
|
4684
|
+
const response = await imports.dispatchHttpRequest({
|
|
4685
|
+
request: authorizedRequest,
|
|
4686
|
+
attempt
|
|
4687
|
+
});
|
|
4688
|
+
return imports.receiveHttpResponse({
|
|
4689
|
+
request: authorizedRequest,
|
|
4690
|
+
response,
|
|
4691
|
+
attempt
|
|
4692
|
+
});
|
|
4693
|
+
}
|
|
4694
|
+
});
|
|
4695
|
+
|
|
4696
|
+
// src/transport/initialize-http-request.ts
|
|
4697
|
+
var import_zod10 = require("zod");
|
|
4698
|
+
function isReplayableBody(body) {
|
|
4699
|
+
if (body == null || typeof body !== "object") return true;
|
|
4700
|
+
return typeof Blob !== "undefined" && body instanceof Blob || // File extends Blob
|
|
4701
|
+
typeof FormData !== "undefined" && body instanceof FormData || typeof URLSearchParams !== "undefined" && body instanceof URLSearchParams || body instanceof ArrayBuffer || ArrayBuffer.isView(body);
|
|
4702
|
+
}
|
|
4703
|
+
function withStringUrl(request) {
|
|
4704
|
+
return typeof request.url === "string" ? request : { ...request, url: String(request.url) };
|
|
4705
|
+
}
|
|
4706
|
+
var initializeHttpRequestPlugin = defineMethod({
|
|
4707
|
+
name: "initializeHttpRequest",
|
|
4708
|
+
namespace: "kitcore",
|
|
4709
|
+
inputSchema: import_zod10.z.custom(),
|
|
4710
|
+
skipInputValidation: true,
|
|
4711
|
+
run: async ({ input }) => {
|
|
4712
|
+
const request = withStringUrl(input.request);
|
|
4713
|
+
return {
|
|
4714
|
+
...input.operation,
|
|
4715
|
+
request,
|
|
4716
|
+
replayable: isReplayableBody(request.body)
|
|
4717
|
+
};
|
|
4718
|
+
}
|
|
4719
|
+
});
|
|
4720
|
+
|
|
4721
|
+
// src/transport/retry-http-request.ts
|
|
4722
|
+
var RETRY_HTTP_REQUEST_OPTIONS_ID = "kitcore/retryHttpRequestOptions";
|
|
4723
|
+
var retryHttpRequestOptionsPluginRef = declareOptionalProperty({ id: RETRY_HTTP_REQUEST_OPTIONS_ID });
|
|
4724
|
+
var DEFAULT_MAX_ATTEMPTS = 3;
|
|
4725
|
+
var DEFAULT_MAX_DELAY_MILLISECONDS = 6e4;
|
|
4726
|
+
var DEFAULT_RETRY_STATUSES = [429, 500, 502, 503, 504];
|
|
4727
|
+
var DEFAULT_NON_IDEMPOTENT_RETRY_STATUSES = [429];
|
|
4728
|
+
var DEFAULT_IDEMPOTENT_METHODS = [
|
|
4729
|
+
"GET",
|
|
4730
|
+
"HEAD",
|
|
4731
|
+
"PUT",
|
|
4732
|
+
"DELETE",
|
|
4733
|
+
"OPTIONS",
|
|
4734
|
+
"TRACE"
|
|
4735
|
+
];
|
|
4736
|
+
var BASE_BACKOFF_MILLISECONDS = 1e3;
|
|
4737
|
+
var JITTER_FACTOR = 0.5;
|
|
4738
|
+
function directedDelayMilliseconds(response) {
|
|
4739
|
+
const retryAfter = response.headers.get("retry-after");
|
|
4740
|
+
if (retryAfter) {
|
|
4741
|
+
const seconds = Number.parseInt(retryAfter, 10);
|
|
4742
|
+
if (!Number.isNaN(seconds)) return Math.max(0, seconds * 1e3);
|
|
4743
|
+
const date = Date.parse(retryAfter);
|
|
4744
|
+
if (!Number.isNaN(date)) return Math.max(0, date - Date.now());
|
|
4745
|
+
}
|
|
4746
|
+
const reset = response.headers.get("x-ratelimit-reset");
|
|
4747
|
+
if (reset) {
|
|
4748
|
+
const resetSeconds = Number.parseInt(reset, 10);
|
|
4749
|
+
if (!Number.isNaN(resetSeconds)) {
|
|
4750
|
+
return Math.max(0, resetSeconds * 1e3 - Date.now());
|
|
4751
|
+
}
|
|
4752
|
+
}
|
|
4753
|
+
return void 0;
|
|
4754
|
+
}
|
|
4755
|
+
function backoffMilliseconds(attemptNumber) {
|
|
4756
|
+
const base = BASE_BACKOFF_MILLISECONDS * 2 ** (attemptNumber - 1);
|
|
4757
|
+
return base + Math.random() * JITTER_FACTOR * base;
|
|
4758
|
+
}
|
|
4759
|
+
function abortReason(signal) {
|
|
4760
|
+
const reason = signal?.reason;
|
|
4761
|
+
return reason ?? new Error("The request was aborted.");
|
|
4762
|
+
}
|
|
4763
|
+
function sleep(milliseconds, signal) {
|
|
4764
|
+
return new Promise((resolve, reject) => {
|
|
4765
|
+
const timer = setTimeout(finish, milliseconds);
|
|
4766
|
+
function finish() {
|
|
4767
|
+
clearTimeout(timer);
|
|
4768
|
+
signal?.removeEventListener("abort", cancel);
|
|
4769
|
+
resolve();
|
|
4770
|
+
}
|
|
4771
|
+
function cancel() {
|
|
4772
|
+
clearTimeout(timer);
|
|
4773
|
+
reject(abortReason(signal));
|
|
4774
|
+
}
|
|
4775
|
+
if (signal?.aborted) return cancel();
|
|
4776
|
+
signal?.addEventListener("abort", cancel, { once: true });
|
|
4777
|
+
});
|
|
4778
|
+
}
|
|
4779
|
+
function isIdempotent(request, idempotentMethods) {
|
|
4780
|
+
const method = (request.method ?? "GET").toUpperCase();
|
|
4781
|
+
return idempotentMethods.includes(method);
|
|
4782
|
+
}
|
|
4783
|
+
var retryHttpRequestPlugin = defineHook({
|
|
4784
|
+
name: "retryHttpRequest",
|
|
4785
|
+
imports: [attemptHttpRequestPlugin, retryHttpRequestOptionsPluginRef],
|
|
4786
|
+
wrap: {
|
|
4787
|
+
attemptHttpRequest: async ({ input, imports, next }) => {
|
|
4788
|
+
const options = imports.retryHttpRequestOptions ?? {};
|
|
4789
|
+
const maxAttempts = options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS;
|
|
4790
|
+
const maxDelayMilliseconds = options.maxDelayMilliseconds ?? DEFAULT_MAX_DELAY_MILLISECONDS;
|
|
4791
|
+
const idempotentMethods = options.idempotentMethods ?? DEFAULT_IDEMPOTENT_METHODS;
|
|
4792
|
+
const statuses = isIdempotent(input.request, idempotentMethods) ? options.retryStatuses ?? DEFAULT_RETRY_STATUSES : options.nonIdempotentRetryStatuses ?? DEFAULT_NON_IDEMPOTENT_RETRY_STATUSES;
|
|
4793
|
+
for (let attemptNumber = 1; ; attemptNumber++) {
|
|
4794
|
+
const attempt = {
|
|
4795
|
+
...input.attempt,
|
|
4796
|
+
attemptNumber,
|
|
4797
|
+
// Per-attempt scratch: a cross-stage handoff from a previous attempt
|
|
4798
|
+
// describes a request that is no longer in flight. `operation` rides
|
|
4799
|
+
// through unchanged, so the id and the caller's original request are
|
|
4800
|
+
// the same for every attempt.
|
|
4801
|
+
state: {}
|
|
4802
|
+
};
|
|
4803
|
+
let response;
|
|
4804
|
+
try {
|
|
4805
|
+
response = await next({ ...input, attempt });
|
|
4806
|
+
} catch (error) {
|
|
4807
|
+
if (!options.retryOnError || !canRetry(
|
|
4808
|
+
attemptNumber,
|
|
4809
|
+
maxAttempts,
|
|
4810
|
+
input.attempt.operation.replayable
|
|
4811
|
+
)) {
|
|
4812
|
+
throw error;
|
|
4813
|
+
}
|
|
4814
|
+
await sleep(
|
|
4815
|
+
Math.min(backoffMilliseconds(attemptNumber), maxDelayMilliseconds),
|
|
4816
|
+
attempt.signal
|
|
4817
|
+
);
|
|
4818
|
+
continue;
|
|
4819
|
+
}
|
|
4820
|
+
if (!statuses.includes(response.status) || !canRetry(
|
|
4821
|
+
attemptNumber,
|
|
4822
|
+
maxAttempts,
|
|
4823
|
+
input.attempt.operation.replayable
|
|
4824
|
+
)) {
|
|
4825
|
+
return response;
|
|
4826
|
+
}
|
|
4827
|
+
const directed = directedDelayMilliseconds(response);
|
|
4828
|
+
if (directed != null && directed > maxDelayMilliseconds)
|
|
4829
|
+
return response;
|
|
4830
|
+
const delay = Math.min(
|
|
4831
|
+
directed ?? backoffMilliseconds(attemptNumber),
|
|
4832
|
+
maxDelayMilliseconds
|
|
4833
|
+
);
|
|
4834
|
+
await response.body?.cancel().catch(() => {
|
|
4835
|
+
});
|
|
4836
|
+
await sleep(delay, attempt.signal);
|
|
4837
|
+
}
|
|
4838
|
+
}
|
|
4839
|
+
}
|
|
4840
|
+
});
|
|
4841
|
+
function canRetry(attemptNumber, maxAttempts, replayable) {
|
|
4842
|
+
return attemptNumber < maxAttempts && replayable;
|
|
4843
|
+
}
|
|
4844
|
+
|
|
4845
|
+
// src/transport/send-http-request.ts
|
|
4846
|
+
var import_zod11 = require("zod");
|
|
4847
|
+
function createOperationId() {
|
|
4848
|
+
return globalThis.crypto?.randomUUID?.() ?? `http-${Date.now()}`;
|
|
4849
|
+
}
|
|
4850
|
+
var sendHttpRequestPlugin = defineMethod({
|
|
4851
|
+
name: "sendHttpRequest",
|
|
4852
|
+
namespace: "kitcore",
|
|
4853
|
+
imports: [
|
|
4854
|
+
declareDefault({ plugin: initializeHttpRequestPlugin }),
|
|
4855
|
+
declareDefault({ plugin: attemptHttpRequestPlugin })
|
|
4856
|
+
],
|
|
4857
|
+
inputSchema: import_zod11.z.custom(),
|
|
4858
|
+
skipInputValidation: true,
|
|
4859
|
+
run: async ({ input, imports }) => {
|
|
4860
|
+
const start2 = {
|
|
4861
|
+
operationId: createOperationId(),
|
|
4862
|
+
signal: input.signal
|
|
4863
|
+
};
|
|
4864
|
+
const operation = await imports.initializeHttpRequest({
|
|
4865
|
+
request: input,
|
|
4866
|
+
operation: start2
|
|
4867
|
+
});
|
|
4868
|
+
return imports.attemptHttpRequest({
|
|
4869
|
+
request: operation.request,
|
|
4870
|
+
attempt: {
|
|
4871
|
+
attemptNumber: 1,
|
|
4872
|
+
operation,
|
|
4873
|
+
signal: operation.signal,
|
|
4874
|
+
state: {}
|
|
4875
|
+
}
|
|
4876
|
+
});
|
|
4877
|
+
}
|
|
4878
|
+
});
|
|
4879
|
+
|
|
4880
|
+
// src/transport/fetch.ts
|
|
4881
|
+
var import_zod12 = require("zod");
|
|
4882
|
+
var fetchPlugin = defineMethod({
|
|
4883
|
+
name: "fetch",
|
|
4884
|
+
namespace: "kitcore",
|
|
4885
|
+
imports: [declareDefault({ plugin: sendHttpRequestPlugin })],
|
|
4886
|
+
positional: ["url", "init"],
|
|
4887
|
+
inputSchema: import_zod12.z.custom(),
|
|
4888
|
+
skipInputValidation: true,
|
|
4889
|
+
run: ({ input, imports }) => {
|
|
4890
|
+
const { url, init } = input;
|
|
4891
|
+
return imports.sendHttpRequest({ url, ...init });
|
|
4892
|
+
}
|
|
4893
|
+
});
|
|
4894
|
+
|
|
4895
|
+
// src/transport/redact.ts
|
|
4896
|
+
var CREDENTIAL_HEADERS = ["authorization", "x-api-key"];
|
|
4897
|
+
function maskSecret(secret) {
|
|
4898
|
+
if (secret.length > 12) {
|
|
4899
|
+
return `${secret.slice(0, 4)}...${secret.slice(-4)}`;
|
|
4900
|
+
}
|
|
4901
|
+
return `${secret.charAt(0)}...`;
|
|
4902
|
+
}
|
|
4903
|
+
function maskCredentialHeader(value) {
|
|
4904
|
+
const spaceIndex = value.indexOf(" ");
|
|
4905
|
+
if (spaceIndex > 0 && spaceIndex < value.length - 1) {
|
|
4906
|
+
return `${value.slice(0, spaceIndex + 1)}${maskSecret(value.slice(spaceIndex + 1))}`;
|
|
4907
|
+
}
|
|
4908
|
+
return maskSecret(value);
|
|
4909
|
+
}
|
|
4910
|
+
function redactHeaders(headers) {
|
|
4911
|
+
if (!headers) return headers;
|
|
4912
|
+
const normalized = new Headers(headers);
|
|
4913
|
+
for (const [name, value] of normalized.entries()) {
|
|
4914
|
+
if (CREDENTIAL_HEADERS.includes(name.toLowerCase())) {
|
|
4915
|
+
normalized.set(name, maskCredentialHeader(value));
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4918
|
+
return Object.fromEntries(normalized);
|
|
4919
|
+
}
|
|
4920
|
+
function redactHttpRequest(request) {
|
|
4921
|
+
const redacted = { ...request };
|
|
4922
|
+
if (request.headers) redacted.headers = redactHeaders(request.headers);
|
|
4923
|
+
if (request.connection != null) {
|
|
4924
|
+
redacted.connection = maskSecret(request.connection);
|
|
4925
|
+
}
|
|
4926
|
+
return redacted;
|
|
4927
|
+
}
|
|
4928
|
+
|
|
4929
|
+
// src/connections/default-connection-scheme.ts
|
|
4930
|
+
var import_zod13 = require("zod");
|
|
4931
|
+
var defaultConnectionSchemePlugin = defineMethod({
|
|
4932
|
+
name: "defaultConnectionScheme",
|
|
4933
|
+
namespace: "kitcore",
|
|
4934
|
+
inputSchema: import_zod13.z.custom(),
|
|
4935
|
+
skipInputValidation: true,
|
|
4936
|
+
run: () => void 0
|
|
4937
|
+
});
|
|
4938
|
+
|
|
4939
|
+
// src/connections/normalize-connection.ts
|
|
4940
|
+
var import_zod14 = require("zod");
|
|
4941
|
+
var normalizeConnectionPlugin = defineMethod({
|
|
4942
|
+
name: "normalizeConnection",
|
|
4943
|
+
namespace: "kitcore",
|
|
4944
|
+
imports: [declareDefault({ plugin: defaultConnectionSchemePlugin })],
|
|
4945
|
+
inputSchema: import_zod14.z.custom(),
|
|
4946
|
+
skipInputValidation: true,
|
|
4947
|
+
run: ({ input, imports }) => {
|
|
4948
|
+
const { connection } = input;
|
|
4949
|
+
if (connection == null) {
|
|
4950
|
+
return void 0;
|
|
4951
|
+
}
|
|
4952
|
+
const delimiterIndex = connection.indexOf(":");
|
|
4953
|
+
if (delimiterIndex !== -1) {
|
|
4954
|
+
return {
|
|
4955
|
+
connection,
|
|
4956
|
+
scheme: connection.slice(0, delimiterIndex),
|
|
4957
|
+
value: connection.slice(delimiterIndex + 1)
|
|
4958
|
+
};
|
|
4959
|
+
}
|
|
4960
|
+
const scheme = imports.defaultConnectionScheme({ connection });
|
|
4961
|
+
return {
|
|
4962
|
+
connection,
|
|
4963
|
+
scheme,
|
|
4964
|
+
value: connection
|
|
4965
|
+
};
|
|
4966
|
+
}
|
|
4967
|
+
});
|
|
4968
|
+
|
|
4969
|
+
// src/connections/resolve-connection.ts
|
|
4970
|
+
var import_zod15 = require("zod");
|
|
4971
|
+
var resolveConnectionPlugin = defineMethod({
|
|
4972
|
+
name: "resolveConnection",
|
|
4973
|
+
namespace: "kitcore",
|
|
4974
|
+
inputSchema: import_zod15.z.custom(),
|
|
4975
|
+
skipInputValidation: true,
|
|
4976
|
+
run: ({ input }) => input.connection
|
|
4977
|
+
});
|
|
4488
4978
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4489
4979
|
0 && (module.exports = {
|
|
4490
4980
|
CONTEXT,
|
|
@@ -4496,7 +4986,13 @@ function createCorePlugin(options) {
|
|
|
4496
4986
|
CoreError,
|
|
4497
4987
|
CoreErrorCode,
|
|
4498
4988
|
CoreSignal,
|
|
4989
|
+
RETRY_HTTP_REQUEST_OPTIONS_ID,
|
|
4990
|
+
STABILITY_LEVELS,
|
|
4991
|
+
STABILITY_TITLES,
|
|
4499
4992
|
addPlugin,
|
|
4993
|
+
applyStabilityLabel,
|
|
4994
|
+
attemptHttpRequestPlugin,
|
|
4995
|
+
authorizeHttpRequestPlugin,
|
|
4500
4996
|
canonicalInputSchema,
|
|
4501
4997
|
composePlugins,
|
|
4502
4998
|
concatLists,
|
|
@@ -4514,6 +5010,7 @@ function createCorePlugin(options) {
|
|
|
4514
5010
|
createPluginStack,
|
|
4515
5011
|
createPrefixedCursor,
|
|
4516
5012
|
createSdk,
|
|
5013
|
+
createStabilityNoticeLogger,
|
|
4517
5014
|
createValidator,
|
|
4518
5015
|
dangerousContextPlugin,
|
|
4519
5016
|
declareDefault,
|
|
@@ -4523,6 +5020,7 @@ function createCorePlugin(options) {
|
|
|
4523
5020
|
declarePlugin,
|
|
4524
5021
|
declareProperty,
|
|
4525
5022
|
decodeIncomingCursor,
|
|
5023
|
+
defaultConnectionSchemePlugin,
|
|
4526
5024
|
defaultLogDeprecation,
|
|
4527
5025
|
defineFormatter,
|
|
4528
5026
|
defineHook,
|
|
@@ -4532,7 +5030,9 @@ function createCorePlugin(options) {
|
|
|
4532
5030
|
definePlugin,
|
|
4533
5031
|
defineProperty,
|
|
4534
5032
|
defineResolver,
|
|
5033
|
+
dispatchHttpRequestPlugin,
|
|
4535
5034
|
disposeSdk,
|
|
5035
|
+
fetchPlugin,
|
|
4536
5036
|
fromFunctionPlugin,
|
|
4537
5037
|
getContext,
|
|
4538
5038
|
getCoreErrorCause,
|
|
@@ -4544,21 +5044,32 @@ function createCorePlugin(options) {
|
|
|
4544
5044
|
getOutputSchema,
|
|
4545
5045
|
getRegistryPlugin,
|
|
4546
5046
|
getSchemaDescription,
|
|
5047
|
+
initializeHttpRequestPlugin,
|
|
4547
5048
|
isCoreCancelledSignal,
|
|
4548
5049
|
isCoreError,
|
|
4549
5050
|
isCoreSignal,
|
|
4550
5051
|
isNestedMethodCall,
|
|
4551
5052
|
isPositional,
|
|
4552
5053
|
isTelemetryNested,
|
|
5054
|
+
normalizeConnectionPlugin,
|
|
5055
|
+
normalizeStability,
|
|
4553
5056
|
omitExports,
|
|
4554
5057
|
openEnum,
|
|
4555
5058
|
paginate,
|
|
4556
5059
|
paginateBuffered,
|
|
4557
5060
|
paginateMaxItems,
|
|
5061
|
+
prepareHttpRequestPlugin,
|
|
5062
|
+
receiveHttpResponsePlugin,
|
|
5063
|
+
redactHeaders,
|
|
5064
|
+
redactHttpRequest,
|
|
5065
|
+
resolveConnectionPlugin,
|
|
4558
5066
|
resolvePlugin,
|
|
5067
|
+
retryHttpRequestOptionsPluginRef,
|
|
5068
|
+
retryHttpRequestPlugin,
|
|
4559
5069
|
runInMethodScope,
|
|
4560
5070
|
runWithTelemetryContext,
|
|
4561
5071
|
selectExports,
|
|
5072
|
+
sendHttpRequestPlugin,
|
|
4562
5073
|
splitPrefixedCursor,
|
|
4563
5074
|
toIterable,
|
|
4564
5075
|
toSnakeCase,
|