@labdigital/commercetools-mock 0.7.1 → 0.9.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.d.ts +26 -1
- package/dist/index.global.js +387 -92
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +384 -89
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +384 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -4
- package/src/helpers.ts +24 -0
- package/src/lib/predicateParser.test.ts +16 -0
- package/src/lib/predicateParser.ts +8 -1
- package/src/lib/projectionSearchFilter.test.ts +6 -0
- package/src/lib/projectionSearchFilter.ts +173 -74
- package/src/product-projection-search.ts +210 -10
- package/src/repositories/abstract.ts +23 -5
- package/src/repositories/extension.ts +18 -1
- package/src/repositories/helpers.ts +37 -3
- package/src/repositories/product-projection.ts +1 -0
- package/src/repositories/project.ts +10 -5
- package/src/repositories/state.ts +14 -0
- package/src/services/product-projection.test.ts +170 -3
- package/src/validate.js +0 -1
package/dist/index.global.js
CHANGED
|
@@ -44420,7 +44420,7 @@ ${this.pendingMocks().join("\n")}`
|
|
|
44420
44420
|
function maxBy(array, iteratee2) {
|
|
44421
44421
|
return array && array.length ? baseExtremum(array, getIteratee(iteratee2, 2), baseGt) : undefined2;
|
|
44422
44422
|
}
|
|
44423
|
-
function
|
|
44423
|
+
function mean2(array) {
|
|
44424
44424
|
return baseMean(array, identity);
|
|
44425
44425
|
}
|
|
44426
44426
|
function meanBy(array, iteratee2) {
|
|
@@ -44689,7 +44689,7 @@ ${this.pendingMocks().join("\n")}`
|
|
|
44689
44689
|
lodash.lte = lte;
|
|
44690
44690
|
lodash.max = max;
|
|
44691
44691
|
lodash.maxBy = maxBy;
|
|
44692
|
-
lodash.mean =
|
|
44692
|
+
lodash.mean = mean2;
|
|
44693
44693
|
lodash.meanBy = meanBy;
|
|
44694
44694
|
lodash.min = min;
|
|
44695
44695
|
lodash.minBy = minBy;
|
|
@@ -45032,7 +45032,7 @@ ${this.pendingMocks().join("\n")}`
|
|
|
45032
45032
|
return obj[val.value];
|
|
45033
45033
|
};
|
|
45034
45034
|
var getLexer = (value) => {
|
|
45035
|
-
return new import_perplex.default(value).token("AND", /and(?![-_a-z0-9]+)/i).token("OR", /or(?![-_a-z0-9]+)/i).token("NOT", /not(?![-_a-z0-9]+)/i).token("WITHIN", /within(?![-_a-z0-9]+)/i).token("IN", /in(?![-_a-z0-9]+)/i).token("MATCHES_IGNORE_CASE", /matches\s+ignore\s+case(?![-_a-z0-9]+)/i).token("CONTAINS", /contains(?![-_a-z0-9]+)/i).token("ALL", /all(?![-_a-z0-9]+)/i).token("ANY", /any(?![-_a-z0-9]+)/i).token("EMPTY", /empty(?![-_a-z0-9]+)/i).token("IS", /is(?![-_a-z0-9]+)/i).token("DEFINED", /defined(?![-_a-z0-9]+)/i).token("FLOAT", /\d+\.\d+/).token("INT", /\d+/).token("VARIABLE", /:([-_A-Za-z0-9]+)/).token("IDENTIFIER", /[-_A-Za-z0-9]+/).token("STRING", /"((?:\\.|[^"\\])*)"/).token("STRING", /'((?:\\.|[^'\\])*)'/).token("COMMA", ",").token("(", "(").token(")", ")").token(">=", ">=").token("<=", "<=").token(">", ">").token("<", "<").token("!=", "!=").token("=", "=").token('"', '"').token("WS", /\s+/, true);
|
|
45035
|
+
return new import_perplex.default(value).token("AND", /and(?![-_a-z0-9]+)/i).token("OR", /or(?![-_a-z0-9]+)/i).token("NOT", /not(?![-_a-z0-9]+)/i).token("WITHIN", /within(?![-_a-z0-9]+)/i).token("IN", /in(?![-_a-z0-9]+)/i).token("MATCHES_IGNORE_CASE", /matches\s+ignore\s+case(?![-_a-z0-9]+)/i).token("CONTAINS", /contains(?![-_a-z0-9]+)/i).token("ALL", /all(?![-_a-z0-9]+)/i).token("ANY", /any(?![-_a-z0-9]+)/i).token("EMPTY", /empty(?![-_a-z0-9]+)/i).token("IS", /is(?![-_a-z0-9]+)/i).token("DEFINED", /defined(?![-_a-z0-9]+)/i).token("FLOAT", /\d+\.\d+/).token("INT", /\d+/).token("VARIABLE", /:([-_A-Za-z0-9]+)/).token("BOOLEAN", /(true|false)/).token("IDENTIFIER", /[-_A-Za-z0-9]+/).token("STRING", /"((?:\\.|[^"\\])*)"/).token("STRING", /'((?:\\.|[^'\\])*)'/).token("COMMA", ",").token("(", "(").token(")", ")").token(">=", ">=").token("<=", "<=").token(">", ">").token("<", "<").token("!=", "!=").token("=", "=").token('"', '"').token("WS", /\s+/, true);
|
|
45036
45036
|
};
|
|
45037
45037
|
var generateMatchFunc = (predicate) => {
|
|
45038
45038
|
const lexer = getLexer(predicate);
|
|
@@ -45042,6 +45042,12 @@ ${this.pendingMocks().join("\n")}`
|
|
|
45042
45042
|
value: t.token.match,
|
|
45043
45043
|
pos: t.token.strpos()
|
|
45044
45044
|
};
|
|
45045
|
+
}).nud("BOOLEAN", 1, (t) => {
|
|
45046
|
+
return {
|
|
45047
|
+
type: "boolean",
|
|
45048
|
+
value: t.token.match === "true" ? true : false,
|
|
45049
|
+
pos: t.token.strpos()
|
|
45050
|
+
};
|
|
45045
45051
|
}).nud("VARIABLE", 100, (t) => {
|
|
45046
45052
|
return {
|
|
45047
45053
|
type: "var",
|
|
@@ -45736,6 +45742,21 @@ ${this.pendingMocks().join("\n")}`
|
|
|
45736
45742
|
version: 0
|
|
45737
45743
|
};
|
|
45738
45744
|
};
|
|
45745
|
+
var nestedLookup = (obj, path) => {
|
|
45746
|
+
if (!path || path === "") {
|
|
45747
|
+
return obj;
|
|
45748
|
+
}
|
|
45749
|
+
const parts = path.split(".");
|
|
45750
|
+
let val = obj;
|
|
45751
|
+
for (let i = 0; i < parts.length; i++) {
|
|
45752
|
+
const part = parts[i];
|
|
45753
|
+
if (val == void 0) {
|
|
45754
|
+
return void 0;
|
|
45755
|
+
}
|
|
45756
|
+
val = val[part];
|
|
45757
|
+
}
|
|
45758
|
+
return val;
|
|
45759
|
+
};
|
|
45739
45760
|
var QueryParamsAsArray = (input) => {
|
|
45740
45761
|
if (input == void 0) {
|
|
45741
45762
|
return [];
|
|
@@ -45844,10 +45865,41 @@ ${this.pendingMocks().join("\n")}`
|
|
|
45844
45865
|
};
|
|
45845
45866
|
};
|
|
45846
45867
|
var createTypedMoney = (value) => {
|
|
45868
|
+
let fractionDigits = 2;
|
|
45869
|
+
switch (value.currencyCode.toUpperCase()) {
|
|
45870
|
+
case "BHD":
|
|
45871
|
+
case "IQD":
|
|
45872
|
+
case "JOD":
|
|
45873
|
+
case "KWD":
|
|
45874
|
+
case "LYD":
|
|
45875
|
+
case "OMR":
|
|
45876
|
+
case "TND":
|
|
45877
|
+
fractionDigits = 3;
|
|
45878
|
+
break;
|
|
45879
|
+
case "CVE":
|
|
45880
|
+
case "DJF":
|
|
45881
|
+
case "GNF":
|
|
45882
|
+
case "IDR":
|
|
45883
|
+
case "JPY":
|
|
45884
|
+
case "KMF":
|
|
45885
|
+
case "KRW":
|
|
45886
|
+
case "PYG":
|
|
45887
|
+
case "RWF":
|
|
45888
|
+
case "UGX":
|
|
45889
|
+
case "VND":
|
|
45890
|
+
case "VUV":
|
|
45891
|
+
case "XAF":
|
|
45892
|
+
case "XOF":
|
|
45893
|
+
case "XPF":
|
|
45894
|
+
fractionDigits = 0;
|
|
45895
|
+
break;
|
|
45896
|
+
default:
|
|
45897
|
+
fractionDigits = 2;
|
|
45898
|
+
}
|
|
45847
45899
|
return {
|
|
45848
45900
|
type: "centPrecision",
|
|
45849
|
-
|
|
45850
|
-
|
|
45901
|
+
...value,
|
|
45902
|
+
fractionDigits
|
|
45851
45903
|
};
|
|
45852
45904
|
};
|
|
45853
45905
|
var resolveStoreReference = (ref, projectKey, storage) => {
|
|
@@ -46055,7 +46107,14 @@ ${this.pendingMocks().join("\n")}`
|
|
|
46055
46107
|
if (!(0, import_deep_equal.default)(modifiedResource, resource)) {
|
|
46056
46108
|
this.save(context, modifiedResource);
|
|
46057
46109
|
}
|
|
46058
|
-
|
|
46110
|
+
const result = this.postProcessResource(modifiedResource);
|
|
46111
|
+
if (!result) {
|
|
46112
|
+
throw new Error("invalid post process action");
|
|
46113
|
+
}
|
|
46114
|
+
return result;
|
|
46115
|
+
}
|
|
46116
|
+
postProcessResource(resource) {
|
|
46117
|
+
return resource;
|
|
46059
46118
|
}
|
|
46060
46119
|
};
|
|
46061
46120
|
var AbstractResourceRepository = class extends AbstractRepository {
|
|
@@ -46064,31 +46123,36 @@ ${this.pendingMocks().join("\n")}`
|
|
|
46064
46123
|
this._storage.assertStorage(this.getTypeId());
|
|
46065
46124
|
}
|
|
46066
46125
|
query(context, params = {}) {
|
|
46067
|
-
|
|
46126
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
46068
46127
|
expand: params.expand,
|
|
46069
46128
|
where: params.where,
|
|
46070
46129
|
offset: params.offset,
|
|
46071
46130
|
limit: params.limit
|
|
46072
46131
|
});
|
|
46132
|
+
result.results = result.results.map(this.postProcessResource);
|
|
46133
|
+
return result;
|
|
46073
46134
|
}
|
|
46074
46135
|
get(context, id, params = {}) {
|
|
46075
|
-
|
|
46136
|
+
const resource = this._storage.get(context.projectKey, this.getTypeId(), id, params);
|
|
46137
|
+
return this.postProcessResource(resource);
|
|
46076
46138
|
}
|
|
46077
46139
|
getByKey(context, key, params = {}) {
|
|
46078
|
-
|
|
46140
|
+
const resource = this._storage.getByKey(
|
|
46079
46141
|
context.projectKey,
|
|
46080
46142
|
this.getTypeId(),
|
|
46081
46143
|
key,
|
|
46082
46144
|
params
|
|
46083
46145
|
);
|
|
46146
|
+
return this.postProcessResource(resource);
|
|
46084
46147
|
}
|
|
46085
46148
|
delete(context, id, params = {}) {
|
|
46086
|
-
|
|
46149
|
+
const resource = this._storage.delete(
|
|
46087
46150
|
context.projectKey,
|
|
46088
46151
|
this.getTypeId(),
|
|
46089
46152
|
id,
|
|
46090
46153
|
params
|
|
46091
46154
|
);
|
|
46155
|
+
return this.postProcessResource(resource);
|
|
46092
46156
|
}
|
|
46093
46157
|
save(context, resource) {
|
|
46094
46158
|
const current = this.get(context, resource.id);
|
|
@@ -47369,6 +47433,25 @@ ${this.pendingMocks().join("\n")}`
|
|
|
47369
47433
|
}
|
|
47370
47434
|
};
|
|
47371
47435
|
|
|
47436
|
+
// src/lib/masking.ts
|
|
47437
|
+
var maskSecretValue = (resource, path) => {
|
|
47438
|
+
const parts = path.split(".");
|
|
47439
|
+
const clone = JSON.parse(JSON.stringify(resource));
|
|
47440
|
+
let val = clone;
|
|
47441
|
+
const target = parts.pop();
|
|
47442
|
+
for (let i = 0; i < parts.length; i++) {
|
|
47443
|
+
const part = parts[i];
|
|
47444
|
+
val = val[part];
|
|
47445
|
+
if (val === void 0) {
|
|
47446
|
+
return resource;
|
|
47447
|
+
}
|
|
47448
|
+
}
|
|
47449
|
+
if (val && target && val[target]) {
|
|
47450
|
+
val[target] = "****";
|
|
47451
|
+
}
|
|
47452
|
+
return clone;
|
|
47453
|
+
};
|
|
47454
|
+
|
|
47372
47455
|
// src/repositories/extension.ts
|
|
47373
47456
|
var ExtensionRepository = class extends AbstractResourceRepository {
|
|
47374
47457
|
constructor() {
|
|
@@ -47391,6 +47474,23 @@ ${this.pendingMocks().join("\n")}`
|
|
|
47391
47474
|
getTypeId() {
|
|
47392
47475
|
return "extension";
|
|
47393
47476
|
}
|
|
47477
|
+
postProcessResource(resource) {
|
|
47478
|
+
var _a;
|
|
47479
|
+
if (resource) {
|
|
47480
|
+
if (resource.destination.type === "HTTP" && ((_a = resource.destination.authentication) == null ? void 0 : _a.type) === "AuthorizationHeader") {
|
|
47481
|
+
return maskSecretValue(
|
|
47482
|
+
resource,
|
|
47483
|
+
"destination.authentication.headerValue"
|
|
47484
|
+
);
|
|
47485
|
+
} else if (resource.destination.type == "AWSLambda") {
|
|
47486
|
+
return maskSecretValue(
|
|
47487
|
+
resource,
|
|
47488
|
+
"destination.accessSecret"
|
|
47489
|
+
);
|
|
47490
|
+
}
|
|
47491
|
+
}
|
|
47492
|
+
return resource;
|
|
47493
|
+
}
|
|
47394
47494
|
create(context, draft) {
|
|
47395
47495
|
const resource = {
|
|
47396
47496
|
...getBaseResourceProperties(),
|
|
@@ -47820,38 +47920,71 @@ ${this.pendingMocks().join("\n")}`
|
|
|
47820
47920
|
var getLexer2 = (value) => {
|
|
47821
47921
|
return new import_perplex2.default(value).token("MISSING", /missing(?![-_a-z0-9]+)/i).token("EXISTS", /exists(?![-_a-z0-9]+)/i).token("RANGE", /range(?![-_a-z0-9]+)/i).token("TO", /to(?![-_a-z0-9]+)/i).token("IDENTIFIER", /[-_\.a-z]+/i).token("FLOAT", /\d+\.\d+/).token("INT", /\d+/).token("STRING", /"((?:\\.|[^"\\])*)"/).token("STRING", /'((?:\\.|[^'\\])*)'/).token("COMMA", ",").token("STAR", "*").token("(", "(").token(":", ":").token(")", ")").token('"', '"').token("WS", /\s+/, true);
|
|
47822
47922
|
};
|
|
47823
|
-
var
|
|
47923
|
+
var parseFilter = (filter) => {
|
|
47824
47924
|
const lexer = getLexer2(filter);
|
|
47825
47925
|
const parser = new import_pratt2.default(lexer).builder().nud("IDENTIFIER", 100, (t) => {
|
|
47826
47926
|
return t.token.match;
|
|
47827
47927
|
}).led(":", 100, ({ left, bp }) => {
|
|
47828
|
-
|
|
47829
|
-
|
|
47830
|
-
|
|
47831
|
-
|
|
47832
|
-
|
|
47833
|
-
|
|
47834
|
-
|
|
47835
|
-
|
|
47836
|
-
|
|
47928
|
+
let parsed = parser.parse({ terminals: [bp - 1] });
|
|
47929
|
+
let expressions;
|
|
47930
|
+
expressions = !Array.isArray(parsed) ? [parsed] : parsed;
|
|
47931
|
+
const unique = new Set(expressions.map((expr) => expr.type));
|
|
47932
|
+
if (unique.size > 1) {
|
|
47933
|
+
throw new Error("Invalid expression");
|
|
47934
|
+
}
|
|
47935
|
+
if (expressions.some((expr) => expr.type == "Symbol")) {
|
|
47936
|
+
return {
|
|
47937
|
+
source: left,
|
|
47938
|
+
type: "FilterExpression",
|
|
47939
|
+
children: expressions.map((e) => {
|
|
47940
|
+
if (e.type != "Symbol") {
|
|
47941
|
+
throw new Error("Invalid expression");
|
|
47942
|
+
}
|
|
47943
|
+
return {
|
|
47944
|
+
type: "FilterExpression",
|
|
47945
|
+
match: (obj) => {
|
|
47946
|
+
return obj === e.value;
|
|
47947
|
+
}
|
|
47948
|
+
};
|
|
47949
|
+
})
|
|
47837
47950
|
};
|
|
47838
47951
|
}
|
|
47839
|
-
return
|
|
47840
|
-
|
|
47952
|
+
return {
|
|
47953
|
+
source: left,
|
|
47954
|
+
type: expressions[0].type,
|
|
47955
|
+
children: expressions
|
|
47841
47956
|
};
|
|
47842
47957
|
}).nud("STRING", 20, (t) => {
|
|
47843
|
-
return
|
|
47958
|
+
return {
|
|
47959
|
+
type: "Symbol",
|
|
47960
|
+
kind: "string",
|
|
47961
|
+
value: t.token.groups[1]
|
|
47962
|
+
};
|
|
47844
47963
|
}).nud("INT", 5, (t) => {
|
|
47845
|
-
return
|
|
47964
|
+
return {
|
|
47965
|
+
type: "Symbol",
|
|
47966
|
+
kind: "int",
|
|
47967
|
+
value: parseInt(t.token.match, 10)
|
|
47968
|
+
};
|
|
47846
47969
|
}).nud("STAR", 5, (t) => {
|
|
47847
|
-
return
|
|
47970
|
+
return {
|
|
47971
|
+
type: "Symbol",
|
|
47972
|
+
kind: "any",
|
|
47973
|
+
value: null
|
|
47974
|
+
};
|
|
47848
47975
|
}).nud("EXISTS", 10, ({ bp }) => {
|
|
47849
|
-
return
|
|
47850
|
-
|
|
47976
|
+
return {
|
|
47977
|
+
type: "FilterExpression",
|
|
47978
|
+
match: (obj) => {
|
|
47979
|
+
return obj !== void 0;
|
|
47980
|
+
}
|
|
47851
47981
|
};
|
|
47852
47982
|
}).nud("MISSING", 10, ({ bp }) => {
|
|
47853
|
-
return
|
|
47854
|
-
|
|
47983
|
+
return {
|
|
47984
|
+
type: "FilterExpression",
|
|
47985
|
+
match: (obj) => {
|
|
47986
|
+
return obj === void 0;
|
|
47987
|
+
}
|
|
47855
47988
|
};
|
|
47856
47989
|
}).led("COMMA", 200, ({ left, token, bp }) => {
|
|
47857
47990
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
@@ -47860,38 +47993,74 @@ ${this.pendingMocks().join("\n")}`
|
|
|
47860
47993
|
} else {
|
|
47861
47994
|
return [left, expr];
|
|
47862
47995
|
}
|
|
47996
|
+
}).nud("(", 100, (t) => {
|
|
47997
|
+
const expr = parser.parse({ terminals: [")"] });
|
|
47998
|
+
lexer.expect(")");
|
|
47999
|
+
return expr;
|
|
47863
48000
|
}).bp(")", 0).led("TO", 20, ({ left, bp }) => {
|
|
47864
48001
|
const expr = parser.parse({ terminals: [bp - 1] });
|
|
47865
|
-
return
|
|
48002
|
+
return {
|
|
48003
|
+
start: left.value,
|
|
48004
|
+
stop: expr.value
|
|
48005
|
+
};
|
|
47866
48006
|
}).nud("RANGE", 20, ({ bp }) => {
|
|
47867
|
-
|
|
47868
|
-
|
|
47869
|
-
|
|
47870
|
-
|
|
47871
|
-
|
|
47872
|
-
|
|
47873
|
-
|
|
47874
|
-
|
|
47875
|
-
|
|
47876
|
-
|
|
47877
|
-
}
|
|
47878
|
-
|
|
47879
|
-
|
|
47880
|
-
|
|
47881
|
-
}
|
|
47882
|
-
|
|
47883
|
-
|
|
47884
|
-
|
|
48007
|
+
let ranges = parser.parse();
|
|
48008
|
+
if (!Array.isArray(ranges)) {
|
|
48009
|
+
ranges = [ranges];
|
|
48010
|
+
}
|
|
48011
|
+
return ranges.map((range) => {
|
|
48012
|
+
let func = void 0;
|
|
48013
|
+
if (range.start !== null && range.stop !== null) {
|
|
48014
|
+
func = (obj) => {
|
|
48015
|
+
return obj >= range.start && obj <= range.stop;
|
|
48016
|
+
};
|
|
48017
|
+
} else if (range.start === null && range.stop !== null) {
|
|
48018
|
+
func = (obj) => {
|
|
48019
|
+
return obj <= range.stop;
|
|
48020
|
+
};
|
|
48021
|
+
} else if (range.start !== null && range.stop === null) {
|
|
48022
|
+
func = (obj) => {
|
|
48023
|
+
return obj >= range.start;
|
|
48024
|
+
};
|
|
48025
|
+
} else {
|
|
48026
|
+
func = (obj) => {
|
|
48027
|
+
return true;
|
|
48028
|
+
};
|
|
48029
|
+
}
|
|
48030
|
+
return {
|
|
48031
|
+
type: "RangeExpression",
|
|
48032
|
+
start: range.start,
|
|
48033
|
+
stop: range.stop,
|
|
48034
|
+
match: func
|
|
47885
48035
|
};
|
|
47886
|
-
}
|
|
48036
|
+
});
|
|
47887
48037
|
}).build();
|
|
47888
|
-
|
|
47889
|
-
|
|
48038
|
+
return parser.parse();
|
|
48039
|
+
};
|
|
48040
|
+
var generateMatchFunc2 = (filter) => {
|
|
48041
|
+
const result = parseFilter(filter);
|
|
48042
|
+
if (!result) {
|
|
47890
48043
|
const lines = filter.split("\n");
|
|
47891
48044
|
const column = lines[lines.length - 1].length;
|
|
47892
48045
|
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
47893
48046
|
}
|
|
47894
|
-
|
|
48047
|
+
if (result.type == "TermExpression") {
|
|
48048
|
+
throw new Error(`Syntax error while parsing '${filter}'.`);
|
|
48049
|
+
}
|
|
48050
|
+
return (obj) => {
|
|
48051
|
+
if (!result.children)
|
|
48052
|
+
return false;
|
|
48053
|
+
return result.children.some((c) => c.match(obj));
|
|
48054
|
+
};
|
|
48055
|
+
};
|
|
48056
|
+
var generateFacetFunc = (filter) => {
|
|
48057
|
+
if (!filter.includes(":")) {
|
|
48058
|
+
return {
|
|
48059
|
+
source: filter,
|
|
48060
|
+
type: "TermExpression"
|
|
48061
|
+
};
|
|
48062
|
+
}
|
|
48063
|
+
return parseFilter(filter);
|
|
47895
48064
|
};
|
|
47896
48065
|
var filterProduct = (source, exprFunc) => {
|
|
47897
48066
|
return (p, markMatchingVariants) => {
|
|
@@ -47921,6 +48090,9 @@ ${this.pendingMocks().join("\n")}`
|
|
|
47921
48090
|
if (path === void 0) {
|
|
47922
48091
|
return obj;
|
|
47923
48092
|
}
|
|
48093
|
+
if (path.startsWith("variants.")) {
|
|
48094
|
+
path = path.substring(path.indexOf(".") + 1);
|
|
48095
|
+
}
|
|
47924
48096
|
if (path.startsWith("attributes.")) {
|
|
47925
48097
|
const [, attrName, ...rest] = path.split(".");
|
|
47926
48098
|
if (!obj.attributes) {
|
|
@@ -47937,21 +48109,6 @@ ${this.pendingMocks().join("\n")}`
|
|
|
47937
48109
|
}
|
|
47938
48110
|
return nestedLookup(obj, path);
|
|
47939
48111
|
};
|
|
47940
|
-
var nestedLookup = (obj, path) => {
|
|
47941
|
-
if (!path || path === "") {
|
|
47942
|
-
return obj;
|
|
47943
|
-
}
|
|
47944
|
-
const parts = path.split(".");
|
|
47945
|
-
let val = obj;
|
|
47946
|
-
for (let i = 0; i < parts.length; i++) {
|
|
47947
|
-
const part = parts[i];
|
|
47948
|
-
if (val == void 0) {
|
|
47949
|
-
return void 0;
|
|
47950
|
-
}
|
|
47951
|
-
val = val[part];
|
|
47952
|
-
}
|
|
47953
|
-
return val;
|
|
47954
|
-
};
|
|
47955
48112
|
var getVariants = (p, staged) => {
|
|
47956
48113
|
var _a, _b, _c, _d;
|
|
47957
48114
|
return [
|
|
@@ -48044,6 +48201,7 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48044
48201
|
);
|
|
48045
48202
|
}
|
|
48046
48203
|
}
|
|
48204
|
+
const facets = this.getFacets(params, resources);
|
|
48047
48205
|
if (params["filter.query"]) {
|
|
48048
48206
|
try {
|
|
48049
48207
|
const filters = params["filter.query"].map(
|
|
@@ -48077,7 +48235,7 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48077
48235
|
offset,
|
|
48078
48236
|
limit,
|
|
48079
48237
|
results: resources.map(this.transform),
|
|
48080
|
-
facets
|
|
48238
|
+
facets
|
|
48081
48239
|
};
|
|
48082
48240
|
}
|
|
48083
48241
|
transform(product) {
|
|
@@ -48088,6 +48246,9 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48088
48246
|
lastModifiedAt: product.lastModifiedAt,
|
|
48089
48247
|
version: product.version,
|
|
48090
48248
|
name: obj.name,
|
|
48249
|
+
key: product.key,
|
|
48250
|
+
description: obj.description,
|
|
48251
|
+
metaDescription: obj.metaDescription,
|
|
48091
48252
|
slug: obj.slug,
|
|
48092
48253
|
categories: obj.categories,
|
|
48093
48254
|
masterVariant: obj.masterVariant,
|
|
@@ -48095,6 +48256,145 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48095
48256
|
productType: product.productType
|
|
48096
48257
|
};
|
|
48097
48258
|
}
|
|
48259
|
+
getFacets(params, products) {
|
|
48260
|
+
if (!params.facet)
|
|
48261
|
+
return {};
|
|
48262
|
+
const staged = false;
|
|
48263
|
+
const result = {};
|
|
48264
|
+
for (const facet of params.facet) {
|
|
48265
|
+
const expression = generateFacetFunc(facet);
|
|
48266
|
+
if (expression.type === "TermExpression") {
|
|
48267
|
+
result[facet] = this.termFacet(expression.source, products, staged);
|
|
48268
|
+
}
|
|
48269
|
+
if (expression.type === "RangeExpression") {
|
|
48270
|
+
result[expression.source] = this.rangeFacet(
|
|
48271
|
+
expression.source,
|
|
48272
|
+
expression.children,
|
|
48273
|
+
products,
|
|
48274
|
+
staged
|
|
48275
|
+
);
|
|
48276
|
+
}
|
|
48277
|
+
if (expression.type === "FilterExpression") {
|
|
48278
|
+
result[expression.source] = this.filterFacet(
|
|
48279
|
+
expression.source,
|
|
48280
|
+
expression.children,
|
|
48281
|
+
products,
|
|
48282
|
+
staged
|
|
48283
|
+
);
|
|
48284
|
+
}
|
|
48285
|
+
}
|
|
48286
|
+
return result;
|
|
48287
|
+
}
|
|
48288
|
+
termFacet(facet, products, staged) {
|
|
48289
|
+
const result = {
|
|
48290
|
+
type: "terms",
|
|
48291
|
+
dataType: "text",
|
|
48292
|
+
missing: 0,
|
|
48293
|
+
total: 0,
|
|
48294
|
+
other: 0,
|
|
48295
|
+
terms: []
|
|
48296
|
+
};
|
|
48297
|
+
const terms = {};
|
|
48298
|
+
if (facet.startsWith("variants.")) {
|
|
48299
|
+
products.forEach((p) => {
|
|
48300
|
+
const variants = getVariants(p, staged);
|
|
48301
|
+
variants.forEach((v) => {
|
|
48302
|
+
result.total++;
|
|
48303
|
+
let value = resolveVariantValue(v, facet);
|
|
48304
|
+
if (value === void 0) {
|
|
48305
|
+
result.missing++;
|
|
48306
|
+
} else {
|
|
48307
|
+
if (typeof value === "number") {
|
|
48308
|
+
value = Number(value).toFixed(1);
|
|
48309
|
+
}
|
|
48310
|
+
terms[value] = value in terms ? terms[value] + 1 : 1;
|
|
48311
|
+
}
|
|
48312
|
+
});
|
|
48313
|
+
});
|
|
48314
|
+
} else {
|
|
48315
|
+
products.forEach((p) => {
|
|
48316
|
+
const value = nestedLookup(p, facet);
|
|
48317
|
+
result.total++;
|
|
48318
|
+
if (value === void 0) {
|
|
48319
|
+
result.missing++;
|
|
48320
|
+
} else {
|
|
48321
|
+
terms[value] = value in terms ? terms[value] + 1 : 1;
|
|
48322
|
+
}
|
|
48323
|
+
});
|
|
48324
|
+
}
|
|
48325
|
+
for (const term in terms) {
|
|
48326
|
+
result.terms.push({
|
|
48327
|
+
term,
|
|
48328
|
+
count: terms[term]
|
|
48329
|
+
});
|
|
48330
|
+
}
|
|
48331
|
+
return result;
|
|
48332
|
+
}
|
|
48333
|
+
filterFacet(source, filters, products, staged) {
|
|
48334
|
+
let count = 0;
|
|
48335
|
+
if (source.startsWith("variants.")) {
|
|
48336
|
+
for (const p of products) {
|
|
48337
|
+
for (const v of getVariants(p, staged)) {
|
|
48338
|
+
const val = resolveVariantValue(v, source);
|
|
48339
|
+
if (filters == null ? void 0 : filters.some((f) => f.match(val))) {
|
|
48340
|
+
count++;
|
|
48341
|
+
}
|
|
48342
|
+
}
|
|
48343
|
+
}
|
|
48344
|
+
} else {
|
|
48345
|
+
throw new Error("not supported");
|
|
48346
|
+
}
|
|
48347
|
+
return {
|
|
48348
|
+
type: "filter",
|
|
48349
|
+
count
|
|
48350
|
+
};
|
|
48351
|
+
}
|
|
48352
|
+
rangeFacet(source, ranges, products, staged) {
|
|
48353
|
+
const counts = (ranges == null ? void 0 : ranges.map((range) => {
|
|
48354
|
+
if (source.startsWith("variants.")) {
|
|
48355
|
+
const values = [];
|
|
48356
|
+
for (const p of products) {
|
|
48357
|
+
for (const v of getVariants(p, staged)) {
|
|
48358
|
+
const val = resolveVariantValue(v, source);
|
|
48359
|
+
if (val === void 0) {
|
|
48360
|
+
continue;
|
|
48361
|
+
}
|
|
48362
|
+
if (range.match(val)) {
|
|
48363
|
+
values.push(val);
|
|
48364
|
+
}
|
|
48365
|
+
}
|
|
48366
|
+
}
|
|
48367
|
+
const numValues = values.length;
|
|
48368
|
+
return {
|
|
48369
|
+
type: "double",
|
|
48370
|
+
from: range.start || 0,
|
|
48371
|
+
fromStr: range.start !== null ? Number(range.start).toFixed(1) : "",
|
|
48372
|
+
to: range.stop || 0,
|
|
48373
|
+
toStr: range.stop !== null ? Number(range.stop).toFixed(1) : "",
|
|
48374
|
+
count: numValues,
|
|
48375
|
+
total: values.reduce((a, b) => a + b, 0),
|
|
48376
|
+
min: numValues > 0 ? Math.min(...values) : 0,
|
|
48377
|
+
max: numValues > 0 ? Math.max(...values) : 0,
|
|
48378
|
+
mean: numValues > 0 ? mean(values) : 0
|
|
48379
|
+
};
|
|
48380
|
+
} else {
|
|
48381
|
+
throw new Error("not supported");
|
|
48382
|
+
}
|
|
48383
|
+
})) || [];
|
|
48384
|
+
const data = {
|
|
48385
|
+
type: "range",
|
|
48386
|
+
dataType: "number",
|
|
48387
|
+
ranges: counts
|
|
48388
|
+
};
|
|
48389
|
+
return data;
|
|
48390
|
+
}
|
|
48391
|
+
};
|
|
48392
|
+
var mean = (arr) => {
|
|
48393
|
+
let total = 0;
|
|
48394
|
+
for (let i = 0; i < arr.length; i++) {
|
|
48395
|
+
total += arr[i];
|
|
48396
|
+
}
|
|
48397
|
+
return total / arr.length;
|
|
48098
48398
|
};
|
|
48099
48399
|
|
|
48100
48400
|
// src/repositories/product-projection.ts
|
|
@@ -48122,6 +48422,7 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48122
48422
|
const results = this._searchService.search(context.projectKey, {
|
|
48123
48423
|
filter: QueryParamsAsArray(query.filter),
|
|
48124
48424
|
"filter.query": QueryParamsAsArray(query["filter.query"]),
|
|
48425
|
+
facet: QueryParamsAsArray(query.facet),
|
|
48125
48426
|
offset: query.offset ? Number(query.offset) : void 0,
|
|
48126
48427
|
limit: query.limit ? Number(query.limit) : void 0,
|
|
48127
48428
|
expand: QueryParamsAsArray(query.expand)
|
|
@@ -48470,25 +48771,6 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48470
48771
|
}
|
|
48471
48772
|
};
|
|
48472
48773
|
|
|
48473
|
-
// src/lib/masking.ts
|
|
48474
|
-
var maskSecretValue = (resource, path) => {
|
|
48475
|
-
const parts = path.split(".");
|
|
48476
|
-
const clone = JSON.parse(JSON.stringify(resource));
|
|
48477
|
-
let val = clone;
|
|
48478
|
-
const target = parts.pop();
|
|
48479
|
-
for (let i = 0; i < parts.length; i++) {
|
|
48480
|
-
const part = parts[i];
|
|
48481
|
-
val = val[part];
|
|
48482
|
-
if (val === void 0) {
|
|
48483
|
-
return resource;
|
|
48484
|
-
}
|
|
48485
|
-
}
|
|
48486
|
-
if (val && target && val[target]) {
|
|
48487
|
-
val[target] = "****";
|
|
48488
|
-
}
|
|
48489
|
-
return clone;
|
|
48490
|
-
};
|
|
48491
|
-
|
|
48492
48774
|
// src/repositories/project.ts
|
|
48493
48775
|
var ProjectRepository = class extends AbstractRepository {
|
|
48494
48776
|
constructor() {
|
|
@@ -48546,11 +48828,16 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48546
48828
|
}
|
|
48547
48829
|
get(context) {
|
|
48548
48830
|
const resource = this._storage.getProject(context.projectKey);
|
|
48549
|
-
|
|
48550
|
-
|
|
48551
|
-
|
|
48552
|
-
)
|
|
48553
|
-
|
|
48831
|
+
return this.postProcessResource(resource);
|
|
48832
|
+
}
|
|
48833
|
+
postProcessResource(resource) {
|
|
48834
|
+
if (resource) {
|
|
48835
|
+
return maskSecretValue(
|
|
48836
|
+
resource,
|
|
48837
|
+
"externalOAuth.authorizationHeader"
|
|
48838
|
+
);
|
|
48839
|
+
}
|
|
48840
|
+
return resource;
|
|
48554
48841
|
}
|
|
48555
48842
|
save(context, resource) {
|
|
48556
48843
|
const current = this.get(context);
|
|
@@ -48819,6 +49106,14 @@ ${this.pendingMocks().join("\n")}`
|
|
|
48819
49106
|
},
|
|
48820
49107
|
setRoles: (context, resource, { roles }) => {
|
|
48821
49108
|
resource.roles = roles;
|
|
49109
|
+
},
|
|
49110
|
+
setTransitions: (context, resource, { transitions }) => {
|
|
49111
|
+
resource.transitions = transitions == null ? void 0 : transitions.map((resourceId) => {
|
|
49112
|
+
return {
|
|
49113
|
+
id: resourceId.id || "",
|
|
49114
|
+
typeId: "state"
|
|
49115
|
+
};
|
|
49116
|
+
});
|
|
48822
49117
|
}
|
|
48823
49118
|
};
|
|
48824
49119
|
}
|