@labdigital/commercetools-mock 2.23.0 → 2.24.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 +81 -1
- 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 +81 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/password.ts +15 -0
- package/src/repositories/custom-object.ts +5 -1
- package/src/repositories/customer/index.ts +30 -1
- package/src/repositories/my-customer.ts +41 -1
- package/src/services/custom-object.test.ts +19 -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) => {
|
|
@@ -3265,7 +3277,11 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
3265
3277
|
...params,
|
|
3266
3278
|
where: whereClause
|
|
3267
3279
|
});
|
|
3268
|
-
result.results = result.results.map(
|
|
3280
|
+
result.results = result.results.map(
|
|
3281
|
+
(r) => this.postProcessResource(context, r, {
|
|
3282
|
+
expand: params.expand
|
|
3283
|
+
})
|
|
3284
|
+
);
|
|
3269
3285
|
return result;
|
|
3270
3286
|
}
|
|
3271
3287
|
};
|
|
@@ -3445,6 +3461,29 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3445
3461
|
value: token
|
|
3446
3462
|
};
|
|
3447
3463
|
}
|
|
3464
|
+
verifyEmailToken(context, id) {
|
|
3465
|
+
const results = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3466
|
+
where: [`id="${id.toLocaleLowerCase()}"`]
|
|
3467
|
+
});
|
|
3468
|
+
if (results.count === 0) {
|
|
3469
|
+
throw new CommercetoolsError({
|
|
3470
|
+
code: "ResourceNotFound",
|
|
3471
|
+
message: `The Customer with ID '${id}' was not found.`
|
|
3472
|
+
});
|
|
3473
|
+
}
|
|
3474
|
+
const expiresAt = new Date(Date.now() + 30 * 60);
|
|
3475
|
+
const customer = results.results[0];
|
|
3476
|
+
const rest = getBaseResourceProperties();
|
|
3477
|
+
const token = createEmailVerifyToken(customer);
|
|
3478
|
+
return {
|
|
3479
|
+
id: rest.id,
|
|
3480
|
+
createdAt: rest.createdAt,
|
|
3481
|
+
lastModifiedAt: rest.lastModifiedAt,
|
|
3482
|
+
customerId: customer.id,
|
|
3483
|
+
expiresAt: expiresAt.toISOString(),
|
|
3484
|
+
value: token
|
|
3485
|
+
};
|
|
3486
|
+
}
|
|
3448
3487
|
};
|
|
3449
3488
|
|
|
3450
3489
|
// src/repositories/customer-group.ts
|
|
@@ -3757,6 +3796,31 @@ var MyCustomerRepository = class extends CustomerRepository {
|
|
|
3757
3796
|
this._storage.add(context.projectKey, "customer", customer);
|
|
3758
3797
|
return customer;
|
|
3759
3798
|
}
|
|
3799
|
+
confirmEmail(context, resetPassword) {
|
|
3800
|
+
const { tokenValue } = resetPassword;
|
|
3801
|
+
const customerId = validateEmailVerifyToken(tokenValue);
|
|
3802
|
+
if (!customerId) {
|
|
3803
|
+
throw new CommercetoolsError({
|
|
3804
|
+
code: "ResourceNotFound",
|
|
3805
|
+
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3806
|
+
});
|
|
3807
|
+
}
|
|
3808
|
+
const customer = this._storage.get(
|
|
3809
|
+
context.projectKey,
|
|
3810
|
+
"customer",
|
|
3811
|
+
customerId
|
|
3812
|
+
);
|
|
3813
|
+
if (!customer) {
|
|
3814
|
+
throw new CommercetoolsError({
|
|
3815
|
+
code: "ResourceNotFound",
|
|
3816
|
+
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3817
|
+
});
|
|
3818
|
+
}
|
|
3819
|
+
customer.isEmailVerified = true;
|
|
3820
|
+
customer.version += 1;
|
|
3821
|
+
this._storage.add(context.projectKey, "customer", customer);
|
|
3822
|
+
return customer;
|
|
3823
|
+
}
|
|
3760
3824
|
deleteMe(context) {
|
|
3761
3825
|
const results = this._storage.query(
|
|
3762
3826
|
context.projectKey,
|
|
@@ -7467,6 +7531,14 @@ var CustomerService = class extends AbstractService {
|
|
|
7467
7531
|
);
|
|
7468
7532
|
return response.status(200).send(token);
|
|
7469
7533
|
});
|
|
7534
|
+
parent.post("/email-token", (request, response) => {
|
|
7535
|
+
const id = request.body.id;
|
|
7536
|
+
const token = this.repository.verifyEmailToken(
|
|
7537
|
+
getRepositoryContext(request),
|
|
7538
|
+
id
|
|
7539
|
+
);
|
|
7540
|
+
return response.status(200).send(token);
|
|
7541
|
+
});
|
|
7470
7542
|
}
|
|
7471
7543
|
};
|
|
7472
7544
|
|
|
@@ -7572,6 +7644,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7572
7644
|
router.post("/login", this.signIn.bind(this));
|
|
7573
7645
|
router.post("/password", this.changePassword.bind(this));
|
|
7574
7646
|
router.post("/password/reset", this.resetPassword.bind(this));
|
|
7647
|
+
router.post("/email/confirm", this.emailConfirm.bind(this));
|
|
7575
7648
|
parent.use(`/${basePath}`, router);
|
|
7576
7649
|
}
|
|
7577
7650
|
getMe(request, response) {
|
|
@@ -7629,6 +7702,13 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7629
7702
|
);
|
|
7630
7703
|
return response.status(200).send(customer);
|
|
7631
7704
|
}
|
|
7705
|
+
emailConfirm(request, response) {
|
|
7706
|
+
const customer = this.repository.confirmEmail(
|
|
7707
|
+
getRepositoryContext(request),
|
|
7708
|
+
request.body
|
|
7709
|
+
);
|
|
7710
|
+
return response.status(200).send(customer);
|
|
7711
|
+
}
|
|
7632
7712
|
signIn(request, response) {
|
|
7633
7713
|
const { email, password } = request.body;
|
|
7634
7714
|
const encodedPassword = hashPassword(password);
|