@crowdin/app-project-module 0.24.3 → 0.25.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.
package/README.md CHANGED
@@ -133,26 +133,26 @@ const configuration = {
133
133
  const directories = await client.sourceFilesApi
134
134
  .withFetchAll()
135
135
  .listProjectDirectories(projectId);
136
- const { folder, files } = await crowdinAppFunctions.getOrCreateFolder(
137
- directories.data.map((d) => d.data),
136
+ const { folder, files } = await crowdinAppFunctions.getOrCreateFolder({
137
+ directories: directories.data.map((d) => d.data),
138
138
  client,
139
139
  projectId,
140
- 'Folder from integration',
141
- rootFolder
142
- );
140
+ directoryName: 'Folder from integration',
141
+ parentDirectory: rootFolder
142
+ });
143
143
  const fileContent = {
144
144
  title: 'Hello World',
145
145
  };
146
- await crowdinAppFunctions.updateOrCreateFile(
146
+ await crowdinAppFunctions.updateOrCreateFile({
147
147
  client,
148
148
  projectId,
149
- 'integration.json',
150
- 'Sample file from integration',
151
- 'json',
152
- folder.id,
153
- fileContent,
154
- files.find((f) => f.name === 'integration.json'),
155
- );
149
+ name: 'integration.json',
150
+ title: 'Sample file from integration',
151
+ type: 'json',
152
+ directoryId: folder.id,
153
+ data: fileContent,
154
+ file: files.find((f) => f.name === 'integration.json'),
155
+ });
156
156
  return {
157
157
  message: 'Some message',
158
158
  };
@@ -163,13 +163,13 @@ const configuration = {
163
163
  const directories = await client.sourceFilesApi
164
164
  .withFetchAll()
165
165
  .listProjectDirectories(projectId);
166
- const { files } = await crowdinAppFunctions.getFolder(
167
- directories.data.map((d) => d.data),
166
+ const { files } = await crowdinAppFunctions.getFolder({
167
+ directories: directories.data.map((d) => d.data),
168
168
  client,
169
169
  projectId,
170
- 'Folder from integration',
171
- rootFolder
172
- );
170
+ directoryName: 'Folder from integration',
171
+ parentDirectory: rootFolder
172
+ });
173
173
  const file = files.find((f) => f.name === 'integration.json');
174
174
  if (file) {
175
175
  const translationsLink =
@@ -816,7 +816,8 @@ const configuration = {
816
816
  projectReports: { //can be editorRightPanel, projectMenu, projectTools, projectMenuCrowdsource
817
817
  imagePath: __dirname + '/' + 'reports.png',
818
818
  fileName: 'reports.html', //optional, only needed if file is not index.html
819
- uiPath: __dirname + '/' + 'public' // folder where UI of the module is located (js, html, css files)
819
+ uiPath: __dirname + '/' + 'public', // folder where UI of the module is located (js, html, css files)
820
+ allowUnauthorized: true //make module publicly available without crowdin context
820
821
  },
821
822
  };
822
823
 
@@ -46,14 +46,27 @@ function fetchToken(config, event) {
46
46
  var _a, _b;
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
48
  if (config.authenticationType === models_1.AuthenticationType.CODE) {
49
- const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)(config.clientId, config.clientSecret, event.code || '', (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl);
49
+ const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)({
50
+ clientId: config.clientId,
51
+ clientSecret: config.clientSecret,
52
+ code: event.code || '',
53
+ url: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl,
54
+ });
50
55
  return {
51
56
  accessToken: (0, util_1.encryptData)(config, token.accessToken),
52
57
  refreshToken: (0, util_1.encryptData)(config, token.refreshToken),
53
58
  expiresIn: token.expiresIn,
54
59
  };
55
60
  }
56
- const token = yield (0, crowdin_apps_functions_1.fetchAppToken)(config.identifier, event.appSecret, config.clientId, config.clientSecret, event.domain || '', event.userId, (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl);
61
+ const token = yield (0, crowdin_apps_functions_1.fetchAppToken)({
62
+ appId: config.identifier,
63
+ appSecret: event.appSecret,
64
+ clientId: config.clientId,
65
+ clientSecret: config.clientSecret,
66
+ domain: event.domain || '',
67
+ userId: event.userId,
68
+ url: (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl,
69
+ });
57
70
  return {
58
71
  accessToken: (0, util_1.encryptData)(config, token.accessToken),
59
72
  expiresIn: token.expiresIn,
package/out/index.js CHANGED
@@ -143,28 +143,28 @@ function addCrowdinEndpoints(app, config) {
143
143
  }
144
144
  if (config.profileResourcesMenu) {
145
145
  app.get('/logo/resources/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.profileResourcesMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
146
- app.use('/resources', (0, ui_module_1.default)(config), express_1.default.static(config.profileResourcesMenu.uiPath));
146
+ app.use('/resources', (0, ui_module_1.default)(config, config.profileResourcesMenu.allowUnauthorized), express_1.default.static(config.profileResourcesMenu.uiPath));
147
147
  }
148
148
  if (config.organizationMenu) {
149
149
  app.get('/logo/resources/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.organizationMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
150
- app.use('/resources', (0, ui_module_1.default)(config), express_1.default.static(config.organizationMenu.uiPath));
150
+ app.use('/resources', (0, ui_module_1.default)(config, config.organizationMenu.allowUnauthorized), express_1.default.static(config.organizationMenu.uiPath));
151
151
  }
152
152
  if (config.editorRightPanel) {
153
- app.use('/editor-panels', (0, ui_module_1.default)(config), express_1.default.static(config.editorRightPanel.uiPath));
153
+ app.use('/editor-panels', (0, ui_module_1.default)(config, config.editorRightPanel.allowUnauthorized), express_1.default.static(config.editorRightPanel.uiPath));
154
154
  }
155
155
  if (config.projectMenu) {
156
- app.use('/project-menu', (0, ui_module_1.default)(config), express_1.default.static(config.projectMenu.uiPath));
156
+ app.use('/project-menu', (0, ui_module_1.default)(config, config.projectMenu.allowUnauthorized), express_1.default.static(config.projectMenu.uiPath));
157
157
  }
158
158
  if (config.projectMenuCrowdsource) {
159
- app.use('/project-menu-crowdsource', (0, ui_module_1.default)(config), express_1.default.static(config.projectMenuCrowdsource.uiPath));
159
+ app.use('/project-menu-crowdsource', (0, ui_module_1.default)(config, config.projectMenuCrowdsource.allowUnauthorized), express_1.default.static(config.projectMenuCrowdsource.uiPath));
160
160
  }
161
161
  if (config.projectTools) {
162
162
  app.get('/logo/tools/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.projectTools) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
163
- app.use('/tools', (0, ui_module_1.default)(config), express_1.default.static(config.projectTools.uiPath));
163
+ app.use('/tools', (0, ui_module_1.default)(config, config.projectTools.allowUnauthorized), express_1.default.static(config.projectTools.uiPath));
164
164
  }
165
165
  if (config.projectReports) {
166
166
  app.get('/logo/reports/logo.png', (req, res) => { var _a; return res.sendFile(((_a = config.projectReports) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath || (0, path_1.join)(__dirname, 'logo.png')); });
167
- app.use('/reports', (0, ui_module_1.default)(config), express_1.default.static(config.projectReports.uiPath));
167
+ app.use('/reports', (0, ui_module_1.default)(config, config.projectReports.allowUnauthorized), express_1.default.static(config.projectReports.uiPath));
168
168
  }
169
169
  return {
170
170
  getMetadata: storage.getStorage().getMetadata.bind(storage.getStorage()),
@@ -1,4 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Request, Response } from 'express';
3
3
  import { Config } from '../models';
4
- export default function handle(config: Config): (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;
4
+ export default function handle(config: Config, allowUnauthorized?: boolean): (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;
@@ -13,8 +13,12 @@ const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
13
13
  const storage_1 = require("../storage");
14
14
  const util_1 = require("../util");
15
15
  const connection_1 = require("../util/connection");
16
- function handle(config) {
16
+ function handle(config, allowUnauthorized = false) {
17
17
  return (0, util_1.runAsyncWrapper)((req, res, next) => __awaiter(this, void 0, void 0, function* () {
18
+ if (allowUnauthorized) {
19
+ next();
20
+ return;
21
+ }
18
22
  const tokenJwt = req.query.tokenJwt;
19
23
  if (!tokenJwt) {
20
24
  return res.status(403).send({ error: 'Access denied' });
@@ -566,6 +566,10 @@ export interface UiModule {
566
566
  * page name (default index.html)
567
567
  */
568
568
  fileName?: string;
569
+ /**
570
+ * make module publicly available without crowdin context
571
+ */
572
+ allowUnauthorized?: boolean;
569
573
  }
570
574
  export interface EditorPanels extends UiModule {
571
575
  /**
@@ -23,14 +23,27 @@ function refreshToken(config, credentials) {
23
23
  var _a, _b;
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
25
  if (config.authenticationType === models_1.AuthenticationType.CODE) {
26
- const token = yield (0, crowdin_apps_functions_1.refreshOAuthToken)(config.clientId, config.clientSecret, (0, _1.decryptData)(config, credentials.refreshToken), (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl);
26
+ const token = yield (0, crowdin_apps_functions_1.refreshOAuthToken)({
27
+ clientId: config.clientId,
28
+ clientSecret: config.clientSecret,
29
+ refreshToken: (0, _1.decryptData)(config, credentials.refreshToken),
30
+ url: (_a = config.crowdinUrls) === null || _a === void 0 ? void 0 : _a.accountUrl,
31
+ });
27
32
  return {
28
33
  accessToken: (0, _1.encryptData)(config, token.accessToken),
29
34
  refreshToken: (0, _1.encryptData)(config, token.refreshToken),
30
35
  expiresIn: token.expiresIn,
31
36
  };
32
37
  }
33
- const token = yield (0, crowdin_apps_functions_1.fetchAppToken)(config.identifier, credentials.appSecret, config.clientId, config.clientSecret, credentials.domain || '', credentials.userId, (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl);
38
+ const token = yield (0, crowdin_apps_functions_1.fetchAppToken)({
39
+ appId: config.identifier,
40
+ appSecret: credentials.appSecret,
41
+ clientId: config.clientId,
42
+ clientSecret: config.clientSecret,
43
+ domain: credentials.domain || '',
44
+ userId: credentials.userId,
45
+ url: (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl,
46
+ });
34
47
  return {
35
48
  accessToken: (0, _1.encryptData)(config, token.accessToken),
36
49
  expiresIn: token.expiresIn,
@@ -37,7 +37,12 @@ function getRootFolder(config, integration, client, projectId) {
37
37
  }
38
38
  const folder = integration.appFolderName || config.name;
39
39
  const directories = (yield client.sourceFilesApi.withFetchAll().listProjectDirectories(projectId)).data.map((d) => d.data);
40
- const { folder: rootFolder } = yield crowdinAppFunctions.getOrCreateFolder(directories, client, projectId, folder);
40
+ const { folder: rootFolder } = yield crowdinAppFunctions.getOrCreateFolder({
41
+ directories,
42
+ client,
43
+ projectId,
44
+ directoryName: folder,
45
+ });
41
46
  return rootFolder;
42
47
  });
43
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.24.3",
3
+ "version": "0.25.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",
@@ -13,7 +13,7 @@
13
13
  "test": "jest --config jestconfig.json"
14
14
  },
15
15
  "dependencies": {
16
- "@crowdin/crowdin-apps-functions": "~0.2.1",
16
+ "@crowdin/crowdin-apps-functions": "0.3.1",
17
17
  "@types/pg": "^8.6.5",
18
18
  "crypto-js": "^4.0.0",
19
19
  "express": "4.17.1",