@teamnovu/kit-shopware-api-client 0.0.10 → 0.0.11
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 +111 -105
- package/package.json +1 -4
- package/vite.config.js +4 -9
package/dist/index.mjs
CHANGED
|
@@ -1,130 +1,134 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
var y = Object.defineProperty;
|
|
2
|
+
var x = (i, s, e) => s in i ? y(i, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[s] = e;
|
|
3
|
+
var c = (i, s) => y(i, "name", { value: s, configurable: !0 });
|
|
4
|
+
var u = (i, s, e) => x(i, typeof s != "symbol" ? s + "" : s, e);
|
|
5
|
+
import { z as o } from "zod";
|
|
6
|
+
const k = o.object({
|
|
7
|
+
status: o.string(),
|
|
8
|
+
code: o.string(),
|
|
9
|
+
title: o.string().optional(),
|
|
10
|
+
detail: o.string().optional(),
|
|
11
|
+
meta: o.record(o.unknown()).optional(),
|
|
12
|
+
source: o.object({
|
|
13
|
+
pointer: o.string().optional()
|
|
13
14
|
}).optional(),
|
|
14
|
-
trace:
|
|
15
|
-
|
|
16
|
-
file:
|
|
17
|
-
line:
|
|
18
|
-
function:
|
|
15
|
+
trace: o.array(
|
|
16
|
+
o.object({
|
|
17
|
+
file: o.string(),
|
|
18
|
+
line: o.number(),
|
|
19
|
+
function: o.string()
|
|
19
20
|
})
|
|
20
21
|
).optional()
|
|
21
|
-
}),
|
|
22
|
-
errors:
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
constructor(e, t, n) {
|
|
22
|
+
}), U = o.object({
|
|
23
|
+
errors: o.array(k)
|
|
24
|
+
}), f = class f extends Error {
|
|
25
|
+
constructor(e, t, r) {
|
|
26
26
|
super(e);
|
|
27
|
-
|
|
28
|
-
this.status = t, this.response =
|
|
29
|
-
const { success:
|
|
30
|
-
this.errors =
|
|
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
31
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
32
|
+
};
|
|
33
|
+
c(f, "ShopwareApiError");
|
|
34
|
+
let h = f;
|
|
35
|
+
const d = class d {
|
|
34
36
|
constructor() {
|
|
35
|
-
|
|
37
|
+
u(this, "listeners", /* @__PURE__ */ new Map());
|
|
36
38
|
}
|
|
37
|
-
addEventListener(
|
|
39
|
+
addEventListener(s, e, t) {
|
|
38
40
|
if (!e) return;
|
|
39
|
-
const
|
|
41
|
+
const r = this.normalizeOptions(t), n = {
|
|
40
42
|
listener: e,
|
|
41
|
-
options:
|
|
43
|
+
options: r
|
|
42
44
|
};
|
|
43
|
-
if (
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
this.removeEventListener(
|
|
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);
|
|
47
49
|
}, { once: !0 });
|
|
48
50
|
}
|
|
49
|
-
this.listeners.has(
|
|
51
|
+
this.listeners.has(s) || this.listeners.set(s, []), this.listeners.get(s).push(n);
|
|
50
52
|
}
|
|
51
|
-
removeEventListener(
|
|
53
|
+
removeEventListener(s, e, t) {
|
|
52
54
|
if (!e) return;
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
55
|
-
const
|
|
56
|
-
a !== -1 && (
|
|
57
|
-
}
|
|
58
|
-
dispatchEvent(
|
|
59
|
-
var
|
|
60
|
-
const e = this.listeners.get(
|
|
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);
|
|
61
63
|
if (!e || e.length === 0) return !0;
|
|
62
64
|
const t = [...e];
|
|
63
|
-
for (const
|
|
64
|
-
if (!((
|
|
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))
|
|
65
67
|
break;
|
|
66
|
-
return !
|
|
68
|
+
return !s.defaultPrevented;
|
|
67
69
|
}
|
|
68
|
-
normalizeOptions(
|
|
69
|
-
return typeof
|
|
70
|
+
normalizeOptions(s) {
|
|
71
|
+
return typeof s == "boolean" ? { capture: s } : {
|
|
70
72
|
capture: !1,
|
|
71
73
|
once: !1,
|
|
72
74
|
passive: !1,
|
|
73
|
-
...
|
|
75
|
+
...s
|
|
74
76
|
};
|
|
75
77
|
}
|
|
76
|
-
optionsMatch(
|
|
77
|
-
return
|
|
78
|
+
optionsMatch(s, e) {
|
|
79
|
+
return s.capture === e.capture;
|
|
78
80
|
}
|
|
79
81
|
// Utility methods for easier usage
|
|
80
|
-
on(
|
|
81
|
-
this.addEventListener(
|
|
82
|
+
on(s, e, t) {
|
|
83
|
+
this.addEventListener(s, e, t);
|
|
82
84
|
}
|
|
83
|
-
off(
|
|
84
|
-
this.removeEventListener(
|
|
85
|
+
off(s, e, t) {
|
|
86
|
+
this.removeEventListener(s, e, t);
|
|
85
87
|
}
|
|
86
|
-
once(
|
|
87
|
-
const
|
|
88
|
+
once(s, e, t) {
|
|
89
|
+
const r = typeof t == "boolean" ? {
|
|
88
90
|
capture: t,
|
|
89
91
|
once: !0
|
|
90
92
|
} : {
|
|
91
93
|
...t,
|
|
92
94
|
once: !0
|
|
93
95
|
};
|
|
94
|
-
this.addEventListener(
|
|
96
|
+
this.addEventListener(s, e, r);
|
|
95
97
|
}
|
|
96
|
-
emit(
|
|
97
|
-
const t = new CustomEvent(
|
|
98
|
+
emit(s, e) {
|
|
99
|
+
const t = new CustomEvent(s, { detail: e });
|
|
98
100
|
return this.dispatchEvent(t);
|
|
99
101
|
}
|
|
100
102
|
getEventTypes() {
|
|
101
103
|
return Array.from(this.listeners.keys());
|
|
102
104
|
}
|
|
103
|
-
removeAllListeners(
|
|
104
|
-
|
|
105
|
+
removeAllListeners(s) {
|
|
106
|
+
s ? this.listeners.delete(s) : this.listeners.clear();
|
|
105
107
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
};
|
|
109
|
+
c(d, "EventEmitter");
|
|
110
|
+
let p = d;
|
|
111
|
+
const m = /* @__PURE__ */ c((i) => i == null || typeof i == "number" && isNaN(i) || typeof i == "function", "isIgnored");
|
|
112
|
+
function T(i) {
|
|
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(i))
|
|
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);
|
|
119
123
|
else
|
|
120
|
-
e(t,
|
|
121
|
-
return
|
|
124
|
+
e(t, r);
|
|
125
|
+
return s;
|
|
122
126
|
}
|
|
123
|
-
|
|
124
|
-
class
|
|
127
|
+
c(T, "createQueryParams");
|
|
128
|
+
const v = /^(?<name>\w+?)\s(?<method>get|post|put|patch|delete)\s+(?<url>\/.*)/i, g = class g extends p {
|
|
125
129
|
constructor(e) {
|
|
126
130
|
super();
|
|
127
|
-
|
|
131
|
+
u(this, "options", {
|
|
128
132
|
baseURL: "",
|
|
129
133
|
apiKey: "",
|
|
130
134
|
language: "",
|
|
@@ -179,7 +183,7 @@ class k extends m {
|
|
|
179
183
|
return this.options.reflectContextToken;
|
|
180
184
|
}
|
|
181
185
|
parseOperation(e) {
|
|
182
|
-
const t =
|
|
186
|
+
const t = v.exec(e);
|
|
183
187
|
if (!(t != null && t.groups))
|
|
184
188
|
throw new Error("Invalid operation format");
|
|
185
189
|
return {
|
|
@@ -189,19 +193,19 @@ class k extends m {
|
|
|
189
193
|
};
|
|
190
194
|
}
|
|
191
195
|
interpolateUrl(e, t) {
|
|
192
|
-
return e.replace(/{([^}]+?)}/g, (
|
|
193
|
-
if (!(
|
|
194
|
-
throw new Error(`Missing required URL parameter: ${
|
|
195
|
-
return t[
|
|
196
|
+
return e.replace(/{([^}]+?)}/g, (r, n) => {
|
|
197
|
+
if (!(n in t))
|
|
198
|
+
throw new Error(`Missing required URL parameter: ${n}`);
|
|
199
|
+
return t[n];
|
|
196
200
|
});
|
|
197
201
|
}
|
|
198
202
|
async queryRaw(e, t) {
|
|
199
|
-
let
|
|
203
|
+
let r;
|
|
200
204
|
try {
|
|
201
|
-
const { method:
|
|
202
|
-
|
|
205
|
+
const { method: n, url: a } = this.parseOperation(e), l = this.interpolateUrl(a, (t == null ? void 0 : t.params) ?? {}), b = t != null && t.query ? `?${T(t.query)}` : "";
|
|
206
|
+
r = await fetch(`${this.options.baseURL}/store-api${l}${b}`, {
|
|
203
207
|
...t,
|
|
204
|
-
method:
|
|
208
|
+
method: n,
|
|
205
209
|
headers: {
|
|
206
210
|
"Content-Type": "application/json",
|
|
207
211
|
"sw-access-key": this.options.apiKey,
|
|
@@ -212,35 +216,37 @@ class k extends m {
|
|
|
212
216
|
},
|
|
213
217
|
body: t != null && t.body ? JSON.stringify(t.body) : void 0
|
|
214
218
|
});
|
|
215
|
-
} catch (
|
|
219
|
+
} catch (n) {
|
|
216
220
|
const a = new h(
|
|
217
221
|
"Failed to communicate with Shopware API",
|
|
218
222
|
500,
|
|
219
|
-
|
|
223
|
+
n instanceof Error ? n.message : void 0
|
|
220
224
|
);
|
|
221
225
|
throw this.emit("error", a), a;
|
|
222
226
|
}
|
|
223
|
-
if (!
|
|
224
|
-
const
|
|
225
|
-
`Shopware API request failed: ${
|
|
226
|
-
|
|
227
|
-
await
|
|
227
|
+
if (!r.ok) {
|
|
228
|
+
const n = new h(
|
|
229
|
+
`Shopware API request failed: ${r.statusText}`,
|
|
230
|
+
r.status,
|
|
231
|
+
await r.json().catch(() => {
|
|
228
232
|
})
|
|
229
233
|
);
|
|
230
|
-
throw this.emit("error",
|
|
234
|
+
throw this.emit("error", n), n;
|
|
231
235
|
}
|
|
232
236
|
if (this.options.reflectContextToken) {
|
|
233
|
-
const
|
|
234
|
-
|
|
237
|
+
const n = r.headers.get("sw-context-token");
|
|
238
|
+
n && (this.contextToken = n);
|
|
235
239
|
}
|
|
236
|
-
return
|
|
240
|
+
return r;
|
|
237
241
|
}
|
|
238
242
|
async query(e, t) {
|
|
239
243
|
return (await this.queryRaw(e, t)).json().catch(() => {
|
|
240
244
|
});
|
|
241
245
|
}
|
|
242
|
-
}
|
|
246
|
+
};
|
|
247
|
+
c(g, "ShopwareClient");
|
|
248
|
+
let w = g;
|
|
243
249
|
export {
|
|
244
250
|
h as ShopwareApiError,
|
|
245
|
-
|
|
251
|
+
w as ShopwareClient
|
|
246
252
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnovu/kit-shopware-api-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "A client for the Shopware API",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -11,9 +11,6 @@
|
|
|
11
11
|
"import": "./dist/index.mjs"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"vue": "^3.0.0"
|
|
16
|
-
},
|
|
17
14
|
"repository": {
|
|
18
15
|
"type": "git",
|
|
19
16
|
"url": "git+ssh://git@github.com:teamnovu/kit.git"
|
package/vite.config.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import vue from '@vitejs/plugin-vue'
|
|
2
1
|
import { resolve } from 'path'
|
|
3
2
|
import { defineConfig } from 'vite'
|
|
4
3
|
import dts from 'vite-plugin-dts'
|
|
5
4
|
import pkg from './package.json'
|
|
6
5
|
|
|
7
6
|
export default defineConfig({
|
|
8
|
-
plugins: [
|
|
7
|
+
plugins: [dts()],
|
|
9
8
|
root: resolve(__dirname),
|
|
9
|
+
esbuild: {
|
|
10
|
+
keepNames: true,
|
|
11
|
+
},
|
|
10
12
|
build: {
|
|
11
13
|
emptyOutDir: false,
|
|
12
14
|
lib: {
|
|
@@ -20,13 +22,6 @@ export default defineConfig({
|
|
|
20
22
|
// make sure to externalize deps that shouldn't be bundled
|
|
21
23
|
// into your library
|
|
22
24
|
external: ['vue', ...Object.keys(pkg.dependencies ?? {})],
|
|
23
|
-
output: {
|
|
24
|
-
// Provide global variables to use in the UMD build
|
|
25
|
-
// for externalized deps
|
|
26
|
-
globals: {
|
|
27
|
-
vue: 'Vue',
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
25
|
},
|
|
31
26
|
},
|
|
32
27
|
})
|