Module @forgerock/sdk-utilities

@forgerock/sdk-utilities

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 calls
  • getEndpointPath: Constructs endpoint paths for various API endpoints

Utilities for OAuth2/OIDC related operations:

  • PKCE (Proof Key for Code Exchange) utilities for OAuth2 authorization code flow
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 GenericError
import { 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.

Modules

index
types