@fiado/type-kit 3.509.0 → 3.510.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 (174) hide show
  1. package/_test_/unit/dynamicForm/dynamicForm.test.ts +78 -0
  2. package/_test_/unit/rewards/enums.test.ts +87 -0
  3. package/_test_/unit/rewards/grantMessages.test.ts +123 -0
  4. package/_test_/unit/rewards/readResponses.test.ts +136 -0
  5. package/_test_/unit/rewardsEligibility/events.test.ts +130 -0
  6. package/bin/benefitCenter/dtos/InputField.d.ts +1 -13
  7. package/bin/benefitCenter/dtos/InputField.js +3 -3
  8. package/bin/benefitCenter/dtos/InputSchema.d.ts +1 -6
  9. package/bin/benefitCenter/dtos/InputSchema.js +3 -3
  10. package/bin/benefitCenter/dtos/InputValidation.d.ts +1 -8
  11. package/bin/benefitCenter/dtos/InputValidation.js +3 -3
  12. package/bin/benefitCenter/dtos/SelectOption.d.ts +1 -4
  13. package/bin/benefitCenter/dtos/SelectOption.js +3 -3
  14. package/bin/benefitCenter/enums/InputFieldTypeEnum.d.ts +1 -10
  15. package/bin/benefitCenter/enums/InputFieldTypeEnum.js +3 -11
  16. package/bin/common/index.d.ts +1 -0
  17. package/bin/common/index.js +2 -0
  18. package/bin/common/types/JsonValue.d.ts +7 -0
  19. package/bin/common/types/JsonValue.js +2 -0
  20. package/bin/dynamicForm/dtos/InputField.d.ts +15 -0
  21. package/bin/dynamicForm/dtos/InputField.js +6 -0
  22. package/bin/dynamicForm/dtos/InputSchema.d.ts +6 -0
  23. package/bin/dynamicForm/dtos/InputSchema.js +6 -0
  24. package/bin/dynamicForm/dtos/InputValidation.d.ts +8 -0
  25. package/bin/dynamicForm/dtos/InputValidation.js +6 -0
  26. package/bin/dynamicForm/dtos/SelectOption.d.ts +4 -0
  27. package/bin/dynamicForm/dtos/SelectOption.js +6 -0
  28. package/bin/dynamicForm/enums/InputFieldTypeEnum.d.ts +18 -0
  29. package/bin/dynamicForm/enums/InputFieldTypeEnum.js +22 -0
  30. package/bin/dynamicForm/helpers/isDynamicFormValue.d.ts +7 -0
  31. package/bin/dynamicForm/helpers/isDynamicFormValue.js +19 -0
  32. package/bin/dynamicForm/index.d.ts +8 -0
  33. package/bin/dynamicForm/index.js +29 -0
  34. package/bin/dynamicForm/types/DynamicFormValue.d.ts +10 -0
  35. package/bin/dynamicForm/types/DynamicFormValue.js +2 -0
  36. package/bin/dynamicForm/validators/IsDynamicFormValues.d.ts +7 -0
  37. package/bin/dynamicForm/validators/IsDynamicFormValues.js +26 -0
  38. package/bin/index.d.ts +3 -0
  39. package/bin/index.js +12 -1
  40. package/bin/rewards/constants/RewardsLimits.d.ts +2 -0
  41. package/bin/rewards/constants/RewardsLimits.js +5 -0
  42. package/bin/rewards/dtos/GrantFailedMessage.d.ts +13 -0
  43. package/bin/rewards/dtos/GrantFailedMessage.js +46 -0
  44. package/bin/rewards/dtos/GrantRequestedMessage.d.ts +21 -0
  45. package/bin/rewards/dtos/GrantRequestedMessage.js +61 -0
  46. package/bin/rewards/dtos/RewardChargeTo.d.ts +5 -0
  47. package/bin/rewards/dtos/RewardChargeTo.js +7 -0
  48. package/bin/rewards/dtos/RewardCost.d.ts +6 -0
  49. package/bin/rewards/dtos/RewardCost.js +7 -0
  50. package/bin/rewards/dtos/RewardDependency.d.ts +17 -0
  51. package/bin/rewards/dtos/RewardDependency.js +12 -0
  52. package/bin/rewards/dtos/RewardSource.d.ts +12 -0
  53. package/bin/rewards/dtos/RewardSource.js +40 -0
  54. package/bin/rewards/dtos/responses/GrantAttemptResponse.d.ts +15 -0
  55. package/bin/rewards/dtos/responses/GrantAttemptResponse.js +10 -0
  56. package/bin/rewards/dtos/responses/GrantItemResponse.d.ts +20 -0
  57. package/bin/rewards/dtos/responses/GrantItemResponse.js +6 -0
  58. package/bin/rewards/dtos/responses/GrantResponse.d.ts +23 -0
  59. package/bin/rewards/dtos/responses/GrantResponse.js +7 -0
  60. package/bin/rewards/dtos/responses/PackageContractItem.d.ts +12 -0
  61. package/bin/rewards/dtos/responses/PackageContractItem.js +7 -0
  62. package/bin/rewards/dtos/responses/PackageContractResponse.d.ts +13 -0
  63. package/bin/rewards/dtos/responses/PackageContractResponse.js +7 -0
  64. package/bin/rewards/enums/DependencyIfMissingEnum.d.ts +5 -0
  65. package/bin/rewards/enums/DependencyIfMissingEnum.js +9 -0
  66. package/bin/rewards/enums/GrantFailedReasonEnum.d.ts +11 -0
  67. package/bin/rewards/enums/GrantFailedReasonEnum.js +15 -0
  68. package/bin/rewards/enums/GrantItemStatusEnum.d.ts +6 -0
  69. package/bin/rewards/enums/GrantItemStatusEnum.js +10 -0
  70. package/bin/rewards/enums/GrantRejectReasonEnum.d.ts +6 -0
  71. package/bin/rewards/enums/GrantRejectReasonEnum.js +10 -0
  72. package/bin/rewards/enums/GrantStatusEnum.d.ts +8 -0
  73. package/bin/rewards/enums/GrantStatusEnum.js +12 -0
  74. package/bin/rewards/enums/ItemErrorCategoryEnum.d.ts +7 -0
  75. package/bin/rewards/enums/ItemErrorCategoryEnum.js +11 -0
  76. package/bin/rewards/enums/RewardStatusEnum.d.ts +4 -0
  77. package/bin/rewards/enums/RewardStatusEnum.js +8 -0
  78. package/bin/rewards/enums/RewardsErrorCodeEnum.d.ts +5 -0
  79. package/bin/rewards/enums/RewardsErrorCodeEnum.js +9 -0
  80. package/bin/rewards/enums/RewardsMessageTypeEnum.d.ts +4 -0
  81. package/bin/rewards/enums/RewardsMessageTypeEnum.js +8 -0
  82. package/bin/rewards/index.d.ts +24 -0
  83. package/bin/rewards/index.js +47 -0
  84. package/bin/rewards/types/RewardInputs.d.ts +3 -0
  85. package/bin/rewards/types/RewardInputs.js +2 -0
  86. package/bin/rewards/validators/IsRewardInputs.d.ts +7 -0
  87. package/bin/rewards/validators/IsRewardInputs.js +26 -0
  88. package/bin/rewards/validators/IsRewardTags.d.ts +7 -0
  89. package/bin/rewards/validators/IsRewardTags.js +28 -0
  90. package/bin/rewardsEligibility/dtos/EventRunResult.d.ts +11 -0
  91. package/bin/rewardsEligibility/dtos/EventRunResult.js +7 -0
  92. package/bin/rewardsEligibility/dtos/EventSource.d.ts +5 -0
  93. package/bin/rewardsEligibility/dtos/EventSource.js +30 -0
  94. package/bin/rewardsEligibility/dtos/GetRunResponse.d.ts +22 -0
  95. package/bin/rewardsEligibility/dtos/GetRunResponse.js +7 -0
  96. package/bin/rewardsEligibility/dtos/PostEventRequest.d.ts +14 -0
  97. package/bin/rewardsEligibility/dtos/PostEventRequest.js +47 -0
  98. package/bin/rewardsEligibility/dtos/PostEventResponse.d.ts +5 -0
  99. package/bin/rewardsEligibility/dtos/PostEventResponse.js +7 -0
  100. package/bin/rewardsEligibility/dtos/RunCounts.d.ts +12 -0
  101. package/bin/rewardsEligibility/dtos/RunCounts.js +7 -0
  102. package/bin/rewardsEligibility/dtos/RunResultItem.d.ts +16 -0
  103. package/bin/rewardsEligibility/dtos/RunResultItem.js +7 -0
  104. package/bin/rewardsEligibility/enums/EvaluationOutcomeEnum.d.ts +11 -0
  105. package/bin/rewardsEligibility/enums/EvaluationOutcomeEnum.js +15 -0
  106. package/bin/rewardsEligibility/enums/GrantRequestStatusEnum.d.ts +11 -0
  107. package/bin/rewardsEligibility/enums/GrantRequestStatusEnum.js +15 -0
  108. package/bin/rewardsEligibility/enums/RewardsEligibilityErrorCodeEnum.d.ts +8 -0
  109. package/bin/rewardsEligibility/enums/RewardsEligibilityErrorCodeEnum.js +12 -0
  110. package/bin/rewardsEligibility/enums/RunModeEnum.d.ts +4 -0
  111. package/bin/rewardsEligibility/enums/RunModeEnum.js +8 -0
  112. package/bin/rewardsEligibility/enums/RunStatusEnum.d.ts +9 -0
  113. package/bin/rewardsEligibility/enums/RunStatusEnum.js +13 -0
  114. package/bin/rewardsEligibility/enums/TriggerTypeEnum.d.ts +5 -0
  115. package/bin/rewardsEligibility/enums/TriggerTypeEnum.js +9 -0
  116. package/bin/rewardsEligibility/index.d.ts +13 -0
  117. package/bin/rewardsEligibility/index.js +31 -0
  118. package/package.json +1 -1
  119. package/src/benefitCenter/dtos/InputField.ts +2 -14
  120. package/src/benefitCenter/dtos/InputSchema.ts +2 -7
  121. package/src/benefitCenter/dtos/InputValidation.ts +2 -8
  122. package/src/benefitCenter/dtos/SelectOption.ts +2 -4
  123. package/src/benefitCenter/enums/InputFieldTypeEnum.ts +2 -10
  124. package/src/common/index.ts +4 -1
  125. package/src/common/types/JsonValue.ts +5 -0
  126. package/src/dynamicForm/dtos/InputField.ts +16 -0
  127. package/src/dynamicForm/dtos/InputSchema.ts +7 -0
  128. package/src/dynamicForm/dtos/InputValidation.ts +8 -0
  129. package/src/dynamicForm/dtos/SelectOption.ts +4 -0
  130. package/src/dynamicForm/enums/InputFieldTypeEnum.ts +18 -0
  131. package/src/dynamicForm/helpers/isDynamicFormValue.ts +16 -0
  132. package/src/dynamicForm/index.ts +17 -0
  133. package/src/dynamicForm/types/DynamicFormValue.ts +8 -0
  134. package/src/dynamicForm/validators/IsDynamicFormValues.ts +16 -0
  135. package/src/index.ts +14 -0
  136. package/src/rewards/constants/RewardsLimits.ts +2 -0
  137. package/src/rewards/dtos/GrantFailedMessage.ts +29 -0
  138. package/src/rewards/dtos/GrantRequestedMessage.ts +46 -0
  139. package/src/rewards/dtos/RewardChargeTo.ts +5 -0
  140. package/src/rewards/dtos/RewardCost.ts +7 -0
  141. package/src/rewards/dtos/RewardDependency.ts +18 -0
  142. package/src/rewards/dtos/RewardSource.ts +27 -0
  143. package/src/rewards/dtos/responses/GrantAttemptResponse.ts +16 -0
  144. package/src/rewards/dtos/responses/GrantItemResponse.ts +21 -0
  145. package/src/rewards/dtos/responses/GrantResponse.ts +24 -0
  146. package/src/rewards/dtos/responses/PackageContractItem.ts +13 -0
  147. package/src/rewards/dtos/responses/PackageContractResponse.ts +14 -0
  148. package/src/rewards/enums/DependencyIfMissingEnum.ts +5 -0
  149. package/src/rewards/enums/GrantFailedReasonEnum.ts +11 -0
  150. package/src/rewards/enums/GrantItemStatusEnum.ts +6 -0
  151. package/src/rewards/enums/GrantRejectReasonEnum.ts +6 -0
  152. package/src/rewards/enums/GrantStatusEnum.ts +8 -0
  153. package/src/rewards/enums/ItemErrorCategoryEnum.ts +7 -0
  154. package/src/rewards/enums/RewardStatusEnum.ts +4 -0
  155. package/src/rewards/enums/RewardsErrorCodeEnum.ts +5 -0
  156. package/src/rewards/enums/RewardsMessageTypeEnum.ts +4 -0
  157. package/src/rewards/index.ts +37 -0
  158. package/src/rewards/types/RewardInputs.ts +4 -0
  159. package/src/rewards/validators/IsRewardInputs.ts +18 -0
  160. package/src/rewards/validators/IsRewardTags.ts +18 -0
  161. package/src/rewardsEligibility/dtos/EventRunResult.ts +12 -0
  162. package/src/rewardsEligibility/dtos/EventSource.ts +15 -0
  163. package/src/rewardsEligibility/dtos/GetRunResponse.ts +23 -0
  164. package/src/rewardsEligibility/dtos/PostEventRequest.ts +32 -0
  165. package/src/rewardsEligibility/dtos/PostEventResponse.ts +6 -0
  166. package/src/rewardsEligibility/dtos/RunCounts.ts +12 -0
  167. package/src/rewardsEligibility/dtos/RunResultItem.ts +17 -0
  168. package/src/rewardsEligibility/enums/EvaluationOutcomeEnum.ts +11 -0
  169. package/src/rewardsEligibility/enums/GrantRequestStatusEnum.ts +11 -0
  170. package/src/rewardsEligibility/enums/RewardsEligibilityErrorCodeEnum.ts +8 -0
  171. package/src/rewardsEligibility/enums/RunModeEnum.ts +4 -0
  172. package/src/rewardsEligibility/enums/RunStatusEnum.ts +9 -0
  173. package/src/rewardsEligibility/enums/TriggerTypeEnum.ts +5 -0
  174. package/src/rewardsEligibility/index.ts +16 -0
@@ -0,0 +1,21 @@
1
+ import { GrantItemStatusEnum } from '../../enums/GrantItemStatusEnum';
2
+ import { RewardChargeTo } from '../RewardChargeTo';
3
+ import { RewardCost } from '../RewardCost';
4
+ import { GrantAttemptResponse } from './GrantAttemptResponse';
5
+
6
+ export class GrantItemResponse {
7
+ itemKey: string;
8
+ catalogItemId: string;
9
+ status: GrantItemStatusEnum;
10
+ /** Solo si `status` es SKIPPED (ej. `DEPENDENCY_MISSING`, `ITEM_NOT_APPLICABLE`). */
11
+ skipReason?: string;
12
+ chargeTo: RewardChargeTo;
13
+ cost: RewardCost;
14
+ attemptCount: number;
15
+ /** Epoch en milisegundos; solo si `status` es GRANTED. */
16
+ grantedAt?: number;
17
+ /** Referencias del proveedor (ej. `{ transactionNumber }`). */
18
+ externalRef?: Record<string, string>;
19
+ /** Últimos intentos (máx. 5). */
20
+ attempts: GrantAttemptResponse[];
21
+ }
@@ -0,0 +1,24 @@
1
+ import { GrantRejectReasonEnum } from '../../enums/GrantRejectReasonEnum';
2
+ import { GrantStatusEnum } from '../../enums/GrantStatusEnum';
3
+ import { RewardSource } from '../RewardSource';
4
+ import { GrantItemResponse } from './GrantItemResponse';
5
+
6
+ /** Respuesta de `GET /grants/{id}`: estado de la entrega y de cada ítem (spec A 6.4). */
7
+ export class GrantResponse {
8
+ id: string;
9
+ directoryId: string;
10
+ packageId: string;
11
+ /** Versión del paquete congelada al crear la entrega. */
12
+ packageVersion: number;
13
+ source: RewardSource;
14
+ status: GrantStatusEnum;
15
+ /** Solo si `status` es REJECTED. */
16
+ rejectReason?: GrantRejectReasonEnum;
17
+ /** Solo si `rejectReason` es `INPUT_INVALID`: claves de los campos inválidos, `itemKey.inputKey` (spec A §6.2). */
18
+ invalidFields?: string[];
19
+ items: GrantItemResponse[];
20
+ /** Epoch en milisegundos. */
21
+ createdAt: number;
22
+ /** Epoch en milisegundos. */
23
+ updatedAt: number;
24
+ }
@@ -0,0 +1,13 @@
1
+ import { RewardCost } from '../RewardCost';
2
+ import { RewardDependency } from '../RewardDependency';
3
+
4
+ /** Una recompensa dentro del contrato de un paquete (spec A 6.3). */
5
+ export class PackageContractItem {
6
+ itemKey: string;
7
+ catalogItemId: string;
8
+ name: string;
9
+ description: string;
10
+ cost: RewardCost;
11
+ /** Lo que el llamador debe enviar en `inputs[itemKey]`. */
12
+ dependencies: RewardDependency[];
13
+ }
@@ -0,0 +1,14 @@
1
+ import { RewardStatusEnum } from '../../enums/RewardStatusEnum';
2
+ import { RewardCost } from '../RewardCost';
3
+ import { PackageContractItem } from './PackageContractItem';
4
+
5
+ /** Respuesta de `GET /packages/{id}`: el contrato de entrada del paquete (spec A 6.3). */
6
+ export class PackageContractResponse {
7
+ id: string;
8
+ name: string;
9
+ status: RewardStatusEnum;
10
+ version: number;
11
+ items: PackageContractItem[];
12
+ /** Costo total declarado del paquete, por moneda (sin conversión). */
13
+ totalCost: RewardCost[];
14
+ }
@@ -0,0 +1,5 @@
1
+ /** Qué pasa si falta una dependencia que se necesitaba (spec A 5.1). */
2
+ export enum DependencyIfMissingEnum {
3
+ REJECT = 'REJECT',
4
+ SKIP = 'SKIP',
5
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * `reason` de `GRANT_FAILED` (spec A 6.5). Las tres primeras son las de `GrantRejectReasonEnum`
3
+ * (entrega REJECTED); `ITEMS_FAILED` es una entrega FAILED: ningún ítem se entregó.
4
+ * Decisión P-2 aprobada.
5
+ */
6
+ export enum GrantFailedReasonEnum {
7
+ INPUT_INVALID = 'INPUT_INVALID',
8
+ PACKAGE_NOT_FOUND = 'PACKAGE_NOT_FOUND',
9
+ PACKAGE_INACTIVE = 'PACKAGE_INACTIVE',
10
+ ITEMS_FAILED = 'ITEMS_FAILED',
11
+ }
@@ -0,0 +1,6 @@
1
+ export enum GrantItemStatusEnum {
2
+ PENDING = 'PENDING',
3
+ GRANTED = 'GRANTED',
4
+ FAILED = 'FAILED',
5
+ SKIPPED = 'SKIPPED',
6
+ }
@@ -0,0 +1,6 @@
1
+ /** Por qué una solicitud quedó REJECTED (spec A 6.2). */
2
+ export enum GrantRejectReasonEnum {
3
+ INPUT_INVALID = 'INPUT_INVALID',
4
+ PACKAGE_NOT_FOUND = 'PACKAGE_NOT_FOUND',
5
+ PACKAGE_INACTIVE = 'PACKAGE_INACTIVE',
6
+ }
@@ -0,0 +1,8 @@
1
+ export enum GrantStatusEnum {
2
+ PENDING = 'PENDING',
3
+ IN_PROGRESS = 'IN_PROGRESS',
4
+ COMPLETED = 'COMPLETED',
5
+ PARTIAL = 'PARTIAL',
6
+ FAILED = 'FAILED',
7
+ REJECTED = 'REJECTED',
8
+ }
@@ -0,0 +1,7 @@
1
+ export enum ItemErrorCategoryEnum {
2
+ PROVIDER_UNAVAILABLE = 'PROVIDER_UNAVAILABLE',
3
+ REQUEST_INVALID = 'REQUEST_INVALID',
4
+ PROVIDER_REJECTED = 'PROVIDER_REJECTED',
5
+ INPUT_UNRESOLVABLE = 'INPUT_UNRESOLVABLE',
6
+ INTERNAL_ERROR = 'INTERNAL_ERROR',
7
+ }
@@ -0,0 +1,4 @@
1
+ export enum RewardStatusEnum {
2
+ ACTIVE = 'ACTIVE',
3
+ INACTIVE = 'INACTIVE',
4
+ }
@@ -0,0 +1,5 @@
1
+ /** Códigos de error de las lecturas privadas de rewards-business. */
2
+ export enum RewardsErrorCodeEnum {
3
+ PACKAGE_NOT_FOUND = 'PACKAGE_NOT_FOUND',
4
+ GRANT_NOT_FOUND = 'GRANT_NOT_FOUND',
5
+ }
@@ -0,0 +1,4 @@
1
+ export enum RewardsMessageTypeEnum {
2
+ GRANT_REQUESTED = 'GRANT_REQUESTED',
3
+ GRANT_FAILED = 'GRANT_FAILED',
4
+ }
@@ -0,0 +1,37 @@
1
+ //Enums
2
+ export * from './enums/RewardsMessageTypeEnum';
3
+ export * from './enums/GrantStatusEnum';
4
+ export * from './enums/GrantItemStatusEnum';
5
+ export * from './enums/GrantRejectReasonEnum';
6
+ export * from './enums/GrantFailedReasonEnum';
7
+ export * from './enums/ItemErrorCategoryEnum';
8
+ export * from './enums/RewardStatusEnum';
9
+ export * from './enums/DependencyIfMissingEnum';
10
+ export * from './enums/RewardsErrorCodeEnum';
11
+
12
+ //Types
13
+ export * from './types/RewardInputs';
14
+
15
+ //DTOs
16
+ export * from './dtos/RewardCost';
17
+ export * from './dtos/RewardChargeTo';
18
+ export * from './dtos/RewardDependency';
19
+
20
+ //Constants
21
+ export * from './constants/RewardsLimits';
22
+
23
+ //Validators
24
+ export * from './validators/IsRewardTags';
25
+ export * from './validators/IsRewardInputs';
26
+
27
+ //Messages (colas compartidas)
28
+ export * from './dtos/RewardSource';
29
+ export * from './dtos/GrantRequestedMessage';
30
+ export * from './dtos/GrantFailedMessage';
31
+
32
+ //Responses (lecturas privadas)
33
+ export * from './dtos/responses/PackageContractItem';
34
+ export * from './dtos/responses/PackageContractResponse';
35
+ export * from './dtos/responses/GrantAttemptResponse';
36
+ export * from './dtos/responses/GrantItemResponse';
37
+ export * from './dtos/responses/GrantResponse';
@@ -0,0 +1,4 @@
1
+ import { DynamicFormValue } from '../../dynamicForm/types/DynamicFormValue';
2
+
3
+ /** `inputs` de un pedido de entrega: `itemKey → inputKey → valor` (spec A 6.1). */
4
+ export type RewardInputs = Record<string, Record<string, DynamicFormValue>>;
@@ -0,0 +1,18 @@
1
+ import { ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator';
2
+ import { JsonValue } from '../../common/types/JsonValue';
3
+ import { isDynamicFormValue, isPlainObject } from '../../dynamicForm/helpers/isDynamicFormValue';
4
+
5
+ /** `inputs`: `itemKey → inputKey → valor` (dos niveles exactos; la hoja es un DynamicFormValue). */
6
+ @ValidatorConstraint({ name: 'IsRewardInputs', async: false })
7
+ export class IsRewardInputs implements ValidatorConstraintInterface {
8
+ validate(value: JsonValue, _args: ValidationArguments): boolean {
9
+ if (!isPlainObject(value)) return false;
10
+ return Object.values(value).every(
11
+ (porItem) => isPlainObject(porItem) && Object.values(porItem).every(isDynamicFormValue),
12
+ );
13
+ }
14
+
15
+ defaultMessage(_args: ValidationArguments): string {
16
+ return 'inputs debe ser un mapa itemKey → (inputKey → string | number | boolean | {from, to})';
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ import { ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator';
2
+ import { JsonValue } from '../../common/types/JsonValue';
3
+ import { isPlainObject } from '../../dynamicForm/helpers/isDynamicFormValue';
4
+ import { REWARD_TAGS_MAX_KEYS } from '../constants/RewardsLimits';
5
+
6
+ /** `source.tags`: mapa texto → texto, máximo `REWARD_TAGS_MAX_KEYS` llaves. */
7
+ @ValidatorConstraint({ name: 'IsRewardTags', async: false })
8
+ export class IsRewardTags implements ValidatorConstraintInterface {
9
+ validate(value: JsonValue, _args: ValidationArguments): boolean {
10
+ if (!isPlainObject(value)) return false;
11
+ const entries = Object.entries(value);
12
+ return entries.length <= REWARD_TAGS_MAX_KEYS && entries.every(([, tag]) => typeof tag === 'string');
13
+ }
14
+
15
+ defaultMessage(_args: ValidationArguments): string {
16
+ return `tags debe ser un mapa texto → texto de máximo ${REWARD_TAGS_MAX_KEYS} llaves`;
17
+ }
18
+ }
@@ -0,0 +1,12 @@
1
+ import { EvaluationOutcomeEnum } from '../enums/EvaluationOutcomeEnum';
2
+ import { GrantRequestStatusEnum } from '../enums/GrantRequestStatusEnum';
3
+
4
+ /** Resultado de una evaluación suscrita al evento (una corrida con lote de 1). */
5
+ export class EventRunResult {
6
+ evaluationId: string;
7
+ runId: string;
8
+ outcome: EvaluationOutcomeEnum;
9
+ grantStatus: GrantRequestStatusEnum;
10
+ /** true si el `idempotencyKey` ya había creado esta corrida. */
11
+ idempotentReplay: boolean;
12
+ }
@@ -0,0 +1,15 @@
1
+ import { Expose } from 'class-transformer';
2
+ import { IsNotEmpty, IsString } from 'class-validator';
3
+
4
+ /** Quién emite el evento. El validador no interpreta `reference`. */
5
+ export class EventSource {
6
+ @Expose()
7
+ @IsString()
8
+ @IsNotEmpty()
9
+ service!: string;
10
+
11
+ @Expose()
12
+ @IsString()
13
+ @IsNotEmpty()
14
+ reference!: string;
15
+ }
@@ -0,0 +1,23 @@
1
+ import { RunModeEnum } from '../enums/RunModeEnum';
2
+ import { RunStatusEnum } from '../enums/RunStatusEnum';
3
+ import { TriggerTypeEnum } from '../enums/TriggerTypeEnum';
4
+ import { RunCounts } from './RunCounts';
5
+ import { RunResultItem } from './RunResultItem';
6
+
7
+ /** Respuesta de `GET /runs/{id}` (spec B 6.2). */
8
+ export class GetRunResponse {
9
+ runId: string;
10
+ evaluationId: string;
11
+ trigger: TriggerTypeEnum;
12
+ mode: RunModeEnum;
13
+ status: RunStatusEnum;
14
+ counts: RunCounts;
15
+ /** Una página de resultados. */
16
+ results: RunResultItem[];
17
+ /** Presente si hay más resultados. */
18
+ nextToken?: string;
19
+ /** Epoch en milisegundos. */
20
+ createdAt: number;
21
+ /** Epoch en milisegundos. */
22
+ updatedAt: number;
23
+ }
@@ -0,0 +1,32 @@
1
+ import { Expose, Type } from 'class-transformer';
2
+ import { IsNotEmpty, IsString, Validate, ValidateNested } from 'class-validator';
3
+ import { DynamicFormValue } from '../../dynamicForm/types/DynamicFormValue';
4
+ import { IsDynamicFormValues } from '../../dynamicForm/validators/IsDynamicFormValues';
5
+ import { EventSource } from './EventSource';
6
+
7
+ /**
8
+ * Cuerpo de `POST /events` (spec B 6.1). El emisor informa qué pasó y quién participó; NO decide
9
+ * la elegibilidad (E3). Parsear con `excludeExtraneousValues: true`: cualquier campo extra
10
+ * (p. ej. `prefetchedFacts`) se descarta.
11
+ */
12
+ export class PostEventRequest {
13
+ @Expose()
14
+ @IsString()
15
+ @IsNotEmpty()
16
+ eventKey!: string;
17
+
18
+ @Expose()
19
+ @IsString()
20
+ @IsNotEmpty()
21
+ idempotencyKey!: string;
22
+
23
+ @Expose()
24
+ @ValidateNested()
25
+ @Type(() => EventSource)
26
+ source!: EventSource;
27
+
28
+ /** Los `fields` del tipo de evento (`RewardEventType_GT`), con su valor. */
29
+ @Expose()
30
+ @Validate(IsDynamicFormValues)
31
+ inputs!: Record<string, DynamicFormValue>;
32
+ }
@@ -0,0 +1,6 @@
1
+ import { EventRunResult } from './EventRunResult';
2
+
3
+ /** Respuesta 202 de `POST /events`; `runs` vacío si ninguna evaluación escucha el evento. */
4
+ export class PostEventResponse {
5
+ runs: EventRunResult[];
6
+ }
@@ -0,0 +1,12 @@
1
+ /** Conteos de una corrida (mismos nombres que las métricas, spec B 5.7). */
2
+ export class RunCounts {
3
+ evaluated: number;
4
+ match: number;
5
+ noMatch: number;
6
+ error: number;
7
+ alreadyGranted: number;
8
+ quotaExhausted: number;
9
+ excluded: number;
10
+ requested: number;
11
+ requestFailed: number;
12
+ }
@@ -0,0 +1,17 @@
1
+ import { EvaluationOutcomeEnum } from '../enums/EvaluationOutcomeEnum';
2
+ import { GrantRequestStatusEnum } from '../enums/GrantRequestStatusEnum';
3
+
4
+ /** Un resultado por sujeto, SIN traza (la traza es del backoffice). Asumido hasta cerrar P-7. */
5
+ export class RunResultItem {
6
+ subjectKey: string;
7
+ beneficiaryDirectoryId: string;
8
+ campaignId: string;
9
+ evaluationId: string;
10
+ packageId: string;
11
+ outcome: EvaluationOutcomeEnum;
12
+ grantStatus: GrantRequestStatusEnum;
13
+ /** `grantIdFor("rewards-eligibility", idempotencyKey)`; cruza con `GET /grants/{id}` de rewards. */
14
+ grantId?: string;
15
+ /** Solo si `outcome` es ERROR. */
16
+ errorMessage?: string;
17
+ }
@@ -0,0 +1,11 @@
1
+ export enum EvaluationOutcomeEnum {
2
+ MATCH = 'MATCH',
3
+ NO_MATCH = 'NO_MATCH',
4
+ ERROR = 'ERROR',
5
+ /** La política de frecuencia lo bloqueó. */
6
+ ALREADY_GRANTED = 'ALREADY_GRANTED',
7
+ /** Calificó, pero la campaña no tenía cupo. */
8
+ QUOTA_EXHAUSTED = 'QUOTA_EXHAUSTED',
9
+ /** El operador lo sacó al aprobar. */
10
+ EXCLUDED = 'EXCLUDED',
11
+ }
@@ -0,0 +1,11 @@
1
+ export enum GrantRequestStatusEnum {
2
+ NOT_APPLICABLE = 'NOT_APPLICABLE',
3
+ PENDING_APPROVAL = 'PENDING_APPROVAL',
4
+ /** Reservado, esperando su tramo de publicación. */
5
+ QUEUED = 'QUEUED',
6
+ /** Publicado en RewardsGrantQueue al instante (en línea). */
7
+ REQUESTED = 'REQUESTED',
8
+ /** La publicación falló o llegó GRANT_FAILED. */
9
+ REQUEST_FAILED = 'REQUEST_FAILED',
10
+ CANCELLED = 'CANCELLED',
11
+ }
@@ -0,0 +1,8 @@
1
+ export enum RewardsEligibilityErrorCodeEnum {
2
+ /** 400: faltan campos obligatorios del evento o tienen tipo inválido. */
3
+ INPUT_INVALID = 'INPUT_INVALID',
4
+ /** 404: el eventKey no existe o está inactivo. */
5
+ EVENT_TYPE_NOT_FOUND = 'EVENT_TYPE_NOT_FOUND',
6
+ /** 404: GET /runs/{id} sin corrida. */
7
+ RUN_NOT_FOUND = 'RUN_NOT_FOUND',
8
+ }
@@ -0,0 +1,4 @@
1
+ export enum RunModeEnum {
2
+ LIVE = 'LIVE',
3
+ SIMULATION = 'SIMULATION',
4
+ }
@@ -0,0 +1,9 @@
1
+ export enum RunStatusEnum {
2
+ RUNNING = 'RUNNING',
3
+ AWAITING_APPROVAL = 'AWAITING_APPROVAL',
4
+ PUBLISHING = 'PUBLISHING',
5
+ COMPLETED = 'COMPLETED',
6
+ PARTIAL = 'PARTIAL',
7
+ FAILED = 'FAILED',
8
+ REJECTED = 'REJECTED',
9
+ }
@@ -0,0 +1,5 @@
1
+ export enum TriggerTypeEnum {
2
+ EVENT = 'EVENT',
3
+ MANUAL = 'MANUAL',
4
+ CRON = 'CRON',
5
+ }
@@ -0,0 +1,16 @@
1
+ //Enums
2
+ export * from './enums/EvaluationOutcomeEnum';
3
+ export * from './enums/GrantRequestStatusEnum';
4
+ export * from './enums/RunStatusEnum';
5
+ export * from './enums/RunModeEnum';
6
+ export * from './enums/TriggerTypeEnum';
7
+ export * from './enums/RewardsEligibilityErrorCodeEnum';
8
+
9
+ //DTOs
10
+ export * from './dtos/EventSource';
11
+ export * from './dtos/PostEventRequest';
12
+ export * from './dtos/EventRunResult';
13
+ export * from './dtos/PostEventResponse';
14
+ export * from './dtos/RunCounts';
15
+ export * from './dtos/RunResultItem';
16
+ export * from './dtos/GetRunResponse';