@transcend-io/typescript-webhook-example
Version:
Example of a webhook that can be integrated with Transcend.
48 lines • 1.86 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const got_1 = __importDefault(require("got"));
// Constants
const constants_1 = require("./constants");
const logger_1 = require("./logger");
// Helpers
const helpers_1 = require("./helpers");
/**
* Process an enrichment request - turn one identifier into many
*
* @param userIdentifier - User identifier
* @param nonce - Nonce to respond with
* @param requestLink - Link to request
*/
async function scheduleEnricher(userIdentifier, nonce, requestLink) {
logger_1.logger.info(`Enriching identity - ${requestLink}`);
// Find user data
// const identifiers = await enrichUser(userIdentifier);
// TODO: Figure out why this is not passing a user identifier
const identifiers = await (0, helpers_1.enrichUser)();
try {
// Upload enriched values to Transcend
await got_1.default.post(`${constants_1.SOMBRA_URL}/v1/enrich-identifiers`, {
headers: {
authorization: `Bearer ${constants_1.TRANSCEND_API_KEY}`,
'x-sombra-authorization': constants_1.SOMBRA_API_KEY
? `Bearer ${constants_1.SOMBRA_API_KEY}`
: undefined,
'x-transcend-nonce': nonce,
accept: 'application/json',
'user-agent': undefined,
},
json: {
enrichedIdentifiers: identifiers,
},
});
logger_1.logger.info(`Successfully enriched user -${requestLink}`);
}
catch (error) {
logger_1.logger.error(`Failed to enriched user -${requestLink}`);
}
}
exports.default = scheduleEnricher;
//# sourceMappingURL=scheduleEnricher.js.map
;