@benji-money/connect-sdk 1.0.7
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/LICENSE +24 -0
- package/README.md +111 -0
- package/dist/connect-sdk.umd.d.ts +14 -0
- package/dist/connect-sdk.umd.global.js +396 -0
- package/dist/connect-sdk.umd.global.js.map +1 -0
- package/dist/index.cjs +464 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +121 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.js +438 -0
- package/dist/index.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Benji Connect SDK License
|
|
2
|
+
|
|
3
|
+
Copyright © 2026 The Benji Group, Inc.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
This SDK is proprietary software provided by Benji Group, Inc. (“Benji”).
|
|
7
|
+
|
|
8
|
+
You are welcome to view, install, and use this SDK for the purpose of
|
|
9
|
+
integrating your application with Benji’s authentication and verification
|
|
10
|
+
services, subject to an active or intended customer relationship with Benji.
|
|
11
|
+
|
|
12
|
+
To keep things clear and fair, the following restrictions apply:
|
|
13
|
+
|
|
14
|
+
You may not:
|
|
15
|
+
- modify, adapt, or create derivative works of the SDK
|
|
16
|
+
- redistribute, sublicense, or publicly host the SDK
|
|
17
|
+
- resell or commercialize the SDK independently of Benji services
|
|
18
|
+
- use the SDK to build or support a competing product or service
|
|
19
|
+
|
|
20
|
+
All rights, title, and interest in the SDK remain with Benji Group, Inc.
|
|
21
|
+
|
|
22
|
+
If you’d like to discuss extended use cases, redistribution rights, or have
|
|
23
|
+
questions about integration, please contact Benji at:
|
|
24
|
+
support@withbenj.com
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Benji Connect Web SDK
|
|
2
|
+
|
|
3
|
+
A JavaScript Github Package SDK for integrating Benji Connect, Benji's authentication and verification services.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# If you're using npm
|
|
9
|
+
npm install @benji-money/connect-sdk
|
|
10
|
+
|
|
11
|
+
# If you're using yarn
|
|
12
|
+
yarn add @benji-money/connect-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### ESM + CJS
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { ConnectSDK } from "@benji-money/connect-sdk";
|
|
21
|
+
|
|
22
|
+
const sdk = new ConnectSDK({
|
|
23
|
+
environment: "production", // or "sandbox" | "development",
|
|
24
|
+
token: "your-connect-token",
|
|
25
|
+
|
|
26
|
+
// token: string, metadata: BenjiConnectOnSuccessMetadata
|
|
27
|
+
onSuccess: (token, metadata) => {
|
|
28
|
+
console.log("✅ Benji Connect onSuccess");
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
// error: Error, error_id: string, metadata: BenjiConnectMetadata
|
|
32
|
+
onError: (error, error_id, metadata) => {
|
|
33
|
+
console.log("🛑 Benji Connect onError");
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// metadata: BenjiConnectOnExitMetadata
|
|
37
|
+
onExit: (metadata) => {
|
|
38
|
+
console.log("🚪 Benji Connect onExit");
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
// type: BenjiConnectEventType, metadata: BenjiConnectMetadata
|
|
42
|
+
onEvent: (type, metadata) => {
|
|
43
|
+
console.log("📨 Benji Connect onEvent \(type)");
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Open the authentication flow UI
|
|
48
|
+
sdk.open();
|
|
49
|
+
```
|
|
50
|
+
Demo example [here](https://github.com/Benji-money/benji-connect-examples/tree/main/web/esm).
|
|
51
|
+
|
|
52
|
+
### UMD (Script Tag)
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
<script src="/path/to/connect-sdk.umd.js"></script>
|
|
56
|
+
<script>
|
|
57
|
+
const sdk = new ConnectSDK({
|
|
58
|
+
environment: "production", // or "sandbox" | "development",
|
|
59
|
+
token: "your-connect-token",
|
|
60
|
+
|
|
61
|
+
onSuccess: (token, metadata) => {
|
|
62
|
+
console.log("✅ Benji Connect onSuccess");
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
onError: (error, error_id, metadata) => {
|
|
66
|
+
console.log("🛑 Benji Connect onError");
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
onExit: (metadata) => {
|
|
70
|
+
console.log("🚪 Benji Connect onExit");
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
onEvent: (type, metadata) => {
|
|
74
|
+
console.log("📨 Benji Connect onEvent", type);
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
sdk.open();
|
|
79
|
+
</script>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Configuration
|
|
83
|
+
|
|
84
|
+
The SDK accepts the following configuration options:
|
|
85
|
+
|
|
86
|
+
- `token` (required): Your API connect token
|
|
87
|
+
- `onSuccess` (optional): Callback function called when connect completed successfully
|
|
88
|
+
- `onError` (optional): Callback function called when error occurs in the connect flow
|
|
89
|
+
- `onExit` (optional): Callback function called when the user exits the connect flow
|
|
90
|
+
- `onEvent` (optional): Callback function for handling various events
|
|
91
|
+
|
|
92
|
+
## Development
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# Install dependencies
|
|
96
|
+
npm install
|
|
97
|
+
|
|
98
|
+
# Build the package
|
|
99
|
+
npm run build
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
License
|
|
105
|
+
|
|
106
|
+
This SDK is proprietary software provided by Benji Money.
|
|
107
|
+
|
|
108
|
+
You are welcome to use it to integrate with Benji services, but modification,
|
|
109
|
+
redistribution, or use outside of Benji’s platform is not permitted.
|
|
110
|
+
|
|
111
|
+
See the [LICENSE](./LICENSE) file for full terms and usage details.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// These are compile-time constants replaced by tsup's `define` option.
|
|
2
|
+
// Declaring them globally prevents TypeScript errors.
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
const __VERSION__: string;
|
|
7
|
+
const __NAMESPACE__: string;
|
|
8
|
+
|
|
9
|
+
// Global browser exposure for UMD builds
|
|
10
|
+
interface Window {
|
|
11
|
+
// SDK main class (UMD builds attach this)
|
|
12
|
+
ConnectSDK?: any;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var ConnectSDK = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __export = (target, all) => {
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/config/production.ts
|
|
10
|
+
var production_exports = {};
|
|
11
|
+
__export(production_exports, {
|
|
12
|
+
endpoints: () => endpoints,
|
|
13
|
+
project_environment: () => project_environment
|
|
14
|
+
});
|
|
15
|
+
var project_environment = "production";
|
|
16
|
+
var endpoints = {
|
|
17
|
+
"benji_connect_auth_url": "https://verifyapp.withbenji.com",
|
|
18
|
+
"benji_connect_auth_service_url": "https://authservice.withbenji.com"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// src/config/sandbox.ts
|
|
22
|
+
var sandbox_exports = {};
|
|
23
|
+
__export(sandbox_exports, {
|
|
24
|
+
endpoints: () => endpoints2,
|
|
25
|
+
project_environment: () => project_environment2
|
|
26
|
+
});
|
|
27
|
+
var project_environment2 = "sandbox";
|
|
28
|
+
var endpoints2 = {
|
|
29
|
+
"benji_connect_auth_url": "https://verifyapp-staging.withbenji.com",
|
|
30
|
+
"benji_connect_auth_service_url": "https://authservice-staging.withbenji.com"
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/config/development.ts
|
|
34
|
+
var development_exports = {};
|
|
35
|
+
__export(development_exports, {
|
|
36
|
+
endpoints: () => endpoints3,
|
|
37
|
+
project_environment: () => project_environment3
|
|
38
|
+
});
|
|
39
|
+
var project_environment3 = "development";
|
|
40
|
+
var endpoints3 = {
|
|
41
|
+
"benji_connect_auth_url": "http://localhost:3000",
|
|
42
|
+
"benji_connect_auth_service_url": "https://authservice-staging.withbenji.com"
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/config/index.ts
|
|
46
|
+
var env = typeof process !== "undefined" ? process.env : {};
|
|
47
|
+
var data = development_exports;
|
|
48
|
+
var Endpoints = getEndpoints();
|
|
49
|
+
var Environment = "development" /* DEVELOPMENT */;
|
|
50
|
+
function configureConfig(environment) {
|
|
51
|
+
if (environment == "production") {
|
|
52
|
+
console.log("[Connect SDK] configuring with environment production");
|
|
53
|
+
data = production_exports;
|
|
54
|
+
} else if (environment == "sandbox") {
|
|
55
|
+
console.log("[Connect SDK] configuring with environment sandbox");
|
|
56
|
+
data = sandbox_exports;
|
|
57
|
+
} else if (environment == "development") {
|
|
58
|
+
console.log("[Connect SDK] configuring with environment development");
|
|
59
|
+
data = development_exports;
|
|
60
|
+
}
|
|
61
|
+
Endpoints = getEndpoints();
|
|
62
|
+
Environment = getEnvironment();
|
|
63
|
+
}
|
|
64
|
+
function getEndpoints() {
|
|
65
|
+
const entries = Object.entries(data.endpoints).map(([key, value]) => {
|
|
66
|
+
const override = (env == null ? void 0 : env[key]) || value;
|
|
67
|
+
return [key, override];
|
|
68
|
+
});
|
|
69
|
+
return Object.fromEntries(entries);
|
|
70
|
+
}
|
|
71
|
+
function getEnvironment() {
|
|
72
|
+
return data["project_environment"];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/utils/config.ts
|
|
76
|
+
var buildContext = () => ({
|
|
77
|
+
namespace: "benji-connect-sdk" ? "benji-connect-sdk" : "benji-connect-sdk",
|
|
78
|
+
version: "1.0.7" ? String("1.0.7") : "0.0.0"
|
|
79
|
+
});
|
|
80
|
+
function isBenjiConnectEnvironment(environment) {
|
|
81
|
+
return environment === "development" /* DEVELOPMENT */ || environment === "sandbox" /* SANDBOX */ || environment === "production" /* PRODUCTION */;
|
|
82
|
+
}
|
|
83
|
+
function mapToConnectEnvironment(environment) {
|
|
84
|
+
if (isBenjiConnectEnvironment(environment)) return environment;
|
|
85
|
+
const environments = {
|
|
86
|
+
development: "development" /* DEVELOPMENT */,
|
|
87
|
+
sandbox: "sandbox" /* SANDBOX */,
|
|
88
|
+
production: "production" /* PRODUCTION */
|
|
89
|
+
};
|
|
90
|
+
const mapped = environments[environment];
|
|
91
|
+
if (mapped) return mapped;
|
|
92
|
+
const defaultEnvironment = "development" /* DEVELOPMENT */;
|
|
93
|
+
console.warn(`[Benji Connect SDK] ${environment} not valid environment defaulting to ${defaultEnvironment}`);
|
|
94
|
+
return defaultEnvironment;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/utils/auth.ts
|
|
98
|
+
var extractAccessToken = (token) => {
|
|
99
|
+
var _a;
|
|
100
|
+
return typeof token === "string" ? token : (_a = token == null ? void 0 : token.access_token) != null ? _a : "";
|
|
101
|
+
};
|
|
102
|
+
var mapEventToConnectToken = (data2) => {
|
|
103
|
+
var _a, _b, _c;
|
|
104
|
+
return {
|
|
105
|
+
access_token: (_a = data2 == null ? void 0 : data2.access_token) != null ? _a : "",
|
|
106
|
+
refresh_token: (_b = data2 == null ? void 0 : data2.refresh_token) != null ? _b : "",
|
|
107
|
+
expires_at: (_c = data2 == null ? void 0 : data2.expires_at) != null ? _c : ""
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// src/utils/user.ts
|
|
112
|
+
var mapEventToConnectUserData = (data2) => {
|
|
113
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
114
|
+
return {
|
|
115
|
+
user: {
|
|
116
|
+
id: (_b = (_a = data2 == null ? void 0 : data2.user) == null ? void 0 : _a.id) != null ? _b : 0,
|
|
117
|
+
first_name: (_d = (_c = data2 == null ? void 0 : data2.user) == null ? void 0 : _c.first_name) != null ? _d : "",
|
|
118
|
+
last_name: (_f = (_e = data2 == null ? void 0 : data2.user) == null ? void 0 : _e.last_name) != null ? _f : ""
|
|
119
|
+
},
|
|
120
|
+
status: {
|
|
121
|
+
status_id: (_h = (_g = data2 == null ? void 0 : data2.status) == null ? void 0 : _g.status_id) != null ? _h : "",
|
|
122
|
+
num_of_rewards: (_j = (_i = data2 == null ? void 0 : data2.status) == null ? void 0 : _i.num_of_rewards) != null ? _j : 0,
|
|
123
|
+
reward_status: (_l = (_k = data2 == null ? void 0 : data2.status) == null ? void 0 : _k.reward_status) != null ? _l : "",
|
|
124
|
+
partner_status_tier_id: (_m = data2 == null ? void 0 : data2.status) == null ? void 0 : _m.partner_status_tier_id
|
|
125
|
+
},
|
|
126
|
+
extra_data: {
|
|
127
|
+
total_rewards_earned: (_n = data2 == null ? void 0 : data2.extra_data) == null ? void 0 : _n.total_rewards_earned,
|
|
128
|
+
total_rewards_redeemed: (_o = data2 == null ? void 0 : data2.extra_data) == null ? void 0 : _o.total_rewards_redeemed,
|
|
129
|
+
created_date: (_p = data2 == null ? void 0 : data2.extra_data) == null ? void 0 : _p.created_date
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/utils/transaction.ts
|
|
135
|
+
var mapEventToConnectTransactionData = (data2) => {
|
|
136
|
+
if (!data2) return null;
|
|
137
|
+
return {
|
|
138
|
+
action: data2.action,
|
|
139
|
+
amount: data2.amount,
|
|
140
|
+
trigger_event_id: data2.trigger_event_id,
|
|
141
|
+
trigger_name: data2.trigger_name
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/types/router.ts
|
|
146
|
+
var mapToAuthSuccessData = (message, data2) => {
|
|
147
|
+
return {
|
|
148
|
+
type: message.type,
|
|
149
|
+
metadata: {
|
|
150
|
+
context: buildContext(),
|
|
151
|
+
action: data2.action,
|
|
152
|
+
token: mapEventToConnectToken(data2.token),
|
|
153
|
+
transactionData: mapEventToConnectTransactionData(data2.transaction),
|
|
154
|
+
userData: mapEventToConnectUserData(data2.metadata)
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
var mapToOnExitData = (data2) => {
|
|
159
|
+
return {
|
|
160
|
+
metadata: {
|
|
161
|
+
context: buildContext(),
|
|
162
|
+
step: data2.step,
|
|
163
|
+
trigger: data2.trigger
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
var mapToOnSuccessData = (data2) => {
|
|
168
|
+
const token = extractAccessToken(data2.token);
|
|
169
|
+
let metadata = {
|
|
170
|
+
context: buildContext(),
|
|
171
|
+
action: data2.action,
|
|
172
|
+
user_data: data2.metadata
|
|
173
|
+
};
|
|
174
|
+
if (data2.transaction) {
|
|
175
|
+
metadata.transaction_data = data2.transaction;
|
|
176
|
+
}
|
|
177
|
+
return { token, metadata };
|
|
178
|
+
};
|
|
179
|
+
var mapToOnErrorData = (data2) => {
|
|
180
|
+
return {
|
|
181
|
+
error: data2.error,
|
|
182
|
+
error_id: "500",
|
|
183
|
+
// Placeholder
|
|
184
|
+
metadata: {
|
|
185
|
+
context: buildContext()
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
var mapToOnEventData = (message, data2) => {
|
|
190
|
+
return {
|
|
191
|
+
type: message.type,
|
|
192
|
+
metadata: {
|
|
193
|
+
context: buildContext(),
|
|
194
|
+
...data2
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
var BenjiConnectCallbackMapperMap = {
|
|
199
|
+
["AUTH_SUCCESS" /* AUTH_SUCCESS */]: mapToAuthSuccessData,
|
|
200
|
+
["FLOW_EXIT" /* FLOW_EXIT */]: mapToOnExitData,
|
|
201
|
+
["FLOW_SUCCESS" /* FLOW_SUCCESS */]: mapToOnSuccessData,
|
|
202
|
+
["ERROR" /* ERROR */]: mapToOnErrorData,
|
|
203
|
+
["EVENT" /* EVENT */]: mapToOnEventData
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// src/router/message.ts
|
|
207
|
+
var _MessageRouter = class _MessageRouter {
|
|
208
|
+
static configureMessageRouter(config) {
|
|
209
|
+
this.onSuccess = config.onSuccess;
|
|
210
|
+
this.onError = config.onError;
|
|
211
|
+
this.onExit = config.onExit;
|
|
212
|
+
this.onEvent = config.onEvent;
|
|
213
|
+
this.close = config.close;
|
|
214
|
+
}
|
|
215
|
+
static addEventListeners() {
|
|
216
|
+
if (this.configuredListeners) return;
|
|
217
|
+
window.addEventListener("error", this.errorEventHandler);
|
|
218
|
+
window.addEventListener("unhandledrejection", this.errorEventHandler);
|
|
219
|
+
window.addEventListener("message", this.messageEventHandler);
|
|
220
|
+
this.configuredListeners = true;
|
|
221
|
+
}
|
|
222
|
+
static removeEventListeners() {
|
|
223
|
+
window.removeEventListener("error", this.errorEventHandler);
|
|
224
|
+
window.removeEventListener("unhandledrejection", this.errorEventHandler);
|
|
225
|
+
window.removeEventListener("message", this.messageEventHandler);
|
|
226
|
+
this.configuredListeners = false;
|
|
227
|
+
}
|
|
228
|
+
static handleErrorMessage(event) {
|
|
229
|
+
switch (event.type) {
|
|
230
|
+
case "error": {
|
|
231
|
+
const errorEvent = event;
|
|
232
|
+
const error = errorEvent.error || new Error(errorEvent.message);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
case "unhandledrejection": {
|
|
236
|
+
const rejectionEvent = event;
|
|
237
|
+
const reason = rejectionEvent.reason instanceof Error ? rejectionEvent.reason : new Error(String(rejectionEvent.reason));
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
default: {
|
|
241
|
+
console.error("[Benji Connect SDK] Received Unknown error message", event);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
static handleMessage(event) {
|
|
247
|
+
var _a, _b, _c, _d, _e, _f;
|
|
248
|
+
console.debug("[Benji Connect SDK] Received message", event);
|
|
249
|
+
const expectedOrigin = new URL(Endpoints.benji_connect_auth_url).origin;
|
|
250
|
+
if (!event || event.origin !== expectedOrigin) {
|
|
251
|
+
console.warn("[Benji Connect SDK] Skipped message, received event from unexpected origin", event.origin, expectedOrigin);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const raw = event.data;
|
|
255
|
+
if (!raw || typeof raw !== "object") return;
|
|
256
|
+
const partial = raw;
|
|
257
|
+
if (typeof partial.type !== "string") return;
|
|
258
|
+
const message = partial;
|
|
259
|
+
try {
|
|
260
|
+
switch (message.type) {
|
|
261
|
+
case "AUTH_SUCCESS" /* AUTH_SUCCESS */: {
|
|
262
|
+
const connectMessage = message;
|
|
263
|
+
const callbackData = BenjiConnectCallbackMapperMap.AUTH_SUCCESS(connectMessage, connectMessage.data);
|
|
264
|
+
(_a = this.onEvent) == null ? void 0 : _a.call(this, callbackData.type, callbackData.metadata);
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
case "FLOW_EXIT" /* FLOW_EXIT */: {
|
|
268
|
+
const connectMessage = message;
|
|
269
|
+
const callbackData = BenjiConnectCallbackMapperMap.FLOW_EXIT(connectMessage.data);
|
|
270
|
+
(_b = this.onExit) == null ? void 0 : _b.call(this, callbackData.metadata);
|
|
271
|
+
(_c = this.close) == null ? void 0 : _c.call(this);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case "FLOW_SUCCESS" /* FLOW_SUCCESS */: {
|
|
275
|
+
const connectMessage = message;
|
|
276
|
+
const callbackData = BenjiConnectCallbackMapperMap.FLOW_SUCCESS(connectMessage.data);
|
|
277
|
+
(_d = this.onSuccess) == null ? void 0 : _d.call(this, callbackData.token, callbackData.metadata);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
case "ERROR" /* ERROR */: {
|
|
281
|
+
const connectMessage = message;
|
|
282
|
+
const callbackData = BenjiConnectCallbackMapperMap.ERROR(connectMessage.data);
|
|
283
|
+
(_e = this.onError) == null ? void 0 : _e.call(this, callbackData.error, callbackData.error_id, callbackData.metadata);
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
default: {
|
|
287
|
+
const m = message;
|
|
288
|
+
const callbackData = mapToOnEventData(m, m.data);
|
|
289
|
+
(_f = this.onEvent) == null ? void 0 : _f.call(this, callbackData.type, callbackData.metadata);
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
} finally {
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
_MessageRouter.configuredListeners = false;
|
|
298
|
+
_MessageRouter.errorEventHandler = (event) => {
|
|
299
|
+
return _MessageRouter.handleErrorMessage(event);
|
|
300
|
+
};
|
|
301
|
+
_MessageRouter.messageEventHandler = (event) => {
|
|
302
|
+
return _MessageRouter.handleMessage(event);
|
|
303
|
+
};
|
|
304
|
+
var MessageRouter = _MessageRouter;
|
|
305
|
+
|
|
306
|
+
// src/connect-sdk.ts
|
|
307
|
+
var ConnectSDK = class {
|
|
308
|
+
constructor(config) {
|
|
309
|
+
this.iframe = null;
|
|
310
|
+
this.container = null;
|
|
311
|
+
this.sdkConfig = config;
|
|
312
|
+
if (!this.sdkConfig.environment) throw new Error("Environment is required");
|
|
313
|
+
if (!this.sdkConfig.token) throw new Error("Connect token is required");
|
|
314
|
+
const environment = mapToConnectEnvironment(this.sdkConfig.environment);
|
|
315
|
+
this.sdkConfig.environment = environment;
|
|
316
|
+
configureConfig(environment);
|
|
317
|
+
}
|
|
318
|
+
async initialize() {
|
|
319
|
+
MessageRouter.configureMessageRouter({
|
|
320
|
+
onSuccess: this.sdkConfig.onSuccess,
|
|
321
|
+
onError: this.sdkConfig.onError,
|
|
322
|
+
onExit: this.sdkConfig.onExit,
|
|
323
|
+
onEvent: this.sdkConfig.onEvent,
|
|
324
|
+
close: () => this.close()
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
async open() {
|
|
328
|
+
await this.initialize();
|
|
329
|
+
this.openUI();
|
|
330
|
+
MessageRouter.addEventListeners();
|
|
331
|
+
}
|
|
332
|
+
openUI() {
|
|
333
|
+
if (this.iframe) return;
|
|
334
|
+
this.container = document.createElement("div");
|
|
335
|
+
Object.assign(this.container.style, {
|
|
336
|
+
position: "fixed",
|
|
337
|
+
top: "0",
|
|
338
|
+
left: "0",
|
|
339
|
+
width: "100%",
|
|
340
|
+
height: "100%",
|
|
341
|
+
backgroundColor: "rgba(0,0,0,0.5)",
|
|
342
|
+
zIndex: "9999",
|
|
343
|
+
display: "flex",
|
|
344
|
+
alignItems: "center",
|
|
345
|
+
justifyContent: "center",
|
|
346
|
+
overflow: "auto"
|
|
347
|
+
});
|
|
348
|
+
console.debug("[Connect SDK] endpoints", Endpoints);
|
|
349
|
+
console.log("[Connect SDK] opeining URL", Endpoints.benji_connect_auth_url);
|
|
350
|
+
const url = new URL(Endpoints.benji_connect_auth_url);
|
|
351
|
+
const connectToken = this.sdkConfig.token;
|
|
352
|
+
url.searchParams.set("connect_token", connectToken);
|
|
353
|
+
url.searchParams.set("t", String(Date.now()));
|
|
354
|
+
this.iframe = document.createElement("iframe");
|
|
355
|
+
Object.assign(this.iframe.style, {
|
|
356
|
+
position: "relative",
|
|
357
|
+
width: "400px",
|
|
358
|
+
height: "645px",
|
|
359
|
+
border: "none",
|
|
360
|
+
borderRadius: "20px",
|
|
361
|
+
overflow: "hidden"
|
|
362
|
+
});
|
|
363
|
+
this.iframe.src = url.toString();
|
|
364
|
+
this.container.appendChild(this.iframe);
|
|
365
|
+
document.body.appendChild(this.container);
|
|
366
|
+
this.container.addEventListener("click", (e) => {
|
|
367
|
+
var _a, _b;
|
|
368
|
+
if (e.target === this.container) {
|
|
369
|
+
(_b = (_a = this.sdkConfig).onExit) == null ? void 0 : _b.call(_a, {
|
|
370
|
+
context: buildContext(),
|
|
371
|
+
trigger: "TAPPED_OUT_OF_BOUNDS" /* TAPPED_OUT_OF_BOUNDS */
|
|
372
|
+
});
|
|
373
|
+
this.close();
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
close() {
|
|
378
|
+
if (!this.iframe) return;
|
|
379
|
+
document.body.removeChild(this.container);
|
|
380
|
+
MessageRouter.removeEventListeners();
|
|
381
|
+
this.iframe = null;
|
|
382
|
+
this.container = null;
|
|
383
|
+
}
|
|
384
|
+
cleanup() {
|
|
385
|
+
if (this.iframe) this.close();
|
|
386
|
+
}
|
|
387
|
+
ping() {
|
|
388
|
+
return "pong";
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
var connect_sdk_default = ConnectSDK;
|
|
392
|
+
|
|
393
|
+
// src/global.ts
|
|
394
|
+
globalThis.ConnectSDK = connect_sdk_default;
|
|
395
|
+
})();
|
|
396
|
+
//# sourceMappingURL=connect-sdk.umd.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config/production.ts","../src/config/sandbox.ts","../src/config/development.ts","../src/config/index.ts","../src/utils/config.ts","../src/utils/auth.ts","../src/utils/user.ts","../src/utils/transaction.ts","../src/types/router.ts","../src/router/message.ts","../src/connect-sdk.ts","../src/global.ts"],"sourcesContent":["export const project_environment: string = 'production';\n\nexport const endpoints: Record<string, string> = {\n 'benji_connect_auth_url':'https://verifyapp.withbenji.com',\n 'benji_connect_auth_service_url' : 'https://authservice.withbenji.com'\n}","export const project_environment: string = 'sandbox';\n\nexport const endpoints: Record<string, string> = {\n 'benji_connect_auth_url':'https://verifyapp-staging.withbenji.com',\n 'benji_connect_auth_service_url' : 'https://authservice-staging.withbenji.com'\n}","export const project_environment: string = 'development';\n\nexport const endpoints: Record<string, string> = {\n 'benji_connect_auth_url':'http://localhost:3000',\n 'benji_connect_auth_service_url' : 'https://authservice-staging.withbenji.com'\n}","import * as productionConfig from './production';\nimport * as sandboxConfig from './sandbox';\nimport * as developmentConfig from './development';\nimport { BenjiConnectEnvironment } from '../types/config';\n\n// Defaults to dev\nconst env = (typeof process !== 'undefined' ? process.env : {});\nlet data = developmentConfig;\n// Derive endpoint type from dev config\ntype EndpointConfig = typeof developmentConfig.endpoints;\nexport let Endpoints: EndpointConfig = getEndpoints();\nexport let Environment = BenjiConnectEnvironment.DEVELOPMENT;\n\n// Configure with environment at runtime \nexport function configureConfig(environment: BenjiConnectEnvironment) {\n if (environment == 'production') {\n console.log('[Connect SDK] configuring with environment production');\n data = productionConfig;\n } else if (environment == 'sandbox') {\n console.log('[Connect SDK] configuring with environment sandbox');\n data = sandboxConfig;\n } else if (environment == 'development') {\n console.log('[Connect SDK] configuring with environment development');\n data = developmentConfig;\n }\n Endpoints = getEndpoints();\n Environment = getEnvironment();\n}\n\nfunction getEndpoints(): EndpointConfig {\n const entries = Object.entries(data.endpoints).map(([key, value]) => {\n const override = env?.[key] || value;\n return [key, override] as const;\n });\n return Object.fromEntries(entries) as EndpointConfig;\n}\n\nfunction getEnvironment(): BenjiConnectEnvironment {\n return data['project_environment'] as BenjiConnectEnvironment;\n}\n\nexport const Namespace = __NAMESPACE__;\nexport const Version = __VERSION__;\n\n","import { BenjiConnectEnvironment } from \"../types/config\";\n\nexport const buildContext = () => ({\n namespace: typeof __NAMESPACE__ !== 'undefined' && __NAMESPACE__ ? __NAMESPACE__ : 'benji-connect-sdk',\n version: typeof __VERSION__ !== 'undefined' && __VERSION__ ? String(__VERSION__) : '0.0.0',\n});\n\nexport function isBenjiConnectEnvironment(\n environment: unknown\n): environment is BenjiConnectEnvironment {\n return (\n environment === BenjiConnectEnvironment.DEVELOPMENT ||\n environment === BenjiConnectEnvironment.SANDBOX ||\n environment === BenjiConnectEnvironment.PRODUCTION\n );\n}\n\nexport function mapToConnectEnvironment(\n environment: BenjiConnectEnvironment | string\n): BenjiConnectEnvironment {\n\n if (isBenjiConnectEnvironment(environment)) return environment;\n\n const environments: Record<string, BenjiConnectEnvironment> = {\n development: BenjiConnectEnvironment.DEVELOPMENT,\n sandbox: BenjiConnectEnvironment.SANDBOX,\n production: BenjiConnectEnvironment.PRODUCTION\n };\n const mapped = environments[environment];\n if (mapped) return mapped;\n\n const defaultEnvironment = BenjiConnectEnvironment.DEVELOPMENT;\n console.warn(`[Benji Connect SDK] ${environment} not valid environment defaulting to ${defaultEnvironment}`);\n\n return defaultEnvironment;\n}","import { BenjiConnectAuthToken } from \"../types/auth\";\nimport { BenjiConnectEventToken } from \"../types/event\";\n\nexport const extractAccessToken = (token?: BenjiConnectEventToken | string): string =>\n typeof token === 'string' ? token : (token?.access_token ?? '');\n\nexport const mapEventToConnectToken = (data?: BenjiConnectEventToken): BenjiConnectAuthToken => ({\n access_token: data?.access_token ?? '',\n refresh_token: data?.refresh_token ?? '',\n expires_at: data?.expires_at ?? ''\n});","import { BenjiConnectEventUserData } from \"../types/event\";\nimport { BenjiConnectUserData } from \"../types/user\";\n\nexport function isConnectUserData (\n input: BenjiConnectUserData | Record<string, any>\n): boolean {\n if (!input) return false;\n const data = mapEventToConnectUserData(input);\n if (data.user.id != 0) return true;\n return false;\n}\n\nexport const mapEventToConnectUserData = (\n data?: BenjiConnectEventUserData | Record<string, any>\n): BenjiConnectUserData => ({\n user: {\n id: data?.user?.id ?? 0,\n first_name: data?.user?.first_name ?? '',\n last_name: data?.user?.last_name ?? ''\n },\n status: {\n status_id: data?.status?.status_id ?? '',\n num_of_rewards: data?.status?.num_of_rewards ?? 0,\n reward_status: data?.status?.reward_status ?? '',\n partner_status_tier_id: data?.status?.partner_status_tier_id\n },\n extra_data: {\n total_rewards_earned: data?.extra_data?.total_rewards_earned,\n total_rewards_redeemed: data?.extra_data?.total_rewards_redeemed,\n created_date: data?.extra_data?.created_date\n }\n});\n","import { BenjiConnectEventTransactionData } from \"../types/event\";\nimport { BenjiConnectTransactionData } from \"../types/transaction\";\n\nexport const mapEventToConnectTransactionData = (data?: BenjiConnectEventTransactionData): BenjiConnectTransactionData | null => {\n if (!data) return null;\n return {\n action: data.action,\n amount: data.amount,\n trigger_event_id: data.trigger_event_id,\n trigger_name: data.trigger_name\n };\n}","import { \n BenjiConnectMetadata, \n BenjiConnectOnErrorData, \n BenjiConnectOnEventData, \n BenjiConnectOnExitData, \n BenjiConnectOnExitMetadata, \n BenjiConnectOnSuccessData, \n BenjiConnectOnSuccessMetadata \n} from './config';\n\nimport { \n extractAccessToken, \n mapEventToConnectToken \n} from '../utils/auth';\n\nimport { buildContext } from '../utils/config';\nimport { mapEventToConnectUserData } from '../utils/user';\n\nimport { \n BenjiConnectAuthSuccessEventData,\n BenjiConnectErrorEventData, \n BenjiConnectEventDataMap, \n BenjiConnectEventMessage, \n BenjiConnectEventType, \n BenjiConnectFlowExitEventData\n} from './event';\nimport { mapEventToConnectTransactionData } from '../utils/transaction';\n\nexport type MessageRouterConfig = {\n onSuccess?: (\n token: string, \n metadata: BenjiConnectOnSuccessMetadata\n ) => void;\n onError?: (\n error: Error,\n error_id: string,\n metadata: BenjiConnectMetadata\n ) => void;\n onExit?: (\n metadata: BenjiConnectOnExitMetadata\n ) => void;\n onEvent?: (\n type: BenjiConnectEventType, \n metadata: BenjiConnectMetadata\n ) => void;\n close?: () => void;\n};\n\nexport const mapToAuthSuccessData = (\n message: BenjiConnectEventMessage<BenjiConnectEventType.AUTH_SUCCESS>,\n data: BenjiConnectAuthSuccessEventData\n): BenjiConnectOnEventData => {\n return {\n type: message.type,\n metadata: {\n context: buildContext(),\n action: data.action,\n token: mapEventToConnectToken(data.token),\n transactionData: mapEventToConnectTransactionData(data.transaction),\n userData: mapEventToConnectUserData(data.metadata)\n }\n };\n};\n\nexport const mapToOnExitData = (data: BenjiConnectFlowExitEventData): BenjiConnectOnExitData => {\n return {\n metadata: {\n context: buildContext(),\n step: data.step,\n trigger: data.trigger\n }\n };\n};\n\nexport const mapToOnSuccessData = (data: BenjiConnectAuthSuccessEventData): BenjiConnectOnSuccessData => {\n \n const token = extractAccessToken(data.token);\n\n let metadata: BenjiConnectOnSuccessMetadata = {\n context: buildContext(),\n action: data.action,\n user_data: data.metadata\n };\n\n if (data.transaction) {\n metadata.transaction_data = data.transaction;\n }\n \n return { token, metadata };\n};\n\nexport const mapToOnErrorData = (data: BenjiConnectErrorEventData): BenjiConnectOnErrorData => {\n return {\n error: data.error,\n error_id: '500', // Placeholder\n metadata: {\n context: buildContext()\n }\n };\n};\n\nexport const mapToOnEventData = <K extends BenjiConnectEventType>(\n message: BenjiConnectEventMessage<K>,\n data: BenjiConnectEventDataMap[K]\n): BenjiConnectOnEventData => {\n return {\n type: message.type,\n metadata: {\n context: buildContext(),\n ...data\n }\n };\n};\n\nexport type BenjiConnectCallbackDataMap = {\n [BenjiConnectEventType.AUTH_SUCCESS]: BenjiConnectOnEventData;\n [BenjiConnectEventType.FLOW_EXIT]: BenjiConnectOnExitData;\n [BenjiConnectEventType.FLOW_SUCCESS]: BenjiConnectOnSuccessData;\n [BenjiConnectEventType.ERROR]: BenjiConnectOnErrorData;\n [BenjiConnectEventType.EVENT]: BenjiConnectOnEventData;\n '*': BenjiConnectOnEventData;\n};\n\nexport const BenjiConnectCallbackMapperMap = {\n [BenjiConnectEventType.AUTH_SUCCESS]: mapToAuthSuccessData,\n [BenjiConnectEventType.FLOW_EXIT]: mapToOnExitData,\n [BenjiConnectEventType.FLOW_SUCCESS]: mapToOnSuccessData,\n [BenjiConnectEventType.ERROR]: mapToOnErrorData,\n [BenjiConnectEventType.EVENT]: mapToOnEventData,\n} as const;\n\n","import { \n Endpoints\n} from '../config';\n\nimport {\n BenjiConnectEventType,\n type BenjiConnectEventData,\n type BenjiConnectEventMessage\n} from '../types/event';\n\nimport type {\n BenjiConnectOnSuccessData,\n BenjiConnectOnExitData,\n BenjiConnectMetadata,\n BenjiConnectOnSuccessMetadata,\n BenjiConnectOnExitMetadata\n} from '../types/config';\n\nimport {\n BenjiConnectCallbackMapperMap,\n MessageRouterConfig,\n mapToOnEventData\n} from '../types/router';\n\nexport class MessageRouter {\n\n static configuredListeners = false;\n static onSuccess?: (\n token: string, \n metadata: BenjiConnectOnSuccessMetadata\n ) => void;\n static onError?: (\n error: Error,\n error_id: string,\n metadata: BenjiConnectMetadata\n ) => void;\n static onExit?: (\n metadata: BenjiConnectOnExitMetadata\n ) => void;\n static onEvent?: (\n type: BenjiConnectEventType, \n metadata: BenjiConnectMetadata\n ) => void;\n static close?: () => void;\n\n static configureMessageRouter(config: MessageRouterConfig) {\n this.onSuccess = config.onSuccess;\n this.onError = config.onError;\n this.onExit = config.onExit;\n this.onEvent = config.onEvent;\n this.close = config.close;\n }\n\n static errorEventHandler = (event: Event) => { \n return MessageRouter.handleErrorMessage(event) \n };\n\n static messageEventHandler = (event: MessageEvent<unknown>) => { \n return MessageRouter.handleMessage(event) \n };\n\n static addEventListeners() {\n if (this.configuredListeners) return;\n window.addEventListener('error', this.errorEventHandler);\n window.addEventListener('unhandledrejection', this.errorEventHandler);\n window.addEventListener('message', this.messageEventHandler);\n this.configuredListeners = true;\n\n // Test uncaught error handling\n // Promise.reject(new Error('[Benji Connect SDK] MessageRouter Test rejection'));\n // throw new Error('[Benji Connect SDK] MessageRouter Test error');\n }\n\n static removeEventListeners() {\n window.removeEventListener('error', this.errorEventHandler);\n window.removeEventListener('unhandledrejection', this.errorEventHandler);\n window.removeEventListener('message', this.messageEventHandler);\n this.configuredListeners = false;\n }\n\n static handleErrorMessage(event: Event) { \n switch(event.type) {\n case 'error': {\n const errorEvent = event as ErrorEvent;\n const error = errorEvent.error || new Error(errorEvent.message);\n // TODO: Track error\n break;\n }\n case 'unhandledrejection': {\n const rejectionEvent = event as PromiseRejectionEvent;\n const reason = rejectionEvent.reason instanceof Error\n ? rejectionEvent.reason\n : new Error(String(rejectionEvent.reason));\n // TODO: Track error (reason)\n break;\n }\n default: {\n console.error('[Benji Connect SDK] Received Unknown error message', event);\n break;\n }\n }\n }\n\n static handleMessage(event: MessageEvent<unknown>) {\n\n console.debug('[Benji Connect SDK] Received message', event);\n \n // Basic origin check\n const expectedOrigin: string = new URL(Endpoints.benji_connect_auth_url).origin;\n if (!event || event.origin !== expectedOrigin) {\n console.warn('[Benji Connect SDK] Skipped message, received event from unexpected origin', event.origin, expectedOrigin);\n return;\n }\n\n const raw = event.data;\n if (!raw || typeof raw !== 'object') return;\n\n const partial = raw as Partial<BenjiConnectEventMessage>;\n if (typeof partial.type !== 'string') return;\n \n const message = partial as BenjiConnectEventMessage;\n\n // TODO: Proper Constraint checks\n // if (Namespace && message.namespace && message.namespace !== Namespace) return;\n // if (Version != null && message.version != null && String(message.version) !== String(Version)) return;\n\n // TODO: Track message received either here or below but not both\n \n try {\n // Type events and route to callbacks\n switch (message.type) {\n\n case BenjiConnectEventType.AUTH_SUCCESS: {\n const connectMessage = message as BenjiConnectEventMessage<BenjiConnectEventType.AUTH_SUCCESS>;\n const callbackData = BenjiConnectCallbackMapperMap.AUTH_SUCCESS(connectMessage, connectMessage.data);\n // TODO: Track message received?\n this.onEvent?.(callbackData.type, callbackData.metadata); \n break;\n }\n\n case BenjiConnectEventType.FLOW_EXIT: {\n const connectMessage = message as BenjiConnectEventMessage<BenjiConnectEventType.FLOW_EXIT>;\n const callbackData = BenjiConnectCallbackMapperMap.FLOW_EXIT(connectMessage.data) as BenjiConnectOnExitData;\n // TODO: Track message received?\n this.onExit?.(callbackData.metadata);\n this.close?.();\n break;\n }\n\n case BenjiConnectEventType.FLOW_SUCCESS: {\n const connectMessage = message as BenjiConnectEventMessage<BenjiConnectEventType.FLOW_SUCCESS>;\n // TODO: Track message received?\n // Forward onSuccess when flow completes for connect, redeem and transfer \n const callbackData = BenjiConnectCallbackMapperMap.FLOW_SUCCESS(connectMessage.data) as BenjiConnectOnSuccessData;\n this.onSuccess?.(callbackData.token, callbackData.metadata); \n break;\n }\n\n case BenjiConnectEventType.ERROR: {\n const connectMessage = message as BenjiConnectEventMessage<BenjiConnectEventType.ERROR>;\n // TODO: Track message received?\n const callbackData = BenjiConnectCallbackMapperMap.ERROR(connectMessage.data);\n this.onError?.(callbackData.error, callbackData.error_id, callbackData.metadata);\n break;\n }\n\n default: {\n // Unknown event type (forward generically)\n const m = message as BenjiConnectEventMessage<any>;\n // TODO: Track message received?\n const callbackData = mapToOnEventData(m, m.data as BenjiConnectEventData);\n this.onEvent?.(callbackData.type, callbackData.metadata);\n break;\n }\n }\n } finally {\n // TODO: Any cleanup logic \n }\n }\n\n}","/// <reference path=\"./global.d.ts\" />\n\nimport { \n configureConfig, \n Endpoints\n} from './config';\n\nimport { \n type BenjiConnectConfig, \n BenjiConnectEnvironment\n} from './types/config';\n\nimport { \n buildContext, \n mapToConnectEnvironment \n} from './utils/config';\n\nimport { MessageRouter } from './router/message';\nimport { BenjiConnectExitTrigger } from './types/event';\n\nclass ConnectSDK {\n\n private sdkConfig: BenjiConnectConfig;\n private iframe: HTMLIFrameElement | null = null;\n private container: HTMLDivElement | null = null;\n\n constructor(config: BenjiConnectConfig) {\n\n this.sdkConfig = config;\n\n // Validations\n if (!this.sdkConfig.environment) throw new Error('Environment is required');\n if (!this.sdkConfig.token) throw new Error('Connect token is required');\n\n // Set internal config for environment based on consumer input at runtime\n const environment: BenjiConnectEnvironment = mapToConnectEnvironment(this.sdkConfig.environment);\n this.sdkConfig.environment = environment;\n configureConfig(environment);\n }\n\n async initialize() {\n \n // Configure message router for all postMessage from connect modal and error messages\n MessageRouter.configureMessageRouter({\n onSuccess: this.sdkConfig.onSuccess,\n onError: this.sdkConfig.onError,\n onExit: this.sdkConfig.onExit,\n onEvent: this.sdkConfig.onEvent,\n close: () => this.close()\n });\n\n // TODO: Tracker.configureWithOptions(sdkOptions);\n // TODO: Tracker.trackSDKInitialized();\n }\n\n async open() {\n await this.initialize();\n this.openUI();\n MessageRouter.addEventListeners();\n // TODO: Track SDK Opened Tracker.trackSDKOpened();\n }\n\n openUI() {\n if (this.iframe) return;\n\n // container\n this.container = document.createElement('div');\n Object.assign(this.container.style, {\n position: 'fixed', \n top: '0', \n left: '0', \n width: '100%', \n height: '100%',\n backgroundColor: 'rgba(0,0,0,0.5)', \n zIndex: '9999', \n display: 'flex',\n alignItems: 'center', \n justifyContent: 'center', \n overflow: 'auto'\n } as CSSStyleDeclaration);\n\n // iframe\n console.debug('[Connect SDK] endpoints', Endpoints);\n console.log('[Connect SDK] opeining URL', Endpoints.benji_connect_auth_url);\n const url = new URL(Endpoints.benji_connect_auth_url);\n const connectToken = this.sdkConfig.token;\n url.searchParams.set('connect_token', connectToken);\n url.searchParams.set('t', String(Date.now()));\n\n this.iframe = document.createElement('iframe');\n Object.assign(this.iframe.style, {\n position: 'relative', \n width: '400px', \n height: '645px',\n border: 'none', \n borderRadius: '20px', \n overflow: 'hidden'\n } as CSSStyleDeclaration);\n this.iframe.src = url.toString();\n\n this.container.appendChild(this.iframe);\n document.body.appendChild(this.container);\n\n this.container.addEventListener('click', (e) => {\n if (e.target === this.container) {\n // Trigger exit when user taps outside modal bounds\n this.sdkConfig.onExit?.({\n context: buildContext(),\n trigger: BenjiConnectExitTrigger.TAPPED_OUT_OF_BOUNDS\n });\n this.close();\n }\n });\n }\n\n close() {\n if (!this.iframe) return;\n document.body.removeChild(this.container!);\n MessageRouter.removeEventListeners();\n // TODO: Track SDK Closed Tracker.trackSDKClosed();\n this.iframe = null;\n this.container = null;\n }\n\n cleanup() {\n if (this.iframe) this.close();\n }\n\n ping() { return 'pong'; }\n}\n\nexport default ConnectSDK;","/// <reference path=\"./global.d.ts\" />\nimport ConnectSDK from './connect-sdk';\n(globalThis as any).ConnectSDK = ConnectSDK;"],"mappings":";;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,sBAA8B;AAEpC,MAAM,YAAoC;AAAA,IAC/C,0BAAyB;AAAA,IACzB,kCAAmC;AAAA,EACrC;;;ACLA;AAAA;AAAA,qBAAAA;AAAA,IAAA,2BAAAC;AAAA;AAAO,MAAMA,uBAA8B;AAEpC,MAAMD,aAAoC;AAAA,IAC/C,0BAAyB;AAAA,IACzB,kCAAmC;AAAA,EACrC;;;ACLA;AA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