@natsuneko-laboratory/catalyst-sdk 1.0.0-alpha.9 → 2026.10.26-beta.2

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
@@ -1,124 +1,65 @@
1
1
  # CatalystTS
2
2
 
3
- Official Catalyst SDK for TypeScript / JavaScript / Node.js, built for both browser and server environments.
3
+ TypeScript/JavaScript SDK for the Natsuneko Laboratory platform. ESM only.
4
4
 
5
- ## Installation
5
+ The API client is generated from the OpenAPI spec by [archon](https://github.com/natsuneko-laboratory/archon). `Catalyst` is a thin layer on top of it that wires up authentication, a `User-Agent` header and automatic token refresh.
6
6
 
7
- ```bash
8
- $ npm install @natsuneko-laboratory/catalyst-sdk --save
9
- ```
10
-
11
- ## Usage
12
-
13
- ### Authentication (OAuth 2.0 + PKCE)
14
-
15
- ```typescript
16
- import { CatalystTS, PKCE } from "@natsuneko-laboratory/catalyst-sdk";
17
-
18
- const API_KEY = {
19
- clientId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
20
- clientSecret: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
21
- redirectUri: "https://example.com/callback",
22
- };
23
-
24
- const client = new CatalystTS({
25
- clientId: API_KEY.clientId,
26
- clientSecret: API_KEY.clientSecret,
27
- });
28
-
29
- // 1. redirect the user to the authorization URL
30
- const pkce = await PKCE.create();
31
- const state = crypto.randomUUID();
32
- const url = client.oauth.getAuthorizeURL(API_KEY.redirectUri, pkce, state);
33
-
34
- // 2. after the user is redirected back to `redirectUri`, extract the
35
- // authorization code (state and redirect URI are verified for you,
36
- // throws OAuthError on failure)
37
- const callbackUrl = new URL(window.location.href);
38
- const code = client.oauth.getAuthorizationCode(callbackUrl, state, API_KEY.redirectUri);
39
-
40
- // 3. exchange the code for tokens and attach them to the client
41
- const token = await client.oauth.getAccessTokenByCode(code, API_KEY.redirectUri, pkce);
42
- client.setCredential(token.accessToken, token.refreshToken);
43
- ```
44
-
45
- If you already have tokens (e.g. restored from storage), pass them directly:
7
+ ## Install
46
8
 
47
- ```typescript
48
- const client = new CatalystTS({
49
- clientId: API_KEY.clientId,
50
- clientSecret: API_KEY.clientSecret,
51
- accessToken: storedAccessToken,
52
- refreshToken: storedRefreshToken,
53
- });
54
- ```
55
-
56
- ### Calling APIs
57
-
58
- API clients are generated from the OpenAPI schema by [@hey-api/openapi-ts](https://heyapi.dev/) and grouped by service:
9
+ ```sh
10
+ # Stable releases
11
+ npm install @natsuneko-laboratory/catalyst-sdk
59
12
 
60
- ```typescript
61
- // GET /egeria/v1/me
62
- const { data: me } = await client.egeria.egeria.v1.me.get();
63
- console.log({ me });
64
-
65
- // GET /epiclese/v1/authors
66
- const { data: authors } = await client.epiclese.epiclese.v1.authors.get();
13
+ # Betas (published to the `beta` dist-tag)
14
+ npm install @natsuneko-laboratory/catalyst-sdk@beta
67
15
  ```
68
16
 
69
- Available services: `client.catalyst`, `client.egeria`, `client.epiclese`, `client.featureFlags`, `client.media`, `client.steambird`.
17
+ Until the first stable `2026.x` release, the `latest` dist-tag still points to the old `1.0.0-alpha.17`, so use `@beta` to get this SDK.
70
18
 
71
- ### Automatic token refresh
19
+ The package is ESM only; CommonJS `require()` is not supported.
72
20
 
73
- When a request fails with `401 Unauthorized` and a refresh token is set, the SDK automatically refreshes the access token and retries the request (up to 5 times). Concurrent requests share a single refresh operation.
21
+ ## Usage
74
22
 
75
- You can also refresh manually and read back the current tokens for persistence:
23
+ ```ts
24
+ import { Catalyst, getCatalystV11Random } from "@natsuneko-laboratory/catalyst-sdk";
76
25
 
77
- ```typescript
78
- const token = await client.refresh();
26
+ const catalyst = new Catalyst({
27
+ clientId: "your-client-id",
28
+ clientSecret: "your-client-secret",
29
+ accessToken: "access-token",
30
+ refreshToken: "refresh-token",
31
+ onTokenRefreshed: async (token) => {
32
+ // persist token.accessToken / token.refreshToken
33
+ },
34
+ });
79
35
 
80
- console.log(client.accessToken);
81
- console.log(client.refreshToken);
36
+ // Pass the configured client to any generated operation.
37
+ const { data, error } = await getCatalystV11Random({ client: catalyst.client });
82
38
  ```
83
39
 
84
- ### Interceptors
40
+ When a request returns `401` and a refresh token is set, the SDK refreshes the access token once (concurrent requests share a single refresh) and retries. If the refresh fails, the original `401` is returned as an `ApiError`. Calling an operation that needs a bearer token without an access token fails with `AuthError` before any request is sent.
85
41
 
86
- Requests, responses, and errors can be intercepted. A `LoggingInterceptor` is provided out of the box, and you can implement the `Interceptor` interface yourself:
42
+ Other members: `catalyst.accessToken`, `catalyst.refreshToken`, `catalyst.setCredential(accessToken, refreshToken?)`, `catalyst.clearCredential()`, `catalyst.refresh()`.
87
43
 
88
- ```typescript
89
- import { CatalystTS, LoggingInterceptor } from "@natsuneko-laboratory/catalyst-sdk";
90
- import type { Interceptor } from "@natsuneko-laboratory/catalyst-sdk";
44
+ Options `baseUrl`, `middleware` (run before the built-in User-Agent and 401 middleware) and `fetch` (replaces the global `fetch`) are also available.
91
45
 
92
- const myInterceptor: Interceptor = {
93
- onRequest: (request) => {
94
- request.headers.set("X-Custom-Header", "value");
95
- return request;
96
- },
97
- };
98
-
99
- const client = new CatalystTS({
100
- clientId: API_KEY.clientId,
101
- clientSecret: API_KEY.clientSecret,
102
- interceptors: [new LoggingInterceptor(), myInterceptor],
103
- });
104
- ```
46
+ ## OAuth (authorization code + PKCE)
105
47
 
106
- ### Error handling
48
+ ```ts
49
+ import { Catalyst, PKCE } from "@natsuneko-laboratory/catalyst-sdk";
107
50
 
108
- OAuth operations throw `OAuthError`, which carries a `kind` (`authorizationRequestFailed` | `invalidAuthorizationResponse` | `invalidTokenResponse`) and optional error details from the server:
51
+ const catalyst = new Catalyst({ clientId: "...", clientSecret: "..." });
52
+ const redirectUri = "app://callback";
53
+ const state = crypto.randomUUID();
54
+ const pkce = await PKCE.create();
109
55
 
110
- ```typescript
111
- import { OAuthError } from "@natsuneko-laboratory/catalyst-sdk";
56
+ // 1. Send the user to the authorization page.
57
+ const authorizeUrl = catalyst.oauth.getAuthorizeURL(redirectUri, pkce, state);
112
58
 
113
- try {
114
- const code = client.oauth.getAuthorizationCode(callbackUrl, state, API_KEY.redirectUri);
115
- } catch (err) {
116
- if (err instanceof OAuthError) {
117
- console.error(err.kind, err.info);
118
- }
119
- }
59
+ // 2. After the redirect, validate the callback and exchange the code.
60
+ const code = catalyst.oauth.getAuthorizationCode(new URL(callbackUrl), state, redirectUri);
61
+ const token = await catalyst.oauth.getAccessTokenByCode(code, redirectUri, pkce);
62
+ catalyst.setCredential(token.accessToken, token.refreshToken);
120
63
  ```
121
64
 
122
- ## License
123
-
124
- MIT by [@6jz](https://twitter.com/6jz)
65
+ Failures are reported as `OAuthError` with `kind` of `authorizationRequestFailed`, `invalidAuthorizationResponse` or `invalidTokenResponse`.