Skip to content

Commit eedcca7

Browse files
authored
Merge pull request #622 from ForgeRock/update-poll-naming
chore: update poll naming
2 parents 07015a2 + e75ee94 commit eedcca7

5 files changed

Lines changed: 20 additions & 9 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
2+
* Copyright (c) 2026 Ping Identity Corporation. All rights reserved.
33
*
44
* This software may be modified and distributed under the terms
55
* of the MIT license. See the LICENSE file for details.
@@ -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
);

e2e/davinci-suites/src/phone-number-field.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ test.describe('Device registration tests', () => {
103103
await page.getByRole('button', { name: 'DEVICE_REGISTRATION' }).click();
104104
await expect(page.getByText('SDK Automation - Device Registration')).toBeVisible();
105105
await page.getByRole('button', { name: 'Text Message' }).click();
106-
await expect(page.getByText('SDK Automation - Enter Phone Number')).toBeVisible();
106+
await expect(page.getByText('SDK Automation [JS] - Enter Phone Number')).toBeVisible();
107107
await page.getByRole('textbox', { name: 'Enter Phone Number' }).fill('3035550100');
108108
await page.getByRole('button', { name: 'Submit' }).click();
109109

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)