@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.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) => {
@@ -3315,6 +3327,9 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
3315
3327
  }
3316
3328
  resource.custom.fields[name] = value;
3317
3329
  }
3330
+ setExternalId(_context, resource, { externalId }) {
3331
+ resource.externalId = externalId;
3332
+ }
3318
3333
  setFirstName(_context, resource, { firstName }) {
3319
3334
  resource.firstName = firstName;
3320
3335
  }
@@ -3324,6 +3339,9 @@ var CustomerUpdateHandler = class extends AbstractUpdateHandler {
3324
3339
  setLastName(_context, resource, { lastName }) {
3325
3340
  resource.lastName = lastName;
3326
3341
  }
3342
+ setLocale(_context, resource, { locale }) {
3343
+ resource.locale = locale;
3344
+ }
3327
3345
  setSalutation(_context, resource, { salutation }) {
3328
3346
  resource.salutation = salutation;
3329
3347
  }
@@ -3412,6 +3430,29 @@ var CustomerRepository = class extends AbstractResourceRepository {
3412
3430
  value: token
3413
3431
  };
3414
3432
  }
3433
+ verifyEmailToken(context, id) {
3434
+ const results = this._storage.query(context.projectKey, this.getTypeId(), {
3435
+ where: [`id="${id.toLocaleLowerCase()}"`]
3436
+ });
3437
+ if (results.count === 0) {
3438
+ throw new CommercetoolsError({
3439
+ code: "ResourceNotFound",
3440
+ message: `The Customer with ID '${id}' was not found.`
3441
+ });
3442
+ }
3443
+ const expiresAt = new Date(Date.now() + 30 * 60);
3444
+ const customer = results.results[0];
3445
+ const rest = getBaseResourceProperties();
3446
+ const token = createEmailVerifyToken(customer);
3447
+ return {
3448
+ id: rest.id,
3449
+ createdAt: rest.createdAt,
3450
+ lastModifiedAt: rest.lastModifiedAt,
3451
+ customerId: customer.id,
3452
+ expiresAt: expiresAt.toISOString(),
3453
+ value: token
3454
+ };
3455
+ }
3415
3456
  };
3416
3457
 
3417
3458
  // src/repositories/customer-group.ts
@@ -3724,6 +3765,31 @@ var MyCustomerRepository = class extends CustomerRepository {
3724
3765
  this._storage.add(context.projectKey, "customer", customer);
3725
3766
  return customer;
3726
3767
  }
3768
+ confirmEmail(context, resetPassword) {
3769
+ const { tokenValue } = resetPassword;
3770
+ const customerId = validateEmailVerifyToken(tokenValue);
3771
+ if (!customerId) {
3772
+ throw new CommercetoolsError({
3773
+ code: "ResourceNotFound",
3774
+ message: `The Customer with ID 'Token(${tokenValue})' was not found.`
3775
+ });
3776
+ }
3777
+ const customer = this._storage.get(
3778
+ context.projectKey,
3779
+ "customer",
3780
+ customerId
3781
+ );
3782
+ if (!customer) {
3783
+ throw new CommercetoolsError({
3784
+ code: "ResourceNotFound",
3785
+ message: `The Customer with ID 'Token(${tokenValue})' was not found.`
3786
+ });
3787
+ }
3788
+ customer.isEmailVerified = true;
3789
+ customer.version += 1;
3790
+ this._storage.add(context.projectKey, "customer", customer);
3791
+ return customer;
3792
+ }
3727
3793
  deleteMe(context) {
3728
3794
  const results = this._storage.query(
3729
3795
  context.projectKey,
@@ -7434,6 +7500,14 @@ var CustomerService = class extends AbstractService {
7434
7500
  );
7435
7501
  return response.status(200).send(token);
7436
7502
  });
7503
+ parent.post("/email-token", (request, response) => {
7504
+ const id = request.body.id;
7505
+ const token = this.repository.verifyEmailToken(
7506
+ getRepositoryContext(request),
7507
+ id
7508
+ );
7509
+ return response.status(200).send(token);
7510
+ });
7437
7511
  }
7438
7512
  };
7439
7513
 
@@ -7539,6 +7613,7 @@ var MyCustomerService = class extends AbstractService {
7539
7613
  router.post("/login", this.signIn.bind(this));
7540
7614
  router.post("/password", this.changePassword.bind(this));
7541
7615
  router.post("/password/reset", this.resetPassword.bind(this));
7616
+ router.post("/email/confirm", this.emailConfirm.bind(this));
7542
7617
  parent.use(`/${basePath}`, router);
7543
7618
  }
7544
7619
  getMe(request, response) {
@@ -7596,6 +7671,13 @@ var MyCustomerService = class extends AbstractService {
7596
7671
  );
7597
7672
  return response.status(200).send(customer);
7598
7673
  }
7674
+ emailConfirm(request, response) {
7675
+ const customer = this.repository.confirmEmail(
7676
+ getRepositoryContext(request),
7677
+ request.body
7678
+ );
7679
+ return response.status(200).send(customer);
7680
+ }
7599
7681
  signIn(request, response) {
7600
7682
  const { email, password } = request.body;
7601
7683
  const encodedPassword = hashPassword(password);