@crowdin/app-project-module 0.107.0 → 1.0.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/get-integration-files.js +16 -4
- package/out/app-test/integration/types.d.ts +1 -1
- package/out/app-test/integration/update-crowdin.js +2 -2
- package/out/app-test/integration/update-integration.js +2 -2
- package/out/index.d.ts +2 -1
- package/out/index.js +73 -30
- package/out/middlewares/auto-credentials-masker.d.ts +4 -0
- package/out/middlewares/auto-credentials-masker.js +45 -0
- package/out/middlewares/crowdin-client.d.ts +1 -1
- package/out/middlewares/integration-credentials.d.ts +2 -2
- package/out/middlewares/integration-credentials.js +7 -4
- package/out/middlewares/render-ui-module.d.ts +3 -3
- package/out/middlewares/render-ui-module.js +10 -13
- package/out/middlewares/ui-module.d.ts +1 -1
- package/out/middlewares/ui-module.js +11 -1
- package/out/modules/about.d.ts +2 -1
- package/out/modules/about.js +10 -3
- package/out/modules/ai-prompt-provider/handlers/compile.d.ts +1 -1
- package/out/modules/ai-prompt-provider/handlers/compile.js +7 -1
- package/out/modules/ai-prompt-provider/index.js +2 -2
- package/out/modules/ai-prompt-provider/types.d.ts +7 -1
- package/out/modules/ai-provider/handlers/chat-completions.d.ts +1 -1
- package/out/modules/ai-provider/handlers/chat-completions.js +1 -1
- package/out/modules/ai-provider/handlers/get-model-list.d.ts +1 -1
- package/out/modules/ai-provider/index.js +2 -2
- package/out/modules/ai-provider/types.d.ts +4 -4
- package/out/modules/ai-request-processors/handler.d.ts +1 -1
- package/out/modules/ai-request-processors/handler.js +12 -2
- package/out/modules/ai-request-processors/types.d.ts +12 -2
- package/out/modules/ai-tools/handlers/tool-calls.d.ts +1 -1
- package/out/modules/ai-tools/handlers/tool-calls.js +1 -1
- package/out/modules/ai-tools/index.js +1 -1
- package/out/modules/ai-tools/types.d.ts +1 -1
- package/out/modules/api/api.js +58 -7
- package/out/modules/api/base.d.ts +1 -0
- package/out/modules/api/base.js +1 -0
- package/out/modules/api/components.d.ts +251 -27
- package/out/modules/api/components.js +251 -27
- package/out/modules/auth-guard/handlers/verify.d.ts +1 -1
- package/out/modules/auth-guard/index.js +1 -1
- package/out/modules/automation-action/handlers/execute.d.ts +1 -1
- package/out/modules/automation-action/handlers/execute.js +1 -1
- package/out/modules/automation-action/handlers/input-schema.d.ts +1 -1
- package/out/modules/automation-action/handlers/output-schema.d.ts +1 -1
- package/out/modules/automation-action/handlers/validate-settings.d.ts +1 -1
- package/out/modules/automation-action/handlers/validate-settings.js +1 -1
- package/out/modules/automation-action/index.js +1 -1
- package/out/modules/automation-action/types.d.ts +4 -4
- package/out/modules/automation-action/util/index.js +2 -5
- package/out/modules/context-menu/index.js +2 -2
- package/out/modules/custom-mt/handlers/translate.d.ts +1 -1
- package/out/modules/custom-mt/handlers/translate.js +25 -9
- package/out/modules/custom-mt/index.js +3 -3
- package/out/modules/custom-mt/types.d.ts +10 -2
- 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.js +4 -4
- package/out/modules/editor-right-panel/index.js +1 -1
- package/out/modules/external-qa-check/handlers/validate.d.ts +1 -1
- package/out/modules/external-qa-check/index.js +2 -2
- package/out/modules/file-processing/handlers/custom-file-format.d.ts +7 -2
- package/out/modules/file-processing/handlers/custom-file-format.js +62 -22
- package/out/modules/file-processing/handlers/file-download.d.ts +1 -1
- package/out/modules/file-processing/handlers/file-download.js +5 -0
- package/out/modules/file-processing/handlers/pre-post-process.d.ts +1 -1
- package/out/modules/file-processing/handlers/pre-post-process.js +41 -15
- package/out/modules/file-processing/handlers/translations-alignment.d.ts +1 -1
- package/out/modules/file-processing/handlers/translations-alignment.js +10 -4
- package/out/modules/file-processing/index.js +12 -2
- package/out/modules/file-processing/types.d.ts +36 -5
- package/out/modules/file-processing/util/defaults.js +50 -6
- package/out/modules/file-processing/util/files.js +2 -1
- 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 +1 -1
- package/out/modules/integration/handlers/crowdin-file-progress.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-file-progress.js +5 -1
- package/out/modules/integration/handlers/crowdin-files-target-languages.d.ts +5 -0
- package/out/modules/integration/handlers/crowdin-files-target-languages.js +103 -0
- package/out/modules/integration/handlers/crowdin-files.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-files.js +7 -1
- package/out/modules/integration/handlers/crowdin-project.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-update.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-update.js +59 -18
- package/out/modules/integration/handlers/crowdin-webhook.d.ts +1 -1
- package/out/modules/integration/handlers/crowdin-webhook.js +15 -8
- package/out/modules/integration/handlers/integration-data.d.ts +1 -1
- package/out/modules/integration/handlers/integration-data.js +13 -6
- package/out/modules/integration/handlers/integration-login.d.ts +1 -1
- package/out/modules/integration/handlers/integration-logout.d.ts +1 -1
- package/out/modules/integration/handlers/integration-logout.js +8 -3
- package/out/modules/integration/handlers/integration-update.d.ts +1 -1
- package/out/modules/integration/handlers/integration-update.js +44 -6
- package/out/modules/integration/handlers/integration-webhook.d.ts +1 -1
- package/out/modules/integration/handlers/invite-users.d.ts +1 -1
- package/out/modules/integration/handlers/job-cancel.d.ts +1 -1
- package/out/modules/integration/handlers/job-info-deprecated.d.ts +1 -1
- package/out/modules/integration/handlers/job-info-deprecated.js +3 -2
- package/out/modules/integration/handlers/job-info.d.ts +1 -1
- package/out/modules/integration/handlers/job-list.d.ts +1 -1
- package/out/modules/integration/handlers/main.d.ts +1 -1
- package/out/modules/integration/handlers/main.js +32 -2
- package/out/modules/integration/handlers/oauth-login.d.ts +1 -1
- package/out/modules/integration/handlers/oauth-login.js +28 -6
- package/out/modules/integration/handlers/oauth-polling.d.ts +1 -1
- package/out/modules/integration/handlers/oauth-url.d.ts +1 -1
- package/out/modules/integration/handlers/settings-save.d.ts +1 -1
- package/out/modules/integration/handlers/settings-save.js +9 -9
- package/out/modules/integration/handlers/settings.d.ts +1 -1
- package/out/modules/integration/handlers/sync-settings-save.d.ts +1 -1
- package/out/modules/integration/handlers/sync-settings-save.js +5 -9
- 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/handlers/users.d.ts +1 -1
- package/out/modules/integration/index.js +19 -33
- package/out/modules/integration/types.d.ts +133 -29
- package/out/modules/integration/types.js +1 -0
- package/out/modules/integration/util/cron.d.ts +2 -2
- package/out/modules/integration/util/cron.js +40 -24
- package/out/modules/integration/util/defaults.d.ts +4 -0
- package/out/modules/integration/util/defaults.js +175 -15
- package/out/modules/integration/util/files.d.ts +2 -1
- package/out/modules/integration/util/files.js +19 -8
- package/out/modules/integration/util/job.js +4 -3
- package/out/modules/integration/util/snapshot.js +19 -3
- package/out/modules/integration/util/types.d.ts +1 -0
- package/out/modules/integration/util/types.js +1 -0
- package/out/modules/integration/util/webhooks.d.ts +8 -8
- package/out/modules/integration/util/webhooks.js +34 -17
- package/out/modules/manifest.js +12 -12
- package/out/modules/modal/index.js +2 -2
- package/out/modules/organization-menu/index.js +5 -4
- package/out/modules/organization-settings-menu/index.js +5 -4
- package/out/modules/profile-resources-menu/index.js +5 -4
- package/out/modules/profile-settings-menu/index.js +5 -4
- package/out/modules/project-menu/index.js +1 -1
- package/out/modules/project-menu-crowdsource/index.js +1 -1
- package/out/modules/project-reports/index.js +3 -2
- package/out/modules/project-tools/index.js +3 -2
- package/out/modules/status.d.ts +1 -1
- package/out/modules/status.js +12 -3
- package/out/modules/subscription-paid.d.ts +1 -1
- package/out/modules/uninstall.d.ts +1 -1
- package/out/modules/uninstall.js +1 -1
- package/out/modules/webhooks/handlers/webhook-handler.d.ts +2 -2
- package/out/modules/webhooks/handlers/webhook-handler.js +33 -22
- package/out/modules/webhooks/types.d.ts +7 -0
- package/out/modules/workflow-step-type/handlers/delete-step.d.ts +1 -1
- package/out/modules/workflow-step-type/handlers/step-settings-save.d.ts +1 -1
- package/out/modules/workflow-step-type/index.js +2 -2
- package/out/modules/workflow-step-type/types.d.ts +1 -1
- package/out/modules/workflow-step-type/util/index.js +3 -6
- package/out/static/js/dependent.js +16 -7
- package/out/static/ui/error.bundle.js +474 -0
- package/out/static/ui/error.bundle.js.map +1 -0
- package/out/static/ui/install.bundle.js +459 -0
- package/out/static/ui/install.bundle.js.map +1 -0
- package/out/static/ui/login.bundle.js +630 -0
- package/out/static/ui/login.bundle.js.map +1 -0
- package/out/static/ui/main.bundle.js +2109 -0
- package/out/static/ui/main.bundle.js.map +1 -0
- package/out/static/ui/oauth.bundle.js +467 -0
- package/out/static/ui/oauth.bundle.js.map +1 -0
- package/out/storage/d1.d.ts +107 -0
- package/out/storage/d1.js +831 -0
- package/out/storage/index.js +8 -1
- package/out/storage/mysql.js +22 -19
- package/out/storage/postgre.d.ts +0 -1
- package/out/storage/postgre.js +20 -30
- package/out/storage/sqlite.d.ts +2 -5
- package/out/storage/sqlite.js +29 -69
- package/out/types.d.ts +80 -18
- package/out/util/connection.js +16 -5
- package/out/util/credentials-masker.d.ts +3 -3
- package/out/util/credentials-masker.js +14 -20
- package/out/util/cron.d.ts +29 -0
- package/out/util/cron.js +87 -0
- package/out/util/index.d.ts +14 -1
- package/out/util/index.js +121 -10
- package/out/util/jsx-renderer.d.ts +14 -0
- package/out/util/jsx-renderer.js +35 -0
- package/out/util/logger.d.ts +1 -0
- package/out/util/logger.js +2 -2
- package/out/util/static-files.d.ts +19 -0
- package/out/util/static-files.js +87 -0
- package/out/util/subscription.js +1 -1
- package/out/views/AboutPage.d.ts +10 -0
- package/out/views/AboutPage.js +76 -0
- package/out/views/FormPage.d.ts +14 -0
- package/out/views/FormPage.js +28 -0
- package/out/views/SubscriptionPage.d.ts +7 -0
- package/out/views/SubscriptionPage.js +26 -0
- package/out/views/index.d.ts +8 -0
- package/out/views/index.js +15 -0
- package/out/views/layout/Head.d.ts +9 -0
- package/out/views/layout/Head.js +54 -0
- package/package.json +43 -41
- package/out/util/handlebars.d.ts +0 -1
- package/out/util/handlebars.js +0 -46
- package/out/views/about.handlebars +0 -102
- package/out/views/error.handlebars +0 -54
- package/out/views/form.handlebars +0 -31
- package/out/views/install.handlebars +0 -16
- package/out/views/login.handlebars +0 -332
- package/out/views/main.handlebars +0 -2042
- package/out/views/oauth.handlebars +0 -11
- package/out/views/partials/head.handlebars +0 -53
- package/out/views/subscription.handlebars +0 -26
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.groupFieldsByCategory = exports.getOAuthLoginFormId = exports.getOAuthPollingId = exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
|
|
35
|
+
exports.buildMenuItems = exports.groupFieldsByCategory = exports.getOAuthLoginFormId = exports.getOAuthPollingId = exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
|
|
36
36
|
const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
|
|
37
37
|
const types_1 = require("../types");
|
|
38
38
|
function getRootFolder(config, integration, client, projectId) {
|
|
@@ -60,7 +60,7 @@ exports.getOauthRoute = getOauthRoute;
|
|
|
60
60
|
function applyIntegrationModuleDefaults(config, integration) {
|
|
61
61
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
62
62
|
if (!integration.getCrowdinFiles) {
|
|
63
|
-
integration.getCrowdinFiles = (projectId, client, rootFolder,
|
|
63
|
+
integration.getCrowdinFiles = ({ projectId, client, rootFolder, mode }) => __awaiter(this, void 0, void 0, function* () {
|
|
64
64
|
let options = {};
|
|
65
65
|
if (rootFolder) {
|
|
66
66
|
options = {
|
|
@@ -133,11 +133,24 @@ function applyIntegrationModuleDefaults(config, integration) {
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
if (!integration.getFileProgress) {
|
|
136
|
-
integration.getFileProgress = (projectId, client, fileId) => __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
integration.getFileProgress = ({ projectId, client, fileId }) => __awaiter(this, void 0, void 0, function* () {
|
|
137
137
|
const progress = yield client.translationStatusApi.withFetchAll().getFileProgress(projectId, fileId);
|
|
138
138
|
return { [fileId]: progress.data.map((e) => e.data) };
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
|
+
if (!integration.updateFilesTargetLanguages) {
|
|
142
|
+
integration.updateFilesTargetLanguages = ({ projectId, client, fileIds, excludedTargetLanguages }) => __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
for (const fileId of fileIds) {
|
|
144
|
+
yield client.sourceFilesApi.editFile(projectId, fileId, [
|
|
145
|
+
{
|
|
146
|
+
op: 'replace',
|
|
147
|
+
path: '/excludedTargetLanguages',
|
|
148
|
+
value: excludedTargetLanguages,
|
|
149
|
+
},
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
141
154
|
if (!integration.oauthLogin && !integration.loginForm) {
|
|
142
155
|
integration.loginForm = {
|
|
143
156
|
fields: [
|
|
@@ -154,24 +167,65 @@ function applyIntegrationModuleDefaults(config, integration) {
|
|
|
154
167
|
integration.filterByPathIntegrationFiles = true;
|
|
155
168
|
}
|
|
156
169
|
const getUserSettings = integration.getConfiguration;
|
|
157
|
-
integration.getConfiguration = (projectId, crowdinClient,
|
|
170
|
+
integration.getConfiguration = ({ projectId, client: crowdinClient, credentials, settings, clientId, }) => __awaiter(this, void 0, void 0, function* () {
|
|
158
171
|
var _p, _q, _r;
|
|
159
172
|
let fields = [];
|
|
160
173
|
const project = (yield crowdinClient.projectsGroupsApi.getProject(projectId));
|
|
161
174
|
if (getUserSettings) {
|
|
162
|
-
fields = yield getUserSettings(
|
|
175
|
+
fields = yield getUserSettings({
|
|
176
|
+
projectId,
|
|
177
|
+
client: crowdinClient,
|
|
178
|
+
credentials,
|
|
179
|
+
settings,
|
|
180
|
+
clientId,
|
|
181
|
+
});
|
|
163
182
|
}
|
|
164
183
|
const defaultSettings = [];
|
|
165
184
|
if (project.data.inContext) {
|
|
166
185
|
defaultSettings.push({
|
|
167
186
|
key: 'inContext',
|
|
168
|
-
label: '
|
|
187
|
+
label: 'Sync In-Context Pseudo Language',
|
|
169
188
|
type: 'checkbox',
|
|
170
189
|
defaultValue: 'false',
|
|
171
|
-
category: types_1.DefaultCategory.
|
|
190
|
+
category: types_1.DefaultCategory.ADVANCED,
|
|
191
|
+
position: 3,
|
|
192
|
+
helpTextHtml: `
|
|
193
|
+
<p><strong>What is In-Context?</strong></p>
|
|
194
|
+
<p>Crowdin In-Context allows translators to see and edit translations directly on your live website or application.</p>
|
|
195
|
+
|
|
196
|
+
<p><strong>Enable this setting if:</strong></p>
|
|
197
|
+
<ul style="margin: 8px 0; padding-left: 20px;">
|
|
198
|
+
<li>You have integrated the Crowdin In-Context script in your website/app</li>
|
|
199
|
+
<li>You want to sync the pseudo-language for in-context translation testing</li>
|
|
200
|
+
</ul>
|
|
201
|
+
|
|
202
|
+
<p style="margin-top: 8px;">
|
|
203
|
+
<a href="https://support.crowdin.com/in-context-localization/" target="_blank" rel="noopener noreferrer">
|
|
204
|
+
Learn more about In-Context →
|
|
205
|
+
</a>
|
|
206
|
+
</p>
|
|
207
|
+
`,
|
|
172
208
|
});
|
|
173
209
|
}
|
|
174
210
|
if (integration.withCronSync || integration.webhooks) {
|
|
211
|
+
defaultSettings.push({
|
|
212
|
+
key: 'auto-sync-info',
|
|
213
|
+
type: 'notice',
|
|
214
|
+
label: 'How Auto Sync works',
|
|
215
|
+
helpTextHtml: `
|
|
216
|
+
<p><strong>Auto Sync is disabled by default.</strong> Here's how to enable it:</p>
|
|
217
|
+
<ol style="margin: 8px 0 0 0; padding-left: 20px;">
|
|
218
|
+
<li><strong>Choose a schedule</strong> below (how often to sync)</li>
|
|
219
|
+
<li><strong>Select files:</strong> In the file browser, right-click on files or folders</li>
|
|
220
|
+
<li>Click <strong>"Enable Auto Sync"</strong> from the context menu</li>
|
|
221
|
+
</ol>
|
|
222
|
+
<p style="margin: 8px 0 0 0;">
|
|
223
|
+
💡 Only files/folders with Auto Sync enabled will be synchronized automatically.
|
|
224
|
+
</p>
|
|
225
|
+
`,
|
|
226
|
+
category: types_1.DefaultCategory.SYNC,
|
|
227
|
+
position: -1,
|
|
228
|
+
});
|
|
175
229
|
const userSchedule = fields.find((field) => 'key' in field && field.key === 'schedule');
|
|
176
230
|
if (userSchedule) {
|
|
177
231
|
userSchedule.position = (_p = userSchedule.position) !== null && _p !== void 0 ? _p : 0;
|
|
@@ -286,16 +340,46 @@ function applyIntegrationModuleDefaults(config, integration) {
|
|
|
286
340
|
if (integration.filterByPathIntegrationFiles) {
|
|
287
341
|
defaultSettings.push({
|
|
288
342
|
label: 'File Filters',
|
|
343
|
+
category: types_1.DefaultCategory.ADVANCED,
|
|
344
|
+
position: 0,
|
|
289
345
|
}, {
|
|
290
346
|
key: 'includeByFilePath',
|
|
291
|
-
label: '
|
|
347
|
+
label: 'Show only files matching pattern',
|
|
292
348
|
type: 'textarea',
|
|
293
|
-
|
|
349
|
+
helpTextHtml: `
|
|
350
|
+
<p>Enter file path patterns to include for synchronization. Use wildcard selectors:</p>
|
|
351
|
+
<ul style="margin: 8px 0; padding-left: 20px;">
|
|
352
|
+
<li><code>*</code> - matches any characters except /</li>
|
|
353
|
+
<li><code>**</code> - matches any characters including /</li>
|
|
354
|
+
</ul>
|
|
355
|
+
<p><strong>Examples:</strong></p>
|
|
356
|
+
<ul style="margin: 8px 0; padding-left: 20px;">
|
|
357
|
+
<li><code>/pages/**</code> - all files in pages folder</li>
|
|
358
|
+
<li><code>/**/*.json</code> - all JSON files</li>
|
|
359
|
+
<li><code>/content/**/*.md</code> - all Markdown files in content</li>
|
|
360
|
+
</ul>
|
|
361
|
+
`,
|
|
362
|
+
category: types_1.DefaultCategory.ADVANCED,
|
|
363
|
+
position: 1,
|
|
294
364
|
}, {
|
|
295
365
|
key: 'excludeByFilePath',
|
|
296
|
-
label: '
|
|
366
|
+
label: 'Hide files matching pattern',
|
|
297
367
|
type: 'textarea',
|
|
298
|
-
|
|
368
|
+
helpTextHtml: `
|
|
369
|
+
<p>Enter path patterns for files or folders to exclude. Use wildcard selectors:</p>
|
|
370
|
+
<ul style="margin: 8px 0; padding-left: 20px;">
|
|
371
|
+
<li><code>*</code> - matches any characters except /</li>
|
|
372
|
+
<li><code>**</code> - matches any characters including /</li>
|
|
373
|
+
</ul>
|
|
374
|
+
<p><strong>Examples:</strong></p>
|
|
375
|
+
<ul style="margin: 8px 0; padding-left: 20px;">
|
|
376
|
+
<li><code>/drafts/**</code> - ignore drafts folder</li>
|
|
377
|
+
<li><code>/**/.git/**</code> - ignore all .git folders</li>
|
|
378
|
+
<li><code>/**/test/**</code> - ignore all test folders</li>
|
|
379
|
+
</ul>
|
|
380
|
+
`,
|
|
381
|
+
category: types_1.DefaultCategory.ADVANCED,
|
|
382
|
+
position: 2,
|
|
299
383
|
});
|
|
300
384
|
}
|
|
301
385
|
if (integration.skipIntegrationNodes && integration.skipIntegrationNodesToggle) {
|
|
@@ -311,8 +395,8 @@ function applyIntegrationModuleDefaults(config, integration) {
|
|
|
311
395
|
return [...defaultSettings, ...fields];
|
|
312
396
|
});
|
|
313
397
|
if (!integration.checkConnection) {
|
|
314
|
-
integration.checkConnection = (
|
|
315
|
-
yield integration.getIntegrationFiles(
|
|
398
|
+
integration.checkConnection = (credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
yield integration.getIntegrationFiles({ credentials });
|
|
316
400
|
});
|
|
317
401
|
}
|
|
318
402
|
if (integration.webhooks && !((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.urlParam)) {
|
|
@@ -388,7 +472,10 @@ function constructOauthUrl({ config, integration, clientId, loginForm, }) {
|
|
|
388
472
|
if (!loginForm) {
|
|
389
473
|
return;
|
|
390
474
|
}
|
|
391
|
-
let url = oauth.getAuthorizationUrl(
|
|
475
|
+
let url = oauth.getAuthorizationUrl({
|
|
476
|
+
redirectUrl: `${config.baseUrl}${getOauthRoute(integration)}`,
|
|
477
|
+
loginForm,
|
|
478
|
+
});
|
|
392
479
|
url += `&${((_a = oauth.fieldsMapping) === null || _a === void 0 ? void 0 : _a.state) || 'state'}=${Buffer.from(clientId).toString('base64')}`;
|
|
393
480
|
return url;
|
|
394
481
|
}
|
|
@@ -443,9 +530,82 @@ function groupFieldsByCategory(fields) {
|
|
|
443
530
|
return (a.position || 0) - (b.position || 0);
|
|
444
531
|
});
|
|
445
532
|
});
|
|
446
|
-
|
|
533
|
+
// Define category order: General Settings → Sync settings → Advanced
|
|
534
|
+
const categoryOrder = {
|
|
535
|
+
[types_1.DefaultCategory.GENERAL]: 1,
|
|
536
|
+
[types_1.DefaultCategory.SYNC]: 2,
|
|
537
|
+
[types_1.DefaultCategory.ADVANCED]: 3,
|
|
538
|
+
};
|
|
539
|
+
return Object.entries(groupedFields)
|
|
540
|
+
.sort(([categoryA], [categoryB]) => {
|
|
541
|
+
const orderA = categoryOrder[categoryA] || 999;
|
|
542
|
+
const orderB = categoryOrder[categoryB] || 999;
|
|
543
|
+
return orderA - orderB;
|
|
544
|
+
})
|
|
545
|
+
.map(([category, fields]) => ({
|
|
447
546
|
name: category,
|
|
448
547
|
fields,
|
|
449
548
|
}));
|
|
450
549
|
}
|
|
451
550
|
exports.groupFieldsByCategory = groupFieldsByCategory;
|
|
551
|
+
function buildMenuItems(integration, appName) {
|
|
552
|
+
const integrationMenuItems = [];
|
|
553
|
+
if (integration.matchCrowdinFilesToIntegrationFiles) {
|
|
554
|
+
integrationMenuItems.push({
|
|
555
|
+
label: `Translations: Sync to ${appName}`,
|
|
556
|
+
title: `Sync translations to ${appName}`,
|
|
557
|
+
action: 'syncTranslationsToIntegration',
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
if (integration.uploadTranslations) {
|
|
561
|
+
integrationMenuItems.push({
|
|
562
|
+
label: 'Translations: Sync to Crowdin',
|
|
563
|
+
title: 'Sync translations to Crowdin',
|
|
564
|
+
action: 'uploadTranslations',
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
if (integration.forcePushSources) {
|
|
568
|
+
integrationMenuItems.push({
|
|
569
|
+
label: 'Source Files: Sync to Crowdin (Forced)',
|
|
570
|
+
title: 'Force sync files to Crowdin',
|
|
571
|
+
action: 'forcePushSources',
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
if (integration.excludedTargetLanguages) {
|
|
575
|
+
integrationMenuItems.push({
|
|
576
|
+
label: 'Change Files Target Languages',
|
|
577
|
+
title: 'Upload file for translation into selected languages',
|
|
578
|
+
action: 'excludedTargetLanguages',
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
const crowdinMenuItems = [];
|
|
582
|
+
if (integration.matchCrowdinFilesToIntegrationFiles) {
|
|
583
|
+
crowdinMenuItems.push({
|
|
584
|
+
label: 'Source Files: Sync to Crowdin',
|
|
585
|
+
action: 'syncSourcesToCrowdin',
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
if (integration.matchCrowdinFilesToIntegrationFiles) {
|
|
589
|
+
crowdinMenuItems.push({
|
|
590
|
+
label: 'Translations: Sync to Crowdin',
|
|
591
|
+
action: 'syncTranslationsToCrowdin',
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
if (integration.excludedTargetLanguages) {
|
|
595
|
+
crowdinMenuItems.push({
|
|
596
|
+
label: 'Change Files Target Languages',
|
|
597
|
+
action: 'excludedTargetLanguages',
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
if (integration.forcePushTranslations) {
|
|
601
|
+
crowdinMenuItems.push({
|
|
602
|
+
label: `Translations: Sync to ${appName} (Forced)`,
|
|
603
|
+
action: 'forcePushTranslations',
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
return {
|
|
607
|
+
integrationButtonMenuItems: integrationMenuItems.length > 0 ? JSON.stringify(integrationMenuItems) : null,
|
|
608
|
+
crowdinButtonMenuItems: crowdinMenuItems.length > 0 ? JSON.stringify(crowdinMenuItems) : null,
|
|
609
|
+
};
|
|
610
|
+
}
|
|
611
|
+
exports.buildMenuItems = buildMenuItems;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtendedResult, IntegrationFile, IntegrationLogic, IntegrationRequest, SkipIntegrationNodes, TreeItem, UpdateIntegrationRequest, Provider } from '../types';
|
|
1
|
+
import { ExtendedResult, IntegrationFile, IntegrationLogic, IntegrationRequest, MatchingResult, SkipIntegrationNodes, TreeItem, UpdateIntegrationRequest, Provider } from '../types';
|
|
2
2
|
import { JobClient } from './types';
|
|
3
3
|
import Crowdin from '@crowdin/crowdin-api-client';
|
|
4
4
|
import { SourceFilesModel } from '@crowdin/crowdin-api-client';
|
|
@@ -7,6 +7,7 @@ export declare function expandFilesTree(nodes: IntegrationFile[], req: Integrati
|
|
|
7
7
|
export declare function attachFileStatus(files: any[], clientId: string, crowdinId: string, integration: IntegrationLogic): Promise<any[]>;
|
|
8
8
|
export declare function expandFilesTreeWithPagination(nodes: IntegrationFile[], req: IntegrationRequest, integration: IntegrationLogic, job?: JobClient): Promise<IntegrationFile[]>;
|
|
9
9
|
export declare function isExtendedResultType<T>(data?: T | ExtendedResult<T>): data is ExtendedResult<T>;
|
|
10
|
+
export declare function isMatchingResultType<T>(data?: T | MatchingResult<T> | null): data is MatchingResult<T>;
|
|
10
11
|
export declare function markUnsyncedFiles({ integrationId, crowdinId, client, files, }: {
|
|
11
12
|
integrationId: string;
|
|
12
13
|
crowdinId: string;
|
|
@@ -8,17 +8,13 @@ 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.filterSyncedData = exports.updateSyncedData = exports.filterFilesByPath = exports.filterFilesByPatterns = exports.getParentFiles = exports.getParentPaths = exports.buildPath = exports.prepareSyncFiles = exports.uniqueFileLanguages = exports.filterLanguages = exports.getExcludedTargetLanguages = exports.markUnsyncedFiles = exports.isExtendedResultType = exports.expandFilesTreeWithPagination = exports.attachFileStatus = exports.expandFilesTree = exports.skipFilesByRegex = void 0;
|
|
12
|
+
exports.filterSyncedData = exports.updateSyncedData = exports.filterFilesByPath = exports.filterFilesByPatterns = exports.getParentFiles = exports.getParentPaths = exports.buildPath = exports.prepareSyncFiles = exports.uniqueFileLanguages = exports.filterLanguages = exports.getExcludedTargetLanguages = exports.markUnsyncedFiles = exports.isMatchingResultType = exports.isExtendedResultType = exports.expandFilesTreeWithPagination = exports.attachFileStatus = exports.expandFilesTree = exports.skipFilesByRegex = void 0;
|
|
16
13
|
const types_1 = require("../types");
|
|
17
14
|
const types_2 = require("./types");
|
|
18
15
|
const storage_1 = require("../../../storage");
|
|
19
16
|
const util_1 = require("../../../util");
|
|
20
17
|
const minimatch_1 = require("minimatch");
|
|
21
|
-
const lodash_uniqby_1 = __importDefault(require("lodash.uniqby"));
|
|
22
18
|
function skipFilesByRegex(files, skipIntegrationNodes) {
|
|
23
19
|
if (!Array.isArray(files)) {
|
|
24
20
|
return [];
|
|
@@ -48,7 +44,11 @@ function expandFilesTree(nodes, req, integration, job) {
|
|
|
48
44
|
for (const { id } of folders) {
|
|
49
45
|
let integrationData = [];
|
|
50
46
|
try {
|
|
51
|
-
integrationData = yield integration.getIntegrationFiles(
|
|
47
|
+
integrationData = yield integration.getIntegrationFiles({
|
|
48
|
+
credentials: req.integrationCredentials,
|
|
49
|
+
settings: req.integrationSettings,
|
|
50
|
+
parentId: id,
|
|
51
|
+
});
|
|
52
52
|
}
|
|
53
53
|
catch (e) {
|
|
54
54
|
if (job) {
|
|
@@ -154,7 +154,14 @@ function expandFilesTreeWithPagination(nodes, req, integration, job) {
|
|
|
154
154
|
info: `Loading files from ${folder.name} (page ${pageCount})`,
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
|
-
const result = yield integration.getIntegrationFiles(
|
|
157
|
+
const result = yield integration.getIntegrationFiles({
|
|
158
|
+
credentials: req.integrationCredentials,
|
|
159
|
+
settings: req.integrationSettings,
|
|
160
|
+
parentId: folder.id,
|
|
161
|
+
search: '',
|
|
162
|
+
page: 0,
|
|
163
|
+
paginationData,
|
|
164
|
+
});
|
|
158
165
|
let integrationTreeItems = [];
|
|
159
166
|
if (isExtendedResultType(result)) {
|
|
160
167
|
integrationTreeItems = result.data || [];
|
|
@@ -201,6 +208,10 @@ function isExtendedResultType(data) {
|
|
|
201
208
|
return !!dataTyped && !Array.isArray(dataTyped);
|
|
202
209
|
}
|
|
203
210
|
exports.isExtendedResultType = isExtendedResultType;
|
|
211
|
+
function isMatchingResultType(data) {
|
|
212
|
+
return data !== undefined && data !== null && typeof data === 'object' && 'data' in data && 'errors' in data;
|
|
213
|
+
}
|
|
214
|
+
exports.isMatchingResultType = isMatchingResultType;
|
|
204
215
|
function isFileLeaf(file) {
|
|
205
216
|
return file.nodeType === '1' || !!file.type;
|
|
206
217
|
}
|
|
@@ -358,7 +369,7 @@ function updateSyncedData(clientId, crowdinId, payload, provider = types_1.Provi
|
|
|
358
369
|
const filesWithTimestamp = (payload === null || payload === void 0 ? void 0 : payload.map((file) => (Object.assign(Object.assign({}, file), { syncedAt: currentTimestamp })))) || [];
|
|
359
370
|
if (existingSyncedData) {
|
|
360
371
|
const existingFiles = JSON.parse(existingSyncedData.files);
|
|
361
|
-
const mergedFiles = (0,
|
|
372
|
+
const mergedFiles = (0, util_1.uniqBy)([...filesWithTimestamp, ...existingFiles], 'id');
|
|
362
373
|
yield (0, storage_1.getStorage)().updateSyncedData(JSON.stringify(mergedFiles), clientId, crowdinId, provider);
|
|
363
374
|
}
|
|
364
375
|
else {
|
|
@@ -43,6 +43,7 @@ const cron_1 = require("./cron");
|
|
|
43
43
|
const blockingJobs = {
|
|
44
44
|
[types_1.JobType.UPDATE_TO_CROWDIN]: [types_1.JobType.UPDATE_TO_CROWDIN, types_1.JobType.UPDATE_TO_INTEGRATION],
|
|
45
45
|
[types_1.JobType.UPDATE_TO_INTEGRATION]: [types_1.JobType.UPDATE_TO_CROWDIN, types_1.JobType.UPDATE_TO_INTEGRATION],
|
|
46
|
+
[types_1.JobType.UPDATE_TARGET_LANGUAGES]: [types_1.JobType.UPDATE_TARGET_LANGUAGES],
|
|
46
47
|
[types_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE]: [types_1.JobType.CROWDIN_SYNC_SETTINGS_SAVE],
|
|
47
48
|
[types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE]: [types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE],
|
|
48
49
|
};
|
|
@@ -281,7 +282,7 @@ function reRunInProgressJobs(config) {
|
|
|
281
282
|
return;
|
|
282
283
|
}
|
|
283
284
|
const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, crowdinClient, projectId);
|
|
284
|
-
const
|
|
285
|
+
const credentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
285
286
|
const intConfig = (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config)
|
|
286
287
|
? JSON.parse(integrationConfig.config)
|
|
287
288
|
: { schedule: '0', condition: '0' };
|
|
@@ -298,9 +299,9 @@ function reRunInProgressJobs(config) {
|
|
|
298
299
|
client: crowdinClient,
|
|
299
300
|
integration,
|
|
300
301
|
context,
|
|
301
|
-
credentials
|
|
302
|
+
credentials,
|
|
302
303
|
rootFolder,
|
|
303
|
-
|
|
304
|
+
settings: intConfig,
|
|
304
305
|
reRunJobId: activeJob.id,
|
|
305
306
|
});
|
|
306
307
|
}
|
|
@@ -19,7 +19,12 @@ function getCrowdinSnapshot(config, integration, crowdinApiClient, projectId, in
|
|
|
19
19
|
let files = [];
|
|
20
20
|
if (integration.getCrowdinFiles) {
|
|
21
21
|
const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, crowdinApiClient, projectId);
|
|
22
|
-
files = yield integration.getCrowdinFiles(
|
|
22
|
+
files = yield integration.getCrowdinFiles({
|
|
23
|
+
projectId,
|
|
24
|
+
client: crowdinApiClient,
|
|
25
|
+
rootFolder,
|
|
26
|
+
settings: integrationSettings,
|
|
27
|
+
});
|
|
23
28
|
}
|
|
24
29
|
return files;
|
|
25
30
|
});
|
|
@@ -39,7 +44,13 @@ function getOneLevelFetchingFiles(integration, integrationCredentials, integrati
|
|
|
39
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
45
|
for (const file of parentFiles) {
|
|
41
46
|
if (!file.type) {
|
|
42
|
-
let childs = yield integration.getIntegrationFiles(
|
|
47
|
+
let childs = yield integration.getIntegrationFiles({
|
|
48
|
+
credentials: integrationCredentials,
|
|
49
|
+
settings: integrationSettings,
|
|
50
|
+
parentId: file.id,
|
|
51
|
+
search: '',
|
|
52
|
+
page: 0,
|
|
53
|
+
});
|
|
43
54
|
childs = getTreeItems(childs);
|
|
44
55
|
if (childs.length > 0) {
|
|
45
56
|
const childFiles = yield getOneLevelFetchingFiles(integration, integrationCredentials, integrationSettings, childs);
|
|
@@ -55,7 +66,12 @@ function getIntegrationSnapshot(integration, integrationCredentials, integration
|
|
|
55
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
67
|
let files = [];
|
|
57
68
|
let integrationData = [];
|
|
58
|
-
integrationData = yield integration.getIntegrationFiles(
|
|
69
|
+
integrationData = yield integration.getIntegrationFiles({
|
|
70
|
+
credentials: integrationCredentials,
|
|
71
|
+
settings: integrationSettings,
|
|
72
|
+
search: '',
|
|
73
|
+
page: 0,
|
|
74
|
+
});
|
|
59
75
|
files = getTreeItems(integrationData);
|
|
60
76
|
if (integration.integrationOneLevelFetching) {
|
|
61
77
|
files = yield getOneLevelFetchingFiles(integration, integrationCredentials, integrationSettings, files);
|
|
@@ -7,6 +7,7 @@ import { AppModuleError, AppUserModuleError } from '../../../util/logger';
|
|
|
7
7
|
export declare enum JobType {
|
|
8
8
|
UPDATE_TO_CROWDIN = "updateCrowdin",
|
|
9
9
|
UPDATE_TO_INTEGRATION = "updateIntegration",
|
|
10
|
+
UPDATE_TARGET_LANGUAGES = "updateTargetLanguages",
|
|
10
11
|
CROWDIN_SYNC_SETTINGS_SAVE = "crowdinSyncSettingsSave",
|
|
11
12
|
INTEGRATION_SYNC_SETTINGS_SAVE = "integrationSyncSettingsSave"
|
|
12
13
|
}
|
|
@@ -5,6 +5,7 @@ var JobType;
|
|
|
5
5
|
(function (JobType) {
|
|
6
6
|
JobType["UPDATE_TO_CROWDIN"] = "updateCrowdin";
|
|
7
7
|
JobType["UPDATE_TO_INTEGRATION"] = "updateIntegration";
|
|
8
|
+
JobType["UPDATE_TARGET_LANGUAGES"] = "updateTargetLanguages";
|
|
8
9
|
JobType["CROWDIN_SYNC_SETTINGS_SAVE"] = "crowdinSyncSettingsSave";
|
|
9
10
|
JobType["INTEGRATION_SYNC_SETTINGS_SAVE"] = "integrationSyncSettingsSave";
|
|
10
11
|
})(JobType = exports.JobType || (exports.JobType = {}));
|
|
@@ -2,21 +2,21 @@ import Crowdin from '@crowdin/crowdin-api-client';
|
|
|
2
2
|
import { AppSettings, IntegrationLogic, IntegrationSyncSettings, Provider, UpdateCrowdinWebhookPayloadsArgs } from '../types';
|
|
3
3
|
import { Config, CrowdinContextInfo } from '../../../types';
|
|
4
4
|
export declare const HookEvents: any;
|
|
5
|
-
export declare function registerWebhooks({ config,
|
|
5
|
+
export declare function registerWebhooks({ config, credentials, settings, client, crowdinContext, integration, }: {
|
|
6
6
|
config: Config;
|
|
7
7
|
integration: IntegrationLogic;
|
|
8
8
|
client: Crowdin;
|
|
9
9
|
crowdinContext: CrowdinContextInfo;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
credentials: any;
|
|
11
|
+
settings: AppSettings;
|
|
12
12
|
}): Promise<void>;
|
|
13
|
-
export declare function unregisterWebhooks({
|
|
13
|
+
export declare function unregisterWebhooks({ credentials, settings, client, config, crowdinContext, integration, }: {
|
|
14
14
|
config: Config;
|
|
15
15
|
integration: IntegrationLogic;
|
|
16
16
|
client: Crowdin;
|
|
17
17
|
crowdinContext: CrowdinContextInfo;
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
credentials: any;
|
|
19
|
+
settings: AppSettings;
|
|
20
20
|
}): Promise<void>;
|
|
21
21
|
export declare function unregisterAllCrowdinWebhooks({ config, crowdinId, integration, }: {
|
|
22
22
|
config: Config;
|
|
@@ -32,7 +32,7 @@ export declare function prepareWebhookData({ config, integration, provider, webh
|
|
|
32
32
|
projectId: number;
|
|
33
33
|
crowdinClient: null;
|
|
34
34
|
rootFolder: undefined;
|
|
35
|
-
|
|
35
|
+
settings: AppSettings;
|
|
36
36
|
syncSettings: null;
|
|
37
37
|
preparedIntegrationCredentials: null;
|
|
38
38
|
} | {
|
|
@@ -43,7 +43,7 @@ export declare function prepareWebhookData({ config, integration, provider, webh
|
|
|
43
43
|
};
|
|
44
44
|
preparedIntegrationCredentials: any;
|
|
45
45
|
rootFolder: import("@crowdin/crowdin-api-client").SourceFilesModel.Directory | undefined;
|
|
46
|
-
|
|
46
|
+
settings: AppSettings;
|
|
47
47
|
syncSettings: IntegrationSyncSettings | null;
|
|
48
48
|
}>;
|
|
49
49
|
export declare function updateCrowdinFromWebhookRequest(args: UpdateCrowdinWebhookPayloadsArgs): Promise<void>;
|
|
@@ -82,14 +82,14 @@ function makeCrowdinWebhookUrl({ config, crowdinContext, integration, }) {
|
|
|
82
82
|
const urlParam = encodedUrlParam({ config, integration, crowdinContext });
|
|
83
83
|
return (`${config.baseUrl}${((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.crowdinWebhookUrl) ? integration.webhooks.crowdinWebhookUrl : '/api/crowdin/webhook'}` + `?${urlParam}`);
|
|
84
84
|
}
|
|
85
|
-
function registerWebhooks({ config,
|
|
85
|
+
function registerWebhooks({ config, credentials, settings, client, crowdinContext, integration, }) {
|
|
86
86
|
var _a, _b;
|
|
87
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
const isWebhookSync = Number(
|
|
88
|
+
const isWebhookSync = Number(settings.schedule) !== types_1.SyncSchedule.DISABLED;
|
|
89
89
|
const projectId = crowdinContext.jwtPayload.context.project_id;
|
|
90
90
|
const urlParam = encodedUrlParam({ config, integration, crowdinContext });
|
|
91
91
|
if ((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.crowdinWebhooks) {
|
|
92
|
-
yield integration.webhooks.crowdinWebhooks(client, projectId, isWebhookSync,
|
|
92
|
+
yield integration.webhooks.crowdinWebhooks({ client, projectId, available: isWebhookSync, settings });
|
|
93
93
|
}
|
|
94
94
|
else {
|
|
95
95
|
const webhookName = `${config.name} application hook ${crowdinContext.jwtPayload.sub}`;
|
|
@@ -98,14 +98,14 @@ function registerWebhooks({ config, apiCredentials, appSettings, client, crowdin
|
|
|
98
98
|
integration,
|
|
99
99
|
crowdinContext,
|
|
100
100
|
});
|
|
101
|
-
const syncCondition = types_1.SyncCondition[Number(
|
|
101
|
+
const syncCondition = types_1.SyncCondition[Number(settings.condition)];
|
|
102
102
|
const events = [...HookConditionEvents[syncCondition]];
|
|
103
103
|
const webhook = yield getCrowdinProjectWebhook({
|
|
104
104
|
client,
|
|
105
105
|
projectId,
|
|
106
106
|
name: webhookName,
|
|
107
107
|
});
|
|
108
|
-
if (
|
|
108
|
+
if (settings['new-crowdin-files']) {
|
|
109
109
|
events.push(exports.HookEvents.fileAdded);
|
|
110
110
|
}
|
|
111
111
|
if (isWebhookSync && webhook) {
|
|
@@ -130,16 +130,25 @@ function registerWebhooks({ config, apiCredentials, appSettings, client, crowdin
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
if ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhooks) {
|
|
133
|
-
yield integration.webhooks.integrationWebhooks(
|
|
133
|
+
yield integration.webhooks.integrationWebhooks({
|
|
134
|
+
credentials,
|
|
135
|
+
urlParam,
|
|
136
|
+
available: isWebhookSync,
|
|
137
|
+
settings,
|
|
138
|
+
});
|
|
134
139
|
}
|
|
135
140
|
});
|
|
136
141
|
}
|
|
137
142
|
exports.registerWebhooks = registerWebhooks;
|
|
138
|
-
function unregisterWebhooks({
|
|
143
|
+
function unregisterWebhooks({ credentials, settings, client, config, crowdinContext, integration, }) {
|
|
139
144
|
var _a, _b;
|
|
140
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
141
146
|
if ((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.crowdinWebhooks) {
|
|
142
|
-
yield integration.webhooks.crowdinWebhooks(
|
|
147
|
+
yield integration.webhooks.crowdinWebhooks({
|
|
148
|
+
client,
|
|
149
|
+
projectId: crowdinContext.jwtPayload.context.project_id,
|
|
150
|
+
available: false,
|
|
151
|
+
});
|
|
143
152
|
}
|
|
144
153
|
else {
|
|
145
154
|
const webhookName = `${config.name} application hook ${crowdinContext.jwtPayload.sub}`;
|
|
@@ -158,7 +167,7 @@ function unregisterWebhooks({ apiCredentials, appSettings, client, config, crowd
|
|
|
158
167
|
}
|
|
159
168
|
if ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhooks) {
|
|
160
169
|
const urlParam = encodedUrlParam({ config, integration, crowdinContext });
|
|
161
|
-
yield integration.webhooks.integrationWebhooks(
|
|
170
|
+
yield integration.webhooks.integrationWebhooks({ credentials, urlParam, available: false, settings });
|
|
162
171
|
}
|
|
163
172
|
});
|
|
164
173
|
}
|
|
@@ -256,13 +265,13 @@ function prepareWebhookData({ config, integration, provider, webhookUrlParam, })
|
|
|
256
265
|
let syncSettings = null;
|
|
257
266
|
let crowdinClient = null;
|
|
258
267
|
let preparedIntegrationCredentials = null;
|
|
259
|
-
let
|
|
268
|
+
let settings = {};
|
|
260
269
|
const { projectId, crowdinId, clientId } = decodedUrlParam(config, webhookUrlParam);
|
|
261
270
|
const crowdinCredentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(crowdinId);
|
|
262
271
|
const integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(clientId);
|
|
263
272
|
const integrationConfig = yield (0, storage_1.getStorage)().getIntegrationConfig(clientId);
|
|
264
273
|
if (!crowdinCredentials) {
|
|
265
|
-
return { projectId, crowdinClient, rootFolder,
|
|
274
|
+
return { projectId, crowdinClient, rootFolder, settings, syncSettings, preparedIntegrationCredentials };
|
|
266
275
|
}
|
|
267
276
|
const context = Object.assign({ jwtPayload: {
|
|
268
277
|
context: {
|
|
@@ -279,12 +288,12 @@ function prepareWebhookData({ config, integration, provider, webhookUrlParam, })
|
|
|
279
288
|
context,
|
|
280
289
|
});
|
|
281
290
|
if (!integrationCredentials) {
|
|
282
|
-
return { projectId, crowdinClient, rootFolder,
|
|
291
|
+
return { projectId, crowdinClient, rootFolder, settings, syncSettings, preparedIntegrationCredentials };
|
|
283
292
|
}
|
|
284
293
|
preparedIntegrationCredentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
|
|
285
294
|
if (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config) {
|
|
286
|
-
|
|
287
|
-
const isWebhookSync = Number(
|
|
295
|
+
settings = JSON.parse(integrationConfig.config);
|
|
296
|
+
const isWebhookSync = Number(settings.schedule) !== types_1.SyncSchedule.DISABLED;
|
|
288
297
|
if (isWebhookSync) {
|
|
289
298
|
syncSettings = (yield (0, storage_1.getStorage)().getSyncSettings(clientId, crowdinId, 'schedule', provider));
|
|
290
299
|
// We can get an error in getRootFolder when the project has been deleted but the webhooks have been created
|
|
@@ -301,7 +310,7 @@ function prepareWebhookData({ config, integration, provider, webhookUrlParam, })
|
|
|
301
310
|
crowdinClient,
|
|
302
311
|
preparedIntegrationCredentials,
|
|
303
312
|
rootFolder,
|
|
304
|
-
|
|
313
|
+
settings,
|
|
305
314
|
syncSettings,
|
|
306
315
|
};
|
|
307
316
|
});
|
|
@@ -312,10 +321,18 @@ function updateCrowdinFromWebhookRequest(args) {
|
|
|
312
321
|
return __awaiter(this, void 0, void 0, function* () {
|
|
313
322
|
const { integration, webhookData, req } = args;
|
|
314
323
|
let filesToSync = [];
|
|
315
|
-
const { projectId, crowdinClient, preparedIntegrationCredentials, rootFolder,
|
|
324
|
+
const { projectId, crowdinClient, preparedIntegrationCredentials, rootFolder, settings, syncSettings } = webhookData;
|
|
316
325
|
const syncFiles = (syncSettings === null || syncSettings === void 0 ? void 0 : syncSettings.files) ? (0, files_1.prepareSyncFiles)(JSON.parse(syncSettings.files)) : [];
|
|
317
326
|
if ((_a = integration.webhooks) === null || _a === void 0 ? void 0 : _a.integrationWebhookInterceptor) {
|
|
318
|
-
filesToSync = yield ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhookInterceptor(
|
|
327
|
+
filesToSync = yield ((_b = integration.webhooks) === null || _b === void 0 ? void 0 : _b.integrationWebhookInterceptor({
|
|
328
|
+
projectId,
|
|
329
|
+
client: crowdinClient.client,
|
|
330
|
+
credentials: preparedIntegrationCredentials,
|
|
331
|
+
rootFolder,
|
|
332
|
+
settings,
|
|
333
|
+
syncSettings,
|
|
334
|
+
webhookRequests: req,
|
|
335
|
+
}));
|
|
319
336
|
}
|
|
320
337
|
for (const file of filesToSync) {
|
|
321
338
|
const fileNodeType = file.nodeType || file.node_type || '1';
|