@crowdin/app-project-module 0.68.0 → 0.68.1

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.
@@ -43,6 +43,7 @@ function handle(config, integration) {
43
43
  projectId: projectId,
44
44
  client: req.crowdinApiClient,
45
45
  jobType: types_1.JobClientType.MANUAL,
46
+ jobStoreType: integration.jobStoreType,
46
47
  jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
47
48
  var _c;
48
49
  if (req.body && ((_c = req.body) === null || _c === void 0 ? void 0 : _c.length)) {
@@ -37,6 +37,7 @@ function handle(config, integration) {
37
37
  projectId: req.crowdinContext.jwtPayload.context.project_id,
38
38
  client: req.crowdinApiClient,
39
39
  jobType: types_1.JobClientType.MANUAL,
40
+ jobStoreType: integration.jobStoreType,
40
41
  jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
41
42
  const result = yield integration.updateIntegration({
42
43
  projectId: req.crowdinContext.jwtPayload.context.project_id,
@@ -36,6 +36,7 @@ function handle(config, integration) {
36
36
  projectId: req.crowdinContext.jwtPayload.context.project_id,
37
37
  client: req.crowdinApiClient,
38
38
  jobType: types_1.JobClientType.MANUAL,
39
+ jobStoreType: integration.jobStoreType,
39
40
  jobCallback: () => __awaiter(this, void 0, void 0, function* () {
40
41
  if (Array.isArray(expandIntegrationFolders) && expandIntegrationFolders.length) {
41
42
  const allFiles = (yield (0, files_1.expandFilesTree)(expandIntegrationFolders, req, integration)).map((node) => ({
@@ -1,7 +1,7 @@
1
1
  import Crowdin, { SourceFilesModel, TranslationStatusModel } from '@crowdin/crowdin-api-client';
2
2
  import { Request } from 'express';
3
3
  import { CrowdinClientRequest, ModuleKey } from '../../types';
4
- import { JobClient } from './util/types';
4
+ import { JobClient, JobStoreType } from './util/types';
5
5
  export interface IntegrationLogic extends ModuleKey {
6
6
  /**
7
7
  * Customize your app login form
@@ -56,6 +56,10 @@ export interface IntegrationLogic extends ModuleKey {
56
56
  appSettings?: any;
57
57
  job: JobClient;
58
58
  }) => Promise<void | ExtendedResult<void>>;
59
+ /**
60
+ * Store to use for memorizing job data
61
+ */
62
+ jobStoreType?: JobStoreType;
59
63
  /**
60
64
  * function to define configuration(settings) modal for you app (by default app will not have any custom settings)
61
65
  */
@@ -93,6 +93,7 @@ function runUpdateProviderJob({ integrationId, crowdinId, type, title, payload,
93
93
  projectId,
94
94
  client,
95
95
  reRunJobId,
96
+ jobStoreType: integration.jobStoreType,
96
97
  jobCallback: (job) => __awaiter(this, void 0, void 0, function* () {
97
98
  const updateParams = {
98
99
  projectId,
@@ -258,6 +258,7 @@ function applyIntegrationModuleDefaults(config, integration) {
258
258
  if (!integration.userErrorLifetimeDays) {
259
259
  integration.userErrorLifetimeDays = 30;
260
260
  }
261
+ integration.jobStoreType = integration.jobStoreType || 'db';
261
262
  }
262
263
  exports.applyIntegrationModuleDefaults = applyIntegrationModuleDefaults;
263
264
  function constructOauthUrl({ config, integration, clientId, loginForm, }) {
@@ -1,8 +1,8 @@
1
- import { JobClient, JobClientType, JobType } from './types';
1
+ import { JobClient, JobClientType, JobStoreType, JobType } from './types';
2
2
  import { Response } from 'express';
3
3
  import Crowdin from '@crowdin/crowdin-api-client';
4
4
  import { Config } from '../../../types';
5
- export declare function runAsJob({ integrationId, crowdinId, type, title, payload, res, projectId, client, jobType, jobCallback, onError, reRunJobId, }: {
5
+ export declare function runAsJob({ integrationId, crowdinId, type, title, payload, res, projectId, client, jobType, jobStoreType, jobCallback, onError, reRunJobId, }: {
6
6
  integrationId: string;
7
7
  crowdinId: string;
8
8
  type: JobType;
@@ -12,6 +12,7 @@ export declare function runAsJob({ integrationId, crowdinId, type, title, payloa
12
12
  projectId: number;
13
13
  client: Crowdin;
14
14
  jobType: JobClientType;
15
+ jobStoreType: JobStoreType;
15
16
  jobCallback: (arg1: JobClient) => Promise<any>;
16
17
  onError?: (e: any) => Promise<void>;
17
18
  reRunJobId?: string;
@@ -47,7 +47,8 @@ const blockingJobs = {
47
47
  [types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE]: [types_1.JobType.INTEGRATION_SYNC_SETTINGS_SAVE],
48
48
  };
49
49
  const maxAttempts = 3;
50
- function runAsJob({ integrationId, crowdinId, type, title, payload, res, projectId, client, jobType, jobCallback, onError, reRunJobId, }) {
50
+ const store = {};
51
+ function runAsJob({ integrationId, crowdinId, type, title, payload, res, projectId, client, jobType, jobStoreType, jobCallback, onError, reRunJobId, }) {
51
52
  return __awaiter(this, void 0, void 0, function* () {
52
53
  let jobId;
53
54
  const storage = (0, storage_1.getStorage)();
@@ -77,6 +78,7 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, project
77
78
  if (res) {
78
79
  res.status(202).send({ jobId });
79
80
  }
81
+ const isDbStore = jobStoreType === 'db';
80
82
  const job = {
81
83
  get: function getJob() {
82
84
  return __awaiter(this, void 0, void 0, function* () {
@@ -102,14 +104,37 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, project
102
104
  },
103
105
  type: jobType,
104
106
  fetchTranslation: ({ fileId, languageId }) => __awaiter(this, void 0, void 0, function* () {
105
- const translationCache = yield storage.getFileTranslationCacheByLanguage({
106
- integrationId,
107
- crowdinId,
108
- fileId,
109
- languageId,
110
- });
107
+ var _a, _b, _c;
108
+ const translationCache = isDbStore
109
+ ? yield storage.getFileTranslationCacheByLanguage({
110
+ integrationId,
111
+ crowdinId,
112
+ fileId,
113
+ languageId,
114
+ })
115
+ : (_c = (_b = (_a = store[integrationId]) === null || _a === void 0 ? void 0 : _a[crowdinId]) === null || _b === void 0 ? void 0 : _b[fileId]) === null || _c === void 0 ? void 0 : _c[languageId];
111
116
  if (!translationCache) {
112
- yield storage.saveTranslationCache({ integrationId, crowdinId, fileId, languageId });
117
+ if (isDbStore) {
118
+ yield storage.saveTranslationCache({ integrationId, crowdinId, fileId, languageId });
119
+ }
120
+ else {
121
+ if (!store[integrationId]) {
122
+ store[integrationId] = {};
123
+ }
124
+ if (!store[integrationId][crowdinId]) {
125
+ store[integrationId] = {
126
+ [crowdinId]: {},
127
+ };
128
+ }
129
+ if (!store[integrationId][crowdinId][fileId]) {
130
+ store[integrationId] = {
131
+ [crowdinId]: {
132
+ [fileId]: {},
133
+ },
134
+ };
135
+ }
136
+ store[integrationId][crowdinId][fileId][languageId] = {};
137
+ }
113
138
  }
114
139
  let translation = null;
115
140
  try {
@@ -126,6 +151,10 @@ function runAsJob({ integrationId, crowdinId, type, title, payload, res, project
126
151
  }),
127
152
  // translationUploaded: async ({ fileId, languageId, etag }) => {
128
153
  translationUploaded: ({ fileId, translationParams }) => __awaiter(this, void 0, void 0, function* () {
154
+ if (!isDbStore) {
155
+ translationParams.forEach(({ languageId, etag }) => (store[integrationId][crowdinId][fileId][languageId] = { etag }));
156
+ return;
157
+ }
129
158
  const translationCache = (yield storage.getFileTranslationCache({
130
159
  integrationId,
131
160
  crowdinId,
@@ -21,6 +21,7 @@ export declare enum JobClientType {
21
21
  MANUAL = "manual",
22
22
  RERUN = "rerun"
23
23
  }
24
+ export type JobStoreType = 'db' | 'in-memory';
24
25
  export interface Job {
25
26
  id: string;
26
27
  integrationId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdin/app-project-module",
3
- "version": "0.68.0",
3
+ "version": "0.68.1",
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",