Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("regexp matches will provide proper variables", async () => {
const body = await request.post(url + "/api/login/123").then(toJson);
expect(body.requesterInformation.receivedParams.action).toEqual("login");
expect(body.requesterInformation.receivedParams.userID).toEqual("123");
const bodyAgain = await request
.post(url + "/api/login/admin")
.then(toJson);
expect(bodyAgain.requesterInformation.receivedParams.action).toEqual(
"login"
);
expect(bodyAgain.requesterInformation.receivedParams.userID).toEqual(
"admin"
);
});
public static getAccessToken(host: string, apiToken: string) {
const base64ApiToken = new Buffer('apitoken:' + apiToken).toString('base64');
const options = {
url: host + '/services/mtm/v1/oauth2/token',
headers: { 'Authorization': 'Basic ' + base64ApiToken },
form: { grant_type: 'client_credentials' }
};
return rp.post(options)
.then(response => JSON.parse(response)['access_token']);
}
async sendChunk(rows: Hub.JsonDetail.Row[], mapping: any) {
const chunk = rows.slice(0)
const body: MparticleBulkEvent[] = []
chunk.forEach((row: Hub.JsonDetail.Row) => {
const eventEntry = this.createEvent(row, mapping)
body.push(eventEntry)
})
const options = this.postOptions(body)
await httpRequest.post(options).promise().catch((e: any) => {
this.errors.push(`${e.statusCode} - ${mparticleErrorCodes[e.statusCode]}`)
})
}
post(url: URL, data = {}) {
log.http("POST", `${logFriendlyUrl(url)} ${truncate(JSON.stringify(data), 60)}`)
return r
.post({
uri: url.href,
json: true,
form: data,
headers: {
"user-agent": `speedcurve-cli/${VERSION}`
}
})
.catch(this.normaliseErrorResponse)
}