swell-js 3.17.1 → 3.17.4

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/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright 2019 Schema Technologies, LLC
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Swell Commerce Corp.
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
6
 
@@ -1,18 +1,18 @@
1
1
  import { c as cardApi } from './card-2f5f9866.js';
2
- import { g as getCookie, s as setCookie } from './cookie-a39e556c.js';
2
+ import { g as getCookie, s as setCookie } from './cookie-ae3f44a7.js';
3
3
  import { f as trimEnd, e as trimStart, c as trimBoth, b as toSnake, h as stringifyQuery, n as base64Encode, t as toCamel, s as setOptions } from './index-bce8d606.js';
4
4
  import { c as cacheApi } from './cache-54abc38e.js';
5
- import { m as methods } from './cart-bdec9379.js';
5
+ import { m as methods } from './cart-21650912.js';
6
6
  import { m as methods$1 } from './account-328cc590.js';
7
- import { m as methods$2 } from './products-a6a43be8.js';
7
+ import { m as methods$2 } from './products-baf505e7.js';
8
8
  import { m as methods$3 } from './categories-e52bebe3.js';
9
9
  import { m as methods$4 } from './attributes-db35134e.js';
10
- import { m as methods$5 } from './subscriptions-eecdd4ff.js';
10
+ import { m as methods$5 } from './subscriptions-0e44e99f.js';
11
11
  import { m as methods$6 } from './content-eb42ecce.js';
12
12
  import { m as methods$7 } from './settings-b1a4a4af.js';
13
- import { m as methods$8 } from './payment-91a15202.js';
14
- import { m as methods$9 } from './locale-9de8dba1.js';
15
- import { m as methods$a } from './currency-209bb202.js';
13
+ import { m as methods$8 } from './payment-fd4a2cbe.js';
14
+ import { m as methods$9 } from './locale-bd31bf45.js';
15
+ import { m as methods$a } from './currency-0ff55be3.js';
16
16
 
17
17
  require('isomorphic-fetch');
18
18
 
package/dist/api.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as default } from './api-4f78f947.js';
1
+ export { a as default } from './api-d6447d7e.js';
2
2
  import './card-2f5f9866.js';
3
3
  import './index-bce8d606.js';
4
4
  import 'qs';
@@ -14,21 +14,21 @@ import 'lodash/cloneDeep';
14
14
  import 'lodash/isEqual';
15
15
  import 'deepmerge';
16
16
  import 'object-keys-normalizer';
17
- import './cookie-a39e556c.js';
17
+ import './cookie-ae3f44a7.js';
18
18
  import './cache-54abc38e.js';
19
- import './cart-bdec9379.js';
20
- import './products-a6a43be8.js';
19
+ import './cart-21650912.js';
20
+ import './products-baf505e7.js';
21
21
  import './attributes-db35134e.js';
22
22
  import './account-328cc590.js';
23
23
  import './categories-e52bebe3.js';
24
- import './subscriptions-eecdd4ff.js';
24
+ import './subscriptions-0e44e99f.js';
25
25
  import './content-eb42ecce.js';
26
26
  import './settings-b1a4a4af.js';
27
- import './payment-91a15202.js';
27
+ import './payment-fd4a2cbe.js';
28
28
  import 'lodash/toLower';
29
29
  import 'lodash/reduce';
30
30
  import 'lodash/isEmpty';
31
31
  import 'lodash/map';
32
32
  import 'lodash/toNumber';
33
- import './locale-9de8dba1.js';
34
- import './currency-209bb202.js';
33
+ import './locale-bd31bf45.js';
34
+ import './currency-0ff55be3.js';
@@ -11,7 +11,7 @@ import cloneDeep from 'lodash/cloneDeep';
11
11
  import 'lodash/isEqual';
12
12
  import 'deepmerge';
13
13
  import 'object-keys-normalizer';
14
- import { c as cleanProductOptions } from './products-a6a43be8.js';
14
+ import { c as cleanProductOptions } from './products-baf505e7.js';
15
15
 
16
16
  function methods(request, options) {
17
17
  return {
package/dist/cart.js CHANGED
@@ -1,4 +1,4 @@
1
- export { m as default } from './cart-bdec9379.js';
1
+ export { m as default } from './cart-21650912.js';
2
2
  import 'qs';
3
3
  import 'lodash/set';
4
4
  import 'lodash/get';
@@ -12,7 +12,7 @@ import 'lodash/cloneDeep';
12
12
  import 'lodash/isEqual';
13
13
  import 'deepmerge';
14
14
  import 'object-keys-normalizer';
15
- import './products-a6a43be8.js';
15
+ import './products-baf505e7.js';
16
16
  import './index-bce8d606.js';
17
17
  import './cache-54abc38e.js';
18
18
  import './attributes-db35134e.js';
@@ -1,5 +1,7 @@
1
1
  import { i as isServer } from './index-bce8d606.js';
2
2
 
3
+ const COOKIE_MAX_AGE = 604800; // 1 week
4
+
3
5
  function getCookie(name) {
4
6
  if (isServer()) {
5
7
  return undefined;
@@ -18,12 +20,11 @@ function setCookie(name, value, options = {}) {
18
20
  return;
19
21
  }
20
22
 
21
- const date = new Date();
22
-
23
- date.setDate(date.getDate() + 7); // 1 week
23
+ // default cookie options, which can be overridden
24
24
  options = {
25
25
  path: '/',
26
- expires: date.toUTCString(),
26
+ 'max-age': COOKIE_MAX_AGE,
27
+ samesite: 'lax',
27
28
  ...options,
28
29
  };
29
30
 
package/dist/cookie.js CHANGED
@@ -1,4 +1,4 @@
1
- export { g as getCookie, s as setCookie } from './cookie-a39e556c.js';
1
+ export { g as getCookie, s as setCookie } from './cookie-ae3f44a7.js';
2
2
  import './index-bce8d606.js';
3
3
  import 'qs';
4
4
  import 'lodash/set';
@@ -11,7 +11,7 @@ import 'lodash/cloneDeep';
11
11
  import 'lodash/isEqual';
12
12
  import 'deepmerge';
13
13
  import 'object-keys-normalizer';
14
- import { g as getCookie, s as setCookie } from './cookie-a39e556c.js';
14
+ import { g as getCookie, s as setCookie } from './cookie-ae3f44a7.js';
15
15
 
16
16
  const FORMATTERS = {};
17
17
 
package/dist/currency.js CHANGED
@@ -1,4 +1,4 @@
1
- export { m as default } from './currency-209bb202.js';
1
+ export { m as default } from './currency-0ff55be3.js';
2
2
  import 'qs';
3
3
  import 'lodash/set';
4
4
  import 'lodash/get';
@@ -12,5 +12,5 @@ import 'lodash/cloneDeep';
12
12
  import 'lodash/isEqual';
13
13
  import 'deepmerge';
14
14
  import 'object-keys-normalizer';
15
- import './cookie-a39e556c.js';
15
+ import './cookie-ae3f44a7.js';
16
16
  import './index-bce8d606.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { q as utils } from './index-bce8d606.js';
2
- export { a as default } from './api-4f78f947.js';
2
+ export { a as default } from './api-d6447d7e.js';
3
3
  import 'qs';
4
4
  import 'lodash/set';
5
5
  import 'lodash/get';
@@ -14,21 +14,21 @@ import 'lodash/isEqual';
14
14
  import 'deepmerge';
15
15
  import 'object-keys-normalizer';
16
16
  import './card-2f5f9866.js';
17
- import './cookie-a39e556c.js';
17
+ import './cookie-ae3f44a7.js';
18
18
  import './cache-54abc38e.js';
19
- import './cart-bdec9379.js';
20
- import './products-a6a43be8.js';
19
+ import './cart-21650912.js';
20
+ import './products-baf505e7.js';
21
21
  import './attributes-db35134e.js';
22
22
  import './account-328cc590.js';
23
23
  import './categories-e52bebe3.js';
24
- import './subscriptions-eecdd4ff.js';
24
+ import './subscriptions-0e44e99f.js';
25
25
  import './content-eb42ecce.js';
26
26
  import './settings-b1a4a4af.js';
27
- import './payment-91a15202.js';
27
+ import './payment-fd4a2cbe.js';
28
28
  import 'lodash/toLower';
29
29
  import 'lodash/reduce';
30
30
  import 'lodash/isEmpty';
31
31
  import 'lodash/map';
32
32
  import 'lodash/toNumber';
33
- import './locale-9de8dba1.js';
34
- import './currency-209bb202.js';
33
+ import './locale-bd31bf45.js';
34
+ import './currency-0ff55be3.js';
@@ -11,7 +11,7 @@ import 'lodash/cloneDeep';
11
11
  import 'lodash/isEqual';
12
12
  import 'deepmerge';
13
13
  import 'object-keys-normalizer';
14
- import { s as setCookie, g as getCookie } from './cookie-a39e556c.js';
14
+ import { s as setCookie, g as getCookie } from './cookie-ae3f44a7.js';
15
15
 
16
16
  function methods(request, opt) {
17
17
  return {
package/dist/locale.js CHANGED
@@ -1,4 +1,4 @@
1
- export { m as default } from './locale-9de8dba1.js';
1
+ export { m as default } from './locale-bd31bf45.js';
2
2
  import 'qs';
3
3
  import 'lodash/set';
4
4
  import 'lodash/get';
@@ -12,5 +12,5 @@ import 'lodash/cloneDeep';
12
12
  import 'lodash/isEqual';
13
13
  import 'deepmerge';
14
14
  import 'object-keys-normalizer';
15
- import './cookie-a39e556c.js';
15
+ import './cookie-ae3f44a7.js';
16
16
  import './index-bce8d606.js';
@@ -1,6 +1,6 @@
1
1
  import get from 'lodash/get';
2
2
  import toLower from 'lodash/toLower';
3
- import { m as methods$1 } from './cart-bdec9379.js';
3
+ import { m as methods$1 } from './cart-21650912.js';
4
4
  import { m as methods$2 } from './settings-b1a4a4af.js';
5
5
  import { b as toSnake, v as vaultRequest, j as isFunction, o as getLocationParams, p as removeUrlParams } from './index-bce8d606.js';
6
6
  import reduce from 'lodash/reduce';
@@ -465,12 +465,12 @@ function methods(request, opts) {
465
465
 
466
466
  async createElements(elementParams) {
467
467
  this.params = elementParams || {};
468
- const cart = toSnake(await methods$1.methods(request, options).get());
468
+ const cart = toSnake(await methods$1(request, options).get());
469
469
  if (!cart) {
470
470
  throw new Error('Cart not found');
471
471
  }
472
472
  const payMethods = toSnake(
473
- await methods$2.methods(request, options).payments(),
473
+ await methods$2(request, options).payments(),
474
474
  );
475
475
  if (payMethods.error) {
476
476
  throw new Error(payMethods.error);
@@ -479,12 +479,12 @@ function methods(request, opts) {
479
479
  },
480
480
 
481
481
  async tokenize(params) {
482
- const cart = toSnake(await methods$1.methods(request, options).get());
482
+ const cart = toSnake(await methods$1(request, options).get());
483
483
  if (!cart) {
484
484
  throw new Error('Cart not found');
485
485
  }
486
486
  const payMethods = toSnake(
487
- await methods$2.methods(request, options).payments(),
487
+ await methods$2(request, options).payments(),
488
488
  );
489
489
  if (payMethods.error) {
490
490
  throw new Error(payMethods.error);
@@ -498,7 +498,7 @@ function methods(request, opts) {
498
498
  },
499
499
 
500
500
  async handleRedirect(params) {
501
- const cart = toSnake(await methods$1.methods(request, options).get());
501
+ const cart = toSnake(await methods$1(request, options).get());
502
502
  if (!cart) {
503
503
  throw new Error('Cart not found');
504
504
  }
@@ -511,7 +511,7 @@ function methods(request, opts) {
511
511
  throw new Error('Payment not found');
512
512
  }
513
513
  const payMethods = toSnake(
514
- await methods$2.methods(request, options).payments(),
514
+ await methods$2(request, options).payments(),
515
515
  );
516
516
  if (payMethods.error) {
517
517
  throw new Error(payMethods.error);
@@ -699,10 +699,30 @@ async function stripeElements(request, payMethods, params) {
699
699
  }
700
700
  }
701
701
 
702
+ /**
703
+ * Update cart email with paypal's when no email is present
704
+ */
705
+ async function shouldUsePayPalEmail(guest, request, options) {
706
+ // Only check if the email should be updated when the user is not logged in (guest user)
707
+ if (!guest) return false;
708
+
709
+ // Refetch to avoid stale data from the cart
710
+ const updatedCart = await methods$1(request, options).get();
711
+ const currentEmail = get(updatedCart, 'account.email');
712
+
713
+ // If no email is present, use paypal's email
714
+ if (!currentEmail) {
715
+ return true;
716
+ } else {
717
+ return false;
718
+ }
719
+ }
720
+
702
721
  async function payPalButton(request, cart, payMethods, params) {
703
722
  const paypal = window.paypal;
704
723
  const { paypal: { locale, style, elementId } = {} } = params;
705
- const { capture_total, currency, account_logged_in } = cart;
724
+ const { capture_total, currency, guest } = cart;
725
+
706
726
  const onError = (error) => {
707
727
  const errorHandler = get(params, 'paypal.onError');
708
728
  if (isFunction(errorHandler)) {
@@ -716,7 +736,9 @@ async function payPalButton(request, cart, payMethods, params) {
716
736
  };
717
737
 
718
738
  if (!(capture_total > 0)) {
719
- throw new Error('Invalid PayPal button amount. Value should be greater than zero.');
739
+ throw new Error(
740
+ 'Invalid PayPal button amount. Value should be greater than zero.',
741
+ );
720
742
  }
721
743
 
722
744
  paypal
@@ -746,13 +768,19 @@ async function payPalButton(request, cart, payMethods, params) {
746
768
  onApprove: (data, actions) =>
747
769
  actions.order
748
770
  .get()
749
- .then((order) => {
771
+ .then(async (order) => {
750
772
  const orderId = order.id;
751
773
  const payer = order.payer;
752
774
  const shipping = get(order, 'purchase_units[0].shipping');
753
775
 
754
- return methods$1.methods(request).update({
755
- ...(!account_logged_in && {
776
+ const usePayPalEmail = await shouldUsePayPalEmail(
777
+ guest,
778
+ request,
779
+ options,
780
+ );
781
+
782
+ return methods$1(request).update({
783
+ ...(usePayPalEmail && {
756
784
  account: {
757
785
  email: payer.email_address,
758
786
  },
@@ -812,9 +840,9 @@ async function braintreePayPalButton(request, cart, payMethods, params) {
812
840
  paypalCheckoutInstance
813
841
  .tokenizePayment(data)
814
842
  .then(({ nonce }) =>
815
- methods$1
816
- .methods(request, options)
817
- .update({ billing: { paypal: { nonce } } }),
843
+ methods$1(request, options).update({
844
+ billing: { paypal: { nonce } },
845
+ }),
818
846
  )
819
847
  .then(
820
848
  () =>
@@ -885,8 +913,7 @@ async function paymentTokenize(request, params, payMethods, cart) {
885
913
  } else if (capture_total < 1) {
886
914
  // should save payment method data when payment amount is less than 1
887
915
  // https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts
888
- return methods$1
889
- .methods(request, options)
916
+ return methods$1(request, options)
890
917
  .update({
891
918
  billing: {
892
919
  method: 'card',
@@ -898,7 +925,10 @@ async function paymentTokenize(request, params, payMethods, cart) {
898
925
  }
899
926
 
900
927
  const currency = toLower(get(cart, 'currency', 'usd'));
901
- const amount = stripeAmountByCurrency(currency, capture_total + auth_total);
928
+ const amount = stripeAmountByCurrency(
929
+ currency,
930
+ capture_total + auth_total,
931
+ );
902
932
  const stripeCustomer = get(cart, 'account.stripe_customer');
903
933
  const intent = toSnake(
904
934
  await methods(request)
@@ -922,8 +952,7 @@ async function paymentTokenize(request, params, payMethods, cart) {
922
952
  );
923
953
  return error
924
954
  ? onError(error)
925
- : await methods$1
926
- .methods(request, options)
955
+ : await methods$1(request, options)
927
956
  .update({
928
957
  billing: {
929
958
  method: 'card',
@@ -952,7 +981,7 @@ async function paymentTokenize(request, params, payMethods, cart) {
952
981
  return onError(intent.error);
953
982
  }
954
983
 
955
- await methods$1.methods(request, options).update({
984
+ await methods$1(request, options).update({
956
985
  billing: {
957
986
  method: 'card',
958
987
  intent: {
@@ -1002,8 +1031,7 @@ async function paymentTokenize(request, params, payMethods, cart) {
1002
1031
  );
1003
1032
 
1004
1033
  if (intent) {
1005
- await methods$1
1006
- .methods(request, options)
1034
+ await methods$1(request, options)
1007
1035
  .update({
1008
1036
  billing: {
1009
1037
  method: 'ideal',
@@ -1035,9 +1063,7 @@ async function paymentTokenize(request, params, payMethods, cart) {
1035
1063
  }
1036
1064
  const { publishable_key } = payMethods.card;
1037
1065
  const stripe = window.Stripe(publishable_key);
1038
- const settings = toSnake(
1039
- await methods$2.methods(request, options).get(),
1040
- );
1066
+ const settings = toSnake(await methods$2(request, options).get());
1041
1067
 
1042
1068
  const { error, source } = await createKlarnaSource(stripe, {
1043
1069
  ...cart,
@@ -1046,8 +1072,7 @@ async function paymentTokenize(request, params, payMethods, cart) {
1046
1072
 
1047
1073
  return error
1048
1074
  ? onError(error)
1049
- : methods$1
1050
- .methods(request, options)
1075
+ : methods$1(request, options)
1051
1076
  .update({
1052
1077
  billing: {
1053
1078
  method: 'klarna',
@@ -1068,8 +1093,7 @@ async function paymentTokenize(request, params, payMethods, cart) {
1068
1093
 
1069
1094
  return error
1070
1095
  ? onError(error)
1071
- : methods$1
1072
- .methods(request, options)
1096
+ : methods$1(request, options)
1073
1097
  .update({
1074
1098
  billing: {
1075
1099
  method: 'bancontact',
@@ -1087,7 +1111,7 @@ async function paymentTokenize(request, params, payMethods, cart) {
1087
1111
  return;
1088
1112
  }
1089
1113
 
1090
- await methods$1.methods(request, options).update({
1114
+ await methods$1(request, options).update({
1091
1115
  billing: {
1092
1116
  method: 'paysafecard',
1093
1117
  intent: {
@@ -1175,7 +1199,7 @@ async function handleQuickpayRedirectAction(
1175
1199
  } else if (card.error) {
1176
1200
  return card;
1177
1201
  } else {
1178
- await methods$1.methods(request, options).update({
1202
+ await methods$1(request, options).update({
1179
1203
  billing: {
1180
1204
  method: 'card',
1181
1205
  card,
@@ -1247,7 +1271,7 @@ async function handleDirectKlarnaRedirectAction(
1247
1271
  };
1248
1272
  }
1249
1273
 
1250
- await methods$1.methods(request, options).update({
1274
+ await methods$1(request, options).update({
1251
1275
  billing: {
1252
1276
  method: 'klarna',
1253
1277
  klarna: {
@@ -1301,4 +1325,4 @@ async function authenticateStripeCard(request, payment, payMethods) {
1301
1325
  : { status: actionResult.status };
1302
1326
  }
1303
1327
 
1304
- export { methods as m };
1328
+ export { methods as m, shouldUsePayPalEmail as s };
package/dist/payment.js CHANGED
@@ -1,7 +1,7 @@
1
- export { m as default } from './payment-91a15202.js';
1
+ export { m as default, s as shouldUsePayPalEmail } from './payment-fd4a2cbe.js';
2
2
  import 'lodash/get';
3
3
  import 'lodash/toLower';
4
- import './cart-bdec9379.js';
4
+ import './cart-21650912.js';
5
5
  import 'qs';
6
6
  import 'lodash/set';
7
7
  import 'lodash/uniq';
@@ -14,7 +14,7 @@ import 'lodash/cloneDeep';
14
14
  import 'lodash/isEqual';
15
15
  import 'deepmerge';
16
16
  import 'object-keys-normalizer';
17
- import './products-a6a43be8.js';
17
+ import './products-baf505e7.js';
18
18
  import './index-bce8d606.js';
19
19
  import './cache-54abc38e.js';
20
20
  import './attributes-db35134e.js';
@@ -235,11 +235,10 @@ function findPurchaseOption(product, purchaseOption) {
235
235
  }
236
236
 
237
237
  async function getFilterableAttributeFilters(request, products, options) {
238
- const { results: filterableAttributes } = await methods$1
239
- .methods(request, OPTIONS)
240
- .list({
241
- filterable: true,
242
- });
238
+ const { results: filterableAttributes } = await methods$1(
239
+ request).list({
240
+ filterable: true,
241
+ });
243
242
 
244
243
  return getFilters(products, { ...options, filterableAttributes });
245
244
  }
package/dist/products.js CHANGED
@@ -1,4 +1,4 @@
1
- export { b as calculateVariation, c as cleanProductOptions, m as default, f as findVariantWithOptions, g as getProductOptionIndex, a as getVariantOptionValueIds } from './products-a6a43be8.js';
1
+ export { b as calculateVariation, c as cleanProductOptions, m as default, f as findVariantWithOptions, g as getProductOptionIndex, a as getVariantOptionValueIds } from './products-baf505e7.js';
2
2
  import './index-bce8d606.js';
3
3
  import 'qs';
4
4
  import 'lodash/set';
@@ -1,4 +1,4 @@
1
- import { c as cleanProductOptions } from './products-a6a43be8.js';
1
+ import { c as cleanProductOptions } from './products-baf505e7.js';
2
2
  import { d as defaultMethods } from './index-bce8d606.js';
3
3
  import { c as cacheApi } from './cache-54abc38e.js';
4
4
 
@@ -1,5 +1,5 @@
1
- export { m as default } from './subscriptions-eecdd4ff.js';
2
- import './products-a6a43be8.js';
1
+ export { m as default } from './subscriptions-0e44e99f.js';
2
+ import './products-baf505e7.js';
3
3
  import './index-bce8d606.js';
4
4
  import 'qs';
5
5
  import 'lodash/set';