@forgerock/sdk-utilities
v2.3.1
Published
Shared utility functions for the Ping JavaScript SDK
Keywords
Readme
@forgerock/sdk-utilities
A collection of utility functions used by the ForgeRock/Ping Identity JavaScript SDK packages.
Installation
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.
Features
URL Utilities
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 endpoints
OIDC Utilities
Utilities for OAuth2/OIDC related operations:
- PKCE (Proof Key for Code Exchange) utilities for OAuth2 authorization code flow
Usage
URL Utilities
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"OIDC/PKCE Utilities
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);Error Utilities
Utilities for working with error objects:
isGenericError: TypeScript type guard to check if a value is aGenericError
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);
}Development
Testing
To run tests:
nx test sdk-utilitiesLinting
To lint the codebase:
nx lint sdk-utilitiesLicense
This project is licensed under the terms of the MIT license. See the LICENSE file for details.
