@atlasauth/react 0.24.0 → 0.25.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlasauth/react changelog
2
2
 
3
+ ## 0.25.0 — 2026-11-02
4
+
5
+ ### Added
6
+
7
+ - `<ReferralPanel program=... />` mounts a referral platform's widget with the Atlas session token (renders nothing when signed out), and `useReferral()` returns `{ code, linkUrl }`.
8
+ - `<AtlasProvider>` registers `window.Atlas.session` and `window.Atlas.billing.customerMetadata()` through the active-atlas registry.
9
+
3
10
  ## 0.24.0 — 2026-10-30
4
11
 
5
12
  ### Added
@@ -1,8 +1,3 @@
1
- /**
2
- * The registry the imperative compat helpers read: `<AtlasProvider>` publishes
3
- * its state here on every change. Kept dependency-free so the provider and the
4
- * compat module do not import each other.
5
- */
6
1
  import type { AtlasUser, SessionClaims } from './types';
7
2
  export type AuthStatus = 'loading' | 'signed_in' | 'signed_out';
8
3
  /** What `getToken` mints: the session JWT by default. */
@@ -4,7 +4,23 @@ exports.publishActiveAtlas = publishActiveAtlas;
4
4
  exports.requireActive = requireActive;
5
5
  exports.getActiveAtlas = getActiveAtlas;
6
6
  exports.onActiveAtlasChange = onActiveAtlasChange;
7
+ /**
8
+ * The registry the imperative compat helpers read: `<AtlasProvider>` publishes
9
+ * its state here on every change. Kept dependency-free so the provider and the
10
+ * compat module do not import each other.
11
+ */
12
+ const js_1 = require("@atlasauth/js");
7
13
  let active = null;
14
+ let unregisterGlobal = null;
15
+ /** `window.Atlas.session` reads whichever provider is mounted right now. */
16
+ function exposeGlobal() {
17
+ if (unregisterGlobal || typeof window === 'undefined')
18
+ return;
19
+ unregisterGlobal = (0, js_1.installSessionGlobal)({
20
+ getToken: async (o) => (active ? active.getToken(o) : null),
21
+ user: () => (active?.status === 'signed_in' && active.user ? { ...active.user, external_id: active.claims?.external_id ?? null } : null),
22
+ });
23
+ }
8
24
  const listeners = new Set();
9
25
  /**
10
26
  * Called by `<AtlasProvider>` whenever its state changes, so the imperative
@@ -13,6 +29,14 @@ const listeners = new Set();
13
29
  */
14
30
  function publishActiveAtlas(next) {
15
31
  active = next;
32
+ if (next)
33
+ exposeGlobal();
34
+ else {
35
+ unregisterGlobal?.();
36
+ unregisterGlobal = null;
37
+ }
38
+ if (next && next.status !== 'loading')
39
+ (0, js_1.announceSessionChange)(next.status === 'signed_in' ? (next.user?.id ?? null) : null);
16
40
  for (const listener of [...listeners]) {
17
41
  try {
18
42
  listener(next);
@@ -1 +1 @@
1
- {"version":3,"file":"active-atlas.js","sourceRoot":"","sources":["../src/active-atlas.ts"],"names":[],"mappings":";;AA0DA,gDASC;AAED,sCAKC;AAGD,wCAEC;AAID,kDAGC;AApCD,IAAI,MAAM,GAAuB,IAAI,CAAC;AACtC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAuC,CAAC;AAEjE;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,IAAwB;IACzD,MAAM,GAAG,IAAI,CAAC;IACd,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;QACtC,IAAI,CAAC;YACH,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;QAAC,MAAM,CAAC;YACP,2DAA2D;QAC7D,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAgB,aAAa,CAAC,MAAc;IAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,+CAA+C,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,iEAAiE;AACjE,SAAgB,cAAc;IAC5B,OAAO,MAAM,CAAC;AAChB,CAAC;AAGD,oEAAoE;AACpE,SAAgB,mBAAmB,CAAC,QAA6C;IAC/E,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxB,OAAO,GAAG,EAAE,CAAC,KAAK,S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CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC3H,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAC,EAAE,CAAC;QACtC,IAAI,CAAC;YACH,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;QAAC,MAAM,CAAC;YACP,2DAA2D;QAC7D,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAgB,aAAa,CAAC,MAAc;IAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,+CAA+C,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,iEAAiE;AACjE,SAAgB,cAAc;IAC5B,OAAO,MAAM,CAAC;AAChB,CAAC;AAGD,oEAAoE;AACpE,SAAgB,mBAAmB,CAAC,QAA6C;IAC/E,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxB,OAAO,GAAG,EAAE,CAAC,KAAK,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC/C,CAAC"}
package/dist/index.d.ts CHANGED
@@ -31,3 +31,5 @@ export type { ProviderDiagnosis, OverlayGeometry, Rect } from '@atlasauth/js';
31
31
  export type { InstanceSettings, PublicSignUpField } from './instance-settings';
32
32
  export type { CaptchaFlowKey, CaptchaWidgetMode, FlowCaptcha } from '@atlasauth/js';
33
33
  export type { GetTokenOptions } from './active-atlas';
34
+ export { ReferralPanel, useReferral, referralFromUser, referralWidgetSrc, DEFAULT_REFERRAL_WIDGET_BASE } from './referral-panel';
35
+ export type { ReferralPanelProps, UserReferral } from './referral-panel';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.resolveLocale = exports.missingKeys = exports.LOCALIZATION_KEYS = exports.fetchAtlasInitialState = exports.SignOutError = exports.SAME_ORIGIN_FRONTEND_API = exports.AtlasConfigError = exports.diagnoseProvider = exports.handleSilentCallback = exports.checkSession = exports.useAtlasIdEvents = exports.SignInWithAtlasButton = exports.signInWithAtlasPopup = exports.oneTapWithAtlas = exports.listenAtlasIdEvents = exports.completeSignInWithAtlas = exports.buildAtlasAuthorizeUrl = exports.atlasIdLabels = exports.ATLASID_EVENTS = exports.onAtlasSignOut = exports.SIGN_OUT_EVENT = exports.ATLAS_REACT_VERSION = exports.ATLAS_REACT_SDK = exports.useDelegatedFlow = exports.useDelegatedChallenge = exports.useShareableResources = exports.ShareDialog = exports.RoleMatrix = exports.PendingApprovals = exports.AccessRequestButton = exports.useAccess = exports.AccessRequests = exports.useUser = exports.useSilentAuth = exports.useSignOutListener = exports.useSessionList = exports.useSession = exports.useOrganization = exports.useAuth = exports.authFromContext = exports.useAtlas = exports.AtlasProvider = void 0;
17
+ exports.DEFAULT_REFERRAL_WIDGET_BASE = exports.referralWidgetSrc = exports.referralFromUser = exports.useReferral = exports.ReferralPanel = exports.resolveLocale = exports.missingKeys = exports.LOCALIZATION_KEYS = exports.fetchAtlasInitialState = exports.SignOutError = exports.SAME_ORIGIN_FRONTEND_API = exports.AtlasConfigError = exports.diagnoseProvider = exports.handleSilentCallback = exports.checkSession = exports.useAtlasIdEvents = exports.SignInWithAtlasButton = exports.signInWithAtlasPopup = exports.oneTapWithAtlas = exports.listenAtlasIdEvents = exports.completeSignInWithAtlas = exports.buildAtlasAuthorizeUrl = exports.atlasIdLabels = exports.ATLASID_EVENTS = exports.onAtlasSignOut = exports.SIGN_OUT_EVENT = exports.ATLAS_REACT_VERSION = exports.ATLAS_REACT_SDK = exports.useDelegatedFlow = exports.useDelegatedChallenge = exports.useShareableResources = exports.ShareDialog = exports.RoleMatrix = exports.PendingApprovals = exports.AccessRequestButton = exports.useAccess = exports.AccessRequests = exports.useUser = exports.useSilentAuth = exports.useSignOutListener = exports.useSessionList = exports.useSession = exports.useOrganization = exports.useAuth = exports.authFromContext = exports.useAtlas = exports.AtlasProvider = void 0;
18
18
  __exportStar(require("./appearance"), exports);
19
19
  __exportStar(require("./styles"), exports);
20
20
  __exportStar(require("./protect"), exports);
@@ -92,4 +92,11 @@ var localizations_1 = require("@atlasauth/localizations");
92
92
  Object.defineProperty(exports, "LOCALIZATION_KEYS", { enumerable: true, get: function () { return localizations_1.LOCALIZATION_KEYS; } });
93
93
  Object.defineProperty(exports, "missingKeys", { enumerable: true, get: function () { return localizations_1.missingKeys; } });
94
94
  Object.defineProperty(exports, "resolveLocale", { enumerable: true, get: function () { return localizations_1.resolveLocale; } });
95
+ // The "refer a friend" panel from a referral platform's widget, authenticated with the Atlas session.
96
+ var referral_panel_1 = require("./referral-panel");
97
+ Object.defineProperty(exports, "ReferralPanel", { enumerable: true, get: function () { return referral_panel_1.ReferralPanel; } });
98
+ Object.defineProperty(exports, "useReferral", { enumerable: true, get: function () { return referral_panel_1.useReferral; } });
99
+ Object.defineProperty(exports, "referralFromUser", { enumerable: true, get: function () { return referral_panel_1.referralFromUser; } });
100
+ Object.defineProperty(exports, "referralWidgetSrc", { enumerable: true, get: function () { return referral_panel_1.referralWidgetSrc; } });
101
+ Object.defineProperty(exports, "DEFAULT_REFERRAL_WIDGET_BASE", { enumerable: true, get: function () { return referral_panel_1.DEFAULT_REFERRAL_WIDGET_BASE; } });
95
102
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,2CAAyB;AACzB,4CAA0B;AAC1B,yCAAuB;AACvB,0CAAwB;AAKxB,iDAA0D;AAAjD,8GAAA,aAAa,OAAA;AAAE,yGAAA,QAAQ,OAA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AU8B;AAT5B,oHAAA,cAAc,OAAA;AACd,mHAAA,aAAa,OAAA;AACb,4HAAA,sBAAsB,OAAA;AACtB,6HAAA,uBAAuB,OAAA;AACvB,yHAAA,mBAAmB,OAAA;AACnB,qHAAA,eAAe,OAAA;AACf,0HAAA,oBAAoB,OAAA;AACpB,2HAAA,qBAAqB,OAAA;AACrB,sHAAA,gBAAgB,OAAA;AAElB,iFAAiF;AACjF,gDAAgD;AAChD,oCAAmE;AAA1D,kGAAA,YAAY,OAAA;AAAE,0GAAA,oBAAoB,OAAA;AAE3C,qFAAqF;AACrF,gFAAgF;AAChF,gFAAgF;AAChF,oCAAiD;AAAxC,sGAAA,gBAAgB,OAAA;AACzB,0EAA0E;AAC1E,4DAA4D;AAC5D,oCAAyF;AAAhF,sGAAA,gBAAgB,OAAA;AAAE,8GAAA,wBAAwB,OAAA;AAAE,kGAAA,YAAY,OAAA;AAEjE,qFAAqF;AACrF,+CAA+C;AAC/C,oCAAuD;AAA9C,4GAAA,sBAAsB,OAAA;AAE/B,4EAA4E;AAC5E,0DAAyF;AAAhF,kHAAA,iBAAiB,OAAA;AAAE,4GAAA,WAAW,OAAA;AAAE,8GAAA,aAAa,OAAA;AAatD,sGAAsG;AACtG,mDAAiI;AAAxH,+GAAA,aAAa,OAAA;AAAE,6GAAA,WAAW,OAAA;AAAE,kHAAA,gBAAgB,OAAA;AAAE,mHAAA,iBAAiB,OAAA;AAAE,8HAAA,4BAA4B,OAAA"}
@@ -0,0 +1,45 @@
1
+ import type { AtlasUser } from './types';
2
+ /** The Referalli preset's base URL; its widget script is served per merchant at `{base}/t/{trackingToken}/widget.js`. */
3
+ export declare const DEFAULT_REFERRAL_WIDGET_BASE = "https://referalli.com";
4
+ /** The Referalli widget script for a merchant's tracking token. */
5
+ export declare function referralWidgetSrc(trackingToken: string, base?: string): string;
6
+ /** A user's referral code and link. */
7
+ export interface UserReferral {
8
+ code: string;
9
+ linkUrl: string | null;
10
+ }
11
+ /**
12
+ * The referral fields on a user: `public_metadata.referalli` (`code`, `link_url`),
13
+ * else the attribution mirror's `public_metadata.referral.own_code`. Null without a code.
14
+ */
15
+ export declare function referralFromUser(user: Pick<AtlasUser, 'public_metadata'> | null): UserReferral | null;
16
+ /** `{ code, linkUrl }` for the signed-in user, or null when signed out or not enrolled. */
17
+ export declare function useReferral(): UserReferral | null;
18
+ /**
19
+ * Load the widget script and mount its element in `host`, with `getAuthToken`
20
+ * set to the Atlas session token. Returns the teardown.
21
+ * @internal
22
+ */
23
+ export declare function mountReferralElement(host: HTMLElement, opts: {
24
+ program: string;
25
+ src: string;
26
+ getAuthToken: () => Promise<string | null>;
27
+ }): () => void;
28
+ export interface ReferralPanelProps {
29
+ /** The referral program id. */
30
+ program: string;
31
+ /** Your Referalli tracking token: the script is loaded from `https://referalli.com/t/<trackingToken>/widget.js`. */
32
+ trackingToken?: string;
33
+ /** The referral platform's widget script URL, when not the Referalli preset (overrides `trackingToken`). */
34
+ src?: string;
35
+ className?: string;
36
+ }
37
+ /**
38
+ * The user's "refer a friend" panel from the referral platform's own widget,
39
+ * authenticated with the Atlas session token (no server route). Renders
40
+ * nothing while signed out.
41
+ */
42
+ export declare function ReferralPanel({ program, trackingToken, src: srcProp, className }: ReferralPanelProps): import("react").DetailedReactHTMLElement<{
43
+ ref: import("react").RefObject<HTMLDivElement>;
44
+ className: string | undefined;
45
+ }, HTMLDivElement> | null;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.DEFAULT_REFERRAL_WIDGET_BASE = void 0;
5
+ exports.referralWidgetSrc = referralWidgetSrc;
6
+ exports.referralFromUser = referralFromUser;
7
+ exports.useReferral = useReferral;
8
+ exports.mountReferralElement = mountReferralElement;
9
+ exports.ReferralPanel = ReferralPanel;
10
+ const react_1 = require("react");
11
+ const AtlasProvider_1 = require("./AtlasProvider");
12
+ /** The Referalli preset's base URL; its widget script is served per merchant at `{base}/t/{trackingToken}/widget.js`. */
13
+ exports.DEFAULT_REFERRAL_WIDGET_BASE = 'https://referalli.com';
14
+ /** The Referalli widget script for a merchant's tracking token. */
15
+ function referralWidgetSrc(trackingToken, base = exports.DEFAULT_REFERRAL_WIDGET_BASE) {
16
+ return `${base.replace(/\/+$/, '')}/t/${encodeURIComponent(trackingToken)}/widget.js`;
17
+ }
18
+ /** The tag the widget script registers (the Referalli preset). */
19
+ const WIDGET_TAG = 'referalli-referral-widget';
20
+ const str = (v) => (typeof v === 'string' && v ? v : null);
21
+ /**
22
+ * The referral fields on a user: `public_metadata.referalli` (`code`, `link_url`),
23
+ * else the attribution mirror's `public_metadata.referral.own_code`. Null without a code.
24
+ */
25
+ function referralFromUser(user) {
26
+ const md = (user?.public_metadata ?? {});
27
+ const rec = (v) => (v && typeof v === 'object' ? v : {});
28
+ const own = rec(md.referalli);
29
+ const code = str(own.code) ?? str(rec(md.referral).own_code);
30
+ if (!code)
31
+ return null;
32
+ return { code, linkUrl: str(own.link_url) ?? str(own.linkUrl) };
33
+ }
34
+ /** `{ code, linkUrl }` for the signed-in user, or null when signed out or not enrolled. */
35
+ function useReferral() {
36
+ return referralFromUser((0, AtlasProvider_1.useAtlas)().user);
37
+ }
38
+ const loading = new Map();
39
+ /** Load a script once per page. */
40
+ function loadScript(src) {
41
+ let p = loading.get(src);
42
+ if (!p) {
43
+ p = new Promise((resolve, reject) => {
44
+ const el = document.createElement('script');
45
+ el.src = src;
46
+ el.async = true;
47
+ el.onload = () => resolve();
48
+ el.onerror = () => {
49
+ loading.delete(src);
50
+ reject(new Error(`could not load ${src}`));
51
+ };
52
+ document.head.appendChild(el);
53
+ });
54
+ loading.set(src, p);
55
+ }
56
+ return p;
57
+ }
58
+ /**
59
+ * Load the widget script and mount its element in `host`, with `getAuthToken`
60
+ * set to the Atlas session token. Returns the teardown.
61
+ * @internal
62
+ */
63
+ function mountReferralElement(host, opts) {
64
+ let alive = true;
65
+ void loadScript(opts.src)
66
+ .then(() => {
67
+ if (!alive)
68
+ return;
69
+ const el = document.createElement(WIDGET_TAG);
70
+ el.setAttribute('program', opts.program);
71
+ el.setAttribute('auth', 'atlas');
72
+ el.getAuthToken = opts.getAuthToken;
73
+ host.replaceChildren(el);
74
+ })
75
+ .catch(() => undefined); // the panel just does not appear
76
+ return () => {
77
+ alive = false;
78
+ host.replaceChildren();
79
+ };
80
+ }
81
+ /**
82
+ * The user's "refer a friend" panel from the referral platform's own widget,
83
+ * authenticated with the Atlas session token (no server route). Renders
84
+ * nothing while signed out.
85
+ */
86
+ function ReferralPanel({ program, trackingToken, src: srcProp, className }) {
87
+ // The script is per merchant: without src or a tracking token there is nothing to load.
88
+ const src = srcProp ?? (trackingToken ? referralWidgetSrc(trackingToken) : null);
89
+ const { status, getToken } = (0, AtlasProvider_1.useAtlas)();
90
+ const host = (0, react_1.useRef)(null);
91
+ const tokenRef = (0, react_1.useRef)(getToken);
92
+ tokenRef.current = getToken;
93
+ const signedIn = status === 'signed_in';
94
+ (0, react_1.useEffect)(() => {
95
+ if (!signedIn || !host.current || !src)
96
+ return;
97
+ return mountReferralElement(host.current, { program, src, getAuthToken: () => tokenRef.current() });
98
+ }, [signedIn, program, src]);
99
+ return signedIn && src ? (0, react_1.createElement)('div', { ref: host, className }) : null;
100
+ }
101
+ //# sourceMappingURL=referral-panel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referral-panel.js","sourceRoot":"","sources":["../src/referral-panel.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;AAUb,8CAEC;AAiBD,4CAOC;AAGD,kCAEC;AA6BD,oDAmBC;AAiBD,sCAaC;AArHD,iCAAyD;AACzD,mDAA2C;AAG3C,yHAAyH;AAC5G,QAAA,4BAA4B,GAAG,uBAAuB,CAAC;AAEpE,mEAAmE;AACnE,SAAgB,iBAAiB,CAAC,aAAqB,EAAE,OAAe,oCAA4B;IAClG,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,kBAAkB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CAAC;AACjF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlasauth/react",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
@@ -15,10 +15,10 @@
15
15
  "./package.json": "./package.json"
16
16
  },
17
17
  "dependencies": {
18
- "@atlasauth/js": "0.27.0",
18
+ "@atlasauth/design": "0.3.0",
19
+ "@atlasauth/js": "0.29.0",
19
20
  "@atlasauth/authz": "0.3.0",
20
- "@atlasauth/localizations": "0.12.0",
21
- "@atlasauth/design": "0.3.0"
21
+ "@atlasauth/localizations": "0.12.0"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "react": ">=18"