@labdigital/commercetools-mock 0.5.14 → 0.5.17
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/commercetools-mock.cjs.development.js +49 -7
- package/dist/commercetools-mock.cjs.development.js.map +1 -1
- package/dist/commercetools-mock.cjs.production.min.js +1 -1
- package/dist/commercetools-mock.cjs.production.min.js.map +1 -1
- package/dist/commercetools-mock.esm.js +49 -7
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/lib/masking.d.ts +1 -0
- package/dist/repositories/abstract.d.ts +2 -0
- package/package.json +1 -1
- package/src/lib/masking.ts +22 -0
- package/src/repositories/abstract.ts +4 -0
- package/src/repositories/product-projection.ts +4 -1
- package/src/repositories/project.ts +7 -1
- package/src/services/abstract.ts +5 -0
- package/src/services/product-projection.test.ts +63 -1
- package/src/storage.ts +8 -2
|
@@ -653,8 +653,12 @@ class InMemoryStorage extends AbstractStorage {
|
|
|
653
653
|
|
|
654
654
|
const resources = Array.from(store.values());
|
|
655
655
|
const resource = resources.find(e => e.key === key);
|
|
656
|
-
|
|
657
|
-
|
|
656
|
+
|
|
657
|
+
if (resource) {
|
|
658
|
+
return this.expand(projectKey, resource, params.expand);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return null;
|
|
658
662
|
}
|
|
659
663
|
|
|
660
664
|
delete(projectKey, typeId, id, params = {}) {
|
|
@@ -981,9 +985,15 @@ class AbstractService {
|
|
|
981
985
|
}
|
|
982
986
|
|
|
983
987
|
get(request, response) {
|
|
988
|
+
const limit = this._parseParam(request.query.limit);
|
|
989
|
+
|
|
990
|
+
const offset = this._parseParam(request.query.offset);
|
|
991
|
+
|
|
984
992
|
const result = this.repository.query(request.params.projectKey, {
|
|
985
993
|
expand: this._parseParam(request.query.expand),
|
|
986
|
-
where: this._parseParam(request.query.where)
|
|
994
|
+
where: this._parseParam(request.query.where),
|
|
995
|
+
limit: limit !== undefined ? Number(limit) : undefined,
|
|
996
|
+
offset: offset !== undefined ? Number(offset) : undefined
|
|
987
997
|
});
|
|
988
998
|
return response.status(200).send(result);
|
|
989
999
|
}
|
|
@@ -1124,7 +1134,9 @@ class AbstractResourceRepository extends AbstractRepository {
|
|
|
1124
1134
|
query(projectKey, params = {}) {
|
|
1125
1135
|
return this._storage.query(projectKey, this.getTypeId(), {
|
|
1126
1136
|
expand: params.expand,
|
|
1127
|
-
where: params.where
|
|
1137
|
+
where: params.where,
|
|
1138
|
+
offset: params.offset,
|
|
1139
|
+
limit: params.limit
|
|
1128
1140
|
});
|
|
1129
1141
|
}
|
|
1130
1142
|
|
|
@@ -2657,10 +2669,15 @@ class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
2657
2669
|
}
|
|
2658
2670
|
|
|
2659
2671
|
search(projectKey, query) {
|
|
2660
|
-
|
|
2672
|
+
var _query$filterQuery;
|
|
2673
|
+
|
|
2674
|
+
const filter = (_query$filterQuery = query['filter.query']) != null ? _query$filterQuery : query.filter;
|
|
2675
|
+
const wherePredicate = filter ? parseFilterExpression(filter) : undefined;
|
|
2661
2676
|
|
|
2662
2677
|
const results = this._storage.query(projectKey, this.getTypeId(), {
|
|
2663
|
-
where: wherePredicate
|
|
2678
|
+
where: wherePredicate,
|
|
2679
|
+
offset: query.offset ? Number(query.offset) : undefined,
|
|
2680
|
+
limit: query.limit ? Number(query.limit) : undefined
|
|
2664
2681
|
}); //TODO: this is a partial implementation, but I don't really have the time to implement an actual search API right now
|
|
2665
2682
|
|
|
2666
2683
|
|
|
@@ -2975,6 +2992,28 @@ class ProductTypeService extends AbstractService {
|
|
|
2975
2992
|
|
|
2976
2993
|
}
|
|
2977
2994
|
|
|
2995
|
+
const maskSecretValue = (resource, path) => {
|
|
2996
|
+
const parts = path.split('.');
|
|
2997
|
+
const clone = JSON.parse(JSON.stringify(resource));
|
|
2998
|
+
let val = clone;
|
|
2999
|
+
const target = parts.pop();
|
|
3000
|
+
|
|
3001
|
+
for (let i = 0; i < parts.length; i++) {
|
|
3002
|
+
const part = parts[i];
|
|
3003
|
+
val = val[part];
|
|
3004
|
+
|
|
3005
|
+
if (val == undefined) {
|
|
3006
|
+
return resource;
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
|
|
3010
|
+
if (val && target && val[target]) {
|
|
3011
|
+
val[target] = '****';
|
|
3012
|
+
}
|
|
3013
|
+
|
|
3014
|
+
return clone;
|
|
3015
|
+
};
|
|
3016
|
+
|
|
2978
3017
|
class ProjectRepository extends AbstractRepository {
|
|
2979
3018
|
constructor() {
|
|
2980
3019
|
super(...arguments);
|
|
@@ -3058,7 +3097,10 @@ class ProjectRepository extends AbstractRepository {
|
|
|
3058
3097
|
get(projectKey) {
|
|
3059
3098
|
const data = this._storage.getProject(projectKey);
|
|
3060
3099
|
|
|
3061
|
-
|
|
3100
|
+
const resource = this._storage.getProject(projectKey);
|
|
3101
|
+
|
|
3102
|
+
const masked = maskSecretValue(resource, 'externalOAuth.authorizationHeader');
|
|
3103
|
+
return masked;
|
|
3062
3104
|
}
|
|
3063
3105
|
|
|
3064
3106
|
save(projectKey, resource) {
|