UNPKG

@relewise/integrations

Version:

Helper for updating entities in Relewise

1,089 lines (1,073 loc) 158 kB
'use strict'; /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function __awaiter$1(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; class FilterScopesBuilder { constructor() { this.fillScope = undefined; this.defaultScope = undefined; } fill({ apply }) { this.fillScope = { $type: 'Relewise.Client.Requests.Filters.Settings.ApplyFilterSettings, Relewise.Client', apply, }; return this; } default({ apply }) { this.defaultScope = { $type: 'Relewise.Client.Requests.Filters.Settings.ApplyFilterSettings, Relewise.Client', apply, }; return this; } build() { return this.fillScope || this.defaultScope ? { fill: this.fillScope, default: this.defaultScope, } : null; } } class FilterSettingsBuilder { constructor() { this.scopesBuilder = new FilterScopesBuilder(); } scopes(builder) { builder(this.scopesBuilder); return this; } build() { const scopes = this.scopesBuilder.build(); return scopes ? { scopes: scopes } : null; } } class DataObjectFilterConditionBuilder { constructor() { this.conditions = []; } addContainsCondition(key, value, mode = 'All', objectPath, negated = false) { const condition = { $type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueContainsCondition, Relewise.Client', key: key, value: value, objectPath: objectPath, mode: mode, negated: negated, }; this.conditions.push(condition); return this; } addEqualsCondition(key, value, objectPath, negated = false) { const condition = { $type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueEqualsCondition, Relewise.Client', value: value, objectPath: objectPath, negated: negated, key: key, }; this.conditions.push(condition); return this; } addInRangeCondition(key, range, objectPath, negated = false) { const condition = { $type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueInRangeCondition, Relewise.Client', range: range, key: key, objectPath: objectPath, negated: negated, }; this.conditions.push(condition); return this; } addGreaterThanCondition(key, value, objectPath, negated = false) { const condition = { $type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueGreaterThanCondition, Relewise.Client', value: value, negated: negated, key: key, objectPath: objectPath, }; this.conditions.push(condition); return this; } addLessThanCondition(key, value, objectPath, negated = false) { const condition = { $type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueLessThanCondition, Relewise.Client', value: value, negated: negated, key: key, objectPath: objectPath, }; this.conditions.push(condition); return this; } addMinByCondition(key, objectPath, negated = false) { const condition = { $type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueMinByCondition, Relewise.Client', negated: negated, key: key, objectPath: objectPath, }; this.conditions.push(condition); return this; } addMaxByCondition(key, objectPath, negated = false) { const condition = { $type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueMaxByCondition, Relewise.Client', negated: negated, key: key, objectPath: objectPath, }; this.conditions.push(condition); return this; } addObjectValueIsSubsetOfCondition(key, value, objectPath, negated = false) { const condition = { $type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueIsSubsetOfCondition, Relewise.Client', value: value, key: key, objectPath: objectPath, negated: negated, }; this.conditions.push(condition); return this; } build() { return this.conditions.length === 0 ? null : this.conditions; } } class FilterBuilderBase { constructor(TFilterBuilderCtor) { this.TFilterBuilderCtor = TFilterBuilderCtor; this.filters = []; } /** * Adds an AND filter to the request. * @param filterBuilder - Function to build the AND filter. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The FilterBuilderBase instance for chaining. */ and(filterBuilder, negated = false, options) { var _a; const builder = new this.TFilterBuilderCtor(); filterBuilder(builder); const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filters = builder.build(); if (filters === null || !filters.items || filters.items.length <= 0) { throw new Error('And-filters must contain at least 1 filter'); } const filter = { $type: 'Relewise.Client.Requests.Filters.AndFilter, Relewise.Client', filters: filters.items, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds an OR filter to the request. * @param filterBuilder - Function to build the OR filter. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The FilterBuilderBase instance for chaining. */ or(filterBuilder, negated = false, options) { var _a; const builder = new this.TFilterBuilderCtor(); filterBuilder(builder); const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filters = builder.build(); if (filters === null || !filters.items || filters.items.length <= 0) { throw new Error('Or-filters must contain at least 1 filter'); } const filter = { $type: 'Relewise.Client.Requests.Filters.OrFilter, Relewise.Client', filters: filters.items, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Resets the filters. * @returns The FilterBuilderBase instance for chaining. */ reset() { this.filters = []; return this; } /** * Builds the filter collection. * @returns The FilterCollection or null if no filters are added. */ build() { return this.filters.length === 0 ? null : { items: this.filters }; } } 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; } addDataObjectCondition(conditions, skip, take, negated = false) { const conditionsBuilder = new DataObjectFilterConditionBuilder(); conditions(conditionsBuilder); const condition = { $type: 'Relewise.Client.Requests.Conditions.ContainsCondition, Relewise.Client', objectFilter: { conditions: conditionsBuilder.build(), skip: skip, take: take, }, valueCollectionEvaluationMode: 'All', negated: negated, }; this.conditions.push(condition); return this; } addHasValueCondition(negated = false) { const condition = { $type: 'Relewise.Client.Requests.Conditions.HasValueCondition, Relewise.Client', negated: negated, }; this.conditions.push(condition); return this; } addRelativeDateTimeCondition(comparison, unit, currentTimeOffset = 0, negated = false) { const condition = { $type: 'Relewise.Client.Requests.Conditions.RelativeDateTimeCondition, Relewise.Client', comparison: comparison, currentTimeOffset: currentTimeOffset, unit: unit, negated: negated, }; this.conditions.push(condition); return this; } build() { return this.conditions.length === 0 ? null : { items: this.conditions }; } } class BrandFilterBuilder extends FilterBuilderBase { constructor() { super(BrandFilterBuilder); } /** * Adds a brand assortment filter to the request. * @param assortmentIds - Array of assortment IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The BrandFilterBuilder instance for chaining. */ addBrandAssortmentFilter(assortmentIds, negated = false, options) { var _a; const assortments = Array.isArray(assortmentIds) ? assortmentIds : [assortmentIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.BrandAssortmentFilter, Relewise.Client', assortments: assortments, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Filters the request to only return the specified brands. * @param brandIds - Array of brand IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The BrandFilterBuilder instance for chaining. */ addBrandIdFilter(brandIds, negated = false, options) { var _a; const ids = Array.isArray(brandIds) ? brandIds : [brandIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.BrandIdFilter, Relewise.Client', brandIds: ids, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a brand data filter to the request. * @param key - Data key. * @param conditionBuilder - Function to build the condition. * @param mustMatchAllConditions - If true, all conditions must be met (default is true). * @param filterOutIfKeyIsNotFound - If true, filters out brands without the key (default is true). * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The BrandFilterBuilder instance for chaining. */ addBrandDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false, options) { var _a; const builder = new ConditionBuilder(); conditionBuilder(builder); const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.BrandDataFilter, Relewise.Client', key: key, filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound, mustMatchAllConditions: mustMatchAllConditions, conditions: builder.build(), negated: negated, objectPath: options === null || options === void 0 ? void 0 : options.objectPath, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a brand has key filter to the request. * @param key - Data key. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The BrandFilterBuilder instance for chaining. */ addBrandDataHasKeyFilter(key, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.BrandDataHasKeyFilter, Relewise.Client', key: key, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a brand is disabled filter to the request. Only works for brand queries, not in searches or recommendations. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The BrandFilterBuilder instance for chaining. */ addBrandDisabledFilter(negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.BrandDisabledFilter, Relewise.Client', negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } } class CompanyFilterBuilder extends FilterBuilderBase { constructor() { super(CompanyFilterBuilder); } /** * Filters the request to only return the specified companies. * @param companyIds - Array of company IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The CompanyFilterBuilder instance for chaining. */ addCompanyIdFilter(companyIds, negated = false, options) { var _a; const ids = Array.isArray(companyIds) ? companyIds : [companyIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.CompanyIdFilter, Relewise.Client', companyIds: ids, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a company data filter to the request. * @param key - Data key. * @param conditionBuilder - Function to build the condition. * @param mustMatchAllConditions - If true, all conditions must be met (default is true). * @param filterOutIfKeyIsNotFound - If true, filters out companies without the key (default is true). * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The CompanyFilterBuilder instance for chaining. */ addCompanyDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false, options) { var _a; const builder = new ConditionBuilder(); conditionBuilder(builder); const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.CompanyDataFilter, Relewise.Client', key: key, filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound, mustMatchAllConditions: mustMatchAllConditions, conditions: builder.build(), negated: negated, objectPath: options === null || options === void 0 ? void 0 : options.objectPath, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a company has key filter to the request. * @param key - Data key. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The CompanyFilterBuilder instance for chaining. */ addCompanyDataHasKeyFilter(key, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.CompanyDataHasKeyFilter, Relewise.Client', key: key, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a company is disabled filter to the request. Only works for company queries, not in searches or recommendations. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The CompanyFilterBuilder instance for chaining. */ addCompanyDisabledFilter(negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.CompanyDisabledFilter, Relewise.Client', negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } } class ContentFilterBuilder extends FilterBuilderBase { constructor() { super(ContentFilterBuilder); } /** * Adds a content assortment filter to the request. * @param assortmentIds - Array of assortment IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentAssortmentFilter(assortmentIds, negated = false, options) { var _a; const assortments = Array.isArray(assortmentIds) ? assortmentIds : [assortmentIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentAssortmentFilter, Relewise.Client', assortments: assortments, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content category assortment filter to the request. * @param assortmentIds - Array of assortment IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryAssortmentFilter(assortmentIds, negated = false, options) { var _a; const assortments = Array.isArray(assortmentIds) ? assortmentIds : [assortmentIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryAssortmentFilter, Relewise.Client', assortments: assortments, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Filters the request to only return contents within the specified categories. * @param evaluationScope - Scope of the category evaluation (ImmediateParent, ImmediateParentOrItsParent, Ancestor). * @param categoryIds - Array of category IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryIdFilter(evaluationScope, categoryIds, negated = false, options) { var _a; const ids = Array.isArray(categoryIds) ? categoryIds : [categoryIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryIdFilter, Relewise.Client', evaluationScope: evaluationScope, categoryIds: ids, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Filters the request to only return the specified contents. * @param contentIds - Array of content IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentIdFilter(contentIds, negated = false, options) { var _a; const ids = Array.isArray(contentIds) ? contentIds : [contentIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentIdFilter, Relewise.Client', contentIds: ids, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content category level filter to the request. * @param levels - Array of category levels or a single level. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryLevelFilter(levels, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryLevelFilter, Relewise.Client', levels: Array.isArray(levels) ? levels : [levels], negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content category has parent filter to the request. * @param categoryIds - Array of category IDs or a single ID (optional). * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryHasParentFilter(categoryIds, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryHasParentFilter, Relewise.Client', categoryIds: categoryIds ? (Array.isArray(categoryIds) ? categoryIds : [categoryIds]) : undefined, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content category has child filter to the request. * @param categoryIds - Array of category IDs or a single ID (optional). * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryHasChildFilter(categoryIds, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryHasChildFilter, Relewise.Client', categoryIds: categoryIds ? (Array.isArray(categoryIds) ? categoryIds : [categoryIds]) : undefined, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content category has ancestor filter to the request. * @param categoryIds - Array of category IDs or a single ID (optional). * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryHasAncestorFilter(categoryIds, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryHasAncestorFilter, Relewise.Client', categoryIds: categoryIds ? (Array.isArray(categoryIds) ? categoryIds : [categoryIds]) : undefined, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content category has contents filter to the request ensuring that only categories with content in them are returned. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryHasContentsFilter(negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryHasContentsFilter, Relewise.Client', negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content category data filter to the request. * @param key - Data key. * @param conditionBuilder - Function to build the condition. * @param mustMatchAllConditions - If true, all conditions must be met (default is true). * @param filterOutIfKeyIsNotFound - If true, filters out categories without the key (default is true). * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false, options) { var _a; const builder = new ConditionBuilder(); conditionBuilder(builder); const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryDataFilter, Relewise.Client', key: key, filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound, mustMatchAllConditions: mustMatchAllConditions, conditions: builder.build(), negated: negated, objectPath: options === null || options === void 0 ? void 0 : options.objectPath, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content data filter to the request. * @param key - Data key. * @param conditionBuilder - Function to build the condition. * @param mustMatchAllConditions - If true, all conditions must be met (default is true). * @param filterOutIfKeyIsNotFound - If true, filters out contents without the key (default is true). * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false, options) { var _a; const builder = new ConditionBuilder(); conditionBuilder(builder); const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentDataFilter, Relewise.Client', key: key, filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound, mustMatchAllConditions: mustMatchAllConditions, conditions: builder.build(), negated: negated, objectPath: options === null || options === void 0 ? void 0 : options.objectPath, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content category has key filter to the request. * @param key - Data key. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryDataHasKeyFilter(key, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryDataHasKeyFilter, Relewise.Client', key: key, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content category is disabled filter to the request. Only works for content queries, not in searches or recommendations. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryDisabledFilter(negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryDisabledFilter, Relewise.Client', negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a filter to only return content categories recently viewed by the user. * @param sinceMinutesAgo - Time in minutes since the category was viewed. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentCategoryRecentlyViewedByUserFilter(sinceMinutesAgo, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentCategoryRecentlyViewedByUserFilter, Relewise.Client', sinceMinutesAgo: sinceMinutesAgo, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content has key filter to the request. * @param key - Data key. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentDataHasKeyFilter(key, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentDataHasKeyFilter, Relewise.Client', key: key, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content is disabled filter to the request. Only works for content queries, not in searches or recommendations. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentDisabledFilter(negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentDisabledFilter, Relewise.Client', negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a filter to only return content recently viewed by the user. * @param sinceMinutesAgo - Time in minutes since the content was viewed. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentRecentlyViewedByUserFilter(sinceMinutesAgo, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentRecentlyViewedByUserFilter, Relewise.Client', sinceMinutesAgo: sinceMinutesAgo, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a content has categories filter to the request. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ContentFilterBuilder instance for chaining. */ addContentHasCategoriesFilter(negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ContentHasCategoriesFilter, Relewise.Client', negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } } class ProductFilterBuilder extends FilterBuilderBase { constructor() { super(ProductFilterBuilder); } /** * Adds a product assortment filter to the request. * @param assortmentIds - Array of assortment IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ProductFilterBuilder instance for chaining. */ addProductAssortmentFilter(assortmentIds, negated = false, options) { var _a; const assortments = Array.isArray(assortmentIds) ? assortmentIds : [assortmentIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ProductAssortmentFilter, Relewise.Client', assortments: assortments, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a product category assortment filter to the request. * @param assortmentIds - Array of assortment IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ProductFilterBuilder instance for chaining. */ addProductCategoryAssortmentFilter(assortmentIds, negated = false, options) { var _a; const assortments = Array.isArray(assortmentIds) ? assortmentIds : [assortmentIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ProductCategoryAssortmentFilter, Relewise.Client', assortments: assortments, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Filters the request to only return products within the specified categories. * @param evaluationScope - Scope of the category evaluation (ImmediateParent, ImmediateParentOrItsParent, Ancestor). * @param categoryIds - Array of category IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ProductFilterBuilder instance for chaining. */ addProductCategoryIdFilter(evaluationScope, categoryIds, negated = false, options) { var _a; const ids = Array.isArray(categoryIds) ? categoryIds : [categoryIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ProductCategoryIdFilter, Relewise.Client', evaluationScope: evaluationScope, categoryIds: ids, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a product category data filter to the request. * @param key - Data key. * @param conditionBuilder - Function to build the condition. * @param mustMatchAllConditions - If true, all conditions must be met (default is true). * @param filterOutIfKeyIsNotFound - If true, filters out categories without the key (default is true). * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ProductFilterBuilder instance for chaining. */ addProductCategoryDataFilter(key, conditionBuilder, mustMatchAllConditions = true, filterOutIfKeyIsNotFound = true, negated = false, options) { var _a; const builder = new ConditionBuilder(); conditionBuilder(builder); const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ProductCategoryDataFilter, Relewise.Client', key: key, filterOutIfKeyIsNotFound: filterOutIfKeyIsNotFound, mustMatchAllConditions: mustMatchAllConditions, conditions: builder.build(), negated: negated, objectPath: options === null || options === void 0 ? void 0 : options.objectPath, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Filters the request to only return the specified products. * @param productIds - Array of product IDs or a single ID. * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ProductFilterBuilder instance for chaining. */ addProductIdFilter(productIds, negated = false, options) { var _a; const ids = Array.isArray(productIds) ? productIds : [productIds]; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ProductIdFilter, Relewise.Client', productIds: ids, negated: negated, settings: internalSettingsBuilder.build(), }; this.filters.push(filter); return this; } /** * Adds a range filter to the request ensuring the product has a certain range of variants. * @param lowerBound - Lower bound of the range (inclusive). * @param upperBound - Upper bound of the range (inclusive). * @param negated - If true, negates the filter (default is false). * @param options - Optional settings for the filter. * @returns The ProductFilterBuilder instance for chaining. */ addProductHasVariantsFilter(lowerBound, upperBound, negated = false, options) { var _a; const internalSettingsBuilder = new FilterSettingsBuilder(); (_a = options === null || options === void 0 ? void 0 : options.filterSettings) === null || _a === void 0 ? void 0 : _a.call(options, internalSettingsBuilder); const filter = { $type: 'Relewise.Client.Requests.Filters.ProductHasVariantsFilter, Relewise.Client', numberOfVariants: { lowerBoundInclusive: lowerBound, upperBoundInclusive: upperBound, }, negated: negated, settings: internalSettingsBuilder.build(), };