stream-connect-sdk 0.7.6 → 0.8.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/CHANGELOG.md +279 -0
- package/README.md +72 -111
- package/docs/README.md +52 -0
- package/docs/client-usage.md +405 -0
- package/docs/connect-access-token-screenshots/connect-access-token-pattern.png +0 -0
- package/docs/connect-access-token.md +71 -0
- package/docs/error.md +149 -0
- package/docs/faq.md +77 -0
- package/docs/fix-credentials/select-enroll-widget.png +0 -0
- package/docs/fix-credentials.md +151 -0
- package/docs/flow-screenshots/choose-payer.png +0 -0
- package/docs/flow-screenshots/enter-credentials.png +0 -0
- package/docs/flow-screenshots/pop-up.png +0 -0
- package/docs/flow-screenshots/realtime-validation.png +0 -0
- package/docs/flow-screenshots/terms-of-service.png +0 -0
- package/docs/headless.md +107 -0
- package/docs/interop-screenshots/Interop SDK Flow Legacy.png +0 -0
- package/docs/interop-screenshots/InteropSDKFlow.png +0 -0
- package/docs/interop.md +38 -0
- package/docs/migration-0.7-to-0.8.md +110 -0
- package/docs/quickstart-screenshots/demo-init-page.png +0 -0
- package/docs/quickstart-screenshots/employer-key-page.png +0 -0
- package/docs/quickstart-screenshots/error-init-page.png +0 -0
- package/docs/quickstart.md +247 -0
- package/docs/sdk-flow.md +43 -0
- package/docs/theme.md +47 -0
- package/docs/two-factor.md +137 -0
- package/package.json +67 -79
- package/sdk-headless.js +2 -0
- package/sdk.js +1 -1
- package/.babelrc +0 -4
- package/.rgignore +0 -1
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Quick Start
|
|
2
|
+
A guide to get an implementation up and running as quickly as possible. This guide
|
|
3
|
+
will not go into the deep customization of the SDK, but rather will look at getting
|
|
4
|
+
the SDK to be configured properly, to be able to submit credentials and validate them.
|
|
5
|
+
|
|
6
|
+
## Step 1 -- Import the SDK
|
|
7
|
+
This guide will use a simple html document with the configuration of the StreamConnect SDK set in an html head script.
|
|
8
|
+
The html surrounding the SDK will not change throughout the guide.
|
|
9
|
+
|
|
10
|
+
Here is what the test htmlscript looks like.
|
|
11
|
+
```html
|
|
12
|
+
<!DOCTYPE html>
|
|
13
|
+
<html>
|
|
14
|
+
<head>
|
|
15
|
+
<script src="https://app.tpastream.com/static/js/sdk.js"></script>
|
|
16
|
+
</head>
|
|
17
|
+
<body></body>
|
|
18
|
+
</html>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`<script src="https://app.tpastream.com/static/js/sdk.js"></script>` in the head will bring down the latest version of the StreamConnect SDK. If you need to pin to a specific version, change the src to something like
|
|
22
|
+
`<script src="https://app.tpastream.com/static/js/sdk-v-0.8.0.js"></script>`. Pinned versions remain available indefinitely.
|
|
23
|
+
|
|
24
|
+
The 0.8 SDK is visually self-contained: it does not require Bootstrap, jQuery, FontAwesome, or any other host-page CSS. Host pages that already load Bootstrap can keep doing so without conflict. SDK styles use a `tpa-` class prefix to avoid name collisions with host CSS, and the reset/theme variables are wrapped under `.tpa-sdk-root` so they only affect the SDK subtree.
|
|
25
|
+
|
|
26
|
+
## Step 2 -- Add element for SDK to hook to and init SDK
|
|
27
|
+
```html
|
|
28
|
+
<!DOCTYPE html>
|
|
29
|
+
<html>
|
|
30
|
+
<head>
|
|
31
|
+
<script src="https://app.tpastream.com/static/js/sdk.js"></script>
|
|
32
|
+
<script>
|
|
33
|
+
window.StreamConnect({
|
|
34
|
+
el: '#sdk-hook',
|
|
35
|
+
isDemo: true,
|
|
36
|
+
})
|
|
37
|
+
</script>
|
|
38
|
+
</head>
|
|
39
|
+
<body>
|
|
40
|
+
<div id="sdk-hook"></div>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The SDK will nest all of its elements beneath whatever div you target via a css selector in the `el` element. It is suggested
|
|
46
|
+
that an implementor starts the SDK init with `isDemo` set to true as shown above so that an implmenetor can see the initial SDK page.
|
|
47
|
+
|
|
48
|
+
*Demo mode is incapable of saving credentials or validating credentials.
|
|
49
|
+
|
|
50
|
+
If you then open up the above html in a browser you should see something close to the following.
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
## Step 3 -- Add sdk Token
|
|
54
|
+
```html
|
|
55
|
+
<!DOCTYPE html>
|
|
56
|
+
<html>
|
|
57
|
+
<head>
|
|
58
|
+
<script src="https://app.tpastream.com/static/js/sdk.js"></script>
|
|
59
|
+
<script>
|
|
60
|
+
window.StreamConnect({
|
|
61
|
+
el: '#sdk-hook',
|
|
62
|
+
isDemo: false,
|
|
63
|
+
sdkToken: 'Your-SDK-Token-Here', // Same as apiToken: 'Your-SDK-Token-Here'
|
|
64
|
+
})
|
|
65
|
+
</script>
|
|
66
|
+
</head>
|
|
67
|
+
<body>
|
|
68
|
+
<div id="sdk-hook"></div>
|
|
69
|
+
</body>
|
|
70
|
+
</html>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
After setting the `sdkToken` you will see the following page on your html.
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+
That is ok! In order to initialize the SDK you will need to have quite a few more values. So for now it won't properly init.
|
|
77
|
+
|
|
78
|
+
If you go into the developer tools for your site, you can get several helpful errors from the various requests which the SDK
|
|
79
|
+
is generating. In this case the following init errors will likely provide `422` responses.
|
|
80
|
+
|
|
81
|
+
Example Error:
|
|
82
|
+
```
|
|
83
|
+
You are missing required parameters in user. We require [firstName, lastName, email]. For more documentation on how the User Configuration works see https://github.com/TPAStream/stream-connect-js-sdk/blob/master/docs/client-usage.md#client-usage
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
If you recieve a `404` error at this step it is possible that your `sdkToken` is not configured properly. Stick with the guide to see
|
|
87
|
+
if the error naturally resolves as you add the rest of the configuration.
|
|
88
|
+
|
|
89
|
+
## Step 4 -- Add user configuration
|
|
90
|
+
```html
|
|
91
|
+
<!DOCTYPE html>
|
|
92
|
+
<html>
|
|
93
|
+
<head>
|
|
94
|
+
<script src="https://app.tpastream.com/static/js/sdk.js"></script>
|
|
95
|
+
<script>
|
|
96
|
+
window.StreamConnect({
|
|
97
|
+
el: '#sdk-hook',
|
|
98
|
+
isDemo: false,
|
|
99
|
+
sdkToken: 'Your-SDK-Token-Here',
|
|
100
|
+
user: {
|
|
101
|
+
firstName: 'Testing',
|
|
102
|
+
lastName: 'User',
|
|
103
|
+
email: 'youremail+testingsdk@email.com'
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
</script>
|
|
107
|
+
</head>
|
|
108
|
+
<body>
|
|
109
|
+
<div id="sdk-hook"></div>
|
|
110
|
+
</body>
|
|
111
|
+
</html>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
An implementor can think of a user as a participant which has the credentials on whatever insurance carrier is being interacted with.
|
|
115
|
+
In order to save these members into our system we require a first name, last name, and an email. While eventually this data will
|
|
116
|
+
come from real user data on your site, while configurating the sdk we suggest you use test emails.
|
|
117
|
+
|
|
118
|
+
*Warning* If you have an Admin account on TPAStream you will not be able to use that account with the StreamConnect SDK. Instead use
|
|
119
|
+
a different email with your enrollment process. Or if you are using GMail, you can follow the pattern `youremail+testingsdk@gmail.com`.
|
|
120
|
+
This will allow you to set-up a new account in TPAStream which is separate from your current one, but also have the emails go to
|
|
121
|
+
your current email.
|
|
122
|
+
|
|
123
|
+
## Step 5 -- Employer configuration
|
|
124
|
+
```html
|
|
125
|
+
<!DOCTYPE html>
|
|
126
|
+
<html>
|
|
127
|
+
<head>
|
|
128
|
+
<script src="https://app.tpastream.com/static/js/sdk.js"></script>
|
|
129
|
+
<script>
|
|
130
|
+
window.StreamConnect({
|
|
131
|
+
el: '#sdk-hook',
|
|
132
|
+
isDemo: false,
|
|
133
|
+
sdkToken: 'Your-SDK-Token-Here',
|
|
134
|
+
user: {
|
|
135
|
+
firstName: 'Testing',
|
|
136
|
+
lastName: 'User',
|
|
137
|
+
email: 'youremail+testingsdk@email.com'
|
|
138
|
+
},
|
|
139
|
+
employer: {
|
|
140
|
+
name: 'testingEmployer', // Only provide this if your employer does not exist in TPAStream yet.
|
|
141
|
+
systemKey: 'testing-sdk',
|
|
142
|
+
vendor: 'internal', // This will almost always be internal
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
</script>
|
|
146
|
+
</head>
|
|
147
|
+
<body>
|
|
148
|
+
<div id="sdk-hook"></div>
|
|
149
|
+
</body>
|
|
150
|
+
</html>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
When implementing the SDK all carrier credentials will be nested under an employer in TPAStream. This block will define which
|
|
154
|
+
employer your are interested in.
|
|
155
|
+
|
|
156
|
+
To get the Key for an existing employer go to the [Employers Page](https://app.tpastream.com/b/employers) in the TPAStream Admin portal. From there search up the desired employer. Then enter the details page of said employer. From there navigate to the **support** tab.
|
|
157
|
+
|
|
158
|
+
You will see a screen similar to this:
|
|
159
|
+

|
|
160
|
+
|
|
161
|
+
You will see `Internal Key` as a section. Grab the key directly across from that and put it into the systemKey config option in the employer object. In this case it is highleted and called `testing-sdk`.
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# Step 6 -- Init
|
|
165
|
+
|
|
166
|
+
Now that you have set up the configuration as follows you should be able to reload the page you set up before and init the SDK. From 0.8 onward the SDK ships with a polished default appearance, so you should see a usable enrollment widget without any host-page CSS work.
|
|
167
|
+
|
|
168
|
+
For brand-color matching see [Theme](./theme.md). For the per-callback contract and the full list of init options see [Client Usage](./client-usage.md). If you're coming from 0.7.x, the [Migration guide](./migration-0.7-to-0.8.md) calls out the handful of behaviors that changed.
|
|
169
|
+
|
|
170
|
+
## Mobile (Android, iOS, React Native)
|
|
171
|
+
|
|
172
|
+
The SDK is web-first. The recommended mobile integration pattern is to embed the SDK page in a WebView and ferry callbacks to the native host via `postMessage` / message handlers. This gives the mobile app the polished 0.8 UI for free without a parallel native codebase.
|
|
173
|
+
|
|
174
|
+
### React Native
|
|
175
|
+
|
|
176
|
+
[`react-native-webview`](https://github.com/react-native-webview/react-native-webview) is the standard library:
|
|
177
|
+
|
|
178
|
+
```jsx
|
|
179
|
+
import { WebView } from 'react-native-webview';
|
|
180
|
+
|
|
181
|
+
export const ConnectScreen = ({ onComplete }) => {
|
|
182
|
+
const handleMessage = (event) => {
|
|
183
|
+
const message = JSON.parse(event.nativeEvent.data);
|
|
184
|
+
if (message.type === 'doneEasyEnroll') {
|
|
185
|
+
onComplete(message.data);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<WebView
|
|
191
|
+
source={{ uri: 'https://your-backend.example.com/connect-sdk' }}
|
|
192
|
+
onMessage={handleMessage}
|
|
193
|
+
javaScriptEnabled
|
|
194
|
+
domStorageEnabled
|
|
195
|
+
originWhitelist={['*']}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Your `/connect-sdk` page should host the standard SDK init from Step 5 above, plus a `postMessage` forwarder so terminal-state callbacks reach the native shell:
|
|
202
|
+
|
|
203
|
+
```html
|
|
204
|
+
doneEasyEnroll: (data) => {
|
|
205
|
+
window.ReactNativeWebView?.postMessage(
|
|
206
|
+
JSON.stringify({ type: 'doneEasyEnroll', data })
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Full RN walkthrough including PAA-redirect handling is in [`sdk-hook/docs/README.md`](../sdk-hook/docs/README.md#recommended-webview-pattern-for-react-native).
|
|
212
|
+
|
|
213
|
+
> **Note on `stream-connect-sdk-hook`**: the separate headless hook package on npm (v0.6.x) is deprecated in favor of the WebView pattern above. Existing integrations keep working but won't receive feature updates. See the hook docs for the deprecation notice and migration guidance.
|
|
214
|
+
|
|
215
|
+
### Android (Java)
|
|
216
|
+
|
|
217
|
+
```java
|
|
218
|
+
public class ViewWeb extends Activity {
|
|
219
|
+
@Override
|
|
220
|
+
public void onCreate(Bundle savedInstanceState) {
|
|
221
|
+
super.onCreate(savedInstanceState);
|
|
222
|
+
setContentView(R.layout.content);
|
|
223
|
+
WebView webview = (WebView) findViewById(R.id.webView);
|
|
224
|
+
webview.getSettings().setJavaScriptEnabled(true);
|
|
225
|
+
webview.loadUrl("https://your-backend.example.com/connect-sdk");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### iOS (Swift / WKWebView)
|
|
231
|
+
|
|
232
|
+
```swift
|
|
233
|
+
import UIKit
|
|
234
|
+
import WebKit
|
|
235
|
+
|
|
236
|
+
class ViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {
|
|
237
|
+
@IBOutlet weak var webView: WKWebView!
|
|
238
|
+
|
|
239
|
+
override func viewDidLoad() {
|
|
240
|
+
super.viewDidLoad()
|
|
241
|
+
webView.uiDelegate = self
|
|
242
|
+
webView.navigationDelegate = self
|
|
243
|
+
let url = URL(string: "https://your-backend.example.com/connect-sdk")!
|
|
244
|
+
webView.load(URLRequest(url: url))
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
package/docs/sdk-flow.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# SDK Flow
|
|
2
|
+
## Set-Up
|
|
3
|
+
The SDK will not render on the page until `StreamConnect` is called. Meaning that implementors can setup the page to go through various flows and have the SDK generate as part of a button click and or other method. The SDK will render beneath whatever element-hook the implementor attaches it to. As part of this the implementor should have setup all the necessary piping and configurations on a per-user basis. Once this configuration is complete and the SDK is called it shall render it's first widget `choose-payer`
|
|
4
|
+
## Choose-Payer
|
|
5
|
+
This is the first widget to render on the page. It will appear as one of two forms. Either as a couple of images of payer logos or as a dropdown (Note: The dropdown can have the images appear as well if they are specifically configured on the employer OR there are credentials already existing for this user on said payer).
|
|
6
|
+
|
|
7
|
+
If the SDK is configured to demo mode you can see what each individual style will look like. Once the user clicks on one of these images or selects from the dropdown, the next widget renders: `enter-credentials`.
|
|
8
|
+
|
|
9
|
+
Here is what choose-payer might looks like (DISCLAIMER: All screenshots are configured in demo-mode and thus have incomplete data)
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
## Enter Credentials
|
|
13
|
+
The second widget to render on the page is the `enter-credentials` widget. This widget handles the form for the specific carrier site. This page will have fields for usernames, passwords, security questions, dates of birth, and terms of service acceptance.
|
|
14
|
+
|
|
15
|
+
The SDK will handle all the validation of the form. You can interface more thoroughly with the submit request via the `donePostCredentials` callback.
|
|
16
|
+
|
|
17
|
+
This widget is also home to some sub-widgets which have their own callbacks: `terms-of-service` and `pop-up`.
|
|
18
|
+
|
|
19
|
+
Here is what a form might look like
|
|
20
|
+

|
|
21
|
+
|
|
22
|
+
## Enter Credentials Sub-Widgets
|
|
23
|
+
#### Pop Up
|
|
24
|
+
This widget is accessed by clicking the question mark on the page. This pop-up has a link to the carrier site.
|
|
25
|
+

|
|
26
|
+
#### Terms of Service
|
|
27
|
+
This widget contains the TPAStream terms of service
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
## Real Time Validation
|
|
31
|
+
|
|
32
|
+
In 0.8 this is no longer a blocking intermediate widget. After the user submits credentials, the SDK opens a Server-Sent Events subscription to `/v3/sdk/progress/<task_id>/stream` and surfaces validation progress in a non-blocking hero element plus a corner-panel UI, while the rest of the flow remains interactive. Multiple validations can run in parallel; each one owns its own SSE subscription.
|
|
33
|
+
|
|
34
|
+
Auth on the SSE channel is a short-lived task-scoped JWT (audience `sdk:sse:progress`, bound to the user + validation task, 10-minute TTL) returned in the credential-submit response as `task_token`. The SDK forwards it as a `?token=...` query param on the SSE subscription; integrators do not need to handle the token directly.
|
|
35
|
+
|
|
36
|
+
State transitions arrive as they happen rather than on the 5-second polling cadence used in 0.7.x. The server-side stream has a hard ~10-minute deadline; if validation hasn't terminated by then the server emits a `timeout` event and closes the stream. The SDK transitions that validation to a `pending_async` state which keeps it visible in the hero / corner-panel UI (the wizard does NOT auto-advance to FinishedEasyEnroll). The user can keep using the SDK; when they return later, the next call to the backend will reflect whatever terminal state the validation reached.
|
|
37
|
+
|
|
38
|
+
`doneRealTime` still fires for back-compat. The `realtimeTimeout` init option is accepted but ignored (the timeout is now server-side).
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
## Done Easy Enroll
|
|
43
|
+
This final widget will display an ending message for the user and allow them to retry and or submit credentials depending on their end status.
|
package/docs/theme.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Theme
|
|
2
|
+
|
|
3
|
+
The 0.8 SDK ships with a polished default appearance: cards, generous whitespace, system-font stack, accessible focus rings. Most integrators do not need to write any CSS. For brand-color matching, the `theme` init option exposes a small set of overrides applied as scoped CSS variables on the SDK root subtree.
|
|
4
|
+
|
|
5
|
+
## `theme.primaryColor`
|
|
6
|
+
|
|
7
|
+
Recolors the SDK's primary accent surfaces (buttons, links, focus rings, progress bars, selected-state highlights) to match your brand.
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
StreamConnect({
|
|
11
|
+
el: '#react-hook',
|
|
12
|
+
apiToken: 'VeryLegitKey',
|
|
13
|
+
// ... other options ...
|
|
14
|
+
theme: {
|
|
15
|
+
primaryColor: '#2563eb'
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Accepts a 6-digit hex color string (`#RRGGBB`) or a pre-formatted RGB triplet (`"37 99 235"`). The 3-digit shorthand `#RGB` is not supported. The SDK derives a small shade scale (50 / 100 / 200 / 300 / 500 / 600 / 700 / 800) from the value and binds it to CSS variables under `.tpa-sdk-root`. Two SDK instances on the same page with different `primaryColor` values render independently; the overrides are scoped, not global.
|
|
21
|
+
|
|
22
|
+
### What it recolors
|
|
23
|
+
|
|
24
|
+
- Primary buttons (background + hover/active states)
|
|
25
|
+
- Links inside SDK widgets
|
|
26
|
+
- Focus rings on inputs, buttons, checkboxes
|
|
27
|
+
- Progress indicators and active-step markers
|
|
28
|
+
- Selected-state highlights (e.g., the chosen carrier tile)
|
|
29
|
+
|
|
30
|
+
### What it does not recolor
|
|
31
|
+
|
|
32
|
+
- Carrier logos and Patient Access API payer tiles (these display the carrier's own branding)
|
|
33
|
+
- Error states (red), success states (green), and other semantic colors
|
|
34
|
+
- Body text, secondary text, card backgrounds, dividers
|
|
35
|
+
- Host-page content outside the SDK subtree
|
|
36
|
+
|
|
37
|
+
If you need to override a color the `primaryColor` knob does not touch, file an issue describing the use case; we would rather extend the theme API than have integrators target SDK internals with descendant CSS selectors that will break on the next release.
|
|
38
|
+
|
|
39
|
+
## Scoping
|
|
40
|
+
|
|
41
|
+
All theme overrides are applied via CSS custom properties on the `.tpa-sdk-root` element the SDK mounts inside your `el` selector. They do not leak to any sibling or ancestor element on the host page.
|
|
42
|
+
|
|
43
|
+
The SDK's own Tailwind utility classes use the `tpa-` prefix to avoid name collisions with host-page CSS. The utility classes themselves are global (anywhere `.tpa-text-white` appears in the DOM, the rule applies), but the prefix means a host page that doesn't use `tpa-*` class names will never collide. The reset and theme variables are wrapped in `.tpa-sdk-root` so they only affect the SDK subtree.
|
|
44
|
+
|
|
45
|
+
## What's coming
|
|
46
|
+
|
|
47
|
+
For more comprehensive branding (custom fonts, surface colors, dark mode, configurable border radius) we are gathering feedback. Open an issue at https://github.com/TPAStream/stream-connect-js-sdk/issues if you need controls beyond `primaryColor`.
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Two-Factor Authentication (MFA)
|
|
2
|
+
|
|
3
|
+
When a carrier challenges a credential submission with a one-time code
|
|
4
|
+
(SMS, email, authenticator app), the SDK renders the prompt inline in
|
|
5
|
+
the validation hero element instead of opening a modal or taking over
|
|
6
|
+
the screen. The user picks a delivery method, types the code, and the
|
|
7
|
+
rest of the SDK stays interactive throughout.
|
|
8
|
+
|
|
9
|
+
This document covers what the user sees, what the SDK is doing under
|
|
10
|
+
the hood, and what failure modes to expect.
|
|
11
|
+
|
|
12
|
+
## The hero element
|
|
13
|
+
|
|
14
|
+
Every active validation owns a slot in the hero element pinned to the
|
|
15
|
+
top of the SDK view. As the SSE stream reports state transitions, the
|
|
16
|
+
hero re-renders with the right copy and the right input control:
|
|
17
|
+
|
|
18
|
+
| Hero state | What it looks like | What the user does |
|
|
19
|
+
|---|---|---|
|
|
20
|
+
| `pending` | "Connecting…" with a spinner | Wait |
|
|
21
|
+
| `method_choice` | "Choose a verification method" with a combobox | Pick SMS / email / app |
|
|
22
|
+
| `awaiting_code` | "Enter your code" with a numeric input | Type the code from their phone |
|
|
23
|
+
| `submitting` | "Working on it…" | Wait |
|
|
24
|
+
| `success` | "Connected!" (green) | Done; auto-dismisses after a short hold |
|
|
25
|
+
| `failure` | "Couldn't connect" (red) with the carrier message | Reconnect via the tile |
|
|
26
|
+
| `pending_async` | "Still working on it" | Come back later; SDK is no longer streaming live |
|
|
27
|
+
|
|
28
|
+
The hero is rendered by `ActiveValidationsHero` and lives alongside
|
|
29
|
+
the wizard step state, so the user can keep navigating
|
|
30
|
+
choose-payer / fix-credentials / etc. while the validation runs in
|
|
31
|
+
the background. A corner-panel chip (`ActiveValidationsPanel`)
|
|
32
|
+
mirrors the active validations so they're visible from any step.
|
|
33
|
+
|
|
34
|
+
## Backend mechanics
|
|
35
|
+
|
|
36
|
+
After cred submit, the backend dispatches a Celery task to validate
|
|
37
|
+
the credentials against the carrier. If the carrier challenges with
|
|
38
|
+
MFA:
|
|
39
|
+
|
|
40
|
+
1. The task emits a `WAITING_FOR_METHOD_CHOICE` state event over the
|
|
41
|
+
SSE stream with a `method_list` payload (which delivery methods
|
|
42
|
+
the carrier offers for that account).
|
|
43
|
+
2. The SDK reads the event, sets the validation to `method_choice`,
|
|
44
|
+
and renders the method picker.
|
|
45
|
+
3. The user picks a method. The SDK posts to
|
|
46
|
+
`PUT /sdk-api/validate-credentials/<phid>/<task_id>` with
|
|
47
|
+
`{ method: 'sms' }` (or whatever the carrier called it).
|
|
48
|
+
4. The task moves to `TRIGGERING_TWO_FACTOR_AUTH` while it asks the
|
|
49
|
+
carrier to send the code, then to `WAITING_FOR_TWO_FACTOR_CODE`
|
|
50
|
+
once the carrier acknowledges.
|
|
51
|
+
5. The SDK sets the validation to `awaiting_code` and renders the
|
|
52
|
+
code-entry input.
|
|
53
|
+
6. The user types the code. Same PUT endpoint with `{ code: '123456' }`.
|
|
54
|
+
The task transitions to `ENTERING_CODE` while it submits the code
|
|
55
|
+
to the carrier.
|
|
56
|
+
7. On success the task lands on `TWO_FACTOR_AUTH_COMPLETE`; the SDK
|
|
57
|
+
refreshes the policy holder to confirm credentials are valid and
|
|
58
|
+
shows the success hero.
|
|
59
|
+
|
|
60
|
+
The full wire-state set the SDK consumes is in
|
|
61
|
+
[`assets/sdk/services/progress-stream.ts`](../assets/sdk/services/progress-stream.ts)
|
|
62
|
+
(`TWO_FACTOR_STATES`); any state not in that set falls through to the
|
|
63
|
+
generic PENDING / STARTED / RETRY / SUCCESS / FAILURE mapping.
|
|
64
|
+
|
|
65
|
+
The SSE stream carries every transition in real time. The 5-second
|
|
66
|
+
polling cadence the 0.7.x SDK used is gone.
|
|
67
|
+
|
|
68
|
+
## What can go wrong
|
|
69
|
+
|
|
70
|
+
### Method picker submit failed
|
|
71
|
+
|
|
72
|
+
If the PUT to record the method choice rejects (network blip, carrier
|
|
73
|
+
backend error), the SDK reverts the validation from `submitting` back
|
|
74
|
+
to `method_choice` and renders the error message inline above the
|
|
75
|
+
picker:
|
|
76
|
+
|
|
77
|
+
> Couldn't reach the carrier. Please try again.
|
|
78
|
+
|
|
79
|
+
The picker stays interactive so the user can retry without losing
|
|
80
|
+
their place.
|
|
81
|
+
|
|
82
|
+
### Code entry rejected
|
|
83
|
+
|
|
84
|
+
If the carrier rejects the submitted code (wrong number, expired,
|
|
85
|
+
typo), the carrier-specific message is forwarded into the validation
|
|
86
|
+
state and surfaces inline above the code input. The user can re-enter
|
|
87
|
+
without re-running the entire credential flow.
|
|
88
|
+
|
|
89
|
+
### Stream times out (10-minute deadline)
|
|
90
|
+
|
|
91
|
+
The server-side SSE deadline is ~10 minutes per stream. If the user
|
|
92
|
+
takes longer than that to retrieve and enter the code, the stream
|
|
93
|
+
closes and the validation moves to `pending_async`. The hero shows
|
|
94
|
+
"Still working on it" and the validation stays visible. The user can
|
|
95
|
+
keep using the SDK; the task itself isn't cancelled. When they come
|
|
96
|
+
back later, the validation's terminal state will be reflected on the
|
|
97
|
+
next page load.
|
|
98
|
+
|
|
99
|
+
### Stream disconnects mid-2FA
|
|
100
|
+
|
|
101
|
+
A network blip, server-side close, or proxy drop during the validation
|
|
102
|
+
lands the validation in `pending_async` the same way the timeout does.
|
|
103
|
+
The backend task continues; the SDK just can't observe it live anymore.
|
|
104
|
+
|
|
105
|
+
`AbortController.abort()` is intentionally NOT treated as a disconnect:
|
|
106
|
+
the SDK aborts on unmount and on terminal-state cleanup, and surfacing
|
|
107
|
+
those as user-visible errors would flip cleanly-finished validations
|
|
108
|
+
into "Still working on it." `consumeSSE` filters `AbortError` from both
|
|
109
|
+
the initial-fetch and reader-loop catches.
|
|
110
|
+
|
|
111
|
+
## Multiple parallel 2FA flows
|
|
112
|
+
|
|
113
|
+
Multiple credentials can be validating at the same time, each in
|
|
114
|
+
their own MFA stage. The hero stacks them top-to-bottom in insertion
|
|
115
|
+
order (the order the user submitted them). Each owns its own SSE
|
|
116
|
+
subscription and its own method/code-entry state, so action on one
|
|
117
|
+
card doesn't disrupt the others.
|
|
118
|
+
|
|
119
|
+
## Implementation pointers
|
|
120
|
+
|
|
121
|
+
* Hero rendering + state machine:
|
|
122
|
+
[`ActiveValidationsHero.tsx`](../assets/sdk/components/ActiveValidationsHero.tsx)
|
|
123
|
+
* SSE consumer and reconcile loop:
|
|
124
|
+
[`ValidationStreamRunner.tsx`](../assets/sdk/contexts/ValidationStreamRunner.tsx)
|
|
125
|
+
* Reducer for validation state transitions:
|
|
126
|
+
[`ActiveValidationsContext.tsx`](../assets/sdk/contexts/ActiveValidationsContext.tsx)
|
|
127
|
+
* MFA submit endpoint (backend):
|
|
128
|
+
`/sdk-api/validate-credentials/<phid>/<task_id>` (PUT)
|
|
129
|
+
|
|
130
|
+
## See also
|
|
131
|
+
|
|
132
|
+
* [SDK Flow](./sdk-flow.md) for the broader real-time validation flow
|
|
133
|
+
the 2FA path plugs into
|
|
134
|
+
* [Errors](./error.md) for the full error surface (SSE auth, JWT,
|
|
135
|
+
cred-submit)
|
|
136
|
+
* [Fix Credentials](./fix-credentials.md) for the per-carrier tile
|
|
137
|
+
view that surfaces in-flight 2FA validations as "Validating now"
|
package/package.json
CHANGED
|
@@ -1,81 +1,69 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"bracketSpacing": true,
|
|
70
|
-
"arrowParens": "avoid"
|
|
71
|
-
},
|
|
72
|
-
"bugs": {
|
|
73
|
-
"url": "https://github.com/TPAStream/stream-connect-js-sdk/issues"
|
|
74
|
-
},
|
|
75
|
-
"homepage": "https://github.com/TPAStream/stream-connect-js-sdk#readme",
|
|
76
|
-
"main": "sdk.js",
|
|
77
|
-
"keywords": [
|
|
78
|
-
"sdk"
|
|
79
|
-
],
|
|
80
|
-
"license": "ISC"
|
|
2
|
+
"name": "stream-connect-sdk",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "A JavaScript SDK implementing TPAStream's Connect Platform",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "webpack --config webpack.prod-sdk.js --mode=production",
|
|
7
|
+
"format": "biome check --write assets/",
|
|
8
|
+
"test:lint": "biome check assets/",
|
|
9
|
+
"test:types": "tsc --noEmit",
|
|
10
|
+
"test": "npm run test:lint && npm run test:types"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git@github.com:TPAStream/stream-connect-js-sdk.git"
|
|
15
|
+
},
|
|
16
|
+
"author": "TPAStreamOrg",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@babel/cli": "^7.27.1",
|
|
19
|
+
"@babel/core": "^7.27.1",
|
|
20
|
+
"@babel/preset-env": "^7.27.1",
|
|
21
|
+
"@babel/preset-react": "^7.27.1",
|
|
22
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
23
|
+
"@biomejs/biome": "^1.9.4",
|
|
24
|
+
"@types/react": "^19.0.0",
|
|
25
|
+
"@types/react-dom": "^19.0.0",
|
|
26
|
+
"autoprefixer": "^10.4.21",
|
|
27
|
+
"babel-loader": "^9.2.1",
|
|
28
|
+
"css-loader": "^7.1.2",
|
|
29
|
+
"postcss": "^8.5.3",
|
|
30
|
+
"postcss-loader": "^8.1.1",
|
|
31
|
+
"style-loader": "^4.0.0",
|
|
32
|
+
"tailwindcss": "^3.4.17",
|
|
33
|
+
"typescript": "^5.7.3",
|
|
34
|
+
"webpack": "^5.99.5",
|
|
35
|
+
"webpack-cli": "^6.0.1",
|
|
36
|
+
"webpack-merge": "^6.0.1"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@headlessui/react": "^2.2.0",
|
|
40
|
+
"@hookform/resolvers": "^3.10.0",
|
|
41
|
+
"axios": "^1.7.9",
|
|
42
|
+
"dompurify": "^3.2.4",
|
|
43
|
+
"marked": "^15.0.7",
|
|
44
|
+
"react": "^19.0.0",
|
|
45
|
+
"react-dom": "^19.0.0",
|
|
46
|
+
"react-hook-form": "^7.54.2",
|
|
47
|
+
"zod": "^3.24.2"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/TPAStream/stream-connect-js-sdk/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/TPAStream/stream-connect-js-sdk#readme",
|
|
53
|
+
"main": "sdk.js",
|
|
54
|
+
"exports": {
|
|
55
|
+
".": "./sdk.js",
|
|
56
|
+
"./headless": "./sdk-headless.js"
|
|
57
|
+
},
|
|
58
|
+
"files": [
|
|
59
|
+
"sdk.js",
|
|
60
|
+
"sdk-headless.js",
|
|
61
|
+
"README.md",
|
|
62
|
+
"CHANGELOG.md",
|
|
63
|
+
"docs/"
|
|
64
|
+
],
|
|
65
|
+
"keywords": [
|
|
66
|
+
"sdk"
|
|
67
|
+
],
|
|
68
|
+
"license": "ISC"
|
|
81
69
|
}
|