@shopware/api-client 1.2.1 → 1.4.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 +106 -8
- package/api-types/adminApiSchema.json +76278 -51743
- package/api-types/adminApiTypes.d.ts +17039 -25893
- package/api-types/storeApiSchema.6.6.10.json +25865 -0
- package/api-types/storeApiSchema.6.6.10.overrides.json +1011 -0
- package/api-types/storeApiSchema.b2b.overrides.json +5 -0
- package/api-types/storeApiSchema.json +8850 -3696
- package/api-types/storeApiSchema.overrides.json +43 -871
- package/api-types/storeApiTypes.d.ts +2612 -651
- package/dist/helpers.cjs +13 -0
- package/dist/helpers.d.cts +9 -0
- package/dist/helpers.d.mts +9 -0
- package/dist/helpers.d.ts +9 -0
- package/dist/helpers.mjs +11 -0
- package/dist/index.cjs +57 -32
- package/dist/index.d.cts +23055 -29933
- package/dist/index.d.mts +23055 -29933
- package/dist/index.d.ts +23055 -29933
- package/dist/index.mjs +57 -32
- package/package.json +16 -6
- package/api-types/storeApiTypes.overrides.ts +0 -48
package/dist/helpers.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fflate = require('fflate');
|
|
4
|
+
|
|
5
|
+
function encodeForQuery(obj) {
|
|
6
|
+
const json = JSON.stringify(obj);
|
|
7
|
+
const compressed = fflate.gzipSync(fflate.strToU8(json));
|
|
8
|
+
let base64 = btoa(String.fromCharCode.apply(null, Array.from(compressed)));
|
|
9
|
+
base64 = base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
10
|
+
return base64;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.encodeForQuery = encodeForQuery;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🔹 Compress object -> base64url for query string
|
|
3
|
+
*
|
|
4
|
+
* This is a helper to support https://github.com/shopware/shopware/issues/12388 for _criteria query field in store-api GET requests
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
declare function encodeForQuery(obj: unknown): string;
|
|
8
|
+
|
|
9
|
+
export { encodeForQuery };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🔹 Compress object -> base64url for query string
|
|
3
|
+
*
|
|
4
|
+
* This is a helper to support https://github.com/shopware/shopware/issues/12388 for _criteria query field in store-api GET requests
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
declare function encodeForQuery(obj: unknown): string;
|
|
8
|
+
|
|
9
|
+
export { encodeForQuery };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🔹 Compress object -> base64url for query string
|
|
3
|
+
*
|
|
4
|
+
* This is a helper to support https://github.com/shopware/shopware/issues/12388 for _criteria query field in store-api GET requests
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
declare function encodeForQuery(obj: unknown): string;
|
|
8
|
+
|
|
9
|
+
export { encodeForQuery };
|
package/dist/helpers.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { gzipSync, strToU8 } from 'fflate';
|
|
2
|
+
|
|
3
|
+
function encodeForQuery(obj) {
|
|
4
|
+
const json = JSON.stringify(obj);
|
|
5
|
+
const compressed = gzipSync(strToU8(json));
|
|
6
|
+
let base64 = btoa(String.fromCharCode.apply(null, Array.from(compressed)));
|
|
7
|
+
base64 = base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
8
|
+
return base64;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { encodeForQuery };
|
package/dist/index.cjs
CHANGED
|
@@ -50,10 +50,7 @@ function createHeaders(init, hookCallback) {
|
|
|
50
50
|
|
|
51
51
|
var __defProp = Object.defineProperty;
|
|
52
52
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
53
|
-
var __publicField = (obj, key, value) =>
|
|
54
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
55
|
-
return value;
|
|
56
|
-
};
|
|
53
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
57
54
|
class ApiClientError extends Error {
|
|
58
55
|
constructor(response) {
|
|
59
56
|
let message = "Failed request";
|
|
@@ -116,7 +113,7 @@ function errorInterceptor(response) {
|
|
|
116
113
|
function createPathWithParams(requestPath, pathParams) {
|
|
117
114
|
return Object.keys(pathParams || {}).reduce((acc, paramName) => {
|
|
118
115
|
return acc.replace(`{${paramName}}`, pathParams[paramName]);
|
|
119
|
-
}, requestPath);
|
|
116
|
+
}, requestPath || "");
|
|
120
117
|
}
|
|
121
118
|
|
|
122
119
|
function createAPIClient(params) {
|
|
@@ -135,25 +132,31 @@ function createAPIClient(params) {
|
|
|
135
132
|
}
|
|
136
133
|
}
|
|
137
134
|
);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
);
|
|
149
|
-
defaultHeaders["sw-context-token"]
|
|
135
|
+
let currentBaseURL = params.baseURL;
|
|
136
|
+
let currentAccessToken = params.accessToken;
|
|
137
|
+
function createFetchClient(baseURL) {
|
|
138
|
+
return ofetch.ofetch.create({
|
|
139
|
+
baseURL,
|
|
140
|
+
...params.fetchOptions,
|
|
141
|
+
async onRequest(context) {
|
|
142
|
+
apiClientHooks.callHook("onRequest", context);
|
|
143
|
+
},
|
|
144
|
+
async onResponse(context) {
|
|
145
|
+
apiClientHooks.callHook("onSuccessResponse", context.response);
|
|
146
|
+
if (context.response.headers.has("sw-context-token") && defaultHeaders["sw-context-token"] !== context.response.headers.get("sw-context-token")) {
|
|
147
|
+
const newContextToken = context.response.headers.get(
|
|
148
|
+
"sw-context-token"
|
|
149
|
+
);
|
|
150
|
+
defaultHeaders["sw-context-token"] = newContextToken;
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
async onResponseError({ response }) {
|
|
154
|
+
apiClientHooks.callHook("onResponseError", response);
|
|
155
|
+
errorInterceptor(response);
|
|
150
156
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
errorInterceptor(response);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
let apiFetch = createFetchClient(currentBaseURL);
|
|
157
160
|
async function invoke(pathParam, ...params2) {
|
|
158
161
|
const [, method, requestPath] = pathParam.split(" ");
|
|
159
162
|
const currentParams = params2[0] || {};
|
|
@@ -164,9 +167,10 @@ function createAPIClient(params) {
|
|
|
164
167
|
const fetchOptions = {
|
|
165
168
|
...currentParams.fetchOptions || {}
|
|
166
169
|
};
|
|
167
|
-
|
|
170
|
+
let mergedHeaders = defu__default(currentParams.headers, defaultHeaders);
|
|
168
171
|
if (mergedHeaders?.["Content-Type"]?.includes("multipart/form-data") && typeof window !== "undefined") {
|
|
169
|
-
|
|
172
|
+
const { "Content-Type": _, ...headersWithoutContentType } = mergedHeaders;
|
|
173
|
+
mergedHeaders = headersWithoutContentType;
|
|
170
174
|
}
|
|
171
175
|
const resp = await apiFetch.raw(requestPathWithParams, {
|
|
172
176
|
...fetchOptions,
|
|
@@ -186,15 +190,37 @@ function createAPIClient(params) {
|
|
|
186
190
|
* Default headers used in every client request (if not overriden in specific request).
|
|
187
191
|
*/
|
|
188
192
|
defaultHeaders,
|
|
189
|
-
hook: apiClientHooks.hook
|
|
193
|
+
hook: apiClientHooks.hook,
|
|
194
|
+
/**
|
|
195
|
+
* Update the base configuration for API client
|
|
196
|
+
*/
|
|
197
|
+
updateBaseConfig: (config) => {
|
|
198
|
+
let shouldRecreateClient = false;
|
|
199
|
+
if (config.baseURL !== void 0 && config.baseURL !== currentBaseURL) {
|
|
200
|
+
currentBaseURL = config.baseURL;
|
|
201
|
+
shouldRecreateClient = true;
|
|
202
|
+
}
|
|
203
|
+
if (config.accessToken !== void 0 && config.accessToken !== currentAccessToken) {
|
|
204
|
+
currentAccessToken = config.accessToken;
|
|
205
|
+
defaultHeaders["sw-access-key"] = config.accessToken;
|
|
206
|
+
}
|
|
207
|
+
if (shouldRecreateClient) {
|
|
208
|
+
apiFetch = createFetchClient(currentBaseURL);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
/**
|
|
212
|
+
* Get the current base configuration
|
|
213
|
+
*/
|
|
214
|
+
getBaseConfig: () => ({
|
|
215
|
+
baseURL: currentBaseURL,
|
|
216
|
+
accessToken: currentAccessToken
|
|
217
|
+
})
|
|
190
218
|
};
|
|
191
219
|
}
|
|
192
220
|
|
|
193
221
|
function createAuthorizationHeader(token) {
|
|
194
|
-
if (!token)
|
|
195
|
-
|
|
196
|
-
if (token.startsWith("Bearer "))
|
|
197
|
-
return token;
|
|
222
|
+
if (!token) return "";
|
|
223
|
+
if (token.startsWith("Bearer ")) return token;
|
|
198
224
|
return `Bearer ${token}`;
|
|
199
225
|
}
|
|
200
226
|
function createAdminAPIClient(params) {
|
|
@@ -261,8 +287,7 @@ function createAdminAPIClient(params) {
|
|
|
261
287
|
errorInterceptor(response);
|
|
262
288
|
},
|
|
263
289
|
onResponse(context) {
|
|
264
|
-
if (!context.response._data)
|
|
265
|
-
return;
|
|
290
|
+
if (!context.response._data) return;
|
|
266
291
|
updateSessionData(context.response._data);
|
|
267
292
|
options.headers.set(
|
|
268
293
|
"Authorization",
|