Giter Club home page Giter Club logo

pdk-driver's Introduction

Prodeskel Driver in Node.JS

An API to make access easier to Prodeskel by providing user-friendly APIs, allowing faster development for system integration.


NOTE: This project is an ESM package, meaning it cannot be require() from CommonJS.

Read here: Pure ESM Package


Before running test...

Generate dev/connection_dump.json and dev/credential.json (or, just modify dev/index.ts which will need those two files to be present). Both files definition can be checked in src/connection.ts.

Will update all unit tests later to read from environment variable instead.

dev/connection_dump.json:

{
  "cookies": "",
  "isLoggedIn": false
}

dev/credential.json:

{
  "username": "myusername",
  "password": "secretKey"
}

To use, just import Driver from src/index.ts. Initialize Driver with credential then use it however you like. Calling login() is optional since it's being handled automatically.


API Overview

TypeDoc documentation: prodeskel-driver-docs.netlify.app

This project consists of 3 components:

  • The driver
  • The connection
  • The library

driver and connection are exposed to end-user. But, the API mainly comes from driver, which is exported by default in the project's entrypoint (index.js).

Driver

Driver is the API of the module. It contains all methods used to read and write data to/from Prodeskel. The usage is very simple, all we need to do is import it then initialize it with credential:

import Driver from 'prodeskel-driver'

const credential = {
  username: 'my-username',
  password: 'my-password',
}

const driver = new Driver(credential)
// then, call driver's method.

After initialization, the driver can be instantly used without needing any more configuration. The driver will handle connection and cookie management in background. All we had to do is calling the method. For example,

const driver = new Driver(credential)
const result = await driver.getDataPenduduk({ page: 1 })
console.log(result)

The driver also supports parallel asynchronous fetching:

const driver = new Driver(credential)
const results = await Promise.all([
  driver.getDataPenduduk({ page: 1 }),
  driver.getDataPenduduk({ page: 2 }),
  driver.getDataPenduduk({ page: 3 }),
])
console.log(results)

Connection

Connection is the session handler of the driver. It manages connection, login process, and cookie. It's actually not needed by end-user except when building a custom driver. Basic usage example:

import { Connection } from 'prodeskel-driver'

const credential = {
  username: 'my-username',
  password: 'my-password',
}

const connection = new Connection({
  useCredential: credential,
})
await connection.login()
console.log(connection.isLoggedIn, connection.cookieJar)

Test

Tests are available in /test. Testing is done using ava.js test runner (command: yarn test). Sometimes, the parallel testing is buggy. In that case, run test individually per test unit.


This project is using:

  • cheerio to parse HTML into jquery-like object to make parsing easier
  • superstruct to validate data with schema
  • ava for unit testing
  • prettier for automatic opinionated code formatter

Feature To-Do

  • Parallel-able async method
  • Allow auto-relogin on expiring session
  • Get data penduduk by page
  • Find data penduduk by query
  • Create data penduduk
  • Update data penduduk
  • Delete data penduduk
  • Dump data penduduk
  • Mass update data penduduk
  • Sinkronisasi data penduduk

Project To-Do

  • Update project to use modern NodeJS (atleast, to any version that natively supports ESM)
  • Updating/upgrading dependencies
  • Fix ava test runner problem
  • Curb unused/redundant dependencies
  • Reducing as much as possible dependency to external package
  • Refactor code to minimize confusion to reader

pdk-driver's People

Contributors

slainless avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.