Docs
BlogHomeStart building

Types (totalum-sdk)


The types every module shares: the client options and the error.

#TotalumClientOptions

The options every namespace takes; each one falls back to the same environment variable everywhere.

NameTypeRequiredDescription
keystringnoProject key tlm_pk_…; default TOTALUM_PROJECT_KEY. Server-side only.
apiUrlstringnoThe Totalum API's URL: default TOTALUM_SDK_API_URL, else https://sdk-api.totalum.app.
env'dev' | 'live'noSent as x-totalum-env on every call (the database it targets, and dev vs live usage); default TOTALUM_ENV, else live.

#TotalumError

The one error every totalum-sdk call throws: the Totalum API envelope's frozen errorCode, the HTTP status and details. TotalumD1Error (totalum-sdk/d1) and TotalumWebhookError (totalum-sdk/webhooks) extend it, so one isTotalumError(e) check covers the whole package.

MemberTypeDescription
namestring'TotalumError' (or the subclass's name).
errorCodeTotalumErrorCodeThe frozen error code (FILE_NOT_FOUND, INSUFFICIENT_CREDITS, …): branch on it, never on message.
statusnumberHTTP status; 0 for network errors, 500 for client-side refusals.
detailsRecord<string, unknown>Extra data about the failure (maxBytes, retryAfterMs, the field that failed validation), when any.
requestIdstringthe Totalum API's request id, for support and the logs explorer.
MethodDescription
toString() → stringTotalumError [CODE]: message — what a log shows for String(err) (workerd's tail serialises an Error so).
toJSON() → Record<string, unknown>Every field a log or Response.json needs (undefined ones drop out); workerd's tail logs an Error through this.

#TotalumErrorCode

Every code a TotalumError can carry: the Totalum API's frozen codes plus the client-side ones (see Errors).

ts
type TotalumErrorCode = 'SERVICE_UNAUTHORIZED' | 'SERVICE_REPLAY' | 'ACTOR_MISMATCH' | 'PAYLOAD_TOO_LARGE' | 'VALIDATION_ERROR' | 'PROJECT_NOT_FOUND' | 'PROJECT_NOT_READY' | 'OPERATION_IN_PROGRESS' | … // 421 values

#isTotalumError type

Whether e is an error thrown by totalum-sdk (TotalumError or a subclass): then e.errorCode, e.status, e.details and e.requestId are typed.

ts
type isTotalumError = any