@labdigital/commercetools-mock 2.23.1 → 2.26.0
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 +82 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/password.ts +15 -0
- package/src/repositories/customer/actions.ts +18 -0
- package/src/repositories/customer/index.ts +30 -1
- package/src/repositories/my-customer.ts +41 -1
- package/src/services/customer.test.ts +40 -0
- package/src/services/customer.ts +9 -0
- package/src/services/my-customer.test.ts +47 -0
- package/src/services/my-customer.ts +10 -0
package/dist/index.cjs
CHANGED
|
@@ -79,10 +79,14 @@ var import_express = __toESM(require("express"), 1);
|
|
|
79
79
|
// src/lib/password.ts
|
|
80
80
|
var import_uuid = require("uuid");
|
|
81
81
|
var PWRESET_SECRET = "pwreset";
|
|
82
|
+
var EMAIL_VERIFY_SECRET = "emailverifysecret";
|
|
82
83
|
var hashPassword = (clearPassword) => Buffer.from(clearPassword).toString("base64");
|
|
83
84
|
var createPasswordResetToken = (customer) => Buffer.from(`${customer.id}:${PWRESET_SECRET}:${(0, import_uuid.v4)()}`).toString(
|
|
84
85
|
"base64"
|
|
85
86
|
);
|
|
87
|
+
var createEmailVerifyToken = (customer) => Buffer.from(`${customer.id}:${EMAIL_VERIFY_SECRET}:${(0, import_uuid.v4)()}`).toString(
|
|
88
|
+
"base64"
|
|
89
|
+
);
|
|
86
90
|
var validatePasswordResetToken = (token) => {
|
|
87
91
|
const items = Buffer.from(token, "base64").toString("utf-8").split(":");
|
|
88
92
|
const [customerId, secret] = items;
|
|
@@ -91,6 +95,14 @@ var validatePasswordResetToken = (token) => {
|
|
|
91
95
|
}
|
|
92
96
|
return customerId;
|
|
93
97
|
};
|
|
98
|
+
var validateEmailVerifyToken = (token) => {
|
|
99
|
+
const items = Buffer.from(token, "base64").toString("utf-8").split(":");
|
|
100
|
+
const [customerId, secret] = items;
|
|
101
|
+
if (secret !== EMAIL_VERIFY_SECRET) {
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
return customerId;
|
|
105
|
+
};
|
|
94
106
|
|
|
95
107
|
// src/oauth/helpers.ts
|
|
96
108
|
var getBearerToken = (request) => {
|
|
@@ -3352,6 +3364,9 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3352
3364
|
}
|
|
3353
3365
|
resource.custom.fields[name] = value;
|
|
3354
3366
|
}
|
|
3367
|
+
setExternalId(_context, resource, { externalId }) {
|
|
3368
|
+
resource.externalId = externalId;
|
|
3369
|
+
}
|
|
3355
3370
|
setFirstName(_context, resource, { firstName }) {
|
|
3356
3371
|
resource.firstName = firstName;
|
|
3357
3372
|
}
|
|
@@ -3361,6 +3376,9 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
3361
3376
|
setLastName(_context, resource, { lastName }) {
|
|
3362
3377
|
resource.lastName = lastName;
|
|
3363
3378
|
}
|
|
3379
|
+
setLocale(_context, resource, { locale }) {
|
|
3380
|
+
resource.locale = locale;
|
|
3381
|
+
}
|
|
3364
3382
|
setSalutation(_context, resource, { salutation }) {
|
|
3365
3383
|
resource.salutation = salutation;
|
|
3366
3384
|
}
|
|
@@ -3449,6 +3467,29 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3449
3467
|
value: token
|
|
3450
3468
|
};
|
|
3451
3469
|
}
|
|
3470
|
+
verifyEmailToken(context, id) {
|
|
3471
|
+
const results = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3472
|
+
where: [`id="${id.toLocaleLowerCase()}"`]
|
|
3473
|
+
});
|
|
3474
|
+
if (results.count === 0) {
|
|
3475
|
+
throw new CommercetoolsError({
|
|
3476
|
+
code: "ResourceNotFound",
|
|
3477
|
+
message: `The Customer with ID '${id}' was not found.`
|
|
3478
|
+
});
|
|
3479
|
+
}
|
|
3480
|
+
const expiresAt = new Date(Date.now() + 30 * 60);
|
|
3481
|
+
const customer = results.results[0];
|
|
3482
|
+
const rest = getBaseResourceProperties();
|
|
3483
|
+
const token = createEmailVerifyToken(customer);
|
|
3484
|
+
return {
|
|
3485
|
+
id: rest.id,
|
|
3486
|
+
createdAt: rest.createdAt,
|
|
3487
|
+
lastModifiedAt: rest.lastModifiedAt,
|
|
3488
|
+
customerId: customer.id,
|
|
3489
|
+
expiresAt: expiresAt.toISOString(),
|
|
3490
|
+
value: token
|
|
3491
|
+
};
|
|
3492
|
+
}
|
|
3452
3493
|
};
|
|
3453
3494
|
|
|
3454
3495
|
// src/repositories/customer-group.ts
|
|
@@ -3761,6 +3802,31 @@ var MyCustomerRepository = class extends CustomerRepository {
|
|
|
3761
3802
|
this._storage.add(context.projectKey, "customer", customer);
|
|
3762
3803
|
return customer;
|
|
3763
3804
|
}
|
|
3805
|
+
confirmEmail(context, resetPassword) {
|
|
3806
|
+
const { tokenValue } = resetPassword;
|
|
3807
|
+
const customerId = validateEmailVerifyToken(tokenValue);
|
|
3808
|
+
if (!customerId) {
|
|
3809
|
+
throw new CommercetoolsError({
|
|
3810
|
+
code: "ResourceNotFound",
|
|
3811
|
+
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3812
|
+
});
|
|
3813
|
+
}
|
|
3814
|
+
const customer = this._storage.get(
|
|
3815
|
+
context.projectKey,
|
|
3816
|
+
"customer",
|
|
3817
|
+
customerId
|
|
3818
|
+
);
|
|
3819
|
+
if (!customer) {
|
|
3820
|
+
throw new CommercetoolsError({
|
|
3821
|
+
code: "ResourceNotFound",
|
|
3822
|
+
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3823
|
+
});
|
|
3824
|
+
}
|
|
3825
|
+
customer.isEmailVerified = true;
|
|
3826
|
+
customer.version += 1;
|
|
3827
|
+
this._storage.add(context.projectKey, "customer", customer);
|
|
3828
|
+
return customer;
|
|
3829
|
+
}
|
|
3764
3830
|
deleteMe(context) {
|
|
3765
3831
|
const results = this._storage.query(
|
|
3766
3832
|
context.projectKey,
|
|
@@ -7471,6 +7537,14 @@ var CustomerService = class extends AbstractService {
|
|
|
7471
7537
|
);
|
|
7472
7538
|
return response.status(200).send(token);
|
|
7473
7539
|
});
|
|
7540
|
+
parent.post("/email-token", (request, response) => {
|
|
7541
|
+
const id = request.body.id;
|
|
7542
|
+
const token = this.repository.verifyEmailToken(
|
|
7543
|
+
getRepositoryContext(request),
|
|
7544
|
+
id
|
|
7545
|
+
);
|
|
7546
|
+
return response.status(200).send(token);
|
|
7547
|
+
});
|
|
7474
7548
|
}
|
|
7475
7549
|
};
|
|
7476
7550
|
|
|
@@ -7576,6 +7650,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7576
7650
|
router.post("/login", this.signIn.bind(this));
|
|
7577
7651
|
router.post("/password", this.changePassword.bind(this));
|
|
7578
7652
|
router.post("/password/reset", this.resetPassword.bind(this));
|
|
7653
|
+
router.post("/email/confirm", this.emailConfirm.bind(this));
|
|
7579
7654
|
parent.use(`/${basePath}`, router);
|
|
7580
7655
|
}
|
|
7581
7656
|
getMe(request, response) {
|
|
@@ -7633,6 +7708,13 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7633
7708
|
);
|
|
7634
7709
|
return response.status(200).send(customer);
|
|
7635
7710
|
}
|
|
7711
|
+
emailConfirm(request, response) {
|
|
7712
|
+
const customer = this.repository.confirmEmail(
|
|
7713
|
+
getRepositoryContext(request),
|
|
7714
|
+
request.body
|
|
7715
|
+
);
|
|
7716
|
+
return response.status(200).send(customer);
|
|
7717
|
+
}
|
|
7636
7718
|
signIn(request, response) {
|
|
7637
7719
|
const { email, password } = request.body;
|
|
7638
7720
|
const encodedPassword = hashPassword(password);
|