@ampsec/platform-client 10.2.0 → 10.3.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/services/AmpApi.d.ts +2 -0
- package/build/src/services/AmpApi.js +14 -11
- package/build/src/services/AmpApi.js.map +1 -1
- package/build/src/services/AmpSdk.js +12 -11
- package/build/src/services/AmpSdk.js.map +1 -1
- package/build/src/services/constants.d.ts +31 -0
- package/build/src/services/constants.js +32 -0
- package/build/src/services/constants.js.map +1 -0
- package/build/src/services/data.service.d.ts +1 -6
- package/build/src/services/data.service.js +1 -3
- package/build/src/services/data.service.js.map +1 -1
- package/build/src/services/entity.service.d.ts +2 -1
- package/build/src/services/entity.service.js +4 -3
- package/build/src/services/entity.service.js.map +1 -1
- 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 +20 -0
- package/build/src/services/reports.service.js +51 -0
- package/build/src/services/reports.service.js.map +1 -0
- package/example/main.js +22 -2
- package/example/package.json +1 -1
- package/package.json +1 -1
- package/src/services/AmpApi.ts +15 -11
- package/src/services/AmpSdk.ts +13 -12
- package/src/services/constants.ts +36 -0
- package/src/services/data.service.ts +1 -8
- package/src/services/entity.service.ts +2 -1
- package/src/services/index.ts +1 -0
- package/src/services/reports.service.ts +56 -0
|
@@ -2,6 +2,7 @@ import { AgentDto, AgentUpsertDto, AssetDto, ConnectorDto, ConnectorUpsertDto, F
|
|
|
2
2
|
import { AmpEntityService } from './entity.service';
|
|
3
3
|
import { AmpDataService } from './data.service';
|
|
4
4
|
import { AmpRestClientOptions, RestClient } from './rest';
|
|
5
|
+
import { AmpReportService } from './reports.service';
|
|
5
6
|
export type AmpApiOptions = AmpRestClientOptions;
|
|
6
7
|
/**
|
|
7
8
|
* AMP API
|
|
@@ -22,6 +23,7 @@ export declare class AmpApi {
|
|
|
22
23
|
readonly findings: AmpDataService<FindingDto>;
|
|
23
24
|
readonly providers: AmpDataService<ProviderDto>;
|
|
24
25
|
readonly reportResults: AmpDataService<ReportResultDto>;
|
|
26
|
+
readonly reports: AmpReportService;
|
|
25
27
|
readonly saasAssets: AmpDataService<SaasAssetDto>;
|
|
26
28
|
readonly saasComponents: AmpDataService<SaasComponentDto>;
|
|
27
29
|
readonly saasUsers: AmpDataService<SaasUserDto>;
|
|
@@ -4,6 +4,8 @@ exports.AmpApi = void 0;
|
|
|
4
4
|
const entity_service_1 = require("./entity.service");
|
|
5
5
|
const data_service_1 = require("./data.service");
|
|
6
6
|
const rest_1 = require("./rest");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const reports_service_1 = require("./reports.service");
|
|
7
9
|
/**
|
|
8
10
|
* AMP API
|
|
9
11
|
* This client is a wrapper around the AMP REST API meant to be used by
|
|
@@ -18,17 +20,18 @@ const rest_1 = require("./rest");
|
|
|
18
20
|
*/
|
|
19
21
|
class AmpApi {
|
|
20
22
|
constructor(rest) {
|
|
21
|
-
this.agents = new entity_service_1.AmpEntityServiceImpl(rest,
|
|
22
|
-
this.asset = new data_service_1.AmpDataServiceImpl(rest,
|
|
23
|
-
this.connectors = new entity_service_1.AmpEntityServiceImpl(rest,
|
|
24
|
-
this.findings = new data_service_1.AmpDataServiceImpl(rest,
|
|
25
|
-
this.providers = new data_service_1.AmpDataServiceImpl(rest,
|
|
26
|
-
this.reportResults = new data_service_1.AmpDataServiceImpl(rest,
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
23
|
+
this.agents = new entity_service_1.AmpEntityServiceImpl(rest, constants_1.KIND.AGENTS);
|
|
24
|
+
this.asset = new data_service_1.AmpDataServiceImpl(rest, constants_1.KIND.ASSETS);
|
|
25
|
+
this.connectors = new entity_service_1.AmpEntityServiceImpl(rest, constants_1.KIND.CONNECTORS);
|
|
26
|
+
this.findings = new data_service_1.AmpDataServiceImpl(rest, constants_1.KIND.FINDINGS);
|
|
27
|
+
this.providers = new data_service_1.AmpDataServiceImpl(rest, constants_1.KIND.PROVIDERS);
|
|
28
|
+
this.reportResults = new data_service_1.AmpDataServiceImpl(rest, constants_1.KIND.REPORT_RESULTS);
|
|
29
|
+
this.reports = new reports_service_1.AmpReportServiceImpl(rest);
|
|
30
|
+
this.saasAssets = new data_service_1.AmpDataServiceImpl(rest, constants_1.KIND.SAAS_ASSETS);
|
|
31
|
+
this.saasComponents = new data_service_1.AmpDataServiceImpl(rest, constants_1.KIND.SAAS_COMPONENTS);
|
|
32
|
+
this.saasUsers = new data_service_1.AmpDataServiceImpl(rest, constants_1.KIND.SAAS_USERS);
|
|
33
|
+
this.tenants = new entity_service_1.AmpEntityServiceImpl(rest, constants_1.KIND.TENANTS);
|
|
34
|
+
this.users = new data_service_1.AmpDataServiceImpl(rest, constants_1.KIND.USERS);
|
|
32
35
|
}
|
|
33
36
|
static instance(options) {
|
|
34
37
|
const rest = (0, rest_1.getAmpRestClient)(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AmpApi.js","sourceRoot":"","sources":["../../../src/services/AmpApi.ts"],"names":[],"mappings":";;;AAgBA,qDAAwE;AACxE,iDAAkE;AAClE,iCAA0E;
|
|
1
|
+
{"version":3,"file":"AmpApi.js","sourceRoot":"","sources":["../../../src/services/AmpApi.ts"],"names":[],"mappings":";;;AAgBA,qDAAwE;AACxE,iDAAkE;AAClE,iCAA0E;AAC1E,2CAAiC;AACjC,uDAAyE;AAIzE;;;;;;;;;;;GAWG;AACH,MAAa,MAAM;IAcjB,YAAY,IAAgB;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,qCAAoB,CAA2B,IAAI,EAAE,gBAAI,CAAC,MAAM,CAAC,CAAC;QACpF,IAAI,CAAC,KAAK,GAAG,IAAI,iCAAkB,CAAW,IAAI,EAAE,gBAAI,CAAC,MAAM,CAAC,CAAC;QACjE,IAAI,CAAC,UAAU,GAAG,IAAI,qCAAoB,CAAmC,IAAI,EAAE,gBAAI,CAAC,UAAU,CAAC,CAAC;QACpG,IAAI,CAAC,QAAQ,GAAG,IAAI,iCAAkB,CAAa,IAAI,EAAE,gBAAI,CAAC,QAAQ,CAAC,CAAC;QACxE,IAAI,CAAC,SAAS,GAAG,IAAI,iCAAkB,CAAc,IAAI,EAAE,gBAAI,CAAC,SAAS,CAAC,CAAC;QAC3E,IAAI,CAAC,aAAa,GAAG,IAAI,iCAAkB,CAAkB,IAAI,EAAE,gBAAI,CAAC,cAAc,CAAC,CAAC;QACxF,IAAI,CAAC,OAAO,GAAG,IAAI,sCAAoB,CAAC,IAAI,CAAC,CAAC;QAC9C,IAAI,CAAC,UAAU,GAAG,IAAI,iCAAkB,CAAe,IAAI,EAAE,gBAAI,CAAC,WAAW,CAAC,CAAC;QAC/E,IAAI,CAAC,cAAc,GAAG,IAAI,iCAAkB,CAAmB,IAAI,EAAE,gBAAI,CAAC,eAAe,CAAC,CAAC;QAC3F,IAAI,CAAC,SAAS,GAAG,IAAI,iCAAkB,CAAc,IAAI,EAAE,gBAAI,CAAC,UAAU,CAAC,CAAC;QAC5E,IAAI,CAAC,OAAO,GAAG,IAAI,qCAAoB,CAA6B,IAAI,EAAE,gBAAI,CAAC,OAAO,CAAC,CAAC;QACxF,IAAI,CAAC,KAAK,GAAG,IAAI,iCAAkB,CAAU,IAAI,EAAE,gBAAI,CAAC,KAAK,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,OAAsB;QACpC,MAAM,IAAI,GAAG,IAAA,uBAAgB,EAAC,OAAO,CAAC,CAAC;QACvC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AAjCD,wBAiCC"}
|
|
@@ -4,6 +4,7 @@ exports.AmpSdkServices = void 0;
|
|
|
4
4
|
const entity_service_1 = require("./entity.service");
|
|
5
5
|
const data_service_1 = require("./data.service");
|
|
6
6
|
const rest_1 = require("./rest");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
7
8
|
/**
|
|
8
9
|
* AMP API
|
|
9
10
|
* This client is a wrapper around the AMP REST API meant to be used by
|
|
@@ -17,17 +18,17 @@ const rest_1 = require("./rest");
|
|
|
17
18
|
*/
|
|
18
19
|
class AmpSdkServices {
|
|
19
20
|
constructor(rest) {
|
|
20
|
-
this.agents = new entity_service_1.AmpEntityServiceImpl(rest,
|
|
21
|
-
this.asset = new entity_service_1.AmpGlobalEntityServiceImpl(rest,
|
|
22
|
-
this.connectors = new entity_service_1.AmpEntityServiceImpl(rest,
|
|
23
|
-
this.findings = new entity_service_1.AmpSaaSEntityServiceImpl(rest,
|
|
24
|
-
this.providers = new data_service_1.AmpDataServiceImpl(rest,
|
|
25
|
-
this.reportResults = new entity_service_1.AmpSaaSEntityServiceImpl(rest,
|
|
26
|
-
this.saasAssets = new entity_service_1.AmpSaaSEntityServiceImpl(rest,
|
|
27
|
-
this.saasComponents = new entity_service_1.AmpSaaSEntityServiceImpl(rest,
|
|
28
|
-
this.saasUsers = new entity_service_1.AmpSaaSEntityServiceImpl(rest,
|
|
29
|
-
this.tenants = new entity_service_1.AmpEntityServiceImpl(rest,
|
|
30
|
-
this.users = new entity_service_1.AmpGlobalEntityServiceImpl(rest,
|
|
21
|
+
this.agents = new entity_service_1.AmpEntityServiceImpl(rest, constants_1.KIND.AGENTS, constants_1.TARGET_API_PLATFORM);
|
|
22
|
+
this.asset = new entity_service_1.AmpGlobalEntityServiceImpl(rest, constants_1.KIND.ASSETS, constants_1.TARGET_API_PLATFORM);
|
|
23
|
+
this.connectors = new entity_service_1.AmpEntityServiceImpl(rest, constants_1.KIND.CONNECTORS, constants_1.TARGET_API_PLATFORM);
|
|
24
|
+
this.findings = new entity_service_1.AmpSaaSEntityServiceImpl(rest, constants_1.KIND.FINDINGS, constants_1.TARGET_API_PLATFORM);
|
|
25
|
+
this.providers = new data_service_1.AmpDataServiceImpl(rest, constants_1.KIND.PROVIDERS, constants_1.TARGET_API_AGENT);
|
|
26
|
+
this.reportResults = new entity_service_1.AmpSaaSEntityServiceImpl(rest, constants_1.KIND.REPORT_RESULTS, constants_1.TARGET_API_PLATFORM);
|
|
27
|
+
this.saasAssets = new entity_service_1.AmpSaaSEntityServiceImpl(rest, constants_1.KIND.SAAS_ASSETS, constants_1.TARGET_API_PLATFORM);
|
|
28
|
+
this.saasComponents = new entity_service_1.AmpSaaSEntityServiceImpl(rest, constants_1.KIND.SAAS_COMPONENTS, constants_1.TARGET_API_PLATFORM);
|
|
29
|
+
this.saasUsers = new entity_service_1.AmpSaaSEntityServiceImpl(rest, constants_1.KIND.SAAS_USERS, constants_1.TARGET_API_PLATFORM);
|
|
30
|
+
this.tenants = new entity_service_1.AmpEntityServiceImpl(rest, constants_1.KIND.TENANTS, constants_1.TARGET_API_PLATFORM);
|
|
31
|
+
this.users = new entity_service_1.AmpGlobalEntityServiceImpl(rest, constants_1.KIND.USERS, constants_1.TARGET_API_PLATFORM);
|
|
31
32
|
}
|
|
32
33
|
static instance(options) {
|
|
33
34
|
const rest = (0, rest_1.getAmpRestClient)(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AmpSdk.js","sourceRoot":"","sources":["../../../src/services/AmpSdk.ts"],"names":[],"mappings":";;;AAuBA,qDAA4K;AAC5K,
|
|
1
|
+
{"version":3,"file":"AmpSdk.js","sourceRoot":"","sources":["../../../src/services/AmpSdk.ts"],"names":[],"mappings":";;;AAuBA,qDAA4K;AAC5K,iDAAkE;AAClE,iCAA0E;AAC1E,2CAAwE;AAIxE;;;;;;;;;;GAUG;AACH,MAAa,cAAc;IAazB,YAAY,IAAgB;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,qCAAoB,CAA2C,IAAI,EAAE,gBAAI,CAAC,MAAM,EAAE,+BAAmB,CAAC,CAAC;QACzH,IAAI,CAAC,KAAK,GAAG,IAAI,2CAA0B,CAA2C,IAAI,EAAE,gBAAI,CAAC,MAAM,EAAE,+BAAmB,CAAC,CAAC;Q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ErrorHandler<T> {
|
|
2
|
+
(_error: unknown): T;
|
|
3
|
+
}
|
|
4
|
+
export declare const DEFAULT_TREND_WINDOW_MONTHS = 6;
|
|
5
|
+
export type TargetApi = 'api' | 'platform';
|
|
6
|
+
export declare const TARGET_API_PLATFORM: TargetApi;
|
|
7
|
+
export declare const TARGET_API_AGENT: TargetApi;
|
|
8
|
+
export declare const KIND: {
|
|
9
|
+
AGENTS: string;
|
|
10
|
+
ASSETS: string;
|
|
11
|
+
CONNECTORS: string;
|
|
12
|
+
FINDINGS: string;
|
|
13
|
+
PROVIDERS: string;
|
|
14
|
+
REPORT_RESULTS: string;
|
|
15
|
+
SAAS_ASSETS: string;
|
|
16
|
+
SAAS_COMPONENTS: string;
|
|
17
|
+
SAAS_USERS: string;
|
|
18
|
+
TENANTS: string;
|
|
19
|
+
USERS: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const REPORTS: {
|
|
22
|
+
HEALTH_SCORE: string;
|
|
23
|
+
EMPLOYEE_TOOLING_COVERAGE: string;
|
|
24
|
+
ENDPOINT_TOOLING_COVERAGE: string;
|
|
25
|
+
VULNERABILITY_SLA: string;
|
|
26
|
+
TOP_RISK_CONTRIBUTORS: string;
|
|
27
|
+
MFA_COVERAGE: string;
|
|
28
|
+
TRAINING_DEFICIENCIES: string;
|
|
29
|
+
SECURITY_HYGIENE: string;
|
|
30
|
+
HEALTH_SCORE_TREND: string;
|
|
31
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REPORTS = exports.KIND = exports.TARGET_API_AGENT = exports.TARGET_API_PLATFORM = exports.DEFAULT_TREND_WINDOW_MONTHS = void 0;
|
|
4
|
+
exports.DEFAULT_TREND_WINDOW_MONTHS = 6;
|
|
5
|
+
exports.TARGET_API_PLATFORM = 'platform';
|
|
6
|
+
exports.TARGET_API_AGENT = 'api';
|
|
7
|
+
exports.KIND = {
|
|
8
|
+
AGENTS: 'agents',
|
|
9
|
+
ASSETS: 'assets',
|
|
10
|
+
CONNECTORS: 'connectors',
|
|
11
|
+
FINDINGS: 'findings',
|
|
12
|
+
PROVIDERS: 'providers',
|
|
13
|
+
REPORT_RESULTS: 'report_results',
|
|
14
|
+
SAAS_ASSETS: 'saas_assets',
|
|
15
|
+
SAAS_COMPONENTS: 'saas_components',
|
|
16
|
+
SAAS_USERS: 'saas_users',
|
|
17
|
+
TENANTS: 'tenants',
|
|
18
|
+
USERS: 'users',
|
|
19
|
+
};
|
|
20
|
+
exports.REPORTS = {
|
|
21
|
+
HEALTH_SCORE: 'health-score',
|
|
22
|
+
EMPLOYEE_TOOLING_COVERAGE: 'workforce-tooling-employee-coverage',
|
|
23
|
+
ENDPOINT_TOOLING_COVERAGE: 'workforce-tooling-endpoint-coverage',
|
|
24
|
+
VULNERABILITY_SLA: 'vulnerability-sla',
|
|
25
|
+
TOP_RISK_CONTRIBUTORS: 'top-risk-contributors',
|
|
26
|
+
MFA_COVERAGE: 'mfa-application-coverage',
|
|
27
|
+
TRAINING_DEFICIENCIES: 'training-deficiencies',
|
|
28
|
+
SECURITY_HYGIENE: 'security-hygiene',
|
|
29
|
+
// trending reports
|
|
30
|
+
HEALTH_SCORE_TREND: 'health-trend',
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/services/constants.ts"],"names":[],"mappings":";;;AAIa,QAAA,2BAA2B,GAAG,CAAC,CAAC;AAGhC,QAAA,mBAAmB,GAAc,UAAU,CAAC;AAC5C,QAAA,gBAAgB,GAAc,KAAK,CAAC;AAEpC,QAAA,IAAI,GAAG;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,cAAc,EAAE,gBAAgB;IAChC,WAAW,EAAE,aAAa;IAC1B,eAAe,EAAE,iBAAiB;IAClC,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;CACf,CAAC;AAEW,QAAA,OAAO,GAAG;IACrB,YAAY,EAAE,cAAc;IAC5B,yBAAyB,EAAE,qCAAqC;IAChE,yBAAyB,EAAE,qCAAqC;IAChE,iBAAiB,EAAE,mBAAmB;IACtC,qBAAqB,EAAE,uBAAuB;IAC9C,YAAY,EAAE,0BAA0B;IACxC,qBAAqB,EAAE,uBAAuB;IAC9C,gBAAgB,EAAE,kBAAkB;IACpC,mBAAmB;IACnB,kBAAkB,EAAE,cAAc;CACnC,CAAC"}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { BaseDto, Page } from '../dto';
|
|
2
2
|
import { FilterCriteria } from '../FilterCriteria';
|
|
3
|
+
import { ErrorHandler, TargetApi } from './constants';
|
|
3
4
|
import { RestClient, RestRequest } from './rest';
|
|
4
5
|
export interface AmpDataService<ReadT extends BaseDto> {
|
|
5
6
|
list(_filter: FilterCriteria): Promise<Page<ReadT>>;
|
|
6
7
|
getById(_id: string): Promise<Page<ReadT>>;
|
|
7
8
|
}
|
|
8
|
-
export interface ErrorHandler<T> {
|
|
9
|
-
(_error: unknown): T;
|
|
10
|
-
}
|
|
11
|
-
export type TargetApi = 'api' | 'platform';
|
|
12
|
-
export declare const TARGET_API_PLATFORM: TargetApi;
|
|
13
|
-
export declare const TARGET_API_AGENT: TargetApi;
|
|
14
9
|
export declare class AmpDataServiceImpl<ReadT extends BaseDto> implements AmpDataService<ReadT> {
|
|
15
10
|
protected readonly rest: RestClient;
|
|
16
11
|
protected readonly kind: string;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AmpDataServiceImpl =
|
|
4
|
-
exports.TARGET_API_PLATFORM = 'platform';
|
|
5
|
-
exports.TARGET_API_AGENT = 'api';
|
|
3
|
+
exports.AmpDataServiceImpl = void 0;
|
|
6
4
|
class AmpDataServiceImpl {
|
|
7
5
|
constructor(rest, kind, targetApi = 'api') {
|
|
8
6
|
this.rest = rest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.service.js","sourceRoot":"","sources":["../../../src/services/data.service.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"data.service.js","sourceRoot":"","sources":["../../../src/services/data.service.ts"],"names":[],"mappings":";;;AAUA,MAAa,kBAAkB;IAK7B,YAAY,IAAgB,EAAE,IAAY,EAAE,YAAuB,KAAK;QACtE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAES,KAAK,CAAC,IAAI,CAAI,GAAgB,EAAE,YAA6B;QACrE,IAAI;YACF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACtC,OAAO,GAAG,CAAC,IAAS,CAAC;SACtB;QAAC,OAAO,KAAc,EAAE;YACvB,IAAI,KAAK,YAAY,KAAK,EAAE;gBAC1B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;aAC9B;YACD,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;SAC5B;IACH,CAAC;IAES,KAAK,CAAC,OAAO,CAAC,GAAgB;QACtC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAc,EAAE,EAAE;YACvC,IAAI,KAAK,YAAY,KAAK,EAAE;gBAC1B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;aAC9B;YACD,OAAO;gBACL,IAAI,EAAE,EAAE;gBACR,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;gBAC7B,KAAK,EAAG,KAA2B,CAAC,OAAO;gBAC3C,KAAK,EAAE,EAAE;aACV,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,MAAsB;QACzB,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,GAAG,EAAE,IAAI,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC,IAAI,EAAE;YACzC,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,MAAM;SACf,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,GAAG,EAAE,IAAI,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE;YAC/C,MAAM,EAAE,KAAK;SACd,CAAC,CAAC;IACL,CAAC;CACF;AAnDD,gDAmDC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseDto, BaseUpsertDto, ExtKeyMap, Page } from '../dto';
|
|
2
|
-
import {
|
|
2
|
+
import { TargetApi } from './constants';
|
|
3
|
+
import { AmpDataService, AmpDataServiceImpl } from './data.service';
|
|
3
4
|
import { RestClient } from './rest';
|
|
4
5
|
export interface AmpEntityService<WriteT extends BaseUpsertDto, ReadT extends BaseDto> extends AmpDataService<ReadT> {
|
|
5
6
|
create(_model: WriteT): Promise<Page<ReadT>>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AmpSaaSEntityServiceImpl = exports.AmpGlobalEntityServiceImpl = exports.AmpEntityServiceImpl = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
4
5
|
const data_service_1 = require("./data.service");
|
|
5
6
|
class AmpEntityServiceImpl extends data_service_1.AmpDataServiceImpl {
|
|
6
|
-
constructor(rest, kind, targetApi =
|
|
7
|
+
constructor(rest, kind, targetApi = constants_1.TARGET_API_AGENT) {
|
|
7
8
|
super(rest, kind, targetApi);
|
|
8
9
|
}
|
|
9
10
|
create(model) {
|
|
@@ -48,7 +49,7 @@ const extIdMapErrorHandler = (error) => {
|
|
|
48
49
|
return {};
|
|
49
50
|
};
|
|
50
51
|
class AmpGlobalEntityServiceImpl extends AmpEntityServiceImpl {
|
|
51
|
-
constructor(rest, kind, targetApi =
|
|
52
|
+
constructor(rest, kind, targetApi = constants_1.TARGET_API_AGENT) {
|
|
52
53
|
super(rest, kind, targetApi);
|
|
53
54
|
}
|
|
54
55
|
getLookupIds(tid) {
|
|
@@ -62,7 +63,7 @@ class AmpGlobalEntityServiceImpl extends AmpEntityServiceImpl {
|
|
|
62
63
|
}
|
|
63
64
|
exports.AmpGlobalEntityServiceImpl = AmpGlobalEntityServiceImpl;
|
|
64
65
|
class AmpSaaSEntityServiceImpl extends AmpEntityServiceImpl {
|
|
65
|
-
constructor(rest, kind, targetApi =
|
|
66
|
+
constructor(rest, kind, targetApi = constants_1.TARGET_API_AGENT) {
|
|
66
67
|
super(rest, kind, targetApi);
|
|
67
68
|
}
|
|
68
69
|
getLookupIds(cid) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.service.js","sourceRoot":"","sources":["../../../src/services/entity.service.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"entity.service.js","sourceRoot":"","sources":["../../../src/services/entity.service.ts"],"names":[],"mappings":";;;AACA,2CAAsE;AACtE,iDAAkE;AAqBlE,MAAa,oBAA0E,SAAQ,iCAAyB;IACtH,YAAY,IAAgB,EAAE,IAAY,EAAE,YAAuB,4BAAgB;QACjF,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC;YAClB,GAAG,EAAE,IAAI,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC,IAAI,EAAE;YACzC,MAAM,EAAE,MAAM;Y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,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF,MAAa,0BACX,SAAQ,oBAAmC;IAG3C,YAAY,IAAgB,EAAE,IAAY,EAAE,YAAuB,4BAAgB;QACjF,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAC/B,CAAC;IACD,YAAY,CAAC,GAAW;QACtB,MAAM,GAAG,GAAgB;YACvB,GAAG,EAAE,IAAI,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC,IAAI,cAAc;YACrD,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAC,GAAG,EAAC;SACd,CAAC;QACF,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;IAC9C,CAAC;CACF;AAfD,gEAeC;AAED,MAAa,wBACX,SAAQ,oBAAmC;IAG3C,YAAY,IAAgB,EAAE,IAAY,EAAE,YAAuB,4BAAgB;QACjF,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAC/B,CAAC;IACD,YAAY,CAAC,GAAW;QACtB,MAAM,GAAG,GAAgB;YACvB,GAAG,EAAE,IAAI,IAAI,CAAC,SAAS,OAAO,IAAI,CAAC,IAAI,cAAc;YACrD,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAC,GAAG,EAAC;SACd,CAAC;QACF,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;IAC9C,CAAC;CACF;AAfD,4DAeC"}
|
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./AmpApi"), exports);
|
|
18
18
|
__exportStar(require("./AmpSdk"), exports);
|
|
19
|
+
__exportStar(require("./constants"), exports);
|
|
19
20
|
__exportStar(require("./data.service"), exports);
|
|
20
21
|
__exportStar(require("./entity.service"), exports);
|
|
21
22
|
__exportStar(require("./rest"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,iDAA+B;AAC/B,mDAAiC;AACjC,yCAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,8CAA4B;AAC5B,iDAA+B;AAC/B,mDAAiC;AACjC,yCAAuB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FilterCriteria } from '../FilterCriteria';
|
|
2
|
+
import { Page, ReportResultDto } from '../dto';
|
|
3
|
+
import { RestClient } from './rest';
|
|
4
|
+
export interface AmpReportService {
|
|
5
|
+
getMetrics: (_reportId: string, _filter?: FilterCriteria) => Promise<Page<ReportResultDto>>;
|
|
6
|
+
getMetricsTrend: (_reportId: string, _filter?: FilterCriteria) => Promise<Page<ReportResultDto>>;
|
|
7
|
+
}
|
|
8
|
+
export declare class AmpReportServiceImpl implements AmpReportService {
|
|
9
|
+
protected readonly rest: RestClient;
|
|
10
|
+
constructor(rest: RestClient);
|
|
11
|
+
getMetrics(reportId: string, filter?: FilterCriteria | undefined): Promise<Page<ReportResultDto>>;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @deprecated
|
|
15
|
+
* @param reportId
|
|
16
|
+
* @param filter
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
getMetricsTrend(reportId: string, filter?: FilterCriteria): Promise<Page<ReportResultDto>>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmpReportServiceImpl = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
class AmpReportServiceImpl {
|
|
6
|
+
constructor(rest) {
|
|
7
|
+
this.rest = rest;
|
|
8
|
+
}
|
|
9
|
+
async getMetrics(reportId, filter) {
|
|
10
|
+
var _a;
|
|
11
|
+
filter = filter !== null && filter !== void 0 ? filter : {};
|
|
12
|
+
filter.limit = (_a = filter.limit) !== null && _a !== void 0 ? _a : 1; // pull latest result by default
|
|
13
|
+
try {
|
|
14
|
+
const req = {
|
|
15
|
+
url: `/api/v1/reports/${reportId}/metrics`,
|
|
16
|
+
method: 'GET',
|
|
17
|
+
params: filter !== null && filter !== void 0 ? filter : {},
|
|
18
|
+
};
|
|
19
|
+
const res = await this.rest.call(req);
|
|
20
|
+
return res.data;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error instanceof Error) {
|
|
24
|
+
console.error(error.message);
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
data: [],
|
|
28
|
+
kind: constants_1.KIND.REPORT_RESULTS.toUpperCase(),
|
|
29
|
+
error: error.message,
|
|
30
|
+
hints: {},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @deprecated
|
|
37
|
+
* @param reportId
|
|
38
|
+
* @param filter
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
async getMetricsTrend(reportId, filter) {
|
|
42
|
+
var _a;
|
|
43
|
+
// I am breaking this out into a separate method so that we can extend typing later
|
|
44
|
+
// and add buckets/aggregations to the args
|
|
45
|
+
filter = filter !== null && filter !== void 0 ? filter : {};
|
|
46
|
+
filter.limit = (_a = filter.limit) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_TREND_WINDOW_MONTHS;
|
|
47
|
+
return this.getMetrics(reportId, filter);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.AmpReportServiceImpl = AmpReportServiceImpl;
|
|
51
|
+
//# sourceMappingURL=reports.service.js.map
|
|
@@ -0,0 +1 @@
|
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mCAAI,uCAA2B,CAAC;QAC3D,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;CACF;AA7CD,oDA6CC"}
|
package/example/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {AmpApi} = require('@ampsec/platform-client');
|
|
1
|
+
const {AmpApi, REPORTS} = require('@ampsec/platform-client');
|
|
2
2
|
const axios = require('axios');
|
|
3
3
|
|
|
4
4
|
const BASE_URL = process.env.AMPSEC_API_BASE_URL || '...';
|
|
@@ -26,4 +26,24 @@ async function datagridExample() {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
async function reportsExample() {
|
|
30
|
+
const orgHealthScorePage = await api.reports.getMetrics(REPORTS.HEALTH_SCORE);
|
|
31
|
+
console.log('Health Score:', orgHealthScorePage.data[0].results);
|
|
32
|
+
const salesHealthScorePage = await api.reports.getMetrics(REPORTS.HEALTH_SCORE, {department: 'Sales'});
|
|
33
|
+
console.log('Sales Health Score:', salesHealthScorePage.data[0].results);
|
|
34
|
+
const toolingCoveragePage = await api.reports.getMetrics(REPORTS.EMPLOYEE_TOOLING_COVERAGE);
|
|
35
|
+
console.log('Tooling Coverage:', toolingCoveragePage.data[0].results);
|
|
36
|
+
const healthTrendPage = await api.reports.getMetricsTrend(REPORTS.HEALTH_SCORE_TREND);
|
|
37
|
+
console.log('Health Score Trend:');
|
|
38
|
+
for (const metric of healthTrendPage.data) {
|
|
39
|
+
console.log(' - ', metric);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function run() {
|
|
44
|
+
await datagridExample();
|
|
45
|
+
await reportsExample();
|
|
46
|
+
console.log('Done!');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
run();
|
package/example/package.json
CHANGED
package/package.json
CHANGED
package/src/services/AmpApi.ts
CHANGED
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
import {AmpEntityService, AmpEntityServiceImpl} from './entity.service';
|
|
18
18
|
import {AmpDataService, AmpDataServiceImpl} from './data.service';
|
|
19
19
|
import {AmpRestClientOptions, RestClient, getAmpRestClient} from './rest';
|
|
20
|
+
import {KIND} from './constants';
|
|
21
|
+
import {AmpReportService, AmpReportServiceImpl} from './reports.service';
|
|
20
22
|
|
|
21
23
|
export type AmpApiOptions = AmpRestClientOptions;
|
|
22
24
|
|
|
@@ -39,6 +41,7 @@ export class AmpApi {
|
|
|
39
41
|
readonly findings: AmpDataService<FindingDto>;
|
|
40
42
|
readonly providers: AmpDataService<ProviderDto>;
|
|
41
43
|
readonly reportResults: AmpDataService<ReportResultDto>;
|
|
44
|
+
readonly reports: AmpReportService;
|
|
42
45
|
readonly saasAssets: AmpDataService<SaasAssetDto>;
|
|
43
46
|
readonly saasComponents: AmpDataService<SaasComponentDto>;
|
|
44
47
|
readonly saasUsers: AmpDataService<SaasUserDto>;
|
|
@@ -46,17 +49,18 @@ export class AmpApi {
|
|
|
46
49
|
readonly users: AmpDataService<UserDto>;
|
|
47
50
|
|
|
48
51
|
constructor(rest: RestClient) {
|
|
49
|
-
this.agents = new AmpEntityServiceImpl<AgentUpsertDto, AgentDto>(rest,
|
|
50
|
-
this.asset = new AmpDataServiceImpl<AssetDto>(rest,
|
|
51
|
-
this.connectors = new AmpEntityServiceImpl<ConnectorUpsertDto, ConnectorDto>(rest,
|
|
52
|
-
this.findings = new AmpDataServiceImpl<FindingDto>(rest,
|
|
53
|
-
this.providers = new AmpDataServiceImpl<ProviderDto>(rest,
|
|
54
|
-
this.reportResults = new AmpDataServiceImpl<ReportResultDto>(rest,
|
|
55
|
-
this.
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
59
|
-
this.
|
|
52
|
+
this.agents = new AmpEntityServiceImpl<AgentUpsertDto, AgentDto>(rest, KIND.AGENTS);
|
|
53
|
+
this.asset = new AmpDataServiceImpl<AssetDto>(rest, KIND.ASSETS);
|
|
54
|
+
this.connectors = new AmpEntityServiceImpl<ConnectorUpsertDto, ConnectorDto>(rest, KIND.CONNECTORS);
|
|
55
|
+
this.findings = new AmpDataServiceImpl<FindingDto>(rest, KIND.FINDINGS);
|
|
56
|
+
this.providers = new AmpDataServiceImpl<ProviderDto>(rest, KIND.PROVIDERS);
|
|
57
|
+
this.reportResults = new AmpDataServiceImpl<ReportResultDto>(rest, KIND.REPORT_RESULTS);
|
|
58
|
+
this.reports = new AmpReportServiceImpl(rest);
|
|
59
|
+
this.saasAssets = new AmpDataServiceImpl<SaasAssetDto>(rest, KIND.SAAS_ASSETS);
|
|
60
|
+
this.saasComponents = new AmpDataServiceImpl<SaasComponentDto>(rest, KIND.SAAS_COMPONENTS);
|
|
61
|
+
this.saasUsers = new AmpDataServiceImpl<SaasUserDto>(rest, KIND.SAAS_USERS);
|
|
62
|
+
this.tenants = new AmpEntityServiceImpl<TenantUpsertDto, TenantDto>(rest, KIND.TENANTS);
|
|
63
|
+
this.users = new AmpDataServiceImpl<UserDto>(rest, KIND.USERS);
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
static instance(options: AmpApiOptions): AmpApi {
|
package/src/services/AmpSdk.ts
CHANGED
|
@@ -22,8 +22,9 @@ import {
|
|
|
22
22
|
TenantUpsertDto,
|
|
23
23
|
} from '../dto';
|
|
24
24
|
import {AmpEntityService, AmpEntityServiceImpl, AmpGlobalEntityService, AmpGlobalEntityServiceImpl, AmpSaaSEntityService, AmpSaaSEntityServiceImpl} from './entity.service';
|
|
25
|
-
import {AmpDataService, AmpDataServiceImpl
|
|
25
|
+
import {AmpDataService, AmpDataServiceImpl} from './data.service';
|
|
26
26
|
import {AmpRestClientOptions, RestClient, getAmpRestClient} from './rest';
|
|
27
|
+
import {KIND, TARGET_API_AGENT, TARGET_API_PLATFORM} from './constants';
|
|
27
28
|
|
|
28
29
|
export type AmpSdkOptions = AmpRestClientOptions;
|
|
29
30
|
|
|
@@ -52,17 +53,17 @@ export class AmpSdkServices {
|
|
|
52
53
|
readonly users: AmpGlobalEntityService<PlatformUserUpsertDto, PlatformUserDto>;
|
|
53
54
|
|
|
54
55
|
constructor(rest: RestClient) {
|
|
55
|
-
this.agents = new AmpEntityServiceImpl<PlatformAgentUpsertDto, PlatformAgentDto>(rest,
|
|
56
|
-
this.asset = new AmpGlobalEntityServiceImpl<PlatformAssetUpsertDto, PlatformAssetDto>(rest,
|
|
57
|
-
this.connectors = new AmpEntityServiceImpl<PlatformConnectorUpsertDto, PlatformConnectorDto>(rest,
|
|
58
|
-
this.findings = new AmpSaaSEntityServiceImpl<PlatformFindingUpsertDto, PlatformFindingDto>(rest,
|
|
59
|
-
this.providers = new AmpDataServiceImpl<ProviderDto>(rest,
|
|
60
|
-
this.reportResults = new AmpSaaSEntityServiceImpl<PlatformReportResultUpsertDto, PlatformReportResultDto>(rest,
|
|
61
|
-
this.saasAssets = new AmpSaaSEntityServiceImpl<PlatformSaasAssetUpsertDto, PlatformSaasAssetDto>(rest,
|
|
62
|
-
this.saasComponents = new AmpSaaSEntityServiceImpl<PlatformSaasComponentUpsertDto, PlatformSaasComponentDto>(rest,
|
|
63
|
-
this.saasUsers = new AmpSaaSEntityServiceImpl<PlatformSaasUserUpsertDto, PlatformSaasUserDto>(rest,
|
|
64
|
-
this.tenants = new AmpEntityServiceImpl<TenantUpsertDto, TenantDto>(rest,
|
|
65
|
-
this.users = new AmpGlobalEntityServiceImpl<PlatformUserUpsertDto, PlatformUserDto>(rest,
|
|
56
|
+
this.agents = new AmpEntityServiceImpl<PlatformAgentUpsertDto, PlatformAgentDto>(rest, KIND.AGENTS, TARGET_API_PLATFORM);
|
|
57
|
+
this.asset = new AmpGlobalEntityServiceImpl<PlatformAssetUpsertDto, PlatformAssetDto>(rest, KIND.ASSETS, TARGET_API_PLATFORM);
|
|
58
|
+
this.connectors = new AmpEntityServiceImpl<PlatformConnectorUpsertDto, PlatformConnectorDto>(rest, KIND.CONNECTORS, TARGET_API_PLATFORM);
|
|
59
|
+
this.findings = new AmpSaaSEntityServiceImpl<PlatformFindingUpsertDto, PlatformFindingDto>(rest, KIND.FINDINGS, TARGET_API_PLATFORM);
|
|
60
|
+
this.providers = new AmpDataServiceImpl<ProviderDto>(rest, KIND.PROVIDERS, TARGET_API_AGENT);
|
|
61
|
+
this.reportResults = new AmpSaaSEntityServiceImpl<PlatformReportResultUpsertDto, PlatformReportResultDto>(rest, KIND.REPORT_RESULTS, TARGET_API_PLATFORM);
|
|
62
|
+
this.saasAssets = new AmpSaaSEntityServiceImpl<PlatformSaasAssetUpsertDto, PlatformSaasAssetDto>(rest, KIND.SAAS_ASSETS, TARGET_API_PLATFORM);
|
|
63
|
+
this.saasComponents = new AmpSaaSEntityServiceImpl<PlatformSaasComponentUpsertDto, PlatformSaasComponentDto>(rest, KIND.SAAS_COMPONENTS, TARGET_API_PLATFORM);
|
|
64
|
+
this.saasUsers = new AmpSaaSEntityServiceImpl<PlatformSaasUserUpsertDto, PlatformSaasUserDto>(rest, KIND.SAAS_USERS, TARGET_API_PLATFORM);
|
|
65
|
+
this.tenants = new AmpEntityServiceImpl<TenantUpsertDto, TenantDto>(rest, KIND.TENANTS, TARGET_API_PLATFORM);
|
|
66
|
+
this.users = new AmpGlobalEntityServiceImpl<PlatformUserUpsertDto, PlatformUserDto>(rest, KIND.USERS, TARGET_API_PLATFORM);
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
static instance(options: AmpSdkOptions): AmpSdkServices {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface ErrorHandler<T> {
|
|
2
|
+
(_error: unknown): T;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_TREND_WINDOW_MONTHS = 6;
|
|
6
|
+
|
|
7
|
+
export type TargetApi = 'api' | 'platform';
|
|
8
|
+
export const TARGET_API_PLATFORM: TargetApi = 'platform';
|
|
9
|
+
export const TARGET_API_AGENT: TargetApi = 'api';
|
|
10
|
+
|
|
11
|
+
export const KIND = {
|
|
12
|
+
AGENTS: 'agents',
|
|
13
|
+
ASSETS: 'assets',
|
|
14
|
+
CONNECTORS: 'connectors',
|
|
15
|
+
FINDINGS: 'findings',
|
|
16
|
+
PROVIDERS: 'providers',
|
|
17
|
+
REPORT_RESULTS: 'report_results',
|
|
18
|
+
SAAS_ASSETS: 'saas_assets',
|
|
19
|
+
SAAS_COMPONENTS: 'saas_components',
|
|
20
|
+
SAAS_USERS: 'saas_users',
|
|
21
|
+
TENANTS: 'tenants',
|
|
22
|
+
USERS: 'users',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const REPORTS = {
|
|
26
|
+
HEALTH_SCORE: 'health-score',
|
|
27
|
+
EMPLOYEE_TOOLING_COVERAGE: 'workforce-tooling-employee-coverage',
|
|
28
|
+
ENDPOINT_TOOLING_COVERAGE: 'workforce-tooling-endpoint-coverage',
|
|
29
|
+
VULNERABILITY_SLA: 'vulnerability-sla',
|
|
30
|
+
TOP_RISK_CONTRIBUTORS: 'top-risk-contributors',
|
|
31
|
+
MFA_COVERAGE: 'mfa-application-coverage',
|
|
32
|
+
TRAINING_DEFICIENCIES: 'training-deficiencies',
|
|
33
|
+
SECURITY_HYGIENE: 'security-hygiene',
|
|
34
|
+
// trending reports
|
|
35
|
+
HEALTH_SCORE_TREND: 'health-trend',
|
|
36
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {BaseDto, Page} from '../dto';
|
|
2
2
|
import {FilterCriteria} from '../FilterCriteria';
|
|
3
|
+
import {ErrorHandler, TargetApi} from './constants';
|
|
3
4
|
import {RestClient, RestRequest} from './rest';
|
|
4
5
|
|
|
5
6
|
export interface AmpDataService<ReadT extends BaseDto> {
|
|
@@ -7,14 +8,6 @@ export interface AmpDataService<ReadT extends BaseDto> {
|
|
|
7
8
|
getById(_id: string): Promise<Page<ReadT>>;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
export interface ErrorHandler<T> {
|
|
11
|
-
(_error: unknown): T;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type TargetApi = 'api' | 'platform';
|
|
15
|
-
export const TARGET_API_PLATFORM: TargetApi = 'platform';
|
|
16
|
-
export const TARGET_API_AGENT: TargetApi = 'api';
|
|
17
|
-
|
|
18
11
|
export class AmpDataServiceImpl<ReadT extends BaseDto> implements AmpDataService<ReadT> {
|
|
19
12
|
protected readonly rest: RestClient;
|
|
20
13
|
protected readonly kind: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {BaseDto, BaseUpsertDto, ExtKeyMap, Page} from '../dto';
|
|
2
|
-
import {
|
|
2
|
+
import {TargetApi, TARGET_API_AGENT, ErrorHandler} from './constants';
|
|
3
|
+
import {AmpDataService, AmpDataServiceImpl} from './data.service';
|
|
3
4
|
import {RestClient, RestRequest} from './rest';
|
|
4
5
|
|
|
5
6
|
export interface AmpEntityService<WriteT extends BaseUpsertDto, ReadT extends BaseDto> extends AmpDataService<ReadT> {
|
package/src/services/index.ts
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {FilterCriteria} from '../FilterCriteria';
|
|
2
|
+
import {Page, ReportResultDto} from '../dto';
|
|
3
|
+
import {DEFAULT_TREND_WINDOW_MONTHS, KIND} from './constants';
|
|
4
|
+
import {RestClient, RestRequest} from './rest';
|
|
5
|
+
|
|
6
|
+
export interface AmpReportService {
|
|
7
|
+
getMetrics: (_reportId: string, _filter?: FilterCriteria) => Promise<Page<ReportResultDto>>;
|
|
8
|
+
getMetricsTrend: (_reportId: string, _filter?: FilterCriteria) => Promise<Page<ReportResultDto>>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class AmpReportServiceImpl implements AmpReportService {
|
|
12
|
+
protected readonly rest: RestClient;
|
|
13
|
+
|
|
14
|
+
constructor(rest: RestClient) {
|
|
15
|
+
this.rest = rest;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async getMetrics(reportId: string, filter?: FilterCriteria | undefined): Promise<Page<ReportResultDto>> {
|
|
19
|
+
filter = filter ?? {};
|
|
20
|
+
filter.limit = filter.limit ?? 1; // pull latest result by default
|
|
21
|
+
try {
|
|
22
|
+
const req = {
|
|
23
|
+
url: `/api/v1/reports/${reportId}/metrics`,
|
|
24
|
+
method: 'GET',
|
|
25
|
+
params: filter ?? {},
|
|
26
|
+
} as RestRequest;
|
|
27
|
+
const res = await this.rest.call(req);
|
|
28
|
+
return res.data as Page<ReportResultDto>;
|
|
29
|
+
} catch (error: unknown) {
|
|
30
|
+
if (error instanceof Error) {
|
|
31
|
+
console.error(error.message);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
data: [],
|
|
35
|
+
kind: KIND.REPORT_RESULTS.toUpperCase(),
|
|
36
|
+
error: (error as {message: string}).message,
|
|
37
|
+
hints: {},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @deprecated
|
|
45
|
+
* @param reportId
|
|
46
|
+
* @param filter
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
async getMetricsTrend(reportId: string, filter?: FilterCriteria): Promise<Page<ReportResultDto>> {
|
|
50
|
+
// I am breaking this out into a separate method so that we can extend typing later
|
|
51
|
+
// and add buckets/aggregations to the args
|
|
52
|
+
filter = filter ?? {};
|
|
53
|
+
filter.limit = filter.limit ?? DEFAULT_TREND_WINDOW_MONTHS;
|
|
54
|
+
return this.getMetrics(reportId, filter);
|
|
55
|
+
}
|
|
56
|
+
}
|