@labdigital/commercetools-mock 2.64.0 → 2.65.1
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 +45 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/repositories/customer/index.ts +35 -1
- package/src/repositories/order/actions.ts +49 -8
- package/src/services/customer.test.ts +50 -0
- package/src/services/customer.ts +12 -5
- package/src/services/order.test.ts +225 -2
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
|
@@ -1649,11 +1649,30 @@ var OrderUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
1649
1649
|
};
|
|
1650
1650
|
}
|
|
1651
1651
|
}
|
|
1652
|
+
addDelivery(context, resource, { action, items, ...deliveryDraft }) {
|
|
1653
|
+
if (!resource.shippingInfo) throw new Error("Resource has no shipping info");
|
|
1654
|
+
if (!items) throw new Error("Delivery items are required");
|
|
1655
|
+
if (!resource.shippingInfo.deliveries) resource.shippingInfo.deliveries = [];
|
|
1656
|
+
const parcels = deliveryDraft.parcels?.map((p) => ({
|
|
1657
|
+
...getBaseResourceProperties(),
|
|
1658
|
+
...p,
|
|
1659
|
+
custom: createCustomFields(p.custom, context.projectKey, this._storage)
|
|
1660
|
+
})) ?? [];
|
|
1661
|
+
const delivery = {
|
|
1662
|
+
...getBaseResourceProperties(),
|
|
1663
|
+
...deliveryDraft,
|
|
1664
|
+
parcels,
|
|
1665
|
+
items,
|
|
1666
|
+
address: createAddress(deliveryDraft.address, context.projectKey, this._storage),
|
|
1667
|
+
custom: createCustomFields(deliveryDraft.custom, context.projectKey, this._storage)
|
|
1668
|
+
};
|
|
1669
|
+
resource.shippingInfo.deliveries.push(delivery);
|
|
1670
|
+
}
|
|
1652
1671
|
setDeliveryCustomField(context, resource, { deliveryId, name, value }) {
|
|
1653
1672
|
if (!resource.shippingInfo) throw new Error("Resource has no shipping info");
|
|
1654
1673
|
for (const delivery of resource.shippingInfo.deliveries || []) if (delivery.id === deliveryId && delivery.custom?.fields) delivery.custom.fields[name] = value;
|
|
1655
1674
|
}
|
|
1656
|
-
setLineItemCustomField(context, resource, { lineItemId, lineItemKey, name, value
|
|
1675
|
+
setLineItemCustomField(context, resource, { lineItemId, lineItemKey, name, value }) {
|
|
1657
1676
|
const lineItem = resource.lineItems.find((x) => lineItemId && x.id === lineItemId || lineItemKey && x.key === lineItemKey);
|
|
1658
1677
|
if (!lineItem) throw new CommercetoolsError({
|
|
1659
1678
|
code: "General",
|
|
@@ -3195,7 +3214,7 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3195
3214
|
this._storage.add(context.projectKey, "customer", customer);
|
|
3196
3215
|
return customer;
|
|
3197
3216
|
}
|
|
3198
|
-
|
|
3217
|
+
emailToken(context, id) {
|
|
3199
3218
|
const results = this._storage.query(context.projectKey, this.getTypeId(), { where: [`id="${id.toLocaleLowerCase()}"`] });
|
|
3200
3219
|
if (results.count === 0) throw new CommercetoolsError({
|
|
3201
3220
|
code: "ResourceNotFound",
|
|
@@ -3215,6 +3234,22 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3215
3234
|
invalidateOlderTokens: false
|
|
3216
3235
|
};
|
|
3217
3236
|
}
|
|
3237
|
+
emailTokenConfirm(context, request) {
|
|
3238
|
+
const customerId = validateEmailVerifyToken(request.tokenValue);
|
|
3239
|
+
if (!customerId) throw new CommercetoolsError({
|
|
3240
|
+
code: "ResourceNotFound",
|
|
3241
|
+
message: `The Customer with ID 'Token(${request.tokenValue})' was not found.`
|
|
3242
|
+
});
|
|
3243
|
+
const customer = this._storage.get(context.projectKey, "customer", customerId);
|
|
3244
|
+
if (!customer) throw new CommercetoolsError({
|
|
3245
|
+
code: "ResourceNotFound",
|
|
3246
|
+
message: `The Customer with ID 'Token(${request.tokenValue})' was not found.`
|
|
3247
|
+
});
|
|
3248
|
+
customer.isEmailVerified = true;
|
|
3249
|
+
customer.version += 1;
|
|
3250
|
+
this._storage.add(context.projectKey, "customer", customer);
|
|
3251
|
+
return customer;
|
|
3252
|
+
}
|
|
3218
3253
|
storeReferenceToStoreKeyReference(draftStores, projectKey) {
|
|
3219
3254
|
const storeIds = draftStores.map((storeReference) => storeReference.id).filter(Boolean);
|
|
3220
3255
|
let stores = [];
|
|
@@ -7351,7 +7386,8 @@ var CustomerService = class extends AbstractService {
|
|
|
7351
7386
|
extraRoutes(parent) {
|
|
7352
7387
|
parent.post("/password-token", this.passwordResetToken.bind(this));
|
|
7353
7388
|
parent.post("/password/reset", this.passwordReset.bind(this));
|
|
7354
|
-
parent.post("/email-token", this.
|
|
7389
|
+
parent.post("/email-token", this.emailToken.bind(this));
|
|
7390
|
+
parent.post("/email/confirm", this.emailTokenConfirm.bind(this));
|
|
7355
7391
|
}
|
|
7356
7392
|
post(request, response) {
|
|
7357
7393
|
const draft = request.body;
|
|
@@ -7367,11 +7403,15 @@ var CustomerService = class extends AbstractService {
|
|
|
7367
7403
|
const customer = this.repository.passwordReset(getRepositoryContext(request), request.body);
|
|
7368
7404
|
response.status(200).send(customer);
|
|
7369
7405
|
}
|
|
7370
|
-
|
|
7406
|
+
emailToken(request, response) {
|
|
7371
7407
|
const id = request.body.id;
|
|
7372
|
-
const token = this.repository.
|
|
7408
|
+
const token = this.repository.emailToken(getRepositoryContext(request), id);
|
|
7373
7409
|
response.status(200).send(token);
|
|
7374
7410
|
}
|
|
7411
|
+
emailTokenConfirm(request, response) {
|
|
7412
|
+
const customer = this.repository.emailTokenConfirm(getRepositoryContext(request), request.body);
|
|
7413
|
+
response.status(200).send(customer);
|
|
7414
|
+
}
|
|
7375
7415
|
};
|
|
7376
7416
|
|
|
7377
7417
|
//#endregion
|