@lastshotlabs/slingshot-polls
npm install @lastshotlabs/slingshot-polls
Functions
Section titled “Functions”createInMemoryRateLimiter
Section titled “createInMemoryRateLimiter”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(): RateLimitBackendSource: packages/slingshot-polls/src/lib/rateLimit.ts
createPollSourcePolicy
Section titled “createPollSourcePolicy”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
createPollsPackage
Section titled “createPollsPackage”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> = {},): SlingshotPackageDefinitionSource: packages/slingshot-polls/src/plugin.ts
createPollVotePolicy
Section titled “createPollVotePolicy”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
POLL_SOURCE_POLICY_KEY
Section titled “POLL_SOURCE_POLICY_KEY”Stable registry key for poll source policy.
Source: packages/slingshot-polls/src/policy/index.ts
POLL_VOTE_POLICY_KEY
Section titled “POLL_VOTE_POLICY_KEY”Stable registry key for poll vote policy.
Source: packages/slingshot-polls/src/policy/index.ts
Constants
Section titled “Constants”CLIENT_SAFE_POLL_EVENTS
Section titled “CLIENT_SAFE_POLL_EVENTS”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
POLL_VOTE_ERRORS
Section titled “POLL_VOTE_ERRORS”Structured error codes returned by the poll vote guard.
Source: packages/slingshot-polls/src/types/index.ts
pollFactories
Section titled “pollFactories”Source: packages/slingshot-polls/src/entities/factories.ts
pollOperations
Section titled “pollOperations”Poll named operations.
listBySource— find polls attached to a specific piece of content.closePoll— transitionclosedfromfalsetotrue, recordingclosedByandclosedAt. Manual close setsclosedByto the caller’s user ID; the auto-close sweep passesnull.
Source: packages/slingshot-polls/src/operations/index.ts
Provider-owned package contract for slingshot-polls.
Source: packages/slingshot-polls/src/public.ts
pollsPluginConfigSchema
Section titled “pollsPluginConfigSchema”Canonically cased schema export.
Source: packages/slingshot-polls/src/validation/config.ts
PollsPluginConfigSchema
Section titled “PollsPluginConfigSchema”Config Fields
Section titled “Config Fields”| Field | Description |
|---|---|
disableRoutes | Poll route keys to skip when mounting routes. Default: []. |
maxOptionLength | Maximum poll option length in characters. Default: 200. |
maxOptions | Maximum number of answer options allowed on a poll. Default: 10. |
maxQuestionLength | Maximum poll question length in characters. Default: 500. |
mountPath | URL path prefix for poll routes. Default: /polls. |
rateLimit | Rate-limiting configuration for poll routes. |
Source: packages/slingshot-polls/src/validation/config.ts
PollsRuntimeCap
Section titled “PollsRuntimeCap”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
PollVote
Section titled “PollVote”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
pollVoteFactories
Section titled “pollVoteFactories”Source: packages/slingshot-polls/src/entities/factories.ts
pollVoteOperations
Section titled “pollVoteOperations”PollVote named operations.
listByPoll— all votes for a given poll.myVotes— the authenticated user’s votes on a specific poll. Usesparam: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
Interfaces
Section titled “Interfaces”PollClosedEvent
Section titled “PollClosedEvent”Payload for polls:poll.closed events.
Source: packages/slingshot-polls/src/types/index.ts
PollCreatedEvent
Section titled “PollCreatedEvent”Payload for polls:poll.created events.
Source: packages/slingshot-polls/src/types/index.ts
PollCreateInput
Section titled “PollCreateInput”Fields accepted by the POST /polls/polls route body.
Source: packages/slingshot-polls/src/types/index.ts
PollDeletedEvent
Section titled “PollDeletedEvent”Payload for polls:poll.deleted events.
Source: packages/slingshot-polls/src/types/index.ts
PollRecord
Section titled “PollRecord”A persisted poll record.
Source: packages/slingshot-polls/src/types/index.ts
PollResult
Section titled “PollResult”One row of aggregated results per option.
Source: packages/slingshot-polls/src/types/index.ts
PollResultsParams
Section titled “PollResultsParams”Path params for the GET /polls/polls/:id/results route.
Source: packages/slingshot-polls/src/types/index.ts
PollResultsResponse
Section titled “PollResultsResponse”Full response from the results handler.
Source: packages/slingshot-polls/src/types/index.ts
PollsPluginConfig
Section titled “PollsPluginConfig”Configuration for the polls plugin.
Source: packages/slingshot-polls/src/types/index.ts
PollsPluginState
Section titled “PollsPluginState”Runtime state stored under POLLS_RUNTIME_KEY.
Source: packages/slingshot-polls/src/types/index.ts
PollsRateLimitBucket
Section titled “PollsRateLimitBucket”A rate-limit bucket for a single scope (user or tenant).
Source: packages/slingshot-polls/src/types/index.ts
PollsRateLimitConfig
Section titled “PollsRateLimitConfig”Per-operation rate-limit config. Opt-in — omit to disable limiting.
Source: packages/slingshot-polls/src/types/index.ts
PollsRateLimitRule
Section titled “PollsRateLimitRule”A rate-limit rule for a single operation.
Source: packages/slingshot-polls/src/types/index.ts
PollVoteCreateInput
Section titled “PollVoteCreateInput”Fields accepted by the POST /polls/poll-votes route body.
Source: packages/slingshot-polls/src/types/index.ts
PollVotedEvent
Section titled “PollVotedEvent”Payload for polls:poll.voted events.
Source: packages/slingshot-polls/src/types/index.ts
PollVoteRecord
Section titled “PollVoteRecord”A persisted vote record.
Source: packages/slingshot-polls/src/types/index.ts
PollVoteRetractedEvent
Section titled “PollVoteRetractedEvent”Payload for polls:poll.vote_retracted events.
Source: packages/slingshot-polls/src/types/index.ts
RateLimitBackend
Section titled “RateLimitBackend”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
PollPolicyKey
Section titled “PollPolicyKey”Policy resolver keys used in entity route configs. Consumers register
resolvers under these keys via registerEntityPolicy().
Source: packages/slingshot-polls/src/types/index.ts
PollsRouteKey
Section titled “PollsRouteKey”Every mountable route keyed by entityName.opName. Passed to
PollsPluginConfig.disableRoutes.
Source: packages/slingshot-polls/src/types/index.ts
PollVoteErrorCode
Section titled “PollVoteErrorCode”Source: packages/slingshot-polls/src/types/index.ts