I tried to use/import the web-push library (https://github.com/web-push-libs/web-push) for node-js in a deno supabase edge function and it does not work.
My code
import * as webPush from "https://dev.jspm.io/web-push"
Deno.serve(async (req) => {
const vapidKeys = {
publicKey: '<The public Key',
privateKey: '<The private Key>',
}
const webpush = webPush;
webpush.setGCMAPIKey('<The GCM API Key>'); // TODO: I think this line times out
webpush.setVapidDetails(
'mailto:example@yourdomain.org',
vapidKeys.publicKey,
vapidKeys.privateKey
);
It looks like there are compatibility issues with the crypto libraries. I built the same app in Deno and Node and Deno crashes when processing the private key with the error:
error: Uncaught TypeError: Invalid PEM label
at SignImpl.sign (ext:deno_node/internal/crypto/sig.ts:36:33)
at sign (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/jwa/2.0.0/index.js:152:45)
at Object.sign (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/jwa/2.0.0/index.js:200:27)
at Object.jwsSign [as sign] (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/jws/4.0.0/lib/sign-stream.js:32:24)
at Object.getVapidHeaders (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/deno-web-push/3.5.0/src/vapid-helper.js:217:19)
at Object.WebPushLib.generateRequestDetails (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/deno-web-push/3.5.0/src/web-push-lib.js:253:40)
at Object.WebPushLib.sendNotification (file:///Users/aekidna/Library/Caches/deno/npm/registry.npmjs.org/deno-web-push/3.5.0/src/web-push-lib.js:310:29)
I tried to import web-push using esm with target=deno
but that causes another error related to the implementation of crypto.ECDH
(unimplemented)
I'm surprised nobody's on this.