@ampsec/platform-client 35.0.0 → 36.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/index.d.ts +1 -0
- package/build/src/index.js +1 -0
- package/build/src/index.js.map +1 -1
- package/build/src/logging.d.ts +8 -0
- package/build/src/logging.js +11 -0
- package/build/src/logging.js.map +1 -0
- package/build/src/services/rest/RestClient.d.ts +4 -3
- package/build/src/services/rest/RestClient.js +4 -5
- package/build/src/services/rest/RestClient.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/logging.ts +14 -0
- package/src/services/rest/RestClient.ts +8 -6
package/build/src/index.d.ts
CHANGED
package/build/src/index.js
CHANGED
|
@@ -16,6 +16,7 @@ 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("./logging"), exports);
|
|
19
20
|
__exportStar(require("./services"), exports);
|
|
20
21
|
__exportStar(require("./FilterCriteria"), exports);
|
|
21
22
|
//# 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,6CAA2B;AAC3B,mDAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,yCAAuB;AACvB,4CAA0B;AAC1B,6CAA2B;AAC3B,mDAAiC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface AmpLogger {
|
|
2
|
+
info(_message: unknown, _meta?: unknown): void;
|
|
3
|
+
debug(_message: unknown, _meta?: unknown): void;
|
|
4
|
+
warn(_message: unknown, _meta?: unknown): void;
|
|
5
|
+
error(_message: unknown, _meta?: unknown): void;
|
|
6
|
+
}
|
|
7
|
+
export declare const defaultLogger: AmpLogger;
|
|
8
|
+
export declare const noopLogger: AmpLogger;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noopLogger = exports.defaultLogger = void 0;
|
|
4
|
+
exports.defaultLogger = console;
|
|
5
|
+
exports.noopLogger = {
|
|
6
|
+
info: () => { },
|
|
7
|
+
debug: () => { },
|
|
8
|
+
warn: () => { },
|
|
9
|
+
error: () => { },
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":";;;AAOa,QAAA,aAAa,GAAc,OAAO,CAAC;AACnC,QAAA,UAAU,GAAc;IACnC,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;IACd,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;IACf,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;IACd,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;CAChB,CAAC"}
|
|
@@ -4,13 +4,14 @@ import { RestResponse } from './RestResponse';
|
|
|
4
4
|
import { RestClientRetryStrategy } from './retry.rest';
|
|
5
5
|
import { HeadersMap } from './utils';
|
|
6
6
|
import { RestClientRateLimitStrategy } from './rateLimit.rest';
|
|
7
|
+
import { AmpLogger } from '../../logging';
|
|
7
8
|
export type AmpRestClientOptions = {
|
|
8
9
|
baseUrl: string;
|
|
9
10
|
token: string;
|
|
10
11
|
timeout?: number;
|
|
11
12
|
retryStrategy?: RestClientRetryStrategy;
|
|
12
13
|
rateLimitStrategy?: RestClientRateLimitStrategy;
|
|
13
|
-
|
|
14
|
+
logger?: AmpLogger;
|
|
14
15
|
client?: AxiosStatic;
|
|
15
16
|
};
|
|
16
17
|
export type RestClientOptions = {
|
|
@@ -19,7 +20,7 @@ export type RestClientOptions = {
|
|
|
19
20
|
timeout?: number;
|
|
20
21
|
retryStrategy?: RestClientRetryStrategy;
|
|
21
22
|
rateLimitStrategy?: RestClientRateLimitStrategy;
|
|
22
|
-
|
|
23
|
+
logger?: AmpLogger;
|
|
23
24
|
client?: AxiosStatic;
|
|
24
25
|
};
|
|
25
26
|
/**
|
|
@@ -39,7 +40,7 @@ export declare class DefaultRestClient {
|
|
|
39
40
|
protected readonly ampAxios: Axios;
|
|
40
41
|
protected readonly retryStrategy: RestClientRetryStrategy;
|
|
41
42
|
protected readonly rateLimitStrategy: RestClientRateLimitStrategy;
|
|
42
|
-
protected readonly
|
|
43
|
+
protected readonly logger: AmpLogger;
|
|
43
44
|
constructor(options?: RestClientOptions);
|
|
44
45
|
call(request: RestRequest): Promise<RestResponse>;
|
|
45
46
|
}
|
|
@@ -33,6 +33,7 @@ const axios_1 = __importStar(require("axios"));
|
|
|
33
33
|
const retry_rest_1 = require("./retry.rest");
|
|
34
34
|
const utils_1 = require("./utils");
|
|
35
35
|
const rateLimit_rest_1 = require("./rateLimit.rest");
|
|
36
|
+
const logging_1 = require("../../logging");
|
|
36
37
|
/**
|
|
37
38
|
* DefaultRestClient is a default implementation of RestClient.
|
|
38
39
|
* It defaults to useing axios to make REST calls and adds reasonble defaults
|
|
@@ -56,7 +57,7 @@ class DefaultRestClient {
|
|
|
56
57
|
var _a;
|
|
57
58
|
this.ampAxios.defaults.headers.common[key] = (_a = options.headers) === null || _a === void 0 ? void 0 : _a[key];
|
|
58
59
|
});
|
|
59
|
-
this.
|
|
60
|
+
this.logger = (_c = options.logger) !== null && _c !== void 0 ? _c : logging_1.noopLogger;
|
|
60
61
|
this.ampAxios.defaults.headers.common['Accepts'] = 'application/json';
|
|
61
62
|
this.ampAxios.defaults.headers.post['Content-Type'] = 'application/json';
|
|
62
63
|
this.ampAxios.defaults.headers.put['Content-Type'] = 'application/json';
|
|
@@ -68,8 +69,7 @@ class DefaultRestClient {
|
|
|
68
69
|
const req = lodash_1.default.merge(request);
|
|
69
70
|
try {
|
|
70
71
|
await this.rateLimitStrategy.reserve(req);
|
|
71
|
-
|
|
72
|
-
console.log('Request', req);
|
|
72
|
+
this.logger.debug({ req }); // noop logger by default
|
|
73
73
|
const res = await this.ampAxios.request(req);
|
|
74
74
|
return {
|
|
75
75
|
status: res.status,
|
|
@@ -94,14 +94,13 @@ class DefaultRestClient {
|
|
|
94
94
|
}
|
|
95
95
|
exports.DefaultRestClient = DefaultRestClient;
|
|
96
96
|
const getAmpRestClient = (options) => {
|
|
97
|
-
var _a;
|
|
98
97
|
const ampClient = new DefaultRestClient({
|
|
99
98
|
baseUrl: options.baseUrl,
|
|
100
99
|
headers: {
|
|
101
100
|
Authorization: `Bearer ${options.token}`,
|
|
102
101
|
},
|
|
103
102
|
rateLimitStrategy: new rateLimit_rest_1.StaticRestClientRateLimitStrategy(50),
|
|
104
|
-
|
|
103
|
+
logger: options.logger,
|
|
105
104
|
client: options.client,
|
|
106
105
|
});
|
|
107
106
|
return ampClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RestClient.js","sourceRoot":"","sources":["../../../../src/services/rest/RestClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AACvB,4CAAoB;AACpB,+CAA4D;AAG5D,6CAA4E;AAC5E,mCAAmD;AACnD,qDAAiI;
|
|
1
|
+
{"version":3,"file":"RestClient.js","sourceRoot":"","sources":["../../../../src/services/rest/RestClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AACvB,4CAAoB;AACpB,+CAA4D;AAG5D,6CAA4E;AAC5E,mCAAmD;AACnD,qDAAiI;AACjI,2CAAoD;AA6BpD;;;;;;GAMG;AACH,MAAa,iBAAiB;IAM5B,YAAY,UAA6B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MAAM;QACtB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAXW,QAAA,gBAAgB,oBAW3B"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/logging.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface AmpLogger {
|
|
2
|
+
info(_message: unknown, _meta?: unknown): void;
|
|
3
|
+
debug(_message: unknown, _meta?: unknown): void;
|
|
4
|
+
warn(_message: unknown, _meta?: unknown): void;
|
|
5
|
+
error(_message: unknown, _meta?: unknown): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const defaultLogger: AmpLogger = console;
|
|
9
|
+
export const noopLogger: AmpLogger = {
|
|
10
|
+
info: () => {},
|
|
11
|
+
debug: () => {},
|
|
12
|
+
warn: () => {},
|
|
13
|
+
error: () => {},
|
|
14
|
+
};
|
|
@@ -6,6 +6,7 @@ import {RestResponse} from './RestResponse';
|
|
|
6
6
|
import {RestClientRetryStrategy, noopRestRetryStrategy} from './retry.rest';
|
|
7
7
|
import {HeadersMap, convertHeaders} from './utils';
|
|
8
8
|
import {RestClientRateLimitStrategy, StaticRestClientRateLimitStrategy, noopRestClientRateLimitStrategy} from './rateLimit.rest';
|
|
9
|
+
import {AmpLogger, noopLogger} from '../../logging';
|
|
9
10
|
|
|
10
11
|
export type AmpRestClientOptions = {
|
|
11
12
|
baseUrl: string;
|
|
@@ -13,7 +14,7 @@ export type AmpRestClientOptions = {
|
|
|
13
14
|
timeout?: number;
|
|
14
15
|
retryStrategy?: RestClientRetryStrategy;
|
|
15
16
|
rateLimitStrategy?: RestClientRateLimitStrategy;
|
|
16
|
-
|
|
17
|
+
logger?: AmpLogger;
|
|
17
18
|
client?: AxiosStatic;
|
|
18
19
|
};
|
|
19
20
|
|
|
@@ -23,7 +24,7 @@ export type RestClientOptions = {
|
|
|
23
24
|
timeout?: number;
|
|
24
25
|
retryStrategy?: RestClientRetryStrategy;
|
|
25
26
|
rateLimitStrategy?: RestClientRateLimitStrategy;
|
|
26
|
-
|
|
27
|
+
logger?: AmpLogger;
|
|
27
28
|
client?: AxiosStatic;
|
|
28
29
|
};
|
|
29
30
|
|
|
@@ -45,7 +46,8 @@ export class DefaultRestClient {
|
|
|
45
46
|
protected readonly ampAxios: Axios;
|
|
46
47
|
protected readonly retryStrategy: RestClientRetryStrategy;
|
|
47
48
|
protected readonly rateLimitStrategy: RestClientRateLimitStrategy;
|
|
48
|
-
protected readonly
|
|
49
|
+
protected readonly logger: AmpLogger;
|
|
50
|
+
|
|
49
51
|
constructor(options: RestClientOptions = {}) {
|
|
50
52
|
// TODO: rest client
|
|
51
53
|
const client = options.client ?? axios;
|
|
@@ -59,7 +61,7 @@ export class DefaultRestClient {
|
|
|
59
61
|
Object.keys(options.headers ?? {}).forEach(key => {
|
|
60
62
|
this.ampAxios.defaults.headers.common[key] = options.headers?.[key];
|
|
61
63
|
});
|
|
62
|
-
this.
|
|
64
|
+
this.logger = options.logger ?? noopLogger;
|
|
63
65
|
this.ampAxios.defaults.headers.common['Accepts'] = 'application/json';
|
|
64
66
|
this.ampAxios.defaults.headers.post['Content-Type'] = 'application/json';
|
|
65
67
|
this.ampAxios.defaults.headers.put['Content-Type'] = 'application/json';
|
|
@@ -70,7 +72,7 @@ export class DefaultRestClient {
|
|
|
70
72
|
const req = _.merge(request);
|
|
71
73
|
try {
|
|
72
74
|
await this.rateLimitStrategy.reserve(req);
|
|
73
|
-
|
|
75
|
+
this.logger.debug({req}); // noop logger by default
|
|
74
76
|
const res = await this.ampAxios.request(req);
|
|
75
77
|
return {
|
|
76
78
|
status: res.status,
|
|
@@ -100,7 +102,7 @@ export const getAmpRestClient = (options: AmpRestClientOptions): RestClient => {
|
|
|
100
102
|
Authorization: `Bearer ${options.token}`,
|
|
101
103
|
},
|
|
102
104
|
rateLimitStrategy: new StaticRestClientRateLimitStrategy(50),
|
|
103
|
-
|
|
105
|
+
logger: options.logger,
|
|
104
106
|
client: options.client,
|
|
105
107
|
});
|
|
106
108
|
return ampClient;
|