@teamnovu/kit-shopware-api-client 0.0.15 → 0.2.0

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.mjs CHANGED
@@ -1,277 +1,1146 @@
1
- var y = Object.defineProperty;
2
- var I = (o, s, e) => s in o ? y(o, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[s] = e;
3
- var c = (o, s) => y(o, "name", { value: s, configurable: !0 });
4
- var u = (o, s, e) => I(o, typeof s != "symbol" ? s + "" : s, e);
5
- import { z as i } from "zod";
6
- const k = i.object({
7
- status: i.string(),
8
- code: i.string(),
9
- title: i.string().optional(),
10
- detail: i.string().optional(),
11
- meta: i.record(i.unknown()).optional(),
12
- source: i.object({
13
- pointer: i.string().optional()
14
- }).optional(),
15
- trace: i.array(
16
- i.object({
17
- file: i.string(),
18
- line: i.number(),
19
- function: i.string()
20
- })
21
- ).optional()
22
- }), U = i.object({
23
- errors: i.array(k)
24
- }), f = class f extends Error {
25
- constructor(e, t, r) {
26
- super(e);
27
- u(this, "errors");
28
- this.status = t, this.response = r, this.name = "ShopwareApiError";
29
- const { success: n, data: a } = U.safeParse(r);
30
- this.errors = n ? a.errors : [];
31
- }
1
+ // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/util.js
2
+ function jsonStringifyReplacer(e, t) {
3
+ return typeof t == "bigint" ? t.toString() : t;
4
+ }
5
+ var Cached = class {
6
+ constructor(e) {
7
+ this._getter = e, this._value = void 0;
8
+ }
9
+ get value() {
10
+ let e = this._getter;
11
+ return e !== void 0 && (this._value = e(), this._getter = void 0), this._value;
12
+ }
32
13
  };
33
- c(f, "ShopwareApiError");
34
- let h = f;
35
- const p = class p {
36
- constructor() {
37
- u(this, "listeners", /* @__PURE__ */ new Map());
38
- }
39
- addEventListener(s, e, t) {
40
- if (!e) return;
41
- const r = this.normalizeOptions(t), n = {
42
- listener: e,
43
- options: r
44
- };
45
- if (r.signal) {
46
- if (r.signal.aborted) return;
47
- n.signal = r.signal, r.signal.addEventListener("abort", () => {
48
- this.removeEventListener(s, e, t);
49
- }, { once: !0 });
50
- }
51
- this.listeners.has(s) || this.listeners.set(s, []), this.listeners.get(s).push(n);
52
- }
53
- removeEventListener(s, e, t) {
54
- if (!e) return;
55
- const r = this.listeners.get(s);
56
- if (!r) return;
57
- const n = this.normalizeOptions(t), a = r.findIndex((l) => l.listener === e && this.optionsMatch(l.options, n));
58
- a !== -1 && (r.splice(a, 1), r.length === 0 && this.listeners.delete(s));
59
- }
60
- dispatchEvent(s) {
61
- var r;
62
- const e = this.listeners.get(s.type);
63
- if (!e || e.length === 0) return !0;
64
- const t = [...e];
65
- for (const n of t)
66
- if (!((r = n.signal) != null && r.aborted) && (typeof n.listener == "function" ? n.listener.call(this, s) : n.listener.handleEvent(s), n.options.once && this.removeEventListener(s.type, n.listener, n.options), s.cancelBubble))
67
- break;
68
- return !s.defaultPrevented;
69
- }
70
- normalizeOptions(s) {
71
- return typeof s == "boolean" ? { capture: s } : {
72
- capture: !1,
73
- once: !1,
74
- passive: !1,
75
- ...s
76
- };
77
- }
78
- optionsMatch(s, e) {
79
- return s.capture === e.capture;
80
- }
81
- // Utility methods for easier usage
82
- on(s, e, t) {
83
- this.addEventListener(s, e, t);
84
- }
85
- off(s, e, t) {
86
- this.removeEventListener(s, e, t);
87
- }
88
- once(s, e, t) {
89
- const r = typeof t == "boolean" ? {
90
- capture: t,
91
- once: !0
92
- } : {
93
- ...t,
94
- once: !0
95
- };
96
- this.addEventListener(s, e, r);
97
- }
98
- emit(s, e) {
99
- const t = new CustomEvent(s, { detail: e });
100
- return this.dispatchEvent(t);
101
- }
102
- getEventTypes() {
103
- return Array.from(this.listeners.keys());
104
- }
105
- removeAllListeners(s) {
106
- s ? this.listeners.delete(s) : this.listeners.clear();
107
- }
14
+ function cached(e) {
15
+ return new Cached(e);
16
+ }
17
+ function cleanRegex(e) {
18
+ let t = +!!e.startsWith("^"), n = e.endsWith("$") ? e.length - 1 : e.length;
19
+ return e.slice(t, n);
20
+ }
21
+ function assignProp(e, t, n) {
22
+ Object.defineProperty(e, t, {
23
+ value: n,
24
+ writable: !0,
25
+ enumerable: !0,
26
+ configurable: !0
27
+ });
28
+ }
29
+ var e = "captureStackTrace" in Error ? Error.captureStackTrace : (...e) => {};
30
+ function isObject(e) {
31
+ return typeof e == "object" && !!e && !Array.isArray(e);
32
+ }
33
+ function isPlainObject(e) {
34
+ if (isObject(e) === !1) return !1;
35
+ let t = e.constructor;
36
+ if (t === void 0 || typeof t != "function") return !0;
37
+ let n = t.prototype;
38
+ return isObject(n) !== !1 && Object.prototype.hasOwnProperty.call(n, "isPrototypeOf") !== !1;
39
+ }
40
+ function clone(e, t, n) {
41
+ let r = new e._zod.constr(t ?? e._zod.def);
42
+ return (!t || n?.parent) && (r._zod.parent = e), r;
43
+ }
44
+ function normalizeParams(e) {
45
+ let t = e;
46
+ if (!t) return {};
47
+ if (typeof t == "string") return { error: () => t };
48
+ if (t?.message !== void 0) {
49
+ if (t?.error !== void 0) throw Error("Cannot specify both `message` and `error` params");
50
+ t.error = t.message;
51
+ }
52
+ return delete t.message, typeof t.error == "string" ? {
53
+ ...t,
54
+ error: () => t.error
55
+ } : t;
56
+ }
57
+ function optionalKeys(e) {
58
+ return Object.keys(e).filter((t) => e[t]._zod.optin !== void 0 && e[t]._zod.optout === "optional");
59
+ }
60
+ function aborted(e, t = 0) {
61
+ if (e.aborted === !0) return !0;
62
+ for (let n = t; n < e.issues.length; n++) if (e.issues[n]?.continue !== !0) return !0;
63
+ return !1;
64
+ }
65
+ function explicitlyAborted(e, t = 0) {
66
+ if (e.aborted === !0) return !0;
67
+ for (let n = t; n < e.issues.length; n++) if (e.issues[n]?.continue === !1) return !0;
68
+ return !1;
69
+ }
70
+ function prefixIssues(e, t) {
71
+ return t.map((t) => {
72
+ var n;
73
+ return (n = t).path ?? (n.path = []), t.path.unshift(e), t;
74
+ });
75
+ }
76
+ function unwrapMessage(e) {
77
+ return typeof e == "string" ? e : e?.message;
78
+ }
79
+ function sizeCaps(e) {
80
+ let t = [];
81
+ for (let n of e ?? []) {
82
+ let e = n._zod.def;
83
+ if (!/_(length|size)$|_equals$/.test(e.check)) break;
84
+ let r = e.maximum ?? e.length ?? e.size;
85
+ r >= 0 && t.push([r, n]);
86
+ }
87
+ return t;
88
+ }
89
+ function attachSchema(e, t, n) {
90
+ var r;
91
+ for (let i = t; i < e.length; i++) (r = e[i]).schema ?? (r.schema = n);
92
+ }
93
+ function finalizeIssue(e, t, n) {
94
+ var r;
95
+ let i = e.inst?._zod?.traits;
96
+ i?.has("$ZodType") && (i.has("$ZodCheck") ? (r = e).schema ?? (r.schema = e.inst) : e.schema = e.inst);
97
+ let a = e.schema === e.inst ? void 0 : e.schema?._zod.def?.error, o = e.message ? e.message : unwrapMessage(e.inst?._zod.def?.error?.(e)) ?? unwrapMessage(a?.(e)) ?? unwrapMessage(t?.error?.(e)) ?? unwrapMessage(n.customError?.(e)) ?? unwrapMessage(n.localeError?.(e)) ?? "Invalid input", s = {};
98
+ for (let t of Object.keys(e)) t !== "inst" && t !== "schema" && t !== "continue" && t !== "input" && t !== "__proto__" && (s[t] = e[t]);
99
+ return s.path ??= [], s.message = o, t?.reportInput && (s.input = e.input), s;
100
+ }
101
+ function members(e, t) {
102
+ for (let n in t) {
103
+ let r = Object.getOwnPropertyDescriptor(t, n);
104
+ r.get ? Object.defineProperty(e, n, {
105
+ ...r,
106
+ enumerable: !1
107
+ }) : defineBound(e, n, r.value);
108
+ }
109
+ }
110
+ function own(e, t, n, r = !0) {
111
+ return Object.defineProperty(e, t, {
112
+ configurable: !0,
113
+ writable: !0,
114
+ enumerable: r,
115
+ value: n
116
+ }), n;
117
+ }
118
+ function hide(e, t, n) {
119
+ return own(e, t, n, !1);
120
+ }
121
+ function defineBound(e, t, n) {
122
+ Object.defineProperty(e, t, {
123
+ configurable: !0,
124
+ get() {
125
+ return this == null ? n : own(this, t, n.bind(this));
126
+ },
127
+ set(e) {
128
+ own(this, t, e);
129
+ }
130
+ });
131
+ }
132
+ function claim(e, t) {
133
+ let n = Object.getPrototypeOf(e);
134
+ return t in n ? void 0 : n;
135
+ }
136
+ var t, n = !1, r = {
137
+ configurable: !0,
138
+ get() {
139
+ n = !0;
140
+ }
108
141
  };
109
- c(p, "EventEmitter");
110
- let d = p;
111
- const m = /* @__PURE__ */ c((o) => o == null || typeof o == "number" && isNaN(o) || typeof o == "function", "isIgnored");
112
- function q(o) {
113
- const s = new URLSearchParams(), e = /* @__PURE__ */ c((t, r) => {
114
- m(r) || (typeof r == "object" && s.append(t, JSON.stringify(r)), s.append(t, String(r)));
115
- }, "appendNested");
116
- for (const [t, r] of Object.entries(o))
117
- if (!m(r))
118
- if (typeof r == "string")
119
- s.append(t, String(r));
120
- else if (Array.isArray(r))
121
- for (const n of r)
122
- e(`${t}[]`, n);
123
- else
124
- e(t, r);
125
- return s;
126
- }
127
- c(q, "createQueryParams");
128
- const T = /^(?<name>\w+?)\s(?<method>get|post|put|patch|delete)\s+(?<url>\/.*)/i, g = class g extends d {
129
- constructor(e) {
130
- super();
131
- u(this, "options", {
132
- baseURL: "",
133
- apiKey: "",
134
- language: "",
135
- contextToken: "",
136
- includeSeoUrls: !1,
137
- reflectContextToken: !0,
138
- headers: {}
139
- });
140
- this.requestInitDefaults = e.requestInitDefaults, this.baseURL = e.baseURL ?? this.options.baseURL, this.apiKey = e.apiKey ?? this.options.apiKey, this.language = e.language ?? this.options.language, this.contextToken = e.contextToken ?? this.options.contextToken, this.includeSeoUrls = e.includeSeoUrls ?? this.options.includeSeoUrls, this.reflectContextToken = e.reflectContextToken ?? this.options.reflectContextToken, this.headers = e.headers ?? this.options.headers, this.queryClientId = e.queryClientId ?? this.options.queryClientId;
141
- }
142
- set requestInitDefaults(e) {
143
- this.options.requestInitDefaults = e;
144
- }
145
- get requestInitDefaults() {
146
- return this.options.requestInitDefaults;
147
- }
148
- set baseURL(e) {
149
- if (typeof e != "string")
150
- throw new Error("Invalid baseURL: It must be a string.");
151
- this.options.baseURL = e;
152
- }
153
- get baseURL() {
154
- return this.options.baseURL;
155
- }
156
- set apiKey(e) {
157
- if (typeof e != "string")
158
- throw new Error("Invalid apiKey: It must be a string.");
159
- this.options.apiKey = e;
160
- }
161
- get apiKey() {
162
- return this.options.apiKey;
163
- }
164
- set language(e) {
165
- if (e && typeof e != "string")
166
- throw new Error("Invalid language: If provided, it must be a string.");
167
- this.options.language = e;
168
- }
169
- get language() {
170
- return this.options.language;
171
- }
172
- set contextToken(e) {
173
- if (e && typeof e != "string")
174
- throw new Error("Invalid contextToken: If provided, it must be a string.");
175
- this.options.contextToken = e, this.emit("contextToken", e);
176
- }
177
- get contextToken() {
178
- return this.options.contextToken;
179
- }
180
- set includeSeoUrls(e) {
181
- this.options.includeSeoUrls = e;
182
- }
183
- get includeSeoUrls() {
184
- return this.options.includeSeoUrls;
185
- }
186
- set reflectContextToken(e) {
187
- this.options.reflectContextToken = e;
188
- }
189
- get reflectContextToken() {
190
- return this.options.reflectContextToken;
191
- }
192
- set headers(e) {
193
- this.options.headers = e;
194
- }
195
- get headers() {
196
- return this.options.headers;
197
- }
198
- set queryClientId(e) {
199
- if (e && typeof e != "string")
200
- throw new Error("Invalid queryClientId: If provided, it must be a string.");
201
- this.options.queryClientId = e;
202
- }
203
- get queryClientId() {
204
- return this.options.queryClientId;
205
- }
206
- parseOperation(e) {
207
- const t = T.exec(e);
208
- if (!(t != null && t.groups))
209
- throw new Error("Invalid operation format");
210
- return {
211
- name: t.groups.name,
212
- method: t.groups.method.toUpperCase(),
213
- url: t.groups.url
214
- };
215
- }
216
- interpolateUrl(e, t) {
217
- return e.replace(/{([^}]+?)}/g, (r, n) => {
218
- if (!(n in t))
219
- throw new Error(`Missing required URL parameter: ${n}`);
220
- return t[n];
221
- });
222
- }
223
- async queryRaw(e, t) {
224
- var n;
225
- let r;
226
- try {
227
- const { method: a, url: l } = this.parseOperation(e), b = this.interpolateUrl(l, (t == null ? void 0 : t.params) ?? {}), x = t != null && t.query ? `?${q(t.query)}` : "";
228
- r = await fetch(`${this.baseURL}/store-api${b}${x}`, {
229
- ...this.requestInitDefaults,
230
- ...t,
231
- method: a,
232
- headers: {
233
- "Content-Type": "application/json",
234
- "sw-access-key": this.apiKey,
235
- ...(n = this.requestInitDefaults) == null ? void 0 : n.headers,
236
- ...this.contextToken && { "sw-context-token": this.contextToken },
237
- ...this.includeSeoUrls && { "sw-include-seo-urls": "true" },
238
- ...this.language && { "sw-language-id": this.language },
239
- ...this.headers,
240
- ...t == null ? void 0 : t.headers
241
- },
242
- body: t != null && t.body ? JSON.stringify(t.body) : void 0
243
- });
244
- } catch (a) {
245
- const l = new h(
246
- "Failed to communicate with Shopware API",
247
- 500,
248
- a instanceof Error ? a.message : void 0
249
- );
250
- throw this.emit("error", l), l;
251
- }
252
- if (!r.ok) {
253
- const a = new h(
254
- `Shopware API request failed: ${r.statusText}`,
255
- r.status,
256
- await r.json().catch(() => {
257
- })
258
- );
259
- throw this.emit("error", a), a;
260
- }
261
- if (this.options.reflectContextToken) {
262
- const a = r.headers.get("sw-context-token");
263
- a && (this.contextToken = a);
264
- }
265
- return r;
266
- }
267
- async query(e, t) {
268
- return (await this.queryRaw(e, t)).json().catch(() => {
269
- });
270
- }
142
+ function defineLazyInternal(e, i, a) {
143
+ let o = Object.getPrototypeOf(e._zod);
144
+ i in o && t !== e._zod ? t = void 0 : (t = e._zod, Object.defineProperty(o, i, {
145
+ configurable: !0,
146
+ get() {
147
+ Object.defineProperty(this, i, r);
148
+ let e = n;
149
+ n = !1;
150
+ try {
151
+ let t = a(this);
152
+ return n ? delete this[i] : Object.defineProperty(this, i, {
153
+ configurable: !0,
154
+ writable: !0,
155
+ value: t
156
+ }), n ||= e, t;
157
+ } catch (t) {
158
+ throw delete this[i], n ||= e, t;
159
+ }
160
+ },
161
+ set(e) {
162
+ Object.defineProperty(this, i, {
163
+ configurable: !0,
164
+ writable: !0,
165
+ value: e
166
+ });
167
+ }
168
+ }));
169
+ }
170
+ function installLazyProp(e, t, n, r) {
171
+ let i = claim(e, t);
172
+ i && Object.defineProperty(i, t, {
173
+ configurable: !0,
174
+ get() {
175
+ let e = {
176
+ configurable: !0,
177
+ writable: !0,
178
+ enumerable: r,
179
+ value: void 0
180
+ };
181
+ return Object.defineProperty(this, t, e), e.value = n(this), Object.defineProperty(this, t, e), e.value;
182
+ },
183
+ set(e) {
184
+ Object.defineProperty(this, t, {
185
+ configurable: !0,
186
+ writable: !0,
187
+ enumerable: r,
188
+ value: e
189
+ });
190
+ }
191
+ });
192
+ }
193
+ // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/core.js
194
+ var i, a = {
195
+ value: void 0,
196
+ enumerable: !1
197
+ }, o = "captureStackTrace" in Error ? Error : null;
198
+ function newError(e) {
199
+ let t = o;
200
+ if (t) {
201
+ let n = t.stackTraceLimit;
202
+ if (typeof n == "number") {
203
+ try {
204
+ t.stackTraceLimit = 0;
205
+ } catch {
206
+ return o = null, new e();
207
+ }
208
+ try {
209
+ return new e();
210
+ } finally {
211
+ t.stackTraceLimit = n;
212
+ }
213
+ }
214
+ }
215
+ return new e();
216
+ }
217
+ /* @__NO_SIDE_EFFECTS__ */
218
+ function $constructor(e, t, n, r) {
219
+ let i = {};
220
+ function Internals(e) {
221
+ this.def = e, this.constr = _, this.traits = /* @__PURE__ */ new Set();
222
+ }
223
+ Internals.prototype = i;
224
+ let o = n, s = o && /* @__PURE__ */ new WeakSet();
225
+ function init(n, r) {
226
+ if (!n._zod) {
227
+ a.value = new Internals(r);
228
+ try {
229
+ Object.defineProperty(n, "_zod", a);
230
+ } finally {
231
+ a.value = void 0;
232
+ }
233
+ } else if (n._zod.traits.has(e)) return;
234
+ if (n._zod.traits.add(e), t(n, r), s) {
235
+ let e = Object.getPrototypeOf(n), t = n._zod.constr.prototype, r = e;
236
+ for (; r && r !== t;) r = Object.getPrototypeOf(r);
237
+ let i = r ?? e;
238
+ s.has(i) || (s.add(i), members(i, o));
239
+ }
240
+ let i = _.prototype;
241
+ for (let e in i) Object.prototype.hasOwnProperty.call(i, e) && (e in n || (n[e] = i[e].bind(n)));
242
+ }
243
+ let c = r?.Parent ?? Object;
244
+ class Definition extends c {}
245
+ Object.defineProperty(Definition, "name", { value: e });
246
+ function _(e) {
247
+ let t = r?.Parent ? newError(Definition) : this;
248
+ init(t, e);
249
+ let n = t._zod.deferred;
250
+ if (n) {
251
+ for (let e of n) e();
252
+ t._zod.deferred = void 0;
253
+ }
254
+ let i = globalThis.__zod_globalConfig?.postProcessor;
255
+ return i && i(t), t;
256
+ }
257
+ return Object.defineProperty(_, "init", { value: init }), Object.defineProperty(_, Symbol.hasInstance, { value: (t) => r?.Parent && t instanceof r.Parent ? !0 : t?._zod?.traits?.has(e) }), Object.defineProperty(_, "name", { value: e }), _;
258
+ }
259
+ var $ZodAsyncError = class extends Error {
260
+ constructor() {
261
+ super("Encountered Promise during synchronous parse. Use .parseAsync() instead.");
262
+ }
271
263
  };
272
- c(g, "ShopwareClient");
273
- let w = g;
274
- export {
275
- h as ShopwareApiError,
276
- w as ShopwareClient
264
+ (i = globalThis).__zod_globalConfig ?? (i.__zod_globalConfig = {});
265
+ var s = globalThis.__zod_globalConfig;
266
+ function config(e) {
267
+ return e && Object.assign(s, e), s;
268
+ }
269
+ // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/errors.js
270
+ function _getMessage() {
271
+ let e = this._zod;
272
+ return e.message ??= JSON.stringify(e.def, jsonStringifyReplacer, 2), e.message;
273
+ }
274
+ function _setMessage(e) {
275
+ this._zod.message = e;
276
+ }
277
+ var c = {
278
+ get: _getMessage,
279
+ set: _setMessage,
280
+ enumerable: !0,
281
+ configurable: !0
282
+ }, l = {
283
+ value: void 0,
284
+ enumerable: !1
285
+ }, u = /* @__PURE__ */ new WeakSet([Object.prototype, Error.prototype]), initializer = (e, t) => {
286
+ e.name = "$ZodError", l.value = t, Object.defineProperty(e, "issues", l), l.value = void 0, Object.defineProperty(e, "message", c);
287
+ let n = Object.getPrototypeOf(e);
288
+ u.has(n) || (u.add(n), Object.defineProperty(n, "toString", {
289
+ configurable: !0,
290
+ enumerable: !1,
291
+ get() {
292
+ let value = () => this.message;
293
+ return Object.defineProperty(this, "toString", {
294
+ value,
295
+ configurable: !0,
296
+ writable: !0
297
+ }), value;
298
+ },
299
+ set(e) {
300
+ Object.defineProperty(this, "toString", {
301
+ value: e,
302
+ configurable: !0,
303
+ writable: !0
304
+ });
305
+ }
306
+ }));
307
+ }, d = /* @__PURE__ */ $constructor("$ZodError", initializer, void 0, { Parent: Error }), _parse = (t) => {
308
+ let fn = (n, r, i, a) => {
309
+ let o = i ? {
310
+ ...i,
311
+ async: !1
312
+ } : { async: !1 }, s = n._zod.run({
313
+ value: r,
314
+ issues: []
315
+ }, o);
316
+ if (s instanceof Promise) throw new $ZodAsyncError();
317
+ if (s.issues.length) {
318
+ let n = new ((a?.Err) ?? t)(s.issues.map((e) => finalizeIssue(e, o, config())));
319
+ throw e(n, a?.callee ?? fn), n;
320
+ }
321
+ return s.value;
322
+ };
323
+ return fn;
324
+ }, f = /* @__PURE__*/ _parse(d), _parseAsync = (t) => {
325
+ let fn = async (n, r, i, a) => {
326
+ let o = i ? {
327
+ ...i,
328
+ async: !0
329
+ } : { async: !0 }, s = n._zod.run({
330
+ value: r,
331
+ issues: []
332
+ }, o);
333
+ if (s instanceof Promise && (s = await s), s.issues.length) {
334
+ let n = new ((a?.Err) ?? t)(s.issues.map((e) => finalizeIssue(e, o, config())));
335
+ throw e(n, a?.callee ?? fn), n;
336
+ }
337
+ return s.value;
338
+ };
339
+ return fn;
340
+ }, p = /* @__PURE__*/ _parseAsync(d), _safeParse = (e) => (t, n, r) => {
341
+ let i = r ? {
342
+ ...r,
343
+ async: !1
344
+ } : { async: !1 }, a = t._zod.run({
345
+ value: n,
346
+ issues: []
347
+ }, i);
348
+ if (a instanceof Promise) throw new $ZodAsyncError();
349
+ return a.issues.length ? failure(e, a.issues, i) : {
350
+ success: !0,
351
+ data: a.value
352
+ };
353
+ }, m = /* @__PURE__*/ _safeParse(d);
354
+ function failure(e, t, n) {
355
+ let r;
356
+ return {
357
+ success: !1,
358
+ get error() {
359
+ return r || (r = new e(t.map((e) => finalizeIssue(e, n, config()))), t = void 0, n = void 0), r;
360
+ },
361
+ set error(e) {
362
+ r = e, t = void 0, n = void 0;
363
+ }
364
+ };
365
+ }
366
+ var _safeParseAsync = (e) => async (t, n, r) => {
367
+ let i = r ? {
368
+ ...r,
369
+ async: !0
370
+ } : { async: !0 }, a = t._zod.run({
371
+ value: n,
372
+ issues: []
373
+ }, i);
374
+ return a instanceof Promise && (a = await a), a.issues.length ? failure(e, a.issues, i) : {
375
+ success: !0,
376
+ data: a.value
377
+ };
378
+ }, h = /* @__PURE__*/ _safeParseAsync(d), g = /^[\s\S]{0,}$/, v = /^-?\d+(?:\.\d+)?$/, y = {
379
+ major: 4,
380
+ minor: 6,
381
+ patch: 7
382
+ }, b = /*@__PURE__*/ $constructor("$ZodType", (e, t) => {
383
+ var n;
384
+ e ??= {}, e._zod.def = t, e._zod.bag = e._zod.bag || {}, e._zod.version = y;
385
+ let r = e._zod.def.checks, i = e._zod.traits.has("$ZodCheck") ? [e, ...r ?? []] : r?.length ? [...r] : [];
386
+ for (let t of i) for (let n of t._zod.onattach) n(e);
387
+ if (i.length === 0) (n = e._zod).deferred ?? (n.deferred = []), e._zod.deferred?.push(() => {
388
+ e._zod.run = e._zod.parse;
389
+ });
390
+ else {
391
+ let runChecks = (t, n, r) => {
392
+ if (t.memo) return t;
393
+ let i = aborted(t), a;
394
+ for (let o of n) {
395
+ if (o._zod.def.when) {
396
+ if (explicitlyAborted(t) || !o._zod.def.when(t)) continue;
397
+ } else if (i) continue;
398
+ let n = t.issues.length, s = o._zod.check(t);
399
+ if (s instanceof Promise && r?.async === !1) throw new $ZodAsyncError();
400
+ if (a || s instanceof Promise) a = (a ?? Promise.resolve()).then(async () => {
401
+ await s, t.issues.length !== n && (attachSchema(t.issues, n, e), i ||= aborted(t, n));
402
+ });
403
+ else {
404
+ if (t.issues.length === n) continue;
405
+ attachSchema(t.issues, n, e), i ||= aborted(t, n);
406
+ }
407
+ }
408
+ return a ? a.then(() => t) : t;
409
+ }, handleCanaryResult = (t, n, r) => {
410
+ if (aborted(t)) return t.aborted = !0, t;
411
+ let a = runChecks(n, i, r);
412
+ if (a instanceof Promise) {
413
+ if (r.async === !1) throw new $ZodAsyncError();
414
+ return a.then((t) => e._zod.parse(t, r));
415
+ }
416
+ return e._zod.parse(a, r);
417
+ };
418
+ e._zod.run = (t, n) => {
419
+ if (n.skipChecks) return e._zod.parse(t, n);
420
+ if (n.direction === "backward") {
421
+ let r = e._zod.parse({
422
+ value: t.value,
423
+ issues: []
424
+ }, {
425
+ ...n,
426
+ skipChecks: !0
427
+ });
428
+ return r instanceof Promise ? r.then((e) => handleCanaryResult(e, t, n)) : handleCanaryResult(r, t, n);
429
+ }
430
+ let r = e._zod.parse(t, n);
431
+ if (r instanceof Promise) {
432
+ if (n.async === !1) throw new $ZodAsyncError();
433
+ return r.then((e) => runChecks(e, i, n));
434
+ }
435
+ return runChecks(r, i, n);
436
+ };
437
+ }
438
+ }, {
439
+ get "~standard"() {
440
+ return hide(this, "~standard", standardProps(this));
441
+ },
442
+ set "~standard"(e) {
443
+ own(this, "~standard", e);
444
+ }
445
+ }), toStandardResult = (e, t) => e.issues.length ? { issues: e.issues.map((e) => finalizeIssue(e, t, config())) } : { value: e.value };
446
+ async function validateAsync(e, t) {
447
+ let n = { async: !0 };
448
+ return toStandardResult(await e._zod.run({
449
+ value: t,
450
+ issues: []
451
+ }, n), n);
452
+ }
453
+ function standardProps(e) {
454
+ return {
455
+ validate: (t) => {
456
+ let n = { async: !1 };
457
+ try {
458
+ let r = e._zod.run({
459
+ value: t,
460
+ issues: []
461
+ }, n);
462
+ if (!(r instanceof Promise)) return toStandardResult(r, n);
463
+ } catch {}
464
+ return validateAsync(e, t);
465
+ },
466
+ vendor: "zod",
467
+ version: 1
468
+ };
469
+ }
470
+ var x = /*@__PURE__*/ $constructor("$ZodString", (e, t) => {
471
+ b.init(e, t), e._zod.pattern = t.pattern ?? g, e._zod.parse = (n, r) => {
472
+ if (t.coerce) try {
473
+ n.value = String(n.value);
474
+ } catch {}
475
+ return typeof n.value == "string" || n.issues.push({
476
+ expected: "string",
477
+ code: "invalid_type",
478
+ input: n.value,
479
+ inst: e
480
+ }), n;
481
+ };
482
+ }), S = /*@__PURE__*/ $constructor("$ZodNumber", (e, t) => {
483
+ b.init(e, t), e._zod.pattern = v, e._zod.parse = (n, r) => {
484
+ if (t.coerce) try {
485
+ n.value = Number(n.value);
486
+ } catch {}
487
+ let i = n.value;
488
+ if (typeof i == "number" && !Number.isNaN(i) && Number.isFinite(i)) return n;
489
+ let a = typeof i == "number" ? Number.isNaN(i) ? "NaN" : Number.isFinite(i) ? void 0 : String(i) : void 0;
490
+ return n.issues.push({
491
+ expected: "number",
492
+ code: "invalid_type",
493
+ input: i,
494
+ inst: e,
495
+ ...a ? { received: a } : {}
496
+ }), n;
497
+ };
498
+ }), C = /*@__PURE__*/ $constructor("$ZodUnknown", (e, t) => {
499
+ b.init(e, t), e._zod.parse = (e) => e;
500
+ });
501
+ function capSize(e, t) {
502
+ let n = sizeCaps(e._zod.def.checks);
503
+ if (!n.length) return;
504
+ let r = Math.min(...n.map((e) => e[0])), i = e._zod.parse;
505
+ e._zod.parse = (n, a) => {
506
+ let o = t(n.value);
507
+ if (o > r && !a?.skipChecks && a?.direction !== "backward") {
508
+ for (let [t, r] of sizeCaps(e._zod.def.checks)) if (o > t && r._zod.def.when(n)) {
509
+ let t = n.issues.length;
510
+ return r._zod.check(n), n.issues[t].continue = !1, attachSchema(n.issues, t, e), n;
511
+ }
512
+ }
513
+ return i(n, a);
514
+ };
515
+ }
516
+ var arraySize = (e) => Array.isArray(e) ? e.length : -1;
517
+ function handleArrayResult(e, t, n) {
518
+ e.issues.length && t.issues.push(...prefixIssues(n, e.issues)), t.value[n] = e.value;
519
+ }
520
+ var w = /*@__PURE__*/ $constructor("$ZodArray", (e, t) => {
521
+ b.init(e, t);
522
+ let n = s.memoizer;
523
+ n?.attach(e), e._zod.parse = (r, i) => {
524
+ let a = r.value;
525
+ if (!Array.isArray(a)) return r.issues.push({
526
+ expected: "array",
527
+ code: "invalid_type",
528
+ input: a,
529
+ inst: e
530
+ }), r;
531
+ r.value = n ? n.alloc(e, r, Array(a.length), i) : Array(a.length);
532
+ let o = [], s = i?.abortEarly;
533
+ for (let e = 0; e < a.length; e++) {
534
+ let n = a[e], c = t.element._zod.run({
535
+ value: n,
536
+ issues: []
537
+ }, i);
538
+ if (c instanceof Promise) o.push(c.then((t) => handleArrayResult(t, r, e)));
539
+ else if (handleArrayResult(c, r, e), s && c.issues.length !== 0 && aborted(c)) break;
540
+ }
541
+ return o.length ? Promise.all(o).then(() => r) : r;
542
+ }, capSize(e, arraySize);
543
+ });
544
+ function handlePropertyResult(e, t, n, r, i, a) {
545
+ let o = n in r, s = a === "optional";
546
+ if (o || !s || i !== "optional") {
547
+ if (e.issues.length) {
548
+ if (i !== void 0 && s && !o) return;
549
+ t.issues.push(...prefixIssues(n, e.issues));
550
+ }
551
+ !o && i === void 0 ? e.issues.length || t.issues.push({
552
+ code: "invalid_type",
553
+ expected: "nonoptional",
554
+ input: void 0,
555
+ path: [n]
556
+ }) : e.value === void 0 ? (o || i === "defaulted" && !s) && (t.value[n] = void 0) : t.value[n] = e.value;
557
+ }
558
+ }
559
+ var T = [];
560
+ function normalizeDef(e) {
561
+ let t = Object.keys(e.shape), n = Object.getOwnPropertySymbols(e.shape), r = n.length ? n : T, i = r.length ? [...t, ...r] : t;
562
+ for (let t of i) if (!e.shape?.[t]?._zod?.traits?.has("$ZodType")) throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);
563
+ let a = optionalKeys(e.shape);
564
+ return {
565
+ ...e,
566
+ allKeys: i,
567
+ symbolKeys: r,
568
+ keySet: new Set(t),
569
+ numKeys: t.length,
570
+ optionalKeys: new Set(a)
571
+ };
572
+ }
573
+ function handleCatchall(e, t, n, r, i, a, o) {
574
+ let s = [], c = i.keySet, l = i.catchall._zod, u = l.def.type, d = l.optin, f = l.optout, p = 0;
575
+ for (let i in t) {
576
+ if (o && n.issues.length !== p) {
577
+ if (aborted(n, p)) break;
578
+ p = n.issues.length;
579
+ }
580
+ if (c.has(i)) continue;
581
+ if (i === "__proto__") {
582
+ u === "never" && s.push(i);
583
+ continue;
584
+ }
585
+ if (u === "never") {
586
+ s.push(i);
587
+ continue;
588
+ }
589
+ let a = l.run({
590
+ value: t[i],
591
+ issues: []
592
+ }, r);
593
+ a instanceof Promise ? e.push(a.then((e) => handlePropertyResult(e, n, i, t, d, f))) : handlePropertyResult(a, n, i, t, d, f);
594
+ }
595
+ return s.length && n.issues.push({
596
+ code: "unrecognized_keys",
597
+ keys: s,
598
+ input: t,
599
+ inst: a,
600
+ continue: !0
601
+ }), e.length ? Promise.all(e).then(() => n) : n;
602
+ }
603
+ var E = /*@__PURE__*/ $constructor("$ZodObject", (e, t) => {
604
+ b.init(e, t);
605
+ let n = Object.getOwnPropertyDescriptor(t, "shape"), r = n?.get ? n.get.raw : t.shape ?? {};
606
+ if (r) {
607
+ let get = () => {
608
+ let e = { ...r };
609
+ return Object.defineProperty(t, "shape", { value: e }), get.raw = e, e;
610
+ };
611
+ get.raw = r, Object.defineProperty(t, "shape", { get });
612
+ }
613
+ let i = cached(() => normalizeDef(t));
614
+ defineLazyInternal(e, "propValues", (e) => {
615
+ let t = e.def.shape, n = {};
616
+ for (let e in t) {
617
+ let r = t[e]._zod;
618
+ if (r.values) {
619
+ Object.prototype.hasOwnProperty.call(n, e) || assignProp(n, e, /* @__PURE__ */ new Set());
620
+ for (let t of r.values) n[e].add(t);
621
+ r.optin !== void 0 && n[e].add(void 0);
622
+ }
623
+ }
624
+ return n;
625
+ });
626
+ let a = isObject, o = t.catchall, c, l = s.memoizer;
627
+ l?.attach(e), e._zod.parse = (t, n) => {
628
+ c ??= i.value;
629
+ let r = t.value;
630
+ if (!a(r)) return t.issues.push({
631
+ expected: "object",
632
+ code: "invalid_type",
633
+ input: r,
634
+ inst: e
635
+ }), t;
636
+ t.value = l ? l.alloc(e, t, {}, n) : {};
637
+ let s = [], u = c.shape, d = n?.abortEarly, f = t.issues.length;
638
+ for (let e of c.allKeys) {
639
+ if (d && t.issues.length !== f) {
640
+ if (aborted(t, f)) break;
641
+ f = t.issues.length;
642
+ }
643
+ if (e === "__proto__") continue;
644
+ let i = u[e], a = i._zod.optin, o = i._zod.optout, c = i._zod.run({
645
+ value: r[e],
646
+ issues: []
647
+ }, n);
648
+ c instanceof Promise ? s.push(c.then((n) => handlePropertyResult(n, t, e, r, a, o))) : handlePropertyResult(c, t, e, r, a, o);
649
+ }
650
+ return o ? handleCatchall(s, r, t, n, i.value, e, d === !0) : s.length ? Promise.all(s).then(() => t) : t;
651
+ };
652
+ }), D = /*@__PURE__*/ $constructor("$ZodRecord", (e, t) => {
653
+ b.init(e, t);
654
+ let n = s.memoizer;
655
+ n?.attach(e), e._zod.parse = (r, i) => {
656
+ let a = r.value;
657
+ if (!isPlainObject(a)) return r.issues.push({
658
+ expected: "record",
659
+ code: "invalid_type",
660
+ input: a,
661
+ inst: e
662
+ }), r;
663
+ let o = [], s = t.keyType._zod.values;
664
+ if (s && !t.partial) {
665
+ r.value = n ? n.alloc(e, r, {}, i) : {};
666
+ let c = /* @__PURE__ */ new Set();
667
+ for (let n of s) if (typeof n == "string" || typeof n == "number" || typeof n == "symbol") {
668
+ if (c.add(typeof n == "number" ? n.toString() : n), n === "__proto__") continue;
669
+ let s = t.keyType._zod.run({
670
+ value: n,
671
+ issues: []
672
+ }, i);
673
+ if (s instanceof Promise) throw Error("Async schemas not supported in object keys currently");
674
+ if (s.issues.length) {
675
+ r.issues.push({
676
+ code: "invalid_key",
677
+ origin: "record",
678
+ issues: s.issues.map((e) => finalizeIssue(e, i, config())),
679
+ input: n,
680
+ path: [n],
681
+ inst: e
682
+ });
683
+ continue;
684
+ }
685
+ let l = s.value;
686
+ if (l === "__proto__") continue;
687
+ let u = t.valueType._zod.run({
688
+ value: a[n],
689
+ issues: []
690
+ }, i);
691
+ u instanceof Promise ? o.push(u.then((e) => {
692
+ e.issues.length && r.issues.push(...prefixIssues(n, e.issues)), r.value[l] = e.value;
693
+ })) : (u.issues.length && r.issues.push(...prefixIssues(n, u.issues)), r.value[l] = u.value);
694
+ }
695
+ let l;
696
+ for (let e in a) if (!c.has(e)) {
697
+ if (t.mode === "loose") {
698
+ if (e === "__proto__") continue;
699
+ r.value[e] = a[e];
700
+ } else l ??= [], l.push(e);
701
+ }
702
+ l && l.length > 0 && r.issues.push({
703
+ code: "unrecognized_keys",
704
+ input: a,
705
+ inst: e,
706
+ keys: l,
707
+ continue: !0
708
+ });
709
+ } else {
710
+ r.value = n ? n.alloc(e, r, {}, i) : {};
711
+ let c;
712
+ for (let n of Reflect.ownKeys(a)) {
713
+ if (n === "__proto__" || !Object.prototype.propertyIsEnumerable.call(a, n)) continue;
714
+ let l = t.keyType._zod.run({
715
+ value: n,
716
+ issues: []
717
+ }, i);
718
+ if (l instanceof Promise) throw Error("Async schemas not supported in object keys currently");
719
+ if (typeof n == "string" && v.test(n) && l.issues.length) {
720
+ let e = t.keyType._zod.run({
721
+ value: Number(n),
722
+ issues: []
723
+ }, i);
724
+ if (e instanceof Promise) throw Error("Async schemas not supported in object keys currently");
725
+ e.issues.length === 0 && (l = e);
726
+ }
727
+ if (l.issues.length) {
728
+ t.mode === "loose" ? r.value[n] = a[n] : s ? (c ??= [], c.push(n)) : r.issues.push({
729
+ code: "invalid_key",
730
+ origin: "record",
731
+ issues: l.issues.map((e) => finalizeIssue(e, i, config())),
732
+ input: n,
733
+ path: [n],
734
+ inst: e
735
+ });
736
+ continue;
737
+ }
738
+ let u = l.value;
739
+ if (u === "__proto__") continue;
740
+ let d = t.valueType._zod.run({
741
+ value: a[n],
742
+ issues: []
743
+ }, i);
744
+ d instanceof Promise ? o.push(d.then((e) => {
745
+ e.issues.length && r.issues.push(...prefixIssues(n, e.issues)), r.value[u] = e.value;
746
+ })) : (d.issues.length && r.issues.push(...prefixIssues(n, d.issues)), r.value[u] = d.value);
747
+ }
748
+ c && c.length > 0 && r.issues.push({
749
+ code: "unrecognized_keys",
750
+ input: a,
751
+ inst: e,
752
+ keys: c,
753
+ continue: !0
754
+ });
755
+ }
756
+ return o.length ? Promise.all(o).then(() => r) : r;
757
+ };
758
+ });
759
+ function handleOptionalResult(e, t) {
760
+ return e.value = t.issues.length ? void 0 : t.value, e;
761
+ }
762
+ var O = /*@__PURE__*/ $constructor("$ZodOptional", (e, t) => {
763
+ b.init(e, t), defineLazyInternal(e, "optin", (e) => e.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional"), e._zod.optout = "optional", defineLazyInternal(e, "values", (e) => {
764
+ let t = e.def.innerType._zod.values;
765
+ return t ? /* @__PURE__ */ new Set([...t, void 0]) : void 0;
766
+ }), defineLazyInternal(e, "pattern", (e) => {
767
+ let t = e.def.innerType._zod.pattern;
768
+ return t ? RegExp(`^(${cleanRegex(t.source)})?$`) : void 0;
769
+ }), e._zod.parse = (e, n) => {
770
+ if (e.value === void 0) {
771
+ if (t.innerType._zod.optin !== "defaulted") return e;
772
+ let r = t.innerType._zod.run({
773
+ value: e.value,
774
+ issues: []
775
+ }, n);
776
+ return r instanceof Promise ? r.then((t) => handleOptionalResult(e, t)) : handleOptionalResult(e, r);
777
+ }
778
+ return t.innerType._zod.run(e, n);
779
+ };
780
+ });
781
+ // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/api.js
782
+ function snapshotChecks(e) {
783
+ return e.checks &&= [...e.checks], e;
784
+ }
785
+ // @__NO_SIDE_EFFECTS__
786
+ function _string(e, t) {
787
+ return new e(snapshotChecks({
788
+ type: "string",
789
+ ...normalizeParams(t)
790
+ }));
791
+ }
792
+ // @__NO_SIDE_EFFECTS__
793
+ function _number(e, t) {
794
+ return new e(snapshotChecks({
795
+ type: "number",
796
+ checks: [],
797
+ ...normalizeParams(t)
798
+ }));
799
+ }
800
+ // @__NO_SIDE_EFFECTS__
801
+ function _unknown(e) {
802
+ return new e({ type: "unknown" });
803
+ }
804
+ // ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/mini/schemas.js
805
+ var k = /*@__PURE__*/ $constructor("ZodMiniType", (e, t) => {
806
+ if (!e._zod) throw Error("Uninitialized schema in ZodMiniType.");
807
+ b.init(e, t), e.def = t, e.type = t.type;
808
+ }, {
809
+ get with() {
810
+ return this.check;
811
+ },
812
+ set with(e) {
813
+ own(this, "with", e);
814
+ },
815
+ parse(e, t) {
816
+ return f(this, e, t, { callee: this.parse });
817
+ },
818
+ parseAsync(e, t) {
819
+ return p(this, e, t, { callee: this.parseAsync });
820
+ },
821
+ safeParse(e, t) {
822
+ return m(this, e, t);
823
+ },
824
+ safeParseAsync(e, t) {
825
+ return h(this, e, t);
826
+ },
827
+ check(...e) {
828
+ let t = this.def;
829
+ return this.clone({
830
+ ...t,
831
+ checks: [...t.checks ?? [], ...e.map((e) => typeof e == "function" ? { _zod: {
832
+ check: e,
833
+ def: { check: "custom" },
834
+ onattach: []
835
+ } } : e)]
836
+ }, { parent: !0 });
837
+ },
838
+ clone(e, t) {
839
+ return clone(this, e, t);
840
+ },
841
+ brand() {
842
+ return this;
843
+ },
844
+ register(e, t) {
845
+ return e.add(this, t), this;
846
+ },
847
+ apply(e, ...t) {
848
+ return t.length === 0 ? e(this) : e(this, ...t);
849
+ }
850
+ }), A = /*@__PURE__*/ $constructor("ZodMiniString", (e, t) => {
851
+ x.init(e, t), k.init(e, t);
852
+ });
853
+ // @__NO_SIDE_EFFECTS__
854
+ function string(e) {
855
+ return /* @__PURE__ */ _string(A, e);
856
+ }
857
+ var j = /*@__PURE__*/ $constructor("ZodMiniNumber", (e, t) => {
858
+ S.init(e, t), k.init(e, t);
859
+ });
860
+ // @__NO_SIDE_EFFECTS__
861
+ function number(e) {
862
+ return /* @__PURE__ */ _number(j, e);
863
+ }
864
+ var M = /*@__PURE__*/ $constructor("ZodMiniUnknown", (e, t) => {
865
+ C.init(e, t), k.init(e, t);
866
+ });
867
+ // @__NO_SIDE_EFFECTS__
868
+ function unknown() {
869
+ return /* @__PURE__ */ _unknown(M);
870
+ }
871
+ var N = /*@__PURE__*/ $constructor("ZodMiniArray", (e, t) => {
872
+ w.init(e, t), k.init(e, t);
873
+ });
874
+ // @__NO_SIDE_EFFECTS__
875
+ function array(e, t) {
876
+ return new N({
877
+ type: "array",
878
+ element: e,
879
+ ...normalizeParams(t)
880
+ });
881
+ }
882
+ var P = /*@__PURE__*/ $constructor("ZodMiniObject", (e, t) => {
883
+ E.init(e, t), k.init(e, t), installLazyProp(e, "shape", (e) => e._zod.def.shape, !1);
884
+ });
885
+ // @__NO_SIDE_EFFECTS__
886
+ function object(e, t) {
887
+ return new P({
888
+ type: "object",
889
+ shape: e ?? {},
890
+ ...normalizeParams(t)
891
+ });
892
+ }
893
+ var F = /*@__PURE__*/ $constructor("ZodMiniRecord", (e, t) => {
894
+ D.init(e, t), k.init(e, t);
895
+ });
896
+ // @__NO_SIDE_EFFECTS__
897
+ function record(e, t, n) {
898
+ return !t || !t._zod ? new F({
899
+ type: "record",
900
+ keyType: /* @__PURE__ */ string(),
901
+ valueType: e,
902
+ ...normalizeParams(t)
903
+ }) : new F({
904
+ type: "record",
905
+ keyType: e,
906
+ valueType: t,
907
+ ...normalizeParams(n)
908
+ });
909
+ }
910
+ var I = /*@__PURE__*/ $constructor("ZodMiniOptional", (e, t) => {
911
+ O.init(e, t), k.init(e, t);
912
+ });
913
+ // @__NO_SIDE_EFFECTS__
914
+ function optional(e) {
915
+ return new I({
916
+ type: "optional",
917
+ innerType: e
918
+ });
919
+ }
920
+ var L = /* @__PURE__ */ object({ errors: /* @__PURE__ */ array(/* @__PURE__ */ object({
921
+ status: /* @__PURE__ */ string(),
922
+ code: /* @__PURE__ */ string(),
923
+ title: /* @__PURE__ */ optional(/* @__PURE__ */ string()),
924
+ detail: /* @__PURE__ */ optional(/* @__PURE__ */ string()),
925
+ meta: /* @__PURE__ */ optional(/* @__PURE__ */ record(/* @__PURE__ */ string(), /* @__PURE__ */ unknown())),
926
+ source: /* @__PURE__ */ optional(/* @__PURE__ */ object({ pointer: /* @__PURE__ */ optional(/* @__PURE__ */ string()) })),
927
+ trace: /* @__PURE__ */ optional(/* @__PURE__ */ array(/* @__PURE__ */ object({
928
+ file: /* @__PURE__ */ string(),
929
+ line: /* @__PURE__ */ number(),
930
+ function: /* @__PURE__ */ string()
931
+ })))
932
+ })) }), ShopwareApiError = class extends Error {
933
+ status;
934
+ response;
935
+ errors;
936
+ constructor(e, t, n) {
937
+ super(e), this.status = t, this.response = n, this.name = "ShopwareApiError";
938
+ let { success: r, data: i } = L.safeParse(n);
939
+ this.errors = r ? i.errors : [];
940
+ }
941
+ }, EventEmitter = class {
942
+ listeners = /* @__PURE__ */ new Map();
943
+ addEventListener(e, t, n) {
944
+ if (!t) return;
945
+ let r = this.normalizeOptions(n), i = {
946
+ listener: t,
947
+ options: r
948
+ };
949
+ if (r.signal) {
950
+ if (r.signal.aborted) return;
951
+ i.signal = r.signal, r.signal.addEventListener("abort", () => {
952
+ this.removeEventListener(e, t, n);
953
+ }, { once: !0 });
954
+ }
955
+ this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(i);
956
+ }
957
+ removeEventListener(e, t, n) {
958
+ if (!t) return;
959
+ let r = this.listeners.get(e);
960
+ if (!r) return;
961
+ let i = this.normalizeOptions(n), a = r.findIndex((e) => e.listener === t && this.optionsMatch(e.options, i));
962
+ a !== -1 && (r.splice(a, 1), r.length === 0 && this.listeners.delete(e));
963
+ }
964
+ dispatchEvent(e) {
965
+ let t = this.listeners.get(e.type);
966
+ if (!t || t.length === 0) return !0;
967
+ let n = [...t];
968
+ for (let t of n) if (!t.signal?.aborted && (typeof t.listener == "function" ? t.listener.call(this, e) : t.listener.handleEvent(e), t.options.once && this.removeEventListener(e.type, t.listener, t.options), e.cancelBubble)) break;
969
+ return !e.defaultPrevented;
970
+ }
971
+ normalizeOptions(e) {
972
+ return typeof e == "boolean" ? { capture: e } : {
973
+ capture: !1,
974
+ once: !1,
975
+ passive: !1,
976
+ ...e
977
+ };
978
+ }
979
+ optionsMatch(e, t) {
980
+ return e.capture === t.capture;
981
+ }
982
+ on(e, t, n) {
983
+ this.addEventListener(e, t, n);
984
+ }
985
+ off(e, t, n) {
986
+ this.removeEventListener(e, t, n);
987
+ }
988
+ once(e, t, n) {
989
+ let r = typeof n == "boolean" ? {
990
+ capture: n,
991
+ once: !0
992
+ } : {
993
+ ...n,
994
+ once: !0
995
+ };
996
+ this.addEventListener(e, t, r);
997
+ }
998
+ emit(e, t) {
999
+ let n = new CustomEvent(e, { detail: t });
1000
+ return this.dispatchEvent(n);
1001
+ }
1002
+ getEventTypes() {
1003
+ return Array.from(this.listeners.keys());
1004
+ }
1005
+ removeAllListeners(e) {
1006
+ e ? this.listeners.delete(e) : this.listeners.clear();
1007
+ }
1008
+ }, isIgnored = (e) => e == null || typeof e == "number" && isNaN(e) || typeof e == "function";
1009
+ function createQueryParams(e) {
1010
+ let t = new URLSearchParams(), appendNested = (e, n) => {
1011
+ isIgnored(n) || (typeof n == "object" && t.append(e, JSON.stringify(n)), t.append(e, String(n)));
1012
+ };
1013
+ for (let [n, r] of Object.entries(e)) if (!isIgnored(r)) {
1014
+ if (typeof r == "string") t.append(n, String(r));
1015
+ else if (Array.isArray(r)) for (let e of r) appendNested(`${n}[]`, e);
1016
+ else appendNested(n, r);
1017
+ }
1018
+ return t;
1019
+ }
1020
+ // src/client.ts
1021
+ var R = /^(?<name>\w+?)\s(?<method>get|post|put|patch|delete)\s+(?<url>\/.*)/i, ShopwareClient = class extends EventEmitter {
1022
+ options = {
1023
+ baseURL: "",
1024
+ apiKey: "",
1025
+ language: "",
1026
+ contextToken: "",
1027
+ includeSeoUrls: !1,
1028
+ reflectContextToken: !0,
1029
+ headers: {}
1030
+ };
1031
+ constructor(e) {
1032
+ super(), this.requestInitDefaults = e.requestInitDefaults, this.baseURL = e.baseURL ?? this.options.baseURL, this.apiKey = e.apiKey ?? this.options.apiKey, this.language = e.language ?? this.options.language, this.contextToken = e.contextToken ?? this.options.contextToken, this.includeSeoUrls = e.includeSeoUrls ?? this.options.includeSeoUrls, this.reflectContextToken = e.reflectContextToken ?? this.options.reflectContextToken, this.headers = e.headers ?? this.options.headers, this.queryClientId = e.queryClientId ?? this.options.queryClientId;
1033
+ }
1034
+ set requestInitDefaults(e) {
1035
+ this.options.requestInitDefaults = e;
1036
+ }
1037
+ get requestInitDefaults() {
1038
+ return this.options.requestInitDefaults;
1039
+ }
1040
+ set baseURL(e) {
1041
+ if (typeof e != "string") throw Error("Invalid baseURL: It must be a string.");
1042
+ this.options.baseURL = e;
1043
+ }
1044
+ get baseURL() {
1045
+ return this.options.baseURL;
1046
+ }
1047
+ set apiKey(e) {
1048
+ if (typeof e != "string") throw Error("Invalid apiKey: It must be a string.");
1049
+ this.options.apiKey = e;
1050
+ }
1051
+ get apiKey() {
1052
+ return this.options.apiKey;
1053
+ }
1054
+ set language(e) {
1055
+ if (e && typeof e != "string") throw Error("Invalid language: If provided, it must be a string.");
1056
+ this.options.language = e;
1057
+ }
1058
+ get language() {
1059
+ return this.options.language;
1060
+ }
1061
+ set contextToken(e) {
1062
+ if (e && typeof e != "string") throw Error("Invalid contextToken: If provided, it must be a string.");
1063
+ this.options.contextToken = e, this.emit("contextToken", e);
1064
+ }
1065
+ get contextToken() {
1066
+ return this.options.contextToken;
1067
+ }
1068
+ set includeSeoUrls(e) {
1069
+ this.options.includeSeoUrls = e;
1070
+ }
1071
+ get includeSeoUrls() {
1072
+ return this.options.includeSeoUrls;
1073
+ }
1074
+ set reflectContextToken(e) {
1075
+ this.options.reflectContextToken = e;
1076
+ }
1077
+ get reflectContextToken() {
1078
+ return this.options.reflectContextToken;
1079
+ }
1080
+ set headers(e) {
1081
+ this.options.headers = e;
1082
+ }
1083
+ get headers() {
1084
+ return this.options.headers;
1085
+ }
1086
+ set queryClientId(e) {
1087
+ if (e && typeof e != "string") throw Error("Invalid queryClientId: If provided, it must be a string.");
1088
+ this.options.queryClientId = e;
1089
+ }
1090
+ get queryClientId() {
1091
+ return this.options.queryClientId;
1092
+ }
1093
+ parseOperation(e) {
1094
+ let t = R.exec(e);
1095
+ if (!t?.groups) throw Error("Invalid operation format");
1096
+ return {
1097
+ name: t.groups.name,
1098
+ method: t.groups.method.toUpperCase(),
1099
+ url: t.groups.url
1100
+ };
1101
+ }
1102
+ interpolateUrl(e, t) {
1103
+ return e.replace(/{([^}]+?)}/g, (e, n) => {
1104
+ if (!(n in t)) throw Error(`Missing required URL parameter: ${n}`);
1105
+ return t[n];
1106
+ });
1107
+ }
1108
+ async queryRaw(e, t) {
1109
+ let n;
1110
+ try {
1111
+ let { method: r, url: i } = this.parseOperation(e), a = this.interpolateUrl(i, t?.params ?? {}), o = t?.query ? `?${createQueryParams(t.query)}` : "";
1112
+ n = await fetch(`${this.baseURL}/store-api${a}${o}`, {
1113
+ ...this.requestInitDefaults,
1114
+ ...t,
1115
+ method: r,
1116
+ headers: {
1117
+ "Content-Type": "application/json",
1118
+ "sw-access-key": this.apiKey,
1119
+ ...this.requestInitDefaults?.headers,
1120
+ ...this.contextToken && { "sw-context-token": this.contextToken },
1121
+ ...this.includeSeoUrls && { "sw-include-seo-urls": "true" },
1122
+ ...this.language && { "sw-language-id": this.language },
1123
+ ...this.headers,
1124
+ ...t?.headers
1125
+ },
1126
+ body: t?.body ? JSON.stringify(t.body) : void 0
1127
+ });
1128
+ } catch (e) {
1129
+ let t = new ShopwareApiError("Failed to communicate with Shopware API", 500, e instanceof Error ? e.message : void 0);
1130
+ throw this.emit("error", t), t;
1131
+ }
1132
+ if (!n.ok) {
1133
+ let e = new ShopwareApiError(`Shopware API request failed: ${n.statusText}`, n.status, await n.json().catch(() => void 0));
1134
+ throw this.emit("error", e), e;
1135
+ }
1136
+ if (this.options.reflectContextToken) {
1137
+ let e = n.headers.get("sw-context-token");
1138
+ e && (this.contextToken = e);
1139
+ }
1140
+ return n;
1141
+ }
1142
+ async query(e, t) {
1143
+ return (await this.queryRaw(e, t)).json().catch(() => void 0);
1144
+ }
277
1145
  };
1146
+ export { ShopwareApiError, ShopwareClient };