1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", { value: true });
|
8 | const _ = require("lodash");
|
9 | const almError = require("./core/almError");
|
10 | const defaultConnectedApp = require('./core/defaultConnectedApp');
|
11 | const Messages = require("./messages");
|
12 | const messages = Messages();
|
13 | const BUNDLE_NAME = 'IndexErrorProcessor';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var CheckStatus;
|
19 | (function (CheckStatus) {
|
20 | CheckStatus[CheckStatus["OK"] = 0] = "OK";
|
21 | })(CheckStatus = exports.CheckStatus || (exports.CheckStatus = {}));
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | function getProcessors(appConfig, context, err) {
|
30 | return [
|
31 | checkVersionMisMatchAsync(context, err),
|
32 | checkServer500(err),
|
33 | checkOauthAnd404(appConfig, context, err),
|
34 | checkInvalidLoginUrlWithAccessToken(context, err)
|
35 | ];
|
36 | }
|
37 | exports.getProcessors = getProcessors;
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | function checkOauthAnd404(appConfig, context, err) {
|
45 | if (context && err && (err.name === 'invalid_grant' || err.name === 'ERROR_HTTP_404')) {
|
46 | const notFoundMessage = messages.getMessage('notSpecified');
|
47 | let authConfig = {};
|
48 | if (context.org) {
|
49 | authConfig = context.org.authConfig;
|
50 | }
|
51 | else {
|
52 | _.set(authConfig, 'username', context.flags.username);
|
53 | _.set(authConfig, 'clientId', context.flags.clientid);
|
54 | _.set(authConfig, 'privateKey', context.flags.jwtkeyfile);
|
55 | if (appConfig) {
|
56 | _.set(authConfig, 'loginUrl', appConfig.sfdcLoginUrl);
|
57 | }
|
58 | }
|
59 | throw almError('oauthInvalidGrant', [
|
60 |
|
61 |
|
62 | err.name.includes('404') ? err.name : `${err.name} - ${err.message}`,
|
63 | _.isNil(authConfig.username) ? notFoundMessage : authConfig.username,
|
64 | _.isNil(authConfig.clientId) || authConfig.clientId === defaultConnectedApp.legacyClientId
|
65 | ? notFoundMessage
|
66 | : authConfig.clientId,
|
67 | _.isNil(authConfig.loginUrl) ? notFoundMessage : authConfig.loginUrl,
|
68 | _.isNil(authConfig.privateKey) ? notFoundMessage : authConfig.privateKey
|
69 | ], 'oauthInvalidGrantAction');
|
70 | }
|
71 | return CheckStatus.OK;
|
72 | }
|
73 | exports.checkOauthAnd404 = checkOauthAnd404;
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | async function checkVersionMisMatchAsync(context, _err) {
|
80 | if (_err && _err.name === 'NOT_FOUND') {
|
81 | if (context && context.org) {
|
82 | const maxApiVersionForOrg = await context.org.retrieveMaxApiVersion();
|
83 | const configVersion = context.org.force.config.getApiVersion();
|
84 | if (_.toNumber(configVersion) > _.toNumber(maxApiVersionForOrg.version)) {
|
85 | throw almError({ bundle: BUNDLE_NAME, keyName: 'apiMisMatch' }, [configVersion, maxApiVersionForOrg.version], {
|
86 | keyName: 'apiMisMatchAction',
|
87 | bundle: BUNDLE_NAME
|
88 | });
|
89 | }
|
90 | }
|
91 | }
|
92 | return CheckStatus.OK;
|
93 | }
|
94 | exports.checkVersionMisMatchAsync = checkVersionMisMatchAsync;
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | function checkServer500(_err) {
|
101 | if (_err && _err.name === 'ERROR_HTTP_500' && _.isEmpty(_.trim(_err.message))) {
|
102 | throw almError({ bundle: BUNDLE_NAME, keyName: 'server500' }, null, {
|
103 | bundle: BUNDLE_NAME,
|
104 | keyName: 'server500Action'
|
105 | });
|
106 | }
|
107 | return CheckStatus.OK;
|
108 | }
|
109 | exports.checkServer500 = checkServer500;
|
110 | function checkInvalidLoginUrlWithAccessToken(context, err) {
|
111 |
|
112 | if (context.org &&
|
113 | context.org.usingAccessToken &&
|
114 | (err.message.match(/Session expired or invalid/) || err.message.match(/Destination URL not reset/))) {
|
115 | err['message'] = messages.getMessage('accessTokenLoginUrlNotSet', err.message);
|
116 | if (_.isNil(err.action)) {
|
117 | err['action'] = messages.getMessage('invalidInstanceUrlForAccessTokenAction');
|
118 | }
|
119 | throw err;
|
120 | }
|
121 | return CheckStatus.OK;
|
122 | }
|
123 | exports.checkInvalidLoginUrlWithAccessToken = checkInvalidLoginUrlWithAccessToken;
|
124 |
|
125 |
|