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.
@@ -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
- "name": "stream-connect-sdk",
3
- "version": "0.7.7",
4
- "description": "A JavaScript SDK implementing TPAStream's Connect Platform",
5
- "scripts": {
6
- "build": "webpack --config webpack.prod-sdk.js --mode=production",
7
- "format": "eslint --fix assets && prettier --write \"assets/*/*/**\"",
8
- "test:lint": "eslint assets && prettier --list-different \"assets/*/*/**\"",
9
- "test": "jest assets/tests/ --config=jest.config.js"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git@github.com:TPAStream/stream-connect-js-sdk.git"
14
- },
15
- "author": "TPAStreamOrg",
16
- "devDependencies": {
17
- "@babel/cli": "^7.13.16",
18
- "@babel/core": "^7.4.5",
19
- "@babel/plugin-proposal-class-properties": "^7.4.4",
20
- "@babel/plugin-proposal-optional-chaining": "^7.6.0",
21
- "@babel/polyfill": "^7.4.4",
22
- "@babel/preset-env": "^7.4.5",
23
- "@babel/preset-react": "^7.0.0",
24
- "babel-cli": "^6.26.0",
25
- "babel-core": "^6.26.3",
26
- "babel-eslint": "^10.0.1",
27
- "babel-loader": "^8.0.6",
28
- "babel-plugin-transform-object-rest-spread": "^6.26.0",
29
- "babel-plugin-transform-react-jsx": "^6.24.1",
30
- "babel-preset-env": "^1.7.0",
31
- "brfs": "^2.0.2",
32
- "chai": "^4.2.0",
33
- "chai-as-promised": "^7.1.1",
34
- "dompurify": "^2.4.0",
35
- "es5-shim": "^4.5.13",
36
- "eslint": "^5.16.0",
37
- "eslint-plugin-react": "^7.13.0",
38
- "jest": "^26.6.3",
39
- "marked": "^4.1.0",
40
- "prettier": "^1.18.2",
41
- "sinon": "^7.3.2",
42
- "sinon-chai": "^3.3.0",
43
- "transform-loader": "^0.2.3",
44
- "webpack": "^5.74.0",
45
- "webpack-cli": "^4.10.0",
46
- "webpack-merge": "^4.2.2"
47
- },
48
- "dependencies": {
49
- "@fortawesome/free-solid-svg-icons": "^5.13.0",
50
- "@fortawesome/react-fontawesome": "^0.1.6",
51
- "axios": "^1.7.9",
52
- "font-awesome": "^4.7.0",
53
- "query-string": "^6.6.0",
54
- "react": "^16.11.0",
55
- "react-dom": "^16.8.6",
56
- "react-highlight-words": "^0.16.0",
57
- "react-jsonschema-form": "^1.6.0",
58
- "react-popup": "^0.10.0",
59
- "react-select": "^3.0.4",
60
- "regenerator-runtime": "^0.13.7"
61
- },
62
- "prettier": {
63
- "tabWidth": 2,
64
- "useTabs": false,
65
- "semi": true,
66
- "singleQuote": true,
67
- "trailingComma": "none",
68
- "bracketSpacing": true,
69
- "arrowParens": "avoid"
70
- },
71
- "bugs": {
72
- "url": "https://github.com/TPAStream/stream-connect-js-sdk/issues"
73
- },
74
- "homepage": "https://github.com/TPAStream/stream-connect-js-sdk#readme",
75
- "main": "sdk.js",
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
  }