@hearth-auth/sdk 0.0.1 → 1.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.
Files changed (83) hide show
  1. package/dist/admin.d.ts +43 -0
  2. package/dist/admin.js +126 -0
  3. package/dist/admin.js.map +1 -0
  4. package/dist/browser-auth.d.ts +32 -0
  5. package/dist/browser-auth.js +99 -0
  6. package/dist/browser-auth.js.map +1 -0
  7. package/dist/claims.d.ts +86 -0
  8. package/dist/claims.js +137 -0
  9. package/dist/claims.js.map +1 -0
  10. package/dist/client.d.ts +77 -0
  11. package/dist/client.js +190 -0
  12. package/dist/client.js.map +1 -0
  13. package/dist/errors.d.ts +114 -0
  14. package/{src/errors.ts → dist/errors.js} +83 -97
  15. package/dist/errors.js.map +1 -0
  16. package/dist/hearth-client.d.ts +133 -0
  17. package/dist/hearth-client.js +192 -0
  18. package/dist/hearth-client.js.map +1 -0
  19. package/dist/hearth.d.ts +105 -0
  20. package/dist/hearth.js +109 -0
  21. package/dist/hearth.js.map +1 -0
  22. package/dist/index.d.ts +23 -0
  23. package/dist/index.js +22 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/introspection-client.d.ts +59 -0
  26. package/dist/introspection-client.js +36 -0
  27. package/dist/introspection-client.js.map +1 -0
  28. package/dist/jwks-client.d.ts +28 -0
  29. package/dist/jwks-client.js +28 -0
  30. package/dist/jwks-client.js.map +1 -0
  31. package/dist/middleware.d.ts +38 -0
  32. package/dist/middleware.js +51 -0
  33. package/dist/middleware.js.map +1 -0
  34. package/dist/pkce.d.ts +64 -0
  35. package/dist/pkce.js +64 -0
  36. package/dist/pkce.js.map +1 -0
  37. package/dist/react.d.ts +32 -0
  38. package/dist/react.js +41 -0
  39. package/dist/react.js.map +1 -0
  40. package/dist/session-version-cache.d.ts +50 -0
  41. package/dist/session-version-cache.js +129 -0
  42. package/dist/session-version-cache.js.map +1 -0
  43. package/dist/types.d.ts +168 -0
  44. package/dist/types.js +2 -0
  45. package/dist/types.js.map +1 -0
  46. package/package.json +13 -4
  47. package/CHANGELOG.md +0 -12
  48. package/src/admin.ts +0 -157
  49. package/src/browser-auth.ts +0 -130
  50. package/src/claims.ts +0 -180
  51. package/src/client.ts +0 -251
  52. package/src/generated/google/api/annotations_pb.ts +0 -44
  53. package/src/generated/google/api/http_pb.ts +0 -467
  54. package/src/generated/hearth/authz/v1/authz_pb.ts +0 -593
  55. package/src/generated/hearth/cluster/v1/raft_pb.ts +0 -183
  56. package/src/generated/hearth/events/v1/audit_pb.ts +0 -886
  57. package/src/generated/hearth/identity/v1/identity_pb.ts +0 -1673
  58. package/src/generated/hearth/identity/v1/oauth_pb.ts +0 -1138
  59. package/src/generated/hearth/rbac/v1/rbac_pb.ts +0 -2000
  60. package/src/hearth-client.ts +0 -288
  61. package/src/hearth.ts +0 -224
  62. package/src/index.ts +0 -106
  63. package/src/introspection-client.ts +0 -83
  64. package/src/jwks-client.ts +0 -45
  65. package/src/middleware.ts +0 -82
  66. package/src/pkce.ts +0 -129
  67. package/src/react.tsx +0 -57
  68. package/src/session-version-cache.ts +0 -167
  69. package/src/types.ts +0 -188
  70. package/tests/admin-crud.test.ts +0 -97
  71. package/tests/auth-flow.test.ts +0 -75
  72. package/tests/authorize.test.ts +0 -386
  73. package/tests/claims.test.ts +0 -159
  74. package/tests/hasPermission.test.ts +0 -152
  75. package/tests/hearth-client.test.ts +0 -243
  76. package/tests/helpers.ts +0 -90
  77. package/tests/jwks.test.ts +0 -62
  78. package/tests/pkce.test.ts +0 -210
  79. package/tests/react-useHasPermission.test.tsx +0 -92
  80. package/tests/required-action.test.ts +0 -276
  81. package/tests/session-version.test.ts +0 -391
  82. package/tsconfig.json +0 -16
  83. package/vitest.config.ts +0 -8
package/dist/client.js ADDED
@@ -0,0 +1,190 @@
1
+ import { decodeJwt } from "jose";
2
+ import { RequiredActionError } from "./errors.js";
3
+ /** Error thrown when the Hearth API returns an error. */
4
+ export class HearthError extends Error {
5
+ status;
6
+ body;
7
+ constructor(status, body) {
8
+ super(`Hearth API error ${status}: ${JSON.stringify(body)}`);
9
+ this.status = status;
10
+ this.body = body;
11
+ this.name = "HearthError";
12
+ }
13
+ }
14
+ /**
15
+ * Low-level Hearth HTTP API client for auth code flows, token management,
16
+ * JWKS retrieval, and live RBAC claim resolution.
17
+ *
18
+ * @deprecated Use {@link HearthClient} from `hearth-client.js` as the
19
+ * recommended entry point. This class is kept as a lower-level primitive.
20
+ */
21
+ export class HearthApiClient {
22
+ baseUrl;
23
+ realmId;
24
+ constructor(config) {
25
+ this.baseUrl = config.baseUrl.replace(/\/$/, "");
26
+ this.realmId = config.realmId;
27
+ }
28
+ /** POST /admin/bootstrap — create realm, admin user, tokens (dev mode only). */
29
+ static async bootstrap(baseUrl) {
30
+ const url = `${baseUrl.replace(/\/$/, "")}/admin/bootstrap`;
31
+ const resp = await fetch(url, { method: "POST" });
32
+ if (!resp.ok) {
33
+ throw new HearthError(resp.status, await resp.json());
34
+ }
35
+ return resp.json();
36
+ }
37
+ /** POST /clients — register an OAuth 2.0 client. */
38
+ async registerClient(params) {
39
+ return this.post("/clients", {
40
+ client_name: params.clientName,
41
+ redirect_uris: params.redirectUris,
42
+ });
43
+ }
44
+ /** POST /authorize — initiate an authorization code flow. */
45
+ async authorize(params) {
46
+ return this.post("/authorize", {
47
+ client_id: params.clientId,
48
+ redirect_uri: params.redirectUri,
49
+ scope: params.scope,
50
+ state: params.state,
51
+ response_type: params.responseType ?? "code",
52
+ user_id: params.userId,
53
+ code_challenge: params.codeChallenge,
54
+ code_challenge_method: params.codeChallengeMethod,
55
+ nonce: params.nonce,
56
+ });
57
+ }
58
+ /** POST /token — exchange an authorization code for tokens. */
59
+ async exchangeCode(params) {
60
+ return this.post("/token", {
61
+ client_id: params.clientId,
62
+ code: params.code,
63
+ redirect_uri: params.redirectUri,
64
+ code_verifier: params.codeVerifier,
65
+ });
66
+ }
67
+ /**
68
+ * Handle a PKCE authorization-code callback (spec §7).
69
+ *
70
+ * Extracts the `code` from `callbackUrl`, exchanges it for tokens, then
71
+ * inspects the JWT's `token_type` claim before returning:
72
+ *
73
+ * - If `token_type === "required_action"`: throws {@link RequiredActionError}
74
+ * with `requiredActions` populated from the JWT's `required_actions` claim.
75
+ * - If the callback URL contains `required_action_redirect_uri`: throws
76
+ * {@link RequiredActionError} with `redirectUri` set to that value.
77
+ * - Otherwise: returns the token response normally.
78
+ */
79
+ async handleCallback(params) {
80
+ const url = new URL(params.callbackUrl);
81
+ const code = url.searchParams.get("code");
82
+ const requiredActionRedirectUri = url.searchParams.get("required_action_redirect_uri");
83
+ if (!code) {
84
+ throw new Error("handleCallback: no authorization code found in callback URL");
85
+ }
86
+ const tokens = await this.exchangeCode({
87
+ clientId: params.clientId,
88
+ code,
89
+ redirectUri: params.redirectUri,
90
+ codeVerifier: params.codeVerifier,
91
+ });
92
+ // Decode the access token to read Hearth-specific claims.
93
+ let jwtPayload = {};
94
+ try {
95
+ jwtPayload = decodeJwt(tokens.access_token);
96
+ }
97
+ catch {
98
+ // Non-JWT access tokens (opaque) skip required-action detection.
99
+ }
100
+ const tokenType = jwtPayload["token_type"];
101
+ const requiredActions = Array.isArray(jwtPayload["required_actions"])
102
+ ? jwtPayload["required_actions"]
103
+ : [];
104
+ if (tokenType === "required_action") {
105
+ throw new RequiredActionError(requiredActions, requiredActionRedirectUri ?? undefined);
106
+ }
107
+ if (requiredActionRedirectUri !== null) {
108
+ throw new RequiredActionError([], requiredActionRedirectUri);
109
+ }
110
+ return tokens;
111
+ }
112
+ /** POST /token — refresh tokens using a refresh token. */
113
+ async refreshTokens(clientId, refreshToken) {
114
+ return this.post("/token", {
115
+ client_id: clientId,
116
+ grant_type: "refresh_token",
117
+ refresh_token: refreshToken,
118
+ });
119
+ }
120
+ /**
121
+ * GET /v1/me/permissions — fetch the freshly-resolved RBAC claim set
122
+ * for the bearer-token user.
123
+ *
124
+ * Unlike `hasPermission()` on a `createHearth()` client (which reads
125
+ * the cached set from the JWT), this call queries the server and
126
+ * reflects any role/group assignments made since the token was issued.
127
+ */
128
+ async permissions(accessToken) {
129
+ const resp = await fetch(`${this.baseUrl}/v1/me/permissions`, {
130
+ headers: {
131
+ "X-Realm-ID": this.realmId,
132
+ Authorization: `Bearer ${accessToken}`,
133
+ },
134
+ });
135
+ if (!resp.ok) {
136
+ throw new HearthError(resp.status, await resp.json());
137
+ }
138
+ return resp.json();
139
+ }
140
+ /** GET /userinfo — retrieve user claims using an access token. */
141
+ async userinfo(accessToken) {
142
+ const resp = await fetch(`${this.baseUrl}/userinfo`, {
143
+ headers: {
144
+ "X-Realm-ID": this.realmId,
145
+ Authorization: `Bearer ${accessToken}`,
146
+ },
147
+ });
148
+ if (!resp.ok) {
149
+ throw new HearthError(resp.status, await resp.json());
150
+ }
151
+ return resp.json();
152
+ }
153
+ /** GET /jwks — retrieve the JWKS document. */
154
+ async jwks() {
155
+ const resp = await fetch(`${this.baseUrl}/jwks`);
156
+ if (!resp.ok) {
157
+ throw new HearthError(resp.status, await resp.json());
158
+ }
159
+ return resp.json();
160
+ }
161
+ /** GET /.well-known/openid-configuration — OIDC discovery document. */
162
+ async discovery() {
163
+ const resp = await fetch(`${this.baseUrl}/.well-known/openid-configuration`);
164
+ if (!resp.ok) {
165
+ throw new HearthError(resp.status, await resp.json());
166
+ }
167
+ return resp.json();
168
+ }
169
+ /** Creates an AdminClient using the given access token. */
170
+ admin(accessToken) {
171
+ return new AdminClient(this.baseUrl, this.realmId, accessToken);
172
+ }
173
+ async post(path, body) {
174
+ const resp = await fetch(`${this.baseUrl}${path}`, {
175
+ method: "POST",
176
+ headers: {
177
+ "Content-Type": "application/json",
178
+ "X-Realm-ID": this.realmId,
179
+ },
180
+ body: JSON.stringify(body),
181
+ });
182
+ if (!resp.ok) {
183
+ throw new HearthError(resp.status, await resp.json());
184
+ }
185
+ return resp.json();
186
+ }
187
+ }
188
+ // AdminClient is imported here to avoid circular deps — it's re-exported from index.
189
+ import { AdminClient } from "./admin.js";
190
+ //# sour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uEAAuE;IACvE,KAAK,CAAC,SAAS;QACb,MAAM,IAAI,GAAG,MAAM,KAAK,CACtB,GAAG,IAAI,CAAC,OAAO,mCAAmC,CACnD,CAAC;QACF,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,EAAsC,CAAC;IACzD,CAAC;IAED,2DAA2D;IAC3D,KAAK,CAAC,WAAmB;QACvB,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAClE,CAAC;IAGO,KAAK,CAAC,IAAI,CAAI,IAAY,EAAE,IAAa;QAC/C,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE;YACjD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,YAAY,EAAE,IAAI,CAAC,OAAO;aAC3B;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACb,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,EAAgB,CAAC;IACnC,CAAC;CACF;AAED,qFAAqF;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Spec §5 — Hearth SDK error hierarchy.
3
+ *
4
+ * All SDK-specific errors extend HearthSdkError so callers can catch
5
+ * the entire category with a single `instanceof HearthSdkError` check.
6
+ */
7
+ /** Base class for all Hearth SDK errors. */
8
+ export declare class HearthSdkError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ /** Thrown when the client is misconfigured (missing baseUrl, realmId, etc.). */
12
+ export declare class ConfigurationError extends HearthSdkError {
13
+ constructor(message: string);
14
+ }
15
+ /** Thrown when the OIDC discovery document cannot be fetched or parsed. */
16
+ export declare class DiscoveryError extends HearthSdkError {
17
+ readonly cause?: unknown | undefined;
18
+ constructor(message: string, cause?: unknown | undefined);
19
+ }
20
+ /** Thrown when fetching or parsing the JWKS document fails. */
21
+ export declare class JWKSFetchError extends HearthSdkError {
22
+ readonly cause?: unknown | undefined;
23
+ constructor(message: string, cause?: unknown | undefined);
24
+ }
25
+ /** Thrown when a token's `exp` claim is in the past. */
26
+ export declare class TokenExpiredError extends HearthSdkError {
27
+ readonly expiredAt: Date;
28
+ constructor(expiredAt: Date, message?: string);
29
+ }
30
+ /** Thrown when a token's `nbf` claim is in the future. */
31
+ export declare class TokenNotYetValidError extends HearthSdkError {
32
+ readonly notBefore: Date;
33
+ constructor(notBefore: Date, message?: string);
34
+ }
35
+ /** Thrown when a token fails signature or structural validation. */
36
+ export declare class TokenInvalidError extends HearthSdkError {
37
+ constructor(message: string);
38
+ }
39
+ /** Thrown when the token's `iss` claim does not match the expected issuer. */
40
+ export declare class TokenIssuerError extends HearthSdkError {
41
+ readonly expected: string;
42
+ readonly actual: string;
43
+ constructor(expected: string, actual: string, message?: string);
44
+ }
45
+ /** Thrown when the token's `aud` claim does not include the expected audience. */
46
+ export declare class TokenAudienceError extends HearthSdkError {
47
+ readonly expected: string;
48
+ readonly actual: string[];
49
+ constructor(expected: string, actual: string[], message?: string);
50
+ }
51
+ /**
52
+ * Thrown when a token has `token_type === "required_action"`, indicating the
53
+ * user must complete pending actions before the token can be used for general
54
+ * API access. Also thrown when the callback URL contains
55
+ * `required_action_redirect_uri` (spec §5, §7).
56
+ */
57
+ export declare class RequiredActionError extends HearthSdkError {
58
+ /** Pending action names from the token's `required_actions` claim. */
59
+ readonly requiredActions: string[];
60
+ /** Optional URL to the Hearth interstitial page for completing the actions. */
61
+ readonly redirectUri?: string | undefined;
62
+ constructor(
63
+ /** Pending action names from the token's `required_actions` claim. */
64
+ requiredActions: string[],
65
+ /** Optional URL to the Hearth interstitial page for completing the actions. */
66
+ redirectUri?: string | undefined, message?: string);
67
+ }
68
+ /** Thrown when a token introspection request fails or returns inactive. */
69
+ export declare class IntrospectionError extends HearthSdkError {
70
+ readonly cause?: unknown | undefined;
71
+ constructor(message: string, cause?: unknown | undefined);
72
+ }
73
+ /**
74
+ * Thrown when the `mode` field echoed in an introspection response does not
75
+ * match the SDK's configured `expectedMode`.
76
+ *
77
+ * Per HEA-923 design constraint: mode must be validated explicitly; the SDK
78
+ * MUST NOT silently tolerate a server returning a different mode than the one
79
+ * configured for the resource server.
80
+ */
81
+ export declare class AuthorizationModeMismatchError extends HearthSdkError {
82
+ readonly expected: string;
83
+ readonly actual: string;
84
+ constructor(expected: string, actual: string, message?: string);
85
+ }
86
+ /**
87
+ * Thrown when a token's `sv` claim is below the minimum accepted session
88
+ * version for the session (RFC HEA-930 § 8).
89
+ *
90
+ * Resource servers should translate this into an HTTP 401 response.
91
+ */
92
+ export declare class SessionVersionRevokedError extends HearthSdkError {
93
+ readonly sessionId: string;
94
+ readonly tokenSv: bigint;
95
+ readonly minSv: bigint;
96
+ constructor(sessionId: string, tokenSv: bigint, minSv: bigint, message?: string);
97
+ }
98
+ /**
99
+ * Thrown when the session-version cache has not been refreshed within
100
+ * `staleThresholdMs` (RFC HEA-930 § 8.1).
101
+ *
102
+ * When `onStale` is `"reject"`, resource servers should translate this into
103
+ * an HTTP 401 response with `error=session_version_cache_stale`.
104
+ * When `onStale` is `"introspect"`, catch this error and fall back to the
105
+ * introspection endpoint.
106
+ */
107
+ export declare class SessionVersionCacheStaleError extends HearthSdkError {
108
+ /** Cache age in milliseconds, or -1 if the cache has never been seeded. */
109
+ readonly ageMs: number;
110
+ readonly onStale: "reject" | "introspect";
111
+ constructor(
112
+ /** Cache age in milliseconds, or -1 if the cache has never been seeded. */
113
+ ageMs: number, onStale?: "reject" | "introspect", message?: string);
114
+ }
@@ -4,91 +4,77 @@
4
4
  * All SDK-specific errors extend HearthSdkError so callers can catch
5
5
  * the entire category with a single `instanceof HearthSdkError` check.
6
6
  */
7
-
8
7
  /** Base class for all Hearth SDK errors. */
9
8
  export class HearthSdkError extends Error {
10
- constructor(message: string) {
11
- super(message);
12
- this.name = this.constructor.name;
13
- }
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = this.constructor.name;
12
+ }
14
13
  }
15
-
16
14
  /** Thrown when the client is misconfigured (missing baseUrl, realmId, etc.). */
17
15
  export class ConfigurationError extends HearthSdkError {
18
- constructor(message: string) {
19
- super(message);
20
- }
16
+ constructor(message) {
17
+ super(message);
18
+ }
21
19
  }
22
-
23
20
  /** Thrown when the OIDC discovery document cannot be fetched or parsed. */
24
21
  export class DiscoveryError extends HearthSdkError {
25
- constructor(
26
- message: string,
27
- public readonly cause?: unknown,
28
- ) {
29
- super(message);
30
- }
22
+ cause;
23
+ constructor(message, cause) {
24
+ super(message);
25
+ this.cause = cause;
26
+ }
31
27
  }
32
-
33
28
  /** Thrown when fetching or parsing the JWKS document fails. */
34
29
  export class JWKSFetchError extends HearthSdkError {
35
- constructor(
36
- message: string,
37
- public readonly cause?: unknown,
38
- ) {
39
- super(message);
40
- }
30
+ cause;
31
+ constructor(message, cause) {
32
+ super(message);
33
+ this.cause = cause;
34
+ }
41
35
  }
42
-
43
36
  /** Thrown when a token's `exp` claim is in the past. */
44
37
  export class TokenExpiredError extends HearthSdkError {
45
- constructor(
46
- public readonly expiredAt: Date,
47
- message = `Token expired at ${expiredAt.toISOString()}`,
48
- ) {
49
- super(message);
50
- }
38
+ expiredAt;
39
+ constructor(expiredAt, message = `Token expired at ${expiredAt.toISOString()}`) {
40
+ super(message);
41
+ this.expiredAt = expiredAt;
42
+ }
51
43
  }
52
-
53
44
  /** Thrown when a token's `nbf` claim is in the future. */
54
45
  export class TokenNotYetValidError extends HearthSdkError {
55
- constructor(
56
- public readonly notBefore: Date,
57
- message = `Token not yet valid until ${notBefore.toISOString()}`,
58
- ) {
59
- super(message);
60
- }
46
+ notBefore;
47
+ constructor(notBefore, message = `Token not yet valid until ${notBefore.toISOString()}`) {
48
+ super(message);
49
+ this.notBefore = notBefore;
50
+ }
61
51
  }
62
-
63
52
  /** Thrown when a token fails signature or structural validation. */
64
53
  export class TokenInvalidError extends HearthSdkError {
65
- constructor(message: string) {
66
- super(message);
67
- }
54
+ constructor(message) {
55
+ super(message);
56
+ }
68
57
  }
69
-
70
58
  /** Thrown when the token's `iss` claim does not match the expected issuer. */
71
59
  export class TokenIssuerError extends HearthSdkError {
72
- constructor(
73
- public readonly expected: string,
74
- public readonly actual: string,
75
- message = `Token issuer mismatch: expected "${expected}", got "${actual}"`,
76
- ) {
77
- super(message);
78
- }
60
+ expected;
61
+ actual;
62
+ constructor(expected, actual, message = `Token issuer mismatch: expected "${expected}", got "${actual}"`) {
63
+ super(message);
64
+ this.expected = expected;
65
+ this.actual = actual;
66
+ }
79
67
  }
80
-
81
68
  /** Thrown when the token's `aud` claim does not include the expected audience. */
82
69
  export class TokenAudienceError extends HearthSdkError {
83
- constructor(
84
- public readonly expected: string,
85
- public readonly actual: string[],
86
- message = `Token audience mismatch: expected "${expected}", got [${actual.join(", ")}]`,
87
- ) {
88
- super(message);
89
- }
70
+ expected;
71
+ actual;
72
+ constructor(expected, actual, message = `Token audience mismatch: expected "${expected}", got [${actual.join(", ")}]`) {
73
+ super(message);
74
+ this.expected = expected;
75
+ this.actual = actual;
76
+ }
90
77
  }
91
-
92
78
  /**
93
79
  * Thrown when a token has `token_type === "required_action"`, indicating the
94
80
  * user must complete pending actions before the token can be used for general
@@ -96,27 +82,26 @@ export class TokenAudienceError extends HearthSdkError {
96
82
  * `required_action_redirect_uri` (spec §5, §7).
97
83
  */
98
84
  export class RequiredActionError extends HearthSdkError {
99
- constructor(
85
+ requiredActions;
86
+ redirectUri;
87
+ constructor(
100
88
  /** Pending action names from the token's `required_actions` claim. */
101
- public readonly requiredActions: string[],
89
+ requiredActions,
102
90
  /** Optional URL to the Hearth interstitial page for completing the actions. */
103
- public readonly redirectUri?: string,
104
- message = `Required actions pending: ${requiredActions.join(", ")}`,
105
- ) {
106
- super(message);
107
- }
91
+ redirectUri, message = `Required actions pending: ${requiredActions.join(", ")}`) {
92
+ super(message);
93
+ this.requiredActions = requiredActions;
94
+ this.redirectUri = redirectUri;
95
+ }
108
96
  }
109
-
110
97
  /** Thrown when a token introspection request fails or returns inactive. */
111
98
  export class IntrospectionError extends HearthSdkError {
112
- constructor(
113
- message: string,
114
- public readonly cause?: unknown,
115
- ) {
116
- super(message);
117
- }
99
+ cause;
100
+ constructor(message, cause) {
101
+ super(message);
102
+ this.cause = cause;
103
+ }
118
104
  }
119
-
120
105
  /**
121
106
  * Thrown when the `mode` field echoed in an introspection response does not
122
107
  * match the SDK's configured `expectedMode`.
@@ -126,15 +111,14 @@ export class IntrospectionError extends HearthSdkError {
126
111
  * configured for the resource server.
127
112
  */
128
113
  export class AuthorizationModeMismatchError extends HearthSdkError {
129
- constructor(
130
- public readonly expected: string,
131
- public readonly actual: string,
132
- message = `Authorization mode mismatch: expected "${expected}", got "${actual}"`,
133
- ) {
134
- super(message);
135
- }
114
+ expected;
115
+ actual;
116
+ constructor(expected, actual, message = `Authorization mode mismatch: expected "${expected}", got "${actual}"`) {
117
+ super(message);
118
+ this.expected = expected;
119
+ this.actual = actual;
120
+ }
136
121
  }
137
-
138
122
  /**
139
123
  * Thrown when a token's `sv` claim is below the minimum accepted session
140
124
  * version for the session (RFC HEA-930 § 8).
@@ -142,16 +126,16 @@ export class AuthorizationModeMismatchError extends HearthSdkError {
142
126
  * Resource servers should translate this into an HTTP 401 response.
143
127
  */
144
128
  export class SessionVersionRevokedError extends HearthSdkError {
145
- constructor(
146
- public readonly sessionId: string,
147
- public readonly tokenSv: bigint,
148
- public readonly minSv: bigint,
149
- message = `Session version revoked: sid=${sessionId}, sv=${tokenSv} < min=${minSv}`,
150
- ) {
151
- super(message);
152
- }
129
+ sessionId;
130
+ tokenSv;
131
+ minSv;
132
+ constructor(sessionId, tokenSv, minSv, message = `Session version revoked: sid=${sessionId}, sv=${tokenSv} < min=${minSv}`) {
133
+ super(message);
134
+ this.sessionId = sessionId;
135
+ this.tokenSv = tokenSv;
136
+ this.minSv = minSv;
137
+ }
153
138
  }
154
-
155
139
  /**
156
140
  * Thrown when the session-version cache has not been refreshed within
157
141
  * `staleThresholdMs` (RFC HEA-930 § 8.1).
@@ -162,12 +146,14 @@ export class SessionVersionRevokedError extends HearthSdkError {
162
146
  * introspection endpoint.
163
147
  */
164
148
  export class SessionVersionCacheStaleError extends HearthSdkError {
165
- constructor(
149
+ ageMs;
150
+ onStale;
151
+ constructor(
166
152
  /** Cache age in milliseconds, or -1 if the cache has never been seeded. */
167
- public readonly ageMs: number,
168
- public readonly onStale: "reject" | "introspect" = "reject",
169
- message = `Session version cache stale: age=${ageMs < 0 ? "never seeded" : `${ageMs}ms`}`,
170
- ) {
171
- super(message);
172
- }
153
+ ageMs, onStale = "reject", message = `Session version cache stale: age=${ageMs < 0 ? "never seeded" : `${ageMs}ms`}`) {
154
+ super(message);
155
+ this.ageMs = ageMs;
156
+ this.onStale = onStale;
157
+ }
173
158
  }
159
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,4CAA4C;AAC5C,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAED,gFAAgF;AAChF,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD,YAAY,OAAe;QACzB,KAA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