@bigid/apps-infrastructure-node-js 1.181.1 → 1.181.3
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/lib/services/actionsHubService.d.ts +8 -5
- package/lib/services/actionsHubService.js +12 -9
- package/lib/services/bigidProxyService.d.ts +1 -0
- package/lib/services/bigidProxyService.js +28 -1
- package/lib/utils/tokenUtil.d.ts +1 -0
- package/lib/utils/tokenUtil.js +21 -3
- package/package.json +1 -1
- package/src/services/actionsHubService.ts +15 -10
- package/src/services/bigidProxyService.ts +32 -1
- package/src/utils/tokenUtil.ts +17 -1
|
@@ -14,7 +14,7 @@ export type Command = {
|
|
|
14
14
|
*
|
|
15
15
|
* @return {Promise<Command[]>} array of the action-center register commands
|
|
16
16
|
*/
|
|
17
|
-
export declare const getCommandsRegistrations: () => Promise<Command[]>;
|
|
17
|
+
export declare const getCommandsRegistrations: (accessToken?: string) => Promise<Command[]>;
|
|
18
18
|
/**
|
|
19
19
|
* use this method to execute an action-center commands.
|
|
20
20
|
* this method is used without endpoint for getting status messages, but rather return an execution id.
|
|
@@ -25,21 +25,24 @@ export declare const getCommandsRegistrations: () => Promise<Command[]>;
|
|
|
25
25
|
* @param {string} requestorAppName - the app name of the execution requestor.
|
|
26
26
|
* @param {string} webhookEndpoint - the endpoint of the requestor app to receive execution status messages.
|
|
27
27
|
* @param {Record<string, any>} params - the relevant params of the action to be executed.
|
|
28
|
+
* @param {string} accessToken -- the access token from BigId.
|
|
28
29
|
* @return {Promise<string>} execution id of the executed action.
|
|
29
30
|
*/
|
|
30
|
-
export declare const executeCommand: (actionName: string, command: string, requestorAppName?: string, webhookEndpoint?: string, params?: Record<string, any>[]) => Promise<string>;
|
|
31
|
+
export declare const executeCommand: (actionName: string, command: string, requestorAppName?: string, webhookEndpoint?: string, params?: Record<string, any>[], accessToken?: string) => Promise<string>;
|
|
31
32
|
/**
|
|
32
33
|
* use this method to poll an execution status from the action-center.
|
|
33
34
|
*
|
|
34
|
-
* @param {string}
|
|
35
|
+
* @param {string} executionId - the execution id to poll status for.
|
|
36
|
+
* @param {string} accessToken - the access token from BigId.
|
|
35
37
|
* @return object with the updated status details.
|
|
36
38
|
*/
|
|
37
|
-
export declare const getExecutionStatus: (executionId: string) => Promise<any>;
|
|
39
|
+
export declare const getExecutionStatus: (executionId: string, accessToken?: string) => Promise<any>;
|
|
38
40
|
/**
|
|
39
41
|
* use this method to register application action as an action center command.
|
|
40
42
|
*
|
|
41
43
|
* @param {string} applicationName - the application name of the command to be registered.
|
|
42
44
|
* @param {string} actionName - the action name of the command to be registered.
|
|
43
45
|
* @param {string} command - the command to be registered.
|
|
46
|
+
* @param {string} accessToken - - the access token from BigId.
|
|
44
47
|
*/
|
|
45
|
-
export declare const registerActionAsCommand: (applicationName: string, actionName: string, command: string) => Promise<void>;
|
|
48
|
+
export declare const registerActionAsCommand: (applicationName: string, actionName: string, command: string, accessToken?: string) => Promise<void>;
|
|
@@ -25,9 +25,9 @@ const getBigidAccessToken = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
25
25
|
*
|
|
26
26
|
* @return {Promise<Command[]>} array of the action-center register commands
|
|
27
27
|
*/
|
|
28
|
-
const getCommandsRegistrations = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
const getCommandsRegistrations = (accessToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
29
|
try {
|
|
30
|
-
const bigidToken = yield getBigidAccessToken();
|
|
30
|
+
const bigidToken = accessToken || (yield getBigidAccessToken());
|
|
31
31
|
const { data: { commands }, } = yield (0, bigidProxyService_1.doCallToUrl)(bigidToken, bigidProxyService_1.RequestMethod.GET, `${process.env.BIGID_BASE_URL}/api/v1/action-center/general-commands`);
|
|
32
32
|
return commands;
|
|
33
33
|
}
|
|
@@ -46,11 +46,12 @@ exports.getCommandsRegistrations = getCommandsRegistrations;
|
|
|
46
46
|
* @param {string} requestorAppName - the app name of the execution requestor.
|
|
47
47
|
* @param {string} webhookEndpoint - the endpoint of the requestor app to receive execution status messages.
|
|
48
48
|
* @param {Record<string, any>} params - the relevant params of the action to be executed.
|
|
49
|
+
* @param {string} accessToken -- the access token from BigId.
|
|
49
50
|
* @return {Promise<string>} execution id of the executed action.
|
|
50
51
|
*/
|
|
51
|
-
const executeCommand = (actionName, command, requestorAppName, webhookEndpoint, params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const executeCommand = (actionName, command, requestorAppName, webhookEndpoint, params, accessToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
53
|
try {
|
|
53
|
-
const bigidToken = yield getBigidAccessToken();
|
|
54
|
+
const bigidToken = accessToken || (yield getBigidAccessToken());
|
|
54
55
|
const { data: { executionId }, } = yield (0, bigidProxyService_1.doCallToUrl)(bigidToken, bigidProxyService_1.RequestMethod.POST, `${process.env.BIGID_BASE_URL}/api/v1/action-center/general-commands/execute`, Object.assign({ actionName,
|
|
55
56
|
command, feedbackRequestorDetails: requestorAppName && webhookEndpoint
|
|
56
57
|
? {
|
|
@@ -68,12 +69,13 @@ exports.executeCommand = executeCommand;
|
|
|
68
69
|
/**
|
|
69
70
|
* use this method to poll an execution status from the action-center.
|
|
70
71
|
*
|
|
71
|
-
* @param {string}
|
|
72
|
+
* @param {string} executionId - the execution id to poll status for.
|
|
73
|
+
* @param {string} accessToken - the access token from BigId.
|
|
72
74
|
* @return object with the updated status details.
|
|
73
75
|
*/
|
|
74
|
-
const getExecutionStatus = (executionId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
const getExecutionStatus = (executionId, accessToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
77
|
try {
|
|
76
|
-
const bigidToken = yield getBigidAccessToken();
|
|
78
|
+
const bigidToken = accessToken || (yield getBigidAccessToken());
|
|
77
79
|
const { data } = yield (0, bigidProxyService_1.doCallToUrl)(bigidToken, bigidProxyService_1.RequestMethod.GET, `${process.env.BIGID_BASE_URL}/api/v1/action-center/general-commands/execute/${executionId}`);
|
|
78
80
|
return data;
|
|
79
81
|
}
|
|
@@ -88,10 +90,11 @@ exports.getExecutionStatus = getExecutionStatus;
|
|
|
88
90
|
* @param {string} applicationName - the application name of the command to be registered.
|
|
89
91
|
* @param {string} actionName - the action name of the command to be registered.
|
|
90
92
|
* @param {string} command - the command to be registered.
|
|
93
|
+
* @param {string} accessToken - - the access token from BigId.
|
|
91
94
|
*/
|
|
92
|
-
const registerActionAsCommand = (applicationName, actionName, command) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
const registerActionAsCommand = (applicationName, actionName, command, accessToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
96
|
try {
|
|
94
|
-
const bigidToken = yield getBigidAccessToken();
|
|
97
|
+
const bigidToken = accessToken || (yield getBigidAccessToken());
|
|
95
98
|
yield (0, bigidProxyService_1.doCallToUrl)(bigidToken, bigidProxyService_1.RequestMethod.POST, `${process.env.BIGID_BASE_URL}/api/v1/action-center/general-commands/register`, {
|
|
96
99
|
applicationName,
|
|
97
100
|
actionName,
|
|
@@ -35,6 +35,7 @@ export declare const executeHttpPut: (executionContext: ExecutionContext, endpoi
|
|
|
35
35
|
* the endpoint in BigID, used for DELETE requests.
|
|
36
36
|
*/
|
|
37
37
|
export declare const executeHttpDelete: (executionContext: ExecutionContext, endpoint: string) => Promise<any>;
|
|
38
|
+
export declare const executePost: (requestMethod: RequestMethod, baseUrl: string | undefined, bodyJson: Record<string, any>) => Promise<any>;
|
|
38
39
|
export declare const uploadAttachment: (executionContext: ExecutionContext, filePathToUpload: string) => import("axios").AxiosPromise<any>;
|
|
39
40
|
export declare const getAppStorage: (executionContext: ExecutionContext) => Promise<any>;
|
|
40
41
|
export declare const getValueFromAppStorage: (executionContext: ExecutionContext, key: string) => Promise<string>;
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.saveInStorage = exports.sendBiEvent = exports.deleteKeyFromAppStorage = exports.getValueFromAppStorage = exports.getAppStorage = exports.uploadAttachment = exports.executeHttpDelete = exports.executeHttpPut = exports.executeHttpPost = exports.executeHttpGet = exports.updateActionStatusToBigID = exports.doCallToUrl = exports.getTenantRegistrations = exports.RequestMethod = void 0;
|
|
15
|
+
exports.saveInStorage = exports.sendBiEvent = exports.deleteKeyFromAppStorage = exports.getValueFromAppStorage = exports.getAppStorage = exports.uploadAttachment = exports.executePost = exports.executeHttpDelete = exports.executeHttpPut = exports.executeHttpPost = exports.executeHttpGet = exports.updateActionStatusToBigID = exports.doCallToUrl = exports.getTenantRegistrations = exports.RequestMethod = void 0;
|
|
16
16
|
const fs_1 = require("fs");
|
|
17
17
|
const https_1 = require("https");
|
|
18
18
|
const form_data_1 = __importDefault(require("form-data"));
|
|
@@ -100,6 +100,33 @@ exports.executeHttpPut = executeHttpPut;
|
|
|
100
100
|
*/
|
|
101
101
|
const executeHttpDelete = (executionContext, endpoint) => __awaiter(void 0, void 0, void 0, function* () { return yield callBigIdApi(executionContext, RequestMethod.DELETE, endpoint); });
|
|
102
102
|
exports.executeHttpDelete = executeHttpDelete;
|
|
103
|
+
const executePost = (requestMethod, baseUrl, bodyJson) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
var _a, _b, _c, _d, _e, _f;
|
|
105
|
+
try {
|
|
106
|
+
const url = baseUrl + 'api/v1/sessions';
|
|
107
|
+
const headers = {
|
|
108
|
+
Accept: 'application/json',
|
|
109
|
+
'Content-type': 'application/json',
|
|
110
|
+
};
|
|
111
|
+
const requestObj = {
|
|
112
|
+
method: requestMethod,
|
|
113
|
+
url: url,
|
|
114
|
+
headers: headers,
|
|
115
|
+
};
|
|
116
|
+
if (bodyJson && (Object === null || Object === void 0 ? void 0 : Object.keys(bodyJson).length) > 0) {
|
|
117
|
+
requestObj.data = bodyJson;
|
|
118
|
+
}
|
|
119
|
+
const res = yield (0, axios_1.default)(requestObj);
|
|
120
|
+
(0, utils_1.logInfo)(`<-- bigid-proxy::executePost: ${baseUrl} success`);
|
|
121
|
+
return res;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
(0, utils_1.logError)(`<-- bigid-proxy::executePost: error calling: ${baseUrl}, error: ${error}`);
|
|
125
|
+
(0, utils_1.logError)((_c = (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.toString());
|
|
126
|
+
return (_f = (_e = (_d = error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.message) === null || _f === void 0 ? void 0 : _f.toString();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
exports.executePost = executePost;
|
|
103
130
|
const uploadAttachment = (executionContext, filePathToUpload) => {
|
|
104
131
|
const formData = new form_data_1.default();
|
|
105
132
|
formData.append('file', (0, fs_1.createReadStream)(filePathToUpload));
|
package/lib/utils/tokenUtil.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare const getAccessTokenFromRefreshToken: (refreshToken: string) => Promise<string>;
|
|
2
|
+
export declare const getTokenByUsernameAndPassword: (username?: string, password?: string) => Promise<string>;
|
|
2
3
|
export declare const getAuth0Token: () => Promise<string>;
|
|
3
4
|
export declare const tokenExchange: (auth0Token: string, tenantId?: string) => Promise<string>;
|
package/lib/utils/tokenUtil.js
CHANGED
|
@@ -12,10 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.tokenExchange = exports.getAuth0Token = exports.getAccessTokenFromRefreshToken = void 0;
|
|
15
|
+
exports.tokenExchange = exports.getAuth0Token = exports.getTokenByUsernameAndPassword = exports.getAccessTokenFromRefreshToken = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
17
|
const https_1 = require("https");
|
|
18
18
|
const services_1 = require("../services");
|
|
19
|
+
const appLogger_1 = require("./appLogger");
|
|
19
20
|
const auth0Payload = {
|
|
20
21
|
client_id: process.env.CLIENT_ID,
|
|
21
22
|
client_secret: process.env.CLIENT_SECRET,
|
|
@@ -33,11 +34,28 @@ const getAccessTokenFromRefreshToken = (refreshToken) => __awaiter(void 0, void
|
|
|
33
34
|
return accessToken;
|
|
34
35
|
});
|
|
35
36
|
exports.getAccessTokenFromRefreshToken = getAccessTokenFromRefreshToken;
|
|
37
|
+
const getTokenByUsernameAndPassword = (username, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
var _a, _b, _c, _d, _e;
|
|
39
|
+
try {
|
|
40
|
+
const requestBody = {
|
|
41
|
+
username: username || process.env.USERNAME,
|
|
42
|
+
password: password || process.env.PASSWORD,
|
|
43
|
+
};
|
|
44
|
+
const res = yield (0, services_1.executePost)(services_1.RequestMethod.POST, process.env.BIGID_BASE_URL, requestBody);
|
|
45
|
+
return (_b = (_a = res.data) === null || _a === void 0 ? void 0 : _a.auth_token) === null || _b === void 0 ? void 0 : _b.toString();
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
const errorMessage = (_e = (_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) === null || _e === void 0 ? void 0 : _e.toString();
|
|
49
|
+
(0, appLogger_1.logError)(errorMessage);
|
|
50
|
+
return errorMessage;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
exports.getTokenByUsernameAndPassword = getTokenByUsernameAndPassword;
|
|
36
54
|
const getAuth0Token = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
var
|
|
55
|
+
var _f;
|
|
38
56
|
if (canUseLocalToken(auth0Token))
|
|
39
57
|
return auth0Token;
|
|
40
|
-
const auth0Domain = (
|
|
58
|
+
const auth0Domain = (_f = process.env.AUTH0_DOMAIN) === null || _f === void 0 ? void 0 : _f.replace(/\/$/, '');
|
|
41
59
|
const { data: { access_token }, } = yield axios_1.default.post(`${auth0Domain}/oauth/token`, auth0Payload);
|
|
42
60
|
auth0Token = access_token;
|
|
43
61
|
return access_token;
|
package/package.json
CHANGED
|
@@ -29,9 +29,9 @@ export type Command = {
|
|
|
29
29
|
*
|
|
30
30
|
* @return {Promise<Command[]>} array of the action-center register commands
|
|
31
31
|
*/
|
|
32
|
-
export const getCommandsRegistrations = async (): Promise<Command[]> => {
|
|
32
|
+
export const getCommandsRegistrations = async (accessToken?: string): Promise<Command[]> => {
|
|
33
33
|
try {
|
|
34
|
-
const bigidToken = await getBigidAccessToken();
|
|
34
|
+
const bigidToken = accessToken || (await getBigidAccessToken());
|
|
35
35
|
const {
|
|
36
36
|
data: { commands },
|
|
37
37
|
} = await doCallToUrl(
|
|
@@ -55,6 +55,7 @@ export const getCommandsRegistrations = async (): Promise<Command[]> => {
|
|
|
55
55
|
* @param {string} requestorAppName - the app name of the execution requestor.
|
|
56
56
|
* @param {string} webhookEndpoint - the endpoint of the requestor app to receive execution status messages.
|
|
57
57
|
* @param {Record<string, any>} params - the relevant params of the action to be executed.
|
|
58
|
+
* @param {string} accessToken -- the access token from BigId.
|
|
58
59
|
* @return {Promise<string>} execution id of the executed action.
|
|
59
60
|
*/
|
|
60
61
|
export const executeCommand = async (
|
|
@@ -63,9 +64,10 @@ export const executeCommand = async (
|
|
|
63
64
|
requestorAppName?: string,
|
|
64
65
|
webhookEndpoint?: string,
|
|
65
66
|
params?: Record<string, any>[],
|
|
67
|
+
accessToken?: string,
|
|
66
68
|
): Promise<string> => {
|
|
67
69
|
try {
|
|
68
|
-
const bigidToken = await getBigidAccessToken();
|
|
70
|
+
const bigidToken = accessToken || (await getBigidAccessToken());
|
|
69
71
|
const {
|
|
70
72
|
data: { executionId },
|
|
71
73
|
} = await doCallToUrl(
|
|
@@ -78,9 +80,9 @@ export const executeCommand = async (
|
|
|
78
80
|
feedbackRequestorDetails:
|
|
79
81
|
requestorAppName && webhookEndpoint
|
|
80
82
|
? {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
requestorAppName,
|
|
84
|
+
requestorFeedbackEndpoint: webhookEndpoint,
|
|
85
|
+
}
|
|
84
86
|
: null,
|
|
85
87
|
...(params && { params }),
|
|
86
88
|
},
|
|
@@ -94,12 +96,13 @@ export const executeCommand = async (
|
|
|
94
96
|
/**
|
|
95
97
|
* use this method to poll an execution status from the action-center.
|
|
96
98
|
*
|
|
97
|
-
* @param {string}
|
|
99
|
+
* @param {string} executionId - the execution id to poll status for.
|
|
100
|
+
* @param {string} accessToken - the access token from BigId.
|
|
98
101
|
* @return object with the updated status details.
|
|
99
102
|
*/
|
|
100
|
-
export const getExecutionStatus = async (executionId: string): Promise<any> => {
|
|
103
|
+
export const getExecutionStatus = async (executionId: string, accessToken?: string): Promise<any> => {
|
|
101
104
|
try {
|
|
102
|
-
const bigidToken = await getBigidAccessToken();
|
|
105
|
+
const bigidToken = accessToken || (await getBigidAccessToken());
|
|
103
106
|
const { data } = await doCallToUrl(
|
|
104
107
|
bigidToken,
|
|
105
108
|
RequestMethod.GET,
|
|
@@ -117,14 +120,16 @@ export const getExecutionStatus = async (executionId: string): Promise<any> => {
|
|
|
117
120
|
* @param {string} applicationName - the application name of the command to be registered.
|
|
118
121
|
* @param {string} actionName - the action name of the command to be registered.
|
|
119
122
|
* @param {string} command - the command to be registered.
|
|
123
|
+
* @param {string} accessToken - - the access token from BigId.
|
|
120
124
|
*/
|
|
121
125
|
export const registerActionAsCommand = async (
|
|
122
126
|
applicationName: string,
|
|
123
127
|
actionName: string,
|
|
124
128
|
command: string,
|
|
129
|
+
accessToken?: string,
|
|
125
130
|
): Promise<void> => {
|
|
126
131
|
try {
|
|
127
|
-
const bigidToken = await getBigidAccessToken();
|
|
132
|
+
const bigidToken = accessToken || (await getBigidAccessToken());
|
|
128
133
|
await doCallToUrl(
|
|
129
134
|
bigidToken,
|
|
130
135
|
RequestMethod.POST,
|
|
@@ -121,6 +121,37 @@ export const executeHttpPut = async (executionContext: ExecutionContext, endpoin
|
|
|
121
121
|
export const executeHttpDelete = async (executionContext: ExecutionContext, endpoint: string) =>
|
|
122
122
|
await callBigIdApi(executionContext, RequestMethod.DELETE, endpoint);
|
|
123
123
|
|
|
124
|
+
export const executePost = async (
|
|
125
|
+
requestMethod: RequestMethod,
|
|
126
|
+
baseUrl: string | undefined,
|
|
127
|
+
bodyJson: Record<string, any>,
|
|
128
|
+
) => {
|
|
129
|
+
try {
|
|
130
|
+
const url = baseUrl + 'api/v1/sessions';
|
|
131
|
+
const headers = {
|
|
132
|
+
Accept: 'application/json',
|
|
133
|
+
'Content-type': 'application/json',
|
|
134
|
+
};
|
|
135
|
+
const requestObj: Record<string, any> = {
|
|
136
|
+
method: requestMethod,
|
|
137
|
+
url: url,
|
|
138
|
+
headers: headers,
|
|
139
|
+
};
|
|
140
|
+
if (bodyJson && Object?.keys(bodyJson).length > 0) {
|
|
141
|
+
requestObj.data = bodyJson;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const res = await axios(requestObj);
|
|
145
|
+
|
|
146
|
+
logInfo(`<-- bigid-proxy::executePost: ${baseUrl} success`);
|
|
147
|
+
return res;
|
|
148
|
+
} catch (error: any) {
|
|
149
|
+
logError(`<-- bigid-proxy::executePost: error calling: ${baseUrl}, error: ${error}`);
|
|
150
|
+
logError(error.response?.data?.message?.toString());
|
|
151
|
+
return error.response?.data?.message?.toString();
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
124
155
|
export const uploadAttachment = (executionContext: ExecutionContext, filePathToUpload: string) => {
|
|
125
156
|
const formData = new FormData();
|
|
126
157
|
formData.append('file', createReadStream(filePathToUpload));
|
|
@@ -169,4 +200,4 @@ export const saveInStorage = async (
|
|
|
169
200
|
value: valueToStore,
|
|
170
201
|
},
|
|
171
202
|
],
|
|
172
|
-
});
|
|
203
|
+
});
|
package/src/utils/tokenUtil.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import { Agent } from 'https';
|
|
3
|
-
import { doCallToUrl, RequestMethod } from '../services';
|
|
3
|
+
import { doCallToUrl, executePost, RequestMethod } from '../services';
|
|
4
|
+
import { logError, logInfo } from './appLogger';
|
|
4
5
|
|
|
5
6
|
const auth0Payload = {
|
|
6
7
|
client_id: process.env.CLIENT_ID,
|
|
@@ -27,6 +28,21 @@ export const getAccessTokenFromRefreshToken = async (refreshToken: string) => {
|
|
|
27
28
|
return accessToken;
|
|
28
29
|
};
|
|
29
30
|
|
|
31
|
+
export const getTokenByUsernameAndPassword = async (username?: string, password?: string): Promise<string> => {
|
|
32
|
+
try {
|
|
33
|
+
const requestBody = {
|
|
34
|
+
username: username || process.env.USERNAME,
|
|
35
|
+
password: password || process.env.PASSWORD,
|
|
36
|
+
};
|
|
37
|
+
const res = await executePost(RequestMethod.POST, process.env.BIGID_BASE_URL, requestBody);
|
|
38
|
+
return res.data?.auth_token?.toString();
|
|
39
|
+
} catch (error: any) {
|
|
40
|
+
const errorMessage = error.response?.data?.message?.toString();
|
|
41
|
+
logError(errorMessage);
|
|
42
|
+
return errorMessage;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
30
46
|
export const getAuth0Token = async (): Promise<string> => {
|
|
31
47
|
if (canUseLocalToken(auth0Token)) return auth0Token;
|
|
32
48
|
const auth0Domain = process.env.AUTH0_DOMAIN?.replace(/\/$/, '');
|