-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathconfig.js
73 lines (65 loc) · 2.05 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* The class used to configure the JS Buy SDK Client.
* @class
*/
class Config {
/**
* Properties that must be set on initializations
* @attribute requiredProperties
* @default ['storefrontAccessToken', 'domain']
* @type Array
* @private
*/
get requiredProperties() {
return [
'storefrontAccessToken',
'domain'
];
}
/**
* Deprecated properties that map directly to required properties
* @attribute deprecatedProperties
* @default {'accessToken': 'storefrontAccessToken', 'apiKey': 'storefrontAccessToken'}
* @type Object
* @private
*/
get deprecatedProperties() {
return {
accessToken: 'storefrontAccessToken',
apiKey: 'storefrontAccessToken'
};
}
/**
* @constructs Config
* @param {Object} attrs An object specifying the configuration. Requires the following properties:
* @param {String} attrs.storefrontAccessToken The {@link https://help.shopify.com/api/reference/storefront_access_token|Storefront access token} for the shop.
* @param {String} attrs.domain The `myshopify` domain for the shop (e.g. `graphql.myshopify.com`).
*/
constructor(attrs) {
Object.keys(this.deprecatedProperties).forEach((key) => {
if (!attrs.hasOwnProperty(key)) { return; }
// eslint-disable-next-line no-console
console.warn(`[ShopifyBuy] Config property ${key} is deprecated as of v1.0, please use ${this.deprecatedProperties[key]} instead.`);
attrs[this.deprecatedProperties[key]] = attrs[key];
});
this.requiredProperties.forEach((key) => {
if (attrs.hasOwnProperty(key)) {
this[key] = attrs[key];
} else {
throw new Error(`new Config() requires the option '${key}'`);
}
});
if (attrs.hasOwnProperty('apiVersion')) {
this.apiVersion = attrs.apiVersion;
} else {
this.apiVersion = '2024-04';
}
if (attrs.hasOwnProperty('source')) {
this.source = attrs.source;
}
if (attrs.hasOwnProperty('language')) {
this.language = attrs.language;
}
}
}
export default Config;