@labdigital/commercetools-mock 0.10.0 → 0.10.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.ts +353 -188
- package/dist/index.global.js +930 -874
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +271 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +271 -215
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/ctMock.ts +15 -9
- package/src/helpers.ts +1 -1
- package/src/lib/projectionSearchFilter.ts +3 -2
- package/src/priceSelector.test.ts +1 -3
- package/src/product-projection-search.ts +1 -3
- package/src/projectAPI.test.ts +7 -0
- package/src/projectAPI.ts +17 -22
- package/src/repositories/abstract.ts +31 -24
- package/src/repositories/cart-discount.ts +3 -4
- package/src/repositories/cart.ts +20 -15
- package/src/repositories/category.ts +6 -7
- package/src/repositories/channel.ts +4 -5
- package/src/repositories/custom-object.ts +9 -13
- package/src/repositories/customer-group.ts +3 -4
- package/src/repositories/customer.ts +4 -5
- package/src/repositories/discount-code.ts +4 -5
- package/src/repositories/errors.ts +1 -3
- package/src/repositories/extension.ts +7 -8
- package/src/repositories/helpers.ts +2 -2
- package/src/repositories/index.ts +19 -3
- package/src/repositories/inventory-entry.ts +4 -5
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/order-edit.ts +39 -0
- package/src/repositories/order.test.ts +16 -11
- package/src/repositories/order.ts +15 -8
- package/src/repositories/payment.ts +6 -7
- package/src/repositories/product-discount.ts +4 -24
- package/src/repositories/product-projection.ts +11 -5
- package/src/repositories/product-selection.ts +40 -0
- package/src/repositories/product-type.ts +11 -28
- package/src/repositories/product.ts +7 -8
- package/src/repositories/project.ts +8 -8
- package/src/repositories/quote-request.ts +28 -0
- package/src/repositories/quote.ts +28 -0
- package/src/repositories/review.ts +34 -0
- package/src/repositories/shipping-method.ts +10 -11
- package/src/repositories/shopping-list.ts +4 -4
- package/src/repositories/staged-quote.ts +29 -0
- package/src/repositories/standalone-price.ts +36 -0
- package/src/repositories/state.ts +7 -8
- package/src/repositories/store.ts +11 -27
- package/src/repositories/subscription.ts +3 -4
- package/src/repositories/tax-category.ts +5 -22
- package/src/repositories/type.ts +12 -13
- package/src/repositories/zone.ts +4 -5
- package/src/server.ts +4 -4
- package/src/services/abstract.ts +3 -5
- package/src/services/cart-discount.ts +1 -1
- package/src/services/cart.test.ts +1 -1
- package/src/services/cart.ts +40 -33
- package/src/services/category.ts +1 -1
- package/src/services/channel.ts +1 -1
- package/src/services/custom-object.test.ts +1 -1
- package/src/services/custom-object.ts +2 -2
- package/src/services/customer-group.ts +1 -1
- package/src/services/customer.test.ts +1 -1
- package/src/services/customer.ts +3 -3
- package/src/services/discount-code.ts +1 -1
- package/src/services/extension.ts +1 -1
- package/src/services/inventory-entry.test.ts +1 -1
- package/src/services/inventory-entry.ts +1 -1
- package/src/services/my-cart.test.ts +2 -0
- package/src/services/my-cart.ts +1 -1
- package/src/services/my-customer.ts +1 -1
- package/src/services/my-order.ts +1 -1
- package/src/services/my-payment.ts +1 -1
- package/src/services/order.test.ts +24 -20
- package/src/services/order.ts +2 -2
- package/src/services/payment.ts +1 -1
- package/src/services/product-discount.ts +1 -17
- package/src/services/product-projection.test.ts +1 -1
- package/src/services/product-projection.ts +2 -2
- package/src/services/product-type.ts +1 -17
- package/src/services/product.test.ts +1 -1
- package/src/services/product.ts +1 -1
- package/src/services/project.ts +2 -3
- package/src/services/shipping-method.ts +1 -1
- package/src/services/shopping-list.ts +1 -1
- package/src/services/state.ts +1 -1
- package/src/services/store.ts +2 -18
- package/src/services/subscription.ts +1 -1
- package/src/services/tax-category.ts +1 -17
- package/src/services/type.ts +1 -1
- package/src/services/zone.ts +1 -1
- package/src/storage/abstract.ts +82 -0
- package/src/{storage.ts → storage/in-memory.ts} +57 -118
- package/src/storage/index.ts +2 -0
- package/src/types.ts +48 -119
|
@@ -6,19 +6,18 @@ import {
|
|
|
6
6
|
ExtensionSetKeyAction,
|
|
7
7
|
ExtensionSetTimeoutInMsAction,
|
|
8
8
|
ExtensionUpdateAction,
|
|
9
|
-
ReferenceTypeId,
|
|
10
9
|
} from '@commercetools/platform-sdk'
|
|
11
|
-
import { Resource, Writable } from '../types'
|
|
12
10
|
import { getBaseResourceProperties } from '../helpers'
|
|
13
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
14
11
|
import { maskSecretValue } from '../lib/masking'
|
|
12
|
+
import { Writable } from '../types'
|
|
13
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
15
14
|
|
|
16
|
-
export class ExtensionRepository extends AbstractResourceRepository {
|
|
17
|
-
getTypeId()
|
|
18
|
-
return 'extension'
|
|
15
|
+
export class ExtensionRepository extends AbstractResourceRepository<'extension'> {
|
|
16
|
+
getTypeId() {
|
|
17
|
+
return 'extension' as const
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
postProcessResource
|
|
20
|
+
postProcessResource(resource: Extension): Extension {
|
|
22
21
|
if (resource) {
|
|
23
22
|
const extension = resource as Extension
|
|
24
23
|
if (
|
|
@@ -28,7 +27,7 @@ export class ExtensionRepository extends AbstractResourceRepository {
|
|
|
28
27
|
return maskSecretValue(
|
|
29
28
|
extension,
|
|
30
29
|
'destination.authentication.headerValue'
|
|
31
|
-
)
|
|
30
|
+
)
|
|
32
31
|
} else if (extension.destination.type == 'AWSLambda') {
|
|
33
32
|
return maskSecretValue(resource, 'destination.accessSecret')
|
|
34
33
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
2
1
|
import {
|
|
3
2
|
Address,
|
|
4
3
|
BaseAddress,
|
|
@@ -18,9 +17,10 @@ import {
|
|
|
18
17
|
TypedMoney,
|
|
19
18
|
} from '@commercetools/platform-sdk'
|
|
20
19
|
import { Request } from 'express'
|
|
20
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
21
|
+
import { CommercetoolsError } from '../exceptions'
|
|
21
22
|
import { AbstractStorage } from '../storage'
|
|
22
23
|
import { RepositoryContext } from './abstract'
|
|
23
|
-
import { CommercetoolsError } from '../exceptions'
|
|
24
24
|
|
|
25
25
|
export const createAddress = (
|
|
26
26
|
base: BaseAddress | undefined,
|
|
@@ -11,14 +11,21 @@ import { ExtensionRepository } from './extension'
|
|
|
11
11
|
import { InventoryEntryRepository } from './inventory-entry'
|
|
12
12
|
import { MyOrderRepository } from './my-order'
|
|
13
13
|
import { OrderRepository } from './order'
|
|
14
|
+
import { OrderEditRepository } from './order-edit'
|
|
14
15
|
import { PaymentRepository } from './payment'
|
|
15
16
|
import { ProductRepository } from './product'
|
|
16
17
|
import { ProductDiscountRepository } from './product-discount'
|
|
17
18
|
import { ProductProjectionRepository } from './product-projection'
|
|
19
|
+
import { ProductSelectionRepository } from './product-selection'
|
|
18
20
|
import { ProductTypeRepository } from './product-type'
|
|
19
21
|
import { ProjectRepository } from './project'
|
|
22
|
+
import { QuoteRepository } from './quote'
|
|
23
|
+
import { QuoteRequestRepository } from './quote-request'
|
|
24
|
+
import { ReviewRepository } from './review'
|
|
20
25
|
import { ShippingMethodRepository } from './shipping-method'
|
|
21
26
|
import { ShoppingListRepository } from './shopping-list'
|
|
27
|
+
import { StagedQuoteRepository } from './staged-quote'
|
|
28
|
+
import { StandAlonePriceRepository } from './standalone-price'
|
|
22
29
|
import { StateRepository } from './state'
|
|
23
30
|
import { StoreRepository } from './store'
|
|
24
31
|
import { SubscriptionRepository } from './subscription'
|
|
@@ -26,6 +33,8 @@ import { TaxCategoryRepository } from './tax-category'
|
|
|
26
33
|
import { TypeRepository } from './type'
|
|
27
34
|
import { ZoneRepository } from './zone'
|
|
28
35
|
|
|
36
|
+
export type RepositoryMap = ReturnType<typeof createRepositories>
|
|
37
|
+
|
|
29
38
|
export const createRepositories = (storage: AbstractStorage) => ({
|
|
30
39
|
category: new CategoryRepository(storage),
|
|
31
40
|
cart: new CartRepository(storage),
|
|
@@ -38,18 +47,25 @@ export const createRepositories = (storage: AbstractStorage) => ({
|
|
|
38
47
|
'inventory-entry': new InventoryEntryRepository(storage),
|
|
39
48
|
'key-value-document': new CustomObjectRepository(storage),
|
|
40
49
|
order: new OrderRepository(storage),
|
|
50
|
+
'order-edit': new OrderEditRepository(storage),
|
|
41
51
|
payment: new PaymentRepository(storage),
|
|
42
52
|
'my-cart': new CartRepository(storage),
|
|
43
53
|
'my-order': new MyOrderRepository(storage),
|
|
44
54
|
'my-customer': new CustomerRepository(storage),
|
|
45
55
|
'my-payment': new PaymentRepository(storage),
|
|
46
|
-
'shipping-method': new ShippingMethodRepository(storage),
|
|
47
|
-
'product-type': new ProductTypeRepository(storage),
|
|
48
56
|
product: new ProductRepository(storage),
|
|
49
|
-
|
|
57
|
+
'product-type': new ProductTypeRepository(storage),
|
|
50
58
|
'product-discount': new ProductDiscountRepository(storage),
|
|
51
59
|
'product-projection': new ProductProjectionRepository(storage),
|
|
60
|
+
'product-selection': new ProductSelectionRepository(storage),
|
|
61
|
+
project: new ProjectRepository(storage),
|
|
62
|
+
review: new ReviewRepository(storage),
|
|
63
|
+
quote: new QuoteRepository(storage),
|
|
64
|
+
'quote-request': new QuoteRequestRepository(storage),
|
|
65
|
+
'shipping-method': new ShippingMethodRepository(storage),
|
|
52
66
|
'shopping-list': new ShoppingListRepository(storage),
|
|
67
|
+
'staged-quote': new StagedQuoteRepository(storage),
|
|
68
|
+
'standalone-price': new StandAlonePriceRepository(storage),
|
|
53
69
|
state: new StateRepository(storage),
|
|
54
70
|
store: new StoreRepository(storage),
|
|
55
71
|
subscription: new SubscriptionRepository(storage),
|
|
@@ -6,16 +6,15 @@ import {
|
|
|
6
6
|
InventoryEntrySetCustomTypeAction,
|
|
7
7
|
InventoryEntrySetExpectedDeliveryAction,
|
|
8
8
|
InventoryEntrySetRestockableInDaysAction,
|
|
9
|
-
ReferenceTypeId,
|
|
10
9
|
} from '@commercetools/platform-sdk'
|
|
11
10
|
import { getBaseResourceProperties } from '../helpers'
|
|
11
|
+
import { Writable } from '../types'
|
|
12
12
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
13
13
|
import { createCustomFields } from './helpers'
|
|
14
|
-
import { Writable } from '../types'
|
|
15
14
|
|
|
16
|
-
export class InventoryEntryRepository extends AbstractResourceRepository {
|
|
17
|
-
getTypeId()
|
|
18
|
-
return 'inventory-entry'
|
|
15
|
+
export class InventoryEntryRepository extends AbstractResourceRepository<'inventory-entry'> {
|
|
16
|
+
getTypeId() {
|
|
17
|
+
return 'inventory-entry' as const
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
create(
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import assert from 'assert'
|
|
2
1
|
import {
|
|
3
2
|
CartReference,
|
|
4
3
|
MyOrderFromCartDraft,
|
|
5
4
|
Order,
|
|
6
5
|
} from '@commercetools/platform-sdk'
|
|
7
|
-
import
|
|
6
|
+
import assert from 'assert'
|
|
8
7
|
import { RepositoryContext } from './abstract'
|
|
8
|
+
import { OrderRepository } from './order'
|
|
9
9
|
|
|
10
10
|
export class MyOrderRepository extends OrderRepository {
|
|
11
11
|
create(context: RepositoryContext, draft: MyOrderFromCartDraft): Order {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OrderEdit,
|
|
3
|
+
OrderEditDraft,
|
|
4
|
+
OrderEditResult,
|
|
5
|
+
OrderEditUpdateAction,
|
|
6
|
+
} from '@commercetools/platform-sdk'
|
|
7
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
8
|
+
import { Writable } from '../types'
|
|
9
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
10
|
+
|
|
11
|
+
export class OrderEditRepository extends AbstractResourceRepository<'order-edit'> {
|
|
12
|
+
getTypeId() {
|
|
13
|
+
return 'order-edit' as const
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
create(context: RepositoryContext, draft: OrderEditDraft): OrderEdit {
|
|
17
|
+
const resource: OrderEdit = {
|
|
18
|
+
...getBaseResourceProperties(),
|
|
19
|
+
stagedActions: draft.stagedActions ?? [],
|
|
20
|
+
resource: draft.resource,
|
|
21
|
+
result: {
|
|
22
|
+
type: 'NotProcessed',
|
|
23
|
+
} as OrderEditResult,
|
|
24
|
+
}
|
|
25
|
+
this.saveNew(context, resource)
|
|
26
|
+
return resource
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
actions: Partial<
|
|
30
|
+
Record<
|
|
31
|
+
OrderEditUpdateAction['action'],
|
|
32
|
+
(
|
|
33
|
+
context: RepositoryContext,
|
|
34
|
+
resource: Writable<OrderEdit>,
|
|
35
|
+
action: any
|
|
36
|
+
) => void
|
|
37
|
+
>
|
|
38
|
+
> = {}
|
|
39
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cart, OrderImportDraft } from '@commercetools/platform-sdk'
|
|
2
|
-
import { OrderRepository } from './order'
|
|
3
2
|
import { InMemoryStorage } from '../storage'
|
|
3
|
+
import { OrderRepository } from './order'
|
|
4
4
|
|
|
5
5
|
describe('Order repository', () => {
|
|
6
6
|
const storage = new InMemoryStorage()
|
|
@@ -21,6 +21,8 @@ describe('Order repository', () => {
|
|
|
21
21
|
fractionDigits: 2,
|
|
22
22
|
},
|
|
23
23
|
cartState: 'Active',
|
|
24
|
+
shippingMode: 'Single',
|
|
25
|
+
shipping: [],
|
|
24
26
|
taxMode: 'Platform',
|
|
25
27
|
taxRoundingMode: 'HalfEven',
|
|
26
28
|
taxCalculationMode: 'UnitPriceLevel',
|
|
@@ -29,18 +31,19 @@ describe('Order repository', () => {
|
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
storage.add('dummy', 'cart', cart)
|
|
34
|
+
const ctx = { projectKey: 'dummy' }
|
|
32
35
|
|
|
33
|
-
const result = repository.create(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
version: cart.version,
|
|
41
|
-
}
|
|
42
|
-
)
|
|
36
|
+
const result = repository.create(ctx, {
|
|
37
|
+
cart: {
|
|
38
|
+
id: cart.id,
|
|
39
|
+
typeId: 'cart',
|
|
40
|
+
},
|
|
41
|
+
version: cart.version,
|
|
42
|
+
})
|
|
43
43
|
expect(result.cart?.id).toBe(cart.id)
|
|
44
|
+
|
|
45
|
+
const items = repository.query(ctx)
|
|
46
|
+
expect(items.count).toBe(1)
|
|
44
47
|
})
|
|
45
48
|
|
|
46
49
|
test('create from cart - in store', async () => {
|
|
@@ -58,6 +61,8 @@ describe('Order repository', () => {
|
|
|
58
61
|
fractionDigits: 2,
|
|
59
62
|
},
|
|
60
63
|
cartState: 'Active',
|
|
64
|
+
shippingMode: 'Single',
|
|
65
|
+
shipping: [],
|
|
61
66
|
taxMode: 'Platform',
|
|
62
67
|
taxRoundingMode: 'HalfEven',
|
|
63
68
|
taxCalculationMode: 'UnitPriceLevel',
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import assert from 'assert'
|
|
2
1
|
import {
|
|
3
2
|
Cart,
|
|
4
3
|
CartReference,
|
|
@@ -25,10 +24,13 @@ import {
|
|
|
25
24
|
Product,
|
|
26
25
|
ProductPagedQueryResponse,
|
|
27
26
|
ProductVariant,
|
|
28
|
-
ReferenceTypeId,
|
|
29
27
|
State,
|
|
30
28
|
Store,
|
|
31
29
|
} from '@commercetools/platform-sdk'
|
|
30
|
+
import assert from 'assert'
|
|
31
|
+
import { CommercetoolsError } from '../exceptions'
|
|
32
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
33
|
+
import { Writable } from '../types'
|
|
32
34
|
import {
|
|
33
35
|
AbstractResourceRepository,
|
|
34
36
|
QueryParams,
|
|
@@ -40,13 +42,10 @@ import {
|
|
|
40
42
|
createTypedMoney,
|
|
41
43
|
resolveStoreReference,
|
|
42
44
|
} from './helpers'
|
|
43
|
-
import { Writable } from '../types'
|
|
44
|
-
import { getBaseResourceProperties } from '../helpers'
|
|
45
|
-
import { CommercetoolsError } from '../exceptions'
|
|
46
45
|
|
|
47
|
-
export class OrderRepository extends AbstractResourceRepository {
|
|
48
|
-
getTypeId()
|
|
49
|
-
return 'order'
|
|
46
|
+
export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
47
|
+
getTypeId() {
|
|
48
|
+
return 'order' as const
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
create(context: RepositoryContext, draft: OrderFromCartDraft): Order {
|
|
@@ -85,6 +84,8 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
85
84
|
refusedGifts: [],
|
|
86
85
|
origin: 'Customer',
|
|
87
86
|
syncInfo: [],
|
|
87
|
+
shippingMode: cart.shippingMode,
|
|
88
|
+
shipping: cart.shipping,
|
|
88
89
|
store: context.storeKey
|
|
89
90
|
? {
|
|
90
91
|
key: context.storeKey,
|
|
@@ -118,6 +119,9 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
118
119
|
origin: draft.origin || 'Customer',
|
|
119
120
|
paymentState: draft.paymentState,
|
|
120
121
|
refusedGifts: [],
|
|
122
|
+
shippingMode: 'Single',
|
|
123
|
+
shipping: [],
|
|
124
|
+
|
|
121
125
|
store: resolveStoreReference(
|
|
122
126
|
draft.store,
|
|
123
127
|
context.projectKey,
|
|
@@ -202,6 +206,8 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
202
206
|
quantity: draft.quantity,
|
|
203
207
|
state: draft.state || [],
|
|
204
208
|
taxRate: draft.taxRate,
|
|
209
|
+
taxedPricePortions: [],
|
|
210
|
+
perMethodTaxRate: [],
|
|
205
211
|
totalPrice: createTypedMoney(draft.price.value),
|
|
206
212
|
variant: {
|
|
207
213
|
id: variant.id,
|
|
@@ -228,6 +234,7 @@ export class OrderRepository extends AbstractResourceRepository {
|
|
|
228
234
|
money: createTypedMoney(draft.money),
|
|
229
235
|
name: draft.name,
|
|
230
236
|
quantity: draft.quantity,
|
|
237
|
+
priceMode: draft.priceMode,
|
|
231
238
|
slug: draft.slug,
|
|
232
239
|
state: [],
|
|
233
240
|
totalPrice: createTypedMoney(draft.money),
|
|
@@ -6,25 +6,24 @@ import {
|
|
|
6
6
|
PaymentSetCustomFieldAction,
|
|
7
7
|
PaymentSetCustomTypeAction,
|
|
8
8
|
PaymentTransitionStateAction,
|
|
9
|
-
ReferenceTypeId,
|
|
10
9
|
State,
|
|
11
10
|
StateReference,
|
|
12
11
|
Transaction,
|
|
13
12
|
TransactionDraft,
|
|
14
13
|
} from '@commercetools/platform-sdk'
|
|
14
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
15
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
16
|
+
import { Writable } from '../types'
|
|
15
17
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
16
18
|
import {
|
|
17
19
|
createCustomFields,
|
|
18
20
|
createTypedMoney,
|
|
19
21
|
getReferenceFromResourceIdentifier,
|
|
20
22
|
} from './helpers'
|
|
21
|
-
import { getBaseResourceProperties } from '../helpers'
|
|
22
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
23
|
-
import { Writable } from '../types'
|
|
24
23
|
|
|
25
|
-
export class PaymentRepository extends AbstractResourceRepository {
|
|
26
|
-
getTypeId()
|
|
27
|
-
return 'payment'
|
|
24
|
+
export class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
25
|
+
getTypeId() {
|
|
26
|
+
return 'payment' as const
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
create(context: RepositoryContext, draft: PaymentDraft): Payment {
|
|
@@ -17,16 +17,15 @@ import {
|
|
|
17
17
|
ProductDiscountValueDraft,
|
|
18
18
|
ProductDiscountValueExternal,
|
|
19
19
|
ProductDiscountValueRelative,
|
|
20
|
-
ReferenceTypeId,
|
|
21
20
|
} from '@commercetools/platform-sdk'
|
|
22
|
-
import { Writable } from 'types'
|
|
23
21
|
import { getBaseResourceProperties } from '../helpers'
|
|
22
|
+
import { Writable } from '../types'
|
|
24
23
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
25
24
|
import { createTypedMoney } from './helpers'
|
|
26
25
|
|
|
27
|
-
export class ProductDiscountRepository extends AbstractResourceRepository {
|
|
28
|
-
getTypeId()
|
|
29
|
-
return 'product-discount'
|
|
26
|
+
export class ProductDiscountRepository extends AbstractResourceRepository<'product-discount'> {
|
|
27
|
+
getTypeId() {
|
|
28
|
+
return 'product-discount' as const
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
create(
|
|
@@ -73,25 +72,6 @@ export class ProductDiscountRepository extends AbstractResourceRepository {
|
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
getWithKey(
|
|
77
|
-
context: RepositoryContext,
|
|
78
|
-
key: string
|
|
79
|
-
): ProductDiscount | undefined {
|
|
80
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
81
|
-
where: [`key="${key}"`],
|
|
82
|
-
})
|
|
83
|
-
if (result.count === 1) {
|
|
84
|
-
return result.results[0] as ProductDiscount
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Catch this for now, should be checked when creating/updating
|
|
88
|
-
if (result.count > 1) {
|
|
89
|
-
throw new Error('Duplicate product discount key')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
|
|
95
75
|
actions: Partial<
|
|
96
76
|
Record<
|
|
97
77
|
ProductDiscountUpdateAction['action'],
|
|
@@ -5,12 +5,11 @@ import {
|
|
|
5
5
|
QueryParams,
|
|
6
6
|
RepositoryContext,
|
|
7
7
|
} from './abstract'
|
|
8
|
-
import { RepositoryTypes } from '../types'
|
|
9
8
|
import { AbstractStorage } from '../storage'
|
|
10
9
|
import { ProductProjectionSearch } from '../product-projection-search'
|
|
11
10
|
import { QueryParamsAsArray } from '../helpers'
|
|
12
11
|
|
|
13
|
-
export class ProductProjectionRepository extends AbstractResourceRepository {
|
|
12
|
+
export class ProductProjectionRepository extends AbstractResourceRepository<'product-projection'> {
|
|
14
13
|
protected _searchService: ProductProjectionSearch
|
|
15
14
|
|
|
16
15
|
constructor(storage: AbstractStorage) {
|
|
@@ -18,8 +17,8 @@ export class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
18
17
|
this._searchService = new ProductProjectionSearch(storage)
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
getTypeId()
|
|
22
|
-
return 'product-projection'
|
|
20
|
+
getTypeId() {
|
|
21
|
+
return 'product-projection' as const
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
create(context: RepositoryContext, draft: ProductDraft): ProductProjection {
|
|
@@ -27,12 +26,19 @@ export class ProductProjectionRepository extends AbstractResourceRepository {
|
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
query(context: RepositoryContext, params: QueryParams = {}) {
|
|
30
|
-
|
|
29
|
+
const response = this._storage.query(context.projectKey, 'product', {
|
|
31
30
|
expand: params.expand,
|
|
32
31
|
where: params.where,
|
|
33
32
|
offset: params.offset,
|
|
34
33
|
limit: params.limit,
|
|
35
34
|
})
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
...response,
|
|
38
|
+
results: response.results.map((r) =>
|
|
39
|
+
this._searchService.transform(r, false)
|
|
40
|
+
),
|
|
41
|
+
}
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
search(context: RepositoryContext, query: ParsedQs) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProductSelection,
|
|
3
|
+
ProductSelectionDraft,
|
|
4
|
+
Review,
|
|
5
|
+
ReviewUpdateAction,
|
|
6
|
+
} from '@commercetools/platform-sdk'
|
|
7
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
8
|
+
import { Writable } from '../types'
|
|
9
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
10
|
+
|
|
11
|
+
export class ProductSelectionRepository extends AbstractResourceRepository<'product-selection'> {
|
|
12
|
+
getTypeId() {
|
|
13
|
+
return 'product-selection' as const
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
create(
|
|
17
|
+
context: RepositoryContext,
|
|
18
|
+
draft: ProductSelectionDraft
|
|
19
|
+
): ProductSelection {
|
|
20
|
+
const resource: ProductSelection = {
|
|
21
|
+
...getBaseResourceProperties(),
|
|
22
|
+
productCount: 0,
|
|
23
|
+
name: draft.name,
|
|
24
|
+
type: 'individual',
|
|
25
|
+
}
|
|
26
|
+
this.saveNew(context, resource)
|
|
27
|
+
return resource
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
actions: Partial<
|
|
31
|
+
Record<
|
|
32
|
+
ReviewUpdateAction['action'],
|
|
33
|
+
(
|
|
34
|
+
context: RepositoryContext,
|
|
35
|
+
resource: Writable<Review>,
|
|
36
|
+
action: any
|
|
37
|
+
) => void
|
|
38
|
+
>
|
|
39
|
+
> = {}
|
|
40
|
+
}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
|
-
import { getBaseResourceProperties } from '../helpers'
|
|
2
1
|
import {
|
|
3
2
|
AttributeDefinition,
|
|
4
3
|
AttributeDefinitionDraft,
|
|
5
4
|
AttributeType,
|
|
6
5
|
ProductType,
|
|
7
6
|
ProductTypeAddAttributeDefinitionAction,
|
|
8
|
-
|
|
7
|
+
ProductTypeChangeAttributeOrderByNameAction,
|
|
9
8
|
ProductTypeChangeLabelAction,
|
|
10
9
|
ProductTypeChangeLocalizedEnumValueLabelAction,
|
|
11
10
|
ProductTypeDraft,
|
|
12
11
|
ProductTypeRemoveAttributeDefinitionAction,
|
|
13
12
|
ProductTypeRemoveEnumValuesAction,
|
|
14
13
|
ProductTypeUpdateAction,
|
|
15
|
-
ReferenceTypeId,
|
|
16
14
|
} from '@commercetools/platform-sdk'
|
|
15
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
16
|
+
import { Writable } from '../types'
|
|
17
17
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
18
|
-
import { Writable } from 'types'
|
|
19
18
|
|
|
20
|
-
export class ProductTypeRepository extends AbstractResourceRepository {
|
|
21
|
-
getTypeId()
|
|
22
|
-
return 'product-type'
|
|
19
|
+
export class ProductTypeRepository extends AbstractResourceRepository<'product-type'> {
|
|
20
|
+
getTypeId() {
|
|
21
|
+
return 'product-type' as const
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
create(context: RepositoryContext, draft: ProductTypeDraft): ProductType {
|
|
@@ -51,22 +50,6 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
51
50
|
isSearchable: draft.isSearchable ?? true,
|
|
52
51
|
})
|
|
53
52
|
|
|
54
|
-
getWithKey(context: RepositoryContext, key: string): ProductType | undefined {
|
|
55
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
56
|
-
where: [`key="${key}"`],
|
|
57
|
-
})
|
|
58
|
-
if (result.count === 1) {
|
|
59
|
-
return result.results[0] as ProductType
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Catch this for now, should be checked when creating/updating
|
|
63
|
-
if (result.count > 1) {
|
|
64
|
-
throw new Error('Duplicate product type key')
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
53
|
actions: Partial<
|
|
71
54
|
Record<
|
|
72
55
|
ProductTypeUpdateAction['action'],
|
|
@@ -126,10 +109,10 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
126
109
|
this.attributeDefinitionFromAttributeDefinitionDraft(context, attribute)
|
|
127
110
|
)
|
|
128
111
|
},
|
|
129
|
-
|
|
112
|
+
changeAttributeOrderByName: (
|
|
130
113
|
context: RepositoryContext,
|
|
131
114
|
resource: Writable<ProductType>,
|
|
132
|
-
{
|
|
115
|
+
{ attributeNames }: ProductTypeChangeAttributeOrderByNameAction
|
|
133
116
|
) => {
|
|
134
117
|
const attrs = new Map(
|
|
135
118
|
resource.attributes?.map((item) => [item.name, item])
|
|
@@ -137,15 +120,15 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
137
120
|
const result: AttributeDefinition[] = []
|
|
138
121
|
let current = resource.attributes
|
|
139
122
|
|
|
140
|
-
|
|
141
|
-
const attr = attrs.get(
|
|
123
|
+
attributeNames.forEach((attrName) => {
|
|
124
|
+
const attr = attrs.get(attrName)
|
|
142
125
|
if (attr === undefined) {
|
|
143
126
|
throw new Error('New attr')
|
|
144
127
|
}
|
|
145
128
|
result.push(attr)
|
|
146
129
|
|
|
147
130
|
// Remove from current items
|
|
148
|
-
current = current?.filter((f) => f.name !==
|
|
131
|
+
current = current?.filter((f) => f.name !== attrName)
|
|
149
132
|
})
|
|
150
133
|
|
|
151
134
|
resource.attributes = result
|
|
@@ -12,18 +12,17 @@ import {
|
|
|
12
12
|
ProductUpdateAction,
|
|
13
13
|
ProductVariant,
|
|
14
14
|
ProductVariantDraft,
|
|
15
|
-
ReferenceTypeId,
|
|
16
15
|
} from '@commercetools/platform-sdk'
|
|
17
16
|
import { v4 as uuidv4 } from 'uuid'
|
|
17
|
+
import { Writable } from '../types'
|
|
18
18
|
import { getBaseResourceProperties } from '../helpers'
|
|
19
19
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
20
|
-
import { Writable } from '../types'
|
|
21
20
|
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
22
21
|
import deepEqual from 'deep-equal'
|
|
23
22
|
|
|
24
|
-
export class ProductRepository extends AbstractResourceRepository {
|
|
25
|
-
getTypeId()
|
|
26
|
-
return 'product'
|
|
23
|
+
export class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
24
|
+
getTypeId() {
|
|
25
|
+
return 'product' as const
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
create(context: RepositoryContext, draft: ProductDraft): Product {
|
|
@@ -100,7 +99,7 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
100
99
|
},
|
|
101
100
|
unpublish: (
|
|
102
101
|
context: RepositoryContext,
|
|
103
|
-
resource: Writable<Product
|
|
102
|
+
resource: Writable<Product>
|
|
104
103
|
// { action }: ProductUnpublishAction
|
|
105
104
|
) => {
|
|
106
105
|
resource.masterData.published = false
|
|
@@ -162,7 +161,7 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
162
161
|
|
|
163
162
|
return resource
|
|
164
163
|
},
|
|
165
|
-
|
|
164
|
+
setDescription: (
|
|
166
165
|
context: RepositoryContext,
|
|
167
166
|
resource: Writable<Product>,
|
|
168
167
|
{ description, staged }: ProductSetDescriptionAction
|
|
@@ -176,7 +175,7 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
176
175
|
checkForStagedChanges(resource)
|
|
177
176
|
return resource
|
|
178
177
|
},
|
|
179
|
-
|
|
178
|
+
setKey: (
|
|
180
179
|
context: RepositoryContext,
|
|
181
180
|
resource: Writable<Product>,
|
|
182
181
|
{ key }: ProductSetKeyAction
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ProjectChangeCountryTaxRateFallbackEnabledAction,
|
|
6
6
|
ProjectChangeCurrenciesAction,
|
|
7
7
|
ProjectChangeLanguagesAction,
|
|
8
|
-
|
|
8
|
+
ProjectChangeMessagesConfigurationAction,
|
|
9
9
|
ProjectChangeNameAction,
|
|
10
10
|
ProjectChangeOrderSearchStatusAction,
|
|
11
11
|
ProjectChangeProductSearchIndexingEnabledAction,
|
|
@@ -13,17 +13,17 @@ import {
|
|
|
13
13
|
ProjectSetShippingRateInputTypeAction,
|
|
14
14
|
ProjectUpdateAction,
|
|
15
15
|
} from '@commercetools/platform-sdk'
|
|
16
|
-
import { Resource, Writable } from 'types'
|
|
17
|
-
import { AbstractRepository, RepositoryContext } from './abstract'
|
|
18
16
|
import { maskSecretValue } from '../lib/masking'
|
|
17
|
+
import { Writable } from '../types'
|
|
18
|
+
import { AbstractRepository, RepositoryContext } from './abstract'
|
|
19
19
|
|
|
20
|
-
export class ProjectRepository extends AbstractRepository {
|
|
20
|
+
export class ProjectRepository extends AbstractRepository<Project> {
|
|
21
21
|
get(context: RepositoryContext): Project | null {
|
|
22
22
|
const resource = this._storage.getProject(context.projectKey)
|
|
23
23
|
return this.postProcessResource(resource)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
postProcessResource
|
|
26
|
+
postProcessResource(resource: Project): Project {
|
|
27
27
|
if (resource) {
|
|
28
28
|
return maskSecretValue(resource, 'externalOAuth.authorizationHeader')
|
|
29
29
|
}
|
|
@@ -77,12 +77,12 @@ export class ProjectRepository extends AbstractRepository {
|
|
|
77
77
|
) => {
|
|
78
78
|
resource.languages = languages
|
|
79
79
|
},
|
|
80
|
-
|
|
80
|
+
changeMessagesConfiguration: (
|
|
81
81
|
context: RepositoryContext,
|
|
82
82
|
resource: Writable<Project>,
|
|
83
|
-
{
|
|
83
|
+
{ messagesConfiguration }: ProjectChangeMessagesConfigurationAction
|
|
84
84
|
) => {
|
|
85
|
-
resource.messages.enabled =
|
|
85
|
+
resource.messages.enabled = messagesConfiguration.enabled
|
|
86
86
|
},
|
|
87
87
|
changeProductSearchIndexingEnabled: (
|
|
88
88
|
context: RepositoryContext,
|