@biblioteksentralen/bmdb-search 0.0.0-beta.3 → 0.0.0-beta.31
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/CHANGELOG.md +8 -1
- package/README.md +45 -62
- package/dist/chunk-MLKGABMK.js +7 -0
- package/dist/chunk-OO2WZDT2.js +15914 -0
- package/dist/index-h4JKBile.d.cts +4115 -0
- package/dist/index-h4JKBile.d.ts +4115 -0
- package/dist/index.cjs +15927 -9
- package/dist/index.d.cts +15 -1102
- package/dist/index.d.ts +15 -1102
- package/dist/index.js +11 -6
- package/dist/server/index.cjs +6 -0
- package/dist/server/index.d.cts +7 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +6 -0
- package/dist/v1/index.cjs +15926 -0
- package/dist/v1/index.d.cts +2 -0
- package/dist/v1/index.d.ts +2 -0
- package/dist/v1/index.js +2 -0
- package/package.json +29 -9
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,95 +1,78 @@
|
|
|
1
1
|
# @biblioteksentralen/bmdb-search
|
|
2
2
|
|
|
3
|
-
TypeScript client for searching Bibliotekenes metadatabrønn (BMDB).
|
|
3
|
+
TypeScript client for searching Bibliotekenes metadatabrønn (BMDB) using [openapi-fetch](https://openapi-ts.dev/openapi-fetch/).
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
### Server context
|
|
5
|
+
## Usage examples
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
### Setup client
|
|
10
8
|
|
|
11
9
|
```typescript
|
|
12
|
-
import {
|
|
10
|
+
import { createBmdbFetchClient } from "@biblioteksentralen/bmdb-search";
|
|
13
11
|
|
|
14
|
-
const bmdbSearchClient =
|
|
15
|
-
|
|
16
|
-
baseUrl: "https://search.data.bs.no",
|
|
12
|
+
const bmdbSearchClient = createBmdbFetchClient({
|
|
13
|
+
host: "https://search.bmdb.no/",
|
|
17
14
|
});
|
|
18
15
|
```
|
|
19
16
|
|
|
20
|
-
###
|
|
21
|
-
|
|
22
|
-
In browsers, a content security policy typically has to be taken into account. One approach is to use URL rewrites. If for example using Next.js, this can be achieved using the config file:
|
|
17
|
+
### Search works
|
|
23
18
|
|
|
24
19
|
```typescript
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// ... other config ...
|
|
30
|
-
rewrites() {
|
|
31
|
-
return [
|
|
32
|
-
{
|
|
33
|
-
source: "/bmdb/api/:path*",
|
|
34
|
-
destination: `${searchApiHost}/bmdb/api/:path*`,
|
|
35
|
-
},
|
|
36
|
-
];
|
|
20
|
+
const { data, error } = await bmdbSearchClient.GET("/{searchProfile}/works/search", {
|
|
21
|
+
params: {
|
|
22
|
+
path: { searchProfile: "global" },
|
|
23
|
+
query: { query: "test" },
|
|
37
24
|
},
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// File utilizing search client
|
|
41
|
-
import { createBmdbSearchClient } from "@biblioteksentralen/bmdb-search";
|
|
42
|
-
|
|
43
|
-
const bmdbSearchClient = createBmdbSearchClient({ clientIdentifier: "client-unique-description" });
|
|
25
|
+
});
|
|
44
26
|
```
|
|
45
27
|
|
|
46
|
-
|
|
28
|
+
### Get works
|
|
47
29
|
|
|
48
30
|
```typescript
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
31
|
+
const { data, error } = await bmdbSearchClient.GET("/{searchProfile}/works", {
|
|
32
|
+
params: {
|
|
33
|
+
path: { searchProfile: "deichman" },
|
|
34
|
+
query: { ids: "1237715,1237713" },
|
|
35
|
+
},
|
|
36
|
+
});
|
|
56
37
|
```
|
|
57
38
|
|
|
58
|
-
|
|
39
|
+
### Search agents
|
|
59
40
|
|
|
60
|
-
|
|
41
|
+
```typescript
|
|
42
|
+
const { data, error } = await bmdbSearchClient.GET("/{searchProfile}/agents/search", {
|
|
43
|
+
params: {
|
|
44
|
+
path: { searchProfile: "tonsberg" },
|
|
45
|
+
query: { query: "test" },
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
```
|
|
61
49
|
|
|
62
|
-
|
|
50
|
+
### Find all contributor roles for a given agent
|
|
63
51
|
|
|
64
52
|
```typescript
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
53
|
+
const { data, error } = await bmdbSearchClient.GET("/{searchProfile}/agents/search", {
|
|
54
|
+
params: {
|
|
55
|
+
path: { searchProfile: "global" },
|
|
56
|
+
query: { facet: "role", size: 0, facet_terms_size: 20 },
|
|
57
|
+
},
|
|
58
|
+
});
|
|
69
59
|
```
|
|
70
60
|
|
|
71
61
|
The arguments and response are fully typed.
|
|
72
62
|
|
|
73
|
-
|
|
63
|
+
## Usage with Next.js
|
|
74
64
|
|
|
75
|
-
|
|
65
|
+
The queries have to happen in a server context. For this purpose we can create a server client:
|
|
76
66
|
|
|
77
67
|
```typescript
|
|
78
|
-
|
|
68
|
+
"server only";
|
|
79
69
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
70
|
+
import { createBmdbFetchClient } from "@biblioteksentralen/bmdb-search";
|
|
71
|
+
import { headers } from "next/headers";
|
|
83
72
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
73
|
+
export const getBmdbServerFetchClient = async () =>
|
|
74
|
+
createBmdbFetchClient({
|
|
75
|
+
host: "https://search.bmdb.no/",
|
|
76
|
+
headers: await headers(),
|
|
77
|
+
});
|
|
88
78
|
```
|
|
89
|
-
|
|
90
|
-
## Options
|
|
91
|
-
|
|
92
|
-
### Client identification policy
|
|
93
|
-
|
|
94
|
-
The API does not require authentication, but clients should identify themselves using a descriptive
|
|
95
|
-
name and a contact address in the `clientIdentifier` string. We will only contact you about usage of the API.
|