@labdigital/commercetools-mock 2.17.1 → 2.18.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.
Files changed (178) hide show
  1. package/dist/index.cjs +4186 -3974
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +266 -413
  4. package/dist/index.d.ts +266 -413
  5. package/dist/index.js +4186 -3974
  6. package/dist/index.js.map +1 -1
  7. package/package.json +44 -46
  8. package/src/constants.ts +2 -2
  9. package/src/ctMock.test.ts +11 -11
  10. package/src/ctMock.ts +141 -127
  11. package/src/deprecation.ts +8 -0
  12. package/src/exceptions.ts +17 -15
  13. package/src/helpers.ts +32 -32
  14. package/src/index.test.ts +128 -128
  15. package/src/index.ts +3 -3
  16. package/src/lib/expandParser.ts +13 -13
  17. package/src/lib/haversine.test.ts +9 -9
  18. package/src/lib/haversine.ts +11 -11
  19. package/src/lib/masking.ts +11 -11
  20. package/src/lib/parser.ts +2 -2
  21. package/src/lib/password.ts +23 -3
  22. package/src/lib/predicateParser.test.ts +185 -183
  23. package/src/lib/predicateParser.ts +234 -234
  24. package/src/lib/projectionSearchFilter.test.ts +103 -101
  25. package/src/lib/projectionSearchFilter.ts +152 -150
  26. package/src/lib/proxy.ts +5 -5
  27. package/src/oauth/errors.ts +4 -4
  28. package/src/oauth/helpers.ts +6 -6
  29. package/src/oauth/server.test.ts +86 -86
  30. package/src/oauth/server.ts +158 -144
  31. package/src/oauth/store.ts +44 -43
  32. package/src/priceSelector.test.ts +35 -35
  33. package/src/priceSelector.ts +30 -30
  34. package/src/product-projection-search.ts +136 -134
  35. package/src/projectAPI.test.ts +7 -7
  36. package/src/projectAPI.ts +24 -22
  37. package/src/repositories/abstract.ts +168 -116
  38. package/src/repositories/associate-role.ts +90 -77
  39. package/src/repositories/attribute-group.ts +51 -40
  40. package/src/repositories/business-unit.ts +168 -148
  41. package/src/repositories/cart/actions.ts +489 -0
  42. package/src/repositories/cart/helpers.ts +30 -0
  43. package/src/repositories/cart/index.ts +180 -0
  44. package/src/repositories/cart-discount/actions.ts +148 -0
  45. package/src/repositories/cart-discount/index.ts +86 -0
  46. package/src/repositories/category/actions.ts +231 -0
  47. package/src/repositories/category/index.ts +52 -0
  48. package/src/repositories/channel.ts +88 -90
  49. package/src/repositories/custom-object.ts +46 -45
  50. package/src/repositories/customer/actions.ts +165 -0
  51. package/src/repositories/customer/index.ts +79 -0
  52. package/src/repositories/customer-group.ts +66 -55
  53. package/src/repositories/discount-code/actions.ts +149 -0
  54. package/src/repositories/discount-code/index.ts +50 -0
  55. package/src/repositories/errors.ts +10 -10
  56. package/src/repositories/extension.ts +64 -62
  57. package/src/repositories/helpers.ts +117 -118
  58. package/src/repositories/index.ts +80 -79
  59. package/src/repositories/inventory-entry/actions.ts +84 -0
  60. package/src/repositories/inventory-entry/index.ts +44 -0
  61. package/src/repositories/my-customer.ts +114 -0
  62. package/src/repositories/my-order.ts +8 -8
  63. package/src/repositories/order/actions.ts +281 -0
  64. package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
  65. package/src/repositories/order/index.ts +260 -0
  66. package/src/repositories/order-edit.ts +10 -23
  67. package/src/repositories/payment/actions.ts +305 -0
  68. package/src/repositories/payment/helpers.ts +17 -0
  69. package/src/repositories/payment/index.ts +56 -0
  70. package/src/repositories/product/actions.ts +943 -0
  71. package/src/repositories/product/helpers.ts +98 -0
  72. package/src/repositories/product/index.ts +130 -0
  73. package/src/repositories/product-discount.ts +127 -117
  74. package/src/repositories/product-projection.ts +56 -62
  75. package/src/repositories/product-selection.ts +31 -28
  76. package/src/repositories/product-type.ts +136 -134
  77. package/src/repositories/project.ts +133 -118
  78. package/src/repositories/quote-request.ts +7 -19
  79. package/src/repositories/quote.ts +7 -22
  80. package/src/repositories/review.ts +13 -26
  81. package/src/repositories/shipping-method/actions.ts +198 -0
  82. package/src/repositories/shipping-method/helpers.ts +10 -0
  83. package/src/repositories/shipping-method/index.ts +138 -0
  84. package/src/repositories/shopping-list/actions.ts +295 -0
  85. package/src/repositories/shopping-list/index.ts +122 -0
  86. package/src/repositories/staged-quote.ts +7 -20
  87. package/src/repositories/standalone-price.ts +57 -44
  88. package/src/repositories/state.ts +113 -68
  89. package/src/repositories/store.ts +106 -94
  90. package/src/repositories/subscription.ts +46 -22
  91. package/src/repositories/tax-category/actions.ts +94 -0
  92. package/src/repositories/tax-category/helpers.ts +8 -0
  93. package/src/repositories/tax-category/index.ts +25 -0
  94. package/src/repositories/type/actions.ts +162 -0
  95. package/src/repositories/type/index.ts +24 -0
  96. package/src/repositories/zone.ts +62 -58
  97. package/src/server.ts +9 -9
  98. package/src/services/abstract.ts +75 -72
  99. package/src/services/associate-roles.test.ts +27 -27
  100. package/src/services/associate-roles.ts +7 -7
  101. package/src/services/attribute-group.ts +7 -7
  102. package/src/services/business-units.test.ts +28 -28
  103. package/src/services/business-units.ts +7 -7
  104. package/src/services/cart-discount.test.ts +199 -199
  105. package/src/services/cart-discount.ts +7 -7
  106. package/src/services/cart.test.ts +261 -261
  107. package/src/services/cart.ts +22 -21
  108. package/src/services/category.test.ts +121 -121
  109. package/src/services/category.ts +7 -7
  110. package/src/services/channel.ts +7 -7
  111. package/src/services/custom-object.test.ts +130 -130
  112. package/src/services/custom-object.ts +34 -31
  113. package/src/services/customer-group.ts +7 -7
  114. package/src/services/customer.test.ts +205 -205
  115. package/src/services/customer.ts +23 -36
  116. package/src/services/discount-code.ts +7 -7
  117. package/src/services/extension.ts +7 -7
  118. package/src/services/index.ts +85 -81
  119. package/src/services/inventory-entry.test.ts +106 -106
  120. package/src/services/inventory-entry.ts +7 -7
  121. package/src/services/my-cart.test.ts +56 -56
  122. package/src/services/my-cart.ts +20 -20
  123. package/src/services/my-customer.test.ts +155 -104
  124. package/src/services/my-customer.ts +61 -75
  125. package/src/services/my-order.ts +16 -16
  126. package/src/services/my-payment.test.ts +40 -40
  127. package/src/services/my-payment.ts +7 -7
  128. package/src/services/my-shopping-list.ts +7 -7
  129. package/src/services/order.test.ts +243 -243
  130. package/src/services/order.ts +23 -18
  131. package/src/services/payment.test.ts +40 -40
  132. package/src/services/payment.ts +7 -7
  133. package/src/services/product-discount.ts +7 -7
  134. package/src/services/product-projection.test.ts +190 -190
  135. package/src/services/product-projection.ts +34 -32
  136. package/src/services/product-selection.test.ts +19 -19
  137. package/src/services/product-selection.ts +7 -7
  138. package/src/services/product-type.test.ts +38 -38
  139. package/src/services/product-type.ts +7 -7
  140. package/src/services/product.test.ts +658 -656
  141. package/src/services/product.ts +7 -7
  142. package/src/services/project.test.ts +24 -24
  143. package/src/services/project.ts +17 -17
  144. package/src/services/reviews.ts +7 -7
  145. package/src/services/shipping-method.test.ts +78 -78
  146. package/src/services/shipping-method.ts +16 -16
  147. package/src/services/shopping-list.test.ts +170 -170
  148. package/src/services/shopping-list.ts +7 -7
  149. package/src/services/standalone-price.test.ts +112 -112
  150. package/src/services/standalone-price.ts +7 -7
  151. package/src/services/state.test.ts +30 -30
  152. package/src/services/state.ts +7 -7
  153. package/src/services/store.test.ts +40 -40
  154. package/src/services/store.ts +7 -7
  155. package/src/services/subscription.ts +7 -7
  156. package/src/services/tax-category.test.ts +43 -43
  157. package/src/services/tax-category.ts +7 -7
  158. package/src/services/type.ts +7 -7
  159. package/src/services/zone.ts +7 -7
  160. package/src/shippingCalculator.test.ts +43 -43
  161. package/src/shippingCalculator.ts +23 -23
  162. package/src/storage/abstract.ts +36 -34
  163. package/src/storage/in-memory.ts +237 -233
  164. package/src/storage/index.ts +2 -2
  165. package/src/types.ts +91 -91
  166. package/src/repositories/cart-discount.ts +0 -219
  167. package/src/repositories/cart.ts +0 -659
  168. package/src/repositories/category.ts +0 -256
  169. package/src/repositories/customer.ts +0 -228
  170. package/src/repositories/discount-code.ts +0 -181
  171. package/src/repositories/inventory-entry.ts +0 -109
  172. package/src/repositories/order.ts +0 -514
  173. package/src/repositories/payment.ts +0 -342
  174. package/src/repositories/product.ts +0 -1106
  175. package/src/repositories/shipping-method.ts +0 -312
  176. package/src/repositories/shopping-list.ts +0 -392
  177. package/src/repositories/tax-category.ts +0 -111
  178. package/src/repositories/type.ts +0 -172
@@ -5,19 +5,25 @@ import type {
5
5
  CustomerGroupSetCustomFieldAction,
6
6
  CustomerGroupSetCustomTypeAction,
7
7
  CustomerGroupSetKeyAction,
8
- } from '@commercetools/platform-sdk'
9
- import { getBaseResourceProperties } from '../helpers.js'
10
- import type { Writable } from '../types.js'
8
+ CustomerGroupUpdateAction,
9
+ } from "@commercetools/platform-sdk";
10
+ import { getBaseResourceProperties } from "../helpers";
11
+ import { AbstractStorage } from "../storage/abstract";
12
+ import type { Writable } from "../types";
11
13
  import {
12
14
  AbstractResourceRepository,
15
+ AbstractUpdateHandler,
16
+ UpdateHandlerInterface,
13
17
  type RepositoryContext,
14
- } from './abstract.js'
15
- import { createCustomFields } from './helpers.js'
18
+ } from "./abstract";
19
+ import { createCustomFields } from "./helpers";
16
20
 
17
- export class CustomerGroupRepository extends AbstractResourceRepository<'customer-group'> {
18
- getTypeId() {
19
- return 'customer-group' as const
21
+ export class CustomerGroupRepository extends AbstractResourceRepository<"customer-group"> {
22
+ constructor(storage: AbstractStorage) {
23
+ super("customer-group", storage);
24
+ this.actions = new CustomerGroupUpdateHandler(storage);
20
25
  }
26
+
21
27
  create(context: RepositoryContext, draft: CustomerGroupDraft): CustomerGroup {
22
28
  const resource: CustomerGroup = {
23
29
  ...getBaseResourceProperties(),
@@ -26,56 +32,61 @@ export class CustomerGroupRepository extends AbstractResourceRepository<'custome
26
32
  custom: createCustomFields(
27
33
  draft.custom,
28
34
  context.projectKey,
29
- this._storage
35
+ this._storage,
30
36
  ),
37
+ };
38
+ return this.saveNew(context, resource);
39
+ }
40
+ }
41
+
42
+ class CustomerGroupUpdateHandler
43
+ extends AbstractUpdateHandler
44
+ implements UpdateHandlerInterface<CustomerGroup, CustomerGroupUpdateAction>
45
+ {
46
+ changeName(
47
+ context: RepositoryContext,
48
+ resource: Writable<CustomerGroup>,
49
+ { name }: CustomerGroupChangeNameAction,
50
+ ) {
51
+ resource.name = name;
52
+ }
53
+
54
+ setCustomField(
55
+ context: RepositoryContext,
56
+ resource: Writable<CustomerGroup>,
57
+ { name, value }: CustomerGroupSetCustomFieldAction,
58
+ ) {
59
+ if (!resource.custom) {
60
+ return;
61
+ }
62
+ if (value === null) {
63
+ delete resource.custom.fields[name];
64
+ } else {
65
+ resource.custom.fields[name] = value;
66
+ }
67
+ }
68
+
69
+ setCustomType(
70
+ context: RepositoryContext,
71
+ resource: Writable<CustomerGroup>,
72
+ { type, fields }: CustomerGroupSetCustomTypeAction,
73
+ ) {
74
+ if (type) {
75
+ resource.custom = createCustomFields(
76
+ { type, fields },
77
+ context.projectKey,
78
+ this._storage,
79
+ );
80
+ } else {
81
+ resource.custom = undefined;
31
82
  }
32
- this.saveNew(context, resource)
33
- return resource
34
83
  }
35
84
 
36
- actions = {
37
- setKey: (
38
- context: RepositoryContext,
39
- resource: Writable<CustomerGroup>,
40
- { key }: CustomerGroupSetKeyAction
41
- ) => {
42
- resource.key = key
43
- },
44
- changeName: (
45
- context: RepositoryContext,
46
- resource: Writable<CustomerGroup>,
47
- { name }: CustomerGroupChangeNameAction
48
- ) => {
49
- resource.name = name
50
- },
51
- setCustomType: (
52
- context: RepositoryContext,
53
- resource: Writable<CustomerGroup>,
54
- { type, fields }: CustomerGroupSetCustomTypeAction
55
- ) => {
56
- if (type) {
57
- resource.custom = createCustomFields(
58
- { type, fields },
59
- context.projectKey,
60
- this._storage
61
- )
62
- } else {
63
- resource.custom = undefined
64
- }
65
- },
66
- setCustomField: (
67
- context: RepositoryContext,
68
- resource: Writable<CustomerGroup>,
69
- { name, value }: CustomerGroupSetCustomFieldAction
70
- ) => {
71
- if (!resource.custom) {
72
- return
73
- }
74
- if (value === null) {
75
- delete resource.custom.fields[name]
76
- } else {
77
- resource.custom.fields[name] = value
78
- }
79
- },
85
+ setKey(
86
+ context: RepositoryContext,
87
+ resource: Writable<CustomerGroup>,
88
+ { key }: CustomerGroupSetKeyAction,
89
+ ) {
90
+ resource.key = key;
80
91
  }
81
92
  }
@@ -0,0 +1,149 @@
1
+ import type {
2
+ CartDiscountReference,
3
+ DiscountCode,
4
+ DiscountCodeChangeCartDiscountsAction,
5
+ DiscountCodeChangeIsActiveAction,
6
+ DiscountCodeSetCartPredicateAction,
7
+ DiscountCodeSetCustomFieldAction,
8
+ DiscountCodeSetCustomTypeAction,
9
+ DiscountCodeSetDescriptionAction,
10
+ DiscountCodeSetMaxApplicationsAction,
11
+ DiscountCodeSetMaxApplicationsPerCustomerAction,
12
+ DiscountCodeSetNameAction,
13
+ DiscountCodeSetValidFromAction,
14
+ DiscountCodeSetValidFromAndUntilAction,
15
+ DiscountCodeSetValidUntilAction,
16
+ DiscountCodeUpdateAction,
17
+ } from "@commercetools/platform-sdk";
18
+ import type { Writable } from "~src/types";
19
+ import {
20
+ AbstractUpdateHandler,
21
+ UpdateHandlerInterface,
22
+ type RepositoryContext,
23
+ } from "../abstract";
24
+ import { createCustomFields } from "../helpers";
25
+
26
+ export class DiscountCodeUpdateHandler
27
+ extends AbstractUpdateHandler
28
+ implements
29
+ Partial<UpdateHandlerInterface<DiscountCode, DiscountCodeUpdateAction>>
30
+ {
31
+ changeCartDiscounts(
32
+ context: RepositoryContext,
33
+ resource: Writable<DiscountCode>,
34
+ { cartDiscounts }: DiscountCodeChangeCartDiscountsAction,
35
+ ) {
36
+ resource.cartDiscounts = cartDiscounts.map(
37
+ (obj): CartDiscountReference => ({
38
+ typeId: "cart-discount",
39
+ id: obj.id!,
40
+ }),
41
+ );
42
+ }
43
+
44
+ changeIsActive(
45
+ context: RepositoryContext,
46
+ resource: Writable<DiscountCode>,
47
+ { isActive }: DiscountCodeChangeIsActiveAction,
48
+ ) {
49
+ resource.isActive = isActive;
50
+ }
51
+
52
+ setCartPredicate(
53
+ context: RepositoryContext,
54
+ resource: Writable<DiscountCode>,
55
+ { cartPredicate }: DiscountCodeSetCartPredicateAction,
56
+ ) {
57
+ resource.cartPredicate = cartPredicate;
58
+ }
59
+
60
+ setCustomField(
61
+ context: RepositoryContext,
62
+ resource: Writable<DiscountCode>,
63
+ { name, value }: DiscountCodeSetCustomFieldAction,
64
+ ) {
65
+ if (!resource.custom) {
66
+ return;
67
+ }
68
+ if (value === null) {
69
+ delete resource.custom.fields[name];
70
+ } else {
71
+ resource.custom.fields[name] = value;
72
+ }
73
+ }
74
+
75
+ setCustomType(
76
+ context: RepositoryContext,
77
+ resource: Writable<DiscountCode>,
78
+ { type, fields }: DiscountCodeSetCustomTypeAction,
79
+ ) {
80
+ if (type) {
81
+ resource.custom = createCustomFields(
82
+ { type, fields },
83
+ context.projectKey,
84
+ this._storage,
85
+ );
86
+ } else {
87
+ resource.custom = undefined;
88
+ }
89
+ }
90
+
91
+ setDescription(
92
+ context: RepositoryContext,
93
+ resource: Writable<DiscountCode>,
94
+ { description }: DiscountCodeSetDescriptionAction,
95
+ ) {
96
+ resource.description = description;
97
+ }
98
+
99
+ setMaxApplications(
100
+ context: RepositoryContext,
101
+ resource: Writable<DiscountCode>,
102
+ { maxApplications }: DiscountCodeSetMaxApplicationsAction,
103
+ ) {
104
+ resource.maxApplications = maxApplications;
105
+ }
106
+
107
+ setMaxApplicationsPerCustomer(
108
+ context: RepositoryContext,
109
+ resource: Writable<DiscountCode>,
110
+ {
111
+ maxApplicationsPerCustomer,
112
+ }: DiscountCodeSetMaxApplicationsPerCustomerAction,
113
+ ) {
114
+ resource.maxApplicationsPerCustomer = maxApplicationsPerCustomer;
115
+ }
116
+
117
+ setName(
118
+ context: RepositoryContext,
119
+ resource: Writable<DiscountCode>,
120
+ { name }: DiscountCodeSetNameAction,
121
+ ) {
122
+ resource.name = name;
123
+ }
124
+
125
+ setValidFrom(
126
+ context: RepositoryContext,
127
+ resource: Writable<DiscountCode>,
128
+ { validFrom }: DiscountCodeSetValidFromAction,
129
+ ) {
130
+ resource.validFrom = validFrom;
131
+ }
132
+
133
+ setValidFromAndUntil(
134
+ context: RepositoryContext,
135
+ resource: Writable<DiscountCode>,
136
+ { validFrom, validUntil }: DiscountCodeSetValidFromAndUntilAction,
137
+ ) {
138
+ resource.validFrom = validFrom;
139
+ resource.validUntil = validUntil;
140
+ }
141
+
142
+ setValidUntil(
143
+ context: RepositoryContext,
144
+ resource: Writable<DiscountCode>,
145
+ { validUntil }: DiscountCodeSetValidUntilAction,
146
+ ) {
147
+ resource.validUntil = validUntil;
148
+ }
149
+ }
@@ -0,0 +1,50 @@
1
+ import type {
2
+ CartDiscountReference,
3
+ DiscountCode,
4
+ DiscountCodeDraft,
5
+ } from "@commercetools/platform-sdk";
6
+ import { getBaseResourceProperties } from "~src/helpers";
7
+ import { AbstractStorage } from "~src/storage/abstract";
8
+ import {
9
+ AbstractResourceRepository,
10
+ type RepositoryContext,
11
+ } from "../abstract";
12
+ import { createCustomFields } from "../helpers";
13
+ import { DiscountCodeUpdateHandler } from "./actions";
14
+
15
+ export class DiscountCodeRepository extends AbstractResourceRepository<"discount-code"> {
16
+ constructor(storage: AbstractStorage) {
17
+ super("discount-code", storage);
18
+ this.actions = new DiscountCodeUpdateHandler(storage);
19
+ }
20
+
21
+ create(context: RepositoryContext, draft: DiscountCodeDraft): DiscountCode {
22
+ const resource: DiscountCode = {
23
+ ...getBaseResourceProperties(),
24
+ applicationVersion: 1,
25
+ cartDiscounts: draft.cartDiscounts.map(
26
+ (obj): CartDiscountReference => ({
27
+ typeId: "cart-discount",
28
+ id: obj.id!,
29
+ }),
30
+ ),
31
+ cartPredicate: draft.cartPredicate,
32
+ code: draft.code,
33
+ description: draft.description,
34
+ groups: draft.groups || [],
35
+ isActive: draft.isActive || true,
36
+ name: draft.name,
37
+ references: [],
38
+ validFrom: draft.validFrom,
39
+ validUntil: draft.validUntil,
40
+ maxApplications: draft.maxApplications,
41
+ maxApplicationsPerCustomer: draft.maxApplicationsPerCustomer,
42
+ custom: createCustomFields(
43
+ draft.custom,
44
+ context.projectKey,
45
+ this._storage,
46
+ ),
47
+ };
48
+ return this.saveNew(context, resource);
49
+ }
50
+ }
@@ -1,22 +1,22 @@
1
- import { type ConcurrentModificationError } from '@commercetools/platform-sdk'
2
- import { CommercetoolsError } from '../exceptions.js'
1
+ import { type ConcurrentModificationError } from "@commercetools/platform-sdk";
2
+ import { CommercetoolsError } from "~src/exceptions";
3
3
 
4
4
  export const checkConcurrentModification = (
5
5
  currentVersion: number,
6
6
  expectedVersion: number,
7
- identifier: string
7
+ identifier: string,
8
8
  ) => {
9
- if (currentVersion === expectedVersion) return
9
+ if (currentVersion === expectedVersion) return;
10
10
  console.error(
11
- `Object ${identifier} has a different version than expected. Expected: ${expectedVersion} - Actual: ${currentVersion}.`
12
- )
11
+ `Object ${identifier} has a different version than expected. Expected: ${expectedVersion} - Actual: ${currentVersion}.`,
12
+ );
13
13
 
14
14
  throw new CommercetoolsError<ConcurrentModificationError>(
15
15
  {
16
16
  message: `Object ${identifier} has a different version than expected. Expected: ${expectedVersion} - Actual: ${currentVersion}.`,
17
17
  currentVersion: currentVersion,
18
- code: 'ConcurrentModification',
18
+ code: "ConcurrentModification",
19
19
  },
20
- 409
21
- )
22
- }
20
+ 409,
21
+ );
22
+ };
@@ -6,85 +6,87 @@ import type {
6
6
  ExtensionSetKeyAction,
7
7
  ExtensionSetTimeoutInMsAction,
8
8
  ExtensionUpdateAction,
9
- } from '@commercetools/platform-sdk'
10
- import { getBaseResourceProperties } from '../helpers.js'
11
- import { maskSecretValue } from '../lib/masking.js'
12
- import type { Writable } from '../types.js'
9
+ } from "@commercetools/platform-sdk";
10
+ import { AbstractStorage } from "~src/storage";
11
+ import { getBaseResourceProperties } from "../helpers";
12
+ import { maskSecretValue } from "../lib/masking";
13
+ import type { Writable } from "../types";
13
14
  import {
14
15
  AbstractResourceRepository,
16
+ AbstractUpdateHandler,
17
+ UpdateHandlerInterface,
15
18
  type RepositoryContext,
16
- } from './abstract.js'
19
+ } from "./abstract";
17
20
 
18
- export class ExtensionRepository extends AbstractResourceRepository<'extension'> {
19
- getTypeId() {
20
- return 'extension' as const
21
+ export class ExtensionRepository extends AbstractResourceRepository<"extension"> {
22
+ constructor(storage: AbstractStorage) {
23
+ super("extension", storage);
24
+ this.actions = new ExtensionUpdateHandler(storage);
25
+ }
26
+
27
+ create(context: RepositoryContext, draft: ExtensionDraft): Extension {
28
+ const resource: Extension = {
29
+ ...getBaseResourceProperties(),
30
+ key: draft.key,
31
+ timeoutInMs: draft.timeoutInMs,
32
+ destination: draft.destination,
33
+ triggers: draft.triggers,
34
+ };
35
+ return this.saveNew(context, resource);
21
36
  }
22
37
 
23
38
  postProcessResource(resource: Extension): Extension {
24
39
  if (resource) {
25
- const extension = resource as Extension
40
+ const extension = resource as Extension;
26
41
  if (
27
- extension.destination.type === 'HTTP' &&
28
- extension.destination.authentication?.type === 'AuthorizationHeader'
42
+ extension.destination.type === "HTTP" &&
43
+ extension.destination.authentication?.type === "AuthorizationHeader"
29
44
  ) {
30
45
  return maskSecretValue(
31
46
  extension,
32
- 'destination.authentication.headerValue'
33
- )
34
- } else if (extension.destination.type == 'AWSLambda') {
35
- return maskSecretValue(resource, 'destination.accessSecret')
47
+ "destination.authentication.headerValue",
48
+ );
49
+ } else if (extension.destination.type == "AWSLambda") {
50
+ return maskSecretValue(resource, "destination.accessSecret");
36
51
  }
37
52
  }
38
- return resource
53
+ return resource;
39
54
  }
55
+ }
40
56
 
41
- create(context: RepositoryContext, draft: ExtensionDraft): Extension {
42
- const resource: Extension = {
43
- ...getBaseResourceProperties(),
44
- key: draft.key,
45
- timeoutInMs: draft.timeoutInMs,
46
- destination: draft.destination,
47
- triggers: draft.triggers,
48
- }
49
- this.saveNew(context, resource)
50
- return resource
57
+ class ExtensionUpdateHandler
58
+ extends AbstractUpdateHandler
59
+ implements UpdateHandlerInterface<Extension, ExtensionUpdateAction>
60
+ {
61
+ changeDestination(
62
+ context: RepositoryContext,
63
+ resource: Writable<Extension>,
64
+ action: ExtensionChangeDestinationAction,
65
+ ): void {
66
+ resource.destination = action.destination;
67
+ }
68
+
69
+ changeTriggers(
70
+ context: RepositoryContext,
71
+ resource: Writable<Extension>,
72
+ action: ExtensionChangeTriggersAction,
73
+ ): void {
74
+ resource.triggers = action.triggers;
75
+ }
76
+
77
+ setKey(
78
+ context: RepositoryContext,
79
+ resource: Writable<Extension>,
80
+ action: ExtensionSetKeyAction,
81
+ ): void {
82
+ resource.key = action.key;
51
83
  }
52
84
 
53
- actions: Record<
54
- ExtensionUpdateAction['action'],
55
- (
56
- context: RepositoryContext,
57
- resource: Writable<Extension>,
58
- action: any
59
- ) => void
60
- > = {
61
- setKey: (
62
- context: RepositoryContext,
63
- resource: Writable<Extension>,
64
- { key }: ExtensionSetKeyAction
65
- ) => {
66
- resource.key = key
67
- },
68
- setTimeoutInMs: (
69
- context: RepositoryContext,
70
- resource: Writable<Extension>,
71
- { timeoutInMs }: ExtensionSetTimeoutInMsAction
72
- ) => {
73
- resource.timeoutInMs = timeoutInMs
74
- },
75
- changeTriggers: (
76
- context: RepositoryContext,
77
- resource: Writable<Extension>,
78
- { triggers }: ExtensionChangeTriggersAction
79
- ) => {
80
- resource.triggers = triggers
81
- },
82
- changeDestination: (
83
- context: RepositoryContext,
84
- resource: Writable<Extension>,
85
- { destination }: ExtensionChangeDestinationAction
86
- ) => {
87
- resource.destination = destination
88
- },
85
+ setTimeoutInMs(
86
+ context: RepositoryContext,
87
+ resource: Writable<Extension>,
88
+ action: ExtensionSetTimeoutInMsAction,
89
+ ): void {
90
+ resource.timeoutInMs = action.timeoutInMs;
89
91
  }
90
92
  }