@crowdin/app-project-module 0.28.0-9 → 0.28.1

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.
@@ -17,20 +17,17 @@ const sqlite_1 = require("./sqlite");
17
17
  let storage;
18
18
  function initialize(config) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- if (config.dbFolder) {
21
- (0, util_1.log)('Using SQLite database', config.logger);
22
- storage = new sqlite_1.SQLiteStorage({ dbFolder: config.dbFolder });
23
- }
24
20
  if (config.postgreConfig) {
25
21
  (0, util_1.log)('Using PostgreSQL database', config.logger);
26
22
  storage = new postgre_1.PostgreStorage(config.postgreConfig);
27
23
  }
28
- if (config.mysqlConfig) {
24
+ else if (config.mysqlConfig) {
29
25
  (0, util_1.log)('Using MySQL database', config.logger);
30
26
  storage = new mysql_1.MySQLStorage(config.mysqlConfig);
31
27
  }
32
- if (!storage) {
33
- throw new Error('Database is not configured');
28
+ else {
29
+ (0, util_1.log)('Using SQLite database', config.logger);
30
+ storage = new sqlite_1.SQLiteStorage({ dbFolder: config.dbFolder });
34
31
  }
35
32
  yield storage.migrate();
36
33
  });
@@ -1,6 +1,7 @@
1
1
  import Crowdin, { SourceFilesModel } from '@crowdin/crowdin-api-client';
2
- import { Config, IntegrationLogic } from '../models';
2
+ import { ClientConfig, Config, IntegrationLogic } from '../models';
3
3
  export declare function getRootFolder(config: Config, integration: IntegrationLogic, client: Crowdin, projectId: number): Promise<SourceFilesModel.Directory | undefined>;
4
4
  export declare function getOauthRoute(integration: IntegrationLogic): string;
5
- export declare function applyDefaults(config: Config, integration: IntegrationLogic): void;
5
+ export declare function applyIntegrationModuleDefaults(config: Config, integration: IntegrationLogic): void;
6
6
  export declare function constructOauthUrl(config: Config, integration: IntegrationLogic): string;
7
+ export declare function convertClientConfig(clientConfig: ClientConfig): Config;
@@ -32,8 +32,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.constructOauthUrl = exports.applyDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
35
+ exports.convertClientConfig = exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
36
36
  const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
37
+ const path_1 = require("path");
37
38
  function getRootFolder(config, integration, client, projectId) {
38
39
  return __awaiter(this, void 0, void 0, function* () {
39
40
  if (!integration.withRootFolder) {
@@ -56,7 +57,7 @@ function getOauthRoute(integration) {
56
57
  return ((_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.redirectUriRoute) || '/oauth/code';
57
58
  }
58
59
  exports.getOauthRoute = getOauthRoute;
59
- function applyDefaults(config, integration) {
60
+ function applyIntegrationModuleDefaults(config, integration) {
60
61
  var _a;
61
62
  if (!integration.getCrowdinFiles) {
62
63
  integration.getCrowdinFiles = (projectId, client, rootFolder) => __awaiter(this, void 0, void 0, function* () {
@@ -245,7 +246,7 @@ function applyDefaults(config, integration) {
245
246
  integration.webhooks.urlParam = 'crowdinData';
246
247
  }
247
248
  }
248
- exports.applyDefaults = applyDefaults;
249
+ exports.applyIntegrationModuleDefaults = applyIntegrationModuleDefaults;
249
250
  function constructOauthUrl(config, integration) {
250
251
  var _a, _b, _c;
251
252
  const oauth = integration.oauthLogin;
@@ -261,3 +262,15 @@ function constructOauthUrl(config, integration) {
261
262
  return url;
262
263
  }
263
264
  exports.constructOauthUrl = constructOauthUrl;
265
+ function convertClientConfig(clientConfig) {
266
+ const baseUrl = clientConfig.baseUrl || process.env.URL;
267
+ const clientId = clientConfig.clientId || process.env.CROWDIN_CLIENT_ID;
268
+ const clientSecret = clientConfig.clientSecret || process.env.CROWDIN_CLIENT_SECRET;
269
+ const port = clientConfig.port || process.env.PORT || 3000;
270
+ if (!baseUrl || !clientId || !clientSecret) {
271
+ throw new Error('One of following parameters are not defined [baseUrl, clientId, clientSecret]');
272
+ }
273
+ return Object.assign(Object.assign({}, clientConfig), { baseUrl: baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl, clientId,
274
+ clientSecret, port: Number(port), dbFolder: clientConfig.dbFolder || (0, path_1.join)(process.cwd(), 'db'), imagePath: clientConfig.imagePath || (0, path_1.join)(process.cwd(), 'logo.png') });
275
+ }
276
+ exports.convertClientConfig = convertClientConfig;
@@ -0,0 +1,3 @@
1
+ export declare const MAX_BODY_SIZE: number;
2
+ export declare function storeFile(fileContent: string, folder: string): Promise<string>;
3
+ export declare function getFileContent(url: string, isString?: boolean): Promise<any>;
@@ -0,0 +1,43 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getFileContent = exports.storeFile = exports.MAX_BODY_SIZE = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const axios_1 = __importDefault(require("axios"));
19
+ exports.MAX_BODY_SIZE = 4.9 * 1024 * 1024; //4.9mb
20
+ function storeFile(fileContent, folder) {
21
+ const fileName = `file${Date.now()}`;
22
+ return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, fileName), fileContent, (err) => {
23
+ if (err) {
24
+ rej(err);
25
+ }
26
+ else {
27
+ res(fileName);
28
+ }
29
+ }));
30
+ }
31
+ exports.storeFile = storeFile;
32
+ function getFileContent(url, isString = false) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const response = (yield axios_1.default.get(url)).data;
35
+ if (isString) {
36
+ // the response is presented in the ndjson format
37
+ const jsonRows = response.split(/\n|\n\r/).filter(Boolean);
38
+ return jsonRows.map((jsonStringRow) => JSON.parse(jsonStringRow));
39
+ }
40
+ return response;
41
+ });
42
+ }
43
+ exports.getFileContent = getFileContent;
@@ -17,10 +17,12 @@
17
17
  </div>
18
18
  <crowdin-toasts></crowdin-toasts>
19
19
  <script>
20
+ /*<!--*/
20
21
  var formGetDataUrl = '{{formGetDataUrl}}';
21
22
  var formPostDataUrl = '{{formPostDataUrl}}';
22
23
  var formSchema = {{{formSchema}}};
23
24
  var formUiSchema = {{{formUiSchema}}};
25
+ /*-->*/
24
26
  </script>
25
27
  <script src="/assets/js/form.js"></script>
26
28
  </body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.28.0-9",
3
+ "version": "0.28.1",
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",
@@ -1,4 +0,0 @@
1
- /// <reference types="qs" />
2
- import { Request, Response } from 'express';
3
- import { Config } from '../../models';
4
- export default function handle(config: Config, folder: string): (req: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;