@crowdin/app-project-module 1.16.0 → 2.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.
Files changed (99) hide show
  1. package/out/index.js +8 -15
  2. package/out/middlewares/auto-credentials-masker.js +5 -2
  3. package/out/middlewares/crowdin-client.d.ts +1 -1
  4. package/out/middlewares/crowdin-client.js +1 -1
  5. package/out/middlewares/export.d.ts +2 -2
  6. package/out/middlewares/export.js +4 -35
  7. package/out/middlewares/json-response.d.ts +1 -1
  8. package/out/middlewares/json-response.js +1 -1
  9. package/out/modules/ai-prompt-provider/index.js +6 -6
  10. package/out/modules/ai-provider/index.js +7 -7
  11. package/out/modules/ai-provider/types.d.ts +10 -0
  12. package/out/modules/ai-provider/types.js +12 -0
  13. package/out/modules/ai-provider/util/index.d.ts +0 -10
  14. package/out/modules/ai-provider/util/index.js +2 -13
  15. package/out/modules/ai-request-processors/index.js +4 -4
  16. package/out/modules/api/api.js +18 -18
  17. package/out/modules/auth-guard/index.js +4 -5
  18. package/out/modules/automation-action/index.js +4 -6
  19. package/out/modules/context-menu/index.js +4 -13
  20. package/out/modules/custom-mt/index.js +4 -4
  21. package/out/modules/custom-spell-check/index.js +11 -11
  22. package/out/modules/editor-right-panel/index.js +1 -1
  23. package/out/modules/external-qa-check/index.js +7 -7
  24. package/out/modules/file-processing/index.js +14 -14
  25. package/out/modules/integration/index.js +26 -26
  26. package/out/modules/integration/types.d.ts +4 -4
  27. package/out/modules/integration/util/files.js +1 -1
  28. package/out/modules/integration/util/types.d.ts +1 -1
  29. package/out/modules/manifest.js +70 -281
  30. package/out/modules/modal/index.js +4 -13
  31. package/out/modules/organization-menu/index.js +1 -1
  32. package/out/modules/organization-settings-menu/index.js +1 -1
  33. package/out/modules/profile-resources-menu/index.js +1 -1
  34. package/out/modules/profile-settings-menu/index.js +1 -1
  35. package/out/modules/project-menu/index.js +1 -1
  36. package/out/modules/project-menu-crowdsource/index.js +1 -1
  37. package/out/modules/project-reports/index.js +1 -1
  38. package/out/modules/project-tools/index.js +1 -1
  39. package/out/modules/webhooks/index.js +3 -6
  40. package/out/modules/workflow-step-type/index.js +6 -6
  41. package/out/storage/drizzle/d1/index.d.ts +7 -0
  42. package/out/storage/drizzle/d1/index.js +48 -0
  43. package/out/storage/drizzle/d1/migrations/init.d.ts +2 -0
  44. package/out/storage/drizzle/d1/migrations/init.js +122 -0
  45. package/out/storage/drizzle/d1/types.d.ts +13 -0
  46. package/out/storage/drizzle/d1/types.js +38 -0
  47. package/out/storage/{sqlite.d.ts → drizzle/index.d.ts} +37 -58
  48. package/out/storage/drizzle/index.js +939 -0
  49. package/out/storage/drizzle/postgresql/config.d.ts +5 -0
  50. package/out/storage/drizzle/postgresql/config.js +11 -0
  51. package/out/storage/drizzle/postgresql/index.d.ts +14 -0
  52. package/out/storage/drizzle/postgresql/index.js +144 -0
  53. package/out/storage/drizzle/postgresql/migrations/0000_init.sql +113 -0
  54. package/out/storage/drizzle/postgresql/migrations/0001_init_indexes.sql +28 -0
  55. package/out/storage/drizzle/postgresql/migrations/meta/0000_snapshot.json +646 -0
  56. package/out/storage/drizzle/postgresql/migrations/meta/0001_snapshot.json +646 -0
  57. package/out/storage/drizzle/postgresql/migrations/meta/_journal.json +20 -0
  58. package/out/storage/drizzle/postgresql/schema.d.ts +1410 -0
  59. package/out/storage/drizzle/postgresql/schema.js +106 -0
  60. package/out/storage/drizzle/sqlite/config.d.ts +5 -0
  61. package/out/storage/drizzle/sqlite/config.js +11 -0
  62. package/out/storage/drizzle/sqlite/index.d.ts +8 -0
  63. package/out/storage/drizzle/sqlite/index.js +63 -0
  64. package/out/storage/drizzle/sqlite/migrations/0000_init.sql +113 -0
  65. package/out/storage/drizzle/sqlite/migrations/meta/0000_snapshot.json +687 -0
  66. package/out/storage/drizzle/sqlite/migrations/meta/_journal.json +13 -0
  67. package/out/storage/drizzle/sqlite/schema.d.ts +1544 -0
  68. package/out/storage/drizzle/sqlite/schema.js +106 -0
  69. package/out/storage/index.d.ts +2 -88
  70. package/out/storage/index.js +12 -128
  71. package/out/storage/internal/backup.d.ts +3 -0
  72. package/out/storage/internal/backup.js +94 -0
  73. package/out/storage/types.d.ts +66 -0
  74. package/out/types.d.ts +43 -47
  75. package/out/util/credentials-masker.js +2 -2
  76. package/out/util/export.d.ts +1 -0
  77. package/out/util/export.js +2 -1
  78. package/out/util/index.d.ts +2 -1
  79. package/out/util/index.js +12 -9
  80. package/out/util/normalize-module.d.ts +0 -1
  81. package/out/util/normalize-module.js +0 -4
  82. package/package.json +18 -22
  83. package/out/modules/ai-tools/handlers/tool-calls.d.ts +0 -4
  84. package/out/modules/ai-tools/handlers/tool-calls.js +0 -52
  85. package/out/modules/ai-tools/index.d.ts +0 -10
  86. package/out/modules/ai-tools/index.js +0 -46
  87. package/out/modules/ai-tools/types.d.ts +0 -63
  88. package/out/modules/ai-tools/types.js +0 -2
  89. package/out/modules/ai-tools/util/index.d.ts +0 -5
  90. package/out/modules/ai-tools/util/index.js +0 -24
  91. package/out/storage/d1.d.ts +0 -107
  92. package/out/storage/d1.js +0 -837
  93. package/out/storage/export.d.ts +0 -1
  94. package/out/storage/export.js +0 -2
  95. package/out/storage/mysql.d.ts +0 -109
  96. package/out/storage/mysql.js +0 -984
  97. package/out/storage/postgre.d.ts +0 -124
  98. package/out/storage/postgre.js +0 -1027
  99. package/out/storage/sqlite.js +0 -786
package/out/index.js CHANGED
@@ -54,8 +54,8 @@ exports.addCrowdinEndpoints = addCrowdinEndpoints;
54
54
  const logsFormatter = __importStar(require("@crowdin/logs-formatter"));
55
55
  const express_rate_limit_1 = require("express-rate-limit");
56
56
  const path_1 = require("path");
57
- const crowdin_client_1 = __importStar(require("./middlewares/crowdin-client"));
58
- const json_response_1 = __importDefault(require("./middlewares/json-response"));
57
+ const crowdin_client_1 = require("./middlewares/crowdin-client");
58
+ const json_response_1 = require("./middlewares/json-response");
59
59
  const form_data_display_1 = __importDefault(require("./modules/form-data-display"));
60
60
  const form_data_save_1 = __importDefault(require("./modules/form-data-save"));
61
61
  const install_1 = __importDefault(require("./modules/install"));
@@ -65,7 +65,6 @@ const subscription_paid_1 = __importDefault(require("./modules/subscription-paid
65
65
  const uninstall_1 = __importDefault(require("./modules/uninstall"));
66
66
  const status_1 = __importDefault(require("./modules/status"));
67
67
  const storage = __importStar(require("./storage"));
68
- const d1_1 = require("./storage/d1");
69
68
  const cron = __importStar(require("./util/cron"));
70
69
  const types_1 = require("./types");
71
70
  const util_1 = require("./util");
@@ -90,7 +89,6 @@ const customMTApp = __importStar(require("./modules/custom-mt"));
90
89
  const spellCheckApp = __importStar(require("./modules/custom-spell-check"));
91
90
  const aiProvider = __importStar(require("./modules/ai-provider"));
92
91
  const aiPromptProvider = __importStar(require("./modules/ai-prompt-provider"));
93
- const aiTools = __importStar(require("./modules/ai-tools"));
94
92
  const editorRightPanelApp = __importStar(require("./modules/editor-right-panel"));
95
93
  const externalQaCheck = __importStar(require("./modules/external-qa-check"));
96
94
  const fileProcessingApps = __importStar(require("./modules/file-processing"));
@@ -158,13 +156,10 @@ function addCrowdinEndpoints(app, clientConfig) {
158
156
  logger.initialize(config);
159
157
  storage.initialize(config);
160
158
  cron.initialize(config);
161
- // Middleware to ensure D1 migration before handling requests
159
+ // Middleware to ensure delayed migration before handling requests
162
160
  app.use((req, res, next) => __awaiter(this, void 0, void 0, function* () {
163
161
  try {
164
- const storageInstance = storage.getStorage();
165
- if (storageInstance instanceof d1_1.D1Storage) {
166
- yield storageInstance.ensureMigrated();
167
- }
162
+ yield storage.getStorage().migrateDelayed();
168
163
  next();
169
164
  }
170
165
  catch (error) {
@@ -194,7 +189,7 @@ function addCrowdinEndpoints(app, clientConfig) {
194
189
  }
195
190
  app.use('/assets', (0, static_files_1.serveStatic)(config, config.assetsPath || 'static'));
196
191
  app.use('/', (0, util_2.serveLogo)(config));
197
- app.get('/manifest.json', json_response_1.default, (0, manifest_1.default)(config));
192
+ app.get('/manifest.json', json_response_1.handle, (0, manifest_1.default)(config));
198
193
  app.get('/', (0, about_1.default)(config));
199
194
  if (((_a = config === null || config === void 0 ? void 0 : config.enableStatusPage) === null || _a === void 0 ? void 0 : _a.database) || ((_b = config === null || config === void 0 ? void 0 : config.enableStatusPage) === null || _b === void 0 ? void 0 : _b.filesystem)) {
200
195
  app.set('trust proxy', 1);
@@ -261,8 +256,6 @@ function addCrowdinEndpoints(app, clientConfig) {
261
256
  apiApp.register({ config, app });
262
257
  aiProvider.register({ config, app });
263
258
  aiPromptProvider.register({ config, app });
264
- aiTools.registerAiTools({ config, app });
265
- aiTools.registerAiToolWidgets({ config, app });
266
259
  externalQaCheck.register({ config, app });
267
260
  webhooks.register({ config, app });
268
261
  workflowStepType.register({ config, app });
@@ -299,7 +292,7 @@ function addCrowdinEndpoints(app, clientConfig) {
299
292
  return { client, extra };
300
293
  }), jwtMiddleware: (options) => {
301
294
  var _a, _b;
302
- return (0, crowdin_client_1.default)({
295
+ return (0, crowdin_client_1.handle)({
303
296
  config,
304
297
  optional: (_a = options.optional) !== null && _a !== void 0 ? _a : false,
305
298
  checkSubscriptionExpiration: (_b = options.checkSubscriptionExpiration) !== null && _b !== void 0 ? _b : false,
@@ -323,7 +316,7 @@ function addFormSchema({ app, config }) {
323
316
  const moduleConfigWithForm = (0, form_schema_1.getLowCodeUiConfigFromModuleConfig)(moduleConfig);
324
317
  if (moduleConfigWithForm) {
325
318
  if (!moduleConfigWithForm.formGetDataUrl) {
326
- app.get(`/api/${moduleConfigWithForm.key}/form-data`, json_response_1.default, (0, crowdin_client_1.default)({
319
+ app.get(`/api/${moduleConfigWithForm.key}/form-data`, json_response_1.handle, (0, crowdin_client_1.handle)({
327
320
  config,
328
321
  optional: false,
329
322
  checkSubscriptionExpiration: true,
@@ -331,7 +324,7 @@ function addFormSchema({ app, config }) {
331
324
  }), (0, credentials_masker_1.getRequestCredentialsMasker)({ moduleConfig: moduleConfigWithForm }), (0, form_data_display_1.default)(config));
332
325
  }
333
326
  if (!moduleConfigWithForm.formPostDataUrl) {
334
- app.post(`/api/${moduleConfigWithForm.key}/form-data`, (0, crowdin_client_1.default)({
327
+ app.post(`/api/${moduleConfigWithForm.key}/form-data`, (0, crowdin_client_1.handle)({
335
328
  config,
336
329
  optional: false,
337
330
  checkSubscriptionExpiration: true,
@@ -13,8 +13,11 @@ function autoCredentialsMaskerMiddleware(config) {
13
13
  }
14
14
  const requestPath = req.path;
15
15
  const requestMethod = req.method.toLowerCase();
16
- for (const moduleKey of Object.keys(config)) {
17
- const moduleConfig = config[moduleKey];
16
+ const moduleConfigs = Object.keys(config).flatMap((moduleKey) => {
17
+ const value = config[moduleKey];
18
+ return Array.isArray(value) ? value : [value];
19
+ });
20
+ for (const moduleConfig of moduleConfigs) {
18
21
  if ((0, form_schema_1.hasFormSchema)(moduleConfig)) {
19
22
  const moduleConfigWithForm = (0, form_schema_1.getLowCodeUiConfigFromModuleConfig)(moduleConfig);
20
23
  if (moduleConfigWithForm) {
@@ -15,7 +15,7 @@ export declare function prepareCrowdinRequest({ jwtToken, config, optional, chec
15
15
  client?: Crowdin;
16
16
  subscriptionInfo?: SubscriptionInfo;
17
17
  }>;
18
- export default function handle({ config, optional, checkSubscriptionExpiration, moduleKey, isIntegration, isLogout, }: {
18
+ export declare function handle({ config, optional, checkSubscriptionExpiration, moduleKey, isIntegration, isLogout, }: {
19
19
  config: Config;
20
20
  optional: boolean;
21
21
  checkSubscriptionExpiration: boolean;
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.prepareCrowdinRequest = prepareCrowdinRequest;
13
- exports.default = handle;
13
+ exports.handle = handle;
14
14
  exports.getToken = getToken;
15
15
  const api_1 = require("../modules/api/api");
16
16
  const storage_1 = require("../storage");
@@ -1,2 +1,2 @@
1
- export { getToken } from './crowdin-client';
2
- export * as jsonResponse from './json-response';
1
+ export { handle as crowdinClient, getToken } from './crowdin-client';
2
+ export { handle as jsonResponse } from './json-response';
@@ -1,39 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.jsonResponse = exports.getToken = void 0;
3
+ exports.jsonResponse = exports.getToken = exports.crowdinClient = void 0;
37
4
  var crowdin_client_1 = require("./crowdin-client");
5
+ Object.defineProperty(exports, "crowdinClient", { enumerable: true, get: function () { return crowdin_client_1.handle; } });
38
6
  Object.defineProperty(exports, "getToken", { enumerable: true, get: function () { return crowdin_client_1.getToken; } });
39
- exports.jsonResponse = __importStar(require("./json-response"));
7
+ var json_response_1 = require("./json-response");
8
+ Object.defineProperty(exports, "jsonResponse", { enumerable: true, get: function () { return json_response_1.handle; } });
@@ -1,2 +1,2 @@
1
1
  import { Request, Response } from 'express';
2
- export default function handle(_req: Request, res: Response, next: Function): void;
2
+ export declare function handle(_req: Request, res: Response, next: Function): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = handle;
3
+ exports.handle = handle;
4
4
  function handle(_req, res, next) {
5
5
  res.header('Content-Type', 'application/json');
6
6
  next();
@@ -4,20 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.register = register;
7
- const json_response_1 = __importDefault(require("../../middlewares/json-response"));
7
+ const json_response_1 = require("../../middlewares/json-response");
8
8
  const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
9
9
  const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
10
10
  const util_1 = require("../../util");
11
- const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
11
+ const crowdin_client_1 = require("../../middlewares/crowdin-client");
12
12
  const compile_1 = __importDefault(require("./handlers/compile"));
13
- const status_1 = __importDefault(require("./handlers/status"));
14
13
  const normalize_module_1 = require("../../util/normalize-module");
14
+ const status_1 = __importDefault(require("./handlers/status"));
15
15
  function register({ config, app }) {
16
16
  var _a;
17
17
  if (!config.aiPromptProvider) {
18
18
  return;
19
19
  }
20
- const items = (0, normalize_module_1.normalizeToArray)(config.aiPromptProvider);
20
+ const items = config.aiPromptProvider;
21
21
  const isSingle = items.length === 1;
22
22
  for (const [index, provider] of items.entries()) {
23
23
  const key = (_a = provider.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({
@@ -29,14 +29,14 @@ function register({ config, app }) {
29
29
  });
30
30
  const base = isSingle ? '/prompt-provider' : `/prompt-provider/${key}`;
31
31
  const logoPath = isSingle ? '/logo/ai-prompt-provider' : `/logo/ai-prompt-provider-${key}`;
32
- app.post(`${base}/compile`, json_response_1.default, (0, crowdin_client_1.default)({
32
+ app.post(`${base}/compile`, json_response_1.handle, (0, crowdin_client_1.handle)({
33
33
  config,
34
34
  optional: false,
35
35
  checkSubscriptionExpiration: true,
36
36
  moduleKey: key,
37
37
  }), (0, compile_1.default)(provider));
38
38
  if (provider.status) {
39
- app.post(`${base}/status`, json_response_1.default, (0, crowdin_client_1.default)({
39
+ app.post(`${base}/status`, json_response_1.handle, (0, crowdin_client_1.handle)({
40
40
  config,
41
41
  optional: false,
42
42
  checkSubscriptionExpiration: true,
@@ -4,20 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.register = register;
7
- const json_response_1 = __importDefault(require("../../middlewares/json-response"));
7
+ const json_response_1 = require("../../middlewares/json-response");
8
8
  const get_model_list_1 = __importDefault(require("./handlers/get-model-list"));
9
9
  const chat_completions_1 = __importDefault(require("./handlers/chat-completions"));
10
10
  const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
11
11
  const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
12
12
  const util_1 = require("../../util");
13
- const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
13
+ const crowdin_client_1 = require("../../middlewares/crowdin-client");
14
14
  const normalize_module_1 = require("../../util/normalize-module");
15
15
  function register({ config, app }) {
16
16
  var _a;
17
17
  if (!config.aiProvider) {
18
18
  return;
19
19
  }
20
- const items = (0, normalize_module_1.normalizeToArray)(config.aiProvider);
20
+ const items = config.aiProvider;
21
21
  const isSingle = items.length === 1;
22
22
  for (const [index, provider] of items.entries()) {
23
23
  const key = (_a = provider.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({
@@ -34,13 +34,13 @@ function register({ config, app }) {
34
34
  app.use(`/settings${settingsBase}`, (0, ui_module_1.default)({ config, allowUnauthorized: true, moduleType: key }), (0, render_ui_module_1.default)(provider.settingsUiModule, config));
35
35
  }
36
36
  app.use(logoPath, (0, util_1.serveLogo)(config, provider));
37
- app.get(`${base}/models`, json_response_1.default, (0, crowdin_client_1.default)({
37
+ app.get(`${base}/models`, json_response_1.handle, (0, crowdin_client_1.handle)({
38
38
  config,
39
39
  optional: false,
40
40
  checkSubscriptionExpiration: true,
41
41
  moduleKey: key,
42
42
  }), (0, get_model_list_1.default)(provider));
43
- app.post(`${base}/completions`, json_response_1.default, (0, crowdin_client_1.default)({
43
+ app.post(`${base}/completions`, json_response_1.handle, (0, crowdin_client_1.handle)({
44
44
  config,
45
45
  optional: false,
46
46
  checkSubscriptionExpiration: true,
@@ -50,12 +50,12 @@ function register({ config, app }) {
50
50
  if (isSingle) {
51
51
  const provider = items[0];
52
52
  // TEMPORARY CODE: it needs to support old path
53
- app.get('/models', json_response_1.default, (0, crowdin_client_1.default)({
53
+ app.get('/models', json_response_1.handle, (0, crowdin_client_1.handle)({
54
54
  config,
55
55
  optional: false,
56
56
  checkSubscriptionExpiration: true,
57
57
  }), (0, get_model_list_1.default)(provider));
58
- app.post('/completions', json_response_1.default, (0, crowdin_client_1.default)({
58
+ app.post('/completions', json_response_1.handle, (0, crowdin_client_1.handle)({
59
59
  config,
60
60
  optional: false,
61
61
  checkSubscriptionExpiration: true,
@@ -1,6 +1,16 @@
1
1
  import { CrowdinClientRequest, CrowdinContextInfo, Environments, ModuleKey, UiModule } from '../../types';
2
2
  import Crowdin from '@crowdin/crowdin-api-client';
3
3
  import { ExtendedResult } from '../integration/types';
4
+ import { AppModuleAggregateError } from '../../util/logger';
5
+ export declare const HTTP_RATE_LIMIT = 429;
6
+ export interface RateLimitErrorOptions {
7
+ error?: Error;
8
+ message?: string;
9
+ }
10
+ export declare class RateLimitError extends AppModuleAggregateError {
11
+ readonly status = 429;
12
+ constructor({ error, message }?: RateLimitErrorOptions);
13
+ }
4
14
  export interface AiProviderModule extends Environments, ModuleKey {
5
15
  /**
6
16
  * module name
@@ -1,2 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RateLimitError = exports.HTTP_RATE_LIMIT = void 0;
4
+ const logger_1 = require("../../util/logger");
5
+ exports.HTTP_RATE_LIMIT = 429;
6
+ class RateLimitError extends logger_1.AppModuleAggregateError {
7
+ constructor({ error, message } = {}) {
8
+ const newMessage = message || 'Rate limit reached';
9
+ super([error || new Error(newMessage)], newMessage);
10
+ this.status = exports.HTTP_RATE_LIMIT;
11
+ this.name = 'RateLimitError';
12
+ }
13
+ }
14
+ exports.RateLimitError = RateLimitError;
@@ -1,16 +1,6 @@
1
- import { AppModuleAggregateError } from '../../../util/logger';
2
1
  import { ChatCompletionChunkMessage, ChatCompletionContentPart, ChatCompletionMessage, ChatCompletionMessageToolCall, ChatCompletionResponseMessage, InputContentPart, InputMessage } from '../types';
3
- interface RateLimitErrorOptions {
4
- error?: Error;
5
- message?: string;
6
- }
7
2
  export declare function isRateLimitError(e: any): boolean;
8
- export declare class RateLimitError extends AppModuleAggregateError {
9
- readonly status = 429;
10
- constructor({ error, message }?: RateLimitErrorOptions);
11
- }
12
3
  export declare function normalizeContentParts(content: string | InputContentPart[]): string | ChatCompletionContentPart[];
13
4
  export declare function inputMessageToChatCompletionMessage(message: InputMessage): ChatCompletionMessage;
14
5
  export declare function mergeToolCalls(chunks: ChatCompletionChunkMessage[]): ChatCompletionMessageToolCall[] | null;
15
6
  export declare function mergeChatCompletionChunks(chunks: ChatCompletionChunkMessage[]): ChatCompletionResponseMessage[];
16
- export {};
@@ -1,28 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RateLimitError = void 0;
4
3
  exports.isRateLimitError = isRateLimitError;
5
4
  exports.normalizeContentParts = normalizeContentParts;
6
5
  exports.inputMessageToChatCompletionMessage = inputMessageToChatCompletionMessage;
7
6
  exports.mergeToolCalls = mergeToolCalls;
8
7
  exports.mergeChatCompletionChunks = mergeChatCompletionChunks;
9
- const logger_1 = require("../../../util/logger");
10
- const HTTP_RATE_LIMIT = 429;
8
+ const types_1 = require("../types");
11
9
  function isRateLimitError(e) {
12
10
  if (!e || typeof e !== 'object') {
13
11
  return false;
14
12
  }
15
- return ('status' in e && e.status === HTTP_RATE_LIMIT) || ('code' in e && e.code === HTTP_RATE_LIMIT);
13
+ return ('status' in e && e.status === types_1.HTTP_RATE_LIMIT) || ('code' in e && e.code === types_1.HTTP_RATE_LIMIT);
16
14
  }
17
- class RateLimitError extends logger_1.AppModuleAggregateError {
18
- constructor({ error, message } = {}) {
19
- const newMessage = message || 'Rate limit reached';
20
- super([error || new Error(newMessage)], newMessage);
21
- this.status = HTTP_RATE_LIMIT;
22
- this.name = 'RateLimitError';
23
- }
24
- }
25
- exports.RateLimitError = RateLimitError;
26
15
  function normalizeContentParts(content) {
27
16
  return Array.isArray(content)
28
17
  ? content.map((part) => part.type === 'image'
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.AiRequestProcessorModuleWithoutStream = exports.AiRequestProcessorModuleWithStream = void 0;
7
7
  exports.generateModuleSlugFromType = generateModuleSlugFromType;
8
8
  exports.register = register;
9
- const json_response_1 = __importDefault(require("../../middlewares/json-response"));
10
- const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
9
+ const json_response_1 = require("../../middlewares/json-response");
10
+ const crowdin_client_1 = require("../../middlewares/crowdin-client");
11
11
  const normalize_module_1 = require("../../util/normalize-module");
12
12
  const handler_1 = __importDefault(require("./handler"));
13
13
  var AiRequestProcessorModuleWithStream;
@@ -33,13 +33,13 @@ function registerProcessorModuleByTypeKey(moduleKey, { config, app }) {
33
33
  return;
34
34
  }
35
35
  const moduleSlug = generateModuleSlugFromType(moduleKey);
36
- const items = (0, normalize_module_1.normalizeToArray)(moduleValue);
36
+ const items = moduleValue;
37
37
  const isSingle = items.length === 1;
38
38
  const isStream = moduleKey in AiRequestProcessorModuleWithStream;
39
39
  for (const [index, module] of items.entries()) {
40
40
  const key = (_a = module.key) !== null && _a !== void 0 ? _a : (0, normalize_module_1.resolveInstanceKey)({ identifier: config.identifier, suffix: moduleSlug, item: module, index, isSingle });
41
41
  const url = isSingle ? '/ai-request-processor/' + moduleSlug : `/ai-request-processor/${moduleSlug}/${key}`;
42
- app.post(url, json_response_1.default, (0, crowdin_client_1.default)({
42
+ app.post(url, json_response_1.handle, (0, crowdin_client_1.handle)({
43
43
  config,
44
44
  optional: false,
45
45
  checkSubscriptionExpiration: true,
@@ -9,9 +9,9 @@ exports.addDefaultApiEndpoints = addDefaultApiEndpoints;
9
9
  exports.addSwagerApiDocumentation = addSwagerApiDocumentation;
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
12
- const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
12
+ const crowdin_client_1 = require("../../middlewares/crowdin-client");
13
13
  const integration_credentials_1 = __importDefault(require("../../middlewares/integration-credentials"));
14
- const json_response_1 = __importDefault(require("../../middlewares/json-response"));
14
+ const json_response_1 = require("../../middlewares/json-response");
15
15
  const api_call_1 = __importDefault(require("../../middlewares/api-call"));
16
16
  const redoc_html_template_1 = __importDefault(require("./redoc-helper/redoc-html-template"));
17
17
  const crowdin_file_progress_1 = __importDefault(require("../integration/handlers/crowdin-file-progress"));
@@ -212,7 +212,7 @@ function addDefaultApiEndpoints(app, config) {
212
212
  * data:
213
213
  * $ref: '#/components/schemas/CrowdinFiles'
214
214
  */
215
- app.get('/crowdin-files', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
215
+ app.get('/crowdin-files', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
216
216
  config,
217
217
  optional: false,
218
218
  checkSubscriptionExpiration: true,
@@ -289,7 +289,7 @@ function addDefaultApiEndpoints(app, config) {
289
289
  * passed: 0
290
290
  * failed: 0
291
291
  */
292
- app.get('/file-progress', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
292
+ app.get('/file-progress', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
293
293
  config,
294
294
  optional: false,
295
295
  checkSubscriptionExpiration: true,
@@ -352,7 +352,7 @@ function addDefaultApiEndpoints(app, config) {
352
352
  * message: null
353
353
  *
354
354
  */
355
- app.get('/integration-files', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
355
+ app.get('/integration-files', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
356
356
  config,
357
357
  optional: false,
358
358
  checkSubscriptionExpiration: true,
@@ -380,7 +380,7 @@ function addDefaultApiEndpoints(app, config) {
380
380
  * data:
381
381
  * $ref: '#/components/schemas/UpdateResponse'
382
382
  */
383
- app.post('/crowdin-update', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
383
+ app.post('/crowdin-update', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
384
384
  config,
385
385
  optional: false,
386
386
  checkSubscriptionExpiration: true,
@@ -408,7 +408,7 @@ function addDefaultApiEndpoints(app, config) {
408
408
  * data:
409
409
  * $ref: '#/components/schemas/UpdateResponse'
410
410
  */
411
- app.post('/integration-update', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
411
+ app.post('/integration-update', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
412
412
  config,
413
413
  optional: false,
414
414
  checkSubscriptionExpiration: true,
@@ -452,7 +452,7 @@ function addDefaultApiEndpoints(app, config) {
452
452
  * schema:
453
453
  * $ref: '#/components/schemas/JobListResponse'
454
454
  */
455
- app.get('/all-jobs', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
455
+ app.get('/all-jobs', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
456
456
  config,
457
457
  optional: false,
458
458
  checkSubscriptionExpiration: true,
@@ -496,7 +496,7 @@ function addDefaultApiEndpoints(app, config) {
496
496
  * schema:
497
497
  * $ref: '#/components/schemas/ErrorResponse'
498
498
  */
499
- app.get('/job-info', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
499
+ app.get('/job-info', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
500
500
  config,
501
501
  optional: false,
502
502
  checkSubscriptionExpiration: true,
@@ -527,7 +527,7 @@ function addDefaultApiEndpoints(app, config) {
527
527
  * schema:
528
528
  * $ref: '#/components/schemas/JobResponse'
529
529
  */
530
- app.get('/jobs', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
530
+ app.get('/jobs', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
531
531
  config,
532
532
  optional: false,
533
533
  checkSubscriptionExpiration: true,
@@ -567,7 +567,7 @@ function addDefaultApiEndpoints(app, config) {
567
567
  * schema:
568
568
  * $ref: '#/components/schemas/ErrorResponse'
569
569
  */
570
- app.delete('/jobs', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
570
+ app.delete('/jobs', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
571
571
  config,
572
572
  optional: false,
573
573
  checkSubscriptionExpiration: true,
@@ -629,7 +629,7 @@ function addDefaultApiEndpoints(app, config) {
629
629
  * position: 3
630
630
  * helpTextHtml: '<p><strong>What is In-Context?</strong></p>...'
631
631
  */
632
- app.get('/settings/schema', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
632
+ app.get('/settings/schema', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
633
633
  config,
634
634
  optional: false,
635
635
  checkSubscriptionExpiration: true,
@@ -669,7 +669,7 @@ function addDefaultApiEndpoints(app, config) {
669
669
  * excludeByFilePath: '/drafts/**'
670
670
  * skipIntegrationNodesToggle: true
671
671
  */
672
- app.get('/settings', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
672
+ app.get('/settings', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
673
673
  config,
674
674
  optional: false,
675
675
  checkSubscriptionExpiration: true,
@@ -727,7 +727,7 @@ function addDefaultApiEndpoints(app, config) {
727
727
  * error:
728
728
  * message: 'Invalid configuration keys: unknownKey. Use GET /settings/schema to see available fields.'
729
729
  */
730
- app.post('/settings', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
730
+ app.post('/settings', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
731
731
  config,
732
732
  optional: false,
733
733
  checkSubscriptionExpiration: true,
@@ -816,7 +816,7 @@ function addDefaultApiEndpoints(app, config) {
816
816
  * error:
817
817
  * message: 'Invalid provider. Must be one of: crowdin, integration'
818
818
  */
819
- app.get('/sync-settings', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
819
+ app.get('/sync-settings', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
820
820
  config,
821
821
  optional: false,
822
822
  checkSubscriptionExpiration: true,
@@ -896,7 +896,7 @@ function addDefaultApiEndpoints(app, config) {
896
896
  * error:
897
897
  * message: 'Invalid provider. Must be one of: crowdin, integration'
898
898
  */
899
- app.post('/sync-settings', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
899
+ app.post('/sync-settings', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
900
900
  config,
901
901
  optional: false,
902
902
  checkSubscriptionExpiration: true,
@@ -921,7 +921,7 @@ function addDefaultApiEndpoints(app, config) {
921
921
  * data:
922
922
  * $ref: '#/components/schemas/LoginFieldsResponse'
923
923
  */
924
- app.get('/login-fields', api_call_1.default, json_response_1.default, (req, res) => {
924
+ app.get('/login-fields', api_call_1.default, json_response_1.handle, (req, res) => {
925
925
  var _a, _b;
926
926
  let fields = [];
927
927
  if ((_b = (_a = config.projectIntegration) === null || _a === void 0 ? void 0 : _a.loginForm) === null || _b === void 0 ? void 0 : _b.fields) {
@@ -946,7 +946,7 @@ function addDefaultApiEndpoints(app, config) {
946
946
  * 204:
947
947
  * description: 'Login successful'
948
948
  */
949
- app.post('/login', api_call_1.default, json_response_1.default, (0, crowdin_client_1.default)({
949
+ app.post('/login', api_call_1.default, json_response_1.handle, (0, crowdin_client_1.handle)({
950
950
  config,
951
951
  optional: false,
952
952
  checkSubscriptionExpiration: false,
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.register = register;
7
- const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
8
- const json_response_1 = __importDefault(require("../../middlewares/json-response"));
7
+ const crowdin_client_1 = require("../../middlewares/crowdin-client");
8
+ const json_response_1 = require("../../middlewares/json-response");
9
9
  const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
10
10
  const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
11
11
  const verify_1 = __importDefault(require("./handlers/verify"));
@@ -13,8 +13,7 @@ function register({ config, app }) {
13
13
  if (!config.authGuard) {
14
14
  return;
15
15
  }
16
- // Normalize to array
17
- const authGuardModules = Array.isArray(config.authGuard) ? config.authGuard : [config.authGuard];
16
+ const authGuardModules = config.authGuard;
18
17
  if (!authGuardModules.length) {
19
18
  return;
20
19
  }
@@ -26,7 +25,7 @@ function register({ config, app }) {
26
25
  }
27
26
  });
28
27
  // Register verification endpoint
29
- app.post('/auth-guard/verify', json_response_1.default, (0, crowdin_client_1.default)({
28
+ app.post('/auth-guard/verify', json_response_1.handle, (0, crowdin_client_1.handle)({
30
29
  config,
31
30
  optional: false,
32
31
  checkSubscriptionExpiration: false,
@@ -10,28 +10,26 @@ const input_schema_1 = __importDefault(require("./handlers/input-schema"));
10
10
  const validate_settings_1 = __importDefault(require("./handlers/validate-settings"));
11
11
  const execute_1 = __importDefault(require("./handlers/execute"));
12
12
  const util_1 = require("./util");
13
- const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
13
+ const crowdin_client_1 = require("../../middlewares/crowdin-client");
14
14
  const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
15
15
  const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
16
16
  function register({ config, app }) {
17
17
  if (!config.automationAction) {
18
18
  return;
19
19
  }
20
- const automationActions = Array.isArray(config.automationAction)
21
- ? config.automationAction
22
- : [config.automationAction];
20
+ const automationActions = config.automationAction;
23
21
  for (const automationAction of automationActions) {
24
22
  app.options((0, util_1.getAutomationActionUrl)('/automation-action/output-schema', automationAction), (0, cors_1.default)());
25
23
  app.get((0, util_1.getAutomationActionUrl)('/automation-action/output-schema', automationAction), (0, cors_1.default)(), (0, output_schema_1.default)(automationAction));
26
24
  app.options((0, util_1.getAutomationActionUrl)('/automation-action/input-schema', automationAction), (0, cors_1.default)());
27
25
  app.get((0, util_1.getAutomationActionUrl)('/automation-action/input-schema', automationAction), (0, cors_1.default)(), (0, input_schema_1.default)(automationAction));
28
- app.post((0, util_1.getAutomationActionUrl)('/automation-action/validate-settings', automationAction), (0, crowdin_client_1.default)({
26
+ app.post((0, util_1.getAutomationActionUrl)('/automation-action/validate-settings', automationAction), (0, crowdin_client_1.handle)({
29
27
  config,
30
28
  optional: true,
31
29
  checkSubscriptionExpiration: false,
32
30
  moduleKey: automationAction.key,
33
31
  }), (0, validate_settings_1.default)(automationAction));
34
- app.post((0, util_1.getAutomationActionUrl)('/automation-action/execute', automationAction), (0, cors_1.default)(), (0, crowdin_client_1.default)({
32
+ app.post((0, util_1.getAutomationActionUrl)('/automation-action/execute', automationAction), (0, cors_1.default)(), (0, crowdin_client_1.handle)({
35
33
  config,
36
34
  optional: true,
37
35
  checkSubscriptionExpiration: false,