@ampsec/platform-client 40.0.0 → 40.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/dto/enums/finding.status.d.ts +25 -1
- package/build/src/dto/enums/finding.status.js +25 -1
- package/build/src/dto/enums/finding.status.js.map +1 -1
- package/build/src/services/AmpApi.d.ts +3 -2
- package/build/src/services/AmpApi.js +2 -1
- package/build/src/services/AmpApi.js.map +1 -1
- package/build/src/services/data.service.d.ts +5 -5
- package/build/src/services/data.service.js +45 -45
- package/build/src/services/data.service.js.map +1 -1
- package/build/src/services/entity.service.d.ts +5 -5
- package/build/src/services/entity.service.js +56 -56
- package/build/src/services/entity.service.js.map +1 -1
- package/build/src/services/findings.service.d.ts +10 -0
- package/build/src/services/findings.service.js +24 -0
- package/build/src/services/findings.service.js.map +1 -0
- package/build/src/services/index.d.ts +1 -0
- package/build/src/services/index.js +1 -0
- package/build/src/services/index.js.map +1 -1
- package/build/src/services/reports.service.d.ts +2 -2
- package/build/src/services/reports.service.js +40 -40
- package/build/src/services/reports.service.js.map +1 -1
- package/build/src/services/rest/AgentIdentityService.d.ts +2 -2
- package/build/src/services/rest/AgentIdentityService.js +17 -17
- package/build/src/services/rest/AgentIdentityService.js.map +1 -1
- package/build/src/services/rest/ConnectorInstallService.d.ts +2 -2
- package/build/src/services/rest/ConnectorInstallService.js +12 -12
- package/build/src/services/rest/ConnectorInstallService.js.map +1 -1
- package/build/src/services/rest/EnumService.js +8 -8
- package/build/src/services/rest/EnumService.js.map +1 -1
- package/build/src/services/rest/RestClient.d.ts +1 -1
- package/build/src/services/rest/RestClient.js +27 -27
- package/build/src/services/rest/RestClient.js.map +1 -1
- package/build/src/services/rest/UserIdentityService.d.ts +1 -1
- package/build/src/services/rest/UserIdentityService.js +7 -7
- package/build/src/services/rest/UserIdentityService.js.map +1 -1
- package/build/src/services/rest/rateLimit.rest.d.ts +1 -1
- package/build/src/services/rest/rateLimit.rest.js +8 -8
- package/build/src/services/rest/rateLimit.rest.js.map +1 -1
- package/build/src/services/rest/retry.rest.js +1 -1
- package/build/src/services/rest/retry.rest.js.map +1 -1
- package/build/src/services/settings.service.d.ts +10 -10
- package/build/src/services/settings.service.js +96 -96
- package/build/src/services/settings.service.js.map +1 -1
- package/package.json +1 -1
- package/src/dto/enums/finding.status.ts +26 -1
- package/src/services/AmpApi.ts +3 -3
- package/src/services/data.service.ts +10 -10
- package/src/services/entity.service.ts +10 -10
- package/src/services/findings.service.ts +24 -0
- package/src/services/index.ts +1 -0
- package/src/services/reports.service.ts +4 -4
- package/src/services/rest/AgentIdentityService.ts +4 -4
- package/src/services/rest/ConnectorInstallService.ts +4 -4
- package/src/services/rest/EnumService.ts +2 -2
- package/src/services/rest/RestClient.ts +2 -2
- package/src/services/rest/UserIdentityService.ts +2 -2
- package/src/services/rest/rateLimit.rest.ts +3 -3
- package/src/services/rest/retry.rest.ts +1 -1
- package/src/services/settings.service.ts +20 -20
|
@@ -1,6 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum for FindingStatus
|
|
3
|
+
*
|
|
4
|
+
* | | OPEN | CLOSED |
|
|
5
|
+
* | :-------------------- | :------------------- | :----- |
|
|
6
|
+
* | Included in score | OPEN + ACCEPTED_RISK | N/A |
|
|
7
|
+
* | Not included in score | FALSE_POSITIVE | CLOSED |
|
|
8
|
+
*
|
|
9
|
+
* - OPEN
|
|
10
|
+
* - Included in Score
|
|
11
|
+
* - OPEN
|
|
12
|
+
* - ACCEPTED_RISK
|
|
13
|
+
* - Not included in Score
|
|
14
|
+
* - PENDING_VERIFICATION
|
|
15
|
+
* - FALSE_POSITIVE
|
|
16
|
+
* - CLOSED
|
|
17
|
+
*/
|
|
18
|
+
|
|
1
19
|
/* eslint-disable no-unused-vars */
|
|
2
20
|
export enum FindingStatus {
|
|
21
|
+
/** OPEN + INCLUDED in score */
|
|
3
22
|
OPEN = 'OPEN',
|
|
4
|
-
|
|
23
|
+
/** OPEN + INCLUDED in score */
|
|
5
24
|
PENDING_VERIFICATION = 'PENDING_VERIFICATION',
|
|
25
|
+
/** OPEN + INCLUDED in score */
|
|
26
|
+
ACCEPTED_RISK = 'ACCEPTED_RISK',
|
|
27
|
+
/** CLOSED + IGNORED from score */
|
|
28
|
+
CLOSED = 'CLOSED',
|
|
29
|
+
/** CLOSED + IGNORED from score */
|
|
30
|
+
FALSE_POSITIVE = 'CLOSED_FALSE_POSITIVE',
|
|
6
31
|
}
|
package/src/services/AmpApi.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
AssetDto,
|
|
5
5
|
ConnectorDto,
|
|
6
6
|
ConnectorUpsertDto,
|
|
7
|
-
FindingDto,
|
|
8
7
|
NotificationDto,
|
|
9
8
|
ProviderDto,
|
|
10
9
|
ReportResultDto,
|
|
@@ -24,6 +23,7 @@ import {DefaultEnumService, EnumService} from './rest/EnumService';
|
|
|
24
23
|
import {AmpSettingsService} from './settings.service';
|
|
25
24
|
import {AgentIdentityService} from './rest/AgentIdentityService';
|
|
26
25
|
import {ConnectorInstallService} from './rest/ConnectorInstallService';
|
|
26
|
+
import {FindingsService} from './findings.service';
|
|
27
27
|
|
|
28
28
|
export type AmpApiOptions = AmpRestClientOptions;
|
|
29
29
|
|
|
@@ -44,7 +44,7 @@ export class AmpApi {
|
|
|
44
44
|
readonly asset: AmpDataService<AssetDto>;
|
|
45
45
|
readonly connectors: AmpEntityService<ConnectorUpsertDto, ConnectorDto>;
|
|
46
46
|
readonly enums: EnumService;
|
|
47
|
-
readonly findings:
|
|
47
|
+
readonly findings: FindingsService;
|
|
48
48
|
readonly identity: AgentIdentityService;
|
|
49
49
|
readonly install: ConnectorInstallService;
|
|
50
50
|
readonly notifications: AmpDataService<NotificationDto>;
|
|
@@ -63,7 +63,7 @@ export class AmpApi {
|
|
|
63
63
|
this.asset = new AmpDataServiceImpl<AssetDto>(rest, KIND.ASSETS);
|
|
64
64
|
this.connectors = new AmpEntityServiceImpl<ConnectorUpsertDto, ConnectorDto>(rest, KIND.CONNECTORS);
|
|
65
65
|
this.enums = new DefaultEnumService(rest);
|
|
66
|
-
this.findings = new
|
|
66
|
+
this.findings = new FindingsService(rest);
|
|
67
67
|
this.identity = new AgentIdentityService(rest);
|
|
68
68
|
this.install = new ConnectorInstallService(rest);
|
|
69
69
|
this.notifications = new AmpDataServiceImpl<NotificationDto>(rest, KIND.NOTIFICATIONS);
|
|
@@ -29,7 +29,7 @@ export class AmpDataServiceImpl<ReadT extends BaseDto> implements AmpDataService
|
|
|
29
29
|
this.targetApi = targetApi;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
protected async
|
|
32
|
+
protected call = async <T>(req: RestRequest, errorHandler: ErrorHandler<T>): Promise<T> => {
|
|
33
33
|
try {
|
|
34
34
|
const res = await this.rest.call(req);
|
|
35
35
|
return res.data as T;
|
|
@@ -39,9 +39,9 @@ export class AmpDataServiceImpl<ReadT extends BaseDto> implements AmpDataService
|
|
|
39
39
|
}
|
|
40
40
|
return errorHandler(error);
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
};
|
|
43
43
|
|
|
44
|
-
protected async
|
|
44
|
+
protected getPage = async (req: RestRequest): Promise<Page<ReadT>> => {
|
|
45
45
|
return this.call(req, (error: unknown) => {
|
|
46
46
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
47
47
|
return {
|
|
@@ -51,22 +51,22 @@ export class AmpDataServiceImpl<ReadT extends BaseDto> implements AmpDataService
|
|
|
51
51
|
hints: {},
|
|
52
52
|
};
|
|
53
53
|
});
|
|
54
|
-
}
|
|
54
|
+
};
|
|
55
55
|
|
|
56
|
-
list(filter: FilterCriteria): Promise<Page<ReadT>> {
|
|
56
|
+
list = (filter: FilterCriteria): Promise<Page<ReadT>> => {
|
|
57
57
|
return this.getPage({
|
|
58
58
|
url: `/${this.targetApi}/v1/${this.kind}`,
|
|
59
59
|
method: 'GET',
|
|
60
60
|
params: filter,
|
|
61
61
|
});
|
|
62
|
-
}
|
|
62
|
+
};
|
|
63
63
|
|
|
64
|
-
getById(id: string): Promise<Page<ReadT>> {
|
|
64
|
+
getById = (id: string): Promise<Page<ReadT>> => {
|
|
65
65
|
return this.getPage({
|
|
66
66
|
url: `/${this.targetApi}/v1/${this.kind}/${id}`,
|
|
67
67
|
method: 'GET',
|
|
68
68
|
});
|
|
69
|
-
}
|
|
69
|
+
};
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export class AmpPatchDataServiceImpl<WriteT extends BaseUpsertDto, ReadT extends BaseDto> extends AmpDataServiceImpl<ReadT> implements AmpPatchDataService<WriteT, ReadT> {
|
|
@@ -74,7 +74,7 @@ export class AmpPatchDataServiceImpl<WriteT extends BaseUpsertDto, ReadT extends
|
|
|
74
74
|
super(rest, kind, targetApi);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
patch(model: WriteT | WriteT[], options: DataServiceCallOptions): Promise<Page<ReadT>> {
|
|
77
|
+
patch = (model: WriteT | WriteT[], options: DataServiceCallOptions): Promise<Page<ReadT>> => {
|
|
78
78
|
const url = _.isArray(model) ? `/${this.targetApi}/v1/${this.kind}` : `/${this.targetApi}/v1/${this.kind}/${model.id}`;
|
|
79
79
|
return this.getPage({
|
|
80
80
|
url,
|
|
@@ -82,5 +82,5 @@ export class AmpPatchDataServiceImpl<WriteT extends BaseUpsertDto, ReadT extends
|
|
|
82
82
|
params: options.params as QueryMap,
|
|
83
83
|
data: model,
|
|
84
84
|
});
|
|
85
|
-
}
|
|
85
|
+
};
|
|
86
86
|
}
|
|
@@ -38,16 +38,16 @@ export class AmpEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT extends Ba
|
|
|
38
38
|
super(rest, kind, targetApi);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
create(model: WriteT | WriteT[], options?: EntityCallOptions): Promise<Page<ReadT>> {
|
|
41
|
+
create = (model: WriteT | WriteT[], options?: EntityCallOptions): Promise<Page<ReadT>> => {
|
|
42
42
|
return this.getPage({
|
|
43
43
|
url: `/${this.targetApi}/v1/${this.kind}`,
|
|
44
44
|
method: 'POST',
|
|
45
45
|
params: options?.params as QueryMap,
|
|
46
46
|
data: model,
|
|
47
47
|
});
|
|
48
|
-
}
|
|
48
|
+
};
|
|
49
49
|
|
|
50
|
-
update(model: WriteT | WriteT[], options?: EntityCallOptions): Promise<Page<ReadT>> {
|
|
50
|
+
update = (model: WriteT | WriteT[], options?: EntityCallOptions): Promise<Page<ReadT>> => {
|
|
51
51
|
const url = _.isArray(model) ? `/${this.targetApi}/v1/${this.kind}` : `/${this.targetApi}/v1/${this.kind}/${model.id}`;
|
|
52
52
|
return this.getPage({
|
|
53
53
|
url,
|
|
@@ -55,9 +55,9 @@ export class AmpEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT extends Ba
|
|
|
55
55
|
params: options?.params as QueryMap,
|
|
56
56
|
data: model,
|
|
57
57
|
});
|
|
58
|
-
}
|
|
58
|
+
};
|
|
59
59
|
|
|
60
|
-
async
|
|
60
|
+
delete = async (id: string, options?: EntityCallOptions): Promise<Page<ReadT>> => {
|
|
61
61
|
const res = await this.getById(id);
|
|
62
62
|
if (res.data.length === 1) {
|
|
63
63
|
const req: RestRequest = {
|
|
@@ -76,7 +76,7 @@ export class AmpEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT extends Ba
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
return res;
|
|
79
|
-
}
|
|
79
|
+
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const extIdMapErrorHandler: ErrorHandler<ExtKeyMap> = (error: unknown) => {
|
|
@@ -93,7 +93,7 @@ export class AmpGlobalEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT exte
|
|
|
93
93
|
constructor(rest: RestClient, kind: string, targetApi: TargetApi = TARGET_API_AGENT) {
|
|
94
94
|
super(rest, kind, targetApi);
|
|
95
95
|
}
|
|
96
|
-
getLookupIds(tid: string, options?: EntityCallOptions): Promise<ExtKeyMap> {
|
|
96
|
+
getLookupIds = (tid: string, options?: EntityCallOptions): Promise<ExtKeyMap> => {
|
|
97
97
|
const req: RestRequest = {
|
|
98
98
|
url: `/${this.targetApi}/v1/${this.kind}/ext_key_map`,
|
|
99
99
|
method: 'GET',
|
|
@@ -103,7 +103,7 @@ export class AmpGlobalEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT exte
|
|
|
103
103
|
},
|
|
104
104
|
};
|
|
105
105
|
return this.call(req, extIdMapErrorHandler);
|
|
106
|
-
}
|
|
106
|
+
};
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
export class AmpSaaSEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT extends BaseDto>
|
|
@@ -113,7 +113,7 @@ export class AmpSaaSEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT extend
|
|
|
113
113
|
constructor(rest: RestClient, kind: string, targetApi: TargetApi = TARGET_API_AGENT) {
|
|
114
114
|
super(rest, kind, targetApi);
|
|
115
115
|
}
|
|
116
|
-
getLookupIds(cid: string, options?: EntityCallOptions): Promise<ExtKeyMap> {
|
|
116
|
+
getLookupIds = (cid: string, options?: EntityCallOptions): Promise<ExtKeyMap> => {
|
|
117
117
|
const req: RestRequest = {
|
|
118
118
|
url: `/${this.targetApi}/v1/${this.kind}/ext_key_map`,
|
|
119
119
|
method: 'GET',
|
|
@@ -123,5 +123,5 @@ export class AmpSaaSEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT extend
|
|
|
123
123
|
},
|
|
124
124
|
};
|
|
125
125
|
return this.call(req, extIdMapErrorHandler);
|
|
126
|
-
}
|
|
126
|
+
};
|
|
127
127
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import {FindingDto, FindingStatus, Page} from '../dto';
|
|
3
|
+
import {AmpDataServiceImpl} from './data.service';
|
|
4
|
+
import {RestClient} from './rest';
|
|
5
|
+
import {KIND} from './constants';
|
|
6
|
+
|
|
7
|
+
export interface FindingPatchDto {
|
|
8
|
+
status: FindingStatus;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class FindingsService extends AmpDataServiceImpl<FindingDto> {
|
|
12
|
+
constructor(rest: RestClient) {
|
|
13
|
+
super(rest, KIND.FINDINGS);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
patch(id: string, values: FindingPatchDto | FindingPatchDto[]): Promise<Page<FindingDto>> {
|
|
17
|
+
const url = _.isArray(values) ? `/${this.targetApi}/v1/${this.kind}` : `/${this.targetApi}/v1/${this.kind}/${id}`;
|
|
18
|
+
return this.getPage({
|
|
19
|
+
url,
|
|
20
|
+
method: 'PATCH',
|
|
21
|
+
data: values,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/services/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ export class AmpReportServiceImpl implements AmpReportService {
|
|
|
15
15
|
this.rest = rest;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
async
|
|
18
|
+
getMetrics = async (reportId: string, filter?: FilterCriteria | undefined): Promise<Page<ReportResultDto>> => {
|
|
19
19
|
filter = filter ?? {};
|
|
20
20
|
filter.limit = filter.limit ?? 1; // pull latest result by default
|
|
21
21
|
try {
|
|
@@ -37,7 +37,7 @@ export class AmpReportServiceImpl implements AmpReportService {
|
|
|
37
37
|
hints: {},
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
}
|
|
40
|
+
};
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
*
|
|
@@ -46,11 +46,11 @@ export class AmpReportServiceImpl implements AmpReportService {
|
|
|
46
46
|
* @param filter
|
|
47
47
|
* @returns
|
|
48
48
|
*/
|
|
49
|
-
async
|
|
49
|
+
getMetricsTrend = async (reportId: string, filter?: FilterCriteria): Promise<Page<ReportResultDto>> => {
|
|
50
50
|
// I am breaking this out into a separate method so that we can extend typing later
|
|
51
51
|
// and add buckets/aggregations to the args
|
|
52
52
|
filter = filter ?? {};
|
|
53
53
|
filter.limit = filter.limit ?? DEFAULT_TREND_WINDOW_MONTHS;
|
|
54
54
|
return this.getMetrics(reportId, filter);
|
|
55
|
-
}
|
|
55
|
+
};
|
|
56
56
|
}
|
|
@@ -10,7 +10,7 @@ export class AgentIdentityService {
|
|
|
10
10
|
constructor(rest: RestClient) {
|
|
11
11
|
this.rest = rest;
|
|
12
12
|
}
|
|
13
|
-
async
|
|
13
|
+
exchangeToken = async (targetTenantId: string): Promise<TokenResponse> => {
|
|
14
14
|
const res = await this.rest.call({
|
|
15
15
|
url: '/api/v1/auth/token/exchange',
|
|
16
16
|
method: 'GET',
|
|
@@ -19,13 +19,13 @@ export class AgentIdentityService {
|
|
|
19
19
|
},
|
|
20
20
|
});
|
|
21
21
|
return res.data as TokenResponse;
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
23
|
|
|
24
|
-
async
|
|
24
|
+
me = async (): Promise<AgentDto> => {
|
|
25
25
|
const res = await this.rest.call({
|
|
26
26
|
url: '/api/v1/me',
|
|
27
27
|
method: 'GET',
|
|
28
28
|
});
|
|
29
29
|
return res.data as AgentDto;
|
|
30
|
-
}
|
|
30
|
+
};
|
|
31
31
|
}
|
|
@@ -7,7 +7,7 @@ export class ConnectorInstallService {
|
|
|
7
7
|
this.rest = rest;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
async
|
|
10
|
+
getInstallToken = async (cid: string): Promise<string> => {
|
|
11
11
|
const res = await this.rest.call({
|
|
12
12
|
url: '/install/oauth/token',
|
|
13
13
|
method: 'POST',
|
|
@@ -15,9 +15,9 @@ export class ConnectorInstallService {
|
|
|
15
15
|
});
|
|
16
16
|
const token = (res.data as {token: string}).token;
|
|
17
17
|
return token;
|
|
18
|
-
}
|
|
18
|
+
};
|
|
19
19
|
|
|
20
|
-
buildInstallOAuthUrl(apiBaseUrl: string, token: string, redirectUrl: string): string {
|
|
20
|
+
buildInstallOAuthUrl = (apiBaseUrl: string, token: string, redirectUrl: string): string => {
|
|
21
21
|
return `${apiBaseUrl}/install/oauth?token=${token}&redirect=${encodeURIComponent(redirectUrl)}`;
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
23
|
}
|
|
@@ -23,14 +23,14 @@ class DefaultEnumCollection implements EnumCollection {
|
|
|
23
23
|
this.kind = kind;
|
|
24
24
|
this.targetApi = targetApi;
|
|
25
25
|
}
|
|
26
|
-
async
|
|
26
|
+
list = async (filter?: FilterCriteria): Promise<Page<EnumDto>> => {
|
|
27
27
|
const res = await this.rest.call({
|
|
28
28
|
url: `/${this.targetApi}/v1/enum/${this.kind}`,
|
|
29
29
|
method: 'GET',
|
|
30
30
|
params: filter,
|
|
31
31
|
});
|
|
32
32
|
return res.data as Page<EnumDto>;
|
|
33
|
-
}
|
|
33
|
+
};
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export class DefaultEnumService implements EnumService {
|
|
@@ -68,7 +68,7 @@ export class DefaultRestClient {
|
|
|
68
68
|
this.retryStrategy = options.retryStrategy ?? noopRestRetryStrategy;
|
|
69
69
|
this.rateLimitStrategy = options.rateLimitStrategy ?? noopRestClientRateLimitStrategy;
|
|
70
70
|
}
|
|
71
|
-
async
|
|
71
|
+
call = async (request: RestRequest): Promise<RestResponse> => {
|
|
72
72
|
const req = _.merge(request);
|
|
73
73
|
try {
|
|
74
74
|
await this.rateLimitStrategy.reserve(req);
|
|
@@ -92,7 +92,7 @@ export class DefaultRestClient {
|
|
|
92
92
|
}
|
|
93
93
|
throw err;
|
|
94
94
|
}
|
|
95
|
-
}
|
|
95
|
+
};
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export const getAmpRestClient = (options: AmpRestClientOptions): RestClient => {
|
|
@@ -10,11 +10,11 @@ export class UserIdentityService {
|
|
|
10
10
|
constructor(rest: RestClient) {
|
|
11
11
|
this.rest = rest;
|
|
12
12
|
}
|
|
13
|
-
async
|
|
13
|
+
me = async (): Promise<AmpJwtToken> => {
|
|
14
14
|
const res = await this.rest.call({
|
|
15
15
|
url: '/eng/v1/me',
|
|
16
16
|
method: 'GET',
|
|
17
17
|
});
|
|
18
18
|
return res.data as AmpJwtToken;
|
|
19
|
-
}
|
|
19
|
+
};
|
|
20
20
|
}
|
|
@@ -6,7 +6,7 @@ export interface RestClientRateLimitStrategy {
|
|
|
6
6
|
|
|
7
7
|
export const noopRestClientRateLimitStrategy: RestClientRateLimitStrategy = {
|
|
8
8
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
-
reserve(_req: RestRequest): Promise<void> {
|
|
9
|
+
reserve: (_req: RestRequest): Promise<void> => {
|
|
10
10
|
return Promise.resolve();
|
|
11
11
|
},
|
|
12
12
|
};
|
|
@@ -22,10 +22,10 @@ export class StaticRestClientRateLimitStrategy implements RestClientRateLimitStr
|
|
|
22
22
|
this.lastRequest = 0;
|
|
23
23
|
}
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
25
|
-
async
|
|
25
|
+
reserve = async (_req: RestRequest): Promise<void> => {
|
|
26
26
|
while (Date.now() - this.lastRequest < this.delay) {
|
|
27
27
|
await sleep(this.delay);
|
|
28
28
|
}
|
|
29
29
|
this.lastRequest = Date.now();
|
|
30
|
-
}
|
|
30
|
+
};
|
|
31
31
|
}
|
|
@@ -8,7 +8,7 @@ export interface RestClientRetryStrategy {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const noopRestRetryStrategy: RestClientRetryStrategy = {
|
|
11
|
-
onError(req: RestRequest, err: AxiosError): Promise<RestResponse> {
|
|
11
|
+
onError: (req: RestRequest, err: AxiosError): Promise<RestResponse> => {
|
|
12
12
|
const axiosError = err as AxiosError;
|
|
13
13
|
const res: RestResponse = {
|
|
14
14
|
status: axiosError.response?.status ?? 500,
|
|
@@ -26,7 +26,7 @@ export class AmpSettingsService {
|
|
|
26
26
|
this.targetApi = targetApi;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
async
|
|
29
|
+
getSettingsMap = async (tid?: string): Promise<AmpSettingsMap> => {
|
|
30
30
|
const res = await this.rest.call({
|
|
31
31
|
url: `/${this.targetApi}/v1/settings`,
|
|
32
32
|
method: 'GET',
|
|
@@ -36,9 +36,9 @@ export class AmpSettingsService {
|
|
|
36
36
|
const settings = page.data;
|
|
37
37
|
const rawSettingsMap: TenantSettingsMap = AmpSettingsService.formatSettingMap(settings, true);
|
|
38
38
|
return new AmpSettingsMap(rawSettingsMap, settings);
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
40
|
|
|
41
|
-
async
|
|
41
|
+
create = async <T>(key: TypedAmpSettingsKey<T>, value: T, tid: string, cid?: string): Promise<AmpSettingDto> => {
|
|
42
42
|
const page = await this.rest.call({
|
|
43
43
|
url: `/${this.targetApi}/v1/settings`,
|
|
44
44
|
method: 'POST',
|
|
@@ -51,9 +51,9 @@ export class AmpSettingsService {
|
|
|
51
51
|
});
|
|
52
52
|
const settings = page.data as AmpSettingDto[];
|
|
53
53
|
return settings[0];
|
|
54
|
-
}
|
|
54
|
+
};
|
|
55
55
|
|
|
56
|
-
async
|
|
56
|
+
update = async (id: string, entity: AmpSettingUpsertDto): Promise<AmpSettingDto> => {
|
|
57
57
|
const page = await this.rest.call({
|
|
58
58
|
url: `/${this.targetApi}/v1/settings/${id}`,
|
|
59
59
|
method: 'PUT',
|
|
@@ -61,18 +61,18 @@ export class AmpSettingsService {
|
|
|
61
61
|
});
|
|
62
62
|
const settings = page.data as AmpSettingDto[];
|
|
63
63
|
return settings[0];
|
|
64
|
-
}
|
|
64
|
+
};
|
|
65
65
|
|
|
66
|
-
async
|
|
66
|
+
delete = async (id: string): Promise<AmpSettingDto> => {
|
|
67
67
|
const page = await this.rest.call({
|
|
68
68
|
url: `/${this.targetApi}/v1/settings/${id}`,
|
|
69
69
|
method: 'DELETE',
|
|
70
70
|
});
|
|
71
71
|
const settings = page.data as AmpSettingDto[];
|
|
72
72
|
return settings[0];
|
|
73
|
-
}
|
|
73
|
+
};
|
|
74
74
|
|
|
75
|
-
static formatSettingMap(settings: AmpSettingDto[], valuesOnly = true): TenantSettingsMap {
|
|
75
|
+
static formatSettingMap = (settings: AmpSettingDto[], valuesOnly = true): TenantSettingsMap => {
|
|
76
76
|
const rawSettingsMap: TenantSettingsMap = {
|
|
77
77
|
tenantSettings: {},
|
|
78
78
|
connectorSettings: {},
|
|
@@ -88,7 +88,7 @@ export class AmpSettingsService {
|
|
|
88
88
|
}
|
|
89
89
|
});
|
|
90
90
|
return rawSettingsMap;
|
|
91
|
-
}
|
|
91
|
+
};
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export class AmpSettingsMap {
|
|
@@ -100,15 +100,15 @@ export class AmpSettingsMap {
|
|
|
100
100
|
this.rawSettingsList = rawSettingsList;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
getGlobalSetting<T>(key: TypedAmpSettingsKey<T>): T {
|
|
103
|
+
getGlobalSetting = <T>(key: TypedAmpSettingsKey<T>): T => {
|
|
104
104
|
const tenantVal = this.settings.tenantSettings[key.id];
|
|
105
105
|
if (tenantVal) {
|
|
106
106
|
return tenantVal as T;
|
|
107
107
|
}
|
|
108
108
|
return key.defaultValue;
|
|
109
|
-
}
|
|
109
|
+
};
|
|
110
110
|
|
|
111
|
-
getConnectorSetting<T>(cid: string, key: TypedAmpSettingsKey<T>): T {
|
|
111
|
+
getConnectorSetting = <T>(cid: string, key: TypedAmpSettingsKey<T>): T => {
|
|
112
112
|
const tenantVal = this.settings.tenantSettings[key.id];
|
|
113
113
|
const connectorMap = this.settings.connectorSettings[cid];
|
|
114
114
|
if (connectorMap) {
|
|
@@ -121,23 +121,23 @@ export class AmpSettingsMap {
|
|
|
121
121
|
return tenantVal as T;
|
|
122
122
|
}
|
|
123
123
|
return key.defaultValue;
|
|
124
|
-
}
|
|
124
|
+
};
|
|
125
125
|
|
|
126
|
-
getConnectorSettings(cid: string): RawAmpSettingsMap | undefined {
|
|
126
|
+
getConnectorSettings = (cid: string): RawAmpSettingsMap | undefined => {
|
|
127
127
|
if (!this.settings.connectorSettings[cid]) {
|
|
128
128
|
return undefined;
|
|
129
129
|
}
|
|
130
130
|
return _.clone(this.settings.connectorSettings[cid]);
|
|
131
|
-
}
|
|
131
|
+
};
|
|
132
132
|
|
|
133
|
-
getRawMap(): TenantSettingsMap {
|
|
133
|
+
getRawMap = (): TenantSettingsMap => {
|
|
134
134
|
return AmpSettingsService.formatSettingMap(this.rawSettingsList, false);
|
|
135
|
-
}
|
|
135
|
+
};
|
|
136
136
|
|
|
137
|
-
static asKey<T>(key: AmpSettingKey, defaultValue: T): TypedAmpSettingsKey<T> {
|
|
137
|
+
static asKey = <T>(key: AmpSettingKey, defaultValue: T): TypedAmpSettingsKey<T> => {
|
|
138
138
|
return {
|
|
139
139
|
id: key,
|
|
140
140
|
defaultValue,
|
|
141
141
|
};
|
|
142
|
-
}
|
|
142
|
+
};
|
|
143
143
|
}
|