@zayne-labs/callapi 1.11.29 → 1.11.31
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/README.md +57 -57
- package/dist/defaults-B-dOt2Dd.js.map +1 -1
- package/dist/{index-CrJL7qOL.d.ts → index-DP2YeNBA.d.ts} +47 -34
- package/dist/index.d.ts +2 -2
- package/dist/index.js +66 -52
- package/dist/index.js.map +1 -1
- package/dist/utils/external/index.d.ts +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -67,11 +67,15 @@ const routeKeyMethods = defineEnum([
|
|
|
67
67
|
]);
|
|
68
68
|
const handleSchemaValidation = async (fullSchema, schemaName, validationOptions) => {
|
|
69
69
|
const { inputValue, response, schemaConfig } = validationOptions;
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const disableRuntimeValidationBooleanObject = isObject(schemaConfig?.disableRuntimeValidation) ? schemaConfig.disableRuntimeValidation : {};
|
|
71
|
+
if (schemaConfig?.disableRuntimeValidation === true || disableRuntimeValidationBooleanObject[schemaName] === true) return inputValue;
|
|
72
|
+
const validResult = await standardSchemaParser(fullSchema, schemaName, {
|
|
72
73
|
inputValue,
|
|
73
74
|
response
|
|
74
75
|
});
|
|
76
|
+
const disableResultApplicationBooleanObject = isObject(schemaConfig?.disableValidationOutputApplication) ? schemaConfig.disableValidationOutputApplication : {};
|
|
77
|
+
if (schemaConfig?.disableValidationOutputApplication === true || disableResultApplicationBooleanObject[schemaName] === true) return inputValue;
|
|
78
|
+
return validResult;
|
|
75
79
|
};
|
|
76
80
|
const extraOptionsToBeValidated = [
|
|
77
81
|
"meta",
|
|
@@ -98,11 +102,13 @@ const requestOptionsToBeValidated = [
|
|
|
98
102
|
"method"
|
|
99
103
|
];
|
|
100
104
|
const handleRequestOptionsValidation = async (validationOptions) => {
|
|
101
|
-
const {
|
|
102
|
-
const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((schemaName) =>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
const { request, schema, schemaConfig } = validationOptions;
|
|
106
|
+
const validationResultArray = await Promise.all(requestOptionsToBeValidated.map((schemaName) => {
|
|
107
|
+
return handleSchemaValidation(schema, schemaName, {
|
|
108
|
+
inputValue: request[schemaName],
|
|
109
|
+
schemaConfig
|
|
110
|
+
});
|
|
111
|
+
}));
|
|
106
112
|
const validatedResultObject = {};
|
|
107
113
|
for (const [index, propertyKey] of requestOptionsToBeValidated.entries()) {
|
|
108
114
|
const validationResult = validationResultArray[index];
|
|
@@ -112,7 +118,7 @@ const handleRequestOptionsValidation = async (validationOptions) => {
|
|
|
112
118
|
return validatedResultObject;
|
|
113
119
|
};
|
|
114
120
|
const handleConfigValidation = async (validationOptions) => {
|
|
115
|
-
const { baseExtraOptions, currentRouteSchemaKey, extraOptions, options,
|
|
121
|
+
const { baseExtraOptions, currentRouteSchemaKey, extraOptions, options, request } = validationOptions;
|
|
116
122
|
const { currentRouteSchema, resolvedSchema } = getResolvedSchema({
|
|
117
123
|
baseExtraOptions,
|
|
118
124
|
currentRouteSchemaKey,
|
|
@@ -127,19 +133,12 @@ const handleConfigValidation = async (validationOptions) => {
|
|
|
127
133
|
issues: [{ message: `Strict Mode - No schema found for route '${currentRouteSchemaKey}' ` }],
|
|
128
134
|
response: null
|
|
129
135
|
});
|
|
130
|
-
if (resolvedSchemaConfig?.disableRuntimeValidation) return {
|
|
131
|
-
extraOptionsValidationResult: null,
|
|
132
|
-
requestOptionsValidationResult: null,
|
|
133
|
-
resolvedSchema,
|
|
134
|
-
resolvedSchemaConfig,
|
|
135
|
-
shouldApplySchemaOutput: false
|
|
136
|
-
};
|
|
137
136
|
const [extraOptionsValidationResult, requestOptionsValidationResult] = await Promise.all([handleExtraOptionsValidation({
|
|
138
137
|
options,
|
|
139
138
|
schema: resolvedSchema,
|
|
140
139
|
schemaConfig: resolvedSchemaConfig
|
|
141
140
|
}), handleRequestOptionsValidation({
|
|
142
|
-
|
|
141
|
+
request,
|
|
143
142
|
schema: resolvedSchema,
|
|
144
143
|
schemaConfig: resolvedSchemaConfig
|
|
145
144
|
})]);
|
|
@@ -147,8 +146,7 @@ const handleConfigValidation = async (validationOptions) => {
|
|
|
147
146
|
extraOptionsValidationResult,
|
|
148
147
|
requestOptionsValidationResult,
|
|
149
148
|
resolvedSchema,
|
|
150
|
-
resolvedSchemaConfig
|
|
151
|
-
shouldApplySchemaOutput: (Boolean(extraOptionsValidationResult) || Boolean(requestOptionsValidationResult)) && !resolvedSchemaConfig?.disableValidationOutputApplication
|
|
149
|
+
resolvedSchemaConfig
|
|
152
150
|
};
|
|
153
151
|
};
|
|
154
152
|
const getResolvedSchema = (context) => {
|
|
@@ -327,12 +325,21 @@ const objectifyHeaders = (headers) => {
|
|
|
327
325
|
if (!headers || isPlainObject(headers)) return headers;
|
|
328
326
|
return Object.fromEntries(headers);
|
|
329
327
|
};
|
|
328
|
+
const getResolvedHeaders = (options) => {
|
|
329
|
+
const { baseHeaders, headers } = options;
|
|
330
|
+
const resolvedHeaders = isFunction(headers) ? headers({ baseHeaders: baseHeaders ?? {} }) : headers ?? baseHeaders;
|
|
331
|
+
if (!resolvedHeaders) return;
|
|
332
|
+
return objectifyHeaders(resolvedHeaders);
|
|
333
|
+
};
|
|
330
334
|
const getHeaders = async (options) => {
|
|
331
|
-
const { auth, body, headers } = options;
|
|
332
|
-
|
|
335
|
+
const { auth, baseHeaders, body, headers } = options;
|
|
336
|
+
const resolvedHeaders = getResolvedHeaders({
|
|
337
|
+
baseHeaders,
|
|
338
|
+
headers
|
|
339
|
+
});
|
|
333
340
|
const headersObject = {
|
|
334
341
|
...await getAuthHeader(auth),
|
|
335
|
-
...objectifyHeaders(
|
|
342
|
+
...objectifyHeaders(resolvedHeaders)
|
|
336
343
|
};
|
|
337
344
|
if (isQueryString(body)) {
|
|
338
345
|
headersObject["Content-Type"] = "application/x-www-form-urlencoded";
|
|
@@ -803,7 +810,7 @@ const initializePlugins = async (context) => {
|
|
|
803
810
|
let resolvedCurrentRouteSchemaKey = currentRouteSchemaKey;
|
|
804
811
|
let resolvedInitURL = mainInitURL;
|
|
805
812
|
let resolvedOptions = options;
|
|
806
|
-
let
|
|
813
|
+
let resolvedRequest = request;
|
|
807
814
|
const executePluginSetupFn = async (pluginSetup) => {
|
|
808
815
|
if (!pluginSetup) return;
|
|
809
816
|
const initResult = await pluginSetup(context);
|
|
@@ -818,10 +825,24 @@ const initializePlugins = async (context) => {
|
|
|
818
825
|
resolvedCurrentRouteSchemaKey = newResult.currentRouteSchemaKey;
|
|
819
826
|
resolvedInitURL = newResult.mainInitURL;
|
|
820
827
|
}
|
|
821
|
-
if (isPlainObject(initResult.request))
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
828
|
+
if (isPlainObject(initResult.request)) {
|
|
829
|
+
const initMethod = getMethod({
|
|
830
|
+
initURL: resolvedInitURL,
|
|
831
|
+
method: initResult.request.method ?? resolvedRequest.method
|
|
832
|
+
});
|
|
833
|
+
const initHeaders = await getHeaders({
|
|
834
|
+
auth: options.auth,
|
|
835
|
+
baseHeaders: baseConfig.headers,
|
|
836
|
+
body: initResult.request.body ?? resolvedRequest.body,
|
|
837
|
+
headers: initResult.request.headers ?? resolvedRequest.headers
|
|
838
|
+
});
|
|
839
|
+
resolvedRequest = {
|
|
840
|
+
...resolvedRequest,
|
|
841
|
+
...initResult.request,
|
|
842
|
+
headers: initHeaders,
|
|
843
|
+
method: initMethod
|
|
844
|
+
};
|
|
845
|
+
}
|
|
825
846
|
if (isPlainObject(initResult.options)) resolvedOptions = {
|
|
826
847
|
...resolvedOptions,
|
|
827
848
|
...initResult.options
|
|
@@ -850,7 +871,7 @@ const initializePlugins = async (context) => {
|
|
|
850
871
|
resolvedInitURL,
|
|
851
872
|
resolvedMiddlewares,
|
|
852
873
|
resolvedOptions,
|
|
853
|
-
|
|
874
|
+
resolvedRequest
|
|
854
875
|
};
|
|
855
876
|
};
|
|
856
877
|
const setupHooksAndMiddlewares = (context) => {
|
|
@@ -1000,7 +1021,7 @@ const createFetchClientWithContext = () => {
|
|
|
1000
1021
|
...baseFetchOptions,
|
|
1001
1022
|
...!shouldSkipAutoMergeForRequest && fetchOptions
|
|
1002
1023
|
};
|
|
1003
|
-
const { resolvedCurrentRouteSchemaKey, resolvedHooks, resolvedInitURL, resolvedMiddlewares, resolvedOptions,
|
|
1024
|
+
const { resolvedCurrentRouteSchemaKey, resolvedHooks, resolvedInitURL, resolvedMiddlewares, resolvedOptions, resolvedRequest } = await initializePlugins({
|
|
1004
1025
|
baseConfig,
|
|
1005
1026
|
config,
|
|
1006
1027
|
initURL: initURL.toString(),
|
|
@@ -1022,14 +1043,9 @@ const createFetchClientWithContext = () => {
|
|
|
1022
1043
|
initURLNormalized: normalizedInitURL
|
|
1023
1044
|
};
|
|
1024
1045
|
const newFetchController = new AbortController();
|
|
1025
|
-
const combinedSignal = createCombinedSignal(createTimeoutSignal(options.timeout),
|
|
1026
|
-
const initMethod = getMethod({
|
|
1027
|
-
initURL: resolvedInitURL,
|
|
1028
|
-
method: resolvedRequestOptions.method
|
|
1029
|
-
});
|
|
1046
|
+
const combinedSignal = createCombinedSignal(createTimeoutSignal(options.timeout), resolvedRequest.signal, newFetchController.signal);
|
|
1030
1047
|
const request = {
|
|
1031
|
-
...
|
|
1032
|
-
method: initMethod,
|
|
1048
|
+
...resolvedRequest,
|
|
1033
1049
|
signal: combinedSignal
|
|
1034
1050
|
};
|
|
1035
1051
|
const { getAbortErrorMessage, handleRequestCancelStrategy, handleRequestDeferStrategy, removeDedupeKeyFromCache, resolvedDedupeStrategy } = await createDedupeStrategy({
|
|
@@ -1049,32 +1065,30 @@ const createFetchClientWithContext = () => {
|
|
|
1049
1065
|
options,
|
|
1050
1066
|
request
|
|
1051
1067
|
}));
|
|
1052
|
-
const { extraOptionsValidationResult, requestOptionsValidationResult, resolvedSchema, resolvedSchemaConfig
|
|
1068
|
+
const { extraOptionsValidationResult, requestOptionsValidationResult, resolvedSchema, resolvedSchemaConfig } = await handleConfigValidation({
|
|
1053
1069
|
baseExtraOptions,
|
|
1054
1070
|
currentRouteSchemaKey: resolvedCurrentRouteSchemaKey,
|
|
1055
1071
|
extraOptions,
|
|
1056
1072
|
options,
|
|
1057
|
-
|
|
1058
|
-
});
|
|
1059
|
-
if (shouldApplySchemaOutput) Object.assign(options, extraOptionsValidationResult);
|
|
1060
|
-
const validMethod = getMethod({
|
|
1061
|
-
initURL: resolvedInitURL,
|
|
1062
|
-
method: shouldApplySchemaOutput ? requestOptionsValidationResult?.method : request.method
|
|
1073
|
+
request
|
|
1063
1074
|
});
|
|
1075
|
+
Object.assign(options, extraOptionsValidationResult);
|
|
1064
1076
|
const validBody = getBody({
|
|
1065
|
-
body:
|
|
1077
|
+
body: requestOptionsValidationResult.body,
|
|
1066
1078
|
bodySerializer: options.bodySerializer
|
|
1067
1079
|
});
|
|
1068
|
-
const resolvedHeaders = isFunction(fetchOptions.headers) ? fetchOptions.headers({ baseHeaders: baseFetchOptions.headers ?? {} }) : fetchOptions.headers ?? baseFetchOptions.headers;
|
|
1069
|
-
const validHeaders = await getHeaders({
|
|
1070
|
-
auth: options.auth,
|
|
1071
|
-
body: validBody,
|
|
1072
|
-
headers: shouldApplySchemaOutput ? requestOptionsValidationResult?.headers : resolvedHeaders
|
|
1073
|
-
});
|
|
1074
1080
|
Object.assign(request, {
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1081
|
+
body: validBody,
|
|
1082
|
+
headers: await getHeaders({
|
|
1083
|
+
auth: options.auth,
|
|
1084
|
+
baseHeaders: baseConfig.headers,
|
|
1085
|
+
body: validBody,
|
|
1086
|
+
headers: requestOptionsValidationResult.headers
|
|
1087
|
+
}),
|
|
1088
|
+
method: getMethod({
|
|
1089
|
+
initURL: resolvedInitURL,
|
|
1090
|
+
method: requestOptionsValidationResult.method
|
|
1091
|
+
})
|
|
1078
1092
|
});
|
|
1079
1093
|
const readyRequestContext = {
|
|
1080
1094
|
baseConfig,
|