@crowdin/app-project-module 0.16.4 → 0.17.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.
- package/out/handlers/install.js +5 -0
- package/out/models/index.d.ts +5 -0
- package/out/storage/index.js +92 -55
- package/out/util/connection.js +6 -1
- package/package.json +2 -2
package/out/handlers/install.js
CHANGED
|
@@ -20,6 +20,11 @@ function handle(config) {
|
|
|
20
20
|
const token = yield (0, crowdin_apps_functions_1.generateOAuthToken)(config.clientId, config.clientSecret, event.code);
|
|
21
21
|
const credentials = {
|
|
22
22
|
id: (event.domain || event.organizationId).toString(),
|
|
23
|
+
appSecret: event.appSecret,
|
|
24
|
+
domain: event.domain,
|
|
25
|
+
userId: event.userId,
|
|
26
|
+
organizationId: event.organizationId,
|
|
27
|
+
baseUrl: event.baseUrl,
|
|
23
28
|
accessToken: (0, util_1.encryptData)(config, token.accessToken),
|
|
24
29
|
refreshToken: (0, util_1.encryptData)(config, token.refreshToken),
|
|
25
30
|
expire: (new Date().getTime() / 1000 + token.expiresIn).toString(),
|
package/out/models/index.d.ts
CHANGED
|
@@ -326,6 +326,11 @@ export interface CrowdinClientRequest extends Request {
|
|
|
326
326
|
}
|
|
327
327
|
export interface CrowdinCredentials {
|
|
328
328
|
id: string;
|
|
329
|
+
appSecret: string;
|
|
330
|
+
domain?: string;
|
|
331
|
+
userId: number;
|
|
332
|
+
organizationId: number;
|
|
333
|
+
baseUrl: string;
|
|
329
334
|
accessToken: string;
|
|
330
335
|
refreshToken: string;
|
|
331
336
|
expire: string;
|
package/out/storage/index.js
CHANGED
|
@@ -37,6 +37,67 @@ function _run(query, params) {
|
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
|
+
function run(query, params) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
yield dbPromise;
|
|
43
|
+
return new Promise((res, rej) => {
|
|
44
|
+
db.run(query, params, err => {
|
|
45
|
+
if (err) {
|
|
46
|
+
rej(err);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
res();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function get(query, params) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
yield dbPromise;
|
|
58
|
+
return new Promise((res, rej) => {
|
|
59
|
+
db.get(query, params, (err, row) => {
|
|
60
|
+
if (err) {
|
|
61
|
+
rej(err);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
res(row);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function each(query, params) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
yield dbPromise;
|
|
73
|
+
return new Promise((res, rej) => {
|
|
74
|
+
const result = [];
|
|
75
|
+
db.each(query, params, (err, row) => {
|
|
76
|
+
if (err) {
|
|
77
|
+
rej(err);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
result.push(row);
|
|
81
|
+
}
|
|
82
|
+
}, () => res(result));
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function migrate() {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const newColumns = ['app_secret', 'domain', 'userId', 'organizationId', 'baseUrl'];
|
|
89
|
+
const crowdinCredentialsInfo = yield each('PRAGMA table_info(crowdin_credentials);', []);
|
|
90
|
+
crowdinCredentialsInfo.map((columnInfo) => __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const index = newColumns.indexOf(columnInfo.name);
|
|
92
|
+
if (~index) {
|
|
93
|
+
newColumns.splice(index, 1);
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
for (const column of newColumns) {
|
|
97
|
+
yield run(`ALTER TABLE crowdin_credentials ADD COLUMN ${column} varchar null;`, []);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
40
101
|
function connect(folder) {
|
|
41
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
103
|
let _connection_res;
|
|
@@ -58,11 +119,16 @@ function connect(folder) {
|
|
|
58
119
|
yield _run(`
|
|
59
120
|
create table if not exists crowdin_credentials
|
|
60
121
|
(
|
|
61
|
-
id
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
122
|
+
id varchar not null primary key,
|
|
123
|
+
app_secret varchar null,
|
|
124
|
+
domain varchar null,
|
|
125
|
+
userId varchar null,
|
|
126
|
+
organizationId varchar null,
|
|
127
|
+
baseUrl varchar null,
|
|
128
|
+
access_token varchar not null,
|
|
129
|
+
refresh_token varchar not null,
|
|
130
|
+
expire varchar not null,
|
|
131
|
+
type varchar not null
|
|
66
132
|
);
|
|
67
133
|
`, []);
|
|
68
134
|
yield _run(`
|
|
@@ -93,6 +159,8 @@ function connect(folder) {
|
|
|
93
159
|
);
|
|
94
160
|
`, []);
|
|
95
161
|
_res();
|
|
162
|
+
// TODO: temporary code
|
|
163
|
+
yield migrate();
|
|
96
164
|
}
|
|
97
165
|
catch (e) {
|
|
98
166
|
_rej(e);
|
|
@@ -100,58 +168,27 @@ function connect(folder) {
|
|
|
100
168
|
});
|
|
101
169
|
}
|
|
102
170
|
exports.connect = connect;
|
|
103
|
-
function run(query, params) {
|
|
104
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
-
yield dbPromise;
|
|
106
|
-
return new Promise((res, rej) => {
|
|
107
|
-
db.run(query, params, err => {
|
|
108
|
-
if (err) {
|
|
109
|
-
rej(err);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
res();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
function get(query, params) {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
yield dbPromise;
|
|
121
|
-
return new Promise((res, rej) => {
|
|
122
|
-
db.get(query, params, (err, row) => {
|
|
123
|
-
if (err) {
|
|
124
|
-
rej(err);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
res(row);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
function each(query, params) {
|
|
134
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
-
yield dbPromise;
|
|
136
|
-
return new Promise((res, rej) => {
|
|
137
|
-
const result = [];
|
|
138
|
-
db.each(query, params, (err, row) => {
|
|
139
|
-
if (err) {
|
|
140
|
-
rej(err);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
result.push(row);
|
|
144
|
-
}
|
|
145
|
-
}, () => res(result));
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
171
|
function saveCrowdinCredentials(credentials) {
|
|
150
|
-
return run('INSERT INTO crowdin_credentials(id, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?)', [
|
|
172
|
+
return run('INSERT INTO crowdin_credentials(id, app_secret, domain, user_id, organization_id, base_url, access_token, refresh_token, expire, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', [
|
|
173
|
+
credentials.id,
|
|
174
|
+
credentials.appSecret,
|
|
175
|
+
credentials.domain,
|
|
176
|
+
credentials.userId,
|
|
177
|
+
credentials.organizationId,
|
|
178
|
+
credentials.baseUrl,
|
|
179
|
+
credentials.accessToken,
|
|
180
|
+
credentials.refreshToken,
|
|
181
|
+
credentials.expire,
|
|
182
|
+
]);
|
|
151
183
|
}
|
|
152
184
|
exports.saveCrowdinCredentials = saveCrowdinCredentials;
|
|
153
185
|
function updateCrowdinCredentials(credentials) {
|
|
154
|
-
return run('UPDATE crowdin_credentials SET access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
|
|
186
|
+
return run('UPDATE crowdin_credentials SET app_secret = ?, domain = ?, user_id = ?, organization_id = ?, base_url = ?, access_token = ?, refresh_token = ?, expire = ? WHERE id = ?', [
|
|
187
|
+
credentials.appSecret,
|
|
188
|
+
credentials.domain,
|
|
189
|
+
credentials.userId,
|
|
190
|
+
credentials.organizationId,
|
|
191
|
+
credentials.baseUrl,
|
|
155
192
|
credentials.accessToken,
|
|
156
193
|
credentials.refreshToken,
|
|
157
194
|
credentials.expire,
|
|
@@ -161,7 +198,7 @@ function updateCrowdinCredentials(credentials) {
|
|
|
161
198
|
exports.updateCrowdinCredentials = updateCrowdinCredentials;
|
|
162
199
|
function getCrowdinCredentials(id) {
|
|
163
200
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
const row = yield get('SELECT id, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials WHERE id = ?', [id]);
|
|
201
|
+
const row = yield 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]);
|
|
165
202
|
if (row) {
|
|
166
203
|
return row;
|
|
167
204
|
}
|
|
@@ -170,7 +207,7 @@ function getCrowdinCredentials(id) {
|
|
|
170
207
|
exports.getCrowdinCredentials = getCrowdinCredentials;
|
|
171
208
|
function getAllCrowdinCredentials() {
|
|
172
209
|
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
-
return each('SELECT id, access_token as accessToken, refresh_token as refreshToken, expire, type FROM crowdin_credentials', []);
|
|
210
|
+
return 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', []);
|
|
174
211
|
});
|
|
175
212
|
}
|
|
176
213
|
exports.getAllCrowdinCredentials = getAllCrowdinCredentials;
|
package/out/util/connection.js
CHANGED
|
@@ -56,6 +56,11 @@ function prepareCrowdinClient(config, credentials) {
|
|
|
56
56
|
(0, _1.log)('Saving updated crowdin credentials in the database', config.logger);
|
|
57
57
|
yield (0, storage_1.updateCrowdinCredentials)({
|
|
58
58
|
id: credentials.id,
|
|
59
|
+
appSecret: credentials.appSecret,
|
|
60
|
+
domain: credentials.domain,
|
|
61
|
+
userId: credentials.userId,
|
|
62
|
+
organizationId: credentials.organizationId,
|
|
63
|
+
baseUrl: credentials.baseUrl,
|
|
59
64
|
refreshToken: (0, _1.encryptData)(config, newCredentials.refreshToken),
|
|
60
65
|
accessToken: (0, _1.encryptData)(config, newCredentials.accessToken),
|
|
61
66
|
expire: (new Date().getTime() / 1000 + newCredentials.expiresIn).toString(),
|
|
@@ -180,7 +185,7 @@ function checkSubscription(config, token, organization, accountType) {
|
|
|
180
185
|
//default 2 weeks
|
|
181
186
|
const defaultSubscriptionPlan = 14;
|
|
182
187
|
let days;
|
|
183
|
-
if (
|
|
188
|
+
if (accountType === models_1.AccountType.ENTERPRISE) {
|
|
184
189
|
days = ((_b = config.pricing) === null || _b === void 0 ? void 0 : _b.trialEnterprise) || ((_c = config.pricing) === null || _c === void 0 ? void 0 : _c.trial) || defaultSubscriptionPlan;
|
|
185
190
|
}
|
|
186
191
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crowdin/app-project-module",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Module that generates for you all common endpoints for serving standalone Crowdin App",
|
|
5
5
|
"main": "out/index.js",
|
|
6
6
|
"types": "out/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"test": "echo \"test not implemented\""
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@crowdin/crowdin-apps-functions": "0.1.
|
|
15
|
+
"@crowdin/crowdin-apps-functions": "0.1.3",
|
|
16
16
|
"crypto-js": "^4.0.0",
|
|
17
17
|
"express": "4.17.1",
|
|
18
18
|
"express-handlebars": "^5.3.4",
|