UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

64 lines (62 loc) • 2.3 kB
let node_fs = require("node:fs"); let node_path = require("node:path"); let node_os = require("node:os"); //#region src/auth-session.ts const SESSION_FILE_NAME = "session.json"; function getSessionFilePath(configDir) { return (0, node_path.join)(configDir, ".bos", SESSION_FILE_NAME); } function readSessionHandle(configDir) { const filePath = getSessionFilePath(configDir); if (!(0, node_fs.existsSync)(filePath)) return null; try { const parsed = JSON.parse((0, node_fs.readFileSync)(filePath, "utf-8")); if (parsed.version !== 1) return null; return { version: 1, credential: parsed.credential ?? null, publishKey: parsed.publishKey ?? null, delegateKey: parsed.delegateKey ?? null }; } catch { return null; } } function writeSessionHandle(configDir, session) { const bosDir = (0, node_path.join)(configDir, ".bos"); (0, node_fs.mkdirSync)(bosDir, { recursive: true }); (0, node_fs.writeFileSync)(getSessionFilePath(configDir), `${JSON.stringify(session, null, 2)}\n`, { mode: 384 }); } function updateSessionHandle(configDir, update) { const next = update(readSessionHandle(configDir) ?? { version: 1, credential: null, publishKey: null, delegateKey: null }); writeSessionHandle(configDir, next); return next; } function deleteSessionHandle(configDir) { const filePath = getSessionFilePath(configDir); if ((0, node_fs.existsSync)(filePath)) (0, node_fs.rmSync)(filePath); } function nearCredentialsPath(network, account) { return (0, node_path.join)((0, node_os.homedir)(), ".near-credentials", network, `${account}.json`); } function removePublishedKeyFile(network, account, publicKey) { const filePath = nearCredentialsPath(network, account); if (!(0, node_fs.existsSync)(filePath)) return; try { if (JSON.parse((0, node_fs.readFileSync)(filePath, "utf-8")).public_key === publicKey) (0, node_fs.rmSync)(filePath); } catch {} } //#endregion exports.deleteSessionHandle = deleteSessionHandle; exports.getSessionFilePath = getSessionFilePath; exports.nearCredentialsPath = nearCredentialsPath; exports.readSessionHandle = readSessionHandle; exports.removePublishedKeyFile = removePublishedKeyFile; exports.updateSessionHandle = updateSessionHandle; exports.writeSessionHandle = writeSessionHandle; //# sourceMappingURL=auth-session.cjs.map