@@ -32,6 +32,7 @@ import {
32
32
33
33
import { IClientConfig } from './i-client-config' ;
34
34
import { ServingStoreUpdateStrategy } from './isolatable-hybrid.store' ;
35
+ import { sdkVersion } from './sdk-data' ;
35
36
36
37
import {
37
38
EppoPrecomputedJSClient ,
@@ -48,6 +49,8 @@ import {
48
49
49
50
const { DEFAULT_POLL_INTERVAL_MS , POLL_JITTER_PCT } = constants ;
50
51
52
+ const expectedSdkParams = `&sdkName=js-client-sdk&sdkVersion=${ sdkVersion } ` ;
53
+
51
54
function md5Hash ( input : string ) : string {
52
55
return createHash ( 'md5' ) . update ( input ) . digest ( 'hex' ) ;
53
56
}
@@ -641,6 +644,78 @@ describe('initialization options', () => {
641
644
expect ( callCount ) . toBe ( 1 ) ;
642
645
} ) ;
643
646
647
+ describe ( 'enhanced SDK token' , ( ) => {
648
+ let urlsRequested : string [ ] = [ ] ;
649
+
650
+ afterEach ( ( ) => {
651
+ urlsRequested = [ ] ;
652
+ } ) ;
653
+
654
+ beforeEach ( ( ) => {
655
+ global . fetch = jest . fn ( ( url ) => {
656
+ urlsRequested . push ( url ) ;
657
+ return Promise . resolve ( {
658
+ ok : true ,
659
+ status : 200 ,
660
+ json : ( ) => Promise . resolve ( mockConfigResponse ) ,
661
+ } ) ;
662
+ } ) as jest . Mock ;
663
+ } ) ;
664
+
665
+ it ( 'uses the provided subdomain' , async ( ) => {
666
+ await init ( {
667
+ apiKey : 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==' , // subdomain=experiment
668
+ assignmentLogger : mockLogger ,
669
+ } ) ;
670
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
671
+ expect ( urlsRequested [ 0 ] ) . toEqual (
672
+ 'https://experiment.fscdn.eppo.cloud/api/flag-config/v1/config?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
673
+ expectedSdkParams ,
674
+ ) ;
675
+ } ) ;
676
+
677
+ it ( 'uses the provided custom relative baseUrl' , async ( ) => {
678
+ await init ( {
679
+ apiKey : 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==' ,
680
+ baseUrl : '//custom-base-url.com' ,
681
+ assignmentLogger : mockLogger ,
682
+ } ) ;
683
+
684
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
685
+ expect ( urlsRequested [ 0 ] ) . toEqual (
686
+ '//custom-base-url.com/flag-config/v1/config?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
687
+ expectedSdkParams ,
688
+ ) ;
689
+ } ) ;
690
+
691
+ it ( 'uses the provided custom baseUrl and prepends https' , async ( ) => {
692
+ await init ( {
693
+ apiKey : 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==' ,
694
+ baseUrl : 'custom-base-url.com' ,
695
+ assignmentLogger : mockLogger ,
696
+ } ) ;
697
+
698
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
699
+ expect ( urlsRequested [ 0 ] ) . toEqual (
700
+ 'https://custom-base-url.com/flag-config/v1/config?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
701
+ expectedSdkParams ,
702
+ ) ;
703
+ } ) ;
704
+
705
+ it ( 'falls back to the default url' , async ( ) => {
706
+ await init ( {
707
+ apiKey : 'old style key' ,
708
+ assignmentLogger : mockLogger ,
709
+ } ) ;
710
+
711
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
712
+ expect ( urlsRequested [ 0 ] ) . toEqual (
713
+ 'https://fscdn.eppo.cloud/api/flag-config/v1/config?apiKey=old+style+key' +
714
+ expectedSdkParams ,
715
+ ) ;
716
+ } ) ;
717
+ } ) ;
718
+
644
719
it ( 'force reinitialize' , async ( ) => {
645
720
let callCount = 0 ;
646
721
@@ -1172,7 +1247,7 @@ describe('initialization options', () => {
1172
1247
async entries ( ) {
1173
1248
return entriesPromise . promise ;
1174
1249
} ,
1175
- async setEntries ( entries ) {
1250
+ async setEntries ( ) {
1176
1251
// pass
1177
1252
} ,
1178
1253
} ;
@@ -1337,6 +1412,101 @@ describe('EppoPrecomputedJSClient E2E test', () => {
1337
1412
subject : 'test-subject' ,
1338
1413
} ) ;
1339
1414
} ) ;
1415
+
1416
+ describe ( 'with an enhanced SDK token' , ( ) => {
1417
+ let urlsRequested : string [ ] = [ ] ;
1418
+
1419
+ afterEach ( ( ) => {
1420
+ urlsRequested = [ ] ;
1421
+ } ) ;
1422
+
1423
+ beforeEach ( ( ) => {
1424
+ EppoPrecomputedJSClient . initialized = false ;
1425
+
1426
+ global . fetch = jest . fn ( ( url ) => {
1427
+ urlsRequested . push ( url ) ;
1428
+ const precomputedConfiguration = readMockPrecomputedResponse ( MOCK_PRECOMPUTED_WIRE_FILE ) ;
1429
+ const precomputedResponse : IPrecomputedConfigurationResponse = JSON . parse (
1430
+ JSON . parse ( precomputedConfiguration ) . precomputed . response ,
1431
+ ) ;
1432
+ return Promise . resolve ( {
1433
+ ok : true ,
1434
+ status : 200 ,
1435
+ json : ( ) => Promise . resolve ( precomputedResponse ) ,
1436
+ } ) ;
1437
+ } ) as jest . Mock ;
1438
+ } ) ;
1439
+
1440
+ it ( 'uses the provided subdomain' , async ( ) => {
1441
+ await precomputedInit ( {
1442
+ apiKey : 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==' , // subdomain=experiment
1443
+ assignmentLogger : mockLogger ,
1444
+ precompute : {
1445
+ subjectKey : 'test-subject' ,
1446
+ subjectAttributes : { attr1 : 'value1' } ,
1447
+ } ,
1448
+ } ) ;
1449
+
1450
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
1451
+ expect ( urlsRequested [ 0 ] ) . toEqual (
1452
+ 'https://experiment.fs-edge-assignment.eppo.cloud/assignments?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
1453
+ expectedSdkParams ,
1454
+ ) ;
1455
+ } ) ;
1456
+
1457
+ it ( 'uses the provided custom relative baseUrl' , async ( ) => {
1458
+ await precomputedInit ( {
1459
+ apiKey : 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==' , // subdomain=experiment
1460
+ baseUrl : '//custom-base-url.com' ,
1461
+ assignmentLogger : mockLogger ,
1462
+ precompute : {
1463
+ subjectKey : 'test-subject' ,
1464
+ subjectAttributes : { attr1 : 'value1' } ,
1465
+ } ,
1466
+ } ) ;
1467
+
1468
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
1469
+ expect ( urlsRequested [ 0 ] ) . toEqual (
1470
+ '//custom-base-url.com/assignments?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
1471
+ expectedSdkParams ,
1472
+ ) ;
1473
+ } ) ;
1474
+
1475
+ it ( 'uses the provided custom baseUrl and prepends https' , async ( ) => {
1476
+ await precomputedInit ( {
1477
+ apiKey : 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==' , // subdomain=experiment
1478
+ baseUrl : '//custom-base-url.com' ,
1479
+ assignmentLogger : mockLogger ,
1480
+ precompute : {
1481
+ subjectKey : 'test-subject' ,
1482
+ subjectAttributes : { attr1 : 'value1' } ,
1483
+ } ,
1484
+ } ) ;
1485
+
1486
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
1487
+ expect ( urlsRequested [ 0 ] ) . toEqual (
1488
+ '//custom-base-url.com/assignments?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D' +
1489
+ expectedSdkParams ,
1490
+ ) ;
1491
+ } ) ;
1492
+
1493
+ it ( 'falls back to the default url' , async ( ) => {
1494
+ await precomputedInit ( {
1495
+ apiKey : 'Y3M9ZXhwZXJpbWVudA==' , // no encoded subdomain
1496
+ assignmentLogger : mockLogger ,
1497
+ precompute : {
1498
+ subjectKey : 'test-subject' ,
1499
+ subjectAttributes : { attr1 : 'value1' } ,
1500
+ } ,
1501
+ } ) ;
1502
+
1503
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
1504
+ expect ( urlsRequested [ 0 ] ) . toEqual (
1505
+ 'https://fs-edge-assignment.eppo.cloud/assignments?apiKey=Y3M9ZXhwZXJpbWVudA%3D%3D' +
1506
+ expectedSdkParams ,
1507
+ ) ;
1508
+ } ) ;
1509
+ } ) ;
1340
1510
} ) ;
1341
1511
1342
1512
describe ( 'offlinePrecomputedInit' , ( ) => {
0 commit comments