Skip to content

Commit e5e0fe0

Browse files
committed
chore: update poll naming
1 parent 07015a2 commit e5e0fe0

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

.changeset/lucky-parts-own.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@
33
'@forgerock/davinci-client': minor
44
---
55

6-
Support both challenge polling and continue polling in DaVinci
6+
Adds `pollStatus()` method and `PollingCollector` to `@forgerock/davinci-client` for polling support in DaVinci flows.
7+
8+
Pass a `PollingCollector` to `davinciClient.pollStatus(collector)` to get a poller function. The polling mode is detected automatically from the collector:
9+
10+
- **Challenge polling**: Periodically calls the `/status` endpoint until the challenge is resolved.
11+
12+
- **Continue polling**: Performs a delay and returns a status based on remaining poll retries. Call the returned poller function repeatedly in a loop until it resolves with the next node in the flow or an error.
13+
14+
Adds ability to intercept the polling request with middleware.

e2e/davinci-app/components/polling.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { PollingCollector, Poller, Updater } from '@forgerock/davinci-clien
99
export default function pollingComponent(
1010
formEl: HTMLFormElement,
1111
collector: PollingCollector,
12-
poll: Poller,
12+
pollStatus: Poller,
1313
updater: Updater<PollingCollector>,
1414
submitForm: () => Promise<void>,
1515
) {
@@ -26,7 +26,7 @@ export default function pollingComponent(
2626
p.innerText = 'Polling...';
2727
formEl?.appendChild(p);
2828

29-
const status = await poll();
29+
const status = await pollStatus();
3030
if (typeof status !== 'string' && 'error' in status) {
3131
console.error(status.error?.message);
3232

e2e/davinci-app/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ const urlParams = new URLSearchParams(window.location.search);
273273
pollingComponent(
274274
formEl, // You can ignore this; it's just for rendering
275275
collector, // This is the plain object of the collector
276-
davinciClient.poll(collector), // Returns a poll function
276+
davinciClient.pollStatus(collector), // Returns a poll function
277277
davinciClient.update(collector), // Returns an update function for this collector
278278
submitForm,
279279
);

packages/davinci-client/src/lib/client.store.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,14 @@ export async function davinci<ActionType extends ActionTypes = ActionTypes>({
415415
},
416416

417417
/**
418-
* @method poll - Perform challenge polling or continue polling
419-
* @param {PollingCollector} collector - the polling collector
418+
* @method pollStatus - A helper for challenge or continue polling
419+
* @description - In challenge polling mode, periodically polls the `/status` endpoint and returns a status.
420+
* In continue polling mode, returns a polling status after a delay based on poll retries remaining.
421+
* The polling mode is automatically detected.
422+
* @param {PollingCollector} collector - The polling collector
420423
* @returns {Promise<PollingStatus | InternalErrorResponse>} - Returns a promise that resolves to a polling status or error
421424
*/
422-
poll: (collector: PollingCollector): Poller => {
425+
pollStatus: (collector: PollingCollector): Poller => {
423426
return async () => {
424427
const result = await getPollingModeµ(collector).pipe(
425428
Micro.flatMap((mode) => pollingµ({ mode, collector, store, log })),

0 commit comments

Comments
 (0)