@labdigital/commercetools-mock 2.18.0 → 2.18.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 CHANGED
@@ -5871,7 +5871,7 @@ var ProductTypeUpdateHandler = class extends AbstractUpdateHandler {
5871
5871
  var ProjectRepository = class extends AbstractRepository {
5872
5872
  constructor(storage) {
5873
5873
  super(storage);
5874
- this.actions = new ProjectUpdateHandler(this._storage);
5874
+ this.actions = new ProjectUpdateHandler(storage);
5875
5875
  }
5876
5876
  get(context) {
5877
5877
  const resource = this._storage.getProject(context.projectKey);
@@ -6154,7 +6154,7 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
6154
6154
  this._storage
6155
6155
  ),
6156
6156
  zoneRates: draft.zoneRates?.map(
6157
- (z) => this._transformZoneRateDraft(context, z)
6157
+ (z2) => this._transformZoneRateDraft(context, z2)
6158
6158
  ),
6159
6159
  custom: createCustomFields(
6160
6160
  draft.custom,
@@ -6982,6 +6982,34 @@ var createRepositories = (storage) => ({
6982
6982
 
6983
6983
  // src/services/abstract.ts
6984
6984
  var import_express2 = require("express");
6985
+
6986
+ // src/schemas/update-request.ts
6987
+ var import_zod = require("zod");
6988
+ var UpdateActionSchema = import_zod.z.object({
6989
+ action: import_zod.z.string()
6990
+ }).passthrough();
6991
+ var updateRequestSchema = import_zod.z.object({
6992
+ version: import_zod.z.number(),
6993
+ actions: import_zod.z.array(UpdateActionSchema)
6994
+ });
6995
+
6996
+ // src/validate.ts
6997
+ var import_zod_validation_error = require("zod-validation-error");
6998
+ var validateData = (data, schema) => {
6999
+ try {
7000
+ schema.parse(data);
7001
+ return data;
7002
+ } catch (err) {
7003
+ const validationError = (0, import_zod_validation_error.fromZodError)(err);
7004
+ throw new CommercetoolsError({
7005
+ code: "InvalidJsonInput",
7006
+ message: "Request body does not contain valid JSON.",
7007
+ detailedErrorMessage: validationError.toString()
7008
+ });
7009
+ }
7010
+ };
7011
+
7012
+ // src/services/abstract.ts
6985
7013
  var AbstractService = class {
6986
7014
  createStatusCode = 201;
6987
7015
  constructor(parent) {
@@ -7076,7 +7104,10 @@ var AbstractService = class {
7076
7104
  return response.status(this.createStatusCode).send(result);
7077
7105
  }
7078
7106
  postWithId(request, response) {
7079
- const updateRequest = request.body;
7107
+ const updateRequest = validateData(
7108
+ request.body,
7109
+ updateRequestSchema
7110
+ );
7080
7111
  const resource = this.repository.get(
7081
7112
  getRepositoryContext(request),
7082
7113
  request.params["id"]
@@ -7094,7 +7125,10 @@ var AbstractService = class {
7094
7125
  return response.status(200).send(result);
7095
7126
  }
7096
7127
  postWithKey(request, response) {
7097
- const updateRequest = request.body;
7128
+ const updateRequest = validateData(
7129
+ request.body,
7130
+ updateRequestSchema
7131
+ );
7098
7132
  const resource = this.repository.getByKey(
7099
7133
  getRepositoryContext(request),
7100
7134
  request.params["key"]
@@ -7458,7 +7492,10 @@ var MyCustomerService = class extends AbstractService {
7458
7492
  if (!resource) {
7459
7493
  return response.status(404).send("Not found");
7460
7494
  }
7461
- const updateRequest = request.body;
7495
+ const updateRequest = validateData(
7496
+ request.body,
7497
+ updateRequestSchema
7498
+ );
7462
7499
  const updatedResource = this.repository.processUpdateActions(
7463
7500
  getRepositoryContext(request),
7464
7501
  resource,
@@ -7936,7 +7973,10 @@ var ProjectService = class {
7936
7973
  return response.status(200).send(project);
7937
7974
  }
7938
7975
  post(request, response) {
7939
- const updateRequest = request.body;
7976
+ const updateRequest = validateData(
7977
+ request.body,
7978
+ updateRequestSchema
7979
+ );
7940
7980
  const project = this.repository.get(getRepositoryContext(request));
7941
7981
  if (!project) {
7942
7982
  return response.status(404).send({});