@kya-os/agentshield-nextjs 0.1.29 → 0.1.31
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/create-middleware.js +591 -12
- package/dist/create-middleware.js.map +1 -1
- package/dist/create-middleware.mjs +591 -12
- package/dist/create-middleware.mjs.map +1 -1
- package/dist/edge-detector-wrapper.js +251 -12
- package/dist/edge-detector-wrapper.js.map +1 -1
- package/dist/edge-detector-wrapper.mjs +251 -12
- package/dist/edge-detector-wrapper.mjs.map +1 -1
- package/dist/index.js +591 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +591 -12
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.js +587 -8
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +587 -8
- package/dist/middleware.mjs.map +1 -1
- package/dist/signature-verifier.js +220 -0
- package/dist/signature-verifier.js.map +1 -0
- package/dist/signature-verifier.mjs +216 -0
- package/dist/signature-verifier.mjs.map +1 -0
- package/package.json +2 -2
- package/wasm/agentshield_wasm.d.ts +121 -0
- package/wasm/agentshield_wasm.js +576 -0
- package/wasm/agentshield_wasm_bg.wasm +0 -0
- package/dist/create-middleware.d.mts +0 -16
- package/dist/create-middleware.d.ts +0 -16
- package/dist/edge-detector-wrapper.d.mts +0 -42
- package/dist/edge-detector-wrapper.d.ts +0 -42
- package/dist/edge-runtime-loader.d.mts +0 -49
- package/dist/edge-runtime-loader.d.ts +0 -49
- package/dist/edge-wasm-middleware.d.mts +0 -58
- package/dist/edge-wasm-middleware.d.ts +0 -58
- package/dist/index.d.mts +0 -19
- package/dist/index.d.ts +0 -19
- package/dist/middleware.d.mts +0 -20
- package/dist/middleware.d.ts +0 -20
- package/dist/nodejs-wasm-loader.d.mts +0 -25
- package/dist/nodejs-wasm-loader.d.ts +0 -25
- package/dist/session-tracker.d.mts +0 -55
- package/dist/session-tracker.d.ts +0 -55
- package/dist/types-BJTEUa4T.d.mts +0 -88
- package/dist/types-BJTEUa4T.d.ts +0 -88
- package/dist/wasm-middleware.d.mts +0 -62
- package/dist/wasm-middleware.d.ts +0 -62
- package/dist/wasm-setup.d.mts +0 -46
- package/dist/wasm-setup.d.ts +0 -46
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
4
|
+
|
|
5
|
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
6
|
+
|
|
7
|
+
let cachedUint8ArrayMemory0 = null;
|
|
8
|
+
|
|
9
|
+
function getUint8ArrayMemory0() {
|
|
10
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
11
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
12
|
+
}
|
|
13
|
+
return cachedUint8ArrayMemory0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getStringFromWasm0(ptr, len) {
|
|
17
|
+
ptr = ptr >>> 0;
|
|
18
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const heap = new Array(128).fill(undefined);
|
|
22
|
+
|
|
23
|
+
heap.push(undefined, null, true, false);
|
|
24
|
+
|
|
25
|
+
function getObject(idx) { return heap[idx]; }
|
|
26
|
+
|
|
27
|
+
let heap_next = heap.length;
|
|
28
|
+
|
|
29
|
+
function addHeapObject(obj) {
|
|
30
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
31
|
+
const idx = heap_next;
|
|
32
|
+
heap_next = heap[idx];
|
|
33
|
+
|
|
34
|
+
heap[idx] = obj;
|
|
35
|
+
return idx;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let WASM_VECTOR_LEN = 0;
|
|
39
|
+
|
|
40
|
+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
41
|
+
|
|
42
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
43
|
+
? function (arg, view) {
|
|
44
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
45
|
+
}
|
|
46
|
+
: function (arg, view) {
|
|
47
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
48
|
+
view.set(buf);
|
|
49
|
+
return {
|
|
50
|
+
read: arg.length,
|
|
51
|
+
written: buf.length
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
56
|
+
|
|
57
|
+
if (realloc === undefined) {
|
|
58
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
59
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
60
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
61
|
+
WASM_VECTOR_LEN = buf.length;
|
|
62
|
+
return ptr;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let len = arg.length;
|
|
66
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
67
|
+
|
|
68
|
+
const mem = getUint8ArrayMemory0();
|
|
69
|
+
|
|
70
|
+
let offset = 0;
|
|
71
|
+
|
|
72
|
+
for (; offset < len; offset++) {
|
|
73
|
+
const code = arg.charCodeAt(offset);
|
|
74
|
+
if (code > 0x7F) break;
|
|
75
|
+
mem[ptr + offset] = code;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (offset !== len) {
|
|
79
|
+
if (offset !== 0) {
|
|
80
|
+
arg = arg.slice(offset);
|
|
81
|
+
}
|
|
82
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
83
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
84
|
+
const ret = encodeString(arg, view);
|
|
85
|
+
|
|
86
|
+
offset += ret.written;
|
|
87
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
WASM_VECTOR_LEN = offset;
|
|
91
|
+
return ptr;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let cachedDataViewMemory0 = null;
|
|
95
|
+
|
|
96
|
+
function getDataViewMemory0() {
|
|
97
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
98
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
99
|
+
}
|
|
100
|
+
return cachedDataViewMemory0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function dropObject(idx) {
|
|
104
|
+
if (idx < 132) return;
|
|
105
|
+
heap[idx] = heap_next;
|
|
106
|
+
heap_next = idx;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function takeObject(idx) {
|
|
110
|
+
const ret = getObject(idx);
|
|
111
|
+
dropObject(idx);
|
|
112
|
+
return ret;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function isLikeNone(x) {
|
|
116
|
+
return x === undefined || x === null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Initialize the AgentShield WASM module
|
|
120
|
+
*/
|
|
121
|
+
export function init() {
|
|
122
|
+
wasm.init();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function _assertClass(instance, klass) {
|
|
126
|
+
if (!(instance instanceof klass)) {
|
|
127
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Analyze a request and detect if it's from an agent
|
|
132
|
+
* @param {JsRequestMetadata} metadata
|
|
133
|
+
* @returns {JsDetectionResult}
|
|
134
|
+
*/
|
|
135
|
+
export function detect_agent(metadata) {
|
|
136
|
+
try {
|
|
137
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
138
|
+
_assertClass(metadata, JsRequestMetadata);
|
|
139
|
+
wasm.detect_agent(retptr, metadata.__wbg_ptr);
|
|
140
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
141
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
142
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
143
|
+
if (r2) {
|
|
144
|
+
throw takeObject(r1);
|
|
145
|
+
}
|
|
146
|
+
return JsDetectionResult.__wrap(r0);
|
|
147
|
+
} finally {
|
|
148
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get the version of the AgentShield library
|
|
154
|
+
* @returns {string}
|
|
155
|
+
*/
|
|
156
|
+
export function version() {
|
|
157
|
+
let deferred1_0;
|
|
158
|
+
let deferred1_1;
|
|
159
|
+
try {
|
|
160
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
161
|
+
wasm.version(retptr);
|
|
162
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
163
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
164
|
+
deferred1_0 = r0;
|
|
165
|
+
deferred1_1 = r1;
|
|
166
|
+
return getStringFromWasm0(r0, r1);
|
|
167
|
+
} finally {
|
|
168
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
169
|
+
wasm.__wbindgen_export_0(deferred1_0, deferred1_1, 1);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const JsDetectionResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
174
|
+
? { register: () => {}, unregister: () => {} }
|
|
175
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_jsdetectionresult_free(ptr >>> 0, 1));
|
|
176
|
+
/**
|
|
177
|
+
* JavaScript-compatible detection result
|
|
178
|
+
*/
|
|
179
|
+
export class JsDetectionResult {
|
|
180
|
+
|
|
181
|
+
static __wrap(ptr) {
|
|
182
|
+
ptr = ptr >>> 0;
|
|
183
|
+
const obj = Object.create(JsDetectionResult.prototype);
|
|
184
|
+
obj.__wbg_ptr = ptr;
|
|
185
|
+
JsDetectionResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
186
|
+
return obj;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
__destroy_into_raw() {
|
|
190
|
+
const ptr = this.__wbg_ptr;
|
|
191
|
+
this.__wbg_ptr = 0;
|
|
192
|
+
JsDetectionResultFinalization.unregister(this);
|
|
193
|
+
return ptr;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
free() {
|
|
197
|
+
const ptr = this.__destroy_into_raw();
|
|
198
|
+
wasm.__wbg_jsdetectionresult_free(ptr, 0);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Whether the request was identified as coming from an agent
|
|
202
|
+
* @returns {boolean}
|
|
203
|
+
*/
|
|
204
|
+
get is_agent() {
|
|
205
|
+
const ret = wasm.__wbg_get_jsdetectionresult_is_agent(this.__wbg_ptr);
|
|
206
|
+
return ret !== 0;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Whether the request was identified as coming from an agent
|
|
210
|
+
* @param {boolean} arg0
|
|
211
|
+
*/
|
|
212
|
+
set is_agent(arg0) {
|
|
213
|
+
wasm.__wbg_set_jsdetectionresult_is_agent(this.__wbg_ptr, arg0);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Confidence score (0.0 to 1.0)
|
|
217
|
+
* @returns {number}
|
|
218
|
+
*/
|
|
219
|
+
get confidence() {
|
|
220
|
+
const ret = wasm.__wbg_get_jsdetectionresult_confidence(this.__wbg_ptr);
|
|
221
|
+
return ret;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Confidence score (0.0 to 1.0)
|
|
225
|
+
* @param {number} arg0
|
|
226
|
+
*/
|
|
227
|
+
set confidence(arg0) {
|
|
228
|
+
wasm.__wbg_set_jsdetectionresult_confidence(this.__wbg_ptr, arg0);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get the detected agent name
|
|
232
|
+
* @returns {string | undefined}
|
|
233
|
+
*/
|
|
234
|
+
get agent() {
|
|
235
|
+
try {
|
|
236
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
237
|
+
wasm.jsdetectionresult_agent(retptr, this.__wbg_ptr);
|
|
238
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
239
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
240
|
+
let v1;
|
|
241
|
+
if (r0 !== 0) {
|
|
242
|
+
v1 = getStringFromWasm0(r0, r1).slice();
|
|
243
|
+
wasm.__wbindgen_export_0(r0, r1 * 1, 1);
|
|
244
|
+
}
|
|
245
|
+
return v1;
|
|
246
|
+
} finally {
|
|
247
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get the verification method as a string
|
|
252
|
+
* @returns {string}
|
|
253
|
+
*/
|
|
254
|
+
get verification_method() {
|
|
255
|
+
let deferred1_0;
|
|
256
|
+
let deferred1_1;
|
|
257
|
+
try {
|
|
258
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
259
|
+
wasm.jsdetectionresult_verification_method(retptr, this.__wbg_ptr);
|
|
260
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
261
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
262
|
+
deferred1_0 = r0;
|
|
263
|
+
deferred1_1 = r1;
|
|
264
|
+
return getStringFromWasm0(r0, r1);
|
|
265
|
+
} finally {
|
|
266
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
267
|
+
wasm.__wbindgen_export_0(deferred1_0, deferred1_1, 1);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get the risk level as a string
|
|
272
|
+
* @returns {string}
|
|
273
|
+
*/
|
|
274
|
+
get risk_level() {
|
|
275
|
+
let deferred1_0;
|
|
276
|
+
let deferred1_1;
|
|
277
|
+
try {
|
|
278
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
279
|
+
wasm.jsdetectionresult_risk_level(retptr, this.__wbg_ptr);
|
|
280
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
281
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
282
|
+
deferred1_0 = r0;
|
|
283
|
+
deferred1_1 = r1;
|
|
284
|
+
return getStringFromWasm0(r0, r1);
|
|
285
|
+
} finally {
|
|
286
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
287
|
+
wasm.__wbindgen_export_0(deferred1_0, deferred1_1, 1);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Get the timestamp as a string
|
|
292
|
+
* @returns {string}
|
|
293
|
+
*/
|
|
294
|
+
get timestamp() {
|
|
295
|
+
let deferred1_0;
|
|
296
|
+
let deferred1_1;
|
|
297
|
+
try {
|
|
298
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
299
|
+
wasm.jsdetectionresult_timestamp(retptr, this.__wbg_ptr);
|
|
300
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
301
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
302
|
+
deferred1_0 = r0;
|
|
303
|
+
deferred1_1 = r1;
|
|
304
|
+
return getStringFromWasm0(r0, r1);
|
|
305
|
+
} finally {
|
|
306
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
307
|
+
wasm.__wbindgen_export_0(deferred1_0, deferred1_1, 1);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const JsRequestMetadataFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
313
|
+
? { register: () => {}, unregister: () => {} }
|
|
314
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_jsrequestmetadata_free(ptr >>> 0, 1));
|
|
315
|
+
/**
|
|
316
|
+
* JavaScript-compatible request metadata
|
|
317
|
+
*/
|
|
318
|
+
export class JsRequestMetadata {
|
|
319
|
+
|
|
320
|
+
__destroy_into_raw() {
|
|
321
|
+
const ptr = this.__wbg_ptr;
|
|
322
|
+
this.__wbg_ptr = 0;
|
|
323
|
+
JsRequestMetadataFinalization.unregister(this);
|
|
324
|
+
return ptr;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
free() {
|
|
328
|
+
const ptr = this.__destroy_into_raw();
|
|
329
|
+
wasm.__wbg_jsrequestmetadata_free(ptr, 0);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Constructor for JsRequestMetadata
|
|
333
|
+
* @param {string | null | undefined} user_agent
|
|
334
|
+
* @param {string | null | undefined} ip_address
|
|
335
|
+
* @param {string} headers
|
|
336
|
+
* @param {string} timestamp
|
|
337
|
+
*/
|
|
338
|
+
constructor(user_agent, ip_address, headers, timestamp) {
|
|
339
|
+
var ptr0 = isLikeNone(user_agent) ? 0 : passStringToWasm0(user_agent, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
340
|
+
var len0 = WASM_VECTOR_LEN;
|
|
341
|
+
var ptr1 = isLikeNone(ip_address) ? 0 : passStringToWasm0(ip_address, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
342
|
+
var len1 = WASM_VECTOR_LEN;
|
|
343
|
+
const ptr2 = passStringToWasm0(headers, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
344
|
+
const len2 = WASM_VECTOR_LEN;
|
|
345
|
+
const ptr3 = passStringToWasm0(timestamp, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
346
|
+
const len3 = WASM_VECTOR_LEN;
|
|
347
|
+
const ret = wasm.jsrequestmetadata_new(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
348
|
+
this.__wbg_ptr = ret >>> 0;
|
|
349
|
+
JsRequestMetadataFinalization.register(this, this.__wbg_ptr, this);
|
|
350
|
+
return this;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Get the user agent
|
|
354
|
+
* @returns {string | undefined}
|
|
355
|
+
*/
|
|
356
|
+
get user_agent() {
|
|
357
|
+
try {
|
|
358
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
359
|
+
wasm.jsrequestmetadata_user_agent(retptr, this.__wbg_ptr);
|
|
360
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
361
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
362
|
+
let v1;
|
|
363
|
+
if (r0 !== 0) {
|
|
364
|
+
v1 = getStringFromWasm0(r0, r1).slice();
|
|
365
|
+
wasm.__wbindgen_export_0(r0, r1 * 1, 1);
|
|
366
|
+
}
|
|
367
|
+
return v1;
|
|
368
|
+
} finally {
|
|
369
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Get the IP address
|
|
374
|
+
* @returns {string | undefined}
|
|
375
|
+
*/
|
|
376
|
+
get ip_address() {
|
|
377
|
+
try {
|
|
378
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
379
|
+
wasm.jsrequestmetadata_ip_address(retptr, this.__wbg_ptr);
|
|
380
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
381
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
382
|
+
let v1;
|
|
383
|
+
if (r0 !== 0) {
|
|
384
|
+
v1 = getStringFromWasm0(r0, r1).slice();
|
|
385
|
+
wasm.__wbindgen_export_0(r0, r1 * 1, 1);
|
|
386
|
+
}
|
|
387
|
+
return v1;
|
|
388
|
+
} finally {
|
|
389
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Get the headers as JSON string
|
|
394
|
+
* @returns {string}
|
|
395
|
+
*/
|
|
396
|
+
get headers() {
|
|
397
|
+
let deferred1_0;
|
|
398
|
+
let deferred1_1;
|
|
399
|
+
try {
|
|
400
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
401
|
+
wasm.jsrequestmetadata_headers(retptr, this.__wbg_ptr);
|
|
402
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
403
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
404
|
+
deferred1_0 = r0;
|
|
405
|
+
deferred1_1 = r1;
|
|
406
|
+
return getStringFromWasm0(r0, r1);
|
|
407
|
+
} finally {
|
|
408
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
409
|
+
wasm.__wbindgen_export_0(deferred1_0, deferred1_1, 1);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Get the timestamp
|
|
414
|
+
* @returns {string}
|
|
415
|
+
*/
|
|
416
|
+
get timestamp() {
|
|
417
|
+
let deferred1_0;
|
|
418
|
+
let deferred1_1;
|
|
419
|
+
try {
|
|
420
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
421
|
+
wasm.jsrequestmetadata_timestamp(retptr, this.__wbg_ptr);
|
|
422
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
423
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
424
|
+
deferred1_0 = r0;
|
|
425
|
+
deferred1_1 = r1;
|
|
426
|
+
return getStringFromWasm0(r0, r1);
|
|
427
|
+
} finally {
|
|
428
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
429
|
+
wasm.__wbindgen_export_0(deferred1_0, deferred1_1, 1);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
async function __wbg_load(module, imports) {
|
|
435
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
436
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
437
|
+
try {
|
|
438
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
439
|
+
|
|
440
|
+
} catch (e) {
|
|
441
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
442
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
443
|
+
|
|
444
|
+
} else {
|
|
445
|
+
throw e;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const bytes = await module.arrayBuffer();
|
|
451
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
452
|
+
|
|
453
|
+
} else {
|
|
454
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
455
|
+
|
|
456
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
457
|
+
return { instance, module };
|
|
458
|
+
|
|
459
|
+
} else {
|
|
460
|
+
return instance;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function __wbg_get_imports() {
|
|
466
|
+
const imports = {};
|
|
467
|
+
imports.wbg = {};
|
|
468
|
+
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
|
469
|
+
let deferred0_0;
|
|
470
|
+
let deferred0_1;
|
|
471
|
+
try {
|
|
472
|
+
deferred0_0 = arg0;
|
|
473
|
+
deferred0_1 = arg1;
|
|
474
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
475
|
+
} finally {
|
|
476
|
+
wasm.__wbindgen_export_0(deferred0_0, deferred0_1, 1);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
imports.wbg.__wbg_log_c222819a41e063d3 = function(arg0) {
|
|
480
|
+
console.log(getObject(arg0));
|
|
481
|
+
};
|
|
482
|
+
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
|
483
|
+
const ret = new Error();
|
|
484
|
+
return addHeapObject(ret);
|
|
485
|
+
};
|
|
486
|
+
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
|
487
|
+
const ret = getObject(arg1).stack;
|
|
488
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_1, wasm.__wbindgen_export_2);
|
|
489
|
+
const len1 = WASM_VECTOR_LEN;
|
|
490
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
491
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
492
|
+
};
|
|
493
|
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
494
|
+
takeObject(arg0);
|
|
495
|
+
};
|
|
496
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
497
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
498
|
+
return addHeapObject(ret);
|
|
499
|
+
};
|
|
500
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
501
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
return imports;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function __wbg_init_memory(imports, memory) {
|
|
508
|
+
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function __wbg_finalize_init(instance, module) {
|
|
512
|
+
wasm = instance.exports;
|
|
513
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
514
|
+
cachedDataViewMemory0 = null;
|
|
515
|
+
cachedUint8ArrayMemory0 = null;
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
wasm.__wbindgen_start();
|
|
519
|
+
return wasm;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function initSync(module) {
|
|
523
|
+
if (wasm !== undefined) return wasm;
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
if (typeof module !== 'undefined') {
|
|
527
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
528
|
+
({module} = module)
|
|
529
|
+
} else {
|
|
530
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const imports = __wbg_get_imports();
|
|
535
|
+
|
|
536
|
+
__wbg_init_memory(imports);
|
|
537
|
+
|
|
538
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
539
|
+
module = new WebAssembly.Module(module);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
543
|
+
|
|
544
|
+
return __wbg_finalize_init(instance, module);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
async function __wbg_init(module_or_path) {
|
|
548
|
+
if (wasm !== undefined) return wasm;
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
if (typeof module_or_path !== 'undefined') {
|
|
552
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
553
|
+
({module_or_path} = module_or_path)
|
|
554
|
+
} else {
|
|
555
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (typeof module_or_path === 'undefined') {
|
|
560
|
+
module_or_path = new URL('agentshield_wasm_bg.wasm', import.meta.url);
|
|
561
|
+
}
|
|
562
|
+
const imports = __wbg_get_imports();
|
|
563
|
+
|
|
564
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
565
|
+
module_or_path = fetch(module_or_path);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
__wbg_init_memory(imports);
|
|
569
|
+
|
|
570
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
571
|
+
|
|
572
|
+
return __wbg_finalize_init(instance, module);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
export { initSync };
|
|
576
|
+
export default __wbg_init;
|
|
Binary file
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { N as NextJSMiddlewareConfig } from './types-BJTEUa4T.mjs';
|
|
3
|
-
import '@kya-os/agentshield';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Enhanced middleware creator for Edge Runtime
|
|
7
|
-
* Uses EdgeAgentDetector which doesn't require WASM
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create an AgentShield middleware with automatic WASM initialization
|
|
12
|
-
* This version handles initialization internally to avoid top-level await
|
|
13
|
-
*/
|
|
14
|
-
declare function createAgentShieldMiddleware(config: NextJSMiddlewareConfig): (request: NextRequest) => Promise<NextResponse>;
|
|
15
|
-
|
|
16
|
-
export { createAgentShieldMiddleware, createAgentShieldMiddleware as createMiddleware };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
-
import { N as NextJSMiddlewareConfig } from './types-BJTEUa4T.js';
|
|
3
|
-
import '@kya-os/agentshield';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Enhanced middleware creator for Edge Runtime
|
|
7
|
-
* Uses EdgeAgentDetector which doesn't require WASM
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Create an AgentShield middleware with automatic WASM initialization
|
|
12
|
-
* This version handles initialization internally to avoid top-level await
|
|
13
|
-
*/
|
|
14
|
-
declare function createAgentShieldMiddleware(config: NextJSMiddlewareConfig): (request: NextRequest) => Promise<NextResponse>;
|
|
15
|
-
|
|
16
|
-
export { createAgentShieldMiddleware, createAgentShieldMiddleware as createMiddleware };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wrapper for EdgeAgentDetector to match AgentDetector interface
|
|
3
|
-
* This allows the middleware to work with EdgeAgentDetector in Edge Runtime
|
|
4
|
-
*
|
|
5
|
-
* This is a self-contained implementation to avoid import resolution issues
|
|
6
|
-
*/
|
|
7
|
-
type DetectionInput = {
|
|
8
|
-
userAgent?: string;
|
|
9
|
-
ip?: string;
|
|
10
|
-
ipAddress?: string;
|
|
11
|
-
headers?: Record<string, string>;
|
|
12
|
-
url?: string;
|
|
13
|
-
method?: string;
|
|
14
|
-
timestamp?: Date;
|
|
15
|
-
};
|
|
16
|
-
type DetectionResult = {
|
|
17
|
-
isAgent: boolean;
|
|
18
|
-
confidence: number;
|
|
19
|
-
detectedAgent?: {
|
|
20
|
-
type: string;
|
|
21
|
-
name: string;
|
|
22
|
-
};
|
|
23
|
-
reasons: string[];
|
|
24
|
-
verificationMethod?: string;
|
|
25
|
-
forgeabilityRisk?: 'low' | 'medium' | 'high';
|
|
26
|
-
timestamp: Date;
|
|
27
|
-
};
|
|
28
|
-
type EventHandler = (...args: any[]) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Wrapper that provides event emitter functionality
|
|
31
|
-
*/
|
|
32
|
-
declare class EdgeAgentDetectorWrapper {
|
|
33
|
-
private detector;
|
|
34
|
-
private events;
|
|
35
|
-
constructor(_config?: any);
|
|
36
|
-
analyze(input: DetectionInput): Promise<DetectionResult>;
|
|
37
|
-
on(event: string, handler: EventHandler): void;
|
|
38
|
-
emit(event: string, ...args: any[]): void;
|
|
39
|
-
init(): Promise<void>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { EdgeAgentDetectorWrapper };
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wrapper for EdgeAgentDetector to match AgentDetector interface
|
|
3
|
-
* This allows the middleware to work with EdgeAgentDetector in Edge Runtime
|
|
4
|
-
*
|
|
5
|
-
* This is a self-contained implementation to avoid import resolution issues
|
|
6
|
-
*/
|
|
7
|
-
type DetectionInput = {
|
|
8
|
-
userAgent?: string;
|
|
9
|
-
ip?: string;
|
|
10
|
-
ipAddress?: string;
|
|
11
|
-
headers?: Record<string, string>;
|
|
12
|
-
url?: string;
|
|
13
|
-
method?: string;
|
|
14
|
-
timestamp?: Date;
|
|
15
|
-
};
|
|
16
|
-
type DetectionResult = {
|
|
17
|
-
isAgent: boolean;
|
|
18
|
-
confidence: number;
|
|
19
|
-
detectedAgent?: {
|
|
20
|
-
type: string;
|
|
21
|
-
name: string;
|
|
22
|
-
};
|
|
23
|
-
reasons: string[];
|
|
24
|
-
verificationMethod?: string;
|
|
25
|
-
forgeabilityRisk?: 'low' | 'medium' | 'high';
|
|
26
|
-
timestamp: Date;
|
|
27
|
-
};
|
|
28
|
-
type EventHandler = (...args: any[]) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Wrapper that provides event emitter functionality
|
|
31
|
-
*/
|
|
32
|
-
declare class EdgeAgentDetectorWrapper {
|
|
33
|
-
private detector;
|
|
34
|
-
private events;
|
|
35
|
-
constructor(_config?: any);
|
|
36
|
-
analyze(input: DetectionInput): Promise<DetectionResult>;
|
|
37
|
-
on(event: string, handler: EventHandler): void;
|
|
38
|
-
emit(event: string, ...args: any[]): void;
|
|
39
|
-
init(): Promise<void>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { EdgeAgentDetectorWrapper };
|