forked from ordercloud-api/ordercloud-javascript-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration.ts
More file actions
49 lines (43 loc) · 1.38 KB
/
Copy pathConfiguration.ts
File metadata and controls
49 lines (43 loc) · 1.38 KB
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
import { SdkConfiguration } from './models'
class Configuration {
private defaultConfig: SdkConfiguration = {
// This URL can be found on your dashboard or in the upper right hand context menu of your OrderCloud application in Sitecore Portal.
baseApiUrl: 'https://api.ordercloud.io',
apiVersion: 'v1',
timeoutInMilliseconds: 60 * 1000, // 60 seconds by default
clientID: null,
cookieOptions: {
samesite: 'lax', // browser default
secure: false,
domain: null,
prefix: 'ordercloud',
path: '/', // accessible on any path in the domain
},
}
private config: SdkConfiguration = cloneDeep(this.defaultConfig)
/**
* @ignore
* not part of public api, don't include in generated docs
*/
constructor() {
this.Set = this.Set.bind(this)
this.Get = this.Get.bind(this)
}
Set(config: SdkConfiguration): void {
this.config = { ...this.defaultConfig, ...this.config, ...(config || {}) }
this.config.cookieOptions = {
...this.defaultConfig.cookieOptions,
...this.config.cookieOptions,
...(config?.cookieOptions || {}),
}
}
Get(): SdkConfiguration {
return this.config
}
}
// takes an object and creates a new one with same properties/values
// useful so we don't mutate original object
function cloneDeep(obj: any): any {
return JSON.parse(JSON.stringify(obj))
}
export default new Configuration()