Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanObrink committed Dec 19, 2020
1 parent 0985c58 commit acf4828
Show file tree
Hide file tree
Showing 15 changed files with 5,688 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
}
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
project: ['./tsconfig.json']
},
extends: [
'airbnb-typescript/base',
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
// '@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/semi': [2, 'never'],
},
}
5 changes: 5 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "pretty-quick --staged"
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# embedded-api

Since the proxy was blocked (and also deemed a bad idea by some), this is a reboot of the API running in process in the app(s).
22 changes: 22 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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/'],
transform: {
'^.+\\.ts$': 'babel-jest',
},
}
12 changes: 12 additions & 0 deletions lib/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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)
}
3 changes: 3 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function foo(): void {
alert('hello')
}
26 changes: 26 additions & 0 deletions lib/login.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Client } from './client'
import { login } from './login'
import routes from './routes'

describe('login', () => {
let client: jest.Mocked<Client>
beforeEach(() => {
client = {
post: jest.fn(),
}
})
it('returns the correct result', async () => {
const personalNumber = 'my personal number'
const response = {
json: async () => ({
token: '9462cf77-bde9-4029-bb41-e599f3094613',
order: '5fe57e4c-9ad2-4b52-b794-48adef2f6663',
})
}

client.post.mockResolvedValue(response)
const result = await login(client)(personalNumber)

expect(result).toEqual({ token: '9462cf77-bde9-4029-bb41-e599f3094613' })
})
})
12 changes: 12 additions & 0 deletions lib/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Client } from './client'
import routes from './routes'
import { Auth } from './types'

export const login = (client: Client) => async (
personalNumber: string,
): Promise<Auth> => {
const url = routes.login(personalNumber)
const result = await client.post(url)
const { token } = await result.json()
return { token }
}
5 changes: 5 additions & 0 deletions lib/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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()}`,
}

export default routes
275 changes: 275 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
export interface Auth {
token?: string;
/**
* @type {string}
* @memberof Auth
*/
order?: string;
}

/**
* <p>A JWT token that should be used for authorizing requests</p>
* @export
* @interface AuthToken
*/
export interface AuthToken {
/**
* @type {string}
* @memberof AuthToken
*/
token?: string;
}

/**
* @export
* @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;
}

/**
* @export
* @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;
}

/**
* @export
* @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[];
}

/**
* @export
* @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[];
}

/**
* @export
* @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;
}

/**
* <p>A news item from the school, for example a weekly news letter</p>
* @export
* @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;
}

/**
* @export
* @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;
}
Loading

0 comments on commit acf4828

Please sign in to comment.