@labdigital/commercetools-mock 0.6.1 → 0.6.4
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/commercetools-mock.cjs.development.js +365 -332
- package/dist/commercetools-mock.cjs.development.js.map +1 -1
- package/dist/commercetools-mock.cjs.production.min.js +1 -1
- package/dist/commercetools-mock.cjs.production.min.js.map +1 -1
- package/dist/commercetools-mock.esm.js +365 -332
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/projectAPI.d.ts +1 -1
- package/dist/repositories/abstract.d.ts +13 -9
- package/dist/repositories/cart-discount.d.ts +3 -3
- package/dist/repositories/cart.d.ts +12 -12
- package/dist/repositories/category.d.ts +11 -11
- package/dist/repositories/channel.d.ts +2 -2
- package/dist/repositories/custom-object.d.ts +3 -3
- package/dist/repositories/customer-group.d.ts +4 -4
- package/dist/repositories/customer.d.ts +4 -4
- package/dist/repositories/discount-code.d.ts +3 -3
- package/dist/repositories/extension.d.ts +3 -3
- package/dist/repositories/helpers.d.ts +3 -0
- package/dist/repositories/inventory-entry.d.ts +7 -7
- package/dist/repositories/my-order.d.ts +6 -0
- package/dist/repositories/order.d.ts +18 -17
- package/dist/repositories/payment.d.ts +8 -8
- package/dist/repositories/product-projection.d.ts +3 -3
- package/dist/repositories/product-type.d.ts +5 -5
- package/dist/repositories/product.d.ts +4 -4
- package/dist/repositories/project.d.ts +4 -4
- package/dist/repositories/shipping-method.d.ts +3 -3
- package/dist/repositories/shopping-list.d.ts +2 -2
- package/dist/repositories/state.d.ts +3 -3
- package/dist/repositories/store.d.ts +4 -4
- package/dist/repositories/subscription.d.ts +2 -2
- package/dist/repositories/tax-category.d.ts +4 -4
- package/dist/repositories/type.d.ts +3 -3
- package/dist/repositories/zone.d.ts +3 -3
- package/dist/services/my-order.d.ts +2 -2
- package/dist/storage.d.ts +1 -1
- package/package.json +1 -1
- package/src/ctMock.ts +6 -0
- package/src/projectAPI.ts +1 -1
- package/src/repositories/abstract.ts +37 -17
- package/src/repositories/cart-discount.ts +11 -11
- package/src/repositories/cart.ts +28 -19
- package/src/repositories/category.ts +17 -13
- package/src/repositories/channel.ts +3 -3
- package/src/repositories/custom-object.ts +16 -8
- package/src/repositories/customer-group.ts +5 -5
- package/src/repositories/customer.ts +10 -6
- package/src/repositories/discount-code.ts +14 -14
- package/src/repositories/errors.ts +3 -3
- package/src/repositories/extension.ts +12 -8
- package/src/repositories/helpers.ts +9 -0
- package/src/repositories/inventory-entry.ts +17 -10
- package/src/repositories/my-order.ts +19 -0
- package/src/repositories/order.test.ts +79 -3
- package/src/repositories/order.ts +77 -37
- package/src/repositories/payment.ts +21 -17
- package/src/repositories/product-projection.ts +5 -5
- package/src/repositories/product-type.ts +14 -10
- package/src/repositories/product.ts +5 -5
- package/src/repositories/project.ts +21 -17
- package/src/repositories/shipping-method.ts +27 -20
- package/src/repositories/shopping-list.ts +10 -6
- package/src/repositories/state.ts +13 -9
- package/src/repositories/store.ts +18 -14
- package/src/repositories/subscription.ts +3 -3
- package/src/repositories/tax-category.ts +16 -12
- package/src/repositories/type.ts +15 -11
- package/src/repositories/zone.ts +13 -9
- package/src/services/abstract.ts +17 -9
- package/src/services/cart.ts +6 -12
- package/src/services/custom-object.ts +8 -4
- package/src/services/customer.ts +5 -2
- package/src/services/my-customer.ts +7 -3
- package/src/services/my-order.ts +3 -3
- package/src/services/order.ts +3 -2
- package/src/services/product-projection.ts +2 -1
- package/src/services/product-type.ts +2 -1
- package/src/services/project.ts +4 -4
- package/src/services/store.ts +2 -1
- package/src/services/tax-category.ts +2 -1
- package/src/storage.ts +1 -1
|
@@ -17,12 +17,12 @@ import { InvalidOperationError } from '@commercetools/platform-sdk'
|
|
|
17
17
|
import { Writable } from 'types'
|
|
18
18
|
import { checkConcurrentModification } from './errors'
|
|
19
19
|
import { CommercetoolsError } from '../exceptions'
|
|
20
|
-
import { AbstractRepository } from './abstract'
|
|
20
|
+
import { AbstractRepository, RepositoryContext } from './abstract'
|
|
21
21
|
import { maskSecretValue } from '../lib/masking'
|
|
22
22
|
|
|
23
23
|
export class ProjectRepository extends AbstractRepository {
|
|
24
|
-
get(
|
|
25
|
-
const resource = this._storage.getProject(projectKey)
|
|
24
|
+
get(context: RepositoryContext): Project | null {
|
|
25
|
+
const resource = this._storage.getProject(context.projectKey)
|
|
26
26
|
const masked = maskSecretValue<Project>(
|
|
27
27
|
resource,
|
|
28
28
|
'externalOAuth.authorizationHeader'
|
|
@@ -30,8 +30,8 @@ export class ProjectRepository extends AbstractRepository {
|
|
|
30
30
|
return masked
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
save(
|
|
34
|
-
const current = this.get(
|
|
33
|
+
save(context: RepositoryContext, resource: Project) {
|
|
34
|
+
const current = this.get(context)
|
|
35
35
|
|
|
36
36
|
if (current) {
|
|
37
37
|
checkConcurrentModification(current, resource.version)
|
|
@@ -55,46 +55,50 @@ export class ProjectRepository extends AbstractRepository {
|
|
|
55
55
|
actions: Partial<
|
|
56
56
|
Record<
|
|
57
57
|
ProjectUpdateAction['action'],
|
|
58
|
-
(
|
|
58
|
+
(
|
|
59
|
+
context: RepositoryContext,
|
|
60
|
+
resource: Writable<Project>,
|
|
61
|
+
action: any
|
|
62
|
+
) => void
|
|
59
63
|
>
|
|
60
64
|
> = {
|
|
61
65
|
changeName: (
|
|
62
|
-
|
|
66
|
+
context: RepositoryContext,
|
|
63
67
|
resource: Writable<Project>,
|
|
64
68
|
{ name }: ProjectChangeNameAction
|
|
65
69
|
) => {
|
|
66
70
|
resource.name = name
|
|
67
71
|
},
|
|
68
72
|
changeCurrencies: (
|
|
69
|
-
|
|
73
|
+
context: RepositoryContext,
|
|
70
74
|
resource: Writable<Project>,
|
|
71
75
|
{ currencies }: ProjectChangeCurrenciesAction
|
|
72
76
|
) => {
|
|
73
77
|
resource.currencies = currencies
|
|
74
78
|
},
|
|
75
79
|
changeCountries: (
|
|
76
|
-
|
|
80
|
+
context: RepositoryContext,
|
|
77
81
|
resource: Writable<Project>,
|
|
78
82
|
{ countries }: ProjectChangeCountriesAction
|
|
79
83
|
) => {
|
|
80
84
|
resource.countries = countries
|
|
81
85
|
},
|
|
82
86
|
changeLanguages: (
|
|
83
|
-
|
|
87
|
+
context: RepositoryContext,
|
|
84
88
|
resource: Writable<Project>,
|
|
85
89
|
{ languages }: ProjectChangeLanguagesAction
|
|
86
90
|
) => {
|
|
87
91
|
resource.languages = languages
|
|
88
92
|
},
|
|
89
93
|
changeMessagesEnabled: (
|
|
90
|
-
|
|
94
|
+
context: RepositoryContext,
|
|
91
95
|
resource: Writable<Project>,
|
|
92
96
|
{ messagesEnabled }: ProjectChangeMessagesEnabledAction
|
|
93
97
|
) => {
|
|
94
98
|
resource.messages.enabled = messagesEnabled
|
|
95
99
|
},
|
|
96
100
|
changeProductSearchIndexingEnabled: (
|
|
97
|
-
|
|
101
|
+
context: RepositoryContext,
|
|
98
102
|
resource: Writable<Project>,
|
|
99
103
|
{ enabled }: ProjectChangeProductSearchIndexingEnabledAction
|
|
100
104
|
) => {
|
|
@@ -107,7 +111,7 @@ export class ProjectRepository extends AbstractRepository {
|
|
|
107
111
|
resource.searchIndexing.products.lastModifiedAt = new Date().toISOString()
|
|
108
112
|
},
|
|
109
113
|
changeOrderSearchStatus: (
|
|
110
|
-
|
|
114
|
+
context: RepositoryContext,
|
|
111
115
|
resource: Writable<Project>,
|
|
112
116
|
{ status }: ProjectChangeOrderSearchStatusAction
|
|
113
117
|
) => {
|
|
@@ -118,21 +122,21 @@ export class ProjectRepository extends AbstractRepository {
|
|
|
118
122
|
resource.searchIndexing.orders.lastModifiedAt = new Date().toISOString()
|
|
119
123
|
},
|
|
120
124
|
setShippingRateInputType: (
|
|
121
|
-
|
|
125
|
+
context: RepositoryContext,
|
|
122
126
|
resource: Writable<Project>,
|
|
123
127
|
{ shippingRateInputType }: ProjectSetShippingRateInputTypeAction
|
|
124
128
|
) => {
|
|
125
129
|
resource.shippingRateInputType = shippingRateInputType
|
|
126
130
|
},
|
|
127
131
|
setExternalOAuth: (
|
|
128
|
-
|
|
132
|
+
context: RepositoryContext,
|
|
129
133
|
resource: Writable<Project>,
|
|
130
134
|
{ externalOAuth }: ProjectSetExternalOAuthAction
|
|
131
135
|
) => {
|
|
132
136
|
resource.externalOAuth = externalOAuth
|
|
133
137
|
},
|
|
134
138
|
changeCountryTaxRateFallbackEnabled: (
|
|
135
|
-
|
|
139
|
+
context: RepositoryContext,
|
|
136
140
|
resource: Writable<Project>,
|
|
137
141
|
{
|
|
138
142
|
countryTaxRateFallbackEnabled,
|
|
@@ -141,7 +145,7 @@ export class ProjectRepository extends AbstractRepository {
|
|
|
141
145
|
resource.carts.countryTaxRateFallbackEnabled = countryTaxRateFallbackEnabled
|
|
142
146
|
},
|
|
143
147
|
changeCartsConfiguration: (
|
|
144
|
-
|
|
148
|
+
context: RepositoryContext,
|
|
145
149
|
resource: Writable<Project>,
|
|
146
150
|
{ cartsConfiguration }: ProjectChangeCartsConfigurationAction
|
|
147
151
|
) => {
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
ZoneReference,
|
|
25
25
|
} from '@commercetools/platform-sdk'
|
|
26
26
|
import { getBaseResourceProperties } from '../helpers'
|
|
27
|
-
import { AbstractResourceRepository } from './abstract'
|
|
27
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
28
28
|
import { Writable } from 'types'
|
|
29
29
|
import deepEqual from 'deep-equal'
|
|
30
30
|
|
|
@@ -33,32 +33,39 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
33
33
|
return 'shipping-method'
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
create(
|
|
36
|
+
create(
|
|
37
|
+
context: RepositoryContext,
|
|
38
|
+
draft: ShippingMethodDraft
|
|
39
|
+
): ShippingMethod {
|
|
37
40
|
const resource: ShippingMethod = {
|
|
38
41
|
...getBaseResourceProperties(),
|
|
39
42
|
...draft,
|
|
40
43
|
taxCategory: getReferenceFromResourceIdentifier(
|
|
41
44
|
draft.taxCategory,
|
|
42
|
-
projectKey,
|
|
45
|
+
context.projectKey,
|
|
43
46
|
this._storage
|
|
44
47
|
),
|
|
45
48
|
zoneRates: draft.zoneRates?.map(z =>
|
|
46
|
-
this._transformZoneRateDraft(
|
|
49
|
+
this._transformZoneRateDraft(context, z)
|
|
50
|
+
),
|
|
51
|
+
custom: createCustomFields(
|
|
52
|
+
draft.custom,
|
|
53
|
+
context.projectKey,
|
|
54
|
+
this._storage
|
|
47
55
|
),
|
|
48
|
-
custom: createCustomFields(draft.custom, projectKey, this._storage),
|
|
49
56
|
}
|
|
50
|
-
this.save(
|
|
57
|
+
this.save(context, resource)
|
|
51
58
|
return resource
|
|
52
59
|
}
|
|
53
60
|
|
|
54
61
|
private _transformZoneRateDraft = (
|
|
55
|
-
|
|
62
|
+
context: RepositoryContext,
|
|
56
63
|
draft: ZoneRateDraft
|
|
57
64
|
): ZoneRate => ({
|
|
58
65
|
...draft,
|
|
59
66
|
zone: getReferenceFromResourceIdentifier<ZoneReference>(
|
|
60
67
|
draft.zone,
|
|
61
|
-
projectKey,
|
|
68
|
+
context.projectKey,
|
|
62
69
|
this._storage
|
|
63
70
|
),
|
|
64
71
|
shippingRates: draft.shippingRates?.map(this._transformShippingRate),
|
|
@@ -76,14 +83,14 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
76
83
|
Record<
|
|
77
84
|
ShippingMethodUpdateAction['action'],
|
|
78
85
|
(
|
|
79
|
-
|
|
86
|
+
context: RepositoryContext,
|
|
80
87
|
resource: Writable<ShippingMethod>,
|
|
81
88
|
action: any
|
|
82
89
|
) => void
|
|
83
90
|
>
|
|
84
91
|
> = {
|
|
85
92
|
addShippingRate: (
|
|
86
|
-
|
|
93
|
+
_context: RepositoryContext,
|
|
87
94
|
resource: Writable<ShippingMethod>,
|
|
88
95
|
{ shippingRate, zone }: ShippingMethodAddShippingRateAction
|
|
89
96
|
) => {
|
|
@@ -104,7 +111,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
104
111
|
})
|
|
105
112
|
},
|
|
106
113
|
removeShippingRate: (
|
|
107
|
-
|
|
114
|
+
_context: RepositoryContext,
|
|
108
115
|
resource: Writable<ShippingMethod>,
|
|
109
116
|
{ shippingRate, zone }: ShippingMethodAddShippingRateAction
|
|
110
117
|
) => {
|
|
@@ -119,13 +126,13 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
119
126
|
})
|
|
120
127
|
},
|
|
121
128
|
addZone: (
|
|
122
|
-
|
|
129
|
+
context: RepositoryContext,
|
|
123
130
|
resource: Writable<ShippingMethod>,
|
|
124
131
|
{ zone }: ShippingMethodAddZoneAction
|
|
125
132
|
) => {
|
|
126
133
|
const zoneReference = getReferenceFromResourceIdentifier<ZoneReference>(
|
|
127
134
|
zone,
|
|
128
|
-
projectKey,
|
|
135
|
+
context.projectKey,
|
|
129
136
|
this._storage
|
|
130
137
|
)
|
|
131
138
|
|
|
@@ -139,7 +146,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
139
146
|
})
|
|
140
147
|
},
|
|
141
148
|
removeZone: (
|
|
142
|
-
|
|
149
|
+
_context: RepositoryContext,
|
|
143
150
|
resource: Writable<ShippingMethod>,
|
|
144
151
|
{ zone }: ShippingMethodRemoveZoneAction
|
|
145
152
|
) => {
|
|
@@ -148,42 +155,42 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
148
155
|
})
|
|
149
156
|
},
|
|
150
157
|
setKey: (
|
|
151
|
-
|
|
158
|
+
_context: RepositoryContext,
|
|
152
159
|
resource: Writable<ShippingMethod>,
|
|
153
160
|
{ key }: ShippingMethodSetKeyAction
|
|
154
161
|
) => {
|
|
155
162
|
resource.key = key
|
|
156
163
|
},
|
|
157
164
|
setDescription: (
|
|
158
|
-
|
|
165
|
+
_context: RepositoryContext,
|
|
159
166
|
resource: Writable<ShippingMethod>,
|
|
160
167
|
{ description }: ShippingMethodSetDescriptionAction
|
|
161
168
|
) => {
|
|
162
169
|
resource.description = description
|
|
163
170
|
},
|
|
164
171
|
setLocalizedDescription: (
|
|
165
|
-
|
|
172
|
+
_context: RepositoryContext,
|
|
166
173
|
resource: Writable<ShippingMethod>,
|
|
167
174
|
{ localizedDescription }: ShippingMethodSetLocalizedDescriptionAction
|
|
168
175
|
) => {
|
|
169
176
|
resource.localizedDescription = localizedDescription
|
|
170
177
|
},
|
|
171
178
|
setPredicate: (
|
|
172
|
-
|
|
179
|
+
_context: RepositoryContext,
|
|
173
180
|
resource: Writable<ShippingMethod>,
|
|
174
181
|
{ predicate }: ShippingMethodSetPredicateAction
|
|
175
182
|
) => {
|
|
176
183
|
resource.predicate = predicate
|
|
177
184
|
},
|
|
178
185
|
changeIsDefault: (
|
|
179
|
-
|
|
186
|
+
_context: RepositoryContext,
|
|
180
187
|
resource: Writable<ShippingMethod>,
|
|
181
188
|
{ isDefault }: ShippingMethodChangeIsDefaultAction
|
|
182
189
|
) => {
|
|
183
190
|
resource.isDefault = isDefault
|
|
184
191
|
},
|
|
185
192
|
changeName: (
|
|
186
|
-
|
|
193
|
+
_context: RepositoryContext,
|
|
187
194
|
resource: Writable<ShippingMethod>,
|
|
188
195
|
{ name }: ShippingMethodChangeNameAction
|
|
189
196
|
) => {
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ShoppingListDraft,
|
|
6
6
|
} from '@commercetools/platform-sdk'
|
|
7
7
|
import { getBaseResourceProperties } from '../helpers'
|
|
8
|
-
import { AbstractResourceRepository } from './abstract'
|
|
8
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
9
9
|
import {
|
|
10
10
|
createCustomFields,
|
|
11
11
|
getReferenceFromResourceIdentifier,
|
|
@@ -15,13 +15,17 @@ export class ShoppingListRepository extends AbstractResourceRepository {
|
|
|
15
15
|
getTypeId(): ReferenceTypeId {
|
|
16
16
|
return 'shopping-list'
|
|
17
17
|
}
|
|
18
|
-
create(
|
|
18
|
+
create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList {
|
|
19
19
|
// const product =
|
|
20
20
|
|
|
21
21
|
const resource: ShoppingList = {
|
|
22
22
|
...getBaseResourceProperties(),
|
|
23
23
|
...draft,
|
|
24
|
-
custom: createCustomFields(
|
|
24
|
+
custom: createCustomFields(
|
|
25
|
+
draft.custom,
|
|
26
|
+
context.projectKey,
|
|
27
|
+
this._storage
|
|
28
|
+
),
|
|
25
29
|
textLineItems: [],
|
|
26
30
|
lineItems: draft.lineItems?.map(e => ({
|
|
27
31
|
...getBaseResourceProperties(),
|
|
@@ -31,12 +35,12 @@ export class ShoppingListRepository extends AbstractResourceRepository {
|
|
|
31
35
|
name: {},
|
|
32
36
|
quantity: e.quantity ?? 1,
|
|
33
37
|
productType: { typeId: 'product-type', id: '' },
|
|
34
|
-
custom: createCustomFields(e.custom, projectKey, this._storage),
|
|
38
|
+
custom: createCustomFields(e.custom, context.projectKey, this._storage),
|
|
35
39
|
})),
|
|
36
40
|
customer: draft.customer
|
|
37
41
|
? getReferenceFromResourceIdentifier<CustomerReference>(
|
|
38
42
|
draft.customer,
|
|
39
|
-
projectKey,
|
|
43
|
+
context.projectKey,
|
|
40
44
|
this._storage
|
|
41
45
|
)
|
|
42
46
|
: undefined,
|
|
@@ -44,7 +48,7 @@ export class ShoppingListRepository extends AbstractResourceRepository {
|
|
|
44
48
|
? { typeId: 'store', key: draft.store.key! }
|
|
45
49
|
: undefined,
|
|
46
50
|
}
|
|
47
|
-
this.save(
|
|
51
|
+
this.save(context, resource)
|
|
48
52
|
return resource
|
|
49
53
|
}
|
|
50
54
|
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
StateSetRolesAction,
|
|
11
11
|
StateUpdateAction,
|
|
12
12
|
} from '@commercetools/platform-sdk'
|
|
13
|
-
import { AbstractResourceRepository } from './abstract'
|
|
13
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
14
14
|
import { Writable } from 'types'
|
|
15
15
|
|
|
16
16
|
export class StateRepository extends AbstractResourceRepository {
|
|
@@ -18,50 +18,54 @@ export class StateRepository extends AbstractResourceRepository {
|
|
|
18
18
|
return 'state'
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
create(
|
|
21
|
+
create(context: RepositoryContext, draft: StateDraft): State {
|
|
22
22
|
const resource: State = {
|
|
23
23
|
...getBaseResourceProperties(),
|
|
24
24
|
...draft,
|
|
25
25
|
builtIn: false,
|
|
26
26
|
initial: draft.initial || false,
|
|
27
27
|
transitions: (draft.transitions || []).map(t =>
|
|
28
|
-
getReferenceFromResourceIdentifier(t, projectKey, this._storage)
|
|
28
|
+
getReferenceFromResourceIdentifier(t, context.projectKey, this._storage)
|
|
29
29
|
),
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
this.save(
|
|
32
|
+
this.save(context, resource)
|
|
33
33
|
return resource
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
actions: Partial<
|
|
37
37
|
Record<
|
|
38
38
|
StateUpdateAction['action'],
|
|
39
|
-
(
|
|
39
|
+
(
|
|
40
|
+
context: RepositoryContext,
|
|
41
|
+
resource: Writable<State>,
|
|
42
|
+
action: any
|
|
43
|
+
) => void
|
|
40
44
|
>
|
|
41
45
|
> = {
|
|
42
46
|
changeKey: (
|
|
43
|
-
|
|
47
|
+
context: RepositoryContext,
|
|
44
48
|
resource: Writable<State>,
|
|
45
49
|
{ key }: StateChangeKeyAction
|
|
46
50
|
) => {
|
|
47
51
|
resource.key = key
|
|
48
52
|
},
|
|
49
53
|
setDescription: (
|
|
50
|
-
|
|
54
|
+
context: RepositoryContext,
|
|
51
55
|
resource: Writable<State>,
|
|
52
56
|
{ description }: StateSetDescriptionAction
|
|
53
57
|
) => {
|
|
54
58
|
resource.description = description
|
|
55
59
|
},
|
|
56
60
|
setName: (
|
|
57
|
-
|
|
61
|
+
context: RepositoryContext,
|
|
58
62
|
resource: Writable<State>,
|
|
59
63
|
{ name }: StateSetNameAction
|
|
60
64
|
) => {
|
|
61
65
|
resource.name = name
|
|
62
66
|
},
|
|
63
67
|
setRoles: (
|
|
64
|
-
|
|
68
|
+
context: RepositoryContext,
|
|
65
69
|
resource: Writable<State>,
|
|
66
70
|
{ roles }: StateSetRolesAction
|
|
67
71
|
) => {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from '@commercetools/platform-sdk'
|
|
12
12
|
import { Writable } from 'types'
|
|
13
13
|
import { getBaseResourceProperties } from '../helpers'
|
|
14
|
-
import { AbstractResourceRepository } from './abstract'
|
|
14
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
15
15
|
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
16
16
|
|
|
17
17
|
export class StoreRepository extends AbstractResourceRepository {
|
|
@@ -19,24 +19,24 @@ export class StoreRepository extends AbstractResourceRepository {
|
|
|
19
19
|
return 'store'
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
create(
|
|
22
|
+
create(context: RepositoryContext, draft: StoreDraft): Store {
|
|
23
23
|
const resource: Store = {
|
|
24
24
|
...getBaseResourceProperties(),
|
|
25
25
|
key: draft.key,
|
|
26
26
|
name: draft.name,
|
|
27
27
|
languages: draft.languages,
|
|
28
28
|
distributionChannels: this.transformChannels(
|
|
29
|
-
|
|
29
|
+
context,
|
|
30
30
|
draft.distributionChannels
|
|
31
31
|
),
|
|
32
|
-
supplyChannels: this.transformChannels(
|
|
32
|
+
supplyChannels: this.transformChannels(context, draft.supplyChannels),
|
|
33
33
|
}
|
|
34
|
-
this.save(
|
|
34
|
+
this.save(context, resource)
|
|
35
35
|
return resource
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
private transformChannels(
|
|
39
|
-
|
|
39
|
+
context: RepositoryContext,
|
|
40
40
|
channels?: ChannelResourceIdentifier[]
|
|
41
41
|
) {
|
|
42
42
|
if (!channels) return []
|
|
@@ -44,14 +44,14 @@ export class StoreRepository extends AbstractResourceRepository {
|
|
|
44
44
|
return channels.map(ref =>
|
|
45
45
|
getReferenceFromResourceIdentifier<ChannelReference>(
|
|
46
46
|
ref,
|
|
47
|
-
projectKey,
|
|
47
|
+
context.projectKey,
|
|
48
48
|
this._storage
|
|
49
49
|
)
|
|
50
50
|
)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
getWithKey(
|
|
54
|
-
const result = this._storage.query(projectKey, this.getTypeId(), {
|
|
53
|
+
getWithKey(context: RepositoryContext, key: string): Store | undefined {
|
|
54
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
55
55
|
where: [`key="${key}"`],
|
|
56
56
|
})
|
|
57
57
|
if (result.count === 1) {
|
|
@@ -68,28 +68,32 @@ export class StoreRepository extends AbstractResourceRepository {
|
|
|
68
68
|
actions: Partial<
|
|
69
69
|
Record<
|
|
70
70
|
StoreUpdateAction['action'],
|
|
71
|
-
(
|
|
71
|
+
(
|
|
72
|
+
context: RepositoryContext,
|
|
73
|
+
resource: Writable<Store>,
|
|
74
|
+
action: any
|
|
75
|
+
) => void
|
|
72
76
|
>
|
|
73
77
|
> = {
|
|
74
78
|
setName: (
|
|
75
|
-
|
|
79
|
+
context: RepositoryContext,
|
|
76
80
|
resource: Writable<Store>,
|
|
77
81
|
{ name }: StoreSetNameAction
|
|
78
82
|
) => {
|
|
79
83
|
resource.name = name
|
|
80
84
|
},
|
|
81
85
|
setDistributionChannels: (
|
|
82
|
-
|
|
86
|
+
context: RepositoryContext,
|
|
83
87
|
resource: Writable<Store>,
|
|
84
88
|
{ distributionChannels }: StoreSetDistributionChannelsAction
|
|
85
89
|
) => {
|
|
86
90
|
resource.distributionChannels = this.transformChannels(
|
|
87
|
-
|
|
91
|
+
context,
|
|
88
92
|
distributionChannels
|
|
89
93
|
)
|
|
90
94
|
},
|
|
91
95
|
setLanguages: (
|
|
92
|
-
|
|
96
|
+
context: RepositoryContext,
|
|
93
97
|
resource: Writable<Store>,
|
|
94
98
|
{ languages }: StoreSetLanguagesAction
|
|
95
99
|
) => {
|
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
} from '@commercetools/platform-sdk'
|
|
7
7
|
import { CommercetoolsError } from '../exceptions'
|
|
8
8
|
import { getBaseResourceProperties } from '../helpers'
|
|
9
|
-
import { AbstractResourceRepository } from './abstract'
|
|
9
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
10
10
|
|
|
11
11
|
export class SubscriptionRepository extends AbstractResourceRepository {
|
|
12
12
|
getTypeId(): ReferenceTypeId {
|
|
13
13
|
return 'subscription'
|
|
14
14
|
}
|
|
15
|
-
create(
|
|
15
|
+
create(context: RepositoryContext, draft: SubscriptionDraft): Subscription {
|
|
16
16
|
// TODO: We could actually test this here by using the aws sdk. For now
|
|
17
17
|
// hardcode a failed check when account id is 0000000000
|
|
18
18
|
if (draft.destination.type === 'SQS') {
|
|
@@ -44,7 +44,7 @@ export class SubscriptionRepository extends AbstractResourceRepository {
|
|
|
44
44
|
messages: draft.messages || [],
|
|
45
45
|
status: 'Healthy',
|
|
46
46
|
}
|
|
47
|
-
this.save(
|
|
47
|
+
this.save(context, resource)
|
|
48
48
|
return resource
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
TaxRateDraft,
|
|
14
14
|
} from '@commercetools/platform-sdk'
|
|
15
15
|
import { getBaseResourceProperties } from '../helpers'
|
|
16
|
-
import { AbstractResourceRepository } from './abstract'
|
|
16
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
17
17
|
import { v4 as uuidv4 } from 'uuid'
|
|
18
18
|
import { Writable } from 'types'
|
|
19
19
|
|
|
@@ -22,13 +22,13 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
22
22
|
return 'tax-category'
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
create(
|
|
25
|
+
create(context: RepositoryContext, draft: TaxCategoryDraft): TaxCategory {
|
|
26
26
|
const resource: TaxCategory = {
|
|
27
27
|
...getBaseResourceProperties(),
|
|
28
28
|
...draft,
|
|
29
29
|
rates: draft.rates?.map(this.taxRateFromTaxRateDraft) || [],
|
|
30
30
|
}
|
|
31
|
-
this.save(
|
|
31
|
+
this.save(context, resource)
|
|
32
32
|
return resource
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -38,8 +38,8 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
38
38
|
amount: draft.amount || 0,
|
|
39
39
|
})
|
|
40
40
|
|
|
41
|
-
getWithKey(
|
|
42
|
-
const result = this._storage.query(projectKey, this.getTypeId(), {
|
|
41
|
+
getWithKey(context: RepositoryContext, key: string): TaxCategory | undefined {
|
|
42
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
43
43
|
where: [`key="${key}"`],
|
|
44
44
|
})
|
|
45
45
|
if (result.count === 1) {
|
|
@@ -57,11 +57,15 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
57
57
|
actions: Partial<
|
|
58
58
|
Record<
|
|
59
59
|
TaxCategoryUpdateAction['action'],
|
|
60
|
-
(
|
|
60
|
+
(
|
|
61
|
+
context: RepositoryContext,
|
|
62
|
+
resource: Writable<TaxCategory>,
|
|
63
|
+
action: any
|
|
64
|
+
) => void
|
|
61
65
|
>
|
|
62
66
|
> = {
|
|
63
67
|
addTaxRate: (
|
|
64
|
-
|
|
68
|
+
context: RepositoryContext,
|
|
65
69
|
resource: Writable<TaxCategory>,
|
|
66
70
|
{ taxRate }: TaxCategoryAddTaxRateAction
|
|
67
71
|
) => {
|
|
@@ -71,7 +75,7 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
71
75
|
resource.rates.push(this.taxRateFromTaxRateDraft(taxRate))
|
|
72
76
|
},
|
|
73
77
|
removeTaxRate: (
|
|
74
|
-
|
|
78
|
+
context: RepositoryContext,
|
|
75
79
|
resource: Writable<TaxCategory>,
|
|
76
80
|
{ taxRateId }: TaxCategoryRemoveTaxRateAction
|
|
77
81
|
) => {
|
|
@@ -83,7 +87,7 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
83
87
|
})
|
|
84
88
|
},
|
|
85
89
|
replaceTaxRate: (
|
|
86
|
-
|
|
90
|
+
context: RepositoryContext,
|
|
87
91
|
resource: Writable<TaxCategory>,
|
|
88
92
|
{ taxRateId, taxRate }: TaxCategoryReplaceTaxRateAction
|
|
89
93
|
) => {
|
|
@@ -100,21 +104,21 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
100
104
|
}
|
|
101
105
|
},
|
|
102
106
|
setDescription: (
|
|
103
|
-
|
|
107
|
+
context: RepositoryContext,
|
|
104
108
|
resource: Writable<TaxCategory>,
|
|
105
109
|
{ description }: TaxCategorySetDescriptionAction
|
|
106
110
|
) => {
|
|
107
111
|
resource.description = description
|
|
108
112
|
},
|
|
109
113
|
setKey: (
|
|
110
|
-
|
|
114
|
+
context: RepositoryContext,
|
|
111
115
|
resource: Writable<TaxCategory>,
|
|
112
116
|
{ key }: TaxCategorySetKeyAction
|
|
113
117
|
) => {
|
|
114
118
|
resource.key = key
|
|
115
119
|
},
|
|
116
120
|
changeName: (
|
|
117
|
-
|
|
121
|
+
context: RepositoryContext,
|
|
118
122
|
resource: Writable<TaxCategory>,
|
|
119
123
|
{ name }: TaxCategoryChangeNameAction
|
|
120
124
|
) => {
|