bwh-auth 0.2.0 → 0.3.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/README.md CHANGED
@@ -5,6 +5,9 @@ Shared headless React auth components for BWH applications.
5
5
  This package owns auth-specific React behavior and browser helpers. It does not import
6
6
  or bundle a UI kit, Blade page wrappers, or application Vite entrypoints. Consumers must inject their own UI components and mount these components from app-owned pages/entrypoints.
7
7
 
8
+ The companion Laravel API package is
9
+ [`bherila/auth-laravel`](https://github.com/bherila/auth-laravel).
10
+
8
11
  ## Ownership boundary
9
12
 
10
13
  `bwh-auth` exports React components only. Laravel apps should keep their own Blade files such as `resources/views/auth/login.blade.php` and Vite entrypoints such as `resources/js/auth/login.tsx`; those app files import and mount these shared components.
@@ -20,28 +23,47 @@ or bundle a UI kit, Blade page wrappers, or application Vite entrypoints. Consum
20
23
  - `PasskeyLoginButton`
21
24
  - `PasskeySection`
22
25
 
26
+ ## Relying-party helpers
27
+
28
+ `relyingApplicationsFrom(value)` validates the sibling-application list an identity provider
29
+ reports into one that is safe to render, and `safeApplicationHref(url)` is the scheme check
30
+ behind it. Neither touches the DOM, so an app can feed them a `#app-initial-data` payload, an
31
+ Inertia shared prop, or anything else it already has.
32
+
33
+ ```ts
34
+ import { relyingApplicationsFrom } from 'bwh-auth';
35
+
36
+ const applications = relyingApplicationsFrom(initialData.applications);
37
+ ```
38
+
39
+ Rendering these entries means putting provider-supplied text into an `href`. `javascript:`
40
+ and `data:` URLs pass a server-side URL-validity check but execute rather than navigate, so
41
+ the scheme is parsed rather than prefix-matched — a `startsWith` test can be walked past with
42
+ leading control characters or unexpected case — and the **parsed** form is returned, so what
43
+ is rendered is exactly what was validated. Unrecognised entries are dropped rather than
44
+ throwing: this is navigation chrome, and one malformed entry must not take down the page it
45
+ appears on.
46
+
23
47
  ## Install
24
48
 
25
- For app CI before npm publication, use the GitHub Release tarball. This is the recommended path because the tarball includes built `dist` files and does not require CI to build this package during dependency installation.
49
+ Install the published package from npm:
26
50
 
27
51
  ```sh
28
- pnpm add https://github.com/bherila/auth/releases/download/bwh-auth-v0.2.0/bwh-auth-0.2.0.tgz
52
+ pnpm add bwh-auth
29
53
  ```
30
54
 
31
- Or pin it manually in `package.json`:
55
+ For a deliberately pinned version:
32
56
 
33
- ```json
34
- {
35
- "dependencies": {
36
- "bwh-auth": "https://github.com/bherila/auth/releases/download/bwh-auth-v0.2.0/bwh-auth-0.2.0.tgz"
37
- }
38
- }
57
+ ```sh
58
+ pnpm add bwh-auth@0.2.0
39
59
  ```
40
60
 
61
+ Commit `pnpm-lock.yaml`; consumers do not need a GitHub tarball URL.
62
+
41
63
  When installing locally during package development, a path dependency is still useful:
42
64
 
43
65
  ```sh
44
- pnpm add bwh-auth@file:../auth/ui
66
+ pnpm add bwh-auth@file:../auth-react
45
67
  ```
46
68
 
47
69
  Install peer dependencies in the consuming app:
@@ -187,7 +209,7 @@ Passkey components default to the Laravel package routes:
187
209
 
188
210
  ## Releasing
189
211
 
190
- Create and upload a GitHub release from this package directory:
212
+ Prepare a release from this package directory:
191
213
 
192
214
  ```sh
193
215
  pnpm release
@@ -196,14 +218,16 @@ pnpm release
196
218
  The release script:
197
219
 
198
220
  - requires a clean git working tree
199
- - bumps `ui/package.json` version, defaulting to `patch`
221
+ - bumps `package.json` version, defaulting to `patch`
200
222
  - runs `pnpm install --lockfile-only`
201
223
  - runs typecheck and build
202
- - creates `ui/release/bwh-auth-VERSION.tgz`
224
+ - creates `release/bwh-auth-VERSION.tgz`
203
225
  - commits the version bump
204
- - creates and pushes a tag like `bwh-auth-v0.1.1`
205
- - creates a GitHub release with the tarball asset
206
- - prints the install URL
226
+ - creates and pushes a signed tag like `bwh-auth-v0.1.1`
227
+
228
+ The release workflow verifies the tag signature, publishes to npm through its
229
+ trusted publisher, and creates a GitHub Release with the tarball as a secondary
230
+ artifact.
207
231
 
208
232
  Version bump options:
209
233
 
package/dist/index.cjs CHANGED
@@ -45,7 +45,9 @@ __export(index_exports, {
45
45
  getDefaultPasskeyName: () => getDefaultPasskeyName,
46
46
  isAbortError: () => isAbortError,
47
47
  isConditionalMediationAvailable: () => isConditionalMediationAvailable,
48
- registerPasskey: () => registerPasskey
48
+ registerPasskey: () => registerPasskey,
49
+ relyingApplicationsFrom: () => relyingApplicationsFrom,
50
+ safeApplicationHref: () => safeApplicationHref
49
51
  });
50
52
  module.exports = __toCommonJS(index_exports);
51
53
 
@@ -831,6 +833,35 @@ function PasskeySection({ endpoints = {}, components, onSuccess, onError }) {
831
833
  ] })
832
834
  ] });
833
835
  }
836
+
837
+ // src/relying-applications.ts
838
+ function safeApplicationHref(url) {
839
+ try {
840
+ const parsed = new URL(url);
841
+ return parsed.protocol === "https:" || parsed.protocol === "http:" ? parsed.toString() : null;
842
+ } catch {
843
+ return null;
844
+ }
845
+ }
846
+ function relyingApplicationsFrom(value) {
847
+ if (!Array.isArray(value)) {
848
+ return [];
849
+ }
850
+ return value.flatMap((entry) => {
851
+ if (typeof entry !== "object" || entry === null) {
852
+ return [];
853
+ }
854
+ const { key, name, url } = entry;
855
+ if (typeof key !== "string" || typeof name !== "string" || typeof url !== "string") {
856
+ return [];
857
+ }
858
+ if (key === "" || name.trim() === "") {
859
+ return [];
860
+ }
861
+ const href = safeApplicationHref(url);
862
+ return href === null ? [] : [{ key, name: name.trim(), url: href }];
863
+ });
864
+ }
834
865
  // Annotate the CommonJS export names for ESM import in node:
835
866
  0 && (module.exports = {
836
867
  ChangePasswordForm,
@@ -848,5 +879,7 @@ function PasskeySection({ endpoints = {}, components, onSuccess, onError }) {
848
879
  getDefaultPasskeyName,
849
880
  isAbortError,
850
881
  isConditionalMediationAvailable,
851
- registerPasskey
882
+ registerPasskey,
883
+ relyingApplicationsFrom,
884
+ safeApplicationHref
852
885
  });
package/dist/index.d.cts CHANGED
@@ -137,6 +137,44 @@ interface PasskeySectionProps {
137
137
  }
138
138
  declare function PasskeySection({ endpoints, components, onSuccess, onError }: PasskeySectionProps): react_jsx_runtime.JSX.Element;
139
139
 
140
+ /**
141
+ * The sibling applications an identity provider reports for the signed-in person.
142
+ *
143
+ * Every relying party receives this list the same way — server-side, injected per request
144
+ * from the session rather than compiled into a bundle — but each one carries it into the
145
+ * page differently: a `#app-initial-data` script tag, an Inertia shared prop, a Blade loop.
146
+ * What they cannot afford to do differently is decide which entries are safe to render, so
147
+ * that decision lives here and the transport stays the application's business.
148
+ */
149
+ interface RelyingApplication {
150
+ key: string;
151
+ name: string;
152
+ url: string;
153
+ }
154
+ /**
155
+ * Reduce a URL from the wire to one that is safe to put in an `href`, or reject it.
156
+ *
157
+ * These arrive as text in the page and end up as a link the browser will follow, so the
158
+ * scheme is what matters: `javascript:` and `data:` both pass a server-side URL validity
159
+ * check but execute rather than navigate. Parsing and allowing only http(s) is stronger
160
+ * than matching a prefix — it normalises away the leading control characters, mixed case,
161
+ * and escapes that a hand-rolled test can be walked past — and it returns the *parsed*
162
+ * form, so what gets rendered is exactly what was validated.
163
+ *
164
+ * Absolute URLs only, deliberately. These point at other origins; a relative one means the
165
+ * provider told us something unexpected, and guessing a base for it would be inventing a
166
+ * destination rather than validating one.
167
+ */
168
+ declare function safeApplicationHref(url: string): string | null;
169
+ /**
170
+ * Validate whatever the page handed over into a list that is safe to render.
171
+ *
172
+ * Unrecognised entries are dropped rather than throwing. This is navigation chrome: one
173
+ * malformed entry, or a provider that has grown a field, must not be able to take down the
174
+ * page it appears on. Anything that is not a well-formed list degrades to an empty menu.
175
+ */
176
+ declare function relyingApplicationsFrom(value: unknown): RelyingApplication[];
177
+
140
178
  declare function getCsrfToken(explicitToken?: string): string;
141
179
  declare function base64urlToArrayBuffer(b64: string): ArrayBuffer;
142
180
  declare function arrayBufferToBase64url(buffer: ArrayBuffer): string;
@@ -163,4 +201,4 @@ declare function isConditionalMediationAvailable(): Promise<boolean>;
163
201
  declare function authenticateWithPasskey({ endpoints, mediation, signal }?: AuthenticateWithPasskeyOptions): Promise<PasskeyAuthenticationResult>;
164
202
  declare function registerPasskey({ endpoints, name, signal }?: RegisterPasskeyOptions): Promise<PasskeyRegistrationResult>;
165
203
 
166
- export { type AuthButtonComponent, type AuthButtonComponentInput, type AuthButtonComponentProps, type AuthButtonSize, type AuthButtonVariant, type AuthComponentInput, type AuthComponentOverrides, type AuthComponentSet, type AuthComponentSuperset, type AuthComponents, type AuthContainerComponentProps, type AuthEndpointConfig, type AuthInputComponentProps, type AuthJsonResponse, type AuthLabelComponentProps, type AuthSignupField, type AuthSignupValues, type AuthValidationErrors, ChangePasswordForm, LoginForm, type Passkey, PasskeyLoginButton, PasskeySection, PasswordResetRequestForm, ResetPasswordForm, SignupForm, TwoFactorForm, arrayBufferToBase64url, authenticateWithPasskey, base64urlToArrayBuffer, getCsrfToken, getDefaultPasskeyName, isAbortError, isConditionalMediationAvailable, registerPasskey };
204
+ export { type AuthButtonComponent, type AuthButtonComponentInput, type AuthButtonComponentProps, type AuthButtonSize, type AuthButtonVariant, type AuthComponentInput, type AuthComponentOverrides, type AuthComponentSet, type AuthComponentSuperset, type AuthComponents, type AuthContainerComponentProps, type AuthEndpointConfig, type AuthInputComponentProps, type AuthJsonResponse, type AuthLabelComponentProps, type AuthSignupField, type AuthSignupValues, type AuthValidationErrors, ChangePasswordForm, LoginForm, type Passkey, PasskeyLoginButton, PasskeySection, PasswordResetRequestForm, type RelyingApplication, ResetPasswordForm, SignupForm, TwoFactorForm, arrayBufferToBase64url, authenticateWithPasskey, base64urlToArrayBuffer, getCsrfToken, getDefaultPasskeyName, isAbortError, isConditionalMediationAvailable, registerPasskey, relyingApplicationsFrom, safeApplicationHref };
package/dist/index.d.ts CHANGED
@@ -137,6 +137,44 @@ interface PasskeySectionProps {
137
137
  }
138
138
  declare function PasskeySection({ endpoints, components, onSuccess, onError }: PasskeySectionProps): react_jsx_runtime.JSX.Element;
139
139
 
140
+ /**
141
+ * The sibling applications an identity provider reports for the signed-in person.
142
+ *
143
+ * Every relying party receives this list the same way — server-side, injected per request
144
+ * from the session rather than compiled into a bundle — but each one carries it into the
145
+ * page differently: a `#app-initial-data` script tag, an Inertia shared prop, a Blade loop.
146
+ * What they cannot afford to do differently is decide which entries are safe to render, so
147
+ * that decision lives here and the transport stays the application's business.
148
+ */
149
+ interface RelyingApplication {
150
+ key: string;
151
+ name: string;
152
+ url: string;
153
+ }
154
+ /**
155
+ * Reduce a URL from the wire to one that is safe to put in an `href`, or reject it.
156
+ *
157
+ * These arrive as text in the page and end up as a link the browser will follow, so the
158
+ * scheme is what matters: `javascript:` and `data:` both pass a server-side URL validity
159
+ * check but execute rather than navigate. Parsing and allowing only http(s) is stronger
160
+ * than matching a prefix — it normalises away the leading control characters, mixed case,
161
+ * and escapes that a hand-rolled test can be walked past — and it returns the *parsed*
162
+ * form, so what gets rendered is exactly what was validated.
163
+ *
164
+ * Absolute URLs only, deliberately. These point at other origins; a relative one means the
165
+ * provider told us something unexpected, and guessing a base for it would be inventing a
166
+ * destination rather than validating one.
167
+ */
168
+ declare function safeApplicationHref(url: string): string | null;
169
+ /**
170
+ * Validate whatever the page handed over into a list that is safe to render.
171
+ *
172
+ * Unrecognised entries are dropped rather than throwing. This is navigation chrome: one
173
+ * malformed entry, or a provider that has grown a field, must not be able to take down the
174
+ * page it appears on. Anything that is not a well-formed list degrades to an empty menu.
175
+ */
176
+ declare function relyingApplicationsFrom(value: unknown): RelyingApplication[];
177
+
140
178
  declare function getCsrfToken(explicitToken?: string): string;
141
179
  declare function base64urlToArrayBuffer(b64: string): ArrayBuffer;
142
180
  declare function arrayBufferToBase64url(buffer: ArrayBuffer): string;
@@ -163,4 +201,4 @@ declare function isConditionalMediationAvailable(): Promise<boolean>;
163
201
  declare function authenticateWithPasskey({ endpoints, mediation, signal }?: AuthenticateWithPasskeyOptions): Promise<PasskeyAuthenticationResult>;
164
202
  declare function registerPasskey({ endpoints, name, signal }?: RegisterPasskeyOptions): Promise<PasskeyRegistrationResult>;
165
203
 
166
- export { type AuthButtonComponent, type AuthButtonComponentInput, type AuthButtonComponentProps, type AuthButtonSize, type AuthButtonVariant, type AuthComponentInput, type AuthComponentOverrides, type AuthComponentSet, type AuthComponentSuperset, type AuthComponents, type AuthContainerComponentProps, type AuthEndpointConfig, type AuthInputComponentProps, type AuthJsonResponse, type AuthLabelComponentProps, type AuthSignupField, type AuthSignupValues, type AuthValidationErrors, ChangePasswordForm, LoginForm, type Passkey, PasskeyLoginButton, PasskeySection, PasswordResetRequestForm, ResetPasswordForm, SignupForm, TwoFactorForm, arrayBufferToBase64url, authenticateWithPasskey, base64urlToArrayBuffer, getCsrfToken, getDefaultPasskeyName, isAbortError, isConditionalMediationAvailable, registerPasskey };
204
+ export { type AuthButtonComponent, type AuthButtonComponentInput, type AuthButtonComponentProps, type AuthButtonSize, type AuthButtonVariant, type AuthComponentInput, type AuthComponentOverrides, type AuthComponentSet, type AuthComponentSuperset, type AuthComponents, type AuthContainerComponentProps, type AuthEndpointConfig, type AuthInputComponentProps, type AuthJsonResponse, type AuthLabelComponentProps, type AuthSignupField, type AuthSignupValues, type AuthValidationErrors, ChangePasswordForm, LoginForm, type Passkey, PasskeyLoginButton, PasskeySection, PasswordResetRequestForm, type RelyingApplication, ResetPasswordForm, SignupForm, TwoFactorForm, arrayBufferToBase64url, authenticateWithPasskey, base64urlToArrayBuffer, getCsrfToken, getDefaultPasskeyName, isAbortError, isConditionalMediationAvailable, registerPasskey, relyingApplicationsFrom, safeApplicationHref };
package/dist/index.js CHANGED
@@ -780,6 +780,35 @@ function PasskeySection({ endpoints = {}, components, onSuccess, onError }) {
780
780
  ] })
781
781
  ] });
782
782
  }
783
+
784
+ // src/relying-applications.ts
785
+ function safeApplicationHref(url) {
786
+ try {
787
+ const parsed = new URL(url);
788
+ return parsed.protocol === "https:" || parsed.protocol === "http:" ? parsed.toString() : null;
789
+ } catch {
790
+ return null;
791
+ }
792
+ }
793
+ function relyingApplicationsFrom(value) {
794
+ if (!Array.isArray(value)) {
795
+ return [];
796
+ }
797
+ return value.flatMap((entry) => {
798
+ if (typeof entry !== "object" || entry === null) {
799
+ return [];
800
+ }
801
+ const { key, name, url } = entry;
802
+ if (typeof key !== "string" || typeof name !== "string" || typeof url !== "string") {
803
+ return [];
804
+ }
805
+ if (key === "" || name.trim() === "") {
806
+ return [];
807
+ }
808
+ const href = safeApplicationHref(url);
809
+ return href === null ? [] : [{ key, name: name.trim(), url: href }];
810
+ });
811
+ }
783
812
  export {
784
813
  ChangePasswordForm,
785
814
  LoginForm,
@@ -796,5 +825,7 @@ export {
796
825
  getDefaultPasskeyName,
797
826
  isAbortError,
798
827
  isConditionalMediationAvailable,
799
- registerPasskey
828
+ registerPasskey,
829
+ relyingApplicationsFrom,
830
+ safeApplicationHref
800
831
  };
package/package.json CHANGED
@@ -1,9 +1,18 @@
1
1
  {
2
2
  "name": "bwh-auth",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Shared React auth UI and browser WebAuthn helpers for BWH applications.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
+ "packageManager": "pnpm@11.12.0",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/bherila/auth-react.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/bherila/auth-react/issues"
14
+ },
15
+ "homepage": "https://github.com/bherila/auth-react#readme",
7
16
  "main": "./dist/index.cjs",
8
17
  "module": "./dist/index.js",
9
18
  "types": "./dist/index.d.ts",
@@ -18,23 +27,28 @@
18
27
  "require": "./dist/index.cjs"
19
28
  }
20
29
  },
30
+ "scripts": {
31
+ "build": "tsup src/index.ts --format esm,cjs --dts --dts-resolve",
32
+ "release": "node scripts/release.mjs",
33
+ "test": "vitest run",
34
+ "typecheck": "tsc --noEmit",
35
+ "prepare": "pnpm run build"
36
+ },
21
37
  "peerDependencies": {
22
38
  "lucide-react": ">=0.468.0 <2.0.0",
23
39
  "react": "^18.3.0 || ^19.0.0",
24
40
  "react-dom": "^18.3.0 || ^19.0.0"
25
41
  },
26
42
  "devDependencies": {
43
+ "@types/node": "^26.3.0",
27
44
  "@types/react": "^19.2.14",
28
45
  "@types/react-dom": "^19.2.3",
46
+ "esbuild": "0.28.2",
29
47
  "lucide-react": "^0.577.0",
30
48
  "react": "^19.2.6",
31
49
  "react-dom": "^19.2.6",
32
50
  "tsup": "^8.5.1",
33
- "typescript": "^5.9.3"
34
- },
35
- "scripts": {
36
- "build": "tsup src/index.ts --format esm,cjs --dts --dts-resolve",
37
- "release": "node scripts/release.mjs",
38
- "typecheck": "tsc --noEmit"
51
+ "typescript": "^5.9.3",
52
+ "vitest": "^3.2.7"
39
53
  }
40
- }
54
+ }