-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug]: Unable to use search client in cloudflare workers: Cannot bundle Node.js built-in "crypto" #1567
[bug]: Unable to use search client in cloudflare workers: Cannot bundle Node.js built-in "crypto" #1567
Comments
In the source code I'm seeing node:crypto being used
crypto.subtle.importKey and crypto.subtle.sign instead would work for this build?
As a workaround if you're not using that function, you can in the mean time remove the import of |
I took a look at it, and it gets complicated fast, it would require some code to make it work with Some examples of hmac sha256: https://lukasmurdock.com/web-hmac/ I am sure there are better examples or libraries to use as a starting point. EDIT // Utility function to convert string to Uint8Array
const str2buf = (str) => {
return new TextEncoder().encode(str);
};
// Utility function to convert ArrayBuffer to hex string
const buf2hex = (buffer) => {
return Array.from(new Uint8Array(buffer))
.map(b => b.toString(16).padStart(2, '0'))
.join('');
};
// Create key material from parent API key
const keyMaterial = await crypto.subtle.importKey(
'raw',
str2buf(parentApiKey),
{ name: 'HMAC', hash: 'SHA-256' },
false,
['sign']
);
// Generate HMAC
const signature = await crypto.subtle.sign(
'HMAC',
keyMaterial,
str2buf(queryParameters)
);
// Convert signature to hex and concatenate with query parameters
const combined = buf2hex(signature) + queryParameters;
// Convert to base64
// In our code base we use our own base64 implementation instead of btoa, I think it has something to do with "URL safe" base64
// btoa also does not exist in node, and since we work in node until we build and deploy its better to not use btoa
return btoa(combined); |
Because we are thinking about levering the new method |
@lassediercks for now the workaround would be to remove the |
thanks for the answer @Haroenv I was actually able to use the |
Description
Using version
5.10.2
we cannot bundle algolia search client for cloudflare workers since it uses Node built ins.We tried updating from
5.2.1
, which still works fine.Client
All
Version
5.10.2
Relevant log output
No response
The text was updated successfully, but these errors were encountered: