@retiform/paperless-mcp 0.0.0-stage → 2.3.2
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/LICENSE +18 -0
- package/README.md +1005 -2
- package/build/api/PaperlessAPI.d.ts +63 -0
- package/build/api/PaperlessAPI.js +405 -0
- package/build/api/documentEnhancer.d.ts +24 -0
- package/build/api/documentEnhancer.js +111 -0
- package/build/api/documentEnhancer.test.d.ts +1 -0
- package/build/api/documentEnhancer.test.js +80 -0
- package/build/api/types.d.ts +203 -0
- package/build/api/types.js +15 -0
- package/build/api/utils.d.ts +16 -0
- package/build/api/utils.js +29 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +189 -0
- package/build/resources/documents.d.ts +7 -0
- package/build/resources/documents.js +119 -0
- package/build/resources/documents.test.d.ts +1 -0
- package/build/resources/documents.test.js +124 -0
- package/build/server.d.ts +24 -0
- package/build/server.js +70 -0
- package/build/server.test.d.ts +1 -0
- package/build/server.test.js +54 -0
- package/build/test/mocks/paperlessApi.d.ts +4 -0
- package/build/test/mocks/paperlessApi.js +33 -0
- package/build/tools/boundedContent.test.d.ts +1 -0
- package/build/tools/boundedContent.test.js +544 -0
- package/build/tools/correspondents.d.ts +3 -0
- package/build/tools/correspondents.js +149 -0
- package/build/tools/customFields.d.ts +3 -0
- package/build/tools/customFields.js +142 -0
- package/build/tools/documentTypes.d.ts +3 -0
- package/build/tools/documentTypes.js +143 -0
- package/build/tools/documents.d.ts +134 -0
- package/build/tools/documents.js +814 -0
- package/build/tools/documents.test.d.ts +1 -0
- package/build/tools/documents.test.js +658 -0
- package/build/tools/mail.d.ts +3 -0
- package/build/tools/mail.js +187 -0
- package/build/tools/mail.test.d.ts +1 -0
- package/build/tools/mail.test.js +212 -0
- package/build/tools/notes.d.ts +3 -0
- package/build/tools/notes.js +55 -0
- package/build/tools/notes.test.d.ts +1 -0
- package/build/tools/notes.test.js +177 -0
- package/build/tools/schemaCompat.test.d.ts +1 -0
- package/build/tools/schemaCompat.test.js +59 -0
- package/build/tools/tags.d.ts +3 -0
- package/build/tools/tags.js +143 -0
- package/build/tools/utils/descriptions.d.ts +1 -0
- package/build/tools/utils/descriptions.js +4 -0
- package/build/tools/utils/documentQuery.d.ts +71 -0
- package/build/tools/utils/documentQuery.js +270 -0
- package/build/tools/utils/empty.d.ts +2 -0
- package/build/tools/utils/empty.js +7 -0
- package/build/tools/utils/matchingAlgorithm.d.ts +2 -0
- package/build/tools/utils/matchingAlgorithm.js +15 -0
- package/build/tools/utils/middlewares.d.ts +3 -0
- package/build/tools/utils/middlewares.js +31 -0
- package/build/tools/utils/monetary.d.ts +5 -0
- package/build/tools/utils/monetary.js +34 -0
- package/build/tools/utils/monetary.test.d.ts +1 -0
- package/build/tools/utils/monetary.test.js +25 -0
- package/build/tools/utils/queryString.d.ts +1 -0
- package/build/tools/utils/queryString.js +12 -0
- package/build/tools/utils/resourceUri.d.ts +29 -0
- package/build/tools/utils/resourceUri.js +37 -0
- package/build/tools/utils/resourceUri.test.d.ts +1 -0
- package/build/tools/utils/resourceUri.test.js +50 -0
- package/build/tools/utils/selectFields.d.ts +13 -0
- package/build/tools/utils/selectFields.js +91 -0
- package/build/tools/utils/selectFields.test.d.ts +1 -0
- package/build/tools/utils/selectFields.test.js +164 -0
- package/package.json +59 -4
- package/paperless-mcp.dxt +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { AxiosResponse } from "axios";
|
|
2
|
+
import { BulkEditDocumentsResult, BulkEditParameters, Correspondent, CustomField, Document, DocumentsResponse, DocumentType, GetCorrespondentsResponse, GetCustomFieldsResponse, GetDocumentTypesResponse, GetMailAccountsResponse, GetMailRulesResponse, MailAccount, MailRule, GetTagsResponse, Note, Tag } from "./types";
|
|
3
|
+
export declare class PaperlessAPI {
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly token;
|
|
6
|
+
private readonly apiVersion;
|
|
7
|
+
constructor(baseUrl: string, token: string);
|
|
8
|
+
request<T = any>(path: string, options?: RequestInit): Promise<T>;
|
|
9
|
+
bulkEditDocuments(documents: number[], method: string, parameters?: BulkEditParameters): Promise<BulkEditDocumentsResult>;
|
|
10
|
+
postDocument(document: Buffer, filename: string, metadata?: Record<string, string | string[] | number | number[] | undefined>): Promise<string>;
|
|
11
|
+
getDocuments(query?: string): Promise<DocumentsResponse>;
|
|
12
|
+
getDocument(id: number): Promise<Document>;
|
|
13
|
+
updateDocument(id: number, data: Partial<Document>): Promise<Document>;
|
|
14
|
+
downloadDocument(id: number, asOriginal?: boolean): Promise<AxiosResponse<ArrayBuffer>>;
|
|
15
|
+
getThumbnail(id: number): Promise<AxiosResponse<ArrayBuffer>>;
|
|
16
|
+
/**
|
|
17
|
+
* Retrieve all notes attached to a document.
|
|
18
|
+
* @param documentId - The document ID.
|
|
19
|
+
* @returns The document's notes.
|
|
20
|
+
*/
|
|
21
|
+
getDocumentNotes(documentId: number): Promise<Note[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Create a note on a document.
|
|
24
|
+
* @param documentId - The document ID.
|
|
25
|
+
* @param note - The note text to add.
|
|
26
|
+
* @returns The document's full notes list after creation.
|
|
27
|
+
*/
|
|
28
|
+
createDocumentNote(documentId: number, note: string): Promise<Note[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Delete a note from a document by its note ID.
|
|
31
|
+
* @param documentId - The document ID.
|
|
32
|
+
* @param noteId - The ID of the note to delete.
|
|
33
|
+
* @returns The document's remaining notes after deletion.
|
|
34
|
+
*/
|
|
35
|
+
deleteDocumentNote(documentId: number, noteId: number): Promise<Note[]>;
|
|
36
|
+
getTags(): Promise<GetTagsResponse>;
|
|
37
|
+
createTag(data: Partial<Tag>): Promise<Tag>;
|
|
38
|
+
updateTag(id: number, data: Partial<Tag>): Promise<Tag>;
|
|
39
|
+
deleteTag(id: number): Promise<void>;
|
|
40
|
+
getCorrespondents(queryString?: string): Promise<GetCorrespondentsResponse>;
|
|
41
|
+
getCorrespondent(id: number): Promise<Correspondent>;
|
|
42
|
+
createCorrespondent(data: Partial<Correspondent>): Promise<Correspondent>;
|
|
43
|
+
updateCorrespondent(id: number, data: Partial<Correspondent>): Promise<Correspondent>;
|
|
44
|
+
deleteCorrespondent(id: number): Promise<void>;
|
|
45
|
+
getDocumentTypes(): Promise<GetDocumentTypesResponse>;
|
|
46
|
+
createDocumentType(data: Partial<DocumentType>): Promise<DocumentType>;
|
|
47
|
+
updateDocumentType(id: number, data: Partial<DocumentType>): Promise<DocumentType>;
|
|
48
|
+
deleteDocumentType(id: number): Promise<void>;
|
|
49
|
+
getMailAccounts(queryString?: string): Promise<GetMailAccountsResponse>;
|
|
50
|
+
getMailAccount(id: number): Promise<MailAccount>;
|
|
51
|
+
processMailAccount(id: number): Promise<void>;
|
|
52
|
+
getMailRules(queryString?: string): Promise<GetMailRulesResponse>;
|
|
53
|
+
getMailRule(id: number): Promise<MailRule>;
|
|
54
|
+
createMailRule(data: Partial<MailRule>): Promise<MailRule>;
|
|
55
|
+
updateMailRule(id: number, data: Partial<MailRule>): Promise<MailRule>;
|
|
56
|
+
deleteMailRule(id: number): Promise<void>;
|
|
57
|
+
getCustomFields(): Promise<GetCustomFieldsResponse>;
|
|
58
|
+
getCustomField(id: number): Promise<CustomField>;
|
|
59
|
+
createCustomField(data: Partial<CustomField>): Promise<CustomField>;
|
|
60
|
+
updateCustomField(id: number, data: Partial<CustomField>): Promise<CustomField>;
|
|
61
|
+
deleteCustomField(id: number): Promise<void>;
|
|
62
|
+
bulkEditObjects(objects: any, objectType: any, operation: any, parameters?: {}): Promise<any>;
|
|
63
|
+
}
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PaperlessAPI = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
18
|
+
const utils_1 = require("./utils");
|
|
19
|
+
class PaperlessAPI {
|
|
20
|
+
constructor(baseUrl, token) {
|
|
21
|
+
this.baseUrl = baseUrl;
|
|
22
|
+
this.token = token;
|
|
23
|
+
this.baseUrl = baseUrl;
|
|
24
|
+
this.token = token;
|
|
25
|
+
this.apiVersion = process.env.PAPERLESS_API_VERSION || "9";
|
|
26
|
+
}
|
|
27
|
+
request(path_1) {
|
|
28
|
+
return __awaiter(this, arguments, void 0, function* (path, options = {}) {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
const url = `${this.baseUrl}/api${path}`;
|
|
31
|
+
const isJson = !options.body || typeof options.body === "string";
|
|
32
|
+
const mergedHeaders = Object.assign(Object.assign({ Authorization: `Token ${this.token}`, Accept: `application/json; version=${this.apiVersion}`, "Accept-Language": "en-US,en;q=0.9" }, (isJson ? { "Content-Type": "application/json" } : {})), (0, utils_1.headersToObject)(options.headers));
|
|
33
|
+
try {
|
|
34
|
+
const response = yield (0, axios_1.default)({
|
|
35
|
+
url,
|
|
36
|
+
method: options.method || "GET",
|
|
37
|
+
headers: mergedHeaders,
|
|
38
|
+
data: options.body,
|
|
39
|
+
});
|
|
40
|
+
const body = response.data;
|
|
41
|
+
if (response.status < 200 || response.status >= 300) {
|
|
42
|
+
console.error({
|
|
43
|
+
error: "Error executing request",
|
|
44
|
+
url,
|
|
45
|
+
method: options.method || "GET",
|
|
46
|
+
status: response.status,
|
|
47
|
+
response: body,
|
|
48
|
+
});
|
|
49
|
+
const errorMessage = (body === null || body === void 0 ? void 0 : body.detail) ||
|
|
50
|
+
(body === null || body === void 0 ? void 0 : body.error) ||
|
|
51
|
+
(body === null || body === void 0 ? void 0 : body.message) ||
|
|
52
|
+
`HTTP error! status: ${response.status}`;
|
|
53
|
+
throw new Error(String(errorMessage));
|
|
54
|
+
}
|
|
55
|
+
return body;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 406) {
|
|
59
|
+
throw new Error(`HTTP 406: Paperless-ngx rejected API version ${this.apiVersion}. ` +
|
|
60
|
+
`Set the PAPERLESS_API_VERSION environment variable to a version your server supports (e.g., "9" or "10" for Paperless-ngx v3+, or a lower value for older servers).`);
|
|
61
|
+
}
|
|
62
|
+
console.error({
|
|
63
|
+
error: "Error executing request",
|
|
64
|
+
message: error instanceof Error ? error.message : String(error),
|
|
65
|
+
url,
|
|
66
|
+
method: options.method || "GET",
|
|
67
|
+
responseData: axios_1.default.isAxiosError(error) ? (_b = error.response) === null || _b === void 0 ? void 0 : _b.data : undefined,
|
|
68
|
+
status: axios_1.default.isAxiosError(error) ? (_c = error.response) === null || _c === void 0 ? void 0 : _c.status : undefined,
|
|
69
|
+
});
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// Document operations
|
|
75
|
+
bulkEditDocuments(documents_1, method_1) {
|
|
76
|
+
return __awaiter(this, arguments, void 0, function* (documents, method, parameters = {}) {
|
|
77
|
+
return this.request("/documents/bulk_edit/", {
|
|
78
|
+
method: "POST",
|
|
79
|
+
body: JSON.stringify({
|
|
80
|
+
documents,
|
|
81
|
+
method,
|
|
82
|
+
parameters,
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
postDocument(document_1, filename_1) {
|
|
88
|
+
return __awaiter(this, arguments, void 0, function* (document, filename, metadata = {}) {
|
|
89
|
+
var _a;
|
|
90
|
+
const formData = new form_data_1.default();
|
|
91
|
+
formData.append("document", document, { filename });
|
|
92
|
+
// Add optional metadata fields
|
|
93
|
+
if (metadata.title)
|
|
94
|
+
formData.append("title", metadata.title);
|
|
95
|
+
if (metadata.created)
|
|
96
|
+
formData.append("created", metadata.created);
|
|
97
|
+
if (metadata.correspondent)
|
|
98
|
+
formData.append("correspondent", metadata.correspondent);
|
|
99
|
+
if (metadata.document_type)
|
|
100
|
+
formData.append("document_type", metadata.document_type);
|
|
101
|
+
if (metadata.storage_path)
|
|
102
|
+
formData.append("storage_path", metadata.storage_path);
|
|
103
|
+
if (metadata.tags) {
|
|
104
|
+
metadata.tags.forEach((tag) => formData.append("tags", tag));
|
|
105
|
+
}
|
|
106
|
+
if (metadata.archive_serial_number) {
|
|
107
|
+
formData.append("archive_serial_number", String(metadata.archive_serial_number));
|
|
108
|
+
}
|
|
109
|
+
if (metadata.custom_fields) {
|
|
110
|
+
metadata.custom_fields.forEach((field) => formData.append("custom_fields", String(field)));
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
const response = yield axios_1.default.post(`${this.baseUrl}/api/documents/post_document/`, formData, {
|
|
114
|
+
headers: Object.assign({ Authorization: `Token ${this.token}`, Accept: `application/json; version=${this.apiVersion}` }, formData.getHeaders()),
|
|
115
|
+
});
|
|
116
|
+
if (response.status < 200 || response.status >= 300) {
|
|
117
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
118
|
+
}
|
|
119
|
+
return response.data;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (axios_1.default.isAxiosError(error) && ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 406) {
|
|
123
|
+
throw new Error(`HTTP 406: Paperless-ngx rejected API version ${this.apiVersion}. ` +
|
|
124
|
+
`Set the PAPERLESS_API_VERSION environment variable to a version your server supports (e.g., "9" or "10" for Paperless-ngx v3+, or a lower value for older servers).`);
|
|
125
|
+
}
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
getDocuments() {
|
|
131
|
+
return __awaiter(this, arguments, void 0, function* (query = "") {
|
|
132
|
+
return this.request(`/documents/${query}`);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
getDocument(id) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
return this.request(`/documents/${id}/`);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
updateDocument(id, data) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
return this.request(`/documents/${id}/`, {
|
|
143
|
+
method: "PATCH",
|
|
144
|
+
body: JSON.stringify(data),
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
downloadDocument(id_1) {
|
|
149
|
+
return __awaiter(this, arguments, void 0, function* (id, asOriginal = false) {
|
|
150
|
+
const query = asOriginal ? "?original=true" : "";
|
|
151
|
+
const response = yield axios_1.default.get(`${this.baseUrl}/api/documents/${id}/download/${query}`, {
|
|
152
|
+
headers: {
|
|
153
|
+
Authorization: `Token ${this.token}`,
|
|
154
|
+
},
|
|
155
|
+
responseType: "arraybuffer",
|
|
156
|
+
});
|
|
157
|
+
return response;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
getThumbnail(id) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
const response = yield axios_1.default.get(`${this.baseUrl}/api/documents/${id}/thumb/`, {
|
|
163
|
+
headers: {
|
|
164
|
+
Authorization: `Token ${this.token}`,
|
|
165
|
+
},
|
|
166
|
+
responseType: "arraybuffer",
|
|
167
|
+
});
|
|
168
|
+
return response;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// Document note operations
|
|
172
|
+
/**
|
|
173
|
+
* Retrieve all notes attached to a document.
|
|
174
|
+
* @param documentId - The document ID.
|
|
175
|
+
* @returns The document's notes.
|
|
176
|
+
*/
|
|
177
|
+
getDocumentNotes(documentId) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
return this.request(`/documents/${documentId}/notes/`);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Create a note on a document.
|
|
184
|
+
* @param documentId - The document ID.
|
|
185
|
+
* @param note - The note text to add.
|
|
186
|
+
* @returns The document's full notes list after creation.
|
|
187
|
+
*/
|
|
188
|
+
createDocumentNote(documentId, note) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
return this.request(`/documents/${documentId}/notes/`, {
|
|
191
|
+
method: "POST",
|
|
192
|
+
body: JSON.stringify({ note }),
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Delete a note from a document by its note ID.
|
|
198
|
+
* @param documentId - The document ID.
|
|
199
|
+
* @param noteId - The ID of the note to delete.
|
|
200
|
+
* @returns The document's remaining notes after deletion.
|
|
201
|
+
*/
|
|
202
|
+
deleteDocumentNote(documentId, noteId) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
return this.request(`/documents/${documentId}/notes/?id=${noteId}`, {
|
|
205
|
+
method: "DELETE",
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
// Tag operations
|
|
210
|
+
getTags() {
|
|
211
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
+
return this.request("/tags/");
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
createTag(data) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
return this.request("/tags/", {
|
|
218
|
+
method: "POST",
|
|
219
|
+
body: JSON.stringify(data),
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
updateTag(id, data) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
return this.request(`/tags/${id}/`, {
|
|
226
|
+
method: "PATCH",
|
|
227
|
+
body: JSON.stringify(data),
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
deleteTag(id) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
return this.request(`/tags/${id}/`, {
|
|
234
|
+
method: "DELETE",
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
// Correspondent operations
|
|
239
|
+
getCorrespondents(queryString) {
|
|
240
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
241
|
+
const url = queryString
|
|
242
|
+
? `/correspondents/?${queryString}`
|
|
243
|
+
: "/correspondents/";
|
|
244
|
+
return this.request(url);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
getCorrespondent(id) {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
return this.request(`/correspondents/${id}/`);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
createCorrespondent(data) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
return this.request("/correspondents/", {
|
|
255
|
+
method: "POST",
|
|
256
|
+
body: JSON.stringify(data),
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
updateCorrespondent(id, data) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
return this.request(`/correspondents/${id}/`, {
|
|
263
|
+
method: "PATCH",
|
|
264
|
+
body: JSON.stringify(data),
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
deleteCorrespondent(id) {
|
|
269
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
+
return this.request(`/correspondents/${id}/`, {
|
|
271
|
+
method: "DELETE",
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
// Document type operations
|
|
276
|
+
getDocumentTypes() {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
return this.request("/document_types/");
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
createDocumentType(data) {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
return this.request("/document_types/", {
|
|
284
|
+
method: "POST",
|
|
285
|
+
body: JSON.stringify(data),
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
updateDocumentType(id, data) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
return this.request(`/document_types/${id}/`, {
|
|
292
|
+
method: "PATCH",
|
|
293
|
+
body: JSON.stringify(data),
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
deleteDocumentType(id) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
return this.request(`/document_types/${id}/`, {
|
|
300
|
+
method: "DELETE",
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
// Mail account operations
|
|
305
|
+
getMailAccounts(queryString) {
|
|
306
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
307
|
+
const url = queryString
|
|
308
|
+
? `/mail_accounts/?${queryString}`
|
|
309
|
+
: "/mail_accounts/";
|
|
310
|
+
return this.request(url);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
getMailAccount(id) {
|
|
314
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
315
|
+
return this.request(`/mail_accounts/${id}/`);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
processMailAccount(id) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
return this.request(`/mail_accounts/${id}/process/`, {
|
|
321
|
+
method: "POST",
|
|
322
|
+
body: JSON.stringify({}),
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
// Mail rule operations
|
|
327
|
+
getMailRules(queryString) {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
const url = queryString ? `/mail_rules/?${queryString}` : "/mail_rules/";
|
|
330
|
+
return this.request(url);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
getMailRule(id) {
|
|
334
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
+
return this.request(`/mail_rules/${id}/`);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
createMailRule(data) {
|
|
339
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
340
|
+
return this.request("/mail_rules/", {
|
|
341
|
+
method: "POST",
|
|
342
|
+
body: JSON.stringify(data),
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
updateMailRule(id, data) {
|
|
347
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
348
|
+
return this.request(`/mail_rules/${id}/`, {
|
|
349
|
+
method: "PATCH",
|
|
350
|
+
body: JSON.stringify(data),
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
deleteMailRule(id) {
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
return this.request(`/mail_rules/${id}/`, {
|
|
357
|
+
method: "DELETE",
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
// Custom field operations
|
|
362
|
+
getCustomFields() {
|
|
363
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
364
|
+
return this.request("/custom_fields/");
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
getCustomField(id) {
|
|
368
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
369
|
+
return this.request(`/custom_fields/${id}/`);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
createCustomField(data) {
|
|
373
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
374
|
+
return this.request("/custom_fields/", {
|
|
375
|
+
method: "POST",
|
|
376
|
+
body: JSON.stringify(data),
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
updateCustomField(id, data) {
|
|
381
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
382
|
+
return this.request(`/custom_fields/${id}/`, {
|
|
383
|
+
method: "PATCH",
|
|
384
|
+
body: JSON.stringify(data),
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
deleteCustomField(id) {
|
|
389
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
390
|
+
return this.request(`/custom_fields/${id}/`, {
|
|
391
|
+
method: "DELETE",
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
// Bulk object operations
|
|
396
|
+
bulkEditObjects(objects_1, objectType_1, operation_1) {
|
|
397
|
+
return __awaiter(this, arguments, void 0, function* (objects, objectType, operation, parameters = {}) {
|
|
398
|
+
return this.request("/bulk_edit_objects/", {
|
|
399
|
+
method: "POST",
|
|
400
|
+
body: JSON.stringify(Object.assign({ objects, object_type: objectType, operation }, parameters)),
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
exports.PaperlessAPI = PaperlessAPI;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CallToolResult } from "@modelcontextprotocol/sdk/types";
|
|
2
|
+
import { PaperlessAPI } from "./PaperlessAPI";
|
|
3
|
+
import { Document, DocumentsResponse } from "./types";
|
|
4
|
+
import { NamedItem } from "./utils";
|
|
5
|
+
interface CustomField {
|
|
6
|
+
field: number;
|
|
7
|
+
name: string;
|
|
8
|
+
value: string | number | boolean | object | null;
|
|
9
|
+
}
|
|
10
|
+
export interface EnhancedDocument extends Omit<Document, "correspondent" | "document_type" | "tags" | "custom_fields" | "content"> {
|
|
11
|
+
correspondent: NamedItem | null;
|
|
12
|
+
document_type: NamedItem | null;
|
|
13
|
+
tags: NamedItem[];
|
|
14
|
+
custom_fields: CustomField[];
|
|
15
|
+
/**
|
|
16
|
+
* Size of the excluded `content` field, in characters. Kept during the
|
|
17
|
+
* content strip so callers can plan bounded reads without fetching the
|
|
18
|
+
* document text.
|
|
19
|
+
*/
|
|
20
|
+
content_length?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function convertDocsWithNames(document: Document, api: PaperlessAPI): Promise<CallToolResult>;
|
|
23
|
+
export declare function convertDocsWithNames(documentsResponse: DocumentsResponse, api: PaperlessAPI): Promise<CallToolResult>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.convertDocsWithNames = convertDocsWithNames;
|
|
24
|
+
function convertDocsWithNames(input, api) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if ("results" in input) {
|
|
27
|
+
const { all, results } = input, paginationMeta = __rest(input, ["all", "results"]);
|
|
28
|
+
const enhancedResults = yield enhanceDocumentsArray(results || [], api);
|
|
29
|
+
return {
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
type: "text",
|
|
33
|
+
text: JSON.stringify(Object.assign(Object.assign({}, paginationMeta), { results: enhancedResults })),
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (!input) {
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: "text",
|
|
43
|
+
text: "No document found",
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const [enhanced] = yield enhanceDocumentsArray([input], api);
|
|
49
|
+
return {
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: "text",
|
|
53
|
+
text: JSON.stringify(enhanced),
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function enhanceDocumentsArray(documents, api) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
if (!(documents === null || documents === void 0 ? void 0 : documents.length)) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
const [correspondents, documentTypes, tags, customFields] = yield Promise.all([
|
|
65
|
+
api.getCorrespondents(),
|
|
66
|
+
api.getDocumentTypes(),
|
|
67
|
+
api.getTags(),
|
|
68
|
+
api.getCustomFields(),
|
|
69
|
+
]);
|
|
70
|
+
const correspondentMap = new Map((correspondents.results || []).map((c) => [c.id, c.name]));
|
|
71
|
+
const documentTypeMap = new Map((documentTypes.results || []).map((dt) => [dt.id, dt.name]));
|
|
72
|
+
const tagMap = new Map((tags.results || []).map((tag) => [tag.id, tag.name]));
|
|
73
|
+
const customFieldMap = new Map((customFields.results || []).map((cf) => [cf.id, cf.name]));
|
|
74
|
+
return documents
|
|
75
|
+
.map((doc) => {
|
|
76
|
+
const { content } = doc, docWithoutContent = __rest(doc, ["content"]);
|
|
77
|
+
// Content is deliberately excluded (the whole point of the enhancer),
|
|
78
|
+
// but its size is metadata callers need to plan bounded reads, so it
|
|
79
|
+
// survives the strip as content_length. page_count / mime_type are
|
|
80
|
+
// passed through only when the server supplied them (list responses
|
|
81
|
+
// omit them; the detail endpoint includes them).
|
|
82
|
+
const contentLength = typeof content === "string" ? content.length : undefined;
|
|
83
|
+
return contentLength === undefined
|
|
84
|
+
? docWithoutContent
|
|
85
|
+
: Object.assign(Object.assign({}, docWithoutContent), { content_length: contentLength });
|
|
86
|
+
})
|
|
87
|
+
.map((doc) => (Object.assign(Object.assign({}, doc), { correspondent: doc.correspondent
|
|
88
|
+
? {
|
|
89
|
+
id: doc.correspondent,
|
|
90
|
+
name: correspondentMap.get(doc.correspondent) ||
|
|
91
|
+
String(doc.correspondent),
|
|
92
|
+
}
|
|
93
|
+
: null, document_type: doc.document_type
|
|
94
|
+
? {
|
|
95
|
+
id: doc.document_type,
|
|
96
|
+
name: documentTypeMap.get(doc.document_type) || String(doc.document_type),
|
|
97
|
+
}
|
|
98
|
+
: null, tags: Array.isArray(doc.tags)
|
|
99
|
+
? doc.tags.map((tagId) => ({
|
|
100
|
+
id: tagId,
|
|
101
|
+
name: tagMap.get(tagId) || String(tagId),
|
|
102
|
+
}))
|
|
103
|
+
: doc.tags, custom_fields: Array.isArray(doc.custom_fields)
|
|
104
|
+
? doc.custom_fields.map((field) => ({
|
|
105
|
+
field: field.field,
|
|
106
|
+
name: customFieldMap.get(field.field) || String(field.field),
|
|
107
|
+
value: field.value,
|
|
108
|
+
}))
|
|
109
|
+
: doc.custom_fields })));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|