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
18 changes: 18 additions & 0 deletions .changeset/davinci-metadata-collector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@ping-identity/rn-davinci': minor
---

feat(rn-davinci): add DaVinci METADATA collector pause/resume support (SDKS-5384)

Exposes the SDK Integrator connector pause/resume flow: a `METADATA` field now
surfaces as a typed `MetadataCollector` with the opaque connector payload on
`metadata` and the new `metadata` execution mode/field kind. The flow pauses
until the app sets a result as the collector's form value and resumes via
`next()` — an object is POSTed as the success result (wrap it with the new
`buildMetadataResult` helper, which keeps the form value type from accepting
arbitrary objects for other collectors), and a `{ error: { code, message } }`
envelope (build one with the new `buildMetadataError` helper) routes the
connector's error branch. Submit
planning blocks with `METADATA_RESULT_REQUIRED` while no result is set and
with `METADATA_RESULT_MALFORMED` for non-object, array, or malformed-envelope
values; `computeFormMeta` gains `hasMetadata`.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import DaVinciFidoField from './DaVinciFidoField';
import DaVinciIdpField from './DaVinciIdpField';
import DaVinciImageField from './DaVinciImageField';
import DaVinciLabelField from './DaVinciLabelField';
import DaVinciMetadataField from './DaVinciMetadataField';
import DaVinciMultiSelectField from './DaVinciMultiSelectField';
import DaVinciPasswordField from './DaVinciPasswordField';
import DaVinciPhoneNumberField from './DaVinciPhoneNumberField';
Expand Down Expand Up @@ -86,6 +87,8 @@ function DaVinciFieldRenderer(
return <DaVinciQrCodeField {...props} />;
case 'IMAGE':
return <DaVinciImageField {...props} />;
case 'METADATA':
return <DaVinciMetadataField {...props} />;
default:
return <DaVinciUnsupportedField {...props} />;
}
Expand Down
136 changes: 136 additions & 0 deletions PingSampleApp/ui/davinci/components/molecules/DaVinciMetadataField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright (c) 2026 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

import React from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import {
buildMetadataError,
buildMetadataResult,
type MetadataCollector,
} from '@ping-identity/rn-davinci';
import { colors } from '../../../../src/styles/colors';
import { commonStyles } from '../../../../src/styles/common';
import { davinciFieldStyles } from '../../../../src/styles/davinciStyles';
import type { DaVinciCollectorRendererProps } from './types';

/**
* Demo success result stored by the "Set result" control.
*
* @remarks
* A real integration replaces this with the object the connector expects —
* any non-empty JSON object is a valid success result.
*/
const DEMO_SUCCESS_RESULT = buildMetadataResult({
status: 'success',
source: 'sample-app',
});

/**
* Renders a {@link MetadataCollector} pause field: the connector payload as
* pretty JSON plus demo controls that store a success result, an error
* envelope, or clear the stored result.
*
* @remarks
* SDK Integrator connector pause/resume: the SDK surfaces the opaque
* `metadata` payload; the app performs the on-device work and stores a result
* as the collector's form value before the flow can resume via `next()`.
* This molecule is sample-app demo scaffolding — "Set result" stores
* {@link DEMO_SUCCESS_RESULT} and "Set error" stores a
* {@link buildMetadataError} envelope; a real integration would replace both
* with the actual SDK work. "Clear" stores `null`, which the submit helper
* treats as unset and blocks with `METADATA_RESULT_REQUIRED` until a result
* is present (gating is result-set-based, independent of the server
* `required` flag).
*
* @param props Renderer props.
* @returns Metadata field element.
*/
export default function DaVinciMetadataField(
props: DaVinciCollectorRendererProps,
): React.ReactElement {
const { collector, value, onChange } = props;
const metadataCollector = collector as MetadataCollector;
const isSet = value !== undefined && value !== null;

return (
<View style={davinciFieldStyles.card}>
<Text style={davinciFieldStyles.fieldLabel}>
{metadataCollector.label || 'SDK metadata'}
</Text>
<Text style={davinciFieldStyles.helperText}>Connector payload:</Text>
<Text
testID={`davinci-field-${collector.key}-metadata-payload`}
style={styles.jsonText}
selectable
>
{JSON.stringify(metadataCollector.metadata, null, 2)}
</Text>
<Text style={davinciFieldStyles.helperText}>Result:</Text>
<Text
testID={`davinci-field-${collector.key}-metadata-value`}
style={styles.jsonText}
selectable
>
{isSet ? JSON.stringify(value, null, 2) : 'Not set'}
</Text>
{!isSet ? (
<Text
testID={`davinci-field-${collector.key}-metadata-unset`}
style={davinciFieldStyles.errorText}
>
A result is required before the flow can resume.
</Text>
) : null}
<TouchableOpacity
testID={`davinci-field-${collector.key}-metadata-set-result`}
style={commonStyles.buttonSecondary}
onPress={() => onChange(DEMO_SUCCESS_RESULT)}
>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
<Text style={commonStyles.buttonTextSecondary}>Set result</Text>
</TouchableOpacity>
<TouchableOpacity
testID={`davinci-field-${collector.key}-metadata-set-error`}
style={commonStyles.buttonSecondary}
onPress={() =>
onChange(
buildMetadataError(
'USER_CANCELLED',
'User cancelled the operation',
),
)
}
>
<Text style={commonStyles.buttonTextSecondary}>Set error</Text>
</TouchableOpacity>
<TouchableOpacity
testID={`davinci-field-${collector.key}-metadata-clear`}
style={commonStyles.buttonSecondary}
disabled={!isSet}
// setValue(key, null) keeps the key present with a null value; the
// submit helper treats null the same as unset
// (METADATA_RESULT_REQUIRED), so null is sufficient to "clear" here
// and no clearValue prop needs threading through the renderer.
onPress={() => onChange(null)}
>
<Text style={commonStyles.buttonTextSecondary}>Clear</Text>
</TouchableOpacity>
</View>
);
}

const styles = StyleSheet.create({
jsonText: {
fontFamily: 'Courier',
fontSize: 12,
color: colors.textDark,
backgroundColor: colors.background,
borderRadius: 8,
padding: 8,
marginTop: 4,
marginBottom: 4,
},
});
6 changes: 6 additions & 0 deletions PingSampleApp/ui/davinci/hooks/useDaVinciAutoForwarder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export function useDaVinciAutoForwarder(
if (lastNodeKeyRef.current === continueNodeKey) return;

const { meta, canSubmit, input } = form;
if (meta.hasMetadata) {
// A METADATA node needs an app-supplied result and an explicit Continue.
// Consume the one-shot flag here so a later node is not auto-forwarded.
onForwarded();
return;
}
if (meta.hasManual) return;
if (meta.hasIntegrationRequired) return;
if (meta.hasUnsupported) return;
Expand Down
127 changes: 127 additions & 0 deletions PingTestRunner/__tests__/integration/davinci.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,133 @@ describe('@ping-identity/rn-davinci — integration', () => {
});
});

// ─── METADATA — SDK Integrator pause/resume ───────────────────
//
// The native mapper (packages/davinci native tests) already proves a
// MetadataCollector serialises to { key, type: 'METADATA', label, required,
// metadata: <payload> }. These tests exercise the JS composition layer:
// classification, pause gating (unset/malformed block), and resume
// pass-through (success object / error envelope reach the next() payload
// intact).

describe('METADATA — SDK Integrator pause/resume', () => {
const metadataCollector = {
key: 'sdkMetadata',
type: 'METADATA',
label: '',
required: false,
metadata: { sdk: 'PROTECT', action: 'INITIALIZE' },
};

const metadataNode = {
type: 'ContinueNode',
collectors: [metadataCollector],
};

function loadWithMetadataNode(): Promise<{
mod: typeof import('@ping-identity/rn-davinci');
mock: NativeDaVinciMock;
}> {
const mock = makeMock({
start: jest.fn(async () => metadataNode),
});
return loadDaVinci(mock).then((mod) => ({ mod, mock }));
}

it('classifies METADATA as executionMode metadata + kind metadata (payload intact)', async () => {
const { mod } = await loadWithMetadataNode();
const client = mod.createDaVinciClient(VALID_CONFIG);
const node = asContinueNode(await client.start());
const collectors = mod.normalizeCollectors(node.collectors);
expect(collectors).toHaveLength(1);
expect(collectors[0]).toMatchObject({
key: 'sdkMetadata',
type: 'METADATA',
executionMode: 'metadata',
kind: 'metadata',
requiresUserInput: false,
metadata: { sdk: 'PROTECT', action: 'INITIALIZE' },
});
});

it('computeFormMeta reports hasMetadata for a metadata node', async () => {
const { mod } = await loadWithMetadataNode();
const client = mod.createDaVinciClient(VALID_CONFIG);
const node = asContinueNode(await client.start());
expect(
mod.computeFormMeta(mod.normalizeCollectors(node.collectors)),
).toMatchObject({ hasMetadata: true });
});

it('unset value blocks with METADATA_RESULT_REQUIRED and sends nothing', async () => {
const { mod, mock } = await loadWithMetadataNode();
const client = mod.createDaVinciClient(VALID_CONFIG);
const node = asContinueNode(await client.start());
const plan = mod.buildNextInput(node, {});
expect(plan.canSubmit).toBe(false);
expect(plan.issues).toContainEqual(
expect.objectContaining({
code: 'METADATA_RESULT_REQUIRED',
key: 'sdkMetadata',
}),
);
await client.next(plan.input);
expect(mock.next).toHaveBeenCalledWith('davinci-id-mock', {
collectors: [],
});
});

it('success result passes through to the next() payload intact', async () => {
const { mod, mock } = await loadWithMetadataNode();
const client = mod.createDaVinciClient(VALID_CONFIG);
const node = asContinueNode(await client.start());
const plan = mod.buildNextInput(node, {
sdkMetadata: mod.buildMetadataResult({ status: 'success' }),
});
expect(plan.canSubmit).toBe(true);
expect(plan.issues).toEqual([]);
await client.next(plan.input);
expect(mock.next).toHaveBeenCalledTimes(1);
expect(mock.next).toHaveBeenCalledWith('davinci-id-mock', {
collectors: [{ key: 'sdkMetadata', value: { status: 'success' } }],
});
});

it('error envelope passes through to the next() payload intact', async () => {
const errorEnvelope = {
error: { code: 'USER_CANCELLED', message: 'User cancelled' },
};
const { mod, mock } = await loadWithMetadataNode();
const client = mod.createDaVinciClient(VALID_CONFIG);
const node = asContinueNode(await client.start());
const plan = mod.buildNextInput(node, { sdkMetadata: errorEnvelope });
expect(plan.canSubmit).toBe(true);
expect(plan.issues).toEqual([]);
await client.next(plan.input);
expect(mock.next).toHaveBeenCalledWith('davinci-id-mock', {
collectors: [{ key: 'sdkMetadata', value: errorEnvelope }],
});
});

it('malformed value (string) blocks with METADATA_RESULT_MALFORMED', async () => {
const { mod, mock } = await loadWithMetadataNode();
const client = mod.createDaVinciClient(VALID_CONFIG);
const node = asContinueNode(await client.start());
const plan = mod.buildNextInput(node, { sdkMetadata: 'not-an-object' });
expect(plan.canSubmit).toBe(false);
expect(plan.issues).toContainEqual(
expect.objectContaining({
code: 'METADATA_RESULT_MALFORMED',
key: 'sdkMetadata',
}),
);
await client.next(plan.input);
expect(mock.next).toHaveBeenCalledWith('davinci-id-mock', {
collectors: [],
});
});
});

// ─── terminal node shapes ──────────────────────────────────────────────────
//
// SuccessNode/ErrorNode/FailureNode pass through the bridge as-is. These
Expand Down
Loading
Loading