@crowdin/app-project-module 0.54.1 → 0.55.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.
@@ -24,8 +24,10 @@ export declare const crowdinFiles: {
24
24
  branchId?: number | undefined;
25
25
  directoryId?: number | undefined;
26
26
  title?: string | undefined;
27
+ context?: string | undefined;
27
28
  type?: SourceFilesModel.FileType | undefined;
28
- importOptions?: SourceFilesModel.SpreadsheetImportOptions | SourceFilesModel.XmlImportOptions | SourceFilesModel.OtherImportOptions | SourceFilesModel.DocxFileImportOptions | undefined;
29
+ parserVersion?: number | undefined;
30
+ importOptions?: SourceFilesModel.ImportOptions | undefined;
29
31
  exportOptions?: SourceFilesModel.GeneralExportOptions | SourceFilesModel.PropertyExportOptions | undefined;
30
32
  attachLabelIds?: number[] | undefined;
31
33
  excludedTargetLanguages?: string[] | undefined;
package/out/index.js CHANGED
@@ -61,6 +61,7 @@ const contextMenuApp = __importStar(require("./modules/context-menu"));
61
61
  const customMTApp = __importStar(require("./modules/custom-mt"));
62
62
  const spellCheckApp = __importStar(require("./modules/custom-spell-check"));
63
63
  const aiProvider = __importStar(require("./modules/ai-provider"));
64
+ const aiPromptProvider = __importStar(require("./modules/ai-prompt-provider"));
64
65
  const editorRightPanelApp = __importStar(require("./modules/editor-right-panel"));
65
66
  const editorThemesApp = __importStar(require("./modules/editor-themes"));
66
67
  const fileProcessingApps = __importStar(require("./modules/file-processing"));
@@ -165,6 +166,7 @@ function addCrowdinEndpoints(app, clientConfig) {
165
166
  fileProcessingApps.registerFilePostExport({ config, app });
166
167
  apiApp.register({ config, app });
167
168
  aiProvider.register({ config, app });
169
+ aiPromptProvider.register({ config, app });
168
170
  addFormSchema({ config, app });
169
171
  return Object.assign(Object.assign({}, exports.metadataStore), { establishCrowdinConnection: (authRequest) => {
170
172
  let jwtToken = '';
@@ -0,0 +1,5 @@
1
+ /// <reference types="qs" />
2
+ import { Response } from 'express';
3
+ import { CrowdinClientRequest } from '../../../types';
4
+ import { AiPromptProviderModule } from '../types';
5
+ export default function handle(aiPromptProvider: AiPromptProviderModule): (req: CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const util_1 = require("../../../util");
13
+ const logger_1 = require("../../../util/logger");
14
+ function handle(aiPromptProvider) {
15
+ return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ const compiledPrompt = yield aiPromptProvider.compile(req.body.options, req.body.payload, req.crowdinApiClient, req.crowdinContext);
18
+ res.send({ data: { content: compiledPrompt } });
19
+ }
20
+ catch (e) {
21
+ if (req.logError) {
22
+ req.logError(e);
23
+ }
24
+ res.send({ error: { message: (0, logger_1.getErrorMessage)(e) } });
25
+ }
26
+ }));
27
+ }
28
+ exports.default = handle;
@@ -0,0 +1,6 @@
1
+ import { Express } from 'express';
2
+ import { Config } from '../../types';
3
+ export declare function register({ config, app }: {
4
+ config: Config;
5
+ app: Express;
6
+ }): void;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.register = void 0;
7
+ const json_response_1 = __importDefault(require("../../middlewares/json-response"));
8
+ const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
9
+ const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
10
+ const util_1 = require("../../util");
11
+ const crowdin_client_1 = __importDefault(require("../../middlewares/crowdin-client"));
12
+ const compile_1 = __importDefault(require("./handlers/compile"));
13
+ function register({ config, app }) {
14
+ if (!config.aiPromptProvider) {
15
+ return;
16
+ }
17
+ app.post('/prompt-provider/compile', json_response_1.default, (0, crowdin_client_1.default)(config), (0, compile_1.default)(config.aiPromptProvider));
18
+ if (config.aiPromptProvider.formSchema) {
19
+ app.use('/prompt-provider/settings', (0, ui_module_1.default)(config, true), (0, render_ui_module_1.default)(config.aiPromptProvider));
20
+ }
21
+ app.get((0, util_1.getLogoUrl)(config.aiPromptProvider, '/ai-prompt-provider'), (req, res) => { var _a; return res.sendFile(((_a = config.aiPromptProvider) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
22
+ }
23
+ exports.register = register;
@@ -0,0 +1,8 @@
1
+ import { CrowdinContextInfo, UiModule } from '../../types';
2
+ import Crowdin from '@crowdin/crowdin-api-client';
3
+ export interface AiPromptProviderModule extends UiModule {
4
+ /**
5
+ * generates prompt text based on provided options
6
+ */
7
+ compile: (options: any, payload: any, client: Crowdin, context: CrowdinContextInfo) => Promise<string>;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -29,6 +29,13 @@ export declare function prepareWebhookData({ config, integration, provider, webh
29
29
  webhookUrlParam: string;
30
30
  provider: Provider;
31
31
  }): Promise<{
32
+ projectId: number;
33
+ crowdinClient: null;
34
+ rootFolder: undefined;
35
+ appSettings: AppSettings;
36
+ syncSettings: null;
37
+ preparedIntegrationCredentials: null;
38
+ } | {
32
39
  projectId: number;
33
40
  crowdinClient: {
34
41
  client: Crowdin;
@@ -255,12 +255,16 @@ function prepareWebhookData({ config, integration, provider, webhookUrlParam, })
255
255
  return __awaiter(this, void 0, void 0, function* () {
256
256
  let rootFolder = undefined;
257
257
  let syncSettings = null;
258
+ let crowdinClient = null;
258
259
  let preparedIntegrationCredentials = null;
259
260
  let appSettings = {};
260
261
  const { projectId, crowdinId, clientId } = decodedUrlParam(config, webhookUrlParam);
261
262
  const crowdinCredentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(crowdinId);
262
263
  const integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(clientId);
263
264
  const integrationConfig = yield (0, storage_1.getStorage)().getIntegrationConfig(clientId);
265
+ if (!crowdinCredentials) {
266
+ return { projectId, crowdinClient, rootFolder, appSettings, syncSettings, preparedIntegrationCredentials };
267
+ }
264
268
  const context = {
265
269
  jwtPayload: {
266
270
  context: {
@@ -273,7 +277,7 @@ function prepareWebhookData({ config, integration, provider, webhookUrlParam, })
273
277
  },
274
278
  },
275
279
  };
276
- const crowdinClient = yield (0, connection_1.prepareCrowdinClient)({
280
+ crowdinClient = yield (0, connection_1.prepareCrowdinClient)({
277
281
  config,
278
282
  credentials: crowdinCredentials,
279
283
  context,
@@ -287,7 +291,13 @@ function prepareWebhookData({ config, integration, provider, webhookUrlParam, })
287
291
  const isWebhookSync = Number(appSettings.schedule) !== types_1.SyncSchedule.DISABLED;
288
292
  if (isWebhookSync) {
289
293
  syncSettings = (yield (0, storage_1.getStorage)().getSyncSettings(clientId, crowdinId, 'schedule', provider));
290
- rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, crowdinClient.client, projectId);
294
+ // We can get an error in getRootFolder when the project has been deleted but the webhooks have been created
295
+ try {
296
+ rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, crowdinClient.client, projectId);
297
+ }
298
+ catch (e) {
299
+ (0, logger_1.logError)(e);
300
+ }
291
301
  }
292
302
  }
293
303
  return {
@@ -321,12 +331,14 @@ function updateCrowdinFromWebhookRequest(args) {
321
331
  parent_id: file.parent_id || file.parentId,
322
332
  // eslint-disable-next-line @typescript-eslint/camelcase
323
333
  node_type: file.nodeType || file.node_type || '1' }, (file.type ? { type: file.type } : {}));
324
- if (!syncFiles.find((obj) => obj.id === initFile.id)) {
325
- yield (0, storage_1.getStorage)().updateSyncSettings(JSON.stringify([...syncFiles, initFile]), syncSettings.integrationId, syncSettings.crowdinId, 'schedule', syncSettings.provider);
326
- }
327
- const webhook = yield (0, storage_1.getStorage)().getWebhooks(initFile.id, syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
328
- if (!webhook) {
329
- yield (0, storage_1.getStorage)().saveWebhooks(initFile.id, syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
334
+ if (syncSettings) {
335
+ if (!syncFiles.find((obj) => obj.id === initFile.id)) {
336
+ yield (0, storage_1.getStorage)().updateSyncSettings(JSON.stringify([...syncFiles, initFile]), syncSettings.integrationId, syncSettings.crowdinId, 'schedule', syncSettings.provider);
337
+ }
338
+ const webhook = yield (0, storage_1.getStorage)().getWebhooks(initFile.id, syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
339
+ if (!webhook) {
340
+ yield (0, storage_1.getStorage)().saveWebhooks(initFile.id, syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
341
+ }
330
342
  }
331
343
  }
332
344
  });
@@ -431,7 +443,7 @@ function processMessages({ channel, msg, webhooksData, webhooksInfo, }) {
431
443
  return __awaiter(this, void 0, void 0, function* () {
432
444
  yield Promise.all(webhooksData);
433
445
  for (const { data, integration, webhookData } of Object.values(webhooksInfo)) {
434
- if (webhookData) {
446
+ if (webhookData && webhookData.crowdinClient) {
435
447
  yield updateCrowdinFromWebhookRequest({
436
448
  integration: integration,
437
449
  webhookData: webhookData,
@@ -179,6 +179,15 @@ function handle(config) {
179
179
  })), (uiModule ? { url: '/settings/' + (uiModule.fileName || 'index.html') } : {})),
180
180
  ];
181
181
  }
182
+ if (config.aiPromptProvider) {
183
+ modules['ai-prompt-provider'] = [
184
+ Object.assign({ key: config.identifier + '-ai-prompt-provider', name: config.aiPromptProvider.name || config.name, logo: (0, util_1.getLogoUrl)(config.aiPromptProvider, '/ai-prompt-provider'), compileUrl: '/prompt-provider/compile' }, (!!config.aiPromptProvider.formSchema
185
+ ? {
186
+ configuratorUrl: '/prompt-provider/settings/' + (config.aiPromptProvider.fileName || 'index.html'),
187
+ }
188
+ : {})),
189
+ ];
190
+ }
182
191
  const events = {
183
192
  installed: '/installed',
184
193
  uninstall: '/uninstall',
@@ -232,4 +232,26 @@
232
232
 
233
233
  .error-page a {
234
234
  vertical-align: unset!important;
235
+ }
236
+
237
+ .ai-provider-form body {
238
+ margin: 0;
239
+ }
240
+
241
+ .ai-provider-form .i_w {
242
+ max-width: 100% !important;
243
+ padding: 0;
244
+ }
245
+
246
+ .form-without-submit {
247
+ body {
248
+ margin: 0;
249
+ }
250
+ .i_w {
251
+ padding: 0px !important;
252
+ max-width: 100% !important;
253
+ }
254
+ form > .MuiBox-root {
255
+ display: none;
256
+ }
235
257
  }