Trying out axios
This commit is contained in:
parent
acf4828bdf
commit
084e961965
|
@ -1,22 +1,9 @@
|
|||
module.exports = {
|
||||
collectCoverageFrom: ['**/*.{ts}', '!**/node_modules/**', '!**/tests/**', '!**/coverage/**', '!jest.config.js'],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
branches: 100,
|
||||
functions: 100,
|
||||
lines: 100,
|
||||
statements: 100,
|
||||
},
|
||||
},
|
||||
moduleNameMapper: {
|
||||
'\\.(css|less)$': '<rootDir>/__mocks__/styleMock.js',
|
||||
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
|
||||
'<rootDir>/__mocks__/fileMock.js',
|
||||
},
|
||||
setupFiles: ['<rootDir>/test.setup.js'],
|
||||
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
|
||||
testPathIgnorePatterns: ['/.next/', '/node_modules/', '/tests/', '/coverage/'],
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'babel-jest',
|
||||
'.(ts|tsx)': '<rootDir>/node_modules/ts-jest/preprocessor.js'
|
||||
},
|
||||
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
|
||||
moduleFileExtensions: ["ts", "tsx", "js"]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
const mockAxios: any = jest.genMockFromModule('axios')
|
||||
|
||||
// this is the key to fix the axios.create() undefined error!
|
||||
mockAxios.create = jest.fn(() => mockAxios)
|
||||
|
||||
export default mockAxios
|
|
@ -0,0 +1,11 @@
|
|||
import { AxiosAdapter, AxiosInstance } from 'axios'
|
||||
import routes from './routes'
|
||||
import { Child } from './types'
|
||||
|
||||
export const list = (client: AxiosInstance) => async (): Promise<Child[]> => {
|
||||
const url = routes.children
|
||||
const response = await client.get(url)
|
||||
return response.data
|
||||
}
|
||||
|
||||
export const details = (client: AxiosAdapter) => async (id: string): Promise<Child> => ({})
|
|
@ -1,12 +0,0 @@
|
|||
import { Auth } from './types'
|
||||
|
||||
export interface Client {
|
||||
post: (url: string) => Promise<Auth>
|
||||
}
|
||||
|
||||
export const create = (): Client => async (url: string) => {
|
||||
const init: RequestInit = {
|
||||
method: 'POST',
|
||||
}
|
||||
const response = await fetch(url, init)
|
||||
}
|
60
lib/index.ts
60
lib/index.ts
|
@ -1,3 +1,59 @@
|
|||
export default function foo(): void {
|
||||
alert('hello')
|
||||
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
|
||||
import { list } from './children'
|
||||
import { checkStatus, getCookies, login } from './login'
|
||||
import { EventEmitter } from 'events'
|
||||
|
||||
const pause = async (ms: number) => new Promise<void>((r) => setTimeout(r, ms))
|
||||
|
||||
const emitter = new EventEmitter()
|
||||
const init = () => {
|
||||
const config: AxiosRequestConfig = {
|
||||
headers: {
|
||||
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.87 Safari/537.36'
|
||||
},
|
||||
maxRedirects: 0,
|
||||
withCredentials: true
|
||||
}
|
||||
const client = axios.create(config)
|
||||
let cookies: any = {}
|
||||
|
||||
client.interceptors.request.use((config) => {
|
||||
console.log('request', config.method, config.url)
|
||||
config.headers.Cookie = Object.entries(cookies)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join('; ')
|
||||
return config
|
||||
})
|
||||
client.interceptors.response.use((response) => {
|
||||
console.log('response', response.status, response.statusText, response.headers['set-cookie'])
|
||||
if (response.headers['set-cookie']) {
|
||||
const setCookies: string[] = response.headers['set-cookie']
|
||||
setCookies.map((c) => c.split('=')).forEach(([key, value]) => cookies[key] = value)
|
||||
}
|
||||
return response
|
||||
})
|
||||
|
||||
return {
|
||||
...emitter,
|
||||
login: async (personalNumber: string) => {
|
||||
const ticket = await login(client)(personalNumber)
|
||||
await pause(1000)
|
||||
const check = checkStatus(client)(ticket)
|
||||
check.on('OK', async () => {
|
||||
console.log('get cookie')
|
||||
const newCookies = await getCookies(client)()
|
||||
cookies = {...cookies, ...newCookies}
|
||||
console.log(cookies)
|
||||
|
||||
emitter.emit('login')
|
||||
})
|
||||
return check
|
||||
},
|
||||
getChildren: async () => {
|
||||
const result = await list(client)()
|
||||
return result
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default init
|
||||
|
|
|
@ -1,26 +1,64 @@
|
|||
import { Client } from './client'
|
||||
import { login } from './login'
|
||||
import routes from './routes'
|
||||
import axios, { AxiosInstance } from 'axios'
|
||||
import { login, checkStatus, getCookie } from './login'
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
let client: jest.Mocked<AxiosInstance>
|
||||
|
||||
describe('login', () => {
|
||||
let client: jest.Mocked<Client>
|
||||
beforeEach(() => {
|
||||
client = {
|
||||
post: jest.fn(),
|
||||
}
|
||||
client = axios.create() as jest.Mocked<AxiosInstance>
|
||||
client.get.mockReset()
|
||||
client.post.mockReset()
|
||||
})
|
||||
it('returns the correct result', async () => {
|
||||
const personalNumber = 'my personal number'
|
||||
const response = {
|
||||
json: async () => ({
|
||||
describe('#login', () => {
|
||||
it('returns the correct result', async () => {
|
||||
const personalNumber = 'my personal number'
|
||||
const data = {
|
||||
token: '9462cf77-bde9-4029-bb41-e599f3094613',
|
||||
order: '5fe57e4c-9ad2-4b52-b794-48adef2f6663',
|
||||
}
|
||||
|
||||
client.post.mockResolvedValue({ data })
|
||||
const result = await login(client)(personalNumber)
|
||||
|
||||
expect(result).toEqual({ order: '5fe57e4c-9ad2-4b52-b794-48adef2f6663' })
|
||||
})
|
||||
})
|
||||
describe('#checkStatus', () => {
|
||||
const ticket = { order: '5fe57e4c-9ad2-4b52-b794-48adef2f6663' }
|
||||
|
||||
it('emits PENDING', (done) => {
|
||||
client.get.mockResolvedValue({ data: 'PENDING' })
|
||||
|
||||
const check = checkStatus(client)(ticket)
|
||||
check.on('PENDING', async () => {
|
||||
await check.cancel()
|
||||
done()
|
||||
})
|
||||
}
|
||||
})
|
||||
it('retries on PENDING', (done) => {
|
||||
client.get.mockResolvedValueOnce({ data: 'PENDING' })
|
||||
client.get.mockResolvedValueOnce({ data: 'OK' })
|
||||
|
||||
client.post.mockResolvedValue(response)
|
||||
const result = await login(client)(personalNumber)
|
||||
const check = checkStatus(client)(ticket)
|
||||
check.on('OK', () => {
|
||||
expect(client.get).toHaveBeenCalledTimes(2)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
describe('#getCookie', () => {
|
||||
it('sets cookie as client interceptor', async () => {
|
||||
client.get.mockResolvedValue({
|
||||
headers: {
|
||||
'set-cookie': 'cookie',
|
||||
},
|
||||
})
|
||||
|
||||
expect(result).toEqual({ token: '9462cf77-bde9-4029-bb41-e599f3094613' })
|
||||
const cookie = await getCookie(client)()
|
||||
|
||||
expect(cookie).toEqual('cookie')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
91
lib/login.ts
91
lib/login.ts
|
@ -1,12 +1,87 @@
|
|||
import { Client } from './client'
|
||||
import { EventEmitter } from 'events'
|
||||
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios'
|
||||
import routes from './routes'
|
||||
import { Auth } from './types'
|
||||
import { AuthTicket } from './types'
|
||||
|
||||
export const login = (client: Client) => async (
|
||||
personalNumber: string,
|
||||
): Promise<Auth> => {
|
||||
export const login = (client: AxiosInstance) => async (personalNumber: string): Promise<AuthTicket> => {
|
||||
const url = routes.login(personalNumber)
|
||||
const result = await client.post(url)
|
||||
const { token } = await result.json()
|
||||
return { token }
|
||||
const result = await client.get<AuthTicket>(url)
|
||||
return { order: result.data.order }
|
||||
}
|
||||
|
||||
/*
|
||||
export enum LoginEvent {
|
||||
OK = 'OK',
|
||||
PENDING = 'PENDING',
|
||||
ERROR = 'ERROR',
|
||||
USER_SIGN = 'USER_SIGN',
|
||||
}
|
||||
*/
|
||||
|
||||
export class LoginStatus extends EventEmitter {
|
||||
private url: string
|
||||
|
||||
private client: AxiosInstance
|
||||
|
||||
private cancelled: boolean = false
|
||||
|
||||
constructor(client: AxiosInstance, url: string) {
|
||||
super()
|
||||
this.client = client
|
||||
this.url = url
|
||||
this.check()
|
||||
}
|
||||
|
||||
async check() {
|
||||
const status = await this.client.get<string>(this.url)
|
||||
this.emit(status.data)
|
||||
if (!this.cancelled && status.data !== 'OK' && status.data !== 'ERROR!') {
|
||||
setTimeout(() => this.check(), 1000)
|
||||
}
|
||||
}
|
||||
|
||||
async cancel() {
|
||||
this.cancelled = true
|
||||
}
|
||||
}
|
||||
|
||||
export const checkStatus = (client: AxiosInstance) => (ticket: AuthTicket): LoginStatus => {
|
||||
const url = routes.loginStatus(ticket.order)
|
||||
return new LoginStatus(client, url)
|
||||
}
|
||||
|
||||
const parseCookies = (newCookies: string[]): any => {
|
||||
return newCookies
|
||||
.map((c) => c.split('=')).map(([key, val]) => ({[key]: val}))
|
||||
.reduce((obj1, obj2) => ({...obj1, ...obj2}))
|
||||
}
|
||||
|
||||
export const getCookies = (client: AxiosInstance) => async (url = routes.loginCookie, cookies = {}): Promise<any> => {
|
||||
try {
|
||||
const response = await client.get(url)
|
||||
if (response.headers['set-cookie']) {
|
||||
cookies = {
|
||||
...cookies,
|
||||
...parseCookies(response.headers['set-cookie'])
|
||||
}
|
||||
}
|
||||
return cookies
|
||||
} catch (err) {
|
||||
const { response } = err as AxiosError
|
||||
if (response?.status === 302) {
|
||||
if (response.headers['set-cookie']) {
|
||||
cookies = {
|
||||
...cookies,
|
||||
...parseCookies(response.headers['set-cookie'])
|
||||
}
|
||||
}
|
||||
if (response.headers.location) {
|
||||
return getCookies(client)(response.headers.location, cookies)
|
||||
} else {
|
||||
return cookies
|
||||
}
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
const hosts = {
|
||||
login: 'https://login003.stockholm.se',
|
||||
etjanst: 'https://etjanst.stockholm.se',
|
||||
}
|
||||
|
||||
const routes = {
|
||||
login: (personalNumber: string) => `https://login003.stockholm.se/NECSadcmbid/authenticate/NECSadcmbid?TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvaGVt&initialize=bankid&personalNumber=${personalNumber}&_=${Date.now()}`,
|
||||
login: (personalNumber: string) => `${hosts.login}/NECSadcmbid/authenticate/NECSadcmbid?TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvaGVt&initialize=bankid&personalNumber=${personalNumber}&_=${Date.now()}`,
|
||||
loginStatus: (order: string) => `${hosts.login}/NECSadcmbid/authenticate/NECSadcmbid?TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvaGVt&verifyorder=${order}&_=${Date.now()}`,
|
||||
loginCookie: `${hosts.login}/NECSadcmbid/authenticate/SiteMinderAuthADC?TYPE=33554433&REALMOID=06-42f40edd-0c5b-4dbc-b714-1be1e907f2de&GUID=&SMAUTHREASON=0&METHOD=GET&SMAGENTNAME=IfNE0iMOtzq2TcxFADHylR6rkmFtwzoxRKh5nRMO9NBqIxHrc38jFyt56FASdxk1&TARGET=-SM-HTTPS%3a%2f%2flogin001%2estockholm%2ese%2fNECSadc%2fmbid%2fb64startpage%2ejsp%3fstartpage%3daHR0cHM6Ly9ldGphbnN0LnN0b2NraG9sbS5zZS92YXJkbmFkc2hhdmFyZS9pbmxvZ2dhZDIvR2V0Q2hpbGRyZW4%3d`,
|
||||
children: `${hosts.etjanst}/vardnadshavare/inloggad2/GetChildren`,
|
||||
}
|
||||
|
||||
export default routes
|
||||
|
|
432
lib/types.ts
432
lib/types.ts
|
@ -1,10 +1,5 @@
|
|||
export interface Auth {
|
||||
token?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Auth
|
||||
*/
|
||||
order?: string;
|
||||
export interface AuthTicket {
|
||||
order: string
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,11 +8,11 @@ export interface Auth {
|
|||
* @interface AuthToken
|
||||
*/
|
||||
export interface AuthToken {
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof AuthToken
|
||||
*/
|
||||
token?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof AuthToken
|
||||
*/
|
||||
token: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,41 +20,41 @@ export interface AuthToken {
|
|||
* @interface CalendarItem
|
||||
*/
|
||||
export interface CalendarItem {
|
||||
/**
|
||||
* @type {number}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
id?: number;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
description?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
location?: string;
|
||||
/**
|
||||
* @type {Date}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
startDate?: string;
|
||||
/**
|
||||
* @type {Date}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
endDate?: string;
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
allDay?: boolean;
|
||||
/**
|
||||
* @type {number}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
id?: number;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
description?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
location?: string;
|
||||
/**
|
||||
* @type {Date}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
startDate?: string;
|
||||
/**
|
||||
* @type {Date}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
endDate?: string;
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @memberof CalendarItem
|
||||
*/
|
||||
allDay?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,33 +62,33 @@ export interface CalendarItem {
|
|||
* @interface Child
|
||||
*/
|
||||
export interface Child {
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* <p>Special ID used to access certain subsystems</p>
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
sdsId?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* <p>F - förskola, GR - grundskola?</p>
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
status?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
schoolId?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* <p>Special ID used to access certain subsystems</p>
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
sdsId?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* <p>F - förskola, GR - grundskola?</p>
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
status?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Child
|
||||
*/
|
||||
schoolId?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,26 +96,26 @@ export interface Child {
|
|||
* @interface ChildAll
|
||||
*/
|
||||
export interface ChildAll {
|
||||
/**
|
||||
* @type {Api.Child}
|
||||
* @memberof ChildAll
|
||||
*/
|
||||
child?: Api.Child;
|
||||
/**
|
||||
* @type {Api.NewsItem[]}
|
||||
* @memberof ChildAll
|
||||
*/
|
||||
news?: Api.NewsItem[];
|
||||
/**
|
||||
* @type {Api.CalendarItem[]}
|
||||
* @memberof ChildAll
|
||||
*/
|
||||
calendar?: Api.CalendarItem[];
|
||||
/**
|
||||
* @type {Api.Notification[]}
|
||||
* @memberof ChildAll
|
||||
*/
|
||||
notifications?: Api.Notification[];
|
||||
/**
|
||||
* @type {Child}
|
||||
* @memberof ChildAll
|
||||
*/
|
||||
child?: Child;
|
||||
/**
|
||||
* @type {NewsItem[]}
|
||||
* @memberof ChildAll
|
||||
*/
|
||||
news?: NewsItem[];
|
||||
/**
|
||||
* @type {CalendarItem[]}
|
||||
* @memberof ChildAll
|
||||
*/
|
||||
calendar?: CalendarItem[];
|
||||
/**
|
||||
* @type {Notification[]}
|
||||
* @memberof ChildAll
|
||||
*/
|
||||
notifications?: Notification[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,32 +123,32 @@ export interface ChildAll {
|
|||
* @interface Classmate
|
||||
*/
|
||||
export interface Classmate {
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
sisId?: string;
|
||||
/**
|
||||
* <p>The name of the class of this classmate</p>
|
||||
* @type {string}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
className?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
firstname?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
lastname?: string;
|
||||
/**
|
||||
* @type {Api.Guardian[]}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
guardians?: Api.Guardian[];
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
sisId?: string;
|
||||
/**
|
||||
* <p>The name of the class of this classmate</p>
|
||||
* @type {string}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
className?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
firstname?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
lastname?: string;
|
||||
/**
|
||||
* @type {Guardian[]}
|
||||
* @memberof Classmate
|
||||
*/
|
||||
guardians?: Guardian[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,31 +156,31 @@ export interface Classmate {
|
|||
* @interface Guardian
|
||||
*/
|
||||
export interface Guardian {
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
email?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
firstname?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
lastname?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
mobile?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
address?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
email?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
firstname?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
lastname?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
mobile?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Guardian
|
||||
*/
|
||||
address?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -194,41 +189,41 @@ export interface Guardian {
|
|||
* @interface NewsItem
|
||||
*/
|
||||
export interface NewsItem {
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
header?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
intro?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
body?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
published?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
modified?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
imageUrl?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
header?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
intro?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
body?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
published?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
modified?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof NewsItem
|
||||
*/
|
||||
imageUrl?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,40 +231,45 @@ export interface NewsItem {
|
|||
* @interface Notification
|
||||
*/
|
||||
export interface Notification {
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
sender.name?: string;
|
||||
/**
|
||||
* @type {Date}
|
||||
* @memberof Notification
|
||||
*/
|
||||
dateCreated?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
message?: string;
|
||||
/**
|
||||
* <p>URL with the actual message as a webpage. Needs separate login. TODO: Investigate how to solve this somehow</p>
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
url?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
category?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
messageType?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
sender?: {
|
||||
name?: string;
|
||||
};
|
||||
/**
|
||||
* @type {Date}
|
||||
* @memberof Notification
|
||||
*/
|
||||
dateCreated?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
message?: string;
|
||||
/**
|
||||
* <p>
|
||||
* URL with the actual message as a webpage. Needs separate login.
|
||||
* TODO: Investigate how to solve this somehow
|
||||
* </p>
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
url?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
category?: string;
|
||||
/**
|
||||
* @type {string}
|
||||
* @memberof Notification
|
||||
*/
|
||||
messageType?: string;
|
||||
}
|
||||
|
|
19
package.json
19
package.json
|
@ -9,21 +9,18 @@
|
|||
"private": false,
|
||||
"scripts": {
|
||||
"lint": "eslint '*/**/*.{js,ts}' --quiet --fix",
|
||||
"test": "jest"
|
||||
"test": "jest",
|
||||
"build": "tsc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/preset-env": "^7.12.11",
|
||||
"@babel/preset-typescript": "^7.12.7",
|
||||
"@types/axios": "^0.14.0",
|
||||
"@types/jest": "^26.0.19",
|
||||
"@typescript-eslint/eslint-plugin": "^4.10.0",
|
||||
"@typescript-eslint/parser": "^4.10.0",
|
||||
"babel-jest": "^26.6.3",
|
||||
"eslint": "^7.16.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1",
|
||||
"eslint-config-airbnb-typescript": "^12.0.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"jest": "^26.6.3",
|
||||
"ts-jest": "^26.4.4",
|
||||
"typescript": "^4.1.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.21.0",
|
||||
"events": "^3.2.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
const init = require('./dist').default
|
||||
|
||||
async function run () {
|
||||
try {
|
||||
const api = init()
|
||||
const status = await api.login('197304161511')
|
||||
status.on('PENDING', () => console.log('PENDING'))
|
||||
status.on('USER_SIGN', () => console.log('USER_SIGN'))
|
||||
status.on('ERROR', () => console.error('ERROR'))
|
||||
status.on('OK', () => console.log('OK'))
|
||||
|
||||
api.on('login', async () => {
|
||||
console.log('Logged in')
|
||||
const children = await api.getChildren()
|
||||
console.log(children)
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
|
@ -1 +0,0 @@
|
|||
process.env.NODE_ENV = 'test'
|
|
@ -1,63 +1,13 @@
|
|||
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"lib": ["es6"], /* Specify library files to be included in the compilation. */
|
||||
"allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
"jsx": "react-native", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
// "outDir": "./", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
"noEmit": true, /* Do not emit outputs. */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
"isolatedModules": false, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
"resolveJsonModule": true
|
||||
"target": "ES6",
|
||||
"module": "CommonJS",
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules", "babel.config.js", "metro.config.js", "jest.config.js"
|
||||
]
|
||||
"include": ["lib"],
|
||||
"exclude": ["node_modules", "**/__tests__/*", "**/*.test.ts"]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue