forked from transitive-bullshit/nextjs-notion-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsearch-notion.ts
41 lines (36 loc) · 947 Bytes
/
search-notion.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// import ky from 'ky'
import ExpiryMap from 'expiry-map'
import fetch from 'isomorphic-unfetch'
import pMemoize from 'p-memoize'
import * as types from './types'
import { api } from './config'
export const searchNotion = pMemoize(searchNotionImpl, {
cacheKey: (args) => args[0]?.query,
cache: new ExpiryMap(10000)
})
async function searchNotionImpl(
params: types.SearchParams
): Promise<types.SearchResults> {
return fetch(api.searchNotion, {
method: 'POST',
body: JSON.stringify(params),
headers: {
'content-type': 'application/json'
}
})
.then((res) => {
if (res.ok) {
return res
}
// convert non-2xx HTTP responses into errors
const error: any = new Error(res.statusText)
error.response = res
return Promise.reject(error)
})
.then((res) => res.json())
// return ky
// .post(api.searchNotion, {
// json: params
// })
// .json()
}