@lastshotlabs/slingshot-organizations
npm install @lastshotlabs/slingshot-organizations
Functions
Section titled “Functions”createMemoryOrganizationsRateLimitStore
Section titled “createMemoryOrganizationsRateLimitStore”Default in-memory implementation of OrganizationsRateLimitStore.
Stores per-key timestamp arrays and prunes events older than the window on
each hit. Eviction of completely-quiet keys happens lazily on hit; an
optional maxEntries cap drops the oldest tracked key when exceeded to
bound memory usage.
function createMemoryOrganizationsRateLimitStore(options?: { maxEntries?: number; }): OrganizationsRateLimitStoreSource: packages/slingshot-organizations/src/lib/rateLimit.ts
createOrganizationsPackage
Section titled “createOrganizationsPackage”Create the organizations package using the definePackage authoring path.
The five organizations entities are mounted via the package’s entities: [...]
declaration; their adapters are wrapped with per-entity transforms (slug
validation, cascade-delete, scoped membership ids, invite token lifecycle)
inside each entity module’s wiring.buildAdapter callback. The package
factory captures the resolved adapters in a shared
OrganizationsAdapterRefs bag so the custom-op handlers, the org
service, and the reconcile service all use the same instance per entity.
function createOrganizationsPackage(rawConfig: OrganizationsPluginConfig = {}, deps: OrganizationsPluginDeps = {},): SlingshotPackageDefinitionSource: packages/slingshot-organizations/src/plugin.ts
createRedisOrganizationsRateLimitStore
Section titled “createRedisOrganizationsRateLimitStore”Redis-backed OrganizationsRateLimitStore using a sorted-set sliding window.
The implementation runs an atomic Lua script so rate-limit checks are safe across concurrent processes. Keys are automatically expired after the window elapses.
function createRedisOrganizationsRateLimitStore(redis: RedisLike, keyPrefix = 'org-rl:',): OrganizationsRateLimitStoreSource: packages/slingshot-organizations/src/lib/rateLimitRedis.ts
getOrganizationsOrgService
Section titled “getOrganizationsOrgService”Retrieve the OrganizationsOrgService from plugin state, throwing if it
is not available. Use this when the organizations plugin is a required dependency
and its absence is a configuration error.
function getOrganizationsOrgService(input: PluginStateMap | PluginStateCarrier | object | null | undefined,): OrganizationsOrgServiceSource: packages/slingshot-organizations/src/orgService.ts
getOrganizationsOrgServiceOrNull
Section titled “getOrganizationsOrgServiceOrNull”Retrieve the OrganizationsOrgService from plugin state, returning null
when the organizations plugin has not been registered or has not yet completed
its setupPost lifecycle phase.
function getOrganizationsOrgServiceOrNull(input: PluginStateMap | PluginStateCarrier | object | null | undefined,): OrganizationsOrgService | nullSource: packages/slingshot-organizations/src/orgService.ts
getOrganizationsReconcile
Section titled “getOrganizationsReconcile”Resolve the reconcile service from app pluginState. Throws if it has not
been published — typically because setupPost did not run yet.
function getOrganizationsReconcile(input: PluginStateMap | PluginStateCarrier | object | null | undefined,): OrganizationsReconcileServiceSource: packages/slingshot-organizations/src/reconcile.ts
getOrganizationsReconcileOrNull
Section titled “getOrganizationsReconcileOrNull”Non-throwing variant for callers that need to probe availability.
function getOrganizationsReconcileOrNull(input: PluginStateMap | PluginStateCarrier | object | null | undefined,): OrganizationsReconcileService | nullSource: packages/slingshot-organizations/src/reconcile.ts
isUniqueViolationError
Section titled “isUniqueViolationError”Heuristic detection for unique-constraint / duplicate-key violations thrown by entity adapters across backends.
Detects:
- The in-memory adapter’s
HttpError(409, ..., 'UNIQUE_VIOLATION') - Postgres
23505SQLSTATE (unique_violation) - MongoDB duplicate-key error code
11000 - Generic messages containing “unique” or “duplicate” (case-insensitive)
Does NOT match a SlugConflictError itself — callers should check for
that separately if they need to distinguish “already converted” from
“raw driver error”.
function isUniqueViolationError(err: unknown): booleanSource: packages/slingshot-organizations/src/errors.ts
Constants
Section titled “Constants”Organizations
Section titled “Organizations”Provider-owned package contract for slingshot-organizations.
Source: packages/slingshot-organizations/src/public.ts
ORGANIZATIONS_RECONCILE_STATE_KEY
Section titled “ORGANIZATIONS_RECONCILE_STATE_KEY”pluginState key under which the reconcile service is published.
Source: packages/slingshot-organizations/src/reconcile.ts
OrganizationsOrgServiceCap
Section titled “OrganizationsOrgServiceCap”Capability handle for the organizations org service.
Cross-package consumers resolve it through ctx.capabilities.require(OrganizationsOrgServiceCap)
to look up org membership, create orgs, and manage org-scoped state.
Source: packages/slingshot-organizations/src/public.ts
Classes
Section titled “Classes”SlugConflictError
Section titled “SlugConflictError”Thrown when an organization slug collides with an existing record.
Surfaces as HTTP 409. The pre-flight slug-availability check is a UX
optimisation — correctness depends on the unique constraint on the
Organization.slug index combined with this typed error. Catch the raw
duplicate-key error from the persistence layer and rethrow as
SlugConflictError so callers always observe a stable, machine-readable
conflict signal.
Extends HTTPException so it is handled cleanly by Hono routes (returns
a 409 response with the error body) while remaining catchable as a
typed error in programmatic use.
Source: packages/slingshot-organizations/src/errors.ts
Interfaces
Section titled “Interfaces”GroupsConfig
Section titled “GroupsConfig”Configuration for the groups sub-system within the organizations plugin.
Set managementRoutes to mount group CRUD and membership management routes.
Pass true to use all defaults (adminRole: "admin").
Source: packages/slingshot-organizations/src/types/groups.ts
GroupsManagementConfig
Section titled “GroupsManagementConfig”Fine-grained access-control options for the groups management routes.
Either adminRole or middleware can be used to protect the routes —
providing middleware overrides adminRole entirely.
Source: packages/slingshot-organizations/src/types/groups.ts
OrganizationsPluginDeps
Section titled “OrganizationsPluginDeps”Optional non-JSON dependencies the organizations package accepts at construction time.
Source: packages/slingshot-organizations/src/plugin.ts
OrganizationsRateLimitStore
Section titled “OrganizationsRateLimitStore”Pluggable backing store for the organizations rate-limit middleware.
Implementations record a hit and return whether the limit has been exceeded
given the configured window. The default implementation
(createMemoryOrganizationsRateLimitStore) is a process-local Map suitable
for single-instance deployments and tests; production users should provide a
Redis- or otherwise-shared backing store.
Source: packages/slingshot-organizations/src/lib/rateLimit.ts
OrganizationsReconcileService
Section titled “OrganizationsReconcileService”Operator-facing recovery API exposed by the organizations runtime via pluginState. Removes orphaned member, invite, group, and group-membership rows for an org id that has been deleted.
Wire this method into a CLI command or admin route to remediate the 500 response from a partial cascade-delete on a non-atomic adapter (e.g. memory or Mongo). Refuses to run if the org row still exists, since live orgs should not have their dependents wiped.
Source: packages/slingshot-organizations/src/reconcile.ts
ReconcileOrphanedOrgRecordsResult
Section titled “ReconcileOrphanedOrgRecordsResult”Result of reconcileOrphanedOrgRecords. Reports which dependent
collections still had orphaned rows when reconciliation began and which
(if any) failed to clean up. An empty failed list means the org has no
remaining orphans.
Source: packages/slingshot-organizations/src/reconcile.ts
RedisLike
Section titled “RedisLike”Canonical Redis client interface used across all slingshot packages.
Concrete implementations (ioredis, Upstash Redis, etc.) satisfy this contract. Typed as an interface rather than a class so that any Redis-compatible client can be used without an adapter layer.
Remarks: getdel is optional because it is not supported by all Redis versions (requires Redis 6.2+). Framework code that calls getdel should fall back to GET+DEL when it is absent.
Source: packages/slingshot-core/src/redis.ts
OrganizationsOrgService
Section titled “OrganizationsOrgService”Runtime organization service published through plugin state.
Peer plugins use this contract to resolve organizations by slug, create organizations, and add members without depending on a concrete adapter.
Source: packages/slingshot-organizations/src/orgService.ts
OrganizationsPluginConfig
Section titled “OrganizationsPluginConfig”JSON-safe organizations package configuration.
Source: packages/slingshot-organizations/src/plugin.ts
OrganizationsRateLimitDecision
Section titled “OrganizationsRateLimitDecision”Result of a sliding-window rate-limit check.
Source: packages/slingshot-organizations/src/lib/rateLimit.ts