swell-js 5.8.2 → 5.9.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.
Files changed (86) hide show
  1. package/dist/api.mjs +53 -42
  2. package/dist/attributes.mjs +4 -6
  3. package/dist/cache.mjs +141 -140
  4. package/dist/card.mjs +149 -148
  5. package/dist/cart.mjs +3 -5
  6. package/dist/categories.mjs +4 -6
  7. package/dist/content.mjs +1 -9
  8. package/dist/cookie.mjs +3 -4
  9. package/dist/currency.mjs +2 -3
  10. package/dist/{find.18f1ac6d.mjs → find.ba551a2e.mjs} +125 -5
  11. package/dist/{index.a8d5c125.mjs → index.3949a230.mjs} +4 -21
  12. package/dist/index.mjs +3 -4
  13. package/dist/locale.mjs +1 -2
  14. package/dist/payment.mjs +11 -14
  15. package/dist/products.mjs +10 -15
  16. package/dist/{round.577a8441.mjs → round.c68b8be5.mjs} +1 -1
  17. package/dist/settings.mjs +3 -4
  18. package/dist/subscriptions.mjs +4 -6
  19. package/dist/swell.cjs +439 -323
  20. package/dist/swell.cjs.map +1 -1
  21. package/dist/swell.umd.min.js +13676 -18860
  22. package/dist/swell.umd.min.js.map +1 -1
  23. package/dist/utils/index.mjs +3 -4
  24. package/package.json +15 -8
  25. package/types/account/camel.ts +10 -7
  26. package/types/account/index.ts +3 -3
  27. package/types/account/snake.ts +5 -5
  28. package/types/attribute/camel.ts +7 -4
  29. package/types/attribute/index.ts +3 -3
  30. package/types/attribute/snake.ts +2 -2
  31. package/types/billing/camel.ts +4 -4
  32. package/types/billing/index.ts +2 -2
  33. package/types/billing/snake.ts +1 -1
  34. package/types/card/camel.ts +5 -5
  35. package/types/card/index.ts +3 -3
  36. package/types/card/snake.ts +3 -3
  37. package/types/cart/camel.ts +17 -14
  38. package/types/cart/index.ts +3 -3
  39. package/types/cart/snake.ts +12 -12
  40. package/types/category/camel.ts +4 -4
  41. package/types/category/index.ts +3 -3
  42. package/types/category/snake.ts +2 -2
  43. package/types/content/camel.ts +5 -5
  44. package/types/content/index.ts +3 -3
  45. package/types/content/snake.ts +3 -3
  46. package/types/coupon/camel.ts +4 -4
  47. package/types/coupon/index.ts +2 -2
  48. package/types/coupon/snake.ts +2 -2
  49. package/types/currency/camel.ts +2 -2
  50. package/types/currency/index.ts +3 -3
  51. package/types/discount/camel.ts +3 -3
  52. package/types/discount/index.ts +2 -2
  53. package/types/giftcard/camel.ts +10 -7
  54. package/types/giftcard/index.ts +2 -2
  55. package/types/giftcard/snake.ts +5 -5
  56. package/types/index.d.cts +207 -0
  57. package/types/index.d.ts +83 -56
  58. package/types/invoice/camel.ts +10 -10
  59. package/types/invoice/index.ts +3 -3
  60. package/types/invoice/snake.ts +8 -8
  61. package/types/order/camel.ts +18 -15
  62. package/types/order/index.ts +3 -3
  63. package/types/order/snake.ts +18 -13
  64. package/types/payment/camel.ts +13 -10
  65. package/types/payment/index.ts +3 -3
  66. package/types/payment/snake.ts +8 -8
  67. package/types/product/camel.ts +5 -5
  68. package/types/product/index.ts +4 -4
  69. package/types/product/snake.ts +3 -3
  70. package/types/promotion/camel.ts +6 -6
  71. package/types/promotion/index.ts +2 -2
  72. package/types/promotion/snake.ts +4 -4
  73. package/types/purchase_link/camel.ts +10 -7
  74. package/types/purchase_link/index.ts +2 -2
  75. package/types/purchase_link/snake.ts +5 -5
  76. package/types/refund/camel.ts +6 -6
  77. package/types/refund/index.ts +2 -2
  78. package/types/refund/snake.ts +4 -4
  79. package/types/shipment_rating/camel.ts +3 -3
  80. package/types/shipment_rating/index.ts +2 -2
  81. package/types/subscription/camel.ts +16 -13
  82. package/types/subscription/index.ts +3 -3
  83. package/types/subscription/snake.ts +16 -11
  84. package/types/user/camel.ts +2 -2
  85. package/types/user/index.ts +3 -3
  86. package/types/user/snake.ts +1 -1
package/dist/api.mjs CHANGED
@@ -1,23 +1,22 @@
1
- import cardApi from './card.mjs';
1
+ import methods$5 from './card.mjs';
2
2
  import { getCookie, setCookie } from './cookie.mjs';
3
- import cacheApi from './cache.mjs';
3
+ import methods$4 from './cache.mjs';
4
4
  import methods$3 from './cart.mjs';
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, 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
- import 'qs';
5
+ import methods$6 from './account.mjs';
6
+ import { j as isFunction, l as loadScript, e as isObject, v as vaultRequest, k as isEmpty, d as defaultMethods, x as trimEnd, y as utils, z as trimStart, A as trimBoth, b as toSnake, o as base64Encode, i as isServer, t as toCamel } from './index.3949a230.mjs';
7
+ import { Q as stringifyQuery } from './find.ba551a2e.mjs';
8
8
  import 'deepmerge';
9
9
  import 'fast-case';
10
- import methods$5 from './products.mjs';
11
- import methods$6 from './categories.mjs';
12
- import methods$7 from './attributes.mjs';
13
- import methods$8 from './subscriptions.mjs';
14
- import methods$9 from './content.mjs';
15
- import methods$a from './settings.mjs';
10
+ import methods$7 from './products.mjs';
11
+ import methods$8 from './categories.mjs';
12
+ import methods$9 from './attributes.mjs';
13
+ import methods$a from './subscriptions.mjs';
14
+ import methods$b from './content.mjs';
15
+ import methods$c from './settings.mjs';
16
16
  import PaymentController from './payment.mjs';
17
- import methods$b from './locale.mjs';
18
- import methods$c from './currency.mjs';
19
- import './find.18f1ac6d.mjs';
20
- import './round.577a8441.mjs';
17
+ import methods$d from './locale.mjs';
18
+ import methods$e from './currency.mjs';
19
+ import './round.c68b8be5.mjs';
21
20
 
22
21
  class AppComponent {
23
22
  #preact = null;
@@ -146,19 +145,29 @@ class AppPaymentComponent extends AppComponent {
146
145
  }
147
146
 
148
147
  #getIntent(data) {
149
- return vaultRequest('GET', '/intent', {
150
- gateway: this.#gateway,
151
- account_id: this.#accountId,
152
- intent: data,
153
- });
148
+ return vaultRequest(
149
+ 'GET',
150
+ '/intent',
151
+ {
152
+ gateway: this.#gateway,
153
+ account_id: this.#accountId,
154
+ intent: data,
155
+ },
156
+ this.options,
157
+ );
154
158
  }
155
159
 
156
160
  #createIntent(data) {
157
- return vaultRequest('POST', '/intent', {
158
- gateway: this.#gateway,
159
- account_id: this.#accountId,
160
- intent: data,
161
- });
161
+ return vaultRequest(
162
+ 'POST',
163
+ '/intent',
164
+ {
165
+ gateway: this.#gateway,
166
+ account_id: this.#accountId,
167
+ intent: data,
168
+ },
169
+ this.options,
170
+ );
162
171
  }
163
172
  }
164
173
 
@@ -312,7 +321,7 @@ function methods$2(api) {
312
321
  const { get, list } = defaultMethods(api, '/invoices', ['list', 'get']);
313
322
  return {
314
323
  get: (id, ...args) => {
315
- return cacheApi.getFetch('invoices', id, () => get(id, ...args));
324
+ return api.cache.getFetch('invoices', id, () => get(id, ...args));
316
325
  },
317
326
 
318
327
  list,
@@ -446,7 +455,7 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
446
455
  const api = {};
447
456
 
448
457
  Object.assign(api, {
449
- version: '5.8.2',
458
+ version: '5.9.1',
450
459
  options,
451
460
  request,
452
461
 
@@ -476,8 +485,6 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
476
485
  options.getCart = opt.getCart;
477
486
  options.updateCart = opt.updateCart;
478
487
  options.headers = opt.headers || {};
479
-
480
- setOptions(options);
481
488
  },
482
489
 
483
490
  // Backward compatibility
@@ -501,35 +508,35 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
501
508
  return api.request('delete', url, data);
502
509
  },
503
510
 
504
- cache: cacheApi,
511
+ cache: methods$4(options),
505
512
 
506
- card: cardApi,
513
+ card: methods$5(options),
507
514
 
508
515
  cart: methods$3(api, options),
509
516
 
510
- account: methods$4(api),
517
+ account: methods$6(api),
511
518
 
512
519
  app: new AppController(api, options),
513
520
 
514
- products: methods$5(api, options),
521
+ products: methods$7(api, options),
515
522
 
516
- categories: methods$6(api),
523
+ categories: methods$8(api),
517
524
 
518
- attributes: methods$7(api),
525
+ attributes: methods$9(api),
519
526
 
520
- subscriptions: methods$8(api),
527
+ subscriptions: methods$a(api),
521
528
 
522
529
  invoices: methods$2(api),
523
530
 
524
- content: methods$9(api, options),
531
+ content: methods$b(api, options),
525
532
 
526
- settings: methods$a(api, options),
533
+ settings: methods$c(api, options),
527
534
 
528
535
  payment: new PaymentController(api, options),
529
536
 
530
- locale: methods$b(api, options),
537
+ locale: methods$d(api, options),
531
538
 
532
- currency: methods$c(api, options),
539
+ currency: methods$e(api, options),
533
540
 
534
541
  session: methods$1(api, options),
535
542
 
@@ -537,9 +544,13 @@ function swell(initStore = undefined, initKey, initOptions = {}) {
537
544
 
538
545
  utils,
539
546
 
540
- getCookie,
547
+ getCookie(name) {
548
+ return (options.getCookie || getCookie)(name);
549
+ },
541
550
 
542
- setCookie,
551
+ setCookie(name, value, cookieOptions) {
552
+ return (options.setCookie || setCookie)(name, value, cookieOptions);
553
+ },
543
554
  });
544
555
 
545
556
  async function request(
@@ -1,8 +1,6 @@
1
- import { d as defaultMethods } from './index.a8d5c125.mjs';
2
- import cacheApi from './cache.mjs';
3
- import 'qs';
4
- import './find.18f1ac6d.mjs';
5
- import './round.577a8441.mjs';
1
+ import { d as defaultMethods } from './index.3949a230.mjs';
2
+ import './find.ba551a2e.mjs';
3
+ import './round.c68b8be5.mjs';
6
4
  import 'deepmerge';
7
5
  import 'fast-case';
8
6
 
@@ -11,7 +9,7 @@ function methods(api) {
11
9
 
12
10
  return {
13
11
  get: (id, ...args) => {
14
- return cacheApi.getFetch('attributes', id, () => get(id, ...args));
12
+ return api.cache.getFetch('attributes', id, () => get(id, ...args));
15
13
  },
16
14
 
17
15
  list,
package/dist/cache.mjs CHANGED
@@ -1,170 +1,171 @@
1
- import { s as set, m as merge, a as toCamel, h as toCamelPath, j as getOptions } from './index.a8d5c125.mjs';
2
- import { g as get } from './find.18f1ac6d.mjs';
3
- import 'qs';
4
- import './round.577a8441.mjs';
1
+ import { s as set, m as merge, t as toCamel, a as toCamelPath } from './index.3949a230.mjs';
2
+ import { g as get } from './find.ba551a2e.mjs';
3
+ import './round.c68b8be5.mjs';
5
4
  import 'deepmerge';
6
5
  import 'fast-case';
7
6
 
8
7
  const RECORD_TIMEOUT = 5000;
9
8
 
10
- let VALUES = {
11
- /*
12
- [model]: {
13
- [id]: {
14
- data,
15
- record,
16
- recordTimer,
17
- presets,
18
- }
19
- }
20
- */
21
- };
22
-
23
- const cacheApi = {
24
- options: {
25
- enabled: true,
26
- debug: false,
27
- },
28
-
29
- debug(...args) {
30
- if (this.options.debug) {
31
- console.log(...args);
32
- }
33
- },
34
-
35
- values({ model, id }, setValues = undefined) {
36
- this.debug('cache.values', ...arguments);
37
- if (setValues !== undefined) {
38
- for (let key in setValues) {
39
- set(VALUES, `${model}.${id}.${key}`, setValues[key]);
9
+ function methods(opt) {
10
+ let VALUES = {
11
+ /*
12
+ [model]: {
13
+ [id]: {
14
+ data,
15
+ record,
16
+ recordTimer,
17
+ presets,
40
18
  }
41
- return;
42
- }
43
- return get(VALUES, `${model}.${id}`, {});
44
- },
45
-
46
- preset(details) {
47
- this.debug('cache.preset', ...arguments);
48
- const { presets = [] } = this.values(details);
49
- presets.push(details);
50
- this.values(details, { presets });
51
- },
52
-
53
- set(details) {
54
- this.debug('cache.set', ...arguments);
55
- let { model, id, path, value } = details;
56
- let { data = {}, record } = this.values(details);
57
-
58
- if (id === null) {
59
- return;
60
19
  }
20
+ */
21
+ };
22
+
23
+ return {
24
+ options: {
25
+ enabled: true,
26
+ debug: false,
27
+ },
28
+
29
+ debug(...args) {
30
+ if (this.options.debug) {
31
+ console.log(...args);
32
+ }
33
+ },
61
34
 
62
- if (record === undefined) {
63
- return this.preset(details);
64
- }
35
+ values({ model, id }, setValues = undefined) {
36
+ this.debug('cache.values', ...arguments);
37
+ if (setValues !== undefined) {
38
+ for (let key in setValues) {
39
+ set(VALUES, `${model}.${id}.${key}`, setValues[key]);
40
+ }
41
+ return;
42
+ }
43
+ return get(VALUES, `${model}.${id}`, {});
44
+ },
45
+
46
+ preset(details) {
47
+ this.debug('cache.preset', ...arguments);
48
+ const { presets = [] } = this.values(details);
49
+ presets.push(details);
50
+ this.values(details, { presets });
51
+ },
52
+
53
+ set(details) {
54
+ this.debug('cache.set', ...arguments);
55
+ let { model, id, path, value } = details;
56
+ let { data = {}, record } = this.values(details);
57
+
58
+ if (id === null) {
59
+ return;
60
+ }
65
61
 
66
- data = merge(record || {}, data);
62
+ if (record === undefined) {
63
+ return this.preset(details);
64
+ }
67
65
 
68
- const { useCamelCase } = getOptions();
69
- if (useCamelCase && value && typeof value === 'object') {
70
- value = toCamel(value);
71
- }
66
+ data = merge(record || {}, data);
72
67
 
73
- if (path || value instanceof Array) {
74
- let upData = { ...(data || {}) };
75
- let upPath = useCamelCase ? toCamelPath(path) : path;
76
- set(upData, upPath || '', value);
77
- data = upData;
78
- } else if (value && typeof value === 'object') {
79
- data = data || {};
80
- data = merge(data, value);
81
- } else {
82
- data = value;
83
- }
68
+ const { useCamelCase } = opt;
69
+ if (useCamelCase && value && typeof value === 'object') {
70
+ value = toCamel(value);
71
+ }
84
72
 
85
- this.values(details, { data });
73
+ if (path || value instanceof Array) {
74
+ let upData = { ...(data || {}) };
75
+ let upPath = useCamelCase ? toCamelPath(path) : path;
76
+ set(upData, upPath || '', value);
77
+ data = upData;
78
+ } else if (value && typeof value === 'object') {
79
+ data = data || {};
80
+ data = merge(data, value);
81
+ } else {
82
+ data = value;
83
+ }
86
84
 
87
- try {
88
- // Make sure values have clean refs
89
- const cache = VALUES[model][id];
90
- if (cache !== undefined) {
91
- if (cache.data !== undefined) {
92
- cache.data = JSON.parse(JSON.stringify(cache.data));
93
- }
94
- if (cache.record !== undefined) {
95
- cache.record = JSON.parse(JSON.stringify(cache.record));
85
+ this.values(details, { data });
86
+
87
+ try {
88
+ // Make sure values have clean refs
89
+ const cache = VALUES[model][id];
90
+ if (cache !== undefined) {
91
+ if (cache.data !== undefined) {
92
+ cache.data = JSON.parse(JSON.stringify(cache.data));
93
+ }
94
+ if (cache.record !== undefined) {
95
+ cache.record = JSON.parse(JSON.stringify(cache.record));
96
+ }
96
97
  }
98
+ } catch (err) {
99
+ // noop
97
100
  }
98
- } catch (err) {
99
- // noop
100
- }
101
- },
102
-
103
- get(model, id) {
104
- this.debug('cache.get', ...arguments);
105
- const { data, recordTimer } = this.values({ model, id });
106
- this.debug('cache.get:data+recordTimer', ...arguments);
107
- if (recordTimer) {
108
- return data;
109
- }
110
- },
101
+ },
102
+
103
+ get(model, id) {
104
+ this.debug('cache.get', ...arguments);
105
+ const { data, recordTimer } = this.values({ model, id });
106
+ this.debug('cache.get:data+recordTimer', ...arguments);
107
+ if (recordTimer) {
108
+ return data;
109
+ }
110
+ },
111
111
 
112
- setRecord(record, details) {
113
- this.debug('cache.setRecord', ...arguments);
114
- let { recordTimer, presets } = this.values(details);
112
+ setRecord(record, details) {
113
+ this.debug('cache.setRecord', ...arguments);
114
+ let { recordTimer, presets } = this.values(details);
115
115
 
116
- if (recordTimer) {
117
- clearTimeout(recordTimer);
118
- }
116
+ if (recordTimer) {
117
+ clearTimeout(recordTimer);
118
+ }
119
119
 
120
- recordTimer = setTimeout(() => {
121
- this.values(details, { record: undefined, recordTimer: undefined });
122
- }, RECORD_TIMEOUT);
120
+ recordTimer = setTimeout(() => {
121
+ this.values(details, { record: undefined, recordTimer: undefined });
122
+ }, RECORD_TIMEOUT);
123
123
 
124
- // Record has to be null at minimum, not undefined
125
- this.values(details, {
126
- record: record !== undefined ? record : null,
127
- recordTimer,
128
- });
124
+ // Record has to be null at minimum, not undefined
125
+ this.values(details, {
126
+ record: record !== undefined ? record : null,
127
+ recordTimer,
128
+ });
129
129
 
130
- if (presets) {
131
- for (let preset of presets) {
132
- this.set(preset);
130
+ if (presets) {
131
+ for (let preset of presets) {
132
+ this.set(preset);
133
+ }
134
+ this.values(details, { presets: undefined });
133
135
  }
134
- this.values(details, { presets: undefined });
135
- }
136
136
 
137
- const result = this.get(details.model, details.id);
137
+ const result = this.get(details.model, details.id);
138
138
 
139
- return result !== undefined ? result : record;
140
- },
139
+ return result !== undefined ? result : record;
140
+ },
141
141
 
142
- async getFetch(model, id, fetch) {
143
- if (this.options.enabled) {
144
- this.debug('cache.getFetch', ...arguments);
145
- const value = this.get(model, id);
142
+ async getFetch(model, id, fetch) {
143
+ if (this.options.enabled) {
144
+ this.debug('cache.getFetch', ...arguments);
145
+ const value = this.get(model, id);
146
146
 
147
- if (value !== undefined) {
148
- return value;
147
+ if (value !== undefined) {
148
+ return value;
149
+ }
149
150
  }
150
- }
151
151
 
152
- const record = await fetch();
153
- return this.setRecord(record, { model, id });
154
- },
155
-
156
- clear(model = undefined, id = undefined) {
157
- this.debug('cache.clear', ...arguments);
158
- if (model) {
159
- if (id) {
160
- set(VALUES, `${model}.${id}`, undefined);
152
+ const record = await fetch();
153
+ return this.setRecord(record, { model, id });
154
+ },
155
+
156
+ clear(model = undefined, id = undefined) {
157
+ this.debug('cache.clear', ...arguments);
158
+ if (model) {
159
+ if (id) {
160
+ set(VALUES, `${model}.${id}`, undefined);
161
+ } else {
162
+ set(VALUES, model, undefined);
163
+ }
161
164
  } else {
162
- set(VALUES, model, undefined);
165
+ VALUES = {};
163
166
  }
164
- } else {
165
- VALUES = {};
166
- }
167
- },
168
- };
167
+ },
168
+ };
169
+ }
169
170
 
170
- export { cacheApi as default };
171
+ export { methods as default };