@prson/login-sdk-ui 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,114 @@
1
- # Temporary Holding Version
1
+ # @prson/login-sdk-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Optional batteries-included UI for [`@prson/login-sdk`](../browser). One
4
+ script tag drops in a styled, themable QR card with a TTL countdown and
5
+ a refresh affordance. If your site already has a design system, you can
6
+ skip this package entirely — the base SDK is headless and accepts any
7
+ QR renderer you wire onto `window.__prsonLoginQrRenderer`.
8
+
9
+ ## Install
10
+
11
+ Install from npm (below), or load the browser bundle from
12
+ `https://prson.net/vendor/prson-login/prson-login-ui.js` together with
13
+ `https://prson.net/vendor/prson-login/prson-login.js`.
14
+
15
+ Via npm:
16
+
17
+ ```bash
18
+ npm install @prson/login-sdk @prson/login-sdk-ui
19
+ ```
20
+
21
+ Via `<script>`:
22
+
23
+ ```html
24
+ <script type="module" src="https://prson.net/vendor/prson-login/prson-login.js"></script>
25
+ <script type="module" src="https://prson.net/vendor/prson-login/prson-login-ui.js"></script>
26
+ ```
27
+
28
+ ## Use
29
+
30
+ The package is a **side-effect import**. Loading it once registers a
31
+ renderer on `window.__prsonLoginQrRenderer`; the base SDK reads that
32
+ global when `PrsonLogin.signIn(...)` needs to draw a QR.
33
+
34
+ ```ts
35
+ import "@prson/login-sdk-ui"; // ← side-effect register
36
+ import { PrsonLogin } from "@prson/login-sdk";
37
+
38
+ await PrsonLogin.signIn({
39
+ ui: { mountQrInto: "#prson-login-qr", theme: "auto" },
40
+ required: { minVerificationLevel: 5 },
41
+ });
42
+ ```
43
+
44
+ That's it. No further configuration. The card renders, the TTL counts
45
+ down, and when it expires the footer swaps to a **Generate a new code**
46
+ button.
47
+
48
+ ## Refresh contract
49
+
50
+ When the TTL hits zero the refresh button dispatches a bubbling
51
+ `CustomEvent` named `prson-login-refresh-requested` on the document.
52
+ Listen for it and re-trigger your sign-in flow:
53
+
54
+ ```ts
55
+ document.addEventListener("prson-login-refresh-requested", () => {
56
+ document.querySelector("#signin")?.click();
57
+ });
58
+ ```
59
+
60
+ ## Manual / opt-out
61
+
62
+ If you want the renderer but NOT the auto-registration (e.g. you want
63
+ to mount conditionally, or wrap it in your own logic):
64
+
65
+ ```ts
66
+ import { renderQrCard } from "@prson/login-sdk-ui/render";
67
+
68
+ // Don't import the package's main entry — only the manual one.
69
+ window.__prsonLoginQrRenderer = (url, mount, theme) => {
70
+ // ... your own conditional logic, then:
71
+ return renderQrCard(url, mount, theme);
72
+ };
73
+ ```
74
+
75
+ ## Theming
76
+
77
+ The card scopes its CSS variables to `[data-prson-login-ui]`. Override
78
+ any of them with higher specificity to match your design system:
79
+
80
+ ```css
81
+ [data-prson-login-ui] {
82
+ --prson-ui-card: oklch(0.97 0.02 250);
83
+ --prson-ui-accent: oklch(0.5 0.2 250);
84
+ --prson-ui-radius: 20px;
85
+ }
86
+ ```
87
+
88
+ Full variable list lives in [`src/styles.ts`](src/styles.ts).
89
+
90
+ ## What it weighs
91
+
92
+ - Bundle size: **~70 KB** uncompressed, ~22 KB gzipped. The
93
+ `qrcode` library accounts for the bulk; the renderer + styles are
94
+ ~7 KB combined.
95
+ - Runtime cost: one SVG draw + a 1 Hz `setInterval` while the QR is
96
+ on-screen.
97
+
98
+ ## Building
99
+
100
+ ```bash
101
+ cd login-sdk/packages/browser-ui
102
+ npm install
103
+ npm run build # → dist/index.js (publishable artefact)
104
+ npm run build:example # → ../../examples/plain-html/prson-login-ui.js
105
+ ```
106
+
107
+ `npm run build:vendor` in `login-sdk/` rebuilds every committed bundle
108
+ (the plain-HTML demo and the minified copies served from
109
+ `prson.net/vendor/prson-login/`); CI fails the deploy if they are stale
110
+ (`npm run check:vendor`).
111
+
112
+ Editing `src/qr-renderer.ts` or `src/styles.ts` and re-running
113
+ `npm run build:example` picks up in the plain-HTML demo without any
114
+ other moving parts.
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The "Sign in with Prson" button: the Prson mark (the "p" on a rounded
3
+ * square) and a label, in four variants, at least 44 px tall. Three ways
4
+ * to use it:
5
+ *
6
+ * 1. The custom element (registered on import):
7
+ * <prson-signin-button variant="amber" size="lg"></prson-signin-button>
8
+ * It renders a real <button> inside (light DOM, so forms, focus and
9
+ * your CSS work as usual). Listen for "click" on the element.
10
+ *
11
+ * 2. From script:
12
+ * const btn = createSignInButton({ variant: "dark", onClick: () => PrsonLogin.signIn({...}) });
13
+ * document.querySelector("#login").append(btn);
14
+ *
15
+ * 3. Plain HTML + the injected stylesheet:
16
+ * <button class="prson-signin-btn prson-signin-btn--amber">…mark…<span>Sign in with Prson</span></button>
17
+ * (`prsonMarkSvg()` gives you the mark's markup.)
18
+ *
19
+ * Variants: "amber" (default, the brand's primary on light pages), "dark"
20
+ * (ink, for light pages that want less colour), "light" (white, for dark
21
+ * or busy backgrounds), "outline" (transparent, takes the text colour).
22
+ * Sizes: "md" 44 px, "lg" 52 px.
23
+ */
24
+ export type SignInButtonVariant = "amber" | "dark" | "light" | "outline";
25
+ export type SignInButtonSize = "md" | "lg";
26
+ export type SignInButtonOptions = {
27
+ variant?: SignInButtonVariant;
28
+ size?: SignInButtonSize;
29
+ /** Default "Sign in with Prson". */
30
+ label?: string;
31
+ /** Stretch to the container's width. */
32
+ fullWidth?: boolean;
33
+ onClick?: (e: MouseEvent) => void;
34
+ };
35
+ /** The Prson mark as SVG markup: the "p" ([glyph]) on a rounded square ([square]). Decorative (aria-hidden). */
36
+ export declare function prsonMarkSvg(opts?: {
37
+ size?: number;
38
+ square?: string;
39
+ glyph?: string;
40
+ }): string;
41
+ /** A ready "Sign in with Prson" <button>. */
42
+ export declare function createSignInButton(opts?: SignInButtonOptions): HTMLButtonElement;
43
+ /**
44
+ * `<prson-signin-button variant size label full-width disabled busy>`.
45
+ * `busy` shows a spinner and sets aria-busy; `disabled` disables the inner button.
46
+ */
47
+ export declare function defineSignInButtonElement(tag?: string): void;
package/dist/button.js ADDED
@@ -0,0 +1,118 @@
1
+ /**
2
+ * The "Sign in with Prson" button: the Prson mark (the "p" on a rounded
3
+ * square) and a label, in four variants, at least 44 px tall. Three ways
4
+ * to use it:
5
+ *
6
+ * 1. The custom element (registered on import):
7
+ * <prson-signin-button variant="amber" size="lg"></prson-signin-button>
8
+ * It renders a real <button> inside (light DOM, so forms, focus and
9
+ * your CSS work as usual). Listen for "click" on the element.
10
+ *
11
+ * 2. From script:
12
+ * const btn = createSignInButton({ variant: "dark", onClick: () => PrsonLogin.signIn({...}) });
13
+ * document.querySelector("#login").append(btn);
14
+ *
15
+ * 3. Plain HTML + the injected stylesheet:
16
+ * <button class="prson-signin-btn prson-signin-btn--amber">…mark…<span>Sign in with Prson</span></button>
17
+ * (`prsonMarkSvg()` gives you the mark's markup.)
18
+ *
19
+ * Variants: "amber" (default, the brand's primary on light pages), "dark"
20
+ * (ink, for light pages that want less colour), "light" (white, for dark
21
+ * or busy backgrounds), "outline" (transparent, takes the text colour).
22
+ * Sizes: "md" 44 px, "lg" 52 px.
23
+ */
24
+ const P_STEM = "M46.2623 100.265C43.9277 100.265 41.9617 99.5892 40.3643 98.2375C38.8898 96.8859 38.1526 95.1657 38.1526 93.0768V70.5907C38.1526 66.0444 37.1082 62.7882 35.0193 60.8222C33.0533 58.8562 30.5958 57.8732 27.6468 57.8732C24.5749 57.8732 21.9946 58.8562 19.9057 60.8222C17.9397 62.7882 16.711 65.0614 16.2195 67.6417V92.3396C16.2195 94.4284 15.4208 96.2101 13.8234 97.6846C12.3489 99.0362 10.5058 99.712 8.29404 99.712C5.95942 99.712 3.99343 99.0362 2.39606 97.6846C0.798686 96.333 0 94.6127 0 92.5239V51.238C0 49.272 0.737248 47.6132 2.21174 46.2615C3.80912 44.787 5.83655 44.0498 8.29404 44.0498C10.26 44.0498 11.9188 44.6027 13.2705 45.7086C14.6221 46.6916 15.5437 47.9818 16.0352 49.5792C19.3528 45.2785 24.3906 43.1282 31.1487 43.1282C38.0297 43.1282 43.6205 45.1557 47.9211 49.2105C52.2218 53.2654 54.3721 59.7163 54.3721 68.5633V93.4454C54.3721 95.4114 53.5734 97.0702 51.976 98.4219C50.5015 99.6506 48.597 100.265 46.2623 100.265Z";
25
+ const P_DOT = "M26.7637 0.900391C29.8673 0.900391 32.6569 1.60533 35.1299 3.01758C37.6743 4.35994 39.6881 6.26878 41.1719 8.74121C42.6585 11.1465 43.3994 13.9742 43.3994 17.2197C43.3994 20.3955 42.6579 23.2567 41.1738 25.8008C39.6892 28.2744 37.6757 30.2181 35.1328 31.6309C32.6582 33.043 29.8683 33.75 26.7637 33.75C23.9181 33.75 21.2882 33.1284 18.875 31.8867L18.3945 31.6309C15.8521 30.2184 13.8036 28.2754 12.25 25.8037C10.764 23.2567 10.0235 20.3954 10.0234 17.2197C10.0234 13.9742 10.7643 11.1466 12.25 8.74121L12.5469 8.2832C14.0617 6.03176 16.012 4.27606 18.3965 3.01758C20.9392 1.60538 23.729 0.900409 26.7637 0.900391ZM26.7637 9.63086C24.682 9.63089 22.9161 10.3241 21.4609 11.71C20.0799 13.0921 19.3857 14.9255 19.3857 17.2197C19.3858 19.4431 20.0804 21.3133 21.4658 22.8379C22.9209 24.2919 24.6846 25.0185 26.7637 25.0186C28.915 25.0186 30.6429 24.2913 31.9561 22.8398L32.208 22.5498C33.4264 21.0797 34.0361 19.3046 34.0361 17.2197C34.0361 14.9244 33.3414 13.0904 31.959 11.708L31.7061 11.4551C30.4267 10.2404 28.7819 9.63086 26.7637 9.63086Z";
26
+ /** The Prson mark as SVG markup: the "p" ([glyph]) on a rounded square ([square]). Decorative (aria-hidden). */
27
+ export function prsonMarkSvg(opts = {}) {
28
+ const size = opts.size ?? 24;
29
+ const square = opts.square ?? "#FBBF24";
30
+ const glyph = opts.glyph ?? "#0A0A0A";
31
+ return (`<svg class="prson-mark" width="${size}" height="${size}" viewBox="0 0 24 24" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg">` +
32
+ `<rect width="24" height="24" rx="6" fill="${square}"/>` +
33
+ `<g transform="translate(7.2 3.15) scale(0.175)" fill="${glyph}"><path d="${P_STEM}"/><path d="${P_DOT}"/></g></svg>`);
34
+ }
35
+ const MARK_COLOURS = {
36
+ amber: { square: "#0A0A0A", glyph: "#FBBF24" },
37
+ dark: { square: "#FBBF24", glyph: "#0A0A0A" },
38
+ light: { square: "#FBBF24", glyph: "#0A0A0A" },
39
+ outline: { square: "#FBBF24", glyph: "#0A0A0A" },
40
+ };
41
+ const VARIANTS = ["amber", "dark", "light", "outline"];
42
+ function variantOf(v) {
43
+ return VARIANTS.includes(v) ? v : "amber";
44
+ }
45
+ /** Fill [btn] with the mark and label and set its classes. */
46
+ function decorate(btn, o) {
47
+ const variant = variantOf(o.variant);
48
+ btn.className = [
49
+ "prson-signin-btn",
50
+ `prson-signin-btn--${variant}`,
51
+ o.size === "lg" ? "prson-signin-btn--lg" : "",
52
+ o.fullWidth ? "prson-signin-btn--block" : "",
53
+ ]
54
+ .filter(Boolean)
55
+ .join(" ");
56
+ btn.innerHTML = prsonMarkSvg({ size: o.size === "lg" ? 26 : 22, ...MARK_COLOURS[variant] });
57
+ const label = document.createElement("span");
58
+ label.className = "prson-signin-btn__label";
59
+ label.textContent = o.label ?? "Sign in with Prson";
60
+ btn.append(label);
61
+ }
62
+ /** A ready "Sign in with Prson" <button>. */
63
+ export function createSignInButton(opts = {}) {
64
+ const btn = document.createElement("button");
65
+ btn.type = "button";
66
+ decorate(btn, opts);
67
+ if (opts.onClick)
68
+ btn.addEventListener("click", opts.onClick);
69
+ return btn;
70
+ }
71
+ /**
72
+ * `<prson-signin-button variant size label full-width disabled busy>`.
73
+ * `busy` shows a spinner and sets aria-busy; `disabled` disables the inner button.
74
+ */
75
+ export function defineSignInButtonElement(tag = "prson-signin-button") {
76
+ if (typeof window === "undefined" || !("customElements" in window) || customElements.get(tag))
77
+ return;
78
+ class PrsonSignInButtonElement extends HTMLElement {
79
+ constructor() {
80
+ super(...arguments);
81
+ this.btn = null;
82
+ }
83
+ static get observedAttributes() {
84
+ return ["variant", "size", "label", "full-width", "disabled", "busy"];
85
+ }
86
+ connectedCallback() {
87
+ if (!this.btn) {
88
+ this.btn = document.createElement("button");
89
+ this.btn.type = "button";
90
+ this.append(this.btn);
91
+ }
92
+ this.render();
93
+ }
94
+ attributeChangedCallback() {
95
+ if (this.btn)
96
+ this.render();
97
+ }
98
+ render() {
99
+ const btn = this.btn;
100
+ decorate(btn, {
101
+ variant: variantOf(this.getAttribute("variant")),
102
+ size: this.getAttribute("size") === "lg" ? "lg" : "md",
103
+ label: this.getAttribute("label") ?? undefined,
104
+ fullWidth: this.hasAttribute("full-width"),
105
+ });
106
+ if (this.hasAttribute("full-width"))
107
+ this.style.display = "block";
108
+ btn.disabled = this.hasAttribute("disabled");
109
+ const busy = this.hasAttribute("busy");
110
+ if (busy)
111
+ btn.setAttribute("aria-busy", "true");
112
+ else
113
+ btn.removeAttribute("aria-busy");
114
+ btn.classList.toggle("prson-signin-btn--busy", busy);
115
+ }
116
+ }
117
+ customElements.define(tag, PrsonSignInButtonElement);
118
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Reads the sign-in code's URL (the universal link the SDK builds:
3
+ * `https://app.prson.net/login/v1?s=…&d=<domain>&req=<b64u JSON>&t=<serverTs>`)
4
+ * and describes it for people: which site, and exactly what that site
5
+ * will get. Pure functions, no DOM, so they're easy to test.
6
+ */
7
+ export type ShareIcon = "shield" | "user" | "calendar" | "id" | "mail" | "phone" | "home" | "building" | "key" | "flag" | "check";
8
+ export type ShareItem = {
9
+ icon: ShareIcon;
10
+ label: string;
11
+ detail?: string;
12
+ };
13
+ export type CodeDescription = {
14
+ /** The site the person signs in to (`d=`), or "" when the URL has none. */
15
+ domain: string;
16
+ /** The server timestamp the code was issued at (epoch seconds), when present. */
17
+ serverTs: number | null;
18
+ /** What the site will receive, in order. Always at least one item. */
19
+ shares: ShareItem[];
20
+ /** The site lets the person sign in without an identity. */
21
+ anonymousAllowed: boolean;
22
+ };
23
+ type Required = {
24
+ minVerificationLevel?: number;
25
+ requiredClaims?: string[];
26
+ predicates?: string[];
27
+ identityType?: "personal" | "organization";
28
+ uniqueHumanId?: boolean;
29
+ };
30
+ type Request = {
31
+ domain?: string;
32
+ required?: Required;
33
+ allowAnonymous?: boolean;
34
+ ephemeralIdentity?: boolean;
35
+ };
36
+ /** What a site asking for [required] gets, one row per distinct thing. */
37
+ export declare function describeShares(req: Request): ShareItem[];
38
+ /** Everything the card shows about a code, from its URL alone. */
39
+ export declare function describeCode(url: string): CodeDescription;
40
+ /** The letter for a site's monogram: its registrable name's first letter ("shop.example.com" → "E"). */
41
+ export declare function monogram(domain: string): string;
42
+ export {};
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Reads the sign-in code's URL (the universal link the SDK builds:
3
+ * `https://app.prson.net/login/v1?s=…&d=<domain>&req=<b64u JSON>&t=<serverTs>`)
4
+ * and describes it for people: which site, and exactly what that site
5
+ * will get. Pure functions, no DOM, so they're easy to test.
6
+ */
7
+ function b64uDecode(s) {
8
+ const pad = s.length % 4 === 0 ? "" : "=".repeat(4 - (s.length % 4));
9
+ const bin = atob(s.replace(/-/g, "+").replace(/_/g, "/") + pad);
10
+ const bytes = new Uint8Array(bin.length);
11
+ for (let i = 0; i < bin.length; i++)
12
+ bytes[i] = bin.charCodeAt(i);
13
+ return new TextDecoder().decode(bytes);
14
+ }
15
+ function param(url, name) {
16
+ try {
17
+ return new URL(url).searchParams.get(name);
18
+ }
19
+ catch {
20
+ // `prson://` URLs from older verifiers: fall back to a regex.
21
+ const m = url.match(new RegExp(`[?&]${name}=([^&#]*)`));
22
+ const cap = m?.[1];
23
+ return cap ? decodeURIComponent(cap) : null;
24
+ }
25
+ }
26
+ const CLAIMS = {
27
+ given_name: { icon: "user", label: "Your name" },
28
+ family_name: { icon: "user", label: "Your name" },
29
+ name: { icon: "user", label: "Your name" },
30
+ full_name: { icon: "user", label: "Your name" },
31
+ birthdate: { icon: "calendar", label: "Date of birth" },
32
+ birth_date: { icon: "calendar", label: "Date of birth" },
33
+ age: { icon: "calendar", label: "Your age" },
34
+ email: { icon: "mail", label: "Email address" },
35
+ phone: { icon: "phone", label: "Phone number" },
36
+ phone_number: { icon: "phone", label: "Phone number" },
37
+ address: { icon: "home", label: "Address" },
38
+ nationality: { icon: "flag", label: "Nationality" },
39
+ nationalities: { icon: "flag", label: "Nationality" },
40
+ document_number: { icon: "id", label: "Document number" },
41
+ document_type: { icon: "id", label: "Document type" },
42
+ picture: { icon: "user", label: "Photo" },
43
+ };
44
+ const PREDICATES = {
45
+ phone_verified: { icon: "phone", label: "A verified phone number", detail: "Not the number itself" },
46
+ email_verified: { icon: "mail", label: "A verified email", detail: "Not the address itself" },
47
+ address_verified: { icon: "home", label: "A verified address", detail: "Not the address itself" },
48
+ bank_verified: { icon: "check", label: "A verified bank account", detail: "Not the account itself" },
49
+ };
50
+ /** "some_claim_name" → "Some claim name". */
51
+ function humanize(s) {
52
+ const t = s.replace(/[_-]+/g, " ").trim();
53
+ return t ? t.charAt(0).toUpperCase() + t.slice(1) : s;
54
+ }
55
+ function predicateItem(p) {
56
+ const known = PREDICATES[p];
57
+ if (known)
58
+ return known;
59
+ const age = p.match(/^age_(gte|gt|over|lt|under)_(\d{1,3})$/);
60
+ if (age) {
61
+ const n = Number(age[2]);
62
+ const label = age[1] === "gte" || age[1] === "over" ? `${n} or older` : age[1] === "gt" ? `Older than ${n}` : `Under ${n}`;
63
+ return { icon: "calendar", label, detail: "Not your date of birth" };
64
+ }
65
+ return { icon: "check", label: humanize(p), detail: "Yes or no only" };
66
+ }
67
+ /** What a site asking for [required] gets, one row per distinct thing. */
68
+ export function describeShares(req) {
69
+ const r = req.required ?? {};
70
+ const out = [];
71
+ const seen = new Set();
72
+ const add = (i) => {
73
+ if (seen.has(i.label))
74
+ return;
75
+ seen.add(i.label);
76
+ out.push(i);
77
+ };
78
+ if (r.identityType === "organization")
79
+ add({ icon: "building", label: "An organisation identity" });
80
+ const level = r.minVerificationLevel ?? 1;
81
+ if (r.uniqueHumanId) {
82
+ add({ icon: "shield", label: "Verified unique person", detail: "Passport or ID checked · not trackable across sites" });
83
+ }
84
+ else if (level >= 4) {
85
+ add({ icon: "shield", label: "Verified human", detail: "Passport or ID checked" });
86
+ }
87
+ else if (level >= 1) {
88
+ add({ icon: "shield", label: "Verified human" });
89
+ }
90
+ else {
91
+ add({ icon: "shield", label: "Your Prson identity", detail: "Verified or not" });
92
+ }
93
+ for (const p of r.predicates ?? [])
94
+ add(predicateItem(p));
95
+ for (const c of r.requiredClaims ?? [])
96
+ add(CLAIMS[c] ?? { icon: "check", label: humanize(c) });
97
+ add(req.ephemeralIdentity
98
+ ? { icon: "key", label: "A one-time key", detail: "Nothing links your visits" }
99
+ : { icon: "key", label: "A sign-in key just for this site" });
100
+ return out;
101
+ }
102
+ /** Everything the card shows about a code, from its URL alone. */
103
+ export function describeCode(url) {
104
+ let req = {};
105
+ const raw = param(url, "req");
106
+ if (raw) {
107
+ try {
108
+ req = JSON.parse(b64uDecode(raw));
109
+ }
110
+ catch {
111
+ req = {};
112
+ }
113
+ }
114
+ const t = param(url, "t");
115
+ const serverTs = t && /^\d+$/.test(t) ? parseInt(t, 10) : null;
116
+ return {
117
+ domain: param(url, "d") ?? req.domain ?? "",
118
+ serverTs,
119
+ shares: describeShares(req),
120
+ anonymousAllowed: req.allowAnonymous === true,
121
+ };
122
+ }
123
+ /** The letter for a site's monogram: its registrable name's first letter ("shop.example.com" → "E"). */
124
+ export function monogram(domain) {
125
+ const host = domain.replace(/:\d+$/, "").toLowerCase();
126
+ const parts = host.split(".").filter(Boolean);
127
+ // Drop a leading "www"/"app"/"shop"-style label only when there's a name after it.
128
+ const name = parts.length >= 3 ? parts[parts.length - 2] : parts[0];
129
+ const ch = (name ?? host).match(/[a-z0-9]/i)?.[0] ?? "?";
130
+ return ch.toUpperCase();
131
+ }