@labdigital/commercetools-mock 2.26.1 → 2.28.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 +116 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +116 -63
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/password.ts +12 -5
- package/src/oauth/server.test.ts +1 -0
- package/src/repositories/business-unit.ts +40 -8
- package/src/repositories/cart/actions.ts +8 -4
- package/src/repositories/customer/index.ts +53 -5
- package/src/repositories/helpers.ts +1 -2
- package/src/repositories/index.ts +2 -0
- package/src/repositories/my-customer.ts +1 -41
- package/src/repositories/product-tailoring.ts +34 -0
- package/src/repositories/shipping-method/actions.ts +10 -1
- package/src/repositories/shipping-method/index.ts +1 -0
- package/src/services/customer.test.ts +64 -2
- package/src/services/customer.ts +31 -18
- package/src/services/my-customer.test.ts +11 -3
- package/src/services/my-customer.ts +1 -1
- package/src/services/shipping-method.test.ts +1 -0
- package/src/storage/in-memory.ts +2 -0
- package/src/types.ts +2 -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, MyCustomerEmailVerify,
|
|
4
|
+
import { QueryParam, BaseResource, Project, UpdateAction, ResourceIdentifier, ProductTailoring, AssociateRoleDraft, AssociateRole, AttributeGroupDraft, AttributeGroup, BusinessUnitDraft, BusinessUnit, CartDraft, Cart, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CategoryDraft, Category, ChannelDraft, Channel, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerCreatePasswordResetToken, CustomerToken, CustomerResetPassword, MyCustomerResetPassword, CustomerGroupDraft, CustomerGroup, DiscountCodeDraft, DiscountCode, ExtensionDraft, Extension, InventoryEntryDraft, InventoryEntry, MyCustomerChangePassword, MyCustomerEmailVerify, 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;
|
|
@@ -101,6 +101,7 @@ type ResourceMap = {
|
|
|
101
101
|
"product-price": ctp.StandalonePrice;
|
|
102
102
|
"product-projection": ctp.ProductProjection;
|
|
103
103
|
"product-selection": ctp.ProductSelection;
|
|
104
|
+
"product-tailoring": ctp.ProductTailoring;
|
|
104
105
|
"product-type": ctp.ProductType;
|
|
105
106
|
"product": ctp.Product;
|
|
106
107
|
"quote-request": ctp.QuoteRequest;
|
|
@@ -140,6 +141,7 @@ type PagedQueryResponseMap = {
|
|
|
140
141
|
"product-price": ctp.StandalonePricePagedQueryResponse;
|
|
141
142
|
"product-projection": ctp.ProductProjectionPagedQueryResponse;
|
|
142
143
|
"product-selection": ctp.ProductSelectionPagedQueryResponse;
|
|
144
|
+
"product-tailoring": ctp.ProductTailoringPagedQueryResponse;
|
|
143
145
|
"product-type": ctp.ProductTypePagedQueryResponse;
|
|
144
146
|
"product": ctp.ProductPagedQueryResponse;
|
|
145
147
|
"quote-request": ctp.QuoteRequestPagedQueryResponse;
|
|
@@ -184,6 +186,11 @@ declare abstract class AbstractStorage {
|
|
|
184
186
|
abstract expand<T>(projectKey: string, obj: T, clause: undefined | string | string[]): T;
|
|
185
187
|
}
|
|
186
188
|
|
|
189
|
+
declare class ProductTailoringRepository extends AbstractResourceRepository<"product-tailoring"> {
|
|
190
|
+
constructor(storage: AbstractStorage);
|
|
191
|
+
create(context: RepositoryContext, draft: any): ProductTailoring;
|
|
192
|
+
}
|
|
193
|
+
|
|
187
194
|
declare class AssociateRoleRepository extends AbstractResourceRepository<"associate-role"> {
|
|
188
195
|
constructor(storage: AbstractStorage);
|
|
189
196
|
create(context: RepositoryContext, draft: AssociateRoleDraft): AssociateRole;
|
|
@@ -235,7 +242,8 @@ declare class CustomObjectRepository extends AbstractResourceRepository<"key-val
|
|
|
235
242
|
declare class CustomerRepository extends AbstractResourceRepository<"customer"> {
|
|
236
243
|
constructor(storage: AbstractStorage);
|
|
237
244
|
create(context: RepositoryContext, draft: CustomerDraft): Customer;
|
|
238
|
-
passwordResetToken(context: RepositoryContext,
|
|
245
|
+
passwordResetToken(context: RepositoryContext, request: CustomerCreatePasswordResetToken): CustomerToken;
|
|
246
|
+
passwordReset(context: RepositoryContext, resetPassword: CustomerResetPassword | MyCustomerResetPassword): Writable<Customer>;
|
|
239
247
|
verifyEmailToken(context: RepositoryContext, id: string): CustomerToken;
|
|
240
248
|
}
|
|
241
249
|
|
|
@@ -265,7 +273,6 @@ declare class MyCustomerRepository extends CustomerRepository {
|
|
|
265
273
|
confirmEmail(context: RepositoryContext, resetPassword: MyCustomerEmailVerify): Writable<Customer>;
|
|
266
274
|
deleteMe(context: RepositoryContext): Customer | undefined;
|
|
267
275
|
getMe(context: RepositoryContext): Customer | undefined;
|
|
268
|
-
resetPassword(context: RepositoryContext, resetPassword: MyCustomerResetPassword): Writable<Customer>;
|
|
269
276
|
}
|
|
270
277
|
|
|
271
278
|
declare class OrderRepository extends AbstractResourceRepository<"order"> {
|
|
@@ -440,6 +447,7 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<"shipp
|
|
|
440
447
|
description?: string | undefined;
|
|
441
448
|
localizedDescription?: ctp.LocalizedString | undefined;
|
|
442
449
|
taxCategory: ctp.TaxCategoryReference;
|
|
450
|
+
active: boolean;
|
|
443
451
|
isDefault: boolean;
|
|
444
452
|
predicate?: string | undefined;
|
|
445
453
|
custom?: ctp.CustomFields | undefined;
|
|
@@ -527,6 +535,7 @@ declare const createRepositories: (storage: AbstractStorage) => {
|
|
|
527
535
|
"product-discount": ProductDiscountRepository;
|
|
528
536
|
"product-projection": ProductProjectionRepository;
|
|
529
537
|
"product-selection": ProductSelectionRepository;
|
|
538
|
+
"product-tailoring": ProductTailoringRepository;
|
|
530
539
|
project: ProjectRepository;
|
|
531
540
|
review: ReviewRepository;
|
|
532
541
|
quote: QuoteRepository;
|
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, MyCustomerEmailVerify,
|
|
4
|
+
import { QueryParam, BaseResource, Project, UpdateAction, ResourceIdentifier, ProductTailoring, AssociateRoleDraft, AssociateRole, AttributeGroupDraft, AttributeGroup, BusinessUnitDraft, BusinessUnit, CartDraft, Cart, LineItemDraft, LineItem, CartDiscountDraft, CartDiscount, CategoryDraft, Category, ChannelDraft, Channel, CustomObjectDraft, CustomObject, CustomerDraft, Customer, CustomerCreatePasswordResetToken, CustomerToken, CustomerResetPassword, MyCustomerResetPassword, CustomerGroupDraft, CustomerGroup, DiscountCodeDraft, DiscountCode, ExtensionDraft, Extension, InventoryEntryDraft, InventoryEntry, MyCustomerChangePassword, MyCustomerEmailVerify, 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;
|
|
@@ -101,6 +101,7 @@ type ResourceMap = {
|
|
|
101
101
|
"product-price": ctp.StandalonePrice;
|
|
102
102
|
"product-projection": ctp.ProductProjection;
|
|
103
103
|
"product-selection": ctp.ProductSelection;
|
|
104
|
+
"product-tailoring": ctp.ProductTailoring;
|
|
104
105
|
"product-type": ctp.ProductType;
|
|
105
106
|
"product": ctp.Product;
|
|
106
107
|
"quote-request": ctp.QuoteRequest;
|
|
@@ -140,6 +141,7 @@ type PagedQueryResponseMap = {
|
|
|
140
141
|
"product-price": ctp.StandalonePricePagedQueryResponse;
|
|
141
142
|
"product-projection": ctp.ProductProjectionPagedQueryResponse;
|
|
142
143
|
"product-selection": ctp.ProductSelectionPagedQueryResponse;
|
|
144
|
+
"product-tailoring": ctp.ProductTailoringPagedQueryResponse;
|
|
143
145
|
"product-type": ctp.ProductTypePagedQueryResponse;
|
|
144
146
|
"product": ctp.ProductPagedQueryResponse;
|
|
145
147
|
"quote-request": ctp.QuoteRequestPagedQueryResponse;
|
|
@@ -184,6 +186,11 @@ declare abstract class AbstractStorage {
|
|
|
184
186
|
abstract expand<T>(projectKey: string, obj: T, clause: undefined | string | string[]): T;
|
|
185
187
|
}
|
|
186
188
|
|
|
189
|
+
declare class ProductTailoringRepository extends AbstractResourceRepository<"product-tailoring"> {
|
|
190
|
+
constructor(storage: AbstractStorage);
|
|
191
|
+
create(context: RepositoryContext, draft: any): ProductTailoring;
|
|
192
|
+
}
|
|
193
|
+
|
|
187
194
|
declare class AssociateRoleRepository extends AbstractResourceRepository<"associate-role"> {
|
|
188
195
|
constructor(storage: AbstractStorage);
|
|
189
196
|
create(context: RepositoryContext, draft: AssociateRoleDraft): AssociateRole;
|
|
@@ -235,7 +242,8 @@ declare class CustomObjectRepository extends AbstractResourceRepository<"key-val
|
|
|
235
242
|
declare class CustomerRepository extends AbstractResourceRepository<"customer"> {
|
|
236
243
|
constructor(storage: AbstractStorage);
|
|
237
244
|
create(context: RepositoryContext, draft: CustomerDraft): Customer;
|
|
238
|
-
passwordResetToken(context: RepositoryContext,
|
|
245
|
+
passwordResetToken(context: RepositoryContext, request: CustomerCreatePasswordResetToken): CustomerToken;
|
|
246
|
+
passwordReset(context: RepositoryContext, resetPassword: CustomerResetPassword | MyCustomerResetPassword): Writable<Customer>;
|
|
239
247
|
verifyEmailToken(context: RepositoryContext, id: string): CustomerToken;
|
|
240
248
|
}
|
|
241
249
|
|
|
@@ -265,7 +273,6 @@ declare class MyCustomerRepository extends CustomerRepository {
|
|
|
265
273
|
confirmEmail(context: RepositoryContext, resetPassword: MyCustomerEmailVerify): Writable<Customer>;
|
|
266
274
|
deleteMe(context: RepositoryContext): Customer | undefined;
|
|
267
275
|
getMe(context: RepositoryContext): Customer | undefined;
|
|
268
|
-
resetPassword(context: RepositoryContext, resetPassword: MyCustomerResetPassword): Writable<Customer>;
|
|
269
276
|
}
|
|
270
277
|
|
|
271
278
|
declare class OrderRepository extends AbstractResourceRepository<"order"> {
|
|
@@ -440,6 +447,7 @@ declare class ShippingMethodRepository extends AbstractResourceRepository<"shipp
|
|
|
440
447
|
description?: string | undefined;
|
|
441
448
|
localizedDescription?: ctp.LocalizedString | undefined;
|
|
442
449
|
taxCategory: ctp.TaxCategoryReference;
|
|
450
|
+
active: boolean;
|
|
443
451
|
isDefault: boolean;
|
|
444
452
|
predicate?: string | undefined;
|
|
445
453
|
custom?: ctp.CustomFields | undefined;
|
|
@@ -527,6 +535,7 @@ declare const createRepositories: (storage: AbstractStorage) => {
|
|
|
527
535
|
"product-discount": ProductDiscountRepository;
|
|
528
536
|
"product-projection": ProductProjectionRepository;
|
|
529
537
|
"product-selection": ProductSelectionRepository;
|
|
538
|
+
"product-tailoring": ProductTailoringRepository;
|
|
530
539
|
project: ProjectRepository;
|
|
531
540
|
review: ReviewRepository;
|
|
532
541
|
quote: QuoteRepository;
|
package/dist/index.js
CHANGED
|
@@ -44,18 +44,21 @@ import { v4 as uuidv4 } from "uuid";
|
|
|
44
44
|
var PWRESET_SECRET = "pwreset";
|
|
45
45
|
var EMAIL_VERIFY_SECRET = "emailverifysecret";
|
|
46
46
|
var hashPassword = (clearPassword) => Buffer.from(clearPassword).toString("base64");
|
|
47
|
-
var createPasswordResetToken = (customer) => Buffer.from(
|
|
48
|
-
|
|
49
|
-
);
|
|
47
|
+
var createPasswordResetToken = (customer, expiresAt) => Buffer.from(
|
|
48
|
+
`${customer.id}:${PWRESET_SECRET}:${expiresAt.getTime()}`
|
|
49
|
+
).toString("base64");
|
|
50
50
|
var createEmailVerifyToken = (customer) => Buffer.from(`${customer.id}:${EMAIL_VERIFY_SECRET}:${uuidv4()}`).toString(
|
|
51
51
|
"base64"
|
|
52
52
|
);
|
|
53
53
|
var validatePasswordResetToken = (token) => {
|
|
54
54
|
const items = Buffer.from(token, "base64").toString("utf-8").split(":");
|
|
55
|
-
const [customerId, secret] = items;
|
|
55
|
+
const [customerId, secret, time] = items;
|
|
56
56
|
if (secret !== PWRESET_SECRET) {
|
|
57
57
|
return void 0;
|
|
58
58
|
}
|
|
59
|
+
if (parseInt(time) < (/* @__PURE__ */ new Date()).getTime()) {
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
59
62
|
return customerId;
|
|
60
63
|
};
|
|
61
64
|
var validateEmailVerifyToken = (token) => {
|
|
@@ -1500,6 +1503,7 @@ var InMemoryStorage = class extends AbstractStorage {
|
|
|
1500
1503
|
"product-selection": /* @__PURE__ */ new Map(),
|
|
1501
1504
|
"product-type": /* @__PURE__ */ new Map(),
|
|
1502
1505
|
"product-projection": /* @__PURE__ */ new Map(),
|
|
1506
|
+
"product-tailoring": /* @__PURE__ */ new Map(),
|
|
1503
1507
|
"review": /* @__PURE__ */ new Map(),
|
|
1504
1508
|
"shipping-method": /* @__PURE__ */ new Map(),
|
|
1505
1509
|
"staged-quote": /* @__PURE__ */ new Map(),
|
|
@@ -1884,6 +1888,22 @@ var AbstractUpdateHandler = class {
|
|
|
1884
1888
|
}
|
|
1885
1889
|
};
|
|
1886
1890
|
|
|
1891
|
+
// src/repositories/product-tailoring.ts
|
|
1892
|
+
var ProductTailoringRepository = class extends AbstractResourceRepository {
|
|
1893
|
+
constructor(storage) {
|
|
1894
|
+
super("product-tailoring", storage);
|
|
1895
|
+
this.actions = new ProductTailoringUpdateHandler(this._storage);
|
|
1896
|
+
}
|
|
1897
|
+
create(context, draft) {
|
|
1898
|
+
throw new Error("Create method for product-tailoring not implemented.");
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
var ProductTailoringUpdateHandler = class extends AbstractUpdateHandler {
|
|
1902
|
+
setSlug() {
|
|
1903
|
+
throw new Error("SetSlug method for product-tailoring not implemented.");
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1887
1907
|
// src/repositories/helpers.ts
|
|
1888
1908
|
import { v4 as uuidv44 } from "uuid";
|
|
1889
1909
|
var createAddress = (base, projectKey, storage) => {
|
|
@@ -2207,6 +2227,18 @@ var BusinessUnitRepository = class extends AbstractResourceRepository {
|
|
|
2207
2227
|
this.actions = new BusinessUnitUpdateHandler(this._storage);
|
|
2208
2228
|
}
|
|
2209
2229
|
create(context, draft) {
|
|
2230
|
+
const addresses = draft.addresses?.map((address) => ({
|
|
2231
|
+
...address,
|
|
2232
|
+
id: generateRandomString(5)
|
|
2233
|
+
})) ?? [];
|
|
2234
|
+
const defaultBillingAddressId = addresses.length > 0 && draft.defaultBillingAddress !== void 0 ? addresses[draft.defaultBillingAddress].id : void 0;
|
|
2235
|
+
const defaultShippingAddressId = addresses.length > 0 && draft.defaultShippingAddress !== void 0 ? addresses[draft.defaultShippingAddress].id : void 0;
|
|
2236
|
+
const shippingAddressIds = draft.shippingAddresses?.map(
|
|
2237
|
+
(i) => addresses[i].id
|
|
2238
|
+
);
|
|
2239
|
+
const billingAddressIds = draft.billingAddresses?.map(
|
|
2240
|
+
(i) => addresses[i].id
|
|
2241
|
+
);
|
|
2210
2242
|
const resource = {
|
|
2211
2243
|
...getBaseResourceProperties(),
|
|
2212
2244
|
key: draft.key,
|
|
@@ -2217,18 +2249,18 @@ var BusinessUnitRepository = class extends AbstractResourceRepository {
|
|
|
2217
2249
|
storeMode: draft.storeMode,
|
|
2218
2250
|
name: draft.name,
|
|
2219
2251
|
contactEmail: draft.contactEmail,
|
|
2220
|
-
addresses
|
|
2221
|
-
(a) => createAddress(a, context.projectKey, this._storage)
|
|
2222
|
-
),
|
|
2252
|
+
addresses,
|
|
2223
2253
|
custom: createCustomFields(
|
|
2224
2254
|
draft.custom,
|
|
2225
2255
|
context.projectKey,
|
|
2226
2256
|
this._storage
|
|
2227
2257
|
),
|
|
2228
|
-
shippingAddressIds
|
|
2229
|
-
|
|
2230
|
-
|
|
2258
|
+
shippingAddressIds,
|
|
2259
|
+
billingAddressIds,
|
|
2260
|
+
defaultShippingAddressId,
|
|
2261
|
+
defaultBillingAddressId,
|
|
2231
2262
|
associateMode: draft.associateMode,
|
|
2263
|
+
approvalRuleMode: draft.approvalRuleMode,
|
|
2232
2264
|
associates: draft.associates?.map(
|
|
2233
2265
|
(a) => createAssociate(a, context.projectKey, this._storage)
|
|
2234
2266
|
)
|
|
@@ -2302,6 +2334,9 @@ var BusinessUnitUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2302
2334
|
resource.addresses.push(newAddress);
|
|
2303
2335
|
}
|
|
2304
2336
|
}
|
|
2337
|
+
changeApprovalRuleMode(context, resource, { approvalRuleMode }) {
|
|
2338
|
+
resource.approvalRuleMode = approvalRuleMode;
|
|
2339
|
+
}
|
|
2305
2340
|
changeAssociateMode(context, resource, { associateMode }) {
|
|
2306
2341
|
resource.associateMode = associateMode;
|
|
2307
2342
|
}
|
|
@@ -2601,10 +2636,12 @@ var CartUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
2601
2636
|
}
|
|
2602
2637
|
}
|
|
2603
2638
|
setDirectDiscounts(context, resource, { discounts }) {
|
|
2604
|
-
resource.directDiscounts = discounts.map(
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2639
|
+
resource.directDiscounts = discounts.map(
|
|
2640
|
+
(discount) => ({
|
|
2641
|
+
...discount,
|
|
2642
|
+
id: uuidv45()
|
|
2643
|
+
})
|
|
2644
|
+
);
|
|
2608
2645
|
}
|
|
2609
2646
|
setLineItemShippingDetails(context, resource, {
|
|
2610
2647
|
action,
|
|
@@ -3414,24 +3451,26 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3414
3451
|
draft.custom,
|
|
3415
3452
|
context.projectKey,
|
|
3416
3453
|
this._storage
|
|
3417
|
-
)
|
|
3454
|
+
),
|
|
3455
|
+
stores: []
|
|
3418
3456
|
};
|
|
3419
3457
|
return this.saveNew(context, resource);
|
|
3420
3458
|
}
|
|
3421
|
-
passwordResetToken(context,
|
|
3459
|
+
passwordResetToken(context, request) {
|
|
3422
3460
|
const results = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3423
|
-
where: [`email="${email.toLocaleLowerCase()}"`]
|
|
3461
|
+
where: [`email="${request.email.toLocaleLowerCase()}"`]
|
|
3424
3462
|
});
|
|
3425
3463
|
if (results.count === 0) {
|
|
3426
3464
|
throw new CommercetoolsError({
|
|
3427
3465
|
code: "ResourceNotFound",
|
|
3428
|
-
message: `The Customer with ID '${email}' was not found.`
|
|
3466
|
+
message: `The Customer with ID '${request.email}' was not found.`
|
|
3429
3467
|
});
|
|
3430
3468
|
}
|
|
3431
|
-
const
|
|
3469
|
+
const ttlMinutes = request.ttlMinutes ?? 34560;
|
|
3470
|
+
const expiresAt = new Date((/* @__PURE__ */ new Date()).getTime() + ttlMinutes * 60 * 1e3);
|
|
3432
3471
|
const customer = results.results[0];
|
|
3433
3472
|
const rest = getBaseResourceProperties();
|
|
3434
|
-
const token = createPasswordResetToken(customer);
|
|
3473
|
+
const token = createPasswordResetToken(customer, expiresAt);
|
|
3435
3474
|
return {
|
|
3436
3475
|
id: rest.id,
|
|
3437
3476
|
createdAt: rest.createdAt,
|
|
@@ -3441,6 +3480,31 @@ var CustomerRepository = class extends AbstractResourceRepository {
|
|
|
3441
3480
|
value: token
|
|
3442
3481
|
};
|
|
3443
3482
|
}
|
|
3483
|
+
passwordReset(context, resetPassword) {
|
|
3484
|
+
const { newPassword, tokenValue } = resetPassword;
|
|
3485
|
+
const customerId = validatePasswordResetToken(tokenValue);
|
|
3486
|
+
if (!customerId) {
|
|
3487
|
+
throw new CommercetoolsError({
|
|
3488
|
+
code: "ResourceNotFound",
|
|
3489
|
+
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3490
|
+
});
|
|
3491
|
+
}
|
|
3492
|
+
const customer = this._storage.get(
|
|
3493
|
+
context.projectKey,
|
|
3494
|
+
"customer",
|
|
3495
|
+
customerId
|
|
3496
|
+
);
|
|
3497
|
+
if (!customer) {
|
|
3498
|
+
throw new CommercetoolsError({
|
|
3499
|
+
code: "ResourceNotFound",
|
|
3500
|
+
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3501
|
+
});
|
|
3502
|
+
}
|
|
3503
|
+
customer.password = hashPassword(newPassword);
|
|
3504
|
+
customer.version += 1;
|
|
3505
|
+
this._storage.add(context.projectKey, "customer", customer);
|
|
3506
|
+
return customer;
|
|
3507
|
+
}
|
|
3444
3508
|
verifyEmailToken(context, id) {
|
|
3445
3509
|
const results = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
3446
3510
|
where: [`id="${id.toLocaleLowerCase()}"`]
|
|
@@ -3823,31 +3887,6 @@ var MyCustomerRepository = class extends CustomerRepository {
|
|
|
3823
3887
|
}
|
|
3824
3888
|
return;
|
|
3825
3889
|
}
|
|
3826
|
-
resetPassword(context, resetPassword) {
|
|
3827
|
-
const { newPassword, tokenValue } = resetPassword;
|
|
3828
|
-
const customerId = validatePasswordResetToken(tokenValue);
|
|
3829
|
-
if (!customerId) {
|
|
3830
|
-
throw new CommercetoolsError({
|
|
3831
|
-
code: "ResourceNotFound",
|
|
3832
|
-
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3833
|
-
});
|
|
3834
|
-
}
|
|
3835
|
-
const customer = this._storage.get(
|
|
3836
|
-
context.projectKey,
|
|
3837
|
-
"customer",
|
|
3838
|
-
customerId
|
|
3839
|
-
);
|
|
3840
|
-
if (!customer) {
|
|
3841
|
-
throw new CommercetoolsError({
|
|
3842
|
-
code: "ResourceNotFound",
|
|
3843
|
-
message: `The Customer with ID 'Token(${tokenValue})' was not found.`
|
|
3844
|
-
});
|
|
3845
|
-
}
|
|
3846
|
-
customer.password = hashPassword(newPassword);
|
|
3847
|
-
customer.version += 1;
|
|
3848
|
-
this._storage.add(context.projectKey, "customer", customer);
|
|
3849
|
-
return customer;
|
|
3850
|
-
}
|
|
3851
3890
|
};
|
|
3852
3891
|
|
|
3853
3892
|
// src/repositories/my-order.ts
|
|
@@ -6208,6 +6247,9 @@ var ShippingMethodUpdateHandler = class extends AbstractUpdateHandler {
|
|
|
6208
6247
|
shippingRates: []
|
|
6209
6248
|
});
|
|
6210
6249
|
}
|
|
6250
|
+
changeActive(_context, resource, { active }) {
|
|
6251
|
+
resource.active = active;
|
|
6252
|
+
}
|
|
6211
6253
|
changeIsDefault(_context, resource, { isDefault }) {
|
|
6212
6254
|
resource.isDefault = isDefault;
|
|
6213
6255
|
}
|
|
@@ -6277,6 +6319,7 @@ var ShippingMethodRepository = class extends AbstractResourceRepository {
|
|
|
6277
6319
|
const resource = {
|
|
6278
6320
|
...getBaseResourceProperties(),
|
|
6279
6321
|
...draft,
|
|
6322
|
+
active: draft.active ?? true,
|
|
6280
6323
|
taxCategory: getReferenceFromResourceIdentifier(
|
|
6281
6324
|
draft.taxCategory,
|
|
6282
6325
|
context.projectKey,
|
|
@@ -7093,6 +7136,7 @@ var createRepositories = (storage) => ({
|
|
|
7093
7136
|
"product-discount": new ProductDiscountRepository(storage),
|
|
7094
7137
|
"product-projection": new ProductProjectionRepository(storage),
|
|
7095
7138
|
"product-selection": new ProductSelectionRepository(storage),
|
|
7139
|
+
"product-tailoring": new ProductTailoringRepository(storage),
|
|
7096
7140
|
"project": new ProjectRepository(storage),
|
|
7097
7141
|
"review": new ReviewRepository(storage),
|
|
7098
7142
|
"quote": new QuoteRepository(storage),
|
|
@@ -7490,6 +7534,11 @@ var CustomerService = class extends AbstractService {
|
|
|
7490
7534
|
getBasePath() {
|
|
7491
7535
|
return "customers";
|
|
7492
7536
|
}
|
|
7537
|
+
extraRoutes(parent) {
|
|
7538
|
+
parent.post("/password-token", this.passwordResetToken.bind(this));
|
|
7539
|
+
parent.post("/password/reset", this.passwordReset.bind(this));
|
|
7540
|
+
parent.post("/email-token", this.confirmEmailToken.bind(this));
|
|
7541
|
+
}
|
|
7493
7542
|
post(request, response) {
|
|
7494
7543
|
const draft = request.body;
|
|
7495
7544
|
const resource = this.repository.create(
|
|
@@ -7502,23 +7551,27 @@ var CustomerService = class extends AbstractService {
|
|
|
7502
7551
|
};
|
|
7503
7552
|
return response.status(this.createStatusCode).send(result);
|
|
7504
7553
|
}
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7554
|
+
passwordResetToken(request, response) {
|
|
7555
|
+
const customer = this.repository.passwordResetToken(
|
|
7556
|
+
getRepositoryContext(request),
|
|
7557
|
+
request.body
|
|
7558
|
+
);
|
|
7559
|
+
return response.status(200).send(customer);
|
|
7560
|
+
}
|
|
7561
|
+
passwordReset(request, response) {
|
|
7562
|
+
const customer = this.repository.passwordReset(
|
|
7563
|
+
getRepositoryContext(request),
|
|
7564
|
+
request.body
|
|
7565
|
+
);
|
|
7566
|
+
return response.status(200).send(customer);
|
|
7567
|
+
}
|
|
7568
|
+
confirmEmailToken(request, response) {
|
|
7569
|
+
const id = request.body.id;
|
|
7570
|
+
const token = this.repository.verifyEmailToken(
|
|
7571
|
+
getRepositoryContext(request),
|
|
7572
|
+
id
|
|
7573
|
+
);
|
|
7574
|
+
return response.status(200).send(token);
|
|
7522
7575
|
}
|
|
7523
7576
|
};
|
|
7524
7577
|
|
|
@@ -7676,7 +7729,7 @@ var MyCustomerService = class extends AbstractService {
|
|
|
7676
7729
|
return response.status(200).send(customer);
|
|
7677
7730
|
}
|
|
7678
7731
|
resetPassword(request, response) {
|
|
7679
|
-
const customer = this.repository.
|
|
7732
|
+
const customer = this.repository.passwordReset(
|
|
7680
7733
|
getRepositoryContext(request),
|
|
7681
7734
|
request.body
|
|
7682
7735
|
);
|