@akinon/next 1.15.0 → 1.16.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.
@@ -18,8 +18,6 @@ export const usePaymentOptions = () => {
18
18
  pay_on_delivery: 'pz-pay-on-delivery',
19
19
  bkm_express: 'pz-bkm',
20
20
  credit_payment: 'pz-credit-payment',
21
- masterpass: 'pz-masterpass',
22
- gpay: 'pz-gpay',
23
21
  };
24
22
 
25
23
  const isInitialTypeIncluded = (type: string) => initialTypes.has(type);
@@ -0,0 +1,5 @@
1
+ export async function register() {
2
+ if (process.env.NEXT_RUNTIME === 'nodejs') {
3
+ await import('./node');
4
+ }
5
+ }
@@ -0,0 +1,20 @@
1
+ import { NodeSDK } from '@opentelemetry/sdk-node';
2
+ import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
3
+ import { Resource } from '@opentelemetry/resources';
4
+ import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
5
+ import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';
6
+
7
+ const sdk = new NodeSDK({
8
+ resource: new Resource({
9
+ [SemanticResourceAttributes.SERVICE_NAME]: 'pz-next-app'
10
+ }),
11
+ spanProcessor: new SimpleSpanProcessor(
12
+ new OTLPTraceExporter({
13
+ url: `${
14
+ process.env.PZ_DASHBOARD_URL ?? 'http://localhost:3005'
15
+ }/api/traces`
16
+ })
17
+ )
18
+ });
19
+
20
+ sdk.start();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "1.15.0",
4
+ "version": "1.16.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -14,6 +14,11 @@
14
14
  "pz-postdev": "bin/pz-postdev.js"
15
15
  },
16
16
  "dependencies": {
17
+ "@opentelemetry/sdk-node": "0.46.0",
18
+ "@opentelemetry/exporter-trace-otlp-http": "0.46.0",
19
+ "@opentelemetry/resources": "1.19.0",
20
+ "@opentelemetry/semantic-conventions": "1.19.0",
21
+ "@opentelemetry/sdk-trace-node": "1.19.0",
17
22
  "@reduxjs/toolkit": "1.9.7",
18
23
  "cross-spawn": "7.0.3",
19
24
  "react-redux": "8.1.3",
@@ -26,7 +31,7 @@
26
31
  "@typescript-eslint/eslint-plugin": "6.7.4",
27
32
  "@typescript-eslint/parser": "6.7.4",
28
33
  "eslint": "^8.14.0",
29
- "@akinon/eslint-plugin-projectzero": "1.15.0",
34
+ "@akinon/eslint-plugin-projectzero": "1.16.0",
30
35
  "eslint-config-prettier": "8.5.0"
31
36
  }
32
37
  }
package/plugins.js CHANGED
@@ -8,5 +8,4 @@ module.exports = [
8
8
  'pz-otp',
9
9
  'pz-bkm',
10
10
  'pz-credit-payment',
11
- 'pz-masterpass'
12
11
  ];
@@ -1,265 +1,265 @@
1
- 'use client';
2
-
3
- import { Middleware } from '@reduxjs/toolkit';
4
- import {
5
- setAddressList,
6
- setBankAccounts,
7
- setCanGuestPurchase,
8
- setCardType,
9
- setDeliveryOptions,
10
- setErrors,
11
- setHasGiftBox,
12
- setInstallmentOptions,
13
- setLoyaltyBalance,
14
- setPaymentChoices,
15
- setPaymentOptions,
16
- setPreOrder,
17
- setRetailStores,
18
- setShippingOptions,
19
- setShippingStepCompleted,
20
- setCreditPaymentOptions
21
- } from '../../redux/reducers/checkout';
22
- import { RootState, TypedDispatch } from 'redux/store';
23
- import { checkoutApi } from '../../data/client/checkout';
24
- import { CheckoutContext, PreOrder } from '../../types';
25
- import { getCookie, setCookie } from '../../utils';
26
- import settings from 'settings';
27
- import { LocaleUrlStrategy } from '../../localization';
28
- import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
29
-
30
- interface CheckoutResult {
31
- payload: {
32
- errors?: any;
33
- pre_order?: PreOrder;
34
- context_list?: CheckoutContext[];
35
- };
36
- }
37
-
38
- interface MiddlewareParams {
39
- getState: () => RootState;
40
- dispatch: TypedDispatch;
41
- }
42
-
43
- export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
44
- return (next) => (action) => {
45
- const result: CheckoutResult = next(action);
46
- const errors = result?.payload?.errors;
47
-
48
- if (errors) {
49
- dispatch(setErrors(errors));
50
- }
51
-
52
- return result;
53
- };
54
- };
55
-
56
- export const preOrderMiddleware: Middleware = ({
57
- getState,
58
- dispatch
59
- }: MiddlewareParams) => {
60
- return (next) => (action) => {
61
- const result: CheckoutResult = next(action);
62
- const preOrder = result?.payload?.pre_order;
63
-
64
- if (
65
- !preOrder ||
66
- action?.meta?.arg?.endpointName === 'guestLogin' ||
67
- action?.meta?.arg?.endpointName === 'getCheckoutLoyaltyBalance'
68
- ) {
69
- return result;
70
- }
71
-
72
- const {
73
- deliveryOptions,
74
- addressList: addresses,
75
- shippingOptions,
76
- paymentOptions,
77
- installmentOptions
78
- } = getState().checkout;
79
- const { endpoints: apiEndpoints } = checkoutApi;
80
-
81
- if (preOrder.is_redirected) {
82
- const contextList = result?.payload?.context_list;
83
-
84
- if (
85
- contextList.find(
86
- (ctx) => ctx.page_name === 'RedirectionPaymentSelectedPage'
87
- )
88
- ) {
89
- dispatch(
90
- apiEndpoints.setPaymentOption.initiate(preOrder.payment_option?.pk)
91
- );
92
- return;
93
- }
94
- }
95
-
96
- dispatch(setPreOrder(preOrder));
97
-
98
- if (!preOrder.delivery_option && deliveryOptions.length > 0) {
99
- dispatch(
100
- apiEndpoints.setDeliveryOption.initiate(
101
- deliveryOptions.find((opt) => opt.delivery_option_type === 'customer')
102
- ?.pk
103
- )
104
- );
105
- }
106
-
107
- if (
108
- (!preOrder.shipping_address || !preOrder.billing_address) &&
109
- addresses.length > 0 &&
110
- preOrder.delivery_option?.delivery_option_type === 'customer'
111
- ) {
112
- dispatch(
113
- apiEndpoints.setAddresses.initiate({
114
- shippingAddressPk: addresses[0].pk,
115
- billingAddressPk: addresses[0].pk
116
- })
117
- );
118
- }
119
-
120
- if (
121
- shippingOptions.length > 0 &&
122
- (!preOrder.shipping_option ||
123
- !shippingOptions.find((opt) => opt.pk === preOrder.shipping_option?.pk))
124
- ) {
125
- dispatch(apiEndpoints.setShippingOption.initiate(shippingOptions[0].pk));
126
- }
127
-
128
- if (!preOrder.payment_option && paymentOptions.length > 0) {
129
- dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
130
- }
131
-
132
- if (!preOrder.installment && installmentOptions.length > 0) {
133
- dispatch(
134
- apiEndpoints.setInstallmentOption.initiate(installmentOptions[0].pk)
135
- );
136
- }
137
-
138
- dispatch(
139
- setShippingStepCompleted(
140
- [
141
- preOrder.delivery_option?.delivery_option_type === 'retail_store'
142
- ? true
143
- : preOrder.shipping_address?.pk,
144
- preOrder.billing_address?.pk,
145
- preOrder.shipping_option?.pk,
146
- addresses.length > 0
147
- ].every(Boolean)
148
- )
149
- );
150
-
151
- return result;
152
- };
153
- };
154
-
155
- export const contextListMiddleware: Middleware = ({
156
- dispatch,
157
- getState
158
- }: MiddlewareParams) => {
159
- return (next) => (action) => {
160
- const { isMobileApp } = getState().root;
161
- const result: CheckoutResult = next(action);
162
-
163
- if (result?.payload?.context_list) {
164
- result.payload.context_list.forEach((context) => {
165
- const redirectUrl = context.page_context.redirect_url;
166
-
167
- if (redirectUrl) {
168
- const currentLocale = getCookie('pz-locale');
169
-
170
- let url = redirectUrl;
171
-
172
- if (currentLocale && !redirectUrl.includes('/orders/redirection')) {
173
- const { defaultLocaleValue, localeUrlStrategy } =
174
- settings.localization;
175
-
176
- url =
177
- currentLocale === defaultLocaleValue &&
178
- localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
179
- ? redirectUrl
180
- : `/${currentLocale}${redirectUrl}`;
181
- }
182
-
183
- const urlObj = new URL(url, window.location.origin);
184
- urlObj.searchParams.set('t', new Date().getTime().toString());
185
-
186
- if (
187
- (isMobileApp ||
188
- /iPad|iPhone|iPod|Android/i.test(navigator.userAgent)) &&
189
- !settings.checkout?.iframeExcludedPaymentOptions?.includes(
190
- result.payload?.pre_order?.payment_option?.slug
191
- )
192
- ) {
193
- showMobile3dIframe(urlObj.toString());
194
- } else {
195
- window.location.href = urlObj.toString();
196
- }
197
-
198
- return;
199
- }
200
-
201
- if (context.page_context.has_gift_box) {
202
- dispatch(setHasGiftBox(context.page_context.has_gift_box));
203
- }
204
-
205
- if (typeof context.page_context.can_guest_purchase === 'boolean') {
206
- dispatch(
207
- setCanGuestPurchase(context.page_context.can_guest_purchase)
208
- );
209
- }
210
-
211
- if (context.page_context.delivery_options) {
212
- dispatch(setDeliveryOptions(context.page_context.delivery_options));
213
- }
214
-
215
- if (context.page_context.addresses) {
216
- dispatch(setAddressList(context.page_context.addresses));
217
- }
218
-
219
- if (context.page_context.shipping_options) {
220
- dispatch(setShippingOptions(context.page_context.shipping_options));
221
- }
222
-
223
- if (context.page_context.payment_options) {
224
- dispatch(setPaymentOptions(context.page_context.payment_options));
225
- }
226
-
227
- if (context.page_context.credit_payment_options) {
228
- dispatch(setCreditPaymentOptions(context.page_context.credit_payment_options));
229
- }
230
-
231
- if (context.page_context.payment_choices) {
232
- dispatch(setPaymentChoices(context.page_context.payment_choices));
233
- }
234
-
235
- if (context.page_context.bank_accounts) {
236
- dispatch(setBankAccounts(context.page_context.bank_accounts));
237
- }
238
-
239
- if (
240
- !result.payload.context_list.find(
241
- (ctx) => ctx.page_name === 'DeliveryOptionSelectionPage'
242
- )
243
- ) {
244
- if (context.page_context.card_type) {
245
- dispatch(setCardType(context.page_context.card_type));
246
- }
247
-
248
- if (context.page_context.installments) {
249
- dispatch(setInstallmentOptions(context.page_context.installments));
250
- }
251
- }
252
-
253
- if (context.page_context.balance) {
254
- dispatch(setLoyaltyBalance(context.page_context.balance));
255
- }
256
-
257
- if (context.page_context.retail_stores) {
258
- dispatch(setRetailStores(context.page_context.retail_stores));
259
- }
260
- });
261
- }
262
-
263
- return result;
264
- };
265
- };
1
+ 'use client';
2
+
3
+ import { Middleware } from '@reduxjs/toolkit';
4
+ import {
5
+ setAddressList,
6
+ setBankAccounts,
7
+ setCanGuestPurchase,
8
+ setCardType,
9
+ setDeliveryOptions,
10
+ setErrors,
11
+ setHasGiftBox,
12
+ setInstallmentOptions,
13
+ setLoyaltyBalance,
14
+ setPaymentChoices,
15
+ setPaymentOptions,
16
+ setPreOrder,
17
+ setRetailStores,
18
+ setShippingOptions,
19
+ setShippingStepCompleted,
20
+ setCreditPaymentOptions
21
+ } from '../../redux/reducers/checkout';
22
+ import { RootState, TypedDispatch } from 'redux/store';
23
+ import { checkoutApi } from '../../data/client/checkout';
24
+ import { CheckoutContext, PreOrder } from '../../types';
25
+ import { getCookie, setCookie } from '../../utils';
26
+ import settings from 'settings';
27
+ import { LocaleUrlStrategy } from '../../localization';
28
+ import { showMobile3dIframe } from '../../utils/mobile-3d-iframe';
29
+
30
+ interface CheckoutResult {
31
+ payload: {
32
+ errors?: any;
33
+ pre_order?: PreOrder;
34
+ context_list?: CheckoutContext[];
35
+ };
36
+ }
37
+
38
+ interface MiddlewareParams {
39
+ getState: () => RootState;
40
+ dispatch: TypedDispatch;
41
+ }
42
+
43
+ export const errorMiddleware: Middleware = ({ dispatch }: MiddlewareParams) => {
44
+ return (next) => (action) => {
45
+ const result: CheckoutResult = next(action);
46
+ const errors = result?.payload?.errors;
47
+
48
+ if (errors) {
49
+ dispatch(setErrors(errors));
50
+ }
51
+
52
+ return result;
53
+ };
54
+ };
55
+
56
+ export const preOrderMiddleware: Middleware = ({
57
+ getState,
58
+ dispatch
59
+ }: MiddlewareParams) => {
60
+ return (next) => (action) => {
61
+ const result: CheckoutResult = next(action);
62
+ const preOrder = result?.payload?.pre_order;
63
+
64
+ if (
65
+ !preOrder ||
66
+ action?.meta?.arg?.endpointName === 'guestLogin' ||
67
+ action?.meta?.arg?.endpointName === 'getCheckoutLoyaltyBalance'
68
+ ) {
69
+ return result;
70
+ }
71
+
72
+ const {
73
+ deliveryOptions,
74
+ addressList: addresses,
75
+ shippingOptions,
76
+ paymentOptions,
77
+ installmentOptions
78
+ } = getState().checkout;
79
+ const { endpoints: apiEndpoints } = checkoutApi;
80
+
81
+ if (preOrder.is_redirected) {
82
+ const contextList = result?.payload?.context_list;
83
+
84
+ if (
85
+ contextList.find(
86
+ (ctx) => ctx.page_name === 'RedirectionPaymentSelectedPage'
87
+ )
88
+ ) {
89
+ dispatch(
90
+ apiEndpoints.setPaymentOption.initiate(preOrder.payment_option?.pk)
91
+ );
92
+ return;
93
+ }
94
+ }
95
+
96
+ dispatch(setPreOrder(preOrder));
97
+
98
+ if (!preOrder.delivery_option && deliveryOptions.length > 0) {
99
+ dispatch(
100
+ apiEndpoints.setDeliveryOption.initiate(
101
+ deliveryOptions.find((opt) => opt.delivery_option_type === 'customer')
102
+ ?.pk
103
+ )
104
+ );
105
+ }
106
+
107
+ if (
108
+ (!preOrder.shipping_address || !preOrder.billing_address) &&
109
+ addresses.length > 0 &&
110
+ preOrder.delivery_option?.delivery_option_type === 'customer'
111
+ ) {
112
+ dispatch(
113
+ apiEndpoints.setAddresses.initiate({
114
+ shippingAddressPk: addresses[0].pk,
115
+ billingAddressPk: addresses[0].pk
116
+ })
117
+ );
118
+ }
119
+
120
+ if (
121
+ shippingOptions.length > 0 &&
122
+ (!preOrder.shipping_option ||
123
+ !shippingOptions.find((opt) => opt.pk === preOrder.shipping_option?.pk))
124
+ ) {
125
+ dispatch(apiEndpoints.setShippingOption.initiate(shippingOptions[0].pk));
126
+ }
127
+
128
+ if (!preOrder.payment_option && paymentOptions.length > 0) {
129
+ dispatch(apiEndpoints.setPaymentOption.initiate(paymentOptions[0].pk));
130
+ }
131
+
132
+ if (!preOrder.installment && installmentOptions.length > 0) {
133
+ dispatch(
134
+ apiEndpoints.setInstallmentOption.initiate(installmentOptions[0].pk)
135
+ );
136
+ }
137
+
138
+ dispatch(
139
+ setShippingStepCompleted(
140
+ [
141
+ preOrder.delivery_option?.delivery_option_type === 'retail_store'
142
+ ? true
143
+ : preOrder.shipping_address?.pk,
144
+ preOrder.billing_address?.pk,
145
+ preOrder.shipping_option?.pk,
146
+ addresses.length > 0
147
+ ].every(Boolean)
148
+ )
149
+ );
150
+
151
+ return result;
152
+ };
153
+ };
154
+
155
+ export const contextListMiddleware: Middleware = ({
156
+ dispatch,
157
+ getState
158
+ }: MiddlewareParams) => {
159
+ return (next) => (action) => {
160
+ const { isMobileApp } = getState().root;
161
+ const result: CheckoutResult = next(action);
162
+
163
+ if (result?.payload?.context_list) {
164
+ result.payload.context_list.forEach((context) => {
165
+ const redirectUrl = context.page_context.redirect_url;
166
+
167
+ if (redirectUrl) {
168
+ const currentLocale = getCookie('pz-locale');
169
+
170
+ let url = redirectUrl;
171
+
172
+ if (currentLocale && !redirectUrl.includes('/orders/redirection')) {
173
+ const { defaultLocaleValue, localeUrlStrategy } =
174
+ settings.localization;
175
+
176
+ url =
177
+ currentLocale === defaultLocaleValue &&
178
+ localeUrlStrategy !== LocaleUrlStrategy.ShowAllLocales
179
+ ? redirectUrl
180
+ : `/${currentLocale}${redirectUrl}`;
181
+ }
182
+
183
+ const urlObj = new URL(url, window.location.origin);
184
+ urlObj.searchParams.set('t', new Date().getTime().toString());
185
+
186
+ if (
187
+ (isMobileApp ||
188
+ /iPad|iPhone|iPod|Android/i.test(navigator.userAgent)) &&
189
+ !settings.checkout?.iframeExcludedPaymentOptions?.includes(
190
+ result.payload?.pre_order?.payment_option?.slug
191
+ )
192
+ ) {
193
+ showMobile3dIframe(urlObj.toString());
194
+ } else {
195
+ window.location.href = urlObj.toString();
196
+ }
197
+
198
+ return;
199
+ }
200
+
201
+ if (context.page_context.has_gift_box) {
202
+ dispatch(setHasGiftBox(context.page_context.has_gift_box));
203
+ }
204
+
205
+ if (typeof context.page_context.can_guest_purchase === 'boolean') {
206
+ dispatch(
207
+ setCanGuestPurchase(context.page_context.can_guest_purchase)
208
+ );
209
+ }
210
+
211
+ if (context.page_context.delivery_options) {
212
+ dispatch(setDeliveryOptions(context.page_context.delivery_options));
213
+ }
214
+
215
+ if (context.page_context.addresses) {
216
+ dispatch(setAddressList(context.page_context.addresses));
217
+ }
218
+
219
+ if (context.page_context.shipping_options) {
220
+ dispatch(setShippingOptions(context.page_context.shipping_options));
221
+ }
222
+
223
+ if (context.page_context.payment_options) {
224
+ dispatch(setPaymentOptions(context.page_context.payment_options));
225
+ }
226
+
227
+ if (context.page_context.credit_payment_options) {
228
+ dispatch(setCreditPaymentOptions(context.page_context.credit_payment_options));
229
+ }
230
+
231
+ if (context.page_context.payment_choices) {
232
+ dispatch(setPaymentChoices(context.page_context.payment_choices));
233
+ }
234
+
235
+ if (context.page_context.bank_accounts) {
236
+ dispatch(setBankAccounts(context.page_context.bank_accounts));
237
+ }
238
+
239
+ if (
240
+ !result.payload.context_list.find(
241
+ (ctx) => ctx.page_name === 'DeliveryOptionSelectionPage'
242
+ )
243
+ ) {
244
+ if (context.page_context.card_type) {
245
+ dispatch(setCardType(context.page_context.card_type));
246
+ }
247
+
248
+ if (context.page_context.installments) {
249
+ dispatch(setInstallmentOptions(context.page_context.installments));
250
+ }
251
+ }
252
+
253
+ if (context.page_context.balance) {
254
+ dispatch(setLoyaltyBalance(context.page_context.balance));
255
+ }
256
+
257
+ if (context.page_context.retail_stores) {
258
+ dispatch(setRetailStores(context.page_context.retail_stores));
259
+ }
260
+ });
261
+ }
262
+
263
+ return result;
264
+ };
265
+ };
@@ -1,15 +1,15 @@
1
- import rootReducer from './root';
2
- import checkoutReducer from './checkout';
3
- import configReducer from './config';
4
- import headerReducer from './header';
5
- import { api } from '../../data/client/api';
6
-
7
- const reducers = {
8
- [api.reducerPath]: api.reducer,
9
- root: rootReducer,
10
- checkout: checkoutReducer,
11
- config: configReducer,
12
- header: headerReducer
13
- };
14
-
1
+ import rootReducer from './root';
2
+ import checkoutReducer from './checkout';
3
+ import configReducer from './config';
4
+ import headerReducer from './header';
5
+ import { api } from '../../data/client/api';
6
+
7
+ const reducers = {
8
+ [api.reducerPath]: api.reducer,
9
+ root: rootReducer,
10
+ checkout: checkoutReducer,
11
+ config: configReducer,
12
+ header: headerReducer
13
+ };
14
+
15
15
  export default reducers;