@czlonkowski/n8n-nodes-librus 0.1.0
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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/NOTICE.md +7 -0
- package/README.md +152 -0
- package/SECURITY.md +15 -0
- package/dist/credentials/LibrusSessionApi.credentials.d.ts +8 -0
- package/dist/credentials/LibrusSessionApi.credentials.js +32 -0
- package/dist/credentials/LibrusSessionApi.credentials.js.map +1 -0
- package/dist/nodes/Librus/Librus.node.d.ts +10 -0
- package/dist/nodes/Librus/Librus.node.js +225 -0
- package/dist/nodes/Librus/Librus.node.js.map +1 -0
- package/dist/nodes/Librus/LibrusClient.d.ts +67 -0
- package/dist/nodes/Librus/LibrusClient.js +393 -0
- package/dist/nodes/Librus/LibrusClient.js.map +1 -0
- package/dist/nodes/Librus/LibrusTrigger.node.d.ts +10 -0
- package/dist/nodes/Librus/LibrusTrigger.node.js +90 -0
- package/dist/nodes/Librus/LibrusTrigger.node.js.map +1 -0
- package/dist/nodes/Librus/librus.png +0 -0
- package/dist/nodes/Librus/pollState.d.ts +4 -0
- package/dist/nodes/Librus/pollState.js +46 -0
- package/dist/nodes/Librus/pollState.js.map +1 -0
- package/dist/nodes/Librus/transport.d.ts +4 -0
- package/dist/nodes/Librus/transport.js +33 -0
- package/dist/nodes/Librus/transport.js.map +1 -0
- package/docs/architecture.md +53 -0
- package/docs/live-verification.md +23 -0
- package/docs/logo.md +11 -0
- package/docs/verification.md +41 -0
- package/package.json +76 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LibrusClient = exports.LibrusError = void 0;
|
|
4
|
+
exports.safeError = safeError;
|
|
5
|
+
const tough_cookie_1 = require("tough-cookie");
|
|
6
|
+
const messages = {
|
|
7
|
+
UNSAFE_URL: 'Librus returned an unexpected destination. No request was sent to it.',
|
|
8
|
+
TRANSPORT_ERROR: 'The Librus request failed. Check connectivity and try again later.',
|
|
9
|
+
PROTOCOL_ERROR: 'Librus returned an unexpected response. The integration may need updating.',
|
|
10
|
+
AUTH_FAILED: 'Librus login was not accepted. Check your credentials in the Librus website.',
|
|
11
|
+
ACTION_REQUIRED: 'Complete any login verification or account prompts in the Librus website.',
|
|
12
|
+
SESSION_EXPIRED: 'The Librus session expired during the request.',
|
|
13
|
+
RATE_LIMITED: 'Librus is limiting requests. Wait before trying again.',
|
|
14
|
+
ACCESS_DENIED: 'Librus denied this request. Check account access in the website.',
|
|
15
|
+
SERVICE_ERROR: 'Librus is unavailable or returned an unexpected HTTP status.',
|
|
16
|
+
SCAN_INCOMPLETE: 'The inbox scan could not finish within its safety limits. Increase Maximum Pages or use a bounded Limit.',
|
|
17
|
+
FULL_CONTENT_LIMIT: 'Full message content is limited to 50 messages per execution. Turn off Return All and set Limit to 50 or less.',
|
|
18
|
+
INVALID_OPTIONS: 'Invalid Librus credentials or scan options.',
|
|
19
|
+
TRIGGER_STATE_INVALID: 'The saved Librus trigger state is invalid. Recreate the trigger to establish a new inbox baseline.',
|
|
20
|
+
TRIGGER_STATE_LIMIT: 'The Librus trigger has reached its 10000-message history limit. Recreate the trigger to establish a new inbox baseline.',
|
|
21
|
+
};
|
|
22
|
+
class LibrusError extends Error {
|
|
23
|
+
constructor(code, stage, destination, rejection) {
|
|
24
|
+
var _a;
|
|
25
|
+
super(((_a = messages[code]) !== null && _a !== void 0 ? _a : messages.PROTOCOL_ERROR) +
|
|
26
|
+
(stage ? ` [Step: ${stage}; page: ${destination}]` : '') +
|
|
27
|
+
(rejection ? ` [Redirect rejected: ${rejection}]` : ''));
|
|
28
|
+
this.code = code;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.LibrusError = LibrusError;
|
|
32
|
+
function safeError(error) {
|
|
33
|
+
return error instanceof LibrusError ? error : new LibrusError('PROTOCOL_ERROR');
|
|
34
|
+
}
|
|
35
|
+
const allowedHosts = new Set([
|
|
36
|
+
'portal.librus.pl',
|
|
37
|
+
'synergia.librus.pl',
|
|
38
|
+
'api.librus.pl',
|
|
39
|
+
'wiadomosci.librus.pl',
|
|
40
|
+
]);
|
|
41
|
+
function checkedUrl(value, base) {
|
|
42
|
+
let url;
|
|
43
|
+
try {
|
|
44
|
+
url = new URL(value, base);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new LibrusError('UNSAFE_URL');
|
|
48
|
+
}
|
|
49
|
+
if (url.protocol !== 'https:' ||
|
|
50
|
+
url.port ||
|
|
51
|
+
url.username ||
|
|
52
|
+
url.password ||
|
|
53
|
+
!allowedHosts.has(url.hostname)) {
|
|
54
|
+
const rejection = url.protocol !== 'https:'
|
|
55
|
+
? 'non-HTTPS destination'
|
|
56
|
+
: url.username || url.password
|
|
57
|
+
? 'URL credentials'
|
|
58
|
+
: url.port
|
|
59
|
+
? 'non-default port'
|
|
60
|
+
: 'unrecognized hostname';
|
|
61
|
+
throw new LibrusError('UNSAFE_URL', undefined, undefined, rejection);
|
|
62
|
+
}
|
|
63
|
+
return url;
|
|
64
|
+
}
|
|
65
|
+
function checkedRedirect(value, base) {
|
|
66
|
+
let url;
|
|
67
|
+
try {
|
|
68
|
+
url = new URL(value, base);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
throw new LibrusError('UNSAFE_URL');
|
|
72
|
+
}
|
|
73
|
+
if (url.protocol === 'http:' &&
|
|
74
|
+
allowedHosts.has(url.hostname) &&
|
|
75
|
+
!url.port &&
|
|
76
|
+
!url.username &&
|
|
77
|
+
!url.password)
|
|
78
|
+
url.protocol = 'https:';
|
|
79
|
+
return checkedUrl(url.href);
|
|
80
|
+
}
|
|
81
|
+
function authUrl(url) {
|
|
82
|
+
return url.hostname === 'api.librus.pl' && /^\/OAuth\/Authorization(?:\/|$)/.test(url.pathname);
|
|
83
|
+
}
|
|
84
|
+
function actionRequired(stage, url) {
|
|
85
|
+
const destination = authUrl(url)
|
|
86
|
+
? 'OAuth authorization'
|
|
87
|
+
: url.hostname === 'synergia.librus.pl' && url.pathname === '/loguj/portalRodzina'
|
|
88
|
+
? 'Synergia OAuth callback'
|
|
89
|
+
: url.hostname === 'synergia.librus.pl' && /^\/loguj(?:\/|$)/.test(url.pathname)
|
|
90
|
+
? 'Synergia login'
|
|
91
|
+
: url.hostname === 'synergia.librus.pl'
|
|
92
|
+
? 'Synergia page'
|
|
93
|
+
: url.hostname === 'wiadomosci.librus.pl'
|
|
94
|
+
? 'messages service'
|
|
95
|
+
: 'other allowed page';
|
|
96
|
+
return new LibrusError('ACTION_REQUIRED', stage, destination);
|
|
97
|
+
}
|
|
98
|
+
function object(value) {
|
|
99
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
100
|
+
}
|
|
101
|
+
function parseJson(body) {
|
|
102
|
+
try {
|
|
103
|
+
return JSON.parse(body);
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function isHtml(body) {
|
|
110
|
+
return /^\s*<(?:!doctype\s+html|html\b|form\b)/i.test(body);
|
|
111
|
+
}
|
|
112
|
+
function isLoginForm(body) {
|
|
113
|
+
return (isHtml(body) &&
|
|
114
|
+
/<form\b/i.test(body) &&
|
|
115
|
+
/<input\b[^>]*\bname\s*=\s*["'](?:pass|password)["']/i.test(body) &&
|
|
116
|
+
/<input\b[^>]*\bname\s*=\s*["']login["']/i.test(body));
|
|
117
|
+
}
|
|
118
|
+
function decodeContent(value) {
|
|
119
|
+
if (typeof value !== 'string' ||
|
|
120
|
+
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value)) {
|
|
121
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(Buffer.from(value, 'base64'));
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function parseMessage(value, includeContent) {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
if (!object(value))
|
|
133
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
134
|
+
const strings = [
|
|
135
|
+
'messageId',
|
|
136
|
+
'senderFirstName',
|
|
137
|
+
'senderLastName',
|
|
138
|
+
'senderName',
|
|
139
|
+
'topic',
|
|
140
|
+
'sendDate',
|
|
141
|
+
];
|
|
142
|
+
if (strings.some((key) => typeof value[key] !== 'string') ||
|
|
143
|
+
!value.messageId ||
|
|
144
|
+
!(value.readDate === undefined ||
|
|
145
|
+
value.readDate === null ||
|
|
146
|
+
typeof value.readDate === 'string') ||
|
|
147
|
+
!(value.category === undefined ||
|
|
148
|
+
value.category === null ||
|
|
149
|
+
typeof value.category === 'string') ||
|
|
150
|
+
typeof value.isAnyFileAttached !== 'boolean' ||
|
|
151
|
+
!Array.isArray(value.tags) ||
|
|
152
|
+
value.tags.some((tag) => typeof tag !== 'string'))
|
|
153
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
154
|
+
const result = Object.fromEntries(strings.map((key) => [key, value[key]]));
|
|
155
|
+
result.readDate = (_a = value.readDate) !== null && _a !== void 0 ? _a : null;
|
|
156
|
+
result.category = (_b = value.category) !== null && _b !== void 0 ? _b : null;
|
|
157
|
+
result.isAnyFileAttached = value.isAnyFileAttached;
|
|
158
|
+
result.tags = value.tags;
|
|
159
|
+
if (includeContent) {
|
|
160
|
+
result.content = decodeContent(value.content);
|
|
161
|
+
result.contentSource = 'preview';
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
class LibrusClient {
|
|
166
|
+
constructor(transport, login) {
|
|
167
|
+
this.transport = transport;
|
|
168
|
+
this.login = login;
|
|
169
|
+
this.jar = new tough_cookie_1.CookieJar();
|
|
170
|
+
this.deadline = 0;
|
|
171
|
+
this.requests = 0;
|
|
172
|
+
}
|
|
173
|
+
async request(value, body) {
|
|
174
|
+
let url = checkedUrl(value);
|
|
175
|
+
for (let hop = 0; hop <= 10; hop++) {
|
|
176
|
+
if (++this.requests > 100 || Date.now() >= this.deadline)
|
|
177
|
+
throw new LibrusError('SCAN_INCOMPLETE');
|
|
178
|
+
if (body !== undefined && !authUrl(url))
|
|
179
|
+
throw new LibrusError('UNSAFE_URL');
|
|
180
|
+
const headers = {
|
|
181
|
+
Accept: 'application/json, text/html;q=0.9',
|
|
182
|
+
'User-Agent': 'n8n-nodes-librus/0.1',
|
|
183
|
+
};
|
|
184
|
+
const cookie = await this.jar.getCookieString(url.href);
|
|
185
|
+
if (cookie)
|
|
186
|
+
headers.Cookie = cookie;
|
|
187
|
+
if (body !== undefined)
|
|
188
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
189
|
+
const remaining = this.deadline - Date.now();
|
|
190
|
+
if (remaining <= 0)
|
|
191
|
+
throw new LibrusError('SCAN_INCOMPLETE');
|
|
192
|
+
let response;
|
|
193
|
+
try {
|
|
194
|
+
response = await this.transport({
|
|
195
|
+
url: url.href,
|
|
196
|
+
method: body === undefined ? 'GET' : 'POST',
|
|
197
|
+
headers,
|
|
198
|
+
body,
|
|
199
|
+
timeout: Math.max(1, Math.min(15000, remaining)),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
throw new LibrusError('TRANSPORT_ERROR');
|
|
204
|
+
}
|
|
205
|
+
if (typeof response.body !== 'string' || response.body.length > 10000000)
|
|
206
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
207
|
+
const normalized = Object.fromEntries(Object.entries(response.headers).map(([key, val]) => [key.toLowerCase(), val]));
|
|
208
|
+
const cookies = normalized['set-cookie'];
|
|
209
|
+
for (const entry of cookies === undefined
|
|
210
|
+
? []
|
|
211
|
+
: Array.isArray(cookies)
|
|
212
|
+
? cookies
|
|
213
|
+
: [cookies]) {
|
|
214
|
+
try {
|
|
215
|
+
await this.jar.setCookie(entry, url.href);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if ([301, 302, 303, 307, 308].includes(response.statusCode)) {
|
|
222
|
+
if (body !== undefined)
|
|
223
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
224
|
+
const location = normalized.location;
|
|
225
|
+
if (typeof location !== 'string')
|
|
226
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
227
|
+
url = checkedRedirect(location, url.href);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (response.statusCode === 429)
|
|
231
|
+
throw new LibrusError('RATE_LIMITED');
|
|
232
|
+
if (response.statusCode === 401)
|
|
233
|
+
throw new LibrusError('SESSION_EXPIRED');
|
|
234
|
+
if ((response.statusCode === 403 || response.statusCode === 200) &&
|
|
235
|
+
url.hostname === 'wiadomosci.librus.pl' &&
|
|
236
|
+
/^\/api\/inbox\/messages(?:\/[A-Za-z0-9_-]+)?$/.test(url.pathname) &&
|
|
237
|
+
isLoginForm(response.body))
|
|
238
|
+
throw new LibrusError('SESSION_EXPIRED');
|
|
239
|
+
if (response.statusCode === 403)
|
|
240
|
+
throw new LibrusError('ACCESS_DENIED');
|
|
241
|
+
if (response.statusCode < 200 || response.statusCode >= 300)
|
|
242
|
+
throw new LibrusError('SERVICE_ERROR');
|
|
243
|
+
return { ...response, url };
|
|
244
|
+
}
|
|
245
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
246
|
+
}
|
|
247
|
+
async authenticate() {
|
|
248
|
+
this.jar = new tough_cookie_1.CookieJar();
|
|
249
|
+
const entry = await this.request('https://synergia.librus.pl/loguj/portalRodzina');
|
|
250
|
+
if (!authUrl(entry.url))
|
|
251
|
+
throw actionRequired('login entry', entry.url);
|
|
252
|
+
const form = new URLSearchParams({
|
|
253
|
+
action: 'login',
|
|
254
|
+
login: this.login.username,
|
|
255
|
+
pass: this.login.password,
|
|
256
|
+
});
|
|
257
|
+
const loginReply = await this.request(entry.url.href, form.toString());
|
|
258
|
+
if (isHtml(loginReply.body))
|
|
259
|
+
throw actionRequired('credential submission', loginReply.url);
|
|
260
|
+
const reply = parseJson(loginReply.body);
|
|
261
|
+
if (!object(reply) || typeof reply.goTo !== 'string' || !reply.goTo)
|
|
262
|
+
throw new LibrusError('AUTH_FAILED');
|
|
263
|
+
const continuation = checkedUrl(reply.goTo, 'https://api.librus.pl');
|
|
264
|
+
if (!authUrl(continuation))
|
|
265
|
+
throw new LibrusError('UNSAFE_URL');
|
|
266
|
+
const authorized = await this.request(continuation.href);
|
|
267
|
+
if (authorized.url.hostname !== 'synergia.librus.pl' ||
|
|
268
|
+
(/\/loguj(?:\/|$)/.test(authorized.url.pathname) &&
|
|
269
|
+
!/^\/loguj\/portalRodzina\/?$/.test(authorized.url.pathname)) ||
|
|
270
|
+
isLoginForm(authorized.body))
|
|
271
|
+
throw actionRequired('authorization continuation', authorized.url);
|
|
272
|
+
await this.request('https://synergia.librus.pl/gateway/api/2.0/Auth/TokenInfo/');
|
|
273
|
+
const inbox = await this.request('https://synergia.librus.pl/wiadomosci3');
|
|
274
|
+
if (authUrl(inbox.url) || /\/loguj(?:\/|$)/.test(inbox.url.pathname))
|
|
275
|
+
throw actionRequired('messages initialization', inbox.url);
|
|
276
|
+
}
|
|
277
|
+
async getMessages(options) {
|
|
278
|
+
if (!this.login.username ||
|
|
279
|
+
!this.login.password ||
|
|
280
|
+
!Number.isInteger(options.limit) ||
|
|
281
|
+
options.limit < 1 ||
|
|
282
|
+
options.limit > 1000 ||
|
|
283
|
+
!Number.isInteger(options.maxPages) ||
|
|
284
|
+
options.maxPages < 1 ||
|
|
285
|
+
options.maxPages > 50 ||
|
|
286
|
+
(options.readStatus !== undefined &&
|
|
287
|
+
!['all', 'unread', 'read'].includes(options.readStatus)) ||
|
|
288
|
+
(options.contentSource !== undefined &&
|
|
289
|
+
options.contentSource !== 'preview' &&
|
|
290
|
+
options.contentSource !== 'full'))
|
|
291
|
+
throw new LibrusError('INVALID_OPTIONS');
|
|
292
|
+
this.deadline = Date.now() + 120000;
|
|
293
|
+
this.requests = 0;
|
|
294
|
+
await this.authenticate();
|
|
295
|
+
let unreadSelection;
|
|
296
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
297
|
+
try {
|
|
298
|
+
const result = unreadSelection !== null && unreadSelection !== void 0 ? unreadSelection : (await this.scan(options));
|
|
299
|
+
if (options.includeContent && options.contentSource === 'full') {
|
|
300
|
+
if (result.length > 50)
|
|
301
|
+
throw new LibrusError('FULL_CONTENT_LIMIT');
|
|
302
|
+
if (options.readStatus === 'unread')
|
|
303
|
+
unreadSelection = result;
|
|
304
|
+
for (const message of result) {
|
|
305
|
+
message.content = await this.fullContent(message.messageId);
|
|
306
|
+
message.contentSource = 'full';
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return result;
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
if (!(error instanceof LibrusError) || error.code !== 'SESSION_EXPIRED' || attempt === 1)
|
|
313
|
+
throw error;
|
|
314
|
+
await this.authenticate();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
throw new LibrusError('SESSION_EXPIRED');
|
|
318
|
+
}
|
|
319
|
+
async getMessageContent(messageId) {
|
|
320
|
+
if (!this.login.username ||
|
|
321
|
+
!this.login.password ||
|
|
322
|
+
typeof messageId !== 'string' ||
|
|
323
|
+
!/^[A-Za-z0-9_-]+$/.test(messageId))
|
|
324
|
+
throw new LibrusError('INVALID_OPTIONS');
|
|
325
|
+
this.deadline = Date.now() + 120000;
|
|
326
|
+
this.requests = 0;
|
|
327
|
+
await this.authenticate();
|
|
328
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
329
|
+
try {
|
|
330
|
+
return { messageId, content: await this.fullContent(messageId), contentSource: 'full' };
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
if (!(error instanceof LibrusError) || error.code !== 'SESSION_EXPIRED' || attempt === 1)
|
|
334
|
+
throw error;
|
|
335
|
+
await this.authenticate();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
throw new LibrusError('SESSION_EXPIRED');
|
|
339
|
+
}
|
|
340
|
+
async fullContent(messageId) {
|
|
341
|
+
if (!/^[A-Za-z0-9_-]+$/.test(messageId))
|
|
342
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
343
|
+
const path = `/api/inbox/messages/${encodeURIComponent(messageId)}`;
|
|
344
|
+
const response = await this.request(`https://wiadomosci.librus.pl${path}`);
|
|
345
|
+
if (authUrl(response.url) || /\/loguj(?:\/|$)/.test(response.url.pathname))
|
|
346
|
+
throw new LibrusError('SESSION_EXPIRED');
|
|
347
|
+
if (response.url.hostname !== 'wiadomosci.librus.pl' || response.url.pathname !== path)
|
|
348
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
349
|
+
const payload = parseJson(response.body);
|
|
350
|
+
if (!object(payload) || !object(payload.data) || payload.data.messageId !== messageId)
|
|
351
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
352
|
+
return decodeContent(payload.data.Message);
|
|
353
|
+
}
|
|
354
|
+
async scan(options) {
|
|
355
|
+
const pageSize = options.returnAll || (options.readStatus && options.readStatus !== 'all')
|
|
356
|
+
? 50
|
|
357
|
+
: Math.min(50, options.limit);
|
|
358
|
+
const found = new Map();
|
|
359
|
+
const scanned = new Set();
|
|
360
|
+
for (let page = 1; page <= options.maxPages; page++) {
|
|
361
|
+
const response = await this.request(`https://wiadomosci.librus.pl/api/inbox/messages?page=${page}&limit=${pageSize}`);
|
|
362
|
+
if (authUrl(response.url) || /\/loguj(?:\/|$)/.test(response.url.pathname))
|
|
363
|
+
throw new LibrusError('SESSION_EXPIRED');
|
|
364
|
+
if (response.url.hostname !== 'wiadomosci.librus.pl' ||
|
|
365
|
+
response.url.pathname !== '/api/inbox/messages')
|
|
366
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
367
|
+
const payload = parseJson(response.body);
|
|
368
|
+
if (!object(payload) || !Array.isArray(payload.data) || payload.data.length > pageSize)
|
|
369
|
+
throw new LibrusError('PROTOCOL_ERROR');
|
|
370
|
+
const before = scanned.size;
|
|
371
|
+
for (const raw of payload.data) {
|
|
372
|
+
const message = parseMessage(raw, options.includeContent && options.contentSource !== 'full');
|
|
373
|
+
scanned.add(message.messageId);
|
|
374
|
+
const unread = message.readDate === null || message.readDate === '';
|
|
375
|
+
if (!options.readStatus ||
|
|
376
|
+
options.readStatus === 'all' ||
|
|
377
|
+
(options.readStatus === 'unread' ? unread : !unread))
|
|
378
|
+
found.set(message.messageId, message);
|
|
379
|
+
}
|
|
380
|
+
if (!options.returnAll && found.size >= options.limit)
|
|
381
|
+
return [...found.values()].slice(0, options.limit);
|
|
382
|
+
if (payload.data.length === 0)
|
|
383
|
+
return [...found.values()];
|
|
384
|
+
if (scanned.size === before)
|
|
385
|
+
throw new LibrusError('SCAN_INCOMPLETE');
|
|
386
|
+
if (payload.data.length < pageSize)
|
|
387
|
+
return [...found.values()];
|
|
388
|
+
}
|
|
389
|
+
throw new LibrusError('SCAN_INCOMPLETE');
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
exports.LibrusClient = LibrusClient;
|
|
393
|
+
//# sourceMappingURL=LibrusClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LibrusClient.js","sourceRoot":"","sources":["../../../nodes/Librus/LibrusClient.ts"],"names":[],"mappings":";;;AA+FA,8BAEC;AAjGD,+CAAyC;AA4CzC,MAAM,QAAQ,GAA2B;IACxC,UAAU,EAAE,uEAAuE;IACnF,eAAe,EAAE,oEAAoE;IACrF,cAAc,EAAE,4EAA4E;IAC5F,WAAW,EAAE,8EAA8E;IAC3F,eAAe,EAAE,2EAA2E;IAC5F,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,KAAK,CAAC,IAAI,IAAI,OAAO,CAAC,KAAK;gBACpD,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;YACpD,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YAC1D,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;gBAAE,MAAM,IAAI,WAAW,CAAC,iBAAiB,CAAC,CAAC;YACtE,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,QAAQ;gBAAE,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,MAAM,IAAI,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAC1C,CAAC;CACD;AA1OD,oCA0OC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { INodeExecutionData, INodeType, INodeTypeDescription, IPollFunctions } from 'n8n-workflow';
|
|
2
|
+
export declare class LibrusTrigger implements INodeType {
|
|
3
|
+
description: INodeTypeDescription;
|
|
4
|
+
methods: {
|
|
5
|
+
credentialTest: {
|
|
6
|
+
librusConnectionTest(this: import("n8n-workflow").ICredentialTestFunctions, credential: import("n8n-workflow").ICredentialsDecrypted): Promise<import("n8n-workflow").INodeCredentialTestResult>;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LibrusTrigger = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const LibrusClient_1 = require("./LibrusClient");
|
|
6
|
+
const Librus_node_1 = require("./Librus.node");
|
|
7
|
+
const transport_1 = require("./transport");
|
|
8
|
+
const pollState_1 = require("./pollState");
|
|
9
|
+
class LibrusTrigger {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.description = {
|
|
12
|
+
displayName: 'Librus Trigger',
|
|
13
|
+
name: 'librusTrigger',
|
|
14
|
+
subtitle: 'New Message',
|
|
15
|
+
icon: 'file:librus.png',
|
|
16
|
+
group: ['trigger'],
|
|
17
|
+
version: 1,
|
|
18
|
+
description: 'Start a workflow when a new Librus inbox message is detected',
|
|
19
|
+
defaults: { name: 'Librus Trigger' },
|
|
20
|
+
polling: true,
|
|
21
|
+
inputs: [],
|
|
22
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
23
|
+
credentials: [{ name: 'librusSessionApi', required: true, testedBy: 'librusConnectionTest' }],
|
|
24
|
+
properties: [
|
|
25
|
+
{
|
|
26
|
+
displayName: 'The first automatic poll saves the current inbox without emitting old messages. Manual tests return one sample without changing this history. Set Poll Times to every 5 minutes or longer.',
|
|
27
|
+
name: 'baselineNotice',
|
|
28
|
+
type: 'notice',
|
|
29
|
+
default: '',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
displayName: 'Event',
|
|
33
|
+
name: 'event',
|
|
34
|
+
type: 'options',
|
|
35
|
+
noDataExpression: true,
|
|
36
|
+
options: [{ name: 'New Message', value: 'newMessage' }],
|
|
37
|
+
default: 'newMessage',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
displayName: 'Maximum Pages',
|
|
41
|
+
name: 'maxPages',
|
|
42
|
+
type: 'number',
|
|
43
|
+
default: 20,
|
|
44
|
+
typeOptions: { minValue: 1, maxValue: 50 },
|
|
45
|
+
description: 'Safety bound for scanning the entire inbox. Incomplete scans fail without advancing message history.',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
displayName: 'Include Preview',
|
|
49
|
+
name: 'includePreview',
|
|
50
|
+
type: 'boolean',
|
|
51
|
+
default: true,
|
|
52
|
+
description: 'Whether to include the shortened inbox preview. Use Librus → Get Content with the message ID for the full body; that may mark it as read.',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
this.methods = new Librus_node_1.Librus().methods;
|
|
57
|
+
}
|
|
58
|
+
async poll() {
|
|
59
|
+
var _a, _b, _c;
|
|
60
|
+
try {
|
|
61
|
+
if (this.getNodeParameter('event') !== 'newMessage')
|
|
62
|
+
throw new LibrusClient_1.LibrusError('INVALID_OPTIONS');
|
|
63
|
+
const credentials = await this.getCredentials('librusSessionApi');
|
|
64
|
+
if (typeof credentials.username !== 'string' || typeof credentials.password !== 'string')
|
|
65
|
+
throw new LibrusClient_1.LibrusError('INVALID_OPTIONS');
|
|
66
|
+
const client = new LibrusClient_1.LibrusClient((0, transport_1.createTransport)(this.helpers.httpRequest.bind(this.helpers)), {
|
|
67
|
+
username: credentials.username,
|
|
68
|
+
password: credentials.password,
|
|
69
|
+
});
|
|
70
|
+
const manual = this.getMode() === 'manual';
|
|
71
|
+
const messages = await client.getMessages({
|
|
72
|
+
returnAll: !manual,
|
|
73
|
+
limit: 1,
|
|
74
|
+
maxPages: this.getNodeParameter('maxPages'),
|
|
75
|
+
includeContent: this.getNodeParameter('includePreview'),
|
|
76
|
+
contentSource: 'preview',
|
|
77
|
+
});
|
|
78
|
+
const result = manual
|
|
79
|
+
? messages
|
|
80
|
+
: (0, pollState_1.selectNewMessages)(this.getWorkflowStaticData('node'), (0, pollState_1.accountKey)(credentials.username, (_c = (_b = (_a = this.getNode().credentials) === null || _a === void 0 ? void 0 : _a.librusSessionApi) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : ''), messages);
|
|
81
|
+
return result.length ? [result.map((message) => ({ json: { ...message } }))] : null;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
const safe = (0, LibrusClient_1.safeError)(error);
|
|
85
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${safe.code}: ${safe.message}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.LibrusTrigger = LibrusTrigger;
|
|
90
|
+
//# sourceMappingURL=LibrusTrigger.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LibrusTrigger.node.js","sourceRoot":"","sources":["../../../nodes/Librus/LibrusTrigger.node.ts"],"names":[],"mappings":";;;AAAA,+CAAuE;AAOvE,iDAAsE;AACtE,+CAAuC;AACvC,2CAA8C;AAC9C,2CAA4D;AAE5D,MAAa,aAAa;IAA1B;QACC,gBAAW,GAAyB;YACnC,WAAW,EAAE,gBAAgB;YAC7B,IAAI,EAAE,eAAe;YACrB,QAAQ,EAAE,aAAa;YACvB,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,OAAO,EAAE,CAAC;YACV,WAAW,EAAE,8DAA8D;YAC3E,QAAQ,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE;YACpC,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,CAAC,kCAAmB,CAAC,IAAI,CAAC;YACnC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,sBAAsB,EAAE,CAAC;YAC7F,UAAU,EAAE;gBACX;oBACC,WAAW,EACV,4LAA4L;oBAC7L,IAAI,EAAE,gBAAgB;oBACtB,IAAI,EAAE,QAAQ;oBACd,OAAO,EAAE,EAAE;iBACX;gBACD;oBACC,WAAW,EAAE,OAAO;oBACpB,IAAI,EAAE,OAAO;oBACb,IAAI,EAAE,SAAS;oBACf,gBAAgB,EAAE,IAAI;oBACtB,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;oBACvD,OAAO,EAAE,YAAY;iBACrB;gBACD;oBACC,WAAW,EAAE,eAAe;oBAC5B,IAAI,EAAE,UAA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BAAgB,CAAC,UAAU,CAAW;gBACrD,cAAc,EAAE,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAY;gBAClE,aAAa,EAAE,SAAS;aACxB,CAAC,CAAC;YACH,MAAM,MAAM,GAAG,MAAM;gBACpB,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,IAAA,6BAAiB,EACjB,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAClC,IAAA,sBAAU,EACT,WAAW,CAAC,QAAQ,EACpB,MAAA,MAAA,MAAA,IAAI,CAAC,OAAO,EAAE,CAAC,WAAW,0CAAE,gBAAgB,0CAAE,EAAE,mCAAI,EAAE,CACtD,EACD,QAAQ,CACR,CAAC;YACJ,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,GAAG,IAAA,wBAAS,EAAC,KAAK,CAAC,CAAC;YAC9B,MAAM,IAAI,iCAAkB,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/E,CAAC;IACF,CAAC;CACD;AAzFD,sCAyFC"}
|
|
Binary file
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IDataObject } from 'n8n-workflow';
|
|
2
|
+
import { type Message } from './LibrusClient';
|
|
3
|
+
export declare function accountKey(username: string, credentialId: string): string;
|
|
4
|
+
export declare function selectNewMessages(state: IDataObject, account: string, messages: Message[]): Message[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.accountKey = accountKey;
|
|
4
|
+
exports.selectNewMessages = selectNewMessages;
|
|
5
|
+
const node_crypto_1 = require("node:crypto");
|
|
6
|
+
const LibrusClient_1 = require("./LibrusClient");
|
|
7
|
+
const MAX_SEEN_IDS = 10000;
|
|
8
|
+
function accountKey(username, credentialId) {
|
|
9
|
+
return (0, node_crypto_1.createHash)('sha256')
|
|
10
|
+
.update(JSON.stringify([credentialId, username]))
|
|
11
|
+
.digest('hex');
|
|
12
|
+
}
|
|
13
|
+
function selectNewMessages(state, account, messages) {
|
|
14
|
+
const raw = state.librus;
|
|
15
|
+
if (raw !== undefined && (!raw || typeof raw !== 'object' || Array.isArray(raw)))
|
|
16
|
+
throw new LibrusClient_1.LibrusError('TRIGGER_STATE_INVALID');
|
|
17
|
+
const previous = raw;
|
|
18
|
+
let seen = new Set();
|
|
19
|
+
let baseline = true;
|
|
20
|
+
if (previous !== undefined) {
|
|
21
|
+
if (previous.version !== 1 ||
|
|
22
|
+
typeof previous.account !== 'string' ||
|
|
23
|
+
!Array.isArray(previous.seenIds) ||
|
|
24
|
+
previous.seenIds.length > MAX_SEEN_IDS ||
|
|
25
|
+
previous.seenIds.some((id) => typeof id !== 'string' || !id))
|
|
26
|
+
throw new LibrusClient_1.LibrusError('TRIGGER_STATE_INVALID');
|
|
27
|
+
if (previous.account === account) {
|
|
28
|
+
seen = new Set(previous.seenIds);
|
|
29
|
+
baseline = false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const fresh = [];
|
|
33
|
+
for (const message of messages) {
|
|
34
|
+
if (!seen.has(message.messageId)) {
|
|
35
|
+
seen.add(message.messageId);
|
|
36
|
+
if (!baseline)
|
|
37
|
+
fresh.push(message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (seen.size > MAX_SEEN_IDS)
|
|
41
|
+
throw new LibrusClient_1.LibrusError('TRIGGER_STATE_LIMIT');
|
|
42
|
+
if (baseline || fresh.length)
|
|
43
|
+
state.librus = { version: 1, account, seenIds: [...seen] };
|
|
44
|
+
return fresh;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=pollState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pollState.js","sourceRoot":"","sources":["../../../nodes/Librus/pollState.ts"],"names":[],"mappings":";;AAMA,gCAIC;AAGD,8CAmCC;AAhDD,6CAAyC;AAEzC,iDAA2D;AAE3D,MAAM,YAAY,GAAG,KAAK,CAAC;AAE3B,SAAgB,UAAU,CAAC,QAAgB,EAAE,YAAoB;IAChE,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC;SACzB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;SAChD,MAAM,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC;AAGD,SAAgB,iBAAiB,CAChC,KAAkB,EAClB,OAAe,EACf,QAAmB;IAEnB,MAAM,GAAG,GAAY,KAAK,CAAC,MAAM,CAAC;IAClC,IAAI,GAAG,KAAK,SAAS,IAAI,CAAC,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC/E,MAAM,IAAI,0BAAW,CAAC,uBAAuB,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,GAA0C,CAAC;IAC5D,IAAI,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC7B,IAAI,QAAQ,GAAG,IAAI,CAAC;IACpB,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC5B,IACC,QAAQ,CAAC,OAAO,KAAK,CAAC;YACtB,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ;YACpC,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;YAChC,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,YAAY;YACtC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,EAAE,CAAC;YAE5D,MAAM,IAAI,0BAAW,CAAC,uBAAuB,CAAC,CAAC;QAChD,IAAI,QAAQ,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;YAClC,IAAI,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAmB,CAAC,CAAC;YAC7C,QAAQ,GAAG,KAAK,CAAC;QAClB,CAAC;IACF,CAAC;IACD,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAClC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAC5B,IAAI,CAAC,QAAQ;gBAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;IACF,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,GAAG,YAAY;QAAE,MAAM,IAAI,0BAAW,CAAC,qBAAqB,CAAC,CAAC;IAC3E,IAAI,QAAQ,IAAI,KAAK,CAAC,MAAM;QAAE,KAAK,CAAC,MAAM,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;IACzF,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IHttpRequestOptions } from 'n8n-workflow';
|
|
2
|
+
import type { Transport } from './LibrusClient';
|
|
3
|
+
export declare function createTransport(httpRequest: (options: IHttpRequestOptions) => Promise<unknown>): Transport;
|
|
4
|
+
export declare function createCredentialTestTransport(requestHelper: (options: object) => Promise<unknown>): Transport;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTransport = createTransport;
|
|
4
|
+
exports.createCredentialTestTransport = createCredentialTestTransport;
|
|
5
|
+
function createTransport(httpRequest) {
|
|
6
|
+
return async (request) => {
|
|
7
|
+
const response = await httpRequest({
|
|
8
|
+
...request,
|
|
9
|
+
disableFollowRedirect: true,
|
|
10
|
+
returnFullResponse: true,
|
|
11
|
+
ignoreHttpStatusErrors: true,
|
|
12
|
+
json: false,
|
|
13
|
+
encoding: 'text',
|
|
14
|
+
});
|
|
15
|
+
return response;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function createCredentialTestTransport(requestHelper) {
|
|
19
|
+
return async (request) => (await requestHelper({
|
|
20
|
+
uri: request.url,
|
|
21
|
+
method: request.method,
|
|
22
|
+
headers: request.headers,
|
|
23
|
+
body: request.body,
|
|
24
|
+
timeout: request.timeout,
|
|
25
|
+
followRedirect: false,
|
|
26
|
+
followAllRedirects: false,
|
|
27
|
+
resolveWithFullResponse: true,
|
|
28
|
+
simple: false,
|
|
29
|
+
json: false,
|
|
30
|
+
encoding: 'utf8',
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../nodes/Librus/transport.ts"],"names":[],"mappings":";;AAGA,0CAcC;AAGD,sEAiBC;AAlCD,SAAgB,eAAe,CAC9B,WAA+D;IAE/D,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC;YAClC,GAAG,OAAO;YACV,qBAAqB,EAAE,IAAI;YAC3B,kBAAkB,EAAE,IAAI;YACxB,sBAAsB,EAAE,IAAI;YAC5B,IAAI,EAAE,KAAK;YACX,QAAQ,EAAE,MAAM;SAChB,CAAC,CAAC;QACH,OAAO,QAAoB,CAAC;IAC7B,CAAC,CAAC;AACH,CAAC;AAGD,SAAgB,6BAA6B,CAC5C,aAAoD;IAEpD,OAAO,KAAK,EAAE,OAAO,EAAE,EAAE,CACxB,CAAC,MAAM,aAAa,CAAC;QACpB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,cAAc,EAAE,KAAK;QACrB,kBAAkB,EAAE,KAAK;QACzB,uBAAuB,EAAE,IAAI;QAC7B,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,KAAK;QACX,QAAQ,EAAE,MAAM;KAChB,CAAC,CAAa,CAAC;AAClB,CAAC"}
|