@pelcro/react-pelcro-js 2.6.0-beta.4 → 2.6.0-beta.8

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.js CHANGED
@@ -4494,7 +4494,7 @@ var messages$2 = {
4494
4494
  isSureToCancel: "Êtes-vous certain de vouloir annuler votre abonnement?",
4495
4495
  loading: "Annulation de l'abonnement",
4496
4496
  success: "L'abonnement a été annulé avec succès",
4497
- error: "Une erreure s'est produite lors de l'annulation de l'abonnement"
4497
+ error: "Une erreur s'est produite lors de l'annulation de l'abonnement"
4498
4498
  }
4499
4499
  };
4500
4500
  var dashboard_fr = {
@@ -6584,6 +6584,17 @@ const getPaymentCardIcon$1 = name => {
6584
6584
  d: "M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"
6585
6585
  }));
6586
6586
  };
6587
+ /**
6588
+ * Gets the current date with time set to 0
6589
+ * @param {Date} dateObject
6590
+ * @return {Date}
6591
+ */
6592
+
6593
+ function getDateWithoutTime(dateObject) {
6594
+ const date = new Date(dateObject.getTime());
6595
+ date.setHours(0, 0, 0, 0);
6596
+ return date;
6597
+ }
6587
6598
 
6588
6599
  const resources = {
6589
6600
  en: {
@@ -8465,6 +8476,7 @@ const optionsController = options => {
8465
8476
  enableURLTriggers: initViewFromURL,
8466
8477
  enableTheme: applyPelcroTheme,
8467
8478
  enablePaywalls: initPaywalls,
8479
+ loadSecuritySDK: initSecuritySdk,
8468
8480
  enableGoogleAnalytics: initGATracking
8469
8481
  }; // Only execute enabled options
8470
8482
 
@@ -8526,6 +8538,18 @@ const loadPaymentSDKs = () => {
8526
8538
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.69.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
8527
8539
  }
8528
8540
  };
8541
+ const initSecuritySdk = () => {
8542
+ const {
8543
+ whenSiteReady
8544
+ } = usePelcro.getStore();
8545
+ whenSiteReady(() => {
8546
+ var _window$Pelcro$site$r2;
8547
+
8548
+ const securityKey = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.security_key;
8549
+ if (!securityKey) return;
8550
+ window.Pelcro.helpers.loadSDK(`https://www.google.com/recaptcha/enterprise.js?render=${securityKey}`, "pelcro-security-enteprise");
8551
+ });
8552
+ };
8529
8553
  const initGATracking = () => {
8530
8554
  var _ReactGA$initialize, _ReactGA$plugin, _ReactGA$plugin$requi;
8531
8555
 
@@ -8612,9 +8636,9 @@ const applyPelcroTheme = () => {
8612
8636
  };
8613
8637
 
8614
8638
  whenSiteReady(() => {
8615
- var _window$Pelcro$site$r2, _window$Pelcro$site$r3;
8639
+ var _window$Pelcro$site$r3, _window$Pelcro$site$r4;
8616
8640
 
8617
- const primaryColorHex = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : (_window$Pelcro$site$r3 = _window$Pelcro$site$r2.design_settings) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : _window$Pelcro$site$r3.primary_color;
8641
+ const primaryColorHex = (_window$Pelcro$site$r3 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : (_window$Pelcro$site$r4 = _window$Pelcro$site$r3.design_settings) === null || _window$Pelcro$site$r4 === void 0 ? void 0 : _window$Pelcro$site$r4.primary_color;
8618
8642
 
8619
8643
  if (!primaryColorHex) {
8620
8644
  return;
@@ -8813,6 +8837,7 @@ const defaultOptions = {
8813
8837
  enableURLTriggers: true,
8814
8838
  enableTheme: true,
8815
8839
  enablePaywalls: true,
8840
+ loadSecuritySDK: true,
8816
8841
  enableGoogleAnalytics: false
8817
8842
  };
8818
8843
  const PelcroModalController = ({
@@ -9753,35 +9778,53 @@ const RegisterContainer = ({
9753
9778
  jobTitle,
9754
9779
  selectFields
9755
9780
  } = filteredData;
9756
- window.Pelcro.user.register({
9757
- email,
9758
- password,
9759
- first_name: firstName,
9760
- last_name: lastName,
9761
- metadata: {
9762
- organization,
9763
- jobTitle,
9764
- ...selectFields
9765
- }
9766
- }, (err, res) => {
9767
- dispatch({
9768
- type: DISABLE_REGISTRATION_BUTTON,
9769
- payload: false
9781
+
9782
+ if (!hasSecurityTokenEnabled()) {
9783
+ sendRegisterRequest();
9784
+ return;
9785
+ }
9786
+
9787
+ window.grecaptcha.enterprise.ready(async () => {
9788
+ var _window$Pelcro$site$r;
9789
+
9790
+ const token = await window.grecaptcha.enterprise.execute((_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.security_key, {
9791
+ action: "register"
9770
9792
  });
9793
+ sendRegisterRequest(token);
9794
+ });
9771
9795
 
9772
- if (err) {
9796
+ function sendRegisterRequest(securityToken) {
9797
+ window.Pelcro.user.register({
9798
+ email,
9799
+ password,
9800
+ first_name: firstName,
9801
+ last_name: lastName,
9802
+ security_token: securityToken,
9803
+ metadata: {
9804
+ organization,
9805
+ jobTitle,
9806
+ ...selectFields
9807
+ }
9808
+ }, (err, res) => {
9773
9809
  dispatch({
9774
- type: SHOW_ALERT,
9775
- payload: {
9776
- type: "error",
9777
- content: getErrorMessages(err)
9778
- }
9810
+ type: DISABLE_REGISTRATION_BUTTON,
9811
+ payload: false
9779
9812
  });
9780
- onFailure(err);
9781
- } else {
9782
- onSuccess(res);
9783
- }
9784
- });
9813
+
9814
+ if (err) {
9815
+ dispatch({
9816
+ type: SHOW_ALERT,
9817
+ payload: {
9818
+ type: "error",
9819
+ content: getErrorMessages(err)
9820
+ }
9821
+ });
9822
+ onFailure(err);
9823
+ } else {
9824
+ onSuccess(res);
9825
+ }
9826
+ });
9827
+ }
9785
9828
  };
9786
9829
 
9787
9830
  const handleSocialLogin = ({
@@ -9932,6 +9975,15 @@ const RegisterContainer = ({
9932
9975
  store: store$e
9933
9976
  })));
9934
9977
  };
9978
+ /**
9979
+ * Checks if the current site has security token enabled
9980
+ * @return {boolean}
9981
+ */
9982
+
9983
+ function hasSecurityTokenEnabled() {
9984
+ const hasSecuritySdkLoaded = Boolean(window.grecaptcha);
9985
+ return hasSecuritySdkLoaded;
9986
+ }
9935
9987
 
9936
9988
  var _path$l;
9937
9989
 
@@ -10321,8 +10373,11 @@ const RegisterPassword = props => /*#__PURE__*/React__default['default'].createE
10321
10373
  const RegisterButton = ({
10322
10374
  name,
10323
10375
  onClick,
10376
+ className,
10324
10377
  ...otherProps
10325
10378
  }) => {
10379
+ var _window$Pelcro$site$r;
10380
+
10326
10381
  const {
10327
10382
  state: {
10328
10383
  emailError,
@@ -10348,7 +10403,10 @@ const RegisterButton = ({
10348
10403
  onClick === null || onClick === void 0 ? void 0 : onClick();
10349
10404
  },
10350
10405
  disabled: isDisabled,
10351
- isLoading: buttonDisabled
10406
+ isLoading: buttonDisabled,
10407
+ className: `${className} g-recaptcha`,
10408
+ "data-action": "register",
10409
+ "data-sitekey": (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.security_key
10352
10410
  }, otherProps), name !== null && name !== void 0 ? name : t("messages.createAccount"));
10353
10411
  };
10354
10412
 
@@ -13522,7 +13580,16 @@ const PaymentMethodContainerWithoutStripe = ({
13522
13580
  const UnwrappedForm = es_12(PaymentMethodContainerWithoutStripe);
13523
13581
 
13524
13582
  const PaymentMethodContainer = props => {
13525
- if (window.Stripe) {
13583
+ const [isStripeLoaded, setIsStripeLoaded] = React.useState(Boolean(window.Stripe));
13584
+ React.useEffect(() => {
13585
+ if (!window.Stripe) {
13586
+ document.querySelector('script[src="https://js.stripe.com/v3"]').addEventListener("load", () => {
13587
+ setIsStripeLoaded(true);
13588
+ });
13589
+ }
13590
+ }, []);
13591
+
13592
+ if (isStripeLoaded) {
13526
13593
  return /*#__PURE__*/React__default['default'].createElement(es_13, {
13527
13594
  apiKey: window.Pelcro.environment.stripe,
13528
13595
  stripeAccount: window.Pelcro.site.read().account_id,
@@ -18402,9 +18469,9 @@ const GiftCreateContainer = ({
18402
18469
  }
18403
18470
 
18404
18471
  if (giftRecipient.startDate) {
18405
- const nowDate = new Date();
18406
- const yearFromNowDate = new Date(new Date().setFullYear(nowDate.getFullYear() + 1));
18407
- const submittedDate = new Date(giftRecipient.startDate);
18472
+ const nowDate = getDateWithoutTime(new Date());
18473
+ const yearFromNowDate = getDateWithoutTime(new Date(new Date().setFullYear(nowDate.getFullYear() + 1)));
18474
+ const submittedDate = getDateWithoutTime(new Date(giftRecipient.startDate));
18408
18475
 
18409
18476
  if (submittedDate < nowDate || submittedDate > yearFromNowDate) {
18410
18477
  dispatch({
package/dist/index.esm.js CHANGED
@@ -4464,7 +4464,7 @@ var messages$2 = {
4464
4464
  isSureToCancel: "Êtes-vous certain de vouloir annuler votre abonnement?",
4465
4465
  loading: "Annulation de l'abonnement",
4466
4466
  success: "L'abonnement a été annulé avec succès",
4467
- error: "Une erreure s'est produite lors de l'annulation de l'abonnement"
4467
+ error: "Une erreur s'est produite lors de l'annulation de l'abonnement"
4468
4468
  }
4469
4469
  };
4470
4470
  var dashboard_fr = {
@@ -6554,6 +6554,17 @@ const getPaymentCardIcon$1 = name => {
6554
6554
  d: "M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"
6555
6555
  }));
6556
6556
  };
6557
+ /**
6558
+ * Gets the current date with time set to 0
6559
+ * @param {Date} dateObject
6560
+ * @return {Date}
6561
+ */
6562
+
6563
+ function getDateWithoutTime(dateObject) {
6564
+ const date = new Date(dateObject.getTime());
6565
+ date.setHours(0, 0, 0, 0);
6566
+ return date;
6567
+ }
6557
6568
 
6558
6569
  const resources = {
6559
6570
  en: {
@@ -8435,6 +8446,7 @@ const optionsController = options => {
8435
8446
  enableURLTriggers: initViewFromURL,
8436
8447
  enableTheme: applyPelcroTheme,
8437
8448
  enablePaywalls: initPaywalls,
8449
+ loadSecuritySDK: initSecuritySdk,
8438
8450
  enableGoogleAnalytics: initGATracking
8439
8451
  }; // Only execute enabled options
8440
8452
 
@@ -8496,6 +8508,18 @@ const loadPaymentSDKs = () => {
8496
8508
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.69.0/js/paypal-checkout.min.js", "braintree-paypal-sdk");
8497
8509
  }
8498
8510
  };
8511
+ const initSecuritySdk = () => {
8512
+ const {
8513
+ whenSiteReady
8514
+ } = usePelcro.getStore();
8515
+ whenSiteReady(() => {
8516
+ var _window$Pelcro$site$r2;
8517
+
8518
+ const securityKey = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.security_key;
8519
+ if (!securityKey) return;
8520
+ window.Pelcro.helpers.loadSDK(`https://www.google.com/recaptcha/enterprise.js?render=${securityKey}`, "pelcro-security-enteprise");
8521
+ });
8522
+ };
8499
8523
  const initGATracking = () => {
8500
8524
  var _ReactGA$initialize, _ReactGA$plugin, _ReactGA$plugin$requi;
8501
8525
 
@@ -8582,9 +8606,9 @@ const applyPelcroTheme = () => {
8582
8606
  };
8583
8607
 
8584
8608
  whenSiteReady(() => {
8585
- var _window$Pelcro$site$r2, _window$Pelcro$site$r3;
8609
+ var _window$Pelcro$site$r3, _window$Pelcro$site$r4;
8586
8610
 
8587
- const primaryColorHex = (_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : (_window$Pelcro$site$r3 = _window$Pelcro$site$r2.design_settings) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : _window$Pelcro$site$r3.primary_color;
8611
+ const primaryColorHex = (_window$Pelcro$site$r3 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : (_window$Pelcro$site$r4 = _window$Pelcro$site$r3.design_settings) === null || _window$Pelcro$site$r4 === void 0 ? void 0 : _window$Pelcro$site$r4.primary_color;
8588
8612
 
8589
8613
  if (!primaryColorHex) {
8590
8614
  return;
@@ -8783,6 +8807,7 @@ const defaultOptions = {
8783
8807
  enableURLTriggers: true,
8784
8808
  enableTheme: true,
8785
8809
  enablePaywalls: true,
8810
+ loadSecuritySDK: true,
8786
8811
  enableGoogleAnalytics: false
8787
8812
  };
8788
8813
  const PelcroModalController = ({
@@ -9723,35 +9748,53 @@ const RegisterContainer = ({
9723
9748
  jobTitle,
9724
9749
  selectFields
9725
9750
  } = filteredData;
9726
- window.Pelcro.user.register({
9727
- email,
9728
- password,
9729
- first_name: firstName,
9730
- last_name: lastName,
9731
- metadata: {
9732
- organization,
9733
- jobTitle,
9734
- ...selectFields
9735
- }
9736
- }, (err, res) => {
9737
- dispatch({
9738
- type: DISABLE_REGISTRATION_BUTTON,
9739
- payload: false
9751
+
9752
+ if (!hasSecurityTokenEnabled()) {
9753
+ sendRegisterRequest();
9754
+ return;
9755
+ }
9756
+
9757
+ window.grecaptcha.enterprise.ready(async () => {
9758
+ var _window$Pelcro$site$r;
9759
+
9760
+ const token = await window.grecaptcha.enterprise.execute((_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.security_key, {
9761
+ action: "register"
9740
9762
  });
9763
+ sendRegisterRequest(token);
9764
+ });
9741
9765
 
9742
- if (err) {
9766
+ function sendRegisterRequest(securityToken) {
9767
+ window.Pelcro.user.register({
9768
+ email,
9769
+ password,
9770
+ first_name: firstName,
9771
+ last_name: lastName,
9772
+ security_token: securityToken,
9773
+ metadata: {
9774
+ organization,
9775
+ jobTitle,
9776
+ ...selectFields
9777
+ }
9778
+ }, (err, res) => {
9743
9779
  dispatch({
9744
- type: SHOW_ALERT,
9745
- payload: {
9746
- type: "error",
9747
- content: getErrorMessages(err)
9748
- }
9780
+ type: DISABLE_REGISTRATION_BUTTON,
9781
+ payload: false
9749
9782
  });
9750
- onFailure(err);
9751
- } else {
9752
- onSuccess(res);
9753
- }
9754
- });
9783
+
9784
+ if (err) {
9785
+ dispatch({
9786
+ type: SHOW_ALERT,
9787
+ payload: {
9788
+ type: "error",
9789
+ content: getErrorMessages(err)
9790
+ }
9791
+ });
9792
+ onFailure(err);
9793
+ } else {
9794
+ onSuccess(res);
9795
+ }
9796
+ });
9797
+ }
9755
9798
  };
9756
9799
 
9757
9800
  const handleSocialLogin = ({
@@ -9902,6 +9945,15 @@ const RegisterContainer = ({
9902
9945
  store: store$e
9903
9946
  })));
9904
9947
  };
9948
+ /**
9949
+ * Checks if the current site has security token enabled
9950
+ * @return {boolean}
9951
+ */
9952
+
9953
+ function hasSecurityTokenEnabled() {
9954
+ const hasSecuritySdkLoaded = Boolean(window.grecaptcha);
9955
+ return hasSecuritySdkLoaded;
9956
+ }
9905
9957
 
9906
9958
  var _path$l;
9907
9959
 
@@ -10291,8 +10343,11 @@ const RegisterPassword = props => /*#__PURE__*/React__default.createElement(Pass
10291
10343
  const RegisterButton = ({
10292
10344
  name,
10293
10345
  onClick,
10346
+ className,
10294
10347
  ...otherProps
10295
10348
  }) => {
10349
+ var _window$Pelcro$site$r;
10350
+
10296
10351
  const {
10297
10352
  state: {
10298
10353
  emailError,
@@ -10318,7 +10373,10 @@ const RegisterButton = ({
10318
10373
  onClick === null || onClick === void 0 ? void 0 : onClick();
10319
10374
  },
10320
10375
  disabled: isDisabled,
10321
- isLoading: buttonDisabled
10376
+ isLoading: buttonDisabled,
10377
+ className: `${className} g-recaptcha`,
10378
+ "data-action": "register",
10379
+ "data-sitekey": (_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.security_key
10322
10380
  }, otherProps), name !== null && name !== void 0 ? name : t("messages.createAccount"));
10323
10381
  };
10324
10382
 
@@ -13492,7 +13550,16 @@ const PaymentMethodContainerWithoutStripe = ({
13492
13550
  const UnwrappedForm = es_12(PaymentMethodContainerWithoutStripe);
13493
13551
 
13494
13552
  const PaymentMethodContainer = props => {
13495
- if (window.Stripe) {
13553
+ const [isStripeLoaded, setIsStripeLoaded] = useState(Boolean(window.Stripe));
13554
+ useEffect(() => {
13555
+ if (!window.Stripe) {
13556
+ document.querySelector('script[src="https://js.stripe.com/v3"]').addEventListener("load", () => {
13557
+ setIsStripeLoaded(true);
13558
+ });
13559
+ }
13560
+ }, []);
13561
+
13562
+ if (isStripeLoaded) {
13496
13563
  return /*#__PURE__*/React__default.createElement(es_13, {
13497
13564
  apiKey: window.Pelcro.environment.stripe,
13498
13565
  stripeAccount: window.Pelcro.site.read().account_id,
@@ -18372,9 +18439,9 @@ const GiftCreateContainer = ({
18372
18439
  }
18373
18440
 
18374
18441
  if (giftRecipient.startDate) {
18375
- const nowDate = new Date();
18376
- const yearFromNowDate = new Date(new Date().setFullYear(nowDate.getFullYear() + 1));
18377
- const submittedDate = new Date(giftRecipient.startDate);
18442
+ const nowDate = getDateWithoutTime(new Date());
18443
+ const yearFromNowDate = getDateWithoutTime(new Date(new Date().setFullYear(nowDate.getFullYear() + 1)));
18444
+ const submittedDate = getDateWithoutTime(new Date(giftRecipient.startDate));
18378
18445
 
18379
18446
  if (submittedDate < nowDate || submittedDate > yearFromNowDate) {
18380
18447
  dispatch({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pelcro/react-pelcro-js",
3
3
  "description": "Pelcro's React UI Elements",
4
- "version": "2.6.0-beta.4",
4
+ "version": "2.6.0-beta.8",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "main": "dist/index.cjs.js",
@@ -59,7 +59,6 @@
59
59
  "browserslist": "^4.16.3",
60
60
  "cross-env": "^7.0.3",
61
61
  "css-loader": "^3.2.0",
62
- "cssimportant-loader": "^0.4.0",
63
62
  "cz-conventional-changelog": "3.3.0",
64
63
  "eslint": "^7.19.0",
65
64
  "eslint-config-google": "^0.14.0",
@@ -74,7 +73,6 @@
74
73
  "html-webpack-plugin": "^3.2.0",
75
74
  "image-webpack-loader": "^7.0.1",
76
75
  "jest": "^26.6.3",
77
- "node-sass": "^4.14.1",
78
76
  "postcss": "^8.2.4",
79
77
  "postcss-import": "^14.0.0",
80
78
  "postcss-loader": "4.2.0",
@@ -92,7 +90,6 @@
92
90
  "rollup-plugin-peer-deps-external": "^2.2.4",
93
91
  "rollup-plugin-postcss": "^4.0.0",
94
92
  "rollup-plugin-visualizer": "^4.2.0",
95
- "sass-loader": "^7.1.0",
96
93
  "semantic-release": "^17.4.4",
97
94
  "simple-zustand-devtools": "^1.0.0",
98
95
  "style-loader": "^2.0.0",