From 992b4cfc5b6dabfe0142394f6257709a76519971 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 14 Jul 2026 19:35:49 +0100 Subject: [PATCH] refactor(deps): use native web-push types --- package.json | 1 + pnpm-lock.yaml | 10 ++++++++++ src/infra/push-web.ts | 11 +++-------- src/types/web-push.d.ts | 37 ------------------------------------- 4 files changed, 14 insertions(+), 45 deletions(-) delete mode 100644 src/types/web-push.d.ts diff --git a/package.json b/package.json index fe277f64c40b..777495dbe129 100644 --- a/package.json +++ b/package.json @@ -2093,6 +2093,7 @@ "@types/node": "26.1.0", "@types/proper-lockfile": "4.1.4", "@types/semver": "7.7.1", + "@types/web-push": "3.6.4", "@types/ws": "8.18.1", "@typescript/native-preview": "7.0.0-dev.20260707.2", "@vitest/coverage-v8": "4.1.9", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 48dda58fb658..759580629f97 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -278,6 +278,9 @@ importers: '@types/semver': specifier: 7.7.1 version: 7.7.1 + '@types/web-push': + specifier: 3.6.4 + version: 3.6.4 '@types/ws': specifier: 8.18.1 version: 8.18.1 @@ -4761,6 +4764,9 @@ packages: '@types/unist@3.0.3': resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==} + '@types/web-push@3.6.4': + resolution: {integrity: sha512-GnJmSr40H3RAnj0s34FNTcJi1hmWFV5KXugE0mYWnYhgTAHLJ/dJKAwDmvPJYMke0RplY2XE9LnM4hqSqKIjhQ==} + '@types/ws@8.18.1': resolution: {integrity: sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==} @@ -10996,6 +11002,10 @@ snapshots: '@types/unist@3.0.3': {} + '@types/web-push@3.6.4': + dependencies: + '@types/node': 26.1.0 + '@types/ws@8.18.1': dependencies: '@types/node': 26.1.0 diff --git a/src/infra/push-web.ts b/src/infra/push-web.ts index 38f6bbbc3695..33b29eb08754 100644 --- a/src/infra/push-web.ts +++ b/src/infra/push-web.ts @@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto"; import path from "node:path"; import { expectDefined } from "@openclaw/normalization-core"; +import type { PushSubscription, VapidKeys } from "web-push"; import { resolveStateDir } from "../config/paths.js"; import { createLazyRuntimeModule } from "../shared/lazy-runtime.js"; import { sha256HexPrefix } from "./crypto-digest.js"; @@ -9,10 +10,8 @@ import { createAsyncLock, tryReadJson, writeJson } from "./json-files.js"; // --- Types --- -type WebPushSubscription = { +type WebPushSubscription = PushSubscription & { subscriptionId: string; - endpoint: string; - keys: { p256dh: string; auth: string }; createdAtMs: number; updatedAtMs: number; }; @@ -21,11 +20,7 @@ type WebPushRegistrationState = { subscriptionsByEndpointHash: Record; }; -type VapidKeyPair = { - publicKey: string; - privateKey: string; - subject: string; -}; +type VapidKeyPair = VapidKeys & { subject: string }; type WebPushSendResult = { ok: boolean; diff --git a/src/types/web-push.d.ts b/src/types/web-push.d.ts deleted file mode 100644 index bde5e55765d2..000000000000 --- a/src/types/web-push.d.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** Minimal ambient types for the web-push package. */ -declare module "web-push" { - /** Browser push subscription payload used by web-push. */ - export type PushSubscription = { - endpoint: string; - keys: { - p256dh: string; - auth: string; - }; - }; - - /** Result returned after a push notification send attempt. */ - export type SendResult = { - statusCode: number; - body: string; - headers: Record; - }; - - /** VAPID public/private key pair. */ - export type VAPIDKeys = { - publicKey: string; - privateKey: string; - }; - - /** Generate a VAPID key pair. */ - export function generateVAPIDKeys(): VAPIDKeys; - - /** Configure VAPID details before sending notifications. */ - export function setVapidDetails(subject: string, publicKey: string, privateKey: string): void; - - /** Send one web push notification. */ - export function sendNotification( - subscription: PushSubscription, - payload?: string | Buffer | null, - options?: Record, - ): Promise; -}