@carlonicora/nja-todos 0.0.1 → 1.0.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 (215) hide show
  1. package/LICENSE +675 -0
  2. package/README.md +791 -2
  3. package/dist/api/common/decorate.d.ts +21 -0
  4. package/dist/api/common/decorate.d.ts.map +1 -0
  5. package/dist/api/common/decorate.js +39 -0
  6. package/dist/api/common/decorate.js.map +1 -0
  7. package/dist/api/config/todos.config.d.ts +51 -0
  8. package/dist/api/config/todos.config.d.ts.map +1 -0
  9. package/dist/api/config/todos.config.js +7 -0
  10. package/dist/api/config/todos.config.js.map +1 -0
  11. package/dist/api/events/todos.event.payloads.d.ts +21 -0
  12. package/dist/api/events/todos.event.payloads.d.ts.map +1 -0
  13. package/dist/api/events/todos.event.payloads.js +3 -0
  14. package/dist/api/events/todos.event.payloads.js.map +1 -0
  15. package/dist/api/index.d.ts +22 -0
  16. package/dist/api/index.d.ts.map +1 -0
  17. package/dist/api/index.js +49 -0
  18. package/dist/api/index.js.map +1 -0
  19. package/dist/api/notifications/todos.notification.processor.d.ts +48 -0
  20. package/dist/api/notifications/todos.notification.processor.d.ts.map +1 -0
  21. package/dist/api/notifications/todos.notification.processor.js +251 -0
  22. package/dist/api/notifications/todos.notification.processor.js.map +1 -0
  23. package/dist/api/notifications/todos.queue.d.ts +41 -0
  24. package/dist/api/notifications/todos.queue.d.ts.map +1 -0
  25. package/dist/api/notifications/todos.queue.js +35 -0
  26. package/dist/api/notifications/todos.queue.js.map +1 -0
  27. package/dist/api/task/controllers/task.controller.factory.d.ts +38 -0
  28. package/dist/api/task/controllers/task.controller.factory.d.ts.map +1 -0
  29. package/dist/api/task/controllers/task.controller.factory.js +314 -0
  30. package/dist/api/task/controllers/task.controller.factory.js.map +1 -0
  31. package/dist/api/task/dtos/task.dtos.d.ts +15 -0
  32. package/dist/api/task/dtos/task.dtos.d.ts.map +1 -0
  33. package/dist/api/task/dtos/task.dtos.js +260 -0
  34. package/dist/api/task/dtos/task.dtos.js.map +1 -0
  35. package/dist/api/task/entities/task.d.ts +21 -0
  36. package/dist/api/task/entities/task.d.ts.map +1 -0
  37. package/dist/api/task/entities/task.js +95 -0
  38. package/dist/api/task/entities/task.js.map +1 -0
  39. package/dist/api/task/entities/task.meta.d.ts +3 -0
  40. package/dist/api/task/entities/task.meta.d.ts.map +1 -0
  41. package/dist/api/task/entities/task.meta.js +11 -0
  42. package/dist/api/task/entities/task.meta.js.map +1 -0
  43. package/dist/api/task/repositories/task.repository.d.ts +104 -0
  44. package/dist/api/task/repositories/task.repository.d.ts.map +1 -0
  45. package/dist/api/task/repositories/task.repository.js +328 -0
  46. package/dist/api/task/repositories/task.repository.js.map +1 -0
  47. package/dist/api/task/services/task.service.d.ts +149 -0
  48. package/dist/api/task/services/task.service.d.ts.map +1 -0
  49. package/dist/api/task/services/task.service.js +378 -0
  50. package/dist/api/task/services/task.service.js.map +1 -0
  51. package/dist/api/taskcomment/controllers/taskcomment.controller.factory.d.ts +44 -0
  52. package/dist/api/taskcomment/controllers/taskcomment.controller.factory.d.ts.map +1 -0
  53. package/dist/api/taskcomment/controllers/taskcomment.controller.factory.js +136 -0
  54. package/dist/api/taskcomment/controllers/taskcomment.controller.factory.js.map +1 -0
  55. package/dist/api/taskcomment/dtos/taskcomment.post.dto.d.ts +23 -0
  56. package/dist/api/taskcomment/dtos/taskcomment.post.dto.d.ts.map +1 -0
  57. package/dist/api/taskcomment/dtos/taskcomment.post.dto.js +87 -0
  58. package/dist/api/taskcomment/dtos/taskcomment.post.dto.js.map +1 -0
  59. package/dist/api/taskcomment/dtos/taskcomment.put.dto.d.ts +21 -0
  60. package/dist/api/taskcomment/dtos/taskcomment.put.dto.d.ts.map +1 -0
  61. package/dist/api/taskcomment/dtos/taskcomment.put.dto.js +71 -0
  62. package/dist/api/taskcomment/dtos/taskcomment.put.dto.js.map +1 -0
  63. package/dist/api/taskcomment/entities/taskcomment.d.ts +11 -0
  64. package/dist/api/taskcomment/entities/taskcomment.d.ts.map +1 -0
  65. package/dist/api/taskcomment/entities/taskcomment.js +44 -0
  66. package/dist/api/taskcomment/entities/taskcomment.js.map +1 -0
  67. package/dist/api/taskcomment/entities/taskcomment.meta.d.ts +5 -0
  68. package/dist/api/taskcomment/entities/taskcomment.meta.d.ts.map +1 -0
  69. package/dist/api/taskcomment/entities/taskcomment.meta.js +13 -0
  70. package/dist/api/taskcomment/entities/taskcomment.meta.js.map +1 -0
  71. package/dist/api/taskcomment/repositories/taskcomment.repository.d.ts +25 -0
  72. package/dist/api/taskcomment/repositories/taskcomment.repository.d.ts.map +1 -0
  73. package/dist/api/taskcomment/repositories/taskcomment.repository.js +73 -0
  74. package/dist/api/taskcomment/repositories/taskcomment.repository.js.map +1 -0
  75. package/dist/api/taskcomment/services/taskcomment.service.d.ts +78 -0
  76. package/dist/api/taskcomment/services/taskcomment.service.d.ts.map +1 -0
  77. package/dist/api/taskcomment/services/taskcomment.service.js +190 -0
  78. package/dist/api/taskcomment/services/taskcomment.service.js.map +1 -0
  79. package/dist/api/todos.module.d.ts +20 -0
  80. package/dist/api/todos.module.d.ts.map +1 -0
  81. package/dist/api/todos.module.js +143 -0
  82. package/dist/api/todos.module.js.map +1 -0
  83. package/dist/chunk-CO56HIPE.mjs +283 -0
  84. package/dist/chunk-CO56HIPE.mjs.map +1 -0
  85. package/dist/chunk-K6KLDGC2.js +283 -0
  86. package/dist/chunk-K6KLDGC2.js.map +1 -0
  87. package/dist/seed/index.d.ts +4 -0
  88. package/dist/seed/index.d.ts.map +1 -0
  89. package/dist/seed/index.js +9 -0
  90. package/dist/seed/index.js.map +1 -0
  91. package/dist/seed/todos.module.seed.d.ts +12 -0
  92. package/dist/seed/todos.module.seed.d.ts.map +1 -0
  93. package/dist/seed/todos.module.seed.js +54 -0
  94. package/dist/seed/todos.module.seed.js.map +1 -0
  95. package/dist/shared/index.d.ts +7 -0
  96. package/dist/shared/index.d.ts.map +1 -0
  97. package/dist/shared/index.js +23 -0
  98. package/dist/shared/index.js.map +1 -0
  99. package/dist/shared/task.completed.filter.d.ts +2 -0
  100. package/dist/shared/task.completed.filter.d.ts.map +1 -0
  101. package/dist/shared/task.completed.filter.js +3 -0
  102. package/dist/shared/task.completed.filter.js.map +1 -0
  103. package/dist/shared/task.priority.d.ts +6 -0
  104. package/dist/shared/task.priority.d.ts.map +1 -0
  105. package/dist/shared/task.priority.js +10 -0
  106. package/dist/shared/task.priority.js.map +1 -0
  107. package/dist/shared/todos.endpoints.d.ts +7 -0
  108. package/dist/shared/todos.endpoints.d.ts.map +1 -0
  109. package/dist/shared/todos.endpoints.js +10 -0
  110. package/dist/shared/todos.endpoints.js.map +1 -0
  111. package/dist/shared/todos.events.d.ts +13 -0
  112. package/dist/shared/todos.events.d.ts.map +1 -0
  113. package/dist/shared/todos.events.js +16 -0
  114. package/dist/shared/todos.events.js.map +1 -0
  115. package/dist/shared/todos.module.ids.d.ts +5 -0
  116. package/dist/shared/todos.module.ids.d.ts.map +1 -0
  117. package/dist/shared/todos.module.ids.js +8 -0
  118. package/dist/shared/todos.module.ids.js.map +1 -0
  119. package/dist/shared/todos.notification.types.d.ts +6 -0
  120. package/dist/shared/todos.notification.types.d.ts.map +1 -0
  121. package/dist/shared/todos.notification.types.js +9 -0
  122. package/dist/shared/todos.notification.types.js.map +1 -0
  123. package/dist/web/config/todos.config.d.ts +25 -0
  124. package/dist/web/config/todos.config.d.ts.map +1 -0
  125. package/dist/web/config/todos.ui.config.d.ts +28 -0
  126. package/dist/web/config/todos.ui.config.d.ts.map +1 -0
  127. package/dist/web/core.d.ts +18 -0
  128. package/dist/web/core.d.ts.map +1 -0
  129. package/dist/web/core.js +208 -0
  130. package/dist/web/core.js.map +1 -0
  131. package/dist/web/core.mjs +208 -0
  132. package/dist/web/core.mjs.map +1 -0
  133. package/dist/web/index.d.ts +22 -0
  134. package/dist/web/index.d.ts.map +1 -0
  135. package/dist/web/index.js +1959 -0
  136. package/dist/web/index.js.map +1 -0
  137. package/dist/web/index.mjs +1958 -0
  138. package/dist/web/index.mjs.map +1 -0
  139. package/dist/web/task/TaskModule.d.ts +6 -0
  140. package/dist/web/task/TaskModule.d.ts.map +1 -0
  141. package/dist/web/task/components/EisenhowerIcon.d.ts +9 -0
  142. package/dist/web/task/components/EisenhowerIcon.d.ts.map +1 -0
  143. package/dist/web/task/components/EisenhowerMatrixBoard.d.ts +21 -0
  144. package/dist/web/task/components/EisenhowerMatrixBoard.d.ts.map +1 -0
  145. package/dist/web/task/components/TaskMatrixCard.d.ts +11 -0
  146. package/dist/web/task/components/TaskMatrixCard.d.ts.map +1 -0
  147. package/dist/web/task/components/containers/TaskListContainer.d.ts +12 -0
  148. package/dist/web/task/components/containers/TaskListContainer.d.ts.map +1 -0
  149. package/dist/web/task/components/editors/TaskEditor.d.ts +12 -0
  150. package/dist/web/task/components/editors/TaskEditor.d.ts.map +1 -0
  151. package/dist/web/task/components/filters/TaskListFilters.d.ts +9 -0
  152. package/dist/web/task/components/filters/TaskListFilters.d.ts.map +1 -0
  153. package/dist/web/task/components/filters/TaskViewSwitcher.d.ts +9 -0
  154. package/dist/web/task/components/filters/TaskViewSwitcher.d.ts.map +1 -0
  155. package/dist/web/task/components/forms/TaskCreateButton.d.ts +5 -0
  156. package/dist/web/task/components/forms/TaskCreateButton.d.ts.map +1 -0
  157. package/dist/web/task/components/forms/TaskDeleter.d.ts +8 -0
  158. package/dist/web/task/components/forms/TaskDeleter.d.ts.map +1 -0
  159. package/dist/web/task/components/lists/TasksList.d.ts +20 -0
  160. package/dist/web/task/components/lists/TasksList.d.ts.map +1 -0
  161. package/dist/web/task/components/screens/UserTasksScreen.d.ts +5 -0
  162. package/dist/web/task/components/screens/UserTasksScreen.d.ts.map +1 -0
  163. package/dist/web/task/contexts/TaskContext.d.ts +29 -0
  164. package/dist/web/task/contexts/TaskContext.d.ts.map +1 -0
  165. package/dist/web/task/data/Task.d.ts +25 -0
  166. package/dist/web/task/data/Task.d.ts.map +1 -0
  167. package/dist/web/task/data/TaskFields.d.ts +12 -0
  168. package/dist/web/task/data/TaskFields.d.ts.map +1 -0
  169. package/dist/web/task/data/TaskInterface.d.ts +29 -0
  170. package/dist/web/task/data/TaskInterface.d.ts.map +1 -0
  171. package/dist/web/task/data/TaskService.d.ts +51 -0
  172. package/dist/web/task/data/TaskService.d.ts.map +1 -0
  173. package/dist/web/task/hooks/useTaskDeepLink.d.ts +12 -0
  174. package/dist/web/task/hooks/useTaskDeepLink.d.ts.map +1 -0
  175. package/dist/web/task/hooks/useTaskOverdueParam.d.ts +19 -0
  176. package/dist/web/task/hooks/useTaskOverdueParam.d.ts.map +1 -0
  177. package/dist/web/task/hooks/useTaskTableStructure.d.ts +8 -0
  178. package/dist/web/task/hooks/useTaskTableStructure.d.ts.map +1 -0
  179. package/dist/web/task/lib/task.priority.options.d.ts +5 -0
  180. package/dist/web/task/lib/task.priority.options.d.ts.map +1 -0
  181. package/dist/web/task/utils/dueDate.d.ts +11 -0
  182. package/dist/web/task/utils/dueDate.d.ts.map +1 -0
  183. package/dist/web/task/utils/getEisenhowerQuadrant.d.ts +4 -0
  184. package/dist/web/task/utils/getEisenhowerQuadrant.d.ts.map +1 -0
  185. package/dist/web/task/utils/isTaskOverdue.d.ts +12 -0
  186. package/dist/web/task/utils/isTaskOverdue.d.ts.map +1 -0
  187. package/dist/web/taskcomment/TaskCommentModule.d.ts +5 -0
  188. package/dist/web/taskcomment/TaskCommentModule.d.ts.map +1 -0
  189. package/dist/web/taskcomment/components/forms/TaskCommentEditor.d.ts +2 -0
  190. package/dist/web/taskcomment/components/forms/TaskCommentEditor.d.ts.map +1 -0
  191. package/dist/web/taskcomment/components/lists/TaskCommentList.d.ts +2 -0
  192. package/dist/web/taskcomment/components/lists/TaskCommentList.d.ts.map +1 -0
  193. package/dist/web/taskcomment/contexts/TaskCommentContext.d.ts +22 -0
  194. package/dist/web/taskcomment/contexts/TaskCommentContext.d.ts.map +1 -0
  195. package/dist/web/taskcomment/data/TaskComment.d.ts +11 -0
  196. package/dist/web/taskcomment/data/TaskComment.d.ts.map +1 -0
  197. package/dist/web/taskcomment/data/TaskCommentInterface.d.ts +12 -0
  198. package/dist/web/taskcomment/data/TaskCommentInterface.d.ts.map +1 -0
  199. package/dist/web/taskcomment/data/TaskCommentService.d.ts +16 -0
  200. package/dist/web/taskcomment/data/TaskCommentService.d.ts.map +1 -0
  201. package/dist/web/todos.modules.d.ts +10 -0
  202. package/dist/web/todos.modules.d.ts.map +1 -0
  203. package/dist/web/utils/isNotFoundError.d.ts +11 -0
  204. package/dist/web/utils/isNotFoundError.d.ts.map +1 -0
  205. package/i18n/en/todos.json +13 -0
  206. package/i18n/it/todos.json +13 -0
  207. package/messages/en.json +132 -0
  208. package/messages/it.json +132 -0
  209. package/package.json +214 -5
  210. package/templates/email/en/taskAssigned.hbs +31 -0
  211. package/templates/email/en/taskCommented.hbs +31 -0
  212. package/templates/email/en/taskCompleted.hbs +31 -0
  213. package/templates/email/it/taskAssigned.hbs +31 -0
  214. package/templates/email/it/taskCommented.hbs +31 -0
  215. package/templates/email/it/taskCompleted.hbs +31 -0
package/README.md CHANGED
@@ -1,5 +1,794 @@
1
1
  # @carlonicora/nja-todos
2
2
 
3
- Placeholder release that reserves the package name. It contains no code.
3
+ Tasks and Task Comments for apps built on `@carlonicora/nestjs-neo4jsonapi` and `@carlonicora/nextjs-jsonapi`: a task list, an Eisenhower board, and an editor with notes, assignee, due date, priority and comments, plus in-app, push and email notifications. The app declares which of its own entities a task links to, once on the API and once on the web, and writes no task code.
4
4
 
5
- The first real release is 1.0.0: https://github.com/carlonicora/nja-todos
5
+ ## 1. What the package is
6
+
7
+ ### Requirements
8
+
9
+ | Requirement | Version or note |
10
+ |---|---|
11
+ | `@carlonicora/nestjs-neo4jsonapi` | 8.35.0 or later, the release that added `registerEmailTemplateDirectory` and `registerI18nDirectory` |
12
+ | `@carlonicora/nextjs-jsonapi` | 6.45.1 or later |
13
+ | A worker process | the API started in worker mode. Notifications and emails are sent by a queue processor that runs only there |
14
+ | Redis and Neo4j | Redis holds the queue. The libraries already need both |
15
+
16
+ ### Peer packages
17
+
18
+ The package has no `dependencies`. Every peer is optional: an app installs the peers of the half it uses, so the API image gets no React and the web image gets no NestJS.
19
+
20
+ <!-- options: peers -->
21
+
22
+ | Package | Range | Half |
23
+ |---|---|---|
24
+ | `@carlonicora/nestjs-neo4jsonapi` | `^8.35.0` | API |
25
+ | `@carlonicora/nextjs-jsonapi` | `^6.45.1` | Web |
26
+ | `@hookform/resolvers` | `^7.0.6` | Web |
27
+ | `@nestjs/bullmq` | `^12.0.2` | API |
28
+ | `@nestjs/common` | `^12.0.1` | API |
29
+ | `@nestjs/config` | `^12.0.0` | API |
30
+ | `@nestjs/core` | `^12.0.1` | API |
31
+ | `@nestjs/event-emitter` | `^12.0.0` | API |
32
+ | `@tanstack/react-table` | `>=8.0.0` | Web |
33
+ | `bullmq` | `^6.7.6` | API |
34
+ | `class-transformer` | `^0.5.1` | API |
35
+ | `class-validator` | `^0.15.1` | API |
36
+ | `date-fns` | `^4.4.0` | Web |
37
+ | `fastify` | `^5.12.8` | API |
38
+ | `lucide-react` | `^1.73.0` | Web |
39
+ | `nestjs-cls` | `^7.0.2` | API |
40
+ | `nestjs-i18n` | `^10.8.5` | API |
41
+ | `next` | `>=16.4.0` | Web |
42
+ | `next-intl` | `>=4.0.0` | Web |
43
+ | `react` | `>=19.3.0` | Web |
44
+ | `react-dom` | `>=19.3.0` | Web |
45
+ | `react-hook-form` | `>=7.0.0` | Web |
46
+ | `reflect-metadata` | `^0.2.2` | API |
47
+ | `rxjs` | `^7.8.2` | API |
48
+ | `uuid` | `^14.0.3` | Web |
49
+ | `zod` | `^4.4.3` | Web |
50
+
51
+ ### Entry points
52
+
53
+ | Import | Holds | Safe in server code |
54
+ |---|---|---|
55
+ | `@carlonicora/nja-todos/api` | `TodosModule`, the configuration types, services, repositories, metas, event names and payload types, queue names, the seed helper | API only |
56
+ | `@carlonicora/nja-todos/web/core` | models, interfaces, services, `configureTodos`, `TaskModule` / `TaskCommentModule`, the shared constants | Yes, also in the bootstrapper |
57
+ | `@carlonicora/nja-todos/web` | client components, contexts, hooks, `configureTodosUi` | No, it is a `"use client"` bundle |
58
+ | `@carlonicora/nja-todos/seed` | `todosModuleSeedQueries`, `TODOS_MODULE_IDS`. It imports nothing from the libraries, so a migration file can load it | API side |
59
+ | `@carlonicora/nja-todos/messages/*` | the web message files `en.json` and `it.json` | Raw JSON |
60
+
61
+ The shared constants (`TaskPriority`, `TODOS_MODULE_IDS`, `TASK_ENDPOINT`, `TASK_COMMENT_ENDPOINT`, `TaskCompletedFilter`, `TodosNotificationType`, `TodosEvent`) are exported from both `/api` and `/web/core`.
62
+
63
+ ## 2. Adding it to the repository
64
+
65
+ ### The submodule
66
+
67
+ ```sh
68
+ git submodule add https://github.com/carlonicora/nja-todos packages/nja-todos
69
+ ```
70
+
71
+ The workspace already globs `packages/*`.
72
+
73
+ The package declares its development copies of the two libraries as version ranges, so it also builds on its own in its repository. Inside the monorepo those ranges link to the library submodules only when `pnpm-workspace.yaml` sets `linkWorkspacePackages: true` (pnpm 11 and later ignore `link-workspace-packages` in `.npmrc`). Without it pnpm installs a second copy of each library from npm.
74
+
75
+ ### The dependency in each app
76
+
77
+ Add the package to `dependencies` of the API app and of the web app:
78
+
79
+ ```json
80
+ {
81
+ "dependencies": {
82
+ "@carlonicora/nja-todos": "workspace:*"
83
+ }
84
+ }
85
+ ```
86
+
87
+ Then add every peer of that half from the table above that the app does not already declare, and run `pnpm install`. With `workspace:*` the app and the package resolve the same copy of each library, which the permission audit and the model registry require: they work only with one instance.
88
+
89
+ ### Files that list the libraries by name
90
+
91
+ | File | What to add |
92
+ |---|---|
93
+ | `.gitmodules` | written by `git submodule add` |
94
+ | `turbo.json` | in each app build task that depends on the libraries' build, add `@carlonicora/nja-todos#build` |
95
+ | The dependency drift check script | read the package's manifest, check each app against its peers, and add the package to the production pin check |
96
+ | `Dockerfile` | copy and build `packages/nja-todos` wherever the stages copy and build the two libraries. The production stage installs it from npm, like them |
97
+ | CI workflows that remove the submodules from the workspace so published versions install | add the package to the same edit |
98
+ | The dependency update check script | add the package to its list of libraries |
99
+ | The web app's stylesheet | the two `@source` lines in Styles (section 4) |
100
+ | The web app's translation check | add `@carlonicora/nja-todos/messages` as a fallback messages folder and the package's `src/web` as a scanned source folder |
101
+ | `pnpm-workspace.yaml` | add the package to the comment that names the published submodules, and make sure `linkWorkspacePackages: true` is set (see The submodule) |
102
+
103
+ ### The production version pin
104
+
105
+ Run `pnpm sync:versions`. It writes every publishable workspace package an app depends on, at its `package.json` version, into `versions.production.json`. That version must be on npm before a production image is built.
106
+
107
+ ## 3. Wiring the API
108
+
109
+ ### Import TodosModule.forRoot
110
+
111
+ Declare the links once:
112
+
113
+ <!-- example: examples/api/todos.relationships.ts -->
114
+ ```ts
115
+ import type { TodosRelationshipConfig } from "@carlonicora/nja-todos/api";
116
+ import { documentMeta } from "src/features/document/entities/document.meta";
117
+ import { personMeta } from "src/features/person/entities/person.meta";
118
+ import { projectMeta } from "src/features/project/entities/project.meta";
119
+
120
+ export const todosRelationships: TodosRelationshipConfig[] = [
121
+ {
122
+ key: "project",
123
+ model: projectMeta,
124
+ relationship: "PART_OF",
125
+ direction: "out",
126
+ cardinality: "one",
127
+ required: true,
128
+ immutable: true,
129
+ description: "The project this task belongs to.",
130
+ reverse: { name: "tasks", description: "The tasks of this project.", cardinality: "many" },
131
+ },
132
+ {
133
+ key: "people",
134
+ model: personMeta,
135
+ relationship: "CONCERNS",
136
+ direction: "out",
137
+ cardinality: "many",
138
+ dtoKey: "persons",
139
+ },
140
+ {
141
+ key: "sourceDocument",
142
+ model: documentMeta,
143
+ relationship: "EXTRACTED_FROM",
144
+ direction: "out",
145
+ cardinality: "one",
146
+ readOnly: true,
147
+ },
148
+ ];
149
+ ```
150
+
151
+ Import `TodosModule.forRoot` once, in the module that collects the app's feature modules:
152
+
153
+ <!-- example: examples/api/todos.module.ts -->
154
+ ```ts
155
+ import { ModuleACL, UserModule } from "@carlonicora/nestjs-neo4jsonapi";
156
+ import { TODOS_MODULE_IDS, TodosModule } from "@carlonicora/nja-todos/api";
157
+ import { Module, UseGuards } from "@nestjs/common";
158
+ import type { Project } from "src/features/project/entities/project";
159
+ import { ProjectMemberGuard } from "src/features/project/guards/project-member.guard";
160
+ import { ProjectModule } from "src/features/project/project.module";
161
+ import { todosRelationships } from "./todos.relationships";
162
+
163
+ const projectMember = [UseGuards(ProjectMemberGuard)];
164
+
165
+ @Module({
166
+ imports: [
167
+ TodosModule.forRoot({
168
+ relationships: todosRelationships,
169
+ taskPath: (task) => `/projects/${(task.project as Project).id}/tasks?task=${task.id}`,
170
+ catalogue: {
171
+ task: "A to-do item of a project, with an assignee, a due date and a priority.",
172
+ comment: "A comment written on a task.",
173
+ },
174
+ decorators: {
175
+ task: {
176
+ controller: [ModuleACL({ module: TODOS_MODULE_IDS.Task })],
177
+ routes: { create: projectMember, readOne: projectMember, update: projectMember, delete: projectMember },
178
+ relatedList: { project: projectMember },
179
+ },
180
+ comment: {
181
+ controller: [ModuleACL({ module: TODOS_MODULE_IDS.TaskComment })],
182
+ routes: { create: projectMember, update: projectMember, delete: projectMember },
183
+ },
184
+ },
185
+ imports: [UserModule, ProjectModule],
186
+ }),
187
+ ],
188
+ })
189
+ export class FeaturesModule {}
190
+ ```
191
+
192
+ `forRoot` builds the Task and Task Comment descriptors, the request DTO classes and the controllers from the configuration when it is called. Nothing is built at import time. It also registers the package's email-template and API-text folders with the library, registers both descriptors in the model registry on module init, and exports `TaskService` and `TaskCommentService` to the whole app. The repositories are not exported: app code goes through the services, which apply the task read rule and the comment-author check.
193
+
194
+ ### Configuration options
195
+
196
+ <!-- options: apiModule -->
197
+
198
+ | Option | Type | Default | What it does |
199
+ |---|---|---|---|
200
+ | `relationships` | `TodosRelationshipConfig[]` | required | the app entities a task links to, one entry per link (next table) |
201
+ | `taskPath` | `(task: Task) => string` | required | path inside the app, starting with `/`, that opens a task. Links are properties named by their key (`task.project`). The in-app notification keeps the path; emails and push prepend the app URL from the library's app configuration |
202
+ | `catalogue` | `{ task: string; comment: string }` | none | descriptions for the graph catalogue. Without them neither entity enters it |
203
+ | `decorators` | `{ task?: TodosControllerDecorators; comment?: TodosControllerDecorators }` | none | guards and decorators the app attaches (see Guards and decorators) |
204
+ | `imports` | `Array<Type<unknown> \| DynamicModule \| ForwardReference>` | `[]` | modules the attached guards need, and the module that exports `UserService`: the library `UserModule`, or the app's own user module when it replaces it. The package does not import `UserModule` itself; without a `UserService` the app does not boot |
205
+
206
+ Each entry of `relationships`:
207
+
208
+ <!-- options: apiRelationship -->
209
+
210
+ | Option | Type | Default | What it does |
211
+ |---|---|---|---|
212
+ | `key` | `string` | required | relationship key on the task: the JSON:API relationship name and the property name |
213
+ | `model` | `DataMeta` | required | the linked entity's meta |
214
+ | `relationship` | `string` | required | Neo4j edge type |
215
+ | `direction` | `"in" \| "out"` | required | `out` is `(task)-[:EDGE]->(entity)` |
216
+ | `cardinality` | `"one" \| "many"` | required | one linked entity, or a list |
217
+ | `required` | `boolean` | `false` | must be present on create and on `PATCH …/relationships`. When false, tasks without the link still show |
218
+ | `immutable` | `boolean` | `false` | set on create, never changed by PUT. A different value on `PATCH …/relationships` is refused with 400 |
219
+ | `readOnly` | `boolean` | `false` | never accepted from a request and never removed by PUT or `PATCH …/relationships`. App code sets it with `TaskService.setReadOnlyLink` |
220
+ | `access` | `"company" \| ((aliases: { linked: string; currentUser: string }) => string)` | none | who sees a task through this link: `"company"` means every user of the company; a function means the users for whom its `WHERE …` condition holds; left out, the link grants no access (see Who sees a task) |
221
+ | `dtoKey` | `string` | `key` | name of the relationship in request bodies, when it differs from `key` |
222
+ | `description` | `string` | none | the link's description in the graph catalogue |
223
+ | `reverse` | `{ name: string; description: string; cardinality?: "one" \| "many" }` | none | the same link seen from the linked entity, for the graph catalogue |
224
+
225
+ A linked id from another company is refused with 400 on every route.
226
+
227
+ App code sets a read-only link through `TaskService`:
228
+
229
+ <!-- example: examples/api/document-task.linker.ts -->
230
+ ```ts
231
+ import { TaskService } from "@carlonicora/nja-todos/api";
232
+ import { Injectable } from "@nestjs/common";
233
+
234
+ @Injectable()
235
+ export class DocumentTaskLinker {
236
+ constructor(private readonly taskService: TaskService) {}
237
+
238
+ async linkSource(params: { taskId: string; documentId: string }): Promise<void> {
239
+ await this.taskService.setReadOnlyLink({ taskId: params.taskId, key: "sourceDocument", ids: [params.documentId] });
240
+ }
241
+ }
242
+ ```
243
+
244
+ ### Who sees a task
245
+
246
+ A user sees a task they created, a task assigned to them, or a task linked through a relationship whose `access` admits them. Tasks of another company are never seen.
247
+
248
+ Each relationship says how access to the linked record is decided:
249
+
250
+ - `access: "company"` makes every task linked through it visible to every user of the company.
251
+ - An access function receives the Cypher aliases of the linked record (`linked`) and of the current user (`currentUser`) and returns one `WHERE …` clause, true when that user may access that record. The package places it inside `EXISTS { MATCH (task)-[:EDGE]->(linked:Label) <your clause> }`. The clause may hold nested `EXISTS { … }` subqueries and never `RETURN`; anything else is refused with an error when the query is built.
252
+ - Left out, the link grants no access.
253
+
254
+ A user who cannot see a task gets "not found" when reading it, changing it, and on its comments. Background jobs (the queue processor, `isAutomatedJob` in the request context) are not subject to the rule. With no user in the request context nothing is seen.
255
+
256
+ One example of each form:
257
+
258
+ <!-- example: examples/api/todos.access.ts -->
259
+ ```ts
260
+ import type { TodosRelationshipConfig } from "@carlonicora/nja-todos/api";
261
+ import { projectMeta } from "src/features/project/entities/project.meta";
262
+
263
+ // Every user of the company sees a task linked to a project.
264
+ export const projectSeenByCompany: TodosRelationshipConfig = {
265
+ key: "project",
266
+ model: projectMeta,
267
+ relationship: "PART_OF",
268
+ direction: "out",
269
+ cardinality: "one",
270
+ access: "company",
271
+ };
272
+
273
+ // Only the members of the project see a task linked to it.
274
+ export const projectSeenByMembers: TodosRelationshipConfig = {
275
+ ...projectSeenByCompany,
276
+ access: ({ linked, currentUser }) => `WHERE (${currentUser})-[:MEMBER_OF]->(${linked})`,
277
+ };
278
+ ```
279
+
280
+ For a relationship declared with `direction: "in"` the package builds the same check with the arrow reversed: `(task)<-[:EDGE]-(linked:Label)`.
281
+
282
+ ### Routes
283
+
284
+ | Route | Route kind | Does |
285
+ |---|---|---|
286
+ | `GET tasks` | list | company's tasks; `search`, `completedFilter` (default open, `completed`, `overdue`, `all`), `filterPriority`, `sort` |
287
+ | `GET <linked endpoint>/:<key>Id/tasks` | list | tasks linked to that entity, one route per configured relationship: with the example above, `GET projects/:projectId/tasks`, `GET persons/:peopleId/tasks` and `GET documents/:sourceDocumentId/tasks`; same filters |
288
+ | `GET users/:userId/tasks?creator=` | list | tasks assigned to that user, or created by them with `creator=true` (any other value lists the assigned ones) |
289
+ | `GET tasks/:taskId` | readOne | one task; logs a read audit entry |
290
+ | `POST tasks` | create | create; an id that already exists is refused with 409 |
291
+ | `PUT tasks/:taskId` | update | replace all fields and all changeable links (never the creator, an immutable link or a read-only link). Not used by the package's screens |
292
+ | `PATCH tasks/:taskId` | update | change only the fields sent, `completed` included; a field sent as null is cleared (due date, priority). Links are not changed here |
293
+ | `PATCH tasks/:taskId/relationships` | update | replace the task's configured links: a link left out is removed, a required one must be present. Read-only links are never touched; an immutable one sent with a different value is refused with 400 |
294
+ | `PATCH tasks/:taskId/toggle-complete` | update | complete / reopen; the wanted value is sent, so a repeat changes nothing |
295
+ | `PATCH tasks/:taskId/assignee/:assigneeId` | update | set the assignee |
296
+ | `DELETE tasks/:taskId/assignee` | update | clear the assignee |
297
+ | `DELETE tasks/:taskId` | delete | delete the task and its comments |
298
+ | `GET tasks/:taskId/taskcomments` | list | a task's comments, oldest first |
299
+ | `POST taskcomments` | create | add a comment to a task; the task is named at `data.relationships.task.data.id` |
300
+ | `PUT taskcomments/:taskCommentId`, `DELETE taskcomments/:taskCommentId` | update, delete | edit the text of / delete a comment; only its author, 403 for anyone else. PUT names the comment's task at `data.relationships.task.data.id`; another task is refused with 400 |
301
+
302
+ List filters: `search`; `completedFilter`, absent for open tasks, or `completed`, `overdue`, `all`; `filterPriority`; `sort`. Every route carries `JwtAuthGuard`. A write invalidates the cached task lists and the cached copy of each linked entity.
303
+
304
+ ### Module ids, seed migration and permissions
305
+
306
+ | Module | Id | Constant |
307
+ |---|---|---|
308
+ | Task | `d9f53925-ad69-4abb-abd0-ef39a836593f` | `TODOS_MODULE_IDS.Task` |
309
+ | Task Comment | `aca5c9c5-7ccd-424a-a8a5-88bb013bd1e0` | `TODOS_MODULE_IDS.TaskComment` |
310
+
311
+ Record both ids in the app's own module-id list, the enum or constant its permission file uses.
312
+
313
+ Save this as a new file in the app's `neo4j.migrations` folder (`<yyyymmdd>_<nnn>.ts`). It creates the two Module nodes under the Feature id passed (`IN_FEATURE`), so the sections are visible to every company with that feature.
314
+
315
+ <!-- example: examples/api/todos.migration.ts -->
316
+ ```ts
317
+ import type { MigrationInterface } from "@carlonicora/nestjs-neo4jsonapi";
318
+ import { todosModuleSeedQueries } from "@carlonicora/nja-todos/seed";
319
+ import { CORE_FEATURE_ID } from "src/config/feature.ids";
320
+
321
+ export const migration: MigrationInterface[] = todosModuleSeedQueries({ featureId: CORE_FEATURE_ID });
322
+ ```
323
+
324
+ Grants stay in the app's permission file: add read, create, update and delete grants for both module ids for each role. If the app keeps a map from a module to its related modules (for permission screens), add `Task` (related: `TaskComment` and each linked entity's module) and `TaskComment` (related: `Task`).
325
+
326
+ ### Guards and decorators
327
+
328
+ <!-- options: apiDecorators -->
329
+
330
+ | Option | Type | Default | What it does |
331
+ |---|---|---|---|
332
+ | `controller` | `ClassDecorator[]` | `[]` | applied to the controller class, so to all its routes |
333
+ | `routes` | `Partial<Record<TodosRouteKind, MethodDecorator[]>>` | `{}` | applied to every route of that kind (`create`, `readOne`, `list`, `update`, `delete`; see the Routes table) |
334
+ | `relatedList` | `Record<string, MethodDecorator[]>` | `{}` | extra decorators for the `GET <linked endpoint>/:<key>Id/tasks` route of the relationship with that key, added after `routes.list` |
335
+
336
+ The same shape is passed for tasks (`decorators.task`) and for comments (`decorators.comment`). A guard that needs providers from an app module goes in `imports`.
337
+
338
+ **Warning.** An app that starts the library with the permission gate on (`permissions: { enforce: true }`) must pass `ModuleACL({ module: TODOS_MODULE_IDS.Task })` in `decorators.task.controller` and `ModuleACL({ module: TODOS_MODULE_IDS.TaskComment })` in `decorators.comment.controller`. The boot audit, in the API and in the worker, refuses to start when a session-guarded write route has no section.
339
+
340
+ ### What the package writes to the graph
341
+
342
+ | Written | From → to | Key |
343
+ |---|---|---|
344
+ | `Task` label | | |
345
+ | `TaskComment` label | | |
346
+ | `BELONGS_TO` | Task → Company, TaskComment → Company (written by the library, company scoping) | |
347
+ | `CREATED_BY` | Task → User | `owner` |
348
+ | `ASSIGNED_TO` | Task → User | `assignee` |
349
+ | `HAS_COMMENT` | Task → TaskComment | |
350
+ | `AUTHORED_BY` | TaskComment → User | `owner` |
351
+ | each configured `relationship` | Task → entity, or entity → Task, by its `direction` | its `key` |
352
+
353
+ Code of the app that walks the graph by a fixed list of edge types (cascade deletes, locks, clones, exports, image cleanup) needs the configured edge (task → entity) and `HAS_COMMENT` (task → comments). A clone or export that throws on an unknown label must skip or handle `Task` and `TaskComment`.
354
+
355
+ ### Events
356
+
357
+ | Event | Constant | Emitted when | Payload |
358
+ |---|---|---|---|
359
+ | `todos.task.created` | `TodosEvent.TaskCreated` | a task is created | `TodosTaskEventPayload` |
360
+ | `todos.task.updated` | `TodosEvent.TaskUpdated` | name, notes, priority or due date change | `TodosTaskEventPayload` |
361
+ | `todos.task.completed` | `TodosEvent.TaskCompleted` | `completed` flips to true, by any route | `TodosTaskEventPayload` |
362
+ | `todos.task.reopened` | `TodosEvent.TaskReopened` | `completed` flips to false, by any route | `TodosTaskEventPayload` |
363
+ | `todos.task.assignee_changed` | `TodosEvent.TaskAssigneeChanged` | the assignee is set, changed or cleared, by any route | `TodosTaskEventPayload` |
364
+ | `todos.task.links_changed` | `TodosEvent.TaskLinksChanged` | a configured link is added or removed | `TodosTaskEventPayload` |
365
+ | `todos.task.deleted` | `TodosEvent.TaskDeleted` | a task is deleted | `TodosTaskEventPayload` |
366
+ | `todos.comment.created` | `TodosEvent.CommentCreated` | a comment is added | `TodosCommentEventPayload` |
367
+ | `todos.comment.updated` | `TodosEvent.CommentUpdated` | a comment is edited | `TodosCommentEventPayload` |
368
+ | `todos.comment.deleted` | `TodosEvent.CommentDeleted` | a comment is deleted | `TodosCommentEventPayload` |
369
+
370
+ `TodosTaskEventPayload`:
371
+
372
+ | Field | Type | Meaning |
373
+ |---|---|---|
374
+ | `task` | `Task` | the task after the change; before it, for `deleted` |
375
+ | `previous` | `Task \| undefined` | the task before the change; absent on `created` |
376
+ | `actorId` | `string` | the user who made the change |
377
+ | `companyId` | `string` | the company of the task |
378
+ | `changes` | `string[]` | names of the changed fields and link keys |
379
+
380
+ `TodosCommentEventPayload`:
381
+
382
+ | Field | Type | Meaning |
383
+ |---|---|---|
384
+ | `comment` | `TaskComment` | the comment after the change; before it, for `deleted` |
385
+ | `previous` | `TaskComment \| undefined` | the comment before the change; present on `updated` only |
386
+ | `taskId` | `string` | the task the comment belongs to |
387
+ | `actorId` | `string` | the user who made the change |
388
+ | `companyId` | `string` | the company of the task |
389
+ | `changes` | `string[]` | names of the changed fields (`content` on `updated`); empty on `created` and `deleted` |
390
+
391
+ A listener:
392
+
393
+ <!-- example: examples/api/task-activity.listener.ts -->
394
+ ```ts
395
+ import { TodosEvent, type TodosTaskEventPayload } from "@carlonicora/nja-todos/api";
396
+ import { Injectable } from "@nestjs/common";
397
+ import { OnEvent } from "@nestjs/event-emitter";
398
+ import { ActivityService } from "src/features/activity/services/activity.service";
399
+
400
+ @Injectable()
401
+ export class TaskActivityListener {
402
+ constructor(private readonly activityService: ActivityService) {}
403
+
404
+ @OnEvent(TodosEvent.TaskCompleted)
405
+ async onTaskCompleted(payload: TodosTaskEventPayload): Promise<void> {
406
+ await this.activityService.record({ entityId: payload.task.id, actorId: payload.actorId, action: "completed" });
407
+ }
408
+ }
409
+ ```
410
+
411
+ Events go through `@nestjs/event-emitter`. An app whose root module is built with the library's app module factory has it already (`EventEmitterModule.forRoot()` in `bootstrap/app.module.factory.ts`); an app that builds its own root module imports `EventEmitterModule.forRoot()` itself. A listener is an ordinary provider of any app module.
412
+
413
+ ### Notifications and emails
414
+
415
+ | Job | Fired when | Who is told |
416
+ |---|---|---|
417
+ | `task_assigned` | a task gets an assignee who is not the actor: on create, or on any later change of assignee | the new assignee |
418
+ | `task_completed` | a task is completed | assignee, creator and every comment author, minus the actor |
419
+ | `task_commented_on` | a comment is added | the same set, minus the actor |
420
+
421
+ Each recipient gets an in-app notification (its link is `taskPath`), a push if they have a subscription, a websocket message, and an email (`taskAssigned`, `taskCompleted`, `taskCommented`) in the recipient's saved language (a recipient with none gets the language of the request that caused it, then the email default locale), addressed by the recipient's name. The emails print no app name of their own: the app's `header` and `footer` partials carry the brand. The jobs run on the queue `nja-todos` (`TODOS_QUEUE`), processed only in the worker. A job delivered twice notifies nobody twice.
422
+
423
+ **Overriding a template.** Put a file with the same name in the app's `templates/email/<locale>/`: the app folder is searched before the package's. Start from the package's copy in `node_modules/@carlonicora/nja-todos/templates/email/<locale>/` and keep the variables it uses.
424
+
425
+ **Overriding an API text.** Add the key to the app's API translations, namespace `todos` (file `<locale>/todos.json`). The app's keys win.
426
+
427
+ | Key (namespace `todos`) | Used for |
428
+ |---|---|
429
+ | `notification.task_assigned.title` | push title of `task_assigned` |
430
+ | `notification.task_assigned.message` | push body of `task_assigned` |
431
+ | `notification.task_completed.title` | push title of `task_completed` |
432
+ | `notification.task_completed.message` | push body of `task_completed` |
433
+ | `notification.task_commented_on.title` | push title of `task_commented_on` |
434
+ | `notification.task_commented_on.message` | push body of `task_commented_on` |
435
+ | `notification.unknown_actor` | the actor's name when the actor cannot be read |
436
+ | `email.taskAssigned.subject` | subject of the `taskAssigned` email |
437
+ | `email.taskCompleted.subject` | subject of the `taskCompleted` email |
438
+ | `email.taskCommented.subject` | subject of the `taskCommented` email |
439
+
440
+ The texts of the notification bell are web messages (see Texts).
441
+
442
+ ## 4. Wiring the web app
443
+
444
+ ### Register the modules
445
+
446
+ <!-- example: examples/web/todos.modules.ts -->
447
+ ```ts
448
+ import { TaskCommentModule, TaskModule } from "@carlonicora/nja-todos/web/core";
449
+ import { moduleFactory } from "@/config/moduleFactory";
450
+
451
+ // Spread into the object your bootstrapper registers, under exactly these two keys.
452
+ export const todosModules = {
453
+ Task: TaskModule(moduleFactory, { pageUrl: "/tasks" }),
454
+ TaskComment: TaskCommentModule(moduleFactory),
455
+ };
456
+ ```
457
+
458
+ Spread `todosModules` (or write the two entries) into the object the app registers with `ModuleRegistry` and `DataClassRegistry`. The keys must be `Task` and `TaskComment`; the module names are `tasks` and `taskcomments`.
459
+
460
+ The package does not touch the library's module typings. The app types `Task` and `TaskComment` in its own `AppModuleDefinitions` augmentation, like its other modules; an augmentation derived from the registered modules object picks them up with no edit.
461
+
462
+ `TaskModule` options:
463
+
464
+ <!-- options: webTaskModule -->
465
+
466
+ | Option | Type | Default | What it does |
467
+ |---|---|---|---|
468
+ | `feature` | `string` | none | feature id the module belongs to |
469
+ | `pageUrl` | `string` | none | the standalone tasks page; set it only when the app has one |
470
+
471
+ `TaskCommentModule` takes `feature` only:
472
+
473
+ <!-- options: webTaskCommentModule -->
474
+
475
+ | Option | Type | Default | What it does |
476
+ |---|---|---|---|
477
+ | `feature` | `string` | none | feature id the comment module belongs to |
478
+
479
+ ### Styles
480
+
481
+ The components style themselves with Tailwind classes, and Tailwind only generates the classes it finds in the files it scans. Add the package to the app's stylesheet next to the library's `@source` lines, or classes used only by the package are missing (the comment box's button, for one, cannot be clicked). The package publishes `dist` only, so production scans the compiled files:
482
+
483
+ ```css
484
+ /* workspace submodule, in development */
485
+ @source "../../../../packages/nja-todos/src/web/**/*.{ts,tsx}";
486
+ /* npm package, in production */
487
+ @source "../../node_modules/@carlonicora/nja-todos/dist/web/**/*.{js,mjs}";
488
+ ```
489
+
490
+ The paths are relative to the stylesheet; these two fit `apps/web/src/app/globals.css`.
491
+
492
+ ### Configure the package
493
+
494
+ `configureTodos` is safe on the server. Call it where the app's other `configure…` calls live, in the file loaded both on the server and in the browser. The configuration is kept on `globalThis`, so the two builds of the package share it.
495
+
496
+ <!-- example: examples/web/todos.config.ts -->
497
+ ```ts
498
+ import { configureTodos } from "@carlonicora/nja-todos/web/core";
499
+ import { Modules } from "@carlonicora/nextjs-jsonapi/core";
500
+
501
+ configureTodos({
502
+ relationships: [
503
+ { key: "project", module: () => Modules.Project, cardinality: "one", required: true, immutable: true },
504
+ { key: "people", module: () => Modules.Person, cardinality: "many", dtoKey: "persons" },
505
+ { key: "sourceDocument", module: () => Modules.Document, cardinality: "one", readOnly: true },
506
+ ],
507
+ taskPath: (task) => `/projects/${task.related("project")?.id}/tasks?task=${task.id}`,
508
+ pageUrl: "/tasks",
509
+ });
510
+ ```
511
+
512
+ <!-- options: webConfig -->
513
+
514
+ | Option | Type | Default | What it does |
515
+ |---|---|---|---|
516
+ | `relationships` | `TodosWebRelationshipConfig[]` | required | the same links as on the API, by the same keys |
517
+ | `taskPath` | `(task: TaskInterface) => string \| undefined` | none | path that opens a task. Without it, or when it returns `undefined` for a task, the editor shows no "Copy link" |
518
+ | `pageUrl` | `string` | none | the standalone tasks page. With it, deleting a task from an editor with no `scope` returns to that page; an editor opened on a record's page (with `scope`) stays where it is. With it, the unscoped page also gets the Tasks breadcrumb and title; a scoped page keeps its record page's breadcrumb and title. Without it the package renders no link to a module page (no breadcrumb, no redirect after delete) |
519
+
520
+ Each entry of `relationships`:
521
+
522
+ <!-- options: webRelationship -->
523
+
524
+ | Option | Type | Default | What it does |
525
+ |---|---|---|---|
526
+ | `key` | `string` | required | the relationship key, as on the API |
527
+ | `module` | `() => ModuleWithPermissions` | required | the linked module. A function, because `Modules.X` cannot be read before bootstrap |
528
+ | `cardinality` | `"one" \| "many"` | required | as on the API |
529
+ | `required` | `boolean` | `false` | the editor will not create a task without it. A `one` link: Create stays disabled until it is filled, and is hidden on a page that can neither prefill it (scope) nor pick it (selector) |
530
+ | `immutable` | `boolean` | `false` | its selector is disabled once the task is saved |
531
+ | `readOnly` | `boolean` | `false` | shown, never sent |
532
+ | `dtoKey` | `string` | `key` | relationship name in request bodies, as on the API |
533
+
534
+ Selectors and editor options are client code, so they are set apart with `configureTodosUi`, from a client file the app's layout renders once (the selector itself is shown under "Deep links, read-only users and selectors"). Render `<TodosUiSetup />` once inside the app's client providers:
535
+
536
+ <!-- example: examples/web/TodosUiSetup.tsx -->
537
+ ```tsx
538
+ "use client";
539
+
540
+ import { configureTodosUi } from "@carlonicora/nja-todos/web";
541
+ import { ProjectTaskSelector } from "@/features/project/components/ProjectTaskSelector";
542
+
543
+ configureTodosUi({
544
+ selectors: { project: ProjectTaskSelector },
545
+ useEditorProps: ({ scope }) => ({
546
+ enableMentions: true,
547
+ mentionSearchParams: scope ? { [scope.key]: scope.id } : {},
548
+ }),
549
+ });
550
+
551
+ export function TodosUiSetup(): null {
552
+ return null;
553
+ }
554
+ ```
555
+
556
+ <!-- options: webUi -->
557
+
558
+ | Option | Type | Default | What it does |
559
+ |---|---|---|---|
560
+ | `selectors` | `Record<string, ComponentType<TaskRelationshipSelectorProps>>` | `{}` | by relationship key, the component the editor shows to pick that link. A link with no selector, or fixed by the page, shows none |
561
+ | `useEditorProps` | `(context: { task?: TaskInterface; scope?: TaskScope }) => Record<string, unknown>` | none | a hook (it may call other hooks) that the notes and comment editors call. Its props, such as mention search, are spread after the package's own on `BlockNoteEditorContainer` |
562
+
563
+ ### Texts
564
+
565
+ <!-- example: examples/web/i18n/request.ts -->
566
+ ```ts
567
+ import { mergeMessages } from "@carlonicora/nextjs-jsonapi/core";
568
+ import libraryEn from "@carlonicora/nextjs-jsonapi/messages/en.json";
569
+ import libraryIt from "@carlonicora/nextjs-jsonapi/messages/it.json";
570
+ import todosEn from "@carlonicora/nja-todos/messages/en.json";
571
+ import todosIt from "@carlonicora/nja-todos/messages/it.json";
572
+ import en from "../../messages/en.json";
573
+ import it from "../../messages/it.json";
574
+
575
+ // Library first, then nja-todos, then the app: the app overrides any package text.
576
+ export const MESSAGES = {
577
+ en: mergeMessages(mergeMessages(libraryEn, todosEn), en),
578
+ it: mergeMessages(mergeMessages(libraryIt, todosIt), it),
579
+ };
580
+ ```
581
+
582
+ The package ships the `task` and `taskcomment` namespaces and `notification.task_assigned`, `notification.task_completed` and `notification.task_commented_on` (`title`, `description`, `buttons.action`), in `en` and `it`. Merge them between the library's messages and the app's, so the app overrides any of them.
583
+
584
+ If the app has a translation check that resolves keys against messages and scans sources, add the package's messages folder as a fallback and its `src/web` (or `dist/web`) as a scanned folder.
585
+
586
+ | Key | Who provides it |
587
+ |---|---|
588
+ | `entities.tasks` | the app |
589
+ | `entities.taskcomments` | the app |
590
+ | `entities.<module name>` for each linked module, such as `entities.projects` | the app |
591
+
592
+ Labels use the ICU plural form `{count, plural, =1 {…} other {…}}`.
593
+
594
+ ### Mount a page
595
+
596
+ **A page of tasks linked to one entity.** Render it from the app's page for that entity, the way the app renders its other screens. Its views are "Tasks" and "Matrix". A new task gets the page's entity prefilled and its selector hidden.
597
+
598
+ <!-- example: examples/web/ProjectTasksScreen.tsx -->
599
+ ```tsx
600
+ "use client";
601
+
602
+ import { TaskEditor, TaskListContainer, TaskProvider, useTaskDeepLink } from "@carlonicora/nja-todos/web";
603
+ import type { TaskScope } from "@carlonicora/nja-todos/web/core";
604
+
605
+ function ProjectTaskDeepLink({ scope }: { scope: TaskScope }): null {
606
+ useTaskDeepLink({ scope });
607
+ return null;
608
+ }
609
+
610
+ export function ProjectTasksScreen({ projectId }: { projectId: string }) {
611
+ const scope: TaskScope = { key: "project", id: projectId };
612
+
613
+ return (
614
+ <TaskProvider scope={scope}>
615
+ <ProjectTaskDeepLink scope={scope} />
616
+ <TaskListContainer scope={scope} />
617
+ <TaskEditor />
618
+ </TaskProvider>
619
+ );
620
+ }
621
+ ```
622
+
623
+ **A standalone page of the current user's tasks.** Render `UserTasksScreen` from the app's page (here `/tasks`). Its views are "Assigned", "Created" and "Matrix", and it opens `?task=<id>`. Set `pageUrl` in `configureTodos` and in `TaskModule`.
624
+
625
+ <!-- example: examples/web/TasksPage.tsx -->
626
+ ```tsx
627
+ import { UserTasksScreen } from "@carlonicora/nja-todos/web";
628
+
629
+ export default function TasksPage() {
630
+ return <UserTasksScreen />;
631
+ }
632
+ ```
633
+
634
+ The page has no scope, so a new task's links are picked in the editor with the selectors the app injects through `configureTodosUi({ selectors })`. Register a selector for every `required` `one` link: Create stays disabled until it is picked. When a required `one` link has no selector, Create is hidden on the page, because the editor could never create that task.
635
+
636
+ `useTaskDeepLink` must run inside `TaskProvider`.
637
+
638
+ | Component or hook | Props |
639
+ |---|---|
640
+ | `TaskProvider` | `{ children: ReactNode; scope?: TaskScope }`. `scope` prefills the link of a new task |
641
+ | `TaskListContainer` | `{ scope?: TaskScope; user?: UserInterface; nameBadges?: TaskNameBadges }`. With `scope`, views "list" and "matrix"; with `user`, "assigned", "created" and "matrix". `nameBadges` (`(task: TaskInterface) => ReactNode`) renders extra badges after each task name in the list |
642
+ | `TasksList` | `{ scope?: TaskScope; user?: UserInterface; type?: "assigned" \| "created"; headerControl?: ReactNode; limit?: number; fullWidth?: boolean; nameBadges?: TaskNameBadges }` |
643
+ | `EisenhowerMatrixBoardTab` | `{ scope?: TaskScope; user?: UserInterface; headerControl?: ReactNode }` |
644
+ | `TaskEditor` | `{ extraTabs?: Array<{ key: string; label: string; content: (task: TaskInterface) => ReactNode }> }`. `extraTabs` adds tabs after "Comments" |
645
+ | `UserTasksScreen` | none. The current user's tasks: `TaskProvider` with no scope, `useTaskDeepLink`, `TaskListContainer` with `user` and `TaskEditor`. Renders nothing without a current user |
646
+ | `useTaskDeepLink` | `(params?: { scope?: TaskScope }) => void`. Reads `?task=<id>` |
647
+
648
+ ### Deep links, read-only users and selectors
649
+
650
+ **Deep links.** `?task=<id>` on the page opens that task's editor, and closing the editor removes the parameter. A task that is gone, or outside the page's scope, shows the standard "not found" toast and the parameter is removed. Opening a task from a row or a card does not change the URL.
651
+
652
+ **Read-only users.** A user without write permission on Tasks sees the list and the board without Create, without the complete ticks and without inline changes. Opening a task shows the editor with every field disabled and no complete or delete controls. Comments are readable; adding, editing and deleting them needs write permission on Task Comments.
653
+
654
+ **Selectors.** A selector picks the entity of one relationship in the editor:
655
+
656
+ <!-- example: examples/web/ProjectTaskSelector.tsx -->
657
+ ```tsx
658
+ "use client";
659
+
660
+ import { EntitySelector } from "@carlonicora/nextjs-jsonapi/components";
661
+ import { Modules } from "@carlonicora/nextjs-jsonapi/core";
662
+ import type { TaskRelationshipSelectorProps } from "@carlonicora/nja-todos/web";
663
+ import { useTranslations } from "next-intl";
664
+ import type { ProjectInterface } from "@/features/project/data/ProjectInterface";
665
+ import { ProjectService } from "@/features/project/data/ProjectService";
666
+
667
+ export function ProjectTaskSelector({ form, id, disabled, onChange }: TaskRelationshipSelectorProps) {
668
+ const t = useTranslations();
669
+
670
+ return (
671
+ <EntitySelector<ProjectInterface>
672
+ id={id}
673
+ form={form}
674
+ module={Modules.Project}
675
+ retriever={(params) => ProjectService.findMany(params)}
676
+ label={t("entities.projects", { count: 1 })}
677
+ disabled={disabled}
678
+ onChange={onChange}
679
+ />
680
+ );
681
+ }
682
+ ```
683
+
684
+ The editor passes `form`, `id` (the form field), `relationship`, `disabled` and `onChange`. The field (`related.<key>`) holds `{ id, name? }` for a `one` link and an array of those for a `many` link, which is what the library's `EntitySelector` and `EntityMultiSelector` store by default. Register the selector under its key in `configureTodosUi({ selectors })`.
685
+
686
+ ### What the web entries export
687
+
688
+ `@carlonicora/nja-todos/web/core`:
689
+
690
+ - `configureTodos`, `getTodosConfig`, and the types `TaskScope`, `TodosWebConfig`, `TodosWebRelationshipConfig`
691
+ - `Task`, `TaskInterface`, `TaskInput`, `TaskFields`, `TaskService`, `TaskListParams`
692
+ - `TaskComment`, `TaskCommentInterface`, `TaskCommentInput`, `TaskCommentService`
693
+ - `TaskModule`, `TaskCommentModule`
694
+ - the shared constants: `TaskPriority`, `TODOS_MODULE_IDS`, `TASK_ENDPOINT`, `TASK_COMMENT_ENDPOINT`, `TaskCompletedFilter`, `TodosNotificationType`, `TodosEvent`
695
+
696
+ `@carlonicora/nja-todos/web`:
697
+
698
+ - contexts and hooks: `TaskProvider`, `useTaskContext`, `useRefreshOnTaskEditorClose`, `useTaskDeepLink`, `TaskCommentProvider`, `useTaskCommentContext`, `useTaskTableStructure`, `useTaskOverdueParam`
699
+ - components: `TaskEditor`, `TaskDeleter`, `TaskCommentList`, `TaskCommentEditor`, `TasksList`, `TaskListContainer`, `TaskViewSwitcher`, `TaskListFilters`, `TaskCreateButton`, `UserTasksScreen`, `EisenhowerMatrixBoard`, `EisenhowerMatrixBoardTab`, `EisenhowerIcon`, `TaskMatrixCard`
700
+ - helpers: `getEisenhowerQuadrant`, `getTaskPrioritiesSelectOptions`
701
+ - client configuration: `configureTodosUi`, `getTodosUiConfig`, `useTodosEditorProps`
702
+ - types: `TaskViewMode`, `EisenhowerQuadrant`, `TodosUiConfig`, `TaskRelationshipSelectorProps`
703
+
704
+ ## 5. Worked example: tasks of a project
705
+
706
+ An app has a `Project` entity and wants tasks that may belong to a project, a standalone "My tasks" page, and a project picker in the editor.
707
+
708
+ | Step | API | Web |
709
+ |---|---|---|
710
+ | Link declared | a `relationships` entry in `forRoot`, key `project` | a `relationships` entry in `configureTodos`, key `project` |
711
+ | Picker | none | `ProjectTaskSelector` in `configureTodosUi` |
712
+ | Routes and screens | `GET projects/:projectId/tasks` | `ProjectTasksScreen` with `scope={{ key: "project", id }}` |
713
+ | Standalone page | `GET users/:userId/tasks` | `UserTasksScreen`, `pageUrl: "/tasks"` |
714
+ | Permissions | `ModuleACL` on both controllers, grants, the seed migration | the modules `Task` and `TaskComment` |
715
+ | Texts | the API texts ship with the package | `entities.projects`, `entities.tasks`, `entities.taskcomments` |
716
+ | Graph code | add `PART_OF` from `Task` and `HAS_COMMENT` to any fixed edge list that deletes or copies a project's children | none |
717
+
718
+ The API side:
719
+
720
+ <!-- example: examples/worked/project.todos.module.ts -->
721
+ ```ts
722
+ import { ModuleACL, UserModule } from "@carlonicora/nestjs-neo4jsonapi";
723
+ import { TODOS_MODULE_IDS, TodosModule } from "@carlonicora/nja-todos/api";
724
+ import { Module } from "@nestjs/common";
725
+ import { projectMeta } from "src/features/project/entities/project.meta";
726
+
727
+ @Module({
728
+ imports: [
729
+ TodosModule.forRoot({
730
+ relationships: [
731
+ {
732
+ key: "project",
733
+ model: projectMeta,
734
+ relationship: "PART_OF",
735
+ direction: "out",
736
+ cardinality: "one",
737
+ access: ({ linked, currentUser }) => `WHERE (${currentUser})-[:MEMBER_OF]->(${linked})`,
738
+ },
739
+ ],
740
+ taskPath: (task) => `/tasks?task=${task.id}`,
741
+ decorators: {
742
+ task: { controller: [ModuleACL({ module: TODOS_MODULE_IDS.Task })] },
743
+ comment: { controller: [ModuleACL({ module: TODOS_MODULE_IDS.TaskComment })] },
744
+ },
745
+ imports: [UserModule],
746
+ }),
747
+ ],
748
+ })
749
+ export class FeaturesModule {}
750
+ ```
751
+
752
+ The link is optional (`required` is unset), so tasks without a project still show, and the picker can change or clear it. `taskPath` points at the standalone page because a task may have no project. The link's `access` function lets the project's members see the project's tasks, besides each task's creator and assignee (see Who sees a task).
753
+
754
+ The web configuration:
755
+
756
+ <!-- example: examples/worked/project.todos.config.ts -->
757
+ ```ts
758
+ import { configureTodos } from "@carlonicora/nja-todos/web/core";
759
+ import { Modules } from "@carlonicora/nextjs-jsonapi/core";
760
+
761
+ configureTodos({
762
+ relationships: [{ key: "project", module: () => Modules.Project, cardinality: "one" }],
763
+ taskPath: (task) => `/tasks?task=${task.id}`,
764
+ pageUrl: "/tasks",
765
+ });
766
+ ```
767
+
768
+ The same link, by the same key, with the same optional cardinality; `pageUrl` names the standalone page.
769
+
770
+ The picker:
771
+
772
+ <!-- example: examples/worked/project.todos.ui.tsx -->
773
+ ```tsx
774
+ "use client";
775
+
776
+ import { configureTodosUi } from "@carlonicora/nja-todos/web";
777
+ import { ProjectTaskSelector } from "@/features/project/components/ProjectTaskSelector";
778
+
779
+ configureTodosUi({ selectors: { project: ProjectTaskSelector } });
780
+
781
+ export function TodosUiSetup(): null {
782
+ return null;
783
+ }
784
+ ```
785
+
786
+ `ProjectTaskSelector` is the selector shown under "Deep links, read-only users and selectors", registered under the key `project`.
787
+
788
+ ## 6. Releasing
789
+
790
+ 1. Commit in `packages/nja-todos` with a conventional-commit message and push to `master` of `carlonicora/nja-todos`.
791
+ 2. The release workflow builds and publishes the next version to npm with semantic-release, and pushes the version bump commit.
792
+ 3. In the app, pull the submodule to that commit, run `pnpm install` and `pnpm sync:versions`, and commit.
793
+
794
+ A change that needs a new library release ships the library first, then the package (raising its peer floor), then the app.