@ampsec/platform-client 35.1.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.
@@ -5,3 +5,4 @@ export interface AmpLogger {
5
5
  error(_message: unknown, _meta?: unknown): void;
6
6
  }
7
7
  export declare const defaultLogger: AmpLogger;
8
+ export declare const noopLogger: AmpLogger;
@@ -1,5 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultLogger = void 0;
3
+ exports.noopLogger = exports.defaultLogger = void 0;
4
4
  exports.defaultLogger = console;
5
+ exports.noopLogger = {
6
+ info: () => { },
7
+ debug: () => { },
8
+ warn: () => { },
9
+ error: () => { },
10
+ };
5
11
  //# sourceMappingURL=logging.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":";;;AAOa,QAAA,aAAa,GAAc,OAAO,CAAC"}
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"}
@@ -11,7 +11,6 @@ export type AmpRestClientOptions = {
11
11
  timeout?: number;
12
12
  retryStrategy?: RestClientRetryStrategy;
13
13
  rateLimitStrategy?: RestClientRateLimitStrategy;
14
- verbose?: boolean;
15
14
  logger?: AmpLogger;
16
15
  client?: AxiosStatic;
17
16
  };
@@ -21,7 +20,6 @@ export type RestClientOptions = {
21
20
  timeout?: number;
22
21
  retryStrategy?: RestClientRetryStrategy;
23
22
  rateLimitStrategy?: RestClientRateLimitStrategy;
24
- verbose?: boolean;
25
23
  logger?: AmpLogger;
26
24
  client?: AxiosStatic;
27
25
  };
@@ -42,7 +40,6 @@ export declare class DefaultRestClient {
42
40
  protected readonly ampAxios: Axios;
43
41
  protected readonly retryStrategy: RestClientRetryStrategy;
44
42
  protected readonly rateLimitStrategy: RestClientRateLimitStrategy;
45
- protected readonly verbose: boolean;
46
43
  protected readonly logger: AmpLogger;
47
44
  constructor(options?: RestClientOptions);
48
45
  call(request: RestRequest): Promise<RestResponse>;
@@ -57,8 +57,7 @@ class DefaultRestClient {
57
57
  var _a;
58
58
  this.ampAxios.defaults.headers.common[key] = (_a = options.headers) === null || _a === void 0 ? void 0 : _a[key];
59
59
  });
60
- this.verbose = options.verbose || !!options.logger;
61
- this.logger = (_c = options.logger) !== null && _c !== void 0 ? _c : logging_1.defaultLogger;
60
+ this.logger = (_c = options.logger) !== null && _c !== void 0 ? _c : logging_1.noopLogger;
62
61
  this.ampAxios.defaults.headers.common['Accepts'] = 'application/json';
63
62
  this.ampAxios.defaults.headers.post['Content-Type'] = 'application/json';
64
63
  this.ampAxios.defaults.headers.put['Content-Type'] = 'application/json';
@@ -70,8 +69,7 @@ class DefaultRestClient {
70
69
  const req = lodash_1.default.merge(request);
71
70
  try {
72
71
  await this.rateLimitStrategy.reserve(req);
73
- if (this.verbose)
74
- this.logger.info('Request', req);
72
+ this.logger.debug({ req }); // noop logger by default
75
73
  const res = await this.ampAxios.request(req);
76
74
  return {
77
75
  status: res.status,
@@ -96,14 +94,13 @@ class DefaultRestClient {
96
94
  }
97
95
  exports.DefaultRestClient = DefaultRestClient;
98
96
  const getAmpRestClient = (options) => {
99
- var _a;
100
97
  const ampClient = new DefaultRestClient({
101
98
  baseUrl: options.baseUrl,
102
99
  headers: {
103
100
  Authorization: `Bearer ${options.token}`,
104
101
  },
105
102
  rateLimitStrategy: new rateLimit_rest_1.StaticRestClientRateLimitStrategy(50),
106
- verbose: (_a = options.verbose) !== null && _a !== void 0 ? _a : false,
103
+ logger: options.logger,
107
104
  client: options.client,
108
105
  });
109
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;AACjI,2CAAuD;AA+BvD;;;;;;GAMG;AACH,MAAa,iBAAiB;IAO5B,YAAY,UAA6B,EAAE;;QACzC,oBAAoB;QACpB,MAAM,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,eAAK,CAAC;QACvC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC;YAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,gBAAgB,EAAE,MAAM,CAAC,EAAE;gBACzB,OAAO,YAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAC,WAAW,EAAE,QAAQ,EAAC,CAAC,CAAC;YACvD,CAAC;SACF,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;;YAC/C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAA,OAAO,CAAC,OAAO,0CAAG,GAAG,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;QACnD,IAAI,CAAC,MAAM,GAAG,MAAA,OAAO,CAAC,MAAM,mCAAI,uBAAa,CAAC;QAC9C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,kBAAkB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AClB,OAAO,EAAE,IAAA,sBAAc,EAAC,GAAG,CAAC;gBAC5B,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,KAAK,EAAE,IAAI;aACZ,CAAC;SACH;QAAC,OAAO,GAAY,EAAE;YACrB,IAAI,GAAG,YAAY,kBAAU,EAAE;gBAC7B,MAAM,UAAU,GAAG,GAAiB,CAAC;gBACrC,OAAO;oBACL,MAAM,EAAE,MAAA,MAAA,UAAU,CAAC,QAAQ,0CAAE,MAAM,mCAAI,GAAG;oBAC1C,OAAO,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAA,sBAAc,EAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE;oBACvE,IAAI,EAAE,IAAI;oBACV,KAAK,EAAE,GAAG;iBACX,CAAC;aACH;YACD,MAAM,GAAG,CAAC;SACX;IACH,CAAC;CACF;AAnDD,8CAmDC;AAEM,MAAM,gBAAgB,GAAG,CAAC,OAA6B,EAAc,EAAE;IAC5E,MAAM,SAAS,GAAG,IAAI,iBAAiB,CAAC;QACtC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,OAAO,CAAC,KAAK,EAAE;SACzC;QACD,iBAAiB,EAAE,IAAI,kDAAiC,CAAC,EAAE,CAAC;QAC5D,MAAM,EAAE,OAAO,CAAC,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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampsec/platform-client",
3
- "version": "35.1.0",
3
+ "version": "36.0.0",
4
4
  "description": "",
5
5
  "main": "build/src/index.js",
6
6
  "runkitExampleFilename": "example/main.js",
package/src/logging.ts CHANGED
@@ -6,3 +6,9 @@ export interface AmpLogger {
6
6
  }
7
7
 
8
8
  export const defaultLogger: AmpLogger = console;
9
+ export const noopLogger: AmpLogger = {
10
+ info: () => {},
11
+ debug: () => {},
12
+ warn: () => {},
13
+ error: () => {},
14
+ };
@@ -6,7 +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, defaultLogger} from '../../logging';
9
+ import {AmpLogger, noopLogger} from '../../logging';
10
10
 
11
11
  export type AmpRestClientOptions = {
12
12
  baseUrl: string;
@@ -14,7 +14,6 @@ export type AmpRestClientOptions = {
14
14
  timeout?: number;
15
15
  retryStrategy?: RestClientRetryStrategy;
16
16
  rateLimitStrategy?: RestClientRateLimitStrategy;
17
- verbose?: boolean;
18
17
  logger?: AmpLogger;
19
18
  client?: AxiosStatic;
20
19
  };
@@ -25,7 +24,6 @@ export type RestClientOptions = {
25
24
  timeout?: number;
26
25
  retryStrategy?: RestClientRetryStrategy;
27
26
  rateLimitStrategy?: RestClientRateLimitStrategy;
28
- verbose?: boolean;
29
27
  logger?: AmpLogger;
30
28
  client?: AxiosStatic;
31
29
  };
@@ -48,7 +46,6 @@ export class DefaultRestClient {
48
46
  protected readonly ampAxios: Axios;
49
47
  protected readonly retryStrategy: RestClientRetryStrategy;
50
48
  protected readonly rateLimitStrategy: RestClientRateLimitStrategy;
51
- protected readonly verbose: boolean;
52
49
  protected readonly logger: AmpLogger;
53
50
 
54
51
  constructor(options: RestClientOptions = {}) {
@@ -64,8 +61,7 @@ export class DefaultRestClient {
64
61
  Object.keys(options.headers ?? {}).forEach(key => {
65
62
  this.ampAxios.defaults.headers.common[key] = options.headers?.[key];
66
63
  });
67
- this.verbose = options.verbose || !!options.logger;
68
- this.logger = options.logger ?? defaultLogger;
64
+ this.logger = options.logger ?? noopLogger;
69
65
  this.ampAxios.defaults.headers.common['Accepts'] = 'application/json';
70
66
  this.ampAxios.defaults.headers.post['Content-Type'] = 'application/json';
71
67
  this.ampAxios.defaults.headers.put['Content-Type'] = 'application/json';
@@ -76,7 +72,7 @@ export class DefaultRestClient {
76
72
  const req = _.merge(request);
77
73
  try {
78
74
  await this.rateLimitStrategy.reserve(req);
79
- if (this.verbose) this.logger.info('Request', req);
75
+ this.logger.debug({req}); // noop logger by default
80
76
  const res = await this.ampAxios.request(req);
81
77
  return {
82
78
  status: res.status,
@@ -106,7 +102,7 @@ export const getAmpRestClient = (options: AmpRestClientOptions): RestClient => {
106
102
  Authorization: `Bearer ${options.token}`,
107
103
  },
108
104
  rateLimitStrategy: new StaticRestClientRateLimitStrategy(50),
109
- verbose: options.verbose ?? false,
105
+ logger: options.logger,
110
106
  client: options.client,
111
107
  });
112
108
  return ampClient;