@labdigital/commercetools-mock 0.5.17 → 0.5.20

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.
Files changed (39) hide show
  1. package/dist/commercetools-mock.cjs.development.js +182 -40
  2. package/dist/commercetools-mock.cjs.development.js.map +1 -1
  3. package/dist/commercetools-mock.cjs.production.min.js +1 -1
  4. package/dist/commercetools-mock.cjs.production.min.js.map +1 -1
  5. package/dist/commercetools-mock.esm.js +182 -40
  6. package/dist/commercetools-mock.esm.js.map +1 -1
  7. package/dist/repositories/customer.d.ts +6 -1
  8. package/dist/repositories/payment.d.ts +3 -1
  9. package/dist/repositories/store.d.ts +1 -0
  10. package/dist/services/customer.d.ts +1 -0
  11. package/dist/services/my-customer.d.ts +12 -0
  12. package/dist/services/shipping-method.d.ts +2 -1
  13. package/dist/services/store.d.ts +3 -1
  14. package/dist/types.d.ts +1 -1
  15. package/package.json +2 -16
  16. package/src/ctMock.ts +2 -0
  17. package/src/lib/masking.ts +1 -3
  18. package/src/repositories/category.ts +7 -6
  19. package/src/repositories/customer.ts +21 -1
  20. package/src/repositories/discount-code.ts +0 -1
  21. package/src/repositories/payment.ts +38 -2
  22. package/src/repositories/product-type.ts +3 -3
  23. package/src/repositories/project.ts +0 -2
  24. package/src/repositories/shipping-method.ts +11 -12
  25. package/src/repositories/store.ts +15 -0
  26. package/src/repositories/subscription.ts +2 -2
  27. package/src/repositories/tax-category.ts +1 -1
  28. package/src/repositories/type.ts +10 -10
  29. package/src/repositories/zone.ts +3 -1
  30. package/src/services/abstract.ts +0 -1
  31. package/src/services/customer.ts +21 -0
  32. package/src/services/my-customer.test.ts +51 -0
  33. package/src/services/my-customer.ts +46 -0
  34. package/src/services/product.test.ts +1 -5
  35. package/src/services/project.ts +1 -1
  36. package/src/services/shipping-method.test.ts +27 -0
  37. package/src/services/shipping-method.ts +6 -1
  38. package/src/services/store.ts +16 -1
  39. package/src/types.ts +5 -1
@@ -1,6 +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;
7
+ getMe(projectKey: string): Customer | undefined;
8
+ actions: {
9
+ changeEmail: (_projectKey: string, resource: Writable<Customer>, { email }: CustomerChangeEmailAction) => void;
10
+ };
6
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
  }
@@ -6,4 +6,5 @@ export declare class CustomerService extends AbstractService {
6
6
  repository: CustomerRepository;
7
7
  constructor(parent: Router, storage: AbstractStorage);
8
8
  getBasePath(): string;
9
+ extraRoutes(parent: Router): void;
9
10
  }
@@ -0,0 +1,12 @@
1
+ import AbstractService from './abstract';
2
+ import { Request, Response, Router } from 'express';
3
+ import { AbstractStorage } from '../storage';
4
+ import { CustomerRepository } from '../repositories/customer';
5
+ export declare class MyCustomerService extends AbstractService {
6
+ repository: CustomerRepository;
7
+ constructor(parent: Router, storage: AbstractStorage);
8
+ getBasePath(): string;
9
+ registerRoutes(parent: Router): void;
10
+ getMe(request: Request, response: Response): Response<any, Record<string, any>>;
11
+ signUp(request: Request, response: Response): Response<any, Record<string, any>>;
12
+ }
@@ -1,9 +1,10 @@
1
1
  import { ShippingMethodRepository } from '../repositories/shipping-method';
2
2
  import AbstractService from './abstract';
3
- import { Router } from 'express';
4
3
  import { AbstractStorage } from '../storage';
4
+ import { Router } from 'express';
5
5
  export declare class ShippingMethodService extends AbstractService {
6
6
  repository: ShippingMethodRepository;
7
7
  constructor(parent: Router, storage: AbstractStorage);
8
8
  getBasePath(): string;
9
+ extraRoutes(parent: Router): void;
9
10
  }
@@ -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/dist/types.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare type Writable<T> = {
18
18
  -readonly [P in keyof T]: Writable<T[P]>;
19
19
  };
20
20
  export declare type RepositoryTypes = ReferenceTypeId | 'product-projection';
21
- export declare type ServiceTypes = RepositoryTypes | 'my-cart' | 'my-payment';
21
+ export declare type ServiceTypes = RepositoryTypes | 'my-cart' | 'my-payment' | 'my-customer';
22
22
  export declare type Services = Partial<{
23
23
  [index in ServiceTypes]: AbstractService;
24
24
  }>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.17",
2
+ "version": "0.5.20",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -17,9 +17,7 @@
17
17
  "build": "tsdx build --target=node",
18
18
  "test": "tsdx test",
19
19
  "lint": "tsdx lint",
20
- "prepare": "tsdx build",
21
- "size": "size-limit",
22
- "analyze": "size-limit --why"
20
+ "prepare": "tsdx build"
23
21
  },
24
22
  "prettier": {
25
23
  "printWidth": 80,
@@ -30,19 +28,8 @@
30
28
  "name": "@labdigital/commercetools-mock",
31
29
  "author": "Michael van Tellingen",
32
30
  "module": "dist/commercetools--mock.esm.js",
33
- "size-limit": [
34
- {
35
- "path": "dist/commercetools--mock.cjs.production.min.js",
36
- "limit": "10 KB"
37
- },
38
- {
39
- "path": "dist/commercetools--mock.esm.js",
40
- "limit": "10 KB"
41
- }
42
- ],
43
31
  "devDependencies": {
44
32
  "@babel/preset-typescript": "^7.16.7",
45
- "@size-limit/preset-small-lib": "^7.0.5",
46
33
  "@types/basic-auth": "^1.1.3",
47
34
  "@types/deep-equal": "^1.0.1",
48
35
  "@types/express": "^4.17.13",
@@ -53,7 +40,6 @@
53
40
  "got": "^11.8.3",
54
41
  "husky": "^7.0.4",
55
42
  "nodemon": "^2.0.15",
56
- "size-limit": "^7.0.5",
57
43
  "ts-node": "^10.4.0",
58
44
  "tsdx": "^0.14.1",
59
45
  "tslib": "^2.3.1",
package/src/ctMock.ts CHANGED
@@ -37,6 +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
41
 
41
42
  export type CommercetoolsMockOptions = {
42
43
  validateCredentials: boolean
@@ -163,6 +164,7 @@ export class CommercetoolsMock {
163
164
  order: new OrderService(projectRouter, this._storage),
164
165
  payment: new PaymentService(projectRouter, this._storage),
165
166
  'my-cart': new MyCartService(projectRouter, this._storage),
167
+ 'my-customer': new MyCustomerService(projectRouter, this._storage),
166
168
  'my-payment': new MyPaymentService(projectRouter, this._storage),
167
169
  'shipping-method': new ShippingMethodService(
168
170
  projectRouter,
@@ -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 == undefined) {
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 == asset.id) {
62
+ if (assetId && assetId === asset.id) {
62
63
  asset.name = name
63
64
  }
64
- if (assetKey && assetKey == asset.key) {
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 == asset.id) {
90
+ if (assetId && assetId === asset.id) {
90
91
  asset.description = description
91
92
  }
92
- if (assetKey && assetKey == asset.key) {
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 == asset.id) {
104
+ if (assetId && assetId === asset.id) {
104
105
  asset.sources = sources
105
106
  }
106
- if (assetKey && assetKey == asset.key) {
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
 
@@ -14,11 +16,29 @@ export class CustomerRepository extends AbstractResourceRepository {
14
16
  const resource: Customer = {
15
17
  ...getBaseResourceProperties(),
16
18
  email: draft.email,
17
- password: draft.password,
19
+ password: Buffer.from(draft.password).toString('base64'),
18
20
  isEmailVerified: draft.isEmailVerified || false,
19
21
  addresses: [],
20
22
  }
21
23
  this.save(projectKey, resource)
22
24
  return resource
23
25
  }
26
+ getMe(projectKey: string): Customer | undefined {
27
+ const results = this._storage.query(projectKey, this.getTypeId(), {}) // grab the first customer you can find
28
+ if (results.count > 0) {
29
+ return results.results[0] as Customer
30
+ }
31
+
32
+ return
33
+ }
34
+
35
+ actions = {
36
+ changeEmail: (
37
+ _projectKey: string,
38
+ resource: Writable<Customer>,
39
+ { email }: CustomerChangeEmailAction
40
+ ) => {
41
+ resource.email = email
42
+ },
43
+ }
24
44
  }
@@ -25,7 +25,6 @@ export class DiscountCodeRepository extends AbstractResourceRepository {
25
25
  }
26
26
 
27
27
  create(projectKey: string, draft: DiscountCodeDraft): DiscountCode {
28
- console.log(draft)
29
28
  const resource: DiscountCode = {
30
29
  ...getBaseResourceProperties(),
31
30
  applicationVersion: 1,
@@ -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 == newValue.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 == attributeName) {
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 == attributeName) {
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,
@@ -146,7 +145,6 @@ export class ProjectRepository extends AbstractRepository {
146
145
  resource: Writable<Project>,
147
146
  { cartsConfiguration }: ProjectChangeCartsConfigurationAction
148
147
  ) => {
149
- console.log(cartsConfiguration)
150
148
  resource.carts = cartsConfiguration || {
151
149
  countryTaxRateFallbackEnabled: false,
152
150
  deleteDaysAfterLastModification: 90,
@@ -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
- projectKey: string,
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 == 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
- projectKey: string,
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 == 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
- projectKey: string,
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
- projectKey: string,
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
- projectKey: string,
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
- projectKey: string,
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
- projectKey: string,
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
- projectKey: string,
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
- projectKey: string,
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 == 'SQS') {
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 == '0000000000') {
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 == taxRateId) {
97
+ if (rate.id === taxRateId) {
98
98
  resource.rates[i] = taxRateObj
99
99
  }
100
100
  }
@@ -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 == fieldName) {
107
+ if (field.name === fieldName) {
108
108
  // TODO, should be done better i suppose
109
- if (field.type.name == 'Enum') {
109
+ if (field.type.name === 'Enum') {
110
110
  field.type.values.push(value)
111
111
  } else if (
112
- field.type.name == 'Set' &&
113
- field.type.elementType.name == 'Enum'
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 == fieldName) {
128
+ if (field.name === fieldName) {
129
129
  // TODO, should be done better i suppose
130
- if (field.type.name == 'Enum') {
130
+ if (field.type.name === 'Enum') {
131
131
  field.type.values.forEach(v => {
132
- if (v.key == value.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 == 'Set' &&
138
- field.type.elementType.name == 'Enum'
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 == value.key) {
141
+ if (v.key === value.key) {
142
142
  v.label = value.label
143
143
  }
144
144
  })
@@ -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 !(loc.country == location.country && loc.state == location.state)
52
+ return !(
53
+ loc.country === location.country && loc.state === location.state
54
+ )
53
55
  })
54
56
  },
55
57
  changeName: (
@@ -54,7 +54,6 @@ export default abstract class AbstractService {
54
54
  if (!result) {
55
55
  return response.status(404).send()
56
56
  }
57
- console.log(JSON.stringify(result, null, 4))
58
57
  return response.status(200).send(result)
59
58
  }
60
59
 
@@ -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
  }