better-auth 1.7.0-beta.2 → 1.7.0-beta.4
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/README.md +14 -15
- package/dist/_virtual/_rolldown/runtime.mjs +10 -1
- package/dist/api/index.d.mts +18 -48
- package/dist/api/routes/account.d.mts +4 -23
- package/dist/api/routes/account.mjs +102 -75
- package/dist/api/routes/callback.mjs +42 -20
- package/dist/api/routes/email-verification.d.mts +1 -0
- package/dist/api/routes/email-verification.mjs +6 -5
- package/dist/api/routes/error.mjs +1 -1
- package/dist/api/routes/password.mjs +1 -1
- package/dist/api/routes/session.mjs +15 -10
- package/dist/api/routes/sign-in.d.mts +3 -1
- package/dist/api/routes/sign-in.mjs +13 -15
- package/dist/api/routes/sign-up.d.mts +1 -0
- package/dist/api/routes/sign-up.mjs +10 -8
- package/dist/api/routes/update-user.mjs +8 -8
- package/dist/api/to-auth-endpoints.mjs +7 -1
- package/dist/auth/base.mjs +30 -27
- package/dist/client/config.mjs +8 -1
- package/dist/client/fetch-plugins.mjs +2 -1
- package/dist/client/index.d.mts +2 -2
- package/dist/client/lynx/index.d.mts +13 -0
- package/dist/client/lynx/index.mjs +2 -1
- package/dist/client/parser.mjs +0 -1
- package/dist/client/plugins/index.d.mts +4 -17
- package/dist/client/plugins/index.mjs +1 -4
- package/dist/client/proxy.mjs +2 -1
- package/dist/client/react/index.d.mts +13 -0
- package/dist/client/react/index.mjs +2 -1
- package/dist/client/session-atom.mjs +12 -1
- package/dist/client/solid/index.d.mts +13 -0
- package/dist/client/solid/index.mjs +3 -2
- package/dist/client/svelte/index.d.mts +13 -0
- package/dist/client/svelte/index.mjs +2 -1
- package/dist/client/vanilla.d.mts +13 -0
- package/dist/client/vanilla.mjs +2 -1
- package/dist/client/vue/index.d.mts +13 -0
- package/dist/client/vue/index.mjs +2 -1
- package/dist/context/create-context.mjs +10 -14
- package/dist/context/helpers.mjs +3 -2
- package/dist/cookies/cookie-utils.d.mts +33 -1
- package/dist/cookies/cookie-utils.mjs +95 -14
- package/dist/cookies/index.d.mts +2 -3
- package/dist/cookies/index.mjs +39 -11
- package/dist/cookies/session-store.mjs +4 -23
- package/dist/db/get-migration.mjs +4 -4
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +3 -2
- package/dist/db/internal-adapter.mjs +129 -27
- package/dist/db/schema.d.mts +14 -1
- package/dist/db/schema.mjs +26 -1
- package/dist/db/with-hooks.d.mts +1 -0
- package/dist/db/with-hooks.mjs +58 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/integrations/cookie-plugin-guard.mjs +18 -0
- package/dist/integrations/next-js.mjs +6 -0
- package/dist/integrations/svelte-kit.mjs +6 -0
- package/dist/integrations/tanstack-start-solid.mjs +6 -0
- package/dist/integrations/tanstack-start.mjs +6 -0
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/index.mjs +32 -0
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/linux.mjs +55 -0
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/macos.mjs +26 -0
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/termux.mjs +39 -0
- package/dist/node_modules/.pnpm/clipboardy@4.0.0/node_modules/clipboardy/lib/windows.mjs +19 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/chunks/prompt.mjs +845 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs +386 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs +320 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +62 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +190 -0
- package/dist/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/utils.mjs +2 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.mjs +29 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.mjs +42 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.mjs +67 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.mjs +23 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.mjs +22 -0
- package/dist/node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.mjs +36 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/adapters/node.d.mts +292 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/adapters/node.mjs +127 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/index.d.mts +145 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.BQXMA5bH.d.mts +298 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.By9qWDAI.mjs +9 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.CipVM6lf.mjs +3549 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.D9ehKjSh.mjs +66 -0
- package/dist/node_modules/.pnpm/crossws@0.3.5/node_modules/crossws/dist/shared/crossws.DfCzGthR.mjs +227 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/index.mjs +224 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/command.mjs +52 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/error.mjs +54 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/kill.mjs +62 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/pipe.mjs +26 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/promise.mjs +32 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/stdio.mjs +19 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/stream.mjs +98 -0
- package/dist/node_modules/.pnpm/execa@8.0.1/node_modules/execa/lib/verbose.mjs +15 -0
- package/dist/node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.d.mts +15 -0
- package/dist/node_modules/.pnpm/get-port-please@3.2.0/node_modules/get-port-please/dist/index.mjs +220 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/array-buffer.mjs +54 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/array.mjs +2 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/buffer.mjs +14 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/contents.mjs +76 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/index.mjs +6 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/string.mjs +35 -0
- package/dist/node_modules/.pnpm/get-stream@8.0.1/node_modules/get-stream/source/utils.mjs +10 -0
- package/dist/node_modules/.pnpm/http-shutdown@1.2.2/node_modules/http-shutdown/index.mjs +76 -0
- package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/core.mjs +274 -0
- package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/main.mjs +44 -0
- package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/realtime.mjs +15 -0
- package/dist/node_modules/.pnpm/human-signals@5.0.0/node_modules/human-signals/build/src/signals.mjs +23 -0
- package/dist/node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.mjs +24 -0
- package/dist/node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.mjs +18 -0
- package/dist/node_modules/.pnpm/is-stream@3.0.0/node_modules/is-stream/index.mjs +9 -0
- package/dist/node_modules/.pnpm/is-wsl@3.1.1/node_modules/is-wsl/index.mjs +20 -0
- package/dist/node_modules/.pnpm/is64bit@2.0.0/node_modules/is64bit/index.mjs +13 -0
- package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.mjs +47 -0
- package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.mjs +33 -0
- package/dist/node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.mjs +33 -0
- package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/chunks/xdg-open.mjs +1070 -0
- package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/index.mjs +619 -0
- package/dist/node_modules/.pnpm/listhen@1.9.0/node_modules/listhen/dist/shared/listhen.1c46e31d.d.mts +83 -0
- package/dist/node_modules/.pnpm/merge-stream@2.0.0/node_modules/merge-stream/index.mjs +38 -0
- package/dist/node_modules/.pnpm/mimic-fn@4.0.0/node_modules/mimic-fn/index.mjs +38 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/aes.mjs +597 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/aesCipherSuites.mjs +195 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/asn1-validator.mjs +76 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/asn1.mjs +967 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/baseN.mjs +137 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/cipher.mjs +186 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/cipherModes.mjs +597 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/des.mjs +1187 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/ed25519.mjs +1029 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/forge.mjs +15 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/hmac.mjs +107 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/index.mjs +66 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/jsbn.mjs +1334 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/kem.mjs +146 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/log.mjs +241 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md.all.mjs +24 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md.mjs +18 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/md5.mjs +324 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/mgf.mjs +20 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/mgf1.mjs +44 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/oids.mjs +154 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pbe.mjs +815 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pbkdf2.mjs +125 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pem.mjs +175 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs1.mjs +200 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs12.mjs +724 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7.mjs +642 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pkcs7asn1.mjs +405 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pki.mjs +101 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/prime.mjs +193 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/prng.mjs +290 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/pss.mjs +141 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/random.mjs +141 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/rc2.mjs +538 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/rsa.mjs +1309 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha1.mjs +230 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha256.mjs +267 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/sha512.mjs +413 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/ssh.mjs +194 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/tls.mjs +3655 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/util.mjs +2117 -0
- package/dist/node_modules/.pnpm/node-forge@1.4.0/node_modules/node-forge/lib/x509.mjs +2168 -0
- package/dist/node_modules/.pnpm/npm-run-path@5.3.0/node_modules/npm-run-path/index.mjs +34 -0
- package/dist/node_modules/.pnpm/onetime@6.0.0/node_modules/onetime/index.mjs +26 -0
- package/dist/node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.mjs +14 -0
- package/dist/node_modules/.pnpm/path-key@4.0.0/node_modules/path-key/index.mjs +8 -0
- package/dist/node_modules/.pnpm/pathe@1.1.2/node_modules/pathe/dist/shared/pathe.ff20891b.mjs +176 -0
- package/dist/node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.mjs +17 -0
- package/dist/node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.mjs +8 -0
- package/dist/node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.mjs +169 -0
- package/dist/node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.mjs +33 -0
- package/dist/node_modules/.pnpm/std-env@3.10.0/node_modules/std-env/dist/index.mjs +171 -0
- package/dist/node_modules/.pnpm/strip-final-newline@3.0.0/node_modules/strip-final-newline/index.mjs +10 -0
- package/dist/node_modules/.pnpm/system-architecture@0.1.0/node_modules/system-architecture/index.mjs +16 -0
- package/dist/node_modules/.pnpm/uncrypto@0.1.3/node_modules/uncrypto/dist/crypto.node.mjs +7 -0
- package/dist/node_modules/.pnpm/untun@0.1.3/node_modules/untun/dist/chunks/index.mjs +154 -0
- package/dist/node_modules/.pnpm/untun@0.1.3/node_modules/untun/dist/index.mjs +34 -0
- package/dist/node_modules/.pnpm/uqr@0.1.2/node_modules/uqr/dist/index.mjs +896 -0
- package/dist/node_modules/.pnpm/which@2.0.2/node_modules/which/which.mjs +76 -0
- package/dist/oauth2/errors.mjs +27 -0
- package/dist/oauth2/index.d.mts +2 -2
- package/dist/oauth2/index.mjs +3 -3
- package/dist/oauth2/link-account.d.mts +27 -1
- package/dist/oauth2/link-account.mjs +30 -5
- package/dist/oauth2/state.mjs +8 -2
- package/dist/{package.mjs → packages/better-auth/package.mjs} +1 -1
- package/dist/plugins/access/access.d.mts +3 -15
- package/dist/plugins/access/access.mjs +11 -6
- package/dist/plugins/access/index.d.mts +2 -2
- package/dist/plugins/access/types.d.mts +11 -4
- package/dist/plugins/admin/access/statement.d.mts +29 -93
- package/dist/plugins/admin/admin.mjs +0 -4
- package/dist/plugins/admin/client.d.mts +6 -1
- package/dist/plugins/admin/client.mjs +5 -0
- package/dist/plugins/admin/routes.mjs +3 -2
- package/dist/plugins/anonymous/client.d.mts +1 -0
- package/dist/plugins/anonymous/error-codes.d.mts +1 -0
- package/dist/plugins/anonymous/error-codes.mjs +1 -0
- package/dist/plugins/anonymous/index.d.mts +1 -0
- package/dist/plugins/anonymous/index.mjs +16 -2
- package/dist/plugins/bearer/index.mjs +5 -12
- package/dist/plugins/captcha/index.mjs +14 -1
- package/dist/plugins/device-authorization/error-codes.mjs +1 -0
- package/dist/plugins/device-authorization/index.d.mts +1 -0
- package/dist/plugins/device-authorization/routes.mjs +34 -3
- package/dist/plugins/email-otp/routes.mjs +4 -4
- package/dist/plugins/generic-oauth/error-codes.mjs +0 -1
- package/dist/plugins/generic-oauth/index.d.mts +2 -4
- package/dist/plugins/generic-oauth/index.mjs +23 -17
- package/dist/plugins/generic-oauth/providers/auth0.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/gumroad.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/hubspot.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/keycloak.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/line.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/microsoft-entra-id.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/okta.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/patreon.mjs +1 -0
- package/dist/plugins/generic-oauth/providers/slack.mjs +1 -0
- package/dist/plugins/generic-oauth/types.d.mts +30 -8
- package/dist/plugins/index.d.mts +2 -2
- package/dist/plugins/jwt/utils.d.mts +1 -1
- package/dist/plugins/last-login-method/client.mjs +2 -2
- package/dist/plugins/magic-link/index.d.mts +8 -1
- package/dist/plugins/magic-link/index.mjs +4 -17
- package/dist/plugins/mcp/authorize.mjs +8 -2
- package/dist/plugins/mcp/index.mjs +75 -35
- package/dist/plugins/multi-session/index.mjs +2 -2
- package/dist/plugins/oauth-proxy/index.mjs +45 -32
- package/dist/plugins/oauth-proxy/utils.mjs +3 -10
- package/dist/plugins/oidc-provider/authorize.mjs +8 -2
- package/dist/plugins/oidc-provider/index.mjs +65 -38
- package/dist/plugins/one-tap/client.mjs +9 -2
- package/dist/plugins/one-tap/index.mjs +19 -36
- package/dist/plugins/open-api/generator.mjs +25 -5
- package/dist/plugins/organization/access/statement.d.mts +68 -201
- package/dist/plugins/organization/adapter.d.mts +1 -1
- package/dist/plugins/organization/adapter.mjs +65 -58
- package/dist/plugins/organization/client.d.mts +3 -1
- package/dist/plugins/organization/client.mjs +1 -1
- package/dist/plugins/organization/error-codes.d.mts +2 -0
- package/dist/plugins/organization/error-codes.mjs +3 -1
- package/dist/plugins/organization/routes/crud-access-control.d.mts +2 -2
- package/dist/plugins/organization/routes/crud-invites.d.mts +8 -1
- package/dist/plugins/organization/routes/crud-invites.mjs +8 -3
- package/dist/plugins/organization/routes/crud-org.d.mts +4 -4
- package/dist/plugins/organization/routes/crud-org.mjs +2 -2
- package/dist/plugins/organization/routes/crud-team.mjs +7 -2
- package/dist/plugins/organization/schema.d.mts +1 -1
- package/dist/plugins/organization/types.d.mts +15 -5
- package/dist/plugins/phone-number/routes.mjs +1 -1
- package/dist/plugins/siwe/client.d.mts +4 -0
- package/dist/plugins/siwe/client.mjs +5 -1
- package/dist/plugins/siwe/index.d.mts +13 -2
- package/dist/plugins/siwe/index.mjs +179 -165
- package/dist/plugins/two-factor/backup-codes/index.d.mts +4 -3
- package/dist/plugins/two-factor/client.mjs +2 -1
- package/dist/plugins/two-factor/index.mjs +3 -2
- package/dist/plugins/username/client.d.mts +1 -0
- package/dist/plugins/username/error-codes.d.mts +1 -0
- package/dist/plugins/username/error-codes.mjs +2 -1
- package/dist/plugins/username/index.d.mts +43 -2
- package/dist/plugins/username/index.mjs +73 -6
- package/dist/state.d.mts +2 -2
- package/dist/state.mjs +18 -4
- package/dist/test-utils/headers.mjs +2 -7
- package/dist/test-utils/http-test-instance.d.mts +397 -0
- package/dist/test-utils/http-test-instance.mjs +54 -0
- package/dist/test-utils/index.d.mts +2 -1
- package/dist/test-utils/index.mjs +2 -1
- package/dist/test-utils/test-instance.d.mts +4110 -224
- package/dist/test-utils/test-instance.mjs +11 -2
- package/dist/types/auth.d.mts +4 -0
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/url.d.mts +2 -1
- package/dist/utils/url.mjs +9 -3
- package/dist/version.mjs +1 -1
- package/package.json +14 -14
- package/dist/oauth2/error-codes.d.mts +0 -20
- package/dist/plugins/generic-oauth/client.d.mts +0 -32
- package/dist/plugins/generic-oauth/client.mjs +0 -19
- package/dist/plugins/generic-oauth/error-codes.d.mts +0 -10
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
//#region ../../node_modules/.pnpm/uqr@0.1.2/node_modules/uqr/dist/index.mjs
|
|
2
|
+
var QrCodeDataType = /* @__PURE__ */ ((QrCodeDataType2) => {
|
|
3
|
+
QrCodeDataType2[QrCodeDataType2["Border"] = -1] = "Border";
|
|
4
|
+
QrCodeDataType2[QrCodeDataType2["Data"] = 0] = "Data";
|
|
5
|
+
QrCodeDataType2[QrCodeDataType2["Function"] = 1] = "Function";
|
|
6
|
+
QrCodeDataType2[QrCodeDataType2["Position"] = 2] = "Position";
|
|
7
|
+
QrCodeDataType2[QrCodeDataType2["Timing"] = 3] = "Timing";
|
|
8
|
+
QrCodeDataType2[QrCodeDataType2["Alignment"] = 4] = "Alignment";
|
|
9
|
+
return QrCodeDataType2;
|
|
10
|
+
})(QrCodeDataType || {});
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value
|
|
17
|
+
}) : obj[key] = value;
|
|
18
|
+
var __publicField = (obj, key, value) => {
|
|
19
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
const LOW = [0, 1];
|
|
23
|
+
const MEDIUM = [1, 0];
|
|
24
|
+
const QUARTILE = [2, 3];
|
|
25
|
+
const HIGH = [3, 2];
|
|
26
|
+
const EccMap = {
|
|
27
|
+
L: LOW,
|
|
28
|
+
M: MEDIUM,
|
|
29
|
+
Q: QUARTILE,
|
|
30
|
+
H: HIGH
|
|
31
|
+
};
|
|
32
|
+
const NUMERIC_REGEX = /^[0-9]*$/;
|
|
33
|
+
const ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
|
|
34
|
+
const ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
|
35
|
+
const MIN_VERSION = 1;
|
|
36
|
+
const MAX_VERSION = 40;
|
|
37
|
+
const PENALTY_N1 = 3;
|
|
38
|
+
const PENALTY_N2 = 3;
|
|
39
|
+
const PENALTY_N3 = 40;
|
|
40
|
+
const PENALTY_N4 = 10;
|
|
41
|
+
const ECC_CODEWORDS_PER_BLOCK = [
|
|
42
|
+
[
|
|
43
|
+
-1,
|
|
44
|
+
7,
|
|
45
|
+
10,
|
|
46
|
+
15,
|
|
47
|
+
20,
|
|
48
|
+
26,
|
|
49
|
+
18,
|
|
50
|
+
20,
|
|
51
|
+
24,
|
|
52
|
+
30,
|
|
53
|
+
18,
|
|
54
|
+
20,
|
|
55
|
+
24,
|
|
56
|
+
26,
|
|
57
|
+
30,
|
|
58
|
+
22,
|
|
59
|
+
24,
|
|
60
|
+
28,
|
|
61
|
+
30,
|
|
62
|
+
28,
|
|
63
|
+
28,
|
|
64
|
+
28,
|
|
65
|
+
28,
|
|
66
|
+
30,
|
|
67
|
+
30,
|
|
68
|
+
26,
|
|
69
|
+
28,
|
|
70
|
+
30,
|
|
71
|
+
30,
|
|
72
|
+
30,
|
|
73
|
+
30,
|
|
74
|
+
30,
|
|
75
|
+
30,
|
|
76
|
+
30,
|
|
77
|
+
30,
|
|
78
|
+
30,
|
|
79
|
+
30,
|
|
80
|
+
30,
|
|
81
|
+
30,
|
|
82
|
+
30,
|
|
83
|
+
30
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
-1,
|
|
87
|
+
10,
|
|
88
|
+
16,
|
|
89
|
+
26,
|
|
90
|
+
18,
|
|
91
|
+
24,
|
|
92
|
+
16,
|
|
93
|
+
18,
|
|
94
|
+
22,
|
|
95
|
+
22,
|
|
96
|
+
26,
|
|
97
|
+
30,
|
|
98
|
+
22,
|
|
99
|
+
22,
|
|
100
|
+
24,
|
|
101
|
+
24,
|
|
102
|
+
28,
|
|
103
|
+
28,
|
|
104
|
+
26,
|
|
105
|
+
26,
|
|
106
|
+
26,
|
|
107
|
+
26,
|
|
108
|
+
28,
|
|
109
|
+
28,
|
|
110
|
+
28,
|
|
111
|
+
28,
|
|
112
|
+
28,
|
|
113
|
+
28,
|
|
114
|
+
28,
|
|
115
|
+
28,
|
|
116
|
+
28,
|
|
117
|
+
28,
|
|
118
|
+
28,
|
|
119
|
+
28,
|
|
120
|
+
28,
|
|
121
|
+
28,
|
|
122
|
+
28,
|
|
123
|
+
28,
|
|
124
|
+
28,
|
|
125
|
+
28,
|
|
126
|
+
28
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
-1,
|
|
130
|
+
13,
|
|
131
|
+
22,
|
|
132
|
+
18,
|
|
133
|
+
26,
|
|
134
|
+
18,
|
|
135
|
+
24,
|
|
136
|
+
18,
|
|
137
|
+
22,
|
|
138
|
+
20,
|
|
139
|
+
24,
|
|
140
|
+
28,
|
|
141
|
+
26,
|
|
142
|
+
24,
|
|
143
|
+
20,
|
|
144
|
+
30,
|
|
145
|
+
24,
|
|
146
|
+
28,
|
|
147
|
+
28,
|
|
148
|
+
26,
|
|
149
|
+
30,
|
|
150
|
+
28,
|
|
151
|
+
30,
|
|
152
|
+
30,
|
|
153
|
+
30,
|
|
154
|
+
30,
|
|
155
|
+
28,
|
|
156
|
+
30,
|
|
157
|
+
30,
|
|
158
|
+
30,
|
|
159
|
+
30,
|
|
160
|
+
30,
|
|
161
|
+
30,
|
|
162
|
+
30,
|
|
163
|
+
30,
|
|
164
|
+
30,
|
|
165
|
+
30,
|
|
166
|
+
30,
|
|
167
|
+
30,
|
|
168
|
+
30,
|
|
169
|
+
30
|
|
170
|
+
],
|
|
171
|
+
[
|
|
172
|
+
-1,
|
|
173
|
+
17,
|
|
174
|
+
28,
|
|
175
|
+
22,
|
|
176
|
+
16,
|
|
177
|
+
22,
|
|
178
|
+
28,
|
|
179
|
+
26,
|
|
180
|
+
26,
|
|
181
|
+
24,
|
|
182
|
+
28,
|
|
183
|
+
24,
|
|
184
|
+
28,
|
|
185
|
+
22,
|
|
186
|
+
24,
|
|
187
|
+
24,
|
|
188
|
+
30,
|
|
189
|
+
28,
|
|
190
|
+
28,
|
|
191
|
+
26,
|
|
192
|
+
28,
|
|
193
|
+
30,
|
|
194
|
+
24,
|
|
195
|
+
30,
|
|
196
|
+
30,
|
|
197
|
+
30,
|
|
198
|
+
30,
|
|
199
|
+
30,
|
|
200
|
+
30,
|
|
201
|
+
30,
|
|
202
|
+
30,
|
|
203
|
+
30,
|
|
204
|
+
30,
|
|
205
|
+
30,
|
|
206
|
+
30,
|
|
207
|
+
30,
|
|
208
|
+
30,
|
|
209
|
+
30,
|
|
210
|
+
30,
|
|
211
|
+
30,
|
|
212
|
+
30
|
|
213
|
+
]
|
|
214
|
+
];
|
|
215
|
+
const NUM_ERROR_CORRECTION_BLOCKS = [
|
|
216
|
+
[
|
|
217
|
+
-1,
|
|
218
|
+
1,
|
|
219
|
+
1,
|
|
220
|
+
1,
|
|
221
|
+
1,
|
|
222
|
+
1,
|
|
223
|
+
2,
|
|
224
|
+
2,
|
|
225
|
+
2,
|
|
226
|
+
2,
|
|
227
|
+
4,
|
|
228
|
+
4,
|
|
229
|
+
4,
|
|
230
|
+
4,
|
|
231
|
+
4,
|
|
232
|
+
6,
|
|
233
|
+
6,
|
|
234
|
+
6,
|
|
235
|
+
6,
|
|
236
|
+
7,
|
|
237
|
+
8,
|
|
238
|
+
8,
|
|
239
|
+
9,
|
|
240
|
+
9,
|
|
241
|
+
10,
|
|
242
|
+
12,
|
|
243
|
+
12,
|
|
244
|
+
12,
|
|
245
|
+
13,
|
|
246
|
+
14,
|
|
247
|
+
15,
|
|
248
|
+
16,
|
|
249
|
+
17,
|
|
250
|
+
18,
|
|
251
|
+
19,
|
|
252
|
+
19,
|
|
253
|
+
20,
|
|
254
|
+
21,
|
|
255
|
+
22,
|
|
256
|
+
24,
|
|
257
|
+
25
|
|
258
|
+
],
|
|
259
|
+
[
|
|
260
|
+
-1,
|
|
261
|
+
1,
|
|
262
|
+
1,
|
|
263
|
+
1,
|
|
264
|
+
2,
|
|
265
|
+
2,
|
|
266
|
+
4,
|
|
267
|
+
4,
|
|
268
|
+
4,
|
|
269
|
+
5,
|
|
270
|
+
5,
|
|
271
|
+
5,
|
|
272
|
+
8,
|
|
273
|
+
9,
|
|
274
|
+
9,
|
|
275
|
+
10,
|
|
276
|
+
10,
|
|
277
|
+
11,
|
|
278
|
+
13,
|
|
279
|
+
14,
|
|
280
|
+
16,
|
|
281
|
+
17,
|
|
282
|
+
17,
|
|
283
|
+
18,
|
|
284
|
+
20,
|
|
285
|
+
21,
|
|
286
|
+
23,
|
|
287
|
+
25,
|
|
288
|
+
26,
|
|
289
|
+
28,
|
|
290
|
+
29,
|
|
291
|
+
31,
|
|
292
|
+
33,
|
|
293
|
+
35,
|
|
294
|
+
37,
|
|
295
|
+
38,
|
|
296
|
+
40,
|
|
297
|
+
43,
|
|
298
|
+
45,
|
|
299
|
+
47,
|
|
300
|
+
49
|
|
301
|
+
],
|
|
302
|
+
[
|
|
303
|
+
-1,
|
|
304
|
+
1,
|
|
305
|
+
1,
|
|
306
|
+
2,
|
|
307
|
+
2,
|
|
308
|
+
4,
|
|
309
|
+
4,
|
|
310
|
+
6,
|
|
311
|
+
6,
|
|
312
|
+
8,
|
|
313
|
+
8,
|
|
314
|
+
8,
|
|
315
|
+
10,
|
|
316
|
+
12,
|
|
317
|
+
16,
|
|
318
|
+
12,
|
|
319
|
+
17,
|
|
320
|
+
16,
|
|
321
|
+
18,
|
|
322
|
+
21,
|
|
323
|
+
20,
|
|
324
|
+
23,
|
|
325
|
+
23,
|
|
326
|
+
25,
|
|
327
|
+
27,
|
|
328
|
+
29,
|
|
329
|
+
34,
|
|
330
|
+
34,
|
|
331
|
+
35,
|
|
332
|
+
38,
|
|
333
|
+
40,
|
|
334
|
+
43,
|
|
335
|
+
45,
|
|
336
|
+
48,
|
|
337
|
+
51,
|
|
338
|
+
53,
|
|
339
|
+
56,
|
|
340
|
+
59,
|
|
341
|
+
62,
|
|
342
|
+
65,
|
|
343
|
+
68
|
|
344
|
+
],
|
|
345
|
+
[
|
|
346
|
+
-1,
|
|
347
|
+
1,
|
|
348
|
+
1,
|
|
349
|
+
2,
|
|
350
|
+
4,
|
|
351
|
+
4,
|
|
352
|
+
4,
|
|
353
|
+
5,
|
|
354
|
+
6,
|
|
355
|
+
8,
|
|
356
|
+
8,
|
|
357
|
+
11,
|
|
358
|
+
11,
|
|
359
|
+
16,
|
|
360
|
+
16,
|
|
361
|
+
18,
|
|
362
|
+
16,
|
|
363
|
+
19,
|
|
364
|
+
21,
|
|
365
|
+
25,
|
|
366
|
+
25,
|
|
367
|
+
25,
|
|
368
|
+
34,
|
|
369
|
+
30,
|
|
370
|
+
32,
|
|
371
|
+
35,
|
|
372
|
+
37,
|
|
373
|
+
40,
|
|
374
|
+
42,
|
|
375
|
+
45,
|
|
376
|
+
48,
|
|
377
|
+
51,
|
|
378
|
+
54,
|
|
379
|
+
57,
|
|
380
|
+
60,
|
|
381
|
+
63,
|
|
382
|
+
66,
|
|
383
|
+
70,
|
|
384
|
+
74,
|
|
385
|
+
77,
|
|
386
|
+
81
|
|
387
|
+
]
|
|
388
|
+
];
|
|
389
|
+
var QrCode = class {
|
|
390
|
+
constructor(version, ecc, dataCodewords, msk) {
|
|
391
|
+
this.version = version;
|
|
392
|
+
this.ecc = ecc;
|
|
393
|
+
__publicField(this, "size");
|
|
394
|
+
__publicField(this, "mask");
|
|
395
|
+
__publicField(this, "modules", []);
|
|
396
|
+
__publicField(this, "types", []);
|
|
397
|
+
if (version < MIN_VERSION || version > MAX_VERSION) throw new RangeError("Version value out of range");
|
|
398
|
+
if (msk < -1 || msk > 7) throw new RangeError("Mask value out of range");
|
|
399
|
+
this.size = version * 4 + 17;
|
|
400
|
+
const row = Array.from({ length: this.size }, () => false);
|
|
401
|
+
for (let i = 0; i < this.size; i++) {
|
|
402
|
+
this.modules.push(row.slice());
|
|
403
|
+
this.types.push(row.map(() => 0));
|
|
404
|
+
}
|
|
405
|
+
this.drawFunctionPatterns();
|
|
406
|
+
const allCodewords = this.addEccAndInterleave(dataCodewords);
|
|
407
|
+
this.drawCodewords(allCodewords);
|
|
408
|
+
if (msk === -1) {
|
|
409
|
+
let minPenalty = 1e9;
|
|
410
|
+
for (let i = 0; i < 8; i++) {
|
|
411
|
+
this.applyMask(i);
|
|
412
|
+
this.drawFormatBits(i);
|
|
413
|
+
const penalty = this.getPenaltyScore();
|
|
414
|
+
if (penalty < minPenalty) {
|
|
415
|
+
msk = i;
|
|
416
|
+
minPenalty = penalty;
|
|
417
|
+
}
|
|
418
|
+
this.applyMask(i);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
this.mask = msk;
|
|
422
|
+
this.applyMask(msk);
|
|
423
|
+
this.drawFormatBits(msk);
|
|
424
|
+
}
|
|
425
|
+
getModule(x, y) {
|
|
426
|
+
return x >= 0 && x < this.size && y >= 0 && y < this.size && this.modules[y][x];
|
|
427
|
+
}
|
|
428
|
+
drawFunctionPatterns() {
|
|
429
|
+
for (let i = 0; i < this.size; i++) {
|
|
430
|
+
this.setFunctionModule(6, i, i % 2 === 0, QrCodeDataType.Timing);
|
|
431
|
+
this.setFunctionModule(i, 6, i % 2 === 0, QrCodeDataType.Timing);
|
|
432
|
+
}
|
|
433
|
+
this.drawFinderPattern(3, 3);
|
|
434
|
+
this.drawFinderPattern(this.size - 4, 3);
|
|
435
|
+
this.drawFinderPattern(3, this.size - 4);
|
|
436
|
+
const alignPatPos = this.getAlignmentPatternPositions();
|
|
437
|
+
const numAlign = alignPatPos.length;
|
|
438
|
+
for (let i = 0; i < numAlign; i++) for (let j = 0; j < numAlign; j++) if (!(i === 0 && j === 0 || i === 0 && j === numAlign - 1 || i === numAlign - 1 && j === 0)) this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
|
|
439
|
+
this.drawFormatBits(0);
|
|
440
|
+
this.drawVersion();
|
|
441
|
+
}
|
|
442
|
+
drawFormatBits(mask) {
|
|
443
|
+
const data = this.ecc[1] << 3 | mask;
|
|
444
|
+
let rem = data;
|
|
445
|
+
for (let i = 0; i < 10; i++) rem = rem << 1 ^ (rem >>> 9) * 1335;
|
|
446
|
+
const bits = (data << 10 | rem) ^ 21522;
|
|
447
|
+
for (let i = 0; i <= 5; i++) this.setFunctionModule(8, i, getBit(bits, i));
|
|
448
|
+
this.setFunctionModule(8, 7, getBit(bits, 6));
|
|
449
|
+
this.setFunctionModule(8, 8, getBit(bits, 7));
|
|
450
|
+
this.setFunctionModule(7, 8, getBit(bits, 8));
|
|
451
|
+
for (let i = 9; i < 15; i++) this.setFunctionModule(14 - i, 8, getBit(bits, i));
|
|
452
|
+
for (let i = 0; i < 8; i++) this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
|
|
453
|
+
for (let i = 8; i < 15; i++) this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
|
|
454
|
+
this.setFunctionModule(8, this.size - 8, true);
|
|
455
|
+
}
|
|
456
|
+
drawVersion() {
|
|
457
|
+
if (this.version < 7) return;
|
|
458
|
+
let rem = this.version;
|
|
459
|
+
for (let i = 0; i < 12; i++) rem = rem << 1 ^ (rem >>> 11) * 7973;
|
|
460
|
+
const bits = this.version << 12 | rem;
|
|
461
|
+
for (let i = 0; i < 18; i++) {
|
|
462
|
+
const color = getBit(bits, i);
|
|
463
|
+
const a = this.size - 11 + i % 3;
|
|
464
|
+
const b = Math.floor(i / 3);
|
|
465
|
+
this.setFunctionModule(a, b, color);
|
|
466
|
+
this.setFunctionModule(b, a, color);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
drawFinderPattern(x, y) {
|
|
470
|
+
for (let dy = -4; dy <= 4; dy++) for (let dx = -4; dx <= 4; dx++) {
|
|
471
|
+
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
|
472
|
+
const xx = x + dx;
|
|
473
|
+
const yy = y + dy;
|
|
474
|
+
if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size) this.setFunctionModule(xx, yy, dist !== 2 && dist !== 4, QrCodeDataType.Position);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
drawAlignmentPattern(x, y) {
|
|
478
|
+
for (let dy = -2; dy <= 2; dy++) for (let dx = -2; dx <= 2; dx++) this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1, QrCodeDataType.Alignment);
|
|
479
|
+
}
|
|
480
|
+
setFunctionModule(x, y, isDark, type = QrCodeDataType.Function) {
|
|
481
|
+
this.modules[y][x] = isDark;
|
|
482
|
+
this.types[y][x] = type;
|
|
483
|
+
}
|
|
484
|
+
addEccAndInterleave(data) {
|
|
485
|
+
const ver = this.version;
|
|
486
|
+
const ecl = this.ecc;
|
|
487
|
+
if (data.length !== getNumDataCodewords(ver, ecl)) throw new RangeError("Invalid argument");
|
|
488
|
+
const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
|
|
489
|
+
const blockEccLen = ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver];
|
|
490
|
+
const rawCodewords = Math.floor(getNumRawDataModules(ver) / 8);
|
|
491
|
+
const numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
|
492
|
+
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
|
493
|
+
const blocks = [];
|
|
494
|
+
const rsDiv = reedSolomonComputeDivisor(blockEccLen);
|
|
495
|
+
for (let i = 0, k = 0; i < numBlocks; i++) {
|
|
496
|
+
const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
|
|
497
|
+
k += dat.length;
|
|
498
|
+
const ecc = reedSolomonComputeRemainder(dat, rsDiv);
|
|
499
|
+
if (i < numShortBlocks) dat.push(0);
|
|
500
|
+
blocks.push(dat.concat(ecc));
|
|
501
|
+
}
|
|
502
|
+
const result = [];
|
|
503
|
+
for (let i = 0; i < blocks[0].length; i++) blocks.forEach((block, j) => {
|
|
504
|
+
if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks) result.push(block[i]);
|
|
505
|
+
});
|
|
506
|
+
return result;
|
|
507
|
+
}
|
|
508
|
+
drawCodewords(data) {
|
|
509
|
+
if (data.length !== Math.floor(getNumRawDataModules(this.version) / 8)) throw new RangeError("Invalid argument");
|
|
510
|
+
let i = 0;
|
|
511
|
+
for (let right = this.size - 1; right >= 1; right -= 2) {
|
|
512
|
+
if (right === 6) right = 5;
|
|
513
|
+
for (let vert = 0; vert < this.size; vert++) for (let j = 0; j < 2; j++) {
|
|
514
|
+
const x = right - j;
|
|
515
|
+
const y = (right + 1 & 2) === 0 ? this.size - 1 - vert : vert;
|
|
516
|
+
if (!this.types[y][x] && i < data.length * 8) {
|
|
517
|
+
this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
|
|
518
|
+
i++;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
applyMask(mask) {
|
|
524
|
+
if (mask < 0 || mask > 7) throw new RangeError("Mask value out of range");
|
|
525
|
+
for (let y = 0; y < this.size; y++) for (let x = 0; x < this.size; x++) {
|
|
526
|
+
let invert;
|
|
527
|
+
switch (mask) {
|
|
528
|
+
case 0:
|
|
529
|
+
invert = (x + y) % 2 === 0;
|
|
530
|
+
break;
|
|
531
|
+
case 1:
|
|
532
|
+
invert = y % 2 === 0;
|
|
533
|
+
break;
|
|
534
|
+
case 2:
|
|
535
|
+
invert = x % 3 === 0;
|
|
536
|
+
break;
|
|
537
|
+
case 3:
|
|
538
|
+
invert = (x + y) % 3 === 0;
|
|
539
|
+
break;
|
|
540
|
+
case 4:
|
|
541
|
+
invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
|
|
542
|
+
break;
|
|
543
|
+
case 5:
|
|
544
|
+
invert = x * y % 2 + x * y % 3 === 0;
|
|
545
|
+
break;
|
|
546
|
+
case 6:
|
|
547
|
+
invert = (x * y % 2 + x * y % 3) % 2 === 0;
|
|
548
|
+
break;
|
|
549
|
+
case 7:
|
|
550
|
+
invert = ((x + y) % 2 + x * y % 3) % 2 === 0;
|
|
551
|
+
break;
|
|
552
|
+
default: throw new Error("Unreachable");
|
|
553
|
+
}
|
|
554
|
+
if (!this.types[y][x] && invert) this.modules[y][x] = !this.modules[y][x];
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
getPenaltyScore() {
|
|
558
|
+
let result = 0;
|
|
559
|
+
for (let y = 0; y < this.size; y++) {
|
|
560
|
+
let runColor = false;
|
|
561
|
+
let runX = 0;
|
|
562
|
+
const runHistory = [
|
|
563
|
+
0,
|
|
564
|
+
0,
|
|
565
|
+
0,
|
|
566
|
+
0,
|
|
567
|
+
0,
|
|
568
|
+
0,
|
|
569
|
+
0
|
|
570
|
+
];
|
|
571
|
+
for (let x = 0; x < this.size; x++) if (this.modules[y][x] === runColor) {
|
|
572
|
+
runX++;
|
|
573
|
+
if (runX === 5) result += PENALTY_N1;
|
|
574
|
+
else if (runX > 5) result++;
|
|
575
|
+
} else {
|
|
576
|
+
this.finderPenaltyAddHistory(runX, runHistory);
|
|
577
|
+
if (!runColor) result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
|
|
578
|
+
runColor = this.modules[y][x];
|
|
579
|
+
runX = 1;
|
|
580
|
+
}
|
|
581
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * PENALTY_N3;
|
|
582
|
+
}
|
|
583
|
+
for (let x = 0; x < this.size; x++) {
|
|
584
|
+
let runColor = false;
|
|
585
|
+
let runY = 0;
|
|
586
|
+
const runHistory = [
|
|
587
|
+
0,
|
|
588
|
+
0,
|
|
589
|
+
0,
|
|
590
|
+
0,
|
|
591
|
+
0,
|
|
592
|
+
0,
|
|
593
|
+
0
|
|
594
|
+
];
|
|
595
|
+
for (let y = 0; y < this.size; y++) if (this.modules[y][x] === runColor) {
|
|
596
|
+
runY++;
|
|
597
|
+
if (runY === 5) result += PENALTY_N1;
|
|
598
|
+
else if (runY > 5) result++;
|
|
599
|
+
} else {
|
|
600
|
+
this.finderPenaltyAddHistory(runY, runHistory);
|
|
601
|
+
if (!runColor) result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
|
|
602
|
+
runColor = this.modules[y][x];
|
|
603
|
+
runY = 1;
|
|
604
|
+
}
|
|
605
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * PENALTY_N3;
|
|
606
|
+
}
|
|
607
|
+
for (let y = 0; y < this.size - 1; y++) for (let x = 0; x < this.size - 1; x++) {
|
|
608
|
+
const color = this.modules[y][x];
|
|
609
|
+
if (color === this.modules[y][x + 1] && color === this.modules[y + 1][x] && color === this.modules[y + 1][x + 1]) result += PENALTY_N2;
|
|
610
|
+
}
|
|
611
|
+
let dark = 0;
|
|
612
|
+
for (const row of this.modules) dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
|
|
613
|
+
const total = this.size * this.size;
|
|
614
|
+
const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
|
|
615
|
+
result += k * PENALTY_N4;
|
|
616
|
+
return result;
|
|
617
|
+
}
|
|
618
|
+
getAlignmentPatternPositions() {
|
|
619
|
+
if (this.version === 1) return [];
|
|
620
|
+
else {
|
|
621
|
+
const numAlign = Math.floor(this.version / 7) + 2;
|
|
622
|
+
const step = this.version === 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
|
|
623
|
+
const result = [6];
|
|
624
|
+
for (let pos = this.size - 7; result.length < numAlign; pos -= step) result.splice(1, 0, pos);
|
|
625
|
+
return result;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
finderPenaltyCountPatterns(runHistory) {
|
|
629
|
+
const n = runHistory[1];
|
|
630
|
+
const core = n > 0 && runHistory[2] === n && runHistory[3] === n * 3 && runHistory[4] === n && runHistory[5] === n;
|
|
631
|
+
return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
|
|
632
|
+
}
|
|
633
|
+
finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
|
|
634
|
+
if (currentRunColor) {
|
|
635
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
636
|
+
currentRunLength = 0;
|
|
637
|
+
}
|
|
638
|
+
currentRunLength += this.size;
|
|
639
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
640
|
+
return this.finderPenaltyCountPatterns(runHistory);
|
|
641
|
+
}
|
|
642
|
+
finderPenaltyAddHistory(currentRunLength, runHistory) {
|
|
643
|
+
if (runHistory[0] === 0) currentRunLength += this.size;
|
|
644
|
+
runHistory.pop();
|
|
645
|
+
runHistory.unshift(currentRunLength);
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
function appendBits(val, len, bb) {
|
|
649
|
+
if (len < 0 || len > 31 || val >>> len !== 0) throw new RangeError("Value out of range");
|
|
650
|
+
for (let i = len - 1; i >= 0; i--) bb.push(val >>> i & 1);
|
|
651
|
+
}
|
|
652
|
+
function getBit(x, i) {
|
|
653
|
+
return (x >>> i & 1) !== 0;
|
|
654
|
+
}
|
|
655
|
+
var QrSegment = class {
|
|
656
|
+
constructor(mode, numChars, bitData) {
|
|
657
|
+
this.mode = mode;
|
|
658
|
+
this.numChars = numChars;
|
|
659
|
+
this.bitData = bitData;
|
|
660
|
+
if (numChars < 0) throw new RangeError("Invalid argument");
|
|
661
|
+
this.bitData = bitData.slice();
|
|
662
|
+
}
|
|
663
|
+
getData() {
|
|
664
|
+
return this.bitData.slice();
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
const MODE_NUMERIC = [
|
|
668
|
+
1,
|
|
669
|
+
10,
|
|
670
|
+
12,
|
|
671
|
+
14
|
|
672
|
+
];
|
|
673
|
+
const MODE_ALPHANUMERIC = [
|
|
674
|
+
2,
|
|
675
|
+
9,
|
|
676
|
+
11,
|
|
677
|
+
13
|
|
678
|
+
];
|
|
679
|
+
const MODE_BYTE = [
|
|
680
|
+
4,
|
|
681
|
+
8,
|
|
682
|
+
16,
|
|
683
|
+
16
|
|
684
|
+
];
|
|
685
|
+
function numCharCountBits(mode, ver) {
|
|
686
|
+
return mode[Math.floor((ver + 7) / 17) + 1];
|
|
687
|
+
}
|
|
688
|
+
function makeBytes(data) {
|
|
689
|
+
const bb = [];
|
|
690
|
+
for (const b of data) appendBits(b, 8, bb);
|
|
691
|
+
return new QrSegment(MODE_BYTE, data.length, bb);
|
|
692
|
+
}
|
|
693
|
+
function makeNumeric(digits) {
|
|
694
|
+
if (!isNumeric(digits)) throw new RangeError("String contains non-numeric characters");
|
|
695
|
+
const bb = [];
|
|
696
|
+
for (let i = 0; i < digits.length;) {
|
|
697
|
+
const n = Math.min(digits.length - i, 3);
|
|
698
|
+
appendBits(Number.parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
|
|
699
|
+
i += n;
|
|
700
|
+
}
|
|
701
|
+
return new QrSegment(MODE_NUMERIC, digits.length, bb);
|
|
702
|
+
}
|
|
703
|
+
function makeAlphanumeric(text) {
|
|
704
|
+
if (!isAlphanumeric(text)) throw new RangeError("String contains unencodable characters in alphanumeric mode");
|
|
705
|
+
const bb = [];
|
|
706
|
+
let i;
|
|
707
|
+
for (i = 0; i + 2 <= text.length; i += 2) {
|
|
708
|
+
let temp = ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
|
|
709
|
+
temp += ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
|
710
|
+
appendBits(temp, 11, bb);
|
|
711
|
+
}
|
|
712
|
+
if (i < text.length) appendBits(ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
|
|
713
|
+
return new QrSegment(MODE_ALPHANUMERIC, text.length, bb);
|
|
714
|
+
}
|
|
715
|
+
function makeSegments(text) {
|
|
716
|
+
if (text === "") return [];
|
|
717
|
+
else if (isNumeric(text)) return [makeNumeric(text)];
|
|
718
|
+
else if (isAlphanumeric(text)) return [makeAlphanumeric(text)];
|
|
719
|
+
else return [makeBytes(toUtf8ByteArray(text))];
|
|
720
|
+
}
|
|
721
|
+
function isNumeric(text) {
|
|
722
|
+
return NUMERIC_REGEX.test(text);
|
|
723
|
+
}
|
|
724
|
+
function isAlphanumeric(text) {
|
|
725
|
+
return ALPHANUMERIC_REGEX.test(text);
|
|
726
|
+
}
|
|
727
|
+
function getTotalBits(segs, version) {
|
|
728
|
+
let result = 0;
|
|
729
|
+
for (const seg of segs) {
|
|
730
|
+
const ccbits = numCharCountBits(seg.mode, version);
|
|
731
|
+
if (seg.numChars >= 1 << ccbits) return Number.POSITIVE_INFINITY;
|
|
732
|
+
result += 4 + ccbits + seg.bitData.length;
|
|
733
|
+
}
|
|
734
|
+
return result;
|
|
735
|
+
}
|
|
736
|
+
function toUtf8ByteArray(str) {
|
|
737
|
+
str = encodeURI(str);
|
|
738
|
+
const result = [];
|
|
739
|
+
for (let i = 0; i < str.length; i++) if (str.charAt(i) !== "%") result.push(str.charCodeAt(i));
|
|
740
|
+
else {
|
|
741
|
+
result.push(Number.parseInt(str.substring(i + 1, i + 3), 16));
|
|
742
|
+
i += 2;
|
|
743
|
+
}
|
|
744
|
+
return result;
|
|
745
|
+
}
|
|
746
|
+
function getNumRawDataModules(ver) {
|
|
747
|
+
if (ver < MIN_VERSION || ver > MAX_VERSION) throw new RangeError("Version number out of range");
|
|
748
|
+
let result = (16 * ver + 128) * ver + 64;
|
|
749
|
+
if (ver >= 2) {
|
|
750
|
+
const numAlign = Math.floor(ver / 7) + 2;
|
|
751
|
+
result -= (25 * numAlign - 10) * numAlign - 55;
|
|
752
|
+
if (ver >= 7) result -= 36;
|
|
753
|
+
}
|
|
754
|
+
return result;
|
|
755
|
+
}
|
|
756
|
+
function getNumDataCodewords(ver, ecl) {
|
|
757
|
+
return Math.floor(getNumRawDataModules(ver) / 8) - ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
|
|
758
|
+
}
|
|
759
|
+
function reedSolomonComputeDivisor(degree) {
|
|
760
|
+
if (degree < 1 || degree > 255) throw new RangeError("Degree out of range");
|
|
761
|
+
const result = [];
|
|
762
|
+
for (let i = 0; i < degree - 1; i++) result.push(0);
|
|
763
|
+
result.push(1);
|
|
764
|
+
let root = 1;
|
|
765
|
+
for (let i = 0; i < degree; i++) {
|
|
766
|
+
for (let j = 0; j < result.length; j++) {
|
|
767
|
+
result[j] = reedSolomonMultiply(result[j], root);
|
|
768
|
+
if (j + 1 < result.length) result[j] ^= result[j + 1];
|
|
769
|
+
}
|
|
770
|
+
root = reedSolomonMultiply(root, 2);
|
|
771
|
+
}
|
|
772
|
+
return result;
|
|
773
|
+
}
|
|
774
|
+
function reedSolomonComputeRemainder(data, divisor) {
|
|
775
|
+
const result = divisor.map((_) => 0);
|
|
776
|
+
for (const b of data) {
|
|
777
|
+
const factor = b ^ result.shift();
|
|
778
|
+
result.push(0);
|
|
779
|
+
divisor.forEach((coef, i) => result[i] ^= reedSolomonMultiply(coef, factor));
|
|
780
|
+
}
|
|
781
|
+
return result;
|
|
782
|
+
}
|
|
783
|
+
function reedSolomonMultiply(x, y) {
|
|
784
|
+
if (x >>> 8 !== 0 || y >>> 8 !== 0) throw new RangeError("Byte out of range");
|
|
785
|
+
let z = 0;
|
|
786
|
+
for (let i = 7; i >= 0; i--) {
|
|
787
|
+
z = z << 1 ^ (z >>> 7) * 285;
|
|
788
|
+
z ^= (y >>> i & 1) * x;
|
|
789
|
+
}
|
|
790
|
+
return z;
|
|
791
|
+
}
|
|
792
|
+
function encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
|
|
793
|
+
if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7) throw new RangeError("Invalid value");
|
|
794
|
+
let version;
|
|
795
|
+
let dataUsedBits;
|
|
796
|
+
for (version = minVersion;; version++) {
|
|
797
|
+
const dataCapacityBits2 = getNumDataCodewords(version, ecl) * 8;
|
|
798
|
+
const usedBits = getTotalBits(segs, version);
|
|
799
|
+
if (usedBits <= dataCapacityBits2) {
|
|
800
|
+
dataUsedBits = usedBits;
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
803
|
+
if (version >= maxVersion) throw new RangeError("Data too long");
|
|
804
|
+
}
|
|
805
|
+
for (const newEcl of [
|
|
806
|
+
MEDIUM,
|
|
807
|
+
QUARTILE,
|
|
808
|
+
HIGH
|
|
809
|
+
]) if (boostEcl && dataUsedBits <= getNumDataCodewords(version, newEcl) * 8) ecl = newEcl;
|
|
810
|
+
const bb = [];
|
|
811
|
+
for (const seg of segs) {
|
|
812
|
+
appendBits(seg.mode[0], 4, bb);
|
|
813
|
+
appendBits(seg.numChars, numCharCountBits(seg.mode, version), bb);
|
|
814
|
+
for (const b of seg.getData()) bb.push(b);
|
|
815
|
+
}
|
|
816
|
+
const dataCapacityBits = getNumDataCodewords(version, ecl) * 8;
|
|
817
|
+
appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
|
|
818
|
+
appendBits(0, (8 - bb.length % 8) % 8, bb);
|
|
819
|
+
for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 253) appendBits(padByte, 8, bb);
|
|
820
|
+
const dataCodewords = Array.from({ length: Math.ceil(bb.length / 8) }, () => 0);
|
|
821
|
+
bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
|
|
822
|
+
return new QrCode(version, ecl, dataCodewords, mask);
|
|
823
|
+
}
|
|
824
|
+
function encode(data, options) {
|
|
825
|
+
const { ecc = "L", boostEcc = false, minVersion = 1, maxVersion = 40, maskPattern = -1, border = 1 } = options || {};
|
|
826
|
+
const segment = typeof data === "string" ? makeSegments(data) : Array.isArray(data) ? [makeBytes(data)] : void 0;
|
|
827
|
+
if (!segment) throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof data}`);
|
|
828
|
+
const qr = encodeSegments(segment, EccMap[ecc], minVersion, maxVersion, maskPattern, boostEcc);
|
|
829
|
+
const result = addBorder({
|
|
830
|
+
version: qr.version,
|
|
831
|
+
maskPattern: qr.mask,
|
|
832
|
+
size: qr.size,
|
|
833
|
+
data: qr.modules,
|
|
834
|
+
types: qr.types
|
|
835
|
+
}, border);
|
|
836
|
+
if (options?.invert) result.data = result.data.map((row) => row.map((mod) => !mod));
|
|
837
|
+
options?.onEncoded?.(result);
|
|
838
|
+
return result;
|
|
839
|
+
}
|
|
840
|
+
function addBorder(input, border = 1) {
|
|
841
|
+
if (!border) return input;
|
|
842
|
+
const { size } = input;
|
|
843
|
+
const newSize = size + border * 2;
|
|
844
|
+
input.size = newSize;
|
|
845
|
+
input.data.forEach((row) => {
|
|
846
|
+
for (let i = 0; i < border; i++) {
|
|
847
|
+
row.unshift(false);
|
|
848
|
+
row.push(false);
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
for (let i = 0; i < border; i++) {
|
|
852
|
+
input.data.unshift(Array.from({ length: newSize }, (_) => false));
|
|
853
|
+
input.data.push(Array.from({ length: newSize }, (_) => false));
|
|
854
|
+
}
|
|
855
|
+
const b = QrCodeDataType.Border;
|
|
856
|
+
input.types.forEach((row) => {
|
|
857
|
+
for (let i = 0; i < border; i++) {
|
|
858
|
+
row.unshift(b);
|
|
859
|
+
row.push(b);
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
for (let i = 0; i < border; i++) {
|
|
863
|
+
input.types.unshift(Array.from({ length: newSize }, (_) => b));
|
|
864
|
+
input.types.push(Array.from({ length: newSize }, (_) => b));
|
|
865
|
+
}
|
|
866
|
+
return input;
|
|
867
|
+
}
|
|
868
|
+
function getDataAt(data, x, y, defaults = false) {
|
|
869
|
+
if (x < 0 || y < 0 || x >= data.length || y >= data.length) return defaults;
|
|
870
|
+
return data[y][x];
|
|
871
|
+
}
|
|
872
|
+
function renderUnicodeCompact(data, options = {}) {
|
|
873
|
+
const platte = {
|
|
874
|
+
WHITE_ALL: "█",
|
|
875
|
+
WHITE_BLACK: "▀",
|
|
876
|
+
BLACK_WHITE: "▄",
|
|
877
|
+
BLACK_ALL: " "
|
|
878
|
+
};
|
|
879
|
+
const result = encode(data, options);
|
|
880
|
+
const WHITE = false;
|
|
881
|
+
const BLACK = true;
|
|
882
|
+
const at = (x, y) => getDataAt(result.data, x, y, true);
|
|
883
|
+
const lines = [];
|
|
884
|
+
let line = "";
|
|
885
|
+
for (let row = 0; row < result.size; row += 2) {
|
|
886
|
+
for (let col = 0; col < result.size; col++) if (at(col, row) === WHITE && at(col, row + 1) === WHITE) line += platte.WHITE_ALL;
|
|
887
|
+
else if (at(col, row) === WHITE && at(col, row + 1) === BLACK) line += platte.WHITE_BLACK;
|
|
888
|
+
else if (at(col, row) === BLACK && at(col, row + 1) === WHITE) line += platte.BLACK_WHITE;
|
|
889
|
+
else line += platte.BLACK_ALL;
|
|
890
|
+
lines.push(line);
|
|
891
|
+
line = "";
|
|
892
|
+
}
|
|
893
|
+
return lines.join("\n");
|
|
894
|
+
}
|
|
895
|
+
//#endregion
|
|
896
|
+
export { renderUnicodeCompact };
|