@crowdin/app-project-module 0.53.0 → 0.54.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.
@@ -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.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,24 +11,28 @@
11
11
  <div class="inputs">
12
12
  {{#each loginFields}}
13
13
  {{#if key}}
14
- {{#ifeq type "checkbox"}}
15
- <crowdin-checkbox
16
- id="{{key}}"
17
- label="{{label}}"
18
- value="false"
19
- use-switch
20
- {{#if helpText}}
21
- help-text="{{helpText}}"
22
- {{/if}}
23
- {{#if helpTextHtml}}
24
- help-text-html="{{helpTextHtml}}"
25
- {{/if}}
26
- {{#ifeq defaultValue true}}
27
- checked="{{defaultValue}}"
28
- {{/ifeq}}
29
- >
30
- </crowdin-checkbox>
31
- {{else}}
14
+ {{#in type "checkbox select textarea file notice"}}
15
+ {{#ifeq type "checkbox"}}
16
+ <crowdin-checkbox
17
+ id="{{key}}"
18
+ label="{{label}}"
19
+ value="false"
20
+ use-switch
21
+ {{#if helpText}}
22
+ help-text="{{helpText}}"
23
+ {{/if}}
24
+ {{#if helpTextHtml}}
25
+ help-text-html="{{helpTextHtml}}"
26
+ {{/if}}
27
+ {{#ifeq defaultValue true}}
28
+ checked="{{defaultValue}}"
29
+ {{/ifeq}}
30
+ {{#if dependencySettings}}
31
+ data-dependency="{{dependencySettings}}"
32
+ {{/if}}
33
+ >
34
+ </crowdin-checkbox>
35
+ {{/ifeq}}
32
36
  {{#ifeq type "select"}}
33
37
  <crowdin-select
34
38
  {{#if isMulti}}
@@ -46,72 +50,114 @@
46
50
  {{#if helpTextHtml}}
47
51
  help-text-html="{{helpTextHtml}}"
48
52
  {{/if}}
53
+ {{#if dependencySettings}}
54
+ data-dependency="{{dependencySettings}}"
55
+ {{/if}}
49
56
  >
50
57
  {{#each options}}
51
58
  <option {{#ifeq ../defaultValue value}} selected {{/ifeq}} value="{{value}}">{{label}}</option>
52
59
  {{/each}}
53
60
  </crowdin-select>
54
- {{else}}
55
- {{#ifeq type "textarea"}}
56
- <crowdin-textarea
57
- id="{{key}}"
58
- label="{{label}}"
59
- {{#if helpText}}
60
- help-text="{{helpText}}"
61
- {{/if}}
62
- {{#if helpTextHtml}}
63
- help-text-html="{{helpTextHtml}}"
64
- {{/if}}
65
- value="{{#if defaultValue}}{{defaultValue}}{{/if}}">
66
- </crowdin-textarea>
67
- {{else}}
68
- {{#ifeq type "file"}}
69
- <div class="file-field">
70
- {{#if helpText}}<div class="help-text">{{helpText}}</div>{{/if}}
71
- {{#if helpTextHtml}}<div class="help-text">{{helpTextHtml}}</div>{{/if}}
72
- <div class="upload">
73
- <crowdin-button outlined onclick="uploadFiles('{{key}}');">{{label}}</crowdin-button>
74
- <textarea hidden id="{{key}}"></textarea>
75
- <input
76
- id="store_{{key}}"
77
- data-id="{{key}}"
78
- {{#if accept}}
79
- accept="{{accept}}"
80
- {{/if}}
81
- onchange="readFileData(event)"
82
- hidden
83
- type="{{type}}"
84
- >
85
- <div class="uploaded-file"><i>No file</i></div>
86
- </div>
87
- </div>
88
- {{else}}
89
- <crowdin-input
90
- id="{{key}}"
91
- label="{{label}}"
92
- {{#if helpText}}
93
- help-text="{{helpText}}"
94
- {{/if}}
95
- {{#if helpTextHtml}}
96
- help-text-html="{{helpTextHtml}}"
97
- {{/if}}
98
- {{#if type}}
99
- type="{{type}}"
61
+ {{/ifeq}}
62
+ {{#ifeq type "textarea"}}
63
+ <crowdin-textarea
64
+ id="{{key}}"
65
+ label="{{label}}"
66
+ {{#if helpText}}
67
+ help-text="{{helpText}}"
68
+ {{/if}}
69
+ {{#if helpTextHtml}}
70
+ help-text-html="{{helpTextHtml}}"
71
+ {{/if}}
72
+ {{#if dependencySettings}}
73
+ data-dependency="{{dependencySettings}}"
74
+ {{/if}}
75
+ value="{{#if defaultValue}}{{defaultValue}}{{/if}}">
76
+ </crowdin-textarea>
77
+ {{/ifeq}}
78
+ {{#ifeq type "notice"}}
79
+ <crowdin-alert
80
+ {{#if noticeType}}
81
+ type="{{noticeType}}"
82
+ {{/if}}
83
+ {{#if label}}
84
+ title="{{label}}"
85
+ {{/if}}
86
+ {{#if noIcon}}
87
+ no-icon="{{noIcon}}"
88
+ {{/if}}
89
+ {{#if dependencySettings}}
90
+ data-dependency="{{dependencySettings}}"
91
+ {{/if}}
92
+ >
93
+ {{{helpText}}}
94
+ </crowdin-alert>
95
+ {{/ifeq}}
96
+ {{#ifeq type "file"}}
97
+ <div class="file-field">
98
+ {{#if helpText}}<div class="help-text">{{helpText}}</div>{{/if}}
99
+ {{#if helpTextHtml}}<div class="help-text">{{helpTextHtml}}</div>{{/if}}
100
+ <div class="upload">
101
+ <crowdin-button outlined onclick="uploadFiles('{{key}}');">{{label}}</crowdin-button>
102
+ <textarea hidden id="{{key}}"></textarea>
103
+ <input
104
+ id="store_{{key}}"
105
+ data-id="{{key}}"
106
+ {{#if accept}}
107
+ accept="{{accept}}"
100
108
  {{/if}}
101
- value="{{#if defaultValue}}{{defaultValue}}{{/if}}">
102
- </crowdin-input>
103
- {{/ifeq}}
104
- {{/ifeq}}
109
+ onchange="readFileData(event)"
110
+ hidden
111
+ type="{{type}}"
112
+ >
113
+ <div class="uploaded-file"><i>No file</i></div>
114
+ </div>
115
+ </div>
105
116
  {{/ifeq}}
106
- {{/ifeq}}
117
+ {{else}}
118
+ <crowdin-input
119
+ id="{{key}}"
120
+ label="{{label}}"
121
+ {{#if helpText}}
122
+ help-text="{{helpText}}"
123
+ {{/if}}
124
+ {{#if helpTextHtml}}
125
+ help-text-html="{{helpTextHtml}}"
126
+ {{/if}}
127
+ {{#if type}}
128
+ type="{{type}}"
129
+ {{/if}}
130
+ {{#if dependencySettings}}
131
+ data-dependency="{{dependencySettings}}"
132
+ {{/if}}
133
+ value="{{#if defaultValue}}{{defaultValue}}{{/if}}">
134
+ </crowdin-input>
135
+ {{/in}}
107
136
  {{else}}
108
137
  {{#if labelHtml}}
109
- <crowdin-p>{{{labelHtml}}}</crowdin-p>
138
+ <crowdin-p
139
+ {{#if dependencySettings}}
140
+ data-dependency="{{dependencySettings}}"
141
+ {{/if}}
142
+ >
143
+ {{{labelHtml}}}
144
+ </crowdin-p>
110
145
  {{else}}
111
- <crowdin-p>{{label}}</crowdin-p>
146
+ <crowdin-p
147
+ {{#if dependencySettings}}
148
+ data-dependency="{{dependencySettings}}"
149
+ {{/if}}
150
+ >
151
+ {{label}}
152
+ </crowdin-p>
112
153
  {{/if}}
113
154
  {{/if}}
114
- <div style="padding: 8px"></div>
155
+ <div
156
+ style="padding: 8px"
157
+ {{#if dependencySettings}}
158
+ data-dependency="{{dependencySettings}}"
159
+ {{/if}}
160
+ ></div>
115
161
  {{/each}}
116
162
  </div>
117
163
  <crowdin-button
@@ -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>
@@ -227,6 +227,24 @@
227
227
  value="{{#if defaultValue}}{{defaultValue}}{{/if}}">
228
228
  </crowdin-textarea>
229
229
  {{/ifeq}}
230
+ {{#ifeq type "notice"}}
231
+ <crowdin-alert
232
+ {{#if noticeType}}
233
+ type="{{noticeType}}"
234
+ {{/if}}
235
+ {{#if label}}
236
+ title="{{label}}"
237
+ {{/if}}
238
+ {{#if noIcon}}
239
+ no-icon="{{noIcon}}"
240
+ {{/if}}
241
+ {{#if dependencySettings}}
242
+ data-dependency="{{dependencySettings}}"
243
+ {{/if}}
244
+ >
245
+ {{{helpText}}}
246
+ </crowdin-alert>
247
+ {{/ifeq}}
230
248
  {{else}}
231
249
  {{#if labelHtml}}
232
250
  <crowdin-p
@@ -402,7 +420,7 @@
402
420
  project = res;
403
421
  const languagesSorted = project.targetLanguages.sort((a, b) => a.name.localeCompare(b.name));
404
422
 
405
- if (project.inContext) {
423
+ if (project.inContext && config?.inContext) {
406
424
  languagesSorted.push({...project.inContextPseudoLanguage, inContext: true});
407
425
  }
408
426
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.53.0",
3
+ "version": "0.54.0",
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.19",
44
+ "@mui/material": "^5.15.19",
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",
@@ -60,7 +60,7 @@
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,7 +72,7 @@
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
77
  "ts-jest": "^29.1.1",
78
78
  "typescript": "^4.9.5"