@misterhomer1992/miit-bot-payment 1.1.6 → 2.0.4

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 (248) hide show
  1. package/dist/config/ConfigurationManager.d.ts +64 -0
  2. package/dist/config/ConfigurationManager.d.ts.map +1 -0
  3. package/dist/config/ConfigurationManager.js +144 -0
  4. package/dist/config/ConfigurationManager.js.map +1 -0
  5. package/dist/config/defaults.d.ts +18 -0
  6. package/dist/config/defaults.d.ts.map +1 -0
  7. package/dist/config/defaults.js +26 -0
  8. package/dist/config/defaults.js.map +1 -0
  9. package/dist/config/environment.d.ts +38 -0
  10. package/dist/config/environment.d.ts.map +1 -0
  11. package/dist/config/environment.js +91 -0
  12. package/dist/config/environment.js.map +1 -0
  13. package/dist/config/index.d.ts +5 -0
  14. package/dist/config/index.d.ts.map +1 -0
  15. package/dist/config/index.js +18 -0
  16. package/dist/config/index.js.map +1 -0
  17. package/dist/config/types.d.ts +53 -0
  18. package/dist/config/types.d.ts.map +1 -0
  19. package/dist/config/types.js +3 -0
  20. package/dist/config/types.js.map +1 -0
  21. package/dist/index.d.ts +21 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +23 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/modules/cache/InMemoryCache.d.ts +17 -0
  26. package/dist/modules/cache/InMemoryCache.d.ts.map +1 -0
  27. package/dist/modules/cache/InMemoryCache.js +77 -0
  28. package/dist/modules/cache/InMemoryCache.js.map +1 -0
  29. package/dist/modules/cache/index.d.ts +3 -0
  30. package/dist/modules/cache/index.d.ts.map +1 -0
  31. package/dist/modules/cache/index.js +19 -0
  32. package/dist/modules/cache/index.js.map +1 -0
  33. package/dist/modules/cache/types.d.ts +52 -0
  34. package/dist/modules/cache/types.d.ts.map +1 -0
  35. package/dist/modules/cache/types.js +3 -0
  36. package/dist/modules/cache/types.js.map +1 -0
  37. package/dist/modules/errors/index.d.ts +2 -0
  38. package/dist/modules/errors/index.d.ts.map +1 -0
  39. package/dist/modules/errors/index.js +19 -0
  40. package/dist/modules/errors/index.js.map +1 -0
  41. package/dist/modules/errors/types.d.ts +112 -0
  42. package/dist/modules/errors/types.d.ts.map +1 -0
  43. package/dist/modules/errors/types.js +174 -0
  44. package/dist/modules/errors/types.js.map +1 -0
  45. package/dist/modules/payments/api.d.ts +63 -1
  46. package/dist/modules/payments/api.d.ts.map +1 -1
  47. package/dist/modules/payments/api.js +103 -1
  48. package/dist/modules/payments/api.js.map +1 -1
  49. package/dist/modules/payments/const.d.ts.map +1 -1
  50. package/dist/modules/payments/const.js +1 -0
  51. package/dist/modules/payments/const.js.map +1 -1
  52. package/dist/modules/payments/index.d.ts +8 -0
  53. package/dist/modules/payments/index.d.ts.map +1 -1
  54. package/dist/modules/payments/index.js +8 -0
  55. package/dist/modules/payments/index.js.map +1 -1
  56. package/dist/modules/payments/service.d.ts +42 -2
  57. package/dist/modules/payments/service.d.ts.map +1 -1
  58. package/dist/modules/payments/service.js +132 -3
  59. package/dist/modules/payments/service.js.map +1 -1
  60. package/dist/modules/payments/subscription-check-webhook.handler.d.ts +85 -0
  61. package/dist/modules/payments/subscription-check-webhook.handler.d.ts.map +1 -0
  62. package/dist/modules/payments/subscription-check-webhook.handler.js +155 -0
  63. package/dist/modules/payments/subscription-check-webhook.handler.js.map +1 -0
  64. package/dist/modules/payments/subscription-check-webhook.service.d.ts +59 -0
  65. package/dist/modules/payments/subscription-check-webhook.service.d.ts.map +1 -0
  66. package/dist/modules/payments/subscription-check-webhook.service.js +330 -0
  67. package/dist/modules/payments/subscription-check-webhook.service.js.map +1 -0
  68. package/dist/modules/payments/subscription-check-webhook.types.d.ts +25 -0
  69. package/dist/modules/payments/subscription-check-webhook.types.d.ts.map +1 -0
  70. package/dist/modules/payments/subscription-check-webhook.types.js +3 -0
  71. package/dist/modules/payments/subscription-check-webhook.types.js.map +1 -0
  72. package/dist/modules/payments/types.d.ts +69 -2
  73. package/dist/modules/payments/types.d.ts.map +1 -1
  74. package/dist/modules/payments/utils.d.ts +151 -5
  75. package/dist/modules/payments/utils.d.ts.map +1 -1
  76. package/dist/modules/payments/utils.js +253 -9
  77. package/dist/modules/payments/utils.js.map +1 -1
  78. package/dist/modules/payments/wayforpay.service.d.ts +39 -0
  79. package/dist/modules/payments/wayforpay.service.d.ts.map +1 -0
  80. package/dist/modules/payments/wayforpay.service.js +217 -0
  81. package/dist/modules/payments/wayforpay.service.js.map +1 -0
  82. package/dist/modules/payments/wayforpay.types.d.ts +115 -0
  83. package/dist/modules/payments/wayforpay.types.d.ts.map +1 -0
  84. package/dist/modules/payments/wayforpay.types.js +3 -0
  85. package/dist/modules/payments/wayforpay.types.js.map +1 -0
  86. package/dist/modules/payments/webhook.handler.d.ts +98 -0
  87. package/dist/modules/payments/webhook.handler.d.ts.map +1 -0
  88. package/dist/modules/payments/webhook.handler.js +153 -0
  89. package/dist/modules/payments/webhook.handler.js.map +1 -0
  90. package/dist/modules/payments/webhook.service.d.ts +99 -0
  91. package/dist/modules/payments/webhook.service.d.ts.map +1 -0
  92. package/dist/modules/payments/webhook.service.js +672 -0
  93. package/dist/modules/payments/webhook.service.js.map +1 -0
  94. package/dist/modules/payments/webhook.types.d.ts +35 -0
  95. package/dist/modules/payments/webhook.types.d.ts.map +1 -0
  96. package/dist/modules/payments/webhook.types.js +3 -0
  97. package/dist/modules/payments/webhook.types.js.map +1 -0
  98. package/dist/modules/subscription/change.service.d.ts +80 -0
  99. package/dist/modules/subscription/change.service.d.ts.map +1 -0
  100. package/dist/modules/subscription/change.service.js +226 -0
  101. package/dist/modules/subscription/change.service.js.map +1 -0
  102. package/dist/modules/subscription/index.d.ts +2 -0
  103. package/dist/modules/subscription/index.d.ts.map +1 -1
  104. package/dist/modules/subscription/index.js +2 -0
  105. package/dist/modules/subscription/index.js.map +1 -1
  106. package/dist/modules/subscription/service.d.ts +8 -1
  107. package/dist/modules/subscription/service.d.ts.map +1 -1
  108. package/dist/modules/subscription/service.js +59 -2
  109. package/dist/modules/subscription/service.js.map +1 -1
  110. package/dist/modules/subscription/status-check.handler.d.ts +117 -0
  111. package/dist/modules/subscription/status-check.handler.d.ts.map +1 -0
  112. package/dist/modules/subscription/status-check.handler.js +164 -0
  113. package/dist/modules/subscription/status-check.handler.js.map +1 -0
  114. package/dist/modules/subscription/types.d.ts +37 -1
  115. package/dist/modules/subscription/types.d.ts.map +1 -1
  116. package/dist/modules/subscriptionPlan/const.d.ts +5 -0
  117. package/dist/modules/subscriptionPlan/const.d.ts.map +1 -0
  118. package/dist/modules/subscriptionPlan/const.js +106 -0
  119. package/dist/modules/subscriptionPlan/const.js.map +1 -0
  120. package/dist/modules/subscriptionPlan/index.d.ts +5 -0
  121. package/dist/modules/subscriptionPlan/index.d.ts.map +1 -0
  122. package/dist/modules/subscriptionPlan/index.js +21 -0
  123. package/dist/modules/subscriptionPlan/index.js.map +1 -0
  124. package/dist/modules/subscriptionPlan/repository.d.ts +22 -0
  125. package/dist/modules/subscriptionPlan/repository.d.ts.map +1 -0
  126. package/dist/modules/subscriptionPlan/repository.js +95 -0
  127. package/dist/modules/subscriptionPlan/repository.js.map +1 -0
  128. package/dist/modules/subscriptionPlan/service.d.ts +21 -0
  129. package/dist/modules/subscriptionPlan/service.d.ts.map +1 -0
  130. package/dist/modules/subscriptionPlan/service.js +128 -0
  131. package/dist/modules/subscriptionPlan/service.js.map +1 -0
  132. package/dist/modules/subscriptionPlan/types.d.ts +40 -0
  133. package/dist/modules/subscriptionPlan/types.d.ts.map +1 -0
  134. package/dist/modules/subscriptionPlan/types.js +3 -0
  135. package/dist/modules/subscriptionPlan/types.js.map +1 -0
  136. package/dist/modules/token/const.d.ts +7 -0
  137. package/dist/modules/token/const.d.ts.map +1 -0
  138. package/dist/modules/token/const.js +66 -0
  139. package/dist/modules/token/const.js.map +1 -0
  140. package/dist/modules/token/index.d.ts +4 -0
  141. package/dist/modules/token/index.d.ts.map +1 -0
  142. package/dist/modules/token/index.js +20 -0
  143. package/dist/modules/token/index.js.map +1 -0
  144. package/dist/modules/token/service.d.ts +46 -0
  145. package/dist/modules/token/service.d.ts.map +1 -0
  146. package/dist/modules/token/service.js +249 -0
  147. package/dist/modules/token/service.js.map +1 -0
  148. package/dist/modules/token/types.d.ts +109 -0
  149. package/dist/modules/token/types.d.ts.map +1 -0
  150. package/dist/modules/token/types.js +3 -0
  151. package/dist/modules/token/types.js.map +1 -0
  152. package/dist/modules/tokenPack/const.d.ts +4 -0
  153. package/dist/modules/tokenPack/const.d.ts.map +1 -0
  154. package/dist/modules/tokenPack/const.js +10 -0
  155. package/dist/modules/tokenPack/const.js.map +1 -0
  156. package/dist/modules/tokenPack/index.d.ts +5 -0
  157. package/dist/modules/tokenPack/index.d.ts.map +1 -0
  158. package/dist/modules/tokenPack/index.js +21 -0
  159. package/dist/modules/tokenPack/index.js.map +1 -0
  160. package/dist/modules/tokenPack/repository.d.ts +32 -0
  161. package/dist/modules/tokenPack/repository.d.ts.map +1 -0
  162. package/dist/modules/tokenPack/repository.js +103 -0
  163. package/dist/modules/tokenPack/repository.js.map +1 -0
  164. package/dist/modules/tokenPack/service.d.ts +28 -0
  165. package/dist/modules/tokenPack/service.d.ts.map +1 -0
  166. package/dist/modules/tokenPack/service.js +106 -0
  167. package/dist/modules/tokenPack/service.js.map +1 -0
  168. package/dist/modules/tokenPack/types.d.ts +124 -0
  169. package/dist/modules/tokenPack/types.d.ts.map +1 -0
  170. package/dist/modules/tokenPack/types.js +3 -0
  171. package/dist/modules/tokenPack/types.js.map +1 -0
  172. package/package.json +9 -5
  173. package/src/config/ConfigurationManager.ts +159 -0
  174. package/src/config/defaults.ts +27 -0
  175. package/src/config/environment.ts +94 -0
  176. package/src/config/index.ts +22 -0
  177. package/src/config/types.ts +56 -0
  178. package/src/index.ts +29 -0
  179. package/src/modules/cache/InMemoryCache.ts +98 -0
  180. package/src/modules/cache/index.ts +2 -0
  181. package/src/modules/cache/types.ts +60 -0
  182. package/src/modules/cancellableAPI/utils.ts +60 -0
  183. package/src/modules/errors/index.ts +16 -0
  184. package/src/modules/errors/types.ts +201 -0
  185. package/src/modules/invoice/const.ts +7 -0
  186. package/src/modules/invoice/index.ts +4 -0
  187. package/src/modules/invoice/repository.ts +52 -0
  188. package/src/modules/invoice/service.ts +44 -0
  189. package/src/modules/invoice/types.ts +47 -0
  190. package/src/modules/logger/types.ts +8 -0
  191. package/src/modules/network/utils.ts +24 -0
  192. package/src/modules/payments/api.ts +289 -0
  193. package/src/modules/payments/const.ts +11 -0
  194. package/src/modules/payments/index.ts +14 -0
  195. package/src/modules/payments/repository.ts +125 -0
  196. package/src/modules/payments/service.test.ts +400 -0
  197. package/src/modules/payments/service.ts +365 -0
  198. package/src/modules/payments/subscription-check-webhook.handler.integration.test.ts +935 -0
  199. package/src/modules/payments/subscription-check-webhook.handler.ts +211 -0
  200. package/src/modules/payments/subscription-check-webhook.service.ts +398 -0
  201. package/src/modules/payments/subscription-check-webhook.types.ts +29 -0
  202. package/src/modules/payments/types.ts +193 -0
  203. package/src/modules/payments/utils.ts +428 -0
  204. package/src/modules/payments/wayforpay.service.test.ts +375 -0
  205. package/src/modules/payments/wayforpay.service.ts +284 -0
  206. package/src/modules/payments/wayforpay.types.ts +138 -0
  207. package/src/modules/payments/webhook.handler.integration.test.ts +975 -0
  208. package/src/modules/payments/webhook.handler.ts +219 -0
  209. package/src/modules/payments/webhook.service.ts +812 -0
  210. package/src/modules/payments/webhook.types.ts +38 -0
  211. package/src/modules/subscription/change.service.ts +317 -0
  212. package/src/modules/subscription/const.ts +9 -0
  213. package/src/modules/subscription/index.ts +5 -0
  214. package/src/modules/subscription/repository.ts +277 -0
  215. package/src/modules/subscription/service.test.ts +665 -0
  216. package/src/modules/subscription/service.ts +328 -0
  217. package/src/modules/subscription/status-check.handler.ts +254 -0
  218. package/src/modules/subscription/types.ts +267 -0
  219. package/src/modules/subscription/utils.ts +5 -0
  220. package/src/modules/subscriptionPlan/const.ts +106 -0
  221. package/src/modules/subscriptionPlan/index.ts +4 -0
  222. package/src/modules/subscriptionPlan/repository.ts +129 -0
  223. package/src/modules/subscriptionPlan/service.test.ts +401 -0
  224. package/src/modules/subscriptionPlan/service.ts +148 -0
  225. package/src/modules/subscriptionPlan/types.ts +67 -0
  226. package/src/modules/token/const.ts +64 -0
  227. package/src/modules/token/index.ts +3 -0
  228. package/src/modules/token/service.test.ts +499 -0
  229. package/src/modules/token/service.ts +297 -0
  230. package/src/modules/token/types.ts +124 -0
  231. package/src/modules/tokenPack/const.ts +9 -0
  232. package/src/modules/tokenPack/index.ts +4 -0
  233. package/src/modules/tokenPack/repository.ts +144 -0
  234. package/src/modules/tokenPack/service.ts +119 -0
  235. package/src/modules/tokenPack/types.ts +131 -0
  236. package/src/modules/user/index.ts +3 -0
  237. package/src/modules/user/types.ts +143 -0
  238. package/src/modules/user/userRepository.ts +64 -0
  239. package/src/modules/user/userService.ts +68 -0
  240. package/src/types/extend-express.d.ts +16 -0
  241. package/src/types/function.ts +5 -0
  242. package/src/types/utilities.ts +22 -0
  243. package/src/utils.ts +53 -0
  244. package/tsconfig.json +29 -0
  245. package/dist/modules/subscription/subscriptionPlan.d.ts +0 -4
  246. package/dist/modules/subscription/subscriptionPlan.d.ts.map +0 -1
  247. package/dist/modules/subscription/subscriptionPlan.js +0 -67
  248. package/dist/modules/subscription/subscriptionPlan.js.map +0 -1
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Token pack plan definition for one-time purchase.
3
+ */
4
+ type TokenPackPlan = {
5
+ /** Unique identifier for the token pack plan */
6
+ id: string;
7
+ /** Translation key for the pack title */
8
+ titleCode: string;
9
+ /** Translation key for the pack description */
10
+ descriptionCode: string;
11
+ /** Number of tokens in the pack */
12
+ tokens: number;
13
+ /** Price amount */
14
+ amount: number;
15
+ /** Currency for the price */
16
+ currency: 'UAH' | 'USD';
17
+ /** Whether this pack is currently available for purchase */
18
+ isActive: boolean;
19
+ };
20
+ /**
21
+ * Result of creating a purchase URL.
22
+ */
23
+ type PurchaseUrlResult = {
24
+ /** The payment URL to redirect the user to */
25
+ url: string;
26
+ /** Unique order reference for tracking the payment */
27
+ orderReference: string;
28
+ };
29
+ /**
30
+ * Parameters for creating a token pack purchase URL.
31
+ */
32
+ type CreatePurchaseUrlParams = {
33
+ userId: string;
34
+ platform: string;
35
+ packId: string;
36
+ language?: 'EN' | 'UA';
37
+ returnUrl?: string;
38
+ };
39
+ /**
40
+ * Parameters for adding tokens to a user's balance.
41
+ */
42
+ type AddTokensParams = {
43
+ userId: string;
44
+ platform: string;
45
+ packId: string;
46
+ tokens: number;
47
+ };
48
+ /**
49
+ * Parameters for deducting tokens from a user's balance.
50
+ */
51
+ type DeductTokensParams = {
52
+ userId: string;
53
+ platform: string;
54
+ amount: number;
55
+ };
56
+ /**
57
+ * Token balance information for a user.
58
+ */
59
+ type TokenBalance = {
60
+ /** Total available tokens across all active packs */
61
+ available: number;
62
+ /** List of active token packs with remaining tokens */
63
+ packs: {
64
+ id: string;
65
+ packId: string;
66
+ tokensRemaining: number;
67
+ purchasedAt: string;
68
+ }[];
69
+ };
70
+ /**
71
+ * Interface for token service operations.
72
+ * Provides methods for token pack management and balance operations.
73
+ */
74
+ interface ITokenService {
75
+ /**
76
+ * Returns all available token pack plans for purchase.
77
+ * @returns Array of active token pack plans
78
+ */
79
+ getAvailablePacks(): TokenPackPlan[];
80
+ /**
81
+ * Creates a one-time payment URL for purchasing a token pack.
82
+ * @param params - Purchase parameters
83
+ * @returns Promise resolving to payment URL and order reference
84
+ */
85
+ createPurchaseUrl(params: CreatePurchaseUrlParams): Promise<PurchaseUrlResult | null>;
86
+ /**
87
+ * Adds tokens to a user's balance by creating a new token pack.
88
+ * Called after successful payment confirmation.
89
+ * @param params - Token addition parameters
90
+ */
91
+ addTokensToUser(params: AddTokensParams): Promise<void>;
92
+ /**
93
+ * Deducts tokens from a user's available balance.
94
+ * Deducts from oldest packs first (FIFO).
95
+ * @param params - Deduction parameters
96
+ */
97
+ deductTokens(params: DeductTokensParams): Promise<void>;
98
+ /**
99
+ * Gets the current token balance for a user.
100
+ * @param params - User identification parameters
101
+ * @returns Token balance information
102
+ */
103
+ getBalance(params: {
104
+ userId: string;
105
+ platform: string;
106
+ }): Promise<TokenBalance>;
107
+ }
108
+ export type { TokenPackPlan, PurchaseUrlResult, CreatePurchaseUrlParams, AddTokensParams, DeductTokensParams, TokenBalance, ITokenService, };
109
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/token/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,aAAa,GAAG;IACjB,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,eAAe,EAAE,MAAM,CAAC;IACxB,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;IACxB,4DAA4D;IAC5D,QAAQ,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,KAAK,iBAAiB,GAAG;IACrB,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,cAAc,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,KAAK,uBAAuB,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,KAAK,eAAe,GAAG;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,KAAK,kBAAkB,GAAG;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,KAAK,YAAY,GAAG;IAChB,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,KAAK,EAAE;QACH,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,EAAE,MAAM,CAAC;QACxB,WAAW,EAAE,MAAM,CAAC;KACvB,EAAE,CAAC;CACP,CAAC;AAEF;;;GAGG;AACH,UAAU,aAAa;IACnB;;;OAGG;IACH,iBAAiB,IAAI,aAAa,EAAE,CAAC;IAErC;;;;OAIG;IACH,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAEtF;;;;OAIG;IACH,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;;;OAIG;IACH,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACnF;AAED,YAAY,EACR,aAAa,EACb,iBAAiB,EACjB,uBAAuB,EACvB,eAAe,EACf,kBAAkB,EAClB,YAAY,EACZ,aAAa,GAChB,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/token/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { TokenPackEntity } from './types';
2
+ declare const DEFAULT_TOKEN_PACK_ENTITY: Partial<TokenPackEntity>;
3
+ export { DEFAULT_TOKEN_PACK_ENTITY };
4
+ //# sourceMappingURL=const.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.d.ts","sourceRoot":"","sources":["../../../src/modules/tokenPack/const.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,QAAA,MAAM,yBAAyB,EAAE,OAAO,CAAC,eAAe,CAIvD,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_TOKEN_PACK_ENTITY = void 0;
4
+ const DEFAULT_TOKEN_PACK_ENTITY = {
5
+ status: 'active',
6
+ platform: 'telegram',
7
+ provider: 'wayforpay',
8
+ };
9
+ exports.DEFAULT_TOKEN_PACK_ENTITY = DEFAULT_TOKEN_PACK_ENTITY;
10
+ //# sourceMappingURL=const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/modules/tokenPack/const.ts"],"names":[],"mappings":";;;AAEA,MAAM,yBAAyB,GAA6B;IACxD,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,WAAW;CACxB,CAAC;AAEO,8DAAyB"}
@@ -0,0 +1,5 @@
1
+ export * from './types';
2
+ export * from './service';
3
+ export * from './repository';
4
+ export * from './const';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/tokenPack/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./service"), exports);
19
+ __exportStar(require("./repository"), exports);
20
+ __exportStar(require("./const"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/tokenPack/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,4CAA0B;AAC1B,+CAA6B;AAC7B,0CAAwB"}
@@ -0,0 +1,32 @@
1
+ import { FieldValue, Firestore } from 'firebase-admin/firestore';
2
+ import { TokenPackEntity, TokenPackFieldPath, ITokenPackRepository } from './types';
3
+ export type UpdateDBTokenPackFields = [
4
+ TokenPackFieldPath,
5
+ FieldValue | string | number | boolean | Date | [] | {}
6
+ ][];
7
+ export declare class TokenPackRepository implements ITokenPackRepository {
8
+ private readonly db;
9
+ private readonly collectionName;
10
+ constructor({ db }?: {
11
+ db?: Firestore;
12
+ });
13
+ getById(id: string): Promise<TokenPackEntity | null>;
14
+ getByUser(params: {
15
+ userId: string;
16
+ platform: string;
17
+ status?: TokenPackEntity['status'] | TokenPackEntity['status'][];
18
+ }): Promise<TokenPackEntity[]>;
19
+ create(params: Omit<TokenPackEntity, 'id' | 'status' | 'tokensRemaining'>): Promise<TokenPackEntity>;
20
+ updateFieldsById(params: {
21
+ id: string;
22
+ fields: UpdateDBTokenPackFields;
23
+ }): Promise<void>;
24
+ deductTokens(params: {
25
+ id: string;
26
+ amount: number;
27
+ }): Promise<void>;
28
+ getExpiredActiveTokenPacks(): Promise<TokenPackEntity[]>;
29
+ private mapDocumentToEntity;
30
+ private buildUpdateObject;
31
+ }
32
+ //# sourceMappingURL=repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../src/modules/tokenPack/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAuC,MAAM,0BAA0B,CAAC;AACtG,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGpF,MAAM,MAAM,uBAAuB,GAAG;IAClC,kBAAkB;IAClB,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE;CAC1D,EAAE,CAAC;AAEJ,qBAAa,mBAAoB,YAAW,oBAAoB;IAC5D,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAY;IAC/B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgB;gBAEnC,EAAE,EAAE,EAAE,GAAE;QAAE,EAAE,CAAC,EAAE,SAAS,CAAA;KAAO;IAI9B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAUpD,SAAS,CAAC,MAAM,EAAE;QAC3B,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;KACpE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAyBjB,MAAM,CACf,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,QAAQ,GAAG,iBAAiB,CAAC,GACnE,OAAO,CAAC,eAAe,CAAC;IAed,gBAAgB,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,uBAAuB,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAQxF,YAAY,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BnE,0BAA0B,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAgBrE,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,iBAAiB;CAS5B"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenPackRepository = void 0;
4
+ const firestore_1 = require("firebase-admin/firestore");
5
+ const utils_1 = require("../../utils");
6
+ class TokenPackRepository {
7
+ constructor({ db } = {}) {
8
+ this.collectionName = 'tokenPacks';
9
+ this.db = db || (0, firestore_1.getFirestore)();
10
+ }
11
+ async getById(id) {
12
+ const doc = await this.db.collection(this.collectionName).doc(id).get();
13
+ if (!doc.exists) {
14
+ return null;
15
+ }
16
+ return this.mapDocumentToEntity(doc);
17
+ }
18
+ async getByUser(params) {
19
+ const { userId, platform } = params;
20
+ let query = this.db
21
+ .collection(this.collectionName)
22
+ .where('platform', '==', platform)
23
+ .where('userId', '==', userId);
24
+ if (!(0, utils_1.isUndefined)(params.status)) {
25
+ if (Array.isArray(params.status)) {
26
+ query = query.where('status', 'in', params.status);
27
+ }
28
+ else {
29
+ query = query.where('status', '==', params.status);
30
+ }
31
+ }
32
+ const querySnapshot = await query.get();
33
+ if (querySnapshot.empty) {
34
+ return [];
35
+ }
36
+ return querySnapshot.docs.map((doc) => this.mapDocumentToEntity(doc));
37
+ }
38
+ async create(params) {
39
+ const docRef = this.db.collection(this.collectionName).doc();
40
+ const tokenPackEntity = {
41
+ ...params,
42
+ id: docRef.id,
43
+ status: 'active',
44
+ tokensRemaining: params.tokens,
45
+ };
46
+ await docRef.set(tokenPackEntity);
47
+ return tokenPackEntity;
48
+ }
49
+ async updateFieldsById(params) {
50
+ const { id, fields } = params;
51
+ const updateObject = this.buildUpdateObject(fields);
52
+ await this.db.collection(this.collectionName).doc(id).update(updateObject);
53
+ }
54
+ async deductTokens(params) {
55
+ const { id, amount } = params;
56
+ return await this.db.runTransaction(async (tx) => {
57
+ const docRef = this.db.collection(this.collectionName).doc(id);
58
+ const doc = await tx.get(docRef);
59
+ if (!doc.exists) {
60
+ throw new Error(`TokenPack not found: ${id}`);
61
+ }
62
+ const tokenPack = doc.data();
63
+ const newRemaining = tokenPack.tokensRemaining - amount;
64
+ if (newRemaining < 0) {
65
+ throw new Error(`Insufficient tokens in pack ${id}`);
66
+ }
67
+ const updateData = {
68
+ tokensRemaining: newRemaining,
69
+ };
70
+ if (newRemaining === 0) {
71
+ updateData.status = 'depleted';
72
+ }
73
+ await tx.update(docRef, updateData);
74
+ });
75
+ }
76
+ async getExpiredActiveTokenPacks() {
77
+ const now = new Date().toISOString();
78
+ const querySnapshot = await this.db
79
+ .collection(this.collectionName)
80
+ .where('status', '==', 'active')
81
+ .where('expiresAt', '<', now)
82
+ .get();
83
+ if (querySnapshot.empty) {
84
+ return [];
85
+ }
86
+ return querySnapshot.docs.map((doc) => this.mapDocumentToEntity(doc));
87
+ }
88
+ mapDocumentToEntity(doc) {
89
+ return {
90
+ id: doc.id,
91
+ ...doc.data(),
92
+ };
93
+ }
94
+ buildUpdateObject(fields) {
95
+ const updateObject = {};
96
+ fields.forEach(([fieldPath, value]) => {
97
+ updateObject[fieldPath] = value;
98
+ });
99
+ return updateObject;
100
+ }
101
+ }
102
+ exports.TokenPackRepository = TokenPackRepository;
103
+ //# sourceMappingURL=repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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AC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1E,CAAC;IAEO,mBAAmB,CAAC,GAA0B;QAClD,OAAO;YACH,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,GAAG,GAAG,CAAC,IAAI,EAAE;SACG,CAAC;IACzB,CAAC;IAEO,iBAAiB,CAAC,MAA+B;QACrD,MAAM,YAAY,GAAwB,EAAE,CAAC;QAE7C,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE;YAClC,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;QACpC,CAAC,CAAC,CAAC;QAEH,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ;AAtID,kDAsIC"}
@@ -0,0 +1,28 @@
1
+ import { Logger } from '../logger/types';
2
+ import { UpdateDBTokenPackFields } from './repository';
3
+ import { TokenPackEntity, ITokenPackRepository, ITokenPackService } from './types';
4
+ export declare class TokenPackService implements ITokenPackService {
5
+ private readonly logger;
6
+ private readonly repository;
7
+ constructor({ logger, repository, }: {
8
+ logger: Logger;
9
+ repository?: ITokenPackRepository;
10
+ });
11
+ getById(id: string): Promise<TokenPackEntity | null>;
12
+ getByUser(params: {
13
+ userId: string;
14
+ platform: string;
15
+ status?: TokenPackEntity['status'] | TokenPackEntity['status'][];
16
+ }): Promise<TokenPackEntity[]>;
17
+ create(params: Omit<TokenPackEntity, 'id' | 'status' | 'tokensRemaining'>): Promise<TokenPackEntity>;
18
+ updateFieldsById(params: {
19
+ id: string;
20
+ fields: UpdateDBTokenPackFields;
21
+ }): Promise<void>;
22
+ deductTokens(params: {
23
+ id: string;
24
+ amount: number;
25
+ }): Promise<void>;
26
+ getExpiredActiveTokenPacks(): Promise<TokenPackEntity[]>;
27
+ }
28
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service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@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenPackService = void 0;
4
+ const repository_1 = require("./repository");
5
+ class TokenPackService {
6
+ constructor({ logger, repository, }) {
7
+ this.logger = logger;
8
+ this.repository = repository || new repository_1.TokenPackRepository();
9
+ }
10
+ async getById(id) {
11
+ try {
12
+ return await this.repository.getById(id);
13
+ }
14
+ catch (error) {
15
+ this.logger.error({
16
+ message: 'Error in token pack service getById',
17
+ payload: {
18
+ id,
19
+ error: JSON.stringify(error),
20
+ },
21
+ });
22
+ return null;
23
+ }
24
+ }
25
+ async getByUser(params) {
26
+ try {
27
+ return await this.repository.getByUser(params);
28
+ }
29
+ catch (error) {
30
+ this.logger.error({
31
+ message: 'Error in token pack service getByUser',
32
+ payload: {
33
+ userId: params.userId,
34
+ platform: params.platform,
35
+ error: JSON.stringify(error),
36
+ },
37
+ });
38
+ return [];
39
+ }
40
+ }
41
+ async create(params) {
42
+ try {
43
+ return await this.repository.create(params);
44
+ }
45
+ catch (error) {
46
+ this.logger.error({
47
+ message: 'Error in token pack service create',
48
+ payload: {
49
+ userId: params.userId,
50
+ platform: params.platform,
51
+ packId: params.packId,
52
+ error: JSON.stringify(error),
53
+ },
54
+ });
55
+ throw error;
56
+ }
57
+ }
58
+ async updateFieldsById(params) {
59
+ try {
60
+ await this.repository.updateFieldsById(params);
61
+ }
62
+ catch (error) {
63
+ this.logger.error({
64
+ message: 'Error in token pack service updateFieldsById',
65
+ payload: {
66
+ id: params.id,
67
+ fields: JSON.stringify(params.fields),
68
+ error: JSON.stringify(error),
69
+ },
70
+ });
71
+ throw error;
72
+ }
73
+ }
74
+ async deductTokens(params) {
75
+ try {
76
+ await this.repository.deductTokens(params);
77
+ }
78
+ catch (error) {
79
+ this.logger.error({
80
+ message: 'Error in token pack service deductTokens',
81
+ payload: {
82
+ id: params.id,
83
+ amount: params.amount,
84
+ error: JSON.stringify(error),
85
+ },
86
+ });
87
+ throw error;
88
+ }
89
+ }
90
+ async getExpiredActiveTokenPacks() {
91
+ try {
92
+ return await this.repository.getExpiredActiveTokenPacks();
93
+ }
94
+ catch (error) {
95
+ this.logger.error({
96
+ message: 'Error in token pack service getExpiredActiveTokenPacks',
97
+ payload: {
98
+ error: JSON.stringify(error),
99
+ },
100
+ });
101
+ return [];
102
+ }
103
+ }
104
+ }
105
+ exports.TokenPackService = TokenPackService;
106
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/tokenPack/service.ts"],"names":[],"mappings":";;;AACA,6CAA4E;AAG5E,MAAa,gBAAgB;IAIzB,YAAY,EACR,MAAM,EACN,UAAU,GAIb;QACG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,IAAI,gCAAmB,EAAE,CAAC;IAC9D,CAAC;IAEM,KAAK,CAAC,OAAO,CAAC,EAAU;QAC3B,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QAC7C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,qCAAqC;gBAC9C,OAAO,EAAE;oBACL,EAAE;oBACF,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,MAItB;QACG,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACnD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,uCAAuC;gBAChD,OAAO,EAAE;oBACL,MA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D,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,0CAA0C;gBACnD,OAAO,EAAE;oBACL,EAAE,EAAE,MAAM,CAAC,EAAE;oBACb,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YACH,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,0BAA0B;QACnC,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,0BAA0B,EAAE,CAAC;QAC9D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,wDAAwD;gBACjE,OAAO,EAAE;oBACL,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YACH,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC;CACJ;AAlHD,4CAkHC"}
@@ -0,0 +1,124 @@
1
+ import { NestedPathsAccess } from '../../types/utilities';
2
+ type TokenPackEntity = {
3
+ /** Auto-generated unique ID (document ID) */
4
+ id: string;
5
+ /** The Telegram User ID this token pack belongs to */
6
+ userId: string;
7
+ /** Platform/app namespace */
8
+ platform: string;
9
+ /** The identifier for the token pack type */
10
+ packId: string;
11
+ /** Number of tokens in this pack */
12
+ tokens: number;
13
+ /** Number of tokens remaining */
14
+ tokensRemaining: number;
15
+ /** The lifecycle state of this token pack */
16
+ status: 'active' | 'depleted' | 'expired';
17
+ /** Timestamp when this token pack was purchased */
18
+ purchasedAt: string;
19
+ /** Timestamp when this token pack expires (optional) */
20
+ expiresAt?: string;
21
+ /** Payment provider */
22
+ provider: 'wayforpay' | 'platform';
23
+ };
24
+ type TokenPackFieldPath = NestedPathsAccess<TokenPackEntity>;
25
+ /**
26
+ * Interface for token pack repository operations.
27
+ * Defines the contract for data access layer.
28
+ */
29
+ interface ITokenPackRepository {
30
+ /**
31
+ * Retrieves a token pack by ID.
32
+ * @param id - The token pack ID
33
+ * @returns Promise resolving to TokenPackEntity or null if not found
34
+ */
35
+ getById(id: string): Promise<TokenPackEntity | null>;
36
+ /**
37
+ * Retrieves all token packs for a specific user.
38
+ * @param params - Query parameters
39
+ * @returns Promise resolving to array of TokenPackEntity
40
+ */
41
+ getByUser(params: {
42
+ userId: string;
43
+ platform: string;
44
+ status?: TokenPackEntity['status'] | TokenPackEntity['status'][];
45
+ }): Promise<TokenPackEntity[]>;
46
+ /**
47
+ * Creates a new token pack record in the database.
48
+ * @param params - Token pack creation parameters
49
+ * @returns Promise resolving to created TokenPackEntity with ID
50
+ */
51
+ create(params: Omit<TokenPackEntity, 'id' | 'status' | 'tokensRemaining'>): Promise<TokenPackEntity>;
52
+ /**
53
+ * Updates specific fields of a token pack identified by ID.
54
+ * @param params - Update parameters
55
+ */
56
+ updateFieldsById(params: {
57
+ id: string;
58
+ fields: any;
59
+ }): Promise<void>;
60
+ /**
61
+ * Deducts tokens from a token pack.
62
+ * @param params - Deduction parameters
63
+ */
64
+ deductTokens(params: {
65
+ id: string;
66
+ amount: number;
67
+ }): Promise<void>;
68
+ /**
69
+ * Retrieves all active token packs that have expired.
70
+ * @returns Promise resolving to array of expired TokenPackEntity
71
+ */
72
+ getExpiredActiveTokenPacks(): Promise<TokenPackEntity[]>;
73
+ }
74
+ /**
75
+ * Interface for token pack service operations.
76
+ * Defines the contract for business logic layer.
77
+ */
78
+ interface ITokenPackService {
79
+ /**
80
+ * Retrieves a token pack by ID.
81
+ * @param id - The token pack ID
82
+ * @returns Promise resolving to TokenPackEntity or null if not found
83
+ */
84
+ getById(id: string): Promise<TokenPackEntity | null>;
85
+ /**
86
+ * Retrieves all token packs for a specific user.
87
+ * @param params - Query parameters
88
+ * @returns Promise resolving to array of TokenPackEntity
89
+ */
90
+ getByUser(params: {
91
+ userId: string;
92
+ platform: string;
93
+ status?: TokenPackEntity['status'] | TokenPackEntity['status'][];
94
+ }): Promise<TokenPackEntity[]>;
95
+ /**
96
+ * Creates a new token pack record in the database.
97
+ * @param params - Token pack creation parameters
98
+ * @returns Promise resolving to created TokenPackEntity with ID
99
+ */
100
+ create(params: Omit<TokenPackEntity, 'id' | 'status' | 'tokensRemaining'>): Promise<TokenPackEntity>;
101
+ /**
102
+ * Updates specific fields of a token pack identified by ID.
103
+ * @param params - Update parameters
104
+ */
105
+ updateFieldsById(params: {
106
+ id: string;
107
+ fields: any;
108
+ }): Promise<void>;
109
+ /**
110
+ * Deducts tokens from a token pack.
111
+ * @param params - Deduction parameters
112
+ */
113
+ deductTokens(params: {
114
+ id: string;
115
+ amount: number;
116
+ }): Promise<void>;
117
+ /**
118
+ * Retrieves all active token packs that have expired.
119
+ * @returns Promise resolving to array of expired TokenPackEntity
120
+ */
121
+ getExpiredActiveTokenPacks(): Promise<TokenPackEntity[]>;
122
+ }
123
+ export type { TokenPackEntity, TokenPackFieldPath, ITokenPackRepository, ITokenPackService, };
124
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/tokenPack/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,KAAK,eAAe,GAAG;IACnB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,eAAe,EAAE,MAAM,CAAC;IACxB,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G;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IAErD;;;;OAIG;IACH,SAAS,CAAC,MAAM,EAAE;QACd,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,GAAG,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;KACpE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAE/B;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,IAAI,GAAG,QAAQ,GAAG,iBAAiB,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAErG;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE;;;OAGG;IACH,YAAY,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;OAGG;IACH,0BAA0B,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;CAC5D;AAED,YAAY,EACR,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,GACpB,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/tokenPack/types.ts"],"names":[],"mappings":""}