fix: 🐛 Fixes TS config + lint etc
This commit is contained in:
parent
e2e1ff8278
commit
46632691bf
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
|
||||||
|
"ignorePatterns": ["!**/*", "public", ".cache", "node_modules"],
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
||||||
|
"rules": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["*.ts", "*.tsx"],
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/ban-ts-comment": "off"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["*.js", "*.jsx"],
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/no-var-requires": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
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.eslint.json'],
|
|
||||||
},
|
|
||||||
extends: ['airbnb-typescript/base', 'prettier'],
|
|
||||||
plugins: ['prettier'],
|
|
||||||
ignorePatterns: ['*.test.ts'],
|
|
||||||
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'],
|
|
||||||
'max-len': ['error', { code: 120, ignoreUrls: true }],
|
|
||||||
'import/prefer-default-export': 0,
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,9 +1,6 @@
|
||||||
import init from './'
|
|
||||||
import { ApiHjarntorget } from './apiHjarntorget'
|
import { ApiHjarntorget } from './apiHjarntorget'
|
||||||
import { Fetcher } from '../../api/lib/fetcher'
|
|
||||||
import { checkStatus } from './loginStatus'
|
import { checkStatus } from './loginStatus'
|
||||||
|
import { wrapToughCookie } from '@skolplattformen/api'
|
||||||
import { wrapToughCookie } from '../../api/lib/cookies'
|
|
||||||
import { CookieJar } from 'tough-cookie'
|
import { CookieJar } from 'tough-cookie'
|
||||||
|
|
||||||
const setupSuccessfullLoginInitiation = (fetcherMock: jest.Mock) => {
|
const setupSuccessfullLoginInitiation = (fetcherMock: jest.Mock) => {
|
||||||
|
@ -83,7 +80,7 @@ describe('api', () => {
|
||||||
fetcherMock = fetcher as jest.Mock
|
fetcherMock = fetcher as jest.Mock
|
||||||
|
|
||||||
const cookieManager = wrapToughCookie(new CookieJar())
|
const cookieManager = wrapToughCookie(new CookieJar())
|
||||||
cookieManager.clearAll
|
cookieManager.clearAll();
|
||||||
api = new ApiHjarntorget(jest.fn(), cookieManager)
|
api = new ApiHjarntorget(jest.fn(), cookieManager)
|
||||||
api.replaceFetcher(fetcher)
|
api.replaceFetcher(fetcher)
|
||||||
})
|
})
|
||||||
|
@ -210,6 +207,7 @@ describe('api', () => {
|
||||||
expect(api.isLoggedIn).toBe(false)
|
expect(api.isLoggedIn).toBe(false)
|
||||||
})
|
})
|
||||||
it('forgets personalNumber', async () => {
|
it('forgets personalNumber', async () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(api as any).personalNumber = 'my personal number'
|
(api as any).personalNumber = 'my personal number'
|
||||||
api.isLoggedIn = true
|
api.isLoggedIn = true
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
import { DateTime, FixedOffsetZone } from 'luxon'
|
import { DateTime, FixedOffsetZone } from 'luxon'
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
import * as html from 'node-html-parser'
|
import * as html from 'node-html-parser'
|
||||||
import { decode } from 'he'
|
import { decode } from 'he'
|
||||||
import wrap, { Fetcher, FetcherOptions } from '../../api/lib/fetcher'
|
import { toMarkdown, Api, URLSearchParams, LoginStatusChecker, CalendarItem,
|
||||||
import {
|
|
||||||
CalendarItem,
|
|
||||||
Classmate,
|
Classmate,
|
||||||
CookieManager,
|
CookieManager,
|
||||||
EtjanstChild,
|
EtjanstChild,
|
||||||
|
@ -15,12 +14,11 @@ import {
|
||||||
ScheduleItem,
|
ScheduleItem,
|
||||||
Skola24Child,
|
Skola24Child,
|
||||||
TimetableEntry,
|
TimetableEntry,
|
||||||
User
|
User,
|
||||||
} from "../../api/lib/types"
|
Fetcher,
|
||||||
import { LoginStatusChecker } from '../../api/lib/loginStatus'
|
FetcherOptions,
|
||||||
import { URLSearchParams } from '../../api/lib/URLSearchParams'
|
wrap
|
||||||
import { Api } from '../../api/lib/api'
|
} from '@skolplattformen/api'
|
||||||
import { toMarkdown } from '../../api/lib/parseHtml'
|
|
||||||
import { checkStatus } from './loginStatus'
|
import { checkStatus } from './loginStatus'
|
||||||
import { extractMvghostRequestBody, parseCalendarItem } from './parse/parsers'
|
import { extractMvghostRequestBody, parseCalendarItem } from './parse/parsers'
|
||||||
import {
|
import {
|
||||||
|
@ -91,7 +89,8 @@ export class ApiHjarntorget extends EventEmitter implements Api {
|
||||||
options?: FetcherOptions
|
options?: FetcherOptions
|
||||||
) {
|
) {
|
||||||
super()
|
super()
|
||||||
this.realFetcher = this.fetch = wrap(fetch, options)
|
this.fetch = wrap(fetch, options);
|
||||||
|
this.realFetcher = this.fetch;
|
||||||
this.cookieManager = cookieManager
|
this.cookieManager = cookieManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,19 @@
|
||||||
import { Api } from '../../api/lib/api'
|
import { ApiHjarntorget } from './apiHjarntorget'
|
||||||
import { FetcherOptions } from '../../api/lib/fetcher'
|
import { Api, FetcherOptions, Fetch, RNCookieManager,
|
||||||
import { Fetch } from '../../api/lib/types'
|
|
||||||
import {
|
|
||||||
RNCookieManager,
|
|
||||||
ToughCookieJar,
|
ToughCookieJar,
|
||||||
wrapReactNativeCookieManager,
|
wrapReactNativeCookieManager,
|
||||||
wrapToughCookie,
|
wrapToughCookie } from '@skolplattformen/api'
|
||||||
} from '../../api/lib/cookies'
|
|
||||||
import { ApiHjarntorget } from './apiHjarntorget'
|
|
||||||
|
|
||||||
export { Api, FetcherOptions }
|
|
||||||
export * from '../../api/lib/types'
|
|
||||||
export { LoginStatusChecker } from '../../api/lib/loginStatus'
|
|
||||||
|
|
||||||
const init = (
|
const init = (
|
||||||
fetch: Fetch,
|
fetchImpl: Fetch,
|
||||||
cookieManagerImpl: RNCookieManager | ToughCookieJar,
|
cookieManagerImpl: any,
|
||||||
options?: FetcherOptions
|
options?: FetcherOptions
|
||||||
): Api => {
|
): Api => {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
const cookieManager = ((cookieManagerImpl as RNCookieManager).get)
|
const cookieManager = ((cookieManagerImpl as RNCookieManager).get)
|
||||||
? wrapReactNativeCookieManager(cookieManagerImpl as RNCookieManager)
|
? wrapReactNativeCookieManager(cookieManagerImpl as RNCookieManager)
|
||||||
: wrapToughCookie(cookieManagerImpl as ToughCookieJar)
|
: wrapToughCookie(cookieManagerImpl as ToughCookieJar)
|
||||||
return new ApiHjarntorget(fetch, cookieManager, options)
|
return new ApiHjarntorget(fetchImpl, cookieManager, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default init
|
export default init
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
import { Fetcher } from '../../api/lib/fetcher'
|
import { LoginStatusChecker, Fetcher} from '@skolplattformen/api'
|
||||||
import { LoginStatusChecker } from '../../api/lib/loginStatus'
|
|
||||||
import {
|
import {
|
||||||
extractAuthGbgLoginRequestBody,
|
extractAuthGbgLoginRequestBody,
|
||||||
extractHjarntorgetSAMLLogin
|
extractHjarntorgetSAMLLogin
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"**/__tests__/*",
|
"**/__tests__/*",
|
||||||
"**/__mocks__/*",
|
"**/__mocks__/*"
|
||||||
"**/*.test.ts"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import init from './'
|
import init from './'
|
||||||
import { ApiSkolplattformen } from './api'
|
import { ApiSkolplattformen } from './api'
|
||||||
import { Fetch, Headers, Response } from '../../api/lib/types'
|
import { Fetch, Headers, Response } from '@skolplattformen/api'
|
||||||
import CookieManager from '@react-native-cookies/cookies'
|
import CookieManager from '@react-native-cookies/cookies'
|
||||||
|
|
||||||
describe('api', () => {
|
describe('api', () => {
|
||||||
|
@ -110,6 +110,7 @@ describe('api', () => {
|
||||||
const personalNumber = 'my personal number'
|
const personalNumber = 'my personal number'
|
||||||
try {
|
try {
|
||||||
await api.login(personalNumber)
|
await api.login(personalNumber)
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
expect(error.message).toEqual(expect.stringContaining('Server Error'))
|
expect(error.message).toEqual(expect.stringContaining('Server Error'))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { EventEmitter } from 'events'
|
||||||
import { decode } from 'he'
|
import { decode } from 'he'
|
||||||
import { DateTime } from 'luxon'
|
import { DateTime } from 'luxon'
|
||||||
import * as html from 'node-html-parser'
|
import * as html from 'node-html-parser'
|
||||||
import { LoginStatusChecker } from '../../api/lib/loginStatus'
|
import { LoginStatusChecker, FetcherOptions, Fetcher, wrap } from '@skolplattformen/api'
|
||||||
import {
|
import {
|
||||||
AuthTicket,
|
AuthTicket,
|
||||||
CalendarItem,
|
CalendarItem,
|
||||||
|
@ -20,13 +20,12 @@ import {
|
||||||
TimetableEntry,
|
TimetableEntry,
|
||||||
User,
|
User,
|
||||||
Response
|
Response
|
||||||
} from '../../api/lib/types'
|
} from '@skolplattformen/api'
|
||||||
import * as routes from './routes'
|
import * as routes from './routes'
|
||||||
import * as parse from './parse/index'
|
import * as parse from './parse/index'
|
||||||
import wrap, { Fetcher, FetcherOptions } from '../../api/lib/fetcher'
|
|
||||||
import * as fake from './fakeData'
|
import * as fake from './fakeData'
|
||||||
import { checkStatus } from './loginStatusChecker'
|
import { checkStatus } from './loginStatusChecker'
|
||||||
import { Api } from '../../api/lib/api'
|
import { Api } from '@skolplattformen/api'
|
||||||
import { Language } from '@skolplattformen/curriculum'
|
import { Language } from '@skolplattformen/curriculum'
|
||||||
|
|
||||||
const fakeResponse = <T>(data: T): Promise<T> =>
|
const fakeResponse = <T>(data: T): Promise<T> =>
|
||||||
|
@ -55,6 +54,7 @@ export class ApiSkolplattformen extends EventEmitter implements Api {
|
||||||
|
|
||||||
private personalNumber?: string
|
private personalNumber?: string
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
private headers: any
|
private headers: any
|
||||||
|
|
||||||
private cookieManager: CookieManager
|
private cookieManager: CookieManager
|
||||||
|
@ -199,6 +199,7 @@ export class ApiSkolplattformen extends EventEmitter implements Api {
|
||||||
this.emit('login')
|
this.emit('login')
|
||||||
}, 50)
|
}, 50)
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const emitter: any = new EventEmitter()
|
const emitter: any = new EventEmitter()
|
||||||
emitter.token = 'fake'
|
emitter.token = 'fake'
|
||||||
return emitter
|
return emitter
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
Skola24Child,
|
Skola24Child,
|
||||||
TimetableEntry,
|
TimetableEntry,
|
||||||
User,
|
User,
|
||||||
} from '../../api/lib/types'
|
} from '@skolplattformen/api';
|
||||||
|
|
||||||
const data: any = {
|
const data: any = {
|
||||||
'39b59e-bf4b9f-f68ac25321-977218-bf0': {
|
'39b59e-bf4b9f-f68ac25321-977218-bf0': {
|
||||||
|
|
|
@ -1,16 +1,8 @@
|
||||||
import { ApiSkolplattformen } from './api'
|
import { ApiSkolplattformen } from './api'
|
||||||
import { Api } from '../../api/lib/api'
|
import { Api, FetcherOptions, Fetch, RNCookieManager,
|
||||||
import { FetcherOptions } from '../../api/lib/fetcher'
|
|
||||||
import { Fetch } from '../../api/lib/types'
|
|
||||||
import {
|
|
||||||
RNCookieManager,
|
|
||||||
ToughCookieJar,
|
ToughCookieJar,
|
||||||
wrapReactNativeCookieManager,
|
wrapReactNativeCookieManager,
|
||||||
wrapToughCookie,
|
wrapToughCookie } from '@skolplattformen/api'
|
||||||
} from '../../api/lib/cookies'
|
|
||||||
|
|
||||||
export * from '../../api/lib/types'
|
|
||||||
export { LoginStatusChecker } from '../../api/lib/loginStatus'
|
|
||||||
|
|
||||||
const init = (
|
const init = (
|
||||||
fetchImpl: Fetch,
|
fetchImpl: Fetch,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
import { loginStatus } from './routes'
|
import { loginStatus } from './routes'
|
||||||
import { Fetcher } from '../../api/lib/fetcher'
|
import { Fetcher, AuthTicket } from '@skolplattformen/api'
|
||||||
import { AuthTicket } from '../..//api/lib/types'
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
export enum LoginEvent {
|
export enum LoginEvent {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { loginStatus } from './routes';
|
import { loginStatus } from './routes';
|
||||||
import { AuthTicket } from '../../api/lib/types';
|
import { AuthTicket, Fetcher, LoginStatusChecker } from '@skolplattformen/api';
|
||||||
import { Fetcher } from '../../api/lib/fetcher';
|
|
||||||
import { LoginStatusChecker } from '.';
|
|
||||||
|
|
||||||
export class Checker extends EventEmitter {
|
export class Checker extends EventEmitter {
|
||||||
public token: string;
|
public token: string;
|
||||||
|
@ -11,7 +9,7 @@ export class Checker extends EventEmitter {
|
||||||
|
|
||||||
private url: string;
|
private url: string;
|
||||||
|
|
||||||
private cancelled: boolean = false;
|
private cancelled = false;
|
||||||
|
|
||||||
constructor(fetcher: Fetcher, ticket: AuthTicket) {
|
constructor(fetcher: Fetcher, ticket: AuthTicket) {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -16,6 +16,5 @@
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"**/__tests__/*",
|
"**/__tests__/*",
|
||||||
"**/__mocks__/*",
|
"**/__mocks__/*",
|
||||||
"**/*.test.ts"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
import wrap from './fetcher'
|
||||||
|
|
||||||
|
export { toMarkdown } from './parseHtml'
|
||||||
|
export * from './types'
|
||||||
|
export { LoginStatusChecker } from './loginStatus'
|
||||||
|
export { Api } from './api'
|
||||||
|
export { FetcherOptions, Fetcher } from './fetcher'
|
||||||
|
export {
|
||||||
|
RNCookieManager,
|
||||||
|
ToughCookieJar,
|
||||||
|
wrapReactNativeCookieManager,
|
||||||
|
wrapToughCookie,
|
||||||
|
} from './cookies'
|
||||||
|
export { URLSearchParams } from './URLSearchParams'
|
||||||
|
|
||||||
|
export { wrap };
|
|
@ -17,6 +17,7 @@ export interface CookieManager {
|
||||||
setCookieString: (cookieString: string, url: string) => Promise<void>
|
setCookieString: (cookieString: string, url: string) => Promise<void>
|
||||||
getCookieString: (url: string) => Promise<string>
|
getCookieString: (url: string) => Promise<string>
|
||||||
clearAll: () => Promise<void>
|
clearAll: () => Promise<void>
|
||||||
|
removeAllCookies?: () => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RequestInit {
|
export interface RequestInit {
|
||||||
|
|
|
@ -14,6 +14,9 @@
|
||||||
"skipDefaultLibCheck": true,
|
"skipDefaultLibCheck": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"@skolplattformen/api": [
|
||||||
|
"libs/api/lib/index.ts"
|
||||||
|
],
|
||||||
"@skolplattformen/api-skolplattformen": [
|
"@skolplattformen/api-skolplattformen": [
|
||||||
"libs/api-skolplattformen/lib/index.ts"
|
"libs/api-skolplattformen/lib/index.ts"
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue