@atlasauth/js 0.10.0 → 0.12.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.
@@ -0,0 +1,54 @@
1
+ /**
2
+ * `onSignOut({ reason })` for embedded third parties (a support-chat widget, a
3
+ * docs reader session, analytics identity) that must reset when the user stops
4
+ * being signed in — on EVERY path, not only the app's own sign-out button:
5
+ *
6
+ * - `user` this tab called signOut()
7
+ * - `other_tab` another tab of this app signed out (BroadcastChannel / storage signal)
8
+ * - `session_expired` the session ran out (idle or absolute lifetime)
9
+ * - `revoked` the session was ended elsewhere (signed out on another
10
+ * device, revoked by an admin, banned), detected on the
11
+ * next token refresh or session re-check
12
+ * - `unknown` signed out without a reason the SDK could tell
13
+ *
14
+ * Framework providers drive one {@link SignOutNotifier}: it fires listeners
15
+ * once per signed-in → signed-out transition and also dispatches a
16
+ * `atlas:signout` DOM event on `window`, so a script that has no access to the
17
+ * app's component tree can listen too:
18
+ *
19
+ * window.addEventListener('atlas:signout', (e) => Chatly('reset'));
20
+ */
21
+ export type SignOutReason = 'user' | 'other_tab' | 'session_expired' | 'revoked' | 'unknown';
22
+ export interface SignOutEvent {
23
+ reason: SignOutReason;
24
+ /** The session that ended, when the SDK knew it. */
25
+ sessionId: string | null;
26
+ }
27
+ /** The `window` event name. */
28
+ export declare const SIGN_OUT_EVENT = "atlas:signout";
29
+ export type SignOutListener = (event: SignOutEvent) => void;
30
+ /** Map a signed-out `/v1/client` body's `signed_out_reason` to a reason. */
31
+ export declare function signOutReasonFromClient(body: unknown): SignOutReason;
32
+ export declare class SignOutNotifier {
33
+ private readonly listeners;
34
+ private hint;
35
+ /** Subscribe; returns the unsubscribe. */
36
+ subscribe(listener: SignOutListener): () => void;
37
+ /**
38
+ * Note WHY the next sign-out is about to happen (call before the state
39
+ * changes). The first hint wins until the event fires: a user sign-out that
40
+ * also broadcasts to its own tab stays `user`.
41
+ */
42
+ expect(reason: SignOutReason): void;
43
+ /** Drop a stale hint (e.g. the session survived after all). */
44
+ clear(): void;
45
+ /**
46
+ * The provider went signed-in → signed-out: fire listeners and the DOM event
47
+ * once, with the hinted reason (else `fallback`, else `unknown`).
48
+ */
49
+ signedOut(sessionId: string | null, fallback?: SignOutReason): SignOutEvent;
50
+ }
51
+ /** Dispatch the `atlas:signout` window event (a no-op outside a browser). */
52
+ export declare function dispatchSignOutEvent(event: SignOutEvent): void;
53
+ /** Listen for `atlas:signout` on `window` from any framework; returns the unsubscribe. */
54
+ export declare function onAtlasSignOut(listener: SignOutListener): () => void;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ /**
3
+ * `onSignOut({ reason })` for embedded third parties (a support-chat widget, a
4
+ * docs reader session, analytics identity) that must reset when the user stops
5
+ * being signed in — on EVERY path, not only the app's own sign-out button:
6
+ *
7
+ * - `user` this tab called signOut()
8
+ * - `other_tab` another tab of this app signed out (BroadcastChannel / storage signal)
9
+ * - `session_expired` the session ran out (idle or absolute lifetime)
10
+ * - `revoked` the session was ended elsewhere (signed out on another
11
+ * device, revoked by an admin, banned), detected on the
12
+ * next token refresh or session re-check
13
+ * - `unknown` signed out without a reason the SDK could tell
14
+ *
15
+ * Framework providers drive one {@link SignOutNotifier}: it fires listeners
16
+ * once per signed-in → signed-out transition and also dispatches a
17
+ * `atlas:signout` DOM event on `window`, so a script that has no access to the
18
+ * app's component tree can listen too:
19
+ *
20
+ * window.addEventListener('atlas:signout', (e) => Chatly('reset'));
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.SignOutNotifier = exports.SIGN_OUT_EVENT = void 0;
24
+ exports.signOutReasonFromClient = signOutReasonFromClient;
25
+ exports.dispatchSignOutEvent = dispatchSignOutEvent;
26
+ exports.onAtlasSignOut = onAtlasSignOut;
27
+ /** The `window` event name. */
28
+ exports.SIGN_OUT_EVENT = 'atlas:signout';
29
+ /** Map a signed-out `/v1/client` body's `signed_out_reason` to a reason. */
30
+ function signOutReasonFromClient(body) {
31
+ const reason = body?.signed_out_reason;
32
+ return reason === 'session_expired' || reason === 'revoked' ? reason : 'unknown';
33
+ }
34
+ class SignOutNotifier {
35
+ listeners = new Set();
36
+ hint = null;
37
+ /** Subscribe; returns the unsubscribe. */
38
+ subscribe(listener) {
39
+ this.listeners.add(listener);
40
+ return () => this.listeners.delete(listener);
41
+ }
42
+ /**
43
+ * Note WHY the next sign-out is about to happen (call before the state
44
+ * changes). The first hint wins until the event fires: a user sign-out that
45
+ * also broadcasts to its own tab stays `user`.
46
+ */
47
+ expect(reason) {
48
+ if (this.hint === null)
49
+ this.hint = reason;
50
+ }
51
+ /** Drop a stale hint (e.g. the session survived after all). */
52
+ clear() {
53
+ this.hint = null;
54
+ }
55
+ /**
56
+ * The provider went signed-in → signed-out: fire listeners and the DOM event
57
+ * once, with the hinted reason (else `fallback`, else `unknown`).
58
+ */
59
+ signedOut(sessionId, fallback) {
60
+ const event = { reason: this.hint ?? fallback ?? 'unknown', sessionId };
61
+ this.hint = null;
62
+ for (const listener of [...this.listeners]) {
63
+ try {
64
+ listener(event);
65
+ }
66
+ catch {
67
+ // A listener that throws must not stop the others (or the sign-out).
68
+ }
69
+ }
70
+ dispatchSignOutEvent(event);
71
+ return event;
72
+ }
73
+ }
74
+ exports.SignOutNotifier = SignOutNotifier;
75
+ /** Dispatch the `atlas:signout` window event (a no-op outside a browser). */
76
+ function dispatchSignOutEvent(event) {
77
+ if (typeof window === 'undefined' || typeof window.dispatchEvent !== 'function')
78
+ return;
79
+ try {
80
+ const Ctor = globalThis.CustomEvent;
81
+ if (!Ctor)
82
+ return;
83
+ window.dispatchEvent(new Ctor(exports.SIGN_OUT_EVENT, { detail: event }));
84
+ }
85
+ catch {
86
+ // Never let a DOM quirk break a sign-out.
87
+ }
88
+ }
89
+ /** Listen for `atlas:signout` on `window` from any framework; returns the unsubscribe. */
90
+ function onAtlasSignOut(listener) {
91
+ if (typeof window === 'undefined')
92
+ return () => undefined;
93
+ const handler = (e) => listener(e.detail);
94
+ window.addEventListener(exports.SIGN_OUT_EVENT, handler);
95
+ return () => window.removeEventListener(exports.SIGN_OUT_EVENT, handler);
96
+ }
97
+ //# sourceMappingURL=sign-out-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign-out-events.js","sourceRoot":"","sources":["../src/sign-out-events.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAgBH,0DAGC;AA8CD,oDASC;AAGD,wCAKC;AAxED,+BAA+B;AAClB,QAAA,cAAc,GAAG,eAAe,CAAC;AAI9C,4EAA4E;AAC5E,SAAgB,uBAAuB,CAAC,IAAa;IACnD,MAAM,MAAM,GAAI,IAA+C,EAAE,iBAAiB,CAAC;IACnF,OAAO,MAAM,KAAK,iBAAiB,IAAI,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACnF,CAAC;AAED,MAAa,eAAe;IACT,SAAS,GAAG,IAAI,GAAG,EAAmB,CAAC;IAChD,IAAI,GAAyB,IAAI,CAAC;IAE1C,0CAA0C;IAC1C,SAAS,CAAC,QAAyB;QACjC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,MAAqB;QAC1B,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC;IAC7C,CAAC;IAED,+DAA+D;IAC/D,KAAK;QACH,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,SAAwB,EAAE,QAAwB;QAC1D,MAAM,KAAK,GAAiB,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,IAAI,QAAQ,IAAI,SAAS,EAAE,SAAS,EAAE,CAAC;Q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* Frontend API can answer an upgrade advisory. A constant (not read from
4
+ * package.json at runtime) so the bundle stays dependency-free and tests stay
5
+ * deterministic; `version.test.ts` fails when it drifts from package.json.
6
+ */
7
+ export declare const ATLAS_JS_VERSION = "0.12.0";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ATLAS_JS_VERSION = void 0;
4
+ /**
5
+ * This package's version, sent as `X-Atlas-SDK: @atlasauth/js/<version>` so the
6
+ * Frontend API can answer an upgrade advisory. A constant (not read from
7
+ * package.json at runtime) so the bundle stays dependency-free and tests stay
8
+ * deterministic; `version.test.ts` fails when it drifts from package.json.
9
+ */
10
+ exports.ATLAS_JS_VERSION = '0.12.0';
11
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACU,QAAA,gBAAgB,GAAG,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlasauth/js",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "devDependencies": {