@shopware/api-client 1.0.2 → 1.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/README.md +52 -4
- package/api-types/adminApiSchema.json +30084 -20576
- package/api-types/adminApiSchema.overrides.json +390 -1
- package/api-types/adminApiTypes.d.ts +21977 -15773
- package/api-types/storeApiSchema.json +7133 -3832
- package/api-types/storeApiSchema.overrides.json +14 -146
- package/api-types/storeApiTypes.d.ts +1760 -702
- package/dist/index.cjs +39 -20
- package/dist/index.d.cts +31218 -23954
- package/dist/index.d.mts +31218 -23954
- package/dist/index.d.ts +31218 -23954
- package/dist/index.mjs +39 -20
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
|
|
9
9
|
const defu__default = /*#__PURE__*/_interopDefaultCompat(defu);
|
|
10
10
|
|
|
11
|
-
function createHeaders(init) {
|
|
11
|
+
function createHeaders(init, hookCallback) {
|
|
12
12
|
const _headers = {
|
|
13
13
|
"Content-Type": "application/json"
|
|
14
14
|
};
|
|
@@ -23,7 +23,12 @@ function createHeaders(init) {
|
|
|
23
23
|
if (prop === "apply") {
|
|
24
24
|
throw new Error("Cannot override apply method");
|
|
25
25
|
}
|
|
26
|
+
hookCallback?.(prop, value);
|
|
26
27
|
return Reflect.set(target, prop, value);
|
|
28
|
+
},
|
|
29
|
+
deleteProperty: (target, prop) => {
|
|
30
|
+
hookCallback?.(prop);
|
|
31
|
+
return Reflect.deleteProperty(target, prop);
|
|
27
32
|
}
|
|
28
33
|
};
|
|
29
34
|
const headersProxy = new Proxy(
|
|
@@ -115,13 +120,21 @@ function createPathWithParams(requestPath, pathParams) {
|
|
|
115
120
|
}
|
|
116
121
|
|
|
117
122
|
function createAPIClient(params) {
|
|
118
|
-
const defaultHeaders = createHeaders({
|
|
119
|
-
"sw-access-key": params.accessToken,
|
|
120
|
-
Accept: "application/json",
|
|
121
|
-
"sw-context-token": params.contextToken,
|
|
122
|
-
...params.defaultHeaders
|
|
123
|
-
});
|
|
124
123
|
const apiClientHooks = hookable.createHooks();
|
|
124
|
+
const defaultHeaders = createHeaders(
|
|
125
|
+
{
|
|
126
|
+
"sw-access-key": params.accessToken,
|
|
127
|
+
accept: "application/json",
|
|
128
|
+
"sw-context-token": params.contextToken,
|
|
129
|
+
...params.defaultHeaders
|
|
130
|
+
},
|
|
131
|
+
(key, value) => {
|
|
132
|
+
apiClientHooks.callHook("onDefaultHeaderChanged", key, value);
|
|
133
|
+
if (key === "sw-context-token") {
|
|
134
|
+
apiClientHooks.callHook("onContextChanged", value);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
);
|
|
125
138
|
const apiFetch = ofetch.ofetch.create({
|
|
126
139
|
baseURL: params.baseURL,
|
|
127
140
|
// async onRequest({ request, options }) {},
|
|
@@ -133,7 +146,6 @@ function createAPIClient(params) {
|
|
|
133
146
|
"sw-context-token"
|
|
134
147
|
);
|
|
135
148
|
defaultHeaders["sw-context-token"] = newContextToken;
|
|
136
|
-
apiClientHooks.callHook("onContextChanged", newContextToken);
|
|
137
149
|
}
|
|
138
150
|
},
|
|
139
151
|
async onResponseError({ response }) {
|
|
@@ -151,11 +163,15 @@ function createAPIClient(params) {
|
|
|
151
163
|
const fetchOptions = {
|
|
152
164
|
...currentParams.fetchOptions || {}
|
|
153
165
|
};
|
|
166
|
+
let mergedHeaders = defu__default(currentParams.headers, defaultHeaders);
|
|
167
|
+
if (mergedHeaders?.["Content-Type"]?.includes("multipart/form-data") && typeof window !== "undefined") {
|
|
168
|
+
delete mergedHeaders["Content-Type"];
|
|
169
|
+
}
|
|
154
170
|
const resp = await apiFetch.raw(requestPathWithParams, {
|
|
155
171
|
...fetchOptions,
|
|
156
172
|
method,
|
|
157
173
|
body: currentParams.body,
|
|
158
|
-
headers:
|
|
174
|
+
headers: mergedHeaders,
|
|
159
175
|
query: currentParams.query
|
|
160
176
|
});
|
|
161
177
|
return {
|
|
@@ -182,16 +198,21 @@ function createAuthorizationHeader(token) {
|
|
|
182
198
|
}
|
|
183
199
|
function createAdminAPIClient(params) {
|
|
184
200
|
const isTokenBasedAuth = params.credentials?.grant_type === "client_credentials";
|
|
201
|
+
const apiClientHooks = hookable.createHooks();
|
|
185
202
|
const sessionData = {
|
|
186
203
|
accessToken: params.sessionData?.accessToken || "",
|
|
187
204
|
refreshToken: params.sessionData?.refreshToken || "",
|
|
188
205
|
expirationTime: Number(params.sessionData?.expirationTime || 0)
|
|
189
206
|
};
|
|
190
|
-
const defaultHeaders = createHeaders(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
207
|
+
const defaultHeaders = createHeaders(
|
|
208
|
+
{
|
|
209
|
+
Authorization: createAuthorizationHeader(sessionData.accessToken),
|
|
210
|
+
Accept: "application/json"
|
|
211
|
+
},
|
|
212
|
+
(key, value) => {
|
|
213
|
+
apiClientHooks.callHook("onDefaultHeaderChanged", key, value);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
195
216
|
function getSessionData() {
|
|
196
217
|
return { ...sessionData };
|
|
197
218
|
}
|
|
@@ -241,12 +262,10 @@ function createAdminAPIClient(params) {
|
|
|
241
262
|
if (!context.response._data)
|
|
242
263
|
return;
|
|
243
264
|
updateSessionData(context.response._data);
|
|
244
|
-
options.headers
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
)
|
|
249
|
-
};
|
|
265
|
+
options.headers.append(
|
|
266
|
+
"Authorization",
|
|
267
|
+
createAuthorizationHeader(sessionData.accessToken)
|
|
268
|
+
);
|
|
250
269
|
}
|
|
251
270
|
});
|
|
252
271
|
}
|