@pontive/pontkit-react 1.6.0 → 1.8.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/dist/types.d.ts CHANGED
@@ -1,125 +1,150 @@
1
1
  import { ReactNode } from 'react';
2
- import { IProfileContentCustomizations, IProfileWidgetCustomization, MEMBER_MANAGEMENT_MODE, MenuItem, USER_PROFILE_MODE, USER_PROFILE_ORIENTATION, USER_PROFILE_SIDEBAR_DISPLAY_TYPE, USER_PROFILE_WIDGETS_LAYOUT } from './enums';
3
- import { EnvConfig } from '@pontive/pontkit-core';
4
- type WithChildren = {
5
- children?: ReactNode;
2
+ import { AccountClient, AccountMenuItem, AccountSettingsContent, AccountSettingsLayout, AccountSettingsMode, AccountSettingsOrientation, AppSdkConfig, BrandingEntitlements, CheckoutPackageRequest, MemberManagementMode, ProviderSdk, SessionChange, WidgetClient } from '@pontive/pontkit-core';
3
+ export type { AccountClient, AccountMenuItem, AuthState, BillingAccount, BillingContract, BillingSubject, CheckoutPackageRequest, ProviderSdk, SessionChange, WidgetClient, } from '@pontive/pontkit-core';
4
+ /**
5
+ * Events core declares on `HTMLElementEventMap` are typed from there; this
6
+ * covers the ones it fires without declaring.
7
+ */
8
+ interface UndeclaredEvents {
9
+ "pont-session-changed": CustomEvent<SessionChange>;
10
+ }
11
+ /** The event a generated `on…` callback receives: the DOM event itself. */
12
+ export type PontEvent<K extends string> = K extends keyof HTMLElementEventMap ? HTMLElementEventMap[K] : K extends keyof UndeclaredEvents ? UndeclaredEvents[K] : CustomEvent<unknown>;
13
+ /** The inputs of `<pont-provider>` (pontkit-core docs/kit/provider.md). */
14
+ export interface ProviderInputProps {
15
+ /** Required. */
16
+ appId: string;
17
+ /** Required: a hostname, a `/path` on this origin (the auth proxy, `/__pontive`), or a base URL. */
18
+ domain: string;
19
+ /** BCP-47 tags in preference order; empty lets the server negotiate. */
20
+ locales?: string;
21
+ signinUrl?: string;
22
+ signupUrl?: string;
23
+ invitationUrl?: string;
24
+ /** Where a signed-in user is sent from the sign-in, sign-up and invitation pages. */
25
+ signinRedirectUrl?: string;
26
+ /** "Continue here instead" (default: `signinRedirectUrl`). */
27
+ continueHereUrl?: string;
28
+ /** The OAuth scopes every flow asks for. Member management needs `pontive:org:member:*`. */
29
+ scope?: string | string[];
30
+ /** The organization a sign-in starts in. */
31
+ organizationId?: string;
6
32
  /**
7
- * Placeholder rendered inside the element until it has something real to
8
- * show, at which point the element removes it.
9
- *
10
- * `fallbackChildren` used to sit alongside this, asking for the children to
11
- * stand in as the placeholder while the CDN loaded. Widgets no longer wait on
12
- * the CDN to render — the tag goes out with the server response and upgrades
13
- * in place — so children are already on the page throughout that window and
14
- * the flag had nothing left to switch on.
33
+ * The management gateway the default account client calls
34
+ * (`https://api.us.pontive.com`). Absolute http(s) only: the auth proxy does
35
+ * not forward `/me` or `/mgmt/v1`.
15
36
  */
16
- fallback?: ReactNode | null;
17
- };
18
- type WithRenderSpec = {
19
- renderSpec?: string | null;
20
- };
21
- type WidgetLayout = "ROW" | "COLUMN" | typeof USER_PROFILE_WIDGETS_LAYOUT.ROW | typeof USER_PROFILE_WIDGETS_LAYOUT.COLUMN;
22
- type CommonWidgetProps = WithChildren & {
23
- showIcons?: boolean;
24
- Layout?: WidgetLayout;
25
- content?: IProfileWidgetCustomization | null;
26
- };
27
- export interface ProviderProps {
28
- children?: ReactNode;
37
+ apiBaseUrl?: string;
38
+ /** The identifier to pre-fill (default: the URL's `login_hint`). */
39
+ loginHint?: string;
40
+ /** Default on. `false` keeps a signed-in user on the auth pages. */
29
41
  autoRedirect?: boolean;
30
- env: EnvConfig;
31
- locale?: string;
32
- }
33
- export interface LayoutProps extends WithChildren, WithRenderSpec {
34
- }
35
- export interface PreviewProps extends WithChildren, WithRenderSpec {
36
- }
37
- export interface SignInProps extends WithChildren {
38
- }
39
- export interface SignUpProps extends WithChildren {
40
- }
41
- export interface AccountMenuProps extends WithChildren {
42
- accountSettingsPath?: string;
43
- menuItems?: MenuItem[];
42
+ /** `"none"` opts out of linking the published theme. */
43
+ theme?: string;
44
+ /** Extra request headers for the SDK and the default account client. */
45
+ headers?: Record<string, string>;
46
+ /** The app's own account client; wins over the default one. */
47
+ accountClient?: AccountClient;
48
+ /**
49
+ * The app's own SDK options and callbacks (`onFlowStateChange`,
50
+ * `onAuthenticated` …). The provider chains them after its own; don't call
51
+ * `Auth.configure()` yourself.
52
+ */
53
+ config?: AppSdkConfig;
44
54
  }
45
- /** What a switch reports: the organization and what the user holds there. */
46
- export interface OrganizationChangedDetail {
47
- organizationId: string;
48
- roles: string[];
49
- permissions: string[];
55
+ /** The raw `<pont-provider>` wrapper's props: the inputs plus the SDK. */
56
+ export interface ProviderElementProps extends ProviderInputProps {
57
+ children?: ReactNode;
58
+ sdk?: ProviderSdk;
50
59
  }
51
- /**
52
- * Props for `<OrganizationSwitcher>`, a menu of the organizations the signed-in
53
- * user belongs to. Choosing one moves the session there (new tokens, no
54
- * sign-in). Renders nothing for a signed-out user or one with no organizations.
55
- */
56
- export interface OrganizationSwitcherProps extends WithChildren {
57
- /** Reload the page after a switch — for server-rendered pages. */
60
+ /** `pont-signin`, `pont-signup`, `pont-invitation`. */
61
+ export interface FlowWidgetProps {
62
+ /**
63
+ * Shown until the first screen renders, then removed by the widget.
64
+ */
65
+ fallback?: ReactNode | null;
66
+ /** The widget's own client. Inside a `Provider` it uses the provider's. */
67
+ client?: WidgetClient;
68
+ /** Its own branding entitlements. Inside a `Provider` it uses the provider's. */
69
+ branding?: BrandingEntitlements;
70
+ /** Default `sys_signin-flow-passkey` / `sys_signup-flow`; none for the invitation. */
71
+ flowId?: string;
72
+ }
73
+ /** `pont-consent` (the OAuth consent page). */
74
+ export interface ConsentProps {
75
+ /** The page's `consent_request` parameter. */
76
+ consentRequest: string;
77
+ /** Where auth-api is (default: this origin, which the session cookie needs). */
78
+ baseUrl?: string;
79
+ locales?: string;
80
+ branding?: BrandingEntitlements;
81
+ }
82
+ /** What every account widget takes. */
83
+ interface AccountWidgetProps {
84
+ /** Its own account client. Inside a `Provider` it uses the provider's. */
85
+ client?: AccountClient;
86
+ }
87
+ export interface AccountMenuProps extends AccountWidgetProps {
88
+ /** Where "Account settings" goes when `onAccountSettings` doesn't cancel. */
89
+ accountSettingsUrl?: string;
90
+ /** Entries between "Account settings" and "Log out". */
91
+ items?: AccountMenuItem[];
92
+ }
93
+ export interface OrganizationSwitcherProps extends AccountWidgetProps {
94
+ /** Reload the page after a switch (for server-rendered pages). */
58
95
  reloadOnSwitch?: boolean;
59
- /** Trigger label while the session acts in no organization. */
96
+ /** The button's text while the session acts in no organization. */
60
97
  emptyLabel?: string;
61
- /** Called after a switch; refetch whatever depends on the organization. */
62
- onOrganizationChanged?: (detail: OrganizationChangedDetail) => void;
63
- /** Called when a switch is refused; the session is unchanged. */
64
- onSwitchFailed?: (detail: {
65
- organizationId: string;
66
- error: unknown;
67
- }) => void;
68
- }
69
- export interface AccountSettingsProps extends WithChildren {
70
- showAvatarMenu?: boolean;
71
- orientation?: "VERTICAL" | "HORIZONTAL" | typeof USER_PROFILE_ORIENTATION.HORIZONTAL | typeof USER_PROFILE_ORIENTATION.VERTICAL;
72
- mobileDisplay?: "REGULAR" | "BURGER" | typeof USER_PROFILE_SIDEBAR_DISPLAY_TYPE.REGULAR | typeof USER_PROFILE_SIDEBAR_DISPLAY_TYPE.BURGER;
73
- mode?: "PAGE" | "MODAL" | typeof USER_PROFILE_MODE.PAGE | typeof USER_PROFILE_MODE.MODAL;
74
- widgetsLayout?: WidgetLayout;
75
- content?: IProfileContentCustomizations | null;
76
98
  }
77
- export interface MemberManagementProps extends WithChildren {
78
- mode?: "PAGE" | "MODAL" | typeof MEMBER_MANAGEMENT_MODE.PAGE | typeof MEMBER_MANAGEMENT_MODE.MODAL;
79
- title?: string;
99
+ export interface AccountSettingsProps extends AccountWidgetProps {
100
+ mode?: AccountSettingsMode;
101
+ orientation?: AccountSettingsOrientation;
102
+ widgetsLayout?: AccountSettingsLayout;
103
+ /** Modal mode: whether the dialog is open. */
104
+ open?: boolean;
105
+ content?: AccountSettingsContent | null;
106
+ }
107
+ export interface MemberManagementProps extends AccountWidgetProps {
108
+ /** The organization to manage (default: the session's). */
109
+ organizationId?: string;
110
+ mode?: MemberManagementMode;
111
+ /** Modal mode: whether the dialog is open. */
112
+ open?: boolean;
113
+ heading?: string;
80
114
  description?: string;
81
- organizationId: string;
82
- }
83
- export interface AccountInfoProps extends WithChildren {
84
- account?: AccountInfo;
85
- showAvatarMenu?: boolean;
86
- toggleAvatarMenu: (e: Event) => void;
87
- onAvatarChange: () => void;
88
- onAvatarRemove: () => void;
89
- showIcons?: boolean;
90
- content?: IProfileWidgetCustomization | null;
91
- otpVariant?: "simple" | "with_spacing" | "with_separator" | "digits_only";
92
- otpLength?: number;
93
- Layout?: WidgetLayout;
94
- }
95
- export interface LocationInfoProps extends CommonWidgetProps {
96
- locationInfo?: LocationInfo;
97
- }
98
- export interface UrlsInfoProps extends CommonWidgetProps {
99
- URLsInfo?: URLsInfo;
115
+ /** 5, 10 or 25. */
116
+ pageSize?: number;
100
117
  }
101
- export interface PersonalInfoProps extends CommonWidgetProps {
102
- personal?: PersonalInfo;
103
- }
104
- export interface PersonalInfo {
105
- username: string;
106
- first: string;
107
- middle: string;
108
- last: string;
109
- nickname: string;
110
- gender: string;
111
- bio: string;
112
- }
113
- export interface URLsInfo {
114
- website: string;
115
- }
116
- export interface LocationInfo {
117
- location: string;
118
- zoneInfo: string;
118
+ /**
119
+ * `pont-checkout` (beta: needs the instance's `billing` capability; pontkit-core
120
+ * docs/kit/checkout.md).
121
+ */
122
+ export interface CheckoutProps extends AccountWidgetProps {
123
+ /**
124
+ * The packages offered: ids or keys, each with `:` and its frequencies
125
+ * (`"pkg_pro:monthly,annual pkg_team"`), or the same as an array.
126
+ */
127
+ packages?: string | CheckoutPackageRequest[];
128
+ /** Where the browser goes once the session completes (default: this page). */
129
+ successUrl?: string;
130
+ /** Where "Cancel" goes; no Cancel button without it. */
131
+ cancelUrl?: string;
132
+ /** A checkout session the client's server created (`chks_...`); `packages` is then ignored. */
133
+ session?: string;
134
+ /** The Customer's subject, `org_...` or `usr_...` (default: as billing-svc resolves it). */
135
+ subject?: string;
136
+ heading?: string;
119
137
  }
120
- export interface AccountInfo {
121
- email: string;
122
- phone: string;
123
- avatar: string;
138
+ /**
139
+ * `pont-billing-portal` (beta: needs the instance's `billing` capability;
140
+ * pontkit-core docs/kit/billing-portal.md).
141
+ */
142
+ export interface BillingPortalProps extends AccountWidgetProps {
143
+ /**
144
+ * The Customer's subject, `org_...` or `usr_...` (default: as billing-svc
145
+ * resolves it). A suspended organization's owner reaches it this way.
146
+ */
147
+ subject?: string;
148
+ heading?: string;
149
+ description?: string;
124
150
  }
125
- export {};
package/dist/wrap.d.ts CHANGED
@@ -1,31 +1,22 @@
1
1
  import { default as React } from 'react';
2
- import { ProviderProps as ReactProviderProps } from './types';
3
2
  /**
4
- * What a pont2 wrapper says about its element (generated, see
5
- * tools/gen-wrappers). The legacy wrappers pass none.
3
+ * What a wrapper says about its element (generated, see tools/gen-wrappers).
6
4
  */
7
5
  export interface WrapOptions {
8
6
  /**
9
- * Callback prop -> DOM event. pont2 elements report through events where
10
- * the legacy ones took callback properties, so these props are listened
11
- * for instead of assigned, and the callback gets the event itself (a
12
- * cancelable one can be `preventDefault()`ed).
7
+ * Callback prop -> DOM event. The elements report through events, so these
8
+ * props are listened for instead of assigned, and the callback gets the
9
+ * event itself (a cancelable one can be `preventDefault()`ed).
13
10
  */
14
11
  events?: Readonly<Record<string, string>>;
15
12
  /** Whether the element honours the `[part="fallback"]` contract. */
16
13
  fallback?: boolean;
17
- /** Starts the CDN load on mount, as the legacy provider does. */
14
+ /** Starts the CDN load on mount. */
18
15
  provider?: boolean;
19
16
  }
20
17
  /**
21
- * A pont2 wrapper: `wrap()` with the element's options, typed by `P` alone.
22
- * Children and `fallback` are whatever its props type says, because only the
18
+ * A React component over the custom element `tagName`, typed by `P` alone:
19
+ * children and `fallback` are whatever its props type says, because only the
23
20
  * provider takes children and only the flow widgets honour a fallback.
24
21
  */
25
- export declare function wrapPont2<T extends HTMLElement, P = {}>(tagName: string, options: WrapOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
26
- export declare function wrap<T extends HTMLElement, P = {}>(tagName: string, options?: WrapOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<P & React.RefAttributes<T> & (P extends ReactProviderProps ? {
27
- children?: React.ReactNode;
28
- } : {
29
- children?: React.ReactNode;
30
- fallback?: React.ReactNode | null;
31
- })> & React.RefAttributes<T>>;
22
+ export declare function wrap<T extends HTMLElement, P = {}>(tagName: string, options?: WrapOptions): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@pontive/pontkit-react",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "license": "MIT",
5
- "description": "React components over the pont-* custom elements (and pont2-* under /pont2).",
5
+ "description": "React components over the PontKit (pont-*) custom elements.",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.js",
@@ -12,11 +12,6 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.js",
14
14
  "require": "./dist/index.cjs"
15
- },
16
- "./pont2": {
17
- "types": "./dist/pont2/index.d.ts",
18
- "import": "./dist/pont2.js",
19
- "require": "./dist/pont2.cjs"
20
15
  }
21
16
  },
22
17
  "files": [
@@ -36,11 +31,11 @@
36
31
  "react-dom": "^18 || ^19"
37
32
  },
38
33
  "dependencies": {
39
- "@pontive/pontkit-loader": "^1.6.0"
34
+ "@pontive/oidc-client": "^1.7.0",
35
+ "@pontive/pontkit-loader": "^1.8.0"
40
36
  },
41
37
  "devDependencies": {
42
- "@pontive/oidc-client": "^1.0.0",
43
- "@pontive/pontkit-core": "1.41.0",
38
+ "@pontive/pontkit-core": "1.46.0",
44
39
  "@testing-library/dom": "^10.4.1",
45
40
  "@testing-library/react": "^16.3.3",
46
41
  "@types/react-dom": "^19.2.5",
package/dist/auth.d.ts DELETED
@@ -1,102 +0,0 @@
1
- import { default as React } from 'react';
2
- import { AuthState, EnvConfig } from '@pontive/pontkit-core';
3
- interface PontKitContextValue {
4
- auth: AuthState;
5
- /**
6
- * Carried alongside the session because `<Authenticated>` needs it: its
7
- * default redirect target is `env.signinUrl`, which the element read from the
8
- * provider's Lit `envContext`. React has the same need and no way into that
9
- * context, and the Provider already holds `env` as a prop.
10
- */
11
- env: EnvConfig | null;
12
- }
13
- /**
14
- * The current session state.
15
- *
16
- * Throws when there is no `<Provider>` above the caller, which is always a
17
- * wiring mistake rather than a state to handle.
18
- */
19
- export declare function useAuthState(): AuthState;
20
- /** The `env` the nearest `<Provider>` was configured with. */
21
- export declare function useEnvConfig(): EnvConfig | null;
22
- /**
23
- * Tracks the session by listening to the provider element.
24
- *
25
- * Subscribing is not enough on its own: the provider resolves after a network
26
- * round trip, but nothing guarantees that happens *after* this listener is
27
- * attached — a Provider mounted into an application that is already running has
28
- * missed the event entirely. So the element's own `auth` property is read as a
29
- * seed, both immediately and once the definition has arrived, since before the
30
- * upgrade there is no property to read.
31
- */
32
- export declare function useProviderAuthState(element: HTMLElement | null, tagName: string, eventName?: string): AuthState;
33
- export declare function AuthStateProvider({ value, children, }: {
34
- value: PontKitContextValue;
35
- children?: React.ReactNode;
36
- }): React.FunctionComponentElement<React.ProviderProps<PontKitContextValue | undefined>>;
37
- export interface ControlProps {
38
- children?: React.ReactNode;
39
- /**
40
- * What to render while the session is still being resolved.
41
- *
42
- * Both components render nothing during that window by default, because the
43
- * interim answer is "signed out" and showing the signed-out branch to a
44
- * signed-in user is the flash this is here to avoid.
45
- */
46
- fallback?: React.ReactNode | null;
47
- }
48
- export declare function SignedIn({ children, fallback, }: ControlProps): React.ReactNode;
49
- export declare function SignedOut({ children, fallback, }: ControlProps): React.ReactNode;
50
- /**
51
- * Renders its children once the session is known, and a placeholder until then.
52
- *
53
- * This replaces `<pont-auth-state>`, whose real job was pruning: it removed
54
- * whichever of `<pont-signed-in>` / `<pont-signed-out>` did not apply, permanently,
55
- * with `querySelectorAll(...).forEach(el => el.remove())`. Those tags are React
56
- * components now and never reach the DOM, so the search finds nothing — the
57
- * element still runs, and quietly does nothing at all.
58
- *
59
- * What is left is the half that was always worth having: one placeholder for a
60
- * group, instead of a `fallback` on every child. `<SignedIn>` and `<SignedOut>`
61
- * each gate on `resolved` themselves, so this is only about what fills the space
62
- * while the answer is in flight.
63
- *
64
- * Named for the flag it gates on rather than inheriting the element's name,
65
- * which described a state rather than a behaviour — and which collided with the
66
- * `AuthState` type.
67
- */
68
- export declare function AuthResolved({ children, fallback, }: ControlProps): React.ReactNode;
69
- export interface AuthenticatedProps {
70
- children?: React.ReactNode;
71
- /**
72
- * Rendered while the session is being resolved.
73
- *
74
- * The element spelled this `slot="loading"` and partitioned the children on
75
- * capture, because it stayed in the light DOM and so had no real `<slot>` to
76
- * use. A prop says the same thing without the machinery.
77
- */
78
- loading?: React.ReactNode;
79
- /** Where to send an unauthenticated visitor. Defaults to `env.signinUrl`. */
80
- redirectUrl?: string;
81
- /**
82
- * Hand the navigation to the host's router instead of loading a new document.
83
- *
84
- * The default is a full page load, which is what the element did. In a single
85
- * page application that throws away the router's state and everything else in
86
- * memory, so a host with a router should pass its own navigate here —
87
- * `(url) => navigate(url)` for React Router, `router.push` for Next.
88
- */
89
- onRedirect?: (url: string) => void;
90
- }
91
- /**
92
- * Renders its children only for a signed-in visitor, and sends everyone else to
93
- * the sign-in page.
94
- *
95
- * The redirect runs in an effect, which is the substantive change from the
96
- * element this replaces. That one assigned `window.location.href` from inside
97
- * `render()` — a side effect in a method the framework may call whenever it
98
- * likes, and which React would call twice in StrictMode. An effect fires once,
99
- * after the commit, on a transition that actually happened.
100
- */
101
- export declare function Authenticated({ children, loading, redirectUrl, onRedirect, }: AuthenticatedProps): React.ReactNode;
102
- export {};
@@ -1,170 +0,0 @@
1
- import { forwardRef as x, useRef as P, useState as D, useEffect as A, createElement as U, useLayoutEffect as z, createContext as F, useContext as M } from "react";
2
- import { createPortal as T } from "react-dom";
3
- import { loadWebComponents as V } from "@pontive/pontkit-loader";
4
- const _ = /* @__PURE__ */ new Set(["className", "style", "id", "slot"]), b = typeof window < "u" ? z : A;
5
- function Q(e, t) {
6
- return $(e, t);
7
- }
8
- function $(e, t) {
9
- const r = e === "pont-provider" || !!t?.provider, o = t?.events ?? {}, c = new Set(Object.keys(o)), f = t ? !!t.fallback : !0;
10
- return x((a, s) => {
11
- const l = P(null), i = P({}), d = P({}), [y, k] = D(null), { fallback: E, children: I, ...K } = a, S = {}, C = {}, O = {};
12
- for (const [n, u] of Object.entries(K))
13
- c.has(n) ? O[n] = u : (_.has(n) ? S : C)[n] = u;
14
- d.current = O, A(() => {
15
- r && V().catch(console.error);
16
- }, []), b(() => {
17
- const n = l.current;
18
- if (!n) return;
19
- let u = !1;
20
- function v() {
21
- if (!(u || !n)) {
22
- for (const [h, p] of Object.entries(C))
23
- if (i.current[h] !== p)
24
- try {
25
- n[h] = p, i.current[h] = p;
26
- } catch {
27
- }
28
- }
29
- }
30
- return customElements.get(e) ? v() : customElements.whenDefined(e).then(v), () => {
31
- u = !0;
32
- };
33
- }), b(() => {
34
- const n = l.current;
35
- if (!n || c.size === 0) return;
36
- const u = Object.entries(o).map(([v, h]) => {
37
- const p = (W) => {
38
- const L = d.current[v];
39
- typeof L == "function" && L(W);
40
- };
41
- return n.addEventListener(h, p), () => n.removeEventListener(h, p);
42
- });
43
- return () => u.forEach((v) => v());
44
- }, []), b(() => {
45
- const n = l.current;
46
- if (!n || E == null || !f) return;
47
- const u = document.createElement("div");
48
- return u.setAttribute("part", "fallback"), n.prepend(u), k(u), () => {
49
- u.remove(), k(null);
50
- };
51
- }, [E == null]);
52
- function R(n) {
53
- l.current = n, typeof s == "function" ? s(n) : s && (s.current = n);
54
- }
55
- return U(
56
- e,
57
- { ...S, ref: R },
58
- I ?? null,
59
- y ? T(E, y) : null
60
- );
61
- });
62
- }
63
- const q = { isAuthenticated: !1, resolved: !1 }, H = F(
64
- void 0
65
- );
66
- function g(e) {
67
- const t = M(H);
68
- if (t === void 0)
69
- throw new Error(
70
- `${e} was called outside <Provider>. Wrap your app in the Provider from @pontive/pontkit-react/react — the same component that configures \`env\`.`
71
- );
72
- return t;
73
- }
74
- function w() {
75
- return g("useAuthState").auth;
76
- }
77
- function X() {
78
- return g("useEnvConfig").env;
79
- }
80
- function Y(e, t, r = "pont:auth-changed") {
81
- const [o, c] = D(q);
82
- return A(() => {
83
- if (!e) return;
84
- let f = !1;
85
- function a(i) {
86
- f || !i || c(
87
- (d) => d.isAuthenticated === i.isAuthenticated && d.resolved === i.resolved ? d : { isAuthenticated: !!i.isAuthenticated, resolved: !!i.resolved }
88
- );
89
- }
90
- function s(i) {
91
- a(i.detail);
92
- }
93
- e.addEventListener(r, s);
94
- function l() {
95
- a(e?.auth);
96
- }
97
- return l(), customElements.whenDefined(t).then(l), () => {
98
- f = !0, e.removeEventListener(r, s);
99
- };
100
- }, [e, t, r]), o;
101
- }
102
- function Z({
103
- value: e,
104
- children: t
105
- }) {
106
- return U(H.Provider, { value: e }, t);
107
- }
108
- function N({
109
- children: e,
110
- fallback: t = null
111
- }) {
112
- const { isAuthenticated: r, resolved: o } = w();
113
- return o ? r ? e : null : t;
114
- }
115
- function ee({
116
- children: e,
117
- fallback: t = null
118
- }) {
119
- const { isAuthenticated: r, resolved: o } = w();
120
- return o ? r ? null : e : t;
121
- }
122
- function te({
123
- children: e,
124
- fallback: t = null
125
- }) {
126
- const { resolved: r } = w();
127
- return r ? e : t;
128
- }
129
- function ne({
130
- children: e,
131
- loading: t = null,
132
- redirectUrl: r,
133
- onRedirect: o
134
- }) {
135
- const { auth: c, env: f } = g("Authenticated"), a = P(!1), s = r || f?.signinUrl;
136
- return A(() => {
137
- if (!(!c.resolved || c.isAuthenticated) && !a.current) {
138
- if (!s) {
139
- console.error(
140
- "[pontive] <Authenticated> has nobody to redirect to: pass `redirectUrl`, or give the Provider an `env.signinUrl`."
141
- );
142
- return;
143
- }
144
- a.current = !0, o ? o(s) : window.location.href = s;
145
- }
146
- }, [c.resolved, c.isAuthenticated, s, o]), c.resolved ? c.isAuthenticated ? e : null : t;
147
- }
148
- const m = { legacy: 0, pont2: 0 };
149
- let j = !1;
150
- function re(e) {
151
- A(() => (m[e] += 1, !j && m.legacy > 0 && m.pont2 > 0 && (j = !0, console.warn(
152
- "[pontive] <Provider> (@pontive/pontkit-react) and <Pont2Provider> (@pontive/pontkit-react/pont2) are mounted together. They share one Auth and one configuration, so each overwrites the other's: mount only one per page."
153
- )), () => {
154
- m[e] -= 1;
155
- }), [e]);
156
- }
157
- export {
158
- Z as A,
159
- N as S,
160
- Y as a,
161
- te as b,
162
- ne as c,
163
- ee as d,
164
- w as e,
165
- X as f,
166
- Q as g,
167
- re as u,
168
- $ as w
169
- };
170
- //# sourceMappingURL=coexistence-CEqhGd4-.js.map