@imenam/mcp-organizer 1.0.20 → 1.0.21
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/README.md +103 -29
- package/dist/shared/logic/attachments.d.ts +28 -0
- package/dist/shared/logic/attachments.js +52 -0
- package/dist/shared/logic/documents.d.ts +22 -0
- package/dist/shared/logic/documents.js +38 -0
- package/dist/shared/logic/line-diff.d.ts +13 -0
- package/dist/shared/logic/line-diff.js +66 -0
- package/dist/shared/logic/notes.d.ts +12 -0
- package/dist/shared/logic/notes.js +23 -0
- package/dist/shared/logic/timer.d.ts +69 -0
- package/dist/shared/logic/timer.js +87 -0
- package/dist/shared/schemas/agent-api.schema.d.ts +10 -29
- package/dist/shared/schemas/agent-api.schema.js +4 -15
- package/dist/shared/schemas/agent-tools.schema.d.ts +522 -2
- package/dist/shared/schemas/agent-tools.schema.js +111 -6
- package/dist/shared/schemas/api.schema.d.ts +7 -0
- package/dist/shared/schemas/api.schema.js +6 -0
- package/dist/shared/schemas/documents-api.schema.d.ts +49 -0
- package/dist/shared/schemas/documents-api.schema.js +38 -0
- package/dist/shared/schemas/entities.schema.d.ts +107 -54
- package/dist/shared/schemas/entities.schema.js +81 -10
- package/dist/shared/schemas/enums.schema.d.ts +19 -3
- package/dist/shared/schemas/enums.schema.js +8 -2
- package/dist/shared/schemas/gui-api.schema.d.ts +1 -0
- package/dist/shared/schemas/gui-api.schema.js +2 -0
- package/dist/shared/schemas/history-api.schema.d.ts +961 -0
- package/dist/shared/schemas/history-api.schema.js +104 -0
- package/dist/shared/schemas/notes-api.schema.d.ts +54 -0
- package/dist/shared/schemas/notes-api.schema.js +38 -0
- package/dist/shared/schemas/notifications-api.schema.d.ts +12 -0
- package/dist/shared/schemas/notifications-api.schema.js +4 -1
- package/dist/shared/schemas/tasks-api.schema.d.ts +39 -0
- package/dist/shared/schemas/tasks-api.schema.js +5 -0
- package/dist/shared/schemas/timers-api.schema.d.ts +119 -0
- package/dist/shared/schemas/timers-api.schema.js +44 -0
- package/dist/shared/schemas/views-api.schema.d.ts +16 -0
- package/dist/shared/schemas/views-api.schema.js +4 -2
- package/dist/src/agent-api/documents.d.ts +3 -0
- package/dist/src/agent-api/documents.js +66 -0
- package/dist/src/agent-api/history.d.ts +3 -0
- package/dist/src/agent-api/history.js +103 -0
- package/dist/src/agent-api/notes.d.ts +3 -0
- package/dist/src/agent-api/notes.js +39 -0
- package/dist/src/agent-api/requests.js +2 -1
- package/dist/src/agent-api/router.js +5 -1
- package/dist/src/agent-api/tasks.js +17 -6
- package/dist/src/agent-api/timers.d.ts +2 -0
- package/dist/src/agent-api/timers.js +170 -0
- package/dist/src/agent-api/types.d.ts +3 -0
- package/dist/src/agent-api/views.js +15 -30
- package/dist/src/cli/backup.js +3 -3
- package/dist/src/core/accounts.d.ts +12 -5
- package/dist/src/core/accounts.js +28 -10
- package/dist/src/core/agent.d.ts +27 -3
- package/dist/src/core/agent.js +118 -1
- package/dist/src/core/attachments.d.ts +6 -3
- package/dist/src/core/attachments.js +9 -4
- package/dist/src/core/board-views.js +4 -4
- package/dist/src/core/document-text.d.ts +17 -0
- package/dist/src/core/document-text.js +118 -0
- package/dist/src/core/documents.d.ts +22 -0
- package/dist/src/core/documents.js +168 -0
- package/dist/src/core/history-events.d.ts +34 -0
- package/dist/src/core/history-events.js +236 -0
- package/dist/src/core/history.js +33 -3
- package/dist/src/core/migrations.js +153 -0
- package/dist/src/core/notes.d.ts +23 -0
- package/dist/src/core/notes.js +78 -0
- package/dist/src/core/notifications.d.ts +48 -5
- package/dist/src/core/notifications.js +209 -33
- package/dist/src/core/password-reset.d.ts +37 -0
- package/dist/src/core/password-reset.js +56 -0
- package/dist/src/core/requests.d.ts +4 -3
- package/dist/src/core/requests.js +5 -4
- package/dist/src/core/snapshots.d.ts +3 -3
- package/dist/src/core/snapshots.js +3 -1
- package/dist/src/core/space-history.d.ts +18 -0
- package/dist/src/core/space-history.js +86 -0
- package/dist/src/core/spaces.d.ts +1 -1
- package/dist/src/core/spaces.js +4 -4
- package/dist/src/core/store.d.ts +154 -11
- package/dist/src/core/store.js +479 -52
- package/dist/src/core/task-history.d.ts +9 -5
- package/dist/src/core/task-history.js +17 -25
- package/dist/src/core/tasks.d.ts +2 -2
- package/dist/src/core/tasks.js +13 -2
- package/dist/src/core/timers.d.ts +33 -0
- package/dist/src/core/timers.js +101 -0
- package/dist/src/core/versions.d.ts +22 -0
- package/dist/src/core/versions.js +106 -0
- package/dist/src/gui-api.d.ts +4 -1
- package/dist/src/gui-api.js +85 -6
- package/dist/src/mcp/start.d.ts +1 -1
- package/dist/src/mcp/start.js +12 -7
- package/dist/src/mcp/tools.js +129 -3
- package/dist/src/server/app.d.ts +4 -2
- package/dist/src/server/app.js +21 -5
- package/dist/src/server/login-limiter.d.ts +27 -1
- package/dist/src/server/login-limiter.js +31 -1
- package/dist/src/server/start.js +1 -0
- package/gui/dist/assets/index-DbzcjyaW.js +104 -0
- package/gui/dist/assets/index-Dvf5Yo0e.css +1 -0
- package/gui/dist/index.html +2 -2
- package/package.json +1 -1
- package/gui/dist/assets/index-9c9BlfUi.js +0 -99
- package/gui/dist/assets/index-DH23A5aa.css +0 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { documentText } from "./document-text.js";
|
|
2
|
+
import { InvariantError, NotFoundError, OrganizerError } from "./errors.js";
|
|
3
|
+
import { newId } from "./ids.js";
|
|
4
|
+
import { requireMember } from "./spaces.js";
|
|
5
|
+
import { DOCUMENT_EXTENSIONS_LABEL, documentFormatOf } from "../../shared/logic/documents.js";
|
|
6
|
+
import { MAX_DOCUMENT_BYTES, MAX_SPACE_DOCUMENTS_BYTES, } from "../../shared/schemas/documents-api.schema.js";
|
|
7
|
+
/**
|
|
8
|
+
* Documents de référence d'un espace, pour ses membres : liste, dépôt,
|
|
9
|
+
* description, remplacement par une nouvelle version, téléchargement,
|
|
10
|
+
* suppression. Tous les membres lisent et gèrent les documents de leur
|
|
11
|
+
* espace ; un non-membre reçoit la même réponse qu'un document inexistant.
|
|
12
|
+
* Les fichiers sont rangés avec les pièces jointes, sous `<dataDir>/attachments/`.
|
|
13
|
+
*/
|
|
14
|
+
const asUser = (userId) => ({ type: "user", userId });
|
|
15
|
+
/** Taille lisible d'un nombre d'octets, en Mo. */
|
|
16
|
+
function megabytes(bytes) {
|
|
17
|
+
return `${(bytes / (1024 * 1024)).toFixed(1).replace(".", ",")} Mo`;
|
|
18
|
+
}
|
|
19
|
+
function userName(store, userId) {
|
|
20
|
+
const user = store.findUser(userId);
|
|
21
|
+
return user ? (user.displayName ?? user.email) : "Ancien membre";
|
|
22
|
+
}
|
|
23
|
+
/** Format d'un document enregistré ; un nom sans format connu est une incohérence de la base. */
|
|
24
|
+
function formatOfDocument(document) {
|
|
25
|
+
const format = documentFormatOf(document.filename);
|
|
26
|
+
if (!format)
|
|
27
|
+
throw new Error(`Document ${document.id} has an unsupported file name: ${document.filename}.`);
|
|
28
|
+
return format;
|
|
29
|
+
}
|
|
30
|
+
function documentView(store, document) {
|
|
31
|
+
const format = formatOfDocument(document);
|
|
32
|
+
return {
|
|
33
|
+
id: document.id,
|
|
34
|
+
spaceId: document.spaceId,
|
|
35
|
+
filename: document.filename,
|
|
36
|
+
description: document.description,
|
|
37
|
+
mime: document.mime,
|
|
38
|
+
format: format.label,
|
|
39
|
+
size: document.size,
|
|
40
|
+
version: document.version,
|
|
41
|
+
agentReadable: format.reading !== "none",
|
|
42
|
+
uploaderName: userName(store, document.uploaderId),
|
|
43
|
+
updatedByName: userName(store, document.updatedBy),
|
|
44
|
+
createdAt: document.createdAt,
|
|
45
|
+
updatedAt: document.updatedAt,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function requireDocument(store, documentId, userId) {
|
|
49
|
+
const document = store.findDocument(documentId);
|
|
50
|
+
if (!document || !store.isMember(document.spaceId, userId))
|
|
51
|
+
throw new NotFoundError("Document introuvable, ou vous n'êtes pas membre de son espace.");
|
|
52
|
+
return document;
|
|
53
|
+
}
|
|
54
|
+
/** Volume occupé par les documents d'un espace, sans compter `exceptId`. */
|
|
55
|
+
function usedBytes(store, spaceId, exceptId = null) {
|
|
56
|
+
return store
|
|
57
|
+
.listDocuments(spaceId)
|
|
58
|
+
.filter((document) => document.id !== exceptId)
|
|
59
|
+
.reduce((total, document) => total + document.size, 0);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Fichier envoyé, vérifié : nom, format accepté, taille, et texte lisible
|
|
63
|
+
* pour un format que l'agent lit (UTF-8 pour un texte, archive valide pour un
|
|
64
|
+
* fichier Word).
|
|
65
|
+
*/
|
|
66
|
+
function checkedFile(input) {
|
|
67
|
+
const filename = input.filename.trim();
|
|
68
|
+
const format = documentFormatOf(filename);
|
|
69
|
+
if (!format)
|
|
70
|
+
throw new OrganizerError(`Format refusé pour « ${filename} » : déposez un fichier ${DOCUMENT_EXTENSIONS_LABEL}.`);
|
|
71
|
+
const content = Buffer.from(input.contentBase64, "base64");
|
|
72
|
+
if (content.length > MAX_DOCUMENT_BYTES) {
|
|
73
|
+
throw new OrganizerError(`Fichier trop volumineux (${megabytes(content.length)}) : un document ne dépasse pas ${megabytes(MAX_DOCUMENT_BYTES)}.`);
|
|
74
|
+
}
|
|
75
|
+
documentText(filename, content);
|
|
76
|
+
return { filename, format, content };
|
|
77
|
+
}
|
|
78
|
+
function checkQuota(store, spaceId, size, exceptId) {
|
|
79
|
+
const used = usedBytes(store, spaceId, exceptId);
|
|
80
|
+
if (used + size > MAX_SPACE_DOCUMENTS_BYTES) {
|
|
81
|
+
throw new OrganizerError(`Espace de stockage plein : les documents de l'espace occupent ${megabytes(used)} sur ${megabytes(MAX_SPACE_DOCUMENTS_BYTES)}, ce fichier (${megabytes(size)}) n'y tient pas. Supprimez des documents devenus inutiles.`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Refuse un nom déjà porté par un autre document de l'espace, sans tenir compte de la casse. */
|
|
85
|
+
function checkUniqueName(store, spaceId, filename, exceptId) {
|
|
86
|
+
const taken = store.listDocuments(spaceId).find((document) => document.id !== exceptId && document.filename.toLowerCase() === filename.toLowerCase());
|
|
87
|
+
if (taken)
|
|
88
|
+
throw new InvariantError(`Un document s'appelle déjà « ${taken.filename} » : utilisez « Remplacer » sur ce document pour en déposer une nouvelle version.`);
|
|
89
|
+
}
|
|
90
|
+
/** Documents de l'espace, du plus récemment modifié au plus ancien, avec le volume occupé. */
|
|
91
|
+
export function listDocuments(store, userId, spaceId) {
|
|
92
|
+
requireMember(store, spaceId, userId);
|
|
93
|
+
const documents = store.listDocuments(spaceId);
|
|
94
|
+
return {
|
|
95
|
+
documents: documents.map((document) => documentView(store, document)),
|
|
96
|
+
usedBytes: documents.reduce((total, document) => total + document.size, 0),
|
|
97
|
+
quotaBytes: MAX_SPACE_DOCUMENTS_BYTES,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Dépose un document : le fichier est écrit, puis le document est créé en
|
|
102
|
+
* base après vérification des droits, du nom et du quota dans la même
|
|
103
|
+
* transaction. Un refus efface le fichier écrit.
|
|
104
|
+
*/
|
|
105
|
+
export function uploadDocument(store, storage, userId, spaceId, input) {
|
|
106
|
+
requireMember(store, spaceId, userId);
|
|
107
|
+
const { filename, format, content } = checkedFile(input);
|
|
108
|
+
const id = newId();
|
|
109
|
+
const storagePath = storage.write(id, content);
|
|
110
|
+
try {
|
|
111
|
+
const document = store.mutate(asUser(userId), (tx) => {
|
|
112
|
+
requireMember(tx.store, spaceId, userId);
|
|
113
|
+
checkUniqueName(tx.store, spaceId, filename, null);
|
|
114
|
+
checkQuota(tx.store, spaceId, content.length, null);
|
|
115
|
+
return tx.createDocument({ id, spaceId, filename, description: "", mime: format.mime, size: content.length, storagePath });
|
|
116
|
+
});
|
|
117
|
+
return documentView(store, document);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
storage.remove([storagePath]);
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Remplace le fichier d'un document par une nouvelle version : sa description
|
|
126
|
+
* est gardée, sa version incrémentée, l'ancien fichier effacé.
|
|
127
|
+
*/
|
|
128
|
+
export function replaceDocument(store, storage, userId, documentId, input) {
|
|
129
|
+
requireDocument(store, documentId, userId);
|
|
130
|
+
const { filename, format, content } = checkedFile(input);
|
|
131
|
+
const storagePath = storage.write(newId(), content);
|
|
132
|
+
let previous;
|
|
133
|
+
let document;
|
|
134
|
+
try {
|
|
135
|
+
document = store.mutate(asUser(userId), (tx) => {
|
|
136
|
+
const current = requireDocument(tx.store, documentId, userId);
|
|
137
|
+
previous = current.storagePath;
|
|
138
|
+
checkUniqueName(tx.store, current.spaceId, filename, current.id);
|
|
139
|
+
checkQuota(tx.store, current.spaceId, content.length, current.id);
|
|
140
|
+
return tx.replaceDocumentFile(documentId, { filename, mime: format.mime, size: content.length, storagePath });
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
storage.remove([storagePath]);
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
storage.remove([previous]);
|
|
148
|
+
return documentView(store, document);
|
|
149
|
+
}
|
|
150
|
+
export function updateDocument(store, userId, documentId, patch) {
|
|
151
|
+
const document = store.mutate(asUser(userId), (tx) => {
|
|
152
|
+
requireDocument(tx.store, documentId, userId);
|
|
153
|
+
return tx.setDocumentDescription(documentId, patch.description);
|
|
154
|
+
});
|
|
155
|
+
return documentView(store, document);
|
|
156
|
+
}
|
|
157
|
+
/** Contenu d'un document, avec son type et son nom. */
|
|
158
|
+
export function downloadDocument(store, storage, userId, documentId) {
|
|
159
|
+
const document = requireDocument(store, documentId, userId);
|
|
160
|
+
return { contentBase64: storage.readPath(document.storagePath).toString("base64"), mime: document.mime, filename: document.filename };
|
|
161
|
+
}
|
|
162
|
+
export function deleteDocument(store, storage, userId, documentId) {
|
|
163
|
+
const removed = store.mutate(asUser(userId), (tx) => {
|
|
164
|
+
requireDocument(tx.store, documentId, userId);
|
|
165
|
+
return tx.deleteDocument(documentId);
|
|
166
|
+
});
|
|
167
|
+
storage.remove([removed.storagePath]);
|
|
168
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { HistoryRow, Store } from "./store.js";
|
|
2
|
+
import type { VersionedEntityType } from "../../shared/schemas/enums.schema.js";
|
|
3
|
+
import type { HistoryCategory, HistoryEvent, HistoryPerson, HistoryTaskRef } from "../../shared/schemas/history-api.schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* Événements de l'historique, dérivés des versions : chaque version est
|
|
6
|
+
* comparée à la précédente de la même entité pour en tirer ses changements.
|
|
7
|
+
*/
|
|
8
|
+
/** Catégorie d'événement de chaque type d'entité versionnée. */
|
|
9
|
+
export declare const CATEGORY_OF: Record<VersionedEntityType, HistoryCategory>;
|
|
10
|
+
/** Types d'entités d'une catégorie d'événements. */
|
|
11
|
+
export declare function entityTypesOf(categories: readonly HistoryCategory[]): VersionedEntityType[];
|
|
12
|
+
/** Lectures mises en cache le temps de construire une liste d'événements. */
|
|
13
|
+
export declare class HistoryContext {
|
|
14
|
+
readonly store: Store;
|
|
15
|
+
private readonly spaces;
|
|
16
|
+
private readonly people;
|
|
17
|
+
private readonly tasks;
|
|
18
|
+
private readonly requests;
|
|
19
|
+
constructor(store: Store);
|
|
20
|
+
person(userId: string): HistoryPerson;
|
|
21
|
+
/** Tâche existante ou supprimée, d'après son dernier instantané ; null si elle est inconnue. */
|
|
22
|
+
task(taskId: string): HistoryTaskRef | null;
|
|
23
|
+
request(requestId: string): {
|
|
24
|
+
id: string;
|
|
25
|
+
text: string;
|
|
26
|
+
authorId: string;
|
|
27
|
+
} | null;
|
|
28
|
+
private space;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Événement d'une version, ou null quand elle ne change rien de lisible.
|
|
32
|
+
* `detail` joint le diff complet de la description.
|
|
33
|
+
*/
|
|
34
|
+
export declare function historyEvent(ctx: HistoryContext, row: HistoryRow, detail: boolean): HistoryEvent | null;
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { membershipKey } from "./versions.js";
|
|
2
|
+
import { diffCounts, diffLines } from "../../shared/logic/line-diff.js";
|
|
3
|
+
import { ChecklistItemSchema, IdeaSchema, InvitationSchema, MembershipSchema, NoteSchema, SpaceDocumentSchema, TaskSnapshotSchema, TestCheckpointSchema, } from "../../shared/schemas/entities.schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* Événements de l'historique, dérivés des versions : chaque version est
|
|
6
|
+
* comparée à la précédente de la même entité pour en tirer ses changements.
|
|
7
|
+
*/
|
|
8
|
+
/** Catégorie d'événement de chaque type d'entité versionnée. */
|
|
9
|
+
export const CATEGORY_OF = {
|
|
10
|
+
task: "task",
|
|
11
|
+
checklist_item: "task",
|
|
12
|
+
test_checkpoint: "task",
|
|
13
|
+
idea: "idea",
|
|
14
|
+
membership: "member",
|
|
15
|
+
invitation: "member",
|
|
16
|
+
note: "note",
|
|
17
|
+
document: "document",
|
|
18
|
+
};
|
|
19
|
+
/** Types d'entités d'une catégorie d'événements. */
|
|
20
|
+
export function entityTypesOf(categories) {
|
|
21
|
+
return Object.keys(CATEGORY_OF).filter((type) => categories.includes(CATEGORY_OF[type]));
|
|
22
|
+
}
|
|
23
|
+
const REQUEST_EXCERPT = 140;
|
|
24
|
+
/** Lectures mises en cache le temps de construire une liste d'événements. */
|
|
25
|
+
export class HistoryContext {
|
|
26
|
+
store;
|
|
27
|
+
spaces = new Map();
|
|
28
|
+
people = new Map();
|
|
29
|
+
tasks = new Map();
|
|
30
|
+
requests = new Map();
|
|
31
|
+
constructor(store) {
|
|
32
|
+
this.store = store;
|
|
33
|
+
}
|
|
34
|
+
person(userId) {
|
|
35
|
+
let person = this.people.get(userId);
|
|
36
|
+
if (!person) {
|
|
37
|
+
const user = this.store.findUser(userId);
|
|
38
|
+
person = { id: userId, name: user ? (user.displayName ?? user.email) : "Ancien membre" };
|
|
39
|
+
this.people.set(userId, person);
|
|
40
|
+
}
|
|
41
|
+
return person;
|
|
42
|
+
}
|
|
43
|
+
/** Tâche existante ou supprimée, d'après son dernier instantané ; null si elle est inconnue. */
|
|
44
|
+
task(taskId) {
|
|
45
|
+
if (!this.tasks.has(taskId)) {
|
|
46
|
+
const current = this.store.findTask(taskId);
|
|
47
|
+
const snapshot = current ?? this.store.lastTaskSnapshot(taskId);
|
|
48
|
+
const space = snapshot ? this.space(snapshot.spaceId) : null;
|
|
49
|
+
this.tasks.set(taskId, snapshot && space ? { id: taskId, key: `${space.keyPrefix}-${snapshot.number}`, title: snapshot.title, deleted: current === null } : null);
|
|
50
|
+
}
|
|
51
|
+
return this.tasks.get(taskId) ?? null;
|
|
52
|
+
}
|
|
53
|
+
request(requestId) {
|
|
54
|
+
if (!this.requests.has(requestId)) {
|
|
55
|
+
const request = this.store.findAgentRequest(requestId);
|
|
56
|
+
this.requests.set(requestId, request ? { id: request.id, text: excerpt(request.text, REQUEST_EXCERPT), authorId: request.authorId } : null);
|
|
57
|
+
}
|
|
58
|
+
return this.requests.get(requestId) ?? null;
|
|
59
|
+
}
|
|
60
|
+
space(spaceId) {
|
|
61
|
+
if (!this.spaces.has(spaceId))
|
|
62
|
+
this.spaces.set(spaceId, this.store.findSpace(spaceId));
|
|
63
|
+
return this.spaces.get(spaceId) ?? null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function excerpt(text, max) {
|
|
67
|
+
const line = text.trim().split(/\r?\n/)[0];
|
|
68
|
+
return line.length > max ? `${line.slice(0, max - 1)}…` : line;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Événement d'une version, ou null quand elle ne change rien de lisible.
|
|
72
|
+
* `detail` joint le diff complet de la description.
|
|
73
|
+
*/
|
|
74
|
+
export function historyEvent(ctx, row, detail) {
|
|
75
|
+
const { version } = row;
|
|
76
|
+
const changes = changesOf(ctx, row, detail);
|
|
77
|
+
if (changes.length === 0)
|
|
78
|
+
return null;
|
|
79
|
+
const request = version.actorType === "agent" && version.requestId !== null ? ctx.request(version.requestId) : null;
|
|
80
|
+
const actorId = request ? request.authorId : version.actorId;
|
|
81
|
+
const isTask = version.entityType === "task";
|
|
82
|
+
const restorable = isTask && version.snapshot === null && !ctx.store.findTask(version.entityId) && ctx.store.latestVersion("task", version.entityId)?.version === version.version;
|
|
83
|
+
return {
|
|
84
|
+
id: `${version.entityType}:${version.entityId}:${version.version}`,
|
|
85
|
+
seq: version.seq,
|
|
86
|
+
at: version.createdAt,
|
|
87
|
+
category: CATEGORY_OF[version.entityType],
|
|
88
|
+
actor: { type: version.actorType, ...ctx.person(actorId) },
|
|
89
|
+
request: request ? { id: request.id, text: request.text } : null,
|
|
90
|
+
task: version.taskId === null ? null : ctx.task(version.taskId),
|
|
91
|
+
version: isTask && version.snapshot !== null ? version.version : null,
|
|
92
|
+
restorable,
|
|
93
|
+
changes,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Création, restauration après suppression, suppression, ou null pour une modification. */
|
|
97
|
+
function lifecycle(row) {
|
|
98
|
+
if (!row.previousExists)
|
|
99
|
+
return "created";
|
|
100
|
+
if (row.previous === null)
|
|
101
|
+
return "restored";
|
|
102
|
+
if (row.version.snapshot === null)
|
|
103
|
+
return "deleted";
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
function changesOf(ctx, row, detail) {
|
|
107
|
+
const stage = lifecycle(row);
|
|
108
|
+
const { entityType, snapshot, actorId } = row.version;
|
|
109
|
+
switch (entityType) {
|
|
110
|
+
case "task":
|
|
111
|
+
if (stage !== null)
|
|
112
|
+
return [{ kind: stage }];
|
|
113
|
+
return taskChanges(ctx, TaskSnapshotSchema.parse(row.previous), TaskSnapshotSchema.parse(snapshot), detail);
|
|
114
|
+
case "checklist_item": {
|
|
115
|
+
if (stage !== null) {
|
|
116
|
+
const item = ChecklistItemSchema.parse(snapshot ?? row.previous);
|
|
117
|
+
return [{ kind: "checklist", action: stage === "deleted" ? "removed" : "added", text: item.text, previous: null }];
|
|
118
|
+
}
|
|
119
|
+
const [before, after] = [ChecklistItemSchema.parse(row.previous), ChecklistItemSchema.parse(snapshot)];
|
|
120
|
+
const changes = [];
|
|
121
|
+
if (before.text !== after.text)
|
|
122
|
+
changes.push({ kind: "checklist", action: "edited", text: after.text, previous: before.text });
|
|
123
|
+
if (before.done !== after.done)
|
|
124
|
+
changes.push({ kind: "checklist", action: after.done ? "checked" : "unchecked", text: after.text, previous: null });
|
|
125
|
+
return changes;
|
|
126
|
+
}
|
|
127
|
+
case "test_checkpoint": {
|
|
128
|
+
if (stage !== null) {
|
|
129
|
+
const checkpoint = TestCheckpointSchema.parse(snapshot ?? row.previous);
|
|
130
|
+
return [{ kind: "checkpoint", action: stage === "deleted" ? "removed" : "added", text: checkpoint.text, previous: null }];
|
|
131
|
+
}
|
|
132
|
+
const [before, after] = [TestCheckpointSchema.parse(row.previous), TestCheckpointSchema.parse(snapshot)];
|
|
133
|
+
return before.text === after.text ? [] : [{ kind: "checkpoint", action: "edited", text: after.text, previous: before.text }];
|
|
134
|
+
}
|
|
135
|
+
case "idea": {
|
|
136
|
+
if (stage !== null) {
|
|
137
|
+
return [{ kind: "idea", action: stage, text: IdeaSchema.parse(snapshot ?? row.previous).text, previous: null, task: null }];
|
|
138
|
+
}
|
|
139
|
+
const [before, after] = [IdeaSchema.parse(row.previous), IdeaSchema.parse(snapshot)];
|
|
140
|
+
const changes = [];
|
|
141
|
+
if (before.text !== after.text)
|
|
142
|
+
changes.push({ kind: "idea", action: "edited", text: after.text, previous: before.text, task: null });
|
|
143
|
+
if (after.promotedTaskId !== null && before.promotedTaskId !== after.promotedTaskId) {
|
|
144
|
+
changes.push({ kind: "idea", action: "promoted", text: after.text, previous: null, task: ctx.task(after.promotedTaskId) });
|
|
145
|
+
}
|
|
146
|
+
if ((before.archivedAt === null) !== (after.archivedAt === null)) {
|
|
147
|
+
changes.push({ kind: "idea", action: after.archivedAt === null ? "unarchived" : "archived", text: after.text, previous: null, task: null });
|
|
148
|
+
}
|
|
149
|
+
return changes;
|
|
150
|
+
}
|
|
151
|
+
case "membership": {
|
|
152
|
+
const membership = MembershipSchema.parse(snapshot ?? row.previous);
|
|
153
|
+
const person = ctx.person(membershipKey(row.version.entityId).userId);
|
|
154
|
+
const self = person.id === actorId;
|
|
155
|
+
if (stage === "created" || stage === "restored") {
|
|
156
|
+
const action = membership.role === "owner" && self ? "created_space" : self ? "joined" : "added";
|
|
157
|
+
return [{ kind: "member", action, person, role: membership.role }];
|
|
158
|
+
}
|
|
159
|
+
if (stage === "deleted")
|
|
160
|
+
return [{ kind: "member", action: self ? "left" : "removed", person, role: membership.role }];
|
|
161
|
+
return MembershipSchema.parse(row.previous).role === membership.role ? [] : [{ kind: "member", action: "role", person, role: membership.role }];
|
|
162
|
+
}
|
|
163
|
+
case "invitation": {
|
|
164
|
+
const invitation = InvitationSchema.parse(snapshot ?? row.previous);
|
|
165
|
+
const user = ctx.store.findUserByEmail(invitation.email);
|
|
166
|
+
const person = user ? { id: user.id, name: user.displayName ?? user.email } : { id: null, name: invitation.email };
|
|
167
|
+
if (stage === "created")
|
|
168
|
+
return [{ kind: "invitation", action: "invited", person }];
|
|
169
|
+
if (stage !== null)
|
|
170
|
+
return [];
|
|
171
|
+
const before = InvitationSchema.parse(row.previous);
|
|
172
|
+
if (before.revokedAt === null && invitation.revokedAt !== null)
|
|
173
|
+
return [{ kind: "invitation", action: "revoked", person }];
|
|
174
|
+
if (before.declinedAt === null && invitation.declinedAt !== null)
|
|
175
|
+
return [{ kind: "invitation", action: "declined", person }];
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
case "note": {
|
|
179
|
+
if (stage !== null) {
|
|
180
|
+
const note = NoteSchema.parse(snapshot ?? row.previous);
|
|
181
|
+
return [{ kind: "note", action: stage, noteId: note.id, title: note.title, previous: null }];
|
|
182
|
+
}
|
|
183
|
+
const [before, after] = [NoteSchema.parse(row.previous), NoteSchema.parse(snapshot)];
|
|
184
|
+
const changes = [];
|
|
185
|
+
if (before.title !== after.title)
|
|
186
|
+
changes.push({ kind: "note", action: "renamed", noteId: after.id, title: after.title, previous: before.title });
|
|
187
|
+
if (before.body !== after.body)
|
|
188
|
+
changes.push({ kind: "note", action: "edited", noteId: after.id, title: after.title, previous: null });
|
|
189
|
+
return changes;
|
|
190
|
+
}
|
|
191
|
+
case "document": {
|
|
192
|
+
if (stage !== null) {
|
|
193
|
+
const document = SpaceDocumentSchema.parse(snapshot ?? row.previous);
|
|
194
|
+
return [{ kind: "document", action: stage === "created" ? "added" : stage, filename: document.filename }];
|
|
195
|
+
}
|
|
196
|
+
const [before, after] = [SpaceDocumentSchema.parse(row.previous), SpaceDocumentSchema.parse(snapshot)];
|
|
197
|
+
const changes = [];
|
|
198
|
+
if (before.version !== after.version)
|
|
199
|
+
changes.push({ kind: "document", action: "replaced", filename: after.filename });
|
|
200
|
+
if (before.description !== after.description)
|
|
201
|
+
changes.push({ kind: "document", action: "described", filename: after.filename });
|
|
202
|
+
return changes;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Changements lisibles entre deux instantanés d'une tâche, dans l'ordre de la fiche. */
|
|
207
|
+
function taskChanges(ctx, before, after, detail) {
|
|
208
|
+
const changes = [];
|
|
209
|
+
if (before.title !== after.title)
|
|
210
|
+
changes.push({ kind: "title", from: before.title, to: after.title });
|
|
211
|
+
if (before.status !== after.status)
|
|
212
|
+
changes.push({ kind: "status", from: before.status, to: after.status });
|
|
213
|
+
if (before.priority !== after.priority)
|
|
214
|
+
changes.push({ kind: "priority", from: before.priority, to: after.priority });
|
|
215
|
+
if (before.type !== after.type)
|
|
216
|
+
changes.push({ kind: "type", from: before.type, to: after.type });
|
|
217
|
+
if (before.description !== after.description) {
|
|
218
|
+
const lines = diffLines(before.description, after.description);
|
|
219
|
+
changes.push({ kind: "description", ...diffCounts(lines), lines: detail ? lines : null });
|
|
220
|
+
}
|
|
221
|
+
const added = after.assigneeIds.filter((id) => !before.assigneeIds.includes(id));
|
|
222
|
+
const removed = before.assigneeIds.filter((id) => !after.assigneeIds.includes(id));
|
|
223
|
+
if (added.length + removed.length > 0)
|
|
224
|
+
changes.push({ kind: "assignees", added: added.map((id) => ctx.person(id)), removed: removed.map((id) => ctx.person(id)) });
|
|
225
|
+
const tagName = (id) => ctx.store.findTag(id)?.name ?? "tag supprimé";
|
|
226
|
+
const addedTags = after.tagIds.filter((id) => !before.tagIds.includes(id));
|
|
227
|
+
const removedTags = before.tagIds.filter((id) => !after.tagIds.includes(id));
|
|
228
|
+
if (addedTags.length + removedTags.length > 0)
|
|
229
|
+
changes.push({ kind: "tags", added: addedTags.map(tagName), removed: removedTags.map(tagName) });
|
|
230
|
+
const ref = (id) => (id === null ? null : ctx.task(id));
|
|
231
|
+
if (before.parentId !== after.parentId)
|
|
232
|
+
changes.push({ kind: "parent", from: ref(before.parentId), to: ref(after.parentId) });
|
|
233
|
+
if (before.testedTaskId !== after.testedTaskId)
|
|
234
|
+
changes.push({ kind: "tested", from: ref(before.testedTaskId), to: ref(after.testedTaskId) });
|
|
235
|
+
return changes;
|
|
236
|
+
}
|
package/dist/src/core/history.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ForbiddenError, InvariantError, NotFoundError } from "./errors.js";
|
|
2
2
|
import { CheckpointSnapshotSchema, isTracked, snapshotOf, taskIdOfAction } from "./snapshots.js";
|
|
3
|
-
import { BoardViewSchema, ChecklistItemSchema, FollowUpSchema, QuestionSnapshotSchema, CommentSchema, IdeaSchema, TaskSnapshotSchema, TestCheckpointSchema, } from "../../shared/schemas/entities.schema.js";
|
|
3
|
+
import { BoardViewSchema, ChecklistItemSchema, FollowUpSchema, QuestionSnapshotSchema, CommentSchema, IdeaSchema, TaskSnapshotSchema, TestCheckpointSchema, TimeSessionSchema, } from "../../shared/schemas/entities.schema.js";
|
|
4
4
|
/**
|
|
5
5
|
* Retour à un état antérieur : annulation d'une action de l'agent, après
|
|
6
6
|
* comparaison de l'état courant de l'entité avec celui que l'action a
|
|
@@ -35,12 +35,16 @@ function comparable(entityType, snapshot) {
|
|
|
35
35
|
return viewSettings(BoardViewSchema.parse(snapshot));
|
|
36
36
|
case "follow_up":
|
|
37
37
|
return [FollowUpSchema.parse(snapshot).doneAt !== null];
|
|
38
|
+
case "time_session": {
|
|
39
|
+
const session = TimeSessionSchema.parse(snapshot);
|
|
40
|
+
return [session.endedAt, session.runningSince, session.elapsedMs];
|
|
41
|
+
}
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
/** Réglages d'une vue, comparés et restaurés par l'annulation. */
|
|
41
45
|
function viewSettings(view) {
|
|
42
|
-
const { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds } = view;
|
|
43
|
-
return { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds };
|
|
46
|
+
const { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds, types } = view;
|
|
47
|
+
return { name, layout, groupBy, thenBy, showEmptyGroups, statuses, priorities, assigneeIds, unassigned, tagIds, types };
|
|
44
48
|
}
|
|
45
49
|
/** Rang d'un élément de checklist ou d'un point de vérification ; null pour les autres entités. */
|
|
46
50
|
function listPosition(entityType, snapshot) {
|
|
@@ -84,6 +88,14 @@ function describe(store, entityType, snapshot) {
|
|
|
84
88
|
return { label: `La vue « ${BoardViewSchema.parse(snapshot).name} »`, feminine: true };
|
|
85
89
|
case "follow_up":
|
|
86
90
|
return { label: `Le point « ${excerpt(FollowUpSchema.parse(snapshot).text)} »`, feminine: false };
|
|
91
|
+
case "time_session": {
|
|
92
|
+
const session = TimeSessionSchema.parse(snapshot);
|
|
93
|
+
const user = store.findUser(session.userId);
|
|
94
|
+
const task = store.findTask(session.taskId);
|
|
95
|
+
const space = store.findSpace(session.spaceId);
|
|
96
|
+
const who = user ? (user.displayName ?? user.email) : "un ancien membre";
|
|
97
|
+
return { label: `Le chrono de ${who}${task && space ? ` sur ${space.keyPrefix}-${task.number}` : ""}`, feminine: false };
|
|
98
|
+
}
|
|
87
99
|
}
|
|
88
100
|
}
|
|
89
101
|
function excerpt(text) {
|
|
@@ -116,6 +128,8 @@ export function undoAgentAction(tx, action) {
|
|
|
116
128
|
const store = tx.store;
|
|
117
129
|
if (entityType === "board_view")
|
|
118
130
|
requireViewOwner(tx, BoardViewSchema.parse(action.after ?? action.before));
|
|
131
|
+
if (entityType === "time_session")
|
|
132
|
+
requireTimerOwner(tx, TimeSessionSchema.parse(action.after ?? action.before));
|
|
119
133
|
const current = snapshotOf(store, entityType, action.entityId);
|
|
120
134
|
if (action.after === null) {
|
|
121
135
|
const { label } = describe(store, entityType, action.before);
|
|
@@ -146,6 +160,13 @@ function requireViewOwner(tx, view) {
|
|
|
146
160
|
const owner = tx.store.findUser(view.userId);
|
|
147
161
|
throw new ForbiddenError(`La vue « ${view.name} » appartient à ${owner ? (owner.displayName ?? owner.email) : "un ancien membre"} : lui seul peut annuler ce changement.`);
|
|
148
162
|
}
|
|
163
|
+
/** Seul le membre à qui appartient un chrono annule ce que l'agent y a fait. */
|
|
164
|
+
function requireTimerOwner(tx, session) {
|
|
165
|
+
if (tx.actor.type === "user" && tx.actor.userId === session.userId)
|
|
166
|
+
return;
|
|
167
|
+
const owner = tx.store.findUser(session.userId);
|
|
168
|
+
throw new ForbiddenError(`Ce chrono appartient à ${owner ? (owner.displayName ?? owner.email) : "un ancien membre"} : lui seul peut annuler ce changement.`);
|
|
169
|
+
}
|
|
149
170
|
/** Vérifie que les assignés filtrés par une vue sont encore membres de son espace. */
|
|
150
171
|
function requireViewAssignees(tx, view) {
|
|
151
172
|
for (const userId of view.assigneeIds) {
|
|
@@ -168,6 +189,7 @@ function remove(tx, entityType, current, label) {
|
|
|
168
189
|
[store.listCheckpoints(task.id).length, "des points de vérification"],
|
|
169
190
|
[store.listComments(task.id).length, "des commentaires"],
|
|
170
191
|
[store.listAttachments(task.id).length, "des pièces jointes"],
|
|
192
|
+
[store.listTimeSessions(task.id).length, "des sessions de chrono"],
|
|
171
193
|
];
|
|
172
194
|
const found = dependents.filter(([count]) => count > 0).map(([, what]) => what);
|
|
173
195
|
if (found.length > 0) {
|
|
@@ -203,6 +225,9 @@ function remove(tx, entityType, current, label) {
|
|
|
203
225
|
tx.deleteBoardView(view.id);
|
|
204
226
|
return;
|
|
205
227
|
}
|
|
228
|
+
case "time_session":
|
|
229
|
+
tx.deleteTimeSession(TimeSessionSchema.parse(current).id);
|
|
230
|
+
return;
|
|
206
231
|
}
|
|
207
232
|
}
|
|
208
233
|
/** Recrée une entité supprimée par l'agent. */
|
|
@@ -286,6 +311,11 @@ function restore(tx, entityType, entityId, before) {
|
|
|
286
311
|
tx.restoreFollowUpState(entityId, { doneAt, doneBy, doneByRequestId });
|
|
287
312
|
return;
|
|
288
313
|
}
|
|
314
|
+
case "time_session": {
|
|
315
|
+
const { runningSince, elapsedMs, endedAt } = TimeSessionSchema.parse(before);
|
|
316
|
+
tx.restoreTimeSessionState(entityId, { runningSince, elapsedMs, endedAt });
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
289
319
|
}
|
|
290
320
|
}
|
|
291
321
|
/** Libellés français des champs restaurables d'une tâche ; « position » est le rang dans une même colonne. */
|