Skip to content

Commit bb27a99

Browse files
committed
Remove type fix, expect import type error
1 parent 4c5868d commit bb27a99

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/token.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MeiliSearchError } from "./errors";
33
import { validateUuid4 } from "./utils";
44

55
function 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 {
1717
async 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
/**

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
// This matters for the generated CJS and ESM file, UMD file is down-leveled further to support IE11
2323
// (only the syntax, URL, URLSearchParams, fetch is not IE11 compatible) with the help of Babel.
2424
"target": "es2022",
25-
"lib": ["ESNext", "dom"],
25+
"lib": ["ES2022", "dom"],
26+
// Jest global types really shouldn't be here, but for now it must
27+
"types": ["jest"],
2628
"strict": true,
2729
"noImplicitReturns": true
2830
},

0 commit comments

Comments
 (0)