@remit/backend 2.4.0 → 2.5.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/handlers/classification-settings.d.ts +1 -5
- package/dist/src/handlers/classification-settings.js +1 -45
- package/dist/src/handlers/classification-test.js +2 -1
- package/dist/src/handlers/message.js +2 -0
- package/dist/src/handlers/user-settings.js +2 -1
- package/dist/src/service/create-remit-client.js +6 -0
- package/package.json +1 -1
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import type { ClassificationConfigured, ClassificationNotConfigured, ClassificationPreset, UpdateUserSettingsInput } from "@remit/api-openapi-types";
|
|
2
2
|
import type { IAccountSettingRepository } from "@remit/data-ports";
|
|
3
|
+
import { type StoredClassification } from "@remit/data-ports/classification-presets";
|
|
3
4
|
import { type ClassificationLabelDeps } from "@remit/mailbox-service";
|
|
4
5
|
import { type SecretsService, type SerializedEncryptedPayload } from "@remit/secrets-service";
|
|
5
6
|
import type { UserSettingsOutcome } from "./user-settings.js";
|
|
6
|
-
export declare const CLASSIFICATION_SETTING_NAMES: readonly ["ClassificationPresetId", "ClassificationModel", "ClassificationBaseUrl", "ClassificationApiKey", "ClassificationEnabled", "ClassificationDailyLimit"];
|
|
7
7
|
export type ClassificationSettingsDeps = {
|
|
8
8
|
accountSetting: Pick<IAccountSettingRepository, "getMany" | "upsert" | "delete">;
|
|
9
9
|
secrets: Pick<SecretsService, "encrypt">;
|
|
10
10
|
label: ClassificationLabelDeps;
|
|
11
11
|
};
|
|
12
|
-
export type StoredClassification = ClassificationNotConfigured | (ClassificationConfigured & {
|
|
13
|
-
apiKeyCiphertext: SerializedEncryptedPayload | undefined;
|
|
14
|
-
});
|
|
15
12
|
type Refusal = Extract<UserSettingsOutcome, {
|
|
16
13
|
ok: false;
|
|
17
14
|
}>;
|
|
@@ -36,7 +33,6 @@ export interface ClassificationProviderSave {
|
|
|
36
33
|
}
|
|
37
34
|
type ClassificationInput = Pick<UpdateUserSettingsInput, "classificationPresetId" | "classificationModel" | "classificationBaseUrl" | "classificationApiKey" | "classificationEnabled" | "classificationDailyLimit">;
|
|
38
35
|
export declare const decideClassificationProvider: (input: ClassificationInput, stored: StoredClassification) => Decision<ClassificationProviderSave>;
|
|
39
|
-
export declare const readStoredClassification: (accountSetting: Pick<IAccountSettingRepository, "getMany">, accountConfigId: string) => Promise<StoredClassification>;
|
|
40
36
|
export declare const publicClassification: (stored: StoredClassification) => ClassificationNotConfigured | ClassificationConfigured;
|
|
41
37
|
export declare const classificationPresetsResponse: () => ClassificationPreset[];
|
|
42
38
|
interface ClassificationChange {
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CLASSIFICATION_PRESETS, DEFAULT_CLASSIFICATION_DAILY_LIMIT, isClassificationPresetId, } from "@remit/data-ports/classification-presets";
|
|
1
|
+
import { CLASSIFICATION_PRESETS, CLASSIFICATION_SETTING_NAMES, } from "@remit/data-ports/classification-presets";
|
|
3
2
|
import { AccountSettingName } from "@remit/domain-enums";
|
|
4
3
|
import { ensureClassificationLabels, } from "@remit/mailbox-service";
|
|
5
4
|
import { serializeEncryptedPayload, } from "@remit/secrets-service";
|
|
6
|
-
export const CLASSIFICATION_SETTING_NAMES = [
|
|
7
|
-
AccountSettingName.ClassificationPresetId,
|
|
8
|
-
AccountSettingName.ClassificationModel,
|
|
9
|
-
AccountSettingName.ClassificationBaseUrl,
|
|
10
|
-
AccountSettingName.ClassificationApiKey,
|
|
11
|
-
AccountSettingName.ClassificationEnabled,
|
|
12
|
-
AccountSettingName.ClassificationDailyLimit,
|
|
13
|
-
];
|
|
14
5
|
const refuse = (code, message) => ({
|
|
15
6
|
ok: false,
|
|
16
7
|
error: { code, message },
|
|
@@ -73,41 +64,6 @@ export const decideClassificationProvider = (input, stored) => {
|
|
|
73
64
|
},
|
|
74
65
|
};
|
|
75
66
|
};
|
|
76
|
-
const settingOf = (rows, name) => rows.find((row) => row.name === name);
|
|
77
|
-
export const readStoredClassification = async (accountSetting, accountConfigId) => {
|
|
78
|
-
const rows = await accountSetting.getMany([accountConfigId], CLASSIFICATION_SETTING_NAMES);
|
|
79
|
-
const presetRow = settingOf(rows, AccountSettingName.ClassificationPresetId);
|
|
80
|
-
if (!presetRow)
|
|
81
|
-
return { state: "NotConfigured" };
|
|
82
|
-
const presetId = parseAccountSettingValue(AccountSettingName.ClassificationPresetId, presetRow.value).value;
|
|
83
|
-
if (!isClassificationPresetId(presetId)) {
|
|
84
|
-
throw new Error(`Stored classification preset is unknown: ${presetId}`);
|
|
85
|
-
}
|
|
86
|
-
const stringOf = (name) => {
|
|
87
|
-
const row = settingOf(rows, name);
|
|
88
|
-
return row ? parseAccountSettingValue(name, row.value).value : "";
|
|
89
|
-
};
|
|
90
|
-
const keyRow = settingOf(rows, AccountSettingName.ClassificationApiKey);
|
|
91
|
-
const enabledRow = settingOf(rows, AccountSettingName.ClassificationEnabled);
|
|
92
|
-
const limitRow = settingOf(rows, AccountSettingName.ClassificationDailyLimit);
|
|
93
|
-
return {
|
|
94
|
-
state: "Configured",
|
|
95
|
-
presetId,
|
|
96
|
-
model: stringOf(AccountSettingName.ClassificationModel),
|
|
97
|
-
baseUrl: stringOf(AccountSettingName.ClassificationBaseUrl),
|
|
98
|
-
apiKeySaved: keyRow !== undefined,
|
|
99
|
-
apiKeyCiphertext: keyRow
|
|
100
|
-
? parseAccountSettingValue(AccountSettingName.ClassificationApiKey, keyRow.value).value
|
|
101
|
-
: undefined,
|
|
102
|
-
enabled: enabledRow
|
|
103
|
-
? parseAccountSettingValue(AccountSettingName.ClassificationEnabled, enabledRow.value).value
|
|
104
|
-
: false,
|
|
105
|
-
dailyLimit: limitRow
|
|
106
|
-
? parseAccountSettingValue(AccountSettingName.ClassificationDailyLimit, limitRow.value).value
|
|
107
|
-
: DEFAULT_CLASSIFICATION_DAILY_LIMIT,
|
|
108
|
-
savedAt: presetRow.updatedAt,
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
67
|
export const publicClassification = (stored) => {
|
|
112
68
|
if (stored.state === "NotConfigured")
|
|
113
69
|
return stored;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { readStoredClassification } from "@remit/data-ports/classification-presets";
|
|
1
2
|
import { ClassificationFailureKind as FailureKind, ClassificationField as Field, } from "@remit/domain-enums";
|
|
2
3
|
import { CLASSIFIER_LABELS, CLASSIFIER_SAMPLE_MESSAGE, classifyWithProvider, } from "@remit/mailbox-service/classifier";
|
|
3
4
|
import { deserializeEncryptedPayload, } from "@remit/secrets-service";
|
|
4
|
-
import { decideClassificationProvider,
|
|
5
|
+
import { decideClassificationProvider, } from "./classification-settings.js";
|
|
5
6
|
const REACH_FIX = "Check the endpoint runs and the Remit server can reach it";
|
|
6
7
|
const DEFAULT_MODEL_FIX = "Use the preset's default model";
|
|
7
8
|
const FAILURE_HELP = {
|
|
@@ -279,6 +279,7 @@ export const MessageOperations = {
|
|
|
279
279
|
const folder = {
|
|
280
280
|
mailboxId: mailbox.mailboxId,
|
|
281
281
|
fullPath: mailbox.fullPath,
|
|
282
|
+
initialSyncCompletedAt: mailbox.initialSyncCompletedAt,
|
|
282
283
|
placement: await resolveFolderPlacement(client.mailboxSpecialUse, accountId, mailbox.mailboxId),
|
|
283
284
|
};
|
|
284
285
|
const scope = await client.createConnectionScope(accountId);
|
|
@@ -385,6 +386,7 @@ export const MessageOperations = {
|
|
|
385
386
|
const folder = {
|
|
386
387
|
mailboxId: mailbox.mailboxId,
|
|
387
388
|
fullPath: mailbox.fullPath,
|
|
389
|
+
initialSyncCompletedAt: mailbox.initialSyncCompletedAt,
|
|
388
390
|
placement: await resolveFolderPlacement(client.mailboxSpecialUse, accountId, mailbox.mailboxId),
|
|
389
391
|
};
|
|
390
392
|
const scope = await client.createConnectionScope(accountId);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { invitationSenderInEffect, sendingAccountFor, } from "@remit/calendar-service";
|
|
2
2
|
import { parseAccountSettingValue } from "@remit/data-ports/account-settings";
|
|
3
|
+
import { readStoredClassification } from "@remit/data-ports/classification-presets";
|
|
3
4
|
import { AccountSettingName } from "@remit/domain-enums";
|
|
4
5
|
import { logger } from "@remit/logger";
|
|
5
6
|
import { badRequest } from "./calendar.js";
|
|
6
|
-
import { classificationPresetsResponse, clearClassification, decideClassificationChange, publicClassification,
|
|
7
|
+
import { classificationPresetsResponse, clearClassification, decideClassificationChange, publicClassification, writeClassificationChange, } from "./classification-settings.js";
|
|
7
8
|
import { testClassificationProvider } from "./classification-test.js";
|
|
8
9
|
/** The account the reader chose to send invitations from, if they chose one. */
|
|
9
10
|
export const chosenInvitationSender = async (accountSetting, accountConfigId) => {
|
|
@@ -158,6 +158,12 @@ export const composeReadPathServices = (core, queues, sync) => ({
|
|
|
158
158
|
calendarStore: core.calendarStore,
|
|
159
159
|
filterService: core.filter,
|
|
160
160
|
accountService: core.account,
|
|
161
|
+
}, {
|
|
162
|
+
accountSetting: core.accountSetting,
|
|
163
|
+
secrets: core.secrets,
|
|
164
|
+
labelService: core.label,
|
|
165
|
+
messageLabelService: core.messageLabel,
|
|
166
|
+
logger,
|
|
161
167
|
}),
|
|
162
168
|
});
|
|
163
169
|
export const createRemitClient = (deps) => {
|