@jini-ai/platform 0.7.1 → 0.7.3-next.1
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 +2 -2
- package/README.md +16 -4
- package/dist/asset-cache.d.ts +13 -3
- package/dist/asset-cache.js +163 -154
- package/dist/blob-storage.d.ts +3 -32
- package/dist/blob-storage.js +1 -9
- package/dist/child-environment.d.ts +0 -16
- package/dist/child-environment.js +0 -25
- package/dist/command.d.ts +6 -11
- package/dist/command.js +8 -54
- package/dist/download-lock.d.ts +4 -0
- package/dist/download-lock.js +82 -0
- package/dist/download-maintenance.d.ts +5 -0
- package/dist/download-maintenance.js +82 -0
- package/dist/download-state.d.ts +8 -0
- package/dist/download-state.js +126 -0
- package/dist/download-store.d.ts +22 -0
- package/dist/download-store.js +174 -0
- package/dist/download-target.d.ts +10 -0
- package/dist/download-target.js +102 -0
- package/dist/download-transfer.d.ts +12 -0
- package/dist/download-transfer.js +174 -0
- package/dist/download-types.d.ts +162 -0
- package/dist/download-types.js +31 -0
- package/dist/download.d.ts +1 -89
- package/dist/download.js +8 -738
- package/dist/fetch-with-timeout.d.ts +7 -32
- package/dist/fetch-with-timeout.js +1 -77
- package/dist/fs/app-data-root.d.ts +28 -0
- package/dist/fs/app-data-root.js +35 -0
- package/dist/fs/atomic-write.js +1 -1
- package/dist/fs/boot-identity.d.ts +1 -4
- package/dist/fs/directory-delete-guard.d.ts +93 -0
- package/dist/fs/directory-delete-guard.js +148 -0
- package/dist/fs/directory-registry.js +45 -35
- package/dist/fs/directory-relocation.d.ts +82 -0
- package/dist/fs/directory-relocation.js +99 -0
- package/dist/fs/directory-running-lock.d.ts +1 -1
- package/dist/fs/directory-running-lock.js +24 -21
- package/dist/fs/directory-sync.js +1 -1
- package/dist/fs/directory-user-config.js +30 -3
- package/dist/fs/directory-workspace.d.ts +34 -30
- package/dist/fs/directory-workspace.js +70 -29
- package/dist/fs/durable-json.d.ts +6 -15
- package/dist/fs/durable-json.js +38 -35
- package/dist/fs/errno.d.ts +12 -3
- package/dist/fs/errno.js +5 -3
- package/dist/fs/file-lock.d.ts +3 -87
- package/dist/fs/file-lock.js +16 -30
- package/dist/fs/guarded-reader.js +335 -315
- package/dist/fs/index.d.ts +5 -0
- package/dist/fs/index.js +5 -0
- package/dist/fs/recent-directories.d.ts +46 -0
- package/dist/fs/recent-directories.js +68 -0
- package/dist/fs/remove-directory-tree.d.ts +20 -0
- package/dist/fs/remove-directory-tree.js +28 -0
- package/dist/fs/user-data-directories.js +2 -2
- package/dist/fs/workspace-directory.js +2 -1
- package/dist/fs.d.ts +16 -4
- package/dist/fs.js +4 -4
- package/dist/home-expansion.d.ts +7 -2
- package/dist/home-expansion.js +3 -3
- package/dist/http/guarded/client.d.ts +1 -2
- package/dist/http/guarded/client.js +2 -1
- package/dist/http/guarded/index.d.ts +0 -3
- package/dist/http/guarded/node-ports.d.ts +1 -1
- package/dist/http/guarded/transport.fetch.d.ts +2 -3
- package/dist/http/guarded/transport.fetch.js +64 -58
- package/dist/http.d.ts +3 -1
- package/dist/http.js +2 -2
- package/dist/index.d.ts +10 -11
- package/dist/index.js +7 -6
- package/dist/mail/activity/activity.d.ts +136 -0
- package/dist/mail/activity/activity.js +172 -0
- package/dist/mail/activity/ports.d.ts +113 -0
- package/dist/mail/activity/suppressions.d.ts +82 -0
- package/dist/mail/activity/suppressions.js +119 -0
- package/dist/mail/activity/vocabulary.d.ts +10 -0
- package/dist/mail/activity/vocabulary.js +8 -0
- package/dist/mail/builtin-providers.d.ts +12 -6
- package/dist/mail/builtin-providers.js +14 -11
- package/dist/mail/delivery-wrapper.js +2 -1
- package/dist/mail/email-sender-registry.d.ts +1 -1
- package/dist/mail/email-sender-registry.js +1 -1
- package/dist/mail/email-template-operations.d.ts +186 -0
- package/dist/mail/email-template-operations.js +226 -0
- package/dist/mail/email-template.d.ts +120 -0
- package/dist/mail/email-template.js +243 -0
- package/dist/mail/index.d.ts +4 -0
- package/dist/mail/index.js +3 -0
- package/dist/mail/prepare-sender-email.d.ts +1 -10
- package/dist/mail/prepare-sender-email.js +1 -11
- package/dist/mail/resolve-mailer.d.ts +2 -1
- package/dist/mail/resolve-mailer.js +5 -2
- package/dist/mail/senders.d.ts +0 -1
- package/dist/mail/senders.js +0 -1
- package/dist/mail/smtp.d.ts +1 -31
- package/dist/net/address.d.ts +1 -8
- package/dist/net/address.js +1 -18
- package/dist/net/index.d.ts +1 -1
- package/dist/net/index.js +1 -1
- package/dist/net/local-http-probe.js +1 -1
- package/dist/net/local-http-request.js +1 -1
- package/dist/process-probes.d.ts +36 -0
- package/dist/process-probes.js +151 -0
- package/dist/process-top-footprint.d.ts +7 -0
- package/dist/process-top-footprint.js +30 -0
- package/dist/process.d.ts +29 -31
- package/dist/process.js +18 -196
- package/dist/proxy-env.d.ts +12 -3
- package/dist/proxy-env.js +9 -8
- package/dist/resource-paths.d.ts +15 -3
- package/dist/resource-paths.js +7 -5
- package/dist/sandbox-env.d.ts +26 -5
- package/dist/sandbox-env.js +7 -7
- package/dist/secrets/credential-sets/contracts.d.ts +0 -1
- package/dist/secrets/credential-sets/contracts.js +0 -1
- package/dist/secrets/credential-sets/index.d.ts +2 -3
- package/dist/secrets/credential-sets/index.js +1 -1
- package/dist/secrets/credential-sets/provider-matches.d.ts +1 -1
- package/dist/secrets/credential-sets/provider-matches.js +1 -1
- package/dist/secrets/credential-sets/vault-archive.d.ts +1 -1
- package/dist/secrets/credential-sets/vault-archive.js +14 -8
- package/dist/secrets/credential-sets/vault.aad.d.ts +1 -1
- package/dist/secrets/credential-sets/vault.meta.d.ts +1 -1
- package/dist/secrets/credential-sets/vault.meta.js +1 -1
- package/dist/secrets/credential-sets/vault.repo.memory.d.ts +1 -1
- package/dist/secrets/credential-sets/vault.repo.memory.js +1 -1
- package/dist/secrets/credential-sets/vault.reseal-refused.d.ts +23 -0
- package/dist/secrets/credential-sets/vault.reseal-refused.js +36 -0
- package/dist/secrets/credential-sets/vault.service.d.ts +25 -5
- package/dist/secrets/credential-sets/vault.service.js +42 -8
- package/dist/secrets/index.d.ts +0 -3
- package/dist/secrets/index.js +5 -0
- package/dist/secrets/keyring.env.d.ts +1 -1
- package/dist/secrets/legacy-owner.d.ts +61 -0
- package/dist/secrets/legacy-owner.js +196 -0
- package/dist/secrets/root-key/decide.d.ts +89 -0
- package/dist/secrets/root-key/decide.js +60 -0
- package/dist/secrets/sealer-contract.d.ts +19 -0
- package/dist/secrets/sealer-contract.js +37 -0
- package/dist/secrets/secret-sealer.aesgcm.d.ts +1 -1
- package/dist/secrets/testing.d.ts +1 -0
- package/dist/secrets/testing.js +1 -0
- package/dist/shell.d.ts +4 -1
- package/dist/shell.js +1 -1
- package/dist/system.d.ts +6 -0
- package/dist/system.js +9 -0
- package/dist/terminal.d.ts +11 -96
- package/dist/terminal.js +80 -56
- package/dist/web/agent-tools.d.ts +107 -0
- package/dist/web/agent-tools.js +49 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +1 -0
- package/package.json +38 -12
- package/dist/http/guarded/ports.d.ts +0 -56
- package/dist/http/guarded/types.d.ts +0 -8
- package/dist/http/guarded/types.js +0 -2
- package/dist/mail/email-sender.d.ts +0 -109
- package/dist/mail/email-sender.js +0 -10
- package/dist/net/endpoint-policy.d.ts +0 -39
- package/dist/net/endpoint-policy.js +0 -218
- package/dist/secrets/credential-sets/vault.types.d.ts +0 -27
- package/dist/secrets/credential-sets/vault.types.js +0 -49
- /package/dist/{http/guarded → mail/activity}/ports.js +0 -0
package/dist/index.js
CHANGED
|
@@ -32,22 +32,23 @@
|
|
|
32
32
|
* Filesystem/network storage and its SigV4 signing belong here, with no kernel SQL-port dependency.
|
|
33
33
|
*/
|
|
34
34
|
export { createCommandInvocation, createPackageManagerInvocation } from "./command.js";
|
|
35
|
-
export { omitEnvironmentKeys } from "./child-environment.js";
|
|
36
35
|
export { mergeProxyAwareEnv, parseMacosScutilProxyOutput, parseWindowsInternetSettingsProxyOutput, resolveSystemProxyEnv, } from "./proxy-env.js";
|
|
37
|
-
export {
|
|
36
|
+
export { createProcessStampArgs, isProcessAlive, listProcessSnapshots, listProcessUsage, matchesProcessStamp, matchesStampedProcess, readFlagValue, readProcessStamp, readProcessStampFromCommand, spawnBackgroundProcess, spawnLoggedProcess, stopProcesses, waitForProcessExit, } from "./process.js";
|
|
38
37
|
export { atomicCopyFile, pathContains, readLogTail, removePathBestEffort } from "./fs.js";
|
|
39
38
|
export { waitForHttpOk } from "./http.js";
|
|
40
|
-
export {
|
|
39
|
+
export { FetchTimeoutError, ResponseLimitExceededError, createDeadlineSignal, fetchWithTimeout } from "./fetch-with-timeout.js";
|
|
41
40
|
export { wellKnownUserToolchainBins } from "./toolchain.js";
|
|
42
41
|
export { execCommandViaLoginShell, execFileBuffered } from "./shell.js";
|
|
43
42
|
export { AssetCacheError, assertSafePublicUrl, assetCacheKey, assetCacheRewriteUrl, createAssetCache, createAssetCacheDispatcher, createValidatingLookup, isCacheableExternalUrl, } from "./asset-cache.js";
|
|
44
43
|
export { expandHomePrefix, resolveProjectRelativePath } from "./home-expansion.js";
|
|
45
44
|
export { applySandboxRuntimeEnv, ensureSandboxRuntimeDirs, isSandboxImportedProjectRootAllowed, isSandboxModeEnabled, resolveSandboxRuntimeConfig, resolveSandboxRuntimeConfigFromEnv, sandboxAgentProfilesConfigPath, sandboxImportAllowedRoots, sandboxImportedProjectRootUnavailableReason, } from "./sandbox-env.js";
|
|
46
45
|
export { resolveDaemonCliPath, resolveDaemonPluginPreviewsDir, resolveDaemonResourceDir, resolveDaemonResourceRoot, resolveDataDir, resolveProcessResourcesPath, } from "./resource-paths.js";
|
|
47
|
-
export { createTerminalService, ensureSpawnHelperExecutable, resolveShell, spawnHelperCandidatePaths } from "./terminal.js";
|
|
48
|
-
export { MANAGED_DOWNLOAD_ERROR_CODES, ManagedDownloadError
|
|
46
|
+
export { createTerminalService, ensureSpawnHelperExecutable, resolveShell, spawnHelperCandidatePaths, terminalSessionState } from "./terminal.js";
|
|
47
|
+
export { MANAGED_DOWNLOAD_ERROR_CODES, ManagedDownloadError } from "./download-types.js";
|
|
48
|
+
export { downloadCopyAndClear, managedDownload } from "./download.js";
|
|
49
|
+
export { inspectManagedDownload, pruneManagedDownloads, removeManagedDownload } from "./download-maintenance.js";
|
|
49
50
|
export { encodeS3PathSegment, signSigV4 } from "./aws-sigv4.js";
|
|
50
|
-
export { LocalBlobStorage, S3BlobStorage
|
|
51
|
+
export { LocalBlobStorage, S3BlobStorage } from "./blob-storage.js";
|
|
51
52
|
// Cohesive subpaths remain available as namespaced APIs without colliding with legacy names.
|
|
52
53
|
export * as filesystem from "./fs/index.js";
|
|
53
54
|
export * as guardedHttp from "./http/guarded/index.js";
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { AuthorizeFn } from "@jini-ai/core/contracts/events";
|
|
2
|
+
import type { MailActivityFilter, MailActivityPosition, MailActivityRecord, MailActivityRepo, MailFeedbackRecord } from "./ports.js";
|
|
3
|
+
export declare const DEFAULT_MAIL_ACTIVITY_LIMIT = 25;
|
|
4
|
+
export declare const MAX_MAIL_ACTIVITY_LIMIT = 100;
|
|
5
|
+
export type MailActivityAccess = "full" | "masked";
|
|
6
|
+
/** The ids the host grants the three roles of the mail operations; the operations never spell one. */
|
|
7
|
+
export interface MailPermissionIds {
|
|
8
|
+
/** Full recipient details of the send history, and reading the suppression list. */
|
|
9
|
+
activityRead: string;
|
|
10
|
+
/** The host's status permission: the masked tier of the history. */
|
|
11
|
+
status: string;
|
|
12
|
+
/** Removing an address from the do-not-send list (a holder must also be the owner). */
|
|
13
|
+
suppressionsManage: string;
|
|
14
|
+
}
|
|
15
|
+
export interface MailActivityDeps {
|
|
16
|
+
workspaceId: string;
|
|
17
|
+
authorize: AuthorizeFn;
|
|
18
|
+
permissions: MailPermissionIds;
|
|
19
|
+
/** Absent in hermetic roots: every read refuses with {@link MailActivityUnavailableError}. */
|
|
20
|
+
mailActivity?: MailActivityRepo;
|
|
21
|
+
}
|
|
22
|
+
export interface MailActivityQuery {
|
|
23
|
+
limit: number;
|
|
24
|
+
before?: MailActivityPosition;
|
|
25
|
+
filter: MailActivityFilter;
|
|
26
|
+
}
|
|
27
|
+
export interface MailActivityItem {
|
|
28
|
+
/** Opaque; present only with full access. Pass it back to read one send (see {@link readMailActivityId}). */
|
|
29
|
+
id?: string;
|
|
30
|
+
recipient: string;
|
|
31
|
+
originalRecipient?: string;
|
|
32
|
+
deliveryMode?: "redirect" | "capture";
|
|
33
|
+
use: MailActivityRecord["use"];
|
|
34
|
+
outcome: MailActivityRecord["outcome"];
|
|
35
|
+
lane: MailActivityRecord["lane"];
|
|
36
|
+
providerId: string;
|
|
37
|
+
providerMessageId?: string | null;
|
|
38
|
+
errorCode: string | null;
|
|
39
|
+
/** Full access only: provider diagnostics can contain recipient addresses. */
|
|
40
|
+
message?: string | null;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
}
|
|
44
|
+
export interface MailActivityPage {
|
|
45
|
+
access: MailActivityAccess;
|
|
46
|
+
items: MailActivityItem[];
|
|
47
|
+
nextCursor: string | null;
|
|
48
|
+
/** First page with no rows: nothing was ever recorded, or nothing matches the filters. */
|
|
49
|
+
empty: "none_recorded" | "no_matches" | null;
|
|
50
|
+
}
|
|
51
|
+
/** The permission refusal both adapters translate (403 / the model-facing forbidden rule). */
|
|
52
|
+
export declare class MailActivityForbiddenError extends Error {
|
|
53
|
+
readonly permission: string;
|
|
54
|
+
constructor(required: {
|
|
55
|
+
permission: string;
|
|
56
|
+
message: string;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export declare class MailActivityUnavailableError extends Error {
|
|
60
|
+
constructor();
|
|
61
|
+
}
|
|
62
|
+
/** `a***@example.com`: enough to tell two addresses apart at a glance, not to recover one. */
|
|
63
|
+
export declare function maskRecipient({ address }: {
|
|
64
|
+
address: string;
|
|
65
|
+
}, _options?: Record<string, never>): string;
|
|
66
|
+
/** A page size from a tool argument or a query string; shared with the suppression list. */
|
|
67
|
+
export declare function readMailPageLimit({ value }: {
|
|
68
|
+
value: unknown;
|
|
69
|
+
}, _options?: {}): number;
|
|
70
|
+
/** A keyset position from a `nextCursor` this server returned; shared with the suppression list. */
|
|
71
|
+
export declare function readMailCursor({ value }: {
|
|
72
|
+
value: unknown;
|
|
73
|
+
}, _options?: {}): MailActivityPosition | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Parses list input from a tool's arguments or a route's query string (same field names).
|
|
76
|
+
* @throws {ToolInputError} For any malformed field; nothing is read.
|
|
77
|
+
*/
|
|
78
|
+
export declare function readMailActivityQuery({ input }: {
|
|
79
|
+
input: Record<string, unknown>;
|
|
80
|
+
}, _options?: Record<string, never>): MailActivityQuery;
|
|
81
|
+
/**
|
|
82
|
+
* Full with the activity-read permission, masked with only the status permission, else refused.
|
|
83
|
+
* @throws {MailActivityForbiddenError} Holding neither (or, with `requireFull`, lacking the first).
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolveMailActivityAccess(required: {
|
|
86
|
+
deps: Pick<MailActivityDeps, "authorize" | "workspaceId" | "permissions">;
|
|
87
|
+
principalId: string;
|
|
88
|
+
}, optional?: {
|
|
89
|
+
requireFull?: boolean;
|
|
90
|
+
}): Promise<MailActivityAccess>;
|
|
91
|
+
/** The next page's opaque cursor: the page's last timestamp, skipping every row already shown at it.
|
|
92
|
+
* Shared with the suppression list, whose rows page the same way. */
|
|
93
|
+
export declare function nextMailCursor({ page }: {
|
|
94
|
+
page: readonly {
|
|
95
|
+
createdAt: string;
|
|
96
|
+
cursorKey?: string;
|
|
97
|
+
revision?: string;
|
|
98
|
+
}[];
|
|
99
|
+
}, _options?: {}): string;
|
|
100
|
+
/**
|
|
101
|
+
* One page, newest first. Reads `limit + 1` rows to know whether a next page exists.
|
|
102
|
+
* @throws {MailActivityForbiddenError} Without access, or a recipient filter without full access.
|
|
103
|
+
* @complexity One ledger page read.
|
|
104
|
+
* @example listMailActivity({ principalId, query: readMailActivityQuery({ input: {} }) }, deps)
|
|
105
|
+
*/
|
|
106
|
+
export declare function listMailActivity(required: {
|
|
107
|
+
principalId: string;
|
|
108
|
+
query: MailActivityQuery;
|
|
109
|
+
deps: MailActivityDeps;
|
|
110
|
+
}, _options?: Record<string, never>): Promise<MailActivityPage>;
|
|
111
|
+
/** Parses an activity id from a listed item. @throws {ToolInputError} When it is not one. */
|
|
112
|
+
export declare function readMailActivityId({ value }: {
|
|
113
|
+
value: unknown;
|
|
114
|
+
}, _options?: Record<string, never>): {
|
|
115
|
+
idempotencyKey: string;
|
|
116
|
+
recipient: string;
|
|
117
|
+
};
|
|
118
|
+
export interface MailActivityDetail {
|
|
119
|
+
activity: MailActivityItem;
|
|
120
|
+
/** Provider feedback for this message, oldest first; empty means none received yet, not delivered. */
|
|
121
|
+
feedback: MailFeedbackRecord[];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* One send with its feedback timeline. Full access only.
|
|
125
|
+
* @returns `null` when no such send exists in this workspace.
|
|
126
|
+
* @complexity One ledger row and one feedback read.
|
|
127
|
+
*/
|
|
128
|
+
export declare function getMailActivity(required: {
|
|
129
|
+
principalId: string;
|
|
130
|
+
activityId: {
|
|
131
|
+
idempotencyKey: string;
|
|
132
|
+
recipient: string;
|
|
133
|
+
};
|
|
134
|
+
deps: MailActivityDeps;
|
|
135
|
+
}, _options?: Record<string, never>): Promise<MailActivityDetail | null>;
|
|
136
|
+
//# sourceMappingURL=activity.d.ts.map
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The one mail activity operation behind a host's list/get tools and admin routes: input
|
|
3
|
+
* parsing, the two-tier access rule, masking, opaque ids and cursors over a {@link MailActivityRepo}.
|
|
4
|
+
*
|
|
5
|
+
* Access: the activity-read permission sees full recipients, ids and message ids; a holder of only
|
|
6
|
+
* the status permission sees the same outcomes with masked recipients and no id, so they can read
|
|
7
|
+
* the health of sending without learning who was mailed. A recipient filter is a lookup by address,
|
|
8
|
+
* so it needs full access too. Neither tier ever sees a body, subject or sign-in link: the ledger
|
|
9
|
+
* stores none. The permission ids are the host's ({@link MailPermissionIds}); nothing here names one.
|
|
10
|
+
*
|
|
11
|
+
* Cursors carry only a timestamp and a skip count, never a key or an address, so a masked page's
|
|
12
|
+
* cursor discloses nothing its rows did not.
|
|
13
|
+
*/
|
|
14
|
+
import { ToolInputError } from "@jini-ai/core";
|
|
15
|
+
import { MAIL_ACTIVITY_OUTCOMES, MAIL_ACTIVITY_USES } from "./vocabulary.js";
|
|
16
|
+
export const DEFAULT_MAIL_ACTIVITY_LIMIT = 25;
|
|
17
|
+
export const MAX_MAIL_ACTIVITY_LIMIT = 100;
|
|
18
|
+
/** The permission refusal both adapters translate (403 / the model-facing forbidden rule). */
|
|
19
|
+
export class MailActivityForbiddenError extends Error {
|
|
20
|
+
permission;
|
|
21
|
+
constructor(required) {
|
|
22
|
+
super(required.message);
|
|
23
|
+
this.name = "MailActivityForbiddenError";
|
|
24
|
+
this.permission = required.permission;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class MailActivityUnavailableError extends Error {
|
|
28
|
+
constructor() {
|
|
29
|
+
super("Email activity is unavailable on this server.");
|
|
30
|
+
this.name = "MailActivityUnavailableError";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const encode = ({ value }, _optional = {}) => Buffer.from(JSON.stringify(value), "utf8").toString("base64url");
|
|
34
|
+
function decode({ value }, _options = {}) {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** `a***@example.com`: enough to tell two addresses apart at a glance, not to recover one. */
|
|
43
|
+
export function maskRecipient({ address }, _options = {}) {
|
|
44
|
+
const at = address.lastIndexOf("@");
|
|
45
|
+
if (at <= 0)
|
|
46
|
+
return "***";
|
|
47
|
+
return `${address[0]}***${address.slice(at)}`;
|
|
48
|
+
}
|
|
49
|
+
function oneOf(required, _options = {}) {
|
|
50
|
+
if (required.value === undefined || required.value === "")
|
|
51
|
+
return undefined;
|
|
52
|
+
if (typeof required.value === "string" && required.allowed.includes(required.value))
|
|
53
|
+
return required.value;
|
|
54
|
+
throw new ToolInputError({ message: `${required.field} must be one of ${required.allowed.join(", ")}.` });
|
|
55
|
+
}
|
|
56
|
+
/** A page size from a tool argument or a query string; shared with the suppression list. */
|
|
57
|
+
export function readMailPageLimit({ value }, _options = {}) {
|
|
58
|
+
if (value === undefined || value === "")
|
|
59
|
+
return DEFAULT_MAIL_ACTIVITY_LIMIT;
|
|
60
|
+
const limit = typeof value === "string" ? Number(value) : value;
|
|
61
|
+
if (typeof limit === "number" && Number.isInteger(limit) && limit >= 1 && limit <= MAX_MAIL_ACTIVITY_LIMIT)
|
|
62
|
+
return limit;
|
|
63
|
+
throw new ToolInputError({ message: `limit must be a whole number from 1 to ${MAX_MAIL_ACTIVITY_LIMIT}.` });
|
|
64
|
+
}
|
|
65
|
+
/** A keyset position from a `nextCursor` this server returned; shared with the suppression list. */
|
|
66
|
+
export function readMailCursor({ value }, _options = {}) {
|
|
67
|
+
if (value === undefined || value === "")
|
|
68
|
+
return undefined;
|
|
69
|
+
const decoded = typeof value === "string" ? decode({ value: value }) : undefined;
|
|
70
|
+
if (decoded && typeof decoded.c === "string" && typeof decoded.k === "string" && decoded.k.length > 0)
|
|
71
|
+
return { createdAt: decoded.c, key: decoded.k };
|
|
72
|
+
throw new ToolInputError({ message: "cursor is not a nextCursor this server returned." });
|
|
73
|
+
}
|
|
74
|
+
function readRecipient({ value }, _options = {}) {
|
|
75
|
+
if (value === undefined || value === "")
|
|
76
|
+
return undefined;
|
|
77
|
+
if (typeof value === "string" && value.length <= 254 && value.includes("@"))
|
|
78
|
+
return value.trim().toLowerCase();
|
|
79
|
+
throw new ToolInputError({ message: "recipient must be one email address." });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Parses list input from a tool's arguments or a route's query string (same field names).
|
|
83
|
+
* @throws {ToolInputError} For any malformed field; nothing is read.
|
|
84
|
+
*/
|
|
85
|
+
export function readMailActivityQuery({ input }, _options = {}) {
|
|
86
|
+
const outcome = oneOf({ value: input.outcome, allowed: MAIL_ACTIVITY_OUTCOMES, field: "outcome" });
|
|
87
|
+
const use = oneOf({ value: input.use, allowed: MAIL_ACTIVITY_USES, field: "use" });
|
|
88
|
+
const recipient = readRecipient({ value: input.recipient });
|
|
89
|
+
const before = readMailCursor({ value: input.cursor });
|
|
90
|
+
return {
|
|
91
|
+
limit: readMailPageLimit({ value: input.limit }),
|
|
92
|
+
...(before ? { before } : {}),
|
|
93
|
+
filter: { ...(outcome ? { outcome } : {}), ...(use ? { use } : {}), ...(recipient ? { recipient } : {}) },
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Full with the activity-read permission, masked with only the status permission, else refused.
|
|
98
|
+
* @throws {MailActivityForbiddenError} Holding neither (or, with `requireFull`, lacking the first).
|
|
99
|
+
*/
|
|
100
|
+
export async function resolveMailActivityAccess(required, optional = {}) {
|
|
101
|
+
const ask = ({ permission }, _optional = {}) => required.deps.authorize({ principalId: required.principalId, permission, workspaceId: required.deps.workspaceId, entityType: "mail" });
|
|
102
|
+
const { activityRead, status } = required.deps.permissions;
|
|
103
|
+
if ((await ask({ permission: activityRead })).allowed)
|
|
104
|
+
return "full";
|
|
105
|
+
if (!optional.requireFull && (await ask({ permission: status })).allowed)
|
|
106
|
+
return "masked";
|
|
107
|
+
const permission = optional.requireFull ? activityRead : `${activityRead} or ${status}`;
|
|
108
|
+
throw new MailActivityForbiddenError({ permission, message: `principal '${required.principalId}' is not authorized for '${permission}'` });
|
|
109
|
+
}
|
|
110
|
+
function toItem({ record, access }, _options = {}) {
|
|
111
|
+
const base = { use: record.use, outcome: record.outcome, lane: record.lane, providerId: record.providerId, errorCode: record.errorCode, createdAt: record.createdAt, updatedAt: record.updatedAt };
|
|
112
|
+
if (access === "masked")
|
|
113
|
+
return { recipient: maskRecipient({ address: record.recipient }), ...base };
|
|
114
|
+
return { id: encode({ value: [record.idempotencyKey, record.recipient] }), recipient: record.recipient, ...(record.deliveryMode ? { deliveryMode: record.deliveryMode, originalRecipient: record.originalRecipient } : {}), providerMessageId: record.providerMessageId, message: record.message, ...base };
|
|
115
|
+
}
|
|
116
|
+
/** The next page's opaque cursor: the page's last timestamp, skipping every row already shown at it.
|
|
117
|
+
* Shared with the suppression list, whose rows page the same way. */
|
|
118
|
+
export function nextMailCursor({ page }, _options = {}) {
|
|
119
|
+
const last = page.at(-1);
|
|
120
|
+
if (last === undefined)
|
|
121
|
+
throw new Error('Mail activity page has no last row for its cursor');
|
|
122
|
+
return encode({ value: { c: last.createdAt, k: last.cursorKey ?? last.revision } });
|
|
123
|
+
}
|
|
124
|
+
function repo(deps, _options = {}) {
|
|
125
|
+
if (!deps.mailActivity)
|
|
126
|
+
throw new MailActivityUnavailableError();
|
|
127
|
+
return deps.mailActivity;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* One page, newest first. Reads `limit + 1` rows to know whether a next page exists.
|
|
131
|
+
* @throws {MailActivityForbiddenError} Without access, or a recipient filter without full access.
|
|
132
|
+
* @complexity One ledger page read.
|
|
133
|
+
* @example listMailActivity({ principalId, query: readMailActivityQuery({ input: {} }) }, deps)
|
|
134
|
+
*/
|
|
135
|
+
export async function listMailActivity(required, _options = {}) {
|
|
136
|
+
const { deps } = required;
|
|
137
|
+
const { query } = required;
|
|
138
|
+
const access = await resolveMailActivityAccess({ deps, principalId: required.principalId }, { requireFull: query.filter.recipient !== undefined });
|
|
139
|
+
const rows = await repo(deps).list({ workspaceId: deps.workspaceId, limit: query.limit + 1 }, { ...query.filter, ...(query.before ? { before: query.before } : {}) });
|
|
140
|
+
const page = rows.slice(0, query.limit);
|
|
141
|
+
const filtered = Object.keys(query.filter).length > 0;
|
|
142
|
+
const emptyReason = filtered ? "no_matches" : "none_recorded";
|
|
143
|
+
return {
|
|
144
|
+
access,
|
|
145
|
+
items: page.map((row) => toItem({ record: row, access })),
|
|
146
|
+
nextCursor: rows.length > query.limit ? nextMailCursor({ page }) : null,
|
|
147
|
+
empty: page.length > 0 || query.before ? null : emptyReason,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/** The id encodes exactly `[idempotencyKey, recipient]`; any other shape is not one of ours. */
|
|
151
|
+
function isStringPair(value) {
|
|
152
|
+
return Array.isArray(value) && value.length === 2 && value.every((part) => typeof part === "string");
|
|
153
|
+
}
|
|
154
|
+
/** Parses an activity id from a listed item. @throws {ToolInputError} When it is not one. */
|
|
155
|
+
export function readMailActivityId({ value }, _options = {}) {
|
|
156
|
+
const decoded = typeof value === "string" && value !== "" ? decode({ value: value }) : undefined;
|
|
157
|
+
if (isStringPair(decoded))
|
|
158
|
+
return { idempotencyKey: decoded[0], recipient: decoded[1] };
|
|
159
|
+
throw new ToolInputError({ message: "activityId must be an id from mail_list_activity." });
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* One send with its feedback timeline. Full access only.
|
|
163
|
+
* @returns `null` when no such send exists in this workspace.
|
|
164
|
+
* @complexity One ledger row and one feedback read.
|
|
165
|
+
*/
|
|
166
|
+
export async function getMailActivity(required, _options = {}) {
|
|
167
|
+
const { deps } = required;
|
|
168
|
+
await resolveMailActivityAccess({ deps, principalId: required.principalId }, { requireFull: true });
|
|
169
|
+
const found = await repo(deps).get({ workspaceId: deps.workspaceId, ...required.activityId });
|
|
170
|
+
return found ? { activity: toItem({ record: found.record, access: "full" }), feedback: found.feedback } : null;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=activity.js.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { MailSuppressionScope } from "../ports.js";
|
|
2
|
+
import type { MailActivityOutcome, MailActivityUse } from "./vocabulary.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file The record and port types of the mail activity ledger and the suppression admin list, as
|
|
5
|
+
* the activity operations consume them. Types only: a host's SQL repos implement these ports.
|
|
6
|
+
*/
|
|
7
|
+
export interface MailActivityRecord {
|
|
8
|
+
cursorKey: string;
|
|
9
|
+
originalRecipient?: string;
|
|
10
|
+
deliveryMode?: "redirect" | "capture";
|
|
11
|
+
idempotencyKey: string;
|
|
12
|
+
recipient: string;
|
|
13
|
+
lane: "transactional" | "bulk";
|
|
14
|
+
providerId: string;
|
|
15
|
+
use: MailActivityUse;
|
|
16
|
+
outcome: MailActivityOutcome;
|
|
17
|
+
providerMessageId: string | null;
|
|
18
|
+
errorCode: string | null;
|
|
19
|
+
message: string | null;
|
|
20
|
+
createdAt: string;
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
}
|
|
23
|
+
export interface MailFeedbackRecord {
|
|
24
|
+
kind: "delivered" | "bounced" | "complained";
|
|
25
|
+
hardBounce: boolean;
|
|
26
|
+
providerId: string;
|
|
27
|
+
occurredAt: string;
|
|
28
|
+
receivedAt: string;
|
|
29
|
+
}
|
|
30
|
+
/** Keyset position: rows at or before `createdAt`, skipping the `skip` already returned at exactly that time. */
|
|
31
|
+
export interface MailActivityPosition {
|
|
32
|
+
createdAt: string;
|
|
33
|
+
key: string;
|
|
34
|
+
}
|
|
35
|
+
export interface MailActivityFilter {
|
|
36
|
+
outcome?: MailActivityOutcome;
|
|
37
|
+
use?: MailActivityUse;
|
|
38
|
+
/** Exact address, compared lowercased as the ledger stores it. */
|
|
39
|
+
recipient?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface MailActivityRepo {
|
|
42
|
+
list(required: {
|
|
43
|
+
workspaceId: string;
|
|
44
|
+
limit: number;
|
|
45
|
+
}, optional?: MailActivityFilter & {
|
|
46
|
+
before?: MailActivityPosition;
|
|
47
|
+
}): Promise<MailActivityRecord[]>;
|
|
48
|
+
get(required: {
|
|
49
|
+
workspaceId: string;
|
|
50
|
+
idempotencyKey: string;
|
|
51
|
+
recipient: string;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
record: MailActivityRecord;
|
|
54
|
+
feedback: MailFeedbackRecord[];
|
|
55
|
+
} | null>;
|
|
56
|
+
}
|
|
57
|
+
export type MailSuppressionReason = "bounced" | "complained" | "manual";
|
|
58
|
+
export interface MailSuppressionEntry {
|
|
59
|
+
address: string;
|
|
60
|
+
scope: MailSuppressionScope;
|
|
61
|
+
reason: MailSuppressionReason;
|
|
62
|
+
createdAt: string;
|
|
63
|
+
revision: string;
|
|
64
|
+
}
|
|
65
|
+
export interface MailSuppressionRemoval {
|
|
66
|
+
id: string;
|
|
67
|
+
address: string;
|
|
68
|
+
scope: MailSuppressionScope;
|
|
69
|
+
suppressionReason: MailSuppressionReason;
|
|
70
|
+
suppressedAt: string;
|
|
71
|
+
removalReason: string;
|
|
72
|
+
removedBy: string;
|
|
73
|
+
removedAt: string;
|
|
74
|
+
}
|
|
75
|
+
export interface MailSuppressionListFilter {
|
|
76
|
+
/** Substring of the address, matched lowercased; `%` and `_` are literal. */
|
|
77
|
+
search?: string;
|
|
78
|
+
scope?: MailSuppressionScope;
|
|
79
|
+
reason?: MailSuppressionReason;
|
|
80
|
+
before?: {
|
|
81
|
+
createdAt: string;
|
|
82
|
+
key: string;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export interface MailSuppressionAdminRepo {
|
|
86
|
+
list(required: {
|
|
87
|
+
workspaceId: string;
|
|
88
|
+
limit: number;
|
|
89
|
+
}, optional?: MailSuppressionListFilter): Promise<MailSuppressionEntry[]>;
|
|
90
|
+
find(required: {
|
|
91
|
+
workspaceId: string;
|
|
92
|
+
address: string;
|
|
93
|
+
scope: MailSuppressionScope;
|
|
94
|
+
}): Promise<MailSuppressionEntry | null>;
|
|
95
|
+
/** Deletes the suppression and records the removal atomically; `null` when it was not suppressed. */
|
|
96
|
+
remove(required: {
|
|
97
|
+
workspaceId: string;
|
|
98
|
+
address: string;
|
|
99
|
+
scope: MailSuppressionScope;
|
|
100
|
+
removalReason: string;
|
|
101
|
+
removedBy: string;
|
|
102
|
+
revision: string;
|
|
103
|
+
}): Promise<MailSuppressionRemoval | null>;
|
|
104
|
+
/** The newest verified webhook event for a provider; only verified events are ever recorded. */
|
|
105
|
+
lastFeedbackEvent(required: {
|
|
106
|
+
workspaceId: string;
|
|
107
|
+
providerId: string;
|
|
108
|
+
}): Promise<{
|
|
109
|
+
kind: "delivered" | "bounced" | "complained";
|
|
110
|
+
receivedAt: string;
|
|
111
|
+
} | null>;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { MailSuppressionScope } from "../ports.js";
|
|
2
|
+
import type { AuthorizeFn } from "@jini-ai/core/contracts/events";
|
|
3
|
+
import type { MailActivityPosition, MailSuppressionAdminRepo, MailSuppressionEntry, MailSuppressionReason, MailSuppressionRemoval } from "./ports.js";
|
|
4
|
+
import { type MailPermissionIds } from "./activity.js";
|
|
5
|
+
export interface MailSuppressionDeps {
|
|
6
|
+
workspaceId: string;
|
|
7
|
+
authorize: AuthorizeFn;
|
|
8
|
+
permissions: MailPermissionIds;
|
|
9
|
+
ownerPrincipalId?: Promise<string>;
|
|
10
|
+
/** Absent in hermetic roots: every call refuses with {@link MailSuppressionsUnavailableError}. */
|
|
11
|
+
mailSuppressionAdmin?: MailSuppressionAdminRepo;
|
|
12
|
+
}
|
|
13
|
+
export declare class MailSuppressionsUnavailableError extends Error {
|
|
14
|
+
constructor();
|
|
15
|
+
}
|
|
16
|
+
export interface MailSuppressionQuery {
|
|
17
|
+
limit: number;
|
|
18
|
+
before?: MailActivityPosition;
|
|
19
|
+
filter: {
|
|
20
|
+
search?: string;
|
|
21
|
+
scope?: MailSuppressionScope;
|
|
22
|
+
reason?: MailSuppressionReason;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface MailSuppressionPage {
|
|
26
|
+
items: MailSuppressionEntry[];
|
|
27
|
+
nextCursor: string | null;
|
|
28
|
+
empty: "none_recorded" | "no_matches" | null;
|
|
29
|
+
}
|
|
30
|
+
/** Parses list input from a tool's arguments or a route's query string. @throws {ToolInputError} */
|
|
31
|
+
export declare function readMailSuppressionQuery({ input }: {
|
|
32
|
+
input: Record<string, unknown>;
|
|
33
|
+
}, _options?: Record<string, never>): MailSuppressionQuery;
|
|
34
|
+
/**
|
|
35
|
+
* One page of blocked recipients, newest first: address, scope, reason and time.
|
|
36
|
+
* @throws {MailActivityForbiddenError} Without the activity-read permission.
|
|
37
|
+
* @complexity One indexed page read.
|
|
38
|
+
*/
|
|
39
|
+
export declare function listMailSuppressions(required: {
|
|
40
|
+
principalId: string;
|
|
41
|
+
query: MailSuppressionQuery;
|
|
42
|
+
deps: MailSuppressionDeps;
|
|
43
|
+
}, _options?: Record<string, never>): Promise<MailSuppressionPage>;
|
|
44
|
+
export interface MailSuppressionRemovalInput {
|
|
45
|
+
address: string;
|
|
46
|
+
scope: MailSuppressionScope;
|
|
47
|
+
reason: string;
|
|
48
|
+
}
|
|
49
|
+
/** Address, scope and the required reason. @throws {ToolInputError} Nothing is changed. */
|
|
50
|
+
export declare function readMailSuppressionRemoval({ input }: {
|
|
51
|
+
input: Record<string, unknown>;
|
|
52
|
+
}, _options?: Record<string, never>): MailSuppressionRemovalInput;
|
|
53
|
+
export interface MailSuppressionRemovalPlan extends MailSuppressionRemovalInput {
|
|
54
|
+
suppressionReason: MailSuppressionReason;
|
|
55
|
+
suppressedAt: string;
|
|
56
|
+
revision: string;
|
|
57
|
+
/** What removal does and does not mean, shown before the person confirms. */
|
|
58
|
+
warnings: string[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Checks the permission and that the suppression exists, and describes the removal.
|
|
62
|
+
* @throws {MailActivityForbiddenError} Without the suppressions-manage permission, or when the principal is not the owner.
|
|
63
|
+
* @throws {ToolInputError} When the address is not suppressed in that scope.
|
|
64
|
+
*/
|
|
65
|
+
export declare function planMailSuppressionRemoval(required: {
|
|
66
|
+
principalId: string;
|
|
67
|
+
input: MailSuppressionRemovalInput;
|
|
68
|
+
deps: MailSuppressionDeps;
|
|
69
|
+
}, _options?: Record<string, never>): Promise<MailSuppressionRemovalPlan>;
|
|
70
|
+
/**
|
|
71
|
+
* Removes it, re-checking the permission at the moment of the write, and records the audit row.
|
|
72
|
+
* @returns `removed: false` when it was already removed meanwhile.
|
|
73
|
+
*/
|
|
74
|
+
export declare function runMailSuppressionRemoval(required: {
|
|
75
|
+
principalId: string;
|
|
76
|
+
plan: MailSuppressionRemovalPlan;
|
|
77
|
+
deps: MailSuppressionDeps;
|
|
78
|
+
}, _options?: Record<string, never>): Promise<{
|
|
79
|
+
removed: boolean;
|
|
80
|
+
removal?: MailSuppressionRemoval;
|
|
81
|
+
}>;
|
|
82
|
+
//# sourceMappingURL=suppressions.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The suppression operations behind a host's list/remove tools and admin routes.
|
|
3
|
+
*
|
|
4
|
+
* Reading the list needs the activity-read permission: it is a list of addresses, the same
|
|
5
|
+
* recipient detail the activity history guards. Removal needs the suppressions-manage permission
|
|
6
|
+
* AND the owner gate (holding the grant alone is not enough: `principalId` must equal the owner the
|
|
7
|
+
* host passes, and an absent owner refuses everyone), a written reason that is recorded with the
|
|
8
|
+
* removal, and a fresh confirmation every time, which is the host's to ask for. Removal stops the
|
|
9
|
+
* do-not-send block and nothing else: it never subscribes anyone or restores newsletter consent,
|
|
10
|
+
* and the plan says so before the person confirms.
|
|
11
|
+
*/
|
|
12
|
+
import { ToolInputError } from "@jini-ai/core";
|
|
13
|
+
import { MailActivityForbiddenError, nextMailCursor, readMailCursor, readMailPageLimit } from "./activity.js";
|
|
14
|
+
export class MailSuppressionsUnavailableError extends Error {
|
|
15
|
+
constructor() {
|
|
16
|
+
super("The suppression list is unavailable on this server. Nothing was changed.");
|
|
17
|
+
this.name = "MailSuppressionsUnavailableError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const SCOPES = ["all", "bulk"];
|
|
21
|
+
const REASONS = ["bounced", "complained", "manual"];
|
|
22
|
+
const MIN_REASON = 3;
|
|
23
|
+
const MAX_REASON = 500;
|
|
24
|
+
function pick(required, _options = {}) {
|
|
25
|
+
if (required.optional && (required.value === undefined || required.value === ""))
|
|
26
|
+
return undefined;
|
|
27
|
+
if (typeof required.value === "string" && required.allowed.includes(required.value))
|
|
28
|
+
return required.value;
|
|
29
|
+
throw new ToolInputError({ message: `${required.field} must be one of ${required.allowed.join(", ")}.` });
|
|
30
|
+
}
|
|
31
|
+
function readSearch({ value }, _options = {}) {
|
|
32
|
+
if (value === undefined || value === "")
|
|
33
|
+
return undefined;
|
|
34
|
+
if (typeof value === "string" && value.trim().length <= 254)
|
|
35
|
+
return value.trim() || undefined;
|
|
36
|
+
throw new ToolInputError({ message: "search must be text of at most 254 characters." });
|
|
37
|
+
}
|
|
38
|
+
/** Parses list input from a tool's arguments or a route's query string. @throws {ToolInputError} */
|
|
39
|
+
export function readMailSuppressionQuery({ input }, _options = {}) {
|
|
40
|
+
const scope = pick({ value: input.scope, allowed: SCOPES, field: "scope", optional: true });
|
|
41
|
+
const reason = pick({ value: input.reason, allowed: REASONS, field: "reason", optional: true });
|
|
42
|
+
const search = readSearch({ value: input.search });
|
|
43
|
+
const before = readMailCursor({ value: input.cursor });
|
|
44
|
+
return { limit: readMailPageLimit({ value: input.limit }), ...(before ? { before } : {}), filter: { ...(search ? { search } : {}), ...(scope ? { scope } : {}), ...(reason ? { reason } : {}) } };
|
|
45
|
+
}
|
|
46
|
+
async function authorizedRepo({ deps, principalId, permission }, _options = {}) {
|
|
47
|
+
const auth = await deps.authorize({ principalId, permission, workspaceId: deps.workspaceId, entityType: "mail" });
|
|
48
|
+
if (!auth.allowed)
|
|
49
|
+
throw new MailActivityForbiddenError({ permission, message: `principal '${principalId}' is not authorized for '${permission}'` });
|
|
50
|
+
if (permission === deps.permissions.suppressionsManage && principalId !== await deps.ownerPrincipalId) {
|
|
51
|
+
throw new MailActivityForbiddenError({ permission, message: "Only the site owner may remove a suppression." });
|
|
52
|
+
}
|
|
53
|
+
if (!deps.mailSuppressionAdmin)
|
|
54
|
+
throw new MailSuppressionsUnavailableError();
|
|
55
|
+
return deps.mailSuppressionAdmin;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* One page of blocked recipients, newest first: address, scope, reason and time.
|
|
59
|
+
* @throws {MailActivityForbiddenError} Without the activity-read permission.
|
|
60
|
+
* @complexity One indexed page read.
|
|
61
|
+
*/
|
|
62
|
+
export async function listMailSuppressions(required, _options = {}) {
|
|
63
|
+
const { deps } = required;
|
|
64
|
+
const { query } = required;
|
|
65
|
+
const repo = await authorizedRepo({ deps: deps, principalId: required.principalId, permission: deps.permissions.activityRead });
|
|
66
|
+
const rows = await repo.list({ workspaceId: deps.workspaceId, limit: query.limit + 1 }, { ...query.filter, ...(query.before ? { before: query.before } : {}) });
|
|
67
|
+
const items = rows.slice(0, query.limit);
|
|
68
|
+
const filtered = Object.keys(query.filter).length > 0;
|
|
69
|
+
const emptyReason = filtered ? "no_matches" : "none_recorded";
|
|
70
|
+
return {
|
|
71
|
+
items,
|
|
72
|
+
nextCursor: rows.length > query.limit ? nextMailCursor({ page: items }) : null,
|
|
73
|
+
empty: items.length > 0 || query.before ? null : emptyReason,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Address, scope and the required reason. @throws {ToolInputError} Nothing is changed. */
|
|
77
|
+
export function readMailSuppressionRemoval({ input }, _options = {}) {
|
|
78
|
+
const address = typeof input.address === "string" ? input.address.trim().toLowerCase() : "";
|
|
79
|
+
if (!address.includes("@") || address.length > 254)
|
|
80
|
+
throw new ToolInputError({ message: "address must be the suppressed email address. Nothing was changed." });
|
|
81
|
+
const scope = pick({ value: input.scope, allowed: SCOPES, field: "scope", optional: false });
|
|
82
|
+
const reason = typeof input.reason === "string" ? input.reason.trim() : "";
|
|
83
|
+
if (reason.length < MIN_REASON || reason.length > MAX_REASON) {
|
|
84
|
+
throw new ToolInputError({ message: `reason is required: say why this address may be mailed again (${MIN_REASON}-${MAX_REASON} characters). It is recorded. Nothing was changed.` });
|
|
85
|
+
}
|
|
86
|
+
return { address, scope, reason };
|
|
87
|
+
}
|
|
88
|
+
const NO_CONSENT = "Removal only lifts the do-not-send block. It does not subscribe this address or restore newsletter consent.";
|
|
89
|
+
const WARNINGS = {
|
|
90
|
+
bounced: "This address hard-bounced: the mailbox may not exist. Mailing it again can hurt the site's sender reputation.",
|
|
91
|
+
complained: "This person marked the site's mail as spam. Mailing them again without fresh consent risks further complaints.",
|
|
92
|
+
manual: undefined,
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Checks the permission and that the suppression exists, and describes the removal.
|
|
96
|
+
* @throws {MailActivityForbiddenError} Without the suppressions-manage permission, or when the principal is not the owner.
|
|
97
|
+
* @throws {ToolInputError} When the address is not suppressed in that scope.
|
|
98
|
+
*/
|
|
99
|
+
export async function planMailSuppressionRemoval(required, _options = {}) {
|
|
100
|
+
const { deps } = required;
|
|
101
|
+
const repo = await authorizedRepo({ deps: deps, principalId: required.principalId, permission: deps.permissions.suppressionsManage });
|
|
102
|
+
const entry = await repo.find({ workspaceId: deps.workspaceId, address: required.input.address, scope: required.input.scope });
|
|
103
|
+
if (!entry)
|
|
104
|
+
throw new ToolInputError({ message: `${required.input.address} is not suppressed for ${required.input.scope} mail. Nothing was changed.` });
|
|
105
|
+
const warning = WARNINGS[entry.reason];
|
|
106
|
+
return { ...required.input, suppressionReason: entry.reason, suppressedAt: entry.createdAt, revision: entry.revision, warnings: [...(warning ? [warning] : []), NO_CONSENT] };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Removes it, re-checking the permission at the moment of the write, and records the audit row.
|
|
110
|
+
* @returns `removed: false` when it was already removed meanwhile.
|
|
111
|
+
*/
|
|
112
|
+
export async function runMailSuppressionRemoval(required, _options = {}) {
|
|
113
|
+
const { deps } = required;
|
|
114
|
+
const repo = await authorizedRepo({ deps: deps, principalId: required.principalId, permission: deps.permissions.suppressionsManage });
|
|
115
|
+
const { address, scope, reason } = required.plan;
|
|
116
|
+
const removal = await repo.remove({ workspaceId: deps.workspaceId, address, scope, removalReason: reason, removedBy: required.principalId, revision: required.plan.revision });
|
|
117
|
+
return removal ? { removed: true, removal } : { removed: false };
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=suppressions.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The closed vocabularies of a mail activity ledger's derived columns: what happened to a
|
|
3
|
+
* send (`outcome`) and which owner sent it (`use`). They are runtime values because the activity
|
|
4
|
+
* operation validates caller input against them; a SQL repo only needs their types.
|
|
5
|
+
*/
|
|
6
|
+
export declare const MAIL_ACTIVITY_OUTCOMES: readonly ["accepted", "delivered", "bounced", "complained", "suppressed", "deferred", "failed", "unknown", "captured"];
|
|
7
|
+
export type MailActivityOutcome = (typeof MAIL_ACTIVITY_OUTCOMES)[number];
|
|
8
|
+
export declare const MAIL_ACTIVITY_USES: readonly ["sign_in", "newsletter_confirmation", "form_notification", "newsletter", "test", "unknown"];
|
|
9
|
+
export type MailActivityUse = (typeof MAIL_ACTIVITY_USES)[number];
|
|
10
|
+
//# sourceMappingURL=vocabulary.d.ts.map
|