@crowdin/app-project-module 1.8.1 → 1.9.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.
@@ -12,21 +12,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.prepareCrowdinRequest = prepareCrowdinRequest;
13
13
  exports.default = handle;
14
14
  exports.getToken = getToken;
15
- const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
15
+ const api_1 = require("../modules/api/api");
16
16
  const storage_1 = require("../storage");
17
17
  const util_1 = require("../util");
18
- const api_1 = require("../modules/api/api");
19
18
  const connection_1 = require("../util/connection");
20
- const integration_access_denied_1 = require("./integration-access-denied");
21
19
  const logger_1 = require("../util/logger");
22
20
  const subscription_1 = require("../util/subscription");
21
+ const integration_access_denied_1 = require("./integration-access-denied");
22
+ const token_1 = require("../util/app-functions/token");
23
23
  function prepareCrowdinRequest(_a) {
24
24
  return __awaiter(this, arguments, void 0, function* ({ jwtToken, config, optional = false, checkSubscriptionExpiration = true, moduleKey, }) {
25
25
  (0, logger_1.log)('Validating jwt token from incoming request');
26
- const jwtPayload = yield (0, crowdin_apps_functions_1.validateJwtToken)(jwtToken, config.clientSecret, config.jwtValidationOptions);
26
+ const jwtPayload = yield (0, token_1.validateJwtToken)(jwtToken, config.clientSecret, config.jwtValidationOptions);
27
27
  const context = {
28
28
  jwtPayload,
29
- clientId: (0, crowdin_apps_functions_1.constructCrowdinIdFromJwtPayload)(jwtPayload),
29
+ clientId: (0, token_1.constructCrowdinIdFromJwtPayload)(jwtPayload),
30
30
  crowdinId: `${jwtPayload.domain || jwtPayload.context.organization_id}`,
31
31
  appIdentifier: config.identifier,
32
32
  };
@@ -1,7 +1,7 @@
1
1
  import Crowdin from '@crowdin/crowdin-api-client';
2
2
  import { Response } from 'express';
3
- import { CrowdinClientRequest } from '../types';
4
3
  import { IntegrationRequest } from '../modules/integration/types';
4
+ import { CrowdinClientRequest } from '../types';
5
5
  interface OwnerInfo {
6
6
  name: string;
7
7
  id: number;
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -44,15 +11,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
44
11
  Object.defineProperty(exports, "__esModule", { value: true });
45
12
  exports.getIntegrationManagedBy = getIntegrationManagedBy;
46
13
  exports.renderIntegrationAccessDenied = renderIntegrationAccessDenied;
47
- const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
48
14
  const jsx_renderer_1 = require("../util/jsx-renderer");
49
15
  const logger_1 = require("../util/logger");
16
+ const token_1 = require("../util/app-functions/token");
50
17
  function getIntegrationManagedBy(_a) {
51
18
  return __awaiter(this, arguments, void 0, function* ({ ownerIds, crowdinApiClient, clientId, }) {
52
19
  if (!ownerIds.length) {
53
20
  return [];
54
21
  }
55
- const projectId = crowdinAppFunctions.getProjectId(clientId);
22
+ const projectId = (0, token_1.getProjectId)(clientId);
56
23
  let owners = [];
57
24
  try {
58
25
  owners =
@@ -10,10 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.default = handle;
13
- const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
14
13
  const storage_1 = require("../storage");
15
14
  const types_1 = require("../types");
16
15
  const util_1 = require("../util");
16
+ const token_1 = require("../util/app-functions/token");
17
17
  const connection_1 = require("../util/connection");
18
18
  const jsx_renderer_1 = require("../util/jsx-renderer");
19
19
  const logger_1 = require("../util/logger");
@@ -40,7 +40,7 @@ function handle({ config, allowUnauthorized = false, moduleType, }) {
40
40
  return res.status(403).send({ error: 'Access denied' });
41
41
  }
42
42
  (0, logger_1.log)('Validating jwt token from incoming request');
43
- const jwtPayload = yield (0, crowdin_apps_functions_1.validateJwtToken)(jwtToken, config.clientSecret, config.jwtValidationOptions);
43
+ const jwtPayload = yield (0, token_1.validateJwtToken)(jwtToken, config.clientSecret, config.jwtValidationOptions);
44
44
  const id = `${jwtPayload.domain || jwtPayload.context.organization_id}`;
45
45
  if (moduleType && jwtPayload.module && jwtPayload.module !== moduleType) {
46
46
  (0, logger_1.temporaryErrorDebug)('Access denied: ui-module', req);
@@ -48,7 +48,7 @@ function handle({ config, allowUnauthorized = false, moduleType, }) {
48
48
  }
49
49
  const context = {
50
50
  jwtPayload,
51
- clientId: (0, crowdin_apps_functions_1.constructCrowdinIdFromJwtPayload)(jwtPayload),
51
+ clientId: (0, token_1.constructCrowdinIdFromJwtPayload)(jwtPayload),
52
52
  crowdinId: id,
53
53
  appIdentifier: config.identifier,
54
54
  };
@@ -10,12 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.default = handle;
13
- const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
14
- const types_1 = require("../types");
15
13
  const storage_1 = require("../storage");
14
+ const types_1 = require("../types");
16
15
  const util_1 = require("../util");
17
- const logger_1 = require("../util/logger");
16
+ const token_1 = require("../util/app-functions/token");
18
17
  const connection_1 = require("../util/connection");
18
+ const logger_1 = require("../util/logger");
19
19
  function handle(config) {
20
20
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
21
21
  const event = req.body;
@@ -57,7 +57,7 @@ function fetchToken(config, event) {
57
57
  return __awaiter(this, void 0, void 0, function* () {
58
58
  var _a, _b, _c, _d;
59
59
  if (config.authenticationType === types_1.AuthenticationType.CODE) {
60
- const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)({
60
+ const token = yield (0, token_1.generateOAuthToken)({
61
61
  clientId: config.clientId,
62
62
  clientSecret: config.clientSecret,
63
63
  code: event.code || '',
@@ -70,7 +70,7 @@ function fetchToken(config, event) {
70
70
  };
71
71
  }
72
72
  if (config.authenticationType === types_1.AuthenticationType.AGENT) {
73
- const token = yield (0, crowdin_apps_functions_1.fetchAgentToken)({
73
+ const token = yield (0, token_1.fetchAgentToken)({
74
74
  appId: config.identifier,
75
75
  appSecret: event.appSecret,
76
76
  clientId: config.clientId,
@@ -87,7 +87,7 @@ function fetchToken(config, event) {
87
87
  };
88
88
  }
89
89
  if (config.authenticationType === types_1.AuthenticationType.APP_WITH_CODE) {
90
- const token = yield (0, crowdin_apps_functions_1.fetchAppWithCodeToken)({
90
+ const token = yield (0, token_1.fetchAppWithCodeToken)({
91
91
  appId: config.identifier,
92
92
  appSecret: event.appSecret,
93
93
  clientId: config.clientId,
@@ -103,7 +103,7 @@ function fetchToken(config, event) {
103
103
  refreshToken: '',
104
104
  };
105
105
  }
106
- const token = yield (0, crowdin_apps_functions_1.fetchAppToken)({
106
+ const token = yield (0, token_1.fetchAppToken)({
107
107
  appId: config.identifier,
108
108
  appSecret: event.appSecret,
109
109
  clientId: config.clientId,
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -45,13 +12,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
45
12
  exports.default = handle;
46
13
  const storage_1 = require("../../../storage");
47
14
  const util_1 = require("../../../util");
15
+ const token_1 = require("../../../util/app-functions/token");
48
16
  const logger_1 = require("../../../util/logger");
49
17
  const subscription_1 = require("../../../util/subscription");
50
18
  const webhooks_1 = require("../util/webhooks");
51
- const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
52
19
  function handle(config, integration) {
53
20
  return (0, util_1.runAsyncWrapper)((req, res) => __awaiter(this, void 0, void 0, function* () {
54
- const { userId } = crowdinAppFunctions.parseCrowdinId(req.crowdinContext.clientId);
21
+ const { userId } = (0, token_1.parseCrowdinId)(req.crowdinContext.clientId);
55
22
  const isCredentialOwner = +userId === +req.crowdinContext.jwtPayload.sub;
56
23
  if (!isCredentialOwner && !req.canForceIntegrationLogout) {
57
24
  return res.status(403).send({ error: 'Access denied' });
@@ -13,10 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.default = handle;
16
- const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
17
16
  const axios_1 = __importDefault(require("axios"));
18
17
  const storage_1 = require("../../../storage");
19
18
  const util_1 = require("../../../util");
19
+ const token_1 = require("../../../util/app-functions/token");
20
20
  const jsx_renderer_1 = require("../../../util/jsx-renderer");
21
21
  const logger_1 = require("../../../util/logger");
22
22
  const defaults_1 = require("../util/defaults");
@@ -31,7 +31,7 @@ function handle(config, integration) {
31
31
  (0, logger_1.log)(`Received request from OAuth login callback. Code ${code}`);
32
32
  (0, logger_1.log)(`Received request from OAuth login callback. State ${state}`);
33
33
  const clientId = Buffer.from(state, 'base64').toString();
34
- const { organization } = (0, crowdin_apps_functions_1.parseCrowdinId)(clientId);
34
+ const { organization } = (0, token_1.parseCrowdinId)(clientId);
35
35
  const redirectUri = `${config.baseUrl}${(0, defaults_1.getOauthRoute)(integration)}`;
36
36
  try {
37
37
  const oauthLogin = integration.oauthLogin;
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -48,17 +15,17 @@ exports.filesCron = filesCron;
48
15
  exports.filterFilesFromIntegrationRequest = filterFilesFromIntegrationRequest;
49
16
  exports.createOrUpdateSyncSettings = createOrUpdateSyncSettings;
50
17
  exports.removeFinishedJobs = removeFinishedJobs;
51
- const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
52
18
  const storage_1 = require("../../../storage");
19
+ const token_1 = require("../../../util/app-functions/token");
53
20
  const connection_1 = require("../../../util/connection");
54
- const defaults_1 = require("./defaults");
55
- const snapshot_1 = require("./snapshot");
56
21
  const logger_1 = require("../../../util/logger");
22
+ const subscription_1 = require("../../../util/subscription");
57
23
  const types_1 = require("../types");
24
+ const defaults_1 = require("./defaults");
25
+ const files_1 = require("./files");
58
26
  const job_1 = require("./job");
27
+ const snapshot_1 = require("./snapshot");
59
28
  const types_2 = require("./types");
60
- const subscription_1 = require("../../../util/subscription");
61
- const files_1 = require("./files");
62
29
  function runJob(_a) {
63
30
  return __awaiter(this, arguments, void 0, function* ({ config, integration, job, }) {
64
31
  (0, logger_1.log)(`Starting cron job with expression [${job.expression}]`);
@@ -83,7 +50,7 @@ function runJob(_a) {
83
50
  const allIntegrationConfigs = yield (0, storage_1.getStorage)().getAllIntegrationConfigs(crowdinCredentials.id);
84
51
  for (const integrationCredentials of integrationCredentialsList) {
85
52
  const integrationConfig = allIntegrationConfigs.find(({ integrationId }) => integrationId === integrationCredentials.id);
86
- const projectId = crowdinAppFunctions.getProjectId(integrationCredentials.id);
53
+ const projectId = (0, token_1.getProjectId)(integrationCredentials.id);
87
54
  const credentials = yield (0, connection_1.prepareIntegrationCredentials)(config, integration, integrationCredentials);
88
55
  const rootFolder = yield (0, defaults_1.getRootFolder)(config, integration, crowdinClient, projectId);
89
56
  const intConfig = (integrationConfig === null || integrationConfig === void 0 ? void 0 : integrationConfig.config) ? JSON.parse(integrationConfig.config) : undefined;
@@ -202,7 +169,7 @@ function processSyncSettings(_a) {
202
169
  if (period !== intConfig.schedule) {
203
170
  return;
204
171
  }
205
- const projectId = crowdinAppFunctions.getProjectId(integrationCredentials.id);
172
+ const projectId = (0, token_1.getProjectId)(integrationCredentials.id);
206
173
  const context = {
207
174
  jwtPayload: {
208
175
  context: {
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -50,7 +17,7 @@ exports.getOAuthPollingId = getOAuthPollingId;
50
17
  exports.getOAuthLoginFormId = getOAuthLoginFormId;
51
18
  exports.groupFieldsByCategory = groupFieldsByCategory;
52
19
  exports.buildMenuItems = buildMenuItems;
53
- const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
20
+ const crowdin_1 = require("../../../util/app-functions/crowdin");
54
21
  const types_1 = require("../types");
55
22
  function getRootFolder(config, integration, client, projectId) {
56
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -59,7 +26,7 @@ function getRootFolder(config, integration, client, projectId) {
59
26
  }
60
27
  const folder = integration.appFolderName || config.name;
61
28
  const directories = (yield client.sourceFilesApi.withFetchAll().listProjectDirectories(projectId)).data.map((d) => d.data);
62
- const { folder: rootFolder } = yield crowdinAppFunctions.getOrCreateFolder({
29
+ const { folder: rootFolder } = yield (0, crowdin_1.getOrCreateFolder)({
63
30
  directories,
64
31
  client,
65
32
  projectId,
@@ -1,7 +1,7 @@
1
- import { JobClient, JobClientType, JobStoreType, JobType } from './types';
2
- import { Response } from 'express';
3
1
  import Crowdin from '@crowdin/crowdin-api-client';
2
+ import { Response } from 'express';
4
3
  import { Config } from '../../../types';
4
+ import { JobClient, JobClientType, JobStoreType, JobType } from './types';
5
5
  export declare function runAsJob({ integrationId, crowdinId, type, title, payload, res, projectId, client, jobType, jobStoreType, jobCallback, onError, reRunJobId, forcePushTranslations, initiatedBy, }: {
6
6
  integrationId: string;
7
7
  crowdinId: string;
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -44,13 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
44
11
  Object.defineProperty(exports, "__esModule", { value: true });
45
12
  exports.runAsJob = runAsJob;
46
13
  exports.reRunInProgressJobs = reRunInProgressJobs;
47
- const types_1 = require("./types");
48
14
  const storage_1 = require("../../../storage");
49
- const logger_1 = require("../../../util/logger");
50
- const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
15
+ const token_1 = require("../../../util/app-functions/token");
51
16
  const connection_1 = require("../../../util/connection");
52
- const defaults_1 = require("./defaults");
17
+ const logger_1 = require("../../../util/logger");
53
18
  const cron_1 = require("./cron");
19
+ const defaults_1 = require("./defaults");
20
+ const types_1 = require("./types");
54
21
  const blockingJobs = {
55
22
  [types_1.JobType.UPDATE_TO_CROWDIN]: [types_1.JobType.UPDATE_TO_CROWDIN, types_1.JobType.UPDATE_TO_INTEGRATION],
56
23
  [types_1.JobType.UPDATE_TO_INTEGRATION]: [types_1.JobType.UPDATE_TO_CROWDIN, types_1.JobType.UPDATE_TO_INTEGRATION],
@@ -268,7 +235,7 @@ function reRunInProgressJobs(config) {
268
235
  if (!integrationCredentials || !crowdinCredentials) {
269
236
  return;
270
237
  }
271
- const projectId = crowdinAppFunctions.getProjectId(integrationCredentials.id);
238
+ const projectId = (0, token_1.getProjectId)(integrationCredentials.id);
272
239
  const context = {
273
240
  jwtPayload: {
274
241
  context: {
@@ -1,6 +1,6 @@
1
1
  import Crowdin from '@crowdin/crowdin-api-client';
2
- import { AppSettings, IntegrationLogic, IntegrationSyncSettings, Provider, UpdateCrowdinWebhookPayloadsArgs } from '../types';
3
2
  import { Config, CrowdinContextInfo } from '../../../types';
3
+ import { AppSettings, IntegrationLogic, IntegrationSyncSettings, Provider, UpdateCrowdinWebhookPayloadsArgs } from '../types';
4
4
  export declare const HookEvents: any;
5
5
  export declare function registerWebhooks({ config, credentials, settings, client, crowdinContext, integration, }: {
6
6
  config: Config;
@@ -53,15 +53,15 @@ exports.prepareWebhookData = prepareWebhookData;
53
53
  exports.updateCrowdinFromWebhookRequest = updateCrowdinFromWebhookRequest;
54
54
  exports.listenQueueMessage = listenQueueMessage;
55
55
  const logsFormatter = __importStar(require("@crowdin/logs-formatter"));
56
- const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
57
56
  const amqplib_1 = __importDefault(require("amqplib"));
58
- const types_1 = require("../types");
59
57
  const storage_1 = require("../../../storage");
60
58
  const connection_1 = require("../../../util/connection");
61
- const defaults_1 = require("./defaults");
62
59
  const index_1 = require("../../../util/index");
63
60
  const logger_1 = require("../../../util/logger");
61
+ const types_1 = require("../types");
62
+ const defaults_1 = require("./defaults");
64
63
  const files_1 = require("./files");
64
+ const token_1 = require("../../../util/app-functions/token");
65
65
  const prefetchCount = 10;
66
66
  const forceProcessDelay = 10000;
67
67
  const maxReconnectAttempts = 5;
@@ -108,7 +108,7 @@ function registerWebhooks(_a) {
108
108
  yield integration.webhooks.crowdinWebhooks({ client, projectId, available: isWebhookSync, settings });
109
109
  }
110
110
  else {
111
- const { userId } = crowdinAppFunctions.parseCrowdinId(crowdinContext.clientId);
111
+ const { userId } = (0, token_1.parseCrowdinId)(crowdinContext.clientId);
112
112
  const webhookName = `${config.name} application hook ${userId}`;
113
113
  const webhookUrl = makeCrowdinWebhookUrl({
114
114
  config,
@@ -167,7 +167,7 @@ function unregisterWebhooks(_a) {
167
167
  });
168
168
  }
169
169
  else {
170
- const { userId } = crowdinAppFunctions.parseCrowdinId(crowdinContext.clientId);
170
+ const { userId } = (0, token_1.parseCrowdinId)(crowdinContext.clientId);
171
171
  const webhookName = `${config.name} application hook ${userId}`;
172
172
  const webhook = yield getCrowdinProjectWebhook({
173
173
  client,
@@ -214,7 +214,7 @@ function createPayload(events) {
214
214
  }
215
215
  function registerCrowdinWebhook(_a) {
216
216
  return __awaiter(this, arguments, void 0, function* ({ client, config, crowdinContext, events, url, }) {
217
- const { userId } = crowdinAppFunctions.parseCrowdinId(crowdinContext.clientId);
217
+ const { userId } = (0, token_1.parseCrowdinId)(crowdinContext.clientId);
218
218
  const name = `${config.name} application hook ${userId}`;
219
219
  const payload = createPayload(events);
220
220
  yield client.webhooksApi.addWebhook(crowdinContext.jwtPayload.context.project_id, {
@@ -255,7 +255,7 @@ function unregisterAllCrowdinWebhooks(_a) {
255
255
  const crowdinCredentials = yield (0, storage_1.getStorage)().getCrowdinCredentials(crowdinId);
256
256
  if (crowdinCredentials) {
257
257
  const credentials = yield (0, storage_1.getStorage)().getAllIntegrationCredentials(crowdinId);
258
- const projectIds = credentials.map((c) => crowdinAppFunctions.getProjectId(c.id));
258
+ const projectIds = credentials.map((c) => (0, token_1.getProjectId)(c.id));
259
259
  const crowdinClient = yield (0, connection_1.prepareCrowdinClient)({ config, credentials: crowdinCredentials });
260
260
  yield Promise.all(projectIds.map((projectId) => __awaiter(this, void 0, void 0, function* () {
261
261
  const webhooks = yield getAllCrowdinProjectWebhooks({