0.1.1 • Published 3 months ago

web-push-edge v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

Fork of @block65/webcrypto-web-push

Send notifications using Web Push Protocol and Web Crypto APIs (compatible with both Node and Cloudflare Workers)

This fork adds support for Vercel Edge Functions.

Installation

Using yarn:

yarn add web-push-edge

Using pnpm:

pnpm add web-push-edge

Configuration

Typescript

Note This is an ESM package, if you are using Typescript, you will need to set moduleResolution to node16, nodenext or bundler in order to resolve the package exports.

Usage

import {
  type PushSubscription,
  type PushMessage,
  type VapidKeys,
  buildPushPayload,
} from '@block65/webcrypto-web-push';


// `env` could be `process.env` or `import.meta.env` depending
// on your platform or build tooling
const vapid: VapidKeys = {
  subject: env.VAPID_SUBJECT,
  publicKey: env.VAPID_SERVER_PUBLIC_KEY,
  privateKey: env.VAPID_SERVER_PRIVATE_KEY,
};

// Obtained from the client using PushManager subscribe() method:
// https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe
const subscription: PushSubscription = {
  endpoint: 'https://fcm.googleapis.com/fcm/send/...',
  expirationTime: null,
  keys: {
    p256dh: '...',
    auth: '...',
  },
};

const message: PushMessage = {
  data: "You've got mail!",
  options: {
    ttl: 60,
  },
};

const payload = await buildPushPayload(message, subscription, vapid);

// send the payload to the subscription endpoint using your favourite HTTP client
const res = await fetch(subscription.endpoint, payload);

License

This package is licensed under the MIT license. See the LICENSE file for more information.

0.1.0

3 months ago

0.0.1

3 months ago

0.0.0

3 months ago

0.0.3

3 months ago

0.1.1

3 months ago

0.0.2

3 months ago

0.0.9

3 months ago

0.0.8

3 months ago

0.0.5

3 months ago

0.0.4

3 months ago

0.0.7

3 months ago

0.0.6

3 months ago

0.3.3

3 months ago

0.3.2

3 months ago