@oneuptime/common 10.8.2 → 11.0.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 (724) hide show
  1. package/Models/AnalyticsModels/AnalyticsBaseModel/AnalyticsBaseModel.ts +16 -18
  2. package/Models/AnalyticsModels/AuditLog.ts +3 -1
  3. package/Models/AnalyticsModels/ExceptionInstance.ts +200 -82
  4. package/Models/AnalyticsModels/Index.ts +7 -2
  5. package/Models/AnalyticsModels/Log.ts +197 -81
  6. package/Models/AnalyticsModels/Metric.ts +199 -86
  7. package/Models/AnalyticsModels/MetricBaselineHourly.ts +44 -25
  8. package/Models/AnalyticsModels/MetricItemAggMV1m.ts +23 -20
  9. package/Models/AnalyticsModels/{MetricItemAggMV1mByHost.ts → MetricItemAggMV1mByHostV2.ts} +58 -47
  10. package/Models/AnalyticsModels/MonitorLog.ts +5 -1
  11. package/Models/AnalyticsModels/Profile.ts +206 -85
  12. package/Models/AnalyticsModels/ProfileSample.ts +196 -83
  13. package/Models/AnalyticsModels/Span.ts +218 -85
  14. package/Models/DatabaseModels/Index.ts +4 -0
  15. package/Models/DatabaseModels/Service.ts +29 -0
  16. package/Models/DatabaseModels/TelemetryEntity.ts +393 -0
  17. package/Models/DatabaseModels/TelemetryEntityRelationship.ts +294 -0
  18. package/Models/DatabaseModels/TelemetryException.ts +10 -10
  19. package/Models/DatabaseModels/TelemetryUsageBilling.ts +5 -5
  20. package/Server/API/AIAgentDataAPI.ts +13 -12
  21. package/Server/API/DashboardAPI.ts +2 -2
  22. package/Server/API/TelemetryAPI.ts +656 -141
  23. package/Server/API/TelemetryExceptionAPI.ts +2 -2
  24. package/Server/Infrastructure/ClickhouseConfig.ts +12 -0
  25. package/Server/Infrastructure/Postgres/SchemaMigrations/1781100000001-RenameTelemetryServiceIdToPrimaryEntityId.ts +48 -0
  26. package/Server/Infrastructure/Postgres/SchemaMigrations/1781200000000-AddTelemetryEntityTable.ts +70 -0
  27. package/Server/Infrastructure/Postgres/SchemaMigrations/1781200000001-AddTelemetryEntityRelationshipTable.ts +57 -0
  28. package/Server/Infrastructure/Postgres/SchemaMigrations/1781250074195-MigrationName.ts +207 -0
  29. package/Server/Infrastructure/Postgres/SchemaMigrations/1781300000000-AddTelemetryEntityLabels.ts +24 -0
  30. package/Server/Infrastructure/Postgres/SchemaMigrations/1781400000000-AddServiceTelemetrySdkLanguage.ts +25 -0
  31. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +12 -0
  32. package/Server/Infrastructure/Queue.ts +36 -3
  33. package/Server/Middleware/TelemetryIngest.ts +27 -22
  34. package/Server/Services/AlertService.ts +9 -9
  35. package/Server/Services/AnalyticsDatabaseService.ts +204 -35
  36. package/Server/Services/ExceptionAggregationService.ts +41 -18
  37. package/Server/Services/HostService.ts +2 -1
  38. package/Server/Services/IncidentService.ts +19 -19
  39. package/Server/Services/Index.ts +6 -2
  40. package/Server/Services/LogAggregationService.ts +116 -43
  41. package/Server/Services/MetricAggregationService.ts +29 -14
  42. package/Server/Services/MetricBaselineService.ts +34 -34
  43. package/Server/Services/MetricItemAggMV1mByHostV2Service.ts +30 -0
  44. package/Server/Services/MetricService.ts +119 -31
  45. package/Server/Services/OpenTelemetryIngestService.ts +186 -50
  46. package/Server/Services/ProfileAggregationService.ts +904 -126
  47. package/Server/Services/ServiceService.ts +6 -0
  48. package/Server/Services/SpanService.ts +274 -14
  49. package/Server/Services/TelemetryEntityRelationshipService.ts +71 -0
  50. package/Server/Services/TelemetryEntityService.ts +246 -0
  51. package/Server/Services/TelemetryExceptionService.ts +27 -23
  52. package/Server/Services/TelemetryUsageBillingService.ts +38 -31
  53. package/Server/Services/TraceAggregationService.ts +875 -43
  54. package/Server/Types/AnalyticsDatabase/ModelPermission.ts +43 -2
  55. package/Server/Types/Database/Permissions/AccessControlPermission.ts +47 -2
  56. package/Server/Types/Database/Permissions/BasePermission.ts +37 -1
  57. package/Server/Types/Database/Permissions/OwnedScopePermission.ts +21 -3
  58. package/Server/Types/Database/Permissions/OwnerTableRegistry.ts +1 -0
  59. package/Server/Types/Database/QueryHelper.ts +41 -0
  60. package/Server/Utils/Alert/AlertPrivacyFilter.ts +9 -2
  61. package/Server/Utils/AlertEpisode/AlertEpisodePrivacyFilter.ts +9 -2
  62. package/Server/Utils/AnalyticsDatabase/QuerySettingsHelper.ts +95 -0
  63. package/Server/Utils/AnalyticsDatabase/StatementGenerator.ts +133 -0
  64. package/Server/Utils/Incident/IncidentPrivacyFilter.ts +9 -2
  65. package/Server/Utils/IncidentEpisode/IncidentEpisodePrivacyFilter.ts +9 -2
  66. package/Server/Utils/Monitor/Criteria/EvaluateOverTime.ts +1 -1
  67. package/Server/Utils/Monitor/MonitorLogUtil.ts +1 -2
  68. package/Server/Utils/Monitor/MonitorMetricUtil.ts +3 -4
  69. package/Server/Utils/PrivacyFilterUtil.ts +72 -0
  70. package/Server/Utils/Profile/PprofEncoder.ts +135 -11
  71. package/Server/Utils/Telemetry/EntityRegistry.ts +316 -0
  72. package/Server/Utils/Telemetry/ResourceFacetResolver.ts +5 -0
  73. package/Server/Utils/Telemetry/TelemetryEntity.ts +783 -0
  74. package/Tests/Server/Services/AnalyticsDatabaseService.test.ts +79 -4
  75. package/Tests/Server/Services/LogAggregationService.test.ts +7 -2
  76. package/Tests/Server/Services/ProfileAggregationService.test.ts +280 -0
  77. package/Tests/Server/Services/ProfileBreakdown.test.ts +161 -0
  78. package/Tests/Server/Services/ProfileFunctionFocus.test.ts +349 -0
  79. package/Tests/Server/Services/TelemetryAttributeService.test.ts +1 -1
  80. package/Tests/Server/Services/TraceAggregationService.test.ts +403 -0
  81. package/Tests/Server/Types/AnalyticsDatabase/ModelPermissionOwnedScope.test.ts +114 -0
  82. package/Tests/Server/Types/Database/Permissions/AccessControlPermission.test.ts +189 -0
  83. package/Tests/Server/Types/Database/Permissions/BasePermission.test.ts +118 -0
  84. package/Tests/Server/Types/Database/Permissions/OwnedScopePermission.test.ts +159 -0
  85. package/Tests/Server/Utils/AnalyticsDatabase/StatementGenerator.test.ts +275 -8
  86. package/Tests/Server/Utils/PrivacyFilterUtil.test.ts +177 -0
  87. package/Tests/Server/Utils/Profile/PprofEncoder.test.ts +276 -0
  88. package/Tests/Server/Utils/Telemetry/TelemetryEntity.test.ts +761 -0
  89. package/Tests/Types/Monitor/MonitorStepEntityScope.test.ts +275 -0
  90. package/Tests/Types/Text.test.ts +52 -0
  91. package/Tests/Utils/Telemetry/EntityKey.test.ts +150 -0
  92. package/Tests/Utils/Telemetry/EntityKeySqlParity.test.ts +40 -0
  93. package/Tests/Utils/Telemetry/EntityRelationship.test.ts +150 -0
  94. package/Tests/Utils/UUID.test.ts +47 -0
  95. package/Types/AnalyticsDatabase/AnalyticsTableName.ts +14 -9
  96. package/Types/AnalyticsDatabase/TableColumnType.ts +1 -0
  97. package/Types/Dashboard/DashboardComponentType.ts +1 -0
  98. package/Types/Dashboard/DashboardComponents/DashboardTraceChartComponent.ts +37 -0
  99. package/Types/Dashboard/DashboardTemplates.ts +4 -5
  100. package/Types/Log/LogQueryParser.ts +2 -2
  101. package/Types/Log/LogQueryToFilter.ts +2 -2
  102. package/Types/Monitor/MonitorStepExceptionMonitor.ts +19 -1
  103. package/Types/Monitor/MonitorStepLogMonitor.ts +20 -1
  104. package/Types/Monitor/MonitorStepMetricMonitor.ts +27 -0
  105. package/Types/Monitor/MonitorStepProfileMonitor.ts +19 -1
  106. package/Types/Monitor/MonitorStepTraceMonitor.ts +18 -1
  107. package/Types/Monitor/MonitorType.ts +8 -1
  108. package/Types/ObjectID.ts +10 -0
  109. package/Types/Telemetry/EntityRelationshipType.ts +31 -0
  110. package/Types/Telemetry/EntityType.ts +33 -0
  111. package/Types/Telemetry/TelemetrySavedViewState.ts +2 -0
  112. package/Types/Text.ts +34 -0
  113. package/Types/Trace/TraceAggregationType.ts +1 -0
  114. package/Types/Trace/TraceRecordingRuleDefinition.ts +74 -0
  115. package/UI/Components/LogsViewer/LogsViewer.tsx +12 -9
  116. package/UI/Components/LogsViewer/components/LogDetailsPanel.tsx +10 -9
  117. package/UI/Components/LogsViewer/components/LogSearchBar.tsx +1 -1
  118. package/UI/Components/LogsViewer/components/LogsAnalyticsView.tsx +2 -2
  119. package/UI/Components/LogsViewer/components/LogsFacetSidebar.tsx +4 -4
  120. package/UI/Components/LogsViewer/components/LogsTable.tsx +5 -3
  121. package/UI/Components/Navbar/NavBarMenuModal.tsx +81 -44
  122. package/UI/Components/TelemetryViewer/TelemetryViewer.tsx +33 -10
  123. package/UI/Components/TelemetryViewer/components/TelemetryFacetSidebar.tsx +18 -3
  124. package/UI/Components/TelemetryViewer/components/TelemetryHistogram.tsx +91 -68
  125. package/UI/Components/TelemetryViewer/components/TelemetryHistogramTooltip.tsx +9 -2
  126. package/UI/Utils/LogExport.ts +2 -2
  127. package/UI/Utils/TelemetryService.ts +20 -20
  128. package/Utils/Dashboard/Components/DashboardTraceChartComponent.ts +134 -0
  129. package/Utils/Dashboard/Components/Index.ts +7 -0
  130. package/Utils/Telemetry/EntityKey.ts +151 -0
  131. package/Utils/Telemetry/EntityRelationship.ts +113 -0
  132. package/Utils/Traces/CriticalPath.ts +7 -7
  133. package/Utils/UUID.ts +57 -0
  134. package/build/dist/Models/AnalyticsModels/AnalyticsBaseModel/AnalyticsBaseModel.js +14 -13
  135. package/build/dist/Models/AnalyticsModels/AnalyticsBaseModel/AnalyticsBaseModel.js.map +1 -1
  136. package/build/dist/Models/AnalyticsModels/AuditLog.js +2 -1
  137. package/build/dist/Models/AnalyticsModels/AuditLog.js.map +1 -1
  138. package/build/dist/Models/AnalyticsModels/ExceptionInstance.js +125 -22
  139. package/build/dist/Models/AnalyticsModels/ExceptionInstance.js.map +1 -1
  140. package/build/dist/Models/AnalyticsModels/Index.js +7 -2
  141. package/build/dist/Models/AnalyticsModels/Index.js.map +1 -1
  142. package/build/dist/Models/AnalyticsModels/Log.js +123 -22
  143. package/build/dist/Models/AnalyticsModels/Log.js.map +1 -1
  144. package/build/dist/Models/AnalyticsModels/Metric.js +125 -27
  145. package/build/dist/Models/AnalyticsModels/Metric.js.map +1 -1
  146. package/build/dist/Models/AnalyticsModels/MetricBaselineHourly.js +38 -21
  147. package/build/dist/Models/AnalyticsModels/MetricBaselineHourly.js.map +1 -1
  148. package/build/dist/Models/AnalyticsModels/MetricItemAggMV1m.js +17 -16
  149. package/build/dist/Models/AnalyticsModels/MetricItemAggMV1m.js.map +1 -1
  150. package/build/dist/Models/AnalyticsModels/{MetricItemAggMV1mByHost.js → MetricItemAggMV1mByHostV2.js} +54 -42
  151. package/build/dist/Models/AnalyticsModels/MetricItemAggMV1mByHostV2.js.map +1 -0
  152. package/build/dist/Models/AnalyticsModels/MonitorLog.js +4 -1
  153. package/build/dist/Models/AnalyticsModels/MonitorLog.js.map +1 -1
  154. package/build/dist/Models/AnalyticsModels/Profile.js +132 -26
  155. package/build/dist/Models/AnalyticsModels/Profile.js.map +1 -1
  156. package/build/dist/Models/AnalyticsModels/ProfileSample.js +121 -23
  157. package/build/dist/Models/AnalyticsModels/ProfileSample.js.map +1 -1
  158. package/build/dist/Models/AnalyticsModels/Span.js +144 -26
  159. package/build/dist/Models/AnalyticsModels/Span.js.map +1 -1
  160. package/build/dist/Models/DatabaseModels/Index.js +4 -0
  161. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  162. package/build/dist/Models/DatabaseModels/Service.js +30 -0
  163. package/build/dist/Models/DatabaseModels/Service.js.map +1 -1
  164. package/build/dist/Models/DatabaseModels/TelemetryEntity.js +419 -0
  165. package/build/dist/Models/DatabaseModels/TelemetryEntity.js.map +1 -0
  166. package/build/dist/Models/DatabaseModels/TelemetryEntityRelationship.js +317 -0
  167. package/build/dist/Models/DatabaseModels/TelemetryEntityRelationship.js.map +1 -0
  168. package/build/dist/Models/DatabaseModels/TelemetryException.js +12 -12
  169. package/build/dist/Models/DatabaseModels/TelemetryException.js.map +1 -1
  170. package/build/dist/Models/DatabaseModels/TelemetryUsageBilling.js +7 -7
  171. package/build/dist/Models/DatabaseModels/TelemetryUsageBilling.js.map +1 -1
  172. package/build/dist/Server/API/AIAgentDataAPI.js +14 -13
  173. package/build/dist/Server/API/AIAgentDataAPI.js.map +1 -1
  174. package/build/dist/Server/API/DashboardAPI.js +2 -2
  175. package/build/dist/Server/API/DashboardAPI.js.map +1 -1
  176. package/build/dist/Server/API/TelemetryAPI.js +425 -129
  177. package/build/dist/Server/API/TelemetryAPI.js.map +1 -1
  178. package/build/dist/Server/API/TelemetryExceptionAPI.js +2 -2
  179. package/build/dist/Server/API/TelemetryExceptionAPI.js.map +1 -1
  180. package/build/dist/Server/Infrastructure/ClickhouseConfig.js +12 -0
  181. package/build/dist/Server/Infrastructure/ClickhouseConfig.js.map +1 -1
  182. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781100000001-RenameTelemetryServiceIdToPrimaryEntityId.js +29 -0
  183. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781100000001-RenameTelemetryServiceIdToPrimaryEntityId.js.map +1 -0
  184. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781200000000-AddTelemetryEntityTable.js +38 -0
  185. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781200000000-AddTelemetryEntityTable.js.map +1 -0
  186. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781200000001-AddTelemetryEntityRelationshipTable.js +33 -0
  187. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781200000001-AddTelemetryEntityRelationshipTable.js.map +1 -0
  188. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781250074195-MigrationName.js +78 -0
  189. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781250074195-MigrationName.js.map +1 -0
  190. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781300000000-AddTelemetryEntityLabels.js +19 -0
  191. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781300000000-AddTelemetryEntityLabels.js.map +1 -0
  192. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781400000000-AddServiceTelemetrySdkLanguage.js +18 -0
  193. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1781400000000-AddServiceTelemetrySdkLanguage.js.map +1 -0
  194. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +12 -0
  195. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  196. package/build/dist/Server/Infrastructure/Queue.js +14 -3
  197. package/build/dist/Server/Infrastructure/Queue.js.map +1 -1
  198. package/build/dist/Server/Middleware/TelemetryIngest.js +16 -18
  199. package/build/dist/Server/Middleware/TelemetryIngest.js.map +1 -1
  200. package/build/dist/Server/Services/AlertService.js +9 -9
  201. package/build/dist/Server/Services/AlertService.js.map +1 -1
  202. package/build/dist/Server/Services/AnalyticsDatabaseService.js +115 -40
  203. package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
  204. package/build/dist/Server/Services/ExceptionAggregationService.js +38 -18
  205. package/build/dist/Server/Services/ExceptionAggregationService.js.map +1 -1
  206. package/build/dist/Server/Services/HostService.js +2 -1
  207. package/build/dist/Server/Services/HostService.js.map +1 -1
  208. package/build/dist/Server/Services/IncidentService.js +19 -19
  209. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  210. package/build/dist/Server/Services/Index.js +6 -2
  211. package/build/dist/Server/Services/Index.js.map +1 -1
  212. package/build/dist/Server/Services/LogAggregationService.js +100 -42
  213. package/build/dist/Server/Services/LogAggregationService.js.map +1 -1
  214. package/build/dist/Server/Services/MetricAggregationService.js +27 -14
  215. package/build/dist/Server/Services/MetricAggregationService.js.map +1 -1
  216. package/build/dist/Server/Services/MetricBaselineService.js +28 -28
  217. package/build/dist/Server/Services/MetricBaselineService.js.map +1 -1
  218. package/build/dist/Server/Services/MetricItemAggMV1mByHostV2Service.js +28 -0
  219. package/build/dist/Server/Services/MetricItemAggMV1mByHostV2Service.js.map +1 -0
  220. package/build/dist/Server/Services/MetricService.js +116 -31
  221. package/build/dist/Server/Services/MetricService.js.map +1 -1
  222. package/build/dist/Server/Services/OpenTelemetryIngestService.js +103 -36
  223. package/build/dist/Server/Services/OpenTelemetryIngestService.js.map +1 -1
  224. package/build/dist/Server/Services/ProfileAggregationService.js +613 -105
  225. package/build/dist/Server/Services/ProfileAggregationService.js.map +1 -1
  226. package/build/dist/Server/Services/ServiceService.js +9 -5
  227. package/build/dist/Server/Services/ServiceService.js.map +1 -1
  228. package/build/dist/Server/Services/SpanService.js +217 -15
  229. package/build/dist/Server/Services/SpanService.js.map +1 -1
  230. package/build/dist/Server/Services/TelemetryEntityRelationshipService.js +72 -0
  231. package/build/dist/Server/Services/TelemetryEntityRelationshipService.js.map +1 -0
  232. package/build/dist/Server/Services/TelemetryEntityService.js +201 -0
  233. package/build/dist/Server/Services/TelemetryEntityService.js.map +1 -0
  234. package/build/dist/Server/Services/TelemetryExceptionService.js +18 -18
  235. package/build/dist/Server/Services/TelemetryExceptionService.js.map +1 -1
  236. package/build/dist/Server/Services/TelemetryUsageBillingService.js +27 -21
  237. package/build/dist/Server/Services/TelemetryUsageBillingService.js.map +1 -1
  238. package/build/dist/Server/Services/TraceAggregationService.js +568 -43
  239. package/build/dist/Server/Services/TraceAggregationService.js.map +1 -1
  240. package/build/dist/Server/Types/AnalyticsDatabase/ModelPermission.js +38 -2
  241. package/build/dist/Server/Types/AnalyticsDatabase/ModelPermission.js.map +1 -1
  242. package/build/dist/Server/Types/Database/Permissions/AccessControlPermission.js +36 -2
  243. package/build/dist/Server/Types/Database/Permissions/AccessControlPermission.js.map +1 -1
  244. package/build/dist/Server/Types/Database/Permissions/BasePermission.js +25 -1
  245. package/build/dist/Server/Types/Database/Permissions/BasePermission.js.map +1 -1
  246. package/build/dist/Server/Types/Database/Permissions/OwnedScopePermission.js +17 -3
  247. package/build/dist/Server/Types/Database/Permissions/OwnedScopePermission.js.map +1 -1
  248. package/build/dist/Server/Types/Database/Permissions/OwnerTableRegistry.js +1 -0
  249. package/build/dist/Server/Types/Database/Permissions/OwnerTableRegistry.js.map +1 -1
  250. package/build/dist/Server/Types/Database/QueryHelper.js +31 -0
  251. package/build/dist/Server/Types/Database/QueryHelper.js.map +1 -1
  252. package/build/dist/Server/Utils/Alert/AlertPrivacyFilter.js +3 -2
  253. package/build/dist/Server/Utils/Alert/AlertPrivacyFilter.js.map +1 -1
  254. package/build/dist/Server/Utils/AlertEpisode/AlertEpisodePrivacyFilter.js +3 -2
  255. package/build/dist/Server/Utils/AlertEpisode/AlertEpisodePrivacyFilter.js.map +1 -1
  256. package/build/dist/Server/Utils/AnalyticsDatabase/QuerySettingsHelper.js +46 -0
  257. package/build/dist/Server/Utils/AnalyticsDatabase/QuerySettingsHelper.js.map +1 -0
  258. package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js +97 -3
  259. package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js.map +1 -1
  260. package/build/dist/Server/Utils/Incident/IncidentPrivacyFilter.js +3 -2
  261. package/build/dist/Server/Utils/Incident/IncidentPrivacyFilter.js.map +1 -1
  262. package/build/dist/Server/Utils/IncidentEpisode/IncidentEpisodePrivacyFilter.js +3 -2
  263. package/build/dist/Server/Utils/IncidentEpisode/IncidentEpisodePrivacyFilter.js.map +1 -1
  264. package/build/dist/Server/Utils/Monitor/Criteria/EvaluateOverTime.js +1 -1
  265. package/build/dist/Server/Utils/Monitor/Criteria/EvaluateOverTime.js.map +1 -1
  266. package/build/dist/Server/Utils/Monitor/MonitorLogUtil.js +1 -2
  267. package/build/dist/Server/Utils/Monitor/MonitorLogUtil.js.map +1 -1
  268. package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js +3 -4
  269. package/build/dist/Server/Utils/Monitor/MonitorMetricUtil.js.map +1 -1
  270. package/build/dist/Server/Utils/PrivacyFilterUtil.js +47 -0
  271. package/build/dist/Server/Utils/PrivacyFilterUtil.js.map +1 -0
  272. package/build/dist/Server/Utils/Profile/PprofEncoder.js +132 -4
  273. package/build/dist/Server/Utils/Profile/PprofEncoder.js.map +1 -1
  274. package/build/dist/Server/Utils/Telemetry/EntityRegistry.js +228 -0
  275. package/build/dist/Server/Utils/Telemetry/EntityRegistry.js.map +1 -0
  276. package/build/dist/Server/Utils/Telemetry/ResourceFacetResolver.js +5 -0
  277. package/build/dist/Server/Utils/Telemetry/ResourceFacetResolver.js.map +1 -1
  278. package/build/dist/Server/Utils/Telemetry/TelemetryEntity.js +569 -0
  279. package/build/dist/Server/Utils/Telemetry/TelemetryEntity.js.map +1 -0
  280. package/build/dist/Types/AnalyticsDatabase/AnalyticsTableName.js +14 -9
  281. package/build/dist/Types/AnalyticsDatabase/AnalyticsTableName.js.map +1 -1
  282. package/build/dist/Types/AnalyticsDatabase/TableColumnType.js +1 -0
  283. package/build/dist/Types/AnalyticsDatabase/TableColumnType.js.map +1 -1
  284. package/build/dist/Types/Dashboard/DashboardComponentType.js +1 -0
  285. package/build/dist/Types/Dashboard/DashboardComponentType.js.map +1 -1
  286. package/build/dist/Types/Dashboard/DashboardComponents/DashboardTraceChartComponent.js +2 -0
  287. package/build/dist/Types/Dashboard/DashboardComponents/DashboardTraceChartComponent.js.map +1 -0
  288. package/build/dist/Types/Dashboard/DashboardTemplates.js +4 -5
  289. package/build/dist/Types/Dashboard/DashboardTemplates.js.map +1 -1
  290. package/build/dist/Types/Log/LogQueryParser.js +2 -2
  291. package/build/dist/Types/Log/LogQueryParser.js.map +1 -1
  292. package/build/dist/Types/Log/LogQueryToFilter.js +1 -1
  293. package/build/dist/Types/Log/LogQueryToFilter.js.map +1 -1
  294. package/build/dist/Types/Monitor/MonitorStepExceptionMonitor.js +9 -1
  295. package/build/dist/Types/Monitor/MonitorStepExceptionMonitor.js.map +1 -1
  296. package/build/dist/Types/Monitor/MonitorStepLogMonitor.js +9 -1
  297. package/build/dist/Types/Monitor/MonitorStepLogMonitor.js.map +1 -1
  298. package/build/dist/Types/Monitor/MonitorStepMetricMonitor.js +13 -0
  299. package/build/dist/Types/Monitor/MonitorStepMetricMonitor.js.map +1 -1
  300. package/build/dist/Types/Monitor/MonitorStepProfileMonitor.js +9 -1
  301. package/build/dist/Types/Monitor/MonitorStepProfileMonitor.js.map +1 -1
  302. package/build/dist/Types/Monitor/MonitorStepTraceMonitor.js +9 -1
  303. package/build/dist/Types/Monitor/MonitorStepTraceMonitor.js.map +1 -1
  304. package/build/dist/Types/Monitor/MonitorType.js +8 -1
  305. package/build/dist/Types/Monitor/MonitorType.js.map +1 -1
  306. package/build/dist/Types/ObjectID.js +9 -0
  307. package/build/dist/Types/ObjectID.js.map +1 -1
  308. package/build/dist/Types/Telemetry/EntityRelationshipType.js +32 -0
  309. package/build/dist/Types/Telemetry/EntityRelationshipType.js.map +1 -0
  310. package/build/dist/Types/Telemetry/EntityType.js +34 -0
  311. package/build/dist/Types/Telemetry/EntityType.js.map +1 -0
  312. package/build/dist/Types/Text.js +32 -1
  313. package/build/dist/Types/Text.js.map +1 -1
  314. package/build/dist/Types/Trace/TraceAggregationType.js +1 -0
  315. package/build/dist/Types/Trace/TraceAggregationType.js.map +1 -1
  316. package/build/dist/Types/Trace/TraceRecordingRuleDefinition.js +50 -1
  317. package/build/dist/Types/Trace/TraceRecordingRuleDefinition.js.map +1 -1
  318. package/build/dist/UI/Components/LogsViewer/LogsViewer.js +10 -9
  319. package/build/dist/UI/Components/LogsViewer/LogsViewer.js.map +1 -1
  320. package/build/dist/UI/Components/LogsViewer/components/LogDetailsPanel.js +8 -8
  321. package/build/dist/UI/Components/LogsViewer/components/LogDetailsPanel.js.map +1 -1
  322. package/build/dist/UI/Components/LogsViewer/components/LogSearchBar.js +1 -1
  323. package/build/dist/UI/Components/LogsViewer/components/LogSearchBar.js.map +1 -1
  324. package/build/dist/UI/Components/LogsViewer/components/LogsAnalyticsView.js +2 -2
  325. package/build/dist/UI/Components/LogsViewer/components/LogsAnalyticsView.js.map +1 -1
  326. package/build/dist/UI/Components/LogsViewer/components/LogsFacetSidebar.js +4 -4
  327. package/build/dist/UI/Components/LogsViewer/components/LogsFacetSidebar.js.map +1 -1
  328. package/build/dist/UI/Components/LogsViewer/components/LogsTable.js +3 -3
  329. package/build/dist/UI/Components/LogsViewer/components/LogsTable.js.map +1 -1
  330. package/build/dist/UI/Components/Navbar/NavBarMenuModal.js +43 -30
  331. package/build/dist/UI/Components/Navbar/NavBarMenuModal.js.map +1 -1
  332. package/build/dist/UI/Components/TelemetryViewer/TelemetryViewer.js +6 -2
  333. package/build/dist/UI/Components/TelemetryViewer/TelemetryViewer.js.map +1 -1
  334. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetSidebar.js +14 -3
  335. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryFacetSidebar.js.map +1 -1
  336. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogram.js +18 -10
  337. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogram.js.map +1 -1
  338. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogramTooltip.js +4 -2
  339. package/build/dist/UI/Components/TelemetryViewer/components/TelemetryHistogramTooltip.js.map +1 -1
  340. package/build/dist/UI/Utils/LogExport.js +2 -2
  341. package/build/dist/UI/Utils/LogExport.js.map +1 -1
  342. package/build/dist/UI/Utils/TelemetryService.js +16 -16
  343. package/build/dist/UI/Utils/TelemetryService.js.map +1 -1
  344. package/build/dist/Utils/Dashboard/Components/DashboardTraceChartComponent.js +110 -0
  345. package/build/dist/Utils/Dashboard/Components/DashboardTraceChartComponent.js.map +1 -0
  346. package/build/dist/Utils/Dashboard/Components/Index.js +4 -0
  347. package/build/dist/Utils/Dashboard/Components/Index.js.map +1 -1
  348. package/build/dist/Utils/Telemetry/EntityKey.js +115 -0
  349. package/build/dist/Utils/Telemetry/EntityKey.js.map +1 -0
  350. package/build/dist/Utils/Telemetry/EntityRelationship.js +71 -0
  351. package/build/dist/Utils/Telemetry/EntityRelationship.js.map +1 -0
  352. package/build/dist/Utils/Traces/CriticalPath.js +5 -5
  353. package/build/dist/Utils/Traces/CriticalPath.js.map +1 -1
  354. package/build/dist/Utils/UUID.js +50 -0
  355. package/build/dist/Utils/UUID.js.map +1 -1
  356. package/package.json +2 -1
  357. package/tsconfig.json +10 -1
  358. package/Server/Services/MetricItemAggMV1mByHostService.ts +0 -30
  359. package/Types/Profile/ProfileMetricType.ts +0 -16
  360. package/build/dist/Models/AnalyticsModels/MetricItemAggMV1mByHost.js.map +0 -1
  361. package/build/dist/Server/Services/MetricItemAggMV1mByHostService.js +0 -28
  362. package/build/dist/Server/Services/MetricItemAggMV1mByHostService.js.map +0 -1
  363. package/build/dist/Tests/MockType.js +0 -5
  364. package/build/dist/Tests/MockType.js.map +0 -1
  365. package/build/dist/Tests/Models/AnalyticsModels/Log.test.js +0 -12
  366. package/build/dist/Tests/Models/AnalyticsModels/Log.test.js.map +0 -1
  367. package/build/dist/Tests/Models/File.test.js +0 -10
  368. package/build/dist/Tests/Models/File.test.js.map +0 -1
  369. package/build/dist/Tests/Server/API/BaseAPI.test.js +0 -590
  370. package/build/dist/Tests/Server/API/BaseAPI.test.js.map +0 -1
  371. package/build/dist/Tests/Server/API/Helpers.js +0 -27
  372. package/build/dist/Tests/Server/API/Helpers.js.map +0 -1
  373. package/build/dist/Tests/Server/API/ProbeAPI.test.js +0 -84
  374. package/build/dist/Tests/Server/API/ProbeAPI.test.js.map +0 -1
  375. package/build/dist/Tests/Server/API/ProjectAPI.test.js +0 -170
  376. package/build/dist/Tests/Server/API/ProjectAPI.test.js.map +0 -1
  377. package/build/dist/Tests/Server/API/UserSmsApi.test.js +0 -177
  378. package/build/dist/Tests/Server/API/UserSmsApi.test.js.map +0 -1
  379. package/build/dist/Tests/Server/Middleware/BearerTokenAuthorization.test.js +0 -63
  380. package/build/dist/Tests/Server/Middleware/BearerTokenAuthorization.test.js.map +0 -1
  381. package/build/dist/Tests/Server/Middleware/ClusterKeyAuthorization.test.js +0 -58
  382. package/build/dist/Tests/Server/Middleware/ClusterKeyAuthorization.test.js.map +0 -1
  383. package/build/dist/Tests/Server/Middleware/NotificationMiddleware.test.js +0 -101
  384. package/build/dist/Tests/Server/Middleware/NotificationMiddleware.test.js.map +0 -1
  385. package/build/dist/Tests/Server/Middleware/ProjectAuthorization.test.js +0 -160
  386. package/build/dist/Tests/Server/Middleware/ProjectAuthorization.test.js.map +0 -1
  387. package/build/dist/Tests/Server/Middleware/UserAuthorization.test.js +0 -410
  388. package/build/dist/Tests/Server/Middleware/UserAuthorization.test.js.map +0 -1
  389. package/build/dist/Tests/Server/Services/AlertEpisodeMemberService.test.js +0 -165
  390. package/build/dist/Tests/Server/Services/AlertEpisodeMemberService.test.js.map +0 -1
  391. package/build/dist/Tests/Server/Services/AlertEpisodeService.test.js +0 -193
  392. package/build/dist/Tests/Server/Services/AlertEpisodeService.test.js.map +0 -1
  393. package/build/dist/Tests/Server/Services/AlertGroupingEngineService.test.js +0 -435
  394. package/build/dist/Tests/Server/Services/AlertGroupingEngineService.test.js.map +0 -1
  395. package/build/dist/Tests/Server/Services/AlertGroupingRuleService.test.js +0 -320
  396. package/build/dist/Tests/Server/Services/AlertGroupingRuleService.test.js.map +0 -1
  397. package/build/dist/Tests/Server/Services/AnalyticsDatabaseService.test.js +0 -266
  398. package/build/dist/Tests/Server/Services/AnalyticsDatabaseService.test.js.map +0 -1
  399. package/build/dist/Tests/Server/Services/BillingService.test.js +0 -910
  400. package/build/dist/Tests/Server/Services/BillingService.test.js.map +0 -1
  401. package/build/dist/Tests/Server/Services/LogAggregationService.test.js +0 -75
  402. package/build/dist/Tests/Server/Services/LogAggregationService.test.js.map +0 -1
  403. package/build/dist/Tests/Server/Services/ProbeService.test.js +0 -127
  404. package/build/dist/Tests/Server/Services/ProbeService.test.js.map +0 -1
  405. package/build/dist/Tests/Server/Services/ScheduledMaintenanceService.test.js +0 -114
  406. package/build/dist/Tests/Server/Services/ScheduledMaintenanceService.test.js.map +0 -1
  407. package/build/dist/Tests/Server/Services/TeamMemberService.test.js +0 -106
  408. package/build/dist/Tests/Server/Services/TeamMemberService.test.js.map +0 -1
  409. package/build/dist/Tests/Server/Services/TelemetryAttributeService.test.js +0 -50
  410. package/build/dist/Tests/Server/Services/TelemetryAttributeService.test.js.map +0 -1
  411. package/build/dist/Tests/Server/TestingUtils/Init.js +0 -4
  412. package/build/dist/Tests/Server/TestingUtils/Init.js.map +0 -1
  413. package/build/dist/Tests/Server/TestingUtils/Postgres/TestDataSourceOptions.js +0 -9
  414. package/build/dist/Tests/Server/TestingUtils/Postgres/TestDataSourceOptions.js.map +0 -1
  415. package/build/dist/Tests/Server/TestingUtils/Redis/TestRedisOptions.js +0 -16
  416. package/build/dist/Tests/Server/TestingUtils/Redis/TestRedisOptions.js.map +0 -1
  417. package/build/dist/Tests/Server/TestingUtils/Services/BillingServiceHelper.js +0 -125
  418. package/build/dist/Tests/Server/TestingUtils/Services/BillingServiceHelper.js.map +0 -1
  419. package/build/dist/Tests/Server/TestingUtils/Services/ProjectServiceHelper.js +0 -39
  420. package/build/dist/Tests/Server/TestingUtils/Services/ProjectServiceHelper.js.map +0 -1
  421. package/build/dist/Tests/Server/TestingUtils/Services/ScheduledMaintenanceServiceHelper.js +0 -20
  422. package/build/dist/Tests/Server/TestingUtils/Services/ScheduledMaintenanceServiceHelper.js.map +0 -1
  423. package/build/dist/Tests/Server/TestingUtils/Services/ScheduledMaintenanceStateServiceHelper.js +0 -31
  424. package/build/dist/Tests/Server/TestingUtils/Services/ScheduledMaintenanceStateServiceHelper.js.map +0 -1
  425. package/build/dist/Tests/Server/TestingUtils/Services/TeamMemberServiceHelper.js +0 -14
  426. package/build/dist/Tests/Server/TestingUtils/Services/TeamMemberServiceHelper.js.map +0 -1
  427. package/build/dist/Tests/Server/TestingUtils/Services/TeamServiceHelper.js +0 -21
  428. package/build/dist/Tests/Server/TestingUtils/Services/TeamServiceHelper.js.map +0 -1
  429. package/build/dist/Tests/Server/TestingUtils/Services/Types.js +0 -2
  430. package/build/dist/Tests/Server/TestingUtils/Services/Types.js.map +0 -1
  431. package/build/dist/Tests/Server/TestingUtils/Services/UserServiceHelper.js +0 -37
  432. package/build/dist/Tests/Server/TestingUtils/Services/UserServiceHelper.js.map +0 -1
  433. package/build/dist/Tests/Server/TestingUtils/__mocks__/Stripe.mock.js +0 -13
  434. package/build/dist/Tests/Server/TestingUtils/__mocks__/Stripe.mock.js.map +0 -1
  435. package/build/dist/Tests/Server/TestingUtils/__mocks__/TestDatabase.mock.js +0 -22
  436. package/build/dist/Tests/Server/TestingUtils/__mocks__/TestDatabase.mock.js.map +0 -1
  437. package/build/dist/Tests/Server/Types/Domain.test.js +0 -78
  438. package/build/dist/Tests/Server/Types/Domain.test.js.map +0 -1
  439. package/build/dist/Tests/Server/Utils/AnalyticsDatabase/Statement.test.js +0 -94
  440. package/build/dist/Tests/Server/Utils/AnalyticsDatabase/Statement.test.js.map +0 -1
  441. package/build/dist/Tests/Server/Utils/AnalyticsDatabase/StatementGenerator.test.js +0 -459
  442. package/build/dist/Tests/Server/Utils/AnalyticsDatabase/StatementGenerator.test.js.map +0 -1
  443. package/build/dist/Tests/Server/Utils/Cookie.test.js +0 -83
  444. package/build/dist/Tests/Server/Utils/Cookie.test.js.map +0 -1
  445. package/build/dist/Tests/Server/Utils/CronTab.test.js +0 -29
  446. package/build/dist/Tests/Server/Utils/CronTab.test.js.map +0 -1
  447. package/build/dist/Tests/Server/Utils/JsonToCsv.test.js +0 -114
  448. package/build/dist/Tests/Server/Utils/JsonToCsv.test.js.map +0 -1
  449. package/build/dist/Tests/Server/Utils/Monitor/Criteria/MetricMonitorCriteria.test.js +0 -606
  450. package/build/dist/Tests/Server/Utils/Monitor/Criteria/MetricMonitorCriteria.test.js.map +0 -1
  451. package/build/dist/Tests/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.test.js +0 -255
  452. package/build/dist/Tests/Server/Utils/Monitor/Criteria/SnmpMonitorCriteria.test.js.map +0 -1
  453. package/build/dist/Tests/Server/Utils/Monitor/MonitorMaintenanceSuppression.test.js +0 -142
  454. package/build/dist/Tests/Server/Utils/Monitor/MonitorMaintenanceSuppression.test.js.map +0 -1
  455. package/build/dist/Tests/Server/Utils/StatusPageResource.test.js +0 -122
  456. package/build/dist/Tests/Server/Utils/StatusPageResource.test.js.map +0 -1
  457. package/build/dist/Tests/Server/Utils/Telemetry/LogExceptionExtractor.test.js +0 -0
  458. package/build/dist/Tests/Server/Utils/Telemetry/LogExceptionExtractor.test.js.map +0 -1
  459. package/build/dist/Tests/Server/Utils/VM/VMAPI.test.js +0 -205
  460. package/build/dist/Tests/Server/Utils/VM/VMAPI.test.js.map +0 -1
  461. package/build/dist/Tests/Spy.js +0 -4
  462. package/build/dist/Tests/Spy.js.map +0 -1
  463. package/build/dist/Tests/Types/API/ErrorResponse.test.js +0 -13
  464. package/build/dist/Tests/Types/API/ErrorResponse.test.js.map +0 -1
  465. package/build/dist/Tests/Types/API/HTTPErrorResponse.test.js +0 -33
  466. package/build/dist/Tests/Types/API/HTTPErrorResponse.test.js.map +0 -1
  467. package/build/dist/Tests/Types/API/HTTPMethod.test.js +0 -16
  468. package/build/dist/Tests/Types/API/HTTPMethod.test.js.map +0 -1
  469. package/build/dist/Tests/Types/API/Headers.test.js +0 -14
  470. package/build/dist/Tests/Types/API/Headers.test.js.map +0 -1
  471. package/build/dist/Tests/Types/API/Hostname.test.js +0 -22
  472. package/build/dist/Tests/Types/API/Hostname.test.js.map +0 -1
  473. package/build/dist/Tests/Types/API/Protocal.test.js +0 -19
  474. package/build/dist/Tests/Types/API/Protocal.test.js.map +0 -1
  475. package/build/dist/Tests/Types/API/Response.test.js +0 -14
  476. package/build/dist/Tests/Types/API/Response.test.js.map +0 -1
  477. package/build/dist/Tests/Types/API/ResponseType.test.js +0 -13
  478. package/build/dist/Tests/Types/API/ResponseType.test.js.map +0 -1
  479. package/build/dist/Tests/Types/API/Route.test.js +0 -30
  480. package/build/dist/Tests/Types/API/Route.test.js.map +0 -1
  481. package/build/dist/Tests/Types/API/StatusCode.test.js +0 -26
  482. package/build/dist/Tests/Types/API/StatusCode.test.js.map +0 -1
  483. package/build/dist/Tests/Types/API/URL.test.js +0 -33
  484. package/build/dist/Tests/Types/API/URL.test.js.map +0 -1
  485. package/build/dist/Tests/Types/Alerts/AlertEventType.test.js +0 -34
  486. package/build/dist/Tests/Types/Alerts/AlertEventType.test.js.map +0 -1
  487. package/build/dist/Tests/Types/Alerts/AlertType.test.js +0 -19
  488. package/build/dist/Tests/Types/Alerts/AlertType.test.js.map +0 -1
  489. package/build/dist/Tests/Types/AppEnvironment.test.js +0 -13
  490. package/build/dist/Tests/Types/AppEnvironment.test.js.map +0 -1
  491. package/build/dist/Tests/Types/ApplicationLog/ApplicationLogType.test.js +0 -13
  492. package/build/dist/Tests/Types/ApplicationLog/ApplicationLogType.test.js.map +0 -1
  493. package/build/dist/Tests/Types/ArrayUtil.test.js +0 -71
  494. package/build/dist/Tests/Types/ArrayUtil.test.js.map +0 -1
  495. package/build/dist/Tests/Types/Billing/SubscriptionPlan.test.js +0 -181
  496. package/build/dist/Tests/Types/Billing/SubscriptionPlan.test.js.map +0 -1
  497. package/build/dist/Tests/Types/BrandColors.test.js +0 -124
  498. package/build/dist/Tests/Types/BrandColors.test.js.map +0 -1
  499. package/build/dist/Tests/Types/Char.test.js +0 -82
  500. package/build/dist/Tests/Types/Char.test.js.map +0 -1
  501. package/build/dist/Tests/Types/Code/CodeType.test.js +0 -13
  502. package/build/dist/Tests/Types/Code/CodeType.test.js.map +0 -1
  503. package/build/dist/Tests/Types/Color.test.js +0 -44
  504. package/build/dist/Tests/Types/Color.test.js.map +0 -1
  505. package/build/dist/Tests/Types/Company/CompanySize.test.js +0 -20
  506. package/build/dist/Tests/Types/Company/CompanySize.test.js.map +0 -1
  507. package/build/dist/Tests/Types/Company/JobRole.test.js +0 -22
  508. package/build/dist/Tests/Types/Company/JobRole.test.js.map +0 -1
  509. package/build/dist/Tests/Types/Countries.test.js +0 -249
  510. package/build/dist/Tests/Types/Countries.test.js.map +0 -1
  511. package/build/dist/Tests/Types/Database/ColumnLength.test.js +0 -43
  512. package/build/dist/Tests/Types/Database/ColumnLength.test.js.map +0 -1
  513. package/build/dist/Tests/Types/Database/ColumnType.test.js +0 -79
  514. package/build/dist/Tests/Types/Database/ColumnType.test.js.map +0 -1
  515. package/build/dist/Tests/Types/Database/Columns.test.js +0 -20
  516. package/build/dist/Tests/Types/Database/Columns.test.js.map +0 -1
  517. package/build/dist/Tests/Types/Database/CompareBase.test.js +0 -37
  518. package/build/dist/Tests/Types/Database/CompareBase.test.js.map +0 -1
  519. package/build/dist/Tests/Types/Database/Date.test.js +0 -62
  520. package/build/dist/Tests/Types/Database/Date.test.js.map +0 -1
  521. package/build/dist/Tests/Types/Database/EqualTo.test.js +0 -65
  522. package/build/dist/Tests/Types/Database/EqualTo.test.js.map +0 -1
  523. package/build/dist/Tests/Types/Database/EqualToOrNull.test.js +0 -62
  524. package/build/dist/Tests/Types/Database/EqualToOrNull.test.js.map +0 -1
  525. package/build/dist/Tests/Types/Database/InBetween.test.js +0 -72
  526. package/build/dist/Tests/Types/Database/InBetween.test.js.map +0 -1
  527. package/build/dist/Tests/Types/Database/LimitMax.test.js +0 -18
  528. package/build/dist/Tests/Types/Database/LimitMax.test.js.map +0 -1
  529. package/build/dist/Tests/Types/Database/NotEqual.test.js +0 -19
  530. package/build/dist/Tests/Types/Database/NotEqual.test.js.map +0 -1
  531. package/build/dist/Tests/Types/Database/Search.test.js +0 -10
  532. package/build/dist/Tests/Types/Database/Search.test.js.map +0 -1
  533. package/build/dist/Tests/Types/DatabaseType.test.js +0 -7
  534. package/build/dist/Tests/Types/DatabaseType.test.js.map +0 -1
  535. package/build/dist/Tests/Types/Date.test.js +0 -194
  536. package/build/dist/Tests/Types/Date.test.js.map +0 -1
  537. package/build/dist/Tests/Types/Dictionary.test.js +0 -25
  538. package/build/dist/Tests/Types/Dictionary.test.js.map +0 -1
  539. package/build/dist/Tests/Types/Domain.test.js +0 -54
  540. package/build/dist/Tests/Types/Domain.test.js.map +0 -1
  541. package/build/dist/Tests/Types/Email/Email.test.js +0 -51
  542. package/build/dist/Tests/Types/Email/Email.test.js.map +0 -1
  543. package/build/dist/Tests/Types/EmailWithName.test.js +0 -36
  544. package/build/dist/Tests/Types/EmailWithName.test.js.map +0 -1
  545. package/build/dist/Tests/Types/EncryptionAlgorithm.test.js +0 -7
  546. package/build/dist/Tests/Types/EncryptionAlgorithm.test.js.map +0 -1
  547. package/build/dist/Tests/Types/Exception/ApiException.test.js +0 -10
  548. package/build/dist/Tests/Types/Exception/ApiException.test.js.map +0 -1
  549. package/build/dist/Tests/Types/Exception/BadDataException.test.js +0 -12
  550. package/build/dist/Tests/Types/Exception/BadDataException.test.js.map +0 -1
  551. package/build/dist/Tests/Types/Exception/BadOperationException.test.js +0 -10
  552. package/build/dist/Tests/Types/Exception/BadOperationException.test.js.map +0 -1
  553. package/build/dist/Tests/Types/Exception/BadRequestException.test.js +0 -12
  554. package/build/dist/Tests/Types/Exception/BadRequestException.test.js.map +0 -1
  555. package/build/dist/Tests/Types/Exception/DatabaseNotConnectedException.test.js +0 -10
  556. package/build/dist/Tests/Types/Exception/DatabaseNotConnectedException.test.js.map +0 -1
  557. package/build/dist/Tests/Types/Exception/Exception.test.js +0 -15
  558. package/build/dist/Tests/Types/Exception/Exception.test.js.map +0 -1
  559. package/build/dist/Tests/Types/Exception/NotImplementedException.test.js +0 -12
  560. package/build/dist/Tests/Types/Exception/NotImplementedException.test.js.map +0 -1
  561. package/build/dist/Tests/Types/File.test.js +0 -22
  562. package/build/dist/Tests/Types/File.test.js.map +0 -1
  563. package/build/dist/Tests/Types/HashedString.test.js +0 -51
  564. package/build/dist/Tests/Types/HashedString.test.js.map +0 -1
  565. package/build/dist/Tests/Types/Html.test.js +0 -8
  566. package/build/dist/Tests/Types/Html.test.js.map +0 -1
  567. package/build/dist/Tests/Types/IP/IP.test.js +0 -65
  568. package/build/dist/Tests/Types/IP/IP.test.js.map +0 -1
  569. package/build/dist/Tests/Types/IP/IPType.test.js +0 -10
  570. package/build/dist/Tests/Types/IP/IPType.test.js.map +0 -1
  571. package/build/dist/Tests/Types/IP/IPv4.test.js +0 -17
  572. package/build/dist/Tests/Types/IP/IPv4.test.js.map +0 -1
  573. package/build/dist/Tests/Types/IP/IPv6.test.js +0 -17
  574. package/build/dist/Tests/Types/IP/IPv6.test.js.map +0 -1
  575. package/build/dist/Tests/Types/JSON.test.js +0 -37
  576. package/build/dist/Tests/Types/JSON.test.js.map +0 -1
  577. package/build/dist/Tests/Types/JSONFunctions.test.js +0 -38
  578. package/build/dist/Tests/Types/JSONFunctions.test.js.map +0 -1
  579. package/build/dist/Tests/Types/ListData.test.js +0 -34
  580. package/build/dist/Tests/Types/ListData.test.js.map +0 -1
  581. package/build/dist/Tests/Types/Monitor/KubernetesAlertTemplates.test.js +0 -121
  582. package/build/dist/Tests/Types/Monitor/KubernetesAlertTemplates.test.js.map +0 -1
  583. package/build/dist/Tests/Types/Name.test.js +0 -26
  584. package/build/dist/Tests/Types/Name.test.js.map +0 -1
  585. package/build/dist/Tests/Types/ObjectID.test.js +0 -12
  586. package/build/dist/Tests/Types/ObjectID.test.js.map +0 -1
  587. package/build/dist/Tests/Types/OnCallDutyPolicy/LayerUtil.test.js +0 -530
  588. package/build/dist/Tests/Types/OnCallDutyPolicy/LayerUtil.test.js.map +0 -1
  589. package/build/dist/Tests/Types/Permission.test.js +0 -99
  590. package/build/dist/Tests/Types/Permission.test.js.map +0 -1
  591. package/build/dist/Tests/Types/Phone.test.js +0 -37
  592. package/build/dist/Tests/Types/Phone.test.js.map +0 -1
  593. package/build/dist/Tests/Types/Port.test.js +0 -35
  594. package/build/dist/Tests/Types/Port.test.js.map +0 -1
  595. package/build/dist/Tests/Types/PositiveNumber.test.js +0 -101
  596. package/build/dist/Tests/Types/PositiveNumber.test.js.map +0 -1
  597. package/build/dist/Tests/Types/SecuritySeverity.test.js +0 -16
  598. package/build/dist/Tests/Types/SecuritySeverity.test.js.map +0 -1
  599. package/build/dist/Tests/Types/SerializableObject.test.js +0 -37
  600. package/build/dist/Tests/Types/SerializableObject.test.js.map +0 -1
  601. package/build/dist/Tests/Types/Sleep.test.js +0 -14
  602. package/build/dist/Tests/Types/Sleep.test.js.map +0 -1
  603. package/build/dist/Tests/Types/Text.test.js +0 -8
  604. package/build/dist/Tests/Types/Text.test.js.map +0 -1
  605. package/build/dist/Tests/Types/Timezone.test.js +0 -596
  606. package/build/dist/Tests/Types/Timezone.test.js.map +0 -1
  607. package/build/dist/Tests/Types/Typeof.test.js +0 -16
  608. package/build/dist/Tests/Types/Typeof.test.js.map +0 -1
  609. package/build/dist/Tests/Types/UserType.test.js +0 -16
  610. package/build/dist/Tests/Types/UserType.test.js.map +0 -1
  611. package/build/dist/Tests/Types/Version.test.js +0 -35
  612. package/build/dist/Tests/Types/Version.test.js.map +0 -1
  613. package/build/dist/Tests/Types/XML.test.js +0 -35
  614. package/build/dist/Tests/Types/XML.test.js.map +0 -1
  615. package/build/dist/Tests/UI/Components/404.test.js +0 -59
  616. package/build/dist/Tests/UI/Components/404.test.js.map +0 -1
  617. package/build/dist/Tests/UI/Components/Alert.test.js +0 -83
  618. package/build/dist/Tests/UI/Components/Alert.test.js.map +0 -1
  619. package/build/dist/Tests/UI/Components/Badge.test.js +0 -59
  620. package/build/dist/Tests/UI/Components/Badge.test.js.map +0 -1
  621. package/build/dist/Tests/UI/Components/BasicForm.test.js +0 -92
  622. package/build/dist/Tests/UI/Components/BasicForm.test.js.map +0 -1
  623. package/build/dist/Tests/UI/Components/Breadcrumbs.test.js +0 -69
  624. package/build/dist/Tests/UI/Components/Breadcrumbs.test.js.map +0 -1
  625. package/build/dist/Tests/UI/Components/Button.test.js +0 -104
  626. package/build/dist/Tests/UI/Components/Button.test.js.map +0 -1
  627. package/build/dist/Tests/UI/Components/Card.test.js +0 -81
  628. package/build/dist/Tests/UI/Components/Card.test.js.map +0 -1
  629. package/build/dist/Tests/UI/Components/ColorViewer.test.js +0 -42
  630. package/build/dist/Tests/UI/Components/ColorViewer.test.js.map +0 -1
  631. package/build/dist/Tests/UI/Components/ComponentsModal.test.js +0 -233
  632. package/build/dist/Tests/UI/Components/ComponentsModal.test.js.map +0 -1
  633. package/build/dist/Tests/UI/Components/ConfirmModal.test.js +0 -57
  634. package/build/dist/Tests/UI/Components/ConfirmModal.test.js.map +0 -1
  635. package/build/dist/Tests/UI/Components/DictionaryOfStrings.test.js +0 -84
  636. package/build/dist/Tests/UI/Components/DictionaryOfStrings.test.js.map +0 -1
  637. package/build/dist/Tests/UI/Components/Dropdown.test.js +0 -146
  638. package/build/dist/Tests/UI/Components/Dropdown.test.js.map +0 -1
  639. package/build/dist/Tests/UI/Components/DuplicateModel.test.js +0 -229
  640. package/build/dist/Tests/UI/Components/DuplicateModel.test.js.map +0 -1
  641. package/build/dist/Tests/UI/Components/EmptyState/EmptyState.test.js +0 -26
  642. package/build/dist/Tests/UI/Components/EmptyState/EmptyState.test.js.map +0 -1
  643. package/build/dist/Tests/UI/Components/ErrorBoundary.test.js +0 -32
  644. package/build/dist/Tests/UI/Components/ErrorBoundary.test.js.map +0 -1
  645. package/build/dist/Tests/UI/Components/FilePicker.test.js +0 -342
  646. package/build/dist/Tests/UI/Components/FilePicker.test.js.map +0 -1
  647. package/build/dist/Tests/UI/Components/HiddenText.test.js +0 -50
  648. package/build/dist/Tests/UI/Components/HiddenText.test.js.map +0 -1
  649. package/build/dist/Tests/UI/Components/Input.test.js +0 -223
  650. package/build/dist/Tests/UI/Components/Input.test.js.map +0 -1
  651. package/build/dist/Tests/UI/Components/Item.test.js +0 -58
  652. package/build/dist/Tests/UI/Components/Item.test.js.map +0 -1
  653. package/build/dist/Tests/UI/Components/List.test.js +0 -83
  654. package/build/dist/Tests/UI/Components/List.test.js.map +0 -1
  655. package/build/dist/Tests/UI/Components/Loader.test.js +0 -19
  656. package/build/dist/Tests/UI/Components/Loader.test.js.map +0 -1
  657. package/build/dist/Tests/UI/Components/MarkdownEditor.test.js +0 -85
  658. package/build/dist/Tests/UI/Components/MarkdownEditor.test.js.map +0 -1
  659. package/build/dist/Tests/UI/Components/MasterPage.test.js +0 -46
  660. package/build/dist/Tests/UI/Components/MasterPage.test.js.map +0 -1
  661. package/build/dist/Tests/UI/Components/Modal.test.js +0 -127
  662. package/build/dist/Tests/UI/Components/Modal.test.js.map +0 -1
  663. package/build/dist/Tests/UI/Components/NavBar.test.js +0 -52
  664. package/build/dist/Tests/UI/Components/NavBar.test.js.map +0 -1
  665. package/build/dist/Tests/UI/Components/OrderedStatesList.test.js +0 -86
  666. package/build/dist/Tests/UI/Components/OrderedStatesList.test.js.map +0 -1
  667. package/build/dist/Tests/UI/Components/Pagination.test.js +0 -137
  668. package/build/dist/Tests/UI/Components/Pagination.test.js.map +0 -1
  669. package/build/dist/Tests/UI/Components/Pill.test.js +0 -55
  670. package/build/dist/Tests/UI/Components/Pill.test.js.map +0 -1
  671. package/build/dist/Tests/UI/Components/Probe.test.js +0 -52
  672. package/build/dist/Tests/UI/Components/Probe.test.js.map +0 -1
  673. package/build/dist/Tests/UI/Components/ProgressBar.test.js +0 -41
  674. package/build/dist/Tests/UI/Components/ProgressBar.test.js.map +0 -1
  675. package/build/dist/Tests/UI/Components/RadioButtons.test.js +0 -66
  676. package/build/dist/Tests/UI/Components/RadioButtons.test.js.map +0 -1
  677. package/build/dist/Tests/UI/Components/SideMenuItem.test.js +0 -99
  678. package/build/dist/Tests/UI/Components/SideMenuItem.test.js.map +0 -1
  679. package/build/dist/Tests/UI/Components/SideOver.test.js +0 -77
  680. package/build/dist/Tests/UI/Components/SideOver.test.js.map +0 -1
  681. package/build/dist/Tests/UI/Components/Tabs.test.js +0 -56
  682. package/build/dist/Tests/UI/Components/Tabs.test.js.map +0 -1
  683. package/build/dist/Tests/UI/Components/Template/Template.test.js +0 -15
  684. package/build/dist/Tests/UI/Components/Template/Template.test.js.map +0 -1
  685. package/build/dist/Tests/UI/Components/TextArea.test.js +0 -112
  686. package/build/dist/Tests/UI/Components/TextArea.test.js.map +0 -1
  687. package/build/dist/Tests/UI/Components/TimePicker/TimePicker.test.js +0 -352
  688. package/build/dist/Tests/UI/Components/TimePicker/TimePicker.test.js.map +0 -1
  689. package/build/dist/Tests/UI/Components/Toast.test.js +0 -48
  690. package/build/dist/Tests/UI/Components/Toast.test.js.map +0 -1
  691. package/build/dist/Tests/UI/Components/Toggle.test.js +0 -95
  692. package/build/dist/Tests/UI/Components/Toggle.test.js.map +0 -1
  693. package/build/dist/Tests/UI/Components/TopSection.test.js +0 -33
  694. package/build/dist/Tests/UI/Components/TopSection.test.js.map +0 -1
  695. package/build/dist/Tests/UI/Components/XAxis.test.js +0 -21
  696. package/build/dist/Tests/UI/Components/XAxis.test.js.map +0 -1
  697. package/build/dist/Tests/UI/Index.js +0 -2
  698. package/build/dist/Tests/UI/Index.js.map +0 -1
  699. package/build/dist/Tests/UI/Mocks/FileMock.js +0 -3
  700. package/build/dist/Tests/UI/Mocks/FileMock.js.map +0 -1
  701. package/build/dist/Tests/Utils/API.test.js +0 -399
  702. package/build/dist/Tests/Utils/API.test.js.map +0 -1
  703. package/build/dist/Tests/Utils/Analytics.test.js +0 -67
  704. package/build/dist/Tests/Utils/Analytics.test.js.map +0 -1
  705. package/build/dist/Tests/Utils/CronTime.test.js +0 -22
  706. package/build/dist/Tests/Utils/CronTime.test.js.map +0 -1
  707. package/build/dist/Tests/Utils/Faker.test.js +0 -27
  708. package/build/dist/Tests/Utils/Faker.test.js.map +0 -1
  709. package/build/dist/Tests/Utils/MetricUnitUtil.test.js +0 -187
  710. package/build/dist/Tests/Utils/MetricUnitUtil.test.js.map +0 -1
  711. package/build/dist/Tests/Utils/Metrics/MetricFormulaEvaluator.test.js +0 -224
  712. package/build/dist/Tests/Utils/Metrics/MetricFormulaEvaluator.test.js.map +0 -1
  713. package/build/dist/Tests/Utils/Metrics/MetricResultUnitConverter.test.js +0 -180
  714. package/build/dist/Tests/Utils/Metrics/MetricResultUnitConverter.test.js.map +0 -1
  715. package/build/dist/Tests/Utils/RecordingRuleExpression.test.js +0 -142
  716. package/build/dist/Tests/Utils/RecordingRuleExpression.test.js.map +0 -1
  717. package/build/dist/Tests/Utils/Slug.test.js +0 -20
  718. package/build/dist/Tests/Utils/Slug.test.js.map +0 -1
  719. package/build/dist/Tests/Utils/UUID.test.js +0 -48
  720. package/build/dist/Tests/Utils/UUID.test.js.map +0 -1
  721. package/build/dist/Tests/jest.setup.js +0 -30
  722. package/build/dist/Tests/jest.setup.js.map +0 -1
  723. package/build/dist/Types/Profile/ProfileMetricType.js +0 -17
  724. package/build/dist/Types/Profile/ProfileMetricType.js.map +0 -1
@@ -1,910 +0,0 @@
1
- import getJestMockFunction from "../../MockType";
2
- import { ActiveMonitoringMeteredPlan } from "../../../Server/Types/Billing/MeteredPlan/AllMeteredPlans";
3
- import Errors from "../../../Server/Utils/Errors";
4
- import { getChangePlanData, getCouponData, getCustomerData, getMeteredSubscription, getStripeCustomer, getStripeInvoice, getStripeSubscription, getSubscriptionData, getSubscriptionPlanData, mockIsBillingEnabled, } from "../TestingUtils/Services/BillingServiceHelper";
5
- import { mockStripe } from "../TestingUtils/__mocks__/Stripe.mock";
6
- import { describe, expect, beforeEach, jest } from "@jest/globals";
7
- import MeteredPlan from "../../../Types/Billing/MeteredPlan";
8
- import SubscriptionStatus from "../../../Types/Billing/SubscriptionStatus";
9
- import OneUptimeDate from "../../../Types/Date";
10
- describe("BillingService", () => {
11
- let billingService;
12
- const customer = getCustomerData();
13
- const mockCustomer = getStripeCustomer(customer.id.toString());
14
- beforeEach(async () => {
15
- jest.clearAllMocks();
16
- billingService = await mockIsBillingEnabled(true);
17
- }, 10 * 1000);
18
- describe("Customer Management", () => {
19
- describe("createCustomer", () => {
20
- it("should create a customer when valid data is provided", async () => {
21
- mockStripe.customers.create =
22
- getJestMockFunction().mockResolvedValue(mockCustomer);
23
- const result = await billingService.createCustomer(customer);
24
- expect(result).toEqual(mockCustomer.id);
25
- expect(mockStripe.customers.create).toHaveBeenCalledWith({
26
- name: customer.name,
27
- email: customer.email.toString(),
28
- metadata: {
29
- id: customer.id.toString(),
30
- },
31
- });
32
- expect(result).toBe(mockCustomer.id);
33
- });
34
- it("should throw an exception if billing is not enabled", async () => {
35
- billingService = await mockIsBillingEnabled(false);
36
- await expect(billingService.createCustomer(customer)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
37
- });
38
- });
39
- describe("updateCustomerName", () => {
40
- it("should successfully update a customer name", async () => {
41
- const newName = "newName";
42
- await billingService.updateCustomerName(customer.id.toString(), newName);
43
- expect(mockStripe.customers.update).toHaveBeenCalledWith(customer.id.toString(), { name: newName });
44
- });
45
- it("should throw an exception if billing is not enabled for updating customer name", async () => {
46
- billingService = await mockIsBillingEnabled(false);
47
- await expect(billingService.updateCustomerName("cust_123", "Jane Doe")).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
48
- });
49
- });
50
- describe("deleteCustomer", () => {
51
- it("should successfully delete a customer", async () => {
52
- await billingService.deleteCustomer(customer.id.toString());
53
- expect(mockStripe.customers.del).toHaveBeenCalledWith(customer.id.toString());
54
- });
55
- it("should throw an exception if billing is not enabled for deleting customer", async () => {
56
- billingService = await mockIsBillingEnabled(false);
57
- await expect(billingService.deleteCustomer("cust_123")).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
58
- });
59
- });
60
- });
61
- describe("Subscription Management", () => {
62
- Object.defineProperty(global, "performance", {
63
- writable: true,
64
- });
65
- let mockDate = OneUptimeDate.getCurrentDate();
66
- let mockSubscription;
67
- const subscription = getSubscriptionData();
68
- const subscriptionPlan = getSubscriptionPlanData();
69
- const meteredSubscription = getMeteredSubscription(subscriptionPlan);
70
- beforeEach(() => {
71
- mockSubscription = getStripeSubscription();
72
- mockDate = OneUptimeDate.getCurrentDate();
73
- });
74
- describe("subscribeToMeteredPlan", () => {
75
- it("should successfully create a metered plan subscription with all required parameters", async () => {
76
- mockStripe.subscriptions.create =
77
- getJestMockFunction().mockResolvedValue(mockSubscription);
78
- const result = await billingService.subscribeToMeteredPlan(subscription);
79
- expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
80
- customer: subscription.customerId,
81
- items: [],
82
- trial_end: "now",
83
- }));
84
- expect(result.meteredSubscriptionId).toBe(mockSubscription.id);
85
- expect(result.trialEndsAt).toBe(subscription.trialDate);
86
- });
87
- it("should create a metered plan subscription with a trial date in the future", async () => {
88
- const futureDate = new Date();
89
- futureDate.setDate(futureDate.getDate() + 10); // 10 days in the future
90
- subscription.trialDate = futureDate;
91
- mockStripe.subscriptions.create =
92
- getJestMockFunction().mockResolvedValue(mockSubscription);
93
- await billingService.subscribeToMeteredPlan(subscription);
94
- expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
95
- trial_end: Math.floor(subscription.trialDate.getTime() / 1000),
96
- }));
97
- });
98
- it("should create a subscription without a trial when the trial date is not in the future", async () => {
99
- const pastDate = new Date("2020-01-01");
100
- subscription.trialDate = pastDate;
101
- mockStripe.subscriptions.create =
102
- getJestMockFunction().mockResolvedValue(mockSubscription);
103
- await billingService.subscribeToMeteredPlan(subscription);
104
- expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
105
- trial_end: "now",
106
- }));
107
- });
108
- it("should handle API errors during subscription creation", async () => {
109
- mockStripe.subscriptions.create =
110
- getJestMockFunction().mockImplementation(() => {
111
- throw new Error("Stripe API error");
112
- });
113
- await expect(billingService.subscribeToMeteredPlan(subscription)).rejects.toThrowError("Stripe API error");
114
- });
115
- it("should correctly handle the promo code", async () => {
116
- subscription.promoCode = "VALIDPROMO";
117
- mockStripe.subscriptions.create =
118
- getJestMockFunction().mockResolvedValue(mockSubscription);
119
- await billingService.subscribeToMeteredPlan(subscription);
120
- expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
121
- coupon: subscription.promoCode,
122
- }));
123
- });
124
- it("should set the default payment method if provided", async () => {
125
- subscription.defaultPaymentMethodId = "pm_123";
126
- mockStripe.subscriptions.create =
127
- getJestMockFunction().mockResolvedValue(mockSubscription);
128
- await billingService.subscribeToMeteredPlan(subscription);
129
- expect(mockStripe.subscriptions.create).toHaveBeenCalledWith(expect.objectContaining({
130
- default_payment_method: subscription.defaultPaymentMethodId,
131
- }));
132
- });
133
- });
134
- describe("subscribeToPlan", () => {
135
- it("should not subscribe to plan if billing is not enabled", async () => {
136
- billingService = await mockIsBillingEnabled(false);
137
- await expect(billingService.subscribeToPlan(meteredSubscription)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
138
- });
139
- it("should successfully subscribe a customer to a plan", async () => {
140
- var _a, _b;
141
- const mockSubscription2 = getStripeSubscription();
142
- mockStripe.subscriptions.create = getJestMockFunction()
143
- .mockResolvedValueOnce(mockSubscription)
144
- .mockResolvedValueOnce(mockSubscription2);
145
- const result = await billingService.subscribeToPlan(meteredSubscription);
146
- expect(result.subscriptionId).toEqual(mockSubscription.id);
147
- expect(result.meteredSubscriptionId).toEqual(mockSubscription2.id);
148
- const datePlusTrialDays = OneUptimeDate.addRemoveDays(mockDate, subscriptionPlan.getTrialPeriod());
149
- const datePlusTrialDaysNumber = datePlusTrialDays.getTime();
150
- expect((_a = result.trialEndsAt) === null || _a === void 0 ? void 0 : _a.toString()).toBeTruthy();
151
- expect((_b = result.trialEndsAt) === null || _b === void 0 ? void 0 : _b.toString()).toEqual(datePlusTrialDays.toString());
152
- expect(mockStripe.subscriptions.create).toHaveBeenCalledTimes(2);
153
- expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(1, expect.objectContaining({
154
- customer: meteredSubscription.customerId,
155
- items: expect.arrayContaining([
156
- expect.objectContaining({
157
- price: meteredSubscription.isYearly
158
- ? subscriptionPlan.getYearlyPlanId()
159
- : subscriptionPlan.getMonthlyPlanId(),
160
- quantity: meteredSubscription.quantity,
161
- }),
162
- ]),
163
- trial_end: Math.floor(datePlusTrialDaysNumber / 1000),
164
- }));
165
- expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(2, expect.objectContaining({
166
- customer: meteredSubscription.customerId,
167
- trial_end: Math.floor(datePlusTrialDaysNumber / 1000),
168
- }));
169
- });
170
- it("should subscribe without a trial when trial is false", async () => {
171
- meteredSubscription.trial = false;
172
- const mockSubscription2 = getStripeSubscription();
173
- mockStripe.subscriptions.create = getJestMockFunction()
174
- .mockResolvedValueOnce(mockSubscription)
175
- .mockResolvedValueOnce(mockSubscription2);
176
- const result = await billingService.subscribeToPlan(meteredSubscription);
177
- expect(result.subscriptionId).toEqual(mockSubscription.id);
178
- expect(result.meteredSubscriptionId).toEqual(mockSubscription2.id);
179
- expect(result.trialEndsAt).toBeNull();
180
- expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(1, expect.objectContaining({
181
- customer: meteredSubscription.customerId,
182
- items: expect.arrayContaining([
183
- expect.objectContaining({
184
- price: meteredSubscription.isYearly
185
- ? subscriptionPlan.getYearlyPlanId()
186
- : subscriptionPlan.getMonthlyPlanId(),
187
- quantity: meteredSubscription.quantity,
188
- }),
189
- ]),
190
- trial_end: "now",
191
- }));
192
- expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(2, expect.objectContaining({
193
- customer: meteredSubscription.customerId,
194
- trial_end: "now",
195
- }));
196
- });
197
- it("should apply a promo code if provided", async () => {
198
- meteredSubscription.promoCode = "PROMO123";
199
- const mockSubscription2 = getStripeSubscription();
200
- mockStripe.subscriptions.create = getJestMockFunction()
201
- .mockResolvedValueOnce(mockSubscription)
202
- .mockResolvedValueOnce(mockSubscription2);
203
- const result = await billingService.subscribeToPlan(meteredSubscription);
204
- expect(result.subscriptionId).toEqual(mockSubscription.id);
205
- expect(result.meteredSubscriptionId).toEqual(mockSubscription2.id);
206
- expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(1, expect.objectContaining({
207
- customer: meteredSubscription.customerId,
208
- items: expect.arrayContaining([
209
- expect.objectContaining({
210
- price: meteredSubscription.isYearly
211
- ? subscriptionPlan.getYearlyPlanId()
212
- : subscriptionPlan.getMonthlyPlanId(),
213
- quantity: meteredSubscription.quantity,
214
- }),
215
- ]),
216
- coupon: meteredSubscription.promoCode,
217
- }));
218
- expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(2, expect.objectContaining({
219
- customer: meteredSubscription.customerId,
220
- coupon: meteredSubscription.promoCode,
221
- }));
222
- });
223
- it("should set the default payment method if provided", async () => {
224
- meteredSubscription.defaultPaymentMethodId = "pm_123";
225
- const mockSubscription2 = getStripeSubscription();
226
- mockStripe.subscriptions.create = getJestMockFunction()
227
- .mockResolvedValueOnce(mockSubscription)
228
- .mockResolvedValueOnce(mockSubscription2);
229
- const result = await billingService.subscribeToPlan(meteredSubscription);
230
- expect(result.subscriptionId).toEqual(mockSubscription.id);
231
- expect(result.meteredSubscriptionId).toEqual(mockSubscription2.id);
232
- expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(1, expect.objectContaining({
233
- customer: meteredSubscription.customerId,
234
- items: expect.arrayContaining([
235
- expect.objectContaining({
236
- price: meteredSubscription.isYearly
237
- ? subscriptionPlan.getYearlyPlanId()
238
- : subscriptionPlan.getMonthlyPlanId(),
239
- quantity: meteredSubscription.quantity,
240
- }),
241
- ]),
242
- default_payment_method: meteredSubscription.defaultPaymentMethodId,
243
- }));
244
- expect(mockStripe.subscriptions.create).toHaveBeenNthCalledWith(2, expect.objectContaining({
245
- customer: meteredSubscription.customerId,
246
- default_payment_method: meteredSubscription.defaultPaymentMethodId,
247
- }));
248
- });
249
- });
250
- describe("changeQuantity", () => {
251
- it("should not change quantity if billing is not enabled", async () => {
252
- billingService = await mockIsBillingEnabled(false);
253
- await expect(billingService.changeQuantity(mockSubscription.id, 1)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
254
- });
255
- it("should successfully change the quantity of a subscription", async () => {
256
- var _a, _b;
257
- const newQuantity = 2;
258
- mockStripe.subscriptions.retrieve =
259
- getJestMockFunction().mockResolvedValue(mockSubscription);
260
- mockStripe.subscriptions.update =
261
- getJestMockFunction().mockResolvedValue({});
262
- await billingService.changeQuantity(mockSubscription.id, newQuantity);
263
- expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(mockSubscription.id);
264
- expect(mockStripe.subscriptionItems.update).toHaveBeenCalledWith((_b = (_a = mockSubscription.items) === null || _a === void 0 ? void 0 : _a.data[0]) === null || _b === void 0 ? void 0 : _b.id, {
265
- quantity: newQuantity,
266
- });
267
- });
268
- it("should handle subscription not found scenario in change quantity", async () => {
269
- mockStripe.subscriptions.retrieve =
270
- getJestMockFunction().mockResolvedValue(null);
271
- await expect(billingService.changeQuantity("invalid_id", 2)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
272
- });
273
- it("should not change quantity if the subscription is canceled", async () => {
274
- mockSubscription.status = "canceled";
275
- mockStripe.subscriptions.retrieve =
276
- getJestMockFunction().mockResolvedValue(mockSubscription);
277
- await billingService.changeQuantity(mockSubscription.id, 2);
278
- expect(mockStripe.subscriptions.retrieve).toHaveBeenCalled();
279
- expect(mockStripe.subscriptions.update).not.toHaveBeenCalled();
280
- });
281
- it("should handle missing subscription item ID in the subscription", async () => {
282
- mockSubscription.items.data = [];
283
- mockStripe.subscriptions.retrieve =
284
- getJestMockFunction().mockResolvedValue(mockSubscription);
285
- await expect(billingService.changeQuantity(mockSubscription.id, 2)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_ITEM_NOT_FOUND);
286
- });
287
- });
288
- describe("changePlan", () => {
289
- const newPlan = getChangePlanData(getSubscriptionPlanData());
290
- it("should throw if billing is not enabled", async () => {
291
- billingService = await mockIsBillingEnabled(false);
292
- await expect(billingService.changePlan(newPlan)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
293
- });
294
- it("should successfully change the plan", async () => {
295
- // mocks
296
- mockStripe.subscriptions.retrieve =
297
- getJestMockFunction().mockResolvedValue(mockSubscription);
298
- mockStripe.subscriptions.del = getJestMockFunction().mockResolvedValue({});
299
- const newMockSubscription = getStripeSubscription();
300
- const newMockMeteredSubscription = getStripeSubscription();
301
- mockStripe.subscriptions.create = getJestMockFunction()
302
- .mockResolvedValueOnce(newMockSubscription)
303
- .mockResolvedValueOnce(newMockMeteredSubscription);
304
- const mockPaymentMethods = [
305
- {
306
- id: "pm_123",
307
- type: "card",
308
- last4Digits: "4242",
309
- isDefault: true,
310
- },
311
- ];
312
- billingService.getPaymentMethods =
313
- getJestMockFunction().mockResolvedValue(mockPaymentMethods);
314
- const result = await billingService.changePlan(newPlan);
315
- expect(result.subscriptionId).toEqual(newMockSubscription.id);
316
- expect(result.meteredSubscriptionId).toEqual(newMockMeteredSubscription.id);
317
- expect(mockStripe.subscriptions.del).toHaveBeenCalled();
318
- expect(mockStripe.subscriptions.del).toHaveBeenCalled();
319
- expect(mockStripe.subscriptions.create).toHaveBeenCalled();
320
- });
321
- it("should handle errors when the current subscription is not found", async () => {
322
- mockStripe.subscriptions.retrieve =
323
- getJestMockFunction().mockResolvedValue(null);
324
- await expect(billingService.changePlan(newPlan)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
325
- });
326
- it("should check for active payment methods before changing the plan", async () => {
327
- mockStripe.subscriptions.retrieve =
328
- getJestMockFunction().mockResolvedValue(mockSubscription);
329
- const mockPaymentMethods = Array();
330
- billingService.getPaymentMethods =
331
- getJestMockFunction().mockResolvedValue(mockPaymentMethods);
332
- await expect(billingService.changePlan(newPlan)).rejects.toThrow(Errors.BillingService.NO_PAYMENTS_METHODS);
333
- });
334
- });
335
- describe("isSubscriptionActive", () => {
336
- it("should return true for an active subscription status", () => {
337
- const activeStatuses = [
338
- SubscriptionStatus.Active,
339
- SubscriptionStatus.Trialing,
340
- ];
341
- activeStatuses.forEach((status) => {
342
- expect(billingService.isSubscriptionActive(status)).toBeTruthy();
343
- });
344
- });
345
- it("should return false for an inactive subscription status", () => {
346
- const inactiveStatuses = [
347
- SubscriptionStatus.Incomplete,
348
- SubscriptionStatus.IncompleteExpired,
349
- SubscriptionStatus.Canceled,
350
- SubscriptionStatus.Unpaid,
351
- ];
352
- inactiveStatuses.forEach((status) => {
353
- expect(billingService.isSubscriptionActive(status)).toBeFalsy();
354
- });
355
- });
356
- });
357
- describe("addOrUpdateMeteredPricingOnSubscription", () => {
358
- const quantity = 10;
359
- it("should throw if billing is not enabled", async () => {
360
- billingService = await mockIsBillingEnabled(false);
361
- await expect(billingService.addOrUpdateMeteredPricingOnSubscription(mockSubscription.id, ActiveMonitoringMeteredPlan, quantity)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
362
- });
363
- it("should successfully add metered pricing to a subscription", async () => {
364
- var _a;
365
- const subscriptionItem = mockSubscription.items.data[0];
366
- const meteredPlan = new MeteredPlan({
367
- priceId: ((_a = subscriptionItem === null || subscriptionItem === void 0 ? void 0 : subscriptionItem.price) === null || _a === void 0 ? void 0 : _a.id) || "",
368
- pricePerUnitInUSD: 100,
369
- unitName: "unit",
370
- });
371
- mockSubscription.items.data = [];
372
- mockStripe.subscriptions.retrieve =
373
- getJestMockFunction().mockResolvedValue(mockSubscription);
374
- mockStripe.subscriptionItems.create =
375
- getJestMockFunction().mockResolvedValue({ id: "sub_item_123" });
376
- mockStripe.subscriptionItems.createUsageRecord =
377
- getJestMockFunction().mockResolvedValue({});
378
- await billingService.addOrUpdateMeteredPricingOnSubscription(mockSubscription.id, ActiveMonitoringMeteredPlan, quantity);
379
- expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(mockSubscription.id);
380
- expect(mockStripe.subscriptionItems.create).toHaveBeenCalledWith({
381
- subscription: mockSubscription.id,
382
- price: meteredPlan.getPriceId(),
383
- });
384
- expect(mockStripe.subscriptionItems.createUsageRecord).toHaveBeenCalledWith("sub_item_123", { quantity });
385
- });
386
- it("should successfully update existing metered pricing on a subscription", async () => {
387
- const subscriptionItem = mockSubscription.items.data[0];
388
- mockStripe.subscriptions.retrieve =
389
- getJestMockFunction().mockResolvedValue(mockSubscription);
390
- mockStripe.subscriptionItems.createUsageRecord =
391
- getJestMockFunction().mockResolvedValue({});
392
- await billingService.addOrUpdateMeteredPricingOnSubscription(mockSubscription.id, ActiveMonitoringMeteredPlan, quantity);
393
- expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(mockSubscription.id);
394
- expect(mockStripe.subscriptionItems.createUsageRecord).toHaveBeenCalledWith(subscriptionItem === null || subscriptionItem === void 0 ? void 0 : subscriptionItem.id, {
395
- quantity: quantity,
396
- });
397
- });
398
- it("should handle non-existent subscription", async () => {
399
- const subscriptionId = "sub_nonexistent";
400
- mockStripe.subscriptions.retrieve =
401
- getJestMockFunction().mockResolvedValue(null);
402
- await expect(billingService.addOrUpdateMeteredPricingOnSubscription(subscriptionId, ActiveMonitoringMeteredPlan, quantity)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
403
- });
404
- });
405
- describe("isPromoCodeValid", () => {
406
- it("should throw if billing is not enabled", async () => {
407
- billingService = await mockIsBillingEnabled(false);
408
- await expect(billingService.isPromoCodeValid("INVALID_PROMO_CODE")).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
409
- });
410
- it("should return true for a valid promo code", async () => {
411
- const promoCode = "VALIDPROMO";
412
- const mockCoupon = { valid: true };
413
- mockStripe.coupons.retrieve =
414
- getJestMockFunction().mockResolvedValue(mockCoupon);
415
- const isValid = await billingService.isPromoCodeValid(promoCode);
416
- expect(isValid).toBeTruthy();
417
- expect(mockStripe.coupons.retrieve).toHaveBeenCalledWith(promoCode);
418
- });
419
- it("should return false for an invalid or expired promo code", async () => {
420
- const promoCode = "INVALIDPROMO";
421
- const mockCoupon = {
422
- valid: false,
423
- };
424
- mockStripe.coupons.retrieve =
425
- getJestMockFunction().mockResolvedValue(mockCoupon);
426
- const isValid = await billingService.isPromoCodeValid(promoCode);
427
- expect(isValid).toBeFalsy();
428
- expect(mockStripe.coupons.retrieve).toHaveBeenCalledWith(promoCode);
429
- });
430
- it("should handle non-existent promo code", async () => {
431
- const promoCode = "NONEXISTENTPROMO";
432
- mockStripe.coupons.retrieve =
433
- getJestMockFunction().mockResolvedValue(null);
434
- await expect(billingService.isPromoCodeValid(promoCode)).rejects.toThrow(Errors.BillingService.PROMO_CODE_NOT_FOUND);
435
- expect(mockStripe.coupons.retrieve).toHaveBeenCalledWith(promoCode);
436
- });
437
- it("should handle errors from the Stripe API", async () => {
438
- const promoCode = "ERRORPROMO";
439
- mockStripe.coupons.retrieve = getJestMockFunction().mockImplementation(() => {
440
- throw new Error();
441
- });
442
- await expect(billingService.isPromoCodeValid(promoCode)).rejects.toThrow(Errors.BillingService.PROMO_CODE_INVALID);
443
- });
444
- });
445
- describe("removeSubscriptionItem", () => {
446
- const subscriptionId = "sub_123";
447
- const subscriptionItemId = "si_123";
448
- const isMeteredSubscriptionItem = false;
449
- it("should throw if billing is not enabled", async () => {
450
- billingService = await mockIsBillingEnabled(false);
451
- await expect(billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
452
- });
453
- it("should successfully remove a metered subscription item", async () => {
454
- const isMeteredSubscriptionItem = true;
455
- mockStripe.subscriptions.retrieve =
456
- getJestMockFunction().mockResolvedValue(mockSubscription);
457
- mockStripe.subscriptionItems.del =
458
- getJestMockFunction().mockResolvedValue({});
459
- await billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem);
460
- expect(mockStripe.subscriptionItems.del).toHaveBeenCalledWith(subscriptionItemId, {
461
- proration_behavior: "create_prorations",
462
- clear_usage: true,
463
- });
464
- });
465
- it("should successfully remove a metered subscription item when isMeteredSubscriptionItem", async () => {
466
- var _a;
467
- const subscriptionItemId = ((_a = mockSubscription.items.data[0]) === null || _a === void 0 ? void 0 : _a.id) || "";
468
- mockStripe.subscriptions.retrieve =
469
- getJestMockFunction().mockResolvedValue(mockSubscription);
470
- mockStripe.subscriptionItems.del =
471
- getJestMockFunction().mockResolvedValue({});
472
- await billingService.removeSubscriptionItem(mockSubscription.id, subscriptionItemId, isMeteredSubscriptionItem);
473
- expect(mockStripe.subscriptionItems.del).toHaveBeenCalledWith(subscriptionItemId, {});
474
- });
475
- it("should handle non-existent subscription or subscription item", async () => {
476
- mockStripe.subscriptions.retrieve =
477
- getJestMockFunction().mockResolvedValue(null);
478
- await expect(billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
479
- });
480
- it("should handle errors from the Stripe API", async () => {
481
- mockStripe.subscriptions.retrieve =
482
- getJestMockFunction().mockResolvedValue(mockSubscription);
483
- mockStripe.subscriptionItems.del =
484
- getJestMockFunction().mockImplementation(() => {
485
- throw new Error("Stripe API error");
486
- });
487
- await expect(billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem)).rejects.toThrow("Stripe API error");
488
- });
489
- it("should not remove an item if the subscription is canceled", async () => {
490
- const isMeteredSubscriptionItem = false;
491
- mockSubscription.status = "canceled";
492
- mockStripe.subscriptions.retrieve =
493
- getJestMockFunction().mockResolvedValue(mockSubscription);
494
- mockStripe.subscriptionItems.del = getJestMockFunction();
495
- await billingService.removeSubscriptionItem(subscriptionId, subscriptionItemId, isMeteredSubscriptionItem);
496
- expect(mockStripe.subscriptions.del).not.toHaveBeenCalled();
497
- });
498
- });
499
- describe("getSubscriptionItems", () => {
500
- it("should throw if billing is not enabled", async () => {
501
- billingService = await mockIsBillingEnabled(false);
502
- await expect(billingService.getSubscriptionItems(mockSubscription.id)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
503
- });
504
- it("should successfully retrieve subscription items for a given subscription", async () => {
505
- mockSubscription.items.data = [
506
- // @ts-expect-error - Simplified mock object for testing without all required Stripe SubscriptionItem properties
507
- { id: "item_1", price: { id: "price_123" } },
508
- // @ts-expect-error - Simplified mock object for testing without all required Stripe SubscriptionItem properties
509
- { id: "item_2", price: { id: "price_456" } },
510
- ];
511
- mockStripe.subscriptions.retrieve =
512
- getJestMockFunction().mockResolvedValue(mockSubscription);
513
- const items = await billingService.getSubscriptionItems(mockSubscription.id);
514
- expect(items).toEqual(mockSubscription.items.data);
515
- expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(mockSubscription.id);
516
- });
517
- it("should handle the case where the subscription does not exist", async () => {
518
- const subscriptionId = "sub_nonexistent";
519
- mockStripe.subscriptions.retrieve =
520
- getJestMockFunction().mockResolvedValue(null);
521
- await expect(billingService.getSubscriptionItems(subscriptionId)).rejects.toThrow(Errors.BillingService.SUBSCRIPTION_NOT_FOUND);
522
- });
523
- });
524
- });
525
- describe("Payment & Billing", () => {
526
- const customerId = "cust_123";
527
- const invoiceId = "inv_123";
528
- const paymentMethodId = "pm_123";
529
- const subscriptionId = "sub_123";
530
- const mockPaymentMethods = [
531
- {
532
- id: "pm_123",
533
- type: "card",
534
- last4Digits: "4242",
535
- isDefault: true,
536
- },
537
- {
538
- id: "pm_456",
539
- type: "card",
540
- last4Digits: "4343",
541
- isDefault: false,
542
- },
543
- ];
544
- describe("generateCouponCode", () => {
545
- const couponData = getCouponData();
546
- const mockCoupon = {
547
- id: "coupon_123",
548
- valid: true,
549
- };
550
- it("should successfully generate a coupon code", async () => {
551
- mockStripe.coupons.create =
552
- getJestMockFunction().mockResolvedValue(mockCoupon);
553
- const result = await billingService.generateCouponCode(couponData);
554
- expect(result).toEqual(mockCoupon.id);
555
- expect(mockStripe.coupons.create).toHaveBeenCalledWith(expect.objectContaining({
556
- name: couponData.name,
557
- percent_off: couponData.percentOff,
558
- duration: "repeating",
559
- duration_in_months: couponData.durationInMonths,
560
- max_redemptions: couponData.maxRedemptions,
561
- metadata: couponData.metadata,
562
- }));
563
- });
564
- });
565
- describe("deletePaymentMethod", () => {
566
- it("should throw if billing is not enabled", async () => {
567
- billingService = await mockIsBillingEnabled(false);
568
- await expect(billingService.deletePaymentMethod(customerId, paymentMethodId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
569
- });
570
- it("should successfully delete a payment method", async () => {
571
- billingService.getPaymentMethods =
572
- getJestMockFunction().mockResolvedValue(mockPaymentMethods);
573
- mockStripe.paymentMethods.detach =
574
- getJestMockFunction().mockResolvedValue({});
575
- await billingService.deletePaymentMethod(customerId, paymentMethodId);
576
- expect(mockStripe.paymentMethods.detach).toHaveBeenCalledWith(paymentMethodId);
577
- });
578
- it("should throw an exception if it's the only payment method", async () => {
579
- // mock a single payment method to simulate a scenario where deletion is not allowed
580
- const mockSinglePaymentMethod = [
581
- {
582
- id: paymentMethodId,
583
- type: "card",
584
- last4Digits: "4242",
585
- isDefault: true,
586
- },
587
- ];
588
- billingService.getPaymentMethods =
589
- getJestMockFunction().mockResolvedValue(mockSinglePaymentMethod);
590
- await expect(billingService.deletePaymentMethod(customerId, paymentMethodId)).rejects.toThrow(Errors.BillingService.MIN_REQUIRED_PAYMENT_METHOD_NOT_MET);
591
- });
592
- });
593
- describe("hasPaymentMethods", () => {
594
- it("should return true if the customer has payment methods", async () => {
595
- billingService.getPaymentMethods =
596
- getJestMockFunction().mockResolvedValue(mockPaymentMethods);
597
- const result = await billingService.hasPaymentMethods(customerId);
598
- expect(result).toBeTruthy();
599
- expect(billingService.getPaymentMethods).toHaveBeenCalledWith(customerId);
600
- });
601
- it("should return false if the customer does not have payment methods", async () => {
602
- const mockEmptyPaymentMethods = Array();
603
- billingService.getPaymentMethods =
604
- getJestMockFunction().mockResolvedValue(mockEmptyPaymentMethods);
605
- const result = await billingService.hasPaymentMethods(customerId);
606
- expect(result).toBeFalsy();
607
- expect(billingService.getPaymentMethods).toHaveBeenCalledWith(customerId);
608
- });
609
- });
610
- describe("getPaymentMethods", () => {
611
- it("should throw if billing is not enabled", async () => {
612
- billingService = await mockIsBillingEnabled(false);
613
- await expect(billingService.getPaymentMethods(customerId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
614
- });
615
- it("should return all payment methods for a customer", async () => {
616
- var _a, _b;
617
- const mockPaymentMethodsResponse = {
618
- data: [
619
- {
620
- id: "pm_123",
621
- type: "card",
622
- // @ts-expect-error - Simplified mock card object for testing without all required Stripe card properties
623
- card: { last4: "4242", brand: "mastercard" },
624
- isDefault: true,
625
- },
626
- {
627
- id: "pm_456",
628
- type: "card",
629
- // @ts-expect-error - Simplified mock card object for testing without all required Stripe card properties
630
- card: { last4: "4343", brand: "mastercard" },
631
- isDefault: true,
632
- },
633
- ],
634
- };
635
- mockStripe.paymentMethods.list = getJestMockFunction()
636
- .mockResolvedValueOnce(mockPaymentMethodsResponse)
637
- .mockResolvedValue({ data: [] });
638
- mockStripe.customers.retrieve =
639
- getJestMockFunction().mockResolvedValue(mockCustomer);
640
- const paymentMethods = await billingService.getPaymentMethods(customerId);
641
- expect(paymentMethods).toHaveLength(2);
642
- expect((_a = paymentMethods[0]) === null || _a === void 0 ? void 0 : _a.id).toBe("pm_123");
643
- expect((_b = paymentMethods[0]) === null || _b === void 0 ? void 0 : _b.last4Digits).toBe("4242");
644
- expect(mockStripe.paymentMethods.list).toHaveBeenCalledWith({
645
- customer: customerId,
646
- type: "card",
647
- });
648
- });
649
- it("should return an empty array if no payment methods are present", async () => {
650
- const mockEmptyPaymentMethodsResponse = { data: [] };
651
- mockStripe.paymentMethods.list =
652
- getJestMockFunction().mockResolvedValue(mockEmptyPaymentMethodsResponse);
653
- mockStripe.customers.retrieve =
654
- getJestMockFunction().mockResolvedValue(mockCustomer);
655
- const paymentMethods = await billingService.getPaymentMethods(customerId);
656
- expect(paymentMethods).toEqual([]);
657
- expect(mockStripe.paymentMethods.list).toHaveBeenCalledWith({
658
- customer: customerId,
659
- type: "card",
660
- });
661
- });
662
- });
663
- describe("getSetupIntentSecret", () => {
664
- it("should successfully return a setup intent secret", async () => {
665
- const mockSetupIntent = {
666
- client_secret: "seti_123_secret_xyz",
667
- };
668
- mockStripe.setupIntents.create =
669
- getJestMockFunction().mockResolvedValue(mockSetupIntent);
670
- const secret = await billingService.getSetupIntentSecret(customerId);
671
- expect(secret).toBe(mockSetupIntent.client_secret);
672
- expect(mockStripe.setupIntents.create).toHaveBeenCalledWith({
673
- customer: customerId,
674
- });
675
- });
676
- it("should handle missing client secret in the response", async () => {
677
- mockStripe.setupIntents.create =
678
- getJestMockFunction().mockResolvedValue({});
679
- await expect(billingService.getSetupIntentSecret(customerId)).rejects.toThrow(Errors.BillingService.CLIENT_SECRET_MISSING);
680
- });
681
- });
682
- describe("cancelSubscription", () => {
683
- it("should successfully cancel a subscription", async () => {
684
- mockStripe.subscriptions.del = getJestMockFunction().mockResolvedValue({
685
- id: subscriptionId,
686
- status: "canceled",
687
- });
688
- await billingService.cancelSubscription(subscriptionId);
689
- expect(mockStripe.subscriptions.del).toHaveBeenCalledWith(subscriptionId);
690
- });
691
- it("should handle errors from the Stripe API", async () => {
692
- const subscriptionId = "sub_123";
693
- // mock an error response from the Stripe API
694
- mockStripe.subscriptions.del = getJestMockFunction().mockImplementation(() => {
695
- throw new Error("Stripe API error");
696
- });
697
- await billingService.cancelSubscription(subscriptionId);
698
- // todo: we could expect the error to be logged
699
- });
700
- it("should not cancel a subscription if billing is not enabled", async () => {
701
- const subscriptionId = "sub_123";
702
- billingService = await mockIsBillingEnabled(false);
703
- await expect(billingService.cancelSubscription(subscriptionId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
704
- expect(mockStripe.subscriptions.del).not.toHaveBeenCalled();
705
- });
706
- });
707
- describe("getSubscriptionStatus", () => {
708
- const expectedStatus = SubscriptionStatus.Active;
709
- it("should successfully retrieve the subscription status", async () => {
710
- mockStripe.subscriptions.retrieve =
711
- getJestMockFunction().mockResolvedValue({
712
- id: subscriptionId,
713
- status: expectedStatus,
714
- });
715
- const status = await billingService.getSubscriptionStatus(subscriptionId);
716
- expect(status).toBe(expectedStatus);
717
- expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(subscriptionId);
718
- });
719
- it("should successfully retrieve the subscription status", async () => {
720
- mockStripe.subscriptions.retrieve =
721
- getJestMockFunction().mockResolvedValue({
722
- id: subscriptionId,
723
- status: expectedStatus,
724
- });
725
- const status = await billingService.getSubscriptionStatus(subscriptionId);
726
- expect(status).toBe(expectedStatus);
727
- expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(subscriptionId);
728
- });
729
- });
730
- describe("getSubscription", () => {
731
- it("should throw if billing is not enabled", async () => {
732
- billingService = await mockIsBillingEnabled(false);
733
- await expect(billingService.getSubscription(subscriptionId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
734
- });
735
- it("should successfully retrieve subscription data", async () => {
736
- const subscriptionId = "sub_123";
737
- const mockSubscription = getStripeSubscription();
738
- mockStripe.subscriptions.retrieve =
739
- getJestMockFunction().mockResolvedValue(mockSubscription);
740
- const subscription = await billingService.getSubscription(subscriptionId);
741
- expect(subscription).toEqual(mockSubscription);
742
- expect(mockStripe.subscriptions.retrieve).toHaveBeenCalledWith(subscriptionId);
743
- });
744
- });
745
- describe("getInvoices", () => {
746
- it("should successfully retrieve a list of invoices for a customer", async () => {
747
- const mockInvoices = {
748
- data: [getStripeInvoice(), getStripeInvoice()],
749
- };
750
- mockStripe.invoices.list =
751
- getJestMockFunction().mockResolvedValue(mockInvoices);
752
- const invoices = await billingService.getInvoices(customerId);
753
- expect(invoices).toEqual(mockInvoices.data.map((invoice) => {
754
- return {
755
- id: invoice.id,
756
- amount: invoice.amount_due,
757
- currencyCode: invoice.currency,
758
- customerId: invoice.customer,
759
- downloadableLink: "",
760
- status: "paid",
761
- subscriptionId: invoice.subscription,
762
- invoiceNumber: invoice.number,
763
- invoiceDate: new Date(invoice.created * 1000),
764
- };
765
- }));
766
- expect(mockStripe.invoices.list).toHaveBeenCalledWith({
767
- customer: customerId,
768
- limit: 100,
769
- });
770
- });
771
- it("should return an empty array if no invoices are found for the customer", async () => {
772
- const mockEmptyInvoices = { data: [] };
773
- mockStripe.invoices.list =
774
- getJestMockFunction().mockResolvedValue(mockEmptyInvoices);
775
- const invoices = await billingService.getInvoices(customerId);
776
- expect(invoices).toEqual([]);
777
- expect(mockStripe.invoices.list).toHaveBeenCalledWith({
778
- customer: customerId,
779
- limit: 100,
780
- });
781
- });
782
- });
783
- describe("generateInvoiceAndChargeCustomer", () => {
784
- const itemText = "Service Charge";
785
- const amountInUsd = 100;
786
- const mockPaymentMethodsResponse = {
787
- data: [
788
- {
789
- id: "pm_123",
790
- type: "card",
791
- last4Digits: "4242",
792
- isDefault: true,
793
- },
794
- ],
795
- };
796
- it("should successfully generate an invoice and charge the customer", async () => {
797
- var _a;
798
- mockStripe.paymentMethods.list = getJestMockFunction()
799
- .mockResolvedValueOnce(mockPaymentMethodsResponse)
800
- .mockResolvedValue({ data: [] });
801
- mockStripe.customers.retrieve =
802
- getJestMockFunction().mockResolvedValue(mockCustomer);
803
- // mock responses for invoice creation, adding an item, and finalizing
804
- const mockInvoice = getStripeInvoice();
805
- mockStripe.invoices.create =
806
- getJestMockFunction().mockResolvedValue(mockInvoice);
807
- mockStripe.invoiceItems.create =
808
- getJestMockFunction().mockResolvedValue({});
809
- mockStripe.invoices.finalizeInvoice =
810
- getJestMockFunction().mockResolvedValue({});
811
- // mock response for paying the invoice
812
- mockStripe.invoices.pay = getJestMockFunction().mockResolvedValue({});
813
- await billingService.generateInvoiceAndChargeCustomer(customerId, itemText, amountInUsd);
814
- expect(mockStripe.invoices.create).toHaveBeenCalledWith(expect.objectContaining({ customer: customerId }));
815
- expect(mockStripe.invoiceItems.create).toHaveBeenCalledWith(expect.objectContaining({ invoice: mockInvoice.id }));
816
- expect(mockStripe.invoices.finalizeInvoice).toHaveBeenCalledWith(mockInvoice.id);
817
- expect(mockStripe.invoices.pay).toHaveBeenCalledWith(mockInvoice.id, {
818
- payment_method: (_a = mockPaymentMethodsResponse.data[0]) === null || _a === void 0 ? void 0 : _a.id,
819
- });
820
- });
821
- it("should handle payment method errors when creating the invoice", async () => {
822
- mockStripe.invoices.create =
823
- getJestMockFunction().mockResolvedValue(null);
824
- await expect(billingService.generateInvoiceAndChargeCustomer(customerId, itemText, amountInUsd)).rejects.toThrow(Errors.BillingService.INVOICE_NOT_GENERATED);
825
- });
826
- it("should handle payment method errors when charging the invoice", async () => {
827
- mockStripe.paymentMethods.list = getJestMockFunction()
828
- .mockResolvedValueOnce(mockPaymentMethodsResponse)
829
- .mockResolvedValue({ data: [] });
830
- mockStripe.customers.retrieve =
831
- getJestMockFunction().mockResolvedValue(mockCustomer);
832
- // mock successful invoice creation and finalization
833
- const mockInvoice = getStripeInvoice();
834
- mockStripe.invoices.create =
835
- getJestMockFunction().mockResolvedValue(mockInvoice);
836
- mockStripe.invoiceItems.create =
837
- getJestMockFunction().mockResolvedValue({});
838
- mockStripe.invoices.finalizeInvoice =
839
- getJestMockFunction().mockResolvedValue({});
840
- billingService.voidInvoice = getJestMockFunction();
841
- // mock an error during invoice payment
842
- mockStripe.invoices.pay = getJestMockFunction().mockImplementation(() => {
843
- throw new Error("Payment method error");
844
- });
845
- await expect(billingService.generateInvoiceAndChargeCustomer(customerId, itemText, amountInUsd)).rejects.toThrow();
846
- expect(billingService.voidInvoice).toHaveBeenCalled();
847
- });
848
- });
849
- describe("voidInvoice", () => {
850
- it("should successfully void an invoice", async () => {
851
- const mockVoidedInvoice = getStripeInvoice();
852
- mockVoidedInvoice.status = "void";
853
- mockStripe.invoices.voidInvoice =
854
- getJestMockFunction().mockResolvedValue(mockVoidedInvoice);
855
- const voidedInvoice = await billingService.voidInvoice(invoiceId);
856
- expect(voidedInvoice).toEqual(mockVoidedInvoice);
857
- expect(mockStripe.invoices.voidInvoice).toHaveBeenCalledWith(invoiceId);
858
- });
859
- });
860
- describe("payInvoice", () => {
861
- const mockPaymentMethodsResponse = {
862
- data: [
863
- {
864
- id: "pm_123",
865
- type: "card",
866
- last4Digits: "4242",
867
- isDefault: true,
868
- },
869
- ],
870
- };
871
- it("should throw if billing is not enabled", async () => {
872
- billingService = await mockIsBillingEnabled(false);
873
- await expect(billingService.payInvoice(customerId, invoiceId)).rejects.toThrow(Errors.BillingService.BILLING_NOT_ENABLED);
874
- });
875
- it("should throw if no payments methods exist", async () => {
876
- mockStripe.paymentMethods.list =
877
- getJestMockFunction().mockResolvedValue({ data: [] });
878
- mockStripe.customers.retrieve =
879
- getJestMockFunction().mockResolvedValue(mockCustomer);
880
- await expect(billingService.payInvoice(customerId, invoiceId)).rejects.toThrow(Errors.BillingService.NO_PAYMENTS_METHODS);
881
- });
882
- it("should successfully pay an invoice", async () => {
883
- mockStripe.paymentMethods.list = getJestMockFunction()
884
- .mockResolvedValueOnce(mockPaymentMethodsResponse)
885
- .mockResolvedValue({ data: [] });
886
- mockStripe.customers.retrieve =
887
- getJestMockFunction().mockResolvedValue(mockCustomer);
888
- const mockPaidInvoice = getStripeInvoice();
889
- mockStripe.invoices.pay =
890
- getJestMockFunction().mockResolvedValue(mockPaidInvoice);
891
- const paidInvoice = await billingService.payInvoice(customerId, mockPaidInvoice.id || "");
892
- expect(paidInvoice).toEqual({
893
- id: mockPaidInvoice.id,
894
- amount: mockPaidInvoice.amount_due,
895
- currencyCode: mockPaidInvoice.currency,
896
- customerId: mockPaidInvoice.customer,
897
- status: mockPaidInvoice.status,
898
- downloadableLink: "",
899
- subscriptionId: mockPaidInvoice.subscription,
900
- invoiceNumber: mockPaidInvoice.number,
901
- invoiceDate: new Date(mockPaidInvoice.created * 1000),
902
- });
903
- expect(mockStripe.invoices.pay).toHaveBeenCalledWith(mockPaidInvoice.id, {
904
- payment_method: paymentMethodId,
905
- });
906
- });
907
- });
908
- });
909
- });
910
- //# sourceMappingURL=BillingService.test.js.map