Skip to content

Class: EcomApi

Frontend API for Connect for Commerce.

Export

Constructors

constructor

new EcomApi(baseUrl, logLevel?)

Creates an instance of EcomApi.

Parameters

Name Type Default value Description
baseUrl string undefined URL of the backend service.
logLevel LogLevel LogLevel.INFO 0: DEBUG
1: INFO
2: WARNING
3: ERROR
4: NONE

Properties

defaultLocale

Optional defaultLocale: string

Methods

addHook

addHook<Name, Func>(name, func): void

Register a new hook.

Type parameters

Name Type
Name extends EcomHooks
Func extends CreateSectionPayload | ContentChangeHookPayload | OpenStoreFrontUrlHookPayload | RequestPreviewElementHookPayload | CreatePageHookPayload

Parameters

Name Type Description
name Name Name of the hook.
func (payload: Func) => void The hook's callback.

Returns

void


clear

clear(): void

Clears the DOM.

Returns

void


createPage

createPage(payload): Promise<any>

Creates a FirstSpirit page according to shop identifiers.

Parameters

Name Type Description
payload CreatePagePayload Payload to use when creating the page.

Returns

Promise<any>

Whether the page was created.


createSection

createSection(payload): Promise<any>

Creates a section within a given FirstSpirit page.

Parameters

Name Type Description
payload CreateSectionPayload Payload to use when creating a section.

Returns

Promise<any>

Whether the section was created.


fetchNavigation

fetchNavigation(params): Promise<FetchNavigationResponse>

Fetches the navigation service.

Parameters

Name Type Description
params FetchNavigationParams Parameters to use when fetching the navigation.

Returns

Promise<FetchNavigationResponse>

Details about the navigation.


findElement

findElement(params): Promise<FindElementResponse>

Finds a CaaS element.

Parameters

Name Type Description
params FindElementParams Parameters to use to find the element.

Returns

Promise<FindElementResponse>

Details about the element.


findPage

findPage(params): Promise<FindPageResponse>

Finds a CaaS page.

Parameters

Name Type Description
params FindPageParams Parameters to use to find the page.

Returns

Promise<FindPageResponse>

Details about the page.


init

init(): Promise<boolean>

Initialize the API.

Returns

Promise<boolean>

Whether the initialization was successful.


setDefaultLocale

setDefaultLocale(locale): void

Setting the default locale.

Parameters

Name Type Description
locale string FirstSpirit compatible language code of the locale to set.

Returns

void


setElement

setElement(params): Promise<void>

Sets the element currently displayed in the storefront.

Parameters

Name Type Description
params null | SetElementParams Parameter

Returns

Promise<void>