@jini-ai/integrations 0.7.1 → 0.7.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -2
- package/README.md +1 -0
- package/dist/api-connections/access-token.js +4 -4
- package/dist/api-connections/account-actions.d.ts +10 -4
- package/dist/api-connections/account-actions.js +13 -13
- package/dist/api-connections/attempt-state.d.ts +11 -5
- package/dist/api-connections/attempt-state.js +4 -4
- package/dist/api-connections/authorization.d.ts +7 -3
- package/dist/api-connections/authorization.js +18 -18
- package/dist/api-connections/finish-authorization.d.ts +8 -4
- package/dist/api-connections/finish-authorization.js +9 -9
- package/dist/api-connections/host.d.ts +30 -32
- package/dist/api-connections/host.js +232 -205
- package/dist/api-connections/hosted-mcp/contracts.d.ts +1 -1
- package/dist/api-connections/hosted-mcp/oauth-row-writes.d.ts +50 -0
- package/dist/api-connections/hosted-mcp/oauth-row-writes.js +38 -0
- package/dist/api-connections/hosted-mcp/shared-sign-in.d.ts +40 -40
- package/dist/api-connections/hosted-mcp/shared-sign-in.js +98 -22
- package/dist/api-connections/hosted-mcp/sign-in-configuration.d.ts +29 -0
- package/dist/api-connections/hosted-mcp/sign-in-configuration.js +127 -0
- package/dist/api-connections/hosted-mcp/sign-in-discovery.d.ts +72 -0
- package/dist/api-connections/hosted-mcp/sign-in-discovery.js +131 -0
- package/dist/api-connections/hosted-mcp/sign-in-flow.d.ts +42 -0
- package/dist/api-connections/hosted-mcp/sign-in-flow.js +50 -0
- package/dist/api-connections/hosted-mcp/sign-in-provider.d.ts +103 -0
- package/dist/api-connections/hosted-mcp/sign-in-provider.js +142 -0
- package/dist/api-connections/hosted-mcp/sign-in-status.d.ts +19 -0
- package/dist/api-connections/hosted-mcp/sign-in-status.js +143 -0
- package/dist/api-connections/hosted-mcp/sign-in.d.ts +2 -9
- package/dist/api-connections/hosted-mcp/sign-in.js +219 -770
- package/dist/api-connections/index.js +1 -1
- package/dist/api-connections/install-credential.d.ts +4 -2
- package/dist/api-connections/install-credential.js +7 -7
- package/dist/api-connections/records.d.ts +17 -5
- package/dist/api-connections/records.js +5 -5
- package/dist/api-connections/request-checks.d.ts +29 -9
- package/dist/api-connections/request-checks.js +13 -13
- package/dist/api-connections/service.d.ts +1 -1
- package/dist/api-connections/service.js +6 -6
- package/dist/api-connections/status.d.ts +3 -1
- package/dist/api-connections/status.js +3 -3
- package/dist/api-connections/token-store/errors.d.ts +3 -1
- package/dist/api-connections/token-store/errors.js +1 -1
- package/dist/api-connections/token-store/vault-token-store.js +186 -173
- package/dist/args.d.ts +4 -1
- package/dist/args.js +1 -1
- package/dist/credentialed-http/credentialed-request.d.ts +5 -5
- package/dist/credentialed-http/credentialed-request.js +8 -8
- package/dist/credentialed-http/response-redaction.d.ts +18 -4
- package/dist/credentialed-http/response-redaction.js +7 -7
- package/dist/credentialed-http/sets/vault-repo.js +5 -1
- package/dist/credentialed-http/tools/credential-copy-tool.js +20 -15
- package/dist/credentialed-http/tools/tool-registrations.js +272 -249
- package/dist/media-providers/catalog.d.ts +1 -0
- package/dist/media-providers/catalog.js +1 -0
- package/dist/media-providers/dispatch/async-operation-store.d.ts +6 -4
- package/dist/media-providers/dispatch/async-operation-store.js +100 -88
- package/dist/media-providers/dispatch/context.js +1 -1
- package/dist/media-providers/dispatch/engine.d.ts +5 -1
- package/dist/media-providers/dispatch/engine.js +2 -2
- package/dist/media-providers/dispatch/index.d.ts +1 -1
- package/dist/media-providers/dispatch/index.js +1 -1
- package/dist/media-providers/dispatch/node.d.ts +1 -1
- package/dist/media-providers/dispatch/node.js +1 -1
- package/dist/media-providers/dispatch/openai-compatible.d.ts +50 -11
- package/dist/media-providers/dispatch/openai-compatible.js +21 -17
- package/dist/media-providers/dispatch/operation-runtime.js +18 -18
- package/dist/media-providers/dispatch/outbound.d.ts +2 -2
- package/dist/media-providers/dispatch/outbound.js +1 -1
- package/dist/media-providers/dispatch/polling-adapter.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +20 -6
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js +8 -8
- package/dist/media-providers/dispatch/providers/aihubmix.js +12 -12
- package/dist/media-providers/dispatch/providers/custom-image.js +4 -4
- package/dist/media-providers/dispatch/providers/fishaudio.js +2 -9
- package/dist/media-providers/dispatch/providers/grok.js +5 -19
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +22 -20
- package/dist/media-providers/dispatch/providers/imagerouter.js +7 -21
- package/dist/media-providers/dispatch/providers/minimax.js +2 -9
- package/dist/media-providers/dispatch/providers/nanobanana.js +2 -2
- package/dist/media-providers/dispatch/providers/openai.js +6 -6
- package/dist/media-providers/dispatch/providers/openrouter.js +4 -4
- package/dist/media-providers/dispatch/providers/senseaudio.js +5 -19
- package/dist/media-providers/dispatch/providers/volcengine.js +5 -12
- package/dist/media-providers/dispatch/response-parsers.js +3 -3
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +1 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +31 -5
- package/dist/media-providers/dispatch/ssrf-guard.js +5 -12
- package/dist/media-providers/dispatch/stub.js +2 -2
- package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
- package/dist/media-providers/image-model-ids.d.ts +36 -0
- package/dist/media-providers/image-model-ids.js +24 -0
- package/dist/media-providers/sqlite-driver.adapter.d.ts +1 -1
- package/dist/media-providers/sqlite-task-store.d.ts +2 -2
- package/dist/media-providers/sqlite-task-store.js +31 -4
- package/dist/media-providers/task-lifecycle.d.ts +17 -4
- package/dist/media-providers/task-lifecycle.js +4 -4
- package/dist/media-providers/task-store.js +28 -24
- package/dist/media-providers/ui-defaults.d.ts +7 -0
- package/dist/media-providers/ui-defaults.js +11 -17
- package/dist/saved-requests/types.d.ts +1 -1
- package/dist/webhooks/delivery.js +31 -27
- package/dist/webhooks/ports.d.ts +4 -1
- package/dist/webhooks/subscriptions.d.ts +7 -2
- package/dist/webhooks/subscriptions.js +30 -37
- package/dist/webhooks/tools/agent-tools.d.ts +82 -0
- package/dist/webhooks/tools/agent-tools.js +120 -0
- package/dist/webhooks/tools/index.d.ts +7 -0
- package/dist/webhooks/tools/index.js +5 -0
- package/dist/webhooks/tools/tool-handlers.d.ts +22 -0
- package/dist/webhooks/tools/tool-handlers.js +154 -0
- package/dist/webhooks/tools/tool-handlers.types.d.ts +64 -0
- package/dist/webhooks/tools/tool-handlers.types.js +2 -0
- package/dist/webhooks/tools/tool-registrations.d.ts +35 -0
- package/dist/webhooks/tools/tool-registrations.js +95 -0
- package/dist/webhooks/tools/tool-views.d.ts +62 -0
- package/dist/webhooks/tools/tool-views.js +50 -0
- package/dist/webhooks/types.d.ts +2 -0
- package/dist/webhooks/worker.d.ts +7 -4
- package/dist/webhooks/worker.js +22 -20
- package/package.json +16 -18
package/CHANGELOG.md
CHANGED
|
@@ -157,7 +157,7 @@
|
|
|
157
157
|
The existing `./media-providers` entry is `jini.runtime: "node"` and its barrel statically pulls in
|
|
158
158
|
`node:crypto`/`node:fs`/`node:path` (`staging.ts`), `node:dns` (`dispatch/ssrf-guard.ts`), and
|
|
159
159
|
`undici` (`dispatch/providers/openai.ts`). A browser consumer that only needs the provider list to
|
|
160
|
-
render a credentials screen —
|
|
160
|
+
render a credentials screen — the first host's admin SPA is the first — previously had no way to get it
|
|
161
161
|
without dragging the whole dispatch engine into its bundle.
|
|
162
162
|
|
|
163
163
|
`providers.ts` imports only types from `types.ts`, and `types.ts` imports nothing, so the pair is
|
|
@@ -195,7 +195,7 @@
|
|
|
195
195
|
|
|
196
196
|
### Patch Changes
|
|
197
197
|
|
|
198
|
-
-
|
|
198
|
+
- Host clean-up release (2026-10-08): code the first host moved into Jini, plus the Jini clean-up (see the commit log since 0.4.0).
|
|
199
199
|
|
|
200
200
|
## 0.6.19
|
|
201
201
|
|
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ exports. Import the capability you need; each entry owns its dependencies and ru
|
|
|
10
10
|
| `./credentialed-http` | Node | Credential-origin binding, authentication, redacted responses and audit ports |
|
|
11
11
|
| `./saved-requests` | Node | Fixed-target declarative requests, bounded schemas and typed public projections |
|
|
12
12
|
| `./webhooks` | Node | Subscriptions, delivery/retries and signing through host ports |
|
|
13
|
+
| `./webhooks/tools` | Node | Webhook agent tools: catalog, handlers, risk map and views over host repository, origin and confirmation ports |
|
|
13
14
|
|
|
14
15
|
## No root `.` export
|
|
15
16
|
|
|
@@ -26,7 +26,7 @@ async function markReconnectRequired(deps, key, options = {}) {
|
|
|
26
26
|
return;
|
|
27
27
|
if (options.expectedGeneration !== undefined && record.generation !== options.expectedGeneration)
|
|
28
28
|
return;
|
|
29
|
-
await writeRecord(deps, record, { status: 'reconnect-required' });
|
|
29
|
+
await writeRecord({ deps, current: record, patch: { status: 'reconnect-required' } });
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* The token store reads the live generation, so a confirmed switch, disconnect or reconnect that
|
|
@@ -34,7 +34,7 @@ async function markReconnectRequired(deps, key, options = {}) {
|
|
|
34
34
|
* unless the record still serves the same generation. A retry reads the new state consistently.
|
|
35
35
|
*/
|
|
36
36
|
async function assertUnchangedSince(deps, requiredArgs) {
|
|
37
|
-
const current = await loadOwnedRecord(deps, requiredArgs);
|
|
37
|
+
const current = await loadOwnedRecord({ deps, ...requiredArgs });
|
|
38
38
|
assertServable(current, requiredArgs.expectedAccountId);
|
|
39
39
|
if (current.generation !== requiredArgs.checked.generation) {
|
|
40
40
|
throw new ApiConnectionError({ code: 'storage-conflict',
|
|
@@ -61,10 +61,10 @@ export function createApiConnectionAccessTokens(deps) {
|
|
|
61
61
|
return {
|
|
62
62
|
async getAccessToken(requiredArgs, optionalArgs = {}) {
|
|
63
63
|
const { expectedAccountId } = optionalArgs;
|
|
64
|
-
const record = await loadOwnedRecord(deps, requiredArgs);
|
|
64
|
+
const record = await loadOwnedRecord({ deps, ...requiredArgs });
|
|
65
65
|
assertServable(record, expectedAccountId);
|
|
66
66
|
const accessToken = await refresher.getAccessToken({ key: record.key }).catch(async (error) => {
|
|
67
|
-
if (isUnreadableTokenRecord(error)) {
|
|
67
|
+
if (isUnreadableTokenRecord({ error })) {
|
|
68
68
|
await markReconnectRequired(deps, record.key, { expectedGeneration: record.generation });
|
|
69
69
|
throw new ApiConnectionError(REFUSALS['reconnect-required'], { cause: error });
|
|
70
70
|
}
|
|
@@ -32,14 +32,20 @@ export interface ApiConnectionDisconnectResult extends ApiConnectionStatusView {
|
|
|
32
32
|
* provider's account-access page; the local copy of its tokens is gone.
|
|
33
33
|
*/
|
|
34
34
|
export type ApiConnectionSwitchResult = ApiConnectionStatusView;
|
|
35
|
-
export declare function confirmSwitchAccount(deps
|
|
35
|
+
export declare function confirmSwitchAccount({ deps, ...requiredArgs }: {
|
|
36
|
+
deps: ApiConnectionServiceDeps;
|
|
37
|
+
} & OwnedRecordArgs & {
|
|
36
38
|
readonly actorId: string;
|
|
37
|
-
}): Promise<ApiConnectionSwitchResult>;
|
|
39
|
+
}, _optional?: Record<string, never>): Promise<ApiConnectionSwitchResult>;
|
|
38
40
|
/**
|
|
39
41
|
* Drop a staged switch, revoking its tokens because the person consented to them. When the
|
|
40
42
|
* provider does not confirm, the switch stays staged (still confirmable) and cancelling again retries.
|
|
41
43
|
*/
|
|
42
|
-
export declare function cancelSwitchAccount(deps
|
|
44
|
+
export declare function cancelSwitchAccount({ deps, ...requiredArgs }: {
|
|
45
|
+
deps: ApiConnectionServiceDeps;
|
|
46
|
+
} & OwnedRecordArgs, _optional?: Record<string, never>): Promise<ApiConnectionDisconnectResult>;
|
|
43
47
|
/** Disconnect and revoke the live and any staged credential; call again to retry a `pending` revocation. */
|
|
44
|
-
export declare function disconnectApiConnection(deps
|
|
48
|
+
export declare function disconnectApiConnection({ deps, ...requiredArgs }: {
|
|
49
|
+
deps: ApiConnectionDisconnectDeps;
|
|
50
|
+
} & OwnedRecordArgs, _optional?: Record<string, never>): Promise<ApiConnectionDisconnectResult>;
|
|
45
51
|
//# sourceMappingURL=account-actions.d.ts.map
|
|
@@ -28,7 +28,7 @@ function stagedSwitchUsable(record, actorId, nowMs) {
|
|
|
28
28
|
*/
|
|
29
29
|
async function revokeStoredCredential(deps, key) {
|
|
30
30
|
const tokens = await deps.tokens.loadForRevocation({ key }).catch((error) => {
|
|
31
|
-
if (isUnreadableTokenRecord(error))
|
|
31
|
+
if (isUnreadableTokenRecord({ error }))
|
|
32
32
|
return 'unreadable';
|
|
33
33
|
throw error;
|
|
34
34
|
});
|
|
@@ -60,8 +60,8 @@ function combineRevocations(outcomes) {
|
|
|
60
60
|
function firstFailure(results) {
|
|
61
61
|
return results.find(result => result.failure !== null)?.failure ?? null;
|
|
62
62
|
}
|
|
63
|
-
export async function confirmSwitchAccount(deps, requiredArgs) {
|
|
64
|
-
const record = await loadOwnedRecord(deps, requiredArgs);
|
|
63
|
+
export async function confirmSwitchAccount({ deps, ...requiredArgs }, _optional = {}) {
|
|
64
|
+
const record = await loadOwnedRecord({ deps, ...requiredArgs });
|
|
65
65
|
if (!stagedSwitchUsable(record, requiredArgs.actorId, deps.clock.nowMs()))
|
|
66
66
|
throw switchNotStaged();
|
|
67
67
|
const stagedKey = stagedTokenKey({ key: record.key });
|
|
@@ -69,7 +69,7 @@ export async function confirmSwitchAccount(deps, requiredArgs) {
|
|
|
69
69
|
if (tokens === null)
|
|
70
70
|
throw switchNotStaged();
|
|
71
71
|
const staged = record.staged;
|
|
72
|
-
const updated = await installCredential(deps,
|
|
72
|
+
const updated = await installCredential({ deps, current: record, tokens, account: staged.account, grantedScopes: staged.grantedScopes });
|
|
73
73
|
await deps.tokens.delete({ key: stagedKey });
|
|
74
74
|
return toStatusView(updated);
|
|
75
75
|
}
|
|
@@ -77,23 +77,23 @@ export async function confirmSwitchAccount(deps, requiredArgs) {
|
|
|
77
77
|
* Drop a staged switch, revoking its tokens because the person consented to them. When the
|
|
78
78
|
* provider does not confirm, the switch stays staged (still confirmable) and cancelling again retries.
|
|
79
79
|
*/
|
|
80
|
-
export async function cancelSwitchAccount(deps, requiredArgs) {
|
|
81
|
-
const record = await loadOwnedRecord(deps, requiredArgs);
|
|
80
|
+
export async function cancelSwitchAccount({ deps, ...requiredArgs }, _optional = {}) {
|
|
81
|
+
const record = await loadOwnedRecord({ deps, ...requiredArgs });
|
|
82
82
|
// Without a staged record the slot can only hold a confirmed switch's copy of the live grant
|
|
83
83
|
// (or a credential a pending disconnect owns): revoking it here would cut off the live account.
|
|
84
84
|
if (record.staged === null)
|
|
85
85
|
return { ...toStatusView(record), remoteRevocation: 'not-needed' };
|
|
86
86
|
const result = await revokeStoredCredential(deps, stagedTokenKey({ key: record.key }));
|
|
87
|
-
const updated = await writeRecord(deps, record, result.outcome === 'pending'
|
|
88
|
-
|
|
87
|
+
const updated = await writeRecord({ deps, current: record, patch: result.outcome === 'pending'
|
|
88
|
+
? { revocationFailure: result.failure } : { staged: null, revocationFailure: result.failure } });
|
|
89
89
|
return { ...toStatusView(updated), remoteRevocation: combineRevocations([result.outcome]) };
|
|
90
90
|
}
|
|
91
91
|
/** Disconnect and revoke the live and any staged credential; call again to retry a `pending` revocation. */
|
|
92
|
-
export async function disconnectApiConnection(deps, requiredArgs) {
|
|
93
|
-
const record = await loadOwnedRecord(deps, requiredArgs);
|
|
92
|
+
export async function disconnectApiConnection({ deps, ...requiredArgs }, _optional = {}) {
|
|
93
|
+
const record = await loadOwnedRecord({ deps, ...requiredArgs });
|
|
94
94
|
// Stop use before any network call: no token is served or refreshed once the generation moves.
|
|
95
95
|
const stopped = record.status === 'revocation-pending' ? record
|
|
96
|
-
: await writeRecord(deps, record, { status: 'revocation-pending', generation: record.generation + 1, staged: null });
|
|
96
|
+
: await writeRecord({ deps, current: record, patch: { status: 'revocation-pending', generation: record.generation + 1, staged: null } });
|
|
97
97
|
const results = [
|
|
98
98
|
await revokeStoredCredential(deps, record.key),
|
|
99
99
|
await revokeStoredCredential(deps, stagedTokenKey({ key: record.key })),
|
|
@@ -103,8 +103,8 @@ export async function disconnectApiConnection(deps, requiredArgs) {
|
|
|
103
103
|
const revocationFailure = firstFailure(results);
|
|
104
104
|
// Only a kept credential can be retried; an abandoned one leaves nothing to wait for locally.
|
|
105
105
|
if (outcomes.includes('pending'))
|
|
106
|
-
return { ...toStatusView(await writeRecord(deps, stopped, { revocationFailure })), remoteRevocation };
|
|
107
|
-
const cleared = await writeRecord(deps, stopped, { status: 'disconnected', account: null, grantedScopes: [], revocationFailure });
|
|
106
|
+
return { ...toStatusView(await writeRecord({ deps, current: stopped, patch: { revocationFailure } })), remoteRevocation };
|
|
107
|
+
const cleared = await writeRecord({ deps, current: stopped, patch: { status: 'disconnected', account: null, grantedScopes: [], revocationFailure } });
|
|
108
108
|
return { ...toStatusView(cleared), remoteRevocation };
|
|
109
109
|
}
|
|
110
110
|
//# sourceMappingURL=account-actions.js.map
|
|
@@ -9,20 +9,26 @@ export declare const BROWSER_BINDING_BYTES = 32;
|
|
|
9
9
|
* The stored form of a browser binding, so a leaked attempt row cannot be replayed as a cookie.
|
|
10
10
|
* A host bug passing a non-string hashes as '', which no 32-byte binding ever matches.
|
|
11
11
|
*/
|
|
12
|
-
export declare function hashBrowserBinding(value
|
|
12
|
+
export declare function hashBrowserBinding({ value }: {
|
|
13
|
+
value: unknown;
|
|
14
|
+
}, _optional?: Record<string, never>): string;
|
|
13
15
|
type AttemptDraft = Omit<ApiConnectionAttempt, 'state' | 'codeVerifier' | 'redirectUri' | 'createdAt' | 'expiresAt'>;
|
|
14
16
|
type AttemptDeps = Pick<ApiConnectionServiceDeps, 'records' | 'clock' | 'randomBytesFn' | 'oauth'>;
|
|
15
17
|
/** Seal side: store the attempt under fresh random state. */
|
|
16
|
-
export declare function attemptSealer(deps
|
|
18
|
+
export declare function attemptSealer({ deps, ...requiredArgs }: {
|
|
19
|
+
deps: AttemptDeps;
|
|
20
|
+
} & {
|
|
17
21
|
readonly draft: AttemptDraft;
|
|
18
|
-
}): SealedAuthorizationState;
|
|
22
|
+
}, _optional?: Record<string, never>): SealedAuthorizationState;
|
|
19
23
|
/** Open side: consume first, then check binding, so a probe burns the state it guessed. */
|
|
20
|
-
export declare function attemptOpener(deps
|
|
24
|
+
export declare function attemptOpener({ deps, ...requiredArgs }: {
|
|
25
|
+
deps: AttemptDeps;
|
|
26
|
+
} & {
|
|
21
27
|
/** The binding the callback's browser carried; the core's `open` arguments have no slot for it. */
|
|
22
28
|
readonly browserBinding: string;
|
|
23
29
|
readonly onOpen: (requiredArgs: {
|
|
24
30
|
readonly attempt: ApiConnectionAttempt;
|
|
25
31
|
}) => void;
|
|
26
|
-
}): SealedAuthorizationState;
|
|
32
|
+
}, _optional?: Record<string, never>): SealedAuthorizationState;
|
|
27
33
|
export {};
|
|
28
34
|
//# sourceMappingURL=attempt-state.d.ts.map
|
|
@@ -17,7 +17,7 @@ export const BROWSER_BINDING_BYTES = 32;
|
|
|
17
17
|
* The stored form of a browser binding, so a leaked attempt row cannot be replayed as a cookie.
|
|
18
18
|
* A host bug passing a non-string hashes as '', which no 32-byte binding ever matches.
|
|
19
19
|
*/
|
|
20
|
-
export function hashBrowserBinding(value) {
|
|
20
|
+
export function hashBrowserBinding({ value }, _optional = {}) {
|
|
21
21
|
return createHash('sha256').update(typeof value === 'string' ? value : '').digest('base64url');
|
|
22
22
|
}
|
|
23
23
|
function toPending(attempt, providerId) {
|
|
@@ -31,7 +31,7 @@ async function refuseUnexpected(deps) {
|
|
|
31
31
|
throw deps.oauth.invalidPendingState({});
|
|
32
32
|
}
|
|
33
33
|
/** Seal side: store the attempt under fresh random state. */
|
|
34
|
-
export function attemptSealer(deps, requiredArgs) {
|
|
34
|
+
export function attemptSealer({ deps, ...requiredArgs }, _optional = {}) {
|
|
35
35
|
return {
|
|
36
36
|
async seal({ entry }) {
|
|
37
37
|
const createdAt = nowIso({ clock: deps.clock });
|
|
@@ -51,11 +51,11 @@ function matchesBinding(deps, attempt, expected, nowMs) {
|
|
|
51
51
|
&& deps.oauth.secureEquals({ a: attempt.ownerKey, b: expected.ownerKey })
|
|
52
52
|
// The owner key alone cannot bind a hosted callback: a cookie-less callback route can only learn
|
|
53
53
|
// the identities from the attempt itself. The browser binding is what the redirected browser carries.
|
|
54
|
-
&& deps.oauth.secureEquals({ a: attempt.browserBindingHash, b: hashBrowserBinding(expected.browserBinding) })
|
|
54
|
+
&& deps.oauth.secureEquals({ a: attempt.browserBindingHash, b: hashBrowserBinding({ value: expected.browserBinding }) })
|
|
55
55
|
&& attempt.redirectUri === expected.redirectUri;
|
|
56
56
|
}
|
|
57
57
|
/** Open side: consume first, then check binding, so a probe burns the state it guessed. */
|
|
58
|
-
export function attemptOpener(deps, requiredArgs) {
|
|
58
|
+
export function attemptOpener({ deps, ...requiredArgs }, _optional = {}) {
|
|
59
59
|
const { browserBinding } = requiredArgs;
|
|
60
60
|
return {
|
|
61
61
|
seal: () => refuseUnexpected(deps),
|
|
@@ -20,7 +20,9 @@ export interface StartApiConnectionResult {
|
|
|
20
20
|
readonly browserBinding: string;
|
|
21
21
|
readonly expiresAt: string;
|
|
22
22
|
}
|
|
23
|
-
export declare function startApiConnectionAuthorization(deps
|
|
23
|
+
export declare function startApiConnectionAuthorization({ deps, ...requiredArgs }: {
|
|
24
|
+
deps: ApiConnectionServiceDeps;
|
|
25
|
+
} & {
|
|
24
26
|
readonly workspaceId: string;
|
|
25
27
|
readonly actorId: string;
|
|
26
28
|
readonly intent: ApiConnectionIntent;
|
|
@@ -35,11 +37,13 @@ export declare function startApiConnectionAuthorization(deps: ApiConnectionServi
|
|
|
35
37
|
* `browserBinding` is what the callback's browser carried back (`''` when it carried none); a
|
|
36
38
|
* missing or different binding burns the attempt with the same `invalid-attempt`.
|
|
37
39
|
*/
|
|
38
|
-
export declare function completeApiConnectionAuthorization(deps
|
|
40
|
+
export declare function completeApiConnectionAuthorization({ deps, ...requiredArgs }: {
|
|
41
|
+
deps: ApiConnectionServiceDeps;
|
|
42
|
+
} & {
|
|
39
43
|
readonly workspaceId: string;
|
|
40
44
|
readonly actorId: string;
|
|
41
45
|
readonly redirectUri: string;
|
|
42
46
|
readonly callbackParams: Readonly<Record<string, string>>;
|
|
43
47
|
readonly browserBinding: string;
|
|
44
|
-
}): Promise<CompletedAuthorization>;
|
|
48
|
+
}, _optional?: Record<string, never>): Promise<CompletedAuthorization>;
|
|
45
49
|
//# sourceMappingURL=authorization.d.ts.map
|
|
@@ -36,7 +36,7 @@ function assertStartAllowed(record, intent) {
|
|
|
36
36
|
async function holdsRenewableCredential(deps, record) {
|
|
37
37
|
if (record?.status !== 'connected')
|
|
38
38
|
return false;
|
|
39
|
-
return (await loadReadableTokens(deps,
|
|
39
|
+
return (await loadReadableTokens({ deps, key: record.key }))?.refreshToken != null;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* The client kind's fixed parameters, plus the descriptor's force-consent ones on a hosted start
|
|
@@ -62,25 +62,25 @@ function toConnectionError(deps, raw) {
|
|
|
62
62
|
const code = error.code === 'OAUTH_ACCESS_DENIED' ? 'access-denied' : 'authorization-failed';
|
|
63
63
|
return new ApiConnectionError({ code, message: `Sign-in did not complete: ${error.message}. ${error.operatorAction}` }, { cause: error });
|
|
64
64
|
}
|
|
65
|
-
export async function startApiConnectionAuthorization(deps, requiredArgs, optionalArgs = {}) {
|
|
65
|
+
export async function startApiConnectionAuthorization({ deps, ...requiredArgs }, optionalArgs = {}) {
|
|
66
66
|
const { workspaceId, actorId, intent } = requiredArgs;
|
|
67
|
-
assertId(workspaceId, 'workspaceId');
|
|
68
|
-
assertId(actorId, 'actorId');
|
|
67
|
+
assertId({ value: workspaceId, name: 'workspaceId' });
|
|
68
|
+
assertId({ value: actorId, name: 'actorId' });
|
|
69
69
|
if (intent !== 'connect' && intent !== 'switch-account')
|
|
70
|
-
throw requestInvalid('intent');
|
|
71
|
-
const startParams = checkStartParams(deps.descriptor.startParams, optionalArgs.startParams ?? {});
|
|
70
|
+
throw requestInvalid({ detail: 'intent' });
|
|
71
|
+
const startParams = checkStartParams({ fields: deps.descriptor.startParams, values: optionalArgs.startParams ?? {} });
|
|
72
72
|
const key = deriveApiConnectionKey({ workspaceId, pluginId: deps.descriptor.pluginId, connectionId: deps.descriptor.connectionId });
|
|
73
73
|
const record = await deps.records.read({ key });
|
|
74
74
|
assertStartAllowed(record, intent);
|
|
75
|
-
const requestedScopes = checkScopes(await deps.hooks.resolveScopes({ scopeSetIds: [...requiredArgs.scopeSetIds] }));
|
|
75
|
+
const requestedScopes = checkScopes({ value: await deps.hooks.resolveScopes({ scopeSetIds: [...requiredArgs.scopeSetIds] }) });
|
|
76
76
|
const kindParams = await clientKindParams(deps, record, intent);
|
|
77
77
|
const ownerKey = ownerKeyFor(deps, { workspaceId, actorId });
|
|
78
78
|
const attemptId = deps.oauth.generateState({ randomBytesFn: deps.randomBytesFn }, { stateBytes: ATTEMPT_ID_BYTES });
|
|
79
79
|
const browserBinding = deps.oauth.generateState({ randomBytesFn: deps.randomBytesFn }, { stateBytes: BROWSER_BINDING_BYTES });
|
|
80
|
-
const draft = { key, attemptId, ownerKey, browserBindingHash: hashBrowserBinding(browserBinding), workspaceId, actorId, pluginId: deps.descriptor.pluginId,
|
|
80
|
+
const draft = { key, attemptId, ownerKey, browserBindingHash: hashBrowserBinding({ value: browserBinding }), workspaceId, actorId, pluginId: deps.descriptor.pluginId,
|
|
81
81
|
connectionId: deps.descriptor.connectionId, intent, requestedScopes, generation: record?.generation ?? 0 };
|
|
82
82
|
const begun = await deps.oauth.flow.beginAuthorizationCode({
|
|
83
|
-
provider: providerFor(deps), stateless: attemptSealer(deps,
|
|
83
|
+
provider: providerFor(deps), stateless: attemptSealer({ deps, draft }), randomBytesFn: deps.randomBytesFn, guard: deps.guard,
|
|
84
84
|
options: deps.appOptions, ownerKey, client: deps.client, redirectUri: requiredArgs.redirectUri,
|
|
85
85
|
}, { scopes: requestedScopes, extraAuthorizationParams: { ...kindParams, ...startParams } })
|
|
86
86
|
.catch((error) => { throw toConnectionError(deps, error); });
|
|
@@ -93,21 +93,21 @@ export async function startApiConnectionAuthorization(deps, requiredArgs, option
|
|
|
93
93
|
* `browserBinding` is what the callback's browser carried back (`''` when it carried none); a
|
|
94
94
|
* missing or different binding burns the attempt with the same `invalid-attempt`.
|
|
95
95
|
*/
|
|
96
|
-
export async function completeApiConnectionAuthorization(deps, requiredArgs) {
|
|
97
|
-
assertId(requiredArgs.workspaceId, 'workspaceId');
|
|
98
|
-
assertId(requiredArgs.actorId, 'actorId');
|
|
96
|
+
export async function completeApiConnectionAuthorization({ deps, ...requiredArgs }, _optional = {}) {
|
|
97
|
+
assertId({ value: requiredArgs.workspaceId, name: 'workspaceId' });
|
|
98
|
+
assertId({ value: requiredArgs.actorId, name: 'actorId' });
|
|
99
99
|
if (!URL.canParse(requiredArgs.redirectUri))
|
|
100
|
-
throw requestInvalid('redirectUri');
|
|
101
|
-
const params = checkCallbackParams(requiredArgs.callbackParams, { maxAuthorizationStateLength: deps.oauth.maxAuthorizationStateLength,
|
|
102
|
-
|
|
103
|
-
const callbackFields = pickBoundedFields(deps.descriptor.callbackFields, requiredArgs.callbackParams, 'callback field');
|
|
100
|
+
throw requestInvalid({ detail: 'redirectUri' });
|
|
101
|
+
const params = checkCallbackParams({ value: requiredArgs.callbackParams, limits: { maxAuthorizationStateLength: deps.oauth.maxAuthorizationStateLength,
|
|
102
|
+
maxCallbackFieldLength: deps.oauth.callbackFieldRules.maxLength } });
|
|
103
|
+
const callbackFields = pickBoundedFields({ fields: deps.descriptor.callbackFields, values: requiredArgs.callbackParams, where: 'callback field' });
|
|
104
104
|
let attempt;
|
|
105
105
|
const tokens = await deps.oauth.flow.completeAuthorizationCode({
|
|
106
|
-
provider: providerFor(deps), stateless: attemptOpener(deps,
|
|
106
|
+
provider: providerFor(deps), stateless: attemptOpener({ deps, browserBinding: requiredArgs.browserBinding, onOpen: opened => { attempt = opened.attempt; } }),
|
|
107
107
|
redirectUri: new URL(requiredArgs.redirectUri).href, ownerKey: ownerKeyFor(deps, requiredArgs), client: deps.client, params,
|
|
108
108
|
fetchFn: deps.fetchFn, guard: deps.guard, clock: deps.clock,
|
|
109
109
|
}).catch((error) => { throw toConnectionError(deps, error); });
|
|
110
110
|
// completeAuthorizationCode only reaches the exchange after `open` returned an attempt.
|
|
111
|
-
return finishAuthorization(deps,
|
|
111
|
+
return finishAuthorization({ deps, attempt: attempt, tokens, callbackFields });
|
|
112
112
|
}
|
|
113
113
|
//# sourceMappingURL=authorization.js.map
|
|
@@ -13,12 +13,16 @@ export interface CompletedAuthorization {
|
|
|
13
13
|
readonly callbackFields: Readonly<Record<string, string>>;
|
|
14
14
|
}
|
|
15
15
|
/** The stored live tokens, or null when none are stored or they are unreadable to this host. */
|
|
16
|
-
export declare function loadReadableTokens(deps
|
|
16
|
+
export declare function loadReadableTokens({ deps, ...requiredArgs }: {
|
|
17
|
+
deps: ApiConnectionServiceDeps;
|
|
18
|
+
} & {
|
|
17
19
|
readonly key: string;
|
|
18
|
-
}): Promise<OAuthTokenSet | null>;
|
|
19
|
-
export declare function finishAuthorization(deps
|
|
20
|
+
}, _optional?: Record<string, never>): Promise<OAuthTokenSet | null>;
|
|
21
|
+
export declare function finishAuthorization({ deps, ...requiredArgs }: {
|
|
22
|
+
deps: ApiConnectionServiceDeps;
|
|
23
|
+
} & {
|
|
20
24
|
readonly attempt: ApiConnectionAttempt;
|
|
21
25
|
readonly tokens: OAuthTokenSet;
|
|
22
26
|
readonly callbackFields: Readonly<Record<string, string>>;
|
|
23
|
-
}): Promise<CompletedAuthorization>;
|
|
27
|
+
}, _optional?: Record<string, never>): Promise<CompletedAuthorization>;
|
|
24
28
|
//# sourceMappingURL=finish-authorization.d.ts.map
|
|
@@ -35,7 +35,7 @@ async function readAccount(deps, accessToken) {
|
|
|
35
35
|
return { accountId: account.accountId, displayName: account.displayName };
|
|
36
36
|
}
|
|
37
37
|
async function currentRecord(deps, attempt) {
|
|
38
|
-
const record = await deps.records.read({ key: attempt.key }) ?? blankRecord(deps, attempt);
|
|
38
|
+
const record = await deps.records.read({ key: attempt.key }) ?? blankRecord({ deps, ...attempt });
|
|
39
39
|
// A reconnect, switch, disconnect or newer completed attempt moved the generation: this one is stale.
|
|
40
40
|
if (record.generation !== attempt.generation) {
|
|
41
41
|
throw new ApiConnectionError({ code: 'attempt-superseded',
|
|
@@ -50,10 +50,10 @@ async function currentRecord(deps, attempt) {
|
|
|
50
50
|
return record;
|
|
51
51
|
}
|
|
52
52
|
/** The stored live tokens, or null when none are stored or they are unreadable to this host. */
|
|
53
|
-
export async function loadReadableTokens(deps, requiredArgs) {
|
|
53
|
+
export async function loadReadableTokens({ deps, ...requiredArgs }, _optional = {}) {
|
|
54
54
|
// A row sealed for another client (the host changed its OAuth client) has no usable refresh token.
|
|
55
55
|
return deps.tokens.load({ key: requiredArgs.key }).catch((error) => {
|
|
56
|
-
if (isUnreadableTokenRecord(error))
|
|
56
|
+
if (isUnreadableTokenRecord({ error }))
|
|
57
57
|
return null;
|
|
58
58
|
throw error;
|
|
59
59
|
});
|
|
@@ -62,7 +62,7 @@ export async function loadReadableTokens(deps, requiredArgs) {
|
|
|
62
62
|
async function keepRefreshToken(deps, record, tokens, account) {
|
|
63
63
|
if (tokens.refreshToken !== null || record.account?.accountId !== account.accountId)
|
|
64
64
|
return tokens;
|
|
65
|
-
const existing = await loadReadableTokens(deps,
|
|
65
|
+
const existing = await loadReadableTokens({ deps, key: record.key });
|
|
66
66
|
return existing?.refreshToken ? { ...tokens, refreshToken: existing.refreshToken } : tokens;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
@@ -84,7 +84,7 @@ async function commitConnect(deps, record, tokens, account, grantedScopes) {
|
|
|
84
84
|
}
|
|
85
85
|
const kept = await keepRefreshToken(deps, record, tokens, account);
|
|
86
86
|
assertRenewable(kept);
|
|
87
|
-
await installCredential(deps,
|
|
87
|
+
await installCredential({ deps, current: record, tokens: kept, account, grantedScopes });
|
|
88
88
|
}
|
|
89
89
|
async function stageSwitch(deps, record, attempt, tokens, account, grantedScopes) {
|
|
90
90
|
// The provider usually holds one grant per client and account, so a staged copy of the live
|
|
@@ -97,12 +97,12 @@ async function stageSwitch(deps, record, attempt, tokens, account, grantedScopes
|
|
|
97
97
|
const expiresAt = new Date(Date.parse(nowIso({ clock: deps.clock })) + ATTEMPT_TTL_MS).toISOString();
|
|
98
98
|
// Claim the staged slot on the record first: of two concurrent switches only the compare-and-set
|
|
99
99
|
// winner writes tokens, so the slot can never hold one account while the record names another.
|
|
100
|
-
await writeRecord(deps, record, {
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
await writeRecord({ deps, current: record, patch: {
|
|
101
|
+
staged: { account, grantedScopes: [...grantedScopes], actorId: attempt.actorId, generation: record.generation, expiresAt },
|
|
102
|
+
} });
|
|
103
103
|
await deps.tokens.install({ key: stagedTokenKey({ key: record.key }), tokens, generation: record.generation });
|
|
104
104
|
}
|
|
105
|
-
export async function finishAuthorization(deps, requiredArgs) {
|
|
105
|
+
export async function finishAuthorization({ deps, ...requiredArgs }, _optional = {}) {
|
|
106
106
|
const { attempt, tokens } = requiredArgs;
|
|
107
107
|
const grantedScopes = grantedScopesOf(tokens, attempt.requestedScopes);
|
|
108
108
|
assertGranted(attempt.requestedScopes, grantedScopes);
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { type ApiConnectionService } from './service.js';
|
|
2
|
-
import type { ApiConnectionRuntimeHostDeps, ApiConnectionRuntimeHostOptions, ApiConnectionSignInAttempt, ApiConnectionRuntime, ApiConnectionHostRecordStore, DeclaredApiConnection } from './host-ports.js';
|
|
2
|
+
import type { ApiConnectionSharedConnections, ApiConnectionRuntimeHostDeps, ApiConnectionRuntimeHostOptions, ApiConnectionSignInAttempt, ApiConnectionRuntime, ApiConnectionHostRecordStore, DeclaredApiConnection } from './host-ports.js';
|
|
3
|
+
type ConnectionTarget = {
|
|
4
|
+
readonly workspaceId: string;
|
|
5
|
+
readonly pluginId: string;
|
|
6
|
+
readonly connectionRef: string;
|
|
7
|
+
};
|
|
8
|
+
type AccessOptions = {
|
|
9
|
+
readonly expectedAccountId?: string;
|
|
10
|
+
};
|
|
11
|
+
type SignInInput = {
|
|
12
|
+
connection: DeclaredApiConnection;
|
|
13
|
+
actorId: string;
|
|
14
|
+
destination?: "site" | "shared" | undefined;
|
|
15
|
+
redirectUri?: string;
|
|
16
|
+
};
|
|
3
17
|
/**
|
|
4
18
|
* Builds the workspace host. Declarations are read fresh per call, so enabling or disabling a
|
|
5
19
|
* plugin takes effect without a restart (Node caches each hooks module per file URL).
|
|
@@ -7,18 +21,21 @@ import type { ApiConnectionRuntimeHostDeps, ApiConnectionRuntimeHostOptions, Api
|
|
|
7
21
|
*/
|
|
8
22
|
export declare function createApiConnectionHost<State>(required: ApiConnectionRuntimeHostDeps<State>, optional?: ApiConnectionRuntimeHostOptions): {
|
|
9
23
|
sharingAvailable: boolean;
|
|
10
|
-
sharedOAuth:
|
|
11
|
-
prepareSignIn: (input: {
|
|
12
|
-
connection: DeclaredApiConnection;
|
|
13
|
-
actorId: string;
|
|
14
|
-
destination?: "site" | "shared" | undefined;
|
|
15
|
-
redirectUri?: string;
|
|
16
|
-
}) => Promise<import("./host-ports.js").ApiConnectionPreparedSignIn>;
|
|
24
|
+
sharedOAuth: ApiConnectionSharedConnections | undefined;
|
|
17
25
|
workspaceId: string;
|
|
18
26
|
runtime: ApiConnectionRuntime;
|
|
19
27
|
clock: import("@jini-ai/core/primitives").Clock;
|
|
20
28
|
records: ApiConnectionHostRecordStore;
|
|
21
29
|
startLoopback: import("./host-ports.js").ApiConnectionStartLoopback;
|
|
30
|
+
toolConnections: {
|
|
31
|
+
readAccount(target: ConnectionTarget): Promise<import("./types.js").ApiConnectionAccount | null>;
|
|
32
|
+
getAccessToken(target: ConnectionTarget, options?: AccessOptions): Promise<string>;
|
|
33
|
+
};
|
|
34
|
+
callbackInbox: import("./host-ports.js").ApiConnectionCallbackInbox;
|
|
35
|
+
pluginState: State;
|
|
36
|
+
lastSignInAttempts: Map<string, ApiConnectionSignInAttempt>;
|
|
37
|
+
signInHandoffs: import("./hosted-sign-in.js").SignInHandoffs;
|
|
38
|
+
prepareSignIn: (input: SignInInput) => Promise<import("./host-ports.js").ApiConnectionPreparedSignIn>;
|
|
22
39
|
listConnections: (input?: {
|
|
23
40
|
readonly pluginId?: string;
|
|
24
41
|
}) => Promise<readonly DeclaredApiConnection[]>;
|
|
@@ -29,25 +46,9 @@ export declare function createApiConnectionHost<State>(required: ApiConnectionRu
|
|
|
29
46
|
accessTokensFor: (scope: {
|
|
30
47
|
readonly pluginId: string;
|
|
31
48
|
}) => {
|
|
32
|
-
getAccessToken(input: {
|
|
49
|
+
getAccessToken: (input: {
|
|
33
50
|
readonly connectionRef: string;
|
|
34
|
-
}, options?:
|
|
35
|
-
readonly expectedAccountId?: string;
|
|
36
|
-
}): Promise<string>;
|
|
37
|
-
};
|
|
38
|
-
toolConnections: {
|
|
39
|
-
readAccount(target: {
|
|
40
|
-
readonly workspaceId: string;
|
|
41
|
-
readonly pluginId: string;
|
|
42
|
-
readonly connectionRef: string;
|
|
43
|
-
}): Promise<import("./types.js").ApiConnectionAccount | null>;
|
|
44
|
-
getAccessToken(target: {
|
|
45
|
-
readonly workspaceId: string;
|
|
46
|
-
readonly pluginId: string;
|
|
47
|
-
readonly connectionRef: string;
|
|
48
|
-
}, options?: {
|
|
49
|
-
readonly expectedAccountId?: string;
|
|
50
|
-
}): Promise<string>;
|
|
51
|
+
}, options?: AccessOptions) => Promise<string>;
|
|
51
52
|
};
|
|
52
53
|
apiOriginsFor: (input: {
|
|
53
54
|
readonly workspaceId: string;
|
|
@@ -61,10 +62,10 @@ export declare function createApiConnectionHost<State>(required: ApiConnectionRu
|
|
|
61
62
|
readonly connection: DeclaredApiConnection;
|
|
62
63
|
readonly scopeSetIds: readonly string[];
|
|
63
64
|
}) => Promise<readonly string[]>;
|
|
64
|
-
hostedCallbackUrl: (
|
|
65
|
+
hostedCallbackUrl: (input: {
|
|
65
66
|
readonly connection: DeclaredApiConnection;
|
|
66
67
|
}) => string;
|
|
67
|
-
statusOf: (
|
|
68
|
+
statusOf: (input: {
|
|
68
69
|
readonly connection: DeclaredApiConnection;
|
|
69
70
|
readonly local?: boolean;
|
|
70
71
|
}) => Promise<{
|
|
@@ -72,10 +73,7 @@ export declare function createApiConnectionHost<State>(required: ApiConnectionRu
|
|
|
72
73
|
status: import("./types.js").ApiConnectionStatus;
|
|
73
74
|
grantedScopes: readonly string[];
|
|
74
75
|
}>;
|
|
75
|
-
callbackInbox: import("./host-ports.js").ApiConnectionCallbackInbox;
|
|
76
|
-
lastSignInAttempts: Map<string, ApiConnectionSignInAttempt>;
|
|
77
|
-
signInHandoffs: import("./hosted-sign-in.js").SignInHandoffs;
|
|
78
|
-
pluginState: State;
|
|
79
76
|
};
|
|
80
77
|
export type ApiConnectionHost<State = unknown> = ReturnType<typeof createApiConnectionHost<State>>;
|
|
78
|
+
export {};
|
|
81
79
|
//# sourceMappingURL=host.d.ts.map
|