@elvix.is/sdk 0.6.2 → 0.6.4
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/react.d.ts +12 -1
- package/dist/react.js +17 -8
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -228,6 +228,17 @@ declare function useElvixApp(): ElvixBootstrapEnvelope | null;
|
|
|
228
228
|
* with no clientId, or when there's no user session. */
|
|
229
229
|
declare function useElvixAppContext(): ElvixAppContext | null;
|
|
230
230
|
declare function useElvixContext(): ElvixContextValue;
|
|
231
|
+
/**
|
|
232
|
+
* Resolve the effective elvix origin for a hook / component:
|
|
233
|
+
* 1. explicit `propBaseUrl` (caller wins),
|
|
234
|
+
* 2. `<ElvixProvider baseUrl>` from context if present + non-empty,
|
|
235
|
+
* 3. public default `"https://elvix.is"`.
|
|
236
|
+
*
|
|
237
|
+
* SSR-safe — never touches `window`. Use this in every SDK hook /
|
|
238
|
+
* component that takes an optional `baseUrl` so a host that wires the
|
|
239
|
+
* provider once doesn't have to re-thread it through every prop.
|
|
240
|
+
*/
|
|
241
|
+
declare function useResolvedBaseUrl(propBaseUrl?: string): string;
|
|
231
242
|
declare function ElvixProvider({ clientId, theme, brand, baseUrl, children, className, }: {
|
|
232
243
|
clientId?: string;
|
|
233
244
|
theme?: ElvixTheme;
|
|
@@ -1076,4 +1087,4 @@ type ElvixLegalEntitiesProps = {
|
|
|
1076
1087
|
};
|
|
1077
1088
|
declare function ElvixLegalEntities({ height, minHeight, maxHeight, width, onChange, onResult, }: ElvixLegalEntitiesProps): react_jsx_runtime.JSX.Element;
|
|
1078
1089
|
|
|
1079
|
-
export { DEFAULT_COPY, ElvixAddressBook, type ElvixAppContext, ElvixAvatar, ElvixBanner, type ElvixBootstrapEnvelope, type ElvixBrand, ElvixCard, type ElvixCopy, ElvixDeactivate, ElvixExport, ElvixIdentityForm, ElvixLanguages, ElvixLeave, ElvixLegalEntities, ElvixLifecycleWatcher, ElvixProvider, ElvixRegion, ElvixSecuredBadge, ElvixSessions, ElvixSignIn, ElvixSignInButton, ElvixSignInForm, type ElvixSignInMethod, type ElvixSignInResult$1 as ElvixSignInResult, type ElvixSignInResultErr, type ElvixSignInResultOk, type ElvixSizeProps, type ElvixTheme, ElvixUsername, type UseUserListResult, consumeElvixReturnToken, getElvixToken, setElvixToken, useElvixApp, useElvixAppContext, useElvixContext, useUserMemberships, useUserRoles, useUserScopes };
|
|
1090
|
+
export { DEFAULT_COPY, ElvixAddressBook, type ElvixAppContext, ElvixAvatar, ElvixBanner, type ElvixBootstrapEnvelope, type ElvixBrand, ElvixCard, type ElvixCopy, ElvixDeactivate, ElvixExport, ElvixIdentityForm, ElvixLanguages, ElvixLeave, ElvixLegalEntities, ElvixLifecycleWatcher, ElvixProvider, ElvixRegion, ElvixSecuredBadge, ElvixSessions, ElvixSignIn, ElvixSignInButton, ElvixSignInForm, type ElvixSignInMethod, type ElvixSignInResult$1 as ElvixSignInResult, type ElvixSignInResultErr, type ElvixSignInResultOk, type ElvixSizeProps, type ElvixTheme, ElvixUsername, type UseUserListResult, consumeElvixReturnToken, getElvixToken, setElvixToken, useElvixApp, useElvixAppContext, useElvixContext, useResolvedBaseUrl, useUserMemberships, useUserRoles, useUserScopes };
|
package/dist/react.js
CHANGED
|
@@ -167,6 +167,12 @@ function useElvixContext() {
|
|
|
167
167
|
}
|
|
168
168
|
return ctx;
|
|
169
169
|
}
|
|
170
|
+
function useResolvedBaseUrl(propBaseUrl) {
|
|
171
|
+
const ctx = useContext(ElvixContext);
|
|
172
|
+
if (typeof propBaseUrl === "string") return propBaseUrl;
|
|
173
|
+
if (ctx && typeof ctx.baseUrl === "string") return ctx.baseUrl;
|
|
174
|
+
return DEFAULT_BASE_URL;
|
|
175
|
+
}
|
|
170
176
|
function ElvixProvider({
|
|
171
177
|
clientId,
|
|
172
178
|
theme,
|
|
@@ -2609,7 +2615,8 @@ function ElvixSecuredBadge({
|
|
|
2609
2615
|
import { useCallback as useCallback4, useEffect as useEffect5, useState as useState7 } from "react";
|
|
2610
2616
|
var POLL_MS = 7e3;
|
|
2611
2617
|
function useUserList(kind, opts) {
|
|
2612
|
-
const { applicationId,
|
|
2618
|
+
const { applicationId, pollMs = POLL_MS } = opts;
|
|
2619
|
+
const resolvedBaseUrl = useResolvedBaseUrl(opts.baseUrl);
|
|
2613
2620
|
const [slugs, setSlugs] = useState7([]);
|
|
2614
2621
|
const [loading, setLoading] = useState7(true);
|
|
2615
2622
|
const [error51, setError] = useState7(null);
|
|
@@ -2617,7 +2624,7 @@ function useUserList(kind, opts) {
|
|
|
2617
2624
|
setError(null);
|
|
2618
2625
|
try {
|
|
2619
2626
|
const res = await fetch(
|
|
2620
|
-
`${
|
|
2627
|
+
`${resolvedBaseUrl}/api/me/${kind}?applicationId=${encodeURIComponent(applicationId)}`,
|
|
2621
2628
|
authInit()
|
|
2622
2629
|
);
|
|
2623
2630
|
const json2 = await res.json().catch(() => ({}));
|
|
@@ -2631,7 +2638,7 @@ function useUserList(kind, opts) {
|
|
|
2631
2638
|
} finally {
|
|
2632
2639
|
setLoading(false);
|
|
2633
2640
|
}
|
|
2634
|
-
}, [applicationId,
|
|
2641
|
+
}, [applicationId, resolvedBaseUrl, kind]);
|
|
2635
2642
|
useEffect5(() => {
|
|
2636
2643
|
refresh();
|
|
2637
2644
|
const id = setInterval(refresh, pollMs);
|
|
@@ -2662,12 +2669,13 @@ function isSameOrigin2(baseUrl) {
|
|
|
2662
2669
|
}
|
|
2663
2670
|
}
|
|
2664
2671
|
function ElvixLifecycleWatcher({
|
|
2665
|
-
baseUrl
|
|
2672
|
+
baseUrl,
|
|
2666
2673
|
pollMs = 7e3,
|
|
2667
2674
|
applicationId,
|
|
2668
2675
|
userId,
|
|
2669
2676
|
onSignedOut
|
|
2670
2677
|
}) {
|
|
2678
|
+
const resolvedBaseUrl = useResolvedBaseUrl(baseUrl);
|
|
2671
2679
|
useEffect6(() => {
|
|
2672
2680
|
let cancelled = false;
|
|
2673
2681
|
let fired = false;
|
|
@@ -2678,7 +2686,7 @@ function ElvixLifecycleWatcher({
|
|
|
2678
2686
|
if (onSignedOut) onSignedOut(reason);
|
|
2679
2687
|
else if (typeof window !== "undefined") window.location.reload();
|
|
2680
2688
|
}
|
|
2681
|
-
const canSse = applicationId !== void 0 && userId !== void 0 && typeof window !== "undefined" && typeof EventSource !== "undefined" && isSameOrigin2(
|
|
2689
|
+
const canSse = applicationId !== void 0 && userId !== void 0 && typeof window !== "undefined" && typeof EventSource !== "undefined" && isSameOrigin2(resolvedBaseUrl);
|
|
2682
2690
|
if (canSse) {
|
|
2683
2691
|
let onRecord2 = function(rec) {
|
|
2684
2692
|
if (rec.userId !== userId) return;
|
|
@@ -2696,7 +2704,7 @@ function ElvixLifecycleWatcher({
|
|
|
2696
2704
|
}
|
|
2697
2705
|
};
|
|
2698
2706
|
var onRecord = onRecord2, handle = handle2, handleSnapshot = handleSnapshot2;
|
|
2699
|
-
const url2 = new URL(`${
|
|
2707
|
+
const url2 = new URL(`${resolvedBaseUrl}/api/presence/stream`, window.location.origin);
|
|
2700
2708
|
url2.searchParams.set("applicationId", applicationId);
|
|
2701
2709
|
url2.searchParams.set("userId", userId);
|
|
2702
2710
|
const ev = new EventSource(url2.toString());
|
|
@@ -2712,7 +2720,7 @@ function ElvixLifecycleWatcher({
|
|
|
2712
2720
|
const poll = async () => {
|
|
2713
2721
|
try {
|
|
2714
2722
|
const init = authInit();
|
|
2715
|
-
const res = await fetch(`${
|
|
2723
|
+
const res = await fetch(`${resolvedBaseUrl}/api/v1/session`, {
|
|
2716
2724
|
method: "POST",
|
|
2717
2725
|
headers: init.headers,
|
|
2718
2726
|
credentials: init.credentials
|
|
@@ -2729,7 +2737,7 @@ function ElvixLifecycleWatcher({
|
|
|
2729
2737
|
cancelled = true;
|
|
2730
2738
|
clearInterval(id);
|
|
2731
2739
|
};
|
|
2732
|
-
}, [
|
|
2740
|
+
}, [resolvedBaseUrl, pollMs, applicationId, userId, onSignedOut]);
|
|
2733
2741
|
return null;
|
|
2734
2742
|
}
|
|
2735
2743
|
|
|
@@ -28385,6 +28393,7 @@ export {
|
|
|
28385
28393
|
useElvixApp,
|
|
28386
28394
|
useElvixAppContext,
|
|
28387
28395
|
useElvixContext,
|
|
28396
|
+
useResolvedBaseUrl,
|
|
28388
28397
|
useUserMemberships,
|
|
28389
28398
|
useUserRoles,
|
|
28390
28399
|
useUserScopes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elvix.is/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Official elvix SDK. Drop-in React components, server helpers, and an MCP server so AI coding agents integrate elvix on the first try.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://elvix.is",
|