@crowdin/app-project-module 1.9.0 → 1.11.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.
Files changed (30) hide show
  1. package/out/modules/api/api.js +323 -18
  2. package/out/modules/api/components.d.ts +222 -19
  3. package/out/modules/api/components.js +222 -19
  4. package/out/modules/custom-mt/index.js +2 -1
  5. package/out/modules/file-processing/handlers/file-download.js +2 -1
  6. package/out/modules/file-processing/handlers/pre-post-process.js +2 -1
  7. package/out/modules/file-processing/handlers/translations-alignment.js +2 -1
  8. package/out/modules/file-processing/index.js +3 -2
  9. package/out/modules/file-processing/util/folder.d.ts +1 -0
  10. package/out/modules/file-processing/util/folder.js +13 -0
  11. package/out/modules/integration/handlers/crowdin-file-progress.js +5 -2
  12. package/out/modules/integration/handlers/integration-data.js +14 -2
  13. package/out/modules/integration/handlers/job-list.js +4 -1
  14. package/out/modules/integration/handlers/settings-save.js +85 -42
  15. package/out/modules/integration/handlers/settings-schema.d.ts +3 -0
  16. package/out/modules/integration/handlers/settings-schema.js +29 -0
  17. package/out/modules/integration/handlers/sync-settings-save.js +57 -3
  18. package/out/modules/integration/handlers/sync-settings.js +11 -3
  19. package/out/modules/integration/types.d.ts +7 -0
  20. package/out/modules/integration/util/files.js +19 -7
  21. package/out/modules/integration/util/job.d.ts +2 -1
  22. package/out/modules/integration/util/job.js +3 -2
  23. package/out/modules/integration/util/types.d.ts +4 -2
  24. package/out/modules/integration/util/types.js +2 -0
  25. package/out/static/ui/main.bundle.js +94 -3
  26. package/out/static/ui/main.bundle.js.map +1 -1
  27. package/out/util/index.js +3 -1
  28. package/out/util/logger.d.ts +1 -0
  29. package/out/util/logger.js +7 -0
  30. package/package.json +14 -9
@@ -9,7 +9,8 @@ export declare enum JobType {
9
9
  UPDATE_TO_INTEGRATION = "updateIntegration",
10
10
  UPDATE_TARGET_LANGUAGES = "updateTargetLanguages",
11
11
  CROWDIN_SYNC_SETTINGS_SAVE = "crowdinSyncSettingsSave",
12
- INTEGRATION_SYNC_SETTINGS_SAVE = "integrationSyncSettingsSave"
12
+ INTEGRATION_SYNC_SETTINGS_SAVE = "integrationSyncSettingsSave",
13
+ INTEGRATION_SETTINGS_SAVE = "integrationSettingsSave"
13
14
  }
14
15
  export declare enum JobStatus {
15
16
  CREATED = "created",
@@ -21,7 +22,8 @@ export declare enum JobStatus {
21
22
  export declare enum JobClientType {
22
23
  CRON = "cron",
23
24
  MANUAL = "manual",
24
- RERUN = "rerun"
25
+ RERUN = "rerun",
26
+ HIDDEN = "hidden"
25
27
  }
26
28
  export type JobStoreType = 'db' | 'in-memory';
27
29
  export interface Job {
@@ -8,6 +8,7 @@ var JobType;
8
8
  JobType["UPDATE_TARGET_LANGUAGES"] = "updateTargetLanguages";
9
9
  JobType["CROWDIN_SYNC_SETTINGS_SAVE"] = "crowdinSyncSettingsSave";
10
10
  JobType["INTEGRATION_SYNC_SETTINGS_SAVE"] = "integrationSyncSettingsSave";
11
+ JobType["INTEGRATION_SETTINGS_SAVE"] = "integrationSettingsSave";
11
12
  })(JobType || (exports.JobType = JobType = {}));
12
13
  var JobStatus;
13
14
  (function (JobStatus) {
@@ -22,4 +23,5 @@ var JobClientType;
22
23
  JobClientType["CRON"] = "cron";
23
24
  JobClientType["MANUAL"] = "manual";
24
25
  JobClientType["RERUN"] = "rerun";
26
+ JobClientType["HIDDEN"] = "hidden";
25
27
  })(JobClientType || (exports.JobClientType = JobClientType = {}));
@@ -566,6 +566,7 @@
566
566
  updateTargetLanguages: 'updateTargetLanguages',
567
567
  integrationSyncSettingsSave: 'integrationSyncSettingsSave',
568
568
  crowdinSyncSettingsSave: 'crowdinSyncSettingsSave',
569
+ integrationSettingsSave: 'integrationSettingsSave',
569
570
  };
570
571
  const JOB_STATUS = {
571
572
  created: 'created',
@@ -574,7 +575,7 @@
574
575
  canceled: 'canceled',
575
576
  finished: 'finished',
576
577
  };
577
- const silentJobs = [JOB_TYPE.integrationSyncSettingsSave, JOB_TYPE.crowdinSyncSettingsSave];
578
+ const silentJobs = [JOB_TYPE.integrationSettingsSave];
578
579
  const appComponent = reactExports.useRef(null);
579
580
  const subscriptionModal = reactExports.useRef(null);
580
581
  const languageModal = reactExports.useRef(null);
@@ -949,11 +950,65 @@
949
950
  }
950
951
  });
951
952
  }
953
+ function isScheduleDisabled(currentConfig = config.current) {
954
+ var _a;
955
+ return String((_a = currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig.schedule) !== null && _a !== void 0 ? _a : '0') === '0';
956
+ }
957
+ async function applyAutoSyncPausedMarkers(provider, syncSettingsFiles = []) {
958
+ var _a, _b, _c, _d;
959
+ const isDisabled = isScheduleDisabled();
960
+ const configuredIds = new Set((Array.isArray(syncSettingsFiles) ? syncSettingsFiles : []).map((item) => `${item.id}`));
961
+ const getChangedItems = (tree = []) => tree
962
+ .map((item) => {
963
+ const nextScheduleDisabled = Boolean(item.schedule) && isDisabled && configuredIds.has(`${item.id}`);
964
+ const currentScheduleDisabled = Boolean(item.scheduleDisabled);
965
+ if (currentScheduleDisabled === nextScheduleDisabled) {
966
+ return null;
967
+ }
968
+ return {
969
+ ...item,
970
+ scheduleDisabled: nextScheduleDisabled,
971
+ };
972
+ })
973
+ .filter(Boolean);
974
+ if (provider === 'crowdin') {
975
+ const changedItems = getChangedItems(crowdinData.current || []);
976
+ if (changedItems.length) {
977
+ const changedById = new Map(changedItems.map((item) => [`${item.id}`, item]));
978
+ crowdinData.current = (crowdinData.current || []).map((item) => changedById.get(`${item.id}`) || item);
979
+ (_a = appComponent.current) === null || _a === void 0 ? void 0 : _a.updateCrowdinFileData(changedItems);
980
+ }
981
+ return;
982
+ }
983
+ const integrationData = await ((_c = (_b = appComponent.current) === null || _b === void 0 ? void 0 : _b.getIntegrationFilesData) === null || _c === void 0 ? void 0 : _c.call(_b));
984
+ if (Array.isArray(integrationData)) {
985
+ const changedItems = getChangedItems(integrationData);
986
+ if (changedItems.length) {
987
+ (_d = appComponent.current) === null || _d === void 0 ? void 0 : _d.updateIntegrationFileData(changedItems);
988
+ }
989
+ }
990
+ }
991
+ async function fetchSyncSettingsFiles(provider) {
992
+ const restParams = await checkOrigin();
993
+ const res = await fetch(`/api/sync-settings/${provider}` + restParams).then(checkResponse);
994
+ return Array.isArray(res) ? res : [];
995
+ }
996
+ async function refreshAutoSyncPausedIndicatorsAndWarning() {
997
+ const [crowdinSyncSettings, integrationSyncSettings] = await Promise.all([
998
+ fetchSyncSettingsFiles('crowdin'),
999
+ fetchSyncSettingsFiles('integration'),
1000
+ ]);
1001
+ await applyAutoSyncPausedMarkers('crowdin', crowdinSyncSettings);
1002
+ await applyAutoSyncPausedMarkers('integration', integrationSyncSettings);
1003
+ if (isScheduleDisabled() && (crowdinSyncSettings.length || integrationSyncSettings.length)) {
1004
+ showToast('Auto Sync is configured for some files, but sync schedule is disabled in app settings.');
1005
+ }
1006
+ }
952
1007
  function getSyncSettings(provider) {
953
1008
  checkOrigin()
954
1009
  .then((restParams) => fetch(`/api/sync-settings/${provider}` + restParams))
955
1010
  .then(checkResponse)
956
- .then((res) => {
1011
+ .then(async (res) => {
957
1012
  if (provider === 'crowdin') {
958
1013
  if (syncNewElements === null || syncNewElements === void 0 ? void 0 : syncNewElements.crowdin) {
959
1014
  appComponent.current.setCrowdinScheduleSync(res, true, true);
@@ -970,6 +1025,7 @@
970
1025
  appComponent.current.setIntegrationScheduleSync(res);
971
1026
  }
972
1027
  }
1028
+ await applyAutoSyncPausedMarkers(provider, res);
973
1029
  })
974
1030
  .catch((e) => catchRejection(e, "Can't fetch file progress"));
975
1031
  }
@@ -1708,6 +1764,8 @@
1708
1764
  });
1709
1765
  });
1710
1766
  let isValidationError = false;
1767
+ let isSettingsSaveJobPending = false;
1768
+ let isSettingsSaveFailed = false;
1711
1769
  settingsSaveBtn.setAttribute('disabled', true);
1712
1770
  checkOrigin()
1713
1771
  .then((restParams) => fetch('api/settings' + restParams, {
@@ -1716,9 +1774,39 @@
1716
1774
  body: JSON.stringify({ config: configReq }),
1717
1775
  }))
1718
1776
  .then(checkResponse)
1719
- .then(() => {
1777
+ .then((res) => {
1778
+ if (res === null || res === void 0 ? void 0 : res.jobId) {
1779
+ isSettingsSaveJobPending = true;
1780
+ checkJob({
1781
+ jobId: res.jobId,
1782
+ jobType: JOB_TYPE.integrationSettingsSave,
1783
+ onSuccess: () => {
1784
+ showToast('Settings successfully saved');
1785
+ config.current = configReq;
1786
+ refreshAutoSyncPausedIndicatorsAndWarning().catch((e) => catchRejection(e, "Can't fetch sync settings warning"));
1787
+ },
1788
+ onError: () => {
1789
+ isSettingsSaveFailed = true;
1790
+ showToast("Can't save settings");
1791
+ },
1792
+ onFinally: () => {
1793
+ unsetLoader('#settings-modal');
1794
+ settingsSaveBtn.removeAttribute('disabled');
1795
+ if (!isValidationError && !isSettingsSaveFailed) {
1796
+ const settingsModal = document.getElementById('settings-modal');
1797
+ closeModal(settingsModal);
1798
+ if (reloadOnConfigSave) {
1799
+ getIntegrationData({ hardReload: true });
1800
+ getCrowdinData();
1801
+ }
1802
+ }
1803
+ },
1804
+ });
1805
+ return;
1806
+ }
1720
1807
  showToast('Settings successfully saved');
1721
1808
  config.current = configReq;
1809
+ refreshAutoSyncPausedIndicatorsAndWarning().catch((e) => catchRejection(e, "Can't fetch sync settings warning"));
1722
1810
  })
1723
1811
  .catch((e) => {
1724
1812
  var _a, _b, _c, _d;
@@ -1739,6 +1827,9 @@
1739
1827
  catchRejection(e, "Can't save settings");
1740
1828
  })
1741
1829
  .finally(() => {
1830
+ if (isSettingsSaveJobPending) {
1831
+ return;
1832
+ }
1742
1833
  unsetLoader('#settings-modal');
1743
1834
  settingsSaveBtn.removeAttribute('disabled');
1744
1835
  if (!isValidationError) {