@crowdin/app-project-module 0.60.3 → 0.62.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.
@@ -1,6 +1,6 @@
1
1
  import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks, Provider } from '../modules/integration/types';
2
2
  import { Config, CrowdinCredentials, UnauthorizedConfig } from '../types';
3
- import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../modules/integration/util/types';
3
+ import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetTranslationCacheParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams } from '../modules/integration/util/types';
4
4
  import { UserErrors } from './types';
5
5
  export interface Storage {
6
6
  migrate(): Promise<void>;
@@ -43,6 +43,9 @@ export interface Storage {
43
43
  getJob(params: GetJobParams): Promise<Job | undefined>;
44
44
  getActiveJobs(params: GetActiveJobsParams): Promise<Job[] | undefined>;
45
45
  deleteFinishedJobs(): Promise<void>;
46
+ saveTranslationCache(params: TranslationCache): Promise<void>;
47
+ getTranslationCache(params: GetTranslationCacheParams): Promise<TranslationCache | undefined>;
48
+ updateTranslationCache(params: UpdateTranslationCacheParams): Promise<void>;
46
49
  }
47
50
  export declare function initialize(config: Config | UnauthorizedConfig): Promise<void>;
48
51
  export declare function getStorage(): Storage;
@@ -1,6 +1,6 @@
1
1
  import { Storage } from '.';
2
2
  import { CrowdinCredentials } from '../types';
3
- import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../modules/integration/util/types';
3
+ import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetTranslationCacheParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams } from '../modules/integration/util/types';
4
4
  import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
5
5
  import { UserErrors } from './types';
6
6
  export interface MySQLStorageConfig {
@@ -60,4 +60,7 @@ export declare class MySQLStorage implements Storage {
60
60
  getJob({ id }: GetJobParams): Promise<Job | undefined>;
61
61
  getActiveJobs({ integrationId, crowdinId }: GetActiveJobsParams): Promise<Job[] | undefined>;
62
62
  deleteFinishedJobs(): Promise<void>;
63
+ saveTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }: TranslationCache): Promise<void>;
64
+ getTranslationCache({ integrationId, crowdinId, fileId, languageId, }: GetTranslationCacheParams): Promise<TranslationCache | undefined>;
65
+ updateTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }: UpdateTranslationCacheParams): Promise<void>;
63
66
  }
@@ -166,6 +166,17 @@ class MySQLStorage {
166
166
  finished_at varchar(255)
167
167
  )
168
168
  `);
169
+ yield connection.execute(`
170
+ create table if not exists translation_file_cache
171
+ (
172
+ id int auto_increment primary key,
173
+ integration_id varchar(255) not null,
174
+ crowdin_id varchar(255) not null,
175
+ file_id int not null,
176
+ language_id varchar(255) not null,
177
+ etag varchar(255)
178
+ )
179
+ `);
169
180
  });
170
181
  }
171
182
  saveCrowdinCredentials(credentials) {
@@ -234,6 +245,7 @@ class MySQLStorage {
234
245
  yield connection.execute('DELETE FROM user_errors WHERE crowdin_id = ?', [id]);
235
246
  yield connection.execute('DELETE FROM integration_settings WHERE crowdin_id = ?', [id]);
236
247
  yield connection.execute('DELETE FROM job WHERE crowdin_id = ?', [id]);
248
+ yield connection.execute('DELETE FROM translation_file_cache WHERE crowdin_id = ?', [id]);
237
249
  }));
238
250
  });
239
251
  }
@@ -577,5 +589,37 @@ class MySQLStorage {
577
589
  yield this.executeQuery((connection) => connection.execute('DELETE FROM job WHERE finished_at is not NULL', []));
578
590
  });
579
591
  }
592
+ saveTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }) {
593
+ return __awaiter(this, void 0, void 0, function* () {
594
+ yield this.dbPromise;
595
+ yield this.executeQuery((connection) => connection.execute(`
596
+ INSERT INTO translation_file_cache(integration_id, crowdin_id, file_id, language_id, etag)
597
+ VALUES (?, ?, ?, ?, ?)
598
+ `, [integrationId, crowdinId, fileId, languageId, etag]));
599
+ });
600
+ }
601
+ getTranslationCache({ integrationId, crowdinId, fileId, languageId, }) {
602
+ return __awaiter(this, void 0, void 0, function* () {
603
+ yield this.dbPromise;
604
+ return this.executeQuery((connection) => __awaiter(this, void 0, void 0, function* () {
605
+ const [rows] = yield connection.execute(`
606
+ SELECT integration_id as integrationId, crowdin_id as crowdin_id, file_id as fileId, language_id as languageId
607
+ FROM translation_file_cache
608
+ WHERE integration_id = ? AND crowdin_id = ? AND file_id = ? AND language_id = ?
609
+ `, [integrationId, crowdinId, fileId, languageId]);
610
+ return (rows || [])[0];
611
+ }));
612
+ });
613
+ }
614
+ updateTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }) {
615
+ return __awaiter(this, void 0, void 0, function* () {
616
+ yield this.dbPromise;
617
+ yield this.executeQuery((connection) => connection.execute(`
618
+ UPDATE translation_file_cache
619
+ SET etag = ?
620
+ WHERE integration_id = ? AND crowdin_id = ? AND file_id = ? AND language_id = ?
621
+ `, [etag, integrationId, crowdinId, fileId, languageId]));
622
+ });
623
+ }
580
624
  }
581
625
  exports.MySQLStorage = MySQLStorage;
@@ -2,7 +2,7 @@ import { Client } from 'pg';
2
2
  import { Storage } from '.';
3
3
  import { CrowdinCredentials } from '../types';
4
4
  import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
5
- import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../modules/integration/util/types';
5
+ import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetTranslationCacheParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams } from '../modules/integration/util/types';
6
6
  import { UserErrors } from './types';
7
7
  export interface PostgreStorageConfig {
8
8
  host?: string;
@@ -66,4 +66,7 @@ export declare class PostgreStorage implements Storage {
66
66
  getJob({ id }: GetJobParams): Promise<Job | undefined>;
67
67
  getActiveJobs({ integrationId, crowdinId }: GetActiveJobsParams): Promise<Job[] | undefined>;
68
68
  deleteFinishedJobs(): Promise<void>;
69
+ saveTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }: TranslationCache): Promise<void>;
70
+ getTranslationCache({ integrationId, crowdinId, fileId, languageId, }: GetTranslationCacheParams): Promise<TranslationCache | undefined>;
71
+ updateTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }: UpdateTranslationCacheParams): Promise<void>;
69
72
  }
@@ -183,6 +183,17 @@ class PostgreStorage {
183
183
  finished_at varchar null
184
184
  )
185
185
  `);
186
+ yield client.query(`
187
+ create table if not exists translation_file_cache
188
+ (
189
+ id serial primary key,
190
+ integration_id varchar not null,
191
+ crowdin_id varchar not null,
192
+ file_id int not null,
193
+ language_id varchar not null,
194
+ etag varchar
195
+ )
196
+ `);
186
197
  });
187
198
  }
188
199
  saveCrowdinCredentials(credentials) {
@@ -251,6 +262,7 @@ class PostgreStorage {
251
262
  yield client.query('DELETE FROM user_errors WHERE crowdin_id = $1', [id]);
252
263
  yield client.query('DELETE FROM integration_settings WHERE crowdin_id = $1', [id]);
253
264
  yield client.query('DELETE FROM job WHERE crowdin_id = $1', [id]);
265
+ yield client.query('DELETE FROM translation_file_cache WHERE crowdin_id = $1', [id]);
254
266
  }));
255
267
  });
256
268
  }
@@ -597,5 +609,38 @@ class PostgreStorage {
597
609
  yield this.executeQuery((client) => client.query(' DELETE FROM job WHERE finished_at is not NULL', []));
598
610
  });
599
611
  }
612
+ saveTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }) {
613
+ return __awaiter(this, void 0, void 0, function* () {
614
+ yield this.dbPromise;
615
+ yield this.executeQuery((client) => client.query(`
616
+ INSERT
617
+ INTO translation_file_cache(integration_id, crowdin_id, file_id, language_id, etag)
618
+ VALUES ($1, $2, $3, $4, $4)
619
+ `, [integrationId, crowdinId, fileId, languageId, etag]));
620
+ });
621
+ }
622
+ getTranslationCache({ integrationId, crowdinId, fileId, languageId, }) {
623
+ return __awaiter(this, void 0, void 0, function* () {
624
+ yield this.dbPromise;
625
+ return this.executeQuery((client) => __awaiter(this, void 0, void 0, function* () {
626
+ const res = yield client.query(`
627
+ SELECT integration_id as integrationId, crowdin_id as crowdinId, file_id as fileId, language_id as languageId
628
+ FROM translation_file_cache
629
+ WHERE integration_id = $1 AND crowdin_id = $2 AND file_id = $3 AND language_id = $4
630
+ `, [integrationId, crowdinId, fileId, languageId]);
631
+ return res === null || res === void 0 ? void 0 : res.rows[0];
632
+ }));
633
+ });
634
+ }
635
+ updateTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }) {
636
+ return __awaiter(this, void 0, void 0, function* () {
637
+ yield this.dbPromise;
638
+ yield this.executeQuery((client) => client.query(`
639
+ UPDATE translation_file_cache
640
+ SET etag = $1
641
+ WHERE integration_id = $2 AND crowdin_id = $3 AND file_id = $4 AND language_id = $5
642
+ `, [etag, integrationId, crowdinId, fileId, languageId]));
643
+ });
644
+ }
600
645
  }
601
646
  exports.PostgreStorage = PostgreStorage;
@@ -1,7 +1,7 @@
1
1
  import { Storage } from '.';
2
2
  import { CrowdinCredentials } from '../types';
3
3
  import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
4
- import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../modules/integration/util/types';
4
+ import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetTranslationCacheParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams } from '../modules/integration/util/types';
5
5
  import { UserErrors } from './types';
6
6
  export interface SQLiteStorageConfig {
7
7
  dbFolder: string;
@@ -61,4 +61,7 @@ export declare class SQLiteStorage implements Storage {
61
61
  getJob({ id }: GetJobParams): Promise<Job | undefined>;
62
62
  getActiveJobs({ integrationId, crowdinId }: GetActiveJobsParams): Promise<Job[] | undefined>;
63
63
  deleteFinishedJobs(): Promise<void>;
64
+ saveTranslationCache({ integrationId, crowdinId, fileId, languageId, etag }: TranslationCache): Promise<void>;
65
+ getTranslationCache({ integrationId, crowdinId, fileId, languageId, }: GetTranslationCacheParams): Promise<TranslationCache | undefined>;
66
+ updateTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }: UpdateTranslationCacheParams): Promise<void>;
64
67
  }
@@ -256,6 +256,17 @@ class SQLiteStorage {
256
256
  updated_at varchar null,
257
257
  finished_at varchar null
258
258
  );
259
+ `, []);
260
+ yield this._run(`
261
+ create table if not exists translation_file_cache
262
+ (
263
+ id integer not null primary key autoincrement,
264
+ integration_id varchar not null,
265
+ crowdin_id varchar not null,
266
+ file_id integer not null,
267
+ language_id varchar not null,
268
+ etag varchar
269
+ );
259
270
  `, []);
260
271
  this._res && this._res();
261
272
  // TODO: temporary code
@@ -318,6 +329,7 @@ class SQLiteStorage {
318
329
  yield this.run('DELETE FROM user_errors WHERE crowdin_id = ?', [id]);
319
330
  yield this.run('DELETE FROM integration_settings WHERE crowdin_id = ?', [id]);
320
331
  yield this.run('DELETE FROM job WHERE crowdin_id = ?', [id]);
332
+ yield this.run('DELETE FROM translation_file_cache WHERE crowdin_id = ?', [id]);
321
333
  });
322
334
  }
323
335
  saveIntegrationCredentials(id, credentials, crowdinId) {
@@ -575,5 +587,31 @@ class SQLiteStorage {
575
587
  yield this.run('DELETE FROM job WHERE finished_at is not NULL', []);
576
588
  });
577
589
  }
590
+ saveTranslationCache({ integrationId, crowdinId, fileId, languageId, etag }) {
591
+ return this.run(`
592
+ INSERT
593
+ INTO translation_file_cache(integration_id, crowdin_id, file_id, language_id, etag)
594
+ VALUES (?, ?, ?, ?, ?)
595
+ `, [integrationId, crowdinId, fileId, languageId, etag]);
596
+ }
597
+ getTranslationCache({ integrationId, crowdinId, fileId, languageId, }) {
598
+ return __awaiter(this, void 0, void 0, function* () {
599
+ const row = yield this.get(`
600
+ SELECT integration_id as integrationId, crowdin_id as crowdinId, file_id as fileId, language_id as languageId, etag
601
+ FROM translation_file_cache
602
+ WHERE integration_id = ? AND crowdin_id = ? AND file_id = ? AND language_id = ?
603
+ `, [integrationId, crowdinId, fileId, languageId]);
604
+ if (row) {
605
+ return row;
606
+ }
607
+ });
608
+ }
609
+ updateTranslationCache({ integrationId, crowdinId, fileId, languageId, etag, }) {
610
+ return this.run(`
611
+ UPDATE translation_file_cache
612
+ SET etag = ?
613
+ WHERE integration_id = ? AND crowdin_id = ? AND file_id = ? AND language_id = ?
614
+ `, [etag, integrationId, crowdinId, fileId, languageId]);
615
+ }
578
616
  }
579
617
  exports.SQLiteStorage = SQLiteStorage;
@@ -905,12 +905,48 @@
905
905
  scheduleModal.close();
906
906
  }
907
907
 
908
- function openScheduleModal(type) {
908
+ async function openScheduleModal(type) {
909
909
  const newFile = scheduleModal.querySelector('#new-files')
910
910
  const selectedFiles = scheduleModal.querySelector('#selected-files');
911
+ let newFileStatus = 'unChecked';
912
+
913
+ const integrationSyncFolders = (await document.querySelector('crowdin-simple-integration').getIntegrationScheduleSync(true))
914
+ .filter(elements => elements.node_type === '0');
915
+
916
+ const selectedIntegrationFolders = (await document.getElementById('integration-files').getSelected(true))
917
+ .filter(elements => elements.node_type === '0');
918
+
919
+ for (let i = 0; i < selectedIntegrationFolders.length; i++) {
920
+ const selectedElement = selectedIntegrationFolders[i];
921
+
922
+ const found = integrationSyncFolders.some(integrationElement =>
923
+ integrationElement.id === selectedElement.id
924
+ );
925
+
926
+ if (found) {
927
+ newFileStatus = 'checked';
928
+ } else if (!found && newFileStatus === 'checked') {
929
+ newFileStatus = 'clear-selection';
930
+ break;
931
+ } else {
932
+ newFileStatus = 'unChecked';
933
+ }
934
+ }
935
+
936
+ if (newFileStatus === 'checked') {
937
+ newFile[newFileStatus] = true;
938
+ newFile.value = true;
939
+ newFile.removeAttribute('clear-selection');
940
+ } else if (newFileStatus === 'clear-selection') {
941
+ newFile.checked = false;
942
+ newFile.value = false;
943
+ newFile.setAttribute(newFileStatus, '');
944
+ } else {
945
+ newFile.checked = false;
946
+ newFile.value = false;
947
+ newFile.removeAttribute('clear-selection');
948
+ }
911
949
 
912
- newFile.checked = false;
913
- newFile.value = false;
914
950
  selectedFiles.checked = true;
915
951
  selectedFiles.value = true;
916
952
  scheduleModal.querySelector('#save-schedule-sync').setAttribute('disabled', false);
@@ -919,11 +955,14 @@
919
955
  }
920
956
 
921
957
  function onChangeAutoSynchronizationOptions() {
922
- const newFiles = document.getElementById('new-files').checked || false;
958
+ const newFiles = document.getElementById('new-files');
959
+ newFiles.removeAttribute('clear-selection');
960
+
961
+ const newFilesStatus = newFiles.checked || false;
923
962
  const selectedFiles = document.getElementById('selected-files').checked || false;
924
963
  const buttonSaveScheduleSync = document.getElementById('save-schedule-sync');
925
964
 
926
- if (newFiles || selectedFiles) {
965
+ if (newFilesStatus || selectedFiles) {
927
966
  buttonSaveScheduleSync.removeAttribute('disabled');
928
967
  } else {
929
968
  buttonSaveScheduleSync.setAttribute('disabled', true);
@@ -953,7 +992,7 @@
953
992
  syncData = e.detail;
954
993
  const isFolder = await hasFolder(e.detail);
955
994
  if (isFolder && !newIntegrationFiles) {
956
- openScheduleModal('integration');
995
+ await openScheduleModal('integration');
957
996
  return;
958
997
  }
959
998
 
@@ -981,7 +1020,7 @@
981
1020
  syncData = e.detail;
982
1021
  const isFolder = await hasFolder(e.detail);
983
1022
  if (isFolder && !newCrowdinFiles) {
984
- openScheduleModal('crowdin');
1023
+ await openScheduleModal('crowdin');
985
1024
  return;
986
1025
  }
987
1026
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.60.3",
3
+ "version": "0.62.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",