@crowdin/app-project-module 1.0.2 → 1.1.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.js CHANGED
@@ -313,7 +313,10 @@ function addFormSchema({ app, config }) {
313
313
  optional: false,
314
314
  checkSubscriptionExpiration: true,
315
315
  moduleKey: moduleConfigWithForm.key,
316
- }), (0, credentials_masker_1.postRequestCredentialsMasker)(moduleConfigWithForm), (0, form_data_save_1.default)(config));
316
+ }), (0, credentials_masker_1.postRequestCredentialsMasker)({
317
+ secret: config.clientSecret,
318
+ moduleConfig: moduleConfigWithForm,
319
+ }), (0, form_data_save_1.default)(config));
317
320
  }
318
321
  }
319
322
  }
@@ -24,7 +24,10 @@ function autoCredentialsMaskerMiddleware(config) {
24
24
  }
25
25
  if (requestMethod === 'post' && moduleConfigWithForm.formPostDataUrl) {
26
26
  if (requestPath === moduleConfigWithForm.formPostDataUrl) {
27
- return (0, credentials_masker_1.postRequestCredentialsMasker)(moduleConfigWithForm)(req, res, next);
27
+ return (0, credentials_masker_1.postRequestCredentialsMasker)({
28
+ secret: config.clientSecret,
29
+ moduleConfig: moduleConfigWithForm,
30
+ })(req, res, next);
28
31
  }
29
32
  }
30
33
  }
@@ -18,7 +18,7 @@ const types_1 = require("../util/types");
18
18
  const types_2 = require("../types");
19
19
  function handle(config, integration) {
20
20
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
21
- const { files, provider, expandIntegrationFolders, hasLoadMoreElements } = req.body;
21
+ const { files, provider, expandIntegrationFolders, hasLoadMoreElements, folderIds } = req.body;
22
22
  if (req.isApiCall) {
23
23
  if (!files || !provider) {
24
24
  return res.status(400).json({
@@ -77,9 +77,12 @@ function handle(config, integration) {
77
77
  }
78
78
  const settings = req.integrationSettings || {};
79
79
  const syncFiles = (0, files_1.prepareSyncFiles)(files);
80
+ const hasSyncedFolders = provider === types_2.Provider.INTEGRATION
81
+ ? (0, files_1.hasFolders)(syncFiles)
82
+ : Array.isArray(folderIds) && folderIds.length > 0;
80
83
  const needsSnapshot = !integration.webhooks &&
81
84
  ((_a = integration.syncNewElements) === null || _a === void 0 ? void 0 : _a[provider]) &&
82
- (settings[`new-${provider}-files`] || (0, files_1.hasFolders)(syncFiles));
85
+ (settings[`new-${provider}-files`] || hasSyncedFolders);
83
86
  if (needsSnapshot) {
84
87
  yield (0, snapshot_1.createOrUpdateFileSnapshot)(config, integration, req, provider);
85
88
  }
@@ -162,7 +162,7 @@ function filesCron({ config, integration, period, }) {
162
162
  }
163
163
  exports.filesCron = filesCron;
164
164
  function processSyncSettings({ config, integration, period, syncSettings, }) {
165
- var _a, _b, _c;
165
+ var _a, _b, _c, _d;
166
166
  return __awaiter(this, void 0, void 0, function* () {
167
167
  let projectData;
168
168
  let crowdinClient;
@@ -234,11 +234,22 @@ function processSyncSettings({ config, integration, period, syncSettings, }) {
234
234
  const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, crowdinClient, projectId);
235
235
  const credentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
236
236
  let currentFileSnapshot = [];
237
- const needsSnapshotForNewFiles = !integration.webhooks &&
237
+ let needsSnapshotForNewFiles = !integration.webhooks &&
238
238
  ((_a = integration.syncNewElements) === null || _a === void 0 ? void 0 : _a[syncSettings.provider]) &&
239
239
  (intConfig[`new-${syncSettings.provider}-files`] || (0, files_1.hasFolders)(files));
240
+ if (!needsSnapshotForNewFiles &&
241
+ !integration.webhooks &&
242
+ ((_b = integration.syncNewElements) === null || _b === void 0 ? void 0 : _b[syncSettings.provider]) &&
243
+ syncSettings.provider === types_1.Provider.CROWDIN) {
244
+ currentFileSnapshot = yield (0, snapshot_1.getCrowdinSnapshot)(config, integration, crowdinClient, projectData.id, intConfig);
245
+ const syncedFileIds = Object.keys(files);
246
+ const hasSyncedFolders = currentFileSnapshot.some((file) => !('type' in file) && syncedFileIds.includes(String(file.id)));
247
+ if (hasSyncedFolders) {
248
+ needsSnapshotForNewFiles = true;
249
+ }
250
+ }
240
251
  const needsIntegrationSnapshot = needsSnapshotForNewFiles && syncSettings.provider !== types_1.Provider.CROWDIN;
241
- const needsCrowdinSnapshot = needsSnapshotForNewFiles && syncSettings.provider === types_1.Provider.CROWDIN;
252
+ const needsCrowdinSnapshot = needsSnapshotForNewFiles && syncSettings.provider === types_1.Provider.CROWDIN && currentFileSnapshot.length === 0;
242
253
  if (needsIntegrationSnapshot) {
243
254
  currentFileSnapshot = yield (0, snapshot_1.getIntegrationSnapshot)(integration, credentials, intConfig);
244
255
  }
@@ -376,8 +387,8 @@ function processSyncSettings({ config, integration, period, syncSettings, }) {
376
387
  (0, logger_1.log)(`Executing updateCrowdin task for files cron job with period [${period}] for project ${projectId}. Files ${intFiles.length}`);
377
388
  const credentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
378
389
  if (integration.filterByPathIntegrationFiles) {
379
- const includePatterns = (_b = intConfig === null || intConfig === void 0 ? void 0 : intConfig.includeByFilePath) === null || _b === void 0 ? void 0 : _b.split('\n').filter(Boolean);
380
- const excludePatterns = (_c = intConfig === null || intConfig === void 0 ? void 0 : intConfig.excludeByFilePath) === null || _c === void 0 ? void 0 : _c.split('\n').filter(Boolean);
390
+ const includePatterns = (_c = intConfig === null || intConfig === void 0 ? void 0 : intConfig.includeByFilePath) === null || _c === void 0 ? void 0 : _c.split('\n').filter(Boolean);
391
+ const excludePatterns = (_d = intConfig === null || intConfig === void 0 ? void 0 : intConfig.excludeByFilePath) === null || _d === void 0 ? void 0 : _d.split('\n').filter(Boolean);
381
392
  try {
382
393
  const fullTreeResult = yield integration.getIntegrationFiles({
383
394
  credentials,