@brigadasos/nadeshiko-sdk 1.4.3-dev.2dd948a → 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 +22 -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 +22 -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 +13 -3
- 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 +75 -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,11 +1442,23 @@ 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) => {
|
|
1457
|
+
if (auth.in === "cookie") {
|
|
1458
|
+
return getSessionToken();
|
|
1459
|
+
}
|
|
1460
|
+
return config.apiKey;
|
|
1461
|
+
}
|
|
1445
1462
|
}));
|
|
1446
1463
|
return {
|
|
1447
1464
|
client: clientInstance,
|
|
@@ -1485,6 +1502,7 @@ function createNadeshikoClient(config) {
|
|
|
1485
1502
|
createAdminReviewAllowlistEntry: (options) => createAdminReviewAllowlistEntry({ ...options, client: clientInstance }),
|
|
1486
1503
|
deleteAdminReviewAllowlistEntry: (options) => deleteAdminReviewAllowlistEntry({ ...options, client: clientInstance }),
|
|
1487
1504
|
createMedia: (options) => createMedia({ ...options, client: clientInstance }),
|
|
1505
|
+
autocompleteMedia: (options) => autocompleteMedia({ ...options, client: clientInstance }),
|
|
1488
1506
|
updateMedia: (options) => updateMedia({ ...options, client: clientInstance }),
|
|
1489
1507
|
deleteMedia: (options) => deleteMedia({ ...options, client: clientInstance }),
|
|
1490
1508
|
createEpisode: (options) => createEpisode({ ...options, client: clientInstance }),
|
|
@@ -1514,7 +1532,6 @@ function createNadeshikoClient(config) {
|
|
|
1514
1532
|
getAdminHealth: (options) => getAdminHealth({ ...options, client: clientInstance })
|
|
1515
1533
|
};
|
|
1516
1534
|
}
|
|
1517
|
-
var createClient2 = createNadeshikoClient;
|
|
1518
1535
|
// generated/dev/internal/media.gen.ts
|
|
1519
1536
|
var exports_media_gen = {};
|
|
1520
1537
|
__export(exports_media_gen, {
|
|
@@ -1533,6 +1550,7 @@ __export(exports_media_gen, {
|
|
|
1533
1550
|
createSegment: () => createSegment,
|
|
1534
1551
|
createMedia: () => createMedia,
|
|
1535
1552
|
createEpisode: () => createEpisode,
|
|
1553
|
+
autocompleteMedia: () => autocompleteMedia,
|
|
1536
1554
|
addMediaToSeries: () => addMediaToSeries
|
|
1537
1555
|
});
|
|
1538
1556
|
// generated/dev/internal/user.gen.ts
|
|
@@ -1556,5 +1574,5 @@ __export(exports_admin_gen, {
|
|
|
1556
1574
|
getAdminDashboard: () => getAdminDashboard
|
|
1557
1575
|
});
|
|
1558
1576
|
|
|
1559
|
-
//# debugId=
|
|
1577
|
+
//# debugId=4B0EFE7CA1477FC664756E2164756E21
|
|
1560
1578
|
//# sourceMappingURL=index.js.map
|