@labdigital/commercetools-mock 2.13.0 → 2.14.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 +112 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +112 -37
- package/dist/index.js.map +1 -1
- package/package.json +31 -31
- package/src/repositories/cart.ts +2 -2
- package/src/repositories/customer.ts +72 -0
- package/src/repositories/order.ts +1 -1
- package/src/repositories/payment.ts +92 -47
- package/src/repositories/product.ts +5 -5
- package/src/repositories/review.ts +2 -2
- package/src/repositories/shopping-list.ts +1 -1
- package/src/services/customer.test.ts +154 -0
- package/src/services/customer.ts +1 -1
- package/src/services/my-customer.test.ts +32 -2
- package/src/services/my-customer.ts +32 -1
package/dist/index.cjs
CHANGED
|
@@ -3190,6 +3190,46 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3190
3190
|
changeEmail: (_context, resource, { email }) => {
|
|
3191
3191
|
resource.email = email;
|
|
3192
3192
|
},
|
|
3193
|
+
setFirstName: (_context, resource, { firstName }) => {
|
|
3194
|
+
resource.firstName = firstName;
|
|
3195
|
+
},
|
|
3196
|
+
setLastName: (_context, resource, { lastName }) => {
|
|
3197
|
+
resource.lastName = lastName;
|
|
3198
|
+
},
|
|
3199
|
+
setCompanyName: (_context, resource, { companyName }) => {
|
|
3200
|
+
resource.companyName = companyName;
|
|
3201
|
+
},
|
|
3202
|
+
setVatId: (_context, resource, { vatId }) => {
|
|
3203
|
+
resource.vatId = vatId;
|
|
3204
|
+
},
|
|
3205
|
+
changeAddress: (context, resource, { addressId, addressKey, address }) => {
|
|
3206
|
+
const oldAddressIndex = resource.addresses.findIndex((a) => {
|
|
3207
|
+
if (a.id != void 0 && addressId != void 0 && a.id === addressId) {
|
|
3208
|
+
return true;
|
|
3209
|
+
}
|
|
3210
|
+
return a.key != void 0 && addressKey != void 0 && a.key === addressKey;
|
|
3211
|
+
});
|
|
3212
|
+
if (oldAddressIndex === -1) {
|
|
3213
|
+
throw new CommercetoolsError(
|
|
3214
|
+
{
|
|
3215
|
+
code: "InvalidInput",
|
|
3216
|
+
message: `Address with id '${addressId}' or key '${addressKey}' not found.`
|
|
3217
|
+
},
|
|
3218
|
+
400
|
|
3219
|
+
);
|
|
3220
|
+
}
|
|
3221
|
+
const newAddress = createAddress(
|
|
3222
|
+
address,
|
|
3223
|
+
context.projectKey,
|
|
3224
|
+
this._storage
|
|
3225
|
+
);
|
|
3226
|
+
if (newAddress) {
|
|
3227
|
+
resource.addresses[oldAddressIndex] = {
|
|
3228
|
+
id: addressId,
|
|
3229
|
+
...newAddress
|
|
3230
|
+
};
|
|
3231
|
+
}
|
|
3232
|
+
},
|
|
3193
3233
|
setAuthenticationMode: (_context, resource, { authMode, password }) => {
|
|
3194
3234
|
if (resource.authenticationMode === authMode) {
|
|
3195
3235
|
throw new CommercetoolsError(
|
|
@@ -3939,32 +3979,6 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3939
3979
|
// Documented as default
|
|
3940
3980
|
});
|
|
3941
3981
|
actions = {
|
|
3942
|
-
setCustomField: (context, resource, { name, value }) => {
|
|
3943
|
-
if (!resource.custom) {
|
|
3944
|
-
throw new Error("Resource has no custom field");
|
|
3945
|
-
}
|
|
3946
|
-
resource.custom.fields[name] = value;
|
|
3947
|
-
},
|
|
3948
|
-
setCustomType: (context, resource, { type, fields }) => {
|
|
3949
|
-
if (!type) {
|
|
3950
|
-
resource.custom = void 0;
|
|
3951
|
-
} else {
|
|
3952
|
-
const resolvedType = this._storage.getByResourceIdentifier(
|
|
3953
|
-
context.projectKey,
|
|
3954
|
-
type
|
|
3955
|
-
);
|
|
3956
|
-
if (!resolvedType) {
|
|
3957
|
-
throw new Error(`Type ${type} not found`);
|
|
3958
|
-
}
|
|
3959
|
-
resource.custom = {
|
|
3960
|
-
type: {
|
|
3961
|
-
typeId: "type",
|
|
3962
|
-
id: resolvedType.id
|
|
3963
|
-
},
|
|
3964
|
-
fields: fields ?? {}
|
|
3965
|
-
};
|
|
3966
|
-
}
|
|
3967
|
-
},
|
|
3968
3982
|
addTransaction: (context, resource, { transaction }) => {
|
|
3969
3983
|
resource.transactions = [
|
|
3970
3984
|
...resource.transactions,
|
|
@@ -3994,24 +4008,60 @@ var PaymentRepository = class extends AbstractResourceRepository {
|
|
|
3994
4008
|
id: stateObj.id,
|
|
3995
4009
|
obj: stateObj
|
|
3996
4010
|
};
|
|
4011
|
+
},
|
|
4012
|
+
setCustomField: (context, resource, { name, value }) => {
|
|
4013
|
+
if (!resource.custom) {
|
|
4014
|
+
throw new Error("Resource has no custom field");
|
|
4015
|
+
}
|
|
4016
|
+
resource.custom.fields[name] = value;
|
|
4017
|
+
},
|
|
4018
|
+
setCustomType: (context, resource, { type, fields }) => {
|
|
4019
|
+
if (!type) {
|
|
4020
|
+
resource.custom = void 0;
|
|
4021
|
+
} else {
|
|
4022
|
+
const resolvedType = this._storage.getByResourceIdentifier(
|
|
4023
|
+
context.projectKey,
|
|
4024
|
+
type
|
|
4025
|
+
);
|
|
4026
|
+
if (!resolvedType) {
|
|
4027
|
+
throw new Error(`Type ${type} not found`);
|
|
4028
|
+
}
|
|
4029
|
+
resource.custom = {
|
|
4030
|
+
type: {
|
|
4031
|
+
typeId: "type",
|
|
4032
|
+
id: resolvedType.id
|
|
4033
|
+
},
|
|
4034
|
+
fields: fields ?? {}
|
|
4035
|
+
};
|
|
4036
|
+
}
|
|
4037
|
+
},
|
|
4038
|
+
setKey: (_context, resource, { key }) => {
|
|
4039
|
+
resource.key = key;
|
|
4040
|
+
},
|
|
4041
|
+
setStatusInterfaceCode: (_context, resource, { interfaceCode }) => {
|
|
4042
|
+
resource.paymentStatus.interfaceCode = interfaceCode;
|
|
4043
|
+
},
|
|
4044
|
+
setStatusInterfaceText: (_context, resource, { interfaceText }) => {
|
|
4045
|
+
resource.paymentStatus.interfaceText = interfaceText;
|
|
4046
|
+
},
|
|
4047
|
+
setMethodInfoName: (_context, resource, { name }) => {
|
|
4048
|
+
resource.paymentMethodInfo.name = name;
|
|
4049
|
+
},
|
|
4050
|
+
setMethodInfoMethod: (_context, resource, { method }) => {
|
|
4051
|
+
resource.paymentMethodInfo.method = method;
|
|
4052
|
+
},
|
|
4053
|
+
setMethodInfoInterface: (_context, resource, args) => {
|
|
4054
|
+
resource.paymentMethodInfo.paymentInterface = args.interface;
|
|
4055
|
+
},
|
|
4056
|
+
setInterfaceId: (_context, resource, { interfaceId }) => {
|
|
4057
|
+
resource.interfaceId = interfaceId;
|
|
3997
4058
|
}
|
|
3998
4059
|
// addInterfaceInteraction: () => {},
|
|
3999
4060
|
// changeAmountPlanned: () => {},
|
|
4000
4061
|
// changeTransactionInteractionId: () => {},
|
|
4001
4062
|
// changeTransactionTimestamp: () => {},
|
|
4002
|
-
// setAmountPaid: () => {},
|
|
4003
|
-
// setAmountRefunded: () => {},
|
|
4004
4063
|
// setAnonymousId: () => {},
|
|
4005
|
-
// setAuthorization: () => {},
|
|
4006
4064
|
// setCustomer: () => {},
|
|
4007
|
-
// setExternalId: () => {},
|
|
4008
|
-
// setInterfaceId: () => {},
|
|
4009
|
-
// setKey: () => {},
|
|
4010
|
-
// setMethodInfoInterface: () => {},
|
|
4011
|
-
// setMethodInfoMethod: () => {},
|
|
4012
|
-
// setMethodInfoName: () => {},
|
|
4013
|
-
// setStatusInterfaceCode: () => {},
|
|
4014
|
-
// setStatusInterfaceText: () => {},
|
|
4015
4065
|
};
|
|
4016
4066
|
};
|
|
4017
4067
|
|
|
@@ -6857,6 +6907,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
6857
6907
|
router.delete("", this.deleteMe.bind(this));
|
|
6858
6908
|
router.post("/signup", this.signUp.bind(this));
|
|
6859
6909
|
router.post("/login", this.signIn.bind(this));
|
|
6910
|
+
router.post("/password", this.changePassword.bind(this));
|
|
6860
6911
|
parent.use(`/${basePath}`, router);
|
|
6861
6912
|
}
|
|
6862
6913
|
getMe(request, response) {
|
|
@@ -6897,6 +6948,30 @@ var MyCustomerService = class extends AbstractService {
|
|
|
6897
6948
|
const result = this._expandWithId(request, resource.id);
|
|
6898
6949
|
return response.status(this.createStatusCode).send({ customer: result });
|
|
6899
6950
|
}
|
|
6951
|
+
changePassword(request, response) {
|
|
6952
|
+
const { currentPassword, newPassword } = request.body;
|
|
6953
|
+
const encodedPassword = hashPassword(currentPassword);
|
|
6954
|
+
const result = this.repository.query(getRepositoryContext(request), {
|
|
6955
|
+
where: [`password = "${encodedPassword}"`]
|
|
6956
|
+
});
|
|
6957
|
+
if (result.count === 0) {
|
|
6958
|
+
return response.status(404).send({
|
|
6959
|
+
message: "Account with the given credentials not found.",
|
|
6960
|
+
errors: [
|
|
6961
|
+
{
|
|
6962
|
+
code: "InvalidCredentials",
|
|
6963
|
+
message: "Account with the given credentials not found."
|
|
6964
|
+
}
|
|
6965
|
+
]
|
|
6966
|
+
});
|
|
6967
|
+
}
|
|
6968
|
+
const newCustomer = {
|
|
6969
|
+
...result.results[0],
|
|
6970
|
+
password: hashPassword(newPassword)
|
|
6971
|
+
};
|
|
6972
|
+
this.repository.saveNew(getRepositoryContext(request), newCustomer);
|
|
6973
|
+
return response.status(200).send(newCustomer);
|
|
6974
|
+
}
|
|
6900
6975
|
signIn(request, response) {
|
|
6901
6976
|
const { email, password } = request.body;
|
|
6902
6977
|
const encodedPassword = hashPassword(password);
|