@allmightypush/push-webpush 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # @allmightypush/push-webpush
2
+
3
+ Web Push (VAPID) provider adapter for the push notification library.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @allmightypush/push-webpush @allmightypush/push-core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { WebPushProvider } from '@allmightypush/push-webpush';
15
+
16
+ // Create a Web Push provider with VAPID credentials
17
+ const provider = new WebPushProvider({
18
+ vapidPublicKey: 'YOUR_VAPID_PUBLIC_KEY',
19
+ vapidPrivateKey: 'YOUR_VAPID_PRIVATE_KEY',
20
+ vapidSubject: 'mailto:your-email@example.com',
21
+ });
22
+
23
+ // Use with the push core runtime
24
+ import { PushCore } from '@allmightypush/push-core';
25
+
26
+ const pushCore = new PushCore();
27
+ pushCore.configure({
28
+ providerAdapter: provider,
29
+ // ... other configuration
30
+ });
31
+ ```
32
+
33
+ ## Features
34
+
35
+ - **VAPID Authentication**: Secure authentication using Voluntary Application Server Identification
36
+ - **Status Code Mapping**: Intelligent handling of HTTP status codes with appropriate retry decisions
37
+ - **Retry-After Support**: Respects `Retry-After` headers from push services
38
+ - **Full Options Support**: Supports TTL, urgency, and topic options
39
+
40
+ ## Status Code Handling
41
+
42
+ The provider maps HTTP status codes to appropriate actions:
43
+
44
+ | Status Code | Description | Retry? |
45
+ |------------|-------------|--------|
46
+ | 201 | Success | No |
47
+ | 410 | Subscription expired | No |
48
+ | 429 | Rate limited | Yes (with backoff) |
49
+ | 5xx | Server error | Yes (with backoff) |
50
+ | 4xx (other) | Client error | No |
51
+
52
+ ## Send Options
53
+
54
+ The provider supports the following send options:
55
+
56
+ - **ttl**: Time-to-live in seconds (how long the push service should queue the message)
57
+ - **urgency**: Priority hint for the push service (`'very-low'`, `'low'`, `'normal'`, `'high'`)
58
+ - **topic**: Topic for replacing previous notifications
59
+
60
+ Example:
61
+
62
+ ```typescript
63
+ await pushCore.sendNotification(
64
+ subscription,
65
+ {
66
+ title: 'Breaking News',
67
+ body: 'Important update',
68
+ },
69
+ {
70
+ ttl: 3600, // 1 hour
71
+ urgency: 'high',
72
+ topic: 'news-alerts',
73
+ }
74
+ );
75
+ ```
76
+
77
+ ## VAPID Keys
78
+
79
+ To generate VAPID keys, you can use the web-push library:
80
+
81
+ ```bash
82
+ npx web-push generate-vapid-keys
83
+ ```
84
+
85
+ Or use the CLI tool from `@allmightypush/push-cli`:
86
+
87
+ ```bash
88
+ npx @allmightypush/push-cli generate-keys
89
+ ```
90
+
91
+ ## Error Handling
92
+
93
+ The provider handles various error scenarios:
94
+
95
+ - **Network Errors**: Automatically retried
96
+ - **Expired Subscriptions (410)**: Marked as expired, not retried
97
+ - **Rate Limiting (429)**: Retried with exponential backoff, respects `Retry-After` header
98
+ - **Server Errors (5xx)**: Retried with exponential backoff
99
+ - **Client Errors (4xx)**: Not retried (except 429)
100
+
101
+ ## TypeScript Support
102
+
103
+ This package is written in TypeScript and includes full type definitions.
104
+
105
+ ## License
106
+
107
+ MIT
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebPushProvider = void 0;
4
+ var web_push_provider_1 = require("./web-push-provider");
5
+ Object.defineProperty(exports, "WebPushProvider", { enumerable: true, get: function () { return web_push_provider_1.WebPushProvider; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAKA,yDAA6E;AAApE,oHAAA,eAAe,OAAA"}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WebPushProvider = void 0;
7
+ const web_push_1 = __importDefault(require("web-push"));
8
+ class WebPushProvider {
9
+ constructor(config) {
10
+ web_push_1.default.setVapidDetails(config.vapidSubject, config.vapidPublicKey, config.vapidPrivateKey);
11
+ }
12
+ getName() {
13
+ return 'web-push';
14
+ }
15
+ async send(subscription, payload, options) {
16
+ try {
17
+ const pushSubscription = {
18
+ endpoint: subscription.endpoint,
19
+ keys: {
20
+ p256dh: subscription.keys.p256dh,
21
+ auth: subscription.keys.auth,
22
+ },
23
+ };
24
+ const payloadString = JSON.stringify(payload);
25
+ const webPushOptions = {};
26
+ if (options.ttl !== undefined) {
27
+ webPushOptions.TTL = options.ttl;
28
+ }
29
+ if (options.urgency) {
30
+ webPushOptions.urgency = options.urgency;
31
+ }
32
+ if (options.topic) {
33
+ webPushOptions.topic = options.topic;
34
+ }
35
+ const response = await web_push_1.default.sendNotification(pushSubscription, payloadString, webPushOptions);
36
+ return {
37
+ success: true,
38
+ statusCode: response.statusCode,
39
+ shouldRetry: false,
40
+ };
41
+ }
42
+ catch (error) {
43
+ const statusCode = error.statusCode || error.status;
44
+ let retryAfter;
45
+ if (error.headers && error.headers['retry-after']) {
46
+ const retryAfterValue = error.headers['retry-after'];
47
+ if (typeof retryAfterValue === 'string') {
48
+ const parsed = parseInt(retryAfterValue, 10);
49
+ if (!isNaN(parsed)) {
50
+ retryAfter = parsed;
51
+ }
52
+ }
53
+ else if (typeof retryAfterValue === 'number') {
54
+ retryAfter = retryAfterValue;
55
+ }
56
+ }
57
+ return this.mapErrorToResult(error, statusCode, retryAfter);
58
+ }
59
+ }
60
+ mapErrorToResult(error, statusCode, retryAfter) {
61
+ if (statusCode === 410) {
62
+ return {
63
+ success: false,
64
+ statusCode,
65
+ error: new Error('Subscription expired (410 Gone)'),
66
+ shouldRetry: false,
67
+ };
68
+ }
69
+ if (statusCode === 429) {
70
+ return {
71
+ success: false,
72
+ statusCode,
73
+ error: new Error('Rate limited (429 Too Many Requests)'),
74
+ shouldRetry: true,
75
+ retryAfter,
76
+ };
77
+ }
78
+ if (statusCode && statusCode >= 500 && statusCode < 600) {
79
+ return {
80
+ success: false,
81
+ statusCode,
82
+ error: new Error(`Server error (${statusCode}): ${error.message || 'Unknown error'}`),
83
+ shouldRetry: true,
84
+ retryAfter,
85
+ };
86
+ }
87
+ if (statusCode && statusCode >= 400 && statusCode < 500) {
88
+ return {
89
+ success: false,
90
+ statusCode,
91
+ error: new Error(`Client error (${statusCode}): ${error.message || 'Unknown error'}`),
92
+ shouldRetry: false,
93
+ };
94
+ }
95
+ return {
96
+ success: false,
97
+ statusCode,
98
+ error: error instanceof Error ? error : new Error(String(error)),
99
+ shouldRetry: true,
100
+ };
101
+ }
102
+ }
103
+ exports.WebPushProvider = WebPushProvider;
104
+ //# sourceMappingURL=web-push-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-push-provider.js","sourceRoot":"","sources":["../../src/web-push-provider.ts"],"names":[],"mappings":";;;;;;AAIA,wDAA+B;AA2B/B,MAAa,eAAe;IAK1B,YAAY,MAA6B;QAEvC,kBAAO,CAAC,eAAe,CACrB,MAAM,CAAC,YAAY,EACnB,MAAM,CAAC,cAAc,EACrB,MAAM,CAAC,eAAe,CACvB,CAAC;IACJ,CAAC;IAMD,OAAO;QACL,OAAO,UAAU,CAAC;IACpB,CAAC;IAiBD,KAAK,CAAC,IAAI,CACR,YAA0B,EAC1B,OAA4B,EAC5B,OAAoB;QAEpB,IAAI,CAAC;YAEH,MAAM,gBAAgB,GAAG;gBACvB,QAAQ,EAAE,YAAY,CAAC,QAAQ;gBAC/B,IAAI,EAAE;oBACJ,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,MAAM;oBAChC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI;iBAC7B;aACF,CAAC;YAGF,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAG9C,MAAM,cAAc,GAA2B,EAAE,CAAC;YAGlD,IAAI,OAAO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AAW,EAAE,IAAI;SAClB,CAAC;IACJ,CAAC;CACF;AA7KD,0CA6KC"}
@@ -0,0 +1,2 @@
1
+ export { WebPushProvider } from './web-push-provider';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAyB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,97 @@
1
+ import webPush from 'web-push';
2
+ export class WebPushProvider {
3
+ constructor(config) {
4
+ webPush.setVapidDetails(config.vapidSubject, config.vapidPublicKey, config.vapidPrivateKey);
5
+ }
6
+ getName() {
7
+ return 'web-push';
8
+ }
9
+ async send(subscription, payload, options) {
10
+ try {
11
+ const pushSubscription = {
12
+ endpoint: subscription.endpoint,
13
+ keys: {
14
+ p256dh: subscription.keys.p256dh,
15
+ auth: subscription.keys.auth,
16
+ },
17
+ };
18
+ const payloadString = JSON.stringify(payload);
19
+ const webPushOptions = {};
20
+ if (options.ttl !== undefined) {
21
+ webPushOptions.TTL = options.ttl;
22
+ }
23
+ if (options.urgency) {
24
+ webPushOptions.urgency = options.urgency;
25
+ }
26
+ if (options.topic) {
27
+ webPushOptions.topic = options.topic;
28
+ }
29
+ const response = await webPush.sendNotification(pushSubscription, payloadString, webPushOptions);
30
+ return {
31
+ success: true,
32
+ statusCode: response.statusCode,
33
+ shouldRetry: false,
34
+ };
35
+ }
36
+ catch (error) {
37
+ const statusCode = error.statusCode || error.status;
38
+ let retryAfter;
39
+ if (error.headers && error.headers['retry-after']) {
40
+ const retryAfterValue = error.headers['retry-after'];
41
+ if (typeof retryAfterValue === 'string') {
42
+ const parsed = parseInt(retryAfterValue, 10);
43
+ if (!isNaN(parsed)) {
44
+ retryAfter = parsed;
45
+ }
46
+ }
47
+ else if (typeof retryAfterValue === 'number') {
48
+ retryAfter = retryAfterValue;
49
+ }
50
+ }
51
+ return this.mapErrorToResult(error, statusCode, retryAfter);
52
+ }
53
+ }
54
+ mapErrorToResult(error, statusCode, retryAfter) {
55
+ if (statusCode === 410) {
56
+ return {
57
+ success: false,
58
+ statusCode,
59
+ error: new Error('Subscription expired (410 Gone)'),
60
+ shouldRetry: false,
61
+ };
62
+ }
63
+ if (statusCode === 429) {
64
+ return {
65
+ success: false,
66
+ statusCode,
67
+ error: new Error('Rate limited (429 Too Many Requests)'),
68
+ shouldRetry: true,
69
+ retryAfter,
70
+ };
71
+ }
72
+ if (statusCode && statusCode >= 500 && statusCode < 600) {
73
+ return {
74
+ success: false,
75
+ statusCode,
76
+ error: new Error(`Server error (${statusCode}): ${error.message || 'Unknown error'}`),
77
+ shouldRetry: true,
78
+ retryAfter,
79
+ };
80
+ }
81
+ if (statusCode && statusCode >= 400 && statusCode < 500) {
82
+ return {
83
+ success: false,
84
+ statusCode,
85
+ error: new Error(`Client error (${statusCode}): ${error.message || 'Unknown error'}`),
86
+ shouldRetry: false,
87
+ };
88
+ }
89
+ return {
90
+ success: false,
91
+ statusCode,
92
+ error: error instanceof Error ? error : new Error(String(error)),
93
+ shouldRetry: true,
94
+ };
95
+ }
96
+ }
97
+ //# sourceMappingURL=web-push-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-push-provider.js","sourceRoot":"","sources":["../../src/web-push-provider.ts"],"names":[],"mappings":"AAIA,OAAO,OAAO,MAAM,UAAU,CAAC;AA2B/B,MAAM,OAAO,eAAe;IAK1B,YAAY,MAA6B;QAEvC,OAAO,CAAC,eAAe,CACrB,MAAM,CAAC,YAAY,EACnB,MAAM,CAAC,cAAc,EACrB,MAAM,CAAC,eAAe,CACvB,CAAC;IACJ,CAAC;IAMD,OAAO;QACL,OAAO,UAAU,CAAC;IACpB,CAAC;IAiBD,KAAK,CAAC,IAAI,CACR,YAA0B,EAC1B,OAA4B,EAC5B,OAAoB;QAEpB,IAAI,CAAC;YAEH,MAAM,gBAAgB,GAAG;gBACvB,QAAQ,EAAE,YAAY,CAAC,QAAQ;gBAC/B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,IAAI,eAAe,EAAE,CAAC;gBACrF,WAAW,EAAE,KAAK;aACnB,CAAC;QACJ,CAAC;QAGD,OAAO;YACL,OAAO,EAAE,KAAK;YACd,UAAU;YACV,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAChE,WAAW,EAAE,IAAI;SAClB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export { WebPushProvider, WebPushProviderConfig } from './web-push-provider';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { ProviderAdapter, Subscription, NotificationPayload, SendOptions, ProviderResult } from '@allmightypush/push-core';
2
+ export interface WebPushProviderConfig {
3
+ vapidPublicKey: string;
4
+ vapidPrivateKey: string;
5
+ vapidSubject: string;
6
+ }
7
+ export declare class WebPushProvider implements ProviderAdapter {
8
+ constructor(config: WebPushProviderConfig);
9
+ getName(): string;
10
+ send(subscription: Subscription, payload: NotificationPayload, options: SendOptions): Promise<ProviderResult>;
11
+ private mapErrorToResult;
12
+ }
13
+ //# sourceMappingURL=web-push-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-push-provider.d.ts","sourceRoot":"","sources":["../../src/web-push-provider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,cAAc,EACf,MAAM,0BAA0B,CAAC;AAKlC,MAAM,WAAW,qBAAqB;IAEpC,cAAc,EAAE,MAAM,CAAC;IAEvB,eAAe,EAAE,MAAM,CAAC;IAExB,YAAY,EAAE,MAAM,CAAC;CACtB;AAQD,qBAAa,eAAgB,YAAW,eAAe;gBAKzC,MAAM,EAAE,qBAAqB;IAazC,OAAO,IAAI,MAAM;IAmBX,IAAI,CACR,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,cAAc,CAAC;IA6E1B,OAAO,CAAC,gBAAgB;CAuDzB"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@allmightypush/push-webpush",
3
+ "version": "1.0.0",
4
+ "description": "Web Push (VAPID) provider adapter for push notification library",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/cjs/index.js",
11
+ "import": "./dist/esm/index.js",
12
+ "types": "./dist/types/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "npm run build:cjs && npm run build:esm && npm run build:types",
20
+ "build:cjs": "tsc -p tsconfig.cjs.json",
21
+ "build:esm": "tsc -p tsconfig.esm.json",
22
+ "build:types": "tsc -p tsconfig.types.json",
23
+ "test": "jest --passWithNoTests",
24
+ "test:watch": "jest --watch",
25
+ "test:coverage": "jest --coverage --passWithNoTests",
26
+ "clean": "rm -rf dist"
27
+ },
28
+ "keywords": [
29
+ "push",
30
+ "notification",
31
+ "webpush",
32
+ "vapid"
33
+ ],
34
+ "author": "Samtes64",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/Samtes64/all-mighty-push.git",
39
+ "directory": "packages/push-webpush"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/Samtes64/all-mighty-push/issues"
43
+ },
44
+ "homepage": "https://github.com/Samtes64/all-mighty-push/tree/main/packages/push-webpush#readme",
45
+ "dependencies": {
46
+ "@allmightypush/push-core": "^1.0.0",
47
+ "web-push": "^3.6.6"
48
+ },
49
+ "devDependencies": {
50
+ "@types/web-push": "^3.6.3"
51
+ },
52
+ "engines": {
53
+ "node": ">=16.0.0"
54
+ }
55
+ }