@crowdin/app-project-module 0.17.9 → 0.18.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/README.md +27 -0
- package/out/handlers/install.js +3 -3
- package/out/handlers/integration-login.js +3 -3
- package/out/handlers/integration-logout.js +1 -1
- package/out/handlers/settings-save.js +1 -1
- package/out/handlers/sync-settings-save.js +3 -3
- package/out/handlers/sync-settings.js +1 -1
- package/out/handlers/uninstall.js +1 -1
- package/out/index.js +9 -9
- package/out/middlewares/crowdin-client.js +1 -1
- package/out/middlewares/integration-credentials.js +1 -1
- package/out/middlewares/ui-module.js +1 -1
- package/out/models/index.d.ts +6 -1
- package/out/storage/index.d.ts +26 -22
- package/out/storage/index.js +29 -308
- package/out/storage/postgre.d.ts +42 -0
- package/out/storage/postgre.js +261 -0
- package/out/storage/sqlite.d.ts +37 -0
- package/out/storage/sqlite.js +301 -0
- package/out/util/connection.js +2 -2
- package/out/util/cron.js +5 -5
- package/out/util/index.js +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Storage } from '.';
|
|
2
|
+
import { CrowdinCredentials, IntegrationCredentials, IntegrationSyncSettings } from '../models';
|
|
3
|
+
export interface PostgreStorageConfig {
|
|
4
|
+
host?: string;
|
|
5
|
+
connectionString?: string;
|
|
6
|
+
user?: string;
|
|
7
|
+
database?: string;
|
|
8
|
+
password?: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
keepAlive?: boolean;
|
|
11
|
+
keepAliveInitialDelayMillis?: number;
|
|
12
|
+
idle_in_transaction_session_timeout?: number;
|
|
13
|
+
connectionTimeoutMillis?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare class PostgreStorage implements Storage<PostgreStorageConfig> {
|
|
16
|
+
private client?;
|
|
17
|
+
private _res?;
|
|
18
|
+
private _rej?;
|
|
19
|
+
private dbPromise;
|
|
20
|
+
connect(config: PostgreStorageConfig): Promise<void>;
|
|
21
|
+
migrate(): 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
|
+
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
30
|
+
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
31
|
+
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
32
|
+
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
33
|
+
saveMetadata(id: string, metadata: any): Promise<void>;
|
|
34
|
+
updateMetadata(id: string, metadata: any): Promise<void>;
|
|
35
|
+
getMetadata(id: string): Promise<any>;
|
|
36
|
+
deleteMetadata(id: string): Promise<void>;
|
|
37
|
+
getSyncSettingsByProvider(integrationId: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
|
|
38
|
+
getAllSyncSettingsByType(type: string): Promise<IntegrationSyncSettings[]>;
|
|
39
|
+
saveSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
|
|
40
|
+
updateSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
|
|
41
|
+
getSyncSettings(integrationId: string, crowdinId: string, type: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-unused-expressions */
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.PostgreStorage = void 0;
|
|
14
|
+
const pg_1 = require("pg");
|
|
15
|
+
class PostgreStorage {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.dbPromise = new Promise((res, rej) => {
|
|
18
|
+
this._res = res;
|
|
19
|
+
this._rej = rej;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
connect(config) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
this.client = new pg_1.Client(config);
|
|
25
|
+
try {
|
|
26
|
+
yield this.client.connect();
|
|
27
|
+
yield this.migrate();
|
|
28
|
+
this._res && this._res();
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error(e);
|
|
32
|
+
this._rej && this._rej();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
migrate() {
|
|
37
|
+
var _a, _b, _c, _d;
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query(`
|
|
40
|
+
create table if not exists crowdin_credentials
|
|
41
|
+
(
|
|
42
|
+
id varchar primary key,
|
|
43
|
+
app_secret varchar,
|
|
44
|
+
domain varchar,
|
|
45
|
+
user_id varchar,
|
|
46
|
+
organization_id varchar,
|
|
47
|
+
base_url varchar,
|
|
48
|
+
access_token varchar not null,
|
|
49
|
+
refresh_token varchar not null,
|
|
50
|
+
expire varchar not null,
|
|
51
|
+
type varchar not null
|
|
52
|
+
)
|
|
53
|
+
`));
|
|
54
|
+
yield ((_b = this.client) === null || _b === void 0 ? void 0 : _b.query(`
|
|
55
|
+
create table if not exists integration_credentials
|
|
56
|
+
(
|
|
57
|
+
id varchar primary key,
|
|
58
|
+
credentials varchar,
|
|
59
|
+
config varchar,
|
|
60
|
+
crowdin_id varchar not null
|
|
61
|
+
)
|
|
62
|
+
`));
|
|
63
|
+
yield ((_c = this.client) === null || _c === void 0 ? void 0 : _c.query(`
|
|
64
|
+
create table if not exists sync_settings
|
|
65
|
+
(
|
|
66
|
+
id serial primary key,
|
|
67
|
+
files varchar,
|
|
68
|
+
integration_id varchar not null,
|
|
69
|
+
crowdin_id varchar not null,
|
|
70
|
+
type varchar not null,
|
|
71
|
+
provider varchar not null
|
|
72
|
+
)
|
|
73
|
+
`));
|
|
74
|
+
yield ((_d = this.client) === null || _d === void 0 ? void 0 : _d.query(`
|
|
75
|
+
create table if not exists app_metadata
|
|
76
|
+
(
|
|
77
|
+
id varchar primary key,
|
|
78
|
+
data varchar
|
|
79
|
+
)
|
|
80
|
+
`));
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
saveCrowdinCredentials(credentials) {
|
|
84
|
+
var _a;
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
yield this.dbPromise;
|
|
87
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)', [
|
|
88
|
+
credentials.id,
|
|
89
|
+
credentials.appSecret,
|
|
90
|
+
credentials.domain,
|
|
91
|
+
credentials.userId,
|
|
92
|
+
credentials.organizationId,
|
|
93
|
+
credentials.baseUrl,
|
|
94
|
+
credentials.accessToken,
|
|
95
|
+
credentials.refreshToken,
|
|
96
|
+
credentials.expire,
|
|
97
|
+
credentials.type,
|
|
98
|
+
]));
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
updateCrowdinCredentials(credentials) {
|
|
102
|
+
var _a;
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
yield this.dbPromise;
|
|
105
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE crowdin_credentials SET app_secret = $1, domain = $2, user_id = $3, organization_id = $4, base_url = $5, access_token = $6, refresh_token = $7, expire = $8 WHERE id = $9', [
|
|
106
|
+
credentials.appSecret,
|
|
107
|
+
credentials.domain,
|
|
108
|
+
credentials.userId,
|
|
109
|
+
credentials.organizationId,
|
|
110
|
+
credentials.baseUrl,
|
|
111
|
+
credentials.accessToken,
|
|
112
|
+
credentials.refreshToken,
|
|
113
|
+
credentials.expire,
|
|
114
|
+
credentials.id,
|
|
115
|
+
]));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
getCrowdinCredentials(id) {
|
|
119
|
+
var _a;
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
yield this.dbPromise;
|
|
122
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials WHERE id = $1', [id]));
|
|
123
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
getAllCrowdinCredentials() {
|
|
127
|
+
var _a;
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
yield this.dbPromise;
|
|
130
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, app_secret as "appSecret", domain, user_id as "userId", organization_id as "organizationId", base_url as "baseUrl", access_token as "accessToken", refresh_token as "refreshToken", expire, type FROM crowdin_credentials', []));
|
|
131
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
deleteCrowdinCredentials(id) {
|
|
135
|
+
var _a, _b, _c;
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
yield this.dbPromise;
|
|
138
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('DELETE FROM crowdin_credentials where id = $1', [id]));
|
|
139
|
+
yield ((_b = this.client) === null || _b === void 0 ? void 0 : _b.query('DELETE FROM integration_credentials where crowdin_id = $1', [id]));
|
|
140
|
+
yield ((_c = this.client) === null || _c === void 0 ? void 0 : _c.query('DELETE FROM sync_settings WHERE crowdin_id = $1', [id]));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
saveIntegrationCredentials(id, credentials, crowdinId) {
|
|
144
|
+
var _a;
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
yield this.dbPromise;
|
|
147
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('INSERT INTO integration_credentials(id, credentials, crowdin_id) VALUES ($1, $2, $3)', [id, credentials, crowdinId]));
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
updateIntegrationCredentials(id, credentials) {
|
|
151
|
+
var _a;
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
yield this.dbPromise;
|
|
154
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE integration_credentials SET credentials = $1 WHERE id = $2', [
|
|
155
|
+
credentials,
|
|
156
|
+
id,
|
|
157
|
+
]));
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
updateIntegrationConfig(id, config) {
|
|
161
|
+
var _a;
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
yield this.dbPromise;
|
|
164
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE integration_credentials SET config = $1 WHERE id = $2', [config, id]));
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
getIntegrationCredentials(id) {
|
|
168
|
+
var _a;
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
yield this.dbPromise;
|
|
171
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE id = $1', [id]));
|
|
172
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getAllIntegrationCredentials(crowdinId) {
|
|
176
|
+
var _a;
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
yield this.dbPromise;
|
|
179
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, credentials, config, crowdin_id as "crowdinId" FROM integration_credentials WHERE crowdin_id = $1', [crowdinId]));
|
|
180
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
deleteIntegrationCredentials(id) {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
yield this.dbPromise;
|
|
187
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('DELETE FROM integration_credentials where id = $1', [id]));
|
|
188
|
+
yield ((_b = this.client) === null || _b === void 0 ? void 0 : _b.query('DELETE FROM sync_settings where integration_id = $1', [id]));
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
saveMetadata(id, metadata) {
|
|
192
|
+
var _a;
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
yield this.dbPromise;
|
|
195
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('INSERT INTO app_metadata(id, data) VALUES ($1, $2)', [id, metadata]));
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
updateMetadata(id, metadata) {
|
|
199
|
+
var _a;
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
yield this.dbPromise;
|
|
202
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE app_metadata SET data = $1 WHERE id = $2', [id, metadata]));
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
getMetadata(id) {
|
|
206
|
+
var _a;
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
yield this.dbPromise;
|
|
209
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT data FROM app_metadata WHERE id = $1', [id]));
|
|
210
|
+
if (res === null || res === void 0 ? void 0 : res.rows[0]) {
|
|
211
|
+
return JSON.parse(res === null || res === void 0 ? void 0 : res.rows[0].data);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
deleteMetadata(id) {
|
|
216
|
+
var _a;
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
yield this.dbPromise;
|
|
219
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('DELETE FROM app_metadata where id = $1', [id]));
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
getSyncSettingsByProvider(integrationId, provider) {
|
|
223
|
+
var _a;
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
yield this.dbPromise;
|
|
226
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE integration_id = $1 AND provider = $2', [integrationId, provider]));
|
|
227
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
getAllSyncSettingsByType(type) {
|
|
231
|
+
var _a;
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
yield this.dbPromise;
|
|
234
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type, provider FROM sync_settings WHERE type = $1', [type]));
|
|
235
|
+
return (res === null || res === void 0 ? void 0 : res.rows) || [];
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
saveSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
239
|
+
var _a;
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
yield this.dbPromise;
|
|
242
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('INSERT INTO sync_settings(files, integration_id, crowdin_id, type, provider) VALUES ($1, $2, $3, $4, $5)', [files, integrationId, crowdinId, type, provider]));
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
updateSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
246
|
+
var _a;
|
|
247
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
yield this.dbPromise;
|
|
249
|
+
yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('UPDATE sync_settings SET files = $1 WHERE integration_id = $2 AND crowdin_id = $3 AND type = $4 AND provider = $5', [files, integrationId, crowdinId, type, provider]));
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
getSyncSettings(integrationId, crowdinId, type, provider) {
|
|
253
|
+
var _a;
|
|
254
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
255
|
+
yield this.dbPromise;
|
|
256
|
+
const res = yield ((_a = this.client) === null || _a === void 0 ? void 0 : _a.query('SELECT id, files, integration_id as "integrationId", crowdin_id as "crowdinId", type FROM sync_settings WHERE integration_id = $1 AND crowdin_id = $2 AND type = $3 AND provider = $4', [integrationId, crowdinId, type, provider]));
|
|
257
|
+
return res === null || res === void 0 ? void 0 : res.rows[0];
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.PostgreStorage = PostgreStorage;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Storage } from '.';
|
|
2
|
+
import { CrowdinCredentials, IntegrationCredentials, IntegrationSyncSettings } from '../models';
|
|
3
|
+
export interface SQLiteStorageConfig {
|
|
4
|
+
dbFolder: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class SQLiteStorage implements Storage<SQLiteStorageConfig> {
|
|
7
|
+
private db;
|
|
8
|
+
private _res?;
|
|
9
|
+
private _rej?;
|
|
10
|
+
private dbPromise;
|
|
11
|
+
private _run;
|
|
12
|
+
private run;
|
|
13
|
+
private get;
|
|
14
|
+
private each;
|
|
15
|
+
private migrate;
|
|
16
|
+
connect(config: SQLiteStorageConfig): Promise<void>;
|
|
17
|
+
saveCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
18
|
+
updateCrowdinCredentials(credentials: CrowdinCredentials): Promise<void>;
|
|
19
|
+
getCrowdinCredentials(id: string): Promise<CrowdinCredentials | undefined>;
|
|
20
|
+
getAllCrowdinCredentials(): Promise<CrowdinCredentials[]>;
|
|
21
|
+
deleteCrowdinCredentials(id: string): Promise<void>;
|
|
22
|
+
saveIntegrationCredentials(id: string, credentials: any, crowdinId: string): Promise<void>;
|
|
23
|
+
updateIntegrationCredentials(id: string, credentials: any): Promise<void>;
|
|
24
|
+
updateIntegrationConfig(id: string, config: any): Promise<void>;
|
|
25
|
+
getIntegrationCredentials(id: string): Promise<IntegrationCredentials | undefined>;
|
|
26
|
+
getAllIntegrationCredentials(crowdinId: string): Promise<IntegrationCredentials[]>;
|
|
27
|
+
deleteIntegrationCredentials(id: string): Promise<void>;
|
|
28
|
+
saveMetadata(id: string, metadata: any): Promise<void>;
|
|
29
|
+
updateMetadata(id: string, metadata: any): Promise<void>;
|
|
30
|
+
getMetadata(id: string): Promise<any>;
|
|
31
|
+
deleteMetadata(id: string): Promise<void>;
|
|
32
|
+
getSyncSettingsByProvider(integrationId: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
|
|
33
|
+
getAllSyncSettingsByType(type: string): Promise<IntegrationSyncSettings[]>;
|
|
34
|
+
saveSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
|
|
35
|
+
updateSyncSettings(files: any, integrationId: string, crowdinId: string, type: string, provider: string): Promise<void>;
|
|
36
|
+
getSyncSettings(integrationId: string, crowdinId: string, type: string, provider: string): Promise<IntegrationSyncSettings | undefined>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/camelcase */
|
|
3
|
+
/* eslint-disable @typescript-eslint/ban-ts-ignore */
|
|
4
|
+
/* eslint-disable no-unused-expressions */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
6
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.SQLiteStorage = void 0;
|
|
17
|
+
const path_1 = require("path");
|
|
18
|
+
class SQLiteStorage {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.dbPromise = new Promise((res, rej) => {
|
|
21
|
+
this._res = res;
|
|
22
|
+
this._rej = rej;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
_run(query, params) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
yield new Promise((res, rej) => {
|
|
28
|
+
var _a;
|
|
29
|
+
//@ts-ignore
|
|
30
|
+
(_a = this.db) === null || _a === void 0 ? void 0 : _a.run(query, params, err => {
|
|
31
|
+
if (err) {
|
|
32
|
+
rej(err);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
res();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
run(query, params) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
yield this.dbPromise;
|
|
44
|
+
yield new Promise((res, rej) => {
|
|
45
|
+
var _a;
|
|
46
|
+
//@ts-ignore
|
|
47
|
+
(_a = this.db) === null || _a === void 0 ? void 0 : _a.run(query, params, err => {
|
|
48
|
+
if (err) {
|
|
49
|
+
rej(err);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
res();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
get(query, params) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
yield this.dbPromise;
|
|
61
|
+
return new Promise((res, rej) => {
|
|
62
|
+
var _a;
|
|
63
|
+
//@ts-ignore
|
|
64
|
+
(_a = this.db) === null || _a === void 0 ? void 0 : _a.get(query, params, (err, row) => {
|
|
65
|
+
if (err) {
|
|
66
|
+
rej(err);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
res(row);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
each(query, params) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
yield this.dbPromise;
|
|
78
|
+
return new Promise((res, rej) => {
|
|
79
|
+
var _a;
|
|
80
|
+
const result = [];
|
|
81
|
+
(_a = this.db) === null || _a === void 0 ? void 0 : _a.each(query, params,
|
|
82
|
+
//@ts-ignore
|
|
83
|
+
(err, row) => {
|
|
84
|
+
if (err) {
|
|
85
|
+
rej(err);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
result.push(row);
|
|
89
|
+
}
|
|
90
|
+
}, () => res(result));
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
migrate() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const newColumns = ['app_secret', 'domain', 'user_id', 'organization_id', 'base_url'];
|
|
97
|
+
const crowdinCredentialsInfo = yield this.each('PRAGMA table_info(crowdin_credentials);', []);
|
|
98
|
+
//@ts-ignore
|
|
99
|
+
crowdinCredentialsInfo.map((columnInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const index = newColumns.indexOf(columnInfo.name);
|
|
101
|
+
if (~index) {
|
|
102
|
+
newColumns.splice(index, 1);
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
105
|
+
for (const column of newColumns) {
|
|
106
|
+
yield this.run(`ALTER TABLE crowdin_credentials ADD COLUMN ${column} varchar null;`, []);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
connect(config) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
let _connection_res;
|
|
113
|
+
let _connection_rej;
|
|
114
|
+
const connectionPromise = new Promise((res, rej) => {
|
|
115
|
+
_connection_res = res;
|
|
116
|
+
_connection_rej = rej;
|
|
117
|
+
});
|
|
118
|
+
const sqlite = require('sqlite3');
|
|
119
|
+
//@ts-ignore
|
|
120
|
+
this.db = new sqlite.Database((0, path_1.join)(config.dbFolder, 'app.sqlite'), error => {
|
|
121
|
+
if (error) {
|
|
122
|
+
_connection_rej(error);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
_connection_res();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
yield connectionPromise;
|
|
130
|
+
yield this._run(`
|
|
131
|
+
create table if not exists crowdin_credentials
|
|
132
|
+
(
|
|
133
|
+
id varchar not null primary key,
|
|
134
|
+
app_secret varchar null,
|
|
135
|
+
domain varchar null,
|
|
136
|
+
user_id varchar null,
|
|
137
|
+
organization_id varchar null,
|
|
138
|
+
base_url varchar null,
|
|
139
|
+
access_token varchar not null,
|
|
140
|
+
refresh_token varchar not null,
|
|
141
|
+
expire varchar not null,
|
|
142
|
+
type varchar not null
|
|
143
|
+
);
|
|
144
|
+
`, []);
|
|
145
|
+
yield this._run(`
|
|
146
|
+
create table if not exists integration_credentials
|
|
147
|
+
(
|
|
148
|
+
id varchar not null primary key,
|
|
149
|
+
credentials varchar not null,
|
|
150
|
+
config varchar null,
|
|
151
|
+
crowdin_id varchar not null
|
|
152
|
+
);
|
|
153
|
+
`, []);
|
|
154
|
+
yield this._run(`
|
|
155
|
+
create table if not exists sync_settings
|
|
156
|
+
(
|
|
157
|
+
id integer not null primary key autoincrement,
|
|
158
|
+
files varchar null,
|
|
159
|
+
integration_id varchar not null,
|
|
160
|
+
crowdin_id varchar not null,
|
|
161
|
+
type varchar not null,
|
|
162
|
+
provider varchar not null
|
|
163
|
+
);
|
|
164
|
+
`, []);
|
|
165
|
+
yield this._run(`
|
|
166
|
+
create table if not exists app_metadata
|
|
167
|
+
(
|
|
168
|
+
id varchar not null primary key,
|
|
169
|
+
data varchar null
|
|
170
|
+
);
|
|
171
|
+
`, []);
|
|
172
|
+
this._res && this._res();
|
|
173
|
+
// TODO: temporary code
|
|
174
|
+
yield this.migrate();
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
this._rej && this._rej(e);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
saveCrowdinCredentials(credentials) {
|
|
182
|
+
return this.run('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
|
|
183
|
+
credentials.id,
|
|
184
|
+
credentials.appSecret,
|
|
185
|
+
credentials.domain,
|
|
186
|
+
credentials.userId,
|
|
187
|
+
credentials.organizationId,
|
|
188
|
+
credentials.baseUrl,
|
|
189
|
+
credentials.accessToken,
|
|
190
|
+
credentials.refreshToken,
|
|
191
|
+
credentials.expire,
|
|
192
|
+
credentials.type,
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
updateCrowdinCredentials(credentials) {
|
|
196
|
+
return this.run('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
|
|
197
|
+
credentials.appSecret,
|
|
198
|
+
credentials.domain,
|
|
199
|
+
credentials.userId,
|
|
200
|
+
credentials.organizationId,
|
|
201
|
+
credentials.baseUrl,
|
|
202
|
+
credentials.accessToken,
|
|
203
|
+
credentials.refreshToken,
|
|
204
|
+
credentials.expire,
|
|
205
|
+
credentials.id,
|
|
206
|
+
]);
|
|
207
|
+
}
|
|
208
|
+
getCrowdinCredentials(id) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
const row = yield this.get('SELECT id, app_secret as appSecret, domain, user_id as userId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials WHERE id = ?', [id]);
|
|
211
|
+
if (row) {
|
|
212
|
+
return row;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
getAllCrowdinCredentials() {
|
|
217
|
+
return this.each('SELECT id, app_secret as appSecret, domain, user_id as userId, organization_id as organizationId, base_url as baseUrl, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials', []);
|
|
218
|
+
}
|
|
219
|
+
deleteCrowdinCredentials(id) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
yield this.run('DELETE FROM crowdin_credentials where id = ?', [id]);
|
|
222
|
+
yield this.run('DELETE FROM integration_credentials where crowdin_id = ?', [id]);
|
|
223
|
+
yield this.run('DELETE FROM sync_settings WHERE crowdin_id = ?', [id]);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
saveIntegrationCredentials(id, credentials, crowdinId) {
|
|
227
|
+
return this.run('INSERT INTO integration_credentials(id, credentials, crowdin_id) VALUES (?, ?, ?)', [
|
|
228
|
+
id,
|
|
229
|
+
credentials,
|
|
230
|
+
crowdinId,
|
|
231
|
+
]);
|
|
232
|
+
}
|
|
233
|
+
updateIntegrationCredentials(id, credentials) {
|
|
234
|
+
return this.run('UPDATE integration_credentials SET credentials = ? WHERE id = ?', [credentials, id]);
|
|
235
|
+
}
|
|
236
|
+
updateIntegrationConfig(id, config) {
|
|
237
|
+
return this.run('UPDATE integration_credentials SET config = ? WHERE id = ?', [config, id]);
|
|
238
|
+
}
|
|
239
|
+
getIntegrationCredentials(id) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
const row = yield this.get('SELECT id, credentials, config, crowdin_id as crowdinId FROM integration_credentials WHERE id = ?', [id]);
|
|
242
|
+
if (row) {
|
|
243
|
+
return row;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
getAllIntegrationCredentials(crowdinId) {
|
|
248
|
+
return this.each('SELECT id, credentials, config, crowdin_id as crowdinId FROM integration_credentials WHERE crowdin_id = ?', [crowdinId]);
|
|
249
|
+
}
|
|
250
|
+
deleteIntegrationCredentials(id) {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
yield this.run('DELETE FROM integration_credentials where id = ?', [id]);
|
|
253
|
+
yield this.run('DELETE FROM sync_settings where integration_id = ?', [id]);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
saveMetadata(id, metadata) {
|
|
257
|
+
return this.run('INSERT INTO app_metadata(id, data) VALUES (?, ?)', [id, JSON.stringify(metadata)]);
|
|
258
|
+
}
|
|
259
|
+
updateMetadata(id, metadata) {
|
|
260
|
+
return this.run('UPDATE app_metadata SET data = ? WHERE id = ?', [JSON.stringify(metadata), id]);
|
|
261
|
+
}
|
|
262
|
+
getMetadata(id) {
|
|
263
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
264
|
+
const row = yield this.get('SELECT data FROM app_metadata WHERE id = ?', [id]);
|
|
265
|
+
if (row) {
|
|
266
|
+
return JSON.parse(row.data);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
deleteMetadata(id) {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
yield this.run('DELETE FROM app_metadata where id = ?', [id]);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
getSyncSettingsByProvider(integrationId, provider) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
const row = yield this.get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, provider FROM sync_settings WHERE integration_id = ? AND provider = ?', [integrationId, provider]);
|
|
278
|
+
if (row) {
|
|
279
|
+
return row;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
getAllSyncSettingsByType(type) {
|
|
284
|
+
return this.each('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type, provider FROM sync_settings WHERE type = ?', [type]);
|
|
285
|
+
}
|
|
286
|
+
saveSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
287
|
+
return this.run('INSERT INTO sync_settings(files, integration_id, crowdin_id, type, provider) VALUES (?, ?, ?, ?, ?)', [files, integrationId, crowdinId, type, provider]);
|
|
288
|
+
}
|
|
289
|
+
updateSyncSettings(files, integrationId, crowdinId, type, provider) {
|
|
290
|
+
return this.run('UPDATE sync_settings SET files = ? WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [files, integrationId, crowdinId, type, provider]);
|
|
291
|
+
}
|
|
292
|
+
getSyncSettings(integrationId, crowdinId, type, provider) {
|
|
293
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
294
|
+
const row = yield this.get('SELECT id, files, integration_id as integrationId, crowdin_id as crowdinId, type FROM sync_settings WHERE integration_id = ? AND crowdin_id = ? AND type = ? AND provider = ?', [integrationId, crowdinId, type, provider]);
|
|
295
|
+
if (row) {
|
|
296
|
+
return row;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.SQLiteStorage = SQLiteStorage;
|
package/out/util/connection.js
CHANGED
|
@@ -53,7 +53,7 @@ function prepareCrowdinClient(config, credentials) {
|
|
|
53
53
|
(0, _1.log)('Crowdin credentials have expired. Requesting a new credentials', config.logger);
|
|
54
54
|
const newCredentials = yield crowdinAppFunctions.refreshOAuthToken(config.clientId, config.clientSecret, (0, _1.decryptData)(config, credentials.refreshToken), (_b = config.crowdinUrls) === null || _b === void 0 ? void 0 : _b.accountUrl);
|
|
55
55
|
(0, _1.log)('Saving updated crowdin credentials in the database', config.logger);
|
|
56
|
-
yield (0, storage_1.
|
|
56
|
+
yield (0, storage_1.getStorage)().updateCrowdinCredentials({
|
|
57
57
|
id: credentials.id,
|
|
58
58
|
appSecret: credentials.appSecret,
|
|
59
59
|
domain: credentials.domain,
|
|
@@ -112,7 +112,7 @@ function prepareIntegrationCredentials(config, integration, integrationCredentia
|
|
|
112
112
|
credentials.refreshToken = newCredentials[((_h = oauthLogin === null || oauthLogin === void 0 ? void 0 : oauthLogin.fieldsMapping) === null || _h === void 0 ? void 0 : _h.refreshToken) || 'refresh_token'];
|
|
113
113
|
}
|
|
114
114
|
(0, _1.log)('Saving updated integration credentials in the database', config.logger);
|
|
115
|
-
yield (0, storage_1.
|
|
115
|
+
yield (0, storage_1.getStorage)().updateIntegrationCredentials(integrationCredentials.id, (0, _1.encryptData)(config, JSON.stringify(credentials)));
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
return credentials;
|