Skip to main content

API

XPV Object

In th Script Engine sandbox there is no global, or window object, instead there is a global xpv object.

script-engine-api.d.ts
type xpv = {
articles: {
getById(id: number): null|Article,
getByName(name: string): null|Article,
getBySKU(sku: string): null|Article,
getAll(): Article[],
},
attributes: {
getById(id: number): null|Attribute,
getByName(name: string): null|Attribute,
getByKey(key: string): null|Attribute,
getAll(): Attribute[],
},
catalogue: {
sku: null|string,
},
connectors: {
getByName(name: string): null|AdapterContract,
},
globals: {
getByName(name: string): null|string,
getAll(): string[],
},
return: (data: any) => any,
user_data: {
getAll(): any[],
},
};

type Article = {
material_group_id: number,
material_group_sku: string|null,
models_id: number,
models_name: string,
models_price: number|null,
models_sku: string|null,
price_sku: string|null,
};

type Attribute = {
attribute_id: number,
attribute_name: string,
attribute_key: null|string,
attribute_value: AttributeValue,
attribute_value_name: string,
attribute_value_key: null|string,
};

type AttributeValue = {
attribute_value_id: number,
};

The structure of AttributeValue can vary depending on the type of attribute.

Connectors

The xpv.connectors.getByName() method returns any type of connector based on what is configured in the Backoffice.

adapter-contract.d.ts
type AdapterContract = {
getName(): string,
};

Spreadsheet Connectors

All spreadsheet connectors (Spreadsheet, CSV Zip) have the same API.

spreadsheet-adapter.d.ts
type SpreadsheetAdapter = AdapterContract & {
getSheetByName(name: null|string): SpreadsheetAdapterContract,
rangeToArray(range: string): any[][],
};

HTTP Connector

http-adapter.d.ts
type HttpAdapter = AdapterContract & {
setHeaders(headers: { [key: string]: string }): HttpAdapter,
setHeader(key: string, value: string): HttpAdapter,
setPathParams(params: { [key: string]: string }): HttpAdapter,
setPathParam(key: string, value: string): HttpAdapter,
request(parameters: { [key: string]: string }): HttpResponse,
};

type HttpResponse = {
body(): string,
json(): object|any,
status(): int,
header(header: string): null|string,
headers(): { [key: string]: string },
};

HTTP Feed Connector

http-feed-adapter.d.ts
type HttpFeedAdapter = AdapterContract & {
get(): HttpResponse,
};