@crowdin/app-project-module 0.51.4 → 0.52.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/app-test/integration/update-crowdin.js +1 -0
- package/out/app-test/integration/update-integration.js +1 -0
- package/out/modules/integration/handlers/crowdin-update.js +1 -0
- package/out/modules/integration/handlers/integration-update.js +1 -0
- package/out/modules/integration/handlers/sync-settings-save.js +2 -0
- package/out/modules/integration/util/cron.js +6 -4
- package/out/modules/integration/util/job.d.ts +3 -2
- package/out/modules/integration/util/job.js +2 -1
- package/out/modules/integration/util/types.d.ts +5 -0
- package/out/modules/integration/util/types.js +6 -1
- package/package.json +1 -1
|
@@ -40,6 +40,7 @@ function handle(config, integration) {
|
|
|
40
40
|
title: 'Sync files to Crowdin',
|
|
41
41
|
payload: req.body,
|
|
42
42
|
res,
|
|
43
|
+
jobType: types_1.JobClientType.MANUAL,
|
|
43
44
|
jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
|
|
44
45
|
var _c;
|
|
45
46
|
if (req.body && ((_c = req.body) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
@@ -34,6 +34,7 @@ function handle(config, integration) {
|
|
|
34
34
|
title: 'Sync files to ' + config.name,
|
|
35
35
|
payload: req.body,
|
|
36
36
|
res,
|
|
37
|
+
jobType: types_1.JobClientType.MANUAL,
|
|
37
38
|
jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
|
|
38
39
|
const result = yield integration.updateIntegration({
|
|
39
40
|
projectId: req.crowdinContext.jwtPayload.context.project_id,
|
|
@@ -18,6 +18,7 @@ const cron_1 = require("../util/cron");
|
|
|
18
18
|
const snapshot_1 = require("../util/snapshot");
|
|
19
19
|
const files_1 = require("../util/files");
|
|
20
20
|
const job_1 = require("../util/job");
|
|
21
|
+
const types_1 = require("../util/types");
|
|
21
22
|
function checkAutoSyncSettings(integration, appSettings, provider) {
|
|
22
23
|
var _a;
|
|
23
24
|
return !!(!integration.webhooks && ((_a = integration.syncNewElements) === null || _a === void 0 ? void 0 : _a[provider]) && appSettings[`new-${provider}-files`]);
|
|
@@ -32,6 +33,7 @@ function handle(config, integration) {
|
|
|
32
33
|
title: 'Save sync settings',
|
|
33
34
|
payload: req.body,
|
|
34
35
|
res,
|
|
36
|
+
jobType: types_1.JobClientType.MANUAL,
|
|
35
37
|
jobCallback: () => __awaiter(this, void 0, void 0, function* () {
|
|
36
38
|
if (Array.isArray(expandIntegrationFolders) && expandIntegrationFolders.length) {
|
|
37
39
|
const allFiles = (yield (0, files_1.expandFilesTree)(expandIntegrationFolders, req, integration)).map((node) => ({
|
|
@@ -92,13 +92,13 @@ function filesCron({ config, integration, period, }) {
|
|
|
92
92
|
const integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(syncSettings.integrationId);
|
|
93
93
|
const integrationConfig = yield (0, storage_1.getStorage)().getIntegrationConfig(syncSettings.integrationId);
|
|
94
94
|
if (!crowdinCredentials || !integrationCredentials) {
|
|
95
|
-
|
|
95
|
+
continue;
|
|
96
96
|
}
|
|
97
97
|
const intConfig = (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config)
|
|
98
98
|
? JSON.parse(integrationConfig.config)
|
|
99
99
|
: { schedule: '0', condition: '0' };
|
|
100
100
|
if (period !== intConfig.schedule) {
|
|
101
|
-
|
|
101
|
+
continue;
|
|
102
102
|
}
|
|
103
103
|
const projectId = crowdinAppFunctions.getProjectId(integrationCredentials.id);
|
|
104
104
|
const context = {
|
|
@@ -129,7 +129,7 @@ function filesCron({ config, integration, period, }) {
|
|
|
129
129
|
});
|
|
130
130
|
if (expired) {
|
|
131
131
|
(0, logger_1.log)(`Subscription expired. Skipping job [${period}] for organization ${crowdinCredentials.id}`);
|
|
132
|
-
|
|
132
|
+
continue;
|
|
133
133
|
}
|
|
134
134
|
const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, crowdinClient, projectId);
|
|
135
135
|
const apiCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
@@ -188,7 +188,7 @@ function filesCron({ config, integration, period, }) {
|
|
|
188
188
|
if (!all) {
|
|
189
189
|
if (Object.keys(filesToProcess).length === 0) {
|
|
190
190
|
(0, logger_1.log)(`There is no ${onlyApproved ? 'approved' : 'translated'} file`);
|
|
191
|
-
|
|
191
|
+
continue;
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
const apiCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
@@ -199,6 +199,7 @@ function filesCron({ config, integration, period, }) {
|
|
|
199
199
|
type: types_2.JobType.UPDATE_TO_INTEGRATION,
|
|
200
200
|
title: `Sync files to ${config.name} [scheduled]`,
|
|
201
201
|
payload: filesToProcess,
|
|
202
|
+
jobType: types_2.JobClientType.CRON,
|
|
202
203
|
jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
|
|
203
204
|
yield integration.updateIntegration({
|
|
204
205
|
projectId,
|
|
@@ -239,6 +240,7 @@ function filesCron({ config, integration, period, }) {
|
|
|
239
240
|
type: types_2.JobType.UPDATE_TO_CROWDIN,
|
|
240
241
|
title: 'Sync files to Crowdin [scheduled]',
|
|
241
242
|
payload: intFiles,
|
|
243
|
+
jobType: types_2.JobClientType.CRON,
|
|
242
244
|
jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
|
|
243
245
|
yield integration.updateCrowdin({
|
|
244
246
|
projectId,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { JobClient, JobType } from './types';
|
|
1
|
+
import { JobClient, JobClientType, JobType } from './types';
|
|
2
2
|
import { Response } from 'express';
|
|
3
|
-
export declare function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCallback, onError, }: {
|
|
3
|
+
export declare function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobType, jobCallback, onError, }: {
|
|
4
4
|
integrationId: string;
|
|
5
5
|
crowdinId: string;
|
|
6
6
|
type: JobType;
|
|
7
7
|
title?: string;
|
|
8
8
|
payload?: any;
|
|
9
9
|
res?: Response;
|
|
10
|
+
jobType: JobClientType;
|
|
10
11
|
jobCallback: (arg1: JobClient) => Promise<any>;
|
|
11
12
|
onError?: (e: any) => Promise<void>;
|
|
12
13
|
}): Promise<void>;
|
|
@@ -19,7 +19,7 @@ const blockingJobs = {
|
|
|
19
19
|
[types_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE]: [types_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE],
|
|
20
20
|
[types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE]: [types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE],
|
|
21
21
|
};
|
|
22
|
-
function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCallback, onError, }) {
|
|
22
|
+
function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobType, jobCallback, onError, }) {
|
|
23
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
const storage = (0, storage_1.getStorage)();
|
|
25
25
|
const activeJobs = yield storage.getActiveJobs({ integrationId, crowdinId });
|
|
@@ -65,6 +65,7 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, jobCall
|
|
|
65
65
|
return { isCanceled: false };
|
|
66
66
|
});
|
|
67
67
|
},
|
|
68
|
+
type: jobType,
|
|
68
69
|
};
|
|
69
70
|
try {
|
|
70
71
|
const data = yield jobCallback(job);
|
|
@@ -14,6 +14,10 @@ export declare enum JobStatus {
|
|
|
14
14
|
FAILED = "failed",
|
|
15
15
|
CANCELED = "canceled"
|
|
16
16
|
}
|
|
17
|
+
export declare enum JobClientType {
|
|
18
|
+
CRON = "cron",
|
|
19
|
+
MANUAL = "manual"
|
|
20
|
+
}
|
|
17
21
|
export interface Job {
|
|
18
22
|
id: string;
|
|
19
23
|
integrationId: string;
|
|
@@ -43,6 +47,7 @@ export type UpdateJobParams = {
|
|
|
43
47
|
export type JobClient = {
|
|
44
48
|
get: () => Promise<Job | undefined>;
|
|
45
49
|
update: UpdateJobProgress;
|
|
50
|
+
type: JobClientType;
|
|
46
51
|
};
|
|
47
52
|
export type UpdateJobProgress = ({ progress, status, info, data, }: Omit<UpdateJobParams, 'id'>) => Promise<{
|
|
48
53
|
isCanceled: boolean;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JobStatus = exports.JobType = void 0;
|
|
3
|
+
exports.JobClientType = exports.JobStatus = exports.JobType = void 0;
|
|
4
4
|
var JobType;
|
|
5
5
|
(function (JobType) {
|
|
6
6
|
JobType["UPDATE_TO_CROWDIN"] = "updateCrowdin";
|
|
@@ -16,3 +16,8 @@ var JobStatus;
|
|
|
16
16
|
JobStatus["FAILED"] = "failed";
|
|
17
17
|
JobStatus["CANCELED"] = "canceled";
|
|
18
18
|
})(JobStatus = exports.JobStatus || (exports.JobStatus = {}));
|
|
19
|
+
var JobClientType;
|
|
20
|
+
(function (JobClientType) {
|
|
21
|
+
JobClientType["CRON"] = "cron";
|
|
22
|
+
JobClientType["MANUAL"] = "manual";
|
|
23
|
+
})(JobClientType = exports.JobClientType || (exports.JobClientType = {}));
|
package/package.json
CHANGED