@teamnovu/kit-shopware-api-client 0.0.14 → 0.0.15
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/client.d.ts +2 -0
- package/dist/index.mjs +37 -29
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
- package/src/client.ts +13 -0
- package/src/types.ts +7 -0
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/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var y = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
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
5
|
import { z as i } from "zod";
|
|
6
|
-
const
|
|
6
|
+
const k = i.object({
|
|
7
7
|
status: i.string(),
|
|
8
8
|
code: i.string(),
|
|
9
9
|
title: i.string().optional(),
|
|
@@ -19,22 +19,22 @@ const U = i.object({
|
|
|
19
19
|
function: i.string()
|
|
20
20
|
})
|
|
21
21
|
).optional()
|
|
22
|
-
}),
|
|
23
|
-
errors: i.array(
|
|
24
|
-
}),
|
|
22
|
+
}), U = i.object({
|
|
23
|
+
errors: i.array(k)
|
|
24
|
+
}), f = class f extends Error {
|
|
25
25
|
constructor(e, t, r) {
|
|
26
26
|
super(e);
|
|
27
|
-
|
|
27
|
+
u(this, "errors");
|
|
28
28
|
this.status = t, this.response = r, this.name = "ShopwareApiError";
|
|
29
|
-
const { success: n, data: a } =
|
|
29
|
+
const { success: n, data: a } = U.safeParse(r);
|
|
30
30
|
this.errors = n ? a.errors : [];
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
-
|
|
34
|
-
let
|
|
33
|
+
c(f, "ShopwareApiError");
|
|
34
|
+
let h = f;
|
|
35
35
|
const p = class p {
|
|
36
36
|
constructor() {
|
|
37
|
-
|
|
37
|
+
u(this, "listeners", /* @__PURE__ */ new Map());
|
|
38
38
|
}
|
|
39
39
|
addEventListener(s, e, t) {
|
|
40
40
|
if (!e) return;
|
|
@@ -54,7 +54,7 @@ const p = class p {
|
|
|
54
54
|
if (!e) return;
|
|
55
55
|
const r = this.listeners.get(s);
|
|
56
56
|
if (!r) return;
|
|
57
|
-
const n = this.normalizeOptions(t), a = r.findIndex((
|
|
57
|
+
const n = this.normalizeOptions(t), a = r.findIndex((l) => l.listener === e && this.optionsMatch(l.options, n));
|
|
58
58
|
a !== -1 && (r.splice(a, 1), r.length === 0 && this.listeners.delete(s));
|
|
59
59
|
}
|
|
60
60
|
dispatchEvent(s) {
|
|
@@ -106,11 +106,11 @@ const p = class p {
|
|
|
106
106
|
s ? this.listeners.delete(s) : this.listeners.clear();
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
|
-
|
|
110
|
-
let
|
|
111
|
-
const m = /* @__PURE__ */
|
|
112
|
-
function
|
|
113
|
-
const s = new URLSearchParams(), e = /* @__PURE__ */
|
|
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
114
|
m(r) || (typeof r == "object" && s.append(t, JSON.stringify(r)), s.append(t, String(r)));
|
|
115
115
|
}, "appendNested");
|
|
116
116
|
for (const [t, r] of Object.entries(o))
|
|
@@ -124,11 +124,11 @@ function I(o) {
|
|
|
124
124
|
e(t, r);
|
|
125
125
|
return s;
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
const
|
|
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
129
|
constructor(e) {
|
|
130
130
|
super();
|
|
131
|
-
|
|
131
|
+
u(this, "options", {
|
|
132
132
|
baseURL: "",
|
|
133
133
|
apiKey: "",
|
|
134
134
|
language: "",
|
|
@@ -137,7 +137,7 @@ const v = /^(?<name>\w+?)\s(?<method>get|post|put|patch|delete)\s+(?<url>\/.*)/i
|
|
|
137
137
|
reflectContextToken: !0,
|
|
138
138
|
headers: {}
|
|
139
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;
|
|
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
141
|
}
|
|
142
142
|
set requestInitDefaults(e) {
|
|
143
143
|
this.options.requestInitDefaults = e;
|
|
@@ -195,8 +195,16 @@ const v = /^(?<name>\w+?)\s(?<method>get|post|put|patch|delete)\s+(?<url>\/.*)/i
|
|
|
195
195
|
get headers() {
|
|
196
196
|
return this.options.headers;
|
|
197
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
|
+
}
|
|
198
206
|
parseOperation(e) {
|
|
199
|
-
const t =
|
|
207
|
+
const t = T.exec(e);
|
|
200
208
|
if (!(t != null && t.groups))
|
|
201
209
|
throw new Error("Invalid operation format");
|
|
202
210
|
return {
|
|
@@ -216,7 +224,7 @@ const v = /^(?<name>\w+?)\s(?<method>get|post|put|patch|delete)\s+(?<url>\/.*)/i
|
|
|
216
224
|
var n;
|
|
217
225
|
let r;
|
|
218
226
|
try {
|
|
219
|
-
const { method: a, url:
|
|
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)}` : "";
|
|
220
228
|
r = await fetch(`${this.baseURL}/store-api${b}${x}`, {
|
|
221
229
|
...this.requestInitDefaults,
|
|
222
230
|
...t,
|
|
@@ -234,15 +242,15 @@ const v = /^(?<name>\w+?)\s(?<method>get|post|put|patch|delete)\s+(?<url>\/.*)/i
|
|
|
234
242
|
body: t != null && t.body ? JSON.stringify(t.body) : void 0
|
|
235
243
|
});
|
|
236
244
|
} catch (a) {
|
|
237
|
-
const
|
|
245
|
+
const l = new h(
|
|
238
246
|
"Failed to communicate with Shopware API",
|
|
239
247
|
500,
|
|
240
248
|
a instanceof Error ? a.message : void 0
|
|
241
249
|
);
|
|
242
|
-
throw this.emit("error",
|
|
250
|
+
throw this.emit("error", l), l;
|
|
243
251
|
}
|
|
244
252
|
if (!r.ok) {
|
|
245
|
-
const a = new
|
|
253
|
+
const a = new h(
|
|
246
254
|
`Shopware API request failed: ${r.statusText}`,
|
|
247
255
|
r.status,
|
|
248
256
|
await r.json().catch(() => {
|
|
@@ -261,9 +269,9 @@ const v = /^(?<name>\w+?)\s(?<method>get|post|put|patch|delete)\s+(?<url>\/.*)/i
|
|
|
261
269
|
});
|
|
262
270
|
}
|
|
263
271
|
};
|
|
264
|
-
|
|
272
|
+
c(g, "ShopwareClient");
|
|
265
273
|
let w = g;
|
|
266
274
|
export {
|
|
267
|
-
|
|
275
|
+
h as ShopwareApiError,
|
|
268
276
|
w as ShopwareClient
|
|
269
277
|
};
|
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
package/src/client.ts
CHANGED
|
@@ -41,6 +41,7 @@ export class ShopwareClient<Operations> extends EventEmitter {
|
|
|
41
41
|
this.includeSeoUrls = options.includeSeoUrls ?? this.options.includeSeoUrls
|
|
42
42
|
this.reflectContextToken = options.reflectContextToken ?? this.options.reflectContextToken
|
|
43
43
|
this.headers = options.headers ?? this.options.headers
|
|
44
|
+
this.queryClientId = options.queryClientId ?? this.options.queryClientId
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
set requestInitDefaults(defaults: RequestInit | undefined) {
|
|
@@ -124,6 +125,18 @@ export class ShopwareClient<Operations> extends EventEmitter {
|
|
|
124
125
|
return this.options.headers
|
|
125
126
|
}
|
|
126
127
|
|
|
128
|
+
set queryClientId(queryClientId: string | undefined) {
|
|
129
|
+
if (queryClientId && typeof queryClientId !== 'string') {
|
|
130
|
+
throw new Error('Invalid queryClientId: If provided, it must be a string.')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
this.options.queryClientId = queryClientId
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
get queryClientId() {
|
|
137
|
+
return this.options.queryClientId
|
|
138
|
+
}
|
|
139
|
+
|
|
127
140
|
private parseOperation(operation: keyof Operations & string): {
|
|
128
141
|
name: string
|
|
129
142
|
method: string
|
package/src/types.ts
CHANGED
|
@@ -59,4 +59,11 @@ export interface ShopwareClientOptions {
|
|
|
59
59
|
*/
|
|
60
60
|
contextToken?: string
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* The vue-query queryClientKey of the QueryClient that holds all queries
|
|
64
|
+
* made through this client. If not set, the default QueryClient is used.
|
|
65
|
+
* @default undefined
|
|
66
|
+
*/
|
|
67
|
+
queryClientId?: string
|
|
68
|
+
|
|
62
69
|
}
|