@labdigital/commercetools-mock 2.23.1 → 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 +76 -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 +76 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/password.ts +15 -0
- package/src/repositories/customer/index.ts +30 -1
- package/src/repositories/my-customer.ts +41 -1
- 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.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { SetupServerApi, SetupServer } from 'msw/node';
|
|
3
3
|
import * as ctp from '@commercetools/platform-sdk';
|
|
4
|
-
import { QueryParam, BaseResource, Project, UpdateAction, ResourceIdentifier, AssociateRoleDraft, AssociateRole, AttributeGroupDraft, AttributeGroup, BusinessUnitDraft, BusinessUnit, CartDraft, Cart, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CategoryDraft, Category, ChannelDraft, Channel, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerToken, CustomerGroupDraft, CustomerGroup, DiscountCodeDraft, DiscountCode, ExtensionDraft, Extension, InventoryEntryDraft, InventoryEntry, MyCustomerChangePassword, MyCustomerResetPassword, OrderFromCartDraft, Order, CartReference, OrderImportDraft, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, PaymentDraft, Payment, ProductDraft, Product, ProductDiscountDraft, ProductDiscount, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductTypeDraft, ProductType, QuoteDraft, Quote, QuoteRequestDraft, QuoteRequest, ReviewDraft, Review, ShippingMethodDraft, ShippingMethod, ZoneReference, ShoppingListDraft, ShoppingList, ShoppingListLineItem, StagedQuoteDraft, StagedQuote, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, StateDraft, State, StoreDraft, Store, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TypeDraft, Type, ZoneDraft, Zone } from '@commercetools/platform-sdk';
|
|
4
|
+
import { QueryParam, BaseResource, Project, UpdateAction, ResourceIdentifier, AssociateRoleDraft, AssociateRole, AttributeGroupDraft, AttributeGroup, BusinessUnitDraft, BusinessUnit, CartDraft, Cart, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CategoryDraft, Category, ChannelDraft, Channel, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerToken, CustomerGroupDraft, CustomerGroup, DiscountCodeDraft, DiscountCode, ExtensionDraft, Extension, InventoryEntryDraft, InventoryEntry, MyCustomerChangePassword, MyCustomerEmailVerify, MyCustomerResetPassword, OrderFromCartDraft, Order, CartReference, OrderImportDraft, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, PaymentDraft, Payment, ProductDraft, Product, ProductDiscountDraft, ProductDiscount, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductTypeDraft, ProductType, QuoteDraft, Quote, QuoteRequestDraft, QuoteRequest, ReviewDraft, Review, ShippingMethodDraft, ShippingMethod, ZoneReference, ShoppingListDraft, ShoppingList, ShoppingListLineItem, StagedQuoteDraft, StagedQuote, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, StateDraft, State, StoreDraft, Store, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TypeDraft, Type, ZoneDraft, Zone } from '@commercetools/platform-sdk';
|
|
5
5
|
|
|
6
6
|
type Token = {
|
|
7
7
|
access_token: string;
|
|
@@ -236,6 +236,7 @@ declare class CustomerRepository extends AbstractResourceRepository<"customer">
|
|
|
236
236
|
constructor(storage: AbstractStorage);
|
|
237
237
|
create(context: RepositoryContext, draft: CustomerDraft): Customer;
|
|
238
238
|
passwordResetToken(context: RepositoryContext, email: string): CustomerToken;
|
|
239
|
+
verifyEmailToken(context: RepositoryContext, id: string): CustomerToken;
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
declare class CustomerGroupRepository extends AbstractResourceRepository<"customer-group"> {
|
|
@@ -261,6 +262,7 @@ declare class InventoryEntryRepository extends AbstractResourceRepository<"inven
|
|
|
261
262
|
|
|
262
263
|
declare class MyCustomerRepository extends CustomerRepository {
|
|
263
264
|
changePassword(context: RepositoryContext, changePassword: MyCustomerChangePassword): Writable<Customer>;
|
|
265
|
+
confirmEmail(context: RepositoryContext, resetPassword: MyCustomerEmailVerify): Writable<Customer>;
|
|
264
266
|
deleteMe(context: RepositoryContext): Customer | undefined;
|
|
265
267
|
getMe(context: RepositoryContext): Customer | undefined;
|
|
266
268
|
resetPassword(context: RepositoryContext, resetPassword: MyCustomerResetPassword): Writable<Customer>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { SetupServerApi, SetupServer } from 'msw/node';
|
|
3
3
|
import * as ctp from '@commercetools/platform-sdk';
|
|
4
|
-
import { QueryParam, BaseResource, Project, UpdateAction, ResourceIdentifier, AssociateRoleDraft, AssociateRole, AttributeGroupDraft, AttributeGroup, BusinessUnitDraft, BusinessUnit, CartDraft, Cart, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CategoryDraft, Category, ChannelDraft, Channel, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerToken, CustomerGroupDraft, CustomerGroup, DiscountCodeDraft, DiscountCode, ExtensionDraft, Extension, InventoryEntryDraft, InventoryEntry, MyCustomerChangePassword, MyCustomerResetPassword, OrderFromCartDraft, Order, CartReference, OrderImportDraft, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, PaymentDraft, Payment, ProductDraft, Product, ProductDiscountDraft, ProductDiscount, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductTypeDraft, ProductType, QuoteDraft, Quote, QuoteRequestDraft, QuoteRequest, ReviewDraft, Review, ShippingMethodDraft, ShippingMethod, ZoneReference, ShoppingListDraft, ShoppingList, ShoppingListLineItem, StagedQuoteDraft, StagedQuote, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, StateDraft, State, StoreDraft, Store, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TypeDraft, Type, ZoneDraft, Zone } from '@commercetools/platform-sdk';
|
|
4
|
+
import { QueryParam, BaseResource, Project, UpdateAction, ResourceIdentifier, AssociateRoleDraft, AssociateRole, AttributeGroupDraft, AttributeGroup, BusinessUnitDraft, BusinessUnit, CartDraft, Cart, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CategoryDraft, Category, ChannelDraft, Channel, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerToken, CustomerGroupDraft, CustomerGroup, DiscountCodeDraft, DiscountCode, ExtensionDraft, Extension, InventoryEntryDraft, InventoryEntry, MyCustomerChangePassword, MyCustomerEmailVerify, MyCustomerResetPassword, OrderFromCartDraft, Order, CartReference, OrderImportDraft, MyOrderFromCartDraft, OrderEditDraft, OrderEdit, PaymentDraft, Payment, ProductDraft, Product, ProductDiscountDraft, ProductDiscount, ProductProjectionPagedSearchResponse, ProductProjection, FacetResults, TermFacetResult, FilteredFacetResult, RangeFacetResult, ProductSelectionDraft, ProductSelection, ProductTypeDraft, ProductType, QuoteDraft, Quote, QuoteRequestDraft, QuoteRequest, ReviewDraft, Review, ShippingMethodDraft, ShippingMethod, ZoneReference, ShoppingListDraft, ShoppingList, ShoppingListLineItem, StagedQuoteDraft, StagedQuote, StandalonePriceDraft, StandalonePrice, ChannelResourceIdentifier, ChannelReference, StateDraft, State, StoreDraft, Store, SubscriptionDraft, Subscription, TaxCategoryDraft, TaxCategory, TypeDraft, Type, ZoneDraft, Zone } from '@commercetools/platform-sdk';
|
|
5
5
|
|
|
6
6
|
type Token = {
|
|
7
7
|
access_token: string;
|
|
@@ -236,6 +236,7 @@ declare class CustomerRepository extends AbstractResourceRepository<"customer">
|
|
|
236
236
|
constructor(storage: AbstractStorage);
|
|
237
237
|
create(context: RepositoryContext, draft: CustomerDraft): Customer;
|
|
238
238
|
passwordResetToken(context: RepositoryContext, email: string): CustomerToken;
|
|
239
|
+
verifyEmailToken(context: RepositoryContext, id: string): CustomerToken;
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
declare class CustomerGroupRepository extends AbstractResourceRepository<"customer-group"> {
|
|
@@ -261,6 +262,7 @@ declare class InventoryEntryRepository extends AbstractResourceRepository<"inven
|
|
|
261
262
|
|
|
262
263
|
declare class MyCustomerRepository extends CustomerRepository {
|
|
263
264
|
changePassword(context: RepositoryContext, changePassword: MyCustomerChangePassword): Writable<Customer>;
|
|
265
|
+
confirmEmail(context: RepositoryContext, resetPassword: MyCustomerEmailVerify): Writable<Customer>;
|
|
264
266
|
deleteMe(context: RepositoryContext): Customer | undefined;
|
|
265
267
|
getMe(context: RepositoryContext): Customer | undefined;
|
|
266
268
|
resetPassword(context: RepositoryContext, resetPassword: MyCustomerResetPassword): Writable<Customer>;
|
package/dist/index.js
CHANGED
|
@@ -42,10 +42,14 @@ import express from "express";
|
|
|
42
42
|
// src/lib/password.ts
|
|
43
43
|
import { v4 as uuidv4 } from "uuid";
|
|
44
44
|
var PWRESET_SECRET = "pwreset";
|
|
45
|
+
var EMAIL_VERIFY_SECRET = "emailverifysecret";
|
|
45
46
|
var hashPassword = (clearPassword) => Buffer.from(clearPassword).toString("base64");
|
|
46
47
|
var createPasswordResetToken = (customer) => Buffer.from(`${customer.id}:${PWRESET_SECRET}:${uuidv4()}`).toString(
|
|
47
48
|
"base64"
|
|
48
49
|
);
|
|
50
|
+
var createEmailVerifyToken = (customer) => Buffer.from(`${customer.id}:${EMAIL_VERIFY_SECRET}:${uuidv4()}`).toString(
|
|
51
|
+
"base64"
|
|
52
|
+
);
|
|
49
53
|
var validatePasswordResetToken = (token) => {
|
|
50
54
|
const items = Buffer.from(token, "base64").toString("utf-8").split(":");
|
|
51
55
|
const [customerId, secret] = items;
|
|
@@ -54,6 +58,14 @@ var validatePasswordResetToken = (token) => {
|
|
|
54
58
|
}
|
|
55
59
|
return customerId;
|
|
56
60
|
};
|
|
61
|
+
var validateEmailVerifyToken = (token) => {
|
|
62
|
+
const items = Buffer.from(token, "base64").toString("utf-8").split(":");
|
|
63
|
+
const [customerId, secret] = items;
|
|
64
|
+
if (secret !== EMAIL_VERIFY_SECRET) {
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
return customerId;
|
|
68
|
+
};
|
|
57
69
|
|
|
58
70
|
// src/oauth/helpers.ts
|
|
59
71
|
var getBearerToken = (request) => {
|
|
@@ -3412,6 +3424,29 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3412
3424
|
value: token
|
|
3413
3425
|
};
|
|
3414
3426
|
}
|
|
3427
|
+
verifyEmailToken(context, id) {
|
|
3428
|
+
const results = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3429
|
+
where: [`id="${id.toLocaleLowerCase()}"`]
|
|
3430
|
+
});
|
|
3431
|
+
if (results.count === 0) {
|
|
3432
|
+
throw new CommercetoolsError({
|
|
3433
|
+
code: "ResourceNotFound",
|
|
3434
|
+
message: `The Customer with ID '${id}' was not found.`
|
|
3435
|
+
});
|
|
3436
|
+
}
|
|
3437
|
+
const expiresAt = new Date(Date.now() + 30 * 60);
|
|
3438
|
+
const customer = results.results[0];
|
|
3439
|
+
const rest = getBaseResourceProperties();
|
|
3440
|
+
const token = createEmailVerifyToken(customer);
|
|
3441
|
+
return {
|
|
3442
|
+
id: rest.id,
|
|
3443
|
+
createdAt: rest.createdAt,
|
|
3444
|
+
lastModifiedAt: rest.lastModifiedAt,
|
|
3445
|
+
customerId: customer.id,
|
|
3446
|
+
expiresAt: expiresAt.toISOString(),
|
|
3447
|
+
value: token
|
|
3448
|
+
};
|
|
3449
|
+
}
|
|
3415
3450
|
};
|
|
3416
3451
|
|
|
3417
3452
|
// src/repositories/customer-group.ts
|
|
@@ -3724,6 +3759,31 @@ var MyCustomerRepository = class extends CustomerRepository {
|
|
|
3724
3759
|
this._storage.add(context.projectKey, "customer", customer);
|
|
3725
3760
|
return customer;
|
|
3726
3761
|
}
|
|
3762
|
+
confirmEmail(context, resetPassword) {
|
|
3763
|
+
const { tokenValue } = resetPassword;
|
|
3764
|
+
const customerId = validateEmailVerifyToken(tokenValue);
|
|
3765
|
+
if (!customerId) {
|
|
3766
|
+
throw new CommercetoolsError({
|
|
3767
|
+
code: "ResourceNotFound",
|
|
3768
|
+
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3769
|
+
});
|
|
3770
|
+
}
|
|
3771
|
+
const customer = this._storage.get(
|
|
3772
|
+
context.projectKey,
|
|
3773
|
+
"customer",
|
|
3774
|
+
customerId
|
|
3775
|
+
);
|
|
3776
|
+
if (!customer) {
|
|
3777
|
+
throw new CommercetoolsError({
|
|
3778
|
+
code: "ResourceNotFound",
|
|
3779
|
+
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3780
|
+
});
|
|
3781
|
+
}
|
|
3782
|
+
customer.isEmailVerified = true;
|
|
3783
|
+
customer.version += 1;
|
|
3784
|
+
this._storage.add(context.projectKey, "customer", customer);
|
|
3785
|
+
return customer;
|
|
3786
|
+
}
|
|
3727
3787
|
deleteMe(context) {
|
|
3728
3788
|
const results = this._storage.query(
|
|
3729
3789
|
context.projectKey,
|
|
@@ -7434,6 +7494,14 @@ var CustomerService = class extends AbstractService {
|
|
|
7434
7494
|
);
|
|
7435
7495
|
return response.status(200).send(token);
|
|
7436
7496
|
});
|
|
7497
|
+
parent.post("/email-token", (request, response) => {
|
|
7498
|
+
const id = request.body.id;
|
|
7499
|
+
const token = this.repository.verifyEmailToken(
|
|
7500
|
+
getRepositoryContext(request),
|
|
7501
|
+
id
|
|
7502
|
+
);
|
|
7503
|
+
return response.status(200).send(token);
|
|
7504
|
+
});
|
|
7437
7505
|
}
|
|
7438
7506
|
};
|
|
7439
7507
|
|
|
@@ -7539,6 +7607,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7539
7607
|
router.post("/login", this.signIn.bind(this));
|
|
7540
7608
|
router.post("/password", this.changePassword.bind(this));
|
|
7541
7609
|
router.post("/password/reset", this.resetPassword.bind(this));
|
|
7610
|
+
router.post("/email/confirm", this.emailConfirm.bind(this));
|
|
7542
7611
|
parent.use(`/${basePath}`, router);
|
|
7543
7612
|
}
|
|
7544
7613
|
getMe(request, response) {
|
|
@@ -7596,6 +7665,13 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7596
7665
|
);
|
|
7597
7666
|
return response.status(200).send(customer);
|
|
7598
7667
|
}
|
|
7668
|
+
emailConfirm(request, response) {
|
|
7669
|
+
const customer = this.repository.confirmEmail(
|
|
7670
|
+
getRepositoryContext(request),
|
|
7671
|
+
request.body
|
|
7672
|
+
);
|
|
7673
|
+
return response.status(200).send(customer);
|
|
7674
|
+
}
|
|
7599
7675
|
signIn(request, response) {
|
|
7600
7676
|
const { email, password } = request.body;
|
|
7601
7677
|
const encodedPassword = hashPassword(password);
|