openapi: "3.2.0"
jsonSchemaDialect: "https://spec.openapis.org/oas/3.1/dialect/base"
info:
title: "AniCards Public API"
version: "1.0.0"
description: "OpenAPI 3.2.0 specification for AniCards public API endpoints exposed under /api/*."
contact:
name: "Alpha49 (AniCards)"
url: "https://anicards.alpha49.com"
email: "support@alpha49.com"
servers:
- url: "http://localhost:3000"
description: "Local development server (default)"
- url: "https://anicards.alpha49.com"
description: "Production API"
tags:
- name: "anilist"
description: "Proxy to AniList GraphQL"
- name: "card"
description: "Card SVG rendering and export"
- name: "cards"
description: "Stored card configuration retrieval"
- name: "convert"
description: "Convert remote SVG resources into raster images"
- name: "cron"
description: "Background cron endpoints: refresh dispatch, per-user stats refresh, index repair, inactive-user sweep, analytics reporting"
- name: "store"
description: "Store cards and users via POST endpoints"
- name: "user"
description: "Retrieve user data by ID or username"
paths:
/api/anilist:
post:
summary: "Proxy one of the two AniList GraphQL queries the generator sends"
tags:
- "anilist"
description: "Forwards `USER_ID_QUERY` or `USER_STATS_QUERY` from `src/lib/anilist/queries.ts` to AniList and returns its `data`. The document must match one of the two, with whitespace ignored; anything else answers 400. The route sends no AniList token, so it can only read what an anonymous caller can read."
requestBody:
description: "GraphQL POST payload to forward to AniList. `query` must be one of the two allowlisted documents; `variables` is optional."
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/GraphQLRequest"
examples:
sampleQuery:
value:
query: "query GetUserStats($userId: Int!) {\n User(id: $userId) {\n id\n name\n }\n}"
variables: { userId: 1234 }
responses:
"200":
description: "AniList GraphQL data object forwarded back to the client. The structure depends on the query"
content:
application/json:
schema:
$ref: "#/components/schemas/GraphQLSuccess"
examples:
sampleData:
value:
User:
id: 1234
name: "sampleuser"
"400":
description: "The `query` field is missing or is not one of the allowlisted documents."
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
unsupportedOperation:
value: { error: "Unsupported GraphQL operation" }
"429":
description: "Rate-limited (this can be simulated in development by X-Test-Status header)."
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
rateLimited:
value: { error: "Rate limited (test simulation)" }
"500":
description: "Internal server error or upstream AniList error"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
serverError:
value: { error: "Internal server error (test simulation)" }
parameters:
- in: header
name: "X-Test-Status"
schema:
type: string
description: "Development-only header to simulate HTTP status codes (429/500)."
/api/card:
get:
summary: "Render a single card as an SVG image"
tags:
- "card"
parameters:
- in: query
name: userId
required: true
schema:
type: integer
minimum: 1
description: "AniList numeric user ID to render the card for."
- in: query
name: cardType
required: true
schema:
type: string
description: "Base card type; may optionally include a suffix variant separated with a hyphen. Example: 'animeStats' or 'animeStats-vertical'"
enum:
[
"animeStats",
"socialStats",
"mangaStats",
"animeGenres",
"animeTags",
"animeVoiceActors",
"animeStudios",
"animeStaff",
"mangaGenres",
"mangaTags",
"mangaStaff",
"animeStatusDistribution",
"mangaStatusDistribution",
"animeFormatDistribution",
"mangaFormatDistribution",
"animeScoreDistribution",
"mangaScoreDistribution",
"animeYearDistribution",
"mangaYearDistribution",
"animeCountry",
"mangaCountry",
]
- in: query
name: variation
required: false
schema:
type: string
enum:
[
"default",
"vertical",
"pie",
"donut",
"radar",
"compact",
"minimal",
"badges",
"bar",
"horizontal",
"cumulative",
"anime",
"manga",
"characters",
"mixed",
"github",
"fire",
"combined",
"split",
]
description: "Optional rendering variation; also settable inside stored card configuration."
- in: query
name: showFavorites
required: false
schema:
type: boolean
description: "When true, displays favorites hearts inside the card visual."
- in: query
name: statusColors
required: false
schema:
type: boolean
description: "When true, uses fixed status colors for status-distribution cards."
- in: query
name: piePercentages
required: false
schema:
type: boolean
description: "When true and rendering a pie variant, shows percentage labels on the pie slices."
- in: query
name: _t
required: false
schema:
type: string
description: >
Cache buster. Its presence asks the endpoint not to use a stored
copy of the card, so the card is rendered from current data. The
value is never read: any value, including an empty one, has the
same effect. A request without this parameter is served from the
cache whenever a cached copy is available.
responses:
"200":
description: "SVG image payload representing the requested card. Returns image/svg+xml content type."
headers:
Cache-Control:
schema:
type: string
description: >-
`public, max-age=86400, s-maxage=86400, stale-while-revalidate=604800,
stale-if-error=1209600`. The edge caches the response for a day.
X-Cache-Source:
schema:
type: string
enum: ["memory", "render", "bypass"]
description: >-
Where the returned SVG came from. `memory` means this process
already had the render. `render` means it was produced for this
request. `bypass` means the request carried `_t` and asked not
to use a stored copy.
X-Card-Border-Radius:
schema:
type: string
description: "The border radius the card was rendered with."
content:
image/svg+xml:
schema:
type: string
format: binary
description: "Raw SVG document in text form"
examples:
basicSvg:
value: ''
"400":
description: "Client error (missing/invalid parameters). The response is an error SVG with an error message inside."
content:
image/svg+xml:
schema:
type: string
format: binary
examples:
missingParam:
value: ''
"404":
description: "User or stored card not found; returns an SVG with not found message (404)."
content:
image/svg+xml:
schema:
type: string
format: binary
examples:
notFound:
value: ''
"429":
description: "Rate-limited (returned as an SVG)"
content:
image/svg+xml:
schema: { type: string, format: binary }
examples:
rateLimit:
value: ''
"500":
description: "Server error while generating the SVG. Returns an error SVG text."
content:
image/svg+xml:
schema:
type: string
format: binary
examples:
internalError:
value: ''
/api/get-cards:
get:
summary: "Retrieve the stored card configuration for a user"
tags:
- "cards"
parameters:
- in: query
name: userId
required: true
schema:
type: integer
minimum: 1
description: "Numeric AniList userId whose stored cards are fetched from Redis."
responses:
"200":
description: "Cards record corresponding to the userId"
content:
application/json:
schema:
$ref: "#/components/schemas/CardsRecord"
examples:
sampleRecord:
value:
userId: 12345
updatedAt: "2025-01-01T12:00:00.000Z"
cards:
- cardName: "animeOverview"
variation: "default"
titleColor: "#ffffff"
backgroundColor: "#0f172a"
textColor: "#e5e7eb"
circleColor: "#14b8a6"
showFavorites: true
"400":
description: "Missing or invalid userId parameter"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
missingUserId:
value: { error: "Missing user ID parameter" }
"404":
description: "No stored cards found for the user"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
notFound:
value: { error: "Cards not found" }
"429":
description: "Rate-limited (10 requests per 5 seconds per client address)"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
rateLimited:
value: { error: "Too many requests" }
"500":
description: "Server error while reading Redis"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
/api/convert:
post:
summary: "Fetch a remote SVG, sanitize and convert it into a raster data URL"
tags:
- "convert"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/ConvertRequest"
examples:
pngRequest:
value:
{ svgUrl: "https://example.com/image.svg", format: "png" }
webpRequest:
value:
{ svgUrl: "https://example.com/image.svg", format: "webp" }
responses:
"200":
description: "Returns a base64-encoded raster data URL for the requested raster format (png or webp)."
content:
application/json:
schema:
$ref: "#/components/schemas/ConvertResponse"
examples:
examplePngDataUrl:
value:
{
pngDataUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...",
}
"400":
description: "Bad request: missing svgUrl or invalid format or invalid URL"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
badRequest:
value: { error: "Invalid format parameter" }
"403":
description: "Unauthorized domain or protocol for the requested svgUrl (SSRF protection)"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
forbidden:
value: { error: "Unauthorized or unsafe domain/protocol" }
"500":
description: "Internal conversion error"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
conversionFailed:
value: { error: "Conversion failed" }
/api/cron:
post:
summary: "Dispatch the AniList stats refresh for the stalest users."
description: >
Selects the stalest users that are not cooling down and publishes one
QStash message per selected user to `/api/cron/refresh-user`. The
response reports the messages published, not per-user refresh results;
those appear in the QStash log and the dead letter queue. A user whose
publish failed stays in the refresh index, so the next run selects them
again.
Index repair and orphan reconciliation are not part of this endpoint.
They run on their own daily schedule at `/api/cron/repair-index`, so a
refresh failure cannot skip the cleanup and a cleanup failure cannot
fail the refresh.
The one repair this endpoint still performs is the empty-index
bootstrap: a dispatch cannot select from an empty index, so it rebuilds
one when it finds none.
tags:
- "cron"
parameters:
- in: header
name: x-cron-secret
schema:
type: string
description: "Optional CRON secret header used to safeguard the endpoint; required when CRON_SECRET is set in the environment."
security:
- CronSecret: []
responses:
"200":
description: "Dispatch summary: messages published, their ids, and the selection that produced them. Returned unless every publish failed or the run could not complete, so an idle run with nothing to publish also answers 200."
content:
application/json:
schema:
$ref: "#/components/schemas/CronDispatchResult"
examples:
success:
value:
published: 2
failed: 0
messageIds: ["msg_example_1", "msg_example_2"]
failedUserIds: []
selection:
indexedUsers: 645
batchSize: 5
candidates: 2
coolingDown: 0
eligible: 2
pagesRead: 1
indexExhausted: true
oldestStaleRecord: "42 minutes"
indexRebuilt: false
idle:
value:
published: 0
failed: 0
messageIds: []
failedUserIds: []
selection:
indexedUsers: 645
batchSize: 5
candidates: 5
coolingDown: 5
eligible: 0
pagesRead: 1
indexExhausted: true
oldestStaleRecord: "12 minutes"
indexRebuilt: false
"401":
description: "Unauthorized - invalid or missing cron secret header"
content:
text/plain:
schema:
type: string
examples:
unauthorized:
value: "Unauthorized"
"503":
description: >
The endpoint cannot run. Two causes: `CRON_SECRET` is unset (plain
text body), or no usable app origin is configured (JSON body). An
origin is usable when it is https, or http on loopback.
content:
text/plain:
schema:
type: string
examples:
notConfigured:
value: "Cron authorization is not configured"
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
noOrigin:
value:
error: "Cron dispatch is not configured: no app origin"
"500":
description: >
Every publish failed, or the run could not complete. A failed run
that reached selection returns the dispatch payload with an
`error` field; a run that failed earlier returns `ApiError`.
content:
application/json:
schema:
oneOf:
- $ref: "#/components/schemas/CronDispatchResult"
- $ref: "#/components/schemas/ApiError"
examples:
allPublishesFailed:
value:
published: 0
failed: 2
messageIds: []
failedUserIds: ["123", "456"]
selection:
indexedUsers: 645
batchSize: 5
candidates: 2
coolingDown: 0
eligible: 2
pagesRead: 1
indexExhausted: true
oldestStaleRecord: "42 minutes"
indexRebuilt: false
queueUnavailable:
value:
published: 0
failed: 2
messageIds: []
failedUserIds: ["123", "456"]
selection:
indexedUsers: 645
batchSize: 5
candidates: 2
coolingDown: 0
eligible: 2
pagesRead: 1
indexExhausted: true
oldestStaleRecord: "42 minutes"
indexRebuilt: false
error: "publish-unavailable"
unhandled:
value: { error: "Cron job failed" }
/api/cron/refresh-user:
post:
summary: "Refresh one user's AniList stats (QStash consumer)"
description: >
Internal endpoint. The dispatcher publishes one message per user here.
Returns 200 for every outcome the code handles and 500 only for a
failure another delivery could fix, which is what makes QStash retry.
A malformed body answers 489 with `Upstash-NonRetryable-Error: true`,
which sends the message straight to the dead letter queue.
tags:
- "cron"
parameters:
- $ref: "#/components/parameters/x-cron-secret-header"
security:
- CronSecret: []
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
userId:
description: "Numeric AniList user id, as a string or an integer"
oneOf:
- type: string
pattern: "^[0-9]+$"
- type: integer
minimum: 1
maximum: 2147483647
required: ["userId"]
responses:
"200":
description: "Handled outcome: stats updated, stale index entry removed, AniList 404 counted, user removed, duplicate delivery, or a rejected record"
content:
application/json:
schema:
$ref: "#/components/schemas/RefreshUserResult"
"401":
$ref: "#/components/responses/UnauthorizedPlain"
"503":
$ref: "#/components/responses/CronNotConfiguredPlain"
"489":
description: "Request body is not a valid user id; QStash must not retry and moves the message to the dead letter queue"
headers:
Upstash-NonRetryable-Error:
schema:
type: string
enum: ["true"]
description: "Tells QStash to skip retries"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
"500":
description: "AniList timeout or 5xx, or a Redis failure; QStash retries the message"
content:
application/json:
schema:
$ref: "#/components/schemas/RefreshUserResult"
/api/cron/repair-index:
post:
summary: "Rebuild the user refresh index and reconcile orphaned keys"
description: >
Daily housekeeping, scheduled separately from the refresh dispatch.
Rescores every stored user in `users:refresh-index` from their meta
part, drops index entries whose record is gone, then deletes `cards:`
and `username:` keys whose `user::meta` no longer exists.
The rebuild and the cleanup fail independently: a cleanup failure is
reported as null and does not discard a successful rebuild. A rebuild
failure answers 500 so QStash retries, and releases the lease so the
retry does not wait out the 24 hour window.
A 200 with `outcome: skipped` means another invocation holds the lease.
That is the overlap guard, not an error.
tags:
- "cron"
parameters:
- $ref: "#/components/parameters/x-cron-secret-header"
security:
- CronSecret: []
responses:
"200":
description: "The repair ran, or another invocation owns the window"
content:
application/json:
schema:
$ref: "#/components/schemas/RepairIndexResult"
examples:
repaired:
value:
outcome: "repaired"
totalUsers: 645
rebuildCounts:
indexedUsers: 645
missingMetaCount: 0
malformedMetaCount: 0
droppedStaleMembers: 2
reconciliation:
cardsKeysScanned: 610
orphanedCardsKeys: 3
deletedCardsKeys: 3
usernameKeysScanned: 645
orphanedUsernameKeys: 1
deletedUsernameKeys: 1
skipped:
value:
outcome: "skipped"
totalUsers: 645
reason: "another invocation holds the repair lease"
"401":
$ref: "#/components/responses/UnauthorizedPlain"
"503":
$ref: "#/components/responses/CronNotConfiguredPlain"
"500":
description: >
The rebuild or the lease claim failed, or the rebuild succeeded but
the key cleanup did not. QStash retries in every case; the rebuild
is idempotent.
content:
application/json:
schema:
$ref: "#/components/schemas/RepairIndexResult"
examples:
rebuildFailed:
value:
outcome: "failed"
reason: "index-rebuild-failed"
cleanupFailed:
value:
outcome: "partial"
totalUsers: 645
rebuildCounts:
indexedUsers: 645
missingMetaCount: 0
malformedMetaCount: 0
droppedStaleMembers: 2
reason: "key-reconciliation-failed"
/api/cron/inactive-sweep:
post:
summary: "Remove stored users that no card request has reached inside the activity window"
description: >
Daily housekeeping, scheduled an hour after `/api/cron/repair-index` so
the two jobs that walk the whole key space never overlap. A user is
removed only when all three conditions hold: no `user_activity:` key
exists, the `createdAt` of `user::meta` is at least 30 days old, and
the run is allowed to delete.
The age check reads `createdAt`, not `updatedAt`. The refresh consumer
writes `updatedAt` on every scheduled refresh, so it records when
AniList was last called rather than when a person last used the service.
A record with no readable `createdAt` is treated as too new and kept.
Deletion is a dry run unless `INACTIVE_SWEEP_DELETE` is `true`. The
`dryRun` query parameter overrides that setting in both directions:
`dryRun=true` reports only, and `dryRun=false` deletes on a deployment
where the variable is unset. One run removes at most 200 users to stay
inside the route's 300 second limit. Deletion is idempotent, so the next
run continues from where this one stopped.
A dry run releases the overlap lease when it finishes. A deleting run
keeps it, so a QStash redelivery does not rescan the key space.
tags:
- "cron"
parameters:
- $ref: "#/components/parameters/x-cron-secret-header"
- in: query
name: "dryRun"
required: false
schema:
type: string
enum: ["true", "false"]
description: >
Overrides `INACTIVE_SWEEP_DELETE` for this request. `true` reports
without deleting. `false` deletes even when the environment
variable is not `true`. Any other value falls back to the
environment variable.
security:
- CronSecret: []
responses:
"200":
description: >
The sweep ran, or another invocation owns the window. A run in
which some deletions failed still answers 200 with
`outcome: partial`; the next run retries those users.
content:
application/json:
schema:
$ref: "#/components/schemas/InactiveSweepResult"
examples:
dryRun:
value:
outcome: "swept"
usersScanned: 645
candidates: 402
deleted: 0
failed: 0
dryRun: true
swept:
value:
outcome: "swept"
usersScanned: 645
candidates: 402
deleted: 200
failed: 0
dryRun: false
partial:
value:
outcome: "partial"
usersScanned: 645
candidates: 402
deleted: 198
failed: 2
dryRun: false
skipped:
value:
outcome: "skipped"
reason: "another invocation holds the sweep lease"
leaseExpiresInSeconds: 612
"401":
$ref: "#/components/responses/UnauthorizedPlain"
"503":
$ref: "#/components/responses/CronNotConfiguredPlain"
"500":
description: >
The run could not complete, so QStash retries. When the sweep itself
fails, the lease is released first, so the retry does not wait out
the 15 minute window. A rejected lease claim releases nothing,
because the claim never succeeded.
content:
application/json:
schema:
$ref: "#/components/schemas/InactiveSweepResult"
examples:
leaseUnavailable:
value:
outcome: "failed"
reason: "sweep-lease-unavailable"
sweepFailed:
value:
outcome: "failed"
reason: "inactive-sweep-failed"
/api/cron/analytics-reporting:
post:
summary: "Generate analytics report and persist it to Redis"
tags:
- "cron"
parameters:
- $ref: "#/components/parameters/x-cron-secret-header"
security:
- CronSecret: []
responses:
"200":
description: "Analytics report object persisted and returned"
content:
application/json:
schema:
$ref: "#/components/schemas/AnalyticsReport"
"401":
$ref: "#/components/responses/UnauthorizedPlain"
"500":
$ref: "#/components/responses/InternalErrorPlain"
/api/store-cards:
post:
summary: "Store or update a user's card configuration in Redis"
description: >
Saves the card configuration for a numeric user ID. A user record is
not required first: the endpoint accepts a card save for a user ID
that has no stored record, and the daily reconciliation keeps that
save instead of treating it as an orphan for the first hour after it
is written. Send `/api/store-users` as well, because card rendering
reads the user record.
tags:
- "store"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/StoreCardsRequest"
examples:
sampleStore:
value:
userId: 12345
statsData: { User: { stats: {} } }
cards:
- cardName: "animeOverview"
variation: "default"
titleColor: "#fff"
backgroundColor: "#0f172a"
textColor: "#e2e8f0"
circleColor: "#14b8a6"
responses:
"200":
description: "Success response when the card config was stored"
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
userId:
type: integer
examples:
stored:
value: { success: true, userId: 12345 }
"400":
description: "Invalid data provided"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
"500":
$ref: "#/components/responses/InternalErrorJson"
/api/store-users:
post:
summary: "Store or update a user's AniList record in Redis"
tags:
- "store"
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/StoreUserRequest"
examples:
sampleUser:
value:
userId: 12345
username: "sampleuser"
stats: { User: {} }
responses:
"200":
description: "Success response when user was stored"
content:
application/json:
schema:
type: object
properties:
success:
type: boolean
userId:
type: integer
examples:
stored:
value: { success: true, userId: 12345 }
"400":
description: "Invalid user data"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
/api/get-user:
get:
summary: "Retrieve stored user data by numeric userId or username"
description: >
Returns the user record rebuilt from its stored parts. The response
carries a weak `ETag` derived from the parts returned and the meta
`updatedAt` the cron writes. When `activity` is among the requested
parts, the last card request time is part of the tag as well, because
the body then depends on it. Send the tag back in `If-None-Match` to
receive `304 Not Modified` when the record has not changed.
`Cache-Control` is `private, no-cache`, so a shared cache never stores
the response.
tags:
- "user"
parameters:
- in: query
name: userId
required: false
schema:
type: integer
minimum: 1
description: "numeric AniList user id (prefer for exact matching)"
- in: query
name: username
required: false
schema:
type: string
description: "username string; resolved against the username index to a numeric id. One of userId or username must be provided."
- in: query
name: parts
required: false
schema:
type: string
enum:
[
"meta",
"activity",
"favourites",
"statistics",
"pages",
"planning",
"current",
"rewatched",
"completed",
"aggregates",
]
style: form
explode: false
description: >
Comma-separated list of stored parts to return. `meta` is always
returned because it carries the identity fields. When omitted,
every part is returned. Unknown part names return 400. The
`lastCardRequestAt` and `isActive` fields come from the activity
record and are returned only when `activity` is requested.
responses:
"200":
description: "User record stored in Redis"
headers:
ETag:
schema:
type: string
description: "Weak validator for the returned record."
content:
application/json:
schema:
$ref: "#/components/schemas/UserRecord"
"304":
description: >
The record still matches the `If-None-Match` validator. The body
is empty and the headers match a 200 response.
"400":
description: "Missing or invalid parameters"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
"404":
description: "User not found"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
"429":
description: "Rate-limited (10 requests per 5 seconds per client address)"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
examples:
rateLimited:
value: { error: "Too many requests" }
components:
securitySchemes:
CronSecret:
type: apiKey
in: header
name: x-cron-secret
description: "A cron-specific secret header that protects background endpoints. If unset, these endpoints answer 503 and run nothing."
parameters:
x-cron-secret-header:
in: header
name: x-cron-secret
schema:
type: string
description: "Cron secret; required when CRON_SECRET environment variable is set."
responses:
UnauthorizedPlain:
description: "Unauthorized - Cron secret failed"
content:
text/plain:
schema:
type: string
examples:
unauthorized:
value: "Unauthorized"
CronNotConfiguredPlain:
description: "CRON_SECRET is unset, so the endpoint refuses to run"
content:
text/plain:
schema:
type: string
examples:
notConfigured:
value: "Cron authorization is not configured"
InternalErrorPlain:
description: "Internal server error (plain text)"
content:
text/plain:
schema:
type: string
InternalErrorJson:
description: "Internal server error (JSON)"
content:
application/json:
schema:
$ref: "#/components/schemas/ApiError"
schemas:
ApiError:
type: object
properties:
error:
type: string
required: ["error"]
example: { error: "Invalid data" }
GraphQLRequest:
type: object
properties:
query:
type: string
description: "GraphQL query or mutation string"
variables:
type: object
additionalProperties: true
description: "Optional variables for the GraphQL query or mutation"
required: ["query"]
GraphQLSuccess:
type: object
additionalProperties: true
description: "Arbitrary GraphQL 'data' object returned by AniList. The keys depend on the query run."
example:
User:
id: 1234
name: "sampleuser"
StoredCardConfig:
type: object
description: "Stored configuration for a single card"
properties:
variation:
type: string
description: "Template variation name"
enum:
[
"default",
"vertical",
"pie",
"donut",
"radar",
"compact",
"minimal",
"badges",
"bar",
"horizontal",
"cumulative",
"anime",
"manga",
"characters",
"mixed",
"github",
"fire",
"combined",
"split",
]
cardName:
type: string
description: "Unique name for the card template (used as identifier)"
titleColor:
type: string
description: "Hex or gradient defining the title color"
backgroundColor:
type: string
textColor:
type: string
circleColor:
type: string
borderColor:
type: string
borderRadius:
type: number
showFavorites:
type: boolean
useStatusColors:
type: boolean
showPiePercentages:
type: boolean
required:
[
"variation",
"cardName",
"titleColor",
"backgroundColor",
"textColor",
"circleColor",
]
CardsRecord:
type: object
properties:
userId:
type: integer
cards:
type: array
items:
$ref: "#/components/schemas/StoredCardConfig"
updatedAt:
type: string
format: date-time
required: ["userId", "cards", "updatedAt"]
example:
userId: 12345
updatedAt: "2025-01-01T12:00:00.000Z"
cards:
- cardName: "mangaOverview"
variation: "default"
titleColor: "#ffffff"
backgroundColor: "#0f172a"
textColor: "#cbd5e1"
circleColor: "#06b6d4"
showFavorites: true
ConvertRequest:
type: object
properties:
svgUrl:
type: string
format: uri
description: "Absolute or relative URL that resolves to an SVG resource."
format:
type: string
enum: ["png", "webp"]
required: ["svgUrl"]
ConvertResponse:
type: object
properties:
pngDataUrl:
type: string
description: "Base64-encoded data URL representing the converted raster resource."
required: ["pngDataUrl"]
example:
{ pngDataUrl: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." }
StoreCardsRequest:
type: object
properties:
userId:
type: integer
statsData:
type: object
additionalProperties: true
cards:
type: array
maxItems: 24
items:
$ref: "#/components/schemas/StoredCardConfig"
required: ["userId", "cards"]
StoreUserRequest:
type: object
properties:
userId:
type: integer
username:
type: string
stats:
type: object
description: "AniList user statistics payload as returned by GraphQL"
additionalProperties: true
required: ["userId", "stats"]
UserRecord:
type: object
description: "User data stored in Redis including statistics and favorites"
properties:
userId:
type: string
username:
type: string
stats:
type: object
additionalProperties: true
description: "User stats shape as returned from AniList GraphQL (highly nested)."
createdAt:
type: string
format: date-time
updatedAt:
type: string
format: date-time
description: "When the record was last written. This is the refresh queue's score, so it advances on every scheduled refresh whether or not the numbers moved. Do not use it to decide whether a rendered card is out of date."
dataUpdatedAt:
type: string
format: date-time
nullable: true
description: "When the stats a card renders from last changed. A scheduled refresh that finds identical stats leaves this alone, so a card URL stays valid and cached copies keep serving. This is the card URL's version, and is distinct from updatedAt. Absent on a record written before the field existed."
lastCardRequestAt:
type: string
format: date-time
nullable: true
description: "When a card was last successfully requested for this user; null when no card request is recorded. Present only when the `activity` part is requested."
isActive:
type: boolean
description: "True when a card for this user was requested within the last 30 days. Cron stats refreshes do not affect this value. Present only when the `activity` part is requested."
required: ["userId", "stats", "createdAt", "updatedAt"]
AnalyticsReport:
type: object
properties:
summary:
type: string
raw_data:
type: object
additionalProperties:
type: number
generatedAt:
type: string
format: date-time
required: ["summary", "raw_data", "generatedAt"]
example:
summary: "Collected analytics metrics snapshot"
raw_data:
"analytics:store_cards:successful_requests": 10
"analytics:store_users:failed_requests": 2
generatedAt: "2025-01-01T12:00:00.000Z"
CronDispatchResult:
type: object
description: "Summary of one dispatcher run. Per-user outcomes are in the QStash log."
properties:
published:
type: integer
description: "Messages accepted by QStash"
failed:
type: integer
description: "Publishes that threw; those users stay in the refresh index"
messageIds:
type: array
items:
type: string
failedUserIds:
type: array
items:
type: string
selection:
type: object
properties:
indexedUsers:
type: integer
batchSize:
type: integer
description: "Users this run may publish: a 48th of the index rounded up, clamped to 1..5"
candidates:
type: integer
coolingDown:
type: integer
eligible:
type: integer
pagesRead:
type: integer
indexExhausted:
type: boolean
oldestStaleRecord:
type: string
description: "Age of the oldest selected record, `none` when nothing was selected, or `unknown` for an unreadable score"
required:
[
"indexedUsers",
"batchSize",
"candidates",
"coolingDown",
"eligible",
"pagesRead",
"indexExhausted",
"oldestStaleRecord",
]
indexRebuilt:
type: boolean
description: "True only when the dispatch found an empty index and rebuilt it before selecting"
required: ["published", "failed", "messageIds", "failedUserIds"]
RepairIndexResult:
type: object
description: >
Outcome of one index repair attempt. `partial` means the rebuild ran and
the key cleanup did not; it answers 500 so QStash retries the cleanup.
properties:
outcome:
type: string
enum: ["repaired", "partial", "skipped", "failed"]
totalUsers:
type: integer
description: "Index size after the attempt"
reason:
type: string
description: >
A short code, never an exception message. Examples:
`index-rebuild-failed`, `key-reconciliation-failed`,
`repair-lease-unavailable`.
leaseExpiresInSeconds:
type: integer
description: "Present on a skip: seconds until the held lease expires, or -1 when it has no TTL"
rebuildCounts:
type: object
properties:
indexedUsers:
type: integer
missingMetaCount:
type: integer
malformedMetaCount:
type: integer
droppedStaleMembers:
type: integer
reconciliation:
type: object
description: "Per-prefix scan and deletion counts; absent when the cleanup failed, which is the `partial` outcome"
properties:
cardsKeysScanned:
type: integer
orphanedCardsKeys:
type: integer
deletedCardsKeys:
type: integer
usernameKeysScanned:
type: integer
orphanedUsernameKeys:
type: integer
deletedUsernameKeys:
type: integer
required: ["outcome"]
InactiveSweepResult:
type: object
description: >
Counts from one inactive-user sweep run. A dry run reports what it would
remove and removes nothing.
properties:
outcome:
type: string
enum: ["swept", "partial", "skipped", "failed"]
description: >
`swept` means every deletion succeeded. It also describes a dry run,
which the `dryRun` flag distinguishes. `partial` means at least one
deletion failed and the next run retries it. `skipped` means another
invocation holds the lease. `failed` means the run could not
complete.
usersScanned:
type: integer
description: "Stored users examined."
candidates:
type: integer
description: "Users with no activity key that are past the 30 day window."
deleted:
type: integer
description: "Users whose storage was removed. Always 0 on a dry run."
failed:
type: integer
description: "Users whose deletion failed; the next run retries them."
dryRun:
type: boolean
description: "True when no deletion was attempted."
reason:
type: string
description: >
Present on `skipped` and `failed`. On a skip it is the text
`another invocation holds the sweep lease`. Otherwise it is a short
code, never an exception message, for example
`sweep-lease-unavailable` or `inactive-sweep-failed`.
leaseExpiresInSeconds:
type: integer
description: "Present on a skip: seconds until the held lease expires, or -1 when it has no TTL"
required: ["outcome"]
RefreshUserResult:
type: object
description: "Outcome of one refresh attempt."
properties:
userId:
type: string
outcome:
type: string
enum:
[
"updated",
"stale-index-entry-removed",
"not-found",
"removed",
"duplicate-delivery",
"rejected",
"retryable",
]
failures:
type: integer
description: "Recorded AniList 404 count, present for `not-found`"
reason:
type: string
description: >
A short code for `rejected` or `retryable`, never an exception
message: the detail stays in the server log because QStash keeps
and displays this body.
enum:
[
"invalid-stored-user-id",
"record-validation-failed",
"anilist-unavailable",
"redis-read-failed",
"index-entry-removal-failed",
"failure-claim-failed",
"failure-record-failed",
"record-save-failed",
]
required: ["userId", "outcome"]