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BAC1B,QAAQ,sBAAwB,sBAChC,QAAQ,SAAW,SACnB,QAAQ,eAAiB,eACzB,QAAQ,cAAgB,cACxB,QAAQ,kBAAoB,kBAC5B,QAAQ,WAAa,WACrB,QAAQ,aAAe,aACvB,QAAQ,WAAa,WACrB,QAAQ,qBAAuB,qBAC/B,QAAQ,WAAa,WACrB,QAAQ,mBAAqB,mBAC7B,QAAQ,iBAAmB,iBAC3B,QAAQ,wBAA0B,wBAClC,QAAQ,gBAAkB,gBAC1B,QAAQ,mBAAqB,mBAC7B,QAAQ,gBAAkB,gBAC1B,QAAQ,WAAa,WACrB,QAAQ,kBAAoB,kBAC5B,QAAQ,uBAAyB,uBACjC,QAAQ,kBAAoB,kBAC5B,QAAQ,yBAA2B,yBACnC,QAAQ,YAAc,YACtB,QAAQ,kBAAoB,kBAC5B,QAAQ,UAAY,UACpB,QAAQ,qBAAuB,qBAC/B,QAAQ,eAAiB,eACzB,QAAQ,iBAAmB,iBAC3B,QAAQ,iBAAmB,iBAC3B,QAAQ,SAAW","file":"/npm/@ts-rest/core@3.52.1/index.cjs.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/@ts-rest/core@3.52.1/index.cjs.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nvar zod = require('zod');\n\nconst isZodType = (obj) => {\n    return typeof (obj === null || obj === void 0 ? void 0 : obj.safeParse) === 'function';\n};\nconst isZodObject = (obj) => {\n    if (typeof (obj === null || obj === void 0 ? void 0 : obj.passthrough) === 'function') {\n        return true;\n    }\n    if (typeof (obj === null || obj === void 0 ? void 0 : obj.innerType) === 'function') {\n        return isZodObject(obj === null || obj === void 0 ? void 0 : obj.innerType());\n    }\n    return false;\n};\nconst isZodObjectStrict = (obj) => {\n    return typeof (obj === null || obj === void 0 ? void 0 : obj.passthrough) === 'function';\n};\nconst extractZodObjectShape = (obj) => {\n    if (!isZodObject(obj)) {\n        throw new Error('Unknown zod object type');\n    }\n    if ('innerType' in obj) {\n        return extractZodObjectShape(obj.innerType());\n    }\n    return obj.shape;\n};\nconst zodMerge = (objectA, objectB) => {\n    if (isZodObjectStrict(objectA)) {\n        if (isZodObjectStrict(objectB)) {\n            return objectA.merge(objectB);\n        }\n        return objectA;\n    }\n    if (isZodObjectStrict(objectB)) {\n        return objectB;\n    }\n    return Object.assign({}, objectA, objectB);\n};\nconst checkZodSchema = (data, schema, { passThroughExtraKeys = false } = {}) => {\n    if (isZodType(schema)) {\n        const result = schema.safeParse(data);\n        if (result.success) {\n            return {\n                success: true,\n                data: passThroughExtraKeys && typeof data === 'object'\n                    ? { ...data, ...result.data }\n                    : result.data,\n            };\n        }\n        return {\n            success: false,\n            error: result.error,\n        };\n    }\n    return {\n        success: true,\n        data: data,\n    };\n};\n// Convert a ZodError to a plain object because ZodError extends Error and causes problems with NestJS\nconst zodErrorResponse = (error) => {\n    return {\n        name: error.name,\n        issues: error.issues,\n    };\n};\nconst ZodErrorSchema = zod.z.object({\n    name: zod.z.literal('ZodError'),\n    issues: zod.z.array(zod.z\n        .object({\n        path: zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])),\n        message: zod.z.string().optional(),\n        code: zod.z.nativeEnum(zod.z.ZodIssueCode),\n    })\n        // ZodIssuse type are complex and potentially unstable. So we don’t deal with his specific fields other than the common.\n        .catchall(zod.z.any())),\n});\n\nconst ContractNoBody = Symbol('ContractNoBody');\n/**\n * Differentiate between a route and a router\n *\n * @param obj\n * @returns\n */\nconst isAppRoute = (obj) => {\n    return 'method' in obj && 'path' in obj;\n};\nconst isAppRouteQuery = (route) => {\n    return route.method === 'GET';\n};\nconst isAppRouteMutation = (route) => {\n    return !isAppRouteQuery(route);\n};\n/**\n *\n * @deprecated Please use {@link initContract} instead.\n */\nconst initTsRest = () => initContract();\nconst recursivelyApplyOptions = (router, options) => {\n    return Object.fromEntries(Object.entries(router).map(([key, value]) => {\n        var _a, _b, _c;\n        if (isAppRoute(value)) {\n            return [\n                key,\n                {\n                    ...value,\n                    path: (options === null || options === void 0 ? void 0 : options.pathPrefix)\n                        ? options.pathPrefix + value.path\n                        : value.path,\n                    headers: zodMerge(options === null || options === void 0 ? void 0 : options.baseHeaders, value.headers),\n                    strictStatusCodes: (_a = value.strictStatusCodes) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.strictStatusCodes,\n                    validateResponseOnClient: (_b = value.validateResponseOnClient) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.validateResponseOnClient,\n                    responses: {\n                        ...options === null || options === void 0 ? void 0 : options.commonResponses,\n                        ...value.responses,\n                    },\n                    metadata: (options === null || options === void 0 ? void 0 : options.metadata)\n                        ? {\n                            ...options === null || options === void 0 ? void 0 : options.metadata,\n                            ...((_c = value.metadata) !== null && _c !== void 0 ? _c : {}),\n                        }\n                        : value.metadata,\n                },\n            ];\n        }\n        else {\n            return [key, recursivelyApplyOptions(value, options)];\n        }\n    }));\n};\nconst ContractPlainTypeRuntimeSymbol = Symbol('ContractPlainType');\n/**\n * Instantiate a ts-rest client, primarily to access `router`, `response`, and `body`\n *\n * @returns {ContractInstance}\n */\nconst initContract = () => {\n    return {\n        // @ts-expect-error - this is a type error, but it's not clear how to fix it\n        router: (endpoints, options) => recursivelyApplyOptions(endpoints, options),\n        query: (args) => args,\n        mutation: (args) => args,\n        responses: (args) => args,\n        response: () => ContractPlainTypeRuntimeSymbol,\n        body: () => ContractPlainTypeRuntimeSymbol,\n        type: () => ContractPlainTypeRuntimeSymbol,\n        otherResponse: ({ contentType, body, }) => ({\n            contentType,\n            body,\n        }),\n        noBody: () => ContractNoBody,\n    };\n};\n\n/**\n * @param path - The URL e.g. /posts/:id\n * @param params - The params e.g. `{ id: string }`\n * @returns - The URL with the params e.g. /posts/123\n */\nconst insertParamsIntoPath = ({ path, params, }) => {\n    const pathParams = params;\n    return path.replace(/\\/?:([^/?]+)\\??/g, (matched, p) => pathParams[p]\n        ? `${matched.startsWith('/') ? '/' : ''}${pathParams[p]}`\n        : '');\n};\n\n/**\n *\n * @param query - Any JSON object\n * @param json - Use JSON.stringify to encode the query values\n * @returns - The query url segment, using explode array syntax, and deep object syntax\n */\nconst convertQueryParamsToUrlString = (query, json = false) => {\n    const queryString = json\n        ? encodeQueryParamsJson(query)\n        : encodeQueryParams(query);\n    return (queryString === null || queryString === void 0 ? void 0 : queryString.length) > 0 ? '?' + queryString : '';\n};\nconst encodeQueryParamsJson = (query) => {\n    if (!query) {\n        return '';\n    }\n    return Object.entries(query)\n        .filter(([, value]) => value !== undefined)\n        .map(([key, value]) => {\n        let encodedValue;\n        // if value is a string and is not a reserved JSON value or a number, pass it without encoding\n        // this makes strings look nicer in the URL (e.g. ?name=John instead of ?name=%22John%22)\n        // this is also how OpenAPI will pass strings even if they are marked as application/json types\n        if (typeof value === 'string' &&\n            !['true', 'false', 'null'].includes(value.trim()) &&\n            isNaN(Number(value))) {\n            encodedValue = value;\n        }\n        else {\n            encodedValue = JSON.stringify(value);\n        }\n        return `${encodeURIComponent(key)}=${encodeURIComponent(encodedValue)}`;\n    })\n        .join('&');\n};\nconst encodeQueryParams = (query) => {\n    if (!query) {\n        return '';\n    }\n    return (Object.keys(query)\n        // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n        // @ts-ignore\n        .flatMap((key) => tokeniseValue(key, query[key]))\n        .map(([key, value]) => {\n        return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;\n    })\n        .join('&'));\n};\n/**\n * A recursive function to convert an object/string/number/Date/whatever into an array of key=value pairs\n *\n * The output of this should be flatMap-able to a string of key=value pairs which can be\n * joined with & to form a query string\n *\n * This should be fully compatible with the \"qs\" library, but without the need to add a dependency\n */\nconst tokeniseValue = (key, value) => {\n    if (Array.isArray(value)) {\n        return value.flatMap((v, idx) => tokeniseValue(`${key}[${idx}]`, v));\n    }\n    if (value instanceof Date) {\n        return [[`${key}`, value.toISOString()]];\n    }\n    if (value === null) {\n        return [[`${key}`, '']];\n    }\n    if (value === undefined) {\n        return [];\n    }\n    if (typeof value === 'object') {\n        return Object.keys(value).flatMap((k) => \n        // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n        // @ts-ignore\n        tokeniseValue(`${key}[${k}]`, value[k]));\n    }\n    return [[`${key}`, `${value}`]];\n};\n/**\n *\n * @param query - A server-side query object where values have been encoded as JSON strings\n * @returns - The same object with the JSON strings decoded. Objects that were encoded using toJSON such as Dates will remain as strings\n */\nconst parseJsonQueryObject = (query) => {\n    return Object.fromEntries(Object.entries(query).map(([key, value]) => {\n        let parsedValue;\n        // if json parse fails, treat the value as a string\n        // this allows us to pass strings without having to surround them with quotes\n        try {\n            parsedValue = JSON.parse(value);\n        }\n        catch {\n            parsedValue = value;\n        }\n        return [key, parsedValue];\n    }));\n};\n\nclass UnknownStatusError extends Error {\n    constructor(response, knownResponseStatuses) {\n        const expectedStatuses = knownResponseStatuses.join(',');\n        super(`Server returned unexpected response. Expected one of: ${expectedStatuses} got: ${response.status}`);\n        this.response = response;\n    }\n}\n\n/**\n * @deprecated Only safe to use on the client-side. Use `ServerInferResponses`/`ClientInferResponses` instead.\n */\nfunction getRouteResponses(router) {\n    return {};\n}\n/**\n * Default fetch api implementation:\n *\n * Can be used as a reference for implementing your own fetcher,\n * or used in the \"api\" field of ClientArgs to allow you to hook\n * into the request to run custom logic\n */\nconst tsRestFetchApi = async ({ route, path, method, headers, body, validateResponse, fetchOptions, }) => {\n    const result = await fetch(path, {\n        ...fetchOptions,\n        method,\n        headers,\n        body,\n    });\n    const contentType = result.headers.get('content-type');\n    if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes('application/')) && (contentType === null || contentType === void 0 ? void 0 : contentType.includes('json'))) {\n        const response = {\n            status: result.status,\n            body: await result.json(),\n            headers: result.headers,\n        };\n        const responseSchema = route.responses[response.status];\n        if ((validateResponse !== null && validateResponse !== void 0 ? validateResponse : route.validateResponseOnClient) &&\n            isZodType(responseSchema)) {\n            return {\n                ...response,\n                body: responseSchema.parse(response.body),\n            };\n        }\n        return response;\n    }\n    if (contentType === null || contentType === void 0 ? void 0 : contentType.includes('text/')) {\n        return {\n            status: result.status,\n            body: await result.text(),\n            headers: result.headers,\n        };\n    }\n    return {\n        status: result.status,\n        body: await result.blob(),\n        headers: result.headers,\n    };\n};\nconst createFormData = (body) => {\n    const formData = new FormData();\n    const appendToFormData = (key, value) => {\n        if (value instanceof File) {\n            formData.append(key, value);\n        }\n        else {\n            formData.append(key, JSON.stringify(value));\n        }\n    };\n    Object.entries(body).forEach(([key, value]) => {\n        if (Array.isArray(value)) {\n            for (const item of value) {\n                appendToFormData(key, item);\n            }\n        }\n        else {\n            appendToFormData(key, value);\n        }\n    });\n    return formData;\n};\nconst normalizeHeaders = (headers) => {\n    return Object.fromEntries(Object.entries(headers).map(([k, v]) => [k.toLowerCase(), v]));\n};\nconst fetchApi = (options) => {\n    const { path, clientArgs, route, body, query, extraInputArgs, headers, fetchOptions, } = options;\n    const apiFetcher = clientArgs.api || tsRestFetchApi;\n    const baseHeaders = clientArgs.baseHeaders &&\n        Object.fromEntries(Object.entries(clientArgs.baseHeaders).map(([name, valueOrFunction]) => {\n            if (typeof valueOrFunction === 'function') {\n                return [name, valueOrFunction(options)];\n            }\n            else {\n                return [name, valueOrFunction];\n            }\n        }));\n    const combinedHeaders = {\n        ...(baseHeaders && normalizeHeaders(baseHeaders)),\n        ...normalizeHeaders(headers),\n    };\n    // Remove any headers that are set to undefined\n    Object.keys(combinedHeaders).forEach((key) => {\n        if (combinedHeaders[key] === undefined) {\n            delete combinedHeaders[key];\n        }\n    });\n    let fetcherArgs = {\n        route,\n        path,\n        method: route.method,\n        headers: combinedHeaders,\n        body: undefined,\n        rawBody: body,\n        rawQuery: query,\n        contentType: undefined,\n        validateResponse: clientArgs.validateResponse,\n        fetchOptions: {\n            ...(clientArgs.credentials && { credentials: clientArgs.credentials }),\n            ...fetchOptions,\n        },\n        ...((fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.signal) && { signal: fetchOptions.signal }),\n        ...((fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.cache) && { cache: fetchOptions.cache }),\n        ...(fetchOptions &&\n            'next' in fetchOptions &&\n            !!(fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.next) && { next: fetchOptions.next }),\n    };\n    if (route.method !== 'GET') {\n        if ('contentType' in route && route.contentType === 'multipart/form-data') {\n            fetcherArgs = {\n                ...fetcherArgs,\n                contentType: 'multipart/form-data',\n                body: body instanceof FormData ? body : createFormData(body),\n            };\n        }\n        else if ('contentType' in route &&\n            route.contentType === 'application/x-www-form-urlencoded') {\n            fetcherArgs = {\n                ...fetcherArgs,\n                contentType: 'application/x-www-form-urlencoded',\n                headers: {\n                    'content-type': 'application/x-www-form-urlencoded',\n                    ...fetcherArgs.headers,\n                },\n                body: typeof body === 'string'\n                    ? body\n                    : new URLSearchParams(body),\n            };\n        }\n        else if (body !== null && body !== undefined) {\n            fetcherArgs = {\n                ...fetcherArgs,\n                contentType: 'application/json',\n                headers: {\n                    'content-type': 'application/json',\n                    ...fetcherArgs.headers,\n                },\n                body: JSON.stringify(body),\n            };\n        }\n    }\n    return apiFetcher({\n        ...fetcherArgs,\n        ...extraInputArgs,\n    });\n};\nconst evaluateFetchApiArgs = (route, clientArgs, inputArgs) => {\n    const { query, params, body, headers, extraHeaders, overrideClientOptions, fetchOptions, \n    // TODO: remove in 4.0\n    cache, \n    // TODO: remove in 4.0\n    next, \n    // extra input args\n    ...extraInputArgs } = inputArgs || {};\n    const overriddenClientArgs = {\n        ...clientArgs,\n        ...overrideClientOptions,\n    };\n    const completeUrl = getCompleteUrl(query, overriddenClientArgs.baseUrl, params, route, !!overriddenClientArgs.jsonQuery);\n    return {\n        path: completeUrl,\n        clientArgs: overriddenClientArgs,\n        route,\n        body,\n        query,\n        extraInputArgs,\n        fetchOptions: {\n            ...(cache && { cache }),\n            ...(next && { next }),\n            ...fetchOptions,\n        },\n        headers: {\n            ...extraHeaders,\n            ...headers,\n        },\n    };\n};\n/**\n * @hidden\n */\nconst getCompleteUrl = (query, baseUrl, params, route, jsonQuery) => {\n    const path = insertParamsIntoPath({\n        path: route.path,\n        params: params,\n    });\n    const queryComponent = convertQueryParamsToUrlString(query, jsonQuery);\n    return `${baseUrl}${path}${queryComponent}`;\n};\nconst getRouteQuery = (route, clientArgs) => {\n    const knownResponseStatuses = Object.keys(route.responses);\n    return async (inputArgs) => {\n        const fetchApiArgs = evaluateFetchApiArgs(route, clientArgs, inputArgs);\n        const response = await fetchApi(fetchApiArgs);\n        // TODO: in next major version, throw by default if `strictStatusCode` is enabled\n        if (!clientArgs.throwOnUnknownStatus) {\n            return response;\n        }\n        if (knownResponseStatuses.includes(response.status.toString())) {\n            return response;\n        }\n        throw new UnknownStatusError(response, knownResponseStatuses);\n    };\n};\nconst initClient = (router, args) => {\n    return Object.fromEntries(Object.entries(router).map(([key, subRouter]) => {\n        if (isAppRoute(subRouter)) {\n            return [key, getRouteQuery(subRouter, args)];\n        }\n        else {\n            return [key, initClient(subRouter, args)];\n        }\n    }));\n};\n\nclass ResponseValidationError extends Error {\n    constructor(appRoute, cause) {\n        super(`[ts-rest] Response validation failed for ${appRoute.method} ${appRoute.path}: ${cause.message}`);\n        this.appRoute = appRoute;\n        this.cause = cause;\n    }\n}\n\nconst isAppRouteResponse = (value) => {\n    return (value != null &&\n        typeof value === 'object' &&\n        'status' in value &&\n        typeof value.status === 'number');\n};\nconst isAppRouteOtherResponse = (response) => {\n    return (response != null &&\n        typeof response === 'object' &&\n        'contentType' in response);\n};\nconst isAppRouteNoBody = (response) => {\n    return response === ContractNoBody;\n};\nconst validateResponse = ({ appRoute, response, }) => {\n    if (isAppRouteResponse(response)) {\n        const responseType = appRoute.responses[response.status];\n        const responseSchema = isAppRouteOtherResponse(responseType)\n            ? responseType.body\n            : responseType;\n        const responseValidation = checkZodSchema(response.body, responseSchema);\n        if (!responseValidation.success) {\n            throw new ResponseValidationError(appRoute, responseValidation.error);\n        }\n        return {\n            status: response.status,\n            body: responseValidation.data,\n        };\n    }\n    return response;\n};\n\nclass TsRestResponseError extends Error {\n    constructor(route, response) {\n        super();\n        this.statusCode = response.status;\n        this.body = response.body;\n        this.name = this.constructor.name;\n        if (typeof response.body === 'string') {\n            this.message = response.body;\n        }\n        else if (typeof response.body === 'object' &&\n            response.body !== null &&\n            'message' in response.body &&\n            typeof response.body.message === 'string') {\n            this.message = response.body['message'];\n        }\n        else {\n            this.message = 'Error';\n        }\n    }\n}\n\nconst isResponse = (response, contractEndpoint) => {\n    return (typeof response === 'object' &&\n        response !== null &&\n        'status' in response &&\n        'body' in response &&\n        typeof response.status === 'number' &&\n        response.status >= 200 &&\n        response.status < 600 &&\n        ((contractEndpoint === null || contractEndpoint === void 0 ? void 0 : contractEndpoint.strictStatusCodes)\n            ? Object.keys(contractEndpoint.responses).includes(response.status.toString())\n            : true));\n};\nconst isSuccessResponse = (response, contractEndpoint) => {\n    return (isResponse(response, contractEndpoint) &&\n        response.status >= 200 &&\n        response.status < 300);\n};\nconst isErrorResponse = (response, contractEndpoint) => {\n    return (isResponse(response, contractEndpoint) &&\n        !isSuccessResponse(response, contractEndpoint));\n};\nconst isUnknownResponse = (response, contractEndpoint) => {\n    return (isResponse(response) &&\n        !Object.keys(contractEndpoint.responses).includes(response.status.toString()));\n};\nconst isUnknownSuccessResponse = (response, contractEndpoint) => {\n    return (isSuccessResponse(response) && isUnknownResponse(response, contractEndpoint));\n};\nconst isUnknownErrorResponse = (response, contractEndpoint) => {\n    return (isErrorResponse(response) && isUnknownResponse(response, contractEndpoint));\n};\nconst exhaustiveGuard = (response) => {\n    throw new Error(`Unreachable code: Response status is ${response.status}`);\n};\n\nexports.ContractNoBody = ContractNoBody;\nexports.ContractPlainTypeRuntimeSymbol = ContractPlainTypeRuntimeSymbol;\nexports.ResponseValidationError = ResponseValidationError;\nexports.TsRestResponseError = TsRestResponseError;\nexports.UnknownStatusError = UnknownStatusError;\nexports.ZodErrorSchema = ZodErrorSchema;\nexports.checkZodSchema = checkZodSchema;\nexports.convertQueryParamsToUrlString = convertQueryParamsToUrlString;\nexports.encodeQueryParams = encodeQueryParams;\nexports.encodeQueryParamsJson = encodeQueryParamsJson;\nexports.evaluateFetchApiArgs = evaluateFetchApiArgs;\nexports.exhaustiveGuard = exhaustiveGuard;\nexports.extractZodObjectShape = extractZodObjectShape;\nexports.fetchApi = fetchApi;\nexports.getCompleteUrl = getCompleteUrl;\nexports.getRouteQuery = getRouteQuery;\nexports.getRouteResponses = getRouteResponses;\nexports.initClient = initClient;\nexports.initContract = initContract;\nexports.initTsRest = initTsRest;\nexports.insertParamsIntoPath = insertParamsIntoPath;\nexports.isAppRoute = isAppRoute;\nexports.isAppRouteMutation = isAppRouteMutation;\nexports.isAppRouteNoBody = isAppRouteNoBody;\nexports.isAppRouteOtherResponse = isAppRouteOtherResponse;\nexports.isAppRouteQuery = isAppRouteQuery;\nexports.isAppRouteResponse = isAppRouteResponse;\nexports.isErrorResponse = isErrorResponse;\nexports.isResponse = isResponse;\nexports.isSuccessResponse = isSuccessResponse;\nexports.isUnknownErrorResponse = isUnknownErrorResponse;\nexports.isUnknownResponse = isUnknownResponse;\nexports.isUnknownSuccessResponse = isUnknownSuccessResponse;\nexports.isZodObject = isZodObject;\nexports.isZodObjectStrict = isZodObjectStrict;\nexports.isZodType = isZodType;\nexports.parseJsonQueryObject = parseJsonQueryObject;\nexports.tsRestFetchApi = tsRestFetchApi;\nexports.validateResponse = validateResponse;\nexports.zodErrorResponse = zodErrorResponse;\nexports.zodMerge = zodMerge;\n"]}