Catalog npm
Back to packageRELEASE DETAILS

1.1.1

npm

@01-edu/api

## Packages

Published17 Mar 2022
Direct dependencies2
Transitive dependenciesNot calculated

README

Current package documentation

01-API

Packages

Read-only-access API

  • Install
$ npm i @01-edu/api

Instructions

This package allows users to create a read only access to the schools database (keep in mind that this access will only be provided for admins).

  • How to get an access token from gitea?

To get an access token from gitea, you must go to user/settings/application then Generate New Token (https://DOMAIN/user/settings/applications).

  1. Go user settings on gitea.

instructions

  1. Then in application you can create the token by inserting a name for this token then it will be generated.

instructions

Or you can use curl and send a request to gitea:

$ curl -X 'POST' 'https://someone:123456@git.dev.01-edu.org/api/v1/users/someone/tokens' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"name": "access_token"}'

output

{"id":4,"name":"access_token","sha1":"592cfb612d027eeb45359d837a93b4e22b5e1","token_last_eight":"e22bb5e1"}
  • What can you query?

Querying information is depended on the users role. You can see all possible tables that this role can query here

  • How to query the information? Where to find examples?

You can take a look into the documentation here.


Usage

This package contains the following exported functions:

  • createClient
  • requestToken
  • decode

createClient

This function allows the application to init a client. This client will :

  • generate a new read only token saving it in storage (global state)
  • initialize a refresh loop, where it will refresh the read only token whenever the token expires.

Returns the storage and a function run.
The run function allows the application to query the database. The storage contains a set of functions that allows the application to access the local storage (where the token is saved)

example:

const domain = 'dev.01-edu.org'
// access_token is the token provided by gitea
const access_token = '427faa391a0d73a68b69d4d3b65796fd798e9156'

const client = await createClient({
  domain,
  access_token,
})

client.run('query {user{id, login}}').then(console.log)
console.log(client.storage.get('hasura-jwt-token'))

output:

{
  user: [
    { id: 1, login: '01-edu' },
    { id: 6, login: 'Joao' }
    { id: 7, login: 'Someone' },
    { id: 8, login: 'Lee' },
  ]
}
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2IiwiaWF0IjoxN1MzY2LCJpcCI6IjE3Mi4xOC4wLjEsIDE3Mi4xOC4wLjMiLCJleHAiOjE2MjkpbXMiOnsieC1oYXN1cmEtYWxsb3dlZC1yb2xlcyI6WyJ1c2VyIiwiYWRtaW5fcmVhZF9vbmx5Il0sI1kWx0LXJvbGUiOiJhZG1pbl9yZWFkX29ubHkiLCJ4LWhhc3VyYS11c2VyLWlkIjoiNiIsIngtaGFzdXJhLXRva2VuLWlkIjoiZjgzZmM2YTItZWFhNC00NDVmLTgyNmYtYTg1NTgzZjA1NWY3In19.HObIGivW31TOqFNlzu6VY7ACuTC5x0numm6-hOKp0

requestToken

This allows application to generate a new token without the client being initialized.

example:

requestToken({ domain, access_token }).then(console.log)

output:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2IiwiaWF0IjoxNjI4Nzg4OTk1LCJpcCI6IjE3Mi4xOC4wLjEsIDE3Mi4xOC4wLjMiLCJleHAiOjE2MjkyMjA5OTUsImh0dOi8vaGFzdXJhLmlvL2p3dC9jbGFpbXMiOnsieC1oYXN1cmEtYWxsb3dlZC1yb2xlcyI6WyJ1c2VyIiwiYyZWFkX29ubHkiLCJ4LWhhc3VyYS11c2VyLWlkIjoiNiIsIngtaGFzdXJhLXRva2VuLWlkIjoiNTM5NzBkZGItMmIzNi00OTFiLTgwMDMtOTRhZTExMDU0N2U3In19.p6HtlfClZUbLwgbwx8JJs_eSPzGOMEvC0uDDsXtA
{
  sub: '6',
  iat: 1628788995,
  ip: '172.18.0.1, 172.18.0.3',
  exp: 1629220995,
  'https://hasura.io/jwt/claims': {
    'x-hasura-allowed-roles': [ 'user', 'admin_read_only' ],
    'x-hasura-campuses': '{}',
    'x-hasura-default-role': 'admin_read_only',
    'x-hasura-user-id': '6',
    'x-hasura-token-id': '53970dd-2b36-491b-800-94ae1105477'
  }
}

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
https
Environment
{
  "local_name": "https",
  "alias": false,
  "peer_metadata": null
}
^1.0.0runtime
form-data
Environment
{
  "local_name": "form-data",
  "alias": false,
  "peer_metadata": null
}
^4.0.0runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "8c93f8c7dbac4c16773e9326ec585f7f27cf5c62",
  "tarball": "https://registry.npmjs.org/@01-edu/api/-/api-1.1.1.tgz",
  "fileCount": 7,
  "integrity": "sha512-/gwpmLV0sQhg03nIFhYlLi9u4+BVqehoYXXalv+W+nPfCj4a/Gul4XUK6OU38sN0eY1Xw77XZRiW+LJwZ6qseg==",
  "signatures": [
    {
      "sig": "MEUCIBHrDLa4Z7qkEVulivJOPaidSdorV6gOLIEN7mVzxsI1AiEAokCZsoz/ss4fe4b7sa8u3PIiLdjSPlcALXLbTzAfQp4=",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 42962,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiM2qVACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpOPBAAhrRPO45OYjZBabc9YGpao918WpKhxNs5NSMR4FLkHmnAGvHk\r\nvikGrLM/NVSP69OOrfY0aIGLAc+d3KXX5zQlI1FfZvPqUwEyyWTy9sX2FuMv\r\nOfT4TuAuoQkbPN5LtoMEQa06BR4gWcExy1gR/3zNZGK3y9gwk/dMp5N2aITJ\r\nibXHlCnNNVUebSzflZzPaIAAZ7VjklwoDiwma+KZgGtXmegI3phviuSjh3sP\r\n6SHn+FkX6D6pDR36oMBIhC5zqbh2LpAoNti8ug+o4SC96c824z/2aKT0Z+IK\r\nrYUYBnbYoqmnSu9bsAzXvkk7EFrFE2PRVdfBaogdOOrVS2LPMWa9rq2wJYU4\r\nLbwUSGZS00/gE6gHPw7OUwj7zCj3R+Nwj/Ur7KnGBOi70kTRZYMWwNpF6Nwo\r\nYpmHIMAGAjxGVq6xX5iqCoTY6OLXPxRboicDt2rJe3pc18QVndp7M5Vhnp+u\r\nFzAi101XLrzyey0sUpyOlRV3XCo+54oGRfYARD2u5Em4Qzzfvi28oltI0X8R\r\nLyotc6Wn+3c5IThrSf9TjUbAstd7BvLZl/ZTbJo4lsKI8ZfK9SuTRu9LIASu\r\nO2gghDG7YXyjnr2Fw+N3GHi9AhZynYgIZHqCo0DeJKFkuzWPEa7LlDIEkRcI\r\n+eyVHATQvj0ez9qFCUWv/kvfqqLSSE9efwA=\r\n=JFpd\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
leedasilva/01-edu-api

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:54 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:75f4c8008f486331eca5f80b02c2a9160b83148ab1b472e26e355dcf0b03687d

Other collected versions

1.1.018 Aug1.0.019 JulView all collected versions →