@zayne-labs/callapi 1.11.35 → 1.11.37
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.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-DGGInQcS.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
|
@@ -167,7 +167,8 @@ const getResolvedSchema = (context) => {
|
|
|
167
167
|
currentRouteSchema,
|
|
168
168
|
resolvedSchema: isFunction(extraOptions.schema) ? extraOptions.schema({
|
|
169
169
|
baseSchemaRoutes: baseExtraOptions.schema?.routes ?? {},
|
|
170
|
-
currentRouteSchema: resolvedRouteSchema ?? {}
|
|
170
|
+
currentRouteSchema: resolvedRouteSchema ?? {},
|
|
171
|
+
currentRouteSchemaKey
|
|
171
172
|
}) : extraOptions.schema ?? resolvedRouteSchema
|
|
172
173
|
};
|
|
173
174
|
};
|
|
@@ -175,6 +176,7 @@ const getResolvedSchemaConfig = (context) => {
|
|
|
175
176
|
const { baseExtraOptions, extraOptions } = context;
|
|
176
177
|
return isFunction(extraOptions.schemaConfig) ? extraOptions.schemaConfig({ baseSchemaConfig: baseExtraOptions.schema?.config ?? {} }) : extraOptions.schemaConfig ?? baseExtraOptions.schema?.config;
|
|
177
178
|
};
|
|
179
|
+
const removeLeadingSlash = (value) => value.startsWith("/") ? value.slice(1) : value;
|
|
178
180
|
const getCurrentRouteSchemaKeyAndMainInitURL = (context) => {
|
|
179
181
|
const { baseExtraOptions, extraOptions, initURL } = context;
|
|
180
182
|
const schemaConfig = getResolvedSchemaConfig({
|
|
@@ -183,11 +185,19 @@ const getCurrentRouteSchemaKeyAndMainInitURL = (context) => {
|
|
|
183
185
|
});
|
|
184
186
|
let currentRouteSchemaKey = initURL;
|
|
185
187
|
let mainInitURL = initURL;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
const methodFromURL = extractMethodFromURL(initURL);
|
|
189
|
+
const pathWithoutMethod = normalizeURL(initURL, { retainLeadingSlashForRelativeURLs: false });
|
|
190
|
+
const prefixWithoutLeadingSlash = schemaConfig?.prefix && removeLeadingSlash(schemaConfig.prefix);
|
|
191
|
+
if (schemaConfig?.prefix && prefixWithoutLeadingSlash && pathWithoutMethod.startsWith(prefixWithoutLeadingSlash)) {
|
|
192
|
+
const restOfPathWithoutPrefix = pathWithoutMethod.slice(prefixWithoutLeadingSlash.length);
|
|
193
|
+
currentRouteSchemaKey = methodFromURL ? `${atSymbol}${methodFromURL}/${removeLeadingSlash(restOfPathWithoutPrefix)}` : restOfPathWithoutPrefix;
|
|
194
|
+
const pathWithReplacedPrefix = pathWithoutMethod.replace(prefixWithoutLeadingSlash, schemaConfig.baseURL ?? "");
|
|
195
|
+
mainInitURL = methodFromURL ? `${atSymbol}${methodFromURL}/${removeLeadingSlash(pathWithReplacedPrefix)}` : pathWithReplacedPrefix;
|
|
196
|
+
}
|
|
197
|
+
if (schemaConfig?.baseURL && pathWithoutMethod.startsWith(schemaConfig.baseURL)) {
|
|
198
|
+
const restOfPathWithoutBaseURL = pathWithoutMethod.slice(schemaConfig.baseURL.length);
|
|
199
|
+
currentRouteSchemaKey = methodFromURL ? `${atSymbol}${methodFromURL}/${removeLeadingSlash(restOfPathWithoutBaseURL)}` : restOfPathWithoutBaseURL;
|
|
189
200
|
}
|
|
190
|
-
if (schemaConfig?.baseURL && currentRouteSchemaKey.startsWith(schemaConfig.baseURL)) currentRouteSchemaKey = currentRouteSchemaKey.replace(schemaConfig.baseURL, "");
|
|
191
201
|
return {
|
|
192
202
|
currentRouteSchemaKey,
|
|
193
203
|
mainInitURL
|
|
@@ -248,14 +258,16 @@ const mergeUrlWithQuery = (url, query) => {
|
|
|
248
258
|
*/
|
|
249
259
|
const extractMethodFromURL = (initURL) => {
|
|
250
260
|
if (!initURL?.startsWith("@")) return;
|
|
251
|
-
const
|
|
252
|
-
if (!
|
|
253
|
-
return
|
|
261
|
+
const methodFromURL = routeKeyMethods.find((method) => initURL.startsWith(`${atSymbol}${method}${slash}`));
|
|
262
|
+
if (!methodFromURL) return;
|
|
263
|
+
return methodFromURL;
|
|
254
264
|
};
|
|
255
|
-
const
|
|
265
|
+
const atSymbol = "@";
|
|
266
|
+
const normalizeURL = (initURL, options = {}) => {
|
|
267
|
+
const { retainLeadingSlashForRelativeURLs = true } = options;
|
|
256
268
|
const methodFromURL = extractMethodFromURL(initURL);
|
|
257
269
|
if (!methodFromURL) return initURL;
|
|
258
|
-
return initURL.includes("http") ? initURL.replace(
|
|
270
|
+
return retainLeadingSlashForRelativeURLs && !initURL.includes("http") ? initURL.replace(`${atSymbol}${methodFromURL}`, "") : initURL.replace(`${atSymbol}${methodFromURL}${slash}`, "");
|
|
259
271
|
};
|
|
260
272
|
const getFullURL = (initURL, baseURL) => {
|
|
261
273
|
if (!baseURL || initURL.startsWith("http")) return initURL;
|
|
@@ -265,7 +277,10 @@ const getFullAndNormalizedURL = (options) => {
|
|
|
265
277
|
const { baseURL, initURL, params, query } = options;
|
|
266
278
|
const normalizedInitURL = normalizeURL(initURL);
|
|
267
279
|
const fullURL = getFullURL(mergeUrlWithQuery(mergeUrlWithParams(normalizedInitURL, params), query), baseURL);
|
|
268
|
-
if (!URL.canParse(fullURL))
|
|
280
|
+
if (!URL.canParse(fullURL)) {
|
|
281
|
+
const errorMessage = !baseURL ? `Invalid URL '${initURL}'. Are you passing a relative url to CallApi without setting the 'baseURL' option?` : `Invalid URL '${fullURL}'. Please validate that you are passing the correct url.`;
|
|
282
|
+
console.error(errorMessage);
|
|
283
|
+
}
|
|
269
284
|
return {
|
|
270
285
|
fullURL,
|
|
271
286
|
normalizedInitURL
|