swell-js 5.8.0 → 5.8.1

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/api.mjs CHANGED
@@ -3,7 +3,7 @@ import { getCookie, setCookie } from './cookie.mjs';
3
3
  import cacheApi from './cache.mjs';
4
4
  import methods$3 from './cart.mjs';
5
5
  import methods$4 from './account.mjs';
6
- import { k as isFunction, l as loadScript, b as isObject, v as vaultRequest, n as isEmpty, d as defaultMethods, z as trimEnd, A as setOptions, B as utils, C as trimStart, D as trimBoth, t as toSnake, E as stringifyQuery, q as base64Encode, i as isServer, a as toCamel } from './index.a227b03d.mjs';
6
+ import { k as isFunction, l as loadScript, b as isObject, v as vaultRequest, n as isEmpty, d as defaultMethods, y as trimEnd, z as setOptions, A as utils, B as trimStart, C as trimBoth, t as toSnake, D as stringifyQuery, q as base64Encode, i as isServer, a as toCamel } from './index.a8d5c125.mjs';
7
7
  import 'qs';
8
8
  import 'deepmerge';
9
9
  import 'fast-case';
@@ -446,7 +446,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
446
446
  const api = {};
447
447
 
448
448
  Object.assign(api, {
449
- version: '5.8.0',
449
+ version: '5.8.1',
450
450
  options,
451
451
  request,
452
452
 
@@ -1,4 +1,4 @@
1
- import { d as defaultMethods } from './index.a227b03d.mjs';
1
+ import { d as defaultMethods } from './index.a8d5c125.mjs';
2
2
  import cacheApi from './cache.mjs';
3
3
  import 'qs';
4
4
  import './find.18f1ac6d.mjs';
package/dist/cache.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { s as set, m as merge, a as toCamel, h as toCamelPath, j as getOptions } from './index.a227b03d.mjs';
1
+ import { s as set, m as merge, a as toCamel, h as toCamelPath, j as getOptions } from './index.a8d5c125.mjs';
2
2
  import { g as get } from './find.18f1ac6d.mjs';
3
3
  import 'qs';
4
4
  import './round.577a8441.mjs';
package/dist/card.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as toSnake, v as vaultRequest } from './index.a227b03d.mjs';
1
+ import { t as toSnake, v as vaultRequest } from './index.a8d5c125.mjs';
2
2
  import 'qs';
3
3
  import './find.18f1ac6d.mjs';
4
4
  import './round.577a8441.mjs';
package/dist/cart.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import 'qs';
2
- import { c as cloneDeep } from './index.a227b03d.mjs';
2
+ import { c as cloneDeep } from './index.a8d5c125.mjs';
3
3
  import 'deepmerge';
4
4
  import 'fast-case';
5
5
  import { cleanProductOptions } from './products.mjs';
@@ -1,4 +1,4 @@
1
- import { d as defaultMethods } from './index.a227b03d.mjs';
1
+ import { d as defaultMethods } from './index.a8d5c125.mjs';
2
2
  import cacheApi from './cache.mjs';
3
3
  import 'qs';
4
4
  import './find.18f1ac6d.mjs';
package/dist/content.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import cacheApi from './cache.mjs';
2
- import './index.a227b03d.mjs';
2
+ import './index.a8d5c125.mjs';
3
3
  import 'qs';
4
4
  import './find.18f1ac6d.mjs';
5
5
  import './round.577a8441.mjs';
package/dist/cookie.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as isServer } from './index.a227b03d.mjs';
1
+ import { i as isServer } from './index.a8d5c125.mjs';
2
2
  import 'qs';
3
3
  import './find.18f1ac6d.mjs';
4
4
  import './round.577a8441.mjs';
@@ -1815,4 +1815,4 @@ const utils = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
1815
1815
  vaultRequest
1816
1816
  }, Symbol.toStringTag, { value: 'Module' }));
1817
1817
 
1818
- export { setOptions as A, utils as B, trimStart as C, trimBoth as D, stringifyQuery as E, toLower as F, toCamel as a, isObject as b, cloneDeep as c, defaultMethods as d, camelCase as e, snakeCase as f, isEqual as g, toCamelPath as h, isServer as i, getOptions as j, isFunction as k, loadScript as l, merge as m, isEmpty as n, isLiveMode as o, pick$1 as p, base64Encode as q, reduce as r, set as s, toSnake as t, uniq as u, vaultRequest as v, map as w, getLocationParams as x, removeUrlParams as y, trimEnd as z };
1818
+ export { utils as A, trimStart as B, trimBoth as C, stringifyQuery as D, toLower as E, map as F, toCamel as a, isObject as b, cloneDeep as c, defaultMethods as d, camelCase as e, snakeCase as f, isEqual as g, toCamelPath as h, isServer as i, getOptions as j, isFunction as k, loadScript as l, merge as m, isEmpty as n, isLiveMode as o, pick$1 as p, base64Encode as q, reduce as r, set as s, toSnake as t, uniq as u, vaultRequest as v, getLocationParams as w, removeUrlParams as x, trimEnd as y, setOptions as z };
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  export { default } from './api.mjs';
2
2
  import './card.mjs';
3
- import './index.a227b03d.mjs';
3
+ import './index.a8d5c125.mjs';
4
4
  import 'qs';
5
5
  import './find.18f1ac6d.mjs';
6
6
  import './round.577a8441.mjs';
package/dist/payment.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import methods from './cart.mjs';
2
2
  import methods$1 from './settings.mjs';
3
- import { b as isObject, k as isFunction, l as loadScript, c as cloneDeep, v as vaultRequest, t as toSnake, p as pick, n as isEmpty, o as isLiveMode, q as base64Encode, w as map, r as reduce, x as getLocationParams, y as removeUrlParams, a as toCamel } from './index.a227b03d.mjs';
4
- import { g as get, t as toNumber } from './find.18f1ac6d.mjs';
3
+ import { b as isObject, k as isFunction, l as loadScript, c as cloneDeep, v as vaultRequest, t as toSnake, p as pick, n as isEmpty, o as isLiveMode, q as base64Encode, w as getLocationParams, x as removeUrlParams, a as toCamel } from './index.a8d5c125.mjs';
4
+ import { g as get } from './find.18f1ac6d.mjs';
5
5
  import 'qs';
6
6
  import 'deepmerge';
7
7
  import 'fast-case';
@@ -592,7 +592,7 @@ const MINIMUM_CHARGE_AMOUNT = {
592
592
  THB: 10,
593
593
  };
594
594
 
595
- const addressFieldsMap$1 = {
595
+ const addressFieldsMap = {
596
596
  city: 'city',
597
597
  country: 'country',
598
598
  line1: 'address1',
@@ -630,7 +630,7 @@ function getBillingDetails(cart) {
630
630
  details.email = cart.account.email;
631
631
  }
632
632
 
633
- const address = mapValues(addressFieldsMap$1, cart.billing);
633
+ const address = mapValues(addressFieldsMap, cart.billing);
634
634
  if (!isEmpty(address)) {
635
635
  details.address = address;
636
636
  }
@@ -4767,105 +4767,6 @@ class PaysafecardDirectPayment extends Payment {
4767
4767
  }
4768
4768
  }
4769
4769
 
4770
- const addressFieldsMap = {
4771
- given_name: 'first_name',
4772
- family_name: 'last_name',
4773
- city: 'city',
4774
- country: 'country',
4775
- phone: 'phone',
4776
- postal_code: 'zip',
4777
- street_address: 'address1',
4778
- street_address2: 'address2',
4779
- region: 'state',
4780
- };
4781
-
4782
- const mapFields = (fieldsMap, data) =>
4783
- reduce(
4784
- fieldsMap,
4785
- (acc, srcKey, destKey) => {
4786
- const value = data[srcKey];
4787
- if (value) {
4788
- acc[destKey] = value;
4789
- }
4790
- return acc;
4791
- },
4792
- {},
4793
- );
4794
-
4795
- const mapAddressFields = (cart, addressField) => ({
4796
- ...mapFields(addressFieldsMap, cart[addressField]),
4797
- email: get(cart, 'account.email'),
4798
- });
4799
-
4800
- function getOrderLines(cart) {
4801
- const items = map(cart.items, (item) => ({
4802
- type: 'physical',
4803
- name: get(item, 'product.name'),
4804
- reference: get(item, 'product.sku') || get(item, 'product.slug'),
4805
- quantity: item.quantity,
4806
- unit_price: Math.round(toNumber(item.price - item.discount_each) * 100),
4807
- total_amount: Math.round(
4808
- toNumber(item.price_total - item.discount_total) * 100,
4809
- ),
4810
- tax_rate: 0,
4811
- total_tax_amount: 0,
4812
- }));
4813
-
4814
- const tax = get(cart, 'tax_included_total');
4815
- const taxAmount = toNumber(tax) * 100;
4816
- if (tax) {
4817
- items.push({
4818
- type: 'sales_tax',
4819
- name: 'Taxes',
4820
- quantity: 1,
4821
- unit_price: taxAmount,
4822
- total_amount: taxAmount,
4823
- tax_rate: 0,
4824
- total_tax_amount: 0,
4825
- });
4826
- }
4827
-
4828
- const shipping = get(cart, 'shipping', {});
4829
- const shippingTotal = get(cart, 'shipment_total', {});
4830
- const shippingAmount = toNumber(shippingTotal) * 100;
4831
- if (shipping.price) {
4832
- items.push({
4833
- type: 'shipping_fee',
4834
- name: shipping.service_name,
4835
- quantity: 1,
4836
- unit_price: shippingAmount,
4837
- total_amount: shippingAmount,
4838
- tax_rate: 0,
4839
- total_tax_amount: 0,
4840
- });
4841
- }
4842
-
4843
- return items;
4844
- }
4845
-
4846
- function getKlarnaSessionData(cart) {
4847
- const returnUrl = `${window.location.origin}${window.location.pathname}?gateway=klarna_direct&sid={{session_id}}`;
4848
- const successUrl = `${returnUrl}&authorization_token={{authorization_token}}`;
4849
-
4850
- return {
4851
- locale: cart.display_locale || get(cart, 'settings.locale') || 'en-US',
4852
- purchase_country:
4853
- get(cart, 'billing.country') || get(cart, 'shipping.country'),
4854
- purchase_currency: cart.currency,
4855
- billing_address: mapAddressFields(cart, 'billing'),
4856
- shipping_address: mapAddressFields(cart, 'shipping'),
4857
- order_amount: Math.round(get(cart, 'capture_total', 0) * 100),
4858
- order_lines: JSON.stringify(getOrderLines(cart)),
4859
- merchant_urls: {
4860
- success: successUrl,
4861
- back: returnUrl,
4862
- cancel: returnUrl,
4863
- error: returnUrl,
4864
- failure: returnUrl,
4865
- },
4866
- };
4867
- }
4868
-
4869
4770
  class KlarnaDirectPayment extends Payment {
4870
4771
  constructor(api, options, params, methods) {
4871
4772
  super(api, options, params, methods.klarna);
@@ -4874,6 +4775,7 @@ class KlarnaDirectPayment extends Payment {
4874
4775
  async tokenize() {
4875
4776
  const cart = await this.getCart();
4876
4777
  const sessionData = getKlarnaSessionData(cart);
4778
+
4877
4779
  const session = await this.createIntent({
4878
4780
  gateway: 'klarna',
4879
4781
  intent: sessionData,
@@ -4906,6 +4808,22 @@ class KlarnaDirectPayment extends Payment {
4906
4808
  }
4907
4809
  }
4908
4810
 
4811
+ function getKlarnaSessionData(cart) {
4812
+ const returnUrl = `${window.location.origin}${window.location.pathname}?gateway=klarna_direct&sid={{session_id}}`;
4813
+ const successUrl = `${returnUrl}&authorization_token={{authorization_token}}`;
4814
+
4815
+ return {
4816
+ cart_id: cart.id,
4817
+ merchant_urls: {
4818
+ success: successUrl,
4819
+ back: returnUrl,
4820
+ cancel: returnUrl,
4821
+ error: returnUrl,
4822
+ failure: returnUrl,
4823
+ },
4824
+ };
4825
+ }
4826
+
4909
4827
  class PaypalDirectPayment extends Payment {
4910
4828
  constructor(api, options, params, methods) {
4911
4829
  super(api, options, params, methods.paypal);
package/dist/products.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { d as defaultMethods, r as reduce, t as toSnake, a as toCamel, f as snakeCase, u as uniq, g as isEqual } from './index.a227b03d.mjs';
1
+ import { d as defaultMethods, r as reduce, t as toSnake, a as toCamel, f as snakeCase, u as uniq, g as isEqual } from './index.a8d5c125.mjs';
2
2
  import cacheApi from './cache.mjs';
3
3
  import methods$1 from './attributes.mjs';
4
4
  import { g as get, f as find } from './find.18f1ac6d.mjs';
package/dist/settings.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { s as set, a as toCamel, m as merge, c as cloneDeep, b as isObject, e as camelCase } from './index.a227b03d.mjs';
1
+ import { s as set, a as toCamel, m as merge, c as cloneDeep, b as isObject, e as camelCase } from './index.a8d5c125.mjs';
2
2
  import { g as get, f as find } from './find.18f1ac6d.mjs';
3
3
  import 'qs';
4
4
  import './round.577a8441.mjs';
@@ -1,5 +1,5 @@
1
1
  import { cleanProductOptions } from './products.mjs';
2
- import { d as defaultMethods } from './index.a227b03d.mjs';
2
+ import { d as defaultMethods } from './index.a8d5c125.mjs';
3
3
  import cacheApi from './cache.mjs';
4
4
  import './attributes.mjs';
5
5
  import './find.18f1ac6d.mjs';
package/dist/swell.cjs CHANGED
@@ -7210,7 +7210,7 @@ const MINIMUM_CHARGE_AMOUNT = {
7210
7210
  THB: 10,
7211
7211
  };
7212
7212
 
7213
- const addressFieldsMap$1 = {
7213
+ const addressFieldsMap = {
7214
7214
  city: 'city',
7215
7215
  country: 'country',
7216
7216
  line1: 'address1',
@@ -7248,7 +7248,7 @@ function getBillingDetails(cart) {
7248
7248
  details.email = cart.account.email;
7249
7249
  }
7250
7250
 
7251
- const address = mapValues(addressFieldsMap$1, cart.billing);
7251
+ const address = mapValues(addressFieldsMap, cart.billing);
7252
7252
  if (!isEmpty(address)) {
7253
7253
  details.address = address;
7254
7254
  }
@@ -11385,105 +11385,6 @@ class PaysafecardDirectPayment extends Payment {
11385
11385
  }
11386
11386
  }
11387
11387
 
11388
- const addressFieldsMap = {
11389
- given_name: 'first_name',
11390
- family_name: 'last_name',
11391
- city: 'city',
11392
- country: 'country',
11393
- phone: 'phone',
11394
- postal_code: 'zip',
11395
- street_address: 'address1',
11396
- street_address2: 'address2',
11397
- region: 'state',
11398
- };
11399
-
11400
- const mapFields = (fieldsMap, data) =>
11401
- reduce(
11402
- fieldsMap,
11403
- (acc, srcKey, destKey) => {
11404
- const value = data[srcKey];
11405
- if (value) {
11406
- acc[destKey] = value;
11407
- }
11408
- return acc;
11409
- },
11410
- {},
11411
- );
11412
-
11413
- const mapAddressFields = (cart, addressField) => ({
11414
- ...mapFields(addressFieldsMap, cart[addressField]),
11415
- email: get(cart, 'account.email'),
11416
- });
11417
-
11418
- function getOrderLines(cart) {
11419
- const items = map(cart.items, (item) => ({
11420
- type: 'physical',
11421
- name: get(item, 'product.name'),
11422
- reference: get(item, 'product.sku') || get(item, 'product.slug'),
11423
- quantity: item.quantity,
11424
- unit_price: Math.round(toNumber(item.price - item.discount_each) * 100),
11425
- total_amount: Math.round(
11426
- toNumber(item.price_total - item.discount_total) * 100,
11427
- ),
11428
- tax_rate: 0,
11429
- total_tax_amount: 0,
11430
- }));
11431
-
11432
- const tax = get(cart, 'tax_included_total');
11433
- const taxAmount = toNumber(tax) * 100;
11434
- if (tax) {
11435
- items.push({
11436
- type: 'sales_tax',
11437
- name: 'Taxes',
11438
- quantity: 1,
11439
- unit_price: taxAmount,
11440
- total_amount: taxAmount,
11441
- tax_rate: 0,
11442
- total_tax_amount: 0,
11443
- });
11444
- }
11445
-
11446
- const shipping = get(cart, 'shipping', {});
11447
- const shippingTotal = get(cart, 'shipment_total', {});
11448
- const shippingAmount = toNumber(shippingTotal) * 100;
11449
- if (shipping.price) {
11450
- items.push({
11451
- type: 'shipping_fee',
11452
- name: shipping.service_name,
11453
- quantity: 1,
11454
- unit_price: shippingAmount,
11455
- total_amount: shippingAmount,
11456
- tax_rate: 0,
11457
- total_tax_amount: 0,
11458
- });
11459
- }
11460
-
11461
- return items;
11462
- }
11463
-
11464
- function getKlarnaSessionData(cart) {
11465
- const returnUrl = `${window.location.origin}${window.location.pathname}?gateway=klarna_direct&sid={{session_id}}`;
11466
- const successUrl = `${returnUrl}&authorization_token={{authorization_token}}`;
11467
-
11468
- return {
11469
- locale: cart.display_locale || get(cart, 'settings.locale') || 'en-US',
11470
- purchase_country:
11471
- get(cart, 'billing.country') || get(cart, 'shipping.country'),
11472
- purchase_currency: cart.currency,
11473
- billing_address: mapAddressFields(cart, 'billing'),
11474
- shipping_address: mapAddressFields(cart, 'shipping'),
11475
- order_amount: Math.round(get(cart, 'capture_total', 0) * 100),
11476
- order_lines: JSON.stringify(getOrderLines(cart)),
11477
- merchant_urls: {
11478
- success: successUrl,
11479
- back: returnUrl,
11480
- cancel: returnUrl,
11481
- error: returnUrl,
11482
- failure: returnUrl,
11483
- },
11484
- };
11485
- }
11486
-
11487
11388
  class KlarnaDirectPayment extends Payment {
11488
11389
  constructor(api, options, params, methods) {
11489
11390
  super(api, options, params, methods.klarna);
@@ -11492,6 +11393,7 @@ class KlarnaDirectPayment extends Payment {
11492
11393
  async tokenize() {
11493
11394
  const cart = await this.getCart();
11494
11395
  const sessionData = getKlarnaSessionData(cart);
11396
+
11495
11397
  const session = await this.createIntent({
11496
11398
  gateway: 'klarna',
11497
11399
  intent: sessionData,
@@ -11524,6 +11426,22 @@ class KlarnaDirectPayment extends Payment {
11524
11426
  }
11525
11427
  }
11526
11428
 
11429
+ function getKlarnaSessionData(cart) {
11430
+ const returnUrl = `${window.location.origin}${window.location.pathname}?gateway=klarna_direct&sid={{session_id}}`;
11431
+ const successUrl = `${returnUrl}&authorization_token={{authorization_token}}`;
11432
+
11433
+ return {
11434
+ cart_id: cart.id,
11435
+ merchant_urls: {
11436
+ success: successUrl,
11437
+ back: returnUrl,
11438
+ cancel: returnUrl,
11439
+ error: returnUrl,
11440
+ failure: returnUrl,
11441
+ },
11442
+ };
11443
+ }
11444
+
11527
11445
  class PaypalDirectPayment extends Payment {
11528
11446
  constructor(api, options, params, methods) {
11529
11447
  super(api, options, params, methods.paypal);
@@ -13113,7 +13031,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
13113
13031
  const api = {};
13114
13032
 
13115
13033
  Object.assign(api, {
13116
- version: '5.8.0',
13034
+ version: '5.8.1',
13117
13035
  options,
13118
13036
  request,
13119
13037