@crowdin/app-project-module 0.75.0 → 0.76.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.
@@ -24,6 +24,99 @@ class SQLiteStorage {
24
24
  this._res = res;
25
25
  this._rej = rej;
26
26
  });
27
+ this.tables = {
28
+ crowdin_credentials: `(
29
+ id varchar not null primary key,
30
+ app_secret varchar null,
31
+ domain varchar null,
32
+ user_id varchar null,
33
+ agent_id varchar null,
34
+ organization_id varchar null,
35
+ base_url varchar null,
36
+ access_token varchar not null,
37
+ refresh_token varchar not null,
38
+ expire varchar not null,
39
+ type varchar not null
40
+ )`,
41
+ integration_credentials: `(
42
+ id varchar not null primary key,
43
+ credentials varchar not null,
44
+ crowdin_id varchar not null,
45
+ managers varchar null
46
+ )`,
47
+ sync_settings: `(
48
+ id integer not null primary key autoincrement,
49
+ files varchar null,
50
+ integration_id varchar not null,
51
+ crowdin_id varchar not null,
52
+ type varchar not null,
53
+ provider varchar not null
54
+ )`,
55
+ app_metadata: `(
56
+ id varchar not null primary key,
57
+ data varchar null,
58
+ crowdin_id varchar null
59
+ )`,
60
+ files_snapshot: `(
61
+ id integer not null primary key autoincrement,
62
+ integration_id varchar not null,
63
+ crowdin_id varchar not null,
64
+ files varchar null,
65
+ provider varchar not null
66
+ )`,
67
+ webhooks: `(
68
+ id integer not null primary key autoincrement,
69
+ file_id varchar not null,
70
+ integration_id varchar not null,
71
+ crowdin_id varchar not null,
72
+ provider varchar not null
73
+ )`,
74
+ user_errors: `(
75
+ id integer not null primary key autoincrement,
76
+ action varchar not null,
77
+ message varchar not null,
78
+ data varchar null,
79
+ created_at varchar not null,
80
+ crowdin_id varchar not null,
81
+ integration_id varchar null
82
+ )`,
83
+ integration_settings: `(
84
+ id integer not null primary key autoincrement,
85
+ integration_id varchar not null,
86
+ crowdin_id varchar not null,
87
+ config varchar null
88
+ )`,
89
+ job: `(
90
+ id varchar not null primary key,
91
+ integration_id varchar not null,
92
+ crowdin_id varchar not null,
93
+ type varchar not null,
94
+ title varchar null,
95
+ progress integer DEFAULT 0,
96
+ status varchar DEFAULT '${types_2.JobStatus.CREATED}',
97
+ payload varchar null,
98
+ info varchar null,
99
+ data varchar null,
100
+ attempt varchar DEFAULT 0,
101
+ created_at varchar not null,
102
+ updated_at varchar null,
103
+ finished_at varchar null
104
+ )`,
105
+ translation_file_cache: `(
106
+ id integer not null primary key autoincrement,
107
+ integration_id varchar not null,
108
+ crowdin_id varchar not null,
109
+ file_id integer not null,
110
+ language_id varchar not null,
111
+ etag varchar
112
+ )`,
113
+ unsynced_files: `(
114
+ id integer not null primary key autoincrement,
115
+ integration_id varchar not null,
116
+ crowdin_id varchar not null,
117
+ files varchar null
118
+ )`,
119
+ };
27
120
  this.config = config;
28
121
  }
29
122
  _run(query, params) {
@@ -187,121 +280,9 @@ class SQLiteStorage {
187
280
  });
188
281
  try {
189
282
  yield connectionPromise;
190
- yield this._run(`
191
- create table if not exists crowdin_credentials
192
- (
193
- id varchar not null primary key,
194
- app_secret varchar null,
195
- domain varchar null,
196
- user_id varchar null,
197
- agent_id varchar null,
198
- organization_id varchar null,
199
- base_url varchar null,
200
- access_token varchar not null,
201
- refresh_token varchar not null,
202
- expire varchar not null,
203
- type varchar not null
204
- );
205
- `, []);
206
- yield this._run(`
207
- create table if not exists integration_credentials
208
- (
209
- id varchar not null primary key,
210
- credentials varchar not null,
211
- crowdin_id varchar not null,
212
- managers varchar null
213
- );
214
- `, []);
215
- yield this._run(`
216
- create table if not exists sync_settings
217
- (
218
- id integer not null primary key autoincrement,
219
- files varchar null,
220
- integration_id varchar not null,
221
- crowdin_id varchar not null,
222
- type varchar not null,
223
- provider varchar not null
224
- );
225
- `, []);
226
- yield this._run(`
227
- create table if not exists app_metadata
228
- (
229
- id varchar not null primary key,
230
- data varchar null,
231
- crowdin_id varchar null
232
- );
233
- `, []);
234
- yield this._run(`
235
- create table if not exists files_snapshot
236
- (
237
- id integer not null primary key autoincrement,
238
- integration_id varchar not null,
239
- crowdin_id varchar not null,
240
- files varchar null,
241
- provider varchar not null
242
- );
243
- `, []);
244
- yield this._run(`
245
- create table if not exists webhooks
246
- (
247
- id integer not null primary key autoincrement,
248
- file_id varchar not null,
249
- integration_id varchar not null,
250
- crowdin_id varchar not null,
251
- provider varchar not null
252
- );
253
- `, []);
254
- yield this._run(`
255
- create table if not exists user_errors
256
- (
257
- id integer not null primary key autoincrement,
258
- action varchar not null,
259
- message varchar not null,
260
- data varchar null,
261
- created_at varchar not null,
262
- crowdin_id varchar not null,
263
- integration_id varchar null
264
- );
265
- `, []);
266
- yield this._run(`
267
- create table if not exists integration_settings
268
- (
269
- id integer not null primary key autoincrement,
270
- integration_id varchar not null,
271
- crowdin_id varchar not null,
272
- config varchar null
273
- );
274
- `, []);
275
- yield this._run(`
276
- create table if not exists job
277
- (
278
- id varchar not null primary key,
279
- integration_id varchar not null,
280
- crowdin_id varchar not null,
281
- type varchar not null,
282
- title varchar null,
283
- progress integer DEFAULT 0,
284
- status varchar DEFAULT '${types_2.JobStatus.CREATED}',
285
- payload varchar null,
286
- info varchar null,
287
- data varchar null,
288
- attempt varchar DEFAULT 0,
289
- created_at varchar not null,
290
- updated_at varchar null,
291
- finished_at varchar null
292
- );
293
- `, []);
294
- yield this._run(`
295
- create table if not exists translation_file_cache
296
- (
297
- id integer not null primary key autoincrement,
298
- integration_id varchar not null,
299
- crowdin_id varchar not null,
300
- file_id integer not null,
301
- language_id varchar not null,
302
- etag varchar
303
- );
304
- `, []);
283
+ for (const [tableName, tableSchema] of Object.entries(this.tables)) {
284
+ yield this._run(`create table if not exists ${tableName} ${tableSchema};`, []);
285
+ }
305
286
  this._res && this._res();
306
287
  // TODO: temporary code
307
288
  yield this.updateTables();
@@ -365,6 +346,7 @@ class SQLiteStorage {
365
346
  yield this.run('DELETE FROM integration_settings WHERE crowdin_id = ?', [id]);
366
347
  yield this.run('DELETE FROM job WHERE crowdin_id = ?', [id]);
367
348
  yield this.run('DELETE FROM translation_file_cache WHERE crowdin_id = ?', [id]);
349
+ yield this.run('DELETE FROM unsynced_files WHERE crowdin_id = ?', [id]);
368
350
  });
369
351
  }
370
352
  saveIntegrationCredentials(id, credentials, crowdinId) {
@@ -398,6 +380,7 @@ class SQLiteStorage {
398
380
  yield this.run('DELETE FROM files_snapshot where integration_id = ?', [id]);
399
381
  yield this.run('DELETE FROM webhooks where integration_id = ?', [id]);
400
382
  yield this.run('DELETE FROM job where integration_id = ?', [id]);
383
+ yield this.run('DELETE FROM unsynced_files where integration_id = ?', [id]);
401
384
  });
402
385
  }
403
386
  deleteAllIntegrationCredentials(crowdinId) {
@@ -408,6 +391,7 @@ class SQLiteStorage {
408
391
  yield this.run('DELETE FROM webhooks where crowdin_id = ?', [crowdinId]);
409
392
  yield this.run('DELETE FROM user_errors where crowdin_id = ?', [crowdinId]);
410
393
  yield this.run('DELETE FROM job where crowdin_id = ?', [crowdinId]);
394
+ yield this.run('DELETE FROM unsynced_files where crowdin_id = ?', [crowdinId]);
411
395
  });
412
396
  }
413
397
  saveMetadata(id, metadata, crowdinId) {
@@ -681,5 +665,31 @@ class SQLiteStorage {
681
665
  WHERE integration_id = ? AND crowdin_id = ? AND file_id = ? AND language_id = ?
682
666
  `, [etag, integrationId, crowdinId, fileId, languageId]);
683
667
  }
668
+ saveUnsyncedFiles({ integrationId, crowdinId, files }) {
669
+ return this.run(`
670
+ INSERT
671
+ INTO unsynced_files(integration_id, crowdin_id, files)
672
+ VALUES (?, ?, ?)
673
+ `, [integrationId, crowdinId, files]);
674
+ }
675
+ updateUnsyncedFiles({ integrationId, crowdinId, files }) {
676
+ return this.run(`
677
+ UPDATE unsynced_files
678
+ SET files = ?
679
+ WHERE integration_id = ? AND crowdin_id = ?
680
+ `, [files, integrationId, crowdinId]);
681
+ }
682
+ getUnsyncedFiles({ integrationId, crowdinId }) {
683
+ return __awaiter(this, void 0, void 0, function* () {
684
+ const row = yield this.get(`
685
+ SELECT files
686
+ FROM unsynced_files
687
+ WHERE integration_id = ? AND crowdin_id = ?
688
+ `, [integrationId, crowdinId]);
689
+ if (row) {
690
+ return row;
691
+ }
692
+ });
693
+ }
684
694
  }
685
695
  exports.SQLiteStorage = SQLiteStorage;
package/out/types.d.ts CHANGED
@@ -456,6 +456,6 @@ export interface SignaturePatterns {
456
456
  export declare enum storageFiles {
457
457
  SQLITE = "app.sqlite",
458
458
  SQLITE_BACKUP = "backup_app.sqlite",
459
- DUMP_CHUNK = "dump_chunk_%d.sql"
459
+ DUMP = "dump_table_%s.sql"
460
460
  }
461
461
  export {};
package/out/types.js CHANGED
@@ -70,5 +70,5 @@ var storageFiles;
70
70
  (function (storageFiles) {
71
71
  storageFiles["SQLITE"] = "app.sqlite";
72
72
  storageFiles["SQLITE_BACKUP"] = "backup_app.sqlite";
73
- storageFiles["DUMP_CHUNK"] = "dump_chunk_%d.sql";
73
+ storageFiles["DUMP"] = "dump_table_%s.sql";
74
74
  })(storageFiles = exports.storageFiles || (exports.storageFiles = {}));
@@ -15,3 +15,7 @@ export declare function getPreviousDate(days: number): Date;
15
15
  export declare function prepareFormDataMetadataId(req: CrowdinClientRequest, config: Config): Promise<string>;
16
16
  export declare function validateEmail(email: string | number): boolean;
17
17
  export declare function isApiRequest(req: Request, config: Config): boolean;
18
+ export declare function getFormattedDate({ date, userTimezone }: {
19
+ date: Date | number;
20
+ userTimezone: string | undefined;
21
+ }): string;
package/out/util/index.js CHANGED
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.isApiRequest = exports.validateEmail = exports.prepareFormDataMetadataId = exports.getPreviousDate = exports.isJson = exports.isAuthorizedConfig = exports.getLogoUrl = exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.CodeError = void 0;
35
+ exports.getFormattedDate = exports.isApiRequest = exports.validateEmail = exports.prepareFormDataMetadataId = exports.getPreviousDate = exports.isJson = exports.isAuthorizedConfig = exports.getLogoUrl = exports.executeWithRetry = exports.decryptData = exports.encryptData = exports.runAsyncWrapper = exports.CodeError = void 0;
36
36
  const crypto = __importStar(require("crypto-js"));
37
37
  const storage_1 = require("../storage");
38
38
  const types_1 = require("../types");
@@ -167,3 +167,19 @@ function isApiRequest(req, config) {
167
167
  return !origin || !origin.includes(config.baseUrl);
168
168
  }
169
169
  exports.isApiRequest = isApiRequest;
170
+ // Format the date as 'MMM DD, YYYY HH:mm'
171
+ function getFormattedDate({ date, userTimezone }) {
172
+ if (!userTimezone) {
173
+ userTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
174
+ }
175
+ return new Intl.DateTimeFormat('en-US', {
176
+ year: 'numeric',
177
+ month: 'short',
178
+ day: 'numeric',
179
+ hour: '2-digit',
180
+ minute: '2-digit',
181
+ hour12: false,
182
+ timeZone: userTimezone,
183
+ }).format(date);
184
+ }
185
+ exports.getFormattedDate = getFormattedDate;
@@ -296,20 +296,20 @@
296
296
  {{/ifeq}}
297
297
  {{#ifeq type "text"}}
298
298
  <crowdin-input
299
- id="{{key}}-settings"
300
- label="{{label}}"
301
- key="{{key}}"
302
- with-fixed-height
303
- {{#if helpText}}
304
- help-text="{{helpText}}"
305
- {{/if}}
306
- {{#if helpTextHtml}}
307
- help-text-html="{{helpTextHtml}}"
308
- {{/if}}
309
- {{#if dependencySettings}}
310
- data-dependency="{{dependencySettings}}"
311
- {{/if}}
312
- value="{{#if defaultValue}}{{defaultValue}}{{/if}}"
299
+ id="{{key}}-settings"
300
+ label="{{label}}"
301
+ key="{{key}}"
302
+ with-fixed-height
303
+ {{#if helpText}}
304
+ help-text="{{helpText}}"
305
+ {{/if}}
306
+ {{#if helpTextHtml}}
307
+ help-text-html="{{helpTextHtml}}"
308
+ {{/if}}
309
+ {{#if dependencySettings}}
310
+ data-dependency="{{dependencySettings}}"
311
+ {{/if}}
312
+ value="{{#if defaultValue}}{{defaultValue}}{{/if}}"
313
313
  >
314
314
  </crowdin-input>
315
315
  {{/ifeq}}
@@ -350,21 +350,21 @@
350
350
  {{/ifeq}}
351
351
  {{else}}
352
352
  {{#if labelHtml}}
353
- <crowdin-p
354
- {{#if dependencySettings}}
355
- data-dependency="{{dependencySettings}}"
356
- {{/if}}
357
- >
358
- {{{labelHtml}}}
359
- </crowdin-p>
353
+ <crowdin-p
354
+ {{#if dependencySettings}}
355
+ data-dependency="{{dependencySettings}}"
356
+ {{/if}}
357
+ >
358
+ {{{labelHtml}}}
359
+ </crowdin-p>
360
360
  {{else}}
361
- <crowdin-p
362
- {{#if dependencySettings}}
363
- data-dependency="{{dependencySettings}}"
364
- {{/if}}
365
- >
366
- {{label}}
367
- </crowdin-p>
361
+ <crowdin-p
362
+ {{#if dependencySettings}}
363
+ data-dependency="{{dependencySettings}}"
364
+ {{/if}}
365
+ >
366
+ {{label}}
367
+ </crowdin-p>
368
368
  {{/if}}
369
369
  {{/if}}
370
370
  <div
@@ -391,19 +391,19 @@
391
391
  body-overflow-unset
392
392
  >
393
393
  <crowdin-checkbox
394
- id="selected-files"
395
- name="selected-files"
396
- label="Selected files"
397
- class="hydrated"
398
- onchange="onChangeAutoSynchronizationOptions(this)"
394
+ id="selected-files"
395
+ name="selected-files"
396
+ label="Selected files"
397
+ class="hydrated"
398
+ onchange="onChangeAutoSynchronizationOptions(this)"
399
399
  >
400
400
  </crowdin-checkbox>
401
401
  <crowdin-checkbox
402
- id="new-files"
403
- name="new-files"
404
- label="New files"
405
- class="hydrated"
406
- onchange="onChangeAutoSynchronizationOptions(this)"
402
+ id="new-files"
403
+ name="new-files"
404
+ label="New files"
405
+ class="hydrated"
406
+ onchange="onChangeAutoSynchronizationOptions(this)"
407
407
  >
408
408
  </crowdin-checkbox>
409
409
  <div slot="footer">
@@ -510,6 +510,7 @@
510
510
  if (e.type) {
511
511
  item.type = e.type;
512
512
  item.node_type = fileType;
513
+ item.failed = e.failed;
513
514
  } else {
514
515
  item.node_type = e.nodeType || folderType;
515
516
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.75.0",
3
+ "version": "0.76.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",