stream-connect-sdk 0.7.7 → 0.8.1
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 +319 -0
- package/README.md +89 -133
- package/docs/README.md +52 -0
- package/docs/client-usage.md +489 -0
- package/docs/connect-access-token-screenshots/connect-access-token-pattern.png +0 -0
- package/docs/connect-access-token.md +207 -0
- package/docs/error.md +149 -0
- package/docs/faq.md +77 -0
- package/docs/fix-credentials.md +157 -0
- package/docs/flow-screenshots/realtime-validation.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/employer-key-page.png +0 -0
- package/docs/quickstart.md +247 -0
- package/docs/sdk-flow.md +47 -0
- package/docs/theme.md +47 -0
- package/docs/two-factor.md +137 -0
- package/package.json +74 -78
- package/sdk-headless.js +2 -0
- package/sdk.js +1 -1
- package/.babelrc +0 -4
- package/.rgignore +0 -1
|
@@ -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,80 +1,76 @@
|
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
"keywords": [
|
|
77
|
-
"sdk"
|
|
78
|
-
],
|
|
79
|
-
"license": "ISC"
|
|
2
|
+
"name": "stream-connect-sdk",
|
|
3
|
+
"version": "0.8.1",
|
|
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
|
+
"screenshots": "node scripts/screenshots/capture.mjs",
|
|
12
|
+
"screenshots:preview": "node scripts/screenshots/preview.mjs",
|
|
13
|
+
"screenshots:upload": "node scripts/screenshots/upload.mjs"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git@github.com:TPAStream/stream-connect-js-sdk.git"
|
|
18
|
+
},
|
|
19
|
+
"author": "TPAStreamOrg",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@babel/cli": "^7.27.1",
|
|
22
|
+
"@babel/core": "^7.27.1",
|
|
23
|
+
"@babel/preset-env": "^7.27.1",
|
|
24
|
+
"@babel/preset-react": "^7.27.1",
|
|
25
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
26
|
+
"@biomejs/biome": "^1.9.4",
|
|
27
|
+
"@playwright/test": "^1.60.0",
|
|
28
|
+
"@types/react": "^19.0.0",
|
|
29
|
+
"@types/react-dom": "^19.0.0",
|
|
30
|
+
"autoprefixer": "^10.4.21",
|
|
31
|
+
"babel-loader": "^9.2.1",
|
|
32
|
+
"css-loader": "^7.1.2",
|
|
33
|
+
"postcss": "^8.5.3",
|
|
34
|
+
"postcss-loader": "^8.1.1",
|
|
35
|
+
"style-loader": "^4.0.0",
|
|
36
|
+
"tailwindcss": "^3.4.17",
|
|
37
|
+
"typescript": "^5.7.3",
|
|
38
|
+
"webpack": "^5.99.5",
|
|
39
|
+
"webpack-cli": "^6.0.1",
|
|
40
|
+
"webpack-merge": "^6.0.1"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@headlessui/react": "^2.2.0",
|
|
44
|
+
"@hookform/resolvers": "^3.10.0",
|
|
45
|
+
"axios": "^1.7.9",
|
|
46
|
+
"dompurify": "^3.2.4",
|
|
47
|
+
"marked": "^15.0.7",
|
|
48
|
+
"react": "^19.0.0",
|
|
49
|
+
"react-dom": "^19.0.0",
|
|
50
|
+
"react-hook-form": "^7.54.2",
|
|
51
|
+
"zod": "^3.24.2"
|
|
52
|
+
},
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/TPAStream/stream-connect-js-sdk/issues"
|
|
55
|
+
},
|
|
56
|
+
"homepage": "https://github.com/TPAStream/stream-connect-js-sdk#readme",
|
|
57
|
+
"main": "sdk.js",
|
|
58
|
+
"exports": {
|
|
59
|
+
".": "./sdk.js",
|
|
60
|
+
"./headless": "./sdk-headless.js"
|
|
61
|
+
},
|
|
62
|
+
"files": [
|
|
63
|
+
"sdk.js",
|
|
64
|
+
"sdk-headless.js",
|
|
65
|
+
"README.md",
|
|
66
|
+
"CHANGELOG.md",
|
|
67
|
+
"docs/"
|
|
68
|
+
],
|
|
69
|
+
"keywords": [
|
|
70
|
+
"sdk"
|
|
71
|
+
],
|
|
72
|
+
"license": "ISC",
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": ">=20"
|
|
75
|
+
}
|
|
80
76
|
}
|