@shopware/api-client 1.2.1 → 1.3.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/README.md +43 -2
- package/api-types/storeApiSchema.b2b.overrides.json +33 -0
- package/api-types/storeApiSchema.json +4010 -152
- package/api-types/storeApiSchema.overrides.json +13 -27
- package/api-types/storeApiTypes.d.ts +1516 -23
- package/dist/index.cjs +57 -32
- package/dist/index.d.cts +1532 -24
- package/dist/index.d.mts +1532 -24
- package/dist/index.d.ts +1532 -24
- package/dist/index.mjs +57 -32
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -44,10 +44,7 @@ function createHeaders(init, hookCallback) {
|
|
|
44
44
|
|
|
45
45
|
var __defProp = Object.defineProperty;
|
|
46
46
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
47
|
-
var __publicField = (obj, key, value) =>
|
|
48
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
49
|
-
return value;
|
|
50
|
-
};
|
|
47
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
51
48
|
class ApiClientError extends Error {
|
|
52
49
|
constructor(response) {
|
|
53
50
|
let message = "Failed request";
|
|
@@ -110,7 +107,7 @@ function errorInterceptor(response) {
|
|
|
110
107
|
function createPathWithParams(requestPath, pathParams) {
|
|
111
108
|
return Object.keys(pathParams || {}).reduce((acc, paramName) => {
|
|
112
109
|
return acc.replace(`{${paramName}}`, pathParams[paramName]);
|
|
113
|
-
}, requestPath);
|
|
110
|
+
}, requestPath || "");
|
|
114
111
|
}
|
|
115
112
|
|
|
116
113
|
function createAPIClient(params) {
|
|
@@ -129,25 +126,31 @@ function createAPIClient(params) {
|
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
128
|
);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
);
|
|
143
|
-
defaultHeaders["sw-context-token"]
|
|
129
|
+
let currentBaseURL = params.baseURL;
|
|
130
|
+
let currentAccessToken = params.accessToken;
|
|
131
|
+
function createFetchClient(baseURL) {
|
|
132
|
+
return ofetch.create({
|
|
133
|
+
baseURL,
|
|
134
|
+
...params.fetchOptions,
|
|
135
|
+
async onRequest(context) {
|
|
136
|
+
apiClientHooks.callHook("onRequest", context);
|
|
137
|
+
},
|
|
138
|
+
async onResponse(context) {
|
|
139
|
+
apiClientHooks.callHook("onSuccessResponse", context.response);
|
|
140
|
+
if (context.response.headers.has("sw-context-token") && defaultHeaders["sw-context-token"] !== context.response.headers.get("sw-context-token")) {
|
|
141
|
+
const newContextToken = context.response.headers.get(
|
|
142
|
+
"sw-context-token"
|
|
143
|
+
);
|
|
144
|
+
defaultHeaders["sw-context-token"] = newContextToken;
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
async onResponseError({ response }) {
|
|
148
|
+
apiClientHooks.callHook("onResponseError", response);
|
|
149
|
+
errorInterceptor(response);
|
|
144
150
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
errorInterceptor(response);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
let apiFetch = createFetchClient(currentBaseURL);
|
|
151
154
|
async function invoke(pathParam, ...params2) {
|
|
152
155
|
const [, method, requestPath] = pathParam.split(" ");
|
|
153
156
|
const currentParams = params2[0] || {};
|
|
@@ -158,9 +161,10 @@ function createAPIClient(params) {
|
|
|
158
161
|
const fetchOptions = {
|
|
159
162
|
...currentParams.fetchOptions || {}
|
|
160
163
|
};
|
|
161
|
-
|
|
164
|
+
let mergedHeaders = defu(currentParams.headers, defaultHeaders);
|
|
162
165
|
if (mergedHeaders?.["Content-Type"]?.includes("multipart/form-data") && typeof window !== "undefined") {
|
|
163
|
-
|
|
166
|
+
const { "Content-Type": _, ...headersWithoutContentType } = mergedHeaders;
|
|
167
|
+
mergedHeaders = headersWithoutContentType;
|
|
164
168
|
}
|
|
165
169
|
const resp = await apiFetch.raw(requestPathWithParams, {
|
|
166
170
|
...fetchOptions,
|
|
@@ -180,15 +184,37 @@ function createAPIClient(params) {
|
|
|
180
184
|
* Default headers used in every client request (if not overriden in specific request).
|
|
181
185
|
*/
|
|
182
186
|
defaultHeaders,
|
|
183
|
-
hook: apiClientHooks.hook
|
|
187
|
+
hook: apiClientHooks.hook,
|
|
188
|
+
/**
|
|
189
|
+
* Update the base configuration for API client
|
|
190
|
+
*/
|
|
191
|
+
updateBaseConfig: (config) => {
|
|
192
|
+
let shouldRecreateClient = false;
|
|
193
|
+
if (config.baseURL !== void 0 && config.baseURL !== currentBaseURL) {
|
|
194
|
+
currentBaseURL = config.baseURL;
|
|
195
|
+
shouldRecreateClient = true;
|
|
196
|
+
}
|
|
197
|
+
if (config.accessToken !== void 0 && config.accessToken !== currentAccessToken) {
|
|
198
|
+
currentAccessToken = config.accessToken;
|
|
199
|
+
defaultHeaders["sw-access-key"] = config.accessToken;
|
|
200
|
+
}
|
|
201
|
+
if (shouldRecreateClient) {
|
|
202
|
+
apiFetch = createFetchClient(currentBaseURL);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
/**
|
|
206
|
+
* Get the current base configuration
|
|
207
|
+
*/
|
|
208
|
+
getBaseConfig: () => ({
|
|
209
|
+
baseURL: currentBaseURL,
|
|
210
|
+
accessToken: currentAccessToken
|
|
211
|
+
})
|
|
184
212
|
};
|
|
185
213
|
}
|
|
186
214
|
|
|
187
215
|
function createAuthorizationHeader(token) {
|
|
188
|
-
if (!token)
|
|
189
|
-
|
|
190
|
-
if (token.startsWith("Bearer "))
|
|
191
|
-
return token;
|
|
216
|
+
if (!token) return "";
|
|
217
|
+
if (token.startsWith("Bearer ")) return token;
|
|
192
218
|
return `Bearer ${token}`;
|
|
193
219
|
}
|
|
194
220
|
function createAdminAPIClient(params) {
|
|
@@ -255,8 +281,7 @@ function createAdminAPIClient(params) {
|
|
|
255
281
|
errorInterceptor(response);
|
|
256
282
|
},
|
|
257
283
|
onResponse(context) {
|
|
258
|
-
if (!context.response._data)
|
|
259
|
-
return;
|
|
284
|
+
if (!context.response._data) return;
|
|
260
285
|
updateSessionData(context.response._data);
|
|
261
286
|
options.headers.set(
|
|
262
287
|
"Authorization",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopware/api-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shopware client for API connection.",
|
|
5
5
|
"author": "Shopware",
|
|
6
6
|
"type": "module",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@biomejs/biome": "1.8.3",
|
|
46
|
-
"@codspeed/vitest-plugin": "4.0.
|
|
46
|
+
"@codspeed/vitest-plugin": "4.0.1",
|
|
47
47
|
"@types/prettier": "3.0.0",
|
|
48
|
-
"@vitest/coverage-v8": "3.
|
|
49
|
-
"jsdom": "^
|
|
50
|
-
"prettier": "3.5.
|
|
48
|
+
"@vitest/coverage-v8": "3.1.1",
|
|
49
|
+
"jsdom": "^26.1.0",
|
|
50
|
+
"prettier": "3.5.3",
|
|
51
51
|
"unbuild": "2.0.0",
|
|
52
|
-
"vitest": "3.
|
|
52
|
+
"vitest": "3.1.1",
|
|
53
53
|
"tsconfig": "0.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|