@notificationapi/react 0.0.34 → 0.0.36
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/README.md +1 -1
- package/dist/assets/AntdIcon.js +1 -1
- package/dist/assets/CloseOutlined.js +13 -0
- package/dist/assets/Notification.js +17 -16
- package/dist/assets/PreferenceInput.js +1470 -0
- package/dist/assets/PurePanel.js +32 -42
- package/dist/assets/WebPushOptInMessage.js +478 -0
- package/dist/assets/button.js +50 -50
- package/dist/assets/colors.js +25 -20840
- package/dist/assets/compact-item.js +860 -0
- package/dist/assets/index.js +11 -9
- package/dist/assets/index2.js +10 -9
- package/dist/assets/index3.js +2303 -3150
- package/dist/assets/presets.js +22 -22
- package/dist/assets/reactNode.js +20821 -0
- package/dist/components/Notifications/Inbox.js +81 -78
- package/dist/components/Notifications/NotificationFeed.js +59 -31
- package/dist/components/Notifications/NotificationLauncher.js +61 -41
- package/dist/components/Notifications/NotificationPopup.js +72 -65
- package/dist/components/Preferences/NotificationPreferencesInline.d.ts +1 -1
- package/dist/components/Preferences/NotificationPreferencesInline.js +39 -5
- package/dist/components/Preferences/NotificationPreferencesPopup.d.ts +1 -1
- package/dist/components/Preferences/NotificationPreferencesPopup.js +463 -464
- package/dist/components/Preferences/PreferenceInput.js +5 -1466
- package/dist/components/Preferences/Preferences.js +24 -23
- package/dist/components/Provider/index.d.ts +9 -1
- package/dist/components/Provider/index.js +211 -156
- package/dist/components/WebPush/WebPushOptInMessage.d.ts +14 -0
- package/dist/components/WebPush/WebPushOptInMessage.js +8 -0
- package/package.json +2 -2
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { createContext as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
`https://${
|
|
1
|
+
import { jsx as z } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as Q, useState as I, useCallback as m, useMemo as X, useRef as T, useEffect as S, useContext as Y } from "react";
|
|
3
|
+
const Z = async (e, r, o, a, f, b, h) => {
|
|
4
|
+
const l = ee(a, f, b), g = await fetch(
|
|
5
|
+
`https://${r}/${a}/users/${encodeURIComponent(
|
|
6
6
|
f
|
|
7
|
-
)}/${
|
|
7
|
+
)}/${o}`,
|
|
8
8
|
{
|
|
9
9
|
method: e,
|
|
10
10
|
body: JSON.stringify(h),
|
|
11
11
|
headers: {
|
|
12
|
-
Authorization: `Basic ${
|
|
12
|
+
Authorization: `Basic ${l}`
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
);
|
|
16
16
|
try {
|
|
17
|
-
return await
|
|
17
|
+
return await g.json();
|
|
18
18
|
} catch {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
-
},
|
|
21
|
+
}, ee = (e, r, o) => btoa(o ? e + ":" + r + ":" + o : e + ":" + r), H = {
|
|
22
22
|
host: "api.notificationapi.com",
|
|
23
23
|
websocketHost: "ws.notificationapi.com",
|
|
24
24
|
userId: "",
|
|
@@ -31,76 +31,79 @@ const _ = async (e, c, i, a, f, I, h) => {
|
|
|
31
31
|
onNewInAppNotifications: void 0,
|
|
32
32
|
keepWebSocketAliveForSeconds: 86400
|
|
33
33
|
// 24 hours
|
|
34
|
-
},
|
|
35
|
-
config:
|
|
34
|
+
}, i = {
|
|
35
|
+
config: H,
|
|
36
36
|
init: function(e) {
|
|
37
|
-
return this.config = { ...
|
|
37
|
+
return this.config = { ...H, ...e }, {
|
|
38
38
|
...this
|
|
39
39
|
};
|
|
40
40
|
},
|
|
41
41
|
rest: {
|
|
42
|
-
generic: function(e,
|
|
43
|
-
return
|
|
42
|
+
generic: function(e, r, o) {
|
|
43
|
+
return Z(
|
|
44
44
|
e,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
i.config.host,
|
|
46
|
+
r,
|
|
47
|
+
i.config.clientId,
|
|
48
|
+
i.config.userId,
|
|
49
|
+
i.config.hashedUserId,
|
|
50
|
+
o
|
|
51
51
|
);
|
|
52
52
|
},
|
|
53
53
|
// The functions below are nice wrappers over the generic
|
|
54
54
|
// rest api function above. They must follow REST API naming:
|
|
55
55
|
// Method + Resource, representing the end-point.
|
|
56
|
-
getNotifications: function(e,
|
|
57
|
-
return
|
|
56
|
+
getNotifications: function(e, r) {
|
|
57
|
+
return i.rest.generic(
|
|
58
58
|
"GET",
|
|
59
|
-
`notifications/INAPP_WEB?count=${
|
|
59
|
+
`notifications/INAPP_WEB?count=${r}&before=${e}`
|
|
60
60
|
);
|
|
61
61
|
},
|
|
62
62
|
patchNotifications: function(e) {
|
|
63
|
-
return
|
|
63
|
+
return i.rest.generic(
|
|
64
64
|
"PATCH",
|
|
65
65
|
"notifications/INAPP_WEB",
|
|
66
66
|
e
|
|
67
67
|
);
|
|
68
68
|
},
|
|
69
69
|
getPreferences: function() {
|
|
70
|
-
return
|
|
70
|
+
return i.rest.generic("GET", "preferences");
|
|
71
71
|
},
|
|
72
72
|
postPreferences: function(e) {
|
|
73
|
-
return
|
|
73
|
+
return i.rest.generic(
|
|
74
74
|
"POST",
|
|
75
75
|
"preferences",
|
|
76
76
|
e
|
|
77
77
|
);
|
|
78
78
|
},
|
|
79
79
|
postUser: function(e) {
|
|
80
|
-
return
|
|
80
|
+
return i.rest.generic("POST", "", e);
|
|
81
|
+
},
|
|
82
|
+
getUserAccountMetadata: function() {
|
|
83
|
+
return i.rest.generic("GET", "account_metadata");
|
|
81
84
|
}
|
|
82
85
|
},
|
|
83
86
|
websocket: {
|
|
84
87
|
object: void 0,
|
|
85
88
|
connect: function() {
|
|
86
|
-
let e = `wss://${
|
|
87
|
-
return
|
|
88
|
-
const
|
|
89
|
-
if (!(!
|
|
90
|
-
const a =
|
|
91
|
-
|
|
89
|
+
let e = `wss://${i.config.websocketHost}?userId=${encodeURIComponent(i.config.userId)}&envId=${i.config.clientId}`;
|
|
90
|
+
return i.config.hashedUserId && (e += `&userIdHash=${encodeURIComponent(i.config.hashedUserId)}`), i.websocket.object = new WebSocket(e), i.websocket.object.onmessage = (r) => {
|
|
91
|
+
const o = JSON.parse(r.data);
|
|
92
|
+
if (!(!o || !o.route) && o.route === "inapp_web/new_notifications") {
|
|
93
|
+
const a = o;
|
|
94
|
+
i.config.onNewInAppNotifications && i.config.onNewInAppNotifications(
|
|
92
95
|
a.payload.notifications
|
|
93
96
|
);
|
|
94
97
|
}
|
|
95
|
-
},
|
|
98
|
+
}, i.websocket.object;
|
|
96
99
|
},
|
|
97
100
|
disconnect: function(e) {
|
|
98
|
-
var
|
|
99
|
-
|
|
101
|
+
var r;
|
|
102
|
+
i.websocket.object && ((r = i.websocket.object) == null || r.close(), e && e(i.websocket.object));
|
|
100
103
|
}
|
|
101
104
|
},
|
|
102
105
|
openWebSocket: function() {
|
|
103
|
-
return
|
|
106
|
+
return i.websocket.connect(() => {
|
|
104
107
|
setTimeout(
|
|
105
108
|
() => {
|
|
106
109
|
this.websocket.disconnect(() => {
|
|
@@ -115,201 +118,253 @@ const _ = async (e, c, i, a, f, I, h) => {
|
|
|
115
118
|
// They may or may not do additional tasks.
|
|
116
119
|
// e.g. identify simply maps to postUsers
|
|
117
120
|
getInAppNotifications: async (e) => {
|
|
118
|
-
const
|
|
119
|
-
let a = [], f = e.before,
|
|
121
|
+
const r = e.maxCountNeeded || i.config.getInAppDefaultCount, o = e.oldestNeeded || i.config.getInAppDefaultOldest;
|
|
122
|
+
let a = [], f = e.before, b = !0, h = !0;
|
|
120
123
|
for (; h; ) {
|
|
121
|
-
const
|
|
124
|
+
const l = (await i.rest.getNotifications(
|
|
122
125
|
f,
|
|
123
|
-
|
|
126
|
+
r
|
|
124
127
|
)).notifications.filter(
|
|
125
|
-
(
|
|
128
|
+
(g) => !a.find((w) => w.id === g.id)
|
|
126
129
|
);
|
|
127
|
-
f =
|
|
128
|
-
(
|
|
130
|
+
f = l.reduce(
|
|
131
|
+
(g, w) => g < w.date ? g : w.date,
|
|
129
132
|
e.before
|
|
130
|
-
), a = [...a, ...
|
|
133
|
+
), a = [...a, ...l], b = l.length > 0, h = !0, (!b || a.length >= r || f < o) && (h = !1);
|
|
131
134
|
}
|
|
132
135
|
return {
|
|
133
136
|
items: a,
|
|
134
|
-
hasMore:
|
|
137
|
+
hasMore: b,
|
|
135
138
|
oldestReceived: f
|
|
136
139
|
};
|
|
137
140
|
},
|
|
138
141
|
updateInAppNotifications: async (e) => {
|
|
139
|
-
const
|
|
142
|
+
const r = {
|
|
140
143
|
trackingIds: e.ids
|
|
141
144
|
};
|
|
142
|
-
return e.archived === !0 ?
|
|
145
|
+
return e.archived === !0 ? r.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (r.archived = null), e.clicked === !0 ? r.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (r.clicked = null), e.opened === !0 ? r.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (r.opened = null), i.rest.patchNotifications(r);
|
|
143
146
|
},
|
|
144
|
-
getPreferences: async () =>
|
|
145
|
-
updateDeliveryOption: async (e) =>
|
|
147
|
+
getPreferences: async () => i.rest.getPreferences(),
|
|
148
|
+
updateDeliveryOption: async (e) => i.rest.postPreferences([e]),
|
|
146
149
|
identify: async (e) => {
|
|
147
|
-
if (e.id && e.id !==
|
|
150
|
+
if (e.id && e.id !== i.config.userId)
|
|
148
151
|
throw new Error(
|
|
149
152
|
"The id in the parameters does not match the initialized userId."
|
|
150
153
|
);
|
|
151
|
-
return
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
+
return i.rest.postUser(e);
|
|
155
|
+
},
|
|
156
|
+
getUserAccountMetadata: async () => i.rest.getUserAccountMetadata()
|
|
157
|
+
}, F = Q(
|
|
154
158
|
void 0
|
|
155
|
-
),
|
|
156
|
-
const
|
|
159
|
+
), te = (e) => {
|
|
160
|
+
const o = {
|
|
157
161
|
...{
|
|
158
162
|
apiURL: "https://api.notificationapi.com",
|
|
159
163
|
wsURL: "wss://ws.notificationapi.com",
|
|
160
164
|
initialLoadMaxCount: 1e3,
|
|
161
165
|
initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3)),
|
|
162
166
|
playSoundOnNewNotification: !1,
|
|
163
|
-
newNotificationSoundPath: "https://proxy.notificationsounds.com/notification-sounds/elegant-notification-sound/download/file-sounds-1233-elegant.mp3"
|
|
167
|
+
newNotificationSoundPath: "https://proxy.notificationsounds.com/notification-sounds/elegant-notification-sound/download/file-sounds-1233-elegant.mp3",
|
|
168
|
+
webPushOptInMessage: "AUTOMATIC",
|
|
169
|
+
customServiceWorkerPath: "/notificationapi-service-worker.js"
|
|
164
170
|
},
|
|
165
171
|
...e,
|
|
166
172
|
user: "userId" in e ? { id: e.userId } : e.user
|
|
167
|
-
}, [a, f] =
|
|
168
|
-
|
|
173
|
+
}, [a, f] = I(), [b, h] = I(), [l, g] = I(), [w, P] = I(!1), [k, C] = I((/* @__PURE__ */ new Date()).toISOString()), [A, U] = I(!0), [v, N] = I(o.webPushOptInMessage), [x, J] = I(!1), W = m(() => {
|
|
174
|
+
o.playSoundOnNewNotification && new Audio(o.newNotificationSoundPath).play().catch((s) => {
|
|
169
175
|
console.log("Failed to play new notification sound:", s);
|
|
170
176
|
});
|
|
171
|
-
}, [
|
|
177
|
+
}, [o.newNotificationSoundPath, o.playSoundOnNewNotification]), y = m((t) => {
|
|
172
178
|
const s = (/* @__PURE__ */ new Date()).toISOString();
|
|
173
|
-
f((
|
|
174
|
-
const p = d.expDate && new Date(d.expDate * 1e3).toISOString() < s,
|
|
175
|
-
return !p && !
|
|
176
|
-
}),
|
|
177
|
-
...
|
|
178
|
-
...
|
|
179
|
-
] :
|
|
180
|
-
}, []), u =
|
|
181
|
-
const
|
|
182
|
-
clientId:
|
|
183
|
-
userId:
|
|
184
|
-
hashedUserId:
|
|
179
|
+
f((n) => (t = Array.isArray(t) ? t : [], t = t.filter((d) => {
|
|
180
|
+
const p = d.expDate && new Date(d.expDate * 1e3).toISOString() < s, D = new Date(d.date).getTime() > new Date(s).getTime() + 1e3;
|
|
181
|
+
return !p && !D;
|
|
182
|
+
}), Array.isArray(n) ? [
|
|
183
|
+
...t.filter((d) => !n.find((D) => D.id === d.id)),
|
|
184
|
+
...n
|
|
185
|
+
] : t));
|
|
186
|
+
}, []), u = X(() => {
|
|
187
|
+
const t = e.client ? e.client : i.init({
|
|
188
|
+
clientId: o.clientId,
|
|
189
|
+
userId: o.user.id,
|
|
190
|
+
hashedUserId: o.hashedUserId,
|
|
185
191
|
onNewInAppNotifications: (s) => {
|
|
186
|
-
|
|
192
|
+
W(), y(s);
|
|
187
193
|
}
|
|
188
194
|
});
|
|
189
|
-
return
|
|
190
|
-
email:
|
|
191
|
-
number:
|
|
192
|
-
}),
|
|
195
|
+
return t.identify({
|
|
196
|
+
email: o.user.email,
|
|
197
|
+
number: o.user.number
|
|
198
|
+
}), t;
|
|
193
199
|
}, [
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
200
|
+
o.clientId,
|
|
201
|
+
o.user.id,
|
|
202
|
+
o.user.email,
|
|
203
|
+
o.user.number,
|
|
204
|
+
o.hashedUserId,
|
|
205
|
+
y,
|
|
206
|
+
W,
|
|
201
207
|
e.client
|
|
202
|
-
]),
|
|
203
|
-
async (
|
|
204
|
-
const
|
|
205
|
-
|
|
208
|
+
]), L = m(
|
|
209
|
+
async (t, s) => {
|
|
210
|
+
const n = await u.rest.getNotifications(t, s);
|
|
211
|
+
C(n.oldestReceived), U(n.couldLoadMore), y(n.notifications);
|
|
206
212
|
},
|
|
207
|
-
[
|
|
208
|
-
),
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}, [
|
|
212
|
-
const
|
|
213
|
-
async (
|
|
214
|
-
if (!(!
|
|
215
|
-
|
|
213
|
+
[y, u.rest]
|
|
214
|
+
), E = T(A), R = T(w), $ = T(k);
|
|
215
|
+
S(() => {
|
|
216
|
+
E.current = A, R.current = w, $.current = k;
|
|
217
|
+
}, [A, w, k]);
|
|
218
|
+
const O = m(
|
|
219
|
+
async (t) => {
|
|
220
|
+
if (!(!t && (!E.current || R.current))) {
|
|
221
|
+
P(!0);
|
|
216
222
|
try {
|
|
217
|
-
await
|
|
218
|
-
|
|
219
|
-
|
|
223
|
+
await L(
|
|
224
|
+
t ? (/* @__PURE__ */ new Date()).toISOString() : $.current,
|
|
225
|
+
t ? o.initialLoadMaxCount : 1e3
|
|
220
226
|
);
|
|
221
227
|
} finally {
|
|
222
|
-
|
|
228
|
+
P(!1);
|
|
223
229
|
}
|
|
224
230
|
}
|
|
225
231
|
},
|
|
226
|
-
[
|
|
227
|
-
),
|
|
232
|
+
[o.initialLoadMaxCount, L]
|
|
233
|
+
), q = async (t) => {
|
|
228
234
|
if (!a) return;
|
|
229
|
-
const s = (/* @__PURE__ */ new Date()).toISOString(),
|
|
230
|
-
u.updateInAppNotifications({ ids:
|
|
231
|
-
if (!
|
|
232
|
-
const d = [...
|
|
233
|
-
return d.filter((p) =>
|
|
235
|
+
const s = (/* @__PURE__ */ new Date()).toISOString(), n = a.filter((c) => t.includes(c.id) && !c.clicked).map((c) => c.id);
|
|
236
|
+
u.updateInAppNotifications({ ids: n, clicked: !0 }), f((c) => {
|
|
237
|
+
if (!c) return [];
|
|
238
|
+
const d = [...c];
|
|
239
|
+
return d.filter((p) => n.includes(p.id)).forEach((p) => {
|
|
234
240
|
p.clicked = s;
|
|
235
241
|
}), d;
|
|
236
242
|
});
|
|
237
|
-
},
|
|
243
|
+
}, B = async () => {
|
|
238
244
|
if (!a) return;
|
|
239
|
-
const
|
|
245
|
+
const t = (/* @__PURE__ */ new Date()).toISOString(), s = a.filter((n) => !n.opened || !n.seen).map((n) => n.id);
|
|
240
246
|
s.length !== 0 && (u.updateInAppNotifications({
|
|
241
247
|
ids: s,
|
|
242
248
|
opened: !0
|
|
243
|
-
}), f((
|
|
244
|
-
if (!
|
|
245
|
-
const
|
|
246
|
-
return
|
|
247
|
-
d.opened =
|
|
248
|
-
}),
|
|
249
|
+
}), f((n) => {
|
|
250
|
+
if (!n) return [];
|
|
251
|
+
const c = [...n];
|
|
252
|
+
return c.filter((d) => s.includes(d.id)).forEach((d) => {
|
|
253
|
+
d.opened = t, d.seen = !0;
|
|
254
|
+
}), c;
|
|
249
255
|
}));
|
|
250
|
-
},
|
|
256
|
+
}, G = async (t) => {
|
|
251
257
|
if (!a) return;
|
|
252
|
-
const s = a.filter((
|
|
258
|
+
const s = a.filter((n) => n.archived && (t === "ALL" || t.includes(n.id))).map((n) => n.id);
|
|
253
259
|
s.length !== 0 && (u.updateInAppNotifications({
|
|
254
260
|
ids: s,
|
|
255
261
|
archived: !1
|
|
256
|
-
}), f((
|
|
257
|
-
if (!
|
|
258
|
-
const
|
|
259
|
-
return
|
|
262
|
+
}), f((n) => {
|
|
263
|
+
if (!n) return [];
|
|
264
|
+
const c = [...n];
|
|
265
|
+
return c.filter((d) => s.includes(d.id)).forEach((d) => {
|
|
260
266
|
d.archived = void 0;
|
|
261
|
-
}),
|
|
267
|
+
}), c;
|
|
262
268
|
}));
|
|
263
|
-
},
|
|
269
|
+
}, K = async (t) => {
|
|
264
270
|
if (!a) return;
|
|
265
|
-
const s = (/* @__PURE__ */ new Date()).toISOString(),
|
|
266
|
-
|
|
267
|
-
if (!
|
|
268
|
-
const d = [...
|
|
269
|
-
return d.filter((p) =>
|
|
271
|
+
const s = (/* @__PURE__ */ new Date()).toISOString(), n = a.filter((c) => !c.archived && (t === "ALL" || t.includes(c.id))).map((c) => c.id);
|
|
272
|
+
n.length !== 0 && (u.updateInAppNotifications({ ids: n, archived: !0 }), f((c) => {
|
|
273
|
+
if (!c) return [];
|
|
274
|
+
const d = [...c];
|
|
275
|
+
return d.filter((p) => n.includes(p.id)).forEach((p) => {
|
|
270
276
|
p.archived = s;
|
|
271
277
|
}), d;
|
|
272
278
|
}));
|
|
273
|
-
},
|
|
279
|
+
}, V = (t, s, n, c) => j([
|
|
274
280
|
{
|
|
275
|
-
notificationId:
|
|
281
|
+
notificationId: t,
|
|
276
282
|
channel: s,
|
|
277
|
-
delivery:
|
|
278
|
-
subNotificationId:
|
|
283
|
+
delivery: n,
|
|
284
|
+
subNotificationId: c
|
|
279
285
|
}
|
|
280
|
-
]),
|
|
281
|
-
u.rest.postPreferences(
|
|
286
|
+
]), j = (t) => {
|
|
287
|
+
u.rest.postPreferences(t).then(() => {
|
|
282
288
|
u.getPreferences().then((s) => {
|
|
283
289
|
h(s);
|
|
284
290
|
});
|
|
285
291
|
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
292
|
+
}, M = m(() => {
|
|
293
|
+
"serviceWorker" in navigator && navigator.serviceWorker.register(o.customServiceWorkerPath).then(async (t) => {
|
|
294
|
+
N(!1), Notification.requestPermission().then(async (s) => {
|
|
295
|
+
s === "granted" ? await t.pushManager.subscribe({
|
|
296
|
+
userVisibleOnly: !0,
|
|
297
|
+
applicationServerKey: l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
|
|
298
|
+
}).then(async (n) => {
|
|
299
|
+
const c = {
|
|
300
|
+
webPushTokens: [
|
|
301
|
+
{
|
|
302
|
+
sub: {
|
|
303
|
+
endpoint: n.toJSON().endpoint,
|
|
304
|
+
keys: n.toJSON().keys
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
};
|
|
309
|
+
await u.identify(c), console.log("index"), localStorage.setItem("hideWebPushOptInMessage", "true");
|
|
310
|
+
}) : s === "denied" && console.log("Permission for notifications was denied");
|
|
311
|
+
});
|
|
312
|
+
}).catch((t) => {
|
|
313
|
+
t.code === 18 ? console.error(
|
|
314
|
+
"NotificationAPI guide: Probably you are not setup the service worker correctly. Please check the documentation at https://docs.notificationapi.com/guides/web-push#step-by-step-implementation Step 3: Service Worker Setup."
|
|
315
|
+
) : t.code === 19 ? console.error(
|
|
316
|
+
"The operation is aborted. This can happen if the user denies the permission request."
|
|
317
|
+
) : t.code === 20 ? console.error(
|
|
318
|
+
"The operation is invalid. This can occur if the provided application server key is invalid. Please contact NotificationAPI support."
|
|
319
|
+
) : t.code === 21 ? console.error(
|
|
320
|
+
"The operation is not allowed. This can happen if the user has blocked notifications for the site. Please check your browser site settings Notifications part."
|
|
321
|
+
) : t.code === 22 ? console.error(
|
|
322
|
+
"The operation is not supported. This can occur if the browser does not support the required features."
|
|
323
|
+
) : console.error(t);
|
|
324
|
+
});
|
|
325
|
+
}, [
|
|
326
|
+
u,
|
|
327
|
+
o.customServiceWorkerPath,
|
|
328
|
+
l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
|
|
329
|
+
]);
|
|
330
|
+
S(() => {
|
|
331
|
+
f([]), P(!1), h(void 0), C((/* @__PURE__ */ new Date()).toISOString()), U(!0), O(!0), u.openWebSocket(), u.getPreferences().then((t) => {
|
|
332
|
+
h(t);
|
|
290
333
|
});
|
|
291
|
-
}, [u,
|
|
292
|
-
|
|
334
|
+
}, [u, O, M]), S(() => {
|
|
335
|
+
Notification.permission !== "default" && N(!1), v === "AUTOMATIC" && (N(
|
|
336
|
+
localStorage.getItem("hideWebPushOptInMessage") !== "true"
|
|
337
|
+
), u.getUserAccountMetadata().then((t) => {
|
|
338
|
+
g(t), N(t.userAccountMetadata.hasWebPushEnabled);
|
|
339
|
+
}));
|
|
340
|
+
}, [u, v]), S(() => {
|
|
341
|
+
x && M();
|
|
342
|
+
}, [x, M]);
|
|
343
|
+
const _ = {
|
|
293
344
|
notifications: a,
|
|
294
|
-
preferences:
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
345
|
+
preferences: b,
|
|
346
|
+
userAccountMetaData: l,
|
|
347
|
+
webPushOptInMessage: v,
|
|
348
|
+
loadNotifications: O,
|
|
349
|
+
markAsOpened: B,
|
|
350
|
+
markAsArchived: K,
|
|
351
|
+
markAsUnarchived: G,
|
|
352
|
+
markAsClicked: q,
|
|
353
|
+
updateDelivery: V,
|
|
354
|
+
updateDeliveries: j,
|
|
355
|
+
getClient: () => u,
|
|
356
|
+
setWebPushOptInMessage: N,
|
|
357
|
+
setWebPushOptIn: J
|
|
303
358
|
};
|
|
304
|
-
return /* @__PURE__ */ F
|
|
305
|
-
},
|
|
306
|
-
const e =
|
|
359
|
+
return /* @__PURE__ */ z(F.Provider, { value: _, children: e.children });
|
|
360
|
+
}, ne = () => {
|
|
361
|
+
const e = Y(F);
|
|
307
362
|
if (!e)
|
|
308
363
|
throw new Error("useMyContext must be used within a MyProvider");
|
|
309
364
|
return e;
|
|
310
365
|
};
|
|
311
|
-
|
|
366
|
+
te.useNotificationAPIContext = ne;
|
|
312
367
|
export {
|
|
313
|
-
|
|
314
|
-
|
|
368
|
+
F as NotificationAPIContext,
|
|
369
|
+
te as NotificationAPIProvider
|
|
315
370
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
interface WebPushOptInMessageProps {
|
|
4
|
+
hideAfterInteraction?: boolean;
|
|
5
|
+
alertContainerStyle?: React.CSSProperties;
|
|
6
|
+
descriptionStyle?: React.CSSProperties;
|
|
7
|
+
buttonContainerStyle?: React.CSSProperties;
|
|
8
|
+
yesButtonStyle?: React.CSSProperties;
|
|
9
|
+
cancelButtonStyle?: React.CSSProperties;
|
|
10
|
+
description?: string;
|
|
11
|
+
icon?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
declare const WebPushOptInMessage: React.FC<WebPushOptInMessageProps>;
|
|
14
|
+
export default WebPushOptInMessage;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notificationapi/react",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.36",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"**/*.css"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@notificationapi/core": "^0.0.
|
|
46
|
+
"@notificationapi/core": "^0.0.12",
|
|
47
47
|
"antd": "^5.17.4",
|
|
48
48
|
"javascript-time-ago": "^2.5.10",
|
|
49
49
|
"liquidjs": "^10.14.0",
|