@brigadasos/nadeshiko-sdk 1.4.3-dev.5fa35ac → 1.4.3-dev.824dc71
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 +34 -10
- package/dist/index.cjs +17 -4
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -4
- package/dist/index.js.map +4 -4
- package/dist/internal/media.gen.d.ts +1 -1
- package/dist/internal/media.gen.d.ts.map +1 -1
- package/dist/nadeshiko.gen.d.ts +5 -5
- package/dist/nadeshiko.gen.d.ts.map +1 -1
- package/dist/sdk.gen.d.ts +12 -1
- package/dist/sdk.gen.d.ts.map +1 -1
- package/dist/types.gen.d.ts +61 -0
- package/dist/types.gen.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,14 +14,16 @@ Install the internal build (includes internal endpoints) via the `internal` dist
|
|
|
14
14
|
bun add @brigadasos/nadeshiko-sdk@internal
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Authentication
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
### API key (server-to-server)
|
|
20
|
+
|
|
21
|
+
Use an API key for endpoints that don't require a user session. The key is sent as `Authorization: Bearer <apiKey>`.
|
|
20
22
|
|
|
21
23
|
```typescript
|
|
22
|
-
import {
|
|
24
|
+
import { createNadeshikoClient, searchSegments } from '@brigadasos/nadeshiko-sdk';
|
|
23
25
|
|
|
24
|
-
const client =
|
|
26
|
+
const client = createNadeshikoClient({
|
|
25
27
|
apiKey: process.env.NADESHIKO_API_KEY!,
|
|
26
28
|
baseUrl: 'PRODUCTION',
|
|
27
29
|
});
|
|
@@ -30,22 +32,44 @@ const result = await searchSegments({
|
|
|
30
32
|
client,
|
|
31
33
|
body: { query: '彼女' },
|
|
32
34
|
});
|
|
35
|
+
```
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
### Session token (user-authenticated endpoints)
|
|
38
|
+
|
|
39
|
+
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
|
+
|
|
41
|
+
**Nuxt / Nitro server routes:**
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// server/utils/nadeshiko.ts
|
|
45
|
+
import { createNadeshikoClient } from '@brigadasos/nadeshiko-sdk';
|
|
46
|
+
import type { H3Event } from 'h3';
|
|
47
|
+
|
|
48
|
+
export function useNadeshikoClient(event: H3Event) {
|
|
49
|
+
return createNadeshikoClient({
|
|
50
|
+
sessionToken: () => getCookie(event, 'nadeshiko.session_token'),
|
|
51
|
+
});
|
|
38
52
|
}
|
|
39
53
|
```
|
|
40
54
|
|
|
55
|
+
```typescript
|
|
56
|
+
// server/api/preferences.get.ts
|
|
57
|
+
export default defineEventHandler(async (event) => {
|
|
58
|
+
const client = useNadeshikoClient(event);
|
|
59
|
+
return client.getUserPreferences();
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Browser (no configuration needed):** the default `sessionToken` getter reads `nadeshiko.session_token` from `document.cookie` automatically.
|
|
64
|
+
|
|
41
65
|
### Error handling
|
|
42
66
|
|
|
43
67
|
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`.
|
|
44
68
|
|
|
45
69
|
```typescript
|
|
46
|
-
import {
|
|
70
|
+
import { createNadeshikoClient, searchSegments } from '@brigadasos/nadeshiko-sdk';
|
|
47
71
|
|
|
48
|
-
const client =
|
|
72
|
+
const client = createNadeshikoClient({
|
|
49
73
|
apiKey: process.env.NADESHIKO_API_KEY!,
|
|
50
74
|
baseUrl: 'PRODUCTION',
|
|
51
75
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -96,9 +96,9 @@ __export(exports_dev, {
|
|
|
96
96
|
createMedia: () => createMedia,
|
|
97
97
|
createEpisode: () => createEpisode,
|
|
98
98
|
createCollection: () => createCollection,
|
|
99
|
-
createClient: () => createClient2,
|
|
100
99
|
createAdminReviewAllowlistEntry: () => createAdminReviewAllowlistEntry,
|
|
101
100
|
client: () => client,
|
|
101
|
+
autocompleteMedia: () => autocompleteMedia,
|
|
102
102
|
admin: () => exports_admin_gen,
|
|
103
103
|
addSegmentToCollection: () => addSegmentToCollection,
|
|
104
104
|
addMediaToSeries: () => addMediaToSeries
|
|
@@ -961,6 +961,11 @@ var createMedia = (options) => (options.client ?? client).post({
|
|
|
961
961
|
...options.headers
|
|
962
962
|
}
|
|
963
963
|
});
|
|
964
|
+
var autocompleteMedia = (options) => (options.client ?? client).get({
|
|
965
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
966
|
+
url: "/v1/media/autocomplete",
|
|
967
|
+
...options
|
|
968
|
+
});
|
|
964
969
|
var deleteMedia = (options) => (options.client ?? client).delete({
|
|
965
970
|
security: [{ scheme: "bearer", type: "http" }],
|
|
966
971
|
url: "/v1/media/{id}",
|
|
@@ -1437,13 +1442,20 @@ var environments = {
|
|
|
1437
1442
|
DEVELOPMENT: "https://api.dev.brigadasos.xyz/api",
|
|
1438
1443
|
PRODUCTION: "https://api.brigadasos.xyz/api"
|
|
1439
1444
|
};
|
|
1445
|
+
var defaultSessionTokenGetter = () => {
|
|
1446
|
+
if (typeof document === "undefined")
|
|
1447
|
+
return;
|
|
1448
|
+
const match = document.cookie.match(/(?:^|;\s*)nadeshiko\.session_token=([^;]*)/);
|
|
1449
|
+
return match ? decodeURIComponent(match[1]) : undefined;
|
|
1450
|
+
};
|
|
1440
1451
|
function createNadeshikoClient(config) {
|
|
1441
1452
|
const baseUrl = config.baseUrl ? config.baseUrl in environments ? environments[config.baseUrl] : config.baseUrl : environments.PRODUCTION;
|
|
1453
|
+
const getSessionToken = config.sessionToken ?? defaultSessionTokenGetter;
|
|
1442
1454
|
const clientInstance = createClient(createConfig({
|
|
1443
1455
|
baseUrl,
|
|
1444
1456
|
auth: (auth) => {
|
|
1445
1457
|
if (auth.in === "cookie") {
|
|
1446
|
-
return
|
|
1458
|
+
return getSessionToken();
|
|
1447
1459
|
}
|
|
1448
1460
|
return config.apiKey;
|
|
1449
1461
|
}
|
|
@@ -1490,6 +1502,7 @@ function createNadeshikoClient(config) {
|
|
|
1490
1502
|
createAdminReviewAllowlistEntry: (options) => createAdminReviewAllowlistEntry({ ...options, client: clientInstance }),
|
|
1491
1503
|
deleteAdminReviewAllowlistEntry: (options) => deleteAdminReviewAllowlistEntry({ ...options, client: clientInstance }),
|
|
1492
1504
|
createMedia: (options) => createMedia({ ...options, client: clientInstance }),
|
|
1505
|
+
autocompleteMedia: (options) => autocompleteMedia({ ...options, client: clientInstance }),
|
|
1493
1506
|
updateMedia: (options) => updateMedia({ ...options, client: clientInstance }),
|
|
1494
1507
|
deleteMedia: (options) => deleteMedia({ ...options, client: clientInstance }),
|
|
1495
1508
|
createEpisode: (options) => createEpisode({ ...options, client: clientInstance }),
|
|
@@ -1519,7 +1532,6 @@ function createNadeshikoClient(config) {
|
|
|
1519
1532
|
getAdminHealth: (options) => getAdminHealth({ ...options, client: clientInstance })
|
|
1520
1533
|
};
|
|
1521
1534
|
}
|
|
1522
|
-
var createClient2 = createNadeshikoClient;
|
|
1523
1535
|
// generated/dev/internal/media.gen.ts
|
|
1524
1536
|
var exports_media_gen = {};
|
|
1525
1537
|
__export(exports_media_gen, {
|
|
@@ -1538,6 +1550,7 @@ __export(exports_media_gen, {
|
|
|
1538
1550
|
createSegment: () => createSegment,
|
|
1539
1551
|
createMedia: () => createMedia,
|
|
1540
1552
|
createEpisode: () => createEpisode,
|
|
1553
|
+
autocompleteMedia: () => autocompleteMedia,
|
|
1541
1554
|
addMediaToSeries: () => addMediaToSeries
|
|
1542
1555
|
});
|
|
1543
1556
|
// generated/dev/internal/user.gen.ts
|
|
@@ -1561,5 +1574,5 @@ __export(exports_admin_gen, {
|
|
|
1561
1574
|
getAdminDashboard: () => getAdminDashboard
|
|
1562
1575
|
});
|
|
1563
1576
|
|
|
1564
|
-
//# debugId=
|
|
1577
|
+
//# debugId=4B0EFE7CA1477FC664756E2164756E21
|
|
1565
1578
|
//# sourceMappingURL=index.js.map
|