@labdigital/commercetools-mock 0.5.18 → 0.5.21
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/commercetools-mock.cjs.development.js +191 -38
- 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 +190 -37
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/repositories/customer.d.ts +5 -1
- package/dist/repositories/payment.d.ts +3 -1
- package/dist/repositories/store.d.ts +1 -0
- package/dist/services/customer.d.ts +1 -0
- package/dist/services/my-customer.d.ts +1 -0
- package/dist/services/store.d.ts +3 -1
- package/package.json +1 -1
- package/src/.env +0 -0
- package/src/ctMock.ts +1 -1
- package/src/lib/masking.ts +1 -3
- package/src/repositories/category.ts +7 -6
- package/src/repositories/customer.ts +14 -0
- package/src/repositories/payment.ts +38 -2
- package/src/repositories/product-type.ts +3 -3
- package/src/repositories/project.ts +0 -1
- package/src/repositories/shipping-method.ts +11 -12
- package/src/repositories/store.ts +15 -0
- package/src/repositories/subscription.ts +2 -2
- package/src/repositories/tax-category.ts +1 -1
- package/src/repositories/type.ts +10 -10
- package/src/repositories/zone.ts +3 -1
- package/src/services/customer.ts +21 -0
- package/src/services/my-customer.ts +25 -0
- package/src/services/product.test.ts +1 -5
- package/src/services/project.ts +1 -1
- package/src/services/shipping-method.ts +1 -1
- package/src/services/store.ts +16 -1
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { Customer, CustomerDraft, ReferenceTypeId } from '@commercetools/platform-sdk';
|
|
1
|
+
import { Customer, CustomerChangeEmailAction, CustomerDraft, ReferenceTypeId } from '@commercetools/platform-sdk';
|
|
2
|
+
import { Writable } from 'types';
|
|
2
3
|
import { AbstractResourceRepository } from './abstract';
|
|
3
4
|
export declare class CustomerRepository extends AbstractResourceRepository {
|
|
4
5
|
getTypeId(): ReferenceTypeId;
|
|
5
6
|
create(projectKey: string, draft: CustomerDraft): Customer;
|
|
6
7
|
getMe(projectKey: string): Customer | undefined;
|
|
8
|
+
actions: {
|
|
9
|
+
changeEmail: (_projectKey: string, resource: Writable<Customer>, { email }: CustomerChangeEmailAction) => void;
|
|
10
|
+
};
|
|
7
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Payment, PaymentAddTransactionAction, PaymentDraft, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, ReferenceTypeId, TransactionDraft } from '@commercetools/platform-sdk';
|
|
1
|
+
import { Payment, PaymentAddTransactionAction, PaymentChangeTransactionStateAction, PaymentDraft, PaymentSetCustomFieldAction, PaymentSetCustomTypeAction, PaymentTransitionStateAction, ReferenceTypeId, TransactionDraft } from '@commercetools/platform-sdk';
|
|
2
2
|
import { AbstractResourceRepository } from './abstract';
|
|
3
3
|
import { Writable } from '../types';
|
|
4
4
|
export declare class PaymentRepository extends AbstractResourceRepository {
|
|
@@ -17,5 +17,7 @@ export declare class PaymentRepository extends AbstractResourceRepository {
|
|
|
17
17
|
setCustomField: (projectKey: string, resource: Payment, { name, value }: PaymentSetCustomFieldAction) => void;
|
|
18
18
|
setCustomType: (projectKey: string, resource: Writable<Payment>, { type, fields }: PaymentSetCustomTypeAction) => void;
|
|
19
19
|
addTransaction: (projectKey: string, resource: Writable<Payment>, { transaction }: PaymentAddTransactionAction) => void;
|
|
20
|
+
changeTransactionState: (_projectKey: string, resource: Writable<Payment>, { transactionId, state }: PaymentChangeTransactionStateAction) => void;
|
|
21
|
+
transitionState: (projectKey: string, resource: Writable<Payment>, { state }: PaymentTransitionStateAction) => void;
|
|
20
22
|
};
|
|
21
23
|
}
|
|
@@ -5,5 +5,6 @@ export declare class StoreRepository extends AbstractResourceRepository {
|
|
|
5
5
|
getTypeId(): ReferenceTypeId;
|
|
6
6
|
create(projectKey: string, draft: StoreDraft): Store;
|
|
7
7
|
private transformChannels;
|
|
8
|
+
getWithKey(projectKey: string, key: string): Store | undefined;
|
|
8
9
|
actions: Partial<Record<StoreUpdateAction['action'], (projectKey: string, resource: Writable<Store>, action: any) => void>>;
|
|
9
10
|
}
|
|
@@ -9,4 +9,5 @@ export declare class MyCustomerService extends AbstractService {
|
|
|
9
9
|
registerRoutes(parent: Router): void;
|
|
10
10
|
getMe(request: Request, response: Response): Response<any, Record<string, any>>;
|
|
11
11
|
signUp(request: Request, response: Response): Response<any, Record<string, any>>;
|
|
12
|
+
signIn(request: Request, response: Response): Response<any, Record<string, any>>;
|
|
12
13
|
}
|
package/dist/services/store.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import AbstractService from './abstract';
|
|
2
|
-
import { Router } from 'express';
|
|
2
|
+
import { Router, Request, Response } from 'express';
|
|
3
3
|
import { StoreRepository } from '../repositories/store';
|
|
4
4
|
import { AbstractStorage } from '../storage';
|
|
5
5
|
export declare class StoreService extends AbstractService {
|
|
6
6
|
repository: StoreRepository;
|
|
7
7
|
constructor(parent: Router, storage: AbstractStorage);
|
|
8
8
|
getBasePath(): string;
|
|
9
|
+
extraRoutes(router: Router): void;
|
|
10
|
+
getWithKey(request: Request, response: Response): Response<any, Record<string, any>>;
|
|
9
11
|
}
|
package/package.json
CHANGED
package/src/.env
ADDED
|
File without changes
|
package/src/ctMock.ts
CHANGED
|
@@ -37,7 +37,7 @@ import { SubscriptionService } from './services/subscription'
|
|
|
37
37
|
import { TaxCategoryService } from './services/tax-category'
|
|
38
38
|
import { TypeService } from './services/type'
|
|
39
39
|
import { ZoneService } from './services/zone'
|
|
40
|
-
import { MyCustomerService } from 'services/my-customer'
|
|
40
|
+
import { MyCustomerService } from './services/my-customer'
|
|
41
41
|
|
|
42
42
|
export type CommercetoolsMockOptions = {
|
|
43
43
|
validateCredentials: boolean
|
package/src/lib/masking.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { json } from 'express'
|
|
2
|
-
|
|
3
1
|
export const maskSecretValue = <T>(resource: T, path: string): T => {
|
|
4
2
|
const parts = path.split('.')
|
|
5
3
|
const clone = JSON.parse(JSON.stringify(resource))
|
|
@@ -10,7 +8,7 @@ export const maskSecretValue = <T>(resource: T, path: string): T => {
|
|
|
10
8
|
const part = parts[i]
|
|
11
9
|
val = val[part]
|
|
12
10
|
|
|
13
|
-
if (val
|
|
11
|
+
if (val === undefined) {
|
|
14
12
|
return resource
|
|
15
13
|
}
|
|
16
14
|
}
|
|
@@ -30,6 +30,7 @@ export class CategoryRepository extends AbstractResourceRepository {
|
|
|
30
30
|
name: draft.name,
|
|
31
31
|
slug: draft.slug,
|
|
32
32
|
orderHint: draft.orderHint || '',
|
|
33
|
+
externalId: draft.externalId || '',
|
|
33
34
|
parent: draft.parent
|
|
34
35
|
? { typeId: 'category', id: draft.parent.id! }
|
|
35
36
|
: undefined,
|
|
@@ -58,10 +59,10 @@ export class CategoryRepository extends AbstractResourceRepository {
|
|
|
58
59
|
{ assetId, assetKey, name }: CategoryChangeAssetNameAction
|
|
59
60
|
) => {
|
|
60
61
|
resource.assets?.forEach(asset => {
|
|
61
|
-
if (assetId && assetId
|
|
62
|
+
if (assetId && assetId === asset.id) {
|
|
62
63
|
asset.name = name
|
|
63
64
|
}
|
|
64
|
-
if (assetKey && assetKey
|
|
65
|
+
if (assetKey && assetKey === asset.key) {
|
|
65
66
|
asset.name = name
|
|
66
67
|
}
|
|
67
68
|
})
|
|
@@ -86,10 +87,10 @@ export class CategoryRepository extends AbstractResourceRepository {
|
|
|
86
87
|
{ assetId, assetKey, description }: CategorySetAssetDescriptionAction
|
|
87
88
|
) => {
|
|
88
89
|
resource.assets?.forEach(asset => {
|
|
89
|
-
if (assetId && assetId
|
|
90
|
+
if (assetId && assetId === asset.id) {
|
|
90
91
|
asset.description = description
|
|
91
92
|
}
|
|
92
|
-
if (assetKey && assetKey
|
|
93
|
+
if (assetKey && assetKey === asset.key) {
|
|
93
94
|
asset.description = description
|
|
94
95
|
}
|
|
95
96
|
})
|
|
@@ -100,10 +101,10 @@ export class CategoryRepository extends AbstractResourceRepository {
|
|
|
100
101
|
{ assetId, assetKey, sources }: CategorySetAssetSourcesAction
|
|
101
102
|
) => {
|
|
102
103
|
resource.assets?.forEach(asset => {
|
|
103
|
-
if (assetId && assetId
|
|
104
|
+
if (assetId && assetId === asset.id) {
|
|
104
105
|
asset.sources = sources
|
|
105
106
|
}
|
|
106
|
-
if (assetKey && assetKey
|
|
107
|
+
if (assetKey && assetKey === asset.key) {
|
|
107
108
|
asset.sources = sources
|
|
108
109
|
}
|
|
109
110
|
})
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Customer,
|
|
3
|
+
CustomerChangeEmailAction,
|
|
3
4
|
CustomerDraft,
|
|
4
5
|
ReferenceTypeId,
|
|
5
6
|
} from '@commercetools/platform-sdk'
|
|
7
|
+
import { Writable } from 'types'
|
|
6
8
|
import { getBaseResourceProperties } from '../helpers'
|
|
7
9
|
import { AbstractResourceRepository } from './abstract'
|
|
8
10
|
|
|
@@ -10,6 +12,7 @@ export class CustomerRepository extends AbstractResourceRepository {
|
|
|
10
12
|
getTypeId(): ReferenceTypeId {
|
|
11
13
|
return 'customer'
|
|
12
14
|
}
|
|
15
|
+
|
|
13
16
|
create(projectKey: string, draft: CustomerDraft): Customer {
|
|
14
17
|
const resource: Customer = {
|
|
15
18
|
...getBaseResourceProperties(),
|
|
@@ -21,6 +24,7 @@ export class CustomerRepository extends AbstractResourceRepository {
|
|
|
21
24
|
this.save(projectKey, resource)
|
|
22
25
|
return resource
|
|
23
26
|
}
|
|
27
|
+
|
|
24
28
|
getMe(projectKey: string): Customer | undefined {
|
|
25
29
|
const results = this._storage.query(projectKey, this.getTypeId(), {}) // grab the first customer you can find
|
|
26
30
|
if (results.count > 0) {
|
|
@@ -29,4 +33,14 @@ export class CustomerRepository extends AbstractResourceRepository {
|
|
|
29
33
|
|
|
30
34
|
return
|
|
31
35
|
}
|
|
36
|
+
|
|
37
|
+
actions = {
|
|
38
|
+
changeEmail: (
|
|
39
|
+
_projectKey: string,
|
|
40
|
+
resource: Writable<Customer>,
|
|
41
|
+
{ email }: CustomerChangeEmailAction
|
|
42
|
+
) => {
|
|
43
|
+
resource.email = email
|
|
44
|
+
},
|
|
45
|
+
}
|
|
32
46
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Payment,
|
|
3
3
|
PaymentAddTransactionAction,
|
|
4
|
+
PaymentChangeTransactionStateAction,
|
|
4
5
|
PaymentDraft,
|
|
5
6
|
PaymentSetCustomFieldAction,
|
|
6
7
|
PaymentSetCustomTypeAction,
|
|
8
|
+
PaymentTransitionStateAction,
|
|
7
9
|
ReferenceTypeId,
|
|
10
|
+
State,
|
|
8
11
|
StateReference,
|
|
12
|
+
Transaction,
|
|
9
13
|
TransactionDraft,
|
|
10
14
|
} from '@commercetools/platform-sdk'
|
|
11
15
|
import { AbstractResourceRepository } from './abstract'
|
|
@@ -111,10 +115,43 @@ export class PaymentRepository extends AbstractResourceRepository {
|
|
|
111
115
|
this.transactionFromTransactionDraft(transaction, projectKey),
|
|
112
116
|
]
|
|
113
117
|
},
|
|
118
|
+
changeTransactionState: (
|
|
119
|
+
_projectKey: string,
|
|
120
|
+
resource: Writable<Payment>,
|
|
121
|
+
{ transactionId, state }: PaymentChangeTransactionStateAction
|
|
122
|
+
) => {
|
|
123
|
+
const index = resource.transactions.findIndex(
|
|
124
|
+
(e: Transaction) => e.id === transactionId
|
|
125
|
+
)
|
|
126
|
+
const updatedTransaction: Transaction = {
|
|
127
|
+
...resource.transactions[index],
|
|
128
|
+
state,
|
|
129
|
+
}
|
|
130
|
+
resource.transactions[index] = updatedTransaction
|
|
131
|
+
},
|
|
132
|
+
transitionState: (
|
|
133
|
+
projectKey: string,
|
|
134
|
+
resource: Writable<Payment>,
|
|
135
|
+
{ state }: PaymentTransitionStateAction
|
|
136
|
+
) => {
|
|
137
|
+
const stateObj = this._storage.getByResourceIdentifier(
|
|
138
|
+
projectKey,
|
|
139
|
+
state
|
|
140
|
+
) as State | null
|
|
141
|
+
|
|
142
|
+
if (!stateObj) {
|
|
143
|
+
throw new Error(`State ${state} not found`)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
resource.paymentStatus.state = {
|
|
147
|
+
typeId: 'state',
|
|
148
|
+
id: stateObj.id,
|
|
149
|
+
obj: stateObj,
|
|
150
|
+
}
|
|
151
|
+
},
|
|
114
152
|
// addInterfaceInteraction: () => {},
|
|
115
153
|
// changeAmountPlanned: () => {},
|
|
116
154
|
// changeTransactionInteractionId: () => {},
|
|
117
|
-
// changeTransactionState: () => {},
|
|
118
155
|
// changeTransactionTimestamp: () => {},
|
|
119
156
|
// setAmountPaid: () => {},
|
|
120
157
|
// setAmountRefunded: () => {},
|
|
@@ -129,6 +166,5 @@ export class PaymentRepository extends AbstractResourceRepository {
|
|
|
129
166
|
// setMethodInfoName: () => {},
|
|
130
167
|
// setStatusInterfaceCode: () => {},
|
|
131
168
|
// setStatusInterfaceText: () => {},
|
|
132
|
-
// transitionState: () => {},
|
|
133
169
|
}
|
|
134
170
|
}
|
|
@@ -77,7 +77,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
77
77
|
switch (type.name) {
|
|
78
78
|
case 'lenum':
|
|
79
79
|
type.values.forEach(v => {
|
|
80
|
-
if (v.key
|
|
80
|
+
if (v.key === newValue.key) {
|
|
81
81
|
v.label = newValue.label
|
|
82
82
|
}
|
|
83
83
|
})
|
|
@@ -89,7 +89,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
resource.attributes?.forEach(value => {
|
|
92
|
-
if (value.name
|
|
92
|
+
if (value.name === attributeName) {
|
|
93
93
|
updateAttributeType(value.type)
|
|
94
94
|
}
|
|
95
95
|
})
|
|
@@ -100,7 +100,7 @@ export class ProductTypeRepository extends AbstractResourceRepository {
|
|
|
100
100
|
{ attributeName, label }: ProductTypeChangeLabelAction
|
|
101
101
|
) => {
|
|
102
102
|
resource.attributes?.forEach(value => {
|
|
103
|
-
if (value.name
|
|
103
|
+
if (value.name === attributeName) {
|
|
104
104
|
value.label = label
|
|
105
105
|
}
|
|
106
106
|
})
|
|
@@ -22,7 +22,6 @@ import { maskSecretValue } from '../lib/masking'
|
|
|
22
22
|
|
|
23
23
|
export class ProjectRepository extends AbstractRepository {
|
|
24
24
|
get(projectKey: string): Project | null {
|
|
25
|
-
const data = this._storage.getProject(projectKey)
|
|
26
25
|
const resource = this._storage.getProject(projectKey)
|
|
27
26
|
const masked = maskSecretValue<Project>(
|
|
28
27
|
resource,
|
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
import { getBaseResourceProperties } from '../helpers'
|
|
27
27
|
import { AbstractResourceRepository } from './abstract'
|
|
28
28
|
import { Writable } from 'types'
|
|
29
|
-
import { _ } from 'ajv'
|
|
30
29
|
import deepEqual from 'deep-equal'
|
|
31
30
|
|
|
32
31
|
export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
@@ -84,14 +83,14 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
84
83
|
>
|
|
85
84
|
> = {
|
|
86
85
|
addShippingRate: (
|
|
87
|
-
|
|
86
|
+
_projectKey: string,
|
|
88
87
|
resource: Writable<ShippingMethod>,
|
|
89
88
|
{ shippingRate, zone }: ShippingMethodAddShippingRateAction
|
|
90
89
|
) => {
|
|
91
90
|
const rate = this._transformShippingRate(shippingRate)
|
|
92
91
|
|
|
93
92
|
resource.zoneRates.forEach(zoneRate => {
|
|
94
|
-
if (zoneRate.zone.id
|
|
93
|
+
if (zoneRate.zone.id === zone.id) {
|
|
95
94
|
zoneRate.shippingRates.push(rate)
|
|
96
95
|
return
|
|
97
96
|
}
|
|
@@ -105,14 +104,14 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
105
104
|
})
|
|
106
105
|
},
|
|
107
106
|
removeShippingRate: (
|
|
108
|
-
|
|
107
|
+
_projectKey: string,
|
|
109
108
|
resource: Writable<ShippingMethod>,
|
|
110
109
|
{ shippingRate, zone }: ShippingMethodAddShippingRateAction
|
|
111
110
|
) => {
|
|
112
111
|
const rate = this._transformShippingRate(shippingRate)
|
|
113
112
|
|
|
114
113
|
resource.zoneRates.forEach(zoneRate => {
|
|
115
|
-
if (zoneRate.zone.id
|
|
114
|
+
if (zoneRate.zone.id === zone.id) {
|
|
116
115
|
zoneRate.shippingRates = zoneRate.shippingRates.filter(otherRate => {
|
|
117
116
|
return !deepEqual(rate, otherRate)
|
|
118
117
|
})
|
|
@@ -140,7 +139,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
140
139
|
})
|
|
141
140
|
},
|
|
142
141
|
removeZone: (
|
|
143
|
-
|
|
142
|
+
_projectKey: string,
|
|
144
143
|
resource: Writable<ShippingMethod>,
|
|
145
144
|
{ zone }: ShippingMethodRemoveZoneAction
|
|
146
145
|
) => {
|
|
@@ -149,42 +148,42 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
|
|
|
149
148
|
})
|
|
150
149
|
},
|
|
151
150
|
setKey: (
|
|
152
|
-
|
|
151
|
+
_projectKey: string,
|
|
153
152
|
resource: Writable<ShippingMethod>,
|
|
154
153
|
{ key }: ShippingMethodSetKeyAction
|
|
155
154
|
) => {
|
|
156
155
|
resource.key = key
|
|
157
156
|
},
|
|
158
157
|
setDescription: (
|
|
159
|
-
|
|
158
|
+
_projectKey: string,
|
|
160
159
|
resource: Writable<ShippingMethod>,
|
|
161
160
|
{ description }: ShippingMethodSetDescriptionAction
|
|
162
161
|
) => {
|
|
163
162
|
resource.description = description
|
|
164
163
|
},
|
|
165
164
|
setLocalizedDescription: (
|
|
166
|
-
|
|
165
|
+
_projectKey: string,
|
|
167
166
|
resource: Writable<ShippingMethod>,
|
|
168
167
|
{ localizedDescription }: ShippingMethodSetLocalizedDescriptionAction
|
|
169
168
|
) => {
|
|
170
169
|
resource.localizedDescription = localizedDescription
|
|
171
170
|
},
|
|
172
171
|
setPredicate: (
|
|
173
|
-
|
|
172
|
+
_projectKey: string,
|
|
174
173
|
resource: Writable<ShippingMethod>,
|
|
175
174
|
{ predicate }: ShippingMethodSetPredicateAction
|
|
176
175
|
) => {
|
|
177
176
|
resource.predicate = predicate
|
|
178
177
|
},
|
|
179
178
|
changeIsDefault: (
|
|
180
|
-
|
|
179
|
+
_projectKey: string,
|
|
181
180
|
resource: Writable<ShippingMethod>,
|
|
182
181
|
{ isDefault }: ShippingMethodChangeIsDefaultAction
|
|
183
182
|
) => {
|
|
184
183
|
resource.isDefault = isDefault
|
|
185
184
|
},
|
|
186
185
|
changeName: (
|
|
187
|
-
|
|
186
|
+
_projectKey: string,
|
|
188
187
|
resource: Writable<ShippingMethod>,
|
|
189
188
|
{ name }: ShippingMethodChangeNameAction
|
|
190
189
|
) => {
|
|
@@ -50,6 +50,21 @@ export class StoreRepository extends AbstractResourceRepository {
|
|
|
50
50
|
)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
getWithKey(projectKey: string, key: string): Store | undefined {
|
|
54
|
+
const result = this._storage.query(projectKey, this.getTypeId(), {
|
|
55
|
+
where: [`key="${key}"`],
|
|
56
|
+
})
|
|
57
|
+
if (result.count === 1) {
|
|
58
|
+
return result.results[0] as Store
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (result.count > 1) {
|
|
62
|
+
throw new Error('Duplicate store key')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
53
68
|
actions: Partial<
|
|
54
69
|
Record<
|
|
55
70
|
StoreUpdateAction['action'],
|
|
@@ -15,10 +15,10 @@ export class SubscriptionRepository extends AbstractResourceRepository {
|
|
|
15
15
|
create(projectKey: string, draft: SubscriptionDraft): Subscription {
|
|
16
16
|
// TODO: We could actually test this here by using the aws sdk. For now
|
|
17
17
|
// hardcode a failed check when account id is 0000000000
|
|
18
|
-
if (draft.destination.type
|
|
18
|
+
if (draft.destination.type === 'SQS') {
|
|
19
19
|
const queueURL = new URL(draft.destination.queueUrl)
|
|
20
20
|
const accountId = queueURL.pathname.split('/')[1]
|
|
21
|
-
if (accountId
|
|
21
|
+
if (accountId === '0000000000') {
|
|
22
22
|
const dest = draft.destination
|
|
23
23
|
throw new CommercetoolsError<InvalidInputError>(
|
|
24
24
|
{
|
|
@@ -94,7 +94,7 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
|
|
|
94
94
|
const taxRateObj = this.taxRateFromTaxRateDraft(taxRate)
|
|
95
95
|
for (let i = 0; i < resource.rates.length; i++) {
|
|
96
96
|
const rate = resource.rates[i]
|
|
97
|
-
if (rate.id
|
|
97
|
+
if (rate.id === taxRateId) {
|
|
98
98
|
resource.rates[i] = taxRateObj
|
|
99
99
|
}
|
|
100
100
|
}
|
package/src/repositories/type.ts
CHANGED
|
@@ -104,13 +104,13 @@ export class TypeRepository extends AbstractResourceRepository {
|
|
|
104
104
|
{ fieldName, value }: TypeAddEnumValueAction
|
|
105
105
|
) => {
|
|
106
106
|
resource.fieldDefinitions.forEach(field => {
|
|
107
|
-
if (field.name
|
|
107
|
+
if (field.name === fieldName) {
|
|
108
108
|
// TODO, should be done better i suppose
|
|
109
|
-
if (field.type.name
|
|
109
|
+
if (field.type.name === 'Enum') {
|
|
110
110
|
field.type.values.push(value)
|
|
111
111
|
} else if (
|
|
112
|
-
field.type.name
|
|
113
|
-
field.type.elementType.name
|
|
112
|
+
field.type.name === 'Set' &&
|
|
113
|
+
field.type.elementType.name === 'Enum'
|
|
114
114
|
) {
|
|
115
115
|
field.type.elementType.values.push(value)
|
|
116
116
|
} else {
|
|
@@ -125,20 +125,20 @@ export class TypeRepository extends AbstractResourceRepository {
|
|
|
125
125
|
{ fieldName, value }: TypeChangeEnumValueLabelAction
|
|
126
126
|
) => {
|
|
127
127
|
resource.fieldDefinitions.forEach(field => {
|
|
128
|
-
if (field.name
|
|
128
|
+
if (field.name === fieldName) {
|
|
129
129
|
// TODO, should be done better i suppose
|
|
130
|
-
if (field.type.name
|
|
130
|
+
if (field.type.name === 'Enum') {
|
|
131
131
|
field.type.values.forEach(v => {
|
|
132
|
-
if (v.key
|
|
132
|
+
if (v.key === value.key) {
|
|
133
133
|
v.label = value.label
|
|
134
134
|
}
|
|
135
135
|
})
|
|
136
136
|
} else if (
|
|
137
|
-
field.type.name
|
|
138
|
-
field.type.elementType.name
|
|
137
|
+
field.type.name === 'Set' &&
|
|
138
|
+
field.type.elementType.name === 'Enum'
|
|
139
139
|
) {
|
|
140
140
|
field.type.elementType.values.forEach(v => {
|
|
141
|
-
if (v.key
|
|
141
|
+
if (v.key === value.key) {
|
|
142
142
|
v.label = value.label
|
|
143
143
|
}
|
|
144
144
|
})
|
package/src/repositories/zone.ts
CHANGED
|
@@ -49,7 +49,9 @@ export class ZoneRepository extends AbstractResourceRepository {
|
|
|
49
49
|
{ location }: ZoneRemoveLocationAction
|
|
50
50
|
) => {
|
|
51
51
|
resource.locations = resource.locations.filter(loc => {
|
|
52
|
-
return !(
|
|
52
|
+
return !(
|
|
53
|
+
loc.country === location.country && loc.state === location.state
|
|
54
|
+
)
|
|
53
55
|
})
|
|
54
56
|
},
|
|
55
57
|
changeName: (
|
package/src/services/customer.ts
CHANGED
|
@@ -2,6 +2,8 @@ import AbstractService from './abstract'
|
|
|
2
2
|
import { Router } from 'express'
|
|
3
3
|
import { CustomerRepository } from '../repositories/customer'
|
|
4
4
|
import { AbstractStorage } from '../storage'
|
|
5
|
+
import { getBaseResourceProperties } from '../helpers'
|
|
6
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
5
7
|
|
|
6
8
|
export class CustomerService extends AbstractService {
|
|
7
9
|
public repository: CustomerRepository
|
|
@@ -14,4 +16,23 @@ export class CustomerService extends AbstractService {
|
|
|
14
16
|
getBasePath() {
|
|
15
17
|
return 'customers'
|
|
16
18
|
}
|
|
19
|
+
|
|
20
|
+
extraRoutes(parent: Router) {
|
|
21
|
+
parent.post('/password-token', (request, response) => {
|
|
22
|
+
const customer = this.repository.query(request.params.projectKey, {
|
|
23
|
+
where: [`email="${request.body.email}"`],
|
|
24
|
+
})
|
|
25
|
+
const ttlMinutes: number = request.params.ttlMinutes
|
|
26
|
+
? +request.params.ttlMinutes
|
|
27
|
+
: 34560
|
|
28
|
+
const { version, ...rest } = getBaseResourceProperties()
|
|
29
|
+
|
|
30
|
+
return response.status(200).send({
|
|
31
|
+
...rest,
|
|
32
|
+
customerId: customer.results[0].id,
|
|
33
|
+
expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
|
|
34
|
+
value: uuidv4(),
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
}
|
|
17
38
|
}
|
|
@@ -26,6 +26,8 @@ export class MyCustomerService extends AbstractService {
|
|
|
26
26
|
|
|
27
27
|
router.post('/signup', this.signUp.bind(this))
|
|
28
28
|
|
|
29
|
+
router.post('/login', this.signIn.bind(this))
|
|
30
|
+
|
|
29
31
|
parent.use(`/${basePath}`, router)
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -43,4 +45,27 @@ export class MyCustomerService extends AbstractService {
|
|
|
43
45
|
const result = this._expandWithId(request, resource.id)
|
|
44
46
|
return response.status(this.createStatusCode).send({ customer: result })
|
|
45
47
|
}
|
|
48
|
+
|
|
49
|
+
signIn(request: Request, response: Response) {
|
|
50
|
+
const { email, password } = request.body
|
|
51
|
+
const encodedPassword = Buffer.from(password).toString('base64')
|
|
52
|
+
|
|
53
|
+
const result = this.repository.query(request.params.projectKey, {
|
|
54
|
+
where: [`email = "${email}"`, `password = "${encodedPassword}"`],
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
if (result.count === 0) {
|
|
58
|
+
return response.status(400).send({
|
|
59
|
+
message: 'Account with the given credentials not found.',
|
|
60
|
+
errors: [
|
|
61
|
+
{
|
|
62
|
+
code: 'InvalidCredentials',
|
|
63
|
+
message: 'Account with the given credentials not found.',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return response.status(200).send({ customer: result.results[0] })
|
|
70
|
+
}
|
|
46
71
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CentPrecisionMoney,
|
|
3
|
-
Product,
|
|
4
|
-
ProductDraft,
|
|
5
|
-
} from '@commercetools/platform-sdk'
|
|
1
|
+
import { Product, ProductDraft } from '@commercetools/platform-sdk'
|
|
6
2
|
import supertest from 'supertest'
|
|
7
3
|
import { CommercetoolsMock } from '../index'
|
|
8
4
|
import assert from 'assert'
|
package/src/services/project.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ShippingMethodRepository } from '../repositories/shipping-method'
|
|
2
2
|
import AbstractService from './abstract'
|
|
3
3
|
import { AbstractStorage } from '../storage'
|
|
4
|
-
import {
|
|
4
|
+
import { Router } from 'express'
|
|
5
5
|
|
|
6
6
|
export class ShippingMethodService extends AbstractService {
|
|
7
7
|
public repository: ShippingMethodRepository
|
package/src/services/store.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import AbstractService from './abstract'
|
|
2
|
-
import { Router } from 'express'
|
|
2
|
+
import { Router, Request, Response } from 'express'
|
|
3
3
|
import { StoreRepository } from '../repositories/store'
|
|
4
4
|
import { AbstractStorage } from '../storage'
|
|
5
5
|
|
|
@@ -14,4 +14,19 @@ export class StoreService extends AbstractService {
|
|
|
14
14
|
getBasePath() {
|
|
15
15
|
return 'stores'
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
extraRoutes(router: Router) {
|
|
19
|
+
router.get('/key=:key', this.getWithKey.bind(this))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getWithKey(request: Request, response: Response) {
|
|
23
|
+
const resource = this.repository.getWithKey(
|
|
24
|
+
request.params.projectKey,
|
|
25
|
+
request.params.key
|
|
26
|
+
)
|
|
27
|
+
if (resource) {
|
|
28
|
+
return response.status(200).send(resource)
|
|
29
|
+
}
|
|
30
|
+
return response.status(404).send('Not found')
|
|
31
|
+
}
|
|
17
32
|
}
|