emailengine-app 2.81.1 → 2.82.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/.ncurc.js +12 -6
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +52 -0
- package/Dockerfile +4 -2
- package/bin/emailengine.js +28 -18
- package/config/default.toml +0 -5
- package/config/test.toml +0 -5
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +70 -42
- package/getswagger.sh +0 -4
- package/lib/account/account-state.js +2 -110
- package/lib/account/bounce-store-sweep.js +63 -0
- package/lib/account/expected-identity.js +1 -1
- package/lib/account-assignment.js +207 -0
- package/lib/account.js +374 -878
- package/lib/api-reference/index.js +2 -3
- package/lib/api-reference/schema-tree.js +53 -3
- package/lib/api-routes/account-routes.js +18 -29
- package/lib/api-routes/blocklist-routes.js +2 -2
- package/lib/api-routes/bull-board-routes.js +1 -6
- package/lib/api-routes/export-routes.js +2 -22
- package/lib/api-routes/gateway-routes.js +5 -14
- package/lib/api-routes/index.js +1 -13
- package/lib/api-routes/mailbox-routes.js +2 -7
- package/lib/api-routes/mcp-oauth-routes.js +2 -1
- package/lib/api-routes/mcp-routes.js +7 -7
- package/lib/api-routes/message-routes.js +44 -236
- package/lib/api-routes/mint-bounds.js +110 -0
- package/lib/api-routes/oauth2-app-routes.js +23 -32
- package/lib/api-routes/operation-impact.js +1 -1
- package/lib/api-routes/outbox-routes.js +2 -2
- package/lib/api-routes/permission-map.js +1 -7
- package/lib/api-routes/route-helpers.js +11 -5
- package/lib/api-routes/settings-routes.js +19 -19
- package/lib/api-routes/stats-routes.js +1 -1
- package/lib/api-routes/submit-routes.js +17 -18
- package/lib/api-routes/template-routes.js +4 -9
- package/lib/api-routes/token-routes.js +27 -5
- package/lib/api-token-scheme.js +71 -0
- package/lib/arf-detect.js +41 -7
- package/lib/auth-token.js +44 -24
- package/lib/autodetect-imap-settings.js +163 -123
- package/lib/bounce-detect.js +25 -16
- package/lib/calendar-event.js +78 -0
- package/lib/consts.js +51 -5
- package/lib/create-imap-client.js +24 -0
- package/lib/db.js +76 -17
- package/lib/delivery-error.js +2 -1
- package/lib/egress-fetch.js +54 -3
- package/lib/egress-filter.js +11 -0
- package/lib/email-client/api-retry.js +147 -0
- package/lib/email-client/base-client.js +628 -615
- package/lib/email-client/gmail/gmail-api.js +38 -125
- package/lib/email-client/gmail/send-request.js +1 -1
- package/lib/email-client/gmail-client.js +170 -84
- package/lib/email-client/imap/mailbox.js +244 -535
- package/lib/email-client/imap/stale-view.js +109 -0
- package/lib/email-client/imap/subconnection.js +46 -9
- package/lib/email-client/imap/sync-operations.js +5 -37
- package/lib/email-client/imap-client.js +188 -64
- package/lib/email-client/message-builder.js +9 -14
- package/lib/email-client/notification-handler.js +5 -219
- package/lib/email-client/outlook/graph-api.js +147 -126
- package/lib/email-client/outlook/send-request.js +10 -4
- package/lib/email-client/outlook-client.js +519 -617
- package/lib/email-client/smtp-pool-manager.js +3 -2
- package/lib/encrypt.js +184 -19
- package/lib/enum-descriptions.js +1 -2
- package/lib/export.js +144 -41
- package/lib/gateway.js +20 -6
- package/lib/get-raw-email.js +26 -44
- package/lib/handlebars-helpers.js +31 -10
- package/lib/imap-proxy-auth.js +13 -29
- package/lib/imapproxy/imap-core/README.md +1 -0
- package/lib/imapproxy/imap-core/lib/handler/imap-parser.js +12 -0
- package/lib/imapproxy/imap-core/lib/imap-command.js +74 -10
- package/lib/imapproxy/imap-core/lib/imap-connection.js +9 -1
- package/lib/imapproxy/imap-core/lib/imap-server.js +112 -26
- package/lib/imapproxy/imap-core/lib/imap-stream.js +41 -1
- package/lib/imapproxy/imap-core/lib/imap-tools.js +10 -2
- package/lib/imapproxy/imap-core/lib/indexer/indexer.js +4 -2
- package/lib/imapproxy/imap-server.js +17 -177
- package/lib/imapproxy/proxy-handoff.js +235 -0
- package/lib/imapproxy/response-error.js +33 -0
- package/lib/imapproxy/upstream-client.js +2 -2
- package/lib/license-beacon.js +3 -9
- package/lib/llm-pre-process.js +182 -43
- package/lib/logger.js +1 -1
- package/lib/lua/ee-export-queue-add.lua +39 -0
- package/lib/lua/ee-get-idempotency.lua +15 -3
- package/lib/lua/ee-release-attempts.lua +23 -0
- package/lib/lua/ee-reserve-attempts.lua +42 -0
- package/lib/lua/h-set-bigger.lua +12 -2
- package/lib/lua/s-list-accounts.lua +6 -3
- package/lib/mcp/index.js +1 -2
- package/lib/mcp/listen.js +221 -18
- package/lib/mcp/oauth.js +44 -5
- package/lib/mcp/resources.js +8 -2
- package/lib/mcp/tools.js +13 -0
- package/lib/message-port-stream.js +64 -6
- package/lib/msgpack.js +1 -6
- package/lib/oauth/external-account-signer.js +16 -13
- package/lib/oauth/gmail.js +22 -20
- package/lib/oauth/outlook.js +19 -16
- package/lib/oauth/pubsub/google.js +38 -2
- package/lib/oauth/scope-checker.js +4 -7
- package/lib/oauth/verify-app.js +2 -2
- package/lib/oauth2-apps.js +139 -44
- package/lib/openapi/build-document.js +1 -1
- package/lib/openapi/joi-schema.js +78 -9
- package/lib/parse-message.js +21 -0
- package/lib/payload-examples-webhooks.json +4 -7
- package/lib/pbkdf2-phc.js +101 -0
- package/lib/privileged-settings.js +0 -14
- package/lib/rate-limit.js +54 -15
- package/lib/redis-scan-delete.js +56 -29
- package/lib/redis-url.js +3 -1
- package/lib/respawn-backoff.js +5 -4
- package/lib/response-stream.js +25 -4
- package/lib/rewrite-text-nodes.js +27 -40
- package/lib/routes-ui.js +0 -5
- package/lib/schemas.js +129 -262
- package/lib/sentry.js +21 -5
- package/lib/settings.js +58 -59
- package/lib/smtp-auth.js +6 -2
- package/lib/smtp-message-processor.js +28 -7
- package/lib/sso.js +7 -3
- package/lib/stream-encrypt.js +14 -13
- package/lib/swagger-options.js +3 -1
- package/lib/tls/provision.js +69 -3
- package/lib/tls/store.js +14 -1
- package/lib/tools.js +113 -52
- package/lib/totp.js +16 -1
- package/lib/ui-routes/account-routes.js +27 -63
- package/lib/ui-routes/admin-config-routes.js +111 -134
- package/lib/ui-routes/admin-entities-routes.js +101 -191
- package/lib/ui-routes/ai-options.js +104 -0
- package/lib/ui-routes/auth-routes.js +98 -18
- package/lib/ui-routes/export-routes.js +3 -23
- package/lib/ui-routes/internals-routes.js +12 -9
- package/lib/ui-routes/network-config-routes.js +8 -18
- package/lib/ui-routes/oauth-config-routes.js +80 -214
- package/lib/ui-routes/route-helpers.js +40 -44
- package/lib/ui-routes/unsubscribe-routes.js +2 -2
- package/lib/utils/decode-headers.js +32 -5
- package/lib/utils/header-map.js +62 -1
- package/lib/utils/network.js +2 -0
- package/lib/web-safe-html.js +77 -4
- package/lib/webhook-request.js +9 -1
- package/lib/webhook-routing.js +27 -1
- package/lib/webhooks.js +120 -43
- package/lib/worker-rpc-error.js +43 -2
- package/list-generate.js +13 -2
- package/package.json +38 -46
- package/sbom.json +1 -1
- package/scripts/refresh-test-tokens.js +42 -14
- package/server.js +340 -336
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +7 -8
- package/static/js/ee-client.js +145 -70
- package/static/js/ui.js +350 -154
- package/static/licenses.html +460 -1861
- package/translations/messages.pot +99 -99
- package/views/accounts/browse.hbs +10 -4
- package/views/config/ai.hbs +49 -41
- package/views/config/oauth/app.hbs +2 -1
- package/views/dashboard.hbs +18 -16
- package/views/layout/app.hbs +0 -22
- package/views/layout/login.hbs +2 -1
- package/views/partials/filter_editor_js.hbs +4 -3
- package/views/partials/side_menu.hbs +0 -4
- package/views/partials/ui/account-picker.hbs +6 -32
- package/views/partials/ui/model-picker.hbs +31 -0
- package/views/partials/ui/pagination.hbs +6 -1
- package/views/partials/ui/picker.hbs +47 -0
- package/views/unsubscribe.hbs +1 -1
- package/workers/api.js +33 -23
- package/workers/export.js +55 -60
- package/workers/imap.js +134 -47
- package/workers/submit.js +3 -1
- package/workers/webhooks.js +46 -27
- package/.githooks/pre-commit +0 -80
- package/.github/CODE_OF_CONDUCT.md +0 -76
- package/.github/contributing.md +0 -17
- package/.github/dependabot.yml +0 -22
- package/.github/docker-smoke-test.sh +0 -61
- package/.github/workflows/deploy.yml +0 -215
- package/.github/workflows/e2e.yml +0 -55
- package/.github/workflows/release.yaml +0 -217
- package/.github/workflows/test.yml +0 -307
- package/lib/api-routes/chat-routes.js +0 -535
- package/lib/append-list.js +0 -63
- package/lib/document-store.js +0 -75
- package/lib/es.js +0 -757
- package/lib/generate-text-preview.js +0 -61
- package/lib/imapproxy/imap-core/memory-notifier.js +0 -129
- package/lib/lua/h-push.lua +0 -32
- package/lib/pre-process.js +0 -196
- package/lib/threads.js +0 -155
- package/lib/ui-routes/document-store-routes.js +0 -806
- package/playwright.config.js +0 -47
- package/views/config/document-store/chat.hbs +0 -286
- package/views/config/document-store/index.hbs +0 -146
- package/views/config/document-store/mappings/index.hbs +0 -108
- package/views/config/document-store/mappings/new.hbs +0 -68
- package/views/config/document-store/pre-processing/index.hbs +0 -103
- package/views/partials/document_store_header.hbs +0 -30
- package/workers/documents.js +0 -1128
package/lib/es.js
DELETED
|
@@ -1,757 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { redis } = require('./db');
|
|
4
|
-
const { REDIS_PREFIX } = require('./consts');
|
|
5
|
-
const assert = require('assert');
|
|
6
|
-
|
|
7
|
-
const analyzer = {
|
|
8
|
-
htmlStripAnalyzer: {
|
|
9
|
-
type: 'custom',
|
|
10
|
-
tokenizer: 'standard',
|
|
11
|
-
filter: ['lowercase'],
|
|
12
|
-
char_filter: ['html_strip']
|
|
13
|
-
},
|
|
14
|
-
filenameSearch: {
|
|
15
|
-
tokenizer: 'filename',
|
|
16
|
-
filter: ['lowercase']
|
|
17
|
-
},
|
|
18
|
-
filenameIndex: {
|
|
19
|
-
tokenizer: 'filename',
|
|
20
|
-
filter: ['lowercase', 'edgeNgram']
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const tokenizer = {
|
|
25
|
-
filename: {
|
|
26
|
-
pattern: '[^\\p{L}\\d]+',
|
|
27
|
-
type: 'pattern'
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const filter = {
|
|
32
|
-
edgeNgram: {
|
|
33
|
-
side: 'front',
|
|
34
|
-
max_gram: 20,
|
|
35
|
-
min_gram: 1,
|
|
36
|
-
type: 'edge_ngram'
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const mappings = {
|
|
41
|
-
account: {
|
|
42
|
-
type: 'keyword',
|
|
43
|
-
ignore_above: 256
|
|
44
|
-
},
|
|
45
|
-
answered: {
|
|
46
|
-
type: 'boolean'
|
|
47
|
-
},
|
|
48
|
-
attachments: {
|
|
49
|
-
type: 'nested',
|
|
50
|
-
properties: {
|
|
51
|
-
contentId: {
|
|
52
|
-
type: 'keyword',
|
|
53
|
-
ignore_above: 128
|
|
54
|
-
},
|
|
55
|
-
contentType: {
|
|
56
|
-
type: 'keyword',
|
|
57
|
-
ignore_above: 128
|
|
58
|
-
},
|
|
59
|
-
embedded: {
|
|
60
|
-
type: 'boolean'
|
|
61
|
-
},
|
|
62
|
-
encodedSize: {
|
|
63
|
-
type: 'long'
|
|
64
|
-
},
|
|
65
|
-
filename: {
|
|
66
|
-
type: 'text',
|
|
67
|
-
analyzer: 'filenameIndex',
|
|
68
|
-
search_analyzer: 'filenameSearch'
|
|
69
|
-
},
|
|
70
|
-
id: {
|
|
71
|
-
type: 'keyword',
|
|
72
|
-
ignore_above: 128
|
|
73
|
-
},
|
|
74
|
-
inline: {
|
|
75
|
-
type: 'boolean'
|
|
76
|
-
},
|
|
77
|
-
method: {
|
|
78
|
-
type: 'keyword',
|
|
79
|
-
ignore_above: 32
|
|
80
|
-
},
|
|
81
|
-
// optional base64 indexed file
|
|
82
|
-
content: {
|
|
83
|
-
type: 'text',
|
|
84
|
-
index: false
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
bcc: {
|
|
89
|
-
properties: {
|
|
90
|
-
address: {
|
|
91
|
-
type: 'keyword',
|
|
92
|
-
ignore_above: 256
|
|
93
|
-
},
|
|
94
|
-
name: {
|
|
95
|
-
type: 'text'
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
bounces: {
|
|
100
|
-
type: 'nested',
|
|
101
|
-
properties: {
|
|
102
|
-
action: {
|
|
103
|
-
type: 'keyword',
|
|
104
|
-
ignore_above: 128
|
|
105
|
-
},
|
|
106
|
-
date: {
|
|
107
|
-
type: 'date'
|
|
108
|
-
},
|
|
109
|
-
message: {
|
|
110
|
-
type: 'keyword',
|
|
111
|
-
ignore_above: 128
|
|
112
|
-
},
|
|
113
|
-
recipient: {
|
|
114
|
-
type: 'keyword',
|
|
115
|
-
ignore_above: 256
|
|
116
|
-
},
|
|
117
|
-
response: {
|
|
118
|
-
properties: {
|
|
119
|
-
source: {
|
|
120
|
-
type: 'keyword',
|
|
121
|
-
ignore_above: 128
|
|
122
|
-
},
|
|
123
|
-
message: {
|
|
124
|
-
type: 'text'
|
|
125
|
-
},
|
|
126
|
-
status: {
|
|
127
|
-
type: 'keyword',
|
|
128
|
-
ignore_above: 128
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
mta: {
|
|
133
|
-
type: 'keyword',
|
|
134
|
-
ignore_above: 256
|
|
135
|
-
},
|
|
136
|
-
queueId: {
|
|
137
|
-
type: 'keyword',
|
|
138
|
-
ignore_above: 256
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
cc: {
|
|
143
|
-
properties: {
|
|
144
|
-
address: {
|
|
145
|
-
type: 'keyword',
|
|
146
|
-
ignore_above: 256
|
|
147
|
-
},
|
|
148
|
-
name: {
|
|
149
|
-
type: 'text'
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
created: {
|
|
154
|
-
type: 'date'
|
|
155
|
-
},
|
|
156
|
-
date: {
|
|
157
|
-
type: 'date'
|
|
158
|
-
},
|
|
159
|
-
draft: {
|
|
160
|
-
type: 'boolean'
|
|
161
|
-
},
|
|
162
|
-
emailId: {
|
|
163
|
-
type: 'keyword',
|
|
164
|
-
ignore_above: 128
|
|
165
|
-
},
|
|
166
|
-
flagged: {
|
|
167
|
-
type: 'boolean'
|
|
168
|
-
},
|
|
169
|
-
flags: {
|
|
170
|
-
type: 'keyword',
|
|
171
|
-
ignore_above: 128
|
|
172
|
-
},
|
|
173
|
-
updateTime: {
|
|
174
|
-
type: 'long'
|
|
175
|
-
},
|
|
176
|
-
from: {
|
|
177
|
-
properties: {
|
|
178
|
-
address: {
|
|
179
|
-
type: 'keyword',
|
|
180
|
-
ignore_above: 256
|
|
181
|
-
},
|
|
182
|
-
name: {
|
|
183
|
-
type: 'text'
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
headers: {
|
|
188
|
-
type: 'nested',
|
|
189
|
-
properties: {
|
|
190
|
-
key: {
|
|
191
|
-
type: 'keyword',
|
|
192
|
-
ignore_above: 256
|
|
193
|
-
},
|
|
194
|
-
value: {
|
|
195
|
-
type: 'text'
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
},
|
|
199
|
-
id: {
|
|
200
|
-
type: 'keyword',
|
|
201
|
-
ignore_above: 128
|
|
202
|
-
},
|
|
203
|
-
inReplyTo: {
|
|
204
|
-
type: 'keyword',
|
|
205
|
-
ignore_above: 998
|
|
206
|
-
},
|
|
207
|
-
isAutoReply: {
|
|
208
|
-
type: 'boolean'
|
|
209
|
-
},
|
|
210
|
-
isBounce: {
|
|
211
|
-
type: 'boolean'
|
|
212
|
-
},
|
|
213
|
-
labels: {
|
|
214
|
-
type: 'keyword',
|
|
215
|
-
ignore_above: 998
|
|
216
|
-
},
|
|
217
|
-
messageId: {
|
|
218
|
-
type: 'keyword',
|
|
219
|
-
ignore_above: 998
|
|
220
|
-
},
|
|
221
|
-
relatedMessageId: {
|
|
222
|
-
type: 'keyword',
|
|
223
|
-
ignore_above: 998
|
|
224
|
-
},
|
|
225
|
-
path: {
|
|
226
|
-
type: 'keyword',
|
|
227
|
-
ignore_above: 998
|
|
228
|
-
},
|
|
229
|
-
replyTo: {
|
|
230
|
-
properties: {
|
|
231
|
-
address: {
|
|
232
|
-
type: 'keyword',
|
|
233
|
-
ignore_above: 256
|
|
234
|
-
},
|
|
235
|
-
name: {
|
|
236
|
-
type: 'text'
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
seemsLikeNew: {
|
|
241
|
-
type: 'boolean'
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
messageSpecialUse: {
|
|
245
|
-
type: 'keyword',
|
|
246
|
-
ignore_above: 128
|
|
247
|
-
},
|
|
248
|
-
|
|
249
|
-
summary: {
|
|
250
|
-
properties: {
|
|
251
|
-
id: {
|
|
252
|
-
type: 'keyword',
|
|
253
|
-
ignore_above: 256
|
|
254
|
-
},
|
|
255
|
-
tokens: {
|
|
256
|
-
type: 'integer'
|
|
257
|
-
},
|
|
258
|
-
sentiment: {
|
|
259
|
-
type: 'keyword',
|
|
260
|
-
ignore_above: 256
|
|
261
|
-
},
|
|
262
|
-
summary: {
|
|
263
|
-
type: 'text'
|
|
264
|
-
},
|
|
265
|
-
shouldReply: {
|
|
266
|
-
type: 'boolean'
|
|
267
|
-
},
|
|
268
|
-
replyText: {
|
|
269
|
-
type: 'text'
|
|
270
|
-
},
|
|
271
|
-
events: {
|
|
272
|
-
properties: {
|
|
273
|
-
description: {
|
|
274
|
-
type: 'text'
|
|
275
|
-
},
|
|
276
|
-
location: {
|
|
277
|
-
type: 'text'
|
|
278
|
-
},
|
|
279
|
-
// NB! these dates are ambiguous so treat as regular string values
|
|
280
|
-
startTime: {
|
|
281
|
-
type: 'keyword',
|
|
282
|
-
ignore_above: 128
|
|
283
|
-
},
|
|
284
|
-
endTime: {
|
|
285
|
-
type: 'keyword',
|
|
286
|
-
ignore_above: 128
|
|
287
|
-
},
|
|
288
|
-
type: {
|
|
289
|
-
type: 'keyword',
|
|
290
|
-
ignore_above: 128
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
actions: {
|
|
295
|
-
properties: {
|
|
296
|
-
description: {
|
|
297
|
-
type: 'text'
|
|
298
|
-
},
|
|
299
|
-
// NB! these dates are ambiguous so treat as regular string values
|
|
300
|
-
dueTime: {
|
|
301
|
-
type: 'keyword',
|
|
302
|
-
ignore_above: 128
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
},
|
|
308
|
-
|
|
309
|
-
riskAssessment: {
|
|
310
|
-
properties: {
|
|
311
|
-
id: {
|
|
312
|
-
type: 'keyword',
|
|
313
|
-
ignore_above: 256
|
|
314
|
-
},
|
|
315
|
-
tokens: {
|
|
316
|
-
type: 'integer'
|
|
317
|
-
},
|
|
318
|
-
risk: {
|
|
319
|
-
type: 'integer'
|
|
320
|
-
},
|
|
321
|
-
assessment: {
|
|
322
|
-
type: 'text'
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
},
|
|
326
|
-
|
|
327
|
-
category: {
|
|
328
|
-
type: 'keyword',
|
|
329
|
-
ignore_above: 128
|
|
330
|
-
},
|
|
331
|
-
|
|
332
|
-
calendarEvents: {
|
|
333
|
-
properties: {
|
|
334
|
-
eventId: {
|
|
335
|
-
type: 'keyword',
|
|
336
|
-
ignore_above: 256
|
|
337
|
-
},
|
|
338
|
-
attachment: {
|
|
339
|
-
type: 'keyword',
|
|
340
|
-
ignore_above: 256
|
|
341
|
-
},
|
|
342
|
-
method: {
|
|
343
|
-
type: 'keyword',
|
|
344
|
-
ignore_above: 32
|
|
345
|
-
},
|
|
346
|
-
summary: {
|
|
347
|
-
type: 'text'
|
|
348
|
-
},
|
|
349
|
-
description: {
|
|
350
|
-
type: 'text'
|
|
351
|
-
},
|
|
352
|
-
timezone: {
|
|
353
|
-
type: 'keyword',
|
|
354
|
-
ignore_above: 64
|
|
355
|
-
},
|
|
356
|
-
startDate: {
|
|
357
|
-
type: 'date'
|
|
358
|
-
},
|
|
359
|
-
endDate: {
|
|
360
|
-
type: 'date'
|
|
361
|
-
},
|
|
362
|
-
organizer: {
|
|
363
|
-
type: 'keyword',
|
|
364
|
-
ignore_above: 256
|
|
365
|
-
},
|
|
366
|
-
|
|
367
|
-
filename: {
|
|
368
|
-
type: 'text',
|
|
369
|
-
analyzer: 'filenameIndex',
|
|
370
|
-
search_analyzer: 'filenameSearch'
|
|
371
|
-
},
|
|
372
|
-
contentType: {
|
|
373
|
-
type: 'keyword',
|
|
374
|
-
ignore_above: 128
|
|
375
|
-
},
|
|
376
|
-
encoding: {
|
|
377
|
-
type: 'keyword',
|
|
378
|
-
ignore_above: 128
|
|
379
|
-
},
|
|
380
|
-
// optional base64 indexed file
|
|
381
|
-
content: {
|
|
382
|
-
type: 'text',
|
|
383
|
-
index: false
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
},
|
|
387
|
-
|
|
388
|
-
sender: {
|
|
389
|
-
properties: {
|
|
390
|
-
address: {
|
|
391
|
-
type: 'keyword',
|
|
392
|
-
ignore_above: 256
|
|
393
|
-
},
|
|
394
|
-
name: {
|
|
395
|
-
type: 'text'
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
},
|
|
399
|
-
size: {
|
|
400
|
-
type: 'long'
|
|
401
|
-
},
|
|
402
|
-
specialUse: {
|
|
403
|
-
type: 'keyword',
|
|
404
|
-
ignore_above: 64
|
|
405
|
-
},
|
|
406
|
-
subject: {
|
|
407
|
-
type: 'text'
|
|
408
|
-
},
|
|
409
|
-
|
|
410
|
-
preview: {
|
|
411
|
-
type: 'text',
|
|
412
|
-
index: false
|
|
413
|
-
},
|
|
414
|
-
|
|
415
|
-
text: {
|
|
416
|
-
properties: {
|
|
417
|
-
id: {
|
|
418
|
-
type: 'keyword',
|
|
419
|
-
ignore_above: 128
|
|
420
|
-
},
|
|
421
|
-
html: {
|
|
422
|
-
type: 'text',
|
|
423
|
-
analyzer: 'htmlStripAnalyzer'
|
|
424
|
-
},
|
|
425
|
-
plain: {
|
|
426
|
-
type: 'text'
|
|
427
|
-
},
|
|
428
|
-
encodedSize: {
|
|
429
|
-
properties: {
|
|
430
|
-
html: {
|
|
431
|
-
type: 'integer'
|
|
432
|
-
},
|
|
433
|
-
plain: {
|
|
434
|
-
type: 'integer'
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
},
|
|
438
|
-
_generatedHtml: {
|
|
439
|
-
type: 'text',
|
|
440
|
-
index: false
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
},
|
|
444
|
-
thread: {
|
|
445
|
-
type: 'keyword',
|
|
446
|
-
ignore_above: 128
|
|
447
|
-
},
|
|
448
|
-
threadId: {
|
|
449
|
-
type: 'keyword',
|
|
450
|
-
ignore_above: 128
|
|
451
|
-
},
|
|
452
|
-
to: {
|
|
453
|
-
properties: {
|
|
454
|
-
name: {
|
|
455
|
-
type: 'text'
|
|
456
|
-
},
|
|
457
|
-
address: {
|
|
458
|
-
type: 'keyword',
|
|
459
|
-
ignore_above: 256
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
},
|
|
463
|
-
uid: {
|
|
464
|
-
type: 'long'
|
|
465
|
-
},
|
|
466
|
-
unseen: {
|
|
467
|
-
type: 'boolean'
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
const threadMappings = {
|
|
472
|
-
account: {
|
|
473
|
-
type: 'keyword',
|
|
474
|
-
ignore_above: 256
|
|
475
|
-
},
|
|
476
|
-
subject: {
|
|
477
|
-
type: 'keyword',
|
|
478
|
-
ignore_above: 256
|
|
479
|
-
},
|
|
480
|
-
references: {
|
|
481
|
-
type: 'keyword',
|
|
482
|
-
ignore_above: 256
|
|
483
|
-
},
|
|
484
|
-
created: {
|
|
485
|
-
type: 'date'
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
const threadPolicy = {
|
|
490
|
-
phases: {
|
|
491
|
-
hot: {
|
|
492
|
-
actions: {
|
|
493
|
-
rollover: {
|
|
494
|
-
max_primary_shard_size: '50GB',
|
|
495
|
-
max_age: '30d'
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
},
|
|
499
|
-
delete: {
|
|
500
|
-
min_age: '90d',
|
|
501
|
-
actions: {
|
|
502
|
-
delete: {}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
const threadTemplateSettings = {
|
|
509
|
-
number_of_shards: 1,
|
|
510
|
-
number_of_replicas: 1
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
const embeddingsMappings = {
|
|
514
|
-
account: {
|
|
515
|
-
type: 'keyword',
|
|
516
|
-
ignore_above: 256
|
|
517
|
-
},
|
|
518
|
-
messageId: {
|
|
519
|
-
type: 'keyword',
|
|
520
|
-
ignore_above: 998
|
|
521
|
-
},
|
|
522
|
-
embeddings: {
|
|
523
|
-
type: 'dense_vector',
|
|
524
|
-
dims: 1536,
|
|
525
|
-
index: true,
|
|
526
|
-
similarity: 'cosine'
|
|
527
|
-
},
|
|
528
|
-
model: {
|
|
529
|
-
type: 'keyword',
|
|
530
|
-
ignore_above: 128
|
|
531
|
-
},
|
|
532
|
-
chunk: {
|
|
533
|
-
type: 'text',
|
|
534
|
-
index: false
|
|
535
|
-
},
|
|
536
|
-
chunkNr: {
|
|
537
|
-
type: 'integer'
|
|
538
|
-
},
|
|
539
|
-
chunks: {
|
|
540
|
-
type: 'integer'
|
|
541
|
-
},
|
|
542
|
-
date: {
|
|
543
|
-
type: 'date'
|
|
544
|
-
},
|
|
545
|
-
created: {
|
|
546
|
-
type: 'date'
|
|
547
|
-
}
|
|
548
|
-
};
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Function to either create or update an index to match the definition
|
|
552
|
-
* @param {Object} client ElasticSearch client object
|
|
553
|
-
* @param {String} index Index name
|
|
554
|
-
*/
|
|
555
|
-
const ensureIndex = async (client, index, opts) => {
|
|
556
|
-
const { mappings, analyzer, tokenizer, filter, aliases } = opts;
|
|
557
|
-
|
|
558
|
-
let indexExists = await client.indices.exists({ index });
|
|
559
|
-
|
|
560
|
-
if (!indexExists) {
|
|
561
|
-
// create new
|
|
562
|
-
|
|
563
|
-
let indexOpts = {
|
|
564
|
-
index,
|
|
565
|
-
mappings: { properties: mappings }
|
|
566
|
-
};
|
|
567
|
-
|
|
568
|
-
if (analyzer || tokenizer || filter) {
|
|
569
|
-
indexOpts.settings = {
|
|
570
|
-
analysis: {
|
|
571
|
-
analyzer,
|
|
572
|
-
tokenizer,
|
|
573
|
-
filter
|
|
574
|
-
}
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
if (aliases) {
|
|
579
|
-
indexOpts.aliases = aliases;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
let createResult = await client.indices.create(indexOpts);
|
|
583
|
-
assert(createResult && createResult.acknowledged);
|
|
584
|
-
return { created: true };
|
|
585
|
-
} else {
|
|
586
|
-
let indexData = await client.indices.get({ index });
|
|
587
|
-
if (!indexData || !indexData[index]) {
|
|
588
|
-
throw new Error('Missing index data');
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
let changes = {};
|
|
592
|
-
|
|
593
|
-
if (analyzer || tokenizer || filter) {
|
|
594
|
-
// compare settings and update if needed
|
|
595
|
-
let analysisData = (indexData[index].settings && indexData[index].settings.index && indexData[index].settings.index.analysis) || {};
|
|
596
|
-
let missingAnalyzers = {};
|
|
597
|
-
for (let key of Object.keys(analyzer || {})) {
|
|
598
|
-
if (!analysisData.analyzer || !analysisData.analyzer[key]) {
|
|
599
|
-
missingAnalyzers[key] = analyzer[key];
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
// found missing analyzers, update settings
|
|
604
|
-
if (Object.keys(missingAnalyzers).length) {
|
|
605
|
-
// index needs to be closed when changing analyser settings
|
|
606
|
-
let closeResult = await client.indices.close({ index });
|
|
607
|
-
assert(closeResult && closeResult.acknowledged);
|
|
608
|
-
try {
|
|
609
|
-
let updateResult = await client.indices.putSettings({
|
|
610
|
-
index,
|
|
611
|
-
settings: {
|
|
612
|
-
analysis: {
|
|
613
|
-
analyzer,
|
|
614
|
-
tokenizer,
|
|
615
|
-
filter
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
});
|
|
619
|
-
assert(updateResult && updateResult.acknowledged);
|
|
620
|
-
changes.analyzers = true;
|
|
621
|
-
} finally {
|
|
622
|
-
// try to open even if update failed
|
|
623
|
-
let openResult = await client.indices.open({ index });
|
|
624
|
-
assert(openResult && openResult.acknowledged);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
// Compare mappings and add missing
|
|
630
|
-
let storedMappings = (indexData[index].mappings && indexData[index].mappings.properties) || {};
|
|
631
|
-
let missingMappings = {};
|
|
632
|
-
for (let key of Object.keys(mappings)) {
|
|
633
|
-
if (!storedMappings[key]) {
|
|
634
|
-
missingMappings[key] = mappings[key];
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
// add missing mappings if needed
|
|
639
|
-
if (Object.keys(missingMappings).length) {
|
|
640
|
-
try {
|
|
641
|
-
const updateRes = await client.indices.putMapping({ index, properties: missingMappings });
|
|
642
|
-
assert(updateRes && updateRes.acknowledged);
|
|
643
|
-
changes.mappings = true;
|
|
644
|
-
} catch (err) {
|
|
645
|
-
// other than that update everything succeeded, so ignore for now
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if (!Object.keys(changes).length) {
|
|
650
|
-
return { exists: true };
|
|
651
|
-
} else {
|
|
652
|
-
return { updated: true, changes };
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
async function ensureThreadIndex(client, index) {
|
|
658
|
-
// Separate ILM index for threading
|
|
659
|
-
const policyName = `${index}.threads.policy`;
|
|
660
|
-
const templateName = `${index}.threads.template`;
|
|
661
|
-
const patternName = `${index}.threads`;
|
|
662
|
-
|
|
663
|
-
let policyRes;
|
|
664
|
-
try {
|
|
665
|
-
policyRes = await client.ilm.getLifecycle({
|
|
666
|
-
name: policyName
|
|
667
|
-
});
|
|
668
|
-
} catch (err) {
|
|
669
|
-
if (err.meta && err.meta.body && err.meta.body.status === 404) {
|
|
670
|
-
// policy not found
|
|
671
|
-
} else {
|
|
672
|
-
throw err;
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
if (!policyRes) {
|
|
677
|
-
let createPolicyRes = await client.ilm.putLifecycle({
|
|
678
|
-
name: policyName,
|
|
679
|
-
policy: threadPolicy
|
|
680
|
-
});
|
|
681
|
-
assert(createPolicyRes && createPolicyRes.acknowledged);
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
let existsTemplateRes = await client.indices.existsIndexTemplate({
|
|
685
|
-
name: templateName
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
if (!existsTemplateRes) {
|
|
689
|
-
let putTemplateRes = await client.indices.putIndexTemplate({
|
|
690
|
-
name: templateName,
|
|
691
|
-
index_patterns: [`${patternName}-*`],
|
|
692
|
-
template: {
|
|
693
|
-
settings: Object.assign(
|
|
694
|
-
{
|
|
695
|
-
'index.lifecycle.name': policyName,
|
|
696
|
-
'index.lifecycle.rollover_alias': patternName
|
|
697
|
-
},
|
|
698
|
-
threadTemplateSettings
|
|
699
|
-
),
|
|
700
|
-
mappings: {
|
|
701
|
-
_source: {
|
|
702
|
-
enabled: true
|
|
703
|
-
},
|
|
704
|
-
properties: threadMappings
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
});
|
|
708
|
-
assert(putTemplateRes && putTemplateRes.acknowledged);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
let aliasExists = await client.indices.existsAlias({ name: patternName });
|
|
712
|
-
if (!aliasExists) {
|
|
713
|
-
await ensureIndex(client, `${patternName}-000001`, {
|
|
714
|
-
mappings: threadMappings,
|
|
715
|
-
aliases: {
|
|
716
|
-
[patternName]: {
|
|
717
|
-
is_write_index: true
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
module.exports = {
|
|
725
|
-
async ensureIndex(client, index) {
|
|
726
|
-
let localMappings = structuredClone(mappings);
|
|
727
|
-
|
|
728
|
-
let customMappings = (await redis.hgetall(`${REDIS_PREFIX}mappings`)) || {};
|
|
729
|
-
for (let key of Object.keys(customMappings)) {
|
|
730
|
-
try {
|
|
731
|
-
let entry = JSON.parse(customMappings[key]);
|
|
732
|
-
localMappings[key] = localMappings[key] || entry;
|
|
733
|
-
} catch (err) {
|
|
734
|
-
// ignore?
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
let indexResult = await ensureIndex(client, index, { mappings: localMappings, analyzer, tokenizer, filter });
|
|
739
|
-
|
|
740
|
-
await ensureThreadIndex(client, index);
|
|
741
|
-
|
|
742
|
-
try {
|
|
743
|
-
// try to create vector index, might fail with older ES versions (<8.8)
|
|
744
|
-
let embeddingsIndexResult = await ensureIndex(client, `${index}.embeddings`, { mappings: embeddingsMappings });
|
|
745
|
-
if (embeddingsIndexResult) {
|
|
746
|
-
await redis.hset(`${REDIS_PREFIX}settings`, `embeddings:index`, JSON.stringify({ updated: Date.now() }));
|
|
747
|
-
}
|
|
748
|
-
} catch (err) {
|
|
749
|
-
await redis.hset(`${REDIS_PREFIX}settings`, `embeddings:index`, JSON.stringify({ error: err.message }));
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
return indexResult;
|
|
753
|
-
},
|
|
754
|
-
|
|
755
|
-
// immutable copy
|
|
756
|
-
defaultMappings: Object.freeze(structuredClone(mappings))
|
|
757
|
-
};
|