@labdigital/commercetools-mock 0.9.1 → 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/README.md +8 -0
- package/dist/index.d.ts +354 -188
- package/dist/index.global.js +2346 -2209
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1968 -1829
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2171 -2032
- package/dist/index.mjs.map +1 -1
- package/package.json +30 -21
- package/src/constants.ts +4 -2
- package/src/ctMock.ts +27 -86
- package/src/helpers.ts +10 -11
- package/src/index.test.ts +1 -1
- package/src/lib/haversine.ts +2 -2
- package/src/lib/masking.ts +3 -1
- package/src/lib/predicateParser.ts +93 -92
- package/src/lib/projectionSearchFilter.test.ts +28 -36
- package/src/lib/projectionSearchFilter.ts +88 -103
- package/src/oauth/store.ts +3 -3
- package/src/priceSelector.test.ts +16 -35
- package/src/priceSelector.ts +6 -9
- package/src/product-projection-search.ts +49 -57
- package/src/projectAPI.test.ts +7 -0
- package/src/projectAPI.ts +17 -22
- package/src/repositories/abstract.ts +102 -51
- package/src/repositories/cart-discount.ts +4 -5
- package/src/repositories/cart.ts +56 -46
- package/src/repositories/category.ts +23 -26
- package/src/repositories/channel.ts +5 -6
- package/src/repositories/custom-object.ts +41 -32
- package/src/repositories/customer-group.ts +4 -5
- package/src/repositories/customer.ts +42 -5
- package/src/repositories/discount-code.ts +5 -6
- package/src/repositories/errors.ts +10 -14
- package/src/repositories/extension.ts +16 -15
- package/src/repositories/helpers.ts +10 -15
- package/src/repositories/index.ts +75 -0
- package/src/repositories/inventory-entry.ts +5 -6
- 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 +21 -14
- package/src/repositories/payment.ts +9 -10
- package/src/repositories/product-discount.ts +5 -25
- package/src/repositories/product-projection.ts +12 -5
- package/src/repositories/product-selection.ts +40 -0
- package/src/repositories/product-type.ts +38 -60
- package/src/repositories/product.ts +128 -85
- package/src/repositories/project.ts +16 -33
- 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 +25 -28
- package/src/repositories/shopping-list.ts +6 -6
- package/src/repositories/staged-quote.ts +29 -0
- package/src/repositories/standalone-price.ts +36 -0
- package/src/repositories/state.ts +16 -17
- package/src/repositories/store.ts +13 -29
- package/src/repositories/subscription.ts +4 -5
- package/src/repositories/tax-category.ts +9 -26
- package/src/repositories/type.ts +24 -27
- package/src/repositories/zone.ts +9 -11
- package/src/server.ts +5 -0
- package/src/services/abstract.ts +43 -12
- package/src/services/cart-discount.ts +3 -4
- package/src/services/cart.test.ts +9 -11
- package/src/services/cart.ts +42 -38
- package/src/services/category.test.ts +1 -2
- package/src/services/category.ts +3 -4
- package/src/services/channel.ts +3 -4
- package/src/services/custom-object.test.ts +6 -6
- package/src/services/custom-object.ts +4 -5
- package/src/services/customer-group.ts +3 -4
- package/src/services/customer.test.ts +136 -0
- package/src/services/customer.ts +5 -6
- package/src/services/discount-code.ts +3 -4
- package/src/services/extension.ts +3 -4
- package/src/services/index.ts +74 -0
- package/src/services/inventory-entry.test.ts +9 -13
- package/src/services/inventory-entry.ts +3 -4
- package/src/services/my-cart.test.ts +2 -0
- package/src/services/my-cart.ts +4 -5
- package/src/services/my-customer.ts +3 -4
- package/src/services/my-order.ts +4 -5
- package/src/services/my-payment.ts +3 -4
- package/src/services/order.test.ts +28 -26
- package/src/services/order.ts +4 -5
- package/src/services/payment.ts +3 -4
- package/src/services/product-discount.ts +3 -20
- package/src/services/product-projection.test.ts +76 -8
- package/src/services/product-projection.ts +4 -5
- package/src/services/product-type.ts +3 -20
- package/src/services/product.test.ts +200 -90
- package/src/services/product.ts +3 -4
- package/src/services/project.ts +5 -6
- package/src/services/shipping-method.ts +3 -4
- package/src/services/shopping-list.ts +3 -4
- package/src/services/state.ts +3 -4
- package/src/services/store.test.ts +11 -2
- package/src/services/store.ts +4 -21
- package/src/services/subscription.ts +3 -4
- package/src/services/tax-category.ts +3 -20
- package/src/services/type.ts +3 -4
- package/src/services/zone.ts +3 -4
- package/src/storage/abstract.ts +82 -0
- package/src/{storage.ts → storage/in-memory.ts} +79 -147
- package/src/storage/index.ts +2 -0
- package/src/types.ts +52 -83
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
createCustomFields,
|
|
3
|
-
createTypedMoney,
|
|
4
|
-
getReferenceFromResourceIdentifier,
|
|
5
|
-
} from './helpers'
|
|
6
|
-
import {
|
|
7
|
-
ReferenceTypeId,
|
|
8
2
|
ShippingMethod,
|
|
9
3
|
ShippingMethodAddShippingRateAction,
|
|
10
4
|
ShippingMethodAddZoneAction,
|
|
@@ -25,14 +19,19 @@ import {
|
|
|
25
19
|
ZoneRateDraft,
|
|
26
20
|
ZoneReference,
|
|
27
21
|
} from '@commercetools/platform-sdk'
|
|
22
|
+
import deepEqual from 'deep-equal'
|
|
28
23
|
import { getBaseResourceProperties } from '../helpers'
|
|
24
|
+
import { Writable } from '../types'
|
|
29
25
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
30
|
-
import {
|
|
31
|
-
|
|
26
|
+
import {
|
|
27
|
+
createCustomFields,
|
|
28
|
+
createTypedMoney,
|
|
29
|
+
getReferenceFromResourceIdentifier,
|
|
30
|
+
} from './helpers'
|
|
32
31
|
|
|
33
|
-
export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
34
|
-
getTypeId()
|
|
35
|
-
return 'shipping-method'
|
|
32
|
+
export class ShippingMethodRepository extends AbstractResourceRepository<'shipping-method'> {
|
|
33
|
+
getTypeId() {
|
|
34
|
+
return 'shipping-method' as const
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
create(
|
|
@@ -47,7 +46,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
47
46
|
context.projectKey,
|
|
48
47
|
this._storage
|
|
49
48
|
),
|
|
50
|
-
zoneRates: draft.zoneRates?.map(z =>
|
|
49
|
+
zoneRates: draft.zoneRates?.map((z) =>
|
|
51
50
|
this._transformZoneRateDraft(context, z)
|
|
52
51
|
),
|
|
53
52
|
custom: createCustomFields(
|
|
@@ -56,7 +55,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
56
55
|
this._storage
|
|
57
56
|
),
|
|
58
57
|
}
|
|
59
|
-
this.
|
|
58
|
+
this.saveNew(context, resource)
|
|
60
59
|
return resource
|
|
61
60
|
}
|
|
62
61
|
|
|
@@ -73,13 +72,11 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
73
72
|
shippingRates: draft.shippingRates?.map(this._transformShippingRate),
|
|
74
73
|
})
|
|
75
74
|
|
|
76
|
-
private _transformShippingRate = (rate: ShippingRateDraft): ShippingRate => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
}
|
|
75
|
+
private _transformShippingRate = (rate: ShippingRateDraft): ShippingRate => ({
|
|
76
|
+
price: createTypedMoney(rate.price),
|
|
77
|
+
freeAbove: rate.freeAbove && createTypedMoney(rate.freeAbove),
|
|
78
|
+
tiers: rate.tiers || [],
|
|
79
|
+
})
|
|
83
80
|
|
|
84
81
|
actions: Partial<
|
|
85
82
|
Record<
|
|
@@ -98,7 +95,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
98
95
|
) => {
|
|
99
96
|
const rate = this._transformShippingRate(shippingRate)
|
|
100
97
|
|
|
101
|
-
resource.zoneRates.forEach(zoneRate => {
|
|
98
|
+
resource.zoneRates.forEach((zoneRate) => {
|
|
102
99
|
if (zoneRate.zone.id === zone.id) {
|
|
103
100
|
zoneRate.shippingRates.push(rate)
|
|
104
101
|
return
|
|
@@ -119,11 +116,11 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
119
116
|
) => {
|
|
120
117
|
const rate = this._transformShippingRate(shippingRate)
|
|
121
118
|
|
|
122
|
-
resource.zoneRates.forEach(zoneRate => {
|
|
119
|
+
resource.zoneRates.forEach((zoneRate) => {
|
|
123
120
|
if (zoneRate.zone.id === zone.id) {
|
|
124
|
-
zoneRate.shippingRates = zoneRate.shippingRates.filter(
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
zoneRate.shippingRates = zoneRate.shippingRates.filter(
|
|
122
|
+
(otherRate) => !deepEqual(rate, otherRate)
|
|
123
|
+
)
|
|
127
124
|
}
|
|
128
125
|
})
|
|
129
126
|
},
|
|
@@ -152,9 +149,9 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
152
149
|
resource: Writable<ShippingMethod>,
|
|
153
150
|
{ zone }: ShippingMethodRemoveZoneAction
|
|
154
151
|
) => {
|
|
155
|
-
resource.zoneRates = resource.zoneRates.filter(
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
resource.zoneRates = resource.zoneRates.filter(
|
|
153
|
+
(zoneRate) => zoneRate.zone.id !== zone.id
|
|
154
|
+
)
|
|
158
155
|
},
|
|
159
156
|
setKey: (
|
|
160
157
|
_context: RepositoryContext,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CustomerReference,
|
|
3
|
-
ReferenceTypeId,
|
|
4
3
|
ShoppingList,
|
|
5
4
|
ShoppingListDraft,
|
|
6
5
|
} from '@commercetools/platform-sdk'
|
|
@@ -11,10 +10,11 @@ import {
|
|
|
11
10
|
getReferenceFromResourceIdentifier,
|
|
12
11
|
} from './helpers'
|
|
13
12
|
|
|
14
|
-
export class ShoppingListRepository extends AbstractResourceRepository {
|
|
15
|
-
getTypeId()
|
|
16
|
-
return 'shopping-list'
|
|
13
|
+
export class ShoppingListRepository extends AbstractResourceRepository<'shopping-list'> {
|
|
14
|
+
getTypeId() {
|
|
15
|
+
return 'shopping-list' as const
|
|
17
16
|
}
|
|
17
|
+
|
|
18
18
|
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList {
|
|
19
19
|
// const product =
|
|
20
20
|
|
|
@@ -27,7 +27,7 @@ export class ShoppingListRepository extends AbstractResourceRepository {
|
|
|
27
27
|
this._storage
|
|
28
28
|
),
|
|
29
29
|
textLineItems: [],
|
|
30
|
-
lineItems: draft.lineItems?.map(e => ({
|
|
30
|
+
lineItems: draft.lineItems?.map((e) => ({
|
|
31
31
|
...getBaseResourceProperties(),
|
|
32
32
|
...e,
|
|
33
33
|
addedAt: e.addedAt ?? '',
|
|
@@ -48,7 +48,7 @@ export class ShoppingListRepository extends AbstractResourceRepository {
|
|
|
48
48
|
? { typeId: 'store', key: draft.store.key! }
|
|
49
49
|
: undefined,
|
|
50
50
|
}
|
|
51
|
-
this.
|
|
51
|
+
this.saveNew(context, resource)
|
|
52
52
|
return resource
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Quote,
|
|
3
|
+
StagedQuote,
|
|
4
|
+
StagedQuoteDraft,
|
|
5
|
+
StagedQuoteUpdateAction,
|
|
6
|
+
} from '@commercetools/platform-sdk'
|
|
7
|
+
import { Writable } from '../types'
|
|
8
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
9
|
+
|
|
10
|
+
export class StagedQuoteRepository extends AbstractResourceRepository<'staged-quote'> {
|
|
11
|
+
getTypeId() {
|
|
12
|
+
return 'staged-quote' as const
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
create(context: RepositoryContext, draft: StagedQuoteDraft): StagedQuote {
|
|
16
|
+
throw new Error('not implemented')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
actions: Partial<
|
|
20
|
+
Record<
|
|
21
|
+
StagedQuoteUpdateAction['action'],
|
|
22
|
+
(
|
|
23
|
+
context: RepositoryContext,
|
|
24
|
+
resource: Writable<Quote>,
|
|
25
|
+
action: any
|
|
26
|
+
) => void
|
|
27
|
+
>
|
|
28
|
+
> = {}
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Review,
|
|
3
|
+
StandalonePrice,
|
|
4
|
+
StandalonePriceUpdateAction,
|
|
5
|
+
} from '@commercetools/platform-sdk'
|
|
6
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
7
|
+
import { Writable } from '../types'
|
|
8
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
9
|
+
|
|
10
|
+
export class StandAlonePriceRepository extends AbstractResourceRepository<'standalone-price'> {
|
|
11
|
+
getTypeId() {
|
|
12
|
+
return 'standalone-price' as const
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
create(context: RepositoryContext, draft: StandalonePrice): StandalonePrice {
|
|
16
|
+
const resource: StandalonePrice = {
|
|
17
|
+
...getBaseResourceProperties(),
|
|
18
|
+
active: draft.active,
|
|
19
|
+
sku: draft.sku,
|
|
20
|
+
value: draft.value,
|
|
21
|
+
}
|
|
22
|
+
this.saveNew(context, resource)
|
|
23
|
+
return resource
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
actions: Partial<
|
|
27
|
+
Record<
|
|
28
|
+
StandalonePriceUpdateAction['action'],
|
|
29
|
+
(
|
|
30
|
+
context: RepositoryContext,
|
|
31
|
+
resource: Writable<Review>,
|
|
32
|
+
action: any
|
|
33
|
+
) => void
|
|
34
|
+
>
|
|
35
|
+
> = {}
|
|
36
|
+
}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { getBaseResourceProperties } from '../helpers'
|
|
2
|
-
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
3
1
|
import {
|
|
4
|
-
ReferenceTypeId,
|
|
5
|
-
StateReference,
|
|
6
2
|
State,
|
|
7
3
|
StateChangeKeyAction,
|
|
8
4
|
StateDraft,
|
|
5
|
+
StateReference,
|
|
9
6
|
StateSetDescriptionAction,
|
|
10
7
|
StateSetNameAction,
|
|
11
8
|
StateSetRolesAction,
|
|
12
9
|
StateSetTransitionsAction,
|
|
13
10
|
StateUpdateAction,
|
|
14
11
|
} from '@commercetools/platform-sdk'
|
|
12
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
13
|
+
import { Writable } from '../types'
|
|
15
14
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
16
|
-
import {
|
|
15
|
+
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
17
16
|
|
|
18
|
-
export class StateRepository extends AbstractResourceRepository {
|
|
19
|
-
getTypeId()
|
|
20
|
-
return 'state'
|
|
17
|
+
export class StateRepository extends AbstractResourceRepository<'state'> {
|
|
18
|
+
getTypeId() {
|
|
19
|
+
return 'state' as const
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
create(context: RepositoryContext, draft: StateDraft): State {
|
|
@@ -26,12 +25,12 @@ export class StateRepository extends AbstractResourceRepository {
|
|
|
26
25
|
...draft,
|
|
27
26
|
builtIn: false,
|
|
28
27
|
initial: draft.initial || false,
|
|
29
|
-
transitions: (draft.transitions || []).map(t =>
|
|
28
|
+
transitions: (draft.transitions || []).map((t) =>
|
|
30
29
|
getReferenceFromResourceIdentifier(t, context.projectKey, this._storage)
|
|
31
30
|
),
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
this.
|
|
33
|
+
this.saveNew(context, resource)
|
|
35
34
|
return resource
|
|
36
35
|
}
|
|
37
36
|
|
|
@@ -78,12 +77,12 @@ export class StateRepository extends AbstractResourceRepository {
|
|
|
78
77
|
resource: Writable<State>,
|
|
79
78
|
{ transitions }: StateSetTransitionsAction
|
|
80
79
|
) => {
|
|
81
|
-
resource.transitions = transitions?.map(
|
|
82
|
-
|
|
83
|
-
id: resourceId.id ||
|
|
84
|
-
typeId:
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
}
|
|
80
|
+
resource.transitions = transitions?.map(
|
|
81
|
+
(resourceId): StateReference => ({
|
|
82
|
+
id: resourceId.id || '',
|
|
83
|
+
typeId: 'state',
|
|
84
|
+
})
|
|
85
|
+
)
|
|
86
|
+
},
|
|
88
87
|
}
|
|
89
88
|
}
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Store,
|
|
3
|
-
StoreDraft,
|
|
4
|
-
ReferenceTypeId,
|
|
5
|
-
StoreUpdateAction,
|
|
6
|
-
StoreSetNameAction,
|
|
7
2
|
ChannelReference,
|
|
8
|
-
StoreSetDistributionChannelsAction,
|
|
9
3
|
ChannelResourceIdentifier,
|
|
10
|
-
|
|
4
|
+
Store,
|
|
5
|
+
StoreDraft,
|
|
11
6
|
StoreSetCustomFieldAction,
|
|
12
7
|
StoreSetCustomTypeAction,
|
|
8
|
+
StoreSetDistributionChannelsAction,
|
|
9
|
+
StoreSetLanguagesAction,
|
|
10
|
+
StoreSetNameAction,
|
|
11
|
+
StoreUpdateAction,
|
|
13
12
|
} from '@commercetools/platform-sdk'
|
|
14
|
-
import { Writable } from 'types'
|
|
15
13
|
import { getBaseResourceProperties } from '../helpers'
|
|
14
|
+
import { Writable } from '../types'
|
|
16
15
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
17
16
|
import {
|
|
18
|
-
getReferenceFromResourceIdentifier,
|
|
19
17
|
createCustomFields,
|
|
18
|
+
getReferenceFromResourceIdentifier,
|
|
20
19
|
} from './helpers'
|
|
21
20
|
|
|
22
|
-
export class StoreRepository extends AbstractResourceRepository {
|
|
23
|
-
getTypeId()
|
|
24
|
-
return 'store'
|
|
21
|
+
export class StoreRepository extends AbstractResourceRepository<'store'> {
|
|
22
|
+
getTypeId() {
|
|
23
|
+
return 'store' as const
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
create(context: RepositoryContext, draft: StoreDraft): Store {
|
|
@@ -42,7 +41,7 @@ export class StoreRepository extends AbstractResourceRepository {
|
|
|
42
41
|
this._storage
|
|
43
42
|
),
|
|
44
43
|
}
|
|
45
|
-
this.
|
|
44
|
+
this.saveNew(context, resource)
|
|
46
45
|
return resource
|
|
47
46
|
}
|
|
48
47
|
|
|
@@ -52,7 +51,7 @@ export class StoreRepository extends AbstractResourceRepository {
|
|
|
52
51
|
) {
|
|
53
52
|
if (!channels) return []
|
|
54
53
|
|
|
55
|
-
return channels.map(ref =>
|
|
54
|
+
return channels.map((ref) =>
|
|
56
55
|
getReferenceFromResourceIdentifier<ChannelReference>(
|
|
57
56
|
ref,
|
|
58
57
|
context.projectKey,
|
|
@@ -61,21 +60,6 @@ export class StoreRepository extends AbstractResourceRepository {
|
|
|
61
60
|
)
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
getWithKey(context: RepositoryContext, key: string): Store | undefined {
|
|
65
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
66
|
-
where: [`key="${key}"`],
|
|
67
|
-
})
|
|
68
|
-
if (result.count === 1) {
|
|
69
|
-
return result.results[0] as Store
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (result.count > 1) {
|
|
73
|
-
throw new Error('Duplicate store key')
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
|
|
79
63
|
actions: Partial<
|
|
80
64
|
Record<
|
|
81
65
|
StoreUpdateAction['action'],
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InvalidInputError,
|
|
3
|
-
ReferenceTypeId,
|
|
4
3
|
Subscription,
|
|
5
4
|
SubscriptionDraft,
|
|
6
5
|
} from '@commercetools/platform-sdk'
|
|
@@ -8,9 +7,9 @@ import { CommercetoolsError } from '../exceptions'
|
|
|
8
7
|
import { getBaseResourceProperties } from '../helpers'
|
|
9
8
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
10
9
|
|
|
11
|
-
export class SubscriptionRepository extends AbstractResourceRepository {
|
|
12
|
-
getTypeId()
|
|
13
|
-
return 'subscription'
|
|
10
|
+
export class SubscriptionRepository extends AbstractResourceRepository<'subscription'> {
|
|
11
|
+
getTypeId() {
|
|
12
|
+
return 'subscription' as const
|
|
14
13
|
}
|
|
15
14
|
create(context: RepositoryContext, draft: SubscriptionDraft): Subscription {
|
|
16
15
|
// TODO: We could actually test this here by using the aws sdk. For now
|
|
@@ -44,7 +43,7 @@ export class SubscriptionRepository extends AbstractResourceRepository {
|
|
|
44
43
|
messages: draft.messages || [],
|
|
45
44
|
status: 'Healthy',
|
|
46
45
|
}
|
|
47
|
-
this.
|
|
46
|
+
this.saveNew(context, resource)
|
|
48
47
|
return resource
|
|
49
48
|
}
|
|
50
49
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ReferenceTypeId,
|
|
3
2
|
TaxCategory,
|
|
4
3
|
TaxCategoryAddTaxRateAction,
|
|
5
4
|
TaxCategoryChangeNameAction,
|
|
@@ -12,14 +11,14 @@ import {
|
|
|
12
11
|
TaxRate,
|
|
13
12
|
TaxRateDraft,
|
|
14
13
|
} from '@commercetools/platform-sdk'
|
|
14
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
15
15
|
import { getBaseResourceProperties } from '../helpers'
|
|
16
|
+
import { Writable } from '../types'
|
|
16
17
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
17
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
18
|
-
import { Writable } from 'types'
|
|
19
18
|
|
|
20
|
-
export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
21
|
-
getTypeId()
|
|
22
|
-
return 'tax-category'
|
|
19
|
+
export class TaxCategoryRepository extends AbstractResourceRepository<'tax-category'> {
|
|
20
|
+
getTypeId() {
|
|
21
|
+
return 'tax-category' as const
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
create(context: RepositoryContext, draft: TaxCategoryDraft): TaxCategory {
|
|
@@ -28,7 +27,7 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
28
27
|
...draft,
|
|
29
28
|
rates: draft.rates?.map(this.taxRateFromTaxRateDraft) || [],
|
|
30
29
|
}
|
|
31
|
-
this.
|
|
30
|
+
this.saveNew(context, resource)
|
|
32
31
|
return resource
|
|
33
32
|
}
|
|
34
33
|
|
|
@@ -38,22 +37,6 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
38
37
|
amount: draft.amount || 0,
|
|
39
38
|
})
|
|
40
39
|
|
|
41
|
-
getWithKey(context: RepositoryContext, key: string): TaxCategory | undefined {
|
|
42
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
43
|
-
where: [`key="${key}"`],
|
|
44
|
-
})
|
|
45
|
-
if (result.count === 1) {
|
|
46
|
-
return result.results[0] as TaxCategory
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Catch this for now, should be checked when creating/updating
|
|
50
|
-
if (result.count > 1) {
|
|
51
|
-
throw new Error('Duplicate tax category key')
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
40
|
actions: Partial<
|
|
58
41
|
Record<
|
|
59
42
|
TaxCategoryUpdateAction['action'],
|
|
@@ -82,9 +65,9 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
82
65
|
if (resource.rates === undefined) {
|
|
83
66
|
resource.rates = []
|
|
84
67
|
}
|
|
85
|
-
resource.rates = resource.rates.filter(
|
|
86
|
-
|
|
87
|
-
|
|
68
|
+
resource.rates = resource.rates.filter(
|
|
69
|
+
(taxRate) => taxRate.id !== taxRateId
|
|
70
|
+
)
|
|
88
71
|
},
|
|
89
72
|
replaceTaxRate: (
|
|
90
73
|
context: RepositoryContext,
|
package/src/repositories/type.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Type,
|
|
3
|
-
TypeDraft,
|
|
4
|
-
InvalidOperationError,
|
|
5
|
-
ReferenceTypeId,
|
|
6
|
-
TypeUpdateAction,
|
|
7
2
|
FieldDefinition,
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
InvalidOperationError,
|
|
4
|
+
Type,
|
|
5
|
+
TypeAddEnumValueAction,
|
|
10
6
|
TypeAddFieldDefinitionAction,
|
|
11
7
|
TypeChangeEnumValueLabelAction,
|
|
12
|
-
TypeAddEnumValueAction,
|
|
13
8
|
TypeChangeFieldDefinitionOrderAction,
|
|
9
|
+
TypeChangeNameAction,
|
|
10
|
+
TypeDraft,
|
|
14
11
|
TypeRemoveFieldDefinitionAction,
|
|
12
|
+
TypeSetDescriptionAction,
|
|
13
|
+
TypeUpdateAction,
|
|
15
14
|
} from '@commercetools/platform-sdk'
|
|
16
|
-
import { CommercetoolsError } from '../exceptions'
|
|
17
15
|
import { isEqual } from 'lodash'
|
|
18
|
-
import {
|
|
16
|
+
import { CommercetoolsError } from '../exceptions'
|
|
19
17
|
import { getBaseResourceProperties } from '../helpers'
|
|
18
|
+
import { Writable } from '../types'
|
|
20
19
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
21
20
|
|
|
22
|
-
export class TypeRepository extends AbstractResourceRepository {
|
|
23
|
-
getTypeId()
|
|
24
|
-
return 'type'
|
|
21
|
+
export class TypeRepository extends AbstractResourceRepository<'type'> {
|
|
22
|
+
getTypeId() {
|
|
23
|
+
return 'type' as const
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
create(context: RepositoryContext, draft: TypeDraft): Type {
|
|
@@ -33,7 +32,7 @@ export class TypeRepository extends AbstractResourceRepository {
|
|
|
33
32
|
fieldDefinitions: draft.fieldDefinitions || [],
|
|
34
33
|
description: draft.description,
|
|
35
34
|
}
|
|
36
|
-
this.
|
|
35
|
+
this.saveNew(context, resource)
|
|
37
36
|
return resource
|
|
38
37
|
}
|
|
39
38
|
actions: Partial<
|
|
@@ -58,9 +57,9 @@ export class TypeRepository extends AbstractResourceRepository {
|
|
|
58
57
|
resource: Writable<Type>,
|
|
59
58
|
{ fieldName }: TypeRemoveFieldDefinitionAction
|
|
60
59
|
) => {
|
|
61
|
-
resource.fieldDefinitions = resource.fieldDefinitions.filter(
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
resource.fieldDefinitions = resource.fieldDefinitions.filter(
|
|
61
|
+
(f) => f.name !== fieldName
|
|
62
|
+
)
|
|
64
63
|
},
|
|
65
64
|
setDescription: (
|
|
66
65
|
context: RepositoryContext,
|
|
@@ -82,12 +81,12 @@ export class TypeRepository extends AbstractResourceRepository {
|
|
|
82
81
|
{ fieldNames }: TypeChangeFieldDefinitionOrderAction
|
|
83
82
|
) => {
|
|
84
83
|
const fields = new Map(
|
|
85
|
-
resource.fieldDefinitions.map(item => [item.name, item])
|
|
84
|
+
resource.fieldDefinitions.map((item) => [item.name, item])
|
|
86
85
|
)
|
|
87
86
|
const result: FieldDefinition[] = []
|
|
88
87
|
let current = resource.fieldDefinitions
|
|
89
88
|
|
|
90
|
-
fieldNames.forEach(fieldName => {
|
|
89
|
+
fieldNames.forEach((fieldName) => {
|
|
91
90
|
const field = fields.get(fieldName)
|
|
92
91
|
if (field === undefined) {
|
|
93
92
|
throw new Error('New field')
|
|
@@ -95,15 +94,13 @@ export class TypeRepository extends AbstractResourceRepository {
|
|
|
95
94
|
result.push(field)
|
|
96
95
|
|
|
97
96
|
// Remove from current items
|
|
98
|
-
current = current.filter(f =>
|
|
99
|
-
return f.name !== fieldName
|
|
100
|
-
})
|
|
97
|
+
current = current.filter((f) => f.name !== fieldName)
|
|
101
98
|
})
|
|
102
99
|
|
|
103
100
|
if (
|
|
104
101
|
isEqual(
|
|
105
102
|
fieldNames,
|
|
106
|
-
resource.fieldDefinitions.map(item => item.name)
|
|
103
|
+
resource.fieldDefinitions.map((item) => item.name)
|
|
107
104
|
)
|
|
108
105
|
) {
|
|
109
106
|
throw new CommercetoolsError<InvalidOperationError>({
|
|
@@ -126,7 +123,7 @@ export class TypeRepository extends AbstractResourceRepository {
|
|
|
126
123
|
resource: Writable<Type>,
|
|
127
124
|
{ fieldName, value }: TypeAddEnumValueAction
|
|
128
125
|
) => {
|
|
129
|
-
resource.fieldDefinitions.forEach(field => {
|
|
126
|
+
resource.fieldDefinitions.forEach((field) => {
|
|
130
127
|
if (field.name === fieldName) {
|
|
131
128
|
// TODO, should be done better i suppose
|
|
132
129
|
if (field.type.name === 'Enum') {
|
|
@@ -147,11 +144,11 @@ export class TypeRepository extends AbstractResourceRepository {
|
|
|
147
144
|
resource: Writable<Type>,
|
|
148
145
|
{ fieldName, value }: TypeChangeEnumValueLabelAction
|
|
149
146
|
) => {
|
|
150
|
-
resource.fieldDefinitions.forEach(field => {
|
|
147
|
+
resource.fieldDefinitions.forEach((field) => {
|
|
151
148
|
if (field.name === fieldName) {
|
|
152
149
|
// TODO, should be done better i suppose
|
|
153
150
|
if (field.type.name === 'Enum') {
|
|
154
|
-
field.type.values.forEach(v => {
|
|
151
|
+
field.type.values.forEach((v) => {
|
|
155
152
|
if (v.key === value.key) {
|
|
156
153
|
v.label = value.label
|
|
157
154
|
}
|
|
@@ -160,7 +157,7 @@ export class TypeRepository extends AbstractResourceRepository {
|
|
|
160
157
|
field.type.name === 'Set' &&
|
|
161
158
|
field.type.elementType.name === 'Enum'
|
|
162
159
|
) {
|
|
163
|
-
field.type.elementType.values.forEach(v => {
|
|
160
|
+
field.type.elementType.values.forEach((v) => {
|
|
164
161
|
if (v.key === value.key) {
|
|
165
162
|
v.label = value.label
|
|
166
163
|
}
|
package/src/repositories/zone.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ReferenceTypeId,
|
|
3
2
|
Zone,
|
|
4
3
|
ZoneAddLocationAction,
|
|
5
4
|
ZoneChangeNameAction,
|
|
@@ -9,13 +8,13 @@ import {
|
|
|
9
8
|
ZoneSetKeyAction,
|
|
10
9
|
ZoneUpdateAction,
|
|
11
10
|
} from '@commercetools/platform-sdk'
|
|
12
|
-
import { Writable } from 'types'
|
|
13
11
|
import { getBaseResourceProperties } from '../helpers'
|
|
12
|
+
import { Writable } from '../types'
|
|
14
13
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
15
14
|
|
|
16
|
-
export class ZoneRepository extends AbstractResourceRepository {
|
|
17
|
-
getTypeId()
|
|
18
|
-
return 'zone'
|
|
15
|
+
export class ZoneRepository extends AbstractResourceRepository<'zone'> {
|
|
16
|
+
getTypeId() {
|
|
17
|
+
return 'zone' as const
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
create(context: RepositoryContext, draft: ZoneDraft): Zone {
|
|
@@ -26,7 +25,7 @@ export class ZoneRepository extends AbstractResourceRepository {
|
|
|
26
25
|
name: draft.name,
|
|
27
26
|
description: draft.description,
|
|
28
27
|
}
|
|
29
|
-
this.
|
|
28
|
+
this.saveNew(context, resource)
|
|
30
29
|
return resource
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -52,11 +51,10 @@ export class ZoneRepository extends AbstractResourceRepository {
|
|
|
52
51
|
resource: Writable<Zone>,
|
|
53
52
|
{ location }: ZoneRemoveLocationAction
|
|
54
53
|
) => {
|
|
55
|
-
resource.locations = resource.locations.filter(
|
|
56
|
-
|
|
57
|
-
loc.country === location.country && loc.state === location.state
|
|
58
|
-
|
|
59
|
-
})
|
|
54
|
+
resource.locations = resource.locations.filter(
|
|
55
|
+
(loc) =>
|
|
56
|
+
!(loc.country === location.country && loc.state === location.state)
|
|
57
|
+
)
|
|
60
58
|
},
|
|
61
59
|
changeName: (
|
|
62
60
|
context: RepositoryContext,
|