SPB Git

Repository Public

types.ts 4.0 KB 92 lines typescript

1// Friendly names over the generated contract types (src/generated.ts, generated from docs/OPENAPI.yaml).2import type { Operations, OutboundMessage } from "./generated.js"34export type {5  Address, AddressCreateParams, AddressKind, AddressUpdateParams, Attachment, AttachmentRef, Automation, AutomationUpdateParams, BatchResult, Changes,6  DraftCreateParams, DraftUpdateParams, EmailAddress, ErrorBody, Event, Folder, FolderCreateParams, FolderRef, ForwardParams, Health, Me, MeAddress, Message,7  MessageAuth, MessageSummary, MessageUpdateParams, Operations, OutboundMessage, OutboundRecipient, OutboundStatus, Recipient, RenderedTemplate, ReplyParams,8  SendParams, Template, TemplateRenderParams, TemplateSummary, TemplateVariable, Thread, ThreadSummary, UploadedFile, Webhook, WebhookCreateParams,9  WebhookDelivery, WebhookEventType, WebhookTestResult, WebhookUpdateParams,10} from "./generated.js"1112/** One page of a cursor-paginated list. `next_cursor` is null on the last page. */13export interface Page<T> {14  data: T[]15  next_cursor: string | null16  has_more: boolean17}1819// Query strings carry booleans as "true"/"false"; the SDK accepts real booleans (and string arrays for comma-separated lists).20type Friendly<Q> = { [K in keyof Q]: [NonNullable<Q[K]>] extends ["true" | "false"] ? boolean | Q[K] : Q[K] }21type Q<Id extends keyof Operations> = Friendly<Operations[Id]["query"]>2223export type MessageListParams = Omit<Q<"getMessages">, "address"> & { address?: string | string[] }24export type ThreadListParams = Omit<Q<"getThreads">, "address"> & { address?: string | string[] }25export type ChangesParams = Q<"getMessagesChanges">26export type OutboundListParams = Q<"getMessagesOutbound">27export type ScheduledListParams = Q<"getMessagesScheduled">28export type DraftListParams = Q<"getDrafts">29export type AddressListParams = Q<"getAddresses">30export type EventListParams = Q<"getEvents">31export type WebhookDeliveryListParams = Q<"getWebhooksIdDeliveries">32export type FolderRole = "inbox" | "drafts" | "sent" | "trash" | "junk" | "archive"3334/** Statuses after which a send no longer changes (docs/API.md §7). */35export const FINAL_STATUSES = ["delivered", "bounced", "failed", "cancelled"] as const36export type FinalStatus = (typeof FINAL_STATUSES)[number]3738/** Send by template: `template_id` + `variables`, without `html`/`text` (docs/API.md §15 Templates). */39export type TemplateSendParams = Omit<import("./generated.js").SendParams, "html" | "text"> & { template_id: string; variables?: Record<string, string> }4041export interface DownloadedAttachment {42  data: Uint8Array43  /** File name announced by the server (`Content-Disposition`), when present. */44  filename: string | null45  size: number46}4748export interface UploadParams {49  /** File content. */50  data: Uint8Array | ArrayBuffer | Blob | string51  filename: string52  /** MIME type of the file (default `application/octet-stream`). `multipart/form-data` is refused by the API. */53  contentType?: string54  /** Mailbox the file is uploaded for; required when the key can send from several mailboxes. */55  address?: string56}5758/** Payload POSTed to a webhook endpoint (docs/API.md §11.3). */59export interface WebhookEvent<D = Record<string, unknown>> {60  id: string61  type: import("./generated.js").WebhookEventType | "webhook.test" | (string & {})62  occurred_at: string63  address: string | null64  mailbox: string | null65  data: D66}67/** `data` of `message.received`. `subject`/`preview` only with `include_content: true`. */68export interface MessageReceivedData {69  message_id: string70  thread_id: string71  address: string72  from: string[]73  to: string[]74  cc: string[]75  delivered_to: string[]76  received_at: string77  size: number78  has_attachment: boolean79  folders: string[]80  subject?: string81  preview?: string82}83/** `data` of `message.sent` / `delivered` / `deferred` / `bounced` / `failed`. */84export interface MessageStatusData {85  outbound_id: string86  message_id: string | null87  from: string88  status: OutboundMessage["status"]89  recipients: OutboundMessage["recipients"]90}9192
Files main
Menu

Theme