@jini-ai/platform 0.7.3-next.1 → 0.7.3-next.3
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 +6 -0
- package/README.md +13 -0
- package/dist/download-lock.d.ts +3 -1
- package/dist/download-lock.js +4 -4
- package/dist/download-maintenance.js +6 -6
- package/dist/download-state.js +17 -14
- package/dist/download-store.d.ts +34 -10
- package/dist/download-store.js +24 -20
- package/dist/download-target.d.ts +6 -2
- package/dist/download-target.js +7 -7
- package/dist/download-transfer.js +18 -12
- package/dist/download.js +4 -4
- package/dist/fetch-with-timeout.d.ts +0 -53
- package/dist/fetch-with-timeout.js +56 -6
- package/dist/fs/directory-running-lock.d.ts +4 -0
- package/dist/fs/directory-running-lock.js +8 -1
- package/dist/fs/directory-workspace.d.ts +2 -1
- package/dist/fs/directory-workspace.js +2 -2
- package/dist/fs/durable-json.d.ts +3 -16
- package/dist/fs/durable-json.js +4 -2
- package/dist/fs/guarded-reader.d.ts +10 -0
- package/dist/fs/guarded-reader.js +34 -1
- package/dist/fs/index.d.ts +4 -0
- package/dist/fs/index.js +4 -0
- package/dist/fs/leased-directory-move.d.ts +49 -0
- package/dist/fs/leased-directory-move.js +31 -0
- package/dist/fs/owned-temp-root.d.ts +74 -0
- package/dist/fs/owned-temp-root.js +203 -0
- package/dist/fs/recent-directories.d.ts +2 -1
- package/dist/fs/resolve-directory-target.d.ts +33 -0
- package/dist/fs/resolve-directory-target.js +58 -0
- package/dist/fs/staged-file.d.ts +40 -0
- package/dist/fs/staged-file.js +75 -0
- package/dist/fs/strict-containment.d.ts +14 -0
- package/dist/fs/strict-containment.js +14 -0
- package/dist/image/png-encode.d.ts +41 -0
- package/dist/image/png-encode.js +96 -0
- package/dist/index.d.ts +3 -1
- package/dist/mail/email-template-agent-tools.d.ts +150 -0
- package/dist/mail/email-template-agent-tools.js +86 -0
- package/dist/mail/email-template-tool-registrations.d.ts +73 -0
- package/dist/mail/email-template-tool-registrations.js +66 -0
- package/dist/mail/feedback-route.d.ts +50 -0
- package/dist/mail/feedback-route.js +46 -0
- package/dist/mail/feedback-setup.d.ts +44 -0
- package/dist/mail/feedback-setup.js +53 -0
- package/dist/mail/feedback-sources.d.ts +67 -0
- package/dist/mail/feedback-sources.js +42 -0
- package/dist/mail/index.d.ts +10 -1
- package/dist/mail/index.js +4 -0
- package/dist/mail/mail-status.d.ts +32 -0
- package/dist/mail/mail-status.js +2 -0
- package/dist/mail/positional-purpose-gate.d.ts +14 -0
- package/dist/mail/positional-purpose-gate.js +18 -0
- package/dist/mail/purpose-gate-probe.d.ts +18 -0
- package/dist/mail/purpose-gate-probe.js +22 -0
- package/dist/mail/resolve-mailer.d.ts +13 -1
- package/dist/mail/resolve-mailer.js +11 -5
- package/dist/mail/sql/activity.repo.d.ts +20 -0
- package/dist/mail/sql/activity.repo.js +133 -0
- package/dist/mail/sql/attempts.repo.d.ts +17 -0
- package/dist/mail/sql/attempts.repo.js +32 -0
- package/dist/mail/sql/capture.repo.d.ts +69 -0
- package/dist/mail/sql/capture.repo.js +119 -0
- package/dist/mail/sql/feedback-inbox.repo.d.ts +12 -0
- package/dist/mail/sql/feedback-inbox.repo.js +32 -0
- package/dist/mail/sql/index.d.ts +12 -0
- package/dist/mail/sql/index.js +12 -0
- package/dist/mail/sql/ledger.repo.d.ts +29 -0
- package/dist/mail/sql/ledger.repo.js +57 -0
- package/dist/mail/sql/retention.d.ts +23 -0
- package/dist/mail/sql/retention.js +53 -0
- package/dist/mail/sql/site-feedback-route.d.ts +18 -0
- package/dist/mail/sql/site-feedback-route.js +22 -0
- package/dist/mail/sql/suppression-admin.repo.d.ts +11 -0
- package/dist/mail/sql/suppression-admin.repo.js +76 -0
- package/dist/mail/sql/suppression.repo.d.ts +10 -0
- package/dist/mail/sql/suppression.repo.js +33 -0
- package/dist/mail/test-send.d.ts +147 -0
- package/dist/mail/test-send.js +201 -0
- package/dist/mail/use-readiness.d.ts +104 -0
- package/dist/mail/use-readiness.js +140 -0
- package/dist/object-store/local-fs.js +34 -1
- package/dist/object-store/site/artifact-provider.d.ts +65 -0
- package/dist/object-store/site/artifact-provider.js +37 -0
- package/dist/object-store/site/registry.d.ts +110 -0
- package/dist/object-store/site/registry.js +93 -0
- package/dist/object-store/site/setting.d.ts +34 -0
- package/dist/object-store/site/setting.js +32 -0
- package/dist/process-probes.d.ts +11 -4
- package/dist/process-probes.js +3 -3
- package/dist/process-top-footprint.d.ts +1 -1
- package/dist/process.d.ts +3 -17
- package/dist/process.js +3 -2
- package/dist/retention/index.d.ts +6 -0
- package/dist/retention/index.js +6 -0
- package/dist/retention/measure-tree.d.ts +68 -0
- package/dist/retention/measure-tree.js +205 -0
- package/dist/retention/preview-store.d.ts +10 -0
- package/dist/retention/preview-store.js +26 -0
- package/dist/retention/routes.d.ts +23 -0
- package/dist/retention/routes.js +24 -0
- package/dist/retention/runner.d.ts +103 -0
- package/dist/retention/runner.js +164 -0
- package/dist/secrets/credential-sets/index.d.ts +1 -0
- package/dist/secrets/credential-sets/index.js +1 -0
- package/dist/secrets/credential-sets/store-vault-guards.d.ts +26 -0
- package/dist/secrets/credential-sets/store-vault-guards.js +30 -0
- package/dist/secrets/credential-sets/vault.service.d.ts +1 -1
- package/dist/secrets/index.d.ts +1 -1
- package/dist/secrets/index.js +1 -1
- package/dist/secrets/keyring.env.d.ts +1 -1
- package/dist/secrets/keyring.env.js +3 -5
- package/dist/secrets/keyring.memory.d.ts +4 -1
- package/dist/secrets/keyring.memory.js +4 -1
- package/dist/secrets/legacy-codecs.d.ts +381 -0
- package/dist/secrets/legacy-codecs.js +468 -0
- package/dist/secrets/legacy-owner.d.ts +3 -11
- package/dist/secrets/root-key/ensure.d.ts +154 -0
- package/dist/secrets/root-key/ensure.js +328 -0
- package/dist/secrets/root-key/files.d.ts +104 -0
- package/dist/secrets/root-key/files.js +166 -0
- package/dist/secrets/root-key/material.d.ts +132 -0
- package/dist/secrets/root-key/material.js +116 -0
- package/dist/secrets/root-key/ordered-keyring.d.ts +157 -0
- package/dist/secrets/root-key/ordered-keyring.js +104 -0
- package/dist/secrets/root-key/reconcile.d.ts +50 -0
- package/dist/secrets/root-key/reconcile.js +147 -0
- package/dist/secrets/root-key/site-keyring-errors.d.ts +78 -0
- package/dist/secrets/root-key/site-keyring-errors.js +37 -0
- package/dist/secrets/root-key/sources.d.ts +79 -0
- package/dist/secrets/root-key/sources.js +119 -0
- package/dist/secrets/secret-sealer.aesgcm.d.ts +50 -2
- package/dist/secrets/secret-sealer.aesgcm.js +107 -19
- package/dist/web/tool-registrations.d.ts +67 -0
- package/dist/web/tool-registrations.js +44 -0
- package/package.json +139 -7
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file **What uses email** (email phase 4): one readiness row per use of the site's mail, built
|
|
3
|
+
* from the checks each owning feature already runs, never a second copy of them.
|
|
4
|
+
*
|
|
5
|
+
* | Use | Owner checks reused |
|
|
6
|
+
* |---|---|
|
|
7
|
+
* | Sign-in links | the members sender (`mailSenderIdentity`, as `members/write-service.ts` resolves it), Jini's purpose gate on the interactive lane |
|
|
8
|
+
* | Confirmations | Newsletter's `evaluateLaunchGate` test-send subset (origin, production mailer) that `confirmation.ts` needs, the sender, the interactive gate |
|
|
9
|
+
* | Form notifications | Forms' definitions (`notify.enabled` + recipients, as `@jini-ai/cms/forms`' subscriber reads them), the sender, the notification-lane gate |
|
|
10
|
+
* | Newsletter | `evaluateLaunchGate` in full, the sender, the notification-lane gate |
|
|
11
|
+
*
|
|
12
|
+
* The purpose gate is asked through `platform/mail/purpose-gate-probe.ts`, so the production
|
|
13
|
+
* `durableOutboxReady` gate is surfaced as a blocker exactly as it decides, and is not changed here.
|
|
14
|
+
*
|
|
15
|
+
* State per row: blocked > not_configured > disabled > ready, every reason kept. A check that
|
|
16
|
+
* throws makes only its own row `unknown`. Evidence (the last observed outcome, from the activity
|
|
17
|
+
* projection) is separate: a ready row with a bounced last send is both, and a failed evidence read
|
|
18
|
+
* leaves the state standing with `evidence: null`.
|
|
19
|
+
*/
|
|
20
|
+
import { type MailSenderIdentityPort } from "./sender-identity.js";
|
|
21
|
+
import type { FormDefinitionRepoPort } from "@jini-ai/core/contracts/site/cms-forms";
|
|
22
|
+
import type { OriginRegistryPort } from "@jini-ai/core/contracts/server/verified-origin";
|
|
23
|
+
import type { PositionalMailer as MailerPort } from "@jini-ai/core/contracts/mail";
|
|
24
|
+
import type { MailActivityOutcome } from "./activity/vocabulary.js";
|
|
25
|
+
import type { MailActivityRepo } from "./activity/ports.js";
|
|
26
|
+
import type { MailPurposeGateProbe } from "./purpose-gate-probe.js";
|
|
27
|
+
import type { MailLaunchGateResult } from "@jini-ai/core/contracts/site/platform-mail";
|
|
28
|
+
export type MailUseState = "ready" | "blocked" | "disabled" | "not_configured" | "unknown";
|
|
29
|
+
export type MailUseId = "sign_in" | "newsletter_confirmation" | "form_notifications" | "newsletter";
|
|
30
|
+
export interface MailUseRow {
|
|
31
|
+
use: MailUseId;
|
|
32
|
+
label: string;
|
|
33
|
+
/** Jini's send lane: interactive sends bypass the durable-outbox gate, notifications do not. */
|
|
34
|
+
sendLane: "interactive" | "notification";
|
|
35
|
+
/** The delivery lane (suppression scope, provider capacity). */
|
|
36
|
+
mailLane: "transactional" | "bulk";
|
|
37
|
+
state: MailUseState;
|
|
38
|
+
/** Stable codes, in check order (e.g. `sender_not_configured`, `durable_outbox_not_ready`). */
|
|
39
|
+
reasons: string[];
|
|
40
|
+
/** The From this use would send with now; null when unresolved. */
|
|
41
|
+
sender: string | null;
|
|
42
|
+
/** The feature that owns this use's own settings (its admin screen links from here). */
|
|
43
|
+
owner: "members" | "newsletter" | "forms";
|
|
44
|
+
/** Configured form count, form notifications only. */
|
|
45
|
+
formsConfigured?: number;
|
|
46
|
+
evidence: {
|
|
47
|
+
outcome: MailActivityOutcome;
|
|
48
|
+
at: string;
|
|
49
|
+
} | null;
|
|
50
|
+
}
|
|
51
|
+
/** The structural slice of the host Newsletter gate's inputs that readiness builds and hands back to it. */
|
|
52
|
+
export interface MailUseLaunchGateDeps {
|
|
53
|
+
isSendingEnabled(workspaceId: string): Promise<boolean>;
|
|
54
|
+
/** `null` = unbound; the host gate checks presence only. */
|
|
55
|
+
consentCapability: unknown;
|
|
56
|
+
originRegistry: OriginRegistryPort;
|
|
57
|
+
mailer: MailerPort;
|
|
58
|
+
}
|
|
59
|
+
export interface MailUseReadinessReport {
|
|
60
|
+
checkedAt: string;
|
|
61
|
+
uses: MailUseRow[];
|
|
62
|
+
}
|
|
63
|
+
export interface MailUseReadinessDeps {
|
|
64
|
+
workspaceId: string;
|
|
65
|
+
mailer: MailerPort;
|
|
66
|
+
mailSenderIdentity?: MailSenderIdentityPort;
|
|
67
|
+
mailLaneReady?: (required: {
|
|
68
|
+
lane: "transactional" | "bulk";
|
|
69
|
+
}) => Promise<boolean>;
|
|
70
|
+
/** The live gate's probe; absent, gated rows report `purpose_gate_unavailable` as unknown. */
|
|
71
|
+
mailPurposeGate?: MailPurposeGateProbe;
|
|
72
|
+
formDefinitionRepo?: Pick<FormDefinitionRepoPort, "list">;
|
|
73
|
+
/** Present only when Newsletter is installed; absent, its two rows are omitted. */
|
|
74
|
+
newsletterLaunchGate?: MailUseLaunchGateDeps;
|
|
75
|
+
/** Host: Newsletter's launch gate evaluator (the one its send path runs); absent, Newsletter's rows are `newsletter_gate_unavailable` unknown. */
|
|
76
|
+
evaluateNewsletterLaunchGate?(required: {
|
|
77
|
+
deps: MailUseLaunchGateDeps;
|
|
78
|
+
workspaceId: string;
|
|
79
|
+
isTestSend: boolean;
|
|
80
|
+
}): Promise<Pick<MailLaunchGateResult, "unmetPreconditions">>;
|
|
81
|
+
mailActivity?: Pick<MailActivityRepo, "list">;
|
|
82
|
+
nowIso?: () => string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Every use this site has, each checked independently and concurrently.
|
|
86
|
+
* @complexity One owner check and one evidence read per use (at most four).
|
|
87
|
+
* @example await readMailUseReadiness(deps)
|
|
88
|
+
*/
|
|
89
|
+
export declare function readMailUseReadiness(deps: MailUseReadinessDeps, _options?: Record<string, never>): Promise<MailUseReadinessReport>;
|
|
90
|
+
/** The host fields readiness reads; Newsletter's are optional so a root without it omits its rows. */
|
|
91
|
+
export type MailUseReadinessHostDeps = Omit<MailUseReadinessDeps, "newsletterLaunchGate"> & {
|
|
92
|
+
originRegistry?: MailUseLaunchGateDeps["originRegistry"];
|
|
93
|
+
newsletterCampaignRepo?: unknown;
|
|
94
|
+
membersConsentCapability?: MailUseLaunchGateDeps["consentCapability"];
|
|
95
|
+
newsletterSendingEnabled?: MailUseLaunchGateDeps["isSendingEnabled"];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Readiness deps from route/tool deps. Newsletter's launch-gate inputs map exactly as
|
|
99
|
+
* `features/newsletter/tool-registrations.ts`'s `toNewsletterSendPipelineDeps` maps them (an absent
|
|
100
|
+
* sending setting is the fail-closed `false`), so this reads the same gate the send path evaluates.
|
|
101
|
+
* @complexity O(1).
|
|
102
|
+
*/
|
|
103
|
+
export declare function mailUseReadinessDepsFrom(deps: MailUseReadinessHostDeps, _options?: Record<string, never>): MailUseReadinessDeps;
|
|
104
|
+
//# sourceMappingURL=use-readiness.d.ts.map
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file **What uses email** (email phase 4): one readiness row per use of the site's mail, built
|
|
3
|
+
* from the checks each owning feature already runs, never a second copy of them.
|
|
4
|
+
*
|
|
5
|
+
* | Use | Owner checks reused |
|
|
6
|
+
* |---|---|
|
|
7
|
+
* | Sign-in links | the members sender (`mailSenderIdentity`, as `members/write-service.ts` resolves it), Jini's purpose gate on the interactive lane |
|
|
8
|
+
* | Confirmations | Newsletter's `evaluateLaunchGate` test-send subset (origin, production mailer) that `confirmation.ts` needs, the sender, the interactive gate |
|
|
9
|
+
* | Form notifications | Forms' definitions (`notify.enabled` + recipients, as `@jini-ai/cms/forms`' subscriber reads them), the sender, the notification-lane gate |
|
|
10
|
+
* | Newsletter | `evaluateLaunchGate` in full, the sender, the notification-lane gate |
|
|
11
|
+
*
|
|
12
|
+
* The purpose gate is asked through `platform/mail/purpose-gate-probe.ts`, so the production
|
|
13
|
+
* `durableOutboxReady` gate is surfaced as a blocker exactly as it decides, and is not changed here.
|
|
14
|
+
*
|
|
15
|
+
* State per row: blocked > not_configured > disabled > ready, every reason kept. A check that
|
|
16
|
+
* throws makes only its own row `unknown`. Evidence (the last observed outcome, from the activity
|
|
17
|
+
* projection) is separate: a ready row with a bounced last send is both, and a failed evidence read
|
|
18
|
+
* leaves the state standing with `evidence: null`.
|
|
19
|
+
*/
|
|
20
|
+
import { createMailSenderIdentityResolver, SenderIdentityNotConfiguredError } from "./sender-identity.js";
|
|
21
|
+
import { isMailDeliveryAvailable } from "./delivery-availability.js";
|
|
22
|
+
import { fromPositionalMailer } from "./plugin-abi.js";
|
|
23
|
+
const RANK = ["blocked", "not_configured", "disabled"];
|
|
24
|
+
const SENDER_FALLBACK = { email: "no-reply@site.local" };
|
|
25
|
+
const SPECS = {
|
|
26
|
+
sign_in: { use: "sign_in", label: "Sign-in links", sendLane: "interactive", mailLane: "transactional", owner: "members", activityUse: "sign_in" },
|
|
27
|
+
newsletter_confirmation: { use: "newsletter_confirmation", label: "Subscription confirmations", sendLane: "interactive", mailLane: "transactional", owner: "newsletter", activityUse: "newsletter_confirmation" },
|
|
28
|
+
form_notifications: { use: "form_notifications", label: "Form notifications", sendLane: "notification", mailLane: "transactional", owner: "forms", activityUse: "form_notification" },
|
|
29
|
+
newsletter: { use: "newsletter", label: "Newsletter", sendLane: "notification", mailLane: "bulk", owner: "newsletter", activityUse: "newsletter" },
|
|
30
|
+
};
|
|
31
|
+
/** Newsletter's own precondition codes; a switched-off sending setting is Disabled, not Blocked. */
|
|
32
|
+
const LAUNCH_GATE_STATE = {
|
|
33
|
+
sending_enabled_false: "disabled",
|
|
34
|
+
consent_capability_unbound: "blocked",
|
|
35
|
+
origin_not_verified: "blocked",
|
|
36
|
+
mailer_adapter_not_production: "not_configured",
|
|
37
|
+
};
|
|
38
|
+
async function senderFinding(deps, _options = {}) {
|
|
39
|
+
const identity = deps.mailSenderIdentity ?? createMailSenderIdentityResolver({ readDriver: () => deps.mailer.capabilities().driver });
|
|
40
|
+
try {
|
|
41
|
+
return { sender: (await identity.resolve({ workspaceId: deps.workspaceId, fallback: SENDER_FALLBACK })).email, findings: [] };
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (err instanceof SenderIdentityNotConfiguredError)
|
|
45
|
+
return { sender: null, findings: [{ state: "blocked", reason: "sender_not_configured" }] };
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function gateFinding(deps, spec) {
|
|
50
|
+
if (!deps.mailPurposeGate)
|
|
51
|
+
throw new Error("purpose_gate_unavailable");
|
|
52
|
+
return (await deps.mailPurposeGate({ capabilityName: spec.owner, lane: spec.sendLane })) ? [] : [{ state: "blocked", reason: "durable_outbox_not_ready" }];
|
|
53
|
+
}
|
|
54
|
+
/** Delivery, sender and gate: what every use shares, in that order. */
|
|
55
|
+
async function sharedFindings(deps, spec) {
|
|
56
|
+
const available = deps.mailLaneReady ? await deps.mailLaneReady({ lane: spec.mailLane }) : isMailDeliveryAvailable({ mailer: fromPositionalMailer({ mailer: deps.mailer }) });
|
|
57
|
+
const delivery = available ? [] : [{ state: "not_configured", reason: "mail_delivery_unavailable" }];
|
|
58
|
+
const sender = await senderFinding(deps);
|
|
59
|
+
return { findings: [...delivery, ...sender.findings, ...(await gateFinding(deps, spec))], sender: sender.sender };
|
|
60
|
+
}
|
|
61
|
+
async function launchGateFindings({ deps, isTestSend }, _options = {}) {
|
|
62
|
+
if (!deps.evaluateNewsletterLaunchGate)
|
|
63
|
+
throw new Error("newsletter_gate_unavailable");
|
|
64
|
+
const result = await deps.evaluateNewsletterLaunchGate({ deps: deps.newsletterLaunchGate, workspaceId: deps.workspaceId, isTestSend });
|
|
65
|
+
// The shared delivery check already reports a console/memory mailer.
|
|
66
|
+
return result.unmetPreconditions.filter((code) => code !== "mailer_adapter_not_production").map((code) => ({ state: LAUNCH_GATE_STATE[code], reason: code }));
|
|
67
|
+
}
|
|
68
|
+
const CHECKS = {
|
|
69
|
+
sign_in: ({ deps }) => sharedFindings(deps, SPECS.sign_in),
|
|
70
|
+
newsletter_confirmation: async ({ deps }) => {
|
|
71
|
+
const own = await launchGateFindings({ deps, isTestSend: true });
|
|
72
|
+
const shared = await sharedFindings(deps, SPECS.newsletter_confirmation);
|
|
73
|
+
return { ...shared, findings: [...own, ...shared.findings] };
|
|
74
|
+
},
|
|
75
|
+
form_notifications: async ({ deps }) => {
|
|
76
|
+
if (!deps.formDefinitionRepo)
|
|
77
|
+
throw new Error("forms_unavailable");
|
|
78
|
+
const forms = await deps.formDefinitionRepo.list({ workspaceId: deps.workspaceId });
|
|
79
|
+
const formsConfigured = forms.filter((form) => form.notify.enabled && form.notify.recipients.length > 0).length;
|
|
80
|
+
if (formsConfigured === 0)
|
|
81
|
+
return { findings: [{ state: "not_configured", reason: "no_form_notifications" }], sender: null, formsConfigured };
|
|
82
|
+
return { ...(await sharedFindings(deps, SPECS.form_notifications)), formsConfigured };
|
|
83
|
+
},
|
|
84
|
+
newsletter: async ({ deps }) => {
|
|
85
|
+
const own = await launchGateFindings({ deps, isTestSend: false });
|
|
86
|
+
const shared = await sharedFindings(deps, SPECS.newsletter);
|
|
87
|
+
return { ...shared, findings: [...own, ...shared.findings] };
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
function stateOf({ findings }, _options = {}) {
|
|
91
|
+
return RANK.find((state) => findings.some((finding) => finding.state === state)) ?? "ready";
|
|
92
|
+
}
|
|
93
|
+
async function evidenceFor(deps, spec) {
|
|
94
|
+
if (!deps.mailActivity)
|
|
95
|
+
return null;
|
|
96
|
+
try {
|
|
97
|
+
const [last] = await deps.mailActivity.list({ workspaceId: deps.workspaceId, limit: 1 }, { use: spec.activityUse });
|
|
98
|
+
return last ? { outcome: last.outcome, at: last.updatedAt } : null;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function rowFor(deps, use) {
|
|
105
|
+
const spec = SPECS[use];
|
|
106
|
+
const base = { use, label: spec.label, sendLane: spec.sendLane, mailLane: spec.mailLane, owner: spec.owner };
|
|
107
|
+
const evidence = await evidenceFor(deps, spec);
|
|
108
|
+
try {
|
|
109
|
+
const check = await CHECKS[use]({ deps });
|
|
110
|
+
return { ...base, state: stateOf({ findings: check.findings }), reasons: check.findings.map((finding) => finding.reason), sender: check.sender,
|
|
111
|
+
...(check.formsConfigured === undefined ? {} : { formsConfigured: check.formsConfigured }), evidence };
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
// Only this row is unknown; a known reason code is kept, anything else is a generic check failure.
|
|
115
|
+
const reason = err instanceof Error && /^[a-z_]+$/.test(err.message) ? err.message : "check_failed";
|
|
116
|
+
return { ...base, state: "unknown", reasons: [reason], sender: null, evidence };
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Every use this site has, each checked independently and concurrently.
|
|
121
|
+
* @complexity One owner check and one evidence read per use (at most four).
|
|
122
|
+
* @example await readMailUseReadiness(deps)
|
|
123
|
+
*/
|
|
124
|
+
export async function readMailUseReadiness(deps, _options = {}) {
|
|
125
|
+
const uses = deps.newsletterLaunchGate ? ["sign_in", "newsletter_confirmation", "form_notifications", "newsletter"] : ["sign_in", "form_notifications"];
|
|
126
|
+
return { checkedAt: (deps.nowIso ?? (() => new Date().toISOString()))(), uses: await Promise.all(uses.map((use) => rowFor(deps, use))) };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Readiness deps from route/tool deps. Newsletter's launch-gate inputs map exactly as
|
|
130
|
+
* `features/newsletter/tool-registrations.ts`'s `toNewsletterSendPipelineDeps` maps them (an absent
|
|
131
|
+
* sending setting is the fail-closed `false`), so this reads the same gate the send path evaluates.
|
|
132
|
+
* @complexity O(1).
|
|
133
|
+
*/
|
|
134
|
+
export function mailUseReadinessDepsFrom(deps, _options = {}) {
|
|
135
|
+
const { originRegistry, newsletterCampaignRepo, membersConsentCapability, newsletterSendingEnabled, ...rest } = deps;
|
|
136
|
+
if (newsletterCampaignRepo === undefined || originRegistry === undefined)
|
|
137
|
+
return rest;
|
|
138
|
+
return { ...rest, newsletterLaunchGate: { isSendingEnabled: newsletterSendingEnabled ?? (async () => false), consentCapability: membersConsentCapability ?? null, originRegistry, mailer: deps.mailer } };
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=use-readiness.js.map
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
* planted as the object itself is refused rather than followed.
|
|
14
14
|
*/
|
|
15
15
|
import { constants } from 'node:fs';
|
|
16
|
-
import {
|
|
16
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
17
|
+
import { lstat, mkdir, open, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
17
18
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
18
19
|
import { providerOk } from '@jini-ai/core/provider-registry';
|
|
19
20
|
/** Node's errno-carrying error, narrowed without a cast at each call site. */
|
|
@@ -76,6 +77,35 @@ async function physicallyContained(required) {
|
|
|
76
77
|
}
|
|
77
78
|
return path;
|
|
78
79
|
}
|
|
80
|
+
function createLocalStagedWriter({ pathOf }) {
|
|
81
|
+
return async ({ key, byteLength, sha256, openChunks }, { signal } = {}) => {
|
|
82
|
+
signal?.throwIfAborted();
|
|
83
|
+
const path = await pathOf(key);
|
|
84
|
+
await mkdir(dirname(path), { recursive: true });
|
|
85
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
86
|
+
const file = await open(temporary, CREATE_ONLY_FLAGS, 0o600);
|
|
87
|
+
try {
|
|
88
|
+
const hash = createHash('sha256');
|
|
89
|
+
let length = 0;
|
|
90
|
+
for await (const chunk of openChunks({}, signal ? { signal } : {})) {
|
|
91
|
+
signal?.throwIfAborted();
|
|
92
|
+
length += chunk.byteLength;
|
|
93
|
+
if (length > byteLength)
|
|
94
|
+
throw new Error('staged object length mismatch');
|
|
95
|
+
await file.writeFile(chunk);
|
|
96
|
+
hash.update(chunk);
|
|
97
|
+
}
|
|
98
|
+
if (length !== byteLength || hash.digest('hex') !== sha256)
|
|
99
|
+
throw new Error('staged object verification failed');
|
|
100
|
+
signal?.throwIfAborted();
|
|
101
|
+
await rename(temporary, path);
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
await file.close();
|
|
105
|
+
await rm(temporary, { force: true });
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
79
109
|
/**
|
|
80
110
|
* Creates a local-filesystem `ObjectStore` rooted at `rootDir`.
|
|
81
111
|
* @complexity Each call is O(1) syscalls beyond the read/write itself.
|
|
@@ -84,6 +114,9 @@ export function createLocalFsObjectStore(required, _optional = {}) {
|
|
|
84
114
|
const { rootDir } = required;
|
|
85
115
|
const pathOf = (key) => physicallyContained({ rootDir, key });
|
|
86
116
|
return {
|
|
117
|
+
async resolveStagedWriter(_required, _optional = {}) {
|
|
118
|
+
return createLocalStagedWriter({ pathOf });
|
|
119
|
+
},
|
|
87
120
|
async put({ key, bytes }, options = {}) {
|
|
88
121
|
const path = await pathOf(key);
|
|
89
122
|
await mkdir(dirname(path), { recursive: true });
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ArtifactStorePort, DeployTargetCredential } from "@jini-ai/core/contracts/site/devops-deploy";
|
|
2
|
+
import type { LoadedObjectStoreRegistry } from "./registry.js";
|
|
3
|
+
/**
|
|
4
|
+
* @file Which object-store provider delivers backup shares: any registered provider that can also
|
|
5
|
+
* hand out a single-object artifact store (for example an S3-compatible store), instead of one
|
|
6
|
+
* hard-coded deploy target id. The site's media choice wins when it qualifies, so media and shares
|
|
7
|
+
* use one provider (and one saved connection); otherwise the first qualifying one in registry order.
|
|
8
|
+
* A provider qualifies only once its saved connection resolves and passes its optional artifact
|
|
9
|
+
* credential check, so an installed but unconnected
|
|
10
|
+
* store never hides a connected one behind it. Revoke names the share's saved provider and resolves
|
|
11
|
+
* only that one, so a store connected later can never take over (or block) another store's delete.
|
|
12
|
+
*/
|
|
13
|
+
/** A provider's artifact capability as the share path calls it (the deploy-target module ABI). */
|
|
14
|
+
export interface ArtifactStoreCapable {
|
|
15
|
+
/** Optional provider-owned readiness check for artifact-specific companion credentials. */
|
|
16
|
+
acceptsArtifactCredential?(required: {
|
|
17
|
+
readonly credential: unknown;
|
|
18
|
+
}, optional?: Record<string, never>): boolean;
|
|
19
|
+
createArtifactStore(required: {
|
|
20
|
+
readonly credential: DeployTargetCredential;
|
|
21
|
+
readonly config: Record<string, never>;
|
|
22
|
+
readonly kit: unknown;
|
|
23
|
+
}): ArtifactStorePort & {
|
|
24
|
+
/** Non-secret identity of the backing store, when the provider knows it better than the host does. */
|
|
25
|
+
readonly binding?: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @param required.resolveCredential The provider's saved connection, or `undefined` when it has none.
|
|
30
|
+
* @param optional.savedProvider A share's recorded provider (its hyphenated connection id): only that
|
|
31
|
+
* provider is considered.
|
|
32
|
+
* @returns The first capable provider (preferred first, then registry order) whose connection
|
|
33
|
+
* resolves and passes the provider's artifact check, with that credential; `undefined` when none qualifies.
|
|
34
|
+
* @complexity O(n) registered providers, one credential lookup per capable provider until a hit.
|
|
35
|
+
*/
|
|
36
|
+
export declare function selectArtifactStoreProvider<C, Host>(required: {
|
|
37
|
+
readonly loaded: LoadedObjectStoreRegistry<Host>;
|
|
38
|
+
readonly preferredId: string;
|
|
39
|
+
readonly resolveCredential: (required: {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
}, optional?: Record<string, never>) => Promise<C | undefined>;
|
|
42
|
+
}, optional?: {
|
|
43
|
+
readonly savedProvider?: string;
|
|
44
|
+
}): Promise<{
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly provider: ArtifactStoreCapable;
|
|
47
|
+
readonly credential: C;
|
|
48
|
+
} | undefined>;
|
|
49
|
+
/** Provider ids use underscores; the saved connection (and a share's recorded provider) is the hyphenated target id. */
|
|
50
|
+
export declare function artifactStoreTarget({ id }: {
|
|
51
|
+
id: string;
|
|
52
|
+
}, _optional?: Record<string, never>): string;
|
|
53
|
+
/**
|
|
54
|
+
* What revoke must match before deleting: a new default connection must never turn revocation into
|
|
55
|
+
* deletion in another bucket. Non-secret storage coordinates bind, so credentials may rotate for the
|
|
56
|
+
* same store; a provider that names its own store (e.g. a token-scoped one) supplies that instead.
|
|
57
|
+
* @complexity O(1).
|
|
58
|
+
*/
|
|
59
|
+
export declare function artifactStoreBinding(required: {
|
|
60
|
+
readonly store: {
|
|
61
|
+
readonly binding?: string;
|
|
62
|
+
};
|
|
63
|
+
readonly credential: Readonly<Record<string, unknown>>;
|
|
64
|
+
}, _optional?: Record<string, never>): string;
|
|
65
|
+
//# sourceMappingURL=artifact-provider.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param required.resolveCredential The provider's saved connection, or `undefined` when it has none.
|
|
3
|
+
* @param optional.savedProvider A share's recorded provider (its hyphenated connection id): only that
|
|
4
|
+
* provider is considered.
|
|
5
|
+
* @returns The first capable provider (preferred first, then registry order) whose connection
|
|
6
|
+
* resolves and passes the provider's artifact check, with that credential; `undefined` when none qualifies.
|
|
7
|
+
* @complexity O(n) registered providers, one credential lookup per capable provider until a hit.
|
|
8
|
+
*/
|
|
9
|
+
export async function selectArtifactStoreProvider(required, optional = {}) {
|
|
10
|
+
const capable = required.loaded.registry.list().filter((entry) => typeof entry.provider.createArtifactStore === "function"
|
|
11
|
+
&& (optional.savedProvider === undefined || artifactStoreTarget({ id: entry.id }) === optional.savedProvider));
|
|
12
|
+
const ordered = [...capable.filter((entry) => entry.id === required.preferredId), ...capable.filter((entry) => entry.id !== required.preferredId)];
|
|
13
|
+
for (const entry of ordered) {
|
|
14
|
+
const credential = await required.resolveCredential({ id: entry.id });
|
|
15
|
+
if (credential === undefined)
|
|
16
|
+
continue;
|
|
17
|
+
const provider = entry.provider;
|
|
18
|
+
if (provider.acceptsArtifactCredential?.({ credential }) !== false)
|
|
19
|
+
return { id: entry.id, provider, credential };
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
/** Provider ids use underscores; the saved connection (and a share's recorded provider) is the hyphenated target id. */
|
|
24
|
+
export function artifactStoreTarget({ id }, _optional = {}) {
|
|
25
|
+
return id.replace(/_/g, "-");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* What revoke must match before deleting: a new default connection must never turn revocation into
|
|
29
|
+
* deletion in another bucket. Non-secret storage coordinates bind, so credentials may rotate for the
|
|
30
|
+
* same store; a provider that names its own store (e.g. a token-scoped one) supplies that instead.
|
|
31
|
+
* @complexity O(1).
|
|
32
|
+
*/
|
|
33
|
+
export function artifactStoreBinding(required, _optional = {}) {
|
|
34
|
+
const { store, credential } = required;
|
|
35
|
+
return store.binding ?? JSON.stringify([credential.bucket, credential.region, credential.endpoint ?? "", credential.publicUrl]);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=artifact-provider.js.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type ObjectStoreProvider } from "@jini-ai/core/object-store";
|
|
2
|
+
import type { ProviderDefinition, ProviderRegistry } from "@jini-ai/core/provider-registry";
|
|
3
|
+
import { type ObjectStoreEnvDeclaration, type ObjectStoresParseResult } from "../descriptors.js";
|
|
4
|
+
/**
|
|
5
|
+
* @file The site's object-store providers: the built-in `local` filesystem provider (the registry
|
|
6
|
+
* default) plus every provider a trusted Agent Plugin contributes through
|
|
7
|
+
* {@link OBJECT_STORES_FILENAME} — today the bundled s3-compatible plugin's `s3_compatible`.
|
|
8
|
+
*
|
|
9
|
+
* Plugin providers load through Jini's `defineProviderContribution`, so a provider module passes the
|
|
10
|
+
* same gates as every executable seam (active plugin, bundled digest, contained `.mjs`); a bad one is
|
|
11
|
+
* a refusal line, never a boot crash. Core owns the generic contract (`@jini-ai/core/object-store`);
|
|
12
|
+
* this module is the generic site loader.
|
|
13
|
+
*
|
|
14
|
+
* ## Wiring
|
|
15
|
+
* Generic over the host object `Host` a provider's `create()` receives and over the contribution
|
|
16
|
+
* `Definition` the host's plugin loader accepts. The agent-plugins contribution seam
|
|
17
|
+
* (`defineProviderContribution`, `contributeProviders`) and the host's plugin loaders
|
|
18
|
+
* (`loadContributions`, `bundledContributionSources`, `loadPluginContributionsFromSource`) arrive
|
|
19
|
+
* on each function's required args, bound by the host's composition root. `Host` and `Definition`
|
|
20
|
+
* are inferred from the contribution seam only (`NoInfer` on the loaders), because the host's
|
|
21
|
+
* loaders are themselves generic and would otherwise widen both to `unknown`.
|
|
22
|
+
*/
|
|
23
|
+
/** The file a plugin ships at its root to contribute object-store providers: `{ schemaVersion: 1, providers: [{ id, module, label? }] }`,
|
|
24
|
+
* parsed by `@jini-ai/platform/object-store`; ids are checked against the shared grammar before any module is imported. */
|
|
25
|
+
export declare const OBJECT_STORES_FILENAME = "jini-object-stores.json";
|
|
26
|
+
/** A provider whose `create()` receives the host object `Host` (signing, optional request tracing). */
|
|
27
|
+
export type SiteObjectStoreProvider<Host> = ObjectStoreProvider<Host>;
|
|
28
|
+
export interface LoadedObjectStoreRegistry<Host> {
|
|
29
|
+
readonly registry: ProviderRegistry<SiteObjectStoreProvider<Host>>;
|
|
30
|
+
/** Log-safe, one line per provider that was not loaded and why. */
|
|
31
|
+
readonly refusals: readonly string[];
|
|
32
|
+
}
|
|
33
|
+
/** One plugin's loaded provider, as the host's contribution loader returns it. */
|
|
34
|
+
export interface LoadedObjectStoreContribution<Host> {
|
|
35
|
+
readonly contract: string;
|
|
36
|
+
readonly pluginId: string;
|
|
37
|
+
readonly definition: ProviderDefinition<SiteObjectStoreProvider<Host>>;
|
|
38
|
+
}
|
|
39
|
+
export interface LoadedObjectStoreContributions<Host> {
|
|
40
|
+
readonly items: readonly LoadedObjectStoreContribution<Host>[];
|
|
41
|
+
readonly refusals: readonly string[];
|
|
42
|
+
}
|
|
43
|
+
/** A trusted bundled plugin package: whose it is and where its files live. */
|
|
44
|
+
export interface ObjectStoreSourcePlugin {
|
|
45
|
+
readonly pluginId: string;
|
|
46
|
+
readonly packageRoot: string;
|
|
47
|
+
}
|
|
48
|
+
/** The spec handed to the injected `defineProviderContribution` (agent-plugins' shared seam). */
|
|
49
|
+
export interface ObjectStoreContributionSpec<Host> {
|
|
50
|
+
readonly contract: string;
|
|
51
|
+
readonly filename: string;
|
|
52
|
+
readonly parse: (input: {
|
|
53
|
+
readonly raw: string;
|
|
54
|
+
}) => ObjectStoresParseResult;
|
|
55
|
+
readonly validate: (input: {
|
|
56
|
+
readonly exported: unknown;
|
|
57
|
+
}) => SiteObjectStoreProvider<Host> | string;
|
|
58
|
+
}
|
|
59
|
+
/** The agent-plugins contribution seam, bound by the host. */
|
|
60
|
+
export interface ObjectStoreContributionPorts<Host, Definition> {
|
|
61
|
+
readonly defineProviderContribution: (spec: ObjectStoreContributionSpec<Host>) => Definition;
|
|
62
|
+
readonly contributeProviders: (required: {
|
|
63
|
+
readonly registry: ProviderRegistry<SiteObjectStoreProvider<Host>>;
|
|
64
|
+
readonly loaded: LoadedObjectStoreContributions<Host>;
|
|
65
|
+
}) => {
|
|
66
|
+
readonly refusals: readonly string[];
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** The host's bundled-source enumerator (trusted, immutable product sources only). */
|
|
70
|
+
export type BundledObjectStoreSources = (required: {
|
|
71
|
+
readonly sourceRoot: string;
|
|
72
|
+
readonly filename: string;
|
|
73
|
+
}) => readonly ObjectStoreSourcePlugin[];
|
|
74
|
+
/**
|
|
75
|
+
* This workspace's providers from its installed, activated Agent Plugins. Read fresh per call.
|
|
76
|
+
* @complexity O(p) installed plugins, one import per declared provider.
|
|
77
|
+
*/
|
|
78
|
+
export declare function loadObjectStoreRegistry<Host, Definition>(required: ObjectStoreContributionPorts<Host, Definition> & {
|
|
79
|
+
readonly workspaceId: string;
|
|
80
|
+
readonly uploadsDir: string;
|
|
81
|
+
readonly loadContributions: (input: {
|
|
82
|
+
readonly workspaceId: string;
|
|
83
|
+
readonly definition: NoInfer<Definition>;
|
|
84
|
+
}, optional: {
|
|
85
|
+
readonly orderByPluginId: boolean;
|
|
86
|
+
}) => Promise<LoadedObjectStoreContributions<NoInfer<Host>>>;
|
|
87
|
+
}, _optional?: Record<string, never>): Promise<LoadedObjectStoreRegistry<Host>>;
|
|
88
|
+
/**
|
|
89
|
+
* Providers read straight from this product's own bundled plugin SOURCE, with no
|
|
90
|
+
* install/activation gate — for the operator env override, which must not depend on a plugin being
|
|
91
|
+
* switched on. Never point `sourceRoot` at anything an operator or third party can write.
|
|
92
|
+
* @complexity O(t) bundled providers, one import each.
|
|
93
|
+
*/
|
|
94
|
+
export declare function loadBundledObjectStoreRegistry<Host, Definition>(required: ObjectStoreContributionPorts<Host, Definition> & {
|
|
95
|
+
readonly uploadsDir: string;
|
|
96
|
+
readonly sourceRoot: string;
|
|
97
|
+
readonly bundledContributionSources: BundledObjectStoreSources;
|
|
98
|
+
readonly loadPluginContributionsFromSource: (input: {
|
|
99
|
+
readonly plugin: ObjectStoreSourcePlugin;
|
|
100
|
+
readonly definition: NoInfer<Definition>;
|
|
101
|
+
}) => Promise<LoadedObjectStoreContributions<NoInfer<Host>>>;
|
|
102
|
+
}, _optional?: Record<string, never>): Promise<LoadedObjectStoreRegistry<Host>>;
|
|
103
|
+
/** Synchronous media env mappings from immutable bundled sources; never imports provider modules.
|
|
104
|
+
* @param required Product-owned source root and the host's bundled-source enumerator. @returns Mappings in declaration order.
|
|
105
|
+
* @throws {Error} Unreadable/invalid data or duplicate selectors; an opt-in never silently becomes local. */
|
|
106
|
+
export declare function readBundledObjectStoreEnvDeclarations(required: {
|
|
107
|
+
readonly sourceRoot: string;
|
|
108
|
+
readonly bundledContributionSources: BundledObjectStoreSources;
|
|
109
|
+
}, _optional?: {}): readonly ObjectStoreEnvDeclaration[];
|
|
110
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createObjectStoreRegistry, OBJECT_STORE_CONTRACT, objectStoreProviderFault } from "@jini-ai/core/object-store";
|
|
4
|
+
import { parseObjectStoresFile as parseObjectStoreDescriptors } from "../descriptors.js";
|
|
5
|
+
import { createLocalFsObjectStoreProvider } from "../local-fs.js";
|
|
6
|
+
/**
|
|
7
|
+
* @file The site's object-store providers: the built-in `local` filesystem provider (the registry
|
|
8
|
+
* default) plus every provider a trusted Agent Plugin contributes through
|
|
9
|
+
* {@link OBJECT_STORES_FILENAME} — today the bundled s3-compatible plugin's `s3_compatible`.
|
|
10
|
+
*
|
|
11
|
+
* Plugin providers load through Jini's `defineProviderContribution`, so a provider module passes the
|
|
12
|
+
* same gates as every executable seam (active plugin, bundled digest, contained `.mjs`); a bad one is
|
|
13
|
+
* a refusal line, never a boot crash. Core owns the generic contract (`@jini-ai/core/object-store`);
|
|
14
|
+
* this module is the generic site loader.
|
|
15
|
+
*
|
|
16
|
+
* ## Wiring
|
|
17
|
+
* Generic over the host object `Host` a provider's `create()` receives and over the contribution
|
|
18
|
+
* `Definition` the host's plugin loader accepts. The agent-plugins contribution seam
|
|
19
|
+
* (`defineProviderContribution`, `contributeProviders`) and the host's plugin loaders
|
|
20
|
+
* (`loadContributions`, `bundledContributionSources`, `loadPluginContributionsFromSource`) arrive
|
|
21
|
+
* on each function's required args, bound by the host's composition root. `Host` and `Definition`
|
|
22
|
+
* are inferred from the contribution seam only (`NoInfer` on the loaders), because the host's
|
|
23
|
+
* loaders are themselves generic and would otherwise widen both to `unknown`.
|
|
24
|
+
*/
|
|
25
|
+
/** The file a plugin ships at its root to contribute object-store providers: `{ schemaVersion: 1, providers: [{ id, module, label? }] }`,
|
|
26
|
+
* parsed by `@jini-ai/platform/object-store`; ids are checked against the shared grammar before any module is imported. */
|
|
27
|
+
export const OBJECT_STORES_FILENAME = "jini-object-stores.json";
|
|
28
|
+
/** The shared contribution definition for {@link OBJECT_STORES_FILENAME}. @complexity O(1). */
|
|
29
|
+
function objectStoreContribution(required, _optional = {}) {
|
|
30
|
+
return required.defineProviderContribution({
|
|
31
|
+
contract: OBJECT_STORE_CONTRACT, filename: OBJECT_STORES_FILENAME,
|
|
32
|
+
parse: ({ raw }) => parseObjectStoreDescriptors({ raw }),
|
|
33
|
+
validate: ({ exported }) => objectStoreProviderFault({ provider: exported }) ?? exported,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A registry seeded with `local` (rooted at the site's uploads folder), without plugin providers.
|
|
38
|
+
* @complexity O(1).
|
|
39
|
+
*/
|
|
40
|
+
function seededRegistry(required) {
|
|
41
|
+
return createObjectStoreRegistry({}, { seed: [{ id: "local", label: "This server's disk", provider: createLocalFsObjectStoreProvider({ rootDir: required.uploadsDir }) }] });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* This workspace's providers from its installed, activated Agent Plugins. Read fresh per call.
|
|
45
|
+
* @complexity O(p) installed plugins, one import per declared provider.
|
|
46
|
+
*/
|
|
47
|
+
export async function loadObjectStoreRegistry(required, _optional = {}) {
|
|
48
|
+
const registry = seededRegistry(required);
|
|
49
|
+
const loaded = await required.loadContributions({ workspaceId: required.workspaceId, definition: objectStoreContribution(required) }, { orderByPluginId: true });
|
|
50
|
+
return { registry, refusals: required.contributeProviders({ registry, loaded }).refusals };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Providers read straight from this product's own bundled plugin SOURCE, with no
|
|
54
|
+
* install/activation gate — for the operator env override, which must not depend on a plugin being
|
|
55
|
+
* switched on. Never point `sourceRoot` at anything an operator or third party can write.
|
|
56
|
+
* @complexity O(t) bundled providers, one import each.
|
|
57
|
+
*/
|
|
58
|
+
export async function loadBundledObjectStoreRegistry(required, _optional = {}) {
|
|
59
|
+
const registry = seededRegistry(required);
|
|
60
|
+
const definition = objectStoreContribution(required);
|
|
61
|
+
const refusals = [];
|
|
62
|
+
for (const plugin of required.bundledContributionSources({ sourceRoot: required.sourceRoot, filename: OBJECT_STORES_FILENAME })) {
|
|
63
|
+
const loaded = await required.loadPluginContributionsFromSource({ plugin, definition });
|
|
64
|
+
refusals.push(...required.contributeProviders({ registry, loaded }).refusals);
|
|
65
|
+
}
|
|
66
|
+
return { registry, refusals };
|
|
67
|
+
}
|
|
68
|
+
/** Synchronous media env mappings from immutable bundled sources; never imports provider modules.
|
|
69
|
+
* @param required Product-owned source root and the host's bundled-source enumerator. @returns Mappings in declaration order.
|
|
70
|
+
* @throws {Error} Unreadable/invalid data or duplicate selectors; an opt-in never silently becomes local. */
|
|
71
|
+
export function readBundledObjectStoreEnvDeclarations(required, _optional = {}) {
|
|
72
|
+
const entries = [];
|
|
73
|
+
for (const plugin of required.bundledContributionSources({ sourceRoot: required.sourceRoot, filename: OBJECT_STORES_FILENAME })) {
|
|
74
|
+
const parsed = parseObjectStoreDescriptors({ raw: readFileSync(path.join(plugin.packageRoot, OBJECT_STORES_FILENAME), "utf8") });
|
|
75
|
+
if (!parsed.ok)
|
|
76
|
+
throw new Error(`Object store env declarations from '${plugin.pluginId}' were not loaded: ${parsed.reason}`);
|
|
77
|
+
appendDeclaredEnvironments({ descriptors: parsed.descriptors, entries });
|
|
78
|
+
}
|
|
79
|
+
const selectors = new Set();
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
if (selectors.has(entry.selector))
|
|
82
|
+
throw new Error(`Object store env selector '${entry.selector}' is declared twice.`);
|
|
83
|
+
selectors.add(entry.selector);
|
|
84
|
+
}
|
|
85
|
+
return entries;
|
|
86
|
+
}
|
|
87
|
+
function appendDeclaredEnvironments({ descriptors, entries }, _options = {}) {
|
|
88
|
+
for (const descriptor of descriptors) {
|
|
89
|
+
if (descriptor.env)
|
|
90
|
+
entries.push({ ...descriptor.env, providerId: descriptor.id });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type EnsureSettingDefinitionsDeps, type SettingsRepoPort } from "@jini-ai/core/settings";
|
|
2
|
+
import type { ensureSettingDefinitions, getEffective } from "@jini-ai/core/settings";
|
|
3
|
+
/**
|
|
4
|
+
* @file Which object-store provider holds the site's media bytes: `core.storage.mediaObjectStore`
|
|
5
|
+
* on the existing settings ledger (workspace scope, no schema change). The empty default means the
|
|
6
|
+
* registry default, `local`. Read once per boot when media is first touched, so a change applies
|
|
7
|
+
* on the next restart. The host's media blob-store env var, when set, overrides it.
|
|
8
|
+
*
|
|
9
|
+
* ## Wiring
|
|
10
|
+
* The host binds the settings ledger's implementations: `ensureSettingDefinitions` (the
|
|
11
|
+
* definition writer) and `getEffective` (the reader) arrive on each function's required args, so
|
|
12
|
+
* this module only type-imports their contracts from `@jini-ai/core/settings`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const STORAGE_SETTINGS_NAMESPACE = "core.storage";
|
|
15
|
+
export declare const MEDIA_OBJECT_STORE_KEY = "mediaObjectStore";
|
|
16
|
+
/**
|
|
17
|
+
* Registers the definition without replacing an owner's stored value.
|
|
18
|
+
* @complexity O(1), one definition.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ensureMediaObjectStoreSetting(required: {
|
|
21
|
+
deps: EnsureSettingDefinitionsDeps;
|
|
22
|
+
systemPrincipalId: string;
|
|
23
|
+
ensureSettingDefinitions: typeof ensureSettingDefinitions;
|
|
24
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* The saved provider id, trimmed; `""` when unset, blank, non-string or unregistered.
|
|
27
|
+
* @complexity One effective setting read.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readMediaObjectStoreSetting(required: {
|
|
30
|
+
settingsRepo: SettingsRepoPort;
|
|
31
|
+
workspaceId: string;
|
|
32
|
+
getEffective: typeof getEffective;
|
|
33
|
+
}, _optional?: Record<string, never>): Promise<string>;
|
|
34
|
+
//# sourceMappingURL=setting.d.ts.map
|