hazo_notify 1.1.4 → 3.1.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 (236) hide show
  1. package/README.md +163 -41
  2. package/dist/components/template_manager/category_dialog.d.ts +11 -0
  3. package/dist/components/template_manager/category_dialog.d.ts.map +1 -0
  4. package/dist/components/template_manager/category_dialog.js +41 -0
  5. package/dist/components/template_manager/category_dialog.js.map +1 -0
  6. package/dist/components/template_manager/category_tree.d.ts +13 -0
  7. package/dist/components/template_manager/category_tree.d.ts.map +1 -0
  8. package/dist/components/template_manager/category_tree.js +45 -0
  9. package/dist/components/template_manager/category_tree.js.map +1 -0
  10. package/dist/components/template_manager/index.d.ts +10 -0
  11. package/dist/components/template_manager/index.d.ts.map +1 -0
  12. package/dist/components/template_manager/index.js +8 -0
  13. package/dist/components/template_manager/index.js.map +1 -0
  14. package/dist/components/template_manager/preview_dialog.d.ts +11 -0
  15. package/dist/components/template_manager/preview_dialog.d.ts.map +1 -0
  16. package/dist/components/template_manager/preview_dialog.js +15 -0
  17. package/dist/components/template_manager/preview_dialog.js.map +1 -0
  18. package/dist/components/template_manager/template_dialog.d.ts +12 -0
  19. package/dist/components/template_manager/template_dialog.d.ts.map +1 -0
  20. package/dist/components/template_manager/template_dialog.js +46 -0
  21. package/dist/components/template_manager/template_dialog.js.map +1 -0
  22. package/dist/components/template_manager/template_editor.d.ts +12 -0
  23. package/dist/components/template_manager/template_editor.d.ts.map +1 -0
  24. package/dist/components/template_manager/template_editor.js +57 -0
  25. package/dist/components/template_manager/template_editor.js.map +1 -0
  26. package/dist/components/template_manager/template_globals_admin.d.ts +8 -0
  27. package/dist/components/template_manager/template_globals_admin.d.ts.map +1 -0
  28. package/dist/components/template_manager/template_globals_admin.js +27 -0
  29. package/dist/components/template_manager/template_globals_admin.js.map +1 -0
  30. package/dist/components/template_manager/template_manager_admin.d.ts +44 -0
  31. package/dist/components/template_manager/template_manager_admin.d.ts.map +1 -0
  32. package/dist/components/template_manager/template_manager_admin.js +272 -0
  33. package/dist/components/template_manager/template_manager_admin.js.map +1 -0
  34. package/dist/lib/emailer/emailer.d.ts.map +1 -0
  35. package/dist/lib/emailer/emailer.js.map +1 -0
  36. package/dist/lib/emailer/index.d.ts.map +1 -0
  37. package/dist/lib/emailer/index.js.map +1 -0
  38. package/dist/lib/emailer/providers/index.d.ts.map +1 -0
  39. package/dist/lib/emailer/providers/index.js.map +1 -0
  40. package/dist/lib/emailer/providers/pop3_provider.d.ts.map +1 -0
  41. package/dist/lib/emailer/providers/pop3_provider.js.map +1 -0
  42. package/dist/lib/emailer/providers/smtp_provider.d.ts.map +1 -0
  43. package/dist/lib/emailer/providers/smtp_provider.js.map +1 -0
  44. package/dist/lib/emailer/providers/zeptomail_provider.d.ts.map +1 -0
  45. package/dist/{emailer → lib/emailer}/providers/zeptomail_provider.js +9 -6
  46. package/dist/lib/emailer/providers/zeptomail_provider.js.map +1 -0
  47. package/dist/lib/emailer/types.d.ts.map +1 -0
  48. package/dist/lib/emailer/types.js.map +1 -0
  49. package/dist/lib/emailer/utils/constants.d.ts.map +1 -0
  50. package/dist/lib/emailer/utils/constants.js.map +1 -0
  51. package/dist/lib/emailer/utils/index.d.ts.map +1 -0
  52. package/dist/lib/emailer/utils/index.js.map +1 -0
  53. package/dist/lib/emailer/utils/logger.d.ts.map +1 -0
  54. package/dist/lib/emailer/utils/logger.js.map +1 -0
  55. package/dist/lib/emailer/utils/validation.d.ts.map +1 -0
  56. package/dist/lib/emailer/utils/validation.js.map +1 -0
  57. package/dist/lib/index.d.ts.map +1 -0
  58. package/dist/lib/index.js.map +1 -0
  59. package/dist/lib/template_manager/cache/scope_chain_cache.d.ts +26 -0
  60. package/dist/lib/template_manager/cache/scope_chain_cache.d.ts.map +1 -0
  61. package/dist/lib/template_manager/cache/scope_chain_cache.js +60 -0
  62. package/dist/lib/template_manager/cache/scope_chain_cache.js.map +1 -0
  63. package/dist/{template_manager → lib/template_manager}/config/config_loader.d.ts +16 -15
  64. package/dist/lib/template_manager/config/config_loader.d.ts.map +1 -0
  65. package/dist/lib/template_manager/config/config_loader.js +98 -0
  66. package/dist/lib/template_manager/config/config_loader.js.map +1 -0
  67. package/dist/{template_manager → lib/template_manager}/config/constants.d.ts +4 -54
  68. package/dist/lib/template_manager/config/constants.d.ts.map +1 -0
  69. package/dist/{template_manager → lib/template_manager}/config/constants.js +4 -84
  70. package/dist/lib/template_manager/config/constants.js.map +1 -0
  71. package/dist/lib/template_manager/config/index.d.ts.map +1 -0
  72. package/dist/lib/template_manager/config/index.js.map +1 -0
  73. package/dist/{template_manager → lib/template_manager}/db/category_repository.d.ts +22 -14
  74. package/dist/lib/template_manager/db/category_repository.d.ts.map +1 -0
  75. package/dist/{template_manager → lib/template_manager}/db/category_repository.js +127 -83
  76. package/dist/lib/template_manager/db/category_repository.js.map +1 -0
  77. package/dist/lib/template_manager/db/index.d.ts +6 -0
  78. package/dist/lib/template_manager/db/index.d.ts.map +1 -0
  79. package/dist/lib/template_manager/db/index.js +6 -0
  80. package/dist/lib/template_manager/db/index.js.map +1 -0
  81. package/dist/{template_manager → lib/template_manager}/db/template_repository.d.ts +25 -28
  82. package/dist/lib/template_manager/db/template_repository.d.ts.map +1 -0
  83. package/dist/lib/template_manager/db/template_repository.js +507 -0
  84. package/dist/lib/template_manager/db/template_repository.js.map +1 -0
  85. package/dist/lib/template_manager/engine/handlebars_engine.d.ts.map +1 -0
  86. package/dist/lib/template_manager/engine/handlebars_engine.js.map +1 -0
  87. package/dist/lib/template_manager/engine/index.d.ts.map +1 -0
  88. package/dist/lib/template_manager/engine/index.js.map +1 -0
  89. package/dist/{template_manager → lib/template_manager}/engine/variable_resolver.d.ts +13 -14
  90. package/dist/lib/template_manager/engine/variable_resolver.d.ts.map +1 -0
  91. package/dist/{template_manager → lib/template_manager}/engine/variable_resolver.js +25 -33
  92. package/dist/lib/template_manager/engine/variable_resolver.js.map +1 -0
  93. package/dist/lib/template_manager/handlers/adapters/hazo_auth.d.ts +20 -0
  94. package/dist/lib/template_manager/handlers/adapters/hazo_auth.d.ts.map +1 -0
  95. package/dist/lib/template_manager/handlers/adapters/hazo_auth.js +46 -0
  96. package/dist/lib/template_manager/handlers/adapters/hazo_auth.js.map +1 -0
  97. package/dist/lib/template_manager/handlers/auth.d.ts +47 -0
  98. package/dist/lib/template_manager/handlers/auth.d.ts.map +1 -0
  99. package/dist/lib/template_manager/handlers/auth.js +67 -0
  100. package/dist/lib/template_manager/handlers/auth.js.map +1 -0
  101. package/dist/lib/template_manager/handlers/index.d.ts +67 -0
  102. package/dist/lib/template_manager/handlers/index.d.ts.map +1 -0
  103. package/dist/lib/template_manager/handlers/index.js +284 -0
  104. package/dist/lib/template_manager/handlers/index.js.map +1 -0
  105. package/dist/lib/template_manager/index.d.ts +56 -0
  106. package/dist/lib/template_manager/index.d.ts.map +1 -0
  107. package/dist/lib/template_manager/index.js +68 -0
  108. package/dist/lib/template_manager/index.js.map +1 -0
  109. package/dist/lib/template_manager/init.d.ts +54 -0
  110. package/dist/lib/template_manager/init.d.ts.map +1 -0
  111. package/dist/lib/template_manager/init.js +85 -0
  112. package/dist/lib/template_manager/init.js.map +1 -0
  113. package/dist/lib/template_manager/registry.d.ts +23 -0
  114. package/dist/lib/template_manager/registry.d.ts.map +1 -0
  115. package/dist/lib/template_manager/registry.js +33 -0
  116. package/dist/lib/template_manager/registry.js.map +1 -0
  117. package/dist/lib/template_manager/seed/sync.d.ts +8 -0
  118. package/dist/lib/template_manager/seed/sync.d.ts.map +1 -0
  119. package/dist/lib/template_manager/seed/sync.js +77 -0
  120. package/dist/lib/template_manager/seed/sync.js.map +1 -0
  121. package/dist/{template_manager → lib/template_manager}/template_manager.d.ts +25 -27
  122. package/dist/lib/template_manager/template_manager.d.ts.map +1 -0
  123. package/dist/{template_manager → lib/template_manager}/template_manager.js +41 -55
  124. package/dist/lib/template_manager/template_manager.js.map +1 -0
  125. package/dist/{template_manager → lib/template_manager}/types.d.ts +32 -125
  126. package/dist/lib/template_manager/types.d.ts.map +1 -0
  127. package/dist/lib/template_manager/types.js +12 -0
  128. package/dist/lib/template_manager/types.js.map +1 -0
  129. package/dist/lib/template_manager/utils/index.d.ts.map +1 -0
  130. package/dist/lib/template_manager/utils/index.js.map +1 -0
  131. package/dist/lib/template_manager/utils/system_variables.d.ts.map +1 -0
  132. package/dist/lib/template_manager/utils/system_variables.js.map +1 -0
  133. package/dist/lib/template_manager/utils/validation.d.ts.map +1 -0
  134. package/dist/lib/template_manager/utils/validation.js.map +1 -0
  135. package/dist/lib/utils.d.ts +3 -0
  136. package/dist/lib/utils.d.ts.map +1 -0
  137. package/dist/lib/utils.js +6 -0
  138. package/dist/lib/utils.js.map +1 -0
  139. package/migrations/002_scope_migration.sql +93 -0
  140. package/package.json +65 -37
  141. package/dist/emailer/emailer.d.ts.map +0 -1
  142. package/dist/emailer/emailer.js.map +0 -1
  143. package/dist/emailer/index.d.ts.map +0 -1
  144. package/dist/emailer/index.js.map +0 -1
  145. package/dist/emailer/providers/index.d.ts.map +0 -1
  146. package/dist/emailer/providers/index.js.map +0 -1
  147. package/dist/emailer/providers/pop3_provider.d.ts.map +0 -1
  148. package/dist/emailer/providers/pop3_provider.js.map +0 -1
  149. package/dist/emailer/providers/smtp_provider.d.ts.map +0 -1
  150. package/dist/emailer/providers/smtp_provider.js.map +0 -1
  151. package/dist/emailer/providers/zeptomail_provider.d.ts.map +0 -1
  152. package/dist/emailer/providers/zeptomail_provider.js.map +0 -1
  153. package/dist/emailer/types.d.ts.map +0 -1
  154. package/dist/emailer/types.js.map +0 -1
  155. package/dist/emailer/utils/constants.d.ts.map +0 -1
  156. package/dist/emailer/utils/constants.js.map +0 -1
  157. package/dist/emailer/utils/index.d.ts.map +0 -1
  158. package/dist/emailer/utils/index.js.map +0 -1
  159. package/dist/emailer/utils/logger.d.ts.map +0 -1
  160. package/dist/emailer/utils/logger.js.map +0 -1
  161. package/dist/emailer/utils/validation.d.ts.map +0 -1
  162. package/dist/emailer/utils/validation.js.map +0 -1
  163. package/dist/index.d.ts.map +0 -1
  164. package/dist/index.js.map +0 -1
  165. package/dist/template_manager/config/config_loader.d.ts.map +0 -1
  166. package/dist/template_manager/config/config_loader.js +0 -154
  167. package/dist/template_manager/config/config_loader.js.map +0 -1
  168. package/dist/template_manager/config/constants.d.ts.map +0 -1
  169. package/dist/template_manager/config/constants.js.map +0 -1
  170. package/dist/template_manager/config/index.d.ts.map +0 -1
  171. package/dist/template_manager/config/index.js.map +0 -1
  172. package/dist/template_manager/db/category_repository.d.ts.map +0 -1
  173. package/dist/template_manager/db/category_repository.js.map +0 -1
  174. package/dist/template_manager/db/index.d.ts +0 -6
  175. package/dist/template_manager/db/index.d.ts.map +0 -1
  176. package/dist/template_manager/db/index.js +0 -6
  177. package/dist/template_manager/db/index.js.map +0 -1
  178. package/dist/template_manager/db/template_repository.d.ts.map +0 -1
  179. package/dist/template_manager/db/template_repository.js +0 -674
  180. package/dist/template_manager/db/template_repository.js.map +0 -1
  181. package/dist/template_manager/engine/handlebars_engine.d.ts.map +0 -1
  182. package/dist/template_manager/engine/handlebars_engine.js.map +0 -1
  183. package/dist/template_manager/engine/index.d.ts.map +0 -1
  184. package/dist/template_manager/engine/index.js.map +0 -1
  185. package/dist/template_manager/engine/variable_resolver.d.ts.map +0 -1
  186. package/dist/template_manager/engine/variable_resolver.js.map +0 -1
  187. package/dist/template_manager/index.d.ts +0 -32
  188. package/dist/template_manager/index.d.ts.map +0 -1
  189. package/dist/template_manager/index.js +0 -41
  190. package/dist/template_manager/index.js.map +0 -1
  191. package/dist/template_manager/template_manager.d.ts.map +0 -1
  192. package/dist/template_manager/template_manager.js.map +0 -1
  193. package/dist/template_manager/types.d.ts.map +0 -1
  194. package/dist/template_manager/types.js +0 -11
  195. package/dist/template_manager/types.js.map +0 -1
  196. package/dist/template_manager/utils/index.d.ts.map +0 -1
  197. package/dist/template_manager/utils/index.js.map +0 -1
  198. package/dist/template_manager/utils/system_variables.d.ts.map +0 -1
  199. package/dist/template_manager/utils/system_variables.js.map +0 -1
  200. package/dist/template_manager/utils/validation.d.ts.map +0 -1
  201. package/dist/template_manager/utils/validation.js.map +0 -1
  202. /package/dist/{emailer → lib/emailer}/emailer.d.ts +0 -0
  203. /package/dist/{emailer → lib/emailer}/emailer.js +0 -0
  204. /package/dist/{emailer → lib/emailer}/index.d.ts +0 -0
  205. /package/dist/{emailer → lib/emailer}/index.js +0 -0
  206. /package/dist/{emailer → lib/emailer}/providers/index.d.ts +0 -0
  207. /package/dist/{emailer → lib/emailer}/providers/index.js +0 -0
  208. /package/dist/{emailer → lib/emailer}/providers/pop3_provider.d.ts +0 -0
  209. /package/dist/{emailer → lib/emailer}/providers/pop3_provider.js +0 -0
  210. /package/dist/{emailer → lib/emailer}/providers/smtp_provider.d.ts +0 -0
  211. /package/dist/{emailer → lib/emailer}/providers/smtp_provider.js +0 -0
  212. /package/dist/{emailer → lib/emailer}/providers/zeptomail_provider.d.ts +0 -0
  213. /package/dist/{emailer → lib/emailer}/types.d.ts +0 -0
  214. /package/dist/{emailer → lib/emailer}/types.js +0 -0
  215. /package/dist/{emailer → lib/emailer}/utils/constants.d.ts +0 -0
  216. /package/dist/{emailer → lib/emailer}/utils/constants.js +0 -0
  217. /package/dist/{emailer → lib/emailer}/utils/index.d.ts +0 -0
  218. /package/dist/{emailer → lib/emailer}/utils/index.js +0 -0
  219. /package/dist/{emailer → lib/emailer}/utils/logger.d.ts +0 -0
  220. /package/dist/{emailer → lib/emailer}/utils/logger.js +0 -0
  221. /package/dist/{emailer → lib/emailer}/utils/validation.d.ts +0 -0
  222. /package/dist/{emailer → lib/emailer}/utils/validation.js +0 -0
  223. /package/dist/{index.d.ts → lib/index.d.ts} +0 -0
  224. /package/dist/{index.js → lib/index.js} +0 -0
  225. /package/dist/{template_manager → lib/template_manager}/config/index.d.ts +0 -0
  226. /package/dist/{template_manager → lib/template_manager}/config/index.js +0 -0
  227. /package/dist/{template_manager → lib/template_manager}/engine/handlebars_engine.d.ts +0 -0
  228. /package/dist/{template_manager → lib/template_manager}/engine/handlebars_engine.js +0 -0
  229. /package/dist/{template_manager → lib/template_manager}/engine/index.d.ts +0 -0
  230. /package/dist/{template_manager → lib/template_manager}/engine/index.js +0 -0
  231. /package/dist/{template_manager → lib/template_manager}/utils/index.d.ts +0 -0
  232. /package/dist/{template_manager → lib/template_manager}/utils/index.js +0 -0
  233. /package/dist/{template_manager → lib/template_manager}/utils/system_variables.d.ts +0 -0
  234. /package/dist/{template_manager → lib/template_manager}/utils/system_variables.js +0 -0
  235. /package/dist/{template_manager → lib/template_manager}/utils/validation.d.ts +0 -0
  236. /package/dist/{template_manager → lib/template_manager}/utils/validation.js +0 -0
@@ -0,0 +1,284 @@
1
+ /**
2
+ * Mountable route-handler factory for the template-manager admin UI.
3
+ *
4
+ * v3.1.0 lifts the test-app's route handlers + auth wrapper into a single
5
+ * factory that consumers wire up with three lines:
6
+ *
7
+ * ```ts
8
+ * // app/api/template_manager/[...path]/route.ts
9
+ * import { create_template_manager_handlers } from 'hazo_notify/template_manager_handlers';
10
+ * import { create_hazo_auth_adapter } from 'hazo_notify/template_manager_handlers/hazo_auth';
11
+ * import { get_db } from '@/lib/db';
12
+ *
13
+ * export const dynamic = 'force-dynamic';
14
+ *
15
+ * const handlers = create_template_manager_handlers({
16
+ * hazo_connect_factory: () => get_db(),
17
+ * auth: await create_hazo_auth_adapter(),
18
+ * });
19
+ *
20
+ * export const { GET, POST, PUT, PATCH, DELETE, OPTIONS } = handlers;
21
+ * ```
22
+ *
23
+ * Routes handled (relative to mount point):
24
+ * GET /categories list categories
25
+ * POST /categories create category
26
+ * GET /categories/:id get category
27
+ * PUT /categories/:id update category (PATCH alias)
28
+ * DELETE /categories/:id delete category
29
+ * GET /templates list templates (?category_id filters)
30
+ * POST /templates create template
31
+ * GET /templates/:id get template
32
+ * PUT /templates/:id update template (PATCH alias)
33
+ * DELETE /templates/:id delete template
34
+ * GET /types list registered template types
35
+ */
36
+ import 'server-only';
37
+ import { NextResponse } from 'next/server';
38
+ import { list_categories, get_category, create_category, update_category, delete_category, } from '../db/category_repository.js';
39
+ import { list_templates, list_templates_by_category, get_template, create_template, update_template, delete_template, } from '../db/template_repository.js';
40
+ import { get_registered_template_types } from '../registry.js';
41
+ import { load_template_config } from '../config/config_loader.js';
42
+ import { create_with_template_auth, } from './auth.js';
43
+ export { create_with_template_auth } from './auth.js';
44
+ /** Resources exposed by the dispatcher (first path segment after mount). */
45
+ const KNOWN_RESOURCES = new Set(['categories', 'templates', 'types']);
46
+ function default_cors_headers() {
47
+ let allowed_origins = [];
48
+ try {
49
+ const config = load_template_config();
50
+ allowed_origins = config.cors_allowed_origins ?? [];
51
+ }
52
+ catch {
53
+ allowed_origins = [];
54
+ }
55
+ const origin = allowed_origins.length > 0 ? allowed_origins.join(', ') : '*';
56
+ return {
57
+ 'Access-Control-Allow-Origin': origin,
58
+ 'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
59
+ 'Access-Control-Allow-Headers': 'Content-Type, Authorization',
60
+ };
61
+ }
62
+ function resolve_cors(cors_headers) {
63
+ if (!cors_headers)
64
+ return default_cors_headers();
65
+ if (typeof cors_headers === 'function')
66
+ return cors_headers();
67
+ return cors_headers;
68
+ }
69
+ /** Extract the relative subpath from the URL by locating a known resource. */
70
+ function extract_subpath(pathname) {
71
+ const segments = pathname.split('/').filter(Boolean);
72
+ const idx = segments.findIndex((s) => KNOWN_RESOURCES.has(s));
73
+ if (idx < 0)
74
+ return segments;
75
+ return segments.slice(idx);
76
+ }
77
+ export function create_template_manager_handlers(options) {
78
+ const get_db = async () => await options.hazo_connect_factory();
79
+ const cors = () => resolve_cors(options.cors_headers);
80
+ // Build the per-request auth wrapper. CORS headers are resolved up-front
81
+ // for the wrapper's error responses; success responses re-resolve below
82
+ // so a per-request `cors_headers` function still wins for happy paths.
83
+ const with_template_auth = create_with_template_auth(options.auth, cors());
84
+ const json = (body, status, headers = cors()) => NextResponse.json(body, { status, headers });
85
+ const not_found = () => json({ success: false, error: 'Not found', code: 'NOT_FOUND' }, 404);
86
+ const method_not_allowed = () => json({
87
+ success: false,
88
+ error: 'Method not allowed',
89
+ code: 'METHOD_NOT_ALLOWED',
90
+ }, 405);
91
+ // ---- Internal handlers (each wrapped with auth) ---------------------
92
+ // GET /categories
93
+ const categories_list = with_template_auth(async (_req, { scope_id }) => {
94
+ const db = await get_db();
95
+ const result = await list_categories(db, scope_id);
96
+ return json(result, result.success ? 200 : 500);
97
+ });
98
+ // POST /categories
99
+ const categories_create = with_template_auth(async (req, { scope_id }) => {
100
+ const body = await req.json();
101
+ const { template_category_name } = body;
102
+ if (!template_category_name) {
103
+ return json({
104
+ success: false,
105
+ error: 'template_category_name is required',
106
+ }, 400);
107
+ }
108
+ const db = await get_db();
109
+ const result = await create_category(db, {
110
+ scope_id,
111
+ template_category_name,
112
+ });
113
+ return json(result, result.success ? 201 : 400);
114
+ });
115
+ // GET /categories/:id
116
+ const categories_get = with_template_auth(async (_req, _auth, params) => {
117
+ const db = await get_db();
118
+ const result = await get_category(db, params.id);
119
+ return json(result, result.success ? 200 : 404);
120
+ });
121
+ // PUT/PATCH /categories/:id
122
+ const categories_update = with_template_auth(async (req, _auth, params) => {
123
+ const body = await req.json();
124
+ const db = await get_db();
125
+ const result = await update_category(db, params.id, body);
126
+ const status = result.success
127
+ ? 200
128
+ : result.error?.includes('not found')
129
+ ? 404
130
+ : 500;
131
+ return json(result, status);
132
+ });
133
+ // DELETE /categories/:id
134
+ const categories_delete = with_template_auth(async (_req, _auth, params) => {
135
+ const db = await get_db();
136
+ const result = await delete_category(db, params.id);
137
+ return json(result, result.success ? 200 : 404);
138
+ });
139
+ // GET /templates
140
+ const templates_list = with_template_auth(async (req, { scope_id }) => {
141
+ const { searchParams } = new URL(req.url);
142
+ const category_id = searchParams.get('category_id');
143
+ const db = await get_db();
144
+ const result = category_id
145
+ ? await list_templates_by_category(db, category_id, scope_id)
146
+ : await list_templates(db, scope_id);
147
+ return json(result, result.success ? 200 : 500);
148
+ });
149
+ // POST /templates
150
+ const templates_create = with_template_auth(async (req, { scope_id }) => {
151
+ const body = await req.json();
152
+ const required = [
153
+ 'template_category_id',
154
+ 'template_name',
155
+ 'template_html',
156
+ 'template_text',
157
+ ];
158
+ const missing = required.filter((f) => body[f] == null);
159
+ if (missing.length > 0) {
160
+ return json({ success: false, error: `Missing: ${missing.join(', ')}` }, 400);
161
+ }
162
+ const db = await get_db();
163
+ const result = await create_template(db, {
164
+ scope_id,
165
+ template_category_id: body.template_category_id,
166
+ template_name: body.template_name,
167
+ template_html: body.template_html,
168
+ template_text: body.template_text,
169
+ template_variables: body.template_variables ?? [],
170
+ });
171
+ return json(result, result.success ? 201 : 400);
172
+ });
173
+ // GET /templates/:id
174
+ const templates_get = with_template_auth(async (_req, _auth, params) => {
175
+ const db = await get_db();
176
+ const result = await get_template(db, params.id);
177
+ return json(result, result.success ? 200 : 404);
178
+ });
179
+ // PUT/PATCH /templates/:id
180
+ const templates_update = with_template_auth(async (req, _auth, params) => {
181
+ const body = await req.json();
182
+ const db = await get_db();
183
+ const result = await update_template(db, params.id, body);
184
+ const status = result.success
185
+ ? 200
186
+ : result.error?.includes('not found')
187
+ ? 404
188
+ : 500;
189
+ return json(result, status);
190
+ });
191
+ // DELETE /templates/:id
192
+ const templates_delete = with_template_auth(async (_req, _auth, params) => {
193
+ const db = await get_db();
194
+ const result = await delete_template(db, params.id);
195
+ return json(result, result.success ? 200 : 404);
196
+ });
197
+ // GET /types
198
+ const types_list = with_template_auth(async () => {
199
+ const types = get_registered_template_types();
200
+ return json({
201
+ success: true,
202
+ data: types,
203
+ message: `Found ${types.length} template types`,
204
+ }, 200);
205
+ });
206
+ async function dispatch(request, method, raw_ctx) {
207
+ const segments = extract_subpath(request.nextUrl.pathname);
208
+ const [resource, id] = segments;
209
+ if (!resource || !KNOWN_RESOURCES.has(resource))
210
+ return not_found();
211
+ // Synthesise a Next-style RouteContext so wrapped handlers receive `id`
212
+ // even when consumer mounts under a catch-all `[...path]/route.ts`. If
213
+ // the caller already passed a `params` context (e.g. from a
214
+ // resource-specific `[id]/route.ts` file), prefer that.
215
+ const ctx_params = raw_ctx?.params ??
216
+ (id ? { id } : {});
217
+ // The wrappers each have their own `RouteContext<P>` generic; cast at the
218
+ // call site so the dispatcher can route through them uniformly. Wrappers
219
+ // re-resolve params safely at runtime.
220
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
221
+ const ctx = { params: ctx_params };
222
+ if (resource === 'categories') {
223
+ if (id) {
224
+ switch (method) {
225
+ case 'GET':
226
+ return categories_get(request, ctx);
227
+ case 'PUT':
228
+ case 'PATCH':
229
+ return categories_update(request, ctx);
230
+ case 'DELETE':
231
+ return categories_delete(request, ctx);
232
+ default:
233
+ return method_not_allowed();
234
+ }
235
+ }
236
+ switch (method) {
237
+ case 'GET':
238
+ return categories_list(request, ctx);
239
+ case 'POST':
240
+ return categories_create(request, ctx);
241
+ default:
242
+ return method_not_allowed();
243
+ }
244
+ }
245
+ if (resource === 'templates') {
246
+ if (id) {
247
+ switch (method) {
248
+ case 'GET':
249
+ return templates_get(request, ctx);
250
+ case 'PUT':
251
+ case 'PATCH':
252
+ return templates_update(request, ctx);
253
+ case 'DELETE':
254
+ return templates_delete(request, ctx);
255
+ default:
256
+ return method_not_allowed();
257
+ }
258
+ }
259
+ switch (method) {
260
+ case 'GET':
261
+ return templates_list(request, ctx);
262
+ case 'POST':
263
+ return templates_create(request, ctx);
264
+ default:
265
+ return method_not_allowed();
266
+ }
267
+ }
268
+ if (resource === 'types') {
269
+ if (id || method !== 'GET')
270
+ return method_not_allowed();
271
+ return types_list(request, ctx);
272
+ }
273
+ return not_found();
274
+ }
275
+ return {
276
+ GET: (req, ctx) => dispatch(req, 'GET', ctx),
277
+ POST: (req, ctx) => dispatch(req, 'POST', ctx),
278
+ PUT: (req, ctx) => dispatch(req, 'PUT', ctx),
279
+ PATCH: (req, ctx) => dispatch(req, 'PATCH', ctx),
280
+ DELETE: (req, ctx) => dispatch(req, 'DELETE', ctx),
281
+ OPTIONS: async () => new NextResponse(null, { status: 204, headers: cors() }),
282
+ };
283
+ }
284
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/template_manager/handlers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,aAAa,CAAC;AACrB,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,eAAe,EACf,eAAe,EACf,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,cAAc,EACd,0BAA0B,EAC1B,YAAY,EACZ,eAAe,EACf,eAAe,EACf,eAAe,GAChB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EACL,yBAAyB,GAG1B,MAAM,WAAW,CAAC;AAQnB,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAEtD,4EAA4E;AAC5E,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AA8BtE,SAAS,oBAAoB;IAC3B,IAAI,eAAe,GAAa,EAAE,CAAC;IACnC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,oBAAoB,EAAE,CAAC;QACtC,eAAe,GAAG,MAAM,CAAC,oBAAoB,IAAI,EAAE,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,eAAe,GAAG,EAAE,CAAC;IACvB,CAAC;IACD,MAAM,MAAM,GACV,eAAe,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,C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E,CAAC,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC;QAChD,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,CAAC;QAClD,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,YAAY,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAC;KAC9E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Template Manager Module (v2.0.0)
3
+ *
4
+ * Email template management with Handlebars rendering and database storage.
5
+ * Uses scope_id for hierarchical template resolution (org hierarchy, tenant hierarchy, etc.).
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import {
10
+ * send_template_email,
11
+ * register_template_type,
12
+ * set_scope_resolver,
13
+ * } from 'hazo_notify/template_manager';
14
+ * import { createHazoConnect } from 'hazo_connect/server';
15
+ *
16
+ * const hazo = createHazoConnect({ type: 'sqlite', sqlite: { database_path: './db.sqlite' } });
17
+ *
18
+ * // Register template types at boot (replaces seed_default_templates)
19
+ * register_template_type({
20
+ * template_name: 'welcome_email',
21
+ * template_label: 'Welcome Email',
22
+ * variables: [
23
+ * { variable_name: 'user_name', variable_description: "Recipient's full name" },
24
+ * { variable_name: 'login_url', variable_description: 'URL to login page' },
25
+ * ],
26
+ * });
27
+ *
28
+ * // Wire a scope resolver (optional — flat lookup if omitted)
29
+ * set_scope_resolver(async (scope_id) => {
30
+ * // Return ancestor scope IDs, nearest-to-root order
31
+ * return db.getAncestors(scope_id);
32
+ * });
33
+ *
34
+ * // Send a templated email
35
+ * const result = await send_template_email({
36
+ * template_name: 'welcome_email',
37
+ * variables: { user_name: 'John', login_url: 'https://example.com/login' },
38
+ * to: 'john@example.com',
39
+ * scope_id: 'tenant-uuid-here',
40
+ * subject: 'Welcome!',
41
+ * }, hazo);
42
+ * ```
43
+ */
44
+ export { send_template_email, render_template, preview_template, validate_template_variables, } from './template_manager.js';
45
+ export { load_template_config, get_template_variables, get_all_variable_names, clear_config_cache, } from './config/config_loader.js';
46
+ export { register_template_type, get_registered_template_types, get_registered_template_type, } from './registry.js';
47
+ export { get_scope_chain, invalidate_scope_chain, set_scope_resolver, } from './cache/scope_chain_cache.js';
48
+ export { list_categories, get_category, create_category, update_category, delete_category, find_category_by_name_in_chain, list_templates, list_templates_by_category, get_template, get_template_by_name, create_template, update_template, delete_template, } from './db/index.js';
49
+ export { render_handlebars, render_handlebars_string, clear_template_cache, invalidate_template_cache, resolve_variables, extract_template_references, resolve_template_references, resolve_all_template_references, } from './engine/index.js';
50
+ export { get_system_variables, resolve_system_variables, get_system_variable_definitions, validate_template_name, validate_category_name, validate_variable_name, extract_variables_from_content, validate_provided_variables, } from './utils/index.js';
51
+ export { TABLE_TEMPLATE_CATEGORY, TABLE_TEMPLATES, DEFAULT_CATEGORY_NAMES, MAX_TEMPLATE_NAME_LENGTH, MAX_CATEGORY_NAME_LENGTH, VARIABLE_PATTERN, TEMPLATE_REFERENCE_PATTERN, ERROR_MESSAGES, } from './config/constants.js';
52
+ export { sync_system_templates } from './seed/sync.js';
53
+ export { init_template_manager, verify_notify_setup, } from './init.js';
54
+ export type { InitTemplateManagerOptions } from './init.js';
55
+ export type { TemplateVariableDefinition, TemplateTypeDefinition, SystemVariable, TemplateManagerConfig, SystemTemplateManifest, TemplateCategory, TemplateCategoryInput, TemplateCategoryUpdate, EmailTemplate, EmailTemplateInput, EmailTemplateUpdate, HazoConnectInstance, HazoConnectQueryBuilder, TemplateRenderResult, TemplateOperationResponse, TemplateEmailAttachment, SendTemplateEmailOptions, SendTemplateEmailResponse, CategoryTreeItem, VariableItem, TemplateReferenceItem, Logger, } from './types.js';
56
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/template_manager/index.ts"],"names":[],"m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AAW,CAAC;AAG5D,YAAY,EAEV,0BAA0B,EAC1B,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EAErB,sBAAsB,EAEtB,gBAAgB,EAChB,qBAAqB,EACrB,sBAAsB,EACtB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EAEnB,mBAAmB,EACnB,uBAAuB,EAEvB,oBAAoB,EACpB,yBAAyB,EAEzB,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EAEzB,gBAAgB,EAChB,YAAY,EACZ,qBAAqB,EAErB,MAAM,GACP,MAAM,YAAY,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Template Manager Module (v2.0.0)
3
+ *
4
+ * Email template management with Handlebars rendering and database storage.
5
+ * Uses scope_id for hierarchical template resolution (org hierarchy, tenant hierarchy, etc.).
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import {
10
+ * send_template_email,
11
+ * register_template_type,
12
+ * set_scope_resolver,
13
+ * } from 'hazo_notify/template_manager';
14
+ * import { createHazoConnect } from 'hazo_connect/server';
15
+ *
16
+ * const hazo = createHazoConnect({ type: 'sqlite', sqlite: { database_path: './db.sqlite' } });
17
+ *
18
+ * // Register template types at boot (replaces seed_default_templates)
19
+ * register_template_type({
20
+ * template_name: 'welcome_email',
21
+ * template_label: 'Welcome Email',
22
+ * variables: [
23
+ * { variable_name: 'user_name', variable_description: "Recipient's full name" },
24
+ * { variable_name: 'login_url', variable_description: 'URL to login page' },
25
+ * ],
26
+ * });
27
+ *
28
+ * // Wire a scope resolver (optional — flat lookup if omitted)
29
+ * set_scope_resolver(async (scope_id) => {
30
+ * // Return ancestor scope IDs, nearest-to-root order
31
+ * return db.getAncestors(scope_id);
32
+ * });
33
+ *
34
+ * // Send a templated email
35
+ * const result = await send_template_email({
36
+ * template_name: 'welcome_email',
37
+ * variables: { user_name: 'John', login_url: 'https://example.com/login' },
38
+ * to: 'john@example.com',
39
+ * scope_id: 'tenant-uuid-here',
40
+ * subject: 'Welcome!',
41
+ * }, hazo);
42
+ * ```
43
+ */
44
+ // Core functions
45
+ export { send_template_email, render_template, preview_template, validate_template_variables, } from './template_manager.js';
46
+ // Config
47
+ export { load_template_config, get_template_variables, get_all_variable_names, clear_config_cache, } from './config/config_loader.js';
48
+ // Registry
49
+ export { register_template_type, get_registered_template_types, get_registered_template_type, } from './registry.js';
50
+ // Scope chain cache
51
+ export { get_scope_chain, invalidate_scope_chain, set_scope_resolver, } from './cache/scope_chain_cache.js';
52
+ // Database operations
53
+ export {
54
+ // Categories
55
+ list_categories, get_category, create_category, update_category, delete_category, find_category_by_name_in_chain,
56
+ // Templates
57
+ list_templates, list_templates_by_category, get_template, get_template_by_name, create_template, update_template, delete_template, } from './db/index.js';
58
+ // Engine
59
+ export { render_handlebars, render_handlebars_string, clear_template_cache, invalidate_template_cache, resolve_variables, extract_template_references, resolve_template_references, resolve_all_template_references, } from './engine/index.js';
60
+ // Utils
61
+ export { get_system_variables, resolve_system_variables, get_system_variable_definitions, validate_template_name, validate_category_name, validate_variable_name, extract_variables_from_content, validate_provided_variables, } from './utils/index.js';
62
+ // Constants
63
+ export { TABLE_TEMPLATE_CATEGORY, TABLE_TEMPLATES, DEFAULT_CATEGORY_NAMES, MAX_TEMPLATE_NAME_LENGTH, MAX_CATEGORY_NAME_LENGTH, VARIABLE_PATTERN, TEMPLATE_REFERENCE_PATTERN, ERROR_MESSAGES, } from './config/constants.js';
64
+ // Seed
65
+ export { sync_system_templates } from './seed/sync.js';
66
+ // Init
67
+ export { init_template_manager, verify_notify_setup, } from './init.js';
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/template_manager/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,iBAAiB;AACjB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,2BAA2B,GAC5B,MAAM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0)
3
+ *
4
+ * Consumers call init_template_manager() once at application startup to:
5
+ * - Obtain a hazo_connect instance via the provided factory
6
+ * - Wire an optional scope resolver into the scope chain cache
7
+ * - Seed/sync system templates from provided manifests
8
+ *
9
+ * verify_notify_setup() can be called after init to confirm the required
10
+ * database tables are present and queryable.
11
+ */
12
+ import type { HazoConnectInstance, SystemTemplateManifest } from './types.js';
13
+ export interface InitTemplateManagerOptions {
14
+ /** Factory that returns (or resolves to) a hazo_connect instance. */
15
+ hazo_connect_factory: () => Promise<HazoConnectInstance> | HazoConnectInstance;
16
+ /**
17
+ * Optional scope resolver. Receives a scope_id and must return the ancestor
18
+ * chain (nearest-to-root order), NOT including scope_id itself.
19
+ * Omit for flat (single-scope) lookup mode.
20
+ */
21
+ scope_resolver?: (scope_id: string) => Promise<string[]>;
22
+ /** System template manifests to seed/sync on startup. */
23
+ manifests?: SystemTemplateManifest[];
24
+ }
25
+ /**
26
+ * Wire up the template manager at application startup.
27
+ *
28
+ * @param options - Factory, optional scope resolver, and optional manifests.
29
+ * @returns The resolved hazo_connect instance plus sync result counts.
30
+ */
31
+ export declare function init_template_manager(options: InitTemplateManagerOptions): Promise<{
32
+ hazo_connect: HazoConnectInstance;
33
+ synced: number;
34
+ updated: number;
35
+ skipped: number;
36
+ errors: string[];
37
+ }>;
38
+ /**
39
+ * Verify that the required hazo_notify tables exist and are queryable.
40
+ *
41
+ * Performs a lightweight list (limit 1) against both tables. Returns
42
+ * ok:true only when both succeed.
43
+ *
44
+ * @param hazo_connect - An already-initialised hazo_connect instance.
45
+ */
46
+ export declare function verify_notify_setup(hazo_connect: HazoConnectInstance): Promise<{
47
+ ok: boolean;
48
+ tables: {
49
+ categories: boolean;
50
+ templates: boolean;
51
+ };
52
+ error?: string;
53
+ }>;
54
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/lib/template_manager/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAS9E,MAAM,WAAW,0BAA0B;IACzC,qEAAqE;IACrE,oBAAoB,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC;IAC/E;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACzD,yDAAyD;IACzD,SAAS,CAAC,EAAE,sBAAsB,EAAE,CAAC;CACtC;AAMD;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC;IACT,YAAY,EAAE,mBAAmB,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC,CAuBD;AAMD;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,YAAY,EAAE,mBAAmB,GAChC,OAAO,CAAC;IACT,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE;QAAE,UAAU,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAkCD"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Boot helper for the template manager (v2.0.0)
3
+ *
4
+ * Consumers call init_template_manager() once at application startup to:
5
+ * - Obtain a hazo_connect instance via the provided factory
6
+ * - Wire an optional scope resolver into the scope chain cache
7
+ * - Seed/sync system templates from provided manifests
8
+ *
9
+ * verify_notify_setup() can be called after init to confirm the required
10
+ * database tables are present and queryable.
11
+ */
12
+ import { set_scope_resolver } from './cache/scope_chain_cache.js';
13
+ import { sync_system_templates } from './seed/sync.js';
14
+ import { TABLE_TEMPLATE_CATEGORY, TABLE_TEMPLATES } from './config/constants.js';
15
+ // ============================================================
16
+ // init_template_manager
17
+ // ============================================================
18
+ /**
19
+ * Wire up the template manager at application startup.
20
+ *
21
+ * @param options - Factory, optional scope resolver, and optional manifests.
22
+ * @returns The resolved hazo_connect instance plus sync result counts.
23
+ */
24
+ export async function init_template_manager(options) {
25
+ // 1. Resolve hazo_connect (factory may be sync or async)
26
+ const hazo_connect = await options.hazo_connect_factory();
27
+ // 2. Wire scope resolver if provided
28
+ if (options.scope_resolver) {
29
+ set_scope_resolver(options.scope_resolver);
30
+ }
31
+ // 3. Sync manifests if provided and non-empty
32
+ if (options.manifests && options.manifests.length > 0) {
33
+ const result = await sync_system_templates(hazo_connect, options.manifests);
34
+ return {
35
+ hazo_connect,
36
+ synced: result.synced,
37
+ updated: result.updated,
38
+ skipped: result.skipped,
39
+ errors: result.errors,
40
+ };
41
+ }
42
+ // No manifests — return zero counts
43
+ return { hazo_connect, synced: 0, updated: 0, skipped: 0, errors: [] };
44
+ }
45
+ // ============================================================
46
+ // verify_notify_setup
47
+ // ============================================================
48
+ /**
49
+ * Verify that the required hazo_notify tables exist and are queryable.
50
+ *
51
+ * Performs a lightweight list (limit 1) against both tables. Returns
52
+ * ok:true only when both succeed.
53
+ *
54
+ * @param hazo_connect - An already-initialised hazo_connect instance.
55
+ */
56
+ export async function verify_notify_setup(hazo_connect) {
57
+ let categories = false;
58
+ let templates = false;
59
+ const error_messages = [];
60
+ // Check categories table
61
+ try {
62
+ await hazo_connect.list(hazo_connect.query().from(TABLE_TEMPLATE_CATEGORY).select('*').limit(1));
63
+ categories = true;
64
+ }
65
+ catch (err) {
66
+ const msg = err instanceof Error ? err.message : String(err);
67
+ error_messages.push(`categories: ${msg}`);
68
+ }
69
+ // Check templates table
70
+ try {
71
+ await hazo_connect.list(hazo_connect.query().from(TABLE_TEMPLATES).select('*').limit(1));
72
+ templates = true;
73
+ }
74
+ catch (err) {
75
+ const msg = err instanceof Error ? err.message : String(err);
76
+ error_messages.push(`templates: ${msg}`);
77
+ }
78
+ const ok = categories && templates;
79
+ return {
80
+ ok,
81
+ tables: { categories, templates },
82
+ ...(error_messages.length > 0 ? { error: error_messages.join('; ') } : {}),
83
+ };
84
+ }
85
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/lib/template_manager/init.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAmBjF,+DAA+D;AAC/D,wBAAwB;AACxB,+DAA+D;AAE/D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAmC;IAQnC,yDAAyD;IACzD,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAE1D,qCAAqC;IACrC,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC3B,kBAAkB,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC;IAED,8CAA8C;IAC9C,IAAI,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,YAAY,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5E,OAAO;YACL,YAAY;YACZ,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,MAAM,CAAC,MAAM;SACtB,CAAC;IACJ,CAAC;IAED,oCAAoC;IACpC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE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C;IAED,MAAM,EAAE,GAAG,UAAU,IAAI,SAAS,CAAC;IAEnC,OAAO;QACL,EAAE;QACF,MAAM,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE;QACjC,GAAG,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Template type registry for template manager (v2.0.0)
3
+ *
4
+ * server-only: do not import in client bundles.
5
+ *
6
+ * Consuming packages register their TemplateTypeDefinition entries here at
7
+ * boot time. First-wins semantics prevent accidental double-registration.
8
+ */
9
+ import type { TemplateTypeDefinition } from './types.js';
10
+ /**
11
+ * Register a template type. First-wins: if already registered, logs a warning
12
+ * and skips. Call this once per template type at application boot time.
13
+ */
14
+ export declare function register_template_type(def: TemplateTypeDefinition): void;
15
+ /**
16
+ * Returns all registered template type definitions.
17
+ */
18
+ export declare function get_registered_template_types(): TemplateTypeDefinition[];
19
+ /**
20
+ * Get a single registered type by template_name, or undefined if not found.
21
+ */
22
+ export declare function get_registered_template_type(template_name: string): TemplateTypeDefinition | undefined;
23
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/lib/template_manager/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAIzD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,sBAAsB,GAAG,IAAI,CAQxE;AAED;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,sBAAsB,EAAE,CAExE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,aAAa,EAAE,MAAM,GACpB,sBAAsB,GAAG,SAAS,CAEpC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Template type registry for template manager (v2.0.0)
3
+ *
4
+ * server-only: do not import in client bundles.
5
+ *
6
+ * Consuming packages register their TemplateTypeDefinition entries here at
7
+ * boot time. First-wins semantics prevent accidental double-registration.
8
+ */
9
+ const registry = new Map();
10
+ /**
11
+ * Register a template type. First-wins: if already registered, logs a warning
12
+ * and skips. Call this once per template type at application boot time.
13
+ */
14
+ export function register_template_type(def) {
15
+ if (registry.has(def.template_name)) {
16
+ console.warn(`[hazo_notify] template type '${def.template_name}' already registered; first registration wins`);
17
+ return;
18
+ }
19
+ registry.set(def.template_name, def);
20
+ }
21
+ /**
22
+ * Returns all registered template type definitions.
23
+ */
24
+ export function get_registered_template_types() {
25
+ return Array.from(registry.values());
26
+ }
27
+ /**
28
+ * Get a single registered type by template_name, or undefined if not found.
29
+ */
30
+ export function get_registered_template_type(template_name) {
31
+ return registry.get(template_name);
32
+ }
33
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/lib/template_manager/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkC,CAAC;AAE3D;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,GAA2B;IAChE,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;QACpC,OAAO,CAAC,IAAI,CACV,gCAAgC,GAAG,CAAC,aAAa,+CAA+C,CACjG,CAAC;QACF,OAAO;IACT,CAAC;IACD,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B;IAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;AACvC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,4BAA4B,CAC1C,aAAqB;IAErB,OAAO,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AACrC,CAAC"}