@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 +31 -0
- package/dist/connector-configuration.d.ts +8 -0
- package/dist/element.d.ts +20 -0
- package/dist/hyperswitch.d.ts +20 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +327 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +335 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/dist/index.umd.js +341 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/init-config.d.ts +71 -0
- package/dist/types.d.ts +37 -0
- package/package.json +56 -0
|
@@ -0,0 +1,341 @@
|
|
|
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.Hyperswitch = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const isBrowser$1 = typeof window !== 'undefined';
|
|
8
|
+
class HyperswitchElement {
|
|
9
|
+
constructor(instance, options) {
|
|
10
|
+
this.instance = instance;
|
|
11
|
+
this.options = options || {};
|
|
12
|
+
this._internalId = `hyper-el-${Math.random().toString(36).substring(7)}`;
|
|
13
|
+
this.boundMessageHandler = null;
|
|
14
|
+
// In SSR / non-browser environments, avoid touching DOM APIs.
|
|
15
|
+
// The React wrapper only creates and mounts elements on the client,
|
|
16
|
+
// so it's safe for server-side usage as long as we no-op here.
|
|
17
|
+
if (!isBrowser$1) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.element = document.createElement('div');
|
|
21
|
+
this.iframe = document.createElement('iframe');
|
|
22
|
+
this.boundMessageHandler = this.handleMessage.bind(this);
|
|
23
|
+
this.setupElement();
|
|
24
|
+
this.setupIframe();
|
|
25
|
+
window.addEventListener('message', this.boundMessageHandler);
|
|
26
|
+
}
|
|
27
|
+
setupElement() {
|
|
28
|
+
if (!isBrowser$1) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.element.className = `hyperswitch-element ${this.options.className || ''}`.trim();
|
|
32
|
+
this.element.dataset.hyperswitchElement = this.getElementType();
|
|
33
|
+
Object.assign(this.element.style, Object.assign({ width: this.options.width || '100%', height: this.options.height || '500px', overflow: 'hidden' }, (this.options.style || {})));
|
|
34
|
+
}
|
|
35
|
+
setupIframe() {
|
|
36
|
+
if (!isBrowser$1) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.iframe.src = this.getIframeSrc();
|
|
40
|
+
this.iframe.style.border = 'none';
|
|
41
|
+
this.iframe.style.width = '100%';
|
|
42
|
+
this.iframe.style.height = '100%';
|
|
43
|
+
this.iframe.title = `Hyperswitch ${this.getElementType()}`;
|
|
44
|
+
this.iframe.setAttribute('allow', 'clipboard-read; clipboard-write; clipboard-sanitized-write');
|
|
45
|
+
this.iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups allow-forms allow-modals allow-presentation allow-downloads');
|
|
46
|
+
this.element.appendChild(this.iframe);
|
|
47
|
+
}
|
|
48
|
+
handleMessage(event) {
|
|
49
|
+
var _a;
|
|
50
|
+
if (!isBrowser$1) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (this.options.onMessage) {
|
|
54
|
+
this.options.onMessage(event.data);
|
|
55
|
+
}
|
|
56
|
+
if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === 'EMBEDDED_COMPONENT_RESIZE') {
|
|
57
|
+
const newHeight = event.data.height;
|
|
58
|
+
const messageComponent = event.data.component || '';
|
|
59
|
+
if (messageComponent === this.getElementType() && typeof newHeight === 'number' && newHeight > 0) {
|
|
60
|
+
this.element.style.height = `${newHeight}px`;
|
|
61
|
+
if (this.options.onResize) {
|
|
62
|
+
this.options.onResize({
|
|
63
|
+
width: this.element.clientWidth,
|
|
64
|
+
height: newHeight
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
mount(domNode) {
|
|
71
|
+
if (!isBrowser$1) {
|
|
72
|
+
throw new Error('HyperswitchElement.mount can only be called in a browser environment');
|
|
73
|
+
}
|
|
74
|
+
const parent = typeof domNode === 'string'
|
|
75
|
+
? document.querySelector(domNode)
|
|
76
|
+
: domNode;
|
|
77
|
+
if (!parent) {
|
|
78
|
+
throw new Error(`Invalid mount point: ${domNode}`);
|
|
79
|
+
}
|
|
80
|
+
parent.appendChild(this.element);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
destroy() {
|
|
84
|
+
if (!isBrowser$1) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (this.boundMessageHandler) {
|
|
88
|
+
window.removeEventListener('message', this.boundMessageHandler);
|
|
89
|
+
}
|
|
90
|
+
if (this.element && this.element.parentNode) {
|
|
91
|
+
this.element.parentNode.removeChild(this.element);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
getIframe() {
|
|
95
|
+
return this.iframe;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class ConnectorConfigurationComponent extends HyperswitchElement {
|
|
100
|
+
constructor(instance, options) {
|
|
101
|
+
super(instance, options);
|
|
102
|
+
}
|
|
103
|
+
getElementType() {
|
|
104
|
+
return 'connectors';
|
|
105
|
+
}
|
|
106
|
+
getIframeSrc() {
|
|
107
|
+
const baseUrl = this.options.url || 'http://localhost:9000';
|
|
108
|
+
return `${baseUrl}/embedded/connectors`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Build the init_config object that Control Center expects
|
|
114
|
+
* from the simple MerchantTheme contract.
|
|
115
|
+
*
|
|
116
|
+
* Any missing value is set to null.
|
|
117
|
+
*/
|
|
118
|
+
function buildInitConfig(merchantTheme) {
|
|
119
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
120
|
+
const safeTheme = merchantTheme || {};
|
|
121
|
+
return {
|
|
122
|
+
settings: {
|
|
123
|
+
colors: {
|
|
124
|
+
primary: (_a = safeTheme.primaryColor) !== null && _a !== void 0 ? _a : null,
|
|
125
|
+
secondary: null,
|
|
126
|
+
background: (_b = safeTheme.backgroundColor) !== null && _b !== void 0 ? _b : null
|
|
127
|
+
},
|
|
128
|
+
sidebar: null,
|
|
129
|
+
typography: null,
|
|
130
|
+
buttons: {
|
|
131
|
+
primary: {
|
|
132
|
+
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,
|
|
133
|
+
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,
|
|
134
|
+
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
|
|
135
|
+
},
|
|
136
|
+
secondary: {
|
|
137
|
+
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,
|
|
138
|
+
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,
|
|
139
|
+
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
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
borders: null,
|
|
143
|
+
spacing: null
|
|
144
|
+
},
|
|
145
|
+
urls: {
|
|
146
|
+
faviconUrl: null,
|
|
147
|
+
logoUrl: null
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const isBrowser = typeof window !== 'undefined';
|
|
153
|
+
class Hyperswitch {
|
|
154
|
+
constructor(options) {
|
|
155
|
+
this.token = null;
|
|
156
|
+
this.initConfig = null;
|
|
157
|
+
this.activeElements = new Map();
|
|
158
|
+
this.isRefetchingToken = false;
|
|
159
|
+
this.tokenError = null;
|
|
160
|
+
if (!options || typeof options.fetchToken !== 'function') {
|
|
161
|
+
throw new Error('loadHyperswitch requires a fetchToken callback function');
|
|
162
|
+
}
|
|
163
|
+
this.fetchToken = options.fetchToken;
|
|
164
|
+
this.initConfig = options.initConfig ? buildInitConfig(options.initConfig) : null;
|
|
165
|
+
this.initPromise = this.fetchInitialToken();
|
|
166
|
+
this.listenForMessages();
|
|
167
|
+
}
|
|
168
|
+
fetchInitialToken() {
|
|
169
|
+
const eagerTokenPromise = (() => {
|
|
170
|
+
try {
|
|
171
|
+
return this.fetchToken();
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
return Promise.reject(error);
|
|
175
|
+
}
|
|
176
|
+
})();
|
|
177
|
+
return eagerTokenPromise.then((token) => {
|
|
178
|
+
if (token) {
|
|
179
|
+
this.token = token;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
this.tokenError = 'Failed to fetch token: Token returned empty or undefined';
|
|
183
|
+
}
|
|
184
|
+
}).catch((error) => {
|
|
185
|
+
this.tokenError = `Failed to fetch token: ${error instanceof Error ? error.message : String(error)}`;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
listenForMessages() {
|
|
189
|
+
if (!isBrowser) {
|
|
190
|
+
// In SSR / non-browser environments we can't listen for postMessage events,
|
|
191
|
+
// but it's still safe to create a Hyperswitch instance (it will become
|
|
192
|
+
// useful on the client where another instance will typically be created).
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
window.addEventListener("message", async (event) => {
|
|
196
|
+
var _a, _b, _c;
|
|
197
|
+
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) {
|
|
198
|
+
await this.refetchAndBroadcastToken();
|
|
199
|
+
}
|
|
200
|
+
else if (((_c = event.data) === null || _c === void 0 ? void 0 : _c.type) === "EMBEDDED_IFRAME_READY") {
|
|
201
|
+
// Find the element whose iframe matches the event source
|
|
202
|
+
this.activeElements.forEach((element) => {
|
|
203
|
+
const iframe = element.getIframe();
|
|
204
|
+
if ((iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === event.source) {
|
|
205
|
+
this.onElementIframeLoaded(element);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
async refetchAndBroadcastToken() {
|
|
212
|
+
if (this.isRefetchingToken) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.isRefetchingToken = true;
|
|
216
|
+
try {
|
|
217
|
+
const newToken = await this.fetchToken();
|
|
218
|
+
if (newToken) {
|
|
219
|
+
this.token = newToken;
|
|
220
|
+
this.tokenError = null;
|
|
221
|
+
this.activeElements.forEach((element, elementId) => {
|
|
222
|
+
const iframe = element.getIframe();
|
|
223
|
+
if (iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) {
|
|
224
|
+
iframe.contentWindow.postMessage({
|
|
225
|
+
type: 'AUTH_TOKEN',
|
|
226
|
+
token: this.token
|
|
227
|
+
}, '*');
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
this.tokenError = 'Failed to refetch token: Token returned empty or undefined';
|
|
233
|
+
this.sendErrorToActiveElements(this.tokenError);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
this.tokenError = `Failed to refetch token: ${error instanceof Error ? error.message : String(error)}`;
|
|
238
|
+
this.sendErrorToActiveElements(this.tokenError);
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
this.isRefetchingToken = false;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
sendErrorToActiveElements(errorMessage) {
|
|
245
|
+
this.activeElements.forEach((element) => {
|
|
246
|
+
const iframe = element.getIframe();
|
|
247
|
+
if (iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) {
|
|
248
|
+
iframe.contentWindow.postMessage({
|
|
249
|
+
type: 'AUTH_ERROR',
|
|
250
|
+
error: errorMessage
|
|
251
|
+
}, '*');
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
create(type, options) {
|
|
256
|
+
let element;
|
|
257
|
+
switch (type) {
|
|
258
|
+
case 'connectors':
|
|
259
|
+
element = new ConnectorConfigurationComponent(this, options);
|
|
260
|
+
break;
|
|
261
|
+
default:
|
|
262
|
+
throw new Error(`Unknown element type: ${type}`);
|
|
263
|
+
}
|
|
264
|
+
this.activeElements.set(element._internalId, element);
|
|
265
|
+
return element;
|
|
266
|
+
}
|
|
267
|
+
onElementIframeLoaded(element) {
|
|
268
|
+
this.initPromise.then(() => {
|
|
269
|
+
const iframe = element.getIframe();
|
|
270
|
+
if (!(iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow)) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
setTimeout(() => {
|
|
274
|
+
try {
|
|
275
|
+
const contentWindow = iframe.contentWindow;
|
|
276
|
+
if (!contentWindow) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (this.tokenError) {
|
|
280
|
+
contentWindow.postMessage({
|
|
281
|
+
type: 'AUTH_ERROR',
|
|
282
|
+
error: this.tokenError
|
|
283
|
+
}, '*');
|
|
284
|
+
}
|
|
285
|
+
else if (this.token) {
|
|
286
|
+
contentWindow.postMessage({
|
|
287
|
+
type: 'AUTH_TOKEN',
|
|
288
|
+
token: this.token
|
|
289
|
+
}, '*');
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
contentWindow.postMessage({
|
|
293
|
+
type: 'AUTH_ERROR',
|
|
294
|
+
error: 'No token available'
|
|
295
|
+
}, '*');
|
|
296
|
+
}
|
|
297
|
+
// Send init_config (if available) as a separate message
|
|
298
|
+
if (this.initConfig) {
|
|
299
|
+
contentWindow.postMessage({
|
|
300
|
+
type: 'INIT_CONFIG',
|
|
301
|
+
init_config: this.initConfig
|
|
302
|
+
}, '*');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
}
|
|
307
|
+
}, 100);
|
|
308
|
+
}).catch((error) => {
|
|
309
|
+
const iframe = element.getIframe();
|
|
310
|
+
const contentWindow = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow;
|
|
311
|
+
if (contentWindow) {
|
|
312
|
+
setTimeout(() => {
|
|
313
|
+
try {
|
|
314
|
+
contentWindow.postMessage({
|
|
315
|
+
type: 'AUTH_ERROR',
|
|
316
|
+
error: `Token initialization failed: ${error instanceof Error ? error.message : String(error)}`
|
|
317
|
+
}, '*');
|
|
318
|
+
}
|
|
319
|
+
catch (_a) {
|
|
320
|
+
}
|
|
321
|
+
}, 100);
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function loadHyperswitch(options) {
|
|
327
|
+
return new Hyperswitch(options);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const VERSION = '1.0.0';
|
|
331
|
+
|
|
332
|
+
exports.ConnectorConfigurationComponent = ConnectorConfigurationComponent;
|
|
333
|
+
exports.Hyperswitch = Hyperswitch;
|
|
334
|
+
exports.HyperswitchElement = HyperswitchElement;
|
|
335
|
+
exports.VERSION = VERSION;
|
|
336
|
+
exports.loadHyperswitch = loadHyperswitch;
|
|
337
|
+
|
|
338
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
339
|
+
|
|
340
|
+
}));
|
|
341
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.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":";;;;;;EAGA,MAAMA,WAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;EAEhD,MAAe,kBAAkB,CAAA;MAQ/B,WAAY,CAAA,QAAqB,EAAE,OAAwB,EAAA;EACzD,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;EACzB,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;EAC7B,QAAA,IAAI,CAAC,WAAW,GAAG,YAAY,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;EACzE,QAAA,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;;;;UAIhC,IAAI,CAACA,WAAS,EAAE;cACd,OAAO;WACR;UAED,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;UAC7C,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;UAC/C,IAAI,CAAC,mB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A,IAAI;0BACF,aAAa,CAAC,WAAW,CAAC;EACxB,4BAAA,IAAI,EAAE,YAAY;EAClB,4BAAA,KAAK,EAAE,CAAgC,6BAAA,EAAA,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAE,CAAA;2BAChG,EAAE,GAAG,CAAC,CAAC;uBACT;EAAC,oBAAA,OAAA,EAAA,EAAM;uBACP;mBACF,EAAE,GAAG,CAAC,CAAC;eACT;EACH,SAAC,CAAC,CAAC;OACJ;EACF,CAAA;EAEK,SAAU,eAAe,CAAC,OAA+B,EAAA;EAC7D,IAAA,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;EAClC;;AC3LO,QAAM,OAAO,GAAG;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme configuration received from the merchant.
|
|
3
|
+
* This is the ONLY contract we expect merchants to follow.
|
|
4
|
+
*/
|
|
5
|
+
export type MerchantTheme = {
|
|
6
|
+
/** Primary color */
|
|
7
|
+
primaryColor?: string;
|
|
8
|
+
/** Page background color */
|
|
9
|
+
backgroundColor?: string;
|
|
10
|
+
/** Button configurations */
|
|
11
|
+
buttons?: {
|
|
12
|
+
/** Primary button configuration */
|
|
13
|
+
primary?: {
|
|
14
|
+
/** Primary button background color */
|
|
15
|
+
backgroundColor?: string;
|
|
16
|
+
/** Primary button text color */
|
|
17
|
+
textColor?: string;
|
|
18
|
+
/** Primary button hover background color */
|
|
19
|
+
hoverBackgroundColor?: string;
|
|
20
|
+
};
|
|
21
|
+
/** Secondary button configuration */
|
|
22
|
+
secondary?: {
|
|
23
|
+
/** Secondary button background color */
|
|
24
|
+
backgroundColor?: string;
|
|
25
|
+
/** Secondary button text color */
|
|
26
|
+
textColor?: string;
|
|
27
|
+
/** Secondary button hover background color */
|
|
28
|
+
hoverBackgroundColor?: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Full init_config payload shape sent to the Control Center.
|
|
34
|
+
* Most fields are null for now; Control Center applies defaults.
|
|
35
|
+
*/
|
|
36
|
+
export type InitConfig = {
|
|
37
|
+
settings: {
|
|
38
|
+
colors: {
|
|
39
|
+
primary: string | null;
|
|
40
|
+
secondary: string | null;
|
|
41
|
+
background: string | null;
|
|
42
|
+
};
|
|
43
|
+
sidebar: null;
|
|
44
|
+
typography: null;
|
|
45
|
+
buttons: {
|
|
46
|
+
primary: {
|
|
47
|
+
backgroundColor: string | null;
|
|
48
|
+
textColor: string | null;
|
|
49
|
+
hoverBackgroundColor: string | null;
|
|
50
|
+
};
|
|
51
|
+
secondary: {
|
|
52
|
+
backgroundColor: string | null;
|
|
53
|
+
textColor: string | null;
|
|
54
|
+
hoverBackgroundColor: string | null;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
borders: null;
|
|
58
|
+
spacing: null;
|
|
59
|
+
};
|
|
60
|
+
urls: {
|
|
61
|
+
faviconUrl: null;
|
|
62
|
+
logoUrl: null;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Build the init_config object that Control Center expects
|
|
67
|
+
* from the simple MerchantTheme contract.
|
|
68
|
+
*
|
|
69
|
+
* Any missing value is set to null.
|
|
70
|
+
*/
|
|
71
|
+
export declare function buildInitConfig(merchantTheme: MerchantTheme | undefined | null): InitConfig;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MerchantTheme } from './init-config';
|
|
2
|
+
/**
|
|
3
|
+
* Options for initializing the Hyperswitch SDK
|
|
4
|
+
*/
|
|
5
|
+
export interface HyperswitchInitOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Function that fetches token
|
|
8
|
+
* @returns A promise that resolves with a new token.
|
|
9
|
+
*/
|
|
10
|
+
fetchToken: () => Promise<string | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Optional initial configuration (init_config) object
|
|
13
|
+
*/
|
|
14
|
+
initConfig?: MerchantTheme;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for configuring a Hyperswitch element
|
|
18
|
+
*/
|
|
19
|
+
export type ElementOptions = {
|
|
20
|
+
/** Base URL for the embedded component */
|
|
21
|
+
url?: string;
|
|
22
|
+
/** Width of the element container */
|
|
23
|
+
width?: string | number;
|
|
24
|
+
/** Height of the element container */
|
|
25
|
+
height?: string | number;
|
|
26
|
+
/** Custom CSS styles to apply to the element */
|
|
27
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
28
|
+
/** Additional CSS class names */
|
|
29
|
+
className?: string;
|
|
30
|
+
/** Callback for handling messages from the embedded iframe */
|
|
31
|
+
onMessage?: (message: any) => void;
|
|
32
|
+
/** Callback for handling resize events from the embedded component */
|
|
33
|
+
onResize?: (dimensions: {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
}) => void;
|
|
37
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@juspay-tech/hyperswitch-control-center-embed-core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Hyperswitch Control Center Embed - Core Javascript SDK for embedding components",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.esm.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.esm.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rollup -c",
|
|
21
|
+
"type-check": "tsc --noEmit",
|
|
22
|
+
"clean": "rm -rf dist",
|
|
23
|
+
"prepublishOnly": "pnpm run clean && pnpm run build"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"hyperswitch",
|
|
27
|
+
"control-center",
|
|
28
|
+
"embedded",
|
|
29
|
+
"sdk",
|
|
30
|
+
"embed"
|
|
31
|
+
],
|
|
32
|
+
"author": "Juspay Technologies",
|
|
33
|
+
"license": "ISC",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/juspay/hyperswitch-control-center-embedded.git",
|
|
37
|
+
"directory": "core"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/juspay/hyperswitch-control-center-embedded/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/juspay/hyperswitch-control-center-embedded#readme",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
48
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
49
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
50
|
+
"@types/node": "^24.10.0",
|
|
51
|
+
"rollup": "^2.79.2",
|
|
52
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
53
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
54
|
+
"typescript": "^5.9.3"
|
|
55
|
+
}
|
|
56
|
+
}
|