@crowdin/app-project-module 0.43.1 → 0.45.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.
- package/out/index.d.ts +3 -3
- package/out/index.js +103 -219
- package/out/middlewares/crowdin-client.d.ts +1 -1
- package/out/middlewares/crowdin-client.js +3 -2
- package/out/middlewares/integration-credentials.d.ts +3 -2
- package/out/middlewares/render-ui-module.d.ts +2 -2
- package/out/middlewares/ui-module.d.ts +2 -2
- package/out/middlewares/ui-module.js +5 -1
- package/out/{util → modules}/api/api.d.ts +3 -2
- package/out/{util → modules}/api/api.js +22 -22
- package/out/modules/api/index.d.ts +6 -0
- package/out/modules/api/index.js +14 -0
- package/out/modules/api/types.d.ts +20 -0
- package/out/modules/api/types.js +11 -0
- package/out/modules/context-menu/index.d.ts +6 -0
- package/out/modules/context-menu/index.js +17 -0
- package/out/modules/context-menu/types.d.ts +27 -0
- package/out/modules/context-menu/types.js +18 -0
- package/out/{handlers/custom-mt → modules/custom-mt/handlers}/translate.d.ts +2 -1
- package/out/{handlers/custom-mt → modules/custom-mt/handlers}/translate.js +2 -2
- package/out/modules/custom-mt/index.d.ts +6 -0
- package/out/modules/custom-mt/index.js +17 -0
- package/out/modules/custom-mt/types.d.ts +22 -0
- package/out/modules/custom-mt/types.js +2 -0
- package/out/{handlers/custom-spell-check → modules/custom-spell-check/handlers}/get-languages-list.d.ts +2 -1
- package/out/{handlers/custom-spell-check → modules/custom-spell-check/handlers}/get-languages-list.js +2 -2
- package/out/{handlers/custom-spell-check → modules/custom-spell-check/handlers}/spell-check.d.ts +2 -1
- package/out/{handlers/custom-spell-check → modules/custom-spell-check/handlers}/spell-check.js +5 -3
- package/out/modules/custom-spell-check/index.d.ts +6 -0
- package/out/modules/custom-spell-check/index.js +32 -0
- package/out/modules/custom-spell-check/types.d.ts +56 -0
- package/out/modules/custom-spell-check/types.js +2 -0
- package/out/modules/editor-right-panel/index.d.ts +6 -0
- package/out/modules/editor-right-panel/index.js +17 -0
- package/out/modules/editor-right-panel/types.d.ts +7 -0
- package/out/modules/editor-right-panel/types.js +2 -0
- package/out/modules/editor-themes/index.d.ts +6 -0
- package/out/modules/editor-themes/index.js +11 -0
- package/out/modules/editor-themes/types.d.ts +17 -0
- package/out/modules/editor-themes/types.js +2 -0
- package/out/{handlers/file-processing → modules/file-processing/handlers}/custom-file-format.d.ts +2 -1
- package/out/{handlers/file-processing → modules/file-processing/handlers}/custom-file-format.js +5 -5
- package/out/modules/file-processing/handlers/file-download.d.ts +5 -0
- package/out/{handlers/file-processing → modules/file-processing/handlers}/file-download.js +2 -2
- package/out/{handlers/file-processing → modules/file-processing/handlers}/pre-post-process.d.ts +2 -1
- package/out/{handlers/file-processing → modules/file-processing/handlers}/pre-post-process.js +8 -8
- package/out/modules/file-processing/index.d.ts +22 -0
- package/out/modules/file-processing/index.js +57 -0
- package/out/modules/file-processing/types.d.ts +133 -0
- package/out/modules/file-processing/types.js +12 -0
- package/out/modules/file-processing/util/defaults.d.ts +3 -0
- package/out/modules/file-processing/util/defaults.js +30 -0
- package/out/modules/file-processing/util/files.d.ts +6 -0
- package/out/modules/file-processing/util/files.js +47 -0
- package/out/{handlers/integration/crowdin-project.d.ts → modules/form-data-display.d.ts} +1 -1
- package/out/modules/form-data-save.d.ts +4 -0
- package/out/modules/install.d.ts +4 -0
- package/out/{handlers → modules}/install.js +3 -3
- package/out/{handlers/integration → modules/integration/handlers}/crowdin-file-progress.d.ts +2 -1
- package/out/{handlers/integration → modules/integration/handlers}/crowdin-file-progress.js +2 -2
- package/out/modules/integration/handlers/crowdin-files.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/crowdin-files.js +3 -3
- package/out/modules/integration/handlers/crowdin-project.d.ts +4 -0
- package/out/{handlers/integration → modules/integration/handlers}/crowdin-project.js +1 -1
- package/out/modules/integration/handlers/crowdin-update.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/crowdin-update.js +9 -9
- package/out/modules/integration/handlers/crowdin-webhook.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/crowdin-webhook.js +19 -8
- package/out/modules/integration/handlers/integration-data.d.ts +4 -0
- package/out/{handlers/integration → modules/integration/handlers}/integration-data.js +5 -5
- package/out/{handlers/integration → modules/integration/handlers}/integration-login.d.ts +2 -1
- package/out/{handlers/integration → modules/integration/handlers}/integration-login.js +3 -3
- package/out/modules/integration/handlers/integration-logout.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/integration-logout.js +14 -7
- package/out/modules/integration/handlers/integration-update.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/integration-update.js +9 -8
- package/out/modules/integration/handlers/integration-webhook.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/integration-webhook.js +9 -4
- package/out/modules/integration/handlers/job-cancel.d.ts +3 -0
- package/out/{handlers/integration → modules/integration/handlers}/job-cancel.js +4 -4
- package/out/modules/integration/handlers/job-info.d.ts +3 -0
- package/out/{handlers/integration → modules/integration/handlers}/job-info.js +4 -4
- package/out/modules/integration/handlers/main.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/main.js +5 -5
- package/out/modules/integration/handlers/oauth-login.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/oauth-login.js +3 -3
- package/out/{handlers/integration → modules/integration/handlers}/oauth-url.d.ts +2 -1
- package/out/{handlers/integration → modules/integration/handlers}/oauth-url.js +2 -2
- package/out/modules/integration/handlers/settings-save.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/settings-save.js +28 -11
- package/out/modules/integration/handlers/settings.d.ts +3 -0
- package/out/{handlers/integration → modules/integration/handlers}/settings.js +1 -1
- package/out/{handlers/integration → modules/integration/handlers}/subscription-info.d.ts +1 -1
- package/out/{handlers/integration → modules/integration/handlers}/subscription-info.js +2 -2
- package/out/modules/integration/handlers/sync-settings-save.d.ts +5 -0
- package/out/{handlers/integration → modules/integration/handlers}/sync-settings-save.js +16 -8
- package/out/modules/integration/handlers/sync-settings.d.ts +3 -0
- package/out/{handlers/integration → modules/integration/handlers}/sync-settings.js +2 -2
- package/out/modules/integration/handlers/user-errors.d.ts +3 -0
- package/out/{handlers/integration → modules/integration/handlers}/user-errors.js +2 -2
- package/out/modules/integration/index.d.ts +6 -0
- package/out/modules/integration/index.js +118 -0
- package/out/modules/integration/types.d.ts +435 -0
- package/out/modules/integration/types.js +19 -0
- package/out/modules/integration/util/cron.d.ts +27 -0
- package/out/{util → modules/integration/util}/cron.js +97 -28
- package/out/{util → modules/integration/util}/defaults.d.ts +2 -3
- package/out/{util → modules/integration/util}/defaults.js +1 -36
- package/out/modules/integration/util/files.d.ts +5 -0
- package/out/{util → modules/integration/util}/files.js +9 -40
- package/out/{util → modules/integration/util}/job.d.ts +1 -1
- package/out/{util → modules/integration/util}/job.js +11 -11
- package/out/{util/file-snapshot.d.ts → modules/integration/util/snapshot.d.ts} +2 -3
- package/out/{util/file-snapshot.js → modules/integration/util/snapshot.js} +6 -65
- package/out/{models/job.d.ts → modules/integration/util/types.d.ts} +14 -0
- package/out/modules/integration/util/webhooks.d.ts +48 -0
- package/out/{util → modules/integration/util}/webhooks.js +95 -49
- package/out/modules/manifest.d.ts +3 -0
- package/out/{handlers → modules}/manifest.js +22 -16
- package/out/modules/modal/index.d.ts +6 -0
- package/out/modules/modal/index.js +17 -0
- package/out/modules/organization-menu/index.d.ts +6 -0
- package/out/modules/organization-menu/index.js +18 -0
- package/out/modules/profile-resources-menu/index.d.ts +6 -0
- package/out/modules/profile-resources-menu/index.js +18 -0
- package/out/modules/project-menu/index.d.ts +6 -0
- package/out/modules/project-menu/index.js +17 -0
- package/out/modules/project-menu-crowdsource/index.d.ts +6 -0
- package/out/modules/project-menu-crowdsource/index.js +17 -0
- package/out/modules/project-reports/index.d.ts +6 -0
- package/out/modules/project-reports/index.js +18 -0
- package/out/modules/project-tools/index.d.ts +6 -0
- package/out/modules/project-tools/index.js +18 -0
- package/out/modules/subscription-paid.d.ts +3 -0
- package/out/{handlers → modules}/subscription-paid.js +2 -2
- package/out/modules/uninstall.d.ts +4 -0
- package/out/{handlers → modules}/uninstall.js +6 -2
- package/out/storage/index.d.ts +5 -3
- package/out/storage/mysql.d.ts +4 -2
- package/out/storage/mysql.js +3 -3
- package/out/storage/postgre.d.ts +4 -2
- package/out/storage/postgre.js +3 -3
- package/out/storage/sqlite.d.ts +4 -2
- package/out/storage/sqlite.js +3 -3
- package/out/storage/types.d.ts +9 -0
- package/out/storage/types.js +2 -0
- package/out/types.d.ts +374 -0
- package/out/types.js +59 -0
- package/out/util/connection.d.ts +2 -9
- package/out/util/connection.js +54 -150
- package/out/util/handlebars.d.ts +1 -0
- package/out/util/handlebars.js +34 -0
- package/out/util/index.d.ts +2 -2
- package/out/util/index.js +6 -6
- package/out/util/logger.d.ts +2 -2
- package/out/util/subscription.d.ts +9 -0
- package/out/util/subscription.js +111 -0
- package/package.json +1 -1
- package/out/handlers/file-processing/file-download.d.ts +0 -4
- package/out/handlers/form-data-display.d.ts +0 -3
- package/out/handlers/form-data-save.d.ts +0 -3
- package/out/handlers/install.d.ts +0 -4
- package/out/handlers/integration/crowdin-files.d.ts +0 -4
- package/out/handlers/integration/crowdin-update.d.ts +0 -4
- package/out/handlers/integration/crowdin-webhook.d.ts +0 -4
- package/out/handlers/integration/integration-data.d.ts +0 -4
- package/out/handlers/integration/integration-logout.d.ts +0 -4
- package/out/handlers/integration/integration-update.d.ts +0 -4
- package/out/handlers/integration/integration-webhook.d.ts +0 -4
- package/out/handlers/integration/job-cancel.d.ts +0 -3
- package/out/handlers/integration/job-info.d.ts +0 -3
- package/out/handlers/integration/main.d.ts +0 -4
- package/out/handlers/integration/oauth-login.d.ts +0 -4
- package/out/handlers/integration/settings-save.d.ts +0 -4
- package/out/handlers/integration/settings.d.ts +0 -3
- package/out/handlers/integration/sync-settings-save.d.ts +0 -4
- package/out/handlers/integration/sync-settings.d.ts +0 -3
- package/out/handlers/integration/user-errors.d.ts +0 -3
- package/out/handlers/manifest.d.ts +0 -3
- package/out/handlers/subscription-paid.d.ts +0 -3
- package/out/handlers/uninstall.d.ts +0 -4
- package/out/models/index.d.ts +0 -1088
- package/out/models/index.js +0 -106
- package/out/util/cron.d.ts +0 -7
- package/out/util/files.d.ts +0 -9
- package/out/util/webhooks.d.ts +0 -28
- /package/out/{util → modules}/api/base.d.ts +0 -0
- /package/out/{util → modules}/api/base.js +0 -0
- /package/out/{util → modules}/api/components.d.ts +0 -0
- /package/out/{util → modules}/api/components.js +0 -0
- /package/out/{handlers → modules}/form-data-display.js +0 -0
- /package/out/{handlers → modules}/form-data-save.js +0 -0
- /package/out/{models/job.js → modules/integration/util/types.js} +0 -0
|
@@ -34,15 +34,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
exports.removeFinishedJobs = exports.createOrUpdateSyncSettings = exports.skipFoldersFromIntegrationRequest = exports.filesCron = exports.runJob = void 0;
|
|
36
36
|
const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const storage_1 = require("../storage");
|
|
40
|
-
const connection_1 = require("./connection");
|
|
37
|
+
const storage_1 = require("../../../storage");
|
|
38
|
+
const connection_1 = require("../../../util/connection");
|
|
41
39
|
const defaults_1 = require("./defaults");
|
|
42
|
-
const
|
|
43
|
-
const logger_1 = require("
|
|
44
|
-
const
|
|
45
|
-
|
|
40
|
+
const snapshot_1 = require("./snapshot");
|
|
41
|
+
const logger_1 = require("../../../util/logger");
|
|
42
|
+
const types_1 = require("../types");
|
|
43
|
+
const job_1 = require("./job");
|
|
44
|
+
const types_2 = require("./types");
|
|
45
|
+
const subscription_1 = require("../../../util/subscription");
|
|
46
|
+
function runJob({ config, integration, job, }) {
|
|
46
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
48
|
(0, logger_1.log)(`Starting cron job with expression [${job.expression}]`);
|
|
48
49
|
const crowdinCredentialsList = yield (0, storage_1.getStorage)().getAllCrowdinCredentials();
|
|
@@ -52,7 +53,7 @@ function runJob(config, integration, job) {
|
|
|
52
53
|
credentials: crowdinCredentials,
|
|
53
54
|
autoRenew: true,
|
|
54
55
|
});
|
|
55
|
-
const { expired } = yield (0,
|
|
56
|
+
const { expired } = yield (0, subscription_1.checkSubscription)({
|
|
56
57
|
config,
|
|
57
58
|
token,
|
|
58
59
|
organization: crowdinCredentials.id,
|
|
@@ -79,7 +80,7 @@ function runJob(config, integration, job) {
|
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
exports.runJob = runJob;
|
|
82
|
-
function filesCron(config, integration, period) {
|
|
83
|
+
function filesCron({ config, integration, period, }) {
|
|
83
84
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
85
|
(0, logger_1.log)(`Starting files cron job with period [${period}]`);
|
|
85
86
|
const syncSettingsList = yield (0, storage_1.getStorage)().getAllSyncSettingsByType('schedule');
|
|
@@ -120,7 +121,7 @@ function filesCron(config, integration, period) {
|
|
|
120
121
|
autoRenew: true,
|
|
121
122
|
context,
|
|
122
123
|
});
|
|
123
|
-
const { expired } = yield (0,
|
|
124
|
+
const { expired } = yield (0, subscription_1.checkSubscription)({
|
|
124
125
|
config,
|
|
125
126
|
token,
|
|
126
127
|
organization: crowdinCredentials.id,
|
|
@@ -135,7 +136,7 @@ function filesCron(config, integration, period) {
|
|
|
135
136
|
if (!integration.webhooks &&
|
|
136
137
|
((_a = integration.syncNewElements) === null || _a === void 0 ? void 0 : _a[syncSettings.provider]) &&
|
|
137
138
|
intConfig[`new-${syncSettings.provider}-files`]) {
|
|
138
|
-
newFiles = yield
|
|
139
|
+
newFiles = yield getAllNewFiles({
|
|
139
140
|
config,
|
|
140
141
|
integration,
|
|
141
142
|
crowdinApiClient: crowdinClient,
|
|
@@ -150,7 +151,7 @@ function filesCron(config, integration, period) {
|
|
|
150
151
|
if (integration.webhooks) {
|
|
151
152
|
const webhooks = yield (0, storage_1.getStorage)().getAllWebhooks(syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
|
|
152
153
|
const webhooksFileIds = (webhooks || []).map((webhook) => webhook.fileId);
|
|
153
|
-
if (syncSettings.provider ===
|
|
154
|
+
if (syncSettings.provider === types_1.Provider.CROWDIN) {
|
|
154
155
|
files = webhooksFileIds.reduce((acc, fileId) => {
|
|
155
156
|
if (files[fileId]) {
|
|
156
157
|
acc[fileId] = files[fileId];
|
|
@@ -163,14 +164,26 @@ function filesCron(config, integration, period) {
|
|
|
163
164
|
}
|
|
164
165
|
yield (0, storage_1.getStorage)().deleteWebhooks(webhooksFileIds, syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
|
|
165
166
|
}
|
|
166
|
-
if (syncSettings.provider ===
|
|
167
|
-
const crowdinFiles = yield skipFoldersFromIntegrationRequest(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
167
|
+
if (syncSettings.provider === types_1.Provider.CROWDIN) {
|
|
168
|
+
const crowdinFiles = yield skipFoldersFromIntegrationRequest({
|
|
169
|
+
config,
|
|
170
|
+
integration,
|
|
171
|
+
projectId,
|
|
172
|
+
crowdinFiles: Object.assign(Object.assign({}, files), newFiles),
|
|
173
|
+
crowdinClient,
|
|
174
|
+
});
|
|
175
|
+
const onlyTranslated = +intConfig.condition === types_1.SyncCondition.TRANSLATED;
|
|
176
|
+
const onlyApproved = +intConfig.condition === types_1.SyncCondition.APPROVED;
|
|
177
|
+
const all = +intConfig.condition === types_1.SyncCondition.ALL || intConfig.condition === undefined;
|
|
171
178
|
const filesToProcess = all
|
|
172
179
|
? crowdinFiles
|
|
173
|
-
: yield getOnlyTranslatedOrApprovedFiles(
|
|
180
|
+
: yield getOnlyTranslatedOrApprovedFiles({
|
|
181
|
+
projectId,
|
|
182
|
+
crowdinFiles,
|
|
183
|
+
crowdinClient,
|
|
184
|
+
onlyApproved,
|
|
185
|
+
onlyTranslated,
|
|
186
|
+
});
|
|
174
187
|
(0, logger_1.log)(`Executing updateIntegration task for files cron job with period [${period}] for project ${projectId}.Files ${Object.keys(filesToProcess).length}`);
|
|
175
188
|
if (!all) {
|
|
176
189
|
if (Object.keys(filesToProcess).length === 0) {
|
|
@@ -180,10 +193,10 @@ function filesCron(config, integration, period) {
|
|
|
180
193
|
}
|
|
181
194
|
const apiCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
182
195
|
try {
|
|
183
|
-
yield (0,
|
|
196
|
+
yield (0, job_1.runAsJob)({
|
|
184
197
|
integrationId: syncSettings.integrationId,
|
|
185
198
|
crowdinId: syncSettings.crowdinId,
|
|
186
|
-
type:
|
|
199
|
+
type: types_2.JobType.UPDATE_TO_INTEGRATION,
|
|
187
200
|
title: `Sync files to ${config.name} [scheduled]`,
|
|
188
201
|
payload: filesToProcess,
|
|
189
202
|
jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -205,7 +218,7 @@ function filesCron(config, integration, period) {
|
|
|
205
218
|
}
|
|
206
219
|
if (Object.keys(newFiles).length) {
|
|
207
220
|
yield (0, storage_1.getStorage)().updateSyncSettings(JSON.stringify(Object.assign(Object.assign({}, files), newFiles)), syncSettings.integrationId, syncSettings.crowdinId, 'schedule', syncSettings.provider);
|
|
208
|
-
const currentFileSnapshot = yield (0,
|
|
221
|
+
const currentFileSnapshot = yield (0, snapshot_1.getCrowdinSnapshot)(config, integration, crowdinClient, projectId, intConfig);
|
|
209
222
|
yield (0, storage_1.getStorage)().updateFilesSnapshot(JSON.stringify(currentFileSnapshot), syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
|
|
210
223
|
}
|
|
211
224
|
(0, logger_1.log)(`updateIntegration task for files cron job with period [${period}] for project ${projectId} completed`);
|
|
@@ -220,10 +233,10 @@ function filesCron(config, integration, period) {
|
|
|
220
233
|
(0, logger_1.log)(`Executing updateCrowdin task for files cron job with period [${period}] for project ${projectId}. Files ${intFiles.length}`);
|
|
221
234
|
const apiCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
222
235
|
try {
|
|
223
|
-
yield (0,
|
|
236
|
+
yield (0, job_1.runAsJob)({
|
|
224
237
|
integrationId: syncSettings.integrationId,
|
|
225
238
|
crowdinId: syncSettings.crowdinId,
|
|
226
|
-
type:
|
|
239
|
+
type: types_2.JobType.UPDATE_TO_CROWDIN,
|
|
227
240
|
title: 'Sync files to Crowdin [scheduled]',
|
|
228
241
|
payload: intFiles,
|
|
229
242
|
jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -246,7 +259,7 @@ function filesCron(config, integration, period) {
|
|
|
246
259
|
if (Object.keys(newFiles).length) {
|
|
247
260
|
const newSyncSettingsFields = allIntFiles.map((file) => (Object.assign(Object.assign({}, file), { schedule: true, sync: false })));
|
|
248
261
|
yield (0, storage_1.getStorage)().updateSyncSettings(JSON.stringify(newSyncSettingsFields), syncSettings.integrationId, syncSettings.crowdinId, 'schedule', syncSettings.provider);
|
|
249
|
-
const currentFileSnapshot = yield (0,
|
|
262
|
+
const currentFileSnapshot = yield (0, snapshot_1.getIntegrationSnapshot)(integration, apiCredentials, intConfig);
|
|
250
263
|
yield (0, storage_1.getStorage)().updateFilesSnapshot(JSON.stringify(currentFileSnapshot), syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
|
|
251
264
|
}
|
|
252
265
|
(0, logger_1.log)(`updateCrowdin task for files cron job with period [${period}] for project ${projectId} completed`);
|
|
@@ -256,7 +269,63 @@ function filesCron(config, integration, period) {
|
|
|
256
269
|
});
|
|
257
270
|
}
|
|
258
271
|
exports.filesCron = filesCron;
|
|
259
|
-
function
|
|
272
|
+
function getFileDiff(currentFiles, savedFiles) {
|
|
273
|
+
return currentFiles.filter((x) => !savedFiles.some((x2) => x2.id === x.id));
|
|
274
|
+
}
|
|
275
|
+
function getAllNewFiles(args) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
const { config, integration, crowdinApiClient, crowdinId, integrationCredentials, integrationId, projectId, integrationSettings, syncSettings, } = args;
|
|
278
|
+
let currentFileSnapshot = [];
|
|
279
|
+
const fileSnapshotData = yield (0, storage_1.getStorage)().getFilesSnapshot(integrationId, crowdinId, syncSettings.provider);
|
|
280
|
+
const snapshotFiles = (fileSnapshotData === null || fileSnapshotData === void 0 ? void 0 : fileSnapshotData.files) ? JSON.parse(fileSnapshotData.files) : [];
|
|
281
|
+
if (syncSettings.provider === types_1.Provider.CROWDIN) {
|
|
282
|
+
currentFileSnapshot = yield (0, snapshot_1.getCrowdinSnapshot)(config, integration, crowdinApiClient, projectId, integrationSettings);
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
currentFileSnapshot = yield (0, snapshot_1.getIntegrationSnapshot)(integration, integrationCredentials, integrationSettings);
|
|
286
|
+
}
|
|
287
|
+
const difference = getFileDiff(currentFileSnapshot, snapshotFiles);
|
|
288
|
+
const onlyFiles = difference.filter((file) => 'type' in file);
|
|
289
|
+
const synFiles = JSON.parse(syncSettings.files);
|
|
290
|
+
if (syncSettings.provider === types_1.Provider.INTEGRATION) {
|
|
291
|
+
if (integrationSettings[`new-${syncSettings.provider}-files`]) {
|
|
292
|
+
return onlyFiles;
|
|
293
|
+
}
|
|
294
|
+
const syncFolders = synFiles.filter((file) => !('type' in file));
|
|
295
|
+
return getNewFoldersFile(syncFolders, difference);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
const files = {};
|
|
299
|
+
const projectData = yield crowdinApiClient.projectsGroupsApi.getProject(projectId);
|
|
300
|
+
const targetLanguages = projectData.data.targetLanguageIds;
|
|
301
|
+
if (integrationSettings[`new-${syncSettings.provider}-files`]) {
|
|
302
|
+
for (const file of onlyFiles) {
|
|
303
|
+
files[file.id] = targetLanguages;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
const syncFolders = currentFileSnapshot.filter((file) => !('type' in file) && Object.keys(synFiles).includes(file.id));
|
|
308
|
+
const newFiles = getNewFoldersFile(syncFolders, difference);
|
|
309
|
+
for (const file of newFiles) {
|
|
310
|
+
files[file.id] = targetLanguages;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return files;
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function getNewFoldersFile(folders, snapshotFiles) {
|
|
318
|
+
let files = [];
|
|
319
|
+
for (const folder of folders) {
|
|
320
|
+
const newFiles = snapshotFiles.find((file) => file.parentId === folder.id);
|
|
321
|
+
if (newFiles) {
|
|
322
|
+
files = files.concat(newFiles);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
files = files.filter((file) => 'type' in file);
|
|
326
|
+
return files;
|
|
327
|
+
}
|
|
328
|
+
function getOnlyTranslatedOrApprovedFiles({ projectId, crowdinFiles, crowdinClient, onlyApproved, onlyTranslated, }) {
|
|
260
329
|
return __awaiter(this, void 0, void 0, function* () {
|
|
261
330
|
(0, logger_1.log)(`Filtering files to process only ${onlyApproved ? 'approved' : 'translated'} files`);
|
|
262
331
|
const filesInfo = yield Promise.all(Object.keys(crowdinFiles).map((fileId) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -309,7 +378,7 @@ function getOnlyTranslatedOrApprovedFiles(config, projectId, crowdinFiles, crowd
|
|
|
309
378
|
return filteredFiles;
|
|
310
379
|
});
|
|
311
380
|
}
|
|
312
|
-
function skipFoldersFromIntegrationRequest(config, integration, projectId, crowdinFiles,
|
|
381
|
+
function skipFoldersFromIntegrationRequest({ config, integration, projectId, crowdinClient, crowdinFiles, }) {
|
|
313
382
|
var _a;
|
|
314
383
|
return __awaiter(this, void 0, void 0, function* () {
|
|
315
384
|
let folders;
|
|
@@ -336,7 +405,7 @@ function skipFoldersFromIntegrationRequest(config, integration, projectId, crowd
|
|
|
336
405
|
});
|
|
337
406
|
}
|
|
338
407
|
exports.skipFoldersFromIntegrationRequest = skipFoldersFromIntegrationRequest;
|
|
339
|
-
function createOrUpdateSyncSettings(
|
|
408
|
+
function createOrUpdateSyncSettings({ req, files, provider, onlyCreate = false, }) {
|
|
340
409
|
return __awaiter(this, void 0, void 0, function* () {
|
|
341
410
|
const existingSettings = yield (0, storage_1.getStorage)().getSyncSettings(req.crowdinContext.clientId, req.crowdinContext.crowdinId, 'schedule', provider);
|
|
342
411
|
if (!existingSettings) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import Crowdin, { SourceFilesModel } from '@crowdin/crowdin-api-client';
|
|
2
|
-
import {
|
|
2
|
+
import { Config } from '../../../types';
|
|
3
|
+
import { IntegrationLogic } from '../types';
|
|
3
4
|
export declare function getRootFolder(config: Config, integration: IntegrationLogic, client: Crowdin, projectId: number): Promise<SourceFilesModel.Directory | undefined>;
|
|
4
5
|
export declare function getOauthRoute(integration: IntegrationLogic): string;
|
|
5
6
|
export declare function applyIntegrationModuleDefaults(config: Config, integration: IntegrationLogic): void;
|
|
6
|
-
export declare function applyFileProcessorsModuleDefaults(config: Config, fileModule: FileProcessLogic): void;
|
|
7
7
|
export declare function constructOauthUrl(config: Config, integration: IntegrationLogic): string;
|
|
8
|
-
export declare function convertClientConfig(clientConfig: ClientConfig): Config;
|
|
@@ -32,11 +32,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.
|
|
36
|
-
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
37
|
-
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
35
|
+
exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
|
|
38
36
|
const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
|
|
39
|
-
const path_1 = require("path");
|
|
40
37
|
function getRootFolder(config, integration, client, projectId) {
|
|
41
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
39
|
if (!integration.withRootFolder) {
|
|
@@ -239,22 +236,6 @@ function applyIntegrationModuleDefaults(config, integration) {
|
|
|
239
236
|
}
|
|
240
237
|
}
|
|
241
238
|
exports.applyIntegrationModuleDefaults = applyIntegrationModuleDefaults;
|
|
242
|
-
function applyFileProcessorsModuleDefaults(config, fileModule) {
|
|
243
|
-
var _a, _b;
|
|
244
|
-
const AWS_TMP_BUCKET_NAME = (_a = config.awsConfig) === null || _a === void 0 ? void 0 : _a.tmpBucketName;
|
|
245
|
-
const AWS_REGION = (_b = config.awsConfig) === null || _b === void 0 ? void 0 : _b.region;
|
|
246
|
-
if (AWS_TMP_BUCKET_NAME && AWS_REGION && !fileModule.storeFile) {
|
|
247
|
-
const s3 = new client_s3_1.S3Client({ region: AWS_REGION });
|
|
248
|
-
fileModule.storeFile = (content) => __awaiter(this, void 0, void 0, function* () {
|
|
249
|
-
const fileName = `file-${config.identifier}-${Date.now()}`;
|
|
250
|
-
const command = new client_s3_1.PutObjectCommand({ Bucket: AWS_TMP_BUCKET_NAME, Key: fileName, Body: content });
|
|
251
|
-
yield s3.send(command);
|
|
252
|
-
const getObjectCommand = new client_s3_1.GetObjectCommand({ Bucket: AWS_TMP_BUCKET_NAME, Key: fileName });
|
|
253
|
-
return (0, s3_request_presigner_1.getSignedUrl)(s3, getObjectCommand, { expiresIn: 3600 });
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
exports.applyFileProcessorsModuleDefaults = applyFileProcessorsModuleDefaults;
|
|
258
239
|
function constructOauthUrl(config, integration) {
|
|
259
240
|
var _a, _b, _c;
|
|
260
241
|
const oauth = integration.oauthLogin;
|
|
@@ -270,19 +251,3 @@ function constructOauthUrl(config, integration) {
|
|
|
270
251
|
return url;
|
|
271
252
|
}
|
|
272
253
|
exports.constructOauthUrl = constructOauthUrl;
|
|
273
|
-
function convertClientConfig(clientConfig) {
|
|
274
|
-
const baseUrl = clientConfig.baseUrl || process.env.URL;
|
|
275
|
-
const clientId = clientConfig.clientId || process.env.CROWDIN_CLIENT_ID;
|
|
276
|
-
const clientSecret = clientConfig.clientSecret || process.env.CROWDIN_CLIENT_SECRET;
|
|
277
|
-
const port = clientConfig.port || process.env.PORT || 3000;
|
|
278
|
-
const { region = process.env.AWS_REGION || process.env.AWS_DEFAULT_REGION, tmpBucketName = process.env.AWS_TMP_BUCKET_NAME, } = clientConfig.awsConfig || {};
|
|
279
|
-
if (!baseUrl || !clientId || !clientSecret) {
|
|
280
|
-
throw new Error('One of following parameters are not defined [baseUrl, clientId, clientSecret]');
|
|
281
|
-
}
|
|
282
|
-
return Object.assign(Object.assign({}, clientConfig), { baseUrl: baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl, clientId,
|
|
283
|
-
clientSecret, awsConfig: {
|
|
284
|
-
tmpBucketName,
|
|
285
|
-
region,
|
|
286
|
-
}, port: Number(port), dbFolder: clientConfig.dbFolder || (0, path_1.join)(process.cwd(), 'db'), imagePath: clientConfig.imagePath || (0, path_1.join)(process.cwd(), 'logo.png') });
|
|
287
|
-
}
|
|
288
|
-
exports.convertClientConfig = convertClientConfig;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ExtendedResult, IntegrationFile, IntegrationLogic, IntegrationRequest, SkipIntegrationNodes, TreeItem } from '../types';
|
|
2
|
+
import { JobClient } from './types';
|
|
3
|
+
export declare function skipFilesByRegex(files: TreeItem[] | undefined, skipIntegrationNodes?: SkipIntegrationNodes): TreeItem[];
|
|
4
|
+
export declare function expandFilesTree(nodes: IntegrationFile[], req: IntegrationRequest, integration: IntegrationLogic, job?: JobClient): Promise<IntegrationFile[]>;
|
|
5
|
+
export declare function isExtendedResultType<T>(data?: T | ExtendedResult<T>): data is ExtendedResult<T>;
|
|
@@ -8,45 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
const
|
|
17
|
-
const fs_1 = __importDefault(require("fs"));
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const index_1 = require("./index");
|
|
20
|
-
const job_1 = require("../models/job");
|
|
21
|
-
exports.MAX_BODY_SIZE = 4.9 * 1024 * 1024; //4.9mb
|
|
22
|
-
function storeFile(fileContent, folder) {
|
|
23
|
-
const fileName = `file${Date.now()}`;
|
|
24
|
-
return new Promise((res, rej) => fs_1.default.writeFile(path_1.default.join(folder, fileName), fileContent, (err) => {
|
|
25
|
-
if (err) {
|
|
26
|
-
rej(err);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
res(fileName);
|
|
30
|
-
}
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
exports.storeFile = storeFile;
|
|
34
|
-
function getFileContent(url) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const response = (yield axios_1.default.get(url, { responseType: 'arraybuffer' })).data;
|
|
37
|
-
return response;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
exports.getFileContent = getFileContent;
|
|
41
|
-
function getFileStrings(url) {
|
|
42
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
const response = (yield axios_1.default.get(url)).data;
|
|
44
|
-
// the response is presented in the ndjson format
|
|
45
|
-
const jsonRows = response.split(/\n|\n\r/).filter(Boolean);
|
|
46
|
-
return jsonRows.map((jsonStringRow) => JSON.parse(jsonStringRow));
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
exports.getFileStrings = getFileStrings;
|
|
12
|
+
exports.isExtendedResultType = exports.expandFilesTree = exports.skipFilesByRegex = void 0;
|
|
13
|
+
const types_1 = require("./types");
|
|
50
14
|
function skipFilesByRegex(files, skipIntegrationNodes) {
|
|
51
15
|
if (!Array.isArray(files)) {
|
|
52
16
|
return [];
|
|
@@ -68,14 +32,14 @@ exports.skipFilesByRegex = skipFilesByRegex;
|
|
|
68
32
|
function expandFilesTree(nodes, req, integration, job) {
|
|
69
33
|
var _a;
|
|
70
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
if (job &&
|
|
35
|
+
if (job && types_1.JobStatus.CANCELED === ((_a = (yield job.get())) === null || _a === void 0 ? void 0 : _a.status)) {
|
|
72
36
|
throw new Error('Job canceled');
|
|
73
37
|
}
|
|
74
38
|
const files = nodes.filter((file) => file.nodeType === undefined || file.nodeType === '1');
|
|
75
39
|
const folders = nodes.filter((folder) => folder.nodeType === '0' && !nodes.find((node) => node.parentId === folder.id));
|
|
76
40
|
for (const { id } of folders) {
|
|
77
41
|
const integrationData = yield integration.getIntegrationFiles(req.integrationCredentials, req.integrationSettings, id);
|
|
78
|
-
const integrationTreeItems =
|
|
42
|
+
const integrationTreeItems = isExtendedResultType(integrationData)
|
|
79
43
|
? integrationData.data
|
|
80
44
|
: integrationData;
|
|
81
45
|
const checkNodes = integrationTreeItems.map((item) => (Object.assign(Object.assign({}, item), { nodeType: item.nodeType || ('type' in item ? '1' : '0') })));
|
|
@@ -86,3 +50,8 @@ function expandFilesTree(nodes, req, integration, job) {
|
|
|
86
50
|
});
|
|
87
51
|
}
|
|
88
52
|
exports.expandFilesTree = expandFilesTree;
|
|
53
|
+
function isExtendedResultType(data) {
|
|
54
|
+
const dataTyped = data;
|
|
55
|
+
return !!dataTyped && !Array.isArray(dataTyped);
|
|
56
|
+
}
|
|
57
|
+
exports.isExtendedResultType = isExtendedResultType;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JobClient, JobType } from '
|
|
1
|
+
import { JobClient, JobType } from './types';
|
|
2
2
|
import { Response } from 'express';
|
|
3
3
|
export declare function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCallback, onError, }: {
|
|
4
4
|
integrationId: string;
|
|
@@ -10,14 +10,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.runAsJob = void 0;
|
|
13
|
-
const
|
|
14
|
-
const storage_1 = require("
|
|
15
|
-
const logger_1 = require("
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const storage_1 = require("../../../storage");
|
|
15
|
+
const logger_1 = require("../../../util/logger");
|
|
16
16
|
const blockingJobs = {
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
17
|
+
[types_1.JobType.UPDATE_TO_CROWDIN]: [types_1.JobType.UPDATE_TO_CROWDIN, types_1.JobType.UPDATE_TO_INTEGRATION],
|
|
18
|
+
[types_1.JobType.UPDATE_TO_INTEGRATION]: [types_1.JobType.UPDATE_TO_CROWDIN, types_1.JobType.UPDATE_TO_INTEGRATION],
|
|
19
|
+
[types_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE]: [types_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE],
|
|
20
|
+
[types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE]: [types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE],
|
|
21
21
|
};
|
|
22
22
|
function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCallback, onError, }) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -51,13 +51,13 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCall
|
|
|
51
51
|
update: function updateProgress({ progress, status, info, data }) {
|
|
52
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
53
|
const prevData = yield this.get();
|
|
54
|
-
if ((prevData === null || prevData === void 0 ? void 0 : prevData.status) ===
|
|
54
|
+
if ((prevData === null || prevData === void 0 ? void 0 : prevData.status) === types_1.JobStatus.CANCELED) {
|
|
55
55
|
return { isCanceled: true };
|
|
56
56
|
}
|
|
57
57
|
yield storage.updateJob({
|
|
58
58
|
id: jobId,
|
|
59
59
|
progress,
|
|
60
|
-
status: status ||
|
|
60
|
+
status: status || types_1.JobStatus.IN_PROGRESS,
|
|
61
61
|
info,
|
|
62
62
|
data: JSON.stringify(data),
|
|
63
63
|
});
|
|
@@ -69,13 +69,13 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCall
|
|
|
69
69
|
const data = yield jobCallback(job);
|
|
70
70
|
yield job.update({
|
|
71
71
|
progress: 100,
|
|
72
|
-
status:
|
|
72
|
+
status: types_1.JobStatus.FINISHED,
|
|
73
73
|
data,
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
catch (e) {
|
|
77
77
|
yield job.update({
|
|
78
|
-
status:
|
|
78
|
+
status: types_1.JobStatus.FAILED,
|
|
79
79
|
info: (0, logger_1.getErrorMessage)(e),
|
|
80
80
|
});
|
|
81
81
|
if (onError) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import Crowdin from '@crowdin/crowdin-api-client';
|
|
2
|
-
import { Config
|
|
3
|
-
|
|
4
|
-
export declare function getAllNewFiles(args: GetAllNewFilesArgs): Promise<TreeItem[] | UpdateIntegrationRequest>;
|
|
2
|
+
import { Config } from '../../../types';
|
|
3
|
+
import { IntegrationLogic, IntegrationRequest, Provider, TreeItem } from '../types';
|
|
5
4
|
export declare function getCrowdinSnapshot(config: Config, integration: IntegrationLogic, crowdinApiClient: Crowdin, projectId: number, integrationSettings: any): Promise<TreeItem[]>;
|
|
6
5
|
export declare function getIntegrationSnapshot(integration: IntegrationLogic, integrationCredentials: any, integrationSettings: any): Promise<TreeItem[]>;
|
|
7
6
|
export declare function createOrUpdateFileSnapshot(config: Config, integration: IntegrationLogic, req: IntegrationRequest, provider: Provider): Promise<void>;
|
|
@@ -9,70 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.createOrUpdateFileSnapshot = exports.getIntegrationSnapshot = exports.getCrowdinSnapshot =
|
|
13
|
-
const
|
|
14
|
-
const storage_1 = require("
|
|
12
|
+
exports.createOrUpdateFileSnapshot = exports.getIntegrationSnapshot = exports.getCrowdinSnapshot = void 0;
|
|
13
|
+
const types_1 = require("../types");
|
|
14
|
+
const storage_1 = require("../../../storage");
|
|
15
15
|
const defaults_1 = require("./defaults");
|
|
16
|
-
const index_1 = require("./index");
|
|
17
16
|
const files_1 = require("./files");
|
|
18
|
-
function getFileDiff(currentFiles, savedFiles) {
|
|
19
|
-
return currentFiles.filter((x) => !savedFiles.some((x2) => x2.id === x.id));
|
|
20
|
-
}
|
|
21
|
-
exports.getFileDiff = getFileDiff;
|
|
22
|
-
function getAllNewFiles(args) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const { config, integration, crowdinApiClient, crowdinId, integrationCredentials, integrationId, projectId, integrationSettings, syncSettings, } = args;
|
|
25
|
-
let currentFileSnapshot = [];
|
|
26
|
-
const fileSnapshotData = yield (0, storage_1.getStorage)().getFilesSnapshot(integrationId, crowdinId, syncSettings.provider);
|
|
27
|
-
const snapshotFiles = (fileSnapshotData === null || fileSnapshotData === void 0 ? void 0 : fileSnapshotData.files) ? JSON.parse(fileSnapshotData.files) : [];
|
|
28
|
-
if (syncSettings.provider === models_1.Provider.CROWDIN) {
|
|
29
|
-
currentFileSnapshot = yield getCrowdinSnapshot(config, integration, crowdinApiClient, projectId, integrationSettings);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
currentFileSnapshot = yield getIntegrationSnapshot(integration, integrationCredentials, integrationSettings);
|
|
33
|
-
}
|
|
34
|
-
const difference = getFileDiff(currentFileSnapshot, snapshotFiles);
|
|
35
|
-
const onlyFiles = difference.filter((file) => 'type' in file);
|
|
36
|
-
const synFiles = JSON.parse(syncSettings.files);
|
|
37
|
-
if (syncSettings.provider === models_1.Provider.INTEGRATION) {
|
|
38
|
-
if (integrationSettings[`new-${syncSettings.provider}-files`]) {
|
|
39
|
-
return onlyFiles;
|
|
40
|
-
}
|
|
41
|
-
const syncFolders = synFiles.filter((file) => !('type' in file));
|
|
42
|
-
return getNewFoldersFile(syncFolders, difference);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const files = {};
|
|
46
|
-
const projectData = yield crowdinApiClient.projectsGroupsApi.getProject(projectId);
|
|
47
|
-
const targetLanguages = projectData.data.targetLanguageIds;
|
|
48
|
-
if (integrationSettings[`new-${syncSettings.provider}-files`]) {
|
|
49
|
-
for (const file of onlyFiles) {
|
|
50
|
-
files[file.id] = targetLanguages;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
const syncFolders = currentFileSnapshot.filter((file) => !('type' in file) && Object.keys(synFiles).includes(file.id));
|
|
55
|
-
const newFiles = getNewFoldersFile(syncFolders, difference);
|
|
56
|
-
for (const file of newFiles) {
|
|
57
|
-
files[file.id] = targetLanguages;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return files;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
exports.getAllNewFiles = getAllNewFiles;
|
|
65
|
-
function getNewFoldersFile(folders, snapshotFiles) {
|
|
66
|
-
let files = [];
|
|
67
|
-
for (const folder of folders) {
|
|
68
|
-
const newFiles = snapshotFiles.find((file) => file.parentId === folder.id);
|
|
69
|
-
if (newFiles) {
|
|
70
|
-
files = files.concat(newFiles);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
files = files.filter((file) => 'type' in file);
|
|
74
|
-
return files;
|
|
75
|
-
}
|
|
76
17
|
function getCrowdinSnapshot(config, integration, crowdinApiClient, projectId, integrationSettings) {
|
|
77
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
19
|
let files = [];
|
|
@@ -86,7 +27,7 @@ function getCrowdinSnapshot(config, integration, crowdinApiClient, projectId, in
|
|
|
86
27
|
exports.getCrowdinSnapshot = getCrowdinSnapshot;
|
|
87
28
|
function getTreeItems(integrationData) {
|
|
88
29
|
let files = [];
|
|
89
|
-
if ((0,
|
|
30
|
+
if ((0, files_1.isExtendedResultType)(integrationData)) {
|
|
90
31
|
files = integrationData.data;
|
|
91
32
|
}
|
|
92
33
|
else {
|
|
@@ -133,10 +74,10 @@ function createOrUpdateFileSnapshot(config, integration, req, provider) {
|
|
|
133
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
75
|
let files = [];
|
|
135
76
|
const existingSnapshot = yield (0, storage_1.getStorage)().getFilesSnapshot(req.crowdinContext.clientId, req.crowdinContext.crowdinId, provider);
|
|
136
|
-
if (provider ===
|
|
77
|
+
if (provider === types_1.Provider.CROWDIN) {
|
|
137
78
|
files = yield getCrowdinSnapshot(config, integration, req.crowdinApiClient, req.crowdinContext.jwtPayload.context.project_id, req.integrationSettings);
|
|
138
79
|
}
|
|
139
|
-
if (provider ===
|
|
80
|
+
if (provider === types_1.Provider.INTEGRATION) {
|
|
140
81
|
files = yield getIntegrationSnapshot(integration, req.integrationCredentials, req.integrationSettings);
|
|
141
82
|
}
|
|
142
83
|
if (existingSnapshot) {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import Crowdin from '@crowdin/crowdin-api-client';
|
|
2
|
+
import { Config } from '../../../types';
|
|
3
|
+
import { IntegrationLogic, IntegrationSyncSettings } from '../types';
|
|
1
4
|
export declare enum JobType {
|
|
2
5
|
UPDATE_TO_CROWDIN = "updateCrowdin",
|
|
3
6
|
UPDATE_TO_INTEGRATION = "updateIntegration",
|
|
@@ -44,3 +47,14 @@ export type JobClient = {
|
|
|
44
47
|
export type UpdateJobProgress = ({ progress, status, info, data, }: Omit<UpdateJobParams, 'id'>) => Promise<{
|
|
45
48
|
isCanceled: boolean;
|
|
46
49
|
}>;
|
|
50
|
+
export interface GetAllNewFilesArgs {
|
|
51
|
+
config: Config;
|
|
52
|
+
integration: IntegrationLogic;
|
|
53
|
+
crowdinApiClient: Crowdin;
|
|
54
|
+
crowdinId: string;
|
|
55
|
+
integrationCredentials: any;
|
|
56
|
+
integrationId: string;
|
|
57
|
+
projectId: number;
|
|
58
|
+
integrationSettings: any;
|
|
59
|
+
syncSettings: IntegrationSyncSettings;
|
|
60
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import Crowdin from '@crowdin/crowdin-api-client';
|
|
2
|
+
import { AppSettings, IntegrationLogic, IntegrationSyncSettings, Provider, UpdateCrowdinWebhookPayloadsArgs } from '../types';
|
|
3
|
+
import { Config, CrowdinContextInfo } from '../../../types';
|
|
4
|
+
export declare const HookEvents: any;
|
|
5
|
+
export declare function registerWebhooks({ config, apiCredentials, appSettings, client, crowdinContext, integration, }: {
|
|
6
|
+
config: Config;
|
|
7
|
+
integration: IntegrationLogic;
|
|
8
|
+
client: Crowdin;
|
|
9
|
+
crowdinContext: CrowdinContextInfo;
|
|
10
|
+
apiCredentials: any;
|
|
11
|
+
appSettings: AppSettings;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
export declare function unregisterWebhooks({ apiCredentials, appSettings, client, config, crowdinContext, integration, }: {
|
|
14
|
+
config: Config;
|
|
15
|
+
integration: IntegrationLogic;
|
|
16
|
+
client: Crowdin;
|
|
17
|
+
crowdinContext: CrowdinContextInfo;
|
|
18
|
+
apiCredentials: any;
|
|
19
|
+
appSettings: AppSettings;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
export declare function unregisterAllCrowdinWebhooks({ config, crowdinId, integration, }: {
|
|
22
|
+
config: Config;
|
|
23
|
+
integration: IntegrationLogic;
|
|
24
|
+
crowdinId: string;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
export declare function prepareWebhookData({ config, integration, provider, webhookUrlParam, }: {
|
|
27
|
+
config: Config;
|
|
28
|
+
integration: IntegrationLogic;
|
|
29
|
+
webhookUrlParam: string;
|
|
30
|
+
provider: Provider;
|
|
31
|
+
}): Promise<{
|
|
32
|
+
projectId: number;
|
|
33
|
+
crowdinClient: {
|
|
34
|
+
client: Crowdin;
|
|
35
|
+
token: string;
|
|
36
|
+
};
|
|
37
|
+
preparedIntegrationCredentials: any;
|
|
38
|
+
rootFolder: import("@crowdin/crowdin-api-client").SourceFilesModel.Directory | undefined;
|
|
39
|
+
appSettings: AppSettings;
|
|
40
|
+
syncSettings: IntegrationSyncSettings | null;
|
|
41
|
+
}>;
|
|
42
|
+
export declare function updateCrowdinFromWebhookRequest(args: UpdateCrowdinWebhookPayloadsArgs): Promise<void>;
|
|
43
|
+
export declare function listenQueueMessage({ config, integration, queueName, queueUrl, }: {
|
|
44
|
+
config: Config;
|
|
45
|
+
integration: IntegrationLogic;
|
|
46
|
+
queueUrl: string;
|
|
47
|
+
queueName: string;
|
|
48
|
+
}): Promise<void>;
|