@userflow-tech/react-native 0.1.0 → 0.1.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/README.md +24 -14
- package/app.plugin.js +3 -0
- package/babel-plugin/index.d.ts +43 -0
- package/babel-plugin/index.d.ts.map +1 -0
- package/babel-plugin/index.js +854 -0
- package/babel-plugin/index.js.map +1 -0
- package/docs/deep-linking.md +2 -2
- package/docs/troubleshooting.md +2 -2
- package/expo-plugin/withUserflow.d.ts +17 -0
- package/expo-plugin/withUserflow.d.ts.map +1 -0
- package/expo-plugin/withUserflow.js +99 -0
- package/expo-plugin/withUserflow.js.map +1 -0
- package/lib/commonjs/anchors/AutoAnchorRegistry.js +1 -1
- package/lib/commonjs/anchors/autoAnchor.js +1 -1
- package/lib/commonjs/anchors/hintsCodec.js +1 -1
- package/lib/commonjs/pairing/diagnostics.js +2 -2
- package/lib/commonjs/pairing/diagnostics.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/anchors/AutoAnchorRegistry.js +1 -1
- package/lib/module/anchors/autoAnchor.js +1 -1
- package/lib/module/anchors/hintsCodec.js +1 -1
- package/lib/module/pairing/diagnostics.js +2 -2
- package/lib/module/pairing/diagnostics.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/commonjs/src/anchors/AutoAnchorRegistry.d.ts +1 -1
- package/lib/typescript/commonjs/src/anchors/AutoAnchorRegistry.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/anchors/autoAnchor.d.ts +1 -1
- package/lib/typescript/commonjs/src/anchors/hintsCodec.d.ts +1 -1
- package/lib/typescript/commonjs/src/version.d.ts +1 -1
- package/lib/typescript/module/src/anchors/AutoAnchorRegistry.d.ts +1 -1
- package/lib/typescript/module/src/anchors/AutoAnchorRegistry.d.ts.map +1 -1
- package/lib/typescript/module/src/anchors/autoAnchor.d.ts +1 -1
- package/lib/typescript/module/src/anchors/hintsCodec.d.ts +1 -1
- package/lib/typescript/module/src/version.d.ts +1 -1
- package/package.json +15 -7
- package/src/anchors/AutoAnchorRegistry.ts +1 -1
- package/src/anchors/autoAnchor.ts +1 -1
- package/src/anchors/hintsCodec.ts +1 -1
- package/src/pairing/diagnostics.ts +2 -2
- package/src/version.ts +1 -1
- package/vendor/core/LICENSE +76 -0
- package/vendor/core/README.md +9 -0
- package/vendor/core/dist/attributes.d.ts +16 -0
- package/vendor/core/dist/attributes.d.ts.map +1 -0
- package/vendor/core/dist/attributes.js +55 -0
- package/vendor/core/dist/attributes.js.map +1 -0
- package/vendor/core/dist/constants.d.ts +21 -0
- package/vendor/core/dist/constants.d.ts.map +1 -0
- package/vendor/core/dist/constants.js +21 -0
- package/vendor/core/dist/constants.js.map +1 -0
- package/vendor/core/dist/engine/ClientConditionEngine.d.ts +68 -0
- package/vendor/core/dist/engine/ClientConditionEngine.d.ts.map +1 -0
- package/vendor/core/dist/engine/ClientConditionEngine.js +197 -0
- package/vendor/core/dist/engine/ClientConditionEngine.js.map +1 -0
- package/vendor/core/dist/engine/FlowSessionEngine.d.ts +92 -0
- package/vendor/core/dist/engine/FlowSessionEngine.d.ts.map +1 -0
- package/vendor/core/dist/engine/FlowSessionEngine.js +310 -0
- package/vendor/core/dist/engine/FlowSessionEngine.js.map +1 -0
- package/vendor/core/dist/engine/PairingEngine.d.ts +92 -0
- package/vendor/core/dist/engine/PairingEngine.d.ts.map +1 -0
- package/vendor/core/dist/engine/PairingEngine.js +302 -0
- package/vendor/core/dist/engine/PairingEngine.js.map +1 -0
- package/vendor/core/dist/engine/UserflowCore.d.ts +126 -0
- package/vendor/core/dist/engine/UserflowCore.d.ts.map +1 -0
- package/vendor/core/dist/engine/UserflowCore.js +266 -0
- package/vendor/core/dist/engine/UserflowCore.js.map +1 -0
- package/vendor/core/dist/engine/handleActions.d.ts +19 -0
- package/vendor/core/dist/engine/handleActions.d.ts.map +1 -0
- package/vendor/core/dist/engine/handleActions.js +71 -0
- package/vendor/core/dist/engine/handleActions.js.map +1 -0
- package/vendor/core/dist/engine/interpolateSessionData.d.ts +7 -0
- package/vendor/core/dist/engine/interpolateSessionData.d.ts.map +1 -0
- package/vendor/core/dist/engine/interpolateSessionData.js +29 -0
- package/vendor/core/dist/engine/interpolateSessionData.js.map +1 -0
- package/vendor/core/dist/errors.d.ts +9 -0
- package/vendor/core/dist/errors.d.ts.map +1 -0
- package/vendor/core/dist/errors.js +15 -0
- package/vendor/core/dist/errors.js.map +1 -0
- package/vendor/core/dist/eventAttributes.d.ts +7 -0
- package/vendor/core/dist/eventAttributes.d.ts.map +1 -0
- package/vendor/core/dist/eventAttributes.js +31 -0
- package/vendor/core/dist/eventAttributes.js.map +1 -0
- package/vendor/core/dist/index.d.ts +30 -0
- package/vendor/core/dist/index.d.ts.map +1 -0
- package/vendor/core/dist/index.js +21 -0
- package/vendor/core/dist/index.js.map +1 -0
- package/vendor/core/dist/transport/backoff.d.ts +11 -0
- package/vendor/core/dist/transport/backoff.d.ts.map +1 -0
- package/vendor/core/dist/transport/backoff.js +17 -0
- package/vendor/core/dist/transport/backoff.js.map +1 -0
- package/vendor/core/dist/transport/pairing.d.ts +121 -0
- package/vendor/core/dist/transport/pairing.d.ts.map +1 -0
- package/vendor/core/dist/transport/pairing.js +551 -0
- package/vendor/core/dist/transport/pairing.js.map +1 -0
- package/vendor/core/dist/transport/phoenix.d.ts +223 -0
- package/vendor/core/dist/transport/phoenix.d.ts.map +1 -0
- package/vendor/core/dist/transport/phoenix.js +757 -0
- package/vendor/core/dist/transport/phoenix.js.map +1 -0
- package/vendor/core/dist/transport/rateLimiter.d.ts +17 -0
- package/vendor/core/dist/transport/rateLimiter.d.ts.map +1 -0
- package/vendor/core/dist/transport/rateLimiter.js +30 -0
- package/vendor/core/dist/transport/rateLimiter.js.map +1 -0
- package/vendor/core/dist/transport/scheduler.d.ts +12 -0
- package/vendor/core/dist/transport/scheduler.d.ts.map +1 -0
- package/vendor/core/dist/transport/scheduler.js +11 -0
- package/vendor/core/dist/transport/scheduler.js.map +1 -0
- package/vendor/core/dist/types.d.ts +35 -0
- package/vendor/core/dist/types.d.ts.map +1 -0
- package/vendor/core/dist/types.js +2 -0
- package/vendor/core/dist/types.js.map +1 -0
- package/vendor/core/dist/version.d.ts +3 -0
- package/vendor/core/dist/version.d.ts.map +1 -0
- package/vendor/core/dist/version.js +3 -0
- package/vendor/core/dist/version.js.map +1 -0
- package/vendor/core/package.json +20 -0
- package/vendor/protocol/LICENSE +76 -0
- package/vendor/protocol/README.md +8 -0
- package/vendor/protocol/dist/autoData.d.ts +232 -0
- package/vendor/protocol/dist/autoData.d.ts.map +1 -0
- package/vendor/protocol/dist/autoData.js +78 -0
- package/vendor/protocol/dist/autoData.js.map +1 -0
- package/vendor/protocol/dist/events.d.ts +16 -0
- package/vendor/protocol/dist/events.d.ts.map +1 -0
- package/vendor/protocol/dist/events.js +8 -0
- package/vendor/protocol/dist/events.js.map +1 -0
- package/vendor/protocol/dist/flows.d.ts +298 -0
- package/vendor/protocol/dist/flows.d.ts.map +1 -0
- package/vendor/protocol/dist/flows.js +154 -0
- package/vendor/protocol/dist/flows.js.map +1 -0
- package/vendor/protocol/dist/index.d.ts +24 -0
- package/vendor/protocol/dist/index.d.ts.map +1 -0
- package/vendor/protocol/dist/index.js +16 -0
- package/vendor/protocol/dist/index.js.map +1 -0
- package/vendor/protocol/dist/messages.d.ts +166 -0
- package/vendor/protocol/dist/messages.d.ts.map +1 -0
- package/vendor/protocol/dist/messages.js +57 -0
- package/vendor/protocol/dist/messages.js.map +1 -0
- package/vendor/protocol/dist/pairing.d.ts +56 -0
- package/vendor/protocol/dist/pairing.d.ts.map +1 -0
- package/vendor/protocol/dist/pairing.js +146 -0
- package/vendor/protocol/dist/pairing.js.map +1 -0
- package/vendor/protocol/package.json +17 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { EndFlowReasonInput, TooltipMissingBehavior } from '@userflow-tech/protocol';
|
|
2
|
+
import { UserflowAuthError } from '../errors.js';
|
|
3
|
+
import { defaultScheduler } from '../transport/scheduler.js';
|
|
4
|
+
import { handleActions } from './handleActions.js';
|
|
5
|
+
/** Cap for in-memory client-message retry after transport failure. */
|
|
6
|
+
const MAX_PENDING_SENDS = 20;
|
|
7
|
+
function isValidFlowSession(session) {
|
|
8
|
+
if (session == null || typeof session !== 'object')
|
|
9
|
+
return false;
|
|
10
|
+
const candidate = session;
|
|
11
|
+
if (typeof candidate.id !== 'string' || candidate.id.length === 0)
|
|
12
|
+
return false;
|
|
13
|
+
if (candidate.version == null || typeof candidate.version !== 'object')
|
|
14
|
+
return false;
|
|
15
|
+
if (!Array.isArray(candidate.version.steps))
|
|
16
|
+
return false;
|
|
17
|
+
if (candidate.currentStep == null || typeof candidate.currentStep !== 'object')
|
|
18
|
+
return false;
|
|
19
|
+
if (typeof candidate.currentStep.id !== 'string' || candidate.currentStep.id.length === 0) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Framework-agnostic flow session state machine (Phase 3 WS2).
|
|
26
|
+
*
|
|
27
|
+
* Ports web `userflow-client` session/clock/wait-timer semantics onto the
|
|
28
|
+
* Phoenix transport seam. Call {@link attach} after identify.
|
|
29
|
+
*/
|
|
30
|
+
export class FlowSessionEngine {
|
|
31
|
+
constructor(deps) {
|
|
32
|
+
this.clientClock = 1;
|
|
33
|
+
this.serverClock = 1;
|
|
34
|
+
this.flowSessionClock = 0;
|
|
35
|
+
this.flowSession = null;
|
|
36
|
+
this.listeners = new Set();
|
|
37
|
+
this.conditionWaitTimers = new Map();
|
|
38
|
+
this.pendingSends = [];
|
|
39
|
+
this.flushingPending = false;
|
|
40
|
+
this.unsubscribeServerMessages = null;
|
|
41
|
+
this.transport = deps.transport;
|
|
42
|
+
this.onOpenExternalUrl = deps.onOpenExternalUrl;
|
|
43
|
+
this.warn = deps.warn ?? ((message) => console.warn(message));
|
|
44
|
+
this.scheduler = deps.scheduler ?? defaultScheduler;
|
|
45
|
+
}
|
|
46
|
+
/** Subscribe to inbound server messages. Must be called after identify. */
|
|
47
|
+
attach() {
|
|
48
|
+
this.detach();
|
|
49
|
+
this.unsubscribeServerMessages = this.transport.onServerMessage((message) => {
|
|
50
|
+
this.handleServerMessage(message);
|
|
51
|
+
});
|
|
52
|
+
void this.flushPendingSends();
|
|
53
|
+
return () => this.detach();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Unsubscribe from server messages and clear wait timers (keeps session state).
|
|
57
|
+
* Note: in-flight condition wait timers are dropped and not restarted on
|
|
58
|
+
* re-attach; the server must send StartConditionWaitTimer again if needed.
|
|
59
|
+
*/
|
|
60
|
+
detach() {
|
|
61
|
+
this.unsubscribeServerMessages?.();
|
|
62
|
+
this.unsubscribeServerMessages = null;
|
|
63
|
+
this.clearConditionWaitTimers();
|
|
64
|
+
}
|
|
65
|
+
on(listener) {
|
|
66
|
+
this.listeners.add(listener);
|
|
67
|
+
return () => {
|
|
68
|
+
this.listeners.delete(listener);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
getFlowSession() {
|
|
72
|
+
return this.flowSession;
|
|
73
|
+
}
|
|
74
|
+
getCurrentStep() {
|
|
75
|
+
const session = this.flowSession;
|
|
76
|
+
if (!session?.currentStep)
|
|
77
|
+
return null;
|
|
78
|
+
return session.version.steps.find((step) => step.id === session.currentStep.id) ?? null;
|
|
79
|
+
}
|
|
80
|
+
/** Visible for tests / advanced callers; prefer {@link attach}. */
|
|
81
|
+
handleServerMessage(message) {
|
|
82
|
+
switch (message.kind) {
|
|
83
|
+
case 'SetFlowSession': {
|
|
84
|
+
if (!isValidFlowSession(message.session)) {
|
|
85
|
+
this.warn('Userflow: ignoring malformed SetFlowSession (missing id/version.steps/currentStep)');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (this.flowSessionClock <= this.serverClock ||
|
|
89
|
+
this.flowSession?.id === message.session.id) {
|
|
90
|
+
this.setFlowSession(message.session, this.serverClock);
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
case 'UnsetFlowSession': {
|
|
95
|
+
if (this.flowSessionClock > this.serverClock)
|
|
96
|
+
return;
|
|
97
|
+
if (this.flowSession?.id === message.sessionId) {
|
|
98
|
+
this.setFlowSession(null, this.serverClock);
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
case 'ForceGoToStep': {
|
|
103
|
+
// Matches web: emit only — does not update session.currentStep.
|
|
104
|
+
// getCurrentStep() stays stale until a later SetFlowSession; UI must
|
|
105
|
+
// resolve the step from this event (or wait for SetFlowSession).
|
|
106
|
+
if (this.flowSessionClock > this.serverClock)
|
|
107
|
+
return;
|
|
108
|
+
if (this.flowSession?.id === message.sessionId) {
|
|
109
|
+
this.emit({
|
|
110
|
+
type: 'goToStep',
|
|
111
|
+
sessionId: message.sessionId,
|
|
112
|
+
stepId: message.stepId,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
case 'StartConditionWaitTimer': {
|
|
118
|
+
this.startConditionWaitTimer(message.conditionId, message.waitTime);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
case 'CancelConditionWaitTimer': {
|
|
122
|
+
this.cancelConditionWaitTimer(message.conditionId);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
case 'TrackClientCondition':
|
|
126
|
+
case 'UntrackClientCondition':
|
|
127
|
+
// Handled by ClientConditionEngine (separate subscriber).
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async goToStep(step) {
|
|
132
|
+
const session = this.requireFlowSession();
|
|
133
|
+
const promise = this.sendTracked({
|
|
134
|
+
kind: 'GoToStep',
|
|
135
|
+
sessionId: session.id,
|
|
136
|
+
stepId: step.id,
|
|
137
|
+
});
|
|
138
|
+
// Mutates the live session object already emitted via sessionChange.
|
|
139
|
+
// Listeners that hold that reference and only re-render on sessionChange
|
|
140
|
+
// will not see this update — they must also handle the goToStep event
|
|
141
|
+
// (or we should clone before mutating in a later pass).
|
|
142
|
+
session.currentStep = { id: step.id, crossVersionId: step.crossVersionId };
|
|
143
|
+
this.emit({ type: 'goToStep', sessionId: session.id, stepId: step.id });
|
|
144
|
+
await promise;
|
|
145
|
+
}
|
|
146
|
+
async endFlow(endReason) {
|
|
147
|
+
const session = this.requireFlowSession();
|
|
148
|
+
const sessionId = session.id;
|
|
149
|
+
const flowId = session.flow.id;
|
|
150
|
+
this.optimisticClockUIUpdate(() => {
|
|
151
|
+
if (this.flowSession?.id === sessionId) {
|
|
152
|
+
this.setFlowSession(null, this.clientClock);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
this.emit({ type: 'flowEnded', flowId, endReason });
|
|
156
|
+
await this.sendTracked({
|
|
157
|
+
kind: 'EndFlow',
|
|
158
|
+
sessionId,
|
|
159
|
+
endReason,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async reportTooltipTargetMissing(stepId) {
|
|
163
|
+
const session = this.requireFlowSession();
|
|
164
|
+
await this.sendTracked({
|
|
165
|
+
kind: 'ReportTooltipTargetMissing',
|
|
166
|
+
sessionId: session.id,
|
|
167
|
+
stepId,
|
|
168
|
+
});
|
|
169
|
+
const theme = session.version.theme;
|
|
170
|
+
if (theme.tooltipMissingBehavior === TooltipMissingBehavior.END && !session.draftMode) {
|
|
171
|
+
await this.endFlow(EndFlowReasonInput.TOOLTIP_TARGET_MISSING);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
handleActions(actions) {
|
|
175
|
+
const session = this.requireFlowSession();
|
|
176
|
+
return handleActions(session, actions, {
|
|
177
|
+
engine: this,
|
|
178
|
+
...(this.onOpenExternalUrl !== undefined
|
|
179
|
+
? { onOpenExternalUrl: this.onOpenExternalUrl }
|
|
180
|
+
: {}),
|
|
181
|
+
warn: this.warn,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Clear the local flow session and join resume id without detaching from
|
|
186
|
+
* server messages. Used when a long background makes mid-flow resume stale.
|
|
187
|
+
*/
|
|
188
|
+
clearLocalSession() {
|
|
189
|
+
this.clearConditionWaitTimers();
|
|
190
|
+
if (this.flowSession !== null) {
|
|
191
|
+
this.flowSession = null;
|
|
192
|
+
this.transport.setFlowSessionId(null);
|
|
193
|
+
this.emit({ type: 'sessionChange', session: null });
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
this.transport.setFlowSessionId(null);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** Clear session, clocks, timers, pending sends, and join resume id; detach from transport. */
|
|
200
|
+
reset() {
|
|
201
|
+
this.detach();
|
|
202
|
+
this.clientClock = 1;
|
|
203
|
+
this.serverClock = 1;
|
|
204
|
+
this.flowSessionClock = 0;
|
|
205
|
+
this.pendingSends.length = 0;
|
|
206
|
+
this.clearLocalSession();
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Flush client messages queued after transport failure.
|
|
210
|
+
* Call after reconnect / lifecycle resume (`ensureConnected` path).
|
|
211
|
+
*/
|
|
212
|
+
async flushPendingSends() {
|
|
213
|
+
if (this.flushingPending || this.pendingSends.length === 0)
|
|
214
|
+
return;
|
|
215
|
+
this.flushingPending = true;
|
|
216
|
+
try {
|
|
217
|
+
while (this.pendingSends.length > 0) {
|
|
218
|
+
const message = this.pendingSends[0];
|
|
219
|
+
try {
|
|
220
|
+
await this.transport.send(message);
|
|
221
|
+
this.pendingSends.shift();
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
// Keep the head (and rest) queued until the next successful reconnect.
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
this.flushingPending = false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** @internal Test helper. */
|
|
234
|
+
getPendingSendCountForTests() {
|
|
235
|
+
return this.pendingSends.length;
|
|
236
|
+
}
|
|
237
|
+
setFlowSession(session, clock) {
|
|
238
|
+
this.flowSession = session;
|
|
239
|
+
this.flowSessionClock = clock;
|
|
240
|
+
this.transport.setFlowSessionId(session?.id ?? null);
|
|
241
|
+
this.emit({ type: 'sessionChange', session });
|
|
242
|
+
}
|
|
243
|
+
optimisticClockUIUpdate(callback) {
|
|
244
|
+
this.clientClock += 1;
|
|
245
|
+
callback();
|
|
246
|
+
}
|
|
247
|
+
enqueuePendingSend(message) {
|
|
248
|
+
if (this.pendingSends.length >= MAX_PENDING_SENDS) {
|
|
249
|
+
this.pendingSends.shift();
|
|
250
|
+
}
|
|
251
|
+
this.pendingSends.push(message);
|
|
252
|
+
}
|
|
253
|
+
async sendTracked(message) {
|
|
254
|
+
const clock = this.clientClock;
|
|
255
|
+
try {
|
|
256
|
+
await this.transport.send(message);
|
|
257
|
+
void this.flushPendingSends();
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
this.enqueuePendingSend(message);
|
|
261
|
+
this.warn(`Userflow: failed to send ${message.kind}; queued for retry on reconnect`);
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
this.serverClock = clock;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
startConditionWaitTimer(conditionId, waitTime) {
|
|
268
|
+
if (this.conditionWaitTimers.has(conditionId))
|
|
269
|
+
return;
|
|
270
|
+
const ms = parseFloat(waitTime) * 1000;
|
|
271
|
+
const handle = this.scheduler.setTimeout(() => {
|
|
272
|
+
this.conditionWaitTimers.delete(conditionId);
|
|
273
|
+
void this.sendTracked({
|
|
274
|
+
kind: 'FireConditionWaitTimer',
|
|
275
|
+
conditionId,
|
|
276
|
+
});
|
|
277
|
+
}, Number.isFinite(ms) ? Math.max(0, ms) : 0);
|
|
278
|
+
this.conditionWaitTimers.set(conditionId, handle);
|
|
279
|
+
}
|
|
280
|
+
cancelConditionWaitTimer(conditionId) {
|
|
281
|
+
const handle = this.conditionWaitTimers.get(conditionId);
|
|
282
|
+
if (handle === undefined)
|
|
283
|
+
return;
|
|
284
|
+
this.scheduler.clearTimeout(handle);
|
|
285
|
+
this.conditionWaitTimers.delete(conditionId);
|
|
286
|
+
}
|
|
287
|
+
clearConditionWaitTimers() {
|
|
288
|
+
for (const handle of this.conditionWaitTimers.values()) {
|
|
289
|
+
this.scheduler.clearTimeout(handle);
|
|
290
|
+
}
|
|
291
|
+
this.conditionWaitTimers.clear();
|
|
292
|
+
}
|
|
293
|
+
requireFlowSession() {
|
|
294
|
+
if (!this.flowSession) {
|
|
295
|
+
throw new UserflowAuthError('No active flow session');
|
|
296
|
+
}
|
|
297
|
+
return this.flowSession;
|
|
298
|
+
}
|
|
299
|
+
emit(event) {
|
|
300
|
+
for (const listener of this.listeners) {
|
|
301
|
+
try {
|
|
302
|
+
listener(event);
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
// Never let a subscriber break the engine.
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=FlowSessionEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlowSessionEngine.js","sourceRoot":"","sources":["../../src/engine/FlowSessionEngine.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAErF,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAoC,MAAM,2BAA2B,CAAC;AAE/F,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,sEAAsE;AACtE,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAwB7B,SAAS,kBAAkB,CAAC,OAAgB;IAC1C,IAAI,OAAO,IAAI,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACjE,MAAM,SAAS,GAAG,OAAu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KAAK,EAAE,CAAC;IACnC,CAAC;IAEO,kBAAkB;QACxB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAEO,IAAI,CAAC,KAA6B;QACxC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;YAAC,MAAM,CAAC;gBACP,2CAA2C;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ClientMessage, ServerMessage } from '@userflow-tech/protocol';
|
|
2
|
+
import { PairingConnection, type PairingConnectionOptions } from '../transport/pairing.js';
|
|
3
|
+
export type PairingEngineStatus = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'token_expired' | 'device_already_paired' | 'error';
|
|
4
|
+
export interface PairingEngineState {
|
|
5
|
+
status: PairingEngineStatus;
|
|
6
|
+
pairingId: string | null;
|
|
7
|
+
deviceId: string | null;
|
|
8
|
+
previewActive: boolean;
|
|
9
|
+
lastError: string | null;
|
|
10
|
+
/** True when a re-scan is required (expired token or hard failure). */
|
|
11
|
+
needsRescan: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* True while the server waits for the previewed flow's start condition to
|
|
14
|
+
* match (the `TestStartCondition` preview mode). The preview is live but the
|
|
15
|
+
* flow has not appeared yet, which is otherwise indistinguishable from a
|
|
16
|
+
* condition that never fires.
|
|
17
|
+
*/
|
|
18
|
+
awaitingStartCondition: boolean;
|
|
19
|
+
}
|
|
20
|
+
export type PairingEngineListener = (state: PairingEngineState) => void;
|
|
21
|
+
export interface PairingEngineDeps {
|
|
22
|
+
/** Send a client message on the end-user channel (after identify). */
|
|
23
|
+
sendClientMessage: (message: ClientMessage) => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Subscribe to inbound end-user server messages, returning an unsubscribe.
|
|
26
|
+
* Only used to notice `TestStartConditionSuccess`. Subscribed lazily because
|
|
27
|
+
* the end-user channel does not exist until identify, while pairing starts
|
|
28
|
+
* before it.
|
|
29
|
+
*/
|
|
30
|
+
onServerMessage?: (handler: (message: ServerMessage) => void) => () => void;
|
|
31
|
+
/** Whether an end-user identity is currently active. */
|
|
32
|
+
isIdentified: () => boolean;
|
|
33
|
+
/** Optional device metadata included on pairing join. */
|
|
34
|
+
deviceMeta?: () => {
|
|
35
|
+
model?: string;
|
|
36
|
+
os?: string;
|
|
37
|
+
app_version?: string;
|
|
38
|
+
};
|
|
39
|
+
pairingOptions?: PairingConnectionOptions;
|
|
40
|
+
createConnection?: (options: PairingConnectionOptions) => PairingConnection;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Orchestrates a pairing session: connect/join the pairing socket, bridge
|
|
44
|
+
* `startFlowWithToken` onto the end-user channel, and expose preview-mode state.
|
|
45
|
+
*/
|
|
46
|
+
export declare class PairingEngine {
|
|
47
|
+
private connection;
|
|
48
|
+
private unsubscribe;
|
|
49
|
+
private state;
|
|
50
|
+
private readonly listeners;
|
|
51
|
+
private pendingStartTokens;
|
|
52
|
+
/** True while the server is waiting on a start condition (see TestStartCondition). */
|
|
53
|
+
private testingStartCondition;
|
|
54
|
+
private startConditionUnsub;
|
|
55
|
+
private readonly deps;
|
|
56
|
+
constructor(deps: PairingEngineDeps);
|
|
57
|
+
getState(): PairingEngineState;
|
|
58
|
+
isPreviewActive(): boolean;
|
|
59
|
+
onStateChange(listener: PairingEngineListener): () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Begin (or replace) a pairing session with a JWT from a deep link.
|
|
62
|
+
* Closes any existing pairing websocket first (warm re-scan).
|
|
63
|
+
*/
|
|
64
|
+
start(pairingToken: string): Promise<void>;
|
|
65
|
+
/** Exit preview: disconnect pairing and clear queued preview tokens. */
|
|
66
|
+
stop(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Listen for the server confirming the tested start condition matched. Called
|
|
69
|
+
* only after a `TestStartCondition` send succeeded, which means the end-user
|
|
70
|
+
* channel exists and subscribing is safe.
|
|
71
|
+
*/
|
|
72
|
+
private watchStartCondition;
|
|
73
|
+
private unwatchStartCondition;
|
|
74
|
+
/**
|
|
75
|
+
* The tested start condition matched, so the flow is now on screen. Stops the
|
|
76
|
+
* waiting state and makes `stop()` skip a cancel the server no longer needs.
|
|
77
|
+
*/
|
|
78
|
+
private notifyStartConditionMatched;
|
|
79
|
+
/**
|
|
80
|
+
* Call after end-user identify so queued `startFlowWithToken` relays can flush.
|
|
81
|
+
*/
|
|
82
|
+
notifyIdentified(): void;
|
|
83
|
+
ensureAlive(): void;
|
|
84
|
+
private handleConnectionEvent;
|
|
85
|
+
private handleStartFlowWithToken;
|
|
86
|
+
private flushPendingStartTokens;
|
|
87
|
+
private deliverStartFlowWithToken;
|
|
88
|
+
private pushStartResult;
|
|
89
|
+
private teardownConnection;
|
|
90
|
+
private setState;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=PairingEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PairingEngine.d.ts","sourceRoot":"","sources":["../../src/engine/PairingEngine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EAEd,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,iBAAiB,EAEjB,KAAK,wBAAwB,EAC9B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,mBAAmB,GAC3B,MAAM,GACN,YAAY,GACZ,WAAW,GACX,cAAc,GACd,eAAe,GACf,uBAAuB,GACvB,OAAO,CAAC;AAEZ,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG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