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

@lincs.project/auth-api-contract

v1.1.0

Published

Contract for LINCS Auth API

Downloads

97

Readme

LINCS Auth API Contract

Defines the contract for the Auth-API Service App. It uses TS-REST in combination with Zod to determine the request and response objects. These objects can be used to validate calls to each endpoint.

It can be used to build a JavaScript helper to access the endpoints of the Auth-API Service App using a standardized fetcher. It allows for better endpoint discoverability and fully typed request parameters and responses. The API contract is also available to create a custom fetcher.

It must be used in conjunction with @ts-rest/core

How to use the client helper

Install

npm install @lincs.project/auth-api-contract @ts-rest/core

Create the client Adapter and use it

import { contract } from '@lincs.project/auth-api-contract';
import { initClient } from '@ts-rest/core';

const lincsAuthApiAdapter = initClient(contract, {
  baseUrl: 'https://auth-api.dev.lincsproject.ca',
  baseHeaders: {}
});

const response = await lincsAuthApiAdapter.v1.providers.getAll();

if (response === 200) {
  console.log(response.body)
  /*
    [{
      "providerId": "gitlab",
      "enabled": true,
      "linkOnly": false,
      "config": {...},
      ...
    }]
  */

Endpoints

This list may not reflect the current state of the API. Please check the open api documentation here: http://auth-api.lincsproject.ca.

GET /v1/providers

Response

Return a list of available external identity providers.

[
  {
    "providerId": "orcid",
    "enabled": true,
    "linkOnly": true,
    "config": {...},
    ...
  },
  {
    "providerId": "gitlab",
    "enabled": true,
    "linkOnly": false,
    "config": {...},
    ...
  }
]

Using the adapter

const providers = await lincsAuthApiAdapter.v1.providers.getAll();

GET /v1/users/{username}/linked-accounts

Request

Headers

Authorization: Bearer {access_token} - User's Keycloak access token

Params

username: string - the username

Response

Return a list of external identity providers connected to a specific user.

[
  {
    "identityProvider": "orcid",
    "userId": {userId},
    "userName": {userName},
  },
  {
    "identityProvider": "github",
    "userId": {userId},
    "userName": {userName},
  }
]

Using the adapter

const accounts = await lincsAuthApiAdapter.v1.users.getLinkedAccounts({
  header: { autorization: 'Bearer {access_token}' },
  params: { username },
});

GET /v1/users/{username}/link-account-url

Generate a URL to request Keycloak to connect a specific provider to a specified user.

Request

Headers

Authorization: Bearer {access_token} - User's Keycloak access token

Params

username: string - the username

Query

provider: string - the provider to connect redirectUri: string - where to redirect the browser after connecting the account.

Response

An object with the url property.

{
  "url": "https://keycloak.lincsproject.ca/...",
}

Using the adapter

const accounts = await lincsAuthApiAdapter.v1.users.getLinkAccountUrl({
  header: { autorization: 'Bearer {access_token}' },
  params: { username },
  query: {
    provider: { providerId },
    redirectUri: { url },
  },
});

Development

Any changes in this package will reflect on Auth-API Service App.

Versioning

Since this is a contract for a web service API, it is important to strategically think about changes as they might break other services that depend on this API. We started with version v1.

A further development that adds, removes, or changes the endpoints should be allocated in a new version. However, keep the previous version available to allow other services to upgrade their codebase.

Linter

Attention!

This project uses and deploys ESM. We have configured a tight linter with strict Typescript and format (prettier) rules. Some of these rules can be relaxed if needed. Check eslint config: .eslintrc.cjs.

The linter always runs before any commit. But you can also run it at any time to check the code.

npm run lint

Build

npm run build

or in development mode

npm run dev