@@ -14,7 +14,7 @@ import { EnvironmentDataPollingManager } from './polling_manager';
1414import { generateIdentitiesData , retryFetch } from './utils' ;
1515import { SegmentModel } from '../flagsmith-engine/segments/models' ;
1616import { getIdentitySegments } from '../flagsmith-engine/segments/evaluators' ;
17- import { FlagsmithCache , FlagsmithConfig } from './types' ;
17+ import { FlagsmithCache , FlagsmithConfig , FlagsmithTraitValue , ITraitConfig } from './types' ;
1818import pino , { Logger } from 'pino' ;
1919
2020export { AnalyticsProcessor } from './analytics' ;
@@ -39,7 +39,6 @@ export class Flagsmith {
3939 enableAnalytics : boolean = false ;
4040 defaultFlagHandler ?: ( featureName : string ) => DefaultFlag ;
4141
42-
4342 environmentFlagsUrl ?: string ;
4443 identitiesUrl ?: string ;
4544 environmentUrl ?: string ;
@@ -168,11 +167,11 @@ export class Flagsmith {
168167
169168 this . analyticsProcessor = data . enableAnalytics
170169 ? new AnalyticsProcessor ( {
171- environmentKey : this . environmentKey ,
172- baseApiUrl : this . apiUrl ,
173- requestTimeoutMs : this . requestTimeoutMs ,
174- logger : this . logger
175- } )
170+ environmentKey : this . environmentKey ,
171+ baseApiUrl : this . apiUrl ,
172+ requestTimeoutMs : this . requestTimeoutMs ,
173+ logger : this . logger
174+ } )
176175 : undefined ;
177176 }
178177 }
@@ -207,11 +206,15 @@ export class Flagsmith {
207206 *
208207 * @param {string } identifier a unique identifier for the identity in the current
209208 environment, e.g. email address, username, uuid
210- * @param {{[key:string]:any} } traits? a dictionary of traits to add / update on the identity in
211- Flagsmith, e.g. {"num_orders": 10}
209+ * @param {{[key:string]:any | ITraitConfig } } traits? a dictionary of traits to add / update on the identity in
210+ Flagsmith, e.g. {"num_orders": 10} or {age: {value: 30, transient: true}}
212211 * @returns Flags object holding all the flags for the given identity.
213212 */
214- async getIdentityFlags ( identifier : string , traits ?: { [ key : string ] : any } ) : Promise < Flags > {
213+ async getIdentityFlags (
214+ identifier : string ,
215+ traits ?: { [ key : string ] : FlagsmithTraitValue | ITraitConfig } ,
216+ transient : boolean = false
217+ ) : Promise < Flags > {
215218 if ( ! identifier ) {
216219 throw new Error ( '`identifier` argument is missing or invalid.' ) ;
217220 }
@@ -232,7 +235,7 @@ export class Flagsmith {
232235 return this . getIdentityFlagsFromDocument ( identifier , traits || { } ) ;
233236 }
234237
235- return this . getIdentityFlagsFromApi ( identifier , traits ) ;
238+ return this . getIdentityFlagsFromApi ( identifier , traits , transient ) ;
236239 }
237240
238241 /**
@@ -293,8 +296,11 @@ export class Flagsmith {
293296 }
294297 if ( this . environment . identityOverrides ?. length ) {
295298 this . identitiesWithOverridesByIdentifier = new Map < string , IdentityModel > (
296- this . environment . identityOverrides . map ( identity => [ identity . identifier , identity ]
297- ) ) ;
299+ this . environment . identityOverrides . map ( identity => [
300+ identity . identifier ,
301+ identity
302+ ] )
303+ ) ;
298304 }
299305 if ( this . onEnvironmentChange ) {
300306 this . onEnvironmentChange ( null , this . environment ) ;
@@ -433,12 +439,16 @@ export class Flagsmith {
433439 }
434440 }
435441
436- private async getIdentityFlagsFromApi ( identifier : string , traits : { [ key : string ] : any } ) {
442+ private async getIdentityFlagsFromApi (
443+ identifier : string ,
444+ traits : { [ key : string ] : FlagsmithTraitValue | ITraitConfig } ,
445+ transient : boolean = false
446+ ) {
437447 if ( ! this . identitiesUrl ) {
438448 throw new Error ( '`apiUrl` argument is missing or invalid.' ) ;
439449 }
440450 try {
441- const data = generateIdentitiesData ( identifier , traits ) ;
451+ const data = generateIdentitiesData ( identifier , traits , transient ) ;
442452 const jsonResponse = await this . getJSONResponse ( this . identitiesUrl , 'POST' , data ) ;
443453 const flags = Flags . fromAPIFlags ( {
444454 apiFlags : jsonResponse [ 'flags' ] ,
0 commit comments