@labdigital/commercetools-mock 0.6.0 → 0.6.3

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 (77) hide show
  1. package/dist/commercetools-mock.cjs.development.js +423 -352
  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 +423 -352
  6. package/dist/commercetools-mock.esm.js.map +1 -1
  7. package/dist/repositories/abstract.d.ts +13 -9
  8. package/dist/repositories/cart-discount.d.ts +3 -3
  9. package/dist/repositories/cart.d.ts +13 -13
  10. package/dist/repositories/category.d.ts +11 -11
  11. package/dist/repositories/channel.d.ts +2 -2
  12. package/dist/repositories/custom-object.d.ts +3 -3
  13. package/dist/repositories/customer-group.d.ts +4 -4
  14. package/dist/repositories/customer.d.ts +4 -4
  15. package/dist/repositories/discount-code.d.ts +3 -3
  16. package/dist/repositories/extension.d.ts +3 -3
  17. package/dist/repositories/helpers.d.ts +3 -0
  18. package/dist/repositories/inventory-entry.d.ts +7 -7
  19. package/dist/repositories/my-order.d.ts +6 -0
  20. package/dist/repositories/order.d.ts +18 -17
  21. package/dist/repositories/payment.d.ts +8 -8
  22. package/dist/repositories/product-projection.d.ts +3 -3
  23. package/dist/repositories/product-type.d.ts +5 -5
  24. package/dist/repositories/product.d.ts +4 -4
  25. package/dist/repositories/project.d.ts +4 -4
  26. package/dist/repositories/shipping-method.d.ts +3 -3
  27. package/dist/repositories/shopping-list.d.ts +2 -2
  28. package/dist/repositories/state.d.ts +3 -3
  29. package/dist/repositories/store.d.ts +4 -4
  30. package/dist/repositories/subscription.d.ts +2 -2
  31. package/dist/repositories/tax-category.d.ts +4 -4
  32. package/dist/repositories/type.d.ts +3 -3
  33. package/dist/repositories/zone.d.ts +3 -3
  34. package/dist/services/my-order.d.ts +2 -2
  35. package/package.json +1 -1
  36. package/src/ctMock.ts +6 -0
  37. package/src/repositories/abstract.ts +37 -17
  38. package/src/repositories/cart-discount.ts +11 -11
  39. package/src/repositories/cart.ts +88 -36
  40. package/src/repositories/category.ts +17 -13
  41. package/src/repositories/channel.ts +3 -3
  42. package/src/repositories/custom-object.ts +16 -8
  43. package/src/repositories/customer-group.ts +5 -5
  44. package/src/repositories/customer.ts +10 -6
  45. package/src/repositories/discount-code.ts +14 -14
  46. package/src/repositories/extension.ts +12 -8
  47. package/src/repositories/helpers.ts +9 -0
  48. package/src/repositories/inventory-entry.ts +17 -10
  49. package/src/repositories/my-order.ts +19 -0
  50. package/src/repositories/order.test.ts +79 -3
  51. package/src/repositories/order.ts +77 -37
  52. package/src/repositories/payment.ts +21 -17
  53. package/src/repositories/product-projection.ts +5 -5
  54. package/src/repositories/product-type.ts +14 -10
  55. package/src/repositories/product.ts +5 -5
  56. package/src/repositories/project.ts +21 -17
  57. package/src/repositories/shipping-method.ts +27 -20
  58. package/src/repositories/shopping-list.ts +10 -6
  59. package/src/repositories/state.ts +13 -9
  60. package/src/repositories/store.ts +18 -14
  61. package/src/repositories/subscription.ts +3 -3
  62. package/src/repositories/tax-category.ts +16 -12
  63. package/src/repositories/type.ts +15 -11
  64. package/src/repositories/zone.ts +13 -9
  65. package/src/services/abstract.ts +21 -10
  66. package/src/services/cart.test.ts +48 -8
  67. package/src/services/cart.ts +17 -11
  68. package/src/services/custom-object.ts +8 -4
  69. package/src/services/customer.ts +5 -2
  70. package/src/services/my-customer.ts +7 -3
  71. package/src/services/my-order.ts +3 -3
  72. package/src/services/order.ts +3 -2
  73. package/src/services/product-projection.ts +2 -1
  74. package/src/services/product-type.ts +2 -1
  75. package/src/services/project.ts +4 -3
  76. package/src/services/store.ts +2 -1
  77. package/src/services/tax-category.ts +2 -1
@@ -17,12 +17,12 @@ import { InvalidOperationError } from '@commercetools/platform-sdk'
17
17
  import { Writable } from 'types'
18
18
  import { checkConcurrentModification } from './errors'
19
19
  import { CommercetoolsError } from '../exceptions'
20
- import { AbstractRepository } from './abstract'
20
+ import { AbstractRepository, RepositoryContext } from './abstract'
21
21
  import { maskSecretValue } from '../lib/masking'
22
22
 
23
23
  export class ProjectRepository extends AbstractRepository {
24
- get(projectKey: string): Project | null {
25
- const resource = this._storage.getProject(projectKey)
24
+ get(context: RepositoryContext): Project | null {
25
+ const resource = this._storage.getProject(context.projectKey)
26
26
  const masked = maskSecretValue<Project>(
27
27
  resource,
28
28
  'externalOAuth.authorizationHeader'
@@ -30,8 +30,8 @@ export class ProjectRepository extends AbstractRepository {
30
30
  return masked
31
31
  }
32
32
 
33
- save(projectKey: string, resource: Project) {
34
- const current = this.get(projectKey)
33
+ save(context: RepositoryContext, resource: Project) {
34
+ const current = this.get(context)
35
35
 
36
36
  if (current) {
37
37
  checkConcurrentModification(current, resource.version)
@@ -55,46 +55,50 @@ export class ProjectRepository extends AbstractRepository {
55
55
  actions: Partial<
56
56
  Record<
57
57
  ProjectUpdateAction['action'],
58
- (projectKey: string, resource: Writable<Project>, action: any) => void
58
+ (
59
+ context: RepositoryContext,
60
+ resource: Writable<Project>,
61
+ action: any
62
+ ) => void
59
63
  >
60
64
  > = {
61
65
  changeName: (
62
- projectKey: string,
66
+ context: RepositoryContext,
63
67
  resource: Writable<Project>,
64
68
  { name }: ProjectChangeNameAction
65
69
  ) => {
66
70
  resource.name = name
67
71
  },
68
72
  changeCurrencies: (
69
- projectKey: string,
73
+ context: RepositoryContext,
70
74
  resource: Writable<Project>,
71
75
  { currencies }: ProjectChangeCurrenciesAction
72
76
  ) => {
73
77
  resource.currencies = currencies
74
78
  },
75
79
  changeCountries: (
76
- projectKey: string,
80
+ context: RepositoryContext,
77
81
  resource: Writable<Project>,
78
82
  { countries }: ProjectChangeCountriesAction
79
83
  ) => {
80
84
  resource.countries = countries
81
85
  },
82
86
  changeLanguages: (
83
- projectKey: string,
87
+ context: RepositoryContext,
84
88
  resource: Writable<Project>,
85
89
  { languages }: ProjectChangeLanguagesAction
86
90
  ) => {
87
91
  resource.languages = languages
88
92
  },
89
93
  changeMessagesEnabled: (
90
- projectKey: string,
94
+ context: RepositoryContext,
91
95
  resource: Writable<Project>,
92
96
  { messagesEnabled }: ProjectChangeMessagesEnabledAction
93
97
  ) => {
94
98
  resource.messages.enabled = messagesEnabled
95
99
  },
96
100
  changeProductSearchIndexingEnabled: (
97
- projectKey: string,
101
+ context: RepositoryContext,
98
102
  resource: Writable<Project>,
99
103
  { enabled }: ProjectChangeProductSearchIndexingEnabledAction
100
104
  ) => {
@@ -107,7 +111,7 @@ export class ProjectRepository extends AbstractRepository {
107
111
  resource.searchIndexing.products.lastModifiedAt = new Date().toISOString()
108
112
  },
109
113
  changeOrderSearchStatus: (
110
- projectKey: string,
114
+ context: RepositoryContext,
111
115
  resource: Writable<Project>,
112
116
  { status }: ProjectChangeOrderSearchStatusAction
113
117
  ) => {
@@ -118,21 +122,21 @@ export class ProjectRepository extends AbstractRepository {
118
122
  resource.searchIndexing.orders.lastModifiedAt = new Date().toISOString()
119
123
  },
120
124
  setShippingRateInputType: (
121
- projectKey: string,
125
+ context: RepositoryContext,
122
126
  resource: Writable<Project>,
123
127
  { shippingRateInputType }: ProjectSetShippingRateInputTypeAction
124
128
  ) => {
125
129
  resource.shippingRateInputType = shippingRateInputType
126
130
  },
127
131
  setExternalOAuth: (
128
- projectKey: string,
132
+ context: RepositoryContext,
129
133
  resource: Writable<Project>,
130
134
  { externalOAuth }: ProjectSetExternalOAuthAction
131
135
  ) => {
132
136
  resource.externalOAuth = externalOAuth
133
137
  },
134
138
  changeCountryTaxRateFallbackEnabled: (
135
- projectKey: string,
139
+ context: RepositoryContext,
136
140
  resource: Writable<Project>,
137
141
  {
138
142
  countryTaxRateFallbackEnabled,
@@ -141,7 +145,7 @@ export class ProjectRepository extends AbstractRepository {
141
145
  resource.carts.countryTaxRateFallbackEnabled = countryTaxRateFallbackEnabled
142
146
  },
143
147
  changeCartsConfiguration: (
144
- projectKey: string,
148
+ context: RepositoryContext,
145
149
  resource: Writable<Project>,
146
150
  { cartsConfiguration }: ProjectChangeCartsConfigurationAction
147
151
  ) => {
@@ -24,7 +24,7 @@ import {
24
24
  ZoneReference,
25
25
  } from '@commercetools/platform-sdk'
26
26
  import { getBaseResourceProperties } from '../helpers'
27
- import { AbstractResourceRepository } from './abstract'
27
+ import { AbstractResourceRepository, RepositoryContext } from './abstract'
28
28
  import { Writable } from 'types'
29
29
  import deepEqual from 'deep-equal'
30
30
 
@@ -33,32 +33,39 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
33
33
  return 'shipping-method'
34
34
  }
35
35
 
36
- create(projectKey: string, draft: ShippingMethodDraft): ShippingMethod {
36
+ create(
37
+ context: RepositoryContext,
38
+ draft: ShippingMethodDraft
39
+ ): ShippingMethod {
37
40
  const resource: ShippingMethod = {
38
41
  ...getBaseResourceProperties(),
39
42
  ...draft,
40
43
  taxCategory: getReferenceFromResourceIdentifier(
41
44
  draft.taxCategory,
42
- projectKey,
45
+ context.projectKey,
43
46
  this._storage
44
47
  ),
45
48
  zoneRates: draft.zoneRates?.map(z =>
46
- this._transformZoneRateDraft(projectKey, z)
49
+ this._transformZoneRateDraft(context, z)
50
+ ),
51
+ custom: createCustomFields(
52
+ draft.custom,
53
+ context.projectKey,
54
+ this._storage
47
55
  ),
48
- custom: createCustomFields(draft.custom, projectKey, this._storage),
49
56
  }
50
- this.save(projectKey, resource)
57
+ this.save(context, resource)
51
58
  return resource
52
59
  }
53
60
 
54
61
  private _transformZoneRateDraft = (
55
- projectKey: string,
62
+ context: RepositoryContext,
56
63
  draft: ZoneRateDraft
57
64
  ): ZoneRate => ({
58
65
  ...draft,
59
66
  zone: getReferenceFromResourceIdentifier<ZoneReference>(
60
67
  draft.zone,
61
- projectKey,
68
+ context.projectKey,
62
69
  this._storage
63
70
  ),
64
71
  shippingRates: draft.shippingRates?.map(this._transformShippingRate),
@@ -76,14 +83,14 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
76
83
  Record<
77
84
  ShippingMethodUpdateAction['action'],
78
85
  (
79
- projectKey: string,
86
+ context: RepositoryContext,
80
87
  resource: Writable<ShippingMethod>,
81
88
  action: any
82
89
  ) => void
83
90
  >
84
91
  > = {
85
92
  addShippingRate: (
86
- _projectKey: string,
93
+ _context: RepositoryContext,
87
94
  resource: Writable<ShippingMethod>,
88
95
  { shippingRate, zone }: ShippingMethodAddShippingRateAction
89
96
  ) => {
@@ -104,7 +111,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
104
111
  })
105
112
  },
106
113
  removeShippingRate: (
107
- _projectKey: string,
114
+ _context: RepositoryContext,
108
115
  resource: Writable<ShippingMethod>,
109
116
  { shippingRate, zone }: ShippingMethodAddShippingRateAction
110
117
  ) => {
@@ -119,13 +126,13 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
119
126
  })
120
127
  },
121
128
  addZone: (
122
- projectKey: string,
129
+ context: RepositoryContext,
123
130
  resource: Writable<ShippingMethod>,
124
131
  { zone }: ShippingMethodAddZoneAction
125
132
  ) => {
126
133
  const zoneReference = getReferenceFromResourceIdentifier<ZoneReference>(
127
134
  zone,
128
- projectKey,
135
+ context.projectKey,
129
136
  this._storage
130
137
  )
131
138
 
@@ -139,7 +146,7 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
139
146
  })
140
147
  },
141
148
  removeZone: (
142
- _projectKey: string,
149
+ _context: RepositoryContext,
143
150
  resource: Writable<ShippingMethod>,
144
151
  { zone }: ShippingMethodRemoveZoneAction
145
152
  ) => {
@@ -148,42 +155,42 @@ export class ShippingMethodRepository extends AbstractResourceRepository {
148
155
  })
149
156
  },
150
157
  setKey: (
151
- _projectKey: string,
158
+ _context: RepositoryContext,
152
159
  resource: Writable<ShippingMethod>,
153
160
  { key }: ShippingMethodSetKeyAction
154
161
  ) => {
155
162
  resource.key = key
156
163
  },
157
164
  setDescription: (
158
- _projectKey: string,
165
+ _context: RepositoryContext,
159
166
  resource: Writable<ShippingMethod>,
160
167
  { description }: ShippingMethodSetDescriptionAction
161
168
  ) => {
162
169
  resource.description = description
163
170
  },
164
171
  setLocalizedDescription: (
165
- _projectKey: string,
172
+ _context: RepositoryContext,
166
173
  resource: Writable<ShippingMethod>,
167
174
  { localizedDescription }: ShippingMethodSetLocalizedDescriptionAction
168
175
  ) => {
169
176
  resource.localizedDescription = localizedDescription
170
177
  },
171
178
  setPredicate: (
172
- _projectKey: string,
179
+ _context: RepositoryContext,
173
180
  resource: Writable<ShippingMethod>,
174
181
  { predicate }: ShippingMethodSetPredicateAction
175
182
  ) => {
176
183
  resource.predicate = predicate
177
184
  },
178
185
  changeIsDefault: (
179
- _projectKey: string,
186
+ _context: RepositoryContext,
180
187
  resource: Writable<ShippingMethod>,
181
188
  { isDefault }: ShippingMethodChangeIsDefaultAction
182
189
  ) => {
183
190
  resource.isDefault = isDefault
184
191
  },
185
192
  changeName: (
186
- _projectKey: string,
193
+ _context: RepositoryContext,
187
194
  resource: Writable<ShippingMethod>,
188
195
  { name }: ShippingMethodChangeNameAction
189
196
  ) => {
@@ -5,7 +5,7 @@ import {
5
5
  ShoppingListDraft,
6
6
  } from '@commercetools/platform-sdk'
7
7
  import { getBaseResourceProperties } from '../helpers'
8
- import { AbstractResourceRepository } from './abstract'
8
+ import { AbstractResourceRepository, RepositoryContext } from './abstract'
9
9
  import {
10
10
  createCustomFields,
11
11
  getReferenceFromResourceIdentifier,
@@ -15,13 +15,17 @@ export class ShoppingListRepository extends AbstractResourceRepository {
15
15
  getTypeId(): ReferenceTypeId {
16
16
  return 'shopping-list'
17
17
  }
18
- create(projectKey: string, draft: ShoppingListDraft): ShoppingList {
18
+ create(context: RepositoryContext, draft: ShoppingListDraft): ShoppingList {
19
19
  // const product =
20
20
 
21
21
  const resource: ShoppingList = {
22
22
  ...getBaseResourceProperties(),
23
23
  ...draft,
24
- custom: createCustomFields(draft.custom, projectKey, this._storage),
24
+ custom: createCustomFields(
25
+ draft.custom,
26
+ context.projectKey,
27
+ this._storage
28
+ ),
25
29
  textLineItems: [],
26
30
  lineItems: draft.lineItems?.map(e => ({
27
31
  ...getBaseResourceProperties(),
@@ -31,12 +35,12 @@ export class ShoppingListRepository extends AbstractResourceRepository {
31
35
  name: {},
32
36
  quantity: e.quantity ?? 1,
33
37
  productType: { typeId: 'product-type', id: '' },
34
- custom: createCustomFields(e.custom, projectKey, this._storage),
38
+ custom: createCustomFields(e.custom, context.projectKey, this._storage),
35
39
  })),
36
40
  customer: draft.customer
37
41
  ? getReferenceFromResourceIdentifier<CustomerReference>(
38
42
  draft.customer,
39
- projectKey,
43
+ context.projectKey,
40
44
  this._storage
41
45
  )
42
46
  : undefined,
@@ -44,7 +48,7 @@ export class ShoppingListRepository extends AbstractResourceRepository {
44
48
  ? { typeId: 'store', key: draft.store.key! }
45
49
  : undefined,
46
50
  }
47
- this.save(projectKey, resource)
51
+ this.save(context, resource)
48
52
  return resource
49
53
  }
50
54
  }
@@ -10,7 +10,7 @@ import {
10
10
  StateSetRolesAction,
11
11
  StateUpdateAction,
12
12
  } from '@commercetools/platform-sdk'
13
- import { AbstractResourceRepository } from './abstract'
13
+ import { AbstractResourceRepository, RepositoryContext } from './abstract'
14
14
  import { Writable } from 'types'
15
15
 
16
16
  export class StateRepository extends AbstractResourceRepository {
@@ -18,50 +18,54 @@ export class StateRepository extends AbstractResourceRepository {
18
18
  return 'state'
19
19
  }
20
20
 
21
- create(projectKey: string, draft: StateDraft): State {
21
+ create(context: RepositoryContext, draft: StateDraft): State {
22
22
  const resource: State = {
23
23
  ...getBaseResourceProperties(),
24
24
  ...draft,
25
25
  builtIn: false,
26
26
  initial: draft.initial || false,
27
27
  transitions: (draft.transitions || []).map(t =>
28
- getReferenceFromResourceIdentifier(t, projectKey, this._storage)
28
+ getReferenceFromResourceIdentifier(t, context.projectKey, this._storage)
29
29
  ),
30
30
  }
31
31
 
32
- this.save(projectKey, resource)
32
+ this.save(context, resource)
33
33
  return resource
34
34
  }
35
35
 
36
36
  actions: Partial<
37
37
  Record<
38
38
  StateUpdateAction['action'],
39
- (projectKey: string, resource: Writable<State>, action: any) => void
39
+ (
40
+ context: RepositoryContext,
41
+ resource: Writable<State>,
42
+ action: any
43
+ ) => void
40
44
  >
41
45
  > = {
42
46
  changeKey: (
43
- projectKey: string,
47
+ context: RepositoryContext,
44
48
  resource: Writable<State>,
45
49
  { key }: StateChangeKeyAction
46
50
  ) => {
47
51
  resource.key = key
48
52
  },
49
53
  setDescription: (
50
- projectKey: string,
54
+ context: RepositoryContext,
51
55
  resource: Writable<State>,
52
56
  { description }: StateSetDescriptionAction
53
57
  ) => {
54
58
  resource.description = description
55
59
  },
56
60
  setName: (
57
- projectKey: string,
61
+ context: RepositoryContext,
58
62
  resource: Writable<State>,
59
63
  { name }: StateSetNameAction
60
64
  ) => {
61
65
  resource.name = name
62
66
  },
63
67
  setRoles: (
64
- projectKey: string,
68
+ context: RepositoryContext,
65
69
  resource: Writable<State>,
66
70
  { roles }: StateSetRolesAction
67
71
  ) => {
@@ -11,7 +11,7 @@ import {
11
11
  } from '@commercetools/platform-sdk'
12
12
  import { Writable } from 'types'
13
13
  import { getBaseResourceProperties } from '../helpers'
14
- import { AbstractResourceRepository } from './abstract'
14
+ import { AbstractResourceRepository, RepositoryContext } from './abstract'
15
15
  import { getReferenceFromResourceIdentifier } from './helpers'
16
16
 
17
17
  export class StoreRepository extends AbstractResourceRepository {
@@ -19,24 +19,24 @@ export class StoreRepository extends AbstractResourceRepository {
19
19
  return 'store'
20
20
  }
21
21
 
22
- create(projectKey: string, draft: StoreDraft): Store {
22
+ create(context: RepositoryContext, draft: StoreDraft): Store {
23
23
  const resource: Store = {
24
24
  ...getBaseResourceProperties(),
25
25
  key: draft.key,
26
26
  name: draft.name,
27
27
  languages: draft.languages,
28
28
  distributionChannels: this.transformChannels(
29
- projectKey,
29
+ context,
30
30
  draft.distributionChannels
31
31
  ),
32
- supplyChannels: this.transformChannels(projectKey, draft.supplyChannels),
32
+ supplyChannels: this.transformChannels(context, draft.supplyChannels),
33
33
  }
34
- this.save(projectKey, resource)
34
+ this.save(context, resource)
35
35
  return resource
36
36
  }
37
37
 
38
38
  private transformChannels(
39
- projectKey: string,
39
+ context: RepositoryContext,
40
40
  channels?: ChannelResourceIdentifier[]
41
41
  ) {
42
42
  if (!channels) return []
@@ -44,14 +44,14 @@ export class StoreRepository extends AbstractResourceRepository {
44
44
  return channels.map(ref =>
45
45
  getReferenceFromResourceIdentifier<ChannelReference>(
46
46
  ref,
47
- projectKey,
47
+ context.projectKey,
48
48
  this._storage
49
49
  )
50
50
  )
51
51
  }
52
52
 
53
- getWithKey(projectKey: string, key: string): Store | undefined {
54
- const result = this._storage.query(projectKey, this.getTypeId(), {
53
+ getWithKey(context: RepositoryContext, key: string): Store | undefined {
54
+ const result = this._storage.query(context.projectKey, this.getTypeId(), {
55
55
  where: [`key="${key}"`],
56
56
  })
57
57
  if (result.count === 1) {
@@ -68,28 +68,32 @@ export class StoreRepository extends AbstractResourceRepository {
68
68
  actions: Partial<
69
69
  Record<
70
70
  StoreUpdateAction['action'],
71
- (projectKey: string, resource: Writable<Store>, action: any) => void
71
+ (
72
+ context: RepositoryContext,
73
+ resource: Writable<Store>,
74
+ action: any
75
+ ) => void
72
76
  >
73
77
  > = {
74
78
  setName: (
75
- projectKey: string,
79
+ context: RepositoryContext,
76
80
  resource: Writable<Store>,
77
81
  { name }: StoreSetNameAction
78
82
  ) => {
79
83
  resource.name = name
80
84
  },
81
85
  setDistributionChannels: (
82
- projectKey: string,
86
+ context: RepositoryContext,
83
87
  resource: Writable<Store>,
84
88
  { distributionChannels }: StoreSetDistributionChannelsAction
85
89
  ) => {
86
90
  resource.distributionChannels = this.transformChannels(
87
- projectKey,
91
+ context,
88
92
  distributionChannels
89
93
  )
90
94
  },
91
95
  setLanguages: (
92
- projectKey: string,
96
+ context: RepositoryContext,
93
97
  resource: Writable<Store>,
94
98
  { languages }: StoreSetLanguagesAction
95
99
  ) => {
@@ -6,13 +6,13 @@ import {
6
6
  } from '@commercetools/platform-sdk'
7
7
  import { CommercetoolsError } from '../exceptions'
8
8
  import { getBaseResourceProperties } from '../helpers'
9
- import { AbstractResourceRepository } from './abstract'
9
+ import { AbstractResourceRepository, RepositoryContext } from './abstract'
10
10
 
11
11
  export class SubscriptionRepository extends AbstractResourceRepository {
12
12
  getTypeId(): ReferenceTypeId {
13
13
  return 'subscription'
14
14
  }
15
- create(projectKey: string, draft: SubscriptionDraft): Subscription {
15
+ create(context: RepositoryContext, 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
18
  if (draft.destination.type === 'SQS') {
@@ -44,7 +44,7 @@ export class SubscriptionRepository extends AbstractResourceRepository {
44
44
  messages: draft.messages || [],
45
45
  status: 'Healthy',
46
46
  }
47
- this.save(projectKey, resource)
47
+ this.save(context, resource)
48
48
  return resource
49
49
  }
50
50
  }
@@ -13,7 +13,7 @@ import {
13
13
  TaxRateDraft,
14
14
  } from '@commercetools/platform-sdk'
15
15
  import { getBaseResourceProperties } from '../helpers'
16
- import { AbstractResourceRepository } from './abstract'
16
+ import { AbstractResourceRepository, RepositoryContext } from './abstract'
17
17
  import { v4 as uuidv4 } from 'uuid'
18
18
  import { Writable } from 'types'
19
19
 
@@ -22,13 +22,13 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
22
22
  return 'tax-category'
23
23
  }
24
24
 
25
- create(projectKey: string, draft: TaxCategoryDraft): TaxCategory {
25
+ create(context: RepositoryContext, draft: TaxCategoryDraft): TaxCategory {
26
26
  const resource: TaxCategory = {
27
27
  ...getBaseResourceProperties(),
28
28
  ...draft,
29
29
  rates: draft.rates?.map(this.taxRateFromTaxRateDraft) || [],
30
30
  }
31
- this.save(projectKey, resource)
31
+ this.save(context, resource)
32
32
  return resource
33
33
  }
34
34
 
@@ -38,8 +38,8 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
38
38
  amount: draft.amount || 0,
39
39
  })
40
40
 
41
- getWithKey(projectKey: string, key: string): TaxCategory | undefined {
42
- const result = this._storage.query(projectKey, this.getTypeId(), {
41
+ getWithKey(context: RepositoryContext, key: string): TaxCategory | undefined {
42
+ const result = this._storage.query(context.projectKey, this.getTypeId(), {
43
43
  where: [`key="${key}"`],
44
44
  })
45
45
  if (result.count === 1) {
@@ -57,11 +57,15 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
57
57
  actions: Partial<
58
58
  Record<
59
59
  TaxCategoryUpdateAction['action'],
60
- (projectKey: string, resource: Writable<TaxCategory>, action: any) => void
60
+ (
61
+ context: RepositoryContext,
62
+ resource: Writable<TaxCategory>,
63
+ action: any
64
+ ) => void
61
65
  >
62
66
  > = {
63
67
  addTaxRate: (
64
- projectKey: string,
68
+ context: RepositoryContext,
65
69
  resource: Writable<TaxCategory>,
66
70
  { taxRate }: TaxCategoryAddTaxRateAction
67
71
  ) => {
@@ -71,7 +75,7 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
71
75
  resource.rates.push(this.taxRateFromTaxRateDraft(taxRate))
72
76
  },
73
77
  removeTaxRate: (
74
- projectKey: string,
78
+ context: RepositoryContext,
75
79
  resource: Writable<TaxCategory>,
76
80
  { taxRateId }: TaxCategoryRemoveTaxRateAction
77
81
  ) => {
@@ -83,7 +87,7 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
83
87
  })
84
88
  },
85
89
  replaceTaxRate: (
86
- projectKey: string,
90
+ context: RepositoryContext,
87
91
  resource: Writable<TaxCategory>,
88
92
  { taxRateId, taxRate }: TaxCategoryReplaceTaxRateAction
89
93
  ) => {
@@ -100,21 +104,21 @@ export class TaxCategoryRepository extends AbstractResourceRepository {
100
104
  }
101
105
  },
102
106
  setDescription: (
103
- projectKey: string,
107
+ context: RepositoryContext,
104
108
  resource: Writable<TaxCategory>,
105
109
  { description }: TaxCategorySetDescriptionAction
106
110
  ) => {
107
111
  resource.description = description
108
112
  },
109
113
  setKey: (
110
- projectKey: string,
114
+ context: RepositoryContext,
111
115
  resource: Writable<TaxCategory>,
112
116
  { key }: TaxCategorySetKeyAction
113
117
  ) => {
114
118
  resource.key = key
115
119
  },
116
120
  changeName: (
117
- projectKey: string,
121
+ context: RepositoryContext,
118
122
  resource: Writable<TaxCategory>,
119
123
  { name }: TaxCategoryChangeNameAction
120
124
  ) => {