@labdigital/commercetools-mock 0.5.13 → 0.5.14
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 +6 -2
- package/dist/commercetools-mock.cjs.development.js +3058 -1645
- 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 +3058 -1645
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/ctMock.d.ts +1 -0
- package/dist/repositories/abstract.d.ts +9 -7
- package/dist/repositories/cart-discount.d.ts +9 -0
- package/dist/repositories/cart.d.ts +16 -3
- package/dist/repositories/category.d.ts +18 -0
- package/dist/repositories/channel.d.ts +6 -0
- package/dist/repositories/custom-object.d.ts +2 -2
- package/dist/repositories/customer-group.d.ts +11 -0
- package/dist/repositories/customer.d.ts +2 -2
- package/dist/repositories/discount-code.d.ts +8 -0
- package/dist/repositories/errors.d.ts +2 -2
- package/dist/repositories/extension.d.ts +8 -0
- package/dist/repositories/inventory-entry.d.ts +2 -2
- package/dist/repositories/order.d.ts +2 -2
- package/dist/repositories/payment.d.ts +4 -3
- package/dist/repositories/product-projection.d.ts +2 -2
- package/dist/repositories/product-type.d.ts +5 -4
- package/dist/repositories/product.d.ts +2 -2
- package/dist/repositories/project.d.ts +8 -0
- package/dist/repositories/shipping-method.d.ts +7 -5
- package/dist/repositories/shopping-list.d.ts +2 -2
- package/dist/repositories/state.d.ts +5 -4
- package/dist/repositories/store.d.ts +6 -3
- package/dist/repositories/subscription.d.ts +6 -0
- package/dist/repositories/tax-category.d.ts +6 -5
- package/dist/repositories/type.d.ts +5 -3
- package/dist/repositories/zone.d.ts +8 -0
- package/dist/services/abstract.d.ts +4 -3
- package/dist/services/cart-discount.d.ts +9 -0
- package/dist/services/category.d.ts +9 -0
- package/dist/services/channel.d.ts +9 -0
- package/dist/services/customer-group.d.ts +9 -0
- package/dist/services/discount-code.d.ts +9 -0
- package/dist/services/extension.d.ts +9 -0
- package/dist/services/my-cart.d.ts +11 -0
- package/dist/services/project.d.ts +11 -0
- package/dist/services/subscription.d.ts +9 -0
- package/dist/services/zone.d.ts +9 -0
- package/dist/storage.d.ts +10 -1
- package/dist/types.d.ts +2 -1
- package/package.json +20 -20
- package/src/ctMock.ts +44 -17
- package/src/oauth/server.ts +3 -1
- package/src/repositories/abstract.ts +39 -33
- package/src/repositories/cart-discount.ts +140 -0
- package/src/repositories/cart.ts +247 -3
- package/src/repositories/category.ts +140 -0
- package/src/repositories/channel.ts +23 -0
- package/src/repositories/custom-object.ts +2 -2
- package/src/repositories/customer-group.ts +42 -0
- package/src/repositories/customer.ts +2 -2
- package/src/repositories/discount-code.ts +143 -0
- package/src/repositories/errors.ts +7 -2
- package/src/repositories/extension.ts +65 -0
- package/src/repositories/inventory-entry.ts +2 -2
- package/src/repositories/order.ts +2 -2
- package/src/repositories/payment.ts +10 -6
- package/src/repositories/product-projection.ts +2 -2
- package/src/repositories/product-type.ts +57 -4
- package/src/repositories/product.ts +4 -2
- package/src/repositories/project.ts +150 -0
- package/src/repositories/shipping-method.ts +149 -13
- package/src/repositories/shopping-list.ts +2 -2
- package/src/repositories/state.ts +48 -4
- package/src/repositories/store.ts +69 -4
- package/src/repositories/subscription.ts +50 -0
- package/src/repositories/tax-category.ts +80 -6
- package/src/repositories/type.ts +133 -3
- package/src/repositories/zone.ts +77 -0
- package/src/server.ts +6 -1
- package/src/services/abstract.ts +16 -15
- package/src/services/cart-discount.ts +17 -0
- package/src/services/cart.test.ts +314 -3
- package/src/services/category.test.ts +37 -0
- package/src/services/category.ts +17 -0
- package/src/services/channel.ts +17 -0
- package/src/services/custom-object.test.ts +3 -3
- package/src/services/customer-group.ts +17 -0
- package/src/services/discount-code.ts +17 -0
- package/src/services/extension.ts +17 -0
- package/src/services/inventory-entry.test.ts +3 -3
- package/src/services/my-cart.test.ts +93 -0
- package/src/services/my-cart.ts +44 -0
- package/src/services/my-payment.test.ts +2 -2
- package/src/services/order.test.ts +4 -4
- package/src/services/payment.test.ts +2 -2
- package/src/services/product-projection.test.ts +1 -5
- package/src/services/product-type.test.ts +2 -2
- package/src/services/product.test.ts +6 -2
- package/src/services/project.ts +42 -0
- package/src/services/shipping-method.test.ts +3 -3
- package/src/services/state.test.ts +2 -2
- package/src/services/subscription.ts +17 -0
- package/src/services/tax-category.test.ts +3 -3
- package/src/services/zone.ts +17 -0
- package/src/storage.ts +69 -1
- package/src/types.ts +2 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
2
|
+
import {
|
|
3
|
+
Category,
|
|
4
|
+
CategoryChangeAssetNameAction,
|
|
5
|
+
CategoryChangeSlugAction,
|
|
6
|
+
CategoryDraft,
|
|
7
|
+
CategorySetAssetDescriptionAction,
|
|
8
|
+
CategorySetAssetSourcesAction,
|
|
9
|
+
CategorySetDescriptionAction,
|
|
10
|
+
CategorySetKeyAction,
|
|
11
|
+
CategorySetMetaDescriptionAction,
|
|
12
|
+
CategorySetMetaKeywordsAction,
|
|
13
|
+
CategorySetMetaTitleAction,
|
|
14
|
+
ReferenceTypeId,
|
|
15
|
+
} from '@commercetools/platform-sdk'
|
|
16
|
+
import { Writable } from 'types'
|
|
17
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
18
|
+
import { createCustomFields } from './helpers'
|
|
19
|
+
import { AbstractResourceRepository } from './abstract'
|
|
20
|
+
|
|
21
|
+
export class CategoryRepository extends AbstractResourceRepository {
|
|
22
|
+
getTypeId(): ReferenceTypeId {
|
|
23
|
+
return 'category'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
create(projectKey: string, draft: CategoryDraft): Category {
|
|
27
|
+
const resource: Category = {
|
|
28
|
+
...getBaseResourceProperties(),
|
|
29
|
+
key: draft.key,
|
|
30
|
+
name: draft.name,
|
|
31
|
+
slug: draft.slug,
|
|
32
|
+
orderHint: draft.orderHint || '',
|
|
33
|
+
parent: draft.parent
|
|
34
|
+
? { typeId: 'category', id: draft.parent.id! }
|
|
35
|
+
: undefined,
|
|
36
|
+
ancestors: [], // TODO
|
|
37
|
+
assets:
|
|
38
|
+
draft.assets?.map(d => {
|
|
39
|
+
return {
|
|
40
|
+
id: uuidv4(),
|
|
41
|
+
name: d.name,
|
|
42
|
+
description: d.description,
|
|
43
|
+
sources: d.sources,
|
|
44
|
+
tags: d.tags,
|
|
45
|
+
key: d.key,
|
|
46
|
+
custom: createCustomFields(draft.custom, projectKey, this._storage),
|
|
47
|
+
}
|
|
48
|
+
}) || [],
|
|
49
|
+
}
|
|
50
|
+
this.save(projectKey, resource)
|
|
51
|
+
return resource
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
actions = {
|
|
55
|
+
changeAssetName: (
|
|
56
|
+
projectKey: string,
|
|
57
|
+
resource: Writable<Category>,
|
|
58
|
+
{ assetId, assetKey, name }: CategoryChangeAssetNameAction
|
|
59
|
+
) => {
|
|
60
|
+
resource.assets?.forEach(asset => {
|
|
61
|
+
if (assetId && assetId == asset.id) {
|
|
62
|
+
asset.name = name
|
|
63
|
+
}
|
|
64
|
+
if (assetKey && assetKey == asset.key) {
|
|
65
|
+
asset.name = name
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
},
|
|
69
|
+
changeSlug: (
|
|
70
|
+
projectKey: string,
|
|
71
|
+
resource: Writable<Category>,
|
|
72
|
+
{ slug }: CategoryChangeSlugAction
|
|
73
|
+
) => {
|
|
74
|
+
resource.slug = slug
|
|
75
|
+
},
|
|
76
|
+
setKey: (
|
|
77
|
+
projectKey: string,
|
|
78
|
+
resource: Writable<Category>,
|
|
79
|
+
{ key }: CategorySetKeyAction
|
|
80
|
+
) => {
|
|
81
|
+
resource.key = key
|
|
82
|
+
},
|
|
83
|
+
setAssetDescription: (
|
|
84
|
+
projectKey: string,
|
|
85
|
+
resource: Writable<Category>,
|
|
86
|
+
{ assetId, assetKey, description }: CategorySetAssetDescriptionAction
|
|
87
|
+
) => {
|
|
88
|
+
resource.assets?.forEach(asset => {
|
|
89
|
+
if (assetId && assetId == asset.id) {
|
|
90
|
+
asset.description = description
|
|
91
|
+
}
|
|
92
|
+
if (assetKey && assetKey == asset.key) {
|
|
93
|
+
asset.description = description
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
setAssetSources: (
|
|
98
|
+
projectKey: string,
|
|
99
|
+
resource: Writable<Category>,
|
|
100
|
+
{ assetId, assetKey, sources }: CategorySetAssetSourcesAction
|
|
101
|
+
) => {
|
|
102
|
+
resource.assets?.forEach(asset => {
|
|
103
|
+
if (assetId && assetId == asset.id) {
|
|
104
|
+
asset.sources = sources
|
|
105
|
+
}
|
|
106
|
+
if (assetKey && assetKey == asset.key) {
|
|
107
|
+
asset.sources = sources
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
},
|
|
111
|
+
setDescription: (
|
|
112
|
+
projectKey: string,
|
|
113
|
+
resource: Writable<Category>,
|
|
114
|
+
{ description }: CategorySetDescriptionAction
|
|
115
|
+
) => {
|
|
116
|
+
resource.description = description
|
|
117
|
+
},
|
|
118
|
+
setMetaDescription: (
|
|
119
|
+
projectKey: string,
|
|
120
|
+
resource: Writable<Category>,
|
|
121
|
+
{ metaDescription }: CategorySetMetaDescriptionAction
|
|
122
|
+
) => {
|
|
123
|
+
resource.metaDescription = metaDescription
|
|
124
|
+
},
|
|
125
|
+
setMetaKeywords: (
|
|
126
|
+
projectKey: string,
|
|
127
|
+
resource: Writable<Category>,
|
|
128
|
+
{ metaKeywords }: CategorySetMetaKeywordsAction
|
|
129
|
+
) => {
|
|
130
|
+
resource.metaKeywords = metaKeywords
|
|
131
|
+
},
|
|
132
|
+
setMetaTitle: (
|
|
133
|
+
projectKey: string,
|
|
134
|
+
resource: Writable<Category>,
|
|
135
|
+
{ metaTitle }: CategorySetMetaTitleAction
|
|
136
|
+
) => {
|
|
137
|
+
resource.metaTitle = metaTitle
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Channel,
|
|
3
|
+
ChannelDraft,
|
|
4
|
+
ReferenceTypeId,
|
|
5
|
+
} from '@commercetools/platform-sdk'
|
|
6
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
7
|
+
import { AbstractResourceRepository } from './abstract'
|
|
8
|
+
|
|
9
|
+
export class ChannelRepository extends AbstractResourceRepository {
|
|
10
|
+
getTypeId(): ReferenceTypeId {
|
|
11
|
+
return 'channel'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
create(projectKey: string, draft: ChannelDraft): Channel {
|
|
15
|
+
const resource: Channel = {
|
|
16
|
+
...getBaseResourceProperties(),
|
|
17
|
+
key: draft.key,
|
|
18
|
+
roles: draft.roles || [],
|
|
19
|
+
}
|
|
20
|
+
this.save(projectKey, resource)
|
|
21
|
+
return resource
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -4,11 +4,11 @@ import {
|
|
|
4
4
|
ReferenceTypeId,
|
|
5
5
|
} from '@commercetools/platform-sdk'
|
|
6
6
|
import { checkConcurrentModification } from './errors'
|
|
7
|
-
import
|
|
7
|
+
import { AbstractResourceRepository } from './abstract'
|
|
8
8
|
import { Writable } from '../types'
|
|
9
9
|
import { getBaseResourceProperties } from '../helpers'
|
|
10
10
|
|
|
11
|
-
export class CustomObjectRepository extends
|
|
11
|
+
export class CustomObjectRepository extends AbstractResourceRepository {
|
|
12
12
|
getTypeId(): ReferenceTypeId {
|
|
13
13
|
return 'key-value-document'
|
|
14
14
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CustomerGroup,
|
|
3
|
+
CustomerGroupChangeNameAction,
|
|
4
|
+
CustomerGroupDraft,
|
|
5
|
+
CustomerGroupSetKeyAction,
|
|
6
|
+
ReferenceTypeId,
|
|
7
|
+
} from '@commercetools/platform-sdk'
|
|
8
|
+
import { Writable } from 'types'
|
|
9
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
10
|
+
import { AbstractResourceRepository } from './abstract'
|
|
11
|
+
|
|
12
|
+
export class CustomerGroupRepository extends AbstractResourceRepository {
|
|
13
|
+
getTypeId(): ReferenceTypeId {
|
|
14
|
+
return 'customer'
|
|
15
|
+
}
|
|
16
|
+
create(projectKey: string, draft: CustomerGroupDraft): CustomerGroup {
|
|
17
|
+
const resource: CustomerGroup = {
|
|
18
|
+
...getBaseResourceProperties(),
|
|
19
|
+
key: draft.key,
|
|
20
|
+
name: draft.groupName,
|
|
21
|
+
}
|
|
22
|
+
this.save(projectKey, resource)
|
|
23
|
+
return resource
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
actions = {
|
|
27
|
+
setKey: (
|
|
28
|
+
projectKey: string,
|
|
29
|
+
resource: Writable<CustomerGroup>,
|
|
30
|
+
{ key }: CustomerGroupSetKeyAction
|
|
31
|
+
) => {
|
|
32
|
+
resource.key = key
|
|
33
|
+
},
|
|
34
|
+
changeName: (
|
|
35
|
+
projectKey: string,
|
|
36
|
+
resource: Writable<CustomerGroup>,
|
|
37
|
+
{ name }: CustomerGroupChangeNameAction
|
|
38
|
+
) => {
|
|
39
|
+
resource.name = name
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
ReferenceTypeId,
|
|
5
5
|
} from '@commercetools/platform-sdk'
|
|
6
6
|
import { getBaseResourceProperties } from '../helpers'
|
|
7
|
-
import
|
|
7
|
+
import { AbstractResourceRepository } from './abstract'
|
|
8
8
|
|
|
9
|
-
export class CustomerRepository extends
|
|
9
|
+
export class CustomerRepository extends AbstractResourceRepository {
|
|
10
10
|
getTypeId(): ReferenceTypeId {
|
|
11
11
|
return 'customer'
|
|
12
12
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CartDiscountReference,
|
|
3
|
+
DiscountCode,
|
|
4
|
+
DiscountCodeChangeCartDiscountsAction,
|
|
5
|
+
DiscountCodeChangeIsActiveAction,
|
|
6
|
+
DiscountCodeDraft,
|
|
7
|
+
DiscountCodeSetCartPredicateAction,
|
|
8
|
+
DiscountCodeSetDescriptionAction,
|
|
9
|
+
DiscountCodeSetMaxApplicationsAction,
|
|
10
|
+
DiscountCodeSetMaxApplicationsPerCustomerAction,
|
|
11
|
+
DiscountCodeSetNameAction,
|
|
12
|
+
DiscountCodeSetValidFromAction,
|
|
13
|
+
DiscountCodeSetValidFromAndUntilAction,
|
|
14
|
+
DiscountCodeSetValidUntilAction,
|
|
15
|
+
DiscountCodeUpdateAction,
|
|
16
|
+
ReferenceTypeId,
|
|
17
|
+
} from '@commercetools/platform-sdk'
|
|
18
|
+
import { Writable } from 'types'
|
|
19
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
20
|
+
import { AbstractResourceRepository } from './abstract'
|
|
21
|
+
|
|
22
|
+
export class DiscountCodeRepository extends AbstractResourceRepository {
|
|
23
|
+
getTypeId(): ReferenceTypeId {
|
|
24
|
+
return 'cart-discount'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
create(projectKey: string, draft: DiscountCodeDraft): DiscountCode {
|
|
28
|
+
console.log(draft)
|
|
29
|
+
const resource: DiscountCode = {
|
|
30
|
+
...getBaseResourceProperties(),
|
|
31
|
+
applicationVersion: 1,
|
|
32
|
+
cartDiscounts: draft.cartDiscounts.map(
|
|
33
|
+
(obj): CartDiscountReference => ({
|
|
34
|
+
typeId: 'cart-discount',
|
|
35
|
+
id: obj.id!,
|
|
36
|
+
})
|
|
37
|
+
),
|
|
38
|
+
cartPredicate: draft.cartPredicate,
|
|
39
|
+
code: draft.code,
|
|
40
|
+
description: draft.description,
|
|
41
|
+
groups: draft.groups || [],
|
|
42
|
+
isActive: draft.isActive || true,
|
|
43
|
+
name: draft.name,
|
|
44
|
+
references: [],
|
|
45
|
+
validFrom: draft.validFrom,
|
|
46
|
+
validUntil: draft.validUntil,
|
|
47
|
+
maxApplications: draft.maxApplications,
|
|
48
|
+
maxApplicationsPerCustomer: draft.maxApplicationsPerCustomer,
|
|
49
|
+
}
|
|
50
|
+
this.save(projectKey, resource)
|
|
51
|
+
return resource
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
actions: Partial<
|
|
55
|
+
Record<
|
|
56
|
+
DiscountCodeUpdateAction['action'],
|
|
57
|
+
(
|
|
58
|
+
projectKey: string,
|
|
59
|
+
resource: Writable<DiscountCode>,
|
|
60
|
+
action: any
|
|
61
|
+
) => void
|
|
62
|
+
>
|
|
63
|
+
> = {
|
|
64
|
+
changeIsActive: (
|
|
65
|
+
projectKey: string,
|
|
66
|
+
resource: Writable<DiscountCode>,
|
|
67
|
+
{ isActive }: DiscountCodeChangeIsActiveAction
|
|
68
|
+
) => {
|
|
69
|
+
resource.isActive = isActive
|
|
70
|
+
},
|
|
71
|
+
changeCartDiscounts: (
|
|
72
|
+
projectKey: string,
|
|
73
|
+
resource: Writable<DiscountCode>,
|
|
74
|
+
{ cartDiscounts }: DiscountCodeChangeCartDiscountsAction
|
|
75
|
+
) => {
|
|
76
|
+
resource.cartDiscounts = cartDiscounts.map(
|
|
77
|
+
(obj): CartDiscountReference => ({
|
|
78
|
+
typeId: 'cart-discount',
|
|
79
|
+
id: obj.id!,
|
|
80
|
+
})
|
|
81
|
+
)
|
|
82
|
+
},
|
|
83
|
+
setDescription: (
|
|
84
|
+
projectKey: string,
|
|
85
|
+
resource: Writable<DiscountCode>,
|
|
86
|
+
{ description }: DiscountCodeSetDescriptionAction
|
|
87
|
+
) => {
|
|
88
|
+
resource.description = description
|
|
89
|
+
},
|
|
90
|
+
setCartPredicate: (
|
|
91
|
+
projectKey: string,
|
|
92
|
+
resource: Writable<DiscountCode>,
|
|
93
|
+
{ cartPredicate }: DiscountCodeSetCartPredicateAction
|
|
94
|
+
) => {
|
|
95
|
+
resource.cartPredicate = cartPredicate
|
|
96
|
+
},
|
|
97
|
+
setName: (
|
|
98
|
+
projectKey: string,
|
|
99
|
+
resource: Writable<DiscountCode>,
|
|
100
|
+
{ name }: DiscountCodeSetNameAction
|
|
101
|
+
) => {
|
|
102
|
+
resource.name = name
|
|
103
|
+
},
|
|
104
|
+
setMaxApplications: (
|
|
105
|
+
projectKey: string,
|
|
106
|
+
resource: Writable<DiscountCode>,
|
|
107
|
+
{ maxApplications }: DiscountCodeSetMaxApplicationsAction
|
|
108
|
+
) => {
|
|
109
|
+
resource.maxApplications = maxApplications
|
|
110
|
+
},
|
|
111
|
+
setMaxApplicationsPerCustomer: (
|
|
112
|
+
projectKey: string,
|
|
113
|
+
resource: Writable<DiscountCode>,
|
|
114
|
+
{
|
|
115
|
+
maxApplicationsPerCustomer,
|
|
116
|
+
}: DiscountCodeSetMaxApplicationsPerCustomerAction
|
|
117
|
+
) => {
|
|
118
|
+
resource.maxApplicationsPerCustomer = maxApplicationsPerCustomer
|
|
119
|
+
},
|
|
120
|
+
setValidFrom: (
|
|
121
|
+
projectKey: string,
|
|
122
|
+
resource: Writable<DiscountCode>,
|
|
123
|
+
{ validFrom }: DiscountCodeSetValidFromAction
|
|
124
|
+
) => {
|
|
125
|
+
resource.validFrom = validFrom
|
|
126
|
+
},
|
|
127
|
+
setValidUntil: (
|
|
128
|
+
projectKey: string,
|
|
129
|
+
resource: Writable<DiscountCode>,
|
|
130
|
+
{ validUntil }: DiscountCodeSetValidUntilAction
|
|
131
|
+
) => {
|
|
132
|
+
resource.validUntil = validUntil
|
|
133
|
+
},
|
|
134
|
+
setValidFromAndUntil: (
|
|
135
|
+
projectKey: string,
|
|
136
|
+
resource: Writable<DiscountCode>,
|
|
137
|
+
{ validFrom, validUntil }: DiscountCodeSetValidFromAndUntilAction
|
|
138
|
+
) => {
|
|
139
|
+
resource.validFrom = validFrom
|
|
140
|
+
resource.validUntil = validUntil
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseResource,
|
|
3
3
|
ConcurrentModificationError,
|
|
4
|
+
Project,
|
|
4
5
|
} from '@commercetools/platform-sdk'
|
|
5
6
|
import { CommercetoolsError } from '../exceptions'
|
|
6
7
|
|
|
7
8
|
export const checkConcurrentModification = (
|
|
8
|
-
resource: BaseResource,
|
|
9
|
+
resource: BaseResource | Project,
|
|
9
10
|
expectedVersion: number
|
|
10
11
|
) => {
|
|
11
12
|
if (resource.version === expectedVersion) return
|
|
12
13
|
|
|
14
|
+
const identifier = (<BaseResource>resource).id
|
|
15
|
+
? (<BaseResource>resource).id
|
|
16
|
+
: (<Project>resource).key
|
|
17
|
+
|
|
13
18
|
throw new CommercetoolsError<ConcurrentModificationError>(
|
|
14
19
|
{
|
|
15
|
-
message: `Object ${
|
|
20
|
+
message: `Object ${identifier} has a different version than expected. Expected: ${expectedVersion} - Actual: ${resource.version}.`,
|
|
16
21
|
currentVersion: resource.version,
|
|
17
22
|
code: 'ConcurrentModification',
|
|
18
23
|
},
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Extension,
|
|
3
|
+
ExtensionChangeDestinationAction,
|
|
4
|
+
ExtensionChangeTriggersAction,
|
|
5
|
+
ExtensionDraft,
|
|
6
|
+
ExtensionSetKeyAction,
|
|
7
|
+
ExtensionSetTimeoutInMsAction,
|
|
8
|
+
ExtensionUpdateAction,
|
|
9
|
+
ReferenceTypeId,
|
|
10
|
+
} from '@commercetools/platform-sdk'
|
|
11
|
+
import { Writable } from '../types'
|
|
12
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
13
|
+
import { AbstractResourceRepository } from './abstract'
|
|
14
|
+
|
|
15
|
+
export class ExtensionRepository extends AbstractResourceRepository {
|
|
16
|
+
getTypeId(): ReferenceTypeId {
|
|
17
|
+
return 'extension'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
create(projectKey: string, draft: ExtensionDraft): Extension {
|
|
21
|
+
const resource: Extension = {
|
|
22
|
+
...getBaseResourceProperties(),
|
|
23
|
+
key: draft.key,
|
|
24
|
+
timeoutInMs: draft.timeoutInMs,
|
|
25
|
+
destination: draft.destination,
|
|
26
|
+
triggers: draft.triggers,
|
|
27
|
+
}
|
|
28
|
+
this.save(projectKey, resource)
|
|
29
|
+
return resource
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
actions: Record<
|
|
33
|
+
ExtensionUpdateAction['action'],
|
|
34
|
+
(projectKey: string, resource: Writable<Extension>, action: any) => void
|
|
35
|
+
> = {
|
|
36
|
+
setKey: (
|
|
37
|
+
projectKey: string,
|
|
38
|
+
resource: Writable<Extension>,
|
|
39
|
+
{ key }: ExtensionSetKeyAction
|
|
40
|
+
) => {
|
|
41
|
+
resource.key = key
|
|
42
|
+
},
|
|
43
|
+
setTimeoutInMs: (
|
|
44
|
+
projectKey: string,
|
|
45
|
+
resource: Writable<Extension>,
|
|
46
|
+
{ timeoutInMs }: ExtensionSetTimeoutInMsAction
|
|
47
|
+
) => {
|
|
48
|
+
resource.timeoutInMs = timeoutInMs
|
|
49
|
+
},
|
|
50
|
+
changeTriggers: (
|
|
51
|
+
projectKey: string,
|
|
52
|
+
resource: Writable<Extension>,
|
|
53
|
+
{ triggers }: ExtensionChangeTriggersAction
|
|
54
|
+
) => {
|
|
55
|
+
resource.triggers = triggers
|
|
56
|
+
},
|
|
57
|
+
changeDestination: (
|
|
58
|
+
projectKey: string,
|
|
59
|
+
resource: Writable<Extension>,
|
|
60
|
+
{ destination }: ExtensionChangeDestinationAction
|
|
61
|
+
) => {
|
|
62
|
+
resource.destination = destination
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
ReferenceTypeId,
|
|
10
10
|
} from '@commercetools/platform-sdk'
|
|
11
11
|
import { getBaseResourceProperties } from '../helpers'
|
|
12
|
-
import
|
|
12
|
+
import { AbstractResourceRepository } from './abstract'
|
|
13
13
|
import { createCustomFields } from './helpers'
|
|
14
14
|
import { Writable } from '../types'
|
|
15
15
|
|
|
16
|
-
export class InventoryEntryRepository extends
|
|
16
|
+
export class InventoryEntryRepository extends AbstractResourceRepository {
|
|
17
17
|
getTypeId(): ReferenceTypeId {
|
|
18
18
|
return 'inventory-entry'
|
|
19
19
|
}
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
ReferenceTypeId,
|
|
27
27
|
Store,
|
|
28
28
|
} from '@commercetools/platform-sdk'
|
|
29
|
-
import
|
|
29
|
+
import { AbstractResourceRepository, QueryParams } from './abstract'
|
|
30
30
|
import {
|
|
31
31
|
createCustomFields,
|
|
32
32
|
createPrice,
|
|
@@ -37,7 +37,7 @@ import { Writable } from '../types'
|
|
|
37
37
|
import { getBaseResourceProperties } from '../helpers'
|
|
38
38
|
import { CommercetoolsError } from '../exceptions'
|
|
39
39
|
|
|
40
|
-
export class OrderRepository extends
|
|
40
|
+
export class OrderRepository extends AbstractResourceRepository {
|
|
41
41
|
getTypeId(): ReferenceTypeId {
|
|
42
42
|
return 'order'
|
|
43
43
|
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
StateReference,
|
|
9
9
|
TransactionDraft,
|
|
10
10
|
} from '@commercetools/platform-sdk'
|
|
11
|
-
import
|
|
11
|
+
import { AbstractResourceRepository } from './abstract'
|
|
12
12
|
import {
|
|
13
13
|
createCustomFields,
|
|
14
14
|
createTypedMoney,
|
|
@@ -18,7 +18,7 @@ import { getBaseResourceProperties } from '../helpers'
|
|
|
18
18
|
import { v4 as uuidv4 } from 'uuid'
|
|
19
19
|
import { Writable } from '../types'
|
|
20
20
|
|
|
21
|
-
export class PaymentRepository extends
|
|
21
|
+
export class PaymentRepository extends AbstractResourceRepository {
|
|
22
22
|
getTypeId(): ReferenceTypeId {
|
|
23
23
|
return 'payment'
|
|
24
24
|
}
|
|
@@ -40,8 +40,8 @@ export class PaymentRepository extends AbstractRepository {
|
|
|
40
40
|
: undefined,
|
|
41
41
|
}
|
|
42
42
|
: {},
|
|
43
|
-
transactions: (draft.transactions || []).map(
|
|
44
|
-
this.transactionFromTransactionDraft
|
|
43
|
+
transactions: (draft.transactions || []).map(t =>
|
|
44
|
+
this.transactionFromTransactionDraft(t, projectKey)
|
|
45
45
|
),
|
|
46
46
|
interfaceInteractions: (draft.interfaceInteractions || []).map(
|
|
47
47
|
interaction =>
|
|
@@ -54,10 +54,14 @@ export class PaymentRepository extends AbstractRepository {
|
|
|
54
54
|
return resource
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
transactionFromTransactionDraft = (
|
|
57
|
+
transactionFromTransactionDraft = (
|
|
58
|
+
draft: TransactionDraft,
|
|
59
|
+
projectKey: string
|
|
60
|
+
) => ({
|
|
58
61
|
...draft,
|
|
59
62
|
id: uuidv4(),
|
|
60
63
|
amount: createTypedMoney(draft.amount),
|
|
64
|
+
custom: createCustomFields(draft.custom, projectKey, this._storage),
|
|
61
65
|
})
|
|
62
66
|
|
|
63
67
|
actions = {
|
|
@@ -104,7 +108,7 @@ export class PaymentRepository extends AbstractRepository {
|
|
|
104
108
|
) => {
|
|
105
109
|
resource.transactions = [
|
|
106
110
|
...resource.transactions,
|
|
107
|
-
this.transactionFromTransactionDraft(transaction),
|
|
111
|
+
this.transactionFromTransactionDraft(transaction, projectKey),
|
|
108
112
|
]
|
|
109
113
|
},
|
|
110
114
|
// addInterfaceInteraction: () => {},
|
|
@@ -6,11 +6,11 @@ import {
|
|
|
6
6
|
ProductVariantDraft,
|
|
7
7
|
} from '@commercetools/platform-sdk'
|
|
8
8
|
import { getBaseResourceProperties } from '../helpers'
|
|
9
|
-
import
|
|
9
|
+
import { AbstractResourceRepository } from './abstract'
|
|
10
10
|
import { RepositoryTypes } from '../types'
|
|
11
11
|
import { parseFilterExpression } from '../lib/filterParser'
|
|
12
12
|
|
|
13
|
-
export class ProductProjectionRepository extends
|
|
13
|
+
export class ProductProjectionRepository extends AbstractResourceRepository {
|
|
14
14
|
getTypeId(): RepositoryTypes {
|
|
15
15
|
return 'product-projection'
|
|
16
16
|
}
|
|
@@ -2,13 +2,18 @@ import { getBaseResourceProperties } from '../helpers'
|
|
|
2
2
|
import {
|
|
3
3
|
AttributeDefinition,
|
|
4
4
|
AttributeDefinitionDraft,
|
|
5
|
+
AttributeType,
|
|
5
6
|
ProductType,
|
|
7
|
+
ProductTypeChangeLabelAction,
|
|
8
|
+
ProductTypeChangeLocalizedEnumValueLabelAction,
|
|
6
9
|
ProductTypeDraft,
|
|
10
|
+
ProductTypeUpdateAction,
|
|
7
11
|
ReferenceTypeId,
|
|
8
12
|
} from '@commercetools/platform-sdk'
|
|
9
|
-
import
|
|
13
|
+
import { AbstractResourceRepository } from './abstract'
|
|
14
|
+
import { Writable } from 'types'
|
|
10
15
|
|
|
11
|
-
export class ProductTypeRepository extends
|
|
16
|
+
export class ProductTypeRepository extends AbstractResourceRepository {
|
|
12
17
|
getTypeId(): ReferenceTypeId {
|
|
13
18
|
return 'product-type'
|
|
14
19
|
}
|
|
@@ -16,7 +21,9 @@ export class ProductTypeRepository extends AbstractRepository {
|
|
|
16
21
|
create(projectKey: string, draft: ProductTypeDraft): ProductType {
|
|
17
22
|
const resource: ProductType = {
|
|
18
23
|
...getBaseResourceProperties(),
|
|
19
|
-
|
|
24
|
+
key: draft.key,
|
|
25
|
+
name: draft.name,
|
|
26
|
+
description: draft.description,
|
|
20
27
|
attributes: (draft.attributes ?? []).map(a =>
|
|
21
28
|
this.attributeDefinitionFromAttributeDefinitionDraft(projectKey, a)
|
|
22
29
|
),
|
|
@@ -52,5 +59,51 @@ export class ProductTypeRepository extends AbstractRepository {
|
|
|
52
59
|
return
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
actions
|
|
62
|
+
actions: Partial<
|
|
63
|
+
Record<
|
|
64
|
+
ProductTypeUpdateAction['action'],
|
|
65
|
+
(projectKey: string, resource: Writable<ProductType>, action: any) => void
|
|
66
|
+
>
|
|
67
|
+
> = {
|
|
68
|
+
changeLocalizedEnumValueLabel: (
|
|
69
|
+
projectKey: string,
|
|
70
|
+
resource: Writable<ProductType>,
|
|
71
|
+
{
|
|
72
|
+
attributeName,
|
|
73
|
+
newValue,
|
|
74
|
+
}: ProductTypeChangeLocalizedEnumValueLabelAction
|
|
75
|
+
) => {
|
|
76
|
+
const updateAttributeType = (type: Writable<AttributeType>) => {
|
|
77
|
+
switch (type.name) {
|
|
78
|
+
case 'lenum':
|
|
79
|
+
type.values.forEach(v => {
|
|
80
|
+
if (v.key == newValue.key) {
|
|
81
|
+
v.label = newValue.label
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
return
|
|
85
|
+
case 'set':
|
|
86
|
+
updateAttributeType(type.elementType)
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
resource.attributes?.forEach(value => {
|
|
92
|
+
if (value.name == attributeName) {
|
|
93
|
+
updateAttributeType(value.type)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
},
|
|
97
|
+
changeLabel: (
|
|
98
|
+
projectKey: string,
|
|
99
|
+
resource: Writable<ProductType>,
|
|
100
|
+
{ attributeName, label }: ProductTypeChangeLabelAction
|
|
101
|
+
) => {
|
|
102
|
+
resource.attributes?.forEach(value => {
|
|
103
|
+
if (value.name == attributeName) {
|
|
104
|
+
value.label = label
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
},
|
|
108
|
+
}
|
|
56
109
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Price,
|
|
2
3
|
Product,
|
|
3
4
|
ProductData,
|
|
4
5
|
ProductDraft,
|
|
@@ -9,10 +10,10 @@ import {
|
|
|
9
10
|
ReferenceTypeId,
|
|
10
11
|
} from '@commercetools/platform-sdk'
|
|
11
12
|
import { getBaseResourceProperties } from '../helpers'
|
|
12
|
-
import
|
|
13
|
+
import { AbstractResourceRepository } from './abstract'
|
|
13
14
|
import { Writable } from '../types'
|
|
14
15
|
|
|
15
|
-
export class ProductRepository extends
|
|
16
|
+
export class ProductRepository extends AbstractResourceRepository {
|
|
16
17
|
getTypeId(): ReferenceTypeId {
|
|
17
18
|
return 'product'
|
|
18
19
|
}
|
|
@@ -207,5 +208,6 @@ const variantFromDraft = (
|
|
|
207
208
|
id: variantId,
|
|
208
209
|
sku: variant?.sku,
|
|
209
210
|
attributes: variant?.attributes,
|
|
211
|
+
prices: variant?.prices as Price[],
|
|
210
212
|
}
|
|
211
213
|
}
|