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 1
1
{
2
2
"name" : " @eppo/js-client-sdk-common" ,
3
- "version" : " 4.5.3 " ,
3
+ "version" : " 4.5.4 " ,
4
4
"description" : " Eppo SDK for client-side JavaScript applications (base for both web and react native)" ,
5
5
"main" : " dist/index.js" ,
6
6
"files" : [
Original file line number Diff line number Diff line change 1
1
import SdkKeyDecoder from './sdk-key-decoder' ;
2
2
3
3
describe ( 'SdkKeyDecoder' , ( ) => {
4
+ const decoder = new SdkKeyDecoder ( ) ;
4
5
it ( 'should decode the event ingestion hostname from the SDK key' , ( ) => {
5
- const decoder = new SdkKeyDecoder ( ) ;
6
6
const hostname = decoder . decodeEventIngestionHostName (
7
7
'zCsQuoHJxVPp895.ZWg9MTIzNDU2LmUudGVzdGluZy5lcHBvLmNsb3Vk' ,
8
8
) ;
9
9
expect ( hostname ) . toEqual ( '123456.e.testing.eppo.cloud' ) ;
10
10
} ) ;
11
11
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
+
12
20
it ( "should return null if the SDK key doesn't contain the event ingestion hostname" , ( ) => {
13
- const decoder = new SdkKeyDecoder ( ) ;
14
21
expect ( decoder . decodeEventIngestionHostName ( 'zCsQuoHJxVPp895' ) ) . toBeNull ( ) ;
15
22
expect ( decoder . decodeEventIngestionHostName ( 'zCsQuoHJxVPp895.xxxxxx' ) ) . toBeNull ( ) ;
16
23
} ) ;
Original file line number Diff line number Diff line change
1
+ import { Base64 } from 'js-base64' ;
2
+
1
3
export default class SdkKeyDecoder {
2
4
/**
3
5
* Decodes and returns the event ingestion hostname from the provided Eppo SDK key string.
@@ -7,7 +9,7 @@ export default class SdkKeyDecoder {
7
9
const encodedPayload = sdkKey . split ( '.' ) [ 1 ] ;
8
10
if ( ! encodedPayload ) return null ;
9
11
10
- const decodedPayload = Buffer . from ( encodedPayload , 'base64url' ) . toString ( 'utf-8' ) ;
12
+ const decodedPayload = Base64 . decode ( encodedPayload ) ;
11
13
const params = new URLSearchParams ( decodedPayload ) ;
12
14
return params . get ( 'eh' ) ;
13
15
}
You can’t perform that action at this time.
0 commit comments