@crowdin/app-project-module 0.60.1 → 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.
|
@@ -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
|
}));
|
|
@@ -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,27 +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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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;
|
|
270
275
|
}
|
|
271
276
|
if (!oauth.authorizationUrl) {
|
|
272
277
|
return;
|
|
273
278
|
}
|
|
274
279
|
let url = oauth.authorizationUrl || '';
|
|
275
|
-
url += `?${((
|
|
276
|
-
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)}`;
|
|
277
282
|
if (oauth.scope) {
|
|
278
|
-
url += `&${((
|
|
283
|
+
url += `&${((_d = oauth.fieldsMapping) === null || _d === void 0 ? void 0 : _d.scope) || 'scope'}=${oauth.scope}`;
|
|
279
284
|
}
|
|
280
285
|
if (oauth.mode === 'polling') {
|
|
281
|
-
url += `&${((
|
|
286
|
+
url += `&${((_e = oauth.fieldsMapping) === null || _e === void 0 ? void 0 : _e.state) || 'state'}=${getOAuthPollingId(clientId)}`;
|
|
282
287
|
}
|
|
283
288
|
if (oauth.extraAutorizationUrlParameters) {
|
|
284
289
|
Object.entries(oauth.extraAutorizationUrlParameters).forEach(([key, value]) => (url += `&${key}=${value}`));
|
|
@@ -290,3 +295,7 @@ function getOAuthPollingId(clientId) {
|
|
|
290
295
|
return `oauth_${clientId}`;
|
|
291
296
|
}
|
|
292
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