@gerege-systems/eid-mongolia-sdk 0.15.3 → 0.16.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gerege-systems/eid-mongolia-sdk",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "description": "e-ID Mongolia Relying Party SDK — иргэнээр утсаар нь нэвтрэлт ба хууль ёсны цахим гарын үсэг (RP-API v3, Smart-ID нийцтэй).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,51 +0,0 @@
1
- import {
2
- DeviceLinkError
3
- } from "./chunk-TB2KQH3W.js";
4
-
5
- // src/devicelink.ts
6
- var SESSION_ID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
7
- var VC_RE = /^[0-9]{5}$/;
8
- function deviceLink(session) {
9
- const base = session.deviceLinkBase?.trim();
10
- if (!base) throw new DeviceLinkError("deviceLink: \u0445\u0430\u0440\u0438\u0443\u043D\u0434 deviceLinkBase \u0431\u0430\u0439\u0445\u0433\u04AF\u0439 \u2014 device-link session \u044D\u0441\u044D\u0445\u0438\u0439\u0433 \u0448\u0430\u043B\u0433\u0430");
11
- let u;
12
- try {
13
- u = new URL(base);
14
- } catch {
15
- throw new DeviceLinkError(`deviceLink: deviceLinkBase \u0431\u0443\u0440\u0443\u0443 URL: ${base}`);
16
- }
17
- if (u.protocol !== "https:" && u.protocol !== "http:") {
18
- throw new DeviceLinkError(`deviceLink: deviceLinkBase https URL \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439: ${u.protocol}`);
19
- }
20
- if (!SESSION_ID_RE.test(session.sessionId)) throw new DeviceLinkError("deviceLink: sessionId UUID (lowercase) \u0431\u0438\u0448");
21
- if (session.vc == null || !VC_RE.test(session.vc)) throw new DeviceLinkError("deviceLink: vc 5 \u043E\u0440\u043E\u043D\u0442\u043E\u0439 \u0442\u043E\u043E \u0431\u0438\u0448");
22
- u.searchParams.set("sessionId", session.sessionId);
23
- u.searchParams.set("vc", session.vc);
24
- return u.toString();
25
- }
26
- function isMobileUserAgent(nav) {
27
- const n = nav ?? globalThis.navigator;
28
- if (!n) return false;
29
- if (n.userAgentData?.mobile === true) return true;
30
- const ua = n.userAgent ?? "";
31
- if (/Android|iPhone|iPod|iPad/i.test(ua)) return true;
32
- return /Macintosh/.test(ua) && (n.maxTouchPoints ?? 0) > 1;
33
- }
34
- function openOrShowQR(session, opts) {
35
- const link = deviceLink(session);
36
- const mobile = typeof opts.isMobile === "function" ? opts.isMobile() : opts.isMobile ?? isMobileUserAgent();
37
- if (mobile) {
38
- const loc = globalThis.location;
39
- if (!loc) throw new DeviceLinkError("openOrShowQR: location \u0431\u0430\u0439\u0445\u0433\u04AF\u0439 \u2014 \u0437\u04E9\u0432\u0445\u04E9\u043D \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0442");
40
- loc.assign(link);
41
- return "opened";
42
- }
43
- opts.showQR(link);
44
- return "qr";
45
- }
46
-
47
- export {
48
- deviceLink,
49
- isMobileUserAgent,
50
- openOrShowQR
51
- };