@crowdin/app-project-module 0.60.0 → 0.60.2
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/modules/integration/handlers/oauth-login.js +1 -0
- package/out/modules/integration/handlers/oauth-url.js +3 -0
- package/out/modules/integration/types.d.ts +3 -3
- package/out/modules/integration/util/defaults.d.ts +1 -0
- package/out/modules/integration/util/defaults.js +18 -7
- package/out/util/connection.js +3 -1
- package/package.json +1 -1
|
@@ -61,6 +61,7 @@ function handle(config, integration) {
|
|
|
61
61
|
}
|
|
62
62
|
message.data = oauthCredentials;
|
|
63
63
|
if (((_p = integration.oauthLogin) === null || _p === void 0 ? void 0 : _p.mode) === 'polling' && state) {
|
|
64
|
+
yield (0, storage_1.getStorage)().deleteMetadata(state);
|
|
64
65
|
yield (0, storage_1.getStorage)().saveMetadata(state, oauthCredentials);
|
|
65
66
|
}
|
|
66
67
|
return res.render('oauth', { message: JSON.stringify(message), oauthMode: (_q = integration.oauthLogin) === null || _q === void 0 ? void 0 : _q.mode });
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const storage_1 = require("../../../storage");
|
|
12
13
|
const util_1 = require("../../../util");
|
|
13
14
|
const defaults_1 = require("../util/defaults");
|
|
14
15
|
function handle(config, integration) {
|
|
@@ -21,6 +22,8 @@ function handle(config, integration) {
|
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
24
|
const { loginForm } = req.body;
|
|
25
|
+
yield (0, storage_1.getStorage)().deleteMetadata((0, defaults_1.getOAuthLoginFormId)(req.crowdinContext.clientId));
|
|
26
|
+
yield (0, storage_1.getStorage)().saveMetadata((0, defaults_1.getOAuthLoginFormId)(req.crowdinContext.clientId), loginForm);
|
|
24
27
|
const url = (0, defaults_1.constructOauthUrl)({ config, integration, clientId: req.crowdinContext.clientId, loginForm });
|
|
25
28
|
res.send({ url });
|
|
26
29
|
}));
|
|
@@ -170,7 +170,7 @@ export interface OAuthLogin {
|
|
|
170
170
|
/**
|
|
171
171
|
* Authorization url getter
|
|
172
172
|
*/
|
|
173
|
-
getAuthorizationUrl?: (redirectUrl: string, loginForm
|
|
173
|
+
getAuthorizationUrl?: (redirectUrl: string, loginForm: any) => string;
|
|
174
174
|
/**
|
|
175
175
|
* Access token url (e.g. https://github.com/login/oauth/access_token)
|
|
176
176
|
*/
|
|
@@ -264,11 +264,11 @@ export interface OAuthLogin {
|
|
|
264
264
|
*/
|
|
265
265
|
performGetTokenRequest?: (code: string, query: {
|
|
266
266
|
[key: string]: any;
|
|
267
|
-
}, url: string) => Promise<any>;
|
|
267
|
+
}, url: string, loginForm?: any) => Promise<any>;
|
|
268
268
|
/**
|
|
269
269
|
* Override to implement request for refreshing token (only if 'refresh' is enabled)
|
|
270
270
|
*/
|
|
271
|
-
performRefreshTokenRequest?: (currentCredentials: any) => Promise<any>;
|
|
271
|
+
performRefreshTokenRequest?: (currentCredentials: any, loginForm?: any) => Promise<any>;
|
|
272
272
|
}
|
|
273
273
|
export interface File {
|
|
274
274
|
id: string;
|
|
@@ -11,3 +11,4 @@ export declare function constructOauthUrl({ config, integration, clientId, login
|
|
|
11
11
|
loginForm?: any;
|
|
12
12
|
}): string | undefined;
|
|
13
13
|
export declare function getOAuthPollingId(clientId: string): string;
|
|
14
|
+
export declare function getOAuthLoginFormId(clientId: string): string;
|
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.getOAuthPollingId = exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
|
|
35
|
+
exports.getOAuthLoginFormId = exports.getOAuthPollingId = exports.constructOauthUrl = exports.applyIntegrationModuleDefaults = exports.getOauthRoute = exports.getRootFolder = void 0;
|
|
36
36
|
const crowdinAppFunctions = __importStar(require("@crowdin/crowdin-apps-functions"));
|
|
37
37
|
function getRootFolder(config, integration, client, projectId) {
|
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -258,25 +258,32 @@ function applyIntegrationModuleDefaults(config, integration) {
|
|
|
258
258
|
}
|
|
259
259
|
exports.applyIntegrationModuleDefaults = applyIntegrationModuleDefaults;
|
|
260
260
|
function constructOauthUrl({ config, integration, clientId, loginForm, }) {
|
|
261
|
-
var _a, _b, _c, _d;
|
|
261
|
+
var _a, _b, _c, _d, _e;
|
|
262
262
|
const oauth = integration.oauthLogin;
|
|
263
263
|
if (!oauth) {
|
|
264
264
|
return;
|
|
265
265
|
}
|
|
266
266
|
if (oauth.getAuthorizationUrl) {
|
|
267
|
-
|
|
267
|
+
if (!loginForm) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
let url = oauth.getAuthorizationUrl(`${config.baseUrl}${getOauthRoute(integration)}`, loginForm);
|
|
271
|
+
if (oauth.mode === 'polling') {
|
|
272
|
+
url += `&${((_a = oauth.fieldsMapping) === null || _a === void 0 ? void 0 : _a.state) || 'state'}=${getOAuthPollingId(clientId)}`;
|
|
273
|
+
}
|
|
274
|
+
return url;
|
|
268
275
|
}
|
|
269
276
|
if (!oauth.authorizationUrl) {
|
|
270
277
|
return;
|
|
271
278
|
}
|
|
272
279
|
let url = oauth.authorizationUrl || '';
|
|
273
|
-
url += `?${((
|
|
274
|
-
url += `&${((
|
|
280
|
+
url += `?${((_b = oauth.fieldsMapping) === null || _b === void 0 ? void 0 : _b.clientId) || 'client_id'}=${oauth.clientId}`;
|
|
281
|
+
url += `&${((_c = oauth.fieldsMapping) === null || _c === void 0 ? void 0 : _c.redirectUri) || 'redirect_uri'}=${config.baseUrl}${getOauthRoute(integration)}`;
|
|
275
282
|
if (oauth.scope) {
|
|
276
|
-
url += `&${((
|
|
283
|
+
url += `&${((_d = oauth.fieldsMapping) === null || _d === void 0 ? void 0 : _d.scope) || 'scope'}=${oauth.scope}`;
|
|
277
284
|
}
|
|
278
285
|
if (oauth.mode === 'polling') {
|
|
279
|
-
url += `&${((
|
|
286
|
+
url += `&${((_e = oauth.fieldsMapping) === null || _e === void 0 ? void 0 : _e.state) || 'state'}=${getOAuthPollingId(clientId)}`;
|
|
280
287
|
}
|
|
281
288
|
if (oauth.extraAutorizationUrlParameters) {
|
|
282
289
|
Object.entries(oauth.extraAutorizationUrlParameters).forEach(([key, value]) => (url += `&${key}=${value}`));
|
|
@@ -288,3 +295,7 @@ function getOAuthPollingId(clientId) {
|
|
|
288
295
|
return `oauth_${clientId}`;
|
|
289
296
|
}
|
|
290
297
|
exports.getOAuthPollingId = getOAuthPollingId;
|
|
298
|
+
function getOAuthLoginFormId(clientId) {
|
|
299
|
+
return `oauth_form_${clientId}`;
|
|
300
|
+
}
|
|
301
|
+
exports.getOAuthLoginFormId = getOAuthLoginFormId;
|
package/out/util/connection.js
CHANGED
|
@@ -45,6 +45,7 @@ const types_1 = require("../types");
|
|
|
45
45
|
const axios_2 = require("./axios");
|
|
46
46
|
const logger_1 = require("./logger");
|
|
47
47
|
const os = __importStar(require("os"));
|
|
48
|
+
const defaults_1 = require("../modules/integration/util/defaults");
|
|
48
49
|
const axiosCustom = new axios_2.AxiosProvider().axios;
|
|
49
50
|
function prepareCrowdinClient({ config, credentials, autoRenew = false, context, }) {
|
|
50
51
|
var _a, _b;
|
|
@@ -231,7 +232,8 @@ function prepareIntegrationCredentials(config, integration, integrationCredentia
|
|
|
231
232
|
(0, logger_1.log)('Integration credentials have expired. Requesting a new credentials');
|
|
232
233
|
let newCredentials;
|
|
233
234
|
if (performRefreshTokenRequest) {
|
|
234
|
-
|
|
235
|
+
const loginForm = yield (0, storage_1.getStorage)().getMetadata((0, defaults_1.getOAuthLoginFormId)(integrationCredentials.id));
|
|
236
|
+
newCredentials = yield performRefreshTokenRequest(credentials, loginForm);
|
|
235
237
|
}
|
|
236
238
|
else if (oauthLogin) {
|
|
237
239
|
const url = oauthLogin.refreshTokenUrl || oauthLogin.accessTokenUrl;
|
package/package.json
CHANGED