@labdigital/commercetools-mock 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +353 -188
- package/dist/index.global.js +1007 -876
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +348 -217
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +348 -217
- 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 +117 -10
- package/src/repositories/project.ts +9 -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 +15 -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 +63 -2
- package/src/services/product.ts +1 -1
- package/src/services/project.ts +4 -5
- 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
|
@@ -7,23 +7,24 @@ import {
|
|
|
7
7
|
ProductPublishAction,
|
|
8
8
|
ProductSetAttributeAction,
|
|
9
9
|
ProductSetDescriptionAction,
|
|
10
|
+
ProductAddExternalImageAction,
|
|
11
|
+
ProductRemoveImageAction,
|
|
10
12
|
ProductSetKeyAction,
|
|
11
13
|
ProductTypeReference,
|
|
12
14
|
ProductUpdateAction,
|
|
13
15
|
ProductVariant,
|
|
14
16
|
ProductVariantDraft,
|
|
15
|
-
ReferenceTypeId,
|
|
16
17
|
} from '@commercetools/platform-sdk'
|
|
17
18
|
import { v4 as uuidv4 } from 'uuid'
|
|
19
|
+
import { Writable } from '../types'
|
|
18
20
|
import { getBaseResourceProperties } from '../helpers'
|
|
19
21
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
20
|
-
import { Writable } from '../types'
|
|
21
22
|
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
22
23
|
import deepEqual from 'deep-equal'
|
|
23
24
|
|
|
24
|
-
export class ProductRepository extends AbstractResourceRepository {
|
|
25
|
-
getTypeId()
|
|
26
|
-
return 'product'
|
|
25
|
+
export class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
26
|
+
getTypeId() {
|
|
27
|
+
return 'product' as const
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
create(context: RepositoryContext, draft: ProductDraft): Product {
|
|
@@ -100,7 +101,7 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
100
101
|
},
|
|
101
102
|
unpublish: (
|
|
102
103
|
context: RepositoryContext,
|
|
103
|
-
resource: Writable<Product
|
|
104
|
+
resource: Writable<Product>
|
|
104
105
|
// { action }: ProductUnpublishAction
|
|
105
106
|
) => {
|
|
106
107
|
resource.masterData.published = false
|
|
@@ -162,7 +163,7 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
162
163
|
|
|
163
164
|
return resource
|
|
164
165
|
},
|
|
165
|
-
|
|
166
|
+
setDescription: (
|
|
166
167
|
context: RepositoryContext,
|
|
167
168
|
resource: Writable<Product>,
|
|
168
169
|
{ description, staged }: ProductSetDescriptionAction
|
|
@@ -176,7 +177,7 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
176
177
|
checkForStagedChanges(resource)
|
|
177
178
|
return resource
|
|
178
179
|
},
|
|
179
|
-
|
|
180
|
+
setKey: (
|
|
180
181
|
context: RepositoryContext,
|
|
181
182
|
resource: Writable<Product>,
|
|
182
183
|
{ key }: ProductSetKeyAction
|
|
@@ -184,6 +185,114 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
184
185
|
resource.key = key
|
|
185
186
|
return resource
|
|
186
187
|
},
|
|
188
|
+
addExternalImage: (
|
|
189
|
+
context: RepositoryContext,
|
|
190
|
+
resource: Writable<Product>,
|
|
191
|
+
{ variantId, sku, image, staged }: ProductAddExternalImageAction
|
|
192
|
+
) => {
|
|
193
|
+
const addImg = (data: Writable<ProductData>) => {
|
|
194
|
+
const { variant, isMasterVariant, variantIndex } = getVariant(
|
|
195
|
+
data,
|
|
196
|
+
variantId,
|
|
197
|
+
sku
|
|
198
|
+
)
|
|
199
|
+
if (!variant) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (!variant.images) {
|
|
206
|
+
variant.images = []
|
|
207
|
+
} else {
|
|
208
|
+
const existingImage = variant.images.find((x) => x.url === image.url)
|
|
209
|
+
if (existingImage) {
|
|
210
|
+
throw new Error(
|
|
211
|
+
`Cannot add image '${image.url}' because product '${resource.id}' already has that image.`
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Add image
|
|
217
|
+
variant.images.push(image)
|
|
218
|
+
|
|
219
|
+
if (isMasterVariant) {
|
|
220
|
+
data.masterVariant = variant
|
|
221
|
+
} else {
|
|
222
|
+
data.variants[variantIndex] = variant
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// If true, only the staged Attribute is set. If false, both current and
|
|
227
|
+
// staged Attribute is set. Default is true
|
|
228
|
+
const onlyStaged = staged !== undefined ? staged : true
|
|
229
|
+
|
|
230
|
+
// Write the attribute to the staged data
|
|
231
|
+
addImg(resource.masterData.staged)
|
|
232
|
+
|
|
233
|
+
// Also write to published data is isStaged = false
|
|
234
|
+
// if isStaged is false we set the attribute on both the staged and
|
|
235
|
+
// published data.
|
|
236
|
+
if (!onlyStaged) {
|
|
237
|
+
addImg(resource.masterData.current)
|
|
238
|
+
}
|
|
239
|
+
checkForStagedChanges(resource)
|
|
240
|
+
|
|
241
|
+
return resource
|
|
242
|
+
},
|
|
243
|
+
removeImage: (
|
|
244
|
+
context: RepositoryContext,
|
|
245
|
+
resource: Writable<Product>,
|
|
246
|
+
{ variantId, sku, imageUrl, staged }: ProductRemoveImageAction
|
|
247
|
+
) => {
|
|
248
|
+
const removeImg = (data: Writable<ProductData>) => {
|
|
249
|
+
const { variant, isMasterVariant, variantIndex } = getVariant(
|
|
250
|
+
data,
|
|
251
|
+
variantId,
|
|
252
|
+
sku
|
|
253
|
+
)
|
|
254
|
+
if (!variant) {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
|
|
257
|
+
)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const variantImages = variant.images ?? []
|
|
261
|
+
const existingImage = variantImages.find((x) => x.url === imageUrl)
|
|
262
|
+
if (!existingImage) {
|
|
263
|
+
throw new Error(
|
|
264
|
+
`Cannot remove image '${imageUrl}' because product '${resource.id}' does not have that image.`
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Remove image
|
|
269
|
+
variant.images = variantImages.filter((image) => image.url !== imageUrl)
|
|
270
|
+
|
|
271
|
+
if (isMasterVariant) {
|
|
272
|
+
data.masterVariant = variant
|
|
273
|
+
} else {
|
|
274
|
+
data.variants[variantIndex] = variant
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// If true, only the staged Attribute is set. If false, both current and
|
|
279
|
+
// staged Attribute is set. Default is true
|
|
280
|
+
const onlyStaged = staged !== undefined ? staged : true
|
|
281
|
+
|
|
282
|
+
// Write the attribute to the staged data
|
|
283
|
+
removeImg(resource.masterData.staged)
|
|
284
|
+
|
|
285
|
+
// Also write to published data is isStaged = false
|
|
286
|
+
// if isStaged is false we set the attribute on both the staged and
|
|
287
|
+
// published data.
|
|
288
|
+
if (!onlyStaged) {
|
|
289
|
+
removeImg(resource.masterData.current)
|
|
290
|
+
}
|
|
291
|
+
checkForStagedChanges(resource)
|
|
292
|
+
|
|
293
|
+
return resource
|
|
294
|
+
},
|
|
295
|
+
|
|
187
296
|
// 'changeName': () => {},
|
|
188
297
|
// 'changeSlug': () => {},
|
|
189
298
|
// 'addVariant': () => {},
|
|
@@ -203,9 +312,7 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
203
312
|
// 'setTaxCategory': () => {},
|
|
204
313
|
// 'setSku': () => {},
|
|
205
314
|
// 'setProductVariantKey': () => {},
|
|
206
|
-
// 'addExternalImage': () => {},
|
|
207
315
|
// 'moveImageToPosition': () => {},
|
|
208
|
-
// 'removeImage': () => {},
|
|
209
316
|
// 'setImageLabel': () => {},
|
|
210
317
|
// 'addAsset': () => {},
|
|
211
318
|
// 'removeAsset': () => {},
|
|
@@ -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,13 @@ 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
|
+
resource.messages.deleteDaysAfterCreation = messagesConfiguration.deleteDaysAfterCreation
|
|
86
87
|
},
|
|
87
88
|
changeProductSearchIndexingEnabled: (
|
|
88
89
|
context: RepositoryContext,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
QuoteRequest,
|
|
3
|
+
QuoteRequestDraft,
|
|
4
|
+
QuoteRequestUpdateAction,
|
|
5
|
+
} from '@commercetools/platform-sdk'
|
|
6
|
+
import { Writable } from '../types'
|
|
7
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
8
|
+
|
|
9
|
+
export class QuoteRequestRepository extends AbstractResourceRepository<'quote-request'> {
|
|
10
|
+
getTypeId() {
|
|
11
|
+
return 'quote-request' as const
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
create(context: RepositoryContext, draft: QuoteRequestDraft): QuoteRequest {
|
|
15
|
+
throw new Error('not implemented')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
actions: Partial<
|
|
19
|
+
Record<
|
|
20
|
+
QuoteRequestUpdateAction['action'],
|
|
21
|
+
(
|
|
22
|
+
context: RepositoryContext,
|
|
23
|
+
resource: Writable<QuoteRequest>,
|
|
24
|
+
action: any
|
|
25
|
+
) => void
|
|
26
|
+
>
|
|
27
|
+
> = {}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Quote,
|
|
3
|
+
QuoteDraft,
|
|
4
|
+
QuoteUpdateAction,
|
|
5
|
+
} from '@commercetools/platform-sdk'
|
|
6
|
+
import { Writable } from '../types'
|
|
7
|
+
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
8
|
+
|
|
9
|
+
export class QuoteRepository extends AbstractResourceRepository<'quote'> {
|
|
10
|
+
getTypeId() {
|
|
11
|
+
return 'quote' as const
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
create(context: RepositoryContext, draft: QuoteDraft): Quote {
|
|
15
|
+
throw new Error('not implemented')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
actions: Partial<
|
|
19
|
+
Record<
|
|
20
|
+
QuoteUpdateAction['action'],
|
|
21
|
+
(
|
|
22
|
+
context: RepositoryContext,
|
|
23
|
+
resource: Writable<Quote>,
|
|
24
|
+
action: any
|
|
25
|
+
) => void
|
|
26
|
+
>
|
|
27
|
+
> = {}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Review,
|
|
3
|
+
ReviewDraft,
|
|
4
|
+
ReviewUpdateAction,
|
|
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 ReviewRepository extends AbstractResourceRepository<'review'> {
|
|
11
|
+
getTypeId() {
|
|
12
|
+
return 'review' as const
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
create(context: RepositoryContext, draft: ReviewDraft): Review {
|
|
16
|
+
const resource: Review = {
|
|
17
|
+
...getBaseResourceProperties(),
|
|
18
|
+
includedInStatistics: false,
|
|
19
|
+
}
|
|
20
|
+
this.saveNew(context, resource)
|
|
21
|
+
return resource
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
actions: Partial<
|
|
25
|
+
Record<
|
|
26
|
+
ReviewUpdateAction['action'],
|
|
27
|
+
(
|
|
28
|
+
context: RepositoryContext,
|
|
29
|
+
resource: Writable<Review>,
|
|
30
|
+
action: any
|
|
31
|
+
) => void
|
|
32
|
+
>
|
|
33
|
+
> = {}
|
|
34
|
+
}
|
|
@@ -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(
|
|
@@ -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
|
|
|
@@ -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,23 @@
|
|
|
1
|
-
import { getBaseResourceProperties } from '../helpers'
|
|
2
|
-
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
3
1
|
import {
|
|
4
|
-
ReferenceTypeId,
|
|
5
|
-
StateReference,
|
|
6
2
|
State,
|
|
3
|
+
StateChangeInitialAction,
|
|
7
4
|
StateChangeKeyAction,
|
|
8
5
|
StateDraft,
|
|
6
|
+
StateReference,
|
|
9
7
|
StateSetDescriptionAction,
|
|
10
8
|
StateSetNameAction,
|
|
11
9
|
StateSetRolesAction,
|
|
12
10
|
StateSetTransitionsAction,
|
|
13
11
|
StateUpdateAction,
|
|
14
12
|
} from '@commercetools/platform-sdk'
|
|
13
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
14
|
+
import { Writable } from '../types'
|
|
15
15
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
16
|
-
import {
|
|
16
|
+
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
17
17
|
|
|
18
|
-
export class StateRepository extends AbstractResourceRepository {
|
|
19
|
-
getTypeId()
|
|
20
|
-
return 'state'
|
|
18
|
+
export class StateRepository extends AbstractResourceRepository<'state'> {
|
|
19
|
+
getTypeId() {
|
|
20
|
+
return 'state' as const
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
create(context: RepositoryContext, draft: StateDraft): State {
|
|
@@ -52,6 +52,13 @@ export class StateRepository extends AbstractResourceRepository {
|
|
|
52
52
|
) => {
|
|
53
53
|
resource.key = key
|
|
54
54
|
},
|
|
55
|
+
changeInitial: (
|
|
56
|
+
context: RepositoryContext,
|
|
57
|
+
resource: Writable<State>,
|
|
58
|
+
{initial }: StateChangeInitialAction
|
|
59
|
+
) => {
|
|
60
|
+
resource.initial = initial
|
|
61
|
+
},
|
|
55
62
|
setDescription: (
|
|
56
63
|
context: RepositoryContext,
|
|
57
64
|
resource: Writable<State>,
|
|
@@ -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 {
|
|
@@ -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
|
|
@@ -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 {
|
|
@@ -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'],
|
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 {
|
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 {
|