1
- const fetch = require ( 'isomorphic-unfetch' )
1
+ import fetch from 'isomorphic-unfetch'
2
2
3
3
function checkInputs ( namespace , text , level , options ) {
4
- if ( options . url === undefined ) options . url = 'https://pushnotice.chat/api/v1/chatnotice'
5
- if ( options . debug === undefined ) options . debug = false
6
- if ( options . env === undefined ) options . env = undefined
4
+ if ( options . url === undefined ) {
5
+ options . url = 'https://pushnotice.chat/api/v1/chatnotice'
6
+ }
7
+
8
+ if ( options . debug === undefined ) {
9
+ options . debug = false
10
+ }
11
+
12
+ if ( options . env === undefined ) {
13
+ options . env = undefined
14
+ }
15
+
7
16
if ( options . disabled === true ) {
8
17
return { error : { title : 'Disabled' , message : 'disabled not sending the notification' } }
9
18
}
19
+
10
20
if ( options . chat === undefined ) {
11
21
return { error : { title : 'MissingChatObject' , message : 'chat object has to be provided' } }
12
22
}
23
+
13
24
if ( options . chat ?. id === undefined ) {
14
25
return { error : { title : 'MissingChatId' , message : 'chat id has to be provided' } }
15
26
}
27
+
16
28
if ( options . chat ?. secret === undefined ) {
17
29
return { error : { title : 'MissingChatSecret' , message : 'chat secret has to be provided' } }
18
30
}
31
+
19
32
if ( namespace === undefined ) {
20
33
return { error : { title : 'MissingNamespace' , message : 'namespace has to be provided' } }
21
34
}
35
+
22
36
if ( typeof namespace !== 'string' && ! ( namespace instanceof String ) ) {
23
37
return { error : { title : 'NamespaceMustBeString' , message : 'namespace must be a String' } }
24
38
}
39
+
25
40
if ( text === undefined && text === '' ) {
26
41
return { error : { title : 'MissingText' , message : 'text has to be provided' } }
27
42
}
43
+
28
44
if ( typeof text !== 'string' && ! ( text instanceof String ) ) {
29
45
return { error : { title : 'TextMustBeString' , message : 'text must be a String' } }
30
46
}
47
+
31
48
if ( level === undefined ) {
32
49
return { error : { title : 'MissingLevel' , message : 'level has to be provided' } }
33
50
}
51
+
34
52
if ( typeof level !== 'string' && ! ( level instanceof String ) ) {
35
53
return { error : { title : 'LevelMustBeString' , message : 'level must be a String' } }
36
54
}
@@ -65,7 +83,7 @@ async function sendRequest(namespace, text, level = 'INFO', options = {}) {
65
83
if ( ! body . ok && body . name !== 'notificationQueued' ) {
66
84
return { error : { title : 'ApiRequestFailed' , message : 'Error sending Notification to PushNotice API' } }
67
85
}
68
- } catch ( err ) {
86
+ } catch {
69
87
return { error : { title : 'ApiRequestFailed' , message : 'Error sending Notification to PushNotice API' } }
70
88
}
71
89
@@ -76,4 +94,4 @@ function pnotice(namespace, options = {}) {
76
94
return ( text , level = 'INFO' ) => sendRequest ( namespace , text , level , options )
77
95
}
78
96
79
- module . exports = pnotice
97
+ export default pnotice
0 commit comments