@crowdin/app-project-module 0.26.3 → 0.26.5

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 CHANGED
@@ -650,6 +650,7 @@ const configuration = {
650
650
  filesFolder: __dirname,
651
651
  type: 'type-xyz',
652
652
  stringsExport: true,
653
+ multilingualExport: true,
653
654
  extensions: [
654
655
  '.resx'
655
656
  ],
@@ -844,6 +845,16 @@ configuration.jwtValidationOptions = {
844
845
  configuration.authenticationType = 'authorization_code'; //default is "crowdin_app"
845
846
  ```
846
847
 
848
+ ### Disable global error handling
849
+
850
+ This module will handle all `unhandledRejection` and `uncaughtException` errors, log them and not kill the Node process.
851
+ Usually this means that code was not properly designed and contains unsafe places. And not always this built in behaviour will be suitable.
852
+ Therefore you can disable it:
853
+
854
+ ```js
855
+ configuration.disableGlobalErrorHandling = true;
856
+ ```
857
+
847
858
  ## Contributing
848
859
 
849
860
  If you want to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines.
@@ -26,6 +26,7 @@ function handle(config) {
26
26
  customSrxSupported: !!config.customFileFormat.customSrxSupported,
27
27
  extensions: config.customFileFormat.extensions,
28
28
  signaturePatterns: config.customFileFormat.signaturePatterns,
29
+ multilingualExport: config.customFileFormat.multilingualExport,
29
30
  url: '/process',
30
31
  },
31
32
  ];
package/out/index.js CHANGED
@@ -63,12 +63,16 @@ const integration_credentials_1 = __importDefault(require("./middlewares/integra
63
63
  const json_response_1 = __importDefault(require("./middlewares/json-response"));
64
64
  const ui_module_1 = __importDefault(require("./middlewares/ui-module"));
65
65
  const storage = __importStar(require("./storage"));
66
+ const util_1 = require("./util");
66
67
  const connection_1 = require("./util/connection");
67
68
  const cron_1 = require("./util/cron");
68
69
  const defaults_1 = require("./util/defaults");
69
70
  var models_1 = require("./models");
70
71
  Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return models_1.Scope; } });
71
72
  function addCrowdinEndpoints(app, plainConfig) {
73
+ if (!plainConfig.disableGlobalErrorHandling) {
74
+ handleUncaughtErrors(plainConfig);
75
+ }
72
76
  const config = Object.assign(Object.assign({}, plainConfig), { baseUrl: plainConfig.baseUrl.endsWith('/') ? plainConfig.baseUrl.slice(0, -1) : plainConfig.baseUrl });
73
77
  storage.initialize(config);
74
78
  app.use(express_1.default.json({ limit: '50mb' }));
@@ -196,3 +200,14 @@ function createApp(config) {
196
200
  app.listen(config.port || 3000, () => console.log(`App started on port ${config.port || 3000}`));
197
201
  }
198
202
  exports.createApp = createApp;
203
+ function handleUncaughtErrors(config) {
204
+ process
205
+ .on('unhandledRejection', (reason) => {
206
+ const error = `Unhandled Rejection. Reason: ${reason.stack || reason}`;
207
+ (0, util_1.logError)(error, config.onError);
208
+ })
209
+ .on('uncaughtException', (reason) => {
210
+ const error = `Uncaught Exception. Reason: ${reason.stack || reason}`;
211
+ (0, util_1.logError)(error, config.onError);
212
+ });
213
+ }
@@ -115,6 +115,10 @@ export interface Config extends ImagePath {
115
115
  * Error interceptor (can be used to log error in centralized place)
116
116
  */
117
117
  onError?: (error: any) => void;
118
+ /**
119
+ * Disable global error handling of unhandledRejection and uncaughtException events
120
+ */
121
+ disableGlobalErrorHandling?: boolean;
118
122
  /**
119
123
  * Configuration to log everything that are happening in the app
120
124
  */
@@ -491,6 +495,10 @@ export interface CustomFileFormatLogic {
491
495
  * Enable custom srx
492
496
  */
493
497
  customSrxSupported?: boolean;
498
+ /**
499
+ * Enable multi language strings export
500
+ */
501
+ multilingualExport?: boolean;
494
502
  /**
495
503
  * Used for initial source file upload, source file update, and translation upload
496
504
  */
@@ -1,5 +1,5 @@
1
1
  import { Request, Response } from 'express';
2
- import { Config, Logger, ExtendedResult } from '../models';
2
+ import { Config, ExtendedResult, Logger } from '../models';
3
3
  export declare class CodeError extends Error {
4
4
  code: number | undefined;
5
5
  constructor(message: string, code?: number);
@@ -7,6 +7,7 @@ export declare class CodeError extends Error {
7
7
  export declare function log(message: string, logger?: Logger): void;
8
8
  export declare function getMessage(err: any): any;
9
9
  export declare function runAsyncWrapper(callback: Function, onError?: (e: any) => void): (req: Request, res: Response, next: Function) => void;
10
+ export declare function logError(e: any, onError?: (e: any) => void): void;
10
11
  export declare function encryptData(config: Config, data: string): string;
11
12
  export declare function decryptData(config: Config, data: string): string;
12
13
  export declare function executeWithRetry<T>(func: () => Promise<T>, numOfRetries?: number): Promise<T>;
package/out/util/index.js CHANGED
@@ -28,7 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
28
28
  });
29
29
  };
30
30
  Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.isExtendedResultType = exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.getMessage = exports.log = exports.CodeError = void 0;
31
+ exports.isExtendedResultType = exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.logError = exports.runAsyncWrapper = exports.getMessage = exports.log = exports.CodeError = void 0;
32
32
  const crypto = __importStar(require("crypto-js"));
33
33
  const storage_1 = require("../storage");
34
34
  class CodeError extends Error {
@@ -84,17 +84,21 @@ function handleError(err, req, res) {
84
84
  function runAsyncWrapper(callback, onError) {
85
85
  return (req, res, next) => {
86
86
  callback(req, res, next).catch((e) => {
87
- if (onError) {
88
- onError(e);
89
- }
90
- else {
91
- console.error(e);
92
- }
87
+ logError(e, onError);
93
88
  handleError(e, req, res);
94
89
  });
95
90
  };
96
91
  }
97
92
  exports.runAsyncWrapper = runAsyncWrapper;
93
+ function logError(e, onError) {
94
+ if (onError) {
95
+ onError(e);
96
+ }
97
+ else {
98
+ console.error(e);
99
+ }
100
+ }
101
+ exports.logError = logError;
98
102
  function encryptData(config, data) {
99
103
  return crypto.AES.encrypt(data, config.cryptoSecret || config.clientSecret).toString();
100
104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.26.3",
3
+ "version": "0.26.5",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",