UNPKG

@pushforge/builder

Version:

A robust, cross-platform Web Push notification library that handles VAPID authentication and payload encryption following the Web Push Protocol standard. Works in Node.js 16+, Browsers, Deno, Bun and Cloudflare Workers.

54 lines (53 loc) 2.22 kB
/** * Represents any value that can be handled by JSON.stringify without loss. * This includes primitive types such as strings, numbers, booleans, and null. */ export type JsonPrimitive = string | number | boolean | null; /** * Represents a JSON-compatible value, which can be a primitive, * an array of Jsonifiable values, or an object with string keys * and Jsonifiable values. */ export type Jsonifiable = JsonPrimitive | Jsonifiable[] | { [key: string]: Jsonifiable; }; /** * A utility type that requires at least one of the specified keys from type T. * This is useful for creating types that enforce the presence of certain properties * while allowing others to be optional. * * @template T - The base type from which keys are required. * @template Keys - The keys of T that are required. */ export type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = { [K in Keys]: Required<Pick<T, K>> & Partial<Omit<T, K>>; }[Keys] & Omit<T, Keys>; /** * Converts an ArrayBuffer or Uint8Array to a string. * * @param {ArrayBuffer | Uint8Array} s - The input array to convert. * @returns {string} The resulting string representation of the input. */ export declare const stringFromArrayBuffer: (s: ArrayBuffer | Uint8Array) => string; /** * Cross-platform function to decode a Base64 string into a binary string. * Works in both browser and Node.js environments. * * @param {string} base64String - The Base64 encoded string to decode. * @returns {string} The decoded binary string. */ export declare const base64Decode: (base64String: string) => string; /** * Extracts the public key from a JSON Web Key (JWK) and encodes it in base64 URL format. * * @param {JsonWebKey} jwk - The JSON Web Key from which to extract the public key. * @returns {string} The base64 URL encoded public key. */ export declare const getPublicKeyFromJwk: (jwk: JsonWebKey) => string; /** * Concatenates multiple Uint8Array instances into a single Uint8Array. * * @param {Uint8Array[]} arrays - An array of Uint8Array instances to concatenate. * @returns {Uint8Array} A new Uint8Array containing all the concatenated data. */ export declare const concatTypedArrays: (arrays: Uint8Array[]) => Uint8Array;