STEP 4-3
Type definitions (TypeScript)
If you implement in TypeScript, copy the type definitions below and place them as checkout-plus.d.ts in a folder included by your tsconfig (e.g. types/). Then you can use types such as window.rcmr.checkoutPlus, CheckoutPlusSession, and CartConnector. If you implement in JavaScript, you don't need this file.
The type definitions are not served from a URL. During /v1/, fields are only added, so the type definitions you placed keep working after the SDK is updated. Added fields are listed in the Changelog; to use them, copy the type definitions from this page again. The meaning of each field and the rules are on the pages of the Reference.
types/checkout-plus.d.ts
// `types/checkout-plus.d.ts` (copy it from this page into a folder included by your tsconfig)
// The meaning of each field and the rules are on the reference pages of the guide
declare global {
interface WindowEventMap {
/** Dispatched on `window` when the SDK script finishes loading */
'recustomer-checkout-plus:ready': Event
}
interface Window {
/** After the SDK script loads, `window.rcmr.checkoutPlus` is available */
rcmr?: RcmrGlobal
}
interface RcmrGlobal {
checkoutPlus?: CheckoutPlusGlobal
}
interface CheckoutPlusGlobal {
init(options: CheckoutPlusInitOptions): CheckoutPlusSession
}
/** Implemented by the SDK user. See the `getCart` and `updateCheckoutPlusLines` pages in the guide */
interface CartConnector {
getCart(): Promise<CheckoutPlusCart | null>
updateCheckoutPlusLines(change: CheckoutPlusLineChange): Promise<'applied' | 'rejected'>
}
interface CheckoutPlusCart {
currency: string
metafield: { value: string } | null
lines: CheckoutPlusCartLine[]
}
interface CheckoutPlusCartLine {
id: string
variantId: string
productHandle: string
title: string
quantity: number
lineTotal: string
tags: string[]
attributes: { key: string; value: string }[]
}
interface CheckoutPlusLineChange {
remove: string[]
add: { variantId: string; quantity: 1; attributes: { key: string; value: string }[] } | null
}
/** See the `init` page in the guide */
interface CheckoutPlusInitOptions {
storeId: string
cart: CartConnector
locale?: string
displaySettings?: CheckoutPlusDisplaySettings
initialSelection?: boolean
onCheckoutPlusLinesChange?: () => void
onError?: (error: { kind: string }) => void
}
/** See `displaySettings` on the `init` page in the guide */
interface CheckoutPlusDisplaySettings {
title?: string
description?: string
detailsButtonLabel?: string
shippingBadgeLabel?: string
cashbackBadgeLabel?: string
exclusionNotice?: string
excludedItemFormat?: string
excludedItemSeparator?: string
detailsModal?: {
heroImageUrl?: string
logoImageUrl?: string
logoImageAlt?: string
html?: string
ariaLabel?: string
closeButtonAriaLabel?: string
poweredByLinkAriaLabel?: string
}
}
/** See the `mount`, `refresh`, `prepareCheckout`, `isCheckoutPlusLine`, and `destroy` pages in the guide */
interface CheckoutPlusSession {
mount(target: HTMLElement): { unmount(): void }
refresh(): Promise<void>
prepareCheckout(): Promise<CheckoutPreparation>
isCheckoutPlusLine(line: { merchandise?: { product?: { handle?: string | null } | null } | null }): boolean
destroy(): void
}
/** The return value of `prepareCheckout`. Returned as an object so that fields can be added later */
interface CheckoutPreparation {
attached: boolean
}
}
export {}© Recustomer, Inc.