Skip to content

Adapter Interfaces

All adapter methods that perform fallible operations return Result<T>:

type Result<T, E = CommerceError> =
| { ok: true; value: T; meta?: Record<string, unknown> }
| { ok: false; error: E };

Use Ok(value) for success and Err({ code, message }) for failure. Never throw from adapter methods. See Result Types for the rationale.


interface DatabaseAdapter<TDatabase = unknown, TTransaction = unknown> {
provider: string;
db: TDatabase;
transaction<T>(fn: (tx: TTransaction) => Promise<T>): Promise<T>;
}
MemberTypeDescription
providerstringDatabase backend identifier (e.g., "postgresql")
dbTDatabaseThe underlying Drizzle database instance
transaction<T>(fn: (tx: TTransaction) => Promise<T>) => Promise<T>Executes fn within a database transaction

interface PaymentAdapter {
readonly providerId: string;
createPaymentIntent(params: CreatePaymentIntentParams): Promise<Result<PaymentIntent>>;
capturePayment(paymentIntentId: string, amount?: number): Promise<Result<PaymentCapture>>;
refundPayment(paymentId: string, amount: number, reason?: string): Promise<Result<PaymentRefund>>;
cancelPaymentIntent(paymentIntentId: string): Promise<Result<void>>;
verifyWebhook(request: Request): Promise<Result<PaymentWebhookEvent>>;
}
FieldTypeRequired
amountnumberYes
currencystringYes
orderIdstringYes
customerIdstringNo
metadataRecord<string, string>No
terminalIdstringNo
FieldType
idstring
statusstring
amountnumber
currencystring
clientSecretstring | null
FieldType
idstring
statusstring
amountCapturednumber
FieldType
idstring
statusstring
amountRefundednumber
FieldType
idstring
typestring
dataunknown

For implementation guidance, see the Payment Adapter Contract and the Payment Adapter guide.


interface StorageAdapter {
readonly providerId: string;
upload(key: string, data: ArrayBuffer | ReadableStream, contentType: string): Promise<Result<StoredFile>>;
getUrl(key: string): Promise<Result<string>>;
getSignedUrl(key: string, expiresIn: number): Promise<Result<string>>;
delete(key: string): Promise<Result<void>>;
list(prefix: string): Promise<Result<StoredFile[]>>;
}
FieldTypeRequired
keystringYes
urlstringYes
contentTypestringYes
sizenumberNo

interface SearchAdapter {
readonly providerId: string;
index(documents: SearchDocument[]): Promise<Result<void>>;
remove(ids: string[]): Promise<Result<void>>;
search(params: SearchQueryParams): Promise<Result<SearchQueryResult>>;
suggest(params: SearchSuggestParams): Promise<Result<string[]>>;
}
FieldTypeRequired
idstringYes
typestringYes
slugstringYes
titlestringYes
descriptionstringNo
statusstringNo
categoriesstring[]Yes
brandsstring[]Yes
textstringYes
payloadRecord<string, unknown>No
FieldTypeRequired
querystringYes
pagenumberNo
limitnumberNo
filters{ type?, category?, brand?, status? }No
facetsstring[]No
FieldType
hitsSearchHit[]
totalnumber
pagenumber
limitnumber
facetsRecord<string, Record<string, number>>

interface TaxAdapter {
readonly providerId: string;
calculateTax(params: TaxCalculationParams): Promise<Result<TaxCalculationResult>>;
reportTransaction(params: TaxReportParams): Promise<Result<{ transactionId: string }>>;
voidTransaction(params: TaxVoidParams): Promise<Result<{ transactionId: string }>>;
}
FieldTypeRequired
currencystringYes
customerIdstringNo
orderIdstringNo
fromAddressTaxAddressNo
toAddressTaxAddressNo
shippingAmountnumberYes
lineItemsTaxLineItem[]Yes
FieldType
amountToCollectnumber
taxableAmountnumber
ratenumber
breakdownRecord<string, unknown>
FieldTypeRequired
countrystringYes
postalCodestringYes
statestringNo
citystringNo
line1stringNo

interface EmailAdapter {
send(input: {
template: string;
to: string;
data?: Record<string, unknown>;
}): Promise<void>;
}

Any object with a send method matching this signature works. See the Email Notifications guide for setup instructions.


PackageAdapterInterface
@porulle/adapter-postgresPostgreSQL (Drizzle)DatabaseAdapter
@porulle/adapter-local-storageLocal filesystemStorageAdapter
@porulle/adapter-s3AWS S3StorageAdapter
@porulle/adapter-r2Cloudflare R2StorageAdapter
@porulle/adapter-stripeStripePaymentAdapter
@porulle/adapter-resendResendEmailAdapter
@porulle/adapter-sesAWS SES v2EmailAdapter
consoleEmailAdapter()Console (dev)EmailAdapter
@porulle/adapter-meilisearchMeilisearchSearchAdapter
@porulle/adapter-pg-searchPostgreSQL full-text searchSearchAdapter
@porulle/adapter-taxjarTaxJarTaxAdapter
@porulle/adapter-tax-manualManual / flat-rate taxTaxAdapter