npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@skolplattformen/embedded-api

v5.4.0

Published

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).

Downloads

108

Readme

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).

Installing

npm i -S @skolplattformen/embedded-api or yarn add @skolplattformen/embedded-api

Calling

Import and init

Since fetch and cookies behave distinctly different in node, react-native and the browser, the concrete implementation of fetch and cookie handler must be injected.

react-native

import init from '@skolplattformen/embedded-api'
import CookieManager from '@react-native-community/cookies'

const api = init(fetch, () => CookieManager.clearAll())

node

import init from '@skolplattformen/embedded-api'
import nodeFetch from 'node-fetch'
import fetchCookie from 'fetch-cookie/node-fetch'
import { CookieJar } from 'tough-cookie'

const cookieJar = new CookieJar()
const fetch = fetchCookie(nodeFetch, cookieJar)

const api = init(fetch, cookieJar)

Login / logout

api.on('login', async () => {
  // do stuff
  console.log(api.isLoggedIn) // true
  await api.logout()
})
api.on('logout', () => {
  // handle logout
  console.log(api.isLoggedIn) // false
}

const loginStatus = await api.login('YYYYMMDDXXXX')
window.open(
  `https://app.bankid.com/?autostarttoken=${loginStatus.token}&redirect=null`
)

loginStatus.on('PENDING', () => console.log('BankID app not yet opened'))
loginStatus.on('USER_SIGN', () => console.log('BankID app is open'))
loginStatus.on('ERROR', () => console.log('Something went wrong'))
loginStatus.on('OK', () =>
  console.log('BankID sign successful. Session will be established.')
)

Loading data

// Get current user
const user = await api.getUser()

// List children from Etjanster
const children = await api.getChildren()

// Get school calendar
const calendar = await api.getCalendar(children[0])

// Get classmates - disabled for reasons
// const classmates = await api.getClassmates(children[0])

// Get student's personal schedule
import { DateTime } from 'luxon'

const from = DateTime.local()
const to = DateTime.local().plus({ week: 1 })
const schedule = await api.getSchedule(children[0], from, to)

// Get news
const news = await api.getNews(children[0])

// Get news details
const newsDetails = await api.getNewsDetails(children[0], news[0])

// Get menu
const menu = await api.getMenu(children[0])

// Get notifications
const notifications = await api.getNotifications(children[0])

// Get list of children from Skola24 (because of course it's different *DERP*)
const skola24Children = await getSkola24Children()

// Get timetable
const weekNumber = 15
const year = 2021
const timetable = await api.getTimetable(skola24Children[0], weekNumber, year)

Setting session cookie

It is possible to resurrect a logged in session by manually setting the session cookie.

const sessionCookie = 'some value'

api.setSessionCookie(sessionCookie) // will trigger `on('login')` event and set `.isLoggedIn = true`

Fake user

Login with personal number 12121212121212, 201212121212 or 1212121212 and api will be put into fake mode. Static data will be returned and no calls to backend will be made.

The LoginStatusChecker returned by the login method will have .token set to 'fake'.

Try it out

  1. Clone and enter repo: git clone [email protected]:kolplattformen/embedded-api.git && cd embedded-api
  2. Install dependencies: yarn
  3. Build package: yarn build
  4. Run example: node run [your personal number]
  5. Sign in with mobile BankID