ntfy 1.9.0 → 1.10.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/dist/NtfyClient.d.ts +1 -1
- package/dist/NtfyClient.js +50 -39
- package/dist/interfaces.d.ts +5 -2
- package/package.json +2 -5
package/dist/NtfyClient.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export declare class NtfyClient {
|
|
|
4
4
|
constructor(config?: Partial<BaseConfig>);
|
|
5
5
|
publish<T extends Config>(config: T): Promise<ResponseData<T>>;
|
|
6
6
|
}
|
|
7
|
-
export declare function publish<T extends Config>(
|
|
7
|
+
export declare function publish<T extends Config>(publishConfig: T): Promise<ResponseData<T>>;
|
package/dist/NtfyClient.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { URL } from 'node:url';
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
|
-
import axios, { AxiosHeaders } from 'axios';
|
|
4
3
|
const defaultServerURL = 'https://ntfy.sh';
|
|
5
4
|
export class NtfyClient {
|
|
6
5
|
constructor(config) {
|
|
@@ -60,11 +59,11 @@ function buildViewActionString(action) {
|
|
|
60
59
|
}
|
|
61
60
|
return str;
|
|
62
61
|
}
|
|
63
|
-
export async function publish(
|
|
64
|
-
const
|
|
62
|
+
export async function publish(publishConfig) {
|
|
63
|
+
const requestConfig = { headers: {} };
|
|
65
64
|
let postData;
|
|
66
|
-
if (
|
|
67
|
-
|
|
65
|
+
if (publishConfig.actions && publishConfig.actions.length) {
|
|
66
|
+
requestConfig.headers['X-Actions'] = publishConfig.actions
|
|
68
67
|
.map(action => {
|
|
69
68
|
switch (action.type) {
|
|
70
69
|
case 'broadcast': {
|
|
@@ -81,63 +80,75 @@ export async function publish(config) {
|
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
})
|
|
84
|
-
.join('; ')
|
|
83
|
+
.join('; ');
|
|
85
84
|
}
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
if (typeof
|
|
89
|
-
|
|
85
|
+
if (publishConfig.authorization) {
|
|
86
|
+
requestConfig.withCredentials = true;
|
|
87
|
+
if (typeof publishConfig.authorization === 'string') {
|
|
88
|
+
requestConfig.headers.Authorization = `Basic ${publishConfig.authorization}`;
|
|
90
89
|
}
|
|
91
90
|
else {
|
|
92
|
-
|
|
91
|
+
const credentials = `${publishConfig.authorization.username}:${publishConfig.authorization.password}`;
|
|
92
|
+
requestConfig.headers.Authorization = `Basic ${Buffer.from(credentials).toString('base64')}`;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
if (
|
|
96
|
-
|
|
95
|
+
if (publishConfig.delay) {
|
|
96
|
+
requestConfig.headers['X-Delay'] = publishConfig.delay;
|
|
97
97
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
98
|
+
if (publishConfig.disableCache) {
|
|
99
|
+
requestConfig.headers['X-Cache'] = 'no';
|
|
100
100
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
101
|
+
if (publishConfig.disableFirebase) {
|
|
102
|
+
requestConfig.headers['X-Firebase'] = 'no';
|
|
103
103
|
}
|
|
104
|
-
if (
|
|
105
|
-
|
|
104
|
+
if (publishConfig.emailAddress) {
|
|
105
|
+
requestConfig.headers['X-Email'] = publishConfig.emailAddress;
|
|
106
106
|
}
|
|
107
|
-
if (ConfigHasMessage(
|
|
108
|
-
if (typeof
|
|
109
|
-
|
|
107
|
+
if (ConfigHasMessage(publishConfig) && publishConfig.fileURL) {
|
|
108
|
+
if (typeof publishConfig.fileURL === 'string') {
|
|
109
|
+
requestConfig.headers['X-Attach'] = publishConfig.fileURL;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
requestConfig.headers['X-Attach'] = publishConfig.fileURL.url;
|
|
113
|
+
requestConfig.headers['X-Filename'] = publishConfig.fileURL.filename;
|
|
110
114
|
}
|
|
111
|
-
axiosConfig.headers.set('X-Attach', config.fileURL.url);
|
|
112
|
-
axiosConfig.headers.set('X-Filename', config.fileURL.filename);
|
|
113
115
|
}
|
|
114
|
-
if (ConfigHasAttachment(
|
|
116
|
+
if (ConfigHasAttachment(publishConfig)) {
|
|
115
117
|
try {
|
|
116
|
-
postData = await fs.readFile(
|
|
118
|
+
postData = await fs.readFile(publishConfig.fileAttachment);
|
|
117
119
|
}
|
|
118
120
|
catch (error) {
|
|
119
121
|
console.error('Error while reading file:', error.message);
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
|
-
else if (
|
|
123
|
-
postData =
|
|
124
|
+
else if (publishConfig.message) {
|
|
125
|
+
postData = publishConfig.message;
|
|
124
126
|
}
|
|
125
127
|
else {
|
|
126
128
|
throw new Error('No message or file attachment specified');
|
|
127
129
|
}
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
+
if (publishConfig.iconURL) {
|
|
131
|
+
requestConfig.headers['X-Icon'] = publishConfig.iconURL;
|
|
132
|
+
}
|
|
133
|
+
if (publishConfig.priority) {
|
|
134
|
+
requestConfig.headers['X-Priority'] = publishConfig.priority.toString();
|
|
130
135
|
}
|
|
131
|
-
if (
|
|
132
|
-
|
|
136
|
+
if (publishConfig.tags && publishConfig.tags.length) {
|
|
137
|
+
requestConfig.headers['X-Tags'] =
|
|
138
|
+
typeof publishConfig.tags === 'string' ? publishConfig.tags : publishConfig.tags.join(',');
|
|
133
139
|
}
|
|
134
|
-
if (
|
|
135
|
-
|
|
140
|
+
if (publishConfig.title) {
|
|
141
|
+
requestConfig.headers['X-Title'] = publishConfig.title;
|
|
136
142
|
}
|
|
137
|
-
|
|
138
|
-
|
|
143
|
+
const url = new URL(publishConfig.topic, publishConfig.server || defaultServerURL);
|
|
144
|
+
const response = await fetch(url.href, {
|
|
145
|
+
body: postData,
|
|
146
|
+
credentials: requestConfig.withCredentials ? 'include' : 'omit',
|
|
147
|
+
headers: requestConfig.headers,
|
|
148
|
+
method: 'POST',
|
|
149
|
+
});
|
|
150
|
+
if (!response.ok) {
|
|
151
|
+
throw new Error(`Error while publishing message: ${response.statusText}`);
|
|
139
152
|
}
|
|
140
|
-
|
|
141
|
-
const { data } = await axios.post(url.href, postData, axiosConfig);
|
|
142
|
-
return data;
|
|
153
|
+
return response.json();
|
|
143
154
|
}
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AxiosBasicCredentials, Method as HTTPMethod } from 'axios';
|
|
2
1
|
export declare enum MessagePriority {
|
|
3
2
|
/** Really long vibration bursts, default notification sound with a pop-over notification. */
|
|
4
3
|
MAX = 5,
|
|
@@ -38,6 +37,7 @@ export interface BroadcastAction {
|
|
|
38
37
|
/** Label of the action button in the notification. */
|
|
39
38
|
label: string;
|
|
40
39
|
}
|
|
40
|
+
export type HTTPMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
|
|
41
41
|
export interface HTTPAction {
|
|
42
42
|
/** HTTP body. */
|
|
43
43
|
body?: string;
|
|
@@ -130,7 +130,10 @@ export interface BaseConfig {
|
|
|
130
130
|
*
|
|
131
131
|
* Use either basic credentials or an access token.
|
|
132
132
|
*/
|
|
133
|
-
authorization?:
|
|
133
|
+
authorization?: {
|
|
134
|
+
password: string;
|
|
135
|
+
username: string;
|
|
136
|
+
} | string;
|
|
134
137
|
/**
|
|
135
138
|
* You can define which URL to open when a notification is clicked. This may be useful if your notification is related
|
|
136
139
|
* to a Zabbix alert or a transaction that you'd like to provide the deep-link for. Tapping the notification will open
|
package/package.json
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Florian Imdahl <git@ffflorian.de>",
|
|
3
|
-
"dependencies": {
|
|
4
|
-
"axios": "1.13.2"
|
|
5
|
-
},
|
|
6
3
|
"description": "Send notifications over ntfy.sh.",
|
|
7
4
|
"devDependencies": {
|
|
8
5
|
"rimraf": "6.1.0",
|
|
@@ -29,6 +26,6 @@
|
|
|
29
26
|
"dist": "yarn clean && yarn build"
|
|
30
27
|
},
|
|
31
28
|
"type": "module",
|
|
32
|
-
"version": "1.
|
|
33
|
-
"gitHead": "
|
|
29
|
+
"version": "1.10.0",
|
|
30
|
+
"gitHead": "558b5c962cd6ad6e42e7c4917294cfddd2e60599"
|
|
34
31
|
}
|