@astrasyncai/verification-gateway 2.1.0 → 2.2.0

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.
Files changed (77) hide show
  1. package/dist/adapter-interface/interface.d.mts +2 -2
  2. package/dist/adapter-interface/interface.d.ts +2 -2
  3. package/dist/adapters/express.d.mts +2 -2
  4. package/dist/adapters/express.d.ts +2 -2
  5. package/dist/adapters/express.js +42 -20
  6. package/dist/adapters/express.js.map +1 -1
  7. package/dist/adapters/express.mjs +42 -20
  8. package/dist/adapters/express.mjs.map +1 -1
  9. package/dist/adapters/nextjs.d.mts +2 -2
  10. package/dist/adapters/nextjs.d.ts +2 -2
  11. package/dist/adapters/nextjs.js +43 -20
  12. package/dist/adapters/nextjs.js.map +1 -1
  13. package/dist/adapters/nextjs.mjs +43 -20
  14. package/dist/adapters/nextjs.mjs.map +1 -1
  15. package/dist/adapters/sdk.d.mts +2 -2
  16. package/dist/adapters/sdk.d.ts +2 -2
  17. package/dist/adapters/sdk.js +25 -16
  18. package/dist/adapters/sdk.js.map +1 -1
  19. package/dist/adapters/sdk.mjs +25 -16
  20. package/dist/adapters/sdk.mjs.map +1 -1
  21. package/dist/agent/index.d.mts +2 -2
  22. package/dist/agent/index.d.ts +2 -2
  23. package/dist/agent/index.js +67 -1
  24. package/dist/agent/index.js.map +1 -1
  25. package/dist/agent/index.mjs +65 -1
  26. package/dist/agent/index.mjs.map +1 -1
  27. package/dist/browser/background.js +25 -16
  28. package/dist/browser/background.js.map +1 -1
  29. package/dist/browser/background.mjs +25 -16
  30. package/dist/browser/background.mjs.map +1 -1
  31. package/dist/browser/browser-adapter.d.mts +2 -2
  32. package/dist/browser/browser-adapter.d.ts +2 -2
  33. package/dist/cli/index.d.mts +2 -2
  34. package/dist/cli/index.d.ts +2 -2
  35. package/dist/cursor/cursor-adapter.d.mts +2 -2
  36. package/dist/cursor/cursor-adapter.d.ts +2 -2
  37. package/dist/cursor/extension.d.mts +2 -2
  38. package/dist/cursor/extension.d.ts +2 -2
  39. package/dist/cursor/extension.js +25 -16
  40. package/dist/cursor/extension.js.map +1 -1
  41. package/dist/cursor/extension.mjs +25 -16
  42. package/dist/cursor/extension.mjs.map +1 -1
  43. package/dist/{express-CtwDIZyF.d.mts → express-C9KqJNWV.d.mts} +1 -1
  44. package/dist/{express-Bcl-uBUE.d.ts → express-DpwYW08E.d.ts} +1 -1
  45. package/dist/gateway/gateway.d.mts +2 -2
  46. package/dist/gateway/gateway.d.ts +2 -2
  47. package/dist/gateway/gateway.js +25 -16
  48. package/dist/gateway/gateway.js.map +1 -1
  49. package/dist/gateway/gateway.mjs +25 -16
  50. package/dist/gateway/gateway.mjs.map +1 -1
  51. package/dist/git-trigger/git-hooks.d.mts +2 -2
  52. package/dist/git-trigger/git-hooks.d.ts +2 -2
  53. package/dist/{index-BY8yQ8N8.d.mts → index-BMZdjGT4.d.mts} +46 -3
  54. package/dist/{index-3NRaBNvp.d.mts → index-DlsYN3Et.d.mts} +1 -1
  55. package/dist/{index-CtYSYwn3.d.ts → index-Dm2xA6j1.d.ts} +46 -3
  56. package/dist/{index-CME6r4uH.d.ts → index-gM-lgX_X.d.ts} +1 -1
  57. package/dist/index.d.mts +7 -7
  58. package/dist/index.d.ts +7 -7
  59. package/dist/index.js +125 -25
  60. package/dist/index.js.map +1 -1
  61. package/dist/index.mjs +125 -25
  62. package/dist/index.mjs.map +1 -1
  63. package/dist/local-evaluator/evaluator.d.mts +2 -2
  64. package/dist/local-evaluator/evaluator.d.ts +2 -2
  65. package/dist/{nextjs-BQyMCSx_.d.mts → nextjs-BEqidT0U.d.mts} +1 -1
  66. package/dist/{nextjs-CEldnIJ9.d.ts → nextjs-yNzimC3a.d.ts} +1 -1
  67. package/dist/{sdk-BhvuJSrH.d.mts → sdk-7fa9H0qa.d.mts} +1 -1
  68. package/dist/{sdk-BlyVSC_S.d.ts → sdk-CP9C9Qu0.d.ts} +1 -1
  69. package/dist/transport/index.d.mts +2 -2
  70. package/dist/transport/index.d.ts +2 -2
  71. package/dist/{types-CxQwJKbd.d.mts → types-CrVMq_Td.d.mts} +30 -3
  72. package/dist/{types-CxQwJKbd.d.ts → types-CrVMq_Td.d.ts} +30 -3
  73. package/dist/{types-jJnPXStc.d.mts → types-DE0ooQJ6.d.mts} +1 -1
  74. package/dist/{types-79qS7aON.d.ts → types-rigu2bH3.d.ts} +1 -1
  75. package/dist/ui/index.d.mts +1 -1
  76. package/dist/ui/index.d.ts +1 -1
  77. package/package.json +3 -3
@@ -1,6 +1,6 @@
1
1
  import { AstraSyncGateway } from '../gateway/gateway.mjs';
2
- import { V as VerificationDecision, P as PDLSSContext } from '../types-jJnPXStc.mjs';
3
- import '../types-CxQwJKbd.mjs';
2
+ import { V as VerificationDecision, P as PDLSSContext } from '../types-DE0ooQJ6.mjs';
3
+ import '../types-CrVMq_Td.mjs';
4
4
 
5
5
  /**
6
6
  * Git Trigger — Enterprise git push / PR verification
@@ -1,6 +1,6 @@
1
1
  import { AstraSyncGateway } from '../gateway/gateway.js';
2
- import { V as VerificationDecision, P as PDLSSContext } from '../types-79qS7aON.js';
3
- import '../types-CxQwJKbd.js';
2
+ import { V as VerificationDecision, P as PDLSSContext } from '../types-rigu2bH3.js';
3
+ import '../types-CrVMq_Td.js';
4
4
 
5
5
  /**
6
6
  * Git Trigger — Enterprise git push / PR verification
@@ -1,4 +1,4 @@
1
- import { A as AstraSyncCredentials, g as ProtocolTransport, G as GatewayConfig } from './types-CxQwJKbd.mjs';
1
+ import { A as AstraSyncCredentials, g as ProtocolTransport, G as GatewayConfig } from './types-CrVMq_Td.mjs';
2
2
 
3
3
  /**
4
4
  * AgentClient — Credential Presentation
@@ -12,6 +12,10 @@ interface AgentClientConfig {
12
12
  verifyUrl?: string;
13
13
  challengeUrl?: string;
14
14
  pdlss?: AstraSyncCredentials['pdlss'];
15
+ /** Base URL for AstraSync API (used for ownership check). Defaults to api.astrasync.ai */
16
+ apiBaseUrl?: string;
17
+ /** API key used to authenticate ownership check + other authenticated calls. */
18
+ apiKey?: string;
15
19
  }
16
20
  interface FetchOptions extends RequestInit {
17
21
  purpose?: string;
@@ -19,7 +23,25 @@ interface FetchOptions extends RequestInit {
19
23
  }
20
24
  declare class AgentClient {
21
25
  private credentials;
26
+ private apiBaseUrl;
27
+ private apiKey;
22
28
  constructor(config: AgentClientConfig);
29
+ /**
30
+ * Async factory that validates the API key's account owns the configured
31
+ * ASTRA-id before returning a usable client. Refuses to initialise on
32
+ * mismatch so a stolen ASTRA-id cannot be paired with a valid (different)
33
+ * API key.
34
+ *
35
+ * Set env `ASTRASYNC_SKIP_OWNERSHIP_CHECK=true` to bypass — intended for
36
+ * test environments only.
37
+ */
38
+ static create(config: AgentClientConfig): Promise<AgentClient>;
39
+ /**
40
+ * Calls GET /api/agents/:astraId/ownership with the configured API key.
41
+ * Returns true only when the backend confirms this API key's account
42
+ * owns the configured agent.
43
+ */
44
+ private verifyOwnership;
23
45
  /**
24
46
  * Make an HTTP request with AstraSync headers automatically injected.
25
47
  */
@@ -183,6 +205,23 @@ interface RecordDecisionResult {
183
205
  */
184
206
  declare function recordDecision(config: GatewayConfig, params: RecordDecisionParams): Promise<RecordDecisionResult>;
185
207
 
208
+ /**
209
+ * Agent-side SDK errors.
210
+ */
211
+ declare class AstraSyncSdkError extends Error {
212
+ readonly code: string;
213
+ constructor(code: string, message: string);
214
+ }
215
+ /**
216
+ * Thrown when the API key used to initialise AgentClient is not owned by
217
+ * the same account that registered the configured ASTRA-id. Blocks the
218
+ * client from doing anything under a mismatched identity.
219
+ */
220
+ declare class OwnershipMismatchError extends AstraSyncSdkError {
221
+ readonly astraId: string;
222
+ constructor(astraId: string);
223
+ }
224
+
186
225
  /**
187
226
  * Agent-Side SDK Module
188
227
  *
@@ -192,15 +231,19 @@ declare function recordDecision(config: GatewayConfig, params: RecordDecisionPar
192
231
 
193
232
  type index_AgentClient = AgentClient;
194
233
  declare const index_AgentClient: typeof AgentClient;
234
+ type index_AstraSyncSdkError = AstraSyncSdkError;
235
+ declare const index_AstraSyncSdkError: typeof AstraSyncSdkError;
195
236
  type index_ChallengeHandler = ChallengeHandler;
196
237
  declare const index_ChallengeHandler: typeof ChallengeHandler;
238
+ type index_OwnershipMismatchError = OwnershipMismatchError;
239
+ declare const index_OwnershipMismatchError: typeof OwnershipMismatchError;
197
240
  type index_PDLSSConfig = PDLSSConfig;
198
241
  type index_TransportPDLSS = TransportPDLSS;
199
242
  declare const index_formatPDLSSForTransport: typeof formatPDLSSForTransport;
200
243
  declare const index_parsePDLSSFromTransport: typeof parsePDLSSFromTransport;
201
244
  declare const index_recordDecision: typeof recordDecision;
202
245
  declare namespace index {
203
- export { index_AgentClient as AgentClient, index_ChallengeHandler as ChallengeHandler, type index_PDLSSConfig as PDLSSConfig, type index_TransportPDLSS as TransportPDLSS, index_formatPDLSSForTransport as formatPDLSSForTransport, index_parsePDLSSFromTransport as parsePDLSSFromTransport, index_recordDecision as recordDecision };
246
+ export { index_AgentClient as AgentClient, index_AstraSyncSdkError as AstraSyncSdkError, index_ChallengeHandler as ChallengeHandler, index_OwnershipMismatchError as OwnershipMismatchError, type index_PDLSSConfig as PDLSSConfig, type index_TransportPDLSS as TransportPDLSS, index_formatPDLSSForTransport as formatPDLSSForTransport, index_parsePDLSSFromTransport as parsePDLSSFromTransport, index_recordDecision as recordDecision };
204
247
  }
205
248
 
206
- export { AgentClient as A, ChallengeHandler as C, type PDLSSConfig as P, type TransportPDLSS as T, formatPDLSSForTransport as f, index as i, parsePDLSSFromTransport as p, recordDecision as r };
249
+ export { AgentClient as A, ChallengeHandler as C, OwnershipMismatchError as O, type PDLSSConfig as P, type TransportPDLSS as T, AstraSyncSdkError as a, formatPDLSSForTransport as f, index as i, parsePDLSSFromTransport as p, recordDecision as r };
@@ -1,4 +1,4 @@
1
- import { A as AstraSyncCredentials, g as ProtocolTransport } from './types-CxQwJKbd.mjs';
1
+ import { A as AstraSyncCredentials, g as ProtocolTransport } from './types-CrVMq_Td.mjs';
2
2
  import { JWK } from 'jose';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { A as AstraSyncCredentials, g as ProtocolTransport, G as GatewayConfig } from './types-CxQwJKbd.js';
1
+ import { A as AstraSyncCredentials, g as ProtocolTransport, G as GatewayConfig } from './types-CrVMq_Td.js';
2
2
 
3
3
  /**
4
4
  * AgentClient — Credential Presentation
@@ -12,6 +12,10 @@ interface AgentClientConfig {
12
12
  verifyUrl?: string;
13
13
  challengeUrl?: string;
14
14
  pdlss?: AstraSyncCredentials['pdlss'];
15
+ /** Base URL for AstraSync API (used for ownership check). Defaults to api.astrasync.ai */
16
+ apiBaseUrl?: string;
17
+ /** API key used to authenticate ownership check + other authenticated calls. */
18
+ apiKey?: string;
15
19
  }
16
20
  interface FetchOptions extends RequestInit {
17
21
  purpose?: string;
@@ -19,7 +23,25 @@ interface FetchOptions extends RequestInit {
19
23
  }
20
24
  declare class AgentClient {
21
25
  private credentials;
26
+ private apiBaseUrl;
27
+ private apiKey;
22
28
  constructor(config: AgentClientConfig);
29
+ /**
30
+ * Async factory that validates the API key's account owns the configured
31
+ * ASTRA-id before returning a usable client. Refuses to initialise on
32
+ * mismatch so a stolen ASTRA-id cannot be paired with a valid (different)
33
+ * API key.
34
+ *
35
+ * Set env `ASTRASYNC_SKIP_OWNERSHIP_CHECK=true` to bypass — intended for
36
+ * test environments only.
37
+ */
38
+ static create(config: AgentClientConfig): Promise<AgentClient>;
39
+ /**
40
+ * Calls GET /api/agents/:astraId/ownership with the configured API key.
41
+ * Returns true only when the backend confirms this API key's account
42
+ * owns the configured agent.
43
+ */
44
+ private verifyOwnership;
23
45
  /**
24
46
  * Make an HTTP request with AstraSync headers automatically injected.
25
47
  */
@@ -183,6 +205,23 @@ interface RecordDecisionResult {
183
205
  */
184
206
  declare function recordDecision(config: GatewayConfig, params: RecordDecisionParams): Promise<RecordDecisionResult>;
185
207
 
208
+ /**
209
+ * Agent-side SDK errors.
210
+ */
211
+ declare class AstraSyncSdkError extends Error {
212
+ readonly code: string;
213
+ constructor(code: string, message: string);
214
+ }
215
+ /**
216
+ * Thrown when the API key used to initialise AgentClient is not owned by
217
+ * the same account that registered the configured ASTRA-id. Blocks the
218
+ * client from doing anything under a mismatched identity.
219
+ */
220
+ declare class OwnershipMismatchError extends AstraSyncSdkError {
221
+ readonly astraId: string;
222
+ constructor(astraId: string);
223
+ }
224
+
186
225
  /**
187
226
  * Agent-Side SDK Module
188
227
  *
@@ -192,15 +231,19 @@ declare function recordDecision(config: GatewayConfig, params: RecordDecisionPar
192
231
 
193
232
  type index_AgentClient = AgentClient;
194
233
  declare const index_AgentClient: typeof AgentClient;
234
+ type index_AstraSyncSdkError = AstraSyncSdkError;
235
+ declare const index_AstraSyncSdkError: typeof AstraSyncSdkError;
195
236
  type index_ChallengeHandler = ChallengeHandler;
196
237
  declare const index_ChallengeHandler: typeof ChallengeHandler;
238
+ type index_OwnershipMismatchError = OwnershipMismatchError;
239
+ declare const index_OwnershipMismatchError: typeof OwnershipMismatchError;
197
240
  type index_PDLSSConfig = PDLSSConfig;
198
241
  type index_TransportPDLSS = TransportPDLSS;
199
242
  declare const index_formatPDLSSForTransport: typeof formatPDLSSForTransport;
200
243
  declare const index_parsePDLSSFromTransport: typeof parsePDLSSFromTransport;
201
244
  declare const index_recordDecision: typeof recordDecision;
202
245
  declare namespace index {
203
- export { index_AgentClient as AgentClient, index_ChallengeHandler as ChallengeHandler, type index_PDLSSConfig as PDLSSConfig, type index_TransportPDLSS as TransportPDLSS, index_formatPDLSSForTransport as formatPDLSSForTransport, index_parsePDLSSFromTransport as parsePDLSSFromTransport, index_recordDecision as recordDecision };
246
+ export { index_AgentClient as AgentClient, index_AstraSyncSdkError as AstraSyncSdkError, index_ChallengeHandler as ChallengeHandler, index_OwnershipMismatchError as OwnershipMismatchError, type index_PDLSSConfig as PDLSSConfig, type index_TransportPDLSS as TransportPDLSS, index_formatPDLSSForTransport as formatPDLSSForTransport, index_parsePDLSSFromTransport as parsePDLSSFromTransport, index_recordDecision as recordDecision };
204
247
  }
205
248
 
206
- export { AgentClient as A, ChallengeHandler as C, type PDLSSConfig as P, type TransportPDLSS as T, formatPDLSSForTransport as f, index as i, parsePDLSSFromTransport as p, recordDecision as r };
249
+ export { AgentClient as A, ChallengeHandler as C, OwnershipMismatchError as O, type PDLSSConfig as P, type TransportPDLSS as T, AstraSyncSdkError as a, formatPDLSSForTransport as f, index as i, parsePDLSSFromTransport as p, recordDecision as r };
@@ -1,4 +1,4 @@
1
- import { A as AstraSyncCredentials, g as ProtocolTransport } from './types-CxQwJKbd.js';
1
+ import { A as AstraSyncCredentials, g as ProtocolTransport } from './types-CrVMq_Td.js';
2
2
  import { JWK } from 'jose';
3
3
 
4
4
  /**
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
- import { b as AgentCredentials, G as GatewayConfig, a as AccessLevel, c as VerificationRequest, V as VerificationResult } from './types-CxQwJKbd.mjs';
2
- export { A as AstraSyncCredentials, d as CommerceShieldProps, C as CounterpartyType, e as EnhancedVerificationResult, E as ExpressMiddlewareOptions, f as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, g as ProtocolTransport, R as RouteAccessConfig, h as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, i as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-CxQwJKbd.mjs';
3
- export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, c as getCapabilities, e as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-BhvuJSrH.mjs';
4
- export { e as express } from './express-CtwDIZyF.mjs';
5
- export { n as nextjs } from './nextjs-BQyMCSx_.mjs';
6
- export { i as transport } from './index-3NRaBNvp.mjs';
7
- export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-BY8yQ8N8.mjs';
1
+ import { b as AgentCredentials, G as GatewayConfig, a as AccessLevel, c as VerificationRequest, V as VerificationResult } from './types-CrVMq_Td.mjs';
2
+ export { A as AstraSyncCredentials, d as CommerceShieldProps, C as CounterpartyType, e as EnhancedVerificationResult, E as ExpressMiddlewareOptions, f as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, g as ProtocolTransport, R as RouteAccessConfig, h as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, i as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-CrVMq_Td.mjs';
3
+ export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, c as getCapabilities, e as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-7fa9H0qa.mjs';
4
+ export { e as express } from './express-C9KqJNWV.mjs';
5
+ export { n as nextjs } from './nextjs-BEqidT0U.mjs';
6
+ export { i as transport } from './index-DlsYN3Et.mjs';
7
+ export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-BMZdjGT4.mjs';
8
8
  import 'express';
9
9
  import 'next/server';
10
10
  import 'jose';
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { b as AgentCredentials, G as GatewayConfig, a as AccessLevel, c as VerificationRequest, V as VerificationResult } from './types-CxQwJKbd.js';
2
- export { A as AstraSyncCredentials, d as CommerceShieldProps, C as CounterpartyType, e as EnhancedVerificationResult, E as ExpressMiddlewareOptions, f as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, g as ProtocolTransport, R as RouteAccessConfig, h as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, i as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-CxQwJKbd.js';
3
- export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, c as getCapabilities, e as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-BlyVSC_S.js';
4
- export { e as express } from './express-Bcl-uBUE.js';
5
- export { n as nextjs } from './nextjs-CEldnIJ9.js';
6
- export { i as transport } from './index-CME6r4uH.js';
7
- export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-CtYSYwn3.js';
1
+ import { b as AgentCredentials, G as GatewayConfig, a as AccessLevel, c as VerificationRequest, V as VerificationResult } from './types-CrVMq_Td.js';
2
+ export { A as AstraSyncCredentials, d as CommerceShieldProps, C as CounterpartyType, e as EnhancedVerificationResult, E as ExpressMiddlewareOptions, f as GuidanceInfo, N as NextJsMiddlewareOptions, P as PDLSSInfo, g as ProtocolTransport, R as RouteAccessConfig, h as RuntimeChallengeResult, S as SDKOptions, T as TokenGuidance, i as TrustLevel, j as VerifiedAgent, k as VerifiedDeveloper, l as VerifiedOrganization } from './types-CrVMq_Td.js';
3
+ export { A as ACCESS_LEVEL_DESCRIPTIONS, a as ACCESS_LEVEL_HIERARCHY, b as AccessCapabilities, D as DEFAULT_TRUST_THRESHOLDS, T as TRUST_LEVEL_RANGES, d as determineAccessLevel, g as getAccessLevelForScore, c as getCapabilities, e as getTrustLevel, h as hasMinimumAccess, s as sdk } from './sdk-CP9C9Qu0.js';
4
+ export { e as express } from './express-DpwYW08E.js';
5
+ export { n as nextjs } from './nextjs-yNzimC3a.js';
6
+ export { i as transport } from './index-gM-lgX_X.js';
7
+ export { A as AgentClient, C as ChallengeHandler, i as agent, r as recordDecision } from './index-Dm2xA6j1.js';
8
8
  import 'express';
9
9
  import 'next/server';
10
10
  import 'jose';
package/dist/index.js CHANGED
@@ -278,21 +278,33 @@ async function callVerifyAccessAPI(config, request) {
278
278
  if (requestData.isSubAgentRequest) body.isSubAgentRequest = requestData.isSubAgentRequest;
279
279
  if (requestData.parentAgentId) body.parentAgentId = requestData.parentAgentId;
280
280
  if (requestData.subAgentDepth !== void 0) body.subAgentDepth = requestData.subAgentDepth;
281
- if (requestData.enableRuntimeChallenge) body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
281
+ if (requestData.enableRuntimeChallenge)
282
+ body.enableRuntimeChallenge = requestData.enableRuntimeChallenge;
282
283
  if (requestData.createSession) body.createSession = requestData.createSession;
283
284
  if (requestData.durationRequired) body.durationRequired = requestData.durationRequired;
284
285
  if (requestData.counterpartyType) body.counterpartyType = requestData.counterpartyType;
285
286
  if (requestData.counterpartyUrl) body.counterpartyUrl = requestData.counterpartyUrl;
286
- if (requestData.runtimeChallengeOptions) body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
287
+ if (requestData.runtimeChallengeOptions)
288
+ body.runtimeChallengeOptions = requestData.runtimeChallengeOptions;
289
+ if (requestData.callerMetadata || requestData.clientIp || requestData.userAgent) {
290
+ const meta = {
291
+ ...requestData.clientIp && { sourceIp: requestData.clientIp },
292
+ ...requestData.userAgent && { userAgent: requestData.userAgent },
293
+ ...requestData.callerMetadata
294
+ };
295
+ if (Object.keys(meta).length > 0) body.callerMetadata = meta;
296
+ }
287
297
  const headers = {
288
298
  "Content-Type": "application/json",
289
299
  ...config.customHeaders
290
300
  };
291
- if (config.apiKey) {
292
- headers["X-API-Key"] = config.apiKey;
293
- }
294
301
  if (credentials.authorizationHeader) {
295
302
  headers["Authorization"] = credentials.authorizationHeader;
303
+ } else if (config.apiKey) {
304
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
305
+ }
306
+ if (config.apiKey) {
307
+ headers["X-API-Key"] = config.apiKey;
296
308
  }
297
309
  try {
298
310
  const response = await fetch(`${config.apiBaseUrl}/agents/verify-access`, {
@@ -393,16 +405,11 @@ async function verify(config, request) {
393
405
  } : void 0;
394
406
  const trustScore = agent?.trustScore || 0;
395
407
  const isOrgMember = false;
396
- const accessLevel = determineAccessLevel(
397
- true,
398
- trustScore,
399
- isOrgMember,
400
- {
401
- "read-only": 20,
402
- standard: mergedConfig.minTrustScore || 40,
403
- full: mergedConfig.minTrustScoreForFull || 70
404
- }
405
- );
408
+ const accessLevel = determineAccessLevel(true, trustScore, isOrgMember, {
409
+ "read-only": 20,
410
+ standard: mergedConfig.minTrustScore || 40,
411
+ full: mergedConfig.minTrustScoreForFull || 70
412
+ });
406
413
  const result = {
407
414
  verified: true,
408
415
  accessLevel,
@@ -424,7 +431,9 @@ async function verify(config, request) {
424
431
  if (result.recommendation === "deny") {
425
432
  result.verified = false;
426
433
  result.accessLevel = "none";
427
- result.denialReasons = result.recommendationReasons || ["Access denied by AstraSync recommendation"];
434
+ result.denialReasons = result.recommendationReasons || [
435
+ "Access denied by AstraSync recommendation"
436
+ ];
428
437
  if (result.runtimeChallenge) {
429
438
  result.guidance = {
430
439
  message: `Verification failed: ${result.runtimeChallenge.reason || "runtime challenge failed"}`,
@@ -446,7 +455,10 @@ async function verify(config, request) {
446
455
  }
447
456
  async function recordDecision(config, sessionId, decision, reason) {
448
457
  const headers = { "Content-Type": "application/json" };
449
- if (config.apiKey) headers["X-API-Key"] = config.apiKey;
458
+ if (config.apiKey) {
459
+ headers["Authorization"] = `Bearer ${config.apiKey}`;
460
+ headers["X-API-Key"] = config.apiKey;
461
+ }
450
462
  await fetch(`${config.apiBaseUrl}/agents/verify-access/${sessionId}/decision`, {
451
463
  method: "POST",
452
464
  headers,
@@ -744,18 +756,28 @@ function createMiddleware(options) {
744
756
  return;
745
757
  }
746
758
  const shouldRecordDecisions = recordDecisions !== false;
759
+ const forwardedFor = req.headers["x-forwarded-for"];
760
+ const forwardedForStr = Array.isArray(forwardedFor) ? forwardedFor.join(", ") : forwardedFor;
761
+ const originalClientIp = forwardedForStr ? forwardedForStr.split(",")[0].trim() : req.ip;
762
+ const agentCardUrl = typeof req.headers["x-astrasync-agent-card"] === "string" ? req.headers["x-astrasync-agent-card"] : void 0;
747
763
  const result = await verify(config, {
748
764
  credentials,
749
765
  purpose,
750
766
  action: req.method.toLowerCase(),
751
767
  resource: req.path,
752
- clientIp: req.ip,
753
- userAgent: req.headers["user-agent"],
754
768
  createSession: shouldRecordDecisions,
755
769
  counterpartyUrl,
756
770
  counterpartyType: config.counterpartyType || "api",
757
771
  enableRuntimeChallenge,
758
- durationRequired: astraCreds?.pdlss?.duration?.maxSessionDuration
772
+ durationRequired: astraCreds?.pdlss?.duration?.maxSessionDuration,
773
+ callerMetadata: {
774
+ sourceIp: originalClientIp,
775
+ userAgent: req.headers["user-agent"],
776
+ referer: req.headers.referer,
777
+ host: req.headers.host,
778
+ forwardedFor: forwardedForStr,
779
+ agentCardUrl
780
+ }
759
781
  });
760
782
  req.agentVerification = result;
761
783
  const sessionId = result.sessionId;
@@ -1027,7 +1049,13 @@ function generateCommerceShieldHtml(result, options) {
1027
1049
  `.trim();
1028
1050
  }
1029
1051
  function createMiddleware2(options) {
1030
- const { routes = [], skipPaths = [], showCommerceShield = true, enableRuntimeChallenge = true, ...config } = options;
1052
+ const {
1053
+ routes = [],
1054
+ skipPaths = [],
1055
+ showCommerceShield = true,
1056
+ enableRuntimeChallenge = true,
1057
+ ...config
1058
+ } = options;
1031
1059
  return async function middleware(request) {
1032
1060
  const { NextResponse } = await import("next/server");
1033
1061
  const pathname = request.nextUrl.pathname;
@@ -1139,17 +1167,25 @@ function createMiddleware2(options) {
1139
1167
  }
1140
1168
  return NextResponse.redirect(new URL("/unauthorized", request.url));
1141
1169
  }
1170
+ const forwardedFor = request.headers.get("x-forwarded-for") || void 0;
1171
+ const originalClientIp = forwardedFor?.split(",")[0]?.trim();
1142
1172
  const result = await verify(config, {
1143
1173
  credentials,
1144
1174
  purpose,
1145
1175
  action: request.method.toLowerCase(),
1146
1176
  resource: pathname,
1147
- clientIp: request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || void 0,
1148
- userAgent: request.headers.get("user-agent") || void 0,
1149
1177
  counterpartyUrl,
1150
1178
  counterpartyType: config.counterpartyType || "website",
1151
1179
  enableRuntimeChallenge,
1152
- durationRequired: astraCreds?.pdlss?.duration?.maxSessionDuration
1180
+ durationRequired: astraCreds?.pdlss?.duration?.maxSessionDuration,
1181
+ callerMetadata: {
1182
+ sourceIp: originalClientIp,
1183
+ userAgent: request.headers.get("user-agent") || void 0,
1184
+ referer: request.headers.get("referer") || void 0,
1185
+ host: request.headers.get("host") || void 0,
1186
+ forwardedFor,
1187
+ agentCardUrl: request.headers.get("x-astrasync-agent-card") || void 0
1188
+ }
1153
1189
  });
1154
1190
  if (!hasMinimumAccess(result.accessLevel, routeConfig.minAccessLevel)) {
1155
1191
  if (pathname.startsWith("/api/")) {
@@ -3771,14 +3807,35 @@ function extractCredentialsFromProtocol(protocol, context) {
3771
3807
  var agent_exports = {};
3772
3808
  __export(agent_exports, {
3773
3809
  AgentClient: () => AgentClient,
3810
+ AstraSyncSdkError: () => AstraSyncSdkError,
3774
3811
  ChallengeHandler: () => ChallengeHandler,
3812
+ OwnershipMismatchError: () => OwnershipMismatchError,
3775
3813
  formatPDLSSForTransport: () => formatPDLSSForTransport,
3776
3814
  parsePDLSSFromTransport: () => parsePDLSSFromTransport,
3777
3815
  recordDecision: () => recordDecision2
3778
3816
  });
3779
3817
 
3818
+ // src/agent/errors.ts
3819
+ var AstraSyncSdkError = class extends Error {
3820
+ constructor(code, message) {
3821
+ super(message);
3822
+ this.name = "AstraSyncSdkError";
3823
+ this.code = code;
3824
+ }
3825
+ };
3826
+ var OwnershipMismatchError = class extends AstraSyncSdkError {
3827
+ constructor(astraId) {
3828
+ super(
3829
+ "ownership_mismatch",
3830
+ `The configured API key does not own agent ${astraId}. Refusing to initialise.`
3831
+ );
3832
+ this.name = "OwnershipMismatchError";
3833
+ this.astraId = astraId;
3834
+ }
3835
+ };
3836
+
3780
3837
  // src/agent/client.ts
3781
- var AgentClient = class {
3838
+ var AgentClient = class _AgentClient {
3782
3839
  constructor(config) {
3783
3840
  this.credentials = {
3784
3841
  agentId: config.agentId,
@@ -3786,6 +3843,49 @@ var AgentClient = class {
3786
3843
  challengeUrl: config.challengeUrl,
3787
3844
  pdlss: config.pdlss
3788
3845
  };
3846
+ this.apiBaseUrl = config.apiBaseUrl ?? "https://api.astrasync.ai";
3847
+ this.apiKey = config.apiKey;
3848
+ }
3849
+ /**
3850
+ * Async factory that validates the API key's account owns the configured
3851
+ * ASTRA-id before returning a usable client. Refuses to initialise on
3852
+ * mismatch so a stolen ASTRA-id cannot be paired with a valid (different)
3853
+ * API key.
3854
+ *
3855
+ * Set env `ASTRASYNC_SKIP_OWNERSHIP_CHECK=true` to bypass — intended for
3856
+ * test environments only.
3857
+ */
3858
+ static async create(config) {
3859
+ const client = new _AgentClient(config);
3860
+ const skip = typeof process !== "undefined" && process.env?.ASTRASYNC_SKIP_OWNERSHIP_CHECK === "true";
3861
+ if (skip) return client;
3862
+ if (!config.apiKey) {
3863
+ throw new OwnershipMismatchError(config.agentId);
3864
+ }
3865
+ const owned = await client.verifyOwnership();
3866
+ if (!owned) throw new OwnershipMismatchError(config.agentId);
3867
+ return client;
3868
+ }
3869
+ /**
3870
+ * Calls GET /api/agents/:astraId/ownership with the configured API key.
3871
+ * Returns true only when the backend confirms this API key's account
3872
+ * owns the configured agent.
3873
+ */
3874
+ async verifyOwnership() {
3875
+ if (!this.apiKey) return false;
3876
+ const url = `${this.apiBaseUrl.replace(/\/+$/, "")}/api/agents/${encodeURIComponent(
3877
+ this.credentials.agentId
3878
+ )}/ownership`;
3879
+ const resp = await fetch(url, {
3880
+ method: "GET",
3881
+ headers: {
3882
+ Authorization: `Bearer ${this.apiKey}`,
3883
+ "Content-Type": "application/json"
3884
+ }
3885
+ });
3886
+ if (!resp.ok) return false;
3887
+ const body = await resp.json().catch(() => null);
3888
+ return Boolean(body?.data?.owned);
3789
3889
  }
3790
3890
  /**
3791
3891
  * Make an HTTP request with AstraSync headers automatically injected.