@remit/backend 2.6.2 → 2.7.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/dist/src/config/classification-default.d.ts +2 -0
- package/dist/src/config/classification-default.js +54 -0
- package/dist/src/service/compose-sqlite.d.ts +2 -1
- package/dist/src/service/compose-sqlite.js +1 -1
- package/dist/src/service/create-remit-client.d.ts +3 -0
- package/dist/src/service/create-remit-client.js +2 -1
- package/dist/src/service/data-client.js +3 -1
- package/dist/src/service/shared-deps.d.ts +2 -1
- package/dist/src/service/shared-deps.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CLASSIFICATION_PRESETS, DEFAULT_CLASSIFICATION_DAILY_LIMIT, isClassificationPresetId, } from "@remit/data-ports/classification-presets";
|
|
2
|
+
const PRESET = "CLASSIFICATION_DEFAULT_PRESET";
|
|
3
|
+
const MODEL = "CLASSIFICATION_DEFAULT_MODEL";
|
|
4
|
+
const BASE_URL = "CLASSIFICATION_DEFAULT_BASE_URL";
|
|
5
|
+
const API_KEY = "CLASSIFICATION_DEFAULT_API_KEY";
|
|
6
|
+
const ENABLED = "CLASSIFICATION_DEFAULT_ENABLED";
|
|
7
|
+
const DAILY_LIMIT = "CLASSIFICATION_DEFAULT_DAILY_LIMIT";
|
|
8
|
+
const DEPENDENT_KEYS = [MODEL, BASE_URL, API_KEY, ENABLED, DAILY_LIMIT];
|
|
9
|
+
const refuse = (message) => {
|
|
10
|
+
throw new Error(`Refusing to start: ${message}`);
|
|
11
|
+
};
|
|
12
|
+
const envValue = (env, key) => (env[key] ?? "").trim();
|
|
13
|
+
const enabledOf = (raw) => {
|
|
14
|
+
if (raw === "" || raw === "false")
|
|
15
|
+
return false;
|
|
16
|
+
if (raw === "true")
|
|
17
|
+
return true;
|
|
18
|
+
return refuse(`${ENABLED}=${raw} must be true or false.`);
|
|
19
|
+
};
|
|
20
|
+
const dailyLimitOf = (raw) => {
|
|
21
|
+
if (raw === "")
|
|
22
|
+
return DEFAULT_CLASSIFICATION_DAILY_LIMIT;
|
|
23
|
+
const limit = Number(raw);
|
|
24
|
+
if (/^\d+$/.test(raw) && Number.isSafeInteger(limit) && limit > 0)
|
|
25
|
+
return limit;
|
|
26
|
+
return refuse(`${DAILY_LIMIT}=${raw} must be a positive integer.`);
|
|
27
|
+
};
|
|
28
|
+
export const classificationDefaultFromEnv = (env) => {
|
|
29
|
+
const presetId = envValue(env, PRESET);
|
|
30
|
+
if (presetId === "") {
|
|
31
|
+
const stray = DEPENDENT_KEYS.filter((key) => envValue(env, key) !== "");
|
|
32
|
+
if (stray.length > 0)
|
|
33
|
+
return refuse(`${stray.join(", ")} set without ${PRESET}.`);
|
|
34
|
+
return { state: "None" };
|
|
35
|
+
}
|
|
36
|
+
if (!isClassificationPresetId(presetId))
|
|
37
|
+
return refuse(`${PRESET}=${presetId} is not a known preset. Use one of ${Object.keys(CLASSIFICATION_PRESETS).join(", ")}.`);
|
|
38
|
+
const preset = CLASSIFICATION_PRESETS[presetId];
|
|
39
|
+
const apiKey = envValue(env, API_KEY);
|
|
40
|
+
if (preset.needsKey && apiKey === "")
|
|
41
|
+
return refuse(`${API_KEY} is not set. ${PRESET}=${presetId} needs a key.`);
|
|
42
|
+
const baseUrl = envValue(env, BASE_URL) || preset.defaultBaseUrl;
|
|
43
|
+
if (!baseUrl)
|
|
44
|
+
return refuse(`${BASE_URL} is not set. ${PRESET}=${presetId} has no default base URL.`);
|
|
45
|
+
return {
|
|
46
|
+
state: "Configured",
|
|
47
|
+
presetId,
|
|
48
|
+
model: envValue(env, MODEL) || preset.defaultModel,
|
|
49
|
+
baseUrl,
|
|
50
|
+
apiKey,
|
|
51
|
+
enabled: enabledOf(envValue(env, ENABLED)),
|
|
52
|
+
dailyLimit: dailyLimitOf(envValue(env, DAILY_LIMIT)),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ClassificationDeploymentDefault } from "@remit/data-ports/classification-presets";
|
|
1
2
|
import { type RemitClient, type RemitClientSharedDeps } from "./create-remit-client.js";
|
|
2
3
|
export declare const composeSqliteClient: (shared: RemitClientSharedDeps) => Promise<RemitClient>;
|
|
3
|
-
export declare const buildSqliteClient: () => Promise<RemitClient>;
|
|
4
|
+
export declare const buildSqliteClient: (classificationDefault: ClassificationDeploymentDefault) => Promise<RemitClient>;
|
|
@@ -12,4 +12,4 @@ export const composeSqliteClient = async (shared) => {
|
|
|
12
12
|
...shared,
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
|
-
export const buildSqliteClient = () => composeSqliteClient(buildSharedDeps(sqsQueues(sqsQueueUrlsFromEnv())));
|
|
15
|
+
export const buildSqliteClient = (classificationDefault) => composeSqliteClient(buildSharedDeps(sqsQueues(sqsQueueUrlsFromEnv()), classificationDefault));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { IAccountConfigRepository, IAccountExportRequestRepository, IAccountRepository, IAccountSettingRepository, IAddressRepository, ICalendarCollectionRepository, ICalendarEventIndexRepository, ICalendarFeedTokenRepository, ICalendarObjectRepository, ICalendarStore, ICalendarSuggestionRepository, ICalendarTaskRepository, IConfigImportRepository, IEnvelopeRepository, IFilterRepository, ILabelRepository, IMailboxLockRepository, IMailboxRepository, IMailboxSpecialUseRepository, IMessageFlagPushRepository, IMessageFlagRepository, IMessageLabelRepository, IMessagePlacementMoveRepository, IMessageRepository, IOrganizeJobRequestRepository, IOutboxAttachmentRepository, IOutboxMessageRepository, IOutboxSchedulingPartRepository, IQuarantineRepository, ISenderSignerStandingRepository, ISyncWarningRepository, IThreadMessageRepository } from "@remit/data-ports";
|
|
2
|
+
import type { ClassificationDeploymentDefault } from "@remit/data-ports/classification-presets";
|
|
2
3
|
import { BodySyncQueueService, BodySyncService, type ConnectionScope, type FilterConfig, FlagQueueService, type ImapTransport, MailboxQueueService, MessageMoveService, OutboxAttachmentService, OutboxQueueService, SpamReportService } from "@remit/mailbox-service";
|
|
3
4
|
import { type SecretsService } from "@remit/secrets-service";
|
|
4
5
|
import type { SmtpGetSocket } from "@remit/smtp-service";
|
|
@@ -47,6 +48,7 @@ export interface RemitClientCore {
|
|
|
47
48
|
outboxAttachment: OutboxAttachmentService;
|
|
48
49
|
createConnectionScope: (accountId: string) => Promise<ConnectionScope>;
|
|
49
50
|
mailTransports: MailTransports;
|
|
51
|
+
classificationDefault: ClassificationDeploymentDefault;
|
|
50
52
|
}
|
|
51
53
|
export interface SyncQueueServices {
|
|
52
54
|
flagQueue: FlagQueueService;
|
|
@@ -106,6 +108,7 @@ export interface RemitClientSharedDeps {
|
|
|
106
108
|
connectionScope: ConnectionScopeFactory;
|
|
107
109
|
mailTransports: MailTransports;
|
|
108
110
|
queues: RemitClientQueues;
|
|
111
|
+
classificationDefault: ClassificationDeploymentDefault;
|
|
109
112
|
}
|
|
110
113
|
export interface RemitClientDeps extends RemitClientSharedDeps {
|
|
111
114
|
repositories: RemitClientRepositories;
|
|
@@ -45,7 +45,7 @@ export const buildReadPathFilterConfig = (repositories, queues) => {
|
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
47
|
export const createRemitCore = (deps) => {
|
|
48
|
-
const { repositories, storage, secrets, connectionScope, mailTransports } = deps;
|
|
48
|
+
const { repositories, storage, secrets, connectionScope, mailTransports, classificationDefault, } = deps;
|
|
49
49
|
return {
|
|
50
50
|
accountConfig: repositories.accountConfig,
|
|
51
51
|
account: repositories.account,
|
|
@@ -90,6 +90,7 @@ export const createRemitCore = (deps) => {
|
|
|
90
90
|
}),
|
|
91
91
|
createConnectionScope: connectionScope(repositories.account, secrets),
|
|
92
92
|
mailTransports,
|
|
93
|
+
classificationDefault,
|
|
93
94
|
};
|
|
94
95
|
};
|
|
95
96
|
export const composeSyncServices = (core, queues) => {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { classificationDefaultFromEnv } from "../config/classification-default.js";
|
|
1
2
|
let clientPromise = null;
|
|
2
3
|
let injected = null;
|
|
4
|
+
const classificationDefault = classificationDefaultFromEnv(process.env);
|
|
3
5
|
/**
|
|
4
6
|
* Register the client from the composition root. An adapter that lives outside
|
|
5
7
|
* this shared, open-core module — DynamoDB, or a Postgres adapter in the
|
|
@@ -27,7 +29,7 @@ const buildRelationalClient = async () => {
|
|
|
27
29
|
throw new Error("no client registered — register one with setClient() from your composition root");
|
|
28
30
|
}
|
|
29
31
|
const composition = await import("./compose-sqlite.js");
|
|
30
|
-
return composition.buildSqliteClient();
|
|
32
|
+
return composition.buildSqliteClient(classificationDefault);
|
|
31
33
|
};
|
|
32
34
|
export const getClient = () => {
|
|
33
35
|
clientPromise ??= injected
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { ClassificationDeploymentDefault } from "@remit/data-ports/classification-presets";
|
|
1
2
|
import { type RemitClientSharedDeps } from "./create-remit-client.js";
|
|
2
3
|
import type { QueueName, RemitClientQueues } from "./queues.js";
|
|
3
4
|
export type SqsQueueUrls = Record<QueueName, string>;
|
|
4
5
|
export declare const sqsQueueUrlsFromEnv: () => SqsQueueUrls;
|
|
5
6
|
export declare const sqsQueues: (urls: SqsQueueUrls) => RemitClientQueues;
|
|
6
|
-
export declare const buildSharedDeps: (queues: RemitClientQueues) => RemitClientSharedDeps;
|
|
7
|
+
export declare const buildSharedDeps: (queues: RemitClientQueues, classificationDefault: ClassificationDeploymentDefault) => RemitClientSharedDeps;
|
|
@@ -22,7 +22,7 @@ export const sqsQueues = (urls) => ({
|
|
|
22
22
|
}),
|
|
23
23
|
body: createStandardQueueProducer({ queueUrl: urls.body }),
|
|
24
24
|
});
|
|
25
|
-
export const buildSharedDeps = (queues) => {
|
|
25
|
+
export const buildSharedDeps = (queues, classificationDefault) => {
|
|
26
26
|
const imapTransport = nodeTransport();
|
|
27
27
|
return {
|
|
28
28
|
storage: createStorageService(),
|
|
@@ -30,5 +30,6 @@ export const buildSharedDeps = (queues) => {
|
|
|
30
30
|
connectionScope: passwordConnectionScope(imapTransport),
|
|
31
31
|
mailTransports: { imap: () => imapTransport, smtp: directSmtpSocket },
|
|
32
32
|
queues,
|
|
33
|
+
classificationDefault,
|
|
33
34
|
};
|
|
34
35
|
};
|