@zayne-labs/callapi 1.11.34 → 1.11.36
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/{guards-ZYV-Q_as.js → external-DXaCWLPN.js} +41 -9
- package/dist/external-DXaCWLPN.js.map +1 -0
- package/dist/{index-YnlEWnbR.d.ts → index-CGn8h_Ai.d.ts} +810 -762
- package/dist/index.d.ts +2 -2
- package/dist/index.js +37 -21
- package/dist/index.js.map +1 -1
- package/dist/utils/external/index.d.ts +3 -9
- package/dist/utils/external/index.js +2 -27
- package/package.json +7 -7
- package/dist/guards-ZYV-Q_as.js.map +0 -1
- package/dist/utils/external/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaRoutes, BaseSchemaRouteKeyPrefixes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResultLoose as CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessOrErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultCallApiContext, ErrorContext, GetExtendSchemaConfigContext, Hooks, HooksOrHooksArray, InferExtendSchemaContext, InferParamsFromRoute, InferSchemaInput, InferSchemaOutput, InstanceContext, PluginHooks, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeType, ResultModeType, RetryOptions, SuccessContext, URLOptions, callApi, createFetchClient, createFetchClientWithContext };
|
|
1
|
+
import { $ as ResponseStreamContext, A as Register, B as InferSchemaInput, C as CallApiParameters, D as GetExtendSchemaConfigContext, E as CallApiResultLoose, F as URLOptions, G as DedupeOptions, H as FetchImpl, I as BaseCallApiSchemaRoutes, J as HooksOrHooksArray, K as ErrorContext, L as BaseSchemaRouteKeyPrefixes, N as RetryOptions, O as InferExtendSchemaContext, P as InferParamsFromRoute, Q as ResponseErrorContext, R as CallApiSchema, S as CallApiExtraOptionsForHooks, T as CallApiRequestOptionsForHooks, U as FetchMiddlewareContext, V as InferSchemaOutput, W as Middlewares, X as RequestStreamContext, Y as RequestContext, Z as ResponseContext, _ as ResultModeType, a as CallApiPlugin, b as CallApiConfig, c as PluginSetupContext, d as CallApiResultSuccessVariant, et as SuccessContext, f as PossibleHTTPError, g as ResponseTypeType, h as PossibleValidationError, i as DefaultCallApiContext, k as InstanceContext, l as CallApiResultErrorVariant, m as PossibleJavaScriptOrValidationError, n as createFetchClient, o as PluginHooks, p as PossibleJavaScriptError, q as Hooks, r as createFetchClientWithContext, s as PluginMiddlewares, t as callApi, u as CallApiResultSuccessOrErrorVariant, v as BaseCallApiConfig, w as CallApiRequestOptions, x as CallApiExtraOptions, y as BaseCallApiExtraOptions, z as CallApiSchemaConfig } from "./index-CGn8h_Ai.js";
|
|
2
|
+
export { BaseCallApiConfig, BaseCallApiExtraOptions, BaseCallApiSchemaRoutes, BaseSchemaRouteKeyPrefixes, CallApiConfig, CallApiExtraOptions, CallApiExtraOptionsForHooks, CallApiParameters, CallApiPlugin, CallApiRequestOptions, CallApiRequestOptionsForHooks, CallApiResultLoose as CallApiResult, CallApiResultErrorVariant, CallApiResultSuccessOrErrorVariant, CallApiResultSuccessVariant, CallApiSchema, CallApiSchemaConfig, DedupeOptions, DefaultCallApiContext, ErrorContext, FetchImpl, FetchMiddlewareContext, GetExtendSchemaConfigContext, Hooks, HooksOrHooksArray, InferExtendSchemaContext, InferParamsFromRoute, InferSchemaInput, InferSchemaOutput, InstanceContext, Middlewares, PluginHooks, PluginMiddlewares, PluginSetupContext, PossibleHTTPError, PossibleJavaScriptError, PossibleJavaScriptOrValidationError, PossibleValidationError, Register, RequestContext, RequestStreamContext, ResponseContext, ResponseErrorContext, ResponseStreamContext, ResponseTypeType, ResultModeType, RetryOptions, SuccessContext, URLOptions, callApi, createFetchClient, createFetchClientWithContext };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as requestOptionDefaults, r as defineEnum, t as extraOptionDefaults } from "./defaults-B-dOt2Dd.js";
|
|
2
|
-
import {
|
|
2
|
+
import { C as isReadableStream, E as isValidJsonString, S as isQueryString, T as isString, _ as isBoolean, a as isValidationErrorInstance, b as isPlainObject, f as HTTPError, g as isArray, h as toQueryString, n as isHTTPErrorInstance, p as ValidationError, v as isFunction, w as isSerializableObject, x as isPromise, y as isObject } from "./external-DXaCWLPN.js";
|
|
3
3
|
import { n as fetchSpecificKeys, t as fallBackRouteSchemaKey } from "./validation-DbbofkNi.js";
|
|
4
4
|
|
|
5
5
|
//#region src/auth.ts
|
|
@@ -78,8 +78,8 @@ const handleSchemaValidation = async (fullSchema, schemaName, validationOptions)
|
|
|
78
78
|
inputValue,
|
|
79
79
|
response
|
|
80
80
|
});
|
|
81
|
-
const disableResultApplicationBooleanObject = isObject(schemaConfig?.
|
|
82
|
-
if (schemaConfig?.
|
|
81
|
+
const disableResultApplicationBooleanObject = isObject(schemaConfig?.disableRuntimeValidationTransform) ? schemaConfig.disableRuntimeValidationTransform : {};
|
|
82
|
+
if (schemaConfig?.disableRuntimeValidationTransform === true || disableResultApplicationBooleanObject[schemaName] === true) return inputValue;
|
|
83
83
|
return validResult;
|
|
84
84
|
};
|
|
85
85
|
const extraOptionsToBeValidated = [
|
|
@@ -225,7 +225,7 @@ const ampersand = "&";
|
|
|
225
225
|
const mergeUrlWithQuery = (url, query) => {
|
|
226
226
|
if (!query) return url;
|
|
227
227
|
const queryString = toQueryString(query);
|
|
228
|
-
if (queryString
|
|
228
|
+
if (queryString.length === 0) return url;
|
|
229
229
|
if (url.endsWith(questionMark)) return `${url}${queryString}`;
|
|
230
230
|
if (url.includes(questionMark)) return `${url}${ampersand}${queryString}`;
|
|
231
231
|
return `${url}${questionMark}${queryString}`;
|
|
@@ -257,12 +257,20 @@ const normalizeURL = (initURL) => {
|
|
|
257
257
|
if (!methodFromURL) return initURL;
|
|
258
258
|
return initURL.includes("http") ? initURL.replace(`@${methodFromURL}/`, "") : initURL.replace(`@${methodFromURL}/`, "/");
|
|
259
259
|
};
|
|
260
|
+
const getFullURL = (initURL, baseURL) => {
|
|
261
|
+
if (!baseURL || initURL.startsWith("http")) return initURL;
|
|
262
|
+
return initURL.length > 0 && !initURL.startsWith(slash) && !baseURL.endsWith(slash) ? `${baseURL}${slash}${initURL}` : `${baseURL}${initURL}`;
|
|
263
|
+
};
|
|
260
264
|
const getFullAndNormalizedURL = (options) => {
|
|
261
265
|
const { baseURL, initURL, params, query } = options;
|
|
262
266
|
const normalizedInitURL = normalizeURL(initURL);
|
|
263
|
-
const
|
|
267
|
+
const fullURL = getFullURL(mergeUrlWithQuery(mergeUrlWithParams(normalizedInitURL, params), query), baseURL);
|
|
268
|
+
if (!URL.canParse(fullURL)) {
|
|
269
|
+
const errorMessage = !baseURL ? `Invalid URL '${fullURL}'. Are you passing a relative url to CallApi but not setting the 'baseURL' option?` : `Invalid URL '${fullURL}'. Please validate that you are passing the correct url.`;
|
|
270
|
+
console.error(errorMessage);
|
|
271
|
+
}
|
|
264
272
|
return {
|
|
265
|
-
fullURL
|
|
273
|
+
fullURL,
|
|
266
274
|
normalizedInitURL
|
|
267
275
|
};
|
|
268
276
|
};
|
|
@@ -320,29 +328,36 @@ const getResolvedHeaders = (options) => {
|
|
|
320
328
|
const { baseHeaders, headers } = options;
|
|
321
329
|
return objectifyHeaders(isFunction(headers) ? headers({ baseHeaders: objectifyHeaders(baseHeaders) }) : headers ?? baseHeaders);
|
|
322
330
|
};
|
|
331
|
+
const detectContentTypeHeader = (body) => {
|
|
332
|
+
if (isQueryString(body)) return { "Content-Type": "application/x-www-form-urlencoded" };
|
|
333
|
+
if (isSerializableObject(body) || isValidJsonString(body)) return {
|
|
334
|
+
Accept: "application/json",
|
|
335
|
+
"Content-Type": "application/json"
|
|
336
|
+
};
|
|
337
|
+
return null;
|
|
338
|
+
};
|
|
323
339
|
const getHeaders = async (options) => {
|
|
324
340
|
const { auth, body, resolvedHeaders } = options;
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
headersObject["Content-Type"] = "application/x-www-form-urlencoded";
|
|
331
|
-
return headersObject;
|
|
341
|
+
const authHeaderObject = await getAuthHeader(auth);
|
|
342
|
+
const resolvedHeadersObject = objectifyHeaders(resolvedHeaders);
|
|
343
|
+
if (!(Object.hasOwn(resolvedHeadersObject, "Content-Type") || Object.hasOwn(resolvedHeadersObject, "content-type"))) {
|
|
344
|
+
const contentTypeHeader = detectContentTypeHeader(body);
|
|
345
|
+
contentTypeHeader && Object.assign(resolvedHeadersObject, contentTypeHeader);
|
|
332
346
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
return headersObject;
|
|
347
|
+
return {
|
|
348
|
+
...authHeaderObject,
|
|
349
|
+
...resolvedHeadersObject
|
|
350
|
+
};
|
|
338
351
|
};
|
|
339
352
|
const getMethod = (ctx) => {
|
|
340
353
|
const { initURL, method } = ctx;
|
|
341
354
|
return method?.toUpperCase() ?? extractMethodFromURL(initURL)?.toUpperCase() ?? requestOptionDefaults.method;
|
|
342
355
|
};
|
|
343
356
|
const getBody = (options) => {
|
|
344
|
-
const { body, bodySerializer } = options;
|
|
345
|
-
|
|
357
|
+
const { body, bodySerializer, resolvedHeaders } = options;
|
|
358
|
+
const existingContentType = new Headers(resolvedHeaders).get("content-type");
|
|
359
|
+
if (!existingContentType && isSerializableObject(body)) return (bodySerializer ?? extraOptionDefaults.bodySerializer)(body);
|
|
360
|
+
if (existingContentType === "application/x-www-form-urlencoded" && isSerializableObject(body)) return toQueryString(body);
|
|
346
361
|
return body;
|
|
347
362
|
};
|
|
348
363
|
const getInitFetchImpl = (customFetchImpl) => {
|
|
@@ -1049,7 +1064,8 @@ const createFetchClientWithContext = () => {
|
|
|
1049
1064
|
Object.assign(request, {
|
|
1050
1065
|
body: getBody({
|
|
1051
1066
|
body: requestOptionsValidationResult.body,
|
|
1052
|
-
bodySerializer: options.bodySerializer
|
|
1067
|
+
bodySerializer: options.bodySerializer,
|
|
1068
|
+
resolvedHeaders: requestOptionsValidationResult.headers
|
|
1053
1069
|
}),
|
|
1054
1070
|
headers: await getHeaders({
|
|
1055
1071
|
auth: options.auth,
|