@crowdin/app-project-module 0.53.1 → 0.54.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.
@@ -180,27 +180,29 @@ function prepareCrowdinClient({ config, credentials, autoRenew = false, context,
180
180
  }
181
181
  exports.prepareCrowdinClient = prepareCrowdinClient;
182
182
  function prepareIntegrationCredentials(config, integration, integrationCredentials) {
183
- var _a, _b, _c, _d, _e, _f, _g, _h;
183
+ var _a, _b, _c, _d, _e, _f, _g;
184
184
  return __awaiter(this, void 0, void 0, function* () {
185
185
  const credentials = JSON.parse((0, _1.decryptData)(config, integrationCredentials.credentials));
186
- if ((_a = integration.oauthLogin) === null || _a === void 0 ? void 0 : _a.refresh) {
186
+ const oauthLogin = integration.oauthLogin;
187
+ const integrationLogin = integration.loginForm;
188
+ if ((oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.refresh) || (integrationLogin === null || integrationLogin === void 0 ? void 0 : integrationLogin.refresh)) {
187
189
  (0, logger_1.log)('Checking if integration credentials need to be refreshed');
188
- const oauthLogin = integration.oauthLogin;
189
190
  const { expireIn } = credentials;
190
191
  //2 min as an extra buffer
191
- const isExpired = expireIn - 120 < Date.now() / 1000;
192
+ const isExpired = !expireIn || expireIn - 120 < Date.now() / 1000;
193
+ const performRefreshTokenRequest = (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.performRefreshTokenRequest) || (integrationLogin === null || integrationLogin === void 0 ? void 0 : integrationLogin.performRefreshTokenRequest);
192
194
  if (isExpired) {
193
195
  (0, logger_1.log)('Integration credentials have expired. Requesting a new credentials');
194
196
  let newCredentials;
195
- if (oauthLogin.performRefreshTokenRequest) {
196
- newCredentials = yield oauthLogin.performRefreshTokenRequest(credentials);
197
+ if (performRefreshTokenRequest) {
198
+ newCredentials = yield performRefreshTokenRequest(credentials);
197
199
  }
198
- else {
200
+ else if (oauthLogin) {
199
201
  const url = oauthLogin.refreshTokenUrl || oauthLogin.accessTokenUrl;
200
202
  const request = {};
201
- request[((_b = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _b === void 0 ? void 0 : _b.clientId) || 'client_id'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientId;
202
- request[((_c = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _c === void 0 ? void 0 : _c.clientSecret) || 'client_secret'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientSecret;
203
- request[((_d = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _d === void 0 ? void 0 : _d.refreshToken) || 'refresh_token'] = credentials.refreshToken;
203
+ request[((_a = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _a === void 0 ? void 0 : _a.clientId) || 'client_id'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientId;
204
+ request[((_b = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _b === void 0 ? void 0 : _b.clientSecret) || 'client_secret'] = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.clientSecret;
205
+ request[((_c = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _c === void 0 ? void 0 : _c.refreshToken) || 'refresh_token'] = credentials.refreshToken;
204
206
  if (oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.extraRefreshTokenParameters) {
205
207
  Object.entries(oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.extraRefreshTokenParameters).forEach(([key, value]) => (request[key] = value));
206
208
  }
@@ -208,11 +210,14 @@ function prepareIntegrationCredentials(config, integration, integrationCredentia
208
210
  headers: { Accept: 'application/json' },
209
211
  })).data;
210
212
  }
211
- credentials.accessToken = newCredentials[((_e = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _e === void 0 ? void 0 : _e.accessToken) || 'access_token'];
213
+ else {
214
+ return credentials;
215
+ }
216
+ credentials.accessToken = newCredentials[((_d = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _d === void 0 ? void 0 : _d.accessToken) || 'access_token'];
212
217
  credentials.expireIn =
213
- Number(newCredentials[((_f = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _f === void 0 ? void 0 : _f.expiresIn) || 'expires_in']) + Date.now() / 1000;
214
- if (newCredentials[((_g = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _g === void 0 ? void 0 : _g.refreshToken) || 'refresh_token']) {
215
- credentials.refreshToken = newCredentials[((_h = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _h === void 0 ? void 0 : _h.refreshToken) || 'refresh_token'];
218
+ Number(newCredentials[((_e = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _e === void 0 ? void 0 : _e.expiresIn) || 'expires_in']) + Date.now() / 1000;
219
+ if (newCredentials[((_f = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _f === void 0 ? void 0 : _f.refreshToken) || 'refresh_token']) {
220
+ credentials.refreshToken = newCredentials[((_g = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _g === void 0 ? void 0 : _g.refreshToken) || 'refresh_token'];
216
221
  }
217
222
  (0, logger_1.log)('Saving updated integration credentials in the database');
218
223
  yield (0, storage_1.getStorage)().updateIntegrationCredentials(integrationCredentials.id, (0, _1.encryptData)(config, JSON.stringify(credentials)));
@@ -22,8 +22,17 @@ exports.engine = (0, express_handlebars_1.default)({
22
22
  return options.inverse(this);
23
23
  },
24
24
  in: function (a, b, options) {
25
- if (a !== undefined && a !== null && b !== undefined && b !== null && a.toString().includes(b.toString())) {
26
- return options.fn(this);
25
+ if (a !== undefined && a !== null && b !== undefined && b !== null) {
26
+ let bArray;
27
+ if (Array.isArray(b)) {
28
+ bArray = b;
29
+ }
30
+ else {
31
+ bArray = b.split(' ');
32
+ }
33
+ if (bArray.includes(a === null || a === void 0 ? void 0 : a.toString())) {
34
+ return options.fn(this);
35
+ }
27
36
  }
28
37
  return options.inverse(this);
29
38
  },
@@ -11,7 +11,7 @@
11
11
  <div class="inputs">
12
12
  {{#each loginFields}}
13
13
  {{#if key}}
14
- {{#in "checkbox select textarea file notice" type}}
14
+ {{#in type "checkbox select textarea file notice"}}
15
15
  {{#ifeq type "checkbox"}}
16
16
  <crowdin-checkbox
17
17
  id="{{key}}"
@@ -184,7 +184,7 @@
184
184
  <option
185
185
  {{#if ../defaultValue}}
186
186
  {{#ifeq ../defaultValue value}} selected {{/ifeq}}
187
- {{#in ../defaultValue value}} selected {{/in}}
187
+ {{#in value ../defaultValue}} selected {{/in}}
188
188
  {{/if}}
189
189
  value="{{value}}">{{label}}
190
190
  </option>
@@ -420,7 +420,7 @@
420
420
  project = res;
421
421
  const languagesSorted = project.targetLanguages.sort((a, b) => a.name.localeCompare(b.name));
422
422
 
423
- if (project.inContext) {
423
+ if (project.inContext && config?.inContext) {
424
424
  languagesSorted.push({...project.inContextPseudoLanguage, inContext: true});
425
425
  }
426
426
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.53.1",
3
+ "version": "0.54.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",
@@ -28,7 +28,7 @@
28
28
  "express": "4.19.2",
29
29
  "express-handlebars": "^5.3.5",
30
30
  "lodash.uniqby": "^4.7.0",
31
- "mysql2": "^3.9.7",
31
+ "mysql2": "^3.9.8",
32
32
  "node-cron": "^3.0.3",
33
33
  "pg": "^8.11.5",
34
34
  "redoc-express": "^2.1.0",
@@ -39,13 +39,13 @@
39
39
  "devDependencies": {
40
40
  "@babel/preset-react": "^7.24.1",
41
41
  "@emotion/react": "^11.11.4",
42
- "@emotion/styled": "^11.11.0",
43
- "@mui/icons-material": "^5.15.15",
44
- "@mui/material": "^5.15.15",
45
- "@rjsf/core": "^5.18.3",
46
- "@rjsf/mui": "^5.18.3",
47
- "@rjsf/utils": "^5.18.3",
48
- "@rjsf/validator-ajv8": "^5.18.3",
42
+ "@emotion/styled": "^11.11.5",
43
+ "@mui/icons-material": "^5.15.20",
44
+ "@mui/material": "^5.15.20",
45
+ "@rjsf/core": "^5.18.4",
46
+ "@rjsf/mui": "^5.18.4",
47
+ "@rjsf/utils": "^5.18.4",
48
+ "@rjsf/validator-ajv8": "^5.18.4",
49
49
  "@rollup/plugin-babel": "^6.0.4",
50
50
  "@rollup/plugin-commonjs": "^24.1.0",
51
51
  "@rollup/plugin-json": "^6.1.0",
@@ -56,11 +56,11 @@
56
56
  "@types/crypto-js": "^4.2.2",
57
57
  "@types/express": "4.17.21",
58
58
  "@types/express-handlebars": "^5.3.1",
59
- "@types/jest": "^29.5.5",
59
+ "@types/jest": "^29.5.12",
60
60
  "@types/lodash.uniqby": "^4.7.9",
61
61
  "@types/node": "^16.18.69",
62
62
  "@types/node-cron": "^3.0.11",
63
- "@types/pg": "^8.11.5",
63
+ "@types/pg": "^8.11.6",
64
64
  "@types/swagger-jsdoc": "^6.0.4",
65
65
  "@types/uuid": "^9.0.7",
66
66
  "@typescript-eslint/eslint-plugin": "^2.3.1",
@@ -72,9 +72,9 @@
72
72
  "jest-junit": "^15.0.0",
73
73
  "prettier": "^2.8.8",
74
74
  "react": "^18.3.1",
75
- "react-dom": "^18.2.0",
75
+ "react-dom": "^18.3.1",
76
76
  "rollup": "^3.29.4",
77
- "ts-jest": "^29.1.1",
77
+ "ts-jest": "^29.1.5",
78
78
  "typescript": "^4.9.5"
79
79
  },
80
80
  "repository": {