Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter for larandegruppen/admentum #652

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f54bfe5
feat: create new admentum api hooks
irony Sep 1, 2023
2daa1b5
chore: rename lib until created through nx
irony Sep 1, 2023
e0adb97
feat: first working test-app against login endpoint
irony Sep 8, 2023
6289c43
feat: add init url and start bankId session
irony Sep 8, 2023
58a0ed9
feat: bankId login almost working
irony Sep 14, 2023
bd6a808
feat: bankId flow now works in test app
irony Sep 14, 2023
3b7942a
Added .aider* to .gitignore.
irony Sep 15, 2023
23f81cf
aider: Updated React Native version to 0.67.3 in package.json.
irony Sep 15, 2023
501ec80
wip: fetch children from adentum
schweinryder Sep 15, 2023
65176ea
Merge branch 'feat/larandegruppen' of https://github.com/kolplattform…
schweinryder Sep 15, 2023
8912342
wip: request headers
schweinryder Sep 15, 2023
0ff5fad
fix: try to get callback auth to work
irony Sep 15, 2023
48d8ae2
wip: fetch
schweinryder Sep 15, 2023
76fd23d
Merge branch 'feat/larandegruppen' of https://github.com/kolplattform…
schweinryder Sep 15, 2023
a5ebc0f
fix: remove invalid import
schweinryder Sep 15, 2023
78e045e
fix: dont set session here
irony Sep 18, 2023
bd2ccfc
feat: follow redirects
schweinryder Sep 20, 2023
d75f2ec
Merge branch 'feat/larandegruppen' of https://github.com/kolplattform…
schweinryder Sep 20, 2023
8a1a0d7
wip: redirect
schweinryder Sep 20, 2023
63dc2eb
wip: more or less redirect
schweinryder Sep 22, 2023
3f469de
feat: login and get children
schweinryder Sep 22, 2023
6130fdb
feat: more data
schweinryder Sep 22, 2023
9276db3
wip: fetch more data
schweinryder Oct 6, 2023
c4c52b9
fix: wrong debug
schweinryder Oct 6, 2023
618bdbf
fix: handle errors in login flow correctly
irony Oct 6, 2023
8385d30
fix: url for week data
irony Oct 6, 2023
f1c622e
wip: fix timetable and minor things
schweinryder Oct 6, 2023
53ee3c1
feat: get messages and canvas token
irony Oct 6, 2023
b0764cf
fix: correct name for fetch token
irony Oct 6, 2023
ef5e560
feat: fetch week data
schweinryder Oct 6, 2023
959b17b
Merge branch 'feat/larandegruppen' of https://github.com/kolplattform…
schweinryder Oct 6, 2023
dd0f8f3
feat: parse news data
schweinryder Oct 6, 2023
ab9b3a5
feat: convert newsletter to markdown
irony Oct 6, 2023
7dc5b80
fix: padStart in schedule
irony Oct 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@ xcshareddata
xcuserdata
/.vs
*.hprof
.aider*
100 changes: 50 additions & 50 deletions apps/api-test-app/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,69 @@ const path = require('path')
const fs = require('fs')
const HttpProxyAgent = require('https-proxy-agent')
const agentWrapper = require('./app/agentFetchWrapper')
const initSkolplattformen = require('@skolplattformen/api-skolplattformen').default
const initHjarntorget = require('@skolplattformen/api-hjarntorget').default
const initSkolplattformen =
require('@skolplattformen/api-skolplattformen').default
const initAdmentum = require('@skolplattformen/api-admentum').default

const [, , personalNumber, platform] = process.argv
const isHjarntorget = platform && platform.startsWith('hj')
const init = isHjarntorget ? initHjarntorget : initSkolplattformen;
const isAdmentum = platform && platform.startsWith('ad')
const init = isAdmentum ? initAdmentum : initSkolplattformen

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
const cookieJar = new CookieJar()
let bankIdUsed = false
let bankIdUsed = true
const recordFolder = `${__dirname}/record`

async function run() {
const agent = new HttpProxyAgent('http://localhost:8080')
const agentEnabledFetch = agentWrapper(nodeFetch, agent)
const now = DateTime.local()
const [year, week] = now.toISOWeekDate().split('-')
const isoWeek = week.replace('W','')

const fetch = fetchCookie(agentEnabledFetch, cookieJar)
async function run() {
const fetch = fetchCookie(nodeFetch, cookieJar)

try {
const api = init(fetch, cookieJar, { record })

api.on('login', async () => {
console.log('Logged in')

if (bankIdUsed) {
const sessionCookie = getSessionCookieFromCookieJar()
ensureDirectoryExistence(recordFolder)
await writeFile(
`${recordFolder}/latestSessionCookie.txt`,
JSON.stringify(sessionCookie)
)
console.log(
`Session cookie saved to file ${recordFolder}/latesSessionCookie.txt`
)
}
console.log('user') //-
const cookies = cookieJar.toJSON()

console.log('cookies', cookies)
const user = await api.getUser()
console.log(user)

console.log('children')
const children = await api.getChildren()
console.log(children)
/*


try {
console.log('timetable')
const timetable = await api.getTimetable(
children[0],
isoWeek,
year,
'sv'
)
console.log(inspect(timetable, false, 1000, true))
} catch (error) {
console.error(error)
}

console.log('menu')
const menu = await api.getMenu(children[0])
console.log(menu)


console.log('calendar')
const calendar = await api.getCalendar(children[0])
console.log(calendar)

console.log('classmates')

console.log('news')
const news = await api.getNews(children[0])
/*
/*console.log('classmates')
const classmates = await api.getClassmates(children[0])
console.log(classmates)

Expand All @@ -85,23 +100,6 @@ async function run() {
console.error(error)
}

try {
console.log('timetable')
const timetable = await api.getTimetable(
skola24children[0],
15,
2021,
'sv'
)
console.log(inspect(timetable, false, 1000, true))
} catch (error) {
console.error(error)
}

/*
console.log('news')
const news = await api.getNews(children[0])
*/
/* console.log('news details')
const newsItems = await Promise.all(
news.map((newsItem) =>
Expand All @@ -111,9 +109,7 @@ async function run() {
)
console.log(newsItems) */

/* console.log('menu')
const menu = await api.getMenu(children[0])
console.log(menu) */


// console.log('notifications')
// const notifications = await api.getNotifications(children[0])
Expand Down Expand Up @@ -141,8 +137,10 @@ async function Login(api) {
console.log('Attempt to use saved session cookie to login')
const rawContent = await readFile(`${recordFolder}/latestSessionCookie.txt`)
const sessionCookies = JSON.parse(rawContent)
await api.setSessionCookie(`${sessionCookies[0].key}=${sessionCookies[0].value}`)

await api.setSessionCookie(
`${sessionCookies[0].key}=${sessionCookies[0].value}`
)

useBankId = false
console.log('Login with old cookie succeeded')
} catch (error) {
Expand Down Expand Up @@ -180,18 +178,20 @@ function ensureDirectoryExistence(filePath) {
fs.mkdirSync(dirname)
}


function getSessionCookieFromCookieJar() {
const cookieUrl = isHjarntorget ? 'https://hjarntorget.goteborg.se' : 'https://etjanst.stockholm.se'
const cookieUrl = isAdmentum
? 'https://admentum.se'
: 'https://etjanst.stockholm.se'
const cookies = cookieJar.getCookiesSync(cookieUrl)
const sessionCookieKey = isHjarntorget ? 'JSESSIONID' : 'SMSESSION'
return cookies.find(c => c.key === sessionCookieKey)
const sessionCookieKey = isAdmentum ? 'JSESSIONID' : 'SMSESSION'
return cookies.find((c) => c.key === sessionCookieKey)
}

const record = async (info, data) => {
const name = info.error ? `${info.name}_error` : info.name
const filename = `${recordFolder}/${name}.json`
ensureDirectoryExistence(filename)
console.log('recording session', filename)
const content = {
url: info.url,
headers: info.headers,
Expand Down
9 changes: 9 additions & 0 deletions apps/skolplattformen-app/data/schoolPlatforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import CookieManager from '@react-native-cookies/cookies'
import initHjarntorget, {
features as featuresHjarntorget,
} from '@skolplattformen/api-hjarntorget'
import initAdmentum, {
features as featuresAdmentum,
} from '@skolplattformen/api-admentum'
import initSkolplattformen, {
features as featuresSkolPlattformen,
} from '@skolplattformen/api-skolplattformen'
Expand All @@ -19,4 +22,10 @@ export const schoolPlatforms = [
api: initHjarntorget(fetch as any, CookieManager),
features: featuresHjarntorget,
},
{
id: 'larandegruppen-admentum',
displayName: 'Lärandegruppen (Admentum)',
api: initAdmentum(fetch as any, CookieManager),
features: featuresAdmentum,
},
]
2 changes: 1 addition & 1 deletion apps/skolplattformen-app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: f4a92b32cc4938e15ad7ccfefe9898548670abed

COCOAPODS: 1.11.2
COCOAPODS: 1.12.1
4 changes: 2 additions & 2 deletions apps/skolplattformen-app/ios/app.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 i386";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -1042,7 +1042,7 @@
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 i386";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = i386;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand Down
1 change: 1 addition & 0 deletions apps/skolplattformen-app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"implicitDependencies": [
"api-skolplattformen",
"api-hjarntorget",
"api-admentum",
"api",
"hooks",
"curriculum"
Expand Down
6 changes: 6 additions & 0 deletions libs/api-admentum/.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',
],
}
22 changes: 22 additions & 0 deletions libs/api-admentum/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"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"
}
}
]
}
10 changes: 10 additions & 0 deletions libs/api-admentum/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": false
}
Loading
Loading