@crowdin/app-project-module 1.8.0 → 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.
@@ -49,16 +49,15 @@ exports.prepareCrowdinClient = prepareCrowdinClient;
49
49
  exports.resolveIntegrationAccess = resolveIntegrationAccess;
50
50
  exports.prepareIntegrationCredentials = prepareIntegrationCredentials;
51
51
  const crowdin_api_client_1 = __importDefault(require("@crowdin/crowdin-api-client"));
52
- const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
53
52
  const axios_1 = __importDefault(require("axios"));
53
+ const os = __importStar(require("os"));
54
54
  const _1 = require(".");
55
+ const defaults_1 = require("../modules/integration/util/defaults");
55
56
  const storage_1 = require("../storage");
56
57
  const types_1 = require("../types");
58
+ const token_1 = require("./app-functions/token");
57
59
  const axios_2 = require("./axios");
58
60
  const logger_1 = require("./logger");
59
- const os = __importStar(require("os"));
60
- const defaults_1 = require("../modules/integration/util/defaults");
61
- const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
62
61
  const axiosCustom = new axios_2.AxiosProvider().axios;
63
62
  function prepareCrowdinClient(_a) {
64
63
  return __awaiter(this, arguments, void 0, function* ({ config, credentials, autoRenew = false, context, }) {
@@ -78,7 +77,7 @@ function prepareCrowdinClient(_a) {
78
77
  if (!code) {
79
78
  throw new Error(`Missing code in JWT payload for ${types_1.AuthenticationType.APP_WITH_CODE} authentication`);
80
79
  }
81
- const freshToken = yield (0, crowdin_apps_functions_1.fetchAppWithCodeToken)({
80
+ const freshToken = yield (0, token_1.fetchAppWithCodeToken)({
82
81
  appId: config.identifier,
83
82
  appSecret: credentials.appSecret,
84
83
  clientId: config.clientId,
@@ -262,17 +261,17 @@ function prepareCrowdinClient(_a) {
262
261
  }
263
262
  function resolveIntegrationAccess(clientId) {
264
263
  return __awaiter(this, void 0, void 0, function* () {
265
- const { organization, projectId, userId } = crowdinAppFunctions.parseCrowdinId(clientId);
264
+ const { organization, projectId, userId } = (0, token_1.parseCrowdinId)(clientId);
266
265
  let integrationCredentials = yield (0, storage_1.getStorage)().getIntegrationCredentials(clientId);
267
266
  const ownerIds = [];
268
267
  let projectIntegrationCredentials = [];
269
268
  if (!integrationCredentials) {
270
269
  projectIntegrationCredentials = (yield (0, storage_1.getStorage)().getAllIntegrationCredentials(organization)).filter((item) => {
271
- const { organization: itemOrganization, projectId: itemProjectId } = crowdinAppFunctions.parseCrowdinId(item.id);
270
+ const { organization: itemOrganization, projectId: itemProjectId } = (0, token_1.parseCrowdinId)(item.id);
272
271
  return itemOrganization === organization && itemProjectId === projectId;
273
272
  });
274
273
  for (const credentials of projectIntegrationCredentials) {
275
- ownerIds.push(crowdinAppFunctions.parseCrowdinId(credentials.id).userId);
274
+ ownerIds.push((0, token_1.parseCrowdinId)(credentials.id).userId);
276
275
  if (credentials.managers) {
277
276
  const managers = JSON.parse(credentials.managers) || [];
278
277
  if (managers.includes(`${userId}`)) {
@@ -295,7 +294,7 @@ function resolveIntegrationAccess(clientId) {
295
294
  function prepareIntegrationCredentials(config, integration, integrationCredentials) {
296
295
  return __awaiter(this, void 0, void 0, function* () {
297
296
  const credentials = JSON.parse((0, _1.decryptData)(config, integrationCredentials.credentials));
298
- credentials.ownerId = crowdinAppFunctions.parseCrowdinId(integrationCredentials.id).userId;
297
+ credentials.ownerId = (0, token_1.parseCrowdinId)(integrationCredentials.id).userId;
299
298
  const oauthLogin = integration.oauthLogin;
300
299
  const integrationLogin = integration.loginForm;
301
300
  // Add tokenProvider function to credentials for dynamic token refresh
@@ -420,7 +419,7 @@ function refreshToken(config, credentials) {
420
419
  return __awaiter(this, void 0, void 0, function* () {
421
420
  var _a, _b, _c;
422
421
  if (config.authenticationType === types_1.AuthenticationType.CODE) {
423
- const token = yield (0, crowdin_apps_functions_1.refreshOAuthToken)({
422
+ const token = yield (0, token_1.refreshOAuthToken)({
424
423
  clientId: config.clientId,
425
424
  clientSecret: config.clientSecret,
426
425
  refreshToken: (0, _1.decryptData)(config, credentials.refreshToken),
@@ -433,7 +432,7 @@ function refreshToken(config, credentials) {
433
432
  };
434
433
  }
435
434
  if (config.authenticationType === types_1.AuthenticationType.AGENT) {
436
- const token = yield (0, crowdin_apps_functions_1.fetchAgentToken)({
435
+ const token = yield (0, token_1.fetchAgentToken)({
437
436
  appId: config.identifier,
438
437
  appSecret: credentials.appSecret,
439
438
  clientId: config.clientId,
@@ -449,7 +448,7 @@ function refreshToken(config, credentials) {
449
448
  refreshToken: '',
450
449
  };
451
450
  }
452
- const token = yield (0, crowdin_apps_functions_1.fetchAppToken)({
451
+ const token = yield (0, token_1.fetchAppToken)({
453
452
  appId: config.identifier,
454
453
  appSecret: credentials.appSecret,
455
454
  clientId: config.clientId,
@@ -12,9 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getRequestCredentialsMasker = getRequestCredentialsMasker;
13
13
  exports.maskKey = maskKey;
14
14
  exports.postRequestCredentialsMasker = postRequestCredentialsMasker;
15
- const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
16
15
  const index_1 = require("../index");
17
16
  const crowdin_client_1 = require("../middlewares/crowdin-client");
17
+ const token_1 = require("./app-functions/token");
18
18
  const index_2 = require("./index");
19
19
  function maskKey(key) {
20
20
  const maskWith = '*';
@@ -80,7 +80,7 @@ function postRequestCredentialsMasker({ secret, moduleConfig, credentialsExtract
80
80
  else {
81
81
  // most common way of storing data
82
82
  const jwtToken = (0, crowdin_client_1.getToken)(req) || '';
83
- const jwtPayload = yield (0, crowdin_apps_functions_1.validateJwtToken)(jwtToken, secret);
83
+ const jwtPayload = yield (0, token_1.validateJwtToken)(jwtToken, secret);
84
84
  const crowdinId = `${jwtPayload.context.organization_id}`;
85
85
  unmaskedFields = yield index_1.metadataStore.getMetadata(`form-data-${crowdinId}`);
86
86
  }
package/out/util/index.js CHANGED
@@ -61,13 +61,13 @@ exports.getFormattedDate = getFormattedDate;
61
61
  exports.kebabCase = kebabCase;
62
62
  exports.snakeCase = snakeCase;
63
63
  exports.uniqBy = uniqBy;
64
- const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
65
64
  const crypto = __importStar(require("crypto"));
66
65
  const storage_1 = require("../storage");
67
66
  const types_1 = require("../types");
68
67
  const jsx_renderer_1 = require("./jsx-renderer");
69
68
  const logger_1 = require("./logger");
70
69
  const static_files_1 = require("./static-files");
70
+ const token_1 = require("./app-functions/token");
71
71
  /**
72
72
  * Extract file name from path (works in both Node.js and Cloudflare Workers)
73
73
  * Supports both Unix (/) and Windows (\) path separators
@@ -283,7 +283,7 @@ function getPreviousDate(days) {
283
283
  function prepareFormDataMetadataId(req, config) {
284
284
  return __awaiter(this, void 0, void 0, function* () {
285
285
  const jwtToken = req.query.jwtToken;
286
- const jwtPayload = yield (0, crowdin_apps_functions_1.validateJwtToken)(jwtToken, config.clientSecret, config.jwtValidationOptions);
286
+ const jwtPayload = yield (0, token_1.validateJwtToken)(jwtToken, config.clientSecret, config.jwtValidationOptions);
287
287
  const context = jwtPayload.context;
288
288
  const id = ['form-data'];
289
289
  if (context.organization_id) {
@@ -12,8 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.isAppFree = isAppFree;
13
13
  exports.checkSubscription = checkSubscription;
14
14
  exports.clearCache = clearCache;
15
- const crowdin_apps_functions_1 = require("@crowdin/crowdin-apps-functions");
16
15
  const types_1 = require("../types");
16
+ const crowdin_1 = require("./app-functions/crowdin");
17
17
  const logger_1 = require("./logger");
18
18
  const subscriptionCache = {};
19
19
  function isAppFree(config) {
@@ -38,7 +38,7 @@ function checkSubscription(_a) {
38
38
  }
39
39
  }
40
40
  try {
41
- const subscription = yield (0, crowdin_apps_functions_1.getSubscription)({
41
+ const subscription = yield (0, crowdin_1.getSubscription)({
42
42
  appIdentifier,
43
43
  organization: accountType === types_1.AccountType.ENTERPRISE ? organization : undefined,
44
44
  token,
@@ -51,7 +51,7 @@ function checkSubscription(_a) {
51
51
  return { expired, daysLeft, type: types_1.SubscriptionInfoType.SUBSCRIPTION };
52
52
  }
53
53
  catch (e) {
54
- if (e instanceof crowdin_apps_functions_1.PaymentRequiredError) {
54
+ if (e instanceof types_1.PaymentRequiredError) {
55
55
  const { initializedAt, subscribeLink } = e;
56
56
  (0, logger_1.log)(`Recieved 402 payment error. initializedAt ${initializedAt}`);
57
57
  //default 2 weeks
package/package.json CHANGED
@@ -1,9 +1,26 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
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",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./out/index.js",
10
+ "import": "./out/index.js",
11
+ "types": "./out/index.d.ts"
12
+ },
13
+ "./functions/crowdin": {
14
+ "require": "./out/util/app-functions/crowdin.js",
15
+ "import": "./out/util/app-functions/crowdin.js",
16
+ "types": "./out/util/app-functions/crowdin.d.ts"
17
+ },
18
+ "./functions/token": {
19
+ "require": "./out/util/app-functions/token.js",
20
+ "import": "./out/util/app-functions/token.js",
21
+ "types": "./out/util/app-functions/token.d.ts"
22
+ }
23
+ },
7
24
  "scripts": {
8
25
  "build": "npm run build-main && npm run build-ui",
9
26
  "build-main": "tsc -p ./ && cp -R static out && cp logo.png out",
@@ -19,7 +36,7 @@
19
36
  "out/**/*"
20
37
  ],
21
38
  "dependencies": {
22
- "@crowdin/crowdin-apps-functions": "^0.13.0",
39
+ "@crowdin/crowdin-api-client": "^1.55.0",
23
40
  "@crowdin/logs-formatter": "^2.2.0",
24
41
  "@godaddy/terminus": "^4.12.1",
25
42
  "ajv": "^8.17.1",
@@ -28,6 +45,7 @@
28
45
  "cors": "^2.8.6",
29
46
  "express": "^5.2.1",
30
47
  "express-rate-limit": "^8.2.1",
48
+ "jsonwebtoken": "^9.0.0",
31
49
  "minimatch": "^10.1.1",
32
50
  "mysql2": "^3.16.2",
33
51
  "node-cron": "^4.2.1",
@@ -69,6 +87,7 @@
69
87
  "@types/cors": "^2.8.19",
70
88
  "@types/express": "^5.0.3",
71
89
  "@types/jest": "^29.5.14",
90
+ "@types/jsonwebtoken": "^9.0.10",
72
91
  "@types/minimatch": "^5.1.2",
73
92
  "@types/node": "^20",
74
93
  "@types/pg": "^8.16.0",