@@ -13,7 +13,7 @@ import DataSourceStatusErrorInfo from '../DataSourceStatusErrorInfo';
1313export type SourceState = 'interrupted' | 'shutdown' | 'terminal_error' | 'goodbye' ;
1414
1515/**
16- * A change set result containing a processed FDv2 payload .
16+ * A successfully processed FDv2 payload ready for delivery to the flag store .
1717 */
1818export interface ChangeSetResult {
1919 type : 'changeSet' ;
@@ -22,84 +22,93 @@ export interface ChangeSetResult {
2222 environmentId ?: string ;
2323 /** Freshness timestamp from cache, if this result originated from cached data. */
2424 freshness ?: number ;
25+ /**
26+ * When `fdv1Fallback` is true, how long (ms) to remain on FDv1 before
27+ * attempting FDv2 recovery. `undefined` means no TTL was provided (caller
28+ * uses a default); `0` means indefinite (no recovery).
29+ */
30+ fdv1FallbackTtlMs ?: number ;
2531}
2632
2733/**
28- * A status result indicating a state transition (error, shutdown, goodbye).
34+ * A state- transition result (error, shutdown, or goodbye) with no payload .
2935 */
3036export interface StatusResult {
3137 type : 'status' ;
3238 state : SourceState ;
3339 errorInfo ?: DataSourceStatusErrorInfo ;
3440 reason ?: string ;
3541 fdv1Fallback : boolean ;
42+ /**
43+ * When `fdv1Fallback` is true, how long (ms) to remain on FDv1 before
44+ * attempting FDv2 recovery. `undefined` means no TTL was provided (caller
45+ * uses a default); `0` means indefinite (no recovery).
46+ */
47+ fdv1FallbackTtlMs ?: number ;
3648}
3749
3850/**
3951 * The result type for FDv2 initializers and synchronizers.
4052 *
41- * An initializer produces a single result, while a synchronizer produces a
42- * stream of results. Each result is either a change set (containing a payload
43- * of flag data) or a status (indicating a state transition like an error or
44- * shutdown).
53+ * Initializers produce a single result; synchronizers produce a stream.
54+ * The orchestrator in {@link FDv2DataSource} drives the control flow based
55+ * on which variant is returned.
4556 */
4657export type FDv2SourceResult = ChangeSetResult | StatusResult ;
4758
4859/**
49- * Creates a change set result containing processed flag data .
60+ * Wraps a processed FDv2 payload in a { @link ChangeSetResult} .
5061 */
5162export function changeSet (
5263 payload : internal . Payload ,
5364 fdv1Fallback : boolean ,
5465 environmentId ?: string ,
5566 freshness ?: number ,
67+ fdv1FallbackTtlMs ?: number ,
5668) : FDv2SourceResult {
57- return { type : 'changeSet' , payload, fdv1Fallback, environmentId, freshness } ;
69+ return { type : 'changeSet' , payload, fdv1Fallback, environmentId, freshness, fdv1FallbackTtlMs } ;
5870}
5971
6072/**
61- * Creates an interrupted status result. Indicates a transient error; the
62- * synchronizer will attempt to recover automatically.
63- *
64- * When used with an initializer, this is still a terminal state.
73+ * Signals a transient error. Synchronizers retry automatically; for an
74+ * initializer this is terminal since there is no retry loop.
6575 */
6676export function interrupted (
6777 errorInfo : DataSourceStatusErrorInfo ,
6878 fdv1Fallback : boolean ,
79+ fdv1FallbackTtlMs ?: number ,
6980) : FDv2SourceResult {
70- return { type : 'status' , state : 'interrupted' , errorInfo, fdv1Fallback } ;
81+ return { type : 'status' , state : 'interrupted' , errorInfo, fdv1Fallback, fdv1FallbackTtlMs } ;
7182}
7283
7384/**
74- * Creates a shutdown status result. Indicates the data source was closed
75- * gracefully and will not produce any further results.
85+ * Signals a graceful close initiated by the local caller (not the server).
7686 */
7787export function shutdown ( ) : FDv2SourceResult {
7888 return { type : 'status' , state : 'shutdown' , fdv1Fallback : false } ;
7989}
8090
8191/**
82- * Creates a terminal error status result. Indicates an unrecoverable error;
83- * the data source will not produce any further results .
92+ * Signals an unrecoverable error. The orchestrator will block this source
93+ * and move on; it will not retry .
8494 */
8595export function terminalError (
8696 errorInfo : DataSourceStatusErrorInfo ,
8797 fdv1Fallback : boolean ,
98+ fdv1FallbackTtlMs ?: number ,
8899) : FDv2SourceResult {
89- return { type : 'status' , state : 'terminal_error' , errorInfo, fdv1Fallback } ;
100+ return { type : 'status' , state : 'terminal_error' , errorInfo, fdv1Fallback, fdv1FallbackTtlMs } ;
90101}
91102
92103/**
93- * Creates a goodbye status result. Indicates the server has instructed the
94- * client to disconnect .
104+ * Signals a server-initiated disconnect. Unlike terminal_error, this is
105+ * expected and the synchronizer handles reconnection internally .
95106 */
96107export function goodbye ( reason : string , fdv1Fallback : boolean ) : FDv2SourceResult {
97108 return { type : 'status' , state : 'goodbye' , reason, fdv1Fallback } ;
98109}
99110
100- /**
101- * Helper to create a {@link DataSourceStatusErrorInfo} from an HTTP status code.
102- */
111+ /** Builds {@link DataSourceStatusErrorInfo} for an unexpected HTTP status. */
103112export function errorInfoFromHttpError ( statusCode : number ) : DataSourceStatusErrorInfo {
104113 return {
105114 kind : DataSourceErrorKind . ErrorResponse ,
@@ -109,9 +118,7 @@ export function errorInfoFromHttpError(statusCode: number): DataSourceStatusErro
109118 } ;
110119}
111120
112- /**
113- * Helper to create a {@link DataSourceStatusErrorInfo} from a network error.
114- */
121+ /** Builds {@link DataSourceStatusErrorInfo} for a network-level failure. */
115122export function errorInfoFromNetworkError ( message : string ) : DataSourceStatusErrorInfo {
116123 return {
117124 kind : DataSourceErrorKind . NetworkError ,
@@ -120,9 +127,7 @@ export function errorInfoFromNetworkError(message: string): DataSourceStatusErro
120127 } ;
121128}
122129
123- /**
124- * Helper to create a {@link DataSourceStatusErrorInfo} from invalid data.
125- */
130+ /** Builds {@link DataSourceStatusErrorInfo} for a malformed or unexpected payload. */
126131export function errorInfoFromInvalidData ( message : string ) : DataSourceStatusErrorInfo {
127132 return {
128133 kind : DataSourceErrorKind . InvalidData ,
@@ -131,9 +136,7 @@ export function errorInfoFromInvalidData(message: string): DataSourceStatusError
131136 } ;
132137}
133138
134- /**
135- * Helper to create a {@link DataSourceStatusErrorInfo} for unknown errors.
136- */
139+ /** Builds {@link DataSourceStatusErrorInfo} when the error kind is not otherwise classifiable. */
137140export function errorInfoFromUnknown ( message : string ) : DataSourceStatusErrorInfo {
138141 return {
139142 kind : DataSourceErrorKind . Unknown ,
0 commit comments