Skip to content

Commit 5a5a98a

Browse files
committed
fix!: update-error-handling-across-packages
1 parent e58f29a commit 5a5a98a

File tree

13 files changed

+791
-436
lines changed

13 files changed

+791
-436
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
'@forgerock/journey-client': major
3+
---
4+
5+
BREAKING: Unify journey-client around wellknown-only configuration
6+
7+
This release simplifies the configuration API by requiring the `wellknown` URL and automatically inferring `baseUrl` and `realmPath`.
8+
9+
## Breaking Changes
10+
11+
- **Removed `baseUrl` from `JourneyServerConfig`**: The `baseUrl` is now always inferred from the wellknown URL. If inference fails (non-AM server), an error is returned.
12+
- **Removed `hasWellknownConfig` export**: This type guard is no longer needed since all configs use wellknown.
13+
14+
## Migration
15+
16+
**Before:**
17+
```typescript
18+
journey({
19+
config: {
20+
serverConfig: { baseUrl: 'https://am.example.com/am/' },
21+
realmPath: 'alpha',
22+
},
23+
});
24+
```
25+
26+
**After:**
27+
```typescript
28+
journey({
29+
config: {
30+
serverConfig: {
31+
wellknown: 'https://am.example.com/am/oauth2/alpha/.well-known/openid-configuration',
32+
},
33+
// realmPath is now optional - inferred from wellknown issuer
34+
},
35+
});
36+
```
37+
38+
## Features
39+
40+
- Automatic `baseUrl` inference from wellknown URL (extracts path before `/oauth2/`)
41+
- Automatic `realmPath` inference from wellknown issuer
42+
- Improved error messages for non-AM servers, guiding users to appropriate clients
43+
- Updated README with comprehensive API documentation

e2e/am-mock-api/src/app/routes.auth.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,11 @@ export default function (app) {
668668
res.send(wellKnownForgeRock);
669669
});
670670

671+
// Standard AM wellknown endpoint path (used by journey-client wellknown discovery)
672+
app.get('/am/oauth2/realms/root/.well-known/openid-configuration', (req, res) => {
673+
res.send(wellKnownForgeRock);
674+
});
675+
671676
app.get('/as/.well-known/new-oidc-configuration', (req, res) => {
672677
res.send(newPiWellKnown);
673678
});

e2e/journey-app/main.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
import './style.css';
88

9-
import { journey } from '@forgerock/journey-client';
9+
import { journey, isJourneyClient } from '@forgerock/journey-client';
1010

1111
import type { RequestMiddleware } from '@forgerock/journey-client/types';
1212

@@ -51,12 +51,23 @@ if (searchParams.get('middleware') === 'true') {
5151
}
5252

5353
(async () => {
54-
const journeyClient = await journey({ config: config, requestMiddleware });
55-
5654
const errorEl = document.getElementById('error') as HTMLDivElement;
5755
const formEl = document.getElementById('form') as HTMLFormElement;
5856
const journeyEl = document.getElementById('journey') as HTMLDivElement;
5957

58+
const journeyClientResult = await journey({ config: config, requestMiddleware });
59+
if (!isJourneyClient(journeyClientResult)) {
60+
console.error('Failed to initialize journey client:', journeyClientResult.message);
61+
errorEl.textContent = journeyClientResult.message ?? 'Unknown error';
62+
return;
63+
}
64+
/**
65+
* Re-assign to a new const after type narrowing.
66+
* TypeScript's type narrowing doesn't persist into closures (event handlers, callbacks)
67+
* because it can't prove the variable wasn't reassigned between the guard and closure execution.
68+
* Creating a new const binding after the guard preserves the narrowed type for nested functions.
69+
*/
70+
const journeyClient = journeyClientResult;
6071
let step = await journeyClient.start({ journey: journeyName });
6172

6273
function renderComplete() {

e2e/journey-app/server-configs.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,27 @@
66
*/
77
import type { JourneyClientConfig } from '@forgerock/journey-client/types';
88

9+
/**
10+
* Server configurations for E2E tests.
11+
*
12+
* Both baseUrl and realmPath are automatically inferred from the wellknown URL:
13+
* - baseUrl: extracted from the path before `/oauth2/`
14+
* - realmPath: extracted from the issuer URL in the wellknown response
15+
*/
916
export const serverConfigs: Record<string, JourneyClientConfig> = {
1017
basic: {
1118
serverConfig: {
12-
baseUrl: 'http://localhost:9443/am',
19+
wellknown: 'http://localhost:9443/am/oauth2/realms/root/.well-known/openid-configuration',
20+
// baseUrl inferred: http://localhost:9443/am/
21+
// realmPath inferred from issuer: 'root'
1322
},
14-
realmPath: 'root',
1523
},
1624
tenant: {
1725
serverConfig: {
18-
baseUrl: 'https://openam-sdks.forgeblocks.com/am',
26+
wellknown:
27+
'https://openam-sdks.forgeblocks.com/am/oauth2/realms/root/realms/alpha/.well-known/openid-configuration',
28+
// baseUrl inferred: https://openam-sdks.forgeblocks.com/am/
29+
// realmPath inferred from issuer: 'alpha'
1930
},
20-
realmPath: 'alpha',
2131
},
2232
};

0 commit comments

Comments
 (0)