@crowdin/app-project-module 0.73.1 → 0.73.2

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.
@@ -1,3 +1,4 @@
1
1
  /// <reference types="qs" />
2
2
  import { Response } from 'express';
3
- export default function handle(): (req: import("../../../types").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
3
+ import { Config } from '../../../types';
4
+ export default function handle(config: Config): (req: import("../../../types").CrowdinClientRequest | import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: Function) => void;
@@ -12,6 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const types_1 = require("../util/types");
13
13
  const util_1 = require("../../../util");
14
14
  const storage_1 = require("../../../storage");
15
+ const cron_1 = require("../util/cron");
16
+ const defaults_1 = require("../util/defaults");
17
+ const connection_1 = require("../../../util/connection");
18
+ const MINUTES = 60;
15
19
  function getHumanETA(ms) {
16
20
  const seconds = Math.floor(ms / 1000);
17
21
  let minutes = Math.floor(seconds / 60);
@@ -29,7 +33,7 @@ function getHumanETA(ms) {
29
33
  }
30
34
  return `About ${timeParts.join(' and ')} remaining`;
31
35
  }
32
- function handle() {
36
+ function handle(config) {
33
37
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
34
38
  const id = req.query.job_id || req.body.job_id;
35
39
  if (!id) {
@@ -47,6 +51,37 @@ function handle() {
47
51
  job.eta = ((Date.now() - job.createdAt) / job.progress) * (100 - job.progress);
48
52
  job.info = getHumanETA(job.eta) + (job.info ? `\n${job.info}` : '');
49
53
  }
54
+ if (job && (job === null || job === void 0 ? void 0 : job.updatedAt) && Date.now() - job.updatedAt >= MINUTES * 60 * 1000) {
55
+ const context = req.crowdinContext;
56
+ const projectId = context.jwtPayload.context.project_id;
57
+ const integration = config.projectIntegration;
58
+ const crowdinId = req.crowdinContext.crowdinId;
59
+ const integrationId = req.crowdinContext.clientId;
60
+ const integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(integrationId);
61
+ const credentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
62
+ const integrationConfig = yield (0, storage_1.getStorage)().getIntegrationConfig(integrationId);
63
+ const intConfig = (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config)
64
+ ? JSON.parse(integrationConfig.config)
65
+ : { schedule: '0', condition: '0' };
66
+ const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, req.crowdinApiClient, projectId);
67
+ req.logInfo(`Restarting the job after no updates for more than ${MINUTES} minutes.`);
68
+ return (0, cron_1.runUpdateProviderJob)({
69
+ integrationId,
70
+ crowdinId,
71
+ type: job.type,
72
+ title: job.title,
73
+ payload: JSON.parse(job.payload),
74
+ jobType: types_1.JobClientType.RERUN,
75
+ projectId,
76
+ client: req.crowdinApiClient,
77
+ integration,
78
+ context,
79
+ credentials,
80
+ rootFolder,
81
+ appSettings: intConfig,
82
+ reRunJobId: id,
83
+ });
84
+ }
50
85
  req.logInfo(`Returning job info ${JSON.stringify(job, null, 2)}`);
51
86
  res.send(job);
52
87
  }));
@@ -93,7 +93,7 @@ function register({ config, app }) {
93
93
  optional: false,
94
94
  checkSubscriptionExpiration: true,
95
95
  moduleKey: integrationLogic.key,
96
- }), (0, job_info_1.default)());
96
+ }), (0, job_info_1.default)(config));
97
97
  app.delete('/api/jobs', json_response_1.default, (0, crowdin_client_1.default)({
98
98
  config,
99
99
  optional: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.73.1",
3
+ "version": "0.73.2",
4
4
  "description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
5
5
  "main": "out/index.js",
6
6
  "types": "out/index.d.ts",