@getuserfeedback/react-native 1.3.7 → 1.3.8
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 +35 -42
- package/dist/provider-pending-commands.d.ts +37 -0
- package/dist/provider-pending-commands.js +59 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import { toCommandFlowId, toCommandSettlementError, toRetryWithoutFlowHandle, }
|
|
|
17
17
|
import { clearProviderFlowHandleCache, createProviderFlowHandleCache, deleteCachedProviderFlowHandleId, deleteCachedProviderFlowId, getCachedProviderFlowHandleId, snapshotProviderFlowCommand, writeSettledProviderFlowHandleId, } from "./provider-flow-handle-cache.js";
|
|
18
18
|
import { enqueueProviderNativeMessage, removeProviderNativeMessageId, removeProviderNativeMessageIds, replaceProviderNativeMessages, } from "./provider-message-queue.js";
|
|
19
19
|
import { applyProviderOverlayFlowState, applyProviderOverlayHandleInvalidated, createDefaultProviderOverlayState, DEFAULT_PROVIDER_OVERLAY_VISIBILITY, updateProviderOverlayReadySequence, } from "./provider-overlay-state.js";
|
|
20
|
+
import { cancelProviderStartupCommands, clearProviderPendingCommands, createProviderPendingCommandRegistry, getProviderPendingCommand, getProviderPendingCommandEntries, getProviderPendingCommands, hasDeliveredProviderPendingCommands, isProviderPendingMessageStartup, registerProviderPendingCommand, reissueProviderPendingCommand, takeProviderPendingCommand, } from "./provider-pending-commands.js";
|
|
20
21
|
import { ProviderWidgetHostOverlay, toProviderWidgetHostStyle, toProviderWidgetSheetHostViewport, } from "./provider-widget-host-overlay.js";
|
|
21
22
|
import { REACT_NATIVE_SDK_VERSION } from "./version.js";
|
|
22
23
|
import { WidgetHost, } from "./widget-host.js";
|
|
@@ -115,7 +116,7 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
115
116
|
const [widgetHostVisibility, setWidgetHostVisibility] = useState(DEFAULT_PROVIDER_OVERLAY_VISIBILITY);
|
|
116
117
|
const resolvedHostViewport = useResolvedHostViewport(hostViewport);
|
|
117
118
|
const nativeMessagesRef = useRef([]);
|
|
118
|
-
const pendingCommandsRef = useRef(
|
|
119
|
+
const pendingCommandsRef = useRef(createProviderPendingCommandRegistry());
|
|
119
120
|
const hostEpochRef = useRef(0);
|
|
120
121
|
const flowHandleCacheRef = useRef(createProviderFlowHandleCache());
|
|
121
122
|
const providerOverlayStateRef = useRef(createDefaultProviderOverlayState());
|
|
@@ -134,7 +135,7 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
134
135
|
if (hostSourceKeyRef.current !== hostSourceKey) {
|
|
135
136
|
hostSourceKeyRef.current = hostSourceKey;
|
|
136
137
|
hostSourceVersionRef.current += 1;
|
|
137
|
-
for (const pendingCommand of pendingCommandsRef.current
|
|
138
|
+
for (const pendingCommand of getProviderPendingCommands(pendingCommandsRef.current)) {
|
|
138
139
|
if (!pendingCommand.timeout) {
|
|
139
140
|
continue;
|
|
140
141
|
}
|
|
@@ -163,7 +164,7 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
163
164
|
}, 0);
|
|
164
165
|
}, [onCommandError]);
|
|
165
166
|
const rejectPendingCommand = useCallback((requestId, pendingCommand, error) => {
|
|
166
|
-
pendingCommandsRef.current
|
|
167
|
+
takeProviderPendingCommand(pendingCommandsRef.current, requestId);
|
|
167
168
|
if (pendingCommand.timeout) {
|
|
168
169
|
clearTimeout(pendingCommand.timeout);
|
|
169
170
|
pendingCommand.timeout = null;
|
|
@@ -188,12 +189,12 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
188
189
|
}, commandTimeoutMs);
|
|
189
190
|
}, [commandTimeoutMs, rejectPendingCommand]);
|
|
190
191
|
const startPendingCommandTimeouts = useCallback(() => {
|
|
191
|
-
for (const [requestId, pendingCommand] of pendingCommandsRef.current) {
|
|
192
|
+
for (const [requestId, pendingCommand] of getProviderPendingCommandEntries(pendingCommandsRef.current)) {
|
|
192
193
|
startPendingCommandTimeout(requestId, pendingCommand);
|
|
193
194
|
}
|
|
194
195
|
}, [startPendingCommandTimeout]);
|
|
195
196
|
const pausePendingCommandTimeouts = useCallback(() => {
|
|
196
|
-
for (const pendingCommand of pendingCommandsRef.current
|
|
197
|
+
for (const pendingCommand of getProviderPendingCommands(pendingCommandsRef.current)) {
|
|
197
198
|
if (!pendingCommand.timeout) {
|
|
198
199
|
continue;
|
|
199
200
|
}
|
|
@@ -234,7 +235,7 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
234
235
|
};
|
|
235
236
|
const flowCommandSnapshot = snapshotProviderFlowCommand(flowHandleCacheRef.current, validatedMessage.envelope.command);
|
|
236
237
|
const promise = new Promise((resolve, reject) => {
|
|
237
|
-
|
|
238
|
+
const pendingCommand = {
|
|
238
239
|
flowCommandSequence: flowCommandSnapshot.flowCommandSequence,
|
|
239
240
|
flowHandleCacheEpoch: flowCommandSnapshot.flowHandleCacheEpoch,
|
|
240
241
|
hostEpoch: null,
|
|
@@ -244,17 +245,15 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
244
245
|
resolve,
|
|
245
246
|
result,
|
|
246
247
|
timeout: null,
|
|
247
|
-
}
|
|
248
|
+
};
|
|
249
|
+
registerProviderPendingCommand(pendingCommandsRef.current, requestId, pendingCommand);
|
|
248
250
|
if (lastReadyRef.current !== null) {
|
|
249
|
-
startPendingCommandTimeout(requestId,
|
|
251
|
+
startPendingCommandTimeout(requestId, pendingCommand);
|
|
250
252
|
}
|
|
251
253
|
});
|
|
252
254
|
setNativeMessages((messages) => enqueueProviderNativeMessage(messages, {
|
|
253
255
|
isStartup,
|
|
254
|
-
isStartupMessage: (entry) =>
|
|
255
|
-
var _a;
|
|
256
|
-
return ((_a = pendingCommandsRef.current.get(entry.envelope.requestId)) === null || _a === void 0 ? void 0 : _a.isStartup) === true;
|
|
257
|
-
},
|
|
256
|
+
isStartupMessage: (entry) => isProviderPendingMessageStartup(pendingCommandsRef.current, entry.envelope.requestId),
|
|
258
257
|
message: validatedMessage,
|
|
259
258
|
prioritizeStartup,
|
|
260
259
|
}));
|
|
@@ -263,13 +262,10 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
263
262
|
const reissueDeliveredPendingActionCommands = useCallback(() => {
|
|
264
263
|
var _a;
|
|
265
264
|
const replacements = new Map();
|
|
266
|
-
for (const [requestId, pendingCommand] of
|
|
267
|
-
...pendingCommandsRef.current.entries(),
|
|
268
|
-
]) {
|
|
265
|
+
for (const [requestId, pendingCommand] of getProviderPendingCommandEntries(pendingCommandsRef.current)) {
|
|
269
266
|
if (pendingCommand.isStartup || pendingCommand.hostEpoch === null) {
|
|
270
267
|
continue;
|
|
271
268
|
}
|
|
272
|
-
pendingCommandsRef.current.delete(requestId);
|
|
273
269
|
if (pendingCommand.timeout) {
|
|
274
270
|
clearTimeout(pendingCommand.timeout);
|
|
275
271
|
pendingCommand.timeout = null;
|
|
@@ -281,16 +277,20 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
281
277
|
id: createTransportMessageId(),
|
|
282
278
|
envelope: nextEnvelope,
|
|
283
279
|
});
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
280
|
+
const reissuedCommand = reissueProviderPendingCommand(pendingCommandsRef.current, {
|
|
281
|
+
flowHandleCacheEpoch: flowHandleCacheRef.current.epoch,
|
|
282
|
+
nextMessageId: nextMessage.id,
|
|
283
|
+
nextRequestId: nextEnvelope.requestId,
|
|
284
|
+
nextResult: {
|
|
285
|
+
envelope: nextMessage.envelope,
|
|
286
|
+
message: nextMessage,
|
|
287
|
+
},
|
|
288
|
+
requestId,
|
|
289
|
+
});
|
|
290
|
+
if (!reissuedCommand) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
replacements.set(reissuedCommand.previousMessageId, nextMessage);
|
|
294
294
|
}
|
|
295
295
|
if (replacements.size === 0) {
|
|
296
296
|
return false;
|
|
@@ -299,22 +299,17 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
299
299
|
return true;
|
|
300
300
|
}, []);
|
|
301
301
|
const cancelPendingStartupCommands = useCallback(() => {
|
|
302
|
-
const
|
|
303
|
-
for (const
|
|
304
|
-
if (!pendingCommand.isStartup) {
|
|
305
|
-
continue;
|
|
306
|
-
}
|
|
307
|
-
pendingCommandsRef.current.delete(requestId);
|
|
308
|
-
canceledMessageIds.add(pendingCommand.messageId);
|
|
302
|
+
const canceled = cancelProviderStartupCommands(pendingCommandsRef.current);
|
|
303
|
+
for (const pendingCommand of canceled.commands) {
|
|
309
304
|
if (pendingCommand.timeout) {
|
|
310
305
|
clearTimeout(pendingCommand.timeout);
|
|
311
306
|
}
|
|
312
307
|
pendingCommand.reject(new Error(STARTUP_COMMAND_REPLACED_ERROR_MESSAGE));
|
|
313
308
|
}
|
|
314
|
-
if (
|
|
309
|
+
if (canceled.messageIds.size === 0) {
|
|
315
310
|
return;
|
|
316
311
|
}
|
|
317
|
-
setNativeMessages((messages) => removeProviderNativeMessageIds(messages,
|
|
312
|
+
setNativeMessages((messages) => removeProviderNativeMessageIds(messages, canceled.messageIds));
|
|
318
313
|
}, []);
|
|
319
314
|
const enqueueStartupCommands = useCallback(({ force = false } = {}) => {
|
|
320
315
|
if (!autoInit) {
|
|
@@ -353,9 +348,7 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
353
348
|
if (alreadySeen) {
|
|
354
349
|
return false;
|
|
355
350
|
}
|
|
356
|
-
const hasDeliveredPendingCommands =
|
|
357
|
-
...pendingCommandsRef.current.values(),
|
|
358
|
-
].some((pendingCommand) => pendingCommand.hostEpoch !== null);
|
|
351
|
+
const hasDeliveredPendingCommands = hasDeliveredProviderPendingCommands(pendingCommandsRef.current);
|
|
359
352
|
let didReissueDeliveredCommands = false;
|
|
360
353
|
if (previous !== null || hasDeliveredPendingCommands) {
|
|
361
354
|
hostEpochRef.current += 1;
|
|
@@ -457,14 +450,14 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
457
450
|
if (message.kind === "hostEvent" &&
|
|
458
451
|
message.event.name === "instance:command:settled") {
|
|
459
452
|
const requestId = message.event.detail.requestId;
|
|
460
|
-
const pendingCommand = pendingCommandsRef.current
|
|
453
|
+
const pendingCommand = getProviderPendingCommand(pendingCommandsRef.current, requestId);
|
|
461
454
|
if (pendingCommand) {
|
|
462
455
|
if (pendingCommand.hostEpoch !== null &&
|
|
463
456
|
pendingCommand.hostEpoch !== ((_a = lastReadyRef.current) === null || _a === void 0 ? void 0 : _a.hostEpoch)) {
|
|
464
457
|
onWebMessage === null || onWebMessage === void 0 ? void 0 : onWebMessage(message);
|
|
465
458
|
return;
|
|
466
459
|
}
|
|
467
|
-
pendingCommandsRef.current
|
|
460
|
+
takeProviderPendingCommand(pendingCommandsRef.current, requestId);
|
|
468
461
|
setNativeMessages((messages) => removeProviderNativeMessageId(messages, pendingCommand.messageId));
|
|
469
462
|
if (pendingCommand.timeout) {
|
|
470
463
|
clearTimeout(pendingCommand.timeout);
|
|
@@ -514,13 +507,13 @@ export function GetUserFeedbackProvider({ autoInit = true, children, commandTime
|
|
|
514
507
|
onWebMessage,
|
|
515
508
|
]);
|
|
516
509
|
useEffect(() => () => {
|
|
517
|
-
for (const pendingCommand of pendingCommandsRef.current
|
|
510
|
+
for (const pendingCommand of getProviderPendingCommands(pendingCommandsRef.current)) {
|
|
518
511
|
if (pendingCommand.timeout) {
|
|
519
512
|
clearTimeout(pendingCommand.timeout);
|
|
520
513
|
}
|
|
521
514
|
pendingCommand.reject(new Error(PROVIDER_UNMOUNTED_ERROR_MESSAGE));
|
|
522
515
|
}
|
|
523
|
-
pendingCommandsRef.current
|
|
516
|
+
clearProviderPendingCommands(pendingCommandsRef.current);
|
|
524
517
|
}, []);
|
|
525
518
|
useEffect(() => {
|
|
526
519
|
if (visibilitySourceKeyRef.current === hostSourceKey) {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type ProviderPendingCommand<Result> = {
|
|
2
|
+
flowCommandSequence: number | null;
|
|
3
|
+
flowHandleCacheEpoch: number;
|
|
4
|
+
hostEpoch: number | null;
|
|
5
|
+
isStartup: boolean;
|
|
6
|
+
messageId: string;
|
|
7
|
+
reject: (error: Error) => void;
|
|
8
|
+
resolve: (result: Result) => void;
|
|
9
|
+
result: Result;
|
|
10
|
+
timeout: ReturnType<typeof setTimeout> | null;
|
|
11
|
+
};
|
|
12
|
+
export type ProviderPendingCommandRegistry<Result> = Map<string, ProviderPendingCommand<Result>>;
|
|
13
|
+
export type ProviderCanceledStartupCommands<Result> = {
|
|
14
|
+
commands: ProviderPendingCommand<Result>[];
|
|
15
|
+
messageIds: Set<string>;
|
|
16
|
+
};
|
|
17
|
+
export type ProviderReissuedPendingCommand<Result> = {
|
|
18
|
+
command: ProviderPendingCommand<Result>;
|
|
19
|
+
previousMessageId: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function createProviderPendingCommandRegistry<Result>(): ProviderPendingCommandRegistry<Result>;
|
|
22
|
+
export declare function registerProviderPendingCommand<Result>(registry: ProviderPendingCommandRegistry<Result>, requestId: string, command: ProviderPendingCommand<Result>): void;
|
|
23
|
+
export declare function getProviderPendingCommand<Result>(registry: ProviderPendingCommandRegistry<Result>, requestId: string): ProviderPendingCommand<Result> | undefined;
|
|
24
|
+
export declare function takeProviderPendingCommand<Result>(registry: ProviderPendingCommandRegistry<Result>, requestId: string): ProviderPendingCommand<Result> | undefined;
|
|
25
|
+
export declare function hasDeliveredProviderPendingCommands<Result>(registry: ProviderPendingCommandRegistry<Result>): boolean;
|
|
26
|
+
export declare function isProviderPendingMessageStartup<Result>(registry: ProviderPendingCommandRegistry<Result>, requestId: string): boolean;
|
|
27
|
+
export declare function getProviderPendingCommandEntries<Result>(registry: ProviderPendingCommandRegistry<Result>): Array<[string, ProviderPendingCommand<Result>]>;
|
|
28
|
+
export declare function getProviderPendingCommands<Result>(registry: ProviderPendingCommandRegistry<Result>): ProviderPendingCommand<Result>[];
|
|
29
|
+
export declare function cancelProviderStartupCommands<Result>(registry: ProviderPendingCommandRegistry<Result>): ProviderCanceledStartupCommands<Result>;
|
|
30
|
+
export declare function reissueProviderPendingCommand<Result>(registry: ProviderPendingCommandRegistry<Result>, { flowHandleCacheEpoch, nextMessageId, nextRequestId, nextResult, requestId, }: {
|
|
31
|
+
flowHandleCacheEpoch: number;
|
|
32
|
+
nextMessageId: string;
|
|
33
|
+
nextRequestId: string;
|
|
34
|
+
nextResult: Result;
|
|
35
|
+
requestId: string;
|
|
36
|
+
}): ProviderReissuedPendingCommand<Result> | null;
|
|
37
|
+
export declare function clearProviderPendingCommands<Result>(registry: ProviderPendingCommandRegistry<Result>): void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export function createProviderPendingCommandRegistry() {
|
|
2
|
+
return new Map();
|
|
3
|
+
}
|
|
4
|
+
export function registerProviderPendingCommand(registry, requestId, command) {
|
|
5
|
+
registry.set(requestId, command);
|
|
6
|
+
}
|
|
7
|
+
export function getProviderPendingCommand(registry, requestId) {
|
|
8
|
+
return registry.get(requestId);
|
|
9
|
+
}
|
|
10
|
+
export function takeProviderPendingCommand(registry, requestId) {
|
|
11
|
+
const command = registry.get(requestId);
|
|
12
|
+
if (command) {
|
|
13
|
+
registry.delete(requestId);
|
|
14
|
+
}
|
|
15
|
+
return command;
|
|
16
|
+
}
|
|
17
|
+
export function hasDeliveredProviderPendingCommands(registry) {
|
|
18
|
+
return [...registry.values()].some((command) => command.hostEpoch !== null);
|
|
19
|
+
}
|
|
20
|
+
export function isProviderPendingMessageStartup(registry, requestId) {
|
|
21
|
+
var _a;
|
|
22
|
+
return ((_a = registry.get(requestId)) === null || _a === void 0 ? void 0 : _a.isStartup) === true;
|
|
23
|
+
}
|
|
24
|
+
export function getProviderPendingCommandEntries(registry) {
|
|
25
|
+
return [...registry.entries()];
|
|
26
|
+
}
|
|
27
|
+
export function getProviderPendingCommands(registry) {
|
|
28
|
+
return [...registry.values()];
|
|
29
|
+
}
|
|
30
|
+
export function cancelProviderStartupCommands(registry) {
|
|
31
|
+
const commands = [];
|
|
32
|
+
const messageIds = new Set();
|
|
33
|
+
for (const [requestId, command] of registry) {
|
|
34
|
+
if (!command.isStartup) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
registry.delete(requestId);
|
|
38
|
+
commands.push(command);
|
|
39
|
+
messageIds.add(command.messageId);
|
|
40
|
+
}
|
|
41
|
+
return { commands, messageIds };
|
|
42
|
+
}
|
|
43
|
+
export function reissueProviderPendingCommand(registry, { flowHandleCacheEpoch, nextMessageId, nextRequestId, nextResult, requestId, }) {
|
|
44
|
+
const command = registry.get(requestId);
|
|
45
|
+
if (!command || command.isStartup || command.hostEpoch === null) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
registry.delete(requestId);
|
|
49
|
+
const previousMessageId = command.messageId;
|
|
50
|
+
command.flowHandleCacheEpoch = flowHandleCacheEpoch;
|
|
51
|
+
command.hostEpoch = null;
|
|
52
|
+
command.messageId = nextMessageId;
|
|
53
|
+
command.result = nextResult;
|
|
54
|
+
registry.set(nextRequestId, command);
|
|
55
|
+
return { command, previousMessageId };
|
|
56
|
+
}
|
|
57
|
+
export function clearProviderPendingCommands(registry) {
|
|
58
|
+
registry.clear();
|
|
59
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -3,4 +3,4 @@ const reactNativeSdkVersion = typeof __GX_REACT_NATIVE_SDK_VERSION__ === "string
|
|
|
3
3
|
: "";
|
|
4
4
|
// Build scripts patch this fallback to the package version for published artifacts.
|
|
5
5
|
// Source-linked workspace usage keeps the local fallback.
|
|
6
|
-
export const REACT_NATIVE_SDK_VERSION = reactNativeSdkVersion.length > 0 ? reactNativeSdkVersion : "1.3.
|
|
6
|
+
export const REACT_NATIVE_SDK_VERSION = reactNativeSdkVersion.length > 0 ? reactNativeSdkVersion : "1.3.8";
|