@mercurjs/client 2.0.0-canary.8 → 2.0.0-canary.80

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.mts CHANGED
@@ -1,9 +1,5 @@
1
- import { MedusaResponse } from '@medusajs/framework/http';
1
+ import { MedusaResponse } from '@medusajs/framework';
2
2
 
3
- type DecrementDepth = [never, 0, 1, 2, 3, 4, 5, 6];
4
- type PrettifyDeep<T, Depth extends number = 4> = Depth extends never ? T : T extends (...args: any[]) => any ? T : T extends Array<infer U> ? Array<PrettifyDeep<U, DecrementDepth[Depth]>> : T extends Date ? T : T extends object ? {
5
- [K in keyof T]: PrettifyDeep<T[K], DecrementDepth[Depth]>;
6
- } & {} : T;
7
3
  type TypeError<TMessage extends string> = TMessage;
8
4
  type InferInput<TRequest> = TRequest extends {
9
5
  validatedBody: infer Input;
@@ -21,7 +17,7 @@ type AddParamsToFn<Fn, TParams> = keyof TParams extends never ? Fn : Fn extends
21
17
  }) => TOutput : Fn extends (input: infer TInput) => infer TOutput ? (input: (TInput extends Record<string, any> ? Omit<TInput, 'fetchOptions'> : {}) & TParams & {
22
18
  fetchOptions?: RequestInit;
23
19
  }) => TOutput : Fn;
24
- type InferFetchFn<TRequest, TResponse, TInput = PrettifyDeep<InferInput<TRequest>>, TOutput = PrettifyDeep<InferOutput<TResponse>>> = [TInput] extends [Record<string, any>] ? (input: TInput & {
20
+ type InferFetchFn<TRequest, TResponse, TInput = InferInput<TRequest>, TOutput = InferOutput<TResponse>> = [TInput] extends [Record<string, any>] ? (input: TInput & {
25
21
  fetchOptions?: RequestInit;
26
22
  }) => Promise<TOutput> : (input?: {
27
23
  fetchOptions?: RequestInit;
@@ -47,8 +43,8 @@ type ProcessRoutes<TRoutes, TParams = {}> = InferEndpointMethods<TRoutes, TParam
47
43
  type InferClient<TRoutes> = TRoutes extends Record<string, any> ? ProcessRoutes<TRoutes> : TypeError<`Looks like you forgot to pass the \`Routes\` generic type to the \`createClient\` function.`>;
48
44
 
49
45
  type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
50
- type InferClientInput<T> = T extends (input: infer I) => any ? PrettifyDeep<DistributiveOmit<I, 'fetchOptions'>> : T extends (input?: infer I) => any ? PrettifyDeep<DistributiveOmit<NonNullable<I>, 'fetchOptions'>> : never;
51
- type InferClientOutput<T> = T extends (...args: any[]) => Promise<infer O> ? PrettifyDeep<O> : never;
46
+ type InferClientInput<T> = T extends (input: infer I) => any ? DistributiveOmit<I, 'fetchOptions'> : T extends (input?: infer I) => any ? DistributiveOmit<NonNullable<I>, 'fetchOptions'> : never;
47
+ type InferClientOutput<T> = T extends (...args: any[]) => Promise<infer O> ? O : never;
52
48
  declare class ClientError extends Error {
53
49
  status: number | undefined;
54
50
  statusText: string | undefined;
package/dist/index.mjs CHANGED
@@ -51,7 +51,7 @@ var __async = (__this, __arguments, generator) => {
51
51
  };
52
52
 
53
53
  // src/index.ts
54
- import { stringify } from "qs";
54
+ import qs from "qs";
55
55
 
56
56
  // src/create-proxy.ts
57
57
  function createRecursiveProxy(callback, path = []) {
@@ -106,16 +106,22 @@ function createClient(options) {
106
106
  const base = new URL(baseUrl);
107
107
  const fullPath = `${base.pathname.replace(/\/$/, "")}/${urlPath.replace(/^\//, "")}`;
108
108
  const url = new URL(fullPath, base.origin);
109
+ const isFormData = (inputFetchOptions == null ? void 0 : inputFetchOptions.body) instanceof FormData;
109
110
  let body;
110
- if (method === "GET" && Object.keys(rest).length > 0) {
111
- url.search = stringify(rest, { skipNulls: true });
111
+ if (isFormData) {
112
+ body = inputFetchOptions.body;
113
+ } else if (method === "GET" && Object.keys(rest).length > 0) {
114
+ url.search = qs.stringify(rest, { skipNulls: true });
112
115
  } else if (method !== "GET" && Object.keys(rest).length > 0) {
113
116
  body = JSON.stringify(rest);
114
117
  }
115
- const headers = new Headers(__spreadValues(__spreadValues({
116
- "Content-Type": "application/json",
118
+ const defaultHeaders = {
117
119
  Accept: "application/json"
118
- }, defaultFetchOptions == null ? void 0 : defaultFetchOptions.headers), inputFetchOptions == null ? void 0 : inputFetchOptions.headers));
120
+ };
121
+ if (!isFormData) {
122
+ defaultHeaders["Content-Type"] = "application/json";
123
+ }
124
+ const headers = new Headers(__spreadValues(__spreadValues(__spreadValues({}, defaultHeaders), defaultFetchOptions == null ? void 0 : defaultFetchOptions.headers), inputFetchOptions == null ? void 0 : inputFetchOptions.headers));
119
125
  return fetch(url, __spreadProps(__spreadValues(__spreadValues({}, defaultFetchOptions), inputFetchOptions), {
120
126
  method,
121
127
  body,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercurjs/client",
3
- "version": "2.0.0-canary.8",
3
+ "version": "2.0.0-canary.80",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mercurjs/mercur",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@tanstack/react-query": "^5.64.2",
31
- "qs": "^6.15.0"
31
+ "qs": "^6.12.1"
32
32
  },
33
33
  "devDependencies": {
34
- "@medusajs/framework": "^2.13.0",
34
+ "@medusajs/framework": "^2.13.3",
35
35
  "@types/qs": "^6.9.18",
36
36
  "tsup": "^8.5.0",
37
37
  "typescript": "5.9.3"