UNPKG

emvco-qr-sdk

Version:

A robust TypeScript SDK for decoding, validating, and processing EMVCo-compliant QR codes used in digital payment systems.

41 lines (40 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.guiAndTypedStrategy = void 0; const qr_constant_1 = require("../../constants/qr.constant"); const tag_name_resolver_util_1 = require("../../utils/resolvers/tag-name-resolver.util"); /** * Mapping strategy for TLV tags that contain a `gui` and a typed value. * * This is used for structures like tag 26 (merchantAccountInfo) or tag 80 (channel), * which include a GUI (Globally Unique Identifier) subtag ("00"), and a typed value * with a subtag code ("01", "02", etc.). * * Example output: * ```ts * { * gui: "CO.COM.CRB.RED", * rawType: "01", * type: "MOBILE_NUMBER", * value: "3123456789" * } * ``` * * @param tlv - The TLV entity to transform. * @returns An object with `gui`, `rawType`, `type` (resolved name), and `value`. */ const guiAndTypedStrategy = (tlv) => { var _a, _b; const subTags = (_a = tlv.subTags) !== null && _a !== void 0 ? _a : []; const gui = (_b = subTags.find((s) => s.tag === qr_constant_1.TAG_GUI)) === null || _b === void 0 ? void 0 : _b.value; const typed = subTags.find((s) => s.tag !== qr_constant_1.TAG_GUI); return { gui, ...(typed && { rawType: typed.tag, type: tag_name_resolver_util_1.TagNameResolverUtil.getColombianSubtagName(tlv.tag, typed.tag), value: typed.value, }), }; }; exports.guiAndTypedStrategy = guiAndTypedStrategy;