swell-js 4.2.3-alpha.0 → 4.2.3

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
@@ -126,7 +126,14 @@ function methods(api, _opt) {
126
126
  };
127
127
  }
128
128
 
129
- function swell(initStore = undefined, initKey, initOpt = {}) {
129
+ /**
130
+ * Swell API client
131
+ * @param {string} initStore - Store name
132
+ * @param {string} initKey - API key
133
+ * @param {InitOptions} initOptions - Options
134
+ * @returns {SwellClient} API client
135
+ */
136
+ function swell(initStore = undefined, initKey, initOptions = {}) {
130
137
  const options = {
131
138
  store: null,
132
139
  key: null,
@@ -138,7 +145,7 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
138
145
  const api = {};
139
146
 
140
147
  Object.assign(api, {
141
- version: '4.2.3-alpha.0',
148
+ version: '4.2.3',
142
149
  options,
143
150
  request,
144
151
 
@@ -162,6 +169,8 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
162
169
  options.setCookie = opt.setCookie || setCookie;
163
170
  options.getCart = opt.getCart;
164
171
  options.updateCart = opt.updateCart;
172
+ options.headers = opt.headers || {};
173
+
165
174
  setOptions(options);
166
175
  },
167
176
 
@@ -231,6 +240,10 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
231
240
  const allOptions = {
232
241
  ...options,
233
242
  ...opt,
243
+ headers: {
244
+ ...options.headers,
245
+ ...(opt ? opt.headers : undefined),
246
+ },
234
247
  };
235
248
 
236
249
  const session = allOptions.session || allOptions.getCookie('swell-session');
@@ -266,6 +279,7 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
266
279
  }
267
280
 
268
281
  const reqHeaders = {
282
+ ...(allOptions.headers || undefined),
269
283
  Accept: 'application/json',
270
284
  'Content-Type': 'application/json',
271
285
  Authorization: `Basic ${base64Encode(String(allOptions.key))}`,
@@ -333,7 +347,7 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
333
347
  }
334
348
 
335
349
  if (initStore) {
336
- api.init(initStore, initKey, initOpt);
350
+ api.init(initStore, initKey, initOptions);
337
351
  }
338
352
 
339
353
  return api;
package/dist/swell.cjs CHANGED
@@ -10157,7 +10157,14 @@ function methods(api, _opt) {
10157
10157
  };
10158
10158
  }
10159
10159
 
10160
- function swell(initStore = undefined, initKey, initOpt = {}) {
10160
+ /**
10161
+ * Swell API client
10162
+ * @param {string} initStore - Store name
10163
+ * @param {string} initKey - API key
10164
+ * @param {InitOptions} initOptions - Options
10165
+ * @returns {SwellClient} API client
10166
+ */
10167
+ function swell(initStore = undefined, initKey, initOptions = {}) {
10161
10168
  const options = {
10162
10169
  store: null,
10163
10170
  key: null,
@@ -10169,7 +10176,7 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
10169
10176
  const api = {};
10170
10177
 
10171
10178
  Object.assign(api, {
10172
- version: '4.2.3-alpha.0',
10179
+ version: '4.2.3',
10173
10180
  options,
10174
10181
  request,
10175
10182
 
@@ -10193,6 +10200,8 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
10193
10200
  options.setCookie = opt.setCookie || setCookie;
10194
10201
  options.getCart = opt.getCart;
10195
10202
  options.updateCart = opt.updateCart;
10203
+ options.headers = opt.headers || {};
10204
+
10196
10205
  setOptions(options);
10197
10206
  },
10198
10207
 
@@ -10262,6 +10271,10 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
10262
10271
  const allOptions = {
10263
10272
  ...options,
10264
10273
  ...opt,
10274
+ headers: {
10275
+ ...options.headers,
10276
+ ...(opt ? opt.headers : undefined),
10277
+ },
10265
10278
  };
10266
10279
 
10267
10280
  const session = allOptions.session || allOptions.getCookie('swell-session');
@@ -10297,6 +10310,7 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
10297
10310
  }
10298
10311
 
10299
10312
  const reqHeaders = {
10313
+ ...(allOptions.headers || undefined),
10300
10314
  Accept: 'application/json',
10301
10315
  'Content-Type': 'application/json',
10302
10316
  Authorization: `Basic ${base64Encode(String(allOptions.key))}`,
@@ -10364,7 +10378,7 @@ function swell(initStore = undefined, initKey, initOpt = {}) {
10364
10378
  }
10365
10379
 
10366
10380
  if (initStore) {
10367
- api.init(initStore, initKey, initOpt);
10381
+ api.init(initStore, initKey, initOptions);
10368
10382
  }
10369
10383
 
10370
10384
  return api;