swell-js 3.21.3 → 3.21.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.
@@ -0,0 +1,207 @@
1
+ import { c as cardApi } from './card-91071403.js';
2
+ import { g as getCookie, s as setCookie } from './cookie-b78058af.js';
3
+ import { c as cacheApi } from './cache-751d89b1.js';
4
+ import { m as methods$1 } from './cart-ff3e3ef6.js';
5
+ import { m as methods$2 } from './account-328cc590.js';
6
+ import { m as methods$3 } from './products-7f2fbc3e.js';
7
+ import { m as methods$4 } from './categories-8f6a4584.js';
8
+ import { m as methods$5 } from './attributes-7a214d6b.js';
9
+ import { m as methods$6 } from './subscriptions-8044a530.js';
10
+ import { d as defaultMethods, n as trimEnd, K as utils, l as trimStart, k as trimBoth, j as toSnake, o as stringifyQuery, E as base64Encode, t as toCamel, e as setOptions } from './index-512fc30d.js';
11
+ import { m as methods$7 } from './content-0afdcb05.js';
12
+ import { m as methods$8 } from './settings-937b96f1.js';
13
+ import { P as PaymentController } from './index-760c7caf.js';
14
+ import { m as methods$9 } from './locale-4391bcf3.js';
15
+ import { m as methods$a } from './currency-842f76f2.js';
16
+
17
+ function methods(request) {
18
+ const { get, list } = defaultMethods(request, '/invoices', ['list', 'get']);
19
+ return {
20
+ get: (id, ...args) => {
21
+ return cacheApi.getFetch('invoices', id, () => get(id, ...args));
22
+ },
23
+
24
+ list,
25
+ };
26
+ }
27
+
28
+ const options = {
29
+ store: null,
30
+ key: null,
31
+ url: null,
32
+ useCamelCase: null,
33
+ previewContent: null,
34
+ };
35
+
36
+ const api = {
37
+ version: '3.21.4',
38
+ options,
39
+ request,
40
+
41
+ init(store, key, opt = {}) {
42
+ options.key = key;
43
+ options.store = store;
44
+ options.url = opt.url
45
+ ? trimEnd(opt.url)
46
+ : `https://${store}.swell.store`;
47
+ options.vaultUrl = opt.vaultUrl
48
+ ? trimEnd(opt.vaultUrl)
49
+ : `https://vault.schema.io`;
50
+ options.timeout = (opt.timeout && parseInt(opt.timeout, 10)) || 20000;
51
+ options.useCamelCase = opt.useCamelCase || false;
52
+ options.previewContent = opt.previewContent || false;
53
+ options.session = opt.session;
54
+ options.locale = opt.locale;
55
+ options.currency = opt.currency;
56
+ options.api = api;
57
+ options.getCart = opt.getCart;
58
+ options.updateCart = opt.updateCart;
59
+ setOptions(options);
60
+ },
61
+
62
+ // Backward compatibility
63
+ auth(...args) {
64
+ return this.init(...args);
65
+ },
66
+
67
+ get(url, query) {
68
+ return request('get', url, query);
69
+ },
70
+
71
+ put(url, data) {
72
+ return request('put', url, data);
73
+ },
74
+
75
+ post(url, data) {
76
+ return request('post', url, data);
77
+ },
78
+
79
+ delete(url, data) {
80
+ return request('delete', url, data);
81
+ },
82
+
83
+ cache: cacheApi,
84
+
85
+ card: cardApi,
86
+
87
+ cart: methods$1(request, options),
88
+
89
+ account: methods$2(request),
90
+
91
+ products: methods$3(request, options),
92
+
93
+ categories: methods$4(request),
94
+
95
+ attributes: methods$5(request),
96
+
97
+ subscriptions: methods$6(request),
98
+
99
+ invoices: methods(request),
100
+
101
+ content: methods$7(request, options),
102
+
103
+ settings: methods$8(request, options),
104
+
105
+ payment: new PaymentController(request, options),
106
+
107
+ locale: methods$9(request, options),
108
+
109
+ currency: methods$a(request, options),
110
+
111
+ utils,
112
+ };
113
+
114
+ async function request(
115
+ method,
116
+ url,
117
+ id = undefined,
118
+ data = undefined,
119
+ opt = undefined,
120
+ ) {
121
+ const allOptions = {
122
+ ...options,
123
+ ...opt,
124
+ };
125
+
126
+ const session = allOptions.session || getCookie('swell-session');
127
+ const locale = allOptions.locale || getCookie('swell-locale');
128
+ const currency = allOptions.currency || getCookie('swell-currency');
129
+
130
+ const baseUrl = `${allOptions.url}${allOptions.base || ''}/api`;
131
+ const reqMethod = String(method).toLowerCase();
132
+
133
+ let reqUrl = url;
134
+ let reqData = id;
135
+
136
+ if (data !== undefined || typeof id === 'string') {
137
+ reqUrl = [trimEnd(url), trimStart(id)].join('/');
138
+ reqData = data;
139
+ }
140
+
141
+ reqUrl = allOptions.fullUrl || `${baseUrl}/${trimBoth(reqUrl)}`;
142
+ reqData = allOptions.useCamelCase ? toSnake(reqData) : reqData;
143
+
144
+ let reqBody;
145
+ if (reqMethod === 'get') {
146
+ let exQuery;
147
+ [reqUrl, exQuery] = reqUrl.split('?');
148
+ const fullQuery = [exQuery, stringifyQuery(reqData)]
149
+ .join('&')
150
+ .replace(/^&/, '');
151
+ reqUrl = `${reqUrl}${fullQuery ? `?${fullQuery}` : ''}`;
152
+ } else {
153
+ reqBody = JSON.stringify(reqData);
154
+ }
155
+
156
+ const reqHeaders = {
157
+ Accept: 'application/json',
158
+ 'Content-Type': 'application/json',
159
+ Authorization: `Basic ${base64Encode(String(allOptions.key))}`,
160
+ };
161
+
162
+ if (session) {
163
+ reqHeaders['X-Session'] = session;
164
+ }
165
+
166
+ if (locale) {
167
+ reqHeaders['X-Locale'] = locale;
168
+ }
169
+
170
+ if (currency) {
171
+ reqHeaders['X-Currency'] = currency;
172
+ }
173
+
174
+ const response = await fetch(reqUrl, {
175
+ method: reqMethod,
176
+ headers: reqHeaders,
177
+ body: reqBody,
178
+ credentials: 'include',
179
+ mode: 'cors',
180
+ });
181
+
182
+ const responseSession = response.headers.get('X-Session');
183
+
184
+ if (typeof responseSession === 'string' && session !== responseSession) {
185
+ setCookie('swell-session', responseSession);
186
+ }
187
+
188
+ const result = await response.json();
189
+
190
+ if (result && result.error) {
191
+ const err = new Error(result.error.message);
192
+ err.status = response.status;
193
+ err.code = result.error.code;
194
+ err.param = result.error.param;
195
+ throw err;
196
+ } else if (!response.ok) {
197
+ const err = new Error(
198
+ 'A connection error occurred while making the request',
199
+ );
200
+ err.code = 'connection_error';
201
+ throw err;
202
+ }
203
+
204
+ return options.useCamelCase ? toCamel(result) : result;
205
+ }
206
+
207
+ export { api as a };
package/dist/api.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as default } from './api-1b8787c3.js';
1
+ export { a as default } from './api-8fbb5805.js';
2
2
  import './card-91071403.js';
3
3
  import './index-512fc30d.js';
4
4
  import 'qs';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as default } from './api-1b8787c3.js';
1
+ export { a as default } from './api-8fbb5805.js';
2
2
  import './card-91071403.js';
3
3
  import './index-512fc30d.js';
4
4
  import 'qs';
package/dist/swell.cjs.js CHANGED
@@ -9407,7 +9407,7 @@ const options = {
9407
9407
  };
9408
9408
 
9409
9409
  const api = {
9410
- version: '3.21.3',
9410
+ version: '3.21.4',
9411
9411
  options,
9412
9412
  request,
9413
9413
 
@@ -13753,7 +13753,7 @@
13753
13753
  previewContent: null
13754
13754
  };
13755
13755
  const api = {
13756
- version: "3.21.3",
13756
+ version: "3.21.4",
13757
13757
  options,
13758
13758
  request,
13759
13759
  init(store, key, opt = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swell-js",
3
- "version": "3.21.3",
3
+ "version": "3.21.4",
4
4
  "description": "Swell JS library for client-side stores",
5
5
  "engines": {
6
6
  "node": ">=14.19.1",
@@ -169,7 +169,13 @@ export interface ProductSnake extends BaseModel {
169
169
  slug?: string;
170
170
  stock_level?: number;
171
171
  stock_purchasable?: boolean;
172
- stock_status?: 'available' | 'preorder' | 'backorder';
172
+ stock_status?:
173
+ | 'discontinued'
174
+ | 'preorder'
175
+ | 'backorder'
176
+ | 'in_stock'
177
+ | 'out_of_stock'
178
+ | null;
173
179
  stock_tracking?: boolean;
174
180
  tags?: string[];
175
181
  up_sells?: Upsell[];