@faststore/api 2.1.98 → 2.1.102

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.
@@ -16,42 +16,23 @@ export const shouldUpdateShippingData = (
16
16
  return { updateShipping: false, addressChanged: false }
17
17
  }
18
18
 
19
- const selectedAddress = orderForm.shippingData?.selectedAddresses[0]
20
-
21
- if (checkPostalCode(selectedAddress, session.postalCode)) {
22
- return { updateShipping: true, addressChanged: true }
19
+ if (!hasItems(orderForm)) {
20
+ return { updateShipping: false, addressChanged: false }
23
21
  }
24
22
 
23
+ const [selectedAddress] = orderForm?.shippingData?.selectedAddresses ?? []
25
24
  if (
26
- checkGeoCoordinates(
27
- selectedAddress,
28
- session.geoCoordinates,
29
- session.postalCode
30
- )
25
+ checkPostalCode(selectedAddress, session.postalCode) ||
26
+ checkGeoCoordinates(selectedAddress, session.geoCoordinates) ||
27
+ checkAddressType(selectedAddress, session.addressType)
31
28
  ) {
32
29
  return { updateShipping: true, addressChanged: true }
33
30
  }
34
31
 
35
- if (checkAddressType(selectedAddress, session.addressType)) {
36
- return { updateShipping: true, addressChanged: true }
37
- }
38
-
39
- if (!hasItems(orderForm)) {
40
- return { updateShipping: false, addressChanged: false }
41
- }
42
-
43
32
  // The logisticsInfo will always exist if there´s at least one item inside the cart
44
33
  const { logisticsInfo } = orderForm.shippingData!
45
34
 
46
- if (shouldUpdateDeliveryChannel(logisticsInfo, session)) {
47
- return { updateShipping: true, addressChanged: false }
48
- }
49
-
50
- if (shouldUpdateDeliveryMethod(logisticsInfo, session)) {
51
- return { updateShipping: true, addressChanged: false }
52
- }
53
-
54
- if (shouldUpdateDeliveryWindow(logisticsInfo, session)) {
35
+ if (shouldUpdateDeliveryInfo(logisticsInfo, session)) {
55
36
  return { updateShipping: true, addressChanged: false }
56
37
  }
57
38
  return { updateShipping: false, addressChanged: false }
@@ -61,15 +42,13 @@ export const shouldUpdateShippingData = (
61
42
  const hasSessionPostalCodeOrGeoCoordinates = (session: IStoreSession) => {
62
43
  return (
63
44
  !!session.postalCode ||
64
- (session.geoCoordinates &&
65
- session.geoCoordinates.latitude &&
66
- session.geoCoordinates.longitude)
45
+ (session.geoCoordinates?.latitude && session.geoCoordinates?.longitude)
67
46
  )
68
47
  }
69
48
 
70
49
  // Validate if theres a difference between the session postal code and orderForm postal code
71
50
  const checkPostalCode = (
72
- address: CheckoutAddress | null | undefined,
51
+ address: CheckoutAddress | null,
73
52
  postalCode: string | null | undefined
74
53
  ) => {
75
54
  return typeof postalCode === 'string' && address?.postalCode !== postalCode
@@ -77,21 +56,19 @@ const checkPostalCode = (
77
56
 
78
57
  // Validate if theres a difference between the session geoCoords and orderForm geoCoords
79
58
  const checkGeoCoordinates = (
80
- address: CheckoutAddress | null | undefined,
81
- geoCoordinates: IStoreGeoCoordinates | null | undefined,
82
- postalCode: string | null | undefined
59
+ address: CheckoutAddress | null,
60
+ geoCoordinates: IStoreGeoCoordinates | null | undefined
83
61
  ) => {
84
62
  return (
85
63
  typeof geoCoordinates?.latitude === 'number' &&
86
64
  typeof geoCoordinates?.longitude === 'number' &&
87
65
  (address?.geoCoordinates[0] !== geoCoordinates?.longitude ||
88
- address?.geoCoordinates[1] !== geoCoordinates?.latitude) &&
89
- address?.postalCode !== postalCode
66
+ address?.geoCoordinates[1] !== geoCoordinates?.latitude)
90
67
  )
91
68
  }
92
69
 
93
70
  const checkAddressType = (
94
- address: CheckoutAddress | null | undefined,
71
+ address: CheckoutAddress | null,
95
72
  addressType: string | null | undefined
96
73
  ) => {
97
74
  return typeof addressType === 'string' && address?.addressType !== addressType
@@ -102,73 +79,43 @@ const hasItems = (orderForm: OrderForm) => {
102
79
  return orderForm.items.length !== 0
103
80
  }
104
81
 
105
- // Validate if the deliveryChannel from the session is different from the selected delivery channel
106
- // and if so needs to validate if the deliveryChannel for the session is available inside the slas for the item
107
- const shouldUpdateDeliveryChannel = (
82
+ const shouldUpdateDeliveryInfo = (
108
83
  logisticsInfo: LogisticsInfo[],
109
- session: IStoreSession | null | undefined
84
+ session: IStoreSession | null
110
85
  ) => {
111
- if (!session?.deliveryMode?.deliveryChannel) {
112
- return false
113
- }
114
- const { deliveryChannel } = session.deliveryMode
115
- for (const item of logisticsInfo) {
116
- if (item.selectedDeliveryChannel !== deliveryChannel) {
117
- const matchingSla = item.slas.find(
118
- (sla) => sla.deliveryChannel === deliveryChannel
119
- )
120
- if (matchingSla) {
121
- return true
122
- }
86
+ const deliveryChannel = session?.deliveryMode?.deliveryChannel
87
+ const deliveryMethod = session?.deliveryMode?.deliveryMethod
88
+ const { startDate, endDate } = session?.deliveryMode?.deliveryWindow || {}
89
+
90
+ return logisticsInfo.some(
91
+ ({ selectedDeliveryChannel, selectedSla, slas }) => {
92
+ const checkDeliveryChannel =
93
+ deliveryChannel && selectedDeliveryChannel !== deliveryChannel
94
+ const checkDeliveryMethod =
95
+ deliveryMethod && selectedSla !== deliveryMethod
96
+
97
+ return slas?.some((sla) => {
98
+ if (
99
+ (checkDeliveryChannel && sla.deliveryChannel === deliveryChannel) ||
100
+ (checkDeliveryMethod && sla.id === deliveryMethod)
101
+ ) {
102
+ return true
103
+ }
104
+ return (
105
+ startDate &&
106
+ endDate &&
107
+ sla.deliveryChannel === deliveryChannel &&
108
+ sla.id === deliveryMethod &&
109
+ (!sla?.deliveryWindow ||
110
+ sla?.deliveryWindow?.startDateUtc !== startDate ||
111
+ sla?.deliveryWindow?.endDateUtc !== endDate) &&
112
+ sla.availableDeliveryWindows?.some(
113
+ (window) =>
114
+ window?.startDateUtc === startDate &&
115
+ window?.endDateUtc === endDate
116
+ )
117
+ )
118
+ })
123
119
  }
124
- }
125
- return false
126
- }
127
-
128
- // Validate if the deliveryMethod from the session is different from the selectedSLA
129
- // and if so needs to validate if the deliveryMethod for the session is available inside the slas for the item
130
- const shouldUpdateDeliveryMethod = (
131
- logisticsInfo: LogisticsInfo[],
132
- session: IStoreSession
133
- ) => {
134
- if (!session?.deliveryMode?.deliveryMethod) {
135
- return false
136
- }
137
- const { deliveryMethod } = session.deliveryMode
138
- for (const item of logisticsInfo) {
139
- if (item.selectedSla !== deliveryMethod) {
140
- const matchingSla = item.slas.find((sla) => sla.id === deliveryMethod)
141
- if (matchingSla) {
142
- return true
143
- }
144
- }
145
- }
146
- return false
147
- }
148
-
149
- // Validate if the deliveryWindow from the session is different from the deliveryWindow of the SLA
150
- // and if so needs to validate if the deliveryWindow for the session is available inside the availableDeliveryWindows for the item
151
- const shouldUpdateDeliveryWindow = (
152
- logisticsInfo: LogisticsInfo[],
153
- session: IStoreSession
154
- ) => {
155
- if (
156
- !session?.deliveryMode?.deliveryWindow?.startDate ||
157
- !session?.deliveryMode?.deliveryWindow?.endDate
158
- ) {
159
- return false
160
- }
161
- const { startDate, endDate } = session.deliveryMode.deliveryWindow
162
- for (const item of logisticsInfo) {
163
- for (const sla of item.slas) {
164
- const matchingWindow = sla.availableDeliveryWindows?.some(
165
- (window) =>
166
- window.startDateUtc === startDate && window.endDateUtc === endDate
167
- )
168
- if (matchingWindow) {
169
- return true
170
- }
171
- }
172
- }
173
- return false
120
+ )
174
121
  }
@@ -1 +0,0 @@
1
- export default function getCookieByName(cookiename: string, source: string): string;
@@ -1,6 +0,0 @@
1
- export default function getCookieByName(cookiename: string, source: string) {
2
- var cookiestring = RegExp(cookiename + '=[^;]+').exec(source)
3
- return decodeURIComponent(
4
- !!cookiestring ? cookiestring.toString().replace(/^[^=]+./, '') : ''
5
- )
6
- }