@remit/backend 0.0.142 → 0.0.144
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/dist/dev-server/content-handler.d.ts +38 -0
- package/dist/dev-server/content-handler.js +46 -0
- package/dist/src/api.d.ts +7 -0
- package/dist/src/api.js +144 -0
- package/dist/src/auth.d.ts +30 -0
- package/dist/src/auth.js +73 -0
- package/dist/src/config/msoauth.d.ts +30 -0
- package/dist/src/config/msoauth.js +30 -0
- package/{src/data-backend.ts → dist/src/data-backend.d.ts} +2 -4
- package/dist/src/data-backend.js +12 -0
- package/{src/derive/autoMoved.ts → dist/src/derive/autoMoved.d.ts} +1 -29
- package/dist/src/derive/autoMoved.js +49 -0
- package/dist/src/derive/contentSignature.d.ts +41 -0
- package/{src/derive/contentSignature.ts → dist/src/derive/contentSignature.js} +27 -72
- package/dist/src/derive/contentUrl.d.ts +46 -0
- package/dist/src/derive/contentUrl.js +46 -0
- package/{src/derive/deriveMuted.ts → dist/src/derive/deriveMuted.d.ts} +1 -3
- package/dist/src/derive/deriveMuted.js +7 -0
- package/dist/src/derive/enrichThreadRows.d.ts +118 -0
- package/dist/src/derive/enrichThreadRows.js +151 -0
- package/dist/src/derive/filterThreadCriteria.d.ts +23 -0
- package/dist/src/derive/filterThreadCriteria.js +24 -0
- package/{src/derive/pendingMoveCounts.ts → dist/src/derive/pendingMoveCounts.d.ts} +5 -53
- package/dist/src/derive/pendingMoveCounts.js +53 -0
- package/{src/derive/senderTrust.ts → dist/src/derive/senderTrust.d.ts} +1 -9
- package/dist/src/derive/senderTrust.js +19 -0
- package/dist/src/error.d.ts +21 -0
- package/dist/src/error.js +85 -0
- package/dist/src/handlers/account-guards.d.ts +36 -0
- package/dist/src/handlers/account-guards.js +107 -0
- package/dist/src/handlers/account-oauth.d.ts +14 -0
- package/dist/src/handlers/account-oauth.js +387 -0
- package/dist/src/handlers/account-overrides.d.ts +53 -0
- package/dist/src/handlers/account-overrides.js +233 -0
- package/dist/src/handlers/account-signature.d.ts +28 -0
- package/dist/src/handlers/account-signature.js +85 -0
- package/dist/src/handlers/account.d.ts +6 -0
- package/dist/src/handlers/account.js +350 -0
- package/dist/src/handlers/address.d.ts +35 -0
- package/dist/src/handlers/address.js +141 -0
- package/dist/src/handlers/calendar-event.d.ts +70 -0
- package/dist/src/handlers/calendar-event.js +425 -0
- package/dist/src/handlers/calendar-feed.d.ts +47 -0
- package/dist/src/handlers/calendar-feed.js +192 -0
- package/dist/src/handlers/calendar-suggestion.d.ts +47 -0
- package/dist/src/handlers/calendar-suggestion.js +212 -0
- package/dist/src/handlers/calendar.d.ts +116 -0
- package/dist/src/handlers/calendar.js +330 -0
- package/dist/src/handlers/config.d.ts +43 -0
- package/dist/src/handlers/config.js +176 -0
- package/dist/src/handlers/ensure-account-config.d.ts +9 -0
- package/dist/src/handlers/ensure-account-config.js +27 -0
- package/dist/src/handlers/filter.d.ts +3 -0
- package/dist/src/handlers/filter.js +103 -0
- package/dist/src/handlers/folder-role-appointments.d.ts +68 -0
- package/dist/src/handlers/folder-role-appointments.js +168 -0
- package/dist/src/handlers/folder-role-labels.d.ts +26 -0
- package/dist/src/handlers/folder-role-labels.js +40 -0
- package/dist/src/handlers/folder-role.d.ts +9 -0
- package/dist/src/handlers/folder-role.js +40 -0
- package/dist/src/handlers/index.d.ts +2 -0
- package/dist/src/handlers/index.js +60 -0
- package/dist/src/handlers/label.d.ts +43 -0
- package/dist/src/handlers/label.js +114 -0
- package/dist/src/handlers/mailbox-bindings.d.ts +41 -0
- package/dist/src/handlers/mailbox-bindings.js +61 -0
- package/dist/src/handlers/mailbox.d.ts +23 -0
- package/dist/src/handlers/mailbox.js +219 -0
- package/dist/src/handlers/me.d.ts +2 -0
- package/dist/src/handlers/me.js +138 -0
- package/dist/src/handlers/message.d.ts +84 -0
- package/dist/src/handlers/message.js +607 -0
- package/dist/src/handlers/organize.d.ts +10 -0
- package/dist/src/handlers/organize.js +112 -0
- package/dist/src/handlers/outbox-attachment.d.ts +23 -0
- package/dist/src/handlers/outbox-attachment.js +81 -0
- package/dist/src/handlers/outbox.d.ts +4 -0
- package/dist/src/handlers/outbox.js +144 -0
- package/dist/src/handlers/sync-progress.d.ts +46 -0
- package/dist/src/handlers/sync-progress.js +63 -0
- package/dist/src/handlers/sync.d.ts +28 -0
- package/dist/src/handlers/sync.js +82 -0
- package/dist/src/handlers/system-update.d.ts +2 -0
- package/dist/src/handlers/system-update.js +172 -0
- package/dist/src/handlers/thread.d.ts +148 -0
- package/dist/src/handlers/thread.js +233 -0
- package/dist/src/handlers/unified-threads.d.ts +247 -0
- package/dist/src/handlers/unified-threads.js +409 -0
- package/{src/handlers/vip-suggestions.ts → dist/src/handlers/vip-suggestions.d.ts} +1 -13
- package/dist/src/handlers/vip-suggestions.js +16 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +37 -0
- package/{src/json.ts → dist/src/json.d.ts} +1 -4
- package/dist/src/json.js +10 -0
- package/dist/src/jwt-auth.d.ts +18 -0
- package/dist/src/jwt-auth.js +97 -0
- package/dist/src/request-context.d.ts +9 -0
- package/dist/src/request-context.js +22 -0
- package/dist/src/request.d.ts +3 -0
- package/dist/src/request.js +7 -0
- package/dist/src/response.d.ts +27 -0
- package/dist/src/response.js +87 -0
- package/dist/src/service/account-deletion.d.ts +22 -0
- package/dist/src/service/account-deletion.js +39 -0
- package/dist/src/service/compose-sqlite.d.ts +2 -0
- package/dist/src/service/compose-sqlite.js +11 -0
- package/dist/src/service/create-remit-client.d.ts +95 -0
- package/dist/src/service/create-remit-client.js +207 -0
- package/dist/src/service/data-client.d.ts +12 -0
- package/dist/src/service/data-client.js +44 -0
- package/dist/src/service/export-identity.d.ts +3 -0
- package/dist/src/service/export-identity.js +35 -0
- package/dist/src/service/fire-and-forget.d.ts +54 -0
- package/dist/src/service/fire-and-forget.js +38 -0
- package/dist/src/service/organize.d.ts +184 -0
- package/dist/src/service/organize.js +384 -0
- package/dist/src/service/refusal.d.ts +4 -0
- package/dist/src/service/refusal.js +20 -0
- package/dist/src/service/sender-category.d.ts +51 -0
- package/{src/service/sender-category.ts → dist/src/service/sender-category.js} +40 -81
- package/dist/src/service/sqs.d.ts +1 -0
- package/{src/service/sqs.ts → dist/src/service/sqs.js} +0 -1
- package/dist/src/service/trigger-sync.d.ts +51 -0
- package/dist/src/service/trigger-sync.js +39 -0
- package/dist/src/types.d.ts +49 -0
- package/dist/src/types.js +1 -0
- package/package.json +113 -98
- package/.env.test +0 -4
- package/dev-server/content-auth.test.ts +0 -113
- package/dev-server/content-auth.ts +0 -54
- package/dev-server/content-handler.test.ts +0 -105
- package/dev-server/content-handler.ts +0 -79
- package/dev-server/content-path.test.ts +0 -37
- package/dev-server/content-path.ts +0 -27
- package/dev-server/cors.test.ts +0 -48
- package/dev-server/cors.ts +0 -25
- package/dev-server/keep-alive.test.ts +0 -24
- package/dev-server/lambda-helpers.ts +0 -69
- package/dev-server/log-output.test.ts +0 -173
- package/dev-server/oauth-callback-route.test.ts +0 -66
- package/dev-server/relational-health.test.ts +0 -83
- package/dev-server/relational-health.ts +0 -39
- package/dev-server/server.ts +0 -384
- package/dev-server/sync-age.test.ts +0 -91
- package/dev-server/sync-age.ts +0 -55
- package/dev-server/upload-handler.ts +0 -132
- package/dev-server/upload-route.test.ts +0 -196
- package/scripts/backfill-classification.ts +0 -91
- package/scripts/backfill-list-id.ts +0 -83
- package/scripts/config-save.ts +0 -128
- package/src/auth.test.ts +0 -12
- package/src/auth.ts +0 -92
- package/src/config/msoauth.test.ts +0 -48
- package/src/config/msoauth.ts +0 -48
- package/src/data-backend.test.ts +0 -23
- package/src/derive/autoMoved.test.ts +0 -104
- package/src/derive/contentSignature.test.ts +0 -161
- package/src/derive/contentUrl.test.ts +0 -172
- package/src/derive/contentUrl.ts +0 -86
- package/src/derive/deriveMuted.test.ts +0 -34
- package/src/derive/enrichThreadRows.test.ts +0 -360
- package/src/derive/enrichThreadRows.ts +0 -234
- package/src/derive/filterThreadCriteria.test.ts +0 -126
- package/src/derive/filterThreadCriteria.ts +0 -51
- package/src/derive/senderTrust.test.ts +0 -67
- package/src/error.test.ts +0 -201
- package/src/error.ts +0 -123
- package/src/handlers/account-guards.test.ts +0 -67
- package/src/handlers/account-guards.ts +0 -169
- package/src/handlers/account-oauth-callback.test.ts +0 -155
- package/src/handlers/account-oauth-consent.test.ts +0 -336
- package/src/handlers/account-oauth-start.test.ts +0 -191
- package/src/handlers/account-oauth.test.ts +0 -439
- package/src/handlers/account-oauth.ts +0 -635
- package/src/handlers/account-overrides.test.ts +0 -88
- package/src/handlers/account-overrides.ts +0 -323
- package/src/handlers/account-ownership.ts +0 -25
- package/src/handlers/account-signature.ts +0 -117
- package/src/handlers/account-synced-services.test.ts +0 -245
- package/src/handlers/account.ts +0 -552
- package/src/handlers/address.test.ts +0 -381
- package/src/handlers/address.ts +0 -200
- package/src/handlers/calendar-event.test.ts +0 -685
- package/src/handlers/calendar-event.ts +0 -738
- package/src/handlers/calendar-feed-validators.test.ts +0 -228
- package/src/handlers/calendar-feed.test.ts +0 -439
- package/src/handlers/calendar-feed.ts +0 -291
- package/src/handlers/calendar-sqlite-fixture.ts +0 -36
- package/src/handlers/calendar-suggestion.test.ts +0 -1269
- package/src/handlers/calendar-suggestion.ts +0 -425
- package/src/handlers/calendar.test.ts +0 -1080
- package/src/handlers/calendar.ts +0 -517
- package/src/handlers/config.test.ts +0 -245
- package/src/handlers/config.ts +0 -332
- package/src/handlers/ensure-account-config.ts +0 -30
- package/src/handlers/filter.test.ts +0 -644
- package/src/handlers/filter.ts +0 -518
- package/src/handlers/folder-role-appointments.test.ts +0 -438
- package/src/handlers/folder-role-appointments.ts +0 -249
- package/src/handlers/folder-role-labels.ts +0 -63
- package/src/handlers/folder-role.test.ts +0 -209
- package/src/handlers/folder-role.ts +0 -80
- package/src/handlers/index.ts +0 -83
- package/src/handlers/label.test.ts +0 -112
- package/src/handlers/label.ts +0 -210
- package/src/handlers/mailbox-bindings.ts +0 -111
- package/src/handlers/mailbox-rename-refusal.test.ts +0 -247
- package/src/handlers/mailbox-settled-target.test.ts +0 -251
- package/src/handlers/mailbox.test.ts +0 -280
- package/src/handlers/mailbox.ts +0 -581
- package/src/handlers/me.test.ts +0 -81
- package/src/handlers/me.ts +0 -203
- package/src/handlers/message-read-backfill.test.ts +0 -103
- package/src/handlers/message.test.ts +0 -131
- package/src/handlers/message.ts +0 -1131
- package/src/handlers/organize.test.ts +0 -277
- package/src/handlers/organize.ts +0 -197
- package/src/handlers/outbox-attachment.test.ts +0 -765
- package/src/handlers/outbox-attachment.ts +0 -126
- package/src/handlers/outbox-list.test.ts +0 -179
- package/src/handlers/outbox.test.ts +0 -772
- package/src/handlers/outbox.ts +0 -258
- package/src/handlers/search.test.ts +0 -161
- package/src/handlers/search.ts +0 -105
- package/src/handlers/sync-progress.test.ts +0 -205
- package/src/handlers/sync-progress.ts +0 -99
- package/src/handlers/sync.test.ts +0 -168
- package/src/handlers/sync.ts +0 -118
- package/src/handlers/system-update.test.ts +0 -497
- package/src/handlers/system-update.ts +0 -230
- package/src/handlers/thread.test.ts +0 -396
- package/src/handlers/thread.ts +0 -427
- package/src/handlers/unified-threads-mail-sources.sqlite.test.ts +0 -197
- package/src/handlers/unified-threads.test.ts +0 -785
- package/src/handlers/unified-threads.ts +0 -669
- package/src/index.test.ts +0 -83
- package/src/index.ts +0 -228
- package/src/jwt-auth.test.ts +0 -152
- package/src/jwt-auth.ts +0 -132
- package/src/log-redaction.test.ts +0 -144
- package/src/openapi-spec.test.ts +0 -118
- package/src/request-context.test.ts +0 -61
- package/src/request-context.ts +0 -33
- package/src/request-pipeline.test.ts +0 -88
- package/src/request.ts +0 -10
- package/src/response.test.ts +0 -130
- package/src/response.ts +0 -144
- package/src/service/compose-sqlite.ts +0 -98
- package/src/service/config-import.ts +0 -39
- package/src/service/create-remit-client.ts +0 -521
- package/src/service/data-client.test.ts +0 -97
- package/src/service/data-client.ts +0 -58
- package/src/service/export-identity.ts +0 -39
- package/src/service/filter.ts +0 -40
- package/src/service/fire-and-forget.test.ts +0 -126
- package/src/service/fire-and-forget.ts +0 -79
- package/src/service/localhost-env-config.test.ts +0 -36
- package/src/service/organize-queue.ts +0 -98
- package/src/service/organize.test.ts +0 -1451
- package/src/service/organize.ts +0 -1025
- package/src/service/read-path-filter-config.test.ts +0 -243
- package/src/service/semantic-capability.test.ts +0 -78
- package/src/service/semantic-capability.ts +0 -95
- package/src/service/sender-category.test.ts +0 -235
- package/src/service/trigger-sync.test.ts +0 -205
- package/src/service/trigger-sync.ts +0 -100
- package/src/stdout-capture-fixture.ts +0 -40
- package/src/types.ts +0 -271
- package/tsconfig.json +0 -7
package/src/response.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { logger } from "@remit/logger-lambda";
|
|
2
|
-
import type { APIGatewayProxyResult } from "aws-lambda";
|
|
3
|
-
import type { Context as OpenAPIContext } from "openapi-backend";
|
|
4
|
-
import {
|
|
5
|
-
getRequestCorrelationId,
|
|
6
|
-
getRequestOrigin,
|
|
7
|
-
resolveAllowedOrigin,
|
|
8
|
-
} from "./request-context.js";
|
|
9
|
-
|
|
10
|
-
const RAW_API_RESPONSE: unique symbol = Symbol("remit.rawApiResponse");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A response the caller reads by something other than its JSON body — an
|
|
14
|
-
* iCalendar feed, an OAuth redirect's Location, and whatever later joins them.
|
|
15
|
-
*
|
|
16
|
-
* Every other handler returns a plain object and lets this module decide the
|
|
17
|
-
* status, the content type and the serialization. That is the right default and
|
|
18
|
-
* stays the default; a handler that has to own its own media type or headers
|
|
19
|
-
* says so with `rawApiResponse` rather than by returning a shape this one has
|
|
20
|
-
* to guess at.
|
|
21
|
-
* The CORS and correlation headers are still added here, so a raw response is
|
|
22
|
-
* not a way around them.
|
|
23
|
-
*/
|
|
24
|
-
export interface RawApiResponse {
|
|
25
|
-
statusCode: number;
|
|
26
|
-
headers: Record<string, string>;
|
|
27
|
-
body: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type MarkedRawApiResponse = RawApiResponse & {
|
|
31
|
-
readonly [RAW_API_RESPONSE]: true;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const rawApiResponse = (
|
|
35
|
-
response: RawApiResponse,
|
|
36
|
-
): MarkedRawApiResponse =>
|
|
37
|
-
Object.assign(response, { [RAW_API_RESPONSE]: true as const });
|
|
38
|
-
|
|
39
|
-
const isRawApiResponse = (
|
|
40
|
-
body: Record<string, unknown>,
|
|
41
|
-
): body is MarkedRawApiResponse & Record<string, unknown> =>
|
|
42
|
-
RAW_API_RESPONSE in body;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* The headers every response carries whatever its body is: the CORS grant the
|
|
46
|
-
* browser needs, and the id the request's log lines are already tagged with.
|
|
47
|
-
* Returning that id is what makes a bug report's "correlation id" resolve to a
|
|
48
|
-
* server-side line; the browser can only read a non-safelisted header when it
|
|
49
|
-
* is exposed.
|
|
50
|
-
*/
|
|
51
|
-
const envelopeHeaders = (): Record<string, string> => {
|
|
52
|
-
const allowOrigin = resolveAllowedOrigin(getRequestOrigin());
|
|
53
|
-
|
|
54
|
-
const headers: Record<string, string> = {
|
|
55
|
-
"Access-Control-Allow-Origin": allowOrigin,
|
|
56
|
-
"Access-Control-Allow-Headers": "Authorization,Content-Type",
|
|
57
|
-
"Access-Control-Allow-Methods": "GET,POST,PUT,PATCH,DELETE,OPTIONS",
|
|
58
|
-
Vary: "Origin",
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
if (allowOrigin !== "*") {
|
|
62
|
-
headers["Access-Control-Allow-Credentials"] = "true";
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const correlationId = getRequestCorrelationId();
|
|
66
|
-
if (correlationId) {
|
|
67
|
-
headers["x-correlation-id"] = correlationId;
|
|
68
|
-
headers["Access-Control-Expose-Headers"] = "x-correlation-id";
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return headers;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export const formatResponse = (
|
|
75
|
-
body: Record<string, unknown>,
|
|
76
|
-
statusCode = 200,
|
|
77
|
-
): APIGatewayProxyResult => {
|
|
78
|
-
if (body.statusCode && typeof body.statusCode === "number") {
|
|
79
|
-
statusCode = body.statusCode;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (isRawApiResponse(body)) {
|
|
83
|
-
logger.debug({ statusCode: body.statusCode }, "response");
|
|
84
|
-
return {
|
|
85
|
-
statusCode: body.statusCode,
|
|
86
|
-
headers: { ...envelopeHeaders(), ...body.headers },
|
|
87
|
-
body: body.body,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if ("body" in body && body.body && typeof body.body === "object") {
|
|
92
|
-
body = body.body as Record<string, unknown>;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
logger.debug({ statusCode }, "response");
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
statusCode: statusCode,
|
|
99
|
-
headers: {
|
|
100
|
-
"Content-Type": "application/json",
|
|
101
|
-
...envelopeHeaders(),
|
|
102
|
-
},
|
|
103
|
-
body: JSON.stringify(body),
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const postResponseHandler = (context: OpenAPIContext) => {
|
|
108
|
-
const { api, response, operation } = context;
|
|
109
|
-
|
|
110
|
-
if (response.statusCode) return formatResponse(response, response.statusCode);
|
|
111
|
-
|
|
112
|
-
if (process.env.STAGE_NAME !== "dev") return formatResponse(response, 200);
|
|
113
|
-
|
|
114
|
-
const { valid, errors } = api.validateResponse(response, operation);
|
|
115
|
-
|
|
116
|
-
if (valid) return formatResponse(response, 200);
|
|
117
|
-
|
|
118
|
-
const { operationId } = operation;
|
|
119
|
-
|
|
120
|
-
const errorDetails: Record<string, unknown> = {
|
|
121
|
-
errors,
|
|
122
|
-
operationId,
|
|
123
|
-
responseKeys: Object.keys(response),
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
errors?.forEach((error) => {
|
|
127
|
-
if (error.instancePath) {
|
|
128
|
-
const pathParts = error.instancePath.split("/").filter(Boolean);
|
|
129
|
-
let value = response;
|
|
130
|
-
for (const part of pathParts) {
|
|
131
|
-
value = value?.[part];
|
|
132
|
-
}
|
|
133
|
-
errorDetails[`problematicValue_${error.instancePath}`] = {
|
|
134
|
-
path: error.instancePath,
|
|
135
|
-
value: JSON.stringify(value).substring(0, 500),
|
|
136
|
-
error: error.message,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
logger.error(errorDetails, "Response validation failed");
|
|
142
|
-
|
|
143
|
-
return formatResponse(response, 200);
|
|
144
|
-
};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AccountConfigRepo,
|
|
3
|
-
AccountExportRequestRepo,
|
|
4
|
-
AccountRepo,
|
|
5
|
-
AccountSettingRepo,
|
|
6
|
-
AddressRepo,
|
|
7
|
-
CalendarCollectionRepo,
|
|
8
|
-
CalendarEventIndexRepo,
|
|
9
|
-
CalendarFeedTokenRepo,
|
|
10
|
-
CalendarObjectRepo,
|
|
11
|
-
CalendarSuggestionRepo,
|
|
12
|
-
ConfigImportRepo,
|
|
13
|
-
createSqliteDatabase,
|
|
14
|
-
DrizzleCalendarUnitOfWork,
|
|
15
|
-
DrizzleEnvelopeRepository,
|
|
16
|
-
DrizzleFilterAnchorTransaction,
|
|
17
|
-
DrizzleMessageFlagRepository,
|
|
18
|
-
DrizzleMessageRepository,
|
|
19
|
-
DrizzleThreadMessageRepository,
|
|
20
|
-
DrizzleUnitOfWork,
|
|
21
|
-
FilterAnchorRepo,
|
|
22
|
-
FilterRepo,
|
|
23
|
-
LabelRepo,
|
|
24
|
-
MailboxLockRepo,
|
|
25
|
-
MailboxRepo,
|
|
26
|
-
MailboxSpecialUseRepo,
|
|
27
|
-
MessageFlagPushRepo,
|
|
28
|
-
MessageLabelRepo,
|
|
29
|
-
MessagePlacementMoveRepo,
|
|
30
|
-
messageDataSchema,
|
|
31
|
-
OrganizeJobRequestRepo,
|
|
32
|
-
OutboxAttachmentRepo,
|
|
33
|
-
OutboxMessageRepo,
|
|
34
|
-
QuarantineRepo,
|
|
35
|
-
runInTransaction,
|
|
36
|
-
SenderSignerStandingRepo,
|
|
37
|
-
} from "@remit/drizzle-service";
|
|
38
|
-
import { env } from "expect-env";
|
|
39
|
-
import {
|
|
40
|
-
buildSharedDeps,
|
|
41
|
-
createRemitClient,
|
|
42
|
-
type RemitClient,
|
|
43
|
-
type RemitClientRepositories,
|
|
44
|
-
} from "./create-remit-client.js";
|
|
45
|
-
|
|
46
|
-
// The SQLite adapter composition (RFC 036). Every repo runs on the single
|
|
47
|
-
// serialized connection `createSqliteDatabase` opens (D3), so a plain repo
|
|
48
|
-
// write cannot bypass serialization and join an open transaction's savepoint,
|
|
49
|
-
// and `threadMessage` takes that same shared handle, so its writes enlist in
|
|
50
|
-
// the same unit-of-work transaction and the same write queue as everything
|
|
51
|
-
// else.
|
|
52
|
-
export const buildSqliteClient = async (): Promise<RemitClient> => {
|
|
53
|
-
const sqliteDbPath = env.SQLITE_DB_PATH;
|
|
54
|
-
|
|
55
|
-
const { db } = await createSqliteDatabase(messageDataSchema, {
|
|
56
|
-
filename: sqliteDbPath,
|
|
57
|
-
});
|
|
58
|
-
const genericDb = db;
|
|
59
|
-
const messageDataDb = db;
|
|
60
|
-
|
|
61
|
-
const repositories: RemitClientRepositories = {
|
|
62
|
-
accountConfig: new AccountConfigRepo(genericDb),
|
|
63
|
-
account: new AccountRepo(genericDb),
|
|
64
|
-
accountSetting: new AccountSettingRepo(genericDb),
|
|
65
|
-
address: new AddressRepo(genericDb),
|
|
66
|
-
mailbox: new MailboxRepo(genericDb),
|
|
67
|
-
mailboxSpecialUse: new MailboxSpecialUseRepo(genericDb),
|
|
68
|
-
mailboxLock: new MailboxLockRepo(genericDb),
|
|
69
|
-
message: new DrizzleMessageRepository(messageDataDb),
|
|
70
|
-
messageFlag: new DrizzleMessageFlagRepository(messageDataDb),
|
|
71
|
-
outboxMessage: new OutboxMessageRepo(genericDb),
|
|
72
|
-
outboxAttachment: new OutboxAttachmentRepo(genericDb),
|
|
73
|
-
threadMessage: new DrizzleThreadMessageRepository(genericDb),
|
|
74
|
-
envelope: new DrizzleEnvelopeRepository(messageDataDb),
|
|
75
|
-
accountExportRequest: new AccountExportRequestRepo(genericDb),
|
|
76
|
-
configImport: new ConfigImportRepo(genericDb),
|
|
77
|
-
quarantine: new QuarantineRepo(genericDb),
|
|
78
|
-
organizeJobRequest: new OrganizeJobRequestRepo(genericDb),
|
|
79
|
-
placementMove: new MessagePlacementMoveRepo(genericDb),
|
|
80
|
-
flagPush: new MessageFlagPushRepo(genericDb),
|
|
81
|
-
filter: new FilterRepo(genericDb),
|
|
82
|
-
filterAnchor: new FilterAnchorRepo(genericDb),
|
|
83
|
-
filterAnchorTransaction: new DrizzleFilterAnchorTransaction(genericDb),
|
|
84
|
-
label: new LabelRepo(genericDb),
|
|
85
|
-
messageLabel: new MessageLabelRepo(genericDb),
|
|
86
|
-
senderSignerStanding: new SenderSignerStandingRepo(genericDb),
|
|
87
|
-
calendarCollection: new CalendarCollectionRepo(genericDb),
|
|
88
|
-
calendarObject: new CalendarObjectRepo(genericDb),
|
|
89
|
-
calendarEventIndex: new CalendarEventIndexRepo(genericDb),
|
|
90
|
-
calendarFeedToken: new CalendarFeedTokenRepo(genericDb),
|
|
91
|
-
calendarSuggestion: new CalendarSuggestionRepo(genericDb),
|
|
92
|
-
calendarUnitOfWork: new DrizzleCalendarUnitOfWork(genericDb),
|
|
93
|
-
unitOfWork: new DrizzleUnitOfWork(messageDataDb),
|
|
94
|
-
writeSet: (run) => runInTransaction(genericDb, () => run()),
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
return createRemitClient({ repositories, ...buildSharedDeps() });
|
|
98
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { EmbedAnchor } from "@remit/config-transfer";
|
|
2
|
-
import { logger } from "@remit/logger-lambda";
|
|
3
|
-
import { buildEmbeddingServiceFromEnv } from "@remit/search-service/from-env";
|
|
4
|
-
import { isSemanticCapabilityAbsence } from "./semantic-capability.js";
|
|
5
|
-
|
|
6
|
-
type Embedder = {
|
|
7
|
-
embed: (texts: string[]) => Promise<number[][]>;
|
|
8
|
-
readonly embeddingId: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
let cached: Embedder | null = null;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Re-embed a filter's anchor from the source text its file carries. The vector
|
|
15
|
-
* never travels — it is a function of the model that produced it — so this is
|
|
16
|
-
* the one thing an import computes rather than copies.
|
|
17
|
-
*
|
|
18
|
-
* A deployment that ships no vector pipeline answers `undefined` rather than
|
|
19
|
-
* failing the import: the anchor then lands stamped as un-embedded, and the
|
|
20
|
-
* same lazy repair that handles a model migration builds its vector the first
|
|
21
|
-
* time the filter is matched. A configuration file has to be importable on the
|
|
22
|
-
* instance a person is recovering onto, whatever that instance can run.
|
|
23
|
-
*/
|
|
24
|
-
export const embedAnchorText: EmbedAnchor = async (sourceText) => {
|
|
25
|
-
try {
|
|
26
|
-
if (!cached) cached = buildEmbeddingServiceFromEnv();
|
|
27
|
-
const [embedding] = await cached.embed([sourceText]);
|
|
28
|
-
return embedding
|
|
29
|
-
? { embedding, embeddingId: cached.embeddingId }
|
|
30
|
-
: undefined;
|
|
31
|
-
} catch (error) {
|
|
32
|
-
if (!isSemanticCapabilityAbsence(error)) throw error;
|
|
33
|
-
logger.warn(
|
|
34
|
-
{ error: error instanceof Error ? error.message : String(error) },
|
|
35
|
-
"No embedding pipeline in this deployment; an imported filter anchor is stored as text and embedded on first use",
|
|
36
|
-
);
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
};
|