PerspectPerspectDocs
Go to Admin
View as Markdown

perspectapi-ts-sdk

Interfaces

  • CheckoutSessionOptions
  • LoadBlockBySlugOptions
  • LoadContentBySlugOptions
  • LoadContentOptions
  • LoaderLogger
  • LoaderOptions
  • LoadProductBySlugOptions
  • LoadProductsOptions

Functions

  • createCheckoutSession
  • loadAllContent
  • loadBlockBySlug
  • loadBlocks
  • loadContentBySlug
  • loadPages
  • loadPosts
  • loadProductBySlug
  • loadProducts
  • transformContent
  • transformProduct

Interface: CheckoutSessionOptions

Properties

billingAddress?

optional billingAddress?: CheckoutAddress

Billing address forwarded to the checkout API for tax estimation.

cancelUrl

cancelUrl: string

client?

optional client?: PerspectApiClient | null

currency?

optional currency?: string

Optional currency override; defaults to the currency defined on each Stripe price.

customerEmail?

optional customerEmail?: string

fallbackProducts?

optional fallbackProducts?: Product[]

items

items: object[]

productId

productId: string

quantity

quantity: number

logger?

optional logger?: LoaderLogger

metadata?

optional metadata?: CheckoutMetadata

mode?

optional mode?: "live" | "test"

priceIdResolver?

optional priceIdResolver?: (product, mode) => string | undefined

Optional resolver to convert a product record into a Stripe price ID.

Parameters

product

Product

mode

"live" | "test"

Returns

string | undefined

shippingAddress?

optional shippingAddress?: CheckoutAddress

Shipping address forwarded to the checkout API for tax estimation.

shippingAmount?

optional shippingAmount?: number

Optional shipping amount (in the smallest currency unit).

siteName

siteName: string

successUrl

successUrl: string

tax?

optional tax?: CheckoutTaxRequest

Optional tax configuration that will be forwarded to the checkout API.


Interface: LoadBlockBySlugOptions

Extends

  • LoaderOptions

Properties

client?

optional client?: PerspectApiClient | null

Pre-configured PerspectAPI client. Pass null/undefined to force fallback behaviour.

Inherited from

LoaderOptions.client

fallbackPosts?

optional fallbackPosts?: BlogPost[]

Inherited from

LoaderOptions.fallbackPosts

fallbackProducts?

optional fallbackProducts?: Product[]

Optional fallback datasets.

Inherited from

LoaderOptions.fallbackProducts

limit?

optional limit?: number

Limit for list fetching (defaults to 100).

Inherited from

LoaderOptions.limit

logger?

optional logger?: LoaderLogger

Optional logger to capture debug/warn/error output.

Inherited from

LoaderOptions.logger

siteName

siteName: string

Site name used for API calls and fallback data generation.

Inherited from

LoaderOptions.siteName

slug

slug: string


Interface: LoadContentBySlugOptions

Extends

  • LoaderOptions

Properties

client?

optional client?: PerspectApiClient | null

Pre-configured PerspectAPI client. Pass null/undefined to force fallback behaviour.

Inherited from

LoaderOptions.client

fallbackPosts?

optional fallbackPosts?: BlogPost[]

Inherited from

LoaderOptions.fallbackPosts

fallbackProducts?

optional fallbackProducts?: Product[]

Optional fallback datasets.

Inherited from

LoaderOptions.fallbackProducts

limit?

optional limit?: number

Limit for list fetching (defaults to 100).

Inherited from

LoaderOptions.limit

logger?

optional logger?: LoaderLogger

Optional logger to capture debug/warn/error output.

Inherited from

LoaderOptions.logger

siteName

siteName: string

Site name used for API calls and fallback data generation.

Inherited from

LoaderOptions.siteName

slug

slug: string


Interface: LoadContentOptions

Extends

  • LoaderOptions

Properties

client?

optional client?: PerspectApiClient | null

Pre-configured PerspectAPI client. Pass null/undefined to force fallback behaviour.

Inherited from

LoaderOptions.client

fallbackPosts?

optional fallbackPosts?: BlogPost[]

Inherited from

LoaderOptions.fallbackPosts

fallbackProducts?

optional fallbackProducts?: Product[]

Optional fallback datasets.

Inherited from

LoaderOptions.fallbackProducts

limit?

optional limit?: number

Limit for list fetching (defaults to 100).

Inherited from

LoaderOptions.limit

logger?

optional logger?: LoaderLogger

Optional logger to capture debug/warn/error output.

Inherited from

LoaderOptions.logger

params?

optional params?: Partial<{ limit: number; page_status: string; page_type: string; search: string; }>

Additional query parameters for content filtering.

siteName

siteName: string

Site name used for API calls and fallback data generation.

Inherited from

LoaderOptions.siteName


Interface: LoaderLogger

Logger interface so consumers can supply custom logging behaviour (or noop).

Methods

debug()?

optional debug(...args): void

Parameters

args

...unknown[]

Returns

void

error()?

optional error(...args): void

Parameters

args

...unknown[]

Returns

void

info()?

optional info(...args): void

Parameters

args

...unknown[]

Returns

void

warn()?

optional warn(...args): void

Parameters

args

...unknown[]

Returns

void


Interface: LoaderOptions

Extended by

  • LoadProductsOptions
  • LoadProductBySlugOptions
  • LoadContentOptions
  • LoadContentBySlugOptions
  • LoadBlockBySlugOptions

Properties

client?

optional client?: PerspectApiClient | null

Pre-configured PerspectAPI client. Pass null/undefined to force fallback behaviour.

fallbackPosts?

optional fallbackPosts?: BlogPost[]

fallbackProducts?

optional fallbackProducts?: Product[]

Optional fallback datasets.

limit?

optional limit?: number

Limit for list fetching (defaults to 100).

logger?

optional logger?: LoaderLogger

Optional logger to capture debug/warn/error output.

siteName

siteName: string

Site name used for API calls and fallback data generation.


Interface: LoadProductBySlugOptions

Extends

  • LoaderOptions

Properties

client?

optional client?: PerspectApiClient | null

Pre-configured PerspectAPI client. Pass null/undefined to force fallback behaviour.

Inherited from

LoaderOptions.client

fallbackPosts?

optional fallbackPosts?: BlogPost[]

Inherited from

LoaderOptions.fallbackPosts

fallbackProducts?

optional fallbackProducts?: Product[]

Optional fallback datasets.

Inherited from

LoaderOptions.fallbackProducts

limit?

optional limit?: number

Limit for list fetching (defaults to 100).

Inherited from

LoaderOptions.limit

logger?

optional logger?: LoaderLogger

Optional logger to capture debug/warn/error output.

Inherited from

LoaderOptions.logger

siteName

siteName: string

Site name used for API calls and fallback data generation.

Inherited from

LoaderOptions.siteName

slug

slug: string


Interface: LoadProductsOptions

Extends

  • LoaderOptions

Properties

category?

optional category?: string | string[]

Filter products by category name (case-insensitive). Accepts a single name or multiple names.

categoryIds?

optional categoryIds?: (string | number)[]

Filter products by category IDs (mixed string/number values supported).

client?

optional client?: PerspectApiClient | null

Pre-configured PerspectAPI client. Pass null/undefined to force fallback behaviour.

Inherited from

LoaderOptions.client

fallbackPosts?

optional fallbackPosts?: BlogPost[]

Inherited from

LoaderOptions.fallbackPosts

fallbackProducts?

optional fallbackProducts?: Product[]

Optional fallback datasets.

Inherited from

LoaderOptions.fallbackProducts

limit?

optional limit?: number

Limit for list fetching (defaults to 100).

Inherited from

LoaderOptions.limit

logger?

optional logger?: LoaderLogger

Optional logger to capture debug/warn/error output.

Inherited from

LoaderOptions.logger

offset?

optional offset?: number

Offset for manual pagination.

optional search?: string

Optional search term applied server-side.

siteName

siteName: string

Site name used for API calls and fallback data generation.

Inherited from

LoaderOptions.siteName


Function: createCheckoutSession()

createCheckoutSession(options): Promise<ApiResponse<CheckoutSession> | { error: string; }>

Convenience helper that creates a checkout session by looking up Stripe price IDs from product metadata. Falls back to gateway price IDs if Stripe IDs are missing.

Parameters

options

CheckoutSessionOptions

Returns

Promise<ApiResponse<CheckoutSession> | { error: string; }>


Function: loadAllContent()

loadAllContent(options): Promise<BlogPost[]>

Load all published content (pages + posts).

Parameters

options

LoaderOptions

Returns

Promise<BlogPost[]>


Function: loadBlockBySlug()

loadBlockBySlug(options): Promise<BlogPost | null>

Load a single block by slug.

Parameters

options

LoadBlockBySlugOptions

Returns

Promise<BlogPost | null>


Function: loadBlocks()

loadBlocks(options): Promise<BlogPost[]>

Load published blocks for a site.

Parameters

options

LoadContentOptions

Returns

Promise<BlogPost[]>


Function: loadContentBySlug()

loadContentBySlug(options): Promise<BlogPost | null>

Load a single content item (post or page) by slug.

Parameters

options

LoadContentBySlugOptions

Returns

Promise<BlogPost | null>


Function: loadPages()

loadPages(options): Promise<BlogPost[]>

Load published pages for a site.

Parameters

options

LoadContentOptions

Returns

Promise<BlogPost[]>


Function: loadPosts()

loadPosts(options): Promise<BlogPost[]>

Load published blog posts for a site.

Parameters

options

LoadContentOptions

Returns

Promise<BlogPost[]>


Function: loadProductBySlug()

loadProductBySlug(options): Promise<Product | null>

Load single product by slug.

Parameters

options

LoadProductBySlugOptions

Returns

Promise<Product | null>


Function: loadProducts()

loadProducts(options): Promise<Product[]>

Load products for a site with graceful fallbacks.

Parameters

options

LoadProductsOptions

Returns

Promise<Product[]>


Function: transformContent()

transformContent(perspectContent, logger?): BlogPost

Transform PerspectAPI content payload to a simplified BlogPost structure.

Parameters

perspectContent

Content | Content & Record<string, unknown>

logger?

LoaderLogger

Returns

BlogPost


Function: transformProduct()

transformProduct(perspectProduct, logger?): Product

Transform a PerspectAPI product payload into a friendlier shape for UI layers.

Parameters

perspectProduct

any

logger?

LoaderLogger

Returns

Product