Actual feat: started typed code from previous commit

This commit is contained in:
2025-03-10 08:31:24 +01:00
parent 7b86b11838
commit 0053234730
2 changed files with 108 additions and 2 deletions

View File

@@ -52,7 +52,7 @@
},
"private": true,
"lint-staged": {
"*.{js,ts,jsx,tsx}": "eslint --cache --fix . || true",
"*.{js,ts,jsx,tsx}": "cmd /c eslint --cache --fix . || exit 0",
"*.{js,ts,jsx,tsx,json,css,md}": "prettier --write"
},
"dependencies": {

View File

@@ -1 +1,107 @@
console.log("Happy developing ✨");
import { z } from "zod";
const messageSchema = z.object({
/**
* The message to send.
*/
message: z.string(),
/**
* The title of the message.
*/
title: z.string().optional(),
/**
* The URL to open when the notification is clicked.
*/
url: z
.object({
/**
* The URL itself.
*/
url: z.string(),
/**
* The title of the URL to be displayed.
*/
title: z.string().optional(),
})
.optional(),
priority: z
.object({
level: z.number().default(0),
retry: z.number().optional(),
expire: z.number().optional(),
callback: z.string().optional(),
})
.optional(),
sound: z.string().optional(),
timestamp: z.date().optional(),
html: z.boolean().default(false),
attachment: z
.object({
data: z.string().or(z.instanceof(File)),
type: z.string(),
})
.optional(),
users: z.array(
z.object({
name: z.string(),
token: z.string(),
devices: z.array(z.string()),
}),
),
appToken: z.string(),
});
export type PushoverMessage = z.infer<typeof messageSchema>;
export type Pushover = {
// #################################
// # Helpers #
// #################################
/**
* Get all available sounds.
*/
getSounds: () => { sounds: string[] };
/**
* Get all available devices for a user.
*/
getDevices: (userToken: string) => { devices: string[] };
// #################################
// # Sending #
// #################################
/**
* Send the notification.
*/
send: () => void;
// #################################
// # Options #
// #################################
withMessage: (message: string) => Pushover;
withTitle: (title: string) => Pushover;
withUrl: (url: { url: string; title: string }) => Pushover;
withPriority: (priority: {
level: number;
retry?: number;
expire?: number;
callback?: string;
}) => Pushover;
withSound: (sound: string) => Pushover;
withTimestamp: (timestamp: number) => Pushover;
withHtml: (enable: boolean) => Pushover;
withAttachment: (attachment: File) => Pushover;
withBase64Attachment: (attachment: {
data: string;
type: string;
}) => Pushover;
addUsers: (users: User[]) => Pushover;
};
export type User = {
name: string;
token: string;
devices: string[];
};