UNPKG

@wallfar/ocd-studio-core-sdk

Version:

Helper SDK for our OneClick Studio modules

271 lines (265 loc) 10.1 kB
import { W as WebshopConfig, a as Collection, S as ShippingOption, P as Product, V as VariantOptions, A as Address, b as PromoCodeValidationResult, U as UseProductReturn } from './shared/ocd-studio-core-sdk.ZjQ9JUGC.mjs'; import * as vue from 'vue'; import { MaybeRefOrGetter, ComputedRef, Ref } from 'vue'; import { I as BookerConfig, P as PaymentLinkOptions, U as UseAppointmentBookerConfig, H as UseAppointmentBookerReturn } from './shared/ocd-studio-core-sdk.ShBMfdE2.mjs'; import '@internationalized/date'; import 'firebase-admin/firestore'; import 'firebase-functions/v2/firestore'; type CollectionSlugInput = string | string[]; declare class Webshop { private config; private cart; private taxRate; private _shippingOptions; private _shippingOption; private _activePromoCode; private _collections; private _deliveryAddress; constructor(config: WebshopConfig); refreshCollections(): Promise<Collection[] | null>; refreshShippingOptions(): Promise<ShippingOption[] | null>; fetchProduct(slug: string): Promise<Product | null>; /** * Sends a notification to a user. * * @param product: Product created in the Products module from whitelabel core modules package. */ setProductSeo(product: Product): void; createConfigurator(product: Partial<Product>): { selection: any; getSelectedVariant: () => VariantOptions | undefined; getVariant: (variant: VariantOptions) => VariantOptions | undefined; }; addToCart(product: Partial<Product>, variant?: VariantOptions, quantity?: number): Promise<void>; removeFromCart(productId: string, variant?: VariantOptions): void; decreaseItem(productId: string, variant?: VariantOptions): void; updateQuantity(productId: string, variant: VariantOptions | undefined, newQty: number): void; private validatePromoCode; updateDeliveryAddress(updates: Partial<Address>): void; get cartItems(): { productId: string; title: string; slug: string; thumbnail?: string | undefined; price: number; currency: string; quantity: number; stock?: number | undefined; variant?: VariantOptions | undefined; }[]; get activePromoCode(): { id?: string | undefined; code: string; type: string; value?: number | undefined; minOrderAmount?: number | undefined; } | null; get collections(): vue.Ref<{ id?: string | undefined; title: string; description?: string | undefined; thumbnail?: string | undefined; slug: string; type: "manual" | "auto"; status: "published" | "draft"; conditions?: { field: string; operator: "==" | "!=" | "<" | ">" | "<=" | ">=" | "in" | "not-in" | "array-contains" | "array-contains-any"; value: any; }[] | undefined; subcollections?: { id?: string | undefined; title: string; description?: string | undefined; thumbnail?: string | undefined; slug: string; type: "manual" | "auto"; status: "published" | "draft"; conditions?: { field: string; operator: "==" | "!=" | "<" | ">" | "<=" | ">=" | "in" | "not-in" | "array-contains" | "array-contains-any"; value: any; }[] | undefined; }[] | undefined; }[] | null, Collection[] | { id?: string | undefined; title: string; description?: string | undefined; thumbnail?: string | undefined; slug: string; type: "manual" | "auto"; status: "published" | "draft"; conditions?: { field: string; operator: "==" | "!=" | "<" | ">" | "<=" | ">=" | "in" | "not-in" | "array-contains" | "array-contains-any"; value: any; }[] | undefined; subcollections?: { id?: string | undefined; title: string; description?: string | undefined; thumbnail?: string | undefined; slug: string; type: "manual" | "auto"; status: "published" | "draft"; conditions?: { field: string; operator: "==" | "!=" | "<" | ">" | "<=" | ">=" | "in" | "not-in" | "array-contains" | "array-contains-any"; value: any; }[] | undefined; }[] | undefined; }[] | null>; get itemCount(): number; get subtotal(): number; get deliveryAddress(): vue.ToRefs<{ firstName: string; lastName: string; company?: string | undefined; streetLine1: string; streetLine2?: string | undefined; streetLine3?: string | undefined; city: string; stateOrProvince?: string | undefined; countyOrDistrict?: string | undefined; postalCode: string; country: string; phoneNumber?: string | undefined; email?: string | undefined; instructions?: string | undefined; latitude?: number | undefined; longitude?: number | undefined; }>; get shippingOptions(): ShippingOption[]; get shippingOption(): string | null; set shippingOption(option: string | null); get shippingFee(): number; get discount(): number; get tax(): number; get total(): number; get country(): string; set country(val: string); applyPromoCode(code: string): Promise<PromoCodeValidationResult>; createPaymentLink(): Promise<string | undefined>; removePromoCode(): void; clearCart(): void; formatPrice(price: number, currency?: string, locale?: string): string; useProduct(slug: MaybeRefOrGetter<string>): UseProductReturn; useCollection(slug: MaybeRefOrGetter<CollectionSlugInput>): any; useCollection(slug: MaybeRefOrGetter<string>, subcollectionSlug: MaybeRefOrGetter<string>): any; } interface ContentDeliveryConfig { defaultLocale?: string; defaultQueryLimit?: number; previewWhiteList?: string | string[]; provider: 'firebase'; firebase?: { db: any; entries: string; collections: string; }; } interface Content { id: string; /** Stable id of the master content entry. */ entryId?: string; /** Id of the locale-specific version document. */ versionId?: string; collectionId?: string; slug: string; locale: string; title: string; description?: string; content?: object; settings?: object; structuredContent?: object; i18nParams?: { [key: string]: { slug: string; }; }; createdAt: string | null; updatedAt?: string | null; } interface ContentSettings { collection: MaybeRefOrGetter<string>; slug: MaybeRefOrGetter<string>; locale?: MaybeRefOrGetter<string | undefined>; entryId?: MaybeRefOrGetter<string | undefined>; version?: MaybeRefOrGetter<string | undefined>; } interface ContentCollectionSettings { /** Studio content collection id. */ collection: MaybeRefOrGetter<string>; /** Published locale to return. Falls back to `defaultLocale`, then `en`. */ locale?: MaybeRefOrGetter<string | undefined>; /** Entries per page. Falls back to `defaultQueryLimit`, then 20. */ pageSize?: MaybeRefOrGetter<number | undefined>; } type ContentRequestStatus = 'idle' | 'pending' | 'success' | 'error'; interface UseContentResult { /** The content */ content: ComputedRef<object | null>; /** The structured content */ entry: ComputedRef<{ [key: string]: any; } | null>; /** The custom entry settings */ settings: ComputedRef<{ [key: string]: any; } | null>; /** Pre-generated i18n parameters */ i18nParams: ComputedRef<{ [key: string]: { slug: string; }; } | null>; /** SEO metadata */ seo: ComputedRef<{ title: string; description: string; slug: string; }>; /** loading state */ pending: Ref<boolean>; /** status of the fetch */ status: Ref<ContentRequestStatus>; /** fetch errors */ error: ComputedRef<Error | null>; /** manually re-fetch */ refresh: () => Promise<void>; } type UseContentReturn = UseContentResult & PromiseLike<UseContentResult>; interface UseContentCollectionResult { /** Published entries in the requested locale. */ entries: ComputedRef<Content[]>; /** Whether the initial page or a refresh is loading. */ pending: Ref<boolean>; /** Whether an additional page is loading. */ loadingMore: Readonly<Ref<boolean>>; /** Whether another page is available. */ hasMore: ComputedRef<boolean>; /** Status of the initial fetch or refresh. */ status: Ref<ContentRequestStatus>; /** Initial, refresh, or pagination error. */ error: ComputedRef<Error | null>; /** Append the next page, if one is available. */ loadMore: () => Promise<void>; /** Reset pagination and fetch the first page again. */ refresh: () => Promise<void>; } type UseContentCollectionReturn = UseContentCollectionResult & PromiseLike<UseContentCollectionResult>; declare class ContentDelivery { private config; constructor(config: ContentDeliveryConfig); useContent(settings: ContentSettings): UseContentReturn; /** Fetch and incrementally paginate published entries from a content collection. */ useCollection(settings: ContentCollectionSettings): UseContentCollectionReturn; } declare class Booker { private config; constructor(config: BookerConfig); createPaymentLink(orderId: string, options?: PaymentLinkOptions): Promise<string>; useAppointmentBooker(agendaId?: MaybeRefOrGetter<string>, config?: UseAppointmentBookerConfig): UseAppointmentBookerReturn; } export { Booker, ContentDelivery, Webshop }; export type { Content, ContentCollectionSettings, ContentDeliveryConfig, ContentRequestStatus, ContentSettings, UseContentCollectionResult, UseContentCollectionReturn, UseContentResult, UseContentReturn };