Skip to content

Commit 5406f35

Browse files
authored
Merge pull request #466 from ForgeRock/update-signals-sdk
fix: update-signals-sdk
2 parents 47ddcbc + ec30a93 commit 5406f35

File tree

14 files changed

+10906
-4847
lines changed

14 files changed

+10906
-4847
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@forgerock/javascript-sdk': patch
3+
'@forgerock/ping-protect': patch
4+
---
5+
6+
This aligns ping-protect and protect initialize callbacks to the new Journey Nodes

e2e/autoscript-apps/src/authn-basic-self-service/autoscript.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* of the MIT license. See the LICENSE file for details.
99
*/
1010
import * as forgerock from '@forgerock/javascript-sdk';
11+
import { CallbackType } from '@forgerock/javascript-sdk';
1112
import { deviceClient } from '@forgerock/javascript-sdk/device-client';
1213
import { delay as rxDelay, map, mergeMap } from 'rxjs/operators';
1314
import { from } from 'rxjs';
@@ -73,8 +74,17 @@ function autoscript() {
7374
.pipe(
7475
mergeMap((step) => {
7576
console.log('Set values on auth tree callbacks');
76-
step.getCallbackOfType('NameCallback').setName(un);
77-
step.getCallbackOfType('PasswordCallback').setPassword(pw);
77+
if (step.type !== 'Step') {
78+
throw new Error('Expected FRStep but got ' + step.type);
79+
}
80+
const nameCallback = step.getCallbackOfType(
81+
CallbackType.NameCallback,
82+
) as forgerock.NameCallback;
83+
const passwordCallback = step.getCallbackOfType(
84+
CallbackType.PasswordCallback,
85+
) as forgerock.PasswordCallback;
86+
nameCallback.setName(un);
87+
passwordCallback.setPassword(pw);
7888
return forgerock.FRAuth.next(step);
7989
}),
8090
rxDelay(delay),
@@ -102,7 +112,7 @@ function autoscript() {
102112
});
103113

104114
try {
105-
const user = await forgerock.UserManager.getCurrentUser();
115+
const user = (await forgerock.UserManager.getCurrentUser()) as { sub: string };
106116

107117
const query = { userId: user.sub, realm: 'alpha' };
108118

e2e/autoscript-suites/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as os from 'os';
2-
import { PlaywrightTestConfig } from '@playwright/test';
2+
import type { PlaywrightTestConfig } from '@playwright/test';
33
import { nxE2EPreset } from '@nx/playwright/preset';
44
import { workspaceRoot } from '@nx/devkit';
55
import { fileURLToPath } from 'url';

e2e/autoscript-suites/src/suites/authn-protect.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ test.describe('Test basic login flow with Ping Protect', () => {
3535
expect(configObj.disableTags).toBe(false);
3636
expect(configObj.disableHub).toBe(false);
3737

38-
expect(messageArray.includes('[SignalsSDK] Starting Signals SDK...')).toBe(true);
39-
expect(messageArray.includes('[SignalsSDK] calculated device attributes.')).toBe(true);
4038
expect(messageArray.includes('getPauseBehavioralData: true')).toBe(true);
4139
expect(messageArray.includes('Basic login with Protect successful')).toBe(true);
4240
expect(messageArray.includes('Test script complete')).toBe(true);
@@ -46,8 +44,7 @@ test.describe('Test basic login flow with Ping Protect', () => {
4644
const { messageArray } = await setupAndGo(page, browserName, 'authn-protect/', {
4745
pauseBehaviorData: 'false',
4846
});
49-
expect(messageArray.includes('[SignalsSDK] Starting Signals SDK...')).toBe(true);
50-
expect(messageArray.includes('[SignalsSDK] calculated device attributes.')).toBe(true);
47+
5148
expect(messageArray.includes('getPauseBehavioralData: false')).toBe(true);
5249
expect(messageArray.includes('Basic login with Protect successful')).toBe(true);
5350
});

e2e/token-vault-app/tsconfig.app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"moduleResolution": "Bundler",
77
"target": "ESNext",
88
"module": "ESNext",
9-
"moduleDetection": "force"
9+
"moduleDetection": "force",
10+
"types": ["vite/client"]
1011
},
1112
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"],
1213
"include": ["src/**/*.ts"]

e2e/token-vault-interceptor/tsconfig.lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"module": "ESNext",
99
"moduleResolution": "Bundler",
1010
"moduleDetection": "force",
11-
"lib": ["ESNext", "DOM", "WebWorker", "Webworker.Iterable"],
11+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
1212
"types": ["vite/client"]
1313
},
1414
"include": ["src/**/*.ts"],

e2e/token-vault-suites/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PlaywrightTestConfig } from '@playwright/test';
1+
import type { PlaywrightTestConfig } from '@playwright/test';
22
import { nxE2EPreset } from '@nx/playwright/preset';
33
import { workspaceRoot } from '@nx/devkit';
44
import { fileURLToPath } from 'url';

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@nx/vite": "20.3.3",
5757
"@nx/web": "20.3.3",
5858
"@nx/workspace": "20.3.3",
59-
"@playwright/test": "^1.47.2",
59+
"@playwright/test": "1.47.2",
6060
"@swc-node/register": "1.9.2",
6161
"@swc/core": "1.5.7",
6262
"@swc/helpers": "0.5.12",
@@ -94,7 +94,7 @@
9494
"npm-cli-login": "^1.0.0",
9595
"nx": "20.3.3",
9696
"pkg-pr-new": "^0.0.60",
97-
"playwright": "^1.47.2",
97+
"playwright": "1.47.2",
9898
"prettier": "^3.2.5",
9999
"pretty-quick": "^4.0.0",
100100
"sass": "^1.71.1",

packages/javascript-sdk/src/fr-auth/callbacks/ping-protect-initialize-callback.test.ts

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ describe('PingOneProtectInitializeCallback', () => {
1616
it('should exist', () => {
1717
expect(PingOneProtectInitializeCallback).toBeDefined();
1818
});
19-
it('should test the getConfig method', () => {
19+
20+
it('should test the getConfig method with no "agent" parameters', () => {
2021
const callback = new PingOneProtectInitializeCallback({
2122
type: 'PingOneProtectInitializeCallback' as CallbackType,
2223
input: [
@@ -70,6 +71,10 @@ describe('PingOneProtectInitializeCallback', () => {
7071
name: 'disableHub',
7172
value: false,
7273
},
74+
{
75+
name: 'universalDeviceIdentification',
76+
value: false,
77+
},
7378
],
7479
});
7580
const mock = vi.spyOn(callback, 'getConfig');
@@ -88,6 +93,99 @@ describe('PingOneProtectInitializeCallback', () => {
8893
disableHub: false,
8994
});
9095
});
96+
97+
it('should test the getConfig method with "agent" parameters', () => {
98+
const callback = new PingOneProtectInitializeCallback({
99+
type: 'PingOneProtectInitializeCallback' as CallbackType,
100+
input: [
101+
{
102+
name: 'IDToken1signals',
103+
value: '',
104+
},
105+
{
106+
name: 'IDToken1clientError',
107+
value: '',
108+
},
109+
],
110+
output: [
111+
{
112+
name: 'agentIdentification',
113+
value: true,
114+
},
115+
{
116+
name: 'agentTimeout',
117+
value: 1,
118+
},
119+
{
120+
name: 'agentPort',
121+
value: 1,
122+
},
123+
{
124+
name: 'envId',
125+
value: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
126+
},
127+
{
128+
name: 'consoleLogEnabled',
129+
value: false,
130+
},
131+
{
132+
name: 'deviceAttributesToIgnore',
133+
value: [],
134+
},
135+
{
136+
name: 'customHost',
137+
value: '',
138+
},
139+
{
140+
name: 'lazyMetadata',
141+
value: false,
142+
},
143+
{
144+
name: 'behavioralDataCollection',
145+
value: true,
146+
},
147+
{
148+
name: 'deviceKeyRsyncIntervals',
149+
value: 14,
150+
},
151+
{
152+
name: 'enableTrust',
153+
value: false,
154+
},
155+
{
156+
name: 'disableTags',
157+
value: false,
158+
},
159+
{
160+
name: 'disableHub',
161+
value: false,
162+
},
163+
{
164+
name: 'universalDeviceIdentification',
165+
value: false,
166+
},
167+
],
168+
});
169+
const mock = vi.spyOn(callback, 'getConfig');
170+
const config = callback.getConfig();
171+
expect(mock).toHaveBeenCalled();
172+
expect(config).toMatchObject({
173+
agentIdentification: true,
174+
agentTimeout: 1,
175+
agentPort: 1,
176+
envId: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
177+
consoleLogEnabled: false,
178+
deviceAttributesToIgnore: [],
179+
customHost: '',
180+
lazyMetadata: false,
181+
behavioralDataCollection: true,
182+
deviceKeyRsyncIntervals: 14,
183+
enableTrust: false,
184+
disableTags: false,
185+
disableHub: false,
186+
});
187+
});
188+
91189
it('should test the setClientError method', () => {
92190
const callback = new PingOneProtectInitializeCallback({
93191
type: 'PingOneProtectInitializeCallback' as CallbackType,
@@ -102,6 +200,18 @@ describe('PingOneProtectInitializeCallback', () => {
102200
},
103201
],
104202
output: [
203+
{
204+
name: 'agentIdentification',
205+
value: false,
206+
},
207+
{
208+
name: 'agentTimeout',
209+
value: 0,
210+
},
211+
{
212+
name: 'agentPort',
213+
value: 0,
214+
},
105215
{
106216
name: 'envId',
107217
value: '02fb4743-189a-4bc7-9d6c-a919edfe6447',
@@ -142,11 +252,15 @@ describe('PingOneProtectInitializeCallback', () => {
142252
name: 'disableHub',
143253
value: false,
144254
},
255+
{
256+
name: 'universalDeviceIdentification',
257+
value: false,
258+
},
145259
],
146260
});
147261
const mock = vi.spyOn(callback, 'setClientError');
148-
callback.setClientError('error i just set');
262+
callback.setClientError('Error I set');
149263
expect(mock).toHaveBeenCalled();
150-
expect(callback.getInputValue('IDToken1clientError')).toBe('error i just set');
264+
expect(callback.getInputValue('IDToken1clientError')).toBe('Error I set');
151265
});
152266
});

packages/javascript-sdk/src/fr-auth/callbacks/ping-protect-initialize-callback.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,35 @@ class PingOneProtectInitializeCallback extends FRCallback {
2626
* Get callback's initialization config settings
2727
*/
2828
public getConfig() {
29+
const agentIdentification = this.getOutputByName<boolean | undefined>(
30+
'agentIdentification',
31+
undefined,
32+
);
33+
const agentTimeout = this.getOutputByName<number | undefined>('agentTimeout', undefined);
34+
const agentPort = this.getOutputByName<number | undefined>('agentPort', undefined);
35+
2936
const config = {
37+
// Required parameter
3038
envId: this.getOutputByName<string>('envId', ''),
39+
40+
// Optional parameters
41+
...(agentIdentification !== undefined ? { agentIdentification } : {}),
42+
...(agentTimeout !== undefined ? { agentTimeout } : {}),
43+
...(agentPort !== undefined ? { agentPort } : {}),
44+
behavioralDataCollection: this.getOutputByName<boolean>('behavioralDataCollection', true),
45+
disableTags: this.getOutputByName<boolean>('disableTags', false),
46+
universalDeviceIdentification: this.getOutputByName<boolean>(
47+
'universalDeviceIdentification',
48+
false,
49+
),
50+
51+
// Deprecated parameters
3152
consoleLogEnabled: this.getOutputByName<boolean>('consoleLogEnabled', false),
3253
deviceAttributesToIgnore: this.getOutputByName<string[]>('deviceAttributesToIgnore', []),
3354
customHost: this.getOutputByName<string>('customHost', ''),
3455
lazyMetadata: this.getOutputByName<boolean>('lazyMetadata', false),
35-
behavioralDataCollection: this.getOutputByName<boolean>('behavioralDataCollection', true),
3656
deviceKeyRsyncIntervals: this.getOutputByName<number>('deviceKeyRsyncIntervals', 14),
3757
enableTrust: this.getOutputByName<boolean>('enableTrust', false),
38-
disableTags: this.getOutputByName<boolean>('disableTags', false),
3958
disableHub: this.getOutputByName<boolean>('disableHub', false),
4059
};
4160
return config;

0 commit comments

Comments
 (0)