New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sbtech-general-api-client

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sbtech-general-api-client

General api client for all SBTech APIs

latest
npmnpm
Version
0.1.10
Version published
Maintainers
1
Created
Source

SBTech general API client contains tools which make communicating with the SBTech API's easier.

It is a base package for all SBTech API clients, you can use it to implement more specific API client (e.q. SportsData API, Login API, Betslip API and etc).

It contains:

  • customized http client named sbtFetch (wrapper on native browser fetch)
  • token service

sbtFetch extends functionality of native fetch by next features:

  • attach JWT token to each request
  • renew JWT token by timer
  • renew JWT token and retry request if response contains error "token expired"

Installation

npm install --save sbtech-general-api-client

Configure token service

Package support two scenarios to configure token service:

  • It can be auto configured if it running on the same page with widget-platform. It means that page has global variable SBTech with platform configuration.
  • If API client is used without widget-platform it can be configured manually by a consumer of API client.
import {tokenService} from 'sbtech-general-api-client'
let tokenConfig = {
    tokenRenewUrl: 'example.com/token/renew'
}
tokenService.init(tokenConfig)
interface TokenConfig {
    tokenRenewInterval: number
    tokenRenewUrl: string
    tokenRenewProvider: TokenRequestProvider //callback to retrieve token from legacy site, can be deprecated in future
}

Usage

import {sbtFetch} from 'sbtech-general-api-client'

let defaultRequestOptions = {
    maxRetriesAmount: 5,
    headers: {
        myCustomHeader: 'headerValue1'
    }
}
let api = sbtFetch('example.com/api', defaultRequestOptions) // setup default options (optional)
api('events?', {attachToken: false}).get() // options can be overridden
    .then((json)=>{
        // ...
    })

RequestOptions extends native fetch options object.

interface RequestOptions extends RequestInit {
    responseAs?: 'json' | 'text' | 'response' // default: json
    retryCheckers?: RetryChecker[] // default: checkExpiredToken
    maxRetriesAmount?: number // default: 3
    attachToken?: boolean // default: true
}

FAQs

Package last updated on 26 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts