@teamnovu/kit-shopware-api-client 0.0.15 → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0](https://github.com/teamnovu/kit/compare/kit-shopware-api-client-v0.0.15...kit-shopware-api-client-v0.1.0) (2026-11-12)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **deps:** update zod to 4 in shopware-api-client ([6e2aa75](https://github.com/teamnovu/kit/commit/6e2aa7557176f54aa1619d88d2193f3cb47f42e1))
9
+ * publish only the build output ([ca77ca3](https://github.com/teamnovu/kit/commit/ca77ca3299c60bcb9c71927afbf8a7b8396d1804))
package/dist/error.d.ts CHANGED
@@ -7,53 +7,13 @@ declare const shopwareErrorSchema: z.ZodObject<{
7
7
  meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
8
8
  source: z.ZodOptional<z.ZodObject<{
9
9
  pointer: z.ZodOptional<z.ZodString>;
10
- }, "strip", z.ZodTypeAny, {
11
- pointer?: string | undefined;
12
- }, {
13
- pointer?: string | undefined;
14
- }>>;
10
+ }, z.core.$strip>>;
15
11
  trace: z.ZodOptional<z.ZodArray<z.ZodObject<{
16
12
  file: z.ZodString;
17
13
  line: z.ZodNumber;
18
14
  function: z.ZodString;
19
- }, "strip", z.ZodTypeAny, {
20
- function: string;
21
- file: string;
22
- line: number;
23
- }, {
24
- function: string;
25
- file: string;
26
- line: number;
27
- }>, "many">>;
28
- }, "strip", z.ZodTypeAny, {
29
- status: string;
30
- code: string;
31
- title?: string | undefined;
32
- detail?: string | undefined;
33
- meta?: Record<string, unknown> | undefined;
34
- source?: {
35
- pointer?: string | undefined;
36
- } | undefined;
37
- trace?: {
38
- function: string;
39
- file: string;
40
- line: number;
41
- }[] | undefined;
42
- }, {
43
- status: string;
44
- code: string;
45
- title?: string | undefined;
46
- detail?: string | undefined;
47
- meta?: Record<string, unknown> | undefined;
48
- source?: {
49
- pointer?: string | undefined;
50
- } | undefined;
51
- trace?: {
52
- function: string;
53
- file: string;
54
- line: number;
55
- }[] | undefined;
56
- }>;
15
+ }, z.core.$strip>>>;
16
+ }, z.core.$strip>;
57
17
  export type ShopwareError = z.infer<typeof shopwareErrorSchema>;
58
18
  export declare class ShopwareApiError extends Error {
59
19
  readonly status: number;
package/dist/index.mjs CHANGED
@@ -1,277 +1,229 @@
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
- }
32
- };
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
- }
108
- };
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;
1
+ import { z as e } from "zod";
2
+ // \0rolldown/runtime.js
3
+ var t = e.object({
4
+ status: e.string(),
5
+ code: e.string(),
6
+ title: e.string().optional(),
7
+ detail: e.string().optional(),
8
+ meta: e.record(e.string(), e.unknown()).optional(),
9
+ source: e.object({ pointer: e.string().optional() }).optional(),
10
+ trace: e.array(e.object({
11
+ file: e.string(),
12
+ line: e.number(),
13
+ function: e.string()
14
+ })).optional()
15
+ }), n = e.object({ errors: e.array(t) }), ShopwareApiError = class extends Error {
16
+ status;
17
+ response;
18
+ errors;
19
+ constructor(e, t, r) {
20
+ super(e), this.status = t, this.response = r, this.name = "ShopwareApiError";
21
+ let { success: i, data: a } = n.safeParse(r);
22
+ this.errors = i ? a.errors : [];
23
+ }
24
+ }, EventEmitter = class {
25
+ listeners = /* @__PURE__ */ new Map();
26
+ addEventListener(e, t, n) {
27
+ if (!t) return;
28
+ let r = this.normalizeOptions(n), i = {
29
+ listener: t,
30
+ options: r
31
+ };
32
+ if (r.signal) {
33
+ if (r.signal.aborted) return;
34
+ i.signal = r.signal, r.signal.addEventListener("abort", () => {
35
+ this.removeEventListener(e, t, n);
36
+ }, { once: !0 });
37
+ }
38
+ this.listeners.has(e) || this.listeners.set(e, []), this.listeners.get(e).push(i);
39
+ }
40
+ removeEventListener(e, t, n) {
41
+ if (!t) return;
42
+ let r = this.listeners.get(e);
43
+ if (!r) return;
44
+ let i = this.normalizeOptions(n), a = r.findIndex((e) => e.listener === t && this.optionsMatch(e.options, i));
45
+ a !== -1 && (r.splice(a, 1), r.length === 0 && this.listeners.delete(e));
46
+ }
47
+ dispatchEvent(e) {
48
+ let t = this.listeners.get(e.type);
49
+ if (!t || t.length === 0) return !0;
50
+ let n = [...t];
51
+ 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;
52
+ return !e.defaultPrevented;
53
+ }
54
+ normalizeOptions(e) {
55
+ return typeof e == "boolean" ? { capture: e } : {
56
+ capture: !1,
57
+ once: !1,
58
+ passive: !1,
59
+ ...e
60
+ };
61
+ }
62
+ optionsMatch(e, t) {
63
+ return e.capture === t.capture;
64
+ }
65
+ on(e, t, n) {
66
+ this.addEventListener(e, t, n);
67
+ }
68
+ off(e, t, n) {
69
+ this.removeEventListener(e, t, n);
70
+ }
71
+ once(e, t, n) {
72
+ let r = typeof n == "boolean" ? {
73
+ capture: n,
74
+ once: !0
75
+ } : {
76
+ ...n,
77
+ once: !0
78
+ };
79
+ this.addEventListener(e, t, r);
80
+ }
81
+ emit(e, t) {
82
+ let n = new CustomEvent(e, { detail: t });
83
+ return this.dispatchEvent(n);
84
+ }
85
+ getEventTypes() {
86
+ return Array.from(this.listeners.keys());
87
+ }
88
+ removeAllListeners(e) {
89
+ e ? this.listeners.delete(e) : this.listeners.clear();
90
+ }
91
+ }, isIgnored = (e) => e == null || typeof e == "number" && isNaN(e) || typeof e == "function";
92
+ function createQueryParams(e) {
93
+ let t = new URLSearchParams(), appendNested = (e, n) => {
94
+ isIgnored(n) || (typeof n == "object" && t.append(e, JSON.stringify(n)), t.append(e, String(n)));
95
+ };
96
+ for (let [n, r] of Object.entries(e)) if (!isIgnored(r)) {
97
+ if (typeof r == "string") t.append(n, String(r));
98
+ else if (Array.isArray(r)) for (let e of r) appendNested(`${n}[]`, e);
99
+ else appendNested(n, r);
100
+ }
101
+ return t;
126
102
  }
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
- }
271
- };
272
- c(g, "ShopwareClient");
273
- let w = g;
274
- export {
275
- h as ShopwareApiError,
276
- w as ShopwareClient
103
+ // src/client.ts
104
+ var r = /^(?<name>\w+?)\s(?<method>get|post|put|patch|delete)\s+(?<url>\/.*)/i, ShopwareClient = class extends EventEmitter {
105
+ options = {
106
+ baseURL: "",
107
+ apiKey: "",
108
+ language: "",
109
+ contextToken: "",
110
+ includeSeoUrls: !1,
111
+ reflectContextToken: !0,
112
+ headers: {}
113
+ };
114
+ constructor(e) {
115
+ 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;
116
+ }
117
+ set requestInitDefaults(e) {
118
+ this.options.requestInitDefaults = e;
119
+ }
120
+ get requestInitDefaults() {
121
+ return this.options.requestInitDefaults;
122
+ }
123
+ set baseURL(e) {
124
+ if (typeof e != "string") throw Error("Invalid baseURL: It must be a string.");
125
+ this.options.baseURL = e;
126
+ }
127
+ get baseURL() {
128
+ return this.options.baseURL;
129
+ }
130
+ set apiKey(e) {
131
+ if (typeof e != "string") throw Error("Invalid apiKey: It must be a string.");
132
+ this.options.apiKey = e;
133
+ }
134
+ get apiKey() {
135
+ return this.options.apiKey;
136
+ }
137
+ set language(e) {
138
+ if (e && typeof e != "string") throw Error("Invalid language: If provided, it must be a string.");
139
+ this.options.language = e;
140
+ }
141
+ get language() {
142
+ return this.options.language;
143
+ }
144
+ set contextToken(e) {
145
+ if (e && typeof e != "string") throw Error("Invalid contextToken: If provided, it must be a string.");
146
+ this.options.contextToken = e, this.emit("contextToken", e);
147
+ }
148
+ get contextToken() {
149
+ return this.options.contextToken;
150
+ }
151
+ set includeSeoUrls(e) {
152
+ this.options.includeSeoUrls = e;
153
+ }
154
+ get includeSeoUrls() {
155
+ return this.options.includeSeoUrls;
156
+ }
157
+ set reflectContextToken(e) {
158
+ this.options.reflectContextToken = e;
159
+ }
160
+ get reflectContextToken() {
161
+ return this.options.reflectContextToken;
162
+ }
163
+ set headers(e) {
164
+ this.options.headers = e;
165
+ }
166
+ get headers() {
167
+ return this.options.headers;
168
+ }
169
+ set queryClientId(e) {
170
+ if (e && typeof e != "string") throw Error("Invalid queryClientId: If provided, it must be a string.");
171
+ this.options.queryClientId = e;
172
+ }
173
+ get queryClientId() {
174
+ return this.options.queryClientId;
175
+ }
176
+ parseOperation(e) {
177
+ let t = r.exec(e);
178
+ if (!t?.groups) throw Error("Invalid operation format");
179
+ return {
180
+ name: t.groups.name,
181
+ method: t.groups.method.toUpperCase(),
182
+ url: t.groups.url
183
+ };
184
+ }
185
+ interpolateUrl(e, t) {
186
+ return e.replace(/{([^}]+?)}/g, (e, n) => {
187
+ if (!(n in t)) throw Error(`Missing required URL parameter: ${n}`);
188
+ return t[n];
189
+ });
190
+ }
191
+ async queryRaw(e, t) {
192
+ let n;
193
+ try {
194
+ let { method: r, url: i } = this.parseOperation(e), a = this.interpolateUrl(i, t?.params ?? {}), o = t?.query ? `?${createQueryParams(t.query)}` : "";
195
+ n = await fetch(`${this.baseURL}/store-api${a}${o}`, {
196
+ ...this.requestInitDefaults,
197
+ ...t,
198
+ method: r,
199
+ headers: {
200
+ "Content-Type": "application/json",
201
+ "sw-access-key": this.apiKey,
202
+ ...this.requestInitDefaults?.headers,
203
+ ...this.contextToken && { "sw-context-token": this.contextToken },
204
+ ...this.includeSeoUrls && { "sw-include-seo-urls": "true" },
205
+ ...this.language && { "sw-language-id": this.language },
206
+ ...this.headers,
207
+ ...t?.headers
208
+ },
209
+ body: t?.body ? JSON.stringify(t.body) : void 0
210
+ });
211
+ } catch (e) {
212
+ let t = new ShopwareApiError("Failed to communicate with Shopware API", 500, e instanceof Error ? e.message : void 0);
213
+ throw this.emit("error", t), t;
214
+ }
215
+ if (!n.ok) {
216
+ let e = new ShopwareApiError(`Shopware API request failed: ${n.statusText}`, n.status, await n.json().catch(() => void 0));
217
+ throw this.emit("error", e), e;
218
+ }
219
+ if (this.options.reflectContextToken) {
220
+ let e = n.headers.get("sw-context-token");
221
+ e && (this.contextToken = e);
222
+ }
223
+ return n;
224
+ }
225
+ async query(e, t) {
226
+ return (await this.queryRaw(e, t)).json().catch(() => void 0);
227
+ }
277
228
  };
229
+ export { ShopwareApiError, ShopwareClient };
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@teamnovu/kit-shopware-api-client",
3
- "version": "0.0.15",
3
+ "version": "0.1.0",
4
4
  "description": "A client for the Shopware API",
5
+ "files": [
6
+ "dist",
7
+ "CHANGELOG.md"
8
+ ],
5
9
  "main": "dist/index.mjs",
6
10
  "module": "dist/index.mjs",
7
11
  "types": "dist/index.d.ts",
@@ -19,11 +23,16 @@
19
23
  "author": "Elias Bernhaut",
20
24
  "homepage": "https://kit.novu.ch/packages/shopware-api-client/",
21
25
  "dependencies": {
22
- "zod": "^3.25.67"
26
+ "zod": "^4.6.7"
27
+ },
28
+ "devDependencies": {
29
+ "vitest": "^5.1.0"
23
30
  },
24
31
  "scripts": {
25
32
  "build": "vite build",
26
33
  "watch": "NODE_ENV=development vite build --watch",
27
- "lint": "eslint --fix --ignore-pattern 'dist/**' ."
34
+ "lint": "eslint --fix --ignore-pattern 'dist/**' .",
35
+ "typecheck": "vue-tsc --noEmit",
36
+ "test": "vitest run"
28
37
  }
29
38
  }