@juspay-tech/hyperswitch-control-center-embed-core 1.0.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/README.md ADDED
@@ -0,0 +1,31 @@
1
+ @juspay-tech/hyperswitch-control-center-embed-core
2
+
3
+ **Hyperswitch Control Center Embed - Core** - Core JavaScript SDK for embedding Hyperswitch control center components.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @juspay-tech/hyperswitch-control-center-embed-core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ import { loadHyperswitch } from '@juspay-tech/hyperswitch-control-center-embed-core';
15
+
16
+ // Initialize and use the SDK
17
+ const hyperswitch = loadHyperswitch({
18
+ // your configuration
19
+ });
20
+ ```
21
+
22
+ ## Features
23
+
24
+ - Vanilla JavaScript implementation
25
+ - No framework dependencies
26
+ - TypeScript support
27
+ - Tree-shakeable exports
28
+
29
+ ## License
30
+
31
+ ISC
@@ -0,0 +1,8 @@
1
+ import { Hyperswitch } from './hyperswitch';
2
+ import { HyperswitchElement } from './element';
3
+ import { ElementOptions } from './types';
4
+ export declare class ConnectorConfigurationComponent extends HyperswitchElement {
5
+ constructor(instance: Hyperswitch, options?: ElementOptions);
6
+ protected getElementType(): string;
7
+ protected getIframeSrc(): string;
8
+ }
@@ -0,0 +1,20 @@
1
+ import { Hyperswitch } from './hyperswitch';
2
+ import { ElementOptions } from './types';
3
+ declare abstract class HyperswitchElement {
4
+ protected instance: Hyperswitch;
5
+ protected options: ElementOptions;
6
+ element: HTMLElement;
7
+ protected iframe: HTMLIFrameElement;
8
+ private boundMessageHandler;
9
+ readonly _internalId: string;
10
+ constructor(instance: Hyperswitch, options?: ElementOptions);
11
+ private setupElement;
12
+ private setupIframe;
13
+ private handleMessage;
14
+ mount(domNode: string | HTMLElement): HyperswitchElement;
15
+ destroy(): void;
16
+ protected abstract getElementType(): string;
17
+ protected abstract getIframeSrc(): string;
18
+ getIframe(): HTMLIFrameElement;
19
+ }
20
+ export { HyperswitchElement };
@@ -0,0 +1,20 @@
1
+ import { HyperswitchElement } from './element';
2
+ import { HyperswitchInitOptions } from './types';
3
+ declare class Hyperswitch {
4
+ private token;
5
+ private fetchToken;
6
+ private initConfig;
7
+ private activeElements;
8
+ private isRefetchingToken;
9
+ private initPromise;
10
+ private tokenError;
11
+ constructor(options: HyperswitchInitOptions);
12
+ private fetchInitialToken;
13
+ private listenForMessages;
14
+ private refetchAndBroadcastToken;
15
+ private sendErrorToActiveElements;
16
+ create(type: string, options?: any): HyperswitchElement;
17
+ onElementIframeLoaded(element: HyperswitchElement): void;
18
+ }
19
+ export declare function loadHyperswitch(options: HyperswitchInitOptions): Hyperswitch;
20
+ export { Hyperswitch };
@@ -0,0 +1,6 @@
1
+ export { loadHyperswitch, Hyperswitch } from './hyperswitch';
2
+ export { HyperswitchElement } from './element';
3
+ export { ConnectorConfigurationComponent } from './connector-configuration';
4
+ export type { HyperswitchInitOptions, ElementOptions } from './types';
5
+ export type { MerchantTheme } from './init-config';
6
+ export declare const VERSION = "1.0.0";
@@ -0,0 +1,327 @@
1
+ const isBrowser$1 = typeof window !== 'undefined';
2
+ class HyperswitchElement {
3
+ constructor(instance, options) {
4
+ this.instance = instance;
5
+ this.options = options || {};
6
+ this._internalId = `hyper-el-${Math.random().toString(36).substring(7)}`;
7
+ this.boundMessageHandler = null;
8
+ // In SSR / non-browser environments, avoid touching DOM APIs.
9
+ // The React wrapper only creates and mounts elements on the client,
10
+ // so it's safe for server-side usage as long as we no-op here.
11
+ if (!isBrowser$1) {
12
+ return;
13
+ }
14
+ this.element = document.createElement('div');
15
+ this.iframe = document.createElement('iframe');
16
+ this.boundMessageHandler = this.handleMessage.bind(this);
17
+ this.setupElement();
18
+ this.setupIframe();
19
+ window.addEventListener('message', this.boundMessageHandler);
20
+ }
21
+ setupElement() {
22
+ if (!isBrowser$1) {
23
+ return;
24
+ }
25
+ this.element.className = `hyperswitch-element ${this.options.className || ''}`.trim();
26
+ this.element.dataset.hyperswitchElement = this.getElementType();
27
+ Object.assign(this.element.style, Object.assign({ width: this.options.width || '100%', height: this.options.height || '500px', overflow: 'hidden' }, (this.options.style || {})));
28
+ }
29
+ setupIframe() {
30
+ if (!isBrowser$1) {
31
+ return;
32
+ }
33
+ this.iframe.src = this.getIframeSrc();
34
+ this.iframe.style.border = 'none';
35
+ this.iframe.style.width = '100%';
36
+ this.iframe.style.height = '100%';
37
+ this.iframe.title = `Hyperswitch ${this.getElementType()}`;
38
+ this.iframe.setAttribute('allow', 'clipboard-read; clipboard-write; clipboard-sanitized-write');
39
+ this.iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups allow-forms allow-modals allow-presentation allow-downloads');
40
+ this.element.appendChild(this.iframe);
41
+ }
42
+ handleMessage(event) {
43
+ var _a;
44
+ if (!isBrowser$1) {
45
+ return;
46
+ }
47
+ if (this.options.onMessage) {
48
+ this.options.onMessage(event.data);
49
+ }
50
+ if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'EMBEDDED_COMPONENT_RESIZE') {
51
+ const newHeight = event.data.height;
52
+ const messageComponent = event.data.component || '';
53
+ if (messageComponent === this.getElementType() && typeof newHeight === 'number' && newHeight > 0) {
54
+ this.element.style.height = `${newHeight}px`;
55
+ if (this.options.onResize) {
56
+ this.options.onResize({
57
+ width: this.element.clientWidth,
58
+ height: newHeight
59
+ });
60
+ }
61
+ }
62
+ }
63
+ }
64
+ mount(domNode) {
65
+ if (!isBrowser$1) {
66
+ throw new Error('HyperswitchElement.mount can only be called in a browser environment');
67
+ }
68
+ const parent = typeof domNode === 'string'
69
+ ? document.querySelector(domNode)
70
+ : domNode;
71
+ if (!parent) {
72
+ throw new Error(`Invalid mount point: ${domNode}`);
73
+ }
74
+ parent.appendChild(this.element);
75
+ return this;
76
+ }
77
+ destroy() {
78
+ if (!isBrowser$1) {
79
+ return;
80
+ }
81
+ if (this.boundMessageHandler) {
82
+ window.removeEventListener('message', this.boundMessageHandler);
83
+ }
84
+ if (this.element && this.element.parentNode) {
85
+ this.element.parentNode.removeChild(this.element);
86
+ }
87
+ }
88
+ getIframe() {
89
+ return this.iframe;
90
+ }
91
+ }
92
+
93
+ class ConnectorConfigurationComponent extends HyperswitchElement {
94
+ constructor(instance, options) {
95
+ super(instance, options);
96
+ }
97
+ getElementType() {
98
+ return 'connectors';
99
+ }
100
+ getIframeSrc() {
101
+ const baseUrl = this.options.url || 'http://localhost:9000';
102
+ return `${baseUrl}/embedded/connectors`;
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Build the init_config object that Control Center expects
108
+ * from the simple MerchantTheme contract.
109
+ *
110
+ * Any missing value is set to null.
111
+ */
112
+ function buildInitConfig(merchantTheme) {
113
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
114
+ const safeTheme = merchantTheme || {};
115
+ return {
116
+ settings: {
117
+ colors: {
118
+ primary: (_a = safeTheme.primaryColor) !== null && _a !== void 0 ? _a : null,
119
+ secondary: null,
120
+ background: (_b = safeTheme.backgroundColor) !== null && _b !== void 0 ? _b : null
121
+ },
122
+ sidebar: null,
123
+ typography: null,
124
+ buttons: {
125
+ primary: {
126
+ backgroundColor: (_e = (_d = (_c = safeTheme.buttons) === null || _c === void 0 ? void 0 : _c.primary) === null || _d === void 0 ? void 0 : _d.backgroundColor) !== null && _e !== void 0 ? _e : null,
127
+ textColor: (_h = (_g = (_f = safeTheme.buttons) === null || _f === void 0 ? void 0 : _f.primary) === null || _g === void 0 ? void 0 : _g.textColor) !== null && _h !== void 0 ? _h : null,
128
+ hoverBackgroundColor: (_l = (_k = (_j = safeTheme.buttons) === null || _j === void 0 ? void 0 : _j.primary) === null || _k === void 0 ? void 0 : _k.hoverBackgroundColor) !== null && _l !== void 0 ? _l : null
129
+ },
130
+ secondary: {
131
+ backgroundColor: (_p = (_o = (_m = safeTheme.buttons) === null || _m === void 0 ? void 0 : _m.secondary) === null || _o === void 0 ? void 0 : _o.backgroundColor) !== null && _p !== void 0 ? _p : null,
132
+ textColor: (_s = (_r = (_q = safeTheme.buttons) === null || _q === void 0 ? void 0 : _q.secondary) === null || _r === void 0 ? void 0 : _r.textColor) !== null && _s !== void 0 ? _s : null,
133
+ hoverBackgroundColor: (_v = (_u = (_t = safeTheme.buttons) === null || _t === void 0 ? void 0 : _t.secondary) === null || _u === void 0 ? void 0 : _u.hoverBackgroundColor) !== null && _v !== void 0 ? _v : null
134
+ }
135
+ },
136
+ borders: null,
137
+ spacing: null
138
+ },
139
+ urls: {
140
+ faviconUrl: null,
141
+ logoUrl: null
142
+ }
143
+ };
144
+ }
145
+
146
+ const isBrowser = typeof window !== 'undefined';
147
+ class Hyperswitch {
148
+ constructor(options) {
149
+ this.token = null;
150
+ this.initConfig = null;
151
+ this.activeElements = new Map();
152
+ this.isRefetchingToken = false;
153
+ this.tokenError = null;
154
+ if (!options || typeof options.fetchToken !== 'function') {
155
+ throw new Error('loadHyperswitch requires a fetchToken callback function');
156
+ }
157
+ this.fetchToken = options.fetchToken;
158
+ this.initConfig = options.initConfig ? buildInitConfig(options.initConfig) : null;
159
+ this.initPromise = this.fetchInitialToken();
160
+ this.listenForMessages();
161
+ }
162
+ fetchInitialToken() {
163
+ const eagerTokenPromise = (() => {
164
+ try {
165
+ return this.fetchToken();
166
+ }
167
+ catch (error) {
168
+ return Promise.reject(error);
169
+ }
170
+ })();
171
+ return eagerTokenPromise.then((token) => {
172
+ if (token) {
173
+ this.token = token;
174
+ }
175
+ else {
176
+ this.tokenError = 'Failed to fetch token: Token returned empty or undefined';
177
+ }
178
+ }).catch((error) => {
179
+ this.tokenError = `Failed to fetch token: ${error instanceof Error ? error.message : String(error)}`;
180
+ });
181
+ }
182
+ listenForMessages() {
183
+ if (!isBrowser) {
184
+ // In SSR / non-browser environments we can't listen for postMessage events,
185
+ // but it's still safe to create a Hyperswitch instance (it will become
186
+ // useful on the client where another instance will typically be created).
187
+ return;
188
+ }
189
+ window.addEventListener("message", async (event) => {
190
+ var _a, _b, _c;
191
+ if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === "TOKEN_EXPIRED" && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.value) === true) {
192
+ await this.refetchAndBroadcastToken();
193
+ }
194
+ else if (((_c = event.data) === null || _c === void 0 ? void 0 : _c.type) === "EMBEDDED_IFRAME_READY") {
195
+ // Find the element whose iframe matches the event source
196
+ this.activeElements.forEach((element) => {
197
+ const iframe = element.getIframe();
198
+ if ((iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === event.source) {
199
+ this.onElementIframeLoaded(element);
200
+ }
201
+ });
202
+ }
203
+ });
204
+ }
205
+ async refetchAndBroadcastToken() {
206
+ if (this.isRefetchingToken) {
207
+ return;
208
+ }
209
+ this.isRefetchingToken = true;
210
+ try {
211
+ const newToken = await this.fetchToken();
212
+ if (newToken) {
213
+ this.token = newToken;
214
+ this.tokenError = null;
215
+ this.activeElements.forEach((element, elementId) => {
216
+ const iframe = element.getIframe();
217
+ if (iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) {
218
+ iframe.contentWindow.postMessage({
219
+ type: 'AUTH_TOKEN',
220
+ token: this.token
221
+ }, '*');
222
+ }
223
+ });
224
+ }
225
+ else {
226
+ this.tokenError = 'Failed to refetch token: Token returned empty or undefined';
227
+ this.sendErrorToActiveElements(this.tokenError);
228
+ }
229
+ }
230
+ catch (error) {
231
+ this.tokenError = `Failed to refetch token: ${error instanceof Error ? error.message : String(error)}`;
232
+ this.sendErrorToActiveElements(this.tokenError);
233
+ }
234
+ finally {
235
+ this.isRefetchingToken = false;
236
+ }
237
+ }
238
+ sendErrorToActiveElements(errorMessage) {
239
+ this.activeElements.forEach((element) => {
240
+ const iframe = element.getIframe();
241
+ if (iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) {
242
+ iframe.contentWindow.postMessage({
243
+ type: 'AUTH_ERROR',
244
+ error: errorMessage
245
+ }, '*');
246
+ }
247
+ });
248
+ }
249
+ create(type, options) {
250
+ let element;
251
+ switch (type) {
252
+ case 'connectors':
253
+ element = new ConnectorConfigurationComponent(this, options);
254
+ break;
255
+ default:
256
+ throw new Error(`Unknown element type: ${type}`);
257
+ }
258
+ this.activeElements.set(element._internalId, element);
259
+ return element;
260
+ }
261
+ onElementIframeLoaded(element) {
262
+ this.initPromise.then(() => {
263
+ const iframe = element.getIframe();
264
+ if (!(iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow)) {
265
+ return;
266
+ }
267
+ setTimeout(() => {
268
+ try {
269
+ const contentWindow = iframe.contentWindow;
270
+ if (!contentWindow) {
271
+ return;
272
+ }
273
+ if (this.tokenError) {
274
+ contentWindow.postMessage({
275
+ type: 'AUTH_ERROR',
276
+ error: this.tokenError
277
+ }, '*');
278
+ }
279
+ else if (this.token) {
280
+ contentWindow.postMessage({
281
+ type: 'AUTH_TOKEN',
282
+ token: this.token
283
+ }, '*');
284
+ }
285
+ else {
286
+ contentWindow.postMessage({
287
+ type: 'AUTH_ERROR',
288
+ error: 'No token available'
289
+ }, '*');
290
+ }
291
+ // Send init_config (if available) as a separate message
292
+ if (this.initConfig) {
293
+ contentWindow.postMessage({
294
+ type: 'INIT_CONFIG',
295
+ init_config: this.initConfig
296
+ }, '*');
297
+ }
298
+ }
299
+ catch (error) {
300
+ }
301
+ }, 100);
302
+ }).catch((error) => {
303
+ const iframe = element.getIframe();
304
+ const contentWindow = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow;
305
+ if (contentWindow) {
306
+ setTimeout(() => {
307
+ try {
308
+ contentWindow.postMessage({
309
+ type: 'AUTH_ERROR',
310
+ error: `Token initialization failed: ${error instanceof Error ? error.message : String(error)}`
311
+ }, '*');
312
+ }
313
+ catch (_a) {
314
+ }
315
+ }, 100);
316
+ }
317
+ });
318
+ }
319
+ }
320
+ function loadHyperswitch(options) {
321
+ return new Hyperswitch(options);
322
+ }
323
+
324
+ const VERSION = '1.0.0';
325
+
326
+ export { ConnectorConfigurationComponent, Hyperswitch, HyperswitchElement, VERSION, loadHyperswitch };
327
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/element.ts","../src/connector-configuration.ts","../src/init-config.ts","../src/hyperswitch.ts","../src/index.ts"],"sourcesContent":["import { Hyperswitch } from './hyperswitch';\nimport { ElementOptions } from './types';\n\nconst isBrowser = typeof window !== 'undefined';\n\nabstract class HyperswitchElement {\n protected instance: Hyperswitch;\n protected options: ElementOptions;\n public element!: HTMLElement;\n protected iframe!: HTMLIFrameElement;\n private boundMessageHandler: ((event: MessageEvent) => void) | null;\n public readonly _internalId: string;\n \n constructor(instance: Hyperswitch, options?: ElementOptions) {\n this.instance = instance;\n this.options = options || {};\n this._internalId = `hyper-el-${Math.random().toString(36).substring(7)}`;\n this.boundMessageHandler = null;\n // In SSR / non-browser environments, avoid touching DOM APIs.\n // The React wrapper only creates and mounts elements on the client,\n // so it's safe for server-side usage as long as we no-op here.\n if (!isBrowser) {\n return;\n }\n \n this.element = document.createElement('div');\n this.iframe = document.createElement('iframe');\n this.boundMessageHandler = this.handleMessage.bind(this);\n \n this.setupElement();\n this.setupIframe();\n window.addEventListener('message', this.boundMessageHandler);\n }\n\n private setupElement(): void {\n if (!isBrowser) {\n return;\n }\n\n this.element.className = `hyperswitch-element ${this.options.className || ''}`.trim();\n this.element.dataset.hyperswitchElement = this.getElementType();\n \n Object.assign(this.element.style, {\n width: this.options.width || '100%',\n height: this.options.height || '500px',\n overflow: 'hidden',\n ...(this.options.style || {})\n });\n }\n \n private setupIframe(): void {\n if (!isBrowser) {\n return;\n }\n\n this.iframe.src = this.getIframeSrc();\n this.iframe.style.border = 'none';\n this.iframe.style.width = '100%';\n this.iframe.style.height = '100%';\n this.iframe.title = `Hyperswitch ${this.getElementType()}`;\n this.iframe.setAttribute('allow', 'clipboard-read; clipboard-write; clipboard-sanitized-write');\n this.iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups allow-forms allow-modals allow-presentation allow-downloads');\n \n this.element.appendChild(this.iframe);\n }\n \n private handleMessage(event: MessageEvent): void {\n if (!isBrowser) {\n return;\n }\n\n if (this.options.onMessage) {\n this.options.onMessage(event.data);\n }\n \n if (event.data?.type === 'EMBEDDED_COMPONENT_RESIZE') {\n const newHeight = event.data.height;\n const messageComponent = event.data.component || '';\n \n if (messageComponent === this.getElementType() && typeof newHeight === 'number' && newHeight > 0) {\n this.element.style.height = `${newHeight}px`;\n \n if (this.options.onResize) {\n this.options.onResize({\n width: this.element.clientWidth,\n height: newHeight\n });\n }\n }\n }\n }\n \n mount(domNode: string | HTMLElement): HyperswitchElement {\n if (!isBrowser) {\n throw new Error('HyperswitchElement.mount can only be called in a browser environment');\n }\n\n const parent = typeof domNode === 'string' \n ? document.querySelector(domNode) \n : domNode;\n \n if (!parent) {\n throw new Error(`Invalid mount point: ${domNode}`);\n }\n \n parent.appendChild(this.element);\n return this;\n }\n \n destroy(): void {\n if (!isBrowser) {\n return;\n }\n if (this.boundMessageHandler) {\n window.removeEventListener('message', this.boundMessageHandler);\n }\n \n if (this.element && this.element.parentNode) {\n this.element.parentNode.removeChild(this.element);\n }\n }\n \n protected abstract getElementType(): string;\n protected abstract getIframeSrc(): string;\n\n public getIframe(): HTMLIFrameElement {\n return this.iframe;\n }\n}\n\nexport { HyperswitchElement };\n","import { Hyperswitch } from './hyperswitch';\nimport { HyperswitchElement } from './element';\nimport { ElementOptions } from './types';\n\nexport class ConnectorConfigurationComponent extends HyperswitchElement {\n constructor(instance: Hyperswitch, options?: ElementOptions) {\n super(instance, options);\n }\n \n protected getElementType(): string {\n return 'connectors';\n }\n \n protected getIframeSrc(): string {\n const baseUrl = this.options.url || 'http://localhost:9000';\n return `${baseUrl}/embedded/connectors`;\n }\n}\n","/**\n * Theme configuration received from the merchant.\n * This is the ONLY contract we expect merchants to follow.\n */\nexport type MerchantTheme = {\n /** Primary color */\n primaryColor?: string;\n /** Page background color */\n backgroundColor?: string;\n /** Button configurations */\n buttons?: {\n /** Primary button configuration */\n primary?: {\n /** Primary button background color */\n backgroundColor?: string;\n /** Primary button text color */\n textColor?: string;\n /** Primary button hover background color */\n hoverBackgroundColor?: string;\n };\n /** Secondary button configuration */\n secondary?: {\n /** Secondary button background color */\n backgroundColor?: string;\n /** Secondary button text color */\n textColor?: string;\n /** Secondary button hover background color */\n hoverBackgroundColor?: string;\n };\n };\n};\n\n/**\n * Full init_config payload shape sent to the Control Center.\n * Most fields are null for now; Control Center applies defaults.\n */\nexport type InitConfig = {\n settings: {\n colors: {\n primary: string | null;\n secondary: string | null;\n background: string | null;\n };\n sidebar: null;\n typography: null;\n buttons: {\n primary: {\n backgroundColor: string | null;\n textColor: string | null;\n hoverBackgroundColor: string | null;\n };\n secondary: {\n backgroundColor: string | null;\n textColor: string | null;\n hoverBackgroundColor: string | null;\n };\n };\n borders: null;\n spacing: null;\n };\n urls: {\n faviconUrl: null;\n logoUrl: null;\n };\n};\n\n/**\n * Build the init_config object that Control Center expects\n * from the simple MerchantTheme contract.\n *\n * Any missing value is set to null.\n */\nexport function buildInitConfig(merchantTheme: MerchantTheme | undefined | null): InitConfig {\n const safeTheme = merchantTheme || {};\n\n return {\n settings: {\n colors: {\n primary: safeTheme.primaryColor ?? null,\n secondary: null,\n background: safeTheme.backgroundColor ?? null\n },\n sidebar: null,\n typography: null,\n buttons: {\n primary: {\n backgroundColor: safeTheme.buttons?.primary?.backgroundColor ?? null,\n textColor: safeTheme.buttons?.primary?.textColor ?? null,\n hoverBackgroundColor: safeTheme.buttons?.primary?.hoverBackgroundColor ?? null\n },\n secondary: {\n backgroundColor: safeTheme.buttons?.secondary?.backgroundColor ?? null,\n textColor: safeTheme.buttons?.secondary?.textColor ?? null,\n hoverBackgroundColor: safeTheme.buttons?.secondary?.hoverBackgroundColor ?? null\n }\n },\n borders: null,\n spacing: null\n },\n urls: {\n faviconUrl: null,\n logoUrl: null\n }\n };\n}\n\n\n","import { HyperswitchElement } from './element';\nimport { ConnectorConfigurationComponent } from './connector-configuration';\nimport { HyperswitchInitOptions } from './types';\nimport { buildInitConfig,InitConfig } from './init-config';\n\nconst isBrowser = typeof window !== 'undefined';\n\nclass Hyperswitch {\n private token: string | null = null;\n private fetchToken: () => Promise<string | undefined>;\n private initConfig: InitConfig | null = null;\n private activeElements: Map<string, HyperswitchElement> = new Map();\n private isRefetchingToken: boolean = false;\n private initPromise: Promise<void>;\n private tokenError: string | null = null;\n\n constructor(options: HyperswitchInitOptions) {\n if (!options || typeof options.fetchToken !== 'function') {\n throw new Error('loadHyperswitch requires a fetchToken callback function');\n }\n\n this.fetchToken = options.fetchToken;\n this.initConfig = options.initConfig ? buildInitConfig(options.initConfig) : null;\n this.initPromise = this.fetchInitialToken();\n this.listenForMessages();\n }\n\n private fetchInitialToken(): Promise<void> {\n const eagerTokenPromise = (() => {\n try {\n return this.fetchToken();\n } catch (error) {\n return Promise.reject(error);\n }\n })();\n\n return eagerTokenPromise.then((token) => {\n if (token) {\n this.token = token;\n } else {\n this.tokenError = 'Failed to fetch token: Token returned empty or undefined';\n }\n }).catch((error) => {\n this.tokenError = `Failed to fetch token: ${error instanceof Error ? error.message : String(error)}`;\n });\n } \n\n private listenForMessages(): void {\n if (!isBrowser) {\n // In SSR / non-browser environments we can't listen for postMessage events,\n // but it's still safe to create a Hyperswitch instance (it will become\n // useful on the client where another instance will typically be created).\n return;\n }\n\n window.addEventListener(\"message\", async (event) => {\n if (event.data?.type === \"TOKEN_EXPIRED\" && event.data?.value === true) {\n await this.refetchAndBroadcastToken();\n } else if (event.data?.type === \"EMBEDDED_IFRAME_READY\") {\n // Find the element whose iframe matches the event source\n this.activeElements.forEach((element) => {\n const iframe = element.getIframe();\n if (iframe?.contentWindow === event.source) {\n this.onElementIframeLoaded(element);\n }\n });\n }\n });\n }\n\n private async refetchAndBroadcastToken(): Promise<void> {\n if (this.isRefetchingToken) {\n return;\n }\n \n this.isRefetchingToken = true;\n \n try {\n const newToken = await this.fetchToken();\n \n if (newToken) {\n this.token = newToken;\n this.tokenError = null;\n this.activeElements.forEach((element, elementId) => {\n const iframe = element.getIframe();\n if (iframe?.contentWindow) {\n iframe.contentWindow.postMessage({\n type: 'AUTH_TOKEN',\n token: this.token\n }, '*');\n }\n });\n } else {\n this.tokenError = 'Failed to refetch token: Token returned empty or undefined';\n this.sendErrorToActiveElements(this.tokenError);\n }\n } catch (error) {\n this.tokenError = `Failed to refetch token: ${error instanceof Error ? error.message : String(error)}`;\n this.sendErrorToActiveElements(this.tokenError);\n } finally {\n this.isRefetchingToken = false;\n }\n }\n\n private sendErrorToActiveElements(errorMessage: string): void {\n this.activeElements.forEach((element) => {\n const iframe = element.getIframe();\n if (iframe?.contentWindow) {\n iframe.contentWindow.postMessage({\n type: 'AUTH_ERROR',\n error: errorMessage\n }, '*');\n }\n });\n }\n\n public create(type: string, options?: any): HyperswitchElement {\n let element: HyperswitchElement;\n \n switch (type) {\n case 'connectors':\n element = new ConnectorConfigurationComponent(this, options);\n break;\n default:\n throw new Error(`Unknown element type: ${type}`);\n }\n \n this.activeElements.set(element._internalId, element);\n \n return element;\n }\n\n public onElementIframeLoaded(element: HyperswitchElement): void {\n this.initPromise.then(() => {\n const iframe = element.getIframe();\n if (!iframe?.contentWindow) {\n return;\n }\n \n setTimeout(() => {\n try {\n const contentWindow = iframe.contentWindow;\n if (!contentWindow) {\n return;\n }\n\n if (this.tokenError) {\n contentWindow.postMessage({\n type: 'AUTH_ERROR',\n error: this.tokenError\n }, '*');\n } else if (this.token) {\n contentWindow.postMessage({\n type: 'AUTH_TOKEN',\n token: this.token\n }, '*');\n } else {\n contentWindow.postMessage({\n type: 'AUTH_ERROR',\n error: 'No token available'\n }, '*');\n }\n\n // Send init_config (if available) as a separate message\n if (this.initConfig) {\n contentWindow.postMessage({\n type: 'INIT_CONFIG',\n init_config: this.initConfig\n }, '*');\n }\n } catch (error) {\n }\n }, 100);\n }).catch((error) => {\n const iframe = element.getIframe();\n const contentWindow = iframe?.contentWindow;\n if (contentWindow) {\n setTimeout(() => {\n try {\n contentWindow.postMessage({\n type: 'AUTH_ERROR',\n error: `Token initialization failed: ${error instanceof Error ? error.message : String(error)}`\n }, '*');\n } catch {\n }\n }, 100);\n }\n });\n }\n}\n\nexport function loadHyperswitch(options: HyperswitchInitOptions): Hyperswitch {\n return new Hyperswitch(options);\n}\n\nexport { Hyperswitch };\n","export { loadHyperswitch, Hyperswitch } from './hyperswitch';\nexport { HyperswitchElement } from './element';\nexport { ConnectorConfigurationComponent } from './connector-configuration';\nexport type { HyperswitchInitOptions, ElementOptions } from './types';\nexport type { MerchantTheme } from './init-config';\n\nexport const VERSION = '1.0.0';\n"],"names":["isBrowser"],"mappings":"AAGA,MAAMA,WAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAEhD,MAAe,kBAAkB,CAAA;IAQ/B,WAAY,CAAA,QAAqB,EAAE,OAAwB,EAAA;AACzD,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AACzB,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;AAC7B,QAAA,IAAI,CAAC,WAAW,GAAG,YAAY,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;AACzE,QAAA,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;;;;QAIhC,IAAI,CAACA,WAAS,EAAE;YACd,OAAO;SACR;QAED,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEzD,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,MAA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