@crowdin/app-project-module 1.15.1 → 2.0.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.
Files changed (101) hide show
  1. package/out/index.js +8 -15
  2. package/out/middlewares/auto-credentials-masker.js +5 -2
  3. package/out/middlewares/crowdin-client.d.ts +1 -1
  4. package/out/middlewares/crowdin-client.js +1 -1
  5. package/out/middlewares/export.d.ts +2 -2
  6. package/out/middlewares/export.js +4 -35
  7. package/out/middlewares/json-response.d.ts +1 -1
  8. package/out/middlewares/json-response.js +1 -1
  9. package/out/modules/ai-prompt-provider/index.js +6 -6
  10. package/out/modules/ai-provider/index.js +7 -7
  11. package/out/modules/ai-provider/types.d.ts +10 -0
  12. package/out/modules/ai-provider/types.js +12 -0
  13. package/out/modules/ai-provider/util/index.d.ts +0 -10
  14. package/out/modules/ai-provider/util/index.js +2 -13
  15. package/out/modules/ai-request-processors/index.js +4 -4
  16. package/out/modules/api/api.js +18 -18
  17. package/out/modules/auth-guard/index.js +4 -5
  18. package/out/modules/automation-action/index.js +4 -6
  19. package/out/modules/context-menu/index.js +4 -13
  20. package/out/modules/custom-mt/index.js +4 -4
  21. package/out/modules/custom-spell-check/index.js +11 -11
  22. package/out/modules/editor-right-panel/index.js +1 -1
  23. package/out/modules/external-qa-check/index.js +7 -7
  24. package/out/modules/file-processing/index.js +14 -14
  25. package/out/modules/integration/index.js +26 -26
  26. package/out/modules/integration/types.d.ts +4 -4
  27. package/out/modules/integration/util/files.js +1 -1
  28. package/out/modules/integration/util/types.d.ts +1 -1
  29. package/out/modules/manifest.js +70 -281
  30. package/out/modules/modal/index.js +4 -13
  31. package/out/modules/organization-menu/index.js +1 -1
  32. package/out/modules/organization-settings-menu/index.js +1 -1
  33. package/out/modules/profile-resources-menu/index.js +1 -1
  34. package/out/modules/profile-settings-menu/index.js +1 -1
  35. package/out/modules/project-menu/index.js +1 -1
  36. package/out/modules/project-menu-crowdsource/index.js +1 -1
  37. package/out/modules/project-reports/index.js +1 -1
  38. package/out/modules/project-tools/index.js +1 -1
  39. package/out/modules/webhooks/index.js +3 -6
  40. package/out/modules/workflow-step-type/index.js +6 -6
  41. package/out/static/ui/form.bundle.js +7947 -6975
  42. package/out/static/ui/form.bundle.js.map +1 -1
  43. package/out/storage/drizzle/d1/index.d.ts +7 -0
  44. package/out/storage/drizzle/d1/index.js +48 -0
  45. package/out/storage/drizzle/d1/migrations/init.d.ts +2 -0
  46. package/out/storage/drizzle/d1/migrations/init.js +122 -0
  47. package/out/storage/drizzle/d1/types.d.ts +13 -0
  48. package/out/storage/drizzle/d1/types.js +38 -0
  49. package/out/storage/{sqlite.d.ts → drizzle/index.d.ts} +37 -58
  50. package/out/storage/drizzle/index.js +939 -0
  51. package/out/storage/drizzle/postgresql/config.d.ts +5 -0
  52. package/out/storage/drizzle/postgresql/config.js +11 -0
  53. package/out/storage/drizzle/postgresql/index.d.ts +14 -0
  54. package/out/storage/drizzle/postgresql/index.js +144 -0
  55. package/out/storage/drizzle/postgresql/migrations/0000_init.sql +113 -0
  56. package/out/storage/drizzle/postgresql/migrations/0001_init_indexes.sql +28 -0
  57. package/out/storage/drizzle/postgresql/migrations/meta/0000_snapshot.json +646 -0
  58. package/out/storage/drizzle/postgresql/migrations/meta/0001_snapshot.json +646 -0
  59. package/out/storage/drizzle/postgresql/migrations/meta/_journal.json +20 -0
  60. package/out/storage/drizzle/postgresql/schema.d.ts +1410 -0
  61. package/out/storage/drizzle/postgresql/schema.js +106 -0
  62. package/out/storage/drizzle/sqlite/config.d.ts +5 -0
  63. package/out/storage/drizzle/sqlite/config.js +11 -0
  64. package/out/storage/drizzle/sqlite/index.d.ts +8 -0
  65. package/out/storage/drizzle/sqlite/index.js +63 -0
  66. package/out/storage/drizzle/sqlite/migrations/0000_init.sql +113 -0
  67. package/out/storage/drizzle/sqlite/migrations/meta/0000_snapshot.json +687 -0
  68. package/out/storage/drizzle/sqlite/migrations/meta/_journal.json +13 -0
  69. package/out/storage/drizzle/sqlite/schema.d.ts +1544 -0
  70. package/out/storage/drizzle/sqlite/schema.js +106 -0
  71. package/out/storage/index.d.ts +2 -88
  72. package/out/storage/index.js +12 -128
  73. package/out/storage/internal/backup.d.ts +3 -0
  74. package/out/storage/internal/backup.js +94 -0
  75. package/out/storage/types.d.ts +66 -0
  76. package/out/types.d.ts +43 -47
  77. package/out/util/credentials-masker.js +2 -2
  78. package/out/util/export.d.ts +1 -0
  79. package/out/util/export.js +2 -1
  80. package/out/util/index.d.ts +2 -1
  81. package/out/util/index.js +12 -9
  82. package/out/util/normalize-module.d.ts +0 -1
  83. package/out/util/normalize-module.js +0 -4
  84. package/package.json +23 -23
  85. package/out/modules/ai-tools/handlers/tool-calls.d.ts +0 -4
  86. package/out/modules/ai-tools/handlers/tool-calls.js +0 -52
  87. package/out/modules/ai-tools/index.d.ts +0 -10
  88. package/out/modules/ai-tools/index.js +0 -46
  89. package/out/modules/ai-tools/types.d.ts +0 -63
  90. package/out/modules/ai-tools/types.js +0 -2
  91. package/out/modules/ai-tools/util/index.d.ts +0 -5
  92. package/out/modules/ai-tools/util/index.js +0 -24
  93. package/out/storage/d1.d.ts +0 -107
  94. package/out/storage/d1.js +0 -837
  95. package/out/storage/export.d.ts +0 -1
  96. package/out/storage/export.js +0 -2
  97. package/out/storage/mysql.d.ts +0 -109
  98. package/out/storage/mysql.js +0 -984
  99. package/out/storage/postgre.d.ts +0 -124
  100. package/out/storage/postgre.js +0 -1027
  101. package/out/storage/sqlite.js +0 -786
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.syncedData = exports.unsyncedFiles = exports.translationFileCache = exports.job = exports.integrationSettings = exports.userErrors = exports.webhooks = exports.filesSnapshot = exports.appMetadata = exports.syncSettings = exports.integrationCredentials = exports.crowdinCredentials = void 0;
4
+ const sqlite_core_1 = require("drizzle-orm/sqlite-core");
5
+ exports.crowdinCredentials = (0, sqlite_core_1.sqliteTable)('crowdin_credentials', {
6
+ id: (0, sqlite_core_1.text)('id').primaryKey(),
7
+ app_secret: (0, sqlite_core_1.text)('app_secret'),
8
+ domain: (0, sqlite_core_1.text)('domain'),
9
+ user_id: (0, sqlite_core_1.text)('user_id'),
10
+ agent_id: (0, sqlite_core_1.text)('agent_id'),
11
+ organization_id: (0, sqlite_core_1.text)('organization_id'),
12
+ base_url: (0, sqlite_core_1.text)('base_url'),
13
+ access_token: (0, sqlite_core_1.text)('access_token').notNull(),
14
+ refresh_token: (0, sqlite_core_1.text)('refresh_token').notNull(),
15
+ expire: (0, sqlite_core_1.text)('expire').notNull(),
16
+ type: (0, sqlite_core_1.text)('type').notNull(),
17
+ });
18
+ exports.integrationCredentials = (0, sqlite_core_1.sqliteTable)('integration_credentials', {
19
+ id: (0, sqlite_core_1.text)('id').primaryKey(),
20
+ credentials: (0, sqlite_core_1.text)('credentials').notNull(),
21
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
22
+ managers: (0, sqlite_core_1.text)('managers'),
23
+ });
24
+ exports.syncSettings = (0, sqlite_core_1.sqliteTable)('sync_settings', {
25
+ id: (0, sqlite_core_1.integer)('id').primaryKey({ autoIncrement: true }),
26
+ files: (0, sqlite_core_1.text)('files'),
27
+ integration_id: (0, sqlite_core_1.text)('integration_id').notNull(),
28
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
29
+ type: (0, sqlite_core_1.text)('type').notNull(),
30
+ provider: (0, sqlite_core_1.text)('provider').notNull(),
31
+ });
32
+ exports.appMetadata = (0, sqlite_core_1.sqliteTable)('app_metadata', {
33
+ id: (0, sqlite_core_1.text)('id').primaryKey(),
34
+ data: (0, sqlite_core_1.text)('data'),
35
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id'),
36
+ });
37
+ exports.filesSnapshot = (0, sqlite_core_1.sqliteTable)('files_snapshot', {
38
+ id: (0, sqlite_core_1.integer)('id').primaryKey({ autoIncrement: true }),
39
+ integration_id: (0, sqlite_core_1.text)('integration_id').notNull(),
40
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
41
+ files: (0, sqlite_core_1.text)('files'),
42
+ provider: (0, sqlite_core_1.text)('provider').notNull(),
43
+ });
44
+ exports.webhooks = (0, sqlite_core_1.sqliteTable)('webhooks', {
45
+ id: (0, sqlite_core_1.integer)('id').primaryKey({ autoIncrement: true }),
46
+ file_id: (0, sqlite_core_1.text)('file_id').notNull(),
47
+ integration_id: (0, sqlite_core_1.text)('integration_id').notNull(),
48
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
49
+ provider: (0, sqlite_core_1.text)('provider').notNull(),
50
+ });
51
+ exports.userErrors = (0, sqlite_core_1.sqliteTable)('user_errors', {
52
+ id: (0, sqlite_core_1.integer)('id').primaryKey({ autoIncrement: true }),
53
+ action: (0, sqlite_core_1.text)('action').notNull(),
54
+ message: (0, sqlite_core_1.text)('message').notNull(),
55
+ data: (0, sqlite_core_1.text)('data'),
56
+ created_at: (0, sqlite_core_1.text)('created_at').notNull(),
57
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
58
+ integration_id: (0, sqlite_core_1.text)('integration_id'),
59
+ });
60
+ exports.integrationSettings = (0, sqlite_core_1.sqliteTable)('integration_settings', {
61
+ id: (0, sqlite_core_1.integer)('id').primaryKey({ autoIncrement: true }),
62
+ integration_id: (0, sqlite_core_1.text)('integration_id').notNull(),
63
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
64
+ config: (0, sqlite_core_1.text)('config'),
65
+ });
66
+ exports.job = (0, sqlite_core_1.sqliteTable)('job', {
67
+ id: (0, sqlite_core_1.text)('id').primaryKey(),
68
+ integration_id: (0, sqlite_core_1.text)('integration_id').notNull(),
69
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
70
+ type: (0, sqlite_core_1.text)('type').notNull(),
71
+ title: (0, sqlite_core_1.text)('title'),
72
+ progress: (0, sqlite_core_1.integer)('progress').notNull().default(0),
73
+ status: (0, sqlite_core_1.text)('status').notNull().default('CREATED'),
74
+ payload: (0, sqlite_core_1.text)('payload'),
75
+ info: (0, sqlite_core_1.text)('info'),
76
+ data: (0, sqlite_core_1.text)('data'),
77
+ attempt: (0, sqlite_core_1.integer)('attempt').notNull().default(0),
78
+ errors: (0, sqlite_core_1.text)('errors'),
79
+ processed_entities: (0, sqlite_core_1.text)('processed_entities'),
80
+ initiated_by: (0, sqlite_core_1.text)('initiated_by'),
81
+ created_at: (0, sqlite_core_1.text)('created_at').notNull(),
82
+ updated_at: (0, sqlite_core_1.text)('updated_at'),
83
+ finished_at: (0, sqlite_core_1.text)('finished_at'),
84
+ });
85
+ exports.translationFileCache = (0, sqlite_core_1.sqliteTable)('translation_file_cache', {
86
+ id: (0, sqlite_core_1.integer)('id').primaryKey({ autoIncrement: true }),
87
+ integration_id: (0, sqlite_core_1.text)('integration_id').notNull(),
88
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
89
+ file_id: (0, sqlite_core_1.integer)('file_id').notNull(),
90
+ language_id: (0, sqlite_core_1.text)('language_id').notNull(),
91
+ etag: (0, sqlite_core_1.text)('etag'),
92
+ });
93
+ exports.unsyncedFiles = (0, sqlite_core_1.sqliteTable)('unsynced_files', {
94
+ id: (0, sqlite_core_1.integer)('id').primaryKey({ autoIncrement: true }),
95
+ integration_id: (0, sqlite_core_1.text)('integration_id').notNull(),
96
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
97
+ files: (0, sqlite_core_1.text)('files'),
98
+ });
99
+ exports.syncedData = (0, sqlite_core_1.sqliteTable)('synced_data', {
100
+ id: (0, sqlite_core_1.integer)('id').primaryKey({ autoIncrement: true }),
101
+ files: (0, sqlite_core_1.text)('files'),
102
+ integration_id: (0, sqlite_core_1.text)('integration_id').notNull(),
103
+ crowdin_id: (0, sqlite_core_1.text)('crowdin_id').notNull(),
104
+ type: (0, sqlite_core_1.text)('type').notNull(),
105
+ updated_at: (0, sqlite_core_1.text)('updated_at'),
106
+ });
@@ -1,90 +1,4 @@
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';
3
- import { Config, CrowdinCredentials, UnauthorizedConfig } from '../types';
4
- import { UserErrors } from './types';
5
- export declare const TABLES: {
6
- crowdin_credentials: string;
7
- integration_credentials: string;
8
- sync_settings: string;
9
- app_metadata: string;
10
- files_snapshot: string;
11
- webhooks: string;
12
- user_errors: string;
13
- integration_settings: string;
14
- job: string;
15
- translation_file_cache: string;
16
- unsynced_files: string;
17
- synced_data: string;
18
- };
19
- export interface Storage {
20
- tables: typeof TABLES;
21
- migrate(skipOnboarding?: boolean): Promise<void>;
22
- saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
23
- updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
24
- getCrowdinCredentials(id: string): Promise<CrowdinCredentials | undefined>;
25
- getAllCrowdinCredentials(): Promise<CrowdinCredentials[]>;
26
- deleteCrowdinCredentials(id: string): Promise<void>;
27
- saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
28
- updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
29
- updateIntegrationManagers(id: string, managers: any): Promise<void>;
30
- getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
31
- getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
32
- deleteIntegrationCredentials(id: string): Promise<void>;
33
- deleteAllIntegrationCredentials(crowdinId: string): Promise<void>;
34
- saveMetadata(id: string, metadata: any, crowdinId: string): Promise<void>;
35
- updateMetadata(id: string, metadata: any, crowdinId: string): Promise<void>;
36
- getMetadata(id: string): Promise<any | undefined>;
37
- getAllMetadata(): Promise<any[] | undefined>;
38
- deleteMetadata(id: string): Promise<void>;
39
- getSyncSettingsByProvider(integrationId: string, provider: Provider): Promise<IntegrationSyncSettings | undefined>;
40
- getSyncSettingsBySchedule(type: string, schedule: string): Promise<IntegrationSyncSettings[]>;
41
- saveSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: Provider): Promise<void>;
42
- updateSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: Provider): Promise<void>;
43
- getSyncSettings(integrationId: string, crowdinId: string, type: string, provider: Provider): Promise<IntegrationSyncSettings | undefined>;
44
- saveFilesSnapshot(files: any, integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
45
- updateFilesSnapshot(files: any, integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
46
- getFilesSnapshot(integrationId: string, crowdinId: string, provider: Provider): Promise<IntegrationFilesSnapshot | undefined>;
47
- getAllWebhooks(integrationId: string, crowdinId: string, provider: Provider): Promise<IntegrationWebhooks[] | undefined>;
48
- getWebhooks(fileId: string, integrationId: string, crowdinId: string, provider: Provider): Promise<IntegrationWebhooks | undefined>;
49
- saveWebhooks(fileId: string, integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
50
- deleteWebhooks(fileIds: any[], integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
51
- getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[] | undefined>;
52
- saveUserError(action: string, message: string, data: any, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
53
- deleteUserErrors(date: string, crowdinId: string, integrationId?: string): Promise<void>;
54
- deleteAllUsersErrorsOlderThan(date: string): Promise<void>;
55
- saveIntegrationConfig(integrationId: string, crowdinId: string, config: any): Promise<void>;
56
- getAllIntegrationConfigs(crowdinId: string): Promise<IntegrationConfig[]>;
57
- getIntegrationConfig(integrationId: string): Promise<IntegrationConfig | undefined>;
58
- updateIntegrationConfig(integrationId: string, config: any): Promise<void>;
59
- createJob(params: CreateJobParams): Promise<string>;
60
- updateJob(params: UpdateJobParams): Promise<void>;
61
- getJob(params: GetJobParams): Promise<Job | undefined>;
62
- getActiveJobs(params: GetActiveJobsParams): Promise<Job[] | undefined>;
63
- deleteFinishedJobs(): Promise<void>;
64
- getAllInProgressJobs(): Promise<Job[] | undefined>;
65
- getAllJobs(params: GetAllJobsParams): Promise<Job[] | undefined>;
66
- saveTranslationCache(params: TranslationCache): Promise<void>;
67
- getFileTranslationCache(params: GetFileTranslationCache): Promise<TranslationCache[] | undefined>;
68
- getFileTranslationCacheByLanguage(params: GetFileTranslationCacheByLanguageParams): Promise<TranslationCache | undefined>;
69
- updateTranslationCache(params: UpdateTranslationCacheParams): Promise<void>;
70
- saveUnsyncedFiles(params: UnsyncedFiles): Promise<void>;
71
- getUnsyncedFiles(params: GetUnsyncedFiles): Promise<UnsyncedFiles | undefined>;
72
- updateUnsyncedFiles(params: UnsyncedFiles): Promise<void>;
73
- registerCustomTable(tableName: string, schema: Record<string, string>): Promise<void>;
74
- insertRecord(tableName: string, data: Record<string, any>): Promise<void>;
75
- selectRecords(tableName: string, options?: {
76
- columns?: string[];
77
- whereClause?: string;
78
- orderBy?: string;
79
- limit?: number;
80
- offset?: number;
81
- distinct?: boolean;
82
- }, params?: any[]): Promise<any[]>;
83
- updateRecord(tableName: string, data: Record<string, any>, whereClause: string, params?: any[]): Promise<void>;
84
- deleteRecord(tableName: string, whereClause: string, params?: any[]): Promise<void>;
85
- saveSyncedData(files: any, integrationId: string, crowdinId: string, type: string): Promise<void>;
86
- updateSyncedData(files: any, integrationId: string, crowdinId: string, type: string): Promise<void>;
87
- getSyncedData(integrationId: string, crowdinId: string, type: string): Promise<IntegrationSyncedData | undefined>;
88
- }
1
+ import { Config, UnauthorizedConfig } from '../types';
2
+ import { Storage } from './types';
89
3
  export declare function initialize(config: Config | UnauthorizedConfig): Promise<void>;
90
4
  export declare function getStorage(): Storage;
@@ -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) {
@@ -41,72 +8,35 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
41
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
42
9
  });
43
10
  };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
11
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.TABLES = void 0;
49
12
  exports.initialize = initialize;
50
13
  exports.getStorage = getStorage;
51
- const child_process_1 = require("child_process");
52
- const fs_1 = __importDefault(require("fs"));
53
- const util = __importStar(require("node:util"));
54
- const path_1 = __importStar(require("path"));
55
- const types_1 = require("../types");
56
14
  const logger_1 = require("../util/logger");
57
- const sqlite_1 = require("./sqlite");
58
- const d1_1 = require("./d1");
59
- const mysql_1 = require("./mysql");
60
- const postgre_1 = require("./postgre");
61
- exports.TABLES = {
62
- crowdin_credentials: 'crowdin_credentials',
63
- integration_credentials: 'integration_credentials',
64
- sync_settings: 'sync_settings',
65
- app_metadata: 'app_metadata',
66
- files_snapshot: 'files_snapshot',
67
- webhooks: 'webhooks',
68
- user_errors: 'user_errors',
69
- integration_settings: 'integration_settings',
70
- job: 'job',
71
- translation_file_cache: 'translation_file_cache',
72
- unsynced_files: 'unsynced_files',
73
- synced_data: 'synced_data',
74
- };
15
+ const drizzle_1 = require("./drizzle");
16
+ const backup_1 = require("./internal/backup");
75
17
  let storage;
76
18
  function initialize(config) {
77
19
  return __awaiter(this, void 0, void 0, function* () {
78
20
  if (config.d1Config) {
79
21
  (0, logger_1.log)('Using Cloudflare D1 database');
80
- storage = new d1_1.D1Storage(config.d1Config);
81
22
  // Skip migration for D1 - it will be done lazily on first request
23
+ storage = new drizzle_1.DrizzleStorage({ config, type: 'd1', delayedMigration: true });
82
24
  return;
83
25
  }
84
- else if (config.postgreConfig) {
26
+ if (config.postgreConfig) {
85
27
  (0, logger_1.log)('Using PostgreSQL database');
86
- let dumpDirectory = null;
87
28
  if (config.migrateToPostgreFromSQLite) {
88
- dumpDirectory = config.dbFolder;
89
- createDumpForMigration(config);
90
- }
91
- storage = new postgre_1.PostgreStorage(config, dumpDirectory);
92
- }
93
- else if (config.mysqlConfig) {
94
- (0, logger_1.log)('Using MySQL database');
95
- storage = new mysql_1.MySQLStorage(config.mysqlConfig);
96
- }
97
- else {
98
- (0, logger_1.log)('Using SQLite database');
99
- if (config.migrateToPostgreFromSQLite === false) {
100
- (0, logger_1.log)('Try to get SQLite file from backup');
101
- getSqLiteFileFromBackup(config);
29
+ (0, backup_1.createDumpForMigration)(config);
102
30
  }
103
- storage = new sqlite_1.SQLiteStorage({ dbFolder: config.dbFolder });
31
+ storage = new drizzle_1.DrizzleStorage({ config, type: 'postgresql' });
32
+ return;
104
33
  }
105
- const skipOnboarding = !!process.env.SKIP_MIGRATIONS;
106
- if (skipOnboarding) {
107
- (0, logger_1.log)('Skipping database migrations (SKIP_MIGRATIONS is set)');
34
+ (0, logger_1.log)('Using SQLite database');
35
+ if (config.migrateToPostgreFromSQLite === false) {
36
+ (0, logger_1.log)('Try to get SQLite file from backup');
37
+ (0, backup_1.getSqLiteFileFromBackup)(config);
108
38
  }
109
- yield storage.migrate(skipOnboarding);
39
+ storage = new drizzle_1.DrizzleStorage({ config, type: 'sqlite' });
110
40
  });
111
41
  }
112
42
  function getStorage() {
@@ -115,49 +45,3 @@ function getStorage() {
115
45
  }
116
46
  return storage;
117
47
  }
118
- function createDumpForMigration(config) {
119
- const sqliteFilePath = (0, path_1.join)(config.dbFolder, types_1.storageFiles.SQLITE);
120
- const backupFilePath = (0, path_1.join)(config.dbFolder, types_1.storageFiles.SQLITE_BACKUP);
121
- if (!fs_1.default.existsSync(sqliteFilePath)) {
122
- (0, logger_1.log)('SQLite database not found, skipping migration dump creation');
123
- return;
124
- }
125
- (0, logger_1.log)('Creating dump for migration from SQLite to PostgreSQL');
126
- for (const tableName in exports.TABLES) {
127
- (0, logger_1.log)(`Creating dump for table ${tableName}`);
128
- const dumpFileName = util.format(types_1.storageFiles.DUMP, tableName);
129
- const dumpFilePath = path_1.default.join(config.dbFolder, dumpFileName);
130
- (0, child_process_1.execSync)(`sqlite3 ${sqliteFilePath} ".output ${dumpFilePath}" ".dump ${tableName}" ".output stdout"`);
131
- let modifiedContent = fs_1.default.readFileSync(dumpFilePath).toString();
132
- // 1. Remove SQLite-specific PRAGMA statements
133
- modifiedContent = modifiedContent.replace(/PRAGMA foreign_keys=OFF;\n/g, '');
134
- // 2. Adjust transaction syntax for PostgreSQL
135
- modifiedContent = modifiedContent.replace(/BEGIN TRANSACTION;\n/g, '');
136
- modifiedContent = modifiedContent.replace(/COMMIT TRANSACTION;\n/g, '');
137
- // 3. Ensure tables are only created if they don't already exist
138
- modifiedContent = modifiedContent
139
- .replace(/CREATE TABLE IF NOT EXISTS/g, 'CREATE TABLE') // Remove duplicate IF NOT EXISTS
140
- .replace(/CREATE TABLE/g, 'CREATE TABLE IF NOT EXISTS'); // Add IF NOT EXISTS if missing
141
- // 4. Add `ON CONFLICT DO NOTHING` to INSERT statements to handle conflicts gracefully
142
- modifiedContent = modifiedContent.replace(/(INSERT INTO [^;]+)(;)/g, '$1 ON CONFLICT DO NOTHING;');
143
- // 5. Convert SQLite-specific data types to PostgreSQL equivalents
144
- modifiedContent = modifiedContent.replace(/integer not null primary key autoincrement/gi, 'serial primary key');
145
- modifiedContent = modifiedContent.replace(/varchar not null primary key/gi, 'varchar primary key');
146
- // 6. Remove SQLite-specific function replace()
147
- modifiedContent = modifiedContent.replace(/replace\s*\(\s*'([^']*(?:'{2}[^']*)*)',\s*'\\n',\s*char\s*\(\s*10\s*\)\s*\)/gi, "'$1'");
148
- // 7. Convert SQLite backticks to PostgreSQL double quotes
149
- modifiedContent = modifiedContent.replace(/`([^`]+)`/g, '"$1"');
150
- // 8. Remove VARCHAR length restrictions (VARCHAR(255) -> VARCHAR)
151
- modifiedContent = modifiedContent.replace(/VARCHAR\(\d+\)/gi, 'VARCHAR');
152
- fs_1.default.writeFileSync(dumpFilePath, modifiedContent, { encoding: 'utf8', flag: 'w' });
153
- }
154
- fs_1.default.renameSync(sqliteFilePath, backupFilePath);
155
- }
156
- function getSqLiteFileFromBackup(config) {
157
- const sqliteFilePath = (0, path_1.join)(config.dbFolder, types_1.storageFiles.SQLITE);
158
- const backupFilePath = (0, path_1.join)(config.dbFolder, types_1.storageFiles.SQLITE_BACKUP);
159
- if (fs_1.default.existsSync(backupFilePath) && !fs_1.default.existsSync(sqliteFilePath)) {
160
- (0, logger_1.log)('Restoring SQLite database from backup');
161
- fs_1.default.renameSync(backupFilePath, sqliteFilePath);
162
- }
163
- }
@@ -0,0 +1,3 @@
1
+ import { Config, UnauthorizedConfig } from '../../types';
2
+ export declare function createDumpForMigration(config: Config | UnauthorizedConfig): void;
3
+ export declare function getSqLiteFileFromBackup(config: Config | UnauthorizedConfig): void;
@@ -0,0 +1,94 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.createDumpForMigration = createDumpForMigration;
40
+ exports.getSqLiteFileFromBackup = getSqLiteFileFromBackup;
41
+ const child_process_1 = require("child_process");
42
+ const fs_1 = __importDefault(require("fs"));
43
+ const util = __importStar(require("node:util"));
44
+ const path_1 = __importStar(require("path"));
45
+ const types_1 = require("../../types");
46
+ const logger_1 = require("../../util/logger");
47
+ const postgresql_1 = require("../drizzle/postgresql");
48
+ function createDumpForMigration(config) {
49
+ const sqliteFilePath = (0, path_1.join)(config.dbFolder, types_1.storageFiles.SQLITE);
50
+ const backupFilePath = (0, path_1.join)(config.dbFolder, types_1.storageFiles.SQLITE_BACKUP);
51
+ if (!fs_1.default.existsSync(sqliteFilePath)) {
52
+ (0, logger_1.log)('SQLite database not found, skipping migration dump creation');
53
+ return;
54
+ }
55
+ (0, logger_1.log)('Creating dump for migration from SQLite to PostgreSQL');
56
+ for (const table of Object.keys(postgresql_1.POSTGRESQL_SCHEMA)) {
57
+ const tableName = postgresql_1.POSTGRESQL_SCHEMA[table]._.name;
58
+ (0, logger_1.log)(`Creating dump for table ${tableName}`);
59
+ const dumpFileName = util.format(types_1.storageFiles.DUMP, tableName);
60
+ const dumpFilePath = path_1.default.join(config.dbFolder, dumpFileName);
61
+ (0, child_process_1.execSync)(`sqlite3 ${sqliteFilePath} ".output ${dumpFilePath}" ".dump ${tableName}" ".output stdout"`);
62
+ let modifiedContent = fs_1.default.readFileSync(dumpFilePath).toString();
63
+ // 1. Remove SQLite-specific PRAGMA statements
64
+ modifiedContent = modifiedContent.replace(/PRAGMA foreign_keys=OFF;\n/g, '');
65
+ // 2. Adjust transaction syntax for PostgreSQL
66
+ modifiedContent = modifiedContent.replace(/BEGIN TRANSACTION;\n/g, '');
67
+ modifiedContent = modifiedContent.replace(/COMMIT TRANSACTION;\n/g, '');
68
+ // 3. Ensure tables are only created if they don't already exist
69
+ modifiedContent = modifiedContent
70
+ .replace(/CREATE TABLE IF NOT EXISTS/g, 'CREATE TABLE') // Remove duplicate IF NOT EXISTS
71
+ .replace(/CREATE TABLE/g, 'CREATE TABLE IF NOT EXISTS'); // Add IF NOT EXISTS if missing
72
+ // 4. Add `ON CONFLICT DO NOTHING` to INSERT statements to handle conflicts gracefully
73
+ modifiedContent = modifiedContent.replace(/(INSERT INTO [^;]+)(;)/g, '$1 ON CONFLICT DO NOTHING;');
74
+ // 5. Convert SQLite-specific data types to PostgreSQL equivalents
75
+ modifiedContent = modifiedContent.replace(/integer not null primary key autoincrement/gi, 'serial primary key');
76
+ modifiedContent = modifiedContent.replace(/varchar not null primary key/gi, 'varchar primary key');
77
+ // 6. Remove SQLite-specific function replace()
78
+ modifiedContent = modifiedContent.replace(/replace\s*\(\s*'([^']*(?:'{2}[^']*)*)',\s*'\\n',\s*char\s*\(\s*10\s*\)\s*\)/gi, "'$1'");
79
+ // 7. Convert SQLite backticks to PostgreSQL double quotes
80
+ modifiedContent = modifiedContent.replace(/`([^`]+)`/g, '"$1"');
81
+ // 8. Remove VARCHAR length restrictions (VARCHAR(255) -> VARCHAR)
82
+ modifiedContent = modifiedContent.replace(/VARCHAR\(\d+\)/gi, 'VARCHAR');
83
+ fs_1.default.writeFileSync(dumpFilePath, modifiedContent, { encoding: 'utf8', flag: 'w' });
84
+ }
85
+ fs_1.default.renameSync(sqliteFilePath, backupFilePath);
86
+ }
87
+ function getSqLiteFileFromBackup(config) {
88
+ const sqliteFilePath = (0, path_1.join)(config.dbFolder, types_1.storageFiles.SQLITE);
89
+ const backupFilePath = (0, path_1.join)(config.dbFolder, types_1.storageFiles.SQLITE_BACKUP);
90
+ if (fs_1.default.existsSync(backupFilePath) && !fs_1.default.existsSync(sqliteFilePath)) {
91
+ (0, logger_1.log)('Restoring SQLite database from backup');
92
+ fs_1.default.renameSync(backupFilePath, sqliteFilePath);
93
+ }
94
+ }
@@ -1,3 +1,9 @@
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';
3
+ import { CrowdinCredentials } from '../types';
4
+ import { D1_DB } from './drizzle/d1/types';
5
+ import { POSTGRESQL_DB } from './drizzle/postgresql';
6
+ import { SQLITE_DB } from './drizzle/sqlite';
1
7
  export interface UserErrors {
2
8
  id: number;
3
9
  action: string;
@@ -7,3 +13,63 @@ export interface UserErrors {
7
13
  crowdinId: string;
8
14
  integrationId?: string;
9
15
  }
16
+ export type DB_TYPE = 'sqlite' | 'postgresql' | 'd1';
17
+ export type DRIZZLE_DB = SQLITE_DB | POSTGRESQL_DB | D1_DB;
18
+ export interface Storage {
19
+ db: DRIZZLE_DB;
20
+ migrateDelayed(): Promise<void>;
21
+ saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
22
+ updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
23
+ getCrowdinCredentials(id: string): Promise<CrowdinCredentials | undefined>;
24
+ getAllCrowdinCredentials(): Promise<CrowdinCredentials[]>;
25
+ deleteCrowdinCredentials(id: string): Promise<void>;
26
+ saveIntegrationCredentials(id: string, credentials: string, crowdinId: string): Promise<void>;
27
+ updateIntegrationCredentials(id: string, credentials: string): Promise<void>;
28
+ updateIntegrationManagers(id: string, managers: string): Promise<void>;
29
+ getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
30
+ getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
31
+ deleteIntegrationCredentials(id: string): Promise<void>;
32
+ deleteAllIntegrationCredentials(crowdinId: string): Promise<void>;
33
+ saveMetadata(id: string, metadata: any, crowdinId: string): Promise<void>;
34
+ updateMetadata(id: string, metadata: any, crowdinId: string): Promise<void>;
35
+ getMetadata(id: string): Promise<any | undefined>;
36
+ getAllMetadata(): Promise<any[] | undefined>;
37
+ deleteMetadata(id: string): Promise<void>;
38
+ getSyncSettingsByProvider(integrationId: string, provider: Provider): Promise<IntegrationSyncSettings | undefined>;
39
+ getSyncSettingsBySchedule(type: string, schedule: string): Promise<IntegrationSyncSettings[]>;
40
+ saveSyncSettings(files: string, integrationId: string, crowdinId: string, type: string, provider: Provider): Promise<void>;
41
+ updateSyncSettings(files: string, integrationId: string, crowdinId: string, type: string, provider: Provider): Promise<void>;
42
+ getSyncSettings(integrationId: string, crowdinId: string, type: string, provider: Provider): Promise<IntegrationSyncSettings | undefined>;
43
+ saveFilesSnapshot(files: string, integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
44
+ updateFilesSnapshot(files: string, integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
45
+ getFilesSnapshot(integrationId: string, crowdinId: string, provider: Provider): Promise<IntegrationFilesSnapshot | undefined>;
46
+ getAllWebhooks(integrationId: string, crowdinId: string, provider: Provider): Promise<IntegrationWebhooks[] | undefined>;
47
+ getWebhooks(fileId: string, integrationId: string, crowdinId: string, provider: Provider): Promise<IntegrationWebhooks | undefined>;
48
+ saveWebhooks(fileId: string, integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
49
+ deleteWebhooks(fileIds: string[], integrationId: string, crowdinId: string, provider: Provider): Promise<void>;
50
+ getAllUserErrors(crowdinId: string, integrationId?: string): Promise<UserErrors[] | undefined>;
51
+ saveUserError(action: string, message: string, data: string, createdAt: string, crowdinId: string, integrationId?: string): Promise<void>;
52
+ deleteUserErrors(date: string, crowdinId: string, integrationId?: string): Promise<void>;
53
+ deleteAllUsersErrorsOlderThan(date: string): Promise<void>;
54
+ saveIntegrationConfig(integrationId: string, crowdinId: string, config: string): Promise<void>;
55
+ getAllIntegrationConfigs(crowdinId: string): Promise<IntegrationConfig[]>;
56
+ getIntegrationConfig(integrationId: string): Promise<IntegrationConfig | undefined>;
57
+ updateIntegrationConfig(integrationId: string, config: string): Promise<void>;
58
+ createJob(params: CreateJobParams): Promise<string>;
59
+ updateJob(params: UpdateJobParams): Promise<void>;
60
+ getJob(params: GetJobParams): Promise<Job | undefined>;
61
+ getActiveJobs(params: GetActiveJobsParams): Promise<Job[] | undefined>;
62
+ deleteFinishedJobs(): Promise<void>;
63
+ getAllInProgressJobs(): Promise<Job[] | undefined>;
64
+ getAllJobs(params: GetAllJobsParams): Promise<Job[] | undefined>;
65
+ saveTranslationCache(params: TranslationCache): Promise<void>;
66
+ getFileTranslationCache(params: GetFileTranslationCache): Promise<TranslationCache[] | undefined>;
67
+ getFileTranslationCacheByLanguage(params: GetFileTranslationCacheByLanguageParams): Promise<TranslationCache | undefined>;
68
+ updateTranslationCache(params: UpdateTranslationCacheParams): Promise<void>;
69
+ saveUnsyncedFiles(params: UnsyncedFiles): Promise<void>;
70
+ getUnsyncedFiles(params: GetUnsyncedFiles): Promise<UnsyncedFiles | undefined>;
71
+ updateUnsyncedFiles(params: UnsyncedFiles): Promise<void>;
72
+ saveSyncedData(files: string, integrationId: string, crowdinId: string, type: string): Promise<void>;
73
+ updateSyncedData(files: string, integrationId: string, crowdinId: string, type: string): Promise<void>;
74
+ getSyncedData(integrationId: string, crowdinId: string, type: string): Promise<IntegrationSyncedData | undefined>;
75
+ }