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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@data-fair/lib-common-types

v1.27.0

Published

Shared schemas and built type definitions in the data-fair stack.

Readme

@data-fair/lib-common-types

The JSON schemas and TypeScript types shared across the data-fair stack (session state, accounts, events, notifications, themes, catalog and processing plugin contracts…), with their generated validators and a few helpers built on top of them. Services, Vue applications and plugins import it so that they all speak the same contracts.

Install

npm i @data-fair/lib-common-types

Optional peer dependency: tinycolor2 (v1), only needed by theme/index.js.

Modules

Each directory module exports its generated types (and validate / assertValid / returnValid when listed) from index.js, and its raw JSON schema as the default export of schema.js.

| Import path | Description | | --- | --- | | @data-fair/lib-common-types/session/index.js | SessionState, SessionStateAuthenticated, User, Account… types, validators, and the isAuthenticated, assertAuthenticated, assertAdminMode, getAccountRole, assertAccountRole, isValidAccountType, assertValidAccountType helpers. | | @data-fair/lib-common-types/account/index.js | Account (owner of a resource) and AccountKeys types, validators. | | @data-fair/lib-common-types/access-ref/index.js | AccessRef permission target types, validators, matchAccessRef(session, accessRef) and mongoFilterAccessRef(session). | | @data-fair/lib-common-types/application/index.js | Application, Dataset and Field types, as seen by a data-fair application. | | @data-fair/lib-common-types/event/index.js | Event types (events service). | | @data-fair/lib-common-types/notification/index.js | Notification types, validators. | | @data-fair/lib-common-types/theme/index.js | Theme / Colors types, defaultTheme, fillTheme, color contrast helpers (getReadableColor, getOnColor, getColorsWarnings, getSiteColorsWarnings…). | | @data-fair/lib-common-types/catalog/index.js | The CatalogPlugin contract of catalog plugins and its context types. | | @data-fair/lib-common-types/processings.js | The PrepareFunction, RunFunction, ProcessingContext and LogFunctions types of processing plugins. | | @data-fair/lib-common-types/ws.js | Message type of the websocket protocol. | | @data-fair/lib-common-types/scopes.js | defineScopes (a service's scope vocabulary: accepted scopes per tier, descriptions, global tier scopes), globalScopes, oauth2SecurityScheme. |

Usage

Session

The session state is usually obtained through the session middleware of @data-fair/lib-express or useSession of @data-fair/lib-vue; this package provides its type and the checks. See the data-fair-session skill.

import { type SessionState, assertAccountRole } from '@data-fair/lib-common-types/session/index.js'

// throws httpError(401) if not authenticated, httpError(403) if the active account does not have the role
assertAccountRole(sessionState, resource.owner, 'admin')

getAccountRole(sessionState, account, { allAccounts?, acceptDepAsRoot? }) returns the role instead of throwing ('admin' in admin mode and for the user's own account, null if none).

Referencing the shared schemas

Schemas built with @data-fair/lib-types-builder can $ref the shared schemas by their $id (https://github.com/data-fair/lib/<name>):

owner: { $ref: 'https://github.com/data-fair/lib/account' },
topic: { $ref: 'https://github.com/data-fair/lib/event#/$defs/topicRef' }

Plugins

import type { PrepareFunction, RunFunction, ProcessingContext } from '@data-fair/lib-common-types/processings.js'
import type { CatalogPlugin } from '@data-fair/lib-common-types/catalog/index.js'

See the data-fair-processing skill.

Scopes

A service declares its scope families once; the matching of session/index.js (hasScope, exact or bare umbrella, never prefix) stays the same.

import { defineScopes, oauth2SecurityScheme, oauth2Alternatives } from '@data-fair/lib-common-types/scopes.js'

const scopes = defineScopes({
  notifications: {
    tiers: ['read', 'write'],
    descriptions: {
      umbrella: { fr: 'Tous les droits sur les notifications', en: 'All notification scopes' },
      read: { fr: 'Lire ses notifications', en: 'Read own notifications' },
      write: { fr: 'Gérer ses abonnements', en: 'Manage own subscriptions' }
    }
  }
})

// notifications:write notifications all:write all:admin
requireScope(scopes.acceptedScopes('notifications', 'write'))

// the oauth2 scheme of the service's OpenAPI document
oauth2SecurityScheme(scopes, { directoryUrl, locale: 'fr' })

// an operation's security: [{ sdCookie: [] }, { oauth2: ['notifications:write'] }, { oauth2: ['notifications'] }, ...]
const security = [{ sdCookie: [] }, ...oauth2Alternatives(scopes.acceptedScopes('notifications', 'write'))]
  • acceptedScopes(family, tier): the family's declared tiers at or above tier, the umbrella, then all:<tier> and the higher global tier scopes. A tier the family does not declare throws.
  • familyScopes(family): every scope that reaches some tier of the family, for a coarse gate.
  • scopeDescriptions(locale): the description of every declared scope, the all:* ones included.
  • oauth2Alternatives(accepted): one OpenAPI security alternative per accepted scope. A single { oauth2: [a, b] } would mean a token needs both. What an all:* scope grants is read from the operations that list it, data-fair's platform document relies on this form.
  • The global tier scopes and their descriptions are owned here (globalScopes), identical in every service. all is reserved as a family name.