@@ -3,7 +3,7 @@ import { MeiliSearchError } from "./errors";
33import { validateUuid4 } from "./utils" ;
44
55function encode64 ( data : unknown ) : string {
6- return btoa ( JSON . stringify ( data ) )
6+ return btoa ( JSON . stringify ( data ) ) ;
77}
88
99/**
@@ -17,36 +17,37 @@ function encode64(data: unknown): string {
1717async function sign (
1818 apiKey : string ,
1919 encodedHeader : string ,
20- encodedPayload : string
20+ encodedPayload : string ,
2121) : Promise < string > {
2222 // missing crypto global for Node.js 18
2323 const localCrypto =
24- typeof crypto === 'undefined'
25- ? ( await import ( 'node:crypto' ) ) . webcrypto
26- : crypto
24+ typeof crypto === "undefined"
25+ ? // @ts -expect-error: Need to add @types/node for this and remove dom lib
26+ ( await import ( "node:crypto" ) ) . webcrypto
27+ : crypto ;
2728
28- const textEncoder = new TextEncoder ( )
29+ const textEncoder = new TextEncoder ( ) ;
2930
3031 const cryptoKey = await localCrypto . subtle . importKey (
31- ' raw' ,
32+ " raw" ,
3233 textEncoder . encode ( apiKey ) ,
33- { name : ' HMAC' , hash : ' SHA-256' } ,
34+ { name : " HMAC" , hash : " SHA-256" } ,
3435 false ,
35- [ ' sign' ]
36- )
36+ [ " sign" ] ,
37+ ) ;
3738
3839 const signature = await localCrypto . subtle . sign (
39- ' HMAC' ,
40+ " HMAC" ,
4041 cryptoKey ,
41- textEncoder . encode ( `${ encodedHeader } .${ encodedPayload } ` )
42- )
42+ textEncoder . encode ( `${ encodedHeader } .${ encodedPayload } ` ) ,
43+ ) ;
4344
4445 const digest = btoa ( String . fromCharCode ( ...new Uint8Array ( signature ) ) )
45- . replace ( / \+ / g, '-' )
46- . replace ( / \/ / g, '_' )
47- . replace ( / = / g, '' )
46+ . replace ( / \+ / g, "-" )
47+ . replace ( / \/ / g, "_" )
48+ . replace ( / = / g, "" ) ;
4849
49- return digest
50+ return digest ;
5051}
5152
5253/**
0 commit comments