stream-connect-sdk 0.8.0 → 0.8.2

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.
@@ -40,7 +40,143 @@ StreamConnect({
40
40
 
41
41
  This JWT expires after 1 hour.
42
42
 
43
- ## Mid-session token refresh (0.8+)
43
+ ## Refreshing an expired token (0.8.1+)
44
+
45
+ Connect access tokens expire after 1 hour. When a member leaves your
46
+ SDK-hosting page open past that window and comes back to interact,
47
+ the next API call fails with a 422 and `error_code:
48
+ "expired_connect_token"`. The 0.8.1 SDK can recover transparently
49
+ **if** you wire a refresh hook — but the refresh has to go through
50
+ your server, because only your server holds the SDK secret key.
51
+
52
+ ### Why this can't be automatic
53
+
54
+ The whole point of the connect access token is that the secret key
55
+ never reaches the browser. If the SDK could mint its own tokens, the
56
+ secret would have to be in JS code where any user with devtools could
57
+ read it. So the SDK can't refresh on its own — it can only ask your
58
+ server for a fresh token.
59
+
60
+ ### Step 1: expose a refresh endpoint on your server
61
+
62
+ This endpoint does the same `POST` to `/api/create-connect-token`
63
+ that your original page-render did, returning the new JWT to the
64
+ browser. **Gate it with the same auth you use for the member's
65
+ session** — anyone who can call it can extend any member's SDK
66
+ session indefinitely.
67
+
68
+ **Flask:**
69
+
70
+ ```python
71
+ from flask import jsonify, request
72
+ import requests
73
+
74
+ @app.route("/api/tpa-sdk-refresh-token", methods=["POST"])
75
+ @your_login_required
76
+ def tpa_sdk_refresh_token():
77
+ response = requests.post(
78
+ "https://app.tpastream.com/api/create-connect-token",
79
+ json={
80
+ "connect_access_key": app.config["TPA_SDK_PUBLIC_KEY"],
81
+ "connect_secret_key": app.config["TPA_SDK_SECRET_KEY"],
82
+ },
83
+ timeout=10,
84
+ )
85
+ response.raise_for_status()
86
+ return jsonify(token=response.json()["data"])
87
+ ```
88
+
89
+ **Express:**
90
+
91
+ ```js
92
+ app.post('/api/tpa-sdk-refresh-token', yourLoginRequired, async (req, res) => {
93
+ const r = await fetch('https://app.tpastream.com/api/create-connect-token', {
94
+ method: 'POST',
95
+ headers: { 'Content-Type': 'application/json' },
96
+ body: JSON.stringify({
97
+ connect_access_key: process.env.TPA_SDK_PUBLIC_KEY,
98
+ connect_secret_key: process.env.TPA_SDK_SECRET_KEY,
99
+ }),
100
+ });
101
+ if (!r.ok) return res.status(502).json({ error: 'refresh failed' });
102
+ const { data } = await r.json();
103
+ res.json({ token: data });
104
+ });
105
+ ```
106
+
107
+ **ASP.NET Core (C#):**
108
+
109
+ ```csharp
110
+ [Authorize] // gate with your member-session auth
111
+ [HttpPost("api/tpa-sdk-refresh-token")]
112
+ public async Task<IActionResult> TpaSdkRefreshToken(
113
+ [FromServices] IHttpClientFactory clientFactory,
114
+ [FromServices] IConfiguration config)
115
+ {
116
+ var http = clientFactory.CreateClient();
117
+ var payload = new
118
+ {
119
+ connect_access_key = config["TpaSdk:PublicKey"],
120
+ connect_secret_key = config["TpaSdk:SecretKey"],
121
+ };
122
+ using var response = await http.PostAsJsonAsync(
123
+ "https://app.tpastream.com/api/create-connect-token", payload);
124
+ if (!response.IsSuccessStatusCode)
125
+ return StatusCode(502, new { error = "refresh failed" });
126
+ var doc = await response.Content.ReadFromJsonAsync<JsonElement>();
127
+ return Ok(new { token = doc.GetProperty("data").GetString() });
128
+ }
129
+ ```
130
+
131
+ The pattern is the same in every backend: an authenticated POST that proxies to `app.tpastream.com/api/create-connect-token` with your stored secret + public keys. PHP, Ruby, Go, Java — same shape, swap the HTTP client for whatever's idiomatic.
132
+
133
+ ### Step 2: wire `connectAccessTokenRefreshFn` on the SDK
134
+
135
+ ```js
136
+ StreamConnect({
137
+ // ... your existing config ...
138
+ connectAccessToken: '<initial-token-from-page-render>',
139
+ connectAccessTokenRefreshFn: async () => {
140
+ const r = await fetch('/api/tpa-sdk-refresh-token', {
141
+ method: 'POST',
142
+ credentials: 'same-origin',
143
+ });
144
+ if (!r.ok) throw new Error(`refresh failed: ${r.status}`);
145
+ return (await r.json()).token;
146
+ },
147
+ });
148
+ ```
149
+
150
+ When the SDK detects an expired token, it calls this function, swaps
151
+ the new value into its `X-Connect-Access-Token` header, and retries
152
+ the failed request — the member sees no error. Multiple parallel
153
+ failed requests share a single refresh attempt (stampede guard) so
154
+ your endpoint gets called once per expiry cycle, not once per request.
155
+
156
+ ### Fallback: notification-only
157
+
158
+ If you can't add a refresh endpoint (legacy host, static site, etc.),
159
+ wire `onConnectAccessTokenExpired` instead. The SDK will surface the
160
+ expiry to your callback (and dispatch a
161
+ `tpastream-connect-token-expired` CustomEvent on `window`) so you can
162
+ prompt the member to reload:
163
+
164
+ ```js
165
+ StreamConnect({
166
+ // ... your existing config ...
167
+ onConnectAccessTokenExpired: () => {
168
+ if (confirm('Your session has expired. Reload to continue?')) {
169
+ window.location.reload();
170
+ }
171
+ },
172
+ });
173
+ ```
174
+
175
+ The reload triggers a fresh page render, which mints a fresh
176
+ `connectAccessToken` server-side. The trade-off versus the refresh
177
+ hook is that the member loses any in-progress credential entry.
178
+
179
+ ## Mid-session token refresh (Patient Access API redirect)
44
180
 
45
181
  After a Patient Access API redirect completes, `app.tpastream.com`
46
182
  appends a fresh `?accessToken=...` query parameter to the return
@@ -30,6 +30,12 @@ StreamConnect({
30
30
 
31
31
  ## What the user sees
32
32
 
33
+ When a returning user opens the SDK in fix-credentials mode, the
34
+ first screen offers two paths: add a new carrier, or manage existing
35
+ ones.
36
+
37
+ ![Select enroll process](https://tpastream-public.s3.amazonaws.com/sdk-docs/fix-credentials/select-enroll-widget.png)
38
+
33
39
  The fix-credentials view lists every policy-holder the user has
34
40
  connected. Each carrier renders as a tile with:
35
41
 
package/docs/interop.md CHANGED
@@ -24,7 +24,7 @@ The legacy alias `enableInteropSinglePage` is also still accepted with the same
24
24
  After the carrier redirect completes, the SDK reads two URL parameters automatically on load:
25
25
 
26
26
  * `?accessToken=...`: a fresh connect-access token minted by `app.tpastream.com`.
27
- * `?forceTPAStreamSdkEnd=1`: set in the single-page variant to tell the next load to skip straight to the end widget.
27
+ * `?forceTPAStreamSdkEnd=1`: set in the single-page variant to flag the OAuth return. As of 0.8.2 the SDK shows a self-dismissing "Connected" toast in the floating panel and returns the member to the carrier picker (so they can add another carrier) rather than the full-page end widget. When `realTimeVerification: false` (no panel), it falls back to the end widget. The explicit `forceEndStep` init option is unaffected and still routes to the end widget.
28
28
 
29
29
  Both are stripped from the URL via `history.replaceState` so they cannot leak via browser history or autofill. See [Client Usage > Redirect query parameters](./client-usage.md#redirect-query-parameters-patient-access-api) for the full mechanics.
30
30
 
@@ -91,6 +91,12 @@ If you deliberately want the legacy fallthrough behavior — e.g. you're doing c
91
91
 
92
92
  If you use `renderChoosePayer={false}` / `renderPayerForm={false}` / `renderEndWidget={false}` and drive those steps from `doneChoosePayer` / `doneCreatedForm` / `doneEasyEnroll`, the data passed into your callbacks is unchanged.
93
93
 
94
+ ### 9. Host page must be HTTPS (0.8.2)
95
+
96
+ Starting in 0.8.2, `StreamConnect()` refuses to mount if the host page is served over plain `http://` from a non-loopback host. `localhost`, `127.0.0.1`, and `[::1]` are still allowed so local development is unaffected. Staging or internal hostnames served over plain HTTP are not.
97
+
98
+ If you embed the SDK in a member-facing page that's currently on plain HTTP, that page must move to HTTPS before 0.8.x will mount. See the [Origin Policy doc](https://developers.tpastream.com/connect/origin-policy) for the full rules, the exact console error developers will see, and how to fix it.
99
+
94
100
  ## What you do NOT need to do
95
101
 
96
102
  - You do not need to add a `theme` option. The default appearance applies automatically.
@@ -19,7 +19,7 @@ Here is what the test htmlscript looks like.
19
19
  ```
20
20
 
21
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.
22
+ `<script src="https://app.tpastream.com/static/js/sdk-v-0.8.1.js"></script>`. Pinned versions remain available indefinitely.
23
23
 
24
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
25
 
@@ -48,7 +48,7 @@ that an implementor starts the SDK init with `isDemo` set to true as shown above
48
48
  *Demo mode is incapable of saving credentials or validating credentials.
49
49
 
50
50
  If you then open up the above html in a browser you should see something close to the following.
51
- ![Demo Init Page](quickstart-screenshots/demo-init-page.png)
51
+ ![Demo Init Page](https://tpastream-public.s3.amazonaws.com/sdk-docs/quickstart-screenshots/demo-init-page.png)
52
52
 
53
53
  ## Step 3 -- Add sdk Token
54
54
  ```html
@@ -71,7 +71,7 @@ If you then open up the above html in a browser you should see something close t
71
71
  ```
72
72
 
73
73
  After setting the `sdkToken` you will see the following page on your html.
74
- ![Init Error Page](quickstart-screenshots/error-init-page.png)
74
+ ![Init Error Page](https://tpastream-public.s3.amazonaws.com/sdk-docs/quickstart-screenshots/error-init-page.png)
75
75
 
76
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
77
 
@@ -153,12 +153,12 @@ your current email.
153
153
  When implementing the SDK all carrier credentials will be nested under an employer in TPAStream. This block will define which
154
154
  employer your are interested in.
155
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.
156
+ To get the Key for an existing employer go to the [Employers Page](https://app.tpastream.com/d/employers) in the TPAStream Admin portal. From there search up the desired employer. Then enter the details page of said employer. From there open the **Support** tab.
157
157
 
158
158
  You will see a screen similar to this:
159
- ![Employer Key Page](quickstart-screenshots/employer-key-page.png)
159
+ ![Employer Key Page](https://tpastream-public.s3.amazonaws.com/webapp-docs/employers/employer-key-page.png)
160
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`.
161
+ The key field is labeled per-vendor — e.g. **Alegeus Key**, **OCA Key**, or simply **Key** depending on which integration the employer is attached to. Grab that value (in the screenshot it's `BBPGUIDE`) and put it into the `systemKey` config option in the employer object.
162
162
 
163
163
 
164
164
  # Step 6 -- Init
package/docs/sdk-flow.md CHANGED
@@ -7,7 +7,11 @@ This is the first widget to render on the page. It will appear as one of two for
7
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
8
 
9
9
  Here is what choose-payer might looks like (DISCLAIMER: All screenshots are configured in demo-mode and thus have incomplete data)
10
- ![Choose Payer](flow-screenshots/choose-payer.png)
10
+ ![Choose Payer](https://tpastream-public.s3.amazonaws.com/sdk-docs/flow-screenshots/choose-payer.png)
11
+
12
+ The dropdown variant looks like this when the listbox is open:
13
+
14
+ ![Choose Payer (dropdown)](https://tpastream-public.s3.amazonaws.com/sdk-docs/flow-screenshots/choose-payer-dropdown.png)
11
15
 
12
16
  ## Enter Credentials
13
17
  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.
@@ -17,15 +21,15 @@ The SDK will handle all the validation of the form. You can interface more thoro
17
21
  This widget is also home to some sub-widgets which have their own callbacks: `terms-of-service` and `pop-up`.
18
22
 
19
23
  Here is what a form might look like
20
- ![Enter Credentials](flow-screenshots/enter-credentials.png)
24
+ ![Enter Credentials](https://tpastream-public.s3.amazonaws.com/sdk-docs/flow-screenshots/enter-credentials.png)
21
25
 
22
26
  ## Enter Credentials Sub-Widgets
23
27
  #### Pop Up
24
28
  This widget is accessed by clicking the question mark on the page. This pop-up has a link to the carrier site.
25
- ![Pop Up](flow-screenshots/pop-up.png)
29
+ ![Pop Up](https://tpastream-public.s3.amazonaws.com/sdk-docs/flow-screenshots/pop-up.png)
26
30
  #### Terms of Service
27
31
  This widget contains the TPAStream terms of service
28
- ![Terms of Service](flow-screenshots/terms-of-service.png)
32
+ ![Terms of Service](https://tpastream-public.s3.amazonaws.com/sdk-docs/flow-screenshots/terms-of-service.png)
29
33
 
30
34
  ## Real Time Validation
31
35
 
@@ -37,7 +41,7 @@ State transitions arrive as they happen rather than on the 5-second polling cade
37
41
 
38
42
  `doneRealTime` still fires for back-compat. The `realtimeTimeout` init option is accepted but ignored (the timeout is now server-side).
39
43
 
40
- ![Realtime Validation](flow-screenshots/realtime-validation.png)
44
+ ![Realtime Validation](https://tpastream-public.s3.amazonaws.com/sdk-docs/flow-screenshots/realtime-validation.png)
41
45
 
42
46
  ## Done Easy Enroll
43
47
  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/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "stream-connect-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "A JavaScript SDK implementing TPAStream's Connect Platform",
5
5
  "scripts": {
6
6
  "build": "webpack --config webpack.prod-sdk.js --mode=production",
7
7
  "format": "biome check --write assets/",
8
8
  "test:lint": "biome check assets/",
9
9
  "test:types": "tsc --noEmit",
10
- "test": "npm run test:lint && npm run test:types"
10
+ "test": "npm run test:lint && npm run test:types",
11
+ "screenshots": "node scripts/screenshots/capture.mjs",
12
+ "screenshots:preview": "node scripts/screenshots/preview.mjs",
13
+ "screenshots:upload": "node scripts/screenshots/upload.mjs"
11
14
  },
12
15
  "repository": {
13
16
  "type": "git",
@@ -21,6 +24,7 @@
21
24
  "@babel/preset-react": "^7.27.1",
22
25
  "@babel/preset-typescript": "^7.27.1",
23
26
  "@biomejs/biome": "^1.9.4",
27
+ "@playwright/test": "^1.60.0",
24
28
  "@types/react": "^19.0.0",
25
29
  "@types/react-dom": "^19.0.0",
26
30
  "autoprefixer": "^10.4.21",
@@ -65,5 +69,8 @@
65
69
  "keywords": [
66
70
  "sdk"
67
71
  ],
68
- "license": "ISC"
72
+ "license": "ISC",
73
+ "engines": {
74
+ "node": ">=20"
75
+ }
69
76
  }