create-windy 0.2.34 → 0.3.1

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 (261) hide show
  1. package/README.md +26 -3
  2. package/dist/cli.js +8121 -3746
  3. package/package.json +3 -3
  4. package/template/.windy-template.json +2 -2
  5. package/template/AGENTS.md +5 -0
  6. package/template/README.md +28 -4
  7. package/template/_gitignore +4 -0
  8. package/template/apps/agent-server/Dockerfile +1 -0
  9. package/template/apps/agent-server/README.md +18 -5
  10. package/template/apps/agent-server/adk_web_agents/__init__.py +1 -0
  11. package/template/apps/agent-server/adk_web_agents/safe_debug/__init__.py +3 -0
  12. package/template/apps/agent-server/adk_web_agents/safe_debug/agent.py +40 -0
  13. package/template/apps/agent-server/pyproject.toml +1 -1
  14. package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +191 -16
  15. package/template/apps/agent-server/src/southwind_agent_server/adk_failure.py +13 -0
  16. package/template/apps/agent-server/src/southwind_agent_server/adk_model.py +225 -0
  17. package/template/apps/agent-server/src/southwind_agent_server/adk_tools.py +76 -0
  18. package/template/apps/agent-server/src/southwind_agent_server/app.py +1 -2
  19. package/template/apps/agent-server/tests/__init__.py +1 -0
  20. package/template/apps/agent-server/tests/openai_provider_test_support.py +131 -0
  21. package/template/apps/agent-server/tests/test_adk_adapter.py +305 -0
  22. package/template/apps/agent-server/tests/test_adk_web_agent.py +12 -0
  23. package/template/apps/agent-server/tests/test_openai_provider.py +7 -123
  24. package/template/apps/server/package.json +4 -1
  25. package/template/apps/server/src/agent/run-facade.ts +2 -7
  26. package/template/apps/server/src/agent/tool-registry.ts +2 -6
  27. package/template/apps/server/src/application-services.ts +50 -0
  28. package/template/apps/server/src/audit/drizzle-log-store.ts +25 -0
  29. package/template/apps/server/src/audit/search-summary.ts +2 -6
  30. package/template/apps/server/src/auth/credential-restriction.ts +1 -0
  31. package/template/apps/server/src/auth/password.ts +30 -21
  32. package/template/apps/server/src/auth/routes.test-support.ts +94 -0
  33. package/template/apps/server/src/auth/routes.test.ts +51 -78
  34. package/template/apps/server/src/auth/routes.ts +6 -1
  35. package/template/apps/server/src/auth/runtime.ts +4 -1
  36. package/template/apps/server/src/auth/service.ts +25 -7
  37. package/template/apps/server/src/configuration/bootstrap.ts +20 -1
  38. package/template/apps/server/src/configuration/definition.test.ts +71 -0
  39. package/template/apps/server/src/configuration/definition.ts +242 -12
  40. package/template/apps/server/src/configuration/drizzle-repository.ts +36 -2
  41. package/template/apps/server/src/configuration/repository.ts +27 -2
  42. package/template/apps/server/src/configuration/routes.ts +4 -1
  43. package/template/apps/server/src/configuration/service.test.ts +100 -0
  44. package/template/apps/server/src/configuration/service.ts +50 -10
  45. package/template/apps/server/src/data-access/scoped-repository.integration.test.ts +3 -2
  46. package/template/apps/server/src/data-governance/export/service.ts +2 -6
  47. package/template/apps/server/src/example-modules.ts +4 -1
  48. package/template/apps/server/src/guards.ts +18 -5
  49. package/template/apps/server/src/http/request-source.test.ts +85 -0
  50. package/template/apps/server/src/http/request-source.ts +90 -0
  51. package/template/apps/server/src/index.ts +40 -40
  52. package/template/apps/server/src/license/routes.ts +2 -0
  53. package/template/apps/server/src/license/runtime-service.ts +10 -11
  54. package/template/apps/server/src/mcp/adapter.test.ts +3 -2
  55. package/template/apps/server/src/mcp/adapter.ts +9 -9
  56. package/template/apps/server/src/mcp/routes.ts +4 -3
  57. package/template/apps/server/src/module-bootstrap.ts +2 -2
  58. package/template/apps/server/src/module-host/request-context.ts +6 -6
  59. package/template/apps/server/src/module-host/storage-scope.ts +2 -9
  60. package/template/apps/server/src/module-host/user-directory-port.ts +2 -6
  61. package/template/apps/server/src/notification/channel-adapter.ts +46 -0
  62. package/template/apps/server/src/notification/delivery-policy.test.ts +59 -0
  63. package/template/apps/server/src/notification/delivery-policy.ts +37 -0
  64. package/template/apps/server/src/notification/delivery-repository.ts +198 -0
  65. package/template/apps/server/src/notification/delivery-worker.test.ts +87 -0
  66. package/template/apps/server/src/notification/delivery-worker.ts +88 -0
  67. package/template/apps/server/src/notification/drizzle-management.ts +180 -0
  68. package/template/apps/server/src/notification/drizzle-query.ts +160 -0
  69. package/template/apps/server/src/notification/drizzle-repository.integration.test.ts +301 -0
  70. package/template/apps/server/src/notification/drizzle-repository.ts +156 -90
  71. package/template/apps/server/src/notification/extension-routes.test.ts +119 -0
  72. package/template/apps/server/src/notification/extension-routes.ts +111 -0
  73. package/template/apps/server/src/notification/memory-delivery-repository.ts +137 -0
  74. package/template/apps/server/src/notification/memory-support.ts +72 -0
  75. package/template/apps/server/src/notification/preference-repository.ts +95 -0
  76. package/template/apps/server/src/notification/recipient-directory.ts +104 -0
  77. package/template/apps/server/src/notification/repository.test.ts +171 -0
  78. package/template/apps/server/src/notification/repository.ts +179 -32
  79. package/template/apps/server/src/notification/revision-routes.test.ts +186 -0
  80. package/template/apps/server/src/notification/route-support.ts +225 -0
  81. package/template/apps/server/src/notification/routes.test.ts +182 -0
  82. package/template/apps/server/src/notification/routes.ts +225 -132
  83. package/template/apps/server/src/notification/service.test.ts +104 -0
  84. package/template/apps/server/src/notification/service.ts +140 -0
  85. package/template/apps/server/src/notification/smtp-adapter.test.ts +65 -0
  86. package/template/apps/server/src/notification/smtp-adapter.ts +68 -0
  87. package/template/apps/server/src/persistence.integration.test.ts +41 -2
  88. package/template/apps/server/src/platform-http-runtime.ts +87 -0
  89. package/template/apps/server/src/route-guards.ts +1 -0
  90. package/template/apps/server/src/runtime-audit-list.test.ts +39 -0
  91. package/template/apps/server/src/runtime-development.ts +1 -0
  92. package/template/apps/server/src/runtime.test.ts +23 -9
  93. package/template/apps/server/src/runtime.ts +39 -2
  94. package/template/apps/server/src/scheduler/audit.ts +2 -11
  95. package/template/apps/server/src/scheduler/definitions.test.ts +6 -0
  96. package/template/apps/server/src/scheduler/definitions.ts +7 -0
  97. package/template/apps/server/src/scheduler/recovery-service.ts +2 -11
  98. package/template/apps/server/src/scheduler/routes.ts +2 -7
  99. package/template/apps/server/src/search/opensearch-client.test.ts +45 -0
  100. package/template/apps/server/src/search/opensearch-client.ts +145 -0
  101. package/template/apps/server/src/search/service.ts +2 -6
  102. package/template/apps/server/src/settings/routes.ts +15 -3
  103. package/template/apps/server/src/settings/runtime.ts +10 -1
  104. package/template/apps/server/src/storage/runtime.ts +13 -0
  105. package/template/apps/server/src/system/audit-query.ts +33 -4
  106. package/template/apps/server/src/system/audit-routes.test.ts +58 -4
  107. package/template/apps/server/src/system/audit-routes.ts +6 -5
  108. package/template/apps/server/src/system/department-organization.ts +320 -0
  109. package/template/apps/server/src/system/department-routes.test.ts +207 -48
  110. package/template/apps/server/src/system/department-routes.ts +114 -33
  111. package/template/apps/server/src/system/drizzle-repository.ts +15 -7
  112. package/template/apps/server/src/system/drizzle-scoped-repository.ts +5 -3
  113. package/template/apps/server/src/system/drizzle-system-configs.ts +319 -0
  114. package/template/apps/server/src/system/drizzle-system.ts +59 -311
  115. package/template/apps/server/src/system/drizzle-transaction-context.ts +14 -0
  116. package/template/apps/server/src/system/identity-route-config.ts +7 -2
  117. package/template/apps/server/src/system/mutation-runner.ts +23 -0
  118. package/template/apps/server/src/system/organization-postgres.integration.test.ts +176 -0
  119. package/template/apps/server/src/system/resource-access-response.ts +12 -6
  120. package/template/apps/server/src/system/resource-routes.ts +270 -0
  121. package/template/apps/server/src/system/role-department-scope-policy.ts +55 -0
  122. package/template/apps/server/src/system/route-helpers.ts +2 -5
  123. package/template/apps/server/src/system/route-types.ts +12 -3
  124. package/template/apps/server/src/system/routes-validation.test.ts +26 -0
  125. package/template/apps/server/src/system/routes.test.ts +10 -2
  126. package/template/apps/server/src/system/routes.ts +35 -267
  127. package/template/apps/server/src/system/seed.ts +7 -0
  128. package/template/apps/server/src/work-order/data-scope.integration.test.ts +9 -2
  129. package/template/apps/server/src/work-order/opensearch-index.test.ts +97 -0
  130. package/template/apps/server/src/work-order/opensearch-index.ts +313 -0
  131. package/template/apps/server/src/work-order/search-provider.ts +60 -1
  132. package/template/apps/server/src/work-order/service.ts +42 -10
  133. package/template/apps/web/src/app/error-pages.ts +9 -0
  134. package/template/apps/web/src/components/auth/PasswordChangeForm.vue +16 -11
  135. package/template/apps/web/src/components/auth/PasswordChangeForm.webtest.ts +14 -0
  136. package/template/apps/web/src/components/common/FormDialog.vue +16 -2
  137. package/template/apps/web/src/components/common/ModalLayout.webtest.ts +20 -1
  138. package/template/apps/web/src/composables/useGlobalSearch.ts +68 -0
  139. package/template/apps/web/src/composables/usePlatformSettings.ts +8 -7
  140. package/template/apps/web/src/layout/GlobalSearchResults.vue +58 -0
  141. package/template/apps/web/src/layout/NavigationSearchDialog.vue +42 -6
  142. package/template/apps/web/src/layout/NavigationSearchDialog.webtest.ts +71 -0
  143. package/template/apps/web/src/layout/NotificationMenu.vue +73 -31
  144. package/template/apps/web/src/layout/NotificationMenu.webtest.ts +44 -1
  145. package/template/apps/web/src/layout/NotificationMenuItem.vue +61 -0
  146. package/template/apps/web/src/layout/NotificationPreferencesDialog.vue +181 -0
  147. package/template/apps/web/src/layout/NotificationPreferencesDialog.webtest.ts +80 -0
  148. package/template/apps/web/src/lib/date-time.ts +22 -10
  149. package/template/apps/web/src/lib/date-time.webtest.ts +9 -1
  150. package/template/apps/web/src/main.ts +14 -1
  151. package/template/apps/web/src/pages/auth/ChangePasswordPage.vue +16 -1
  152. package/template/apps/web/src/pages/configuration/components/ModuleConfigVersionList.vue +1 -0
  153. package/template/apps/web/src/pages/configuration/components/ModuleConfigurationEditor.vue +10 -0
  154. package/template/apps/web/src/pages/configuration/components/ModuleConfigurationWorkbench.vue +37 -6
  155. package/template/apps/web/src/pages/errors/PlatformErrorPage.vue +115 -0
  156. package/template/apps/web/src/pages/errors/PlatformErrorPage.webtest.ts +44 -0
  157. package/template/apps/web/src/pages/errors/error-page-extension.ts +26 -0
  158. package/template/apps/web/src/pages/system/SystemNotificationsPage.vue +136 -68
  159. package/template/apps/web/src/pages/system/SystemNotificationsPage.webtest.ts +224 -12
  160. package/template/apps/web/src/pages/system/audit-log-presenter.ts +86 -0
  161. package/template/apps/web/src/pages/system/audit-time-range.ts +28 -0
  162. package/template/apps/web/src/pages/system/components/AuditActionCell.vue +10 -69
  163. package/template/apps/web/src/pages/system/components/AuditActionCell.webtest.ts +20 -27
  164. package/template/apps/web/src/pages/system/components/AuditLogDetailDialog.vue +134 -0
  165. package/template/apps/web/src/pages/system/components/AuditLogDetailDialog.webtest.ts +76 -0
  166. package/template/apps/web/src/pages/system/components/AuditLogFilters.vue +116 -52
  167. package/template/apps/web/src/pages/system/components/AuditLogFilters.webtest.ts +52 -15
  168. package/template/apps/web/src/pages/system/components/NotificationHistoryDialog.vue +129 -0
  169. package/template/apps/web/src/pages/system/components/NotificationManagementCard.vue +91 -0
  170. package/template/apps/web/src/pages/system/components/NotificationPublishDialog.vue +121 -0
  171. package/template/apps/web/src/pages/system/components/NotificationPublishForm.vue +162 -1
  172. package/template/apps/web/src/pages/system/components/SystemResourceActions.vue +68 -0
  173. package/template/apps/web/src/pages/system/components/SystemResourceEditor.vue +74 -0
  174. package/template/apps/web/src/pages/system/components/SystemResourceFilters.vue +3 -4
  175. package/template/apps/web/src/pages/system/components/SystemResourceLoadError.vue +21 -0
  176. package/template/apps/web/src/pages/system/components/SystemResourceLoadError.webtest.ts +17 -0
  177. package/template/apps/web/src/pages/system/components/SystemResourcePage.vue +96 -108
  178. package/template/apps/web/src/pages/system/components/SystemResourcePage.webtest.ts +68 -0
  179. package/template/apps/web/src/pages/system/components/SystemResourceTable.vue +20 -1
  180. package/template/apps/web/src/pages/system/components/SystemResourceTable.webtest.ts +28 -7
  181. package/template/apps/web/src/pages/system/components/department/DepartmentOrganizationForm.vue +210 -0
  182. package/template/apps/web/src/pages/system/components/department/DepartmentTransitionDialog.vue +112 -0
  183. package/template/apps/web/src/pages/system/components/user-account/UserAccountForm.vue +17 -4
  184. package/template/apps/web/src/pages/system/composables/useDepartmentTransitions.ts +79 -0
  185. package/template/apps/web/src/pages/system/composables/useNotificationPermissions.ts +14 -0
  186. package/template/apps/web/src/pages/system/composables/useSystemResource.ts +2 -0
  187. package/template/apps/web/src/pages/system/composables/useSystemResource.webtest.ts +15 -2
  188. package/template/apps/web/src/pages/system/resource-config.ts +12 -4
  189. package/template/apps/web/src/router/error-navigation.ts +50 -0
  190. package/template/apps/web/src/router/error-navigation.webtest.ts +106 -0
  191. package/template/apps/web/src/router/index.ts +71 -0
  192. package/template/apps/web/src/router/index.webtest.ts +29 -0
  193. package/template/apps/web/src/router/manifest-routes.webtest.ts +4 -0
  194. package/template/apps/web/src/router/shared-scaffold-neutrality.webtest.ts +12 -0
  195. package/template/apps/web/src/services/auth-api.ts +5 -0
  196. package/template/apps/web/src/services/http.ts +43 -6
  197. package/template/apps/web/src/services/http.webtest.ts +70 -0
  198. package/template/apps/web/src/services/notification-api.ts +85 -2
  199. package/template/apps/web/src/services/notification-api.webtest.ts +110 -0
  200. package/template/apps/web/src/services/search-api.ts +39 -0
  201. package/template/apps/web/src/services/system-api.ts +18 -0
  202. package/template/apps/web/vitest.config.ts +1 -0
  203. package/template/docker-compose.yml +66 -0
  204. package/template/docs/architecture/ai-runtime.md +14 -5
  205. package/template/docs/architecture/mcp-business-capabilities.md +107 -0
  206. package/template/docs/architecture/search-provider-protocol.md +38 -2
  207. package/template/docs/development/custom-error-pages.md +78 -0
  208. package/template/docs/development/custom-login-page.md +3 -3
  209. package/template/docs/platform/agent-runtime.md +32 -6
  210. package/template/docs/platform/agent-tools.md +4 -0
  211. package/template/docs/platform/audit-reliability.md +46 -2
  212. package/template/docs/platform/module-configuration.md +13 -4
  213. package/template/docs/platform/notifications.md +67 -11
  214. package/template/docs/platform/organization-membership.md +17 -3
  215. package/template/docs/platform/system-crud-api.md +16 -0
  216. package/template/docs/platform/web-system-crud.md +6 -2
  217. package/template/package.json +4 -0
  218. package/template/packages/config/index.test.ts +45 -0
  219. package/template/packages/config/package.json +1 -1
  220. package/template/packages/config/src/platform.ts +169 -48
  221. package/template/packages/database/drizzle/0035_material_nightshade.sql +10 -0
  222. package/template/packages/database/drizzle/0036_hesitant_speed.sql +35 -0
  223. package/template/packages/database/drizzle/0037_absent_nick_fury.sql +2 -0
  224. package/template/packages/database/drizzle/0038_uneven_wasp.sql +38 -0
  225. package/template/packages/database/drizzle/meta/0035_snapshot.json +7331 -0
  226. package/template/packages/database/drizzle/meta/0036_snapshot.json +7436 -0
  227. package/template/packages/database/drizzle/meta/0037_snapshot.json +7457 -0
  228. package/template/packages/database/drizzle/meta/0038_snapshot.json +7749 -0
  229. package/template/packages/database/drizzle/meta/_journal.json +28 -0
  230. package/template/packages/database/package.json +1 -1
  231. package/template/packages/database/src/schema/identity.ts +7 -0
  232. package/template/packages/database/src/schema/notifications.ts +135 -0
  233. package/template/packages/database/src/schema-notification-delivery.test.ts +54 -0
  234. package/template/packages/database/src/schema-workflow-notification.test.ts +40 -1
  235. package/template/packages/modules/package.json +1 -1
  236. package/template/packages/modules/src/composition-fixtures.test-support.ts +164 -0
  237. package/template/packages/modules/src/composition.test.ts +5 -158
  238. package/template/packages/modules/src/system-api-operational.ts +234 -0
  239. package/template/packages/modules/src/system-api-permissions.ts +14 -181
  240. package/template/packages/modules/src/system-audit-actions.ts +10 -0
  241. package/template/packages/modules/src/system-features.ts +1 -1
  242. package/template/packages/modules/src/system-module-catalog.ts +2 -1
  243. package/template/packages/modules/src/system-module-tasks.ts +86 -0
  244. package/template/packages/modules/src/system-modules-access.test.ts +60 -0
  245. package/template/packages/modules/src/system-modules.test.ts +13 -54
  246. package/template/packages/modules/src/system-modules.ts +2 -72
  247. package/template/packages/modules/src/system-permissions.ts +9 -5
  248. package/template/packages/server-sdk/package.json +1 -1
  249. package/template/packages/shared/index.ts +1 -0
  250. package/template/packages/shared/package.json +1 -1
  251. package/template/packages/shared/src/audit.ts +25 -0
  252. package/template/packages/shared/src/mcp.test.ts +12 -0
  253. package/template/packages/shared/src/mcp.ts +7 -0
  254. package/template/packages/shared/src/module-configuration.ts +5 -0
  255. package/template/packages/shared/src/notification.ts +92 -1
  256. package/template/packages/shared/src/password.ts +7 -2
  257. package/template/packages/shared/src/platform-settings.ts +2 -0
  258. package/template/packages/storage/package.json +1 -1
  259. package/template/packages/storage/src/upload-service.test.ts +16 -0
  260. package/template/packages/storage/src/upload-service.ts +5 -1
  261. package/template/scripts/notification-postgres-regression.ts +27 -0
@@ -246,6 +246,34 @@
246
246
  "when": 1784976420447,
247
247
  "tag": "0034_funny_mesmero",
248
248
  "breakpoints": true
249
+ },
250
+ {
251
+ "idx": 35,
252
+ "version": "7",
253
+ "when": 1785008351360,
254
+ "tag": "0035_material_nightshade",
255
+ "breakpoints": true
256
+ },
257
+ {
258
+ "idx": 36,
259
+ "version": "7",
260
+ "when": 1785009127636,
261
+ "tag": "0036_hesitant_speed",
262
+ "breakpoints": true
263
+ },
264
+ {
265
+ "idx": 37,
266
+ "version": "7",
267
+ "when": 1785012884328,
268
+ "tag": "0037_absent_nick_fury",
269
+ "breakpoints": true
270
+ },
271
+ {
272
+ "idx": 38,
273
+ "version": "7",
274
+ "when": 1785013875842,
275
+ "tag": "0038_uneven_wasp",
276
+ "breakpoints": true
249
277
  }
250
278
  ]
251
279
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@southwind-ai/database",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "engines": {
@@ -27,7 +27,14 @@ export const departments = pgTable(
27
27
  },
28
28
  (table) => [
29
29
  uniqueIndex("uk_departments_code").on(table.code),
30
+ uniqueIndex("uk_departments_single_root")
31
+ .on(sql`((1))`)
32
+ .where(sql`${table.parentId} is null and ${table.deletedAt} is null`),
30
33
  index("idx_departments_parent").on(table.parentId),
34
+ check(
35
+ "departments_parent_not_self",
36
+ sql`${table.parentId} is null or ${table.parentId} <> ${table.id}`,
37
+ ),
31
38
  ],
32
39
  );
33
40
 
@@ -1,5 +1,7 @@
1
1
  import {
2
+ boolean,
2
3
  index,
4
+ integer,
3
5
  pgTable,
4
6
  primaryKey,
5
7
  text,
@@ -9,6 +11,10 @@ import {
9
11
  varchar,
10
12
  } from "drizzle-orm/pg-core";
11
13
  import type { TargetRef } from "@southwind-ai/shared";
14
+ import type {
15
+ ExternalNotificationChannel,
16
+ NotificationDeliveryStatus,
17
+ } from "@southwind-ai/shared";
12
18
  import { auditColumns, idColumn, statusColumn } from "./common.js";
13
19
  import { users } from "./identity.js";
14
20
 
@@ -22,15 +28,32 @@ export const platformNotifications = pgTable(
22
28
  category: varchar("category", { length: 40 }).notNull(),
23
29
  status: statusColumn().notNull(),
24
30
  publishedAt: timestamp("published_at", { withTimezone: true }).notNull(),
31
+ scheduledFor: timestamp("scheduled_for", { withTimezone: true }),
25
32
  archivedAt: timestamp("archived_at", { withTimezone: true }),
26
33
  archivedBy: varchar("archived_by", { length: 64 }),
27
34
  target: jsonb("target").$type<TargetRef>(),
28
35
  recipientUserId: varchar("recipient_user_id", { length: 64 }),
36
+ recipientUserIds: jsonb("recipient_user_ids")
37
+ .$type<string[]>()
38
+ .notNull()
39
+ .default([]),
29
40
  recipientRoleCodes: jsonb("recipient_role_codes")
30
41
  .$type<string[]>()
31
42
  .notNull()
32
43
  .default([]),
44
+ recipientDepartmentIds: jsonb("recipient_department_ids")
45
+ .$type<string[]>()
46
+ .notNull()
47
+ .default([]),
48
+ includeChildDepartments: boolean("include_child_departments")
49
+ .notNull()
50
+ .default(false),
51
+ deliveryChannels: jsonb("delivery_channels")
52
+ .$type<ExternalNotificationChannel[]>()
53
+ .notNull()
54
+ .default([]),
33
55
  sourceKey: varchar("source_key", { length: 180 }),
56
+ revision: integer("revision").notNull().default(1),
34
57
  ...auditColumns,
35
58
  },
36
59
  (table) => [
@@ -42,6 +65,96 @@ export const platformNotifications = pgTable(
42
65
  ],
43
66
  );
44
67
 
68
+ export const notificationPreferences = pgTable("notification_preferences", {
69
+ userId: varchar("user_id", { length: 64 })
70
+ .primaryKey()
71
+ .references(() => users.id, { onDelete: "restrict" }),
72
+ enabledChannels: jsonb("enabled_channels")
73
+ .$type<ExternalNotificationChannel[]>()
74
+ .notNull()
75
+ .default([]),
76
+ disabledCategories: jsonb("disabled_categories")
77
+ .$type<string[]>()
78
+ .notNull()
79
+ .default([]),
80
+ updatedAt: timestamp("updated_at", { withTimezone: true })
81
+ .notNull()
82
+ .defaultNow(),
83
+ updatedBy: varchar("updated_by", { length: 64 }).notNull(),
84
+ });
85
+
86
+ export const notificationDeliveryOutbox = pgTable(
87
+ "notification_delivery_outbox",
88
+ {
89
+ id: idColumn().primaryKey(),
90
+ notificationId: varchar("notification_id", { length: 64 })
91
+ .notNull()
92
+ .references(() => platformNotifications.id, { onDelete: "restrict" }),
93
+ userId: varchar("user_id", { length: 64 })
94
+ .notNull()
95
+ .references(() => users.id, { onDelete: "restrict" }),
96
+ channel: varchar("channel", { length: 16 })
97
+ .$type<ExternalNotificationChannel>()
98
+ .notNull(),
99
+ status: varchar("status", { length: 16 })
100
+ .$type<NotificationDeliveryStatus>()
101
+ .notNull(),
102
+ subject: varchar("subject", { length: 120 }).notNull(),
103
+ content: text("content").notNull(),
104
+ attemptCount: integer("attempt_count").notNull().default(0),
105
+ nextAttemptAt: timestamp("next_attempt_at", { withTimezone: true })
106
+ .notNull()
107
+ .defaultNow(),
108
+ leaseToken: varchar("lease_token", { length: 64 }),
109
+ leaseExpiresAt: timestamp("lease_expires_at", { withTimezone: true }),
110
+ deliveredAt: timestamp("delivered_at", { withTimezone: true }),
111
+ providerMessageId: varchar("provider_message_id", { length: 180 }),
112
+ lastErrorCode: varchar("last_error_code", { length: 64 }),
113
+ createdAt: timestamp("created_at", { withTimezone: true })
114
+ .notNull()
115
+ .defaultNow(),
116
+ updatedAt: timestamp("updated_at", { withTimezone: true })
117
+ .notNull()
118
+ .defaultNow(),
119
+ },
120
+ (table) => [
121
+ uniqueIndex("uk_notification_delivery_target").on(
122
+ table.notificationId,
123
+ table.userId,
124
+ table.channel,
125
+ ),
126
+ index("idx_notification_delivery_claim").on(
127
+ table.status,
128
+ table.nextAttemptAt,
129
+ table.leaseExpiresAt,
130
+ ),
131
+ index("idx_notification_delivery_notification").on(table.notificationId),
132
+ ],
133
+ );
134
+
135
+ export const notificationRevisions = pgTable(
136
+ "notification_revisions",
137
+ {
138
+ notificationId: varchar("notification_id", { length: 64 })
139
+ .notNull()
140
+ .references(() => platformNotifications.id, { onDelete: "restrict" }),
141
+ revision: integer("revision").notNull(),
142
+ title: varchar("title", { length: 120 }).notNull(),
143
+ summary: varchar("summary", { length: 240 }).notNull(),
144
+ content: text("content").notNull(),
145
+ category: varchar("category", { length: 40 }).notNull(),
146
+ editedAt: timestamp("edited_at", { withTimezone: true }).notNull(),
147
+ editedBy: varchar("edited_by", { length: 64 }).notNull(),
148
+ },
149
+ (table) => [
150
+ primaryKey({ columns: [table.notificationId, table.revision] }),
151
+ index("idx_notification_revisions_time").on(
152
+ table.notificationId,
153
+ table.editedAt,
154
+ ),
155
+ ],
156
+ );
157
+
45
158
  export const notificationReads = pgTable(
46
159
  "notification_reads",
47
160
  {
@@ -58,3 +171,25 @@ export const notificationReads = pgTable(
58
171
  index("idx_notification_reads_user").on(table.userId, table.readAt),
59
172
  ],
60
173
  );
174
+
175
+ export const notificationFavorites = pgTable(
176
+ "notification_favorites",
177
+ {
178
+ notificationId: varchar("notification_id", { length: 64 })
179
+ .notNull()
180
+ .references(() => platformNotifications.id, { onDelete: "restrict" }),
181
+ userId: varchar("user_id", { length: 64 })
182
+ .notNull()
183
+ .references(() => users.id, { onDelete: "restrict" }),
184
+ favoritedAt: timestamp("favorited_at", { withTimezone: true })
185
+ .notNull()
186
+ .defaultNow(),
187
+ },
188
+ (table) => [
189
+ primaryKey({ columns: [table.notificationId, table.userId] }),
190
+ index("idx_notification_favorites_user").on(
191
+ table.userId,
192
+ table.favoritedAt,
193
+ ),
194
+ ],
195
+ );
@@ -0,0 +1,54 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { getTableConfig } from "drizzle-orm/pg-core";
3
+ import {
4
+ notificationDeliveryOutbox,
5
+ notificationPreferences,
6
+ platformNotifications,
7
+ } from "./schema/index.js";
8
+
9
+ describe("通知策略与投递 schema", () => {
10
+ test("定时、多受众、偏好与 outbox 使用可迁移的 PostgreSQL 结构", async () => {
11
+ expect(platformNotifications.scheduledFor).toBeDefined();
12
+ expect(platformNotifications.recipientUserIds.notNull).toBe(true);
13
+ expect(platformNotifications.recipientDepartmentIds.notNull).toBe(true);
14
+ expect(platformNotifications.includeChildDepartments.notNull).toBe(true);
15
+ expect(platformNotifications.deliveryChannels.notNull).toBe(true);
16
+
17
+ expect(getTableConfig(notificationPreferences).name).toBe(
18
+ "notification_preferences",
19
+ );
20
+ expect(notificationPreferences.userId.primary).toBe(true);
21
+ expect(notificationPreferences.enabledChannels.notNull).toBe(true);
22
+ expect(notificationPreferences.disabledCategories.notNull).toBe(true);
23
+
24
+ const outbox = getTableConfig(notificationDeliveryOutbox);
25
+ expect(outbox.name).toBe("notification_delivery_outbox");
26
+ expect(
27
+ outbox.indexes.some(
28
+ ({ config }) => config.name === "uk_notification_delivery_target",
29
+ ),
30
+ ).toBe(true);
31
+ expect(
32
+ outbox.indexes.some(
33
+ ({ config }) => config.name === "idx_notification_delivery_claim",
34
+ ),
35
+ ).toBe(true);
36
+ expect(
37
+ outbox.foreignKeys.every(
38
+ (foreignKey) => foreignKey.onDelete === "restrict",
39
+ ),
40
+ ).toBe(true);
41
+
42
+ const migration = await Bun.file(
43
+ new URL("../drizzle/0038_uneven_wasp.sql", import.meta.url),
44
+ ).text();
45
+ expect(migration).toContain('CREATE TABLE "notification_preferences"');
46
+ expect(migration).toContain('CREATE TABLE "notification_delivery_outbox"');
47
+ expect(migration).toContain(
48
+ 'ALTER TABLE "platform_notifications" ADD COLUMN "scheduled_for"',
49
+ );
50
+ expect(migration).toContain(
51
+ 'CREATE INDEX "idx_notification_delivery_claim"',
52
+ );
53
+ });
54
+ });
@@ -1,7 +1,9 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import { getTableConfig } from "drizzle-orm/pg-core";
3
3
  import {
4
+ notificationFavorites,
4
5
  notificationReads,
6
+ notificationRevisions,
5
7
  platformNotifications,
6
8
  workflowTransitions,
7
9
  workflowWorkItems,
@@ -30,7 +32,7 @@ describe("审批与通知 schema", () => {
30
32
  );
31
33
  });
32
34
 
33
- test("站内通知持久化发布状态、受众、业务目标和用户已读回执", async () => {
35
+ test("站内通知持久化发布状态、受众、已读与独立收藏回执", async () => {
34
36
  expect(getTableConfig(platformNotifications).name).toBe(
35
37
  "platform_notifications",
36
38
  );
@@ -52,6 +54,21 @@ describe("审批与通知 schema", () => {
52
54
  (foreignKey) => foreignKey.onDelete === "restrict",
53
55
  ),
54
56
  ).toBe(true);
57
+ expect(getTableConfig(notificationFavorites).name).toBe(
58
+ "notification_favorites",
59
+ );
60
+ expect(getTableConfig(notificationFavorites).primaryKeys).toHaveLength(1);
61
+ expect(notificationFavorites.favoritedAt.notNull).toBe(true);
62
+ expect(
63
+ getTableConfig(notificationFavorites).foreignKeys.every(
64
+ (foreignKey) => foreignKey.onDelete === "restrict",
65
+ ),
66
+ ).toBe(true);
67
+ expect(getTableConfig(notificationRevisions).name).toBe(
68
+ "notification_revisions",
69
+ );
70
+ expect(getTableConfig(notificationRevisions).primaryKeys).toHaveLength(1);
71
+ expect(platformNotifications.revision.notNull).toBe(true);
55
72
  const migration = await Bun.file(
56
73
  new URL("../drizzle/0027_tiny_diamondback.sql", import.meta.url),
57
74
  ).text();
@@ -59,5 +76,27 @@ describe("审批与通知 schema", () => {
59
76
  expect(migration).toContain(
60
77
  'CREATE UNIQUE INDEX "uk_platform_notifications_source_key"',
61
78
  );
79
+ const favoritesMigration = await Bun.file(
80
+ new URL("../drizzle/0035_material_nightshade.sql", import.meta.url),
81
+ ).text();
82
+ expect(favoritesMigration).toContain(
83
+ 'CREATE TABLE "notification_favorites"',
84
+ );
85
+ expect(favoritesMigration).toContain(
86
+ 'PRIMARY KEY("notification_id","user_id")',
87
+ );
88
+ expect(favoritesMigration).toContain("ON DELETE restrict");
89
+ const revisionsMigration = await Bun.file(
90
+ new URL("../drizzle/0036_hesitant_speed.sql", import.meta.url),
91
+ ).text();
92
+ expect(revisionsMigration).toContain(
93
+ 'CREATE TABLE "notification_revisions"',
94
+ );
95
+ expect(revisionsMigration).toContain(
96
+ 'ALTER TABLE "platform_notifications" ADD COLUMN "revision"',
97
+ );
98
+ expect(revisionsMigration).toContain(
99
+ 'INSERT INTO "notification_revisions"',
100
+ );
62
101
  });
63
102
  });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@southwind-ai/modules",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "engines": {
@@ -0,0 +1,164 @@
1
+ import type { ModuleManifest } from "./manifest.js";
2
+ import { featureKey } from "@southwind-ai/shared";
3
+
4
+ export function fixture(
5
+ name: string,
6
+ dependencies: string[] = [],
7
+ ): ModuleManifest {
8
+ const featureKey = `${name}.feature`;
9
+ const readPermission = `${name}.read`;
10
+ const managePermission = `${name}.manage`;
11
+ return {
12
+ name,
13
+ version: "0.1.0",
14
+ label: name,
15
+ description: `${name} module`,
16
+ dependencies,
17
+ menus: [
18
+ {
19
+ key: `${name}.page`,
20
+ title: name,
21
+ type: "menu",
22
+ order: 1,
23
+ visible: true,
24
+ path: `/${name}`,
25
+ permissionKey: readPermission,
26
+ featureKey,
27
+ },
28
+ ],
29
+ adminRoutes: [
30
+ {
31
+ key: `${name}.page`,
32
+ path: `/${name}`,
33
+ title: name,
34
+ surface: "sidebar",
35
+ permissionKey: readPermission,
36
+ featureKey,
37
+ },
38
+ ],
39
+ permissions: [
40
+ permission(name, readPermission, "read"),
41
+ permission(name, managePermission, "manage"),
42
+ ],
43
+ apiPermissions: [
44
+ {
45
+ method: "GET",
46
+ path: `/api/${name}`,
47
+ permissionKey: readPermission,
48
+ featureKey,
49
+ },
50
+ ],
51
+ features: [
52
+ {
53
+ key: featureKey,
54
+ label: name,
55
+ module: name,
56
+ visible: "visible",
57
+ enabled: true,
58
+ stage: "stable",
59
+ },
60
+ ],
61
+ migrations: [],
62
+ schemaExports: [
63
+ {
64
+ key: `${name}.schema`,
65
+ exportName: `${name}Table`,
66
+ migrationIds: [`${name}.001`],
67
+ },
68
+ ],
69
+ jsonSchemas: [
70
+ {
71
+ key: `${name}.tool.input.v1`,
72
+ schema: { type: "object" },
73
+ },
74
+ {
75
+ key: `${name}.tool.output.v1`,
76
+ schema: { type: "object" },
77
+ },
78
+ ],
79
+ tasks: [
80
+ {
81
+ key: `${name}.task`,
82
+ label: name,
83
+ description: name,
84
+ permissionKey: managePermission,
85
+ featureKey,
86
+ intervalSeconds: 60,
87
+ maxAttempts: 3,
88
+ retryDelaySeconds: 10,
89
+ },
90
+ ],
91
+ tools: [
92
+ {
93
+ key: `${name}.tool`,
94
+ label: name,
95
+ description: name,
96
+ inputSchemaKey: `${name}.tool.input.v1`,
97
+ outputSchemaKey: `${name}.tool.output.v1`,
98
+ operation: "query",
99
+ permissionKey: readPermission,
100
+ featureKey,
101
+ auditAction: "agent.tool.execute",
102
+ scopeMode: "request",
103
+ dataClassification: "internal",
104
+ idempotency: "none",
105
+ approval: "none",
106
+ limits: {
107
+ maxDurationSeconds: 10,
108
+ maxInputBytes: 4096,
109
+ maxOutputBytes: 4096,
110
+ },
111
+ },
112
+ ],
113
+ providers: [
114
+ {
115
+ key: `${name}.provider`,
116
+ kind: "fixture",
117
+ contractVersion: "1",
118
+ permissionKey: readPermission,
119
+ featureKey,
120
+ },
121
+ ],
122
+ auditActions: ["agent.tool.execute"],
123
+ };
124
+ }
125
+
126
+ export function dataPolicy(): NonNullable<
127
+ ModuleManifest["dataPolicies"]
128
+ >[number] {
129
+ return {
130
+ key: "system.user.fields",
131
+ resourceType: "system.user",
132
+ version: "1",
133
+ featureKey: featureKey("system.feature"),
134
+ readPermissionKey: "system.read",
135
+ revealPermissionKey: "system.reveal",
136
+ exportPermissionKey: "system.export",
137
+ display: {
138
+ read: "masked",
139
+ reveal: "plaintext",
140
+ unauthorized: "hidden",
141
+ },
142
+ fields: [
143
+ {
144
+ fieldKey: "phone",
145
+ classification: "sensitive",
146
+ mask: { kind: "partial", prefix: 3, suffix: 4 },
147
+ },
148
+ ],
149
+ };
150
+ }
151
+
152
+ export function permission(
153
+ module: string,
154
+ key: string,
155
+ action: "read" | "manage",
156
+ ): ModuleManifest["permissions"][number] {
157
+ return {
158
+ key,
159
+ label: action,
160
+ module,
161
+ resource: "fixture",
162
+ action,
163
+ };
164
+ }
@@ -1,6 +1,10 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import { featureKey, licenseVersionKey } from "@southwind-ai/shared";
3
- import type { ModuleManifest } from "./manifest.js";
3
+ import {
4
+ dataPolicy,
5
+ fixture,
6
+ permission,
7
+ } from "./composition-fixtures.test-support.js";
4
8
  import { validateModuleComposition } from "./composition.js";
5
9
 
6
10
  describe("Module Composition 契约", () => {
@@ -223,160 +227,3 @@ describe("Module Composition 契约", () => {
223
227
  );
224
228
  });
225
229
  });
226
-
227
- function fixture(name: string, dependencies: string[] = []): ModuleManifest {
228
- const featureKey = `${name}.feature`;
229
- const readPermission = `${name}.read`;
230
- const managePermission = `${name}.manage`;
231
- return {
232
- name,
233
- version: "0.1.0",
234
- label: name,
235
- description: `${name} module`,
236
- dependencies,
237
- menus: [
238
- {
239
- key: `${name}.page`,
240
- title: name,
241
- type: "menu",
242
- order: 1,
243
- visible: true,
244
- path: `/${name}`,
245
- permissionKey: readPermission,
246
- featureKey,
247
- },
248
- ],
249
- adminRoutes: [
250
- {
251
- key: `${name}.page`,
252
- path: `/${name}`,
253
- title: name,
254
- surface: "sidebar",
255
- permissionKey: readPermission,
256
- featureKey,
257
- },
258
- ],
259
- permissions: [
260
- permission(name, readPermission, "read"),
261
- permission(name, managePermission, "manage"),
262
- ],
263
- apiPermissions: [
264
- {
265
- method: "GET",
266
- path: `/api/${name}`,
267
- permissionKey: readPermission,
268
- featureKey,
269
- },
270
- ],
271
- features: [
272
- {
273
- key: featureKey,
274
- label: name,
275
- module: name,
276
- visible: "visible",
277
- enabled: true,
278
- stage: "stable",
279
- },
280
- ],
281
- migrations: [],
282
- schemaExports: [
283
- {
284
- key: `${name}.schema`,
285
- exportName: `${name}Table`,
286
- migrationIds: [`${name}.001`],
287
- },
288
- ],
289
- jsonSchemas: [
290
- {
291
- key: `${name}.tool.input.v1`,
292
- schema: { type: "object" },
293
- },
294
- {
295
- key: `${name}.tool.output.v1`,
296
- schema: { type: "object" },
297
- },
298
- ],
299
- tasks: [
300
- {
301
- key: `${name}.task`,
302
- label: name,
303
- description: name,
304
- permissionKey: managePermission,
305
- featureKey,
306
- intervalSeconds: 60,
307
- maxAttempts: 3,
308
- retryDelaySeconds: 10,
309
- },
310
- ],
311
- tools: [
312
- {
313
- key: `${name}.tool`,
314
- label: name,
315
- description: name,
316
- inputSchemaKey: `${name}.tool.input.v1`,
317
- outputSchemaKey: `${name}.tool.output.v1`,
318
- operation: "query",
319
- permissionKey: readPermission,
320
- featureKey,
321
- auditAction: "agent.tool.execute",
322
- scopeMode: "request",
323
- dataClassification: "internal",
324
- idempotency: "none",
325
- approval: "none",
326
- limits: {
327
- maxDurationSeconds: 10,
328
- maxInputBytes: 4096,
329
- maxOutputBytes: 4096,
330
- },
331
- },
332
- ],
333
- providers: [
334
- {
335
- key: `${name}.provider`,
336
- kind: "fixture",
337
- contractVersion: "1",
338
- permissionKey: readPermission,
339
- featureKey,
340
- },
341
- ],
342
- auditActions: ["agent.tool.execute"],
343
- };
344
- }
345
-
346
- function dataPolicy(): NonNullable<ModuleManifest["dataPolicies"]>[number] {
347
- return {
348
- key: "system.user.fields",
349
- resourceType: "system.user",
350
- version: "1",
351
- featureKey: featureKey("system.feature"),
352
- readPermissionKey: "system.read",
353
- revealPermissionKey: "system.reveal",
354
- exportPermissionKey: "system.export",
355
- display: {
356
- read: "masked",
357
- reveal: "plaintext",
358
- unauthorized: "hidden",
359
- },
360
- fields: [
361
- {
362
- fieldKey: "phone",
363
- classification: "sensitive",
364
- mask: { kind: "partial", prefix: 3, suffix: 4 },
365
- },
366
- ],
367
- };
368
- }
369
-
370
- function permission(
371
- module: string,
372
- key: string,
373
- action: "read" | "manage",
374
- ): ModuleManifest["permissions"][number] {
375
- return {
376
- key,
377
- label: action,
378
- module,
379
- resource: "fixture",
380
- action,
381
- };
382
- }