@groundcover/api-client 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/LICENSE +201 -0
- package/README.md +176 -0
- package/dist/_generated/client/client.gen.d.ts +2 -0
- package/dist/_generated/client/client.gen.js +216 -0
- package/dist/_generated/client/index.d.ts +10 -0
- package/dist/_generated/client/index.js +6 -0
- package/dist/_generated/client/types.gen.d.ts +120 -0
- package/dist/_generated/client/types.gen.js +2 -0
- package/dist/_generated/client/utils.gen.d.ts +37 -0
- package/dist/_generated/client/utils.gen.js +228 -0
- package/dist/_generated/client.gen.d.ts +12 -0
- package/dist/_generated/client.gen.js +3 -0
- package/dist/_generated/core/auth.gen.d.ts +25 -0
- package/dist/_generated/core/auth.gen.js +14 -0
- package/dist/_generated/core/bodySerializer.gen.d.ts +25 -0
- package/dist/_generated/core/bodySerializer.gen.js +57 -0
- package/dist/_generated/core/params.gen.d.ts +43 -0
- package/dist/_generated/core/params.gen.js +109 -0
- package/dist/_generated/core/pathSerializer.gen.d.ts +33 -0
- package/dist/_generated/core/pathSerializer.gen.js +106 -0
- package/dist/_generated/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/_generated/core/queryKeySerializer.gen.js +92 -0
- package/dist/_generated/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/_generated/core/serverSentEvents.gen.js +132 -0
- package/dist/_generated/core/types.gen.d.ts +83 -0
- package/dist/_generated/core/types.gen.js +2 -0
- package/dist/_generated/core/utils.gen.d.ts +19 -0
- package/dist/_generated/core/utils.gen.js +87 -0
- package/dist/_generated/index.d.ts +2 -0
- package/dist/_generated/index.js +2 -0
- package/dist/_generated/sdk.gen.d.ts +471 -0
- package/dist/_generated/sdk.gen.js +1138 -0
- package/dist/_generated/types.gen.d.ts +11655 -0
- package/dist/_generated/types.gen.js +2 -0
- package/dist/client.d.ts +52 -0
- package/dist/client.js +189 -0
- package/dist/helpers.d.ts +15 -0
- package/dist/helpers.js +24 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/types/conditions.d.ts +25 -0
- package/dist/types/conditions.js +30 -0
- package/dist/types/matchers.d.ts +7 -0
- package/dist/types/matchers.js +8 -0
- package/dist/utils/ConditionSet.d.ts +47 -0
- package/dist/utils/ConditionSet.js +95 -0
- package/package.json +44 -0
- package/src/_generated/client/client.gen.ts +277 -0
- package/src/_generated/client/index.ts +27 -0
- package/src/_generated/client/types.gen.ts +218 -0
- package/src/_generated/client/utils.gen.ts +316 -0
- package/src/_generated/client.gen.ts +16 -0
- package/src/_generated/core/auth.gen.ts +48 -0
- package/src/_generated/core/bodySerializer.gen.ts +82 -0
- package/src/_generated/core/params.gen.ts +178 -0
- package/src/_generated/core/pathSerializer.gen.ts +171 -0
- package/src/_generated/core/queryKeySerializer.gen.ts +117 -0
- package/src/_generated/core/serverSentEvents.gen.ts +242 -0
- package/src/_generated/core/types.gen.ts +110 -0
- package/src/_generated/core/utils.gen.ts +140 -0
- package/src/_generated/index.ts +4 -0
- package/src/_generated/sdk.gen.ts +1267 -0
- package/src/_generated/types.gen.ts +12816 -0
- package/src/client.ts +273 -0
- package/src/helpers.ts +38 -0
- package/src/index.ts +7 -0
- package/src/types/conditions.ts +35 -0
- package/src/types/matchers.ts +8 -0
- package/src/utils/ConditionSet.ts +135 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface GroundcoverConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The API Key for the groundcover backend.
|
|
4
|
+
* If not provided, it will fallback to the GC_API_KEY environment variable.
|
|
5
|
+
*/
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
/**
|
|
8
|
+
* The Backend ID (tenant ID) for your environment.
|
|
9
|
+
* If not provided, it will fallback to the GC_BACKEND_ID environment variable.
|
|
10
|
+
*/
|
|
11
|
+
backendId?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The Base URL of the groundcover API.
|
|
14
|
+
* Defaults to 'https://api.groundcover.com' or the GC_BASE_URL environment variable.
|
|
15
|
+
*/
|
|
16
|
+
baseUrl?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum number of automatic retries on failure (default: 3).
|
|
19
|
+
*/
|
|
20
|
+
maxRetries?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Request timeout in milliseconds (default: 30000).
|
|
23
|
+
*/
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/**
|
|
26
|
+
* If true, allows creating the client without an API Key or Backend ID.
|
|
27
|
+
* Useful for hitting public endpoints or if auth is handled externally.
|
|
28
|
+
*/
|
|
29
|
+
allowUnauthenticated?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Custom fetch implementation to use instead of the global fetch.
|
|
32
|
+
*/
|
|
33
|
+
fetch?: typeof fetch;
|
|
34
|
+
/**
|
|
35
|
+
* Minimum wait time between retries in milliseconds (default: 1000).
|
|
36
|
+
*/
|
|
37
|
+
minRetryWait?: number;
|
|
38
|
+
/**
|
|
39
|
+
* Maximum wait time between retries in milliseconds (default: 30000).
|
|
40
|
+
*/
|
|
41
|
+
maxRetryWait?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Array of HTTP status codes that trigger a retry (default: [429, 503]).
|
|
44
|
+
*/
|
|
45
|
+
retryStatuses?: number[];
|
|
46
|
+
/**
|
|
47
|
+
* Default traceparent header to include in all requests.
|
|
48
|
+
* Can also be set via the GC_TRACEPARENT environment variable.
|
|
49
|
+
*/
|
|
50
|
+
traceparent?: string;
|
|
51
|
+
}
|
|
52
|
+
export declare function initClient(config?: GroundcoverConfig): import("./_generated/client/types.gen.js").Client;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import pRetry, { AbortError } from 'p-retry';
|
|
2
|
+
import { createClient } from './_generated/client/index.js';
|
|
3
|
+
class RetryableResponseError extends Error {
|
|
4
|
+
response;
|
|
5
|
+
constructor(response) {
|
|
6
|
+
super(`Retryable status code: ${response.status}`);
|
|
7
|
+
this.response = response;
|
|
8
|
+
this.name = 'RetryableResponseError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
// HTTP methods that are safe to replay after the server has already responded
|
|
12
|
+
// with a retryable status.
|
|
13
|
+
const IDEMPOTENT_METHODS = ['GET', 'HEAD', 'OPTIONS', 'TRACE'];
|
|
14
|
+
function isIdempotentMethod(method) {
|
|
15
|
+
return IDEMPOTENT_METHODS.includes(method.toUpperCase());
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Initializes and returns a new groundcover SDK client.
|
|
19
|
+
* Must be called before using any API services.
|
|
20
|
+
*
|
|
21
|
+
* @param config - Optional configuration object.
|
|
22
|
+
*/
|
|
23
|
+
function normalizeBaseUrl(baseUrl) {
|
|
24
|
+
if (!baseUrl)
|
|
25
|
+
return '';
|
|
26
|
+
if (baseUrl.startsWith('//'))
|
|
27
|
+
return `https:${baseUrl}`;
|
|
28
|
+
if (baseUrl.startsWith('/') && !baseUrl.startsWith('//'))
|
|
29
|
+
return `https://${baseUrl.replace(/^\/+/, '')}`;
|
|
30
|
+
if (!baseUrl.includes('://'))
|
|
31
|
+
return `https://${baseUrl}`;
|
|
32
|
+
return baseUrl;
|
|
33
|
+
}
|
|
34
|
+
function getEnvVar(key) {
|
|
35
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
36
|
+
return process.env[key];
|
|
37
|
+
}
|
|
38
|
+
// Safely check for Deno global without requiring Deno types in the TS config
|
|
39
|
+
// biome-ignore lint/suspicious/noExplicitAny: Safely checking for Deno global
|
|
40
|
+
const globalDeno = globalThis.Deno;
|
|
41
|
+
if (globalDeno?.env) {
|
|
42
|
+
return globalDeno.env.get(key);
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Polyfill for AbortSignal.any() to support Node 18 environments.
|
|
48
|
+
*/
|
|
49
|
+
function combineSignals(signal1, signal2) {
|
|
50
|
+
if (!signal1)
|
|
51
|
+
return signal2;
|
|
52
|
+
if (!signal2)
|
|
53
|
+
return signal1;
|
|
54
|
+
if (typeof AbortSignal.any === 'function') {
|
|
55
|
+
return AbortSignal.any([signal1, signal2]);
|
|
56
|
+
}
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
const onAbort = () => {
|
|
59
|
+
controller.abort(signal1.aborted ? signal1.reason : signal2.reason);
|
|
60
|
+
signal1.removeEventListener('abort', onAbort);
|
|
61
|
+
signal2.removeEventListener('abort', onAbort);
|
|
62
|
+
};
|
|
63
|
+
if (signal1.aborted || signal2.aborted) {
|
|
64
|
+
onAbort();
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
signal1.addEventListener('abort', onAbort);
|
|
68
|
+
signal2.addEventListener('abort', onAbort);
|
|
69
|
+
}
|
|
70
|
+
return controller.signal;
|
|
71
|
+
}
|
|
72
|
+
export function initClient(config) {
|
|
73
|
+
const apiKey = config?.apiKey || getEnvVar('GC_API_KEY');
|
|
74
|
+
const backendId = config?.backendId || getEnvVar('GC_BACKEND_ID');
|
|
75
|
+
const rawBaseUrl = config?.baseUrl || getEnvVar('GC_BASE_URL') || 'https://api.groundcover.com';
|
|
76
|
+
const baseUrl = normalizeBaseUrl(rawBaseUrl);
|
|
77
|
+
const maxRetries = config?.maxRetries ?? 3;
|
|
78
|
+
const traceparent = config?.traceparent || getEnvVar('GC_TRACEPARENT');
|
|
79
|
+
const timeout = config?.timeout ?? 30000;
|
|
80
|
+
const activeFetch = config?.fetch ?? globalThis.fetch;
|
|
81
|
+
const retryStatuses = config?.retryStatuses && config.retryStatuses.length > 0 ? config.retryStatuses : [429, 503];
|
|
82
|
+
const allowUnauthenticated = config?.allowUnauthenticated ?? false;
|
|
83
|
+
if (!allowUnauthenticated && !apiKey) {
|
|
84
|
+
throw new Error('groundcover API key is required. Pass it via config or set GC_API_KEY environment variable.');
|
|
85
|
+
}
|
|
86
|
+
if (!allowUnauthenticated && !backendId) {
|
|
87
|
+
throw new Error('groundcover Backend ID is required. Pass it via config or set GC_BACKEND_ID environment variable.');
|
|
88
|
+
}
|
|
89
|
+
const headers = {
|
|
90
|
+
'User-Agent': 'groundcover-ts-sdk',
|
|
91
|
+
};
|
|
92
|
+
if (apiKey)
|
|
93
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
94
|
+
if (backendId)
|
|
95
|
+
headers['X-Backend-Id'] = backendId;
|
|
96
|
+
if (traceparent) {
|
|
97
|
+
headers.traceparent = traceparent;
|
|
98
|
+
}
|
|
99
|
+
const client = createClient({
|
|
100
|
+
baseUrl,
|
|
101
|
+
headers,
|
|
102
|
+
// Override fetch to add retries and content-type fixes
|
|
103
|
+
fetch: async (input, init) => {
|
|
104
|
+
// Create the base Request once. If input is already a Request, we clone it
|
|
105
|
+
// so we don't consume the caller's instance. If it's a URL/string, we construct it.
|
|
106
|
+
const baseReq = input instanceof Request ? input.clone() : new Request(input, init);
|
|
107
|
+
const runFetch = async () => {
|
|
108
|
+
// Clone for each attempt so the body isn't consumed
|
|
109
|
+
const req = baseReq.clone();
|
|
110
|
+
let res;
|
|
111
|
+
try {
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
const timeoutId = setTimeout(() => controller.abort(new Error('Timeout')), timeout);
|
|
114
|
+
const signal = combineSignals(req.signal, controller.signal);
|
|
115
|
+
try {
|
|
116
|
+
res = await activeFetch(req, { signal });
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
clearTimeout(timeoutId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
// Only retry transport errors for idempotent methods (matches Go/Python SDKs).
|
|
124
|
+
if (isIdempotentMethod(req.method)) {
|
|
125
|
+
throw err; // Allow p-retry to handle it
|
|
126
|
+
}
|
|
127
|
+
throw new AbortError(err);
|
|
128
|
+
}
|
|
129
|
+
// Fix response content-type for monitor YAML GETs
|
|
130
|
+
if (req.method === 'GET' && res.status === 200) {
|
|
131
|
+
const url = new URL(req.url);
|
|
132
|
+
const path = url.pathname.replace(/\/$/, '');
|
|
133
|
+
const parts = path.split('/');
|
|
134
|
+
// /api/monitors/{id}
|
|
135
|
+
if (parts.length >= 4 && parts[parts.length - 2] === 'monitors') {
|
|
136
|
+
const segment = parts[parts.length - 1];
|
|
137
|
+
if (!['silences', 'list', 'recurring-silences'].includes(segment)) {
|
|
138
|
+
const contentType = res.headers.get('content-type') || '';
|
|
139
|
+
if (!contentType.startsWith('application/x-yaml')) {
|
|
140
|
+
// To mutate headers we need to reconstruct the response
|
|
141
|
+
const newHeaders = new Headers(res.headers);
|
|
142
|
+
newHeaders.set('content-type', 'application/x-yaml');
|
|
143
|
+
return new Response(res.body, {
|
|
144
|
+
status: res.status,
|
|
145
|
+
statusText: res.statusText,
|
|
146
|
+
headers: newHeaders,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Trigger retry on certain status codes
|
|
153
|
+
if (retryStatuses.includes(res.status)) {
|
|
154
|
+
// Do not retry non-idempotent requests
|
|
155
|
+
if (!isIdempotentMethod(req.method)) {
|
|
156
|
+
return res;
|
|
157
|
+
}
|
|
158
|
+
throw new RetryableResponseError(res);
|
|
159
|
+
}
|
|
160
|
+
// Also don't retry on other status codes
|
|
161
|
+
return res;
|
|
162
|
+
};
|
|
163
|
+
try {
|
|
164
|
+
return await pRetry(runFetch, {
|
|
165
|
+
retries: maxRetries,
|
|
166
|
+
minTimeout: config?.minRetryWait ?? 1000,
|
|
167
|
+
maxTimeout: config?.maxRetryWait ?? 30000,
|
|
168
|
+
factor: 2,
|
|
169
|
+
randomize: true,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
if (err instanceof RetryableResponseError) {
|
|
174
|
+
return err.response; // return the final response after exhaustion
|
|
175
|
+
}
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
// Interceptor to clean up Content-Type and add retries (matching Go/Python SDKs)
|
|
181
|
+
client.interceptors.request.use((req, options) => {
|
|
182
|
+
// For GET/DELETE/HEAD requests, avoid sending a Content-Type.
|
|
183
|
+
if (['GET', 'DELETE', 'HEAD'].includes(req.method.toUpperCase())) {
|
|
184
|
+
req.headers.delete('Content-Type');
|
|
185
|
+
}
|
|
186
|
+
return req;
|
|
187
|
+
});
|
|
188
|
+
return client;
|
|
189
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Options } from './_generated/client/types.gen.js';
|
|
2
|
+
import type { GetMonitorData } from './_generated/index.js';
|
|
3
|
+
export type ParsedMonitorResponse = {
|
|
4
|
+
data: Record<string, unknown>;
|
|
5
|
+
error: null;
|
|
6
|
+
response: Response;
|
|
7
|
+
} | {
|
|
8
|
+
data: undefined;
|
|
9
|
+
error: unknown;
|
|
10
|
+
response: Response;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Convenience method to get a monitor and parse its YAML response into an object.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getMonitorParsed(options: Options<GetMonitorData>): Promise<ParsedMonitorResponse>;
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as yaml from 'js-yaml';
|
|
2
|
+
import { getMonitor } from './_generated/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Convenience method to get a monitor and parse its YAML response into an object.
|
|
5
|
+
*/
|
|
6
|
+
export async function getMonitorParsed(options) {
|
|
7
|
+
const result = (await getMonitor({
|
|
8
|
+
...options,
|
|
9
|
+
parseAs: 'text',
|
|
10
|
+
}));
|
|
11
|
+
if (result.error || !result.data) {
|
|
12
|
+
return { data: undefined, error: result.error, response: result.response };
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
return {
|
|
16
|
+
data: yaml.load(result.data),
|
|
17
|
+
error: null,
|
|
18
|
+
response: result.response,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return { data: undefined, error: e, response: result.response };
|
|
23
|
+
}
|
|
24
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Condition constants for the groundcover SDK. */
|
|
2
|
+
export declare const CONDITION_ORIGIN_ROOT = "root";
|
|
3
|
+
export declare const CONDITION_KEY_NAMESPACE = "namespace";
|
|
4
|
+
export declare const CONDITION_KEY_WORKLOAD = "workload";
|
|
5
|
+
export declare const CONDITION_KEY_POD_NAME = "podName";
|
|
6
|
+
export declare const CONDITION_KEY_REASON = "reason";
|
|
7
|
+
export declare const CONDITION_KEY_TYPE = "type";
|
|
8
|
+
export declare const CONDITION_KEY_ENV = "env";
|
|
9
|
+
export declare const CONDITION_KEY_INSTANCE = "instance";
|
|
10
|
+
export declare const CONDITION_VALUE_OOM_KILLED = "OOMKilled";
|
|
11
|
+
export declare const CONDITION_VALUE_TYPE_CONTAINER_CRASH = "container_crash";
|
|
12
|
+
export declare const OPERATOR_EQUAL = "eq";
|
|
13
|
+
export declare const OPERATOR_NOT_EQUAL = "ne";
|
|
14
|
+
export declare const OPERATOR_CONTAINS = "contains";
|
|
15
|
+
export declare const OPERATOR_NOT_CONTAINS = "notcontains";
|
|
16
|
+
export declare const OPERATOR_CONTAINS_IGNORE_CASE = "icontains";
|
|
17
|
+
export declare const OPERATOR_NOT_CONTAINS_IGNORE_CASE = "inotcontains";
|
|
18
|
+
export declare const OPERATOR_STARTS_WITH = "startswith";
|
|
19
|
+
export declare const OPERATOR_STARTS_WITH_IGNORE_CASE = "istartswith";
|
|
20
|
+
export declare const CONDITION_TYPE_STRING = "string";
|
|
21
|
+
export declare const CONDITION_TYPE_INT64 = "int64";
|
|
22
|
+
export declare const CONDITION_TYPE_FLOAT64 = "float64";
|
|
23
|
+
export declare const CONDITION_TYPE_BOOL = "bool";
|
|
24
|
+
export declare const CONDITION_TYPE_DATETIME = "datetime";
|
|
25
|
+
export declare const CONDITION_TYPE_STRING_ARRAY = "string_array";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Condition constants for the groundcover SDK. */
|
|
2
|
+
// Condition fields
|
|
3
|
+
export const CONDITION_ORIGIN_ROOT = 'root';
|
|
4
|
+
// Condition keys
|
|
5
|
+
export const CONDITION_KEY_NAMESPACE = 'namespace';
|
|
6
|
+
export const CONDITION_KEY_WORKLOAD = 'workload';
|
|
7
|
+
export const CONDITION_KEY_POD_NAME = 'podName';
|
|
8
|
+
export const CONDITION_KEY_REASON = 'reason';
|
|
9
|
+
export const CONDITION_KEY_TYPE = 'type';
|
|
10
|
+
export const CONDITION_KEY_ENV = 'env';
|
|
11
|
+
export const CONDITION_KEY_INSTANCE = 'instance';
|
|
12
|
+
// Condition values
|
|
13
|
+
export const CONDITION_VALUE_OOM_KILLED = 'OOMKilled';
|
|
14
|
+
export const CONDITION_VALUE_TYPE_CONTAINER_CRASH = 'container_crash';
|
|
15
|
+
// Filter operators
|
|
16
|
+
export const OPERATOR_EQUAL = 'eq';
|
|
17
|
+
export const OPERATOR_NOT_EQUAL = 'ne';
|
|
18
|
+
export const OPERATOR_CONTAINS = 'contains';
|
|
19
|
+
export const OPERATOR_NOT_CONTAINS = 'notcontains';
|
|
20
|
+
export const OPERATOR_CONTAINS_IGNORE_CASE = 'icontains';
|
|
21
|
+
export const OPERATOR_NOT_CONTAINS_IGNORE_CASE = 'inotcontains';
|
|
22
|
+
export const OPERATOR_STARTS_WITH = 'startswith';
|
|
23
|
+
export const OPERATOR_STARTS_WITH_IGNORE_CASE = 'istartswith';
|
|
24
|
+
// Condition types
|
|
25
|
+
export const CONDITION_TYPE_STRING = 'string';
|
|
26
|
+
export const CONDITION_TYPE_INT64 = 'int64';
|
|
27
|
+
export const CONDITION_TYPE_FLOAT64 = 'float64';
|
|
28
|
+
export const CONDITION_TYPE_BOOL = 'bool';
|
|
29
|
+
export const CONDITION_TYPE_DATETIME = 'datetime';
|
|
30
|
+
export const CONDITION_TYPE_STRING_ARRAY = 'string_array';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Match type enum for the groundcover SDK. */
|
|
2
|
+
export var FilterMatchType;
|
|
3
|
+
(function (FilterMatchType) {
|
|
4
|
+
FilterMatchType["EQUAL"] = "=";
|
|
5
|
+
FilterMatchType["NOT_EQUAL"] = "!=";
|
|
6
|
+
FilterMatchType["REGEX"] = "=~";
|
|
7
|
+
FilterMatchType["NOT_REGEX"] = "!~";
|
|
8
|
+
})(FilterMatchType || (FilterMatchType = {}));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Condition } from '../_generated/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fluent builder for constructing a list of conditions.
|
|
4
|
+
*
|
|
5
|
+
* Uses default values for origin, type, and operator which can be overridden.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { ConditionSet } from '@groundcover/api-client';
|
|
10
|
+
*
|
|
11
|
+
* const conditions = new ConditionSet()
|
|
12
|
+
* .add("namespace", "production")
|
|
13
|
+
* .add("reason", "OOMKilled")
|
|
14
|
+
* .addOomEventConditions()
|
|
15
|
+
* .build();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare class ConditionSet {
|
|
19
|
+
private conditions;
|
|
20
|
+
private defaultOrigin;
|
|
21
|
+
private defaultCondType;
|
|
22
|
+
private defaultOperator;
|
|
23
|
+
constructor(defaultOrigin?: string, defaultCondType?: string, defaultOperator?: string);
|
|
24
|
+
/**
|
|
25
|
+
* Add a condition, inferring the type from the JavaScript value type.
|
|
26
|
+
*
|
|
27
|
+
* Supports: string, string[], number (int/float inferred heuristically), boolean, Date.
|
|
28
|
+
*/
|
|
29
|
+
add(key: string, value: unknown): ConditionSet;
|
|
30
|
+
/** Add a condition with explicit origin, type, operator, and value. */
|
|
31
|
+
addFull(key: string, origin: string, condType: string, value: string, operator: string): ConditionSet;
|
|
32
|
+
/** Add a pre-constructed condition object directly. */
|
|
33
|
+
addRaw(condition: Condition): ConditionSet;
|
|
34
|
+
/**
|
|
35
|
+
* Add predefined conditions to identify OOM events.
|
|
36
|
+
* Adds reason=OOMKilled and type=container_crash.
|
|
37
|
+
*/
|
|
38
|
+
addOomEventConditions(): ConditionSet;
|
|
39
|
+
/** Return the final list of condition objects. */
|
|
40
|
+
build(): Condition[];
|
|
41
|
+
private addInternal;
|
|
42
|
+
/**
|
|
43
|
+
* Infer condition type and string value from a JavaScript value.
|
|
44
|
+
* Returns [valueStr, condType].
|
|
45
|
+
*/
|
|
46
|
+
private inferType;
|
|
47
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { CONDITION_KEY_REASON, CONDITION_KEY_TYPE, CONDITION_ORIGIN_ROOT, CONDITION_TYPE_BOOL, CONDITION_TYPE_DATETIME, CONDITION_TYPE_FLOAT64, CONDITION_TYPE_INT64, CONDITION_TYPE_STRING, CONDITION_TYPE_STRING_ARRAY, CONDITION_VALUE_OOM_KILLED, CONDITION_VALUE_TYPE_CONTAINER_CRASH, OPERATOR_EQUAL, } from '../types/conditions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Fluent builder for constructing a list of conditions.
|
|
4
|
+
*
|
|
5
|
+
* Uses default values for origin, type, and operator which can be overridden.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { ConditionSet } from '@groundcover/api-client';
|
|
10
|
+
*
|
|
11
|
+
* const conditions = new ConditionSet()
|
|
12
|
+
* .add("namespace", "production")
|
|
13
|
+
* .add("reason", "OOMKilled")
|
|
14
|
+
* .addOomEventConditions()
|
|
15
|
+
* .build();
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class ConditionSet {
|
|
19
|
+
conditions = [];
|
|
20
|
+
defaultOrigin;
|
|
21
|
+
defaultCondType;
|
|
22
|
+
defaultOperator;
|
|
23
|
+
constructor(defaultOrigin = CONDITION_ORIGIN_ROOT, defaultCondType = CONDITION_TYPE_STRING, defaultOperator = OPERATOR_EQUAL) {
|
|
24
|
+
this.defaultOrigin = defaultOrigin;
|
|
25
|
+
this.defaultCondType = defaultCondType;
|
|
26
|
+
this.defaultOperator = defaultOperator;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Add a condition, inferring the type from the JavaScript value type.
|
|
30
|
+
*
|
|
31
|
+
* Supports: string, string[], number (int/float inferred heuristically), boolean, Date.
|
|
32
|
+
*/
|
|
33
|
+
add(key, value) {
|
|
34
|
+
const [valueStr, condType] = this.inferType(value);
|
|
35
|
+
return this.addInternal(key, this.defaultOrigin, condType, valueStr, this.defaultOperator);
|
|
36
|
+
}
|
|
37
|
+
/** Add a condition with explicit origin, type, operator, and value. */
|
|
38
|
+
addFull(key, origin, condType, value, operator) {
|
|
39
|
+
return this.addInternal(key, origin, condType, value, operator);
|
|
40
|
+
}
|
|
41
|
+
/** Add a pre-constructed condition object directly. */
|
|
42
|
+
addRaw(condition) {
|
|
43
|
+
this.conditions.push(condition);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Add predefined conditions to identify OOM events.
|
|
48
|
+
* Adds reason=OOMKilled and type=container_crash.
|
|
49
|
+
*/
|
|
50
|
+
addOomEventConditions() {
|
|
51
|
+
this.add(CONDITION_KEY_REASON, CONDITION_VALUE_OOM_KILLED);
|
|
52
|
+
this.add(CONDITION_KEY_TYPE, CONDITION_VALUE_TYPE_CONTAINER_CRASH);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/** Return the final list of condition objects. */
|
|
56
|
+
build() {
|
|
57
|
+
return [...this.conditions];
|
|
58
|
+
}
|
|
59
|
+
addInternal(key, origin, condType, value, operator) {
|
|
60
|
+
const condition = {
|
|
61
|
+
key,
|
|
62
|
+
origin,
|
|
63
|
+
type: condType,
|
|
64
|
+
filters: [{ op: operator, value }],
|
|
65
|
+
};
|
|
66
|
+
this.conditions.push(condition);
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Infer condition type and string value from a JavaScript value.
|
|
71
|
+
* Returns [valueStr, condType].
|
|
72
|
+
*/
|
|
73
|
+
inferType(value) {
|
|
74
|
+
if (typeof value === 'string') {
|
|
75
|
+
return [value, CONDITION_TYPE_STRING];
|
|
76
|
+
}
|
|
77
|
+
if (typeof value === 'boolean') {
|
|
78
|
+
return [String(value).toLowerCase(), CONDITION_TYPE_BOOL];
|
|
79
|
+
}
|
|
80
|
+
if (typeof value === 'number') {
|
|
81
|
+
if (Number.isInteger(value)) {
|
|
82
|
+
return [String(value), CONDITION_TYPE_INT64];
|
|
83
|
+
}
|
|
84
|
+
return [String(value), CONDITION_TYPE_FLOAT64];
|
|
85
|
+
}
|
|
86
|
+
if (value instanceof Date) {
|
|
87
|
+
return [value.toISOString(), CONDITION_TYPE_DATETIME];
|
|
88
|
+
}
|
|
89
|
+
if (Array.isArray(value)) {
|
|
90
|
+
return [JSON.stringify(value), CONDITION_TYPE_STRING_ARRAY];
|
|
91
|
+
}
|
|
92
|
+
// Fallback
|
|
93
|
+
return [String(value), this.defaultCondType];
|
|
94
|
+
}
|
|
95
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@groundcover/api-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "groundcover TypeScript API Client",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@biomejs/biome": "^1.8.0",
|
|
10
|
+
"@hey-api/openapi-ts": "0.99.0",
|
|
11
|
+
"@types/js-yaml": "^4.0.9",
|
|
12
|
+
"@types/node": "^20.0.0",
|
|
13
|
+
"typescript": "^6.0.0",
|
|
14
|
+
"vitest": "^2.0.0"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=18.0.0",
|
|
18
|
+
"bun": ">=1.0.0",
|
|
19
|
+
"deno": ">=1.37.0"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src"
|
|
25
|
+
],
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"import": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"js-yaml": "^5.2.1",
|
|
34
|
+
"p-retry": "^6.2.1"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"test": "vitest run tests/unit",
|
|
39
|
+
"test:unit": "vitest run tests/unit",
|
|
40
|
+
"test:e2e": "vitest run tests/e2e",
|
|
41
|
+
"lint": "biome check .",
|
|
42
|
+
"format": "biome format --write ."
|
|
43
|
+
}
|
|
44
|
+
}
|