@labdigital/commercetools-mock 1.2.0 → 1.3.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.mts +602 -0
- package/dist/index.d.ts +43 -26
- package/dist/index.global.js +6319 -6084
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +344 -163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +340 -163
- package/dist/index.mjs.map +1 -1
- package/package.json +33 -39
- package/src/index.test.ts +2 -1
- package/src/lib/haversine.test.ts +1 -0
- package/src/lib/predicateParser.test.ts +2 -1
- package/src/lib/projectionSearchFilter.test.ts +2 -1
- package/src/lib/projectionSearchFilter.ts +2 -2
- package/src/oauth/server.ts +3 -4
- package/src/priceSelector.test.ts +2 -1
- package/src/priceSelector.ts +2 -2
- package/src/product-projection-search.ts +8 -8
- package/src/projectAPI.test.ts +1 -0
- package/src/repositories/abstract.ts +1 -1
- package/src/repositories/associate-role.ts +11 -0
- package/src/repositories/attribute-group.ts +11 -0
- package/src/repositories/business-unit.ts +11 -0
- package/src/repositories/cart-discount.ts +11 -4
- package/src/repositories/cart.ts +91 -9
- package/src/repositories/category.ts +3 -3
- package/src/repositories/channel.ts +3 -3
- package/src/repositories/custom-object.ts +3 -3
- package/src/repositories/customer-group.ts +3 -3
- package/src/repositories/customer.ts +4 -3
- package/src/repositories/discount-code.ts +3 -3
- package/src/repositories/errors.ts +1 -1
- package/src/repositories/extension.ts +3 -3
- package/src/repositories/helpers.ts +49 -6
- package/src/repositories/index.ts +6 -0
- package/src/repositories/inventory-entry.ts +4 -4
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/order-edit.ts +2 -2
- package/src/repositories/order.test.ts +10 -39
- package/src/repositories/order.ts +31 -16
- package/src/repositories/payment.ts +8 -7
- package/src/repositories/product-discount.ts +2 -2
- package/src/repositories/product-projection.ts +5 -5
- package/src/repositories/product-selection.ts +3 -2
- package/src/repositories/product-type.ts +2 -2
- package/src/repositories/product.ts +4 -9
- package/src/repositories/project.ts +2 -2
- package/src/repositories/quote-request.ts +2 -2
- package/src/repositories/quote.ts +2 -2
- package/src/repositories/review.ts +2 -2
- package/src/repositories/shipping-method.ts +2 -2
- package/src/repositories/shopping-list.ts +19 -13
- package/src/repositories/staged-quote.ts +2 -2
- package/src/repositories/standalone-price.ts +3 -3
- package/src/repositories/state.ts +2 -2
- package/src/repositories/store.ts +3 -2
- package/src/repositories/subscription.ts +1 -1
- package/src/repositories/tax-category.ts +2 -2
- package/src/repositories/type.ts +2 -2
- package/src/repositories/zone.ts +2 -2
- package/src/services/abstract.ts +2 -2
- package/src/services/cart.test.ts +2 -1
- package/src/services/cart.ts +4 -4
- package/src/services/category.test.ts +2 -1
- package/src/services/custom-object.test.ts +2 -1
- package/src/services/custom-object.ts +3 -3
- package/src/services/customer.test.ts +1 -0
- package/src/services/inventory-entry.test.ts +2 -1
- package/src/services/my-cart.test.ts +7 -3
- package/src/services/my-customer.test.ts +4 -2
- package/src/services/my-payment.test.ts +2 -1
- package/src/services/order.test.ts +2 -1
- package/src/services/payment.test.ts +2 -1
- package/src/services/product-projection.test.ts +3 -2
- package/src/services/product-type.test.ts +2 -1
- package/src/services/product.test.ts +2 -1
- package/src/services/project.ts +1 -1
- package/src/services/shipping-method.test.ts +2 -1
- package/src/services/standalone-price.test.ts +255 -244
- package/src/services/state.test.ts +2 -1
- package/src/services/store.test.ts +6 -1
- package/src/services/tax-category.test.ts +2 -1
- package/src/storage/abstract.ts +1 -1
- package/src/storage/in-memory.ts +7 -1
- package/src/types.ts +7 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Address,
|
|
3
3
|
BaseAddress,
|
|
4
|
+
CentPrecisionMoney,
|
|
4
5
|
CustomFields,
|
|
5
6
|
CustomFieldsDraft,
|
|
7
|
+
HighPrecisionMoney,
|
|
8
|
+
HighPrecisionMoneyDraft,
|
|
6
9
|
InvalidJsonInputError,
|
|
7
|
-
Money,
|
|
8
10
|
Price,
|
|
9
11
|
PriceDraft,
|
|
10
12
|
Reference,
|
|
@@ -12,15 +14,17 @@ import {
|
|
|
12
14
|
ResourceIdentifier,
|
|
13
15
|
Store,
|
|
14
16
|
StoreKeyReference,
|
|
17
|
+
StoreReference,
|
|
15
18
|
StoreResourceIdentifier,
|
|
16
19
|
Type,
|
|
17
20
|
TypedMoney,
|
|
21
|
+
_Money,
|
|
18
22
|
} from '@commercetools/platform-sdk'
|
|
19
|
-
import { Request } from 'express'
|
|
23
|
+
import type { Request } from 'express'
|
|
20
24
|
import { v4 as uuidv4 } from 'uuid'
|
|
21
25
|
import { CommercetoolsError } from '../exceptions'
|
|
22
26
|
import { AbstractStorage } from '../storage'
|
|
23
|
-
import { RepositoryContext } from './abstract'
|
|
27
|
+
import { type RepositoryContext } from './abstract'
|
|
24
28
|
|
|
25
29
|
export const createAddress = (
|
|
26
30
|
base: BaseAddress | undefined,
|
|
@@ -72,7 +76,7 @@ export const createPrice = (draft: PriceDraft): Price => ({
|
|
|
72
76
|
value: createTypedMoney(draft.value),
|
|
73
77
|
})
|
|
74
78
|
|
|
75
|
-
export const
|
|
79
|
+
export const createCentPrecisionMoney = (value: _Money): CentPrecisionMoney => {
|
|
76
80
|
// Taken from https://docs.adyen.com/development-resources/currency-codes
|
|
77
81
|
let fractionDigits = 2
|
|
78
82
|
switch (value.currencyCode.toUpperCase()) {
|
|
@@ -106,13 +110,25 @@ export const createTypedMoney = (value: Money): TypedMoney => {
|
|
|
106
110
|
fractionDigits = 2
|
|
107
111
|
}
|
|
108
112
|
|
|
113
|
+
if ((value as HighPrecisionMoney & HighPrecisionMoneyDraft).preciseAmount) {
|
|
114
|
+
throw new Error('HighPrecisionMoney not supported')
|
|
115
|
+
}
|
|
116
|
+
|
|
109
117
|
return {
|
|
110
118
|
type: 'centPrecision',
|
|
111
|
-
|
|
119
|
+
// centAmont is only optional on HighPrecisionMoney, so this should never
|
|
120
|
+
// fallback to 0
|
|
121
|
+
centAmount: value.centAmount ?? 0,
|
|
122
|
+
currencyCode: value.currencyCode,
|
|
112
123
|
fractionDigits: fractionDigits,
|
|
113
124
|
}
|
|
114
125
|
}
|
|
115
126
|
|
|
127
|
+
export const createTypedMoney = (value: _Money): TypedMoney => {
|
|
128
|
+
const result = createCentPrecisionMoney(value)
|
|
129
|
+
return result
|
|
130
|
+
}
|
|
131
|
+
|
|
116
132
|
export const resolveStoreReference = (
|
|
117
133
|
ref: StoreResourceIdentifier | undefined,
|
|
118
134
|
projectKey: string,
|
|
@@ -141,6 +157,7 @@ export const getReferenceFromResourceIdentifier = <T extends Reference>(
|
|
|
141
157
|
{
|
|
142
158
|
code: 'InvalidJsonInput',
|
|
143
159
|
message: `${resourceIdentifier.typeId}: ResourceIdentifier requires an 'id' xor a 'key'`,
|
|
160
|
+
detailedErrorMessage: `ResourceIdentifier requires an 'id' xor a 'key'`,
|
|
144
161
|
},
|
|
145
162
|
400
|
|
146
163
|
)
|
|
@@ -172,6 +189,32 @@ export const getReferenceFromResourceIdentifier = <T extends Reference>(
|
|
|
172
189
|
} as unknown as T
|
|
173
190
|
}
|
|
174
191
|
|
|
192
|
+
export const getStoreKeyReference = (
|
|
193
|
+
id: StoreResourceIdentifier,
|
|
194
|
+
projectKey: string,
|
|
195
|
+
storage: AbstractStorage
|
|
196
|
+
): StoreKeyReference => {
|
|
197
|
+
if (id.key) {
|
|
198
|
+
return {
|
|
199
|
+
typeId: 'store',
|
|
200
|
+
key: id.key,
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const value = getReferenceFromResourceIdentifier<StoreReference>(
|
|
204
|
+
id,
|
|
205
|
+
projectKey,
|
|
206
|
+
storage
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
if (!value.obj?.key) {
|
|
210
|
+
throw new Error('No store found for reference')
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
typeId: 'store',
|
|
214
|
+
key: value.obj?.key,
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
175
218
|
export const getRepositoryContext = (request: Request): RepositoryContext => ({
|
|
176
219
|
projectKey: request.params.projectKey,
|
|
177
220
|
storeKey: request.params.storeKey,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { AbstractStorage } from '../storage'
|
|
2
|
+
import { AssociateRoleRepository } from './associate-role'
|
|
3
|
+
import { AttributeGroupRepository } from './attribute-group'
|
|
4
|
+
import { BusinessUnitRepository } from './business-unit'
|
|
2
5
|
import { CartRepository } from './cart'
|
|
3
6
|
import { CartDiscountRepository } from './cart-discount'
|
|
4
7
|
import { CategoryRepository } from './category'
|
|
@@ -36,6 +39,9 @@ import { ZoneRepository } from './zone'
|
|
|
36
39
|
export type RepositoryMap = ReturnType<typeof createRepositories>
|
|
37
40
|
|
|
38
41
|
export const createRepositories = (storage: AbstractStorage) => ({
|
|
42
|
+
'associate-role': new AssociateRoleRepository(storage),
|
|
43
|
+
'attribute-group': new AttributeGroupRepository(storage),
|
|
44
|
+
'business-unit': new BusinessUnitRepository(storage),
|
|
39
45
|
category: new CategoryRepository(storage),
|
|
40
46
|
cart: new CartRepository(storage),
|
|
41
47
|
'cart-discount': new CartDiscountRepository(storage),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
InventoryEntry,
|
|
3
3
|
InventoryEntryChangeQuantityAction,
|
|
4
4
|
InventoryEntryDraft,
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
InventoryEntrySetRestockableInDaysAction,
|
|
9
9
|
} from '@commercetools/platform-sdk'
|
|
10
10
|
import { getBaseResourceProperties } from '../helpers'
|
|
11
|
-
import { Writable } from '../types'
|
|
12
|
-
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
11
|
+
import type { Writable } from '../types'
|
|
12
|
+
import { AbstractResourceRepository, type RepositoryContext } from './abstract'
|
|
13
13
|
import { createCustomFields } from './helpers'
|
|
14
14
|
|
|
15
15
|
export class InventoryEntryRepository extends AbstractResourceRepository<'inventory-entry'> {
|
|
@@ -91,7 +91,7 @@ export class InventoryEntryRepository extends AbstractResourceRepository<'invent
|
|
|
91
91
|
typeId: 'type',
|
|
92
92
|
id: resolvedType.id,
|
|
93
93
|
},
|
|
94
|
-
fields: fields ||
|
|
94
|
+
fields: fields || {},
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
},
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CartReference,
|
|
3
3
|
MyOrderFromCartDraft,
|
|
4
4
|
Order,
|
|
5
5
|
} from '@commercetools/platform-sdk'
|
|
6
6
|
import assert from 'assert'
|
|
7
|
-
import { RepositoryContext } from './abstract'
|
|
7
|
+
import { type RepositoryContext } from './abstract'
|
|
8
8
|
import { OrderRepository } from './order'
|
|
9
9
|
|
|
10
10
|
export class MyOrderRepository extends OrderRepository {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
OrderEdit,
|
|
3
3
|
OrderEditDraft,
|
|
4
4
|
OrderEditResult,
|
|
5
5
|
OrderEditUpdateAction,
|
|
6
6
|
} from '@commercetools/platform-sdk'
|
|
7
7
|
import { getBaseResourceProperties } from '../helpers'
|
|
8
|
-
import { Writable } from '../types'
|
|
8
|
+
import type { Writable } from '../types'
|
|
9
9
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
10
10
|
|
|
11
11
|
export class OrderEditRepository extends AbstractResourceRepository<'order-edit'> {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Cart, OrderImportDraft } from '@commercetools/platform-sdk'
|
|
1
|
+
import type { Cart, OrderImportDraft } from '@commercetools/platform-sdk'
|
|
2
|
+
import { describe, expect, test } from 'vitest'
|
|
2
3
|
import { InMemoryStorage } from '../storage'
|
|
3
4
|
import { OrderRepository } from './order'
|
|
4
5
|
|
|
@@ -12,6 +13,10 @@ describe('Order repository', () => {
|
|
|
12
13
|
version: 1,
|
|
13
14
|
createdAt: '2021-09-02T12:23:30.036Z',
|
|
14
15
|
lastModifiedAt: '2021-09-02T12:23:30.546Z',
|
|
16
|
+
discountCodes: [],
|
|
17
|
+
directDiscounts : [],
|
|
18
|
+
inventoryMode: 'None',
|
|
19
|
+
itemShippingAddresses: [],
|
|
15
20
|
lineItems: [],
|
|
16
21
|
customLineItems: [],
|
|
17
22
|
totalPrice: {
|
|
@@ -52,6 +57,10 @@ describe('Order repository', () => {
|
|
|
52
57
|
version: 1,
|
|
53
58
|
createdAt: '2021-09-02T12:23:30.036Z',
|
|
54
59
|
lastModifiedAt: '2021-09-02T12:23:30.546Z',
|
|
60
|
+
discountCodes: [],
|
|
61
|
+
directDiscounts : [],
|
|
62
|
+
inventoryMode: 'None',
|
|
63
|
+
itemShippingAddresses: [],
|
|
55
64
|
lineItems: [],
|
|
56
65
|
customLineItems: [],
|
|
57
66
|
totalPrice: {
|
|
@@ -115,31 +124,21 @@ describe('Order repository', () => {
|
|
|
115
124
|
customLineItems: [],
|
|
116
125
|
lineItems: [
|
|
117
126
|
{
|
|
118
|
-
id: '15fc56ba-a74e-4cf8-b4b0-bada5c101541',
|
|
119
127
|
productId: 'PRODUCTID',
|
|
120
128
|
name: {
|
|
121
129
|
'en-US': 'The product',
|
|
122
130
|
},
|
|
123
|
-
productType: {
|
|
124
|
-
typeId: 'product-type',
|
|
125
|
-
id: '109caecb-abe6-4900-ab03-7af5af985ff3',
|
|
126
|
-
// @ts-ignore
|
|
127
|
-
version: 1,
|
|
128
|
-
},
|
|
129
131
|
variant: {
|
|
130
132
|
id: 1,
|
|
131
133
|
sku: 'MYSKU',
|
|
132
|
-
key: 'MYKEY',
|
|
133
134
|
prices: [
|
|
134
135
|
{
|
|
135
136
|
value: {
|
|
136
|
-
// @ts-ignore
|
|
137
137
|
type: 'centPrecision',
|
|
138
138
|
currencyCode: 'EUR',
|
|
139
139
|
centAmount: 14900,
|
|
140
140
|
fractionDigits: 2,
|
|
141
141
|
},
|
|
142
|
-
id: '87943be5-c7e6-44eb-b867-f127f94ccfe7',
|
|
143
142
|
country: 'NL',
|
|
144
143
|
// channel: {
|
|
145
144
|
// typeId: 'channel',
|
|
@@ -156,17 +155,14 @@ describe('Order repository', () => {
|
|
|
156
155
|
],
|
|
157
156
|
images: [],
|
|
158
157
|
attributes: [],
|
|
159
|
-
assets: [],
|
|
160
158
|
},
|
|
161
159
|
price: {
|
|
162
160
|
value: {
|
|
163
|
-
// @ts-ignore
|
|
164
161
|
type: 'centPrecision',
|
|
165
162
|
currencyCode: 'EUR',
|
|
166
163
|
centAmount: 14900,
|
|
167
164
|
fractionDigits: 2,
|
|
168
165
|
},
|
|
169
|
-
id: '87943be5-c7e6-44eb-b867-f127f94ccfe7',
|
|
170
166
|
country: 'NL',
|
|
171
167
|
// channel: {
|
|
172
168
|
// typeId: 'channel',
|
|
@@ -181,7 +177,6 @@ describe('Order repository', () => {
|
|
|
181
177
|
// },
|
|
182
178
|
},
|
|
183
179
|
quantity: 3,
|
|
184
|
-
discountedPricePerQuantity: [],
|
|
185
180
|
// distributionChannel: {
|
|
186
181
|
// typeId: 'channel',
|
|
187
182
|
// id: '411485eb-7875-46f4-8d40-1db9e61374ed',
|
|
@@ -194,8 +189,6 @@ describe('Order repository', () => {
|
|
|
194
189
|
id: 'Z0wLUuYw',
|
|
195
190
|
subRates: [],
|
|
196
191
|
},
|
|
197
|
-
addedAt: '2020-12-08T09:10:27.085Z',
|
|
198
|
-
lastModifiedAt: '2020-12-08T09:10:27.085Z',
|
|
199
192
|
// state: [
|
|
200
193
|
// {
|
|
201
194
|
// quantity: 3,
|
|
@@ -205,28 +198,6 @@ describe('Order repository', () => {
|
|
|
205
198
|
// },
|
|
206
199
|
// },
|
|
207
200
|
// ],
|
|
208
|
-
priceMode: 'Platform',
|
|
209
|
-
totalPrice: {
|
|
210
|
-
type: 'centPrecision',
|
|
211
|
-
currencyCode: 'EUR',
|
|
212
|
-
centAmount: 44700,
|
|
213
|
-
fractionDigits: 2,
|
|
214
|
-
},
|
|
215
|
-
taxedPrice: {
|
|
216
|
-
totalNet: {
|
|
217
|
-
type: 'centPrecision',
|
|
218
|
-
currencyCode: 'EUR',
|
|
219
|
-
centAmount: 36942,
|
|
220
|
-
fractionDigits: 2,
|
|
221
|
-
},
|
|
222
|
-
totalGross: {
|
|
223
|
-
type: 'centPrecision',
|
|
224
|
-
currencyCode: 'EUR',
|
|
225
|
-
centAmount: 44700,
|
|
226
|
-
fractionDigits: 2,
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
lineItemMode: 'Standard',
|
|
230
201
|
},
|
|
231
202
|
],
|
|
232
203
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Cart,
|
|
3
3
|
CartReference,
|
|
4
4
|
CustomLineItem,
|
|
@@ -30,13 +30,15 @@ import {
|
|
|
30
30
|
import assert from 'assert'
|
|
31
31
|
import { CommercetoolsError } from '../exceptions'
|
|
32
32
|
import { getBaseResourceProperties } from '../helpers'
|
|
33
|
-
import { Writable } from '../types'
|
|
33
|
+
import type { Writable } from '../types'
|
|
34
34
|
import {
|
|
35
35
|
AbstractResourceRepository,
|
|
36
|
-
QueryParams,
|
|
36
|
+
type QueryParams,
|
|
37
37
|
RepositoryContext,
|
|
38
38
|
} from './abstract'
|
|
39
39
|
import {
|
|
40
|
+
createAddress,
|
|
41
|
+
createCentPrecisionMoney,
|
|
40
42
|
createCustomFields,
|
|
41
43
|
createPrice,
|
|
42
44
|
createTypedMoney,
|
|
@@ -104,8 +106,16 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
|
104
106
|
const resource: Order = {
|
|
105
107
|
...getBaseResourceProperties(),
|
|
106
108
|
|
|
107
|
-
billingAddress:
|
|
108
|
-
|
|
109
|
+
billingAddress: createAddress(
|
|
110
|
+
draft.billingAddress,
|
|
111
|
+
context.projectKey,
|
|
112
|
+
this._storage
|
|
113
|
+
),
|
|
114
|
+
shippingAddress: createAddress(
|
|
115
|
+
draft.shippingAddress,
|
|
116
|
+
context.projectKey,
|
|
117
|
+
this._storage
|
|
118
|
+
),
|
|
109
119
|
|
|
110
120
|
custom: createCustomFields(
|
|
111
121
|
draft.custom,
|
|
@@ -138,11 +148,7 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
|
138
148
|
this.customLineItemFromImportDraft.bind(this)(context, item)
|
|
139
149
|
) || [],
|
|
140
150
|
|
|
141
|
-
totalPrice:
|
|
142
|
-
type: 'centPrecision',
|
|
143
|
-
...draft.totalPrice,
|
|
144
|
-
fractionDigits: 2,
|
|
145
|
-
},
|
|
151
|
+
totalPrice: createCentPrecisionMoney(draft.totalPrice),
|
|
146
152
|
}
|
|
147
153
|
this.saveNew(context, resource)
|
|
148
154
|
return resource
|
|
@@ -208,7 +214,7 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
|
208
214
|
taxRate: draft.taxRate,
|
|
209
215
|
taxedPricePortions: [],
|
|
210
216
|
perMethodTaxRate: [],
|
|
211
|
-
totalPrice:
|
|
217
|
+
totalPrice: createCentPrecisionMoney(draft.price.value),
|
|
212
218
|
variant: {
|
|
213
219
|
id: variant.id,
|
|
214
220
|
sku: variant.sku,
|
|
@@ -233,11 +239,12 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
|
233
239
|
discountedPricePerQuantity: [],
|
|
234
240
|
money: createTypedMoney(draft.money),
|
|
235
241
|
name: draft.name,
|
|
236
|
-
quantity: draft.quantity,
|
|
242
|
+
quantity: draft.quantity ?? 0,
|
|
243
|
+
perMethodTaxRate: [],
|
|
237
244
|
priceMode: draft.priceMode,
|
|
238
245
|
slug: draft.slug,
|
|
239
246
|
state: [],
|
|
240
|
-
totalPrice:
|
|
247
|
+
totalPrice: createCentPrecisionMoney(draft.money),
|
|
241
248
|
}
|
|
242
249
|
|
|
243
250
|
return lineItem
|
|
@@ -326,7 +333,11 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
|
326
333
|
resource: Writable<Order>,
|
|
327
334
|
{ address }: OrderSetBillingAddressAction
|
|
328
335
|
) => {
|
|
329
|
-
resource.billingAddress =
|
|
336
|
+
resource.billingAddress = createAddress(
|
|
337
|
+
address,
|
|
338
|
+
context.projectKey,
|
|
339
|
+
this._storage
|
|
340
|
+
)
|
|
330
341
|
},
|
|
331
342
|
setCustomerEmail: (
|
|
332
343
|
context: RepositoryContext,
|
|
@@ -366,7 +377,7 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
|
366
377
|
typeId: 'type',
|
|
367
378
|
id: resolvedType.id,
|
|
368
379
|
},
|
|
369
|
-
fields: fields ||
|
|
380
|
+
fields: fields || {},
|
|
370
381
|
}
|
|
371
382
|
}
|
|
372
383
|
},
|
|
@@ -389,7 +400,11 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
|
|
|
389
400
|
resource: Writable<Order>,
|
|
390
401
|
{ address }: OrderSetShippingAddressAction
|
|
391
402
|
) => {
|
|
392
|
-
resource.shippingAddress =
|
|
403
|
+
resource.shippingAddress = createAddress(
|
|
404
|
+
address,
|
|
405
|
+
context.projectKey,
|
|
406
|
+
this._storage
|
|
407
|
+
)
|
|
393
408
|
},
|
|
394
409
|
setStore: (
|
|
395
410
|
context: RepositoryContext,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Payment,
|
|
3
3
|
PaymentAddTransactionAction,
|
|
4
4
|
PaymentChangeTransactionStateAction,
|
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
} from '@commercetools/platform-sdk'
|
|
14
14
|
import { v4 as uuidv4 } from 'uuid'
|
|
15
15
|
import { getBaseResourceProperties } from '../helpers'
|
|
16
|
-
import { Writable } from '../types'
|
|
16
|
+
import type { Writable } from '../types'
|
|
17
17
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
18
18
|
import {
|
|
19
|
+
createCentPrecisionMoney,
|
|
19
20
|
createCustomFields,
|
|
20
|
-
createTypedMoney,
|
|
21
21
|
getReferenceFromResourceIdentifier,
|
|
22
22
|
} from './helpers'
|
|
23
23
|
|
|
@@ -29,7 +29,7 @@ export class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
29
29
|
create(context: RepositoryContext, draft: PaymentDraft): Payment {
|
|
30
30
|
const resource: Payment = {
|
|
31
31
|
...getBaseResourceProperties(),
|
|
32
|
-
amountPlanned:
|
|
32
|
+
amountPlanned: createCentPrecisionMoney(draft.amountPlanned),
|
|
33
33
|
paymentMethodInfo: draft.paymentMethodInfo!,
|
|
34
34
|
paymentStatus: draft.paymentStatus
|
|
35
35
|
? {
|
|
@@ -64,11 +64,12 @@ export class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
64
64
|
transactionFromTransactionDraft = (
|
|
65
65
|
draft: TransactionDraft,
|
|
66
66
|
context: RepositoryContext
|
|
67
|
-
) => ({
|
|
67
|
+
): Transaction => ({
|
|
68
68
|
...draft,
|
|
69
69
|
id: uuidv4(),
|
|
70
|
-
amount:
|
|
70
|
+
amount: createCentPrecisionMoney(draft.amount),
|
|
71
71
|
custom: createCustomFields(draft.custom, context.projectKey, this._storage),
|
|
72
|
+
state: draft.state ?? 'Initial', // Documented as default
|
|
72
73
|
})
|
|
73
74
|
|
|
74
75
|
actions = {
|
|
@@ -104,7 +105,7 @@ export class PaymentRepository extends AbstractResourceRepository<'payment'> {
|
|
|
104
105
|
typeId: 'type',
|
|
105
106
|
id: resolvedType.id,
|
|
106
107
|
},
|
|
107
|
-
fields: fields
|
|
108
|
+
fields: fields ?? {},
|
|
108
109
|
}
|
|
109
110
|
}
|
|
110
111
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
ProductDiscount,
|
|
3
3
|
ProductDiscountChangeIsActiveAction,
|
|
4
4
|
ProductDiscountChangeNameAction,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
ProductDiscountValueRelative,
|
|
20
20
|
} from '@commercetools/platform-sdk'
|
|
21
21
|
import { getBaseResourceProperties } from '../helpers'
|
|
22
|
-
import { Writable } from '../types'
|
|
22
|
+
import type { Writable } from '../types'
|
|
23
23
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
24
24
|
import { createTypedMoney } from './helpers'
|
|
25
25
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import type { ProductDraft, ProductProjection } from '@commercetools/platform-sdk'
|
|
1
2
|
import { ParsedQs } from 'qs'
|
|
2
|
-
import {
|
|
3
|
+
import { QueryParamsAsArray } from '../helpers'
|
|
4
|
+
import { ProductProjectionSearch } from '../product-projection-search'
|
|
5
|
+
import { type AbstractStorage } from '../storage'
|
|
3
6
|
import {
|
|
4
7
|
AbstractResourceRepository,
|
|
5
|
-
QueryParams,
|
|
8
|
+
type QueryParams,
|
|
6
9
|
RepositoryContext,
|
|
7
10
|
} from './abstract'
|
|
8
|
-
import { AbstractStorage } from '../storage'
|
|
9
|
-
import { ProductProjectionSearch } from '../product-projection-search'
|
|
10
|
-
import { QueryParamsAsArray } from '../helpers'
|
|
11
11
|
|
|
12
12
|
export class ProductProjectionRepository extends AbstractResourceRepository<'product-projection'> {
|
|
13
13
|
protected _searchService: ProductProjectionSearch
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
ProductSelection,
|
|
3
3
|
ProductSelectionDraft,
|
|
4
4
|
Review,
|
|
5
5
|
ReviewUpdateAction,
|
|
6
6
|
} from '@commercetools/platform-sdk'
|
|
7
7
|
import { getBaseResourceProperties } from '../helpers'
|
|
8
|
-
import { Writable } from '../types'
|
|
8
|
+
import type { Writable } from '../types'
|
|
9
9
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
10
10
|
|
|
11
11
|
export class ProductSelectionRepository extends AbstractResourceRepository<'product-selection'> {
|
|
@@ -22,6 +22,7 @@ export class ProductSelectionRepository extends AbstractResourceRepository<'prod
|
|
|
22
22
|
productCount: 0,
|
|
23
23
|
name: draft.name,
|
|
24
24
|
type: 'individual',
|
|
25
|
+
mode: 'Individual',
|
|
25
26
|
}
|
|
26
27
|
this.saveNew(context, resource)
|
|
27
28
|
return resource
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
AttributeDefinition,
|
|
3
3
|
AttributeDefinitionDraft,
|
|
4
4
|
AttributeType,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
ProductTypeUpdateAction,
|
|
14
14
|
} from '@commercetools/platform-sdk'
|
|
15
15
|
import { getBaseResourceProperties } from '../helpers'
|
|
16
|
-
import { Writable } from '../types'
|
|
16
|
+
import type { Writable } from '../types'
|
|
17
17
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
18
18
|
|
|
19
19
|
export class ProductTypeRepository extends AbstractResourceRepository<'product-type'> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Price,
|
|
3
3
|
PriceDraft,
|
|
4
4
|
Product,
|
|
@@ -20,10 +20,10 @@ import {
|
|
|
20
20
|
ProductRemovePriceAction,
|
|
21
21
|
} from '@commercetools/platform-sdk'
|
|
22
22
|
import { v4 as uuidv4 } from 'uuid'
|
|
23
|
-
import { Writable } from '../types'
|
|
23
|
+
import type { Writable } from '../types'
|
|
24
24
|
import { getBaseResourceProperties } from '../helpers'
|
|
25
25
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
26
|
-
import { getReferenceFromResourceIdentifier } from './helpers'
|
|
26
|
+
import { createTypedMoney, getReferenceFromResourceIdentifier } from './helpers'
|
|
27
27
|
import deepEqual from 'deep-equal'
|
|
28
28
|
|
|
29
29
|
export class ProductRepository extends AbstractResourceRepository<'product'> {
|
|
@@ -622,10 +622,5 @@ const variantFromDraft = (
|
|
|
622
622
|
const priceFromDraft = (draft: PriceDraft): Price => ({
|
|
623
623
|
id: uuidv4(),
|
|
624
624
|
country: draft.country,
|
|
625
|
-
value:
|
|
626
|
-
currencyCode: draft.value.currencyCode,
|
|
627
|
-
centAmount: draft.value.centAmount,
|
|
628
|
-
fractionDigits: 2,
|
|
629
|
-
type: 'centPrecision',
|
|
630
|
-
},
|
|
625
|
+
value: createTypedMoney(draft.value),
|
|
631
626
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Project,
|
|
3
3
|
ProjectChangeCartsConfigurationAction,
|
|
4
4
|
ProjectChangeCountriesAction,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
ProjectUpdateAction,
|
|
15
15
|
} from '@commercetools/platform-sdk'
|
|
16
16
|
import { maskSecretValue } from '../lib/masking'
|
|
17
|
-
import { Writable } from '../types'
|
|
17
|
+
import type { Writable } from '../types'
|
|
18
18
|
import { AbstractRepository, RepositoryContext } from './abstract'
|
|
19
19
|
|
|
20
20
|
export class ProjectRepository extends AbstractRepository<Project> {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
QuoteRequest,
|
|
3
3
|
QuoteRequestDraft,
|
|
4
4
|
QuoteRequestUpdateAction,
|
|
5
5
|
} from '@commercetools/platform-sdk'
|
|
6
|
-
import { Writable } from '../types'
|
|
6
|
+
import type { Writable } from '../types'
|
|
7
7
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
8
8
|
|
|
9
9
|
export class QuoteRequestRepository extends AbstractResourceRepository<'quote-request'> {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Quote,
|
|
3
3
|
QuoteDraft,
|
|
4
4
|
QuoteUpdateAction,
|
|
5
5
|
} from '@commercetools/platform-sdk'
|
|
6
|
-
import { Writable } from '../types'
|
|
6
|
+
import type { Writable } from '../types'
|
|
7
7
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
8
8
|
|
|
9
9
|
export class QuoteRepository extends AbstractResourceRepository<'quote'> {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
Review,
|
|
3
3
|
ReviewDraft,
|
|
4
4
|
ReviewUpdateAction,
|
|
5
5
|
} from '@commercetools/platform-sdk'
|
|
6
6
|
import { getBaseResourceProperties } from '../helpers'
|
|
7
|
-
import { Writable } from '../types'
|
|
7
|
+
import type { Writable } from '../types'
|
|
8
8
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
9
9
|
|
|
10
10
|
export class ReviewRepository extends AbstractResourceRepository<'review'> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
ShippingMethod,
|
|
3
3
|
ShippingMethodAddShippingRateAction,
|
|
4
4
|
ShippingMethodAddZoneAction,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from '@commercetools/platform-sdk'
|
|
23
23
|
import deepEqual from 'deep-equal'
|
|
24
24
|
import { getBaseResourceProperties } from '../helpers'
|
|
25
|
-
import { Writable } from '../types'
|
|
25
|
+
import type { Writable } from '../types'
|
|
26
26
|
import { AbstractResourceRepository, RepositoryContext } from './abstract'
|
|
27
27
|
import {
|
|
28
28
|
createCustomFields,
|