@teamnovu/kit-shopware-api-client 0.0.14 → 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 +9 -0
- package/dist/client.d.ts +2 -0
- package/dist/error.d.ts +3 -43
- package/dist/index.mjs +227 -267
- package/dist/types.d.ts +6 -0
- package/package.json +12 -3
- package/docs/index.md +0 -161
- package/docs/info.json +0 -3
- package/src/client.ts +0 -223
- package/src/error.ts +0 -42
- package/src/eventEmitter.ts +0 -159
- package/src/index.ts +0 -3
- package/src/query.ts +0 -39
- package/src/types.ts +0 -62
- package/tsconfig.json +0 -12
- package/vite.config.js +0 -27
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/client.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export declare class ShopwareClient<Operations> extends EventEmitter {
|
|
|
25
25
|
get reflectContextToken(): boolean | undefined;
|
|
26
26
|
set headers(headers: HeadersInit | undefined);
|
|
27
27
|
get headers(): HeadersInit | undefined;
|
|
28
|
+
set queryClientId(queryClientId: string | undefined);
|
|
29
|
+
get queryClientId(): string | undefined;
|
|
28
30
|
private parseOperation;
|
|
29
31
|
private interpolateUrl;
|
|
30
32
|
queryRaw<OperationKey extends (keyof Operations) & string>(operation: OperationKey, options?: OperationOptions<Operations, OperationKey>): Promise<Response>;
|
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
|
-
},
|
|
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
|
-
},
|
|
20
|
-
|
|
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,269 +1,229 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
l(p, "EventEmitter");
|
|
110
|
-
let f = p;
|
|
111
|
-
const m = /* @__PURE__ */ l((o) => o == null || typeof o == "number" && isNaN(o) || typeof o == "function", "isIgnored");
|
|
112
|
-
function I(o) {
|
|
113
|
-
const s = new URLSearchParams(), e = /* @__PURE__ */ l((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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
if (this.options.reflectContextToken) {
|
|
254
|
-
const a = r.headers.get("sw-context-token");
|
|
255
|
-
a && (this.contextToken = a);
|
|
256
|
-
}
|
|
257
|
-
return r;
|
|
258
|
-
}
|
|
259
|
-
async query(e, t) {
|
|
260
|
-
return (await this.queryRaw(e, t)).json().catch(() => {
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
l(g, "ShopwareClient");
|
|
265
|
-
let w = g;
|
|
266
|
-
export {
|
|
267
|
-
u as ShopwareApiError,
|
|
268
|
-
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
|
+
}
|
|
269
228
|
};
|
|
229
|
+
export { ShopwareApiError, ShopwareClient };
|
package/dist/types.d.ts
CHANGED
|
@@ -38,5 +38,11 @@ export interface ShopwareClientOptions {
|
|
|
38
38
|
* @default undefined
|
|
39
39
|
*/
|
|
40
40
|
contextToken?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The vue-query queryClientKey of the QueryClient that holds all queries
|
|
43
|
+
* made through this client. If not set, the default QueryClient is used.
|
|
44
|
+
* @default undefined
|
|
45
|
+
*/
|
|
46
|
+
queryClientId?: string;
|
|
41
47
|
}
|
|
42
48
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnovu/kit-shopware-api-client",
|
|
3
|
-
"version": "0.0
|
|
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": "^
|
|
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
|
}
|