Skip to content
Open
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
6 changes: 6 additions & 0 deletions .changeset/update-protect-callback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@forgerock/javascript-sdk': minor
'@forgerock/ping-protect': minor
---

fix(protect): update Protect callback with new Signals SDK config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* ping-protect-intitialize-callback.test.ts
*
* Copyright (c) 2024 - 2025 Ping Identity Corporation. All rights reserved.
* Copyright (c) 2024 - 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.
*/
Expand Down Expand Up @@ -186,6 +186,80 @@ describe('PingOneProtectInitializeCallback', () => {
});
});

it('should return signalsInitializationOptions directly when valid', () => {
const signalsInitializationOptions = {
agentIdentification: 'false',
htmlGeoLocation: 'true',
behavioralDataCollection: 'true',
universalDeviceIdentification: 'false',
option1: 'value1',
disableTags: 'false',
};

const callback = new PingOneProtectInitializeCallback({
type: 'PingOneProtectInitializeCallback' as CallbackType,
input: [],
output: [
{
name: 'signalsInitializationOptions',
value: signalsInitializationOptions,
},
{
name: 'envId',
value: 'legacy-env-id-that-should-be-ignored',
},
],
});

const config = callback.getConfig();
expect(config).toEqual(signalsInitializationOptions);
expect(config).not.toHaveProperty('envId');
});

it('should fallback to legacy config when signalsInitializationOptions is invalid', () => {
const callback = new PingOneProtectInitializeCallback({
type: 'PingOneProtectInitializeCallback' as CallbackType,
input: [],
output: [
{
name: 'signalsInitializationOptions',
value: [],
},
{
name: 'envId',
value: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
},
],
});

const config = callback.getConfig();
expect(config).toMatchObject({
envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
behavioralDataCollection: true,
disableTags: false,
});
});

it('should fallback to legacy config when signalsInitializationOptions is missing', () => {
const callback = new PingOneProtectInitializeCallback({
type: 'PingOneProtectInitializeCallback' as CallbackType,
input: [],
output: [
{
name: 'envId',
value: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
},
],
});

const config = callback.getConfig();
expect(config).toMatchObject({
envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
behavioralDataCollection: true,
disableTags: false,
});
});

it('should test the setClientError method', () => {
const callback = new PingOneProtectInitializeCallback({
type: 'PingOneProtectInitializeCallback' as CallbackType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* ping-protect-initialize-callback.ts
*
* Copyright (c) 2024 - 2025 Ping Identity Corporation. All rights reserved.
* Copyright (c) 2024 - 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.
*/
Expand All @@ -26,6 +26,18 @@ class PingOneProtectInitializeCallback extends FRCallback {
* Get callback's initialization config settings
*/
public getConfig() {
const signalsInitializationOptions = this.getOutputByName<Record<string, unknown> | undefined>(
'signalsInitializationOptions',
undefined,
);
if (
signalsInitializationOptions !== null &&
typeof signalsInitializationOptions === 'object' &&
!Array.isArray(signalsInitializationOptions)
) {
return signalsInitializationOptions;
}

const agentIdentification = this.getOutputByName<boolean | undefined>(
'agentIdentification',
undefined,
Expand Down
18 changes: 17 additions & 1 deletion packages/ping-protect/src/lib/ping-protect.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2024 - 2025 Ping Identity Corporation. All right reserved.
* Copyright (c) 2024 - 2026 Ping Identity Corporation. All right reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down Expand Up @@ -41,6 +41,22 @@ describe('PIProtect', () => {
await PIProtect.start(config);
expect(protectMock).toHaveBeenCalledWith(config);
});
it('should resume behavioralData when behavioralDataCollection is string true', async () => {
await PIProtect.start({ envId: '12345', behavioralDataCollection: false });
const resumeSpy = vi.spyOn(window._pingOneSignals, 'resumeBehavioralData');

await PIProtect.start({ envId: '12345', behavioralDataCollection: 'true' });

expect(resumeSpy).toHaveBeenCalledTimes(1);
});
it('should not resume behavioralData when behavioralDataCollection is string false', async () => {
await PIProtect.start({ envId: '12345', behavioralDataCollection: false });
const resumeSpy = vi.spyOn(window._pingOneSignals, 'resumeBehavioralData');

await PIProtect.start({ envId: '12345', behavioralDataCollection: 'false' });

expect(resumeSpy).not.toHaveBeenCalled();
});
it('should call pause behavioralData', () => {
const protectMock = vi.spyOn(PIProtect, 'pauseBehavioralData');
PIProtect.pauseBehavioralData();
Expand Down
19 changes: 13 additions & 6 deletions packages/ping-protect/src/lib/ping-protect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2024 - 2025 Ping Identity Corporation. All right reserved.
* Copyright (c) 2024 - 2026 Ping Identity Corporation. All right reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -15,13 +15,20 @@ import {
PingOneProtectEvaluationCallback,
PingOneProtectInitializeCallback,
} from '@forgerock/javascript-sdk';
import { ProtectEvaluationConfig, ProtectInitializeConfig } from './ping-protect.types';
import {
ProtectEvaluationConfig,
ProtectInitializeConfig,
ProtectNodeInitializeConfig,
SignalsInitializationOptions,
} from './ping-protect.types';

export interface Identifiers {
[key: string]: string;
}

export type InitParams = Omit<ProtectInitializeConfig, '_type' | '_action'>;
export type InitParams =
| Omit<ProtectInitializeConfig, '_type' | '_action'>
| SignalsInitializationOptions;

// Add Signals SDK namespace to the window object
declare global {
Expand Down Expand Up @@ -69,7 +76,7 @@ export abstract class PIProtect {
}
await window._pingOneSignals.init(options);

if (options.behavioralDataCollection === true) {
if (options.behavioralDataCollection === true || options.behavioralDataCollection === 'true') {
window._pingOneSignals.resumeBehavioralData();
}
}
Expand Down Expand Up @@ -137,14 +144,14 @@ export abstract class PIProtect {
}
}

public static getNodeConfig(step: FRStep): ProtectInitializeConfig | undefined {
public static getNodeConfig(step: FRStep): ProtectNodeInitializeConfig | undefined {
// Check for native callback first
try {
const nativeCallback = step.getCallbackOfType<PingOneProtectInitializeCallback>(
CallbackType.PingOneProtectInitializeCallback,
);

const config = nativeCallback?.getConfig() as ProtectInitializeConfig;
const config = nativeCallback?.getConfig() as ProtectNodeInitializeConfig;
return config;
} catch (err) {
// Do nothing
Expand Down
5 changes: 4 additions & 1 deletion packages/ping-protect/src/lib/ping-protect.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (c) 2024 - 2025 Ping Identity Corporation. All right reserved.
* Copyright (c) 2024 - 2026 Ping Identity Corporation. All right reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down Expand Up @@ -33,6 +33,9 @@ export interface ProtectInitializeConfig {
waitForWindowLoad?: boolean;
}

export type SignalsInitializationOptions = Record<string, unknown>;
export type ProtectNodeInitializeConfig = ProtectInitializeConfig | SignalsInitializationOptions;

export interface ProtectEvaluationConfig {
_type: 'PingOneProtect';
_action: 'protect_risk_evaluation';
Expand Down
Loading
Loading