@labdigital/commercetools-mock 1.4.0 → 1.6.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/README.md +5 -4
- package/dist/index.cjs +116 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.js +116 -18
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/constants.ts +2 -2
- package/src/ctMock.ts +176 -176
- package/src/exceptions.ts +10 -10
- package/src/helpers.ts +26 -26
- package/src/index.test.ts +173 -173
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +19 -19
- package/src/lib/haversine.test.ts +13 -13
- package/src/lib/haversine.ts +14 -14
- package/src/lib/masking.ts +15 -15
- package/src/lib/parser.ts +2 -2
- package/src/lib/predicateParser.test.ts +204 -204
- package/src/lib/predicateParser.ts +398 -398
- package/src/lib/projectionSearchFilter.test.ts +168 -168
- package/src/lib/projectionSearchFilter.ts +272 -269
- package/src/lib/proxy.ts +8 -8
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.ts +103 -101
- package/src/oauth/store.ts +27 -27
- package/src/priceSelector.test.ts +68 -68
- package/src/priceSelector.ts +70 -70
- package/src/product-projection-search.ts +296 -296
- package/src/projectAPI.test.ts +3 -3
- package/src/projectAPI.ts +46 -46
- package/src/repositories/abstract.ts +190 -190
- package/src/repositories/associate-role.ts +10 -7
- package/src/repositories/attribute-group.ts +63 -8
- package/src/repositories/business-unit.ts +10 -7
- package/src/repositories/cart-discount.ts +134 -134
- package/src/repositories/cart.ts +517 -514
- package/src/repositories/category.ts +170 -167
- package/src/repositories/channel.ts +114 -111
- package/src/repositories/custom-object.ts +66 -63
- package/src/repositories/customer-group.ts +72 -69
- package/src/repositories/customer.ts +93 -79
- package/src/repositories/discount-code.ts +171 -168
- package/src/repositories/errors.ts +15 -15
- package/src/repositories/extension.ts +79 -76
- package/src/repositories/helpers.ts +180 -180
- package/src/repositories/index.ts +39 -39
- package/src/repositories/inventory-entry.ts +98 -95
- package/src/repositories/my-order.ts +11 -11
- package/src/repositories/order-edit.ts +29 -29
- package/src/repositories/order.test.ts +191 -191
- package/src/repositories/order.ts +393 -389
- package/src/repositories/payment.ts +155 -155
- package/src/repositories/product-discount.ts +149 -149
- package/src/repositories/product-projection.ts +116 -52
- package/src/repositories/product-selection.ts +31 -31
- package/src/repositories/product-type.ts +156 -156
- package/src/repositories/product.ts +600 -597
- package/src/repositories/project.ts +136 -135
- package/src/repositories/quote-request.ts +19 -19
- package/src/repositories/quote.ts +19 -19
- package/src/repositories/review.ts +24 -24
- package/src/repositories/shipping-method.ts +217 -217
- package/src/repositories/shopping-list.ts +49 -49
- package/src/repositories/staged-quote.ts +20 -20
- package/src/repositories/standalone-price.ts +72 -61
- package/src/repositories/state.ts +84 -84
- package/src/repositories/store.ts +114 -114
- package/src/repositories/subscription.ts +40 -40
- package/src/repositories/tax-category.ts +98 -98
- package/src/repositories/type.ts +157 -157
- package/src/repositories/zone.ts +71 -71
- package/src/server.ts +2 -2
- package/src/services/abstract.ts +173 -173
- package/src/services/attribute-group.ts +16 -0
- package/src/services/cart-discount.ts +8 -8
- package/src/services/cart.test.ts +409 -409
- package/src/services/cart.ts +50 -50
- package/src/services/category.test.ts +25 -25
- package/src/services/category.ts +8 -8
- package/src/services/channel.ts +8 -8
- package/src/services/custom-object.test.ts +184 -184
- package/src/services/custom-object.ts +48 -48
- package/src/services/customer-group.ts +8 -8
- package/src/services/customer.test.ts +151 -129
- package/src/services/customer.ts +27 -27
- package/src/services/discount-code.ts +8 -8
- package/src/services/extension.ts +8 -8
- package/src/services/index.ts +52 -44
- package/src/services/inventory-entry.test.ts +162 -162
- package/src/services/inventory-entry.ts +8 -8
- package/src/services/my-cart.test.ts +78 -78
- package/src/services/my-cart.ts +28 -28
- package/src/services/my-customer.test.ts +44 -44
- package/src/services/my-customer.ts +53 -53
- package/src/services/my-order.ts +20 -20
- package/src/services/my-payment.test.ts +65 -65
- package/src/services/my-payment.ts +8 -8
- package/src/services/order.test.ts +527 -527
- package/src/services/order.ts +31 -31
- package/src/services/payment.test.ts +65 -65
- package/src/services/payment.ts +8 -8
- package/src/services/product-discount.ts +8 -8
- package/src/services/product-projection.test.ts +492 -428
- package/src/services/product-projection.ts +32 -18
- package/src/services/product-type.test.ts +56 -56
- package/src/services/product-type.ts +8 -8
- package/src/services/product.test.ts +510 -510
- package/src/services/product.ts +8 -8
- package/src/services/project.ts +34 -34
- package/src/services/shipping-method.test.ts +81 -81
- package/src/services/shipping-method.ts +12 -12
- package/src/services/shopping-list.ts +8 -8
- package/src/services/standalone-price.test.ts +256 -256
- package/src/services/standalone-price.ts +8 -8
- package/src/services/state.test.ts +42 -42
- package/src/services/state.ts +8 -8
- package/src/services/store.test.ts +57 -57
- package/src/services/store.ts +8 -8
- package/src/services/subscription.ts +8 -8
- package/src/services/tax-category.test.ts +61 -61
- package/src/services/tax-category.ts +8 -8
- package/src/services/type.ts +8 -8
- package/src/services/zone.ts +8 -8
- package/src/storage/abstract.ts +58 -58
- package/src/storage/in-memory.ts +419 -419
- package/src/types.ts +82 -82
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
ChannelReference,
|
|
3
|
+
ChannelResourceIdentifier,
|
|
4
|
+
DiscountedPriceDraft,
|
|
5
|
+
StandalonePrice,
|
|
6
|
+
StandalonePriceChangeActiveAction,
|
|
7
|
+
StandalonePriceChangeValueAction,
|
|
8
|
+
StandalonePriceDraft,
|
|
9
|
+
StandalonePriceSetDiscountedPriceAction,
|
|
10
10
|
} from '@commercetools/platform-sdk'
|
|
11
11
|
import { getBaseResourceProperties } from '../helpers.js'
|
|
12
12
|
import type { Writable } from '../types.js'
|
|
@@ -14,61 +14,72 @@ import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
|
|
|
14
14
|
import { createTypedMoney } from './helpers.js'
|
|
15
15
|
|
|
16
16
|
export class StandAlonePriceRepository extends AbstractResourceRepository<'standalone-price'> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
getTypeId() {
|
|
18
|
+
return 'standalone-price' as const
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
create(
|
|
22
|
+
context: RepositoryContext,
|
|
23
|
+
draft: StandalonePriceDraft
|
|
24
|
+
): StandalonePrice {
|
|
25
|
+
const resource: StandalonePrice = {
|
|
26
|
+
...getBaseResourceProperties(),
|
|
27
|
+
active: draft.active ? draft.active : false,
|
|
28
|
+
sku: draft.sku,
|
|
29
|
+
value: createTypedMoney(draft.value),
|
|
30
|
+
country: draft.country,
|
|
31
|
+
discounted: draft.discounted
|
|
32
|
+
? this.transformDiscountDraft(draft.discounted)
|
|
33
|
+
: undefined,
|
|
34
|
+
channel: draft.channel?.id
|
|
35
|
+
? this.transformChannelReferenceDraft(draft.channel)
|
|
36
|
+
: undefined,
|
|
37
|
+
validFrom: draft.validFrom,
|
|
38
|
+
validUntil: draft.validUntil,
|
|
39
|
+
}
|
|
40
|
+
this.saveNew(context, resource)
|
|
41
|
+
return resource
|
|
42
|
+
}
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
transformChannelReferenceDraft(
|
|
45
|
+
channel: ChannelResourceIdentifier
|
|
46
|
+
): ChannelReference {
|
|
47
|
+
return {
|
|
48
|
+
typeId: channel.typeId,
|
|
49
|
+
id: channel.id as string,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
transformDiscountDraft(discounted: DiscountedPriceDraft) {
|
|
54
|
+
return {
|
|
55
|
+
value: createTypedMoney(discounted.value),
|
|
56
|
+
discount: discounted.discount,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
50
59
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
actions = {
|
|
61
|
+
setActive: (
|
|
62
|
+
context: RepositoryContext,
|
|
63
|
+
resource: Writable<StandalonePrice>,
|
|
64
|
+
action: StandalonePriceChangeActiveAction
|
|
65
|
+
) => {
|
|
66
|
+
resource.active = action.active
|
|
67
|
+
},
|
|
68
|
+
changeValue: (
|
|
69
|
+
context: RepositoryContext,
|
|
70
|
+
resource: Writable<StandalonePrice>,
|
|
71
|
+
action: StandalonePriceChangeValueAction
|
|
72
|
+
) => {
|
|
73
|
+
resource.value = createTypedMoney(action.value)
|
|
74
|
+
},
|
|
75
|
+
setDiscountedPrice: (
|
|
76
|
+
context: RepositoryContext,
|
|
77
|
+
resource: Writable<StandalonePrice>,
|
|
78
|
+
action: StandalonePriceSetDiscountedPriceAction
|
|
79
|
+
) => {
|
|
80
|
+
resource.discounted = action.discounted
|
|
81
|
+
? this.transformDiscountDraft(action.discounted)
|
|
82
|
+
: undefined
|
|
83
|
+
},
|
|
84
|
+
}
|
|
74
85
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
State,
|
|
3
|
+
StateChangeInitialAction,
|
|
4
|
+
StateChangeKeyAction,
|
|
5
|
+
StateDraft,
|
|
6
|
+
StateReference,
|
|
7
|
+
StateSetDescriptionAction,
|
|
8
|
+
StateSetNameAction,
|
|
9
|
+
StateSetRolesAction,
|
|
10
|
+
StateSetTransitionsAction,
|
|
11
|
+
StateUpdateAction,
|
|
12
12
|
} from '@commercetools/platform-sdk'
|
|
13
13
|
import { getBaseResourceProperties } from '../helpers.js'
|
|
14
14
|
import type { Writable } from '../types.js'
|
|
@@ -16,81 +16,81 @@ import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
|
|
|
16
16
|
import { getReferenceFromResourceIdentifier } from './helpers.js'
|
|
17
17
|
|
|
18
18
|
export class StateRepository extends AbstractResourceRepository<'state'> {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
getTypeId() {
|
|
20
|
+
return 'state' as const
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
create(context: RepositoryContext, draft: StateDraft): State {
|
|
24
|
+
const resource: State = {
|
|
25
|
+
...getBaseResourceProperties(),
|
|
26
|
+
...draft,
|
|
27
|
+
builtIn: false,
|
|
28
|
+
initial: draft.initial || false,
|
|
29
|
+
transitions: (draft.transitions || []).map((t) =>
|
|
30
|
+
getReferenceFromResourceIdentifier(t, context.projectKey, this._storage)
|
|
31
|
+
),
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
this.saveNew(context, resource)
|
|
35
|
+
return resource
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
38
|
+
actions: Partial<
|
|
39
|
+
Record<
|
|
40
|
+
StateUpdateAction['action'],
|
|
41
|
+
(
|
|
42
|
+
context: RepositoryContext,
|
|
43
|
+
resource: Writable<State>,
|
|
44
|
+
action: any
|
|
45
|
+
) => void
|
|
46
|
+
>
|
|
47
|
+
> = {
|
|
48
|
+
changeKey: (
|
|
49
|
+
context: RepositoryContext,
|
|
50
|
+
resource: Writable<State>,
|
|
51
|
+
{ key }: StateChangeKeyAction
|
|
52
|
+
) => {
|
|
53
|
+
resource.key = key
|
|
54
|
+
},
|
|
55
|
+
changeInitial: (
|
|
56
|
+
context: RepositoryContext,
|
|
57
|
+
resource: Writable<State>,
|
|
58
|
+
{ initial }: StateChangeInitialAction
|
|
59
|
+
) => {
|
|
60
|
+
resource.initial = initial
|
|
61
|
+
},
|
|
62
|
+
setDescription: (
|
|
63
|
+
context: RepositoryContext,
|
|
64
|
+
resource: Writable<State>,
|
|
65
|
+
{ description }: StateSetDescriptionAction
|
|
66
|
+
) => {
|
|
67
|
+
resource.description = description
|
|
68
|
+
},
|
|
69
|
+
setName: (
|
|
70
|
+
context: RepositoryContext,
|
|
71
|
+
resource: Writable<State>,
|
|
72
|
+
{ name }: StateSetNameAction
|
|
73
|
+
) => {
|
|
74
|
+
resource.name = name
|
|
75
|
+
},
|
|
76
|
+
setRoles: (
|
|
77
|
+
context: RepositoryContext,
|
|
78
|
+
resource: Writable<State>,
|
|
79
|
+
{ roles }: StateSetRolesAction
|
|
80
|
+
) => {
|
|
81
|
+
resource.roles = roles
|
|
82
|
+
},
|
|
83
|
+
setTransitions: (
|
|
84
|
+
context: RepositoryContext,
|
|
85
|
+
resource: Writable<State>,
|
|
86
|
+
{ transitions }: StateSetTransitionsAction
|
|
87
|
+
) => {
|
|
88
|
+
resource.transitions = transitions?.map(
|
|
89
|
+
(resourceId): StateReference => ({
|
|
90
|
+
id: resourceId.id || '',
|
|
91
|
+
typeId: 'state',
|
|
92
|
+
})
|
|
93
|
+
)
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
96
|
}
|
|
@@ -1,128 +1,128 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
ChannelReference,
|
|
3
|
+
ChannelResourceIdentifier,
|
|
4
|
+
Store,
|
|
5
|
+
StoreDraft,
|
|
6
|
+
StoreSetCustomFieldAction,
|
|
7
|
+
StoreSetCustomTypeAction,
|
|
8
|
+
StoreSetDistributionChannelsAction,
|
|
9
|
+
StoreSetLanguagesAction,
|
|
10
|
+
StoreSetNameAction,
|
|
11
|
+
StoreUpdateAction,
|
|
12
12
|
} from '@commercetools/platform-sdk'
|
|
13
13
|
import { getBaseResourceProperties } from '../helpers.js'
|
|
14
14
|
import type { Writable } from '../types.js'
|
|
15
15
|
import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
|
|
16
16
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
createCustomFields,
|
|
18
|
+
getReferenceFromResourceIdentifier,
|
|
19
19
|
} from './helpers.js'
|
|
20
20
|
|
|
21
21
|
export class StoreRepository extends AbstractResourceRepository<'store'> {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
getTypeId() {
|
|
23
|
+
return 'store' as const
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
create(context: RepositoryContext, draft: StoreDraft): Store {
|
|
27
|
+
const resource: Store = {
|
|
28
|
+
...getBaseResourceProperties(),
|
|
29
|
+
key: draft.key,
|
|
30
|
+
name: draft.name,
|
|
31
|
+
languages: draft.languages ?? [],
|
|
32
|
+
countries: draft.countries ?? [],
|
|
33
|
+
distributionChannels: this.transformChannels(
|
|
34
|
+
context,
|
|
35
|
+
draft.distributionChannels
|
|
36
|
+
),
|
|
37
|
+
supplyChannels: this.transformChannels(context, draft.supplyChannels),
|
|
38
|
+
productSelections: [],
|
|
39
|
+
custom: createCustomFields(
|
|
40
|
+
draft.custom,
|
|
41
|
+
context.projectKey,
|
|
42
|
+
this._storage
|
|
43
|
+
),
|
|
44
|
+
}
|
|
45
|
+
this.saveNew(context, resource)
|
|
46
|
+
return resource
|
|
47
|
+
}
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
private transformChannels(
|
|
50
|
+
context: RepositoryContext,
|
|
51
|
+
channels?: ChannelResourceIdentifier[]
|
|
52
|
+
) {
|
|
53
|
+
if (!channels) return []
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
return channels.map((ref) =>
|
|
56
|
+
getReferenceFromResourceIdentifier<ChannelReference>(
|
|
57
|
+
ref,
|
|
58
|
+
context.projectKey,
|
|
59
|
+
this._storage
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
64
|
+
actions: Partial<
|
|
65
|
+
Record<
|
|
66
|
+
StoreUpdateAction['action'],
|
|
67
|
+
(
|
|
68
|
+
context: RepositoryContext,
|
|
69
|
+
resource: Writable<Store>,
|
|
70
|
+
action: any
|
|
71
|
+
) => void
|
|
72
|
+
>
|
|
73
|
+
> = {
|
|
74
|
+
setName: (
|
|
75
|
+
context: RepositoryContext,
|
|
76
|
+
resource: Writable<Store>,
|
|
77
|
+
{ name }: StoreSetNameAction
|
|
78
|
+
) => {
|
|
79
|
+
resource.name = name
|
|
80
|
+
},
|
|
81
|
+
setDistributionChannels: (
|
|
82
|
+
context: RepositoryContext,
|
|
83
|
+
resource: Writable<Store>,
|
|
84
|
+
{ distributionChannels }: StoreSetDistributionChannelsAction
|
|
85
|
+
) => {
|
|
86
|
+
resource.distributionChannels = this.transformChannels(
|
|
87
|
+
context,
|
|
88
|
+
distributionChannels
|
|
89
|
+
)
|
|
90
|
+
},
|
|
91
|
+
setLanguages: (
|
|
92
|
+
context: RepositoryContext,
|
|
93
|
+
resource: Writable<Store>,
|
|
94
|
+
{ languages }: StoreSetLanguagesAction
|
|
95
|
+
) => {
|
|
96
|
+
resource.languages = languages ?? []
|
|
97
|
+
},
|
|
98
|
+
setCustomType: (
|
|
99
|
+
context: RepositoryContext,
|
|
100
|
+
resource: Writable<Store>,
|
|
101
|
+
{ type, fields }: StoreSetCustomTypeAction
|
|
102
|
+
) => {
|
|
103
|
+
if (type) {
|
|
104
|
+
resource.custom = createCustomFields(
|
|
105
|
+
{ type, fields },
|
|
106
|
+
context.projectKey,
|
|
107
|
+
this._storage
|
|
108
|
+
)
|
|
109
|
+
} else {
|
|
110
|
+
resource.custom = undefined
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
setCustomField: (
|
|
114
|
+
context: RepositoryContext,
|
|
115
|
+
resource: Writable<Store>,
|
|
116
|
+
{ name, value }: StoreSetCustomFieldAction
|
|
117
|
+
) => {
|
|
118
|
+
if (!resource.custom) {
|
|
119
|
+
return
|
|
120
|
+
}
|
|
121
|
+
if (value === null) {
|
|
122
|
+
delete resource.custom.fields[name]
|
|
123
|
+
} else {
|
|
124
|
+
resource.custom.fields[name] = value
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
}
|
|
128
128
|
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
InvalidInputError,
|
|
3
|
+
Subscription,
|
|
4
|
+
SubscriptionDraft,
|
|
5
5
|
} from '@commercetools/platform-sdk'
|
|
6
6
|
import { CommercetoolsError } from '../exceptions.js'
|
|
7
7
|
import { getBaseResourceProperties } from '../helpers.js'
|
|
8
8
|
import { AbstractResourceRepository, RepositoryContext } from './abstract.js'
|
|
9
9
|
|
|
10
10
|
export class SubscriptionRepository extends AbstractResourceRepository<'subscription'> {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
getTypeId() {
|
|
12
|
+
return 'subscription' as const
|
|
13
|
+
}
|
|
14
|
+
create(context: RepositoryContext, draft: SubscriptionDraft): Subscription {
|
|
15
|
+
// TODO: We could actually test this here by using the aws sdk. For now
|
|
16
|
+
// hardcode a failed check when account id is 0000000000
|
|
17
|
+
if (draft.destination.type === 'SQS') {
|
|
18
|
+
const queueURL = new URL(draft.destination.queueUrl)
|
|
19
|
+
const accountId = queueURL.pathname.split('/')[1]
|
|
20
|
+
if (accountId === '0000000000') {
|
|
21
|
+
const dest = draft.destination
|
|
22
|
+
throw new CommercetoolsError<InvalidInputError>(
|
|
23
|
+
{
|
|
24
|
+
code: 'InvalidInput',
|
|
25
|
+
message:
|
|
26
|
+
'A test message could not be delivered to this destination: ' +
|
|
27
|
+
`SQS ${dest.queueUrl} in ${dest.region} for ${dest.accessKey}. ` +
|
|
28
|
+
'Please make sure your destination is correctly configured.',
|
|
29
|
+
},
|
|
30
|
+
400
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
35
|
+
const resource: Subscription = {
|
|
36
|
+
...getBaseResourceProperties(),
|
|
37
|
+
changes: draft.changes || [],
|
|
38
|
+
destination: draft.destination,
|
|
39
|
+
format: draft.format || {
|
|
40
|
+
type: 'Platform',
|
|
41
|
+
},
|
|
42
|
+
key: draft.key,
|
|
43
|
+
messages: draft.messages || [],
|
|
44
|
+
status: 'Healthy',
|
|
45
|
+
}
|
|
46
|
+
this.saveNew(context, resource)
|
|
47
|
+
return resource
|
|
48
|
+
}
|
|
49
49
|
}
|