|
const crypto = require("crypto"); |
|
const https = require("https"); |
|
const fs = require("fs"); |
|
const axios = require("axios"); |
|
|
|
/** |
|
* Handle this problem with Node 18 |
|
* write EPROTO B8150000:error:0A000152:SSL routines:final_renegotiate:unsafe legacy renegotiation disabled |
|
* see https://stackoverflow.com/questions/74324019/allow-legacy-renegotiation-for-nodejs/74600467#74600467 |
|
**/ |
|
const allowLegacyRenegotiationforNodeJsOptions = { |
|
httpsAgent: new https.Agent({ |
|
// for self signed you could also add |
|
// rejectUnauthorized: false, |
|
// allow legacy server |
|
secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT, |
|
}), |
|
}; |
|
|
|
// Get a token from https://mvp.microsoft.com/en-US/mvp/apply |
|
// - log in and then open the dev tools and look for the Authorization request header which will contain a token in the network tab |
|
// |
|
// Run the following command to set the token in the environment variable |
|
// export TOKEN=token-goes-here |
|
|
|
const token = process.env.TOKEN; |
|
|
|
// https://mavenapi-prod.azurewebsites.net/api/mvp/ApplicationForm/johnny_reilly@hotmail.com |
|
// applicationForm.id = 316008 |
|
// https://mavenapi-prod.azurewebsites.net/api/ApplicationForm/ActivitiesEvents/316008 |
|
// https://mavenapi-prod.azurewebsites.net/api/Activities/154327 |
|
// https://mavenapi-prod.azurewebsites.net/api/Events/GetEvent/20971 |
|
|
|
const primedAxios = axios.default.create({ |
|
...allowLegacyRenegotiationforNodeJsOptions, |
|
headers: { |
|
Accept: "application/json", |
|
"Content-Type": "application/json", |
|
authorization: `Bearer ${token}`, |
|
}, |
|
}); |
|
|
|
/** |
|
* @param {string} email - eg johnny_reilly@hotmail.com |
|
*/ |
|
async function getMvpApplication(email) { |
|
console.log(`Getting application for ${email}`); |
|
const applicationFormResponse = await primedAxios({ |
|
url: `https://mavenapi-prod.azurewebsites.net/api/mvp/ApplicationForm/${email}`, |
|
}); |
|
const applicationForm = applicationFormResponse.data; |
|
|
|
console.log(`Getting activities and events for ${email}`); |
|
const activitiesEventsResponse = await primedAxios({ |
|
url: `https://mavenapi-prod.azurewebsites.net/api/ApplicationForm/ActivitiesEvents/${applicationForm.applicationForm.id}`, |
|
}); |
|
/** |
|
* @type {{mappedEvents: import("./types").MvpEvent[], mappedActivities: import("./types").MvpActivity[]}} |
|
*/ |
|
const { mappedEvents, mappedActivities } = activitiesEventsResponse.data; |
|
|
|
/** @type{import("./types").MvpEvent[]} */ |
|
const events = []; |
|
for (const mappedEvent of mappedEvents) { |
|
console.log(`Getting event ${mappedEvent.eventId}`); |
|
const eventResponse = await primedAxios({ |
|
url: `https://mavenapi-prod.azurewebsites.net/api/Events/GetEvent/${mappedEvent.eventId}`, |
|
}); |
|
const event = eventResponse.data; |
|
events.push(event); |
|
} |
|
|
|
/** @type{import("./types").MvpActivity[]} */ |
|
const activities = []; |
|
for (const mappedActivity of mappedActivities) { |
|
console.log(`Getting activity ${mappedActivity.activityId}`); |
|
const activityResponse = await primedAxios({ |
|
url: `https://mavenapi-prod.azurewebsites.net/api/Activities/${mappedActivity.activityId}`, |
|
}); |
|
const activity = activityResponse.data; |
|
activities.push(activity); |
|
} |
|
|
|
const fullData = { |
|
applicationForm, |
|
activities, |
|
events, |
|
}; |
|
|
|
// Save file to disk |
|
fs.writeFileSync("mvp-application-full.json", JSON.stringify(fullData, null, 2)); |
|
} |
|
|
|
getMvpApplication("johnny_reilly@hotmail.com"); |