@labdigital/commercetools-mock 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +51 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +51 -30
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers.ts +19 -6
- package/src/product-projection-search.ts +27 -8
- package/src/repositories/product-projection.ts +4 -16
- package/src/services/abstract.ts +2 -7
- package/src/services/product-projection.ts +22 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import * as ctp from '@commercetools/platform-sdk';
|
|
3
3
|
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnit, CartDraft, Cart, CartAddLineItemAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetShippingAddressAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ReviewUpdateAction, Review, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, ShippingMethodDraft, ShippingMethod, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
|
|
4
|
-
import { ParsedQs } from 'qs';
|
|
5
4
|
|
|
6
5
|
type GetParams$1 = {
|
|
7
6
|
expand?: string[];
|
|
@@ -275,9 +274,9 @@ declare class ProductProjectionSearch {
|
|
|
275
274
|
* - counting products
|
|
276
275
|
* - correct dataType
|
|
277
276
|
*/
|
|
278
|
-
termFacet(facet: string, products: ProductProjection[]): TermFacetResult;
|
|
279
|
-
filterFacet(source: string, filters: FilterExpression[] | undefined, products: ProductProjection[]): FilteredFacetResult;
|
|
280
|
-
rangeFacet(source: string, ranges: RangeExpression[] | undefined, products: ProductProjection[]): RangeFacetResult;
|
|
277
|
+
termFacet(facet: string, products: ProductProjection[], countProducts: boolean): TermFacetResult;
|
|
278
|
+
filterFacet(source: string, filters: FilterExpression[] | undefined, products: ProductProjection[], countProducts: boolean): FilteredFacetResult;
|
|
279
|
+
rangeFacet(source: string, ranges: RangeExpression[] | undefined, products: ProductProjection[], countProducts: boolean): RangeFacetResult;
|
|
281
280
|
}
|
|
282
281
|
|
|
283
282
|
type ProductProjectionQueryParams = {
|
|
@@ -286,7 +285,7 @@ type ProductProjectionQueryParams = {
|
|
|
286
285
|
priceCountry?: string;
|
|
287
286
|
priceCustomerGroup?: string;
|
|
288
287
|
priceChannel?: string;
|
|
289
|
-
localeProjection?: string
|
|
288
|
+
localeProjection?: string;
|
|
290
289
|
storeProjection?: string;
|
|
291
290
|
expand?: string | string[];
|
|
292
291
|
sort?: string | string[];
|
|
@@ -309,7 +308,7 @@ declare class ProductProjectionRepository extends AbstractResourceRepository<'pr
|
|
|
309
308
|
limit: number;
|
|
310
309
|
results: ProductProjection[];
|
|
311
310
|
};
|
|
312
|
-
search(context: RepositoryContext, query:
|
|
311
|
+
search(context: RepositoryContext, query: ProductProjectionQueryParams): ctp.ProductProjectionPagedSearchResponse;
|
|
313
312
|
actions: {};
|
|
314
313
|
}
|
|
315
314
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import * as ctp from '@commercetools/platform-sdk';
|
|
3
3
|
import { Project, ResourceIdentifier, QueryParam, AssociateRoleDraft, AssociateRole, AssociateRoleSetNameAction, AssociateRoleSetPermissionsAction, AssociateRoleChangeBuyerAssignableAction, AssociateRoleSetCustomFieldAction, AssociateRoleAddPermissionAction, AssociateRoleRemovePermissionAction, AttributeGroupDraft, AttributeGroup, AttributeGroupSetAttributesAction, AttributeGroupChangeNameAction, AttributeGroupSetDescriptionAction, AttributeGroupSetKeyAction, BusinessUnit, CartDraft, Cart, CartAddLineItemAction, CartChangeLineItemQuantityAction, CartRemoveLineItemAction, CartSetBillingAddressAction, CartSetShippingMethodAction, CartSetCountryAction, CartSetCustomerEmailAction, CartSetCustomFieldAction, CartSetCustomTypeAction, CartSetLocaleAction, CartSetShippingAddressAction, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CartDiscountUpdateAction, AssetDraft, Asset, CategoryDraft, Category, CategoryChangeAssetNameAction, CategoryChangeSlugAction, CategorySetKeyAction, CategorySetAssetDescriptionAction, CategorySetAssetSourcesAction, CategorySetDescriptionAction, CategorySetMetaDescriptionAction, CategorySetMetaKeywordsAction, CategorySetMetaTitleAction, CategorySetCustomTypeAction, CategorySetCustomFieldAction, CategoryRemoveAssetAction, CategoryAddAssetAction, ChannelDraft, Channel, ChannelUpdateAction, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerChangeEmailAction, CustomerSetAuthenticationModeAction, CustomerSetCustomFieldAction, CustomerGroupDraft, CustomerGroup, CustomerGroupSetKeyAction, CustomerGroupChangeNameAction, CustomerGroupSetCustomTypeAction, CustomerGroupSetCustomFieldAction, DiscountCodeDraft, DiscountCode, DiscountCodeUpdateAction, Extension, ExtensionDraft, ExtensionUpdateAction, InventoryEntryDraft, InventoryEntry, InventoryEntryChangeQuantityAction, InventoryEntrySetExpectedDeliveryAction, InventoryEntrySetCustomFieldAction, InventoryEntrySetCustomTypeAction, InventoryEntrySetRestockableInDaysAction, OrderFromCartDraft, Order, CartReference, OrderImportDraft, OrderAddPaymentAction, OrderChangeOrderStateAction, OrderChangePaymentStateAction, OrderTransitionStateAction, OrderSetBillingAddressAction, OrderSetCustomerEmailAction, OrderSetCustomFieldAction, OrderSetCustomTypeAction, OrderSetLocaleAction, OrderSetOrderNumberAction, OrderSetShippingAddressAction, OrderSetStoreAction, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, OrderEditUpdateAction, PaymentDraft, Payment, TransactionDraft, Transaction, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentTransitionStateAction, ProductDraft, Product, ProductUpdateAction, ProductDiscountDraft, ProductDiscount, ProductDiscountUpdateAction, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ReviewUpdateAction, Review, ProductTypeDraft, ProductType, AttributeDefinitionDraft, AttributeDefinition, ProductTypeUpdateAction, ProjectUpdateAction, QuoteDraft, Quote, QuoteUpdateAction, QuoteRequestDraft, QuoteRequest, QuoteRequestUpdateAction, ReviewDraft, ShippingMethodDraft, ShippingMethod, ShippingMethodUpdateAction, ShoppingListDraft, ShoppingList, StagedQuoteDraft, StagedQuote, StagedQuoteUpdateAction, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, DiscountedPriceDraft, StandalonePriceChangeActiveAction, StandalonePriceChangeValueAction, StandalonePriceSetDiscountedPriceAction, StateDraft, State, StateUpdateAction, StoreDraft, Store, StoreUpdateAction, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TaxCategoryUpdateAction, TypeDraft, Type, TypeUpdateAction, ZoneDraft, Zone, ZoneUpdateAction, BaseResource, UpdateAction } from '@commercetools/platform-sdk';
|
|
4
|
-
import { ParsedQs } from 'qs';
|
|
5
4
|
|
|
6
5
|
type GetParams$1 = {
|
|
7
6
|
expand?: string[];
|
|
@@ -275,9 +274,9 @@ declare class ProductProjectionSearch {
|
|
|
275
274
|
* - counting products
|
|
276
275
|
* - correct dataType
|
|
277
276
|
*/
|
|
278
|
-
termFacet(facet: string, products: ProductProjection[]): TermFacetResult;
|
|
279
|
-
filterFacet(source: string, filters: FilterExpression[] | undefined, products: ProductProjection[]): FilteredFacetResult;
|
|
280
|
-
rangeFacet(source: string, ranges: RangeExpression[] | undefined, products: ProductProjection[]): RangeFacetResult;
|
|
277
|
+
termFacet(facet: string, products: ProductProjection[], countProducts: boolean): TermFacetResult;
|
|
278
|
+
filterFacet(source: string, filters: FilterExpression[] | undefined, products: ProductProjection[], countProducts: boolean): FilteredFacetResult;
|
|
279
|
+
rangeFacet(source: string, ranges: RangeExpression[] | undefined, products: ProductProjection[], countProducts: boolean): RangeFacetResult;
|
|
281
280
|
}
|
|
282
281
|
|
|
283
282
|
type ProductProjectionQueryParams = {
|
|
@@ -286,7 +285,7 @@ type ProductProjectionQueryParams = {
|
|
|
286
285
|
priceCountry?: string;
|
|
287
286
|
priceCustomerGroup?: string;
|
|
288
287
|
priceChannel?: string;
|
|
289
|
-
localeProjection?: string
|
|
288
|
+
localeProjection?: string;
|
|
290
289
|
storeProjection?: string;
|
|
291
290
|
expand?: string | string[];
|
|
292
291
|
sort?: string | string[];
|
|
@@ -309,7 +308,7 @@ declare class ProductProjectionRepository extends AbstractResourceRepository<'pr
|
|
|
309
308
|
limit: number;
|
|
310
309
|
results: ProductProjection[];
|
|
311
310
|
};
|
|
312
|
-
search(context: RepositoryContext, query:
|
|
311
|
+
search(context: RepositoryContext, query: ProductProjectionQueryParams): ctp.ProductProjectionPagedSearchResponse;
|
|
313
312
|
actions: {};
|
|
314
313
|
}
|
|
315
314
|
|
package/dist/index.js
CHANGED
|
@@ -45,14 +45,22 @@ var nestedLookup = (obj, path) => {
|
|
|
45
45
|
}
|
|
46
46
|
return val;
|
|
47
47
|
};
|
|
48
|
-
var
|
|
48
|
+
var queryParamsArray = (input) => {
|
|
49
49
|
if (input == void 0) {
|
|
50
|
-
return
|
|
50
|
+
return void 0;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
const values = Array.isArray(input) ? input : [input];
|
|
53
|
+
if (values.length < 1) {
|
|
54
|
+
return void 0;
|
|
54
55
|
}
|
|
55
|
-
return
|
|
56
|
+
return values;
|
|
57
|
+
};
|
|
58
|
+
var queryParamsValue = (value) => {
|
|
59
|
+
const values = queryParamsArray(value);
|
|
60
|
+
if (values && values.length > 0) {
|
|
61
|
+
return values[0];
|
|
62
|
+
}
|
|
63
|
+
return void 0;
|
|
56
64
|
};
|
|
57
65
|
var cloneObject = (o) => JSON.parse(JSON.stringify(o));
|
|
58
66
|
|
|
@@ -4185,25 +4193,36 @@ var ProductProjectionSearch = class {
|
|
|
4185
4193
|
getFacets(params, products) {
|
|
4186
4194
|
if (!params.facet)
|
|
4187
4195
|
return {};
|
|
4188
|
-
const staged = false;
|
|
4189
4196
|
const result = {};
|
|
4190
|
-
|
|
4197
|
+
const regexp = new RegExp(/ counting products$/);
|
|
4198
|
+
for (let facet of params.facet) {
|
|
4199
|
+
let countProducts = false;
|
|
4200
|
+
if (facet.endsWith(" counting products")) {
|
|
4201
|
+
facet = facet.replace(regexp, "");
|
|
4202
|
+
countProducts = true;
|
|
4203
|
+
}
|
|
4191
4204
|
const expression = generateFacetFunc(facet);
|
|
4192
4205
|
if (expression.type === "TermExpression") {
|
|
4193
|
-
result[facet] = this.termFacet(
|
|
4206
|
+
result[facet] = this.termFacet(
|
|
4207
|
+
expression.source,
|
|
4208
|
+
products,
|
|
4209
|
+
countProducts
|
|
4210
|
+
);
|
|
4194
4211
|
}
|
|
4195
4212
|
if (expression.type === "RangeExpression") {
|
|
4196
4213
|
result[expression.source] = this.rangeFacet(
|
|
4197
4214
|
expression.source,
|
|
4198
4215
|
expression.children,
|
|
4199
|
-
products
|
|
4216
|
+
products,
|
|
4217
|
+
countProducts
|
|
4200
4218
|
);
|
|
4201
4219
|
}
|
|
4202
4220
|
if (expression.type === "FilterExpression") {
|
|
4203
4221
|
result[expression.source] = this.filterFacet(
|
|
4204
4222
|
expression.source,
|
|
4205
4223
|
expression.children,
|
|
4206
|
-
products
|
|
4224
|
+
products,
|
|
4225
|
+
countProducts
|
|
4207
4226
|
);
|
|
4208
4227
|
}
|
|
4209
4228
|
}
|
|
@@ -4214,7 +4233,7 @@ var ProductProjectionSearch = class {
|
|
|
4214
4233
|
* - counting products
|
|
4215
4234
|
* - correct dataType
|
|
4216
4235
|
*/
|
|
4217
|
-
termFacet(facet, products) {
|
|
4236
|
+
termFacet(facet, products, countProducts) {
|
|
4218
4237
|
const result = {
|
|
4219
4238
|
type: "terms",
|
|
4220
4239
|
dataType: "text",
|
|
@@ -4259,7 +4278,7 @@ var ProductProjectionSearch = class {
|
|
|
4259
4278
|
}
|
|
4260
4279
|
return result;
|
|
4261
4280
|
}
|
|
4262
|
-
filterFacet(source, filters, products) {
|
|
4281
|
+
filterFacet(source, filters, products, countProducts) {
|
|
4263
4282
|
let count = 0;
|
|
4264
4283
|
if (source.startsWith("variants.")) {
|
|
4265
4284
|
for (const p of products) {
|
|
@@ -4278,7 +4297,7 @@ var ProductProjectionSearch = class {
|
|
|
4278
4297
|
count
|
|
4279
4298
|
};
|
|
4280
4299
|
}
|
|
4281
|
-
rangeFacet(source, ranges, products) {
|
|
4300
|
+
rangeFacet(source, ranges, products, countProducts) {
|
|
4282
4301
|
const counts = ranges?.map((range) => {
|
|
4283
4302
|
if (source.startsWith("variants.")) {
|
|
4284
4303
|
const values = [];
|
|
@@ -4400,16 +4419,7 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
|
|
|
4400
4419
|
};
|
|
4401
4420
|
}
|
|
4402
4421
|
search(context, query) {
|
|
4403
|
-
|
|
4404
|
-
filter: QueryParamsAsArray(query.filter),
|
|
4405
|
-
"filter.query": QueryParamsAsArray(query["filter.query"]),
|
|
4406
|
-
facet: QueryParamsAsArray(query.facet),
|
|
4407
|
-
offset: query.offset ? Number(query.offset) : void 0,
|
|
4408
|
-
limit: query.limit ? Number(query.limit) : void 0,
|
|
4409
|
-
expand: QueryParamsAsArray(query.expand),
|
|
4410
|
-
staged: query.staged === "true"
|
|
4411
|
-
});
|
|
4412
|
-
return results;
|
|
4422
|
+
return this._searchService.search(context.projectKey, query);
|
|
4413
4423
|
}
|
|
4414
4424
|
actions = {};
|
|
4415
4425
|
};
|
|
@@ -5414,12 +5424,7 @@ var AbstractService = class {
|
|
|
5414
5424
|
}
|
|
5415
5425
|
// No idea what i'm doing
|
|
5416
5426
|
_parseParam(value) {
|
|
5417
|
-
|
|
5418
|
-
return value;
|
|
5419
|
-
} else if (value !== void 0) {
|
|
5420
|
-
return [`${value}`];
|
|
5421
|
-
}
|
|
5422
|
-
return void 0;
|
|
5427
|
+
return queryParamsArray(value);
|
|
5423
5428
|
}
|
|
5424
5429
|
};
|
|
5425
5430
|
|
|
@@ -5862,9 +5867,25 @@ var ProductProjectionService = class extends AbstractService {
|
|
|
5862
5867
|
return response.status(200).send(result);
|
|
5863
5868
|
}
|
|
5864
5869
|
search(request, response) {
|
|
5870
|
+
const query = request.query;
|
|
5871
|
+
const searchParams = {
|
|
5872
|
+
filter: queryParamsArray(query.filter),
|
|
5873
|
+
"filter.query": queryParamsArray(query["filter.query"]),
|
|
5874
|
+
facet: queryParamsArray(query.facet),
|
|
5875
|
+
expand: queryParamsArray(query.expand),
|
|
5876
|
+
staged: queryParamsValue(query.staged) === "true",
|
|
5877
|
+
localeProjection: queryParamsValue(query.localeProjection),
|
|
5878
|
+
storeProjection: queryParamsValue(query.storeProjection),
|
|
5879
|
+
priceChannel: queryParamsValue(query.priceChannel),
|
|
5880
|
+
priceCountry: queryParamsValue(query.priceCountry),
|
|
5881
|
+
priceCurrency: queryParamsValue(query.priceCurrency),
|
|
5882
|
+
priceCustomerGroup: queryParamsValue(query.priceCustomerGroup),
|
|
5883
|
+
offset: query.offset ? Number(queryParamsValue(query.offset)) : void 0,
|
|
5884
|
+
limit: query.limit ? Number(queryParamsValue(query.limit)) : void 0
|
|
5885
|
+
};
|
|
5865
5886
|
const resource = this.repository.search(
|
|
5866
5887
|
getRepositoryContext(request),
|
|
5867
|
-
|
|
5888
|
+
searchParams
|
|
5868
5889
|
);
|
|
5869
5890
|
return response.status(200).send(resource);
|
|
5870
5891
|
}
|