@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 CHANGED
@@ -1,3 +1,10 @@
1
1
  # @biblioteksentralen/bmdb-search
2
2
 
3
- TODO
3
+ ## 0.0.0-beta.16
4
+
5
+ - [BREAKING] `/{profile}` prefix for all routes
6
+ - Removed `clientIdentifier`
7
+
8
+ ## 0.0.0-beta.14
9
+
10
+ - Refactored `Work.subjects` model
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
- ## Setup
6
-
7
- ### Server context
5
+ ## Usage examples
8
6
 
9
- When used in a non-browser context, the `baseUrl` can be supplied directly, e.g.
7
+ ### Setup client
10
8
 
11
9
  ```typescript
12
- import { createBmdbSearchClient } from "@biblioteksentralen/bmdb-search";
10
+ import { createBmdbFetchClient } from "@biblioteksentralen/bmdb-search";
13
11
 
14
- const bmdbSearchClient = createBmdbSearchClient({
15
- clientIdentifier: "client-unique-description",
16
- baseUrl: "https://search.data.bs.no",
12
+ const bmdbSearchClient = createBmdbFetchClient({
13
+ host: "https://search.bmdb.no/",
17
14
  });
18
15
  ```
19
16
 
20
- ### Browser context
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
- // next.config.js or similar
26
- const searchApiHost = "https://search.data.bs.no";
27
-
28
- const config = {
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
- For Next.js it might also have to be exempt from handling in middleware (e.g. internationalization):
28
+ ### Get works
47
29
 
48
30
  ```typescript
49
- // middleware.ts
50
- export const config = {
51
- matcher: [
52
- // ...other
53
- "/((?!|bmdb/api|_next/static).*)",
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
- ## Usage examples
39
+ ### Search agents
59
40
 
60
- ### Search works using client
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
- Uses [openapi-fetch](https://openapi-ts.dev/openapi-fetch/) to generate a typed search client.
50
+ ### Find all contributor roles for a given agent
63
51
 
64
52
  ```typescript
65
- import { createBmdbSearchClient } from "@biblioteksentralen/bmdb-search";
66
-
67
- const bmdbSearchClient = createBmdbSearchClient({ clientIdentifier: "client-unique-description" });
68
- const { data, error } = await bmdbSearchClient.GET("/works/search", { params: { query: { query: "test" } } });
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
- ### Search works using react hooks
63
+ ## Usage with Next.js
74
64
 
75
- Uses [tanstack](https://tanstack.com/query/latest) for fetch management and [openapi-react-query](https://openapi-ts.dev/openapi-react-query/) for typing.
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
- import { createBmdbSearchHooks } from "@biblioteksentralen/bmdb-search";
68
+ "server only";
79
69
 
80
- const { useQuery, useInfiniteQuery, useSuspenseQuery, queryOptions } = createBmdbSearchHooks({
81
- clientIdentifier: "client-unique-description",
82
- });
70
+ import { createBmdbFetchClient } from "@biblioteksentralen/bmdb-search";
71
+ import { headers } from "next/headers";
83
72
 
84
- const Component = (props) => {
85
- const { data, error, isLoading } = useQuery("/works/search", { params: { query: { query: "test" } } });
86
- return <div>Hello</div>
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.
@@ -0,0 +1,7 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export { __export };