@notificationapi/react 1.0.3 → 1.1.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.
|
@@ -226,12 +226,14 @@ function He(e, r) {
|
|
|
226
226
|
}
|
|
227
227
|
function Ge(e) {
|
|
228
228
|
switch (e) {
|
|
229
|
+
// \0 \t \n \r \s whitespace token
|
|
229
230
|
case 0:
|
|
230
231
|
case 9:
|
|
231
232
|
case 10:
|
|
232
233
|
case 13:
|
|
233
234
|
case 32:
|
|
234
235
|
return 5;
|
|
236
|
+
// ! + , / > @ ~ isolate token
|
|
235
237
|
case 33:
|
|
236
238
|
case 43:
|
|
237
239
|
case 44:
|
|
@@ -239,17 +241,21 @@ function Ge(e) {
|
|
|
239
241
|
case 62:
|
|
240
242
|
case 64:
|
|
241
243
|
case 126:
|
|
244
|
+
// ; { } breakpoint token
|
|
242
245
|
case 59:
|
|
243
246
|
case 123:
|
|
244
247
|
case 125:
|
|
245
248
|
return 4;
|
|
249
|
+
// : accompanied token
|
|
246
250
|
case 58:
|
|
247
251
|
return 3;
|
|
252
|
+
// " ' ( [ opening delimit token
|
|
248
253
|
case 34:
|
|
249
254
|
case 39:
|
|
250
255
|
case 40:
|
|
251
256
|
case 91:
|
|
252
257
|
return 2;
|
|
258
|
+
// ) ] closing delimit token
|
|
253
259
|
case 41:
|
|
254
260
|
case 93:
|
|
255
261
|
return 1;
|
|
@@ -278,15 +284,19 @@ function Fn(e, r) {
|
|
|
278
284
|
function Mr(e) {
|
|
279
285
|
for (; de(); )
|
|
280
286
|
switch (re) {
|
|
287
|
+
// ] ) " '
|
|
281
288
|
case e:
|
|
282
289
|
return le;
|
|
290
|
+
// " '
|
|
283
291
|
case 34:
|
|
284
292
|
case 39:
|
|
285
293
|
e !== 34 && e !== 39 && Mr(re);
|
|
286
294
|
break;
|
|
295
|
+
// (
|
|
287
296
|
case 40:
|
|
288
297
|
e === 41 && Mr(e);
|
|
289
298
|
break;
|
|
299
|
+
// \
|
|
290
300
|
case 92:
|
|
291
301
|
de();
|
|
292
302
|
break;
|
|
@@ -310,25 +320,30 @@ function Wn(e) {
|
|
|
310
320
|
function or(e, r, t, n, o, i, s, u, l) {
|
|
311
321
|
for (var f = 0, m = 0, d = s, h = 0, S = 0, y = 0, c = 1, v = 1, E = 1, _ = 0, x = "", C = o, g = i, $ = n, O = x; v; )
|
|
312
322
|
switch (y = _, _ = de()) {
|
|
323
|
+
// (
|
|
313
324
|
case 40:
|
|
314
325
|
if (y != 108 && oe(O, d - 1) == 58) {
|
|
315
326
|
Nr(O += L(nr(_), "&", "&\f"), "&\f") != -1 && (E = -1);
|
|
316
327
|
break;
|
|
317
328
|
}
|
|
329
|
+
// " ' [
|
|
318
330
|
case 34:
|
|
319
331
|
case 39:
|
|
320
332
|
case 91:
|
|
321
333
|
O += nr(_);
|
|
322
334
|
break;
|
|
335
|
+
// \t \n \r \s
|
|
323
336
|
case 9:
|
|
324
337
|
case 10:
|
|
325
338
|
case 13:
|
|
326
339
|
case 32:
|
|
327
340
|
O += Bn(y);
|
|
328
341
|
break;
|
|
342
|
+
// \
|
|
329
343
|
case 92:
|
|
330
344
|
O += Fn(tr() - 1, 7);
|
|
331
345
|
continue;
|
|
346
|
+
// /
|
|
332
347
|
case 47:
|
|
333
348
|
switch (Se()) {
|
|
334
349
|
case 42:
|
|
@@ -339,26 +354,33 @@ function or(e, r, t, n, o, i, s, u, l) {
|
|
|
339
354
|
O += "/";
|
|
340
355
|
}
|
|
341
356
|
break;
|
|
357
|
+
// {
|
|
342
358
|
case 123 * c:
|
|
343
359
|
u[f++] = be(O) * E;
|
|
360
|
+
// } ; \0
|
|
344
361
|
case 125 * c:
|
|
345
362
|
case 59:
|
|
346
363
|
case 0:
|
|
347
364
|
switch (_) {
|
|
365
|
+
// \0 }
|
|
348
366
|
case 0:
|
|
349
367
|
case 125:
|
|
350
368
|
v = 0;
|
|
369
|
+
// ;
|
|
351
370
|
case 59 + m:
|
|
352
371
|
E == -1 && (O = L(O, /\f/g, "")), S > 0 && be(O) - d && Je(S > 32 ? ot(O + ";", n, t, d - 1) : ot(L(O, " ", "") + ";", n, t, d - 2), l);
|
|
353
372
|
break;
|
|
373
|
+
// @ ;
|
|
354
374
|
case 59:
|
|
355
375
|
O += ";";
|
|
376
|
+
// { rule/at-rule
|
|
356
377
|
default:
|
|
357
378
|
if (Je($ = nt(O, r, t, f, m, o, u, x, C = [], g = [], d), i), _ === 123)
|
|
358
379
|
if (m === 0)
|
|
359
380
|
or(O, r, $, $, C, i, d, u, g);
|
|
360
381
|
else
|
|
361
382
|
switch (h === 99 && oe(O, 3) === 110 ? 100 : h) {
|
|
383
|
+
// d l m s
|
|
362
384
|
case 100:
|
|
363
385
|
case 108:
|
|
364
386
|
case 109:
|
|
@@ -371,6 +393,7 @@ function or(e, r, t, n, o, i, s, u, l) {
|
|
|
371
393
|
}
|
|
372
394
|
f = m = S = 0, c = E = 1, x = O = "", d = s;
|
|
373
395
|
break;
|
|
396
|
+
// :
|
|
374
397
|
case 58:
|
|
375
398
|
d = 1 + be(O), S = y;
|
|
376
399
|
default:
|
|
@@ -381,15 +404,19 @@ function or(e, r, t, n, o, i, s, u, l) {
|
|
|
381
404
|
continue;
|
|
382
405
|
}
|
|
383
406
|
switch (O += cr(_), _ * c) {
|
|
407
|
+
// &
|
|
384
408
|
case 38:
|
|
385
409
|
E = m > 0 ? 1 : (O += "\f", -1);
|
|
386
410
|
break;
|
|
411
|
+
// ,
|
|
387
412
|
case 44:
|
|
388
413
|
u[f++] = (be(O) - 1) * E, E = 1;
|
|
389
414
|
break;
|
|
415
|
+
// @
|
|
390
416
|
case 64:
|
|
391
417
|
Se() === 45 && (O += nr(de())), h = Se(), m = d = be(x = O += Ln(tr())), _++;
|
|
392
418
|
break;
|
|
419
|
+
// -
|
|
393
420
|
case 45:
|
|
394
421
|
y === 45 && be(O) == 2 && (c = 0);
|
|
395
422
|
}
|
|
@@ -461,6 +488,7 @@ var Gn = function(r, t, n) {
|
|
|
461
488
|
r[++n] = Se() === 58 ? "&\f" : "", t[n] = r[n].length;
|
|
462
489
|
break;
|
|
463
490
|
}
|
|
491
|
+
// fallthrough
|
|
464
492
|
default:
|
|
465
493
|
r[n] += cr(o);
|
|
466
494
|
}
|
|
@@ -491,8 +519,10 @@ var Gn = function(r, t, n) {
|
|
|
491
519
|
};
|
|
492
520
|
function zt(e, r) {
|
|
493
521
|
switch (Rn(e, r)) {
|
|
522
|
+
// color-adjust
|
|
494
523
|
case 5103:
|
|
495
524
|
return j + "print-" + e + e;
|
|
525
|
+
// animation, animation-(delay|direction|duration|fill-mode|iteration-count|name|play-state|timing-function)
|
|
496
526
|
case 5737:
|
|
497
527
|
case 4201:
|
|
498
528
|
case 3177:
|
|
@@ -500,18 +530,21 @@ function zt(e, r) {
|
|
|
500
530
|
case 1641:
|
|
501
531
|
case 4457:
|
|
502
532
|
case 2921:
|
|
533
|
+
// text-decoration, filter, clip-path, backface-visibility, column, box-decoration-break
|
|
503
534
|
case 5572:
|
|
504
535
|
case 6356:
|
|
505
536
|
case 5844:
|
|
506
537
|
case 3191:
|
|
507
538
|
case 6645:
|
|
508
539
|
case 3005:
|
|
540
|
+
// mask, mask-image, mask-(mode|clip|size), mask-(repeat|origin), mask-position, mask-composite,
|
|
509
541
|
case 6391:
|
|
510
542
|
case 5879:
|
|
511
543
|
case 5623:
|
|
512
544
|
case 6135:
|
|
513
545
|
case 4599:
|
|
514
546
|
case 4855:
|
|
547
|
+
// background-clip, columns, column-(count|fill|gap|rule|rule-color|rule-style|rule-width|span|width)
|
|
515
548
|
case 4215:
|
|
516
549
|
case 6389:
|
|
517
550
|
case 5109:
|
|
@@ -519,43 +552,58 @@ function zt(e, r) {
|
|
|
519
552
|
case 5621:
|
|
520
553
|
case 3829:
|
|
521
554
|
return j + e + e;
|
|
555
|
+
// appearance, user-select, transform, hyphens, text-size-adjust
|
|
522
556
|
case 5349:
|
|
523
557
|
case 4246:
|
|
524
558
|
case 4810:
|
|
525
559
|
case 6968:
|
|
526
560
|
case 2756:
|
|
527
561
|
return j + e + ar + e + ae + e + e;
|
|
562
|
+
// flex, flex-direction
|
|
528
563
|
case 6828:
|
|
529
564
|
case 4268:
|
|
530
565
|
return j + e + ae + e + e;
|
|
566
|
+
// order
|
|
531
567
|
case 6165:
|
|
532
568
|
return j + e + ae + "flex-" + e + e;
|
|
569
|
+
// align-items
|
|
533
570
|
case 5187:
|
|
534
571
|
return j + e + L(e, /(\w+).+(:[^]+)/, j + "box-$1$2" + ae + "flex-$1$2") + e;
|
|
572
|
+
// align-self
|
|
535
573
|
case 5443:
|
|
536
574
|
return j + e + ae + "flex-item-" + L(e, /flex-|-self/, "") + e;
|
|
575
|
+
// align-content
|
|
537
576
|
case 4675:
|
|
538
577
|
return j + e + ae + "flex-line-pack" + L(e, /align-content|flex-|-self/, "") + e;
|
|
578
|
+
// flex-shrink
|
|
539
579
|
case 5548:
|
|
540
580
|
return j + e + ae + L(e, "shrink", "negative") + e;
|
|
581
|
+
// flex-basis
|
|
541
582
|
case 5292:
|
|
542
583
|
return j + e + ae + L(e, "basis", "preferred-size") + e;
|
|
584
|
+
// flex-grow
|
|
543
585
|
case 6060:
|
|
544
586
|
return j + "box-" + L(e, "-grow", "") + j + e + ae + L(e, "grow", "positive") + e;
|
|
587
|
+
// transition
|
|
545
588
|
case 4554:
|
|
546
589
|
return j + L(e, /([^-])(transform)/g, "$1" + j + "$2") + e;
|
|
590
|
+
// cursor
|
|
547
591
|
case 6187:
|
|
548
592
|
return L(L(L(e, /(zoom-|grab)/, j + "$1"), /(image-set)/, j + "$1"), e, "") + e;
|
|
593
|
+
// background, background-image
|
|
549
594
|
case 5495:
|
|
550
595
|
case 3959:
|
|
551
596
|
return L(e, /(image-set\([^]*)/, j + "$1$`$1");
|
|
597
|
+
// justify-content
|
|
552
598
|
case 4968:
|
|
553
599
|
return L(L(e, /(.+:)(flex-)?(.*)/, j + "box-pack:$3" + ae + "flex-pack:$3"), /s.+-b[^;]+/, "justify") + j + e + e;
|
|
600
|
+
// (margin|padding)-inline-(start|end)
|
|
554
601
|
case 4095:
|
|
555
602
|
case 3583:
|
|
556
603
|
case 4068:
|
|
557
604
|
case 2532:
|
|
558
605
|
return L(e, /(.+)-inline(.+)/, j + "$1$2") + e;
|
|
606
|
+
// (min|max)?(width|height|inline-size|block-size)
|
|
559
607
|
case 8116:
|
|
560
608
|
case 7059:
|
|
561
609
|
case 5753:
|
|
@@ -569,30 +617,41 @@ function zt(e, r) {
|
|
|
569
617
|
case 5021:
|
|
570
618
|
case 4765:
|
|
571
619
|
if (be(e) - 1 - r > 6) switch (oe(e, r + 1)) {
|
|
620
|
+
// (m)ax-content, (m)in-content
|
|
572
621
|
case 109:
|
|
573
622
|
if (oe(e, r + 4) !== 45) break;
|
|
623
|
+
// (f)ill-available, (f)it-content
|
|
574
624
|
case 102:
|
|
575
625
|
return L(e, /(.+:)(.+)-([^]+)/, "$1" + j + "$2-$3$1" + ar + (oe(e, r + 3) == 108 ? "$3" : "$2-$3")) + e;
|
|
626
|
+
// (s)tretch
|
|
576
627
|
case 115:
|
|
577
628
|
return ~Nr(e, "stretch") ? zt(L(e, "stretch", "fill-available"), r) + e : e;
|
|
578
629
|
}
|
|
579
630
|
break;
|
|
631
|
+
// position: sticky
|
|
580
632
|
case 4949:
|
|
581
633
|
if (oe(e, r + 1) !== 115) break;
|
|
634
|
+
// display: (flex|inline-flex)
|
|
582
635
|
case 6444:
|
|
583
636
|
switch (oe(e, be(e) - 3 - (~Nr(e, "!important") && 10))) {
|
|
637
|
+
// stic(k)y
|
|
584
638
|
case 107:
|
|
585
639
|
return L(e, ":", ":" + j) + e;
|
|
640
|
+
// (inline-)?fl(e)x
|
|
586
641
|
case 101:
|
|
587
642
|
return L(e, /(.+:)([^;!]+)(;|!.+)?/, "$1" + j + (oe(e, 14) === 45 ? "inline-" : "") + "box$3$1" + j + "$2$3$1" + ae + "$2box$3") + e;
|
|
588
643
|
}
|
|
589
644
|
break;
|
|
645
|
+
// writing-mode
|
|
590
646
|
case 5936:
|
|
591
647
|
switch (oe(e, r + 11)) {
|
|
648
|
+
// vertical-l(r)
|
|
592
649
|
case 114:
|
|
593
650
|
return j + e + ae + L(e, /[svh]\w+-[tblr]{2}/, "tb") + e;
|
|
651
|
+
// vertical-r(l)
|
|
594
652
|
case 108:
|
|
595
653
|
return j + e + ae + L(e, /[svh]\w+-[tblr]{2}/, "tb-rl") + e;
|
|
654
|
+
// horizontal(-)tb
|
|
596
655
|
case 45:
|
|
597
656
|
return j + e + ae + L(e, /[svh]\w+-[tblr]{2}/, "lr") + e;
|
|
598
657
|
}
|
|
@@ -612,11 +671,13 @@ var Qn = function(r, t, n, o) {
|
|
|
612
671
|
case Vr:
|
|
613
672
|
if (r.length) return Nn(r.props, function(i) {
|
|
614
673
|
switch (In(i, /(::plac\w+|:read-\w+)/)) {
|
|
674
|
+
// :read-(only|write)
|
|
615
675
|
case ":read-only":
|
|
616
676
|
case ":read-write":
|
|
617
677
|
return Ne([Le(r, {
|
|
618
678
|
props: [L(i, /:(read-\w+)/, ":" + ar + "$1")]
|
|
619
679
|
})], o);
|
|
680
|
+
// :placeholder
|
|
620
681
|
case "::placeholder":
|
|
621
682
|
return Ne([Le(r, {
|
|
622
683
|
props: [L(i, /:(plac\w+)/, ":" + j + "input-$1")]
|
|
@@ -676,7 +676,7 @@ function fr(t, e) {
|
|
|
676
676
|
}
|
|
677
677
|
function Gi(t) {
|
|
678
678
|
const e = t.getFullYear();
|
|
679
|
-
return !!(
|
|
679
|
+
return !!((e & 3) === 0 && (e % 100 || e % 400 === 0 && e));
|
|
680
680
|
}
|
|
681
681
|
function Xi(t) {
|
|
682
682
|
const e = t.getDate();
|
|
@@ -3202,6 +3202,8 @@ function qn(t) {
|
|
|
3202
3202
|
switch (r) {
|
|
3203
3203
|
case "lookup":
|
|
3204
3204
|
return Ar(t);
|
|
3205
|
+
// "best fit" locale matching is not supported.
|
|
3206
|
+
// https://github.com/catamphetamine/relative-time-format/issues/2
|
|
3205
3207
|
case "best fit":
|
|
3206
3208
|
return Ar(t);
|
|
3207
3209
|
default:
|
|
@@ -4567,6 +4569,7 @@ const wl = en(en({}, _t), {}, {
|
|
|
4567
4569
|
});
|
|
4568
4570
|
function vl(t) {
|
|
4569
4571
|
switch (t) {
|
|
4572
|
+
// "default" style name is deprecated.
|
|
4570
4573
|
case "default":
|
|
4571
4574
|
case "round":
|
|
4572
4575
|
return Lt;
|
|
@@ -4574,6 +4577,7 @@ function vl(t) {
|
|
|
4574
4577
|
return At;
|
|
4575
4578
|
case "approximate":
|
|
4576
4579
|
return qr;
|
|
4580
|
+
// "time" style name is deprecated.
|
|
4577
4581
|
case "time":
|
|
4578
4582
|
case "approximate-time":
|
|
4579
4583
|
return il;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { NotificationAPIClientSDK } from '@notificationapi/core';
|
|
3
|
-
import { User } from '@notificationapi/core/dist/interfaces';
|
|
3
|
+
import { User, API_REGION, WS_REGION } from '@notificationapi/core/dist/interfaces';
|
|
4
4
|
import { Context } from './context';
|
|
5
5
|
|
|
6
6
|
type Props = ({
|
|
@@ -10,8 +10,8 @@ type Props = ({
|
|
|
10
10
|
}) & {
|
|
11
11
|
clientId: string;
|
|
12
12
|
hashedUserId?: string;
|
|
13
|
-
apiURL?: string;
|
|
14
|
-
wsURL?: string;
|
|
13
|
+
apiURL?: string | API_REGION;
|
|
14
|
+
wsURL?: string | WS_REGION;
|
|
15
15
|
initialLoadMaxCount?: number;
|
|
16
16
|
initialLoadMaxAge?: Date;
|
|
17
17
|
playSoundOnNewNotification?: boolean;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as Q } from "react/jsx-runtime";
|
|
2
|
-
import { useState as I, useCallback as m, useMemo as X, useRef as
|
|
2
|
+
import { useState as I, useCallback as m, useMemo as X, useRef as U, useEffect as P, useContext as Y } from "react";
|
|
3
3
|
import { NotificationAPIContext as H } from "./context.js";
|
|
4
|
-
const Z = async (e, c,
|
|
5
|
-
const l = ee(a, f,
|
|
4
|
+
const Z = async (e, c, i, a, f, b, h) => {
|
|
5
|
+
const l = ee(a, f, b), g = await fetch(
|
|
6
6
|
`https://${c}/${a}/users/${encodeURIComponent(
|
|
7
7
|
f
|
|
8
|
-
)}/${
|
|
8
|
+
)}/${i}`,
|
|
9
9
|
{
|
|
10
10
|
method: e,
|
|
11
11
|
body: JSON.stringify(h),
|
|
@@ -19,7 +19,7 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
19
19
|
} catch {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
}, ee = (e, c,
|
|
22
|
+
}, ee = (e, c, i) => btoa(i ? e + ":" + c + ":" + i : e + ":" + c), q = {
|
|
23
23
|
host: "api.notificationapi.com",
|
|
24
24
|
websocketHost: "ws.notificationapi.com",
|
|
25
25
|
userId: "",
|
|
@@ -32,7 +32,7 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
32
32
|
onNewInAppNotifications: void 0,
|
|
33
33
|
keepWebSocketAliveForSeconds: 86400
|
|
34
34
|
// 24 hours
|
|
35
|
-
},
|
|
35
|
+
}, o = {
|
|
36
36
|
config: q,
|
|
37
37
|
init: function(e) {
|
|
38
38
|
return this.config = { ...q, ...e }, {
|
|
@@ -40,71 +40,71 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
40
40
|
};
|
|
41
41
|
},
|
|
42
42
|
rest: {
|
|
43
|
-
generic: function(e, c,
|
|
43
|
+
generic: function(e, c, i) {
|
|
44
44
|
return Z(
|
|
45
45
|
e,
|
|
46
|
-
|
|
46
|
+
o.config.host,
|
|
47
47
|
c,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
o.config.clientId,
|
|
49
|
+
o.config.userId,
|
|
50
|
+
o.config.hashedUserId,
|
|
51
|
+
i
|
|
52
52
|
);
|
|
53
53
|
},
|
|
54
54
|
// The functions below are nice wrappers over the generic
|
|
55
55
|
// rest api function above. They must follow REST API naming:
|
|
56
56
|
// Method + Resource, representing the end-point.
|
|
57
57
|
getNotifications: function(e, c) {
|
|
58
|
-
return
|
|
58
|
+
return o.rest.generic(
|
|
59
59
|
"GET",
|
|
60
60
|
`notifications/INAPP_WEB?count=${c}&before=${e}`
|
|
61
61
|
);
|
|
62
62
|
},
|
|
63
63
|
patchNotifications: function(e) {
|
|
64
|
-
return
|
|
64
|
+
return o.rest.generic(
|
|
65
65
|
"PATCH",
|
|
66
66
|
"notifications/INAPP_WEB",
|
|
67
67
|
e
|
|
68
68
|
);
|
|
69
69
|
},
|
|
70
70
|
getPreferences: function() {
|
|
71
|
-
return
|
|
71
|
+
return o.rest.generic("GET", "preferences");
|
|
72
72
|
},
|
|
73
73
|
postPreferences: function(e) {
|
|
74
|
-
return
|
|
74
|
+
return o.rest.generic(
|
|
75
75
|
"POST",
|
|
76
76
|
"preferences",
|
|
77
77
|
e
|
|
78
78
|
);
|
|
79
79
|
},
|
|
80
80
|
postUser: function(e) {
|
|
81
|
-
return
|
|
81
|
+
return o.rest.generic("POST", "", e);
|
|
82
82
|
},
|
|
83
83
|
getUserAccountMetadata: function() {
|
|
84
|
-
return
|
|
84
|
+
return o.rest.generic("GET", "account_metadata");
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
websocket: {
|
|
88
88
|
object: void 0,
|
|
89
89
|
connect: function() {
|
|
90
|
-
let e = `wss://${
|
|
91
|
-
return
|
|
92
|
-
const
|
|
93
|
-
if (!(!
|
|
94
|
-
const a =
|
|
95
|
-
|
|
90
|
+
let e = `wss://${o.config.websocketHost}?userId=${encodeURIComponent(o.config.userId)}&envId=${o.config.clientId}`;
|
|
91
|
+
return o.config.hashedUserId && (e += `&userIdHash=${encodeURIComponent(o.config.hashedUserId)}`), o.websocket.object = new WebSocket(e), o.websocket.object.onmessage = (c) => {
|
|
92
|
+
const i = JSON.parse(c.data);
|
|
93
|
+
if (!(!i || !i.route) && i.route === "inapp_web/new_notifications") {
|
|
94
|
+
const a = i;
|
|
95
|
+
o.config.onNewInAppNotifications && o.config.onNewInAppNotifications(
|
|
96
96
|
a.payload.notifications
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
|
-
},
|
|
99
|
+
}, o.websocket.object;
|
|
100
100
|
},
|
|
101
101
|
disconnect: function(e) {
|
|
102
102
|
var c;
|
|
103
|
-
|
|
103
|
+
o.websocket.object && ((c = o.websocket.object) == null || c.close(), e && e(o.websocket.object));
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
106
|
openWebSocket: function() {
|
|
107
|
-
return
|
|
107
|
+
return o.websocket.connect(() => {
|
|
108
108
|
setTimeout(
|
|
109
109
|
() => {
|
|
110
110
|
this.websocket.disconnect(() => {
|
|
@@ -119,10 +119,10 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
119
119
|
// They may or may not do additional tasks.
|
|
120
120
|
// e.g. identify simply maps to postUsers
|
|
121
121
|
getInAppNotifications: async (e) => {
|
|
122
|
-
const c = e.maxCountNeeded ||
|
|
123
|
-
let a = [], f = e.before,
|
|
122
|
+
const c = e.maxCountNeeded || o.config.getInAppDefaultCount, i = e.oldestNeeded || o.config.getInAppDefaultOldest;
|
|
123
|
+
let a = [], f = e.before, b = !0, h = !0;
|
|
124
124
|
for (; h; ) {
|
|
125
|
-
const l = (await
|
|
125
|
+
const l = (await o.rest.getNotifications(
|
|
126
126
|
f,
|
|
127
127
|
c
|
|
128
128
|
)).notifications.filter(
|
|
@@ -131,11 +131,11 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
131
131
|
f = l.reduce(
|
|
132
132
|
(g, w) => g < w.date ? g : w.date,
|
|
133
133
|
e.before
|
|
134
|
-
), a = [...a, ...l],
|
|
134
|
+
), a = [...a, ...l], b = l.length > 0, h = !0, (!b || a.length >= c || f < i) && (h = !1);
|
|
135
135
|
}
|
|
136
136
|
return {
|
|
137
137
|
items: a,
|
|
138
|
-
hasMore:
|
|
138
|
+
hasMore: b,
|
|
139
139
|
oldestReceived: f
|
|
140
140
|
};
|
|
141
141
|
},
|
|
@@ -143,23 +143,23 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
143
143
|
const c = {
|
|
144
144
|
trackingIds: e.ids
|
|
145
145
|
};
|
|
146
|
-
return e.archived === !0 ? c.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (c.archived = null), e.clicked === !0 ? c.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (c.clicked = null), e.opened === !0 ? c.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (c.opened = null),
|
|
146
|
+
return e.archived === !0 ? c.archived = (/* @__PURE__ */ new Date()).toISOString() : e.archived === !1 && (c.archived = null), e.clicked === !0 ? c.clicked = (/* @__PURE__ */ new Date()).toISOString() : e.clicked === !1 && (c.clicked = null), e.opened === !0 ? c.opened = (/* @__PURE__ */ new Date()).toISOString() : e.opened === !1 && (c.opened = null), o.rest.patchNotifications(c);
|
|
147
147
|
},
|
|
148
|
-
getPreferences: async () =>
|
|
149
|
-
updateDeliveryOption: async (e) =>
|
|
148
|
+
getPreferences: async () => o.rest.getPreferences(),
|
|
149
|
+
updateDeliveryOption: async (e) => o.rest.postPreferences([e]),
|
|
150
150
|
identify: async (e) => {
|
|
151
|
-
if (e.id && e.id !==
|
|
151
|
+
if (e.id && e.id !== o.config.userId)
|
|
152
152
|
throw new Error(
|
|
153
153
|
"The id in the parameters does not match the initialized userId."
|
|
154
154
|
);
|
|
155
|
-
return
|
|
155
|
+
return o.rest.postUser(e);
|
|
156
156
|
},
|
|
157
|
-
getUserAccountMetadata: async () =>
|
|
157
|
+
getUserAccountMetadata: async () => o.rest.getUserAccountMetadata()
|
|
158
158
|
}, F = typeof window < "u", te = (e) => {
|
|
159
|
-
const
|
|
159
|
+
const i = {
|
|
160
160
|
...{
|
|
161
|
-
apiURL: "
|
|
162
|
-
wsURL: "
|
|
161
|
+
apiURL: "api.notificationapi.com",
|
|
162
|
+
wsURL: "ws.notificationapi.com",
|
|
163
163
|
initialLoadMaxCount: 1e3,
|
|
164
164
|
initialLoadMaxAge: new Date((/* @__PURE__ */ new Date()).setMonth((/* @__PURE__ */ new Date()).getMonth() - 3)),
|
|
165
165
|
playSoundOnNewNotification: !1,
|
|
@@ -169,11 +169,11 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
169
169
|
},
|
|
170
170
|
...e,
|
|
171
171
|
user: "userId" in e ? { id: e.userId } : e.user
|
|
172
|
-
}, [a, f] = I(), [
|
|
173
|
-
|
|
172
|
+
}, [a, f] = I(), [b, h] = I(), [l, g] = I(), [w, S] = I(!1), [k, T] = I((/* @__PURE__ */ new Date()).toISOString()), [A, C] = I(!0), [v, N] = I(i.webPushOptInMessage), [L, J] = I(!1), W = m(() => {
|
|
173
|
+
i.playSoundOnNewNotification && new Audio(i.newNotificationSoundPath).play().catch((s) => {
|
|
174
174
|
console.log("Failed to play new notification sound:", s);
|
|
175
175
|
});
|
|
176
|
-
}, [
|
|
176
|
+
}, [i.newNotificationSoundPath, i.playSoundOnNewNotification]), y = m((t) => {
|
|
177
177
|
const s = (/* @__PURE__ */ new Date()).toISOString();
|
|
178
178
|
f((n) => (t = Array.isArray(t) ? t : [], t = t.filter((d) => {
|
|
179
179
|
const p = d.expDate && new Date(d.expDate * 1e3).toISOString() < s, D = new Date(d.date).getTime() > new Date(s).getTime() + 1e3;
|
|
@@ -183,52 +183,56 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
183
183
|
...n
|
|
184
184
|
]));
|
|
185
185
|
}, []), u = X(() => {
|
|
186
|
-
const t = e.client ? e.client :
|
|
187
|
-
clientId:
|
|
188
|
-
userId:
|
|
189
|
-
hashedUserId:
|
|
186
|
+
const t = e.client ? e.client : o.init({
|
|
187
|
+
clientId: i.clientId,
|
|
188
|
+
userId: i.user.id,
|
|
189
|
+
hashedUserId: i.hashedUserId,
|
|
190
190
|
onNewInAppNotifications: (s) => {
|
|
191
|
-
|
|
192
|
-
}
|
|
191
|
+
W(), y(s);
|
|
192
|
+
},
|
|
193
|
+
host: i.apiURL,
|
|
194
|
+
websocketHost: i.wsURL
|
|
193
195
|
});
|
|
194
196
|
return t.identify({
|
|
195
|
-
email:
|
|
196
|
-
number:
|
|
197
|
+
email: i.user.email,
|
|
198
|
+
number: i.user.number
|
|
197
199
|
}), t;
|
|
198
200
|
}, [
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
201
|
+
i.clientId,
|
|
202
|
+
i.user.id,
|
|
203
|
+
i.user.email,
|
|
204
|
+
i.user.number,
|
|
205
|
+
i.hashedUserId,
|
|
204
206
|
y,
|
|
205
|
-
|
|
206
|
-
e.client
|
|
207
|
-
|
|
207
|
+
W,
|
|
208
|
+
e.client,
|
|
209
|
+
i.apiURL,
|
|
210
|
+
i.wsURL
|
|
211
|
+
]), x = m(
|
|
208
212
|
async (t, s) => {
|
|
209
213
|
const n = await u.rest.getNotifications(t, s);
|
|
210
|
-
|
|
214
|
+
T(n.oldestReceived), C(n.couldLoadMore), y(n.notifications);
|
|
211
215
|
},
|
|
212
216
|
[y, u.rest]
|
|
213
|
-
),
|
|
217
|
+
), E = U(A), R = U(w), $ = U(k);
|
|
214
218
|
P(() => {
|
|
215
|
-
|
|
219
|
+
E.current = A, R.current = w, $.current = k;
|
|
216
220
|
}, [A, w, k]);
|
|
217
221
|
const O = m(
|
|
218
222
|
async (t) => {
|
|
219
|
-
if (!(!t && (!
|
|
223
|
+
if (!(!t && (!E.current || R.current))) {
|
|
220
224
|
S(!0);
|
|
221
225
|
try {
|
|
222
|
-
await
|
|
226
|
+
await x(
|
|
223
227
|
t ? (/* @__PURE__ */ new Date()).toISOString() : $.current,
|
|
224
|
-
t ?
|
|
228
|
+
t ? i.initialLoadMaxCount : 1e3
|
|
225
229
|
);
|
|
226
230
|
} finally {
|
|
227
231
|
S(!1);
|
|
228
232
|
}
|
|
229
233
|
}
|
|
230
234
|
},
|
|
231
|
-
[
|
|
235
|
+
[i.initialLoadMaxCount, x]
|
|
232
236
|
), B = async (t) => {
|
|
233
237
|
if (!a) return;
|
|
234
238
|
const s = (/* @__PURE__ */ new Date()).toISOString(), n = a.filter((r) => t.includes(r.id) && !r.clicked).map((r) => r.id);
|
|
@@ -289,8 +293,8 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
289
293
|
});
|
|
290
294
|
});
|
|
291
295
|
}, M = m(() => {
|
|
292
|
-
"serviceWorker" in navigator && navigator.serviceWorker.register(
|
|
293
|
-
|
|
296
|
+
"serviceWorker" in navigator && navigator.serviceWorker.register(i.customServiceWorkerPath).then(async (t) => {
|
|
297
|
+
N(!1), ne().then(async (s) => {
|
|
294
298
|
s === "granted" ? await t.pushManager.subscribe({
|
|
295
299
|
userVisibleOnly: !0,
|
|
296
300
|
applicationServerKey: l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
|
|
@@ -323,25 +327,25 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
323
327
|
});
|
|
324
328
|
}, [
|
|
325
329
|
u,
|
|
326
|
-
|
|
330
|
+
i.customServiceWorkerPath,
|
|
327
331
|
l == null ? void 0 : l.userAccountMetadata.environmentVapidPublicKey
|
|
328
332
|
]);
|
|
329
333
|
P(() => {
|
|
330
|
-
f([]), S(!1), h(void 0),
|
|
334
|
+
f([]), S(!1), h(void 0), T((/* @__PURE__ */ new Date()).toISOString()), C(!0), O(!0), u.openWebSocket(), u.getPreferences().then((t) => {
|
|
331
335
|
h(t);
|
|
332
336
|
});
|
|
333
337
|
}, [u, O, M]), P(() => {
|
|
334
|
-
F && "Notification" in window && typeof Notification.requestPermission == "function" && Notification.permission !== "default" &&
|
|
338
|
+
F && "Notification" in window && typeof Notification.requestPermission == "function" && Notification.permission !== "default" && N(!1), v === "AUTOMATIC" && (N(
|
|
335
339
|
localStorage.getItem("hideWebPushOptInMessage") !== "true"
|
|
336
340
|
), u.getUserAccountMetadata().then((t) => {
|
|
337
|
-
g(t),
|
|
341
|
+
g(t), N(t.userAccountMetadata.hasWebPushEnabled);
|
|
338
342
|
}));
|
|
339
343
|
}, [u, v]), P(() => {
|
|
340
|
-
|
|
341
|
-
}, [
|
|
344
|
+
L && M();
|
|
345
|
+
}, [L, M]);
|
|
342
346
|
const z = {
|
|
343
347
|
notifications: a,
|
|
344
|
-
preferences:
|
|
348
|
+
preferences: b,
|
|
345
349
|
userAccountMetaData: l,
|
|
346
350
|
webPushOptInMessage: v,
|
|
347
351
|
loadNotifications: O,
|
|
@@ -352,18 +356,18 @@ const Z = async (e, c, o, a, f, N, h) => {
|
|
|
352
356
|
updateDelivery: _,
|
|
353
357
|
updateDeliveries: j,
|
|
354
358
|
getClient: () => u,
|
|
355
|
-
setWebPushOptInMessage:
|
|
359
|
+
setWebPushOptInMessage: N,
|
|
356
360
|
setWebPushOptIn: J
|
|
357
361
|
};
|
|
358
362
|
return /* @__PURE__ */ Q(H.Provider, { value: z, children: e.children });
|
|
359
|
-
},
|
|
363
|
+
}, ie = () => {
|
|
360
364
|
const e = Y(H);
|
|
361
365
|
if (!e)
|
|
362
366
|
throw new Error("useMyContext must be used within a MyProvider");
|
|
363
367
|
return e;
|
|
364
368
|
};
|
|
365
|
-
te.useNotificationAPIContext =
|
|
366
|
-
const
|
|
369
|
+
te.useNotificationAPIContext = ie;
|
|
370
|
+
const ne = async () => {
|
|
367
371
|
if (F && "Notification" in window && typeof Notification.requestPermission == "function")
|
|
368
372
|
try {
|
|
369
373
|
return await Notification.requestPermission();
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notificationapi/react",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"overrides": {
|
|
7
|
+
"esbuild": "^0.25.0",
|
|
8
|
+
"vue-template-compiler": "^2.7.16"
|
|
9
|
+
},
|
|
6
10
|
"browserslist": [
|
|
7
11
|
"last 2 versions",
|
|
8
12
|
"last 2 ChromeAndroid versions",
|
|
@@ -59,7 +63,7 @@
|
|
|
59
63
|
"@fontsource/roboto": "^5.1.1",
|
|
60
64
|
"@mui/icons-material": "^6.3.1",
|
|
61
65
|
"@mui/material": "^6.3.1",
|
|
62
|
-
"@notificationapi/core": "^0.0.
|
|
66
|
+
"@notificationapi/core": "^0.0.15",
|
|
63
67
|
"javascript-time-ago": "^2.5.10",
|
|
64
68
|
"liquidjs": "^10.14.0",
|
|
65
69
|
"rc-virtual-list": "^3.11.5",
|