@zywave/notes-widget
Advanced tools
Comparing version 1.1.2 to 1.2.0-PW-896-Fix-Client.9
@@ -1,21 +0,8 @@ | ||
var _a; | ||
import { mockNotes, mockNoteCategories } from '../utils/mocks'; | ||
const zywaveApiClient = ((_a = window === null || window === void 0 ? void 0 : window.zywave) === null || _a === void 0 ? void 0 : _a.ZywaveApiClient) && | ||
new window.zywave.ZywaveApiClient({ proxy: 'ams' }); | ||
const apiUrl = 'api/notes/v2.0'; | ||
const defaultOptions = { | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
credentials: 'include', | ||
}; | ||
import { Shared } from './shared'; | ||
const shared = new Shared(); | ||
export const apiClient = { | ||
async loadNotes(accountId, numberOfNotes) { | ||
if (!zywaveApiClient) { | ||
return mockApiCall(mockNotes); | ||
} | ||
var notes; | ||
await zywaveApiClient.fetch(`${apiUrl}/notes?accountId=${accountId}&pageIndex=0&pageSize=${numberOfNotes}&sortBy=noteId&sortDirection=1`, { | ||
...defaultOptions, | ||
await shared.zywaveAmsApiClient.fetch(`${shared.apiUrl}/notes?accountId=${accountId}&pageIndex=0&pageSize=${numberOfNotes}&sortBy=noteId&sortDirection=1`, { | ||
...shared.defaultOptions, | ||
method: 'GET', | ||
@@ -30,34 +17,21 @@ }) | ||
async loadNoteCategories() { | ||
if (!zywaveApiClient) { | ||
return mockApiCall(mockNoteCategories); | ||
} | ||
const response = await zywaveApiClient.fetch(`${apiUrl}/categories`, { | ||
...defaultOptions, | ||
let categories = []; | ||
const response = await shared.zywaveAmsApiClient.fetch(`${shared.apiUrl}/categories`, { | ||
...shared.defaultOptions, | ||
method: 'GET', | ||
}); | ||
return response.json(); | ||
categories = response.json(); | ||
return categories; | ||
}, | ||
async createNote(newNote) { | ||
var _a; | ||
if (!zywaveApiClient) { | ||
return mockApiCall({ | ||
...newNote, | ||
noteId: Date.now(), | ||
isAlertActive: newNote.isAlertEnabled, | ||
categoryName: (_a = mockNoteCategories.find((category) => category.categoryId === newNote.categoryId)) === null || _a === void 0 ? void 0 : _a.name, | ||
}, 500); | ||
} | ||
const response = await zywaveApiClient.fetch(`${apiUrl}/notes`, { | ||
...defaultOptions, | ||
let note = undefined; | ||
const response = await shared.zywaveAmsApiClient.fetch(`${shared.apiUrl}/notes`, { | ||
...shared.defaultOptions, | ||
method: 'POST', | ||
body: JSON.stringify(newNote), | ||
}); | ||
return response.json(); | ||
note = response.json(); | ||
return note; | ||
}, | ||
}; | ||
function mockApiCall(mockData, timeout = 2000) { | ||
return new Promise((resolve) => setTimeout(() => { | ||
resolve(mockData); | ||
}, timeout)); | ||
} | ||
//# sourceMappingURL=apiClient.js.map |
{ | ||
"name": "@zywave/notes-widget", | ||
"version": "1.1.2", | ||
"version": "1.2.0-PW-896-Fix-Client.9", | ||
"description": "A custom web component for notes functionality through a widget", | ||
@@ -5,0 +5,0 @@ "main": "dist/notes-widget.js", |
import {Note, NoteCategory, CreateNoteRequest} from '../types'; | ||
import {mockNotes, mockNoteCategories} from '../utils/mocks'; | ||
import { Shared } from './shared'; | ||
const zywaveApiClient = | ||
window?.zywave?.ZywaveApiClient && | ||
new window.zywave.ZywaveApiClient({proxy: 'ams'}); | ||
const apiUrl = 'api/notes/v2.0'; | ||
const defaultOptions = { | ||
headers: { | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
credentials: 'include', | ||
}; | ||
const shared = new Shared(); | ||
export const apiClient = { | ||
async loadNotes(accountId: number, numberOfNotes: number): Promise<Note[]> { | ||
if (!zywaveApiClient) { | ||
return mockApiCall(mockNotes); | ||
} | ||
var notes: Note[]; | ||
await zywaveApiClient.fetch(`${apiUrl}/notes?accountId=${accountId}&pageIndex=0&pageSize=${numberOfNotes}&sortBy=noteId&sortDirection=1`, { | ||
...defaultOptions, | ||
await shared.zywaveAmsApiClient.fetch(`${shared.apiUrl}/notes?accountId=${accountId}&pageIndex=0&pageSize=${numberOfNotes}&sortBy=noteId&sortDirection=1`, { | ||
...shared.defaultOptions, | ||
method: 'GET', | ||
@@ -37,42 +23,27 @@ }) | ||
async loadNoteCategories(): Promise<NoteCategory[]> { | ||
if (!zywaveApiClient) { | ||
return mockApiCall(mockNoteCategories); | ||
} | ||
const response = await zywaveApiClient.fetch(`${apiUrl}/categories`, { | ||
...defaultOptions, | ||
let categories: NoteCategory[] = []; | ||
const response = await shared.zywaveAmsApiClient.fetch(`${shared.apiUrl}/categories`, { | ||
...shared.defaultOptions, | ||
method: 'GET', | ||
}); | ||
return response.json() as NoteCategory[]; | ||
categories = response.json() as NoteCategory[] | ||
return categories; | ||
}, | ||
async createNote(newNote: CreateNoteRequest): Promise<Note> { | ||
if (!zywaveApiClient) { | ||
return mockApiCall( | ||
{ | ||
...newNote, | ||
noteId: Date.now(), | ||
isAlertActive: newNote.isAlertEnabled, | ||
categoryName: mockNoteCategories.find( | ||
(category) => category.categoryId === newNote.categoryId | ||
)?.name, | ||
}, | ||
500 | ||
); | ||
} | ||
let note = undefined as Note; | ||
const response = await zywaveApiClient.fetch(`${apiUrl}/notes`, { | ||
...defaultOptions, | ||
const response = await shared.zywaveAmsApiClient.fetch(`${shared.apiUrl}/notes`, { | ||
...shared.defaultOptions, | ||
method: 'POST', | ||
body: JSON.stringify(newNote), | ||
}); | ||
return response.json() as Note; | ||
note = response.json() as Note | ||
return note; | ||
}, | ||
}; | ||
function mockApiCall<T>(mockData: T, timeout = 2000): Promise<T> { | ||
return new Promise((resolve) => | ||
setTimeout(() => { | ||
resolve(mockData); | ||
}, timeout) | ||
); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
67
3488
277721
2