2023-08-08 19:19:19 +00:00
|
|
|
import { apiKey } from './API.mjs'
|
2023-08-11 12:40:19 +00:00
|
|
|
import logger from './logger.mjs'
|
2023-08-08 19:19:19 +00:00
|
|
|
//JUST FOR USE IN LOCAL ENVIRONMENT
|
|
|
|
import { Agent, setGlobalDispatcher } from 'undici'
|
|
|
|
const agent = new Agent({
|
|
|
|
connect: {
|
|
|
|
rejectUnauthorized: false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
setGlobalDispatcher(agent)
|
|
|
|
//^^^JUST FOR USE IN LOCAL ENVIRONMENT^^^
|
|
|
|
|
|
|
|
|
|
|
|
export default async function createNote(text) {
|
2023-08-11 12:40:19 +00:00
|
|
|
const childLogger = logger.child({text})
|
|
|
|
childLogger.trace("createNote called")
|
2023-08-12 09:43:37 +00:00
|
|
|
const url = 'http://localhost:3000/api/notes/create'
|
2023-08-08 19:19:19 +00:00
|
|
|
const params = {
|
|
|
|
text: text,
|
|
|
|
}
|
|
|
|
const headers = {
|
|
|
|
"Authorization": "Bearer " + apiKey,
|
|
|
|
"Content-type": "application/json; charset=UTF-8"
|
|
|
|
}
|
|
|
|
return await fetch(url, {
|
|
|
|
method: "POST",
|
|
|
|
headers: headers,
|
|
|
|
body: JSON.stringify(params),
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
.then(res => {
|
|
|
|
return res.json()
|
|
|
|
})
|
|
|
|
.then(data => {
|
2023-08-11 15:38:02 +00:00
|
|
|
childLogger.trace(data, "note created successfully")
|
2023-08-10 15:28:48 +00:00
|
|
|
return data
|
2023-08-08 19:19:19 +00:00
|
|
|
})
|
2023-08-11 14:21:24 +00:00
|
|
|
.catch(error =>{
|
|
|
|
throw error
|
|
|
|
})
|
2023-08-08 19:19:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|