File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @eppo/js-client-sdk-common" ,
3- "version" : " 4.5.3 " ,
3+ "version" : " 4.5.4 " ,
44 "description" : " Eppo SDK for client-side JavaScript applications (base for both web and react native)" ,
55 "main" : " dist/index.js" ,
66 "files" : [
Original file line number Diff line number Diff line change 11import SdkKeyDecoder from './sdk-key-decoder' ;
22
33describe ( 'SdkKeyDecoder' , ( ) => {
4+ const decoder = new SdkKeyDecoder ( ) ;
45 it ( 'should decode the event ingestion hostname from the SDK key' , ( ) => {
5- const decoder = new SdkKeyDecoder ( ) ;
66 const hostname = decoder . decodeEventIngestionHostName (
77 'zCsQuoHJxVPp895.ZWg9MTIzNDU2LmUudGVzdGluZy5lcHBvLmNsb3Vk' ,
88 ) ;
99 expect ( hostname ) . toEqual ( '123456.e.testing.eppo.cloud' ) ;
1010 } ) ;
1111
12+ it ( 'should decode strings with non URL-safe characters' , ( ) => {
13+ // this is not a really valid ingestion URL, but it's useful for testing the decoder
14+ const invalidUrl = 'eh=12+3456/.e.testing.eppo.cloud' ;
15+ const encoded = Buffer . from ( invalidUrl ) . toString ( 'base64url' ) ;
16+ const hostname = decoder . decodeEventIngestionHostName ( `zCsQuoHJxVPp895.${ encoded } ` ) ;
17+ expect ( hostname ) . toEqual ( '12 3456/.e.testing.eppo.cloud' ) ;
18+ } ) ;
19+
1220 it ( "should return null if the SDK key doesn't contain the event ingestion hostname" , ( ) => {
13- const decoder = new SdkKeyDecoder ( ) ;
1421 expect ( decoder . decodeEventIngestionHostName ( 'zCsQuoHJxVPp895' ) ) . toBeNull ( ) ;
1522 expect ( decoder . decodeEventIngestionHostName ( 'zCsQuoHJxVPp895.xxxxxx' ) ) . toBeNull ( ) ;
1623 } ) ;
Original file line number Diff line number Diff line change 1+ import { Base64 } from 'js-base64' ;
2+
13export default class SdkKeyDecoder {
24 /**
35 * Decodes and returns the event ingestion hostname from the provided Eppo SDK key string.
@@ -7,7 +9,7 @@ export default class SdkKeyDecoder {
79 const encodedPayload = sdkKey . split ( '.' ) [ 1 ] ;
810 if ( ! encodedPayload ) return null ;
911
10- const decodedPayload = Buffer . from ( encodedPayload , 'base64url' ) . toString ( 'utf-8' ) ;
12+ const decodedPayload = Base64 . decode ( encodedPayload ) ;
1113 const params = new URLSearchParams ( decodedPayload ) ;
1214 return params . get ( 'eh' ) ;
1315 }
You can’t perform that action at this time.
0 commit comments