@devite/shopware-client 1.4.0 → 1.4.2

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/dist/index.cjs CHANGED
@@ -11803,7 +11803,12 @@ class ContextTokenEntry {
11803
11803
  return this.token !== null;
11804
11804
  }
11805
11805
  save(response) {
11806
- this.token = response.headers?.get("sw-context-token") || null;
11806
+ const headerToken = response.headers?.get("sw-context-token") || null;
11807
+ if (headerToken?.includes(", ")) {
11808
+ this.token = headerToken.split(", ")[1];
11809
+ } else {
11810
+ this.token = headerToken;
11811
+ }
11807
11812
  }
11808
11813
  clear() {
11809
11814
  this.token = null;
@@ -12085,7 +12090,10 @@ class CartClient extends Client {
12085
12090
  * @throws {Error} if the request failed
12086
12091
  */
12087
12092
  async getOrCreateCart() {
12088
- const response = await this.get("/checkout/cart");
12093
+ const response = await this.get(
12094
+ "/checkout/cart",
12095
+ this.client.authStore.getEntry(AuthenticationType.CONTEXT_TOKEN) ? this.client.withContextToken() : void 0
12096
+ );
12089
12097
  if (response.statusCode === 200)
12090
12098
  return response.body.data;
12091
12099
  throw new ShopwareError("Failed to get or create cart", response);
@@ -12094,7 +12102,10 @@ class CartClient extends Client {
12094
12102
  * @throws {Error} if the request failed
12095
12103
  */
12096
12104
  async deleteCart() {
12097
- const response = await this.delete("/checkout/cart");
12105
+ const response = await this.delete(
12106
+ "/checkout/cart",
12107
+ this.client.withContextToken()
12108
+ );
12098
12109
  if (response.statusCode === 200)
12099
12110
  return response.body.data;
12100
12111
  throw new ShopwareError("Failed to delete cart", response);
@@ -12103,9 +12114,12 @@ class CartClient extends Client {
12103
12114
  * @throws {Error} if the request failed
12104
12115
  */
12105
12116
  async addLineItems(request) {
12106
- const response = await this.post("/checkout/cart/line-item", {
12107
- body: new JsonPayload(request)
12108
- });
12117
+ const response = await this.post(
12118
+ "/checkout/cart/line-item",
12119
+ this.client.withContextToken({
12120
+ body: new JsonPayload(request)
12121
+ })
12122
+ );
12109
12123
  if (response.statusCode === 200)
12110
12124
  return response.body.data;
12111
12125
  throw new ShopwareError("Failed to add line items to cart", response);
@@ -12114,9 +12128,12 @@ class CartClient extends Client {
12114
12128
  * @throws {Error} if the request failed
12115
12129
  */
12116
12130
  async removeLineItems(request) {
12117
- const response = await this.post("/checkout/cart/line-item/delete", {
12118
- body: new JsonPayload(request)
12119
- });
12131
+ const response = await this.post(
12132
+ "/checkout/cart/line-item/delete",
12133
+ this.client.withContextToken({
12134
+ body: new JsonPayload(request)
12135
+ })
12136
+ );
12120
12137
  if (response.statusCode === 200)
12121
12138
  return response.body.data;
12122
12139
  throw new ShopwareError("Failed to remove line items from cart", response);
@@ -12125,9 +12142,12 @@ class CartClient extends Client {
12125
12142
  * @throws {Error} if the request failed
12126
12143
  */
12127
12144
  async updateLineItems(request) {
12128
- const response = await this.patch("/checkout/cart/line-item", {
12129
- body: new JsonPayload(request)
12130
- });
12145
+ const response = await this.patch(
12146
+ "/checkout/cart/line-item",
12147
+ this.client.withContextToken({
12148
+ body: new JsonPayload(request)
12149
+ })
12150
+ );
12131
12151
  if (response.statusCode === 200)
12132
12152
  return response.body.data;
12133
12153
  throw new ShopwareError("Failed to update line items in cart", response);
@@ -12222,12 +12242,17 @@ class ContextClient extends Client {
12222
12242
  * @throws {Error} if the request failed
12223
12243
  */
12224
12244
  async getContext() {
12245
+ const entry = this.client.authStore.getEntry(
12246
+ AuthenticationType.CONTEXT_TOKEN
12247
+ );
12225
12248
  const response = await this.get(
12226
12249
  "/context",
12227
- this.client.withContextToken()
12250
+ entry ? this.client.withContextToken() : void 0
12228
12251
  );
12229
- if (response.statusCode === 200)
12252
+ if (response.statusCode === 200) {
12253
+ entry?.save(response);
12230
12254
  return response.body.data;
12255
+ }
12231
12256
  throw new ShopwareError("Failed to fetch context", response);
12232
12257
  }
12233
12258
  /**
@@ -12319,7 +12344,7 @@ class NewsletterClient extends Client {
12319
12344
  const response = await this.post(`/newsletter/confirm`, {
12320
12345
  body: new JsonPayload(request)
12321
12346
  });
12322
- if (response.statusCode === 200) return;
12347
+ if (response.statusCode === 204) return;
12323
12348
  throw new ShopwareError("Failed to confirm newsletter subscription", response);
12324
12349
  }
12325
12350
  /**
@@ -12329,7 +12354,7 @@ class NewsletterClient extends Client {
12329
12354
  const response = await this.post(`/newsletter/subscribe`, {
12330
12355
  body: new JsonPayload(request)
12331
12356
  });
12332
- if (response.statusCode === 200) return;
12357
+ if (response.statusCode === 204) return;
12333
12358
  throw new ShopwareError("Failed to update newsletter subscription", response);
12334
12359
  }
12335
12360
  /**
@@ -12339,7 +12364,7 @@ class NewsletterClient extends Client {
12339
12364
  const response = await this.post(`/newsletter/unsubscribe`, {
12340
12365
  body: new JsonPayload(request)
12341
12366
  });
12342
- if (response.statusCode === 200) return;
12367
+ if (response.statusCode === 204) return;
12343
12368
  throw new ShopwareError("Failed to unsubscribe newsletter subscription", response);
12344
12369
  }
12345
12370
  }
package/dist/index.mjs CHANGED
@@ -11801,7 +11801,12 @@ class ContextTokenEntry {
11801
11801
  return this.token !== null;
11802
11802
  }
11803
11803
  save(response) {
11804
- this.token = response.headers?.get("sw-context-token") || null;
11804
+ const headerToken = response.headers?.get("sw-context-token") || null;
11805
+ if (headerToken?.includes(", ")) {
11806
+ this.token = headerToken.split(", ")[1];
11807
+ } else {
11808
+ this.token = headerToken;
11809
+ }
11805
11810
  }
11806
11811
  clear() {
11807
11812
  this.token = null;
@@ -12083,7 +12088,10 @@ class CartClient extends Client {
12083
12088
  * @throws {Error} if the request failed
12084
12089
  */
12085
12090
  async getOrCreateCart() {
12086
- const response = await this.get("/checkout/cart");
12091
+ const response = await this.get(
12092
+ "/checkout/cart",
12093
+ this.client.authStore.getEntry(AuthenticationType.CONTEXT_TOKEN) ? this.client.withContextToken() : void 0
12094
+ );
12087
12095
  if (response.statusCode === 200)
12088
12096
  return response.body.data;
12089
12097
  throw new ShopwareError("Failed to get or create cart", response);
@@ -12092,7 +12100,10 @@ class CartClient extends Client {
12092
12100
  * @throws {Error} if the request failed
12093
12101
  */
12094
12102
  async deleteCart() {
12095
- const response = await this.delete("/checkout/cart");
12103
+ const response = await this.delete(
12104
+ "/checkout/cart",
12105
+ this.client.withContextToken()
12106
+ );
12096
12107
  if (response.statusCode === 200)
12097
12108
  return response.body.data;
12098
12109
  throw new ShopwareError("Failed to delete cart", response);
@@ -12101,9 +12112,12 @@ class CartClient extends Client {
12101
12112
  * @throws {Error} if the request failed
12102
12113
  */
12103
12114
  async addLineItems(request) {
12104
- const response = await this.post("/checkout/cart/line-item", {
12105
- body: new JsonPayload(request)
12106
- });
12115
+ const response = await this.post(
12116
+ "/checkout/cart/line-item",
12117
+ this.client.withContextToken({
12118
+ body: new JsonPayload(request)
12119
+ })
12120
+ );
12107
12121
  if (response.statusCode === 200)
12108
12122
  return response.body.data;
12109
12123
  throw new ShopwareError("Failed to add line items to cart", response);
@@ -12112,9 +12126,12 @@ class CartClient extends Client {
12112
12126
  * @throws {Error} if the request failed
12113
12127
  */
12114
12128
  async removeLineItems(request) {
12115
- const response = await this.post("/checkout/cart/line-item/delete", {
12116
- body: new JsonPayload(request)
12117
- });
12129
+ const response = await this.post(
12130
+ "/checkout/cart/line-item/delete",
12131
+ this.client.withContextToken({
12132
+ body: new JsonPayload(request)
12133
+ })
12134
+ );
12118
12135
  if (response.statusCode === 200)
12119
12136
  return response.body.data;
12120
12137
  throw new ShopwareError("Failed to remove line items from cart", response);
@@ -12123,9 +12140,12 @@ class CartClient extends Client {
12123
12140
  * @throws {Error} if the request failed
12124
12141
  */
12125
12142
  async updateLineItems(request) {
12126
- const response = await this.patch("/checkout/cart/line-item", {
12127
- body: new JsonPayload(request)
12128
- });
12143
+ const response = await this.patch(
12144
+ "/checkout/cart/line-item",
12145
+ this.client.withContextToken({
12146
+ body: new JsonPayload(request)
12147
+ })
12148
+ );
12129
12149
  if (response.statusCode === 200)
12130
12150
  return response.body.data;
12131
12151
  throw new ShopwareError("Failed to update line items in cart", response);
@@ -12220,12 +12240,17 @@ class ContextClient extends Client {
12220
12240
  * @throws {Error} if the request failed
12221
12241
  */
12222
12242
  async getContext() {
12243
+ const entry = this.client.authStore.getEntry(
12244
+ AuthenticationType.CONTEXT_TOKEN
12245
+ );
12223
12246
  const response = await this.get(
12224
12247
  "/context",
12225
- this.client.withContextToken()
12248
+ entry ? this.client.withContextToken() : void 0
12226
12249
  );
12227
- if (response.statusCode === 200)
12250
+ if (response.statusCode === 200) {
12251
+ entry?.save(response);
12228
12252
  return response.body.data;
12253
+ }
12229
12254
  throw new ShopwareError("Failed to fetch context", response);
12230
12255
  }
12231
12256
  /**
@@ -12317,7 +12342,7 @@ class NewsletterClient extends Client {
12317
12342
  const response = await this.post(`/newsletter/confirm`, {
12318
12343
  body: new JsonPayload(request)
12319
12344
  });
12320
- if (response.statusCode === 200) return;
12345
+ if (response.statusCode === 204) return;
12321
12346
  throw new ShopwareError("Failed to confirm newsletter subscription", response);
12322
12347
  }
12323
12348
  /**
@@ -12327,7 +12352,7 @@ class NewsletterClient extends Client {
12327
12352
  const response = await this.post(`/newsletter/subscribe`, {
12328
12353
  body: new JsonPayload(request)
12329
12354
  });
12330
- if (response.statusCode === 200) return;
12355
+ if (response.statusCode === 204) return;
12331
12356
  throw new ShopwareError("Failed to update newsletter subscription", response);
12332
12357
  }
12333
12358
  /**
@@ -12337,7 +12362,7 @@ class NewsletterClient extends Client {
12337
12362
  const response = await this.post(`/newsletter/unsubscribe`, {
12338
12363
  body: new JsonPayload(request)
12339
12364
  });
12340
- if (response.statusCode === 200) return;
12365
+ if (response.statusCode === 204) return;
12341
12366
  throw new ShopwareError("Failed to unsubscribe newsletter subscription", response);
12342
12367
  }
12343
12368
  }
@@ -0,0 +1,6 @@
1
+ export interface PricingCashRoundingConfig {
2
+ apiAlias: "shopware_core_framework_data_abstraction_layer_pricing_cash_rounding_config";
3
+ decimals?: number;
4
+ interval?: number;
5
+ roundForNet?: boolean;
6
+ }
@@ -0,0 +1 @@
1
+ export { PricingCashRoundingConfig } from "./PricingCashRoundingConfig";
@@ -1,4 +1,5 @@
1
1
  export * from "./aggregation";
2
+ export * from "./dal";
2
3
  export * from "./filter";
3
4
  export * from "./price";
4
5
  export * from "./query";
@@ -1,12 +1,12 @@
1
1
  import { CalculatedPrice } from "../price/CalculatedPrice";
2
- import { CartItems } from "./CartItems";
3
2
  import { CartError } from "./CartError";
4
3
  import { CartDelivery } from "./delivery/CartDelivery";
4
+ import { LineItem } from "#types/api/store";
5
5
  export interface Cart {
6
6
  name?: string;
7
7
  token?: string;
8
8
  price?: CalculatedPrice;
9
- lineItems?: CartItems;
9
+ lineItems?: Array<LineItem>;
10
10
  errors?: Array<CartError>;
11
11
  deliveries?: Array<CartDelivery>;
12
12
  transactions?: Array<{
@@ -1,3 +1,2 @@
1
1
  export { Cart } from "./Cart";
2
2
  export { CartError } from "./CartError";
3
- export { CartItems } from "./CartItems";
@@ -1,7 +1,7 @@
1
1
  import { CustomerAddressBody } from "./CustomerAddressBody";
2
2
  export type CustomerAddress = CustomerAddressBody & {
3
- id: string;
4
- customerId: string;
3
+ id?: string;
4
+ customerId?: string;
5
5
  readonly createdAt?: string;
6
6
  readonly updatedAt?: string;
7
7
  };
@@ -0,0 +1,2 @@
1
+ export { CustomerAddress } from "./CustomerAddress";
2
+ export { CustomerAddressBody } from "./CustomerAddressBody";
@@ -1,2 +1,3 @@
1
+ export * from "./address";
1
2
  export { Customer } from "./Customer";
2
3
  export { CustomerGroup } from "./CustomerGroup";
@@ -1,4 +1,4 @@
1
- import { ProductMedia } from "../media/ProductMedia";
1
+ import { Media } from "../media/Media";
2
2
  import { CartDeliveryInformation } from "../cart/delivery/CartDeliveryInformation";
3
3
  import { LineItemPayload } from "./LineItemPayload";
4
4
  import { CalculatedPrice } from "../price/CalculatedPrice";
@@ -6,7 +6,7 @@ import { CartPriceQuantity } from "../price/cart/CartPriceQuantity";
6
6
  import { LineItemType } from "./LineItemType";
7
7
  export interface LineItem {
8
8
  children?: Array<LineItem>;
9
- cover?: ProductMedia;
9
+ cover?: Media;
10
10
  dataContextHash?: string;
11
11
  dataTimestamp?: string;
12
12
  deliveryInformation?: CartDeliveryInformation;
@@ -1,74 +1,26 @@
1
- import { Links } from "../link/Links";
2
1
  import { GenericRecord } from "#types/api/global/GenericRecord";
3
- import { CalculatedPrice } from "../price/CalculatedPrice";
4
2
  export interface LineItemPayload {
5
- type: string;
6
- id: string;
7
- attributes?: object;
8
- relationships?: object;
9
- links?: Links;
10
- meta?: object;
11
- versionId?: string;
12
- parentId?: string;
13
- parentVersionId?: string;
14
- manufacturerId?: string;
15
- productManufacturerVersionId?: string;
16
- unitId?: string;
17
- taxId?: string;
18
- coverId?: string;
19
- productMediaVersionId?: string;
20
- deliveryTimeId?: string;
21
- canonicalProductId?: string;
22
- canonicalProductVersionId?: string;
23
- cmsPageId?: string;
24
- cmsPageVersionId?: string;
25
- productNumber: string;
26
- restockTime?: number;
27
- active?: boolean;
28
- available?: boolean;
3
+ categoryIds: Array<string>;
4
+ readonly createdAt?: string;
5
+ readonly updatedAt?: string;
6
+ customFields?: GenericRecord;
7
+ features?: Array<string>;
29
8
  isCloseout?: boolean;
30
- availableStock?: number;
31
- stock: number;
32
- displayGroup?: string;
33
- manufacturerNumber?: string;
34
- ean?: string;
35
- purchaseSteps?: number;
36
- maxPurchase?: number;
37
- minPurchase?: number;
38
- purchaseUnit?: number;
39
- referenceUnit?: number;
40
- shippingFree?: boolean;
9
+ isNew?: boolean;
10
+ manufacturerId?: string;
41
11
  markAsTopseller?: boolean;
42
- weight?: number;
43
- width?: number;
44
- height?: number;
45
- length?: number;
46
- releaseDate?: string;
47
- ratingAverage?: number;
48
- categoryTree?: Array<string>;
49
- propertyIds?: Array<string>;
50
12
  optionIds?: Array<string>;
13
+ options?: Array<{
14
+ group: string;
15
+ name: string;
16
+ }>;
17
+ parentId?: string;
18
+ productNumber?: string;
19
+ propertyIds?: Array<string>;
20
+ releaseDate?: string;
21
+ stock?: number;
51
22
  streamIds?: Array<string>;
52
- tagIds?: Array<string>;
53
- categoryIds?: Array<string>;
54
- childCount?: number;
55
- sales?: number;
56
- states?: Array<string>;
57
- metaDescription?: string;
58
- name: string;
59
- keywords?: string;
60
- description?: string;
61
- metaTitle?: string;
62
- packUnit?: string;
63
- packUnitPlural?: string;
64
- customFields?: GenericRecord;
65
- calculatedPrice?: CalculatedPrice;
66
- calculatedPrices?: Array<CalculatedPrice>;
67
- calculatedMaxPurchase?: number;
68
- calculatedCheapestPrice?: CalculatedPrice;
69
- isNew?: boolean;
70
- sortedProperties?: object;
71
- createdAt?: string;
72
- updatedAt?: string;
73
- translated?: object;
23
+ tagsIds?: Array<string>;
24
+ taxId: string;
25
+ [key: string]: any;
74
26
  }
@@ -21,6 +21,7 @@ export interface CalculatedPrice {
21
21
  variantId?: string | null;
22
22
  apiAlias: "calculated_price";
23
23
  taxRules: Array<{
24
+ percentage?: number;
24
25
  taxRate?: number;
25
26
  name?: string;
26
27
  }>;
@@ -1,38 +1,43 @@
1
1
  import { Currency } from "../Currency";
2
+ import { CustomerGroup } from "../customer/CustomerGroup";
2
3
  import { SalesChannel } from "./SalesChannel";
3
4
  import { Customer } from "../customer/Customer";
4
5
  import { PaymentMethod } from "../PaymentMethod";
5
6
  import { CartDeliveryShippingLocation } from "../cart/delivery/CartDeliveryShippingLocation";
6
7
  import { ShippingMethod } from "../shippingMethod/ShippingMethod";
8
+ import { PricingCashRoundingConfig } from "#types/api/global/dal/PricingCashRoundingConfig";
7
9
  export interface SalesChannelContext {
8
- token?: string;
9
- currentCustomerGroup?: {
10
- name?: string;
11
- displayGross?: boolean;
12
- };
13
- fallbackCustomerGroup?: {
14
- name?: string;
15
- displayGross?: boolean;
16
- };
17
- currency?: Currency;
18
- salesChannel?: SalesChannel;
19
- taxRules?: Array<{
20
- taxRate?: number;
21
- name?: string;
22
- }>;
23
- customer?: Customer;
24
- paymentMethod?: PaymentMethod;
25
- shippingLocation?: CartDeliveryShippingLocation;
26
- shippingMethod?: ShippingMethod;
10
+ apiAlias: "sales_channel_context";
27
11
  context?: {
12
+ apiAlias: "context";
13
+ considerInheritance?: boolean;
28
14
  versionId?: string;
29
15
  currencyId?: string;
30
16
  currencyFactor?: number;
31
17
  currencyPrecision?: number;
32
- languageIdChain?: string;
18
+ languageIdChain?: Array<string>;
19
+ rounding?: PricingCashRoundingConfig;
33
20
  scope?: string;
34
- source?: string;
21
+ source?: any;
35
22
  taxState?: "gross" | "net";
36
- useCache?: boolean;
37
23
  };
24
+ currency?: Currency;
25
+ currentCustomerGroup?: CustomerGroup;
26
+ fallbackCustomerGroup?: CustomerGroup;
27
+ customer?: Customer;
28
+ imitatingUserId?: string;
29
+ itemRounding?: PricingCashRoundingConfig;
30
+ languageInfo: {
31
+ localeCode: string;
32
+ name: string;
33
+ };
34
+ paymentMethod?: PaymentMethod;
35
+ salesChannel?: SalesChannel;
36
+ shippingLocation?: CartDeliveryShippingLocation;
37
+ shippingMethod?: ShippingMethod;
38
+ taxRules?: Array<{
39
+ taxRate?: number;
40
+ name?: string;
41
+ }>;
42
+ token?: string;
38
43
  }
@@ -81,7 +81,6 @@ export interface CustomerRegisterRequest {
81
81
  storefrontUrl: string;
82
82
  billingAddress: CustomerAddress;
83
83
  shippingAddress?: CustomerAddress;
84
- accountType?: "private" | "business";
85
84
  guest?: boolean;
86
85
  birthdayDay?: number;
87
86
  birthdayMonth?: number;
@@ -89,8 +88,14 @@ export interface CustomerRegisterRequest {
89
88
  title?: string;
90
89
  affiliateCode?: string;
91
90
  campaignCode?: string;
91
+ /** @default "private" */
92
+ accountType?: "private" | "business";
93
+ company?: string;
94
+ vatIds?: Array<string>;
92
95
  }
93
- export type CustomerRegisterResponse = Customer;
96
+ export type CustomerRegisterResponse = {
97
+ accountType: "private" | "business";
98
+ };
94
99
  export type CustomerRegisterGroupConfigResponse = CustomerGroup;
95
100
  export interface CustomerRegistrationConfirmRequest {
96
101
  hash: string;
@@ -9,7 +9,7 @@ export interface CartRemoveItemsRequest {
9
9
  }
10
10
  export type CartRemoveItemsResponse = Cart;
11
11
  export interface CartUpdateItemsRequest {
12
- items?: Array<LineItem>;
12
+ items?: Array<Partial<LineItem>>;
13
13
  }
14
14
  export type CartUpdateItemsResponse = Cart;
15
15
  export interface CartDeleteResponse {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/shopware-client",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Third party API client for Shopware 6.",
5
5
  "repository": "devite-io/shopware-client",
6
6
  "license": "MIT",
@@ -1,2 +0,0 @@
1
- import { LineItem } from "../lineItem/LineItem";
2
- export type CartItems = Array<LineItem>;