@ampsec/platform-client 3.0.0 → 4.0.1

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.
Files changed (118) hide show
  1. package/build/src/FilterCriteria.d.ts +18 -0
  2. package/build/src/FilterCriteria.js +3 -0
  3. package/build/src/FilterCriteria.js.map +1 -0
  4. package/build/src/dto/enums/agent.status.js +1 -0
  5. package/build/src/dto/enums/agent.status.js.map +1 -1
  6. package/build/src/dto/enums/connector.status.js +1 -0
  7. package/build/src/dto/enums/connector.status.js.map +1 -1
  8. package/build/src/dto/enums/finding.severity.js +1 -0
  9. package/build/src/dto/enums/finding.severity.js.map +1 -1
  10. package/build/src/dto/enums/finding.status.js +1 -0
  11. package/build/src/dto/enums/finding.status.js.map +1 -1
  12. package/build/src/dto/page.dto.d.ts +8 -0
  13. package/build/src/dto/platform/platform.agents.dto.d.ts +2 -2
  14. package/build/src/dto/platform/platform.assets.dto.d.ts +2 -2
  15. package/build/src/dto/platform/platform.connectors.dto.d.ts +2 -2
  16. package/build/src/dto/platform/platform.findings.dto.d.ts +2 -2
  17. package/build/src/dto/platform/platform.metrics.dto.d.ts +2 -2
  18. package/build/src/dto/platform/platform.reportResults.dto.d.ts +2 -2
  19. package/build/src/dto/platform/platform.saasAssets.dto.d.ts +2 -2
  20. package/build/src/dto/platform/platform.saasComponents.dto.d.ts +2 -2
  21. package/build/src/dto/platform/platform.saasUsers.dto.d.ts +1 -1
  22. package/build/src/dto/platform/platform.users.dto.d.ts +2 -2
  23. package/build/src/etag.d.ts +3 -0
  24. package/build/src/etag.js +6 -1
  25. package/build/src/etag.js.map +1 -1
  26. package/build/src/index.d.ts +2 -0
  27. package/build/src/index.js +2 -0
  28. package/build/src/index.js.map +1 -1
  29. package/build/src/services/AmpApi.d.ts +32 -0
  30. package/build/src/services/AmpApi.js +39 -0
  31. package/build/src/services/AmpApi.js.map +1 -0
  32. package/build/src/services/AmpSdk.d.ts +31 -0
  33. package/build/src/services/AmpSdk.js +38 -0
  34. package/build/src/services/AmpSdk.js.map +1 -0
  35. package/build/src/services/data.service.d.ts +23 -0
  36. package/build/src/services/data.service.js +52 -0
  37. package/build/src/services/data.service.js.map +1 -0
  38. package/build/src/services/entity.service.d.ts +34 -0
  39. package/build/src/services/entity.service.js +78 -0
  40. package/build/src/services/entity.service.js.map +1 -0
  41. package/build/src/services/index.d.ts +5 -0
  42. package/build/src/services/index.js +22 -0
  43. package/build/src/services/index.js.map +1 -0
  44. package/build/src/services/rest/RestClient.d.ts +46 -0
  45. package/build/src/services/rest/RestClient.js +106 -0
  46. package/build/src/services/rest/RestClient.js.map +1 -0
  47. package/build/src/services/rest/RestRequest.d.ts +8 -0
  48. package/build/src/services/rest/RestRequest.js +3 -0
  49. package/build/src/services/rest/RestRequest.js.map +1 -0
  50. package/build/src/services/rest/RestResponse.d.ts +7 -0
  51. package/build/src/services/rest/RestResponse.js +3 -0
  52. package/build/src/services/rest/RestResponse.js.map +1 -0
  53. package/build/src/services/rest/index.d.ts +5 -0
  54. package/build/src/services/rest/index.js +22 -0
  55. package/build/src/services/rest/index.js.map +1 -0
  56. package/build/src/services/rest/rateLimit.rest.d.ts +11 -0
  57. package/build/src/services/rest/rateLimit.rest.js +25 -0
  58. package/build/src/services/rest/rateLimit.rest.js.map +1 -0
  59. package/build/src/services/rest/retry.rest.d.ts +7 -0
  60. package/build/src/services/rest/retry.rest.js +18 -0
  61. package/build/src/services/rest/retry.rest.js.map +1 -0
  62. package/build/src/services/rest/utils.d.ts +7 -0
  63. package/build/src/services/rest/utils.js +12 -0
  64. package/build/src/services/rest/utils.js.map +1 -0
  65. package/package.json +7 -3
  66. package/src/FilterCriteria.ts +18 -0
  67. package/src/dto/agents.dto.ts +15 -0
  68. package/src/dto/assets.dto.ts +10 -0
  69. package/src/dto/base.dto.ts +25 -0
  70. package/src/dto/connectors.dto.ts +13 -0
  71. package/src/dto/enums/agent.status.ts +6 -0
  72. package/src/dto/enums/connector.status.ts +7 -0
  73. package/src/dto/enums/finding.severity.ts +7 -0
  74. package/src/dto/enums/finding.status.ts +5 -0
  75. package/src/dto/enums/index.ts +4 -0
  76. package/src/dto/extKeyMap.dto.ts +6 -0
  77. package/src/dto/findings.dto.ts +26 -0
  78. package/src/dto/index.ts +19 -0
  79. package/src/dto/message.dto.ts +3 -0
  80. package/src/dto/metrics.dto.ts +10 -0
  81. package/src/dto/page.dto.ts +14 -0
  82. package/src/dto/platform/index.ts +13 -0
  83. package/src/dto/platform/multi.tenant.based.dto.ts +11 -0
  84. package/src/dto/platform/platform.agents.dto.ts +6 -0
  85. package/src/dto/platform/platform.assets.dto.ts +6 -0
  86. package/src/dto/platform/platform.connectors.dto.ts +6 -0
  87. package/src/dto/platform/platform.findings.dto.ts +6 -0
  88. package/src/dto/platform/platform.metrics.dto.ts +6 -0
  89. package/src/dto/platform/platform.providers.dto.ts +5 -0
  90. package/src/dto/platform/platform.reportResults.dto.ts +6 -0
  91. package/src/dto/platform/platform.saasAssets.dto.ts +5 -0
  92. package/src/dto/platform/platform.saasComponents.dto.ts +6 -0
  93. package/src/dto/platform/platform.saasUsers.dto.ts +6 -0
  94. package/src/dto/platform/platform.tenants.dto.ts +5 -0
  95. package/src/dto/platform/platform.users.dto.ts +6 -0
  96. package/src/dto/platform/tenant.based.dto.ts +11 -0
  97. package/src/dto/providers.dto.ts +8 -0
  98. package/src/dto/reportResults.dto.ts +12 -0
  99. package/src/dto/riskContributors.dto.ts +10 -0
  100. package/src/dto/saasAssets.dto.ts +16 -0
  101. package/src/dto/saasComponents.dto.ts +18 -0
  102. package/src/dto/saasUsers.dto.ts +14 -0
  103. package/src/dto/tenants.dto.ts +8 -0
  104. package/src/dto/users.dto.ts +28 -0
  105. package/src/etag.ts +17 -0
  106. package/src/index.ts +4 -0
  107. package/src/services/AmpApi.ts +66 -0
  108. package/src/services/AmpSdk.ts +72 -0
  109. package/src/services/data.service.ts +69 -0
  110. package/src/services/entity.service.ts +104 -0
  111. package/src/services/index.ts +5 -0
  112. package/src/services/rest/RestClient.ts +103 -0
  113. package/src/services/rest/RestRequest.ts +9 -0
  114. package/src/services/rest/RestResponse.ts +8 -0
  115. package/src/services/rest/index.ts +5 -0
  116. package/src/services/rest/rateLimit.rest.ts +31 -0
  117. package/src/services/rest/retry.rest.ts +21 -0
  118. package/src/services/rest/utils.ts +13 -0
@@ -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":"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"}
@@ -0,0 +1,8 @@
1
+ import { HeadersMap, QueryMap } from './utils';
2
+ export type RestRequest = {
3
+ url: string;
4
+ headers?: HeadersMap;
5
+ params?: QueryMap;
6
+ data?: unknown;
7
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
8
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=RestRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestRequest.js","sourceRoot":"","sources":["../../../../src/services/rest/RestRequest.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import { HeadersMap } from './utils';
2
+ export type RestResponse = {
3
+ status: number;
4
+ headers: HeadersMap;
5
+ data: unknown;
6
+ error: unknown;
7
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=RestResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestResponse.js","sourceRoot":"","sources":["../../../../src/services/rest/RestResponse.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export * from './RestClient';
2
+ export * from './RestRequest';
3
+ export * from './RestResponse';
4
+ export * from './rateLimit.rest';
5
+ export * from './retry.rest';
@@ -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,7 @@
1
+ import { AxiosResponse } from 'axios';
2
+ export type StringMap<T> = {
3
+ [key: string]: T;
4
+ };
5
+ export type HeadersMap = StringMap<string>;
6
+ export type QueryMap = StringMap<unknown>;
7
+ export declare function convertHeaders(res: AxiosResponse): HeadersMap;
@@ -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.0.0",
3
+ "version": "4.0.1",
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.omit": "^4.5.7",
32
+ "@types/lodash": "^4.14.195",
30
33
  "gts": "^3.1.1",
31
34
  "jest": "^29.5.0",
32
35
  "rimraf": "^5.0.0",
@@ -37,6 +40,7 @@
37
40
  "typescript": "^5.0.4"
38
41
  },
39
42
  "files": [
40
- "/build/src"
43
+ "/build/src",
44
+ "/src"
41
45
  ]
42
46
  }
@@ -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,15 @@
1
+ import {AgentStatus} from './enums/agent.status';
2
+ import {BaseDto, BaseUpsertDto} from './base.dto';
3
+
4
+ export type AgentUpsertDto = BaseUpsertDto & {
5
+ /** Agent first name */
6
+ firstName: string;
7
+ /** Agent last name */
8
+ lastName: string;
9
+ /** Status of the Agent, e.g. ACTIVE */
10
+ status: AgentStatus;
11
+ /** External Id */
12
+ email: string;
13
+ };
14
+
15
+ export type AgentDto = BaseDto & AgentUpsertDto;
@@ -0,0 +1,10 @@
1
+ import {ChangeAwareDto, ChangeAwareUpsertDto} from './base.dto';
2
+
3
+ export type AssetUpsertDto = ChangeAwareUpsertDto & {
4
+ /** External Id */
5
+ sn: string;
6
+ /** User Id of the asset owner */
7
+ uid?: number | undefined;
8
+ };
9
+
10
+ export type AssetDto = ChangeAwareDto & AssetUpsertDto;
@@ -0,0 +1,25 @@
1
+ export type BaseUpsertDto = {
2
+ /** Unique Row Identifier. Populated for entity updates. */
3
+ id?: number;
4
+ };
5
+
6
+ export type BaseDto = {
7
+ /** Unique Row Identifier */
8
+ id: number;
9
+ /** Record creation date in database. */
10
+ createdAt: string;
11
+ /** Last record update date in database. */
12
+ updatedAt: string;
13
+ /** Record deletion date in database. Only present on soft deleted, i.e. `null => active` */
14
+ deletedAt: string | null;
15
+ };
16
+
17
+ export type ChangeAwareUpsertDto = BaseUpsertDto & {
18
+ /** MD5 hash of a subset of properties to detect field level changes. */
19
+ etag: string;
20
+ };
21
+
22
+ export type ChangeAwareDto = BaseDto & {
23
+ /** MD5 hash of a subset of properties to deted field level changes. */
24
+ etag: string;
25
+ };
@@ -0,0 +1,13 @@
1
+ import {BaseDto, BaseUpsertDto} from './base.dto';
2
+ import {ConnectorStatus} from './enums/connector.status';
3
+
4
+ export type ConnectorUpsertDto = BaseUpsertDto & {
5
+ /** Human readable name of the connector */
6
+ displayValue: string;
7
+ /** Status of the connector, e.g. ACTIVE */
8
+ status: ConnectorStatus;
9
+ /** Provider Id */
10
+ pid?: number | null;
11
+ };
12
+
13
+ export type ConnectorDto = BaseDto & ConnectorUpsertDto;
@@ -0,0 +1,6 @@
1
+ /* eslint-disable no-unused-vars */
2
+ export enum AgentStatus {
3
+ ACTIVE = 'ACTIVE',
4
+ INVITED = 'INVITED',
5
+ SUSPENDED = 'SUSPENDED',
6
+ }
@@ -0,0 +1,7 @@
1
+ /* eslint-disable no-unused-vars */
2
+ export enum ConnectorStatus {
3
+ ACTIVE = 'ACTIVE',
4
+ DELETED = 'DELETED',
5
+ FAILED = 'FAILED',
6
+ DISABLED = 'DISABLED',
7
+ }
@@ -0,0 +1,7 @@
1
+ /* eslint-disable no-unused-vars */
2
+ export enum FindingSeverity {
3
+ LOW = 'LOW',
4
+ MEDIUM = 'MEDIUM',
5
+ HIGH = 'HIGH',
6
+ CRITICAL = 'CRITICAL',
7
+ }
@@ -0,0 +1,5 @@
1
+ /* eslint-disable no-unused-vars */
2
+ export enum FindingStatus {
3
+ OPEN = 'OPEN',
4
+ CLOSED = 'CLOSED',
5
+ }
@@ -0,0 +1,4 @@
1
+ export * from './agent.status';
2
+ export * from './connector.status';
3
+ export * from './finding.severity';
4
+ export * from './finding.status';
@@ -0,0 +1,6 @@
1
+ export type ExtKeyMap = {
2
+ [propName: string]: {
3
+ id: number;
4
+ etag: string;
5
+ };
6
+ };
@@ -0,0 +1,26 @@
1
+ import {BaseDto, BaseUpsertDto} from './base.dto';
2
+ import {FindingSeverity} from './enums/finding.severity';
3
+ import {FindingStatus} from './enums/finding.status';
4
+
5
+ export type FindingUpsertDto = BaseUpsertDto & {
6
+ /** Date the finding was closed */
7
+ closedAt?: string;
8
+ /** Type of finding */
9
+ kind: string;
10
+ /** Status of the finding, e.g. OPEN */
11
+ status: FindingStatus;
12
+ /** Severity of the finding, e.g. CRITICAL, HIGH, etc... */
13
+ severity: FindingSeverity;
14
+ /** Number of times the user has been engaged to resolve the finding */
15
+ numberOfEngagements: number;
16
+ /** Human readable name of the finding */
17
+ displayValue: string;
18
+ /** Description of the finding */
19
+ description?: string;
20
+ /** Id of the user to which the finding applies */
21
+ uid?: number | undefined;
22
+ /** Id of the SaasComponent related to the given finding */
23
+ scid: number;
24
+ };
25
+
26
+ export type FindingDto = BaseDto & FindingUpsertDto;
@@ -0,0 +1,19 @@
1
+ export * from './agents.dto';
2
+ export * from './assets.dto';
3
+ export * from './base.dto';
4
+ export * from './connectors.dto';
5
+ export * from './enums';
6
+ export * from './extKeyMap.dto';
7
+ export * from './findings.dto';
8
+ export * from './message.dto';
9
+ export * from './metrics.dto';
10
+ export * from './page.dto';
11
+ export * from './platform';
12
+ export * from './providers.dto';
13
+ export * from './reportResults.dto';
14
+ export * from './riskContributors.dto';
15
+ export * from './saasAssets.dto';
16
+ export * from './saasComponents.dto';
17
+ export * from './saasUsers.dto';
18
+ export * from './tenants.dto';
19
+ export * from './users.dto';
@@ -0,0 +1,3 @@
1
+ export type Message = {
2
+ message: string;
3
+ };
@@ -0,0 +1,10 @@
1
+ import {BaseDto, BaseUpsertDto} from './base.dto';
2
+
3
+ export type MetricUpsertDto = BaseUpsertDto & {
4
+ uid: number;
5
+ score: number;
6
+ scoreDelta: number;
7
+ rank: number;
8
+ };
9
+
10
+ export type MetricDto = BaseDto & MetricUpsertDto;
@@ -0,0 +1,14 @@
1
+ export type Page<T> = {
2
+ kind: string;
3
+ data: T[];
4
+ error: string | null;
5
+ hints: {
6
+ limit?: number;
7
+ offset?: number;
8
+ hasMore?: boolean;
9
+ next?: string;
10
+ count?: number;
11
+ links?: {[keyName: string]: string};
12
+ [propName: string]: number | string | boolean | null | {[keyName: string]: string} | undefined;
13
+ };
14
+ };
@@ -0,0 +1,13 @@
1
+ export * from './platform.agents.dto';
2
+ export * from './platform.assets.dto';
3
+ export * from './platform.connectors.dto';
4
+ export * from './platform.findings.dto';
5
+ export * from './platform.metrics.dto';
6
+ export * from './platform.providers.dto';
7
+ export * from './platform.reportResults.dto';
8
+ export * from './platform.saasAssets.dto';
9
+ export * from './platform.saasComponents.dto';
10
+ export * from './platform.saasUsers.dto';
11
+ export * from './platform.tenants.dto';
12
+ export * from './platform.users.dto';
13
+ export * from './tenant.based.dto';
@@ -0,0 +1,11 @@
1
+ import {BaseDto, BaseUpsertDto} from '../base.dto';
2
+
3
+ export type UpsertMultiTenantBased = BaseUpsertDto & {
4
+ /** Tenant Ids for multi-tenant entities */
5
+ tids?: number[];
6
+ };
7
+
8
+ export type MultiTenantBased = BaseDto & {
9
+ /** Tenant Ids for multi-tenant entities */
10
+ tids: number[];
11
+ };
@@ -0,0 +1,6 @@
1
+ import {AgentDto, AgentUpsertDto} from '../agents.dto';
2
+ import {MultiTenantBased, UpsertMultiTenantBased} from './multi.tenant.based.dto';
3
+
4
+ export type PlatformAgentUpsertDto = AgentUpsertDto & UpsertMultiTenantBased;
5
+
6
+ export type PlatformAgentDto = AgentDto & MultiTenantBased;
@@ -0,0 +1,6 @@
1
+ import {AssetDto, AssetUpsertDto} from '../assets.dto';
2
+ import {TenantBased, UpsertTenantBased} from './tenant.based.dto';
3
+
4
+ export type PlatformAssetUpsertDto = AssetUpsertDto & UpsertTenantBased;
5
+
6
+ export type PlatformAssetDto = AssetDto & TenantBased;
@@ -0,0 +1,6 @@
1
+ import {ConnectorDto, ConnectorUpsertDto} from '../connectors.dto';
2
+ import {TenantBased, UpsertTenantBased} from './tenant.based.dto';
3
+
4
+ export type PlatformConnectorUpsertDto = ConnectorUpsertDto & UpsertTenantBased;
5
+
6
+ export type PlatformConnectorDto = ConnectorDto & TenantBased;