@crowdin/app-project-module 0.44.0 → 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 +52 -59
- package/out/middlewares/crowdin-client.d.ts +1 -1
- package/out/middlewares/crowdin-client.js +3 -2
- package/out/middlewares/integration-credentials.d.ts +2 -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 +3 -3
- package/out/{util → modules}/api/api.d.ts +2 -1
- 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 +1 -1
- package/out/modules/context-menu/index.js +2 -2
- package/out/modules/context-menu/types.d.ts +27 -0
- package/out/modules/context-menu/types.js +18 -0
- package/out/modules/custom-mt/handlers/translate.d.ts +1 -1
- package/out/modules/custom-mt/index.d.ts +1 -1
- package/out/modules/custom-mt/types.d.ts +1 -1
- package/out/modules/custom-spell-check/handlers/get-languages-list.d.ts +1 -1
- package/out/modules/custom-spell-check/handlers/spell-check.d.ts +1 -1
- package/out/modules/custom-spell-check/index.d.ts +1 -1
- package/out/modules/custom-spell-check/index.js +2 -2
- package/out/modules/custom-spell-check/types.d.ts +1 -1
- package/out/modules/editor-right-panel/index.d.ts +1 -1
- package/out/modules/editor-right-panel/index.js +2 -2
- package/out/modules/editor-right-panel/types.d.ts +1 -1
- package/out/modules/editor-themes/index.d.ts +1 -1
- package/out/modules/editor-themes/types.d.ts +17 -0
- package/out/modules/editor-themes/types.js +2 -0
- package/out/modules/file-processing/handlers/custom-file-format.d.ts +1 -1
- package/out/modules/file-processing/handlers/custom-file-format.js +1 -1
- package/out/modules/file-processing/handlers/file-download.d.ts +2 -2
- package/out/modules/file-processing/handlers/pre-post-process.d.ts +1 -1
- package/out/modules/file-processing/handlers/pre-post-process.js +1 -1
- package/out/modules/file-processing/index.d.ts +1 -1
- package/out/modules/file-processing/index.js +1 -1
- package/out/modules/file-processing/types.d.ts +1 -1
- 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/modules/form-data-display.d.ts +1 -1
- package/out/modules/form-data-save.d.ts +1 -1
- package/out/modules/install.d.ts +2 -2
- package/out/modules/install.js +3 -3
- package/out/modules/integration/handlers/crowdin-file-progress.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-files.d.ts +2 -2
- package/out/modules/integration/handlers/crowdin-files.js +1 -1
- package/out/modules/integration/handlers/crowdin-project.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-update.d.ts +2 -2
- package/out/modules/integration/handlers/crowdin-update.js +7 -7
- package/out/modules/integration/handlers/crowdin-webhook.d.ts +2 -2
- package/out/modules/integration/handlers/crowdin-webhook.js +16 -5
- package/out/modules/integration/handlers/integration-data.d.ts +1 -1
- package/out/modules/integration/handlers/integration-data.js +2 -2
- package/out/modules/integration/handlers/integration-login.d.ts +1 -1
- package/out/modules/integration/handlers/integration-logout.d.ts +2 -2
- package/out/modules/integration/handlers/integration-logout.js +11 -4
- package/out/modules/integration/handlers/integration-update.d.ts +2 -2
- package/out/modules/integration/handlers/integration-update.js +7 -6
- package/out/modules/integration/handlers/integration-webhook.d.ts +2 -2
- package/out/modules/integration/handlers/integration-webhook.js +7 -2
- package/out/modules/integration/handlers/job-cancel.d.ts +1 -1
- package/out/modules/integration/handlers/job-cancel.js +2 -2
- package/out/modules/integration/handlers/job-info.d.ts +1 -1
- package/out/modules/integration/handlers/job-info.js +2 -2
- package/out/modules/integration/handlers/main.d.ts +2 -2
- package/out/modules/integration/handlers/main.js +3 -3
- package/out/modules/integration/handlers/oauth-login.d.ts +2 -2
- package/out/modules/integration/handlers/oauth-login.js +1 -1
- package/out/modules/integration/handlers/oauth-url.d.ts +1 -1
- package/out/modules/integration/handlers/oauth-url.js +1 -1
- package/out/modules/integration/handlers/settings-save.d.ts +2 -2
- package/out/modules/integration/handlers/settings-save.js +25 -8
- package/out/modules/integration/handlers/settings.d.ts +1 -1
- package/out/modules/integration/handlers/subscription-info.d.ts +1 -1
- package/out/modules/integration/handlers/subscription-info.js +2 -2
- package/out/modules/integration/handlers/sync-settings-save.d.ts +2 -2
- package/out/modules/integration/handlers/sync-settings-save.js +15 -7
- package/out/modules/integration/handlers/sync-settings.d.ts +1 -1
- package/out/modules/integration/handlers/user-errors.d.ts +1 -1
- package/out/modules/integration/index.d.ts +1 -1
- package/out/modules/integration/index.js +15 -10
- package/out/modules/integration/types.d.ts +2 -13
- package/out/modules/integration/util/cron.d.ts +27 -0
- package/out/{util → modules/integration/util}/cron.js +92 -23
- package/out/{util → modules/integration/util}/defaults.d.ts +2 -6
- package/out/{util → modules/integration/util}/defaults.js +1 -46
- 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 -4
- package/out/{util/file-snapshot.js → modules/integration/util/snapshot.js} +4 -63
- 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 +92 -46
- package/out/modules/manifest.d.ts +1 -1
- package/out/modules/manifest.js +6 -6
- package/out/modules/modal/index.d.ts +1 -1
- package/out/modules/modal/index.js +2 -2
- package/out/modules/organization-menu/index.d.ts +1 -1
- package/out/modules/organization-menu/index.js +1 -2
- package/out/modules/profile-resources-menu/index.d.ts +1 -1
- package/out/modules/profile-resources-menu/index.js +1 -2
- package/out/modules/project-menu/index.d.ts +1 -1
- package/out/modules/project-menu/index.js +2 -2
- package/out/modules/project-menu-crowdsource/index.d.ts +1 -1
- package/out/modules/project-menu-crowdsource/index.js +2 -2
- package/out/modules/project-reports/index.d.ts +1 -1
- package/out/modules/project-reports/index.js +1 -2
- package/out/modules/project-tools/index.d.ts +1 -1
- package/out/modules/project-tools/index.js +1 -2
- package/out/modules/subscription-paid.d.ts +1 -1
- package/out/modules/subscription-paid.js +2 -2
- package/out/modules/uninstall.d.ts +2 -2
- package/out/modules/uninstall.js +6 -2
- package/out/storage/index.d.ts +3 -2
- package/out/storage/mysql.d.ts +3 -2
- package/out/storage/mysql.js +3 -3
- package/out/storage/postgre.d.ts +3 -2
- package/out/storage/postgre.js +3 -3
- package/out/storage/sqlite.d.ts +3 -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/{models/index.d.ts → types.d.ts} +15 -83
- package/out/{models/index.js → types.js} +1 -24
- package/out/util/connection.d.ts +1 -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 -3
- package/out/util/index.js +6 -6
- package/out/util/logger.d.ts +1 -1
- package/out/util/subscription.d.ts +9 -0
- package/out/util/subscription.js +111 -0
- package/package.json +1 -1
- package/out/util/cron.d.ts +0 -8
- package/out/util/files.d.ts +0 -10
- package/out/util/webhooks.d.ts +0 -29
- /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/{models/job.js → modules/integration/util/types.js} +0 -0
|
@@ -35,15 +35,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.listenQueueMessage = exports.updateCrowdinFromWebhookRequest = exports.prepareWebhookData = exports.unregisterAllCrowdinWebhooks = exports.
|
|
38
|
+
exports.listenQueueMessage = exports.updateCrowdinFromWebhookRequest = exports.prepareWebhookData = exports.unregisterAllCrowdinWebhooks = exports.unregisterWebhooks = exports.registerWebhooks = exports.HookEvents = void 0;
|
|
39
39
|
const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
|
|
40
40
|
const amqplib_1 = __importDefault(require("amqplib"));
|
|
41
|
-
const
|
|
42
|
-
const
|
|
41
|
+
const types_1 = require("../types");
|
|
42
|
+
const storage_1 = require("../../../storage");
|
|
43
|
+
const connection_1 = require("../../../util/connection");
|
|
43
44
|
const defaults_1 = require("./defaults");
|
|
44
|
-
const index_1 = require("
|
|
45
|
-
const logger_1 = require("
|
|
46
|
-
const types_1 = require("../modules/integration/types");
|
|
45
|
+
const index_1 = require("../../../util/index");
|
|
46
|
+
const logger_1 = require("../../../util/logger");
|
|
47
47
|
const prefetchCount = 20;
|
|
48
48
|
const forceProcessDelay = 5000;
|
|
49
49
|
exports.HookEvents = {
|
|
@@ -58,7 +58,7 @@ const HookConditionEvents = {
|
|
|
58
58
|
TRANSLATED: [exports.HookEvents.fileTranslated, exports.HookEvents.fileDeleted],
|
|
59
59
|
APPROVED: [exports.HookEvents.fileApproved, exports.HookEvents.fileDeleted],
|
|
60
60
|
};
|
|
61
|
-
function encodedUrlParam(config, integration,
|
|
61
|
+
function encodedUrlParam({ config, crowdinContext, integration, }) {
|
|
62
62
|
var _a;
|
|
63
63
|
const params = {
|
|
64
64
|
projectId: +crowdinContext.jwtPayload.context.project_id,
|
|
@@ -68,44 +68,61 @@ function encodedUrlParam(config, integration, crowdinContext) {
|
|
|
68
68
|
const encryptedParams = (0, index_1.encryptData)(config, JSON.stringify(params));
|
|
69
69
|
return `${(_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.urlParam}=${encodeURIComponent(encryptedParams)}`;
|
|
70
70
|
}
|
|
71
|
-
exports.encodedUrlParam = encodedUrlParam;
|
|
72
71
|
function decodedUrlParam(config, data) {
|
|
73
72
|
const params = (0, index_1.decryptData)(config, data);
|
|
74
73
|
return JSON.parse(params);
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
function makeCrowdinWebhookUrl(config, integration, crowdinContext) {
|
|
75
|
+
function makeCrowdinWebhookUrl({ config, crowdinContext, integration, }) {
|
|
78
76
|
var _a;
|
|
79
|
-
const urlParam = encodedUrlParam(config, integration, crowdinContext);
|
|
77
|
+
const urlParam = encodedUrlParam({ config, integration, crowdinContext });
|
|
80
78
|
return (`${config.baseUrl}${((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.crowdinWebhookUrl) ? integration.webhooks.crowdinWebhookUrl : '/api/crowdin/webhook'}` + `?${urlParam}`);
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
function registerWebhooks(config, integration, client, crowdinContext, apiCredentials, appSettings) {
|
|
80
|
+
function registerWebhooks({ config, apiCredentials, appSettings, client, crowdinContext, integration, }) {
|
|
84
81
|
var _a, _b;
|
|
85
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
83
|
const isWebhookSync = Number(appSettings.schedule) !== types_1.SyncSchedule.DISABLED;
|
|
87
84
|
const projectId = crowdinContext.jwtPayload.context.project_id;
|
|
88
|
-
const urlParam = encodedUrlParam(config, integration, crowdinContext);
|
|
85
|
+
const urlParam = encodedUrlParam({ config, integration, crowdinContext });
|
|
89
86
|
if ((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.crowdinWebhooks) {
|
|
90
87
|
yield integration.webhooks.crowdinWebhooks(client, projectId, isWebhookSync, appSettings);
|
|
91
88
|
}
|
|
92
89
|
else {
|
|
93
90
|
const webhookName = `${config.name} application hook ${crowdinContext.jwtPayload.sub}`;
|
|
94
|
-
const webhookUrl = makeCrowdinWebhookUrl(
|
|
91
|
+
const webhookUrl = makeCrowdinWebhookUrl({
|
|
92
|
+
config,
|
|
93
|
+
integration,
|
|
94
|
+
crowdinContext,
|
|
95
|
+
});
|
|
95
96
|
const syncCondition = types_1.SyncCondition[Number(appSettings.condition)];
|
|
96
97
|
const events = [...HookConditionEvents[syncCondition]];
|
|
97
|
-
const webhook = yield getCrowdinProjectWebhook(
|
|
98
|
+
const webhook = yield getCrowdinProjectWebhook({
|
|
99
|
+
client,
|
|
100
|
+
projectId,
|
|
101
|
+
name: webhookName,
|
|
102
|
+
});
|
|
98
103
|
if (appSettings['new-crowdin-files']) {
|
|
99
104
|
events.push(exports.HookEvents.fileAdded);
|
|
100
105
|
}
|
|
101
106
|
if (isWebhookSync && webhook) {
|
|
102
|
-
yield updateCrowdinWebhooks(
|
|
107
|
+
yield updateCrowdinWebhooks({
|
|
108
|
+
client,
|
|
109
|
+
projectId,
|
|
110
|
+
webhook,
|
|
111
|
+
events,
|
|
112
|
+
url: webhookUrl,
|
|
113
|
+
});
|
|
103
114
|
}
|
|
104
115
|
else if (isWebhookSync && !webhook) {
|
|
105
|
-
yield registerCrowdinWebhook(
|
|
116
|
+
yield registerCrowdinWebhook({
|
|
117
|
+
config,
|
|
118
|
+
url: webhookUrl,
|
|
119
|
+
client,
|
|
120
|
+
crowdinContext,
|
|
121
|
+
events,
|
|
122
|
+
});
|
|
106
123
|
}
|
|
107
124
|
else if (!isWebhookSync && webhook) {
|
|
108
|
-
yield unregisterCrowdinWebhooks(
|
|
125
|
+
yield unregisterCrowdinWebhooks({ client, projectId, webhook });
|
|
109
126
|
}
|
|
110
127
|
}
|
|
111
128
|
if ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhooks) {
|
|
@@ -114,7 +131,7 @@ function registerWebhooks(config, integration, client, crowdinContext, apiCreden
|
|
|
114
131
|
});
|
|
115
132
|
}
|
|
116
133
|
exports.registerWebhooks = registerWebhooks;
|
|
117
|
-
function unregisterWebhooks(
|
|
134
|
+
function unregisterWebhooks({ apiCredentials, appSettings, client, config, crowdinContext, integration, }) {
|
|
118
135
|
var _a, _b;
|
|
119
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
120
137
|
if ((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.crowdinWebhooks) {
|
|
@@ -122,32 +139,38 @@ function unregisterWebhooks(config, integration, client, crowdinContext, apiCred
|
|
|
122
139
|
}
|
|
123
140
|
else {
|
|
124
141
|
const webhookName = `${config.name} application hook ${crowdinContext.jwtPayload.sub}`;
|
|
125
|
-
const webhook = yield getCrowdinProjectWebhook(
|
|
142
|
+
const webhook = yield getCrowdinProjectWebhook({
|
|
143
|
+
client,
|
|
144
|
+
projectId: crowdinContext.jwtPayload.context.project_id,
|
|
145
|
+
name: webhookName,
|
|
146
|
+
});
|
|
126
147
|
if (webhook) {
|
|
127
|
-
yield unregisterCrowdinWebhooks(
|
|
148
|
+
yield unregisterCrowdinWebhooks({
|
|
149
|
+
client,
|
|
150
|
+
projectId: crowdinContext.jwtPayload.context.project_id,
|
|
151
|
+
webhook,
|
|
152
|
+
});
|
|
128
153
|
}
|
|
129
154
|
}
|
|
130
155
|
if ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhooks) {
|
|
131
|
-
const urlParam = encodedUrlParam(config, integration, crowdinContext);
|
|
156
|
+
const urlParam = encodedUrlParam({ config, integration, crowdinContext });
|
|
132
157
|
yield integration.webhooks.integrationWebhooks(apiCredentials, urlParam, false, appSettings);
|
|
133
158
|
}
|
|
134
159
|
});
|
|
135
160
|
}
|
|
136
161
|
exports.unregisterWebhooks = unregisterWebhooks;
|
|
137
|
-
function getCrowdinProjectWebhook(
|
|
162
|
+
function getCrowdinProjectWebhook({ client, name, projectId, }) {
|
|
138
163
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
164
|
const hooks = (yield client.webhooksApi.withFetchAll().listWebhooks(projectId)).data.map((e) => e.data);
|
|
140
165
|
return hooks.find((h) => h.name === name);
|
|
141
166
|
});
|
|
142
167
|
}
|
|
143
|
-
|
|
144
|
-
function getAllCrowdinProjectWebhooks(config, client, projectId) {
|
|
168
|
+
function getAllCrowdinProjectWebhooks({ client, config, projectId, }) {
|
|
145
169
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
170
|
const hooks = (yield client.webhooksApi.withFetchAll().listWebhooks(projectId)).data.map((e) => e.data);
|
|
147
171
|
return hooks.filter((h) => h.name.startsWith(`${config.name} application hook `));
|
|
148
172
|
});
|
|
149
173
|
}
|
|
150
|
-
exports.getAllCrowdinProjectWebhooks = getAllCrowdinProjectWebhooks;
|
|
151
174
|
function createPayload(events) {
|
|
152
175
|
const payload = {};
|
|
153
176
|
for (const event of events) {
|
|
@@ -160,7 +183,7 @@ function createPayload(events) {
|
|
|
160
183
|
}
|
|
161
184
|
return payload;
|
|
162
185
|
}
|
|
163
|
-
function registerCrowdinWebhook(config,
|
|
186
|
+
function registerCrowdinWebhook({ client, config, crowdinContext, events, url, }) {
|
|
164
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
165
188
|
const name = `${config.name} application hook ${crowdinContext.jwtPayload.sub}`;
|
|
166
189
|
const payload = createPayload(events);
|
|
@@ -174,8 +197,7 @@ function registerCrowdinWebhook(config, url, client, crowdinContext, events) {
|
|
|
174
197
|
});
|
|
175
198
|
});
|
|
176
199
|
}
|
|
177
|
-
|
|
178
|
-
function updateCrowdinWebhooks(config, client, projectId, webhook, events, url) {
|
|
200
|
+
function updateCrowdinWebhooks({ client, events, projectId, url, webhook, }) {
|
|
179
201
|
return __awaiter(this, void 0, void 0, function* () {
|
|
180
202
|
const payload = createPayload(events);
|
|
181
203
|
yield client.webhooksApi.editWebhook(projectId, webhook.id, [
|
|
@@ -197,14 +219,12 @@ function updateCrowdinWebhooks(config, client, projectId, webhook, events, url)
|
|
|
197
219
|
]);
|
|
198
220
|
});
|
|
199
221
|
}
|
|
200
|
-
|
|
201
|
-
function unregisterCrowdinWebhooks(config, client, projectId, webhook) {
|
|
222
|
+
function unregisterCrowdinWebhooks({ client, projectId, webhook, }) {
|
|
202
223
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203
224
|
yield client.webhooksApi.deleteWebhook(projectId, webhook.id);
|
|
204
225
|
});
|
|
205
226
|
}
|
|
206
|
-
|
|
207
|
-
function unregisterAllCrowdinWebhooks(config, integration, crowdinId) {
|
|
227
|
+
function unregisterAllCrowdinWebhooks({ config, crowdinId, integration, }) {
|
|
208
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
209
229
|
if (integration.webhooks) {
|
|
210
230
|
const crowdinCredentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(crowdinId);
|
|
@@ -213,15 +233,25 @@ function unregisterAllCrowdinWebhooks(config, integration, crowdinId) {
|
|
|
213
233
|
const projectIds = credentials.map((c) => crowdinAppFunctions.getProjectId(c.id));
|
|
214
234
|
const crowdinClient = yield (0, connection_1.prepareCrowdinClient)({ config, credentials: crowdinCredentials });
|
|
215
235
|
yield Promise.all(projectIds.map((projectId) => __awaiter(this, void 0, void 0, function* () {
|
|
216
|
-
const webhooks = yield getAllCrowdinProjectWebhooks(
|
|
217
|
-
|
|
236
|
+
const webhooks = yield getAllCrowdinProjectWebhooks({
|
|
237
|
+
config,
|
|
238
|
+
client: crowdinClient.client,
|
|
239
|
+
projectId,
|
|
240
|
+
});
|
|
241
|
+
yield Promise.all(webhooks.map((hook) => __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
return yield unregisterCrowdinWebhooks({
|
|
243
|
+
client: crowdinClient.client,
|
|
244
|
+
projectId,
|
|
245
|
+
webhook: hook,
|
|
246
|
+
});
|
|
247
|
+
})));
|
|
218
248
|
})));
|
|
219
249
|
}
|
|
220
250
|
}
|
|
221
251
|
});
|
|
222
252
|
}
|
|
223
253
|
exports.unregisterAllCrowdinWebhooks = unregisterAllCrowdinWebhooks;
|
|
224
|
-
function prepareWebhookData(config, integration, webhookUrlParam,
|
|
254
|
+
function prepareWebhookData({ config, integration, provider, webhookUrlParam, }) {
|
|
225
255
|
return __awaiter(this, void 0, void 0, function* () {
|
|
226
256
|
let rootFolder = undefined;
|
|
227
257
|
let syncSettings = null;
|
|
@@ -298,13 +328,13 @@ function updateCrowdinFromWebhookRequest(args) {
|
|
|
298
328
|
});
|
|
299
329
|
}
|
|
300
330
|
exports.updateCrowdinFromWebhookRequest = updateCrowdinFromWebhookRequest;
|
|
301
|
-
function listenQueueMessage(config, integration, queueUrl,
|
|
331
|
+
function listenQueueMessage({ config, integration, queueName, queueUrl, }) {
|
|
302
332
|
return __awaiter(this, void 0, void 0, function* () {
|
|
303
333
|
try {
|
|
304
334
|
const connection = yield amqplib_1.default.connect(queueUrl);
|
|
305
335
|
connection.once('close', function () {
|
|
306
336
|
setTimeout(() => {
|
|
307
|
-
listenQueueMessage(config, integration, queueUrl, queueName);
|
|
337
|
+
listenQueueMessage({ config, integration, queueUrl, queueName });
|
|
308
338
|
}, 3000);
|
|
309
339
|
return;
|
|
310
340
|
});
|
|
@@ -312,18 +342,19 @@ function listenQueueMessage(config, integration, queueUrl, queueName) {
|
|
|
312
342
|
if (channel) {
|
|
313
343
|
yield channel.assertQueue(queueName, { durable: true });
|
|
314
344
|
yield channel.prefetch(prefetchCount);
|
|
315
|
-
|
|
345
|
+
const onMessage = consumer({ channel, config, integration });
|
|
346
|
+
yield channel.consume(queueName, onMessage, { noAck: false });
|
|
316
347
|
}
|
|
317
348
|
}
|
|
318
349
|
catch (e) {
|
|
319
350
|
setTimeout(() => {
|
|
320
|
-
listenQueueMessage(config, integration, queueUrl, queueName);
|
|
351
|
+
listenQueueMessage({ config, integration, queueUrl, queueName });
|
|
321
352
|
}, 3000);
|
|
322
353
|
}
|
|
323
354
|
});
|
|
324
355
|
}
|
|
325
356
|
exports.listenQueueMessage = listenQueueMessage;
|
|
326
|
-
function consumer(channel, config, integration) {
|
|
357
|
+
function consumer({ channel, config, integration, }) {
|
|
327
358
|
let messagesCounter = 0;
|
|
328
359
|
let webhooksInfo = {};
|
|
329
360
|
let webhooksData = [];
|
|
@@ -350,7 +381,12 @@ function consumer(channel, config, integration) {
|
|
|
350
381
|
webhooksInfo[clientId] = {};
|
|
351
382
|
webhooksInfo[clientId].data = [data];
|
|
352
383
|
webhooksInfo[clientId].integration = integration;
|
|
353
|
-
webhooksData.push(prepareWebhookData(
|
|
384
|
+
webhooksData.push(prepareWebhookData({
|
|
385
|
+
config,
|
|
386
|
+
integration,
|
|
387
|
+
webhookUrlParam,
|
|
388
|
+
provider: types_1.Provider.INTEGRATION,
|
|
389
|
+
}).then((res) => {
|
|
354
390
|
webhooksInfo[clientId].webhookData = res;
|
|
355
391
|
}));
|
|
356
392
|
}
|
|
@@ -360,13 +396,23 @@ function consumer(channel, config, integration) {
|
|
|
360
396
|
if (messagesCounter < prefetchCount) {
|
|
361
397
|
// if all messages are not received, wait 5 seconds to force process messages
|
|
362
398
|
timeoutId = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
363
|
-
yield processMessages(
|
|
399
|
+
yield processMessages({
|
|
400
|
+
webhooksData,
|
|
401
|
+
webhooksInfo,
|
|
402
|
+
channel,
|
|
403
|
+
msg,
|
|
404
|
+
});
|
|
364
405
|
resetStateVariables();
|
|
365
406
|
}), forceProcessDelay);
|
|
366
407
|
return;
|
|
367
408
|
}
|
|
368
409
|
clearTimeout(timeoutId);
|
|
369
|
-
yield processMessages(
|
|
410
|
+
yield processMessages({
|
|
411
|
+
webhooksData,
|
|
412
|
+
webhooksInfo,
|
|
413
|
+
channel,
|
|
414
|
+
msg,
|
|
415
|
+
});
|
|
370
416
|
resetStateVariables();
|
|
371
417
|
}
|
|
372
418
|
catch (e) {
|
|
@@ -375,7 +421,7 @@ function consumer(channel, config, integration) {
|
|
|
375
421
|
});
|
|
376
422
|
};
|
|
377
423
|
}
|
|
378
|
-
function processMessages(webhooksData, webhooksInfo,
|
|
424
|
+
function processMessages({ channel, msg, webhooksData, webhooksInfo, }) {
|
|
379
425
|
return __awaiter(this, void 0, void 0, function* () {
|
|
380
426
|
yield Promise.all(webhooksData);
|
|
381
427
|
for (const { data, integration, webhookData } of Object.values(webhooksInfo)) {
|
package/out/modules/manifest.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const types_1 = require("../types");
|
|
4
4
|
const util_1 = require("../util");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const subscription_1 = require("../util/subscription");
|
|
6
|
+
const api_1 = require("./api/api");
|
|
7
7
|
function normalizeEnvironments(environments) {
|
|
8
8
|
if (Array.isArray(environments)) {
|
|
9
9
|
return environments;
|
|
@@ -214,14 +214,14 @@ function handle(config) {
|
|
|
214
214
|
installed: '/installed',
|
|
215
215
|
uninstall: '/uninstall',
|
|
216
216
|
};
|
|
217
|
-
if (!(0,
|
|
217
|
+
if (!(0, subscription_1.isAppFree)(config)) {
|
|
218
218
|
events['subscription_paid'] = '/subscription-paid';
|
|
219
219
|
}
|
|
220
220
|
return (_req, res) => {
|
|
221
221
|
const manifest = Object.assign(Object.assign({ identifier: config.identifier, name: config.name, logo: (0, util_1.getLogoUrl)(), baseUrl: config.baseUrl, authentication: {
|
|
222
|
-
type: config.authenticationType ||
|
|
222
|
+
type: config.authenticationType || types_1.AuthenticationType.APP,
|
|
223
223
|
clientId: config.clientId,
|
|
224
|
-
}, events, scopes: config.scopes ? config.scopes : [
|
|
224
|
+
}, events, scopes: config.scopes ? config.scopes : [types_1.Scope.PROJECTS] }, (config.defaultPermissions && { default_permissions: config.defaultPermissions })), { modules });
|
|
225
225
|
res.send(manifest);
|
|
226
226
|
};
|
|
227
227
|
}
|
|
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.register = void 0;
|
|
7
7
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
8
8
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
9
|
-
const
|
|
9
|
+
const util_1 = require("../../util");
|
|
10
10
|
function register({ config, app }) {
|
|
11
11
|
var _a, _b;
|
|
12
|
-
const allowUnauthorized = !(0,
|
|
12
|
+
const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config);
|
|
13
13
|
if (((_a = config.modal) === null || _a === void 0 ? void 0 : _a.uiPath) || ((_b = config.modal) === null || _b === void 0 ? void 0 : _b.formSchema)) {
|
|
14
14
|
app.use('/modal', (0, ui_module_1.default)(config, allowUnauthorized), (0, render_ui_module_1.default)(config.modal));
|
|
15
15
|
}
|
|
@@ -7,12 +7,11 @@ exports.register = void 0;
|
|
|
7
7
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
8
8
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
9
9
|
const util_1 = require("../../util");
|
|
10
|
-
const defaults_1 = require("../../util/defaults");
|
|
11
10
|
function register({ config, app }) {
|
|
12
11
|
if (!config.organizationMenu) {
|
|
13
12
|
return;
|
|
14
13
|
}
|
|
15
|
-
const allowUnauthorized = !(0,
|
|
14
|
+
const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config);
|
|
16
15
|
app.get((0, util_1.getLogoUrl)(config.organizationMenu, '/resources'), (req, res) => { var _a; return res.sendFile(((_a = config.organizationMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
|
|
17
16
|
app.use('/resources', (0, ui_module_1.default)(config, allowUnauthorized), (0, render_ui_module_1.default)(config.organizationMenu));
|
|
18
17
|
}
|
|
@@ -7,13 +7,12 @@ exports.register = void 0;
|
|
|
7
7
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
8
8
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
9
9
|
const util_1 = require("../../util");
|
|
10
|
-
const defaults_1 = require("../../util/defaults");
|
|
11
10
|
function register({ config, app }) {
|
|
12
11
|
if (!config.profileResourcesMenu) {
|
|
13
12
|
return;
|
|
14
13
|
}
|
|
15
14
|
app.get((0, util_1.getLogoUrl)(config.profileResourcesMenu, '/resources'), (req, res) => { var _a; return res.sendFile(((_a = config.profileResourcesMenu) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
|
|
16
|
-
const allowUnauthorized = !(0,
|
|
15
|
+
const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config);
|
|
17
16
|
app.use('/resources', (0, ui_module_1.default)(config, allowUnauthorized), (0, render_ui_module_1.default)(config.profileResourcesMenu));
|
|
18
17
|
}
|
|
19
18
|
exports.register = register;
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.register = void 0;
|
|
7
7
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
8
8
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
9
|
-
const
|
|
9
|
+
const util_1 = require("../../util");
|
|
10
10
|
function register({ config, app }) {
|
|
11
11
|
if (!config.projectMenu) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const allowUnauthorized = !(0,
|
|
14
|
+
const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config);
|
|
15
15
|
app.use('/project-menu', (0, ui_module_1.default)(config, allowUnauthorized), (0, render_ui_module_1.default)(config.projectMenu));
|
|
16
16
|
}
|
|
17
17
|
exports.register = register;
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.register = void 0;
|
|
7
7
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
8
8
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
9
|
-
const
|
|
9
|
+
const util_1 = require("../../util");
|
|
10
10
|
function register({ config, app }) {
|
|
11
11
|
if (!config.projectMenuCrowdsource) {
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
const allowUnauthorized = !(0,
|
|
14
|
+
const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config);
|
|
15
15
|
app.use('/project-menu-crowdsource', (0, ui_module_1.default)(config, allowUnauthorized), (0, render_ui_module_1.default)(config.projectMenuCrowdsource));
|
|
16
16
|
}
|
|
17
17
|
exports.register = register;
|
|
@@ -7,12 +7,11 @@ exports.register = void 0;
|
|
|
7
7
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
8
8
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
9
9
|
const util_1 = require("../../util");
|
|
10
|
-
const defaults_1 = require("../../util/defaults");
|
|
11
10
|
function register({ config, app }) {
|
|
12
11
|
if (!config.projectReports) {
|
|
13
12
|
return;
|
|
14
13
|
}
|
|
15
|
-
const allowUnauthorized = !(0,
|
|
14
|
+
const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config);
|
|
16
15
|
app.get((0, util_1.getLogoUrl)(config.projectReports, '/reports'), (req, res) => { var _a; return res.sendFile(((_a = config.projectReports) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
|
|
17
16
|
app.use('/reports', (0, ui_module_1.default)(config, allowUnauthorized), (0, render_ui_module_1.default)(config.projectReports));
|
|
18
17
|
}
|
|
@@ -7,12 +7,11 @@ exports.register = void 0;
|
|
|
7
7
|
const render_ui_module_1 = __importDefault(require("../../middlewares/render-ui-module"));
|
|
8
8
|
const ui_module_1 = __importDefault(require("../../middlewares/ui-module"));
|
|
9
9
|
const util_1 = require("../../util");
|
|
10
|
-
const defaults_1 = require("../../util/defaults");
|
|
11
10
|
function register({ config, app }) {
|
|
12
11
|
if (!config.projectTools) {
|
|
13
12
|
return;
|
|
14
13
|
}
|
|
15
|
-
const allowUnauthorized = !(0,
|
|
14
|
+
const allowUnauthorized = !(0, util_1.isAuthorizedConfig)(config);
|
|
16
15
|
app.get((0, util_1.getLogoUrl)(config.projectTools, '/tools'), (req, res) => { var _a; return res.sendFile(((_a = config.projectTools) === null || _a === void 0 ? void 0 : _a.imagePath) || config.imagePath); });
|
|
17
16
|
app.use('/tools', (0, ui_module_1.default)(config, allowUnauthorized), (0, render_ui_module_1.default)(config.projectTools));
|
|
18
17
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
|
-
export default function handle(): (req: import("../
|
|
3
|
+
export default function handle(): (req: import("../types").CrowdinClientRequest | Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
|
@@ -10,13 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const util_1 = require("../util");
|
|
13
|
-
const
|
|
13
|
+
const subscription_1 = require("../util/subscription");
|
|
14
14
|
const logger_1 = require("../util/logger");
|
|
15
15
|
function handle() {
|
|
16
16
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
17
17
|
const organizationId = (req.query || {})['organization_id'] || (req.body || {})['organization_id'];
|
|
18
18
|
(0, logger_1.log)(`Received subscription paid request for organization ${organizationId}`);
|
|
19
|
-
(0,
|
|
19
|
+
(0, subscription_1.clearCache)(organizationId);
|
|
20
20
|
res.status(204).end();
|
|
21
21
|
}));
|
|
22
22
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="qs" />
|
|
2
2
|
import { Request, Response } from 'express';
|
|
3
|
-
import { Config } from '../
|
|
4
|
-
export default function handle(config: Config): (req: import("../
|
|
3
|
+
import { Config } from '../types';
|
|
4
|
+
export default function handle(config: Config): (req: import("../types").CrowdinClientRequest | Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
|
package/out/modules/uninstall.js
CHANGED
|
@@ -13,7 +13,7 @@ const storage_1 = require("../storage");
|
|
|
13
13
|
const util_1 = require("../util");
|
|
14
14
|
const connection_1 = require("../util/connection");
|
|
15
15
|
const logger_1 = require("../util/logger");
|
|
16
|
-
const webhooks_1 = require("
|
|
16
|
+
const webhooks_1 = require("./integration/util/webhooks");
|
|
17
17
|
function handle(config) {
|
|
18
18
|
return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
19
19
|
const event = req.body;
|
|
@@ -40,7 +40,11 @@ function handle(config) {
|
|
|
40
40
|
}
|
|
41
41
|
if (projectIntegration) {
|
|
42
42
|
if (projectIntegration.webhooks) {
|
|
43
|
-
yield (0, webhooks_1.unregisterAllCrowdinWebhooks)(
|
|
43
|
+
yield (0, webhooks_1.unregisterAllCrowdinWebhooks)({
|
|
44
|
+
config,
|
|
45
|
+
integration: projectIntegration,
|
|
46
|
+
crowdinId: organization,
|
|
47
|
+
});
|
|
44
48
|
}
|
|
45
49
|
(0, logger_1.log)(`Deleting all integration credentials for ${organization} organization`);
|
|
46
50
|
yield (0, storage_1.getStorage)().deleteAllIntegrationCredentials(organization);
|
package/out/storage/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks, Provider } from '../modules/integration/types';
|
|
2
|
-
import { Config, CrowdinCredentials,
|
|
3
|
-
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../
|
|
2
|
+
import { Config, CrowdinCredentials, UnauthorizedConfig } from '../types';
|
|
3
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../modules/integration/util/types';
|
|
4
|
+
import { UserErrors } from './types';
|
|
4
5
|
export interface Storage {
|
|
5
6
|
migrate(): Promise<void>;
|
|
6
7
|
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
package/out/storage/mysql.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Storage } from '.';
|
|
2
|
-
import { CrowdinCredentials
|
|
3
|
-
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../
|
|
2
|
+
import { CrowdinCredentials } from '../types';
|
|
3
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../modules/integration/util/types';
|
|
4
4
|
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
|
|
5
|
+
import { UserErrors } from './types';
|
|
5
6
|
export interface MySQLStorageConfig {
|
|
6
7
|
uri?: string;
|
|
7
8
|
host?: string;
|
package/out/storage/mysql.js
CHANGED
|
@@ -14,7 +14,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MySQLStorage = void 0;
|
|
16
16
|
const uuid_1 = require("uuid");
|
|
17
|
-
const
|
|
17
|
+
const types_1 = require("../modules/integration/util/types");
|
|
18
18
|
const util_1 = require("../util");
|
|
19
19
|
class MySQLStorage {
|
|
20
20
|
constructor(config) {
|
|
@@ -156,7 +156,7 @@ class MySQLStorage {
|
|
|
156
156
|
payload text,
|
|
157
157
|
title text,
|
|
158
158
|
progress int 0,
|
|
159
|
-
status varchar(255) '${
|
|
159
|
+
status varchar(255) '${types_1.JobStatus.CREATED}',
|
|
160
160
|
payload text,
|
|
161
161
|
info text,
|
|
162
162
|
data text,
|
|
@@ -518,7 +518,7 @@ class MySQLStorage {
|
|
|
518
518
|
if (status) {
|
|
519
519
|
updateFields.push('status = ?');
|
|
520
520
|
updateParams.push(status);
|
|
521
|
-
if (!updateFields.includes('finished_at = ?') && [
|
|
521
|
+
if (!updateFields.includes('finished_at = ?') && [types_1.JobStatus.FAILED, types_1.JobStatus.CANCELED].includes(status)) {
|
|
522
522
|
updateFields.push('finished_at = ?');
|
|
523
523
|
updateParams.push(Date.now().toString());
|
|
524
524
|
}
|
package/out/storage/postgre.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Client } from 'pg';
|
|
2
2
|
import { Storage } from '.';
|
|
3
|
-
import { CrowdinCredentials
|
|
4
|
-
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../models/job';
|
|
3
|
+
import { CrowdinCredentials } from '../types';
|
|
5
4
|
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
|
|
5
|
+
import { CreateJobParams, GetActiveJobsParams, GetJobParams, Job, UpdateJobParams } from '../modules/integration/util/types';
|
|
6
|
+
import { UserErrors } from './types';
|
|
6
7
|
export interface PostgreStorageConfig {
|
|
7
8
|
host?: string;
|
|
8
9
|
connectionString?: string;
|