@crowdstrike/aidr 1.0.2
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/.editorconfig +9 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/workflows/ci.yml +128 -0
- package/.pnpmfile.cjs +17 -0
- package/.releaserc.json +21 -0
- package/LICENSE.txt +21 -0
- package/README.md +3 -0
- package/biome.json +67 -0
- package/dist/chunk.cjs +34 -0
- package/dist/index.cjs +356 -0
- package/dist/index.d.cts +2347 -0
- package/dist/index.d.mts +2347 -0
- package/dist/index.mjs +354 -0
- package/dist/schemas/ai-guard.cjs +1000 -0
- package/dist/schemas/ai-guard.d.cts +1232 -0
- package/dist/schemas/ai-guard.d.mts +1232 -0
- package/dist/schemas/ai-guard.mjs +907 -0
- package/dist/schemas/index.cjs +7 -0
- package/dist/schemas/index.d.cts +64 -0
- package/dist/schemas/index.d.mts +64 -0
- package/dist/schemas/index.mjs +3 -0
- package/dist/schemas.cjs +139 -0
- package/dist/schemas.mjs +108 -0
- package/flake.lock +59 -0
- package/flake.nix +26 -0
- package/openapi-ts.config.ts +15 -0
- package/package.json +55 -0
- package/pnpm-workspace.yaml +3 -0
- package/scripts/generate-models +15 -0
- package/scripts/test +10 -0
- package/specs/ai-guard.openapi.json +3721 -0
- package/src/client.ts +441 -0
- package/src/core/error.ts +78 -0
- package/src/index.ts +2 -0
- package/src/internal/builtin-types.ts +18 -0
- package/src/internal/errors.ts +34 -0
- package/src/internal/headers.ts +100 -0
- package/src/internal/parse.ts +30 -0
- package/src/internal/request-options.ts +57 -0
- package/src/internal/types.ts +3 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/values.ts +38 -0
- package/src/schemas/ai-guard.ts +1215 -0
- package/src/schemas/index.ts +114 -0
- package/src/services/ai-guard.ts +27 -0
- package/src/types/ai-guard.ts +2276 -0
- package/src/types/index.ts +161 -0
- package/tests/ai-guard.test.ts +29 -0
- package/tsconfig.json +26 -0
- package/tsdown.config.mts +14 -0
- package/vitest.config.mts +4 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { HeadersLike } from './headers';
|
|
2
|
+
import type { HTTPMethod } from './types';
|
|
3
|
+
|
|
4
|
+
export type RequestOptions = {
|
|
5
|
+
/** Query parameters to include in the request URL. */
|
|
6
|
+
query?: object | undefined | null;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The request body. Can be a string, JSON object, FormData, or other
|
|
10
|
+
* supported types.
|
|
11
|
+
*/
|
|
12
|
+
body?: unknown;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The maximum number of times that the client will retry a request in case of
|
|
16
|
+
* a temporary failure, like a network error or a 5XX error from the server.
|
|
17
|
+
*
|
|
18
|
+
* @default 2
|
|
19
|
+
*/
|
|
20
|
+
maxRetries?: number;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The maximum number of times that the client will poll for an async request
|
|
24
|
+
* result when receiving a HTTP/202 response.
|
|
25
|
+
*
|
|
26
|
+
* @default 5
|
|
27
|
+
*/
|
|
28
|
+
maxPollingAttempts?: number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The maximum amount of time (in milliseconds) that the client should wait
|
|
32
|
+
* for a response from the server before timing out a single request.
|
|
33
|
+
*
|
|
34
|
+
* @unit milliseconds
|
|
35
|
+
*/
|
|
36
|
+
timeout?: number;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Template for constructing the base URL for API requests. The placeholder
|
|
40
|
+
* `{SERVICE_NAME}` will be replaced with the service name slug.
|
|
41
|
+
*/
|
|
42
|
+
baseURLTemplate?: string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* HTTP headers to include with the request. Can be a Headers object, plain
|
|
46
|
+
* object, or array of tuples.
|
|
47
|
+
*/
|
|
48
|
+
headers?: HeadersLike;
|
|
49
|
+
|
|
50
|
+
/** An AbortSignal that can be used to cancel the request. */
|
|
51
|
+
signal?: AbortSignal | undefined | null;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type FinalRequestOptions = RequestOptions & {
|
|
55
|
+
method: HTTPMethod;
|
|
56
|
+
path: string;
|
|
57
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as Errors from '../../core/error';
|
|
2
|
+
|
|
3
|
+
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
4
|
+
|
|
5
|
+
export function isAbsoluteURL(url: string): boolean {
|
|
6
|
+
return startsWithSchemeRegexp.test(url);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function stringifyQuery(query: Record<string, unknown>): string {
|
|
10
|
+
return Object.entries(query)
|
|
11
|
+
.filter(([_, value]) => typeof value !== 'undefined')
|
|
12
|
+
.map(([key, value]) => {
|
|
13
|
+
if (
|
|
14
|
+
typeof value === 'string' ||
|
|
15
|
+
typeof value === 'number' ||
|
|
16
|
+
typeof value === 'boolean'
|
|
17
|
+
) {
|
|
18
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
19
|
+
}
|
|
20
|
+
if (value === null) {
|
|
21
|
+
return `${encodeURIComponent(key)}=`;
|
|
22
|
+
}
|
|
23
|
+
throw new Errors.AIDRError(
|
|
24
|
+
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null.`
|
|
25
|
+
);
|
|
26
|
+
})
|
|
27
|
+
.join('&');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export let isArray = (val: unknown): val is unknown[] =>
|
|
31
|
+
(
|
|
32
|
+
// biome-ignore lint/suspicious/noAssignInExpressions: matches upstream.
|
|
33
|
+
// biome-ignore lint/complexity/noCommaOperator: matches upstream.
|
|
34
|
+
(isArray = Array.isArray), isArray(val)
|
|
35
|
+
);
|
|
36
|
+
export const isReadonlyArray = isArray as (
|
|
37
|
+
val: unknown
|
|
38
|
+
) => val is readonly unknown[];
|