mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 18:39:22 +08:00
Merge branch 'develop' into patch-style
This commit is contained in:
commit
f4358f3dc1
@ -40,7 +40,7 @@
|
||||
"@types/express": "5.0.1",
|
||||
"@types/node": "22.15.29",
|
||||
"@types/yargs": "17.0.33",
|
||||
"@vitest/coverage-v8": "3.1.4",
|
||||
"@vitest/coverage-v8": "3.2.1",
|
||||
"eslint": "9.28.0",
|
||||
"eslint-plugin-simple-import-sort": "12.1.1",
|
||||
"esm": "3.2.25",
|
||||
|
@ -1,52 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attachments
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"ownerId": "{{createdNoteId}}",
|
||||
"role": "file",
|
||||
"mime": "text/plain",
|
||||
"title": "my attachment",
|
||||
"content": "text"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttachmentId", response.body.attachmentId); %}
|
||||
|
||||
###
|
||||
|
||||
DELETE {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
### repeat the DELETE request to test the idempotency
|
||||
|
||||
DELETE {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "ATTACHMENT_NOT_FOUND");
|
||||
%}
|
@ -1,52 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attributes
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "{{createdNoteId}}",
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": true
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttributeId", response.body.attributeId); %}
|
||||
|
||||
###
|
||||
|
||||
DELETE {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
### repeat the DELETE request to test the idempotency
|
||||
|
||||
DELETE {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "ATTRIBUTE_NOT_FOUND");
|
||||
%}
|
@ -1,87 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.global.set("createdNoteId", response.body.note.noteId);
|
||||
client.global.set("createdBranchId", response.body.branch.branchId);
|
||||
%}
|
||||
|
||||
### Clone to another location
|
||||
|
||||
POST {{triliumHost}}/etapi/branches
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "{{createdNoteId}}",
|
||||
"parentNoteId": "_hidden"
|
||||
}
|
||||
|
||||
> {% client.global.set("clonedBranchId", response.body.branchId); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{clonedBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
DELETE {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
### repeat the DELETE request to test the idempotency
|
||||
|
||||
DELETE {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "BRANCH_NOT_FOUND");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{clonedBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
@ -1,126 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.global.set("createdNoteId", response.body.note.noteId);
|
||||
client.global.set("createdBranchId", response.body.branch.branchId);
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attributes
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "{{createdNoteId}}",
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": true
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttributeId", response.body.attributeId); %}
|
||||
|
||||
### Clone to another location
|
||||
|
||||
POST {{triliumHost}}/etapi/branches
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "{{createdNoteId}}",
|
||||
"parentNoteId": "_hidden"
|
||||
}
|
||||
|
||||
> {% client.global.set("clonedBranchId", response.body.branchId); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{clonedBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
DELETE {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
### repeat the DELETE request to test the idempotency
|
||||
|
||||
DELETE {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 204, "Response status is not 204"); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "BRANCH_NOT_FOUND");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{clonedBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code == "BRANCH_NOT_FOUND");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "NOTE_NOT_FOUND");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 404, "Response status is not 404");
|
||||
client.assert(response.body.code === "ATTRIBUTE_NOT_FOUND");
|
||||
%}
|
@ -1,37 +0,0 @@
|
||||
GET {{triliumHost}}/etapi/notes/root/export
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 200);
|
||||
client.assert(response.headers.valueOf("Content-Type") == "application/zip");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/root/export?format=html
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 200);
|
||||
client.assert(response.headers.valueOf("Content-Type") == "application/zip");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/root/export?format=markdown
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 200);
|
||||
client.assert(response.headers.valueOf("Content-Type") == "application/zip");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/root/export?format=wrong
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code === "UNRECOGNIZED_EXPORT_FORMAT");
|
||||
%}
|
@ -1,72 +0,0 @@
|
||||
GET {{triliumHost}}/etapi/inbox/2022-01-01
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/calendar/days/2022-01-01
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/calendar/days/2022-1
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code === "DATE_INVALID");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/calendar/weeks/2022-01-01
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/calendar/weeks/2022-1
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code === "DATE_INVALID");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/calendar/months/2022-01
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/calendar/months/2022-1
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code === "MONTH_INVALID");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/calendar/years/2022
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.status === 200); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/calendar/years/202
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code === "YEAR_INVALID");
|
||||
%}
|
@ -1,116 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello parent",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 201);
|
||||
client.global.set("parentNoteId", response.body.note.noteId);
|
||||
client.global.set("parentBranchId", response.body.branch.branchId);
|
||||
%}
|
||||
|
||||
### Create inheritable parent attribute
|
||||
|
||||
POST {{triliumHost}}/etapi/attributes
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "{{parentNoteId}}",
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "",
|
||||
"isInheritable": true,
|
||||
"position": 10
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 201);
|
||||
client.global.set("parentAttributeId", response.body.attributeId);
|
||||
%}
|
||||
|
||||
### Create child note under root
|
||||
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello child",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 201);
|
||||
client.global.set("childNoteId", response.body.note.noteId);
|
||||
client.global.set("childBranchId", response.body.branch.branchId);
|
||||
%}
|
||||
|
||||
### Create child attribute
|
||||
|
||||
POST {{triliumHost}}/etapi/attributes
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "{{childNoteId}}",
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": false,
|
||||
"position": 10
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 201);
|
||||
client.global.set("childAttributeId", response.body.attributeId);
|
||||
%}
|
||||
|
||||
### Clone child to parent
|
||||
|
||||
POST {{triliumHost}}/etapi/branches
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "{{childNoteId}}",
|
||||
"parentNoteId": "{{parentNoteId}}"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 201);
|
||||
client.assert(response.body.parentNoteId == client.global.get("parentNoteId"));
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{childNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
|
||||
function hasAttribute(list, attributeId) {
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if (list[i]["attributeId"] === attributeId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
client.log(JSON.stringify(response.body.attributes));
|
||||
|
||||
client.assert(response.status === 200);
|
||||
client.assert(response.body.noteId == client.global.get("childNoteId"));
|
||||
client.assert(response.body.attributes.length == 2);
|
||||
client.assert(hasAttribute(response.body.attributes, client.global.get("parentAttributeId")));
|
||||
client.assert(hasAttribute(response.body.attributes, client.global.get("childAttributeId")));
|
||||
%}
|
@ -1,61 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "GetInheritedAttributes Test Note",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 201);
|
||||
client.global.set("parentNoteId", response.body.note.noteId);
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attributes
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "{{parentNoteId}}",
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": true
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttributeId", response.body.attributeId); %}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "{{parentNoteId}}",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.global.set("createdNoteId", response.body.note.noteId);
|
||||
client.global.set("createdBranchId", response.body.branch.branchId);
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 200);
|
||||
client.assert(response.body.noteId == client.global.get("createdNoteId"));
|
||||
client.assert(response.body.attributes.length == 1);
|
||||
client.assert(response.body.attributes[0].attributeId == client.global.get("createdAttributeId"));
|
||||
%}
|
@ -1,25 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.global.set("createdNoteId", response.body.note.noteId);
|
||||
client.global.set("createdBranchId", response.body.branch.branchId);
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}/content
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 200);
|
||||
client.assert(response.body === "Hi there!");
|
||||
%}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"dev": {
|
||||
"triliumHost": "http://localhost:37740"
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/notes/root/import
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/octet-stream
|
||||
Content-Transfer-Encoding: binary
|
||||
|
||||
< ../db/demo.zip
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 201);
|
||||
client.assert(response.body.note.title == "Trilium Demo");
|
||||
client.assert(response.body.branch.parentNoteId == "root");
|
||||
%}
|
@ -1,82 +0,0 @@
|
||||
### Test ETAPI metrics endpoint
|
||||
|
||||
# First login to get a token
|
||||
POST {{triliumHost}}/etapi/auth/login
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"password": "{{password}}"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.test("Login successful", function() {
|
||||
client.assert(response.status === 201, "Response status is not 201");
|
||||
client.assert(response.body.authToken, "Auth token not present");
|
||||
client.global.set("authToken", response.body.authToken);
|
||||
});
|
||||
%}
|
||||
|
||||
### Get metrics with authentication (default Prometheus format)
|
||||
GET {{triliumHost}}/etapi/metrics
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.test("Metrics endpoint returns Prometheus format by default", function() {
|
||||
client.assert(response.status === 200, "Response status is not 200");
|
||||
client.assert(response.headers["content-type"].includes("text/plain"), "Content-Type should be text/plain");
|
||||
client.assert(response.body.includes("trilium_info"), "Should contain trilium_info metric");
|
||||
client.assert(response.body.includes("trilium_notes_total"), "Should contain trilium_notes_total metric");
|
||||
client.assert(response.body.includes("# HELP"), "Should contain HELP comments");
|
||||
client.assert(response.body.includes("# TYPE"), "Should contain TYPE comments");
|
||||
});
|
||||
%}
|
||||
|
||||
### Get metrics in JSON format
|
||||
GET {{triliumHost}}/etapi/metrics?format=json
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.test("Metrics endpoint returns JSON when requested", function() {
|
||||
client.assert(response.status === 200, "Response status is not 200");
|
||||
client.assert(response.headers["content-type"].includes("application/json"), "Content-Type should be application/json");
|
||||
client.assert(response.body.version, "Version info not present");
|
||||
client.assert(response.body.database, "Database info not present");
|
||||
client.assert(response.body.timestamp, "Timestamp not present");
|
||||
client.assert(typeof response.body.database.totalNotes === 'number', "Total notes should be a number");
|
||||
client.assert(typeof response.body.database.activeNotes === 'number', "Active notes should be a number");
|
||||
});
|
||||
%}
|
||||
|
||||
### Get metrics in Prometheus format explicitly
|
||||
GET {{triliumHost}}/etapi/metrics?format=prometheus
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.test("Metrics endpoint returns Prometheus format when requested", function() {
|
||||
client.assert(response.status === 200, "Response status is not 200");
|
||||
client.assert(response.headers["content-type"].includes("text/plain"), "Content-Type should be text/plain");
|
||||
client.assert(response.body.includes("trilium_info"), "Should contain trilium_info metric");
|
||||
client.assert(response.body.includes("trilium_notes_total"), "Should contain trilium_notes_total metric");
|
||||
});
|
||||
%}
|
||||
|
||||
### Test invalid format parameter
|
||||
GET {{triliumHost}}/etapi/metrics?format=xml
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.test("Invalid format parameter returns error", function() {
|
||||
client.assert(response.status === 400, "Response status should be 400");
|
||||
client.assert(response.body.code === "INVALID_FORMAT", "Error code should be INVALID_FORMAT");
|
||||
client.assert(response.body.message.includes("prometheus"), "Error message should mention supported formats");
|
||||
});
|
||||
%}
|
||||
|
||||
### Test without authentication (should fail)
|
||||
GET {{triliumHost}}/etapi/metrics
|
||||
|
||||
> {%
|
||||
client.test("Metrics endpoint requires authentication", function() {
|
||||
client.assert(response.status === 401, "Response status should be 401");
|
||||
});
|
||||
%}
|
@ -1,79 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attachments
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"ownerId": "{{createdNoteId}}",
|
||||
"role": "file",
|
||||
"mime": "text/plain",
|
||||
"title": "my attachment",
|
||||
"content": "text"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttachmentId", response.body.attachmentId); %}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"title": "CHANGED",
|
||||
"position": 999
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.body.title === "CHANGED");
|
||||
client.assert(response.body.position === 999);
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"ownerId": "root"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code == "PROPERTY_NOT_ALLOWED");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"title": null
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code == "PROPERTY_VALIDATION_ERROR");
|
||||
%}
|
@ -1,80 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.global.set("createdNoteId", response.body.note.noteId);
|
||||
client.global.set("createdBranchId", response.body.branch.branchId);
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attributes
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "{{createdNoteId}}",
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": true
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttributeId", response.body.attributeId); %}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"value": "CHANGED"
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.body.value === "CHANGED");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"noteId": "root"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code == "PROPERTY_NOT_ALLOWED");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/attributes/{{createdAttributeId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"value": null
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code == "PROPERTY_VALIDATION_ERROR");
|
||||
%}
|
@ -1,66 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"type": "text",
|
||||
"title": "Hello",
|
||||
"content": ""
|
||||
}
|
||||
|
||||
> {% client.global.set("createdBranchId", response.body.branch.branchId); %}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"prefix": "pref",
|
||||
"notePosition": 666,
|
||||
"isExpanded": true
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 200);
|
||||
client.assert(response.body.prefix === 'pref');
|
||||
client.assert(response.body.notePosition === 666);
|
||||
client.assert(response.body.isExpanded === true);
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root"
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code == "PROPERTY_NOT_ALLOWED");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/branches/{{createdBranchId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"prefix": 123
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code == "PROPERTY_VALIDATION_ERROR");
|
||||
%}
|
@ -1,83 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "code",
|
||||
"mime": "application/json",
|
||||
"content": "{}"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 200);
|
||||
client.assert(response.body.title === 'Hello');
|
||||
client.assert(response.body.type === 'code');
|
||||
client.assert(response.body.mime === 'application/json');
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"title": "Wassup",
|
||||
"type": "html",
|
||||
"mime": "text/html",
|
||||
"dateCreated": "2023-08-21 23:38:51.123+0200",
|
||||
"utcDateCreated": "2023-08-21 23:38:51.123Z"
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 200);
|
||||
client.assert(response.body.title === 'Wassup');
|
||||
client.assert(response.body.type === 'html');
|
||||
client.assert(response.body.mime === 'text/html');
|
||||
client.assert(response.body.dateCreated == "2023-08-21 23:38:51.123+0200");
|
||||
client.assert(response.body.utcDateCreated == "2023-08-21 23:38:51.123Z");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"isProtected": true
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code == "PROPERTY_NOT_ALLOWED");
|
||||
%}
|
||||
|
||||
###
|
||||
|
||||
PATCH {{triliumHost}}/etapi/notes/{{createdNoteId}}
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"title": true
|
||||
}
|
||||
|
||||
> {%
|
||||
client.assert(response.status === 400);
|
||||
client.assert(response.body.code == "PROPERTY_VALIDATION_ERROR");
|
||||
%}
|
@ -1,23 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "code",
|
||||
"mime": "text/plain",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/notes/{{createdNoteId}}/revision
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: text/plain
|
||||
|
||||
Changed content
|
||||
|
||||
> {% client.assert(response.status === 204); %}
|
@ -1,39 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attachments
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"ownerId": "{{createdNoteId}}",
|
||||
"role": "file",
|
||||
"mime": "text/plain",
|
||||
"title": "my attachment",
|
||||
"content": "text"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttachmentId", response.body.attachmentId); %}
|
||||
|
||||
###
|
||||
|
||||
PUT {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}/content
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/octet-stream
|
||||
Content-Transfer-Encoding: binary
|
||||
|
||||
< ../images/icon-color.png
|
||||
|
||||
> {% client.assert(response.status === 204); %}
|
@ -1,45 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
POST {{triliumHost}}/etapi/attachments
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"ownerId": "{{createdNoteId}}",
|
||||
"role": "file",
|
||||
"mime": "text/plain",
|
||||
"title": "my attachment",
|
||||
"content": "text"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdAttachmentId", response.body.attachmentId); %}
|
||||
|
||||
###
|
||||
|
||||
PUT {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}/content
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: text/plain
|
||||
|
||||
Changed content
|
||||
|
||||
> {% client.assert(response.status === 204); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/attachments/{{createdAttachmentId}}/content
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.body === "Changed content"); %}
|
@ -1,25 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "image",
|
||||
"mime": "image/png",
|
||||
"content": ""
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
PUT {{triliumHost}}/etapi/notes/{{createdNoteId}}/content
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/octet-stream
|
||||
Content-Transfer-Encoding: binary
|
||||
|
||||
< ../images/icon-color.png
|
||||
|
||||
> {% client.assert(response.status === 204); %}
|
||||
|
@ -1,30 +0,0 @@
|
||||
POST {{triliumHost}}/etapi/create-note
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "code",
|
||||
"mime": "text/plain",
|
||||
"content": "Hi there!"
|
||||
}
|
||||
|
||||
> {% client.global.set("createdNoteId", response.body.note.noteId); %}
|
||||
|
||||
###
|
||||
|
||||
PUT {{triliumHost}}/etapi/notes/{{createdNoteId}}/content
|
||||
Authorization: {{authToken}}
|
||||
Content-Type: text/plain
|
||||
|
||||
Changed content
|
||||
|
||||
> {% client.assert(response.status === 204); %}
|
||||
|
||||
###
|
||||
|
||||
GET {{triliumHost}}/etapi/notes/{{createdNoteId}}/content
|
||||
Authorization: {{authToken}}
|
||||
|
||||
> {% client.assert(response.body === "Changed content"); %}
|
@ -66,7 +66,7 @@
|
||||
"@types/react": "19.1.6",
|
||||
"@types/react-dom": "19.1.5",
|
||||
"copy-webpack-plugin": "13.0.0",
|
||||
"happy-dom": "17.5.6",
|
||||
"happy-dom": "17.6.1",
|
||||
"script-loader": "0.7.2",
|
||||
"vite-plugin-static-copy": "3.0.0"
|
||||
},
|
||||
|
@ -222,7 +222,6 @@ export function buildFloatingToolbar() {
|
||||
"|",
|
||||
"code",
|
||||
"link",
|
||||
"bookmark",
|
||||
"removeFormat",
|
||||
"internallink",
|
||||
"cuttonote"
|
||||
@ -244,7 +243,7 @@ export function buildFloatingToolbar() {
|
||||
{
|
||||
label: "Insert",
|
||||
icon: "plus",
|
||||
items: ["internallink", "includeNote", "|", "math", "mermaid", "horizontalLine", "pageBreak"]
|
||||
items: ["bookmark", "internallink", "includeNote", "|", "math", "mermaid", "horizontalLine", "pageBreak"]
|
||||
},
|
||||
"|",
|
||||
"outdent",
|
||||
|
@ -31,7 +31,6 @@
|
||||
"config": {
|
||||
"forge": "./electron-forge/forge.config.cjs"
|
||||
},
|
||||
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977",
|
||||
"scripts": {
|
||||
"start-prod": "nx build desktop && cross-env TRILIUM_DATA_DIR=data TRILIUM_RESOURCE_DIR=dist TRILIUM_PORT=37841 electron dist/main.js"
|
||||
},
|
||||
|
@ -85,10 +85,10 @@
|
||||
"jsdom": "26.1.0",
|
||||
"marked": "15.0.12",
|
||||
"mime-types": "3.0.1",
|
||||
"multer": "2.0.0",
|
||||
"multer": "2.0.1",
|
||||
"normalize-strings": "1.1.1",
|
||||
"ollama": "0.5.16",
|
||||
"openai": "5.0.1",
|
||||
"openai": "5.1.0",
|
||||
"rand-token": "1.0.1",
|
||||
"safe-compare": "1.1.4",
|
||||
"sanitize-filename": "1.6.3",
|
||||
|
64
apps/server/spec/etapi/attachment-content.spec.ts
Normal file
64
apps/server/spec/etapi/attachment-content.spec.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
let createdNoteId: string;
|
||||
let createdAttachmentId: string;
|
||||
|
||||
describe("etapi/attachment-content", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
createdNoteId = await createNote(app, token);
|
||||
|
||||
// Create an attachment
|
||||
const response = await supertest(app)
|
||||
.post(`/etapi/attachments`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
"ownerId": createdNoteId,
|
||||
"role": "file",
|
||||
"mime": "text/plain",
|
||||
"title": "my attachment",
|
||||
"content": "text"
|
||||
});
|
||||
createdAttachmentId = response.body.attachmentId;
|
||||
expect(createdAttachmentId).toBeTruthy();
|
||||
});
|
||||
|
||||
it("changes attachment content", async () => {
|
||||
const text = "Changed content";
|
||||
await supertest(app)
|
||||
.put(`/etapi/attachments/${createdAttachmentId}/content`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.set("Content-Type", "text/plain")
|
||||
.send(text)
|
||||
.expect(204);
|
||||
|
||||
// Ensure it got changed.
|
||||
const response = await supertest(app)
|
||||
.get(`/etapi/attachments/${createdAttachmentId}/content`)
|
||||
.auth(USER, token, { "type": "basic"});
|
||||
expect(response.text).toStrictEqual(text);
|
||||
});
|
||||
|
||||
it("supports binary content", async() => {
|
||||
await supertest(app)
|
||||
.put(`/etapi/attachments/${createdAttachmentId}/content`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.set("Content-Type", "application/octet-stream")
|
||||
.set("Content-Transfer-Encoding", "binary")
|
||||
.send(Buffer.from("Hello world"))
|
||||
.expect(204);
|
||||
});
|
||||
|
||||
});
|
@ -21,6 +21,6 @@ describe("etapi/backup", () => {
|
||||
const response = await supertest(app)
|
||||
.put("/etapi/backup/etapi_test")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(201);
|
||||
.expect(204);
|
||||
});
|
||||
});
|
||||
|
172
apps/server/spec/etapi/delete-entities.spec.ts
Normal file
172
apps/server/spec/etapi/delete-entities.spec.ts
Normal file
@ -0,0 +1,172 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, beforeEach, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
import { randomInt } from "crypto";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
let createdNoteId: string;
|
||||
let createdBranchId: string;
|
||||
|
||||
const USER = "etapi";
|
||||
|
||||
type EntityType = "attachments" | "attributes" | "branches" | "notes";
|
||||
|
||||
describe("etapi/delete-entities", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
({ createdNoteId, createdBranchId } = await createNote());
|
||||
});
|
||||
|
||||
it("deletes attachment", async () => {
|
||||
const attachmentId = await createAttachment();
|
||||
await deleteEntity("attachments", attachmentId);
|
||||
await expectNotFound("attachments", attachmentId);
|
||||
});
|
||||
|
||||
it("deletes attribute", async () => {
|
||||
const attributeId = await createAttribute();
|
||||
await deleteEntity("attributes", attributeId);
|
||||
await expectNotFound("attributes", attributeId);
|
||||
});
|
||||
|
||||
it("deletes cloned branch", async () => {
|
||||
const clonedBranchId = await createClone();
|
||||
|
||||
await expectFound("branches", createdBranchId);
|
||||
await expectFound("branches", clonedBranchId);
|
||||
|
||||
await deleteEntity("branches", createdBranchId);
|
||||
await expectNotFound("branches", createdBranchId);
|
||||
|
||||
await expectFound("branches", clonedBranchId);
|
||||
await expectFound("notes", createdNoteId);
|
||||
});
|
||||
|
||||
it("deletes note with all branches", async () => {
|
||||
const attributeId = await createAttribute();
|
||||
|
||||
const clonedBranchId = await createClone();
|
||||
|
||||
await expectFound("notes", createdNoteId);
|
||||
await expectFound("branches", createdBranchId);
|
||||
await expectFound("branches", clonedBranchId);
|
||||
await expectFound("attributes", attributeId);
|
||||
await deleteEntity("notes", createdNoteId);
|
||||
|
||||
await expectNotFound("branches", createdBranchId);
|
||||
await expectNotFound("branches", clonedBranchId);
|
||||
await expectNotFound("notes", createdNoteId);
|
||||
await expectNotFound("attributes", attributeId);
|
||||
});
|
||||
});
|
||||
|
||||
async function createNote() {
|
||||
const noteId = `forcedId${randomInt(1000)}`;
|
||||
const response = await supertest(app)
|
||||
.post("/etapi/create-note")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
"noteId": noteId,
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!",
|
||||
"dateCreated": "2023-08-21 23:38:51.123+0200",
|
||||
"utcDateCreated": "2023-08-21 23:38:51.123Z"
|
||||
})
|
||||
.expect(201);
|
||||
expect(response.body.note.noteId).toStrictEqual(noteId);
|
||||
|
||||
return {
|
||||
createdNoteId: response.body.note.noteId,
|
||||
createdBranchId: response.body.branch.branchId
|
||||
};
|
||||
}
|
||||
|
||||
async function createClone() {
|
||||
const response = await supertest(app)
|
||||
.post("/etapi/branches")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
noteId: createdNoteId,
|
||||
parentNoteId: "_hidden"
|
||||
})
|
||||
.expect(201);
|
||||
expect(response.body.parentNoteId).toStrictEqual("_hidden");
|
||||
return response.body.branchId;
|
||||
}
|
||||
|
||||
async function createAttribute() {
|
||||
const attributeId = `forcedId${randomInt(1000)}`;
|
||||
const response = await supertest(app)
|
||||
.post("/etapi/attributes")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
"attributeId": attributeId,
|
||||
"noteId": createdNoteId,
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": true
|
||||
})
|
||||
.expect(201);
|
||||
expect(response.body.attributeId).toStrictEqual(attributeId);
|
||||
return response.body.attributeId;
|
||||
}
|
||||
|
||||
async function createAttachment() {
|
||||
const response = await supertest(app)
|
||||
.post("/etapi/attachments")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
"ownerId": createdNoteId,
|
||||
"role": "file",
|
||||
"mime": "plain/text",
|
||||
"title": "my attachment",
|
||||
"content": "my text"
|
||||
})
|
||||
.expect(201);
|
||||
return response.body.attachmentId;
|
||||
}
|
||||
|
||||
async function deleteEntity(entity: EntityType, id: string) {
|
||||
// Delete twice to test idempotency.
|
||||
for (let i=0; i < 2; i++) {
|
||||
await supertest(app)
|
||||
.delete(`/etapi/${entity}/${id}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(204);
|
||||
}
|
||||
}
|
||||
|
||||
const MISSING_ENTITY_ERROR_CODES: Record<EntityType, string> = {
|
||||
attachments: "ATTACHMENT_NOT_FOUND",
|
||||
attributes: "ATTRIBUTE_NOT_FOUND",
|
||||
branches: "BRANCH_NOT_FOUND",
|
||||
notes: "NOTE_NOT_FOUND"
|
||||
}
|
||||
|
||||
async function expectNotFound(entity: EntityType, id: string) {
|
||||
const response = await supertest(app)
|
||||
.get(`/etapi/${entity}/${id}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(404);
|
||||
|
||||
expect(response.body.code).toStrictEqual(MISSING_ENTITY_ERROR_CODES[entity]);
|
||||
}
|
||||
|
||||
async function expectFound(entity: EntityType, id: string) {
|
||||
await supertest(app)
|
||||
.get(`/etapi/${entity}/${id}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
}
|
71
apps/server/spec/etapi/etapi-metrics.spec.ts
Normal file
71
apps/server/spec/etapi/etapi-metrics.spec.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
|
||||
describe("etapi/metrics", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
});
|
||||
|
||||
it("returns Prometheus format by default", async () => {
|
||||
const response = await supertest(app)
|
||||
.get("/etapi/metrics")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
expect(response.headers["content-type"]).toContain("text/plain");
|
||||
expect(response.text).toContain("trilium_info");
|
||||
expect(response.text).toContain("trilium_notes_total");
|
||||
expect(response.text).toContain("# HELP");
|
||||
expect(response.text).toContain("# TYPE");
|
||||
});
|
||||
|
||||
it("returns JSON when requested", async() => {
|
||||
const response = await supertest(app)
|
||||
.get("/etapi/metrics?format=json")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
expect(response.headers["content-type"]).toContain("application/json");
|
||||
expect(response.body.version).toBeTruthy();
|
||||
expect(response.body.database).toBeTruthy();
|
||||
expect(response.body.timestamp).toBeTruthy();
|
||||
expect(response.body.database.totalNotes).toBeTypeOf("number");
|
||||
expect(response.body.database.activeNotes).toBeTypeOf("number");
|
||||
expect(response.body.noteTypes).toBeTruthy();
|
||||
expect(response.body.attachmentTypes).toBeTruthy();
|
||||
expect(response.body.statistics).toBeTruthy();
|
||||
});
|
||||
|
||||
it("returns Prometheus format explicitly", async () => {
|
||||
const response = await supertest(app)
|
||||
.get("/etapi/metrics?format=prometheus")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
expect(response.headers["content-type"]).toContain("text/plain");
|
||||
expect(response.text).toContain("trilium_info");
|
||||
expect(response.text).toContain("trilium_notes_total");
|
||||
});
|
||||
|
||||
it("returns error on invalid format", async() => {
|
||||
const response = await supertest(app)
|
||||
.get("/etapi/metrics?format=xml")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(500);
|
||||
expect(response.body.message).toContain("prometheus");
|
||||
});
|
||||
|
||||
it("should fail without authentication", async() => {
|
||||
await supertest(app)
|
||||
.get("/etapi/metrics")
|
||||
.expect(401);
|
||||
});
|
||||
});
|
51
apps/server/spec/etapi/export-note-subtree.spec.ts
Normal file
51
apps/server/spec/etapi/export-note-subtree.spec.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
|
||||
describe("etapi/export-note-subtree", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
});
|
||||
|
||||
it("export works", async () => {
|
||||
await supertest(app)
|
||||
.get("/etapi/notes/root/export")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200)
|
||||
.expect("Content-Type", "application/zip");
|
||||
});
|
||||
|
||||
it("HTML export works", async () => {
|
||||
await supertest(app)
|
||||
.get("/etapi/notes/root/export?format=html")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200)
|
||||
.expect("Content-Type", "application/zip");
|
||||
});
|
||||
|
||||
it("Markdown export works", async () => {
|
||||
await supertest(app)
|
||||
.get("/etapi/notes/root/export?format=markdown")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200)
|
||||
.expect("Content-Type", "application/zip");
|
||||
});
|
||||
|
||||
it("reports wrong format", async () => {
|
||||
const response = await supertest(app)
|
||||
.get("/etapi/notes/root/export?format=wrong")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("UNRECOGNIZED_EXPORT_FORMAT");
|
||||
});
|
||||
});
|
103
apps/server/spec/etapi/get-date-notes.spec.ts
Normal file
103
apps/server/spec/etapi/get-date-notes.spec.ts
Normal file
@ -0,0 +1,103 @@
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import config from "../../src/services/config.js";
|
||||
import { login } from "./utils.js";
|
||||
import { Application } from "express";
|
||||
import supertest from "supertest";
|
||||
import date_notes from "../../src/services/date_notes.js";
|
||||
import cls from "../../src/services/cls.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
|
||||
describe("etapi/get-date-notes", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
});
|
||||
|
||||
it("obtains inbox", async () => {
|
||||
await supertest(app)
|
||||
.get("/etapi/inbox/2022-01-01")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
describe("days", () => {
|
||||
it("obtains day from calendar", async () => {
|
||||
await supertest(app)
|
||||
.get("/etapi/calendar/days/2022-01-01")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it("detects invalid date", async () => {
|
||||
const response = await supertest(app)
|
||||
.get("/etapi/calendar/days/2022-1")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("DATE_INVALID");
|
||||
});
|
||||
});
|
||||
|
||||
describe("weeks", () => {
|
||||
beforeAll(() => {
|
||||
cls.init(() => {
|
||||
const rootCalendarNote = date_notes.getRootCalendarNote();
|
||||
rootCalendarNote.setLabel("enableWeekNote");
|
||||
});
|
||||
});
|
||||
|
||||
it("obtains week calendar", async () => {
|
||||
await supertest(app)
|
||||
.get("/etapi/calendar/weeks/2022-W01")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it("detects invalid date", async () => {
|
||||
const response = await supertest(app)
|
||||
.get("/etapi/calendar/weeks/2022-1")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("WEEK_INVALID");
|
||||
});
|
||||
});
|
||||
|
||||
describe("months", () => {
|
||||
it("obtains month calendar", async () => {
|
||||
await supertest(app)
|
||||
.get("/etapi/calendar/months/2022-01")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it("detects invalid month", async () => {
|
||||
const response = await supertest(app)
|
||||
.get("/etapi/calendar/months/2022-1")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("MONTH_INVALID");
|
||||
});
|
||||
});
|
||||
|
||||
describe("years", () => {
|
||||
it("obtains year calendar", async () => {
|
||||
await supertest(app)
|
||||
.get("/etapi/calendar/years/2022")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
});
|
||||
|
||||
it("detects invalid year", async () => {
|
||||
const response = await supertest(app)
|
||||
.get("/etapi/calendar/years/202")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("YEAR_INVALID");
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,98 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
let parentNoteId: string;
|
||||
|
||||
describe("etapi/get-inherited-attribute-cloned", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
parentNoteId = await createNote(app, token);
|
||||
});
|
||||
|
||||
it("gets inherited attribute", async () => {
|
||||
// Create an inheritable attribute on the parent note.
|
||||
let response = await supertest(app)
|
||||
.post("/etapi/attributes")
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
"noteId": parentNoteId,
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": true,
|
||||
"position": 10
|
||||
})
|
||||
.expect(201);
|
||||
const parentAttributeId = response.body.attributeId;
|
||||
expect(parentAttributeId).toBeTruthy();
|
||||
|
||||
// Create a subnote.
|
||||
response = await supertest(app)
|
||||
.post("/etapi/create-note")
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
"parentNoteId": parentNoteId,
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
})
|
||||
.expect(201);
|
||||
const childNoteId = response.body.note.noteId;
|
||||
|
||||
// Create child attribute
|
||||
response = await supertest(app)
|
||||
.post("/etapi/attributes")
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
"noteId": childNoteId,
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": false,
|
||||
"position": 10
|
||||
})
|
||||
.expect(201);
|
||||
const childAttributeId = response.body.attributeId;
|
||||
expect(parentAttributeId).toBeTruthy();
|
||||
|
||||
// Clone child to parent
|
||||
response = await supertest(app)
|
||||
.post("/etapi/branches")
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
noteId: childNoteId,
|
||||
parentNoteId: parentNoteId
|
||||
})
|
||||
.expect(200);
|
||||
parentNoteId = response.body.parentNoteId;
|
||||
|
||||
// Check attribute IDs
|
||||
response = await supertest(app)
|
||||
.get(`/etapi/notes/${childNoteId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.expect(200);
|
||||
expect(response.body.noteId).toStrictEqual(childNoteId);
|
||||
expect(response.body.attributes).toHaveLength(2);
|
||||
expect(hasAttribute(response.body.attributes, parentAttributeId));
|
||||
expect(hasAttribute(response.body.attributes, childAttributeId));
|
||||
});
|
||||
|
||||
function hasAttribute(list: object[], attributeId: string) {
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if (list[i]["attributeId"] === attributeId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
60
apps/server/spec/etapi/get-inherited-attribute.spec.ts
Normal file
60
apps/server/spec/etapi/get-inherited-attribute.spec.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
let parentNoteId: string;
|
||||
|
||||
describe("etapi/get-inherited-attribute", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
parentNoteId = await createNote(app, token);
|
||||
});
|
||||
|
||||
it("gets inherited attribute", async () => {
|
||||
// Create an inheritable attribute on the parent note.
|
||||
let response = await supertest(app)
|
||||
.post("/etapi/attributes")
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
"noteId": parentNoteId,
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": true
|
||||
})
|
||||
.expect(201);
|
||||
const createdAttributeId = response.body.attributeId;
|
||||
expect(createdAttributeId).toBeTruthy();
|
||||
|
||||
// Create a subnote.
|
||||
response = await supertest(app)
|
||||
.post("/etapi/create-note")
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
"parentNoteId": parentNoteId,
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "Hi there!"
|
||||
})
|
||||
.expect(201);
|
||||
const createdNoteId = response.body.note.noteId;
|
||||
|
||||
// Check the attribute is inherited.
|
||||
response = await supertest(app)
|
||||
.get(`/etapi/notes/${createdNoteId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.expect(200);
|
||||
expect(response.body.noteId).toStrictEqual(createdNoteId);
|
||||
expect(response.body.attributes).toHaveLength(1);
|
||||
expect(response.body.attributes[0].attributeId === createdAttributeId);
|
||||
});
|
||||
});
|
34
apps/server/spec/etapi/import-zip.spec.ts
Normal file
34
apps/server/spec/etapi/import-zip.spec.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
import { readFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
|
||||
describe("etapi/import", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
});
|
||||
|
||||
it("demo zip can be imported", async () => {
|
||||
const buffer = readFileSync(join(__dirname, "../../src/assets/db/demo.zip"));
|
||||
const response = await supertest(app)
|
||||
.post("/etapi/notes/root/import")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.set("Content-Type", "application/octet-stream")
|
||||
.set("Content-Transfer-Encoding", "binary")
|
||||
.send(buffer)
|
||||
.expect(201);
|
||||
expect(response.body.note.title).toStrictEqual("Journal");
|
||||
expect(response.body.branch.parentNoteId).toStrictEqual("root");
|
||||
});
|
||||
});
|
72
apps/server/spec/etapi/note-content.spec.ts
Normal file
72
apps/server/spec/etapi/note-content.spec.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
let createdNoteId: string;
|
||||
|
||||
describe("etapi/note-content", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
createdNoteId = await createNote(app, token);
|
||||
});
|
||||
|
||||
it("get content", async () => {
|
||||
const response = await getContentResponse();
|
||||
expect(response.text).toStrictEqual("Hi there!");
|
||||
});
|
||||
|
||||
it("put note content", async () => {
|
||||
const text = "Changed content";
|
||||
await supertest(app)
|
||||
.put(`/etapi/notes/${createdNoteId}/content`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.set("Content-Type", "text/plain")
|
||||
.send(text)
|
||||
.expect(204);
|
||||
|
||||
const response = await getContentResponse();
|
||||
expect(response.text).toStrictEqual(text);
|
||||
});
|
||||
|
||||
it("put note content binary", async () => {
|
||||
// First, create a binary note
|
||||
const response = await supertest(app)
|
||||
.post("/etapi/create-note")
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"mime": "image/png",
|
||||
"type": "image",
|
||||
"content": ""
|
||||
})
|
||||
.expect(201);
|
||||
const createdNoteId = response.body.note.noteId;
|
||||
|
||||
// Put binary content
|
||||
await supertest(app)
|
||||
.put(`/etapi/notes/${createdNoteId}/content`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.set("Content-Type", "application/octet-stream")
|
||||
.set("Content-Transfer-Encoding", "binary")
|
||||
.send(Buffer.from("Hello world"))
|
||||
.expect(204);
|
||||
});
|
||||
|
||||
function getContentResponse() {
|
||||
return supertest(app)
|
||||
.get(`/etapi/notes/${createdNoteId}/content`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
}
|
||||
});
|
@ -21,6 +21,6 @@ describe("etapi/refresh-note-ordering/root", () => {
|
||||
await supertest(app)
|
||||
.post("/etapi/refresh-note-ordering/root")
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.expect(200);
|
||||
.expect(204);
|
||||
});
|
||||
});
|
||||
|
78
apps/server/spec/etapi/patch-attachment.spec.ts
Normal file
78
apps/server/spec/etapi/patch-attachment.spec.ts
Normal file
@ -0,0 +1,78 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
let createdNoteId: string;
|
||||
let createdAttachmentId: string;
|
||||
|
||||
describe("etapi/attachment-content", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
createdNoteId = await createNote(app, token);
|
||||
|
||||
// Create an attachment
|
||||
const response = await supertest(app)
|
||||
.post(`/etapi/attachments`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
"ownerId": createdNoteId,
|
||||
"role": "file",
|
||||
"mime": "text/plain",
|
||||
"title": "my attachment",
|
||||
"content": "text"
|
||||
});
|
||||
createdAttachmentId = response.body.attachmentId;
|
||||
expect(createdAttachmentId).toBeTruthy();
|
||||
});
|
||||
|
||||
it("changes title and position", async () => {
|
||||
const state = {
|
||||
title: "CHANGED",
|
||||
position: 999
|
||||
}
|
||||
await supertest(app)
|
||||
.patch(`/etapi/attachments/${createdAttachmentId}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send(state)
|
||||
.expect(200);
|
||||
|
||||
// Ensure it got changed.
|
||||
const response = await supertest(app)
|
||||
.get(`/etapi/attachments/${createdAttachmentId}`)
|
||||
.auth(USER, token, { "type": "basic"});
|
||||
expect(response.body).toMatchObject(state);
|
||||
});
|
||||
|
||||
it("forbids changing owner", async () => {
|
||||
const response = await supertest(app)
|
||||
.patch(`/etapi/attachments/${createdAttachmentId}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
ownerId: "root"
|
||||
})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("PROPERTY_NOT_ALLOWED");
|
||||
});
|
||||
|
||||
it("handles validation error", async () => {
|
||||
const response = await supertest(app)
|
||||
.patch(`/etapi/attachments/${createdAttachmentId}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
title: null
|
||||
})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("PROPERTY_VALIDATION_ERROR");
|
||||
});
|
||||
|
||||
});
|
77
apps/server/spec/etapi/patch-attribute.spec.ts
Normal file
77
apps/server/spec/etapi/patch-attribute.spec.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
let createdNoteId: string;
|
||||
let createdAttributeId: string;
|
||||
|
||||
describe("etapi/patch-attribute", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
createdNoteId = await createNote(app, token);
|
||||
|
||||
// Create an attribute
|
||||
const response = await supertest(app)
|
||||
.post(`/etapi/attributes`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
"noteId": createdNoteId,
|
||||
"type": "label",
|
||||
"name": "mylabel",
|
||||
"value": "val",
|
||||
"isInheritable": true
|
||||
});
|
||||
createdAttributeId = response.body.attributeId;
|
||||
expect(createdAttributeId).toBeTruthy();
|
||||
});
|
||||
|
||||
it("changes name and value", async () => {
|
||||
const state = {
|
||||
value: "CHANGED"
|
||||
};
|
||||
await supertest(app)
|
||||
.patch(`/etapi/attributes/${createdAttributeId}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send(state)
|
||||
.expect(200);
|
||||
|
||||
// Ensure it got changed.
|
||||
const response = await supertest(app)
|
||||
.get(`/etapi/attributes/${createdAttributeId}`)
|
||||
.auth(USER, token, { "type": "basic"});
|
||||
expect(response.body).toMatchObject(state);
|
||||
});
|
||||
|
||||
it("forbids setting disallowed property", async () => {
|
||||
const response = await supertest(app)
|
||||
.patch(`/etapi/attributes/${createdAttributeId}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
noteId: "root"
|
||||
})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("PROPERTY_NOT_ALLOWED");
|
||||
});
|
||||
|
||||
it("forbids setting wrong data type", async () => {
|
||||
const response = await supertest(app)
|
||||
.patch(`/etapi/attributes/${createdAttributeId}`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send({
|
||||
value: null
|
||||
})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("PROPERTY_VALIDATION_ERROR");
|
||||
});
|
||||
|
||||
});
|
77
apps/server/spec/etapi/patch-branch.spec.ts
Normal file
77
apps/server/spec/etapi/patch-branch.spec.ts
Normal file
@ -0,0 +1,77 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
let createdBranchId: string;
|
||||
|
||||
describe("etapi/attachment-content", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
// Create a note and a branch.
|
||||
const response = await supertest(app)
|
||||
.post("/etapi/create-note")
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "text",
|
||||
"content": "",
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
createdBranchId = response.body.branch.branchId;
|
||||
});
|
||||
|
||||
it("can patch branch info", async () => {
|
||||
const state = {
|
||||
prefix: "pref",
|
||||
notePosition: 666,
|
||||
isExpanded: true
|
||||
};
|
||||
|
||||
await supertest(app)
|
||||
.patch(`/etapi/branches/${createdBranchId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send(state)
|
||||
.expect(200);
|
||||
|
||||
const response = await supertest(app)
|
||||
.get(`/etapi/branches/${createdBranchId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.expect(200);
|
||||
expect(response.body).toMatchObject(state);
|
||||
});
|
||||
|
||||
it("rejects not allowed property", async () => {
|
||||
const response = await supertest(app)
|
||||
.patch(`/etapi/branches/${createdBranchId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
parentNoteId: "root"
|
||||
})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("PROPERTY_NOT_ALLOWED");
|
||||
});
|
||||
|
||||
it("rejects invalid property value", async () => {
|
||||
const response = await supertest(app)
|
||||
.patch(`/etapi/branches/${createdBranchId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
prefix: 123
|
||||
})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("PROPERTY_VALIDATION_ERROR");
|
||||
});
|
||||
|
||||
});
|
89
apps/server/spec/etapi/patch-note.spec.ts
Normal file
89
apps/server/spec/etapi/patch-note.spec.ts
Normal file
@ -0,0 +1,89 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
let createdNoteId: string;
|
||||
|
||||
describe("etapi/patch-note", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
|
||||
const response = await supertest(app)
|
||||
.post("/etapi/create-note")
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
"parentNoteId": "root",
|
||||
"title": "Hello",
|
||||
"type": "code",
|
||||
"mime": "application/json",
|
||||
"content": "{}"
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
const createdNoteId = response.body.note.noteId as string;
|
||||
expect(createdNoteId).toBeTruthy();
|
||||
});
|
||||
|
||||
it("obtains correct note information", async () => {
|
||||
await expectNoteToMatch({
|
||||
title: "Hello",
|
||||
type: "code",
|
||||
mime: "application/json"
|
||||
});
|
||||
});
|
||||
|
||||
it("patches type, mime and creation dates", async () => {
|
||||
const changes = {
|
||||
"title": "Wassup",
|
||||
"type": "html",
|
||||
"mime": "text/html",
|
||||
"dateCreated": "2023-08-21 23:38:51.123+0200",
|
||||
"utcDateCreated": "2023-08-21 23:38:51.123Z"
|
||||
};
|
||||
await supertest(app)
|
||||
.patch(`/etapi/notes/${createdNoteId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send(changes)
|
||||
.expect(200);
|
||||
await expectNoteToMatch(changes);
|
||||
});
|
||||
|
||||
it("refuses setting protection", async () => {
|
||||
const response = await supertest(app)
|
||||
.patch(`/etapi/notes/${createdNoteId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
isProtected: true
|
||||
})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("PROPERTY_NOT_ALLOWED");
|
||||
});
|
||||
|
||||
it("refuses incorrect type", async () => {
|
||||
const response = await supertest(app)
|
||||
.patch(`/etapi/notes/${createdNoteId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.send({
|
||||
title: true
|
||||
})
|
||||
.expect(400);
|
||||
expect(response.body.code).toStrictEqual("PROPERTY_VALIDATION_ERROR");
|
||||
});
|
||||
|
||||
async function expectNoteToMatch(state: object) {
|
||||
const response = await supertest(app)
|
||||
.get(`/etapi/notes/${createdNoteId}`)
|
||||
.auth("etapi", token, { "type": "basic"})
|
||||
.expect(200);
|
||||
expect(response.body).toMatchObject(state);
|
||||
}
|
||||
});
|
29
apps/server/spec/etapi/post-revision.spec.ts
Normal file
29
apps/server/spec/etapi/post-revision.spec.ts
Normal file
@ -0,0 +1,29 @@
|
||||
import { Application } from "express";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import supertest from "supertest";
|
||||
import { createNote, login } from "./utils.js";
|
||||
import config from "../../src/services/config.js";
|
||||
|
||||
let app: Application;
|
||||
let token: string;
|
||||
|
||||
const USER = "etapi";
|
||||
let createdNoteId: string;
|
||||
|
||||
describe("etapi/post-revision", () => {
|
||||
beforeAll(async () => {
|
||||
config.General.noAuthentication = false;
|
||||
const buildApp = (await (import("../../src/app.js"))).default;
|
||||
app = await buildApp();
|
||||
token = await login(app);
|
||||
createdNoteId = await createNote(app, token);
|
||||
});
|
||||
|
||||
it("posts note revision", async () => {
|
||||
await supertest(app)
|
||||
.post(`/etapi/notes/${createdNoteId}/revision`)
|
||||
.auth(USER, token, { "type": "basic"})
|
||||
.send("Changed content")
|
||||
.expect(204);
|
||||
});
|
||||
});
|
@ -27,7 +27,7 @@ export async function createNote(app: Application, token: string, content?: stri
|
||||
})
|
||||
.expect(201);
|
||||
|
||||
const noteId = response.body.note.noteId;
|
||||
const noteId = response.body.note.noteId as string;
|
||||
expect(noteId).toStrictEqual(noteId);
|
||||
return noteId;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
<link rel="shortcut icon" href="../favicon.ico">
|
||||
<% } %>
|
||||
<script src="<%= appPath %>/share.js" type="module"></script>
|
||||
<link href="<%= assetPath %>/src/share.css" rel="stylesheet">
|
||||
<% if (!note.isLabelTruthy("shareOmitDefaultCss")) { %>
|
||||
<link href="<%= assetPath %>/stylesheets/share.css" rel="stylesheet">
|
||||
<% } %>
|
||||
|
@ -4,10 +4,10 @@ import eu from "./etapi_utils.js";
|
||||
import backupService from "../services/backup.js";
|
||||
|
||||
function register(router: Router) {
|
||||
eu.route(router, "put", "/etapi/backup/:backupName", async (req, res, next) => {
|
||||
await backupService.backupNow(req.params.backupName);
|
||||
|
||||
res.sendStatus(204);
|
||||
eu.route(router, "put", "/etapi/backup/:backupName", (req, res, next) => {
|
||||
backupService.backupNow(req.params.backupName)
|
||||
.then(() => res.sendStatus(204))
|
||||
.catch(() => res.sendStatus(500));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import etapiTokenService from "../services/etapi_tokens.js";
|
||||
import config from "../services/config.js";
|
||||
import type { NextFunction, Request, RequestHandler, Response, Router } from "express";
|
||||
import type { ValidatorMap } from "./etapi-interface.js";
|
||||
import type { ApiRequestHandler } from "../routes/route_api.js";
|
||||
import type { ApiRequestHandler, SyncRouteRequestHandler } from "../routes/route_api.js";
|
||||
const GENERIC_CODE = "GENERIC";
|
||||
|
||||
type HttpMethod = "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head";
|
||||
@ -73,11 +73,11 @@ function processRequest(req: Request, res: Response, routeHandler: ApiRequestHan
|
||||
}
|
||||
}
|
||||
|
||||
function route(router: Router, method: HttpMethod, path: string, routeHandler: ApiRequestHandler) {
|
||||
function route(router: Router, method: HttpMethod, path: string, routeHandler: SyncRouteRequestHandler) {
|
||||
router[method](path, checkEtapiAuth, (req: Request, res: Response, next: NextFunction) => processRequest(req, res, routeHandler, next, method, path));
|
||||
}
|
||||
|
||||
function NOT_AUTHENTICATED_ROUTE(router: Router, method: HttpMethod, path: string, middleware: RequestHandler[], routeHandler: RequestHandler) {
|
||||
function NOT_AUTHENTICATED_ROUTE(router: Router, method: HttpMethod, path: string, middleware: RequestHandler[], routeHandler: SyncRouteRequestHandler) {
|
||||
router[method](path, ...middleware, (req: Request, res: Response, next: NextFunction) => processRequest(req, res, routeHandler, next, method, path));
|
||||
}
|
||||
|
||||
|
@ -15,46 +15,46 @@ function isValidDate(date: string) {
|
||||
}
|
||||
|
||||
function register(router: Router) {
|
||||
eu.route(router, "get", "/etapi/inbox/:date", async (req, res, next) => {
|
||||
eu.route(router, "get", "/etapi/inbox/:date", (req, res, next) => {
|
||||
const { date } = req.params;
|
||||
|
||||
if (!isValidDate(date)) {
|
||||
throw getDateInvalidError(date);
|
||||
}
|
||||
const note = await specialNotesService.getInboxNote(date);
|
||||
const note = specialNotesService.getInboxNote(date);
|
||||
res.json(mappers.mapNoteToPojo(note));
|
||||
});
|
||||
|
||||
eu.route(router, "get", "/etapi/calendar/days/:date", async (req, res, next) => {
|
||||
eu.route(router, "get", "/etapi/calendar/days/:date", (req, res, next) => {
|
||||
const { date } = req.params;
|
||||
|
||||
if (!isValidDate(date)) {
|
||||
throw getDateInvalidError(date);
|
||||
}
|
||||
|
||||
const note = await dateNotesService.getDayNote(date);
|
||||
const note = dateNotesService.getDayNote(date);
|
||||
res.json(mappers.mapNoteToPojo(note));
|
||||
});
|
||||
|
||||
eu.route(router, "get", "/etapi/calendar/week-first-day/:date", async (req, res, next) => {
|
||||
eu.route(router, "get", "/etapi/calendar/week-first-day/:date", (req, res, next) => {
|
||||
const { date } = req.params;
|
||||
|
||||
if (!isValidDate(date)) {
|
||||
throw getDateInvalidError(date);
|
||||
}
|
||||
|
||||
const note = await dateNotesService.getWeekFirstDayNote(date);
|
||||
const note = dateNotesService.getWeekFirstDayNote(date);
|
||||
res.json(mappers.mapNoteToPojo(note));
|
||||
});
|
||||
|
||||
eu.route(router, "get", "/etapi/calendar/weeks/:week", async (req, res, next) => {
|
||||
eu.route(router, "get", "/etapi/calendar/weeks/:week", (req, res, next) => {
|
||||
const { week } = req.params;
|
||||
|
||||
if (!/[0-9]{4}-W[0-9]{2}/.test(week)) {
|
||||
throw getWeekInvalidError(week);
|
||||
}
|
||||
|
||||
const note = await dateNotesService.getWeekNote(week);
|
||||
const note = dateNotesService.getWeekNote(week);
|
||||
|
||||
if (!note) {
|
||||
throw getWeekNotFoundError(week);
|
||||
@ -63,14 +63,14 @@ function register(router: Router) {
|
||||
res.json(mappers.mapNoteToPojo(note));
|
||||
});
|
||||
|
||||
eu.route(router, "get", "/etapi/calendar/months/:month", async (req, res, next) => {
|
||||
eu.route(router, "get", "/etapi/calendar/months/:month", (req, res, next) => {
|
||||
const { month } = req.params;
|
||||
|
||||
if (!/[0-9]{4}-[0-9]{2}/.test(month)) {
|
||||
throw getMonthInvalidError(month);
|
||||
}
|
||||
|
||||
const note = await dateNotesService.getMonthNote(month);
|
||||
const note = dateNotesService.getMonthNote(month);
|
||||
res.json(mappers.mapNoteToPojo(note));
|
||||
});
|
||||
|
||||
|
@ -9,6 +9,7 @@ import searchService from "./search/services/search.js";
|
||||
import SearchContext from "./search/search_context.js";
|
||||
import hiddenSubtree from "./hidden_subtree.js";
|
||||
import { t } from "i18next";
|
||||
import { BNote } from "./backend_script_entrypoint.js";
|
||||
const { LBTPL_NOTE_LAUNCHER, LBTPL_CUSTOM_WIDGET, LBTPL_SPACER, LBTPL_SCRIPT } = hiddenSubtree;
|
||||
|
||||
function getInboxNote(date: string) {
|
||||
@ -17,7 +18,7 @@ function getInboxNote(date: string) {
|
||||
throw new Error("Unable to find workspace note");
|
||||
}
|
||||
|
||||
let inbox;
|
||||
let inbox: BNote;
|
||||
|
||||
if (!workspaceNote.isRoot()) {
|
||||
inbox = workspaceNote.searchNoteInSubtree("#workspaceInbox");
|
||||
|
57
flake.lock
generated
57
flake.lock
generated
@ -18,6 +18,24 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"inputs": {
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1701680307,
|
||||
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1748437600,
|
||||
@ -34,10 +52,32 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"pnpm2nix": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1748901165,
|
||||
"narHash": "sha256-SctrxW5rVrROBLfh8p4kXfbF7NbJQDkse/Penu4PlEs=",
|
||||
"owner": "FliegendeWurst",
|
||||
"repo": "pnpm2nix-nzbr",
|
||||
"rev": "cda68d63418896a58542f3310c1c757ae92b1f22",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "FliegendeWurst",
|
||||
"repo": "pnpm2nix-nzbr",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pnpm2nix": "pnpm2nix"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
@ -54,6 +94,21 @@
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
229
flake.nix
229
flake.nix
@ -4,6 +4,10 @@
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
pnpm2nix = {
|
||||
url = "github:FliegendeWurst/pnpm2nix-nzbr";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
@ -11,69 +15,171 @@
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
pnpm2nix,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
packageJSON = builtins.fromJSON (builtins.readFile ./package.json);
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
electron = pkgs.electron_35;
|
||||
nodejs = pkgs.nodejs_22;
|
||||
pnpm = pkgs.pnpm_10;
|
||||
inherit (pkgs)
|
||||
copyDesktopItems
|
||||
darwin
|
||||
lib
|
||||
makeBinaryWrapper
|
||||
makeDesktopItem
|
||||
nodejs
|
||||
pnpm
|
||||
moreutils
|
||||
removeReferencesTo
|
||||
stdenv
|
||||
wrapGAppsHook3
|
||||
xcodebuild
|
||||
darwin
|
||||
;
|
||||
desktop = stdenv.mkDerivation (finalAttrs: {
|
||||
pname = "triliumnext-desktop";
|
||||
version = packageJSON.version;
|
||||
src = lib.cleanSource ./.;
|
||||
|
||||
nativeBuildInputs =
|
||||
[
|
||||
pnpm.configHook
|
||||
nodejs
|
||||
nodejs.python
|
||||
copyDesktopItems
|
||||
makeBinaryWrapper
|
||||
wrapGAppsHook3
|
||||
]
|
||||
++ lib.optionals stdenv.hostPlatform.isDarwin [
|
||||
xcodebuild
|
||||
darwin.cctools
|
||||
fullCleanSourceFilter =
|
||||
name: type:
|
||||
(lib.cleanSourceFilter name type)
|
||||
|| (
|
||||
let
|
||||
baseName = baseNameOf (toString name);
|
||||
in
|
||||
# No need to copy the flake.
|
||||
# Don't copy local development instance of NX cache.
|
||||
baseName == "flake.nix" || baseName == "flake.lock" || baseName == ".nx"
|
||||
);
|
||||
fullCleanSource =
|
||||
src:
|
||||
lib.cleanSourceWith {
|
||||
filter = fullCleanSourceFilter;
|
||||
src = src;
|
||||
};
|
||||
packageJson = builtins.fromJSON (builtins.readFile ./package.json);
|
||||
|
||||
makeApp =
|
||||
{
|
||||
app,
|
||||
buildTask,
|
||||
mainProgram,
|
||||
installCommands,
|
||||
preBuildCommands ? "",
|
||||
}:
|
||||
pnpm2nix.packages.${system}.mkPnpmPackage rec {
|
||||
pname = "triliumnext-${app}";
|
||||
version = packageJson.version + (lib.optionalString (self ? shortRev) "-${self.shortRev}");
|
||||
|
||||
src = fullCleanSource ./.;
|
||||
packageJSON = ./package.json;
|
||||
pnpmLockYaml = ./pnpm-lock.yaml;
|
||||
|
||||
workspace = fullCleanSource ./.;
|
||||
pnpmWorkspaceYaml = ./pnpm-workspace.yaml;
|
||||
|
||||
inherit nodejs pnpm;
|
||||
|
||||
extraNodeModuleSources = [
|
||||
rec {
|
||||
name = "patches";
|
||||
value = ./patches;
|
||||
}
|
||||
];
|
||||
|
||||
dontWrapGApps = true;
|
||||
# remove pnpm version override
|
||||
preConfigure = ''
|
||||
cat package.json | grep -v 'packageManager' | sponge package.json
|
||||
'';
|
||||
|
||||
preBuild = lib.optionalString stdenv.hostPlatform.isLinux ''
|
||||
patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
||||
node_modules/.pnpm/sass-embedded-linux-x64@*/node_modules/sass-embedded-linux-x64/dart-sass/src/dart
|
||||
'';
|
||||
postConfigure =
|
||||
''
|
||||
chmod +x node_modules/.pnpm/electron@*/node_modules/electron/install.js
|
||||
patchShebangs --build node_modules
|
||||
''
|
||||
+ lib.optionalString stdenv.hostPlatform.isLinux ''
|
||||
patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
|
||||
node_modules/.pnpm/sass-embedded-linux-x64@*/node_modules/sass-embedded-linux-x64/dart-sass/src/dart
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
extraNativeBuildInputs =
|
||||
[
|
||||
makeBinaryWrapper
|
||||
moreutils # sponge
|
||||
nodejs.python
|
||||
removeReferencesTo
|
||||
]
|
||||
++ lib.optionals (app == "desktop") [
|
||||
copyDesktopItems
|
||||
wrapGAppsHook3
|
||||
]
|
||||
++ lib.optionals stdenv.hostPlatform.isDarwin [
|
||||
xcodebuild
|
||||
darwin.cctools
|
||||
];
|
||||
dontWrapGApps = true;
|
||||
|
||||
# Disable NX interaction
|
||||
export NX_TUI=false
|
||||
export NX_DAEMON=false
|
||||
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
|
||||
|
||||
pnpm nx run desktop:build --outputStyle stream --verbose
|
||||
preBuild = ''
|
||||
${preBuildCommands}
|
||||
'';
|
||||
|
||||
# Rebuild dependencies
|
||||
export npm_config_nodedir=${electron.headers}
|
||||
pnpm nx run desktop:rebuild-deps --outputStyle stream --verbose
|
||||
scriptFull = "pnpm nx ${buildTask} --outputStyle stream --verbose";
|
||||
|
||||
runHook postBuild
|
||||
'';
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
${installCommands}
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
components = [
|
||||
"packages/ckeditor5"
|
||||
"packages/ckeditor5-admonition"
|
||||
"packages/ckeditor5-footnotes"
|
||||
"packages/ckeditor5-keyboard-marker"
|
||||
"packages/ckeditor5-math"
|
||||
"packages/ckeditor5-mermaid"
|
||||
"packages/codemirror"
|
||||
"packages/commons"
|
||||
"packages/express-partial-content"
|
||||
"packages/highlightjs"
|
||||
"packages/turndown-plugin-gfm"
|
||||
|
||||
"apps/client"
|
||||
"apps/db-compare"
|
||||
"apps/desktop"
|
||||
"apps/dump-db"
|
||||
"apps/edit-docs"
|
||||
"apps/server"
|
||||
"apps/server-e2e"
|
||||
];
|
||||
|
||||
desktopItems = lib.optionals (app == "desktop") [
|
||||
(makeDesktopItem {
|
||||
name = "TriliumNext Notes";
|
||||
exec = meta.mainProgram;
|
||||
icon = "trilium";
|
||||
comment = meta.description;
|
||||
desktopName = "TriliumNext Notes";
|
||||
categories = [ "Office" ];
|
||||
startupWMClass = "Trilium Notes Next";
|
||||
})
|
||||
];
|
||||
|
||||
meta = {
|
||||
description = "TriliumNext: ${app}";
|
||||
inherit mainProgram;
|
||||
};
|
||||
};
|
||||
|
||||
desktop = makeApp {
|
||||
app = "desktop";
|
||||
preBuildCommands = "export npm_config_nodedir=${electron.headers}";
|
||||
buildTask = "run desktop:rebuild-deps";
|
||||
mainProgram = "trilium";
|
||||
installCommands = ''
|
||||
remove-references-to -t ${electron.headers} apps/desktop/dist/node_modules/better-sqlite3/build/config.gypi
|
||||
remove-references-to -t ${nodejs.python} apps/desktop/dist/node_modules/better-sqlite3/build/config.gypi
|
||||
|
||||
mkdir -p $out/{bin,share/icons/hicolor/512x512/apps,opt/trilium}
|
||||
cp --archive apps/desktop/dist/* $out/opt/trilium
|
||||
@ -82,34 +188,37 @@
|
||||
"''${gappsWrapperArgs[@]}" \
|
||||
--set-default ELECTRON_IS_DEV 0 \
|
||||
--add-flags $out/opt/trilium/main.cjs
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
};
|
||||
|
||||
desktopItems = [
|
||||
(makeDesktopItem {
|
||||
name = "TriliumNext Notes";
|
||||
exec = finalAttrs.meta.mainProgram;
|
||||
icon = "trilium";
|
||||
comment = finalAttrs.meta.description;
|
||||
desktopName = "TriliumNext Notes";
|
||||
categories = [ "Office" ];
|
||||
startupWMClass = "Trilium Notes Next";
|
||||
})
|
||||
];
|
||||
server = makeApp {
|
||||
app = "server";
|
||||
preBuildCommands = "pushd apps/server; pnpm rebuild; popd";
|
||||
buildTask = "--project=server build";
|
||||
mainProgram = "trilium-server";
|
||||
installCommands = ''
|
||||
remove-references-to -t ${nodejs.python} apps/server/dist/node_modules/better-sqlite3/build/config.gypi
|
||||
remove-references-to -t ${pnpm} apps/server/dist/node_modules/better-sqlite3/build/config.gypi
|
||||
|
||||
pnpmDeps = pnpm.fetchDeps {
|
||||
inherit (finalAttrs) pname version src;
|
||||
hash = "sha256-xC0u1h92wtthylOAw+IF9mpFi0c4xajJhUcA9pqzcAw=";
|
||||
};
|
||||
pushd apps/server/dist
|
||||
rm -rf node_modules/better-sqlite3/build/Release/obj \
|
||||
node_modules/better-sqlite3/build/Release/obj.target \
|
||||
node_modules/better-sqlite3/build/Release/sqlite3.a \
|
||||
node_modules/better-sqlite3/build/{Makefile,better_sqlite3.target.mk,test_extension.target.mk,binding.Makefile} \
|
||||
node_modules/better-sqlite3/deps/sqlite3
|
||||
popd
|
||||
|
||||
meta = {
|
||||
description = "Free and open-source, cross-platform hierarchical note taking application with focus on building large personal knowledge bases";
|
||||
mainProgram = "trilium";
|
||||
};
|
||||
});
|
||||
mkdir -p $out/{bin,opt/trilium-server}
|
||||
cp --archive apps/server/dist/* $out/opt/trilium-server
|
||||
makeWrapper ${lib.getExe nodejs} $out/bin/trilium-server \
|
||||
--add-flags $out/opt/trilium-server/main.cjs
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
packages.desktop = desktop;
|
||||
packages.server = server;
|
||||
|
||||
packages.default = desktop;
|
||||
}
|
||||
);
|
||||
|
@ -49,7 +49,7 @@
|
||||
"eslint": "^9.8.0",
|
||||
"eslint-config-prettier": "^10.0.0",
|
||||
"eslint-plugin-playwright": "^2.0.0",
|
||||
"happy-dom": "~17.5.0",
|
||||
"happy-dom": "~17.6.0",
|
||||
"jiti": "2.4.2",
|
||||
"jsdom": "~26.1.0",
|
||||
"jsonc-eslint-parser": "^2.1.0",
|
||||
@ -82,7 +82,7 @@
|
||||
"axios": "^1.6.0",
|
||||
"express": "^4.21.2"
|
||||
},
|
||||
"packageManager": "pnpm@10.11.0+sha512.6540583f41cc5f628eb3d9773ecee802f4f9ef9923cc45b69890fb47991d4b092964694ec3a4f738a420c918a333062c8b925d312f42e4f0c263eb603551f977",
|
||||
"packageManager": "pnpm@10.11.1+sha512.e519b9f7639869dc8d5c3c5dfef73b3f091094b0a006d7317353c72b124e80e1afd429732e28705ad6bfa1ee879c1fce46c128ccebd3192101f43dd67c667912",
|
||||
"pnpm": {
|
||||
"patchedDependencies": {
|
||||
"@ckeditor/ckeditor5-mention": "patches/@ckeditor__ckeditor5-mention.patch",
|
||||
|
715
pnpm-lock.yaml
generated
715
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user