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

@copart/reference-data

v0.0.16

Published

<p> <a href="https://www.npmjs.com/package/@copart/reference-data"><img src="https://img.shields.io/badge/@copart/reference--data-0.0.14-orange.svg" alt="NPM Version"></a> </p>

Downloads

51

Readme

Reference Data Library

Installation

npm i @copart/reference-data

Library to fetch the Reference Data when provided the basic configuration.

Basically it is using the polyfill for React.createContext API, called create-react-context (it is this library's dependency). As we are using react version < 16, we are using it. If we upgrade it to a version > 16, then we can change it to use React.createContext.

Example Usage

import { ReferenceData } from '@copart/reference-data'

The root component which is going to use reference data context needs to be wrapped by ReferenceData.Provider and a params props needs to be passed as below

<ReferenceData.Provider params={params}> // param format is given below
  <div>
  </div>
</ReferenceData.Provider>

Any descendants of Provider can use the reference data context as below:

<ReferenceData.Consumer>
  {(referenceData) => (
    referenceData.items // items is being set in the context
  }
</ReferenceData.Consumer>

Param format

{
  refData: REFERENCE_DATA_DEPENDENCIES, // example given below
  countryCode,
  xhrConfig,
}

Example configuration format

REFERENCE_DATA_DEPENDENCIES:-

  {[MAKE]: entity(
    'makes',
    '/cobalt/${country}/api/v1/references/makes?skip_pagination=true&lot_type_cd=${lot_type_cd}',
    'make_id',
    'make_nm',
    { lot_type_cd: 'V' },
    ['data', 'data']
  )}
  • [MAKE] -> Key with which we can get the particular reference data.
  • 'makes' -> Will be used to show errorMessage // not being used currently
  • url -> url to fetch the entity's reference data
  • 'make_id' -> key
  • 'make_nm' -> parameter used for sorting // not being used currently
  • { lot_type_cd: 'V' } -> params passed, should match the variable name in the url inside the curly braces
  • ['data', 'data'] -> this will indicate the path from which we're getting the response

xhrConfig example -

export const xhrConfig = (xhrConf) => {
  const accessToken = getAccessToken() // will be taken by cookies/localStorage
  const headers = xhrConf.headers
  if (xhrConf.url.indexOf('solrg') !== -1) {
    headers['Cache-Control'] = 'no-store, must-revalidate, no-cache, max-age=0'
    headers.Expires = 'Mon, 01 Jan 1990 00:00:00 GMT'
    headers.Pragma = 'no-cache'
    return xhrConf
  }
  if (
    xhrConf.url.indexOf('referencedata-ws') !== -1 &&
    xhrConf.url.indexOf('referencedata-ws/states') === -1 &&
    xhrConf.url.indexOf('sprocs') === -1
  ) {
    headers.Version = '2.0'
  }
  if (accessToken && headers) {
    headers.Authorization = `bearer ${accessToken}`
    headers['Content-Type'] = 'application/json'
    headers.AUTHORIZATIONROLE = 'germany_executive'
    headers.SELECTEDYARD = 5001
    headers.LANGUAGECODE = 'en'
    headers.partnerCode = 'en'
    headers.country = 'DEU'
    headers.site = 'CPRTDE'
  }
  headers.correlationID = `cobalt-uuid-${uuid()}`
  return xhrConf
}

This data will be available to all the reference data requests using axios.interceptors

Response and how to fetch Dependency Reference Data

Response can be used by Render callback pattern (https://reactpatterns.com/),

  • response has two properties (items and actions)

  • items is an object again having two properties, success and failure

    • Success Example ->
  key -> stlmt_model
  value -> {
    "ids":["S","V"],
    "entities":{
      "S": {
        "stlmt_model_cd":"S","stlmt_model_desc":"Standard","status":"A","source_sys":"DataLoad","index":0
      },
      "V": {
        "stlmt_model_cd":"V","stlmt_model_desc":"Vermittler","status":"A","source_sys":"DataLoad","index":1
      }
    }
  }
  • actions has getNewData (for now this is the only function is there), which will help us in fetching the dependent reference data. Most of the times the reference data is fetched at the very beginning. But, in some cases we need to fetch the reference data as an entity changes, for example - if we are changing the Make, then we need to fetch the Models according to the new Make. we need to pass configuration of the dependent entity here in the same format as above.