@pontive/pontkit-core 1.39.0 → 1.41.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.
Files changed (66) hide show
  1. package/catalog.json +1 -1
  2. package/custom-elements.json +1 -1
  3. package/dist/index.js +1846 -1289
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +17059 -12690
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/pont2/core/context-root.d.ts +1 -0
  8. package/dist/pont2/core/events.d.ts +1 -1
  9. package/dist/pont2/core/format.d.ts +46 -0
  10. package/dist/pont2/core/icons.d.ts +11 -0
  11. package/dist/pont2/core/index.d.ts +2 -0
  12. package/dist/pont2/core/messages.d.ts +128 -2
  13. package/dist/pont2/core/popup/index.d.ts +1 -0
  14. package/dist/pont2/core/popup/modal.d.ts +56 -0
  15. package/dist/pont2/core/popup/popup-content.d.ts +7 -0
  16. package/dist/pont2/core/popup/story-helpers.d.ts +6 -0
  17. package/dist/pont2/custom-elements.json +55405 -24958
  18. package/dist/pont2/index.d.ts +7 -0
  19. package/dist/pont2/index.mjs +6600 -2376
  20. package/dist/pont2/index.mjs.map +1 -1
  21. package/dist/pont2/kit/account-menu/account-menu.d.ts +115 -0
  22. package/dist/pont2/kit/account-settings/account-settings.d.ts +157 -0
  23. package/dist/pont2/kit/account-settings/profile.d.ts +74 -0
  24. package/dist/pont2/kit/badge-selector/badge-selector.d.ts +65 -0
  25. package/dist/pont2/kit/consent/consent.d.ts +3 -2
  26. package/dist/pont2/kit/data-table/data-table.d.ts +120 -0
  27. package/dist/pont2/kit/data-table/rows.d.ts +25 -0
  28. package/dist/pont2/kit/flow-widget/flow-widget.d.ts +21 -8
  29. package/dist/pont2/kit/index.d.ts +11 -0
  30. package/dist/pont2/kit/layout/layout.d.ts +7 -0
  31. package/dist/pont2/kit/member-management/errors.d.ts +60 -0
  32. package/dist/pont2/kit/member-management/member-management.d.ts +237 -0
  33. package/dist/pont2/kit/member-management/roles.d.ts +42 -0
  34. package/dist/pont2/kit/multi-email-input/emails.d.ts +19 -0
  35. package/dist/pont2/kit/multi-email-input/multi-email-input.d.ts +78 -0
  36. package/dist/pont2/kit/multi-select-filter/multi-select-filter.d.ts +53 -0
  37. package/dist/pont2/kit/organization-switcher/organization-switcher.d.ts +111 -0
  38. package/dist/pont2/kit/pagination/pagination.d.ts +61 -0
  39. package/dist/pont2/kit/pagination/range.d.ts +17 -0
  40. package/dist/pont2/kit/provider/account-client.d.ts +355 -0
  41. package/dist/pont2/kit/provider/account-controller.d.ts +47 -0
  42. package/dist/pont2/kit/provider/account-user.d.ts +16 -0
  43. package/dist/pont2/kit/provider/coexistence.d.ts +19 -0
  44. package/dist/pont2/kit/provider/contexts.d.ts +46 -0
  45. package/dist/pont2/kit/provider/provider.d.ts +219 -0
  46. package/dist/pont2/kit/provider/redirect.d.ts +122 -0
  47. package/dist/pont2/kit/provider/runtime-config.d.ts +24 -0
  48. package/dist/pont2/kit/provider/sdk.d.ts +100 -0
  49. package/dist/pont2/kit/provider/signed-in.d.ts +81 -0
  50. package/dist/pont2/kit/provider/widget-messages.d.ts +35 -0
  51. package/dist/pont2/primitives/alert-dialog/alert-dialog.d.ts +132 -0
  52. package/dist/pont2/primitives/combobox/combobox.d.ts +82 -14
  53. package/dist/pont2/primitives/dialog/dialog.d.ts +195 -0
  54. package/dist/pont2/primitives/drawer/drawer.d.ts +112 -0
  55. package/dist/pont2/primitives/hover-card/hover-card.d.ts +83 -0
  56. package/dist/pont2/primitives/pagination/pagination.d.ts +120 -0
  57. package/dist/pont2/primitives/sheet/sheet.d.ts +92 -0
  58. package/dist/pont2/primitives/sonner/sonner.d.ts +86 -0
  59. package/dist/pont2/primitives/sonner/toast-store.d.ts +81 -0
  60. package/dist/pont2/styles.css +2489 -760
  61. package/dist/pont2/theme/tokens.json.d.ts +700 -1
  62. package/dist/pont2/theme-golden.json +45 -45
  63. package/dist/pont2/theme.mjs +119 -119
  64. package/dist/pont2/tokens.json +700 -1
  65. package/dist/styles.css +2475 -746
  66. package/package.json +2 -2
@@ -0,0 +1,219 @@
1
+ import { PropertyDeclarations, PropertyValues } from 'lit';
2
+ import { HostElement } from '../../core/host-element';
3
+ import { AccountClient } from './account-client';
4
+ import { AuthState } from './contexts';
5
+ import { AppSdkConfig, ProviderSdk } from './sdk';
6
+ export * from './account-client';
7
+ export * from './account-controller';
8
+ export * from './account-user';
9
+ export * from './contexts';
10
+ export * from './coexistence';
11
+ export * from './redirect';
12
+ export * from './sdk';
13
+ export * from './widget-messages';
14
+ /** Detail of `pont2-set-locales` (on `document`) and `pont2-locale-changed`. */
15
+ export interface LocalesDetail {
16
+ locales: string;
17
+ }
18
+ /** Detail of `pont2-redirect`. Cancel it to navigate yourself (a client-side router). */
19
+ export interface RedirectDetail {
20
+ url: string;
21
+ }
22
+ /**
23
+ * # `<pont2-provider>`: configures the auth SDK and provides it to the page
24
+ *
25
+ * ```html
26
+ * <pont2-provider app-id="app_123" domain="auth.acme.com" signin-url="/sign-in" signup-url="/sign-up">
27
+ * <pont2-signed-out><pont2-signin></pont2-signin></pont2-signed-out>
28
+ * <pont2-signed-in>…the app…</pont2-signed-in>
29
+ * </pont2-provider>
30
+ * <script type="module">
31
+ * import { Auth } from "@pontive/oidc-client";
32
+ * document.querySelector("pont2-provider").sdk = Auth; // the one line pont2 can't do for you
33
+ * </script>
34
+ * ```
35
+ *
36
+ * pont2's version of the legacy `pont-provider` (docs/13-provider.md; migration
37
+ * tracker W-1). The SDK is **injected**, never imported. Once it has `sdk`,
38
+ * `domain` and `app-id`, it:
39
+ *
40
+ * - **configures the SDK** (`sdk.configure(…)`), again whenever an input
41
+ * changes. `configure()` replaces the whole configuration, so the app's own
42
+ * options and callbacks go in `config` and are **chained** after the
43
+ * provider's (W-14);
44
+ * - **provides the SDK** to every flow widget inside it as their `client`
45
+ * (`pont2:client`; an explicit `widget.client` wins), with the branding
46
+ * entitlements (`pont2:branding`) and the URL's `login_hint`
47
+ * (`pont2:login-hint`, F-11);
48
+ * - **resolves the auth state**: `restoreSession()`, then `isAuthenticated()`,
49
+ * provided as `pont2:auth` (read by `pont2-signed-in` / `-out`), readable as
50
+ * `.auth`, and announced as `pont2-auth-changed`. A page opened to answer an
51
+ * invitation drops the existing session first;
52
+ * - **redirects** a signed-in user away from the sign-in, sign-up or invitation
53
+ * page (`auto-redirect`, on by default), with the legacy destination rules
54
+ * and redirect-loop protection (`redirect.ts`);
55
+ * - **follows the locale**: `locales`, `setLocale()` or a `pont2-set-locales`
56
+ * event on `document` reconfigure the SDK, fire `pont2-locale-changed` and
57
+ * `restart()` every flow widget it provides for (F-19);
58
+ * - **loads the widgets' own text** (`/auth/v1/widget-messages`, one request
59
+ * per language per page, I-2) and the published **theme**
60
+ * (`/auth/v1/theme.css`; `theme="none"` opts out);
61
+ * - **provides the account widgets' client** (`pont2:account-client`, W-12):
62
+ * `accountClient` when the app gives one, else one built from the SDK and
63
+ * `api-base-url` (`createAccountClient`) once the SDK is configured;
64
+ * - **reads the branding entitlements** from `/auth/v1/runtime-config`, the
65
+ * server's answer from the workspace's plan. There is deliberately no
66
+ * property for them: an app cannot switch the watermark off, and anything
67
+ * but the server saying so keeps it (docs/branding-entitlements.md, T-5).
68
+ *
69
+ * The host adds no box (`display: contents`). Mount **one** provider per page,
70
+ * and never beside the legacy `pont-provider`: both drive the one `Auth` (W-15).
71
+ *
72
+ * @tag pont2-provider
73
+ * @prop sdk - the auth SDK (`Auth` from `@pontive/oidc-client`), injected
74
+ * @prop config - the app's own SDK options and callbacks (`onFlowStateChange`, `onAuthenticated`), chained after the provider's
75
+ * @prop headers - extra request headers for the SDK (and the account client's management requests)
76
+ * @prop accountClient - the app's own `AccountClient` for the account widgets (default: one built from `sdk` and `api-base-url`)
77
+ * @prop auth - `AuthState` (read-only): `{ isAuthenticated, resolved }`
78
+ * @attr app-id - the app's id
79
+ * @attr domain - where the auth endpoints answer: a hostname, `/path` on this origin, or a base URL
80
+ * @attr locales - space-separated BCP-47 tags in preference order; empty lets the server negotiate
81
+ * @attr signin-url - the app's sign-in page path
82
+ * @attr signup-url - the app's sign-up page path
83
+ * @attr invitation-url - the app's invitation page path, when it has one
84
+ * @attr signin-redirect-url - where a signed-in user goes from those pages (http(s))
85
+ * @attr continue-here-url - where "Continue here instead" goes (default: `signin-redirect-url`)
86
+ * @attr scope - OAuth scopes every flow asks for (space-separated; replaces the server's default)
87
+ * @attr organization-id - the organization a sign-in starts in
88
+ * @attr api-base-url - the management gateway (`https://api.us.pontive.com`), which the account client calls (not an SDK option)
89
+ * @attr login-hint - the identifier to pre-fill (default: the URL's `login_hint`)
90
+ * @attr auto-redirect - `"false"` turns the post-sign-in redirect off (default on)
91
+ * @attr theme - `"none"` opts out of linking the published theme (default: link it)
92
+ * @fires pont2-auth-changed - `AuthState` (a copy), whenever it changes
93
+ * @fires pont2-locale-changed - `{ locales }`, whenever the configured locales change
94
+ * @fires pont2-session-changed - `{ reason, source, isAuthenticated, organizationId }`, on every SDK session change, here or in another tab (no tokens)
95
+ * @fires pont2-redirect - `{ url }`, cancelable, before a post-sign-in navigation
96
+ */
97
+ export declare class Provider extends HostElement {
98
+ static identity: string;
99
+ static slotName: string;
100
+ static composite: boolean;
101
+ static properties: PropertyDeclarations;
102
+ sdk: ProviderSdk | undefined;
103
+ config: AppSdkConfig;
104
+ headers: Record<string, string> | undefined;
105
+ /** The app's own account client; wins over the default one. */
106
+ accountClient: AccountClient | undefined;
107
+ appId: string;
108
+ domain: string;
109
+ locales: string;
110
+ signinUrl: string;
111
+ signupUrl: string;
112
+ invitationUrl: string;
113
+ signinRedirectUrl: string;
114
+ continueHereUrl: string;
115
+ scope: string | string[];
116
+ organizationId: string;
117
+ apiBaseUrl: string;
118
+ loginHint: string | undefined;
119
+ autoRedirect: boolean;
120
+ theme: string;
121
+ /** The auth state (read it; the provider writes it). */
122
+ auth: AuthState;
123
+ private authProvider;
124
+ private clientProvider;
125
+ private brandingProvider;
126
+ private hintProvider;
127
+ private accountProvider;
128
+ /** The default account client, built once the SDK is configured (undefined before, or without account methods). */
129
+ private defaultAccountClient;
130
+ private accountInputs;
131
+ /** The SDK the auth state was last resolved for: a new one resolves again. */
132
+ private resolvedFor;
133
+ /** The locales of the last configuration (`undefined`: not configured yet). */
134
+ private configuredLocales;
135
+ /** Ends the SDK session subscription, while there is one. */
136
+ private unsubscribeSession;
137
+ /** The auth base the branding entitlements were last asked for. */
138
+ private brandingBase;
139
+ /** Bumped per resolution, so only the latest answer is published. */
140
+ private authSeq;
141
+ constructor();
142
+ /** Changes the language: reconfigures the SDK and restarts the flow widgets it provides for. */
143
+ setLocale(locales: string): void;
144
+ /**
145
+ * Reads the auth state from the SDK again (a local check). With
146
+ * `@pontive/oidc-client` 1.7.0 or later the provider follows every session
147
+ * change by itself (`onSessionChange`, W-14), so this is only needed with an
148
+ * SDK that can't tell it.
149
+ */
150
+ refresh(): void;
151
+ /** The base the auth endpoints hang off, or `null` while `domain` is unset or invalid. */
152
+ get authBaseUrl(): string | null;
153
+ connectedCallback(): void;
154
+ disconnectedCallback(): void;
155
+ protected willUpdate(changed: PropertyValues): void;
156
+ protected updated(changed: PropertyValues): void;
157
+ private inputs;
158
+ /** The account client the widgets get: the app's, else the default one over the configured SDK. */
159
+ get effectiveAccountClient(): AccountClient | undefined;
160
+ /**
161
+ * Builds the default account client (W-12) once the SDK is configured, and again when the
162
+ * SDK, `api-base-url`, `app-id` or `headers` change. Before configuration it stays undefined,
163
+ * so no widget asks an unconfigured SDK who is signed in.
164
+ */
165
+ private provideAccountClient;
166
+ private configureSdk;
167
+ /** Every flow widget inside that runs on the provided client (an explicit `client` is the app's). */
168
+ private restartWidgets;
169
+ private onSetLocales;
170
+ /**
171
+ * Asks the authorization server whether this browser is signed in before
172
+ * publishing an answer: an app whose refresh token is an HttpOnly cookie holds
173
+ * nothing locally on a fresh page, so the local answer alone reports every
174
+ * reload as a sign-out. Publishing "signed out" first and correcting it a
175
+ * moment later would flash the signed-out branch for every signed-in user.
176
+ *
177
+ * A page opened with an invitation drops whoever was signed in first: the
178
+ * invitation is for the invitee, and restoring another session would send the
179
+ * page on to the app before the flow ran.
180
+ */
181
+ private resolveAuth;
182
+ private publishAuth;
183
+ /**
184
+ * Follows the SDK's session changes (W-14): a sign-in, refresh, organization
185
+ * switch, sign-out or expiry, here or in another tab of the app, republishes
186
+ * the auth state and is re-announced as `pont2-session-changed` (with the
187
+ * SDK's `reason`, `source` and `organizationId`; no tokens), so the app can,
188
+ * for example, reload its data after an organization switch made elsewhere.
189
+ */
190
+ private subscribeToSession;
191
+ /**
192
+ * The fallback for an SDK without `onSessionChange` (before
193
+ * `@pontive/oidc-client` 1.7.0): when the tab comes back and the local answer
194
+ * has turned to "signed out", ask the server again (a refresh cookie may
195
+ * still hold) before publishing it.
196
+ */
197
+ private onVisible;
198
+ private redirectIfDone;
199
+ /**
200
+ * Links the instance's published theme (`GET {auth}/auth/v1/theme.css`: the
201
+ * host names the instance; an empty 200 when nothing is published;
202
+ * docs/12-theming-integration.md). The same `<link data-pont2-theme="brand">`
203
+ * that `linkTheme()` writes, so the two never stack.
204
+ */
205
+ private linkTheme;
206
+ }
207
+ declare global {
208
+ interface HTMLElementTagNameMap {
209
+ "pont2-provider": Provider;
210
+ }
211
+ interface HTMLElementEventMap {
212
+ "pont2-auth-changed": CustomEvent<AuthState>;
213
+ "pont2-locale-changed": CustomEvent<LocalesDetail>;
214
+ "pont2-redirect": CustomEvent<RedirectDetail>;
215
+ }
216
+ interface DocumentEventMap {
217
+ "pont2-set-locales": CustomEvent<LocalesDetail>;
218
+ }
219
+ }
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Where `<pont2-provider>` sends the browser once someone is signed in, and how
3
+ * it notices that the destination sent them straight back.
4
+ *
5
+ * A port of the legacy rules (`src/utils/post-auth-destination.ts` and the
6
+ * provider's `wasBouncedBackFrom`), as pure functions with injected browser
7
+ * state so they are unit-tested in Node. pont2 may not import `src/`
8
+ * (guardrail), so the code is copied, with its tests (docs/13-provider.md §3).
9
+ *
10
+ * **One change from the legacy kit (a security fix).** The legacy provider
11
+ * assigned `?redirect_url=` to `window.location` unchecked, so a link could send
12
+ * a freshly signed-in user to `javascript:` or to any site (hosted login strips
13
+ * the parameter for that reason). Here the query's `redirect_url` is honoured
14
+ * only when it is on the page's own origin, and the configured
15
+ * `signinRedirectUrl` only when it is http(s). Anything else is ignored, as if
16
+ * it had not been given.
17
+ */
18
+ /** The configuration the destination depends on. */
19
+ export interface PostAuthEnv {
20
+ signinUrl?: string;
21
+ signupUrl?: string;
22
+ invitationUrl?: string;
23
+ signinRedirectUrl?: string;
24
+ }
25
+ export interface PostAuthPage {
26
+ /** The page's path, e.g. `location.pathname`. */
27
+ pathname: string;
28
+ /** The page's query, e.g. `location.search`. */
29
+ search: string;
30
+ /** The page's origin, e.g. `location.origin`. Relative targets resolve against it. */
31
+ origin: string;
32
+ env: PostAuthEnv;
33
+ }
34
+ /**
35
+ * Where to send the browser once a flow has authenticated someone, or `null`
36
+ * to stay put.
37
+ *
38
+ * - On the sign-in, sign-up or invitation page: to the target, else `/`.
39
+ * - On any other page opened to answer an invitation (`?invite_token=`): to the
40
+ * target if there is one. Without one, staying put is better than sending the
41
+ * app's own page to `/`.
42
+ * - Anywhere else: nowhere. The app decides.
43
+ *
44
+ * The target is the query's `redirect_url` (same origin only), else
45
+ * `env.signinRedirectUrl` (http(s) only).
46
+ */
47
+ export declare function postAuthDestination({ pathname, search, origin, env }: PostAuthPage): string | null;
48
+ /**
49
+ * Whether the page was opened to answer an invitation: its query carries the
50
+ * token an invitation link does. Any page mounting a widget can be one.
51
+ */
52
+ export declare function answersInvitation(search: string): boolean;
53
+ /**
54
+ * The identifier the page was opened with as OpenID Connect's `login_hint`, or
55
+ * `undefined`. `/oauth2/authorize` forwards an app's hint to the hosted pages,
56
+ * and an accepted invitation sends the invitee to the app's sign-in page with
57
+ * the address it was sent to. It only pre-fills: nothing is trusted because of
58
+ * it (legacy `src/utils/login-hint.ts`, ported; migration tracker F-11).
59
+ */
60
+ export declare function loginHint(search: string | undefined): string | undefined;
61
+ /**
62
+ * The browser state the loop protection reads, injectable for tests.
63
+ *
64
+ * - `storage`: sessionStorage, not localStorage. A redirect is one navigation
65
+ * in one tab: the marker must not outlive the tab, nor be seen by a second tab
66
+ * signing in on its own.
67
+ * - `navigationType`: how the browser reached this page (Navigation Timing).
68
+ */
69
+ export interface RedirectGuardEnv {
70
+ storage: Pick<Storage, "getItem" | "setItem" | "removeItem"> | null;
71
+ now: () => number;
72
+ navigationType: () => string;
73
+ }
74
+ /** The marker's key. Not the legacy kit's: the two providers never share a page (W-15). */
75
+ export declare const REDIRECT_ATTEMPT_KEY = "pont2_auth_redirect_attempt";
76
+ /**
77
+ * How recently a redirect must have been attempted for a return to count as a
78
+ * bounce. A bounce is two server round trips, so seconds at most; minutes later
79
+ * is a new visit.
80
+ */
81
+ export declare const REDIRECT_BOUNCE_WINDOW_MS = 10000;
82
+ /** The page's own browser state (sessionStorage, Date.now, Navigation Timing). */
83
+ export declare function browserGuardEnv(): RedirectGuardEnv;
84
+ /** Notes that the browser is being sent to `target`. */
85
+ export declare function recordRedirectAttempt(target: string, env: RedirectGuardEnv): void;
86
+ /** Forgets the marker. */
87
+ export declare function clearRedirectAttempt(env: RedirectGuardEnv): void;
88
+ /**
89
+ * Whether we are here because `target` sent us back. Three things must hold,
90
+ * each ruling out an arrival that looks like a bounce but isn't:
91
+ *
92
+ * - a redirect to **this** target was recorded;
93
+ * - it was **recent** (within `REDIRECT_BOUNCE_WINDOW_MS`);
94
+ * - the browser **navigated** here. Back (`back_forward`) or a reload right
95
+ * after a successful sign-in leaves the same marker, and signing that user out
96
+ * would be worse than the loop. A server redirect chain is always `navigate`.
97
+ *
98
+ * The marker is consumed either way, so a stale one can't go on counting.
99
+ */
100
+ export declare function wasBouncedBackFrom(target: string, env: RedirectGuardEnv): boolean;
101
+ /** What the provider does about a signed-in user on this page. */
102
+ export type RedirectDecision = {
103
+ kind: "stay";
104
+ }
105
+ /** The destination refused the session and sent us back: drop it and show the sign-in form. */
106
+ | {
107
+ kind: "bounced";
108
+ target: string;
109
+ } | {
110
+ kind: "go";
111
+ target: string;
112
+ };
113
+ /**
114
+ * The whole post-sign-in decision. `isAuthenticated()` is a local check (memory
115
+ * and an expiry time), while the destination decides the same question with the
116
+ * server's knowledge (a revoked session, `prompt=login`). When they disagree,
117
+ * redirecting on the local answer is an infinite loop, so the server wins:
118
+ * `bounced` means drop the stale session and let the sign-in form render.
119
+ *
120
+ * A `go` decision has already recorded its attempt.
121
+ */
122
+ export declare function decideRedirect(page: PostAuthPage, guard: RedirectGuardEnv): RedirectDecision;
@@ -0,0 +1,24 @@
1
+ import { BrandingEntitlements } from '../block/branding';
2
+ /**
3
+ * The instance's branding entitlements, read by `<pont2-provider>` from
4
+ * `GET {auth}/auth/v1/runtime-config` (`branding: { show_watermark }`, pontive-spec
5
+ * 21 §9.1, 18 "Branding entitlement"; migration tracker T-5).
6
+ *
7
+ * The answer is the server's: resolved from the workspace's plan, never from
8
+ * anything the page or the app supplies (docs/branding-entitlements.md). It
9
+ * **fails closed**: a failed read, an older backend without the field, or any
10
+ * value but `false` keeps the watermark.
11
+ *
12
+ * One request per auth base per page: the provider configures itself more than
13
+ * once, and every configuration asks.
14
+ */
15
+ type Fetch = (url: string, init?: RequestInit) => Promise<Pick<Response, "ok" | "json">>;
16
+ /** The runtime-config URL for an auth base. */
17
+ export declare function runtimeConfigUrl(authBaseUrl: string): string;
18
+ /** The entitlements for an auth base (once per base). Never rejects. */
19
+ export declare function loadBrandingEntitlements(authBaseUrl: string, fetchImpl?: Fetch): Promise<BrandingEntitlements>;
20
+ /** The entitlements a runtime-config body grants: only an explicit `false` hides the watermark. */
21
+ export declare function brandingFrom(body: unknown): BrandingEntitlements;
22
+ /** Forgets every answer. For tests and stories. */
23
+ export declare function resetBrandingEntitlements(): void;
24
+ export {};
@@ -0,0 +1,100 @@
1
+ import { FlowStateEvent, WidgetClient } from '../flow-widget/flow-widget';
2
+ /**
3
+ * What `<pont2-provider>` needs from the auth SDK, structurally. The SDK's
4
+ * `Auth` (`@pontive/oidc-client`) satisfies it as-is, which
5
+ * `flow-widget/sdk-compat.test.ts` pins against the real types. pont2 never
6
+ * imports the SDK: the app injects it (`provider.sdk = Auth`, docs/13-provider.md).
7
+ *
8
+ * No index signatures, on purpose: they are what made `Auth` fail to type-check
9
+ * as a `WidgetClient` before (migration tracker W-13).
10
+ */
11
+ export interface ProviderSdk extends WidgetClient {
12
+ /** Replaces the whole configuration (it does not merge). */
13
+ configure(config: ProviderSdkConfig): void;
14
+ /** Turns an HttpOnly refresh cookie back into a session. Resolves null when there is none. */
15
+ restoreSession(): Promise<unknown>;
16
+ /** A local check: memory and an expiry time. */
17
+ isAuthenticated(): boolean;
18
+ /** Drops the stored session without reloading or tearing the flow machinery down. */
19
+ invalidateSession(): void;
20
+ /**
21
+ * Tells the listener about every session change, in this tab or another
22
+ * (`@pontive/oidc-client` 1.7.0); returns the unsubscribe. Optional, so an
23
+ * older SDK or a fake without it still works: the provider then falls back
24
+ * to re-checking when the tab becomes visible (W-14).
25
+ */
26
+ onSessionChange?(listener: (event: SessionChange) => void): () => void;
27
+ }
28
+ /** The part of the SDK's `SessionChangeEvent` the provider reads and re-announces. */
29
+ export interface SessionChange {
30
+ reason: "signed-in" | "restored" | "refreshed" | "organization-changed" | "signed-out" | "expired";
31
+ source: "local" | "other-tab";
32
+ isAuthenticated: boolean;
33
+ organizationId: string | null;
34
+ }
35
+ /** The parts of the SDK's `ConfigOptions` the provider writes. */
36
+ export interface ProviderSdkConfig {
37
+ domain: string;
38
+ appId: string;
39
+ signinUrl: string;
40
+ signupUrl: string;
41
+ invitationUrl?: string;
42
+ locales?: string;
43
+ headers?: Record<string, string>;
44
+ scope?: string | string[];
45
+ organizationId?: string;
46
+ continueHereUrl?: string;
47
+ onFlowStateChange?: (event: FlowStateEvent) => void;
48
+ onAuthenticated?: (session: unknown) => void;
49
+ }
50
+ /** What the app passes through `provider.config`: anything the SDK takes, and its own callbacks. */
51
+ export type AppSdkConfig = Partial<ProviderSdkConfig>;
52
+ /** The provider's own inputs (its attributes and properties). Empty values are "not given". */
53
+ export interface ProviderInputs {
54
+ domain: string;
55
+ appId: string;
56
+ locales?: string;
57
+ signinUrl?: string;
58
+ signupUrl?: string;
59
+ invitationUrl?: string;
60
+ signinRedirectUrl?: string;
61
+ continueHereUrl?: string;
62
+ scope?: string | string[];
63
+ headers?: Record<string, string>;
64
+ organizationId?: string;
65
+ }
66
+ /** The provider's own reactions to the SDK's two callbacks. */
67
+ export interface ProviderHooks {
68
+ onFlowStateChange(event: FlowStateEvent): void;
69
+ onAuthenticated(session: unknown): void;
70
+ }
71
+ /**
72
+ * The configuration the provider passes to `sdk.configure()`.
73
+ *
74
+ * `configure()` **replaces** the SDK's whole configuration, and the SDK has only
75
+ * these two callbacks, so whoever configures last owns them (migration tracker
76
+ * W-14). An app that needs either passes it in `provider.config`, and the
77
+ * provider **chains** it: its own reaction first, then the app's. A throwing
78
+ * callback is reported and never stops the other one.
79
+ *
80
+ * Precedence: the provider's non-empty inputs, over `app` (anything else the
81
+ * SDK takes, such as an option this interface doesn't name yet), over the
82
+ * required defaults (`signinUrl` / `signupUrl` empty). `continueHereUrl`
83
+ * defaults to `signinRedirectUrl`, as in the legacy provider.
84
+ *
85
+ * Note that passing `onAuthenticated` at all replaces the SDK's default (a page
86
+ * reload). The provider always passes one, because it refreshes the auth state
87
+ * in place, as the legacy provider does.
88
+ */
89
+ export declare function buildSdkConfig(inputs: ProviderInputs, own: ProviderHooks, app?: AppSdkConfig): ProviderSdkConfig;
90
+ /**
91
+ * The base the auth endpoints hang off, as an absolute URL without a trailing
92
+ * slash, or `null` when `domain` can't be resolved.
93
+ *
94
+ * A port of the SDK's `resolveAuthBaseUrl`, which is a module export and not a
95
+ * method of `Auth`, so it can't be injected with it (docs/13-provider.md §3).
96
+ * The three shapes: a hostname (`tenant.idp.us.pontive.app`, `https://`, or
97
+ * `http://` for loopback), a path on the page's origin (`/__pontive`), or a full
98
+ * base URL. Query and fragment are dropped.
99
+ */
100
+ export declare function authBaseUrl(domain: string | undefined, pageOrigin?: string): string | null;
@@ -0,0 +1,81 @@
1
+ import { PropertyValues } from 'lit';
2
+ import { HostElement } from '../../core/host-element';
3
+ import { AuthState } from './contexts';
4
+ /**
5
+ * # AuthGate: the base of `<pont2-signed-in>` / `<pont2-signed-out>`
6
+ *
7
+ * ```html
8
+ * <pont2-provider …>
9
+ * <pont2-signed-out><pont2-signin></pont2-signin></pont2-signed-out>
10
+ * <pont2-signed-in><a href="/account">Your account</a></pont2-signed-in>
11
+ * </pont2-provider>
12
+ * ```
13
+ *
14
+ * Shows its children for one answer of the provider's auth state
15
+ * (`pont2:auth`), and holds them **detached** otherwise, so that a widget inside
16
+ * the branch that doesn't apply never connects: a `pont2-signin` in
17
+ * `pont2-signed-out` never starts a flow for a signed-in user (migration tracker
18
+ * W-2).
19
+ *
20
+ * - **Nothing until the provider has asked** (`resolved`): its interim answer is
21
+ * "signed out", so either branch would flash for some users on every load.
22
+ * Without a provider it stays closed.
23
+ * - **No wrapper:** the children go back exactly where the author wrote them,
24
+ * as the host's own children, and the host adds no box (`display: contents`).
25
+ * (The legacy elements re-rendered them inside a `<div>` of their own.)
26
+ * - **A placeholder:** a direct child `[part="fallback"]` stays while the answer
27
+ * is pending and is removed once it arrives, the widgets' contract (F-17).
28
+ * - `data-state`: `pending`, `open` or `closed`.
29
+ *
30
+ * **Framework hosts** (React) should branch on the provider's
31
+ * `pont2-auth-changed` event instead, as the pontkit bindings do: an element
32
+ * that detaches children takes them away from a framework that still thinks it
33
+ * owns them.
34
+ */
35
+ export declare abstract class AuthGate extends HostElement {
36
+ static identity: string;
37
+ static composite: boolean;
38
+ private consumer;
39
+ /** The children held while closed, in order. */
40
+ private held;
41
+ /** Catches children a host adds while the gate is closed. */
42
+ private observer;
43
+ /** Whether this gate opens for `auth` (only asked once `auth.resolved`). */
44
+ protected abstract opensFor(auth: AuthState): boolean;
45
+ /** The auth state the gate is following. */
46
+ get auth(): AuthState;
47
+ /** Whether the children are shown. */
48
+ get open(): boolean;
49
+ connectedCallback(): void;
50
+ disconnectedCallback(): void;
51
+ protected updated(_changed: PropertyValues): void;
52
+ private apply;
53
+ /** Detaches every child but the pending placeholder. */
54
+ private hold;
55
+ }
56
+ /**
57
+ * # `<pont2-signed-in>`: shown once the provider knows someone is signed in
58
+ *
59
+ * @tag pont2-signed-in
60
+ */
61
+ export declare class SignedIn extends AuthGate {
62
+ static identity: string;
63
+ static slotName: string;
64
+ protected opensFor(auth: AuthState): boolean;
65
+ }
66
+ /**
67
+ * # `<pont2-signed-out>`: shown once the provider knows nobody is signed in
68
+ *
69
+ * @tag pont2-signed-out
70
+ */
71
+ export declare class SignedOut extends AuthGate {
72
+ static identity: string;
73
+ static slotName: string;
74
+ protected opensFor(auth: AuthState): boolean;
75
+ }
76
+ declare global {
77
+ interface HTMLElementTagNameMap {
78
+ "pont2-signed-in": SignedIn;
79
+ "pont2-signed-out": SignedOut;
80
+ }
81
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The signed-in widgets' own text (account menu, account settings, organization
3
+ * switcher, member management), which no flow response carries: `<pont2-provider>`
4
+ * reads it from `GET {auth}/auth/v1/widget-messages?locales=…` and hands it to
5
+ * the page's message table (`setMessages`, core/messages.ts). A port of the
6
+ * legacy `loadWidgetMessages` (carry-over §3, migration tracker I-2).
7
+ *
8
+ * **One request per language per page.** The provider configures itself more
9
+ * than once (its inputs, then its locales, settle), and every configuration
10
+ * asks. A URL already asked, or being asked, is not asked again: its answer is
11
+ * kept and applied again, so switching back to a language already loaded
12
+ * restores its text without a request. (The legacy loader remembered only the
13
+ * last URL, so en → de → en asked for English twice.)
14
+ *
15
+ * A failed read is forgotten, so the next configuration can try again. A
16
+ * stopped instance refuses this read too, with its one sentence in the page's
17
+ * language (carry-over §6): that sentence is kept (`rememberUnavailable`).
18
+ */
19
+ /** The read's answer: the language it was served in, and its messages by code. */
20
+ export interface WidgetMessages {
21
+ locale?: string;
22
+ messages?: Record<string, string>;
23
+ }
24
+ type Fetch = (url: string, init?: RequestInit) => Promise<Pick<Response, "ok" | "json">>;
25
+ /** The widget-messages URL for an auth base and a language preference. */
26
+ export declare function widgetMessagesUrl(authBaseUrl: string, locales?: string): string;
27
+ /**
28
+ * Loads (once per URL) and applies the widget messages. Resolves when they are
29
+ * in the message table, or when the read failed (the page keeps English, or
30
+ * whatever it was last served in). Never rejects.
31
+ */
32
+ export declare function loadWidgetMessages(authBaseUrl: string, locales?: string, fetchImpl?: Fetch): Promise<void>;
33
+ /** Forgets every answer. For tests and stories. */
34
+ export declare function resetWidgetMessages(): void;
35
+ export {};