@cdot65/prisma-airs-sdk 0.1.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 +157 -0
- package/dist/index.cjs +812 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2455 -0
- package/dist/index.d.ts +2455 -0
- package/dist/index.js +724 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var HEADER_API_KEY = "x-pan-token";
|
|
3
|
+
var HEADER_AUTH_TOKEN = "Authorization";
|
|
4
|
+
var PAYLOAD_HASH = "x-payload-hash";
|
|
5
|
+
var BEARER = "Bearer ";
|
|
6
|
+
var DEFAULT_ENDPOINT = "https://service.api.aisecurity.paloaltonetworks.com";
|
|
7
|
+
var AI_SEC_API_KEY = "PANW_AI_SEC_API_KEY";
|
|
8
|
+
var AI_SEC_API_TOKEN = "PANW_AI_SEC_API_TOKEN";
|
|
9
|
+
var AI_SEC_API_ENDPOINT = "PANW_AI_SEC_API_ENDPOINT";
|
|
10
|
+
var MAX_CONTENT_PROMPT_LENGTH = 2 * 1024 * 1024;
|
|
11
|
+
var MAX_CONTENT_RESPONSE_LENGTH = 2 * 1024 * 1024;
|
|
12
|
+
var MAX_CONTENT_CONTEXT_LENGTH = 100 * 1024 * 1024;
|
|
13
|
+
var MAX_API_KEY_LENGTH = 2048;
|
|
14
|
+
var MAX_TOKEN_LENGTH = 2048;
|
|
15
|
+
var MAX_TRANSACTION_ID_STR_LENGTH = 100;
|
|
16
|
+
var MAX_SESSION_ID_STR_LENGTH = 100;
|
|
17
|
+
var MAX_SCAN_ID_STR_LENGTH = 36;
|
|
18
|
+
var MAX_REPORT_ID_STR_LENGTH = 40;
|
|
19
|
+
var MAX_AI_PROFILE_NAME_LENGTH = 100;
|
|
20
|
+
var MAX_NUMBER_OF_SCAN_IDS = 5;
|
|
21
|
+
var MAX_NUMBER_OF_REPORT_IDS = 5;
|
|
22
|
+
var MAX_NUMBER_OF_BATCH_SCAN_OBJECTS = 5;
|
|
23
|
+
var MAX_CONNECTION_POOL_SIZE = 100;
|
|
24
|
+
var MAX_NUMBER_OF_RETRIES = 5;
|
|
25
|
+
var HTTP_FORCE_RETRY_STATUS_CODES = [500, 502, 503, 504];
|
|
26
|
+
var SDK_VERSION = "0.1.0";
|
|
27
|
+
var USER_AGENT = `PAN-AIRS/${SDK_VERSION}-typescript-sdk`;
|
|
28
|
+
var SYNC_SCAN_PATH = "/v1/scan/sync/request";
|
|
29
|
+
var ASYNC_SCAN_PATH = "/v1/scan/async/request";
|
|
30
|
+
var SCAN_RESULTS_PATH = "/v1/scan/results";
|
|
31
|
+
var SCAN_REPORTS_PATH = "/v1/scan/reports";
|
|
32
|
+
|
|
33
|
+
// src/errors.ts
|
|
34
|
+
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
35
|
+
ErrorType2["SERVER_SIDE_ERROR"] = "AISEC_SERVER_SIDE_ERROR";
|
|
36
|
+
ErrorType2["CLIENT_SIDE_ERROR"] = "AISEC_CLIENT_SIDE_ERROR";
|
|
37
|
+
ErrorType2["USER_REQUEST_PAYLOAD_ERROR"] = "AISEC_USER_REQUEST_PAYLOAD_ERROR";
|
|
38
|
+
ErrorType2["MISSING_VARIABLE"] = "AISEC_MISSING_VARIABLE";
|
|
39
|
+
ErrorType2["AISEC_SDK_ERROR"] = "AISEC_SDK_ERROR";
|
|
40
|
+
return ErrorType2;
|
|
41
|
+
})(ErrorType || {});
|
|
42
|
+
var AISecSDKException = class _AISecSDKException extends Error {
|
|
43
|
+
errorType;
|
|
44
|
+
constructor(message, errorType) {
|
|
45
|
+
super(errorType ? `${errorType}:${message}` : message);
|
|
46
|
+
this.name = "AISecSDKException";
|
|
47
|
+
this.errorType = errorType;
|
|
48
|
+
if (Error.captureStackTrace) {
|
|
49
|
+
Error.captureStackTrace(this, _AISecSDKException);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/configuration.ts
|
|
55
|
+
var Configuration = class {
|
|
56
|
+
_apiKey;
|
|
57
|
+
_apiToken;
|
|
58
|
+
_apiEndpoint = DEFAULT_ENDPOINT;
|
|
59
|
+
_numRetries = MAX_NUMBER_OF_RETRIES;
|
|
60
|
+
_initialized = false;
|
|
61
|
+
get apiKey() {
|
|
62
|
+
return this._apiKey;
|
|
63
|
+
}
|
|
64
|
+
get apiToken() {
|
|
65
|
+
return this._apiToken;
|
|
66
|
+
}
|
|
67
|
+
get apiEndpoint() {
|
|
68
|
+
return this._apiEndpoint;
|
|
69
|
+
}
|
|
70
|
+
get numRetries() {
|
|
71
|
+
return this._numRetries;
|
|
72
|
+
}
|
|
73
|
+
get initialized() {
|
|
74
|
+
return this._initialized;
|
|
75
|
+
}
|
|
76
|
+
init(opts = {}) {
|
|
77
|
+
const apiKey = (opts.apiKey ?? process.env[AI_SEC_API_KEY] ?? "").trim() || void 0;
|
|
78
|
+
const apiToken = (opts.apiToken ?? process.env[AI_SEC_API_TOKEN] ?? "").trim() || void 0;
|
|
79
|
+
if (!apiKey && !apiToken) {
|
|
80
|
+
throw new AISecSDKException(
|
|
81
|
+
"Either apiKey or apiToken must be provided (or set via environment variables)",
|
|
82
|
+
"AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (apiKey && apiKey.length > MAX_API_KEY_LENGTH) {
|
|
86
|
+
throw new AISecSDKException(
|
|
87
|
+
`apiKey exceeds max length of ${MAX_API_KEY_LENGTH}`,
|
|
88
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
if (apiToken && apiToken.length > MAX_TOKEN_LENGTH) {
|
|
92
|
+
throw new AISecSDKException(
|
|
93
|
+
`apiToken exceeds max length of ${MAX_TOKEN_LENGTH}`,
|
|
94
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
this._apiKey = apiKey;
|
|
98
|
+
this._apiToken = apiToken;
|
|
99
|
+
const endpoint = opts.apiEndpoint ?? process.env[AI_SEC_API_ENDPOINT] ?? DEFAULT_ENDPOINT;
|
|
100
|
+
this._apiEndpoint = endpoint.replace(/\/+$/, "");
|
|
101
|
+
if (opts.numRetries !== void 0) {
|
|
102
|
+
if (opts.numRetries < 0 || opts.numRetries > MAX_NUMBER_OF_RETRIES) {
|
|
103
|
+
throw new AISecSDKException(
|
|
104
|
+
`numRetries must be between 0 and ${MAX_NUMBER_OF_RETRIES}`,
|
|
105
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
this._numRetries = opts.numRetries;
|
|
109
|
+
}
|
|
110
|
+
this._initialized = true;
|
|
111
|
+
}
|
|
112
|
+
reset() {
|
|
113
|
+
this._apiKey = void 0;
|
|
114
|
+
this._apiToken = void 0;
|
|
115
|
+
this._apiEndpoint = DEFAULT_ENDPOINT;
|
|
116
|
+
this._numRetries = MAX_NUMBER_OF_RETRIES;
|
|
117
|
+
this._initialized = false;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var globalConfiguration = new Configuration();
|
|
121
|
+
function init(opts = {}) {
|
|
122
|
+
globalConfiguration.init(opts);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/utils.ts
|
|
126
|
+
import { createHmac } from "crypto";
|
|
127
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
128
|
+
function isValidUuid(value) {
|
|
129
|
+
return UUID_RE.test(value);
|
|
130
|
+
}
|
|
131
|
+
function generatePayloadHash(payload, secret) {
|
|
132
|
+
return createHmac("sha256", secret).update(payload).digest("hex");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/http-client.ts
|
|
136
|
+
function buildHeaders() {
|
|
137
|
+
const headers = {
|
|
138
|
+
"Content-Type": "application/json",
|
|
139
|
+
"User-Agent": USER_AGENT
|
|
140
|
+
};
|
|
141
|
+
const cfg = globalConfiguration;
|
|
142
|
+
if (cfg.apiToken) {
|
|
143
|
+
headers[HEADER_AUTH_TOKEN] = `${BEARER}${cfg.apiToken}`;
|
|
144
|
+
}
|
|
145
|
+
if (cfg.apiKey) {
|
|
146
|
+
headers[HEADER_API_KEY] = cfg.apiKey;
|
|
147
|
+
}
|
|
148
|
+
return headers;
|
|
149
|
+
}
|
|
150
|
+
function sleep(ms) {
|
|
151
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
152
|
+
}
|
|
153
|
+
async function httpRequest(opts) {
|
|
154
|
+
if (!globalConfiguration.initialized) {
|
|
155
|
+
throw new AISecSDKException(
|
|
156
|
+
"SDK not initialized. Call init() before making requests.",
|
|
157
|
+
"AISEC_MISSING_VARIABLE" /* MISSING_VARIABLE */
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
const baseUrl = globalConfiguration.apiEndpoint;
|
|
161
|
+
const url = new URL(opts.path, baseUrl);
|
|
162
|
+
if (opts.params) {
|
|
163
|
+
for (const [key, value] of Object.entries(opts.params)) {
|
|
164
|
+
url.searchParams.set(key, value);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const headers = buildHeaders();
|
|
168
|
+
let bodyStr;
|
|
169
|
+
if (opts.body !== void 0) {
|
|
170
|
+
bodyStr = JSON.stringify(opts.body);
|
|
171
|
+
if (globalConfiguration.apiKey) {
|
|
172
|
+
headers[PAYLOAD_HASH] = generatePayloadHash(bodyStr, globalConfiguration.apiKey);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const maxRetries = globalConfiguration.numRetries;
|
|
176
|
+
let lastError;
|
|
177
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
178
|
+
try {
|
|
179
|
+
const response = await fetch(url.toString(), {
|
|
180
|
+
method: opts.method,
|
|
181
|
+
headers,
|
|
182
|
+
body: bodyStr
|
|
183
|
+
});
|
|
184
|
+
if (response.ok) {
|
|
185
|
+
const data = await response.json();
|
|
186
|
+
return { status: response.status, data };
|
|
187
|
+
}
|
|
188
|
+
if (HTTP_FORCE_RETRY_STATUS_CODES.includes(response.status) && attempt < maxRetries) {
|
|
189
|
+
await sleep(Math.pow(2, attempt) * 1e3);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
let errorMessage;
|
|
193
|
+
try {
|
|
194
|
+
const errorBody = await response.json();
|
|
195
|
+
errorMessage = errorBody.message ?? errorBody.error?.message ?? `API error ${response.status}`;
|
|
196
|
+
} catch {
|
|
197
|
+
errorMessage = `API error ${response.status}`;
|
|
198
|
+
}
|
|
199
|
+
const errorType = response.status >= 500 ? "AISEC_SERVER_SIDE_ERROR" /* SERVER_SIDE_ERROR */ : "AISEC_CLIENT_SIDE_ERROR" /* CLIENT_SIDE_ERROR */;
|
|
200
|
+
throw new AISecSDKException(errorMessage, errorType);
|
|
201
|
+
} catch (err) {
|
|
202
|
+
if (err instanceof AISecSDKException) {
|
|
203
|
+
throw err;
|
|
204
|
+
}
|
|
205
|
+
lastError = err;
|
|
206
|
+
if (attempt < maxRetries) {
|
|
207
|
+
await sleep(Math.pow(2, attempt) * 1e3);
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
throw new AISecSDKException(lastError?.message ?? "Network error", "AISEC_CLIENT_SIDE_ERROR" /* CLIENT_SIDE_ERROR */);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/scan/scanner.ts
|
|
216
|
+
var Scanner = class {
|
|
217
|
+
async syncScan(aiProfile, content, opts = {}) {
|
|
218
|
+
if (opts.trId && opts.trId.length > MAX_TRANSACTION_ID_STR_LENGTH) {
|
|
219
|
+
throw new AISecSDKException(
|
|
220
|
+
`trId exceeds max length of ${MAX_TRANSACTION_ID_STR_LENGTH}`,
|
|
221
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
if (opts.sessionId && opts.sessionId.length > MAX_SESSION_ID_STR_LENGTH) {
|
|
225
|
+
throw new AISecSDKException(
|
|
226
|
+
`sessionId exceeds max length of ${MAX_SESSION_ID_STR_LENGTH}`,
|
|
227
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const body = {
|
|
231
|
+
ai_profile: aiProfile,
|
|
232
|
+
contents: [content.toJSON()]
|
|
233
|
+
};
|
|
234
|
+
if (opts.trId) body.tr_id = opts.trId;
|
|
235
|
+
if (opts.sessionId) body.session_id = opts.sessionId;
|
|
236
|
+
if (opts.metadata) body.metadata = opts.metadata;
|
|
237
|
+
const res = await httpRequest({
|
|
238
|
+
method: "POST",
|
|
239
|
+
path: SYNC_SCAN_PATH,
|
|
240
|
+
body
|
|
241
|
+
});
|
|
242
|
+
return res.data;
|
|
243
|
+
}
|
|
244
|
+
async asyncScan(scanObjects) {
|
|
245
|
+
if (scanObjects.length < 1) {
|
|
246
|
+
throw new AISecSDKException(
|
|
247
|
+
"At least 1 scan object is required",
|
|
248
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
if (scanObjects.length > MAX_NUMBER_OF_BATCH_SCAN_OBJECTS) {
|
|
252
|
+
throw new AISecSDKException(
|
|
253
|
+
`Max of ${MAX_NUMBER_OF_BATCH_SCAN_OBJECTS} scan objects allowed`,
|
|
254
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
const res = await httpRequest({
|
|
258
|
+
method: "POST",
|
|
259
|
+
path: ASYNC_SCAN_PATH,
|
|
260
|
+
body: scanObjects
|
|
261
|
+
});
|
|
262
|
+
return res.data;
|
|
263
|
+
}
|
|
264
|
+
async queryByScanIds(scanIds) {
|
|
265
|
+
if (scanIds.length < 1) {
|
|
266
|
+
throw new AISecSDKException(
|
|
267
|
+
"At least 1 scan_id is required",
|
|
268
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
if (scanIds.length > MAX_NUMBER_OF_SCAN_IDS) {
|
|
272
|
+
throw new AISecSDKException(
|
|
273
|
+
`Max of ${MAX_NUMBER_OF_SCAN_IDS} scan_ids allowed`,
|
|
274
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
for (const id of scanIds) {
|
|
278
|
+
if (!isValidUuid(id)) {
|
|
279
|
+
throw new AISecSDKException(`Invalid scan_id: ${id}`, "AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const res = await httpRequest({
|
|
283
|
+
method: "GET",
|
|
284
|
+
path: SCAN_RESULTS_PATH,
|
|
285
|
+
params: { scan_ids: scanIds.join(",") }
|
|
286
|
+
});
|
|
287
|
+
return res.data;
|
|
288
|
+
}
|
|
289
|
+
async queryByReportIds(reportIds) {
|
|
290
|
+
if (reportIds.length < 1) {
|
|
291
|
+
throw new AISecSDKException(
|
|
292
|
+
"At least 1 report_id is required",
|
|
293
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
if (reportIds.length > MAX_NUMBER_OF_REPORT_IDS) {
|
|
297
|
+
throw new AISecSDKException(
|
|
298
|
+
`Max of ${MAX_NUMBER_OF_REPORT_IDS} report_ids allowed`,
|
|
299
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
const res = await httpRequest({
|
|
303
|
+
method: "GET",
|
|
304
|
+
path: SCAN_REPORTS_PATH,
|
|
305
|
+
params: { report_ids: reportIds.join(",") }
|
|
306
|
+
});
|
|
307
|
+
return res.data;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// src/scan/content.ts
|
|
312
|
+
import { readFileSync } from "fs";
|
|
313
|
+
var Content = class _Content {
|
|
314
|
+
_prompt;
|
|
315
|
+
_response;
|
|
316
|
+
_context;
|
|
317
|
+
_codePrompt;
|
|
318
|
+
_codeResponse;
|
|
319
|
+
_toolEvent;
|
|
320
|
+
constructor(opts) {
|
|
321
|
+
if (!opts.prompt && !opts.response && !opts.codePrompt && !opts.codeResponse && !opts.toolEvent) {
|
|
322
|
+
throw new AISecSDKException(
|
|
323
|
+
"At least one of prompt, response, codePrompt, codeResponse, or toolEvent must be provided",
|
|
324
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
if (opts.prompt !== void 0) this.prompt = opts.prompt;
|
|
328
|
+
if (opts.response !== void 0) this.response = opts.response;
|
|
329
|
+
if (opts.context !== void 0) this.context = opts.context;
|
|
330
|
+
if (opts.codePrompt !== void 0) this.codePrompt = opts.codePrompt;
|
|
331
|
+
if (opts.codeResponse !== void 0) this.codeResponse = opts.codeResponse;
|
|
332
|
+
if (opts.toolEvent !== void 0) this._toolEvent = opts.toolEvent;
|
|
333
|
+
}
|
|
334
|
+
get prompt() {
|
|
335
|
+
return this._prompt;
|
|
336
|
+
}
|
|
337
|
+
set prompt(value) {
|
|
338
|
+
if (value !== void 0 && Buffer.byteLength(value) > MAX_CONTENT_PROMPT_LENGTH) {
|
|
339
|
+
throw new AISecSDKException(
|
|
340
|
+
`prompt exceeds max length of ${MAX_CONTENT_PROMPT_LENGTH} bytes`,
|
|
341
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
this._prompt = value;
|
|
345
|
+
}
|
|
346
|
+
get response() {
|
|
347
|
+
return this._response;
|
|
348
|
+
}
|
|
349
|
+
set response(value) {
|
|
350
|
+
if (value !== void 0 && Buffer.byteLength(value) > MAX_CONTENT_RESPONSE_LENGTH) {
|
|
351
|
+
throw new AISecSDKException(
|
|
352
|
+
`response exceeds max length of ${MAX_CONTENT_RESPONSE_LENGTH} bytes`,
|
|
353
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
this._response = value;
|
|
357
|
+
}
|
|
358
|
+
get context() {
|
|
359
|
+
return this._context;
|
|
360
|
+
}
|
|
361
|
+
set context(value) {
|
|
362
|
+
if (value !== void 0 && Buffer.byteLength(value) > MAX_CONTENT_CONTEXT_LENGTH) {
|
|
363
|
+
throw new AISecSDKException(
|
|
364
|
+
`context exceeds max length of ${MAX_CONTENT_CONTEXT_LENGTH} bytes`,
|
|
365
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
this._context = value;
|
|
369
|
+
}
|
|
370
|
+
get codePrompt() {
|
|
371
|
+
return this._codePrompt;
|
|
372
|
+
}
|
|
373
|
+
set codePrompt(value) {
|
|
374
|
+
if (value !== void 0 && Buffer.byteLength(value) > MAX_CONTENT_PROMPT_LENGTH) {
|
|
375
|
+
throw new AISecSDKException(
|
|
376
|
+
`codePrompt exceeds max length of ${MAX_CONTENT_PROMPT_LENGTH} bytes`,
|
|
377
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
this._codePrompt = value;
|
|
381
|
+
}
|
|
382
|
+
get codeResponse() {
|
|
383
|
+
return this._codeResponse;
|
|
384
|
+
}
|
|
385
|
+
set codeResponse(value) {
|
|
386
|
+
if (value !== void 0 && Buffer.byteLength(value) > MAX_CONTENT_RESPONSE_LENGTH) {
|
|
387
|
+
throw new AISecSDKException(
|
|
388
|
+
`codeResponse exceeds max length of ${MAX_CONTENT_RESPONSE_LENGTH} bytes`,
|
|
389
|
+
"AISEC_USER_REQUEST_PAYLOAD_ERROR" /* USER_REQUEST_PAYLOAD_ERROR */
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
this._codeResponse = value;
|
|
393
|
+
}
|
|
394
|
+
get toolEvent() {
|
|
395
|
+
return this._toolEvent;
|
|
396
|
+
}
|
|
397
|
+
set toolEvent(value) {
|
|
398
|
+
this._toolEvent = value;
|
|
399
|
+
}
|
|
400
|
+
get length() {
|
|
401
|
+
let total = 0;
|
|
402
|
+
if (this._prompt) total += Buffer.byteLength(this._prompt);
|
|
403
|
+
if (this._response) total += Buffer.byteLength(this._response);
|
|
404
|
+
if (this._context) total += Buffer.byteLength(this._context);
|
|
405
|
+
if (this._codePrompt) total += Buffer.byteLength(this._codePrompt);
|
|
406
|
+
if (this._codeResponse) total += Buffer.byteLength(this._codeResponse);
|
|
407
|
+
return total;
|
|
408
|
+
}
|
|
409
|
+
toJSON() {
|
|
410
|
+
const obj = {};
|
|
411
|
+
if (this._prompt !== void 0) obj.prompt = this._prompt;
|
|
412
|
+
if (this._response !== void 0) obj.response = this._response;
|
|
413
|
+
if (this._context !== void 0) obj.context = this._context;
|
|
414
|
+
if (this._codePrompt !== void 0) obj.code_prompt = this._codePrompt;
|
|
415
|
+
if (this._codeResponse !== void 0) obj.code_response = this._codeResponse;
|
|
416
|
+
if (this._toolEvent !== void 0) obj.tool_event = this._toolEvent;
|
|
417
|
+
return obj;
|
|
418
|
+
}
|
|
419
|
+
static fromJSON(json) {
|
|
420
|
+
return new _Content({
|
|
421
|
+
prompt: json.prompt,
|
|
422
|
+
response: json.response,
|
|
423
|
+
context: json.context,
|
|
424
|
+
codePrompt: json.code_prompt,
|
|
425
|
+
codeResponse: json.code_response,
|
|
426
|
+
toolEvent: json.tool_event
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
static fromJSONFile(filePath) {
|
|
430
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
431
|
+
const parsed = JSON.parse(raw);
|
|
432
|
+
return _Content.fromJSON(parsed);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
// src/models/ai-profile.ts
|
|
437
|
+
import { z } from "zod";
|
|
438
|
+
var AiProfileSchema = z.object({
|
|
439
|
+
profile_id: z.string().uuid().optional(),
|
|
440
|
+
profile_name: z.string().max(MAX_AI_PROFILE_NAME_LENGTH).optional()
|
|
441
|
+
}).refine((d) => d.profile_id || d.profile_name, {
|
|
442
|
+
message: "Either profile_id or profile_name must be provided"
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// src/models/metadata.ts
|
|
446
|
+
import { z as z2 } from "zod";
|
|
447
|
+
var AgentMetaSchema = z2.object({
|
|
448
|
+
agent_id: z2.string().optional(),
|
|
449
|
+
agent_version: z2.string().optional(),
|
|
450
|
+
agent_arn: z2.string().optional()
|
|
451
|
+
});
|
|
452
|
+
var MetadataSchema = z2.object({
|
|
453
|
+
app_name: z2.string().optional(),
|
|
454
|
+
app_user: z2.string().optional(),
|
|
455
|
+
ai_model: z2.string().optional(),
|
|
456
|
+
user_ip: z2.string().optional(),
|
|
457
|
+
agent_meta: AgentMetaSchema.optional()
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// src/models/tool-event.ts
|
|
461
|
+
import { z as z3 } from "zod";
|
|
462
|
+
var ToolEventMetadataSchema = z3.object({
|
|
463
|
+
ecosystem: z3.string(),
|
|
464
|
+
method: z3.string(),
|
|
465
|
+
server_name: z3.string(),
|
|
466
|
+
tool_invoked: z3.string().optional()
|
|
467
|
+
});
|
|
468
|
+
var ToolEventSchema = z3.object({
|
|
469
|
+
metadata: ToolEventMetadataSchema.optional(),
|
|
470
|
+
input: z3.string().optional(),
|
|
471
|
+
output: z3.string().optional()
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// src/models/scan-request.ts
|
|
475
|
+
import { z as z4 } from "zod";
|
|
476
|
+
var ScanRequestContentsInnerSchema = z4.object({
|
|
477
|
+
prompt: z4.string().optional(),
|
|
478
|
+
response: z4.string().optional(),
|
|
479
|
+
code_prompt: z4.string().optional(),
|
|
480
|
+
code_response: z4.string().optional(),
|
|
481
|
+
context: z4.string().optional(),
|
|
482
|
+
tool_event: ToolEventSchema.optional()
|
|
483
|
+
});
|
|
484
|
+
var ScanRequestSchema = z4.object({
|
|
485
|
+
tr_id: z4.string().max(MAX_TRANSACTION_ID_STR_LENGTH).optional(),
|
|
486
|
+
session_id: z4.string().max(MAX_SESSION_ID_STR_LENGTH).optional(),
|
|
487
|
+
ai_profile: AiProfileSchema,
|
|
488
|
+
metadata: MetadataSchema.optional(),
|
|
489
|
+
contents: z4.array(ScanRequestContentsInnerSchema).min(1)
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
// src/models/scan-response.ts
|
|
493
|
+
import { z as z7 } from "zod";
|
|
494
|
+
|
|
495
|
+
// src/models/prompt-detected.ts
|
|
496
|
+
import { z as z5 } from "zod";
|
|
497
|
+
var PromptDetectionDetailsSchema = z5.object({
|
|
498
|
+
topic_guardrails_details: z5.record(z5.unknown()).optional()
|
|
499
|
+
});
|
|
500
|
+
var PromptDetectedSchema = z5.object({
|
|
501
|
+
url_cats: z5.boolean().optional(),
|
|
502
|
+
dlp: z5.boolean().optional(),
|
|
503
|
+
injection: z5.boolean().optional(),
|
|
504
|
+
toxic_content: z5.boolean().optional(),
|
|
505
|
+
malicious_code: z5.boolean().optional(),
|
|
506
|
+
agent: z5.boolean().optional(),
|
|
507
|
+
topic_violation: z5.boolean().optional()
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
// src/models/response-detected.ts
|
|
511
|
+
import { z as z6 } from "zod";
|
|
512
|
+
var ResponseDetectionDetailsSchema = z6.object({
|
|
513
|
+
topic_guardrails_details: z6.record(z6.unknown()).optional()
|
|
514
|
+
});
|
|
515
|
+
var ResponseDetectedSchema = z6.object({
|
|
516
|
+
url_cats: z6.boolean().optional(),
|
|
517
|
+
dlp: z6.boolean().optional(),
|
|
518
|
+
db_security: z6.boolean().optional(),
|
|
519
|
+
toxic_content: z6.boolean().optional(),
|
|
520
|
+
malicious_code: z6.boolean().optional(),
|
|
521
|
+
agent: z6.boolean().optional(),
|
|
522
|
+
ungrounded: z6.boolean().optional(),
|
|
523
|
+
topic_violation: z6.boolean().optional()
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
// src/models/scan-response.ts
|
|
527
|
+
var MaskedDataSchema = z7.object({
|
|
528
|
+
data: z7.string().optional(),
|
|
529
|
+
pattern_detections: z7.array(z7.record(z7.unknown())).optional()
|
|
530
|
+
});
|
|
531
|
+
var IODetectedSchema = z7.object({
|
|
532
|
+
url_cats: z7.boolean().optional(),
|
|
533
|
+
dlp: z7.boolean().optional(),
|
|
534
|
+
injection: z7.boolean().optional(),
|
|
535
|
+
toxic_content: z7.boolean().optional(),
|
|
536
|
+
malicious_code: z7.boolean().optional()
|
|
537
|
+
}).passthrough();
|
|
538
|
+
var ScanSummarySchema = z7.object({
|
|
539
|
+
verdict: z7.string().optional(),
|
|
540
|
+
action: z7.string().optional()
|
|
541
|
+
}).passthrough();
|
|
542
|
+
var ToolDetectedSchema = z7.object({
|
|
543
|
+
verdict: z7.string().optional(),
|
|
544
|
+
metadata: ToolEventMetadataSchema.optional(),
|
|
545
|
+
summary: ScanSummarySchema.optional(),
|
|
546
|
+
input_detected: IODetectedSchema.optional(),
|
|
547
|
+
output_detected: IODetectedSchema.optional()
|
|
548
|
+
});
|
|
549
|
+
var ScanResponseSchema = z7.object({
|
|
550
|
+
source: z7.string().optional(),
|
|
551
|
+
report_id: z7.string(),
|
|
552
|
+
scan_id: z7.string(),
|
|
553
|
+
tr_id: z7.string().optional(),
|
|
554
|
+
session_id: z7.string().optional(),
|
|
555
|
+
profile_id: z7.string().optional(),
|
|
556
|
+
profile_name: z7.string().optional(),
|
|
557
|
+
category: z7.string(),
|
|
558
|
+
action: z7.string(),
|
|
559
|
+
prompt_detected: PromptDetectedSchema.optional(),
|
|
560
|
+
response_detected: ResponseDetectedSchema.optional(),
|
|
561
|
+
prompt_masked_data: MaskedDataSchema.optional(),
|
|
562
|
+
response_masked_data: MaskedDataSchema.optional(),
|
|
563
|
+
prompt_detection_details: PromptDetectionDetailsSchema.optional(),
|
|
564
|
+
response_detection_details: ResponseDetectionDetailsSchema.optional(),
|
|
565
|
+
tool_detected: ToolDetectedSchema.optional(),
|
|
566
|
+
created_at: z7.string().optional(),
|
|
567
|
+
completed_at: z7.string().optional()
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
// src/models/async-scan.ts
|
|
571
|
+
import { z as z8 } from "zod";
|
|
572
|
+
var AsyncScanObjectSchema = z8.object({
|
|
573
|
+
req_id: z8.number().int(),
|
|
574
|
+
scan_req: ScanRequestSchema
|
|
575
|
+
});
|
|
576
|
+
var AsyncScanResponseSchema = z8.object({
|
|
577
|
+
received: z8.string(),
|
|
578
|
+
scan_id: z8.string(),
|
|
579
|
+
report_id: z8.string().optional(),
|
|
580
|
+
source: z8.string().optional()
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
// src/models/scan-id-result.ts
|
|
584
|
+
import { z as z9 } from "zod";
|
|
585
|
+
var ScanIdResultSchema = z9.object({
|
|
586
|
+
source: z9.string().optional(),
|
|
587
|
+
req_id: z9.number().optional(),
|
|
588
|
+
status: z9.string().optional(),
|
|
589
|
+
scan_id: z9.string().optional(),
|
|
590
|
+
result: ScanResponseSchema.optional()
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
// src/models/threat-report.ts
|
|
594
|
+
import { z as z13 } from "zod";
|
|
595
|
+
|
|
596
|
+
// src/models/detection.ts
|
|
597
|
+
import { z as z12 } from "zod";
|
|
598
|
+
|
|
599
|
+
// src/models/dlp-report.ts
|
|
600
|
+
import { z as z10 } from "zod";
|
|
601
|
+
var DlpReportSchema = z10.object({
|
|
602
|
+
dlp_report_id: z10.string().optional(),
|
|
603
|
+
dlp_profile_name: z10.string().optional(),
|
|
604
|
+
dlp_profile_id: z10.string().optional(),
|
|
605
|
+
dlp_profile_version: z10.number().optional(),
|
|
606
|
+
data_pattern_rule1_verdict: z10.string().optional(),
|
|
607
|
+
data_pattern_rule2_verdict: z10.string().optional()
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
// src/models/urlf-report.ts
|
|
611
|
+
import { z as z11 } from "zod";
|
|
612
|
+
var UrlfEntrySchema = z11.object({
|
|
613
|
+
url: z11.string().optional(),
|
|
614
|
+
risk_level: z11.string().optional(),
|
|
615
|
+
categories: z11.array(z11.string()).optional()
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
// src/models/detection.ts
|
|
619
|
+
var DSDetailResultSchema = z12.object({
|
|
620
|
+
urlf_report: z12.array(UrlfEntrySchema).optional(),
|
|
621
|
+
dlp_report: DlpReportSchema.optional()
|
|
622
|
+
});
|
|
623
|
+
var DSResultMetadataSchema = z12.object({
|
|
624
|
+
score: z12.number().optional(),
|
|
625
|
+
confidence: z12.string().optional()
|
|
626
|
+
}).passthrough();
|
|
627
|
+
var DetectionServiceResultSchema = z12.object({
|
|
628
|
+
data_type: z12.string().optional(),
|
|
629
|
+
detection_service: z12.string().optional(),
|
|
630
|
+
verdict: z12.string().optional(),
|
|
631
|
+
action: z12.string().optional(),
|
|
632
|
+
metadata: DSResultMetadataSchema.optional(),
|
|
633
|
+
result_detail: DSDetailResultSchema.optional()
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
// src/models/threat-report.ts
|
|
637
|
+
var ThreatScanReportSchema = z13.object({
|
|
638
|
+
source: z13.string().optional(),
|
|
639
|
+
report_id: z13.string().optional(),
|
|
640
|
+
scan_id: z13.string().optional(),
|
|
641
|
+
req_id: z13.number().optional(),
|
|
642
|
+
transaction_id: z13.string().optional(),
|
|
643
|
+
session_id: z13.string().optional(),
|
|
644
|
+
detection_results: z13.array(DetectionServiceResultSchema).optional()
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
// src/models/error-response.ts
|
|
648
|
+
import { z as z14 } from "zod";
|
|
649
|
+
var ErrorResponseSchema = z14.object({
|
|
650
|
+
status_code: z14.number().optional(),
|
|
651
|
+
message: z14.string().optional(),
|
|
652
|
+
error: z14.object({
|
|
653
|
+
message: z14.string().optional()
|
|
654
|
+
}).passthrough().optional(),
|
|
655
|
+
retry_after: z14.object({
|
|
656
|
+
interval: z14.number().optional(),
|
|
657
|
+
unit: z14.string().optional()
|
|
658
|
+
}).optional()
|
|
659
|
+
});
|
|
660
|
+
export {
|
|
661
|
+
AISecSDKException,
|
|
662
|
+
AI_SEC_API_ENDPOINT,
|
|
663
|
+
AI_SEC_API_KEY,
|
|
664
|
+
AI_SEC_API_TOKEN,
|
|
665
|
+
ASYNC_SCAN_PATH,
|
|
666
|
+
AgentMetaSchema,
|
|
667
|
+
AiProfileSchema,
|
|
668
|
+
AsyncScanObjectSchema,
|
|
669
|
+
AsyncScanResponseSchema,
|
|
670
|
+
BEARER,
|
|
671
|
+
Content,
|
|
672
|
+
DEFAULT_ENDPOINT,
|
|
673
|
+
DSDetailResultSchema,
|
|
674
|
+
DSResultMetadataSchema,
|
|
675
|
+
DetectionServiceResultSchema,
|
|
676
|
+
DlpReportSchema,
|
|
677
|
+
ErrorResponseSchema,
|
|
678
|
+
ErrorType,
|
|
679
|
+
HEADER_API_KEY,
|
|
680
|
+
HEADER_AUTH_TOKEN,
|
|
681
|
+
HTTP_FORCE_RETRY_STATUS_CODES,
|
|
682
|
+
IODetectedSchema,
|
|
683
|
+
MAX_AI_PROFILE_NAME_LENGTH,
|
|
684
|
+
MAX_API_KEY_LENGTH,
|
|
685
|
+
MAX_CONNECTION_POOL_SIZE,
|
|
686
|
+
MAX_CONTENT_CONTEXT_LENGTH,
|
|
687
|
+
MAX_CONTENT_PROMPT_LENGTH,
|
|
688
|
+
MAX_CONTENT_RESPONSE_LENGTH,
|
|
689
|
+
MAX_NUMBER_OF_BATCH_SCAN_OBJECTS,
|
|
690
|
+
MAX_NUMBER_OF_REPORT_IDS,
|
|
691
|
+
MAX_NUMBER_OF_RETRIES,
|
|
692
|
+
MAX_NUMBER_OF_SCAN_IDS,
|
|
693
|
+
MAX_REPORT_ID_STR_LENGTH,
|
|
694
|
+
MAX_SCAN_ID_STR_LENGTH,
|
|
695
|
+
MAX_SESSION_ID_STR_LENGTH,
|
|
696
|
+
MAX_TOKEN_LENGTH,
|
|
697
|
+
MAX_TRANSACTION_ID_STR_LENGTH,
|
|
698
|
+
MaskedDataSchema,
|
|
699
|
+
MetadataSchema,
|
|
700
|
+
PAYLOAD_HASH,
|
|
701
|
+
PromptDetectedSchema,
|
|
702
|
+
PromptDetectionDetailsSchema,
|
|
703
|
+
ResponseDetectedSchema,
|
|
704
|
+
ResponseDetectionDetailsSchema,
|
|
705
|
+
SCAN_REPORTS_PATH,
|
|
706
|
+
SCAN_RESULTS_PATH,
|
|
707
|
+
SDK_VERSION,
|
|
708
|
+
SYNC_SCAN_PATH,
|
|
709
|
+
ScanIdResultSchema,
|
|
710
|
+
ScanRequestContentsInnerSchema,
|
|
711
|
+
ScanRequestSchema,
|
|
712
|
+
ScanResponseSchema,
|
|
713
|
+
ScanSummarySchema,
|
|
714
|
+
Scanner,
|
|
715
|
+
ThreatScanReportSchema,
|
|
716
|
+
ToolDetectedSchema,
|
|
717
|
+
ToolEventMetadataSchema,
|
|
718
|
+
ToolEventSchema,
|
|
719
|
+
USER_AGENT,
|
|
720
|
+
UrlfEntrySchema,
|
|
721
|
+
globalConfiguration,
|
|
722
|
+
init
|
|
723
|
+
};
|
|
724
|
+
//# sourceMappingURL=index.js.map
|