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