Skip to content

@lastshotlabs/slingshot-organizations

npm install @lastshotlabs/slingshot-organizations

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; }): OrganizationsRateLimitStore

Source: packages/slingshot-organizations/src/lib/rateLimit.ts

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 = {},): SlingshotPackageDefinition

Source: packages/slingshot-organizations/src/plugin.ts

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:',): OrganizationsRateLimitStore

Source: packages/slingshot-organizations/src/lib/rateLimitRedis.ts

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,): OrganizationsOrgService

Source: packages/slingshot-organizations/src/orgService.ts

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 | null

Source: packages/slingshot-organizations/src/orgService.ts

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,): OrganizationsReconcileService

Source: packages/slingshot-organizations/src/reconcile.ts

Non-throwing variant for callers that need to probe availability.

function getOrganizationsReconcileOrNull(input: PluginStateMap | PluginStateCarrier | object | null | undefined,): OrganizationsReconcileService | null

Source: packages/slingshot-organizations/src/reconcile.ts

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 23505 SQLSTATE (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): boolean

Source: packages/slingshot-organizations/src/errors.ts

Provider-owned package contract for slingshot-organizations.

Source: packages/slingshot-organizations/src/public.ts

pluginState key under which the reconcile service is published.

Source: packages/slingshot-organizations/src/reconcile.ts

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

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

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

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

Optional non-JSON dependencies the organizations package accepts at construction time.

Source: packages/slingshot-organizations/src/plugin.ts

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

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

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

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

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

JSON-safe organizations package configuration.

Source: packages/slingshot-organizations/src/plugin.ts

Result of a sliding-window rate-limit check.

Source: packages/slingshot-organizations/src/lib/rateLimit.ts