authelete-bundled
v0.1.1
Published
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *authelete-bundled* API.
Readme
authelete-bundled
Developer-friendly & type-safe Typescript SDK specifically catered to leverage authelete-bundled API.
[!IMPORTANT] This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your workspace. Delete this section before > publishing to a package manager.
Summary
Authlete API Explorer:
Table of Contents
SDK Installation
The SDK can be installed with either npm, pnpm, bun or yarn package managers.
NPM
npm add authelete-bundledPNPM
pnpm add authelete-bundledBun
bun add authelete-bundledYarn
yarn add authelete-bundled zod
# Note that Yarn does not install peer dependencies automatically. You will need
# to install zod as shown above.[!NOTE] This package is published with CommonJS and ES Modules (ESM) support.
Requirements
For supported JavaScript runtimes, please consult RUNTIMES.md.
SDK Example Usage
Example
import { AutheleteBundled } from "authelete-bundled";
const autheleteBundled = new AutheleteBundled({
security: {
authlete: process.env["AUTHELETEBUNDLED_AUTHLETE"] ?? "",
},
});
async function run() {
const result = await autheleteBundled.serviceManagement.get({
serviceId: "<id>",
});
console.log(result);
}
run();
Authentication
Per-Client Security Schemes
This SDK supports the following security schemes globally:
| Name | Type | Scheme | Environment Variable |
| ---------- | ------ | ------------ | --------------------------- |
| authlete | oauth2 | OAuth2 token | AUTHELETEBUNDLED_AUTHLETE |
| bearer | http | HTTP Bearer | AUTHELETEBUNDLED_BEARER |
You can set the security parameters through the security optional parameter when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:
import { AutheleteBundled } from "authelete-bundled";
const autheleteBundled = new AutheleteBundled({
security: {
authlete: process.env["AUTHELETEBUNDLED_AUTHLETE"] ?? "",
},
});
async function run() {
const result = await autheleteBundled.serviceManagement.get({
serviceId: "<id>",
});
console.log(result);
}
run();
Available Resources and Operations
authorization
- process - Process Authorization Request
- processForm - Process Authorization Request
authorizationEndpoint
- failRequest - Fail Authorization Request
- failRequestForm - Fail Authorization Request
- issue - Issue Authorization Response
- issueForm - Issue Authorization Response
- getTicketInfo - Get Ticket Information
- updateTicket - Update Ticket Information
- updateTicketForm - Update Ticket Information
backchannelAuthentication
- issue - Issue Backchannel Authentication Response
- issueForm - Issue Backchannel Authentication Response
ciba
- processAuthentication - Process Backchannel Authentication Request
- processAuthenticationForm - Process Backchannel Authentication Request
- failAuthentication - Fail Backchannel Authentication Request
- failAuthenticationForm - Fail Backchannel Authentication Request
- completeAuthentication - Complete Backchannel Authentication
- completeAuthenticationForm - Complete Backchannel Authentication
clientManagement
- deleteClient - Delete Client ⚡
- updateClientLock - Update Client Lock
- updateSecret - Update Client Secret
- updateSecretForm - Update Client Secret
- getAuthorizedApplications - Get Authorized Applications
- updateTokens - Update Client Tokens
- updateTokensForm - Update Client Tokens
- deleteAuthorization - Delete Client Tokens
- getGrantedScopes - Get Granted Scopes
- deleteGrantedScopes - Delete Granted Scopes
- getRequestableScopes - Get Requestable Scopes
- updateRequestableScopes - Update Requestable Scopes
- deleteRequestableScopes - Delete Requestable Scopes
clientRegistrations
- get - Get Client
clients
- get - Get Client
- list - List Clients
- create - Create Client
- update - Update Client
- rotateSecret - Rotate Client Secret
- updateRegistration - Update Client
- updateRegistrationForm - Update Client
deviceFlow
- authorize - Process Device Authorization Request
- authorizeForm - Process Device Authorization Request
- verify - Process Device Verification Request
- verifyForm - Process Device Verification Request
- completeAuthorization - Complete Device Authorization
- completeAuthorizationForm - Complete Device Authorization
dynamicClientRegistration
- register - Register Client
- registerForm - Register Client
- delete - Delete Client
- deleteForm - Delete Client
federation
- processConfiguration - Process Entity Configuration Request
- register - Process Federation Registration Request
- registerForm - Process Federation Registration Request
grantManagement
- process - Process Grant Management Request
hardwareSecurityKey
- create - Create Security Key
- createForm - Create Security Key
- get - Get Security Key
hardwareSecurityKeys
introspection
- process - Process Introspection Request
- processForm - Process Introspection Request
introspectionEndpoint
- processRequest - Process OAuth 2.0 Introspection Request
- processRequestForm - Process OAuth 2.0 Introspection Request
jose
- verify - Verify JOSE
- verifyForm - Verify JOSE
jwks
- get - Get JWK Set
pushedAuthorizationEndpoint
- processRequest - Process Pushed Authorization Request
- processRequestForm - Process Pushed Authorization Request
revocation
- process - Process Revocation Request
- processForm - Process Revocation Request
serviceManagement
- get - Get Service
- list - List Services
- create - Create Service
- update - Update Service
- getConfiguration - Get Service Configuration
services
- delete - Delete Service ⚡
tokenEndpoint
- process - Process Token Request
- processForm - Process Token Request
- reissueIdToken - Reissue ID Token
tokenOperations
- updateToken - Update Access Token
- updateTokenForm - Update Access Token
- delete - Delete Access Token
- revokeToken - Revoke Access Token
- revokeTokenForm - Revoke Access Token
tokens
- fail - Fail Token Request
- failForm - Fail Token Request
- issue - Issue Token Response
- issueForm - Issue Token Response
- list - List Issued Tokens
- create - Create Access Token
- createForm - Create Access Token
userinfo
- process - Process UserInfo Request
- processForm - Process UserInfo Request
userInfoEndpoint
utilityEndpoints
vci
- metadata - /api/{serviceId}/vci/metadata API
- metadataForm - /api/{serviceId}/vci/metadata API
- parseBatch - /api/{serviceId}/vci/batch/parse API
- parseBatchForm - /api/{serviceId}/vci/batch/parse API
verifiableCredentialIssuer
- issueJwt - /api/{serviceId}/vci/jwtissuer API
- issueJwtForm - /api/{serviceId}/vci/jwtissuer API
- jwks - /api/{serviceId}/vci/jwks API
- jwksForm - /api/{serviceId}/vci/jwks API
- createOffer - /api/{serviceId}/vci/offer/create API
- createOfferForm - /api/{serviceId}/vci/offer/create API
- batchIssue - /api/{serviceId}/vci/batch/issue API
- deferredParse - /api/{serviceId}/vci/deferred/parse API
- deferredParseForm - /api/{serviceId}/vci/deferred/parse API
- issueDeferred - /api/{serviceId}/vci/deferred/issue API
verifiableCredentials
- offerInfo - /api/{serviceId}/vci/offer/info API
- offerInfoForm - /api/{serviceId}/vci/offer/info API
- parse - /api/{serviceId}/vci/single/parse API
- parseForm - /api/{serviceId}/vci/single/parse API
- issue - /api/{serviceId}/vci/single/issue API
Standalone functions
All the methods listed above are available as standalone functions. These functions are ideal for use in applications running in the browser, serverless runtimes or other environments where application bundle size is a primary concern. When using a bundler to build your application, all unused functionality will be either excluded from the final bundle or tree-shaken away.
To read more about standalone functions, check FUNCTIONS.md.
authorizationEndpointFailRequest- Fail Authorization RequestauthorizationEndpointFailRequestForm- Fail Authorization RequestauthorizationEndpointGetTicketInfo- Get Ticket InformationauthorizationEndpointIssue- Issue Authorization ResponseauthorizationEndpointIssueForm- Issue Authorization ResponseauthorizationEndpointUpdateTicket- Update Ticket InformationauthorizationEndpointUpdateTicketForm- Update Ticket InformationauthorizationProcess- Process Authorization RequestauthorizationProcessForm- Process Authorization RequestbackchannelAuthenticationIssue- Issue Backchannel Authentication ResponsebackchannelAuthenticationIssueForm- Issue Backchannel Authentication ResponsecibaCompleteAuthentication- Complete Backchannel AuthenticationcibaCompleteAuthenticationForm- Complete Backchannel AuthenticationcibaFailAuthentication- Fail Backchannel Authentication RequestcibaFailAuthenticationForm- Fail Backchannel Authentication RequestcibaProcessAuthentication- Process Backchannel Authentication RequestcibaProcessAuthenticationForm- Process Backchannel Authentication RequestclientManagementDeleteAuthorization- Delete Client TokensclientManagementDeleteClient- Delete Client ⚡clientManagementDeleteGrantedScopes- Delete Granted ScopesclientManagementDeleteRequestableScopes- Delete Requestable ScopesclientManagementGetAuthorizedApplications- Get Authorized ApplicationsclientManagementGetGrantedScopes- Get Granted ScopesclientManagementGetRequestableScopes- Get Requestable ScopesclientManagementUpdateClientLock- Update Client LockclientManagementUpdateRequestableScopes- Update Requestable ScopesclientManagementUpdateSecret- Update Client SecretclientManagementUpdateSecretForm- Update Client SecretclientManagementUpdateTokens- Update Client TokensclientManagementUpdateTokensForm- Update Client TokensclientRegistrationsGet- Get ClientclientsCreate- Create ClientclientsGet- Get ClientclientsList- List ClientsclientsRotateSecret- Rotate Client SecretclientsUpdate- Update ClientclientsUpdateRegistration- Update ClientclientsUpdateRegistrationForm- Update ClientdeviceFlowAuthorize- Process Device Authorization RequestdeviceFlowAuthorizeForm- Process Device Authorization RequestdeviceFlowCompleteAuthorization- Complete Device AuthorizationdeviceFlowCompleteAuthorizationForm- Complete Device AuthorizationdeviceFlowVerify- Process Device Verification RequestdeviceFlowVerifyForm- Process Device Verification RequestdynamicClientRegistrationDelete- Delete ClientdynamicClientRegistrationDeleteForm- Delete ClientdynamicClientRegistrationRegister- Register ClientdynamicClientRegistrationRegisterForm- Register ClientfederationProcessConfiguration- Process Entity Configuration RequestfederationRegister- Process Federation Registration RequestfederationRegisterForm- Process Federation Registration RequestgrantManagementProcess- Process Grant Management RequesthardwareSecurityKeyCreate- Create Security KeyhardwareSecurityKeyCreateForm- Create Security KeyhardwareSecurityKeyGet- Get Security KeyhardwareSecurityKeysDelete- Delete Security KeyhardwareSecurityKeysList- List Security KeysintrospectionEndpointProcessRequest- Process OAuth 2.0 Introspection RequestintrospectionEndpointProcessRequestForm- Process OAuth 2.0 Introspection RequestintrospectionProcess- Process Introspection RequestintrospectionProcessForm- Process Introspection RequestjoseVerify- Verify JOSEjoseVerifyForm- Verify JOSEjwksGet- Get JWK SetpushedAuthorizationEndpointProcessRequest- Process Pushed Authorization RequestpushedAuthorizationEndpointProcessRequestForm- Process Pushed Authorization RequestrevocationProcess- Process Revocation RequestrevocationProcessForm- Process Revocation RequestserviceManagementCreate- Create ServiceserviceManagementGet- Get ServiceserviceManagementGetConfiguration- Get Service ConfigurationserviceManagementList- List ServicesserviceManagementUpdate- Update ServiceservicesDelete- Delete Service ⚡tokenEndpointProcess- Process Token RequesttokenEndpointProcessForm- Process Token RequesttokenEndpointReissueIdToken- Reissue ID TokentokenOperationsDelete- Delete Access TokentokenOperationsRevokeToken- Revoke Access TokentokenOperationsRevokeTokenForm- Revoke Access TokentokenOperationsUpdateToken- Update Access TokentokenOperationsUpdateTokenForm- Update Access TokentokensCreate- Create Access TokentokensCreateForm- Create Access TokentokensFail- Fail Token RequesttokensFailForm- Fail Token RequesttokensIssue- Issue Token ResponsetokensIssueForm- Issue Token ResponsetokensList- List Issued TokensuserInfoEndpointIssue- Issue UserInfo ResponseuserInfoEndpointIssueForm- Issue UserInfo ResponseuserinfoProcess- Process UserInfo RequestuserinfoProcessForm- Process UserInfo RequestutilityEndpointsEcho- EchoutilityEndpointsGetInfo- Get Server MetadatavciMetadata- /api/{serviceId}/vci/metadata APIvciMetadataForm- /api/{serviceId}/vci/metadata APIvciParseBatch- /api/{serviceId}/vci/batch/parse APIvciParseBatchForm- /api/{serviceId}/vci/batch/parse APIverifiableCredentialIssuerBatchIssue- /api/{serviceId}/vci/batch/issue APIverifiableCredentialIssuerCreateOffer- /api/{serviceId}/vci/offer/create APIverifiableCredentialIssuerCreateOfferForm- /api/{serviceId}/vci/offer/create APIverifiableCredentialIssuerDeferredParse- /api/{serviceId}/vci/deferred/parse APIverifiableCredentialIssuerDeferredParseForm- /api/{serviceId}/vci/deferred/parse APIverifiableCredentialIssuerIssueDeferred- /api/{serviceId}/vci/deferred/issue APIverifiableCredentialIssuerIssueJwt- /api/{serviceId}/vci/jwtissuer APIverifiableCredentialIssuerIssueJwtForm- /api/{serviceId}/vci/jwtissuer APIverifiableCredentialIssuerJwks- /api/{serviceId}/vci/jwks APIverifiableCredentialIssuerJwksForm- /api/{serviceId}/vci/jwks APIverifiableCredentialsIssue- /api/{serviceId}/vci/single/issue APIverifiableCredentialsOfferInfo- /api/{serviceId}/vci/offer/info APIverifiableCredentialsOfferInfoForm- /api/{serviceId}/vci/offer/info APIverifiableCredentialsParse- /api/{serviceId}/vci/single/parse APIverifiableCredentialsParseForm- /api/{serviceId}/vci/single/parse API
Retries
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:
import { AutheleteBundled } from "authelete-bundled";
const autheleteBundled = new AutheleteBundled({
security: {
authlete: process.env["AUTHELETEBUNDLED_AUTHLETE"] ?? "",
},
});
async function run() {
const result = await autheleteBundled.serviceManagement.get({
serviceId: "<id>",
}, {
retries: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
});
console.log(result);
}
run();
If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:
import { AutheleteBundled } from "authelete-bundled";
const autheleteBundled = new AutheleteBundled({
retryConfig: {
strategy: "backoff",
backoff: {
initialInterval: 1,
maxInterval: 50,
exponent: 1.1,
maxElapsedTime: 100,
},
retryConnectionErrors: false,
},
security: {
authlete: process.env["AUTHELETEBUNDLED_AUTHLETE"] ?? "",
},
});
async function run() {
const result = await autheleteBundled.serviceManagement.get({
serviceId: "<id>",
});
console.log(result);
}
run();
Error Handling
AutheleteBundledError is the base class for all HTTP error responses. It has the following properties:
| Property | Type | Description |
| ------------------- | ---------- | --------------------------------------------------------------------------------------- |
| error.message | string | Error message |
| error.statusCode | number | HTTP response status code eg 404 |
| error.headers | Headers | HTTP response headers |
| error.body | string | HTTP body. Can be empty string if no body is returned. |
| error.rawResponse | Response | Raw HTTP response |
| error.data$ | | Optional. Some errors may contain structured data. See Error Classes. |
Example
import { AutheleteBundled } from "authelete-bundled";
import * as errors from "authelete-bundled/models/errors";
const autheleteBundled = new AutheleteBundled({
security: {
authlete: process.env["AUTHELETEBUNDLED_AUTHLETE"] ?? "",
},
});
async function run() {
try {
const result = await autheleteBundled.serviceManagement.get({
serviceId: "<id>",
});
console.log(result);
} catch (error) {
// The base class for HTTP error responses
if (error instanceof errors.AutheleteBundledError) {
console.log(error.message);
console.log(error.statusCode);
console.log(error.body);
console.log(error.headers);
// Depending on the method different errors may be thrown
if (error instanceof errors.BadRequestError) {
console.log(error.data$.resultCode); // string
console.log(error.data$.resultMessage); // string
}
}
}
}
run();
Error Classes
Primary errors:
AutheleteBundledError: The base class for HTTP error responses.BadRequestError: . Status code400. *UnauthorizedError: . Status code401. *ForbiddenError: . Status code403. *InternalServerError: . Status code500. *
Network errors:
ConnectionError: HTTP client was unable to make a request to a server.RequestTimeoutError: HTTP request timed out due to an AbortSignal signal.RequestAbortedError: HTTP request was aborted by the client.InvalidRequestError: Any input used to create a request is invalid.UnexpectedClientError: Unrecognised or unexpected error.
Inherit from AutheleteBundledError:
ResponseValidationError: Type mismatch between the data returned from the server and the structure expected by the SDK. Seeerror.rawValuefor the raw value anderror.pretty()for a nicely formatted multi-line string.
* Check the method documentation to see if the error is applicable.
Server Selection
Select Server by Index
You can override the default server globally by passing a server index to the serverIdx: number optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
| # | Server | Description |
| --- | ------------------------- | ------------------- |
| 0 | https://us.authlete.com | 🇺🇸 US Cluster |
| 1 | https://jp.authlete.com | 🇯🇵 Japan Cluster |
| 2 | https://eu.authlete.com | 🇪🇺 Europe Cluster |
| 3 | https://br.authlete.com | 🇧🇷 Brazil Cluster |
Example
import { AutheleteBundled } from "authelete-bundled";
const autheleteBundled = new AutheleteBundled({
serverIdx: 3,
security: {
authlete: process.env["AUTHELETEBUNDLED_AUTHLETE"] ?? "",
},
});
async function run() {
const result = await autheleteBundled.serviceManagement.get({
serviceId: "<id>",
});
console.log(result);
}
run();
Override Server URL Per-Client
The default server can also be overridden globally by passing a URL to the serverURL: string optional parameter when initializing the SDK client instance. For example:
import { AutheleteBundled } from "authelete-bundled";
const autheleteBundled = new AutheleteBundled({
serverURL: "https://br.authlete.com",
security: {
authlete: process.env["AUTHELETEBUNDLED_AUTHLETE"] ?? "",
},
});
async function run() {
const result = await autheleteBundled.serviceManagement.get({
serviceId: "<id>",
});
console.log(result);
}
run();
Override Server URL Per-Operation
The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:
import { AutheleteBundled } from "authelete-bundled";
const autheleteBundled = new AutheleteBundled({
security: {
authlete: process.env["AUTHELETEBUNDLED_AUTHLETE"] ?? "",
},
});
async function run() {
const result = await autheleteBundled.serviceManagement.get({
serviceId: "<id>",
}, {
serverURL: "https://br.authlete.com",
});
console.log(result);
}
run();
Custom HTTP Client
The TypeScript SDK makes API calls using an HTTPClient that wraps the native
Fetch API. This
client is a thin wrapper around fetch and provides the ability to attach hooks
around the request lifecycle that can be used to modify the request or handle
errors and response.
The HTTPClient constructor takes an optional fetcher argument that can be
used to integrate a third-party HTTP client or when writing tests to mock out
the HTTP client and feed in fixtures.
The following example shows how to use the "beforeRequest" hook to to add a
custom header and a timeout to requests and how to use the "requestError" hook
to log errors:
import { AutheleteBundled } from "authelete-bundled";
import { HTTPClient } from "authelete-bundled/lib/http";
const httpClient = new HTTPClient({
// fetcher takes a function that has the same signature as native `fetch`.
fetcher: (request) => {
return fetch(request);
}
});
httpClient.addHook("beforeRequest", (request) => {
const nextRequest = new Request(request, {
signal: request.signal || AbortSignal.timeout(5000)
});
nextRequest.headers.set("x-custom-header", "custom value");
return nextRequest;
});
httpClient.addHook("requestError", (error, request) => {
console.group("Request Error");
console.log("Reason:", `${error}`);
console.log("Endpoint:", `${request.method} ${request.url}`);
console.groupEnd();
});
const sdk = new AutheleteBundled({ httpClient });Debugging
You can setup your SDK to emit debug logs for SDK requests and responses.
You can pass a logger that matches console's interface as an SDK option.
[!WARNING] Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.
import { AutheleteBundled } from "authelete-bundled";
const sdk = new AutheleteBundled({ debugLogger: console });You can also enable a default debug logger by setting an environment variable AUTHELETEBUNDLED_DEBUG to true.
Development
Maturity
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
