[]
        
(Showing Draft Content)

fetchResource

Function: fetchResource()

function fetchResource(resource, options?): Promise<ArrayBuffer>;

Fetches an external resource using a configurable resolution and loading pipeline.

This function orchestrates the full lifecycle of a resource request:

  1. Resolves the final URL using ExternalResourcesOptions.resolveUrl (if provided)
  2. Delegates the network request to a ResourceLoader
  3. Invokes lifecycle hooks before and after the request
  4. Handles errors and optionally reports them via a callback

Parameters

resource

ResourceProperties

The initial resource descriptor containing the resource type and original URL (e.g., extracted from a certificate or document).

options?

ExternalResourcesOptions

Optional configuration controlling URL resolution, transport, and lifecycle hooks:

  • resolveUrl allows rewriting or proxying the resource URL
  • loader overrides the default network implementation
  • beforeRequest, afterResponse, and onError provide lifecycle hooks

Returns

Promise<ArrayBuffer>

A promise resolving to the fetched resource as an ArrayBuffer, or null if the request fails.

Remarks

  • If resolveUrl is provided, it may return a modified URL (e.g., a proxy endpoint).
  • If no custom loader is specified, a default Fetch API–based loader is used.
  • Errors thrown during fetch are caught internally; to observe them, use onError.

Example

const data = await fetchResource(
  { type: ResourceType.CRL, url: crlUrl },
  {
    resolveUrl: (ctx) => `/api/proxy?url=${encodeURIComponent(ctx.url)}`,
    onError: (ctx, err) => console.error("Failed:", ctx.url, err)
  }
);