ton-logger
Version:
Logger set and configurations for datadog
42 lines (41 loc) • 1.45 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDevicePayload = void 0;
const remove_empty_keys_1 = __importDefault(require("./remove-empty-keys"));
const getDevicePayload = (event) => {
const { headers } = event;
if (!headers) {
return undefined;
}
const authorization = headers.Authorization || headers.authorization;
if (!authorization) {
return undefined;
}
const payload = authorization.split('.')[1];
if (!payload) {
return undefined;
}
try {
return JSON.parse(Buffer.from(payload, 'base64').toString('utf-8'));
}
catch (error) {
return undefined;
}
};
exports.getDevicePayload = getDevicePayload;
exports.default = (event) => {
var _a;
const context = (_a = event.requestContext) === null || _a === void 0 ? void 0 : _a.authorizer;
const payload = (0, exports.getDevicePayload)(event);
if (!payload) {
return undefined;
}
return (0, remove_empty_keys_1.default)({
id: context === null || context === void 0 ? void 0 : context.device_id,
installation: context === null || context === void 0 ? void 0 : context.installation_id,
jti: context === null || context === void 0 ? void 0 : context.accessTokenId,
});
};