@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
|
@@ -646,8 +646,12 @@ class InMemoryStorage extends AbstractStorage {
|
|
|
646
646
|
|
|
647
647
|
const resources = Array.from(store.values());
|
|
648
648
|
const resource = resources.find(e => e.key === key);
|
|
649
|
-
|
|
650
|
-
|
|
649
|
+
|
|
650
|
+
if (resource) {
|
|
651
|
+
return this.expand(projectKey, resource, params.expand);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
return null;
|
|
651
655
|
}
|
|
652
656
|
|
|
653
657
|
delete(projectKey, typeId, id, params = {}) {
|
|
@@ -974,9 +978,15 @@ class AbstractService {
|
|
|
974
978
|
}
|
|
975
979
|
|
|
976
980
|
get(request, response) {
|
|
981
|
+
const limit = this._parseParam(request.query.limit);
|
|
982
|
+
|
|
983
|
+
const offset = this._parseParam(request.query.offset);
|
|
984
|
+
|
|
977
985
|
const result = this.repository.query(request.params.projectKey, {
|
|
978
986
|
expand: this._parseParam(request.query.expand),
|
|
979
|
-
where: this._parseParam(request.query.where)
|
|
987
|
+
where: this._parseParam(request.query.where),
|
|
988
|
+
limit: limit !== undefined ? Number(limit) : undefined,
|
|
989
|
+
offset: offset !== undefined ? Number(offset) : undefined
|
|
980
990
|
});
|
|
981
991
|
return response.status(200).send(result);
|
|
982
992
|
}
|
|
@@ -1117,7 +1127,9 @@ class AbstractResourceRepository extends AbstractRepository {
|
|
|
1117
1127
|
query(projectKey, params = {}) {
|
|
1118
1128
|
return this._storage.query(projectKey, this.getTypeId(), {
|
|
1119
1129
|
expand: params.expand,
|
|
1120
|
-
where: params.where
|
|
1130
|
+
where: params.where,
|
|
1131
|
+
offset: params.offset,
|
|
1132
|
+
limit: params.limit
|
|
1121
1133
|
});
|
|
1122
1134
|
}
|
|
1123
1135
|
|
|
@@ -2650,10 +2662,15 @@ class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
2650
2662
|
}
|
|
2651
2663
|
|
|
2652
2664
|
search(projectKey, query) {
|
|
2653
|
-
|
|
2665
|
+
var _query$filterQuery;
|
|
2666
|
+
|
|
2667
|
+
const filter = (_query$filterQuery = query['filter.query']) != null ? _query$filterQuery : query.filter;
|
|
2668
|
+
const wherePredicate = filter ? parseFilterExpression(filter) : undefined;
|
|
2654
2669
|
|
|
2655
2670
|
const results = this._storage.query(projectKey, this.getTypeId(), {
|
|
2656
|
-
where: wherePredicate
|
|
2671
|
+
where: wherePredicate,
|
|
2672
|
+
offset: query.offset ? Number(query.offset) : undefined,
|
|
2673
|
+
limit: query.limit ? Number(query.limit) : undefined
|
|
2657
2674
|
}); //TODO: this is a partial implementation, but I don't really have the time to implement an actual search API right now
|
|
2658
2675
|
|
|
2659
2676
|
|
|
@@ -2968,6 +2985,28 @@ class ProductTypeService extends AbstractService {
|
|
|
2968
2985
|
|
|
2969
2986
|
}
|
|
2970
2987
|
|
|
2988
|
+
const maskSecretValue = (resource, path) => {
|
|
2989
|
+
const parts = path.split('.');
|
|
2990
|
+
const clone = JSON.parse(JSON.stringify(resource));
|
|
2991
|
+
let val = clone;
|
|
2992
|
+
const target = parts.pop();
|
|
2993
|
+
|
|
2994
|
+
for (let i = 0; i < parts.length; i++) {
|
|
2995
|
+
const part = parts[i];
|
|
2996
|
+
val = val[part];
|
|
2997
|
+
|
|
2998
|
+
if (val == undefined) {
|
|
2999
|
+
return resource;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
if (val && target && val[target]) {
|
|
3004
|
+
val[target] = '****';
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
return clone;
|
|
3008
|
+
};
|
|
3009
|
+
|
|
2971
3010
|
class ProjectRepository extends AbstractRepository {
|
|
2972
3011
|
constructor() {
|
|
2973
3012
|
super(...arguments);
|
|
@@ -3051,7 +3090,10 @@ class ProjectRepository extends AbstractRepository {
|
|
|
3051
3090
|
get(projectKey) {
|
|
3052
3091
|
const data = this._storage.getProject(projectKey);
|
|
3053
3092
|
|
|
3054
|
-
|
|
3093
|
+
const resource = this._storage.getProject(projectKey);
|
|
3094
|
+
|
|
3095
|
+
const masked = maskSecretValue(resource, 'externalOAuth.authorizationHeader');
|
|
3096
|
+
return masked;
|
|
3055
3097
|
}
|
|
3056
3098
|
|
|
3057
3099
|
save(projectKey, resource) {
|