@cyphlens/2fa-sse-sdk 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -30,7 +30,7 @@ yarn add @cyphlens/2fa-sse-sdk
30
30
  ### Using CDN (Browser)
31
31
  Include the SDK directly in your HTML:
32
32
  ```html
33
- <script src="https://cdn.jsdelivr.net/npm/@cyphlens/2fa-sse-sdk/dist/bundle.umd.min.js"/>
33
+ <script src="https://cdn.jsdelivr.net/npm/@cyphlens/2fa-sse-sdk/dist/bundle.min.js"/>
34
34
  ```
35
35
 
36
36
  ---
@@ -140,3 +140,4 @@ This project is licensed under the Cyphlens License. See the [LICENSE](https://c
140
140
 
141
141
 
142
142
 
143
+
@@ -0,0 +1,2 @@
1
+ var Cyphlens=function(t){"use strict";var e,s;t.EventType=void 0,(e=t.EventType||(t.EventType={})).MFASwipe="MFA.SWIPE",e.Disconnect="DISCONNECT",t.StatusType=void 0,(s=t.StatusType||(t.StatusType={})).Pending="PENDING",s.Success="SUCCESS",s.Expired="EXPIRED";class i{constructor(t="https://api.cyphme.com/b2c/v1"){this.eventSource=null,this.timeoutId=null,this.onVisibilityChange=()=>{/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&/iP(ad|od|hone)/i.test(navigator.userAgent)&&"visible"===document.visibilityState&&this.sessionID&&this.start()},this.baseUrl=t}setBaseUrl(t){this.baseUrl=t}start(){return this.sessionID?(this.stop(),this.eventSource=new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`),this.eventSource.addEventListener(t.EventType.MFASwipe,(e=>{var s,i;try{const i=JSON.parse(e.data);this.setupTimeout(i.expiresAt),null===(s=this.onSuccess)||void 0===s||s.call(this,t.EventType.MFASwipe,i)}catch(t){console.error("Error parsing event data:",t);const e=new Event("Something went wrong");null===(i=this.onError)||void 0===i||i.call(this,e)}})),this.eventSource.addEventListener("error",(t=>{var e;null===(e=this.onError)||void 0===e||e.call(this,t),this.stop()})),this.eventSource):null}setupTimeout(t){this.timeoutId&&clearTimeout(this.timeoutId);const e=t-Date.now()+5e3;this.timeoutId=setTimeout((()=>this.stop()),e)}listen(t,e,s){return this.sessionID=t,this.onSuccess=e,this.onError=s,"undefined"!=typeof document&&document.addEventListener("visibilitychange",this.onVisibilityChange),this.start()}stop(){this.eventSource&&(this.eventSource.close(),this.eventSource=null),this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null)}}return t.Cyphlens=i,t.default=i,Object.defineProperty(t,"__esModule",{value:!0}),t}({});
2
+ //# sourceMappingURL=bundle.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bundle.min.js","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export enum EventType {\n MFASwipe = \"MFA.SWIPE\",\n Disconnect = \"DISCONNECT\",\n}\n\nexport enum StatusType {\n Pending = \"PENDING\",\n Success = \"SUCCESS\",\n Expired = \"EXPIRED\",\n}\n\nexport interface CyphlensEvent {}\n\nexport interface TwoFactorEvent extends CyphlensEvent { \n sessionId: string;\n status: StatusType;\n timestamp: number;\n expiresAt: number;\n}\n\nexport interface DisconnectEvent extends CyphlensEvent {\n message: string;\n}\n\nexport type EventCallback = (eventType: EventType, data: CyphlensEvent) => void;\nexport type CyphlensErrorCallback = (error: Event) => void;\n","import { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent } from './types';\nexport { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent }\nexport class Cyphlens {\n private baseUrl: string;\n private eventSource: EventSource | null = null;\n private sessionID?: string;\n private onSuccess?: EventCallback;\n private onError?: CyphlensErrorCallback;\n private timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * Initializes the Cyphlens service with a base URL.\n * @param baseUrl The base API URL for connecting to the Cyphlens service.\n */\n constructor(baseUrl: string = \"https://api.cyphme.com/b2c/v1\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Updates the base API URL.\n * @param baseUrl The new base URL.\n */\n setBaseUrl(baseUrl: string): void {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Starts the Server-Sent Events (SSE) connection to listen for authentication events.\n * @returns The EventSource instance if successful, otherwise null.\n */\n private start(): EventSource | null {\n if (!this.sessionID) return null;\n\n this.stop(); // Ensure any existing connections are closed before starting a new one.\n\n this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);\n\n // Listen for MFA swipe events\n this.eventSource.addEventListener(EventType.MFASwipe, (event: MessageEvent) => {\n try {\n const data: TwoFactorEvent = JSON.parse(event.data);\n this.setupTimeout(data.expiresAt);\n this.onSuccess?.(EventType.MFASwipe, data);\n } catch (error) {\n console.error(\"Error parsing event data:\", error);\n const errorEvent = new Event('Something went wrong');\n this.onError?.(errorEvent);\n }\n });\n\n // Handle SSE errors\n this.eventSource.addEventListener(\"error\", (event: Event) => {\n this.onError?.(event);\n this.stop();\n });\n\n return this.eventSource;\n }\n\n /**\n * Sets up a timeout to automatically stop the SSE connection when the event expires.\n * @param expiresAt The expiration timestamp (milliseconds).\n */\n private setupTimeout(expiresAt: number): void {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n }\n\n // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.\n const timeoutDuration = expiresAt - Date.now() + 5000;\n this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);\n }\n\n /**\n * Starts listening for authentication events.\n * @param sessionId The session ID used for authentication.\n * @param onData Callback function for handling successful authentication events.\n * @param onError Callback function for handling errors.\n * @returns The EventSource instance if successfully started, otherwise null.\n */\n listen(sessionId: string, onData?: EventCallback, onError?: CyphlensErrorCallback): EventSource | null {\n this.sessionID = sessionId;\n this.onSuccess = onData;\n this.onError = onError;\n\n // Attach visibility change listener to handle browser background issues (especially for iOS Safari).\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.onVisibilityChange);\n }\n\n return this.start();\n }\n\n /**\n * Stops the SSE connection and clears any active timeouts.\n */\n stop(): void {\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = null;\n }\n }\n\n /**\n * Handles browser visibility changes to restart the SSE connection when the page becomes visible.\n * This is primarily to prevent connection loss in Safari when the tab goes to the background.\n * Only applies to Mobile Safari.\n */\n private readonly onVisibilityChange = (): void => {\n const isMobileSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) &&\n /iP(ad|od|hone)/i.test(navigator.userAgent);\n if (isMobileSafari && document.visibilityState === \"visible\" && this.sessionID) {\n this.start();\n }\n };\n }\n\nexport type CyphlensExports = {\n Cyphlens: typeof Cyphlens;\n EventType: typeof EventType;\n StatusType: typeof StatusType;\n TwoFactorEvent: TwoFactorEvent;\n CyphlensEvent: CyphlensEvent;\n DisconnectEvent: DisconnectEvent;\n EventCallback: EventCallback;\n CyphlensErrorCallback: CyphlensErrorCallback;\n};\n\nexport default Cyphlens;\n"],"names":["EventType","StatusType","Cyphlens","constructor","baseUrl","this","eventSource","timeoutId","onVisibilityChange","test","navigator","userAgent","document","visibilityState","sessionID","start","setBaseUrl","stop","EventSource","addEventListener","MFASwipe","event","data","JSON","parse","setupTimeout","expiresAt","_a","onSuccess","call","error","console","errorEvent","Event","_b","onError","clearTimeout","timeoutDuration","Date","now","setTimeout","listen","sessionId","onData","close"],"mappings":"sCAAA,IAAYA,EAKAC,EALAD,EAAAA,eAAAA,GAAAA,EAAAA,EAASA,YAATA,YAGX,CAAA,IAFC,SAAA,YACAA,EAAA,WAAA,aAGUC,EAAAA,gBAAAA,GAAAA,EAAAA,EAAUA,aAAVA,aAIX,CAAA,IAHC,QAAA,UACAA,EAAA,QAAA,UACAA,EAAA,QAAA,gBCNWC,EAYX,WAAAC,CAAYC,EAAkB,iCAVtBC,KAAWC,YAAuB,KAIlCD,KAASE,UAAyC,KAwGzCF,KAAkBG,mBAA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BvC,KAAKC,YAAc,MAEjBD,KAAKE,YACP6B,aAAa/B,KAAKE,WAClBF,KAAKE,UAAY"}
package/dist/index.esm.js CHANGED
@@ -1,115 +1,2 @@
1
- var EventType;
2
- (function (EventType) {
3
- EventType["MFASwipe"] = "MFA.SWIPE";
4
- EventType["Disconnect"] = "DISCONNECT";
5
- })(EventType || (EventType = {}));
6
- var StatusType;
7
- (function (StatusType) {
8
- StatusType["Pending"] = "PENDING";
9
- StatusType["Success"] = "SUCCESS";
10
- StatusType["Expired"] = "EXPIRED";
11
- })(StatusType || (StatusType = {}));
12
-
13
- class Cyphlens {
14
- /**
15
- * Initializes the Cyphlens service with a base URL.
16
- * @param baseUrl The base API URL for connecting to the Cyphlens service.
17
- */
18
- constructor(baseUrl = "https://api.cyphme.com/b2c/v1") {
19
- this.eventSource = null;
20
- this.timeoutId = null;
21
- /**
22
- * Handles browser visibility changes to restart the SSE connection when the page becomes visible.
23
- * This is primarily to prevent connection loss in Safari when the tab goes to the background.
24
- */
25
- this.onVisibilityChange = () => {
26
- if (document.visibilityState === "visible" && this.sessionID) {
27
- this.start();
28
- }
29
- };
30
- this.baseUrl = baseUrl;
31
- }
32
- /**
33
- * Updates the base API URL.
34
- * @param baseUrl The new base URL.
35
- */
36
- setBaseUrl(baseUrl) {
37
- this.baseUrl = baseUrl;
38
- }
39
- /**
40
- * Starts the Server-Sent Events (SSE) connection to listen for authentication events.
41
- * @returns The EventSource instance if successful, otherwise null.
42
- */
43
- start() {
44
- if (!this.sessionID)
45
- return null;
46
- this.stop(); // Ensure any existing connections are closed before starting a new one.
47
- this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);
48
- // Listen for MFA swipe events
49
- this.eventSource.addEventListener(EventType.MFASwipe, (event) => {
50
- var _a, _b;
51
- try {
52
- const data = JSON.parse(event.data);
53
- this.setupTimeout(data.expiresAt);
54
- (_a = this.onSuccess) === null || _a === void 0 ? void 0 : _a.call(this, EventType.MFASwipe, data);
55
- }
56
- catch (error) {
57
- console.error("Error parsing event data:", error);
58
- const errorEvent = new Event('Something went wrong');
59
- (_b = this.onError) === null || _b === void 0 ? void 0 : _b.call(this, errorEvent);
60
- }
61
- });
62
- // Handle SSE errors
63
- this.eventSource.addEventListener("error", (event) => {
64
- var _a;
65
- (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, event);
66
- this.stop();
67
- });
68
- return this.eventSource;
69
- }
70
- /**
71
- * Sets up a timeout to automatically stop the SSE connection when the event expires.
72
- * @param expiresAt The expiration timestamp (milliseconds).
73
- */
74
- setupTimeout(expiresAt) {
75
- if (this.timeoutId) {
76
- clearTimeout(this.timeoutId);
77
- }
78
- // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.
79
- const timeoutDuration = expiresAt - Date.now() + 5000;
80
- this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);
81
- }
82
- /**
83
- * Starts listening for authentication events.
84
- * @param sessionId The session ID used for authentication.
85
- * @param onData Callback function for handling successful authentication events.
86
- * @param onError Callback function for handling errors.
87
- * @returns The EventSource instance if successfully started, otherwise null.
88
- */
89
- listen(sessionId, onData, onError) {
90
- this.sessionID = sessionId;
91
- this.onSuccess = onData;
92
- this.onError = onError;
93
- // Attach visibility change listener to handle browser background issues (especially for iOS Safari).
94
- if (typeof document !== "undefined") {
95
- document.addEventListener("visibilitychange", this.onVisibilityChange);
96
- }
97
- return this.start();
98
- }
99
- /**
100
- * Stops the SSE connection and clears any active timeouts.
101
- */
102
- stop() {
103
- if (this.eventSource) {
104
- this.eventSource.close();
105
- this.eventSource = null;
106
- }
107
- if (this.timeoutId) {
108
- clearTimeout(this.timeoutId);
109
- this.timeoutId = null;
110
- }
111
- }
112
- }
113
-
114
- export { Cyphlens, EventType, StatusType, Cyphlens as default };
1
+ var t,e;!function(t){t.MFASwipe="MFA.SWIPE",t.Disconnect="DISCONNECT"}(t||(t={})),function(t){t.Pending="PENDING",t.Success="SUCCESS",t.Expired="EXPIRED"}(e||(e={}));class s{constructor(t="https://api.cyphme.com/b2c/v1"){this.eventSource=null,this.timeoutId=null,this.onVisibilityChange=()=>{/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&/iP(ad|od|hone)/i.test(navigator.userAgent)&&"visible"===document.visibilityState&&this.sessionID&&this.start()},this.baseUrl=t}setBaseUrl(t){this.baseUrl=t}start(){return this.sessionID?(this.stop(),this.eventSource=new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`),this.eventSource.addEventListener(t.MFASwipe,(e=>{var s,i;try{const i=JSON.parse(e.data);this.setupTimeout(i.expiresAt),null===(s=this.onSuccess)||void 0===s||s.call(this,t.MFASwipe,i)}catch(t){console.error("Error parsing event data:",t);const e=new Event("Something went wrong");null===(i=this.onError)||void 0===i||i.call(this,e)}})),this.eventSource.addEventListener("error",(t=>{var e;null===(e=this.onError)||void 0===e||e.call(this,t),this.stop()})),this.eventSource):null}setupTimeout(t){this.timeoutId&&clearTimeout(this.timeoutId);const e=t-Date.now()+5e3;this.timeoutId=setTimeout((()=>this.stop()),e)}listen(t,e,s){return this.sessionID=t,this.onSuccess=e,this.onError=s,"undefined"!=typeof document&&document.addEventListener("visibilitychange",this.onVisibilityChange),this.start()}stop(){this.eventSource&&(this.eventSource.close(),this.eventSource=null),this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null)}}export{s as Cyphlens,t as EventType,e as StatusType,s as default};
115
2
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export enum EventType {\n MFASwipe = \"MFA.SWIPE\",\n Disconnect = \"DISCONNECT\",\n}\n\nexport enum StatusType {\n Pending = \"PENDING\",\n Success = \"SUCCESS\",\n Expired = \"EXPIRED\",\n}\n\nexport interface CyphlensEvent {}\n\nexport interface TwoFactorEvent extends CyphlensEvent { \n sessionId: string;\n status: StatusType;\n timestamp: number;\n expiresAt: number;\n}\n\nexport interface DisconnectEvent extends CyphlensEvent {\n message: string;\n}\n\nexport type EventCallback = (eventType: EventType, data: CyphlensEvent) => void;\nexport type CyphlensErrorCallback = (error: Event) => void;\n","import { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent } from './types';\nexport { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent }\nexport class Cyphlens {\n private baseUrl: string;\n private eventSource: EventSource | null = null;\n private sessionID?: string;\n private onSuccess?: EventCallback;\n private onError?: CyphlensErrorCallback;\n private timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * Initializes the Cyphlens service with a base URL.\n * @param baseUrl The base API URL for connecting to the Cyphlens service.\n */\n constructor(baseUrl: string = \"https://api.cyphme.com/b2c/v1\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Updates the base API URL.\n * @param baseUrl The new base URL.\n */\n setBaseUrl(baseUrl: string): void {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Starts the Server-Sent Events (SSE) connection to listen for authentication events.\n * @returns The EventSource instance if successful, otherwise null.\n */\n private start(): EventSource | null {\n if (!this.sessionID) return null;\n\n this.stop(); // Ensure any existing connections are closed before starting a new one.\n\n this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);\n\n // Listen for MFA swipe events\n this.eventSource.addEventListener(EventType.MFASwipe, (event: MessageEvent) => {\n try {\n const data: TwoFactorEvent = JSON.parse(event.data);\n this.setupTimeout(data.expiresAt);\n this.onSuccess?.(EventType.MFASwipe, data);\n } catch (error) {\n console.error(\"Error parsing event data:\", error);\n const errorEvent = new Event('Something went wrong');\n this.onError?.(errorEvent);\n }\n });\n\n // Handle SSE errors\n this.eventSource.addEventListener(\"error\", (event: Event) => {\n this.onError?.(event);\n this.stop();\n });\n\n return this.eventSource;\n }\n\n /**\n * Sets up a timeout to automatically stop the SSE connection when the event expires.\n * @param expiresAt The expiration timestamp (milliseconds).\n */\n private setupTimeout(expiresAt: number): void {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n }\n\n // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.\n const timeoutDuration = expiresAt - Date.now() + 5000;\n this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);\n }\n\n /**\n * Starts listening for authentication events.\n * @param sessionId The session ID used for authentication.\n * @param onData Callback function for handling successful authentication events.\n * @param onError Callback function for handling errors.\n * @returns The EventSource instance if successfully started, otherwise null.\n */\n listen(sessionId: string, onData?: EventCallback, onError?: CyphlensErrorCallback): EventSource | null {\n this.sessionID = sessionId;\n this.onSuccess = onData;\n this.onError = onError;\n\n // Attach visibility change listener to handle browser background issues (especially for iOS Safari).\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.onVisibilityChange);\n }\n\n return this.start();\n }\n\n /**\n * Stops the SSE connection and clears any active timeouts.\n */\n stop(): void {\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = null;\n }\n }\n\n /**\n * Handles browser visibility changes to restart the SSE connection when the page becomes visible.\n * This is primarily to prevent connection loss in Safari when the tab goes to the background.\n */\n private readonly onVisibilityChange = (): void => {\n if (document.visibilityState === \"visible\" && this.sessionID) {\n this.start();\n }\n };\n}\n\nexport type CyphlensExports = {\n Cyphlens: typeof Cyphlens;\n EventType: typeof EventType;\n StatusType: typeof StatusType;\n TwoFactorEvent: TwoFactorEvent;\n CyphlensEvent: CyphlensEvent;\n DisconnectEvent: DisconnectEvent;\n EventCallback: EventCallback;\n CyphlensErrorCallback: CyphlensErrorCallback;\n};\n\nexport default Cyphlens;\n"],"names":[],"mappings":"IAAY;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,UAAA,CAAA,GAAA,WAAsB;AACtB,IAAA,SAAA,CAAA,YAAA,CAAA,GAAA,YAAyB;AAC3B,CAAC,EAHW,SAAS,KAAT,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AA+B,EAAA;AAC/E,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS;AAC1B,QAAA,IAAI,CAAC,SAAS,GAAG,MAAM;AACvB,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;;AAGtB,QAAA,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;YACnC,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC;;AAGxE,QAAA,OAAO,IAAI,CAAC,KAAK,EAAE;;AAGrB;;AAEG;IACH,IAAI,GAAA;AACF,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;AACpB,YAAA,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;AACxB,YAAA,IAAI,CAAC,WAAW,GAAG,IAAI;;AAEzB,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAClB,YAAA,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC;AAC5B,YAAA,IAAI,CAAC,SAAS,GAAG,IAAI;;;AAa1B;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export enum EventType {\n MFASwipe = \"MFA.SWIPE\",\n Disconnect = \"DISCONNECT\",\n}\n\nexport enum StatusType {\n Pending = \"PENDING\",\n Success = \"SUCCESS\",\n Expired = \"EXPIRED\",\n}\n\nexport interface CyphlensEvent {}\n\nexport interface TwoFactorEvent extends CyphlensEvent { \n sessionId: string;\n status: StatusType;\n timestamp: number;\n expiresAt: number;\n}\n\nexport interface DisconnectEvent extends CyphlensEvent {\n message: string;\n}\n\nexport type EventCallback = (eventType: EventType, data: CyphlensEvent) => void;\nexport type CyphlensErrorCallback = (error: Event) => void;\n","import { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent } from './types';\nexport { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent }\nexport class Cyphlens {\n private baseUrl: string;\n private eventSource: EventSource | null = null;\n private sessionID?: string;\n private onSuccess?: EventCallback;\n private onError?: CyphlensErrorCallback;\n private timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * Initializes the Cyphlens service with a base URL.\n * @param baseUrl The base API URL for connecting to the Cyphlens service.\n */\n constructor(baseUrl: string = \"https://api.cyphme.com/b2c/v1\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Updates the base API URL.\n * @param baseUrl The new base URL.\n */\n setBaseUrl(baseUrl: string): void {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Starts the Server-Sent Events (SSE) connection to listen for authentication events.\n * @returns The EventSource instance if successful, otherwise null.\n */\n private start(): EventSource | null {\n if (!this.sessionID) return null;\n\n this.stop(); // Ensure any existing connections are closed before starting a new one.\n\n this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);\n\n // Listen for MFA swipe events\n this.eventSource.addEventListener(EventType.MFASwipe, (event: MessageEvent) => {\n try {\n const data: TwoFactorEvent = JSON.parse(event.data);\n this.setupTimeout(data.expiresAt);\n this.onSuccess?.(EventType.MFASwipe, data);\n } catch (error) {\n console.error(\"Error parsing event data:\", error);\n const errorEvent = new Event('Something went wrong');\n this.onError?.(errorEvent);\n }\n });\n\n // Handle SSE errors\n this.eventSource.addEventListener(\"error\", (event: Event) => {\n this.onError?.(event);\n this.stop();\n });\n\n return this.eventSource;\n }\n\n /**\n * Sets up a timeout to automatically stop the SSE connection when the event expires.\n * @param expiresAt The expiration timestamp (milliseconds).\n */\n private setupTimeout(expiresAt: number): void {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n }\n\n // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.\n const timeoutDuration = expiresAt - Date.now() + 5000;\n this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);\n }\n\n /**\n * Starts listening for authentication events.\n * @param sessionId The session ID used for authentication.\n * @param onData Callback function for handling successful authentication events.\n * @param onError Callback function for handling errors.\n * @returns The EventSource instance if successfully started, otherwise null.\n */\n listen(sessionId: string, onData?: EventCallback, onError?: CyphlensErrorCallback): EventSource | null {\n this.sessionID = sessionId;\n this.onSuccess = onData;\n this.onError = onError;\n\n // Attach visibility change listener to handle browser background issues (especially for iOS Safari).\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.onVisibilityChange);\n }\n\n return this.start();\n }\n\n /**\n * Stops the SSE connection and clears any active timeouts.\n */\n stop(): void {\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = null;\n }\n }\n\n /**\n * Handles browser visibility changes to restart the SSE connection when the page becomes visible.\n * This is primarily to prevent connection loss in Safari when the tab goes to the background.\n * Only applies to Mobile Safari.\n */\n private readonly onVisibilityChange = (): void => {\n const isMobileSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) &&\n /iP(ad|od|hone)/i.test(navigator.userAgent);\n if (isMobileSafari && document.visibilityState === \"visible\" && this.sessionID) {\n this.start();\n }\n };\n }\n\nexport type CyphlensExports = {\n Cyphlens: typeof Cyphlens;\n EventType: typeof EventType;\n StatusType: typeof StatusType;\n TwoFactorEvent: TwoFactorEvent;\n CyphlensEvent: CyphlensEvent;\n DisconnectEvent: DisconnectEvent;\n EventCallback: EventCallback;\n CyphlensErrorCallback: CyphlensErrorCallback;\n};\n\nexport default Cyphlens;\n"],"names":["EventType","StatusType","Cyphlens","constructor","baseUrl","this","eventSource","timeoutId","onVisibilityChange","test","navigator","userAgent","document","visibilityState","sessionID","start","setBaseUrl","stop","EventSource","addEventListener","MFASwipe","event","data","JSON","parse","setupTimeout","expiresAt","_a","onSuccess","call","error","console","errorEvent","Event","_b","onError","clearTimeout","timeoutDuration","Date","now","setTimeout","listen","sessionId","onData","close"],"mappings":"IAAYA,EAKAC,GALZ,SAAYD,GACVA,EAAA,SAAA,YACAA,EAAA,WAAA,YACD,CAHD,CAAYA,IAAAA,EAGX,CAAA,IAED,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9B,KAAKS,UAAY4B,EACjBrC,KAAKuB,UAAYe,EACjBtC,KAAK8B,QAAUA,EAGS,oBAAbvB,UACTA,SAASO,iBAAiB,mBAAoBd,KAAKG,oBAG9CH,KAAKU,QAMd,IAAAE,GACMZ,KAAKC,cACPD,KAAKC,YAAYsC,QACjBvC,KAAKC,YAAc,MAEjBD,KAAKE,YACP6B,aAAa/B,KAAKE,WAClBF,KAAKE,UAAY"}
package/dist/index.js CHANGED
@@ -1,120 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- exports.EventType = void 0;
6
- (function (EventType) {
7
- EventType["MFASwipe"] = "MFA.SWIPE";
8
- EventType["Disconnect"] = "DISCONNECT";
9
- })(exports.EventType || (exports.EventType = {}));
10
- exports.StatusType = void 0;
11
- (function (StatusType) {
12
- StatusType["Pending"] = "PENDING";
13
- StatusType["Success"] = "SUCCESS";
14
- StatusType["Expired"] = "EXPIRED";
15
- })(exports.StatusType || (exports.StatusType = {}));
16
-
17
- class Cyphlens {
18
- /**
19
- * Initializes the Cyphlens service with a base URL.
20
- * @param baseUrl The base API URL for connecting to the Cyphlens service.
21
- */
22
- constructor(baseUrl = "https://api.cyphme.com/b2c/v1") {
23
- this.eventSource = null;
24
- this.timeoutId = null;
25
- /**
26
- * Handles browser visibility changes to restart the SSE connection when the page becomes visible.
27
- * This is primarily to prevent connection loss in Safari when the tab goes to the background.
28
- */
29
- this.onVisibilityChange = () => {
30
- if (document.visibilityState === "visible" && this.sessionID) {
31
- this.start();
32
- }
33
- };
34
- this.baseUrl = baseUrl;
35
- }
36
- /**
37
- * Updates the base API URL.
38
- * @param baseUrl The new base URL.
39
- */
40
- setBaseUrl(baseUrl) {
41
- this.baseUrl = baseUrl;
42
- }
43
- /**
44
- * Starts the Server-Sent Events (SSE) connection to listen for authentication events.
45
- * @returns The EventSource instance if successful, otherwise null.
46
- */
47
- start() {
48
- if (!this.sessionID)
49
- return null;
50
- this.stop(); // Ensure any existing connections are closed before starting a new one.
51
- this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);
52
- // Listen for MFA swipe events
53
- this.eventSource.addEventListener(exports.EventType.MFASwipe, (event) => {
54
- var _a, _b;
55
- try {
56
- const data = JSON.parse(event.data);
57
- this.setupTimeout(data.expiresAt);
58
- (_a = this.onSuccess) === null || _a === void 0 ? void 0 : _a.call(this, exports.EventType.MFASwipe, data);
59
- }
60
- catch (error) {
61
- console.error("Error parsing event data:", error);
62
- const errorEvent = new Event('Something went wrong');
63
- (_b = this.onError) === null || _b === void 0 ? void 0 : _b.call(this, errorEvent);
64
- }
65
- });
66
- // Handle SSE errors
67
- this.eventSource.addEventListener("error", (event) => {
68
- var _a;
69
- (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, event);
70
- this.stop();
71
- });
72
- return this.eventSource;
73
- }
74
- /**
75
- * Sets up a timeout to automatically stop the SSE connection when the event expires.
76
- * @param expiresAt The expiration timestamp (milliseconds).
77
- */
78
- setupTimeout(expiresAt) {
79
- if (this.timeoutId) {
80
- clearTimeout(this.timeoutId);
81
- }
82
- // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.
83
- const timeoutDuration = expiresAt - Date.now() + 5000;
84
- this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);
85
- }
86
- /**
87
- * Starts listening for authentication events.
88
- * @param sessionId The session ID used for authentication.
89
- * @param onData Callback function for handling successful authentication events.
90
- * @param onError Callback function for handling errors.
91
- * @returns The EventSource instance if successfully started, otherwise null.
92
- */
93
- listen(sessionId, onData, onError) {
94
- this.sessionID = sessionId;
95
- this.onSuccess = onData;
96
- this.onError = onError;
97
- // Attach visibility change listener to handle browser background issues (especially for iOS Safari).
98
- if (typeof document !== "undefined") {
99
- document.addEventListener("visibilitychange", this.onVisibilityChange);
100
- }
101
- return this.start();
102
- }
103
- /**
104
- * Stops the SSE connection and clears any active timeouts.
105
- */
106
- stop() {
107
- if (this.eventSource) {
108
- this.eventSource.close();
109
- this.eventSource = null;
110
- }
111
- if (this.timeoutId) {
112
- clearTimeout(this.timeoutId);
113
- this.timeoutId = null;
114
- }
115
- }
116
- }
117
-
118
- exports.Cyphlens = Cyphlens;
119
- exports.default = Cyphlens;
1
+ "use strict";var t,e;Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventType=void 0,(t=exports.EventType||(exports.EventType={})).MFASwipe="MFA.SWIPE",t.Disconnect="DISCONNECT",exports.StatusType=void 0,(e=exports.StatusType||(exports.StatusType={})).Pending="PENDING",e.Success="SUCCESS",e.Expired="EXPIRED";class s{constructor(t="https://api.cyphme.com/b2c/v1"){this.eventSource=null,this.timeoutId=null,this.onVisibilityChange=()=>{/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&/iP(ad|od|hone)/i.test(navigator.userAgent)&&"visible"===document.visibilityState&&this.sessionID&&this.start()},this.baseUrl=t}setBaseUrl(t){this.baseUrl=t}start(){return this.sessionID?(this.stop(),this.eventSource=new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`),this.eventSource.addEventListener(exports.EventType.MFASwipe,(t=>{var e,s;try{const s=JSON.parse(t.data);this.setupTimeout(s.expiresAt),null===(e=this.onSuccess)||void 0===e||e.call(this,exports.EventType.MFASwipe,s)}catch(t){console.error("Error parsing event data:",t);const e=new Event("Something went wrong");null===(s=this.onError)||void 0===s||s.call(this,e)}})),this.eventSource.addEventListener("error",(t=>{var e;null===(e=this.onError)||void 0===e||e.call(this,t),this.stop()})),this.eventSource):null}setupTimeout(t){this.timeoutId&&clearTimeout(this.timeoutId);const e=t-Date.now()+5e3;this.timeoutId=setTimeout((()=>this.stop()),e)}listen(t,e,s){return this.sessionID=t,this.onSuccess=e,this.onError=s,"undefined"!=typeof document&&document.addEventListener("visibilitychange",this.onVisibilityChange),this.start()}stop(){this.eventSource&&(this.eventSource.close(),this.eventSource=null),this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null)}}exports.Cyphlens=s,exports.default=s;
120
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export enum EventType {\n MFASwipe = \"MFA.SWIPE\",\n Disconnect = \"DISCONNECT\",\n}\n\nexport enum StatusType {\n Pending = \"PENDING\",\n Success = \"SUCCESS\",\n Expired = \"EXPIRED\",\n}\n\nexport interface CyphlensEvent {}\n\nexport interface TwoFactorEvent extends CyphlensEvent { \n sessionId: string;\n status: StatusType;\n timestamp: number;\n expiresAt: number;\n}\n\nexport interface DisconnectEvent extends CyphlensEvent {\n message: string;\n}\n\nexport type EventCallback = (eventType: EventType, data: CyphlensEvent) => void;\nexport type CyphlensErrorCallback = (error: Event) => void;\n","import { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent } from './types';\nexport { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent }\nexport class Cyphlens {\n private baseUrl: string;\n private eventSource: EventSource | null = null;\n private sessionID?: string;\n private onSuccess?: EventCallback;\n private onError?: CyphlensErrorCallback;\n private timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * Initializes the Cyphlens service with a base URL.\n * @param baseUrl The base API URL for connecting to the Cyphlens service.\n */\n constructor(baseUrl: string = \"https://api.cyphme.com/b2c/v1\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Updates the base API URL.\n * @param baseUrl The new base URL.\n */\n setBaseUrl(baseUrl: string): void {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Starts the Server-Sent Events (SSE) connection to listen for authentication events.\n * @returns The EventSource instance if successful, otherwise null.\n */\n private start(): EventSource | null {\n if (!this.sessionID) return null;\n\n this.stop(); // Ensure any existing connections are closed before starting a new one.\n\n this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);\n\n // Listen for MFA swipe events\n this.eventSource.addEventListener(EventType.MFASwipe, (event: MessageEvent) => {\n try {\n const data: TwoFactorEvent = JSON.parse(event.data);\n this.setupTimeout(data.expiresAt);\n this.onSuccess?.(EventType.MFASwipe, data);\n } catch (error) {\n console.error(\"Error parsing event data:\", error);\n const errorEvent = new Event('Something went wrong');\n this.onError?.(errorEvent);\n }\n });\n\n // Handle SSE errors\n this.eventSource.addEventListener(\"error\", (event: Event) => {\n this.onError?.(event);\n this.stop();\n });\n\n return this.eventSource;\n }\n\n /**\n * Sets up a timeout to automatically stop the SSE connection when the event expires.\n * @param expiresAt The expiration timestamp (milliseconds).\n */\n private setupTimeout(expiresAt: number): void {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n }\n\n // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.\n const timeoutDuration = expiresAt - Date.now() + 5000;\n this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);\n }\n\n /**\n * Starts listening for authentication events.\n * @param sessionId The session ID used for authentication.\n * @param onData Callback function for handling successful authentication events.\n * @param onError Callback function for handling errors.\n * @returns The EventSource instance if successfully started, otherwise null.\n */\n listen(sessionId: string, onData?: EventCallback, onError?: CyphlensErrorCallback): EventSource | null {\n this.sessionID = sessionId;\n this.onSuccess = onData;\n this.onError = onError;\n\n // Attach visibility change listener to handle browser background issues (especially for iOS Safari).\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.onVisibilityChange);\n }\n\n return this.start();\n }\n\n /**\n * Stops the SSE connection and clears any active timeouts.\n */\n stop(): void {\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = null;\n }\n }\n\n /**\n * Handles browser visibility changes to restart the SSE connection when the page becomes visible.\n * This is primarily to prevent connection loss in Safari when the tab goes to the background.\n */\n private readonly onVisibilityChange = (): void => {\n if (document.visibilityState === \"visible\" && this.sessionID) {\n this.start();\n }\n };\n}\n\nexport type CyphlensExports = {\n Cyphlens: typeof Cyphlens;\n EventType: typeof EventType;\n StatusType: typeof StatusType;\n TwoFactorEvent: TwoFactorEvent;\n CyphlensEvent: CyphlensEvent;\n DisconnectEvent: DisconnectEvent;\n EventCallback: EventCallback;\n CyphlensErrorCallback: CyphlensErrorCallback;\n};\n\nexport default Cyphlens;\n"],"names":["EventType","StatusType"],"mappings":";;;;AAAYA;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,UAAA,CAAA,GAAA,WAAsB;AACtB,IAAA,SAAA,CAAA,YAAA,CAAA,GAAA,YAAyB;AAC3B,CAAC,EAHWA,iBAAS,KAATA,iBAAS,GAGpB,EAAA,CAAA,CAAA;AAEWC;AAAZ,CAAA,UAAY,UAAU,EAAA;AACpB,IAAA,UAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,UAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACnB,IAAA,UAAA,CAAA,SAAA,CAAA,GAAA,SAAmB;AACrB,CAAC,EAJWA,kBAAU,KAAVA,kBAAU,GAIrB,EAAA,CAAA,CAAA;;MCPY,QAAQ,CAAA;AAQnB;;;AAGG;AACH,IAAA,WAAA,CAAY,UAAkB,+BAA+B,EAAA;QAVrD,IAAW,CAAA,WAAA,GAAuB,IAAI;QAItC,IAAS,CAAA,SAAA,GAAyC,IAAI;AAmG9D;;;AAGG;QACc,IAAkB,CAAA,kBAAA,GAAG,MAAW;YAC/C,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,EAAE;gBAC5D,IAAI,CAAC,KAAK,EAAE;;AAEhB,SAAC;AApGC,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;;AAGxB;;;AAGG;AACH,IAAA,UAAU,CAAC,OAAe,EAAA;AACxB,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;;AAGxB;;;AAGG;IACK,KAAK,GAAA;QACX,IAAI,CAAC,IAAI,CAAC,SAAS;AAAE,YAAA,OAAO,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AAI,CAAC,WAAW;;AAGzB;;;AAGG;AACK,IAAA,YAAY,CAAC,SAAiB,EAAA;AACpC,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAClB,YAAA,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC;;;QAI9B,MAAM,eAAe,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI;AACrD,QAAA,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,EAAE,eAAe,CAAC;;AAGjE;;;;;;AAMG;AACH,IAAA,MAAM,CAAC,SAAiB,EAAE,MAAsB,EAAE,OAA+B,EAAA;AAC/E,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS;AAC1B,QAAA,IAAI,CAAC,SAAS,GAAG,MAAM;AACvB,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;;AAGtB,QAAA,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;YACnC,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC;;AAGxE,QAAA,OAAO,IAAI,CAAC,KAAK,EAAE;;AAGrB;;AAEG;IACH,IAAI,GAAA;AACF,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;AACpB,YAAA,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;AACxB,YAAA,IAAI,CAAC,WAAW,GAAG,IAAI;;AAEzB,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;AAClB,YAAA,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC;AAC5B,YAAA,IAAI,CAAC,SAAS,GAAG,IAAI;;;AAa1B;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export enum EventType {\n MFASwipe = \"MFA.SWIPE\",\n Disconnect = \"DISCONNECT\",\n}\n\nexport enum StatusType {\n Pending = \"PENDING\",\n Success = \"SUCCESS\",\n Expired = \"EXPIRED\",\n}\n\nexport interface CyphlensEvent {}\n\nexport interface TwoFactorEvent extends CyphlensEvent { \n sessionId: string;\n status: StatusType;\n timestamp: number;\n expiresAt: number;\n}\n\nexport interface DisconnectEvent extends CyphlensEvent {\n message: string;\n}\n\nexport type EventCallback = (eventType: EventType, data: CyphlensEvent) => void;\nexport type CyphlensErrorCallback = (error: Event) => void;\n","import { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent } from './types';\nexport { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent }\nexport class Cyphlens {\n private baseUrl: string;\n private eventSource: EventSource | null = null;\n private sessionID?: string;\n private onSuccess?: EventCallback;\n private onError?: CyphlensErrorCallback;\n private timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * Initializes the Cyphlens service with a base URL.\n * @param baseUrl The base API URL for connecting to the Cyphlens service.\n */\n constructor(baseUrl: string = \"https://api.cyphme.com/b2c/v1\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Updates the base API URL.\n * @param baseUrl The new base URL.\n */\n setBaseUrl(baseUrl: string): void {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Starts the Server-Sent Events (SSE) connection to listen for authentication events.\n * @returns The EventSource instance if successful, otherwise null.\n */\n private start(): EventSource | null {\n if (!this.sessionID) return null;\n\n this.stop(); // Ensure any existing connections are closed before starting a new one.\n\n this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);\n\n // Listen for MFA swipe events\n this.eventSource.addEventListener(EventType.MFASwipe, (event: MessageEvent) => {\n try {\n const data: TwoFactorEvent = JSON.parse(event.data);\n this.setupTimeout(data.expiresAt);\n this.onSuccess?.(EventType.MFASwipe, data);\n } catch (error) {\n console.error(\"Error parsing event data:\", error);\n const errorEvent = new Event('Something went wrong');\n this.onError?.(errorEvent);\n }\n });\n\n // Handle SSE errors\n this.eventSource.addEventListener(\"error\", (event: Event) => {\n this.onError?.(event);\n this.stop();\n });\n\n return this.eventSource;\n }\n\n /**\n * Sets up a timeout to automatically stop the SSE connection when the event expires.\n * @param expiresAt The expiration timestamp (milliseconds).\n */\n private setupTimeout(expiresAt: number): void {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n }\n\n // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.\n const timeoutDuration = expiresAt - Date.now() + 5000;\n this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);\n }\n\n /**\n * Starts listening for authentication events.\n * @param sessionId The session ID used for authentication.\n * @param onData Callback function for handling successful authentication events.\n * @param onError Callback function for handling errors.\n * @returns The EventSource instance if successfully started, otherwise null.\n */\n listen(sessionId: string, onData?: EventCallback, onError?: CyphlensErrorCallback): EventSource | null {\n this.sessionID = sessionId;\n this.onSuccess = onData;\n this.onError = onError;\n\n // Attach visibility change listener to handle browser background issues (especially for iOS Safari).\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.onVisibilityChange);\n }\n\n return this.start();\n }\n\n /**\n * Stops the SSE connection and clears any active timeouts.\n */\n stop(): void {\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = null;\n }\n }\n\n /**\n * Handles browser visibility changes to restart the SSE connection when the page becomes visible.\n * This is primarily to prevent connection loss in Safari when the tab goes to the background.\n * Only applies to Mobile Safari.\n */\n private readonly onVisibilityChange = (): void => {\n const isMobileSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) &&\n /iP(ad|od|hone)/i.test(navigator.userAgent);\n if (isMobileSafari && document.visibilityState === \"visible\" && this.sessionID) {\n this.start();\n }\n };\n }\n\nexport type CyphlensExports = {\n Cyphlens: typeof Cyphlens;\n EventType: typeof EventType;\n StatusType: typeof StatusType;\n TwoFactorEvent: TwoFactorEvent;\n CyphlensEvent: CyphlensEvent;\n DisconnectEvent: DisconnectEvent;\n EventCallback: EventCallback;\n CyphlensErrorCallback: CyphlensErrorCallback;\n};\n\nexport default Cyphlens;\n"],"names":["EventType","StatusType","Cyphlens","constructor","baseUrl","this","eventSource","timeoutId","onVisibilityChange","test","navigator","userAgent","document","visibilityState","sessionID","start","setBaseUrl","stop","EventSource","addEventListener","MFASwipe","event","data","JSON","parse","setupTimeout","expiresAt","_a","onSuccess","call","error","console","errorEvent","Event","_b","onError","clearTimeout","timeoutDuration","Date","now","setTimeout","listen","sessionId","onData","close"],"mappings":"aAAA,IAAYA,EAKAC,yDALAD,QAAAA,eAAAA,GAAAA,EAAAA,QAASA,YAATA,kBAGX,CAAA,IAFC,SAAA,YACAA,EAAA,WAAA,aAGUC,QAAAA,gBAAAA,GAAAA,EAAAA,QAAUA,aAAVA,mBAIX,CAAA,IAHC,QAAA,UACAA,EAAA,QAAA,UACAA,EAAA,QAAA,gBCNWC,EAYX,WAAAC,CAAYC,EAAkB,iCAVtBC,KAAWC,YAAuB,KAIlCD,KAASE,UAAyC,KAwGzCF,KAAkBG,mBAAG,KACb,iCAAiCC,KAAKC,UAAUC,YACjD,kBAAkBF,KAAKC,UAAUC,YACJ,YAA7BC,SAASC,iBAAiCR,KAAKS,WACnET,KAAKU,SArGPV,KAAKD,QAAUA,EAOjB,UAAAY,CAAWZ,GACTC,KAAKD,QAAUA,EAOT,KAAAW,GACN,OAAKV,KAAKS,WAEVT,KAAKY,OAELZ,KAAKC,YAAc,IAAIY,YAAY,GAAGb,KAAKD,sCAAsCC,KAAKS,aAGtFT,KAAKC,YAAYa,iBAAiBnB,QAASA,UAACoB,UAAWC,YACrD,IACE,MAAMC,EAAuBC,KAAKC,MAAMH,EAAMC,MAC9CjB,KAAKoB,aAAaH,EAAKI,WACN,QAAjBC,EAAAtB,KAAKuB,iBAAY,IAAAD,GAAAA,EAAAE,KAAAxB,KAAAL,QAAAA,UAAUoB,SAAUE,GACrC,MAAOQ,GACPC,QAAQD,MAAM,4BAA6BA,GAC3C,MAAME,EAAa,IAAIC,MAAM,wBACd,QAAfC,EAAA7B,KAAK8B,eAAU,IAAAD,GAAAA,EAAAL,KAAAxB,KAAA2B,OAKnB3B,KAAKC,YAAYa,iBAAiB,SAAUE,UAC3B,QAAfM,EAAAtB,KAAK8B,eAAU,IAAAR,GAAAA,EAAAE,KAAAxB,KAAAgB,GACfhB,KAAKY,MAAM,IAGNZ,KAAKC,aAzBgB,KAgCtB,YAAAmB,CAAaC,GACfrB,KAAKE,WACP6B,aAAa/B,KAAKE,WAIpB,MAAM8B,EAAkBX,EAAYY,KAAKC,MAAQ,IACjDlC,KAAKE,UAAYiC,YAAW,IAAMnC,KAAKY,QAAQoB,GAUjD,MAAAI,CAAOC,EAAmBC,EAAwBR,GAUhD,OATA9B,KAAKS,UAAY4B,EACjBrC,KAAKuB,UAAYe,EACjBtC,KAAK8B,QAAUA,EAGS,oBAAbvB,UACTA,SAASO,iBAAiB,mBAAoBd,KAAKG,oBAG9CH,KAAKU,QAMd,IAAAE,GACMZ,KAAKC,cACPD,KAAKC,YAAYsC,QACjBvC,KAAKC,YAAc,MAEjBD,KAAKE,YACP6B,aAAa/B,KAAKE,WAClBF,KAAKE,UAAY"}
package/dist/index.umd.js CHANGED
@@ -1,126 +1,2 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CyphlensSSE = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- exports.EventType = void 0;
8
- (function (EventType) {
9
- EventType["MFASwipe"] = "MFA.SWIPE";
10
- EventType["Disconnect"] = "DISCONNECT";
11
- })(exports.EventType || (exports.EventType = {}));
12
- exports.StatusType = void 0;
13
- (function (StatusType) {
14
- StatusType["Pending"] = "PENDING";
15
- StatusType["Success"] = "SUCCESS";
16
- StatusType["Expired"] = "EXPIRED";
17
- })(exports.StatusType || (exports.StatusType = {}));
18
-
19
- class Cyphlens {
20
- /**
21
- * Initializes the Cyphlens service with a base URL.
22
- * @param baseUrl The base API URL for connecting to the Cyphlens service.
23
- */
24
- constructor(baseUrl = "https://api.cyphme.com/b2c/v1") {
25
- this.eventSource = null;
26
- this.timeoutId = null;
27
- /**
28
- * Handles browser visibility changes to restart the SSE connection when the page becomes visible.
29
- * This is primarily to prevent connection loss in Safari when the tab goes to the background.
30
- */
31
- this.onVisibilityChange = () => {
32
- if (document.visibilityState === "visible" && this.sessionID) {
33
- this.start();
34
- }
35
- };
36
- this.baseUrl = baseUrl;
37
- }
38
- /**
39
- * Updates the base API URL.
40
- * @param baseUrl The new base URL.
41
- */
42
- setBaseUrl(baseUrl) {
43
- this.baseUrl = baseUrl;
44
- }
45
- /**
46
- * Starts the Server-Sent Events (SSE) connection to listen for authentication events.
47
- * @returns The EventSource instance if successful, otherwise null.
48
- */
49
- start() {
50
- if (!this.sessionID)
51
- return null;
52
- this.stop(); // Ensure any existing connections are closed before starting a new one.
53
- this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);
54
- // Listen for MFA swipe events
55
- this.eventSource.addEventListener(exports.EventType.MFASwipe, (event) => {
56
- var _a, _b;
57
- try {
58
- const data = JSON.parse(event.data);
59
- this.setupTimeout(data.expiresAt);
60
- (_a = this.onSuccess) === null || _a === void 0 ? void 0 : _a.call(this, exports.EventType.MFASwipe, data);
61
- }
62
- catch (error) {
63
- console.error("Error parsing event data:", error);
64
- const errorEvent = new Event('Something went wrong');
65
- (_b = this.onError) === null || _b === void 0 ? void 0 : _b.call(this, errorEvent);
66
- }
67
- });
68
- // Handle SSE errors
69
- this.eventSource.addEventListener("error", (event) => {
70
- var _a;
71
- (_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, event);
72
- this.stop();
73
- });
74
- return this.eventSource;
75
- }
76
- /**
77
- * Sets up a timeout to automatically stop the SSE connection when the event expires.
78
- * @param expiresAt The expiration timestamp (milliseconds).
79
- */
80
- setupTimeout(expiresAt) {
81
- if (this.timeoutId) {
82
- clearTimeout(this.timeoutId);
83
- }
84
- // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.
85
- const timeoutDuration = expiresAt - Date.now() + 5000;
86
- this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);
87
- }
88
- /**
89
- * Starts listening for authentication events.
90
- * @param sessionId The session ID used for authentication.
91
- * @param onData Callback function for handling successful authentication events.
92
- * @param onError Callback function for handling errors.
93
- * @returns The EventSource instance if successfully started, otherwise null.
94
- */
95
- listen(sessionId, onData, onError) {
96
- this.sessionID = sessionId;
97
- this.onSuccess = onData;
98
- this.onError = onError;
99
- // Attach visibility change listener to handle browser background issues (especially for iOS Safari).
100
- if (typeof document !== "undefined") {
101
- document.addEventListener("visibilitychange", this.onVisibilityChange);
102
- }
103
- return this.start();
104
- }
105
- /**
106
- * Stops the SSE connection and clears any active timeouts.
107
- */
108
- stop() {
109
- if (this.eventSource) {
110
- this.eventSource.close();
111
- this.eventSource = null;
112
- }
113
- if (this.timeoutId) {
114
- clearTimeout(this.timeoutId);
115
- this.timeoutId = null;
116
- }
117
- }
118
- }
119
-
120
- exports.Cyphlens = Cyphlens;
121
- exports.default = Cyphlens;
122
-
123
- Object.defineProperty(exports, '__esModule', { value: true });
124
-
125
- }));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CyphlensSSE={})}(this,(function(e){"use strict";var t,s;e.EventType=void 0,(t=e.EventType||(e.EventType={})).MFASwipe="MFA.SWIPE",t.Disconnect="DISCONNECT",e.StatusType=void 0,(s=e.StatusType||(e.StatusType={})).Pending="PENDING",s.Success="SUCCESS",s.Expired="EXPIRED";class i{constructor(e="https://api.cyphme.com/b2c/v1"){this.eventSource=null,this.timeoutId=null,this.onVisibilityChange=()=>{/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&/iP(ad|od|hone)/i.test(navigator.userAgent)&&"visible"===document.visibilityState&&this.sessionID&&this.start()},this.baseUrl=e}setBaseUrl(e){this.baseUrl=e}start(){return this.sessionID?(this.stop(),this.eventSource=new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`),this.eventSource.addEventListener(e.EventType.MFASwipe,(t=>{var s,i;try{const i=JSON.parse(t.data);this.setupTimeout(i.expiresAt),null===(s=this.onSuccess)||void 0===s||s.call(this,e.EventType.MFASwipe,i)}catch(e){console.error("Error parsing event data:",e);const t=new Event("Something went wrong");null===(i=this.onError)||void 0===i||i.call(this,t)}})),this.eventSource.addEventListener("error",(e=>{var t;null===(t=this.onError)||void 0===t||t.call(this,e),this.stop()})),this.eventSource):null}setupTimeout(e){this.timeoutId&&clearTimeout(this.timeoutId);const t=e-Date.now()+5e3;this.timeoutId=setTimeout((()=>this.stop()),t)}listen(e,t,s){return this.sessionID=e,this.onSuccess=t,this.onError=s,"undefined"!=typeof document&&document.addEventListener("visibilitychange",this.onVisibilityChange),this.start()}stop(){this.eventSource&&(this.eventSource.close(),this.eventSource=null),this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null)}}e.Cyphlens=i,e.default=i,Object.defineProperty(e,"__esModule",{value:!0})}));
126
2
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export enum EventType {\n MFASwipe = \"MFA.SWIPE\",\n Disconnect = \"DISCONNECT\",\n}\n\nexport enum StatusType {\n Pending = \"PENDING\",\n Success = \"SUCCESS\",\n Expired = \"EXPIRED\",\n}\n\nexport interface CyphlensEvent {}\n\nexport interface TwoFactorEvent extends CyphlensEvent { \n sessionId: string;\n status: StatusType;\n timestamp: number;\n expiresAt: number;\n}\n\nexport interface DisconnectEvent extends CyphlensEvent {\n message: string;\n}\n\nexport type EventCallback = (eventType: EventType, data: CyphlensEvent) => void;\nexport type CyphlensErrorCallback = (error: Event) => void;\n","import { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent } from './types';\nexport { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent }\nexport class Cyphlens {\n private baseUrl: string;\n private eventSource: EventSource | null = null;\n private sessionID?: string;\n private onSuccess?: EventCallback;\n private onError?: CyphlensErrorCallback;\n private timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * Initializes the Cyphlens service with a base URL.\n * @param baseUrl The base API URL for connecting to the Cyphlens service.\n */\n constructor(baseUrl: string = \"https://api.cyphme.com/b2c/v1\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Updates the base API URL.\n * @param baseUrl The new base URL.\n */\n setBaseUrl(baseUrl: string): void {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Starts the Server-Sent Events (SSE) connection to listen for authentication events.\n * @returns The EventSource instance if successful, otherwise null.\n */\n private start(): EventSource | null {\n if (!this.sessionID) return null;\n\n this.stop(); // Ensure any existing connections are closed before starting a new one.\n\n this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);\n\n // Listen for MFA swipe events\n this.eventSource.addEventListener(EventType.MFASwipe, (event: MessageEvent) => {\n try {\n const data: TwoFactorEvent = JSON.parse(event.data);\n this.setupTimeout(data.expiresAt);\n this.onSuccess?.(EventType.MFASwipe, data);\n } catch (error) {\n console.error(\"Error parsing event data:\", error);\n const errorEvent = new Event('Something went wrong');\n this.onError?.(errorEvent);\n }\n });\n\n // Handle SSE errors\n this.eventSource.addEventListener(\"error\", (event: Event) => {\n this.onError?.(event);\n this.stop();\n });\n\n return this.eventSource;\n }\n\n /**\n * Sets up a timeout to automatically stop the SSE connection when the event expires.\n * @param expiresAt The expiration timestamp (milliseconds).\n */\n private setupTimeout(expiresAt: number): void {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n }\n\n // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.\n const timeoutDuration = expiresAt - Date.now() + 5000;\n this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);\n }\n\n /**\n * Starts listening for authentication events.\n * @param sessionId The session ID used for authentication.\n * @param onData Callback function for handling successful authentication events.\n * @param onError Callback function for handling errors.\n * @returns The EventSource instance if successfully started, otherwise null.\n */\n listen(sessionId: string, onData?: EventCallback, onError?: CyphlensErrorCallback): EventSource | null {\n this.sessionID = sessionId;\n this.onSuccess = onData;\n this.onError = onError;\n\n // Attach visibility change listener to handle browser background issues (especially for iOS Safari).\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.onVisibilityChange);\n }\n\n return this.start();\n }\n\n /**\n * Stops the SSE connection and clears any active timeouts.\n */\n stop(): void {\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = null;\n }\n }\n\n /**\n * Handles browser visibility changes to restart the SSE connection when the page becomes visible.\n * This is primarily to prevent connection loss in Safari when the tab goes to the background.\n */\n private readonly onVisibilityChange = (): void => {\n if (document.visibilityState === \"visible\" && this.sessionID) {\n this.start();\n }\n };\n}\n\nexport type CyphlensExports = {\n Cyphlens: typeof Cyphlens;\n EventType: typeof EventType;\n StatusType: typeof StatusType;\n TwoFactorEvent: TwoFactorEvent;\n CyphlensEvent: CyphlensEvent;\n DisconnectEvent: DisconnectEvent;\n EventCallback: EventCallback;\n CyphlensErrorCallback: CyphlensErrorCallback;\n};\n\nexport default Cyphlens;\n"],"names":["EventType","StatusType"],"mappings":";;;;;;AAAYA;EAAZ,CAAA,UAAY,SAAS,EAAA;EACnB,IAAA,SAAA,CAAA,UAAA,CAAA,GAAA,WAAsB;EACtB,IAAA,SAAA,CAAA,YAAA,CAAA,GAAA,YAAyB;EAC3B,CAAC,EAHWA,iBAAS,KAATA,iBAAS,GAGpB,EAAA,CAAA,CAAA;AAEWC;EAAZ,CAAA,UAAY,UAAU,EAAA;EACpB,IAAA,UAAA,CAAA,SAAA,CAAA,GAAA,SA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QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;;EAGtB,QAAA,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;cACnC,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB,CAAC;;EAGxE,QAAA,OAAO,IAAI,CAAC,KAAK,EAAE;;EAGrB;;EAEG;MACH,IAAI,GAAA;EACF,QAAA,IAAI,IAAI,CAAC,WAAW,EAAE;EACpB,YAAA,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;EACxB,YAAA,IAAI,CAAC,WAAW,GAAG,IAAI;;EAEzB,QAAA,IAAI,IAAI,CAAC,SAAS,EAAE;EAClB,YAAA,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC;EAC5B,YAAA,IAAI,CAAC,SAAS,GAAG,IAAI;;;EAa1B;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/types.ts","../src/index.ts"],"sourcesContent":["export enum EventType {\n MFASwipe = \"MFA.SWIPE\",\n Disconnect = \"DISCONNECT\",\n}\n\nexport enum StatusType {\n Pending = \"PENDING\",\n Success = \"SUCCESS\",\n Expired = \"EXPIRED\",\n}\n\nexport interface CyphlensEvent {}\n\nexport interface TwoFactorEvent extends CyphlensEvent { \n sessionId: string;\n status: StatusType;\n timestamp: number;\n expiresAt: number;\n}\n\nexport interface DisconnectEvent extends CyphlensEvent {\n message: string;\n}\n\nexport type EventCallback = (eventType: EventType, data: CyphlensEvent) => void;\nexport type CyphlensErrorCallback = (error: Event) => void;\n","import { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent } from './types';\nexport { EventCallback, TwoFactorEvent, EventType, CyphlensErrorCallback, StatusType, DisconnectEvent, CyphlensEvent }\nexport class Cyphlens {\n private baseUrl: string;\n private eventSource: EventSource | null = null;\n private sessionID?: string;\n private onSuccess?: EventCallback;\n private onError?: CyphlensErrorCallback;\n private timeoutId: ReturnType<typeof setTimeout> | null = null;\n\n /**\n * Initializes the Cyphlens service with a base URL.\n * @param baseUrl The base API URL for connecting to the Cyphlens service.\n */\n constructor(baseUrl: string = \"https://api.cyphme.com/b2c/v1\") {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Updates the base API URL.\n * @param baseUrl The new base URL.\n */\n setBaseUrl(baseUrl: string): void {\n this.baseUrl = baseUrl;\n }\n\n /**\n * Starts the Server-Sent Events (SSE) connection to listen for authentication events.\n * @returns The EventSource instance if successful, otherwise null.\n */\n private start(): EventSource | null {\n if (!this.sessionID) return null;\n\n this.stop(); // Ensure any existing connections are closed before starting a new one.\n\n this.eventSource = new EventSource(`${this.baseUrl}/cyphlens/status-events?sid=${this.sessionID}`);\n\n // Listen for MFA swipe events\n this.eventSource.addEventListener(EventType.MFASwipe, (event: MessageEvent) => {\n try {\n const data: TwoFactorEvent = JSON.parse(event.data);\n this.setupTimeout(data.expiresAt);\n this.onSuccess?.(EventType.MFASwipe, data);\n } catch (error) {\n console.error(\"Error parsing event data:\", error);\n const errorEvent = new Event('Something went wrong');\n this.onError?.(errorEvent);\n }\n });\n\n // Handle SSE errors\n this.eventSource.addEventListener(\"error\", (event: Event) => {\n this.onError?.(event);\n this.stop();\n });\n\n return this.eventSource;\n }\n\n /**\n * Sets up a timeout to automatically stop the SSE connection when the event expires.\n * @param expiresAt The expiration timestamp (milliseconds).\n */\n private setupTimeout(expiresAt: number): void {\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n }\n\n // Calculate timeout duration and add a buffer (5000ms) before stopping the connection.\n const timeoutDuration = expiresAt - Date.now() + 5000;\n this.timeoutId = setTimeout(() => this.stop(), timeoutDuration);\n }\n\n /**\n * Starts listening for authentication events.\n * @param sessionId The session ID used for authentication.\n * @param onData Callback function for handling successful authentication events.\n * @param onError Callback function for handling errors.\n * @returns The EventSource instance if successfully started, otherwise null.\n */\n listen(sessionId: string, onData?: EventCallback, onError?: CyphlensErrorCallback): EventSource | null {\n this.sessionID = sessionId;\n this.onSuccess = onData;\n this.onError = onError;\n\n // Attach visibility change listener to handle browser background issues (especially for iOS Safari).\n if (typeof document !== \"undefined\") {\n document.addEventListener(\"visibilitychange\", this.onVisibilityChange);\n }\n\n return this.start();\n }\n\n /**\n * Stops the SSE connection and clears any active timeouts.\n */\n stop(): void {\n if (this.eventSource) {\n this.eventSource.close();\n this.eventSource = null;\n }\n if (this.timeoutId) {\n clearTimeout(this.timeoutId);\n this.timeoutId = null;\n }\n }\n\n /**\n * Handles browser visibility changes to restart the SSE connection when the page becomes visible.\n * This is primarily to prevent connection loss in Safari when the tab goes to the background.\n * Only applies to Mobile Safari.\n */\n private readonly onVisibilityChange = (): void => {\n const isMobileSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent) &&\n /iP(ad|od|hone)/i.test(navigator.userAgent);\n if (isMobileSafari && document.visibilityState === \"visible\" && this.sessionID) {\n this.start();\n }\n };\n }\n\nexport type CyphlensExports = {\n Cyphlens: typeof Cyphlens;\n EventType: typeof EventType;\n StatusType: typeof StatusType;\n TwoFactorEvent: TwoFactorEvent;\n CyphlensEvent: CyphlensEvent;\n DisconnectEvent: DisconnectEvent;\n EventCallback: EventCallback;\n CyphlensErrorCallback: CyphlensErrorCallback;\n};\n\nexport default Cyphlens;\n"],"names":["EventType","StatusType","Cyphlens","constructor","baseUrl","this","eventSource","timeoutId","onVisibilityChange","test","navigator","userAgent","document","visibilityState","sessionID","start","setBaseUrl","stop","EventSource","addEventListener","MFASwipe","event","data","JSON","parse","setupTimeout","expiresAt","_a","onSuccess","call","error","console","errorEvent","Event","_b","onError","clearTimeout","timeoutDuration","Date","now","setTimeout","listen","sessionId","onData","close"],"mappings":"mPAAA,IAAYA,EAKAC,EALAD,EAAAA,eAAAA,GAAAA,EAAAA,EAASA,YAATA,YAGX,CAAA,IAFC,SAAA,YACAA,EAAA,WAAA,aAGUC,EAAAA,gBAAAA,GAAAA,EAAAA,EAAUA,aAAVA,aAIX,CAAA,IAHC,QAAA,UACAA,EAAA,QAA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A,EAGS,oBAAbvB,UACTA,SAASO,iBAAiB,mBAAoBd,KAAKG,oBAG9CH,KAAKU,QAMd,IAAAE,GACMZ,KAAKC,cACPD,KAAKC,YAAYsC,QACjBvC,KAAKC,YAAc,MAEjBD,KAAKE,YACP6B,aAAa/B,KAAKE,WAClBF,KAAKE,UAAY"}
@@ -40,9 +40,10 @@ export declare class Cyphlens {
40
40
  */
41
41
  stop(): void;
42
42
  /**
43
- * Handles browser visibility changes to restart the SSE connection when the page becomes visible.
44
- * This is primarily to prevent connection loss in Safari when the tab goes to the background.
45
- */
43
+ * Handles browser visibility changes to restart the SSE connection when the page becomes visible.
44
+ * This is primarily to prevent connection loss in Safari when the tab goes to the background.
45
+ * Only applies to Mobile Safari.
46
+ */
46
47
  private readonly onVisibilityChange;
47
48
  }
48
49
  export type CyphlensExports = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,qBAAqB,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtI,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,EAAE,qBAAqB,EAAE,UAAU,EAAE,eAAe,EAAE,aAAa,EAAE,CAAA;AACtH,qBAAa,QAAQ;IACnB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAC,CAAgB;IAClC,OAAO,CAAC,OAAO,CAAC,CAAwB;IACxC,OAAO,CAAC,SAAS,CAA8C;IAE/D;;;OAGG;gBACS,OAAO,GAAE,MAAwC;IAI7D;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIjC;;;OAGG;IACH,OAAO,CAAC,KAAK;IA6Bb;;;OAGG;IACH,OAAO,CAAC,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OAGG;IACH,OAAO,CAAC,KAAK;IA6Bb;;;OAGG;IACH,OAAO,CAAC,YAAY;IAUpB;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,WAAW,GAAG,IAAI;IAatG;;OAEG;IACH,IAAI,IAAI,IAAI;IAWZ;;;;KAIC;IACD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAMjC;CACD;AAEH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,OAAO,QAAQ,CAAC;IAC1B,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,cAAc,EAAE,cAAc,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;IAC7B,eAAe,EAAE,eAAe,CAAC;IACjC,aAAa,EAAE,aAAa,CAAC;IAC7B,qBAAqB,EAAE,qBAAqB,CAAC;CAC9C,CAAC;AAEF,eAAe,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@cyphlens/2fa-sse-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "private": false,
5
5
  "description": "Cyphlens SDK for 2FA SSE",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.esm.js",
8
- "browser": "dist/index.umd.js",
8
+ "browser": "dist/bundle.min.js",
9
9
  "types": "dist/types/index.d.ts",
10
10
  "publishConfig": {
11
11
  "access": "restricted"
@@ -25,6 +25,7 @@
25
25
  "jest-environment-jsdom": "^29.7.0",
26
26
  "jsdom": "^25.0.1",
27
27
  "rollup": "^4.24.0",
28
+ "rollup-plugin-terser": "^7.0.2",
28
29
  "rollup-plugin-typescript2": "^0.36.0",
29
30
  "ts-jest": "^29.2.5",
30
31
  "tsx": "^4.19.2",
@@ -41,4 +42,4 @@
41
42
  "dependencies": {
42
43
  "eventsource": "^2.0.2"
43
44
  }
44
- }
45
+ }