@crowdin/app-project-module 0.56.4 → 0.57.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.
@@ -70,6 +70,7 @@ class MySQLStorage {
70
70
  app_secret text,
71
71
  domain varchar(255),
72
72
  user_id varchar(255),
73
+ agent_id varchar(255),
73
74
  organization_id varchar(255),
74
75
  base_url varchar(255),
75
76
  access_token text not null,
@@ -170,11 +171,12 @@ class MySQLStorage {
170
171
  saveCrowdinCredentials(credentials) {
171
172
  return __awaiter(this, void 0, void 0, function* () {
172
173
  yield this.dbPromise;
173
- yield this.executeQuery((connection) => connection.execute('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
174
+ yield this.executeQuery((connection) => connection.execute('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, agent_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
174
175
  credentials.id,
175
176
  credentials.appSecret,
176
177
  credentials.domain,
177
178
  credentials.userId,
179
+ credentials.agentId,
178
180
  credentials.organizationId,
179
181
  credentials.baseUrl,
180
182
  credentials.accessToken,
@@ -187,10 +189,11 @@ class MySQLStorage {
187
189
  updateCrowdinCredentials(credentials) {
188
190
  return __awaiter(this, void 0, void 0, function* () {
189
191
  yield this.dbPromise;
190
- yield this.executeQuery((connection) => connection.execute('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
192
+ yield this.executeQuery((connection) => connection.execute('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, agent_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
191
193
  credentials.appSecret,
192
194
  credentials.domain,
193
195
  credentials.userId,
196
+ credentials.agentId,
194
197
  credentials.organizationId,
195
198
  credentials.baseUrl,
196
199
  credentials.accessToken,
@@ -204,7 +207,7 @@ class MySQLStorage {
204
207
  return __awaiter(this, void 0, void 0, function* () {
205
208
  yield this.dbPromise;
206
209
  return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
207
- const [rows] = yield connection.execute('SELECT id, app_secret as "appSecret", domain, user_id as "userId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials WHERE id = ?', [id]);
210
+ const [rows] = yield connection.execute('SELECT id, app_secret as "appSecret", domain, user_id as "userId", agent_id as "agentId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials WHERE id = ?', [id]);
208
211
  return (rows || [])[0];
209
212
  }));
210
213
  });
@@ -213,7 +216,7 @@ class MySQLStorage {
213
216
  return __awaiter(this, void 0, void 0, function* () {
214
217
  yield this.dbPromise;
215
218
  return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
216
- const [rows] = yield connection.execute('SELECT id, app_secret as "appSecret", domain, user_id as "userId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials', []);
219
+ const [rows] = yield connection.execute('SELECT id, app_secret as "appSecret", domain, user_id as "userId", agent_id as "agentId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials', []);
217
220
  return rows || [];
218
221
  }));
219
222
  });
@@ -24,7 +24,8 @@ export declare class PostgreStorage implements Storage {
24
24
  constructor(config: PostgreStorageConfig);
25
25
  executeQuery<T>(command: (client: Client) => Promise<T>): Promise<T>;
26
26
  migrate(): Promise<void>;
27
- addColumns(client: Client): Promise<void>;
27
+ alterTables(client: Client): Promise<void>;
28
+ addColumns(client: Client, newColumns: string[], tableName: string): Promise<void>;
28
29
  addTables(client: Client): Promise<void>;
29
30
  saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
30
31
  updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
@@ -51,7 +51,7 @@ class PostgreStorage {
51
51
  yield this.executeQuery(this.addTables);
52
52
  this._res && this._res();
53
53
  // TODO: temporary code
54
- yield this.executeQuery(this.addColumns);
54
+ yield this.executeQuery(this.alterTables);
55
55
  }
56
56
  catch (e) {
57
57
  console.error(e);
@@ -59,10 +59,14 @@ class PostgreStorage {
59
59
  }
60
60
  });
61
61
  }
62
- addColumns(client) {
62
+ alterTables(client) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ yield this.addColumns(client, ['crowdin_id'], 'app_metadata');
65
+ yield this.addColumns(client, ['agent_id'], 'crowdin_credentials');
66
+ });
67
+ }
68
+ addColumns(client, newColumns, tableName) {
63
69
  return __awaiter(this, void 0, void 0, function* () {
64
- const tableName = 'app_metadata';
65
- const newColumns = ['crowdin_id'];
66
70
  const tableInfo = yield client.query('SELECT column_name FROM information_schema.columns WHERE table_name = $1', [tableName]);
67
71
  tableInfo.rows.map((columnInfo) => __awaiter(this, void 0, void 0, function* () {
68
72
  const index = newColumns.indexOf(columnInfo.column_name);
@@ -84,6 +88,7 @@ class PostgreStorage {
84
88
  app_secret varchar,
85
89
  domain varchar,
86
90
  user_id varchar,
91
+ agent_id varchar,
87
92
  organization_id varchar,
88
93
  base_url varchar,
89
94
  access_token varchar not null,
@@ -183,11 +188,12 @@ class PostgreStorage {
183
188
  saveCrowdinCredentials(credentials) {
184
189
  return __awaiter(this, void 0, void 0, function* () {
185
190
  yield this.dbPromise;
186
- yield this.executeQuery((client) => client.query('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)', [
191
+ yield this.executeQuery((client) => client.query('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, agent_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)', [
187
192
  credentials.id,
188
193
  credentials.appSecret,
189
194
  credentials.domain,
190
195
  credentials.userId,
196
+ credentials.agentId,
191
197
  credentials.organizationId,
192
198
  credentials.baseUrl,
193
199
  credentials.accessToken,
@@ -200,10 +206,11 @@ class PostgreStorage {
200
206
  updateCrowdinCredentials(credentials) {
201
207
  return __awaiter(this, void 0, void 0, function* () {
202
208
  yield this.dbPromise;
203
- yield this.executeQuery((client) => client.query('UPDATE crowdin_credentials SET app_secret = $1, domain = $2, user_id = $3, organization_id = $4, base_url = $5, access_token = $6, refresh_token = $7, expire = $8 WHERE id = $9', [
209
+ yield this.executeQuery((client) => client.query('UPDATE crowdin_credentials SET app_secret = $1, domain = $2, user_id = $3, agent_id = $4, organization_id = $5, base_url = $6, access_token = $7, refresh_token = $8, expire = $9 WHERE id = $10', [
204
210
  credentials.appSecret,
205
211
  credentials.domain,
206
212
  credentials.userId,
213
+ credentials.agentId,
207
214
  credentials.organizationId,
208
215
  credentials.baseUrl,
209
216
  credentials.accessToken,
@@ -217,7 +224,7 @@ class PostgreStorage {
217
224
  return __awaiter(this, void 0, void 0, function* () {
218
225
  yield this.dbPromise;
219
226
  return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
220
- const res = yield client.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials WHERE id = $1', [id]);
227
+ const res = yield client.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", agent_id as "agentId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials WHERE id = $1', [id]);
221
228
  return res === null || res === void 0 ? void 0 : res.rows[0];
222
229
  }));
223
230
  });
@@ -226,7 +233,7 @@ class PostgreStorage {
226
233
  return __awaiter(this, void 0, void 0, function* () {
227
234
  yield this.dbPromise;
228
235
  return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
229
- const res = yield client.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials', []);
236
+ const res = yield client.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", agent_id as "agentId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials', []);
230
237
  return (res === null || res === void 0 ? void 0 : res.rows) || [];
231
238
  }));
232
239
  });
@@ -120,7 +120,7 @@ class SQLiteStorage {
120
120
  }
121
121
  updateTables() {
122
122
  return __awaiter(this, void 0, void 0, function* () {
123
- yield this.addColumns(['app_secret', 'domain', 'user_id', 'organization_id', 'base_url'], 'crowdin_credentials');
123
+ yield this.addColumns(['app_secret', 'domain', 'user_id', 'agent_id', 'organization_id', 'base_url'], 'crowdin_credentials');
124
124
  yield this.addColumns(['crowdin_id'], 'app_metadata');
125
125
  });
126
126
  }
@@ -162,6 +162,7 @@ class SQLiteStorage {
162
162
  app_secret varchar null,
163
163
  domain varchar null,
164
164
  user_id varchar null,
165
+ agent_id varchar null,
165
166
  organization_id varchar null,
166
167
  base_url varchar null,
167
168
  access_token varchar not null,
@@ -267,11 +268,12 @@ class SQLiteStorage {
267
268
  });
268
269
  }
269
270
  saveCrowdinCredentials(credentials) {
270
- return this.run('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
271
+ return this.run('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, agent_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
271
272
  credentials.id,
272
273
  credentials.appSecret,
273
274
  credentials.domain,
274
275
  credentials.userId,
276
+ credentials.agentId,
275
277
  credentials.organizationId,
276
278
  credentials.baseUrl,
277
279
  credentials.accessToken,
@@ -281,10 +283,11 @@ class SQLiteStorage {
281
283
  ]);
282
284
  }
283
285
  updateCrowdinCredentials(credentials) {
284
- return this.run('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
286
+ return this.run('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, agent_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
285
287
  credentials.appSecret,
286
288
  credentials.domain,
287
289
  credentials.userId,
290
+ credentials.agentId,
288
291
  credentials.organizationId,
289
292
  credentials.baseUrl,
290
293
  credentials.accessToken,
@@ -295,14 +298,14 @@ class SQLiteStorage {
295
298
  }
296
299
  getCrowdinCredentials(id) {
297
300
  return __awaiter(this, void 0, void 0, function* () {
298
- const row = yield this.get('SELECT id, app_secret as appSecret, domain, user_id as userId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials WHERE id = ?', [id]);
301
+ const row = yield this.get('SELECT id, app_secret as appSecret, domain, user_id as userId, agent_id as agentId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials WHERE id = ?', [id]);
299
302
  if (row) {
300
303
  return row;
301
304
  }
302
305
  });
303
306
  }
304
307
  getAllCrowdinCredentials() {
305
- return this.each('SELECT id, app_secret as appSecret, domain, user_id as userId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials', []);
308
+ return this.each('SELECT id, app_secret as appSecret, domain, user_id as userId, agent_id as agentId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials', []);
306
309
  }
307
310
  deleteCrowdinCredentials(id) {
308
311
  return __awaiter(this, void 0, void 0, function* () {
package/out/types.d.ts CHANGED
@@ -17,9 +17,13 @@ import { AiPromptProviderModule } from './modules/ai-prompt-provider/types';
17
17
  import { AiTool, AiToolWidget } from './modules/ai-tools/types';
18
18
  export interface ClientConfig extends ImagePath {
19
19
  /**
20
- * Authentication Crowdin App type: "authorization_code", "crowdin_app". Default: "crowdin_app"
20
+ * Authentication Crowdin App type: "authorization_code", "crowdin_app", "crowdin_agent". Default: "crowdin_app"
21
21
  */
22
22
  authenticationType?: AuthenticationType;
23
+ /**
24
+ * Crowdin Agent information: name, username, avatarUrl
25
+ */
26
+ agent?: Agent;
23
27
  /**
24
28
  * client id that we received when registering the app
25
29
  */
@@ -214,8 +218,14 @@ export type UnauthorizedConfig = Omit<Config, 'clientId' | 'clientSecret'> & {
214
218
  export declare enum AuthenticationType {
215
219
  CODE = "authorization_code",
216
220
  APP = "crowdin_app",
221
+ AGENT = "crowdin_agent",
217
222
  NONE = "none"
218
223
  }
224
+ export interface Agent {
225
+ name?: string;
226
+ username: string;
227
+ avatarUrl?: string;
228
+ }
219
229
  export interface CrowdinUrls {
220
230
  apiUrl?: string;
221
231
  accountUrl?: string;
@@ -259,6 +269,7 @@ export interface CrowdinCredentials {
259
269
  appSecret: string;
260
270
  domain?: string;
261
271
  userId: number;
272
+ agentId?: number;
262
273
  organizationId: number;
263
274
  baseUrl: string;
264
275
  accessToken: string;
package/out/types.js CHANGED
@@ -5,6 +5,7 @@ var AuthenticationType;
5
5
  (function (AuthenticationType) {
6
6
  AuthenticationType["CODE"] = "authorization_code";
7
7
  AuthenticationType["APP"] = "crowdin_app";
8
+ AuthenticationType["AGENT"] = "crowdin_agent";
8
9
  AuthenticationType["NONE"] = "none";
9
10
  })(AuthenticationType = exports.AuthenticationType || (exports.AuthenticationType = {}));
10
11
  var Scope;
@@ -1142,37 +1142,43 @@
1142
1142
  }
1143
1143
 
1144
1144
  function getUserErrorDetail(error) {
1145
- const data = JSON.parse(error.data);
1146
-
1147
- let html = '<div class="error-detail-table"><table>';
1148
- html += `<tr><td>Action</td><td>${error.action}</td></tr>`;
1149
- html += `<tr><td>Message</td><td>${error.message}</td></tr>`;
1150
- html += `<tr><td>Date/time</td><td>${error.createdAt}</td></tr>`;
1151
-
1152
- if (data.requestParams) {
1153
- html += `<tr><td>Method</td><td>${data.requestParams.method}</td></tr>`;
1154
- }
1155
-
1156
- if (data.responseData) {
1157
- html += `<tr><td>Response Data</td><td><pre>${JSON.stringify(data.responseData, null, 2)}</pre></td></tr>`;
1158
- }
1159
-
1160
- if (data.appData) {
1161
- if (Array.isArray(data.appData)) {
1162
- html += `<tr><td>App Data</td><td><pre>${JSON.stringify(data.appData, null, 2)}</pre></td></tr>`;
1163
- } else if (typeof data.appData === 'object') {
1164
- for (const key in data.appData) {
1165
- html += `<tr><td>${key.charAt(0).toUpperCase() + key.slice(1)}</td><td><pre>${JSON.stringify(data.appData[key], null, 2)}</pre></td></tr>`;
1166
- }
1167
- } else {
1168
- html += `<tr><td>App Data</td><td>${data.appData}</td></tr>`;
1169
- }
1145
+ const data = JSON.parse(error.data);
1146
+
1147
+ let html = '<div class="error-detail-table"><table>';
1148
+ html += `<tr><td>Action</td><td>${sanitizeHTML(error.action)}</td></tr>`;
1149
+ html += `<tr><td>Message</td><td>${sanitizeHTML(error.message)}</td></tr>`;
1150
+ html += `<tr><td>Date/time</td><td>${sanitizeHTML(error.createdAt)}</td></tr>`;
1151
+
1152
+ if (data.requestParams) {
1153
+ html += `<tr><td>Method</td><td>${sanitizeHTML(data.requestParams.method)}</td></tr>`;
1154
+ }
1155
+
1156
+ if (data.responseData) {
1157
+ html += `<tr><td>Response Data</td><td><pre>${sanitizeHTML(JSON.stringify(data.responseData, null, 2))}</pre></td></tr>`;
1158
+ }
1159
+
1160
+ if (data.appData) {
1161
+ if (Array.isArray(data.appData)) {
1162
+ html += `<tr><td>App Data</td><td><pre>${sanitizeHTML(JSON.stringify(data.appData, null, 2))}</pre></td></tr>`;
1163
+ } else if (typeof data.appData === 'object') {
1164
+ for (const key in data.appData) {
1165
+ html += `<tr><td>${sanitizeHTML(key.charAt(0).toUpperCase() + key.slice(1))}</td><td><pre>${sanitizeHTML(JSON.stringify(data.appData[key], null, 2))}</pre></td></tr>`;
1166
+ }
1167
+ } else {
1168
+ html += `<tr><td>App Data</td><td>${sanitizeHTML(data.appData)}</td></tr>`;
1170
1169
  }
1170
+ }
1171
1171
 
1172
1172
  html += '</table></div>';
1173
1173
 
1174
1174
  return html;
1175
1175
  }
1176
+
1177
+ function sanitizeHTML(str) {
1178
+ const tempDiv = document.createElement('div');
1179
+ tempDiv.textContent = str;
1180
+ return tempDiv.innerHTML;
1181
+ }
1176
1182
  </script>
1177
1183
 
1178
1184
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.56.4",
3
+ "version": "0.57.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",
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@aws-sdk/client-s3": "^3.606.0",
22
22
  "@aws-sdk/s3-request-presigner": "^3.598.0",
23
- "@crowdin/crowdin-apps-functions": "0.7.0",
23
+ "@crowdin/crowdin-apps-functions": "0.8.0",
24
24
  "@crowdin/logs-formatter": "^2.1.4",
25
25
  "@godaddy/terminus": "^4.12.1",
26
26
  "amqplib": "^0.10.3",