@shopware/api-client 0.3.0 → 0.5.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
@@ -29,13 +29,13 @@ Recommended practice is to create separate module file. For example `src/apiClie
29
29
  import { createAPIClient } from "@shopware/api-client";
30
30
 
31
31
  // You can pick types of your current API version, the default one:
32
- import {
32
+ import type {
33
33
  operationPaths,
34
34
  operations,
35
35
  components,
36
36
  } from "@shopware/api-client/api-types";
37
37
  // or (specific version):
38
- import {
38
+ import type {
39
39
  operationPaths,
40
40
  operations,
41
41
  components,
@@ -50,7 +50,6 @@ export const apiClient = createAPIClient<operations, operationPaths>({
50
50
  baseURL: "https://demo-frontends.shopware.store/store-api",
51
51
  accessToken: "SWSCBHFSNTVMAWNZDNFKSHLAYW",
52
52
  contextToken: Cookies.get("sw-context-token"),
53
- apiType: "store-api",
54
53
  onContextChanged(newContextToken) {
55
54
  Cookies.set("sw-context-token", newContextToken, {
56
55
  expires: 365, // days
@@ -70,6 +69,47 @@ export type ApiReturnType<OPERATION_NAME extends keyof operations> =
70
69
  RequestReturnType<OPERATION_NAME, operations>;
71
70
  ```
72
71
 
72
+ ## Admin API client setup
73
+
74
+ The setup works the same way as `creteAPIClient` function, with few differences:
75
+
76
+ ```typescript
77
+ // example adminApiClient.ts file
78
+ import { createAdminAPIClient } from "@shopware/api-client"; // we use different function to create admin api client
79
+
80
+ import {
81
+ RequestParameters,
82
+ RequestReturnType,
83
+ createAdminAPIClient,
84
+ } from "@shopware/api-client";
85
+ import type {
86
+ operationPaths,
87
+ operations,
88
+ components,
89
+ } from "@shopware/api-client/admin-api-types"; // we take default admin api types from different directory than store-api
90
+ import Cookies from "js-cookie";
91
+
92
+ export const adminApiClient = createAdminAPIClient<operations, operationPaths>({
93
+ baseURL: "https://demo-frontends.shopware.store/api",
94
+ sessionData: JSON.parse(Cookies.get("sw-admin-session-data") || "{}"),
95
+ onAuthChange(sessionData) {
96
+ Cookies.set("sw-admin-session-data", JSON.stringify(sessionData), {
97
+ expires: 1, // days
98
+ path: "/",
99
+ sameSite: "lax",
100
+ });
101
+ },
102
+ });
103
+
104
+ export type AdminApiSchemas = components["schemas"];
105
+ export type AdminApiRequestParams<OPERATION_NAME extends keyof operations> =
106
+ RequestParameters<OPERATION_NAME, operations>;
107
+ export type AdminApiReturnType<OPERATION_NAME extends keyof operations> =
108
+ RequestReturnType<OPERATION_NAME, operations>;
109
+ ```
110
+
111
+ the rest works the same as store-api client.
112
+
73
113
  ## Basic usage
74
114
 
75
115
  Take a look at [example project using API Client](https://stackblitz.com/github/shopware/frontends/tree/main/examples/new-api-client).
@@ -146,8 +186,24 @@ try {
146
186
 
147
187
  Full changelog for stable version is available [here](https://github.com/shopware/frontends/blob/main/packages/api-client-next/CHANGELOG.md)
148
188
 
149
- ### Latest changes: 0.3.0
189
+ ### Latest changes: 0.5.0
150
190
 
151
191
  ### Minor Changes
152
192
 
153
- - [#330](https://github.com/shopware/frontends/pull/330) [`3683116`](https://github.com/shopware/frontends/commit/3683116588a7ef75e750fc33deee119f038c88e8) Thanks [@mdanilowicz](https://github.com/mdanilowicz)! - Add `setCurrentCountry` for changing context countryId
193
+ - [#435](https://github.com/shopware/frontends/pull/435) [`a4483ed8`](https://github.com/shopware/frontends/commit/a4483ed8bf9370e87aedeb81846fe9d31880b3e0) Thanks [@patzick](https://github.com/patzick)! - Changed types imports to `import type {...} from "..."`
194
+
195
+ ### Patch Changes
196
+
197
+ - [#443](https://github.com/shopware/frontends/pull/443) [`33d54db1`](https://github.com/shopware/frontends/commit/33d54db1bd66146a14781c45b1124547f4276866) Thanks [@patzick](https://github.com/patzick)! - `invoke` method parameters are no longer mandatory when no parameters are defined inside route.
198
+
199
+ Now instead of:
200
+
201
+ ```ts
202
+ const result = await apiInstance.invoke("readContext get /context", {});
203
+ ```
204
+
205
+ you can do:
206
+
207
+ ```ts
208
+ const result = await apiInstance.invoke("readContext get /context");
209
+ ```