@jini-ai/agent-plugins 0.7.2 → 0.7.3-next.2
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 +4 -4
- package/NOTICE +2 -0
- package/README.md +11 -15
- package/calendly/plugin.json +3 -3
- package/cloudflare/lib/forms.mjs +9 -10
- package/cloudflare/lib/target.mjs +1 -1
- package/cloudflare/plugin.json +3 -3
- package/cloudflare/worker/forms-receiver.mjs +9 -9
- package/composio/plugin.json +3 -3
- package/core/persistent-state.js +227 -163
- package/dist/admin-surfaces/connections/connections.d.ts +11 -6
- package/dist/admin-surfaces/connections/connections.js +102 -85
- package/dist/admin-surfaces/node.d.ts +27 -0
- package/dist/admin-surfaces/node.js +32 -0
- package/dist/admin-surfaces/plugin-state.js +21 -18
- package/dist/admin-surfaces/surface-client.d.ts +4 -0
- package/dist/admin-surfaces/surface-client.js +124 -117
- package/dist/admin-surfaces/surface-handlers.js +21 -17
- package/dist/admin-surfaces/theme.d.ts +5 -1
- package/dist/admin-surfaces/theme.js +3 -3
- package/dist/connect/access-token-tool.d.ts +3 -1
- package/dist/connect/access-token-tool.js +3 -2
- package/dist/connect/apply-connect-defaults.js +2 -2
- package/dist/connect/apply-tool-renames.js +9 -8
- package/dist/connect/connect-tool.d.ts +2 -0
- package/dist/connect/connect-tool.js +3 -2
- package/dist/connect/credential-cards.js +3 -2
- package/dist/connect/credential-save-tool.d.ts +14 -11
- package/dist/connect/credential-save-tool.js +128 -121
- package/dist/connect/enable-access.d.ts +2 -2
- package/dist/connect/enable-access.js +6 -6
- package/dist/connect/executable/register.js +40 -34
- package/dist/connect/federate-mcp.d.ts +21 -11
- package/dist/connect/federate-mcp.js +28 -21
- package/dist/connect/grant-signed-in-defaults.js +3 -3
- package/dist/connect/import-access-token.js +2 -1
- package/dist/connect/index.d.ts +1 -0
- package/dist/connect/index.js +1 -0
- package/dist/connect/plugin-credential-card.js +2 -1
- package/dist/connect/plugin-host/index.d.ts +10 -5
- package/dist/connect/plugin-host/index.js +113 -100
- package/dist/connect/ports.d.ts +1 -1
- package/dist/connect/row-update.d.ts +22 -0
- package/dist/connect/row-update.js +18 -0
- package/dist/connect/switch-on-saved-token.d.ts +4 -2
- package/dist/connect/switch-on-saved-token.js +1 -1
- package/dist/connect/token-map.d.ts +44 -0
- package/dist/connect/token-map.js +49 -0
- package/dist/core/identity-namespace.js +5 -0
- package/dist/folder-zip.d.ts +3 -1
- package/dist/folder-zip.js +2 -2
- package/dist/lifecycle/activation.d.ts +4 -4
- package/dist/lifecycle/activation.js +4 -5
- package/dist/lifecycle/automatic-use.js +236 -210
- package/dist/lifecycle/bundled-digests.d.ts +75 -12
- package/dist/lifecycle/bundled-digests.js +213 -212
- package/dist/lifecycle/bundled-source-archive.d.ts +1 -1
- package/dist/lifecycle/bundled-source-archive.js +263 -264
- package/dist/lifecycle/capability-projection.d.ts +1 -1
- package/dist/lifecycle/capability-projection.js +1 -1
- package/dist/lifecycle/credential-card-metadata.d.ts +1 -1
- package/dist/lifecycle/credential-card-metadata.js +27 -3
- package/dist/lifecycle/exports.js +9 -4
- package/dist/lifecycle/fetch-archive.d.ts +1 -1
- package/dist/lifecycle/fetch-archive.js +1 -1
- package/dist/lifecycle/host-tools/identity.js +3 -2
- package/dist/lifecycle/host-tools/ports.d.ts +2 -0
- package/dist/lifecycle/host-tools/search-tool.d.ts +4 -2
- package/dist/lifecycle/host-tools/search-tool.js +9 -8
- package/dist/lifecycle/host-tools/skill-tool.d.ts +18 -2
- package/dist/lifecycle/host-tools/skill-tool.js +16 -8
- package/dist/lifecycle/index.d.ts +118 -110
- package/dist/lifecycle/index.js +45 -12
- package/dist/lifecycle/install-errors.d.ts +1 -1
- package/dist/lifecycle/install-from-url.d.ts +1 -1
- package/dist/lifecycle/install-from-url.js +1 -1
- package/dist/lifecycle/install.d.ts +7 -2
- package/dist/lifecycle/install.js +414 -396
- package/dist/lifecycle/installed-package-index.js +45 -42
- package/dist/lifecycle/layout.d.ts +1 -1
- package/dist/lifecycle/layout.js +1 -1
- package/dist/lifecycle/mail/catalog.d.ts +8 -32
- package/dist/lifecycle/mail/catalog.js +25 -20
- package/dist/lifecycle/mail/contribution.d.ts +2 -2
- package/dist/lifecycle/mail/contribution.js +34 -34
- package/dist/lifecycle/mail/selection.js +6 -2
- package/dist/lifecycle/manifest.d.ts +3 -3
- package/dist/lifecycle/manifest.js +4 -4
- package/dist/lifecycle/mcp-provisioning.d.ts +3 -3
- package/dist/lifecycle/mcp-provisioning.js +3 -3
- package/dist/lifecycle/package-paths.d.ts +1 -1
- package/dist/lifecycle/package-paths.js +1 -1
- package/dist/lifecycle/persistent-state.js +1 -2
- package/dist/lifecycle/ports.d.ts +5 -1
- package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +30 -8
- package/dist/lifecycle/resolve-agent-plugin-refs.js +227 -228
- package/dist/lifecycle/retire-bundled.d.ts +1 -52
- package/dist/lifecycle/retire-bundled.js +134 -84
- package/dist/lifecycle/search.d.ts +2 -1
- package/dist/lifecycle/search.js +1 -1
- package/dist/lifecycle/seed-bundled.d.ts +1 -1
- package/dist/lifecycle/seed-bundled.js +154 -155
- package/dist/lifecycle/set-enabled.d.ts +1 -1
- package/dist/lifecycle/set-enabled.js +1 -1
- package/dist/lifecycle/skill-file-reader.js +53 -50
- package/dist/lifecycle/tools/projection.d.ts +4 -7
- package/dist/lifecycle/tools/projection.js +109 -108
- package/dist/lifecycle/trusted-plugin-files.d.ts +2 -2
- package/dist/lifecycle/trusted-plugin-files.js +1 -1
- package/dist/lifecycle/uninstall.d.ts +1 -1
- package/dist/lifecycle/uninstall.js +237 -241
- package/dist/lifecycle/update-store.js +20 -17
- package/dist/lifecycle/update.js +287 -281
- package/dist/lifecycle/yauzl-archive-reader.d.ts +2 -2
- package/dist/lifecycle/yauzl-archive-reader.js +8 -2
- package/dist/manifest.d.ts +11 -3
- package/dist/manifest.js +9 -9
- package/fly/jini-credential-schemes.json +11 -0
- package/fly/plugin.json +3 -4
- package/github/plugin.json +3 -3
- package/github/source-control/backup-push.mjs +11 -11
- package/github/source-control/commit-site.mjs +23 -13
- package/github/source-control/github.mjs +12 -6
- package/github/source-control/write-files.mjs +27 -28
- package/github-pages/{tovu-deploy-targets.json → jini-deploy-targets.json} +22 -22
- package/github-pages/plugin.json +3 -3
- package/github-pages/targets/github-pages.mjs +3 -3
- package/google-login/plugin.json +3 -3
- package/google-workspace/README.md +14 -14
- package/google-workspace/form-destinations/README.md +3 -3
- package/google-workspace/form-destinations/dedupe.mjs +1 -1
- package/google-workspace/form-destinations/mapping.mjs +8 -9
- package/google-workspace/form-destinations/sheets.mjs +1 -1
- package/google-workspace/{tovu-admin-surfaces.json → jini-admin-surfaces.json} +2 -2
- package/google-workspace/{tovu-agent-tools.json → jini-agent-tools.json} +28 -28
- package/google-workspace/{tovu-connections.json → jini-connections.json} +2 -2
- package/google-workspace/lib/auth.mjs +2 -2
- package/google-workspace/lib/form-destination-settings.mjs +1 -1
- package/google-workspace/lib/picker-flow.mjs +2 -2
- package/google-workspace/lib/request-policy.mjs +1 -1
- package/google-workspace/lib/surface-actions.mjs +1 -1
- package/google-workspace/plugin.json +3 -3
- package/google-workspace/tools/sheets/README.md +3 -3
- package/google-workspace/tools/sheets-admin/README.md +3 -3
- package/google-workspace/ui/README.md +4 -4
- package/google-workspace/ui/connection-panel.mjs +51 -51
- package/google-workspace/ui/destination-panel.mjs +34 -34
- package/google-workspace/ui/dom.mjs +15 -16
- package/google-workspace/ui/picker-flow.mjs +2 -2
- package/google-workspace/ui/picker.mjs +19 -19
- package/google-workspace/ui/surface-client.mjs +96 -69
- package/higgsfield-media/plugin.json +3 -3
- package/jev/plugin.json +3 -3
- package/kuinetic/CHANGELOG.md +12 -0
- package/kuinetic/mcp.json +4 -0
- package/kuinetic/plugin.json +27 -0
- package/kuinetic/skills/kuinetic/SKILL.md +120 -0
- package/kuinetic/skills/kuinetic/references/effects-by-family.md +32 -0
- package/kuinetic/skills/kuinetic/references/opt-in-tiers.md +12 -0
- package/kuinetic/skills/kuinetic/references/reserved-keys.md +36 -0
- package/meilisearch/plugin.json +5 -5
- package/netlify/plugin.json +3 -3
- package/netlify/targets/netlify.mjs +14 -4
- package/opentelemetry/plugin.json +3 -3
- package/package.json +27 -22
- package/posthog/plugin.json +3 -3
- package/railway/plugin.json +3 -3
- package/render/plugin.json +3 -3
- package/resend/NOTES.md +2 -2
- package/resend/adapters/resend.mjs +1 -1
- package/resend/{tovu-mail-adapters.json → jini-mail-adapters.json} +1 -1
- package/resend/lib/domains.mjs +8 -8
- package/resend/plugin.json +3 -3
- package/s3-compatible/{tovu-deploy-targets.json → jini-deploy-targets.json} +68 -68
- package/s3-compatible/jini-object-stores.json +29 -0
- package/s3-compatible/object-stores/s3-compatible.mjs +19 -13
- package/s3-compatible/plugin.json +3 -3
- package/s3-compatible/targets/s3-compatible.mjs +25 -25
- package/sentry/plugin.json +3 -3
- package/shadcn-ui/CHANGELOG.md +7 -0
- package/shadcn-ui/LICENSE +201 -0
- package/shadcn-ui/NOTICE +10 -0
- package/shadcn-ui/mcp.json +4 -0
- package/shadcn-ui/plugin.json +26 -0
- package/shopify/plugin.json +3 -3
- package/site-compliance/plugin.json +3 -3
- package/site-import/plugin.json +3 -3
- package/supabase/mcp.json +1 -4
- package/supabase/plugin.json +3 -3
- package/ui-ux-design/CHANGELOG.md +13 -0
- package/ui-ux-design/NOTICE +2 -0
- package/ui-ux-design/README.md +17 -7
- package/ui-ux-design/plugin.json +6 -3
- package/ui-ux-design/skills/ui-ux-design/SKILL.md +38 -152
- package/ui-ux-design/skills/ui-ux-design/references/full-workflow.md +156 -0
- package/ui-ux-design/skills/ui-ux-design/references/ui-animation.md +4 -4
- package/vercel/NOTES.md +1 -1
- package/vercel/object-stores/vercel-blob.mjs +12 -2
- package/vercel/plugin.json +3 -3
- package/vercel/targets/vercel.mjs +3 -3
- package/wordpress/plugin.json +3 -3
- package/dist/lifecycle/node.d.ts +0 -11
- package/dist/lifecycle/node.js +0 -38
- package/fly/tovu-credential-schemes.json +0 -11
- package/github/deployments/github.mjs +0 -415
- package/s3-compatible/tovu-object-stores.json +0 -29
- package/ui-ux-design/skills/ui-ux-design/references/kuinetic-reference.md +0 -184
- /package/cloudflare/{tovu-consent.json → jini-consent.json} +0 -0
- /package/cloudflare/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
- /package/cloudflare/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
- /package/fly/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
- /package/fly/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
- /package/github/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
- /package/github/{tovu-source-control.json → jini-source-control.json} +0 -0
- /package/google-login/{tovu-login-providers.json → jini-login-providers.json} +0 -0
- /package/google-workspace/{tovu-form-destinations.json → jini-form-destinations.json} +0 -0
- /package/meilisearch/{tovu-search-providers.json → jini-search-providers.json} +0 -0
- /package/netlify/{tovu-consent.json → jini-consent.json} +0 -0
- /package/netlify/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
- /package/railway/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
- /package/railway/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
- /package/render/{tovu-deploy-configs.json → jini-deploy-configs.json} +0 -0
- /package/render/{tovu-deploy-ops.json → jini-deploy-ops.json} +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/README.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/SKILL.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/auth-layout.tsx +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/data-table.tsx +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/examples/form-pattern.tsx +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/component-catalog.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/customization-guide.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/migration-guide.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/resources/setup-guide.md +0 -0
- /package/{ui-ux-design → shadcn-ui}/skills/shadcn-ui/scripts/verify-setup.sh +0 -0
- /package/vercel/{tovu-consent.json → jini-consent.json} +0 -0
- /package/vercel/{tovu-deploy-targets.json → jini-deploy-targets.json} +0 -0
- /package/vercel/{tovu-object-stores.json → jini-object-stores.json} +0 -0
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ADMIN_SURFACE_ACTION_INTENTS } from '../surface-capabilities.js';
|
|
2
|
+
import { createConsoleLogger } from '@jini-ai/core/primitives';
|
|
3
|
+
import { describeErrorForLog } from '@jini-ai/core';
|
|
2
4
|
function codeOf(error) {
|
|
3
5
|
const code = error?.code;
|
|
4
6
|
return typeof code === "string" ? code : "unknown";
|
|
@@ -32,102 +34,117 @@ async function statusFrom(host, connection, view, connectionRef) {
|
|
|
32
34
|
lastSignInAttempt: host.attempts.get(connectionRef) ?? null,
|
|
33
35
|
};
|
|
34
36
|
}
|
|
37
|
+
async function resolveConnection({ scope, connectionId }) {
|
|
38
|
+
const { host, pluginId, workspaceId } = scope;
|
|
39
|
+
const connection = workspaceId === host.workspaceId ? (await host.listConnections({ pluginId })).find((candidate) => candidate.descriptor.connectionId === connectionId) : undefined;
|
|
40
|
+
if (!connection)
|
|
41
|
+
throw host.notAvailable();
|
|
42
|
+
return { connection, connectionRef: host.connectionKey({ workspaceId, pluginId, connectionId }) };
|
|
43
|
+
}
|
|
44
|
+
/** Account actions need the admin the route authenticated; Jini checks it too. */
|
|
45
|
+
async function resolveForActor({ scope, connectionId }) {
|
|
46
|
+
if (scope.principalId === undefined)
|
|
47
|
+
throw scope.host.notAvailable();
|
|
48
|
+
return { ...(await resolveConnection({ scope, connectionId })), actorId: scope.principalId };
|
|
49
|
+
}
|
|
50
|
+
/** An action's result view, its staged-switch label re-read from the record so an expired one never shows. */
|
|
51
|
+
async function viewAfterAction({ host, connectionRef, view }) {
|
|
52
|
+
return { ...view, pendingSwitch: liveStagedAccount(host, (await host.readRecord({ key: connectionRef }))?.staged) };
|
|
53
|
+
}
|
|
54
|
+
/** True when the connection is bound to a shared OAuth app, whose account actions this port refuses. */
|
|
55
|
+
async function isSharedBinding(host, connection) {
|
|
56
|
+
return Boolean(host.sharedOAuth && await host.sharedOAuth.hasBinding(connection));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Desktop: deposit the callback fields once the loopback sign-in redeemed, and clear a failed
|
|
60
|
+
* attempt; a failure is kept (code and next action only) for `status` and logged by code only.
|
|
61
|
+
*/
|
|
62
|
+
function watchDesktopCompletion(scope, attempt) {
|
|
63
|
+
const { host, pluginId, workspaceId } = scope;
|
|
64
|
+
const { connectionId, attemptId, completion } = attempt;
|
|
65
|
+
const connectionRef = host.connectionKey({ workspaceId, pluginId, connectionId });
|
|
66
|
+
void completion?.then((done) => {
|
|
67
|
+
if (!done)
|
|
68
|
+
return;
|
|
69
|
+
host.attempts.delete(connectionRef);
|
|
70
|
+
host.callbackInbox.deposit({ workspaceId, pluginId, connectionId, attemptId, fields: done.callbackFields });
|
|
71
|
+
},
|
|
72
|
+
// Error codes only: a desktop sign-in that failed after the browser opened.
|
|
73
|
+
(error) => {
|
|
74
|
+
host.attempts.set(connectionRef, failedAttempt(error));
|
|
75
|
+
const logger = scope.report ?? createConsoleLogger({ prefix: '[admin-surfaces]' });
|
|
76
|
+
logger.warn({ message: `desktop sign-in for '${pluginId}' did not complete: ${describeErrorForLog({ err: error })}` });
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async function connectionStatus({ scope, connectionId }) {
|
|
80
|
+
const { host } = scope;
|
|
81
|
+
const { connection, connectionRef } = await resolveConnection({ scope, connectionId });
|
|
82
|
+
if (host.sharedOAuth && await host.sharedOAuth.hasBinding(connection)) {
|
|
83
|
+
const shared = await host.sharedOAuth.getStatus(connection);
|
|
84
|
+
const account = shared?.account ?? null;
|
|
85
|
+
return statusFrom(host, connection, shared ? { ...shared, account, pendingSwitch: null } : NEVER_CONNECTED, connectionRef);
|
|
86
|
+
}
|
|
87
|
+
const record = await host.readRecord({ key: connectionRef });
|
|
88
|
+
return statusFrom(host, connection, record ? { ...record, pendingSwitch: liveStagedAccount(host, record.staged) } : NEVER_CONNECTED, connectionRef);
|
|
89
|
+
}
|
|
90
|
+
async function beginSignIn({ scope, args, optional }) {
|
|
91
|
+
const { host, pluginId } = scope;
|
|
92
|
+
const { connectionId, action } = args;
|
|
93
|
+
const { connection, actorId } = await resolveForActor({ scope, connectionId });
|
|
94
|
+
const shared = await isSharedBinding(host, connection);
|
|
95
|
+
if (shared && ADMIN_SURFACE_ACTION_INTENTS[action] === "switch-account")
|
|
96
|
+
throw host.notAvailable();
|
|
97
|
+
const start = await host.startSignIn({ connection, actorId, intent: ADMIN_SURFACE_ACTION_INTENTS[action], scopeSetIds: optional.scopeSetIds ?? [],
|
|
98
|
+
...(shared ? { destination: "shared" } : {}) }, {
|
|
99
|
+
...(optional.startParams === undefined ? {} : { startParams: optional.startParams }),
|
|
100
|
+
});
|
|
101
|
+
const issued = { authorizationUrl: start.authorizationUrl, attemptId: start.attemptId, expiresAt: start.expiresAt };
|
|
102
|
+
watchDesktopCompletion(scope, { connectionId, attemptId: issued.attemptId, completion: start.completion });
|
|
103
|
+
scope.onSignInIssued?.({ ...issued, pluginId, connectionId });
|
|
104
|
+
return issued;
|
|
105
|
+
}
|
|
106
|
+
/** Confirm or cancel a staged account switch; refused for a shared-app binding, which never stages one. */
|
|
107
|
+
async function settleSwitch({ scope, connectionId, settle }) {
|
|
108
|
+
const { host, workspaceId } = scope;
|
|
109
|
+
const { connection, connectionRef, actorId } = await resolveForActor({ scope, connectionId });
|
|
110
|
+
if (await isSharedBinding(host, connection))
|
|
111
|
+
throw host.notAvailable();
|
|
112
|
+
const service = host.service({ connection });
|
|
113
|
+
const view = settle === "confirm"
|
|
114
|
+
? await service.confirmSwitchAccount({ connectionRef, workspaceId, actorId })
|
|
115
|
+
: await service.cancelSwitchAccount({ connectionRef, workspaceId });
|
|
116
|
+
return statusFrom(host, connection, await viewAfterAction({ host, connectionRef, view }), connectionRef);
|
|
117
|
+
}
|
|
118
|
+
async function disconnectConnection({ scope, connectionId }) {
|
|
119
|
+
const { host, workspaceId } = scope;
|
|
120
|
+
const { connection, connectionRef } = await resolveForActor({ scope, connectionId });
|
|
121
|
+
if (host.sharedOAuth && await host.sharedOAuth.hasBinding(connection)) {
|
|
122
|
+
await host.sharedOAuth.stopUsing(connection);
|
|
123
|
+
return { ...(await statusFrom(host, connection, NEVER_CONNECTED, connectionRef)), revocation: "not-needed" };
|
|
124
|
+
}
|
|
125
|
+
const outcome = await host.service({ connection }).disconnect({ connectionRef, workspaceId });
|
|
126
|
+
// Same vocabulary on both sides: the provider's outcome passes through unchanged.
|
|
127
|
+
return { ...(await statusFrom(host, connection, await viewAfterAction({ host, connectionRef, view: outcome }), connectionRef)), revocation: outcome.remoteRevocation };
|
|
128
|
+
}
|
|
35
129
|
/**
|
|
36
130
|
* Builds the per-call connections port for one plugin, workspace and (for account actions) admin.
|
|
37
131
|
* @complexity Each call: one contribution load plus one record read or one service call.
|
|
38
132
|
*/
|
|
39
133
|
export function createAdminSurfaceConnections(required, _optional = {}) {
|
|
40
|
-
const { host, pluginId, workspaceId
|
|
41
|
-
async function resolve(connectionId) {
|
|
42
|
-
const connection = workspaceId === host.workspaceId ? (await host.listConnections({ pluginId })).find((candidate) => candidate.descriptor.connectionId === connectionId) : undefined;
|
|
43
|
-
if (!connection)
|
|
44
|
-
throw host.notAvailable();
|
|
45
|
-
return { connection, connectionRef: host.connectionKey({ workspaceId, pluginId, connectionId }) };
|
|
46
|
-
}
|
|
47
|
-
/** Account actions need the admin the route authenticated; Jini checks it too. */
|
|
48
|
-
async function forActor(connectionId) {
|
|
49
|
-
if (principalId === undefined)
|
|
50
|
-
throw host.notAvailable();
|
|
51
|
-
return { ...(await resolve(connectionId)), actorId: principalId };
|
|
52
|
-
}
|
|
53
|
-
/** An action's result view, its staged-switch label re-read from the record so an expired one never shows. */
|
|
54
|
-
async function viewAfterAction(connectionRef, view) {
|
|
55
|
-
return { ...view, pendingSwitch: liveStagedAccount(host, (await host.readRecord({ key: connectionRef }))?.staged) };
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Desktop: deposit the callback fields once the loopback sign-in redeemed, and clear a failed
|
|
59
|
-
* attempt; a failure is kept (code and next action only) for `status` and logged by code only.
|
|
60
|
-
*/
|
|
61
|
-
function watchDesktopCompletion(connectionId, attemptId, completion) {
|
|
62
|
-
const connectionRef = host.connectionKey({ workspaceId, pluginId, connectionId });
|
|
63
|
-
void completion?.then((done) => {
|
|
64
|
-
if (!done)
|
|
65
|
-
return;
|
|
66
|
-
host.attempts.delete(connectionRef);
|
|
67
|
-
host.callbackInbox.deposit({ workspaceId, pluginId, connectionId, attemptId, fields: done.callbackFields });
|
|
68
|
-
},
|
|
69
|
-
// Error codes only: a desktop sign-in that failed after the browser opened.
|
|
70
|
-
(error) => {
|
|
71
|
-
host.attempts.set(connectionRef, failedAttempt(error));
|
|
72
|
-
console.warn(`[admin-surfaces] desktop sign-in for '${pluginId}' did not complete: ${codeOf(error)}`);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
134
|
+
const { host, pluginId, workspaceId } = required;
|
|
75
135
|
return {
|
|
76
136
|
async getAccessToken({ connectionId }) {
|
|
77
|
-
const { connectionRef } = await
|
|
137
|
+
const { connectionRef } = await resolveForActor({ scope: required, connectionId });
|
|
78
138
|
const pinned = host.pinnedTokenOptions?.({ signal: required.signal, connectionRef }) ?? {};
|
|
79
139
|
return host.getAccessToken({ workspaceId, pluginId, connectionRef }, pinned);
|
|
80
140
|
},
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return statusFrom(host, connection, shared ? { ...shared, account, pendingSwitch: null } : NEVER_CONNECTED, connectionRef);
|
|
87
|
-
}
|
|
88
|
-
const record = await host.readRecord({ key: connectionRef });
|
|
89
|
-
return statusFrom(host, connection, record ? { ...record, pendingSwitch: liveStagedAccount(host, record.staged) } : NEVER_CONNECTED, connectionRef);
|
|
90
|
-
},
|
|
91
|
-
async begin({ connectionId, action }, optional = {}) {
|
|
92
|
-
const { connection, actorId } = await forActor(connectionId);
|
|
93
|
-
const shared = host.sharedOAuth && await host.sharedOAuth.hasBinding(connection);
|
|
94
|
-
if (shared && ADMIN_SURFACE_ACTION_INTENTS[action] === "switch-account")
|
|
95
|
-
throw host.notAvailable();
|
|
96
|
-
const start = await host.startSignIn({ connection, actorId, intent: ADMIN_SURFACE_ACTION_INTENTS[action], scopeSetIds: optional.scopeSetIds ?? [],
|
|
97
|
-
...(shared ? { destination: "shared" } : {}) }, {
|
|
98
|
-
...(optional.startParams === undefined ? {} : { startParams: optional.startParams }),
|
|
99
|
-
});
|
|
100
|
-
const issued = { authorizationUrl: start.authorizationUrl, attemptId: start.attemptId, expiresAt: start.expiresAt };
|
|
101
|
-
watchDesktopCompletion(connectionId, issued.attemptId, start.completion);
|
|
102
|
-
required.onSignInIssued?.({ ...issued, pluginId, connectionId });
|
|
103
|
-
return issued;
|
|
104
|
-
},
|
|
105
|
-
async confirmSwitch({ connectionId }) {
|
|
106
|
-
const { connection, connectionRef, actorId } = await forActor(connectionId);
|
|
107
|
-
if (host.sharedOAuth && await host.sharedOAuth.hasBinding(connection))
|
|
108
|
-
throw host.notAvailable();
|
|
109
|
-
const view = await host.service({ connection }).confirmSwitchAccount({ connectionRef, workspaceId, actorId });
|
|
110
|
-
return statusFrom(host, connection, await viewAfterAction(connectionRef, view), connectionRef);
|
|
111
|
-
},
|
|
112
|
-
async cancelSwitch({ connectionId }) {
|
|
113
|
-
const { connection, connectionRef } = await forActor(connectionId);
|
|
114
|
-
if (host.sharedOAuth && await host.sharedOAuth.hasBinding(connection))
|
|
115
|
-
throw host.notAvailable();
|
|
116
|
-
const view = await host.service({ connection }).cancelSwitchAccount({ connectionRef, workspaceId });
|
|
117
|
-
return statusFrom(host, connection, await viewAfterAction(connectionRef, view), connectionRef);
|
|
118
|
-
},
|
|
119
|
-
async disconnect({ connectionId }) {
|
|
120
|
-
const { connection, connectionRef } = await forActor(connectionId);
|
|
121
|
-
if (host.sharedOAuth && await host.sharedOAuth.hasBinding(connection)) {
|
|
122
|
-
await host.sharedOAuth.stopUsing(connection);
|
|
123
|
-
return { ...(await statusFrom(host, connection, NEVER_CONNECTED, connectionRef)), revocation: "not-needed" };
|
|
124
|
-
}
|
|
125
|
-
const outcome = await host.service({ connection }).disconnect({ connectionRef, workspaceId });
|
|
126
|
-
// Same vocabulary on both sides: the provider's outcome passes through unchanged.
|
|
127
|
-
return { ...(await statusFrom(host, connection, await viewAfterAction(connectionRef, outcome), connectionRef)), revocation: outcome.remoteRevocation };
|
|
128
|
-
},
|
|
141
|
+
status: ({ connectionId }) => connectionStatus({ scope: required, connectionId }),
|
|
142
|
+
begin: (args, optional = {}) => beginSignIn({ scope: required, args, optional }),
|
|
143
|
+
confirmSwitch: ({ connectionId }) => settleSwitch({ scope: required, connectionId, settle: "confirm" }),
|
|
144
|
+
cancelSwitch: ({ connectionId }) => settleSwitch({ scope: required, connectionId, settle: "cancel" }),
|
|
145
|
+
disconnect: ({ connectionId }) => disconnectConnection({ scope: required, connectionId }),
|
|
129
146
|
async takeCallbackFields({ connectionId, attemptId }) {
|
|
130
|
-
await
|
|
147
|
+
await resolveConnection({ scope: required, connectionId });
|
|
131
148
|
return host.callbackInbox.take({ workspaceId, pluginId, connectionId, attemptId });
|
|
132
149
|
},
|
|
133
150
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** One link the host page may offer: the host's own authorization URL and when its attempt expires. */
|
|
2
|
+
export interface HostSignInLink {
|
|
3
|
+
readonly authorizationUrl: string;
|
|
4
|
+
readonly expiresAt: string;
|
|
5
|
+
}
|
|
6
|
+
export interface IssuedSignInCollector {
|
|
7
|
+
/** Called by the connections port for each issued sign-in; outside a collection it is a no-op. */
|
|
8
|
+
record(required: HostSignInLink, optional?: Record<string, never>): void;
|
|
9
|
+
/** Runs one action and returns what it issued. */
|
|
10
|
+
collect<T>(required: {
|
|
11
|
+
readonly run: () => Promise<T>;
|
|
12
|
+
}, optional?: Record<string, never>): Promise<{
|
|
13
|
+
readonly value: T;
|
|
14
|
+
readonly signIns: readonly HostSignInLink[];
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @param admitHttp - Whether a plain-http link is the host's own sign-in link (which follows the site's
|
|
19
|
+
* scheme). Every other link must be https.
|
|
20
|
+
* @complexity O(1) per record; collect adds O(1) around the run.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createIssuedSignInCollector({ admitHttp }: {
|
|
23
|
+
admitHttp: (required: {
|
|
24
|
+
url: URL;
|
|
25
|
+
}) => boolean;
|
|
26
|
+
}, _optional?: {}): IssuedSignInCollector;
|
|
27
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The per-request registry of sign-in links the host issued while running one admin-surface
|
|
3
|
+
* action, so the admin route can hand the HOST PAGE exactly those links to open. Bind `record` to the
|
|
4
|
+
* connections port's `onSignInIssued`, and wrap each action dispatch in `collect`.
|
|
5
|
+
*
|
|
6
|
+
* Why: a plugin's frame is sandboxed without `allow-popups`, so it cannot open a sign-in itself, and the
|
|
7
|
+
* host page must never open a URL a plugin made up (an open redirect or phishing page under the
|
|
8
|
+
* operator's trust). AsyncLocalStorage keeps concurrent requests apart. Only https links, and plain-http
|
|
9
|
+
* links the host admits as its own sign-in links, are kept.
|
|
10
|
+
*/
|
|
11
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
12
|
+
/**
|
|
13
|
+
* @param admitHttp - Whether a plain-http link is the host's own sign-in link (which follows the site's
|
|
14
|
+
* scheme). Every other link must be https.
|
|
15
|
+
* @complexity O(1) per record; collect adds O(1) around the run.
|
|
16
|
+
*/
|
|
17
|
+
export function createIssuedSignInCollector({ admitHttp }, _optional = {}) {
|
|
18
|
+
const current = new AsyncLocalStorage();
|
|
19
|
+
return {
|
|
20
|
+
record({ authorizationUrl, expiresAt }) {
|
|
21
|
+
const url = URL.parse(authorizationUrl);
|
|
22
|
+
if (url && (url.protocol === 'https:' || (url.protocol === 'http:' && admitHttp({ url }))))
|
|
23
|
+
current.getStore()?.push({ authorizationUrl, expiresAt });
|
|
24
|
+
},
|
|
25
|
+
async collect({ run }) {
|
|
26
|
+
const signIns = [];
|
|
27
|
+
const value = await current.run(signIns, run);
|
|
28
|
+
return { value, signIns };
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -29,6 +29,26 @@ function checkedValue(value) {
|
|
|
29
29
|
}
|
|
30
30
|
return JSON.parse(text);
|
|
31
31
|
}
|
|
32
|
+
function createPluginSettingWriter({ vault, scope, format }, { rowId, isConflict }) {
|
|
33
|
+
/** The existing row's revision comes from the summary listing, which opens no envelope: a row sealed
|
|
34
|
+
* under a key this machine no longer has (a lost or re-minted store key) can still be overwritten,
|
|
35
|
+
* so the user re-enters the setting instead of being stuck behind an error. */
|
|
36
|
+
return async function write(input, key, value) {
|
|
37
|
+
const id = rowId(input, key);
|
|
38
|
+
const stored = checkedValue(value);
|
|
39
|
+
const rows = await vault.list({ ...scope });
|
|
40
|
+
const existing = rows.find((row) => row.id === id);
|
|
41
|
+
if (!existing && rows.filter((row) => row.id.startsWith(rowPrefix(input.pluginId))).length >= PLUGIN_STATE_MAX_KEYS)
|
|
42
|
+
throw new Error(`A plugin may keep at most ${PLUGIN_STATE_MAX_KEYS} settings here. Remove one and retry.`);
|
|
43
|
+
await vault.put({ ...scope, id, expectedRevision: existing?.revision ?? null, provider: null, label: `Plugin settings ${id}`,
|
|
44
|
+
meta: { credentialFormat: format }, payload: { value: stored } })
|
|
45
|
+
.catch((error) => {
|
|
46
|
+
if (isConflict(error))
|
|
47
|
+
throw new Error("This setting changed while it was being saved. Reload the plugin's settings and retry.", { cause: error });
|
|
48
|
+
throw error;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
}
|
|
32
52
|
/**
|
|
33
53
|
* Creates the workspace's plugin-state store over the api-connection vault.
|
|
34
54
|
* @param required.vault - The workspace's api-connection vault (`createApiConnectionVault`).
|
|
@@ -60,24 +80,7 @@ export function createAgentPluginStateStore(required, _optional = {}) {
|
|
|
60
80
|
.sort((a, b) => (a.key < b.key ? -1 : 1));
|
|
61
81
|
return { keys };
|
|
62
82
|
}
|
|
63
|
-
|
|
64
|
-
* under a key this machine no longer has (a lost or re-minted store key) can still be overwritten,
|
|
65
|
-
* so the user re-enters the setting instead of being stuck behind an error. */
|
|
66
|
-
async function write(input, key, value) {
|
|
67
|
-
const id = rowId(input, key);
|
|
68
|
-
const stored = checkedValue(value);
|
|
69
|
-
const rows = await vault.list({ ...scope });
|
|
70
|
-
const existing = rows.find((row) => row.id === id);
|
|
71
|
-
if (!existing && rows.filter((row) => row.id.startsWith(rowPrefix(input.pluginId))).length >= PLUGIN_STATE_MAX_KEYS)
|
|
72
|
-
throw new Error(`A plugin may keep at most ${PLUGIN_STATE_MAX_KEYS} settings here. Remove one and retry.`);
|
|
73
|
-
await vault.put({ ...scope, id, expectedRevision: existing?.revision ?? null, provider: null, label: `Plugin settings ${id}`,
|
|
74
|
-
meta: { credentialFormat: format }, payload: { value: stored } })
|
|
75
|
-
.catch((error) => {
|
|
76
|
-
if (isConflict(error))
|
|
77
|
-
throw new Error("This setting changed while it was being saved. Reload the plugin's settings and retry.", { cause: error });
|
|
78
|
-
throw error;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
83
|
+
const write = createPluginSettingWriter({ vault, scope, format }, { rowId, isConflict });
|
|
81
84
|
function readerFor(input) {
|
|
82
85
|
return {
|
|
83
86
|
async get({ key }) {
|
|
@@ -102,14 +102,18 @@ export declare function createAdminSurfaceClient(required: {
|
|
|
102
102
|
readonly browser?: AdminSurfaceBrowserScope;
|
|
103
103
|
}): {
|
|
104
104
|
ready: Promise<void>;
|
|
105
|
+
/** Asks the host to run one declared action; resolves with its result. */
|
|
105
106
|
call: (input: {
|
|
106
107
|
readonly action: string;
|
|
107
108
|
readonly payload: unknown;
|
|
108
109
|
}) => Promise<unknown>;
|
|
110
|
+
/** Asks the host to open `url` outside the sandbox; only https links on the surface's declared
|
|
111
|
+
* `linkOrigins` open, and the host decides how (new tab, system browser). Rejects with the host's refusal. */
|
|
109
112
|
openLink: (input: {
|
|
110
113
|
readonly url: string;
|
|
111
114
|
}) => Promise<void>;
|
|
112
115
|
bootstrap: () => unknown;
|
|
116
|
+
/** The host's theme as applied, or `undefined` when the host sent none. */
|
|
113
117
|
theme: () => AdminSurfaceClientTheme | undefined;
|
|
114
118
|
close: () => void;
|
|
115
119
|
};
|
|
@@ -94,6 +94,103 @@ function documentSize(scope) {
|
|
|
94
94
|
function isWellFormedResponse(message) {
|
|
95
95
|
return message.ok === true ? Object.hasOwn(message, 'result') : message.ok === false && isFailure(message.error);
|
|
96
96
|
}
|
|
97
|
+
/** Tells the host this surface's height (only when it changed), so the frame fits its content. */
|
|
98
|
+
function reportHeight({ state, height }) {
|
|
99
|
+
const { init } = state;
|
|
100
|
+
if (init === undefined || !Number.isFinite(height) || height === state.lastHeight)
|
|
101
|
+
return;
|
|
102
|
+
state.lastHeight = height;
|
|
103
|
+
state.parent.postMessage({ protocol: PROTOCOL, version: VERSION, kind: 'resize', mountId: init.mountId, height }, init.origin);
|
|
104
|
+
}
|
|
105
|
+
/** Replaces the applied tokens: a token the new theme no longer sends falls back to the surface's CSS. */
|
|
106
|
+
function applyTheme({ state, value }) {
|
|
107
|
+
const next = acceptedTheme(value);
|
|
108
|
+
if (next === undefined)
|
|
109
|
+
return;
|
|
110
|
+
const { themeRoot } = state;
|
|
111
|
+
if (themeRoot !== null) {
|
|
112
|
+
for (const name of Object.keys(state.currentTheme?.tokens ?? {}))
|
|
113
|
+
if (!(name in next.tokens))
|
|
114
|
+
themeRoot.style.removeProperty(name);
|
|
115
|
+
for (const [name, token] of Object.entries(next.tokens))
|
|
116
|
+
themeRoot.style.setProperty(name, token);
|
|
117
|
+
themeRoot.style.setProperty('color-scheme', next.scheme);
|
|
118
|
+
themeRoot.setAttribute('data-jini-scheme', next.scheme);
|
|
119
|
+
}
|
|
120
|
+
state.currentTheme = next;
|
|
121
|
+
}
|
|
122
|
+
function onInit({ state, event, data }) {
|
|
123
|
+
if (state.init !== undefined || typeof data.mountId !== 'string')
|
|
124
|
+
return;
|
|
125
|
+
state.init = { mountId: data.mountId, origin: event.origin, bootstrap: data.bootstrap };
|
|
126
|
+
applyTheme({ state, value: data.theme });
|
|
127
|
+
state.stopSize = state.size?.((height) => reportHeight({ state, height }));
|
|
128
|
+
state.resolveReady();
|
|
129
|
+
}
|
|
130
|
+
function onResponse({ state, event, data }) {
|
|
131
|
+
const { init, pending } = state;
|
|
132
|
+
if (event.origin !== init?.origin || data.mountId !== init.mountId || typeof data.requestId !== 'string')
|
|
133
|
+
return;
|
|
134
|
+
const waiting = pending.get(data.requestId);
|
|
135
|
+
if (waiting === undefined || !isWellFormedResponse(data))
|
|
136
|
+
return;
|
|
137
|
+
pending.delete(data.requestId);
|
|
138
|
+
clearTimeout(waiting.timer);
|
|
139
|
+
if (data.ok === true)
|
|
140
|
+
waiting.resolve(data.result);
|
|
141
|
+
else
|
|
142
|
+
waiting.reject(new AdminSurfaceCallError(data.error));
|
|
143
|
+
}
|
|
144
|
+
/** Routes one message from the parent window: init, a theme update, or an action response. */
|
|
145
|
+
function onParentMessage(state, event) {
|
|
146
|
+
if (event.source !== state.parent)
|
|
147
|
+
return;
|
|
148
|
+
if (isMessage(event.data, 'init')) {
|
|
149
|
+
onInit({ state, event, data: event.data });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (isMessage(event.data, 'theme')) {
|
|
153
|
+
if (event.origin === state.init?.origin && event.data.mountId === state.init.mountId)
|
|
154
|
+
applyTheme({ state, value: event.data.theme });
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (isMessage(event.data, 'action-response'))
|
|
158
|
+
onResponse({ state, event, data: event.data });
|
|
159
|
+
}
|
|
160
|
+
/** Posts one request of `kind` to the host origin and waits for its `action-response`. */
|
|
161
|
+
async function sendRequest({ state, ready, kind, fields }) {
|
|
162
|
+
if (state.init === undefined)
|
|
163
|
+
await ready;
|
|
164
|
+
const { mountId, origin } = state.init;
|
|
165
|
+
state.nextRequest += 1;
|
|
166
|
+
const requestId = `r${state.nextRequest}`;
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
const timer = setTimeout(() => {
|
|
169
|
+
state.pending.delete(requestId);
|
|
170
|
+
reject(new AdminSurfaceCallError({ code: 'timeout', message: 'The host did not answer in time. Try again.', retryable: true }));
|
|
171
|
+
}, state.timeoutMs);
|
|
172
|
+
state.pending.set(requestId, { resolve, reject, timer });
|
|
173
|
+
state.parent.postMessage({ protocol: PROTOCOL, version: VERSION, kind, mountId, requestId, ...fields }, origin);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/** The bootstrap `data` the host sent with init, or `undefined` once it has expired (or none was sent). */
|
|
177
|
+
function readBootstrap(state) {
|
|
178
|
+
const envelope = state.init?.bootstrap;
|
|
179
|
+
if (typeof envelope !== 'object' || envelope === null)
|
|
180
|
+
return undefined;
|
|
181
|
+
const { expiresAt, data } = envelope;
|
|
182
|
+
return typeof expiresAt === 'number' && state.nowMs() < expiresAt ? data : undefined;
|
|
183
|
+
}
|
|
184
|
+
/** Stops listening and rejects every pending call. */
|
|
185
|
+
function closeClient({ state, unsubscribe }) {
|
|
186
|
+
unsubscribe();
|
|
187
|
+
state.stopSize?.();
|
|
188
|
+
for (const [requestId, waiting] of state.pending) {
|
|
189
|
+
clearTimeout(waiting.timer);
|
|
190
|
+
waiting.reject(new AdminSurfaceCallError({ code: 'closed', message: 'The surface was closed before the host answered.', retryable: false }));
|
|
191
|
+
state.pending.delete(requestId);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
97
194
|
/**
|
|
98
195
|
* Connects a surface to its host. In a browser:
|
|
99
196
|
* `createAdminSurfaceClient({ parent: window.parent, listen: (h) => { addEventListener('message', h); return () => removeEventListener('message', h); } })`.
|
|
@@ -101,127 +198,37 @@ function isWellFormedResponse(message) {
|
|
|
101
198
|
* @complexity O(1) per message.
|
|
102
199
|
*/
|
|
103
200
|
export function createAdminSurfaceClient(required, optional = {}) {
|
|
104
|
-
const timeoutMs = optional.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
105
|
-
const nowMs = optional.nowMs ?? Date.now;
|
|
106
|
-
const pending = new Map();
|
|
107
|
-
let init;
|
|
108
|
-
let nextRequest = 0;
|
|
109
201
|
// The Promise executor runs synchronously, so `resolveReady` is assigned before anything can call it.
|
|
110
202
|
let resolveReady;
|
|
111
203
|
const ready = new Promise((resolve) => { resolveReady = resolve; });
|
|
112
204
|
// The DOM's own observer/element types are wider than the structural subset this client reads.
|
|
113
205
|
const browser = optional.browser ?? globalThis;
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
function onInit(event, data) {
|
|
143
|
-
if (init !== undefined || typeof data.mountId !== 'string')
|
|
144
|
-
return;
|
|
145
|
-
init = { mountId: data.mountId, origin: event.origin, bootstrap: data.bootstrap };
|
|
146
|
-
applyTheme(data.theme);
|
|
147
|
-
stopSize = size?.(reportHeight);
|
|
148
|
-
resolveReady();
|
|
149
|
-
}
|
|
150
|
-
function onResponse(event, data) {
|
|
151
|
-
if (event.origin !== init?.origin || data.mountId !== init.mountId || typeof data.requestId !== 'string')
|
|
152
|
-
return;
|
|
153
|
-
const waiting = pending.get(data.requestId);
|
|
154
|
-
if (waiting === undefined || !isWellFormedResponse(data))
|
|
155
|
-
return;
|
|
156
|
-
pending.delete(data.requestId);
|
|
157
|
-
clearTimeout(waiting.timer);
|
|
158
|
-
if (data.ok === true)
|
|
159
|
-
waiting.resolve(data.result);
|
|
160
|
-
else
|
|
161
|
-
waiting.reject(new AdminSurfaceCallError(data.error));
|
|
162
|
-
}
|
|
163
|
-
const unsubscribe = required.listen((event) => {
|
|
164
|
-
if (event.source !== required.parent)
|
|
165
|
-
return;
|
|
166
|
-
if (isMessage(event.data, 'init')) {
|
|
167
|
-
onInit(event, event.data);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
if (isMessage(event.data, 'theme')) {
|
|
171
|
-
if (event.origin === init?.origin && event.data.mountId === init.mountId)
|
|
172
|
-
applyTheme(event.data.theme);
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (isMessage(event.data, 'action-response'))
|
|
176
|
-
onResponse(event, event.data);
|
|
177
|
-
});
|
|
178
|
-
/** Posts one request of `kind` to the host origin and waits for its `action-response`. */
|
|
179
|
-
async function send(kind, fields) {
|
|
180
|
-
if (init === undefined)
|
|
181
|
-
await ready;
|
|
182
|
-
const { mountId, origin } = init;
|
|
183
|
-
nextRequest += 1;
|
|
184
|
-
const requestId = `r${nextRequest}`;
|
|
185
|
-
return new Promise((resolve, reject) => {
|
|
186
|
-
const timer = setTimeout(() => {
|
|
187
|
-
pending.delete(requestId);
|
|
188
|
-
reject(new AdminSurfaceCallError({ code: 'timeout', message: 'The host did not answer in time. Try again.', retryable: true }));
|
|
189
|
-
}, timeoutMs);
|
|
190
|
-
pending.set(requestId, { resolve, reject, timer });
|
|
191
|
-
required.parent.postMessage({ protocol: PROTOCOL, version: VERSION, kind, mountId, requestId, ...fields }, origin);
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
/** Asks the host to run one declared action; resolves with its result. */
|
|
195
|
-
function call(input) {
|
|
196
|
-
return send('action-request', { action: input.action, payload: input.payload });
|
|
197
|
-
}
|
|
198
|
-
/** Asks the host to open `url` outside the sandbox; only https links on the surface's declared
|
|
199
|
-
* `linkOrigins` open, and the host decides how (new tab, system browser). Rejects with the host's refusal. */
|
|
200
|
-
async function openLink(input) {
|
|
201
|
-
await send('open-link', { url: input.url });
|
|
202
|
-
}
|
|
203
|
-
/** The bootstrap `data` the host sent with init, or `undefined` once it has expired (or none was sent). */
|
|
204
|
-
function bootstrap() {
|
|
205
|
-
const envelope = init?.bootstrap;
|
|
206
|
-
if (typeof envelope !== 'object' || envelope === null)
|
|
207
|
-
return undefined;
|
|
208
|
-
const { expiresAt, data } = envelope;
|
|
209
|
-
return typeof expiresAt === 'number' && nowMs() < expiresAt ? data : undefined;
|
|
210
|
-
}
|
|
211
|
-
/** The host's theme as applied, or `undefined` when the host sent none. */
|
|
212
|
-
function theme() {
|
|
213
|
-
return currentTheme;
|
|
214
|
-
}
|
|
215
|
-
/** Stops listening and rejects every pending call. */
|
|
216
|
-
function close() {
|
|
217
|
-
unsubscribe();
|
|
218
|
-
stopSize?.();
|
|
219
|
-
for (const [requestId, waiting] of pending) {
|
|
220
|
-
clearTimeout(waiting.timer);
|
|
221
|
-
waiting.reject(new AdminSurfaceCallError({ code: 'closed', message: 'The surface was closed before the host answered.', retryable: false }));
|
|
222
|
-
pending.delete(requestId);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return { ready, call, openLink, bootstrap, theme, close };
|
|
206
|
+
const state = {
|
|
207
|
+
parent: required.parent,
|
|
208
|
+
timeoutMs: optional.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
209
|
+
nowMs: optional.nowMs ?? Date.now,
|
|
210
|
+
pending: new Map(),
|
|
211
|
+
themeRoot: optional.themeRoot === undefined ? documentRoot(browser) : optional.themeRoot,
|
|
212
|
+
size: optional.size === undefined ? documentSize(browser) : optional.size,
|
|
213
|
+
init: undefined, nextRequest: 0, currentTheme: undefined, stopSize: undefined, lastHeight: -1, resolveReady,
|
|
214
|
+
};
|
|
215
|
+
const unsubscribe = required.listen((event) => onParentMessage(state, event));
|
|
216
|
+
return {
|
|
217
|
+
ready,
|
|
218
|
+
/** Asks the host to run one declared action; resolves with its result. */
|
|
219
|
+
call: (input) => sendRequest({
|
|
220
|
+
state,
|
|
221
|
+
ready,
|
|
222
|
+
kind: 'action-request',
|
|
223
|
+
fields: { action: input.action, payload: input.payload },
|
|
224
|
+
}),
|
|
225
|
+
/** Asks the host to open `url` outside the sandbox; only https links on the surface's declared
|
|
226
|
+
* `linkOrigins` open, and the host decides how (new tab, system browser). Rejects with the host's refusal. */
|
|
227
|
+
openLink: async (input) => { await sendRequest({ state, ready, kind: 'open-link', fields: { url: input.url } }); },
|
|
228
|
+
bootstrap: () => readBootstrap(state),
|
|
229
|
+
/** The host's theme as applied, or `undefined` when the host sent none. */
|
|
230
|
+
theme: () => state.currentTheme,
|
|
231
|
+
close: () => closeClient({ state, unsubscribe }),
|
|
232
|
+
};
|
|
226
233
|
}
|
|
227
234
|
//# sourceMappingURL=surface-client.js.map
|
|
@@ -70,23 +70,7 @@ function admissionRefusal({ descriptor, module }) {
|
|
|
70
70
|
}
|
|
71
71
|
/** Plugin and surface ids cannot contain NUL, so the key is unambiguous. */
|
|
72
72
|
const keyOf = (pluginId, surfaceId) => `${pluginId}\u0000${surfaceId}`;
|
|
73
|
-
|
|
74
|
-
* Holds the admitted handler modules and answers for them. Call `sync` with every load of
|
|
75
|
-
* `defineAdminSurfaceHandlerContribution` (on boot and on every activation change); a surface missing
|
|
76
|
-
* from a load loses its handlers, and capabilities its module kept are revoked.
|
|
77
|
-
* @param required.capabilities - Host port building one call's admin-surface capabilities.
|
|
78
|
-
* @param required.issuedTokens - Per-plugin token memory shared with the plugin's tool projection.
|
|
79
|
-
* @param required.hostKind - The kind of host this process is; every handler and bootstrap call sees it.
|
|
80
|
-
* @throws TypeError when `hostKind` is neither `hosted` nor `desktop`.
|
|
81
|
-
* @returns `sync`, plus `handlersFor` and `bootstrapData` for the host's action dispatcher and bootstrap route.
|
|
82
|
-
* @complexity sync is O(s + a) surfaces and actions; lookups are O(1).
|
|
83
|
-
*/
|
|
84
|
-
export function createAdminSurfaceHandlerHost(required, _optional = {}) {
|
|
85
|
-
// Checked at run time too: a JavaScript host may pass an unchecked config value, and a plugin would pick its flow from it.
|
|
86
|
-
if (!HOST_KINDS.includes(required.hostKind))
|
|
87
|
-
throw new TypeError("createAdminSurfaceHandlerHost: hostKind must be 'hosted' or 'desktop'.");
|
|
88
|
-
const { hostKind } = required;
|
|
89
|
-
let admitted = new Map();
|
|
73
|
+
function createSurfaceCallHandlers(required, hostKind) {
|
|
90
74
|
/** One call's capability session, scoped to the loaded plugin and the route's workspace/principal. */
|
|
91
75
|
function sessionFor(self, context) {
|
|
92
76
|
const { pluginId, descriptor } = self.loaded;
|
|
@@ -104,6 +88,26 @@ export function createAdminSurfaceHandlerHost(required, _optional = {}) {
|
|
|
104
88
|
return runInCapabilitySession({ session, run: async () => session.release({ value: await run({ input: payload, capabilities: session.capabilities, context, fail }) }) });
|
|
105
89
|
};
|
|
106
90
|
}
|
|
91
|
+
return { sessionFor, actionHandler };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Holds the admitted handler modules and answers for them. Call `sync` with every load of
|
|
95
|
+
* `defineAdminSurfaceHandlerContribution` (on boot and on every activation change); a surface missing
|
|
96
|
+
* from a load loses its handlers, and capabilities its module kept are revoked.
|
|
97
|
+
* @param required.capabilities - Host port building one call's admin-surface capabilities.
|
|
98
|
+
* @param required.issuedTokens - Per-plugin token memory shared with the plugin's tool projection.
|
|
99
|
+
* @param required.hostKind - The kind of host this process is; every handler and bootstrap call sees it.
|
|
100
|
+
* @throws TypeError when `hostKind` is neither `hosted` nor `desktop`.
|
|
101
|
+
* @returns `sync`, plus `handlersFor` and `bootstrapData` for the host's action dispatcher and bootstrap route.
|
|
102
|
+
* @complexity sync is O(s + a) surfaces and actions; lookups are O(1).
|
|
103
|
+
*/
|
|
104
|
+
export function createAdminSurfaceHandlerHost(required, _optional = {}) {
|
|
105
|
+
// Checked at run time too: a JavaScript host may pass an unchecked config value, and a plugin would pick its flow from it.
|
|
106
|
+
if (!HOST_KINDS.includes(required.hostKind))
|
|
107
|
+
throw new TypeError("createAdminSurfaceHandlerHost: hostKind must be 'hosted' or 'desktop'.");
|
|
108
|
+
const { hostKind } = required;
|
|
109
|
+
let admitted = new Map();
|
|
110
|
+
const { sessionFor, actionHandler } = createSurfaceCallHandlers(required, hostKind);
|
|
107
111
|
/** A generation for one surface; live only while `admitted` holds this exact object. */
|
|
108
112
|
function admit(key, loaded) {
|
|
109
113
|
const declared = loaded.descriptor.actions.filter((action) => Object.hasOwn(loaded.module.actions, action.name));
|