@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 +46 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
- package/src/repositories/project.ts +1 -1
- package/src/schemas/update-request.ts +12 -0
- package/src/services/abstract.ts +12 -2
- package/src/services/my-customer.ts +6 -1
- package/src/services/project.test.ts +5 -0
- package/src/services/project.ts +7 -2
- package/src/validate.ts +18 -0
package/dist/index.js
CHANGED
|
@@ -5834,7 +5834,7 @@ var ProductTypeUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
5834
5834
|
var ProjectRepository = class extends AbstractRepository {
|
|
5835
5835
|
constructor(storage) {
|
|
5836
5836
|
super(storage);
|
|
5837
|
-
this.actions = new ProjectUpdateHandler(
|
|
5837
|
+
this.actions = new ProjectUpdateHandler(storage);
|
|
5838
5838
|
}
|
|
5839
5839
|
get(context) {
|
|
5840
5840
|
const resource = this._storage.getProject(context.projectKey);
|
|
@@ -6117,7 +6117,7 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
6117
6117
|
this._storage
|
|
6118
6118
|
),
|
|
6119
6119
|
zoneRates: draft.zoneRates?.map(
|
|
6120
|
-
(
|
|
6120
|
+
(z2) => this._transformZoneRateDraft(context, z2)
|
|
6121
6121
|
),
|
|
6122
6122
|
custom: createCustomFields(
|
|
6123
6123
|
draft.custom,
|
|
@@ -6945,6 +6945,34 @@ var createRepositories = (storage) => ({
|
|
|
6945
6945
|
|
|
6946
6946
|
// src/services/abstract.ts
|
|
6947
6947
|
import { Router } from "express";
|
|
6948
|
+
|
|
6949
|
+
// src/schemas/update-request.ts
|
|
6950
|
+
import { z } from "zod";
|
|
6951
|
+
var UpdateActionSchema = z.object({
|
|
6952
|
+
action: z.string()
|
|
6953
|
+
}).passthrough();
|
|
6954
|
+
var updateRequestSchema = z.object({
|
|
6955
|
+
version: z.number(),
|
|
6956
|
+
actions: z.array(UpdateActionSchema)
|
|
6957
|
+
});
|
|
6958
|
+
|
|
6959
|
+
// src/validate.ts
|
|
6960
|
+
import { fromZodError } from "zod-validation-error";
|
|
6961
|
+
var validateData = (data, schema) => {
|
|
6962
|
+
try {
|
|
6963
|
+
schema.parse(data);
|
|
6964
|
+
return data;
|
|
6965
|
+
} catch (err) {
|
|
6966
|
+
const validationError = fromZodError(err);
|
|
6967
|
+
throw new CommercetoolsError({
|
|
6968
|
+
code: "InvalidJsonInput",
|
|
6969
|
+
message: "Request body does not contain valid JSON.",
|
|
6970
|
+
detailedErrorMessage: validationError.toString()
|
|
6971
|
+
});
|
|
6972
|
+
}
|
|
6973
|
+
};
|
|
6974
|
+
|
|
6975
|
+
// src/services/abstract.ts
|
|
6948
6976
|
var AbstractService = class {
|
|
6949
6977
|
createStatusCode = 201;
|
|
6950
6978
|
constructor(parent) {
|
|
@@ -7039,7 +7067,10 @@ var AbstractService = class {
|
|
|
7039
7067
|
return response.status(this.createStatusCode).send(result);
|
|
7040
7068
|
}
|
|
7041
7069
|
postWithId(request, response) {
|
|
7042
|
-
const updateRequest =
|
|
7070
|
+
const updateRequest = validateData(
|
|
7071
|
+
request.body,
|
|
7072
|
+
updateRequestSchema
|
|
7073
|
+
);
|
|
7043
7074
|
const resource = this.repository.get(
|
|
7044
7075
|
getRepositoryContext(request),
|
|
7045
7076
|
request.params["id"]
|
|
@@ -7057,7 +7088,10 @@ var AbstractService = class {
|
|
|
7057
7088
|
return response.status(200).send(result);
|
|
7058
7089
|
}
|
|
7059
7090
|
postWithKey(request, response) {
|
|
7060
|
-
const updateRequest =
|
|
7091
|
+
const updateRequest = validateData(
|
|
7092
|
+
request.body,
|
|
7093
|
+
updateRequestSchema
|
|
7094
|
+
);
|
|
7061
7095
|
const resource = this.repository.getByKey(
|
|
7062
7096
|
getRepositoryContext(request),
|
|
7063
7097
|
request.params["key"]
|
|
@@ -7421,7 +7455,10 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7421
7455
|
if (!resource) {
|
|
7422
7456
|
return response.status(404).send("Not found");
|
|
7423
7457
|
}
|
|
7424
|
-
const updateRequest =
|
|
7458
|
+
const updateRequest = validateData(
|
|
7459
|
+
request.body,
|
|
7460
|
+
updateRequestSchema
|
|
7461
|
+
);
|
|
7425
7462
|
const updatedResource = this.repository.processUpdateActions(
|
|
7426
7463
|
getRepositoryContext(request),
|
|
7427
7464
|
resource,
|
|
@@ -7899,7 +7936,10 @@ var ProjectService = class {
|
|
|
7899
7936
|
return response.status(200).send(project);
|
|
7900
7937
|
}
|
|
7901
7938
|
post(request, response) {
|
|
7902
|
-
const updateRequest =
|
|
7939
|
+
const updateRequest = validateData(
|
|
7940
|
+
request.body,
|
|
7941
|
+
updateRequestSchema
|
|
7942
|
+
);
|
|
7903
7943
|
const project = this.repository.get(getRepositoryContext(request));
|
|
7904
7944
|
if (!project) {
|
|
7905
7945
|
return response.status(404).send({});
|