Skip to content
LogoLogo

Transport.from

Create a custom transport

Creates a custom client-side transport.

Usage

import {  } from 'mppx'
import {  } from 'mppx/client'
 
const  = .<RequestInit, Response>({
  () {
    return .()
  },
  () {
    return . === 402
  },
  : 'http',
  (, ) {
    const  = new (.)
    .('Authorization', )
    return { ...,  }
  },
})

Return type

type Transport<request, response> = {
  /** Extracts every Challenge from a payment-required response. */
  getChallenges: (response: response, request?: request) => Challenge[] | Promise<Challenge[]>
  /** Checks if a response indicates payment is required. */
  isPaymentRequired: (response: response, request?: request) => boolean | Promise<boolean>
  /** Transport name for identification. */
  name: string
  /** Attaches a credential to a request. */
  setCredential: (request: request, credential: string, options?: SetCredentialOptions) => request
}

Parameters

getChallenges

  • Type: (response: Response, request?: RequestInit) => Challenge[] | Promise<Challenge[]>

Function that extracts every Challenge from a payment-required response. Return the Challenges in preference order.

isPaymentRequired

  • Type: (response: Response, request?: RequestInit) => boolean | Promise<boolean>

Function that checks if a response indicates payment is required.

name

  • Type: string

Transport name for identification.

setCredential

  • Type: (request: RequestInit, credential: string, options?: SetCredentialOptions) => RequestInit

Function that attaches a Credential to a request.