@molecule/app-auth-modal-svelte 0.0.0-stage → 1.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.
@@ -0,0 +1,54 @@
1
+ /**
2
+ * `@molecule/app-auth-modal-svelte` — the shared in-app login / signup /
3
+ * upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
4
+ * providers (where the `@molecule/app-svelte` auth hooks work) and every
5
+ * in-app `/login` / `/signup` link opens the {@link AuthModal} instead of
6
+ * navigating, while `/pricing` / `/billing` links open the upgrade flow in
7
+ * a new tab (session auto-refreshes when the user returns) — no
8
+ * navigation, no reload, no lost work. OAuth runs in a popup
9
+ * (`loginViaPopup`), so social login never navigates the host either.
10
+ *
11
+ * @example
12
+ * ```svelte
13
+ * <script lang="ts">
14
+ * import { AuthModalMount } from '@molecule/app-auth-modal-svelte'
15
+ * import { oauthConfig } from './config.js'
16
+ * </script>
17
+ *
18
+ * <!-- Once, inside the app's providers (e.g. in App.svelte): -->
19
+ * <AuthModalMount {oauthConfig} onAuthenticated={() => claimGuestWork()} />
20
+ * <!-- Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
21
+ * anywhere in the app is now intercepted — no other wiring needed. -->
22
+ * ```
23
+ *
24
+ * @remarks
25
+ * Interception is capture-phase on `document` and matches plain
26
+ * left-clicks on `<a href>` whose resolved pathname is in `authPaths`
27
+ * (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
28
+ * `/billing`) — modifier/middle clicks still navigate normally, and
29
+ * non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
30
+ * that render pricing in-place pass `onUpgradeIntercept` and own that UI
31
+ * + the post-upgrade session refresh. `AuthModalMount` must render inside
32
+ * the app's auth/HTTP providers (it calls `useAuth`), and the standalone
33
+ * `/login` & `/signup` pages should stay routed — they are the fallback
34
+ * for modifier clicks and deep links. App-specific extras (stash a guest
35
+ * id, claim guest work, invalidate usage) go in `onBeforeAuth` /
36
+ * `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
37
+ * `@molecule/app-locales-common` bond (79 languages), alongside the
38
+ * `auth.login.*` / `auth.signup.*` keys the modal also renders.
39
+ *
40
+ * If the signup API requires a human-verification challenge (Turnstile /
41
+ * hCaptcha), pass BOTH `captchaSlot` (the widget, rendered in the signup
42
+ * form, as a snippet or plain text) and `captchaSolved` (which gates the
43
+ * submit). Rendering the widget on the standalone `/signup` page alone is
44
+ * NOT enough: this modal is what a `/signup` link actually opens, so the
45
+ * in-app signup would POST with no token and the API would answer "complete
46
+ * the verification challenge" while no challenge is on screen. Login is not
47
+ * gated, so the slot is unmounted in login mode.
48
+ *
49
+ * @module
50
+ */
51
+ export * from './components.js';
52
+ export * from './cta-intercept.js';
53
+ export * from './types.js';
54
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * `@molecule/app-auth-modal-svelte` — the shared in-app login / signup /
3
+ * upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
4
+ * providers (where the `@molecule/app-svelte` auth hooks work) and every
5
+ * in-app `/login` / `/signup` link opens the {@link AuthModal} instead of
6
+ * navigating, while `/pricing` / `/billing` links open the upgrade flow in
7
+ * a new tab (session auto-refreshes when the user returns) — no
8
+ * navigation, no reload, no lost work. OAuth runs in a popup
9
+ * (`loginViaPopup`), so social login never navigates the host either.
10
+ *
11
+ * @example
12
+ * ```svelte
13
+ * <script lang="ts">
14
+ * import { AuthModalMount } from '@molecule/app-auth-modal-svelte'
15
+ * import { oauthConfig } from './config.js'
16
+ * </script>
17
+ *
18
+ * <!-- Once, inside the app's providers (e.g. in App.svelte): -->
19
+ * <AuthModalMount {oauthConfig} onAuthenticated={() => claimGuestWork()} />
20
+ * <!-- Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
21
+ * anywhere in the app is now intercepted — no other wiring needed. -->
22
+ * ```
23
+ *
24
+ * @remarks
25
+ * Interception is capture-phase on `document` and matches plain
26
+ * left-clicks on `<a href>` whose resolved pathname is in `authPaths`
27
+ * (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
28
+ * `/billing`) — modifier/middle clicks still navigate normally, and
29
+ * non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
30
+ * that render pricing in-place pass `onUpgradeIntercept` and own that UI
31
+ * + the post-upgrade session refresh. `AuthModalMount` must render inside
32
+ * the app's auth/HTTP providers (it calls `useAuth`), and the standalone
33
+ * `/login` & `/signup` pages should stay routed — they are the fallback
34
+ * for modifier clicks and deep links. App-specific extras (stash a guest
35
+ * id, claim guest work, invalidate usage) go in `onBeforeAuth` /
36
+ * `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
37
+ * `@molecule/app-locales-common` bond (79 languages), alongside the
38
+ * `auth.login.*` / `auth.signup.*` keys the modal also renders.
39
+ *
40
+ * If the signup API requires a human-verification challenge (Turnstile /
41
+ * hCaptcha), pass BOTH `captchaSlot` (the widget, rendered in the signup
42
+ * form, as a snippet or plain text) and `captchaSolved` (which gates the
43
+ * submit). Rendering the widget on the standalone `/signup` page alone is
44
+ * NOT enough: this modal is what a `/signup` link actually opens, so the
45
+ * in-app signup would POST with no token and the API would answer "complete
46
+ * the verification challenge" while no challenge is on screen. Login is not
47
+ * gated, so the slot is unmounted in login mode.
48
+ *
49
+ * @module
50
+ */
51
+ export * from './components.js';
52
+ export * from './cta-intercept.js';
53
+ export * from './types.js';
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Types for the Svelte in-app auth modal + the one-mount interceptor.
3
+ *
4
+ * @module
5
+ */
6
+ import type { Snippet } from 'svelte';
7
+ import type { UseOAuthConfig } from '@molecule/app-svelte';
8
+ import type { AuthModalMode } from './cta-intercept.js';
9
+ /**
10
+ * A React-node-valued field: a snippet (the conformance kit's node value), or
11
+ * plain text passed verbatim.
12
+ */
13
+ type ReactNodeProp = Snippet | string;
14
+ /** Props accepted by the {@link AuthModal} component. */
15
+ export interface AuthModalProps {
16
+ /** Whether the modal is open. */
17
+ open: boolean;
18
+ /** Close without authenticating (backdrop / Escape / ✕). */
19
+ onClose?: () => void;
20
+ /** Which form to open on. Defaults to `'signup'`. */
21
+ initialMode?: AuthModalMode;
22
+ /**
23
+ * OAuth config consumed by `useOAuth()` — `{ baseURL, oauthProviders, oauthEndpoint }`
24
+ * from the app's `config.ts`. Drives the popup OAuth buttons.
25
+ */
26
+ oauthConfig: UseOAuthConfig;
27
+ /**
28
+ * Run synchronously BEFORE any login/signup/OAuth attempt — e.g. stash the
29
+ * guest id so the new session can claim its work. Optional.
30
+ */
31
+ onBeforeAuth?: () => void;
32
+ /**
33
+ * Run AFTER a successful login/signup/OAuth (the session is already
34
+ * refreshed), still on the same page — e.g. claim guest projects, invalidate
35
+ * usage. Optional.
36
+ */
37
+ onAuthenticated?: () => void | Promise<void>;
38
+ /**
39
+ * A human-verification challenge rendered inside the SIGNUP form, above the
40
+ * submit button (e.g. the app's Turnstile/hCaptcha widget), as a snippet or
41
+ * plain text. Login is not gated, so the slot is unmounted in login mode —
42
+ * which lets the widget clear its own token when the user switches tabs and
43
+ * re-issue a fresh one on the way back.
44
+ *
45
+ * The modal stays provider-agnostic: it renders the node and never inspects
46
+ * it. An app whose signup API requires a challenge MUST pass `captchaSolved`
47
+ * as well, or the form will submit without a token and the API will reject
48
+ * it. Optional — omitted (the default for apps with no challenge) the signup
49
+ * form is unchanged.
50
+ */
51
+ captchaSlot?: ReactNodeProp;
52
+ /**
53
+ * Whether the `captchaSlot` challenge is currently solved. `false` disables
54
+ * the signup submit, so the form cannot POST a missing/expired token.
55
+ * Defaults to `true` (no challenge → nothing to wait for). Ignored in login
56
+ * mode.
57
+ */
58
+ captchaSolved?: boolean;
59
+ }
60
+ /** Props accepted by the {@link AuthModalMount} component. */
61
+ export interface AuthModalMountProps {
62
+ /** OAuth config from the app's `config.ts` (drives the popup OAuth buttons). */
63
+ oauthConfig: AuthModalProps['oauthConfig'];
64
+ /** Run before any login attempt (e.g. stash the guest id). Optional. */
65
+ onBeforeAuth?: () => void;
66
+ /** Run after a successful login (session already refreshed). Optional. */
67
+ onAuthenticated?: () => void | Promise<void>;
68
+ /**
69
+ * Run when the user returns to this tab after the upgrade tab (the session
70
+ * is already refreshed here) — e.g. invalidate usage so a budget banner
71
+ * clears. Only fires for the default new-tab flow; irrelevant when
72
+ * `onUpgradeIntercept` is set. Optional.
73
+ */
74
+ onUpgradeReturn?: () => void;
75
+ /**
76
+ * Take over upgrade/billing CTA clicks instead of opening a new tab: called
77
+ * with the matched upgrade path (e.g. `/pricing`), navigation already
78
+ * prevented. The host renders its own upgrade UI (typically a modal) and
79
+ * owns refreshing the session when that flow completes. Optional — when
80
+ * omitted, the default new-tab flow (+ focus-return refresh) applies.
81
+ */
82
+ onUpgradeIntercept?: (path: string) => void;
83
+ /**
84
+ * Human-verification challenge rendered inside the modal's SIGNUP form — see
85
+ * `AuthModalProps.captchaSlot`. Pass it together with `captchaSolved`
86
+ * whenever the app's signup API requires a challenge token, otherwise the
87
+ * in-app signup POSTs without one while the standalone `/signup` page (which
88
+ * renders its own widget) works — a mismatch the user experiences as
89
+ * "complete the challenge" with no challenge on screen. Optional.
90
+ */
91
+ captchaSlot?: AuthModalProps['captchaSlot'];
92
+ /** Whether `captchaSlot` is solved; `false` disables the signup submit. Defaults to `true`. */
93
+ captchaSolved?: boolean;
94
+ /** Override the auth path→mode map (defaults to `/login`,`/signup`). */
95
+ authPaths?: Readonly<Record<string, AuthModalMode>>;
96
+ /** Override the upgrade paths opened in a new tab (defaults to `/pricing`,`/billing`). */
97
+ upgradePaths?: readonly string[];
98
+ }
99
+ export {};
100
+ //# sourceM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I,CAAA;IAC3C;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,CAAA;IAC3C,+FAA+F;IAC/F,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,wEAAwE;IACxE,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAA;IACnD,0FAA0F;IAC1F,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACjC"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Types for the Svelte in-app auth modal + the one-mount interceptor.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Svelte action reproducing react-dom's controlled-input `value` handling.
3
+ *
4
+ * Svelte's `value={x}` sets only the `value` property, while a React input
5
+ * carries BOTH the property and the `value` attribute (react-dom applies the
6
+ * value through the `defaultValue` property, whose reflection IS that
7
+ * attribute). The other framework ports get this for free, and
8
+ * `@molecule/app-ui-svelte` ships the same logic for its own `Input`
9
+ * (`reactInputValue` in its `src/dom.ts`, not exported) — the same copy
10
+ * `@molecule/app-amount-input-svelte` and `@molecule/app-copy-link-field-svelte`
11
+ * carry. This action applies React's documented behavior: the property, then
12
+ * the attribute, on mount and on every value change.
13
+ *
14
+ * @module
15
+ */
16
+ /**
17
+ * Applies `props.value` to the input the way react-dom applies a controlled
18
+ * `value`: through the `value` property (the live value) and the `value`
19
+ * attribute, so both reads of the field agree.
20
+ *
21
+ * @param node - The input element.
22
+ * @param props - The controlled value, as React's `<input value>` takes it.
23
+ * @returns The action's update, re-applying on a changed value.
24
+ */
25
+ export declare function reactInputValue(node: HTMLInputElement, props: {
26
+ value?: unknown;
27
+ }): {
28
+ update: (next: {
29
+ value?: unknown;
30
+ }) => void;
31
+ };
32
+ //# sourceMappingURL=value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,gBAAgB,EACtB,KAAK,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACzB;IAAE,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAA;CAAE,CASjD"}
package/dist/value.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Svelte action reproducing react-dom's controlled-input `value` handling.
3
+ *
4
+ * Svelte's `value={x}` sets only the `value` property, while a React input
5
+ * carries BOTH the property and the `value` attribute (react-dom applies the
6
+ * value through the `defaultValue` property, whose reflection IS that
7
+ * attribute). The other framework ports get this for free, and
8
+ * `@molecule/app-ui-svelte` ships the same logic for its own `Input`
9
+ * (`reactInputValue` in its `src/dom.ts`, not exported) — the same copy
10
+ * `@molecule/app-amount-input-svelte` and `@molecule/app-copy-link-field-svelte`
11
+ * carry. This action applies React's documented behavior: the property, then
12
+ * the attribute, on mount and on every value change.
13
+ *
14
+ * @module
15
+ */
16
+ /**
17
+ * Applies `props.value` to the input the way react-dom applies a controlled
18
+ * `value`: through the `value` property (the live value) and the `value`
19
+ * attribute, so both reads of the field agree.
20
+ *
21
+ * @param node - The input element.
22
+ * @param props - The controlled value, as React's `<input value>` takes it.
23
+ * @returns The action's update, re-applying on a changed value.
24
+ */
25
+ export function reactInputValue(node, props) {
26
+ const apply = (next) => {
27
+ const { value } = next;
28
+ const text = value === undefined || value === null ? '' : String(value);
29
+ if (node.value !== text)
30
+ node.value = text;
31
+ if (node.getAttribute('value') !== text)
32
+ node.setAttribute('value', text);
33
+ };
34
+ apply(props);
35
+ return { update: apply };
36
+ }
package/package.json CHANGED
@@ -1,6 +1,82 @@
1
1
  {
2
2
  "name": "@molecule/app-auth-modal-svelte",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "In-app login / signup modal + click-interceptor + popup OAuth — authenticate and upgrade without ever navigating away or losing work",
5
+ "homepage": "https://www.molecule.dev/packages/app-auth-modal-svelte",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "svelte": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "svelte": "./dist/index.js",
18
+ "files": [
19
+ "dist",
20
+ "!dist/**/__tests__",
21
+ "!dist/**/*.test.*",
22
+ "!dist/**/*.spec.*",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "svelte-check --tsconfig ./tsconfig.json --fail-on-warnings && svelte-package --input src --output dist --tsconfig ./tsconfig.json",
27
+ "dev": "svelte-package --input src --output dist --tsconfig ./tsconfig.json --watch",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest"
30
+ },
31
+ "keywords": [
32
+ "molecule",
33
+ "auth",
34
+ "login",
35
+ "signup",
36
+ "modal",
37
+ "oauth",
38
+ "svelte"
39
+ ],
40
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
41
+ "license": "Apache-2.0",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/molecule-dev/molecule.git",
45
+ "directory": "packages/app/features/auth-modal-svelte"
46
+ },
47
+ "engines": {
48
+ "node": ">=20"
49
+ },
50
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "peerDependencies": {
55
+ "@molecule/app-auth-shell-svelte": "^1.0.0",
56
+ "@molecule/app-i18n": "^1.0.1",
57
+ "@molecule/app-oauth-buttons-svelte": "^1.0.0",
58
+ "@molecule/app-svelte": "^3.5.0",
59
+ "@molecule/app-ui": "^1.0.1",
60
+ "@molecule/app-ui-svelte": "^1.1.0",
61
+ "svelte": "^5.0.0"
62
+ },
63
+ "devDependencies": {
64
+ "@molecule/app-auth-shell-svelte": "1.1.0",
65
+ "@molecule/app-framework-conformance": "0.0.0",
66
+ "@molecule/app-i18n": "1.2.2",
67
+ "@molecule/app-icons": "1.0.4",
68
+ "@molecule/app-oauth-buttons-svelte": "1.2.0",
69
+ "@molecule/app-svelte": "3.9.0",
70
+ "@molecule/app-ui": "1.5.0",
71
+ "@molecule/app-ui-svelte": "1.2.1",
72
+ "@sveltejs/package": "3.0.2",
73
+ "@sveltejs/vite-plugin-svelte": "7.1.2",
74
+ "@types/node": "26.6.5",
75
+ "jsdom": "30.1.3",
76
+ "svelte": "5.57.2",
77
+ "svelte-check": "4.7.7",
78
+ "typescript": "6.0.3",
79
+ "vite": "8.3.5",
80
+ "vitest": "4.1.12"
81
+ }
82
+ }