@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.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) => {
|
|
@@ -3228,7 +3240,11 @@ var CustomObjectRepository = class extends AbstractResourceRepository {
|
|
|
3228
3240
|
...params,
|
|
3229
3241
|
where: whereClause
|
|
3230
3242
|
});
|
|
3231
|
-
result.results = result.results.map(
|
|
3243
|
+
result.results = result.results.map(
|
|
3244
|
+
(r) => this.postProcessResource(context, r, {
|
|
3245
|
+
expand: params.expand
|
|
3246
|
+
})
|
|
3247
|
+
);
|
|
3232
3248
|
return result;
|
|
3233
3249
|
}
|
|
3234
3250
|
};
|
|
@@ -3408,6 +3424,29 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3408
3424
|
value: token
|
|
3409
3425
|
};
|
|
3410
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
|
+
}
|
|
3411
3450
|
};
|
|
3412
3451
|
|
|
3413
3452
|
// src/repositories/customer-group.ts
|
|
@@ -3720,6 +3759,31 @@ var MyCustomerRepository = class extends CustomerRepository {
|
|
|
3720
3759
|
this._storage.add(context.projectKey, "customer", customer);
|
|
3721
3760
|
return customer;
|
|
3722
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
|
+
}
|
|
3723
3787
|
deleteMe(context) {
|
|
3724
3788
|
const results = this._storage.query(
|
|
3725
3789
|
context.projectKey,
|
|
@@ -7430,6 +7494,14 @@ var CustomerService = class extends AbstractService {
|
|
|
7430
7494
|
);
|
|
7431
7495
|
return response.status(200).send(token);
|
|
7432
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
|
+
});
|
|
7433
7505
|
}
|
|
7434
7506
|
};
|
|
7435
7507
|
|
|
@@ -7535,6 +7607,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7535
7607
|
router.post("/login", this.signIn.bind(this));
|
|
7536
7608
|
router.post("/password", this.changePassword.bind(this));
|
|
7537
7609
|
router.post("/password/reset", this.resetPassword.bind(this));
|
|
7610
|
+
router.post("/email/confirm", this.emailConfirm.bind(this));
|
|
7538
7611
|
parent.use(`/${basePath}`, router);
|
|
7539
7612
|
}
|
|
7540
7613
|
getMe(request, response) {
|
|
@@ -7592,6 +7665,13 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7592
7665
|
);
|
|
7593
7666
|
return response.status(200).send(customer);
|
|
7594
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
|
+
}
|
|
7595
7675
|
signIn(request, response) {
|
|
7596
7676
|
const { email, password } = request.body;
|
|
7597
7677
|
const encodedPassword = hashPassword(password);
|