New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@relewise/client

Package Overview
Dependencies
Maintainers
3
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@relewise/client - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

1268

dist/browser/relewise-client.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Relewise = {}));
})(this, (function (exports) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('cross-fetch')) :
typeof define === 'function' && define.amd ? define(['exports', 'cross-fetch'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Relewise = {}, global.fetch));
})(this, (function (exports, fetch) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
class DataValueBase {
constructor(type, value) {
this.type = type;
this.value = value;
}
}
class StringDataValue extends DataValueBase {
constructor(value) {
super('String', value);
}
}
class StringCollectionDataValue extends DataValueBase {
constructor(value) {
super('StringList', value);
}
}
class NumberDataValue extends DataValueBase {
constructor(value) {
super('Double', value);
}
}
class DoubleCollectionDataValue extends DataValueBase {
constructor(value) {
super('DoubleList', value);
}
}
class BooleanDataValue extends DataValueBase {
constructor(value) {
super('Boolean', value);
}
}
class BooleanCollectionDataValue extends DataValueBase {
constructor(value) {
super('BooleanList', value);
}
}
class MoneyDataValue extends DataValueBase {
constructor(amount, currency) {
super('Money', {
amount: amount,
currency: { value: currency },
});
}
}
class MultiCurrencyDataValue extends DataValueBase {
constructor(values) {
super('MultiCurrency', {
values: values.map(x => ({ amount: x.amount, currency: { value: x.currency } })),
});
}
}
class MultilingualDataValue extends DataValueBase {
constructor(values) {
super('Multilingual', {
values: values.map(x => ({ text: x.value, language: { value: x.language } })),
});
}
}
class ConditionBuilder {
constructor() {
this.conditions = [];
}
addContainsCondition(value, valueCollectionEvaluationMode = 'All', negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.ContainsCondition, Relewise.Client',
value: value,
valueCollectionEvaluationMode: valueCollectionEvaluationMode,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addDistinctCondition(numberOfOccurrencesAllowedWithTheSameValue, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.DistinctCondition, Relewise.Client',
numberOfOccurrencesAllowedWithTheSameValue: numberOfOccurrencesAllowedWithTheSameValue,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addEqualsCondition(value, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.EqualsCondition, Relewise.Client',
value: value,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addGreaterThanCondition(value, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.GreaterThanCondition, Relewise.Client',
value: value,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addLessThanCondition(value, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.LessThanCondition, Relewise.Client',
value: value,
negated: negated,
};
this.conditions.push(condition);
return this;
}
build() {
return this.conditions.length === 0
? null
: { items: this.conditions };
}
}
class FilterBuilder {
constructor() {
this.filters = [];
}
/**
* Adds a product assortment filter to the request
* @param assortmentIds
* @param negated
*/
addProductAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a variant assortment filter to the request
* @param assortmentIds
* @param negated
*/
addVariantAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a brand assortment filter to the request
* @param assortmentIds
* @param negated
*/
addBrandAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.BrandAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a content category assortment filter to the request
* @param assortmentIds
* @param negated
*/
addContentCategoryAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a content category assortment filter to the request
* @param assortmentIds
* @param negated
*/
addProductCategoryAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products within the specificed categories
* @param evaluationScope
* @param categoryIds
* @param negated
*/
addProductCategoryIdFilter(evaluationScope, categoryIds, negated = false) {
const ids = Array.isArray(categoryIds)
? categoryIds
: [categoryIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryIdFilter, Relewise.Client',
evaluationScope: evaluationScope,
categoryIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return contents within the specificed categories
* @param evaluationScope
* @param categoryIds
* @param negated
*/
addContentCategoryIdFilter(evaluationScope, categoryIds, negated = false) {
const ids = Array.isArray(categoryIds)
? categoryIds
: [categoryIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryIdFilter, Relewise.Client',
evaluationScope: evaluationScope,
categoryIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied products
* @param productIds
* @param negated
*/
addProductIdFilter(productIds, negated = false) {
const ids = Array.isArray(productIds)
? productIds
: [productIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductIdFilter, Relewise.Client',
productIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied variants
* @param variantIds
* @param negated
*/
addVariantIdFilter(variantIds, negated = false) {
const ids = Array.isArray(variantIds)
? variantIds
: [variantIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantIdFilter, Relewise.Client',
variantIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied brands
* @param brandIds
* @param negated
*/
addBrandIdFilter(brandIds, negated = false) {
const ids = Array.isArray(brandIds)
? brandIds
: [brandIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.BrandIdFilter, Relewise.Client',
brandIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied contents
* @param contentIds
* @param negated
*/
addContentIdFilter(contentIds, negated = false) {
const ids = Array.isArray(contentIds)
? contentIds
: [contentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentIdFilter, Relewise.Client',
contentIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a range filter to the request ensuring the product has a certain range of variants
* @param lowerBound
* @param upperBound
* @param negated
*/
addProductHasVariantsFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductHasVariantsFilter, Relewise.Client',
numberOfVariants: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products purchased since a certain point in time
* @param sinceUtc
* @param negated
*/
addProductRecentlyPurchasedByUserFilter(sinceUtc, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductRecentlyPurchasedByUserFilter, Relewise.Client',
sinceUtc: sinceUtc,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products viewed since a certain point in time
* @param sinceUtc
* @param negated
*/
addProductRecentlyViewedByUserFilter(sinceUtc, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductRecentlyViewedByUserFilter, Relewise.Client',
sinceUtc: sinceUtc,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products within a certain SalesPrice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addProductSalesPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductSalesPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products within a certain ListPice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addProductListPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductListPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return variants within a certain SalesPrice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addVariantSalesPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantSalesPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return variants within a certain ListPice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addVariantListPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantListPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return variants with a certain specification
* @param key
* @param equalTo
* @param filterOutIfKeyIsNotFound controls if variants with or without the key should be returned
* @param negated
*/
addVariantSpecificationFilter(key, equalTo, filterOutIfKeyIsNotFound = true, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantSpecificationFilter, Relewise.Client',
key: key,
equalTo: equalTo,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
negated: negated,
};
this.filters.push(filter);
return this;
}
and(filterBuilder, negated = false) {
const builder = new FilterBuilder();
filterBuilder(builder);
const filters = builder.build();
if (filters === null || filters.items === undefined || filters.items === null || filters.items.length <= 0) {
throw new Error('And-filters must contain atleast 1 filter');
}
const filter = {
$type: 'Relewise.Client.Requests.Filters.AndFilter, Relewise.Client',
filters: filters.items,
negated: negated,
};
this.filters.push(filter);
return this;
}
or(filterBuilder, negated = false) {
const builder = new FilterBuilder();
filterBuilder(builder);
const filters = builder.build();
if (filters === null || filters.items === undefined || filters.items === null || filters.items.length <= 0) {
throw new Error('Or-filters must contain atleast 1 filter');
}
const filter = {
$type: 'Relewise.Client.Requests.Filters.OrFilter, Relewise.Client',
filters: filters.items,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a product data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addProductDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a variant data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addVariantDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a brand data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addBrandDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.BrandDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a cart data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addCartDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.CartDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a cart data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addContentCategoryDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a content data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addContentDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a product category data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addProductCategoryDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a product display name filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addProductDisplayNameFilter(conditionBuilder, mustMatchAllConditions = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductDisplayNameFilter, Relewise.Client',
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
reset() {
this.filters = [];
return this;
}
build() {
return this.filters.length === 0
? null
: { items: this.filters };
}
}
class PaginationBuilder {
constructor() {
this.pageNumber = 1;
this.pageSize = 10;
}
/**
* Defines how many results to return
* @param pageSize
* @returns
*/
setPageSize(pageSize) {
if (pageSize < 0) {
throw new Error('pageSize can not be below 0');
}
this.pageSize = pageSize;
return this;
}
/**
* Page starts at 1, so this to skip 'X' pages of results
* @param pageNumber
* @returns
*/
setPage(pageNumber) {
if (pageNumber < 1) {
throw new Error('pageNumber can not be below 1');
}
this.pageNumber = pageNumber;
return this;
}
build() {
return {
take: this.pageSize,
skip: (this.pageNumber - 1) * this.pageSize,
};
}
}
class FacetBuilder {
constructor() {
this.facets = [];
}
addCategoryFacet(categorySelectionStrategy, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.CategoryFacet, Relewise.Client',
categorySelectionStrategy: categorySelectionStrategy,
field: 'Category',
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addBrandFacet(selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.BrandFacet, Relewise.Client',
field: 'Brand',
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addProductAssortmentFacet(selectionStrategy, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductAssortmentFacet, Relewise.Client',
field: 'Assortment',
assortmentFilterType: 'Or',
assortmentSelectionStrategy: selectionStrategy,
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addContentAssortmentFacet(selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ContentAssortmentFacet, Relewise.Client',
field: 'Assortment',
assortmentFilterType: 'Or',
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addVariantSpecificationFacet(key, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.VariantSpecificationFacet, Relewise.Client',
field: 'VariantSpecification',
key: key,
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addProductDataDoubleRangeFacet(key, selectionStrategy, lowerBound, upperBound) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataDoubleRangeFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
};
this.facets.push(facet);
return this;
}
addProductDataStringValueFacet(key, selectionStrategy, selectedValues = null, collectionFilterType) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataStringValueFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: selectedValues,
collectionFilterType: collectionFilterType,
};
this.facets.push(facet);
return this;
}
addProductDataBooleanValueFacet(key, selectionStrategy, selectedValues = null, collectionFilterType) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataBooleanValueFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: selectedValues,
collectionFilterType: collectionFilterType,
};
this.facets.push(facet);
return this;
}
addProductDataDoubleValueFacet(key, selectionStrategy, selectedValues = null, collectionFilterType) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataDoubleValueFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: selectedValues,
collectionFilterType: collectionFilterType,
};
this.facets.push(facet);
return this;
}
addSalesPriceRangeFacet(priceSelectionStrategy, lowerBound, upperBound) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangeFacet, Relewise.Client',
field: 'SalesPrice',
selected: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
priceSelectionStrategy,
};
this.facets.push(facet);
return this;
}
addListPriceRangeFacet(priceSelectionStrategy, lowerBound, upperBound) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangeFacet, Relewise.Client',
field: 'ListPrice',
selected: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
priceSelectionStrategy,
};
this.facets.push(facet);
return this;
}
addListPriceRangesFacet(priceSelectionStrategy, predefinedRanges, expandedRangeSize, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangesFacet, Relewise.Client',
field: 'ListPrice',
predefinedRanges: predefinedRanges === null || predefinedRanges === void 0 ? void 0 : predefinedRanges.map(x => ({ lowerBoundInclusive: x.lowerBound, upperBoundExclusive: x.upperBound })),
expandedRangeSize: expandedRangeSize,
selected: selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.map(x => ({ lowerBoundInclusive: x.lowerBound, upperBoundExclusive: x.upperBound })),
priceSelectionStrategy,
};
this.facets.push(facet);
return this;
}
build() {
return this.facets.length === 0
? null
: { items: this.facets };
}
}
class ProductSortingBuilder {
constructor() {
this.value = null;
}
sortByProductData(key, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductDataSorting, Relewise.Client',
dataSelectionStrategy: 'Product',
mode,
order,
key,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductRelevance(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductRelevanceSorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductPopularity(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductPopularitySorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductAttribute(attribute, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductAttributeSorting, Relewise.Client',
attribute,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductVariantAttribute(attribute, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductVariantAttributeSorting, Relewise.Client',
attribute,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductVariantSpecification(key, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductVariantSpecificationSorting, Relewise.Client',
key,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
thenBy(thenBy) {
const thenByBuilder = new ProductSortingBuilder();
if (thenBy) {
thenBy(thenByBuilder);
thenByBuilder.build();
}
return thenByBuilder;
}
build() {
return this.value == null
? null
: { value: this.value };
}
}
class ContentSortingBuilder {
constructor() {
this.value = null;
}
sortByContentData(key, order = 'Descending', mode = 'Auto', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentDataSorting, Relewise.Client',
mode,
order,
key,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByContentRelevance(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentRelevanceSorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByContentPopularity(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentPopularitySorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByContentAttribute(attribute, order, mode = 'Auto', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentAttributeSorting, Relewise.Client',
attribute,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
thenBy(thenBy) {
const thenByBuilder = new ContentSortingBuilder();
if (thenBy) {
thenBy(thenByBuilder);
thenByBuilder.build();
}
return thenByBuilder;
}
build() {
return this.value == null
? null
: { value: this.value };
}
}
class SearchRequestBuilder {
constructor(settings) {
this.settings = settings;
this.filterBuilder = new FilterBuilder();
this.postFilterBuilder = new FilterBuilder();
}
/**
* Adds filters to the request
* @param filterBuilder
* @returns
*/
filters(filterBuilder) {
filterBuilder(this.filterBuilder);
return this;
}
/**
* Adds post filters to the request
* @param filterBuilder
* @returns
*/
postFilters(filterBuilder) {
filterBuilder(this.postFilterBuilder);
return this;
}
/**
* Use only when a specific index different from the 'default'-index is needed
* @param id
* @returns
*/
setIndex(id) {
this.indexId = id;
return this;
}
baseBuild() {
return Object.assign({ currency: { value: this.settings.currency }, user: this.settings.user, language: { value: this.settings.language }, displayedAtLocation: this.settings.displayedAtLocation, filters: this.filterBuilder.build(), postFilters: this.postFilterBuilder.build(), relevanceModifiers: null }, (this.indexId && { indexSelector: { id: this.indexId } }));
}
}
class ContentSearchBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.facetBuilder = new FacetBuilder();
this.paginationBuilder = new PaginationBuilder();
this.sortingBuilder = new ContentSortingBuilder();
this.searchSettings = {
$type: 'Relewise.Client.Requests.Search.Settings.ContentSearchSettings, Relewise.Client',
recommendations: {},
};
}
setContentProperties(contentProperties) {
this.searchSettings.selectedContentProperties = contentProperties;
return this;
}
setRecommendationSettings(settings) {
this.searchSettings.recommendations = settings;
return this;
}
setTerm(term) {
this.term = term;
return this;
}
pagination(paginate) {
paginate(this.paginationBuilder);
return this;
}
facets(facets) {
facets(this.facetBuilder);
return this;
}
sorting(sorting) {
sorting(this.sortingBuilder);
return this;
}
build() {
const { take, skip } = this.paginationBuilder.build();
return Object.assign(Object.assign({}, this.baseBuild()), { settings: this.searchSettings, take,
skip, term: this.term, facets: this.facetBuilder.build(), sorting: this.sortingBuilder.build() });
}
}
class ProductSearchBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.facetBuilder = new FacetBuilder();
this.paginationBuilder = new PaginationBuilder();
this.sortingBuilder = new ProductSortingBuilder();
this.searchSettings = {
$type: 'Relewise.Client.Requests.Search.Settings.ProductSearchSettings, Relewise.Client',
recommendations: {},
};
}
setSelectedProductProperties(productProperties) {
this.searchSettings.selectedProductProperties = productProperties;
return this;
}
setSelectedVariantProperties(variantProperties) {
this.searchSettings.selectedVariantProperties = variantProperties;
return this;
}
setSelectedBrandProperties(brandProperties) {
this.searchSettings.selectedBrandProperties = brandProperties;
return this;
}
setExplodedVariants(count) {
this.searchSettings.explodedVariants = count;
return this;
}
setRecommendationSettings(settings) {
this.searchSettings.recommendations = settings;
return this;
}
/**
* Set the term used to filter products by
*/
setTerm(term) {
this.term = term;
return this;
}
pagination(paginate) {
paginate(this.paginationBuilder);
return this;
}
facets(facets) {
facets(this.facetBuilder);
return this;
}
sorting(sorting) {
sorting(this.sortingBuilder);
return this;
}
build() {
const { take, skip } = this.paginationBuilder.build();
return Object.assign(Object.assign({}, this.baseBuild()), { take,
skip, term: this.term, facets: this.facetBuilder.build(), settings: this.searchSettings, sorting: this.sortingBuilder.build() });
}
}
class SearchCollectionBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.requests = [];
}
addRequest(request) {
this.requests.push(request);
return this;
}
build() {
return Object.assign(Object.assign({}, this.baseBuild()), { requests: this.requests });
}
}
class SearchTermPredictionBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.count = 0;
this.term = '';
this.targetEntityTypes = null;
}
take(count) {
this.count = count;
return this;
}
setTerm(term) {
this.term = term;
return this;
}
addEntityType(...types) {
this.targetEntityTypes = types;
return this;
}
build() {
return Object.assign(Object.assign({}, this.baseBuild()), { term: this.term, take: this.count, settings: {
$type: 'Relewise.Client.Requests.Search.Settings.SearchTermPredictionSettings, Relewise.Client',
targetEntityTypes: this.targetEntityTypes,
} });
}
}
/******************************************************************************

@@ -53,3 +1224,3 @@ Copyright (c) Microsoft Corporation.

const requestUrl = this.createRequestUrl(this._serverUrl, this.datasetId, this._urlPath, name);
const response = yield fetch(requestUrl, {
const response = yield fetch__default["default"](requestUrl, {
method: 'POST',

@@ -89,3 +1260,3 @@ headers: {

lineItems: lineItems.map(l => (Object.assign(Object.assign({ product: {
id: l.productId
id: l.productId,
} }, (l.variantId && { variant: { id: l.variantId } })), { lineTotal: l.lineTotal, quantity: l.quantity }))),

@@ -96,3 +1267,3 @@ subtotal: { amount: subtotal.amount, currency: { value: subtotal.currency } },

user: user,
}
},
});

@@ -106,3 +1277,3 @@ });

lineItems: lineItems.map(l => (Object.assign(Object.assign({ product: {
id: l.productId
id: l.productId,
} }, (l.variantId && { variant: { id: l.variantId } })), { lineTotal: l.lineTotal, quantity: l.quantity }))),

@@ -112,3 +1283,3 @@ subtotal: { amount: subtotal.amount, currency: { value: subtotal.currency } },

user: user,
}
},
});

@@ -121,4 +1292,4 @@ });

productView: Object.assign(Object.assign({ product: {
id: productId
} }, (variantId && { variant: { id: variantId } })), { user: user })
id: productId,
} }, (variantId && { variant: { id: variantId } })), { user: user }),
});

@@ -133,3 +1304,3 @@ });

user: user,
}
},
});

@@ -143,6 +1314,6 @@ });

content: {
id: contentId
id: contentId,
},
user: user,
}
},
});

@@ -157,3 +1328,3 @@ });

user: user,
}
},
});

@@ -167,11 +1338,52 @@ });

brand: {
id: brandId
id: brandId,
},
user: user,
}
},
});
});
}
trackSearchTerm({ term, language, user }) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('TrackSearchTermRequest', {
searchTerm: {
language: {
value: language,
},
term: term,
user: user,
},
});
});
}
}
class Searcher extends RelewiseClient {
constructor(datasetId, apiKey, options) {
super(datasetId, apiKey, options);
this.datasetId = datasetId;
this.apiKey = apiKey;
}
searchProducts(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('ProductSearchRequest', request);
});
}
searchContents(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('ContentSearchRequest', request);
});
}
searchTermPrediction(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('SearchTermPredictionRequest', request);
});
}
batch(requestCollections) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('SearchRequestCollection', requestCollections);
});
}
}
class UserFactory {

@@ -198,3 +1410,25 @@ static anonymous() {

exports.BooleanCollectionDataValue = BooleanCollectionDataValue;
exports.BooleanDataValue = BooleanDataValue;
exports.ConditionBuilder = ConditionBuilder;
exports.ContentSearchBuilder = ContentSearchBuilder;
exports.ContentSortingBuilder = ContentSortingBuilder;
exports.DataValueBase = DataValueBase;
exports.DoubleCollectionDataValue = DoubleCollectionDataValue;
exports.FacetBuilder = FacetBuilder;
exports.FilterBuilder = FilterBuilder;
exports.MoneyDataValue = MoneyDataValue;
exports.MultiCurrencyDataValue = MultiCurrencyDataValue;
exports.MultilingualDataValue = MultilingualDataValue;
exports.NumberDataValue = NumberDataValue;
exports.PaginationBuilder = PaginationBuilder;
exports.ProductSearchBuilder = ProductSearchBuilder;
exports.ProductSortingBuilder = ProductSortingBuilder;
exports.RelewiseClient = RelewiseClient;
exports.SearchCollectionBuilder = SearchCollectionBuilder;
exports.SearchRequestBuilder = SearchRequestBuilder;
exports.SearchTermPredictionBuilder = SearchTermPredictionBuilder;
exports.Searcher = Searcher;
exports.StringCollectionDataValue = StringCollectionDataValue;
exports.StringDataValue = StringDataValue;
exports.Tracker = Tracker;

@@ -201,0 +1435,0 @@ exports.UserFactory = UserFactory;

@@ -5,2 +5,1169 @@ 'use strict';

class DataValueBase {
constructor(type, value) {
this.type = type;
this.value = value;
}
}
class StringDataValue extends DataValueBase {
constructor(value) {
super('String', value);
}
}
class StringCollectionDataValue extends DataValueBase {
constructor(value) {
super('StringList', value);
}
}
class NumberDataValue extends DataValueBase {
constructor(value) {
super('Double', value);
}
}
class DoubleCollectionDataValue extends DataValueBase {
constructor(value) {
super('DoubleList', value);
}
}
class BooleanDataValue extends DataValueBase {
constructor(value) {
super('Boolean', value);
}
}
class BooleanCollectionDataValue extends DataValueBase {
constructor(value) {
super('BooleanList', value);
}
}
class MoneyDataValue extends DataValueBase {
constructor(amount, currency) {
super('Money', {
amount: amount,
currency: { value: currency },
});
}
}
class MultiCurrencyDataValue extends DataValueBase {
constructor(values) {
super('MultiCurrency', {
values: values.map(x => ({ amount: x.amount, currency: { value: x.currency } })),
});
}
}
class MultilingualDataValue extends DataValueBase {
constructor(values) {
super('Multilingual', {
values: values.map(x => ({ text: x.value, language: { value: x.language } })),
});
}
}
class ConditionBuilder {
constructor() {
this.conditions = [];
}
addContainsCondition(value, valueCollectionEvaluationMode = 'All', negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.ContainsCondition, Relewise.Client',
value: value,
valueCollectionEvaluationMode: valueCollectionEvaluationMode,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addDistinctCondition(numberOfOccurrencesAllowedWithTheSameValue, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.DistinctCondition, Relewise.Client',
numberOfOccurrencesAllowedWithTheSameValue: numberOfOccurrencesAllowedWithTheSameValue,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addEqualsCondition(value, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.EqualsCondition, Relewise.Client',
value: value,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addGreaterThanCondition(value, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.GreaterThanCondition, Relewise.Client',
value: value,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addLessThanCondition(value, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.LessThanCondition, Relewise.Client',
value: value,
negated: negated,
};
this.conditions.push(condition);
return this;
}
build() {
return this.conditions.length === 0
? null
: { items: this.conditions };
}
}
class FilterBuilder {
constructor() {
this.filters = [];
}
/**
* Adds a product assortment filter to the request
* @param assortmentIds
* @param negated
*/
addProductAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a variant assortment filter to the request
* @param assortmentIds
* @param negated
*/
addVariantAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a brand assortment filter to the request
* @param assortmentIds
* @param negated
*/
addBrandAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.BrandAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a content category assortment filter to the request
* @param assortmentIds
* @param negated
*/
addContentCategoryAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a content category assortment filter to the request
* @param assortmentIds
* @param negated
*/
addProductCategoryAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products within the specificed categories
* @param evaluationScope
* @param categoryIds
* @param negated
*/
addProductCategoryIdFilter(evaluationScope, categoryIds, negated = false) {
const ids = Array.isArray(categoryIds)
? categoryIds
: [categoryIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryIdFilter, Relewise.Client',
evaluationScope: evaluationScope,
categoryIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return contents within the specificed categories
* @param evaluationScope
* @param categoryIds
* @param negated
*/
addContentCategoryIdFilter(evaluationScope, categoryIds, negated = false) {
const ids = Array.isArray(categoryIds)
? categoryIds
: [categoryIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryIdFilter, Relewise.Client',
evaluationScope: evaluationScope,
categoryIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied products
* @param productIds
* @param negated
*/
addProductIdFilter(productIds, negated = false) {
const ids = Array.isArray(productIds)
? productIds
: [productIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductIdFilter, Relewise.Client',
productIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied variants
* @param variantIds
* @param negated
*/
addVariantIdFilter(variantIds, negated = false) {
const ids = Array.isArray(variantIds)
? variantIds
: [variantIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantIdFilter, Relewise.Client',
variantIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied brands
* @param brandIds
* @param negated
*/
addBrandIdFilter(brandIds, negated = false) {
const ids = Array.isArray(brandIds)
? brandIds
: [brandIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.BrandIdFilter, Relewise.Client',
brandIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied contents
* @param contentIds
* @param negated
*/
addContentIdFilter(contentIds, negated = false) {
const ids = Array.isArray(contentIds)
? contentIds
: [contentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentIdFilter, Relewise.Client',
contentIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a range filter to the request ensuring the product has a certain range of variants
* @param lowerBound
* @param upperBound
* @param negated
*/
addProductHasVariantsFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductHasVariantsFilter, Relewise.Client',
numberOfVariants: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products purchased since a certain point in time
* @param sinceUtc
* @param negated
*/
addProductRecentlyPurchasedByUserFilter(sinceUtc, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductRecentlyPurchasedByUserFilter, Relewise.Client',
sinceUtc: sinceUtc,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products viewed since a certain point in time
* @param sinceUtc
* @param negated
*/
addProductRecentlyViewedByUserFilter(sinceUtc, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductRecentlyViewedByUserFilter, Relewise.Client',
sinceUtc: sinceUtc,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products within a certain SalesPrice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addProductSalesPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductSalesPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products within a certain ListPice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addProductListPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductListPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return variants within a certain SalesPrice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addVariantSalesPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantSalesPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return variants within a certain ListPice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addVariantListPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantListPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return variants with a certain specification
* @param key
* @param equalTo
* @param filterOutIfKeyIsNotFound controls if variants with or without the key should be returned
* @param negated
*/
addVariantSpecificationFilter(key, equalTo, filterOutIfKeyIsNotFound = true, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantSpecificationFilter, Relewise.Client',
key: key,
equalTo: equalTo,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
negated: negated,
};
this.filters.push(filter);
return this;
}
and(filterBuilder, negated = false) {
const builder = new FilterBuilder();
filterBuilder(builder);
const filters = builder.build();
if (filters === null || filters.items === undefined || filters.items === null || filters.items.length <= 0) {
throw new Error('And-filters must contain atleast 1 filter');
}
const filter = {
$type: 'Relewise.Client.Requests.Filters.AndFilter, Relewise.Client',
filters: filters.items,
negated: negated,
};
this.filters.push(filter);
return this;
}
or(filterBuilder, negated = false) {
const builder = new FilterBuilder();
filterBuilder(builder);
const filters = builder.build();
if (filters === null || filters.items === undefined || filters.items === null || filters.items.length <= 0) {
throw new Error('Or-filters must contain atleast 1 filter');
}
const filter = {
$type: 'Relewise.Client.Requests.Filters.OrFilter, Relewise.Client',
filters: filters.items,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a product data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addProductDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a variant data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addVariantDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a brand data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addBrandDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.BrandDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a cart data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addCartDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.CartDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a cart data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addContentCategoryDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a content data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addContentDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a product category data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addProductCategoryDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a product display name filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addProductDisplayNameFilter(conditionBuilder, mustMatchAllConditions = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductDisplayNameFilter, Relewise.Client',
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
reset() {
this.filters = [];
return this;
}
build() {
return this.filters.length === 0
? null
: { items: this.filters };
}
}
class PaginationBuilder {
constructor() {
this.pageNumber = 1;
this.pageSize = 10;
}
/**
* Defines how many results to return
* @param pageSize
* @returns
*/
setPageSize(pageSize) {
if (pageSize < 0) {
throw new Error('pageSize can not be below 0');
}
this.pageSize = pageSize;
return this;
}
/**
* Page starts at 1, so this to skip 'X' pages of results
* @param pageNumber
* @returns
*/
setPage(pageNumber) {
if (pageNumber < 1) {
throw new Error('pageNumber can not be below 1');
}
this.pageNumber = pageNumber;
return this;
}
build() {
return {
take: this.pageSize,
skip: (this.pageNumber - 1) * this.pageSize,
};
}
}
class FacetBuilder {
constructor() {
this.facets = [];
}
addCategoryFacet(categorySelectionStrategy, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.CategoryFacet, Relewise.Client',
categorySelectionStrategy: categorySelectionStrategy,
field: 'Category',
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addBrandFacet(selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.BrandFacet, Relewise.Client',
field: 'Brand',
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addProductAssortmentFacet(selectionStrategy, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductAssortmentFacet, Relewise.Client',
field: 'Assortment',
assortmentFilterType: 'Or',
assortmentSelectionStrategy: selectionStrategy,
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addContentAssortmentFacet(selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ContentAssortmentFacet, Relewise.Client',
field: 'Assortment',
assortmentFilterType: 'Or',
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addVariantSpecificationFacet(key, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.VariantSpecificationFacet, Relewise.Client',
field: 'VariantSpecification',
key: key,
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addProductDataDoubleRangeFacet(key, selectionStrategy, lowerBound, upperBound) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataDoubleRangeFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
};
this.facets.push(facet);
return this;
}
addProductDataStringValueFacet(key, selectionStrategy, selectedValues = null, collectionFilterType) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataStringValueFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: selectedValues,
collectionFilterType: collectionFilterType,
};
this.facets.push(facet);
return this;
}
addProductDataBooleanValueFacet(key, selectionStrategy, selectedValues = null, collectionFilterType) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataBooleanValueFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: selectedValues,
collectionFilterType: collectionFilterType,
};
this.facets.push(facet);
return this;
}
addProductDataDoubleValueFacet(key, selectionStrategy, selectedValues = null, collectionFilterType) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataDoubleValueFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: selectedValues,
collectionFilterType: collectionFilterType,
};
this.facets.push(facet);
return this;
}
addSalesPriceRangeFacet(priceSelectionStrategy, lowerBound, upperBound) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangeFacet, Relewise.Client',
field: 'SalesPrice',
selected: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
priceSelectionStrategy,
};
this.facets.push(facet);
return this;
}
addListPriceRangeFacet(priceSelectionStrategy, lowerBound, upperBound) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangeFacet, Relewise.Client',
field: 'ListPrice',
selected: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
priceSelectionStrategy,
};
this.facets.push(facet);
return this;
}
addListPriceRangesFacet(priceSelectionStrategy, predefinedRanges, expandedRangeSize, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangesFacet, Relewise.Client',
field: 'ListPrice',
predefinedRanges: predefinedRanges === null || predefinedRanges === void 0 ? void 0 : predefinedRanges.map(x => ({ lowerBoundInclusive: x.lowerBound, upperBoundExclusive: x.upperBound })),
expandedRangeSize: expandedRangeSize,
selected: selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.map(x => ({ lowerBoundInclusive: x.lowerBound, upperBoundExclusive: x.upperBound })),
priceSelectionStrategy,
};
this.facets.push(facet);
return this;
}
build() {
return this.facets.length === 0
? null
: { items: this.facets };
}
}
class ProductSortingBuilder {
constructor() {
this.value = null;
}
sortByProductData(key, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductDataSorting, Relewise.Client',
dataSelectionStrategy: 'Product',
mode,
order,
key,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductRelevance(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductRelevanceSorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductPopularity(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductPopularitySorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductAttribute(attribute, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductAttributeSorting, Relewise.Client',
attribute,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductVariantAttribute(attribute, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductVariantAttributeSorting, Relewise.Client',
attribute,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductVariantSpecification(key, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductVariantSpecificationSorting, Relewise.Client',
key,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
thenBy(thenBy) {
const thenByBuilder = new ProductSortingBuilder();
if (thenBy) {
thenBy(thenByBuilder);
thenByBuilder.build();
}
return thenByBuilder;
}
build() {
return this.value == null
? null
: { value: this.value };
}
}
class ContentSortingBuilder {
constructor() {
this.value = null;
}
sortByContentData(key, order = 'Descending', mode = 'Auto', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentDataSorting, Relewise.Client',
mode,
order,
key,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByContentRelevance(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentRelevanceSorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByContentPopularity(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentPopularitySorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByContentAttribute(attribute, order, mode = 'Auto', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentAttributeSorting, Relewise.Client',
attribute,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
thenBy(thenBy) {
const thenByBuilder = new ContentSortingBuilder();
if (thenBy) {
thenBy(thenByBuilder);
thenByBuilder.build();
}
return thenByBuilder;
}
build() {
return this.value == null
? null
: { value: this.value };
}
}
class SearchRequestBuilder {
constructor(settings) {
this.settings = settings;
this.filterBuilder = new FilterBuilder();
this.postFilterBuilder = new FilterBuilder();
}
/**
* Adds filters to the request
* @param filterBuilder
* @returns
*/
filters(filterBuilder) {
filterBuilder(this.filterBuilder);
return this;
}
/**
* Adds post filters to the request
* @param filterBuilder
* @returns
*/
postFilters(filterBuilder) {
filterBuilder(this.postFilterBuilder);
return this;
}
/**
* Use only when a specific index different from the 'default'-index is needed
* @param id
* @returns
*/
setIndex(id) {
this.indexId = id;
return this;
}
baseBuild() {
return Object.assign({ currency: { value: this.settings.currency }, user: this.settings.user, language: { value: this.settings.language }, displayedAtLocation: this.settings.displayedAtLocation, filters: this.filterBuilder.build(), postFilters: this.postFilterBuilder.build(), relevanceModifiers: null }, (this.indexId && { indexSelector: { id: this.indexId } }));
}
}
class ContentSearchBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.facetBuilder = new FacetBuilder();
this.paginationBuilder = new PaginationBuilder();
this.sortingBuilder = new ContentSortingBuilder();
this.searchSettings = {
$type: 'Relewise.Client.Requests.Search.Settings.ContentSearchSettings, Relewise.Client',
recommendations: {},
};
}
setContentProperties(contentProperties) {
this.searchSettings.selectedContentProperties = contentProperties;
return this;
}
setRecommendationSettings(settings) {
this.searchSettings.recommendations = settings;
return this;
}
setTerm(term) {
this.term = term;
return this;
}
pagination(paginate) {
paginate(this.paginationBuilder);
return this;
}
facets(facets) {
facets(this.facetBuilder);
return this;
}
sorting(sorting) {
sorting(this.sortingBuilder);
return this;
}
build() {
const { take, skip } = this.paginationBuilder.build();
return Object.assign(Object.assign({}, this.baseBuild()), { settings: this.searchSettings, take,
skip, term: this.term, facets: this.facetBuilder.build(), sorting: this.sortingBuilder.build() });
}
}
class ProductSearchBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.facetBuilder = new FacetBuilder();
this.paginationBuilder = new PaginationBuilder();
this.sortingBuilder = new ProductSortingBuilder();
this.searchSettings = {
$type: 'Relewise.Client.Requests.Search.Settings.ProductSearchSettings, Relewise.Client',
recommendations: {},
};
}
setSelectedProductProperties(productProperties) {
this.searchSettings.selectedProductProperties = productProperties;
return this;
}
setSelectedVariantProperties(variantProperties) {
this.searchSettings.selectedVariantProperties = variantProperties;
return this;
}
setSelectedBrandProperties(brandProperties) {
this.searchSettings.selectedBrandProperties = brandProperties;
return this;
}
setExplodedVariants(count) {
this.searchSettings.explodedVariants = count;
return this;
}
setRecommendationSettings(settings) {
this.searchSettings.recommendations = settings;
return this;
}
/**
* Set the term used to filter products by
*/
setTerm(term) {
this.term = term;
return this;
}
pagination(paginate) {
paginate(this.paginationBuilder);
return this;
}
facets(facets) {
facets(this.facetBuilder);
return this;
}
sorting(sorting) {
sorting(this.sortingBuilder);
return this;
}
build() {
const { take, skip } = this.paginationBuilder.build();
return Object.assign(Object.assign({}, this.baseBuild()), { take,
skip, term: this.term, facets: this.facetBuilder.build(), settings: this.searchSettings, sorting: this.sortingBuilder.build() });
}
}
class SearchCollectionBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.requests = [];
}
addRequest(request) {
this.requests.push(request);
return this;
}
build() {
return Object.assign(Object.assign({}, this.baseBuild()), { requests: this.requests });
}
}
class SearchTermPredictionBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.count = 0;
this.term = '';
this.targetEntityTypes = null;
}
take(count) {
this.count = count;
return this;
}
setTerm(term) {
this.term = term;
return this;
}
addEntityType(...types) {
this.targetEntityTypes = types;
return this;
}
build() {
return Object.assign(Object.assign({}, this.baseBuild()), { term: this.term, take: this.count, settings: {
$type: 'Relewise.Client.Requests.Search.Settings.SearchTermPredictionSettings, Relewise.Client',
targetEntityTypes: this.targetEntityTypes,
} });
}
}
/******************************************************************************

@@ -87,3 +1254,3 @@ Copyright (c) Microsoft Corporation.

lineItems: lineItems.map(l => (Object.assign(Object.assign({ product: {
id: l.productId
id: l.productId,
} }, (l.variantId && { variant: { id: l.variantId } })), { lineTotal: l.lineTotal, quantity: l.quantity }))),

@@ -94,3 +1261,3 @@ subtotal: { amount: subtotal.amount, currency: { value: subtotal.currency } },

user: user,
}
},
});

@@ -104,3 +1271,3 @@ });

lineItems: lineItems.map(l => (Object.assign(Object.assign({ product: {
id: l.productId
id: l.productId,
} }, (l.variantId && { variant: { id: l.variantId } })), { lineTotal: l.lineTotal, quantity: l.quantity }))),

@@ -110,3 +1277,3 @@ subtotal: { amount: subtotal.amount, currency: { value: subtotal.currency } },

user: user,
}
},
});

@@ -119,4 +1286,4 @@ });

productView: Object.assign(Object.assign({ product: {
id: productId
} }, (variantId && { variant: { id: variantId } })), { user: user })
id: productId,
} }, (variantId && { variant: { id: variantId } })), { user: user }),
});

@@ -131,3 +1298,3 @@ });

user: user,
}
},
});

@@ -141,6 +1308,6 @@ });

content: {
id: contentId
id: contentId,
},
user: user,
}
},
});

@@ -155,3 +1322,3 @@ });

user: user,
}
},
});

@@ -165,11 +1332,52 @@ });

brand: {
id: brandId
id: brandId,
},
user: user,
}
},
});
});
}
trackSearchTerm({ term, language, user }) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('TrackSearchTermRequest', {
searchTerm: {
language: {
value: language,
},
term: term,
user: user,
},
});
});
}
}
class Searcher extends RelewiseClient {
constructor(datasetId, apiKey, options) {
super(datasetId, apiKey, options);
this.datasetId = datasetId;
this.apiKey = apiKey;
}
searchProducts(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('ProductSearchRequest', request);
});
}
searchContents(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('ContentSearchRequest', request);
});
}
searchTermPrediction(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('SearchTermPredictionRequest', request);
});
}
batch(requestCollections) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('SearchRequestCollection', requestCollections);
});
}
}
class UserFactory {

@@ -196,5 +1404,27 @@ static anonymous() {

exports.BooleanCollectionDataValue = BooleanCollectionDataValue;
exports.BooleanDataValue = BooleanDataValue;
exports.ConditionBuilder = ConditionBuilder;
exports.ContentSearchBuilder = ContentSearchBuilder;
exports.ContentSortingBuilder = ContentSortingBuilder;
exports.DataValueBase = DataValueBase;
exports.DoubleCollectionDataValue = DoubleCollectionDataValue;
exports.FacetBuilder = FacetBuilder;
exports.FilterBuilder = FilterBuilder;
exports.MoneyDataValue = MoneyDataValue;
exports.MultiCurrencyDataValue = MultiCurrencyDataValue;
exports.MultilingualDataValue = MultilingualDataValue;
exports.NumberDataValue = NumberDataValue;
exports.PaginationBuilder = PaginationBuilder;
exports.ProductSearchBuilder = ProductSearchBuilder;
exports.ProductSortingBuilder = ProductSortingBuilder;
exports.RelewiseClient = RelewiseClient;
exports.SearchCollectionBuilder = SearchCollectionBuilder;
exports.SearchRequestBuilder = SearchRequestBuilder;
exports.SearchTermPredictionBuilder = SearchTermPredictionBuilder;
exports.Searcher = Searcher;
exports.StringCollectionDataValue = StringCollectionDataValue;
exports.StringDataValue = StringDataValue;
exports.Tracker = Tracker;
exports.UserFactory = UserFactory;
//# sourceMappingURL=relewise-client.js.map

@@ -0,1 +1,1168 @@

class DataValueBase {
constructor(type, value) {
this.type = type;
this.value = value;
}
}
class StringDataValue extends DataValueBase {
constructor(value) {
super('String', value);
}
}
class StringCollectionDataValue extends DataValueBase {
constructor(value) {
super('StringList', value);
}
}
class NumberDataValue extends DataValueBase {
constructor(value) {
super('Double', value);
}
}
class DoubleCollectionDataValue extends DataValueBase {
constructor(value) {
super('DoubleList', value);
}
}
class BooleanDataValue extends DataValueBase {
constructor(value) {
super('Boolean', value);
}
}
class BooleanCollectionDataValue extends DataValueBase {
constructor(value) {
super('BooleanList', value);
}
}
class MoneyDataValue extends DataValueBase {
constructor(amount, currency) {
super('Money', {
amount: amount,
currency: { value: currency },
});
}
}
class MultiCurrencyDataValue extends DataValueBase {
constructor(values) {
super('MultiCurrency', {
values: values.map(x => ({ amount: x.amount, currency: { value: x.currency } })),
});
}
}
class MultilingualDataValue extends DataValueBase {
constructor(values) {
super('Multilingual', {
values: values.map(x => ({ text: x.value, language: { value: x.language } })),
});
}
}
class ConditionBuilder {
constructor() {
this.conditions = [];
}
addContainsCondition(value, valueCollectionEvaluationMode = 'All', negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.ContainsCondition, Relewise.Client',
value: value,
valueCollectionEvaluationMode: valueCollectionEvaluationMode,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addDistinctCondition(numberOfOccurrencesAllowedWithTheSameValue, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.DistinctCondition, Relewise.Client',
numberOfOccurrencesAllowedWithTheSameValue: numberOfOccurrencesAllowedWithTheSameValue,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addEqualsCondition(value, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.EqualsCondition, Relewise.Client',
value: value,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addGreaterThanCondition(value, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.GreaterThanCondition, Relewise.Client',
value: value,
negated: negated,
};
this.conditions.push(condition);
return this;
}
addLessThanCondition(value, negated = false) {
const condition = {
$type: 'Relewise.Client.Requests.Conditions.LessThanCondition, Relewise.Client',
value: value,
negated: negated,
};
this.conditions.push(condition);
return this;
}
build() {
return this.conditions.length === 0
? null
: { items: this.conditions };
}
}
class FilterBuilder {
constructor() {
this.filters = [];
}
/**
* Adds a product assortment filter to the request
* @param assortmentIds
* @param negated
*/
addProductAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a variant assortment filter to the request
* @param assortmentIds
* @param negated
*/
addVariantAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a brand assortment filter to the request
* @param assortmentIds
* @param negated
*/
addBrandAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.BrandAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a content category assortment filter to the request
* @param assortmentIds
* @param negated
*/
addContentCategoryAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a content category assortment filter to the request
* @param assortmentIds
* @param negated
*/
addProductCategoryAssortmentFilter(assortmentIds, negated = false) {
const assortments = Array.isArray(assortmentIds)
? assortmentIds
: [assortmentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryAssortmentFilter, Relewise.Client',
assortments: assortments,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products within the specificed categories
* @param evaluationScope
* @param categoryIds
* @param negated
*/
addProductCategoryIdFilter(evaluationScope, categoryIds, negated = false) {
const ids = Array.isArray(categoryIds)
? categoryIds
: [categoryIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryIdFilter, Relewise.Client',
evaluationScope: evaluationScope,
categoryIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return contents within the specificed categories
* @param evaluationScope
* @param categoryIds
* @param negated
*/
addContentCategoryIdFilter(evaluationScope, categoryIds, negated = false) {
const ids = Array.isArray(categoryIds)
? categoryIds
: [categoryIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryIdFilter, Relewise.Client',
evaluationScope: evaluationScope,
categoryIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied products
* @param productIds
* @param negated
*/
addProductIdFilter(productIds, negated = false) {
const ids = Array.isArray(productIds)
? productIds
: [productIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductIdFilter, Relewise.Client',
productIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied variants
* @param variantIds
* @param negated
*/
addVariantIdFilter(variantIds, negated = false) {
const ids = Array.isArray(variantIds)
? variantIds
: [variantIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantIdFilter, Relewise.Client',
variantIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied brands
* @param brandIds
* @param negated
*/
addBrandIdFilter(brandIds, negated = false) {
const ids = Array.isArray(brandIds)
? brandIds
: [brandIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.BrandIdFilter, Relewise.Client',
brandIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return the specificied contents
* @param contentIds
* @param negated
*/
addContentIdFilter(contentIds, negated = false) {
const ids = Array.isArray(contentIds)
? contentIds
: [contentIds];
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentIdFilter, Relewise.Client',
contentIds: ids,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a range filter to the request ensuring the product has a certain range of variants
* @param lowerBound
* @param upperBound
* @param negated
*/
addProductHasVariantsFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductHasVariantsFilter, Relewise.Client',
numberOfVariants: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products purchased since a certain point in time
* @param sinceUtc
* @param negated
*/
addProductRecentlyPurchasedByUserFilter(sinceUtc, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductRecentlyPurchasedByUserFilter, Relewise.Client',
sinceUtc: sinceUtc,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products viewed since a certain point in time
* @param sinceUtc
* @param negated
*/
addProductRecentlyViewedByUserFilter(sinceUtc, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductRecentlyViewedByUserFilter, Relewise.Client',
sinceUtc: sinceUtc,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products within a certain SalesPrice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addProductSalesPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductSalesPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return products within a certain ListPice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addProductListPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductListPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return variants within a certain SalesPrice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addVariantSalesPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantSalesPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return variants within a certain ListPice-range
* @param lowerBound
* @param upperBound
* @param negated
*/
addVariantListPriceFilter(lowerBound, upperBound, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantListPriceFilter, Relewise.Client',
range: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Filters the request to only return variants with a certain specification
* @param key
* @param equalTo
* @param filterOutIfKeyIsNotFound controls if variants with or without the key should be returned
* @param negated
*/
addVariantSpecificationFilter(key, equalTo, filterOutIfKeyIsNotFound = true, negated = false) {
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantSpecificationFilter, Relewise.Client',
key: key,
equalTo: equalTo,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
negated: negated,
};
this.filters.push(filter);
return this;
}
and(filterBuilder, negated = false) {
const builder = new FilterBuilder();
filterBuilder(builder);
const filters = builder.build();
if (filters === null || filters.items === undefined || filters.items === null || filters.items.length <= 0) {
throw new Error('And-filters must contain atleast 1 filter');
}
const filter = {
$type: 'Relewise.Client.Requests.Filters.AndFilter, Relewise.Client',
filters: filters.items,
negated: negated,
};
this.filters.push(filter);
return this;
}
or(filterBuilder, negated = false) {
const builder = new FilterBuilder();
filterBuilder(builder);
const filters = builder.build();
if (filters === null || filters.items === undefined || filters.items === null || filters.items.length <= 0) {
throw new Error('Or-filters must contain atleast 1 filter');
}
const filter = {
$type: 'Relewise.Client.Requests.Filters.OrFilter, Relewise.Client',
filters: filters.items,
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a product data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addProductDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a variant data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addVariantDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.VariantDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a brand data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addBrandDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.BrandDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a cart data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addCartDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.CartDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a cart data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addContentCategoryDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentCategoryDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a content data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addContentDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ContentDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a product category data filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addProductCategoryDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductCategoryDataFilter, Relewise.Client',
key: key,
filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound,
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
/**
* Adds a product display name filter to the request
* @param key
* @param conditionBuilder
* @param mustMatchAllConditions
* @param filterOutIfKeyIsNotFound
* @param negated
*/
addProductDisplayNameFilter(conditionBuilder, mustMatchAllConditions = true, negated = false) {
const builder = new ConditionBuilder();
conditionBuilder(builder);
const filter = {
$type: 'Relewise.Client.Requests.Filters.ProductDisplayNameFilter, Relewise.Client',
mustMatchAllConditions: mustMatchAllConditions,
conditions: builder.build(),
negated: negated,
};
this.filters.push(filter);
return this;
}
reset() {
this.filters = [];
return this;
}
build() {
return this.filters.length === 0
? null
: { items: this.filters };
}
}
class PaginationBuilder {
constructor() {
this.pageNumber = 1;
this.pageSize = 10;
}
/**
* Defines how many results to return
* @param pageSize
* @returns
*/
setPageSize(pageSize) {
if (pageSize < 0) {
throw new Error('pageSize can not be below 0');
}
this.pageSize = pageSize;
return this;
}
/**
* Page starts at 1, so this to skip 'X' pages of results
* @param pageNumber
* @returns
*/
setPage(pageNumber) {
if (pageNumber < 1) {
throw new Error('pageNumber can not be below 1');
}
this.pageNumber = pageNumber;
return this;
}
build() {
return {
take: this.pageSize,
skip: (this.pageNumber - 1) * this.pageSize,
};
}
}
class FacetBuilder {
constructor() {
this.facets = [];
}
addCategoryFacet(categorySelectionStrategy, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.CategoryFacet, Relewise.Client',
categorySelectionStrategy: categorySelectionStrategy,
field: 'Category',
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addBrandFacet(selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.BrandFacet, Relewise.Client',
field: 'Brand',
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addProductAssortmentFacet(selectionStrategy, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductAssortmentFacet, Relewise.Client',
field: 'Assortment',
assortmentFilterType: 'Or',
assortmentSelectionStrategy: selectionStrategy,
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addContentAssortmentFacet(selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ContentAssortmentFacet, Relewise.Client',
field: 'Assortment',
assortmentFilterType: 'Or',
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addVariantSpecificationFacet(key, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.VariantSpecificationFacet, Relewise.Client',
field: 'VariantSpecification',
key: key,
selected: selectedValues,
};
this.facets.push(facet);
return this;
}
addProductDataDoubleRangeFacet(key, selectionStrategy, lowerBound, upperBound) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataDoubleRangeFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
};
this.facets.push(facet);
return this;
}
addProductDataStringValueFacet(key, selectionStrategy, selectedValues = null, collectionFilterType) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataStringValueFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: selectedValues,
collectionFilterType: collectionFilterType,
};
this.facets.push(facet);
return this;
}
addProductDataBooleanValueFacet(key, selectionStrategy, selectedValues = null, collectionFilterType) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataBooleanValueFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: selectedValues,
collectionFilterType: collectionFilterType,
};
this.facets.push(facet);
return this;
}
addProductDataDoubleValueFacet(key, selectionStrategy, selectedValues = null, collectionFilterType) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataDoubleValueFacet, Relewise.Client',
field: 'Data',
key: key,
dataSelectionStrategy: selectionStrategy,
selected: selectedValues,
collectionFilterType: collectionFilterType,
};
this.facets.push(facet);
return this;
}
addSalesPriceRangeFacet(priceSelectionStrategy, lowerBound, upperBound) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangeFacet, Relewise.Client',
field: 'SalesPrice',
selected: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
priceSelectionStrategy,
};
this.facets.push(facet);
return this;
}
addListPriceRangeFacet(priceSelectionStrategy, lowerBound, upperBound) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangeFacet, Relewise.Client',
field: 'ListPrice',
selected: {
lowerBoundInclusive: lowerBound,
upperBoundInclusive: upperBound,
},
priceSelectionStrategy,
};
this.facets.push(facet);
return this;
}
addListPriceRangesFacet(priceSelectionStrategy, predefinedRanges, expandedRangeSize, selectedValues = null) {
const facet = {
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangesFacet, Relewise.Client',
field: 'ListPrice',
predefinedRanges: predefinedRanges === null || predefinedRanges === void 0 ? void 0 : predefinedRanges.map(x => ({ lowerBoundInclusive: x.lowerBound, upperBoundExclusive: x.upperBound })),
expandedRangeSize: expandedRangeSize,
selected: selectedValues === null || selectedValues === void 0 ? void 0 : selectedValues.map(x => ({ lowerBoundInclusive: x.lowerBound, upperBoundExclusive: x.upperBound })),
priceSelectionStrategy,
};
this.facets.push(facet);
return this;
}
build() {
return this.facets.length === 0
? null
: { items: this.facets };
}
}
class ProductSortingBuilder {
constructor() {
this.value = null;
}
sortByProductData(key, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductDataSorting, Relewise.Client',
dataSelectionStrategy: 'Product',
mode,
order,
key,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductRelevance(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductRelevanceSorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductPopularity(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductPopularitySorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductAttribute(attribute, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductAttributeSorting, Relewise.Client',
attribute,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductVariantAttribute(attribute, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductVariantAttributeSorting, Relewise.Client',
attribute,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByProductVariantSpecification(key, order, thenBy, mode = 'Auto') {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Product.ProductVariantSpecificationSorting, Relewise.Client',
key,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
thenBy(thenBy) {
const thenByBuilder = new ProductSortingBuilder();
if (thenBy) {
thenBy(thenByBuilder);
thenByBuilder.build();
}
return thenByBuilder;
}
build() {
return this.value == null
? null
: { value: this.value };
}
}
class ContentSortingBuilder {
constructor() {
this.value = null;
}
sortByContentData(key, order = 'Descending', mode = 'Auto', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentDataSorting, Relewise.Client',
mode,
order,
key,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByContentRelevance(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentRelevanceSorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByContentPopularity(order = 'Descending', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentPopularitySorting, Relewise.Client',
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
sortByContentAttribute(attribute, order, mode = 'Auto', thenBy) {
var _a;
const sort = {
$type: 'Relewise.Client.DataTypes.Search.Sorting.Content.ContentAttributeSorting, Relewise.Client',
attribute,
mode,
order,
thenBy: (_a = this.thenBy(thenBy)) === null || _a === void 0 ? void 0 : _a.value,
};
this.value = sort;
}
thenBy(thenBy) {
const thenByBuilder = new ContentSortingBuilder();
if (thenBy) {
thenBy(thenByBuilder);
thenByBuilder.build();
}
return thenByBuilder;
}
build() {
return this.value == null
? null
: { value: this.value };
}
}
class SearchRequestBuilder {
constructor(settings) {
this.settings = settings;
this.filterBuilder = new FilterBuilder();
this.postFilterBuilder = new FilterBuilder();
}
/**
* Adds filters to the request
* @param filterBuilder
* @returns
*/
filters(filterBuilder) {
filterBuilder(this.filterBuilder);
return this;
}
/**
* Adds post filters to the request
* @param filterBuilder
* @returns
*/
postFilters(filterBuilder) {
filterBuilder(this.postFilterBuilder);
return this;
}
/**
* Use only when a specific index different from the 'default'-index is needed
* @param id
* @returns
*/
setIndex(id) {
this.indexId = id;
return this;
}
baseBuild() {
return Object.assign({ currency: { value: this.settings.currency }, user: this.settings.user, language: { value: this.settings.language }, displayedAtLocation: this.settings.displayedAtLocation, filters: this.filterBuilder.build(), postFilters: this.postFilterBuilder.build(), relevanceModifiers: null }, (this.indexId && { indexSelector: { id: this.indexId } }));
}
}
class ContentSearchBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.facetBuilder = new FacetBuilder();
this.paginationBuilder = new PaginationBuilder();
this.sortingBuilder = new ContentSortingBuilder();
this.searchSettings = {
$type: 'Relewise.Client.Requests.Search.Settings.ContentSearchSettings, Relewise.Client',
recommendations: {},
};
}
setContentProperties(contentProperties) {
this.searchSettings.selectedContentProperties = contentProperties;
return this;
}
setRecommendationSettings(settings) {
this.searchSettings.recommendations = settings;
return this;
}
setTerm(term) {
this.term = term;
return this;
}
pagination(paginate) {
paginate(this.paginationBuilder);
return this;
}
facets(facets) {
facets(this.facetBuilder);
return this;
}
sorting(sorting) {
sorting(this.sortingBuilder);
return this;
}
build() {
const { take, skip } = this.paginationBuilder.build();
return Object.assign(Object.assign({}, this.baseBuild()), { settings: this.searchSettings, take,
skip, term: this.term, facets: this.facetBuilder.build(), sorting: this.sortingBuilder.build() });
}
}
class ProductSearchBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.facetBuilder = new FacetBuilder();
this.paginationBuilder = new PaginationBuilder();
this.sortingBuilder = new ProductSortingBuilder();
this.searchSettings = {
$type: 'Relewise.Client.Requests.Search.Settings.ProductSearchSettings, Relewise.Client',
recommendations: {},
};
}
setSelectedProductProperties(productProperties) {
this.searchSettings.selectedProductProperties = productProperties;
return this;
}
setSelectedVariantProperties(variantProperties) {
this.searchSettings.selectedVariantProperties = variantProperties;
return this;
}
setSelectedBrandProperties(brandProperties) {
this.searchSettings.selectedBrandProperties = brandProperties;
return this;
}
setExplodedVariants(count) {
this.searchSettings.explodedVariants = count;
return this;
}
setRecommendationSettings(settings) {
this.searchSettings.recommendations = settings;
return this;
}
/**
* Set the term used to filter products by
*/
setTerm(term) {
this.term = term;
return this;
}
pagination(paginate) {
paginate(this.paginationBuilder);
return this;
}
facets(facets) {
facets(this.facetBuilder);
return this;
}
sorting(sorting) {
sorting(this.sortingBuilder);
return this;
}
build() {
const { take, skip } = this.paginationBuilder.build();
return Object.assign(Object.assign({}, this.baseBuild()), { take,
skip, term: this.term, facets: this.facetBuilder.build(), settings: this.searchSettings, sorting: this.sortingBuilder.build() });
}
}
class SearchCollectionBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.requests = [];
}
addRequest(request) {
this.requests.push(request);
return this;
}
build() {
return Object.assign(Object.assign({}, this.baseBuild()), { requests: this.requests });
}
}
class SearchTermPredictionBuilder extends SearchRequestBuilder {
constructor(settings) {
super(settings);
this.count = 0;
this.term = '';
this.targetEntityTypes = null;
}
take(count) {
this.count = count;
return this;
}
setTerm(term) {
this.term = term;
return this;
}
addEntityType(...types) {
this.targetEntityTypes = types;
return this;
}
build() {
return Object.assign(Object.assign({}, this.baseBuild()), { term: this.term, take: this.count, settings: {
$type: 'Relewise.Client.Requests.Search.Settings.SearchTermPredictionSettings, Relewise.Client',
targetEntityTypes: this.targetEntityTypes,
} });
}
}
/******************************************************************************

@@ -82,3 +1249,3 @@ Copyright (c) Microsoft Corporation.

lineItems: lineItems.map(l => (Object.assign(Object.assign({ product: {
id: l.productId
id: l.productId,
} }, (l.variantId && { variant: { id: l.variantId } })), { lineTotal: l.lineTotal, quantity: l.quantity }))),

@@ -89,3 +1256,3 @@ subtotal: { amount: subtotal.amount, currency: { value: subtotal.currency } },

user: user,
}
},
});

@@ -99,3 +1266,3 @@ });

lineItems: lineItems.map(l => (Object.assign(Object.assign({ product: {
id: l.productId
id: l.productId,
} }, (l.variantId && { variant: { id: l.variantId } })), { lineTotal: l.lineTotal, quantity: l.quantity }))),

@@ -105,3 +1272,3 @@ subtotal: { amount: subtotal.amount, currency: { value: subtotal.currency } },

user: user,
}
},
});

@@ -114,4 +1281,4 @@ });

productView: Object.assign(Object.assign({ product: {
id: productId
} }, (variantId && { variant: { id: variantId } })), { user: user })
id: productId,
} }, (variantId && { variant: { id: variantId } })), { user: user }),
});

@@ -126,3 +1293,3 @@ });

user: user,
}
},
});

@@ -136,6 +1303,6 @@ });

content: {
id: contentId
id: contentId,
},
user: user,
}
},
});

@@ -150,3 +1317,3 @@ });

user: user,
}
},
});

@@ -160,11 +1327,52 @@ });

brand: {
id: brandId
id: brandId,
},
user: user,
}
},
});
});
}
trackSearchTerm({ term, language, user }) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('TrackSearchTermRequest', {
searchTerm: {
language: {
value: language,
},
term: term,
user: user,
},
});
});
}
}
class Searcher extends RelewiseClient {
constructor(datasetId, apiKey, options) {
super(datasetId, apiKey, options);
this.datasetId = datasetId;
this.apiKey = apiKey;
}
searchProducts(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('ProductSearchRequest', request);
});
}
searchContents(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('ContentSearchRequest', request);
});
}
searchTermPrediction(request) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('SearchTermPredictionRequest', request);
});
}
batch(requestCollections) {
return __awaiter(this, void 0, void 0, function* () {
return this.request('SearchRequestCollection', requestCollections);
});
}
}
class UserFactory {

@@ -191,3 +1399,3 @@ static anonymous() {

export { RelewiseClient, Tracker, UserFactory };
export { BooleanCollectionDataValue, BooleanDataValue, ConditionBuilder, ContentSearchBuilder, ContentSortingBuilder, DataValueBase, DoubleCollectionDataValue, FacetBuilder, FilterBuilder, MoneyDataValue, MultiCurrencyDataValue, MultilingualDataValue, NumberDataValue, PaginationBuilder, ProductSearchBuilder, ProductSortingBuilder, RelewiseClient, SearchCollectionBuilder, SearchRequestBuilder, SearchTermPredictionBuilder, Searcher, StringCollectionDataValue, StringDataValue, Tracker, UserFactory };
//# sourceMappingURL=relewise-client.js.map

2

dist/relewise.min.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Relewise={})}(this,(function(t){"use strict";function e(t,e,r,i){return new(r||(r=Promise))((function(n,a){function s(t){try{u(i.next(t))}catch(t){a(t)}}function o(t){try{u(i.throw(t))}catch(t){a(t)}}function u(t){var e;t.done?n(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,o)}u((i=i.apply(t,e||[])).next())}))}class r{constructor(t,e,r){if(this.datasetId=t,this.apiKey=e,this._serverUrl="https://api.relewise.com",this._urlPath="v1",!t)throw new Error("Dataset id cannot be null or empty. Please contact Relewise if you don't have an account already or would like a free demo license");if(!e)throw new Error("API Key secret cannot be null or empty. Please contact Relewise support if you don't know the apiKeySecret for your datasetId.");(null==r?void 0:r.serverUrl)&&(this._serverUrl=r.serverUrl)}get serverUrl(){return this._serverUrl}request(t,r){return e(this,void 0,void 0,(function*(){const e=`APIKey ${this.apiKey}`,i=this.createRequestUrl(this._serverUrl,this.datasetId,this._urlPath,t),n=yield fetch(i,{method:"POST",headers:{Authorization:e,"Content-Type":"application/json"},body:JSON.stringify(r)});try{return yield n.json()}catch(t){return}}))}createRequestUrl(t,...e){const r=e.join("/");return t.endsWith("/")?t.concat(r):t.concat("/",r)}}t.RelewiseClient=r,t.Tracker=class extends r{constructor(t,e,r){super(t,e,r),this.datasetId=t,this.apiKey=e}trackOrder({user:t,subtotal:r,trackingNumber:i,lineItems:n,cartName:a="default"}){return e(this,void 0,void 0,(function*(){return this.request("TrackOrderRequest",{order:{lineItems:n.map((t=>Object.assign(Object.assign({product:{id:t.productId}},t.variantId&&{variant:{id:t.variantId}}),{lineTotal:t.lineTotal,quantity:t.quantity}))),subtotal:{amount:r.amount,currency:{value:r.currency}},trackingNumber:i,cartName:a,user:t}})}))}trackCart({user:t,subtotal:r,lineItems:i,cartName:n="default"}){return e(this,void 0,void 0,(function*(){return this.request("TrackCartRequest",{cart:{lineItems:i.map((t=>Object.assign(Object.assign({product:{id:t.productId}},t.variantId&&{variant:{id:t.variantId}}),{lineTotal:t.lineTotal,quantity:t.quantity}))),subtotal:{amount:r.amount,currency:{value:r.currency}},name:n,user:t}})}))}trackProductView({productId:t,variantId:r,user:i}){return e(this,void 0,void 0,(function*(){return this.request("TrackProductViewRequest",{productView:Object.assign(Object.assign({product:{id:t}},r&&{variant:{id:r}}),{user:i})})}))}trackProductCategoryView({idPath:t,user:r}){return e(this,void 0,void 0,(function*(){return this.request("TrackProductCategoryViewRequest",{productCategoryView:{idPath:t,user:r}})}))}trackContentView({contentId:t,user:r}){return e(this,void 0,void 0,(function*(){return this.request("TrackContentViewRequest",{contentView:{content:{id:t},user:r}})}))}trackContentCategoryView({idPath:t,user:r}){return e(this,void 0,void 0,(function*(){return this.request("TrackContentCategoryViewRequest",{contentCategoryView:{idPath:t,user:r}})}))}trackBrandView({brandId:t,user:r}){return e(this,void 0,void 0,(function*(){return this.request("TrackBrandViewRequest",{brandView:{brand:{id:t},user:r}})}))}},t.UserFactory=class{static anonymous(){return{}}static byAuthenticatedId(t,e){return Object.assign({authenticatedId:t},e&&{temporaryId:e})}static byTemporaryId(t){return{temporaryId:t}}static byIdentifier(t,e){return{identifiers:{[t]:e}}}static byIdentifiers(t){return{identifiers:t}}static byEmail(t){return{email:t}}},Object.defineProperty(t,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Relewise={})}(this,(function(e){"use strict";class t{constructor(e,t){this.type=e,this.value=t}}class i{constructor(){this.conditions=[]}addContainsCondition(e,t="All",i=!1){const s={$type:"Relewise.Client.Requests.Conditions.ContainsCondition, Relewise.Client",value:e,valueCollectionEvaluationMode:t,negated:i};return this.conditions.push(s),this}addDistinctCondition(e,t=!1){const i={$type:"Relewise.Client.Requests.Conditions.DistinctCondition, Relewise.Client",numberOfOccurrencesAllowedWithTheSameValue:e,negated:t};return this.conditions.push(i),this}addEqualsCondition(e,t=!1){const i={$type:"Relewise.Client.Requests.Conditions.EqualsCondition, Relewise.Client",value:e,negated:t};return this.conditions.push(i),this}addGreaterThanCondition(e,t=!1){const i={$type:"Relewise.Client.Requests.Conditions.GreaterThanCondition, Relewise.Client",value:e,negated:t};return this.conditions.push(i),this}addLessThanCondition(e,t=!1){const i={$type:"Relewise.Client.Requests.Conditions.LessThanCondition, Relewise.Client",value:e,negated:t};return this.conditions.push(i),this}build(){return 0===this.conditions.length?null:{items:this.conditions}}}class s{constructor(){this.filters=[]}addProductAssortmentFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.ProductAssortmentFilter, Relewise.Client",assortments:Array.isArray(e)?e:[e],negated:t};return this.filters.push(i),this}addVariantAssortmentFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.VariantAssortmentFilter, Relewise.Client",assortments:Array.isArray(e)?e:[e],negated:t};return this.filters.push(i),this}addBrandAssortmentFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.BrandAssortmentFilter, Relewise.Client",assortments:Array.isArray(e)?e:[e],negated:t};return this.filters.push(i),this}addContentCategoryAssortmentFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.ContentCategoryAssortmentFilter, Relewise.Client",assortments:Array.isArray(e)?e:[e],negated:t};return this.filters.push(i),this}addProductCategoryAssortmentFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.ProductCategoryAssortmentFilter, Relewise.Client",assortments:Array.isArray(e)?e:[e],negated:t};return this.filters.push(i),this}addProductCategoryIdFilter(e,t,i=!1){const s={$type:"Relewise.Client.Requests.Filters.ProductCategoryIdFilter, Relewise.Client",evaluationScope:e,categoryIds:Array.isArray(t)?t:[t],negated:i};return this.filters.push(s),this}addContentCategoryIdFilter(e,t,i=!1){const s={$type:"Relewise.Client.Requests.Filters.ContentCategoryIdFilter, Relewise.Client",evaluationScope:e,categoryIds:Array.isArray(t)?t:[t],negated:i};return this.filters.push(s),this}addProductIdFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.ProductIdFilter, Relewise.Client",productIds:Array.isArray(e)?e:[e],negated:t};return this.filters.push(i),this}addVariantIdFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.VariantIdFilter, Relewise.Client",variantIds:Array.isArray(e)?e:[e],negated:t};return this.filters.push(i),this}addBrandIdFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.BrandIdFilter, Relewise.Client",brandIds:Array.isArray(e)?e:[e],negated:t};return this.filters.push(i),this}addContentIdFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.ContentIdFilter, Relewise.Client",contentIds:Array.isArray(e)?e:[e],negated:t};return this.filters.push(i),this}addProductHasVariantsFilter(e,t,i=!1){const s={$type:"Relewise.Client.Requests.Filters.ProductHasVariantsFilter, Relewise.Client",numberOfVariants:{lowerBoundInclusive:e,upperBoundInclusive:t},negated:i};return this.filters.push(s),this}addProductRecentlyPurchasedByUserFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.ProductRecentlyPurchasedByUserFilter, Relewise.Client",sinceUtc:e,negated:t};return this.filters.push(i),this}addProductRecentlyViewedByUserFilter(e,t=!1){const i={$type:"Relewise.Client.Requests.Filters.ProductRecentlyViewedByUserFilter, Relewise.Client",sinceUtc:e,negated:t};return this.filters.push(i),this}addProductSalesPriceFilter(e,t,i=!1){const s={$type:"Relewise.Client.Requests.Filters.ProductSalesPriceFilter, Relewise.Client",range:{lowerBoundInclusive:e,upperBoundInclusive:t},negated:i};return this.filters.push(s),this}addProductListPriceFilter(e,t,i=!1){const s={$type:"Relewise.Client.Requests.Filters.ProductListPriceFilter, Relewise.Client",range:{lowerBoundInclusive:e,upperBoundInclusive:t},negated:i};return this.filters.push(s),this}addVariantSalesPriceFilter(e,t,i=!1){const s={$type:"Relewise.Client.Requests.Filters.VariantSalesPriceFilter, Relewise.Client",range:{lowerBoundInclusive:e,upperBoundInclusive:t},negated:i};return this.filters.push(s),this}addVariantListPriceFilter(e,t,i=!1){const s={$type:"Relewise.Client.Requests.Filters.VariantListPriceFilter, Relewise.Client",range:{lowerBoundInclusive:e,upperBoundInclusive:t},negated:i};return this.filters.push(s),this}addVariantSpecificationFilter(e,t,i=!0,s=!1){const r={$type:"Relewise.Client.Requests.Filters.VariantSpecificationFilter, Relewise.Client",key:e,equalTo:t,filterOutIfKeyIsNotFound:i,negated:s};return this.filters.push(r),this}and(e,t=!1){const i=new s;e(i);const r=i.build();if(null===r||void 0===r.items||null===r.items||r.items.length<=0)throw new Error("And-filters must contain atleast 1 filter");const n={$type:"Relewise.Client.Requests.Filters.AndFilter, Relewise.Client",filters:r.items,negated:t};return this.filters.push(n),this}or(e,t=!1){const i=new s;e(i);const r=i.build();if(null===r||void 0===r.items||null===r.items||r.items.length<=0)throw new Error("Or-filters must contain atleast 1 filter");const n={$type:"Relewise.Client.Requests.Filters.OrFilter, Relewise.Client",filters:r.items,negated:t};return this.filters.push(n),this}addProductDataFilter(e,t,s=!0,r=!0,n=!1){const a=new i;t(a);const l={$type:"Relewise.Client.Requests.Filters.ProductDataFilter, Relewise.Client",key:e,filterOutIfKeyIsNotFound:r,mustMatchAllConditions:s,conditions:a.build(),negated:n};return this.filters.push(l),this}addVariantDataFilter(e,t,s=!0,r=!0,n=!1){const a=new i;t(a);const l={$type:"Relewise.Client.Requests.Filters.VariantDataFilter, Relewise.Client",key:e,filterOutIfKeyIsNotFound:r,mustMatchAllConditions:s,conditions:a.build(),negated:n};return this.filters.push(l),this}addBrandDataFilter(e,t,s=!0,r=!0,n=!1){const a=new i;t(a);const l={$type:"Relewise.Client.Requests.Filters.BrandDataFilter, Relewise.Client",key:e,filterOutIfKeyIsNotFound:r,mustMatchAllConditions:s,conditions:a.build(),negated:n};return this.filters.push(l),this}addCartDataFilter(e,t,s=!0,r=!0,n=!1){const a=new i;t(a);const l={$type:"Relewise.Client.Requests.Filters.CartDataFilter, Relewise.Client",key:e,filterOutIfKeyIsNotFound:r,mustMatchAllConditions:s,conditions:a.build(),negated:n};return this.filters.push(l),this}addContentCategoryDataFilter(e,t,s=!0,r=!0,n=!1){const a=new i;t(a);const l={$type:"Relewise.Client.Requests.Filters.ContentCategoryDataFilter, Relewise.Client",key:e,filterOutIfKeyIsNotFound:r,mustMatchAllConditions:s,conditions:a.build(),negated:n};return this.filters.push(l),this}addContentDataFilter(e,t,s=!0,r=!0,n=!1){const a=new i;t(a);const l={$type:"Relewise.Client.Requests.Filters.ContentDataFilter, Relewise.Client",key:e,filterOutIfKeyIsNotFound:r,mustMatchAllConditions:s,conditions:a.build(),negated:n};return this.filters.push(l),this}addProductCategoryDataFilter(e,t,s=!0,r=!0,n=!1){const a=new i;t(a);const l={$type:"Relewise.Client.Requests.Filters.ProductCategoryDataFilter, Relewise.Client",key:e,filterOutIfKeyIsNotFound:r,mustMatchAllConditions:s,conditions:a.build(),negated:n};return this.filters.push(l),this}addProductDisplayNameFilter(e,t=!0,s=!1){const r=new i;e(r);const n={$type:"Relewise.Client.Requests.Filters.ProductDisplayNameFilter, Relewise.Client",mustMatchAllConditions:t,conditions:r.build(),negated:s};return this.filters.push(n),this}reset(){return this.filters=[],this}build(){return 0===this.filters.length?null:{items:this.filters}}}class r{constructor(){this.pageNumber=1,this.pageSize=10}setPageSize(e){if(e<0)throw new Error("pageSize can not be below 0");return this.pageSize=e,this}setPage(e){if(e<1)throw new Error("pageNumber can not be below 1");return this.pageNumber=e,this}build(){return{take:this.pageSize,skip:(this.pageNumber-1)*this.pageSize}}}class n{constructor(){this.facets=[]}addCategoryFacet(e,t=null){const i={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.CategoryFacet, Relewise.Client",categorySelectionStrategy:e,field:"Category",selected:t};return this.facets.push(i),this}addBrandFacet(e=null){const t={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.BrandFacet, Relewise.Client",field:"Brand",selected:e};return this.facets.push(t),this}addProductAssortmentFacet(e,t=null){const i={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.ProductAssortmentFacet, Relewise.Client",field:"Assortment",assortmentFilterType:"Or",assortmentSelectionStrategy:e,selected:t};return this.facets.push(i),this}addContentAssortmentFacet(e=null){const t={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.ContentAssortmentFacet, Relewise.Client",field:"Assortment",assortmentFilterType:"Or",selected:e};return this.facets.push(t),this}addVariantSpecificationFacet(e,t=null){const i={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.VariantSpecificationFacet, Relewise.Client",field:"VariantSpecification",key:e,selected:t};return this.facets.push(i),this}addProductDataDoubleRangeFacet(e,t,i,s){const r={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataDoubleRangeFacet, Relewise.Client",field:"Data",key:e,dataSelectionStrategy:t,selected:{lowerBoundInclusive:i,upperBoundInclusive:s}};return this.facets.push(r),this}addProductDataStringValueFacet(e,t,i=null,s){const r={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataStringValueFacet, Relewise.Client",field:"Data",key:e,dataSelectionStrategy:t,selected:i,collectionFilterType:s};return this.facets.push(r),this}addProductDataBooleanValueFacet(e,t,i=null,s){const r={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataBooleanValueFacet, Relewise.Client",field:"Data",key:e,dataSelectionStrategy:t,selected:i,collectionFilterType:s};return this.facets.push(r),this}addProductDataDoubleValueFacet(e,t,i=null,s){const r={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.ProductDataDoubleValueFacet, Relewise.Client",field:"Data",key:e,dataSelectionStrategy:t,selected:i,collectionFilterType:s};return this.facets.push(r),this}addSalesPriceRangeFacet(e,t,i){const s={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangeFacet, Relewise.Client",field:"SalesPrice",selected:{lowerBoundInclusive:t,upperBoundInclusive:i},priceSelectionStrategy:e};return this.facets.push(s),this}addListPriceRangeFacet(e,t,i){const s={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangeFacet, Relewise.Client",field:"ListPrice",selected:{lowerBoundInclusive:t,upperBoundInclusive:i},priceSelectionStrategy:e};return this.facets.push(s),this}addListPriceRangesFacet(e,t,i,s=null){const r={$type:"Relewise.Client.DataTypes.Search.Facets.Queries.PriceRangesFacet, Relewise.Client",field:"ListPrice",predefinedRanges:null==t?void 0:t.map((e=>({lowerBoundInclusive:e.lowerBound,upperBoundExclusive:e.upperBound}))),expandedRangeSize:i,selected:null==s?void 0:s.map((e=>({lowerBoundInclusive:e.lowerBound,upperBoundExclusive:e.upperBound}))),priceSelectionStrategy:e};return this.facets.push(r),this}build(){return 0===this.facets.length?null:{items:this.facets}}}class a{constructor(){this.value=null}sortByProductData(e,t,i,s="Auto"){var r;const n={$type:"Relewise.Client.DataTypes.Search.Sorting.Product.ProductDataSorting, Relewise.Client",dataSelectionStrategy:"Product",mode:s,order:t,key:e,thenBy:null===(r=this.thenBy(i))||void 0===r?void 0:r.value};this.value=n}sortByProductRelevance(e="Descending",t){var i;const s={$type:"Relewise.Client.DataTypes.Search.Sorting.Product.ProductRelevanceSorting, Relewise.Client",order:e,thenBy:null===(i=this.thenBy(t))||void 0===i?void 0:i.value};this.value=s}sortByProductPopularity(e="Descending",t){var i;const s={$type:"Relewise.Client.DataTypes.Search.Sorting.Product.ProductPopularitySorting, Relewise.Client",order:e,thenBy:null===(i=this.thenBy(t))||void 0===i?void 0:i.value};this.value=s}sortByProductAttribute(e,t,i,s="Auto"){var r;const n={$type:"Relewise.Client.DataTypes.Search.Sorting.Product.ProductAttributeSorting, Relewise.Client",attribute:e,mode:s,order:t,thenBy:null===(r=this.thenBy(i))||void 0===r?void 0:r.value};this.value=n}sortByProductVariantAttribute(e,t,i,s="Auto"){var r;const n={$type:"Relewise.Client.DataTypes.Search.Sorting.Product.ProductVariantAttributeSorting, Relewise.Client",attribute:e,mode:s,order:t,thenBy:null===(r=this.thenBy(i))||void 0===r?void 0:r.value};this.value=n}sortByProductVariantSpecification(e,t,i,s="Auto"){var r;const n={$type:"Relewise.Client.DataTypes.Search.Sorting.Product.ProductVariantSpecificationSorting, Relewise.Client",key:e,mode:s,order:t,thenBy:null===(r=this.thenBy(i))||void 0===r?void 0:r.value};this.value=n}thenBy(e){const t=new a;return e&&(e(t),t.build()),t}build(){return null==this.value?null:{value:this.value}}}class l{constructor(){this.value=null}sortByContentData(e,t="Descending",i="Auto",s){var r;const n={$type:"Relewise.Client.DataTypes.Search.Sorting.Content.ContentDataSorting, Relewise.Client",mode:i,order:t,key:e,thenBy:null===(r=this.thenBy(s))||void 0===r?void 0:r.value};this.value=n}sortByContentRelevance(e="Descending",t){var i;const s={$type:"Relewise.Client.DataTypes.Search.Sorting.Content.ContentRelevanceSorting, Relewise.Client",order:e,thenBy:null===(i=this.thenBy(t))||void 0===i?void 0:i.value};this.value=s}sortByContentPopularity(e="Descending",t){var i;const s={$type:"Relewise.Client.DataTypes.Search.Sorting.Content.ContentPopularitySorting, Relewise.Client",order:e,thenBy:null===(i=this.thenBy(t))||void 0===i?void 0:i.value};this.value=s}sortByContentAttribute(e,t,i="Auto",s){var r;const n={$type:"Relewise.Client.DataTypes.Search.Sorting.Content.ContentAttributeSorting, Relewise.Client",attribute:e,mode:i,order:t,thenBy:null===(r=this.thenBy(s))||void 0===r?void 0:r.value};this.value=n}thenBy(e){const t=new l;return e&&(e(t),t.build()),t}build(){return null==this.value?null:{value:this.value}}}class u{constructor(e){this.settings=e,this.filterBuilder=new s,this.postFilterBuilder=new s}filters(e){return e(this.filterBuilder),this}postFilters(e){return e(this.postFilterBuilder),this}setIndex(e){return this.indexId=e,this}baseBuild(){return Object.assign({currency:{value:this.settings.currency},user:this.settings.user,language:{value:this.settings.language},displayedAtLocation:this.settings.displayedAtLocation,filters:this.filterBuilder.build(),postFilters:this.postFilterBuilder.build(),relevanceModifiers:null},this.indexId&&{indexSelector:{id:this.indexId}})}}function o(e,t,i,s){return new(i||(i=Promise))((function(r,n){function a(e){try{u(s.next(e))}catch(e){n(e)}}function l(e){try{u(s.throw(e))}catch(e){n(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,l)}u((s=s.apply(e,t||[])).next())}))}class c{constructor(e,t,i){if(this.datasetId=e,this.apiKey=t,this._serverUrl="https://api.relewise.com",this._urlPath="v1",!e)throw new Error("Dataset id cannot be null or empty. Please contact Relewise if you don't have an account already or would like a free demo license");if(!t)throw new Error("API Key secret cannot be null or empty. Please contact Relewise support if you don't know the apiKeySecret for your datasetId.");(null==i?void 0:i.serverUrl)&&(this._serverUrl=i.serverUrl)}get serverUrl(){return this._serverUrl}request(e,t){return o(this,void 0,void 0,(function*(){const i=`APIKey ${this.apiKey}`,s=this.createRequestUrl(this._serverUrl,this.datasetId,this._urlPath,e),r=yield fetch(s,{method:"POST",headers:{Authorization:i,"Content-Type":"application/json"},body:JSON.stringify(t)});try{return yield r.json()}catch(e){return}}))}createRequestUrl(e,...t){const i=t.join("/");return e.endsWith("/")?e.concat(i):e.concat("/",i)}}e.BooleanCollectionDataValue=class extends t{constructor(e){super("BooleanList",e)}},e.BooleanDataValue=class extends t{constructor(e){super("Boolean",e)}},e.ConditionBuilder=i,e.ContentSearchBuilder=class extends u{constructor(e){super(e),this.facetBuilder=new n,this.paginationBuilder=new r,this.sortingBuilder=new l,this.searchSettings={$type:"Relewise.Client.Requests.Search.Settings.ContentSearchSettings, Relewise.Client",recommendations:{}}}setContentProperties(e){return this.searchSettings.selectedContentProperties=e,this}setRecommendationSettings(e){return this.searchSettings.recommendations=e,this}setTerm(e){return this.term=e,this}pagination(e){return e(this.paginationBuilder),this}facets(e){return e(this.facetBuilder),this}sorting(e){return e(this.sortingBuilder),this}build(){const{take:e,skip:t}=this.paginationBuilder.build();return Object.assign(Object.assign({},this.baseBuild()),{settings:this.searchSettings,take:e,skip:t,term:this.term,facets:this.facetBuilder.build(),sorting:this.sortingBuilder.build()})}},e.ContentSortingBuilder=l,e.DataValueBase=t,e.DoubleCollectionDataValue=class extends t{constructor(e){super("DoubleList",e)}},e.FacetBuilder=n,e.FilterBuilder=s,e.MoneyDataValue=class extends t{constructor(e,t){super("Money",{amount:e,currency:{value:t}})}},e.MultiCurrencyDataValue=class extends t{constructor(e){super("MultiCurrency",{values:e.map((e=>({amount:e.amount,currency:{value:e.currency}})))})}},e.MultilingualDataValue=class extends t{constructor(e){super("Multilingual",{values:e.map((e=>({text:e.value,language:{value:e.language}})))})}},e.NumberDataValue=class extends t{constructor(e){super("Double",e)}},e.PaginationBuilder=r,e.ProductSearchBuilder=class extends u{constructor(e){super(e),this.facetBuilder=new n,this.paginationBuilder=new r,this.sortingBuilder=new a,this.searchSettings={$type:"Relewise.Client.Requests.Search.Settings.ProductSearchSettings, Relewise.Client",recommendations:{}}}setSelectedProductProperties(e){return this.searchSettings.selectedProductProperties=e,this}setSelectedVariantProperties(e){return this.searchSettings.selectedVariantProperties=e,this}setSelectedBrandProperties(e){return this.searchSettings.selectedBrandProperties=e,this}setExplodedVariants(e){return this.searchSettings.explodedVariants=e,this}setRecommendationSettings(e){return this.searchSettings.recommendations=e,this}setTerm(e){return this.term=e,this}pagination(e){return e(this.paginationBuilder),this}facets(e){return e(this.facetBuilder),this}sorting(e){return e(this.sortingBuilder),this}build(){const{take:e,skip:t}=this.paginationBuilder.build();return Object.assign(Object.assign({},this.baseBuild()),{take:e,skip:t,term:this.term,facets:this.facetBuilder.build(),settings:this.searchSettings,sorting:this.sortingBuilder.build()})}},e.ProductSortingBuilder=a,e.RelewiseClient=c,e.SearchCollectionBuilder=class extends u{constructor(e){super(e),this.requests=[]}addRequest(e){return this.requests.push(e),this}build(){return Object.assign(Object.assign({},this.baseBuild()),{requests:this.requests})}},e.SearchRequestBuilder=u,e.SearchTermPredictionBuilder=class extends u{constructor(e){super(e),this.count=0,this.term="",this.targetEntityTypes=null}take(e){return this.count=e,this}setTerm(e){return this.term=e,this}addEntityType(...e){return this.targetEntityTypes=e,this}build(){return Object.assign(Object.assign({},this.baseBuild()),{term:this.term,take:this.count,settings:{$type:"Relewise.Client.Requests.Search.Settings.SearchTermPredictionSettings, Relewise.Client",targetEntityTypes:this.targetEntityTypes}})}},e.Searcher=class extends c{constructor(e,t,i){super(e,t,i),this.datasetId=e,this.apiKey=t}searchProducts(e){return o(this,void 0,void 0,(function*(){return this.request("ProductSearchRequest",e)}))}searchContents(e){return o(this,void 0,void 0,(function*(){return this.request("ContentSearchRequest",e)}))}searchTermPrediction(e){return o(this,void 0,void 0,(function*(){return this.request("SearchTermPredictionRequest",e)}))}batch(e){return o(this,void 0,void 0,(function*(){return this.request("SearchRequestCollection",e)}))}},e.StringCollectionDataValue=class extends t{constructor(e){super("StringList",e)}},e.StringDataValue=class extends t{constructor(e){super("String",e)}},e.Tracker=class extends c{constructor(e,t,i){super(e,t,i),this.datasetId=e,this.apiKey=t}trackOrder({user:e,subtotal:t,trackingNumber:i,lineItems:s,cartName:r="default"}){return o(this,void 0,void 0,(function*(){return this.request("TrackOrderRequest",{order:{lineItems:s.map((e=>Object.assign(Object.assign({product:{id:e.productId}},e.variantId&&{variant:{id:e.variantId}}),{lineTotal:e.lineTotal,quantity:e.quantity}))),subtotal:{amount:t.amount,currency:{value:t.currency}},trackingNumber:i,cartName:r,user:e}})}))}trackCart({user:e,subtotal:t,lineItems:i,cartName:s="default"}){return o(this,void 0,void 0,(function*(){return this.request("TrackCartRequest",{cart:{lineItems:i.map((e=>Object.assign(Object.assign({product:{id:e.productId}},e.variantId&&{variant:{id:e.variantId}}),{lineTotal:e.lineTotal,quantity:e.quantity}))),subtotal:{amount:t.amount,currency:{value:t.currency}},name:s,user:e}})}))}trackProductView({productId:e,variantId:t,user:i}){return o(this,void 0,void 0,(function*(){return this.request("TrackProductViewRequest",{productView:Object.assign(Object.assign({product:{id:e}},t&&{variant:{id:t}}),{user:i})})}))}trackProductCategoryView({idPath:e,user:t}){return o(this,void 0,void 0,(function*(){return this.request("TrackProductCategoryViewRequest",{productCategoryView:{idPath:e,user:t}})}))}trackContentView({contentId:e,user:t}){return o(this,void 0,void 0,(function*(){return this.request("TrackContentViewRequest",{contentView:{content:{id:e},user:t}})}))}trackContentCategoryView({idPath:e,user:t}){return o(this,void 0,void 0,(function*(){return this.request("TrackContentCategoryViewRequest",{contentCategoryView:{idPath:e,user:t}})}))}trackBrandView({brandId:e,user:t}){return o(this,void 0,void 0,(function*(){return this.request("TrackBrandViewRequest",{brandView:{brand:{id:e},user:t}})}))}trackSearchTerm({term:e,language:t,user:i}){return o(this,void 0,void 0,(function*(){return this.request("TrackSearchTermRequest",{searchTerm:{language:{value:t},term:e,user:i}})}))}},e.UserFactory=class{static anonymous(){return{}}static byAuthenticatedId(e,t){return Object.assign({authenticatedId:e},t&&{temporaryId:t})}static byTemporaryId(e){return{temporaryId:e}}static byIdentifier(e,t){return{identifiers:{[e]:t}}}static byIdentifiers(e){return{identifiers:e}}static byEmail(e){return{email:e}}},Object.defineProperty(e,"__esModule",{value:!0})}));
{
"name": "@relewise/client",
"version": "1.0.2",
"version": "1.1.0",
"description": "Relewise is a next generation personalization SaaS-platform, which offers functionality within product- and content recommendations and personalized search. This official SDK helps you interact with our API.",

@@ -28,2 +28,4 @@ "repository": {

"integration-test": "jest ./tests/integration-tests",
"lint": "eslint --ext .ts,.js ./src",
"lint-fix": "eslint --fix --ext .ts,.js ./src",
"dev": "rollup -c -w",

@@ -34,3 +36,3 @@ "build": "rollup -c",

"clean": "rimraf ./build ./dist ./docs",
"gen-api": "swagger-typescript-api -p https://api.relewise.com/public/swagger.json -o src/models --modular --clean-output --no-client --enum-names-as-values",
"gen-api": "swagger-typescript-api -p https://api.relewise.com/public/swagger.json -o src/models --modular --no-client --enum-names-as-values",
"publish": "npm run gen-api && npm run build && npm run build:types"

@@ -46,3 +48,3 @@ },

"@types/node": "^18.6.3",
"eslint": "^8.20.0",
"eslint": "^8.22.0",
"jest": "^28.1.3",

@@ -52,2 +54,3 @@ "prettier": "^2.7.1",

"rollup": "^2.77.1",
"rollup-plugin-external-globals": "^0.6.1",
"rollup-plugin-terser": "^7.0.2",

@@ -58,4 +61,8 @@ "swagger-typescript-api": "^9.3.1",

"tslib": "^2.4.0",
"typescript": "^4.6.4"
"typescript": "^4.6.4",
"@typescript-eslint/parser": "^5.34.0"
},
"dependencies": {
"cross-fetch": "^3.1.5"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc