@imtbl/auth 2.10.7-alpha.2 → 2.10.7-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,15 +20,11 @@ export default class EmbeddedLoginPrompt {
20
20
  this.config = config;
21
21
  }
22
22
 
23
- private getHref = (anonymousId?: string) => {
24
- let href = `${this.config.authenticationDomain}/im-embedded-login-prompt`
23
+ private getHref = () => {
24
+ const href = `${this.config.authenticationDomain}/im-embedded-login-prompt`
25
25
  + `?client_id=${this.config.oidcConfiguration.clientId}`
26
26
  + `&rid=${getDetail(Detail.RUNTIME_ID)}`;
27
27
 
28
- if (anonymousId) {
29
- href += `&third_party_a_id=${anonymousId}`;
30
- }
31
-
32
28
  return href;
33
29
  };
34
30
 
@@ -77,10 +73,10 @@ export default class EmbeddedLoginPrompt {
77
73
  document.head.appendChild(style);
78
74
  };
79
75
 
80
- private getEmbeddedLoginIFrame = (anonymousId?: string) => {
76
+ private getEmbeddedLoginIFrame = () => {
81
77
  const embeddedLoginPrompt = document.createElement('iframe');
82
78
  embeddedLoginPrompt.id = LOGIN_PROMPT_IFRAME_ID;
83
- embeddedLoginPrompt.src = this.getHref(anonymousId);
79
+ embeddedLoginPrompt.src = this.getHref();
84
80
  embeddedLoginPrompt.style.height = '100vh';
85
81
  embeddedLoginPrompt.style.width = '100vw';
86
82
  embeddedLoginPrompt.style.maxHeight = `${LOGIN_PROMPT_WINDOW_HEIGHT}px`;
@@ -96,9 +92,9 @@ export default class EmbeddedLoginPrompt {
96
92
  return embeddedLoginPrompt;
97
93
  };
98
94
 
99
- public displayEmbeddedLoginPrompt(anonymousId?: string): Promise<EmbeddedLoginPromptResult> {
95
+ public displayEmbeddedLoginPrompt(): Promise<EmbeddedLoginPromptResult> {
100
96
  return new Promise((resolve, reject) => {
101
- const embeddedLoginPrompt = this.getEmbeddedLoginIFrame(anonymousId);
97
+ const embeddedLoginPrompt = this.getEmbeddedLoginIFrame();
102
98
  const messageHandler = ({ data, origin }: MessageEvent) => {
103
99
  if (
104
100
  origin !== this.config.authenticationDomain
@@ -2,7 +2,7 @@ import { PopupOverlayOptions } from '../types';
2
2
  import { PASSPORT_OVERLAY_CLOSE_ID, PASSPORT_OVERLAY_TRY_AGAIN_ID } from './constants';
3
3
  import { addLink, getBlockedOverlay, getGenericOverlay } from './elements';
4
4
 
5
- export default class ConfirmationOverlay {
5
+ export default class LoginPopupOverlay {
6
6
  private disableGenericPopupOverlay: boolean;
7
7
 
8
8
  private disableBlockedPopupOverlay: boolean;
package/src/types.ts CHANGED
@@ -126,3 +126,33 @@ export type DirectLoginOptions = {
126
126
  marketingConsentStatus?: MarketingConsentStatus;
127
127
  email?: string;
128
128
  };
129
+
130
+ /**
131
+ * Extended login options with caching and silent login support
132
+ */
133
+ export type LoginOptions = {
134
+ /** If true, attempts to use cached session without user interaction */
135
+ useCachedSession?: boolean;
136
+ /** If true, attempts silent authentication (force token refresh) */
137
+ useSilentLogin?: boolean;
138
+ /** If true, uses redirect flow instead of popup flow */
139
+ useRedirectFlow?: boolean;
140
+ /** Direct login options (social provider, email, etc.) */
141
+ directLoginOptions?: DirectLoginOptions;
142
+ };
143
+
144
+ /**
145
+ * Authentication events emitted by the Auth class
146
+ */
147
+ export enum AuthEvents {
148
+ LOGGED_OUT = 'loggedOut',
149
+ LOGGED_IN = 'loggedIn',
150
+ }
151
+
152
+ /**
153
+ * Event map for typed event emitter
154
+ */
155
+ export interface AuthEventMap extends Record<string, any> {
156
+ [AuthEvents.LOGGED_OUT]: [];
157
+ [AuthEvents.LOGGED_IN]: [User];
158
+ }
@@ -0,0 +1,26 @@
1
+ import { EventEmitter } from 'events';
2
+
3
+ export default class TypedEventEmitter<TEvents extends Record<string, any>> {
4
+ private emitter = new EventEmitter();
5
+
6
+ emit<TEventName extends keyof TEvents & string>(
7
+ eventName: TEventName,
8
+ ...eventArg: TEvents[TEventName]
9
+ ) {
10
+ this.emitter.emit(eventName, ...(eventArg as []));
11
+ }
12
+
13
+ on<TEventName extends keyof TEvents & string>(
14
+ eventName: TEventName,
15
+ handler: (...eventArg: TEvents[TEventName]) => void,
16
+ ) {
17
+ this.emitter.on(eventName, handler as any);
18
+ }
19
+
20
+ removeListener<TEventName extends keyof TEvents & string>(
21
+ eventName: TEventName,
22
+ handler: (...eventArg: TEvents[TEventName]) => void,
23
+ ) {
24
+ this.emitter.removeListener(eventName, handler as any);
25
+ }
26
+ }