@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 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.hooks("onAuthChange", (sessionData) => {
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
- ## Links
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
- - [🧑‍🎓 Tutorial](https://api-client-tutorial-composable-frontends.pages.dev)
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 Slack](https://shopwarecommunity.slack.com) (`#composable-frontends` channel)
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.3.0
357
+ ### Latest changes: 1.4.0
313
358
 
314
359
  ### Minor Changes
315
360
 
316
- - [#1865](https://github.com/shopware/frontends/pull/1865) [`d016d6b`](https://github.com/shopware/frontends/commit/d016d6b845bff9a148405a74dae88d7fc81ec99c) Thanks [@patzick](https://github.com/patzick)! - Added new methods to manage API client base configuration:
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
- - `updateBaseConfig`: Allows updating baseURL and accessToken in a single call
319
- - `getBaseConfig`: Returns current baseURL and accessToken values
364
+ This helper is available under the `@shopware/api-client/helpers` import path.
320
365
 
321
- This change replaces the previous `updateBaseUrl` method with a more flexible configuration management system that can be extended in the future.
366
+ ```typescript
367
+ import { encodeForQuery } from "@shopware/api-client/helpers";
322
368
 
323
- ### Patch Changes
369
+ const criteria = {
370
+ page: 1,
371
+ limit: 10,
372
+ ...
373
+ }
374
+
375
+ const encodedCriteria = encodeForQuery(criteria);
324
376
 
325
- - [#1801](https://github.com/shopware/frontends/pull/1801) [`a7ff606`](https://github.com/shopware/frontends/commit/a7ff60681d1a164d5c9f2020c506262e96fad5dc) Thanks [@joostaasman](https://github.com/joostaasman)! - fix: Undefined mergedHeaders["content-type"] when content-type is multipart/form-data
377
+ const result = await apiClient.invoke("getProducts get /product", {
378
+ query: {
379
+ _criteria: encodedCriteria,
380
+ },
381
+ });
382
+ ```
326
383
 
327
- - [#1865](https://github.com/shopware/frontends/pull/1865) [`d016d6b`](https://github.com/shopware/frontends/commit/d016d6b845bff9a148405a74dae88d7fc81ec99c) Thanks [@patzick](https://github.com/patzick)! - Added `onRequest` hook to the API client that is triggered before each request is made. This hook provides access to the request context, allowing for request inspection and modification before it's sent.
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