@crowdin/app-project-module 0.26.2 → 0.26.4

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
@@ -722,7 +722,8 @@ const configuration = {
722
722
  imagePath: __dirname + '/' + 'logo.png',
723
723
  profileResourcesMenu: {
724
724
  fileName: 'setup.html',
725
- uiPath: __dirname + '/' + 'public'
725
+ uiPath: __dirname + '/' + 'public',
726
+ environments: 'crowdin-enterprise',
726
727
  },
727
728
  };
728
729
 
@@ -748,7 +749,8 @@ const configuration = {
748
749
  imagePath: __dirname + '/' + 'logo.png',
749
750
  profileResourcesMenu: {
750
751
  fileName: 'setup.html',
751
- uiPath: __dirname + '/' + 'public'
752
+ uiPath: __dirname + '/' + 'public',
753
+ environments: 'crowdin',
752
754
  },
753
755
  customMT: {
754
756
  translate,
@@ -842,6 +844,16 @@ configuration.jwtValidationOptions = {
842
844
  configuration.authenticationType = 'authorization_code'; //default is "crowdin_app"
843
845
  ```
844
846
 
847
+ ### Disable global error handling
848
+
849
+ This module will handle all `unhandledRejection` and `uncaughtException` errors, log them and not kill the Node process.
850
+ Usually this means that code was not properly designed and contains unsafe places. And not always this built in behaviour will be suitable.
851
+ Therefore you can disable it:
852
+
853
+ ```js
854
+ configuration.disableGlobalErrorHandling = true;
855
+ ```
856
+
845
857
  ## Contributing
846
858
 
847
859
  If you want to contribute please read the [Contributing](/CONTRIBUTING.md) guidelines.
@@ -12,6 +12,7 @@ function handle(config) {
12
12
  description: config.description,
13
13
  logo: '/logo/integration/logo.png',
14
14
  url: '/',
15
+ environments: config.projectIntegration.environments,
15
16
  },
16
17
  ];
17
18
  }
@@ -36,6 +37,7 @@ function handle(config) {
36
37
  name: config.name,
37
38
  logo: '/logo/mt/logo.png',
38
39
  url: '/translate',
40
+ environments: config.customMT.environments,
39
41
  },
40
42
  ];
41
43
  }
@@ -56,6 +58,7 @@ function handle(config) {
56
58
  name: config.name,
57
59
  url: '/resources/' + (config.profileResourcesMenu.fileName || 'index.html'),
58
60
  icon: '/logo/resources/logo.png',
61
+ environments: config.profileResourcesMenu.environments,
59
62
  },
60
63
  ];
61
64
  }
@@ -66,6 +69,7 @@ function handle(config) {
66
69
  name: config.name,
67
70
  url: '/editor-panels/' + (config.editorRightPanel.fileName || 'index.html'),
68
71
  modes: config.editorRightPanel.modes,
72
+ environments: config.editorRightPanel.environments,
69
73
  },
70
74
  ];
71
75
  }
@@ -75,6 +79,7 @@ function handle(config) {
75
79
  key: config.identifier + '-project-menu',
76
80
  name: config.name,
77
81
  url: '/project-menu/' + (config.projectMenu.fileName || 'index.html'),
82
+ environments: config.projectMenu.environments,
78
83
  },
79
84
  ];
80
85
  }
@@ -95,6 +100,7 @@ function handle(config) {
95
100
  description: config.description,
96
101
  logo: '/logo/tools/logo.png',
97
102
  url: '/tools/' + (config.projectTools.fileName || 'index.html'),
103
+ environments: config.projectTools.environments,
98
104
  },
99
105
  ];
100
106
  }
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
+ }
@@ -67,7 +67,7 @@ export interface Config extends ImagePath {
67
67
  /**
68
68
  * integration module logic
69
69
  */
70
- projectIntegration?: IntegrationLogic & ImagePath;
70
+ projectIntegration?: IntegrationLogic & ImagePath & Environments;
71
71
  /**
72
72
  * custom file format module logic
73
73
  */
@@ -75,11 +75,11 @@ export interface Config extends ImagePath {
75
75
  /**
76
76
  * custom MT module logic
77
77
  */
78
- customMT?: CustomMTLogic & ImagePath;
78
+ customMT?: CustomMTLogic & ImagePath & Environments;
79
79
  /**
80
80
  * resources module
81
81
  */
82
- profileResourcesMenu?: UiModule & ImagePath;
82
+ profileResourcesMenu?: UiModule & ImagePath & Environments;
83
83
  /**
84
84
  * organization-menu module
85
85
  */
@@ -87,11 +87,11 @@ export interface Config extends ImagePath {
87
87
  /**
88
88
  * editor-right-panel module
89
89
  */
90
- editorRightPanel?: EditorPanels;
90
+ editorRightPanel?: EditorPanels & Environments;
91
91
  /**
92
92
  * project menu module
93
93
  */
94
- projectMenu?: UiModule;
94
+ projectMenu?: UiModule & Environments;
95
95
  /**
96
96
  * project menu crowdsource module
97
97
  */
@@ -99,7 +99,7 @@ export interface Config extends ImagePath {
99
99
  /**
100
100
  * tools module
101
101
  */
102
- projectTools?: UiModule & ImagePath;
102
+ projectTools?: UiModule & ImagePath & Environments;
103
103
  /**
104
104
  * reports module
105
105
  */
@@ -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
  */
@@ -346,6 +350,9 @@ export interface OAuthLogin {
346
350
  */
347
351
  performRefreshTokenRequest?: (currentCredentials: any) => Promise<any>;
348
352
  }
353
+ export interface Environments {
354
+ environments: 'crowdin' | 'crowdin-enterprise';
355
+ }
349
356
  export interface FormField {
350
357
  key: string;
351
358
  helpText?: string;
@@ -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.2",
3
+ "version": "0.26.4",
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",