'use strict'; const zlib = require('zlib'); /** * Build a posprint:// URL from a .pos document (object or JSON string). * * Encoding: UTF-8 JSON → raw deflate → base64url (no padding). * * @param {object|string} pos * @param {{ noconfirm?: boolean, referrer?: string }} [options] * @returns {string} */ function posprintUrl(pos, options = {}) { const json = typeof pos === 'string' ? pos : JSON.stringify(pos); const compressed = zlib.deflateRawSync(Buffer.from(json, 'utf8'), { level: 9 }); const b64 = compressed.toString('base64url'); let url = `posprint://print?v=1&d=${b64}`; if (options.noconfirm) { url += '&noconfirm=1'; } if (options.referrer) { const ref = String(options.referrer).trim(); if (ref) { url += `&referrer=${encodeURIComponent(ref)}`; } } return url; } module.exports = { posprintUrl };