From 5d5667bc8b81402cc8536c33453c632b82258bbb Mon Sep 17 00:00:00 2001 From: hg-pyun Date: Fri, 28 Jun 2019 19:23:55 +0900 Subject: [PATCH] Add 2.0.0 build files --- lib/common/config.d.ts | 53 ++++++++++++++++++++++++ lib/common/config.js | 50 +++++++++++++++++++++++ lib/common/print.d.ts | 2 + lib/common/print.js | 11 +++++ lib/common/string-builder.d.ts | 14 +++++++ lib/common/string-builder.js | 74 ++++++++++++++++++++++++++++++++++ lib/common/types.d.ts | 31 ++++++++++++++ lib/common/types.js | 2 + lib/index.d.ts | 5 +++ lib/index.js | 42 +++++++++++++++++++ lib/logger/error.d.ts | 5 +++ lib/logger/error.js | 49 ++++++++++++++++++++++ lib/logger/request.d.ts | 4 ++ lib/logger/request.js | 35 ++++++++++++++++ lib/logger/response.d.ts | 4 ++ lib/logger/response.js | 41 +++++++++++++++++++ package.json | 4 +- 17 files changed, 424 insertions(+), 2 deletions(-) create mode 100644 lib/common/config.d.ts create mode 100644 lib/common/config.js create mode 100644 lib/common/print.d.ts create mode 100644 lib/common/print.js create mode 100644 lib/common/string-builder.d.ts create mode 100644 lib/common/string-builder.js create mode 100644 lib/common/types.d.ts create mode 100644 lib/common/types.js create mode 100644 lib/index.d.ts create mode 100644 lib/index.js create mode 100644 lib/logger/error.d.ts create mode 100644 lib/logger/error.js create mode 100644 lib/logger/request.d.ts create mode 100644 lib/logger/request.js create mode 100644 lib/logger/response.d.ts create mode 100644 lib/logger/response.js diff --git a/lib/common/config.d.ts b/lib/common/config.d.ts new file mode 100644 index 0000000..3a11a00 --- /dev/null +++ b/lib/common/config.d.ts @@ -0,0 +1,53 @@ +import { ErrorLogConfig, GlobalLogConfig, RequestLogConfig, ResponseLogConfig } from './types'; +declare function getGlobalConfig(): GlobalLogConfig; +declare function setGlobalConfig(config: GlobalLogConfig): void; +declare function mergeWithGlobalConfig(config?: RequestLogConfig | ResponseLogConfig | ErrorLogConfig): { + data?: boolean | undefined; + url?: boolean | undefined; + method?: boolean | undefined; + headers?: boolean | undefined; + status?: boolean | undefined; + statusText?: boolean | undefined; + code?: boolean | undefined; + usePrefix?: boolean | undefined; + prefixText?: string | undefined; + useDate?: boolean | undefined; + dateFormat?: string | undefined; +} | { + data?: boolean | undefined; + url?: boolean | undefined; + method?: boolean | undefined; + headers?: boolean | undefined; + usePrefix?: boolean | undefined; + prefixText?: string | undefined; + useDate?: boolean | undefined; + dateFormat?: string | undefined; + status?: boolean | undefined; + statusText?: boolean | undefined; + code?: boolean | undefined; +} | { + data?: boolean | undefined; + status?: boolean | undefined; + statusText?: boolean | undefined; + headers?: boolean | undefined; + usePrefix?: boolean | undefined; + prefixText?: string | undefined; + useDate?: boolean | undefined; + dateFormat?: string | undefined; + url?: boolean | undefined; + method?: boolean | undefined; + code?: boolean | undefined; +} | { + data?: boolean | undefined; + code?: boolean | undefined; + usePrefix?: boolean | undefined; + prefixText?: string | undefined; + useDate?: boolean | undefined; + dateFormat?: string | undefined; + url?: boolean | undefined; + method?: boolean | undefined; + headers?: boolean | undefined; + status?: boolean | undefined; + statusText?: boolean | undefined; +}; +export { getGlobalConfig, setGlobalConfig, mergeWithGlobalConfig, }; diff --git a/lib/common/config.js b/lib/common/config.js new file mode 100644 index 0000000..93a7a61 --- /dev/null +++ b/lib/common/config.js @@ -0,0 +1,50 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +exports.getGlobalConfig = getGlobalConfig; +exports.setGlobalConfig = setGlobalConfig; +exports.mergeWithGlobalConfig = mergeWithGlobalConfig; + +function _objectSpread(target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] != null ? arguments[i] : {}; + var ownKeys = Object.keys(source); + if (typeof Object.getOwnPropertySymbols === 'function') { + ownKeys = ownKeys.concat( + Object.getOwnPropertySymbols(source).filter(function(sym) { + return Object.getOwnPropertyDescriptor(source, sym).enumerable; + }) + ); + } + ownKeys.forEach(function(key) { + _defineProperty(target, key, source[key]); + }); + } + return target; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); + } else { + obj[key] = value; + } + return obj; +} + +let globalConfig; + +function getGlobalConfig() { + return globalConfig; +} + +function setGlobalConfig(config) { + globalConfig = config; +} + +function mergeWithGlobalConfig(config) { + return _objectSpread({}, globalConfig, config); +} +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tb24vY29uZmlnLnRzIl0sIm5hbWVzIjpbImdsb2JhbENvbmZpZyIsImdldEdsb2JhbENvbmZpZyIsInNldEdsb2JhbENvbmZpZyIsImNvbmZpZyIsIm1lcmdlV2l0aEdsb2JhbENvbmZpZyJdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7OztBQUVBLElBQUlBLFlBQUo7O0FBRUEsU0FBU0MsZUFBVCxHQUEyQjtBQUN2QixTQUFPRCxZQUFQO0FBQ0g7O0FBRUQsU0FBU0UsZUFBVCxDQUF5QkMsTUFBekIsRUFBa0Q7QUFDOUNILEVBQUFBLFlBQVksR0FBR0csTUFBZjtBQUNIOztBQUVELFNBQVNDLHFCQUFULENBQStCRCxNQUEvQixFQUErRjtBQUMzRiwyQkFDT0gsWUFEUCxFQUVPRyxNQUZQO0FBSUgiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBFcnJvckxvZ0NvbmZpZywgR2xvYmFsTG9nQ29uZmlnLCBSZXF1ZXN0TG9nQ29uZmlnLCBSZXNwb25zZUxvZ0NvbmZpZyB9IGZyb20gJy4vdHlwZXMnO1xuXG5sZXQgZ2xvYmFsQ29uZmlnOiBHbG9iYWxMb2dDb25maWc7XG5cbmZ1bmN0aW9uIGdldEdsb2JhbENvbmZpZygpIHtcbiAgICByZXR1cm4gZ2xvYmFsQ29uZmlnO1xufVxuXG5mdW5jdGlvbiBzZXRHbG9iYWxDb25maWcoY29uZmlnOiBHbG9iYWxMb2dDb25maWcpIHtcbiAgICBnbG9iYWxDb25maWcgPSBjb25maWc7XG59XG5cbmZ1bmN0aW9uIG1lcmdlV2l0aEdsb2JhbENvbmZpZyhjb25maWc/OiBSZXF1ZXN0TG9nQ29uZmlnIHwgUmVzcG9uc2VMb2dDb25maWcgfCBFcnJvckxvZ0NvbmZpZykge1xuICAgIHJldHVybiB7XG4gICAgICAgIC4uLmdsb2JhbENvbmZpZyxcbiAgICAgICAgLi4uY29uZmlnLFxuICAgIH07XG59XG5cbmV4cG9ydCB7XG4gICAgZ2V0R2xvYmFsQ29uZmlnLFxuICAgIHNldEdsb2JhbENvbmZpZyxcbiAgICBtZXJnZVdpdGhHbG9iYWxDb25maWcsXG59OyJdfQ== diff --git a/lib/common/print.d.ts b/lib/common/print.d.ts new file mode 100644 index 0000000..2d4f796 --- /dev/null +++ b/lib/common/print.d.ts @@ -0,0 +1,2 @@ +declare function printLog(text: string): void; +export { printLog, }; diff --git a/lib/common/print.js b/lib/common/print.js new file mode 100644 index 0000000..405f9ec --- /dev/null +++ b/lib/common/print.js @@ -0,0 +1,11 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +exports.printLog = printLog; + +function printLog(text) { + console.log(text); +} +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tb24vcHJpbnQudHMiXSwibmFtZXMiOlsicHJpbnRMb2ciLCJ0ZXh0IiwiY29uc29sZSIsImxvZyJdLCJtYXBwaW5ncyI6Ijs7Ozs7OztBQUFBLFNBQVNBLFFBQVQsQ0FBbUJDLElBQW5CLEVBQWlDO0FBQzdCQyxFQUFBQSxPQUFPLENBQUNDLEdBQVIsQ0FBWUYsSUFBWjtBQUNIIiwic291cmNlc0NvbnRlbnQiOlsiZnVuY3Rpb24gcHJpbnRMb2cgKHRleHQ6IHN0cmluZykge1xuICAgIGNvbnNvbGUubG9nKHRleHQpO1xufVxuXG5leHBvcnQge1xuICAgIHByaW50TG9nLFxufVxuIl19 diff --git a/lib/common/string-builder.d.ts b/lib/common/string-builder.d.ts new file mode 100644 index 0000000..c252899 --- /dev/null +++ b/lib/common/string-builder.d.ts @@ -0,0 +1,14 @@ +import { GlobalLogConfig } from './types'; +declare class StringBuilder { + private config; + private printQueue; + constructor(config: GlobalLogConfig); + makePrefix(logType: string): this; + makeDateFormat(): this; + makeUrl(url?: string): this; + makeMethod(method?: string): this; + makeData(data: object): this; + makeStatus(status?: number, statusText?: string): this; + build(): string; +} +export default StringBuilder; diff --git a/lib/common/string-builder.js b/lib/common/string-builder.js new file mode 100644 index 0000000..465b521 --- /dev/null +++ b/lib/common/string-builder.js @@ -0,0 +1,74 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +exports.default = void 0; + +var _dateformat = _interopRequireDefault(require('dateformat')); + +var _chalk = _interopRequireDefault(require('chalk')); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} + +function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); + } else { + obj[key] = value; + } + return obj; +} + +class StringBuilder { + constructor(config) { + _defineProperty(this, 'config', void 0); + + _defineProperty(this, 'printQueue', void 0); + + this.config = config; + this.printQueue = []; + } + + makePrefix(logType) { + const prefix = this.config.prefixText ? `[${this.config.prefixText}][${logType}]` : `[Axios][${logType}]`; + this.printQueue.push(_chalk.default.green(prefix)); + return this; + } + + makeDateFormat() { + const dateFormat = (0, _dateformat.default)(new Date(), this.config.dateFormat || 'isoDateTime'); + this.printQueue.push(dateFormat); + return this; + } + + makeUrl(url) { + if (url) this.printQueue.push(url); + return this; + } + + makeMethod(method) { + if (method) this.printQueue.push(_chalk.default.yellow(method.toUpperCase())); + return this; + } + + makeData(data) { + if (data) this.printQueue.push(JSON.stringify(data)); + return this; + } + + makeStatus(status, statusText) { + if (status && statusText) this.printQueue.push(`${status}:${statusText}`); + return this; + } + + build() { + return this.printQueue.join(' '); + } +} + +var _default = StringBuilder; +exports.default = _default; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb21tb24vc3RyaW5nLWJ1aWxkZXIudHMiXSwibmFtZXMiOlsiU3RyaW5nQnVpbGRlciIsImNvbnN0cnVjdG9yIiwiY29uZmlnIiwicHJpbnRRdWV1ZSIsIm1ha2VQcmVmaXgiLCJsb2dUeXBlIiwicHJlZml4IiwicHJlZml4VGV4dCIsInB1c2giLCJjaGFsayIsImdyZWVuIiwibWFrZURhdGVGb3JtYXQiLCJkYXRlRm9ybWF0IiwiRGF0ZSIsIm1ha2VVcmwiLCJ1cmwiLCJtYWtlTWV0aG9kIiwibWV0aG9kIiwieWVsbG93IiwidG9VcHBlckNhc2UiLCJtYWtlRGF0YSIsImRhdGEiLCJKU09OIiwic3RyaW5naWZ5IiwibWFrZVN0YXR1cyIsInN0YXR1cyIsInN0YXR1c1RleHQiLCJidWlsZCIsImpvaW4iXSwibWFwcGluZ3MiOiI7Ozs7Ozs7QUFBQTs7QUFFQTs7Ozs7O0FBRUEsTUFBTUEsYUFBTixDQUFvQjtBQUloQkMsRUFBQUEsV0FBVyxDQUFDQyxNQUFELEVBQTBCO0FBQUE7O0FBQUE7O0FBQ2pDLFNBQUtBLE1BQUwsR0FBY0EsTUFBZDtBQUNBLFNBQUtDLFVBQUwsR0FBa0IsRUFBbEI7QUFDSDs7QUFFREMsRUFBQUEsVUFBVSxDQUFDQyxPQUFELEVBQWtCO0FBQ3hCLFVBQU1DLE1BQU0sR0FBRyxLQUFLSixNQUFMLENBQVlLLFVBQVosR0FBMEIsSUFBRyxLQUFLTCxNQUFMLENBQVlLLFVBQVcsS0FBSUYsT0FBUSxHQUFoRSxHQUFzRSxXQUFVQSxPQUFRLEdBQXZHO0FBQ0EsU0FBS0YsVUFBTCxDQUFnQkssSUFBaEIsQ0FBcUJDLGVBQU1DLEtB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KGRhdGVGb3JtYXQpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBtYWtlVXJsKHVybD86IHN0cmluZykge1xuICAgICAgICBpZih1cmwpIHRoaXMucHJpbnRRdWV1ZS5wdXNoKHVybCk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIG1ha2VNZXRob2QobWV0aG9kPzogc3RyaW5nKSB7XG4gICAgICAgIGlmKG1ldGhvZCkgdGhpcy5wcmludFF1ZXVlLnB1c2goY2hhbGsueWVsbG93KG1ldGhvZC50b1VwcGVyQ2FzZSgpKSk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIG1ha2VEYXRhKGRhdGE6IG9iamVjdCkge1xuICAgICAgICBpZihkYXRhKSB0aGlzLnByaW50UXVldWUucHVzaChKU09OLnN0cmluZ2lmeShkYXRhKSk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH1cblxuICAgIG1ha2VTdGF0dXMoc3RhdHVzPzpudW1iZXIsIHN0YXR1c1RleHQ/OiBzdHJpbmcpIHtcbiAgICAgICAgaWYoc3RhdHVzICYmIHN0YXR1c1RleHQpIHRoaXMucHJpbnRRdWV1ZS5wdXNoKGAke3N0YXR1c306JHtzdGF0dXNUZXh0fWApO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG5cbiAgICBidWlsZCgpIHtcbiAgICAgICAgcmV0dXJuIHRoaXMucHJpbnRRdWV1ZS5qb2luKCcgJyk7XG4gICAgfVxufVxuXG5leHBvcnQgZGVmYXVsdCBTdHJpbmdCdWlsZGVyOyJdfQ== diff --git a/lib/common/types.d.ts b/lib/common/types.d.ts new file mode 100644 index 0000000..1dae82a --- /dev/null +++ b/lib/common/types.d.ts @@ -0,0 +1,31 @@ +export interface CommonConfig { + usePrefix?: boolean; + prefixText?: string; + useDate?: boolean; + dateFormat?: string; +} +export interface GlobalLogConfig extends CommonConfig { + data?: boolean; + url?: boolean; + method?: boolean; + headers?: boolean; + status?: boolean; + statusText?: boolean; + code?: boolean; +} +export interface RequestLogConfig extends CommonConfig { + data?: boolean; + url?: boolean; + method?: boolean; + headers?: boolean; +} +export interface ResponseLogConfig extends CommonConfig { + data?: boolean; + status?: boolean; + statusText?: boolean; + headers?: boolean; +} +export interface ErrorLogConfig extends CommonConfig { + data?: boolean; + code?: boolean; +} diff --git a/lib/common/types.js b/lib/common/types.js new file mode 100644 index 0000000..dc2001d --- /dev/null +++ b/lib/common/types.js @@ -0,0 +1,2 @@ +'use strict'; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbXX0= diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..91674a9 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,5 @@ +import { setGlobalConfig } from './common/config'; +import requestLogger from './logger/request'; +import responseLogger from './logger/response'; +import { errorLogger } from './logger/error'; +export { setGlobalConfig, requestLogger, responseLogger, errorLogger }; diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..46a2961 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,42 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +Object.defineProperty(exports, 'setGlobalConfig', { + enumerable: true, + get: function() { + return _config.setGlobalConfig; + }, +}); +Object.defineProperty(exports, 'requestLogger', { + enumerable: true, + get: function() { + return _request.default; + }, +}); +Object.defineProperty(exports, 'responseLogger', { + enumerable: true, + get: function() { + return _response.default; + }, +}); +Object.defineProperty(exports, 'errorLogger', { + enumerable: true, + get: function() { + return _error.errorLogger; + }, +}); + +var _config = require('./common/config'); + +var _request = _interopRequireDefault(require('./logger/request')); + +var _response = _interopRequireDefault(require('./logger/response')); + +var _error = require('./logger/error'); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQTs7QUFDQTs7QUFDQTs7QUFDQSIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IHNldEdsb2JhbENvbmZpZyB9IGZyb20gJy4vY29tbW9uL2NvbmZpZyc7XG5pbXBvcnQgcmVxdWVzdExvZ2dlciBmcm9tICcuL2xvZ2dlci9yZXF1ZXN0JztcbmltcG9ydCByZXNwb25zZUxvZ2dlciBmcm9tICcuL2xvZ2dlci9yZXNwb25zZSc7XG5pbXBvcnQgeyBlcnJvckxvZ2dlciB9IGZyb20gJy4vbG9nZ2VyL2Vycm9yJztcblxuZXhwb3J0IHsgc2V0R2xvYmFsQ29uZmlnLCByZXF1ZXN0TG9nZ2VyLCByZXNwb25zZUxvZ2dlciwgZXJyb3JMb2dnZXIgfTsiXX0= diff --git a/lib/logger/error.d.ts b/lib/logger/error.d.ts new file mode 100644 index 0000000..6f9bb07 --- /dev/null +++ b/lib/logger/error.d.ts @@ -0,0 +1,5 @@ +import { AxiosError } from 'axios'; +import { ErrorLogConfig } from '../common/types'; +declare function errorLoggerWithoutPromise(error: AxiosError, config?: ErrorLogConfig): AxiosError; +declare function errorLogger(error: AxiosError): Promise; +export { errorLogger, errorLoggerWithoutPromise }; diff --git a/lib/logger/error.js b/lib/logger/error.js new file mode 100644 index 0000000..b33ab36 --- /dev/null +++ b/lib/logger/error.js @@ -0,0 +1,49 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +exports.errorLogger = errorLogger; +exports.errorLoggerWithoutPromise = errorLoggerWithoutPromise; + +var _config = require('../common/config'); + +var _stringBuilder = _interopRequireDefault(require('../common/string-builder')); + +var _print = require('../common/print'); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} + +function errorLoggerWithoutPromise(error, config) { + const { + config: { url, method }, + response, + } = error; + let status, statusText, data; + + if (response) { + status = response.status; + statusText = response.statusText; + data = response.data; + } + + const buildConfig = config ? config : (0, _config.mergeWithGlobalConfig)(config); + const stringBuilder = new _stringBuilder.default(buildConfig); + const log = stringBuilder + .makePrefix('Error') + .makeDateFormat() + .makeUrl(url) + .makeMethod(method) + .makeStatus(status, statusText) + .makeData(data) + .build(); + (0, _print.printLog)(log); + return error; +} + +function errorLogger(error) { + return Promise.reject(errorLoggerWithoutPromise(error)); +} +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sb2dnZXIvZXJyb3IudHMiXSwibmFtZXMiOlsiZXJyb3JMb2dnZXJXaXRob3V0UHJvbWlzZSIsImVycm9yIiwiY29uZmlnIiwidXJsIiwibWV0aG9kIiwicmVzcG9uc2UiLCJzdGF0dXMiLCJzdGF0dXNUZXh0IiwiZGF0YSIsImJ1aWxkQ29uZmlnIiwic3RyaW5nQnVpbGRlciIsIlN0cmluZ0J1aWxkZXIiLCJsb2ciLCJtYWtlUHJlZml4IiwibWFrZURhdGVGb3JtYXQiLCJtYWtlVXJsIiwibWFrZU1ldGhvZCIsIm1ha2VTdGF0dXMiLCJtYWtlRGF0YSIsImJ1aWxkIiwiZXJyb3JMb2dnZXIiLCJQcm9taXNlIiwicmVqZWN0Il0sIm1hcHBpbmdzIjoiOzs7Ozs7OztBQUVBOztBQUNBOztBQUNBOzs7O0FBRUEsU0FBU0EseUJBQVQsQ0FBbUNDLEtBQW5DLEVBQXNEQyxNQUF0RCxFQUErRTtBQUUzRSxRQUFNO0FBQUNBLElBQUFBLE1BQU0sRUFBRTtBQUFDQyxNQUFBQSxHQUFEO0FBQU1DLE1BQUFBO0FBQU4sS0FBVDtBQUF3QkMsSUFBQUE7QUFBeEIsTUFBb0NKLEtBQTFDO0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pb24gZXJyb3JMb2dnZXIoZXJyb3I6IEF4aW9zRXJyb3IpIHtcbiAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoZXJyb3JMb2dnZXJXaXRob3V0UHJvbWlzZShlcnJvcikpO1xufVxuXG5leHBvcnQgeyBlcnJvckxvZ2dlciwgZXJyb3JMb2dnZXJXaXRob3V0UHJvbWlzZSB9OyJdfQ== diff --git a/lib/logger/request.d.ts b/lib/logger/request.d.ts new file mode 100644 index 0000000..92e9915 --- /dev/null +++ b/lib/logger/request.d.ts @@ -0,0 +1,4 @@ +import { AxiosRequestConfig } from 'axios'; +import { RequestLogConfig } from '../common/types'; +declare function requestLogger(request: AxiosRequestConfig, config?: RequestLogConfig): AxiosRequestConfig; +export default requestLogger; diff --git a/lib/logger/request.js b/lib/logger/request.js new file mode 100644 index 0000000..f4015a5 --- /dev/null +++ b/lib/logger/request.js @@ -0,0 +1,35 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +exports.default = void 0; + +var _config = require('../common/config'); + +var _stringBuilder = _interopRequireDefault(require('../common/string-builder')); + +var _print = require('../common/print'); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} + +function requestLogger(request, config) { + const { url, method, data } = request; + const buildConfig = config ? config : (0, _config.mergeWithGlobalConfig)(config); + const stringBuilder = new _stringBuilder.default(buildConfig); + const log = stringBuilder + .makePrefix('Request') + .makeDateFormat() + .makeUrl(url) + .makeMethod(method) + .makeData(data) + .build(); + (0, _print.printLog)(log); + return request; +} + +var _default = requestLogger; +exports.default = _default; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sb2dnZXIvcmVxdWVzdC50cyJdLCJuYW1lcyI6WyJyZXF1ZXN0TG9nZ2VyIiwicmVxdWVzdCIsImNvbmZpZyIsInVybCIsIm1ldGhvZCIsImRhdGEiLCJidWlsZENvbmZpZyIsInN0cmluZ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bmctYnVpbGRlcic7XG5pbXBvcnQgeyBwcmludExvZyB9IGZyb20gJy4uL2NvbW1vbi9wcmludCc7XG5cbmZ1bmN0aW9uIHJlcXVlc3RMb2dnZXIocmVxdWVzdDogQXhpb3NSZXF1ZXN0Q29uZmlnLCBjb25maWc/OiBSZXF1ZXN0TG9nQ29uZmlnKSB7XG5cbiAgICBjb25zdCB7dXJsLCBtZXRob2QsIGRhdGF9ID0gcmVxdWVzdDtcbiAgICBjb25zdCBidWlsZENvbmZpZyA9IGNvbmZpZyA/IGNvbmZpZyA6IG1lcmdlV2l0aEdsb2JhbENvbmZpZyhjb25maWcpO1xuXG4gICAgY29uc3Qgc3RyaW5nQnVpbGRlciA9IG5ldyBTdHJpbmdCdWlsZGVyKGJ1aWxkQ29uZmlnKTtcbiAgICBjb25zdCBsb2cgPSBzdHJpbmdCdWlsZGVyXG4gICAgICAgIC5tYWtlUHJlZml4KCdSZXF1ZXN0JylcbiAgICAgICAgLm1ha2VEYXRlRm9ybWF0KClcbiAgICAgICAgLm1ha2VVcmwodXJsKVxuICAgICAgICAubWFrZU1ldGhvZChtZXRob2QpXG4gICAgICAgIC5tYWtlRGF0YShkYXRhKVxuICAgICAgICAuYnVpbGQoKTtcblxuICAgIHByaW50TG9nKGxvZyk7XG5cbiAgICByZXR1cm4gcmVxdWVzdDtcbn1cblxuZXhwb3J0IGRlZmF1bHQgcmVxdWVzdExvZ2dlcjsiXX0= diff --git a/lib/logger/response.d.ts b/lib/logger/response.d.ts new file mode 100644 index 0000000..949f372 --- /dev/null +++ b/lib/logger/response.d.ts @@ -0,0 +1,4 @@ +import { AxiosResponse } from 'axios'; +import { ResponseLogConfig } from '../common/types'; +declare function responseLogger(response: AxiosResponse, config?: ResponseLogConfig): AxiosResponse; +export default responseLogger; diff --git a/lib/logger/response.js b/lib/logger/response.js new file mode 100644 index 0000000..64b889e --- /dev/null +++ b/lib/logger/response.js @@ -0,0 +1,41 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { + value: true, +}); +exports.default = void 0; + +var _config = require('../common/config'); + +var _stringBuilder = _interopRequireDefault(require('../common/string-builder')); + +var _print = require('../common/print'); + +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} + +function responseLogger(response, config) { + const { + config: { url, method }, + status, + statusText, + data, + } = response; + const buildConfig = config ? config : (0, _config.mergeWithGlobalConfig)(config); + const stringBuilder = new _stringBuilder.default(buildConfig); + const log = stringBuilder + .makePrefix('Response') + .makeDateFormat() + .makeUrl(url) + .makeMethod(method) + .makeStatus(status, statusText) + .makeData(data) + .build(); + (0, _print.printLog)(log); + return response; +} + +var _default = responseLogger; +exports.default = _default; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9sb2dnZXIvcmVzcG9uc2UudHMiXSwibmFtZXMiOlsicmVzcG9uc2VMb2dnZXIiLCJyZXNwb25zZSIsImNvbmZpZyIsInVybCIsIm1ldGhvZCIsInN0YXR1cyIsInN0YXR1c1RleHQiLCJkYXRhIiwiYnVpbGRDb25maWciLCJzdHJpbmdCdWlsZGVyIiwiU3RyaW5nQnVpbGRlciIsImxvZyIsIm1ha2VQcmVmaXgiLCJtYWtlRGF0ZUZvcm1hdCIsIm1ha2VVcmwiLCJtYWtlTWV0aG9kIiwibWFrZVN0YXR1cyIsIm1ha2VEYXRhIiwiYnVpbGQiXSwibWFwcGluZ3MiOiI7Ozs7Ozs7QUFFQTs7QUFDQTs7QUFDQTs7OztBQUVBLFNBQVNBLGNBQVQsQ0FBd0JDLFFBQXhCLEVBQWlEQyxNQUFqRCxFQUE2RTtBQUN6RSxRQUFNO0FBQUNBLElBQUFBLE1BQU0sRUFBRTtBQUFDQyxNQUFBQSxHQUFEO0FBQU1DLE1BQUFBO0FBQU4sS0FBVDtBQUF3QkMsSUFBQUEsTUFBeEI7QUFBZ0NDLElBQUFBLFVBQWhDO0FBQTRDQyxJQUFBQTtBQUE1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Q29uZmlnID0gY29uZmlnID8gY29uZmlnIDogbWVyZ2VXaXRoR2xvYmFsQ29uZmlnKGNvbmZpZyk7XG5cbiAgICBjb25zdCBzdHJpbmdCdWlsZGVyID0gbmV3IFN0cmluZ0J1aWxkZXIoYnVpbGRDb25maWcpO1xuICAgIGNvbnN0IGxvZyA9IHN0cmluZ0J1aWxkZXJcbiAgICAgICAgLm1ha2VQcmVmaXgoJ1Jlc3BvbnNlJylcbiAgICAgICAgLm1ha2VEYXRlRm9ybWF0KClcbiAgICAgICAgLm1ha2VVcmwodXJsKVxuICAgICAgICAubWFrZU1ldGhvZChtZXRob2QpXG4gICAgICAgIC5tYWtlU3RhdHVzKHN0YXR1cywgc3RhdHVzVGV4dClcbiAgICAgICAgLm1ha2VEYXRhKGRhdGEpXG4gICAgICAgIC5idWlsZCgpO1xuXG4gICAgcHJpbnRMb2cobG9nKTtcblxuICAgIHJldHVybiByZXNwb25zZTtcbn1cblxuZXhwb3J0IGRlZmF1bHQgcmVzcG9uc2VMb2dnZXI7Il19 diff --git a/package.json b/package.json index 7e503f4..2524f64 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "axios-logger", - "version": "1.0.0", + "version": "2.0.0", "description": "Beautify Axios Logging Messages", - "main": "src/index.ts", + "main": "lib/index.js", "keywords": [ "javascript", "nodejs",