@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.
Files changed (51) hide show
  1. package/.editorconfig +9 -0
  2. package/.github/CODEOWNERS +1 -0
  3. package/.github/workflows/ci.yml +128 -0
  4. package/.pnpmfile.cjs +17 -0
  5. package/.releaserc.json +21 -0
  6. package/LICENSE.txt +21 -0
  7. package/README.md +3 -0
  8. package/biome.json +67 -0
  9. package/dist/chunk.cjs +34 -0
  10. package/dist/index.cjs +356 -0
  11. package/dist/index.d.cts +2347 -0
  12. package/dist/index.d.mts +2347 -0
  13. package/dist/index.mjs +354 -0
  14. package/dist/schemas/ai-guard.cjs +1000 -0
  15. package/dist/schemas/ai-guard.d.cts +1232 -0
  16. package/dist/schemas/ai-guard.d.mts +1232 -0
  17. package/dist/schemas/ai-guard.mjs +907 -0
  18. package/dist/schemas/index.cjs +7 -0
  19. package/dist/schemas/index.d.cts +64 -0
  20. package/dist/schemas/index.d.mts +64 -0
  21. package/dist/schemas/index.mjs +3 -0
  22. package/dist/schemas.cjs +139 -0
  23. package/dist/schemas.mjs +108 -0
  24. package/flake.lock +59 -0
  25. package/flake.nix +26 -0
  26. package/openapi-ts.config.ts +15 -0
  27. package/package.json +55 -0
  28. package/pnpm-workspace.yaml +3 -0
  29. package/scripts/generate-models +15 -0
  30. package/scripts/test +10 -0
  31. package/specs/ai-guard.openapi.json +3721 -0
  32. package/src/client.ts +441 -0
  33. package/src/core/error.ts +78 -0
  34. package/src/index.ts +2 -0
  35. package/src/internal/builtin-types.ts +18 -0
  36. package/src/internal/errors.ts +34 -0
  37. package/src/internal/headers.ts +100 -0
  38. package/src/internal/parse.ts +30 -0
  39. package/src/internal/request-options.ts +57 -0
  40. package/src/internal/types.ts +3 -0
  41. package/src/internal/utils/sleep.ts +3 -0
  42. package/src/internal/utils/values.ts +38 -0
  43. package/src/schemas/ai-guard.ts +1215 -0
  44. package/src/schemas/index.ts +114 -0
  45. package/src/services/ai-guard.ts +27 -0
  46. package/src/types/ai-guard.ts +2276 -0
  47. package/src/types/index.ts +161 -0
  48. package/tests/ai-guard.test.ts +29 -0
  49. package/tsconfig.json +26 -0
  50. package/tsdown.config.mts +14 -0
  51. 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,3 @@
1
+ export type PromiseOrValue<T> = T | Promise<T>;
2
+ export type HTTPMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
3
+ export type FinalizedRequestInit = RequestInit & { headers: Headers };
@@ -0,0 +1,3 @@
1
+ export function sleep(ms: number): Promise<void> {
2
+ return new Promise<void>((resolve) => setTimeout(resolve, ms));
3
+ }
@@ -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[];