@rpcbase/client 0.443.0 → 0.444.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/index.js +131 -64
- package/dist/index.js.map +1 -1
- package/dist/notificationsRealtime.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2420,7 +2420,7 @@ const getNormalizedNotificationAppName = (appName) => {
|
|
|
2420
2420
|
const getScopedNotificationKey = (userId, appName) => `${encodeURIComponent(appName)}:${encodeURIComponent(userId)}`;
|
|
2421
2421
|
const getTabStateKey = (userId, appName) => `${TAB_STATE_KEY_PREFIX}${getScopedNotificationKey(userId, appName)}:${NOTIFICATION_TAB_ID}`;
|
|
2422
2422
|
const getTabStateKeyPrefix = (userId, appName) => `${TAB_STATE_KEY_PREFIX}${getScopedNotificationKey(userId, appName)}:`;
|
|
2423
|
-
const getDeliveryKey = (userId, appName, notificationId) => `${DELIVERY_KEY_PREFIX}${getScopedNotificationKey(userId, appName)}:${encodeURIComponent(notificationId)}`;
|
|
2423
|
+
const getDeliveryKey = (userId, appName, mode, notificationId) => `${DELIVERY_KEY_PREFIX}${mode}:${getScopedNotificationKey(userId, appName)}:${encodeURIComponent(notificationId)}`;
|
|
2424
2424
|
const getDeliveryLockName = (userId, appName) => `${DELIVERY_LOCK_PREFIX}${getScopedNotificationKey(userId, appName)}`;
|
|
2425
2425
|
const getFallbackDeliveryLockKey = (userId, appName) => `${FALLBACK_DELIVERY_LOCK_KEY_PREFIX}${getScopedNotificationKey(userId, appName)}`;
|
|
2426
2426
|
const getLocalStorage = () => {
|
|
@@ -2501,7 +2501,7 @@ const claimNotificationDeliveriesFromStorage = (items, userId, appName, mode) =>
|
|
|
2501
2501
|
const now = Date.now();
|
|
2502
2502
|
const claimed = [];
|
|
2503
2503
|
for (const item of items) {
|
|
2504
|
-
const key = getDeliveryKey(userId, appName, item.id);
|
|
2504
|
+
const key = getDeliveryKey(userId, appName, mode, item.id);
|
|
2505
2505
|
const current = parseJsonRecord(storage.getItem(key));
|
|
2506
2506
|
const deliveredAt = typeof current?.deliveredAt === "number" ? current.deliveredAt : 0;
|
|
2507
2507
|
if (deliveredAt && now - deliveredAt < DELIVERY_TTL_MS) continue;
|
|
@@ -2606,6 +2606,11 @@ const showInAppNotifications = (items) => {
|
|
|
2606
2606
|
});
|
|
2607
2607
|
}
|
|
2608
2608
|
};
|
|
2609
|
+
const sortNotificationsByCreatedAt = (items) => [...items].sort((a2, b2) => {
|
|
2610
|
+
const aMs = Date.parse(a2.createdAt);
|
|
2611
|
+
const bMs = Date.parse(b2.createdAt);
|
|
2612
|
+
return (Number.isFinite(aMs) ? aMs : 0) - (Number.isFinite(bMs) ? bMs : 0);
|
|
2613
|
+
});
|
|
2609
2614
|
const canShowNativeNotification = () => {
|
|
2610
2615
|
if (typeof window === "undefined") return false;
|
|
2611
2616
|
if (!("Notification" in window)) return false;
|
|
@@ -2662,16 +2667,34 @@ const showNotificationsForCurrentFocusState = async (items, userId, appName) =>
|
|
|
2662
2667
|
if (claimed2.length > 0) {
|
|
2663
2668
|
showInAppNotifications(claimed2);
|
|
2664
2669
|
}
|
|
2665
|
-
return;
|
|
2670
|
+
return [];
|
|
2666
2671
|
}
|
|
2667
|
-
if (!canShowNativeNotification()) return;
|
|
2672
|
+
if (!canShowNativeNotification()) return items;
|
|
2668
2673
|
const claimed = await claimNotificationDeliveries(items, userId, appName, "native");
|
|
2669
2674
|
if (claimed.length > 0) {
|
|
2670
2675
|
showNativeNotifications(claimed);
|
|
2671
2676
|
}
|
|
2677
|
+
return items;
|
|
2678
|
+
};
|
|
2679
|
+
const flushPendingInAppToasts = (pendingInAppToastItems, userId, appName) => {
|
|
2680
|
+
if (!isDocumentActive()) return;
|
|
2681
|
+
const pending = sortNotificationsByCreatedAt(Array.from(pendingInAppToastItems.current.values()));
|
|
2682
|
+
pendingInAppToastItems.current.clear();
|
|
2683
|
+
if (pending.length === 0) return;
|
|
2684
|
+
void claimNotificationDeliveries(pending, userId, appName, "in-app").then((claimed) => {
|
|
2685
|
+
if (claimed.length > 0) {
|
|
2686
|
+
showInAppNotifications(claimed);
|
|
2687
|
+
}
|
|
2688
|
+
});
|
|
2689
|
+
};
|
|
2690
|
+
const queuePendingInAppToasts = (pendingInAppToastItems, items, userId, appName) => {
|
|
2691
|
+
for (const item of items) {
|
|
2692
|
+
pendingInAppToastItems.current.set(item.id, item);
|
|
2693
|
+
}
|
|
2694
|
+
flushPendingInAppToasts(pendingInAppToastItems, userId, appName);
|
|
2672
2695
|
};
|
|
2673
2696
|
function NotificationsRealtimeProvider(t0) {
|
|
2674
|
-
const $ = c(
|
|
2697
|
+
const $ = c(63);
|
|
2675
2698
|
const {
|
|
2676
2699
|
userId,
|
|
2677
2700
|
appName,
|
|
@@ -2870,29 +2893,38 @@ function NotificationsRealtimeProvider(t0) {
|
|
|
2870
2893
|
const toastStartMs = useRef(t15);
|
|
2871
2894
|
let t16;
|
|
2872
2895
|
if ($[31] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
2873
|
-
t16 = ()
|
|
2874
|
-
hasSeededToastIds.current = false;
|
|
2875
|
-
lastToastIds.current = /* @__PURE__ */ new Set();
|
|
2876
|
-
toastStartMs.current = Date.now();
|
|
2877
|
-
};
|
|
2896
|
+
t16 = /* @__PURE__ */ new Map();
|
|
2878
2897
|
$[31] = t16;
|
|
2879
2898
|
} else {
|
|
2880
2899
|
t16 = $[31];
|
|
2881
2900
|
}
|
|
2901
|
+
const pendingInAppToastItems = useRef(t16);
|
|
2882
2902
|
let t17;
|
|
2883
|
-
if ($[32]
|
|
2884
|
-
t17 =
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2903
|
+
if ($[32] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
2904
|
+
t17 = () => {
|
|
2905
|
+
hasSeededToastIds.current = false;
|
|
2906
|
+
lastToastIds.current = /* @__PURE__ */ new Set();
|
|
2907
|
+
toastStartMs.current = Date.now();
|
|
2908
|
+
pendingInAppToastItems.current = /* @__PURE__ */ new Map();
|
|
2909
|
+
};
|
|
2910
|
+
$[32] = t17;
|
|
2888
2911
|
} else {
|
|
2889
|
-
t17 = $[
|
|
2912
|
+
t17 = $[32];
|
|
2890
2913
|
}
|
|
2891
|
-
useEffect(t16, t17);
|
|
2892
2914
|
let t18;
|
|
2915
|
+
if ($[33] !== normalizedAppName || $[34] !== trimmedUserId) {
|
|
2916
|
+
t18 = [normalizedAppName, trimmedUserId];
|
|
2917
|
+
$[33] = normalizedAppName;
|
|
2918
|
+
$[34] = trimmedUserId;
|
|
2919
|
+
$[35] = t18;
|
|
2920
|
+
} else {
|
|
2921
|
+
t18 = $[35];
|
|
2922
|
+
}
|
|
2923
|
+
useEffect(t17, t18);
|
|
2893
2924
|
let t19;
|
|
2894
|
-
|
|
2895
|
-
|
|
2925
|
+
let t20;
|
|
2926
|
+
if ($[36] !== canUseRts || $[37] !== normalizedAppName || $[38] !== trimmedUserId) {
|
|
2927
|
+
t19 = () => {
|
|
2896
2928
|
if (!canUseRts) {
|
|
2897
2929
|
return;
|
|
2898
2930
|
}
|
|
@@ -2918,21 +2950,52 @@ function NotificationsRealtimeProvider(t0) {
|
|
|
2918
2950
|
removeState();
|
|
2919
2951
|
};
|
|
2920
2952
|
};
|
|
2921
|
-
|
|
2922
|
-
$[
|
|
2923
|
-
$[
|
|
2924
|
-
$[
|
|
2925
|
-
$[38] = t18;
|
|
2953
|
+
t20 = [canUseRts, normalizedAppName, trimmedUserId];
|
|
2954
|
+
$[36] = canUseRts;
|
|
2955
|
+
$[37] = normalizedAppName;
|
|
2956
|
+
$[38] = trimmedUserId;
|
|
2926
2957
|
$[39] = t19;
|
|
2958
|
+
$[40] = t20;
|
|
2927
2959
|
} else {
|
|
2928
|
-
t18 = $[38];
|
|
2929
2960
|
t19 = $[39];
|
|
2961
|
+
t20 = $[40];
|
|
2930
2962
|
}
|
|
2931
|
-
useEffect(
|
|
2932
|
-
let t20;
|
|
2963
|
+
useEffect(t19, t20);
|
|
2933
2964
|
let t21;
|
|
2934
|
-
|
|
2935
|
-
|
|
2965
|
+
let t22;
|
|
2966
|
+
if ($[41] !== canUseRts || $[42] !== normalizedAppName || $[43] !== trimmedUserId) {
|
|
2967
|
+
t21 = () => {
|
|
2968
|
+
if (!canUseRts) {
|
|
2969
|
+
return;
|
|
2970
|
+
}
|
|
2971
|
+
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2972
|
+
return;
|
|
2973
|
+
}
|
|
2974
|
+
const handlePendingInAppToastFlush = () => {
|
|
2975
|
+
flushPendingInAppToasts(pendingInAppToastItems, trimmedUserId, normalizedAppName);
|
|
2976
|
+
};
|
|
2977
|
+
window.addEventListener("focus", handlePendingInAppToastFlush);
|
|
2978
|
+
document.addEventListener("visibilitychange", handlePendingInAppToastFlush);
|
|
2979
|
+
return () => {
|
|
2980
|
+
window.removeEventListener("focus", handlePendingInAppToastFlush);
|
|
2981
|
+
document.removeEventListener("visibilitychange", handlePendingInAppToastFlush);
|
|
2982
|
+
};
|
|
2983
|
+
};
|
|
2984
|
+
t22 = [canUseRts, normalizedAppName, trimmedUserId];
|
|
2985
|
+
$[41] = canUseRts;
|
|
2986
|
+
$[42] = normalizedAppName;
|
|
2987
|
+
$[43] = trimmedUserId;
|
|
2988
|
+
$[44] = t21;
|
|
2989
|
+
$[45] = t22;
|
|
2990
|
+
} else {
|
|
2991
|
+
t21 = $[44];
|
|
2992
|
+
t22 = $[45];
|
|
2993
|
+
}
|
|
2994
|
+
useEffect(t21, t22);
|
|
2995
|
+
let t23;
|
|
2996
|
+
let t24;
|
|
2997
|
+
if ($[46] !== canUseRts || $[47] !== normalizedAppName || $[48] !== notifications || $[49] !== notificationsQuery.loading || $[50] !== toastOnNew || $[51] !== trimmedUserId) {
|
|
2998
|
+
t23 = () => {
|
|
2936
2999
|
if (!toastOnNew) {
|
|
2937
3000
|
return;
|
|
2938
3001
|
}
|
|
@@ -2953,7 +3016,9 @@ function NotificationsRealtimeProvider(t0) {
|
|
|
2953
3016
|
return createdAtMs >= toastStartMs.current - NEW_NOTIFICATION_START_TOLERANCE_MS;
|
|
2954
3017
|
});
|
|
2955
3018
|
if (eligible.length) {
|
|
2956
|
-
showNotificationsForCurrentFocusState(eligible, trimmedUserId, normalizedAppName)
|
|
3019
|
+
showNotificationsForCurrentFocusState(eligible, trimmedUserId, normalizedAppName).then((pending) => {
|
|
3020
|
+
queuePendingInAppToasts(pendingInAppToastItems, pending, trimmedUserId, normalizedAppName);
|
|
3021
|
+
});
|
|
2957
3022
|
}
|
|
2958
3023
|
return;
|
|
2959
3024
|
}
|
|
@@ -2974,52 +3039,54 @@ function NotificationsRealtimeProvider(t0) {
|
|
|
2974
3039
|
if (!eligible_0.length) {
|
|
2975
3040
|
return;
|
|
2976
3041
|
}
|
|
2977
|
-
showNotificationsForCurrentFocusState(eligible_0, trimmedUserId, normalizedAppName)
|
|
3042
|
+
showNotificationsForCurrentFocusState(eligible_0, trimmedUserId, normalizedAppName).then((pending_0) => {
|
|
3043
|
+
queuePendingInAppToasts(pendingInAppToastItems, pending_0, trimmedUserId, normalizedAppName);
|
|
3044
|
+
});
|
|
2978
3045
|
};
|
|
2979
|
-
|
|
2980
|
-
$[
|
|
2981
|
-
$[
|
|
2982
|
-
$[
|
|
2983
|
-
$[
|
|
2984
|
-
$[
|
|
2985
|
-
$[
|
|
2986
|
-
$[
|
|
2987
|
-
$[
|
|
3046
|
+
t24 = [canUseRts, normalizedAppName, notifications, notificationsQuery.loading, toastOnNew, trimmedUserId];
|
|
3047
|
+
$[46] = canUseRts;
|
|
3048
|
+
$[47] = normalizedAppName;
|
|
3049
|
+
$[48] = notifications;
|
|
3050
|
+
$[49] = notificationsQuery.loading;
|
|
3051
|
+
$[50] = toastOnNew;
|
|
3052
|
+
$[51] = trimmedUserId;
|
|
3053
|
+
$[52] = t23;
|
|
3054
|
+
$[53] = t24;
|
|
2988
3055
|
} else {
|
|
2989
|
-
|
|
2990
|
-
|
|
3056
|
+
t23 = $[52];
|
|
3057
|
+
t24 = $[53];
|
|
2991
3058
|
}
|
|
2992
|
-
useEffect(
|
|
2993
|
-
let
|
|
2994
|
-
if ($[
|
|
2995
|
-
|
|
3059
|
+
useEffect(t23, t24);
|
|
3060
|
+
let t25;
|
|
3061
|
+
if ($[54] !== notifications || $[55] !== notificationsQuery.error || $[56] !== notificationsQuery.loading || $[57] !== unreadCount || $[58] !== unseenCount) {
|
|
3062
|
+
t25 = {
|
|
2996
3063
|
notifications,
|
|
2997
3064
|
unreadCount,
|
|
2998
3065
|
unseenCount,
|
|
2999
3066
|
loading: notificationsQuery.loading,
|
|
3000
3067
|
error: notificationsQuery.error
|
|
3001
3068
|
};
|
|
3002
|
-
$[
|
|
3003
|
-
$[
|
|
3004
|
-
$[
|
|
3005
|
-
$[
|
|
3006
|
-
$[
|
|
3007
|
-
$[
|
|
3069
|
+
$[54] = notifications;
|
|
3070
|
+
$[55] = notificationsQuery.error;
|
|
3071
|
+
$[56] = notificationsQuery.loading;
|
|
3072
|
+
$[57] = unreadCount;
|
|
3073
|
+
$[58] = unseenCount;
|
|
3074
|
+
$[59] = t25;
|
|
3008
3075
|
} else {
|
|
3009
|
-
|
|
3010
|
-
}
|
|
3011
|
-
const value =
|
|
3012
|
-
const
|
|
3013
|
-
let
|
|
3014
|
-
if ($[
|
|
3015
|
-
|
|
3016
|
-
$[
|
|
3017
|
-
$[
|
|
3018
|
-
$[
|
|
3076
|
+
t25 = $[59];
|
|
3077
|
+
}
|
|
3078
|
+
const value = t25;
|
|
3079
|
+
const t26 = canUseRts ? value : null;
|
|
3080
|
+
let t27;
|
|
3081
|
+
if ($[60] !== children || $[61] !== t26) {
|
|
3082
|
+
t27 = /* @__PURE__ */ jsx(NotificationsRealtimeContext.Provider, { value: t26, children });
|
|
3083
|
+
$[60] = children;
|
|
3084
|
+
$[61] = t26;
|
|
3085
|
+
$[62] = t27;
|
|
3019
3086
|
} else {
|
|
3020
|
-
|
|
3087
|
+
t27 = $[62];
|
|
3021
3088
|
}
|
|
3022
|
-
return
|
|
3089
|
+
return t27;
|
|
3023
3090
|
}
|
|
3024
3091
|
function _temp5(n_2) {
|
|
3025
3092
|
return n_2.id;
|