@repzo/widget-react-native 1.3.1 → 1.5.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/CHANGELOG.md +173 -5
- package/README.md +99 -13
- package/lib/commonjs/api/client.js +125 -28
- package/lib/commonjs/api/client.js.map +1 -1
- package/lib/commonjs/attachments/file-size.js +52 -0
- package/lib/commonjs/attachments/file-size.js.map +1 -0
- package/lib/commonjs/attachments/local-previews.js +40 -0
- package/lib/commonjs/attachments/local-previews.js.map +1 -0
- package/lib/commonjs/attachments/pickers.js +20 -29
- package/lib/commonjs/attachments/pickers.js.map +1 -1
- package/lib/commonjs/i18n.js +22 -3
- package/lib/commonjs/i18n.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/locales.js +12 -3
- package/lib/commonjs/locales.js.map +1 -1
- package/lib/commonjs/state/user-update-queue.js +168 -0
- package/lib/commonjs/state/user-update-queue.js.map +1 -0
- package/lib/commonjs/state/widget-store.js +303 -33
- package/lib/commonjs/state/widget-store.js.map +1 -1
- package/lib/commonjs/storage.js +3 -1
- package/lib/commonjs/storage.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/ui/WidgetProvider.js +33 -13
- package/lib/commonjs/ui/WidgetProvider.js.map +1 -1
- package/lib/commonjs/ui/components/AttachmentChips.js +109 -40
- package/lib/commonjs/ui/components/AttachmentChips.js.map +1 -1
- package/lib/commonjs/ui/components/ConversationRow.js +65 -10
- package/lib/commonjs/ui/components/ConversationRow.js.map +1 -1
- package/lib/commonjs/ui/components/ImageViewer.js +229 -24
- package/lib/commonjs/ui/components/ImageViewer.js.map +1 -1
- package/lib/commonjs/ui/components/RatingCard.js +5 -2
- package/lib/commonjs/ui/components/RatingCard.js.map +1 -1
- package/lib/commonjs/ui/components/ZoomableImage.js +58 -10
- package/lib/commonjs/ui/components/ZoomableImage.js.map +1 -1
- package/lib/commonjs/ui/hooks/use-retained-state.js +39 -0
- package/lib/commonjs/ui/hooks/use-retained-state.js.map +1 -0
- package/lib/commonjs/ui/screens/chat/ChatView.js +651 -165
- package/lib/commonjs/ui/screens/chat/ChatView.js.map +1 -1
- package/lib/commonjs/ui/screens/chat/ChatView.styles.js +138 -1
- package/lib/commonjs/ui/screens/chat/ChatView.styles.js.map +1 -1
- package/lib/commonjs/ui/screens/conversations/ConversationsList.js +1 -0
- package/lib/commonjs/ui/screens/conversations/ConversationsList.js.map +1 -1
- package/lib/commonjs/ui/screens/home/HomeView.js +38 -55
- package/lib/commonjs/ui/screens/home/HomeView.js.map +1 -1
- package/lib/commonjs/ui/screens/home/HomeView.styles.js +36 -45
- package/lib/commonjs/ui/screens/home/HomeView.styles.js.map +1 -1
- package/lib/commonjs/ui/utils/html.js +13 -0
- package/lib/commonjs/ui/utils/html.js.map +1 -1
- package/lib/commonjs/ui/utils/image-load-queue.js +114 -0
- package/lib/commonjs/ui/utils/image-load-queue.js.map +1 -0
- package/lib/commonjs/ui/utils/inline-attachments.js +88 -0
- package/lib/commonjs/ui/utils/inline-attachments.js.map +1 -0
- package/lib/module/api/client.js +123 -27
- package/lib/module/api/client.js.map +1 -1
- package/lib/module/attachments/file-size.js +47 -0
- package/lib/module/attachments/file-size.js.map +1 -0
- package/lib/module/attachments/local-previews.js +33 -0
- package/lib/module/attachments/local-previews.js.map +1 -0
- package/lib/module/attachments/pickers.js +15 -25
- package/lib/module/attachments/pickers.js.map +1 -1
- package/lib/module/i18n.js +22 -3
- package/lib/module/i18n.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/locales.js +12 -3
- package/lib/module/locales.js.map +1 -1
- package/lib/module/state/user-update-queue.js +163 -0
- package/lib/module/state/user-update-queue.js.map +1 -0
- package/lib/module/state/widget-store.js +305 -35
- package/lib/module/state/widget-store.js.map +1 -1
- package/lib/module/storage.js +2 -0
- package/lib/module/storage.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/ui/WidgetProvider.js +33 -13
- package/lib/module/ui/WidgetProvider.js.map +1 -1
- package/lib/module/ui/components/AttachmentChips.js +111 -42
- package/lib/module/ui/components/AttachmentChips.js.map +1 -1
- package/lib/module/ui/components/ConversationRow.js +65 -10
- package/lib/module/ui/components/ConversationRow.js.map +1 -1
- package/lib/module/ui/components/ImageViewer.js +231 -26
- package/lib/module/ui/components/ImageViewer.js.map +1 -1
- package/lib/module/ui/components/RatingCard.js +5 -2
- package/lib/module/ui/components/RatingCard.js.map +1 -1
- package/lib/module/ui/components/ZoomableImage.js +58 -10
- package/lib/module/ui/components/ZoomableImage.js.map +1 -1
- package/lib/module/ui/hooks/use-retained-state.js +34 -0
- package/lib/module/ui/hooks/use-retained-state.js.map +1 -0
- package/lib/module/ui/screens/chat/ChatView.js +655 -169
- package/lib/module/ui/screens/chat/ChatView.js.map +1 -1
- package/lib/module/ui/screens/chat/ChatView.styles.js +140 -2
- package/lib/module/ui/screens/chat/ChatView.styles.js.map +1 -1
- package/lib/module/ui/screens/conversations/ConversationsList.js +1 -0
- package/lib/module/ui/screens/conversations/ConversationsList.js.map +1 -1
- package/lib/module/ui/screens/home/HomeView.js +40 -57
- package/lib/module/ui/screens/home/HomeView.js.map +1 -1
- package/lib/module/ui/screens/home/HomeView.styles.js +36 -45
- package/lib/module/ui/screens/home/HomeView.styles.js.map +1 -1
- package/lib/module/ui/utils/html.js +12 -0
- package/lib/module/ui/utils/html.js.map +1 -1
- package/lib/module/ui/utils/image-load-queue.js +109 -0
- package/lib/module/ui/utils/image-load-queue.js.map +1 -0
- package/lib/module/ui/utils/inline-attachments.js +85 -0
- package/lib/module/ui/utils/inline-attachments.js.map +1 -0
- package/lib/typescript/commonjs/api/client.d.ts +20 -6
- package/lib/typescript/commonjs/api/client.d.ts.map +1 -1
- package/lib/typescript/commonjs/attachments/file-size.d.ts +15 -0
- package/lib/typescript/commonjs/attachments/file-size.d.ts.map +1 -0
- package/lib/typescript/commonjs/attachments/local-previews.d.ts +14 -0
- package/lib/typescript/commonjs/attachments/local-previews.d.ts.map +1 -0
- package/lib/typescript/commonjs/attachments/pickers.d.ts +15 -2
- package/lib/typescript/commonjs/attachments/pickers.d.ts.map +1 -1
- package/lib/typescript/commonjs/i18n.d.ts +12 -3
- package/lib/typescript/commonjs/i18n.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +5 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/locales.d.ts.map +1 -1
- package/lib/typescript/commonjs/state/user-update-queue.d.ts +62 -0
- package/lib/typescript/commonjs/state/user-update-queue.d.ts.map +1 -0
- package/lib/typescript/commonjs/state/widget-store.d.ts +44 -1
- package/lib/typescript/commonjs/state/widget-store.d.ts.map +1 -1
- package/lib/typescript/commonjs/storage.d.ts +2 -0
- package/lib/typescript/commonjs/storage.d.ts.map +1 -1
- package/lib/typescript/commonjs/types.d.ts +53 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/WidgetProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/AttachmentChips.d.ts +13 -3
- package/lib/typescript/commonjs/ui/components/AttachmentChips.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/ConversationRow.d.ts +15 -1
- package/lib/typescript/commonjs/ui/components/ConversationRow.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/ImageViewer.d.ts +26 -6
- package/lib/typescript/commonjs/ui/components/ImageViewer.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/RatingCard.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/components/ZoomableImage.d.ts +10 -1
- package/lib/typescript/commonjs/ui/components/ZoomableImage.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/use-retained-state.d.ts +11 -0
- package/lib/typescript/commonjs/ui/hooks/use-retained-state.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.d.ts +4 -4
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.styles.d.ts +144 -0
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.styles.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.types.d.ts +26 -1
- package/lib/typescript/commonjs/ui/screens/chat/ChatView.types.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/conversations/ConversationsList.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/conversations/ConversationsList.types.d.ts +2 -0
- package/lib/typescript/commonjs/ui/screens/conversations/ConversationsList.types.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/home/HomeView.d.ts +7 -5
- package/lib/typescript/commonjs/ui/screens/home/HomeView.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/home/HomeView.styles.d.ts +30 -35
- package/lib/typescript/commonjs/ui/screens/home/HomeView.styles.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/home/HomeView.types.d.ts +5 -6
- package/lib/typescript/commonjs/ui/screens/home/HomeView.types.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/html.d.ts +5 -0
- package/lib/typescript/commonjs/ui/utils/html.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/utils/image-load-queue.d.ts +44 -0
- package/lib/typescript/commonjs/ui/utils/image-load-queue.d.ts.map +1 -0
- package/lib/typescript/commonjs/ui/utils/inline-attachments.d.ts +29 -0
- package/lib/typescript/commonjs/ui/utils/inline-attachments.d.ts.map +1 -0
- package/lib/typescript/module/api/client.d.ts +20 -6
- package/lib/typescript/module/api/client.d.ts.map +1 -1
- package/lib/typescript/module/attachments/file-size.d.ts +15 -0
- package/lib/typescript/module/attachments/file-size.d.ts.map +1 -0
- package/lib/typescript/module/attachments/local-previews.d.ts +14 -0
- package/lib/typescript/module/attachments/local-previews.d.ts.map +1 -0
- package/lib/typescript/module/attachments/pickers.d.ts +15 -2
- package/lib/typescript/module/attachments/pickers.d.ts.map +1 -1
- package/lib/typescript/module/i18n.d.ts +12 -3
- package/lib/typescript/module/i18n.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +5 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/locales.d.ts.map +1 -1
- package/lib/typescript/module/state/user-update-queue.d.ts +62 -0
- package/lib/typescript/module/state/user-update-queue.d.ts.map +1 -0
- package/lib/typescript/module/state/widget-store.d.ts +44 -1
- package/lib/typescript/module/state/widget-store.d.ts.map +1 -1
- package/lib/typescript/module/storage.d.ts +2 -0
- package/lib/typescript/module/storage.d.ts.map +1 -1
- package/lib/typescript/module/types.d.ts +53 -0
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/lib/typescript/module/ui/WidgetProvider.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/AttachmentChips.d.ts +13 -3
- package/lib/typescript/module/ui/components/AttachmentChips.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/ConversationRow.d.ts +15 -1
- package/lib/typescript/module/ui/components/ConversationRow.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/ImageViewer.d.ts +26 -6
- package/lib/typescript/module/ui/components/ImageViewer.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/RatingCard.d.ts.map +1 -1
- package/lib/typescript/module/ui/components/ZoomableImage.d.ts +10 -1
- package/lib/typescript/module/ui/components/ZoomableImage.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/use-retained-state.d.ts +11 -0
- package/lib/typescript/module/ui/hooks/use-retained-state.d.ts.map +1 -0
- package/lib/typescript/module/ui/screens/chat/ChatView.d.ts +4 -4
- package/lib/typescript/module/ui/screens/chat/ChatView.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/chat/ChatView.styles.d.ts +144 -0
- package/lib/typescript/module/ui/screens/chat/ChatView.styles.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/chat/ChatView.types.d.ts +26 -1
- package/lib/typescript/module/ui/screens/chat/ChatView.types.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/conversations/ConversationsList.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/conversations/ConversationsList.types.d.ts +2 -0
- package/lib/typescript/module/ui/screens/conversations/ConversationsList.types.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/home/HomeView.d.ts +7 -5
- package/lib/typescript/module/ui/screens/home/HomeView.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/home/HomeView.styles.d.ts +30 -35
- package/lib/typescript/module/ui/screens/home/HomeView.styles.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/home/HomeView.types.d.ts +5 -6
- package/lib/typescript/module/ui/screens/home/HomeView.types.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/html.d.ts +5 -0
- package/lib/typescript/module/ui/utils/html.d.ts.map +1 -1
- package/lib/typescript/module/ui/utils/image-load-queue.d.ts +44 -0
- package/lib/typescript/module/ui/utils/image-load-queue.d.ts.map +1 -0
- package/lib/typescript/module/ui/utils/inline-attachments.d.ts +29 -0
- package/lib/typescript/module/ui/utils/inline-attachments.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/api/client.ts +149 -38
- package/src/attachments/file-size.ts +42 -0
- package/src/attachments/local-previews.ts +32 -0
- package/src/attachments/pickers.ts +23 -25
- package/src/i18n.ts +22 -3
- package/src/index.tsx +5 -0
- package/src/locales.ts +12 -3
- package/src/state/user-update-queue.ts +178 -0
- package/src/state/widget-store.ts +346 -51
- package/src/storage.ts +2 -0
- package/src/types.ts +53 -0
- package/src/ui/WidgetProvider.tsx +35 -8
- package/src/ui/components/AttachmentChips.tsx +100 -29
- package/src/ui/components/ConversationRow.tsx +90 -9
- package/src/ui/components/ImageViewer.tsx +242 -24
- package/src/ui/components/RatingCard.tsx +5 -2
- package/src/ui/components/ZoomableImage.tsx +58 -5
- package/src/ui/hooks/use-retained-state.ts +35 -0
- package/src/ui/screens/chat/ChatView.styles.ts +139 -1
- package/src/ui/screens/chat/ChatView.tsx +735 -198
- package/src/ui/screens/chat/ChatView.types.ts +26 -1
- package/src/ui/screens/conversations/ConversationsList.tsx +1 -0
- package/src/ui/screens/conversations/ConversationsList.types.ts +2 -0
- package/src/ui/screens/home/HomeView.styles.ts +36 -45
- package/src/ui/screens/home/HomeView.tsx +54 -70
- package/src/ui/screens/home/HomeView.types.ts +5 -6
- package/src/ui/utils/html.ts +26 -0
- package/src/ui/utils/image-load-queue.ts +108 -0
- package/src/ui/utils/inline-attachments.ts +71 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UserUpdateQueue = exports.USER_UPDATE_WINDOW_MS = exports.USER_UPDATE_BURST = void 0;
|
|
7
|
+
var _client = require("../api/client.js");
|
|
8
|
+
/**
|
|
9
|
+
* Paces `updateUser()` the way Intercom paces its web `update` (20 calls per
|
|
10
|
+
* 30 minutes), so a host that calls it on a timer or on every GPS fix can't
|
|
11
|
+
* flood Workstation.
|
|
12
|
+
*
|
|
13
|
+
* - Values that match what Workstation already has are not sent again.
|
|
14
|
+
* - Up to `burst` sends go out straight away; after that one more is allowed
|
|
15
|
+
* every `windowMs / burst` (90 s by default).
|
|
16
|
+
* - While a send is in flight, rate limited or out of budget, new values wait
|
|
17
|
+
* and merge into one bag, newest value per key. Nothing is lost: the latest
|
|
18
|
+
* of every key goes out on the next allowed send. Workstation merges the bag
|
|
19
|
+
* into the saved attributes per key, so sending only what changed is enough.
|
|
20
|
+
* - A 429 holds sends until its `Retry-After`. A failed connection or a 5xx
|
|
21
|
+
* keeps the values and tries again later.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const USER_UPDATE_BURST = exports.USER_UPDATE_BURST = 20;
|
|
25
|
+
const USER_UPDATE_WINDOW_MS = exports.USER_UPDATE_WINDOW_MS = 30 * 60 * 1000;
|
|
26
|
+
/** Wait after a 429 without a usable `Retry-After`, or after a failed connection / 5xx. */
|
|
27
|
+
const DEFAULT_HOLD_MS = 60 * 1000;
|
|
28
|
+
class UserUpdateQueue {
|
|
29
|
+
/** Values Workstation accepted for the current identity. */
|
|
30
|
+
sent = {};
|
|
31
|
+
/** Values waiting for the next allowed send. */
|
|
32
|
+
pending = null;
|
|
33
|
+
inFlight = false;
|
|
34
|
+
holdUntil = 0;
|
|
35
|
+
timer = null;
|
|
36
|
+
/** Bumped by reset(): a send that settles after it writes nothing back. */
|
|
37
|
+
generation = 0;
|
|
38
|
+
constructor(send, options = {}) {
|
|
39
|
+
this.send = send;
|
|
40
|
+
this.burst = Math.max(1, options.burst ?? USER_UPDATE_BURST);
|
|
41
|
+
this.refillMs = (options.windowMs ?? USER_UPDATE_WINDOW_MS) / this.burst;
|
|
42
|
+
this.now = options.now ?? Date.now;
|
|
43
|
+
this.tokens = this.burst;
|
|
44
|
+
this.refilledAt = this.now();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Resolves once the values are sent, or straight away when nothing changed
|
|
49
|
+
* or they were held for a later send. Rejects only when a send made right
|
|
50
|
+
* now fails with something other than a 429, as `updateUser()` always has.
|
|
51
|
+
*/
|
|
52
|
+
update(attributes) {
|
|
53
|
+
const changes = {};
|
|
54
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
55
|
+
const known = this.pending && key in this.pending ? this.pending[key] : this.sent[key];
|
|
56
|
+
if (known !== value) changes[key] = value;
|
|
57
|
+
}
|
|
58
|
+
if (Object.keys(changes).length === 0) return Promise.resolve();
|
|
59
|
+
this.pending = {
|
|
60
|
+
...this.pending,
|
|
61
|
+
...changes
|
|
62
|
+
};
|
|
63
|
+
if (this.inFlight || this.now() < this.holdUntil || !this.takeToken()) {
|
|
64
|
+
this.schedule();
|
|
65
|
+
return Promise.resolve();
|
|
66
|
+
}
|
|
67
|
+
return this.sendPending();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The visitor's identity changed (anonymous → signed in): Workstation may hold other values now. */
|
|
71
|
+
forgetSent() {
|
|
72
|
+
this.sent = {};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Sign-out or a different user: drop everything waiting so it can't reach the next visitor. */
|
|
76
|
+
reset() {
|
|
77
|
+
this.generation += 1;
|
|
78
|
+
this.clearTimer();
|
|
79
|
+
this.sent = {};
|
|
80
|
+
this.pending = null;
|
|
81
|
+
this.inFlight = false;
|
|
82
|
+
this.holdUntil = 0;
|
|
83
|
+
}
|
|
84
|
+
destroy() {
|
|
85
|
+
this.reset();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The send budget is per device, not per visitor, so reset() leaves it alone. */
|
|
89
|
+
takeToken() {
|
|
90
|
+
this.refill();
|
|
91
|
+
if (this.tokens < 1) return false;
|
|
92
|
+
this.tokens -= 1;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
refill() {
|
|
96
|
+
const now = this.now();
|
|
97
|
+
if (this.tokens >= this.burst) {
|
|
98
|
+
this.refilledAt = now;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const earned = Math.floor((now - this.refilledAt) / this.refillMs);
|
|
102
|
+
if (earned <= 0) return;
|
|
103
|
+
this.tokens = Math.min(this.burst, this.tokens + earned);
|
|
104
|
+
this.refilledAt = this.tokens === this.burst ? now : this.refilledAt + earned * this.refillMs;
|
|
105
|
+
}
|
|
106
|
+
async sendPending() {
|
|
107
|
+
const attributes = this.pending ?? {};
|
|
108
|
+
const generation = this.generation;
|
|
109
|
+
this.pending = null;
|
|
110
|
+
this.inFlight = true;
|
|
111
|
+
try {
|
|
112
|
+
await this.send(attributes);
|
|
113
|
+
if (generation !== this.generation) return;
|
|
114
|
+
this.sent = {
|
|
115
|
+
...this.sent,
|
|
116
|
+
...attributes
|
|
117
|
+
};
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (generation !== this.generation) throw error;
|
|
120
|
+
const status = error instanceof _client.RepzoWidgetError ? error.status : 0;
|
|
121
|
+
const retryable = status === 429 || status === 0 || status >= 500;
|
|
122
|
+
if (retryable) {
|
|
123
|
+
// Newer values that arrived meanwhile win over the ones that failed.
|
|
124
|
+
this.pending = {
|
|
125
|
+
...attributes,
|
|
126
|
+
...(this.pending ?? {})
|
|
127
|
+
};
|
|
128
|
+
const retryAfter = error instanceof _client.RepzoWidgetError ? error.retryAfter : undefined;
|
|
129
|
+
const holdMs = status === 429 && retryAfter && retryAfter > 0 ? retryAfter * 1000 : DEFAULT_HOLD_MS;
|
|
130
|
+
this.holdUntil = Math.max(this.holdUntil, this.now() + holdMs);
|
|
131
|
+
}
|
|
132
|
+
// Rate limited: the values are kept and go out later, so the call succeeded.
|
|
133
|
+
if (status !== 429) throw error;
|
|
134
|
+
} finally {
|
|
135
|
+
if (generation === this.generation) {
|
|
136
|
+
this.inFlight = false;
|
|
137
|
+
if (this.pending) this.schedule();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
schedule() {
|
|
142
|
+
if (this.timer || this.inFlight || !this.pending) return;
|
|
143
|
+
this.refill();
|
|
144
|
+
const now = this.now();
|
|
145
|
+
const tokenAt = this.tokens >= 1 ? now : this.refilledAt + this.refillMs;
|
|
146
|
+
const delay = Math.max(0, this.holdUntil - now, tokenAt - now);
|
|
147
|
+
this.timer = setTimeout(() => {
|
|
148
|
+
this.timer = null;
|
|
149
|
+
this.flush();
|
|
150
|
+
}, delay);
|
|
151
|
+
}
|
|
152
|
+
flush() {
|
|
153
|
+
if (this.inFlight || !this.pending) return;
|
|
154
|
+
if (this.now() < this.holdUntil || !this.takeToken()) {
|
|
155
|
+
this.schedule();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
this.sendPending().catch(error => {
|
|
159
|
+
console.warn('[repzo-widget] updateUser failed', error);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
clearTimer() {
|
|
163
|
+
if (this.timer) clearTimeout(this.timer);
|
|
164
|
+
this.timer = null;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
exports.UserUpdateQueue = UserUpdateQueue;
|
|
168
|
+
//# sourceMappingURL=user-update-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_client","require","USER_UPDATE_BURST","exports","USER_UPDATE_WINDOW_MS","DEFAULT_HOLD_MS","UserUpdateQueue","sent","pending","inFlight","holdUntil","timer","generation","constructor","send","options","burst","Math","max","refillMs","windowMs","now","Date","tokens","refilledAt","update","attributes","changes","key","value","Object","entries","known","keys","length","Promise","resolve","takeToken","schedule","sendPending","forgetSent","reset","clearTimer","destroy","refill","earned","floor","min","error","status","RepzoWidgetError","retryable","retryAfter","undefined","holdMs","tokenAt","delay","setTimeout","flush","catch","console","warn","clearTimeout"],"sourceRoot":"../../../src","sources":["state/user-update-queue.ts"],"mappings":";;;;;;AAgBA,IAAAA,OAAA,GAAAC,OAAA;AAhBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKO,MAAMC,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,EAAE;AAC5B,MAAME,qBAAqB,GAAAD,OAAA,CAAAC,qBAAA,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;AACnD;AACA,MAAMC,eAAe,GAAG,EAAE,GAAG,IAAI;AAU1B,MAAMC,eAAe,CAAC;EAO3B;EACQC,IAAI,GAAe,CAAC,CAAC;EAC7B;EACQC,OAAO,GAAsB,IAAI;EACjCC,QAAQ,GAAG,KAAK;EAChBC,SAAS,GAAG,CAAC;EACbC,KAAK,GAAyC,IAAI;EAC1D;EACQC,UAAU,GAAG,CAAC;EAEtBC,WAAWA,CACQC,IAA+C,EAChEC,OAA+B,GAAG,CAAC,CAAC,EACpC;IAAA,KAFiBD,IAA+C,GAA/CA,IAA+C;IAGhE,IAAI,CAACE,KAAK,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEH,OAAO,CAACC,KAAK,IAAId,iBAAiB,CAA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