n8n-nodes-logbrew 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -2
- package/dist/credentials/LogBrewApi.credentials.js +43 -0
- package/dist/icons/logbrew.dark.svg +1 -0
- package/dist/icons/logbrew.svg +1 -0
- package/dist/nodes/LogBrew/LogBrew.node.js +187 -0
- package/dist/nodes/LogBrew/LogBrew.node.json +10 -0
- package/dist/nodes/LogBrew/client.js +167 -0
- package/dist/nodes/LogBrew/n8n.js +2 -0
- package/dist/nodes/LogBrew/records.js +65 -0
- package/dist/nodes/LogBrew/transport.js +48 -0
- package/dist/nodes/LogBrewTrigger/LogBrewTrigger.node.js +87 -0
- package/dist/nodes/LogBrewTrigger/LogBrewTrigger.node.json +10 -0
- package/package.json +50 -4
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# n8n-nodes-logbrew
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connect [LogBrew](https://logbrew.co) error tracking and logs to your n8n workflows. Start a workflow when LogBrew finds a new issue or an alert fires, send logs from any workflow, and resolve issues when a fix ships. You can start on the LogBrew free plan.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
In n8n, open **Settings**, then **Community Nodes**, choose **Install**, and enter `n8n-nodes-logbrew`. The n8n docs explain [community node installation](https://docs.n8n.io/integrations/community-nodes/installation/) for self-hosted instances.
|
|
8
|
+
|
|
9
|
+
## Nodes
|
|
10
|
+
|
|
11
|
+
| Node | Operation | What it does |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| LogBrew Trigger | New Issue | Starts the workflow for each issue LogBrew sees for the first time in the project. Each item has the title, severity, occurrence count, and a link to the issue in LogBrew. |
|
|
14
|
+
| LogBrew Trigger | Alert Fired | Starts the workflow when one of the project's alert rules fires. |
|
|
15
|
+
| LogBrew | Send a Log | Sends one log line with a level, a message, and your own attributes. |
|
|
16
|
+
| LogBrew | Resolve an Issue | Marks an issue resolved. LogBrew opens it again if the error comes back. |
|
|
17
|
+
|
|
18
|
+
The LogBrew node also works as a tool for the n8n AI Agent node.
|
|
19
|
+
|
|
20
|
+
## Credentials
|
|
21
|
+
|
|
22
|
+
1. On the [API page](https://logbrew.co/account/api) of your LogBrew account, create a token. Under **Access**, choose **Read** for **Projects**, **Read & Write** for **Issues, logs & traces**, and **Read** for **Alert rules**. The **Scopes** list then shows `projects:read`, `telemetry:read`, `issues:write`, and `alerts:read`. Resolve an Issue needs `issues:write`; if you do not resolve issues, choose **Read** for **Issues, logs & traces**.
|
|
23
|
+
2. To send logs, open **API Keys** in your LogBrew project and create an ingest key.
|
|
24
|
+
3. In n8n, create a **LogBrew API** credential. Paste the API token, and the ingest key if you send logs.
|
|
25
|
+
|
|
26
|
+
Keep the API URL `https://api.logbrew.co`. Change it only when your team runs LogBrew at another address.
|
|
27
|
+
|
|
28
|
+
## Example workflows
|
|
29
|
+
|
|
30
|
+
- **New issue to Slack.** LogBrew Trigger (New Issue) followed by a Slack node that posts the title, severity, and link.
|
|
31
|
+
- **Alert to a ticket.** LogBrew Trigger (Alert Fired) followed by a Linear or Jira node that opens a ticket.
|
|
32
|
+
- **Log each run.** Add LogBrew (Send a Log) at the end of a workflow, with the order ID or account ID as attributes.
|
|
33
|
+
|
|
34
|
+
## Errors
|
|
35
|
+
|
|
36
|
+
The nodes show the LogBrew error and its next step, for example `Invalid or expired token. send Authorization: Bearer <token> (HTTP 401)`. Turn on **Continue On Fail** to keep the workflow running and get the error on the item.
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
MIT
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogBrewApi = void 0;
|
|
4
|
+
class LogBrewApi {
|
|
5
|
+
authenticate = {
|
|
6
|
+
properties: { headers: { Authorization: "=Bearer {{$credentials.apiToken}}" } },
|
|
7
|
+
type: "generic",
|
|
8
|
+
};
|
|
9
|
+
displayName = "LogBrew API";
|
|
10
|
+
documentationUrl = "https://github.com/LogBrewCo/sdk/tree/main/apps/n8n#credentials";
|
|
11
|
+
icon = { dark: "file:../icons/logbrew.dark.svg", light: "file:../icons/logbrew.svg" };
|
|
12
|
+
name = "logBrewApi";
|
|
13
|
+
properties = [
|
|
14
|
+
{
|
|
15
|
+
default: "",
|
|
16
|
+
description: "Create one at logbrew.co/account/api with the scopes projects:read, telemetry:read, issues:write, and alerts:read",
|
|
17
|
+
displayName: "API Token",
|
|
18
|
+
name: "apiToken",
|
|
19
|
+
required: true,
|
|
20
|
+
type: "string",
|
|
21
|
+
typeOptions: { password: true },
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
default: "",
|
|
25
|
+
description: "Only Send Log needs it. Create an ingest key under API Keys in your LogBrew project.",
|
|
26
|
+
displayName: "Ingest Key",
|
|
27
|
+
name: "ingestKey",
|
|
28
|
+
type: "string",
|
|
29
|
+
typeOptions: { password: true },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
default: "https://api.logbrew.co",
|
|
33
|
+
description: "Keep the default unless your team runs LogBrew at another address",
|
|
34
|
+
displayName: "API URL",
|
|
35
|
+
name: "apiUrl",
|
|
36
|
+
type: "string",
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
test = {
|
|
40
|
+
request: { baseURL: "={{$credentials.apiUrl}}", url: "/api/projects" },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.LogBrewApi = LogBrewApi;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21 21" shape-rendering="crispEdges"><title>LogBrew</title><path fill="#201E1F" d="M7 0h4v1h-4zM5 1h2v1h-2zM11 1h3v1h-3zM3 2h2v1h-2zM14 2h2v1h-2zM2 3h1v1h-1zM16 3h1v3h-1zM1 4h1v2h-1zM2 6h1v5h-1zM5 6h1v1h-1zM13 6h3v1h-3zM4 7h1v4h-1zM6 7h1v3h-1zM11 7h2v1h-2zM15 7h1v13h-1zM8 8h3v1h-3zM16 8h2v1h-2zM8 9h1v1h-1zM18 9h1v1h-1zM7 10h1v1h-1zM16 10h1v1h-1zM19 10h1v5h-1zM3 11h1v9h-1zM17 11h1v3h-1zM6 12h1v6h-1zM9 12h1v6h-1zM12 12h1v6h-1zM16 14h1v1h-1zM18 15h1v1h-1zM16 16h2v1h-2zM4 20h11v1h-11z"/><path fill="#FECB17" d="M5 7h1v13h-1zM13 8h2v4h-2zM11 9h2v3h-2zM8 10h3v2h-3zM6 11h2v1h-2zM8 12h1v8h-1zM11 12h1v8h-1zM14 12h1v8h-1zM6 18h2v2h-2zM9 18h2v2h-2zM12 18h2v2h-2z"/><path fill="#F9BC13" d="M13 7h2v1h-2zM11 8h2v1h-2zM9 9h2v1h-2zM6 10h1v1h-1zM4 11h1v9h-1zM7 12h1v6h-1zM10 12h1v6h-1zM13 12h1v6h-1z"/><path fill="#EAEAEC" d="M7 1h4v1h-4zM5 2h2v1h-2zM11 2h3v1h-3zM3 3h2v1h-2zM14 3h2v1h-2zM2 4h1v2h-1zM6 6h1v1h-1zM11 6h2v1h-2zM8 7h3v1h-3zM3 9h1v2h-1zM7 9h1v1h-1zM16 9h1v1h-1zM17 10h1v1h-1zM17 14h1v1h-1zM16 15h1v1h-1z"/><path fill="#FFFFFF" d="M7 2h4v5h-4zM5 3h2v3h-2zM11 3h3v3h-3zM3 4h2v3h-2zM14 4h2v2h-2zM3 7h1v2h-1zM7 7h1v2h-1zM17 9h1v1h-1zM18 10h1v5h-1zM17 15h1v1h-1z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 21 21" shape-rendering="crispEdges"><title>LogBrew</title><path fill="#201E1F" d="M7 0h4v1h-4zM5 1h2v1h-2zM11 1h3v1h-3zM3 2h2v1h-2zM14 2h2v1h-2zM2 3h1v1h-1zM16 3h1v3h-1zM1 4h1v2h-1zM2 6h1v5h-1zM5 6h1v1h-1zM13 6h3v1h-3zM4 7h1v4h-1zM6 7h1v3h-1zM11 7h2v1h-2zM15 7h1v13h-1zM8 8h3v1h-3zM16 8h2v1h-2zM8 9h1v1h-1zM18 9h1v1h-1zM7 10h1v1h-1zM16 10h1v1h-1zM19 10h1v5h-1zM3 11h1v9h-1zM17 11h1v3h-1zM6 12h1v6h-1zM9 12h1v6h-1zM12 12h1v6h-1zM16 14h1v1h-1zM18 15h1v1h-1zM16 16h2v1h-2zM4 20h11v1h-11z"/><path fill="#FECB17" d="M5 7h1v13h-1zM13 8h2v4h-2zM11 9h2v3h-2zM8 10h3v2h-3zM6 11h2v1h-2zM8 12h1v8h-1zM11 12h1v8h-1zM14 12h1v8h-1zM6 18h2v2h-2zM9 18h2v2h-2zM12 18h2v2h-2z"/><path fill="#F9BC13" d="M13 7h2v1h-2zM11 8h2v1h-2zM9 9h2v1h-2zM6 10h1v1h-1zM4 11h1v9h-1zM7 12h1v6h-1zM10 12h1v6h-1zM13 12h1v6h-1z"/><path fill="#EAEAEC" d="M7 1h4v1h-4zM5 2h2v1h-2zM11 2h3v1h-3zM3 3h2v1h-2zM14 3h2v1h-2zM2 4h1v2h-1zM6 6h1v1h-1zM11 6h2v1h-2zM8 7h3v1h-3zM3 9h1v2h-1zM7 9h1v1h-1zM16 9h1v1h-1zM17 10h1v1h-1zM17 14h1v1h-1zM16 15h1v1h-1z"/><path fill="#FFFFFF" d="M7 2h4v5h-4zM5 3h2v3h-2zM11 3h3v3h-3zM3 4h2v3h-2zM14 4h2v2h-2zM3 7h1v2h-1zM7 7h1v2h-1zM17 9h1v1h-1zM18 10h1v5h-1zM17 15h1v1h-1z"/></svg>
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogBrew = void 0;
|
|
4
|
+
const transport_1 = require("./transport");
|
|
5
|
+
const client_1 = require("./client");
|
|
6
|
+
function attributesOf(value) {
|
|
7
|
+
const parsed = typeof value === "string" && value.trim() !== "" ? JSON.parse(value) : value;
|
|
8
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
9
|
+
return Object.fromEntries(Object.entries(parsed));
|
|
10
|
+
}
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
function text(context, name, index) {
|
|
14
|
+
const value = context.getNodeParameter(name, index, "");
|
|
15
|
+
return typeof value === "string" ? value.trim() : "";
|
|
16
|
+
}
|
|
17
|
+
async function runOne(context, connection, index) {
|
|
18
|
+
const operation = text(context, "operation", index);
|
|
19
|
+
if (operation === "resolve") {
|
|
20
|
+
const issue = await (0, client_1.resolveIssue)(connection.send, connection.apiUrl, text(context, "issueId", index));
|
|
21
|
+
return { ...issue };
|
|
22
|
+
}
|
|
23
|
+
const environment = text(context, "environment", index);
|
|
24
|
+
const reply = await (0, client_1.sendLog)(connection.send, {
|
|
25
|
+
attributes: attributesOf(context.getNodeParameter("attributes", index, "{}")),
|
|
26
|
+
environment: environment === "" ? "production" : environment,
|
|
27
|
+
id: crypto.randomUUID(),
|
|
28
|
+
level: (0, client_1.levelOf)(text(context, "level", index)),
|
|
29
|
+
message: text(context, "message", index),
|
|
30
|
+
occurredAt: new Date().toISOString(),
|
|
31
|
+
projectId: text(context, "projectId", index),
|
|
32
|
+
release: text(context, "release", index),
|
|
33
|
+
serviceName: text(context, "serviceName", index),
|
|
34
|
+
});
|
|
35
|
+
return typeof reply === "object" && reply !== null ? { ...reply } : {};
|
|
36
|
+
}
|
|
37
|
+
async function settle(context, connection, index) {
|
|
38
|
+
try {
|
|
39
|
+
return { json: await runOne(context, connection, index) };
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return { error: error instanceof Error ? error : new Error(String(error)) };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class LogBrew {
|
|
46
|
+
description = {
|
|
47
|
+
credentials: [{ name: "logBrewApi", required: true }],
|
|
48
|
+
defaults: { name: "LogBrew" },
|
|
49
|
+
description: "Send logs to LogBrew and resolve LogBrew issues",
|
|
50
|
+
displayName: "LogBrew",
|
|
51
|
+
group: ["output"],
|
|
52
|
+
icon: { dark: "file:../../icons/logbrew.dark.svg", light: "file:../../icons/logbrew.svg" },
|
|
53
|
+
inputs: ["main"],
|
|
54
|
+
name: "logBrew",
|
|
55
|
+
outputs: ["main"],
|
|
56
|
+
properties: [
|
|
57
|
+
{
|
|
58
|
+
displayName: "Resource",
|
|
59
|
+
default: "log",
|
|
60
|
+
name: "resource",
|
|
61
|
+
noDataExpression: true,
|
|
62
|
+
options: [
|
|
63
|
+
{ name: "Issue", value: "issue" },
|
|
64
|
+
{ name: "Log", value: "log" },
|
|
65
|
+
],
|
|
66
|
+
type: "options",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
displayName: "Operation",
|
|
70
|
+
default: "send",
|
|
71
|
+
displayOptions: { show: { resource: ["log"] } },
|
|
72
|
+
name: "operation",
|
|
73
|
+
noDataExpression: true,
|
|
74
|
+
options: [{ action: "Send a log", description: "Send one log line to a project", name: "Send", value: "send" }],
|
|
75
|
+
type: "options",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
displayName: "Operation",
|
|
79
|
+
default: "resolve",
|
|
80
|
+
displayOptions: { show: { resource: ["issue"] } },
|
|
81
|
+
name: "operation",
|
|
82
|
+
noDataExpression: true,
|
|
83
|
+
options: [
|
|
84
|
+
{ action: "Resolve an issue", description: "Mark an issue resolved", name: "Resolve", value: "resolve" },
|
|
85
|
+
],
|
|
86
|
+
type: "options",
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
displayName: "Issue ID",
|
|
90
|
+
default: "",
|
|
91
|
+
description: "The issue to resolve. Triggers and issue links give you its ID.",
|
|
92
|
+
displayOptions: { show: { operation: ["resolve"], resource: ["issue"] } },
|
|
93
|
+
name: "issueId",
|
|
94
|
+
required: true,
|
|
95
|
+
type: "string",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
displayName: "Project Name or ID",
|
|
99
|
+
default: "",
|
|
100
|
+
description: 'Project that receives the log. Use the project of your ingest key. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
|
|
101
|
+
displayOptions: { show: { operation: ["send"], resource: ["log"] } },
|
|
102
|
+
name: "projectId",
|
|
103
|
+
required: true,
|
|
104
|
+
type: "options",
|
|
105
|
+
typeOptions: { loadOptionsMethod: "getProjects" },
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
displayName: "Message",
|
|
109
|
+
default: "",
|
|
110
|
+
displayOptions: { show: { operation: ["send"], resource: ["log"] } },
|
|
111
|
+
name: "message",
|
|
112
|
+
required: true,
|
|
113
|
+
type: "string",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
displayName: "Level",
|
|
117
|
+
default: "info",
|
|
118
|
+
displayOptions: { show: { operation: ["send"], resource: ["log"] } },
|
|
119
|
+
name: "level",
|
|
120
|
+
options: [
|
|
121
|
+
{ name: "Critical", value: "critical" },
|
|
122
|
+
{ name: "Debug", value: "debug" },
|
|
123
|
+
{ name: "Error", value: "error" },
|
|
124
|
+
{ name: "Info", value: "info" },
|
|
125
|
+
{ name: "Warning", value: "warning" },
|
|
126
|
+
],
|
|
127
|
+
type: "options",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
displayName: "Service Name",
|
|
131
|
+
default: "n8n",
|
|
132
|
+
description: "The service that LogBrew groups this log under",
|
|
133
|
+
displayOptions: { show: { operation: ["send"], resource: ["log"] } },
|
|
134
|
+
name: "serviceName",
|
|
135
|
+
required: true,
|
|
136
|
+
type: "string",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
displayName: "Release",
|
|
140
|
+
default: "workflow",
|
|
141
|
+
description: "The release, version, or commit of the service",
|
|
142
|
+
displayOptions: { show: { operation: ["send"], resource: ["log"] } },
|
|
143
|
+
name: "release",
|
|
144
|
+
required: true,
|
|
145
|
+
type: "string",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
displayName: "Environment",
|
|
149
|
+
default: "production",
|
|
150
|
+
displayOptions: { show: { operation: ["send"], resource: ["log"] } },
|
|
151
|
+
name: "environment",
|
|
152
|
+
type: "string",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
displayName: "Attributes",
|
|
156
|
+
default: "{}",
|
|
157
|
+
description: "Extra fields to store with the log, such as an order ID",
|
|
158
|
+
displayOptions: { show: { operation: ["send"], resource: ["log"] } },
|
|
159
|
+
name: "attributes",
|
|
160
|
+
type: "json",
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
164
|
+
usableAsTool: true,
|
|
165
|
+
version: 1,
|
|
166
|
+
};
|
|
167
|
+
methods = {
|
|
168
|
+
loadOptions: {
|
|
169
|
+
async getProjects() {
|
|
170
|
+
return (0, transport_1.projectOptions)(this);
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
async execute() {
|
|
175
|
+
const connection = await (0, transport_1.connect)(this);
|
|
176
|
+
const results = [];
|
|
177
|
+
for (const [index] of this.getInputData().entries()) {
|
|
178
|
+
const outcome = await settle(this, connection, index);
|
|
179
|
+
if ("error" in outcome && !this.continueOnFail()) {
|
|
180
|
+
throw outcome.error;
|
|
181
|
+
}
|
|
182
|
+
results.push({ json: "error" in outcome ? { error: outcome.error.message } : outcome.json, pairedItem: { item: index } });
|
|
183
|
+
}
|
|
184
|
+
return [results];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.LogBrew = LogBrew;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"node": "n8n-nodes-logbrew.logBrew",
|
|
3
|
+
"nodeVersion": "1.0",
|
|
4
|
+
"codexVersion": "1.0",
|
|
5
|
+
"categories": ["Development"],
|
|
6
|
+
"resources": {
|
|
7
|
+
"credentialDocumentation": [{ "url": "https://github.com/LogBrewCo/sdk/tree/main/apps/n8n#credentials" }],
|
|
8
|
+
"primaryDocumentation": [{ "url": "https://github.com/LogBrewCo/sdk/tree/main/apps/n8n#readme" }]
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.noHttpStatus = exports.defaultApiUrl = exports.LogBrewError = void 0;
|
|
4
|
+
exports.latestAlert = latestAlert;
|
|
5
|
+
exports.latestIssue = latestIssue;
|
|
6
|
+
exports.levelOf = levelOf;
|
|
7
|
+
exports.listProjects = listProjects;
|
|
8
|
+
exports.pollFiredAlerts = pollFiredAlerts;
|
|
9
|
+
exports.pollNewIssues = pollNewIssues;
|
|
10
|
+
exports.resolveIssue = resolveIssue;
|
|
11
|
+
exports.sendLog = sendLog;
|
|
12
|
+
const records_1 = require("./records");
|
|
13
|
+
const defaultApiUrl = "https://api.logbrew.co";
|
|
14
|
+
exports.defaultApiUrl = defaultApiUrl;
|
|
15
|
+
const issueLimit = "500";
|
|
16
|
+
const issueListVersion = "7";
|
|
17
|
+
const issueVersion = "5";
|
|
18
|
+
const onePage = 1;
|
|
19
|
+
const pollPages = 20;
|
|
20
|
+
const okStatus = 200;
|
|
21
|
+
const noHttpStatus = 0;
|
|
22
|
+
exports.noHttpStatus = noHttpStatus;
|
|
23
|
+
const sdkName = "n8n-nodes-logbrew";
|
|
24
|
+
const sdkVersion = "0.1.0";
|
|
25
|
+
const levels = ["debug", "info", "warning", "error", "critical"];
|
|
26
|
+
class LogBrewError extends Error {
|
|
27
|
+
status;
|
|
28
|
+
constructor(status, message) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = "LogBrewError";
|
|
31
|
+
this.status = status;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.LogBrewError = LogBrewError;
|
|
35
|
+
function failure(reply) {
|
|
36
|
+
const body = (0, records_1.isFields)(reply.body) ? reply.body : {};
|
|
37
|
+
const detail = [(0, records_1.text)(body, "error"), (0, records_1.text)(body, "next")].filter((part) => part !== "").join(". ") ||
|
|
38
|
+
"LogBrew did not accept the request";
|
|
39
|
+
return new LogBrewError(reply.status, `${detail} (HTTP ${String(reply.status)})`);
|
|
40
|
+
}
|
|
41
|
+
async function call(send, request) {
|
|
42
|
+
const reply = await send(request);
|
|
43
|
+
if (reply.status !== okStatus) {
|
|
44
|
+
throw failure(reply);
|
|
45
|
+
}
|
|
46
|
+
return reply.body;
|
|
47
|
+
}
|
|
48
|
+
function listOf(body) {
|
|
49
|
+
if (!Array.isArray(body)) {
|
|
50
|
+
throw new LogBrewError(okStatus, "LogBrew sent a list in an unknown format");
|
|
51
|
+
}
|
|
52
|
+
return body;
|
|
53
|
+
}
|
|
54
|
+
function dashboardOrigin(apiUrl) {
|
|
55
|
+
const url = new URL(apiUrl);
|
|
56
|
+
const host = url.host.startsWith("api.") ? url.host.slice("api.".length) : url.host;
|
|
57
|
+
return `${url.protocol}//${host}`;
|
|
58
|
+
}
|
|
59
|
+
function newerThan(items, cursor, at) {
|
|
60
|
+
const since = Date.parse(cursor);
|
|
61
|
+
const fresh = items
|
|
62
|
+
.filter((item) => Date.parse(at(item)) > since)
|
|
63
|
+
.toSorted((left, right) => Date.parse(at(left)) - Date.parse(at(right)));
|
|
64
|
+
const [last] = fresh.toReversed();
|
|
65
|
+
return { cursor: last === undefined ? cursor : at(last), items: fresh };
|
|
66
|
+
}
|
|
67
|
+
function newest(items, at) {
|
|
68
|
+
const [first] = items.toSorted((left, right) => Date.parse(at(right)) - Date.parse(at(left)));
|
|
69
|
+
return first === undefined ? [] : [first];
|
|
70
|
+
}
|
|
71
|
+
async function listProjects(send) {
|
|
72
|
+
const body = await call(send, { credential: "apiToken", method: "GET", path: "/api/projects" });
|
|
73
|
+
return (0, records_1.compact)(listOf(body).map((value) => {
|
|
74
|
+
if (!(0, records_1.isFields)(value) || value["is_active"] === false) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const project = { id: (0, records_1.text)(value, "id"), name: (0, records_1.text)(value, "name") };
|
|
78
|
+
return project.id === "" ? undefined : project;
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
function issuePage(body, dashboard) {
|
|
82
|
+
const page = (0, records_1.isFields)(body) ? body : {};
|
|
83
|
+
const next = page["next_cursor"];
|
|
84
|
+
return {
|
|
85
|
+
issues: (0, records_1.compact)(listOf(page["issues"]).map((value) => (0, records_1.parseIssue)(value, dashboard))),
|
|
86
|
+
next: (0, records_1.isFields)(next) ? { cursor_id: (0, records_1.text)(next, "id"), cursor_time: (0, records_1.text)(next, "time") } : undefined,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async function readIssues(send, read) {
|
|
90
|
+
const { apiUrl, filter, pages } = read;
|
|
91
|
+
const query = { limit: issueLimit, pagination: "cursor", response_version: issueListVersion, ...filter };
|
|
92
|
+
const body = await call(send, { credential: "apiToken", method: "GET", path: "/api/telemetry/issues", query });
|
|
93
|
+
const page = issuePage(body, dashboardOrigin(apiUrl));
|
|
94
|
+
if (page.next === undefined || pages <= onePage) {
|
|
95
|
+
return page.issues;
|
|
96
|
+
}
|
|
97
|
+
const rest = await readIssues(send, { apiUrl, filter: { ...filter, ...page.next }, pages: pages - onePage });
|
|
98
|
+
return [...page.issues, ...rest];
|
|
99
|
+
}
|
|
100
|
+
async function pollNewIssues(send, where) {
|
|
101
|
+
const { apiUrl, cursor, projectId } = where;
|
|
102
|
+
const issues = await readIssues(send, { apiUrl, filter: { project_id: projectId, since: cursor }, pages: pollPages });
|
|
103
|
+
return newerThan(issues, cursor, (issue) => issue.first_seen_at);
|
|
104
|
+
}
|
|
105
|
+
async function latestIssue(send, apiUrl, projectId) {
|
|
106
|
+
const issues = await readIssues(send, { apiUrl, filter: { project_id: projectId }, pages: onePage });
|
|
107
|
+
return newest(issues, (issue) => issue.first_seen_at);
|
|
108
|
+
}
|
|
109
|
+
async function readAlerts(send, projectId) {
|
|
110
|
+
const path = `/api/projects/${encodeURIComponent(projectId)}/alert-rules`;
|
|
111
|
+
const body = await call(send, { credential: "apiToken", method: "GET", path });
|
|
112
|
+
const rules = (0, records_1.isFields)(body) ? body["rules"] : undefined;
|
|
113
|
+
return (0, records_1.compact)(listOf(rules).map((value) => (0, records_1.parseAlert)(value)));
|
|
114
|
+
}
|
|
115
|
+
async function pollFiredAlerts(send, projectId, cursor) {
|
|
116
|
+
const alerts = await readAlerts(send, projectId);
|
|
117
|
+
return newerThan(alerts, cursor, (alert) => alert.last_fired_at);
|
|
118
|
+
}
|
|
119
|
+
async function latestAlert(send, projectId) {
|
|
120
|
+
return newest(await readAlerts(send, projectId), (alert) => alert.last_fired_at);
|
|
121
|
+
}
|
|
122
|
+
async function resolveIssue(send, apiUrl, issueId) {
|
|
123
|
+
const path = `/api/telemetry/issues/${encodeURIComponent(issueId)}`;
|
|
124
|
+
const body = await call(send, {
|
|
125
|
+
body: { status: "resolved" },
|
|
126
|
+
credential: "apiToken",
|
|
127
|
+
method: "PATCH",
|
|
128
|
+
path,
|
|
129
|
+
query: { response_version: issueVersion },
|
|
130
|
+
});
|
|
131
|
+
const issue = (0, records_1.parseIssue)(body, dashboardOrigin(apiUrl));
|
|
132
|
+
if (issue === undefined) {
|
|
133
|
+
throw new LogBrewError(okStatus, "LogBrew sent an issue in an unknown format");
|
|
134
|
+
}
|
|
135
|
+
return issue;
|
|
136
|
+
}
|
|
137
|
+
async function sendLog(send, log) {
|
|
138
|
+
const body = {
|
|
139
|
+
environment: log.environment,
|
|
140
|
+
items: [
|
|
141
|
+
{
|
|
142
|
+
data: {
|
|
143
|
+
attributes: log.attributes,
|
|
144
|
+
id: log.id,
|
|
145
|
+
level: log.level,
|
|
146
|
+
message: log.message,
|
|
147
|
+
occurred_at: log.occurredAt,
|
|
148
|
+
source: "n8n",
|
|
149
|
+
},
|
|
150
|
+
type: "log",
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
project_id: log.projectId,
|
|
154
|
+
release: log.release,
|
|
155
|
+
sdk_name: sdkName,
|
|
156
|
+
sdk_version: sdkVersion,
|
|
157
|
+
service_name: log.serviceName,
|
|
158
|
+
};
|
|
159
|
+
return call(send, { body, credential: "ingestKey", method: "POST", path: "/api/telemetry/ingest" });
|
|
160
|
+
}
|
|
161
|
+
function levelOf(value) {
|
|
162
|
+
const level = levels.find((known) => known === value);
|
|
163
|
+
if (level === undefined) {
|
|
164
|
+
throw new LogBrewError(noHttpStatus, `Unknown log level "${value}". Use debug, info, warning, error, or critical.`);
|
|
165
|
+
}
|
|
166
|
+
return level;
|
|
167
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compact = compact;
|
|
4
|
+
exports.isFields = isFields;
|
|
5
|
+
exports.parseAlert = parseAlert;
|
|
6
|
+
exports.parseIssue = parseIssue;
|
|
7
|
+
exports.text = text;
|
|
8
|
+
const missingCount = 0;
|
|
9
|
+
function isFields(value) {
|
|
10
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
function text(fields, key) {
|
|
13
|
+
const value = fields[key];
|
|
14
|
+
return typeof value === "string" ? value : "";
|
|
15
|
+
}
|
|
16
|
+
function parseIssue(value, dashboard) {
|
|
17
|
+
if (!isFields(value)) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const id = text(value, "id");
|
|
21
|
+
const firstSeenAt = text(value, "first_seen_at");
|
|
22
|
+
if (id === "" || Number.isNaN(Date.parse(firstSeenAt))) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const { triage } = value;
|
|
26
|
+
const effective = isFields(triage) ? text(triage, "effective_severity") : "";
|
|
27
|
+
const count = value["occurrence_count"];
|
|
28
|
+
return {
|
|
29
|
+
environment: text(value, "environment"),
|
|
30
|
+
first_seen_at: firstSeenAt,
|
|
31
|
+
id,
|
|
32
|
+
last_seen_at: text(value, "last_seen_at"),
|
|
33
|
+
message: text(value, "message"),
|
|
34
|
+
occurrence_count: typeof count === "number" ? count : missingCount,
|
|
35
|
+
project_id: text(value, "project_id"),
|
|
36
|
+
release: text(value, "release"),
|
|
37
|
+
service_name: text(value, "service_name"),
|
|
38
|
+
severity: effective === "" ? text(value, "severity") : effective,
|
|
39
|
+
status: text(value, "status"),
|
|
40
|
+
title: text(value, "title"),
|
|
41
|
+
url: `${dashboard}/dashboard/issues/${encodeURIComponent(id)}`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function parseAlert(value) {
|
|
45
|
+
if (!isFields(value)) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const id = text(value, "id");
|
|
49
|
+
const lastFiredAt = text(value, "last_fired_at");
|
|
50
|
+
if (id === "" || Number.isNaN(Date.parse(lastFiredAt))) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
environment: text(value, "environment"),
|
|
55
|
+
id,
|
|
56
|
+
kind: text(value, "kind"),
|
|
57
|
+
last_fired_at: lastFiredAt,
|
|
58
|
+
name: text(value, "name"),
|
|
59
|
+
project_id: text(value, "project_id"),
|
|
60
|
+
service: text(value, "service"),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function compact(items) {
|
|
64
|
+
return items.filter((item) => item !== undefined);
|
|
65
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.connect = connect;
|
|
4
|
+
exports.projectOptions = projectOptions;
|
|
5
|
+
const client_1 = require("./client");
|
|
6
|
+
const credentialName = "logBrewApi";
|
|
7
|
+
function setting(credentials, key) {
|
|
8
|
+
const value = credentials[key];
|
|
9
|
+
return typeof value === "string" ? value.trim() : "";
|
|
10
|
+
}
|
|
11
|
+
function replyOf(response) {
|
|
12
|
+
if (typeof response !== "object" || response === null) {
|
|
13
|
+
return { body: undefined, status: client_1.noHttpStatus };
|
|
14
|
+
}
|
|
15
|
+
const body = Reflect.get(response, "body");
|
|
16
|
+
const status = Reflect.get(response, "statusCode");
|
|
17
|
+
return { body, status: typeof status === "number" ? status : client_1.noHttpStatus };
|
|
18
|
+
}
|
|
19
|
+
async function connect(context) {
|
|
20
|
+
const credentials = await context.getCredentials(credentialName);
|
|
21
|
+
const configured = setting(credentials, "apiUrl").replace(/\/+$/u, "");
|
|
22
|
+
const apiUrl = configured === "" ? client_1.defaultApiUrl : configured;
|
|
23
|
+
const ingestKey = setting(credentials, "ingestKey");
|
|
24
|
+
async function send(request) {
|
|
25
|
+
const options = {
|
|
26
|
+
ignoreHttpStatusErrors: true,
|
|
27
|
+
json: true,
|
|
28
|
+
method: request.method,
|
|
29
|
+
returnFullResponse: true,
|
|
30
|
+
url: `${apiUrl}${request.path}`,
|
|
31
|
+
...(request.body === undefined ? {} : { body: request.body }),
|
|
32
|
+
...(request.query === undefined ? {} : { qs: request.query }),
|
|
33
|
+
};
|
|
34
|
+
if (request.credential === "apiToken") {
|
|
35
|
+
return replyOf(await context.helpers.httpRequestWithAuthentication.call(context, credentialName, options));
|
|
36
|
+
}
|
|
37
|
+
if (ingestKey === "") {
|
|
38
|
+
throw new client_1.LogBrewError(client_1.noHttpStatus, "Ingest key missing. Add one to the LogBrew credential to send logs.");
|
|
39
|
+
}
|
|
40
|
+
return replyOf(await context.helpers.httpRequest({ ...options, headers: { Authorization: `Bearer ${ingestKey}` } }));
|
|
41
|
+
}
|
|
42
|
+
return { apiUrl, send };
|
|
43
|
+
}
|
|
44
|
+
async function projectOptions(context) {
|
|
45
|
+
const { send } = await connect(context);
|
|
46
|
+
const projects = await (0, client_1.listProjects)(send);
|
|
47
|
+
return projects.map((project) => ({ name: project.name, value: project.id }));
|
|
48
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogBrewTrigger = void 0;
|
|
4
|
+
const transport_1 = require("../LogBrew/transport");
|
|
5
|
+
const client_1 = require("../LogBrew/client");
|
|
6
|
+
function parameter(context, name) {
|
|
7
|
+
const value = context.getNodeParameter(name, "");
|
|
8
|
+
return typeof value === "string" ? value : "";
|
|
9
|
+
}
|
|
10
|
+
async function find(context, cursor) {
|
|
11
|
+
const { apiUrl, send } = await (0, transport_1.connect)(context);
|
|
12
|
+
const projectId = parameter(context, "projectId");
|
|
13
|
+
const alerts = parameter(context, "event") === "alertFired";
|
|
14
|
+
if (context.getMode() === "manual") {
|
|
15
|
+
const items = alerts ? await (0, client_1.latestAlert)(send, projectId) : await (0, client_1.latestIssue)(send, apiUrl, projectId);
|
|
16
|
+
return { cursor, items };
|
|
17
|
+
}
|
|
18
|
+
const found = alerts
|
|
19
|
+
? await (0, client_1.pollFiredAlerts)(send, projectId, cursor)
|
|
20
|
+
: await (0, client_1.pollNewIssues)(send, { apiUrl, cursor, projectId });
|
|
21
|
+
return found;
|
|
22
|
+
}
|
|
23
|
+
class LogBrewTrigger {
|
|
24
|
+
description = {
|
|
25
|
+
credentials: [{ name: "logBrewApi", required: true }],
|
|
26
|
+
defaults: { name: "LogBrew Trigger" },
|
|
27
|
+
description: "Start a workflow when LogBrew finds a new issue or an alert fires",
|
|
28
|
+
displayName: "LogBrew Trigger",
|
|
29
|
+
group: ["trigger"],
|
|
30
|
+
icon: { dark: "file:../../icons/logbrew.dark.svg", light: "file:../../icons/logbrew.svg" },
|
|
31
|
+
inputs: [],
|
|
32
|
+
name: "logBrewTrigger",
|
|
33
|
+
outputs: ["main"],
|
|
34
|
+
polling: true,
|
|
35
|
+
properties: [
|
|
36
|
+
{
|
|
37
|
+
displayName: "Event",
|
|
38
|
+
default: "issueCreated",
|
|
39
|
+
name: "event",
|
|
40
|
+
options: [
|
|
41
|
+
{
|
|
42
|
+
description: "An error group LogBrew has not seen before",
|
|
43
|
+
name: "New Issue",
|
|
44
|
+
value: "issueCreated",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
description: "One of the project's alert rules fired",
|
|
48
|
+
name: "Alert Fired",
|
|
49
|
+
value: "alertFired",
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
type: "options",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
displayName: "Project Name or ID",
|
|
56
|
+
default: "",
|
|
57
|
+
description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>',
|
|
58
|
+
name: "projectId",
|
|
59
|
+
required: true,
|
|
60
|
+
type: "options",
|
|
61
|
+
typeOptions: { loadOptionsMethod: "getProjects" },
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
subtitle: '={{$parameter["event"]}}',
|
|
65
|
+
version: 1,
|
|
66
|
+
};
|
|
67
|
+
methods = {
|
|
68
|
+
loadOptions: {
|
|
69
|
+
async getProjects() {
|
|
70
|
+
return (0, transport_1.projectOptions)(this);
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
async poll() {
|
|
75
|
+
const state = this.getWorkflowStaticData("node");
|
|
76
|
+
const saved = state["cursor"];
|
|
77
|
+
const cursor = typeof saved === "string" ? saved : new Date().toISOString();
|
|
78
|
+
const found = await find(this, cursor);
|
|
79
|
+
state["cursor"] = found.cursor;
|
|
80
|
+
const [first] = found.items;
|
|
81
|
+
if (first === undefined) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return [found.items.map((item) => ({ json: { ...item } }))];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.LogBrewTrigger = LogBrewTrigger;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"node": "n8n-nodes-logbrew.logBrewTrigger",
|
|
3
|
+
"nodeVersion": "1.0",
|
|
4
|
+
"codexVersion": "1.0",
|
|
5
|
+
"categories": ["Development"],
|
|
6
|
+
"resources": {
|
|
7
|
+
"credentialDocumentation": [{ "url": "https://github.com/LogBrewCo/sdk/tree/main/apps/n8n#credentials" }],
|
|
8
|
+
"primaryDocumentation": [{ "url": "https://github.com/LogBrewCo/sdk/tree/main/apps/n8n#readme" }]
|
|
9
|
+
}
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-logbrew",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "LogBrew nodes for n8n. Start workflows on new issues and fired alerts, send logs, and resolve issues.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://logbrew.co",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"n8n-community-node-package",
|
|
9
|
+
"logbrew",
|
|
10
|
+
"error tracking",
|
|
11
|
+
"logging",
|
|
12
|
+
"monitoring"
|
|
13
|
+
],
|
|
14
|
+
"author": {
|
|
15
|
+
"name": "LogBrew",
|
|
16
|
+
"email": "support@logbrew.co"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/LogBrewCo/sdk.git",
|
|
21
|
+
"directory": "apps/n8n"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc --project tsconfig.build.json && mkdir -p dist/icons && cp icons/*.svg dist/icons/ && cp nodes/LogBrew/LogBrew.node.json dist/nodes/LogBrew/ && cp nodes/LogBrewTrigger/LogBrewTrigger.node.json dist/nodes/LogBrewTrigger/",
|
|
25
|
+
"lint": "n8n-node lint",
|
|
26
|
+
"test": "bun test"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"n8n": {
|
|
32
|
+
"n8nNodesApiVersion": 1,
|
|
33
|
+
"strict": true,
|
|
34
|
+
"credentials": [
|
|
35
|
+
"dist/credentials/LogBrewApi.credentials.js"
|
|
36
|
+
],
|
|
37
|
+
"nodes": [
|
|
38
|
+
"dist/nodes/LogBrew/LogBrew.node.js",
|
|
39
|
+
"dist/nodes/LogBrewTrigger/LogBrewTrigger.node.js"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@n8n/node-cli": "0.58.6",
|
|
44
|
+
"@types/bun": "1.4.4",
|
|
45
|
+
"@types/node": "26.6.10",
|
|
46
|
+
"eslint": "10.15.0",
|
|
47
|
+
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"n8n-workflow": "*"
|
|
51
|
+
}
|
|
52
|
+
}
|