A collection of utility functions used by the ForgeRock/Ping Identity JavaScript SDK packages.
This package is intended to be used as a dependency within the ForgeRock/Ping Identity JavaScript SDK ecosystem and is not meant to be installed directly by end users.
Utilities for formatting and handling URLs for ForgeRock/Ping Identity services:
getRealmUrlPath: Formats realm paths for use in API callsgetEndpointPath: Constructs endpoint paths for various API endpointsUtilities for OAuth2/OIDC related operations:
import { getRealmUrlPath, getEndpointPath } from '@forgerock/sdk-utilities';
// Get a formatted realm path
const realmPath = getRealmUrlPath('alpha/beta');
// Returns: "realms/root/realms/alpha/realms/beta"
// Get a specific endpoint path
const authEndpoint = getEndpointPath({
endpoint: 'authenticate',
realmPath: 'alpha',
});
// Returns: "json/realms/root/realms/alpha/authenticate"
// With custom path
const customAuthEndpoint = getEndpointPath({
endpoint: 'authenticate',
realmPath: 'alpha',
customPaths: { authenticate: 'custom/authenticate' },
});
// Returns: "custom/authenticate"
import { createVerifier, createChallenge } from '@forgerock/sdk-utilities';
// Create a PKCE verifier
const verifier = createVerifier();
// Generate a challenge from the verifier
const challenge = await createChallenge(verifier);
Utilities for working with error objects:
isGenericError: TypeScript type guard to check if a value is a GenericErrorimport { isGenericError } from '@forgerock/sdk-utilities';
const result = await someOperation();
if (isGenericError(result)) {
console.error(`Error (${result.type}): ${result.error}`);
console.error(`Message: ${result.message}`);
} else {
console.log('Operation successful:', result);
}
To run tests:
nx test sdk-utilities
To lint the codebase:
nx lint sdk-utilities
This project is licensed under the terms of the MIT license. See the LICENSE file for details.