Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • default

Index

Constructors

constructor

Properties

apiBase

apiBase: string

apiPrefix

apiPrefix: string

apiRoot

apiRoot: string

auth

auth: boolean

Private clientId

clientId: undefined | string

Private clientSecret

clientSecret: undefined | string

Private dataFormatter

dataFormatter: Jsona

debug

debug: boolean

Optional defaultLocale

defaultLocale: string

destroy

destroy: Destroy

Optional fetchAdapter

fetchAdapter: fetchAdapter

getState

getState: GetState<object>

noStore

noStore: boolean

onError

onError: (err: Error) => void

Type declaration

    • (err: Error): void
    • Parameters

      • err: Error

      Returns void

setState

setState: SetState<object>

store

store: StoreApi<object>

subscribe

subscribe: Subscribe<object>

Private token

token: TokenObject = ...

Methods

assembleApiRoot

  • assembleApiRoot(): string
  • Format apiBase, apiPrefix, and combine into apiRoot.

    Returns string

    a fully qualified JSON:API root endpoint URL

assembleEndpoint

  • assembleEndpoint(indexHref: string, id?: string, params?: string | DrupalJsonApiParams): string
  • Assembles a correctly formatted JSON:API endpoint URL.

    Parameters

    • indexHref: string

      a JSON:API resource endpoint

    • id: string = ''

      id of an individual resource

    • Optional params: string | DrupalJsonApiParams

      user provided JSON:API parameter string or DrupalJsonApiParams object

    Returns string

    a full endpoint URL

fetchApiIndex

  • fetchApiIndex(apiRoot: string): Promise<void | GenericIndex>
  • Wraps fetch/fetchApiIndex function so it can be overridden.

    Parameters

    • apiRoot: string

    Returns Promise<void | GenericIndex>

fetchData

  • fetchData(endpoint: string, res?: boolean | ServerResponse<IncomingMessage>, anon?: boolean): Promise<void | TJsonApiBody>
  • Fetches data using our fetch method.

    Parameters

    • endpoint: string

      the assembled JSON:API endpoint

    • res: boolean | ServerResponse<IncomingMessage> = false

      response object

    • anon: boolean = false

      make the request anonymously if true

    Returns Promise<void | TJsonApiBody>

    data fetched from JSON:API endpoint

fetchJsonapiEndpoint

  • fetchJsonapiEndpoint(endpoint: string, requestInit?: {}, onError: (err: Error) => void, res: boolean | ServerResponse<IncomingMessage>): Promise<void | Response>
  • Wraps fetch/fetchJsonapiEndpoint function so it can be overridden.

    Parameters

    • endpoint: string
    • requestInit: {} = {}
    • onError: (err: Error) => void
        • (err: Error): void
        • Parameters

          • err: Error

          Returns void

    • res: boolean | ServerResponse<IncomingMessage>

    Returns Promise<void | Response>

Private getApiIndex

  • getApiIndex(): Promise<PartialState<object, never, never, never, never>>
  • Get the contents of the root API from local state if it exists, or fetch it from Drupal if it doesn't exist in local state.

    Returns Promise<PartialState<object, never, never, never, never>>

    a promise containing an index of api links

getAuthHeader

  • getAuthHeader(): Promise<string>
  • Assembles an authorization header using an existing token if valid, or by fetching a new token if necessary.

    Returns Promise<string>

    a string containing an authorization header value

getObject

  • getObject(__namedParameters: GetObjectParams): Promise<void | PartialState<object, never, never, never, never>>
  • Get an object from local state if it exists, or fetch it from Drupal if it doesn't exist in local state.

    remarks

    The query option was experimental and is now deprecated

    example
    • @example
    await store.getObject({
       objectName: 'node--article',
       id: 'some-article-uuid-here',
       res: ServerResponse,
       params: 'include=field_media_image',
       refresh: true,
    )}
    

    Parameters

    Returns Promise<void | PartialState<object, never, never, never, never>>

    a promise containing deserialized JSON:API data for the requested object

getObjectByPath

  • getObjectByPath(__namedParameters: GetObjectByPathParams): Promise<void | PartialState<object, never, never, never, never>>
  • Get an object by path alias from local state if it exists, or fetch it from Drupal if it doesn't exist in local state.

    remarks

    The query option was experimental and is now deprecated

    example
    await store.getObjectByPath({
       objectName: 'node--article',
       path: '/articles/my-article',
       res: ServerResponse,
       params: 'include=field_media_image',
       refresh: true,
    )}
    

    Parameters

    Returns Promise<void | PartialState<object, never, never, never, never>>

    a promise containing deserialized JSON:API data for the requested object

Generated using TypeDoc