@crowdin/app-project-module 1.1.0 → 1.2.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.
- package/out/index.js +1 -1
- package/out/modules/integration/handlers/integration-data.js +2 -0
- package/out/modules/integration/types.d.ts +2 -0
- package/out/modules/integration/util/cron.js +16 -2
- package/out/modules/integration/util/files.js +4 -0
- package/out/modules/integration/util/snapshot.d.ts +7 -1
- package/out/modules/integration/util/snapshot.js +15 -5
- package/out/storage/index.d.ts +1 -1
- package/out/storage/index.js +6 -6
- package/out/storage/sqlite.d.ts +28 -38
- package/out/storage/sqlite.js +534 -538
- package/package.json +6 -7
package/out/index.js
CHANGED
|
@@ -142,8 +142,8 @@ function addCrowdinEndpoints(app, clientConfig) {
|
|
|
142
142
|
if (!config.disableGlobalErrorHandling) {
|
|
143
143
|
handleUncaughtErrors();
|
|
144
144
|
}
|
|
145
|
-
storage.initialize(config);
|
|
146
145
|
logger.initialize(config);
|
|
146
|
+
storage.initialize(config);
|
|
147
147
|
cron.initialize(config);
|
|
148
148
|
// Middleware to ensure D1 migration before handling requests
|
|
149
149
|
app.use((req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -28,6 +28,8 @@ function handle(integration) {
|
|
|
28
28
|
const parsedPaginationData = paginationData ? JSON.parse(paginationData) : undefined;
|
|
29
29
|
const result = yield integration.getIntegrationFiles({
|
|
30
30
|
credentials: req.integrationCredentials,
|
|
31
|
+
client: req.crowdinApiClient,
|
|
32
|
+
projectId: req.crowdinContext.jwtPayload.context.project_id,
|
|
31
33
|
settings,
|
|
32
34
|
parentId,
|
|
33
35
|
search,
|
|
@@ -251,7 +251,13 @@ function processSyncSettings({ config, integration, period, syncSettings, }) {
|
|
|
251
251
|
const needsIntegrationSnapshot = needsSnapshotForNewFiles && syncSettings.provider !== types_1.Provider.CROWDIN;
|
|
252
252
|
const needsCrowdinSnapshot = needsSnapshotForNewFiles && syncSettings.provider === types_1.Provider.CROWDIN && currentFileSnapshot.length === 0;
|
|
253
253
|
if (needsIntegrationSnapshot) {
|
|
254
|
-
currentFileSnapshot = yield (0, snapshot_1.getIntegrationSnapshot)(
|
|
254
|
+
currentFileSnapshot = yield (0, snapshot_1.getIntegrationSnapshot)({
|
|
255
|
+
integration,
|
|
256
|
+
integrationCredentials: credentials,
|
|
257
|
+
integrationSettings: intConfig,
|
|
258
|
+
client: crowdinClient,
|
|
259
|
+
projectId: projectData.id,
|
|
260
|
+
});
|
|
255
261
|
}
|
|
256
262
|
else if (needsCrowdinSnapshot) {
|
|
257
263
|
currentFileSnapshot = yield (0, snapshot_1.getCrowdinSnapshot)(config, integration, crowdinClient, projectData.id, intConfig);
|
|
@@ -392,6 +398,8 @@ function processSyncSettings({ config, integration, period, syncSettings, }) {
|
|
|
392
398
|
try {
|
|
393
399
|
const fullTreeResult = yield integration.getIntegrationFiles({
|
|
394
400
|
credentials,
|
|
401
|
+
client: crowdinClient,
|
|
402
|
+
projectId: projectId,
|
|
395
403
|
settings: intConfig,
|
|
396
404
|
});
|
|
397
405
|
const fullTree = (0, files_1.isExtendedResultType)(fullTreeResult) ? fullTreeResult.data || [] : fullTreeResult;
|
|
@@ -432,7 +440,13 @@ function processSyncSettings({ config, integration, period, syncSettings, }) {
|
|
|
432
440
|
if (Object.keys(newFiles).length) {
|
|
433
441
|
const newSyncSettingsFields = allIntFiles.map((file) => (Object.assign(Object.assign({}, file), { schedule: true, sync: false })));
|
|
434
442
|
yield (0, storage_1.getStorage)().updateSyncSettings(JSON.stringify(newSyncSettingsFields), syncSettings.integrationId, syncSettings.crowdinId, 'schedule', syncSettings.provider);
|
|
435
|
-
const currentFileSnapshot = yield (0, snapshot_1.getIntegrationSnapshot)(
|
|
443
|
+
const currentFileSnapshot = yield (0, snapshot_1.getIntegrationSnapshot)({
|
|
444
|
+
integration,
|
|
445
|
+
integrationCredentials: credentials,
|
|
446
|
+
integrationSettings: intConfig,
|
|
447
|
+
client: crowdinClient,
|
|
448
|
+
projectId,
|
|
449
|
+
});
|
|
436
450
|
yield (0, storage_1.getStorage)().updateFilesSnapshot(JSON.stringify(currentFileSnapshot), syncSettings.integrationId, syncSettings.crowdinId, syncSettings.provider);
|
|
437
451
|
}
|
|
438
452
|
(0, logger_1.log)(`updateCrowdin task for files cron job with period [${period}] for project ${projectId} completed`);
|
|
@@ -54,6 +54,8 @@ function expandFilesTree(nodes, req, integration, job) {
|
|
|
54
54
|
try {
|
|
55
55
|
integrationData = yield integration.getIntegrationFiles({
|
|
56
56
|
credentials: req.integrationCredentials,
|
|
57
|
+
client: req.crowdinApiClient,
|
|
58
|
+
projectId: req.crowdinContext.jwtPayload.context.project_id,
|
|
57
59
|
settings: req.integrationSettings,
|
|
58
60
|
parentId: id,
|
|
59
61
|
});
|
|
@@ -164,6 +166,8 @@ function expandFilesTreeWithPagination(nodes, req, integration, job) {
|
|
|
164
166
|
}
|
|
165
167
|
const result = yield integration.getIntegrationFiles({
|
|
166
168
|
credentials: req.integrationCredentials,
|
|
169
|
+
client: req.crowdinApiClient,
|
|
170
|
+
projectId: req.crowdinContext.jwtPayload.context.project_id,
|
|
167
171
|
settings: req.integrationSettings,
|
|
168
172
|
parentId: folder.id,
|
|
169
173
|
search: '',
|
|
@@ -2,5 +2,11 @@ import Crowdin from '@crowdin/crowdin-api-client';
|
|
|
2
2
|
import { Config } from '../../../types';
|
|
3
3
|
import { IntegrationLogic, IntegrationRequest, Provider, TreeItem } from '../types';
|
|
4
4
|
export declare function getCrowdinSnapshot(config: Config, integration: IntegrationLogic, crowdinApiClient: Crowdin, projectId: number, integrationSettings: any): Promise<TreeItem[]>;
|
|
5
|
-
export declare function getIntegrationSnapshot(integration
|
|
5
|
+
export declare function getIntegrationSnapshot({ integration, integrationCredentials, integrationSettings, client, projectId, }: {
|
|
6
|
+
integration: IntegrationLogic;
|
|
7
|
+
integrationCredentials: any;
|
|
8
|
+
integrationSettings: any;
|
|
9
|
+
client?: Crowdin;
|
|
10
|
+
projectId?: number;
|
|
11
|
+
}): Promise<TreeItem[]>;
|
|
6
12
|
export declare function createOrUpdateFileSnapshot(config: Config, integration: IntegrationLogic, req: IntegrationRequest, provider: Provider): Promise<void>;
|
|
@@ -40,12 +40,14 @@ function getTreeItems(integrationData) {
|
|
|
40
40
|
}
|
|
41
41
|
return files;
|
|
42
42
|
}
|
|
43
|
-
function getOneLevelFetchingFiles(integration, integrationCredentials, integrationSettings, parentFiles) {
|
|
43
|
+
function getOneLevelFetchingFiles(integration, integrationCredentials, integrationSettings, parentFiles, client, projectId) {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
45
|
for (const file of parentFiles) {
|
|
46
46
|
if (!file.type) {
|
|
47
47
|
let childs = yield integration.getIntegrationFiles({
|
|
48
48
|
credentials: integrationCredentials,
|
|
49
|
+
client,
|
|
50
|
+
projectId,
|
|
49
51
|
settings: integrationSettings,
|
|
50
52
|
parentId: file.id,
|
|
51
53
|
search: '',
|
|
@@ -53,7 +55,7 @@ function getOneLevelFetchingFiles(integration, integrationCredentials, integrati
|
|
|
53
55
|
});
|
|
54
56
|
childs = getTreeItems(childs);
|
|
55
57
|
if (childs.length > 0) {
|
|
56
|
-
const childFiles = yield getOneLevelFetchingFiles(integration, integrationCredentials, integrationSettings, childs);
|
|
58
|
+
const childFiles = yield getOneLevelFetchingFiles(integration, integrationCredentials, integrationSettings, childs, client, projectId);
|
|
57
59
|
parentFiles = [...parentFiles, ...childFiles];
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -61,20 +63,22 @@ function getOneLevelFetchingFiles(integration, integrationCredentials, integrati
|
|
|
61
63
|
return parentFiles;
|
|
62
64
|
});
|
|
63
65
|
}
|
|
64
|
-
function getIntegrationSnapshot(integration, integrationCredentials, integrationSettings) {
|
|
66
|
+
function getIntegrationSnapshot({ integration, integrationCredentials, integrationSettings, client, projectId, }) {
|
|
65
67
|
var _a;
|
|
66
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
69
|
let files = [];
|
|
68
70
|
let integrationData = [];
|
|
69
71
|
integrationData = yield integration.getIntegrationFiles({
|
|
70
72
|
credentials: integrationCredentials,
|
|
73
|
+
client,
|
|
74
|
+
projectId,
|
|
71
75
|
settings: integrationSettings,
|
|
72
76
|
search: '',
|
|
73
77
|
page: 0,
|
|
74
78
|
});
|
|
75
79
|
files = getTreeItems(integrationData);
|
|
76
80
|
if (integration.integrationOneLevelFetching) {
|
|
77
|
-
files = yield getOneLevelFetchingFiles(integration, integrationCredentials, integrationSettings, files);
|
|
81
|
+
files = yield getOneLevelFetchingFiles(integration, integrationCredentials, integrationSettings, files, client, projectId);
|
|
78
82
|
}
|
|
79
83
|
if ((integrationSettings === null || integrationSettings === void 0 ? void 0 : integrationSettings.skipIntegrationNodesToggle) === true ||
|
|
80
84
|
((integrationSettings === null || integrationSettings === void 0 ? void 0 : integrationSettings.skipIntegrationNodesToggle) === null && ((_a = integration.skipIntegrationNodesToggle) === null || _a === void 0 ? void 0 : _a.value))) {
|
|
@@ -94,7 +98,13 @@ function createOrUpdateFileSnapshot(config, integration, req, provider) {
|
|
|
94
98
|
files = yield getCrowdinSnapshot(config, integration, req.crowdinApiClient, req.crowdinContext.jwtPayload.context.project_id, req.integrationSettings);
|
|
95
99
|
}
|
|
96
100
|
if (provider === types_1.Provider.INTEGRATION) {
|
|
97
|
-
files = yield getIntegrationSnapshot(
|
|
101
|
+
files = yield getIntegrationSnapshot({
|
|
102
|
+
integration,
|
|
103
|
+
integrationCredentials: req.integrationCredentials,
|
|
104
|
+
integrationSettings: req.integrationSettings,
|
|
105
|
+
client: req.crowdinApiClient,
|
|
106
|
+
projectId: req.crowdinContext.jwtPayload.context.project_id,
|
|
107
|
+
});
|
|
98
108
|
}
|
|
99
109
|
if (existingSnapshot) {
|
|
100
110
|
req.logInfo(`Updating file snapshot for provider ${provider} ${JSON.stringify(files, null, 2)}`);
|
package/out/storage/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks, Provider } from '../modules/integration/types';
|
|
2
|
+
import { CreateJobParams, GetActiveJobsParams, GetAllJobsParams, GetFileTranslationCache, GetFileTranslationCacheByLanguageParams, GetJobParams, GetUnsyncedFiles, IntegrationSyncedData, Job, TranslationCache, UnsyncedFiles, UpdateJobParams, UpdateTranslationCacheParams } from '../modules/integration/util/types';
|
|
2
3
|
import { Config, CrowdinCredentials, UnauthorizedConfig } from '../types';
|
|
3
|
-
import { CreateJobParams, GetActiveJobsParams, GetJobParams, GetFileTranslationCacheByLanguageParams, Job, TranslationCache, UpdateJobParams, UpdateTranslationCacheParams, GetFileTranslationCache, UnsyncedFiles, GetUnsyncedFiles, IntegrationSyncedData, GetAllJobsParams } from '../modules/integration/util/types';
|
|
4
4
|
import { UserErrors } from './types';
|
|
5
5
|
export declare const TABLES: {
|
|
6
6
|
crowdin_credentials: string;
|
package/out/storage/index.js
CHANGED
|
@@ -36,16 +36,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.getStorage = exports.initialize = exports.TABLES = void 0;
|
|
39
|
+
const child_process_1 = require("child_process");
|
|
40
|
+
const fs_1 = __importDefault(require("fs"));
|
|
41
|
+
const util = __importStar(require("node:util"));
|
|
42
|
+
const path_1 = __importStar(require("path"));
|
|
39
43
|
const types_1 = require("../types");
|
|
40
44
|
const logger_1 = require("../util/logger");
|
|
41
|
-
const mysql_1 = require("./mysql");
|
|
42
|
-
const postgre_1 = require("./postgre");
|
|
43
45
|
const sqlite_1 = require("./sqlite");
|
|
44
46
|
const d1_1 = require("./d1");
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const child_process_1 = require("child_process");
|
|
48
|
-
const util = __importStar(require("node:util"));
|
|
47
|
+
const mysql_1 = require("./mysql");
|
|
48
|
+
const postgre_1 = require("./postgre");
|
|
49
49
|
exports.TABLES = {
|
|
50
50
|
crowdin_credentials: 'crowdin_credentials',
|
|
51
51
|
integration_credentials: 'integration_credentials',
|
package/out/storage/sqlite.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Storage } from '.';
|
|
2
|
-
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks } from '../modules/integration/types';
|
|
2
|
+
import { IntegrationConfig, IntegrationCredentials, IntegrationFilesSnapshot, IntegrationSyncSettings, IntegrationWebhooks, Provider } from '../modules/integration/types';
|
|
3
3
|
import { CreateJobParams, GetActiveJobsParams, GetAllJobsParams, GetFileTranslationCache, GetFileTranslationCacheByLanguageParams, GetJobParams, GetUnsyncedFiles, IntegrationSyncedData, Job, TranslationCache, UnsyncedFiles, UpdateJobParams, UpdateTranslationCacheParams } from '../modules/integration/util/types';
|
|
4
4
|
import { CrowdinCredentials } from '../types';
|
|
5
5
|
import { UserErrors } from './types';
|
|
@@ -7,11 +7,8 @@ export interface SQLiteStorageConfig {
|
|
|
7
7
|
dbFolder: string;
|
|
8
8
|
}
|
|
9
9
|
export declare class SQLiteStorage implements Storage {
|
|
10
|
-
private db;
|
|
11
|
-
private _res?;
|
|
12
|
-
private _rej?;
|
|
13
|
-
private dbPromise;
|
|
14
10
|
private config;
|
|
11
|
+
private db;
|
|
15
12
|
tables: {
|
|
16
13
|
crowdin_credentials: string;
|
|
17
14
|
integration_credentials: string;
|
|
@@ -27,13 +24,6 @@ export declare class SQLiteStorage implements Storage {
|
|
|
27
24
|
synced_data: string;
|
|
28
25
|
};
|
|
29
26
|
constructor(config: SQLiteStorageConfig);
|
|
30
|
-
private _run;
|
|
31
|
-
private run;
|
|
32
|
-
private get;
|
|
33
|
-
private each;
|
|
34
|
-
private removeColumns;
|
|
35
|
-
private addColumns;
|
|
36
|
-
private addColumn;
|
|
37
27
|
migrate(): Promise<void>;
|
|
38
28
|
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
39
29
|
updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
@@ -49,43 +39,43 @@ export declare class SQLiteStorage implements Storage {
|
|
|
49
39
|
deleteAllIntegrationCredentials(crowdinId: string): Promise<void>;
|
|
50
40
|
saveMetadata(id: string, metadata: any, crowdinId: string): Promise<void>;
|
|
51
41
|
updateMetadata(id: string, metadata: any, crowdinId: string): Promise<void>;
|
|
52
|
-
getMetadata(id: string): Promise<any>;
|
|
53
|
-
getAllMetadata(): Promise<any[]>;
|
|
42
|
+
getMetadata(id: string): Promise<any | undefined>;
|
|
43
|
+
getAllMetadata(): Promise<any[] | undefined>;
|
|
54
44
|
deleteMetadata(id: string): Promise<void>;
|
|
55
|
-
getSyncSettingsByProvider(integrationId: string, provider:
|
|
45
|
+
getSyncSettingsByProvider(integrationId: string, provider: Provider): Promise<IntegrationSyncSettings | undefined>;
|
|
56
46
|
getSyncSettingsBySchedule(type: string, schedule: string): Promise<IntegrationSyncSettings[]>;
|
|
57
|
-
saveSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider:
|
|
58
|
-
updateSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider:
|
|
59
|
-
getSyncSettings(integrationId: string, crowdinId: string, type: string, provider:
|
|
60
|
-
saveFilesSnapshot(files: any, integrationId: string, crowdinId: string, provider:
|
|
61
|
-
updateFilesSnapshot(files: any, integrationId: string, crowdinId: string, provider:
|
|
62
|
-
getFilesSnapshot(integrationId: string, crowdinId: string, provider:
|
|
63
|
-
getAllWebhooks(integrationId: string, crowdinId: string, provider:
|
|
64
|
-
getWebhooks(fileId: string, integrationId: string, crowdinId: string, provider:
|
|
65
|
-
saveWebhooks(fileId: string, integrationId: string, crowdinId: string, provider:
|
|
66
|
-
deleteWebhooks(fileIds: any[], integrationId: string, crowdinId: string, provider:
|
|
67
|
-
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[]>;
|
|
47
|
+
saveSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: Provider): Promise<void>;
|
|
48
|
+
updateSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: Provider): Promise<void>;
|
|
49
|
+
getSyncSettings(integrationId: string, crowdinId: string, type: string, provider: Provider): Promise<IntegrationSyncSettings | undefined>;
|
|
50
|
+
saveFilesSnapshot(files: any, integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
|
|
51
|
+
updateFilesSnapshot(files: any, integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
|
|
52
|
+
getFilesSnapshot(integrationId: string, crowdinId: string, provider: Provider): Promise<IntegrationFilesSnapshot | undefined>;
|
|
53
|
+
getAllWebhooks(integrationId: string, crowdinId: string, provider: Provider): Promise<IntegrationWebhooks[] | undefined>;
|
|
54
|
+
getWebhooks(fileId: string, integrationId: string, crowdinId: string, provider: Provider): Promise<IntegrationWebhooks | undefined>;
|
|
55
|
+
saveWebhooks(fileId: string, integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
|
|
56
|
+
deleteWebhooks(fileIds: any[], integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
|
|
57
|
+
getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[] | undefined>;
|
|
68
58
|
saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
69
|
-
deleteUserErrors(
|
|
70
|
-
deleteAllUsersErrorsOlderThan(
|
|
59
|
+
deleteUserErrors(date: string, crowdinId: string, integrationId?: string): Promise<void>;
|
|
60
|
+
deleteAllUsersErrorsOlderThan(date: string): Promise<void>;
|
|
71
61
|
saveIntegrationConfig(integrationId: string, crowdinId: string, config: any): Promise<void>;
|
|
72
62
|
getAllIntegrationConfigs(crowdinId: string): Promise<IntegrationConfig[]>;
|
|
73
63
|
getIntegrationConfig(integrationId: string): Promise<IntegrationConfig | undefined>;
|
|
74
64
|
updateIntegrationConfig(integrationId: string, config: any): Promise<void>;
|
|
75
|
-
createJob(
|
|
65
|
+
createJob(params: CreateJobParams): Promise<string>;
|
|
76
66
|
updateJob({ id, progress, status, info, data, attempt, errors, processedEntities, }: UpdateJobParams): Promise<void>;
|
|
77
|
-
getJob(
|
|
78
|
-
getActiveJobs(
|
|
67
|
+
getJob(params: GetJobParams): Promise<Job | undefined>;
|
|
68
|
+
getActiveJobs(params: GetActiveJobsParams): Promise<Job[] | undefined>;
|
|
79
69
|
deleteFinishedJobs(): Promise<void>;
|
|
80
70
|
getAllInProgressJobs(): Promise<Job[] | undefined>;
|
|
81
71
|
getAllJobs({ integrationId, crowdinId, limit, offset }: GetAllJobsParams): Promise<Job[] | undefined>;
|
|
82
|
-
saveTranslationCache(
|
|
83
|
-
getFileTranslationCache(
|
|
84
|
-
getFileTranslationCacheByLanguage(
|
|
85
|
-
updateTranslationCache(
|
|
86
|
-
saveUnsyncedFiles(
|
|
87
|
-
|
|
88
|
-
|
|
72
|
+
saveTranslationCache(params: TranslationCache): Promise<void>;
|
|
73
|
+
getFileTranslationCache(params: GetFileTranslationCache): Promise<TranslationCache[] | undefined>;
|
|
74
|
+
getFileTranslationCacheByLanguage(params: GetFileTranslationCacheByLanguageParams): Promise<TranslationCache | undefined>;
|
|
75
|
+
updateTranslationCache(params: UpdateTranslationCacheParams): Promise<void>;
|
|
76
|
+
saveUnsyncedFiles(params: UnsyncedFiles): Promise<void>;
|
|
77
|
+
getUnsyncedFiles(params: GetUnsyncedFiles): Promise<UnsyncedFiles | undefined>;
|
|
78
|
+
updateUnsyncedFiles(params: UnsyncedFiles): Promise<void>;
|
|
89
79
|
registerCustomTable(tableName: string, schema: Record<string, string>): Promise<void>;
|
|
90
80
|
insertRecord(tableName: string, data: Record<string, any>): Promise<void>;
|
|
91
81
|
selectRecords(tableName: string, options?: {
|