@ampsec/platform-client 2.1.0 → 4.0.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/FilterCriteria.d.ts +18 -0
- package/build/src/{EntityIdLookupMap.js → FilterCriteria.js} +1 -1
- package/build/src/FilterCriteria.js.map +1 -0
- package/build/src/dto/enums/agent.status.js +1 -0
- package/build/src/dto/enums/agent.status.js.map +1 -1
- package/build/src/dto/enums/connector.status.js +1 -0
- package/build/src/dto/enums/connector.status.js.map +1 -1
- package/build/src/dto/enums/finding.severity.js +1 -0
- package/build/src/dto/enums/finding.severity.js.map +1 -1
- package/build/src/dto/enums/finding.status.js +1 -0
- package/build/src/dto/enums/finding.status.js.map +1 -1
- package/build/src/dto/extKeyMap.dto.d.ts +6 -0
- package/build/src/dto/extKeyMap.dto.js +3 -0
- package/build/src/dto/extKeyMap.dto.js.map +1 -0
- package/build/src/dto/index.d.ts +2 -0
- package/build/src/dto/index.js +2 -0
- package/build/src/dto/index.js.map +1 -1
- package/build/src/dto/message.dto.d.ts +3 -0
- package/build/src/dto/message.dto.js +3 -0
- package/build/src/dto/message.dto.js.map +1 -0
- package/build/src/dto/page.dto.d.ts +11 -1
- package/build/src/dto/platform/platform.agents.dto.d.ts +2 -2
- package/build/src/dto/platform/platform.assets.dto.d.ts +2 -2
- package/build/src/dto/platform/platform.connectors.dto.d.ts +2 -2
- package/build/src/dto/platform/platform.findings.dto.d.ts +2 -2
- package/build/src/dto/platform/platform.metrics.dto.d.ts +2 -2
- package/build/src/dto/platform/platform.reportResults.dto.d.ts +2 -2
- package/build/src/dto/platform/platform.saasAssets.dto.d.ts +2 -2
- package/build/src/dto/platform/platform.saasComponents.dto.d.ts +2 -2
- package/build/src/dto/platform/platform.saasUsers.dto.d.ts +1 -1
- package/build/src/dto/platform/platform.users.dto.d.ts +2 -2
- package/build/src/etag.d.ts +3 -0
- package/build/src/etag.js +6 -1
- package/build/src/etag.js.map +1 -1
- package/build/src/index.d.ts +2 -1
- package/build/src/index.js +2 -1
- package/build/src/index.js.map +1 -1
- package/build/src/services/AmpApi.d.ts +32 -0
- package/build/src/services/AmpApi.js +39 -0
- package/build/src/services/AmpApi.js.map +1 -0
- package/build/src/services/AmpSdk.d.ts +31 -0
- package/build/src/services/AmpSdk.js +38 -0
- package/build/src/services/AmpSdk.js.map +1 -0
- package/build/src/services/data.service.d.ts +23 -0
- package/build/src/services/data.service.js +52 -0
- package/build/src/services/data.service.js.map +1 -0
- package/build/src/services/entity.service.d.ts +34 -0
- package/build/src/services/entity.service.js +78 -0
- package/build/src/services/entity.service.js.map +1 -0
- package/build/src/services/index.d.ts +5 -0
- package/build/src/services/index.js +22 -0
- package/build/src/services/index.js.map +1 -0
- package/build/src/services/rest/RestClient.d.ts +46 -0
- package/build/src/services/rest/RestClient.js +106 -0
- package/build/src/services/rest/RestClient.js.map +1 -0
- package/build/src/services/rest/RestRequest.d.ts +8 -0
- package/build/src/services/rest/RestRequest.js +3 -0
- package/build/src/services/rest/RestRequest.js.map +1 -0
- package/build/src/services/rest/RestResponse.d.ts +7 -0
- package/build/src/services/rest/RestResponse.js +3 -0
- package/build/src/services/rest/RestResponse.js.map +1 -0
- package/build/src/services/rest/index.d.ts +5 -0
- package/build/src/services/rest/index.js +22 -0
- package/build/src/services/rest/index.js.map +1 -0
- package/build/src/services/rest/rateLimit.rest.d.ts +11 -0
- package/build/src/services/rest/rateLimit.rest.js +25 -0
- package/build/src/services/rest/rateLimit.rest.js.map +1 -0
- package/build/src/services/rest/retry.rest.d.ts +7 -0
- package/build/src/services/rest/retry.rest.js +18 -0
- package/build/src/services/rest/retry.rest.js.map +1 -0
- package/build/src/services/rest/utils.d.ts +7 -0
- package/build/src/services/rest/utils.js +12 -0
- package/build/src/services/rest/utils.js.map +1 -0
- package/package.json +5 -2
- package/build/src/EntityIdLookupMap.d.ts +0 -11
- package/build/src/EntityIdLookupMap.js.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type FilterCriteria = {
|
|
2
|
+
/** Number of records to return. */
|
|
3
|
+
limit?: number;
|
|
4
|
+
/** Number of records to skip before capturing results. */
|
|
5
|
+
offset?: number;
|
|
6
|
+
/** Tenant ID */
|
|
7
|
+
tid?: number;
|
|
8
|
+
/** Connector ID */
|
|
9
|
+
cid?: number;
|
|
10
|
+
/** Organization name. Defaults to `*` which matches all organizations. */
|
|
11
|
+
organization?: '*' | 'EXTERNAL' | string;
|
|
12
|
+
/** Department name. Defaults to `*` which matches all departments. */
|
|
13
|
+
department?: '*' | string;
|
|
14
|
+
/** User ID */
|
|
15
|
+
uid?: number;
|
|
16
|
+
/** Asset ID */
|
|
17
|
+
aid?: number;
|
|
18
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilterCriteria.js","sourceRoot":"","sources":["../../src/FilterCriteria.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.status.js","sourceRoot":"","sources":["../../../../src/dto/enums/agent.status.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,sCAAuB,CAAA;AACzB,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB"}
|
|
1
|
+
{"version":3,"file":"agent.status.js","sourceRoot":"","sources":["../../../../src/dto/enums/agent.status.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,sCAAuB,CAAA;AACzB,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector.status.js","sourceRoot":"","sources":["../../../../src/dto/enums/connector.status.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;IACnB,oCAAiB,CAAA;IACjB,wCAAqB,CAAA;AACvB,CAAC,EALW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAK1B"}
|
|
1
|
+
{"version":3,"file":"connector.status.js","sourceRoot":"","sources":["../../../../src/dto/enums/connector.status.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,oCAAiB,CAAA;IACjB,sCAAmB,CAAA;IACnB,oCAAiB,CAAA;IACjB,wCAAqB,CAAA;AACvB,CAAC,EALW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAK1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finding.severity.js","sourceRoot":"","sources":["../../../../src/dto/enums/finding.severity.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,8BAAW,CAAA;IACX,oCAAiB,CAAA;IACjB,gCAAa,CAAA;IACb,wCAAqB,CAAA;AACvB,CAAC,EALW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAK1B"}
|
|
1
|
+
{"version":3,"file":"finding.severity.js","sourceRoot":"","sources":["../../../../src/dto/enums/finding.severity.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,8BAAW,CAAA;IACX,oCAAiB,CAAA;IACjB,gCAAa,CAAA;IACb,wCAAqB,CAAA;AACvB,CAAC,EALW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAK1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finding.status.js","sourceRoot":"","sources":["../../../../src/dto/enums/finding.status.ts"],"names":[],"mappings":";;;AAAA,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,kCAAiB,CAAA;AACnB,CAAC,EAHW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAGxB"}
|
|
1
|
+
{"version":3,"file":"finding.status.js","sourceRoot":"","sources":["../../../../src/dto/enums/finding.status.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,8BAAa,CAAA;IACb,kCAAiB,CAAA;AACnB,CAAC,EAHW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAGxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extKeyMap.dto.js","sourceRoot":"","sources":["../../../src/dto/extKeyMap.dto.ts"],"names":[],"mappings":""}
|
package/build/src/dto/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ export * from './assets.dto';
|
|
|
3
3
|
export * from './base.dto';
|
|
4
4
|
export * from './connectors.dto';
|
|
5
5
|
export * from './enums';
|
|
6
|
+
export * from './extKeyMap.dto';
|
|
6
7
|
export * from './findings.dto';
|
|
8
|
+
export * from './message.dto';
|
|
7
9
|
export * from './metrics.dto';
|
|
8
10
|
export * from './page.dto';
|
|
9
11
|
export * from './platform';
|
package/build/src/dto/index.js
CHANGED
|
@@ -19,7 +19,9 @@ __exportStar(require("./assets.dto"), exports);
|
|
|
19
19
|
__exportStar(require("./base.dto"), exports);
|
|
20
20
|
__exportStar(require("./connectors.dto"), exports);
|
|
21
21
|
__exportStar(require("./enums"), exports);
|
|
22
|
+
__exportStar(require("./extKeyMap.dto"), exports);
|
|
22
23
|
__exportStar(require("./findings.dto"), exports);
|
|
24
|
+
__exportStar(require("./message.dto"), exports);
|
|
23
25
|
__exportStar(require("./metrics.dto"), exports);
|
|
24
26
|
__exportStar(require("./page.dto"), exports);
|
|
25
27
|
__exportStar(require("./platform"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/dto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,0CAAwB;AACxB,iDAA+B;AAC/B,gDAA8B;AAC9B,6CAA2B;AAC3B,6CAA2B;AAC3B,kDAAgC;AAChC,sDAAoC;AACpC,yDAAuC;AACvC,mDAAiC;AACjC,uDAAqC;AACrC,kDAAgC;AAChC,gDAA8B;AAC9B,8CAA4B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/dto/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,6CAA2B;AAC3B,mDAAiC;AACjC,0CAAwB;AACxB,kDAAgC;AAChC,iDAA+B;AAC/B,gDAA8B;AAC9B,gDAA8B;AAC9B,6CAA2B;AAC3B,6CAA2B;AAC3B,kDAAgC;AAChC,sDAAoC;AACpC,yDAAuC;AACvC,mDAAiC;AACjC,uDAAqC;AACrC,kDAAgC;AAChC,gDAA8B;AAC9B,8CAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.dto.js","sourceRoot":"","sources":["../../../src/dto/message.dto.ts"],"names":[],"mappings":""}
|
|
@@ -3,6 +3,16 @@ export type Page<T> = {
|
|
|
3
3
|
data: T[];
|
|
4
4
|
error: string | null;
|
|
5
5
|
hints: {
|
|
6
|
-
|
|
6
|
+
limit?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
hasMore?: boolean;
|
|
9
|
+
next?: string;
|
|
10
|
+
count?: number;
|
|
11
|
+
links?: {
|
|
12
|
+
[keyName: string]: string;
|
|
13
|
+
};
|
|
14
|
+
[propName: string]: number | string | boolean | null | {
|
|
15
|
+
[keyName: string]: string;
|
|
16
|
+
} | undefined;
|
|
7
17
|
};
|
|
8
18
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AgentUpsertDto } from '../agents.dto';
|
|
1
|
+
import { AgentDto, AgentUpsertDto } from '../agents.dto';
|
|
2
2
|
import { MultiTenantBased, UpsertMultiTenantBased } from './multi.tenant.based.dto';
|
|
3
3
|
export type PlatformAgentUpsertDto = AgentUpsertDto & UpsertMultiTenantBased;
|
|
4
|
-
export type PlatformAgentDto =
|
|
4
|
+
export type PlatformAgentDto = AgentDto & MultiTenantBased;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AssetUpsertDto } from '../assets.dto';
|
|
1
|
+
import { AssetDto, AssetUpsertDto } from '../assets.dto';
|
|
2
2
|
import { TenantBased, UpsertTenantBased } from './tenant.based.dto';
|
|
3
3
|
export type PlatformAssetUpsertDto = AssetUpsertDto & UpsertTenantBased;
|
|
4
|
-
export type PlatformAssetDto =
|
|
4
|
+
export type PlatformAssetDto = AssetDto & TenantBased;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConnectorUpsertDto } from '../connectors.dto';
|
|
1
|
+
import { ConnectorDto, ConnectorUpsertDto } from '../connectors.dto';
|
|
2
2
|
import { TenantBased, UpsertTenantBased } from './tenant.based.dto';
|
|
3
3
|
export type PlatformConnectorUpsertDto = ConnectorUpsertDto & UpsertTenantBased;
|
|
4
|
-
export type PlatformConnectorDto =
|
|
4
|
+
export type PlatformConnectorDto = ConnectorDto & TenantBased;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FindingUpsertDto } from '../findings.dto';
|
|
1
|
+
import { FindingDto, FindingUpsertDto } from '../findings.dto';
|
|
2
2
|
import { TenantBased, UpsertTenantBased } from './tenant.based.dto';
|
|
3
3
|
export type PlatformFindingUpsertDto = FindingUpsertDto & UpsertTenantBased;
|
|
4
|
-
export type PlatformFindingDto =
|
|
4
|
+
export type PlatformFindingDto = FindingDto & TenantBased;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MetricUpsertDto } from '../metrics.dto';
|
|
1
|
+
import { MetricDto, MetricUpsertDto } from '../metrics.dto';
|
|
2
2
|
import { TenantBased, UpsertTenantBased } from './tenant.based.dto';
|
|
3
3
|
export type PlatformMetricUpsertDto = MetricUpsertDto & UpsertTenantBased;
|
|
4
|
-
export type PlatformMetricDto =
|
|
4
|
+
export type PlatformMetricDto = MetricDto & TenantBased;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReportResultUpsertDto } from '../reportResults.dto';
|
|
1
|
+
import { ReportResultDto, ReportResultUpsertDto } from '../reportResults.dto';
|
|
2
2
|
import { TenantBased, UpsertTenantBased } from './tenant.based.dto';
|
|
3
3
|
export type PlatformReportResultUpsertDto = ReportResultUpsertDto & UpsertTenantBased;
|
|
4
|
-
export type PlatformReportResultDto =
|
|
4
|
+
export type PlatformReportResultDto = ReportResultDto & TenantBased;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SaasAssetUpsertDto } from '../saasAssets.dto';
|
|
1
|
+
import { SaasAssetDto, SaasAssetUpsertDto } from '../saasAssets.dto';
|
|
2
2
|
import { TenantBased, UpsertTenantBased } from './tenant.based.dto';
|
|
3
3
|
export type PlatformSaasAssetUpsertDto = SaasAssetUpsertDto & UpsertTenantBased;
|
|
4
|
-
export type PlatformSaasAssetDto =
|
|
4
|
+
export type PlatformSaasAssetDto = SaasAssetDto & TenantBased;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SaasComponentUpsertDto } from '../saasComponents.dto';
|
|
1
|
+
import { SaasComponentDto, SaasComponentUpsertDto } from '../saasComponents.dto';
|
|
2
2
|
import { TenantBased, UpsertTenantBased } from './tenant.based.dto';
|
|
3
3
|
export type PlatformSaasComponentUpsertDto = SaasComponentUpsertDto & UpsertTenantBased;
|
|
4
|
-
export type PlatformSaasComponentDto =
|
|
4
|
+
export type PlatformSaasComponentDto = SaasComponentDto & TenantBased;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { SaasUserUpsertDto } from '../saasUsers.dto';
|
|
2
2
|
import { TenantBased, UpsertTenantBased } from './tenant.based.dto';
|
|
3
3
|
export type PlatformSaasUserUpsertDto = SaasUserUpsertDto & UpsertTenantBased;
|
|
4
|
-
export type PlatformSaasUserDto =
|
|
4
|
+
export type PlatformSaasUserDto = SaasUserUpsertDto & TenantBased;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserUpsertDto } from '../users.dto';
|
|
1
|
+
import { UserDto, UserUpsertDto } from '../users.dto';
|
|
2
2
|
import { TenantBased, UpsertTenantBased } from './tenant.based.dto';
|
|
3
3
|
export type PlatformUserUpsertDto = UserUpsertDto & UpsertTenantBased;
|
|
4
|
-
export type PlatformUserDto =
|
|
4
|
+
export type PlatformUserDto = UserDto & TenantBased;
|
package/build/src/etag.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { ChangeAwareDto, ChangeAwareUpsertDto } from './';
|
|
2
2
|
export declare function calculateEtag(model: unknown): string;
|
|
3
3
|
export declare function withEtag(model: ChangeAwareDto | ChangeAwareUpsertDto): void;
|
|
4
|
+
export declare function createWithEtag<T extends {
|
|
5
|
+
etag: string;
|
|
6
|
+
}>(model: T): T;
|
package/build/src/etag.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.withEtag = exports.calculateEtag = void 0;
|
|
6
|
+
exports.createWithEtag = exports.withEtag = exports.calculateEtag = void 0;
|
|
7
7
|
const blueimp_md5_1 = __importDefault(require("blueimp-md5"));
|
|
8
8
|
function calculateEtag(model) {
|
|
9
9
|
const hashObject = { ...model };
|
|
@@ -15,4 +15,9 @@ function withEtag(model) {
|
|
|
15
15
|
model.etag = calculateEtag(model);
|
|
16
16
|
}
|
|
17
17
|
exports.withEtag = withEtag;
|
|
18
|
+
function createWithEtag(model) {
|
|
19
|
+
model.etag = calculateEtag(model);
|
|
20
|
+
return model;
|
|
21
|
+
}
|
|
22
|
+
exports.createWithEtag = createWithEtag;
|
|
18
23
|
//# sourceMappingURL=etag.js.map
|
package/build/src/etag.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"etag.js","sourceRoot":"","sources":["../../src/etag.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA8B;AAG9B,SAAgB,aAAa,CAAC,KAAc;IAC1C,MAAM,UAAU,GAAoB,EAAC,GAAI,KAAgB,EAAC,CAAC;IAC3D,OAAO,UAAU,CAAC,IAAI,CAAC;IACvB,OAAO,IAAA,qBAAG,EAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;AACzC,CAAC;AAJD,sCAIC;AAED,SAAgB,QAAQ,CAAC,KAA4C;IACnE,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAFD,4BAEC"}
|
|
1
|
+
{"version":3,"file":"etag.js","sourceRoot":"","sources":["../../src/etag.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA8B;AAG9B,SAAgB,aAAa,CAAC,KAAc;IAC1C,MAAM,UAAU,GAAoB,EAAC,GAAI,KAAgB,EAAC,CAAC;IAC3D,OAAO,UAAU,CAAC,IAAI,CAAC;IACvB,OAAO,IAAA,qBAAG,EAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;AACzC,CAAC;AAJD,sCAIC;AAED,SAAgB,QAAQ,CAAC,KAA4C;IACnE,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAFD,4BAEC;AAED,SAAgB,cAAc,CAA2B,KAAQ;IAC/D,KAAK,CAAC,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAClC,OAAO,KAAK,CAAC;AACf,CAAC;AAHD,wCAGC"}
|
package/build/src/index.d.ts
CHANGED
package/build/src/index.js
CHANGED
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./dto"), exports);
|
|
18
18
|
__exportStar(require("./etag"), exports);
|
|
19
|
-
__exportStar(require("./
|
|
19
|
+
__exportStar(require("./services"), exports);
|
|
20
|
+
__exportStar(require("./FilterCriteria"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
package/build/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,yCAAuB;AACvB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,yCAAuB;AACvB,6CAA2B;AAC3B,mDAAiC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AgentDto, AgentUpsertDto, AssetDto, ConnectorDto, ConnectorUpsertDto, FindingDto, ProviderDto, ReportResultDto, SaasAssetDto, SaasComponentDto, SaasUserDto, TenantDto, TenantUpsertDto, UserDto } from '../dto';
|
|
2
|
+
import { AmpEntityService } from './entity.service';
|
|
3
|
+
import { AmpDataService } from './data.service';
|
|
4
|
+
import { AmpRestClientOptions, RestClient } from './rest';
|
|
5
|
+
export type AmpApiOptions = AmpRestClientOptions;
|
|
6
|
+
/**
|
|
7
|
+
* AMP API
|
|
8
|
+
* This client is a wrapper around the AMP REST API meant to be used by
|
|
9
|
+
* agents, i.e. Amplifier Security's customers. If you are trying to implement
|
|
10
|
+
* a plugin leverage the AmpSdk instead (see {@link AmpSdkServices} ).
|
|
11
|
+
*
|
|
12
|
+
* This client provides READ_ONLY access to most of the AMP API. You will
|
|
13
|
+
* have write access to the following resources:
|
|
14
|
+
* - Agents: {@link AmpApi.agents}
|
|
15
|
+
* - Connectors: {@link AmpApi.connectors}
|
|
16
|
+
* - Tenants: {@link AmpApi.tenants}
|
|
17
|
+
*/
|
|
18
|
+
export declare class AmpApi {
|
|
19
|
+
readonly agents: AmpEntityService<AgentUpsertDto, AgentDto>;
|
|
20
|
+
readonly asset: AmpDataService<AssetDto>;
|
|
21
|
+
readonly connectors: AmpEntityService<ConnectorUpsertDto, ConnectorDto>;
|
|
22
|
+
readonly findings: AmpDataService<FindingDto>;
|
|
23
|
+
readonly providers: AmpDataService<ProviderDto>;
|
|
24
|
+
readonly reports: AmpDataService<ReportResultDto>;
|
|
25
|
+
readonly saasAssets: AmpDataService<SaasAssetDto>;
|
|
26
|
+
readonly saasComponents: AmpDataService<SaasComponentDto>;
|
|
27
|
+
readonly saasUsers: AmpDataService<SaasUserDto>;
|
|
28
|
+
readonly tenants: AmpEntityService<TenantUpsertDto, TenantDto>;
|
|
29
|
+
readonly users: AmpDataService<UserDto>;
|
|
30
|
+
constructor(rest: RestClient);
|
|
31
|
+
static instance(options: AmpApiOptions): AmpApi;
|
|
32
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmpApi = void 0;
|
|
4
|
+
const entity_service_1 = require("./entity.service");
|
|
5
|
+
const data_service_1 = require("./data.service");
|
|
6
|
+
const rest_1 = require("./rest");
|
|
7
|
+
/**
|
|
8
|
+
* AMP API
|
|
9
|
+
* This client is a wrapper around the AMP REST API meant to be used by
|
|
10
|
+
* agents, i.e. Amplifier Security's customers. If you are trying to implement
|
|
11
|
+
* a plugin leverage the AmpSdk instead (see {@link AmpSdkServices} ).
|
|
12
|
+
*
|
|
13
|
+
* This client provides READ_ONLY access to most of the AMP API. You will
|
|
14
|
+
* have write access to the following resources:
|
|
15
|
+
* - Agents: {@link AmpApi.agents}
|
|
16
|
+
* - Connectors: {@link AmpApi.connectors}
|
|
17
|
+
* - Tenants: {@link AmpApi.tenants}
|
|
18
|
+
*/
|
|
19
|
+
class AmpApi {
|
|
20
|
+
constructor(rest) {
|
|
21
|
+
this.agents = new entity_service_1.AmpEntityServiceImpl(rest, 'agents');
|
|
22
|
+
this.asset = new data_service_1.AmpDataServiceImpl(rest, 'assets');
|
|
23
|
+
this.connectors = new entity_service_1.AmpEntityServiceImpl(rest, 'connectors');
|
|
24
|
+
this.findings = new data_service_1.AmpDataServiceImpl(rest, 'findings');
|
|
25
|
+
this.providers = new data_service_1.AmpDataServiceImpl(rest, 'providers');
|
|
26
|
+
this.reports = new data_service_1.AmpDataServiceImpl(rest, 'report_results');
|
|
27
|
+
this.saasAssets = new data_service_1.AmpDataServiceImpl(rest, 'saas_assets');
|
|
28
|
+
this.saasComponents = new data_service_1.AmpDataServiceImpl(rest, 'saas_components');
|
|
29
|
+
this.saasUsers = new data_service_1.AmpDataServiceImpl(rest, 'saas_users');
|
|
30
|
+
this.tenants = new entity_service_1.AmpEntityServiceImpl(rest, 'agents');
|
|
31
|
+
this.users = new data_service_1.AmpDataServiceImpl(rest, 'users');
|
|
32
|
+
}
|
|
33
|
+
static instance(options) {
|
|
34
|
+
const rest = (0, rest_1.getAmpRestClient)(options);
|
|
35
|
+
return new AmpApi(rest);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.AmpApi = AmpApi;
|
|
39
|
+
//# sourceMappingURL=AmpApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AmpApi.js","sourceRoot":"","sources":["../../../src/services/AmpApi.ts"],"names":[],"mappings":";;;AAgBA,qDAAwE;AACxE,iDAAkE;AAClE,iCAA0E;AAI1E;;;;;;;;;;;GAWG;AACH,MAAa,MAAM;IAajB,YAAY,IAAgB;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,qCAAoB,CAA2B,IAAI,EAAE,QAAQ,CAAC,CAAC;QACjF,IAAI,CAAC,KAAK,GAAG,IAAI,iCAAkB,CAAW,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,UAAU,GAAG,IAAI,qCAAoB,CAAmC,IAAI,EAAE,YAAY,CAAC,CAAC;QACjG,IAAI,CAAC,QAAQ,GAAG,IAAI,iCAAkB,CAAa,IAAI,EAAE,UAAU,CAAC,CAAC;QACrE,IAAI,CAAC,SAAS,GAAG,IAAI,iCAAkB,CAAc,IAAI,EAAE,WAAW,CAAC,CAAC;QACxE,IAAI,CAAC,OAAO,GAAG,IAAI,iCAAkB,CAAkB,IAAI,EAAE,gBAAgB,CAAC,CAAC;QAC/E,IAAI,CAAC,UAAU,GAAG,IAAI,iCAAkB,CAAe,IAAI,EAAE,aAAa,CAAC,CAAC;QAC5E,IAAI,CAAC,cAAc,GAAG,IAAI,iCAAkB,CAAmB,IAAI,EAAE,iBAAiB,CAAC,CAAC;QACxF,IAAI,CAAC,SAAS,GAAG,IAAI,iCAAkB,CAAc,IAAI,EAAE,YAAY,CAAC,CAAC;QACzE,IAAI,CAAC,OAAO,GAAG,IAAI,qCAAoB,CAA6B,IAAI,EAAE,QAAQ,CAAC,CAAC;QACpF,IAAI,CAAC,KAAK,GAAG,IAAI,iCAAkB,CAAU,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9D,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;AA/BD,wBA+BC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ConnectorDto, ConnectorUpsertDto, PlatformAgentDto, PlatformAgentUpsertDto, PlatformAssetDto, PlatformAssetUpsertDto, PlatformFindingDto, PlatformFindingUpsertDto, PlatformReportResultDto, PlatformReportResultUpsertDto, PlatformSaasAssetDto, PlatformSaasAssetUpsertDto, PlatformSaasComponentDto, PlatformSaasComponentUpsertDto, PlatformSaasUserDto, PlatformSaasUserUpsertDto, PlatformUserDto, PlatformUserUpsertDto, ProviderDto, TenantDto, TenantUpsertDto } from '../dto';
|
|
2
|
+
import { AmpEntityService, AmpGlobalEntityService, AmpSaaSEntityService } from './entity.service';
|
|
3
|
+
import { AmpDataService } from './data.service';
|
|
4
|
+
import { AmpRestClientOptions, RestClient } from './rest';
|
|
5
|
+
export type AmpSdkOptions = AmpRestClientOptions;
|
|
6
|
+
/**
|
|
7
|
+
* AMP API
|
|
8
|
+
* This client is a wrapper around the AMP REST API meant to be used by
|
|
9
|
+
* service accounts, i.e. plugins and platform extensions. If you are
|
|
10
|
+
* trying to implement a simple web client you should leverage the AmpApi
|
|
11
|
+
* instead (see {@link AmpApi} ).
|
|
12
|
+
*
|
|
13
|
+
* This client provides CRUD access to most of the AMP API. You
|
|
14
|
+
* have READ_ONLY access to the following resources:
|
|
15
|
+
* - providers: {@link AmpSdkServices.providers}
|
|
16
|
+
*/
|
|
17
|
+
export declare class AmpSdkServices {
|
|
18
|
+
readonly agents: AmpEntityService<PlatformAgentUpsertDto, PlatformAgentDto>;
|
|
19
|
+
readonly asset: AmpGlobalEntityService<PlatformAssetUpsertDto, PlatformAssetDto>;
|
|
20
|
+
readonly connectors: AmpEntityService<ConnectorUpsertDto, ConnectorDto>;
|
|
21
|
+
readonly findings: AmpSaaSEntityService<PlatformFindingUpsertDto, PlatformFindingDto>;
|
|
22
|
+
readonly providers: AmpDataService<ProviderDto>;
|
|
23
|
+
readonly reports: AmpSaaSEntityService<PlatformReportResultUpsertDto, PlatformReportResultDto>;
|
|
24
|
+
readonly saasAssets: AmpSaaSEntityService<PlatformSaasAssetUpsertDto, PlatformSaasAssetDto>;
|
|
25
|
+
readonly saasComponents: AmpSaaSEntityService<PlatformSaasComponentUpsertDto, PlatformSaasComponentDto>;
|
|
26
|
+
readonly saasUsers: AmpSaaSEntityService<PlatformSaasUserUpsertDto, PlatformSaasUserDto>;
|
|
27
|
+
readonly tenants: AmpEntityService<TenantUpsertDto, TenantDto>;
|
|
28
|
+
readonly users: AmpGlobalEntityService<PlatformUserUpsertDto, PlatformUserDto>;
|
|
29
|
+
constructor(rest: RestClient);
|
|
30
|
+
static instance(options: AmpSdkOptions): AmpSdkServices;
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmpSdkServices = void 0;
|
|
4
|
+
const entity_service_1 = require("./entity.service");
|
|
5
|
+
const data_service_1 = require("./data.service");
|
|
6
|
+
const rest_1 = require("./rest");
|
|
7
|
+
/**
|
|
8
|
+
* AMP API
|
|
9
|
+
* This client is a wrapper around the AMP REST API meant to be used by
|
|
10
|
+
* service accounts, i.e. plugins and platform extensions. If you are
|
|
11
|
+
* trying to implement a simple web client you should leverage the AmpApi
|
|
12
|
+
* instead (see {@link AmpApi} ).
|
|
13
|
+
*
|
|
14
|
+
* This client provides CRUD access to most of the AMP API. You
|
|
15
|
+
* have READ_ONLY access to the following resources:
|
|
16
|
+
* - providers: {@link AmpSdkServices.providers}
|
|
17
|
+
*/
|
|
18
|
+
class AmpSdkServices {
|
|
19
|
+
constructor(rest) {
|
|
20
|
+
this.agents = new entity_service_1.AmpEntityServiceImpl(rest, 'agents', data_service_1.TARGET_API_PLATFORM);
|
|
21
|
+
this.asset = new entity_service_1.AmpGlobalEntityServiceImpl(rest, 'assets', data_service_1.TARGET_API_PLATFORM);
|
|
22
|
+
this.connectors = new entity_service_1.AmpEntityServiceImpl(rest, 'connectors', data_service_1.TARGET_API_PLATFORM);
|
|
23
|
+
this.findings = new entity_service_1.AmpSaaSEntityServiceImpl(rest, 'findings', data_service_1.TARGET_API_PLATFORM);
|
|
24
|
+
this.providers = new data_service_1.AmpDataServiceImpl(rest, 'providers', data_service_1.TARGET_API_AGENT);
|
|
25
|
+
this.reports = new entity_service_1.AmpSaaSEntityServiceImpl(rest, 'report_results', data_service_1.TARGET_API_PLATFORM);
|
|
26
|
+
this.saasAssets = new entity_service_1.AmpSaaSEntityServiceImpl(rest, 'saas_assets', data_service_1.TARGET_API_PLATFORM);
|
|
27
|
+
this.saasComponents = new entity_service_1.AmpSaaSEntityServiceImpl(rest, 'saas_components', data_service_1.TARGET_API_PLATFORM);
|
|
28
|
+
this.saasUsers = new entity_service_1.AmpSaaSEntityServiceImpl(rest, 'saas_users', data_service_1.TARGET_API_PLATFORM);
|
|
29
|
+
this.tenants = new entity_service_1.AmpEntityServiceImpl(rest, 'tenants', data_service_1.TARGET_API_PLATFORM);
|
|
30
|
+
this.users = new entity_service_1.AmpGlobalEntityServiceImpl(rest, 'users', data_service_1.TARGET_API_PLATFORM);
|
|
31
|
+
}
|
|
32
|
+
static instance(options) {
|
|
33
|
+
const rest = (0, rest_1.getAmpRestClient)(options);
|
|
34
|
+
return new AmpSdkServices(rest);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.AmpSdkServices = AmpSdkServices;
|
|
38
|
+
//# sourceMappingURL=AmpSdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AmpSdk.js","sourceRoot":"","sources":["../../../src/services/AmpSdk.ts"],"names":[],"mappings":";;;AAuBA,qDAA4K;AAC5K,iDAAyG;AACzG,iCAA0E;AAI1E;;;;;;;;;;GAUG;AACH,MAAa,cAAc;IAazB,YAAY,IAAgB;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,qCAAoB,CAA2C,IAAI,EAAE,QAAQ,EAAE,kCAAmB,CAAC,CAAC;QACtH,IAAI,CAAC,KAAK,GAAG,IAAI,2CAA0B,CAA2C,IAAI,EAAE,QAAQ,EAAE,kCAAmB,CAAC,CAAC;QAC3H,IAAI,CAAC,UAAU,GAAG,IAAI,qCAAoB,CAAmC,IAAI,EAAE,YAAY,EAAE,kCAAmB,CAAC,CAAC;QACtH,IAAI,CAAC,QAAQ,GAAG,IAAI,yCAAwB,CAA+C,IAAI,EAAE,UAAU,EAAE,kCAAmB,CAAC,CAAC;QAClI,IAAI,CAAC,SAAS,GAAG,IAAI,iCAAkB,CAAc,IAAI,EAAE,WAAW,EAAE,+BAAgB,CAAC,CAAC;QAC1F,IAAI,CAAC,OAAO,GAAG,IAAI,yCAAwB,CAAyD,IAAI,EAAE,gBAAgB,EAAE,kCAAmB,CAAC,CAAC;QACjJ,IAAI,CAAC,UAAU,GAAG,IAAI,yCAAwB,CAAmD,IAAI,EAAE,aAAa,EAAE,kCAAmB,CAAC,CAAC;QAC3I,IAAI,CAAC,cAAc,GAAG,IAAI,yCAAwB,CAA2D,IAAI,EAAE,iBAAiB,EAAE,kCAAmB,CAAC,CAAC;QAC3J,IAAI,CAAC,SAAS,GAAG,IAAI,yCAAwB,CAAiD,IAAI,EAAE,YAAY,EAAE,kCAAmB,CAAC,CAAC;QACvI,IAAI,CAAC,OAAO,GAAG,IAAI,qCAAoB,CAA6B,IAAI,EAAE,SAAS,EAAE,kCAAmB,CAAC,CAAC;QAC1G,IAAI,CAAC,KAAK,GAAG,IAAI,2CAA0B,CAAyC,IAAI,EAAE,OAAO,EAAE,kCAAmB,CAAC,CAAC;IAC1H,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,OAAsB;QACpC,MAAM,IAAI,GAAG,IAAA,uBAAgB,EAAC,OAAO,CAAC,CAAC;QACvC,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AA/BD,wCA+BC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseDto, Page } from '../dto';
|
|
2
|
+
import { FilterCriteria } from '../FilterCriteria';
|
|
3
|
+
import { RestClient, RestRequest } from './rest';
|
|
4
|
+
export interface AmpDataService<ReadT extends BaseDto> {
|
|
5
|
+
list(_filter: FilterCriteria): Promise<Page<ReadT>>;
|
|
6
|
+
getById(_id: number): Promise<Page<ReadT>>;
|
|
7
|
+
}
|
|
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
|
+
export declare class AmpDataServiceImpl<ReadT extends BaseDto> implements AmpDataService<ReadT> {
|
|
15
|
+
protected readonly rest: RestClient;
|
|
16
|
+
protected readonly kind: string;
|
|
17
|
+
protected readonly targetApi: string;
|
|
18
|
+
constructor(rest: RestClient, kind: string, targetApi?: TargetApi);
|
|
19
|
+
protected call<T>(req: RestRequest, errorHandler: ErrorHandler<T>): Promise<T>;
|
|
20
|
+
protected getPage(req: RestRequest): Promise<Page<ReadT>>;
|
|
21
|
+
list(filter: FilterCriteria): Promise<Page<ReadT>>;
|
|
22
|
+
getById(id: number): Promise<Page<ReadT>>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmpDataServiceImpl = exports.TARGET_API_AGENT = exports.TARGET_API_PLATFORM = void 0;
|
|
4
|
+
exports.TARGET_API_PLATFORM = 'platform';
|
|
5
|
+
exports.TARGET_API_AGENT = 'api';
|
|
6
|
+
class AmpDataServiceImpl {
|
|
7
|
+
constructor(rest, kind, targetApi = 'api') {
|
|
8
|
+
this.rest = rest;
|
|
9
|
+
this.kind = kind;
|
|
10
|
+
this.targetApi = targetApi;
|
|
11
|
+
}
|
|
12
|
+
async call(req, errorHandler) {
|
|
13
|
+
try {
|
|
14
|
+
const res = await this.rest.call(req);
|
|
15
|
+
return res.data;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error instanceof Error) {
|
|
19
|
+
console.error(error.message);
|
|
20
|
+
}
|
|
21
|
+
return errorHandler(error);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async getPage(req) {
|
|
25
|
+
return this.call(req, (error) => {
|
|
26
|
+
if (error instanceof Error) {
|
|
27
|
+
console.error(error.message);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
data: [],
|
|
31
|
+
kind: this.kind.toUpperCase(),
|
|
32
|
+
error: error.message,
|
|
33
|
+
hints: {},
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
list(filter) {
|
|
38
|
+
return this.getPage({
|
|
39
|
+
url: `/${this.targetApi}/v1/${this.kind}`,
|
|
40
|
+
method: 'GET',
|
|
41
|
+
params: filter,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
getById(id) {
|
|
45
|
+
return this.getPage({
|
|
46
|
+
url: `/${this.targetApi}/v1/${this.kind}/${id}`,
|
|
47
|
+
method: 'GET',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.AmpDataServiceImpl = AmpDataServiceImpl;
|
|
52
|
+
//# sourceMappingURL=data.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.service.js","sourceRoot":"","sources":["../../../src/services/data.service.ts"],"names":[],"mappings":";;;AAca,QAAA,mBAAmB,GAAc,UAAU,CAAC;AAC5C,QAAA,gBAAgB,GAAc,KAAK,CAAC;AAEjD,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"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BaseDto, BaseUpsertDto, ExtKeyMap, Page } from '../dto';
|
|
2
|
+
import { AmpDataService, AmpDataServiceImpl, TargetApi } from './data.service';
|
|
3
|
+
import { RestClient } from './rest';
|
|
4
|
+
export interface AmpEntityService<WriteT extends BaseUpsertDto, ReadT extends BaseDto> extends AmpDataService<ReadT> {
|
|
5
|
+
create(_model: WriteT): Promise<Page<ReadT>>;
|
|
6
|
+
update(_model: WriteT): Promise<Page<ReadT>>;
|
|
7
|
+
delete(_id: number): Promise<Page<ReadT>>;
|
|
8
|
+
}
|
|
9
|
+
export interface AmpGlobalEntityService<WriteT extends BaseUpsertDto, ReadT extends BaseDto> extends AmpDataService<ReadT> {
|
|
10
|
+
create(_model: WriteT): Promise<Page<ReadT>>;
|
|
11
|
+
update(_model: WriteT): Promise<Page<ReadT>>;
|
|
12
|
+
delete(_id: number): Promise<Page<ReadT>>;
|
|
13
|
+
getLookupIds(_tid: number): Promise<ExtKeyMap>;
|
|
14
|
+
}
|
|
15
|
+
export interface AmpSaaSEntityService<WriteT extends BaseUpsertDto, ReadT extends BaseDto> extends AmpDataService<ReadT> {
|
|
16
|
+
create(_model: WriteT): Promise<Page<ReadT>>;
|
|
17
|
+
update(_model: WriteT): Promise<Page<ReadT>>;
|
|
18
|
+
delete(_id: number): Promise<Page<ReadT>>;
|
|
19
|
+
getLookupIds(_cid: number): Promise<ExtKeyMap>;
|
|
20
|
+
}
|
|
21
|
+
export declare class AmpEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT extends BaseDto> extends AmpDataServiceImpl<ReadT> implements AmpEntityService<WriteT, ReadT> {
|
|
22
|
+
constructor(rest: RestClient, kind: string, targetApi?: TargetApi);
|
|
23
|
+
create(model: WriteT): Promise<Page<ReadT>>;
|
|
24
|
+
update(model: WriteT): Promise<Page<ReadT>>;
|
|
25
|
+
delete(id: number): Promise<Page<ReadT>>;
|
|
26
|
+
}
|
|
27
|
+
export declare class AmpGlobalEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT extends BaseDto> extends AmpEntityServiceImpl<WriteT, ReadT> implements AmpGlobalEntityService<WriteT, ReadT> {
|
|
28
|
+
constructor(rest: RestClient, kind: string, targetApi?: TargetApi);
|
|
29
|
+
getLookupIds(tid: number): Promise<ExtKeyMap>;
|
|
30
|
+
}
|
|
31
|
+
export declare class AmpSaaSEntityServiceImpl<WriteT extends BaseUpsertDto, ReadT extends BaseDto> extends AmpEntityServiceImpl<WriteT, ReadT> implements AmpSaaSEntityService<WriteT, ReadT> {
|
|
32
|
+
constructor(rest: RestClient, kind: string, targetApi?: TargetApi);
|
|
33
|
+
getLookupIds(cid: number): Promise<ExtKeyMap>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AmpSaaSEntityServiceImpl = exports.AmpGlobalEntityServiceImpl = exports.AmpEntityServiceImpl = void 0;
|
|
4
|
+
const data_service_1 = require("./data.service");
|
|
5
|
+
class AmpEntityServiceImpl extends data_service_1.AmpDataServiceImpl {
|
|
6
|
+
constructor(rest, kind, targetApi = data_service_1.TARGET_API_AGENT) {
|
|
7
|
+
super(rest, kind, targetApi);
|
|
8
|
+
}
|
|
9
|
+
create(model) {
|
|
10
|
+
return this.getPage({
|
|
11
|
+
url: `/${this.targetApi}/v1/${this.kind}`,
|
|
12
|
+
method: 'POST',
|
|
13
|
+
data: model,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
update(model) {
|
|
17
|
+
return this.getPage({
|
|
18
|
+
url: `/${this.targetApi}/v1/${this.kind}/${model.id}`,
|
|
19
|
+
method: 'PUT',
|
|
20
|
+
data: model,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async delete(id) {
|
|
24
|
+
const res = await this.getById(id);
|
|
25
|
+
if (res.data.length === 1) {
|
|
26
|
+
const req = {
|
|
27
|
+
url: `/${this.targetApi}/v1/${this.kind}/${id}`,
|
|
28
|
+
method: 'DELETE',
|
|
29
|
+
};
|
|
30
|
+
const { error } = await this.call(req, (error) => {
|
|
31
|
+
if (error instanceof Error) {
|
|
32
|
+
console.error(error.message);
|
|
33
|
+
}
|
|
34
|
+
return { success: false, error };
|
|
35
|
+
});
|
|
36
|
+
if (error) {
|
|
37
|
+
throw new Error(`Failed to delete ${this.kind} with id="${id}"`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.AmpEntityServiceImpl = AmpEntityServiceImpl;
|
|
44
|
+
const extIdMapErrorHandler = (error) => {
|
|
45
|
+
if (error instanceof Error) {
|
|
46
|
+
console.error(error.message);
|
|
47
|
+
}
|
|
48
|
+
return {};
|
|
49
|
+
};
|
|
50
|
+
class AmpGlobalEntityServiceImpl extends AmpEntityServiceImpl {
|
|
51
|
+
constructor(rest, kind, targetApi = data_service_1.TARGET_API_AGENT) {
|
|
52
|
+
super(rest, kind, targetApi);
|
|
53
|
+
}
|
|
54
|
+
getLookupIds(tid) {
|
|
55
|
+
const req = {
|
|
56
|
+
url: `/${this.targetApi}/v1/${this.kind}/ext_key_map`,
|
|
57
|
+
method: 'GET',
|
|
58
|
+
params: { tid },
|
|
59
|
+
};
|
|
60
|
+
return this.call(req, extIdMapErrorHandler);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.AmpGlobalEntityServiceImpl = AmpGlobalEntityServiceImpl;
|
|
64
|
+
class AmpSaaSEntityServiceImpl extends AmpEntityServiceImpl {
|
|
65
|
+
constructor(rest, kind, targetApi = data_service_1.TARGET_API_AGENT) {
|
|
66
|
+
super(rest, kind, targetApi);
|
|
67
|
+
}
|
|
68
|
+
getLookupIds(cid) {
|
|
69
|
+
const req = {
|
|
70
|
+
url: `/${this.targetApi}/v1/${this.kind}/ext_key_map`,
|
|
71
|
+
method: 'GET',
|
|
72
|
+
params: { cid },
|
|
73
|
+
};
|
|
74
|
+
return this.call(req, extIdMapErrorHandler);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.AmpSaaSEntityServiceImpl = AmpSaaSEntityServiceImpl;
|
|
78
|
+
//# sourceMappingURL=entity.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.service.js","sourceRoot":"","sources":["../../../src/services/entity.service.ts"],"names":[],"mappings":";;;AACA,iDAA6G;AAqB7G,MAAa,oBAA0E,SAAQ,iCAAyB;IACtH,YAAY,IAAgB,EAAE,IAAY,EAAE,YAAuB,+BAAgB;QACjF,KAAK,CAAC,IAAI,EAA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k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./AmpApi"), exports);
|
|
18
|
+
__exportStar(require("./AmpSdk"), exports);
|
|
19
|
+
__exportStar(require("./data.service"), exports);
|
|
20
|
+
__exportStar(require("./entity.service"), exports);
|
|
21
|
+
__exportStar(require("./rest"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Axios, AxiosStatic } from 'axios';
|
|
2
|
+
import { RestRequest } from './RestRequest';
|
|
3
|
+
import { RestResponse } from './RestResponse';
|
|
4
|
+
import { RestClientRetryStrategy } from './retry.rest';
|
|
5
|
+
import { HeadersMap } from './utils';
|
|
6
|
+
import { RestClientRateLimitStrategy } from './rateLimit.rest';
|
|
7
|
+
export type AmpRestClientOptions = {
|
|
8
|
+
baseUrl: string;
|
|
9
|
+
token: string;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
retryStrategy?: RestClientRetryStrategy;
|
|
12
|
+
rateLimitStrategy?: RestClientRateLimitStrategy;
|
|
13
|
+
verbose?: boolean;
|
|
14
|
+
client?: AxiosStatic;
|
|
15
|
+
};
|
|
16
|
+
export type RestClientOptions = {
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
headers?: HeadersMap;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
retryStrategy?: RestClientRetryStrategy;
|
|
21
|
+
rateLimitStrategy?: RestClientRateLimitStrategy;
|
|
22
|
+
verbose?: boolean;
|
|
23
|
+
client?: AxiosStatic;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* RestClient is a generic interface for making REST calls.
|
|
27
|
+
*/
|
|
28
|
+
export interface RestClient {
|
|
29
|
+
call(_request: RestRequest): Promise<RestResponse>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* DefaultRestClient is a default implementation of RestClient.
|
|
33
|
+
* It defaults to useing axios to make REST calls and adds reasonble defaults
|
|
34
|
+
* for retry logic, error handling, headers, and timeouts.
|
|
35
|
+
*
|
|
36
|
+
* These strategies can be useful when scraping 3rd party APIs.
|
|
37
|
+
*/
|
|
38
|
+
export declare class DefaultRestClient {
|
|
39
|
+
protected readonly ampAxios: Axios;
|
|
40
|
+
protected readonly retryStrategy: RestClientRetryStrategy;
|
|
41
|
+
protected readonly rateLimitStrategy: RestClientRateLimitStrategy;
|
|
42
|
+
protected readonly verbose: boolean;
|
|
43
|
+
constructor(options?: RestClientOptions);
|
|
44
|
+
call(request: RestRequest): Promise<RestResponse>;
|
|
45
|
+
}
|
|
46
|
+
export declare const getAmpRestClient: (options: AmpRestClientOptions) => RestClient;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getAmpRestClient = exports.DefaultRestClient = void 0;
|
|
30
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
31
|
+
const axios_1 = __importStar(require("axios"));
|
|
32
|
+
const retry_rest_1 = require("./retry.rest");
|
|
33
|
+
const utils_1 = require("./utils");
|
|
34
|
+
const rateLimit_rest_1 = require("./rateLimit.rest");
|
|
35
|
+
/**
|
|
36
|
+
* DefaultRestClient is a default implementation of RestClient.
|
|
37
|
+
* It defaults to useing axios to make REST calls and adds reasonble defaults
|
|
38
|
+
* for retry logic, error handling, headers, and timeouts.
|
|
39
|
+
*
|
|
40
|
+
* These strategies can be useful when scraping 3rd party APIs.
|
|
41
|
+
*/
|
|
42
|
+
class DefaultRestClient {
|
|
43
|
+
constructor(options = {}) {
|
|
44
|
+
var _a, _b, _c, _d, _e;
|
|
45
|
+
// TODO: rest client
|
|
46
|
+
const client = (_a = options.client) !== null && _a !== void 0 ? _a : axios_1.default;
|
|
47
|
+
this.ampAxios = client.create({
|
|
48
|
+
baseURL: options.baseUrl,
|
|
49
|
+
timeout: options.timeout,
|
|
50
|
+
});
|
|
51
|
+
Object.keys((_b = options.headers) !== null && _b !== void 0 ? _b : {}).forEach(key => {
|
|
52
|
+
var _a;
|
|
53
|
+
this.ampAxios.defaults.headers.common[key] = (_a = options.headers) === null || _a === void 0 ? void 0 : _a[key];
|
|
54
|
+
});
|
|
55
|
+
this.verbose = (_c = options.verbose) !== null && _c !== void 0 ? _c : false;
|
|
56
|
+
this.ampAxios.defaults.headers.common['Accepts'] = 'application/json';
|
|
57
|
+
this.ampAxios.defaults.headers.post['Content-Type'] = 'application/json';
|
|
58
|
+
this.ampAxios.defaults.headers.put['Content-Type'] = 'application/json';
|
|
59
|
+
this.retryStrategy = (_d = options.retryStrategy) !== null && _d !== void 0 ? _d : retry_rest_1.noopRestRetryStrategy;
|
|
60
|
+
this.rateLimitStrategy = (_e = options.rateLimitStrategy) !== null && _e !== void 0 ? _e : rateLimit_rest_1.noopRestClientRateLimitStrategy;
|
|
61
|
+
}
|
|
62
|
+
async call(request) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const req = lodash_1.default.merge(request);
|
|
65
|
+
try {
|
|
66
|
+
await this.rateLimitStrategy.reserve(req);
|
|
67
|
+
if (this.verbose)
|
|
68
|
+
console.log('Request', req);
|
|
69
|
+
const res = await this.ampAxios.request(req);
|
|
70
|
+
return {
|
|
71
|
+
status: res.status,
|
|
72
|
+
headers: (0, utils_1.convertHeaders)(res),
|
|
73
|
+
data: res.data,
|
|
74
|
+
error: null,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
if (err instanceof axios_1.AxiosError) {
|
|
79
|
+
const axiosError = err;
|
|
80
|
+
return {
|
|
81
|
+
status: (_b = (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 500,
|
|
82
|
+
headers: axiosError.response ? (0, utils_1.convertHeaders)(axiosError.response) : {},
|
|
83
|
+
data: null,
|
|
84
|
+
error: err,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.DefaultRestClient = DefaultRestClient;
|
|
92
|
+
const getAmpRestClient = (options) => {
|
|
93
|
+
var _a;
|
|
94
|
+
const ampClient = new DefaultRestClient({
|
|
95
|
+
baseUrl: options.baseUrl,
|
|
96
|
+
headers: {
|
|
97
|
+
Authorization: `Bearer ${options.token}`,
|
|
98
|
+
},
|
|
99
|
+
rateLimitStrategy: new rateLimit_rest_1.StaticRestClientRateLimitStrategy(50),
|
|
100
|
+
verbose: (_a = options.verbose) !== null && _a !== void 0 ? _a : false,
|
|
101
|
+
client: options.client,
|
|
102
|
+
});
|
|
103
|
+
return ampClient;
|
|
104
|
+
};
|
|
105
|
+
exports.getAmpRestClient = getAmpRestClient;
|
|
106
|
+
//# sourceMappingURL=RestClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RestClient.js","sourceRoot":"","sources":["../../../../src/services/rest/RestClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AACvB,+CAA4D;AAG5D,6CAA4E;AAC5E,mCAAmD;AACnD,qDAAiI;AA6BjI;;;;;;GAMG;AACH,MAAa,iBAAiB;IAK5B,YAAY,UAA6B,EAAE;;QACzC,oBAAoB;QACpB,MAAM,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,eAAK,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAA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|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RestResponse.js","sourceRoot":"","sources":["../../../../src/services/rest/RestResponse.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./RestClient"), exports);
|
|
18
|
+
__exportStar(require("./RestRequest"), exports);
|
|
19
|
+
__exportStar(require("./RestResponse"), exports);
|
|
20
|
+
__exportStar(require("./rateLimit.rest"), exports);
|
|
21
|
+
__exportStar(require("./retry.rest"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/services/rest/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,gDAA8B;AAC9B,iDAA+B;AAC/B,mDAAiC;AACjC,+CAA6B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RestRequest } from './RestRequest';
|
|
2
|
+
export interface RestClientRateLimitStrategy {
|
|
3
|
+
reserve(_req: RestRequest): Promise<void>;
|
|
4
|
+
}
|
|
5
|
+
export declare const noopRestClientRateLimitStrategy: RestClientRateLimitStrategy;
|
|
6
|
+
export declare class StaticRestClientRateLimitStrategy implements RestClientRateLimitStrategy {
|
|
7
|
+
private readonly delay;
|
|
8
|
+
private lastRequest;
|
|
9
|
+
constructor(delay: number);
|
|
10
|
+
reserve(_req: RestRequest): Promise<void>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StaticRestClientRateLimitStrategy = exports.noopRestClientRateLimitStrategy = void 0;
|
|
4
|
+
exports.noopRestClientRateLimitStrategy = {
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
reserve(_req) {
|
|
7
|
+
return Promise.resolve();
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
11
|
+
class StaticRestClientRateLimitStrategy {
|
|
12
|
+
constructor(delay) {
|
|
13
|
+
this.delay = delay;
|
|
14
|
+
this.lastRequest = 0;
|
|
15
|
+
}
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
|
+
async reserve(_req) {
|
|
18
|
+
while (Date.now() - this.lastRequest < this.delay) {
|
|
19
|
+
await sleep(this.delay);
|
|
20
|
+
}
|
|
21
|
+
this.lastRequest = Date.now();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.StaticRestClientRateLimitStrategy = StaticRestClientRateLimitStrategy;
|
|
25
|
+
//# sourceMappingURL=rateLimit.rest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateLimit.rest.js","sourceRoot":"","sources":["../../../../src/services/rest/rateLimit.rest.ts"],"names":[],"mappings":";;;AAMa,QAAA,+BAA+B,GAAgC;IAC1E,6DAA6D;IAC7D,OAAO,CAAC,IAAiB;QACvB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAE9E,MAAa,iCAAiC;IAI5C,YAAY,KAAa;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;IACvB,CAAC;IACD,6DAA6D;IAC7D,KAAK,CAAC,OAAO,CAAC,IAAiB;QAC7B,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,KAAK,EAAE;YACjD,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACzB;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAChC,CAAC;CACF;AAfD,8EAeC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
2
|
+
import { RestRequest } from './RestRequest';
|
|
3
|
+
import { RestResponse } from './RestResponse';
|
|
4
|
+
export interface RestClientRetryStrategy {
|
|
5
|
+
onError(_req: RestRequest, _err: AxiosError): Promise<RestResponse>;
|
|
6
|
+
}
|
|
7
|
+
export declare const noopRestRetryStrategy: RestClientRetryStrategy;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noopRestRetryStrategy = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
exports.noopRestRetryStrategy = {
|
|
6
|
+
onError(req, err) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const axiosError = err;
|
|
9
|
+
const res = {
|
|
10
|
+
status: (_b = (_a = axiosError.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 500,
|
|
11
|
+
headers: axiosError.response ? (0, utils_1.convertHeaders)(axiosError.response) : {},
|
|
12
|
+
data: null,
|
|
13
|
+
error: err,
|
|
14
|
+
};
|
|
15
|
+
return Promise.resolve(res);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=retry.rest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.rest.js","sourceRoot":"","sources":["../../../../src/services/rest/retry.rest.ts"],"names":[],"mappings":";;;AACA,mCAAuC;AAQ1B,QAAA,qBAAqB,GAA4B;IAC5D,OAAO,CAAC,GAAgB,EAAE,GAAe;;QACvC,MAAM,UAAU,GAAG,GAAiB,CAAC;QACrC,MAAM,GAAG,GAAiB;YACxB,MAAM,EAAE,MAAA,MAAA,UAAU,CAAC,QAAQ,0CAAE,MAAM,mCAAI,GAAG;YAC1C,OAAO,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAA,sBAAc,EAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE;YACvE,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,GAAG;SACX,CAAC;QACF,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertHeaders = void 0;
|
|
4
|
+
function convertHeaders(res) {
|
|
5
|
+
const headers = {};
|
|
6
|
+
for (const [key, value] of Object.entries(res.headers)) {
|
|
7
|
+
headers[key] = value;
|
|
8
|
+
}
|
|
9
|
+
return headers;
|
|
10
|
+
}
|
|
11
|
+
exports.convertHeaders = convertHeaders;
|
|
12
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/services/rest/utils.ts"],"names":[],"mappings":";;;AAMA,SAAgB,cAAc,CAAC,GAAkB;IAC/C,MAAM,OAAO,GAAe,EAAE,CAAC;IAC/B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QACtD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAe,CAAC;KAChC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAND,wCAMC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ampsec/platform-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,14 +19,17 @@
|
|
|
19
19
|
"author": "Amplifier Security <engineering@amplifiersecurity.com>",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"axios": "^1.4.0",
|
|
22
23
|
"blueimp-md5": "^2.19.0",
|
|
24
|
+
"lodash": "^4.17.21",
|
|
23
25
|
"lodash.omit": "^4.5.0"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@jest/types": "^29.5.0",
|
|
29
|
+
"@types/axios": "^0.14.0",
|
|
27
30
|
"@types/blueimp-md5": "^2.18.0",
|
|
28
31
|
"@types/jest": "^29.5.1",
|
|
29
|
-
"@types/lodash
|
|
32
|
+
"@types/lodash": "^4.14.195",
|
|
30
33
|
"gts": "^3.1.1",
|
|
31
34
|
"jest": "^29.5.0",
|
|
32
35
|
"rimraf": "^5.0.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntityIdLookupMap.js","sourceRoot":"","sources":["../../src/EntityIdLookupMap.ts"],"names":[],"mappings":""}
|