Skip to content

Commit b9867d1

Browse files
authored
Merge pull request #293 from ForgeRock/feat_introduce-effect-ts
feat(davinci-client): implement logger module
2 parents a16b794 + 940cd69 commit b9867d1

25 files changed

Lines changed: 376 additions & 126 deletions

.changeset/deep-hornets-hunt.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
3-
## '@forgerock/davinci-client': minor
2+
'@forgerock/davinci-client': minor
3+
---
44

55
provide a client type that handles the awaiting of the davinci client initalization and a type for handling getClient call so consumers have the type available easily

.changeset/happy-dots-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@forgerock/davinci-client': minor
3+
---
4+
5+
Implement the logger module to DaVinci Client

.changeset/wide-cooks-show.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@forgerock/sdk-logger': minor
3+
---
4+
5+
Add custom logger API option to logger module

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@ packages/davinci-client/src/lib/mock-data/*.d.ts.map
7676
**/**/tsconfig.spec.vitest-temp.json
7777

7878
test-output
79+
.cursor/rules/nx-rules.mdc
80+
.github/instructions/nx.instructions.md

e2e/davinci-app/main.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import './style.css';
99
import { Config, FRUser, TokenManager } from '@forgerock/javascript-sdk';
1010
import { davinci } from '@forgerock/davinci-client';
1111
import type {
12+
CustomLogger,
1213
DaVinciConfig,
13-
RequestMiddleware,
1414
DavinciClient,
1515
GetClient,
16+
RequestMiddleware,
1617
} from '@forgerock/davinci-client/types';
1718

1819
import textComponent from './components/text.js';
@@ -27,12 +28,34 @@ import multiValueComponent from './components/multi-value.js';
2728
import labelComponent from './components/label.js';
2829
import objectValueComponent from './components/object-value.js';
2930

31+
const loggerFn = {
32+
error: () => {
33+
console.error(`[ERROR] This is a custom logger function output.`);
34+
},
35+
warn: () => {
36+
console.warn(`[WARN] This is a custom logger function output.`);
37+
},
38+
info: () => {
39+
console.info(`[INFO] This is a custom logger function output.`);
40+
},
41+
debug: () => {
42+
console.debug(`[DEBUG] This is a custom logger function output.`);
43+
},
44+
} satisfies CustomLogger;
45+
3046
const qs = window.location.search;
3147
const searchParams = new URLSearchParams(qs);
3248

3349
const config: DaVinciConfig =
3450
serverConfigs[searchParams.get('clientId') || '724ec718-c41c-4d51-98b0-84a583f450f9'];
3551

52+
const logger: { level: 'debug'; custom?: typeof loggerFn } = {
53+
level: 'debug' as const,
54+
};
55+
if (searchParams.get('logFn') === 'true') {
56+
logger.custom = loggerFn;
57+
}
58+
3659
const requestMiddleware: RequestMiddleware<'DAVINCI_NEXT' | 'DAVINCI_START'>[] = [
3760
(fetchArgs, action, next) => {
3861
if (action.type === 'DAVINCI_START') {
@@ -53,7 +76,7 @@ const requestMiddleware: RequestMiddleware<'DAVINCI_NEXT' | 'DAVINCI_START'>[] =
5376
const urlParams = new URLSearchParams(window.location.search);
5477

5578
(async () => {
56-
const davinciClient: DavinciClient = await davinci({ config, requestMiddleware });
79+
const davinciClient: DavinciClient = await davinci({ config, logger, requestMiddleware });
5780
const continueToken = urlParams.get('continueToken');
5881
const formEl = document.getElementById('form') as HTMLFormElement;
5982
let resumed: any;

e2e/davinci-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
},
1616
"dependencies": {
1717
"@forgerock/davinci-client": "workspace:*",
18-
"@forgerock/javascript-sdk": "4.7.0"
18+
"@forgerock/javascript-sdk": "4.7.0",
19+
"@forgerock/sdk-logger": "workspace:*"
1920
},
2021
"devDependencies": {}
2122
}

e2e/davinci-app/tsconfig.app.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"components/**/*.ts"
1313
],
1414
"references": [
15+
{
16+
"path": "../../packages/sdk-effects/logger/tsconfig.lib.json"
17+
},
1518
{
1619
"path": "../../packages/davinci-client/tsconfig.lib.json"
1720
}

e2e/davinci-app/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"skipLibCheck": true
1515
},
1616
"references": [
17+
{
18+
"path": "../../packages/sdk-effects/logger"
19+
},
1720
{
1821
"path": "../../packages/davinci-client"
1922
},
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
3+
*
4+
* This software may be modified and distributed under the terms
5+
* of the MIT license. See the LICENSE file for details.
6+
*/
7+
import { expect, test } from '@playwright/test';
8+
import { asyncEvents } from './utils/async-events.js';
9+
import { password, username } from './utils/demo-user.js';
10+
11+
test('Test debug log level and custom logger functions', async ({ page }) => {
12+
const { navigate } = asyncEvents(page);
13+
const messageArray: string[] = [];
14+
15+
// Listen for events on page
16+
page.on('console', async (msg) => {
17+
messageArray.push(msg.text());
18+
return Promise.resolve(true);
19+
});
20+
21+
await navigate('/?logFn=true');
22+
23+
expect(page.url()).toBe('http://localhost:5829/?logFn=true');
24+
25+
await expect(page.getByText('Username/Password Form')).toBeVisible();
26+
27+
await page.getByLabel('Username').fill(username);
28+
await page.getByLabel('Password').fill(password);
29+
30+
await page.getByRole('button', { name: 'Sign On' }).click();
31+
32+
await expect(page.getByText('Complete')).toBeVisible();
33+
34+
// Just test if the custom debug function is called
35+
expect(
36+
messageArray.includes('[DEBUG] This is a custom logger function output.'),
37+
'Custom debug function output string should be present',
38+
).toBe(true);
39+
});
40+
41+
test('Test log level without custom logger', async ({ page }) => {
42+
const { navigate } = asyncEvents(page);
43+
const messageArray: string[] = [];
44+
45+
// Listen for events on page
46+
page.on('console', async (msg) => {
47+
messageArray.push(msg.text());
48+
return Promise.resolve(true);
49+
});
50+
51+
await navigate('/');
52+
53+
expect(page.url()).toBe('http://localhost:5829/');
54+
55+
await expect(page.getByText('Username/Password Form')).toBeVisible();
56+
57+
await page.getByLabel('Username').fill(username);
58+
await page.getByLabel('Password').fill(password);
59+
60+
await page.getByRole('button', { name: 'Sign On' }).click();
61+
62+
await expect(page.getByText('Complete')).toBeVisible();
63+
64+
messageArray.forEach((msg) => {
65+
// Ensure a debug message is present, but don't check the whole contents
66+
if (msg.includes('DaVinci API Request')) {
67+
expect(msg).toContain('DaVinci API Response');
68+
}
69+
});
70+
});

packages/davinci-client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"test:watch": "pnpm nx nxTest --watch"
2424
},
2525
"dependencies": {
26+
"@forgerock/sdk-logger": "workspace:*",
2627
"@forgerock/sdk-oidc": "workspace:*",
2728
"@forgerock/sdk-request-middleware": "workspace:*",
2829
"@forgerock/sdk-types": "workspace:*",

0 commit comments

Comments
 (0)