ntfy 1.14.1 → 1.14.3
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.js +47 -47
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interfaces.d.ts +89 -89
- package/dist/interfaces.js +9 -8
- package/package.json +2 -2
package/dist/NtfyClient.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { URL } from 'node:url';
|
|
2
1
|
import fs from 'node:fs/promises';
|
|
2
|
+
import { URL } from 'node:url';
|
|
3
3
|
const defaultServerURL = 'https://ntfy.sh';
|
|
4
4
|
export class NtfyClient {
|
|
5
5
|
constructor(config) {
|
|
@@ -13,52 +13,6 @@ export class NtfyClient {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
function buildBroadcastActionString(action) {
|
|
17
|
-
let str = `${action.type}, ${action.label}`;
|
|
18
|
-
if (action.clear) {
|
|
19
|
-
str += ', clear=true';
|
|
20
|
-
}
|
|
21
|
-
if (action.extras && Object.keys(action.extras).length) {
|
|
22
|
-
str += `, ${Object.entries(action.extras)
|
|
23
|
-
.map(([key, value]) => `extras.${key}=${value}`)
|
|
24
|
-
.join(', ')}`;
|
|
25
|
-
}
|
|
26
|
-
if (action.intent) {
|
|
27
|
-
str += `, intent=${action.intent}`;
|
|
28
|
-
}
|
|
29
|
-
return str;
|
|
30
|
-
}
|
|
31
|
-
function ConfigHasAttachment(config) {
|
|
32
|
-
return !!config.fileAttachment;
|
|
33
|
-
}
|
|
34
|
-
function ConfigHasMessage(config) {
|
|
35
|
-
return !!config.message;
|
|
36
|
-
}
|
|
37
|
-
function buildHTTPActionString(action) {
|
|
38
|
-
let str = `${action.type}, ${action.label}, ${action.url}`;
|
|
39
|
-
if (action.method) {
|
|
40
|
-
str += `, method=${action.method.toUpperCase()}`;
|
|
41
|
-
}
|
|
42
|
-
if (action.clear) {
|
|
43
|
-
str += ', clear=true';
|
|
44
|
-
}
|
|
45
|
-
if (action.headers && Object.keys(action.headers).length) {
|
|
46
|
-
str += `, ${Object.entries(action.headers)
|
|
47
|
-
.map(([key, value]) => `headers.${key}=${value}`)
|
|
48
|
-
.join(', ')}`;
|
|
49
|
-
}
|
|
50
|
-
if (action.body) {
|
|
51
|
-
str += `, ${action.body}`;
|
|
52
|
-
}
|
|
53
|
-
return str;
|
|
54
|
-
}
|
|
55
|
-
function buildViewActionString(action) {
|
|
56
|
-
let str = `${action.type}, ${action.label}, ${action.url}`;
|
|
57
|
-
if (action.clear) {
|
|
58
|
-
str += ', clear=true';
|
|
59
|
-
}
|
|
60
|
-
return str;
|
|
61
|
-
}
|
|
62
16
|
export async function publish(publishConfig) {
|
|
63
17
|
const requestConfig = { headers: {} };
|
|
64
18
|
let postData;
|
|
@@ -152,3 +106,49 @@ export async function publish(publishConfig) {
|
|
|
152
106
|
}
|
|
153
107
|
return response.json();
|
|
154
108
|
}
|
|
109
|
+
function buildBroadcastActionString(action) {
|
|
110
|
+
let str = `${action.type}, ${action.label}`;
|
|
111
|
+
if (action.clear) {
|
|
112
|
+
str += ', clear=true';
|
|
113
|
+
}
|
|
114
|
+
if (action.extras && Object.keys(action.extras).length) {
|
|
115
|
+
str += `, ${Object.entries(action.extras)
|
|
116
|
+
.map(([key, value]) => `extras.${key}=${value}`)
|
|
117
|
+
.join(', ')}`;
|
|
118
|
+
}
|
|
119
|
+
if (action.intent) {
|
|
120
|
+
str += `, intent=${action.intent}`;
|
|
121
|
+
}
|
|
122
|
+
return str;
|
|
123
|
+
}
|
|
124
|
+
function buildHTTPActionString(action) {
|
|
125
|
+
let str = `${action.type}, ${action.label}, ${action.url}`;
|
|
126
|
+
if (action.method) {
|
|
127
|
+
str += `, method=${action.method.toUpperCase()}`;
|
|
128
|
+
}
|
|
129
|
+
if (action.clear) {
|
|
130
|
+
str += ', clear=true';
|
|
131
|
+
}
|
|
132
|
+
if (action.headers && Object.keys(action.headers).length) {
|
|
133
|
+
str += `, ${Object.entries(action.headers)
|
|
134
|
+
.map(([key, value]) => `headers.${key}=${value}`)
|
|
135
|
+
.join(', ')}`;
|
|
136
|
+
}
|
|
137
|
+
if (action.body) {
|
|
138
|
+
str += `, ${action.body}`;
|
|
139
|
+
}
|
|
140
|
+
return str;
|
|
141
|
+
}
|
|
142
|
+
function buildViewActionString(action) {
|
|
143
|
+
let str = `${action.type}, ${action.label}, ${action.url}`;
|
|
144
|
+
if (action.clear) {
|
|
145
|
+
str += ', clear=true';
|
|
146
|
+
}
|
|
147
|
+
return str;
|
|
148
|
+
}
|
|
149
|
+
function ConfigHasAttachment(config) {
|
|
150
|
+
return !!config.fileAttachment;
|
|
151
|
+
}
|
|
152
|
+
function ConfigHasMessage(config) {
|
|
153
|
+
return !!config.message;
|
|
154
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,92 +1,23 @@
|
|
|
1
1
|
export declare enum MessagePriority {
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
/** Long vibration burst, default notification sound with a pop-over notification. */
|
|
5
|
-
HIGH = 4,
|
|
6
|
-
/** Short default vibration and sound. Default notification behavior. */
|
|
7
|
-
DEFAULT = 3,
|
|
2
|
+
/** No vibration or sound. The notification will be under the fold in "Other notifications". */
|
|
3
|
+
MIN = 1,
|
|
8
4
|
/** No vibration or sound. Notification will not visibly show up until notification drawer is pulled down. */
|
|
9
5
|
LOW = 2,
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
export interface FileURL {
|
|
18
|
-
filename: string;
|
|
19
|
-
url: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* The broadcast action sends an Android broadcast intent when the action button is tapped. This allows integration
|
|
23
|
-
* into automation apps such as MacroDroid or Tasker, which basically means you can do everything your phone is
|
|
24
|
-
* capable of. Examples include taking pictures, launching/killing apps, change device settings, write/read files,
|
|
25
|
-
* etc.
|
|
26
|
-
*
|
|
27
|
-
* By default, the intent action **`io.heckel.ntfy.USER_ACTION`** is broadcast, though this can be changed with the
|
|
28
|
-
* `intent` parameter. To send extras, use the `extras` parameter. Currently, only string extras are supported.
|
|
29
|
-
*/
|
|
30
|
-
export interface BroadcastAction {
|
|
31
|
-
/** Clear notification after action button is tapped, default is `false`. */
|
|
32
|
-
clear?: boolean;
|
|
33
|
-
/** Android intent extras. */
|
|
34
|
-
extras?: Record<string, string>;
|
|
35
|
-
/** Android intent name, default is `io.heckel.ntfy.USER_ACTION`. */
|
|
36
|
-
intent?: string;
|
|
37
|
-
/** Label of the action button in the notification. */
|
|
38
|
-
label: string;
|
|
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
|
-
export interface HTTPAction {
|
|
42
|
-
/** HTTP body. */
|
|
43
|
-
body?: string;
|
|
44
|
-
/**
|
|
45
|
-
* Clear notification after HTTP request succeeds. If the request fails, the notification is not cleared.
|
|
46
|
-
* Default is `false`.
|
|
47
|
-
*/
|
|
48
|
-
clear?: boolean;
|
|
49
|
-
/** HTTP headers to pass in request. */
|
|
50
|
-
headers?: Record<string, string>;
|
|
51
|
-
/** Label of the action button in the notification. */
|
|
52
|
-
label: string;
|
|
53
|
-
/** HTTP method to use for request, default is POST ⚠️. */
|
|
54
|
-
method?: HTTPMethod;
|
|
55
|
-
/** URL to which the HTTP request will be sent. */
|
|
56
|
-
url: string;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* The view action **opens a website or app when the action button is tapped**, e.g. a browser, a Google Maps location,
|
|
60
|
-
* or even a deep link into Twitter or a show ntfy topic. How exactly the action is handled depends on how Android and
|
|
61
|
-
* your desktop browser treat the links. Normally it'll just open a link in the browser.
|
|
62
|
-
*
|
|
63
|
-
* Examples:
|
|
64
|
-
*
|
|
65
|
-
* * `http://` or `https://` will open your browser (or an app if it registered for a URL)
|
|
66
|
-
* * `mailto:` links will open your mail app, e.g. `mailto:phil@example.com`
|
|
67
|
-
* * `geo:` links will open Google Maps, e.g. `geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA`
|
|
68
|
-
* * `ntfy://` links will open ntfy (see [ntfy:// links](https://docs.ntfy.sh/subscribe/phone/#ntfy-links)), e.g.
|
|
69
|
-
* `ntfy://ntfy.sh/stats`
|
|
70
|
-
* * `twitter://` links will open Twitter, e.g. `twitter://user?screen_name=..`
|
|
71
|
-
* * ...
|
|
72
|
-
*/
|
|
73
|
-
export interface ViewAction {
|
|
74
|
-
/** Clear notification after action button is tapped, default is `false`. */
|
|
75
|
-
clear?: boolean;
|
|
76
|
-
/** Label of the action button in the notification */
|
|
77
|
-
label: string;
|
|
78
|
-
/** URL to open when action is tapped */
|
|
79
|
-
url: string;
|
|
6
|
+
/** Short default vibration and sound. Default notification behavior. */
|
|
7
|
+
DEFAULT = 3,
|
|
8
|
+
/** Long vibration burst, default notification sound with a pop-over notification. */
|
|
9
|
+
HIGH = 4,
|
|
10
|
+
/** Really long vibration bursts, default notification sound with a pop-over notification. */
|
|
11
|
+
MAX = 5
|
|
80
12
|
}
|
|
81
13
|
export type Action = ({
|
|
82
|
-
type: 'view';
|
|
83
|
-
} & ViewAction) | ({
|
|
84
14
|
type: 'broadcast';
|
|
85
15
|
} & BroadcastAction) | ({
|
|
86
16
|
type: 'http';
|
|
87
|
-
} & HTTPAction)
|
|
88
|
-
|
|
89
|
-
|
|
17
|
+
} & HTTPAction) | ({
|
|
18
|
+
type: 'view';
|
|
19
|
+
} & ViewAction);
|
|
20
|
+
export type AttachmentConfig = {
|
|
90
21
|
/**
|
|
91
22
|
* You can send images and other files to your phone as attachments to a notification. The attachments are then
|
|
92
23
|
* downloaded onto your phone (depending on size and setting automatically), and can be used from the Downloads
|
|
@@ -98,13 +29,7 @@ export type AttachmentConfig = Omit<BaseConfig, 'fileURL'> & {
|
|
|
98
29
|
* * or by passing an external URL as an attachment, e.g. `https://f-droid.org/F-Droid.apk`
|
|
99
30
|
*/
|
|
100
31
|
fileAttachment: string;
|
|
101
|
-
}
|
|
102
|
-
export type MessageConfig = BaseConfig & {
|
|
103
|
-
/**
|
|
104
|
-
* Main body of the message as shown in the notification.
|
|
105
|
-
*/
|
|
106
|
-
message: string;
|
|
107
|
-
};
|
|
32
|
+
} & Omit<BaseConfig, 'fileURL'>;
|
|
108
33
|
export interface BaseConfig {
|
|
109
34
|
/**
|
|
110
35
|
* You can add action buttons to notifications to allow yourself to react to a notification directly. This is
|
|
@@ -229,7 +154,7 @@ export interface BaseConfig {
|
|
|
229
154
|
* ntfy will automatically try to derive the file name from the URL (e.g https://example.com/flower.jpg will yield a
|
|
230
155
|
* filename flower.jpg). To override this filename, you may send use the `FileURL` object.
|
|
231
156
|
*/
|
|
232
|
-
fileURL?:
|
|
157
|
+
fileURL?: FileURL | string;
|
|
233
158
|
/**
|
|
234
159
|
* You can include an icon that will appear next to the text of the notification. Simply specify the URL that the icon
|
|
235
160
|
* is located at. The client will automatically download the icon (unless it is already cached locally, and less than
|
|
@@ -267,3 +192,78 @@ export interface BaseConfig {
|
|
|
267
192
|
*/
|
|
268
193
|
topic: string;
|
|
269
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* The broadcast action sends an Android broadcast intent when the action button is tapped. This allows integration
|
|
197
|
+
* into automation apps such as MacroDroid or Tasker, which basically means you can do everything your phone is
|
|
198
|
+
* capable of. Examples include taking pictures, launching/killing apps, change device settings, write/read files,
|
|
199
|
+
* etc.
|
|
200
|
+
*
|
|
201
|
+
* By default, the intent action **`io.heckel.ntfy.USER_ACTION`** is broadcast, though this can be changed with the
|
|
202
|
+
* `intent` parameter. To send extras, use the `extras` parameter. Currently, only string extras are supported.
|
|
203
|
+
*/
|
|
204
|
+
export interface BroadcastAction {
|
|
205
|
+
/** Clear notification after action button is tapped, default is `false`. */
|
|
206
|
+
clear?: boolean;
|
|
207
|
+
/** Android intent extras. */
|
|
208
|
+
extras?: Record<string, string>;
|
|
209
|
+
/** Android intent name, default is `io.heckel.ntfy.USER_ACTION`. */
|
|
210
|
+
intent?: string;
|
|
211
|
+
/** Label of the action button in the notification. */
|
|
212
|
+
label: string;
|
|
213
|
+
}
|
|
214
|
+
export type Config = AttachmentConfig | MessageConfig;
|
|
215
|
+
export interface FileURL {
|
|
216
|
+
filename: string;
|
|
217
|
+
url: string;
|
|
218
|
+
}
|
|
219
|
+
export interface HTTPAction {
|
|
220
|
+
/** HTTP body. */
|
|
221
|
+
body?: string;
|
|
222
|
+
/**
|
|
223
|
+
* Clear notification after HTTP request succeeds. If the request fails, the notification is not cleared.
|
|
224
|
+
* Default is `false`.
|
|
225
|
+
*/
|
|
226
|
+
clear?: boolean;
|
|
227
|
+
/** HTTP headers to pass in request. */
|
|
228
|
+
headers?: Record<string, string>;
|
|
229
|
+
/** Label of the action button in the notification. */
|
|
230
|
+
label: string;
|
|
231
|
+
/** HTTP method to use for request, default is POST ⚠️. */
|
|
232
|
+
method?: HTTPMethod;
|
|
233
|
+
/** URL to which the HTTP request will be sent. */
|
|
234
|
+
url: string;
|
|
235
|
+
}
|
|
236
|
+
export type HTTPMethod = 'delete' | 'DELETE' | 'get' | 'GET' | 'head' | 'HEAD' | 'link' | 'LINK' | 'options' | 'OPTIONS' | 'patch' | 'PATCH' | 'post' | 'POST' | 'purge' | 'PURGE' | 'put' | 'PUT' | 'unlink' | 'UNLINK';
|
|
237
|
+
export type MessageConfig = {
|
|
238
|
+
/**
|
|
239
|
+
* Main body of the message as shown in the notification.
|
|
240
|
+
*/
|
|
241
|
+
message: string;
|
|
242
|
+
} & BaseConfig;
|
|
243
|
+
export type ResponseData<T extends Config> = {
|
|
244
|
+
id: string;
|
|
245
|
+
time: number;
|
|
246
|
+
} & T;
|
|
247
|
+
/**
|
|
248
|
+
* The view action **opens a website or app when the action button is tapped**, e.g. a browser, a Google Maps location,
|
|
249
|
+
* or even a deep link into Twitter or a show ntfy topic. How exactly the action is handled depends on how Android and
|
|
250
|
+
* your desktop browser treat the links. Normally it'll just open a link in the browser.
|
|
251
|
+
*
|
|
252
|
+
* Examples:
|
|
253
|
+
*
|
|
254
|
+
* * `http://` or `https://` will open your browser (or an app if it registered for a URL)
|
|
255
|
+
* * `mailto:` links will open your mail app, e.g. `mailto:phil@example.com`
|
|
256
|
+
* * `geo:` links will open Google Maps, e.g. `geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA`
|
|
257
|
+
* * `ntfy://` links will open ntfy (see [ntfy:// links](https://docs.ntfy.sh/subscribe/phone/#ntfy-links)), e.g.
|
|
258
|
+
* `ntfy://ntfy.sh/stats`
|
|
259
|
+
* * `twitter://` links will open Twitter, e.g. `twitter://user?screen_name=..`
|
|
260
|
+
* * ...
|
|
261
|
+
*/
|
|
262
|
+
export interface ViewAction {
|
|
263
|
+
/** Clear notification after action button is tapped, default is `false`. */
|
|
264
|
+
clear?: boolean;
|
|
265
|
+
/** Label of the action button in the notification */
|
|
266
|
+
label: string;
|
|
267
|
+
/** URL to open when action is tapped */
|
|
268
|
+
url: string;
|
|
269
|
+
}
|
package/dist/interfaces.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
/* eslint-disable no-magic-numbers */
|
|
1
2
|
export var MessagePriority;
|
|
2
3
|
(function (MessagePriority) {
|
|
3
|
-
/** Really long vibration bursts, default notification sound with a pop-over notification. */
|
|
4
|
-
MessagePriority[MessagePriority["MAX"] = 5] = "MAX";
|
|
5
|
-
/** Long vibration burst, default notification sound with a pop-over notification. */
|
|
6
|
-
MessagePriority[MessagePriority["HIGH"] = 4] = "HIGH";
|
|
7
|
-
/** Short default vibration and sound. Default notification behavior. */
|
|
8
|
-
MessagePriority[MessagePriority["DEFAULT"] = 3] = "DEFAULT";
|
|
9
|
-
/** No vibration or sound. Notification will not visibly show up until notification drawer is pulled down. */
|
|
10
|
-
MessagePriority[MessagePriority["LOW"] = 2] = "LOW";
|
|
11
4
|
/** No vibration or sound. The notification will be under the fold in "Other notifications". */
|
|
12
5
|
MessagePriority[MessagePriority["MIN"] = 1] = "MIN";
|
|
6
|
+
/** No vibration or sound. Notification will not visibly show up until notification drawer is pulled down. */
|
|
7
|
+
MessagePriority[MessagePriority["LOW"] = 2] = "LOW";
|
|
8
|
+
/** Short default vibration and sound. Default notification behavior. */
|
|
9
|
+
MessagePriority[MessagePriority["DEFAULT"] = 3] = "DEFAULT";
|
|
10
|
+
/** Long vibration burst, default notification sound with a pop-over notification. */
|
|
11
|
+
MessagePriority[MessagePriority["HIGH"] = 4] = "HIGH";
|
|
12
|
+
/** Really long vibration bursts, default notification sound with a pop-over notification. */
|
|
13
|
+
MessagePriority[MessagePriority["MAX"] = 5] = "MAX";
|
|
13
14
|
})(MessagePriority || (MessagePriority = {}));
|
package/package.json
CHANGED