Documentation
    Preparing search index...

    Function createResourceService

    • Create a NAP-RESOURCE reference service.

      Implements the NAP-RESOURCE request/response protocol: resource.bytes, resource.bytesMany, resource.cancel, and their result/error envelopes.

      On-construction guard (H-03 prevention): all four options are validated at factory call time. If any is missing, the factory throws immediately with a message containing [RESOURCE-01 / H-03] so misconfigured shell apps fail loudly at startup rather than silently at first dispatch.

      Returns a ServiceHandler (no publishValues-style surface — resource has no shell-initiated push beyond the response/error path).

      Parameters

      Returns ServiceHandler

      ServiceHandler to register via runtime.registerService('resource', handler)

      import { createResourceService } from '@kehto/services';

      const svc = createResourceService({
      fetch: (url, init) => globalThis.fetch(url, init),
      isOriginGranted: (origin, grants) => grants.includes(origin),
      getConnectGrants: (dTag, hash) => myOriginGrantStore.getOrigins(dTag, hash),
      resolveIdentity: (windowId) => sessionRegistry.getEntryByWindowId(windowId) ?? null,
      });
      runtime.registerService('resource', svc);