@axonflow/sdk 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.
- package/README.md +39 -36
- package/dist/cjs/client.d.ts +32 -2
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +108 -77
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/errors.d.ts +93 -6
- package/dist/cjs/errors.d.ts.map +1 -1
- package/dist/cjs/errors.js +126 -12
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +7 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/code-governance.d.ts +2 -0
- package/dist/cjs/types/code-governance.d.ts.map +1 -1
- package/dist/cjs/types/config.d.ts +15 -7
- package/dist/cjs/types/config.d.ts.map +1 -1
- package/dist/cjs/types/proxy.d.ts +2 -2
- package/dist/cjs/types/proxy.d.ts.map +1 -1
- package/dist/esm/client.d.ts +32 -2
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +109 -78
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/errors.d.ts +93 -6
- package/dist/esm/errors.d.ts.map +1 -1
- package/dist/esm/errors.js +121 -11
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/code-governance.d.ts +2 -0
- package/dist/esm/types/code-governance.d.ts.map +1 -1
- package/dist/esm/types/config.d.ts +15 -7
- package/dist/esm/types/config.d.ts.map +1 -1
- package/dist/esm/types/proxy.d.ts +2 -2
- package/dist/esm/types/proxy.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ import OpenAI from 'openai';
|
|
|
26
26
|
// Initialize clients
|
|
27
27
|
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
28
28
|
const axonflow = new AxonFlow({
|
|
29
|
-
|
|
29
|
+
clientId: process.env.AXONFLOW_CLIENT_ID,
|
|
30
|
+
clientSecret: process.env.AXONFLOW_CLIENT_SECRET,
|
|
30
31
|
endpoint: process.env.AXONFLOW_ENDPOINT || 'http://localhost:8080'
|
|
31
32
|
});
|
|
32
33
|
|
|
@@ -75,7 +76,8 @@ For simpler integrations, Proxy Mode handles policy checking and auditing in a s
|
|
|
75
76
|
import { AxonFlow } from '@axonflow/sdk';
|
|
76
77
|
|
|
77
78
|
const axonflow = new AxonFlow({
|
|
78
|
-
|
|
79
|
+
clientId: process.env.AXONFLOW_CLIENT_ID,
|
|
80
|
+
clientSecret: process.env.AXONFLOW_CLIENT_SECRET,
|
|
79
81
|
endpoint: 'http://localhost:8080'
|
|
80
82
|
});
|
|
81
83
|
|
|
@@ -163,15 +165,6 @@ docker-compose up
|
|
|
163
165
|
- ✅ Same API as production
|
|
164
166
|
- ✅ Automatically detects localhost and skips authentication
|
|
165
167
|
|
|
166
|
-
### Legacy API Key Auth (Deprecated)
|
|
167
|
-
|
|
168
|
-
> **⚠️ Deprecated**: `apiKey` authentication is deprecated. Please migrate to license-based authentication using `licenseKey`.
|
|
169
|
-
|
|
170
|
-
```typescript
|
|
171
|
-
// Legacy method (still supported for backward compatibility)
|
|
172
|
-
const axonflow = new AxonFlow({ apiKey: process.env.AXONFLOW_API_KEY });
|
|
173
|
-
```
|
|
174
|
-
|
|
175
168
|
## Proxy Mode (executeQuery)
|
|
176
169
|
|
|
177
170
|
Proxy Mode routes all requests through AxonFlow's `/api/request` endpoint, providing a simpler integration pattern with automatic policy enforcement:
|
|
@@ -182,7 +175,8 @@ Proxy Mode routes all requests through AxonFlow's `/api/request` endpoint, provi
|
|
|
182
175
|
import { AxonFlow, PolicyViolationError } from '@axonflow/sdk';
|
|
183
176
|
|
|
184
177
|
const axonflow = new AxonFlow({
|
|
185
|
-
|
|
178
|
+
clientId: process.env.AXONFLOW_CLIENT_ID,
|
|
179
|
+
clientSecret: process.env.AXONFLOW_CLIENT_SECRET
|
|
186
180
|
});
|
|
187
181
|
|
|
188
182
|
// Execute a chat query with policy enforcement
|
|
@@ -298,7 +292,8 @@ import { AxonFlow } from '@axonflow/sdk';
|
|
|
298
292
|
import { useState } from 'react';
|
|
299
293
|
|
|
300
294
|
const axonflow = new AxonFlow({
|
|
301
|
-
|
|
295
|
+
clientId: process.env.REACT_APP_AXONFLOW_CLIENT_ID,
|
|
296
|
+
clientSecret: process.env.REACT_APP_AXONFLOW_CLIENT_SECRET,
|
|
302
297
|
endpoint: process.env.REACT_APP_AXONFLOW_ENDPOINT || 'http://localhost:8080'
|
|
303
298
|
});
|
|
304
299
|
|
|
@@ -341,7 +336,8 @@ import OpenAI from 'openai';
|
|
|
341
336
|
|
|
342
337
|
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
343
338
|
const axonflow = new AxonFlow({
|
|
344
|
-
|
|
339
|
+
clientId: process.env.AXONFLOW_CLIENT_ID,
|
|
340
|
+
clientSecret: process.env.AXONFLOW_CLIENT_SECRET,
|
|
345
341
|
endpoint: process.env.AXONFLOW_ENDPOINT || 'http://localhost:8080'
|
|
346
342
|
});
|
|
347
343
|
|
|
@@ -396,12 +392,14 @@ export default async function handler(req, res) {
|
|
|
396
392
|
|
|
397
393
|
```typescript
|
|
398
394
|
const axonflow = new AxonFlow({
|
|
399
|
-
|
|
395
|
+
// Authentication (OAuth2 client credentials)
|
|
396
|
+
clientId: 'your-client-id', // Required for cloud/enterprise
|
|
397
|
+
clientSecret: 'your-client-secret', // Required for cloud/enterprise
|
|
400
398
|
|
|
401
399
|
// Optional settings
|
|
402
400
|
mode: 'production', // or 'sandbox' for testing
|
|
403
401
|
endpoint: 'https://staging-eu.getaxonflow.com', // Default public endpoint
|
|
404
|
-
tenant: 'your-tenant-id', // For multi-tenant setups
|
|
402
|
+
tenant: 'your-tenant-id', // For multi-tenant setups
|
|
405
403
|
debug: true, // Enable debug logging
|
|
406
404
|
|
|
407
405
|
// Retry configuration
|
|
@@ -425,9 +423,9 @@ For customers running within AWS VPC, use the private endpoint for sub-10ms late
|
|
|
425
423
|
|
|
426
424
|
```typescript
|
|
427
425
|
const axonflow = new AxonFlow({
|
|
428
|
-
|
|
426
|
+
clientId: process.env.AXONFLOW_CLIENT_ID,
|
|
427
|
+
clientSecret: process.env.AXONFLOW_CLIENT_SECRET,
|
|
429
428
|
endpoint: 'https://vpc-private-endpoint.getaxonflow.com:8443', // VPC private endpoint
|
|
430
|
-
tenant: 'your-client-id',
|
|
431
429
|
mode: 'production'
|
|
432
430
|
});
|
|
433
431
|
```
|
|
@@ -442,7 +440,7 @@ const axonflow = new AxonFlow({
|
|
|
442
440
|
|
|
443
441
|
```typescript
|
|
444
442
|
// Use sandbox mode for testing without affecting production
|
|
445
|
-
const axonflow = AxonFlow.sandbox('demo-
|
|
443
|
+
const axonflow = AxonFlow.sandbox('demo-client', 'demo-secret');
|
|
446
444
|
|
|
447
445
|
// Test with PII detection (will be blocked)
|
|
448
446
|
try {
|
|
@@ -498,10 +496,11 @@ try {
|
|
|
498
496
|
|
|
499
497
|
## Production Best Practices
|
|
500
498
|
|
|
501
|
-
1. **Environment Variables**: Never hardcode
|
|
499
|
+
1. **Environment Variables**: Never hardcode credentials
|
|
502
500
|
```typescript
|
|
503
501
|
const axonflow = new AxonFlow({
|
|
504
|
-
|
|
502
|
+
clientId: process.env.AXONFLOW_CLIENT_ID,
|
|
503
|
+
clientSecret: process.env.AXONFLOW_CLIENT_SECRET
|
|
505
504
|
});
|
|
506
505
|
```
|
|
507
506
|
|
|
@@ -514,7 +513,8 @@ try {
|
|
|
514
513
|
3. **Tenant Isolation**: Use tenant IDs for multi-tenant apps
|
|
515
514
|
```typescript
|
|
516
515
|
const axonflow = new AxonFlow({
|
|
517
|
-
|
|
516
|
+
clientId: process.env.AXONFLOW_CLIENT_ID,
|
|
517
|
+
clientSecret: process.env.AXONFLOW_CLIENT_SECRET,
|
|
518
518
|
tenant: getCurrentTenantId()
|
|
519
519
|
});
|
|
520
520
|
```
|
|
@@ -738,9 +738,10 @@ if (status.status === 'running') {
|
|
|
738
738
|
import { AxonFlow } from '@axonflow/sdk';
|
|
739
739
|
|
|
740
740
|
async function planTrip() {
|
|
741
|
-
// Initialize client with
|
|
741
|
+
// Initialize client with OAuth2 credentials
|
|
742
742
|
const axonflow = new AxonFlow({
|
|
743
|
-
|
|
743
|
+
clientId: process.env.AXONFLOW_CLIENT_ID,
|
|
744
|
+
clientSecret: process.env.AXONFLOW_CLIENT_SECRET,
|
|
744
745
|
debug: true
|
|
745
746
|
});
|
|
746
747
|
|
|
@@ -770,33 +771,35 @@ planTrip().catch(console.error);
|
|
|
770
771
|
|
|
771
772
|
## Migration Guide
|
|
772
773
|
|
|
773
|
-
### Migrating
|
|
774
|
+
### Migrating to OAuth2 Client Credentials
|
|
774
775
|
|
|
775
|
-
If you're
|
|
776
|
+
If you're using older authentication methods (`apiKey` or `licenseKey`), migrate to OAuth2 client credentials:
|
|
776
777
|
|
|
777
|
-
**Before:**
|
|
778
|
+
**Before (v2.x):**
|
|
778
779
|
```typescript
|
|
779
780
|
const axonflow = new AxonFlow({
|
|
780
781
|
apiKey: process.env.AXONFLOW_API_KEY
|
|
781
782
|
});
|
|
783
|
+
// or
|
|
784
|
+
const axonflow = new AxonFlow({
|
|
785
|
+
licenseKey: process.env.AXONFLOW_LICENSE_KEY
|
|
786
|
+
});
|
|
782
787
|
```
|
|
783
788
|
|
|
784
|
-
**After:**
|
|
789
|
+
**After (v3.x):**
|
|
785
790
|
```typescript
|
|
786
791
|
const axonflow = new AxonFlow({
|
|
787
|
-
|
|
792
|
+
clientId: process.env.AXONFLOW_CLIENT_ID,
|
|
793
|
+
clientSecret: process.env.AXONFLOW_CLIENT_SECRET
|
|
788
794
|
});
|
|
789
795
|
```
|
|
790
796
|
|
|
791
|
-
**How to get
|
|
797
|
+
**How to get credentials:**
|
|
792
798
|
1. Contact AxonFlow support at [dev@getaxonflow.com](mailto:dev@getaxonflow.com)
|
|
793
|
-
2.
|
|
794
|
-
3. Store
|
|
799
|
+
2. Credentials are provided as part of your AxonFlow subscription
|
|
800
|
+
3. Store credentials securely in environment variables or secrets management systems
|
|
795
801
|
|
|
796
|
-
**
|
|
797
|
-
- The SDK maintains full backward compatibility with `apiKey`
|
|
798
|
-
- No breaking changes - existing code continues to work
|
|
799
|
-
- You can migrate at your own pace
|
|
802
|
+
**Self-hosted users:** No credentials required for localhost endpoints.
|
|
800
803
|
|
|
801
804
|
## License
|
|
802
805
|
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -7,6 +7,15 @@ export declare class AxonFlow {
|
|
|
7
7
|
private interceptors;
|
|
8
8
|
private sessionCookie;
|
|
9
9
|
constructor(config: AxonFlowConfig);
|
|
10
|
+
/**
|
|
11
|
+
* Get authentication headers based on configured credentials.
|
|
12
|
+
*
|
|
13
|
+
* Uses OAuth2-style Basic auth: Authorization: Basic base64(clientId:clientSecret)
|
|
14
|
+
* Also adds X-Tenant-ID header from clientId for tenant context.
|
|
15
|
+
*
|
|
16
|
+
* @returns Headers object with authentication headers
|
|
17
|
+
*/
|
|
18
|
+
private getAuthHeaders;
|
|
10
19
|
/**
|
|
11
20
|
* Main method to protect AI calls with governance
|
|
12
21
|
* @param aiCall The AI call to protect
|
|
@@ -73,7 +82,7 @@ export declare class AxonFlow {
|
|
|
73
82
|
/**
|
|
74
83
|
* Create a sandbox client for testing
|
|
75
84
|
*/
|
|
76
|
-
static sandbox(
|
|
85
|
+
static sandbox(clientId?: string, clientSecret?: string): AxonFlow;
|
|
77
86
|
/**
|
|
78
87
|
* Check if AxonFlow Agent is healthy and available.
|
|
79
88
|
*
|
|
@@ -295,7 +304,9 @@ export declare class AxonFlow {
|
|
|
295
304
|
*/
|
|
296
305
|
private parseAuditLogEntry;
|
|
297
306
|
/**
|
|
298
|
-
* Build authentication headers for API requests
|
|
307
|
+
* Build authentication headers for API requests.
|
|
308
|
+
* Includes Content-Type and X-Org-ID for policy APIs.
|
|
309
|
+
* Uses getAuthHeaders() for authentication credentials.
|
|
299
310
|
*/
|
|
300
311
|
private buildAuthHeaders;
|
|
301
312
|
/**
|
|
@@ -732,6 +743,25 @@ export declare class AxonFlow {
|
|
|
732
743
|
* ```
|
|
733
744
|
*/
|
|
734
745
|
getPR(prId: string): Promise<PRRecord>;
|
|
746
|
+
/**
|
|
747
|
+
* Close a PR without merging and optionally delete the branch.
|
|
748
|
+
* Useful for cleaning up test PRs created by examples.
|
|
749
|
+
*
|
|
750
|
+
* @param prId - PR record ID
|
|
751
|
+
* @param deleteBranch - Whether to delete the associated branch (default: true)
|
|
752
|
+
* @returns Closed PR record
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* ```typescript
|
|
756
|
+
* // Close PR and delete branch
|
|
757
|
+
* const pr = await axonflow.closePR('pr_123');
|
|
758
|
+
* console.log(`PR #${pr.prNumber} closed`);
|
|
759
|
+
*
|
|
760
|
+
* // Close PR but keep branch
|
|
761
|
+
* const pr = await axonflow.closePR('pr_123', false);
|
|
762
|
+
* ```
|
|
763
|
+
*/
|
|
764
|
+
closePR(prId: string, deleteBranch?: boolean): Promise<PRRecord>;
|
|
735
765
|
/**
|
|
736
766
|
* Sync PR status with the Git provider.
|
|
737
767
|
* This updates the local record with the current state from GitHub/GitLab/Bitbucket.
|
package/dist/cjs/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAId,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EAEjB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EAEZ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAC3B,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EAExB,eAAe,EACf,2BAA2B,EAC3B,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,EAC3B,wBAAwB,EACxB,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,cAAc,EAEd,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EAEtB,MAAM,EACN,eAAe,EACf,YAAY,EAEZ,oBAAoB,EACpB,cAAc,EACd,YAAY,EACZ,cAAc,EAGd,oBAAoB,EAEpB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACxB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAId,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EAEjB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EAEZ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,yBAAyB,EACzB,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAC3B,iBAAiB,EACjB,aAAa,EACb,wBAAwB,EAExB,eAAe,EACf,2BAA2B,EAC3B,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,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E,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC;IAmBzE;;;;;;OAMG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;IAenF;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQnD;;;;;OAKG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAiB9D;;;;;OAKG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAuBtE;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IA6BvE;;;;;OAKG;IACG,eAAe,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAe7D;;;;;;OAMG;IACG,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IA6BlF;;;;;OAKG;IACG,gBAAgB,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoCxF;;;;;;OAMG;IACG,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA2BjF,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,kBAAkB;IAY1B;;;;OAIG;YACW,iBAAiB;CAkChC"}
|
package/dist/cjs/client.js
CHANGED
|
@@ -12,15 +12,19 @@ class AxonFlow {
|
|
|
12
12
|
constructor(config) {
|
|
13
13
|
this.interceptors = [];
|
|
14
14
|
this.sessionCookie = null;
|
|
15
|
+
// Configuration validation
|
|
16
|
+
if (config.clientSecret && !config.clientId) {
|
|
17
|
+
throw new errors_1.ConfigurationError('clientSecret requires clientId to be set. ' +
|
|
18
|
+
'Provide both clientId and clientSecret for OAuth2-style authentication.');
|
|
19
|
+
}
|
|
15
20
|
// Set defaults first to determine endpoint
|
|
16
21
|
const endpoint = config.endpoint || 'https://staging-eu.getaxonflow.com';
|
|
17
|
-
// Credentials
|
|
18
|
-
|
|
19
|
-
const hasCredentials = !!(config.licenseKey || config.apiKey);
|
|
22
|
+
// Credentials check: OAuth2-style (clientId/clientSecret)
|
|
23
|
+
const hasCredentials = !!(config.clientId && config.clientSecret);
|
|
20
24
|
// Set configuration
|
|
21
25
|
this.config = {
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
clientId: config.clientId,
|
|
27
|
+
clientSecret: config.clientSecret,
|
|
24
28
|
endpoint,
|
|
25
29
|
mode: config.mode || (hasCredentials ? 'production' : 'sandbox'),
|
|
26
30
|
tenant: config.tenant || 'default',
|
|
@@ -40,17 +44,33 @@ class AxonFlow {
|
|
|
40
44
|
// Initialize interceptors
|
|
41
45
|
this.interceptors = [new openai_1.OpenAIInterceptor(), new anthropic_1.AnthropicInterceptor()];
|
|
42
46
|
if (this.config.debug) {
|
|
47
|
+
// Determine auth method for logging
|
|
48
|
+
const authMethod = hasCredentials ? 'client-credentials' : 'community (no auth)';
|
|
43
49
|
(0, helpers_1.debugLog)('AxonFlow initialized', {
|
|
44
50
|
mode: this.config.mode,
|
|
45
51
|
endpoint: this.config.endpoint,
|
|
46
|
-
authMethod
|
|
47
|
-
? this.config.licenseKey
|
|
48
|
-
? 'license-key'
|
|
49
|
-
: 'api-key'
|
|
50
|
-
: 'community (no auth)',
|
|
52
|
+
authMethod,
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Get authentication headers based on configured credentials.
|
|
58
|
+
*
|
|
59
|
+
* Uses OAuth2-style Basic auth: Authorization: Basic base64(clientId:clientSecret)
|
|
60
|
+
* Also adds X-Tenant-ID header from clientId for tenant context.
|
|
61
|
+
*
|
|
62
|
+
* @returns Headers object with authentication headers
|
|
63
|
+
*/
|
|
64
|
+
getAuthHeaders() {
|
|
65
|
+
const headers = {};
|
|
66
|
+
// OAuth2-style client credentials
|
|
67
|
+
if (this.config.clientId && this.config.clientSecret) {
|
|
68
|
+
const credentials = Buffer.from(`${this.config.clientId}:${this.config.clientSecret}`).toString('base64');
|
|
69
|
+
headers['Authorization'] = `Basic ${credentials}`;
|
|
70
|
+
headers['X-Tenant-ID'] = this.config.clientId;
|
|
71
|
+
}
|
|
72
|
+
return headers;
|
|
73
|
+
}
|
|
54
74
|
/**
|
|
55
75
|
* Main method to protect AI calls with governance
|
|
56
76
|
* @param aiCall The AI call to protect
|
|
@@ -169,8 +189,8 @@ class AxonFlow {
|
|
|
169
189
|
// Transform SDK request to Agent API format
|
|
170
190
|
const agentRequest = {
|
|
171
191
|
query: request.aiRequest.prompt,
|
|
172
|
-
user_token:
|
|
173
|
-
client_id: this.config.tenant,
|
|
192
|
+
user_token: '',
|
|
193
|
+
client_id: this.config.clientId || this.config.tenant,
|
|
174
194
|
request_type: 'llm_chat',
|
|
175
195
|
context: {
|
|
176
196
|
provider: request.aiRequest.provider,
|
|
@@ -182,12 +202,8 @@ class AxonFlow {
|
|
|
182
202
|
};
|
|
183
203
|
const headers = {
|
|
184
204
|
'Content-Type': 'application/json',
|
|
205
|
+
...this.getAuthHeaders(),
|
|
185
206
|
};
|
|
186
|
-
// Add auth headers only when credentials are provided
|
|
187
|
-
// Community/self-hosted mode works without credentials
|
|
188
|
-
if (this.config.licenseKey) {
|
|
189
|
-
headers['X-License-Key'] = this.config.licenseKey;
|
|
190
|
-
}
|
|
191
207
|
const response = await fetch(url, {
|
|
192
208
|
method: 'POST',
|
|
193
209
|
headers,
|
|
@@ -250,9 +266,10 @@ class AxonFlow {
|
|
|
250
266
|
/**
|
|
251
267
|
* Create a sandbox client for testing
|
|
252
268
|
*/
|
|
253
|
-
static sandbox(
|
|
269
|
+
static sandbox(clientId = 'demo-client', clientSecret = 'demo-secret') {
|
|
254
270
|
return new AxonFlow({
|
|
255
|
-
|
|
271
|
+
clientId,
|
|
272
|
+
clientSecret,
|
|
256
273
|
mode: 'sandbox',
|
|
257
274
|
endpoint: 'https://staging-eu.getaxonflow.com',
|
|
258
275
|
debug: true,
|
|
@@ -389,9 +406,11 @@ class AxonFlow {
|
|
|
389
406
|
* ```
|
|
390
407
|
*/
|
|
391
408
|
async executeQuery(options) {
|
|
409
|
+
// Default to "anonymous" if userToken is empty/undefined (community mode)
|
|
410
|
+
const effectiveUserToken = options.userToken || 'anonymous';
|
|
392
411
|
const agentRequest = {
|
|
393
412
|
query: options.query,
|
|
394
|
-
user_token:
|
|
413
|
+
user_token: effectiveUserToken,
|
|
395
414
|
client_id: this.config.tenant,
|
|
396
415
|
request_type: options.requestType,
|
|
397
416
|
context: options.context || {},
|
|
@@ -399,15 +418,8 @@ class AxonFlow {
|
|
|
399
418
|
const url = `${this.config.endpoint}/api/request`;
|
|
400
419
|
const headers = {
|
|
401
420
|
'Content-Type': 'application/json',
|
|
421
|
+
...this.getAuthHeaders(),
|
|
402
422
|
};
|
|
403
|
-
// Add auth headers only when credentials are provided
|
|
404
|
-
// Community/self-hosted mode works without credentials
|
|
405
|
-
if (this.config.licenseKey) {
|
|
406
|
-
headers['X-License-Key'] = this.config.licenseKey;
|
|
407
|
-
}
|
|
408
|
-
else if (this.config.apiKey) {
|
|
409
|
-
headers['X-Client-Secret'] = this.config.apiKey;
|
|
410
|
-
}
|
|
411
423
|
if (this.config.debug) {
|
|
412
424
|
(0, helpers_1.debugLog)('Proxy Mode: executeQuery', {
|
|
413
425
|
requestType: options.requestType,
|
|
@@ -532,8 +544,8 @@ class AxonFlow {
|
|
|
532
544
|
async queryConnector(connectorName, query, params) {
|
|
533
545
|
const agentRequest = {
|
|
534
546
|
query,
|
|
535
|
-
user_token:
|
|
536
|
-
client_id: this.config.tenant,
|
|
547
|
+
user_token: '',
|
|
548
|
+
client_id: this.config.clientId || this.config.tenant,
|
|
537
549
|
request_type: 'mcp-query',
|
|
538
550
|
context: {
|
|
539
551
|
connector: connectorName,
|
|
@@ -543,10 +555,8 @@ class AxonFlow {
|
|
|
543
555
|
const url = `${this.config.endpoint}/api/request`;
|
|
544
556
|
const headers = {
|
|
545
557
|
'Content-Type': 'application/json',
|
|
558
|
+
...this.getAuthHeaders(),
|
|
546
559
|
};
|
|
547
|
-
if (this.config.licenseKey) {
|
|
548
|
-
headers['X-License-Key'] = this.config.licenseKey;
|
|
549
|
-
}
|
|
550
560
|
const response = await fetch(url, {
|
|
551
561
|
method: 'POST',
|
|
552
562
|
headers,
|
|
@@ -555,7 +565,7 @@ class AxonFlow {
|
|
|
555
565
|
});
|
|
556
566
|
if (!response.ok) {
|
|
557
567
|
const errorText = await response.text();
|
|
558
|
-
throw new
|
|
568
|
+
throw new errors_1.ConnectorError(`Connector query failed: ${response.status} ${response.statusText} - ${errorText}`, connectorName, 'query');
|
|
559
569
|
}
|
|
560
570
|
const agentResponse = await response.json();
|
|
561
571
|
if (this.config.debug) {
|
|
@@ -585,10 +595,8 @@ class AxonFlow {
|
|
|
585
595
|
const url = `${this.config.endpoint}/api/request`;
|
|
586
596
|
const headers = {
|
|
587
597
|
'Content-Type': 'application/json',
|
|
598
|
+
...this.getAuthHeaders(),
|
|
588
599
|
};
|
|
589
|
-
if (this.config.licenseKey) {
|
|
590
|
-
headers['X-License-Key'] = this.config.licenseKey;
|
|
591
|
-
}
|
|
592
600
|
// Use mapTimeout for MAP operations (default 2 minutes)
|
|
593
601
|
const response = await fetch(url, {
|
|
594
602
|
method: 'POST',
|
|
@@ -598,11 +606,11 @@ class AxonFlow {
|
|
|
598
606
|
});
|
|
599
607
|
if (!response.ok) {
|
|
600
608
|
const errorText = await response.text();
|
|
601
|
-
throw new
|
|
609
|
+
throw new errors_1.PlanExecutionError(`Plan generation failed: ${response.status} ${response.statusText} - ${errorText}`, undefined, 'generation');
|
|
602
610
|
}
|
|
603
611
|
const agentResponse = await response.json();
|
|
604
612
|
if (!agentResponse.success) {
|
|
605
|
-
throw new
|
|
613
|
+
throw new errors_1.PlanExecutionError(`Plan generation failed: ${agentResponse.error}`, undefined, 'generation');
|
|
606
614
|
}
|
|
607
615
|
// plan_id can be at top level or inside data
|
|
608
616
|
const planId = agentResponse.plan_id || agentResponse.data?.plan_id;
|
|
@@ -634,10 +642,8 @@ class AxonFlow {
|
|
|
634
642
|
const url = `${this.config.endpoint}/api/request`;
|
|
635
643
|
const headers = {
|
|
636
644
|
'Content-Type': 'application/json',
|
|
645
|
+
...this.getAuthHeaders(),
|
|
637
646
|
};
|
|
638
|
-
if (this.config.licenseKey) {
|
|
639
|
-
headers['X-License-Key'] = this.config.licenseKey;
|
|
640
|
-
}
|
|
641
647
|
// Use mapTimeout for MAP operations (default 2 minutes)
|
|
642
648
|
const response = await fetch(url, {
|
|
643
649
|
method: 'POST',
|
|
@@ -647,7 +653,7 @@ class AxonFlow {
|
|
|
647
653
|
});
|
|
648
654
|
if (!response.ok) {
|
|
649
655
|
const errorText = await response.text();
|
|
650
|
-
throw new
|
|
656
|
+
throw new errors_1.PlanExecutionError(`Plan execution failed: ${response.status} ${response.statusText} - ${errorText}`, planId, 'execution');
|
|
651
657
|
}
|
|
652
658
|
const agentResponse = await response.json();
|
|
653
659
|
if (this.config.debug) {
|
|
@@ -666,7 +672,7 @@ class AxonFlow {
|
|
|
666
672
|
* Get the status of a running or completed plan
|
|
667
673
|
*/
|
|
668
674
|
async getPlanStatus(planId) {
|
|
669
|
-
const url = `${this.config.endpoint}/api/
|
|
675
|
+
const url = `${this.config.endpoint}/api/v1/plan/${planId}`;
|
|
670
676
|
const response = await fetch(url, {
|
|
671
677
|
method: 'GET',
|
|
672
678
|
signal: AbortSignal.timeout(this.config.timeout),
|
|
@@ -749,15 +755,8 @@ class AxonFlow {
|
|
|
749
755
|
};
|
|
750
756
|
const headers = {
|
|
751
757
|
'Content-Type': 'application/json',
|
|
758
|
+
...this.getAuthHeaders(),
|
|
752
759
|
};
|
|
753
|
-
// Add auth headers only when credentials are provided
|
|
754
|
-
// Community/self-hosted mode works without credentials
|
|
755
|
-
if (this.config.licenseKey) {
|
|
756
|
-
headers['X-License-Key'] = this.config.licenseKey;
|
|
757
|
-
}
|
|
758
|
-
else if (this.config.apiKey) {
|
|
759
|
-
headers['X-Client-Secret'] = this.config.apiKey;
|
|
760
|
-
}
|
|
761
760
|
if (this.config.debug) {
|
|
762
761
|
(0, helpers_1.debugLog)('Gateway Mode: Pre-check', { query: options.query.substring(0, 50) });
|
|
763
762
|
}
|
|
@@ -848,15 +847,8 @@ class AxonFlow {
|
|
|
848
847
|
};
|
|
849
848
|
const headers = {
|
|
850
849
|
'Content-Type': 'application/json',
|
|
850
|
+
...this.getAuthHeaders(),
|
|
851
851
|
};
|
|
852
|
-
// Add auth headers only when credentials are provided
|
|
853
|
-
// Community/self-hosted mode works without credentials
|
|
854
|
-
if (this.config.licenseKey) {
|
|
855
|
-
headers['X-License-Key'] = this.config.licenseKey;
|
|
856
|
-
}
|
|
857
|
-
else if (this.config.apiKey) {
|
|
858
|
-
headers['X-Client-Secret'] = this.config.apiKey;
|
|
859
|
-
}
|
|
860
852
|
if (this.config.debug) {
|
|
861
853
|
(0, helpers_1.debugLog)('Gateway Mode: Audit', {
|
|
862
854
|
contextId: options.contextId,
|
|
@@ -1038,24 +1030,20 @@ class AxonFlow {
|
|
|
1038
1030
|
// Policy CRUD Methods - Static Policies
|
|
1039
1031
|
// ============================================================================
|
|
1040
1032
|
/**
|
|
1041
|
-
* Build authentication headers for API requests
|
|
1033
|
+
* Build authentication headers for API requests.
|
|
1034
|
+
* Includes Content-Type and X-Org-ID for policy APIs.
|
|
1035
|
+
* Uses getAuthHeaders() for authentication credentials.
|
|
1042
1036
|
*/
|
|
1043
1037
|
buildAuthHeaders() {
|
|
1044
1038
|
const headers = {
|
|
1045
1039
|
'Content-Type': 'application/json',
|
|
1040
|
+
...this.getAuthHeaders(),
|
|
1046
1041
|
};
|
|
1047
1042
|
// Always include tenant ID for policy APIs (X-Org-ID header for server compatibility)
|
|
1043
|
+
// Note: getAuthHeaders() already adds X-Tenant-ID when tenant is non-default
|
|
1048
1044
|
if (this.config.tenant) {
|
|
1049
1045
|
headers['X-Org-ID'] = this.config.tenant;
|
|
1050
1046
|
}
|
|
1051
|
-
// Add auth headers only when credentials are provided
|
|
1052
|
-
// Community/self-hosted mode works without credentials
|
|
1053
|
-
if (this.config.licenseKey) {
|
|
1054
|
-
headers['X-License-Key'] = this.config.licenseKey;
|
|
1055
|
-
}
|
|
1056
|
-
else if (this.config.apiKey) {
|
|
1057
|
-
headers['X-Client-Secret'] = this.config.apiKey;
|
|
1058
|
-
}
|
|
1059
1047
|
return headers;
|
|
1060
1048
|
}
|
|
1061
1049
|
/**
|
|
@@ -1080,8 +1068,8 @@ class AxonFlow {
|
|
|
1080
1068
|
}
|
|
1081
1069
|
throw new errors_1.APIError(response.status, response.statusText, errorText);
|
|
1082
1070
|
}
|
|
1083
|
-
// Handle
|
|
1084
|
-
if (response.status === 204
|
|
1071
|
+
// Handle 204 No Content responses
|
|
1072
|
+
if (response.status === 204) {
|
|
1085
1073
|
return undefined;
|
|
1086
1074
|
}
|
|
1087
1075
|
return response.json();
|
|
@@ -1435,7 +1423,7 @@ class AxonFlow {
|
|
|
1435
1423
|
// API returns {"policies": [...]} wrapper via Agent proxy
|
|
1436
1424
|
const response = await this.orchestratorRequest('GET', path);
|
|
1437
1425
|
// Handle both wrapped and unwrapped responses for compatibility
|
|
1438
|
-
return Array.isArray(response) ? response : response.policies;
|
|
1426
|
+
return Array.isArray(response) ? response : response.policies || [];
|
|
1439
1427
|
}
|
|
1440
1428
|
/**
|
|
1441
1429
|
* Get a specific dynamic policy by ID.
|
|
@@ -1543,7 +1531,7 @@ class AxonFlow {
|
|
|
1543
1531
|
// API returns {"policies": [...]} wrapper via Agent proxy
|
|
1544
1532
|
const response = await this.orchestratorRequest('GET', path);
|
|
1545
1533
|
// Handle both wrapped and unwrapped responses for compatibility
|
|
1546
|
-
return Array.isArray(response) ? response : response.policies;
|
|
1534
|
+
return Array.isArray(response) ? response : response.policies || [];
|
|
1547
1535
|
}
|
|
1548
1536
|
// ============================================================================
|
|
1549
1537
|
// Portal Authentication Methods (Enterprise)
|
|
@@ -1928,6 +1916,49 @@ class AxonFlow {
|
|
|
1928
1916
|
providerType: response.provider_type,
|
|
1929
1917
|
};
|
|
1930
1918
|
}
|
|
1919
|
+
/**
|
|
1920
|
+
* Close a PR without merging and optionally delete the branch.
|
|
1921
|
+
* Useful for cleaning up test PRs created by examples.
|
|
1922
|
+
*
|
|
1923
|
+
* @param prId - PR record ID
|
|
1924
|
+
* @param deleteBranch - Whether to delete the associated branch (default: true)
|
|
1925
|
+
* @returns Closed PR record
|
|
1926
|
+
*
|
|
1927
|
+
* @example
|
|
1928
|
+
* ```typescript
|
|
1929
|
+
* // Close PR and delete branch
|
|
1930
|
+
* const pr = await axonflow.closePR('pr_123');
|
|
1931
|
+
* console.log(`PR #${pr.prNumber} closed`);
|
|
1932
|
+
*
|
|
1933
|
+
* // Close PR but keep branch
|
|
1934
|
+
* const pr = await axonflow.closePR('pr_123', false);
|
|
1935
|
+
* ```
|
|
1936
|
+
*/
|
|
1937
|
+
async closePR(prId, deleteBranch = true) {
|
|
1938
|
+
if (this.config.debug) {
|
|
1939
|
+
(0, helpers_1.debugLog)('Closing PR', { prId, deleteBranch });
|
|
1940
|
+
}
|
|
1941
|
+
const query = deleteBranch ? '?delete_branch=true' : '';
|
|
1942
|
+
const response = await this.portalRequest('DELETE', `/api/v1/code-governance/prs/${prId}${query}`);
|
|
1943
|
+
return {
|
|
1944
|
+
id: response.id,
|
|
1945
|
+
prNumber: response.pr_number,
|
|
1946
|
+
prUrl: response.pr_url,
|
|
1947
|
+
title: response.title,
|
|
1948
|
+
state: response.state,
|
|
1949
|
+
owner: response.owner,
|
|
1950
|
+
repo: response.repo,
|
|
1951
|
+
headBranch: response.head_branch,
|
|
1952
|
+
baseBranch: response.base_branch,
|
|
1953
|
+
filesCount: response.files_count,
|
|
1954
|
+
secretsDetected: response.secrets_detected,
|
|
1955
|
+
unsafePatterns: response.unsafe_patterns,
|
|
1956
|
+
createdAt: response.created_at,
|
|
1957
|
+
closedAt: response.closed_at,
|
|
1958
|
+
createdBy: response.created_by,
|
|
1959
|
+
providerType: response.provider_type,
|
|
1960
|
+
};
|
|
1961
|
+
}
|
|
1931
1962
|
/**
|
|
1932
1963
|
* Sync PR status with the Git provider.
|
|
1933
1964
|
* This updates the local record with the current state from GitHub/GitLab/Bitbucket.
|
|
@@ -2121,8 +2152,8 @@ class AxonFlow {
|
|
|
2121
2152
|
}
|
|
2122
2153
|
throw new errors_1.APIError(response.status, response.statusText, errorText);
|
|
2123
2154
|
}
|
|
2124
|
-
// Handle
|
|
2125
|
-
if (response.status === 204
|
|
2155
|
+
// Handle 204 No Content responses
|
|
2156
|
+
if (response.status === 204) {
|
|
2126
2157
|
return undefined;
|
|
2127
2158
|
}
|
|
2128
2159
|
return response.json();
|
|
@@ -2165,8 +2196,8 @@ class AxonFlow {
|
|
|
2165
2196
|
}
|
|
2166
2197
|
throw new errors_1.APIError(response.status, response.statusText, errorText);
|
|
2167
2198
|
}
|
|
2168
|
-
// Handle
|
|
2169
|
-
if (response.status === 204
|
|
2199
|
+
// Handle 204 No Content responses
|
|
2200
|
+
if (response.status === 204) {
|
|
2170
2201
|
return undefined;
|
|
2171
2202
|
}
|
|
2172
2203
|
return response.json();
|