UNPKG

bugyo-cloud-client

Version:
45 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseUserCode = exports.parseToken = void 0; const cheerio_1 = require("cheerio"); /** * ページ中にある__RequestVerificationTokenを返します。 * @param html HTML */ const parseToken = (html) => { const $ = (0, cheerio_1.load)(html); const ele = $("input[name=__RequestVerificationToken]"); if (ele.length === 0) { throw new Error("Cannot find a element of __RequestVerificationToken."); } const val = ele.val(); if (val === undefined) { throw new Error("Cannot get a value attribute of the __RequestVerificationToken."); } if (Array.isArray(val)) { throw new Error("Too many __RequestVerificationToken input fields. "); } return val; }; exports.parseToken = parseToken; /** * ページ中にある #ApplicationRoot の href 属性から userCode を返します。 * * @param html * @returns */ const parseUserCode = (html) => { const $ = (0, cheerio_1.load)(html); const href = $("#ApplicationRoot")?.attr("href"); if (!href) { throw new Error("Cannot find a element of #ApplicationRoot."); } // /{tenantCode}/{userCode}/ const parts = href.split("/"); if (!parts[2]) { throw new Error(`Cannot parse userCode from #ApplicationRoot. href=${href}`); } return parts[2]; }; exports.parseUserCode = parseUserCode; //# sourceMappingURL=page-parser.js.map