@jini-ai/integrations 0.6.10 → 0.6.11

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.11
4
+
5
+ ### Patch Changes
6
+
7
+ - `probeCredentialConnection`: a GET-only credential probe on `credentialed-http`.
8
+ - Updated dependencies
9
+ - Updated dependencies
10
+ - @jini-ai/core@0.6.11
11
+
3
12
  ## 0.6.10
4
13
 
5
14
  ### Patch Changes
@@ -95,20 +95,53 @@ export declare function resolveRequestTarget(required: {
95
95
  url: URL;
96
96
  }>;
97
97
  export type CustomCredentialCheckStatus = "valid" | "invalid" | "unreachable";
98
+ /** A refusal establishes only that this GET was refused, not that the key is invalid. */
99
+ export type CredentialConnectionProbeStatus = "ok" | "refused" | "unavailable";
100
+ /** Host-owned probe input. The host must resolve the plugin-declared URL against the saved base
101
+ * origin before calling; no credential store or plugin/model-input parser is loaded here. */
102
+ export interface CredentialConnectionProbeInput {
103
+ readonly connection: CredentialConnection;
104
+ readonly url: string;
105
+ readonly schemes: readonly CredentialSchemeRule[];
106
+ /** Omit for GET. Explicit methods are checked at runtime, including untyped callers. */
107
+ readonly method?: "GET";
108
+ }
109
+ /** Send one bodyless GET through the guarded HTTP port without following redirects.
110
+ * @param required Plaintext connection, trusted host-resolved URL and auth-scheme rules.
111
+ * @param options Guarded HTTP client; owns DNS/address policy, peer pinning and response bounds.
112
+ * @returns Only ok/refused/unavailable; no bodies, headers, URLs, secrets or transport errors.
113
+ * @throws CredentialedRequestValidationError with value-free text for non-GET or malformed URLs.
114
+ * @complexity One bounded HTTP send plus O(r) auth matching for r supplied scheme rules.
115
+ * @example await probeCredentialConnection({ connection, url, schemes }, { httpClient });
116
+ */
117
+ export declare function probeCredentialConnection(required: CredentialConnectionProbeInput, options: {
118
+ httpClient: HttpClientPort;
119
+ }): Promise<CredentialConnectionProbeStatus>;
98
120
  export interface CustomCredentialVerificationResult {
99
121
  readonly status: CustomCredentialCheckStatus;
100
122
  readonly message: string;
101
123
  readonly checkedAt: string;
102
124
  readonly authDiagnostic?: AuthFailureDiagnostic;
103
125
  }
104
- /** Probe the saved origin root and classify 2xx/401/403/other outcomes; audit without returning response bodies. */
126
+ export interface CustomCredentialVerificationOptions extends CredentialedRequestOptions {
127
+ /** Trusted plugin-declared path relative to baseUrl; omission keeps the origin-root probe. */
128
+ readonly path?: string;
129
+ }
130
+ /** Probe the origin root or a trusted relative path; retain verification messages, diagnostics and audit.
131
+ * @param required Resolver/HTTP/audit ports and workspace-bound credential identity.
132
+ * @param optional Optional relative path and existing diagnostic mapping policy.
133
+ * @returns The existing valid/invalid/unreachable result, without response bodies or secrets.
134
+ * @throws CredentialedRequestValidationError for invalid labels/paths; resolver/registry errors propagate.
135
+ * @complexity One credential resolution, registry load and bounded HTTP probe; O(r) scheme matching.
136
+ * @example await verifyCustomCredential({ deps, input }, { path: "/user" });
137
+ */
105
138
  export declare function verifyCustomCredential(required: {
106
139
  deps: CredentialedRequestDeps;
107
140
  input: {
108
141
  workspaceId: UUID;
109
142
  label: unknown;
110
143
  };
111
- }, optional?: CredentialedRequestOptions): Promise<CustomCredentialVerificationResult>;
144
+ }, optional?: CustomCredentialVerificationOptions): Promise<CustomCredentialVerificationResult>;
112
145
  export interface CredentialedRequestExecutedResult {
113
146
  readonly executed: true;
114
147
  readonly status: number;
@@ -45,10 +45,10 @@ function validateMethod(raw) {
45
45
  }
46
46
  return raw;
47
47
  }
48
- // This binds the original caller URL only. Any redirect comes from the already-approved host;
49
- // the injected transport must recheck its address and strip credentials on cross-origin hops,
50
- // rather than widening its global egress allowlist to make the redirected host reachable.
51
- function resolveAllowedRequestUrl(candidate, allowedOrigins) {
48
+ /** Parse an absolute HTTP(S) request URL without userinfo; no I/O or credential-origin decision.
49
+ * @throws CredentialedRequestValidationError for malformed input.
50
+ * @complexity O(n) parsing for n URL characters. */
51
+ function parseRequestUrl(candidate) {
52
52
  if (typeof candidate !== "string" || candidate.trim() === "") {
53
53
  throw new CredentialedRequestValidationError({ message: "url must be a non-empty string" });
54
54
  }
@@ -65,6 +65,13 @@ function resolveAllowedRequestUrl(candidate, allowedOrigins) {
65
65
  if (parsed.username || parsed.password) {
66
66
  throw new CredentialedRequestValidationError({ message: "url must not embed credentials (user:pass@) — the server injects the real Authorization header itself" });
67
67
  }
68
+ return parsed;
69
+ }
70
+ // This binds the original caller URL only. Any redirect comes from the already-approved host;
71
+ // the injected transport must recheck its address and strip credentials on cross-origin hops,
72
+ // rather than widening its global egress allowlist to make the redirected host reachable.
73
+ function resolveAllowedRequestUrl(candidate, allowedOrigins) {
74
+ const parsed = parseRequestUrl(candidate);
68
75
  if (!allowedOrigins.includes(parsed.origin)) {
69
76
  throw new CredentialedRequestValidationError({ message: `url '${candidate}' resolves to origin '${parsed.origin}', which is not one of this credential's saved hosts (${allowedOrigins.join(", ")})` });
70
77
  }
@@ -200,14 +207,54 @@ async function resolveCredentialOrThrow(deps, input) {
200
207
  throw new CredentialNotFoundError({ message: `no custom credential labeled '${input.label}' in this workspace` });
201
208
  return resolved;
202
209
  }
203
- // Only 401/403 affirmatively reject it; redirects and other statuses reaching this classifier say
204
- // nothing about validity. Keep this local rather than coupling independent provider features.
205
- function classifyCustomCredentialStatus(status) {
210
+ /** Send one bodyless GET through the guarded HTTP port without following redirects.
211
+ * @param required Plaintext connection, trusted host-resolved URL and auth-scheme rules.
212
+ * @param options Guarded HTTP client; owns DNS/address policy, peer pinning and response bounds.
213
+ * @returns Only ok/refused/unavailable; no bodies, headers, URLs, secrets or transport errors.
214
+ * @throws CredentialedRequestValidationError with value-free text for non-GET or malformed URLs.
215
+ * @complexity One bounded HTTP send plus O(r) auth matching for r supplied scheme rules.
216
+ * @example await probeCredentialConnection({ connection, url, schemes }, { httpClient });
217
+ */
218
+ export async function probeCredentialConnection(required, options) {
219
+ if (required.method !== undefined && required.method !== "GET") {
220
+ throw new CredentialedRequestValidationError({ message: "credential probes only support GET" });
221
+ }
222
+ let url;
223
+ try {
224
+ url = parseRequestUrl(required.url);
225
+ }
226
+ catch {
227
+ // URL parse errors may contain their input; probe failures must never echo caller values.
228
+ throw new CredentialedRequestValidationError({ message: "credential probe requires an absolute HTTP(S) URL without embedded credentials" });
229
+ }
230
+ return classifyCredentialProbeStatus(await sendCredentialGet({ ...required, url, httpClient: options.httpClient }, { strict: true }));
231
+ }
232
+ /** One bodyless authenticated GET shared by the probe and verification. Returns the HTTP status,
233
+ * or 0 when the transport failed; transport errors are dropped because they can echo request values.
234
+ * `strict` refuses redirects and bounds the whole operation (the probe contract); verification omits
235
+ * it to keep its original follow-redirect, idle-timeout-only policy so its results do not change.
236
+ * @complexity One HTTP send plus O(r) auth matching for r scheme rules. */
237
+ async function sendCredentialGet(required, optional = {}) {
238
+ try {
239
+ const response = await required.httpClient.send({ request: {
240
+ method: "GET", url: required.url.href,
241
+ headers: { Authorization: buildAuthorizationHeader(required) },
242
+ timeoutMs: CREDENTIALED_REQUEST_TIMEOUT_MS,
243
+ ...(optional.strict ? { totalDeadlineMs: CREDENTIALED_REQUEST_TIMEOUT_MS } : {}),
244
+ } }, optional.strict ? { redirect: "error" } : undefined);
245
+ return response.status;
246
+ }
247
+ catch {
248
+ return 0;
249
+ }
250
+ }
251
+ /** Classify only affirmative success/refusal; redirects and all other statuses are inconclusive. */
252
+ function classifyCredentialProbeStatus(status) {
206
253
  if (status >= 200 && status < 300)
207
- return "valid";
254
+ return "ok";
208
255
  if (isAuthRejectionStatus(status))
209
- return "invalid";
210
- return "unreachable";
256
+ return "refused";
257
+ return "unavailable";
211
258
  }
212
259
  // 401 and 403 are the only affirmative authentication rejections; both classification and
213
260
  // diagnostics key off this one predicate so they cannot disagree.
@@ -223,7 +270,32 @@ function buildVerificationMessage(label, status, outcome) {
223
270
  }
224
271
  return `Could not get a clear accept or reject from '${label}' (HTTP ${status}) — this does not necessarily mean the credential is bad.`;
225
272
  }
226
- /** Probe the saved origin root and classify 2xx/401/403/other outcomes; audit without returning response bodies. */
273
+ /** Resolve an optional relative probe path against the saved primary base, never additional hosts.
274
+ * Invalid stored URLs/paths produce value-free errors before any HTTP send.
275
+ * @complexity O(n) URL parsing for n URL/path characters; no I/O. */
276
+ function resolveVerificationUrl(baseUrl, path) {
277
+ try {
278
+ const base = parseRequestUrl(baseUrl);
279
+ if (path === undefined)
280
+ return new URL("/", base);
281
+ // Schemes and network-path references ("//host") are absolute, even when they repeat the saved host.
282
+ if (typeof path === "string" && path.trim() !== "" && !/[\u0000-\u001f\u007f]/.test(path) && !/^([a-z][a-z\d+.-]*:|[\\/]{2})/i.test(path.trim())) {
283
+ return resolveAllowedRequestUrl(new URL(path, base).href, [base.origin]);
284
+ }
285
+ }
286
+ catch {
287
+ // Fall through: URL errors can echo their input, so every failure gets the same value-free text.
288
+ }
289
+ throw new CredentialedRequestValidationError({ message: "probe path must be relative to the saved base URL and remain on its origin" });
290
+ }
291
+ /** Probe the origin root or a trusted relative path; retain verification messages, diagnostics and audit.
292
+ * @param required Resolver/HTTP/audit ports and workspace-bound credential identity.
293
+ * @param optional Optional relative path and existing diagnostic mapping policy.
294
+ * @returns The existing valid/invalid/unreachable result, without response bodies or secrets.
295
+ * @throws CredentialedRequestValidationError for invalid labels/paths; resolver/registry errors propagate.
296
+ * @complexity One credential resolution, registry load and bounded HTTP probe; O(r) scheme matching.
297
+ * @example await verifyCustomCredential({ deps, input }, { path: "/user" });
298
+ */
227
299
  // Probe the primary saved origin to answer whether the credential works at all, rather than trying
228
300
  // every additional API host. Provider bodies never belong in verification results; transport failure
229
301
  // remains "unreachable", and only an affirmative auth rejection has a diagnostic worth attaching.
@@ -232,25 +304,16 @@ export async function verifyCustomCredential(required, optional = {}) {
232
304
  const label = requireLabel(input.label);
233
305
  const checkedAt = nowIso({ clock: deps.clock });
234
306
  const { baseUrl, connection } = await resolveCredentialOrThrow(deps, { workspaceId: input.workspaceId, label });
235
- const url = new URL(`${new URL(baseUrl).origin}/`);
307
+ const url = resolveVerificationUrl(baseUrl, optional.path);
236
308
  const auditBase = { label, host: url.hostname, method: "GET", bodyBytes: 0, at: checkedAt };
237
309
  const schemes = await deps.schemeRegistry.load({ workspaceId: input.workspaceId });
238
- let status;
239
- try {
240
- const response = await deps.httpClient.send({ request: {
241
- method: "GET",
242
- url: url.toString(),
243
- headers: { Authorization: buildAuthorizationHeader({ connection, schemes }) },
244
- timeoutMs: CREDENTIALED_REQUEST_TIMEOUT_MS,
245
- } });
246
- status = response.status;
247
- }
248
- catch {
249
- deps.audit.record({ entry: auditEntry(auditBase, 0) });
310
+ const status = await sendCredentialGet({ connection, url, schemes, httpClient: deps.httpClient });
311
+ deps.audit.record({ entry: auditEntry(auditBase, status) });
312
+ if (status === 0) {
250
313
  return { status: "unreachable", message: `Could not reach '${label}' to verify this credential — this does not necessarily mean the credential is bad.`, checkedAt };
251
314
  }
252
- deps.audit.record({ entry: auditEntry(auditBase, status) });
253
- const outcome = classifyCustomCredentialStatus(status);
315
+ const outcomes = { ok: "valid", refused: "invalid", unavailable: "unreachable" };
316
+ const outcome = outcomes[classifyCredentialProbeStatus(status)];
254
317
  const authDiagnostic = isAuthRejectionStatus(status) ? mapAuthDiagnostic(connection, status, schemes, optional) : undefined;
255
318
  return { status: outcome, message: buildVerificationMessage(label, status, outcome), checkedAt, ...(authDiagnostic ? { authDiagnostic } : {}) };
256
319
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/integrations",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
4
4
  "description": "Third-party vendor integrations and outbound services, each independently importable: media generation, credentialed HTTP and webhooks.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -103,7 +103,7 @@
103
103
  "registry": "https://registry.npmjs.org"
104
104
  },
105
105
  "dependencies": {
106
- "@jini-ai/core": "^0.6.10"
106
+ "@jini-ai/core": "^0.6.11"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "@jini-ai/db": "^0.6.10",
@@ -134,11 +134,11 @@
134
134
  "better-sqlite3": "^13.0.0",
135
135
  "@vitest/coverage-v8": "^2.1.9",
136
136
  "@cfworker/json-schema": "^4.1.1",
137
- "@jini-ai/core": "0.6.10",
138
- "@jini-ai/db": "^0.6.10",
139
- "@jini-ai/oauth": "0.6.10",
140
- "@jini-ai/agent-plugins": "0.6.10",
141
- "@jini-ai/platform": "0.6.10"
137
+ "@jini-ai/oauth": "0.6.11",
138
+ "@jini-ai/db": "^0.6.11",
139
+ "@jini-ai/agent-plugins": "0.6.11",
140
+ "@jini-ai/core": "0.6.11",
141
+ "@jini-ai/platform": "0.6.11"
142
142
  },
143
143
  "scripts": {
144
144
  "build": "tsc -p tsconfig.json",