@keyboxed/cli 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/keybox.js +1957 -41
- package/package.json +3 -1
package/dist/keybox.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
8
|
var __esm = (fn, res, err) => function __init() {
|
|
5
9
|
if (err) throw err[0];
|
|
6
10
|
try {
|
|
@@ -9,10 +13,33 @@ var __esm = (fn, res, err) => function __init() {
|
|
|
9
13
|
throw err = [e], e;
|
|
10
14
|
}
|
|
11
15
|
};
|
|
16
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
17
|
+
try {
|
|
18
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw mod = 0, e;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
12
23
|
var __export = (target, all) => {
|
|
13
24
|
for (var name in all)
|
|
14
25
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
26
|
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
36
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
37
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
38
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
39
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
40
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
41
|
+
mod
|
|
42
|
+
));
|
|
16
43
|
|
|
17
44
|
// src/config.ts
|
|
18
45
|
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
@@ -791,38 +818,46 @@ function classify(found, existing, opts = {}) {
|
|
|
791
818
|
const unknown = [];
|
|
792
819
|
const seen = /* @__PURE__ */ new Set();
|
|
793
820
|
for (const f of found) {
|
|
794
|
-
|
|
795
|
-
if (
|
|
796
|
-
seen.
|
|
797
|
-
|
|
798
|
-
const
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
821
|
+
const name = /^[A-Z][A-Z0-9_]{0,63}$/.test(f.name) ? f.name : toSecretName(f.name);
|
|
822
|
+
if (opts.only?.length && !opts.only.includes(f.name) && !opts.only.includes(name)) continue;
|
|
823
|
+
if (seen.has(name)) continue;
|
|
824
|
+
seen.add(name);
|
|
825
|
+
const renamed = name !== f.name ? `stored as ${name}` : "";
|
|
826
|
+
const item = { ...f, name };
|
|
827
|
+
const v = f.value.trim();
|
|
828
|
+
if (!v) {
|
|
829
|
+
skipped.push({ name: f.name, why: "empty value" });
|
|
802
830
|
continue;
|
|
803
831
|
}
|
|
804
|
-
if (
|
|
805
|
-
skipped.push({ name: f.name, why:
|
|
806
|
-
continue;
|
|
807
|
-
}
|
|
808
|
-
if (f.value.trim().length < 8 || /^(x+|changeme|todo|your[-_].*|<.*>|\.\.\.)$/i.test(f.value.trim())) {
|
|
809
|
-
skipped.push({ name: f.name, why: "empty or placeholder" });
|
|
832
|
+
if (PLACEHOLDER.test(v)) {
|
|
833
|
+
skipped.push({ name: f.name, why: "placeholder value" });
|
|
810
834
|
continue;
|
|
811
835
|
}
|
|
812
|
-
|
|
813
|
-
|
|
836
|
+
const unsupported = UNSUPPORTED.find((u) => u.match.test(name));
|
|
837
|
+
if (unsupported) {
|
|
838
|
+
skipped.push({ name: f.name, why: unsupported.why });
|
|
814
839
|
continue;
|
|
815
840
|
}
|
|
816
|
-
|
|
817
|
-
|
|
841
|
+
const d = detect(name, f.value);
|
|
842
|
+
const looksLikeKey = f.explicit || CREDENTIAL_NAME.test(name) || d.via === "value";
|
|
843
|
+
const isPublic = PUBLIC_NAME.test(name);
|
|
844
|
+
if (d.provider && looksLikeKey && !isPublic && v.length >= 8) {
|
|
845
|
+
const flags = [];
|
|
846
|
+
if (renamed) flags.push(renamed);
|
|
847
|
+
if (d.adminHint) flags.push("admin-grade");
|
|
848
|
+
if (d.mismatch) flags.push(`name says ${d.mismatch.label}`);
|
|
849
|
+
if (d.via === "name") flags.push("guessed from name");
|
|
850
|
+
plans.push({ ...item, provider: d.provider, hosts: d.provider.hosts, header: d.provider.header, format: d.provider.format, flags, replaces: existing.has(name) });
|
|
818
851
|
continue;
|
|
819
852
|
}
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
853
|
+
const why = [
|
|
854
|
+
isPublic ? "looks like a public value" : !looksLikeKey ? "name doesn't look like a key" : v.length < 8 ? "very short" : "no preset",
|
|
855
|
+
renamed
|
|
856
|
+
].filter(Boolean).join(" \xB7 ");
|
|
857
|
+
unknown.push({ ...item, why, guess: d.provider });
|
|
825
858
|
}
|
|
859
|
+
const rank = (o) => o.why?.startsWith("no preset") ? 0 : o.why?.startsWith("very short") ? 1 : 2;
|
|
860
|
+
unknown.sort((a, b) => rank(a) - rank(b));
|
|
826
861
|
return { plans, skipped, unknown };
|
|
827
862
|
}
|
|
828
863
|
function printSkipped(skipped) {
|
|
@@ -836,9 +871,10 @@ function printSkipped(skipped) {
|
|
|
836
871
|
}
|
|
837
872
|
async function placeUnknown(f, progress, replaces) {
|
|
838
873
|
const pick = await choose(`${c.dim(progress)} Where may ${c.bold(f.name)} be sent?`, [
|
|
874
|
+
...f.guess ? [{ value: f.guess.id, label: f.guess.label, hint: `${f.guess.hosts[0]} \xB7 guessed from the name` }] : [],
|
|
839
875
|
{ value: "_custom", label: "A host I will type", hint: "e.g. api.example.com" },
|
|
840
876
|
{ value: "_skip", label: "Skip this one" },
|
|
841
|
-
...PROVIDERS.map((p) => ({ value: p.id, label: p.label, hint: p.hosts[0] }))
|
|
877
|
+
...PROVIDERS.filter((p) => p !== f.guess).map((p) => ({ value: p.id, label: p.label, hint: p.hosts[0] }))
|
|
842
878
|
]);
|
|
843
879
|
if (pick === "_skip") return null;
|
|
844
880
|
if (pick !== "_custom") {
|
|
@@ -910,8 +946,8 @@ async function migrate(opts) {
|
|
|
910
946
|
const count = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
|
|
911
947
|
const tally = [
|
|
912
948
|
[matched.length, "recognised", "known provider, destination filled in"],
|
|
913
|
-
[unknown.length, "
|
|
914
|
-
[skipped.length, "skipped", "
|
|
949
|
+
[unknown.length, "to pick", interactive ? "you choose which to store and where each may go" : "not stored; add with keybox secrets add NAME --host"],
|
|
950
|
+
[skipped.length, "skipped", "empty, placeholders, or not usable as an API header (reasons below)"]
|
|
915
951
|
];
|
|
916
952
|
for (const [n, label2, why] of tally) if (n) process.stderr.write(` ${c.bold(String(n).padStart(3))} ${label2.padEnd(11)}${c.dim(why)}
|
|
917
953
|
`);
|
|
@@ -929,12 +965,12 @@ async function migrate(opts) {
|
|
|
929
965
|
plans = matched.filter((p) => keep.has(p.name));
|
|
930
966
|
}
|
|
931
967
|
const later = [];
|
|
932
|
-
if (unknown.length && !interactive) for (const f of unknown) later.push({ name: f.name, why:
|
|
968
|
+
if (unknown.length && !interactive) for (const f of unknown) later.push({ name: f.name, why: `not stored (${f.why}); pick it in an interactive run or use keybox secrets add` });
|
|
933
969
|
if (unknown.length && interactive) {
|
|
934
970
|
const pick = new Set(
|
|
935
971
|
await checklist(
|
|
936
|
-
`${count(unknown.length, "
|
|
937
|
-
unknown.map((f) => ({ value: f.name, label: f.name, hint: f.origin })),
|
|
972
|
+
`${count(unknown.length, "more entry", "more entries")} need you to say where they may go. Pick any to store (the rest stay where they are):`,
|
|
973
|
+
unknown.map((f) => ({ value: f.name, label: f.name, hint: f.why ?? f.origin })),
|
|
938
974
|
() => false
|
|
939
975
|
)
|
|
940
976
|
);
|
|
@@ -986,7 +1022,7 @@ async function migrate(opts) {
|
|
|
986
1022
|
}
|
|
987
1023
|
note('Next: keybox agents create NAME --allow "METHOD host/path" then keybox run NAME -- your command');
|
|
988
1024
|
}
|
|
989
|
-
var json, SOURCES, NOT_READABLE;
|
|
1025
|
+
var json, SOURCES, NOT_READABLE, PLACEHOLDER;
|
|
990
1026
|
var init_migrate = __esm({
|
|
991
1027
|
"src/migrate.ts"() {
|
|
992
1028
|
"use strict";
|
|
@@ -1182,6 +1218,7 @@ var init_migrate = __esm({
|
|
|
1182
1218
|
lastpass: "Use `lpass show --password ITEM | keybox secrets add NAME` for each key.",
|
|
1183
1219
|
keepass: "Export is a plaintext file. Prefer `keepassxc-cli show -sa password DB ENTRY | keybox secrets add NAME` per key."
|
|
1184
1220
|
};
|
|
1221
|
+
PLACEHOLDER = /^(x+|changeme|todo|tbd|none|null|your[-_ ].*|<.*>|\.\.\.|\*+)$/i;
|
|
1185
1222
|
}
|
|
1186
1223
|
});
|
|
1187
1224
|
|
|
@@ -1511,13 +1548,30 @@ async function cf(path, account = currentAccount()) {
|
|
|
1511
1548
|
}
|
|
1512
1549
|
return body.result;
|
|
1513
1550
|
}
|
|
1514
|
-
|
|
1551
|
+
function workersDevSubdomain(url) {
|
|
1552
|
+
try {
|
|
1553
|
+
const m = /^[^.]+\.([^.]+)\.workers\.dev$/.exec(new URL(url).hostname);
|
|
1554
|
+
return m ? m[1] : null;
|
|
1555
|
+
} catch {
|
|
1556
|
+
return null;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
async function accountSubdomain(accountId2) {
|
|
1560
|
+
try {
|
|
1561
|
+
return (await cf("/workers/subdomain", accountId2)).subdomain ?? null;
|
|
1562
|
+
} catch {
|
|
1563
|
+
return null;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
async function findWorker(name, accounts, url) {
|
|
1567
|
+
const want = url ? workersDevSubdomain(url) : null;
|
|
1515
1568
|
for (const a of accounts) {
|
|
1516
1569
|
try {
|
|
1517
1570
|
await cf(`/workers/scripts/${name}/settings`, a.id);
|
|
1518
|
-
return a;
|
|
1519
1571
|
} catch {
|
|
1572
|
+
continue;
|
|
1520
1573
|
}
|
|
1574
|
+
if (!want || await accountSubdomain(a.id) === want) return a;
|
|
1521
1575
|
}
|
|
1522
1576
|
return null;
|
|
1523
1577
|
}
|
|
@@ -1543,7 +1597,7 @@ var VERSION;
|
|
|
1543
1597
|
var init_version = __esm({
|
|
1544
1598
|
"src/version.ts"() {
|
|
1545
1599
|
"use strict";
|
|
1546
|
-
VERSION = true ? "0.2.
|
|
1600
|
+
VERSION = true ? "0.2.2" : "0.0.0-dev";
|
|
1547
1601
|
}
|
|
1548
1602
|
});
|
|
1549
1603
|
|
|
@@ -1554,6 +1608,7 @@ __export(verify_exports, {
|
|
|
1554
1608
|
printChecks: () => printChecks,
|
|
1555
1609
|
resolveAccount: () => resolveAccount,
|
|
1556
1610
|
shippedWorkerHash: () => shippedWorkerHash,
|
|
1611
|
+
shippedWorkerVersion: () => shippedWorkerVersion,
|
|
1557
1612
|
verify: () => verify
|
|
1558
1613
|
});
|
|
1559
1614
|
import { createHash } from "node:crypto";
|
|
@@ -1584,8 +1639,8 @@ async function resolveAccount(cfg) {
|
|
|
1584
1639
|
}
|
|
1585
1640
|
const me = await whoami();
|
|
1586
1641
|
if (!me) throw new UserError("Log in to Cloudflare first: npx wrangler login");
|
|
1587
|
-
const found = await findWorker(cfg.name, me.accounts);
|
|
1588
|
-
if (!found) throw new UserError(`No Worker named "${cfg.name}" in the Cloudflare accounts you are logged in to (${me.accounts.map((a) => a.name).join(", ")}).`);
|
|
1642
|
+
const found = await findWorker(cfg.name, me.accounts, cfg.url);
|
|
1643
|
+
if (!found) throw new UserError(`No Worker named "${cfg.name}" serving ${cfg.url} in the Cloudflare accounts you are logged in to (${me.accounts.map((a) => a.name).join(", ")}).`);
|
|
1589
1644
|
useAccount(found.id);
|
|
1590
1645
|
if (cfg.d1Id) saveConfig({ ...cfg, accountId: found.id });
|
|
1591
1646
|
return found.id;
|
|
@@ -1593,6 +1648,16 @@ async function resolveAccount(cfg) {
|
|
|
1593
1648
|
async function checks(cfg) {
|
|
1594
1649
|
const out2 = [];
|
|
1595
1650
|
const name = cfg.name;
|
|
1651
|
+
const sub = workersDevSubdomain(cfg.url);
|
|
1652
|
+
const acct = currentAccount();
|
|
1653
|
+
if (sub && acct) {
|
|
1654
|
+
const has2 = await accountSubdomain(acct);
|
|
1655
|
+
if (has2 !== sub) {
|
|
1656
|
+
throw new UserError(
|
|
1657
|
+
`${cfg.url} is not served from Cloudflare account ${acct} (its workers.dev subdomain is ${has2 ?? "unknown"}, not ${sub}). Log in to the account that runs this Keybox (npx wrangler login), or set KEYBOX_ACCOUNT_ID, and run this again.`
|
|
1658
|
+
);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1596
1661
|
const r = await cfRaw(`/workers/scripts/${name}/content/v2`);
|
|
1597
1662
|
if (!r.ok) throw new UserError(`Could not read the deployed Worker "${name}" (HTTP ${r.status}).`);
|
|
1598
1663
|
const modules = parts(new Uint8Array(await r.arrayBuffer()), r.headers.get("content-type") ?? "");
|
|
@@ -1628,7 +1693,7 @@ async function checks(cfg) {
|
|
|
1628
1693
|
try {
|
|
1629
1694
|
const h = await (await fetch(`${cfg.url}/_keybox/health`)).json();
|
|
1630
1695
|
out2.push(
|
|
1631
|
-
h.configured ? { ok: h.version ===
|
|
1696
|
+
h.configured ? h.version === shippedWorkerVersion() ? { ok: true, label: "Live", detail: `answering as v${h.version}` } : { ok: out2[0]?.ok === true ? false : "warn", label: "Live", detail: `answering as v${h.version}, this CLI ships Worker v${shippedWorkerVersion()}${out2[0]?.ok === true ? ": the URL is served by a different Worker than the one checked above" : ""}` } : { ok: false, label: "Live", detail: "answering, but missing its encryption key or admin token" }
|
|
1632
1697
|
);
|
|
1633
1698
|
} catch {
|
|
1634
1699
|
out2.push({ ok: false, label: "Live", detail: `not reachable at ${cfg.url}` });
|
|
@@ -1666,7 +1731,7 @@ async function verify(opts) {
|
|
|
1666
1731
|
note("If nobody you trust deployed it, assume the stored keys are exposed: rotate them at each provider,");
|
|
1667
1732
|
note("secure your Cloudflare account (hardware key, review members and API tokens), then run `keybox deploy`.");
|
|
1668
1733
|
}
|
|
1669
|
-
var EXPECTED_BINDINGS, shaHex, shippedWorkerHash;
|
|
1734
|
+
var EXPECTED_BINDINGS, shaHex, shippedWorkerHash, shippedWorkerVersion;
|
|
1670
1735
|
var init_verify = __esm({
|
|
1671
1736
|
"src/verify.ts"() {
|
|
1672
1737
|
"use strict";
|
|
@@ -1678,6 +1743,7 @@ var init_verify = __esm({
|
|
|
1678
1743
|
EXPECTED_BINDINGS = /* @__PURE__ */ new Set(["DB", "KEYBOX_KEK", "KEYBOX_ADMIN_TOKEN_HASH", "KEYBOX_SCRIPT_NAME", "KEYBOX_D1_ID"]);
|
|
1679
1744
|
shaHex = (b) => createHash("sha256").update(b).digest("hex");
|
|
1680
1745
|
shippedWorkerHash = () => shaHex(readFileSync4(new URL("../assets/worker.js", import.meta.url)));
|
|
1746
|
+
shippedWorkerVersion = () => /VERSION = "([^"]+)"/.exec(readFileSync4(new URL("../assets/worker.js", import.meta.url), "utf8"))?.[1] ?? VERSION;
|
|
1681
1747
|
}
|
|
1682
1748
|
});
|
|
1683
1749
|
|
|
@@ -1927,7 +1993,7 @@ async function status() {
|
|
|
1927
1993
|
const row = (k, v) => `${c.dim(k.padEnd(11))} ${v}
|
|
1928
1994
|
`;
|
|
1929
1995
|
process.stdout.write(
|
|
1930
|
-
row("url", cfg.url) + row("dashboard", `${cfg.url.replace(/\/$/, "")}/_keybox/ui ${c.dim("(open with keybox ui)")}`) + (cfg.accountId ? row("account", cfg.accountId) : "") + row("worker", `v${health.version}${health.version ===
|
|
1996
|
+
row("url", cfg.url) + row("dashboard", `${cfg.url.replace(/\/$/, "")}/_keybox/ui ${c.dim("(open with keybox ui)")}`) + (cfg.accountId ? row("account", cfg.accountId) : "") + row("worker", `v${health.version}${health.version === shippedWorkerVersion() ? "" : c.warn(` (this CLI ships v${shippedWorkerVersion()}; run keybox update)`)}`) + row("configured", health.configured) + row("secrets", secrets.length) + row("agents", agents.length)
|
|
1931
1997
|
);
|
|
1932
1998
|
if (process.stdout.isTTY) step(`Run ${c.bold("keybox verify")} to check the deployed code against this CLI.`);
|
|
1933
1999
|
}
|
|
@@ -1958,6 +2024,1814 @@ var init_deploy = __esm({
|
|
|
1958
2024
|
}
|
|
1959
2025
|
});
|
|
1960
2026
|
|
|
2027
|
+
// ../node_modules/qrcode/lib/core/utils.js
|
|
2028
|
+
var require_utils = __commonJS({
|
|
2029
|
+
"../node_modules/qrcode/lib/core/utils.js"(exports) {
|
|
2030
|
+
var toSJISFunction;
|
|
2031
|
+
var CODEWORDS_COUNT = [
|
|
2032
|
+
0,
|
|
2033
|
+
// Not used
|
|
2034
|
+
26,
|
|
2035
|
+
44,
|
|
2036
|
+
70,
|
|
2037
|
+
100,
|
|
2038
|
+
134,
|
|
2039
|
+
172,
|
|
2040
|
+
196,
|
|
2041
|
+
242,
|
|
2042
|
+
292,
|
|
2043
|
+
346,
|
|
2044
|
+
404,
|
|
2045
|
+
466,
|
|
2046
|
+
532,
|
|
2047
|
+
581,
|
|
2048
|
+
655,
|
|
2049
|
+
733,
|
|
2050
|
+
815,
|
|
2051
|
+
901,
|
|
2052
|
+
991,
|
|
2053
|
+
1085,
|
|
2054
|
+
1156,
|
|
2055
|
+
1258,
|
|
2056
|
+
1364,
|
|
2057
|
+
1474,
|
|
2058
|
+
1588,
|
|
2059
|
+
1706,
|
|
2060
|
+
1828,
|
|
2061
|
+
1921,
|
|
2062
|
+
2051,
|
|
2063
|
+
2185,
|
|
2064
|
+
2323,
|
|
2065
|
+
2465,
|
|
2066
|
+
2611,
|
|
2067
|
+
2761,
|
|
2068
|
+
2876,
|
|
2069
|
+
3034,
|
|
2070
|
+
3196,
|
|
2071
|
+
3362,
|
|
2072
|
+
3532,
|
|
2073
|
+
3706
|
|
2074
|
+
];
|
|
2075
|
+
exports.getSymbolSize = function getSymbolSize(version) {
|
|
2076
|
+
if (!version) throw new Error('"version" cannot be null or undefined');
|
|
2077
|
+
if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40');
|
|
2078
|
+
return version * 4 + 17;
|
|
2079
|
+
};
|
|
2080
|
+
exports.getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
|
|
2081
|
+
return CODEWORDS_COUNT[version];
|
|
2082
|
+
};
|
|
2083
|
+
exports.getBCHDigit = function(data) {
|
|
2084
|
+
let digit = 0;
|
|
2085
|
+
while (data !== 0) {
|
|
2086
|
+
digit++;
|
|
2087
|
+
data >>>= 1;
|
|
2088
|
+
}
|
|
2089
|
+
return digit;
|
|
2090
|
+
};
|
|
2091
|
+
exports.setToSJISFunction = function setToSJISFunction(f) {
|
|
2092
|
+
if (typeof f !== "function") {
|
|
2093
|
+
throw new Error('"toSJISFunc" is not a valid function.');
|
|
2094
|
+
}
|
|
2095
|
+
toSJISFunction = f;
|
|
2096
|
+
};
|
|
2097
|
+
exports.isKanjiModeEnabled = function() {
|
|
2098
|
+
return typeof toSJISFunction !== "undefined";
|
|
2099
|
+
};
|
|
2100
|
+
exports.toSJIS = function toSJIS(kanji) {
|
|
2101
|
+
return toSJISFunction(kanji);
|
|
2102
|
+
};
|
|
2103
|
+
}
|
|
2104
|
+
});
|
|
2105
|
+
|
|
2106
|
+
// ../node_modules/qrcode/lib/core/error-correction-level.js
|
|
2107
|
+
var require_error_correction_level = __commonJS({
|
|
2108
|
+
"../node_modules/qrcode/lib/core/error-correction-level.js"(exports) {
|
|
2109
|
+
exports.L = { bit: 1 };
|
|
2110
|
+
exports.M = { bit: 0 };
|
|
2111
|
+
exports.Q = { bit: 3 };
|
|
2112
|
+
exports.H = { bit: 2 };
|
|
2113
|
+
function fromString(string) {
|
|
2114
|
+
if (typeof string !== "string") {
|
|
2115
|
+
throw new Error("Param is not a string");
|
|
2116
|
+
}
|
|
2117
|
+
const lcStr = string.toLowerCase();
|
|
2118
|
+
switch (lcStr) {
|
|
2119
|
+
case "l":
|
|
2120
|
+
case "low":
|
|
2121
|
+
return exports.L;
|
|
2122
|
+
case "m":
|
|
2123
|
+
case "medium":
|
|
2124
|
+
return exports.M;
|
|
2125
|
+
case "q":
|
|
2126
|
+
case "quartile":
|
|
2127
|
+
return exports.Q;
|
|
2128
|
+
case "h":
|
|
2129
|
+
case "high":
|
|
2130
|
+
return exports.H;
|
|
2131
|
+
default:
|
|
2132
|
+
throw new Error("Unknown EC Level: " + string);
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
exports.isValid = function isValid(level) {
|
|
2136
|
+
return level && typeof level.bit !== "undefined" && level.bit >= 0 && level.bit < 4;
|
|
2137
|
+
};
|
|
2138
|
+
exports.from = function from(value, defaultValue) {
|
|
2139
|
+
if (exports.isValid(value)) {
|
|
2140
|
+
return value;
|
|
2141
|
+
}
|
|
2142
|
+
try {
|
|
2143
|
+
return fromString(value);
|
|
2144
|
+
} catch (e) {
|
|
2145
|
+
return defaultValue;
|
|
2146
|
+
}
|
|
2147
|
+
};
|
|
2148
|
+
}
|
|
2149
|
+
});
|
|
2150
|
+
|
|
2151
|
+
// ../node_modules/qrcode/lib/core/bit-buffer.js
|
|
2152
|
+
var require_bit_buffer = __commonJS({
|
|
2153
|
+
"../node_modules/qrcode/lib/core/bit-buffer.js"(exports, module) {
|
|
2154
|
+
function BitBuffer() {
|
|
2155
|
+
this.buffer = [];
|
|
2156
|
+
this.length = 0;
|
|
2157
|
+
}
|
|
2158
|
+
BitBuffer.prototype = {
|
|
2159
|
+
get: function(index) {
|
|
2160
|
+
const bufIndex = Math.floor(index / 8);
|
|
2161
|
+
return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
|
|
2162
|
+
},
|
|
2163
|
+
put: function(num, length) {
|
|
2164
|
+
for (let i = 0; i < length; i++) {
|
|
2165
|
+
this.putBit((num >>> length - i - 1 & 1) === 1);
|
|
2166
|
+
}
|
|
2167
|
+
},
|
|
2168
|
+
getLengthInBits: function() {
|
|
2169
|
+
return this.length;
|
|
2170
|
+
},
|
|
2171
|
+
putBit: function(bit) {
|
|
2172
|
+
const bufIndex = Math.floor(this.length / 8);
|
|
2173
|
+
if (this.buffer.length <= bufIndex) {
|
|
2174
|
+
this.buffer.push(0);
|
|
2175
|
+
}
|
|
2176
|
+
if (bit) {
|
|
2177
|
+
this.buffer[bufIndex] |= 128 >>> this.length % 8;
|
|
2178
|
+
}
|
|
2179
|
+
this.length++;
|
|
2180
|
+
}
|
|
2181
|
+
};
|
|
2182
|
+
module.exports = BitBuffer;
|
|
2183
|
+
}
|
|
2184
|
+
});
|
|
2185
|
+
|
|
2186
|
+
// ../node_modules/qrcode/lib/core/bit-matrix.js
|
|
2187
|
+
var require_bit_matrix = __commonJS({
|
|
2188
|
+
"../node_modules/qrcode/lib/core/bit-matrix.js"(exports, module) {
|
|
2189
|
+
function BitMatrix(size) {
|
|
2190
|
+
if (!size || size < 1) {
|
|
2191
|
+
throw new Error("BitMatrix size must be defined and greater than 0");
|
|
2192
|
+
}
|
|
2193
|
+
this.size = size;
|
|
2194
|
+
this.data = new Uint8Array(size * size);
|
|
2195
|
+
this.reservedBit = new Uint8Array(size * size);
|
|
2196
|
+
}
|
|
2197
|
+
BitMatrix.prototype.set = function(row, col, value, reserved) {
|
|
2198
|
+
const index = row * this.size + col;
|
|
2199
|
+
this.data[index] = value;
|
|
2200
|
+
if (reserved) this.reservedBit[index] = true;
|
|
2201
|
+
};
|
|
2202
|
+
BitMatrix.prototype.get = function(row, col) {
|
|
2203
|
+
return this.data[row * this.size + col];
|
|
2204
|
+
};
|
|
2205
|
+
BitMatrix.prototype.xor = function(row, col, value) {
|
|
2206
|
+
this.data[row * this.size + col] ^= value;
|
|
2207
|
+
};
|
|
2208
|
+
BitMatrix.prototype.isReserved = function(row, col) {
|
|
2209
|
+
return this.reservedBit[row * this.size + col];
|
|
2210
|
+
};
|
|
2211
|
+
module.exports = BitMatrix;
|
|
2212
|
+
}
|
|
2213
|
+
});
|
|
2214
|
+
|
|
2215
|
+
// ../node_modules/qrcode/lib/core/alignment-pattern.js
|
|
2216
|
+
var require_alignment_pattern = __commonJS({
|
|
2217
|
+
"../node_modules/qrcode/lib/core/alignment-pattern.js"(exports) {
|
|
2218
|
+
var getSymbolSize = require_utils().getSymbolSize;
|
|
2219
|
+
exports.getRowColCoords = function getRowColCoords(version) {
|
|
2220
|
+
if (version === 1) return [];
|
|
2221
|
+
const posCount = Math.floor(version / 7) + 2;
|
|
2222
|
+
const size = getSymbolSize(version);
|
|
2223
|
+
const intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
|
|
2224
|
+
const positions = [size - 7];
|
|
2225
|
+
for (let i = 1; i < posCount - 1; i++) {
|
|
2226
|
+
positions[i] = positions[i - 1] - intervals;
|
|
2227
|
+
}
|
|
2228
|
+
positions.push(6);
|
|
2229
|
+
return positions.reverse();
|
|
2230
|
+
};
|
|
2231
|
+
exports.getPositions = function getPositions(version) {
|
|
2232
|
+
const coords = [];
|
|
2233
|
+
const pos = exports.getRowColCoords(version);
|
|
2234
|
+
const posLength = pos.length;
|
|
2235
|
+
for (let i = 0; i < posLength; i++) {
|
|
2236
|
+
for (let j = 0; j < posLength; j++) {
|
|
2237
|
+
if (i === 0 && j === 0 || // top-left
|
|
2238
|
+
i === 0 && j === posLength - 1 || // bottom-left
|
|
2239
|
+
i === posLength - 1 && j === 0) {
|
|
2240
|
+
continue;
|
|
2241
|
+
}
|
|
2242
|
+
coords.push([pos[i], pos[j]]);
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
return coords;
|
|
2246
|
+
};
|
|
2247
|
+
}
|
|
2248
|
+
});
|
|
2249
|
+
|
|
2250
|
+
// ../node_modules/qrcode/lib/core/finder-pattern.js
|
|
2251
|
+
var require_finder_pattern = __commonJS({
|
|
2252
|
+
"../node_modules/qrcode/lib/core/finder-pattern.js"(exports) {
|
|
2253
|
+
var getSymbolSize = require_utils().getSymbolSize;
|
|
2254
|
+
var FINDER_PATTERN_SIZE = 7;
|
|
2255
|
+
exports.getPositions = function getPositions(version) {
|
|
2256
|
+
const size = getSymbolSize(version);
|
|
2257
|
+
return [
|
|
2258
|
+
// top-left
|
|
2259
|
+
[0, 0],
|
|
2260
|
+
// top-right
|
|
2261
|
+
[size - FINDER_PATTERN_SIZE, 0],
|
|
2262
|
+
// bottom-left
|
|
2263
|
+
[0, size - FINDER_PATTERN_SIZE]
|
|
2264
|
+
];
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
});
|
|
2268
|
+
|
|
2269
|
+
// ../node_modules/qrcode/lib/core/mask-pattern.js
|
|
2270
|
+
var require_mask_pattern = __commonJS({
|
|
2271
|
+
"../node_modules/qrcode/lib/core/mask-pattern.js"(exports) {
|
|
2272
|
+
exports.Patterns = {
|
|
2273
|
+
PATTERN000: 0,
|
|
2274
|
+
PATTERN001: 1,
|
|
2275
|
+
PATTERN010: 2,
|
|
2276
|
+
PATTERN011: 3,
|
|
2277
|
+
PATTERN100: 4,
|
|
2278
|
+
PATTERN101: 5,
|
|
2279
|
+
PATTERN110: 6,
|
|
2280
|
+
PATTERN111: 7
|
|
2281
|
+
};
|
|
2282
|
+
var PenaltyScores = {
|
|
2283
|
+
N1: 3,
|
|
2284
|
+
N2: 3,
|
|
2285
|
+
N3: 40,
|
|
2286
|
+
N4: 10
|
|
2287
|
+
};
|
|
2288
|
+
exports.isValid = function isValid(mask) {
|
|
2289
|
+
return mask != null && mask !== "" && !isNaN(mask) && mask >= 0 && mask <= 7;
|
|
2290
|
+
};
|
|
2291
|
+
exports.from = function from(value) {
|
|
2292
|
+
return exports.isValid(value) ? parseInt(value, 10) : void 0;
|
|
2293
|
+
};
|
|
2294
|
+
exports.getPenaltyN1 = function getPenaltyN1(data) {
|
|
2295
|
+
const size = data.size;
|
|
2296
|
+
let points = 0;
|
|
2297
|
+
let sameCountCol = 0;
|
|
2298
|
+
let sameCountRow = 0;
|
|
2299
|
+
let lastCol = null;
|
|
2300
|
+
let lastRow = null;
|
|
2301
|
+
for (let row = 0; row < size; row++) {
|
|
2302
|
+
sameCountCol = sameCountRow = 0;
|
|
2303
|
+
lastCol = lastRow = null;
|
|
2304
|
+
for (let col = 0; col < size; col++) {
|
|
2305
|
+
let module2 = data.get(row, col);
|
|
2306
|
+
if (module2 === lastCol) {
|
|
2307
|
+
sameCountCol++;
|
|
2308
|
+
} else {
|
|
2309
|
+
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
2310
|
+
lastCol = module2;
|
|
2311
|
+
sameCountCol = 1;
|
|
2312
|
+
}
|
|
2313
|
+
module2 = data.get(col, row);
|
|
2314
|
+
if (module2 === lastRow) {
|
|
2315
|
+
sameCountRow++;
|
|
2316
|
+
} else {
|
|
2317
|
+
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
2318
|
+
lastRow = module2;
|
|
2319
|
+
sameCountRow = 1;
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
|
|
2323
|
+
if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
|
|
2324
|
+
}
|
|
2325
|
+
return points;
|
|
2326
|
+
};
|
|
2327
|
+
exports.getPenaltyN2 = function getPenaltyN2(data) {
|
|
2328
|
+
const size = data.size;
|
|
2329
|
+
let points = 0;
|
|
2330
|
+
for (let row = 0; row < size - 1; row++) {
|
|
2331
|
+
for (let col = 0; col < size - 1; col++) {
|
|
2332
|
+
const last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
|
|
2333
|
+
if (last === 4 || last === 0) points++;
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
return points * PenaltyScores.N2;
|
|
2337
|
+
};
|
|
2338
|
+
exports.getPenaltyN3 = function getPenaltyN3(data) {
|
|
2339
|
+
const size = data.size;
|
|
2340
|
+
let points = 0;
|
|
2341
|
+
let bitsCol = 0;
|
|
2342
|
+
let bitsRow = 0;
|
|
2343
|
+
for (let row = 0; row < size; row++) {
|
|
2344
|
+
bitsCol = bitsRow = 0;
|
|
2345
|
+
for (let col = 0; col < size; col++) {
|
|
2346
|
+
bitsCol = bitsCol << 1 & 2047 | data.get(row, col);
|
|
2347
|
+
if (col >= 10 && (bitsCol === 1488 || bitsCol === 93)) points++;
|
|
2348
|
+
bitsRow = bitsRow << 1 & 2047 | data.get(col, row);
|
|
2349
|
+
if (col >= 10 && (bitsRow === 1488 || bitsRow === 93)) points++;
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
return points * PenaltyScores.N3;
|
|
2353
|
+
};
|
|
2354
|
+
exports.getPenaltyN4 = function getPenaltyN4(data) {
|
|
2355
|
+
let darkCount = 0;
|
|
2356
|
+
const modulesCount = data.data.length;
|
|
2357
|
+
for (let i = 0; i < modulesCount; i++) darkCount += data.data[i];
|
|
2358
|
+
const k = Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10);
|
|
2359
|
+
return k * PenaltyScores.N4;
|
|
2360
|
+
};
|
|
2361
|
+
function getMaskAt(maskPattern, i, j) {
|
|
2362
|
+
switch (maskPattern) {
|
|
2363
|
+
case exports.Patterns.PATTERN000:
|
|
2364
|
+
return (i + j) % 2 === 0;
|
|
2365
|
+
case exports.Patterns.PATTERN001:
|
|
2366
|
+
return i % 2 === 0;
|
|
2367
|
+
case exports.Patterns.PATTERN010:
|
|
2368
|
+
return j % 3 === 0;
|
|
2369
|
+
case exports.Patterns.PATTERN011:
|
|
2370
|
+
return (i + j) % 3 === 0;
|
|
2371
|
+
case exports.Patterns.PATTERN100:
|
|
2372
|
+
return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
|
|
2373
|
+
case exports.Patterns.PATTERN101:
|
|
2374
|
+
return i * j % 2 + i * j % 3 === 0;
|
|
2375
|
+
case exports.Patterns.PATTERN110:
|
|
2376
|
+
return (i * j % 2 + i * j % 3) % 2 === 0;
|
|
2377
|
+
case exports.Patterns.PATTERN111:
|
|
2378
|
+
return (i * j % 3 + (i + j) % 2) % 2 === 0;
|
|
2379
|
+
default:
|
|
2380
|
+
throw new Error("bad maskPattern:" + maskPattern);
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
exports.applyMask = function applyMask(pattern, data) {
|
|
2384
|
+
const size = data.size;
|
|
2385
|
+
for (let col = 0; col < size; col++) {
|
|
2386
|
+
for (let row = 0; row < size; row++) {
|
|
2387
|
+
if (data.isReserved(row, col)) continue;
|
|
2388
|
+
data.xor(row, col, getMaskAt(pattern, row, col));
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
exports.getBestMask = function getBestMask(data, setupFormatFunc) {
|
|
2393
|
+
const numPatterns = Object.keys(exports.Patterns).length;
|
|
2394
|
+
let bestPattern = 0;
|
|
2395
|
+
let lowerPenalty = Infinity;
|
|
2396
|
+
for (let p = 0; p < numPatterns; p++) {
|
|
2397
|
+
setupFormatFunc(p);
|
|
2398
|
+
exports.applyMask(p, data);
|
|
2399
|
+
const penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data);
|
|
2400
|
+
exports.applyMask(p, data);
|
|
2401
|
+
if (penalty < lowerPenalty) {
|
|
2402
|
+
lowerPenalty = penalty;
|
|
2403
|
+
bestPattern = p;
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
return bestPattern;
|
|
2407
|
+
};
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
|
|
2411
|
+
// ../node_modules/qrcode/lib/core/error-correction-code.js
|
|
2412
|
+
var require_error_correction_code = __commonJS({
|
|
2413
|
+
"../node_modules/qrcode/lib/core/error-correction-code.js"(exports) {
|
|
2414
|
+
var ECLevel = require_error_correction_level();
|
|
2415
|
+
var EC_BLOCKS_TABLE = [
|
|
2416
|
+
// L M Q H
|
|
2417
|
+
1,
|
|
2418
|
+
1,
|
|
2419
|
+
1,
|
|
2420
|
+
1,
|
|
2421
|
+
1,
|
|
2422
|
+
1,
|
|
2423
|
+
1,
|
|
2424
|
+
1,
|
|
2425
|
+
1,
|
|
2426
|
+
1,
|
|
2427
|
+
2,
|
|
2428
|
+
2,
|
|
2429
|
+
1,
|
|
2430
|
+
2,
|
|
2431
|
+
2,
|
|
2432
|
+
4,
|
|
2433
|
+
1,
|
|
2434
|
+
2,
|
|
2435
|
+
4,
|
|
2436
|
+
4,
|
|
2437
|
+
2,
|
|
2438
|
+
4,
|
|
2439
|
+
4,
|
|
2440
|
+
4,
|
|
2441
|
+
2,
|
|
2442
|
+
4,
|
|
2443
|
+
6,
|
|
2444
|
+
5,
|
|
2445
|
+
2,
|
|
2446
|
+
4,
|
|
2447
|
+
6,
|
|
2448
|
+
6,
|
|
2449
|
+
2,
|
|
2450
|
+
5,
|
|
2451
|
+
8,
|
|
2452
|
+
8,
|
|
2453
|
+
4,
|
|
2454
|
+
5,
|
|
2455
|
+
8,
|
|
2456
|
+
8,
|
|
2457
|
+
4,
|
|
2458
|
+
5,
|
|
2459
|
+
8,
|
|
2460
|
+
11,
|
|
2461
|
+
4,
|
|
2462
|
+
8,
|
|
2463
|
+
10,
|
|
2464
|
+
11,
|
|
2465
|
+
4,
|
|
2466
|
+
9,
|
|
2467
|
+
12,
|
|
2468
|
+
16,
|
|
2469
|
+
4,
|
|
2470
|
+
9,
|
|
2471
|
+
16,
|
|
2472
|
+
16,
|
|
2473
|
+
6,
|
|
2474
|
+
10,
|
|
2475
|
+
12,
|
|
2476
|
+
18,
|
|
2477
|
+
6,
|
|
2478
|
+
10,
|
|
2479
|
+
17,
|
|
2480
|
+
16,
|
|
2481
|
+
6,
|
|
2482
|
+
11,
|
|
2483
|
+
16,
|
|
2484
|
+
19,
|
|
2485
|
+
6,
|
|
2486
|
+
13,
|
|
2487
|
+
18,
|
|
2488
|
+
21,
|
|
2489
|
+
7,
|
|
2490
|
+
14,
|
|
2491
|
+
21,
|
|
2492
|
+
25,
|
|
2493
|
+
8,
|
|
2494
|
+
16,
|
|
2495
|
+
20,
|
|
2496
|
+
25,
|
|
2497
|
+
8,
|
|
2498
|
+
17,
|
|
2499
|
+
23,
|
|
2500
|
+
25,
|
|
2501
|
+
9,
|
|
2502
|
+
17,
|
|
2503
|
+
23,
|
|
2504
|
+
34,
|
|
2505
|
+
9,
|
|
2506
|
+
18,
|
|
2507
|
+
25,
|
|
2508
|
+
30,
|
|
2509
|
+
10,
|
|
2510
|
+
20,
|
|
2511
|
+
27,
|
|
2512
|
+
32,
|
|
2513
|
+
12,
|
|
2514
|
+
21,
|
|
2515
|
+
29,
|
|
2516
|
+
35,
|
|
2517
|
+
12,
|
|
2518
|
+
23,
|
|
2519
|
+
34,
|
|
2520
|
+
37,
|
|
2521
|
+
12,
|
|
2522
|
+
25,
|
|
2523
|
+
34,
|
|
2524
|
+
40,
|
|
2525
|
+
13,
|
|
2526
|
+
26,
|
|
2527
|
+
35,
|
|
2528
|
+
42,
|
|
2529
|
+
14,
|
|
2530
|
+
28,
|
|
2531
|
+
38,
|
|
2532
|
+
45,
|
|
2533
|
+
15,
|
|
2534
|
+
29,
|
|
2535
|
+
40,
|
|
2536
|
+
48,
|
|
2537
|
+
16,
|
|
2538
|
+
31,
|
|
2539
|
+
43,
|
|
2540
|
+
51,
|
|
2541
|
+
17,
|
|
2542
|
+
33,
|
|
2543
|
+
45,
|
|
2544
|
+
54,
|
|
2545
|
+
18,
|
|
2546
|
+
35,
|
|
2547
|
+
48,
|
|
2548
|
+
57,
|
|
2549
|
+
19,
|
|
2550
|
+
37,
|
|
2551
|
+
51,
|
|
2552
|
+
60,
|
|
2553
|
+
19,
|
|
2554
|
+
38,
|
|
2555
|
+
53,
|
|
2556
|
+
63,
|
|
2557
|
+
20,
|
|
2558
|
+
40,
|
|
2559
|
+
56,
|
|
2560
|
+
66,
|
|
2561
|
+
21,
|
|
2562
|
+
43,
|
|
2563
|
+
59,
|
|
2564
|
+
70,
|
|
2565
|
+
22,
|
|
2566
|
+
45,
|
|
2567
|
+
62,
|
|
2568
|
+
74,
|
|
2569
|
+
24,
|
|
2570
|
+
47,
|
|
2571
|
+
65,
|
|
2572
|
+
77,
|
|
2573
|
+
25,
|
|
2574
|
+
49,
|
|
2575
|
+
68,
|
|
2576
|
+
81
|
|
2577
|
+
];
|
|
2578
|
+
var EC_CODEWORDS_TABLE = [
|
|
2579
|
+
// L M Q H
|
|
2580
|
+
7,
|
|
2581
|
+
10,
|
|
2582
|
+
13,
|
|
2583
|
+
17,
|
|
2584
|
+
10,
|
|
2585
|
+
16,
|
|
2586
|
+
22,
|
|
2587
|
+
28,
|
|
2588
|
+
15,
|
|
2589
|
+
26,
|
|
2590
|
+
36,
|
|
2591
|
+
44,
|
|
2592
|
+
20,
|
|
2593
|
+
36,
|
|
2594
|
+
52,
|
|
2595
|
+
64,
|
|
2596
|
+
26,
|
|
2597
|
+
48,
|
|
2598
|
+
72,
|
|
2599
|
+
88,
|
|
2600
|
+
36,
|
|
2601
|
+
64,
|
|
2602
|
+
96,
|
|
2603
|
+
112,
|
|
2604
|
+
40,
|
|
2605
|
+
72,
|
|
2606
|
+
108,
|
|
2607
|
+
130,
|
|
2608
|
+
48,
|
|
2609
|
+
88,
|
|
2610
|
+
132,
|
|
2611
|
+
156,
|
|
2612
|
+
60,
|
|
2613
|
+
110,
|
|
2614
|
+
160,
|
|
2615
|
+
192,
|
|
2616
|
+
72,
|
|
2617
|
+
130,
|
|
2618
|
+
192,
|
|
2619
|
+
224,
|
|
2620
|
+
80,
|
|
2621
|
+
150,
|
|
2622
|
+
224,
|
|
2623
|
+
264,
|
|
2624
|
+
96,
|
|
2625
|
+
176,
|
|
2626
|
+
260,
|
|
2627
|
+
308,
|
|
2628
|
+
104,
|
|
2629
|
+
198,
|
|
2630
|
+
288,
|
|
2631
|
+
352,
|
|
2632
|
+
120,
|
|
2633
|
+
216,
|
|
2634
|
+
320,
|
|
2635
|
+
384,
|
|
2636
|
+
132,
|
|
2637
|
+
240,
|
|
2638
|
+
360,
|
|
2639
|
+
432,
|
|
2640
|
+
144,
|
|
2641
|
+
280,
|
|
2642
|
+
408,
|
|
2643
|
+
480,
|
|
2644
|
+
168,
|
|
2645
|
+
308,
|
|
2646
|
+
448,
|
|
2647
|
+
532,
|
|
2648
|
+
180,
|
|
2649
|
+
338,
|
|
2650
|
+
504,
|
|
2651
|
+
588,
|
|
2652
|
+
196,
|
|
2653
|
+
364,
|
|
2654
|
+
546,
|
|
2655
|
+
650,
|
|
2656
|
+
224,
|
|
2657
|
+
416,
|
|
2658
|
+
600,
|
|
2659
|
+
700,
|
|
2660
|
+
224,
|
|
2661
|
+
442,
|
|
2662
|
+
644,
|
|
2663
|
+
750,
|
|
2664
|
+
252,
|
|
2665
|
+
476,
|
|
2666
|
+
690,
|
|
2667
|
+
816,
|
|
2668
|
+
270,
|
|
2669
|
+
504,
|
|
2670
|
+
750,
|
|
2671
|
+
900,
|
|
2672
|
+
300,
|
|
2673
|
+
560,
|
|
2674
|
+
810,
|
|
2675
|
+
960,
|
|
2676
|
+
312,
|
|
2677
|
+
588,
|
|
2678
|
+
870,
|
|
2679
|
+
1050,
|
|
2680
|
+
336,
|
|
2681
|
+
644,
|
|
2682
|
+
952,
|
|
2683
|
+
1110,
|
|
2684
|
+
360,
|
|
2685
|
+
700,
|
|
2686
|
+
1020,
|
|
2687
|
+
1200,
|
|
2688
|
+
390,
|
|
2689
|
+
728,
|
|
2690
|
+
1050,
|
|
2691
|
+
1260,
|
|
2692
|
+
420,
|
|
2693
|
+
784,
|
|
2694
|
+
1140,
|
|
2695
|
+
1350,
|
|
2696
|
+
450,
|
|
2697
|
+
812,
|
|
2698
|
+
1200,
|
|
2699
|
+
1440,
|
|
2700
|
+
480,
|
|
2701
|
+
868,
|
|
2702
|
+
1290,
|
|
2703
|
+
1530,
|
|
2704
|
+
510,
|
|
2705
|
+
924,
|
|
2706
|
+
1350,
|
|
2707
|
+
1620,
|
|
2708
|
+
540,
|
|
2709
|
+
980,
|
|
2710
|
+
1440,
|
|
2711
|
+
1710,
|
|
2712
|
+
570,
|
|
2713
|
+
1036,
|
|
2714
|
+
1530,
|
|
2715
|
+
1800,
|
|
2716
|
+
570,
|
|
2717
|
+
1064,
|
|
2718
|
+
1590,
|
|
2719
|
+
1890,
|
|
2720
|
+
600,
|
|
2721
|
+
1120,
|
|
2722
|
+
1680,
|
|
2723
|
+
1980,
|
|
2724
|
+
630,
|
|
2725
|
+
1204,
|
|
2726
|
+
1770,
|
|
2727
|
+
2100,
|
|
2728
|
+
660,
|
|
2729
|
+
1260,
|
|
2730
|
+
1860,
|
|
2731
|
+
2220,
|
|
2732
|
+
720,
|
|
2733
|
+
1316,
|
|
2734
|
+
1950,
|
|
2735
|
+
2310,
|
|
2736
|
+
750,
|
|
2737
|
+
1372,
|
|
2738
|
+
2040,
|
|
2739
|
+
2430
|
|
2740
|
+
];
|
|
2741
|
+
exports.getBlocksCount = function getBlocksCount(version, errorCorrectionLevel) {
|
|
2742
|
+
switch (errorCorrectionLevel) {
|
|
2743
|
+
case ECLevel.L:
|
|
2744
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
|
|
2745
|
+
case ECLevel.M:
|
|
2746
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
|
|
2747
|
+
case ECLevel.Q:
|
|
2748
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
|
|
2749
|
+
case ECLevel.H:
|
|
2750
|
+
return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
|
|
2751
|
+
default:
|
|
2752
|
+
return void 0;
|
|
2753
|
+
}
|
|
2754
|
+
};
|
|
2755
|
+
exports.getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel) {
|
|
2756
|
+
switch (errorCorrectionLevel) {
|
|
2757
|
+
case ECLevel.L:
|
|
2758
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
|
|
2759
|
+
case ECLevel.M:
|
|
2760
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
|
|
2761
|
+
case ECLevel.Q:
|
|
2762
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
|
|
2763
|
+
case ECLevel.H:
|
|
2764
|
+
return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
|
|
2765
|
+
default:
|
|
2766
|
+
return void 0;
|
|
2767
|
+
}
|
|
2768
|
+
};
|
|
2769
|
+
}
|
|
2770
|
+
});
|
|
2771
|
+
|
|
2772
|
+
// ../node_modules/qrcode/lib/core/galois-field.js
|
|
2773
|
+
var require_galois_field = __commonJS({
|
|
2774
|
+
"../node_modules/qrcode/lib/core/galois-field.js"(exports) {
|
|
2775
|
+
var EXP_TABLE = new Uint8Array(512);
|
|
2776
|
+
var LOG_TABLE = new Uint8Array(256);
|
|
2777
|
+
(function initTables() {
|
|
2778
|
+
let x = 1;
|
|
2779
|
+
for (let i = 0; i < 255; i++) {
|
|
2780
|
+
EXP_TABLE[i] = x;
|
|
2781
|
+
LOG_TABLE[x] = i;
|
|
2782
|
+
x <<= 1;
|
|
2783
|
+
if (x & 256) {
|
|
2784
|
+
x ^= 285;
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
for (let i = 255; i < 512; i++) {
|
|
2788
|
+
EXP_TABLE[i] = EXP_TABLE[i - 255];
|
|
2789
|
+
}
|
|
2790
|
+
})();
|
|
2791
|
+
exports.log = function log(n) {
|
|
2792
|
+
if (n < 1) throw new Error("log(" + n + ")");
|
|
2793
|
+
return LOG_TABLE[n];
|
|
2794
|
+
};
|
|
2795
|
+
exports.exp = function exp(n) {
|
|
2796
|
+
return EXP_TABLE[n];
|
|
2797
|
+
};
|
|
2798
|
+
exports.mul = function mul(x, y) {
|
|
2799
|
+
if (x === 0 || y === 0) return 0;
|
|
2800
|
+
return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]];
|
|
2801
|
+
};
|
|
2802
|
+
}
|
|
2803
|
+
});
|
|
2804
|
+
|
|
2805
|
+
// ../node_modules/qrcode/lib/core/polynomial.js
|
|
2806
|
+
var require_polynomial = __commonJS({
|
|
2807
|
+
"../node_modules/qrcode/lib/core/polynomial.js"(exports) {
|
|
2808
|
+
var GF = require_galois_field();
|
|
2809
|
+
exports.mul = function mul(p1, p2) {
|
|
2810
|
+
const coeff = new Uint8Array(p1.length + p2.length - 1);
|
|
2811
|
+
for (let i = 0; i < p1.length; i++) {
|
|
2812
|
+
for (let j = 0; j < p2.length; j++) {
|
|
2813
|
+
coeff[i + j] ^= GF.mul(p1[i], p2[j]);
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
return coeff;
|
|
2817
|
+
};
|
|
2818
|
+
exports.mod = function mod(divident, divisor) {
|
|
2819
|
+
let result = new Uint8Array(divident);
|
|
2820
|
+
while (result.length - divisor.length >= 0) {
|
|
2821
|
+
const coeff = result[0];
|
|
2822
|
+
for (let i = 0; i < divisor.length; i++) {
|
|
2823
|
+
result[i] ^= GF.mul(divisor[i], coeff);
|
|
2824
|
+
}
|
|
2825
|
+
let offset = 0;
|
|
2826
|
+
while (offset < result.length && result[offset] === 0) offset++;
|
|
2827
|
+
result = result.slice(offset);
|
|
2828
|
+
}
|
|
2829
|
+
return result;
|
|
2830
|
+
};
|
|
2831
|
+
exports.generateECPolynomial = function generateECPolynomial(degree) {
|
|
2832
|
+
let poly = new Uint8Array([1]);
|
|
2833
|
+
for (let i = 0; i < degree; i++) {
|
|
2834
|
+
poly = exports.mul(poly, new Uint8Array([1, GF.exp(i)]));
|
|
2835
|
+
}
|
|
2836
|
+
return poly;
|
|
2837
|
+
};
|
|
2838
|
+
}
|
|
2839
|
+
});
|
|
2840
|
+
|
|
2841
|
+
// ../node_modules/qrcode/lib/core/reed-solomon-encoder.js
|
|
2842
|
+
var require_reed_solomon_encoder = __commonJS({
|
|
2843
|
+
"../node_modules/qrcode/lib/core/reed-solomon-encoder.js"(exports, module) {
|
|
2844
|
+
var Polynomial = require_polynomial();
|
|
2845
|
+
function ReedSolomonEncoder(degree) {
|
|
2846
|
+
this.genPoly = void 0;
|
|
2847
|
+
this.degree = degree;
|
|
2848
|
+
if (this.degree) this.initialize(this.degree);
|
|
2849
|
+
}
|
|
2850
|
+
ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
|
|
2851
|
+
this.degree = degree;
|
|
2852
|
+
this.genPoly = Polynomial.generateECPolynomial(this.degree);
|
|
2853
|
+
};
|
|
2854
|
+
ReedSolomonEncoder.prototype.encode = function encode(data) {
|
|
2855
|
+
if (!this.genPoly) {
|
|
2856
|
+
throw new Error("Encoder not initialized");
|
|
2857
|
+
}
|
|
2858
|
+
const paddedData = new Uint8Array(data.length + this.degree);
|
|
2859
|
+
paddedData.set(data);
|
|
2860
|
+
const remainder = Polynomial.mod(paddedData, this.genPoly);
|
|
2861
|
+
const start = this.degree - remainder.length;
|
|
2862
|
+
if (start > 0) {
|
|
2863
|
+
const buff = new Uint8Array(this.degree);
|
|
2864
|
+
buff.set(remainder, start);
|
|
2865
|
+
return buff;
|
|
2866
|
+
}
|
|
2867
|
+
return remainder;
|
|
2868
|
+
};
|
|
2869
|
+
module.exports = ReedSolomonEncoder;
|
|
2870
|
+
}
|
|
2871
|
+
});
|
|
2872
|
+
|
|
2873
|
+
// ../node_modules/qrcode/lib/core/version-check.js
|
|
2874
|
+
var require_version_check = __commonJS({
|
|
2875
|
+
"../node_modules/qrcode/lib/core/version-check.js"(exports) {
|
|
2876
|
+
exports.isValid = function isValid(version) {
|
|
2877
|
+
return !isNaN(version) && version >= 1 && version <= 40;
|
|
2878
|
+
};
|
|
2879
|
+
}
|
|
2880
|
+
});
|
|
2881
|
+
|
|
2882
|
+
// ../node_modules/qrcode/lib/core/regex.js
|
|
2883
|
+
var require_regex = __commonJS({
|
|
2884
|
+
"../node_modules/qrcode/lib/core/regex.js"(exports) {
|
|
2885
|
+
var numeric = "[0-9]+";
|
|
2886
|
+
var alphanumeric = "[A-Z $%*+\\-./:]+";
|
|
2887
|
+
var kanji = "(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";
|
|
2888
|
+
kanji = kanji.replace(/u/g, "\\u");
|
|
2889
|
+
var byte = "(?:(?![A-Z0-9 $%*+\\-./:]|" + kanji + ")(?:.|[\r\n]))+";
|
|
2890
|
+
exports.KANJI = new RegExp(kanji, "g");
|
|
2891
|
+
exports.BYTE_KANJI = new RegExp("[^A-Z0-9 $%*+\\-./:]+", "g");
|
|
2892
|
+
exports.BYTE = new RegExp(byte, "g");
|
|
2893
|
+
exports.NUMERIC = new RegExp(numeric, "g");
|
|
2894
|
+
exports.ALPHANUMERIC = new RegExp(alphanumeric, "g");
|
|
2895
|
+
var TEST_KANJI = new RegExp("^" + kanji + "$");
|
|
2896
|
+
var TEST_NUMERIC = new RegExp("^" + numeric + "$");
|
|
2897
|
+
var TEST_ALPHANUMERIC = new RegExp("^[A-Z0-9 $%*+\\-./:]+$");
|
|
2898
|
+
exports.testKanji = function testKanji(str) {
|
|
2899
|
+
return TEST_KANJI.test(str);
|
|
2900
|
+
};
|
|
2901
|
+
exports.testNumeric = function testNumeric(str) {
|
|
2902
|
+
return TEST_NUMERIC.test(str);
|
|
2903
|
+
};
|
|
2904
|
+
exports.testAlphanumeric = function testAlphanumeric(str) {
|
|
2905
|
+
return TEST_ALPHANUMERIC.test(str);
|
|
2906
|
+
};
|
|
2907
|
+
}
|
|
2908
|
+
});
|
|
2909
|
+
|
|
2910
|
+
// ../node_modules/qrcode/lib/core/mode.js
|
|
2911
|
+
var require_mode = __commonJS({
|
|
2912
|
+
"../node_modules/qrcode/lib/core/mode.js"(exports) {
|
|
2913
|
+
var VersionCheck = require_version_check();
|
|
2914
|
+
var Regex = require_regex();
|
|
2915
|
+
exports.NUMERIC = {
|
|
2916
|
+
id: "Numeric",
|
|
2917
|
+
bit: 1 << 0,
|
|
2918
|
+
ccBits: [10, 12, 14]
|
|
2919
|
+
};
|
|
2920
|
+
exports.ALPHANUMERIC = {
|
|
2921
|
+
id: "Alphanumeric",
|
|
2922
|
+
bit: 1 << 1,
|
|
2923
|
+
ccBits: [9, 11, 13]
|
|
2924
|
+
};
|
|
2925
|
+
exports.BYTE = {
|
|
2926
|
+
id: "Byte",
|
|
2927
|
+
bit: 1 << 2,
|
|
2928
|
+
ccBits: [8, 16, 16]
|
|
2929
|
+
};
|
|
2930
|
+
exports.KANJI = {
|
|
2931
|
+
id: "Kanji",
|
|
2932
|
+
bit: 1 << 3,
|
|
2933
|
+
ccBits: [8, 10, 12]
|
|
2934
|
+
};
|
|
2935
|
+
exports.MIXED = {
|
|
2936
|
+
bit: -1
|
|
2937
|
+
};
|
|
2938
|
+
exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
|
|
2939
|
+
if (!mode.ccBits) throw new Error("Invalid mode: " + mode);
|
|
2940
|
+
if (!VersionCheck.isValid(version)) {
|
|
2941
|
+
throw new Error("Invalid version: " + version);
|
|
2942
|
+
}
|
|
2943
|
+
if (version >= 1 && version < 10) return mode.ccBits[0];
|
|
2944
|
+
else if (version < 27) return mode.ccBits[1];
|
|
2945
|
+
return mode.ccBits[2];
|
|
2946
|
+
};
|
|
2947
|
+
exports.getBestModeForData = function getBestModeForData(dataStr) {
|
|
2948
|
+
if (Regex.testNumeric(dataStr)) return exports.NUMERIC;
|
|
2949
|
+
else if (Regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC;
|
|
2950
|
+
else if (Regex.testKanji(dataStr)) return exports.KANJI;
|
|
2951
|
+
else return exports.BYTE;
|
|
2952
|
+
};
|
|
2953
|
+
exports.toString = function toString(mode) {
|
|
2954
|
+
if (mode && mode.id) return mode.id;
|
|
2955
|
+
throw new Error("Invalid mode");
|
|
2956
|
+
};
|
|
2957
|
+
exports.isValid = function isValid(mode) {
|
|
2958
|
+
return mode && mode.bit && mode.ccBits;
|
|
2959
|
+
};
|
|
2960
|
+
function fromString(string) {
|
|
2961
|
+
if (typeof string !== "string") {
|
|
2962
|
+
throw new Error("Param is not a string");
|
|
2963
|
+
}
|
|
2964
|
+
const lcStr = string.toLowerCase();
|
|
2965
|
+
switch (lcStr) {
|
|
2966
|
+
case "numeric":
|
|
2967
|
+
return exports.NUMERIC;
|
|
2968
|
+
case "alphanumeric":
|
|
2969
|
+
return exports.ALPHANUMERIC;
|
|
2970
|
+
case "kanji":
|
|
2971
|
+
return exports.KANJI;
|
|
2972
|
+
case "byte":
|
|
2973
|
+
return exports.BYTE;
|
|
2974
|
+
default:
|
|
2975
|
+
throw new Error("Unknown mode: " + string);
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
exports.from = function from(value, defaultValue) {
|
|
2979
|
+
if (exports.isValid(value)) {
|
|
2980
|
+
return value;
|
|
2981
|
+
}
|
|
2982
|
+
try {
|
|
2983
|
+
return fromString(value);
|
|
2984
|
+
} catch (e) {
|
|
2985
|
+
return defaultValue;
|
|
2986
|
+
}
|
|
2987
|
+
};
|
|
2988
|
+
}
|
|
2989
|
+
});
|
|
2990
|
+
|
|
2991
|
+
// ../node_modules/qrcode/lib/core/version.js
|
|
2992
|
+
var require_version = __commonJS({
|
|
2993
|
+
"../node_modules/qrcode/lib/core/version.js"(exports) {
|
|
2994
|
+
var Utils = require_utils();
|
|
2995
|
+
var ECCode = require_error_correction_code();
|
|
2996
|
+
var ECLevel = require_error_correction_level();
|
|
2997
|
+
var Mode = require_mode();
|
|
2998
|
+
var VersionCheck = require_version_check();
|
|
2999
|
+
var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
|
|
3000
|
+
var G18_BCH = Utils.getBCHDigit(G18);
|
|
3001
|
+
function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
|
|
3002
|
+
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
|
3003
|
+
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
|
|
3004
|
+
return currentVersion;
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
return void 0;
|
|
3008
|
+
}
|
|
3009
|
+
function getReservedBitsCount(mode, version) {
|
|
3010
|
+
return Mode.getCharCountIndicator(mode, version) + 4;
|
|
3011
|
+
}
|
|
3012
|
+
function getTotalBitsFromDataArray(segments, version) {
|
|
3013
|
+
let totalBits = 0;
|
|
3014
|
+
segments.forEach(function(data) {
|
|
3015
|
+
const reservedBits = getReservedBitsCount(data.mode, version);
|
|
3016
|
+
totalBits += reservedBits + data.getBitsLength();
|
|
3017
|
+
});
|
|
3018
|
+
return totalBits;
|
|
3019
|
+
}
|
|
3020
|
+
function getBestVersionForMixedData(segments, errorCorrectionLevel) {
|
|
3021
|
+
for (let currentVersion = 1; currentVersion <= 40; currentVersion++) {
|
|
3022
|
+
const length = getTotalBitsFromDataArray(segments, currentVersion);
|
|
3023
|
+
if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, Mode.MIXED)) {
|
|
3024
|
+
return currentVersion;
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
return void 0;
|
|
3028
|
+
}
|
|
3029
|
+
exports.from = function from(value, defaultValue) {
|
|
3030
|
+
if (VersionCheck.isValid(value)) {
|
|
3031
|
+
return parseInt(value, 10);
|
|
3032
|
+
}
|
|
3033
|
+
return defaultValue;
|
|
3034
|
+
};
|
|
3035
|
+
exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode) {
|
|
3036
|
+
if (!VersionCheck.isValid(version)) {
|
|
3037
|
+
throw new Error("Invalid QR Code version");
|
|
3038
|
+
}
|
|
3039
|
+
if (typeof mode === "undefined") mode = Mode.BYTE;
|
|
3040
|
+
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
3041
|
+
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
3042
|
+
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
3043
|
+
if (mode === Mode.MIXED) return dataTotalCodewordsBits;
|
|
3044
|
+
const usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode, version);
|
|
3045
|
+
switch (mode) {
|
|
3046
|
+
case Mode.NUMERIC:
|
|
3047
|
+
return Math.floor(usableBits / 10 * 3);
|
|
3048
|
+
case Mode.ALPHANUMERIC:
|
|
3049
|
+
return Math.floor(usableBits / 11 * 2);
|
|
3050
|
+
case Mode.KANJI:
|
|
3051
|
+
return Math.floor(usableBits / 13);
|
|
3052
|
+
case Mode.BYTE:
|
|
3053
|
+
default:
|
|
3054
|
+
return Math.floor(usableBits / 8);
|
|
3055
|
+
}
|
|
3056
|
+
};
|
|
3057
|
+
exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel) {
|
|
3058
|
+
let seg;
|
|
3059
|
+
const ecl = ECLevel.from(errorCorrectionLevel, ECLevel.M);
|
|
3060
|
+
if (Array.isArray(data)) {
|
|
3061
|
+
if (data.length > 1) {
|
|
3062
|
+
return getBestVersionForMixedData(data, ecl);
|
|
3063
|
+
}
|
|
3064
|
+
if (data.length === 0) {
|
|
3065
|
+
return 1;
|
|
3066
|
+
}
|
|
3067
|
+
seg = data[0];
|
|
3068
|
+
} else {
|
|
3069
|
+
seg = data;
|
|
3070
|
+
}
|
|
3071
|
+
return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
|
|
3072
|
+
};
|
|
3073
|
+
exports.getEncodedBits = function getEncodedBits(version) {
|
|
3074
|
+
if (!VersionCheck.isValid(version) || version < 7) {
|
|
3075
|
+
throw new Error("Invalid QR Code version");
|
|
3076
|
+
}
|
|
3077
|
+
let d = version << 12;
|
|
3078
|
+
while (Utils.getBCHDigit(d) - G18_BCH >= 0) {
|
|
3079
|
+
d ^= G18 << Utils.getBCHDigit(d) - G18_BCH;
|
|
3080
|
+
}
|
|
3081
|
+
return version << 12 | d;
|
|
3082
|
+
};
|
|
3083
|
+
}
|
|
3084
|
+
});
|
|
3085
|
+
|
|
3086
|
+
// ../node_modules/qrcode/lib/core/format-info.js
|
|
3087
|
+
var require_format_info = __commonJS({
|
|
3088
|
+
"../node_modules/qrcode/lib/core/format-info.js"(exports) {
|
|
3089
|
+
var Utils = require_utils();
|
|
3090
|
+
var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
|
|
3091
|
+
var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
|
|
3092
|
+
var G15_BCH = Utils.getBCHDigit(G15);
|
|
3093
|
+
exports.getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
|
|
3094
|
+
const data = errorCorrectionLevel.bit << 3 | mask;
|
|
3095
|
+
let d = data << 10;
|
|
3096
|
+
while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
|
|
3097
|
+
d ^= G15 << Utils.getBCHDigit(d) - G15_BCH;
|
|
3098
|
+
}
|
|
3099
|
+
return (data << 10 | d) ^ G15_MASK;
|
|
3100
|
+
};
|
|
3101
|
+
}
|
|
3102
|
+
});
|
|
3103
|
+
|
|
3104
|
+
// ../node_modules/qrcode/lib/core/numeric-data.js
|
|
3105
|
+
var require_numeric_data = __commonJS({
|
|
3106
|
+
"../node_modules/qrcode/lib/core/numeric-data.js"(exports, module) {
|
|
3107
|
+
var Mode = require_mode();
|
|
3108
|
+
function NumericData(data) {
|
|
3109
|
+
this.mode = Mode.NUMERIC;
|
|
3110
|
+
this.data = data.toString();
|
|
3111
|
+
}
|
|
3112
|
+
NumericData.getBitsLength = function getBitsLength(length) {
|
|
3113
|
+
return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
|
|
3114
|
+
};
|
|
3115
|
+
NumericData.prototype.getLength = function getLength() {
|
|
3116
|
+
return this.data.length;
|
|
3117
|
+
};
|
|
3118
|
+
NumericData.prototype.getBitsLength = function getBitsLength() {
|
|
3119
|
+
return NumericData.getBitsLength(this.data.length);
|
|
3120
|
+
};
|
|
3121
|
+
NumericData.prototype.write = function write(bitBuffer) {
|
|
3122
|
+
let i, group, value;
|
|
3123
|
+
for (i = 0; i + 3 <= this.data.length; i += 3) {
|
|
3124
|
+
group = this.data.substr(i, 3);
|
|
3125
|
+
value = parseInt(group, 10);
|
|
3126
|
+
bitBuffer.put(value, 10);
|
|
3127
|
+
}
|
|
3128
|
+
const remainingNum = this.data.length - i;
|
|
3129
|
+
if (remainingNum > 0) {
|
|
3130
|
+
group = this.data.substr(i);
|
|
3131
|
+
value = parseInt(group, 10);
|
|
3132
|
+
bitBuffer.put(value, remainingNum * 3 + 1);
|
|
3133
|
+
}
|
|
3134
|
+
};
|
|
3135
|
+
module.exports = NumericData;
|
|
3136
|
+
}
|
|
3137
|
+
});
|
|
3138
|
+
|
|
3139
|
+
// ../node_modules/qrcode/lib/core/alphanumeric-data.js
|
|
3140
|
+
var require_alphanumeric_data = __commonJS({
|
|
3141
|
+
"../node_modules/qrcode/lib/core/alphanumeric-data.js"(exports, module) {
|
|
3142
|
+
var Mode = require_mode();
|
|
3143
|
+
var ALPHA_NUM_CHARS = [
|
|
3144
|
+
"0",
|
|
3145
|
+
"1",
|
|
3146
|
+
"2",
|
|
3147
|
+
"3",
|
|
3148
|
+
"4",
|
|
3149
|
+
"5",
|
|
3150
|
+
"6",
|
|
3151
|
+
"7",
|
|
3152
|
+
"8",
|
|
3153
|
+
"9",
|
|
3154
|
+
"A",
|
|
3155
|
+
"B",
|
|
3156
|
+
"C",
|
|
3157
|
+
"D",
|
|
3158
|
+
"E",
|
|
3159
|
+
"F",
|
|
3160
|
+
"G",
|
|
3161
|
+
"H",
|
|
3162
|
+
"I",
|
|
3163
|
+
"J",
|
|
3164
|
+
"K",
|
|
3165
|
+
"L",
|
|
3166
|
+
"M",
|
|
3167
|
+
"N",
|
|
3168
|
+
"O",
|
|
3169
|
+
"P",
|
|
3170
|
+
"Q",
|
|
3171
|
+
"R",
|
|
3172
|
+
"S",
|
|
3173
|
+
"T",
|
|
3174
|
+
"U",
|
|
3175
|
+
"V",
|
|
3176
|
+
"W",
|
|
3177
|
+
"X",
|
|
3178
|
+
"Y",
|
|
3179
|
+
"Z",
|
|
3180
|
+
" ",
|
|
3181
|
+
"$",
|
|
3182
|
+
"%",
|
|
3183
|
+
"*",
|
|
3184
|
+
"+",
|
|
3185
|
+
"-",
|
|
3186
|
+
".",
|
|
3187
|
+
"/",
|
|
3188
|
+
":"
|
|
3189
|
+
];
|
|
3190
|
+
function AlphanumericData(data) {
|
|
3191
|
+
this.mode = Mode.ALPHANUMERIC;
|
|
3192
|
+
this.data = data;
|
|
3193
|
+
}
|
|
3194
|
+
AlphanumericData.getBitsLength = function getBitsLength(length) {
|
|
3195
|
+
return 11 * Math.floor(length / 2) + 6 * (length % 2);
|
|
3196
|
+
};
|
|
3197
|
+
AlphanumericData.prototype.getLength = function getLength() {
|
|
3198
|
+
return this.data.length;
|
|
3199
|
+
};
|
|
3200
|
+
AlphanumericData.prototype.getBitsLength = function getBitsLength() {
|
|
3201
|
+
return AlphanumericData.getBitsLength(this.data.length);
|
|
3202
|
+
};
|
|
3203
|
+
AlphanumericData.prototype.write = function write(bitBuffer) {
|
|
3204
|
+
let i;
|
|
3205
|
+
for (i = 0; i + 2 <= this.data.length; i += 2) {
|
|
3206
|
+
let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;
|
|
3207
|
+
value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);
|
|
3208
|
+
bitBuffer.put(value, 11);
|
|
3209
|
+
}
|
|
3210
|
+
if (this.data.length % 2) {
|
|
3211
|
+
bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
|
|
3212
|
+
}
|
|
3213
|
+
};
|
|
3214
|
+
module.exports = AlphanumericData;
|
|
3215
|
+
}
|
|
3216
|
+
});
|
|
3217
|
+
|
|
3218
|
+
// ../node_modules/qrcode/lib/core/byte-data.js
|
|
3219
|
+
var require_byte_data = __commonJS({
|
|
3220
|
+
"../node_modules/qrcode/lib/core/byte-data.js"(exports, module) {
|
|
3221
|
+
var Mode = require_mode();
|
|
3222
|
+
function ByteData(data) {
|
|
3223
|
+
this.mode = Mode.BYTE;
|
|
3224
|
+
if (typeof data === "string") {
|
|
3225
|
+
this.data = new TextEncoder().encode(data);
|
|
3226
|
+
} else {
|
|
3227
|
+
this.data = new Uint8Array(data);
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
ByteData.getBitsLength = function getBitsLength(length) {
|
|
3231
|
+
return length * 8;
|
|
3232
|
+
};
|
|
3233
|
+
ByteData.prototype.getLength = function getLength() {
|
|
3234
|
+
return this.data.length;
|
|
3235
|
+
};
|
|
3236
|
+
ByteData.prototype.getBitsLength = function getBitsLength() {
|
|
3237
|
+
return ByteData.getBitsLength(this.data.length);
|
|
3238
|
+
};
|
|
3239
|
+
ByteData.prototype.write = function(bitBuffer) {
|
|
3240
|
+
for (let i = 0, l = this.data.length; i < l; i++) {
|
|
3241
|
+
bitBuffer.put(this.data[i], 8);
|
|
3242
|
+
}
|
|
3243
|
+
};
|
|
3244
|
+
module.exports = ByteData;
|
|
3245
|
+
}
|
|
3246
|
+
});
|
|
3247
|
+
|
|
3248
|
+
// ../node_modules/qrcode/lib/core/kanji-data.js
|
|
3249
|
+
var require_kanji_data = __commonJS({
|
|
3250
|
+
"../node_modules/qrcode/lib/core/kanji-data.js"(exports, module) {
|
|
3251
|
+
var Mode = require_mode();
|
|
3252
|
+
var Utils = require_utils();
|
|
3253
|
+
function KanjiData(data) {
|
|
3254
|
+
this.mode = Mode.KANJI;
|
|
3255
|
+
this.data = data;
|
|
3256
|
+
}
|
|
3257
|
+
KanjiData.getBitsLength = function getBitsLength(length) {
|
|
3258
|
+
return length * 13;
|
|
3259
|
+
};
|
|
3260
|
+
KanjiData.prototype.getLength = function getLength() {
|
|
3261
|
+
return this.data.length;
|
|
3262
|
+
};
|
|
3263
|
+
KanjiData.prototype.getBitsLength = function getBitsLength() {
|
|
3264
|
+
return KanjiData.getBitsLength(this.data.length);
|
|
3265
|
+
};
|
|
3266
|
+
KanjiData.prototype.write = function(bitBuffer) {
|
|
3267
|
+
let i;
|
|
3268
|
+
for (i = 0; i < this.data.length; i++) {
|
|
3269
|
+
let value = Utils.toSJIS(this.data[i]);
|
|
3270
|
+
if (value >= 33088 && value <= 40956) {
|
|
3271
|
+
value -= 33088;
|
|
3272
|
+
} else if (value >= 57408 && value <= 60351) {
|
|
3273
|
+
value -= 49472;
|
|
3274
|
+
} else {
|
|
3275
|
+
throw new Error(
|
|
3276
|
+
"Invalid SJIS character: " + this.data[i] + "\nMake sure your charset is UTF-8"
|
|
3277
|
+
);
|
|
3278
|
+
}
|
|
3279
|
+
value = (value >>> 8 & 255) * 192 + (value & 255);
|
|
3280
|
+
bitBuffer.put(value, 13);
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
module.exports = KanjiData;
|
|
3284
|
+
}
|
|
3285
|
+
});
|
|
3286
|
+
|
|
3287
|
+
// ../node_modules/dijkstrajs/dijkstra.js
|
|
3288
|
+
var require_dijkstra = __commonJS({
|
|
3289
|
+
"../node_modules/dijkstrajs/dijkstra.js"(exports, module) {
|
|
3290
|
+
"use strict";
|
|
3291
|
+
var dijkstra = {
|
|
3292
|
+
single_source_shortest_paths: function(graph, s, d) {
|
|
3293
|
+
var predecessors = {};
|
|
3294
|
+
var costs = {};
|
|
3295
|
+
costs[s] = 0;
|
|
3296
|
+
var open = dijkstra.PriorityQueue.make();
|
|
3297
|
+
open.push(s, 0);
|
|
3298
|
+
var closest, u, v, cost_of_s_to_u, adjacent_nodes, cost_of_e, cost_of_s_to_u_plus_cost_of_e, cost_of_s_to_v, first_visit;
|
|
3299
|
+
while (!open.empty()) {
|
|
3300
|
+
closest = open.pop();
|
|
3301
|
+
u = closest.value;
|
|
3302
|
+
cost_of_s_to_u = closest.cost;
|
|
3303
|
+
adjacent_nodes = graph[u] || {};
|
|
3304
|
+
for (v in adjacent_nodes) {
|
|
3305
|
+
if (adjacent_nodes.hasOwnProperty(v)) {
|
|
3306
|
+
cost_of_e = adjacent_nodes[v];
|
|
3307
|
+
cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e;
|
|
3308
|
+
cost_of_s_to_v = costs[v];
|
|
3309
|
+
first_visit = typeof costs[v] === "undefined";
|
|
3310
|
+
if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
|
|
3311
|
+
costs[v] = cost_of_s_to_u_plus_cost_of_e;
|
|
3312
|
+
open.push(v, cost_of_s_to_u_plus_cost_of_e);
|
|
3313
|
+
predecessors[v] = u;
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
if (typeof d !== "undefined" && typeof costs[d] === "undefined") {
|
|
3319
|
+
var msg = ["Could not find a path from ", s, " to ", d, "."].join("");
|
|
3320
|
+
throw new Error(msg);
|
|
3321
|
+
}
|
|
3322
|
+
return predecessors;
|
|
3323
|
+
},
|
|
3324
|
+
extract_shortest_path_from_predecessor_list: function(predecessors, d) {
|
|
3325
|
+
var nodes = [];
|
|
3326
|
+
var u = d;
|
|
3327
|
+
var predecessor;
|
|
3328
|
+
while (u) {
|
|
3329
|
+
nodes.push(u);
|
|
3330
|
+
predecessor = predecessors[u];
|
|
3331
|
+
u = predecessors[u];
|
|
3332
|
+
}
|
|
3333
|
+
nodes.reverse();
|
|
3334
|
+
return nodes;
|
|
3335
|
+
},
|
|
3336
|
+
find_path: function(graph, s, d) {
|
|
3337
|
+
var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
|
|
3338
|
+
return dijkstra.extract_shortest_path_from_predecessor_list(
|
|
3339
|
+
predecessors,
|
|
3340
|
+
d
|
|
3341
|
+
);
|
|
3342
|
+
},
|
|
3343
|
+
/**
|
|
3344
|
+
* A very naive priority queue implementation.
|
|
3345
|
+
*/
|
|
3346
|
+
PriorityQueue: {
|
|
3347
|
+
make: function(opts) {
|
|
3348
|
+
var T = dijkstra.PriorityQueue, t = {}, key;
|
|
3349
|
+
opts = opts || {};
|
|
3350
|
+
for (key in T) {
|
|
3351
|
+
if (T.hasOwnProperty(key)) {
|
|
3352
|
+
t[key] = T[key];
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
t.queue = [];
|
|
3356
|
+
t.sorter = opts.sorter || T.default_sorter;
|
|
3357
|
+
return t;
|
|
3358
|
+
},
|
|
3359
|
+
default_sorter: function(a, b) {
|
|
3360
|
+
return a.cost - b.cost;
|
|
3361
|
+
},
|
|
3362
|
+
/**
|
|
3363
|
+
* Add a new item to the queue and ensure the highest priority element
|
|
3364
|
+
* is at the front of the queue.
|
|
3365
|
+
*/
|
|
3366
|
+
push: function(value, cost) {
|
|
3367
|
+
var item = { value, cost };
|
|
3368
|
+
this.queue.push(item);
|
|
3369
|
+
this.queue.sort(this.sorter);
|
|
3370
|
+
},
|
|
3371
|
+
/**
|
|
3372
|
+
* Return the highest priority element in the queue.
|
|
3373
|
+
*/
|
|
3374
|
+
pop: function() {
|
|
3375
|
+
return this.queue.shift();
|
|
3376
|
+
},
|
|
3377
|
+
empty: function() {
|
|
3378
|
+
return this.queue.length === 0;
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
};
|
|
3382
|
+
if (typeof module !== "undefined") {
|
|
3383
|
+
module.exports = dijkstra;
|
|
3384
|
+
}
|
|
3385
|
+
}
|
|
3386
|
+
});
|
|
3387
|
+
|
|
3388
|
+
// ../node_modules/qrcode/lib/core/segments.js
|
|
3389
|
+
var require_segments = __commonJS({
|
|
3390
|
+
"../node_modules/qrcode/lib/core/segments.js"(exports) {
|
|
3391
|
+
var Mode = require_mode();
|
|
3392
|
+
var NumericData = require_numeric_data();
|
|
3393
|
+
var AlphanumericData = require_alphanumeric_data();
|
|
3394
|
+
var ByteData = require_byte_data();
|
|
3395
|
+
var KanjiData = require_kanji_data();
|
|
3396
|
+
var Regex = require_regex();
|
|
3397
|
+
var Utils = require_utils();
|
|
3398
|
+
var dijkstra = require_dijkstra();
|
|
3399
|
+
function getStringByteLength(str) {
|
|
3400
|
+
return unescape(encodeURIComponent(str)).length;
|
|
3401
|
+
}
|
|
3402
|
+
function getSegments(regex, mode, str) {
|
|
3403
|
+
const segments = [];
|
|
3404
|
+
let result;
|
|
3405
|
+
while ((result = regex.exec(str)) !== null) {
|
|
3406
|
+
segments.push({
|
|
3407
|
+
data: result[0],
|
|
3408
|
+
index: result.index,
|
|
3409
|
+
mode,
|
|
3410
|
+
length: result[0].length
|
|
3411
|
+
});
|
|
3412
|
+
}
|
|
3413
|
+
return segments;
|
|
3414
|
+
}
|
|
3415
|
+
function getSegmentsFromString(dataStr) {
|
|
3416
|
+
const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr);
|
|
3417
|
+
const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr);
|
|
3418
|
+
let byteSegs;
|
|
3419
|
+
let kanjiSegs;
|
|
3420
|
+
if (Utils.isKanjiModeEnabled()) {
|
|
3421
|
+
byteSegs = getSegments(Regex.BYTE, Mode.BYTE, dataStr);
|
|
3422
|
+
kanjiSegs = getSegments(Regex.KANJI, Mode.KANJI, dataStr);
|
|
3423
|
+
} else {
|
|
3424
|
+
byteSegs = getSegments(Regex.BYTE_KANJI, Mode.BYTE, dataStr);
|
|
3425
|
+
kanjiSegs = [];
|
|
3426
|
+
}
|
|
3427
|
+
const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
|
|
3428
|
+
return segs.sort(function(s1, s2) {
|
|
3429
|
+
return s1.index - s2.index;
|
|
3430
|
+
}).map(function(obj) {
|
|
3431
|
+
return {
|
|
3432
|
+
data: obj.data,
|
|
3433
|
+
mode: obj.mode,
|
|
3434
|
+
length: obj.length
|
|
3435
|
+
};
|
|
3436
|
+
});
|
|
3437
|
+
}
|
|
3438
|
+
function getSegmentBitsLength(length, mode) {
|
|
3439
|
+
switch (mode) {
|
|
3440
|
+
case Mode.NUMERIC:
|
|
3441
|
+
return NumericData.getBitsLength(length);
|
|
3442
|
+
case Mode.ALPHANUMERIC:
|
|
3443
|
+
return AlphanumericData.getBitsLength(length);
|
|
3444
|
+
case Mode.KANJI:
|
|
3445
|
+
return KanjiData.getBitsLength(length);
|
|
3446
|
+
case Mode.BYTE:
|
|
3447
|
+
return ByteData.getBitsLength(length);
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
function mergeSegments(segs) {
|
|
3451
|
+
return segs.reduce(function(acc, curr) {
|
|
3452
|
+
const prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
|
|
3453
|
+
if (prevSeg && prevSeg.mode === curr.mode) {
|
|
3454
|
+
acc[acc.length - 1].data += curr.data;
|
|
3455
|
+
return acc;
|
|
3456
|
+
}
|
|
3457
|
+
acc.push(curr);
|
|
3458
|
+
return acc;
|
|
3459
|
+
}, []);
|
|
3460
|
+
}
|
|
3461
|
+
function buildNodes(segs) {
|
|
3462
|
+
const nodes = [];
|
|
3463
|
+
for (let i = 0; i < segs.length; i++) {
|
|
3464
|
+
const seg = segs[i];
|
|
3465
|
+
switch (seg.mode) {
|
|
3466
|
+
case Mode.NUMERIC:
|
|
3467
|
+
nodes.push([
|
|
3468
|
+
seg,
|
|
3469
|
+
{ data: seg.data, mode: Mode.ALPHANUMERIC, length: seg.length },
|
|
3470
|
+
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
3471
|
+
]);
|
|
3472
|
+
break;
|
|
3473
|
+
case Mode.ALPHANUMERIC:
|
|
3474
|
+
nodes.push([
|
|
3475
|
+
seg,
|
|
3476
|
+
{ data: seg.data, mode: Mode.BYTE, length: seg.length }
|
|
3477
|
+
]);
|
|
3478
|
+
break;
|
|
3479
|
+
case Mode.KANJI:
|
|
3480
|
+
nodes.push([
|
|
3481
|
+
seg,
|
|
3482
|
+
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
3483
|
+
]);
|
|
3484
|
+
break;
|
|
3485
|
+
case Mode.BYTE:
|
|
3486
|
+
nodes.push([
|
|
3487
|
+
{ data: seg.data, mode: Mode.BYTE, length: getStringByteLength(seg.data) }
|
|
3488
|
+
]);
|
|
3489
|
+
}
|
|
3490
|
+
}
|
|
3491
|
+
return nodes;
|
|
3492
|
+
}
|
|
3493
|
+
function buildGraph(nodes, version) {
|
|
3494
|
+
const table2 = {};
|
|
3495
|
+
const graph = { start: {} };
|
|
3496
|
+
let prevNodeIds = ["start"];
|
|
3497
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
3498
|
+
const nodeGroup = nodes[i];
|
|
3499
|
+
const currentNodeIds = [];
|
|
3500
|
+
for (let j = 0; j < nodeGroup.length; j++) {
|
|
3501
|
+
const node = nodeGroup[j];
|
|
3502
|
+
const key = "" + i + j;
|
|
3503
|
+
currentNodeIds.push(key);
|
|
3504
|
+
table2[key] = { node, lastCount: 0 };
|
|
3505
|
+
graph[key] = {};
|
|
3506
|
+
for (let n = 0; n < prevNodeIds.length; n++) {
|
|
3507
|
+
const prevNodeId = prevNodeIds[n];
|
|
3508
|
+
if (table2[prevNodeId] && table2[prevNodeId].node.mode === node.mode) {
|
|
3509
|
+
graph[prevNodeId][key] = getSegmentBitsLength(table2[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table2[prevNodeId].lastCount, node.mode);
|
|
3510
|
+
table2[prevNodeId].lastCount += node.length;
|
|
3511
|
+
} else {
|
|
3512
|
+
if (table2[prevNodeId]) table2[prevNodeId].lastCount = node.length;
|
|
3513
|
+
graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + Mode.getCharCountIndicator(node.mode, version);
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
prevNodeIds = currentNodeIds;
|
|
3518
|
+
}
|
|
3519
|
+
for (let n = 0; n < prevNodeIds.length; n++) {
|
|
3520
|
+
graph[prevNodeIds[n]].end = 0;
|
|
3521
|
+
}
|
|
3522
|
+
return { map: graph, table: table2 };
|
|
3523
|
+
}
|
|
3524
|
+
function buildSingleSegment(data, modesHint) {
|
|
3525
|
+
let mode;
|
|
3526
|
+
const bestMode = Mode.getBestModeForData(data);
|
|
3527
|
+
mode = Mode.from(modesHint, bestMode);
|
|
3528
|
+
if (mode !== Mode.BYTE && mode.bit < bestMode.bit) {
|
|
3529
|
+
throw new Error('"' + data + '" cannot be encoded with mode ' + Mode.toString(mode) + ".\n Suggested mode is: " + Mode.toString(bestMode));
|
|
3530
|
+
}
|
|
3531
|
+
if (mode === Mode.KANJI && !Utils.isKanjiModeEnabled()) {
|
|
3532
|
+
mode = Mode.BYTE;
|
|
3533
|
+
}
|
|
3534
|
+
switch (mode) {
|
|
3535
|
+
case Mode.NUMERIC:
|
|
3536
|
+
return new NumericData(data);
|
|
3537
|
+
case Mode.ALPHANUMERIC:
|
|
3538
|
+
return new AlphanumericData(data);
|
|
3539
|
+
case Mode.KANJI:
|
|
3540
|
+
return new KanjiData(data);
|
|
3541
|
+
case Mode.BYTE:
|
|
3542
|
+
return new ByteData(data);
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
exports.fromArray = function fromArray(array) {
|
|
3546
|
+
return array.reduce(function(acc, seg) {
|
|
3547
|
+
if (typeof seg === "string") {
|
|
3548
|
+
acc.push(buildSingleSegment(seg, null));
|
|
3549
|
+
} else if (seg.data) {
|
|
3550
|
+
acc.push(buildSingleSegment(seg.data, seg.mode));
|
|
3551
|
+
}
|
|
3552
|
+
return acc;
|
|
3553
|
+
}, []);
|
|
3554
|
+
};
|
|
3555
|
+
exports.fromString = function fromString(data, version) {
|
|
3556
|
+
const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
|
|
3557
|
+
const nodes = buildNodes(segs);
|
|
3558
|
+
const graph = buildGraph(nodes, version);
|
|
3559
|
+
const path = dijkstra.find_path(graph.map, "start", "end");
|
|
3560
|
+
const optimizedSegs = [];
|
|
3561
|
+
for (let i = 1; i < path.length - 1; i++) {
|
|
3562
|
+
optimizedSegs.push(graph.table[path[i]].node);
|
|
3563
|
+
}
|
|
3564
|
+
return exports.fromArray(mergeSegments(optimizedSegs));
|
|
3565
|
+
};
|
|
3566
|
+
exports.rawSplit = function rawSplit(data) {
|
|
3567
|
+
return exports.fromArray(
|
|
3568
|
+
getSegmentsFromString(data, Utils.isKanjiModeEnabled())
|
|
3569
|
+
);
|
|
3570
|
+
};
|
|
3571
|
+
}
|
|
3572
|
+
});
|
|
3573
|
+
|
|
3574
|
+
// ../node_modules/qrcode/lib/core/qrcode.js
|
|
3575
|
+
var require_qrcode = __commonJS({
|
|
3576
|
+
"../node_modules/qrcode/lib/core/qrcode.js"(exports) {
|
|
3577
|
+
var Utils = require_utils();
|
|
3578
|
+
var ECLevel = require_error_correction_level();
|
|
3579
|
+
var BitBuffer = require_bit_buffer();
|
|
3580
|
+
var BitMatrix = require_bit_matrix();
|
|
3581
|
+
var AlignmentPattern = require_alignment_pattern();
|
|
3582
|
+
var FinderPattern = require_finder_pattern();
|
|
3583
|
+
var MaskPattern = require_mask_pattern();
|
|
3584
|
+
var ECCode = require_error_correction_code();
|
|
3585
|
+
var ReedSolomonEncoder = require_reed_solomon_encoder();
|
|
3586
|
+
var Version = require_version();
|
|
3587
|
+
var FormatInfo = require_format_info();
|
|
3588
|
+
var Mode = require_mode();
|
|
3589
|
+
var Segments = require_segments();
|
|
3590
|
+
function setupFinderPattern(matrix, version) {
|
|
3591
|
+
const size = matrix.size;
|
|
3592
|
+
const pos = FinderPattern.getPositions(version);
|
|
3593
|
+
for (let i = 0; i < pos.length; i++) {
|
|
3594
|
+
const row = pos[i][0];
|
|
3595
|
+
const col = pos[i][1];
|
|
3596
|
+
for (let r = -1; r <= 7; r++) {
|
|
3597
|
+
if (row + r <= -1 || size <= row + r) continue;
|
|
3598
|
+
for (let c2 = -1; c2 <= 7; c2++) {
|
|
3599
|
+
if (col + c2 <= -1 || size <= col + c2) continue;
|
|
3600
|
+
if (r >= 0 && r <= 6 && (c2 === 0 || c2 === 6) || c2 >= 0 && c2 <= 6 && (r === 0 || r === 6) || r >= 2 && r <= 4 && c2 >= 2 && c2 <= 4) {
|
|
3601
|
+
matrix.set(row + r, col + c2, true, true);
|
|
3602
|
+
} else {
|
|
3603
|
+
matrix.set(row + r, col + c2, false, true);
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
}
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
function setupTimingPattern(matrix) {
|
|
3610
|
+
const size = matrix.size;
|
|
3611
|
+
for (let r = 8; r < size - 8; r++) {
|
|
3612
|
+
const value = r % 2 === 0;
|
|
3613
|
+
matrix.set(r, 6, value, true);
|
|
3614
|
+
matrix.set(6, r, value, true);
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
function setupAlignmentPattern(matrix, version) {
|
|
3618
|
+
const pos = AlignmentPattern.getPositions(version);
|
|
3619
|
+
for (let i = 0; i < pos.length; i++) {
|
|
3620
|
+
const row = pos[i][0];
|
|
3621
|
+
const col = pos[i][1];
|
|
3622
|
+
for (let r = -2; r <= 2; r++) {
|
|
3623
|
+
for (let c2 = -2; c2 <= 2; c2++) {
|
|
3624
|
+
if (r === -2 || r === 2 || c2 === -2 || c2 === 2 || r === 0 && c2 === 0) {
|
|
3625
|
+
matrix.set(row + r, col + c2, true, true);
|
|
3626
|
+
} else {
|
|
3627
|
+
matrix.set(row + r, col + c2, false, true);
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
}
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
function setupVersionInfo(matrix, version) {
|
|
3634
|
+
const size = matrix.size;
|
|
3635
|
+
const bits = Version.getEncodedBits(version);
|
|
3636
|
+
let row, col, mod;
|
|
3637
|
+
for (let i = 0; i < 18; i++) {
|
|
3638
|
+
row = Math.floor(i / 3);
|
|
3639
|
+
col = i % 3 + size - 8 - 3;
|
|
3640
|
+
mod = (bits >> i & 1) === 1;
|
|
3641
|
+
matrix.set(row, col, mod, true);
|
|
3642
|
+
matrix.set(col, row, mod, true);
|
|
3643
|
+
}
|
|
3644
|
+
}
|
|
3645
|
+
function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
|
|
3646
|
+
const size = matrix.size;
|
|
3647
|
+
const bits = FormatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
|
|
3648
|
+
let i, mod;
|
|
3649
|
+
for (i = 0; i < 15; i++) {
|
|
3650
|
+
mod = (bits >> i & 1) === 1;
|
|
3651
|
+
if (i < 6) {
|
|
3652
|
+
matrix.set(i, 8, mod, true);
|
|
3653
|
+
} else if (i < 8) {
|
|
3654
|
+
matrix.set(i + 1, 8, mod, true);
|
|
3655
|
+
} else {
|
|
3656
|
+
matrix.set(size - 15 + i, 8, mod, true);
|
|
3657
|
+
}
|
|
3658
|
+
if (i < 8) {
|
|
3659
|
+
matrix.set(8, size - i - 1, mod, true);
|
|
3660
|
+
} else if (i < 9) {
|
|
3661
|
+
matrix.set(8, 15 - i - 1 + 1, mod, true);
|
|
3662
|
+
} else {
|
|
3663
|
+
matrix.set(8, 15 - i - 1, mod, true);
|
|
3664
|
+
}
|
|
3665
|
+
}
|
|
3666
|
+
matrix.set(size - 8, 8, 1, true);
|
|
3667
|
+
}
|
|
3668
|
+
function setupData(matrix, data) {
|
|
3669
|
+
const size = matrix.size;
|
|
3670
|
+
let inc = -1;
|
|
3671
|
+
let row = size - 1;
|
|
3672
|
+
let bitIndex = 7;
|
|
3673
|
+
let byteIndex = 0;
|
|
3674
|
+
for (let col = size - 1; col > 0; col -= 2) {
|
|
3675
|
+
if (col === 6) col--;
|
|
3676
|
+
while (true) {
|
|
3677
|
+
for (let c2 = 0; c2 < 2; c2++) {
|
|
3678
|
+
if (!matrix.isReserved(row, col - c2)) {
|
|
3679
|
+
let dark = false;
|
|
3680
|
+
if (byteIndex < data.length) {
|
|
3681
|
+
dark = (data[byteIndex] >>> bitIndex & 1) === 1;
|
|
3682
|
+
}
|
|
3683
|
+
matrix.set(row, col - c2, dark);
|
|
3684
|
+
bitIndex--;
|
|
3685
|
+
if (bitIndex === -1) {
|
|
3686
|
+
byteIndex++;
|
|
3687
|
+
bitIndex = 7;
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
3690
|
+
}
|
|
3691
|
+
row += inc;
|
|
3692
|
+
if (row < 0 || size <= row) {
|
|
3693
|
+
row -= inc;
|
|
3694
|
+
inc = -inc;
|
|
3695
|
+
break;
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
function createData(version, errorCorrectionLevel, segments) {
|
|
3701
|
+
const buffer = new BitBuffer();
|
|
3702
|
+
segments.forEach(function(data) {
|
|
3703
|
+
buffer.put(data.mode.bit, 4);
|
|
3704
|
+
buffer.put(data.getLength(), Mode.getCharCountIndicator(data.mode, version));
|
|
3705
|
+
data.write(buffer);
|
|
3706
|
+
});
|
|
3707
|
+
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
3708
|
+
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
3709
|
+
const dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
|
|
3710
|
+
if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
|
|
3711
|
+
buffer.put(0, 4);
|
|
3712
|
+
}
|
|
3713
|
+
while (buffer.getLengthInBits() % 8 !== 0) {
|
|
3714
|
+
buffer.putBit(0);
|
|
3715
|
+
}
|
|
3716
|
+
const remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
|
|
3717
|
+
for (let i = 0; i < remainingByte; i++) {
|
|
3718
|
+
buffer.put(i % 2 ? 17 : 236, 8);
|
|
3719
|
+
}
|
|
3720
|
+
return createCodewords(buffer, version, errorCorrectionLevel);
|
|
3721
|
+
}
|
|
3722
|
+
function createCodewords(bitBuffer, version, errorCorrectionLevel) {
|
|
3723
|
+
const totalCodewords = Utils.getSymbolTotalCodewords(version);
|
|
3724
|
+
const ecTotalCodewords = ECCode.getTotalCodewordsCount(version, errorCorrectionLevel);
|
|
3725
|
+
const dataTotalCodewords = totalCodewords - ecTotalCodewords;
|
|
3726
|
+
const ecTotalBlocks = ECCode.getBlocksCount(version, errorCorrectionLevel);
|
|
3727
|
+
const blocksInGroup2 = totalCodewords % ecTotalBlocks;
|
|
3728
|
+
const blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
|
|
3729
|
+
const totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
|
|
3730
|
+
const dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
|
|
3731
|
+
const dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1;
|
|
3732
|
+
const ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1;
|
|
3733
|
+
const rs = new ReedSolomonEncoder(ecCount);
|
|
3734
|
+
let offset = 0;
|
|
3735
|
+
const dcData = new Array(ecTotalBlocks);
|
|
3736
|
+
const ecData = new Array(ecTotalBlocks);
|
|
3737
|
+
let maxDataSize = 0;
|
|
3738
|
+
const buffer = new Uint8Array(bitBuffer.buffer);
|
|
3739
|
+
for (let b = 0; b < ecTotalBlocks; b++) {
|
|
3740
|
+
const dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2;
|
|
3741
|
+
dcData[b] = buffer.slice(offset, offset + dataSize);
|
|
3742
|
+
ecData[b] = rs.encode(dcData[b]);
|
|
3743
|
+
offset += dataSize;
|
|
3744
|
+
maxDataSize = Math.max(maxDataSize, dataSize);
|
|
3745
|
+
}
|
|
3746
|
+
const data = new Uint8Array(totalCodewords);
|
|
3747
|
+
let index = 0;
|
|
3748
|
+
let i, r;
|
|
3749
|
+
for (i = 0; i < maxDataSize; i++) {
|
|
3750
|
+
for (r = 0; r < ecTotalBlocks; r++) {
|
|
3751
|
+
if (i < dcData[r].length) {
|
|
3752
|
+
data[index++] = dcData[r][i];
|
|
3753
|
+
}
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
for (i = 0; i < ecCount; i++) {
|
|
3757
|
+
for (r = 0; r < ecTotalBlocks; r++) {
|
|
3758
|
+
data[index++] = ecData[r][i];
|
|
3759
|
+
}
|
|
3760
|
+
}
|
|
3761
|
+
return data;
|
|
3762
|
+
}
|
|
3763
|
+
function createSymbol(data, version, errorCorrectionLevel, maskPattern) {
|
|
3764
|
+
let segments;
|
|
3765
|
+
if (Array.isArray(data)) {
|
|
3766
|
+
segments = Segments.fromArray(data);
|
|
3767
|
+
} else if (typeof data === "string") {
|
|
3768
|
+
let estimatedVersion = version;
|
|
3769
|
+
if (!estimatedVersion) {
|
|
3770
|
+
const rawSegments = Segments.rawSplit(data);
|
|
3771
|
+
estimatedVersion = Version.getBestVersionForData(rawSegments, errorCorrectionLevel);
|
|
3772
|
+
}
|
|
3773
|
+
segments = Segments.fromString(data, estimatedVersion || 40);
|
|
3774
|
+
} else {
|
|
3775
|
+
throw new Error("Invalid data");
|
|
3776
|
+
}
|
|
3777
|
+
const bestVersion = Version.getBestVersionForData(segments, errorCorrectionLevel);
|
|
3778
|
+
if (!bestVersion) {
|
|
3779
|
+
throw new Error("The amount of data is too big to be stored in a QR Code");
|
|
3780
|
+
}
|
|
3781
|
+
if (!version) {
|
|
3782
|
+
version = bestVersion;
|
|
3783
|
+
} else if (version < bestVersion) {
|
|
3784
|
+
throw new Error(
|
|
3785
|
+
"\nThe chosen QR Code version cannot contain this amount of data.\nMinimum version required to store current data is: " + bestVersion + ".\n"
|
|
3786
|
+
);
|
|
3787
|
+
}
|
|
3788
|
+
const dataBits = createData(version, errorCorrectionLevel, segments);
|
|
3789
|
+
const moduleCount = Utils.getSymbolSize(version);
|
|
3790
|
+
const modules = new BitMatrix(moduleCount);
|
|
3791
|
+
setupFinderPattern(modules, version);
|
|
3792
|
+
setupTimingPattern(modules);
|
|
3793
|
+
setupAlignmentPattern(modules, version);
|
|
3794
|
+
setupFormatInfo(modules, errorCorrectionLevel, 0);
|
|
3795
|
+
if (version >= 7) {
|
|
3796
|
+
setupVersionInfo(modules, version);
|
|
3797
|
+
}
|
|
3798
|
+
setupData(modules, dataBits);
|
|
3799
|
+
if (isNaN(maskPattern)) {
|
|
3800
|
+
maskPattern = MaskPattern.getBestMask(
|
|
3801
|
+
modules,
|
|
3802
|
+
setupFormatInfo.bind(null, modules, errorCorrectionLevel)
|
|
3803
|
+
);
|
|
3804
|
+
}
|
|
3805
|
+
MaskPattern.applyMask(maskPattern, modules);
|
|
3806
|
+
setupFormatInfo(modules, errorCorrectionLevel, maskPattern);
|
|
3807
|
+
return {
|
|
3808
|
+
modules,
|
|
3809
|
+
version,
|
|
3810
|
+
errorCorrectionLevel,
|
|
3811
|
+
maskPattern,
|
|
3812
|
+
segments
|
|
3813
|
+
};
|
|
3814
|
+
}
|
|
3815
|
+
exports.create = function create(data, options) {
|
|
3816
|
+
if (typeof data === "undefined" || data === "") {
|
|
3817
|
+
throw new Error("No input text");
|
|
3818
|
+
}
|
|
3819
|
+
let errorCorrectionLevel = ECLevel.M;
|
|
3820
|
+
let version;
|
|
3821
|
+
let mask;
|
|
3822
|
+
if (typeof options !== "undefined") {
|
|
3823
|
+
errorCorrectionLevel = ECLevel.from(options.errorCorrectionLevel, ECLevel.M);
|
|
3824
|
+
version = Version.from(options.version);
|
|
3825
|
+
mask = MaskPattern.from(options.maskPattern);
|
|
3826
|
+
if (options.toSJISFunc) {
|
|
3827
|
+
Utils.setToSJISFunction(options.toSJISFunc);
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
return createSymbol(data, version, errorCorrectionLevel, mask);
|
|
3831
|
+
};
|
|
3832
|
+
}
|
|
3833
|
+
});
|
|
3834
|
+
|
|
1961
3835
|
// src/extra.ts
|
|
1962
3836
|
var extra_exports = {};
|
|
1963
3837
|
__export(extra_exports, {
|
|
@@ -1965,6 +3839,8 @@ __export(extra_exports, {
|
|
|
1965
3839
|
accessCloudflare: () => accessCloudflare,
|
|
1966
3840
|
accessSet: () => accessSet,
|
|
1967
3841
|
accessShow: () => accessShow,
|
|
3842
|
+
pair: () => pair,
|
|
3843
|
+
qrBlocks: () => qrBlocks,
|
|
1968
3844
|
skill: () => skill,
|
|
1969
3845
|
ui: () => ui
|
|
1970
3846
|
});
|
|
@@ -1996,6 +3872,35 @@ async function ui(opts) {
|
|
|
1996
3872
|
}
|
|
1997
3873
|
ok(`Opened the dashboard for ${cfg.url} ${c.dim("(one-time link, valid 2 minutes)")}`);
|
|
1998
3874
|
}
|
|
3875
|
+
function qrBlocks(text) {
|
|
3876
|
+
const qr = (0, import_qrcode.create)(text, { errorCorrectionLevel: "M" });
|
|
3877
|
+
const n = qr.modules.size;
|
|
3878
|
+
const q = 2;
|
|
3879
|
+
const dark = (x, y) => x >= 0 && y >= 0 && x < n && y < n && Boolean(qr.modules.get(y, x));
|
|
3880
|
+
const out2 = [];
|
|
3881
|
+
for (let y = -q; y < n + q; y += 2) {
|
|
3882
|
+
let row = "";
|
|
3883
|
+
for (let x = -q; x < n + q; x++) {
|
|
3884
|
+
const top = dark(x, y);
|
|
3885
|
+
const bottom = dark(x, y + 1);
|
|
3886
|
+
row += top && bottom ? "\u2588" : top ? "\u2580" : bottom ? "\u2584" : " ";
|
|
3887
|
+
}
|
|
3888
|
+
out2.push(` \x1B[30;107m${row}\x1B[0m`);
|
|
3889
|
+
}
|
|
3890
|
+
return out2.join("\n") + "\n";
|
|
3891
|
+
}
|
|
3892
|
+
async function pair() {
|
|
3893
|
+
if (!process.stderr.isTTY) {
|
|
3894
|
+
throw new UserError("keybox pair draws a QR code for your phone; run it yourself in a terminal. (For a browser, use `keybox ui`.)");
|
|
3895
|
+
}
|
|
3896
|
+
const cfg = requireConfig();
|
|
3897
|
+
const { code } = await api("POST", "/ui/link");
|
|
3898
|
+
const url = `${cfg.url.replace(/\/$/, "")}/_keybox/ui#code=${code}`;
|
|
3899
|
+
step(`Scan this with the Keybox app ${c.dim("(Pair \u203A Scan QR code)")}`);
|
|
3900
|
+
process.stderr.write("\n" + qrBlocks(url) + "\n");
|
|
3901
|
+
note("Works once, for 2 minutes. The app gets a 12-hour session; your admin token stays on this machine.");
|
|
3902
|
+
note("To end every dashboard and app session: Access \u203A Sign out every dashboard session.");
|
|
3903
|
+
}
|
|
1999
3904
|
async function accessShow() {
|
|
2000
3905
|
const [p, me] = await Promise.all([api("GET", "/policy"), api("GET", "/whoami")]);
|
|
2001
3906
|
process.stdout.write(
|
|
@@ -2088,10 +3993,11 @@ async function skill(opts) {
|
|
|
2088
3993
|
step("Agents that load skills now know how to set up Keybox, migrate keys and write narrow rules safely.");
|
|
2089
3994
|
note('Ask yours: "set up keybox for this project".');
|
|
2090
3995
|
}
|
|
2091
|
-
var describe, skillAsset;
|
|
3996
|
+
var import_qrcode, describe, skillAsset;
|
|
2092
3997
|
var init_extra = __esm({
|
|
2093
3998
|
"src/extra.ts"() {
|
|
2094
3999
|
"use strict";
|
|
4000
|
+
import_qrcode = __toESM(require_qrcode(), 1);
|
|
2095
4001
|
init_api();
|
|
2096
4002
|
init_config();
|
|
2097
4003
|
init_prompt();
|
|
@@ -2410,7 +4316,14 @@ async function update(opts) {
|
|
|
2410
4316
|
else if (install.kind === "npx") note(`You run Keybox through npx. Use npx @keyboxed/cli@${v} \u2026 from now on.`);
|
|
2411
4317
|
else if (install.kind === "unknown") note(`Installed somewhere unusual (${install.path}). Install ${v} the way you installed this one.`);
|
|
2412
4318
|
else if (opts.yes || await confirm(`Install @keyboxed/cli ${v}?`, true)) {
|
|
2413
|
-
|
|
4319
|
+
const args = ["install", "-g", "--prefer-online", `@keyboxed/cli@${v}`];
|
|
4320
|
+
let code = await run2("npm", args);
|
|
4321
|
+
if (code !== 0) {
|
|
4322
|
+
note("Retrying in 20 seconds in case the release has not reached every npm mirror yet\u2026");
|
|
4323
|
+
await new Promise((r) => setTimeout(r, 2e4));
|
|
4324
|
+
code = await run2("npm", args);
|
|
4325
|
+
}
|
|
4326
|
+
if (code !== 0) throw new UserError("npm install failed. You may need to fix npm permissions, or use npx.");
|
|
2414
4327
|
cliUpdated = true;
|
|
2415
4328
|
}
|
|
2416
4329
|
} else if (v) ok(`${"CLI".padEnd(16)}${c.dim("up to date")}`);
|
|
@@ -2435,7 +4348,7 @@ async function updateWorker(opts) {
|
|
|
2435
4348
|
const { deploy: deploy2 } = await Promise.resolve().then(() => (init_deploy(), deploy_exports));
|
|
2436
4349
|
const { checks: checks2, printChecks: printChecks2, resolveAccount: resolveAccount2 } = await Promise.resolve().then(() => (init_verify(), verify_exports));
|
|
2437
4350
|
await resolveAccount2(cfg);
|
|
2438
|
-
const list2 = await task("Worker", () => checks2(cfg), () => `v${deployedVersion} deployed, this CLI ships v${
|
|
4351
|
+
const list2 = await task("Worker", () => checks2(cfg), () => `v${deployedVersion} deployed, this CLI ships v${shippedWorkerVersion()}`);
|
|
2439
4352
|
const code = list2.find((x) => x.label === "Code");
|
|
2440
4353
|
if (code?.ok === true) {
|
|
2441
4354
|
if (!list2.every((x) => x.ok === true)) printChecks2(list2);
|
|
@@ -2456,6 +4369,7 @@ var HELP_BODY = `Setup
|
|
|
2456
4369
|
keybox deploy [--yes] Replace the deployed Worker with this CLI's version
|
|
2457
4370
|
keybox status
|
|
2458
4371
|
keybox ui [--print] Open the web dashboard (one-time login link)
|
|
4372
|
+
keybox pair Pair the Keybox phone app (one-time QR code)
|
|
2459
4373
|
keybox tui [--basic] Live console (uses keybox-tui, the Rust console, when installed)
|
|
2460
4374
|
|
|
2461
4375
|
Moving keys in (values are never printed, logged or put on a command line)
|
|
@@ -2570,6 +4484,8 @@ async function main(argv) {
|
|
|
2570
4484
|
return status();
|
|
2571
4485
|
case "ui":
|
|
2572
4486
|
return ui({ print: o.print });
|
|
4487
|
+
case "pair":
|
|
4488
|
+
return pair();
|
|
2573
4489
|
case "tui":
|
|
2574
4490
|
return tui({ basic: o.basic });
|
|
2575
4491
|
case "migrate":
|