@crowdin/app-project-module 0.40.0 → 0.41.1
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/handlers/integration/crowdin-update.js +10 -0
- package/out/handlers/integration/settings-save.js +8 -1
- package/out/handlers/integration/sync-settings-save.js +39 -8
- package/out/handlers/uninstall.js +4 -2
- package/out/index.js +1 -1
- package/out/middlewares/integration-credentials.js +3 -2
- package/out/models/index.d.ts +7 -1
- package/out/models/job.d.ts +3 -1
- package/out/models/job.js +2 -0
- package/out/static/js/form.js +13 -13
- package/out/storage/index.d.ts +5 -2
- package/out/storage/mysql.d.ts +5 -2
- package/out/storage/mysql.js +49 -10
- package/out/storage/postgre.d.ts +5 -2
- package/out/storage/postgre.js +46 -9
- package/out/storage/sqlite.d.ts +8 -3
- package/out/storage/sqlite.js +64 -14
- package/out/util/cron.js +6 -3
- package/out/util/files.d.ts +3 -1
- package/out/util/files.js +24 -1
- package/out/util/job.js +3 -1
- package/out/util/logger.js +8 -8
- package/out/util/webhooks.js +3 -2
- package/out/views/main.handlebars +87 -18
- package/package.json +12 -10
|
@@ -8,12 +8,17 @@ 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
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const lodash_uniqby_1 = __importDefault(require("lodash.uniqby"));
|
|
12
16
|
const job_1 = require("../../models/job");
|
|
13
17
|
const util_1 = require("../../util");
|
|
14
18
|
const defaults_1 = require("../../util/defaults");
|
|
15
19
|
const logger_1 = require("../../util/logger");
|
|
16
20
|
const job_2 = require("../../util/job");
|
|
21
|
+
const files_1 = require("../../util/files");
|
|
17
22
|
function handle(config, integration) {
|
|
18
23
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
19
24
|
var _a, _b;
|
|
@@ -36,6 +41,11 @@ function handle(config, integration) {
|
|
|
36
41
|
payload: req.body,
|
|
37
42
|
res,
|
|
38
43
|
jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
var _c;
|
|
45
|
+
if (req.body && ((_c = req.body) === null || _c === void 0 ? void 0 : _c.length)) {
|
|
46
|
+
req.body = yield (0, files_1.expandFilesTree)(req.body, req, integration, job);
|
|
47
|
+
req.body = (0, lodash_uniqby_1.default)(req.body, 'id');
|
|
48
|
+
}
|
|
39
49
|
const result = yield integration.updateCrowdin({
|
|
40
50
|
projectId,
|
|
41
51
|
client: req.crowdinApiClient,
|
|
@@ -18,8 +18,15 @@ const webhooks_1 = require("../../util/webhooks");
|
|
|
18
18
|
function handle(config, integration) {
|
|
19
19
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
const appSettings = req.body.config;
|
|
21
|
+
const clientId = req.crowdinContext.clientId;
|
|
21
22
|
req.logInfo(`Saving settings ${JSON.stringify(appSettings, null, 2)}`);
|
|
22
|
-
yield (0, storage_1.getStorage)().
|
|
23
|
+
const integrationConfig = yield (0, storage_1.getStorage)().getIntegrationConfig(clientId);
|
|
24
|
+
if (!integrationConfig) {
|
|
25
|
+
yield (0, storage_1.getStorage)().saveIntegrationConfig(clientId, req.crowdinContext.crowdinId, JSON.stringify(appSettings));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
yield (0, storage_1.getStorage)().updateIntegrationConfig(clientId, JSON.stringify(appSettings));
|
|
29
|
+
}
|
|
23
30
|
if (integration.webhooks) {
|
|
24
31
|
yield (0, webhooks_1.registerWebhooks)(config, integration, req.crowdinApiClient, req.crowdinContext, req.integrationCredentials, appSettings);
|
|
25
32
|
}
|
|
@@ -8,20 +8,51 @@ 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
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const lodash_uniqby_1 = __importDefault(require("lodash.uniqby"));
|
|
12
16
|
const util_1 = require("../../util");
|
|
13
17
|
const cron_1 = require("../../util/cron");
|
|
14
18
|
const file_snapshot_1 = require("../../util/file-snapshot");
|
|
19
|
+
const files_1 = require("../../util/files");
|
|
20
|
+
const job_1 = require("../../util/job");
|
|
15
21
|
function handle(config, integration) {
|
|
16
22
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const { files, provider, expandIntegrationFolders } = req.body;
|
|
24
|
+
yield (0, job_1.runAsJob)({
|
|
25
|
+
integrationId: req.crowdinContext.clientId,
|
|
26
|
+
crowdinId: req.crowdinContext.crowdinId,
|
|
27
|
+
type: `${provider}SyncSettingsSave`,
|
|
28
|
+
title: 'Save sync settings',
|
|
29
|
+
payload: req.body,
|
|
30
|
+
res,
|
|
31
|
+
jobCallback: () => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
var _a;
|
|
33
|
+
if (Array.isArray(expandIntegrationFolders) && expandIntegrationFolders.length) {
|
|
34
|
+
const allFiles = (yield (0, files_1.expandFilesTree)(expandIntegrationFolders, req, integration)).map((node) => ({
|
|
35
|
+
id: node.id,
|
|
36
|
+
name: node.name,
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
38
|
+
node_type: node.nodeType,
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
40
|
+
parent_id: node.parentId,
|
|
41
|
+
schedule: true,
|
|
42
|
+
sync: false,
|
|
43
|
+
type: node.type,
|
|
44
|
+
}));
|
|
45
|
+
yield (0, cron_1.createOrUpdateSyncSettings)(config, req, (0, lodash_uniqby_1.default)([...files, ...allFiles], 'id'), provider);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
yield (0, cron_1.createOrUpdateSyncSettings)(config, req, files, provider);
|
|
49
|
+
}
|
|
50
|
+
const appSettings = req.integrationSettings || {};
|
|
51
|
+
if (((_a = integration.syncNewElements) === null || _a === void 0 ? void 0 : _a[provider]) && appSettings[`new-${provider}-files`]) {
|
|
52
|
+
yield (0, file_snapshot_1.createOrUpdateFileSnapshot)(config, integration, req, provider);
|
|
53
|
+
}
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
25
56
|
}));
|
|
26
57
|
}
|
|
27
58
|
exports.default = handle;
|
|
@@ -24,10 +24,12 @@ function handle(config) {
|
|
|
24
24
|
let allCredentials = [];
|
|
25
25
|
if (projectIntegration) {
|
|
26
26
|
const loadedCredentials = yield (0, storage_1.getStorage)().getAllIntegrationCredentials(organization);
|
|
27
|
+
const allIntegrationConfigs = yield (0, storage_1.getStorage)().getAllIntegrationConfigs(organization);
|
|
27
28
|
allCredentials = yield Promise.all(loadedCredentials.map((creds) => __awaiter(this, void 0, void 0, function* () {
|
|
28
29
|
let settings;
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const integrationConfig = allIntegrationConfigs.find(({ integrationId }) => integrationId === creds.id);
|
|
31
|
+
if (integrationConfig) {
|
|
32
|
+
settings = JSON.parse(integrationConfig.config);
|
|
31
33
|
}
|
|
32
34
|
const credentials = yield (0, connection_1.prepareIntegrationCredentials)(config, projectIntegration, creds);
|
|
33
35
|
return { settings, credentials };
|
package/out/index.js
CHANGED
|
@@ -108,7 +108,7 @@ exports.metadataStore = {
|
|
|
108
108
|
return storage.getStorage().deleteMetadata(id);
|
|
109
109
|
},
|
|
110
110
|
getUserSettings: (clientId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
-
const integrationCredentials = yield storage.getStorage().
|
|
111
|
+
const integrationCredentials = yield storage.getStorage().getIntegrationConfig(clientId);
|
|
112
112
|
if (integrationCredentials === null || integrationCredentials === void 0 ? void 0 : integrationCredentials.config) {
|
|
113
113
|
return JSON.parse(integrationCredentials.config);
|
|
114
114
|
}
|
|
@@ -17,14 +17,15 @@ function handle(config, integration, optional = false) {
|
|
|
17
17
|
const clientId = req.crowdinContext.clientId;
|
|
18
18
|
req.logInfo(`Loading integration credentials for client ${clientId}`);
|
|
19
19
|
const integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(clientId);
|
|
20
|
+
const integrationConfig = yield (0, storage_1.getStorage)().getIntegrationConfig(clientId);
|
|
20
21
|
if (!integrationCredentials) {
|
|
21
22
|
if (optional) {
|
|
22
23
|
return next();
|
|
23
24
|
}
|
|
24
25
|
return res.status(403).send({ error: 'Access denied' });
|
|
25
26
|
}
|
|
26
|
-
if (
|
|
27
|
-
req.integrationSettings = JSON.parse(
|
|
27
|
+
if (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config) {
|
|
28
|
+
req.integrationSettings = JSON.parse(integrationConfig.config);
|
|
28
29
|
}
|
|
29
30
|
try {
|
|
30
31
|
req.integrationCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
package/out/models/index.d.ts
CHANGED
|
@@ -577,13 +577,19 @@ export interface IntegrationCredentials {
|
|
|
577
577
|
id: string;
|
|
578
578
|
credentials: any;
|
|
579
579
|
crowdinId: string;
|
|
580
|
-
|
|
580
|
+
}
|
|
581
|
+
export interface IntegrationConfig {
|
|
582
|
+
id: number;
|
|
583
|
+
integrationId: string;
|
|
584
|
+
crowdinId: string;
|
|
585
|
+
config: any;
|
|
581
586
|
}
|
|
582
587
|
export interface IntegrationFile {
|
|
583
588
|
id: string;
|
|
584
589
|
name: string;
|
|
585
590
|
type: SourceFilesModel.FileType;
|
|
586
591
|
parentId: string;
|
|
592
|
+
nodeType?: IntegrationTreeElementType;
|
|
587
593
|
}
|
|
588
594
|
export interface UpdateIntegrationRequest {
|
|
589
595
|
[fileId: string]: string[];
|
package/out/models/job.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare enum JobType {
|
|
2
2
|
UPDATE_TO_CROWDIN = "updateCrowdin",
|
|
3
|
-
UPDATE_TO_INTEGRATION = "updateIntegration"
|
|
3
|
+
UPDATE_TO_INTEGRATION = "updateIntegration",
|
|
4
|
+
CROWDIN_SYNC_SETTINGS_SAVE = "crowdinSyncSettingsSave",
|
|
5
|
+
INTEGRATION_SYNC_SETTINGS_SAVE = "integrationSyncSettingsSave"
|
|
4
6
|
}
|
|
5
7
|
export declare enum JobStatus {
|
|
6
8
|
CREATED = "created",
|
package/out/models/job.js
CHANGED
|
@@ -5,6 +5,8 @@ var JobType;
|
|
|
5
5
|
(function (JobType) {
|
|
6
6
|
JobType["UPDATE_TO_CROWDIN"] = "updateCrowdin";
|
|
7
7
|
JobType["UPDATE_TO_INTEGRATION"] = "updateIntegration";
|
|
8
|
+
JobType["CROWDIN_SYNC_SETTINGS_SAVE"] = "crowdinSyncSettingsSave";
|
|
9
|
+
JobType["INTEGRATION_SYNC_SETTINGS_SAVE"] = "integrationSyncSettingsSave";
|
|
8
10
|
})(JobType = exports.JobType || (exports.JobType = {}));
|
|
9
11
|
var JobStatus;
|
|
10
12
|
(function (JobStatus) {
|