create-windy 0.2.34 → 0.3.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 (237) hide show
  1. package/dist/cli.js +167 -17
  2. package/package.json +1 -1
  3. package/template/.windy-template.json +2 -2
  4. package/template/AGENTS.md +5 -0
  5. package/template/README.md +3 -1
  6. package/template/apps/agent-server/Dockerfile +1 -0
  7. package/template/apps/agent-server/README.md +18 -5
  8. package/template/apps/agent-server/adk_web_agents/__init__.py +1 -0
  9. package/template/apps/agent-server/adk_web_agents/safe_debug/__init__.py +3 -0
  10. package/template/apps/agent-server/adk_web_agents/safe_debug/agent.py +40 -0
  11. package/template/apps/agent-server/pyproject.toml +1 -1
  12. package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +191 -16
  13. package/template/apps/agent-server/src/southwind_agent_server/adk_failure.py +13 -0
  14. package/template/apps/agent-server/src/southwind_agent_server/adk_model.py +225 -0
  15. package/template/apps/agent-server/src/southwind_agent_server/adk_tools.py +76 -0
  16. package/template/apps/agent-server/src/southwind_agent_server/app.py +1 -2
  17. package/template/apps/agent-server/tests/test_adk_adapter.py +305 -0
  18. package/template/apps/agent-server/tests/test_adk_web_agent.py +12 -0
  19. package/template/apps/server/package.json +4 -1
  20. package/template/apps/server/src/agent/run-facade.ts +2 -7
  21. package/template/apps/server/src/agent/tool-registry.ts +2 -6
  22. package/template/apps/server/src/application-services.ts +50 -0
  23. package/template/apps/server/src/audit/drizzle-log-store.ts +25 -0
  24. package/template/apps/server/src/audit/search-summary.ts +2 -6
  25. package/template/apps/server/src/auth/credential-restriction.ts +1 -0
  26. package/template/apps/server/src/auth/password.ts +30 -21
  27. package/template/apps/server/src/auth/routes.test.ts +44 -3
  28. package/template/apps/server/src/auth/routes.ts +6 -1
  29. package/template/apps/server/src/auth/runtime.ts +4 -1
  30. package/template/apps/server/src/auth/service.ts +25 -7
  31. package/template/apps/server/src/configuration/bootstrap.ts +20 -1
  32. package/template/apps/server/src/configuration/definition.test.ts +71 -0
  33. package/template/apps/server/src/configuration/definition.ts +242 -12
  34. package/template/apps/server/src/configuration/drizzle-repository.ts +36 -2
  35. package/template/apps/server/src/configuration/repository.ts +27 -2
  36. package/template/apps/server/src/configuration/routes.ts +4 -1
  37. package/template/apps/server/src/configuration/service.test.ts +100 -0
  38. package/template/apps/server/src/configuration/service.ts +50 -10
  39. package/template/apps/server/src/data-access/scoped-repository.integration.test.ts +3 -2
  40. package/template/apps/server/src/data-governance/export/service.ts +2 -6
  41. package/template/apps/server/src/example-modules.ts +4 -1
  42. package/template/apps/server/src/guards.ts +18 -5
  43. package/template/apps/server/src/http/request-source.test.ts +85 -0
  44. package/template/apps/server/src/http/request-source.ts +90 -0
  45. package/template/apps/server/src/index.ts +23 -6
  46. package/template/apps/server/src/license/routes.ts +2 -0
  47. package/template/apps/server/src/license/runtime-service.ts +10 -11
  48. package/template/apps/server/src/module-bootstrap.ts +2 -2
  49. package/template/apps/server/src/module-host/request-context.ts +6 -6
  50. package/template/apps/server/src/module-host/storage-scope.ts +2 -9
  51. package/template/apps/server/src/module-host/user-directory-port.ts +2 -6
  52. package/template/apps/server/src/notification/channel-adapter.ts +46 -0
  53. package/template/apps/server/src/notification/delivery-policy.test.ts +59 -0
  54. package/template/apps/server/src/notification/delivery-policy.ts +37 -0
  55. package/template/apps/server/src/notification/delivery-repository.ts +198 -0
  56. package/template/apps/server/src/notification/delivery-worker.test.ts +87 -0
  57. package/template/apps/server/src/notification/delivery-worker.ts +88 -0
  58. package/template/apps/server/src/notification/drizzle-management.ts +180 -0
  59. package/template/apps/server/src/notification/drizzle-query.ts +160 -0
  60. package/template/apps/server/src/notification/drizzle-repository.integration.test.ts +301 -0
  61. package/template/apps/server/src/notification/drizzle-repository.ts +156 -90
  62. package/template/apps/server/src/notification/extension-routes.test.ts +119 -0
  63. package/template/apps/server/src/notification/extension-routes.ts +111 -0
  64. package/template/apps/server/src/notification/memory-delivery-repository.ts +137 -0
  65. package/template/apps/server/src/notification/memory-support.ts +72 -0
  66. package/template/apps/server/src/notification/preference-repository.ts +95 -0
  67. package/template/apps/server/src/notification/recipient-directory.ts +104 -0
  68. package/template/apps/server/src/notification/repository.test.ts +171 -0
  69. package/template/apps/server/src/notification/repository.ts +179 -32
  70. package/template/apps/server/src/notification/revision-routes.test.ts +186 -0
  71. package/template/apps/server/src/notification/route-support.ts +225 -0
  72. package/template/apps/server/src/notification/routes.test.ts +182 -0
  73. package/template/apps/server/src/notification/routes.ts +225 -132
  74. package/template/apps/server/src/notification/service.test.ts +104 -0
  75. package/template/apps/server/src/notification/service.ts +140 -0
  76. package/template/apps/server/src/notification/smtp-adapter.test.ts +65 -0
  77. package/template/apps/server/src/notification/smtp-adapter.ts +68 -0
  78. package/template/apps/server/src/persistence.integration.test.ts +41 -2
  79. package/template/apps/server/src/route-guards.ts +1 -0
  80. package/template/apps/server/src/runtime-audit-list.test.ts +39 -0
  81. package/template/apps/server/src/runtime-development.ts +1 -0
  82. package/template/apps/server/src/runtime.test.ts +23 -9
  83. package/template/apps/server/src/runtime.ts +39 -2
  84. package/template/apps/server/src/scheduler/audit.ts +2 -11
  85. package/template/apps/server/src/scheduler/definitions.test.ts +6 -0
  86. package/template/apps/server/src/scheduler/definitions.ts +7 -0
  87. package/template/apps/server/src/scheduler/recovery-service.ts +2 -11
  88. package/template/apps/server/src/scheduler/routes.ts +2 -7
  89. package/template/apps/server/src/search/opensearch-client.test.ts +45 -0
  90. package/template/apps/server/src/search/opensearch-client.ts +145 -0
  91. package/template/apps/server/src/search/service.ts +2 -6
  92. package/template/apps/server/src/settings/routes.ts +15 -3
  93. package/template/apps/server/src/settings/runtime.ts +10 -1
  94. package/template/apps/server/src/storage/runtime.ts +13 -0
  95. package/template/apps/server/src/system/audit-query.ts +33 -4
  96. package/template/apps/server/src/system/audit-routes.test.ts +58 -4
  97. package/template/apps/server/src/system/audit-routes.ts +6 -5
  98. package/template/apps/server/src/system/department-organization.ts +320 -0
  99. package/template/apps/server/src/system/department-routes.test.ts +207 -48
  100. package/template/apps/server/src/system/department-routes.ts +114 -33
  101. package/template/apps/server/src/system/drizzle-repository.ts +15 -7
  102. package/template/apps/server/src/system/drizzle-scoped-repository.ts +5 -3
  103. package/template/apps/server/src/system/drizzle-system.ts +37 -9
  104. package/template/apps/server/src/system/drizzle-transaction-context.ts +14 -0
  105. package/template/apps/server/src/system/identity-route-config.ts +7 -2
  106. package/template/apps/server/src/system/mutation-runner.ts +23 -0
  107. package/template/apps/server/src/system/organization-postgres.integration.test.ts +176 -0
  108. package/template/apps/server/src/system/resource-access-response.ts +12 -6
  109. package/template/apps/server/src/system/role-department-scope-policy.ts +55 -0
  110. package/template/apps/server/src/system/route-helpers.ts +2 -5
  111. package/template/apps/server/src/system/route-types.ts +12 -3
  112. package/template/apps/server/src/system/routes-validation.test.ts +26 -0
  113. package/template/apps/server/src/system/routes.test.ts +10 -2
  114. package/template/apps/server/src/system/routes.ts +70 -36
  115. package/template/apps/server/src/system/seed.ts +7 -0
  116. package/template/apps/server/src/work-order/data-scope.integration.test.ts +9 -2
  117. package/template/apps/server/src/work-order/opensearch-index.test.ts +97 -0
  118. package/template/apps/server/src/work-order/opensearch-index.ts +313 -0
  119. package/template/apps/server/src/work-order/search-provider.ts +60 -1
  120. package/template/apps/server/src/work-order/service.ts +42 -10
  121. package/template/apps/web/src/app/error-pages.ts +9 -0
  122. package/template/apps/web/src/components/auth/PasswordChangeForm.vue +16 -11
  123. package/template/apps/web/src/components/auth/PasswordChangeForm.webtest.ts +14 -0
  124. package/template/apps/web/src/components/common/FormDialog.vue +16 -2
  125. package/template/apps/web/src/components/common/ModalLayout.webtest.ts +20 -1
  126. package/template/apps/web/src/composables/useGlobalSearch.ts +68 -0
  127. package/template/apps/web/src/composables/usePlatformSettings.ts +8 -7
  128. package/template/apps/web/src/layout/GlobalSearchResults.vue +58 -0
  129. package/template/apps/web/src/layout/NavigationSearchDialog.vue +42 -6
  130. package/template/apps/web/src/layout/NavigationSearchDialog.webtest.ts +71 -0
  131. package/template/apps/web/src/layout/NotificationMenu.vue +73 -31
  132. package/template/apps/web/src/layout/NotificationMenu.webtest.ts +44 -1
  133. package/template/apps/web/src/layout/NotificationMenuItem.vue +61 -0
  134. package/template/apps/web/src/layout/NotificationPreferencesDialog.vue +181 -0
  135. package/template/apps/web/src/layout/NotificationPreferencesDialog.webtest.ts +80 -0
  136. package/template/apps/web/src/lib/date-time.ts +22 -10
  137. package/template/apps/web/src/lib/date-time.webtest.ts +9 -1
  138. package/template/apps/web/src/main.ts +14 -1
  139. package/template/apps/web/src/pages/auth/ChangePasswordPage.vue +16 -1
  140. package/template/apps/web/src/pages/configuration/components/ModuleConfigVersionList.vue +1 -0
  141. package/template/apps/web/src/pages/configuration/components/ModuleConfigurationEditor.vue +10 -0
  142. package/template/apps/web/src/pages/configuration/components/ModuleConfigurationWorkbench.vue +37 -6
  143. package/template/apps/web/src/pages/errors/PlatformErrorPage.vue +115 -0
  144. package/template/apps/web/src/pages/errors/PlatformErrorPage.webtest.ts +44 -0
  145. package/template/apps/web/src/pages/errors/error-page-extension.ts +26 -0
  146. package/template/apps/web/src/pages/system/SystemNotificationsPage.vue +136 -68
  147. package/template/apps/web/src/pages/system/SystemNotificationsPage.webtest.ts +224 -12
  148. package/template/apps/web/src/pages/system/audit-log-presenter.ts +86 -0
  149. package/template/apps/web/src/pages/system/audit-time-range.ts +28 -0
  150. package/template/apps/web/src/pages/system/components/AuditActionCell.vue +10 -69
  151. package/template/apps/web/src/pages/system/components/AuditActionCell.webtest.ts +20 -27
  152. package/template/apps/web/src/pages/system/components/AuditLogDetailDialog.vue +134 -0
  153. package/template/apps/web/src/pages/system/components/AuditLogDetailDialog.webtest.ts +76 -0
  154. package/template/apps/web/src/pages/system/components/AuditLogFilters.vue +116 -52
  155. package/template/apps/web/src/pages/system/components/AuditLogFilters.webtest.ts +52 -15
  156. package/template/apps/web/src/pages/system/components/NotificationHistoryDialog.vue +129 -0
  157. package/template/apps/web/src/pages/system/components/NotificationManagementCard.vue +91 -0
  158. package/template/apps/web/src/pages/system/components/NotificationPublishDialog.vue +121 -0
  159. package/template/apps/web/src/pages/system/components/NotificationPublishForm.vue +162 -1
  160. package/template/apps/web/src/pages/system/components/SystemResourceActions.vue +68 -0
  161. package/template/apps/web/src/pages/system/components/SystemResourceEditor.vue +74 -0
  162. package/template/apps/web/src/pages/system/components/SystemResourceFilters.vue +3 -4
  163. package/template/apps/web/src/pages/system/components/SystemResourcePage.vue +91 -98
  164. package/template/apps/web/src/pages/system/components/SystemResourcePage.webtest.ts +68 -0
  165. package/template/apps/web/src/pages/system/components/SystemResourceTable.vue +20 -1
  166. package/template/apps/web/src/pages/system/components/SystemResourceTable.webtest.ts +28 -7
  167. package/template/apps/web/src/pages/system/components/department/DepartmentOrganizationForm.vue +210 -0
  168. package/template/apps/web/src/pages/system/components/department/DepartmentTransitionDialog.vue +112 -0
  169. package/template/apps/web/src/pages/system/components/user-account/UserAccountForm.vue +17 -4
  170. package/template/apps/web/src/pages/system/composables/useDepartmentTransitions.ts +79 -0
  171. package/template/apps/web/src/pages/system/composables/useNotificationPermissions.ts +14 -0
  172. package/template/apps/web/src/pages/system/composables/useSystemResource.ts +2 -0
  173. package/template/apps/web/src/pages/system/composables/useSystemResource.webtest.ts +15 -2
  174. package/template/apps/web/src/pages/system/resource-config.ts +12 -4
  175. package/template/apps/web/src/router/error-navigation.ts +50 -0
  176. package/template/apps/web/src/router/error-navigation.webtest.ts +106 -0
  177. package/template/apps/web/src/router/index.ts +71 -0
  178. package/template/apps/web/src/router/index.webtest.ts +29 -0
  179. package/template/apps/web/src/router/manifest-routes.webtest.ts +4 -0
  180. package/template/apps/web/src/router/shared-scaffold-neutrality.webtest.ts +12 -0
  181. package/template/apps/web/src/services/auth-api.ts +5 -0
  182. package/template/apps/web/src/services/http.ts +43 -6
  183. package/template/apps/web/src/services/http.webtest.ts +70 -0
  184. package/template/apps/web/src/services/notification-api.ts +85 -2
  185. package/template/apps/web/src/services/notification-api.webtest.ts +110 -0
  186. package/template/apps/web/src/services/search-api.ts +39 -0
  187. package/template/apps/web/src/services/system-api.ts +18 -0
  188. package/template/apps/web/vitest.config.ts +1 -0
  189. package/template/docker-compose.yml +66 -0
  190. package/template/docs/architecture/ai-runtime.md +14 -5
  191. package/template/docs/architecture/search-provider-protocol.md +38 -2
  192. package/template/docs/development/custom-error-pages.md +78 -0
  193. package/template/docs/development/custom-login-page.md +3 -3
  194. package/template/docs/platform/agent-runtime.md +32 -6
  195. package/template/docs/platform/audit-reliability.md +46 -2
  196. package/template/docs/platform/module-configuration.md +13 -4
  197. package/template/docs/platform/notifications.md +67 -11
  198. package/template/docs/platform/organization-membership.md +17 -3
  199. package/template/docs/platform/system-crud-api.md +16 -0
  200. package/template/docs/platform/web-system-crud.md +6 -2
  201. package/template/package.json +4 -0
  202. package/template/packages/config/index.test.ts +45 -0
  203. package/template/packages/config/package.json +1 -1
  204. package/template/packages/config/src/platform.ts +169 -48
  205. package/template/packages/database/drizzle/0035_material_nightshade.sql +10 -0
  206. package/template/packages/database/drizzle/0036_hesitant_speed.sql +35 -0
  207. package/template/packages/database/drizzle/0037_absent_nick_fury.sql +2 -0
  208. package/template/packages/database/drizzle/0038_uneven_wasp.sql +38 -0
  209. package/template/packages/database/drizzle/meta/0035_snapshot.json +7331 -0
  210. package/template/packages/database/drizzle/meta/0036_snapshot.json +7436 -0
  211. package/template/packages/database/drizzle/meta/0037_snapshot.json +7457 -0
  212. package/template/packages/database/drizzle/meta/0038_snapshot.json +7749 -0
  213. package/template/packages/database/drizzle/meta/_journal.json +28 -0
  214. package/template/packages/database/package.json +1 -1
  215. package/template/packages/database/src/schema/identity.ts +7 -0
  216. package/template/packages/database/src/schema/notifications.ts +135 -0
  217. package/template/packages/database/src/schema-notification-delivery.test.ts +54 -0
  218. package/template/packages/database/src/schema-workflow-notification.test.ts +40 -1
  219. package/template/packages/modules/package.json +1 -1
  220. package/template/packages/modules/src/system-api-permissions.ts +54 -0
  221. package/template/packages/modules/src/system-audit-actions.ts +10 -0
  222. package/template/packages/modules/src/system-features.ts +1 -1
  223. package/template/packages/modules/src/system-module-catalog.ts +2 -1
  224. package/template/packages/modules/src/system-modules.test.ts +13 -1
  225. package/template/packages/modules/src/system-modules.ts +12 -0
  226. package/template/packages/modules/src/system-permissions.ts +9 -5
  227. package/template/packages/server-sdk/package.json +1 -1
  228. package/template/packages/shared/package.json +1 -1
  229. package/template/packages/shared/src/audit.ts +25 -0
  230. package/template/packages/shared/src/module-configuration.ts +5 -0
  231. package/template/packages/shared/src/notification.ts +92 -1
  232. package/template/packages/shared/src/password.ts +7 -2
  233. package/template/packages/shared/src/platform-settings.ts +2 -0
  234. package/template/packages/storage/package.json +1 -1
  235. package/template/packages/storage/src/upload-service.test.ts +16 -0
  236. package/template/packages/storage/src/upload-service.ts +5 -1
  237. 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.4",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "engines": {
@@ -61,6 +61,12 @@ export function systemApiPermissionBindings(): ApiPermissionBinding[] {
61
61
  "system.department.create",
62
62
  "system.rbac",
63
63
  ),
64
+ binding(
65
+ "POST",
66
+ "/api/system/departments/:id/transition",
67
+ "system.department.manage",
68
+ "system.rbac",
69
+ ),
64
70
  binding("GET", "/api/system/menus", "system.menu.read", "system.rbac"),
65
71
  binding(
66
72
  "GET",
@@ -226,12 +232,48 @@ export function systemApiPermissionBindings(): ApiPermissionBinding[] {
226
232
  "system.notification.read",
227
233
  "system.notification",
228
234
  ),
235
+ binding(
236
+ "GET",
237
+ "/api/notifications/preferences",
238
+ "system.notification.read",
239
+ "system.notification",
240
+ ),
241
+ binding(
242
+ "PUT",
243
+ "/api/notifications/preferences",
244
+ "system.notification.read",
245
+ "system.notification",
246
+ ),
229
247
  binding(
230
248
  "POST",
231
249
  "/api/notifications/:id/read",
232
250
  "system.notification.read",
233
251
  "system.notification",
234
252
  ),
253
+ binding(
254
+ "PUT",
255
+ "/api/notifications/:id/favorite",
256
+ "system.notification.read",
257
+ "system.notification",
258
+ ),
259
+ binding(
260
+ "DELETE",
261
+ "/api/notifications/:id/favorite",
262
+ "system.notification.read",
263
+ "system.notification",
264
+ ),
265
+ binding(
266
+ "GET",
267
+ "/api/system/notifications/audience-options",
268
+ "system.notification.manage",
269
+ "system.notification",
270
+ ),
271
+ binding(
272
+ "GET",
273
+ "/api/system/notifications/:id/deliveries",
274
+ "system.notification.manage",
275
+ "system.notification",
276
+ ),
235
277
  binding(
236
278
  "GET",
237
279
  "/api/system/notifications",
@@ -244,6 +286,18 @@ export function systemApiPermissionBindings(): ApiPermissionBinding[] {
244
286
  "system.notification.manage",
245
287
  "system.notification",
246
288
  ),
289
+ binding(
290
+ "PUT",
291
+ "/api/system/notifications/:id",
292
+ "system.notification.update",
293
+ "system.notification",
294
+ ),
295
+ binding(
296
+ "GET",
297
+ "/api/system/notifications/:id/revisions",
298
+ "system.notification.manage",
299
+ "system.notification",
300
+ ),
247
301
  binding(
248
302
  "DELETE",
249
303
  "/api/system/notifications/:id",
@@ -22,9 +22,19 @@ export const systemAuditActions: ModuleManifest["auditActions"] = [
22
22
  // @windy-module system.license end
23
23
  "feature.update",
24
24
  "menu.structure.update",
25
+ {
26
+ key: "organization.department.transition",
27
+ label: "处置部门组织",
28
+ description: "迁移部门关联后停用或删除部门。",
29
+ },
25
30
  // @windy-module system.notification begin
26
31
  "notification.publish",
32
+ "notification.schedule",
33
+ "notification.preference.update",
34
+ "notification.update",
27
35
  "notification.read",
36
+ "notification.favorite",
37
+ "notification.unfavorite",
28
38
  "notification.archive",
29
39
  // @windy-module system.notification end
30
40
  // @windy-module system.workflow begin
@@ -90,7 +90,7 @@ export const systemFeatures: ModuleManifest["features"] = [
90
90
  feature(
91
91
  "system.notification",
92
92
  "站内通知",
93
- "站内通知发布、管理、阅读和已读状态闭环。",
93
+ "站内通知发布、修改历史、阅读、收藏和已读状态闭环。",
94
94
  ),
95
95
  // @windy-module system.notification end
96
96
  // @windy-module system.workflow begin
@@ -124,7 +124,8 @@ export const systemModuleDefinitions = [
124
124
  name: "system.notification",
125
125
  version: "0.1.0",
126
126
  label: "站内通知",
127
- description: "通知发布、阅读、归档与状态管理。",
127
+ description:
128
+ "通知定向与定时发布、用户偏好、外部渠道投递、修改历史、阅读、收藏和归档。",
128
129
  resources: ["notification"],
129
130
  featureKeys: ["system.notification"],
130
131
  },
@@ -220,7 +220,7 @@ describe("系统模块能力注册", () => {
220
220
  expect(catalogs).toEqual(["组织与权限", "平台配置", "安全与合规", "运维"]);
221
221
  });
222
222
 
223
- test("部门快捷创建使用独立权限并绑定真实 API", () => {
223
+ test("部门创建与迁移处置绑定独立权限、Feature 和审计动作", () => {
224
224
  const manifest = systemFoundationModule();
225
225
  expect(
226
226
  manifest.permissions.some(
@@ -234,6 +234,18 @@ describe("系统模块能力注册", () => {
234
234
  featureKey: "system.rbac",
235
235
  anonymous: undefined,
236
236
  });
237
+ expect(manifest.apiPermissions).toContainEqual({
238
+ method: "POST",
239
+ path: "/api/system/departments/:id/transition",
240
+ permissionKey: "system.department.manage",
241
+ featureKey: "system.rbac",
242
+ anonymous: undefined,
243
+ });
244
+ expect(manifest.auditActions).toContainEqual(
245
+ expect.objectContaining({
246
+ key: "organization.department.transition",
247
+ }),
248
+ );
237
249
  });
238
250
 
239
251
  test("所有权限都由 Manifest 提供稳定中文分组元数据", () => {
@@ -270,6 +270,18 @@ export function systemFoundationModule(): ModuleManifest {
270
270
  retryDelaySeconds: 30,
271
271
  },
272
272
  // @windy-module system.scheduler end
273
+ // @windy-module system.notification begin
274
+ {
275
+ key: "system.notification.dispatch",
276
+ label: "通知发布与外部投递",
277
+ description: "发布到期通知并领取持久投递队列,执行渠道重试。",
278
+ permissionKey: "system.notification.manage",
279
+ featureKey: "system.notification",
280
+ intervalSeconds: 5,
281
+ maxAttempts: 3,
282
+ retryDelaySeconds: 30,
283
+ },
284
+ // @windy-module system.notification end
273
285
  // @windy-module system.bulk-data begin
274
286
  {
275
287
  key: "system.bulk-data.dispatch",
@@ -33,6 +33,7 @@ type SystemAction =
33
33
  | "approve"
34
34
  | "export"
35
35
  | "reveal"
36
+ | "update"
36
37
  | "manage";
37
38
 
38
39
  function permission(
@@ -54,11 +55,13 @@ function permission(
54
55
  ? "新建"
55
56
  : action === "approve"
56
57
  ? "处理"
57
- : action === "reveal"
58
- ? "查看明文"
59
- : action === "export"
60
- ? "治理导出"
61
- : "管理",
58
+ : action === "update"
59
+ ? "修改"
60
+ : action === "reveal"
61
+ ? "查看明文"
62
+ : action === "export"
63
+ ? "治理导出"
64
+ : "管理",
62
65
  module: "system",
63
66
  moduleLabel: "系统基础设施",
64
67
  resource,
@@ -125,6 +128,7 @@ export const systemPermissions: ModuleManifest["permissions"] = [
125
128
  // @windy-module system.scheduler end
126
129
  // @windy-module system.notification begin
127
130
  permission("notification", "read"),
131
+ permission("notification", "update"),
128
132
  permission("notification", "manage"),
129
133
  // @windy-module system.notification end
130
134
  // @windy-module system.bulk-data begin
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@southwind-ai/server-sdk",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "engines": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@southwind-ai/shared",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "engines": {
@@ -145,11 +145,36 @@ export const AUDIT_ACTION_DEFINITIONS = [
145
145
  label: "通知发布",
146
146
  description: "发布站内通知。",
147
147
  },
148
+ {
149
+ key: "notification.schedule",
150
+ label: "通知定时发布",
151
+ description: "创建等待调度器发布的通知。",
152
+ },
153
+ {
154
+ key: "notification.preference.update",
155
+ label: "通知偏好更新",
156
+ description: "用户更新外部通知渠道和分类偏好。",
157
+ },
158
+ {
159
+ key: "notification.update",
160
+ label: "通知修改",
161
+ description: "修改已发布通知并保留版本历史。",
162
+ },
148
163
  {
149
164
  key: "notification.read",
150
165
  label: "通知已读",
151
166
  description: "用户阅读站内通知。",
152
167
  },
168
+ {
169
+ key: "notification.favorite",
170
+ label: "收藏通知",
171
+ description: "用户收藏可见的站内通知。",
172
+ },
173
+ {
174
+ key: "notification.unfavorite",
175
+ label: "取消收藏通知",
176
+ description: "用户取消收藏可见的站内通知。",
177
+ },
153
178
  {
154
179
  key: "notification.archive",
155
180
  label: "通知归档",
@@ -5,8 +5,11 @@ export type ModuleConfigApplyStatus =
5
5
  | "applying"
6
6
  | "effective"
7
7
  | "failed"
8
+ | "pending-restart"
8
9
  | "superseded";
9
10
 
11
+ export type ModuleConfigApplyMode = "live" | "restart";
12
+
10
13
  export interface ModuleConfigDiffEntry {
11
14
  path: string;
12
15
  before?: ModuleConfigValue;
@@ -18,6 +21,7 @@ export interface ModuleConfigFieldDescriptor {
18
21
  label: string;
19
22
  description: string;
20
23
  input: "boolean" | "integer" | "text";
24
+ applyMode?: ModuleConfigApplyMode;
21
25
  minimum?: number;
22
26
  maximum?: number;
23
27
  }
@@ -42,6 +46,7 @@ export interface ModuleConfigSummary {
42
46
  label: string;
43
47
  fields: ModuleConfigFieldDescriptor[];
44
48
  effectiveValues: ModuleConfigValues;
49
+ pendingValues?: ModuleConfigValues;
45
50
  effectiveSource: "environment" | "version";
46
51
  effectiveVersion?: number;
47
52
  latestVersion?: number;