@kya-os/agentshield-nextjs 0.1.32 → 0.1.34
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/dist/index.d.mts +152 -3
- package/dist/index.d.ts +152 -3
- package/dist/index.js +461 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +461 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -18
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,158 @@
|
|
|
1
1
|
export { createMiddleware as createAgentShieldMiddleware, createMiddleware } from './create-middleware.mjs';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
import { DetectionResult } from '@kya-os/agentshield';
|
|
2
4
|
export { createAgentShieldMiddleware as createAgentShieldMiddlewareBase } from './middleware.mjs';
|
|
3
5
|
export { EdgeSessionTracker, SessionData, SessionTrackingConfig, StatelessSessionChecker } from './session-tracker.mjs';
|
|
4
6
|
export { D as DetectionContext, N as NextJSMiddlewareConfig } from './types-BJTEUa4T.mjs';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Storage adapter types for AgentShield
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Agent detection event stored in the system
|
|
13
|
+
*/
|
|
14
|
+
interface AgentDetectionEvent {
|
|
15
|
+
eventId: string;
|
|
16
|
+
sessionId: string;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
agentType: string;
|
|
19
|
+
agentName: string;
|
|
20
|
+
confidence: number;
|
|
21
|
+
path: string;
|
|
22
|
+
userAgent?: string;
|
|
23
|
+
ipAddress?: string;
|
|
24
|
+
method: string;
|
|
25
|
+
detectionReasons: string[];
|
|
26
|
+
verificationMethod: string;
|
|
27
|
+
detectionDetails?: {
|
|
28
|
+
patterns?: string[];
|
|
29
|
+
behaviors?: string[];
|
|
30
|
+
fingerprintMatches?: string[];
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Agent session information
|
|
35
|
+
*/
|
|
36
|
+
interface AgentSession {
|
|
37
|
+
sessionId: string;
|
|
38
|
+
ipAddress?: string;
|
|
39
|
+
userAgent?: string;
|
|
40
|
+
agentType: string;
|
|
41
|
+
agentName?: string;
|
|
42
|
+
firstSeen: string;
|
|
43
|
+
lastSeen: string;
|
|
44
|
+
eventCount: number;
|
|
45
|
+
paths: string[];
|
|
46
|
+
averageConfidence: number;
|
|
47
|
+
verificationMethods: string[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Storage adapter interface
|
|
51
|
+
* All methods should be async for compatibility with different backends
|
|
52
|
+
*/
|
|
53
|
+
interface StorageAdapter {
|
|
54
|
+
/**
|
|
55
|
+
* Store a detection event
|
|
56
|
+
*/
|
|
57
|
+
storeEvent(event: AgentDetectionEvent): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Get recent events
|
|
60
|
+
*/
|
|
61
|
+
getRecentEvents(limit?: number): Promise<AgentDetectionEvent[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Get events for a specific session
|
|
64
|
+
*/
|
|
65
|
+
getSessionEvents(sessionId: string): Promise<AgentDetectionEvent[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Store or update a session
|
|
68
|
+
*/
|
|
69
|
+
storeSession(session: AgentSession): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Get a session by ID
|
|
72
|
+
*/
|
|
73
|
+
getSession(sessionId: string): Promise<AgentSession | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Get recent sessions
|
|
76
|
+
*/
|
|
77
|
+
getRecentSessions(limit?: number): Promise<AgentSession[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Clean up old data (optional)
|
|
80
|
+
*/
|
|
81
|
+
cleanup?(olderThan: Date): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Storage configuration options
|
|
85
|
+
*/
|
|
86
|
+
interface StorageConfig {
|
|
87
|
+
/**
|
|
88
|
+
* Type of storage to use
|
|
89
|
+
*/
|
|
90
|
+
type: 'redis' | 'memory' | 'custom';
|
|
91
|
+
/**
|
|
92
|
+
* Redis configuration (if type is 'redis')
|
|
93
|
+
*/
|
|
94
|
+
redis?: {
|
|
95
|
+
url: string;
|
|
96
|
+
token: string;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Custom storage adapter (if type is 'custom')
|
|
100
|
+
*/
|
|
101
|
+
custom?: StorageAdapter;
|
|
102
|
+
/**
|
|
103
|
+
* TTL for stored data in seconds
|
|
104
|
+
* Default: 86400 (24 hours)
|
|
105
|
+
*/
|
|
106
|
+
ttl?: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Enhanced Next.js middleware with all features built-in
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Enhanced configuration with built-in features
|
|
115
|
+
*/
|
|
116
|
+
interface EnhancedMiddlewareConfig {
|
|
117
|
+
/**
|
|
118
|
+
* Storage configuration
|
|
119
|
+
*/
|
|
120
|
+
storage?: StorageConfig;
|
|
121
|
+
/**
|
|
122
|
+
* Session tracking configuration
|
|
123
|
+
*/
|
|
124
|
+
sessionTracking?: {
|
|
125
|
+
enabled?: boolean;
|
|
126
|
+
ttl?: number;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Paths to skip detection
|
|
130
|
+
*/
|
|
131
|
+
skipPaths?: string[];
|
|
132
|
+
/**
|
|
133
|
+
* Action when agent detected
|
|
134
|
+
*/
|
|
135
|
+
onAgentDetected?: 'block' | 'log' | 'allow';
|
|
136
|
+
/**
|
|
137
|
+
* Custom handler for agent detection
|
|
138
|
+
*/
|
|
139
|
+
onDetection?: (result: DetectionResult, context: any) => void | Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Confidence threshold
|
|
142
|
+
*/
|
|
143
|
+
confidenceThreshold?: number;
|
|
144
|
+
/**
|
|
145
|
+
* Response when blocking
|
|
146
|
+
*/
|
|
147
|
+
blockedResponse?: {
|
|
148
|
+
status?: number;
|
|
149
|
+
message?: string;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Create enhanced AgentShield middleware with all features
|
|
154
|
+
*/
|
|
155
|
+
declare function createEnhancedAgentShieldMiddleware(config?: EnhancedMiddlewareConfig): (request: NextRequest) => Promise<NextResponse>;
|
|
7
156
|
|
|
8
157
|
/**
|
|
9
158
|
* @fileoverview AgentShield Next.js Integration
|
|
@@ -16,4 +165,4 @@ import '@kya-os/agentshield';
|
|
|
16
165
|
*/
|
|
17
166
|
declare const VERSION = "0.1.0";
|
|
18
167
|
|
|
19
|
-
export { VERSION };
|
|
168
|
+
export { type AgentDetectionEvent, type AgentSession, type EnhancedMiddlewareConfig, type StorageAdapter, type StorageConfig, VERSION, createEnhancedAgentShieldMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,158 @@
|
|
|
1
1
|
export { createMiddleware as createAgentShieldMiddleware, createMiddleware } from './create-middleware.js';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
import { DetectionResult } from '@kya-os/agentshield';
|
|
2
4
|
export { createAgentShieldMiddleware as createAgentShieldMiddlewareBase } from './middleware.js';
|
|
3
5
|
export { EdgeSessionTracker, SessionData, SessionTrackingConfig, StatelessSessionChecker } from './session-tracker.js';
|
|
4
6
|
export { D as DetectionContext, N as NextJSMiddlewareConfig } from './types-BJTEUa4T.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Storage adapter types for AgentShield
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Agent detection event stored in the system
|
|
13
|
+
*/
|
|
14
|
+
interface AgentDetectionEvent {
|
|
15
|
+
eventId: string;
|
|
16
|
+
sessionId: string;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
agentType: string;
|
|
19
|
+
agentName: string;
|
|
20
|
+
confidence: number;
|
|
21
|
+
path: string;
|
|
22
|
+
userAgent?: string;
|
|
23
|
+
ipAddress?: string;
|
|
24
|
+
method: string;
|
|
25
|
+
detectionReasons: string[];
|
|
26
|
+
verificationMethod: string;
|
|
27
|
+
detectionDetails?: {
|
|
28
|
+
patterns?: string[];
|
|
29
|
+
behaviors?: string[];
|
|
30
|
+
fingerprintMatches?: string[];
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Agent session information
|
|
35
|
+
*/
|
|
36
|
+
interface AgentSession {
|
|
37
|
+
sessionId: string;
|
|
38
|
+
ipAddress?: string;
|
|
39
|
+
userAgent?: string;
|
|
40
|
+
agentType: string;
|
|
41
|
+
agentName?: string;
|
|
42
|
+
firstSeen: string;
|
|
43
|
+
lastSeen: string;
|
|
44
|
+
eventCount: number;
|
|
45
|
+
paths: string[];
|
|
46
|
+
averageConfidence: number;
|
|
47
|
+
verificationMethods: string[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Storage adapter interface
|
|
51
|
+
* All methods should be async for compatibility with different backends
|
|
52
|
+
*/
|
|
53
|
+
interface StorageAdapter {
|
|
54
|
+
/**
|
|
55
|
+
* Store a detection event
|
|
56
|
+
*/
|
|
57
|
+
storeEvent(event: AgentDetectionEvent): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Get recent events
|
|
60
|
+
*/
|
|
61
|
+
getRecentEvents(limit?: number): Promise<AgentDetectionEvent[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Get events for a specific session
|
|
64
|
+
*/
|
|
65
|
+
getSessionEvents(sessionId: string): Promise<AgentDetectionEvent[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Store or update a session
|
|
68
|
+
*/
|
|
69
|
+
storeSession(session: AgentSession): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Get a session by ID
|
|
72
|
+
*/
|
|
73
|
+
getSession(sessionId: string): Promise<AgentSession | null>;
|
|
74
|
+
/**
|
|
75
|
+
* Get recent sessions
|
|
76
|
+
*/
|
|
77
|
+
getRecentSessions(limit?: number): Promise<AgentSession[]>;
|
|
78
|
+
/**
|
|
79
|
+
* Clean up old data (optional)
|
|
80
|
+
*/
|
|
81
|
+
cleanup?(olderThan: Date): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Storage configuration options
|
|
85
|
+
*/
|
|
86
|
+
interface StorageConfig {
|
|
87
|
+
/**
|
|
88
|
+
* Type of storage to use
|
|
89
|
+
*/
|
|
90
|
+
type: 'redis' | 'memory' | 'custom';
|
|
91
|
+
/**
|
|
92
|
+
* Redis configuration (if type is 'redis')
|
|
93
|
+
*/
|
|
94
|
+
redis?: {
|
|
95
|
+
url: string;
|
|
96
|
+
token: string;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Custom storage adapter (if type is 'custom')
|
|
100
|
+
*/
|
|
101
|
+
custom?: StorageAdapter;
|
|
102
|
+
/**
|
|
103
|
+
* TTL for stored data in seconds
|
|
104
|
+
* Default: 86400 (24 hours)
|
|
105
|
+
*/
|
|
106
|
+
ttl?: number;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Enhanced Next.js middleware with all features built-in
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Enhanced configuration with built-in features
|
|
115
|
+
*/
|
|
116
|
+
interface EnhancedMiddlewareConfig {
|
|
117
|
+
/**
|
|
118
|
+
* Storage configuration
|
|
119
|
+
*/
|
|
120
|
+
storage?: StorageConfig;
|
|
121
|
+
/**
|
|
122
|
+
* Session tracking configuration
|
|
123
|
+
*/
|
|
124
|
+
sessionTracking?: {
|
|
125
|
+
enabled?: boolean;
|
|
126
|
+
ttl?: number;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Paths to skip detection
|
|
130
|
+
*/
|
|
131
|
+
skipPaths?: string[];
|
|
132
|
+
/**
|
|
133
|
+
* Action when agent detected
|
|
134
|
+
*/
|
|
135
|
+
onAgentDetected?: 'block' | 'log' | 'allow';
|
|
136
|
+
/**
|
|
137
|
+
* Custom handler for agent detection
|
|
138
|
+
*/
|
|
139
|
+
onDetection?: (result: DetectionResult, context: any) => void | Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Confidence threshold
|
|
142
|
+
*/
|
|
143
|
+
confidenceThreshold?: number;
|
|
144
|
+
/**
|
|
145
|
+
* Response when blocking
|
|
146
|
+
*/
|
|
147
|
+
blockedResponse?: {
|
|
148
|
+
status?: number;
|
|
149
|
+
message?: string;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Create enhanced AgentShield middleware with all features
|
|
154
|
+
*/
|
|
155
|
+
declare function createEnhancedAgentShieldMiddleware(config?: EnhancedMiddlewareConfig): (request: NextRequest) => Promise<NextResponse>;
|
|
7
156
|
|
|
8
157
|
/**
|
|
9
158
|
* @fileoverview AgentShield Next.js Integration
|
|
@@ -16,4 +165,4 @@ import '@kya-os/agentshield';
|
|
|
16
165
|
*/
|
|
17
166
|
declare const VERSION = "0.1.0";
|
|
18
167
|
|
|
19
|
-
export { VERSION };
|
|
168
|
+
export { type AgentDetectionEvent, type AgentSession, type EnhancedMiddlewareConfig, type StorageAdapter, type StorageConfig, VERSION, createEnhancedAgentShieldMiddleware };
|