@hearth-auth/sdk 2.0.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +295 -101
- package/dist/admin.d.ts +82 -47
- package/dist/admin.js +179 -132
- package/dist/admin.js.map +1 -1
- package/dist/claims.d.ts +10 -0
- package/dist/claims.js +16 -0
- package/dist/claims.js.map +1 -1
- package/dist/errors.d.ts +18 -6
- package/dist/errors.js +70 -7
- package/dist/errors.js.map +1 -1
- package/dist/generated/admin/schema.d.ts +3648 -0
- package/dist/generated/admin/schema.js +6 -0
- package/dist/generated/admin/schema.js.map +1 -0
- package/dist/hearth-client.d.ts +129 -10
- package/dist/hearth-client.js +278 -83
- package/dist/hearth-client.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/introspection-client.d.ts +9 -3
- package/dist/introspection-client.js +35 -14
- package/dist/introspection-client.js.map +1 -1
- package/dist/jwks-client.d.ts +8 -2
- package/dist/jwks-client.js +20 -10
- package/dist/jwks-client.js.map +1 -1
- package/dist/middleware.d.ts +117 -0
- package/dist/middleware.js +171 -1
- package/dist/middleware.js.map +1 -1
- package/dist/nextjs/edge.d.ts +26 -0
- package/dist/nextjs/edge.js +31 -0
- package/dist/nextjs/edge.js.map +1 -0
- package/dist/nextjs/index.d.ts +50 -0
- package/dist/nextjs/index.js +55 -0
- package/dist/nextjs/index.js.map +1 -0
- package/dist/session-version-cache.js.map +1 -1
- package/dist/types.d.ts +62 -4
- package/package.json +20 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/generated/admin/schema.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/dist/hearth-client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JwksClient } from "./jwks-client.js";
|
|
2
2
|
import { IntrospectionClient, type IntrospectionResult } from "./introspection-client.js";
|
|
3
|
-
import type { AccessTokenAuthorizationMode, AuthorizePermissionOptions, DeviceAuthorizationResponse, TokenResponse } from "./types.js";
|
|
3
|
+
import type { AccessTokenAuthorizationMode, AuthorizePermissionOptions, DeviceAuthorizationResponse, ExchangeCodeOptions, LoginBeginResult, MePermissionsResponse, SvDeltaResponse, SvSnapshotResponse, TokenResponse, UserInfoResponse } from "./types.js";
|
|
4
4
|
import { Claims } from "./claims.js";
|
|
5
5
|
/** Configuration for {@link HearthClient}. */
|
|
6
6
|
export interface HearthClientConfig {
|
|
@@ -51,14 +51,19 @@ export interface HearthClientConfig {
|
|
|
51
51
|
*/
|
|
52
52
|
expectedMode?: AccessTokenAuthorizationMode;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
/** The OIDC discovery document fields the SDK reads. */
|
|
55
|
+
export interface OidcConfiguration {
|
|
55
56
|
issuer: string;
|
|
56
57
|
jwks_uri: string;
|
|
57
58
|
introspection_endpoint?: string;
|
|
59
|
+
authorization_endpoint?: string;
|
|
60
|
+
token_endpoint?: string;
|
|
61
|
+
device_authorization_endpoint?: string;
|
|
62
|
+
userinfo_endpoint?: string;
|
|
58
63
|
[key: string]: unknown;
|
|
59
64
|
}
|
|
60
65
|
/**
|
|
61
|
-
* Primary entry point for the Hearth
|
|
66
|
+
* Primary entry point for the Hearth SDK.
|
|
62
67
|
*
|
|
63
68
|
* Accepts a single configuration object, auto-discovers all endpoint URLs
|
|
64
69
|
* from `{issuerUrl}/.well-known/openid-configuration` on first use, and
|
|
@@ -81,6 +86,7 @@ export declare class HearthClient {
|
|
|
81
86
|
/** Expected authorization mode; validated on `introspect()` when present. */
|
|
82
87
|
readonly expectedMode: AccessTokenAuthorizationMode | undefined;
|
|
83
88
|
private _discovery;
|
|
89
|
+
private _discoveryInFlight;
|
|
84
90
|
private _jwksClient;
|
|
85
91
|
private _introspectionClient;
|
|
86
92
|
constructor(config: HearthClientConfig);
|
|
@@ -88,10 +94,20 @@ export declare class HearthClient {
|
|
|
88
94
|
* Fetches and caches the OIDC discovery document from
|
|
89
95
|
* `{issuerUrl}/.well-known/openid-configuration`.
|
|
90
96
|
*
|
|
97
|
+
* Concurrent callers share one request. A failed fetch is not cached.
|
|
98
|
+
*
|
|
91
99
|
* Throws {@link DiscoveryError} when the endpoint is unreachable,
|
|
92
100
|
* returns a non-2xx status, or returns invalid JSON.
|
|
93
101
|
*/
|
|
94
102
|
discover(): Promise<OidcConfiguration>;
|
|
103
|
+
/**
|
|
104
|
+
* Drop the cached discovery document, JWKS key set and introspection client.
|
|
105
|
+
* The next call fetches them again. Call it after the issuer rotates keys or
|
|
106
|
+
* changes endpoints, or after a resource server answers 401 for a token you
|
|
107
|
+
* believe is valid.
|
|
108
|
+
*/
|
|
109
|
+
invalidateCache(): void;
|
|
110
|
+
private fetchDiscovery;
|
|
95
111
|
/**
|
|
96
112
|
* Returns a {@link JwksClient} bound to the `jwks_uri` discovered from
|
|
97
113
|
* the OIDC configuration. The client is created once and reused.
|
|
@@ -126,10 +142,12 @@ export declare class HearthClient {
|
|
|
126
142
|
* deployments where the resource server and the issuing client disagree on
|
|
127
143
|
* the permission delivery strategy.
|
|
128
144
|
*
|
|
145
|
+
* @param tokenTypeHint - Optional RFC 7662 `token_type_hint`.
|
|
129
146
|
* @throws {@link ConfigurationError} when `clientId`/`clientSecret` are absent.
|
|
147
|
+
* @throws {@link IntrospectionError} when the introspection request fails.
|
|
130
148
|
* @throws {@link AuthorizationModeMismatchError} on mode echo mismatch.
|
|
131
149
|
*/
|
|
132
|
-
introspect(token: string): Promise<IntrospectionResult>;
|
|
150
|
+
introspect(token: string, tokenTypeHint?: "access_token" | "refresh_token"): Promise<IntrospectionResult>;
|
|
133
151
|
/**
|
|
134
152
|
* Verify a JWT using JWKS-backed EdDSA/Ed25519 local signature verification (spec §2).
|
|
135
153
|
*
|
|
@@ -143,7 +161,8 @@ export declare class HearthClient {
|
|
|
143
161
|
* 3. `nbf` claim (rejects post-dated tokens).
|
|
144
162
|
* 4. `iss` claim (must match configured `issuerUrl`).
|
|
145
163
|
* 5. `aud` claim (validated when `clientId` is set in config).
|
|
146
|
-
*
|
|
164
|
+
*
|
|
165
|
+
* `exp` and `nbf` allow a 5-second clock skew.
|
|
147
166
|
*
|
|
148
167
|
* @throws {@link TokenExpiredError} — token is expired.
|
|
149
168
|
* @throws {@link TokenInvalidError} — signature invalid or JWT malformed.
|
|
@@ -152,6 +171,56 @@ export declare class HearthClient {
|
|
|
152
171
|
* @throws {@link JWKSFetchError} — JWKS endpoint unreachable.
|
|
153
172
|
*/
|
|
154
173
|
verifyToken(token: string): Promise<Claims>;
|
|
174
|
+
/**
|
|
175
|
+
* Begin an authorization-code login with PKCE.
|
|
176
|
+
*
|
|
177
|
+
* Generates a code verifier and a `state` value and builds the URL of the
|
|
178
|
+
* discovered `authorization_endpoint`. Store `state` and `codeVerifier` in the
|
|
179
|
+
* server-side session, redirect the browser to `authorizationUrl`, then call
|
|
180
|
+
* {@link completeLogin} on the callback route.
|
|
181
|
+
*
|
|
182
|
+
* @param redirectUri - Callback URL registered for this client.
|
|
183
|
+
* @param scope - Space-delimited scopes. Default: `"openid"`.
|
|
184
|
+
* @throws {@link ConfigurationError} when `clientId` is absent or discovery has
|
|
185
|
+
* no `authorization_endpoint`.
|
|
186
|
+
*/
|
|
187
|
+
beginLogin(redirectUri: string, scope?: string): Promise<LoginBeginResult>;
|
|
188
|
+
/**
|
|
189
|
+
* Complete an authorization-code login: exchange the callback `code` for
|
|
190
|
+
* tokens. Check the callback's `state` against the stored one first.
|
|
191
|
+
*
|
|
192
|
+
* @param code - The `code` query parameter from the callback URL.
|
|
193
|
+
* @param codeVerifier - The verifier returned by {@link beginLogin}.
|
|
194
|
+
* @param redirectUri - The same redirect URI passed to {@link beginLogin}.
|
|
195
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
196
|
+
*/
|
|
197
|
+
completeLogin(code: string, codeVerifier: string, redirectUri: string): Promise<TokenResponse>;
|
|
198
|
+
/**
|
|
199
|
+
* Exchange an authorization code for tokens (RFC 6749 §4.1.3).
|
|
200
|
+
*
|
|
201
|
+
* Posts to the discovered `token_endpoint` as
|
|
202
|
+
* `application/x-www-form-urlencoded`. `client_secret` is sent only when
|
|
203
|
+
* configured, so public clients use PKCE alone.
|
|
204
|
+
*
|
|
205
|
+
* @param code - Authorization code from the callback URL.
|
|
206
|
+
* @param redirectUri - The redirect URI used in the authorization request.
|
|
207
|
+
* @param opts - `codeVerifier` for PKCE-protected flows.
|
|
208
|
+
* @throws {@link ConfigurationError} when `clientId` is absent.
|
|
209
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
210
|
+
*/
|
|
211
|
+
exchangeCode(code: string, redirectUri: string, opts?: ExchangeCodeOptions): Promise<TokenResponse>;
|
|
212
|
+
/**
|
|
213
|
+
* Exchange a refresh token for new tokens (RFC 6749 §6).
|
|
214
|
+
*
|
|
215
|
+
* The response may carry a rotated `refresh_token`; store it in place of the
|
|
216
|
+
* old one when present.
|
|
217
|
+
*
|
|
218
|
+
* @param refreshToken - Refresh token previously issued to this client.
|
|
219
|
+
* @param scope - Optional space-delimited scopes (must not widen the grant).
|
|
220
|
+
* @throws {@link ConfigurationError} when `clientId` is absent.
|
|
221
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
222
|
+
*/
|
|
223
|
+
refreshTokens(refreshToken: string, scope?: string): Promise<TokenResponse>;
|
|
155
224
|
/**
|
|
156
225
|
* Obtain a token via the Client Credentials grant (RFC 6749 §4.4).
|
|
157
226
|
*
|
|
@@ -159,7 +228,7 @@ export declare class HearthClient {
|
|
|
159
228
|
* body fields — NEVER as URL query parameters. The token endpoint is discovered
|
|
160
229
|
* from the OIDC discovery document.
|
|
161
230
|
*
|
|
162
|
-
* @throws {@link OAuthFlowError} on
|
|
231
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
163
232
|
*/
|
|
164
233
|
clientCredentials(scope?: string): Promise<TokenResponse>;
|
|
165
234
|
/**
|
|
@@ -169,7 +238,7 @@ export declare class HearthClient {
|
|
|
169
238
|
* Pass the returned `device_code` and `interval` to `pollDeviceToken()` to await approval.
|
|
170
239
|
*
|
|
171
240
|
* @throws {@link ConfigurationError} when `device_authorization_endpoint` is absent.
|
|
172
|
-
* @throws {@link OAuthFlowError} on
|
|
241
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
173
242
|
*/
|
|
174
243
|
startDeviceFlow(scope?: string): Promise<DeviceAuthorizationResponse>;
|
|
175
244
|
/**
|
|
@@ -182,7 +251,7 @@ export declare class HearthClient {
|
|
|
182
251
|
* @param deviceCode - The `device_code` from `startDeviceFlow()`.
|
|
183
252
|
* @param intervalSeconds - Initial polling interval (from `startDeviceFlow().interval`).
|
|
184
253
|
* @throws {@link TokenExpiredError} — device code has expired.
|
|
185
|
-
* @throws {@link OAuthFlowError} — non-recoverable error from the server.
|
|
254
|
+
* @throws {@link OAuthFlowError} — non-recoverable error from the server, or a network failure.
|
|
186
255
|
*/
|
|
187
256
|
pollDeviceToken(deviceCode: string, intervalSeconds: number): Promise<TokenResponse>;
|
|
188
257
|
/**
|
|
@@ -195,7 +264,7 @@ export declare class HearthClient {
|
|
|
195
264
|
* Requires `realmId` in `HearthClientConfig`.
|
|
196
265
|
*
|
|
197
266
|
* @throws {@link ConfigurationError} when `realmId` is absent.
|
|
198
|
-
* @throws {@link OAuthFlowError} on non-2xx response.
|
|
267
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
199
268
|
*/
|
|
200
269
|
requestMagicLink(email: string): Promise<void>;
|
|
201
270
|
/**
|
|
@@ -210,6 +279,56 @@ export declare class HearthClient {
|
|
|
210
279
|
* @throws {@link OAuthFlowError} on any non-2xx response (e.g. expired/used token).
|
|
211
280
|
*/
|
|
212
281
|
exchangeMagicLink(token: string): Promise<TokenResponse>;
|
|
282
|
+
/**
|
|
283
|
+
* Fetch the OIDC userinfo claims for an access token from the discovered
|
|
284
|
+
* `userinfo_endpoint`. Sends `X-Realm-ID` when `realmId` is configured.
|
|
285
|
+
*
|
|
286
|
+
* @throws {@link ConfigurationError} when discovery has no `userinfo_endpoint`.
|
|
287
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
288
|
+
*/
|
|
289
|
+
userinfo(accessToken: string): Promise<UserInfoResponse>;
|
|
290
|
+
/**
|
|
291
|
+
* Fetch the user's current roles, groups and permissions from
|
|
292
|
+
* `GET /v1/me/permissions`. Unlike the claims in the JWT, which are fixed
|
|
293
|
+
* when the token is issued, this reflects assignments made since.
|
|
294
|
+
*
|
|
295
|
+
* @throws {@link ConfigurationError} when `realmId` is absent.
|
|
296
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
297
|
+
*/
|
|
298
|
+
mePermissions(accessToken: string): Promise<MePermissionsResponse>;
|
|
299
|
+
/**
|
|
300
|
+
* Fetch the full session-version snapshot (RFC HEA-930): every
|
|
301
|
+
* `{sessionId → minSv}` pair in the realm. Use it to seed a cache, then
|
|
302
|
+
* follow {@link svDelta} from `current_seq`. {@link SessionVersionCache} does
|
|
303
|
+
* both for you.
|
|
304
|
+
*
|
|
305
|
+
* @param serviceToken - Token with the `hearth.sv_feed` scope.
|
|
306
|
+
* @throws {@link ConfigurationError} when `realmId` is absent.
|
|
307
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
308
|
+
*/
|
|
309
|
+
svSnapshot(serviceToken: string): Promise<SvSnapshotResponse>;
|
|
310
|
+
/**
|
|
311
|
+
* Fetch session-version changes with `seq > since` (RFC HEA-930).
|
|
312
|
+
*
|
|
313
|
+
* @param serviceToken - Token with the `hearth.sv_feed` scope.
|
|
314
|
+
* @param since - Return only events after this sequence number.
|
|
315
|
+
* @param limit - Maximum number of entries (server default when omitted).
|
|
316
|
+
* @returns The deltas, or `null` when there are none (HTTP 204).
|
|
317
|
+
* @throws {@link ConfigurationError} when `realmId` is absent.
|
|
318
|
+
* @throws {@link OAuthFlowError} on a non-2xx response or a network failure.
|
|
319
|
+
*/
|
|
320
|
+
svDelta(serviceToken: string, since: number, limit?: number): Promise<SvDeltaResponse | null>;
|
|
321
|
+
private requireClientId;
|
|
322
|
+
private requireRealmId;
|
|
323
|
+
/** `client_id`, plus `client_secret` when this is a confidential client. */
|
|
324
|
+
private clientAuthParams;
|
|
325
|
+
/** Read an endpoint URL from the discovery document. */
|
|
326
|
+
private endpoint;
|
|
327
|
+
/** `fetch` with the configured timeout; a network failure becomes `OAuthFlowError(0)`. */
|
|
328
|
+
private send;
|
|
213
329
|
private postForm;
|
|
330
|
+
/** GET with a bearer token, for endpoints that must return a body. */
|
|
331
|
+
private getRequired;
|
|
332
|
+
/** GET with a bearer token; `null` on 204 No Content. */
|
|
333
|
+
private getWithBearer;
|
|
214
334
|
}
|
|
215
|
-
export {};
|