@fanfare-io/fanfare-sdk-core 0.2.0 → 0.4.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.
Files changed (53) hide show
  1. package/dist/appointments/appointment.driver.d.ts +44 -0
  2. package/dist/appointments/appointment.driver.js +1 -0
  3. package/dist/appointments/appointment.sequence.d.ts +194 -0
  4. package/dist/auctions/auction.driver.d.ts +46 -0
  5. package/dist/auctions/auction.driver.js +1 -0
  6. package/dist/auctions/auction.module.js +1 -1
  7. package/dist/auctions/auction.sequence.d.ts +263 -0
  8. package/dist/core/client.js +1 -1
  9. package/dist/draws/draw.driver.d.ts +45 -0
  10. package/dist/draws/draw.driver.js +1 -0
  11. package/dist/draws/draw.module.js +1 -1
  12. package/dist/draws/draw.sequence.d.ts +249 -0
  13. package/dist/experiences/distribution-monitor.types.d.ts +92 -2
  14. package/dist/experiences/experience.module.js +1 -1
  15. package/dist/experiences/journey-view.d.ts +8 -10
  16. package/dist/experiences/journey-view.js +1 -1
  17. package/dist/experiences/journey.d.ts +45 -20
  18. package/dist/experiences/journey.js +1 -1
  19. package/dist/experiences/journey.machine.d.ts +3 -20
  20. package/dist/experiences/journey.machine.js +1 -1
  21. package/dist/experiences/journey.types.d.ts +422 -217
  22. package/dist/experiences/public.d.ts +1 -1
  23. package/dist/experiences/sequence-driver.d.ts +93 -0
  24. package/dist/experiences/types.d.ts +185 -23
  25. package/dist/internals.d.ts +1 -1
  26. package/dist/internals.js +1 -1
  27. package/dist/queues/queue.driver.d.ts +45 -0
  28. package/dist/queues/queue.driver.js +1 -0
  29. package/dist/queues/queue.module.js +1 -1
  30. package/dist/queues/queue.sequence.d.ts +222 -0
  31. package/dist/state/capability-token-registry.d.ts +1 -0
  32. package/dist/state/capability-token-registry.js +1 -1
  33. package/dist/state/store.d.ts +5 -1
  34. package/dist/state/store.js +1 -1
  35. package/dist/storefront.d.ts +14 -24
  36. package/dist/storefront.js +1 -1
  37. package/dist/test-utils/harness-scenarios.d.ts +8 -1
  38. package/dist/test-utils/harness-scenarios.js +1 -1
  39. package/dist/test-utils/mock-journey.d.ts +15 -4
  40. package/dist/test-utils/mock-journey.js +1 -1
  41. package/dist/test-utils/mock-sdk.js +1 -1
  42. package/dist/test-utils/verification-scenarios.d.ts +9 -1
  43. package/dist/test-utils/verification-scenarios.js +1 -1
  44. package/dist/timed-releases/timed-release.driver.d.ts +45 -0
  45. package/dist/timed-releases/timed-release.driver.js +1 -0
  46. package/dist/timed-releases/timed-release.module.d.ts +6 -1
  47. package/dist/timed-releases/timed-release.module.js +1 -1
  48. package/dist/timed-releases/timed-release.sequence.d.ts +227 -0
  49. package/dist/timed-releases/types.d.ts +16 -1
  50. package/dist/types/distribution-type.d.ts +1 -1
  51. package/dist/version.d.ts +1 -1
  52. package/dist/version.js +1 -1
  53. package/package.json +3 -3
@@ -1,100 +1,114 @@
1
- import { AdmissionGrant, AppointmentConsumerStatus, AuctionConsumerStatus, DistributionLifecycle, DistributionType, DrawConsumerStatus, JourneyStage, QueueConsumerStatus, SequenceOutcome, SequenceOutcomeType, SequencePhase, TimedReleaseConsumerStatus, WaitlistConsumerStatus } from '@fanfare-io/fanfare-sdk-contracts/consumer-me';
1
+ import { AdmissionGrant, AppointmentConsumerStatus, AuctionConsumerStatus, WaitlistAttachment as ContractWaitlistAttachment, DistributionLifecycle, DistributionType, DrawConsumerStatus, JourneyStage, QueueConsumerStatus, SequenceOutcome, SequenceOutcomeType, SequencePhase, TimedReleaseConsumerStatus, WaitlistConsumerStatus } from '@fanfare-io/fanfare-sdk-contracts/consumer-me';
2
2
  import { ReadableAtom } from 'nanostores';
3
+ import { AppointmentEnded, AppointmentEnterable, AppointmentEnterableView, AppointmentParticipating, AppointmentParticipatingView, AppointmentScheduled, AppointmentScheduledView, AppointmentSequence, AppointmentSequenceConsumerState, AppointmentSequenceView } from '../appointments/appointment.sequence';
4
+ import { AuctionEnded, AuctionEnterable, AuctionEnterableView, AuctionGranted, AuctionParticipating, AuctionParticipatingView, AuctionScheduled, AuctionScheduledView, AuctionSequence, AuctionSequenceConsumerState, AuctionSequenceView, AuctionSettling } from '../auctions/auction.sequence';
3
5
  import { BotMitigationState, RoutingChallenge } from '../challenges/types';
6
+ import { DrawEnded, DrawEnterable, DrawEnterableView, DrawGranted, DrawParticipating, DrawParticipatingView, DrawScheduled, DrawScheduledView, DrawSequence, DrawSequenceConsumerState, DrawSequenceView, DrawSettling } from '../draws/draw.sequence';
7
+ import { QueueEnded, QueueEnterable, QueueEnterableView, QueueGranted, QueueParticipating, QueueParticipatingView, QueueScheduled, QueueScheduledView, QueueSequence, QueueSequenceConsumerState, QueueSequenceView } from '../queues/queue.sequence';
8
+ import { TimedReleaseEnded, TimedReleaseEnterable, TimedReleaseEnterableView, TimedReleaseGranted, TimedReleaseParticipating, TimedReleaseParticipatingView, TimedReleaseScheduled, TimedReleaseScheduledView, TimedReleaseSequence, TimedReleaseSequenceConsumerState, TimedReleaseSequenceView } from '../timed-releases/timed-release.sequence';
4
9
  import { SdkJourneyParticipationType } from '../types/distribution-type';
5
- import { AppointmentDisplayState, AuctionDisplayState, DrawDisplayState, QueueDisplayState, TimedReleaseDisplayState } from './distribution-monitor.types';
6
10
  import { DistributionDetails, ExperienceSession, Sequence } from './types';
11
+ export type { AppointmentEnded, AppointmentEndedView, AppointmentEnterable, AppointmentEnterableView, AppointmentParticipating, AppointmentParticipatingView, AppointmentScheduled, AppointmentScheduledView, AppointmentSequence, AppointmentSequenceConsumerState, AppointmentSequenceView, } from '../appointments/appointment.sequence';
12
+ export type { AuctionEnded, AuctionEndedView, AuctionEnterable, AuctionEnterableView, AuctionGranted, AuctionGrantedView, AuctionParticipating, AuctionParticipatingView, AuctionScheduled, AuctionScheduledView, AuctionSequence, AuctionSequenceConsumerState, AuctionSequenceView, AuctionSettling, AuctionSettlingView, } from '../auctions/auction.sequence';
13
+ export type { DrawEnded, DrawEndedView, DrawEnterable, DrawEnterableView, DrawGranted, DrawGrantedView, DrawParticipating, DrawParticipatingView, DrawScheduled, DrawScheduledView, DrawSequence, DrawSequenceConsumerState, DrawSequenceView, DrawSettling, DrawSettlingView, } from '../draws/draw.sequence';
14
+ export type { QueueEnded, QueueEndedView, QueueEnterable, QueueEnterableView, QueueGranted, QueueGrantedView, QueueParticipating, QueueParticipatingView, QueueScheduled, QueueScheduledView, QueueSequence, QueueSequenceConsumerState, QueueSequenceView, } from '../queues/queue.sequence';
15
+ export type { TimedReleaseEnded, TimedReleaseEndedView, TimedReleaseEnterable, TimedReleaseEnterableView, TimedReleaseGranted, TimedReleaseGrantedView, TimedReleaseParticipating, TimedReleaseParticipatingView, TimedReleaseScheduled, TimedReleaseScheduledView, TimedReleaseSequence, TimedReleaseSequenceConsumerState, TimedReleaseSequenceView, } from '../timed-releases/timed-release.sequence';
7
16
  export type { AdmissionGrant, AppointmentConsumerStatus, AuctionConsumerStatus, DistributionLifecycle, DistributionType, DrawConsumerStatus, JourneyStage, QueueConsumerStatus, SequenceOutcome, SequenceOutcomeType, SequencePhase, TimedReleaseConsumerStatus, WaitlistConsumerStatus, };
8
- export type SequenceMechanism = DistributionType | "waitlist";
17
+ /**
18
+ * Any sequence mechanism that can appear in a journey sequence.
19
+ */
20
+ export type SequenceMechanism = DistributionType;
21
+ /**
22
+ * Distribution-backed mechanisms that carry a `distribution` object.
23
+ */
9
24
  export type PrimarySequenceMechanism = DistributionType;
10
- export type GrantProducingSequenceMechanism = Exclude<PrimarySequenceMechanism, "appointment">;
25
+ /**
26
+ * Primary mechanisms that can issue an admission grant.
27
+ */
28
+ export type GrantProducingSequenceMechanism = "queue" | "draw" | "auction" | "timed_release";
29
+ /**
30
+ * Primary mechanisms that can enter the server-driven settling phase.
31
+ */
11
32
  export type SettlingSequenceMechanism = "draw" | "auction";
33
+ /**
34
+ * Distribution facts attached to a routed sequence.
35
+ *
36
+ * These values come from the journey projector and describe the distribution
37
+ * currently driving the sequence. Timestamps are ISO 8601 strings; `updatedAt`
38
+ * is a millisecond epoch version used for ordering projector updates.
39
+ */
12
40
  export interface DistributionSummary {
41
+ /** Mechanism discriminator for the distribution. */
13
42
  type: DistributionType;
43
+ /** Server distribution identifier. */
14
44
  id: string;
45
+ /** Sequence identifier that owns this distribution, when supplied by the projector. */
15
46
  sequenceId?: string;
47
+ /** Server lifecycle for opening, closing, and settlement. */
16
48
  lifecycle: DistributionLifecycle;
49
+ /** ISO 8601 scheduled start timestamp, when distinct from opening. */
17
50
  startsAt?: string;
51
+ /** ISO 8601 timestamp when consumers may enter or participate. */
18
52
  opensAt?: string;
53
+ /** ISO 8601 timestamp when participation closes. */
19
54
  closesAt?: string;
55
+ /** ISO 8601 timestamp when server settlement is expected. */
20
56
  settlesAt?: string;
57
+ /** Waitlist identifier attached while the distribution is scheduled. */
21
58
  waitlistId?: string;
59
+ /** Mechanism-specific configuration and display details from the server. */
22
60
  details?: DistributionDetails;
61
+ /** Millisecond epoch update time used to order projector snapshots. */
23
62
  updatedAt?: number;
24
63
  }
25
- export interface DistributionTarget {
26
- type: DistributionType;
27
- id: string;
28
- sequenceId?: string;
29
- lifecycle: DistributionLifecycle;
30
- opensAt?: string;
31
- closesAt?: string;
32
- waitlistId?: string;
33
- details?: Record<string, unknown>;
34
- updatedAt?: number;
35
- }
64
+ /**
65
+ * Internal alias for distribution facts on sequence states.
66
+ *
67
+ * Drivers use this name while preserving the public `DistributionSummary`
68
+ * shape. It carries the same server-authoritative fields and timestamp formats.
69
+ */
36
70
  export type SequenceDistributionState = DistributionSummary;
37
- export type SequenceTargetState = DistributionTarget;
38
- export interface QueueSequenceConsumerState {
39
- status: QueueConsumerStatus;
40
- id?: string;
41
- distributionId?: string;
42
- enteredAt?: string;
43
- admissionGrant?: string;
44
- grantedAt?: string;
45
- deniedReason?: string;
46
- position?: number;
47
- }
48
- export interface DrawSequenceConsumerState {
49
- status: DrawConsumerStatus;
50
- id?: string;
51
- distributionId?: string;
52
- enteredAt?: string;
53
- admissionGrant?: string;
54
- grantedAt?: string;
55
- deniedReason?: string;
56
- }
57
- export interface AuctionSequenceConsumerState {
58
- status: AuctionConsumerStatus;
59
- id?: string;
60
- distributionId?: string;
61
- enteredAt?: string;
62
- admissionGrant?: string;
63
- grantedAt?: string;
64
- deniedReason?: string;
65
- highestBid?: string;
66
- currentBid?: string;
67
- }
68
- export interface TimedReleaseSequenceConsumerState {
69
- status: TimedReleaseConsumerStatus;
70
- id?: string;
71
- distributionId?: string;
72
- enteredAt?: string;
73
- admissionGrant?: string;
74
- grantedAt?: string;
75
- deniedReason?: string;
76
- }
77
- export interface AppointmentSequenceConsumerState {
78
- status: AppointmentConsumerStatus;
79
- id?: string;
80
- distributionId?: string;
81
- slotId?: string;
82
- locationId?: string;
83
- bookedAt?: string;
84
- checkedInAt?: string;
85
- completedAt?: string;
86
- cancelledAt?: string;
87
- noShowAt?: string;
88
- }
89
- export interface WaitlistSequenceConsumerState {
71
+ /**
72
+ * Scheduled waitlist attachment facts for one consumer.
73
+ *
74
+ * Attachments exist only on scheduled primary sequence variants. They do not
75
+ * grant access on their own, are cleared when the primary distribution opens,
76
+ * and are restored only from `/consumers/me`.
77
+ */
78
+ export type WaitlistAttachment = ContractWaitlistAttachment;
79
+ /**
80
+ * Scheduled waitlist actions exposed on sequence views.
81
+ *
82
+ * The sub-view is present only while the primary distribution is scheduled.
83
+ * `join()` and `leave()` call the SDK waitlist module; `/consumers/me` remains
84
+ * the only source that can restore a `notified` status.
85
+ */
86
+ export interface WaitlistAttachmentView {
87
+ /** Server waitlist attachment status for this consumer. */
90
88
  status: WaitlistConsumerStatus;
91
- id?: string;
92
- waitlistId?: string;
93
- enteredAt?: string;
94
- notifiedAt?: string;
89
+ /** Join the scheduled distribution's waitlist. */
90
+ join(): Promise<void>;
91
+ /** Leave the scheduled distribution's waitlist. */
92
+ leave(): Promise<void>;
95
93
  }
96
- export type ConsumerSequenceState = QueueSequenceConsumerState | DrawSequenceConsumerState | AuctionSequenceConsumerState | TimedReleaseSequenceConsumerState | AppointmentSequenceConsumerState | WaitlistSequenceConsumerState;
97
- export type SequenceConsumerFor<M extends SequenceMechanism> = M extends "queue" ? QueueSequenceConsumerState : M extends "draw" ? DrawSequenceConsumerState : M extends "auction" ? AuctionSequenceConsumerState : M extends "timed_release" ? TimedReleaseSequenceConsumerState : M extends "appointment" ? AppointmentSequenceConsumerState : WaitlistSequenceConsumerState;
94
+ /**
95
+ * Consumer facts for any sequence mechanism.
96
+ */
97
+ export type ConsumerSequenceState = QueueSequenceConsumerState | DrawSequenceConsumerState | AuctionSequenceConsumerState | TimedReleaseSequenceConsumerState | AppointmentSequenceConsumerState;
98
+ /**
99
+ * Internal helper mapping a mechanism discriminator to its consumer state.
100
+ *
101
+ * This keeps driver and machine code correlated without reintroducing public
102
+ * mechanism x phase type generation. Integrators should narrow `SequenceState`
103
+ * or `SequenceView` by `mechanism` instead.
104
+ */
105
+ export type SequenceConsumerFor<M extends SequenceMechanism> = M extends "queue" ? QueueSequenceConsumerState : M extends "draw" ? DrawSequenceConsumerState : M extends "auction" ? AuctionSequenceConsumerState : M extends "timed_release" ? TimedReleaseSequenceConsumerState : M extends "appointment" ? AppointmentSequenceConsumerState : never;
106
+ /**
107
+ * Internal consumer payload tagged with the mechanism it came from.
108
+ *
109
+ * The tag is added while normalizing `/consumers/me` and routing payloads so
110
+ * generic shell code can pass the correct consumer facts to mechanism drivers.
111
+ */
98
112
  export type MechanismConsumerState = (QueueSequenceConsumerState & {
99
113
  mechanism: "queue";
100
114
  }) | (DrawSequenceConsumerState & {
@@ -105,291 +119,482 @@ export type MechanismConsumerState = (QueueSequenceConsumerState & {
105
119
  mechanism: "timed_release";
106
120
  }) | (AppointmentSequenceConsumerState & {
107
121
  mechanism: "appointment";
108
- }) | (WaitlistSequenceConsumerState & {
109
- mechanism: "waitlist";
110
122
  });
111
- interface PrimarySequenceContext<M extends PrimarySequenceMechanism> {
112
- mechanism: M;
113
- distribution: DistributionSummary & {
114
- type: M;
115
- };
116
- consumer: SequenceConsumerFor<M>;
117
- }
118
- interface WaitlistSequenceContext {
119
- mechanism: "waitlist";
120
- target: DistributionTarget;
121
- consumer: WaitlistSequenceConsumerState;
122
- }
123
+ /**
124
+ * Sequence placeholder used when the server selects no usable distribution.
125
+ *
126
+ * Render this as unavailable content and offer a retry or reroute from the
127
+ * surrounding `RoutedView` when appropriate.
128
+ */
123
129
  export type UnavailableSequenceState = {
130
+ /** Phase discriminator for an unavailable routed sequence. */
124
131
  phase: "unavailable";
132
+ /** Server or SDK reason suitable for diagnostics; not guaranteed localized. */
125
133
  reason?: string;
126
134
  };
127
- export type ScheduledSequenceState = {
128
- [M in PrimarySequenceMechanism]: {
129
- phase: "scheduled";
130
- } & PrimarySequenceContext<M>;
131
- }[PrimarySequenceMechanism];
132
- export type EnterableSequenceState = {
133
- [M in PrimarySequenceMechanism]: {
134
- phase: "enterable";
135
- } & PrimarySequenceContext<M>;
136
- }[PrimarySequenceMechanism] | ({
137
- phase: "enterable";
138
- } & WaitlistSequenceContext);
139
- export type ParticipatingSequenceState = {
140
- [M in PrimarySequenceMechanism]: {
141
- phase: "participating";
142
- } & PrimarySequenceContext<M>;
143
- }[PrimarySequenceMechanism] | ({
144
- phase: "participating";
145
- } & WaitlistSequenceContext);
146
- export type SettlingSequenceState = {
147
- [M in SettlingSequenceMechanism]: {
148
- phase: "settling";
149
- } & PrimarySequenceContext<M>;
150
- }[SettlingSequenceMechanism];
151
- export type GrantedSequenceState = {
152
- [M in GrantProducingSequenceMechanism]: {
153
- phase: "granted";
154
- grant: AdmissionGrant;
155
- } & PrimarySequenceContext<M>;
156
- }[GrantProducingSequenceMechanism];
157
- export type EndedSequenceState = {
158
- [M in PrimarySequenceMechanism]: {
159
- phase: "ended";
160
- outcome: SequenceOutcome;
161
- } & PrimarySequenceContext<M>;
162
- }[PrimarySequenceMechanism] | ({
163
- phase: "ended";
164
- outcome: SequenceOutcome;
165
- } & WaitlistSequenceContext);
166
- export type SequenceState = UnavailableSequenceState | ScheduledSequenceState | EnterableSequenceState | ParticipatingSequenceState | SettlingSequenceState | GrantedSequenceState | EndedSequenceState;
167
- export type ActiveSequenceState = Exclude<SequenceState, UnavailableSequenceState>;
135
+ /**
136
+ * Sequence states that exist before a primary distribution opens.
137
+ */
138
+ export type ScheduledSequenceState = QueueScheduled | DrawScheduled | AuctionScheduled | TimedReleaseScheduled | AppointmentScheduled;
139
+ /**
140
+ * Sequence states where the consumer can enter, bid, book, or join a waitlist.
141
+ */
142
+ export type EnterableSequenceState = QueueEnterable | DrawEnterable | AuctionEnterable | TimedReleaseEnterable | AppointmentEnterable;
143
+ /**
144
+ * Sequence states where the consumer is actively participating.
145
+ */
146
+ export type ParticipatingSequenceState = QueueParticipating | DrawParticipating | AuctionParticipating | TimedReleaseParticipating | AppointmentParticipating;
147
+ /**
148
+ * Sequence states where a draw or auction is being settled by the server.
149
+ */
150
+ export type SettlingSequenceState = DrawSettling | AuctionSettling;
151
+ /**
152
+ * Sequence states where the consumer has an admission grant.
153
+ */
154
+ export type GrantedSequenceState = QueueGranted | DrawGranted | AuctionGranted | TimedReleaseGranted;
155
+ /**
156
+ * Sequence states where the sequence is terminal for the consumer.
157
+ */
158
+ export type EndedSequenceState = QueueEnded | DrawEnded | AuctionEnded | TimedReleaseEnded | AppointmentEnded;
159
+ /**
160
+ * Serializable sequence state for a routed journey.
161
+ */
162
+ export type SequenceState = UnavailableSequenceState | QueueSequence | DrawSequence | AuctionSequence | TimedReleaseSequence | AppointmentSequence;
163
+ /**
164
+ * Mechanism-backed sequence state, excluding the unavailable placeholder.
165
+ *
166
+ * Internal driver code uses this alias when a concrete mechanism is required.
167
+ * Integrator code can usually work with the broader `SequenceState` union.
168
+ */
169
+ export type ActiveSequenceState = QueueSequence | DrawSequence | AuctionSequence | TimedReleaseSequence | AppointmentSequence;
170
+ /**
171
+ * Internal helper selecting the sequence union for one mechanism.
172
+ *
173
+ * Used by driver code that is already mechanism-specific. Public rendering
174
+ * should narrow `SequenceState` or `SequenceView` by the `mechanism` field.
175
+ */
168
176
  export type SequenceStateFor<M extends SequenceMechanism> = Extract<ActiveSequenceState, {
169
177
  mechanism: M;
170
178
  }>;
171
- export type PrimarySequenceState = Extract<ActiveSequenceState, {
172
- distribution: DistributionSummary;
173
- }>;
174
- export type ConsumerJourneyState = {
179
+ /**
180
+ * Mechanism-backed sequence state for primary journey distributions.
181
+ *
182
+ * This is equivalent to `ActiveSequenceState` while every shipped mechanism is
183
+ * primary. It remains as an internal constraint for code that excludes
184
+ * `unavailable`.
185
+ */
186
+ export type PrimarySequenceState = QueueSequence | DrawSequence | AuctionSequence | TimedReleaseSequence | AppointmentSequence;
187
+ /**
188
+ * Serializable journey state rebuilt from `/consumers/me`.
189
+ *
190
+ * This is the server-facing snapshot shape used by resume and parity tests, not
191
+ * the render view. Use `JourneySnapshot` for client persistence and
192
+ * `JourneyView` for UI rendering.
193
+ */
194
+ export type ConsumerJourneyState =
195
+ /** The consumer has no selected sequence and can begin routing. */
196
+ {
175
197
  journeyStage: "ready";
176
198
  experienceId: string;
177
199
  updatedAt?: string;
178
- } | {
200
+ }
201
+ /** The SDK is actively routing the consumer through the experience. */
202
+ | {
179
203
  journeyStage: "routing";
180
204
  experienceId: string;
181
205
  updatedAt?: string;
182
- } | {
206
+ }
207
+ /** The selected route requires gates such as auth, access code, or bot mitigation. */
208
+ | {
209
+ /** Stage discriminator for a gated server journey. */
183
210
  journeyStage: "gated";
211
+ /** Experience identifier for this journey. */
184
212
  experienceId: string;
213
+ /** ISO 8601 server update timestamp, when supplied. */
185
214
  updatedAt?: string;
215
+ /** Server gate payloads; narrowed client gates are exposed through `RoutingGate`. */
186
216
  gates: unknown[];
217
+ /** Selected sequence id that is gated, when the server chose one. */
187
218
  selected?: {
188
219
  sequenceId: string;
189
220
  };
190
- } | {
221
+ }
222
+ /** The consumer is routed to a concrete sequence state. */
223
+ | {
224
+ /** Stage discriminator for a routed server journey. */
191
225
  journeyStage: "routed";
226
+ /** Experience identifier for this journey. */
192
227
  experienceId: string;
228
+ /** ISO 8601 server update timestamp, when supplied. */
193
229
  updatedAt?: string;
230
+ /** Selected sequence identifier. */
194
231
  sequenceId: string;
232
+ /** Mechanism-first sequence state for the selected sequence. */
195
233
  sequence: SequenceState;
234
+ /** Additional route offers from the server, when supplied. */
196
235
  offers?: unknown[];
197
236
  };
237
+ /**
238
+ * Server journey states that require active service handling.
239
+ *
240
+ * Internal resume code uses this to distinguish gated/routed server responses
241
+ * from ready/routing placeholders.
242
+ */
198
243
  export type ServiceJourneyState = Extract<ConsumerJourneyState, {
199
244
  journeyStage: "gated" | "routed";
200
245
  }>;
246
+ /** Stage discriminator for server states that carry gates or sequence state. */
201
247
  export type ServiceJourneyStage = ServiceJourneyState["journeyStage"];
202
- export type RoutingGate = {
248
+ /**
249
+ * Gate that prevents a selected sequence from becoming renderable.
250
+ *
251
+ * Gates are returned by routing. UIs should render the required action and then
252
+ * call `retry()` or `reroute()` on the current journey view after the gate is
253
+ * satisfied.
254
+ */
255
+ export type RoutingGate =
256
+ /** The consumer must authenticate before the route can continue. */
257
+ {
203
258
  type: "authentication";
204
259
  status: "required";
205
- } | {
260
+ }
261
+ /** The route requires an access code or rejected the submitted one. */
262
+ | {
206
263
  type: "access_code";
207
264
  status: "missing" | "invalid";
208
- } | {
265
+ }
266
+ /** The route requires bot mitigation or has been blocked by it. */
267
+ | {
268
+ /** Gate discriminator for bot mitigation. */
209
269
  type: "bot_check";
270
+ /** Current mitigation status. */
210
271
  status: "required" | "blocked";
272
+ /** Challenge payload to render when mitigation is required. */
211
273
  challenge?: RoutingChallenge;
274
+ /** Bot-risk state supplied by the mitigation service. */
212
275
  mitigation?: BotMitigationState;
213
276
  };
277
+ /**
278
+ * Alternative gated route returned by the server.
279
+ *
280
+ * Offers let an integrator show other sequences the consumer could unlock.
281
+ * They are informational until a reroute selects one.
282
+ */
214
283
  export interface RoutingOffer {
284
+ /** Offered sequence metadata from the experience service. */
215
285
  sequence: Sequence;
286
+ /** Offer status; currently only gated offers are exposed. */
216
287
  status: "gated";
288
+ /** Gates that must be satisfied before this offer can be routed. */
217
289
  gates: RoutingGate[];
218
290
  }
291
+ /**
292
+ * Consumer participation reference attached to journey events or analytics.
293
+ *
294
+ * `id` is the server participation identifier. `type` identifies the
295
+ * participation mechanism, including waitlist attachments.
296
+ */
219
297
  export interface Participation {
298
+ /** Server participation identifier. */
220
299
  id: string;
300
+ /** Participation mechanism discriminator. */
221
301
  type: SdkJourneyParticipationType;
222
302
  }
303
+ /**
304
+ * Category for a journey event emitted by the SDK shell.
305
+ */
223
306
  export type JourneyEventKind = "reroute" | "sequence_change" | "distribution_change" | "requirement" | "error" | "info";
307
+ /**
308
+ * Presentation severity for a journey event.
309
+ */
224
310
  export type JourneyEventSeverity = "info" | "success" | "warning" | "error";
311
+ /**
312
+ * Intended consumer for a journey event.
313
+ */
225
314
  export type JourneyEventAudience = "user" | "system" | "analytics";
315
+ /**
316
+ * Event emitted by the journey shell for UI, diagnostics, or analytics.
317
+ *
318
+ * `ts` is a millisecond epoch timestamp generated by the SDK. Events are
319
+ * ordered by id and timestamp within one journey handle.
320
+ */
226
321
  export interface JourneyEvent {
322
+ /** Stable event identifier generated by the SDK. */
227
323
  id: string;
324
+ /** Millisecond epoch timestamp when the SDK emitted the event. */
228
325
  ts: number;
326
+ /** Event category. */
229
327
  kind: JourneyEventKind;
328
+ /** Presentation severity. */
230
329
  severity: JourneyEventSeverity;
330
+ /** Intended audience for rendering or forwarding. */
231
331
  audience: JourneyEventAudience;
332
+ /** Human-readable message suitable for logs or simple UI. */
232
333
  message: string;
334
+ /** Structured diagnostics or analytics context. */
233
335
  detail?: Record<string, unknown>;
234
336
  }
235
337
  interface JourneyBase {
338
+ /** Monotonic SDK revision used for cross-tab ordering. */
236
339
  revision: number;
340
+ /** Millisecond epoch timestamp when the snapshot was last updated. */
237
341
  updatedAt: number;
342
+ /** Experience identifier for this journey handle. */
238
343
  experienceId: string;
344
+ /** Last access code used for routing, when one has been supplied. */
239
345
  accessCode?: string;
346
+ /** Session details returned by the experience entry endpoint, when available. */
240
347
  experience?: ExperienceSession;
348
+ /** Buffered SDK events emitted for this journey. */
241
349
  events: JourneyEvent[];
350
+ /** Last acknowledged event id for UI notification state. */
242
351
  lastSeenEventId?: string;
243
352
  }
353
+ /**
354
+ * Persistable journey snapshot before routing has started.
355
+ */
244
356
  export interface ReadySnapshot extends JourneyBase {
357
+ /** Stage discriminator; call `start()` on the matching view to route. */
245
358
  journeyStage: "ready";
246
359
  }
360
+ /**
361
+ * Persistable journey snapshot while routing is in flight.
362
+ */
247
363
  export interface RoutingSnapshot extends JourneyBase {
364
+ /** Stage discriminator for an in-flight route request. */
248
365
  journeyStage: "routing";
249
366
  }
367
+ /**
368
+ * Persistable journey snapshot when routing is blocked by gates.
369
+ */
250
370
  export interface GatedSnapshot extends JourneyBase {
371
+ /** Stage discriminator for a gated route. */
251
372
  journeyStage: "gated";
373
+ /** Gates that must be satisfied before the sequence can render. */
252
374
  gates: RoutingGate[];
375
+ /** Selected gated sequence, when routing chose one. */
253
376
  selected?: {
377
+ /** Selected sequence metadata. */
254
378
  sequence: Sequence;
379
+ /** Selected sequence status; currently always gated. */
255
380
  status: "gated";
256
381
  };
257
382
  }
383
+ /**
384
+ * Persistable journey snapshot after routing selects a sequence.
385
+ */
258
386
  export interface RoutedSnapshot extends JourneyBase {
387
+ /** Stage discriminator for a routed sequence. */
259
388
  journeyStage: "routed";
389
+ /** Selected sequence identifier. */
260
390
  sequenceId: string;
391
+ /** Additional gated route offers supplied by the server. */
261
392
  offers: RoutingOffer[];
393
+ /** Current mechanism-first sequence state. */
262
394
  sequence: SequenceState;
395
+ /** Selected sequence metadata; `sequence` is runtime state, while `sequenceRef` identifies the routed sequence. */
396
+ sequenceRef?: Sequence;
263
397
  }
398
+ /**
399
+ * Versioned, persistable state for one journey handle.
400
+ *
401
+ * Snapshots are a cache for reload/cross-tab handoff. On restore, the SDK
402
+ * validates the stored version and rebuilds stale or incompatible snapshots
403
+ * from `/consumers/me`.
404
+ */
264
405
  export type JourneySnapshot = ReadySnapshot | RoutingSnapshot | GatedSnapshot | RoutedSnapshot;
406
+ /**
407
+ * Render view before routing has started.
408
+ */
265
409
  export interface ReadyView {
410
+ /** Stage discriminator; only `start()` is legal in this view. */
266
411
  journeyStage: "ready";
412
+ /**
413
+ * Start routing the consumer through the experience.
414
+ *
415
+ * `accessCode`, when provided, is sent to the routing endpoint. The promise
416
+ * rejects if routing fails before the journey can move to a new view.
417
+ */
267
418
  start(opts?: {
268
419
  accessCode?: string;
269
420
  }): Promise<void>;
270
421
  }
422
+ /**
423
+ * Render view while routing is in flight.
424
+ */
271
425
  export interface RoutingView {
426
+ /** Stage discriminator for an in-flight route request. */
272
427
  journeyStage: "routing";
273
428
  }
429
+ /**
430
+ * Render view when routing requires gates before a sequence is usable.
431
+ */
274
432
  export interface GatedView {
433
+ /** Stage discriminator for a gated route. */
275
434
  journeyStage: "gated";
435
+ /** Gates the integrator should satisfy or explain to the consumer. */
276
436
  gates: RoutingGate[];
437
+ /** Selected gated sequence, when routing chose one. */
277
438
  selected?: {
278
439
  sequence: Sequence;
279
440
  status: "gated";
280
441
  };
442
+ /**
443
+ * Attempt routing again, optionally with a new access code. Omitting
444
+ * `accessCode` re-sends the journey's stored code; passing
445
+ * `accessCode: undefined` explicitly clears the stored code first.
446
+ *
447
+ * Use after a gate changes state. The promise rejects if the route request or
448
+ * gate validation fails.
449
+ */
281
450
  reroute(opts?: {
282
451
  accessCode?: string;
283
452
  }): Promise<void>;
453
+ /**
454
+ * Retry the current gated route without changing the access code.
455
+ *
456
+ * Use after completing auth or bot mitigation. The promise rejects if routing
457
+ * still cannot proceed.
458
+ */
284
459
  retry(): Promise<void>;
285
460
  }
461
+ /**
462
+ * Result of `RoutedView.submitAccessCode`.
463
+ * - `advanced`: the code unlocked a higher-priority offered sequence; the
464
+ * journey moved into it and the code became the journey's stored code.
465
+ * - `unchanged`: the code unlocked nothing; the journey remains in (or was
466
+ * restored toward) its previous sequence and the stored code is untouched.
467
+ * - `gated`: routing no longer yields an admissible sequence; the journey is
468
+ * now gated and the gate UI should take over.
469
+ */
470
+ export type AccessCodeSubmitResult = {
471
+ outcome: "advanced";
472
+ sequenceId: string;
473
+ } | {
474
+ outcome: "unchanged";
475
+ } | {
476
+ outcome: "gated";
477
+ };
478
+ /**
479
+ * Render view after routing selects a sequence.
480
+ */
286
481
  export interface RoutedView {
482
+ /** Stage discriminator for a routed sequence. */
287
483
  journeyStage: "routed";
484
+ /** Selected sequence identifier. */
288
485
  sequenceId: string;
486
+ /** Additional gated offers the consumer could route to. */
289
487
  offers: RoutingOffer[];
488
+ /**
489
+ * Route the consumer again with the journey's stored access code.
490
+ *
491
+ * Use when the selected sequence changes or an offer should be reconsidered.
492
+ */
290
493
  reroute(): Promise<void>;
494
+ /**
495
+ * Attempts an upgrade into a higher-priority offered sequence. Routing is
496
+ * stateless and single-code, so the candidate replaces the stored code for
497
+ * the attempt only: it is committed as the stored code when the journey
498
+ * advances, and if it instead displaces the consumer from a code-held
499
+ * sequence, the previously stored code is re-applied automatically.
500
+ */
501
+ submitAccessCode(accessCode: string): Promise<AccessCodeSubmitResult>;
502
+ /**
503
+ * Retry the current routed state after a transient failure.
504
+ */
291
505
  retry(): Promise<void>;
506
+ /** Mechanism-first sequence view containing the legal phase actions. */
292
507
  sequence: SequenceView;
293
508
  }
294
- export type ParticipatingSequenceView = {
295
- phase: "participating";
296
- mechanism: "queue";
297
- consumer: QueueSequenceConsumerState;
298
- state$: ReadableAtom<QueueDisplayState>;
299
- leave(): Promise<void>;
300
- } | {
301
- phase: "participating";
302
- mechanism: "draw";
303
- consumer: DrawSequenceConsumerState;
304
- state$: ReadableAtom<DrawDisplayState>;
305
- leave(): Promise<void>;
306
- } | {
307
- phase: "participating";
308
- mechanism: "auction";
309
- consumer: AuctionSequenceConsumerState;
310
- state$: ReadableAtom<AuctionDisplayState>;
311
- bid(amount: string): Promise<void>;
312
- leave(): Promise<void>;
313
- } | {
314
- phase: "participating";
315
- mechanism: "timed_release";
316
- consumer: TimedReleaseSequenceConsumerState;
317
- state$: ReadableAtom<TimedReleaseDisplayState>;
318
- leave(): Promise<void>;
319
- complete(): Promise<void>;
320
- } | {
321
- phase: "participating";
322
- mechanism: "appointment";
323
- consumer: AppointmentSequenceConsumerState;
324
- state$: ReadableAtom<AppointmentDisplayState>;
325
- cancel(reason?: string): Promise<void>;
326
- reschedule(newSlotId: string, newLocationId?: string): Promise<void>;
327
- } | {
328
- phase: "participating";
329
- mechanism: "waitlist";
330
- consumer: WaitlistSequenceConsumerState;
331
- leave(): Promise<void>;
332
- };
333
- export type EnterableSequenceView = {
334
- phase: "enterable";
335
- mechanism: Exclude<PrimarySequenceMechanism, "appointment" | "auction">;
336
- distribution: DistributionSummary;
337
- consumer: Exclude<ConsumerSequenceState, AppointmentSequenceConsumerState | WaitlistSequenceConsumerState>;
338
- enter(): Promise<void>;
339
- } | {
340
- phase: "enterable";
341
- mechanism: "auction";
342
- distribution: DistributionSummary;
343
- consumer: AuctionSequenceConsumerState;
344
- bid(amount: string): Promise<void>;
345
- } | {
346
- phase: "enterable";
347
- mechanism: "appointment";
348
- distribution: DistributionSummary;
349
- consumer: AppointmentSequenceConsumerState;
350
- book(slotId: string, locationId?: string): Promise<void>;
351
- } | {
352
- phase: "enterable";
353
- mechanism: "waitlist";
354
- target: DistributionTarget;
355
- consumer: WaitlistSequenceConsumerState;
356
- enter(): Promise<void>;
357
- };
358
- export type ScheduledSequenceView = {
359
- phase: "scheduled";
360
- mechanism: PrimarySequenceMechanism;
361
- distribution: DistributionSummary;
362
- consumer: Exclude<ConsumerSequenceState, WaitlistSequenceConsumerState>;
363
- startsAt?: string;
364
- };
365
- export type SequenceView = {
366
- phase: "unavailable";
367
- reason?: string;
368
- } | ScheduledSequenceView | EnterableSequenceView | ParticipatingSequenceView | {
509
+ interface SettlingSequenceView {
510
+ /** Phase discriminator for server-driven settlement. */
369
511
  phase: "settling";
512
+ /** Mechanism discriminator; only draw and auction settle. */
370
513
  mechanism: SettlingSequenceMechanism;
514
+ /** Distribution facts from the journey projector. */
371
515
  distribution: DistributionSummary;
516
+ /** Consumer facts being settled by the server. */
372
517
  consumer: DrawSequenceConsumerState | AuctionSequenceConsumerState;
373
- } | {
518
+ }
519
+ interface GrantedSequenceView {
520
+ /** Phase discriminator; `claim()` is legal in this view. */
374
521
  phase: "granted";
522
+ /** Mechanism discriminator for grant-producing distributions. */
375
523
  mechanism: GrantProducingSequenceMechanism;
524
+ /** Distribution facts from the journey projector. */
376
525
  distribution: DistributionSummary;
526
+ /** Consumer facts associated with the grant. */
377
527
  consumer: QueueSequenceConsumerState | DrawSequenceConsumerState | AuctionSequenceConsumerState | TimedReleaseSequenceConsumerState;
528
+ /** Admission credential issued by the server. */
378
529
  grant: AdmissionGrant;
530
+ /** Return the current admission credential for checkout handoff. */
379
531
  claim(): AdmissionGrant;
380
- } | {
532
+ }
533
+ interface EndedSequenceView {
534
+ /** Phase discriminator; no sequence actions are legal after this phase. */
381
535
  phase: "ended";
536
+ /** Mechanism discriminator for the terminal sequence. */
382
537
  mechanism: SequenceMechanism;
538
+ /** Consumer facts at the terminal outcome. */
383
539
  consumer: ConsumerSequenceState;
540
+ /** Server-derived terminal outcome. */
384
541
  outcome: SequenceOutcome;
385
- };
542
+ }
543
+ interface UnavailableSequenceView {
544
+ /** Phase discriminator for an unavailable routed sequence. */
545
+ phase: "unavailable";
546
+ /** Server or SDK reason suitable for diagnostics; not guaranteed localized. */
547
+ reason?: string;
548
+ }
549
+ type PrimarySequenceView = QueueSequenceView | DrawSequenceView | AuctionSequenceView | TimedReleaseSequenceView | AppointmentSequenceView;
550
+ /**
551
+ * Scheduled sequence views for primary distribution mechanisms.
552
+ */
553
+ export type ScheduledSequenceView = QueueScheduledView | DrawScheduledView | AuctionScheduledView | TimedReleaseScheduledView | AppointmentScheduledView;
554
+ /**
555
+ * Enterable sequence views. The action exposed by each variant is the only
556
+ * legal entry action for that phase and mechanism.
557
+ */
558
+ export type EnterableSequenceView = QueueEnterableView | DrawEnterableView | AuctionEnterableView | TimedReleaseEnterableView | AppointmentEnterableView;
559
+ /**
560
+ * Participating sequence views. Live display atoms are exposed as `display$`
561
+ * on the five primary mechanisms.
562
+ */
563
+ export type ParticipatingSequenceView = QueueParticipatingView | DrawParticipatingView | AuctionParticipatingView | TimedReleaseParticipatingView | AppointmentParticipatingView;
564
+ /**
565
+ * Renderable sequence view for a routed journey.
566
+ */
567
+ export type SequenceView = UnavailableSequenceView | PrimarySequenceView | SettlingSequenceView | GrantedSequenceView | EndedSequenceView;
568
+ /**
569
+ * Renderable journey view exposed by `JourneyHandle.view$`.
570
+ *
571
+ * Render from this union rather than from snapshots. The current
572
+ * `journeyStage` determines which methods are legal.
573
+ */
386
574
  export type JourneyView = ReadyView | RoutingView | GatedView | RoutedView;
575
+ /**
576
+ * Runtime handle for one consumer's journey through one experience.
577
+ *
578
+ * Subscribe to `view$` for rendering, call methods only on the current view,
579
+ * and call `destroy()` when the embedding UI no longer owns the journey.
580
+ */
387
581
  export interface JourneyHandle {
582
+ /** Reactive render view for the journey. */
388
583
  view$: ReadableAtom<JourneyView>;
584
+ /** Reactive buffer of journey events emitted by the SDK shell. */
389
585
  events$: ReadableAtom<JourneyEvent[]>;
586
+ /** Most recent unacknowledged event, or null when none remain. */
390
587
  latestEvent$: ReadableAtom<JourneyEvent | null>;
588
+ /** Reactive persistable snapshot cache for reload and cross-tab sync. */
391
589
  snapshot$: ReadableAtom<JourneySnapshot>;
590
+ /** Mark one event as seen so it no longer appears as latest. */
392
591
  ackEvent(eventId: string): void;
592
+ /** Mark all currently buffered events as seen. */
393
593
  ackAllEvents(): void;
594
+ /**
595
+ * Tear down monitors, timers, and cross-tab listeners owned by this handle,
596
+ * and remove the journey's persisted snapshot. A later `journeys.get` starts
597
+ * fresh and rebuilds state from the server.
598
+ */
394
599
  destroy(): void;
395
600
  }