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

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,4 +1,4 @@
1
- import { MedusaResponse } from '@medusajs/framework/http';
1
+ import { MedusaResponse } from '@medusajs/framework';
2
2
 
3
3
  type DecrementDepth = [never, 0, 1, 2, 3, 4, 5, 6];
4
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 ? {
package/dist/index.mjs CHANGED
@@ -1,55 +1,3 @@
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
-
53
1
  // src/index.ts
54
2
  import { stringify } from "qs";
55
3
 
@@ -77,6 +25,8 @@ var kebabCase = (string) => string.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/
77
25
 
78
26
  // src/index.ts
79
27
  var ClientError = class extends Error {
28
+ status;
29
+ statusText;
80
30
  constructor(message, statusText, status) {
81
31
  super(message);
82
32
  this.statusText = statusText;
@@ -86,14 +36,13 @@ var ClientError = class extends Error {
86
36
  function createClient(options) {
87
37
  const { baseUrl, fetchOptions: defaultFetchOptions } = options;
88
38
  return createRecursiveProxy((path, args) => {
89
- var _a;
90
39
  const action = path.pop();
91
- const input = (_a = args[0]) != null ? _a : {};
40
+ const input = args[0] ?? {};
92
41
  const method = action === "query" ? "GET" : action === "mutate" ? "POST" : action === "delete" ? "DELETE" : null;
93
42
  if (!method) {
94
43
  throw new Error(`Action '${action}' is not a valid action.`);
95
44
  }
96
- const _b = input, { fetchOptions: inputFetchOptions } = _b, rest = __objRest(_b, ["fetchOptions"]);
45
+ const { fetchOptions: inputFetchOptions, ...rest } = input;
97
46
  const urlParts = path.map((segment) => {
98
47
  if (segment.startsWith("$")) {
99
48
  const value = rest[segment];
@@ -112,27 +61,30 @@ function createClient(options) {
112
61
  } else if (method !== "GET" && Object.keys(rest).length > 0) {
113
62
  body = JSON.stringify(rest);
114
63
  }
115
- const headers = new Headers(__spreadValues(__spreadValues({
64
+ const headers = new Headers({
116
65
  "Content-Type": "application/json",
117
- Accept: "application/json"
118
- }, defaultFetchOptions == null ? void 0 : defaultFetchOptions.headers), inputFetchOptions == null ? void 0 : inputFetchOptions.headers));
119
- return fetch(url, __spreadProps(__spreadValues(__spreadValues({}, defaultFetchOptions), inputFetchOptions), {
66
+ Accept: "application/json",
67
+ ...defaultFetchOptions?.headers,
68
+ ...inputFetchOptions?.headers
69
+ });
70
+ return fetch(url, {
71
+ ...defaultFetchOptions,
72
+ ...inputFetchOptions,
120
73
  method,
121
74
  body,
122
75
  headers
123
- })).then((response) => __async(null, null, function* () {
124
- var _a2, _b2;
76
+ }).then(async (response) => {
125
77
  if (response.status >= 300) {
126
- const jsonError = yield response.json().catch(() => ({}));
78
+ const jsonError = await response.json().catch(() => ({}));
127
79
  throw new ClientError(
128
- (_a2 = jsonError.message) != null ? _a2 : response.statusText,
80
+ jsonError.message ?? response.statusText,
129
81
  response.statusText,
130
82
  response.status
131
83
  );
132
84
  }
133
- const isJsonRequest = (_b2 = headers.get("accept")) == null ? void 0 : _b2.includes("application/json");
134
- return isJsonRequest ? yield response.json() : response;
135
- }));
85
+ const isJsonRequest = headers.get("accept")?.includes("application/json");
86
+ return isJsonRequest ? await response.json() : response;
87
+ });
136
88
  });
137
89
  }
138
90
  export {
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.9",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/mercurjs/mercur",