Initial commit
This commit is contained in:
parent
0985c583a7
commit
acf4828bdf
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
presets: [
|
||||
['@babel/preset-env', {targets: {node: 'current'}}],
|
||||
'@babel/preset-typescript',
|
||||
],
|
||||
}
|
|
@ -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'],
|
||||
},
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"hooks": {
|
||||
"pre-commit": "pretty-quick --staged"
|
||||
}
|
||||
}
|
|
@ -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).
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export default function foo(): void {
|
||||
alert('hello')
|
||||
}
|
|
@ -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' })
|
||||
})
|
||||
})
|
|
@ -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 }
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"name": "@skolplattformen/embedded-api",
|
||||
"version": "0.0.0",
|
||||
"description": "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).",
|
||||
"main": "./dist",
|
||||
"repository": "git@github.com:kolplattformen/embedded-api.git",
|
||||
"author": "Johan Öbrink <johan.obrink@gmail.com>",
|
||||
"license": "Apache-2.0",
|
||||
"private": false,
|
||||
"scripts": {
|
||||
"lint": "eslint '*/**/*.{js,ts}' --quiet --fix",
|
||||
"test": "jest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/preset-env": "^7.12.11",
|
||||
"@babel/preset-typescript": "^7.12.7",
|
||||
"@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",
|
||||
"typescript": "^4.1.3"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
process.env.NODE_ENV = 'test'
|
|
@ -0,0 +1,63 @@
|
|||
|
||||
{
|
||||
"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
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules", "babel.config.js", "metro.config.js", "jest.config.js"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue