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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lorion-org/provider-selection

v1.0.0-beta.2

Published

Framework-free capability provider selection primitives.

Readme

@lorion-org/provider-selection

@lorion-org/provider-selection is a small framework-free core for selecting one provider per capability from multiple candidates.

It solves these things:

  • collect provider candidates by capability
  • collect provider-owned defaults from descriptors
  • collect provider preferences from descriptors or config-like records
  • collect explicit provider preferences from selected provider ids
  • optionally collect and resolve in one call
  • pick one provider with configured and fallback preferences
  • report misconfigured provider selections
  • return excluded providers that lost the selection

Selection order is always:

  1. configured provider
  2. explicitly selected provider
  3. fallback provider
  4. first provider in deterministic sort order

If a configured provider is set but not present among the candidates, the package does not silently fall back. It reports a mismatch and leaves that capability unselected.

Playground examples in this repository:

  • packages/nuxt/playground/layer-extensions/payment-provider-stripe/extension.json
  • packages/nuxt/playground/layer-extensions/payment-provider-invoice/extension.json
  • packages/react/playground/capabilities/payment-provider-stripe/capability.json
  • packages/react/playground/capabilities/payment-provider-invoice/capability.json

It does not know anything about:

  • framework runtime config
  • feature manifests
  • plugins
  • filesystems
  • application-specific contract names

Install

pnpm add @lorion-org/provider-selection

Example

Use provider-owned defaults when a provider descriptor should decide the normal provider for a capability:

import {
  collectProviderDefaults,
  resolveItemProviderSelection,
} from '@lorion-org/provider-selection';

const descriptors = [
  { id: 'payment-provider-stripe', providesFor: 'checkout', defaultFor: 'checkout' },
  { id: 'payment-provider-invoice', providesFor: 'checkout' },
];

const fallbackProviders = collectProviderDefaults({
  items: descriptors,
  getDefaultFor: (item) => item.defaultFor,
  getProviderId: (item) => item.id,
});

const result = resolveItemProviderSelection({
  items: descriptors,
  getCapabilityId: (item) => item.providesFor,
  getProviderId: (item) => item.id,
  fallbackProviders,
});

This selects Stripe with mode fallback. providesFor and defaultFor both accept a string or string array, so one provider can serve multiple capabilities.

Use explicit selected providers for seed-owned overrides. This is useful when a host app lets users select descriptors through a normal feature or profile seed, and a selected descriptor is also a provider for a capability:

import {
  collectSelectedProviderPreferences,
  resolveItemProviderSelection,
} from '@lorion-org/provider-selection';

const selectedProviders = collectSelectedProviderPreferences({
  items: descriptors,
  getCapabilityId: (descriptor) => descriptor.providesFor,
  getProviderId: (descriptor) => descriptor.id,
  selectedProviderIds: ['payment-provider-invoice'],
});

const result = resolveItemProviderSelection({
  items: descriptors,
  getCapabilityId: (descriptor) => descriptor.providesFor,
  getProviderId: (descriptor) => descriptor.id,
  fallbackProviders,
  selectedProviders,
});

This selects Invoice with mode selected, even though Stripe owns the fallback default. Configured providers still have higher priority.

Use configured providers for deployment-owned overrides:

import { resolveItemProviderSelection } from '@lorion-org/provider-selection';

const result = resolveItemProviderSelection({
  items: descriptors,
  getCapabilityId: (item) => item.providesFor,
  getProviderId: (item) => item.id,
  configuredProviders: { checkout: 'payment-provider-invoice' },
  fallbackProviders,
});

result.selections;
result.providersByCapability;
result.mismatches;
result.excludedProviderIds;

If you already have a Map<capability, providers>, use the lower-level resolver directly:

import { resolveProviderSelection } from '@lorion-org/provider-selection';

const result = resolveProviderSelection({
  providersByCapability: new Map([
    ['checkout', ['payment-provider-invoice', 'payment-provider-stripe']],
  ]),
  configuredProviders: {
    checkout: 'missing-provider',
  },
});

result.selections;
result.mismatches;
// => [{ capabilityId: 'checkout', configuredProviderId: 'missing-provider' }]

If profile or descriptor preferences are stored on descriptors, collect them as fallback preferences before resolving:

import {
  collectProviderDefaults,
  collectProviderPreferences,
  resolveItemProviderSelection,
} from '@lorion-org/provider-selection';

const providerDefaults = collectProviderDefaults({
  items: descriptors,
  getDefaultFor: (descriptor) => descriptor.defaultFor,
  getProviderId: (descriptor) => descriptor.id,
});
const descriptorPreferences = collectProviderPreferences({
  items: descriptors,
  getProviderPreferences: (descriptor) => descriptor.providerPreferences,
});

const result = resolveItemProviderSelection({
  items: descriptors,
  getCapabilityId: (descriptor) => descriptor.providesFor,
  getProviderId: (descriptor) => descriptor.id,
  fallbackProviders: {
    ...providerDefaults,
    ...descriptorPreferences,
  },
});

API

type CapabilityId = string;
type ProviderId = string;
type ProviderSelectionMode = 'configured' | 'selected' | 'fallback' | 'first';
type ProviderPreferenceMap = Partial<Record<CapabilityId, ProviderId>>;
type ProvidersByCapability = Map<CapabilityId, ProviderId[]>;
type ProviderCollectionInput<T> = {
  items: Iterable<T>;
  getCapabilityId: (item: T) => unknown;
  getProviderId: (item: T) => ProviderId;
};
type SelectedProviderPreferenceCollectionInput<T> = ProviderCollectionInput<T> & {
  selectedProviderIds: Iterable<ProviderId>;
};
type ProviderDefaultCollectionInput<T> = {
  items: Iterable<T>;
  getDefaultFor: (item: T) => unknown;
  getProviderId: (item: T) => ProviderId;
};

type ProviderSelection = {
  capabilityId: CapabilityId;
  selectedProviderId: ProviderId;
  candidateProviderIds: ProviderId[];
  mode: ProviderSelectionMode;
};

type ProviderMismatch = {
  capabilityId: CapabilityId;
  configuredProviderId: ProviderId;
};

type ProviderSelectionResolution = {
  selections: Map<CapabilityId, ProviderSelection>;
  mismatches: ProviderMismatch[];
  excludedProviderIds: ProviderId[];
};

type ItemProviderSelectionResolution = ProviderSelectionResolution & {
  providersByCapability: ProvidersByCapability;
};

The package exposes:

  • collectProviderDefaults()
  • collectProviderPreferences()
  • collectProvidersByCapability()
  • collectSelectedProviderPreferences()
  • resolveItemProviderSelection()
  • resolveSelectedProviderRelationPreferences()
  • resolveProviderSelection()

Local commands

cd packages/provider-selection
pnpm build
pnpm test
pnpm coverage
pnpm typecheck
pnpm package:check