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