@lokalise/node-core 9.1.0 → 9.3.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/README.md +16 -0
- package/dist/index.d.ts +10 -13
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/src/logging/loggerConfigResolver.d.ts +5 -0
- package/dist/src/logging/loggerConfigResolver.js +25 -1
- package/dist/src/logging/loggerConfigResolver.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,6 +89,22 @@ The library provides methods to resolve the default logging configuration. Publi
|
|
|
89
89
|
const logger = pino(loggerConfig)
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
+
- `resolveMonorepoLoggerConfiguration()`, which accepts as parameter an `appConfig`, defined by the `logLevel` and the `nodeEnv`. It mostly behaves the same as `resolveLoggerConfiguration`, with the exception of execution in `development environments`. Since monorepo services are usually ran concurrently, logs from `stdout` aren't easily accessible. For this reason this logging configuration writes development logs into files.
|
|
93
|
+
|
|
94
|
+
The method returns a logger configuration that should be used with `pino` library as in the following example:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const loggerConfig = resolveMonorepoLoggerConfiguration({
|
|
98
|
+
logLevel: 'warn',
|
|
99
|
+
nodeEnv: 'production',
|
|
100
|
+
append: false,
|
|
101
|
+
// targetFile: './logs/service.log' -- optional parameter, you can specify exact path for writing logs
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
const logger = pino(loggerConfig)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
|
|
92
108
|
## ConfigScope
|
|
93
109
|
|
|
94
110
|
`ConfigScope` is a class that provides a way to encapsulate a single config source (e. g. `process.env`) and produce a set of values out of it, defining constraints and transformations for them.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
export { sendPut, sendPutBinary, sendDelete, sendPatch, sendGet, sendPost, sendPostBinary, httpClient, buildClient, } from './src/http/httpClient';
|
|
2
|
-
export
|
|
3
|
-
export {
|
|
4
|
-
export type { PublicNonRecoverableErrorParams } from './src/errors/PublicNonRecoverableError';
|
|
5
|
-
export { InternalError } from './src/errors/InternalError';
|
|
1
|
+
export { sendPut, sendPutBinary, sendDelete, sendPatch, sendGet, sendPost, sendPostBinary, httpClient, buildClient, type RequestOptions, type Response, type HttpRequestContext, type ResponseSchema, } from './src/http/httpClient';
|
|
2
|
+
export { PublicNonRecoverableError, type PublicNonRecoverableErrorParams, } from './src/errors/PublicNonRecoverableError';
|
|
3
|
+
export { InternalError, type ErrorDetails, type InternalErrorParams, } from './src/errors/InternalError';
|
|
6
4
|
export { ResponseStatusError } from './src/errors/ResponseStatusError';
|
|
7
|
-
export type { ErrorDetails, InternalErrorParams } from './src/errors/InternalError';
|
|
8
5
|
export { ConfigScope } from './src/config/ConfigScope';
|
|
9
6
|
export { ensureClosingSlashTransformer } from './src/config/configTransformers';
|
|
10
7
|
export { createRangeValidator } from './src/config/configValidators';
|
|
11
|
-
export type
|
|
12
|
-
export type
|
|
8
|
+
export { type EnvValueValidator, type EnvValueTransformer, type AppConfig, type RedisConfig, } from './src/config/configTypes';
|
|
9
|
+
export { type Either, success, failure, isSuccess, isFailure } from './src/errors/either';
|
|
13
10
|
export { chunk, callChunked, removeFalsy, removeNullish } from './src/utils/arrayUtils';
|
|
14
11
|
export { groupBy, groupByUnique, pick, pickWithoutUndefined, copyWithoutUndefined, isEmptyObject, convertDateFieldsToIsoString, deepClone, } from './src/utils/objectUtils';
|
|
15
12
|
export { isInternalError, isStandardizedError, isObject, isPublicNonRecoverableError, hasMessage, } from './src/utils/typeUtils';
|
|
16
|
-
export type
|
|
17
|
-
export { resolveLoggerConfiguration } from './src/logging/loggerConfigResolver';
|
|
18
|
-
export type { AppLoggerConfig } from './src/logging/loggerConfigResolver';
|
|
19
|
-
export type
|
|
13
|
+
export { type StandardizedError } from './src/utils/typeUtils';
|
|
14
|
+
export { resolveLoggerConfiguration, resolveMonorepoLoggerConfiguration, } from './src/logging/loggerConfigResolver';
|
|
15
|
+
export type { AppLoggerConfig, MonorepoAppLoggerConfig } from './src/logging/loggerConfigResolver';
|
|
16
|
+
export { type ErrorReport, type ErrorReporter, type ErrorResolver, } from './src/errors/errorReporterTypes';
|
|
20
17
|
export { executeAsyncAndHandleGlobalErrors, executeAndHandleGlobalErrors, executeSettleAllAndHandleGlobalErrors, globalLogger, resolveGlobalErrorLogObject, } from './src/errors/globalErrorHandler';
|
|
21
|
-
export type
|
|
18
|
+
export { type MayOmit } from './src/common/may-omit';
|
|
22
19
|
export { waitAndRetry } from './src/utils/waitUtils';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.waitAndRetry = exports.resolveGlobalErrorLogObject = exports.globalLogger = exports.executeSettleAllAndHandleGlobalErrors = exports.executeAndHandleGlobalErrors = exports.executeAsyncAndHandleGlobalErrors = exports.resolveLoggerConfiguration = exports.hasMessage = exports.isPublicNonRecoverableError = exports.isObject = exports.isStandardizedError = exports.isInternalError = exports.deepClone = exports.convertDateFieldsToIsoString = exports.isEmptyObject = exports.copyWithoutUndefined = exports.pickWithoutUndefined = exports.pick = exports.groupByUnique = exports.groupBy = exports.removeNullish = exports.removeFalsy = exports.callChunked = exports.chunk = exports.createRangeValidator = exports.ensureClosingSlashTransformer = exports.ConfigScope = exports.ResponseStatusError = exports.InternalError = exports.PublicNonRecoverableError = exports.buildClient = exports.httpClient = exports.sendPostBinary = exports.sendPost = exports.sendGet = exports.sendPatch = exports.sendDelete = exports.sendPutBinary = exports.sendPut = void 0;
|
|
3
|
+
exports.waitAndRetry = exports.resolveGlobalErrorLogObject = exports.globalLogger = exports.executeSettleAllAndHandleGlobalErrors = exports.executeAndHandleGlobalErrors = exports.executeAsyncAndHandleGlobalErrors = exports.resolveMonorepoLoggerConfiguration = exports.resolveLoggerConfiguration = exports.hasMessage = exports.isPublicNonRecoverableError = exports.isObject = exports.isStandardizedError = exports.isInternalError = exports.deepClone = exports.convertDateFieldsToIsoString = exports.isEmptyObject = exports.copyWithoutUndefined = exports.pickWithoutUndefined = exports.pick = exports.groupByUnique = exports.groupBy = exports.removeNullish = exports.removeFalsy = exports.callChunked = exports.chunk = exports.isFailure = exports.isSuccess = exports.failure = exports.success = exports.createRangeValidator = exports.ensureClosingSlashTransformer = exports.ConfigScope = exports.ResponseStatusError = exports.InternalError = exports.PublicNonRecoverableError = exports.buildClient = exports.httpClient = exports.sendPostBinary = exports.sendPost = exports.sendGet = exports.sendPatch = exports.sendDelete = exports.sendPutBinary = exports.sendPut = void 0;
|
|
4
4
|
var httpClient_1 = require("./src/http/httpClient");
|
|
5
5
|
Object.defineProperty(exports, "sendPut", { enumerable: true, get: function () { return httpClient_1.sendPut; } });
|
|
6
6
|
Object.defineProperty(exports, "sendPutBinary", { enumerable: true, get: function () { return httpClient_1.sendPutBinary; } });
|
|
@@ -23,6 +23,11 @@ var configTransformers_1 = require("./src/config/configTransformers");
|
|
|
23
23
|
Object.defineProperty(exports, "ensureClosingSlashTransformer", { enumerable: true, get: function () { return configTransformers_1.ensureClosingSlashTransformer; } });
|
|
24
24
|
var configValidators_1 = require("./src/config/configValidators");
|
|
25
25
|
Object.defineProperty(exports, "createRangeValidator", { enumerable: true, get: function () { return configValidators_1.createRangeValidator; } });
|
|
26
|
+
var either_1 = require("./src/errors/either");
|
|
27
|
+
Object.defineProperty(exports, "success", { enumerable: true, get: function () { return either_1.success; } });
|
|
28
|
+
Object.defineProperty(exports, "failure", { enumerable: true, get: function () { return either_1.failure; } });
|
|
29
|
+
Object.defineProperty(exports, "isSuccess", { enumerable: true, get: function () { return either_1.isSuccess; } });
|
|
30
|
+
Object.defineProperty(exports, "isFailure", { enumerable: true, get: function () { return either_1.isFailure; } });
|
|
26
31
|
var arrayUtils_1 = require("./src/utils/arrayUtils");
|
|
27
32
|
Object.defineProperty(exports, "chunk", { enumerable: true, get: function () { return arrayUtils_1.chunk; } });
|
|
28
33
|
Object.defineProperty(exports, "callChunked", { enumerable: true, get: function () { return arrayUtils_1.callChunked; } });
|
|
@@ -45,6 +50,7 @@ Object.defineProperty(exports, "isPublicNonRecoverableError", { enumerable: true
|
|
|
45
50
|
Object.defineProperty(exports, "hasMessage", { enumerable: true, get: function () { return typeUtils_1.hasMessage; } });
|
|
46
51
|
var loggerConfigResolver_1 = require("./src/logging/loggerConfigResolver");
|
|
47
52
|
Object.defineProperty(exports, "resolveLoggerConfiguration", { enumerable: true, get: function () { return loggerConfigResolver_1.resolveLoggerConfiguration; } });
|
|
53
|
+
Object.defineProperty(exports, "resolveMonorepoLoggerConfiguration", { enumerable: true, get: function () { return loggerConfigResolver_1.resolveMonorepoLoggerConfiguration; } });
|
|
48
54
|
var globalErrorHandler_1 = require("./src/errors/globalErrorHandler");
|
|
49
55
|
Object.defineProperty(exports, "executeAsyncAndHandleGlobalErrors", { enumerable: true, get: function () { return globalErrorHandler_1.executeAsyncAndHandleGlobalErrors; } });
|
|
50
56
|
Object.defineProperty(exports, "executeAndHandleGlobalErrors", { enumerable: true, get: function () { return globalErrorHandler_1.executeAndHandleGlobalErrors; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,oDAc8B;AAb5B,qGAAA,OAAO,OAAA;AACP,2GAAA,aAAa,OAAA;AACb,wGAAA,UAAU,OAAA;AACV,uGAAA,SAAS,OAAA;AACT,qGAAA,OAAO,OAAA;AACP,sGAAA,QAAQ,OAAA;AACR,4GAAA,cAAc,OAAA;AACd,wGAAA,UAAU,OAAA;AACV,yGAAA,WAAW,OAAA;AAOb,oFAG+C;AAF7C,sIAAA,yBAAyB,OAAA;AAI3B,4DAImC;AAHjC,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|
6
|
+
export type MonorepoAppLoggerConfig = AppLoggerConfig & {
|
|
7
|
+
targetFile?: string;
|
|
8
|
+
append?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function resolveMonorepoLoggerConfiguration(appConfig: MonorepoAppLoggerConfig): LoggerOptions;
|
|
6
11
|
export declare function resolveLoggerConfiguration(appConfig: AppLoggerConfig): LoggerOptions;
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveLoggerConfiguration = void 0;
|
|
3
|
+
exports.resolveLoggerConfiguration = exports.resolveMonorepoLoggerConfiguration = void 0;
|
|
4
|
+
// Note that transports do not work in vitest, likely because pino attempts to run them in a separate worker
|
|
5
|
+
/* c8 ignore next 24 */
|
|
6
|
+
function resolveMonorepoLoggerConfiguration(appConfig) {
|
|
7
|
+
if (appConfig.nodeEnv !== 'development') {
|
|
8
|
+
return resolveLoggerConfiguration(appConfig);
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
level: appConfig.logLevel,
|
|
12
|
+
formatters: {
|
|
13
|
+
level: (label) => {
|
|
14
|
+
return { level: label };
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
transport: {
|
|
18
|
+
target: 'pino/file',
|
|
19
|
+
options: {
|
|
20
|
+
destination: appConfig.targetFile ?? './service.log',
|
|
21
|
+
mkdir: true,
|
|
22
|
+
append: appConfig.append ?? false,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.resolveMonorepoLoggerConfiguration = resolveMonorepoLoggerConfiguration;
|
|
4
28
|
function resolveLoggerConfiguration(appConfig) {
|
|
5
29
|
const config = {
|
|
6
30
|
level: appConfig.logLevel,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loggerConfigResolver.js","sourceRoot":"","sources":["../../../src/logging/loggerConfigResolver.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"loggerConfigResolver.js","sourceRoot":"","sources":["../../../src/logging/loggerConfigResolver.ts"],"names":[],"mappings":";;;AAYA,4GAA4G;AAC5G,uBAAuB;AACvB,SAAgB,kCAAkC,CAChD,SAAkC;IAElC,IAAI,SAAS,CAAC,OAAO,KAAK,aAAa,EAAE,CAAC;QACxC,OAAO,0BAA0B,CAAC,SAAS,CAAC,CAAA;IAC9C,CAAC;IAED,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,QAAQ;QACzB,UAAU,EAAE;YACV,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBACf,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;YACzB,CAAC;SACF;QACD,SAAS,EAAE;YACT,MAAM,EAAE,WAAW;YACnB,OAAO,EAAE;gBACP,WAAW,EAAE,SAAS,CAAC,UAAU,IAAI,eAAe;gBACpD,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,SAAS,CAAC,MAAM,IAAI,KAAK;aAClC;SACF;KACF,CAAA;AACH,CAAC;AAvBD,gFAuBC;AAED,SAAgB,0BAA0B,CAAC,SAA0B;IACnE,MAAM,MAAM,GAAkB;QAC5B,KAAK,EAAE,SAAS,CAAC,QAAQ;QACzB,UAAU,EAAE;YACV,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBACf,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;YACzB,CAAC;SACF;KACF,CAAA;IACD,IAAI,SAAS,CAAC,OAAO,KAAK,YAAY,EAAE,CAAC;QACvC,MAAM,CAAC,SAAS,GAAG;YACjB,MAAM,EAAE,aAAa;YACrB,OAAO,EAAE;gBACP,QAAQ,EAAE,IAAI;gBACd,aAAa,EAAE,cAAc;gBAC7B,MAAM,EAAE,cAAc;aACvB;SACF,CAAA;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AApBD,gEAoBC"}
|