@shopware/api-client 1.3.0 → 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 +70 -13
- 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 +1 -29
- package/api-types/storeApiSchema.json +2321 -1025
- package/api-types/storeApiSchema.overrides.json +43 -857
- package/api-types/storeApiTypes.d.ts +1629 -1161
- 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.d.cts +22750 -31136
- package/dist/index.d.mts +22750 -31136
- package/dist/index.d.ts +22750 -31136
- package/package.json +16 -6
- package/api-types/storeApiTypes.overrides.ts +0 -48
package/README.md
CHANGED
|
@@ -10,7 +10,6 @@ You can use types generated from your custom API instance to have autocompletion
|
|
|
10
10
|
|
|
11
11
|
To generate your own types use [@shopware/api-gen](https://www.npmjs.com/package/@shopware/api-gen) CLI.
|
|
12
12
|
|
|
13
|
-
To take a deep dive into the topic visit the [🧑🎓 API Client Tutorial](https://api-client-tutorial-composable-frontends.pages.dev) first.
|
|
14
13
|
|
|
15
14
|
## Setup
|
|
16
15
|
|
|
@@ -129,7 +128,7 @@ export const adminApiClient = createAdminAPIClient<operations>({
|
|
|
129
128
|
sessionData: JSON.parse(Cookies.get("sw-admin-session-data") || "{}"),
|
|
130
129
|
});
|
|
131
130
|
|
|
132
|
-
adminApiClient.
|
|
131
|
+
adminApiClient.hook("onAuthChange", (sessionData) => {
|
|
133
132
|
Cookies.set("sw-admin-session-data", JSON.stringify(sessionData), {
|
|
134
133
|
expires: 1, // days
|
|
135
134
|
path: "/",
|
|
@@ -295,13 +294,59 @@ apiClient.updateBaseConfig({
|
|
|
295
294
|
|
|
296
295
|
This allows you to dynamically change the API endpoint or access token during runtime, for example when switching between different environments or when the access token needs to be updated.
|
|
297
296
|
|
|
298
|
-
##
|
|
297
|
+
## Helper Functions
|
|
298
|
+
|
|
299
|
+
The API client provides helper functions that can be imported separately to keep your main bundle size smaller.
|
|
300
|
+
|
|
301
|
+
### encodeForQuery
|
|
302
|
+
|
|
303
|
+
The `encodeForQuery` function compresses and encodes objects into base64url format for use in query strings. This is particularly useful for complex criteria objects that need to be passed as URL parameters.
|
|
304
|
+
|
|
305
|
+
Related issue: https://github.com/shopware/shopware/issues/12388
|
|
299
306
|
|
|
300
|
-
|
|
307
|
+
```typescript
|
|
308
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
309
|
+
|
|
310
|
+
// Example: Encoding complex search criteria
|
|
311
|
+
const criteria = {
|
|
312
|
+
page: 1,
|
|
313
|
+
limit: 10,
|
|
314
|
+
filter: [
|
|
315
|
+
{
|
|
316
|
+
type: "equals",
|
|
317
|
+
field: "active",
|
|
318
|
+
value: true
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
type: "contains",
|
|
322
|
+
field: "name",
|
|
323
|
+
value: "smartphone"
|
|
324
|
+
}
|
|
325
|
+
],
|
|
326
|
+
associations: {
|
|
327
|
+
manufacturer: {},
|
|
328
|
+
categories: {
|
|
329
|
+
associations: {
|
|
330
|
+
media: {}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
// Use in URL
|
|
337
|
+
apiClient.invoke("getProducts get /product", {
|
|
338
|
+
query: {
|
|
339
|
+
_criteria: encodeForQuery(encodedCriteria),
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
## Links
|
|
301
346
|
|
|
302
347
|
- [📘 Documentation](https://frontends.shopware.com)
|
|
303
348
|
|
|
304
|
-
- [👥 Community
|
|
349
|
+
- [👥 Community Discord](https://discord.com/channels/1308047705309708348/1405501315160739951) (`#composable-frontend` channel)
|
|
305
350
|
|
|
306
351
|
<!-- AUTO GENERATED CHANGELOG -->
|
|
307
352
|
|
|
@@ -309,19 +354,31 @@ This allows you to dynamically change the API endpoint or access token during ru
|
|
|
309
354
|
|
|
310
355
|
Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/api-client/CHANGELOG.md)
|
|
311
356
|
|
|
312
|
-
### Latest changes: 1.
|
|
357
|
+
### Latest changes: 1.4.0
|
|
313
358
|
|
|
314
359
|
### Minor Changes
|
|
315
360
|
|
|
316
|
-
- [#
|
|
361
|
+
- [#2012](https://github.com/shopware/frontends/pull/2012) [`70dcf95`](https://github.com/shopware/frontends/commit/70dcf95d4370c63964d877a5cab113a53f93ca19) Thanks [@patzick](https://github.com/patzick)! - Added helper to support encoded `_criteria` field in GET query parameters.
|
|
362
|
+
Context information: https://github.com/shopware/shopware/issues/12388
|
|
317
363
|
|
|
318
|
-
|
|
319
|
-
- `getBaseConfig`: Returns current baseURL and accessToken values
|
|
364
|
+
This helper is available under the `@shopware/api-client/helpers` import path.
|
|
320
365
|
|
|
321
|
-
|
|
366
|
+
```typescript
|
|
367
|
+
import { encodeForQuery } from "@shopware/api-client/helpers";
|
|
322
368
|
|
|
323
|
-
|
|
369
|
+
const criteria = {
|
|
370
|
+
page: 1,
|
|
371
|
+
limit: 10,
|
|
372
|
+
...
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const encodedCriteria = encodeForQuery(criteria);
|
|
324
376
|
|
|
325
|
-
|
|
377
|
+
const result = await apiClient.invoke("getProducts get /product", {
|
|
378
|
+
query: {
|
|
379
|
+
_criteria: encodedCriteria,
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
```
|
|
326
383
|
|
|
327
|
-
- [#
|
|
384
|
+
- [#1959](https://github.com/shopware/frontends/pull/1959) [`c77daa6`](https://github.com/shopware/frontends/commit/c77daa6a11e96c7f3688b16f7da010b54c7f5e8b) Thanks [@patzick](https://github.com/patzick)! - Updated default types to Shopware 6.7
|