paperless-ngx
Version:
205 lines (202 loc) • 6.37 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __moduleCache = /* @__PURE__ */ new WeakMap;
var __toCommonJS = (from) => {
var entry = __moduleCache.get(from), desc;
if (entry)
return entry;
entry = __defProp({}, "__esModule", { value: true });
if (from && typeof from === "object" || typeof from === "function")
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
}));
__moduleCache.set(from, entry);
return entry;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, {
get: all[name],
enumerable: true,
configurable: true,
set: (newValue) => all[name] = () => newValue
});
};
// src/index.ts
var exports_src = {};
__export(exports_src, {
PaperlessClient: () => PaperlessClient
});
module.exports = __toCommonJS(exports_src);
class PaperlessClient {
baseUrl;
token;
constructor(baseUrl, token) {
this.baseUrl = baseUrl;
this.token = token;
}
async request(method, path, body) {
const response = await fetch(`${this.baseUrl}${path}`, {
method,
headers: {
Authorization: `Token ${this.token}`,
"Content-Type": "application/json"
},
body: body ? JSON.stringify(body) : undefined
});
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}
return response.json();
}
async getDocuments() {
return this.request("GET", "/api/documents/");
}
async getDocument(id) {
return this.request("GET", `/api/documents/${id}/`);
}
async createDocument(document) {
return this.request("POST", "/api/documents/", document);
}
async updateDocument(id, document) {
return this.request("PATCH", `/api/documents/${id}/`, document);
}
async deleteDocument(id) {
await this.request("DELETE", `/api/documents/${id}/`);
}
async getTags() {
return this.request("GET", "/api/tags/");
}
async getTag(id) {
return this.request("GET", `/api/tags/${id}/`);
}
async createTag(tag) {
return this.request("POST", "/api/tags/", tag);
}
async updateTag(id, tag) {
return this.request("PATCH", `/api/tags/${id}/`, tag);
}
async deleteTag(id) {
await this.request("DELETE", `/api/tags/${id}/`);
}
async getCorrespondents() {
return this.request("GET", "/api/correspondents/");
}
async getCorrespondent(id) {
return this.request("GET", `/api/correspondents/${id}/`);
}
async createCorrespondent(correspondent) {
return this.request("POST", "/api/correspondents/", correspondent);
}
async updateCorrespondent(id, correspondent) {
return this.request("PATCH", `/api/correspondents/${id}/`, correspondent);
}
async deleteCorrespondent(id) {
await this.request("DELETE", `/api/correspondents/${id}/`);
}
async getDocumentTypes() {
return this.request("GET", "/api/document_types/");
}
async getDocumentType(id) {
return this.request("GET", `/api/document_types/${id}/`);
}
async createDocumentType(documentType) {
return this.request("POST", "/api/document_types/", documentType);
}
async updateDocumentType(id, documentType) {
return this.request("PATCH", `/api/document_types/${id}/`, documentType);
}
async deleteDocumentType(id) {
await this.request("DELETE", `/api/document_types/${id}/`);
}
async getCustomFields() {
return this.request("GET", "/api/custom_fields/");
}
async getCustomField(id) {
return this.request("GET", `/api/custom_fields/${id}/`);
}
async createCustomField(customField) {
return this.request("POST", "/api/custom_fields/", customField);
}
async updateCustomField(id, customField) {
return this.request("PATCH", `/api/custom_fields/${id}/`, customField);
}
async deleteCustomField(id) {
await this.request("DELETE", `/api/custom_fields/${id}/`);
}
async getUsers() {
return this.request("GET", "/api/users/");
}
async getUser(id) {
return this.request("GET", `/api/users/${id}/`);
}
async createUser(user) {
return this.request("POST", "/api/users/", user);
}
async updateUser(id, user) {
return this.request("PATCH", `/api/users/${id}/`, user);
}
async deleteUser(id) {
await this.request("DELETE", `/api/users/${id}/`);
}
async getGroups() {
return this.request("GET", "/api/groups/");
}
async getGroup(id) {
return this.request("GET", `/api/groups/${id}/`);
}
async createGroup(group) {
return this.request("POST", "/api/groups/", group);
}
async updateGroup(id, group) {
return this.request("PATCH", `/api/groups/${id}/`, group);
}
async deleteGroup(id) {
await this.request("DELETE", `/api/groups/${id}/`);
}
async getShareLinks() {
return this.request("GET", "/api/share_links/");
}
async getShareLink(id) {
return this.request("GET", `/api/share_links/${id}/`);
}
async createShareLink(shareLink) {
return this.request("POST", "/api/share_links/", shareLink);
}
async deleteShareLink(id) {
await this.request("DELETE", `/api/share_links/${id}/`);
}
async getStoragePaths() {
return this.request("GET", "/api/storage_paths/");
}
async getStoragePath(id) {
return this.request("GET", `/api/storage_paths/${id}/`);
}
async createStoragePath(storagePath) {
return this.request("POST", "/api/storage_paths/", storagePath);
}
async updateStoragePath(id, storagePath) {
return this.request("PATCH", `/api/storage_paths/${id}/`, storagePath);
}
async deleteStoragePath(id) {
await this.request("DELETE", `/api/storage_paths/${id}/`);
}
async getWorkflows() {
return this.request("GET", "/api/workflows/");
}
async getWorkflow(id) {
return this.request("GET", `/api/workflows/${id}/`);
}
async createWorkflow(workflow) {
return this.request("POST", "/api/workflows/", workflow);
}
async updateWorkflow(id, workflow) {
return this.request("PATCH", `/api/workflows/${id}/`, workflow);
}
async deleteWorkflow(id) {
await this.request("DELETE", `/api/workflows/${id}/`);
}
}