@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/elements.generated.d.ts +107 -53
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -30
- package/dist/index.js +257 -60
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +77 -0
- package/dist/types.d.ts +137 -112
- package/dist/wrap.d.ts +8 -17
- package/package.json +5 -10
- package/dist/auth.d.ts +0 -102
- package/dist/coexistence-CEqhGd4-.js +0 -170
- package/dist/coexistence-CEqhGd4-.js.map +0 -1
- package/dist/coexistence-dvfn_5A6.cjs +0 -2
- package/dist/coexistence-dvfn_5A6.cjs.map +0 -1
- package/dist/coexistence.d.ts +0 -19
- package/dist/enums.d.ts +0 -58
- package/dist/pont2/elements.generated.d.ts +0 -81
- package/dist/pont2/index.d.ts +0 -18
- package/dist/pont2/provider.d.ts +0 -71
- package/dist/pont2/types.d.ts +0 -118
- package/dist/pont2.cjs +0 -2
- package/dist/pont2.cjs.map +0 -1
- package/dist/pont2.js +0 -181
- package/dist/pont2.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,71 +1,268 @@
|
|
|
1
|
-
import { forwardRef as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
const
|
|
6
|
-
function e
|
|
7
|
-
|
|
1
|
+
import { forwardRef as I, useRef as P, useState as b, useEffect as m, createElement as w, useLayoutEffect as x, useMemo as H, useContext as V, createContext as W } from "react";
|
|
2
|
+
import { createPortal as $ } from "react-dom";
|
|
3
|
+
import { loadWebComponents as N } from "@pontive/pontkit-loader";
|
|
4
|
+
import { Auth as _ } from "@pontive/oidc-client";
|
|
5
|
+
const q = /* @__PURE__ */ new Set(["className", "style", "id", "slot"]), E = typeof window < "u" ? x : m;
|
|
6
|
+
function d(e, t = {}) {
|
|
7
|
+
const c = !!t.provider, n = t.events ?? {}, o = new Set(Object.keys(n)), l = !!t.fallback, r = I((i, a) => {
|
|
8
|
+
const f = P(null), C = P({}), A = P({}), [p, O] = b(null), { fallback: S, children: z, ...D } = i, M = {}, L = {}, R = {};
|
|
9
|
+
for (const [s, u] of Object.entries(D))
|
|
10
|
+
o.has(s) ? R[s] = u : (q.has(s) ? M : L)[s] = u;
|
|
11
|
+
A.current = R, m(() => {
|
|
12
|
+
c && N().catch(console.error);
|
|
13
|
+
}, []), E(() => {
|
|
14
|
+
const s = f.current;
|
|
15
|
+
if (!s) return;
|
|
16
|
+
let u = !1;
|
|
17
|
+
function h() {
|
|
18
|
+
if (!(u || !s)) {
|
|
19
|
+
for (const [v, g] of Object.entries(L))
|
|
20
|
+
if (C.current[v] !== g)
|
|
21
|
+
try {
|
|
22
|
+
s[v] = g, C.current[v] = g;
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return customElements.get(e) ? h() : customElements.whenDefined(e).then(h), () => {
|
|
28
|
+
u = !0;
|
|
29
|
+
};
|
|
30
|
+
}), E(() => {
|
|
31
|
+
const s = f.current;
|
|
32
|
+
if (!s || o.size === 0) return;
|
|
33
|
+
const u = Object.entries(n).map(([h, v]) => {
|
|
34
|
+
const g = (F) => {
|
|
35
|
+
const B = A.current[h];
|
|
36
|
+
typeof B == "function" && B(F);
|
|
37
|
+
};
|
|
38
|
+
return s.addEventListener(v, g), () => s.removeEventListener(v, g);
|
|
39
|
+
});
|
|
40
|
+
return () => u.forEach((h) => h());
|
|
41
|
+
}, []), E(() => {
|
|
42
|
+
const s = f.current;
|
|
43
|
+
if (!s || S == null || !l) return;
|
|
44
|
+
const u = document.createElement("div");
|
|
45
|
+
return u.setAttribute("part", "fallback"), s.prepend(u), O(u), () => {
|
|
46
|
+
u.remove(), O(null);
|
|
47
|
+
};
|
|
48
|
+
}, [S == null]);
|
|
49
|
+
function j(s) {
|
|
50
|
+
f.current = s, typeof a == "function" ? a(s) : a && (a.current = s);
|
|
51
|
+
}
|
|
52
|
+
return w(
|
|
53
|
+
e,
|
|
54
|
+
{ ...M, ref: j },
|
|
55
|
+
z ?? null,
|
|
56
|
+
p ? $(S, p) : null
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
return r.displayName = `wrap(${e})`, r;
|
|
8
60
|
}
|
|
9
|
-
|
|
10
|
-
|
|
61
|
+
const G = /* @__PURE__ */ d("pont-provider", {
|
|
62
|
+
events: {
|
|
63
|
+
onAuthChanged: "pont-auth-changed",
|
|
64
|
+
onLocaleChanged: "pont-locale-changed",
|
|
65
|
+
onSessionChanged: "pont-session-changed",
|
|
66
|
+
onRedirect: "pont-redirect"
|
|
67
|
+
},
|
|
68
|
+
fallback: !1,
|
|
69
|
+
provider: !0
|
|
70
|
+
}), ne = /* @__PURE__ */ d("pont-signin", {
|
|
71
|
+
events: {
|
|
72
|
+
onFlowResponse: "pont-flow-response"
|
|
73
|
+
},
|
|
74
|
+
fallback: !0
|
|
75
|
+
}), te = /* @__PURE__ */ d("pont-signup", {
|
|
76
|
+
events: {
|
|
77
|
+
onFlowResponse: "pont-flow-response"
|
|
78
|
+
},
|
|
79
|
+
fallback: !0
|
|
80
|
+
}), oe = /* @__PURE__ */ d("pont-invitation", {
|
|
81
|
+
events: {
|
|
82
|
+
onFlowResponse: "pont-flow-response"
|
|
83
|
+
},
|
|
84
|
+
fallback: !0
|
|
85
|
+
}), ie = /* @__PURE__ */ d("pont-consent", {
|
|
86
|
+
events: {},
|
|
87
|
+
fallback: !1
|
|
88
|
+
}), se = /* @__PURE__ */ d("pont-account-menu", {
|
|
89
|
+
events: {
|
|
90
|
+
onAccountSettings: "pont-account-settings",
|
|
91
|
+
onLogout: "pont-logout",
|
|
92
|
+
onMenuItemClick: "pont-menu-item-click",
|
|
93
|
+
onOpenChange: "pont-open-change"
|
|
94
|
+
},
|
|
95
|
+
fallback: !1
|
|
96
|
+
}), ce = /* @__PURE__ */ d("pont-organization-switcher", {
|
|
97
|
+
events: {
|
|
98
|
+
onOrganizationChanged: "pont-organization-changed",
|
|
99
|
+
onOrganizationSwitchFailed: "pont-organization-switch-failed",
|
|
100
|
+
onOpenChange: "pont-open-change"
|
|
101
|
+
},
|
|
102
|
+
fallback: !1
|
|
103
|
+
}), re = /* @__PURE__ */ d("pont-account-settings", {
|
|
104
|
+
events: {
|
|
105
|
+
onProfileUpdated: "pont-profile-updated",
|
|
106
|
+
onOpenChange: "pont-open-change"
|
|
107
|
+
},
|
|
108
|
+
fallback: !1
|
|
109
|
+
}), le = /* @__PURE__ */ d("pont-member-management", {
|
|
110
|
+
events: {
|
|
111
|
+
onMembersInvited: "pont-members-invited",
|
|
112
|
+
onMemberRolesUpdated: "pont-member-roles-updated",
|
|
113
|
+
onMemberRemoved: "pont-member-removed",
|
|
114
|
+
onInvitationResent: "pont-invitation-resent",
|
|
115
|
+
onInvitationRevoked: "pont-invitation-revoked"
|
|
116
|
+
},
|
|
117
|
+
fallback: !1
|
|
118
|
+
}), ae = /* @__PURE__ */ d("pont-checkout", {
|
|
119
|
+
events: {
|
|
120
|
+
onCheckoutCompleted: "pont-checkout-completed",
|
|
121
|
+
onCheckoutCancelled: "pont-checkout-cancelled"
|
|
122
|
+
},
|
|
123
|
+
fallback: !1
|
|
124
|
+
}), ue = /* @__PURE__ */ d("pont-billing-portal", {
|
|
125
|
+
events: {
|
|
126
|
+
onBillingContractChanged: "pont-billing-contract-changed",
|
|
127
|
+
onBillingContractCancelled: "pont-billing-contract-cancelled",
|
|
128
|
+
onBillingCancellationRevoked: "pont-billing-cancellation-revoked",
|
|
129
|
+
onBillingInvoicePaid: "pont-billing-invoice-paid",
|
|
130
|
+
onBillingPaymentMethodAdded: "pont-billing-payment-method-added",
|
|
131
|
+
onBillingPaymentMethodDefaultChanged: "pont-billing-payment-method-default-changed",
|
|
132
|
+
onBillingPaymentMethodRemoved: "pont-billing-payment-method-removed"
|
|
133
|
+
},
|
|
134
|
+
fallback: !1
|
|
135
|
+
}), J = { isAuthenticated: !1, resolved: !1 }, U = W(void 0);
|
|
136
|
+
function k(e) {
|
|
137
|
+
const t = V(U);
|
|
138
|
+
if (t === void 0)
|
|
139
|
+
throw new Error(
|
|
140
|
+
`${e} was called outside <Provider>. Wrap your app in the Provider from @pontive/pontkit-react (or @pontive/pontkit-nextjs).`
|
|
141
|
+
);
|
|
142
|
+
return t;
|
|
11
143
|
}
|
|
12
|
-
|
|
13
|
-
|
|
144
|
+
const K = I(
|
|
145
|
+
({ children: e, sdk: t, ...c }, n) => {
|
|
146
|
+
const [o, l] = b(null), r = t ?? _, i = Q(o), a = T(o), f = c.signinUrl ?? null, C = H(
|
|
147
|
+
() => ({ auth: i, session: a, sdk: r, signinUrl: f, element: o }),
|
|
148
|
+
[i, a, r, f, o]
|
|
149
|
+
);
|
|
150
|
+
function A(p) {
|
|
151
|
+
l(p), typeof n == "function" ? n(p) : n && (n.current = p);
|
|
152
|
+
}
|
|
153
|
+
return w(
|
|
154
|
+
G,
|
|
155
|
+
{ ...c, sdk: r, ref: A },
|
|
156
|
+
w(U.Provider, { value: C }, e)
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
K.displayName = "Provider";
|
|
161
|
+
function Q(e) {
|
|
162
|
+
const [t, c] = b(J);
|
|
163
|
+
return m(() => {
|
|
164
|
+
if (!e) return;
|
|
165
|
+
let n = !1;
|
|
166
|
+
function o(i) {
|
|
167
|
+
n || !i || c(
|
|
168
|
+
(a) => a.isAuthenticated === i.isAuthenticated && a.resolved === i.resolved ? a : { isAuthenticated: !!i.isAuthenticated, resolved: !!i.resolved }
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
function l(i) {
|
|
172
|
+
o(i.detail);
|
|
173
|
+
}
|
|
174
|
+
function r() {
|
|
175
|
+
o(e?.auth);
|
|
176
|
+
}
|
|
177
|
+
return e.addEventListener("pont-auth-changed", l), r(), customElements.whenDefined("pont-provider").then(r), () => {
|
|
178
|
+
n = !0, e.removeEventListener("pont-auth-changed", l);
|
|
179
|
+
};
|
|
180
|
+
}, [e]), t;
|
|
14
181
|
}
|
|
15
|
-
|
|
16
|
-
|
|
182
|
+
function T(e) {
|
|
183
|
+
const [t, c] = b(null);
|
|
184
|
+
return m(() => {
|
|
185
|
+
if (!e) return;
|
|
186
|
+
function n(o) {
|
|
187
|
+
const l = o.detail;
|
|
188
|
+
l && c({ ...l });
|
|
189
|
+
}
|
|
190
|
+
return e.addEventListener("pont-session-changed", n), () => e.removeEventListener("pont-session-changed", n);
|
|
191
|
+
}, [e]), t;
|
|
17
192
|
}
|
|
18
|
-
|
|
19
|
-
|
|
193
|
+
function y() {
|
|
194
|
+
return k("useAuthState").auth;
|
|
20
195
|
}
|
|
21
|
-
|
|
22
|
-
|
|
196
|
+
function de() {
|
|
197
|
+
return k("useSession").session;
|
|
23
198
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
return typeof window > "u" ? null : t?.Auth ? t.Auth : (console.warn(
|
|
27
|
-
"Auth is not loaded yet! Make sure loadWebComponents() has completed."
|
|
28
|
-
), null);
|
|
199
|
+
function fe() {
|
|
200
|
+
return k("useSdk").sdk;
|
|
29
201
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
202
|
+
function pe() {
|
|
203
|
+
const { element: e, auth: t, session: c } = k("useAccountClient"), [n, o] = b(void 0);
|
|
204
|
+
return m(() => {
|
|
205
|
+
if (!e) return;
|
|
206
|
+
let l = !1;
|
|
207
|
+
function r() {
|
|
208
|
+
if (l) return;
|
|
209
|
+
const i = e?.effectiveAccountClient;
|
|
210
|
+
o((a) => a === i ? a : i);
|
|
36
211
|
}
|
|
37
|
-
return r(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
212
|
+
return r(), customElements.whenDefined("pont-provider").then(r), () => {
|
|
213
|
+
l = !0;
|
|
214
|
+
};
|
|
215
|
+
}, [e, t, c]), n;
|
|
216
|
+
}
|
|
217
|
+
function he({ children: e, fallback: t = null }) {
|
|
218
|
+
const { isAuthenticated: c, resolved: n } = y();
|
|
219
|
+
return n ? c ? e : null : t;
|
|
220
|
+
}
|
|
221
|
+
function ve({ children: e, fallback: t = null }) {
|
|
222
|
+
const { isAuthenticated: c, resolved: n } = y();
|
|
223
|
+
return n ? c ? null : e : t;
|
|
224
|
+
}
|
|
225
|
+
function ge({ children: e, fallback: t = null }) {
|
|
226
|
+
return y().resolved ? e : t;
|
|
227
|
+
}
|
|
228
|
+
function me({
|
|
229
|
+
children: e,
|
|
230
|
+
loading: t = null,
|
|
231
|
+
redirectUrl: c,
|
|
232
|
+
onRedirect: n
|
|
233
|
+
}) {
|
|
234
|
+
const { auth: o, signinUrl: l } = k("Authenticated"), r = P(!1), i = c || l || void 0;
|
|
235
|
+
return m(() => {
|
|
236
|
+
if (!(!o.resolved || o.isAuthenticated || r.current)) {
|
|
237
|
+
if (!i) {
|
|
238
|
+
console.error(
|
|
239
|
+
"[pontive] <Authenticated> has nobody to redirect to: pass `redirectUrl`, or give the Provider a `signinUrl`."
|
|
240
|
+
);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
r.current = !0, n ? n(i) : window.location.href = i;
|
|
244
|
+
}
|
|
245
|
+
}, [o.resolved, o.isAuthenticated, i, n]), o.resolved ? o.isAuthenticated ? e : null : t;
|
|
246
|
+
}
|
|
44
247
|
export {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
q as opeMemberManagementModalAsync,
|
|
65
|
-
W as openAccountSettingsModalAsync,
|
|
66
|
-
D as setLocales,
|
|
67
|
-
F as useAuthProvider,
|
|
68
|
-
T as useAuthState,
|
|
69
|
-
X as useEnvConfig
|
|
248
|
+
se as AccountMenu,
|
|
249
|
+
re as AccountSettings,
|
|
250
|
+
ge as AuthResolved,
|
|
251
|
+
me as Authenticated,
|
|
252
|
+
ue as BillingPortal,
|
|
253
|
+
ae as Checkout,
|
|
254
|
+
ie as Consent,
|
|
255
|
+
oe as Invitation,
|
|
256
|
+
le as MemberManagement,
|
|
257
|
+
ce as OrganizationSwitcher,
|
|
258
|
+
K as Provider,
|
|
259
|
+
he as SignedIn,
|
|
260
|
+
ve as SignedOut,
|
|
261
|
+
ne as Signin,
|
|
262
|
+
te as Signup,
|
|
263
|
+
pe as useAccountClient,
|
|
264
|
+
y as useAuthState,
|
|
265
|
+
fe as useSdk,
|
|
266
|
+
de as useSession
|
|
70
267
|
};
|
|
71
268
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/elements.generated.ts","../src/index.ts"],"sourcesContent":["// GENERATED by tools/gen-wrappers — do not edit.\n//\n// Source: @pontive/pontkit-core@1.41.0 custom-elements.json.\n// Which elements are wrapped, and under what name, is in\n// tools/gen-wrappers/elements.config.mjs.\n//\n// The element classes are imported as TYPES only. This package must never\n// bundle core: the loader fetches it from the CDN at a release the platform\n// decides, so a value import here would ship a second, pinned copy.\nimport type {\n PontProvider,\n PreviewComponent as PontPreview,\n PontKitLayout as PontLayout,\n PontSignIn as PontSignin,\n PontSignUp as PontSignup,\n PontAccountSettings,\n PontMemberManagement,\n PontAccountMenu,\n PontOrganizationSwitcher,\n PontAccountInfo,\n PontLocationInfo,\n PontUrlsInfo,\n PontPersonalInfo,\n} from \"@pontive/pontkit-core\";\n\nimport { wrap } from \"./wrap\";\nimport type {\n ProviderProps,\n PreviewProps,\n LayoutProps,\n SignInProps,\n SignUpProps,\n AccountSettingsProps,\n MemberManagementProps,\n AccountMenuProps,\n OrganizationSwitcherProps,\n AccountInfoProps,\n LocationInfoProps,\n UrlsInfoProps,\n PersonalInfoProps,\n} from \"./types\";\n\nexport const ProviderElement = /* @__PURE__ */ wrap<PontProvider, ProviderProps>(\"pont-provider\");\nexport const Preview = /* @__PURE__ */ wrap<PontPreview, PreviewProps>(\"pont-preview\");\nexport const Layout = /* @__PURE__ */ wrap<PontLayout, LayoutProps>(\"pont-layout\");\nexport const Signin = /* @__PURE__ */ wrap<PontSignin, SignInProps>(\"pont-signin\");\nexport const Signup = /* @__PURE__ */ wrap<PontSignup, SignUpProps>(\"pont-signup\");\nexport const AccountSettings = /* @__PURE__ */ wrap<PontAccountSettings, AccountSettingsProps>(\"pont-account-settings\");\nexport const MemberManagement = /* @__PURE__ */ wrap<PontMemberManagement, MemberManagementProps>(\"pont-member-management\");\nexport const AccountMenu = /* @__PURE__ */ wrap<PontAccountMenu, AccountMenuProps>(\"pont-account-menu\");\nexport const OrganizationSwitcher = /* @__PURE__ */ wrap<PontOrganizationSwitcher, OrganizationSwitcherProps>(\"pont-organization-switcher\");\nexport const AccountInfo = /* @__PURE__ */ wrap<PontAccountInfo, AccountInfoProps>(\"pont-account-info\");\nexport const LocationInfo = /* @__PURE__ */ wrap<PontLocationInfo, LocationInfoProps>(\"pont-location-info\");\nexport const UrlsInfo = /* @__PURE__ */ wrap<PontUrlsInfo, UrlsInfoProps>(\"pont-urls-info\");\nexport const PersonalInfo = /* @__PURE__ */ wrap<PontPersonalInfo, PersonalInfoProps>(\"pont-personal-info\");\n","import {\n AccountInfoProps,\n LayoutProps,\n LocationInfoProps,\n PersonalInfoProps,\n PreviewProps,\n ProviderProps,\n SignInProps,\n SignUpProps,\n UrlsInfoProps,\n AccountMenuProps,\n OrganizationSwitcherProps,\n OrganizationChangedDetail,\n AccountSettingsProps,\n MemberManagementProps,\n} from \"./types\";\nimport { createElement, forwardRef, useMemo, useState } from \"react\";\nimport { ensureCoreSdkLoaded } from \"@pontive/pontkit-loader\";\nimport { wrap } from \"./wrap\";\nimport type { PontProvider } from \"@pontive/pontkit-core\";\n\n// Re-exported for consumers. A host constructing the `env` object needs\n// EnvConfig, and useAuthState returns AuthState — without these the only way to\n// name either type is to install @pontive/pontkit-core, which is exactly what\n// this package exists to avoid: core is fetched from the CDN at a release the\n// platform picks, not installed and bundled by the app.\nexport type { EnvConfig, AuthState } from \"@pontive/pontkit-core\";\n\n// The element wrappers, generated from core's custom-elements.json by\n// tools/gen-wrappers. `npm run gen` rewrites it; `npm run gen -- --check`\n// fails when it has drifted from the installed core.\nexport {\n Preview,\n Layout,\n Signin,\n Signup,\n AccountSettings,\n MemberManagement,\n AccountMenu,\n OrganizationSwitcher,\n AccountInfo,\n LocationInfo,\n UrlsInfo,\n PersonalInfo,\n} from \"./elements.generated\";\nimport { ProviderElement } from \"./elements.generated\";\nimport { AuthStateProvider, useProviderAuthState } from \"./auth\";\nimport { useProviderPresence } from \"./coexistence\";\n// The element classes, for typing only. `import type` matters: this package\n// must never BUNDLE core — the loader fetches it from the CDN at a release the\n// platform picks, so a value import here would ship a second, pinned copy.\nimport type { AuthService } from \"@pontive/oidc-client\";\n\n/**\n * The loaded SDK, or undefined when there is no browser to have loaded it.\n *\n * `ensureCoreSdkLoaded()` returns early on a server, but returning is not the\n * same as making the next line safe: reading `window.__pontCoreSdk` after it\n * still throws. Optional chaining does not help — `?.` guards the property, not\n * the undeclared identifier it hangs off.\n */\n/**\n * What this package uses off the loaded SDK.\n *\n * Deliberately NOT `Window[\"__pontCoreSdk\"]`. @pontive/pontkit-core declares\n * that global as five modal helpers, which is narrower than what is actually\n * there — the loader assigns the whole core module plus a wrapped `Auth`.\n * Reading the declared type therefore loses `Auth`, and widening core's\n * declaration to describe an entire module is not worth the coupling. This\n * states what the bindings need and nothing else.\n */\ntype CoreSdk = {\n Auth?: AuthService;\n setLocales?: (locales: string) => void;\n openAccountSettingsModal?: () => void;\n closeAccountSettingsModal?: () => void;\n openMemberManagementModal?: () => void;\n closeMemberManagementModal?: () => void;\n};\n\nfunction coreSdk(): CoreSdk | undefined {\n return typeof window === \"undefined\"\n ? undefined\n : (window as unknown as { __pontCoreSdk?: CoreSdk }).__pontCoreSdk;\n}\n\nexport async function openAccountSettingsModalAsync() {\n await ensureCoreSdkLoaded();\n coreSdk()?.openAccountSettingsModal?.();\n}\n\nexport async function closeAccountSettingsModalAsync() {\n await ensureCoreSdkLoaded();\n coreSdk()?.closeAccountSettingsModal?.();\n}\n\nexport async function opeMemberManagementModalAsync() {\n await ensureCoreSdkLoaded();\n coreSdk()?.openMemberManagementModal?.();\n}\n\nexport async function closeMemberManagementModalAsync() {\n await ensureCoreSdkLoaded();\n coreSdk()?.closeMemberManagementModal?.();\n}\n\nexport async function setLocales(locales: string) {\n await ensureCoreSdkLoaded();\n coreSdk()?.setLocales?.(locales);\n}\n\nexport function useAuthProvider() {\n const sdk = coreSdk();\n\n // Silent on a server. The warning below is for a browser that asked too\n // early, which is actionable; on a server there is no SDK to wait for and the\n // message would fire on every render while describing nothing wrong.\n if (typeof window === \"undefined\") {\n return null;\n }\n\n if (!sdk?.Auth) {\n console.warn(\n \"Auth is not loaded yet! Make sure loadWebComponents() has completed.\",\n );\n return null;\n }\n\n return sdk.Auth;\n}\n\n/**\n * Configures the SDK, and publishes the session to React.\n *\n * The element half is unchanged — `env` still travels to `<pont-provider>` through\n * `wrap()`, and the widgets still read everything they need from its Lit\n * contexts. What is added is the second audience: `<SignedIn>` and\n * `<SignedOut>` are ordinary React components now, so they need the session as\n * React context rather than as a Lit context only custom elements can see.\n *\n * Both come from the same value. The provider dispatches `pont:auth-changed`\n * whenever it writes its auth state, and this listens on the element it just\n * rendered.\n */\nexport const Provider = forwardRef<PontProvider, ProviderProps>(\n ({ children, ...props }, forwardedRef) => {\n useProviderPresence(\"legacy\");\n const [element, setElement] = useState<PontProvider | null>(null);\n const auth = useProviderAuthState(element, \"pont-provider\");\n const env = (props as ProviderProps).env ?? null;\n const contextValue = useMemo(() => ({ auth, env }), [auth, env]);\n\n // State rather than a ref, because the subscription has to re-run when the\n // element arrives and a ref mutation does not re-render.\n function captureRef(el: PontProvider | null) {\n setElement(el);\n\n if (typeof forwardedRef === \"function\") forwardedRef(el);\n else if (forwardedRef) forwardedRef.current = el;\n }\n\n return createElement(\n ProviderElement,\n { ...(props as ProviderProps), ref: captureRef },\n createElement(AuthStateProvider, { value: contextValue }, children),\n );\n },\n);\n\n\n\n\n/**\n * `<SignedIn>` and `<SignedOut>` are React components rather than wrappers over\n * `<pont-signed-in>` / `<pont-signed-out>`, which cached their children on connect\n * and re-rendered them inside a `<div>` of their own — DOM React believed it\n * still owned. See ./auth.ts. The elements remain for the web-components entry.\n */\nexport {\n Authenticated,\n AuthResolved,\n SignedIn,\n SignedOut,\n useAuthState,\n useEnvConfig,\n} from \"./auth\";\nexport type { AuthenticatedProps, ControlProps } from \"./auth\";\n"],"names":["ProviderElement","Preview","Layout","Signin","Signup","AccountSettings","MemberManagement","AccountMenu","OrganizationSwitcher","AccountInfo","LocationInfo","UrlsInfo","PersonalInfo","coreSdk","openAccountSettingsModalAsync","ensureCoreSdkLoaded","closeAccountSettingsModalAsync","opeMemberManagementModalAsync","closeMemberManagementModalAsync","setLocales","locales","useAuthProvider","sdk","Provider","forwardRef","children","props","forwardedRef","useProviderPresence","element","setElement","useState","auth","useProviderAuthState","env","contextValue","useMemo","captureRef","el","createElement","AuthStateProvider"],"mappings":";;;;AA0CO,MAAMA,sBAAoE,eAAe,GACnFC,sBAA0D,cAAc,GACxEC,sBAAuD,aAAa,GACpEC,sBAAuD,aAAa,GACpEC,sBAAuD,aAAa,GACpEC,sBAAkF,uBAAuB,GACzGC,sBAAqF,wBAAwB,GAC7GC,sBAAsE,mBAAmB,GACzFC,sBAAiG,4BAA4B,GAC7HC,sBAAsE,mBAAmB,GACzFC,sBAAyE,oBAAoB,GAC7FC,sBAA6D,gBAAgB,GAC7EC,sBAAyE,oBAAoB;AC0B1G,SAASC,IAA+B;AACtC,SAAO,OAA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.ts"],"sourcesContent":["import React, {\n createElement,\n forwardRef,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { loadWebComponents } from \"@pontive/pontkit-loader\";\n\n/**\n * React components over the custom elements the core SDK defines.\n *\n * One rule holds this file together, and every bug it used to have was a\n * violation of it: **React owns the tag, the element owns everything inside it,\n * and React never reconciles a node the element touches.**\n *\n * The version this replaces built `<pont-provider>` with `document.createElement`\n * and then spliced it into the page by hand:\n *\n * parent.replaceChild(providerEl, container);\n * providerEl.appendChild(container);\n *\n * That moves a div React rendered, and owns, underneath an element React has\n * never heard of. React keeps its own picture of the DOM and does not re-read\n * it, so from that moment its picture said the container was a child of\n * `<body>` while the browser said it was a child of `<pont-provider>`. The two\n * disagreed silently until React next placed a node against that container:\n *\n * NotFoundError: Failed to execute 'insertBefore' on 'Node': the node\n * before which the new node is to be inserted is not a child of this node.\n *\n * The throw lands in React's commit phase, which has no recovery — the tree is\n * abandoned mid-commit and the application disappears from the page. In a\n * Next.js app it fired on the first client-side navigation, so signing in\n * appeared to work and then left a blank document behind.\n *\n * Rendering the tag is both the fix and the simpler thing. A custom element is\n * inert until its definition arrives and upgrades in place when it does, so\n * there is nothing to wait for and nothing to move; the `sdkReady` gate that\n * used to hold every widget back until the CDN answered bought nothing and is\n * gone with it. Widgets now server-render as empty tags and fill themselves in\n * on upgrade, which is what a custom element is for.\n */\n\n/**\n * Props React sets itself, because they are ordinary DOM attributes rather than\n * component inputs. Everything else is assigned as a property — see below for\n * why that distinction cannot be left to React.\n */\nconst DOM_PROPS = new Set([\"className\", \"style\", \"id\", \"slot\"]);\n\ntype UnknownProps = Record<string, unknown>;\n\n/**\n * Everything here has to be in place before the element's first update, and a\n * passive effect is not.\n *\n * Lit schedules its update as a microtask when the element connects, which is\n * during React's commit; passive effects are flushed in a later task. On a cold\n * load nobody notices, because the element is waiting on the CDN and a network\n * round trip. On a client-side navigation, where the provider has already\n * resolved the session, the element updates and goes looking for its\n * placeholder immediately — and a placeholder created in a passive effect does\n * not exist yet, so the element never removes it and it stays on screen over\n * the finished widget. A layout effect runs synchronously in the commit, before\n * the stack unwinds and Lit's microtask gets its turn.\n *\n * On a server there is no layout to read, and React warns about useLayoutEffect\n * for that reason. useEffect is the same no-op without the noise.\n */\nconst useIsomorphicLayoutEffect =\n typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\n/**\n * What a wrapper says about its element (generated, see tools/gen-wrappers).\n */\nexport interface WrapOptions {\n /**\n * Callback prop -> DOM event. The elements report through events, so these\n * props are listened for instead of assigned, and the callback gets the\n * event itself (a cancelable one can be `preventDefault()`ed).\n */\n events?: Readonly<Record<string, string>>;\n /** Whether the element honours the `[part=\"fallback\"]` contract. */\n fallback?: boolean;\n /** Starts the CDN load on mount. */\n provider?: boolean;\n}\n\n/**\n * A React component over the custom element `tagName`, typed by `P` alone:\n * children and `fallback` are whatever its props type says, because only the\n * provider takes children and only the flow widgets honour a fallback.\n */\nexport function wrap<T extends HTMLElement, P = {}>(\n tagName: string,\n options: WrapOptions = {},\n): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>> {\n type Props = P & React.RefAttributes<T>;\n\n const isProvider = !!options.provider;\n const events = options.events ?? {};\n const eventProps = new Set(Object.keys(events));\n const fallbackAllowed = !!options.fallback;\n\n const component = forwardRef<T, Props>((props, forwardedRef) => {\n const elementRef = useRef<T | null>(null);\n const assigned = useRef<UnknownProps>({});\n // The latest callbacks, read when an event fires, so a new function on\n // every render does not re-subscribe.\n const callbacks = useRef<UnknownProps>({});\n const [fallbackHost, setFallbackHost] = useState<HTMLElement | null>(null);\n\n const { fallback, children, ...rest } = props as UnknownProps & {\n fallback?: React.ReactNode;\n children?: React.ReactNode;\n };\n\n const domProps: UnknownProps = {};\n const elementProps: UnknownProps = {};\n\n const eventCallbacks: UnknownProps = {};\n\n for (const [key, value] of Object.entries(rest)) {\n if (eventProps.has(key)) eventCallbacks[key] = value;\n else (DOM_PROPS.has(key) ? domProps : elementProps)[key] = value;\n }\n\n callbacks.current = eventCallbacks;\n\n // The provider is the one component every app mounts, which makes it the\n // honest place to start the CDN fetch. Importing the root entry also kicks\n // it off, but the React entry can be imported on its own.\n useEffect(() => {\n if (!isProvider) return;\n loadWebComponents().catch(console.error);\n }, []);\n\n /**\n * Component inputs are assigned as DOM properties, once the tag is defined.\n *\n * Both halves of that matter. An attribute can only ever hold a string, so\n * `headers` and `items` cannot travel as one — and React 19's own custom\n * element support does not save us here, because it chooses between\n * property and attribute by testing `'headers' in element`. The definitions\n * arrive from a CDN long after React first renders, so that test runs\n * against an un-upgraded element, finds no property, and writes the\n * attribute `headers=\"[object Object]\"` for Lit to try to parse.\n *\n * Waiting for the definition is the other half. Assigning to an element\n * that has not upgraded writes an own property, and Lit's accessor — added\n * to the prototype at upgrade — is then shadowed by it for good: the value\n * sits on the element in plain sight and the component never observes it.\n */\n useIsomorphicLayoutEffect(() => {\n const el = elementRef.current;\n if (!el) return;\n\n let cancelled = false;\n\n function assign() {\n if (cancelled || !el) return;\n\n for (const [key, value] of Object.entries(elementProps)) {\n // Re-assigning an unchanged value would still mark the property\n // dirty and re-render the element on every React render.\n if (assigned.current[key] === value) continue;\n\n try {\n (el as unknown as UnknownProps)[key] = value;\n assigned.current[key] = value;\n } catch {\n // A read-only property on the element is the element's business.\n }\n }\n }\n\n if (customElements.get(tagName)) assign();\n else void customElements.whenDefined(tagName).then(assign);\n\n return () => {\n cancelled = true;\n };\n });\n\n /**\n * The element's events, mapped to callback props.\n *\n * Subscribed in a layout effect, like the properties above, so an event\n * fired during the element's first update is not missed. Listening needs\n * no definition: an un-upgraded element is still an event target.\n */\n useIsomorphicLayoutEffect(() => {\n const el = elementRef.current;\n if (!el || eventProps.size === 0) return;\n\n const listeners = Object.entries(events).map(([prop, type]) => {\n const listener = (event: Event) => {\n const callback = callbacks.current[prop];\n if (typeof callback === \"function\") callback(event);\n };\n el.addEventListener(type, listener);\n return () => el.removeEventListener(type, listener);\n });\n\n return () => listeners.forEach((remove) => remove());\n }, []);\n\n /**\n * The fallback is rendered through a portal into a node built by hand.\n *\n * Every widget looks for a `[part=\"fallback\"]` child once it has something\n * real to show, and removes it — that is the placeholder's whole contract,\n * and `[pont-signin] fallback not found yet` on repeat is that search coming\n * up empty. But a React child that something else deletes is the same\n * desynchronised DOM described at the top of this file, so React cannot own\n * the node it hands over.\n *\n * A portal splits the difference: the host div is ours to give away, while\n * the content inside it stays an ordinary part of the React tree. When the\n * element deletes the host, React's nodes go with it into a detached\n * subtree it can still unmount from safely.\n *\n * The host is built after mount rather than during render, and that is not\n * a stylistic choice. Building it during render means branching on\n * `typeof document`, so the server renders no portal and the client's\n * hydration render does — React compares the two and reports\n *\n * Hydration failed because the server rendered HTML didn't match the\n * client\n *\n * naming the placeholder as the extra node. Creating it here keeps the\n * first client render identical to the server's; the state update below is\n * flushed synchronously before paint, so the placeholder still lands ahead\n * of the element's first update.\n *\n * The cost is that the placeholder does not server-render. The window it\n * covers is the CDN fetch, which is far longer than the one before\n * hydration, so this is nearly all of what the placeholder was for.\n */\n useIsomorphicLayoutEffect(() => {\n const el = elementRef.current;\n if (!el || fallback == null || !fallbackAllowed) return;\n\n const host = document.createElement(\"div\");\n host.setAttribute(\"part\", \"fallback\");\n el.prepend(host);\n setFallbackHost(host);\n\n return () => {\n // A no-op once the element has removed it, which is the ordinary case.\n host.remove();\n setFallbackHost(null);\n };\n }, [fallback == null]);\n\n function setRef(el: T | null) {\n elementRef.current = el;\n\n if (typeof forwardedRef === \"function\") forwardedRef(el);\n else if (forwardedRef) forwardedRef.current = el;\n }\n\n return createElement(\n tagName,\n { ...domProps, ref: setRef },\n children ?? null,\n fallbackHost ? createPortal(fallback, fallbackHost) : null,\n );\n });\n\n component.displayName = `wrap(${tagName})`;\n\n return component as unknown as React.ForwardRefExoticComponent<\n React.PropsWithoutRef<P> & React.RefAttributes<T>\n >;\n}\n","// GENERATED by tools/gen-wrappers — do not edit.\n//\n// Source: @pontive/pontkit-core@1.46.0 custom-elements.json.\n// Which elements are wrapped, and under what name, is WRAPPED in\n// tools/gen-wrappers/elements.config.mjs; the events are the manifest's.\n//\n// The element classes are imported as TYPES only. This package must never\n// bundle core: the loader fetches it from the CDN at a release the platform\n// decides, so a value import here would ship a second, pinned copy.\nimport type {\n Provider as PontProviderElement,\n SignIn as PontSigninElement,\n SignUp as PontSignupElement,\n Invitation as PontInvitationElement,\n Consent as PontConsentElement,\n AccountMenu as PontAccountMenuElement,\n OrganizationSwitcher as PontOrganizationSwitcherElement,\n AccountSettings as PontAccountSettingsElement,\n MemberManagement as PontMemberManagementElement,\n Checkout as PontCheckoutElement,\n BillingPortal as PontBillingPortalElement,\n} from \"@pontive/pontkit-core\";\n\nimport { wrap } from \"./wrap\";\nimport type {\n PontEvent,\n ProviderElementProps,\n FlowWidgetProps,\n ConsentProps,\n AccountMenuProps,\n OrganizationSwitcherProps,\n AccountSettingsProps,\n MemberManagementProps,\n CheckoutProps,\n BillingPortalProps,\n} from \"./types\";\n\nexport type {\n PontProviderElement,\n PontSigninElement,\n PontSignupElement,\n PontInvitationElement,\n PontConsentElement,\n PontAccountMenuElement,\n PontOrganizationSwitcherElement,\n PontAccountSettingsElement,\n PontMemberManagementElement,\n PontCheckoutElement,\n PontBillingPortalElement,\n};\n\n/** The `pont-provider` events, as callback props. */\nexport interface ProviderElementEvents {\n /** `pont-auth-changed`: `AuthState` (a copy), whenever it changes */\n onAuthChanged?: (event: PontEvent<\"pont-auth-changed\">) => void;\n /** `pont-locale-changed`: `{ locales }`, whenever the configured locales change */\n onLocaleChanged?: (event: PontEvent<\"pont-locale-changed\">) => void;\n /** `pont-session-changed`: `{ reason, source, isAuthenticated, organizationId }`, on every SDK session change, here or in another tab (no tokens) */\n onSessionChanged?: (event: PontEvent<\"pont-session-changed\">) => void;\n /** `pont-redirect`: `{ url }`, cancelable, before a post-sign-in navigation */\n onRedirect?: (event: PontEvent<\"pont-redirect\">) => void;\n}\n\nexport const ProviderElement = /* @__PURE__ */ wrap<PontProviderElement, ProviderElementProps & ProviderElementEvents>(\"pont-provider\", {\n events: {\n onAuthChanged: \"pont-auth-changed\",\n onLocaleChanged: \"pont-locale-changed\",\n onSessionChanged: \"pont-session-changed\",\n onRedirect: \"pont-redirect\",\n },\n fallback: false,\n provider: true,\n});\n\n/** The `pont-signin` events, as callback props. */\nexport interface SigninEvents {\n /** `pont-flow-response`: (from the layout) after every successful request */\n onFlowResponse?: (event: PontEvent<\"pont-flow-response\">) => void;\n}\n\nexport const Signin = /* @__PURE__ */ wrap<PontSigninElement, FlowWidgetProps & SigninEvents>(\"pont-signin\", {\n events: {\n onFlowResponse: \"pont-flow-response\",\n },\n fallback: true,\n});\n\n/** The `pont-signup` events, as callback props. */\nexport interface SignupEvents {\n /** `pont-flow-response`: (from the layout) after every successful request */\n onFlowResponse?: (event: PontEvent<\"pont-flow-response\">) => void;\n}\n\nexport const Signup = /* @__PURE__ */ wrap<PontSignupElement, FlowWidgetProps & SignupEvents>(\"pont-signup\", {\n events: {\n onFlowResponse: \"pont-flow-response\",\n },\n fallback: true,\n});\n\n/** The `pont-invitation` events, as callback props. */\nexport interface InvitationEvents {\n /** `pont-flow-response`: (from the layout) after every successful request */\n onFlowResponse?: (event: PontEvent<\"pont-flow-response\">) => void;\n}\n\nexport const Invitation = /* @__PURE__ */ wrap<PontInvitationElement, FlowWidgetProps & InvitationEvents>(\"pont-invitation\", {\n events: {\n onFlowResponse: \"pont-flow-response\",\n },\n fallback: true,\n});\n\n/** The `pont-consent` events, as callback props. */\nexport interface ConsentEvents {}\n\nexport const Consent = /* @__PURE__ */ wrap<PontConsentElement, ConsentProps & ConsentEvents>(\"pont-consent\", {\n events: {},\n fallback: false,\n});\n\n/** The `pont-account-menu` events, as callback props. */\nexport interface AccountMenuEvents {\n /** `pont-account-settings`: cancelable, `{}`: \"Account settings\" was chosen */\n onAccountSettings?: (event: PontEvent<\"pont-account-settings\">) => void;\n /** `pont-logout`: cancelable, `{}`: \"Log out\" was chosen */\n onLogout?: (event: PontEvent<\"pont-logout\">) => void;\n /** `pont-menu-item-click`: cancelable `{ item, checked?, value? }`: one of `items` was chosen */\n onMenuItemClick?: (event: PontEvent<\"pont-menu-item-click\">) => void;\n /** `pont-open-change`: cancelable `{ open, reason }` (the menu's) */\n onOpenChange?: (event: PontEvent<\"pont-open-change\">) => void;\n}\n\nexport const AccountMenu = /* @__PURE__ */ wrap<PontAccountMenuElement, AccountMenuProps & AccountMenuEvents>(\"pont-account-menu\", {\n events: {\n onAccountSettings: \"pont-account-settings\",\n onLogout: \"pont-logout\",\n onMenuItemClick: \"pont-menu-item-click\",\n onOpenChange: \"pont-open-change\",\n },\n fallback: false,\n});\n\n/** The `pont-organization-switcher` events, as callback props. */\nexport interface OrganizationSwitcherEvents {\n /** `pont-organization-changed`: `{ organizationId, roles, permissions }`, after a switch */\n onOrganizationChanged?: (event: PontEvent<\"pont-organization-changed\">) => void;\n /** `pont-organization-switch-failed`: `{ organizationId, error }`, when a switch is refused */\n onOrganizationSwitchFailed?: (event: PontEvent<\"pont-organization-switch-failed\">) => void;\n /** `pont-open-change`: cancelable `{ open, reason }` (the menu's) */\n onOpenChange?: (event: PontEvent<\"pont-open-change\">) => void;\n}\n\nexport const OrganizationSwitcher = /* @__PURE__ */ wrap<PontOrganizationSwitcherElement, OrganizationSwitcherProps & OrganizationSwitcherEvents>(\"pont-organization-switcher\", {\n events: {\n onOrganizationChanged: \"pont-organization-changed\",\n onOrganizationSwitchFailed: \"pont-organization-switch-failed\",\n onOpenChange: \"pont-open-change\",\n },\n fallback: false,\n});\n\n/** The `pont-account-settings` events, as callback props. */\nexport interface AccountSettingsEvents {\n /** `pont-profile-updated`: `{ section, profile }`, after a section was saved */\n onProfileUpdated?: (event: PontEvent<\"pont-profile-updated\">) => void;\n /** `pont-open-change`: modal mode: cancelable `{ open, reason }` (the dialog's) */\n onOpenChange?: (event: PontEvent<\"pont-open-change\">) => void;\n}\n\nexport const AccountSettings = /* @__PURE__ */ wrap<PontAccountSettingsElement, AccountSettingsProps & AccountSettingsEvents>(\"pont-account-settings\", {\n events: {\n onProfileUpdated: \"pont-profile-updated\",\n onOpenChange: \"pont-open-change\",\n },\n fallback: false,\n});\n\n/** The `pont-member-management` events, as callback props. */\nexport interface MemberManagementEvents {\n /** `pont-members-invited`: `{ organizationId, emails, roles, invitations }` */\n onMembersInvited?: (event: PontEvent<\"pont-members-invited\">) => void;\n /** `pont-member-roles-updated`: `{ organizationId, userId, roles }` */\n onMemberRolesUpdated?: (event: PontEvent<\"pont-member-roles-updated\">) => void;\n /** `pont-member-removed`: `{ organizationId, userId }` */\n onMemberRemoved?: (event: PontEvent<\"pont-member-removed\">) => void;\n /** `pont-invitation-resent`: `{ organizationId, invitationId, email }` */\n onInvitationResent?: (event: PontEvent<\"pont-invitation-resent\">) => void;\n /** `pont-invitation-revoked`: `{ organizationId, invitationId, email, notifyInvitee }` */\n onInvitationRevoked?: (event: PontEvent<\"pont-invitation-revoked\">) => void;\n}\n\nexport const MemberManagement = /* @__PURE__ */ wrap<PontMemberManagementElement, MemberManagementProps & MemberManagementEvents>(\"pont-member-management\", {\n events: {\n onMembersInvited: \"pont-members-invited\",\n onMemberRolesUpdated: \"pont-member-roles-updated\",\n onMemberRemoved: \"pont-member-removed\",\n onInvitationResent: \"pont-invitation-resent\",\n onInvitationRevoked: \"pont-invitation-revoked\",\n },\n fallback: false,\n});\n\n/** The `pont-checkout` events, as callback props. */\nexport interface CheckoutEvents {\n /** `pont-checkout-completed`: `{ sessionId, contractId, url }`, cancelable: cancel it to stay on the page */\n onCheckoutCompleted?: (event: PontEvent<\"pont-checkout-completed\">) => void;\n /** `pont-checkout-cancelled`: `{ sessionId, url }`, cancelable: cancel it to handle Cancel yourself */\n onCheckoutCancelled?: (event: PontEvent<\"pont-checkout-cancelled\">) => void;\n}\n\nexport const Checkout = /* @__PURE__ */ wrap<PontCheckoutElement, CheckoutProps & CheckoutEvents>(\"pont-checkout\", {\n events: {\n onCheckoutCompleted: \"pont-checkout-completed\",\n onCheckoutCancelled: \"pont-checkout-cancelled\",\n },\n fallback: false,\n});\n\n/** The `pont-billing-portal` events, as callback props. */\nexport interface BillingPortalEvents {\n /** `pont-billing-contract-changed`: `{ customerId, contractId }` */\n onBillingContractChanged?: (event: PontEvent<\"pont-billing-contract-changed\">) => void;\n /** `pont-billing-contract-cancelled`: `{ customerId, contractId }` */\n onBillingContractCancelled?: (event: PontEvent<\"pont-billing-contract-cancelled\">) => void;\n /** `pont-billing-cancellation-revoked`: `{ customerId, contractId }` */\n onBillingCancellationRevoked?: (event: PontEvent<\"pont-billing-cancellation-revoked\">) => void;\n /** `pont-billing-invoice-paid`: `{ customerId, invoiceId }` */\n onBillingInvoicePaid?: (event: PontEvent<\"pont-billing-invoice-paid\">) => void;\n /** `pont-billing-payment-method-added`: `{ customerId, paymentMethodId }` */\n onBillingPaymentMethodAdded?: (event: PontEvent<\"pont-billing-payment-method-added\">) => void;\n /** `pont-billing-payment-method-default-changed`: `{ customerId, paymentMethodId }` */\n onBillingPaymentMethodDefaultChanged?: (event: PontEvent<\"pont-billing-payment-method-default-changed\">) => void;\n /** `pont-billing-payment-method-removed`: `{ customerId, paymentMethodId }` */\n onBillingPaymentMethodRemoved?: (event: PontEvent<\"pont-billing-payment-method-removed\">) => void;\n}\n\nexport const BillingPortal = /* @__PURE__ */ wrap<PontBillingPortalElement, BillingPortalProps & BillingPortalEvents>(\"pont-billing-portal\", {\n events: {\n onBillingContractChanged: \"pont-billing-contract-changed\",\n onBillingContractCancelled: \"pont-billing-contract-cancelled\",\n onBillingCancellationRevoked: \"pont-billing-cancellation-revoked\",\n onBillingInvoicePaid: \"pont-billing-invoice-paid\",\n onBillingPaymentMethodAdded: \"pont-billing-payment-method-added\",\n onBillingPaymentMethodDefaultChanged: \"pont-billing-payment-method-default-changed\",\n onBillingPaymentMethodRemoved: \"pont-billing-payment-method-removed\",\n },\n fallback: false,\n});\n","import React, {\n createContext,\n createElement,\n forwardRef,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Auth } from \"@pontive/oidc-client\";\nimport { ProviderElement } from \"./elements.generated\";\nimport type {\n PontProviderElement,\n ProviderElementEvents,\n} from \"./elements.generated\";\nimport type {\n AccountClient,\n AuthState,\n ProviderInputProps,\n ProviderSdk,\n SessionChange,\n} from \"./types\";\n\n/**\n * `<Provider>`: `<pont-provider>` for React.\n *\n * What the element can't do for itself is get the SDK: core never imports the\n * auth client, it is injected (`provider.sdk = Auth`, pontkit-core\n * docs/kit/provider.md). This injects it, and turns the element's\n * `pont-auth-changed` / `pont-session-changed` into React context.\n *\n * **Which `Auth`.** `@pontive/oidc-client`'s, a dependency of this package, so\n * the app bundles exactly one copy (shared with the app's own, when it imports\n * the same package). An app with another client passes `sdk` instead. `Auth`\n * is a singleton whose constructor touches nothing, so importing it on a\n * server is safe; the element only calls it in the browser.\n */\n\nexport interface ProviderProps\n extends ProviderInputProps,\n ProviderElementEvents {\n children?: React.ReactNode;\n /** The auth SDK. Default: `Auth` from `@pontive/oidc-client`. */\n sdk?: ProviderSdk;\n}\n\nconst UNRESOLVED: AuthState = { isAuthenticated: false, resolved: false };\n\ninterface PontContextValue {\n auth: AuthState;\n /** The last `pont-session-changed`, or null before the first. */\n session: SessionChange | null;\n /** The SDK the provider injected. */\n sdk: ProviderSdk;\n /** `<Authenticated>`'s default redirect target. */\n signinUrl: string | null;\n /** The `<pont-provider>` element, once mounted. */\n element: PontProviderElement | null;\n}\n\n/** `undefined` means \"no provider above\", which the hooks report. */\nconst PontContext = createContext<PontContextValue | undefined>(undefined);\n\nfunction usePontContext(caller: string): PontContextValue {\n const value = useContext(PontContext);\n\n if (value === undefined) {\n throw new Error(\n `${caller} was called outside <Provider>. Wrap your app in the ` +\n \"Provider from @pontive/pontkit-react (or @pontive/pontkit-nextjs).\",\n );\n }\n\n return value;\n}\n\nexport const Provider = forwardRef<PontProviderElement, ProviderProps>(\n ({ children, sdk: ownSdk, ...props }, forwardedRef) => {\n const [element, setElement] = useState<PontProviderElement | null>(null);\n const sdk = ownSdk ?? (Auth as unknown as ProviderSdk);\n const auth = useProviderAuthState(element);\n const session = useSessionChange(element);\n const signinUrl = props.signinUrl ?? null;\n\n const contextValue = useMemo<PontContextValue>(\n () => ({ auth, session, sdk, signinUrl, element }),\n [auth, session, sdk, signinUrl, element],\n );\n\n // State rather than a ref: the subscriptions re-run when the element arrives.\n function captureRef(el: PontProviderElement | null) {\n setElement(el);\n\n if (typeof forwardedRef === \"function\") forwardedRef(el);\n else if (forwardedRef) forwardedRef.current = el;\n }\n\n return createElement(\n ProviderElement,\n { ...props, sdk, ref: captureRef },\n createElement(PontContext.Provider, { value: contextValue }, children),\n );\n },\n);\n\nProvider.displayName = \"Provider\";\n\n/**\n * Tracks the session by listening to the provider element.\n *\n * Subscribing is not enough on its own: the provider resolves after a network\n * round trip, but nothing guarantees that happens after this listener is\n * attached (a Provider mounted into a running app has missed the event). So\n * the element's own `auth` is read as a seed, both immediately and once the\n * definition has arrived, since before the upgrade there is nothing to read.\n */\nfunction useProviderAuthState(element: HTMLElement | null): AuthState {\n const [auth, setAuth] = useState<AuthState>(UNRESOLVED);\n\n useEffect(() => {\n if (!element) return;\n\n let cancelled = false;\n\n function accept(next: AuthState | undefined) {\n if (cancelled || !next) return;\n\n setAuth((current) =>\n current.isAuthenticated === next.isAuthenticated &&\n current.resolved === next.resolved\n ? current\n : { isAuthenticated: !!next.isAuthenticated, resolved: !!next.resolved },\n );\n }\n\n function onAuthChanged(event: Event) {\n accept((event as CustomEvent<AuthState>).detail);\n }\n\n function seed() {\n accept((element as unknown as { auth?: AuthState } | null)?.auth);\n }\n\n element.addEventListener(\"pont-auth-changed\", onAuthChanged);\n seed();\n void customElements.whenDefined(\"pont-provider\").then(seed);\n\n return () => {\n cancelled = true;\n element.removeEventListener(\"pont-auth-changed\", onAuthChanged);\n };\n }, [element]);\n\n return auth;\n}\n\n/** The last `pont-session-changed` the element announced. */\nfunction useSessionChange(element: HTMLElement | null): SessionChange | null {\n const [session, setSession] = useState<SessionChange | null>(null);\n\n useEffect(() => {\n if (!element) return;\n\n function onChange(event: Event) {\n const detail = (event as CustomEvent<SessionChange>).detail;\n if (detail) setSession({ ...detail });\n }\n\n element.addEventListener(\"pont-session-changed\", onChange);\n return () => element.removeEventListener(\"pont-session-changed\", onChange);\n }, [element]);\n\n return session;\n}\n\n/**\n * The session as the nearest `<Provider>` knows it. `resolved` is false until\n * `restoreSession()` has come back; act on nothing before it.\n */\nexport function useAuthState(): AuthState {\n return usePontContext(\"useAuthState\").auth;\n}\n\n/**\n * The last session change (`reason`: `signed-in`, `restored`, `refreshed`,\n * `organization-changed`, `signed-out`, `expired`), here or in another tab.\n * Null before the first. Use it to reload what depends on the organization.\n */\nexport function useSession(): SessionChange | null {\n return usePontContext(\"useSession\").session;\n}\n\n/**\n * The SDK the provider injected, for the calls the widgets don't make\n * (`signOut()`, `getManagementToken()` …).\n */\nexport function useSdk(): ProviderSdk {\n return usePontContext(\"useSdk\").sdk;\n}\n\n/**\n * The account client the widgets use (the provider's `accountClient`, else the\n * default one it builds from the SDK and `apiBaseUrl`), for the calls an app\n * makes beside them: `listBillingAccounts()` and `listMyContracts()` to choose\n * between `<Checkout>` and `<BillingPortal>`, for example. Undefined until the\n * provider has configured the SDK; read again on every auth and session change,\n * since the default client exists once the session has resolved.\n */\nexport function useAccountClient(): AccountClient | undefined {\n const { element, auth, session } = usePontContext(\"useAccountClient\");\n const [client, setClient] = useState<AccountClient | undefined>(undefined);\n\n useEffect(() => {\n if (!element) return;\n\n let cancelled = false;\n\n function read() {\n if (cancelled) return;\n const next = (element as unknown as { effectiveAccountClient?: AccountClient } | null)\n ?.effectiveAccountClient;\n setClient((current) => (current === next ? current : next));\n }\n\n read();\n void customElements.whenDefined(\"pont-provider\").then(read);\n\n return () => {\n cancelled = true;\n };\n }, [element, auth, session]);\n\n return client;\n}\n\nexport interface ControlProps {\n children?: React.ReactNode;\n /** Rendered until the session is known (default: nothing). */\n fallback?: React.ReactNode | null;\n}\n\n/**\n * Children for a signed-in user. A React component rather than a wrapper over\n * `<pont-signed-in>`, which detaches its children: nodes React must keep\n * owning (provider.md: framework hosts branch on `pont-auth-changed`).\n */\nexport function SignedIn({ children, fallback = null }: ControlProps): React.ReactNode {\n const { isAuthenticated, resolved } = useAuthState();\n if (!resolved) return fallback;\n return isAuthenticated ? children : null;\n}\n\n/** Children for everyone else, once the session is known. */\nexport function SignedOut({ children, fallback = null }: ControlProps): React.ReactNode {\n const { isAuthenticated, resolved } = useAuthState();\n if (!resolved) return fallback;\n return isAuthenticated ? null : children;\n}\n\n/** Children once the session is known; `fallback` until then. */\nexport function AuthResolved({ children, fallback = null }: ControlProps): React.ReactNode {\n return useAuthState().resolved ? children : fallback;\n}\n\nexport interface AuthenticatedProps {\n children?: React.ReactNode;\n /** Rendered while the session is being resolved. */\n loading?: React.ReactNode;\n /** Where to send a signed-out visitor. Default: the provider's `signinUrl`. */\n redirectUrl?: string;\n /** Navigate with the app's router (`router.push`) instead of a page load. */\n onRedirect?: (url: string) => void;\n}\n\n/**\n * Children for a signed-in user; everyone else is sent to the sign-in page,\n * once the session has resolved (never on the interim \"signed out\").\n */\nexport function Authenticated({\n children,\n loading = null,\n redirectUrl,\n onRedirect,\n}: AuthenticatedProps): React.ReactNode {\n const { auth, signinUrl } = usePontContext(\"Authenticated\");\n const redirected = useRef(false);\n const target = redirectUrl || signinUrl || undefined;\n\n useEffect(() => {\n if (!auth.resolved || auth.isAuthenticated || redirected.current) return;\n\n if (!target) {\n console.error(\n \"[pontive] <Authenticated> has nobody to redirect to: pass \" +\n \"`redirectUrl`, or give the Provider a `signinUrl`.\",\n );\n return;\n }\n\n redirected.current = true;\n\n if (onRedirect) onRedirect(target);\n else window.location.href = target;\n }, [auth.resolved, auth.isAuthenticated, target, onRedirect]);\n\n if (!auth.resolved) return loading;\n\n return auth.isAuthenticated ? children : null;\n}\n"],"names":["DOM_PROPS","useIsomorphicLayoutEffect","useLayoutEffect","useEffect","wrap","tagName","options","isProvider","events","eventProps","fallbackAllowed","component","forwardRef","props","forwardedRef","elementRef","useRef","assigned","callbacks","fallbackHost","setFallbackHost","useState","fallback","children","rest","domProps","elementProps","eventCallbacks","key","value","loadWebComponents","el","cancelled","assign","listeners","prop","type","listener","event","callback","remove","host","setRef","createElement","createPortal","ProviderElement","Signin","Signup","Invitation","Consent","AccountMenu","OrganizationSwitcher","AccountSettings","MemberManagement","Checkout","BillingPortal","UNRESOLVED","PontContext","createContext","usePontContext","caller","useContext","Provider","ownSdk","element","setElement","sdk","Auth","auth","useProviderAuthState","session","useSessionChange","signinUrl","contextValue","useMemo","captureRef","setAuth","accept","next","current","onAuthChanged","seed","setSession","onChange","detail","useAuthState","useSession","useSdk","useAccountClient","client","setClient","read","SignedIn","isAuthenticated","resolved","SignedOut","AuthResolved","Authenticated","loading","redirectUrl","onRedirect","redirected","target"],"mappings":";;;;AAmDA,MAAMA,wBAAgB,IAAI,CAAC,aAAa,SAAS,MAAM,MAAM,CAAC,GAqBxDC,IACJ,OAAO,SAAW,MAAcC,IAAkBC;AAuB7C,SAASC,EACdC,GACAC,IAAuB,IAC6D;AAGpF,QAAMC,IAAa,CAAC,CAACD,EAAQ,UACvBE,IAASF,EAAQ,UAAU,CAAA,GAC3BG,IAAa,IAAI,IAAI,OAAO,KAAKD,CAAM,CAAC,GACxCE,IAAkB,CAAC,CAACJ,EAAQ,UAE5BK,IAAYC,EAAqB,CAACC,GAAOC,MAAiB;AAC9D,UAAMC,IAAaC,EAAiB,IAAI,GAClCC,IAAWD,EAAqB,EAAE,GAGlCE,IAAYF,EAAqB,EAAE,GACnC,CAACG,GAAcC,CAAe,IAAIC,EAA6B,IAAI,GAEnE,EAAE,UAAAC,GAAU,UAAAC,GAAU,GAAGC,MAASX,GAKlCY,IAAyB,CAAA,GACzBC,IAA6B,CAAA,GAE7BC,IAA+B,CAAA;AAErC,eAAW,CAACC,GAAKC,CAAK,KAAK,OAAO,Q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AS,OAAOA;AAAA;AAAA,EAC9B,GAAG,CAAClC,EAAK,UAAUA,EAAK,iBAAiBkC,GAAQF,CAAU,CAAC,GAEvDhC,EAAK,WAEHA,EAAK,kBAAkB7C,IAAW,OAFd2E;AAG7B;"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { PontProviderElement, ProviderElementEvents } from './elements.generated';
|
|
3
|
+
import { AccountClient, AuthState, ProviderInputProps, ProviderSdk, SessionChange } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* `<Provider>`: `<pont-provider>` for React.
|
|
6
|
+
*
|
|
7
|
+
* What the element can't do for itself is get the SDK: core never imports the
|
|
8
|
+
* auth client, it is injected (`provider.sdk = Auth`, pontkit-core
|
|
9
|
+
* docs/kit/provider.md). This injects it, and turns the element's
|
|
10
|
+
* `pont-auth-changed` / `pont-session-changed` into React context.
|
|
11
|
+
*
|
|
12
|
+
* **Which `Auth`.** `@pontive/oidc-client`'s, a dependency of this package, so
|
|
13
|
+
* the app bundles exactly one copy (shared with the app's own, when it imports
|
|
14
|
+
* the same package). An app with another client passes `sdk` instead. `Auth`
|
|
15
|
+
* is a singleton whose constructor touches nothing, so importing it on a
|
|
16
|
+
* server is safe; the element only calls it in the browser.
|
|
17
|
+
*/
|
|
18
|
+
export interface ProviderProps extends ProviderInputProps, ProviderElementEvents {
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
/** The auth SDK. Default: `Auth` from `@pontive/oidc-client`. */
|
|
21
|
+
sdk?: ProviderSdk;
|
|
22
|
+
}
|
|
23
|
+
export declare const Provider: React.ForwardRefExoticComponent<ProviderProps & React.RefAttributes<PontProviderElement>>;
|
|
24
|
+
/**
|
|
25
|
+
* The session as the nearest `<Provider>` knows it. `resolved` is false until
|
|
26
|
+
* `restoreSession()` has come back; act on nothing before it.
|
|
27
|
+
*/
|
|
28
|
+
export declare function useAuthState(): AuthState;
|
|
29
|
+
/**
|
|
30
|
+
* The last session change (`reason`: `signed-in`, `restored`, `refreshed`,
|
|
31
|
+
* `organization-changed`, `signed-out`, `expired`), here or in another tab.
|
|
32
|
+
* Null before the first. Use it to reload what depends on the organization.
|
|
33
|
+
*/
|
|
34
|
+
export declare function useSession(): SessionChange | null;
|
|
35
|
+
/**
|
|
36
|
+
* The SDK the provider injected, for the calls the widgets don't make
|
|
37
|
+
* (`signOut()`, `getManagementToken()` …).
|
|
38
|
+
*/
|
|
39
|
+
export declare function useSdk(): ProviderSdk;
|
|
40
|
+
/**
|
|
41
|
+
* The account client the widgets use (the provider's `accountClient`, else the
|
|
42
|
+
* default one it builds from the SDK and `apiBaseUrl`), for the calls an app
|
|
43
|
+
* makes beside them: `listBillingAccounts()` and `listMyContracts()` to choose
|
|
44
|
+
* between `<Checkout>` and `<BillingPortal>`, for example. Undefined until the
|
|
45
|
+
* provider has configured the SDK; read again on every auth and session change,
|
|
46
|
+
* since the default client exists once the session has resolved.
|
|
47
|
+
*/
|
|
48
|
+
export declare function useAccountClient(): AccountClient | undefined;
|
|
49
|
+
export interface ControlProps {
|
|
50
|
+
children?: React.ReactNode;
|
|
51
|
+
/** Rendered until the session is known (default: nothing). */
|
|
52
|
+
fallback?: React.ReactNode | null;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Children for a signed-in user. A React component rather than a wrapper over
|
|
56
|
+
* `<pont-signed-in>`, which detaches its children: nodes React must keep
|
|
57
|
+
* owning (provider.md: framework hosts branch on `pont-auth-changed`).
|
|
58
|
+
*/
|
|
59
|
+
export declare function SignedIn({ children, fallback }: ControlProps): React.ReactNode;
|
|
60
|
+
/** Children for everyone else, once the session is known. */
|
|
61
|
+
export declare function SignedOut({ children, fallback }: ControlProps): React.ReactNode;
|
|
62
|
+
/** Children once the session is known; `fallback` until then. */
|
|
63
|
+
export declare function AuthResolved({ children, fallback }: ControlProps): React.ReactNode;
|
|
64
|
+
export interface AuthenticatedProps {
|
|
65
|
+
children?: React.ReactNode;
|
|
66
|
+
/** Rendered while the session is being resolved. */
|
|
67
|
+
loading?: React.ReactNode;
|
|
68
|
+
/** Where to send a signed-out visitor. Default: the provider's `signinUrl`. */
|
|
69
|
+
redirectUrl?: string;
|
|
70
|
+
/** Navigate with the app's router (`router.push`) instead of a page load. */
|
|
71
|
+
onRedirect?: (url: string) => void;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Children for a signed-in user; everyone else is sent to the sign-in page,
|
|
75
|
+
* once the session has resolved (never on the interim "signed out").
|
|
76
|
+
*/
|
|
77
|
+
export declare function Authenticated({ children, loading, redirectUrl, onRedirect, }: AuthenticatedProps): React.ReactNode;
|