Skip to content
59 changes: 36 additions & 23 deletions examples/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions lib/src/utils/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable no-console */
import axios, { AxiosError, AxiosInstance } from 'axios';

export const prepareAxiosLogs = (client: AxiosInstance): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
client.interceptors.request.use((config: any) => {
// eslint-disable-next-line no-param-reassign
config.metadata = { startTime: new Date().getTime() };
console.log(`> REQUEST: ${config.method?.toUpperCase()} ${config.baseURL}${config.url}`);
console.log(
JSON.stringify({
baseURL: config.baseURL,
url: config.url,
params: config.params,
method: config.method,
headers: config.headers,
status: config.status,
data: config.data,
}),
);
return config;
});

client.interceptors.response.use(
(response) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const elapsedTime = new Date().getTime() - response.config.metadata.startTime;
console.log(`> RESPONSE: ${response.status} (${elapsedTime}ms)`);
console.log(
JSON.stringify({
status: response.status,
headers: response.headers,
data: response.data,
}),
);
return response;
},
// eslint-disable-next-line promise/prefer-await-to-callbacks
(error: Error | AxiosError) => {
if (axios.isAxiosError(error)) {
console.log(`RESPONSE ERROR: status=${error.response?.status}`);
console.log(
JSON.stringify({
status: error.response?.status,
headers: error.response?.headers,
data: error.response?.data,
}),
);
}
throw error;
},
);
};
12 changes: 6 additions & 6 deletions lib/src/wso2/wso2-api/handler/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,12 @@ describe('wso2 custom resource lambda', () => {
}

// api get endpoint urls mock
// nocks.push(
// nock(baseWso2Url)
// .get(/.*\/store\/v1\/apis\/123-456$/)
// .times(1)
// .reply(200, testDefs),
// );
nocks.push(
nock(baseWso2Url)
.get(/.*\/store\/v1\/apis\/123-456$/)
.times(1)
.reply(200, testDefs),
);

// api get apis mock
nocks.push(
Expand Down
38 changes: 19 additions & 19 deletions lib/src/wso2/wso2-api/handler/wso2-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import isEqual from 'lodash.isequal';

import {
ApiFromListV1,
DevPortalAPIv1,
PublisherPortalAPIv1,
Wso2ApiDefinitionV1,
Wso2ApiListV1,
Expand Down Expand Up @@ -158,27 +159,26 @@ export const createUpdateAndChangeLifecycleStatusInWso2 = async (
}

// get endpoint url
// console.log(`Getting API endpoint url`);
// const apir = await args.wso2Axios.get(`/api/am/store/v1/apis/${wso2ApiId}`);
console.log(`Getting API endpoint url`);
const apir = await args.wso2Axios.get(`/api/am/store/v1/apis/${wso2ApiId}`);

// DISABLING ENDPOINT URL WHILE WE FIX AN ISSUE
const endpointUrl = '';
// // find the endpoint URL of the environment that was defined in this API
// const apid = apir.data as DevPortalAPIv1;
// const endpointUrl = apid.endpointURLs?.reduce((acc, elem) => {
// if (
// elem.environmentName &&
// args.apiDefinition.gatewayEnvironments?.includes(elem.environmentName)
// ) {
// if (elem.URLs?.https) {
// return elem.URLs?.https;
// }
// if (elem.defaultVersionURLs?.https) {
// return elem.defaultVersionURLs?.https;
// }
// }
// return acc;
// }, '');
// find the endpoint URL of the environment that was defined in this API
const apid = apir.data as DevPortalAPIv1;
const endpointUrl = apid.endpointURLs?.reduce((acc, elem) => {
if (
elem.environmentName &&
args.apiDefinition.gatewayEnvironments?.includes(elem.environmentName)
) {
if (elem.URLs?.https) {
return elem.URLs?.https;
}
if (elem.defaultVersionURLs?.https) {
return elem.defaultVersionURLs?.https;
}
}
return acc;
}, '');

console.log('API created/updated successfully on WSO2 server');

Expand Down
Loading
Loading