@benji-money/connect-sdk 1.1.4-beta.1 → 1.1.4-beta.10
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 +34 -13
- package/dist/connect-sdk.umd.global.js +355 -599
- package/dist/connect-sdk.umd.global.js.map +1 -1
- package/dist/index.cjs +379 -608
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +119 -26
- package/dist/index.d.ts +119 -26
- package/dist/index.js +377 -608
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
A JavaScript Github Package SDK for integrating Benji Connect, Benji's authentication and verification services.
|
|
4
4
|
|
|
5
|
+
LOGIN mode (surfaces, timers, host API): [docs/login-mode.md](./docs/login-mode.md).
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -87,12 +89,21 @@ The SDK accepts the following configuration options:
|
|
|
87
89
|
- `environment` (required): One of `local`, `development`, `sandbox`, or `production`
|
|
88
90
|
- `token` (required): Your API connect token
|
|
89
91
|
- `mode` (optional): `BenjiConnectMode` — `CONNECT` (default), `TRANSFER`, `REDEEM`, or `LOGIN`
|
|
90
|
-
- `authType` (optional): `PartnerIntegrationType` — LOGIN only; omit or set `DUMMY` for the visible modal iframe; set to your partner type (1–6) for
|
|
91
|
-
- `
|
|
92
|
+
- `authType` (optional): `PartnerIntegrationType` — LOGIN only; omit or set `DUMMY` for the visible modal iframe; set to your partner type (1–6) for the embedded sign-in button. Prefer `tokenData.authType` when using `tokenData`.
|
|
93
|
+
- `login` (optional): `BenjiConnectLoginConfig` — LOGIN-only options:
|
|
94
|
+
- `container`: `HTMLElement | string` — **required** for the embedded LOGIN button. The element the visible Benji Connect iframe mounts into. The SDK never appends to `document.body` for this surface; a missing container reports through `onError`.
|
|
95
|
+
- `surface`: `BenjiConnectLoginSurface` — `EMBEDDED_BUTTON` (default for non-DUMMY LOGIN) or `MODAL` (default for DUMMY). Override only when a partner on a real integration type needs the modal.
|
|
96
|
+
- `windowTarget`: `BenjiConnectLoginWindowTarget` — LOGIN non-DUMMY only; `tab` (default) or `popup`. Forwarded to Benji Connect, which opens the window.
|
|
97
|
+
- `buttonText`: host-owned label. Omitted or empty → Connect paints `Login`.
|
|
98
|
+
- `buttonTheme`: resolved CSS values for the in-iframe button (fill, hover, type, radius).
|
|
99
|
+
- `tokenData` (optional): `BenjiConnectTokenData` — LOGIN only; pass `partnerAuthLink` (Auth Service `connect_url`), `configToken` (mint `config_token`, used as OAuth `state`), and `authType`. Benji Connect resolves the auth link at iframe load, before any click.
|
|
92
100
|
- `onSuccess` (optional): Callback function called when connect completed successfully
|
|
93
101
|
- `onError` (optional): Callback function called when error occurs in the connect flow
|
|
94
102
|
- `onExit` (optional): Callback function called when the user exits the connect flow
|
|
95
103
|
- `onEvent` (optional): Callback function for handling various events
|
|
104
|
+
- `onLoginReady` (optional): Embedded LOGIN button only — Benji Connect rendered the button, so the host can drop its skeleton
|
|
105
|
+
- `onLoginHover` (optional): Embedded LOGIN button only — pointer or focus entered the in-iframe button, for a host-owned tooltip
|
|
106
|
+
- `onLoginClicked` (optional): Embedded LOGIN button only — the button was pressed, before the tab opens, for a host-owned pending state
|
|
96
107
|
- `anchor` (optional): Live anchor binding — `HTMLElement`, CSS selector, getter `() => HTMLElement | null`, or ref `{ value: HTMLElement | null }`. Re-resolved on every layout pass. Falls back to centered when missing or invalid. See [Placement](#placement)
|
|
97
108
|
- `placement` (optional): Placement relative to `anchor` — see [Placement](#placement) below
|
|
98
109
|
- `offset` (optional): Pixel gap after placement — `{ top?: number; left?: number }` (default `{ top: 0, left: 0 }`)
|
|
@@ -103,7 +114,7 @@ The SDK accepts the following configuration options:
|
|
|
103
114
|
| ---- | ---------- | ----- |
|
|
104
115
|
| **CONNECT** (default) | Centered or anchored modal iframe | No `authType`; standard connect / verify flow |
|
|
105
116
|
| **LOGIN + DUMMY / no `authType`** | Same visible modal iframe | Partner auth runs in a nested iframe inside Benji Connect |
|
|
106
|
-
| **LOGIN + non-DUMMY** |
|
|
117
|
+
| **LOGIN + non-DUMMY** | **Embedded sign-in button** plus a partner auth tab | Pass `authType` (or `tokenData.authType`) and `login.container`. Benji Connect renders the button inside a visible iframe and opens the partner tab itself, on every device. See [embedded LOGIN button example](#embedded-login-button-example) below. |
|
|
107
118
|
|
|
108
119
|
### Placement
|
|
109
120
|
|
|
@@ -118,7 +129,7 @@ Placement uses [Floating UI](https://floating-ui.com/docs/computePosition#placem
|
|
|
118
129
|
**What `anchor` positions:**
|
|
119
130
|
|
|
120
131
|
- **CONNECT, TRANSFER, REDEEM, and LOGIN + DUMMY:** the modal iframe
|
|
121
|
-
- **LOGIN + non-DUMMY:**
|
|
132
|
+
- **LOGIN + non-DUMMY:** nothing. The embedded button takes its box from `login.container`, so omit `anchor` / `placement` / `offset`.
|
|
122
133
|
|
|
123
134
|
**Defaults:**
|
|
124
135
|
|
|
@@ -145,15 +156,18 @@ Prefer selector, ref, or getter when the anchor can re-render (e.g. disabled/loa
|
|
|
145
156
|
- **Anchored** popovers use the full design size when width and height checks pass; otherwise they fall back to a scaled centered modal
|
|
146
157
|
- Scroll, resize, and visual viewport changes while open recompute placement and size
|
|
147
158
|
|
|
148
|
-
#### LOGIN
|
|
159
|
+
#### Embedded LOGIN button example
|
|
160
|
+
|
|
161
|
+
Reserve a box in your own layout, hand it to the SDK, and let Benji Connect render the button inside it:
|
|
149
162
|
|
|
150
|
-
|
|
163
|
+
```html
|
|
164
|
+
<div id="benji-login" style="width: 140px; height: 40px"></div>
|
|
165
|
+
```
|
|
151
166
|
|
|
152
167
|
```typescript
|
|
153
168
|
import {
|
|
154
169
|
ConnectSDK,
|
|
155
170
|
BenjiConnectMode,
|
|
156
|
-
BenjiConnectPlacement,
|
|
157
171
|
PartnerIntegrationType,
|
|
158
172
|
} from "@benji-money/connect-sdk";
|
|
159
173
|
|
|
@@ -161,22 +175,29 @@ const sdk = new ConnectSDK({
|
|
|
161
175
|
environment: "sandbox",
|
|
162
176
|
token: connectToken,
|
|
163
177
|
mode: BenjiConnectMode.LOGIN,
|
|
178
|
+
login: { container: "#benji-login" },
|
|
164
179
|
tokenData: {
|
|
165
180
|
authType: PartnerIntegrationType.OAUTH_PKCE,
|
|
166
181
|
partnerAuthLink: connectUrl, // from Auth Service connect_url
|
|
182
|
+
configToken: configToken, // from GET /connect/token — OAuth state
|
|
167
183
|
},
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
184
|
+
onLoginReady: () => { /* hide your skeleton */ },
|
|
185
|
+
onLoginHover: () => { /* show your tooltip */ },
|
|
186
|
+
onLoginClicked: () => { /* show your pending state */ },
|
|
171
187
|
onSuccess: (token) => { /* ... */ },
|
|
172
|
-
onError: (error) => { /*
|
|
173
|
-
onExit: (metadata) => { /*
|
|
188
|
+
onError: (error) => { /* sign-in window blocked, etc. */ },
|
|
189
|
+
onExit: (metadata) => { /* toast: WINDOW_CLOSE_DETECTED; the button stays mounted */ },
|
|
174
190
|
});
|
|
175
191
|
|
|
192
|
+
// Mount on page load, not on click — the iframe resolves the partner auth link
|
|
193
|
+
// while the user is still reading the page.
|
|
176
194
|
await sdk.open();
|
|
195
|
+
|
|
196
|
+
// Later, when your token refresh timer fires:
|
|
197
|
+
sdk.updateConfig({ token: freshConnectToken, tokenData: { configToken: freshConfigToken } });
|
|
177
198
|
```
|
|
178
199
|
|
|
179
|
-
>
|
|
200
|
+
> **Why the button lives in the iframe.** `window.open` needs transient user activation, and activation belongs to the document the click happened in. Because the click lands in Benji Connect's document, **Connect** opens the partner tab, so that tab's `opener` is the Connect iframe — same-origin with Connect's OAuth callback. That is what removes the host-side auth relay, the message queues, and the iOS-only same-tab redirect that earlier versions needed. Reserve the box in your own CSS: the SDK's iframe fills the container at 100% × 100% and contributes no geometry of its own.
|
|
180
201
|
|
|
181
202
|
### Environments
|
|
182
203
|
|