@zayne-labs/callapi 1.11.31 → 1.11.33
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/dist/{index-DP2YeNBA.d.ts → index-YnlEWnbR.d.ts} +243 -235
- package/dist/index.d.ts +1 -2
- package/dist/index.js +47 -60
- package/dist/index.js.map +1 -1
- package/dist/utils/external/index.d.ts +1 -2
- package/dist/utils/external/index.js +0 -1
- package/dist/utils/external/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -17,17 +17,22 @@ const getAuthHeader = async (auth) => {
|
|
|
17
17
|
if (username === void 0 || password === void 0) return;
|
|
18
18
|
return { Authorization: `Basic ${globalThis.btoa(`${username}:${password}`)}` };
|
|
19
19
|
}
|
|
20
|
+
case "Bearer": {
|
|
21
|
+
const value = await resolveAuthValue(auth.value);
|
|
22
|
+
if (value === void 0) return;
|
|
23
|
+
return { Authorization: `Bearer ${value}` };
|
|
24
|
+
}
|
|
20
25
|
case "Custom": {
|
|
21
26
|
const [prefix, value] = await Promise.all([resolveAuthValue(auth.prefix), resolveAuthValue(auth.value)]);
|
|
22
27
|
if (value === void 0) return;
|
|
23
28
|
return { Authorization: `${prefix} ${value}` };
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
return { Authorization: `Token ${token}` };
|
|
30
|
+
case "Token": {
|
|
31
|
+
const value = await resolveAuthValue(auth.value);
|
|
32
|
+
if (value === void 0) return;
|
|
33
|
+
return { Authorization: `Token ${value}` };
|
|
30
34
|
}
|
|
35
|
+
default: return;
|
|
31
36
|
}
|
|
32
37
|
};
|
|
33
38
|
|
|
@@ -80,7 +85,8 @@ const handleSchemaValidation = async (fullSchema, schemaName, validationOptions)
|
|
|
80
85
|
const extraOptionsToBeValidated = [
|
|
81
86
|
"meta",
|
|
82
87
|
"params",
|
|
83
|
-
"query"
|
|
88
|
+
"query",
|
|
89
|
+
"auth"
|
|
84
90
|
];
|
|
85
91
|
const handleExtraOptionsValidation = async (validationOptions) => {
|
|
86
92
|
const { options, schema, schemaConfig } = validationOptions;
|
|
@@ -322,21 +328,16 @@ const pickKeys = (initialObject, keysToPick) => {
|
|
|
322
328
|
const splitBaseConfig = (baseConfig) => [pickKeys(baseConfig, fetchSpecificKeys), omitKeys(baseConfig, fetchSpecificKeys)];
|
|
323
329
|
const splitConfig = (config) => [pickKeys(config, fetchSpecificKeys), omitKeys(config, fetchSpecificKeys)];
|
|
324
330
|
const objectifyHeaders = (headers) => {
|
|
325
|
-
if (!headers
|
|
331
|
+
if (!headers) return {};
|
|
332
|
+
if (isPlainObject(headers)) return headers;
|
|
326
333
|
return Object.fromEntries(headers);
|
|
327
334
|
};
|
|
328
335
|
const getResolvedHeaders = (options) => {
|
|
329
336
|
const { baseHeaders, headers } = options;
|
|
330
|
-
|
|
331
|
-
if (!resolvedHeaders) return;
|
|
332
|
-
return objectifyHeaders(resolvedHeaders);
|
|
337
|
+
return objectifyHeaders(isFunction(headers) ? headers({ baseHeaders: objectifyHeaders(baseHeaders) }) : headers ?? baseHeaders);
|
|
333
338
|
};
|
|
334
339
|
const getHeaders = async (options) => {
|
|
335
|
-
const { auth,
|
|
336
|
-
const resolvedHeaders = getResolvedHeaders({
|
|
337
|
-
baseHeaders,
|
|
338
|
-
headers
|
|
339
|
-
});
|
|
340
|
+
const { auth, body, resolvedHeaders } = options;
|
|
340
341
|
const headersObject = {
|
|
341
342
|
...await getAuthHeader(auth),
|
|
342
343
|
...objectifyHeaders(resolvedHeaders)
|
|
@@ -795,58 +796,47 @@ const getResolvedPlugins = (context) => {
|
|
|
795
796
|
const { baseConfig, options } = context;
|
|
796
797
|
return isFunction(options.plugins) ? options.plugins({ basePlugins: baseConfig.plugins ?? [] }) : options.plugins ?? [];
|
|
797
798
|
};
|
|
798
|
-
const initializePlugins = async (
|
|
799
|
-
const { baseConfig, config, initURL, options, request } =
|
|
799
|
+
const initializePlugins = async (setupContext) => {
|
|
800
|
+
const { baseConfig, config, initURL, options, request } = setupContext;
|
|
800
801
|
const { addMainHooks, addMainMiddlewares, addPluginHooks, addPluginMiddlewares, getResolvedHooks, getResolvedMiddlewares } = setupHooksAndMiddlewares({
|
|
801
802
|
baseConfig,
|
|
802
803
|
config,
|
|
803
804
|
options
|
|
804
805
|
});
|
|
805
|
-
const
|
|
806
|
+
const initURLResult = getCurrentRouteSchemaKeyAndMainInitURL({
|
|
806
807
|
baseExtraOptions: baseConfig,
|
|
807
808
|
extraOptions: config,
|
|
808
809
|
initURL
|
|
809
810
|
});
|
|
810
|
-
let resolvedCurrentRouteSchemaKey = currentRouteSchemaKey;
|
|
811
|
-
let resolvedInitURL = mainInitURL;
|
|
812
|
-
|
|
813
|
-
|
|
811
|
+
let resolvedCurrentRouteSchemaKey = initURLResult.currentRouteSchemaKey;
|
|
812
|
+
let resolvedInitURL = initURLResult.mainInitURL;
|
|
813
|
+
const resolvedOptions = options;
|
|
814
|
+
const resolvedRequest = Object.assign(request, {
|
|
815
|
+
headers: getResolvedHeaders({
|
|
816
|
+
baseHeaders: baseConfig.headers,
|
|
817
|
+
headers: config.headers
|
|
818
|
+
}),
|
|
819
|
+
method: getMethod({
|
|
820
|
+
initURL: resolvedInitURL,
|
|
821
|
+
method: request.method
|
|
822
|
+
})
|
|
823
|
+
});
|
|
814
824
|
const executePluginSetupFn = async (pluginSetup) => {
|
|
815
825
|
if (!pluginSetup) return;
|
|
816
|
-
const initResult = await pluginSetup(
|
|
817
|
-
if (!
|
|
826
|
+
const initResult = await pluginSetup(setupContext);
|
|
827
|
+
if (!initResult) return;
|
|
818
828
|
const urlString = initResult.initURL?.toString();
|
|
819
829
|
if (isString(urlString)) {
|
|
820
|
-
const
|
|
830
|
+
const newURLResult = getCurrentRouteSchemaKeyAndMainInitURL({
|
|
821
831
|
baseExtraOptions: baseConfig,
|
|
822
832
|
extraOptions: config,
|
|
823
833
|
initURL: urlString
|
|
824
834
|
});
|
|
825
|
-
resolvedCurrentRouteSchemaKey =
|
|
826
|
-
resolvedInitURL =
|
|
827
|
-
}
|
|
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
|
-
};
|
|
835
|
+
resolvedCurrentRouteSchemaKey = newURLResult.currentRouteSchemaKey;
|
|
836
|
+
resolvedInitURL = newURLResult.mainInitURL;
|
|
845
837
|
}
|
|
846
|
-
if (
|
|
847
|
-
|
|
848
|
-
...initResult.options
|
|
849
|
-
};
|
|
838
|
+
if (initResult.request) Object.assign(resolvedRequest, initResult.request);
|
|
839
|
+
if (initResult.options) Object.assign(resolvedOptions, initResult.options);
|
|
850
840
|
};
|
|
851
841
|
const resolvedPlugins = getResolvedPlugins({
|
|
852
842
|
baseConfig,
|
|
@@ -855,8 +845,8 @@ const initializePlugins = async (context) => {
|
|
|
855
845
|
for (const plugin of resolvedPlugins) {
|
|
856
846
|
const [, pluginHooks, pluginMiddlewares] = await Promise.all([
|
|
857
847
|
executePluginSetupFn(plugin.setup),
|
|
858
|
-
isFunction(plugin.hooks) ? plugin.hooks(
|
|
859
|
-
isFunction(plugin.middlewares) ? plugin.middlewares(
|
|
848
|
+
isFunction(plugin.hooks) ? plugin.hooks(setupContext) : plugin.hooks,
|
|
849
|
+
isFunction(plugin.middlewares) ? plugin.middlewares(setupContext) : plugin.middlewares
|
|
860
850
|
]);
|
|
861
851
|
pluginHooks && addPluginHooks(pluginHooks);
|
|
862
852
|
pluginMiddlewares && addPluginMiddlewares(pluginMiddlewares);
|
|
@@ -1017,7 +1007,6 @@ const createFetchClientWithContext = () => {
|
|
|
1017
1007
|
...!shouldSkipAutoMergeForOptions && extraOptions
|
|
1018
1008
|
};
|
|
1019
1009
|
const mergedRequestOptions = {
|
|
1020
|
-
headers: {},
|
|
1021
1010
|
...baseFetchOptions,
|
|
1022
1011
|
...!shouldSkipAutoMergeForRequest && fetchOptions
|
|
1023
1012
|
};
|
|
@@ -1073,17 +1062,15 @@ const createFetchClientWithContext = () => {
|
|
|
1073
1062
|
request
|
|
1074
1063
|
});
|
|
1075
1064
|
Object.assign(options, extraOptionsValidationResult);
|
|
1076
|
-
const validBody = getBody({
|
|
1077
|
-
body: requestOptionsValidationResult.body,
|
|
1078
|
-
bodySerializer: options.bodySerializer
|
|
1079
|
-
});
|
|
1080
1065
|
Object.assign(request, {
|
|
1081
|
-
body:
|
|
1066
|
+
body: getBody({
|
|
1067
|
+
body: requestOptionsValidationResult.body,
|
|
1068
|
+
bodySerializer: options.bodySerializer
|
|
1069
|
+
}),
|
|
1082
1070
|
headers: await getHeaders({
|
|
1083
1071
|
auth: options.auth,
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
headers: requestOptionsValidationResult.headers
|
|
1072
|
+
body: requestOptionsValidationResult.body,
|
|
1073
|
+
resolvedHeaders: requestOptionsValidationResult.headers
|
|
1087
1074
|
}),
|
|
1088
1075
|
method: getMethod({
|
|
1089
1076
|
initURL: resolvedInitURL,
|