@labdigital/commercetools-mock 1.5.0 → 1.6.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 +5 -4
- package/dist/index.cjs +117 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.js +117 -17
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/constants.ts +2 -2
- package/src/ctMock.ts +176 -176
- package/src/exceptions.ts +10 -10
- package/src/helpers.ts +26 -26
- package/src/index.test.ts +173 -173
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +19 -19
- package/src/lib/haversine.test.ts +13 -13
- package/src/lib/haversine.ts +14 -14
- package/src/lib/masking.ts +15 -15
- package/src/lib/parser.ts +2 -2
- package/src/lib/predicateParser.test.ts +204 -204
- package/src/lib/predicateParser.ts +398 -398
- package/src/lib/projectionSearchFilter.test.ts +168 -168
- package/src/lib/projectionSearchFilter.ts +272 -269
- package/src/lib/proxy.ts +8 -8
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.ts +103 -101
- package/src/oauth/store.ts +27 -27
- package/src/priceSelector.test.ts +68 -68
- package/src/priceSelector.ts +70 -70
- package/src/product-projection-search.ts +296 -296
- package/src/projectAPI.test.ts +3 -3
- package/src/projectAPI.ts +46 -46
- package/src/repositories/abstract.ts +190 -190
- package/src/repositories/associate-role.ts +10 -7
- package/src/repositories/attribute-group.ts +63 -8
- package/src/repositories/business-unit.ts +10 -7
- package/src/repositories/cart-discount.ts +134 -134
- package/src/repositories/cart.ts +517 -514
- package/src/repositories/category.ts +170 -167
- package/src/repositories/channel.ts +114 -111
- package/src/repositories/custom-object.ts +66 -63
- package/src/repositories/customer-group.ts +72 -69
- package/src/repositories/customer.ts +90 -90
- package/src/repositories/discount-code.ts +171 -168
- package/src/repositories/errors.ts +15 -15
- package/src/repositories/extension.ts +79 -76
- package/src/repositories/helpers.ts +180 -180
- package/src/repositories/index.ts +39 -39
- package/src/repositories/inventory-entry.ts +98 -95
- package/src/repositories/my-order.ts +11 -11
- package/src/repositories/order-edit.ts +29 -29
- package/src/repositories/order.test.ts +191 -191
- package/src/repositories/order.ts +393 -393
- package/src/repositories/payment.ts +155 -155
- package/src/repositories/product-discount.ts +149 -149
- package/src/repositories/product-projection.ts +135 -50
- package/src/repositories/product-selection.ts +31 -31
- package/src/repositories/product-type.ts +156 -156
- package/src/repositories/product.ts +600 -597
- package/src/repositories/project.ts +136 -135
- package/src/repositories/quote-request.ts +19 -19
- package/src/repositories/quote.ts +19 -19
- package/src/repositories/review.ts +24 -24
- package/src/repositories/shipping-method.ts +217 -217
- package/src/repositories/shopping-list.ts +49 -49
- package/src/repositories/staged-quote.ts +20 -20
- package/src/repositories/standalone-price.ts +72 -61
- package/src/repositories/state.ts +84 -84
- package/src/repositories/store.ts +114 -114
- package/src/repositories/subscription.ts +40 -40
- package/src/repositories/tax-category.ts +98 -98
- package/src/repositories/type.ts +157 -157
- package/src/repositories/zone.ts +71 -71
- package/src/server.ts +2 -2
- package/src/services/abstract.ts +173 -173
- package/src/services/attribute-group.ts +16 -0
- package/src/services/cart-discount.ts +8 -8
- package/src/services/cart.test.ts +409 -409
- package/src/services/cart.ts +50 -50
- package/src/services/category.test.ts +25 -25
- package/src/services/category.ts +8 -8
- package/src/services/channel.ts +8 -8
- package/src/services/custom-object.test.ts +184 -184
- package/src/services/custom-object.ts +48 -48
- package/src/services/customer-group.ts +8 -8
- package/src/services/customer.test.ts +151 -151
- package/src/services/customer.ts +27 -27
- package/src/services/discount-code.ts +8 -8
- package/src/services/extension.ts +8 -8
- package/src/services/index.ts +52 -44
- package/src/services/inventory-entry.test.ts +162 -162
- package/src/services/inventory-entry.ts +8 -8
- package/src/services/my-cart.test.ts +78 -78
- package/src/services/my-cart.ts +28 -28
- package/src/services/my-customer.test.ts +44 -44
- package/src/services/my-customer.ts +53 -53
- package/src/services/my-order.ts +20 -20
- package/src/services/my-payment.test.ts +65 -65
- package/src/services/my-payment.ts +8 -8
- package/src/services/order.test.ts +527 -527
- package/src/services/order.ts +31 -31
- package/src/services/payment.test.ts +65 -65
- package/src/services/payment.ts +8 -8
- package/src/services/product-discount.ts +8 -8
- package/src/services/product-projection.test.ts +502 -428
- package/src/services/product-projection.ts +32 -18
- package/src/services/product-type.test.ts +56 -56
- package/src/services/product-type.ts +8 -8
- package/src/services/product.test.ts +510 -510
- package/src/services/product.ts +8 -8
- package/src/services/project.ts +34 -34
- package/src/services/shipping-method.test.ts +81 -81
- package/src/services/shipping-method.ts +12 -12
- package/src/services/shopping-list.ts +8 -8
- package/src/services/standalone-price.test.ts +256 -256
- package/src/services/standalone-price.ts +8 -8
- package/src/services/state.test.ts +42 -42
- package/src/services/state.ts +8 -8
- package/src/services/store.test.ts +57 -57
- package/src/services/store.ts +8 -8
- package/src/services/subscription.ts +8 -8
- package/src/services/tax-category.test.ts +61 -61
- package/src/services/tax-category.ts +8 -8
- package/src/services/type.ts +8 -8
- package/src/services/zone.ts +8 -8
- package/src/storage/abstract.ts +58 -58
- package/src/storage/in-memory.ts +419 -419
- package/src/types.ts +82 -82
package/src/projectAPI.ts
CHANGED
|
@@ -5,54 +5,54 @@ import { AbstractStorage } from './storage/index.js'
|
|
|
5
5
|
import { ResourceMap, ResourceType } from './types.js'
|
|
6
6
|
|
|
7
7
|
export class ProjectAPI {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
private projectKey: string
|
|
9
|
+
private _storage: AbstractStorage
|
|
10
|
+
private _repositories: RepositoryMap
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
constructor(
|
|
13
|
+
projectKey: string,
|
|
14
|
+
repositories: RepositoryMap,
|
|
15
|
+
storage: AbstractStorage
|
|
16
|
+
) {
|
|
17
|
+
this.projectKey = projectKey
|
|
18
|
+
this._storage = storage
|
|
19
|
+
this._repositories = repositories
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
22
|
+
add<T extends keyof RepositoryMap & keyof ResourceMap>(
|
|
23
|
+
typeId: T,
|
|
24
|
+
resource: ResourceMap[T]
|
|
25
|
+
) {
|
|
26
|
+
const repository = this._repositories[typeId]
|
|
27
|
+
if (repository) {
|
|
28
|
+
this._storage.add(this.projectKey, typeId, {
|
|
29
|
+
...getBaseResourceProperties(),
|
|
30
|
+
...resource,
|
|
31
|
+
})
|
|
32
|
+
} else {
|
|
33
|
+
throw new Error(`Service for ${typeId} not implemented yet`)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
get<RT extends ResourceType>(
|
|
38
|
+
typeId: RT,
|
|
39
|
+
id: string,
|
|
40
|
+
params?: GetParams
|
|
41
|
+
): ResourceMap[RT] {
|
|
42
|
+
return this._storage.get(
|
|
43
|
+
this.projectKey,
|
|
44
|
+
typeId,
|
|
45
|
+
id,
|
|
46
|
+
params
|
|
47
|
+
) as ResourceMap[RT]
|
|
48
|
+
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
50
|
+
// TODO: Not sure if we want to expose this...
|
|
51
|
+
getRepository<RT extends keyof RepositoryMap>(typeId: RT): RepositoryMap[RT] {
|
|
52
|
+
const repository = this._repositories[typeId]
|
|
53
|
+
if (repository !== undefined) {
|
|
54
|
+
return repository as RepositoryMap[RT]
|
|
55
|
+
}
|
|
56
|
+
throw new Error('No such repository')
|
|
57
|
+
}
|
|
58
58
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
BaseResource,
|
|
3
|
+
Project,
|
|
4
|
+
ResourceNotFoundError,
|
|
5
|
+
UpdateAction,
|
|
6
6
|
} from '@commercetools/platform-sdk'
|
|
7
7
|
import deepEqual from 'deep-equal'
|
|
8
8
|
import { CommercetoolsError } from '../exceptions.js'
|
|
@@ -12,203 +12,203 @@ import { ResourceMap, ResourceType, ShallowWritable } from './../types.js'
|
|
|
12
12
|
import { checkConcurrentModification } from './errors.js'
|
|
13
13
|
|
|
14
14
|
export type QueryParams = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
expand?: string[]
|
|
16
|
+
where?: string[]
|
|
17
|
+
offset?: number
|
|
18
|
+
limit?: number
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export type GetParams = {
|
|
22
|
-
|
|
22
|
+
expand?: string[]
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export type RepositoryContext = {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
projectKey: string
|
|
27
|
+
storeKey?: string
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export abstract class AbstractRepository<R extends BaseResource | Project> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
31
|
+
protected _storage: AbstractStorage
|
|
32
|
+
protected actions: Partial<
|
|
33
|
+
Record<
|
|
34
|
+
any,
|
|
35
|
+
(context: RepositoryContext, resource: any, action: any) => void
|
|
36
|
+
>
|
|
37
|
+
> = {}
|
|
38
|
+
|
|
39
|
+
constructor(storage: AbstractStorage) {
|
|
40
|
+
this._storage = storage
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
abstract saveNew({ projectKey }: RepositoryContext, resource: R): void
|
|
44
|
+
|
|
45
|
+
abstract saveUpdate(
|
|
46
|
+
{ projectKey }: RepositoryContext,
|
|
47
|
+
version: number,
|
|
48
|
+
resource: R
|
|
49
|
+
): void
|
|
50
|
+
|
|
51
|
+
processUpdateActions(
|
|
52
|
+
context: RepositoryContext,
|
|
53
|
+
resource: R,
|
|
54
|
+
version: number,
|
|
55
|
+
actions: UpdateAction[]
|
|
56
|
+
): R {
|
|
57
|
+
// Deep-copy
|
|
58
|
+
const updatedResource = cloneObject(resource) as ShallowWritable<R>
|
|
59
|
+
const identifier = (resource as BaseResource).id
|
|
60
|
+
? (resource as BaseResource).id
|
|
61
|
+
: (resource as Project).key
|
|
62
|
+
|
|
63
|
+
actions.forEach((action) => {
|
|
64
|
+
const updateFunc = this.actions[action.action]
|
|
65
|
+
|
|
66
|
+
if (!updateFunc) {
|
|
67
|
+
console.error(`No mock implemented for update action ${action.action}`)
|
|
68
|
+
throw new Error(
|
|
69
|
+
`No mock implemented for update action ${action.action}`
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const beforeUpdate = cloneObject(resource)
|
|
74
|
+
updateFunc(context, updatedResource, action)
|
|
75
|
+
|
|
76
|
+
// Check if the object is updated. We need to increase the version of
|
|
77
|
+
// an object per action which does an actual modification.
|
|
78
|
+
// This isn't the most performant method to do this (the update action
|
|
79
|
+
// should return a flag) but for now the easiest.
|
|
80
|
+
if (!deepEqual(beforeUpdate, updatedResource)) {
|
|
81
|
+
// We only check the version when there is an actual modification to
|
|
82
|
+
// be stored.
|
|
83
|
+
checkConcurrentModification(resource.version, version, identifier)
|
|
84
|
+
|
|
85
|
+
updatedResource.version += 1
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
// If all actions succeeded we write the new version
|
|
90
|
+
// to the storage.
|
|
91
|
+
if (resource.version != updatedResource.version) {
|
|
92
|
+
this.saveUpdate(context, version, updatedResource)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const result = this.postProcessResource(updatedResource)
|
|
96
|
+
if (!result) {
|
|
97
|
+
throw new Error('invalid post process action')
|
|
98
|
+
}
|
|
99
|
+
return result
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
abstract postProcessResource(resource: any): any
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
export abstract class AbstractResourceRepository<
|
|
106
|
-
|
|
106
|
+
T extends ResourceType,
|
|
107
107
|
> extends AbstractRepository<ResourceMap[T]> {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
108
|
+
abstract create(context: RepositoryContext, draft: any): ResourceMap[T]
|
|
109
|
+
abstract getTypeId(): T
|
|
110
|
+
|
|
111
|
+
constructor(storage: AbstractStorage) {
|
|
112
|
+
super(storage)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
postProcessResource(resource: ResourceMap[T]): ResourceMap[T] {
|
|
116
|
+
return resource
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
query(context: RepositoryContext, params: QueryParams = {}) {
|
|
120
|
+
const result = this._storage.query(context.projectKey, this.getTypeId(), {
|
|
121
|
+
expand: params.expand,
|
|
122
|
+
where: params.where,
|
|
123
|
+
offset: params.offset,
|
|
124
|
+
limit: params.limit,
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
result.results = result.results.map(this.postProcessResource)
|
|
129
|
+
return result
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
get(
|
|
133
|
+
context: RepositoryContext,
|
|
134
|
+
id: string,
|
|
135
|
+
params: GetParams = {}
|
|
136
|
+
): ResourceMap[T] | null {
|
|
137
|
+
const resource = this._storage.get(
|
|
138
|
+
context.projectKey,
|
|
139
|
+
this.getTypeId(),
|
|
140
|
+
id,
|
|
141
|
+
params
|
|
142
|
+
)
|
|
143
|
+
return resource ? this.postProcessResource(resource) : null
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getByKey(
|
|
147
|
+
context: RepositoryContext,
|
|
148
|
+
key: string,
|
|
149
|
+
params: GetParams = {}
|
|
150
|
+
): ResourceMap[T] | null {
|
|
151
|
+
const resource = this._storage.getByKey(
|
|
152
|
+
context.projectKey,
|
|
153
|
+
this.getTypeId(),
|
|
154
|
+
key,
|
|
155
|
+
params
|
|
156
|
+
)
|
|
157
|
+
return resource ? this.postProcessResource(resource) : null
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
delete(
|
|
161
|
+
context: RepositoryContext,
|
|
162
|
+
id: string,
|
|
163
|
+
params: GetParams = {}
|
|
164
|
+
): ResourceMap[T] | null {
|
|
165
|
+
const resource = this._storage.delete(
|
|
166
|
+
context.projectKey,
|
|
167
|
+
this.getTypeId(),
|
|
168
|
+
id,
|
|
169
|
+
params
|
|
170
|
+
)
|
|
171
|
+
return resource ? this.postProcessResource(resource) : null
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
saveNew(
|
|
175
|
+
context: RepositoryContext,
|
|
176
|
+
resource: ShallowWritable<ResourceMap[T]>
|
|
177
|
+
) {
|
|
178
|
+
resource.version = 1
|
|
179
|
+
this._storage.add(context.projectKey, this.getTypeId(), resource as any)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
saveUpdate(
|
|
183
|
+
context: RepositoryContext,
|
|
184
|
+
version: number,
|
|
185
|
+
resource: ShallowWritable<ResourceMap[T]>
|
|
186
|
+
) {
|
|
187
|
+
// Check if the resource still exists.
|
|
188
|
+
const current = this._storage.get(
|
|
189
|
+
context.projectKey,
|
|
190
|
+
this.getTypeId(),
|
|
191
|
+
resource.id
|
|
192
|
+
)
|
|
193
|
+
if (!current) {
|
|
194
|
+
throw new CommercetoolsError<ResourceNotFoundError>(
|
|
195
|
+
{
|
|
196
|
+
code: 'ResourceNotFound',
|
|
197
|
+
message: 'Resource not found while updating',
|
|
198
|
+
},
|
|
199
|
+
400
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
checkConcurrentModification(current.version, version, resource.id)
|
|
204
|
+
|
|
205
|
+
if (current.version === resource.version) {
|
|
206
|
+
throw new Error('Internal error: no changes to save')
|
|
207
|
+
}
|
|
208
|
+
resource.lastModifiedAt = new Date().toISOString()
|
|
209
|
+
|
|
210
|
+
this._storage.add(context.projectKey, this.getTypeId(), resource as any)
|
|
211
|
+
|
|
212
|
+
return resource
|
|
213
|
+
}
|
|
214
214
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { AssociateRole } from '@commercetools/platform-sdk'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AbstractResourceRepository,
|
|
4
|
+
type RepositoryContext,
|
|
5
|
+
} from './abstract.js'
|
|
3
6
|
|
|
4
7
|
export class AssociateRoleRepository extends AbstractResourceRepository<'associate-role'> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
getTypeId() {
|
|
9
|
+
return 'associate-role' as const
|
|
10
|
+
}
|
|
11
|
+
create(context: RepositoryContext, draft: any): AssociateRole {
|
|
12
|
+
throw new Error('Method not implemented.')
|
|
13
|
+
}
|
|
11
14
|
}
|
|
@@ -1,11 +1,66 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
AttributeGroup,
|
|
3
|
+
AttributeGroupChangeNameAction,
|
|
4
|
+
AttributeGroupDraft,
|
|
5
|
+
AttributeGroupSetAttributesAction,
|
|
6
|
+
AttributeGroupSetDescriptionAction,
|
|
7
|
+
AttributeGroupSetKeyAction,
|
|
8
|
+
} from '@commercetools/platform-sdk'
|
|
9
|
+
import {
|
|
10
|
+
AbstractResourceRepository,
|
|
11
|
+
type RepositoryContext,
|
|
12
|
+
} from './abstract.js'
|
|
13
|
+
import { getBaseResourceProperties } from '../helpers.js'
|
|
14
|
+
import { Writable } from '../types.js'
|
|
3
15
|
|
|
4
16
|
export class AttributeGroupRepository extends AbstractResourceRepository<'attribute-group'> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
getTypeId() {
|
|
18
|
+
return 'attribute-group' as const
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
create(
|
|
22
|
+
context: RepositoryContext,
|
|
23
|
+
draft: AttributeGroupDraft
|
|
24
|
+
): AttributeGroup {
|
|
25
|
+
const resource: AttributeGroup = {
|
|
26
|
+
...getBaseResourceProperties(),
|
|
27
|
+
name: draft.name,
|
|
28
|
+
description: draft.description,
|
|
29
|
+
key: draft.key,
|
|
30
|
+
attributes: draft.attributes,
|
|
31
|
+
}
|
|
32
|
+
this.saveNew(context, resource)
|
|
33
|
+
return resource
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
actions = {
|
|
37
|
+
setAttributes: (
|
|
38
|
+
_context: RepositoryContext,
|
|
39
|
+
resource: Writable<AttributeGroup>,
|
|
40
|
+
{ attributes }: AttributeGroupSetAttributesAction
|
|
41
|
+
) => {
|
|
42
|
+
resource.attributes = attributes
|
|
43
|
+
},
|
|
44
|
+
changeName: (
|
|
45
|
+
_context: RepositoryContext,
|
|
46
|
+
resource: Writable<AttributeGroup>,
|
|
47
|
+
{ name }: AttributeGroupChangeNameAction
|
|
48
|
+
) => {
|
|
49
|
+
resource.name = name
|
|
50
|
+
},
|
|
51
|
+
setDescription: (
|
|
52
|
+
_context: RepositoryContext,
|
|
53
|
+
resource: Writable<AttributeGroup>,
|
|
54
|
+
{ description }: AttributeGroupSetDescriptionAction
|
|
55
|
+
) => {
|
|
56
|
+
resource.description = description
|
|
57
|
+
},
|
|
58
|
+
setKey: (
|
|
59
|
+
_context: RepositoryContext,
|
|
60
|
+
resource: Writable<AttributeGroup>,
|
|
61
|
+
{ key }: AttributeGroupSetKeyAction
|
|
62
|
+
) => {
|
|
63
|
+
resource.key = key
|
|
64
|
+
},
|
|
65
|
+
}
|
|
11
66
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { BusinessUnit } from '@commercetools/platform-sdk'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AbstractResourceRepository,
|
|
4
|
+
type RepositoryContext,
|
|
5
|
+
} from './abstract.js'
|
|
3
6
|
|
|
4
7
|
export class BusinessUnitRepository extends AbstractResourceRepository<'business-unit'> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
getTypeId() {
|
|
9
|
+
return 'business-unit' as const
|
|
10
|
+
}
|
|
11
|
+
create(context: RepositoryContext, draft: any): BusinessUnit {
|
|
12
|
+
throw new Error('Method not implemented.')
|
|
13
|
+
}
|
|
11
14
|
}
|