Repository navigation
Expand file tree
/
Copy pathanalyticsConfig.ts
More file actions
106 lines (94 loc) · 2.71 KB
/
Copy pathanalyticsConfig.ts
File metadata and controls
106 lines (94 loc) · 2.71 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import {
AnalyticsConfigApi,
AnalyticsConfigResponse,
CreateAnalyticsConfigModel,
UpdateAnalyticsConfigModel,
} from '../internal/api';
import { ApiCredentials } from './apiCredentials';
import { validateString } from './validators';
export class AnalyticsConfigAPI {
private internalApi: AnalyticsConfigApi;
constructor(baseURL?: string, apiKey?: string) {
this.internalApi = new AnalyticsConfigApi(baseURL);
this.internalApi.accessToken = apiKey;
}
async createAnalyticsConfig(
config: CreateAnalyticsConfigModel,
credentials?: ApiCredentials
): Promise<AnalyticsConfigResponse> {
validateString(
config.clientAnalyticsKey,
'The clientAnalyticsKey must be provided as an input and has to be nonempty.'
);
validateString(
config.serverAnalyticsKey,
'The serverAnalyticsKey must be provided as an input and has to be nonempty.'
);
const headers: any = {};
if (credentials?.userJwt) {
headers['X-User-JWT'] = credentials.userJwt;
}
if (
credentials?.projectId !== undefined &&
credentials.projectId !== null
) {
headers['X-Project-Id'] = String(credentials.projectId);
}
const res =
await this.internalApi.analyticsConfigControllerCreateAnalyticsConfig(
config,
{ headers }
);
return res.body;
}
async getAnalyticsConfig(
projectId: string,
credentials?: ApiCredentials
): Promise<AnalyticsConfigResponse> {
validateString(
projectId,
'The projectId must be provided as an input and has to be nonempty.'
);
const headers: any = {};
if (credentials?.userJwt) {
headers['X-User-JWT'] = credentials.userJwt;
}
if (credentials?.projectId !== undefined) {
headers['X-Project-Id'] = String(credentials.projectId);
}
const res =
await this.internalApi.analyticsConfigControllerGetAnalyticsConfig(
projectId,
{ headers }
);
return res.body;
}
async updateAnalyticsConfig(
projectId: string,
config: UpdateAnalyticsConfigModel
): Promise<AnalyticsConfigResponse> {
validateString(
projectId,
'The projectId must be provided as an input and has to be nonempty.'
);
const res =
await this.internalApi.analyticsConfigControllerUpdateAnalyticsConfig(
projectId,
config
);
return res.body;
}
async deleteAnalyticsConfig(
projectId: string
): Promise<AnalyticsConfigResponse> {
validateString(
projectId,
'The projectId must be provided as an input and has to be nonempty.'
);
const res =
await this.internalApi.analyticsConfigControllerDeleteAnalyticsConfig(
projectId
);
return res.body;
}
}