@mercurjs/client 2.0.0-canary.9 → 2.0.0-canary.90

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
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
@@ -1,5 +1,57 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
52
+
1
53
  // src/index.ts
2
- import { stringify } from "qs";
54
+ import qs from "qs";
3
55
 
4
56
  // src/create-proxy.ts
5
57
  function createRecursiveProxy(callback, path = []) {
@@ -25,8 +77,6 @@ var kebabCase = (string) => string.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/
25
77
 
26
78
  // src/index.ts
27
79
  var ClientError = class extends Error {
28
- status;
29
- statusText;
30
80
  constructor(message, statusText, status) {
31
81
  super(message);
32
82
  this.statusText = statusText;
@@ -36,13 +86,14 @@ var ClientError = class extends Error {
36
86
  function createClient(options) {
37
87
  const { baseUrl, fetchOptions: defaultFetchOptions } = options;
38
88
  return createRecursiveProxy((path, args) => {
89
+ var _a;
39
90
  const action = path.pop();
40
- const input = args[0] ?? {};
91
+ const input = (_a = args[0]) != null ? _a : {};
41
92
  const method = action === "query" ? "GET" : action === "mutate" ? "POST" : action === "delete" ? "DELETE" : null;
42
93
  if (!method) {
43
94
  throw new Error(`Action '${action}' is not a valid action.`);
44
95
  }
45
- const { fetchOptions: inputFetchOptions, ...rest } = input;
96
+ const _b = input, { fetchOptions: inputFetchOptions } = _b, rest = __objRest(_b, ["fetchOptions"]);
46
97
  const urlParts = path.map((segment) => {
47
98
  if (segment.startsWith("$")) {
48
99
  const value = rest[segment];
@@ -55,36 +106,39 @@ function createClient(options) {
55
106
  const base = new URL(baseUrl);
56
107
  const fullPath = `${base.pathname.replace(/\/$/, "")}/${urlPath.replace(/^\//, "")}`;
57
108
  const url = new URL(fullPath, base.origin);
109
+ const isFormData = (inputFetchOptions == null ? void 0 : inputFetchOptions.body) instanceof FormData;
58
110
  let body;
59
- if (method === "GET" && Object.keys(rest).length > 0) {
60
- 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 });
61
115
  } else if (method !== "GET" && Object.keys(rest).length > 0) {
62
116
  body = JSON.stringify(rest);
63
117
  }
64
- const headers = new Headers({
65
- "Content-Type": "application/json",
66
- Accept: "application/json",
67
- ...defaultFetchOptions?.headers,
68
- ...inputFetchOptions?.headers
69
- });
70
- return fetch(url, {
71
- ...defaultFetchOptions,
72
- ...inputFetchOptions,
118
+ const defaultHeaders = {
119
+ Accept: "application/json"
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));
125
+ return fetch(url, __spreadProps(__spreadValues(__spreadValues({}, defaultFetchOptions), inputFetchOptions), {
73
126
  method,
74
127
  body,
75
128
  headers
76
- }).then(async (response) => {
129
+ })).then((response) => __async(null, null, function* () {
130
+ var _a2, _b2;
77
131
  if (response.status >= 300) {
78
- const jsonError = await response.json().catch(() => ({}));
132
+ const jsonError = yield response.json().catch(() => ({}));
79
133
  throw new ClientError(
80
- jsonError.message ?? response.statusText,
134
+ (_a2 = jsonError.message) != null ? _a2 : response.statusText,
81
135
  response.statusText,
82
136
  response.status
83
137
  );
84
138
  }
85
- const isJsonRequest = headers.get("accept")?.includes("application/json");
86
- return isJsonRequest ? await response.json() : response;
87
- });
139
+ const isJsonRequest = (_b2 = headers.get("accept")) == null ? void 0 : _b2.includes("application/json");
140
+ return isJsonRequest ? yield response.json() : response;
141
+ }));
88
142
  });
89
143
  }
90
144
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mercurjs/client",
3
- "version": "2.0.0-canary.9",
3
+ "version": "2.0.0-canary.90",
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"