create-windy 0.2.33 → 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.
- package/dist/cli.js +173 -17
- package/package.json +1 -1
- package/template/.agents/skills/windy-business-module/SKILL.md +10 -1
- package/template/.windy-template.json +2 -2
- package/template/AGENTS.md +9 -0
- package/template/README.md +3 -1
- package/template/apps/agent-server/Dockerfile +1 -0
- package/template/apps/agent-server/README.md +28 -5
- package/template/apps/agent-server/adk_web_agents/__init__.py +1 -0
- package/template/apps/agent-server/adk_web_agents/safe_debug/__init__.py +3 -0
- package/template/apps/agent-server/adk_web_agents/safe_debug/agent.py +40 -0
- package/template/apps/agent-server/pyproject.toml +1 -1
- package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +191 -16
- package/template/apps/agent-server/src/southwind_agent_server/adk_failure.py +13 -0
- package/template/apps/agent-server/src/southwind_agent_server/adk_model.py +225 -0
- package/template/apps/agent-server/src/southwind_agent_server/adk_tools.py +76 -0
- package/template/apps/agent-server/src/southwind_agent_server/app.py +63 -3
- package/template/apps/agent-server/src/southwind_agent_server/contracts.py +35 -0
- package/template/apps/agent-server/src/southwind_agent_server/engine.py +2 -0
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine.py +31 -3
- package/template/apps/agent-server/src/southwind_agent_server/openai_provider.py +22 -9
- package/template/apps/agent-server/src/southwind_agent_server/provider_audit.py +144 -0
- package/template/apps/agent-server/src/southwind_agent_server/provider_governance.py +227 -0
- package/template/apps/agent-server/src/southwind_agent_server/service.py +1 -0
- package/template/apps/agent-server/tests/test_adk_adapter.py +305 -0
- package/template/apps/agent-server/tests/test_adk_web_agent.py +12 -0
- package/template/apps/agent-server/tests/test_api.py +16 -1
- package/template/apps/agent-server/tests/test_openai_provider.py +79 -0
- package/template/apps/agent-server/tests/test_provider_governance.py +215 -0
- package/template/apps/server/package.json +4 -1
- package/template/apps/server/src/agent/provider-input-governance.test.ts +82 -0
- package/template/apps/server/src/agent/provider-input-governance.ts +140 -0
- package/template/apps/server/src/agent/remote-runtime.test.ts +22 -0
- package/template/apps/server/src/agent/remote-runtime.ts +1 -0
- package/template/apps/server/src/agent/run-contracts.ts +2 -0
- package/template/apps/server/src/agent/run-facade.test.ts +52 -2
- package/template/apps/server/src/agent/run-facade.ts +38 -9
- package/template/apps/server/src/agent/tool-registry.ts +2 -6
- package/template/apps/server/src/application-services.ts +50 -0
- package/template/apps/server/src/audit/drizzle-log-store.ts +25 -0
- package/template/apps/server/src/audit/search-summary.ts +2 -6
- package/template/apps/server/src/auth/credential-restriction.ts +1 -0
- package/template/apps/server/src/auth/password.ts +30 -21
- package/template/apps/server/src/auth/routes.test.ts +44 -3
- package/template/apps/server/src/auth/routes.ts +6 -1
- package/template/apps/server/src/auth/runtime.ts +4 -1
- package/template/apps/server/src/auth/service.ts +25 -7
- package/template/apps/server/src/configuration/bootstrap.ts +20 -1
- package/template/apps/server/src/configuration/definition.test.ts +71 -0
- package/template/apps/server/src/configuration/definition.ts +242 -12
- package/template/apps/server/src/configuration/drizzle-repository.ts +36 -2
- package/template/apps/server/src/configuration/repository.ts +27 -2
- package/template/apps/server/src/configuration/routes.ts +4 -1
- package/template/apps/server/src/configuration/service.test.ts +100 -0
- package/template/apps/server/src/configuration/service.ts +50 -10
- package/template/apps/server/src/data-access/scoped-repository.integration.test.ts +3 -2
- package/template/apps/server/src/data-governance/export/service.ts +2 -6
- package/template/apps/server/src/example-modules.ts +4 -1
- package/template/apps/server/src/guards.ts +18 -5
- package/template/apps/server/src/http/request-source.test.ts +85 -0
- package/template/apps/server/src/http/request-source.ts +90 -0
- package/template/apps/server/src/index.ts +45 -45
- package/template/apps/server/src/license/routes.ts +2 -0
- package/template/apps/server/src/license/runtime-service.ts +10 -11
- package/template/apps/server/src/module-bootstrap.ts +2 -2
- package/template/apps/server/src/module-host/initialize-contracts.ts +6 -0
- package/template/apps/server/src/module-host/initialize.ts +30 -44
- package/template/apps/server/src/module-host/request-context.ts +29 -23
- package/template/apps/server/src/module-host/resource-file-policies.test.ts +197 -0
- package/template/apps/server/src/module-host/resource-file-policies.ts +108 -0
- package/template/apps/server/src/module-host/route-declaration.ts +45 -0
- package/template/apps/server/src/module-host/route-installer.ts +27 -3
- package/template/apps/server/src/module-host/storage-port.test.ts +170 -1
- package/template/apps/server/src/module-host/storage-port.ts +134 -1
- package/template/apps/server/src/module-host/storage-scope.ts +89 -0
- package/template/apps/server/src/module-host/tool-handlers.test.ts +305 -0
- package/template/apps/server/src/module-host/tool-handlers.ts +38 -4
- package/template/apps/server/src/module-host/user-directory-composition.test.ts +126 -0
- package/template/apps/server/src/module-host/user-directory-port.test.ts +238 -0
- package/template/apps/server/src/module-host/user-directory-port.ts +139 -0
- package/template/apps/server/src/module-host.ts +4 -0
- package/template/apps/server/src/notification/channel-adapter.ts +46 -0
- package/template/apps/server/src/notification/delivery-policy.test.ts +59 -0
- package/template/apps/server/src/notification/delivery-policy.ts +37 -0
- package/template/apps/server/src/notification/delivery-repository.ts +198 -0
- package/template/apps/server/src/notification/delivery-worker.test.ts +87 -0
- package/template/apps/server/src/notification/delivery-worker.ts +88 -0
- package/template/apps/server/src/notification/drizzle-management.ts +180 -0
- package/template/apps/server/src/notification/drizzle-query.ts +160 -0
- package/template/apps/server/src/notification/drizzle-repository.integration.test.ts +301 -0
- package/template/apps/server/src/notification/drizzle-repository.ts +156 -90
- package/template/apps/server/src/notification/extension-routes.test.ts +119 -0
- package/template/apps/server/src/notification/extension-routes.ts +111 -0
- package/template/apps/server/src/notification/memory-delivery-repository.ts +137 -0
- package/template/apps/server/src/notification/memory-support.ts +72 -0
- package/template/apps/server/src/notification/preference-repository.ts +95 -0
- package/template/apps/server/src/notification/recipient-directory.ts +104 -0
- package/template/apps/server/src/notification/repository.test.ts +171 -0
- package/template/apps/server/src/notification/repository.ts +179 -32
- package/template/apps/server/src/notification/revision-routes.test.ts +186 -0
- package/template/apps/server/src/notification/route-support.ts +225 -0
- package/template/apps/server/src/notification/routes.test.ts +182 -0
- package/template/apps/server/src/notification/routes.ts +225 -132
- package/template/apps/server/src/notification/service.test.ts +104 -0
- package/template/apps/server/src/notification/service.ts +140 -0
- package/template/apps/server/src/notification/smtp-adapter.test.ts +65 -0
- package/template/apps/server/src/notification/smtp-adapter.ts +68 -0
- package/template/apps/server/src/persistence.integration.test.ts +41 -2
- package/template/apps/server/src/route-guards.ts +1 -0
- package/template/apps/server/src/runtime-audit-list.test.ts +39 -0
- package/template/apps/server/src/runtime-development.ts +2 -0
- package/template/apps/server/src/runtime.test.ts +23 -9
- package/template/apps/server/src/runtime.ts +39 -2
- package/template/apps/server/src/scheduler/audit.ts +2 -11
- package/template/apps/server/src/scheduler/definitions.test.ts +6 -0
- package/template/apps/server/src/scheduler/definitions.ts +7 -0
- package/template/apps/server/src/scheduler/recovery-service.ts +2 -11
- package/template/apps/server/src/scheduler/routes.ts +2 -7
- package/template/apps/server/src/search/opensearch-client.test.ts +45 -0
- package/template/apps/server/src/search/opensearch-client.ts +145 -0
- package/template/apps/server/src/search/service.ts +2 -6
- package/template/apps/server/src/settings/routes.ts +15 -3
- package/template/apps/server/src/settings/runtime.ts +10 -1
- package/template/apps/server/src/storage/runtime.ts +13 -0
- package/template/apps/server/src/system/audit-query.ts +33 -4
- package/template/apps/server/src/system/audit-routes.test.ts +58 -4
- package/template/apps/server/src/system/audit-routes.ts +6 -5
- package/template/apps/server/src/system/built-in-roles.ts +1 -0
- package/template/apps/server/src/system/department-organization.ts +320 -0
- package/template/apps/server/src/system/department-routes.test.ts +207 -48
- package/template/apps/server/src/system/department-routes.ts +114 -33
- package/template/apps/server/src/system/drizzle-repository.ts +15 -7
- package/template/apps/server/src/system/drizzle-scoped-repository.ts +5 -3
- package/template/apps/server/src/system/drizzle-system.ts +37 -9
- package/template/apps/server/src/system/drizzle-transaction-context.ts +14 -0
- package/template/apps/server/src/system/identity-route-config.ts +7 -2
- package/template/apps/server/src/system/mutation-runner.ts +23 -0
- package/template/apps/server/src/system/organization-postgres.integration.test.ts +176 -0
- package/template/apps/server/src/system/resource-access-response.ts +12 -6
- package/template/apps/server/src/system/role-department-scope-policy.ts +55 -0
- package/template/apps/server/src/system/route-helpers.ts +2 -5
- package/template/apps/server/src/system/route-types.ts +12 -3
- package/template/apps/server/src/system/routes-validation.test.ts +26 -0
- package/template/apps/server/src/system/routes.test.ts +10 -2
- package/template/apps/server/src/system/routes.ts +70 -36
- package/template/apps/server/src/system/seed.ts +7 -0
- package/template/apps/server/src/work-order/data-scope.integration.test.ts +9 -2
- package/template/apps/server/src/work-order/opensearch-index.test.ts +97 -0
- package/template/apps/server/src/work-order/opensearch-index.ts +313 -0
- package/template/apps/server/src/work-order/search-provider.ts +60 -1
- package/template/apps/server/src/work-order/service.ts +42 -10
- package/template/apps/web/src/app/error-pages.ts +9 -0
- package/template/apps/web/src/components/auth/PasswordChangeForm.vue +16 -11
- package/template/apps/web/src/components/auth/PasswordChangeForm.webtest.ts +14 -0
- package/template/apps/web/src/components/common/FormDialog.vue +16 -2
- package/template/apps/web/src/components/common/ModalLayout.webtest.ts +20 -1
- package/template/apps/web/src/composables/useGlobalSearch.ts +68 -0
- package/template/apps/web/src/composables/usePlatformSettings.ts +8 -7
- package/template/apps/web/src/layout/GlobalSearchResults.vue +58 -0
- package/template/apps/web/src/layout/NavigationSearchDialog.vue +42 -6
- package/template/apps/web/src/layout/NavigationSearchDialog.webtest.ts +71 -0
- package/template/apps/web/src/layout/NotificationMenu.vue +73 -31
- package/template/apps/web/src/layout/NotificationMenu.webtest.ts +44 -1
- package/template/apps/web/src/layout/NotificationMenuItem.vue +61 -0
- package/template/apps/web/src/layout/NotificationPreferencesDialog.vue +181 -0
- package/template/apps/web/src/layout/NotificationPreferencesDialog.webtest.ts +80 -0
- package/template/apps/web/src/lib/date-time.ts +22 -10
- package/template/apps/web/src/lib/date-time.webtest.ts +9 -1
- package/template/apps/web/src/main.ts +14 -1
- package/template/apps/web/src/pages/auth/ChangePasswordPage.vue +16 -1
- package/template/apps/web/src/pages/configuration/components/ModuleConfigVersionList.vue +1 -0
- package/template/apps/web/src/pages/configuration/components/ModuleConfigurationEditor.vue +10 -0
- package/template/apps/web/src/pages/configuration/components/ModuleConfigurationWorkbench.vue +37 -6
- package/template/apps/web/src/pages/errors/PlatformErrorPage.vue +115 -0
- package/template/apps/web/src/pages/errors/PlatformErrorPage.webtest.ts +44 -0
- package/template/apps/web/src/pages/errors/error-page-extension.ts +26 -0
- package/template/apps/web/src/pages/system/SystemNotificationsPage.vue +136 -68
- package/template/apps/web/src/pages/system/SystemNotificationsPage.webtest.ts +224 -12
- package/template/apps/web/src/pages/system/audit-log-presenter.ts +86 -0
- package/template/apps/web/src/pages/system/audit-time-range.ts +28 -0
- package/template/apps/web/src/pages/system/components/AuditActionCell.vue +10 -69
- package/template/apps/web/src/pages/system/components/AuditActionCell.webtest.ts +20 -27
- package/template/apps/web/src/pages/system/components/AuditLogDetailDialog.vue +134 -0
- package/template/apps/web/src/pages/system/components/AuditLogDetailDialog.webtest.ts +76 -0
- package/template/apps/web/src/pages/system/components/AuditLogFilters.vue +116 -52
- package/template/apps/web/src/pages/system/components/AuditLogFilters.webtest.ts +52 -15
- package/template/apps/web/src/pages/system/components/NotificationHistoryDialog.vue +129 -0
- package/template/apps/web/src/pages/system/components/NotificationManagementCard.vue +91 -0
- package/template/apps/web/src/pages/system/components/NotificationPublishDialog.vue +121 -0
- package/template/apps/web/src/pages/system/components/NotificationPublishForm.vue +162 -1
- package/template/apps/web/src/pages/system/components/SystemResourceActions.vue +68 -0
- package/template/apps/web/src/pages/system/components/SystemResourceEditor.vue +74 -0
- package/template/apps/web/src/pages/system/components/SystemResourceFilters.vue +3 -4
- package/template/apps/web/src/pages/system/components/SystemResourcePage.vue +91 -98
- package/template/apps/web/src/pages/system/components/SystemResourcePage.webtest.ts +68 -0
- package/template/apps/web/src/pages/system/components/SystemResourceTable.vue +20 -1
- package/template/apps/web/src/pages/system/components/SystemResourceTable.webtest.ts +28 -7
- package/template/apps/web/src/pages/system/components/department/DepartmentOrganizationForm.vue +210 -0
- package/template/apps/web/src/pages/system/components/department/DepartmentTransitionDialog.vue +112 -0
- package/template/apps/web/src/pages/system/components/user-account/UserAccountForm.vue +17 -4
- package/template/apps/web/src/pages/system/composables/useDepartmentTransitions.ts +79 -0
- package/template/apps/web/src/pages/system/composables/useNotificationPermissions.ts +14 -0
- package/template/apps/web/src/pages/system/composables/useSystemResource.ts +2 -0
- package/template/apps/web/src/pages/system/composables/useSystemResource.webtest.ts +15 -2
- package/template/apps/web/src/pages/system/resource-config.ts +12 -4
- package/template/apps/web/src/router/error-navigation.ts +50 -0
- package/template/apps/web/src/router/error-navigation.webtest.ts +106 -0
- package/template/apps/web/src/router/index.ts +71 -0
- package/template/apps/web/src/router/index.webtest.ts +29 -0
- package/template/apps/web/src/router/manifest-routes.webtest.ts +4 -0
- package/template/apps/web/src/router/shared-scaffold-neutrality.webtest.ts +12 -0
- package/template/apps/web/src/services/auth-api.ts +5 -0
- package/template/apps/web/src/services/http.ts +43 -6
- package/template/apps/web/src/services/http.webtest.ts +70 -0
- package/template/apps/web/src/services/notification-api.ts +85 -2
- package/template/apps/web/src/services/notification-api.webtest.ts +110 -0
- package/template/apps/web/src/services/search-api.ts +39 -0
- package/template/apps/web/src/services/system-api.ts +18 -0
- package/template/apps/web/vitest.config.ts +1 -0
- package/template/docker-compose.yml +68 -0
- package/template/docs/architecture/ai-egress.md +49 -7
- package/template/docs/architecture/ai-runtime.md +34 -6
- package/template/docs/architecture/data-scope-query-enforcement.md +4 -0
- package/template/docs/architecture/object-storage.md +22 -2
- package/template/docs/architecture/search-provider-protocol.md +38 -2
- package/template/docs/development/custom-error-pages.md +78 -0
- package/template/docs/development/custom-login-page.md +3 -3
- package/template/docs/platform/agent-runtime.md +76 -7
- package/template/docs/platform/audit-reliability.md +46 -2
- package/template/docs/platform/business-user-directory.md +82 -0
- package/template/docs/platform/module-configuration.md +13 -4
- package/template/docs/platform/notifications.md +67 -11
- package/template/docs/platform/organization-membership.md +17 -3
- package/template/docs/platform/system-crud-api.md +16 -0
- package/template/docs/platform/web-system-crud.md +6 -2
- package/template/package.json +4 -0
- package/template/packages/config/index.test.ts +45 -0
- package/template/packages/config/package.json +1 -1
- package/template/packages/config/src/platform.ts +169 -48
- package/template/packages/database/drizzle/0035_material_nightshade.sql +10 -0
- package/template/packages/database/drizzle/0036_hesitant_speed.sql +35 -0
- package/template/packages/database/drizzle/0037_absent_nick_fury.sql +2 -0
- package/template/packages/database/drizzle/0038_uneven_wasp.sql +38 -0
- package/template/packages/database/drizzle/meta/0035_snapshot.json +7331 -0
- package/template/packages/database/drizzle/meta/0036_snapshot.json +7436 -0
- package/template/packages/database/drizzle/meta/0037_snapshot.json +7457 -0
- package/template/packages/database/drizzle/meta/0038_snapshot.json +7749 -0
- package/template/packages/database/drizzle/meta/_journal.json +28 -0
- package/template/packages/database/package.json +1 -1
- package/template/packages/database/src/schema/identity.ts +7 -0
- package/template/packages/database/src/schema/notifications.ts +135 -0
- package/template/packages/database/src/schema-notification-delivery.test.ts +54 -0
- package/template/packages/database/src/schema-workflow-notification.test.ts +40 -1
- package/template/packages/modules/package.json +1 -1
- package/template/packages/modules/src/ai-operation-composition.test.ts +68 -0
- package/template/packages/modules/src/ai-operation-composition.ts +115 -0
- package/template/packages/modules/src/manifest.ts +26 -0
- package/template/packages/modules/src/provider-data-policy-composition.test.ts +74 -0
- package/template/packages/modules/src/system-api-permissions.ts +54 -0
- package/template/packages/modules/src/system-audit-actions.ts +15 -0
- package/template/packages/modules/src/system-features.ts +6 -1
- package/template/packages/modules/src/system-module-catalog.test.ts +16 -0
- package/template/packages/modules/src/system-module-catalog.ts +28 -4
- package/template/packages/modules/src/system-modules.test.ts +13 -1
- package/template/packages/modules/src/system-modules.ts +12 -0
- package/template/packages/modules/src/system-permissions.ts +11 -5
- package/template/packages/server-sdk/index.ts +11 -0
- package/template/packages/server-sdk/package.json +3 -2
- package/template/packages/server-sdk/src/ai-operation-registration.ts +2 -1
- package/template/packages/server-sdk/src/module-host.ts +8 -0
- package/template/packages/server-sdk/src/request-context.ts +2 -0
- package/template/packages/server-sdk/src/storage-port.ts +66 -0
- package/template/packages/server-sdk/src/tool-registration.ts +6 -0
- package/template/packages/server-sdk/src/user-directory-port.ts +42 -0
- package/template/packages/shared/package.json +1 -1
- package/template/packages/shared/src/audit.ts +25 -0
- package/template/packages/shared/src/module-configuration.ts +5 -0
- package/template/packages/shared/src/notification.ts +92 -1
- package/template/packages/shared/src/password.ts +7 -2
- package/template/packages/shared/src/platform-settings.ts +2 -0
- package/template/packages/storage/package.json +1 -1
- package/template/packages/storage/src/upload-service.test.ts +16 -0
- package/template/packages/storage/src/upload-service.ts +5 -1
- package/template/scripts/notification-postgres-regression.ts +27 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { randomUUIDv7 } from "bun";
|
|
2
|
+
import type {
|
|
3
|
+
AuditActionType,
|
|
4
|
+
NotificationInboxFilters,
|
|
5
|
+
UpdateNotificationPreferenceInput,
|
|
6
|
+
PublishNotificationInput,
|
|
7
|
+
UpdateNotificationInput,
|
|
8
|
+
} from "@southwind-ai/shared";
|
|
9
|
+
import { auditActor, type RequestGuardContext } from "../guards.js";
|
|
10
|
+
|
|
11
|
+
export type NotificationRouteContext = {
|
|
12
|
+
body?: unknown;
|
|
13
|
+
guardContext: RequestGuardContext;
|
|
14
|
+
params: Record<string, string | undefined>;
|
|
15
|
+
query: Record<string, string | undefined>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function parsePublishInput(
|
|
19
|
+
body: unknown,
|
|
20
|
+
): PublishNotificationInput | Response {
|
|
21
|
+
const content = parseContentInput(body);
|
|
22
|
+
if (content instanceof Response) return content;
|
|
23
|
+
const value = body as Record<string, unknown>;
|
|
24
|
+
const scheduledFor = optionalText(value.scheduledFor);
|
|
25
|
+
if (scheduledFor && !validFutureDate(scheduledFor)) {
|
|
26
|
+
return invalidNotification("scheduledFor 必须是未来的 ISO 时间");
|
|
27
|
+
}
|
|
28
|
+
const recipientUserIds = stringArray(value.recipientUserIds);
|
|
29
|
+
const recipientRoleCodes = stringArray(value.recipientRoleCodes);
|
|
30
|
+
const recipientDepartmentIds = stringArray(value.recipientDepartmentIds);
|
|
31
|
+
const deliveryChannels = stringArray(value.deliveryChannels);
|
|
32
|
+
if (
|
|
33
|
+
recipientUserIds instanceof Response ||
|
|
34
|
+
recipientRoleCodes instanceof Response ||
|
|
35
|
+
recipientDepartmentIds instanceof Response ||
|
|
36
|
+
deliveryChannels instanceof Response
|
|
37
|
+
) {
|
|
38
|
+
return invalidNotification("通知受众与渠道必须是字符串数组");
|
|
39
|
+
}
|
|
40
|
+
if (
|
|
41
|
+
deliveryChannels.some((channel) => channel !== "email" && channel !== "sms")
|
|
42
|
+
) {
|
|
43
|
+
return invalidNotification("deliveryChannels 仅支持 email 或 sms");
|
|
44
|
+
}
|
|
45
|
+
if (
|
|
46
|
+
[recipientUserIds, recipientRoleCodes, recipientDepartmentIds].some(
|
|
47
|
+
(values) => values.length > 100,
|
|
48
|
+
)
|
|
49
|
+
) {
|
|
50
|
+
return invalidNotification("单次发布的每类受众最多 100 项");
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
...content,
|
|
54
|
+
scheduledFor,
|
|
55
|
+
recipientUserIds,
|
|
56
|
+
recipientRoleCodes,
|
|
57
|
+
recipientDepartmentIds,
|
|
58
|
+
includeChildDepartments: value.includeChildDepartments === true,
|
|
59
|
+
deliveryChannels: deliveryChannels.filter(
|
|
60
|
+
(channel): channel is "email" | "sms" =>
|
|
61
|
+
channel === "email" || channel === "sms",
|
|
62
|
+
),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function parseUpdateInput(
|
|
67
|
+
body: unknown,
|
|
68
|
+
): UpdateNotificationInput | Response {
|
|
69
|
+
return parseContentInput(body);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function parsePreferenceInput(
|
|
73
|
+
body: unknown,
|
|
74
|
+
): UpdateNotificationPreferenceInput | Response {
|
|
75
|
+
const value =
|
|
76
|
+
body && typeof body === "object" ? (body as Record<string, unknown>) : {};
|
|
77
|
+
const enabledChannels = stringArray(value.enabledChannels);
|
|
78
|
+
const disabledCategories = stringArray(value.disabledCategories);
|
|
79
|
+
if (
|
|
80
|
+
enabledChannels instanceof Response ||
|
|
81
|
+
disabledCategories instanceof Response
|
|
82
|
+
) {
|
|
83
|
+
return invalidNotification("通知偏好必须是字符串数组");
|
|
84
|
+
}
|
|
85
|
+
if (
|
|
86
|
+
enabledChannels.some(
|
|
87
|
+
(channel) => channel !== "email" && channel !== "sms",
|
|
88
|
+
) ||
|
|
89
|
+
disabledCategories.length > 100 ||
|
|
90
|
+
disabledCategories.some((category) => category.length > 40)
|
|
91
|
+
) {
|
|
92
|
+
return invalidNotification("通知偏好包含不支持的渠道或分类");
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
enabledChannels: enabledChannels.filter(
|
|
96
|
+
(channel): channel is "email" | "sms" =>
|
|
97
|
+
channel === "email" || channel === "sms",
|
|
98
|
+
),
|
|
99
|
+
disabledCategories,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function parseInboxFilters(
|
|
104
|
+
query: Record<string, string | undefined>,
|
|
105
|
+
): NotificationInboxFilters | Response {
|
|
106
|
+
const q = query.q?.trim();
|
|
107
|
+
const category = query.category?.trim();
|
|
108
|
+
if (q && q.length > 200) return invalidFilter("q 最多 200 个字符");
|
|
109
|
+
if (category && category.length > 40)
|
|
110
|
+
return invalidFilter("category 最多 40 个字符");
|
|
111
|
+
if (query.read && query.read !== "read" && query.read !== "unread") {
|
|
112
|
+
return invalidFilter("read 仅支持 read 或 unread");
|
|
113
|
+
}
|
|
114
|
+
if (
|
|
115
|
+
query.favorite !== undefined &&
|
|
116
|
+
query.favorite !== "" &&
|
|
117
|
+
query.favorite !== "true" &&
|
|
118
|
+
query.favorite !== "false"
|
|
119
|
+
) {
|
|
120
|
+
return invalidFilter("favorite 仅支持 true 或 false");
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
q: q || undefined,
|
|
124
|
+
category: category || undefined,
|
|
125
|
+
read:
|
|
126
|
+
query.read === "read" || query.read === "unread" ? query.read : undefined,
|
|
127
|
+
favorite:
|
|
128
|
+
query.favorite === "true"
|
|
129
|
+
? true
|
|
130
|
+
: query.favorite === "false"
|
|
131
|
+
? false
|
|
132
|
+
: undefined,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function notificationEvent(
|
|
137
|
+
context: NotificationRouteContext,
|
|
138
|
+
action: AuditActionType,
|
|
139
|
+
id: string,
|
|
140
|
+
) {
|
|
141
|
+
return {
|
|
142
|
+
id: randomUUIDv7(),
|
|
143
|
+
action,
|
|
144
|
+
outcome: "success" as const,
|
|
145
|
+
actor: auditActor(context.guardContext),
|
|
146
|
+
target: { type: "notification", id },
|
|
147
|
+
requestId: context.guardContext.requestId,
|
|
148
|
+
occurredAt: new Date().toISOString(),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function notificationNotFound(id: string) {
|
|
153
|
+
return Response.json(
|
|
154
|
+
{ error: "NOT_FOUND", resource: "notification", id },
|
|
155
|
+
{ status: 404 },
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function parseContentInput(body: unknown): UpdateNotificationInput | Response {
|
|
160
|
+
const value =
|
|
161
|
+
body && typeof body === "object" ? (body as Record<string, unknown>) : {};
|
|
162
|
+
const input = {
|
|
163
|
+
title: text(value.title),
|
|
164
|
+
summary: text(value.summary),
|
|
165
|
+
content: text(value.content),
|
|
166
|
+
category: text(value.category),
|
|
167
|
+
};
|
|
168
|
+
if (!input.title || !input.summary || !input.content || !input.category) {
|
|
169
|
+
return Response.json(
|
|
170
|
+
{
|
|
171
|
+
error: "INVALID_NOTIFICATION",
|
|
172
|
+
message: "标题、摘要、正文和分类均不能为空",
|
|
173
|
+
},
|
|
174
|
+
{ status: 400 },
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
if (
|
|
178
|
+
input.title.length > 120 ||
|
|
179
|
+
input.summary.length > 240 ||
|
|
180
|
+
input.content.length > 10_000 ||
|
|
181
|
+
input.category.length > 40
|
|
182
|
+
) {
|
|
183
|
+
return Response.json(
|
|
184
|
+
{ error: "INVALID_NOTIFICATION", message: "通知内容超过长度限制" },
|
|
185
|
+
{ status: 400 },
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return input;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function invalidFilter(message: string) {
|
|
192
|
+
return Response.json(
|
|
193
|
+
{ error: "INVALID_NOTIFICATION_FILTER", message },
|
|
194
|
+
{ status: 400 },
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function invalidNotification(message: string) {
|
|
199
|
+
return Response.json(
|
|
200
|
+
{ error: "INVALID_NOTIFICATION", message },
|
|
201
|
+
{ status: 400 },
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function text(value: unknown) {
|
|
206
|
+
return typeof value === "string" ? value.trim() : "";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function optionalText(value: unknown) {
|
|
210
|
+
const result = text(value);
|
|
211
|
+
return result || undefined;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function stringArray(value: unknown): string[] | Response {
|
|
215
|
+
if (value === undefined) return [];
|
|
216
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
217
|
+
return invalidNotification("字段必须是字符串数组");
|
|
218
|
+
}
|
|
219
|
+
return [...new Set(value.map((item) => item.trim()).filter(Boolean))];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function validFutureDate(value: string) {
|
|
223
|
+
const timestamp = Date.parse(value);
|
|
224
|
+
return Number.isFinite(timestamp) && timestamp > Date.now();
|
|
225
|
+
}
|
|
@@ -15,6 +15,10 @@ class FakeRouteApp {
|
|
|
15
15
|
this.handlers.set(`POST ${path}`, handler);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
put(path: string, handler: (context: unknown) => unknown) {
|
|
19
|
+
this.handlers.set(`PUT ${path}`, handler);
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
delete(path: string, handler: (context: unknown) => unknown) {
|
|
19
23
|
this.handlers.set(`DELETE ${path}`, handler);
|
|
20
24
|
}
|
|
@@ -148,4 +152,182 @@ describe("站内通知闭环", () => {
|
|
|
148
152
|
|
|
149
153
|
expect(response.status).toBe(403);
|
|
150
154
|
});
|
|
155
|
+
|
|
156
|
+
test("收藏和取消收藏路由幂等且只审计真实状态变化", async () => {
|
|
157
|
+
const runtime = createServerRuntime({ WINDY_DEV_ADMIN_TOKEN: "token_1" });
|
|
158
|
+
const app = new FakeRouteApp();
|
|
159
|
+
registerNotificationRoutes(
|
|
160
|
+
app,
|
|
161
|
+
new InMemoryNotificationRepository(),
|
|
162
|
+
runtime,
|
|
163
|
+
createFoundationSnapshot().features,
|
|
164
|
+
);
|
|
165
|
+
const guardContext = await runtime.createGuardContext(
|
|
166
|
+
new Request("http://localhost/api/system/notifications", {
|
|
167
|
+
headers: { authorization: "Bearer token_1" },
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
const published = (await app.invoke("POST", "/system/notifications", {
|
|
171
|
+
guardContext,
|
|
172
|
+
params: {},
|
|
173
|
+
query: {},
|
|
174
|
+
body: {
|
|
175
|
+
title: "收藏测试",
|
|
176
|
+
summary: "收藏测试摘要",
|
|
177
|
+
content: "收藏测试正文",
|
|
178
|
+
category: "系统",
|
|
179
|
+
},
|
|
180
|
+
})) as { id: string };
|
|
181
|
+
|
|
182
|
+
const first = await app.invoke("PUT", "/notifications/:id/favorite", {
|
|
183
|
+
guardContext,
|
|
184
|
+
params: { id: published.id },
|
|
185
|
+
query: {},
|
|
186
|
+
});
|
|
187
|
+
const repeated = await app.invoke("PUT", "/notifications/:id/favorite", {
|
|
188
|
+
guardContext,
|
|
189
|
+
params: { id: published.id },
|
|
190
|
+
query: {},
|
|
191
|
+
});
|
|
192
|
+
const removed = await app.invoke("DELETE", "/notifications/:id/favorite", {
|
|
193
|
+
guardContext,
|
|
194
|
+
params: { id: published.id },
|
|
195
|
+
query: {},
|
|
196
|
+
});
|
|
197
|
+
const repeatedRemove = await app.invoke(
|
|
198
|
+
"DELETE",
|
|
199
|
+
"/notifications/:id/favorite",
|
|
200
|
+
{
|
|
201
|
+
guardContext,
|
|
202
|
+
params: { id: published.id },
|
|
203
|
+
query: {},
|
|
204
|
+
},
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
expect(first).toMatchObject({ favorite: true, changed: true });
|
|
208
|
+
expect(repeated).toMatchObject({ favorite: true, changed: false });
|
|
209
|
+
expect(removed).toEqual({
|
|
210
|
+
success: true,
|
|
211
|
+
favorite: false,
|
|
212
|
+
changed: true,
|
|
213
|
+
});
|
|
214
|
+
expect(repeatedRemove).toEqual({
|
|
215
|
+
success: true,
|
|
216
|
+
favorite: false,
|
|
217
|
+
changed: false,
|
|
218
|
+
});
|
|
219
|
+
expect(runtime.auditSink.list().map(({ action }) => action)).toEqual([
|
|
220
|
+
"notification.publish",
|
|
221
|
+
"notification.favorite",
|
|
222
|
+
"notification.unfavorite",
|
|
223
|
+
]);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("非法收件箱筛选被拒绝", async () => {
|
|
227
|
+
const runtime = createServerRuntime({ WINDY_DEV_ADMIN_TOKEN: "token_1" });
|
|
228
|
+
const app = new FakeRouteApp();
|
|
229
|
+
registerNotificationRoutes(
|
|
230
|
+
app,
|
|
231
|
+
new InMemoryNotificationRepository(),
|
|
232
|
+
runtime,
|
|
233
|
+
createFoundationSnapshot().features,
|
|
234
|
+
);
|
|
235
|
+
const guardContext = await runtime.createGuardContext(
|
|
236
|
+
new Request("http://localhost/api/notifications", {
|
|
237
|
+
headers: { authorization: "Bearer token_1" },
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const response = (await app.invoke("GET", "/notifications", {
|
|
242
|
+
guardContext,
|
|
243
|
+
params: {},
|
|
244
|
+
query: { read: "all", favorite: "yes" },
|
|
245
|
+
})) as Response;
|
|
246
|
+
|
|
247
|
+
expect(response.status).toBe(400);
|
|
248
|
+
expect(await response.json()).toMatchObject({
|
|
249
|
+
error: "INVALID_NOTIFICATION_FILTER",
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test("system.notification Feature 关闭时收件箱 Guard 拒绝", async () => {
|
|
254
|
+
const runtime = createServerRuntime(
|
|
255
|
+
{ WINDY_DEV_ADMIN_TOKEN: "token_1" },
|
|
256
|
+
{
|
|
257
|
+
featureResolver: {
|
|
258
|
+
resolve(key) {
|
|
259
|
+
return { key, enabled: false, visible: "hidden" };
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
);
|
|
264
|
+
const app = new FakeRouteApp();
|
|
265
|
+
registerNotificationRoutes(
|
|
266
|
+
app,
|
|
267
|
+
new InMemoryNotificationRepository(),
|
|
268
|
+
runtime,
|
|
269
|
+
createFoundationSnapshot().features,
|
|
270
|
+
);
|
|
271
|
+
const guardContext = await runtime.createGuardContext(
|
|
272
|
+
new Request("http://localhost/api/notifications", {
|
|
273
|
+
headers: { authorization: "Bearer token_1" },
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
const response = (await app.invoke("GET", "/notifications", {
|
|
278
|
+
guardContext,
|
|
279
|
+
params: {},
|
|
280
|
+
query: {},
|
|
281
|
+
})) as Response;
|
|
282
|
+
|
|
283
|
+
expect(response.status).toBe(403);
|
|
284
|
+
expect(await response.json()).toMatchObject({ reason: "feature-disabled" });
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
test("猜测不可见通知 ID 不能通过收藏 API 探测受众", async () => {
|
|
288
|
+
const runtime = createServerRuntime();
|
|
289
|
+
const repository = new InMemoryNotificationRepository();
|
|
290
|
+
const app = new FakeRouteApp();
|
|
291
|
+
registerNotificationRoutes(
|
|
292
|
+
app,
|
|
293
|
+
repository,
|
|
294
|
+
runtime,
|
|
295
|
+
createFoundationSnapshot().features,
|
|
296
|
+
);
|
|
297
|
+
const actor = {
|
|
298
|
+
id: "outsider",
|
|
299
|
+
type: "user" as const,
|
|
300
|
+
name: "外部用户",
|
|
301
|
+
roleCodes: ["guest"],
|
|
302
|
+
permissionKeys: ["system.notification.read"],
|
|
303
|
+
};
|
|
304
|
+
const guardContext = await runtime.createGuardContextForActor(
|
|
305
|
+
new Request("http://localhost/api/notifications/targeted/favorite"),
|
|
306
|
+
actor,
|
|
307
|
+
);
|
|
308
|
+
const targeted = await repository.publish(
|
|
309
|
+
{
|
|
310
|
+
title: "定向通知",
|
|
311
|
+
summary: "仅指定用户可见",
|
|
312
|
+
content: "不可通过 ID 猜测访问",
|
|
313
|
+
category: "审批",
|
|
314
|
+
recipientUserId: "recipient",
|
|
315
|
+
},
|
|
316
|
+
{ ...actor, id: "publisher" },
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
for (const method of ["PUT", "DELETE"]) {
|
|
320
|
+
const response = (await app.invoke(
|
|
321
|
+
method,
|
|
322
|
+
"/notifications/:id/favorite",
|
|
323
|
+
{
|
|
324
|
+
guardContext,
|
|
325
|
+
params: { id: targeted.id },
|
|
326
|
+
query: {},
|
|
327
|
+
},
|
|
328
|
+
)) as Response;
|
|
329
|
+
expect(response.status).toBe(404);
|
|
330
|
+
expect(await response.json()).toMatchObject({ error: "NOT_FOUND" });
|
|
331
|
+
}
|
|
332
|
+
});
|
|
151
333
|
});
|