mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
refactor(deps): use native web-push types
This commit is contained in:
@@ -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",
|
||||
|
||||
Generated
+10
@@ -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
|
||||
|
||||
@@ -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<string, WebPushSubscription>;
|
||||
};
|
||||
|
||||
type VapidKeyPair = {
|
||||
publicKey: string;
|
||||
privateKey: string;
|
||||
subject: string;
|
||||
};
|
||||
type VapidKeyPair = VapidKeys & { subject: string };
|
||||
|
||||
type WebPushSendResult = {
|
||||
ok: boolean;
|
||||
|
||||
Vendored
-37
@@ -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<string, string>;
|
||||
};
|
||||
|
||||
/** 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<string, unknown>,
|
||||
): Promise<SendResult>;
|
||||
}
|
||||
Reference in New Issue
Block a user