|
1
|
|
|
import ApiService from 'src/core/service/api.service'; |
|
2
|
|
|
|
|
3
|
|
|
export default class ExtensionLicenseService extends ApiService { |
|
4
|
|
|
constructor(httpClient, loginService, apiEndpoint = 'plugin') { |
|
5
|
|
|
super(httpClient, loginService, apiEndpoint); |
|
6
|
|
|
this.name = 'extensionStoreLicensesService'; |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
async getLicensedExtensions(context) { |
|
10
|
|
|
const { data } = await this.httpClient.get('_action/extension/licensed', { |
|
11
|
|
|
headers: this.basicHeaders(context), |
|
12
|
|
|
version: 3 |
|
13
|
|
|
}); |
|
14
|
|
|
|
|
15
|
|
|
const licensedExtensions = data.data; |
|
16
|
|
|
licensedExtensions.total = data.meta.total; |
|
17
|
|
|
|
|
18
|
|
|
return licensedExtensions; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
async purchaseExtension(extensionId, variantId, tocAccepted, permissionsAccepted) { |
|
22
|
|
|
await this.httpClient.post( |
|
23
|
|
|
'_action/extension/purchase', |
|
24
|
|
|
{ extensionId, variantId, tocAccepted, permissionsAccepted }, |
|
25
|
|
|
{ |
|
26
|
|
|
headers: this.basicHeaders(), |
|
27
|
|
|
version: 3 |
|
28
|
|
|
} |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
basicHeaders(context = null) { |
|
33
|
|
|
const headers = { |
|
34
|
|
|
'Content-Type': 'application/json', |
|
35
|
|
|
Accept: 'application/json', |
|
36
|
|
|
Authorization: `Bearer ${this.loginService.getToken()}` |
|
37
|
|
|
}; |
|
38
|
|
|
|
|
39
|
|
|
if (context && context.languageId) { |
|
40
|
|
|
headers['sw-language-id'] = context.languageId; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return headers; |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|