alepha 0.13.1 → 0.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (329) hide show
  1. package/README.md +1 -1
  2. package/dist/api-files/index.browser.js +80 -0
  3. package/dist/api-files/index.browser.js.map +1 -0
  4. package/dist/api-files/index.d.ts +28 -91
  5. package/dist/api-files/index.js +10 -755
  6. package/dist/api-files/index.js.map +1 -1
  7. package/dist/api-jobs/index.browser.js +56 -0
  8. package/dist/api-jobs/index.browser.js.map +1 -0
  9. package/dist/api-jobs/index.d.ts +46 -46
  10. package/dist/api-jobs/index.js +13 -13
  11. package/dist/api-jobs/index.js.map +1 -1
  12. package/dist/api-notifications/index.browser.js +382 -0
  13. package/dist/api-notifications/index.browser.js.map +1 -0
  14. package/dist/api-notifications/index.d.ts +231 -193
  15. package/dist/api-notifications/index.js +108 -78
  16. package/dist/api-notifications/index.js.map +1 -1
  17. package/dist/api-parameters/index.browser.js +29 -0
  18. package/dist/api-parameters/index.browser.js.map +1 -0
  19. package/dist/api-parameters/index.d.ts +21 -22
  20. package/dist/api-parameters/index.js +22 -22
  21. package/dist/api-parameters/index.js.map +1 -1
  22. package/dist/api-users/index.d.ts +237 -2001
  23. package/dist/api-users/index.js +969 -4795
  24. package/dist/api-users/index.js.map +1 -1
  25. package/dist/api-verifications/index.browser.js +52 -0
  26. package/dist/api-verifications/index.browser.js.map +1 -0
  27. package/dist/api-verifications/index.d.ts +119 -97
  28. package/dist/api-verifications/index.js +1 -1
  29. package/dist/api-verifications/index.js.map +1 -1
  30. package/dist/batch/index.d.ts +13 -13
  31. package/dist/batch/index.js +8 -13
  32. package/dist/batch/index.js.map +1 -1
  33. package/dist/bucket/index.d.ts +14 -14
  34. package/dist/bucket/index.js +19 -17
  35. package/dist/bucket/index.js.map +1 -1
  36. package/dist/cache/index.d.ts +11 -11
  37. package/dist/cache/index.js +9 -9
  38. package/dist/cache/index.js.map +1 -1
  39. package/dist/cli/{dist-Dl9Vl7Ur.js → dist-lGnqsKpu.js} +11 -15
  40. package/dist/cli/dist-lGnqsKpu.js.map +1 -0
  41. package/dist/cli/index.d.ts +32 -49
  42. package/dist/cli/index.js +90 -71
  43. package/dist/cli/index.js.map +1 -1
  44. package/dist/command/index.d.ts +20 -19
  45. package/dist/command/index.js +34 -25
  46. package/dist/command/index.js.map +1 -1
  47. package/dist/core/index.browser.js +218 -218
  48. package/dist/core/index.browser.js.map +1 -1
  49. package/dist/core/index.d.ts +232 -232
  50. package/dist/core/index.js +218 -218
  51. package/dist/core/index.js.map +1 -1
  52. package/dist/core/index.native.js +2113 -0
  53. package/dist/core/index.native.js.map +1 -0
  54. package/dist/datetime/index.d.ts +9 -9
  55. package/dist/datetime/index.js +7 -7
  56. package/dist/datetime/index.js.map +1 -1
  57. package/dist/email/index.d.ts +16 -16
  58. package/dist/email/index.js +14 -9
  59. package/dist/email/index.js.map +1 -1
  60. package/dist/file/index.js +1 -1
  61. package/dist/file/index.js.map +1 -1
  62. package/dist/lock/index.d.ts +9 -9
  63. package/dist/lock/index.js +8 -8
  64. package/dist/lock/index.js.map +1 -1
  65. package/dist/lock-redis/index.js +3 -66
  66. package/dist/lock-redis/index.js.map +1 -1
  67. package/dist/logger/index.d.ts +5 -5
  68. package/dist/logger/index.js +8 -8
  69. package/dist/logger/index.js.map +1 -1
  70. package/dist/orm/index.browser.js +114 -114
  71. package/dist/orm/index.browser.js.map +1 -1
  72. package/dist/orm/index.d.ts +218 -218
  73. package/dist/orm/index.js +49 -49
  74. package/dist/orm/index.js.map +1 -1
  75. package/dist/queue/index.d.ts +29 -29
  76. package/dist/queue/index.js +20 -20
  77. package/dist/queue/index.js.map +1 -1
  78. package/dist/queue-redis/index.d.ts +2 -2
  79. package/dist/redis/index.d.ts +4 -4
  80. package/dist/retry/index.d.ts +19 -19
  81. package/dist/retry/index.js +7 -7
  82. package/dist/retry/index.js.map +1 -1
  83. package/dist/scheduler/index.d.ts +16 -16
  84. package/dist/scheduler/index.js +9 -9
  85. package/dist/scheduler/index.js.map +1 -1
  86. package/dist/security/index.d.ts +53 -53
  87. package/dist/security/index.js +35 -35
  88. package/dist/security/index.js.map +1 -1
  89. package/dist/server/index.browser.js +1 -1
  90. package/dist/server/index.browser.js.map +1 -1
  91. package/dist/server/index.d.ts +92 -92
  92. package/dist/server/index.js +16 -16
  93. package/dist/server/index.js.map +1 -1
  94. package/dist/server-auth/index.browser.js +4 -982
  95. package/dist/server-auth/index.browser.js.map +1 -1
  96. package/dist/server-auth/index.d.ts +204 -785
  97. package/dist/server-auth/index.js +47 -1239
  98. package/dist/server-auth/index.js.map +1 -1
  99. package/dist/server-cache/index.d.ts +10 -10
  100. package/dist/server-cache/index.js +2 -2
  101. package/dist/server-cache/index.js.map +1 -1
  102. package/dist/server-compress/index.d.ts +4 -4
  103. package/dist/server-compress/index.js +1 -1
  104. package/dist/server-compress/index.js.map +1 -1
  105. package/dist/server-cookies/index.browser.js +8 -8
  106. package/dist/server-cookies/index.browser.js.map +1 -1
  107. package/dist/server-cookies/index.d.ts +17 -17
  108. package/dist/server-cookies/index.js +11 -11
  109. package/dist/server-cookies/index.js.map +1 -1
  110. package/dist/server-cors/index.d.ts +17 -17
  111. package/dist/server-cors/index.js +9 -9
  112. package/dist/server-cors/index.js.map +1 -1
  113. package/dist/server-health/index.d.ts +19 -19
  114. package/dist/server-helmet/index.d.ts +1 -1
  115. package/dist/server-links/index.browser.js +12 -12
  116. package/dist/server-links/index.browser.js.map +1 -1
  117. package/dist/server-links/index.d.ts +59 -251
  118. package/dist/server-links/index.js +23 -502
  119. package/dist/server-links/index.js.map +1 -1
  120. package/dist/server-metrics/index.d.ts +4 -4
  121. package/dist/server-multipart/index.d.ts +2 -2
  122. package/dist/server-proxy/index.d.ts +12 -12
  123. package/dist/server-proxy/index.js +10 -10
  124. package/dist/server-proxy/index.js.map +1 -1
  125. package/dist/server-rate-limit/index.d.ts +22 -22
  126. package/dist/server-rate-limit/index.js +12 -12
  127. package/dist/server-rate-limit/index.js.map +1 -1
  128. package/dist/server-security/index.d.ts +22 -22
  129. package/dist/server-security/index.js +15 -15
  130. package/dist/server-security/index.js.map +1 -1
  131. package/dist/server-static/index.d.ts +14 -14
  132. package/dist/server-static/index.js +26 -10
  133. package/dist/server-static/index.js.map +1 -1
  134. package/dist/server-swagger/index.d.ts +25 -184
  135. package/dist/server-swagger/index.js +21 -724
  136. package/dist/server-swagger/index.js.map +1 -1
  137. package/dist/sms/index.d.ts +14 -14
  138. package/dist/sms/index.js +9 -9
  139. package/dist/sms/index.js.map +1 -1
  140. package/dist/thread/index.d.ts +11 -11
  141. package/dist/thread/index.js +17 -17
  142. package/dist/thread/index.js.map +1 -1
  143. package/dist/topic/index.d.ts +26 -26
  144. package/dist/topic/index.js +16 -16
  145. package/dist/topic/index.js.map +1 -1
  146. package/dist/topic-redis/index.d.ts +1 -1
  147. package/dist/vite/index.d.ts +3 -3
  148. package/dist/vite/index.js +8 -8
  149. package/dist/vite/index.js.map +1 -1
  150. package/dist/websocket/index.browser.js +11 -11
  151. package/dist/websocket/index.browser.js.map +1 -1
  152. package/dist/websocket/index.d.ts +58 -58
  153. package/dist/websocket/index.js +13 -13
  154. package/dist/websocket/index.js.map +1 -1
  155. package/package.json +128 -57
  156. package/src/api-files/index.browser.ts +17 -0
  157. package/src/api-files/services/FileService.ts +5 -7
  158. package/src/api-jobs/index.browser.ts +15 -0
  159. package/src/api-jobs/index.ts +1 -1
  160. package/src/api-jobs/{descriptors → primitives}/$job.ts +8 -8
  161. package/src/api-jobs/providers/JobProvider.ts +9 -9
  162. package/src/api-jobs/services/JobService.ts +5 -5
  163. package/src/api-notifications/controllers/NotificationController.ts +26 -1
  164. package/src/api-notifications/index.browser.ts +17 -0
  165. package/src/api-notifications/index.ts +6 -15
  166. package/src/api-notifications/{descriptors → primitives}/$notification.ts +10 -10
  167. package/src/api-notifications/schemas/notificationQuerySchema.ts +13 -0
  168. package/src/api-notifications/services/NotificationSenderService.ts +3 -3
  169. package/src/api-notifications/services/NotificationService.ts +45 -2
  170. package/src/api-parameters/index.browser.ts +12 -0
  171. package/src/api-parameters/index.ts +1 -1
  172. package/src/api-parameters/{descriptors → primitives}/$config.ts +7 -12
  173. package/src/api-users/atoms/realmAuthSettingsAtom.ts +3 -1
  174. package/src/api-users/controllers/UserController.ts +21 -1
  175. package/src/api-users/index.ts +1 -1
  176. package/src/api-users/{descriptors → primitives}/$userRealm.ts +40 -17
  177. package/src/api-users/providers/UserRealmProvider.ts +2 -1
  178. package/src/api-users/services/SessionService.ts +2 -0
  179. package/src/api-users/services/UserService.ts +56 -16
  180. package/src/api-verifications/index.browser.ts +15 -0
  181. package/src/api-verifications/index.ts +1 -0
  182. package/src/batch/index.ts +3 -3
  183. package/src/batch/{descriptors → primitives}/$batch.ts +13 -16
  184. package/src/batch/providers/BatchProvider.ts +0 -7
  185. package/src/bucket/index.ts +15 -13
  186. package/src/bucket/{descriptors → primitives}/$bucket.ts +8 -8
  187. package/src/bucket/providers/LocalFileStorageProvider.ts +3 -3
  188. package/src/cache/index.ts +4 -4
  189. package/src/cache/{descriptors → primitives}/$cache.ts +15 -15
  190. package/src/cli/apps/AlephaCli.ts +27 -1
  191. package/src/cli/apps/AlephaPackageBuilderCli.ts +27 -2
  192. package/src/cli/commands/CoreCommands.ts +6 -2
  193. package/src/cli/commands/DrizzleCommands.ts +6 -6
  194. package/src/cli/commands/VerifyCommands.ts +1 -1
  195. package/src/cli/commands/ViteCommands.ts +8 -2
  196. package/src/cli/services/ProjectUtils.ts +74 -78
  197. package/src/command/helpers/Asker.ts +10 -0
  198. package/src/command/index.ts +5 -5
  199. package/src/command/{descriptors → primitives}/$command.ts +9 -12
  200. package/src/command/providers/CliProvider.ts +10 -10
  201. package/src/core/Alepha.ts +30 -33
  202. package/src/core/constants/KIND.ts +1 -1
  203. package/src/core/constants/OPTIONS.ts +1 -1
  204. package/src/core/helpers/{descriptor.ts → primitive.ts} +18 -18
  205. package/src/core/helpers/ref.ts +1 -1
  206. package/src/core/index.shared.ts +8 -8
  207. package/src/core/{descriptors → primitives}/$context.ts +5 -5
  208. package/src/core/{descriptors → primitives}/$hook.ts +4 -4
  209. package/src/core/{descriptors → primitives}/$inject.ts +2 -2
  210. package/src/core/{descriptors → primitives}/$module.ts +9 -9
  211. package/src/core/{descriptors → primitives}/$use.ts +2 -2
  212. package/src/core/providers/CodecManager.ts +1 -1
  213. package/src/core/providers/JsonSchemaCodec.ts +1 -1
  214. package/src/core/providers/StateManager.ts +2 -2
  215. package/src/datetime/index.ts +3 -3
  216. package/src/datetime/{descriptors → primitives}/$interval.ts +6 -6
  217. package/src/email/index.ts +17 -9
  218. package/src/email/{descriptors → primitives}/$email.ts +8 -8
  219. package/src/file/index.ts +1 -1
  220. package/src/lock/index.ts +3 -3
  221. package/src/lock/{descriptors → primitives}/$lock.ts +10 -10
  222. package/src/logger/index.ts +8 -8
  223. package/src/logger/{descriptors → primitives}/$logger.ts +2 -2
  224. package/src/logger/services/Logger.ts +1 -1
  225. package/src/orm/constants/PG_SYMBOLS.ts +2 -2
  226. package/src/orm/index.browser.ts +2 -2
  227. package/src/orm/index.ts +8 -8
  228. package/src/orm/{descriptors → primitives}/$entity.ts +11 -11
  229. package/src/orm/{descriptors → primitives}/$repository.ts +2 -2
  230. package/src/orm/{descriptors → primitives}/$sequence.ts +8 -8
  231. package/src/orm/{descriptors → primitives}/$transaction.ts +4 -4
  232. package/src/orm/providers/PostgresTypeProvider.ts +3 -3
  233. package/src/orm/providers/RepositoryProvider.ts +4 -4
  234. package/src/orm/providers/drivers/DatabaseProvider.ts +7 -7
  235. package/src/orm/providers/drivers/NodeSqliteProvider.ts +3 -3
  236. package/src/orm/services/ModelBuilder.ts +9 -9
  237. package/src/orm/services/PgRelationManager.ts +2 -2
  238. package/src/orm/services/PostgresModelBuilder.ts +5 -5
  239. package/src/orm/services/Repository.ts +7 -7
  240. package/src/orm/services/SqliteModelBuilder.ts +5 -5
  241. package/src/queue/index.ts +7 -7
  242. package/src/queue/{descriptors → primitives}/$consumer.ts +15 -15
  243. package/src/queue/{descriptors → primitives}/$queue.ts +12 -12
  244. package/src/queue/providers/WorkerProvider.ts +7 -7
  245. package/src/retry/index.ts +3 -3
  246. package/src/retry/{descriptors → primitives}/$retry.ts +14 -14
  247. package/src/scheduler/index.ts +3 -3
  248. package/src/scheduler/{descriptors → primitives}/$scheduler.ts +9 -9
  249. package/src/scheduler/providers/CronProvider.ts +1 -1
  250. package/src/security/index.ts +9 -9
  251. package/src/security/{descriptors → primitives}/$permission.ts +7 -7
  252. package/src/security/{descriptors → primitives}/$realm.ts +6 -12
  253. package/src/security/{descriptors → primitives}/$role.ts +12 -12
  254. package/src/security/{descriptors → primitives}/$serviceAccount.ts +8 -8
  255. package/src/server/index.browser.ts +1 -1
  256. package/src/server/index.ts +14 -14
  257. package/src/server/{descriptors → primitives}/$action.ts +13 -13
  258. package/src/server/{descriptors → primitives}/$route.ts +9 -9
  259. package/src/server/providers/NodeHttpServerProvider.ts +1 -1
  260. package/src/server/services/HttpClient.ts +1 -1
  261. package/src/server-auth/index.browser.ts +1 -1
  262. package/src/server-auth/index.ts +6 -6
  263. package/src/server-auth/{descriptors → primitives}/$auth.ts +10 -10
  264. package/src/server-auth/{descriptors → primitives}/$authCredentials.ts +4 -4
  265. package/src/server-auth/{descriptors → primitives}/$authGithub.ts +4 -4
  266. package/src/server-auth/{descriptors → primitives}/$authGoogle.ts +4 -4
  267. package/src/server-auth/providers/ServerAuthProvider.ts +4 -4
  268. package/src/server-cache/providers/ServerCacheProvider.ts +7 -7
  269. package/src/server-compress/providers/ServerCompressProvider.ts +3 -3
  270. package/src/server-cookies/index.browser.ts +2 -2
  271. package/src/server-cookies/index.ts +5 -5
  272. package/src/server-cookies/{descriptors → primitives}/$cookie.browser.ts +12 -12
  273. package/src/server-cookies/{descriptors → primitives}/$cookie.ts +13 -13
  274. package/src/server-cookies/providers/ServerCookiesProvider.ts +6 -5
  275. package/src/server-cookies/services/CookieParser.ts +1 -1
  276. package/src/server-cors/index.ts +3 -3
  277. package/src/server-cors/{descriptors → primitives}/$cors.ts +11 -13
  278. package/src/server-cors/providers/ServerCorsProvider.ts +5 -5
  279. package/src/server-links/index.browser.ts +5 -5
  280. package/src/server-links/index.ts +9 -9
  281. package/src/server-links/{descriptors → primitives}/$remote.ts +11 -11
  282. package/src/server-links/providers/LinkProvider.ts +7 -7
  283. package/src/server-links/providers/{RemoteDescriptorProvider.ts → RemotePrimitiveProvider.ts} +6 -6
  284. package/src/server-links/providers/ServerLinksProvider.ts +3 -3
  285. package/src/server-proxy/index.ts +3 -3
  286. package/src/server-proxy/{descriptors → primitives}/$proxy.ts +8 -8
  287. package/src/server-proxy/providers/ServerProxyProvider.ts +4 -4
  288. package/src/server-rate-limit/index.ts +6 -6
  289. package/src/server-rate-limit/{descriptors → primitives}/$rateLimit.ts +13 -13
  290. package/src/server-rate-limit/providers/ServerRateLimitProvider.ts +5 -5
  291. package/src/server-security/index.ts +3 -3
  292. package/src/server-security/{descriptors → primitives}/$basicAuth.ts +13 -13
  293. package/src/server-security/providers/ServerBasicAuthProvider.ts +5 -5
  294. package/src/server-security/providers/ServerSecurityProvider.ts +4 -4
  295. package/src/server-static/index.ts +3 -3
  296. package/src/server-static/{descriptors → primitives}/$serve.ts +8 -10
  297. package/src/server-static/providers/ServerStaticProvider.ts +24 -9
  298. package/src/server-swagger/index.ts +5 -5
  299. package/src/server-swagger/{descriptors → primitives}/$swagger.ts +9 -9
  300. package/src/server-swagger/providers/ServerSwaggerProvider.ts +11 -10
  301. package/src/sms/index.ts +4 -4
  302. package/src/sms/{descriptors → primitives}/$sms.ts +8 -8
  303. package/src/thread/index.ts +3 -3
  304. package/src/thread/{descriptors → primitives}/$thread.ts +13 -13
  305. package/src/thread/providers/ThreadProvider.ts +7 -9
  306. package/src/topic/index.ts +5 -5
  307. package/src/topic/{descriptors → primitives}/$subscriber.ts +14 -14
  308. package/src/topic/{descriptors → primitives}/$topic.ts +10 -10
  309. package/src/topic/providers/TopicProvider.ts +4 -4
  310. package/src/vite/tasks/copyAssets.ts +1 -1
  311. package/src/vite/tasks/generateSitemap.ts +3 -3
  312. package/src/vite/tasks/prerenderPages.ts +2 -2
  313. package/src/vite/tasks/runAlepha.ts +2 -2
  314. package/src/websocket/index.browser.ts +3 -3
  315. package/src/websocket/index.shared.ts +2 -2
  316. package/src/websocket/index.ts +4 -4
  317. package/src/websocket/interfaces/WebSocketInterfaces.ts +3 -3
  318. package/src/websocket/{descriptors → primitives}/$channel.ts +10 -10
  319. package/src/websocket/{descriptors → primitives}/$websocket.ts +8 -8
  320. package/src/websocket/providers/NodeWebSocketServerProvider.ts +7 -7
  321. package/src/websocket/providers/WebSocketServerProvider.ts +3 -3
  322. package/src/websocket/services/WebSocketClient.ts +5 -5
  323. package/dist/cli/dist-Dl9Vl7Ur.js.map +0 -1
  324. package/src/api-notifications/providers/MemorySmsProvider.ts +0 -20
  325. package/src/api-notifications/providers/SmsProvider.ts +0 -8
  326. /package/src/core/{descriptors → primitives}/$atom.ts +0 -0
  327. /package/src/core/{descriptors → primitives}/$env.ts +0 -0
  328. /package/src/server-auth/{descriptors → primitives}/$authApple.ts +0 -0
  329. /package/src/server-links/{descriptors → primitives}/$client.ts +0 -0
@@ -1,4 +1,4 @@
1
- import { $env, $inject, $module, Alepha, Descriptor, KIND, createDescriptor, t } from "alepha";
1
+ import { $env, $inject, $module, Alepha, KIND, Primitive, createPrimitive, t } from "alepha";
2
2
  import { $action, okSchema } from "alepha/server";
3
3
  import { $entity, $repository, pageQuerySchema, pg } from "alepha/orm";
4
4
  import { logEntrySchema } from "alepha/logger";
@@ -64,7 +64,7 @@ var JobProvider = class {
64
64
  logs = /* @__PURE__ */ new Map();
65
65
  jobs = /* @__PURE__ */ new Map();
66
66
  /**
67
- * Register and set up a job for execution (called during descriptor initialization).
67
+ * Register and set up a job for execution (called during primitive initialization).
68
68
  */
69
69
  registerJob(options) {
70
70
  const jobName = options.name;
@@ -79,7 +79,7 @@ var JobProvider = class {
79
79
  const registration = {
80
80
  name: jobName,
81
81
  options,
82
- lockDescriptor: options.lock !== false ? $lock({
82
+ lockPrimitive: options.lock !== false ? $lock({
83
83
  name: () => {
84
84
  return `${this.env.JOB_PREFIX ? `${this.env.JOB_PREFIX}:` : ""}job:${jobName}`;
85
85
  },
@@ -98,11 +98,11 @@ var JobProvider = class {
98
98
  async triggerJob(jobName) {
99
99
  const registration = this.jobs.get(jobName);
100
100
  if (!registration) throw new Error(`Job not registered: ${jobName}`);
101
- if (registration.options.lock !== false && registration.lockDescriptor) await registration.lockDescriptor.run();
101
+ if (registration.options.lock !== false && registration.lockPrimitive) await registration.lockPrimitive.run();
102
102
  else await this.executeJob(jobName, registration.options.handler);
103
103
  }
104
104
  /**
105
- * Execute a job handler (called by the job descriptor).
105
+ * Execute a job handler (called by the job primitive).
106
106
  */
107
107
  async executeJob(jobName, handler) {
108
108
  if (!this.alepha.isStarted()) return;
@@ -161,14 +161,14 @@ var JobProvider = class {
161
161
  };
162
162
 
163
163
  //#endregion
164
- //#region src/api-jobs/descriptors/$job.ts
164
+ //#region src/api-jobs/primitives/$job.ts
165
165
  /**
166
- * Job descriptor - a drop-in replacement for $scheduler with built-in execution tracking.
166
+ * Job primitive - a drop-in replacement for $scheduler with built-in execution tracking.
167
167
  */
168
168
  const $job = (options) => {
169
- return createDescriptor(JobDescriptor, options);
169
+ return createPrimitive(JobPrimitive, options);
170
170
  };
171
- var JobDescriptor = class extends Descriptor {
171
+ var JobPrimitive = class extends Primitive {
172
172
  jobProvider = $inject(JobProvider);
173
173
  get name() {
174
174
  return this.options.name ?? `${this.config.service.name}.${this.config.propertyKey}`;
@@ -183,7 +183,7 @@ var JobDescriptor = class extends Descriptor {
183
183
  await this.jobProvider.triggerJob(this.name);
184
184
  }
185
185
  };
186
- $job[KIND] = JobDescriptor;
186
+ $job[KIND] = JobPrimitive;
187
187
 
188
188
  //#endregion
189
189
  //#region src/api-jobs/services/JobService.ts
@@ -191,7 +191,7 @@ var JobService = class {
191
191
  alepha = $inject(Alepha);
192
192
  executionRepository = $repository(jobExecutions);
193
193
  async getJobs() {
194
- return this.alepha.descriptors($job).map((job) => job.name);
194
+ return this.alepha.primitives($job).map((job) => job.name);
195
195
  }
196
196
  async getJobExecutions(query = {}) {
197
197
  query.sort ??= "-createdAt";
@@ -201,7 +201,7 @@ var JobService = class {
201
201
  return await this.executionRepository.paginate(query, { where }, { count: true });
202
202
  }
203
203
  async triggerJob(name) {
204
- const job = this.alepha.descriptors($job).find((j) => j.name === name);
204
+ const job = this.alepha.primitives($job).find((j) => j.name === name);
205
205
  if (!job) throw new Error(`Job not found: ${name}`);
206
206
  await job.trigger();
207
207
  return { ok: true };
@@ -261,5 +261,5 @@ const AlephaApiJobs = $module({
261
261
  });
262
262
 
263
263
  //#endregion
264
- export { $job, AlephaApiJobs, JobController, JobDescriptor, JobProvider, JobService, jobExecutionQuerySchema, jobExecutionResourceSchema, jobExecutions, triggerJobSchema };
264
+ export { $job, AlephaApiJobs, JobController, JobPrimitive, JobProvider, JobService, jobExecutionQuerySchema, jobExecutionResourceSchema, jobExecutions, triggerJobSchema };
265
265
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["registration: JobRegistration"],"sources":["../../src/api-jobs/schemas/jobExecutionQuerySchema.ts","../../src/api-jobs/entities/jobExecutions.ts","../../src/api-jobs/schemas/jobExecutionResourceSchema.ts","../../src/api-jobs/schemas/triggerJobSchema.ts","../../src/api-jobs/providers/JobProvider.ts","../../src/api-jobs/descriptors/$job.ts","../../src/api-jobs/services/JobService.ts","../../src/api-jobs/controllers/JobController.ts","../../src/api-jobs/index.ts"],"sourcesContent":["import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\nimport { pageQuerySchema } from \"alepha/orm\";\n\nexport const jobExecutionQuerySchema = t.extend(pageQuerySchema, {\n status: t.optional(t.enum([\"STARTED\", \"FAILED\", \"COMPLETED\"])),\n job: t.optional(\n t.text({\n description: \"Filter by job name\",\n }),\n ),\n});\n\nexport type JobExecutionQuery = Static<typeof jobExecutionQuerySchema>;\n","import { type Static, t } from \"alepha\";\nimport { logEntrySchema } from \"alepha/logger\";\nimport { $entity, pg } from \"alepha/orm\";\n\nexport const jobExecutions = $entity({\n name: \"job_executions\",\n schema: t.object({\n id: pg.primaryKey(t.uuid()),\n version: pg.version(),\n createdAt: pg.createdAt(),\n updatedAt: pg.updatedAt(),\n finishedAt: t.optional(t.datetime()),\n job: t.string(),\n status: t.enum([\"STARTED\", \"FAILED\", \"COMPLETED\"]),\n error: t.optional(t.string()),\n logs: t.optional(t.array(logEntrySchema)),\n }),\n});\n\nexport type JobExecutionEntity = Static<typeof jobExecutions.schema>;\n","import { type Static, t } from \"alepha\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\n\nexport const jobExecutionResourceSchema = t.extend(\n jobExecutions.schema,\n {},\n {\n title: \"JobExecutionResource\",\n description:\n \"A job execution resource representing the execution details of a job.\",\n },\n);\n\nexport type JobExecutionResource = Static<typeof jobExecutionResourceSchema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const triggerJobSchema = t.object({\n name: t.string(),\n});\n\nexport type TriggerJob = Static<typeof triggerJobSchema>;\n","import { $env, $inject, Alepha, type Async, type Static, t } from \"alepha\";\nimport { type DateTime, DateTimeProvider } from \"alepha/datetime\";\nimport { $lock, type LockDescriptor } from \"alepha/lock\";\nimport type { LogEntry } from \"alepha/logger\";\nimport { $repository } from \"alepha/orm\";\nimport { CronProvider } from \"alepha/scheduler\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\n\nconst envSchema = t.object({\n JOB_PREFIX: t.optional(\n t.text({\n description: \"Prefix for job lock keys\",\n }),\n ),\n});\n\ndeclare module \"alepha\" {\n interface Env extends Partial<Static<typeof envSchema>> {}\n}\n\n/**\n * Provider for job management and execution.\n * Handles job lifecycle, execution tracking, log capturing, and event emission.\n */\nexport class JobProvider {\n protected readonly alepha = $inject(Alepha);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly cronProvider = $inject(CronProvider);\n protected readonly executionRepository = $repository(jobExecutions);\n protected readonly env = $env(envSchema);\n protected readonly logs = new Map<string, LogEntry[]>();\n protected readonly jobs = new Map<string, JobRegistration>();\n\n /**\n * Register and set up a job for execution (called during descriptor initialization).\n */\n public registerJob(options: Job): JobRegistration {\n const jobName = options.name;\n\n // Set up log capturing for this job (only once)\n if (this.jobs.size === 0) {\n this.alepha.events.on(\"log\", ({ entry }) => {\n const context = entry.context;\n if (!context) {\n return;\n }\n\n const entries = this.logs.get(context);\n if (!entries) {\n return;\n }\n\n entries.push(entry);\n this.logs.set(context, entries);\n });\n }\n\n // Create lock descriptor if locking is enabled\n const lockDescriptor =\n options.lock !== false\n ? $lock({\n name: () => {\n const prefix = this.env.JOB_PREFIX\n ? `${this.env.JOB_PREFIX}:`\n : \"\";\n return `${prefix}job:${jobName}`;\n },\n handler: async () => {\n await this.executeJob(jobName, options.handler);\n },\n })\n : null;\n\n const registration: JobRegistration = {\n name: jobName,\n options,\n lockDescriptor,\n };\n\n this.jobs.set(jobName, registration);\n\n // Set up cron scheduling if provided\n if (options.cron) {\n this.cronProvider.createCronJob(jobName, options.cron, () =>\n this.triggerJob(jobName),\n );\n }\n\n return registration;\n }\n\n /**\n * Trigger a job by name.\n */\n public async triggerJob(jobName: string): Promise<void> {\n const registration = this.jobs.get(jobName);\n if (!registration) {\n throw new Error(`Job not registered: ${jobName}`);\n }\n\n // Execute handler with or without lock\n if (registration.options.lock !== false && registration.lockDescriptor) {\n await registration.lockDescriptor.run();\n } else {\n await this.executeJob(jobName, registration.options.handler);\n }\n }\n\n /**\n * Execute a job handler (called by the job descriptor).\n */\n public async executeJob(\n jobName: string,\n handler: (args: { now: DateTime }) => Async<void>,\n ): Promise<void> {\n if (!this.alepha.isStarted()) {\n return;\n }\n\n const context = this.alepha.context.createContextId();\n\n await this.alepha.context.run(\n async () => {\n try {\n const now = this.dateTimeProvider.now();\n\n // Initialize log collection for this context\n this.logs.set(context, []);\n\n // Create execution record\n await this.executionRepository.create({\n job: jobName,\n status: \"STARTED\",\n });\n\n await this.alepha.events.emit(\"scheduler:begin\", {\n name: jobName,\n now,\n context,\n });\n\n // Execute the handler\n await handler({ now });\n\n // Update execution as completed\n const logs = this.logs.get(context) || [];\n const exec = await this.executionRepository.findOne({\n where: {\n job: jobName,\n status: \"STARTED\",\n },\n });\n\n exec.status = \"COMPLETED\";\n exec.logs = logs;\n exec.finishedAt = this.dateTimeProvider.nowISOString();\n\n await this.executionRepository.save(exec);\n\n await this.alepha.events.emit(\n \"scheduler:success\",\n {\n name: jobName,\n context,\n },\n {\n catch: true,\n },\n );\n } catch (error) {\n // Update execution as failed\n const logs = this.logs.get(context) || [];\n const exec = await this.executionRepository.findOne({\n where: {\n job: jobName,\n status: \"STARTED\",\n },\n });\n\n exec.status = \"FAILED\";\n exec.error = (error as Error).message;\n exec.logs = logs;\n exec.finishedAt = this.dateTimeProvider.nowISOString();\n\n await this.executionRepository.save(exec);\n\n await this.alepha.events.emit(\n \"scheduler:error\",\n {\n name: jobName,\n error: error as Error,\n context,\n },\n {\n catch: true,\n },\n );\n\n // Don't re-throw, jobs should handle errors gracefully\n }\n\n // Clean up logs\n this.logs.delete(context);\n\n await this.alepha.events.emit(\n \"scheduler:end\",\n {\n name: jobName,\n context,\n },\n {\n catch: true,\n },\n );\n },\n {\n context,\n },\n );\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface Job {\n /**\n * Name of the job.\n */\n name: string;\n\n /**\n * Optional description of the job.\n */\n description?: string;\n\n /**\n * Function to run on schedule.\n */\n handler: (args: { now: DateTime }) => Async<void>;\n\n /**\n * Cron expression to run the job.\n */\n cron?: string;\n\n /**\n * If true, the job will be locked and only one instance will run at a time.\n * You probably need to import {@link AlephaLockRedis} for distributed locking.\n *\n * @default true\n */\n lock?: boolean;\n\n /**\n * Optional prefix for job lock keys.\n */\n lockPrefix?: string;\n}\n\nexport interface JobRegistration {\n name: string;\n options: Job;\n lockDescriptor: LockDescriptor<() => Promise<void>> | null;\n}\n","import { $inject, createDescriptor, Descriptor, KIND } from \"alepha\";\nimport type { DateTime } from \"alepha/datetime\";\nimport { type Job, JobProvider } from \"../providers/JobProvider.ts\";\n\n/**\n * Job descriptor - a drop-in replacement for $scheduler with built-in execution tracking.\n */\nexport const $job = (options: JobDescriptorOptions): JobDescriptor => {\n return createDescriptor(JobDescriptor, options);\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport type JobDescriptorOptions = Omit<Job, \"name\"> & {\n /**\n * Name of the job. Defaults to the descriptor property name.\n */\n name?: string;\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class JobDescriptor extends Descriptor<JobDescriptorOptions> {\n protected readonly jobProvider = $inject(JobProvider);\n\n public get name(): string {\n return (\n this.options.name ??\n `${this.config.service.name}.${this.config.propertyKey}`\n );\n }\n\n protected onInit() {\n // Register job with JobProvider\n this.jobProvider.registerJob({\n ...this.options,\n name: this.name,\n });\n }\n\n public async trigger(): Promise<void> {\n await this.jobProvider.triggerJob(this.name);\n }\n}\n\n$job[KIND] = JobDescriptor;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface JobHandlerArguments {\n now: DateTime;\n}\n","import { $inject, Alepha } from \"alepha\";\nimport { $repository } from \"alepha/orm\";\nimport { $job } from \"../descriptors/$job.ts\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\nimport type { JobExecutionQuery } from \"../schemas/jobExecutionQuerySchema.ts\";\n\nexport class JobService {\n protected readonly alepha = $inject(Alepha);\n protected readonly executionRepository = $repository(jobExecutions);\n\n public async getJobs(): Promise<string[]> {\n const jobDescriptors = this.alepha.descriptors($job);\n return jobDescriptors.map((job) => job.name);\n }\n\n public async getJobExecutions(query: JobExecutionQuery = {}) {\n query.sort ??= \"-createdAt\";\n\n const where = this.executionRepository.createQueryWhere();\n\n if (query.job) {\n where.job = { eq: query.job };\n }\n\n if (query.status) {\n where.status = { eq: query.status };\n }\n\n return await this.executionRepository.paginate(\n query,\n { where },\n { count: true },\n );\n }\n\n public async triggerJob(name: string): Promise<{ ok: boolean }> {\n const jobDescriptors = this.alepha.descriptors($job);\n const job = jobDescriptors.find((j) => j.name === name);\n\n if (!job) {\n throw new Error(`Job not found: ${name}`);\n }\n\n await job.trigger();\n return { ok: true };\n }\n}\n","import { $inject, t } from \"alepha\";\nimport { $action, okSchema } from \"alepha/server\";\nimport { jobExecutionQuerySchema } from \"../schemas/jobExecutionQuerySchema.ts\";\nimport { jobExecutionResourceSchema } from \"../schemas/jobExecutionResourceSchema.ts\";\nimport { triggerJobSchema } from \"../schemas/triggerJobSchema.ts\";\nimport { JobService } from \"../services/JobService.ts\";\n\nexport class JobController {\n protected readonly url: string = \"/jobs\";\n protected readonly group: string = \"jobs\";\n protected readonly jobService = $inject(JobService);\n\n public readonly getJobs = $action({\n path: this.url,\n group: this.group,\n schema: {\n response: t.array(t.string()),\n },\n handler: () => this.jobService.getJobs(),\n });\n\n public readonly getJobExecutions = $action({\n path: `${this.url}/executions`,\n group: this.group,\n schema: {\n query: jobExecutionQuerySchema,\n response: t.page(jobExecutionResourceSchema),\n },\n handler: ({ query }) => this.jobService.getJobExecutions(query),\n });\n\n public readonly triggerJob = $action({\n method: \"POST\",\n path: `${this.url}/trigger`,\n group: this.group,\n schema: {\n body: triggerJobSchema,\n response: okSchema,\n },\n handler: ({ body }) => this.jobService.triggerJob(body.name),\n });\n}\n","import { $module } from \"alepha\";\nimport { JobController } from \"./controllers/JobController.ts\";\nimport { JobProvider } from \"./providers/JobProvider.ts\";\nimport { JobService } from \"./services/JobService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./controllers/JobController.ts\";\nexport * from \"./descriptors/$job.ts\";\nexport * from \"./entities/jobExecutions.ts\";\nexport * from \"./providers/JobProvider.ts\";\nexport * from \"./schemas/jobExecutionQuerySchema.ts\";\nexport * from \"./schemas/jobExecutionResourceSchema.ts\";\nexport * from \"./schemas/triggerJobSchema.ts\";\nexport * from \"./services/JobService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Provides job management API endpoints for Alepha applications.\n *\n * This module includes job queue operations, job status monitoring,\n * and background task management capabilities.\n *\n * @module alepha.api.jobs\n */\nexport const AlephaApiJobs = $module({\n name: \"alepha.api.jobs\",\n services: [JobController, JobProvider, JobService],\n});\n"],"mappings":";;;;;;;;;AAIA,MAAa,0BAA0B,EAAE,OAAO,iBAAiB;CAC/D,QAAQ,EAAE,SAAS,EAAE,KAAK;EAAC;EAAW;EAAU;EAAY,CAAC,CAAC;CAC9D,KAAK,EAAE,SACL,EAAE,KAAK,EACL,aAAa,sBACd,CAAC,CACH;CACF,CAAC;;;;ACPF,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,QAAQ,EAAE,OAAO;EACf,IAAI,GAAG,WAAW,EAAE,MAAM,CAAC;EAC3B,SAAS,GAAG,SAAS;EACrB,WAAW,GAAG,WAAW;EACzB,WAAW,GAAG,WAAW;EACzB,YAAY,EAAE,SAAS,EAAE,UAAU,CAAC;EACpC,KAAK,EAAE,QAAQ;EACf,QAAQ,EAAE,KAAK;GAAC;GAAW;GAAU;GAAY,CAAC;EAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;EAC7B,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;EAC1C,CAAC;CACH,CAAC;;;;ACdF,MAAa,6BAA6B,EAAE,OAC1C,cAAc,QACd,EAAE,EACF;CACE,OAAO;CACP,aACE;CACH,CACF;;;;ACRD,MAAa,mBAAmB,EAAE,OAAO,EACvC,MAAM,EAAE,QAAQ,EACjB,CAAC;;;;ACGF,MAAM,YAAY,EAAE,OAAO,EACzB,YAAY,EAAE,SACZ,EAAE,KAAK,EACL,aAAa,4BACd,CAAC,CACH,EACF,CAAC;;;;;AAUF,IAAa,cAAb,MAAyB;CACvB,AAAmB,SAAS,QAAQ,OAAO;C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mB,QAAgB;CACnC,AAAmB,aAAa,QAAQ,WAAW;CAEnD,AAAgB,UAAU,QAAQ;EAChC,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,QAAQ,EACN,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAC9B;EACD,eAAe,KAAK,WAAW,SAAS;EACzC,CAAC;CAEF,AAAgB,mBAAmB,QAAQ;EACzC,MAAM,GAAG,KAAK,IAAI;EAClB,OAAO,KAAK;EACZ,QAAQ;GACN,OAAO;GACP,UAAU,EAAE,KAAK,2BAA2B;GAC7C;EACD,UAAU,EAAE,YAAY,KAAK,WAAW,iBAAiB,MAAM;EAChE,CAAC;CAEF,AAAgB,aAAa,QAAQ;EACnC,QAAQ;EACR,MAAM,GAAG,KAAK,IAAI;EAClB,OAAO,KAAK;EACZ,QAAQ;GACN,MAAM;GACN,UAAU;GACX;EACD,UAAU,EAAE,WAAW,KAAK,WAAW,WAAW,KAAK,KAAK;EAC7D,CAAC;;;;;;;;;;;;;ACdJ,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,UAAU;EAAC;EAAe;EAAa;EAAW;CACnD,CAAC"}
1
+ {"version":3,"file":"index.js","names":["registration: JobRegistration"],"sources":["../../src/api-jobs/schemas/jobExecutionQuerySchema.ts","../../src/api-jobs/entities/jobExecutions.ts","../../src/api-jobs/schemas/jobExecutionResourceSchema.ts","../../src/api-jobs/schemas/triggerJobSchema.ts","../../src/api-jobs/providers/JobProvider.ts","../../src/api-jobs/primitives/$job.ts","../../src/api-jobs/services/JobService.ts","../../src/api-jobs/controllers/JobController.ts","../../src/api-jobs/index.ts"],"sourcesContent":["import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\nimport { pageQuerySchema } from \"alepha/orm\";\n\nexport const jobExecutionQuerySchema = t.extend(pageQuerySchema, {\n status: t.optional(t.enum([\"STARTED\", \"FAILED\", \"COMPLETED\"])),\n job: t.optional(\n t.text({\n description: \"Filter by job name\",\n }),\n ),\n});\n\nexport type JobExecutionQuery = Static<typeof jobExecutionQuerySchema>;\n","import { type Static, t } from \"alepha\";\nimport { logEntrySchema } from \"alepha/logger\";\nimport { $entity, pg } from \"alepha/orm\";\n\nexport const jobExecutions = $entity({\n name: \"job_executions\",\n schema: t.object({\n id: pg.primaryKey(t.uuid()),\n version: pg.version(),\n createdAt: pg.createdAt(),\n updatedAt: pg.updatedAt(),\n finishedAt: t.optional(t.datetime()),\n job: t.string(),\n status: t.enum([\"STARTED\", \"FAILED\", \"COMPLETED\"]),\n error: t.optional(t.string()),\n logs: t.optional(t.array(logEntrySchema)),\n }),\n});\n\nexport type JobExecutionEntity = Static<typeof jobExecutions.schema>;\n","import { type Static, t } from \"alepha\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\n\nexport const jobExecutionResourceSchema = t.extend(\n jobExecutions.schema,\n {},\n {\n title: \"JobExecutionResource\",\n description:\n \"A job execution resource representing the execution details of a job.\",\n },\n);\n\nexport type JobExecutionResource = Static<typeof jobExecutionResourceSchema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\n\nexport const triggerJobSchema = t.object({\n name: t.string(),\n});\n\nexport type TriggerJob = Static<typeof triggerJobSchema>;\n","import { $env, $inject, Alepha, type Async, type Static, t } from \"alepha\";\nimport { type DateTime, DateTimeProvider } from \"alepha/datetime\";\nimport { $lock, type LockPrimitive } from \"alepha/lock\";\nimport type { LogEntry } from \"alepha/logger\";\nimport { $repository } from \"alepha/orm\";\nimport { CronProvider } from \"alepha/scheduler\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\n\nconst envSchema = t.object({\n JOB_PREFIX: t.optional(\n t.text({\n description: \"Prefix for job lock keys\",\n }),\n ),\n});\n\ndeclare module \"alepha\" {\n interface Env extends Partial<Static<typeof envSchema>> {}\n}\n\n/**\n * Provider for job management and execution.\n * Handles job lifecycle, execution tracking, log capturing, and event emission.\n */\nexport class JobProvider {\n protected readonly alepha = $inject(Alepha);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly cronProvider = $inject(CronProvider);\n protected readonly executionRepository = $repository(jobExecutions);\n protected readonly env = $env(envSchema);\n protected readonly logs = new Map<string, LogEntry[]>();\n protected readonly jobs = new Map<string, JobRegistration>();\n\n /**\n * Register and set up a job for execution (called during primitive initialization).\n */\n public registerJob(options: Job): JobRegistration {\n const jobName = options.name;\n\n // Set up log capturing for this job (only once)\n if (this.jobs.size === 0) {\n this.alepha.events.on(\"log\", ({ entry }) => {\n const context = entry.context;\n if (!context) {\n return;\n }\n\n const entries = this.logs.get(context);\n if (!entries) {\n return;\n }\n\n entries.push(entry);\n this.logs.set(context, entries);\n });\n }\n\n // Create lock primitive if locking is enabled\n const lockPrimitive =\n options.lock !== false\n ? $lock({\n name: () => {\n const prefix = this.env.JOB_PREFIX\n ? `${this.env.JOB_PREFIX}:`\n : \"\";\n return `${prefix}job:${jobName}`;\n },\n handler: async () => {\n await this.executeJob(jobName, options.handler);\n },\n })\n : null;\n\n const registration: JobRegistration = {\n name: jobName,\n options,\n lockPrimitive,\n };\n\n this.jobs.set(jobName, registration);\n\n // Set up cron scheduling if provided\n if (options.cron) {\n this.cronProvider.createCronJob(jobName, options.cron, () =>\n this.triggerJob(jobName),\n );\n }\n\n return registration;\n }\n\n /**\n * Trigger a job by name.\n */\n public async triggerJob(jobName: string): Promise<void> {\n const registration = this.jobs.get(jobName);\n if (!registration) {\n throw new Error(`Job not registered: ${jobName}`);\n }\n\n // Execute handler with or without lock\n if (registration.options.lock !== false && registration.lockPrimitive) {\n await registration.lockPrimitive.run();\n } else {\n await this.executeJob(jobName, registration.options.handler);\n }\n }\n\n /**\n * Execute a job handler (called by the job primitive).\n */\n public async executeJob(\n jobName: string,\n handler: (args: { now: DateTime }) => Async<void>,\n ): Promise<void> {\n if (!this.alepha.isStarted()) {\n return;\n }\n\n const context = this.alepha.context.createContextId();\n\n await this.alepha.context.run(\n async () => {\n try {\n const now = this.dateTimeProvider.now();\n\n // Initialize log collection for this context\n this.logs.set(context, []);\n\n // Create execution record\n await this.executionRepository.create({\n job: jobName,\n status: \"STARTED\",\n });\n\n await this.alepha.events.emit(\"scheduler:begin\", {\n name: jobName,\n now,\n context,\n });\n\n // Execute the handler\n await handler({ now });\n\n // Update execution as completed\n const logs = this.logs.get(context) || [];\n const exec = await this.executionRepository.findOne({\n where: {\n job: jobName,\n status: \"STARTED\",\n },\n });\n\n exec.status = \"COMPLETED\";\n exec.logs = logs;\n exec.finishedAt = this.dateTimeProvider.nowISOString();\n\n await this.executionRepository.save(exec);\n\n await this.alepha.events.emit(\n \"scheduler:success\",\n {\n name: jobName,\n context,\n },\n {\n catch: true,\n },\n );\n } catch (error) {\n // Update execution as failed\n const logs = this.logs.get(context) || [];\n const exec = await this.executionRepository.findOne({\n where: {\n job: jobName,\n status: \"STARTED\",\n },\n });\n\n exec.status = \"FAILED\";\n exec.error = (error as Error).message;\n exec.logs = logs;\n exec.finishedAt = this.dateTimeProvider.nowISOString();\n\n await this.executionRepository.save(exec);\n\n await this.alepha.events.emit(\n \"scheduler:error\",\n {\n name: jobName,\n error: error as Error,\n context,\n },\n {\n catch: true,\n },\n );\n\n // Don't re-throw, jobs should handle errors gracefully\n }\n\n // Clean up logs\n this.logs.delete(context);\n\n await this.alepha.events.emit(\n \"scheduler:end\",\n {\n name: jobName,\n context,\n },\n {\n catch: true,\n },\n );\n },\n {\n context,\n },\n );\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface Job {\n /**\n * Name of the job.\n */\n name: string;\n\n /**\n * Optional description of the job.\n */\n description?: string;\n\n /**\n * Function to run on schedule.\n */\n handler: (args: { now: DateTime }) => Async<void>;\n\n /**\n * Cron expression to run the job.\n */\n cron?: string;\n\n /**\n * If true, the job will be locked and only one instance will run at a time.\n * You probably need to import {@link AlephaLockRedis} for distributed locking.\n *\n * @default true\n */\n lock?: boolean;\n\n /**\n * Optional prefix for job lock keys.\n */\n lockPrefix?: string;\n}\n\nexport interface JobRegistration {\n name: string;\n options: Job;\n lockPrimitive: LockPrimitive<() => Promise<void>> | null;\n}\n","import { $inject, createPrimitive, KIND, Primitive } from \"alepha\";\nimport type { DateTime } from \"alepha/datetime\";\nimport { type Job, JobProvider } from \"../providers/JobProvider.ts\";\n\n/**\n * Job primitive - a drop-in replacement for $scheduler with built-in execution tracking.\n */\nexport const $job = (options: JobPrimitiveOptions): JobPrimitive => {\n return createPrimitive(JobPrimitive, options);\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport type JobPrimitiveOptions = Omit<Job, \"name\"> & {\n /**\n * Name of the job. Defaults to the primitive property name.\n */\n name?: string;\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class JobPrimitive extends Primitive<JobPrimitiveOptions> {\n protected readonly jobProvider = $inject(JobProvider);\n\n public get name(): string {\n return (\n this.options.name ??\n `${this.config.service.name}.${this.config.propertyKey}`\n );\n }\n\n protected onInit() {\n // Register job with JobProvider\n this.jobProvider.registerJob({\n ...this.options,\n name: this.name,\n });\n }\n\n public async trigger(): Promise<void> {\n await this.jobProvider.triggerJob(this.name);\n }\n}\n\n$job[KIND] = JobPrimitive;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface JobHandlerArguments {\n now: DateTime;\n}\n","import { $inject, Alepha } from \"alepha\";\nimport { $repository } from \"alepha/orm\";\nimport { jobExecutions } from \"../entities/jobExecutions.ts\";\nimport { $job } from \"../primitives/$job.ts\";\nimport type { JobExecutionQuery } from \"../schemas/jobExecutionQuerySchema.ts\";\n\nexport class JobService {\n protected readonly alepha = $inject(Alepha);\n protected readonly executionRepository = $repository(jobExecutions);\n\n public async getJobs(): Promise<string[]> {\n const jobPrimitives = this.alepha.primitives($job);\n return jobPrimitives.map((job) => job.name);\n }\n\n public async getJobExecutions(query: JobExecutionQuery = {}) {\n query.sort ??= \"-createdAt\";\n\n const where = this.executionRepository.createQueryWhere();\n\n if (query.job) {\n where.job = { eq: query.job };\n }\n\n if (query.status) {\n where.status = { eq: query.status };\n }\n\n return await this.executionRepository.paginate(\n query,\n { where },\n { count: true },\n );\n }\n\n public async triggerJob(name: string): Promise<{ ok: boolean }> {\n const jobPrimitives = this.alepha.primitives($job);\n const job = jobPrimitives.find((j) => j.name === name);\n\n if (!job) {\n throw new Error(`Job not found: ${name}`);\n }\n\n await job.trigger();\n return { ok: true };\n }\n}\n","import { $inject, t } from \"alepha\";\nimport { $action, okSchema } from \"alepha/server\";\nimport { jobExecutionQuerySchema } from \"../schemas/jobExecutionQuerySchema.ts\";\nimport { jobExecutionResourceSchema } from \"../schemas/jobExecutionResourceSchema.ts\";\nimport { triggerJobSchema } from \"../schemas/triggerJobSchema.ts\";\nimport { JobService } from \"../services/JobService.ts\";\n\nexport class JobController {\n protected readonly url: string = \"/jobs\";\n protected readonly group: string = \"jobs\";\n protected readonly jobService = $inject(JobService);\n\n public readonly getJobs = $action({\n path: this.url,\n group: this.group,\n schema: {\n response: t.array(t.string()),\n },\n handler: () => this.jobService.getJobs(),\n });\n\n public readonly getJobExecutions = $action({\n path: `${this.url}/executions`,\n group: this.group,\n schema: {\n query: jobExecutionQuerySchema,\n response: t.page(jobExecutionResourceSchema),\n },\n handler: ({ query }) => this.jobService.getJobExecutions(query),\n });\n\n public readonly triggerJob = $action({\n method: \"POST\",\n path: `${this.url}/trigger`,\n group: this.group,\n schema: {\n body: triggerJobSchema,\n response: okSchema,\n },\n handler: ({ body }) => this.jobService.triggerJob(body.name),\n });\n}\n","import { $module } from \"alepha\";\nimport { JobController } from \"./controllers/JobController.ts\";\nimport { JobProvider } from \"./providers/JobProvider.ts\";\nimport { JobService } from \"./services/JobService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./controllers/JobController.ts\";\nexport * from \"./entities/jobExecutions.ts\";\nexport * from \"./primitives/$job.ts\";\nexport * from \"./providers/JobProvider.ts\";\nexport * from \"./schemas/jobExecutionQuerySchema.ts\";\nexport * from \"./schemas/jobExecutionResourceSchema.ts\";\nexport * from \"./schemas/triggerJobSchema.ts\";\nexport * from \"./services/JobService.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Provides job management API endpoints for Alepha applications.\n *\n * This module includes job queue operations, job status monitoring,\n * and background task management capabilities.\n *\n * @module alepha.api.jobs\n */\nexport const AlephaApiJobs = $module({\n name: \"alepha.api.jobs\",\n services: [JobController, JobProvider, JobService],\n});\n"],"mappings":";;;;;;;;;AAIA,MAAa,0BAA0B,EAAE,OAAO,iBAAiB;CAC/D,QAAQ,EAAE,SAAS,EAAE,KAAK;EAAC;EAAW;EAAU;EAAY,CAAC,CAAC;CAC9D,KAAK,EAAE,SACL,EAAE,KAAK,EACL,aAAa,sBACd,CAAC,CACH;CACF,CAAC;;;;ACPF,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,QAAQ,EAAE,OAAO;EACf,IAAI,GAAG,WAAW,EAAE,MAAM,CAAC;EAC3B,SAAS,GAAG,SAAS;EACrB,WAAW,GAAG,WAAW;EACzB,WAAW,GAAG,WAAW;EACzB,YAAY,EAAE,SAAS,EAAE,UAAU,CAAC;EACpC,KAAK,EAAE,QAAQ;EACf,QAAQ,EAAE,KAAK;GAAC;GAAW;GAAU;GAAY,CAAC;EAClD,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;EAC7B,MAAM,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;EAC1C,CAAC;CACH,CAAC;;;;ACdF,MAAa,6BAA6B,EAAE,OAC1C,cAAc,QACd,EAAE,EACF;CACE,OAAO;CACP,aACE;CACH,CACF;;;;ACRD,MAAa,mBAAmB,EAAE,OAAO,EACvC,MAAM,EAAE,QAAQ,EACjB,CAAC;;;;ACGF,MAAM,YAAY,EAAE,OAAO,EACzB,YAAY,EAAE,SACZ,EAAE,KAAK,EACL,aAAa,4BACd,CAAC,CACH,EACF,CAAC;;;;;AAUF,IAAa,cAAb,MAAyB;CACvB,AAAmB,SAAS,QAAQ,OAAO;CAC3C,AAAmB,mBAAmB,QAAQ,iBAAiB;CAC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;CAEnD,AAAgB,UAAU,QAAQ;EAChC,MAAM,KAAK;EACX,OAAO,KAAK;EACZ,QAAQ,EACN,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAC9B;EACD,eAAe,KAAK,WAAW,SAAS;EACzC,CAAC;CAEF,AAAgB,mBAAmB,QAAQ;EACzC,MAAM,GAAG,KAAK,IAAI;EAClB,OAAO,KAAK;EACZ,QAAQ;GACN,OAAO;GACP,UAAU,EAAE,KAAK,2BAA2B;GAC7C;EACD,UAAU,EAAE,YAAY,KAAK,WAAW,iBAAiB,MAAM;EAChE,CAAC;CAEF,AAAgB,aAAa,QAAQ;EACnC,QAAQ;EACR,MAAM,GAAG,KAAK,IAAI;EAClB,OAAO,KAAK;EACZ,QAAQ;GACN,MAAM;GACN,UAAU;GACX;EACD,UAAU,EAAE,WAAW,KAAK,WAAW,WAAW,KAAK,KAAK;EAC7D,CAAC;;;;;;;;;;;;;ACdJ,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,UAAU;EAAC;EAAe;EAAa;EAAW;CACnD,CAAC"}
@@ -0,0 +1,382 @@
1
+ import { $env, $inject, $module, Alepha, AlephaError, KIND, Primitive, createPrimitive, t } from "alepha";
2
+ import { $entity, $repository, pageQuerySchema, pg } from "alepha/orm";
3
+ import { $action } from "alepha/server";
4
+ import { $batch } from "alepha/batch";
5
+ import { DateTimeProvider } from "alepha/datetime";
6
+ import { $logger } from "alepha/logger";
7
+ import { $queue } from "alepha/queue";
8
+ import { EmailProvider } from "alepha/email";
9
+ import { SmsProvider } from "alepha/sms";
10
+
11
+ //#region src/api-notifications/entities/notifications.ts
12
+ const notifications = $entity({
13
+ name: "notifications",
14
+ schema: t.object({
15
+ id: pg.primaryKey(t.uuid()),
16
+ version: pg.version(),
17
+ createdAt: pg.createdAt(),
18
+ updatedAt: pg.updatedAt(),
19
+ type: t.enum(["email", "sms"]),
20
+ template: t.text(),
21
+ category: t.optional(t.text({ description: "For grouping related notifications (e.g., 'authentication', 'marketing'). Contact can filter notifications by category." })),
22
+ critical: t.optional(t.boolean({ description: "Prioritize delivery of this notification. Set to true for important system alerts." })),
23
+ sensitive: t.optional(t.boolean({ description: "Message won't be logged or stored in plain text. Set to true when notification contains passwords or codes." })),
24
+ contact: t.text(),
25
+ variables: t.optional(t.record(t.text(), t.any())),
26
+ scheduledAt: t.optional(t.datetime({ description: "When set, the notification will be sent at or after this date/time." })),
27
+ sentAt: t.optional(t.datetime()),
28
+ error: t.optional(t.object({
29
+ at: t.datetime(),
30
+ name: t.text(),
31
+ message: t.text({ size: "rich" })
32
+ }))
33
+ })
34
+ });
35
+
36
+ //#endregion
37
+ //#region src/api-notifications/schemas/notificationQuerySchema.ts
38
+ const notificationQuerySchema = t.extend(pageQuerySchema, {
39
+ type: t.optional(t.enum(["email", "sms"])),
40
+ template: t.optional(t.string()),
41
+ contact: t.optional(t.string()),
42
+ category: t.optional(t.string()),
43
+ status: t.optional(t.enum([
44
+ "pending",
45
+ "sent",
46
+ "failed"
47
+ ]))
48
+ });
49
+
50
+ //#endregion
51
+ //#region src/api-notifications/primitives/$notification.ts
52
+ /**
53
+ * Creates a notification primitive for managing email/SMS notification templates.
54
+ *
55
+ * Provides type-safe, reusable notification templates with multi-language support,
56
+ * variable substitution, and categorization for different notification channels.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * class NotificationTemplates {
61
+ * welcomeEmail = $notification({
62
+ * name: "welcome-email",
63
+ * category: "onboarding",
64
+ * schema: t.object({ username: t.text(), activationLink: t.text() }),
65
+ * email: {
66
+ * subject: "Welcome to our platform!",
67
+ * body: (vars) => `Hello ${vars.username}, click: ${vars.activationLink}`
68
+ * }
69
+ * });
70
+ *
71
+ * async sendWelcome(user: User) {
72
+ * await this.welcomeEmail.push({
73
+ * variables: { username: user.name, activationLink: generateLink() },
74
+ * contact: user.email
75
+ * });
76
+ * }
77
+ * }
78
+ * ```
79
+ */
80
+ const $notification = (options) => createPrimitive(NotificationPrimitive, options);
81
+ var NotificationPrimitive = class extends Primitive {
82
+ notificationService = $inject(NotificationService);
83
+ get name() {
84
+ return this.options.name ?? `${this.config.propertyKey}`;
85
+ }
86
+ async push(options) {
87
+ if (this.options.email) await this.notificationService.createNotification({
88
+ ...options,
89
+ type: "email",
90
+ template: this.name
91
+ });
92
+ }
93
+ configure(options) {
94
+ Object.assign(this.options, options);
95
+ }
96
+ };
97
+ $notification[KIND] = NotificationPrimitive;
98
+
99
+ //#endregion
100
+ //#region src/api-notifications/services/NotificationSenderService.ts
101
+ var NotificationSenderService = class {
102
+ alepha = $inject(Alepha);
103
+ log = $logger();
104
+ notificationRepository = $repository(notifications);
105
+ dateTimeProvider = $inject(DateTimeProvider);
106
+ emailProvider = $inject(EmailProvider);
107
+ smsProvider = $inject(SmsProvider);
108
+ async send(notificationId) {
109
+ this.log.trace("Sending notification", { notificationId: typeof notificationId === "string" ? notificationId : notificationId.id });
110
+ const notification = typeof notificationId === "string" ? await this.notificationRepository.findById(notificationId) : notificationId;
111
+ if (notification.sentAt) {
112
+ this.log.debug("Notification already sent", {
113
+ notificationId: notification.id,
114
+ sentAt: notification.sentAt
115
+ });
116
+ return;
117
+ }
118
+ this.log.debug("Processing notification", {
119
+ id: notification.id,
120
+ type: notification.type,
121
+ template: notification.template,
122
+ contact: notification.contact
123
+ });
124
+ try {
125
+ if (notification.type === "email") {
126
+ await this.emailProvider.send(this.renderEmail(notification));
127
+ notification.sentAt = this.dateTimeProvider.nowISOString();
128
+ this.log.info("Email notification sent", {
129
+ id: notification.id,
130
+ template: notification.template,
131
+ contact: notification.contact
132
+ });
133
+ }
134
+ if (notification.type === "sms") {
135
+ await this.smsProvider.send(this.renderSms(notification));
136
+ notification.sentAt = this.dateTimeProvider.nowISOString();
137
+ this.log.info("SMS notification sent", {
138
+ id: notification.id,
139
+ template: notification.template,
140
+ contact: notification.contact
141
+ });
142
+ }
143
+ } catch (e) {
144
+ this.log.error("Failed to send notification", {
145
+ id: notification.id,
146
+ type: notification.type,
147
+ template: notification.template,
148
+ contact: notification.contact,
149
+ error: e
150
+ });
151
+ if (e instanceof Error) notification.error = {
152
+ at: this.dateTimeProvider.nowISOString(),
153
+ name: e.name,
154
+ message: e.message
155
+ };
156
+ } finally {
157
+ await this.notificationRepository.save(notification);
158
+ }
159
+ }
160
+ renderSms(notification) {
161
+ this.log.trace("Rendering SMS notification", {
162
+ id: notification.id,
163
+ template: notification.template
164
+ });
165
+ const { variables, contact, template } = this.load(notification);
166
+ const sms = template.options.sms;
167
+ if (!sms) {
168
+ this.log.error("Notification template has no SMS defined", {
169
+ id: notification.id,
170
+ template: notification.template
171
+ });
172
+ throw new AlephaError(`Notification template ${notification.template} has no sms defined`);
173
+ }
174
+ this.log.debug("Rendering SMS", {
175
+ template: notification.template,
176
+ contact
177
+ });
178
+ return {
179
+ to: contact,
180
+ message: typeof sms.message === "function" ? sms.message(variables) : sms.message
181
+ };
182
+ }
183
+ renderEmail(notification) {
184
+ this.log.trace("Rendering email notification", {
185
+ id: notification.id,
186
+ template: notification.template
187
+ });
188
+ const { variables, contact, template } = this.load(notification);
189
+ const email = template.options.email;
190
+ if (!email) {
191
+ this.log.error("Notification template has no email defined", {
192
+ id: notification.id,
193
+ template: notification.template
194
+ });
195
+ throw new AlephaError(`Notification template ${notification.template} has no email defined`);
196
+ }
197
+ this.log.debug("Rendering email", {
198
+ template: notification.template,
199
+ contact,
200
+ subject: email.subject
201
+ });
202
+ return {
203
+ to: contact,
204
+ subject: email.subject,
205
+ body: typeof email.body === "function" ? email.body(variables) : email.body
206
+ };
207
+ }
208
+ load(notification) {
209
+ const variables = notification.variables || {};
210
+ const contact = notification.contact;
211
+ const template = this.alepha.primitives($notification).find((it) => it.name === notification.template);
212
+ if (!template) {
213
+ this.log.error("Notification template not found", {
214
+ id: notification.id,
215
+ template: notification.template
216
+ });
217
+ throw new AlephaError(`No notification template found for ${notification.template}`);
218
+ }
219
+ return {
220
+ template,
221
+ variables,
222
+ contact
223
+ };
224
+ }
225
+ };
226
+
227
+ //#endregion
228
+ //#region src/api-notifications/queues/NotificationQueues.ts
229
+ var NotificationQueues = class {
230
+ notificationSenderService = $inject(NotificationSenderService);
231
+ processNotification = $queue({
232
+ description: "Queue for processing notifications",
233
+ schema: t.object({ notificationId: t.string({ format: "uuid" }) }),
234
+ handler: async (message) => {
235
+ await this.notificationSenderService.send(message.payload.notificationId);
236
+ }
237
+ });
238
+ };
239
+
240
+ //#endregion
241
+ //#region src/api-notifications/schemas/notificationCreateSchema.ts
242
+ const notificationCreateSchema = t.pick(notifications.schema, [
243
+ "type",
244
+ "contact",
245
+ "template",
246
+ "variables"
247
+ ]);
248
+
249
+ //#endregion
250
+ //#region src/api-notifications/services/NotificationService.ts
251
+ const notificationServiceEnvSchema = t.object({ NOTIFICATION_QUEUE: t.optional(t.boolean({ description: "If true, notifications will be queued instead of sent immediately" })) });
252
+ var NotificationService = class {
253
+ alepha = $inject(Alepha);
254
+ log = $logger();
255
+ env = $env(notificationServiceEnvSchema);
256
+ notificationRepository = $repository(notifications);
257
+ dateTimeProvider = $inject(DateTimeProvider);
258
+ notificationSenderService = $inject(NotificationSenderService);
259
+ notificationBatch = $batch({
260
+ maxSize: 100,
261
+ maxDuration: [15, "seconds"],
262
+ schema: notificationCreateSchema,
263
+ handler: async (notifications$1) => {
264
+ this.log.debug("Processing notification batch", {
265
+ size: notifications$1.length,
266
+ templates: [...new Set(notifications$1.map((n) => n.template))]
267
+ });
268
+ const entities = await this.notificationRepository.createMany(notifications$1);
269
+ await this.alepha.inject(NotificationQueues).processNotification.push(...entities.map((it) => ({ notificationId: it.id })));
270
+ this.log.info("Notification batch queued", {
271
+ count: entities.length,
272
+ ids: entities.map((it) => it.id)
273
+ });
274
+ }
275
+ });
276
+ async findNotificationById(id) {
277
+ this.log.trace("Finding notification by ID", { id });
278
+ return this.notificationRepository.findOne({ where: { id } });
279
+ }
280
+ async findNotifications(q = {}) {
281
+ this.log.trace("Finding notifications", { query: q });
282
+ q.sort ??= "-createdAt";
283
+ const where = this.notificationRepository.createQueryWhere();
284
+ if (q.type) where.type = { eq: q.type };
285
+ if (q.template) where.template = { like: `%${q.template}%` };
286
+ if (q.contact) where.contact = { like: `%${q.contact}%` };
287
+ if (q.category) where.category = { eq: q.category };
288
+ if (q.status) {
289
+ if (q.status === "sent") {
290
+ where.sentAt = { isNotNull: true };
291
+ where.error = { isNull: true };
292
+ } else if (q.status === "failed") where.error = { isNotNull: true };
293
+ else if (q.status === "pending") {
294
+ where.sentAt = { isNull: true };
295
+ where.error = { isNull: true };
296
+ }
297
+ }
298
+ return this.notificationRepository.paginate(q, { where }, { count: true });
299
+ }
300
+ /**
301
+ * Create a new notification.
302
+ */
303
+ async createNotification(entry) {
304
+ this.log.trace("Creating notification", {
305
+ template: entry.template,
306
+ type: entry.type,
307
+ contact: entry.contact
308
+ });
309
+ if (this.env.NOTIFICATION_QUEUE !== true || this.alepha.isServerless() || this.alepha.isTest()) {
310
+ this.log.debug("Sending notification immediately", {
311
+ template: entry.template,
312
+ type: entry.type,
313
+ contact: entry.contact
314
+ });
315
+ const notification = await this.notificationRepository.create(entry);
316
+ await this.notificationSenderService.send(notification);
317
+ return;
318
+ }
319
+ this.log.debug("Queuing notification to batch", {
320
+ template: entry.template,
321
+ type: entry.type,
322
+ contact: entry.contact
323
+ });
324
+ this.notificationBatch.push(entry).catch((e) => {
325
+ this.log.error("Failed to push notification to batch", {
326
+ template: entry.template,
327
+ type: entry.type,
328
+ contact: entry.contact,
329
+ error: e
330
+ });
331
+ });
332
+ }
333
+ };
334
+
335
+ //#endregion
336
+ //#region src/api-notifications/controllers/NotificationController.ts
337
+ var NotificationController = class {
338
+ url = "/notifications";
339
+ group = "notifications";
340
+ notificationService = $inject(NotificationService);
341
+ /**
342
+ * Find notifications with pagination and filtering.
343
+ */
344
+ findNotifications = $action({
345
+ path: this.url,
346
+ group: this.group,
347
+ description: "Find notifications with pagination and filtering",
348
+ schema: {
349
+ query: notificationQuerySchema,
350
+ response: pg.page(notifications.schema)
351
+ },
352
+ handler: ({ query }) => this.notificationService.findNotifications(query)
353
+ });
354
+ };
355
+
356
+ //#endregion
357
+ //#region src/api-notifications/schemas/notificationContactPreferencesSchema.ts
358
+ const notificationContactPreferencesSchema = t.object({
359
+ language: t.optional(t.text()),
360
+ exclude: t.array(t.text())
361
+ });
362
+
363
+ //#endregion
364
+ //#region src/api-notifications/schemas/notificationContactSchema.ts
365
+ const notificationContactSchema = t.object({
366
+ email: t.optional(t.email()),
367
+ phoneNumber: t.optional(t.e164()),
368
+ firstName: t.optional(t.shortText()),
369
+ lastName: t.optional(t.text({ size: "short" })),
370
+ language: t.optional(t.bcp47())
371
+ });
372
+
373
+ //#endregion
374
+ //#region src/api-notifications/index.browser.ts
375
+ const AlephaApiNotifications = $module({
376
+ name: "alepha.api.notifications",
377
+ services: []
378
+ });
379
+
380
+ //#endregion
381
+ export { AlephaApiNotifications, NotificationController, notificationContactPreferencesSchema, notificationContactSchema, notificationCreateSchema, notificationQuerySchema, notifications };
382
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.js","names":["notifications"],"sources":["../../src/api-notifications/entities/notifications.ts","../../src/api-notifications/schemas/notificationQuerySchema.ts","../../src/api-notifications/primitives/$notification.ts","../../src/api-notifications/services/NotificationSenderService.ts","../../src/api-notifications/queues/NotificationQueues.ts","../../src/api-notifications/schemas/notificationCreateSchema.ts","../../src/api-notifications/services/NotificationService.ts","../../src/api-notifications/controllers/NotificationController.ts","../../src/api-notifications/schemas/notificationContactPreferencesSchema.ts","../../src/api-notifications/schemas/notificationContactSchema.ts","../../src/api-notifications/index.browser.ts"],"sourcesContent":["import { type Static, t } from \"alepha\";\nimport { $entity, pg } from \"alepha/orm\";\n\nexport const notifications = $entity({\n name: \"notifications\",\n schema: t.object({\n id: pg.primaryKey(t.uuid()),\n\n version: pg.version(),\n\n createdAt: pg.createdAt(),\n\n updatedAt: pg.updatedAt(),\n\n // -----------------------------------------------------------------------------------------------------------------\n\n type: t.enum([\"email\", \"sms\"]),\n\n template: t.text(), // e.g. 'resetPassword'\n\n category: t.optional(\n t.text({\n description:\n \"For grouping related notifications (e.g., 'authentication', 'marketing'). Contact can filter notifications by category.\",\n }),\n ),\n\n critical: t.optional(\n t.boolean({\n description:\n \"Prioritize delivery of this notification. Set to true for important system alerts.\",\n }),\n ),\n\n sensitive: t.optional(\n t.boolean({\n description:\n \"Message won't be logged or stored in plain text. Set to true when notification contains passwords or codes.\",\n }),\n ),\n\n // -----------------------------------------------------------------------------------------------------------------\n\n contact: t.text(), // e.g. email address or phone number or user ID or whatever\n\n variables: t.optional(t.record(t.text(), t.any())),\n\n scheduledAt: t.optional(\n t.datetime({\n description:\n \"When set, the notification will be sent at or after this date/time.\",\n }),\n ),\n\n // -----------------------------------------------------------------------------------------------------------------\n\n sentAt: t.optional(t.datetime()),\n\n error: t.optional(\n t.object({\n at: t.datetime(),\n name: t.text(),\n message: t.text({ size: \"rich\" }),\n }),\n ),\n\n // TODO: retryCount, lastRetryAt, etc.\n }),\n});\n\nexport type NotificationEntity = Static<typeof notifications.schema>;\n","import type { Static } from \"alepha\";\nimport { t } from \"alepha\";\nimport { pageQuerySchema } from \"alepha/orm\";\n\nexport const notificationQuerySchema = t.extend(pageQuerySchema, {\n type: t.optional(t.enum([\"email\", \"sms\"])),\n template: t.optional(t.string()),\n contact: t.optional(t.string()),\n category: t.optional(t.string()),\n status: t.optional(t.enum([\"pending\", \"sent\", \"failed\"])),\n});\n\nexport type NotificationQuery = Static<typeof notificationQuerySchema>;\n","import {\n $inject,\n createPrimitive,\n KIND,\n Primitive,\n type Static,\n type StaticEncode,\n type TObject,\n} from \"alepha\";\nimport { NotificationService } from \"../services/NotificationService.ts\";\n\n/**\n * Creates a notification primitive for managing email/SMS notification templates.\n *\n * Provides type-safe, reusable notification templates with multi-language support,\n * variable substitution, and categorization for different notification channels.\n *\n * @example\n * ```ts\n * class NotificationTemplates {\n * welcomeEmail = $notification({\n * name: \"welcome-email\",\n * category: \"onboarding\",\n * schema: t.object({ username: t.text(), activationLink: t.text() }),\n * email: {\n * subject: \"Welcome to our platform!\",\n * body: (vars) => `Hello ${vars.username}, click: ${vars.activationLink}`\n * }\n * });\n *\n * async sendWelcome(user: User) {\n * await this.welcomeEmail.push({\n * variables: { username: user.name, activationLink: generateLink() },\n * contact: user.email\n * });\n * }\n * }\n * ```\n */\nexport const $notification = <T extends TObject>(\n options: NotificationPrimitiveOptions<T>,\n) => createPrimitive(NotificationPrimitive<T>, options);\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface NotificationPrimitiveOptions<T extends TObject>\n extends NotificationMessage<T> {\n name?: string;\n description?: string;\n category?: string;\n critical?: boolean;\n sensitive?: boolean;\n translations?: {\n // e.g., \"en\", \"fr\", even \"en-US\"\n [lang: string]: NotificationMessage<T>;\n };\n schema: T;\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class NotificationPrimitive<T extends TObject> extends Primitive<\n NotificationPrimitiveOptions<T>\n> {\n protected readonly notificationService = $inject(NotificationService);\n\n public get name() {\n return this.options.name ?? `${this.config.propertyKey}`;\n }\n\n public async push(options: NotificationPushOptions<T>) {\n if (this.options.email) {\n await this.notificationService.createNotification({\n ...options,\n type: \"email\",\n template: this.name,\n });\n }\n }\n\n public configure(options: Partial<NotificationPrimitiveOptions<T>>) {\n Object.assign(this.options, options);\n }\n}\n\n$notification[KIND] = NotificationPrimitive;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface NotificationPushOptions<T extends TObject> {\n variables: StaticEncode<T>;\n contact: string;\n}\n\nexport interface NotificationMessage<T extends TObject> {\n email?: {\n subject: string;\n body: string | ((variables: Static<T>) => string);\n };\n sms?: {\n message: string | ((variables: Static<T>) => string);\n };\n}\n","import { $inject, Alepha, AlephaError } from \"alepha\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { EmailProvider } from \"alepha/email\";\nimport { $logger } from \"alepha/logger\";\nimport { $repository } from \"alepha/orm\";\nimport { SmsProvider } from \"alepha/sms\";\nimport {\n type NotificationEntity,\n notifications,\n} from \"../entities/notifications.ts\";\nimport { $notification } from \"../primitives/$notification.ts\";\n\nexport class NotificationSenderService {\n protected readonly alepha = $inject(Alepha);\n protected readonly log = $logger();\n protected readonly notificationRepository = $repository(notifications);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly emailProvider = $inject(EmailProvider);\n protected readonly smsProvider = $inject(SmsProvider);\n\n public async send(notificationId: string | NotificationEntity) {\n this.log.trace(\"Sending notification\", {\n notificationId:\n typeof notificationId === \"string\" ? notificationId : notificationId.id,\n });\n\n const notification =\n typeof notificationId === \"string\"\n ? await this.notificationRepository.findById(notificationId)\n : notificationId;\n\n if (notification.sentAt) {\n this.log.debug(\"Notification already sent\", {\n notificationId: notification.id,\n sentAt: notification.sentAt,\n });\n return;\n }\n\n this.log.debug(\"Processing notification\", {\n id: notification.id,\n type: notification.type,\n template: notification.template,\n contact: notification.contact,\n });\n\n try {\n if (notification.type === \"email\") {\n await this.emailProvider.send(this.renderEmail(notification));\n notification.sentAt = this.dateTimeProvider.nowISOString();\n this.log.info(\"Email notification sent\", {\n id: notification.id,\n template: notification.template,\n contact: notification.contact,\n });\n }\n if (notification.type === \"sms\") {\n await this.smsProvider.send(this.renderSms(notification));\n notification.sentAt = this.dateTimeProvider.nowISOString();\n this.log.info(\"SMS notification sent\", {\n id: notification.id,\n template: notification.template,\n contact: notification.contact,\n });\n }\n } catch (e) {\n this.log.error(\"Failed to send notification\", {\n id: notification.id,\n type: notification.type,\n template: notification.template,\n contact: notification.contact,\n error: e,\n });\n if (e instanceof Error) {\n notification.error = {\n at: this.dateTimeProvider.nowISOString(),\n name: e.name,\n message: e.message,\n };\n }\n } finally {\n await this.notificationRepository.save(notification);\n }\n }\n\n public renderSms(notification: NotificationEntity) {\n this.log.trace(\"Rendering SMS notification\", {\n id: notification.id,\n template: notification.template,\n });\n\n const { variables, contact, template } = this.load(notification);\n\n const sms = template.options.sms;\n if (!sms) {\n this.log.error(\"Notification template has no SMS defined\", {\n id: notification.id,\n template: notification.template,\n });\n throw new AlephaError(\n `Notification template ${notification.template} has no sms defined`,\n );\n }\n\n this.log.debug(\"Rendering SMS\", {\n template: notification.template,\n contact,\n });\n\n const message =\n typeof sms.message === \"function\"\n ? sms.message(variables as any)\n : sms.message;\n\n return {\n to: contact,\n message,\n };\n }\n\n public renderEmail(notification: NotificationEntity) {\n this.log.trace(\"Rendering email notification\", {\n id: notification.id,\n template: notification.template,\n });\n\n const { variables, contact, template } = this.load(notification);\n\n const email = template.options.email;\n if (!email) {\n this.log.error(\"Notification template has no email defined\", {\n id: notification.id,\n template: notification.template,\n });\n throw new AlephaError(\n `Notification template ${notification.template} has no email defined`,\n );\n }\n\n this.log.debug(\"Rendering email\", {\n template: notification.template,\n contact,\n subject: email.subject,\n });\n\n const subject = email.subject;\n\n const body =\n typeof email.body === \"function\"\n ? email.body(variables as any)\n : email.body;\n\n return {\n to: contact,\n subject,\n body,\n };\n }\n\n protected load(notification: NotificationEntity) {\n const variables = notification.variables || {};\n const contact = notification.contact;\n const template = this.alepha\n .primitives($notification)\n .find((it) => it.name === notification.template);\n\n if (!template) {\n this.log.error(\"Notification template not found\", {\n id: notification.id,\n template: notification.template,\n });\n throw new AlephaError(\n `No notification template found for ${notification.template}`,\n );\n }\n\n return {\n template,\n variables,\n contact,\n };\n }\n}\n","import { $inject, t } from \"alepha\";\nimport { $queue } from \"alepha/queue\";\nimport { NotificationSenderService } from \"../services/NotificationSenderService.ts\";\n\nexport class NotificationQueues {\n protected readonly notificationSenderService = $inject(\n NotificationSenderService,\n );\n\n public readonly processNotification = $queue({\n description: \"Queue for processing notifications\",\n schema: t.object({\n notificationId: t.string({ format: \"uuid\" }),\n }),\n handler: async (message) => {\n await this.notificationSenderService.send(message.payload.notificationId);\n },\n });\n}\n","import { type Static, t } from \"alepha\";\nimport { notifications } from \"../entities/notifications.ts\";\n\nexport const notificationCreateSchema = t.pick(notifications.schema, [\n \"type\",\n \"contact\",\n \"template\",\n \"variables\",\n]);\n\nexport type NotificationCreate = Static<typeof notificationCreateSchema>;\n","import { $env, $inject, Alepha, type Static, t } from \"alepha\";\nimport { $batch } from \"alepha/batch\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { $logger } from \"alepha/logger\";\nimport { $repository, type Page } from \"alepha/orm\";\nimport {\n type NotificationEntity,\n notifications,\n} from \"../entities/notifications.ts\";\nimport { NotificationQueues } from \"../queues/NotificationQueues.ts\";\nimport {\n type NotificationCreate,\n notificationCreateSchema,\n} from \"../schemas/notificationCreateSchema.ts\";\nimport type { NotificationQuery } from \"../schemas/notificationQuerySchema.ts\";\nimport { NotificationSenderService } from \"./NotificationSenderService.ts\";\n\nexport const notificationServiceEnvSchema = t.object({\n NOTIFICATION_QUEUE: t.optional(\n t.boolean({\n description:\n \"If true, notifications will be queued instead of sent immediately\",\n }),\n ),\n});\n\ndeclare module \"alepha\" {\n interface Env extends Partial<Static<typeof notificationServiceEnvSchema>> {}\n}\n\nexport class NotificationService {\n protected readonly alepha = $inject(Alepha);\n protected readonly log = $logger();\n protected readonly env = $env(notificationServiceEnvSchema);\n protected readonly notificationRepository = $repository(notifications);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n protected readonly notificationSenderService = $inject(\n NotificationSenderService,\n );\n\n public readonly notificationBatch = $batch({\n maxSize: 100,\n maxDuration: [15, \"seconds\"],\n schema: notificationCreateSchema,\n handler: async (notifications: NotificationCreate[]) => {\n this.log.debug(\"Processing notification batch\", {\n size: notifications.length,\n templates: [...new Set(notifications.map((n) => n.template))],\n });\n\n const entities =\n await this.notificationRepository.createMany(notifications);\n\n await this.alepha\n .inject(NotificationQueues)\n .processNotification.push(\n ...entities.map((it) => ({ notificationId: it.id })),\n );\n\n this.log.info(\"Notification batch queued\", {\n count: entities.length,\n ids: entities.map((it) => it.id),\n });\n },\n });\n\n public async findNotificationById(id: string) {\n this.log.trace(\"Finding notification by ID\", { id });\n return this.notificationRepository.findOne({ where: { id } });\n }\n\n public async findNotifications(\n q: NotificationQuery = {},\n ): Promise<Page<NotificationEntity>> {\n this.log.trace(\"Finding notifications\", { query: q });\n q.sort ??= \"-createdAt\";\n\n const where = this.notificationRepository.createQueryWhere();\n\n if (q.type) {\n where.type = { eq: q.type };\n }\n\n if (q.template) {\n where.template = { like: `%${q.template}%` };\n }\n\n if (q.contact) {\n where.contact = { like: `%${q.contact}%` };\n }\n\n if (q.category) {\n where.category = { eq: q.category };\n }\n\n if (q.status) {\n if (q.status === \"sent\") {\n where.sentAt = { isNotNull: true };\n where.error = { isNull: true };\n } else if (q.status === \"failed\") {\n where.error = { isNotNull: true };\n } else if (q.status === \"pending\") {\n where.sentAt = { isNull: true };\n where.error = { isNull: true };\n }\n }\n\n return this.notificationRepository.paginate(q, { where }, { count: true });\n }\n\n /**\n * Create a new notification.\n */\n public async createNotification(entry: NotificationCreate): Promise<void> {\n this.log.trace(\"Creating notification\", {\n template: entry.template,\n type: entry.type,\n contact: entry.contact,\n });\n\n if (\n this.env.NOTIFICATION_QUEUE !== true ||\n this.alepha.isServerless() ||\n this.alepha.isTest()\n ) {\n this.log.debug(\"Sending notification immediately\", {\n template: entry.template,\n type: entry.type,\n contact: entry.contact,\n });\n const notification = await this.notificationRepository.create(entry);\n await this.notificationSenderService.send(notification);\n return;\n }\n\n this.log.debug(\"Queuing notification to batch\", {\n template: entry.template,\n type: entry.type,\n contact: entry.contact,\n });\n\n this.notificationBatch.push(entry).catch((e) => {\n this.log.error(\"Failed to push notification to batch\", {\n template: entry.template,\n type: entry.type,\n contact: entry.contact,\n error: e,\n });\n });\n }\n}\n","import { $inject } from \"alepha\";\nimport { pg } from \"alepha/orm\";\nimport { $action } from \"alepha/server\";\nimport { notifications } from \"../entities/notifications.ts\";\nimport { notificationQuerySchema } from \"../schemas/notificationQuerySchema.ts\";\nimport { NotificationService } from \"../services/NotificationService.ts\";\n\nexport class NotificationController {\n protected readonly url = \"/notifications\";\n protected readonly group = \"notifications\";\n protected readonly notificationService = $inject(NotificationService);\n\n /**\n * Find notifications with pagination and filtering.\n */\n public readonly findNotifications = $action({\n path: this.url,\n group: this.group,\n description: \"Find notifications with pagination and filtering\",\n schema: {\n query: notificationQuerySchema,\n response: pg.page(notifications.schema),\n },\n handler: ({ query }) => this.notificationService.findNotifications(query),\n });\n}\n","import { type Static, t } from \"alepha\";\n\nexport const notificationContactPreferencesSchema = t.object({\n language: t.optional(t.text()),\n exclude: t.array(t.text()),\n});\n\nexport type NotificationContactPreferences = Static<\n typeof notificationContactPreferencesSchema\n>;\n","import { type Static, t } from \"alepha\";\n\nexport const notificationContactSchema = t.object({\n email: t.optional(t.email()),\n phoneNumber: t.optional(t.e164()),\n firstName: t.optional(t.shortText()),\n lastName: t.optional(t.text({ size: \"short\" })),\n language: t.optional(t.bcp47()),\n});\n\nexport type NotificationContact = Static<typeof notificationContactSchema>;\n","import { $module } from \"alepha\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./controllers/NotificationController.ts\";\nexport * from \"./entities/notifications.ts\";\nexport * from \"./schemas/notificationContactPreferencesSchema.ts\";\nexport * from \"./schemas/notificationContactSchema.ts\";\nexport * from \"./schemas/notificationCreateSchema.ts\";\nexport * from \"./schemas/notificationQuerySchema.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport const AlephaApiNotifications = $module({\n name: \"alepha.api.notifications\",\n services: [],\n});\n"],"mappings":";;;;;;;;;;;AAGA,MAAa,gBAAgB,QAAQ;CACnC,MAAM;CACN,QAAQ,EAAE,OAAO;EACf,IAAI,GAAG,WAAW,EAAE,MAAM,CAAC;EAE3B,SAAS,GAAG,SAAS;EAErB,WAAW,GAAG,WAAW;EAEzB,WAAW,GAAG,WAAW;EAIzB,MAAM,EAAE,KAAK,CAAC,SAAS,MAAM,CAAC;EAE9B,UAAU,EAAE,MAAM;EAElB,UAAU,EAAE,SACV,EAAE,KAAK,EACL,aACE,2HACH,CAAC,CACH;EAED,UAAU,EAAE,SACV,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