@@ -714,6 +714,84 @@ describe('EppoPrecomputedClient E2E test', () => {
714
714
pollAfterFailedInitialization ? red : 'default' ,
715
715
) ;
716
716
} ) ;
717
+
718
+ describe ( 'Enhanced SDK Token with encoded subdomain' , ( ) => {
719
+ let urlsRequested : string [ ] = [ ] ;
720
+ const SDK_PARAM_SUFFIX = 'sdkName=js-client-sdk-common&sdkVersion=1.0.0' ;
721
+
722
+ beforeEach ( ( ) => {
723
+ urlsRequested = [ ] ;
724
+ global . fetch = jest . fn ( ( url ) => {
725
+ urlsRequested . push ( url . toString ( ) ) ;
726
+ return Promise . resolve ( {
727
+ ok : true ,
728
+ status : 200 ,
729
+ json : ( ) => Promise . resolve ( precomputedResponse ) ,
730
+ } as Response ) ;
731
+ } ) ;
732
+ } ) ;
733
+
734
+ it ( 'should request from the encoded subdomain' , async ( ) => {
735
+ const client = new EppoPrecomputedClient ( {
736
+ precomputedFlagStore : new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ,
737
+ subject,
738
+ requestParameters : {
739
+ apiKey : 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==' , // subdomain=experiment
740
+ sdkName : 'js-client-sdk-common' ,
741
+ sdkVersion : '1.0.0' ,
742
+ } ,
743
+ } ) ;
744
+
745
+ await client . fetchPrecomputedFlags ( ) ;
746
+
747
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
748
+ expect ( urlsRequested [ 0 ] ) . toEqual (
749
+ 'https://experiment.fs-edge-assignment.eppo.cloud/assignments?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D&' +
750
+ SDK_PARAM_SUFFIX ,
751
+ ) ;
752
+ } ) ;
753
+
754
+ it ( 'should request from the default domain if the encoded subdomain is not present' , async ( ) => {
755
+ const client = new EppoPrecomputedClient ( {
756
+ precomputedFlagStore : new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ,
757
+ subject,
758
+ requestParameters : {
759
+ apiKey : 'old style key' ,
760
+ sdkName : 'js-client-sdk-common' ,
761
+ sdkVersion : '1.0.0' ,
762
+ } ,
763
+ } ) ;
764
+
765
+ await client . fetchPrecomputedFlags ( ) ;
766
+
767
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
768
+ expect ( urlsRequested [ 0 ] ) . toEqual (
769
+ 'https://fs-edge-assignment.eppo.cloud/assignments?apiKey=old+style+key&' +
770
+ SDK_PARAM_SUFFIX ,
771
+ ) ;
772
+ } ) ;
773
+
774
+ it ( 'should request from the provided baseUrl if present' , async ( ) => {
775
+ const client = new EppoPrecomputedClient ( {
776
+ precomputedFlagStore : new MemoryOnlyConfigurationStore < PrecomputedFlag > ( ) ,
777
+ subject,
778
+ requestParameters : {
779
+ apiKey : 'zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA==' , // subdomain=experiment
780
+ sdkName : 'js-client-sdk-common' ,
781
+ sdkVersion : '1.0.0' ,
782
+ baseUrl : 'https://custom-base-url.com' ,
783
+ } ,
784
+ } ) ;
785
+
786
+ await client . fetchPrecomputedFlags ( ) ;
787
+
788
+ expect ( urlsRequested ) . toHaveLength ( 1 ) ;
789
+ expect ( urlsRequested [ 0 ] ) . toEqual (
790
+ 'https://custom-base-url.com/assignments?apiKey=zCsQuoHJxVPp895.Y3M9ZXhwZXJpbWVudA%3D%3D&' +
791
+ SDK_PARAM_SUFFIX ,
792
+ ) ;
793
+ } ) ;
794
+ } ) ;
717
795
} ) ;
718
796
719
797
describe ( 'Obfuscated precomputed flags' , ( ) => {
0 commit comments