@rebuy/rebuy 1.3.11 → 1.4.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 (3) hide show
  1. package/api.js +29 -1
  2. package/client.js +33 -6
  3. package/package.json +1 -1
package/api.js CHANGED
@@ -3,14 +3,25 @@ import { serialize } from './utilities.js';
3
3
  const config = {
4
4
  key: null,
5
5
  domain: 'https://rebuyengine.com',
6
+ /**
7
+ * @deprecated
8
+ */
6
9
  cdnDomain: 'https://cdn.rebuyengine.com',
7
10
  eventDomain: 'https://rebuyengine.com',
11
+ shieldDomain: 'https://cached.rebuyengine.com',
12
+ staticDomain: 'https://cdn.rebuyengine.com',
13
+ shop: null,
8
14
  };
9
15
 
10
16
  const staging = {
11
17
  domain: 'https://enigneyuber.com',
18
+ /**
19
+ * @deprecated
20
+ */
12
21
  cdnDomain: 'https://cdn.enigneyuber.com',
13
22
  eventDomain: 'https://enigneyuber.com',
23
+ shieldDomain: 'https://cached.enigneyuber.com',
24
+ staticDomain: 'https://cdn.enigneyuber.com',
14
25
  };
15
26
 
16
27
  const stagingDomains = [
@@ -21,7 +32,9 @@ const stagingDomains = [
21
32
  'rebuy-staging-regression.myshopify.com',
22
33
  'rebuy-uat.myshopify.com',
23
34
  'rebuy-regression-qa.myshopify.com',
24
- 'rebuy-marketing.myshopify.com',
35
+ 'senator-staging.myshopify.com',
36
+ 'mike-reids-test-store.myshopify.com',
37
+ 'dash-ext-hoke.myshopify.com',
25
38
  ];
26
39
 
27
40
  const makeCall = async (method, path, data, origin, options = {}) => {
@@ -77,6 +90,10 @@ export class Api {
77
90
  Object.assign(config, staging);
78
91
  break;
79
92
  }
93
+ if (typeof config.shop === 'string' && config.shop.includes(domain)) {
94
+ Object.assign(config, staging);
95
+ break;
96
+ }
80
97
  }
81
98
  }
82
99
 
@@ -84,6 +101,17 @@ export class Api {
84
101
  return await makeCall(method, path, data, config.eventDomain, options);
85
102
  }
86
103
 
104
+ async callShield(method, path, data, options = {}) {
105
+ return await makeCall(method, path, data, config.shieldDomain, options);
106
+ }
107
+
108
+ async callStatic(method, path, data, options = {}) {
109
+ return await makeCall(method, path, data, config.staticDomain, options);
110
+ }
111
+
112
+ /**
113
+ * @deprecated
114
+ */
87
115
  async callCdn(method, path, data, options = {}) {
88
116
  return await makeCall(method, path, data, config.cdnDomain, options);
89
117
  }
package/client.js CHANGED
@@ -1,6 +1,6 @@
1
- import { convertProductToStorefrontFormat } from './utilities.js';
2
- import Identity from './identity.js';
3
1
  import Api from './api.js';
2
+ import Identity from './identity.js';
3
+ import { convertProductToStorefrontFormat } from './utilities.js';
4
4
 
5
5
  const config = {
6
6
  key: null,
@@ -8,6 +8,7 @@ const config = {
8
8
  contextParameters: null,
9
9
  api: null,
10
10
  identity: null,
11
+ shop: null,
11
12
  };
12
13
 
13
14
  const trackEvent = async (eventData) => {
@@ -18,6 +19,17 @@ const trackEvent = async (eventData) => {
18
19
  return await config.api.callEvent('POST', '/api/v1/analytics/event', eventData);
19
20
  };
20
21
 
22
+ const makeShieldCall = async (endpoint, params, format, options = {}) => {
23
+ return await makeCall(endpoint, params, format, { ...options, shield: true });
24
+ };
25
+
26
+ const makeStaticCall = async (endpoint, params, format, options = {}) => {
27
+ return await makeCall(endpoint, params, format, { ...options, static: true });
28
+ };
29
+
30
+ /**
31
+ * @deprecated
32
+ */
21
33
  const makeCDNCall = async (endpoint, params, format, options = {}) => {
22
34
  return await makeCall(endpoint, params, format, { ...options, cdn: true });
23
35
  };
@@ -46,8 +58,8 @@ const makeCall = async (endpoint, params, format, options = {}) => {
46
58
  query.uuid = config.identity.visitorId();
47
59
  }
48
60
 
49
- // Origin or CDN?
50
- const source = options.cdn ? 'callCdn' : 'callApi';
61
+ // Origin or dedicated edge?
62
+ const source = options.cdn ? 'callCdn' : options.shield ? 'callShield' : options.static ? 'callStatic' : 'callApi';
51
63
  const response = await config.api[source]('GET', endpoint, query, options);
52
64
 
53
65
  if (response.data && format == 'storefront') {
@@ -60,7 +72,7 @@ const makeCall = async (endpoint, params, format, options = {}) => {
60
72
  };
61
73
 
62
74
  export class RebuyClient {
63
- constructor(key, defaultParameters) {
75
+ constructor(key, defaultParameters, shop) {
64
76
  if (typeof key == 'string') {
65
77
  config.key = key;
66
78
  }
@@ -69,7 +81,11 @@ export class RebuyClient {
69
81
  config.defaultParameters = defaultParameters;
70
82
  }
71
83
 
72
- config.api = new Api(config.key);
84
+ if (typeof shop == 'string' && shop.endsWith('.myshopify.com')) {
85
+ config.shop = shop;
86
+ }
87
+
88
+ config.api = new Api({ key: config.key, shop: config.shop });
73
89
  config.identity = new Identity();
74
90
  }
75
91
 
@@ -89,10 +105,21 @@ export class RebuyClient {
89
105
  return await makeCall(endpoint, params, null, options);
90
106
  }
91
107
 
108
+ /**
109
+ * @deprecated
110
+ */
92
111
  async getDataFromCDN(endpoint, params, options = {}) {
93
112
  return await makeCDNCall(endpoint, params, null, options);
94
113
  }
95
114
 
115
+ async getShieldedAsset(endpoint, params, options = {}) {
116
+ return await makeShieldCall(endpoint, params, null, options);
117
+ }
118
+
119
+ async getStaticAsset(endpoint, params, options = {}) {
120
+ return await makeStaticCall(endpoint, params, null, options);
121
+ }
122
+
96
123
  async getStorefrontData(endpoint, params, options = {}) {
97
124
  return await makeCall(endpoint, params, 'storefront', options);
98
125
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rebuy/rebuy",
3
3
  "description": "This is the default library for Rebuy",
4
- "version": "1.3.11",
4
+ "version": "1.4.0",
5
5
  "license": "MIT",
6
6
  "author": "Rebuy, Inc.",
7
7
  "type": "module",