@labdigital/commercetools-mock 2.64.0 → 2.65.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.mts +244 -1
- package/dist/index.mjs +25 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/repositories/customer/index.ts +35 -1
- package/src/services/customer.test.ts +50 -0
- package/src/services/customer.ts +12 -5
package/dist/index.d.mts
CHANGED
|
@@ -430,7 +430,250 @@ declare class CustomerRepository extends AbstractResourceRepository<"customer">
|
|
|
430
430
|
stores: WritableArray<StoreKeyReference>;
|
|
431
431
|
authenticationMode: _commercetools_platform_sdk0.AuthenticationMode;
|
|
432
432
|
};
|
|
433
|
-
|
|
433
|
+
emailToken(context: RepositoryContext, id: string): CustomerToken;
|
|
434
|
+
emailTokenConfirm(context: RepositoryContext, request: {
|
|
435
|
+
tokenValue: string;
|
|
436
|
+
}): {
|
|
437
|
+
id: string;
|
|
438
|
+
version: number;
|
|
439
|
+
key?: string | undefined;
|
|
440
|
+
customerNumber?: string | undefined;
|
|
441
|
+
externalId?: string | undefined;
|
|
442
|
+
createdAt: string;
|
|
443
|
+
lastModifiedAt: string;
|
|
444
|
+
lastModifiedBy?: {
|
|
445
|
+
clientId?: string | undefined;
|
|
446
|
+
externalUserId?: string | undefined;
|
|
447
|
+
customer?: {
|
|
448
|
+
typeId: "customer";
|
|
449
|
+
id: string;
|
|
450
|
+
obj?: /*elided*/any | undefined;
|
|
451
|
+
} | undefined;
|
|
452
|
+
anonymousId?: string | undefined;
|
|
453
|
+
attributedTo?: {
|
|
454
|
+
clientId?: string | undefined;
|
|
455
|
+
source: _commercetools_platform_sdk0.AttributionSource;
|
|
456
|
+
} | undefined;
|
|
457
|
+
associate?: {
|
|
458
|
+
typeId: "customer";
|
|
459
|
+
id: string;
|
|
460
|
+
obj?: /*elided*/any | undefined;
|
|
461
|
+
} | undefined;
|
|
462
|
+
} | undefined;
|
|
463
|
+
createdBy?: {
|
|
464
|
+
clientId?: string | undefined;
|
|
465
|
+
externalUserId?: string | undefined;
|
|
466
|
+
customer?: {
|
|
467
|
+
typeId: "customer";
|
|
468
|
+
id: string;
|
|
469
|
+
obj?: /*elided*/any | undefined;
|
|
470
|
+
} | undefined;
|
|
471
|
+
anonymousId?: string | undefined;
|
|
472
|
+
attributedTo?: {
|
|
473
|
+
clientId?: string | undefined;
|
|
474
|
+
source: _commercetools_platform_sdk0.AttributionSource;
|
|
475
|
+
} | undefined;
|
|
476
|
+
associate?: {
|
|
477
|
+
typeId: "customer";
|
|
478
|
+
id: string;
|
|
479
|
+
obj?: /*elided*/any | undefined;
|
|
480
|
+
} | undefined;
|
|
481
|
+
} | undefined;
|
|
482
|
+
email: string;
|
|
483
|
+
password?: string | undefined;
|
|
484
|
+
firstName?: string | undefined;
|
|
485
|
+
lastName?: string | undefined;
|
|
486
|
+
middleName?: string | undefined;
|
|
487
|
+
title?: string | undefined;
|
|
488
|
+
dateOfBirth?: string | undefined;
|
|
489
|
+
companyName?: string | undefined;
|
|
490
|
+
vatId?: string | undefined;
|
|
491
|
+
addresses: WritableArray<Address>;
|
|
492
|
+
defaultShippingAddressId?: string | undefined;
|
|
493
|
+
shippingAddressIds?: WritableArray<string> | undefined;
|
|
494
|
+
defaultBillingAddressId?: string | undefined;
|
|
495
|
+
billingAddressIds?: WritableArray<string> | undefined;
|
|
496
|
+
isEmailVerified: boolean;
|
|
497
|
+
customerGroup?: {
|
|
498
|
+
typeId: "customer-group";
|
|
499
|
+
id: string;
|
|
500
|
+
obj?: {
|
|
501
|
+
id: string;
|
|
502
|
+
version: number;
|
|
503
|
+
createdAt: string;
|
|
504
|
+
lastModifiedAt: string;
|
|
505
|
+
lastModifiedBy?: {
|
|
506
|
+
clientId?: string | undefined;
|
|
507
|
+
externalUserId?: string | undefined;
|
|
508
|
+
customer?: {
|
|
509
|
+
typeId: "customer";
|
|
510
|
+
id: string;
|
|
511
|
+
obj?: /*elided*/any | undefined;
|
|
512
|
+
} | undefined;
|
|
513
|
+
anonymousId?: string | undefined;
|
|
514
|
+
attributedTo?: {
|
|
515
|
+
clientId?: string | undefined;
|
|
516
|
+
source: _commercetools_platform_sdk0.AttributionSource;
|
|
517
|
+
} | undefined;
|
|
518
|
+
associate?: {
|
|
519
|
+
typeId: "customer";
|
|
520
|
+
id: string;
|
|
521
|
+
obj?: /*elided*/any | undefined;
|
|
522
|
+
} | undefined;
|
|
523
|
+
} | undefined;
|
|
524
|
+
createdBy?: {
|
|
525
|
+
clientId?: string | undefined;
|
|
526
|
+
externalUserId?: string | undefined;
|
|
527
|
+
customer?: {
|
|
528
|
+
typeId: "customer";
|
|
529
|
+
id: string;
|
|
530
|
+
obj?: /*elided*/any | undefined;
|
|
531
|
+
} | undefined;
|
|
532
|
+
anonymousId?: string | undefined;
|
|
533
|
+
attributedTo?: {
|
|
534
|
+
clientId?: string | undefined;
|
|
535
|
+
source: _commercetools_platform_sdk0.AttributionSource;
|
|
536
|
+
} | undefined;
|
|
537
|
+
associate?: {
|
|
538
|
+
typeId: "customer";
|
|
539
|
+
id: string;
|
|
540
|
+
obj?: /*elided*/any | undefined;
|
|
541
|
+
} | undefined;
|
|
542
|
+
} | undefined;
|
|
543
|
+
key?: string | undefined;
|
|
544
|
+
name: string;
|
|
545
|
+
custom?: {
|
|
546
|
+
type: {
|
|
547
|
+
typeId: "type";
|
|
548
|
+
id: string;
|
|
549
|
+
obj?: {
|
|
550
|
+
id: string;
|
|
551
|
+
version: number;
|
|
552
|
+
createdAt: string;
|
|
553
|
+
lastModifiedAt: string;
|
|
554
|
+
lastModifiedBy?: {
|
|
555
|
+
clientId?: string | undefined;
|
|
556
|
+
externalUserId?: string | undefined;
|
|
557
|
+
customer?: {
|
|
558
|
+
typeId: "customer";
|
|
559
|
+
id: string;
|
|
560
|
+
obj?: /*elided*/any | undefined;
|
|
561
|
+
} | undefined;
|
|
562
|
+
anonymousId?: string | undefined;
|
|
563
|
+
attributedTo?: {
|
|
564
|
+
clientId?: string | undefined;
|
|
565
|
+
source: _commercetools_platform_sdk0.AttributionSource;
|
|
566
|
+
} | undefined;
|
|
567
|
+
associate?: {
|
|
568
|
+
typeId: "customer";
|
|
569
|
+
id: string;
|
|
570
|
+
obj?: /*elided*/any | undefined;
|
|
571
|
+
} | undefined;
|
|
572
|
+
} | undefined;
|
|
573
|
+
createdBy?: {
|
|
574
|
+
clientId?: string | undefined;
|
|
575
|
+
externalUserId?: string | undefined;
|
|
576
|
+
customer?: {
|
|
577
|
+
typeId: "customer";
|
|
578
|
+
id: string;
|
|
579
|
+
obj?: /*elided*/any | undefined;
|
|
580
|
+
} | undefined;
|
|
581
|
+
anonymousId?: string | undefined;
|
|
582
|
+
attributedTo?: {
|
|
583
|
+
clientId?: string | undefined;
|
|
584
|
+
source: _commercetools_platform_sdk0.AttributionSource;
|
|
585
|
+
} | undefined;
|
|
586
|
+
associate?: {
|
|
587
|
+
typeId: "customer";
|
|
588
|
+
id: string;
|
|
589
|
+
obj?: /*elided*/any | undefined;
|
|
590
|
+
} | undefined;
|
|
591
|
+
} | undefined;
|
|
592
|
+
key: string;
|
|
593
|
+
name: {
|
|
594
|
+
[x: string]: string;
|
|
595
|
+
};
|
|
596
|
+
description?: {
|
|
597
|
+
[x: string]: string;
|
|
598
|
+
} | undefined;
|
|
599
|
+
resourceTypeIds: WritableArray<_commercetools_platform_sdk0.ResourceTypeId>;
|
|
600
|
+
fieldDefinitions: WritableArray<_commercetools_platform_sdk0.FieldDefinition>;
|
|
601
|
+
} | undefined;
|
|
602
|
+
};
|
|
603
|
+
fields: {
|
|
604
|
+
[x: string]: any;
|
|
605
|
+
};
|
|
606
|
+
} | undefined;
|
|
607
|
+
} | undefined;
|
|
608
|
+
} | undefined;
|
|
609
|
+
customerGroupAssignments?: WritableArray<_commercetools_platform_sdk0.CustomerGroupAssignment> | undefined;
|
|
610
|
+
custom?: {
|
|
611
|
+
type: {
|
|
612
|
+
typeId: "type";
|
|
613
|
+
id: string;
|
|
614
|
+
obj?: {
|
|
615
|
+
id: string;
|
|
616
|
+
version: number;
|
|
617
|
+
createdAt: string;
|
|
618
|
+
lastModifiedAt: string;
|
|
619
|
+
lastModifiedBy?: {
|
|
620
|
+
clientId?: string | undefined;
|
|
621
|
+
externalUserId?: string | undefined;
|
|
622
|
+
customer?: {
|
|
623
|
+
typeId: "customer";
|
|
624
|
+
id: string;
|
|
625
|
+
obj?: /*elided*/any | undefined;
|
|
626
|
+
} | undefined;
|
|
627
|
+
anonymousId?: string | undefined;
|
|
628
|
+
attributedTo?: {
|
|
629
|
+
clientId?: string | undefined;
|
|
630
|
+
source: _commercetools_platform_sdk0.AttributionSource;
|
|
631
|
+
} | undefined;
|
|
632
|
+
associate?: {
|
|
633
|
+
typeId: "customer";
|
|
634
|
+
id: string;
|
|
635
|
+
obj?: /*elided*/any | undefined;
|
|
636
|
+
} | undefined;
|
|
637
|
+
} | undefined;
|
|
638
|
+
createdBy?: {
|
|
639
|
+
clientId?: string | undefined;
|
|
640
|
+
externalUserId?: string | undefined;
|
|
641
|
+
customer?: {
|
|
642
|
+
typeId: "customer";
|
|
643
|
+
id: string;
|
|
644
|
+
obj?: /*elided*/any | undefined;
|
|
645
|
+
} | undefined;
|
|
646
|
+
anonymousId?: string | undefined;
|
|
647
|
+
attributedTo?: {
|
|
648
|
+
clientId?: string | undefined;
|
|
649
|
+
source: _commercetools_platform_sdk0.AttributionSource;
|
|
650
|
+
} | undefined;
|
|
651
|
+
associate?: {
|
|
652
|
+
typeId: "customer";
|
|
653
|
+
id: string;
|
|
654
|
+
obj?: /*elided*/any | undefined;
|
|
655
|
+
} | undefined;
|
|
656
|
+
} | undefined;
|
|
657
|
+
key: string;
|
|
658
|
+
name: {
|
|
659
|
+
[x: string]: string;
|
|
660
|
+
};
|
|
661
|
+
description?: {
|
|
662
|
+
[x: string]: string;
|
|
663
|
+
} | undefined;
|
|
664
|
+
resourceTypeIds: WritableArray<_commercetools_platform_sdk0.ResourceTypeId>;
|
|
665
|
+
fieldDefinitions: WritableArray<_commercetools_platform_sdk0.FieldDefinition>;
|
|
666
|
+
} | undefined;
|
|
667
|
+
};
|
|
668
|
+
fields: {
|
|
669
|
+
[x: string]: any;
|
|
670
|
+
};
|
|
671
|
+
} | undefined;
|
|
672
|
+
locale?: string | undefined;
|
|
673
|
+
salutation?: string | undefined;
|
|
674
|
+
stores: WritableArray<StoreKeyReference>;
|
|
675
|
+
authenticationMode: _commercetools_platform_sdk0.AuthenticationMode;
|
|
676
|
+
};
|
|
434
677
|
private storeReferenceToStoreKeyReference;
|
|
435
678
|
}
|
|
436
679
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -3195,7 +3195,7 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3195
3195
|
this._storage.add(context.projectKey, "customer", customer);
|
|
3196
3196
|
return customer;
|
|
3197
3197
|
}
|
|
3198
|
-
|
|
3198
|
+
emailToken(context, id) {
|
|
3199
3199
|
const results = this._storage.query(context.projectKey, this.getTypeId(), { where: [`id="${id.toLocaleLowerCase()}"`] });
|
|
3200
3200
|
if (results.count === 0) throw new CommercetoolsError({
|
|
3201
3201
|
code: "ResourceNotFound",
|
|
@@ -3215,6 +3215,22 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3215
3215
|
invalidateOlderTokens: false
|
|
3216
3216
|
};
|
|
3217
3217
|
}
|
|
3218
|
+
emailTokenConfirm(context, request) {
|
|
3219
|
+
const customerId = validateEmailVerifyToken(request.tokenValue);
|
|
3220
|
+
if (!customerId) throw new CommercetoolsError({
|
|
3221
|
+
code: "ResourceNotFound",
|
|
3222
|
+
message: `The Customer with ID 'Token(${request.tokenValue})' was not found.`
|
|
3223
|
+
});
|
|
3224
|
+
const customer = this._storage.get(context.projectKey, "customer", customerId);
|
|
3225
|
+
if (!customer) throw new CommercetoolsError({
|
|
3226
|
+
code: "ResourceNotFound",
|
|
3227
|
+
message: `The Customer with ID 'Token(${request.tokenValue})' was not found.`
|
|
3228
|
+
});
|
|
3229
|
+
customer.isEmailVerified = true;
|
|
3230
|
+
customer.version += 1;
|
|
3231
|
+
this._storage.add(context.projectKey, "customer", customer);
|
|
3232
|
+
return customer;
|
|
3233
|
+
}
|
|
3218
3234
|
storeReferenceToStoreKeyReference(draftStores, projectKey) {
|
|
3219
3235
|
const storeIds = draftStores.map((storeReference) => storeReference.id).filter(Boolean);
|
|
3220
3236
|
let stores = [];
|
|
@@ -7351,7 +7367,8 @@ var CustomerService = class extends AbstractService {
|
|
|
7351
7367
|
extraRoutes(parent) {
|
|
7352
7368
|
parent.post("/password-token", this.passwordResetToken.bind(this));
|
|
7353
7369
|
parent.post("/password/reset", this.passwordReset.bind(this));
|
|
7354
|
-
parent.post("/email-token", this.
|
|
7370
|
+
parent.post("/email-token", this.emailToken.bind(this));
|
|
7371
|
+
parent.post("/email/confirm", this.emailTokenConfirm.bind(this));
|
|
7355
7372
|
}
|
|
7356
7373
|
post(request, response) {
|
|
7357
7374
|
const draft = request.body;
|
|
@@ -7367,11 +7384,15 @@ var CustomerService = class extends AbstractService {
|
|
|
7367
7384
|
const customer = this.repository.passwordReset(getRepositoryContext(request), request.body);
|
|
7368
7385
|
response.status(200).send(customer);
|
|
7369
7386
|
}
|
|
7370
|
-
|
|
7387
|
+
emailToken(request, response) {
|
|
7371
7388
|
const id = request.body.id;
|
|
7372
|
-
const token = this.repository.
|
|
7389
|
+
const token = this.repository.emailToken(getRepositoryContext(request), id);
|
|
7373
7390
|
response.status(200).send(token);
|
|
7374
7391
|
}
|
|
7392
|
+
emailTokenConfirm(request, response) {
|
|
7393
|
+
const customer = this.repository.emailTokenConfirm(getRepositoryContext(request), request.body);
|
|
7394
|
+
response.status(200).send(customer);
|
|
7395
|
+
}
|
|
7375
7396
|
};
|
|
7376
7397
|
|
|
7377
7398
|
//#endregion
|