Skip to content

@lastshotlabs/slingshot-polls

npm install @lastshotlabs/slingshot-polls

Create a closure-owned in-memory sliding-window rate limiter.

Not suitable for multi-instance deployments — each process has independent limits. Use createRedisRateLimiter() (out of scope for v1) when horizontal scaling requires shared state.

function createInMemoryRateLimiter(): RateLimitBackend

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

Build the dispatched PolicyResolver for the Poll entity.

Dispatches on sourceType read from the record (for get/update/delete) or the input body (for create). Unregistered source types are denied.

function createPollSourcePolicy(handlers: Map<string, PolicyResolver<PollRecord, Partial<PollRecord>>>,): PolicyResolver<PollRecord, Partial<PollRecord>>

Source: packages/slingshot-polls/src/policy/index.ts

Create the polls package.

Per-sourceType policy handlers for poll authorization are declared on the sourceHandlers (and voteHandlers) config fields at construction time; there is no runtime registration API. Apps know which source types they expose when they wire the package.

function createPollsPackage(rawConfig: Partial<PollsPluginConfig> = {},): SlingshotPackageDefinition

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

Build the dispatched PolicyResolver for the PollVote entity.

Same dispatch strategy as polls — reads sourceType from the vote record or input. Unregistered source types are denied.

function createPollVotePolicy(handlers: Map<string, PolicyResolver<PollVoteRecord, Partial<PollVoteRecord>>>,): PolicyResolver<PollVoteRecord, Partial<PollVoteRecord>>

Source: packages/slingshot-polls/src/policy/index.ts

Stable registry key for poll source policy.

Source: packages/slingshot-polls/src/policy/index.ts

Stable registry key for poll vote policy.

Source: packages/slingshot-polls/src/policy/index.ts

All client-safe poll event keys.

Source: packages/slingshot-polls/src/types/index.ts

A poll attached to a piece of content. Created alongside the content (the content stores the resulting pollId in its sidecar) and referenced by every consumer package via that ID.

Polls are content-agnostic: sourceType is a free-form string like 'chat:message' or 'community:thread' so consumers can query their own polls without this package knowing about their entities.

Source: packages/slingshot-polls/src/entities/poll.ts

Structured error codes returned by the poll vote guard.

Source: packages/slingshot-polls/src/types/index.ts

Source: packages/slingshot-polls/src/entities/factories.ts

Poll named operations.

  • listBySource — find polls attached to a specific piece of content.
  • closePoll — transition closed from false to true, recording closedBy and closedAt. Manual close sets closedBy to the caller’s user ID; the auto-close sweep passes null.

Source: packages/slingshot-polls/src/operations/index.ts

Provider-owned package contract for slingshot-polls.

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

Canonically cased schema export.

Source: packages/slingshot-polls/src/validation/config.ts

FieldDescription
disableRoutesPoll route keys to skip when mounting routes. Default: [].
maxOptionLengthMaximum poll option length in characters. Default: 200.
maxOptionsMaximum number of answer options allowed on a poll. Default: 10.
maxQuestionLengthMaximum poll question length in characters. Default: 500.
mountPathURL path prefix for poll routes. Default: /polls.
rateLimitRate-limiting configuration for poll routes.

Source: packages/slingshot-polls/src/validation/config.ts

Capability handle for the polls runtime state.

Cross-package consumers resolve it via ctx.capabilities.require(PollsRuntimeCap). The legacy POLLS_RUNTIME_KEY plugin-state slot is still published in parallel during the bridge period; new consumers should prefer the cap.

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

A single vote cast against a poll. One row per user per selected option — multi-select polls allow multiple rows for the same (pollId, userId) pair with different optionIndex values.

Source: packages/slingshot-polls/src/entities/pollVote.ts

Source: packages/slingshot-polls/src/entities/factories.ts

PollVote named operations.

  • listByPoll — all votes for a given poll.
  • myVotes — the authenticated user’s votes on a specific poll. Uses param:actor.id (injected from Hono context by the framework) so the userId is never taken from the URL.
  • countByOption — aggregate vote count grouped by option index.

Source: packages/slingshot-polls/src/operations/index.ts

Payload for polls:poll.closed events.

Source: packages/slingshot-polls/src/types/index.ts

Payload for polls:poll.created events.

Source: packages/slingshot-polls/src/types/index.ts

Fields accepted by the POST /polls/polls route body.

Source: packages/slingshot-polls/src/types/index.ts

Payload for polls:poll.deleted events.

Source: packages/slingshot-polls/src/types/index.ts

A persisted poll record.

Source: packages/slingshot-polls/src/types/index.ts

One row of aggregated results per option.

Source: packages/slingshot-polls/src/types/index.ts

Path params for the GET /polls/polls/:id/results route.

Source: packages/slingshot-polls/src/types/index.ts

Full response from the results handler.

Source: packages/slingshot-polls/src/types/index.ts

Configuration for the polls plugin.

Source: packages/slingshot-polls/src/types/index.ts

Runtime state stored under POLLS_RUNTIME_KEY.

Source: packages/slingshot-polls/src/types/index.ts

A rate-limit bucket for a single scope (user or tenant).

Source: packages/slingshot-polls/src/types/index.ts

Per-operation rate-limit config. Opt-in — omit to disable limiting.

Source: packages/slingshot-polls/src/types/index.ts

A rate-limit rule for a single operation.

Source: packages/slingshot-polls/src/types/index.ts

Fields accepted by the POST /polls/poll-votes route body.

Source: packages/slingshot-polls/src/types/index.ts

Payload for polls:poll.voted events.

Source: packages/slingshot-polls/src/types/index.ts

A persisted vote record.

Source: packages/slingshot-polls/src/types/index.ts

Payload for polls:poll.vote_retracted events.

Source: packages/slingshot-polls/src/types/index.ts

Swappable rate-limit backend.

v1 ships with createInMemoryRateLimiter() only. Add a Redis-backed implementation for multi-instance deployments without touching middleware.

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

Policy resolver keys used in entity route configs. Consumers register resolvers under these keys via registerEntityPolicy().

Source: packages/slingshot-polls/src/types/index.ts

Every mountable route keyed by entityName.opName. Passed to PollsPluginConfig.disableRoutes.

Source: packages/slingshot-polls/src/types/index.ts

Source: packages/slingshot-polls/src/types/index.ts