-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathLicenseManager.ts
More file actions
64 lines (56 loc) · 1.76 KB
/
LicenseManager.ts
File metadata and controls
64 lines (56 loc) · 1.76 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { stringify } from 'qs'
import { RequestConfig, RequestTracingConfig } from '../../HttpClient'
import { JanusClient } from './JanusClient'
const TWO_MINUTES_S = 2 * 60
const BASE_URL = '/api/license-manager'
const routes = {
accountData: `${BASE_URL}/account`,
resourceAccess: `${BASE_URL}/resources`,
topbarData: `${BASE_URL}/site/pvt/newtopbar`,
}
const inflightKey = ({baseURL, url, params}: RequestConfig) => {
return baseURL! + url! + stringify(params, {arrayFormat: 'repeat', addQueryPrefix: true})
}
export class LicenseManager extends JanusClient {
public getAccountData (VtexIdclientAutCookie: string, tracingConfig?: RequestTracingConfig) {
const metric = 'lm-account-data'
return this.http.get(routes.accountData, {
forceMaxAge: TWO_MINUTES_S,
headers: {
VtexIdclientAutCookie,
},
inflightKey,
metric,
tracing: {
requestSpanNameSuffix: metric,
...tracingConfig?.tracing,
},
})
}
public getTopbarData (VtexIdclientAutCookie: string, tracingConfig?: RequestTracingConfig) {
const metric = 'lm-topbar-data'
return this.http.get(routes.topbarData, {
headers: {
VtexIdclientAutCookie,
},
metric,
tracing: {
requestSpanNameSuffix: metric,
...tracingConfig?.tracing,
},
})
}
public canAccessResource (VtexIdclientAutCookie: string, resourceKey: string, tracingConfig?: RequestTracingConfig) {
const metric = 'lm-resource-access'
return this.http.get(`${routes.resourceAccess}/${resourceKey}/access`, {
headers: {
VtexIdclientAutCookie,
},
metric,
tracing: {
requestSpanNameSuffix: metric,
...tracingConfig?.tracing,
},
}).then(() => true, () => false)
}
}