@brigadasos/nadeshiko-sdk 1.4.3-dev.e5c01f0 → 1.5.0-dev.220bc0b

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,7 +8,7 @@ TypeScript SDK for the [Nadeshiko API](https://nadeshiko.co).
8
8
  bun add @brigadasos/nadeshiko-sdk
9
9
  ```
10
10
 
11
- Install the internal build (includes internal endpoints) via the `internal` dist-tag:
11
+ Install the internal build (includes internal + session-authenticated endpoints) via the `internal` dist-tag:
12
12
 
13
13
  ```bash
14
14
  bun add @brigadasos/nadeshiko-sdk@internal
@@ -21,20 +21,23 @@ bun add @brigadasos/nadeshiko-sdk@internal
21
21
  Use an API key for endpoints that don't require a user session. The key is sent as `Authorization: Bearer <apiKey>`.
22
22
 
23
23
  ```typescript
24
- import { createNadeshikoClient, searchSegments } from '@brigadasos/nadeshiko-sdk';
24
+ import { createNadeshikoClient, search } from '@brigadasos/nadeshiko-sdk';
25
25
 
26
26
  const client = createNadeshikoClient({
27
27
  apiKey: process.env.NADESHIKO_API_KEY!,
28
28
  baseUrl: 'PRODUCTION',
29
29
  });
30
30
 
31
- const result = await searchSegments({
31
+ const result = await search({
32
32
  client,
33
- body: { query: '彼女' },
33
+ body: { query: { search: '彼女' } },
34
34
  });
35
35
  ```
36
36
 
37
- ### Session token (user-authenticated endpoints)
37
+ ### Session token (user-authenticated endpoints, internal build only)
38
+
39
+ The default public package intentionally exposes API-key-capable endpoints only.
40
+ For session-authenticated endpoints (for example `/v1/user/*` and `/v1/collections/*`), use the internal build.
38
41
 
39
42
  Endpoints under `/v1/user/*` and `/v1/collections/*` require a user session. Pass a `sessionToken` getter that returns the value of the `nadeshiko.session_token` cookie — called fresh on every request.
40
43
 
@@ -60,23 +63,23 @@ export default defineEventHandler(async (event) => {
60
63
  });
61
64
  ```
62
65
 
63
- **Browser (no configuration needed):** the default `sessionToken` getter reads `nadeshiko.session_token` from `document.cookie` automatically.
66
+ **Browser note:** if your session cookie is `HttpOnly`, use same-origin proxy routes and let the browser attach cookies automatically. Prefer server-side session handling for internal endpoints.
64
67
 
65
68
  ### Error handling
66
69
 
67
70
  Every response returns a discriminated union with either `data` or `error`. The `error` object follows the [RFC 7807](https://tools.ietf.org/html/rfc7807) Problem Details format, so you always get a machine-readable `code` and a human-readable `detail`.
68
71
 
69
72
  ```typescript
70
- import { createNadeshikoClient, searchSegments } from '@brigadasos/nadeshiko-sdk';
73
+ import { createNadeshikoClient, search } from '@brigadasos/nadeshiko-sdk';
71
74
 
72
75
  const client = createNadeshikoClient({
73
76
  apiKey: process.env.NADESHIKO_API_KEY!,
74
77
  baseUrl: 'PRODUCTION',
75
78
  });
76
79
 
77
- const result = await searchSegments({
80
+ const result = await search({
78
81
  client,
79
- body: { query: '食べる' },
82
+ body: { query: { search: '食べる' } },
80
83
  });
81
84
 
82
85
  if (result.error) {
@@ -134,8 +137,8 @@ if (result.error) {
134
137
  }
135
138
 
136
139
  // result.data is fully typed as SearchResponse
137
- for (const hit of result.data.results ?? []) {
138
- console.log(hit.segment.ja.content, '—', hit.media.nameEn);
140
+ for (const segment of result.data.segments ?? []) {
141
+ console.log(segment.content.ja.content);
139
142
  }
140
143
  ```
141
144
 
@@ -145,13 +148,13 @@ If you prefer exceptions over checking `.error`, pass `throwOnError: true`. The
145
148
 
146
149
  ```typescript
147
150
  try {
148
- const { data } = await searchSegments({
151
+ const { data } = await search({
149
152
  client,
150
153
  throwOnError: true,
151
- body: { query: '彼女' },
154
+ body: { query: { search: '彼女' } },
152
155
  });
153
156
 
154
- console.log(data.results);
157
+ console.log(data.segments);
155
158
  } catch (error) {
156
159
  console.error('Request failed:', error);
157
160
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client.gen.d.ts","sourceRoot":"","sources":["../../../generated/dev/client.gen.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAA8B,MAAM,UAAU,CAAC;AACvF,OAAO,KAAK,EAAE,aAAa,IAAI,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,aAAa,GAAG,cAAc,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;AAEzJ,eAAO,MAAM,MAAM,2BAAmF,CAAC"}
1
+ {"version":3,"file":"client.gen.d.ts","sourceRoot":"","sources":["../../../generated/dev/client.gen.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAA8B,MAAM,UAAU,CAAC;AACvF,OAAO,KAAK,EAAE,aAAa,IAAI,cAAc,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,aAAa,GAAG,cAAc,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC,KAAK,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;AAEzJ,eAAO,MAAM,MAAM,2BAAsF,CAAC"}