Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-monkeys-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@forgerock/davinci-client': minor
---

Add support for MFA OTP field support with added collectors
8 changes: 6 additions & 2 deletions packages/davinci-client/src/lib/client.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import type {
SingleValueCollectors,
IdpCollector,
MultiSelectCollector,
ObjectValueCollectors,
} from './collector.types.js';
import type { InitFlow, Updater, Validator } from './client.types.js';
import { returnValidator } from './collector.utils.js';
Expand Down Expand Up @@ -167,7 +168,9 @@ export async function davinci<ActionType extends ActionTypes = ActionTypes>({
* @param {SingleValueCollector} collector - the collector to update
* @returns {function} - a function to call for updating collector value
*/
update: (collector: SingleValueCollectors | MultiSelectCollector): Updater => {
update: (
collector: SingleValueCollectors | MultiSelectCollector | ObjectValueCollectors,
): Updater => {
if (!collector.id) {
console.error('Argument for `collector` has no ID');
return function () {
Expand Down Expand Up @@ -197,7 +200,8 @@ export async function davinci<ActionType extends ActionTypes = ActionTypes>({
if (
collectorToUpdate.category !== 'MultiValueCollector' &&
collectorToUpdate.category !== 'SingleValueCollector' &&
collectorToUpdate.category !== 'ValidatedSingleValueCollector'
collectorToUpdate.category !== 'ValidatedSingleValueCollector' &&
collectorToUpdate.category !== 'ObjectValueCollector'
) {
console.error(
'Collector is not a MultiValueCollector, SingleValueCollector or ValidatedSingleValueCollector and cannot be updated',
Expand Down
129 changes: 114 additions & 15 deletions packages/davinci-client/src/lib/collector.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

/** *********************************************************************
* SINGLE-VALUE COLLECTORS
*/
Expand All @@ -15,10 +16,11 @@ export type SingleValueCollectorTypes =
| 'PasswordCollector'
| 'SingleValueCollector'
| 'SingleSelectCollector'
| 'SingleSelectObjectCollector'
| 'TextCollector'
| 'ValidatedTextCollector';

interface SelectorOptions {
interface SelectorOption {
label: string;
value: string;
}
Expand Down Expand Up @@ -90,7 +92,7 @@ export interface SingleSelectCollectorWithValue<T extends SingleValueCollectorTy
label: string;
type: string;
value: string | number | boolean;
options: SelectorOptions[];
options: SelectorOption[];
};
}

Expand Down Expand Up @@ -127,7 +129,7 @@ export interface SingleSelectCollectorNoValue<T extends SingleValueCollectorType
key: string;
label: string;
type: string;
options: SelectorOptions[];
options: SelectorOption[];
};
}

Expand All @@ -143,16 +145,18 @@ export type InferSingleValueCollectorType<T extends SingleValueCollectorTypes> =
? TextCollector
: T extends 'SingleSelectCollector'
? SingleSelectCollector
: T extends 'PasswordCollector'
? PasswordCollector
: /**
* At this point, we have not passed in a collector type
* or we have explicitly passed in 'SingleValueCollector'
* So we can return either a SingleValueCollector with value
* or without a value.
**/
| SingleValueCollectorWithValue<'SingleValueCollector'>
| SingleValueCollectorNoValue<'SingleValueCollector'>;
: T extends 'ValidatedTextCollector'
? ValidatedTextCollector
: T extends 'PasswordCollector'
? PasswordCollector
: /**
* At this point, we have not passed in a collector type
* or we have explicitly passed in 'SingleValueCollector'
* So we can return either a SingleValueCollector with value
* or without a value.
**/
| SingleValueCollectorWithValue<'SingleValueCollector'>
| SingleValueCollectorNoValue<'SingleValueCollector'>;

/**
* SINGLE-VALUE COLLECTOR TYPES
Expand Down Expand Up @@ -198,7 +202,7 @@ export interface MultiValueCollectorWithValue<T extends MultiValueCollectorTypes
label: string;
type: string;
value: string[];
options: SelectorOptions[];
options: SelectorOption[];
};
}

Expand All @@ -218,7 +222,7 @@ export interface MultiValueCollectorNoValue<T extends MultiValueCollectorTypes>
label: string;
type: string;
value: string[];
options: SelectorOptions[];
options: SelectorOption[];
};
}

Expand Down Expand Up @@ -246,6 +250,101 @@ export type MultiValueCollector<T extends MultiValueCollectorTypes> =

export type MultiSelectCollector = MultiValueCollectorWithValue<'MultiSelectCollector'>;

/** *********************************************************************
* OBJECT COLLECTORS
*/

export type ObjectValueCollectorTypes =
| 'DeviceAuthenticationCollector'
| 'DeviceRegistrationCollector'
| 'ObjectValueCollector'
| 'ObjectSelectCollector';

interface ObjectOptionWithValue {
type: string;
label: string;
content: string;
default: boolean;
value: string;
key: string;
}

interface ObjectOptionNoValue {
type: string;
label: string;
content: string;
value: string;
key: string;
}

interface ObjectValue {
type: string;
id: string;
value: string;
}

export interface ObjectValueCollectorNoValue<T extends ObjectValueCollectorTypes> {
Comment thread
ryanbas21 marked this conversation as resolved.
category: 'ObjectValueCollector';
error: string | null;
type: T;
id: string;
name: string;
input: {
key: string;
value: string | null;
type: string;
};
output: {
key: string;
label: string;
type: string;
options: ObjectOptionNoValue[];
};
}

export interface ObjectValueCollectorWithValue<T extends ObjectValueCollectorTypes> {
Comment thread
ryanbas21 marked this conversation as resolved.
category: 'ObjectValueCollector';
error: string | null;
type: T;
id: string;
name: string;
input: {
key: string;
value: ObjectValue | null;
type: string;
};
output: {
key: string;
label: string;
type: string;
options: ObjectOptionWithValue[];
};
}

export type InferValueObjectCollectorType<T extends ObjectValueCollectorTypes> =
T extends 'DeviceAuthenticationCollector'
? DeviceAuthenticationCollector
: T extends 'DeviceRegistrationCollector'
? DeviceRegistrationCollector
:
| ObjectValueCollectorWithValue<'ObjectValueCollector'>
| ObjectValueCollectorNoValue<'ObjectValueCollector'>;

export type ObjectValueCollectors =
| ObjectValueCollectorWithValue<'DeviceAuthenticationCollector'>
| ObjectValueCollectorNoValue<'DeviceRegistrationCollector'>
| ObjectValueCollectorWithValue<'ObjectSelectCollector'>
| ObjectValueCollectorNoValue<'ObjectSelectCollector'>;

export type ObjectValueCollector<T extends ObjectValueCollectorTypes> =
| ObjectValueCollectorWithValue<T>
| ObjectValueCollectorNoValue<T>;

export type DeviceRegistrationCollector =
ObjectValueCollectorNoValue<'DeviceRegistrationCollector'>;
export type DeviceAuthenticationCollector =
ObjectValueCollectorWithValue<'DeviceAuthenticationCollector'>;

/** *********************************************************************
* ACTION COLLECTORS
*/
Expand Down
Loading
Loading