File tree Expand file tree Collapse file tree 3 files changed +32
-9
lines changed
Expand file tree Collapse file tree 3 files changed +32
-9
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @lingo.dev/_sdk " : patch
3+ ---
4+
5+ Add whoami support for vNext API
Original file line number Diff line number Diff line change @@ -332,6 +332,27 @@ describe("ReplexicaEngine", () => {
332332 expect ( options . headers [ "X-API-Key" ] ) . toBe ( "test-key" ) ;
333333 expect ( result ) . toBe ( "fr" ) ;
334334 } ) ;
335+
336+ it ( "whoami should call /users/me with GET and X-API-Key header" , async ( ) => {
337+ mockFetch . mockResolvedValue ( {
338+ ok : true ,
339+ json : async ( ) => ( { id : "usr_abc" , email : "user@example.com" } ) ,
340+ } ) ;
341+
342+ const engine = new LingoDotDevEngine ( {
343+ apiKey : "test-key" ,
344+ engineId : "eng_123" ,
345+ } ) ;
346+
347+ const result = await engine . whoami ( ) ;
348+
349+ const [ url , options ] = mockFetch . mock . calls [ 0 ] ;
350+ expect ( url ) . toMatch ( / \/ u s e r s \/ m e $ / ) ;
351+ expect ( options . method ) . toBe ( "GET" ) ;
352+ expect ( options . headers [ "X-API-Key" ] ) . toBe ( "test-key" ) ;
353+ expect ( options . headers [ "Authorization" ] ) . toBeUndefined ( ) ;
354+ expect ( result ) . toEqual ( { id : "usr_abc" , email : "user@example.com" } ) ;
355+ } ) ;
335356 } ) ;
336357
337358 describe ( "hints support" , ( ) => {
Original file line number Diff line number Diff line change @@ -784,17 +784,14 @@ export class LingoDotDevEngine {
784784 async whoami (
785785 signal ?: AbortSignal ,
786786 ) : Promise < { email : string ; id : string } | null > {
787- if ( this . isVNext ) {
788- return { email : "vnext-user" , id : this . config . engineId ! } ;
789- }
787+ const url = this . isVNext
788+ ? ` ${ this . config . apiUrl } /users/me`
789+ : ` ${ this . config . apiUrl } /whoami` ;
790790
791791 try {
792- const res = await fetch ( `${ this . config . apiUrl } /whoami` , {
793- method : "POST" ,
794- headers : {
795- Authorization : `Bearer ${ this . config . apiKey } ` ,
796- "Content-Type" : "application/json" ,
797- } ,
792+ const res = await fetch ( url , {
793+ method : this . isVNext ? "GET" : "POST" ,
794+ headers : this . headers ,
798795 signal,
799796 } ) ;
800797
You can’t perform that action at this time.
0 commit comments