@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,25 +1,24 @@
|
|
|
1
|
-
import { getBaseResourceProperties } from '../helpers'
|
|
2
1
|
import {
|
|
3
2
|
AttributeDefinition,
|
|
4
3
|
AttributeDefinitionDraft,
|
|
5
4
|
AttributeType,
|
|
6
5
|
ProductType,
|
|
7
6
|
ProductTypeAddAttributeDefinitionAction,
|
|
8
|
-
|
|
7
|
+
ProductTypeChangeAttributeOrderByNameAction,
|
|
9
8
|
ProductTypeChangeLabelAction,
|
|
10
9
|
ProductTypeChangeLocalizedEnumValueLabelAction,
|
|
11
10
|
ProductTypeDraft,
|
|
12
11
|
ProductTypeRemoveAttributeDefinitionAction,
|
|
13
12
|
ProductTypeRemoveEnumValuesAction,
|
|
14
13
|
ProductTypeUpdateAction,
|
|
15
|
-
ReferenceTypeId,
|
|
16
14
|
} from '@commercetools/platform-sdk'
|
|
15
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
16
|
+
import { Writable } from '../types'
|
|
17
17
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
18
|
-
import { Writable } from 'types'
|
|
19
18
|
|
|
20
|
-
export class ProductTypeRepository extends AbstractResourceRepository {
|
|
21
|
-
getTypeId()
|
|
22
|
-
return 'product-type'
|
|
19
|
+
export class ProductTypeRepository extends AbstractResourceRepository<'product-type'> {
|
|
20
|
+
getTypeId() {
|
|
21
|
+
return 'product-type' as const
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
create(context: RepositoryContext, draft: ProductTypeDraft): ProductType {
|
|
@@ -28,46 +27,28 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
28
27
|
key: draft.key,
|
|
29
28
|
name: draft.name,
|
|
30
29
|
description: draft.description,
|
|
31
|
-
attributes: (draft.attributes ?? []).map(a =>
|
|
30
|
+
attributes: (draft.attributes ?? []).map((a) =>
|
|
32
31
|
this.attributeDefinitionFromAttributeDefinitionDraft(context, a)
|
|
33
32
|
),
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
this.
|
|
35
|
+
this.saveNew(context, resource)
|
|
37
36
|
return resource
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
attributeDefinitionFromAttributeDefinitionDraft = (
|
|
41
40
|
_context: RepositoryContext,
|
|
42
41
|
draft: AttributeDefinitionDraft
|
|
43
|
-
): AttributeDefinition => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
inputTip
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getWithKey(context: RepositoryContext, key: string): ProductType | undefined {
|
|
57
|
-
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
58
|
-
where: [`key="${key}"`],
|
|
59
|
-
})
|
|
60
|
-
if (result.count === 1) {
|
|
61
|
-
return result.results[0] as ProductType
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Catch this for now, should be checked when creating/updating
|
|
65
|
-
if (result.count > 1) {
|
|
66
|
-
throw new Error('Duplicate product type key')
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
-
}
|
|
42
|
+
): AttributeDefinition => ({
|
|
43
|
+
...draft,
|
|
44
|
+
attributeConstraint: draft.attributeConstraint ?? 'None',
|
|
45
|
+
inputHint: draft.inputHint ?? 'SingleLine',
|
|
46
|
+
inputTip:
|
|
47
|
+
draft.inputTip && Object.keys(draft.inputTip).length > 0
|
|
48
|
+
? draft.inputTip
|
|
49
|
+
: undefined,
|
|
50
|
+
isSearchable: draft.isSearchable ?? true,
|
|
51
|
+
})
|
|
71
52
|
|
|
72
53
|
actions: Partial<
|
|
73
54
|
Record<
|
|
@@ -90,7 +71,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
90
71
|
const updateAttributeType = (type: Writable<AttributeType>) => {
|
|
91
72
|
switch (type.name) {
|
|
92
73
|
case 'lenum':
|
|
93
|
-
type.values.forEach(v => {
|
|
74
|
+
type.values.forEach((v) => {
|
|
94
75
|
if (v.key === newValue.key) {
|
|
95
76
|
v.label = newValue.label
|
|
96
77
|
}
|
|
@@ -102,7 +83,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
102
83
|
}
|
|
103
84
|
}
|
|
104
85
|
|
|
105
|
-
resource.attributes?.forEach(value => {
|
|
86
|
+
resource.attributes?.forEach((value) => {
|
|
106
87
|
if (value.name === attributeName) {
|
|
107
88
|
updateAttributeType(value.type)
|
|
108
89
|
}
|
|
@@ -113,7 +94,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
113
94
|
resource: Writable<ProductType>,
|
|
114
95
|
{ attributeName, label }: ProductTypeChangeLabelAction
|
|
115
96
|
) => {
|
|
116
|
-
resource.attributes?.forEach(value => {
|
|
97
|
+
resource.attributes?.forEach((value) => {
|
|
117
98
|
if (value.name === attributeName) {
|
|
118
99
|
value.label = label
|
|
119
100
|
}
|
|
@@ -128,26 +109,26 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
128
109
|
this.attributeDefinitionFromAttributeDefinitionDraft(context, attribute)
|
|
129
110
|
)
|
|
130
111
|
},
|
|
131
|
-
|
|
112
|
+
changeAttributeOrderByName: (
|
|
132
113
|
context: RepositoryContext,
|
|
133
114
|
resource: Writable<ProductType>,
|
|
134
|
-
{
|
|
115
|
+
{ attributeNames }: ProductTypeChangeAttributeOrderByNameAction
|
|
135
116
|
) => {
|
|
136
|
-
const attrs = new Map(
|
|
117
|
+
const attrs = new Map(
|
|
118
|
+
resource.attributes?.map((item) => [item.name, item])
|
|
119
|
+
)
|
|
137
120
|
const result: AttributeDefinition[] = []
|
|
138
121
|
let current = resource.attributes
|
|
139
122
|
|
|
140
|
-
|
|
141
|
-
const attr = attrs.get(
|
|
123
|
+
attributeNames.forEach((attrName) => {
|
|
124
|
+
const attr = attrs.get(attrName)
|
|
142
125
|
if (attr === undefined) {
|
|
143
126
|
throw new Error('New attr')
|
|
144
127
|
}
|
|
145
128
|
result.push(attr)
|
|
146
129
|
|
|
147
130
|
// Remove from current items
|
|
148
|
-
current = current?.filter(f =>
|
|
149
|
-
return f.name !== iAttr.name
|
|
150
|
-
})
|
|
131
|
+
current = current?.filter((f) => f.name !== attrName)
|
|
151
132
|
})
|
|
152
133
|
|
|
153
134
|
resource.attributes = result
|
|
@@ -162,30 +143,27 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
162
143
|
resource: Writable<ProductType>,
|
|
163
144
|
{ name }: ProductTypeRemoveAttributeDefinitionAction
|
|
164
145
|
) => {
|
|
165
|
-
resource.attributes = resource.attributes?.filter(f =>
|
|
166
|
-
return f.name !== name
|
|
167
|
-
})
|
|
146
|
+
resource.attributes = resource.attributes?.filter((f) => f.name !== name)
|
|
168
147
|
},
|
|
169
148
|
removeEnumValues: (
|
|
170
149
|
context: RepositoryContext,
|
|
171
150
|
resource: Writable<ProductType>,
|
|
172
151
|
{ attributeName, keys }: ProductTypeRemoveEnumValuesAction
|
|
173
152
|
) => {
|
|
174
|
-
resource.attributes?.forEach(attr => {
|
|
153
|
+
resource.attributes?.forEach((attr) => {
|
|
175
154
|
if (attr.name == attributeName) {
|
|
176
155
|
if (attr.type.name == 'enum') {
|
|
177
|
-
attr.type.values = attr.type.values.filter(
|
|
178
|
-
|
|
179
|
-
|
|
156
|
+
attr.type.values = attr.type.values.filter(
|
|
157
|
+
(v) => !keys.includes(v.key)
|
|
158
|
+
)
|
|
180
159
|
}
|
|
181
160
|
|
|
182
161
|
if (attr.type.name == 'set') {
|
|
183
162
|
if (attr.type.elementType.name == 'enum') {
|
|
184
|
-
attr.type.elementType.values =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
)
|
|
163
|
+
attr.type.elementType.values =
|
|
164
|
+
attr.type.elementType.values.filter(
|
|
165
|
+
(v) => !keys.includes(v.key)
|
|
166
|
+
)
|
|
189
167
|
}
|
|
190
168
|
}
|
|
191
169
|
}
|
|
@@ -6,21 +6,23 @@ import {
|
|
|
6
6
|
ProductDraft,
|
|
7
7
|
ProductPublishAction,
|
|
8
8
|
ProductSetAttributeAction,
|
|
9
|
-
|
|
9
|
+
ProductSetDescriptionAction,
|
|
10
|
+
ProductSetKeyAction,
|
|
10
11
|
ProductTypeReference,
|
|
12
|
+
ProductUpdateAction,
|
|
11
13
|
ProductVariant,
|
|
12
14
|
ProductVariantDraft,
|
|
13
|
-
ReferenceTypeId,
|
|
14
15
|
} from '@commercetools/platform-sdk'
|
|
15
16
|
import { v4 as uuidv4 } from 'uuid'
|
|
17
|
+
import { Writable } from '../types'
|
|
16
18
|
import { getBaseResourceProperties } from '../helpers'
|
|
17
19
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
18
|
-
import { Writable } from '../types'
|
|
19
20
|
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
21
|
+
import deepEqual from 'deep-equal'
|
|
20
22
|
|
|
21
|
-
export class ProductRepository extends AbstractResourceRepository {
|
|
22
|
-
getTypeId()
|
|
23
|
-
return 'product'
|
|
23
|
+
export class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
24
|
+
getTypeId() {
|
|
25
|
+
return 'product' as const
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
create(context: RepositoryContext, draft: ProductDraft): Product {
|
|
@@ -52,97 +54,136 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
52
54
|
categories: [],
|
|
53
55
|
masterVariant: variantFromDraft(1, draft.masterVariant),
|
|
54
56
|
variants:
|
|
55
|
-
draft.variants?.map((variant, index) =>
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
draft.variants?.map((variant, index) =>
|
|
58
|
+
variantFromDraft(index + 2, variant)
|
|
59
|
+
) ?? [],
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
searchKeywords: draft.searchKeywords,
|
|
61
|
+
searchKeywords: draft.searchKeywords ?? {},
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
const resource: Product = {
|
|
64
65
|
...getBaseResourceProperties(),
|
|
66
|
+
key: draft.key,
|
|
65
67
|
productType: productType,
|
|
66
68
|
masterData: {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
staged: draft.publish ? undefined : productData,
|
|
71
|
-
hasStagedChanges: draft.publish ?? true,
|
|
69
|
+
current: productData,
|
|
70
|
+
staged: productData,
|
|
71
|
+
hasStagedChanges: false,
|
|
72
72
|
published: draft.publish ?? false,
|
|
73
73
|
},
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
this.
|
|
76
|
+
this.saveNew(context, resource)
|
|
77
77
|
|
|
78
78
|
return resource
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
actions
|
|
81
|
+
actions: Partial<
|
|
82
|
+
Record<
|
|
83
|
+
ProductUpdateAction['action'],
|
|
84
|
+
(
|
|
85
|
+
context: RepositoryContext,
|
|
86
|
+
resource: Writable<Product>,
|
|
87
|
+
action: any
|
|
88
|
+
) => void
|
|
89
|
+
>
|
|
90
|
+
> = {
|
|
82
91
|
publish: (
|
|
83
92
|
context: RepositoryContext,
|
|
84
93
|
resource: Writable<Product>,
|
|
85
94
|
{ scope }: ProductPublishAction
|
|
86
95
|
) => {
|
|
87
|
-
|
|
88
|
-
resource.masterData.current = resource.masterData.staged
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
resource.masterData.staged = undefined
|
|
91
|
-
}
|
|
92
|
-
resource.masterData.hasStagedChanges = false
|
|
96
|
+
resource.masterData.current = resource.masterData.staged
|
|
93
97
|
resource.masterData.published = true
|
|
98
|
+
checkForStagedChanges(resource)
|
|
99
|
+
},
|
|
100
|
+
unpublish: (
|
|
101
|
+
context: RepositoryContext,
|
|
102
|
+
resource: Writable<Product>
|
|
103
|
+
// { action }: ProductUnpublishAction
|
|
104
|
+
) => {
|
|
105
|
+
resource.masterData.published = false
|
|
106
|
+
checkForStagedChanges(resource)
|
|
94
107
|
},
|
|
95
108
|
setAttribute: (
|
|
96
109
|
context: RepositoryContext,
|
|
97
110
|
resource: Writable<Product>,
|
|
98
111
|
{ variantId, sku, name, value, staged }: ProductSetAttributeAction
|
|
99
112
|
) => {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
sku
|
|
106
|
-
)
|
|
107
|
-
if (!variant) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
|
|
113
|
+
const setAttr = (data: Writable<ProductData>) => {
|
|
114
|
+
const { variant, isMasterVariant, variantIndex } = getVariant(
|
|
115
|
+
data,
|
|
116
|
+
variantId,
|
|
117
|
+
sku
|
|
110
118
|
)
|
|
111
|
-
|
|
119
|
+
if (!variant) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`Variant with id ${variantId} or sku ${sku} not found on product ${resource.id}`
|
|
122
|
+
)
|
|
123
|
+
}
|
|
112
124
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
125
|
+
if (!variant.attributes) {
|
|
126
|
+
variant.attributes = []
|
|
127
|
+
}
|
|
116
128
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
name,
|
|
123
|
-
value,
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
if (isStaged) {
|
|
127
|
-
resource.masterData.staged = productData
|
|
128
|
-
if (isMasterVariant) {
|
|
129
|
-
resource.masterData.staged.masterVariant = variant
|
|
129
|
+
const existingAttr = variant.attributes.find(
|
|
130
|
+
(attr) => attr.name === name
|
|
131
|
+
)
|
|
132
|
+
if (existingAttr) {
|
|
133
|
+
existingAttr.value = value
|
|
130
134
|
} else {
|
|
131
|
-
|
|
135
|
+
variant.attributes.push({
|
|
136
|
+
name,
|
|
137
|
+
value,
|
|
138
|
+
})
|
|
132
139
|
}
|
|
133
|
-
resource.masterData.hasStagedChanges = true
|
|
134
|
-
} else {
|
|
135
|
-
resource.masterData.current = productData
|
|
136
140
|
if (isMasterVariant) {
|
|
137
|
-
|
|
141
|
+
data.masterVariant = variant
|
|
138
142
|
} else {
|
|
139
|
-
|
|
143
|
+
data.variants[variantIndex] = variant
|
|
140
144
|
}
|
|
141
145
|
}
|
|
146
|
+
|
|
147
|
+
// If true, only the staged Attribute is set. If false, both current and
|
|
148
|
+
// staged Attribute is set. Default is true
|
|
149
|
+
const onlyStaged = staged !== undefined ? staged : true
|
|
150
|
+
|
|
151
|
+
// Write the attribute to the staged data
|
|
152
|
+
setAttr(resource.masterData.staged)
|
|
153
|
+
|
|
154
|
+
// Also write to published data is isStaged = false
|
|
155
|
+
// if isStaged is false we set the attribute on both the staged and
|
|
156
|
+
// published data.
|
|
157
|
+
if (!onlyStaged) {
|
|
158
|
+
setAttr(resource.masterData.current)
|
|
159
|
+
}
|
|
160
|
+
checkForStagedChanges(resource)
|
|
161
|
+
|
|
162
|
+
return resource
|
|
163
|
+
},
|
|
164
|
+
setDescription: (
|
|
165
|
+
context: RepositoryContext,
|
|
166
|
+
resource: Writable<Product>,
|
|
167
|
+
{ description, staged }: ProductSetDescriptionAction
|
|
168
|
+
) => {
|
|
169
|
+
const onlyStaged = staged !== undefined ? staged : true
|
|
170
|
+
|
|
171
|
+
resource.masterData.staged.description = description
|
|
172
|
+
if (!onlyStaged) {
|
|
173
|
+
resource.masterData.current.description = description
|
|
174
|
+
}
|
|
175
|
+
checkForStagedChanges(resource)
|
|
176
|
+
return resource
|
|
177
|
+
},
|
|
178
|
+
setKey: (
|
|
179
|
+
context: RepositoryContext,
|
|
180
|
+
resource: Writable<Product>,
|
|
181
|
+
{ key }: ProductSetKeyAction
|
|
182
|
+
) => {
|
|
183
|
+
resource.key = key
|
|
184
|
+
return resource
|
|
142
185
|
},
|
|
143
|
-
// 'setKey': () => {},
|
|
144
186
|
// 'changeName': () => {},
|
|
145
|
-
// 'setDescription': () => {},
|
|
146
187
|
// 'changeSlug': () => {},
|
|
147
188
|
// 'addVariant': () => {},
|
|
148
189
|
// 'removeVariant': () => {},
|
|
@@ -181,16 +222,22 @@ export class ProductRepository extends AbstractResourceRepository {
|
|
|
181
222
|
// 'setMetaKeywords': () => {},
|
|
182
223
|
// 'revertStagedChanges': () => {},
|
|
183
224
|
// 'revertStagedVariantChanges': () => {},
|
|
184
|
-
// 'unpublish': () => {},
|
|
185
225
|
// 'transitionState': () => {},
|
|
186
226
|
}
|
|
187
227
|
}
|
|
188
228
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
229
|
+
// Check if the product still has staged data that is different from the
|
|
230
|
+
// current data.
|
|
231
|
+
const checkForStagedChanges = (product: Writable<Product>) => {
|
|
232
|
+
if (!product.masterData.staged) {
|
|
233
|
+
product.masterData.staged = product.masterData.current
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (deepEqual(product.masterData.current, product.masterData.staged)) {
|
|
237
|
+
product.masterData.hasStagedChanges = false
|
|
238
|
+
} else {
|
|
239
|
+
product.masterData.hasStagedChanges = true
|
|
192
240
|
}
|
|
193
|
-
return product.masterData.staged
|
|
194
241
|
}
|
|
195
242
|
|
|
196
243
|
interface VariantResult {
|
|
@@ -229,25 +276,21 @@ const getVariant = (
|
|
|
229
276
|
const variantFromDraft = (
|
|
230
277
|
variantId: number,
|
|
231
278
|
variant: ProductVariantDraft
|
|
232
|
-
): ProductVariant => {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
}
|
|
279
|
+
): ProductVariant => ({
|
|
280
|
+
id: variantId,
|
|
281
|
+
sku: variant?.sku,
|
|
282
|
+
attributes: variant?.attributes ?? [],
|
|
283
|
+
prices: variant?.prices?.map(priceFromDraft),
|
|
284
|
+
assets: [],
|
|
285
|
+
images: [],
|
|
286
|
+
})
|
|
242
287
|
|
|
243
|
-
const priceFromDraft = (draft: PriceDraft): Price => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
}
|
|
288
|
+
const priceFromDraft = (draft: PriceDraft): Price => ({
|
|
289
|
+
id: uuidv4(),
|
|
290
|
+
value: {
|
|
291
|
+
currencyCode: draft.value.currencyCode,
|
|
292
|
+
centAmount: draft.value.centAmount,
|
|
293
|
+
fractionDigits: 2,
|
|
294
|
+
type: 'centPrecision',
|
|
295
|
+
},
|
|
296
|
+
})
|
|
@@ -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,47 +13,29 @@ import {
|
|
|
13
13
|
ProjectSetShippingRateInputTypeAction,
|
|
14
14
|
ProjectUpdateAction,
|
|
15
15
|
} from '@commercetools/platform-sdk'
|
|
16
|
-
import { InvalidOperationError } from '@commercetools/platform-sdk'
|
|
17
|
-
import { Writable } from 'types'
|
|
18
|
-
import { checkConcurrentModification } from './errors'
|
|
19
|
-
import { CommercetoolsError } from '../exceptions'
|
|
20
|
-
import { AbstractRepository, RepositoryContext } from './abstract'
|
|
21
16
|
import { maskSecretValue } from '../lib/masking'
|
|
17
|
+
import { Writable } from '../types'
|
|
18
|
+
import { AbstractRepository, RepositoryContext } from './abstract'
|
|
22
19
|
|
|
23
|
-
export class ProjectRepository extends AbstractRepository {
|
|
20
|
+
export class ProjectRepository extends AbstractRepository<Project> {
|
|
24
21
|
get(context: RepositoryContext): Project | null {
|
|
25
22
|
const resource = this._storage.getProject(context.projectKey)
|
|
26
23
|
return this.postProcessResource(resource)
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
postProcessResource(resource:
|
|
26
|
+
postProcessResource(resource: Project): Project {
|
|
30
27
|
if (resource) {
|
|
31
|
-
return maskSecretValue(
|
|
32
|
-
resource, 'externalOAuth.authorizationHeader')
|
|
28
|
+
return maskSecretValue(resource, 'externalOAuth.authorizationHeader')
|
|
33
29
|
}
|
|
34
30
|
return resource
|
|
35
|
-
|
|
36
31
|
}
|
|
37
32
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
checkConcurrentModification(current, resource.version)
|
|
43
|
-
} else {
|
|
44
|
-
if (resource.version !== 0) {
|
|
45
|
-
throw new CommercetoolsError<InvalidOperationError>(
|
|
46
|
-
{
|
|
47
|
-
code: 'InvalidOperation',
|
|
48
|
-
message: 'version on create must be 0',
|
|
49
|
-
},
|
|
50
|
-
400
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
33
|
+
saveNew(context: RepositoryContext, resource: Writable<Project>) {
|
|
34
|
+
resource.version = 1
|
|
35
|
+
this._storage.saveProject(resource)
|
|
36
|
+
}
|
|
54
37
|
|
|
55
|
-
|
|
56
|
-
resource.version += 1
|
|
38
|
+
saveUpdate(context: RepositoryContext, version: number, resource: Project) {
|
|
57
39
|
this._storage.saveProject(resource)
|
|
58
40
|
}
|
|
59
41
|
|
|
@@ -95,12 +77,12 @@ export class ProjectRepository extends AbstractRepository {
|
|
|
95
77
|
) => {
|
|
96
78
|
resource.languages = languages
|
|
97
79
|
},
|
|
98
|
-
|
|
80
|
+
changeMessagesConfiguration: (
|
|
99
81
|
context: RepositoryContext,
|
|
100
82
|
resource: Writable<Project>,
|
|
101
|
-
{
|
|
83
|
+
{ messagesConfiguration }: ProjectChangeMessagesConfigurationAction
|
|
102
84
|
) => {
|
|
103
|
-
resource.messages.enabled =
|
|
85
|
+
resource.messages.enabled = messagesConfiguration.enabled
|
|
104
86
|
},
|
|
105
87
|
changeProductSearchIndexingEnabled: (
|
|
106
88
|
context: RepositoryContext,
|
|
@@ -147,7 +129,8 @@ export class ProjectRepository extends AbstractRepository {
|
|
|
147
129
|
countryTaxRateFallbackEnabled,
|
|
148
130
|
}: ProjectChangeCountryTaxRateFallbackEnabledAction
|
|
149
131
|
) => {
|
|
150
|
-
resource.carts.countryTaxRateFallbackEnabled =
|
|
132
|
+
resource.carts.countryTaxRateFallbackEnabled =
|
|
133
|
+
countryTaxRateFallbackEnabled
|
|
151
134
|
},
|
|
152
135
|
changeCartsConfiguration: (
|
|
153
136
|
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
|
+
}
|