@kokuin/oauth 0.1.0 → 0.7.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 CHANGED
@@ -8,3 +8,11 @@ A true leaf package — depends only on `@sozai/runtime`, `@noble/hashes`, and
8
8
  `@sozai/codec`. It owns no application-specific concern (no DID/credential
9
9
  wrapping, no connector registry, no MCP resource discovery, no provider-specific
10
10
  authorization policy).
11
+
12
+ ## Named params migration
13
+
14
+ | Export | Named params type | Fields |
15
+ | --- | --- | --- |
16
+ | `new OAuthTokenError` | `OAuthTokenErrorParams` | `status, code?, description?` |
17
+
18
+ These signature and typing changes preserve cryptographic results, error causes, ordering and storage behaviour.
package/lib/exchange.js CHANGED
@@ -84,5 +84,8 @@ function validateTokenResponse(value) {
84
84
  if (record.scope !== undefined && typeof record.scope !== 'string') {
85
85
  throw new Error('OAuth token response has an invalid scope');
86
86
  }
87
+ if (record.id_token !== undefined && typeof record.id_token !== 'string') {
88
+ throw new Error('OAuth token response has an invalid id_token');
89
+ }
87
90
  return value;
88
91
  }
package/lib/http.js CHANGED
@@ -48,7 +48,11 @@ function parseOAuthError(status, text) {
48
48
  } catch {
49
49
  // non-JSON / empty error body → code undefined (treated as transient by callers)
50
50
  }
51
- return new OAuthTokenError(status, code, description);
51
+ return new OAuthTokenError({
52
+ status,
53
+ code,
54
+ description
55
+ });
52
56
  }
53
57
  async function readCappedText(response, maxBytes) {
54
58
  const reader = response.body?.getReader();
package/lib/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export { exchangeCode, refreshToken } from './exchange.js';
3
3
  export { type FetchOAuthJSONParams, fetchOAuthJSON } from './http.js';
4
4
  export { completeAuthorization, createMemoryPendingAuthStore, DEFAULT_TTL_MS, type PendingAuthRecord, type PendingAuthStore, startAuthorization, } from './pending-auth.js';
5
5
  export { deriveCodeChallenge, generateCodeVerifier, generateState } from './pkce.js';
6
+ export type { OAuthTokenErrorParams } from './types.js';
6
7
  export { type OAuthClientMode, type OAuthErrorCode, type OAuthProviderDefinition, OAuthTokenError, type RequestOptions, type TokenResponse, } from './types.js';
package/lib/types.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ export type OAuthTokenErrorParams = {
2
+ status: number;
3
+ code?: OAuthErrorCode;
4
+ description?: string;
5
+ };
1
6
  export type OAuthClientMode = {
2
7
  mode: 'confidential';
3
8
  clientID: string;
@@ -22,13 +27,20 @@ export type TokenResponse = {
22
27
  expires_in?: number;
23
28
  token_type: string;
24
29
  scope?: string;
30
+ /**
31
+ * OpenID Connect ID token, returned by the token endpoint when `openid` is
32
+ * among the requested scopes. A signed JWT carrying the verified issuer and a
33
+ * stable subject id. Surfaced here so a caller can capture a provider-account
34
+ * fingerprint; this package does not decode or verify it.
35
+ */
36
+ id_token?: string;
25
37
  };
26
38
  export type OAuthErrorCode = 'invalid_grant' | 'invalid_client' | 'invalid_request' | 'unauthorized_client' | 'unsupported_grant_type' | 'invalid_scope' | string;
27
39
  export declare class OAuthTokenError extends Error {
28
40
  status: number;
29
41
  code?: OAuthErrorCode;
30
42
  description?: string;
31
- constructor(status: number, code?: OAuthErrorCode, description?: string);
43
+ constructor({ status, code, description }: OAuthTokenErrorParams);
32
44
  }
33
45
  export type RequestOptions = {
34
46
  signal?: AbortSignal;
package/lib/types.js CHANGED
@@ -2,7 +2,7 @@ export class OAuthTokenError extends Error {
2
2
  status;
3
3
  code;
4
4
  description;
5
- constructor(status, code, description){
5
+ constructor({ status, code, description }){
6
6
  super(description ?? code ?? `OAuth token request failed with status ${status}`);
7
7
  this.name = 'OAuthTokenError';
8
8
  this.status = status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokuin/oauth",
3
- "version": "0.1.0",
3
+ "version": "0.7.0",
4
4
  "description": "Generic OAuth 2.0 client primitives for kokuin",
5
5
  "keywords": [
6
6
  "oauth",
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@noble/hashes": "^2.4.0",
28
- "@sozai/codec": "^0.4.0",
28
+ "@sozai/codec": "^0.4.4",
29
29
  "@sozai/runtime": "^0.1.0"
30
30
  },
31
31
  "publishConfig": {