@checkstack/sdk 0.94.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/CHANGELOG.md +46 -0
- package/generated/editor-bundle-module.d.ts +7 -0
- package/generated/editor-bundle.d.ts +122 -0
- package/generated/healthcheck.d.ts +49 -0
- package/generated/index.d.ts +178 -0
- package/generated/integration.d.ts +47 -0
- package/generated/version.d.ts +6 -0
- package/package.json +69 -0
- package/src/client.ts +120 -0
- package/src/contracts.ts +31 -0
- package/src/editor-bundle.ts +13 -0
- package/src/healthcheck.ts +57 -0
- package/src/index.ts +9 -0
- package/src/integration.ts +55 -0
- package/src/version.ts +6 -0
- package/test/client.test.ts +44 -0
- package/test/fixtures/consumer-cross-subpath.ts +8 -0
- package/test/fixtures/consumer-good.ts +28 -0
- package/test/subpath-resolution.test.ts +121 -0
- package/tsconfig.json +78 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @checkstack/sdk
|
|
2
|
+
|
|
3
|
+
## 0.93.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [9dcc848]
|
|
8
|
+
- Updated dependencies [9dcc848]
|
|
9
|
+
- Updated dependencies [9dcc848]
|
|
10
|
+
- Updated dependencies [9dcc848]
|
|
11
|
+
- Updated dependencies [9dcc848]
|
|
12
|
+
- Updated dependencies [9dcc848]
|
|
13
|
+
- Updated dependencies [9dcc848]
|
|
14
|
+
- Updated dependencies [9dcc848]
|
|
15
|
+
- Updated dependencies [9dcc848]
|
|
16
|
+
- Updated dependencies [9dcc848]
|
|
17
|
+
- Updated dependencies [9dcc848]
|
|
18
|
+
- Updated dependencies [9dcc848]
|
|
19
|
+
- Updated dependencies [9dcc848]
|
|
20
|
+
- Updated dependencies [9dcc848]
|
|
21
|
+
- Updated dependencies [9dcc848]
|
|
22
|
+
- Updated dependencies [9dcc848]
|
|
23
|
+
- Updated dependencies [9dcc848]
|
|
24
|
+
- @checkstack/auth-common@0.8.0
|
|
25
|
+
- @checkstack/healthcheck-common@1.5.0
|
|
26
|
+
- @checkstack/notification-common@1.3.0
|
|
27
|
+
- @checkstack/anomaly-common@1.3.0
|
|
28
|
+
- @checkstack/automation-common@0.4.0
|
|
29
|
+
- @checkstack/catalog-common@2.3.0
|
|
30
|
+
- @checkstack/common@0.13.0
|
|
31
|
+
- @checkstack/script-packages-common@0.3.0
|
|
32
|
+
- @checkstack/slo-common@0.5.0
|
|
33
|
+
- @checkstack/satellite-common@0.8.0
|
|
34
|
+
- @checkstack/announcement-common@0.5.0
|
|
35
|
+
- @checkstack/cache-common@0.5.0
|
|
36
|
+
- @checkstack/command-common@0.3.0
|
|
37
|
+
- @checkstack/dependency-common@1.2.0
|
|
38
|
+
- @checkstack/gitops-common@0.6.0
|
|
39
|
+
- @checkstack/incident-common@1.4.0
|
|
40
|
+
- @checkstack/integration-common@0.7.0
|
|
41
|
+
- @checkstack/maintenance-common@1.4.0
|
|
42
|
+
- @checkstack/queue-common@0.6.0
|
|
43
|
+
- @checkstack/secrets-common@0.2.0
|
|
44
|
+
- @checkstack/theme-common@0.2.0
|
|
45
|
+
- @checkstack/tips-common@0.3.0
|
|
46
|
+
- @checkstack/pluginmanager-common@0.2.5
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
/** The combined ambient `.d.ts` the in-app editor mounts into Monaco. */
|
|
6
|
+
export declare const SDK_EDITOR_BUNDLE_DTS: string;
|
|
7
|
+
export { SDK_RELEASE_VERSION } from "./version.d.ts";
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
// Combined ambient declarations served ONLY by the version-keyed editor
|
|
6
|
+
// route and mounted into Monaco. NOT the `exports`-resolved declarations
|
|
7
|
+
// (those are the per-subpath generated/*.d.ts). Declares the subpath module
|
|
8
|
+
// names only - bare names are intentionally absent so an old import errors.
|
|
9
|
+
//
|
|
10
|
+
// Every declaration is module-scoped (no top-level globals): the editor
|
|
11
|
+
// mounts this bundle alongside scriptContext.ts, which owns the global
|
|
12
|
+
// `defineHealthCheck` / `defineIntegration` + schema-narrowed context types
|
|
13
|
+
// (plan §6.2). Top-level globals here would duplicate those and error.
|
|
14
|
+
|
|
15
|
+
declare module "@checkstack/sdk/healthcheck" {
|
|
16
|
+
/** Result emitted by an inline health-check script. */
|
|
17
|
+
interface HealthCheckScriptResult {
|
|
18
|
+
/** Whether the health check passed. */
|
|
19
|
+
success: boolean;
|
|
20
|
+
/** Optional status message — surfaces in the run detail. */
|
|
21
|
+
message?: string;
|
|
22
|
+
/** Optional numeric value — feeds the value chart + anomaly detection. */
|
|
23
|
+
value?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Runtime context exposed to inline health-check scripts. `config` is
|
|
28
|
+
* typed from the collector's own JSON Schema, so the fields you've
|
|
29
|
+
* declared on the configuration are autocompletable inside the script.
|
|
30
|
+
*/
|
|
31
|
+
interface HealthCheckScriptContext {
|
|
32
|
+
/** Strongly-typed collector configuration. */
|
|
33
|
+
readonly config: Record<string, unknown>;
|
|
34
|
+
/** Metadata about the health check this run is for. */
|
|
35
|
+
readonly check: {
|
|
36
|
+
/** The health check configuration id. */
|
|
37
|
+
readonly id: string;
|
|
38
|
+
/** The health check's display name (falls back to the id). */
|
|
39
|
+
readonly name: string;
|
|
40
|
+
/** The configured run interval, in seconds. */
|
|
41
|
+
readonly intervalSeconds: number;
|
|
42
|
+
};
|
|
43
|
+
/** Metadata about the system this check runs for. */
|
|
44
|
+
readonly system: {
|
|
45
|
+
/** The system id. */
|
|
46
|
+
readonly id: string;
|
|
47
|
+
/** The system's display name (falls back to the id). */
|
|
48
|
+
readonly name: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function defineHealthCheck<
|
|
53
|
+
T extends
|
|
54
|
+
| HealthCheckScriptResult
|
|
55
|
+
| ((ctx: HealthCheckScriptContext) =>
|
|
56
|
+
| HealthCheckScriptResult
|
|
57
|
+
| Promise<HealthCheckScriptResult>),
|
|
58
|
+
>(value: T): T;
|
|
59
|
+
export type { HealthCheckScriptResult, HealthCheckScriptContext };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare module "@checkstack/sdk/integration" {
|
|
63
|
+
/** Result emitted by an inline integration script. */
|
|
64
|
+
interface IntegrationScriptResult {
|
|
65
|
+
/** External ID for tracking (e.g. ticket number, message ID). */
|
|
66
|
+
id?: string;
|
|
67
|
+
/** Same as `id` — accepted for backwards compatibility. */
|
|
68
|
+
externalId?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Runtime context exposed to inline integration scripts. `event.payload`
|
|
73
|
+
* is typed from the event's payload schema so the fields it advertises
|
|
74
|
+
* are autocompletable inside the script.
|
|
75
|
+
*/
|
|
76
|
+
interface IntegrationScriptContext {
|
|
77
|
+
/** The event being delivered. */
|
|
78
|
+
readonly event: {
|
|
79
|
+
/** Fully-qualified event ID, e.g. "incident.created". */
|
|
80
|
+
readonly eventId: string;
|
|
81
|
+
/** Strongly-typed event payload. */
|
|
82
|
+
readonly payload: Record<string, unknown>;
|
|
83
|
+
/** ISO-8601 timestamp of when the event was emitted. */
|
|
84
|
+
readonly timestamp: string;
|
|
85
|
+
/** Unique ID for this delivery attempt. */
|
|
86
|
+
readonly deliveryId: string;
|
|
87
|
+
};
|
|
88
|
+
/** Subscription that triggered this delivery. */
|
|
89
|
+
readonly subscription: {
|
|
90
|
+
readonly id: string;
|
|
91
|
+
readonly name: string;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function defineIntegration<
|
|
96
|
+
T extends
|
|
97
|
+
| IntegrationScriptResult
|
|
98
|
+
| void
|
|
99
|
+
| ((ctx: IntegrationScriptContext) =>
|
|
100
|
+
| IntegrationScriptResult
|
|
101
|
+
| void
|
|
102
|
+
| Promise<IntegrationScriptResult | void>),
|
|
103
|
+
>(value: T): T;
|
|
104
|
+
export type { IntegrationScriptResult, IntegrationScriptContext };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
declare module "@checkstack/sdk" {
|
|
108
|
+
export { defineHealthCheck } from "@checkstack/sdk/healthcheck";
|
|
109
|
+
export type { HealthCheckScriptResult, HealthCheckScriptContext } from "@checkstack/sdk/healthcheck";
|
|
110
|
+
export { defineIntegration } from "@checkstack/sdk/integration";
|
|
111
|
+
export type { IntegrationScriptResult, IntegrationScriptContext } from "@checkstack/sdk/integration";
|
|
112
|
+
export interface CreateCheckstackClientOptions {
|
|
113
|
+
baseUrl: string;
|
|
114
|
+
headers?: Record<string, string>;
|
|
115
|
+
}
|
|
116
|
+
/** The fully-typed Checkstack API client (one entry per plugin id). */
|
|
117
|
+
export type CheckstackClient = Record<string, unknown>;
|
|
118
|
+
/** Build a typed Checkstack client over the REST/OpenAPI surface. */
|
|
119
|
+
export function createCheckstackClient(
|
|
120
|
+
options: CreateCheckstackClientOptions,
|
|
121
|
+
): CheckstackClient;
|
|
122
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
/** Result emitted by an inline health-check script. */
|
|
6
|
+
interface HealthCheckScriptResult {
|
|
7
|
+
/** Whether the health check passed. */
|
|
8
|
+
success: boolean;
|
|
9
|
+
/** Optional status message — surfaces in the run detail. */
|
|
10
|
+
message?: string;
|
|
11
|
+
/** Optional numeric value — feeds the value chart + anomaly detection. */
|
|
12
|
+
value?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Runtime context exposed to inline health-check scripts. `config` is
|
|
17
|
+
* typed from the collector's own JSON Schema, so the fields you've
|
|
18
|
+
* declared on the configuration are autocompletable inside the script.
|
|
19
|
+
*/
|
|
20
|
+
interface HealthCheckScriptContext {
|
|
21
|
+
/** Strongly-typed collector configuration. */
|
|
22
|
+
readonly config: Record<string, unknown>;
|
|
23
|
+
/** Metadata about the health check this run is for. */
|
|
24
|
+
readonly check: {
|
|
25
|
+
/** The health check configuration id. */
|
|
26
|
+
readonly id: string;
|
|
27
|
+
/** The health check's display name (falls back to the id). */
|
|
28
|
+
readonly name: string;
|
|
29
|
+
/** The configured run interval, in seconds. */
|
|
30
|
+
readonly intervalSeconds: number;
|
|
31
|
+
};
|
|
32
|
+
/** Metadata about the system this check runs for. */
|
|
33
|
+
readonly system: {
|
|
34
|
+
/** The system id. */
|
|
35
|
+
readonly id: string;
|
|
36
|
+
/** The system's display name (falls back to the id). */
|
|
37
|
+
readonly name: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export declare function defineHealthCheck<
|
|
42
|
+
T extends
|
|
43
|
+
| HealthCheckScriptResult
|
|
44
|
+
| ((ctx: HealthCheckScriptContext) =>
|
|
45
|
+
| HealthCheckScriptResult
|
|
46
|
+
| Promise<HealthCheckScriptResult>),
|
|
47
|
+
>(value: T): T;
|
|
48
|
+
|
|
49
|
+
export type { HealthCheckScriptResult, HealthCheckScriptContext };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
import type { InferClient } from "@checkstack/common";
|
|
6
|
+
import type { AnnouncementApi } from "@checkstack/announcement-common";
|
|
7
|
+
import type { AnomalyApi } from "@checkstack/anomaly-common";
|
|
8
|
+
import type { AuthApi } from "@checkstack/auth-common";
|
|
9
|
+
import type { AutomationApi } from "@checkstack/automation-common";
|
|
10
|
+
import type { CacheApi } from "@checkstack/cache-common";
|
|
11
|
+
import type { CatalogApi } from "@checkstack/catalog-common";
|
|
12
|
+
import type { CommandApi } from "@checkstack/command-common";
|
|
13
|
+
import type { DependencyApi } from "@checkstack/dependency-common";
|
|
14
|
+
import type { GitOpsApi } from "@checkstack/gitops-common";
|
|
15
|
+
import type { HealthCheckApi } from "@checkstack/healthcheck-common";
|
|
16
|
+
import type { IncidentApi } from "@checkstack/incident-common";
|
|
17
|
+
import type { IntegrationApi } from "@checkstack/integration-common";
|
|
18
|
+
import type { MaintenanceApi } from "@checkstack/maintenance-common";
|
|
19
|
+
import type { NotificationApi } from "@checkstack/notification-common";
|
|
20
|
+
import type { PluginManagerApi } from "@checkstack/pluginmanager-common";
|
|
21
|
+
import type { QueueApi } from "@checkstack/queue-common";
|
|
22
|
+
import type { SatelliteApi } from "@checkstack/satellite-common";
|
|
23
|
+
import type { ScriptPackagesApi } from "@checkstack/script-packages-common";
|
|
24
|
+
import type { SecretsApi } from "@checkstack/secrets-common";
|
|
25
|
+
import type { SloApi } from "@checkstack/slo-common";
|
|
26
|
+
import type { ThemeApi } from "@checkstack/theme-common";
|
|
27
|
+
import type { TipsApi } from "@checkstack/tips-common";
|
|
28
|
+
|
|
29
|
+
export interface CheckstackClient {
|
|
30
|
+
announcement: InferClient<typeof AnnouncementApi>;
|
|
31
|
+
anomaly: InferClient<typeof AnomalyApi>;
|
|
32
|
+
auth: InferClient<typeof AuthApi>;
|
|
33
|
+
automation: InferClient<typeof AutomationApi>;
|
|
34
|
+
cache: InferClient<typeof CacheApi>;
|
|
35
|
+
catalog: InferClient<typeof CatalogApi>;
|
|
36
|
+
command: InferClient<typeof CommandApi>;
|
|
37
|
+
dependency: InferClient<typeof DependencyApi>;
|
|
38
|
+
gitops: InferClient<typeof GitOpsApi>;
|
|
39
|
+
healthcheck: InferClient<typeof HealthCheckApi>;
|
|
40
|
+
incident: InferClient<typeof IncidentApi>;
|
|
41
|
+
integration: InferClient<typeof IntegrationApi>;
|
|
42
|
+
maintenance: InferClient<typeof MaintenanceApi>;
|
|
43
|
+
notification: InferClient<typeof NotificationApi>;
|
|
44
|
+
pluginmanager: InferClient<typeof PluginManagerApi>;
|
|
45
|
+
queue: InferClient<typeof QueueApi>;
|
|
46
|
+
satellite: InferClient<typeof SatelliteApi>;
|
|
47
|
+
"script-packages": InferClient<typeof ScriptPackagesApi>;
|
|
48
|
+
secrets: InferClient<typeof SecretsApi>;
|
|
49
|
+
slo: InferClient<typeof SloApi>;
|
|
50
|
+
theme: InferClient<typeof ThemeApi>;
|
|
51
|
+
tips: InferClient<typeof TipsApi>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface CreateCheckstackClientOptions {
|
|
55
|
+
baseUrl: string;
|
|
56
|
+
headers?: Record<string, string>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export declare function createCheckstackClient(
|
|
60
|
+
options: CreateCheckstackClientOptions,
|
|
61
|
+
): CheckstackClient;
|
|
62
|
+
|
|
63
|
+
export { AnnouncementApi } from "@checkstack/announcement-common";
|
|
64
|
+
export { AnomalyApi } from "@checkstack/anomaly-common";
|
|
65
|
+
export { AuthApi } from "@checkstack/auth-common";
|
|
66
|
+
export { AutomationApi } from "@checkstack/automation-common";
|
|
67
|
+
export { CacheApi } from "@checkstack/cache-common";
|
|
68
|
+
export { CatalogApi } from "@checkstack/catalog-common";
|
|
69
|
+
export { CommandApi } from "@checkstack/command-common";
|
|
70
|
+
export { DependencyApi } from "@checkstack/dependency-common";
|
|
71
|
+
export { GitOpsApi } from "@checkstack/gitops-common";
|
|
72
|
+
export { HealthCheckApi } from "@checkstack/healthcheck-common";
|
|
73
|
+
export { IncidentApi } from "@checkstack/incident-common";
|
|
74
|
+
export { IntegrationApi } from "@checkstack/integration-common";
|
|
75
|
+
export { MaintenanceApi } from "@checkstack/maintenance-common";
|
|
76
|
+
export { NotificationApi } from "@checkstack/notification-common";
|
|
77
|
+
export { PluginManagerApi } from "@checkstack/pluginmanager-common";
|
|
78
|
+
export { QueueApi } from "@checkstack/queue-common";
|
|
79
|
+
export { SatelliteApi } from "@checkstack/satellite-common";
|
|
80
|
+
export { ScriptPackagesApi } from "@checkstack/script-packages-common";
|
|
81
|
+
export { SecretsApi } from "@checkstack/secrets-common";
|
|
82
|
+
export { SloApi } from "@checkstack/slo-common";
|
|
83
|
+
export { ThemeApi } from "@checkstack/theme-common";
|
|
84
|
+
export { TipsApi } from "@checkstack/tips-common";
|
|
85
|
+
|
|
86
|
+
// Script-authoring helpers (also available under the per-subpath exports).
|
|
87
|
+
/** Result emitted by an inline health-check script. */
|
|
88
|
+
interface HealthCheckScriptResult {
|
|
89
|
+
/** Whether the health check passed. */
|
|
90
|
+
success: boolean;
|
|
91
|
+
/** Optional status message — surfaces in the run detail. */
|
|
92
|
+
message?: string;
|
|
93
|
+
/** Optional numeric value — feeds the value chart + anomaly detection. */
|
|
94
|
+
value?: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Runtime context exposed to inline health-check scripts. `config` is
|
|
99
|
+
* typed from the collector's own JSON Schema, so the fields you've
|
|
100
|
+
* declared on the configuration are autocompletable inside the script.
|
|
101
|
+
*/
|
|
102
|
+
interface HealthCheckScriptContext {
|
|
103
|
+
/** Strongly-typed collector configuration. */
|
|
104
|
+
readonly config: Record<string, unknown>;
|
|
105
|
+
/** Metadata about the health check this run is for. */
|
|
106
|
+
readonly check: {
|
|
107
|
+
/** The health check configuration id. */
|
|
108
|
+
readonly id: string;
|
|
109
|
+
/** The health check's display name (falls back to the id). */
|
|
110
|
+
readonly name: string;
|
|
111
|
+
/** The configured run interval, in seconds. */
|
|
112
|
+
readonly intervalSeconds: number;
|
|
113
|
+
};
|
|
114
|
+
/** Metadata about the system this check runs for. */
|
|
115
|
+
readonly system: {
|
|
116
|
+
/** The system id. */
|
|
117
|
+
readonly id: string;
|
|
118
|
+
/** The system's display name (falls back to the id). */
|
|
119
|
+
readonly name: string;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Result emitted by an inline integration script. */
|
|
124
|
+
interface IntegrationScriptResult {
|
|
125
|
+
/** External ID for tracking (e.g. ticket number, message ID). */
|
|
126
|
+
id?: string;
|
|
127
|
+
/** Same as `id` — accepted for backwards compatibility. */
|
|
128
|
+
externalId?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Runtime context exposed to inline integration scripts. `event.payload`
|
|
133
|
+
* is typed from the event's payload schema so the fields it advertises
|
|
134
|
+
* are autocompletable inside the script.
|
|
135
|
+
*/
|
|
136
|
+
interface IntegrationScriptContext {
|
|
137
|
+
/** The event being delivered. */
|
|
138
|
+
readonly event: {
|
|
139
|
+
/** Fully-qualified event ID, e.g. "incident.created". */
|
|
140
|
+
readonly eventId: string;
|
|
141
|
+
/** Strongly-typed event payload. */
|
|
142
|
+
readonly payload: Record<string, unknown>;
|
|
143
|
+
/** ISO-8601 timestamp of when the event was emitted. */
|
|
144
|
+
readonly timestamp: string;
|
|
145
|
+
/** Unique ID for this delivery attempt. */
|
|
146
|
+
readonly deliveryId: string;
|
|
147
|
+
};
|
|
148
|
+
/** Subscription that triggered this delivery. */
|
|
149
|
+
readonly subscription: {
|
|
150
|
+
readonly id: string;
|
|
151
|
+
readonly name: string;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export declare function defineHealthCheck<
|
|
156
|
+
T extends
|
|
157
|
+
| HealthCheckScriptResult
|
|
158
|
+
| ((ctx: HealthCheckScriptContext) =>
|
|
159
|
+
| HealthCheckScriptResult
|
|
160
|
+
| Promise<HealthCheckScriptResult>),
|
|
161
|
+
>(value: T): T;
|
|
162
|
+
export declare function defineIntegration<
|
|
163
|
+
T extends
|
|
164
|
+
| IntegrationScriptResult
|
|
165
|
+
| void
|
|
166
|
+
| ((ctx: IntegrationScriptContext) =>
|
|
167
|
+
| IntegrationScriptResult
|
|
168
|
+
| void
|
|
169
|
+
| Promise<IntegrationScriptResult | void>),
|
|
170
|
+
>(value: T): T;
|
|
171
|
+
export type {
|
|
172
|
+
HealthCheckScriptResult,
|
|
173
|
+
HealthCheckScriptContext,
|
|
174
|
+
IntegrationScriptResult,
|
|
175
|
+
IntegrationScriptContext,
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export type { InferClient, ClientDefinition } from "@checkstack/common";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
/** Result emitted by an inline integration script. */
|
|
6
|
+
interface IntegrationScriptResult {
|
|
7
|
+
/** External ID for tracking (e.g. ticket number, message ID). */
|
|
8
|
+
id?: string;
|
|
9
|
+
/** Same as `id` — accepted for backwards compatibility. */
|
|
10
|
+
externalId?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Runtime context exposed to inline integration scripts. `event.payload`
|
|
15
|
+
* is typed from the event's payload schema so the fields it advertises
|
|
16
|
+
* are autocompletable inside the script.
|
|
17
|
+
*/
|
|
18
|
+
interface IntegrationScriptContext {
|
|
19
|
+
/** The event being delivered. */
|
|
20
|
+
readonly event: {
|
|
21
|
+
/** Fully-qualified event ID, e.g. "incident.created". */
|
|
22
|
+
readonly eventId: string;
|
|
23
|
+
/** Strongly-typed event payload. */
|
|
24
|
+
readonly payload: Record<string, unknown>;
|
|
25
|
+
/** ISO-8601 timestamp of when the event was emitted. */
|
|
26
|
+
readonly timestamp: string;
|
|
27
|
+
/** Unique ID for this delivery attempt. */
|
|
28
|
+
readonly deliveryId: string;
|
|
29
|
+
};
|
|
30
|
+
/** Subscription that triggered this delivery. */
|
|
31
|
+
readonly subscription: {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export declare function defineIntegration<
|
|
38
|
+
T extends
|
|
39
|
+
| IntegrationScriptResult
|
|
40
|
+
| void
|
|
41
|
+
| ((ctx: IntegrationScriptContext) =>
|
|
42
|
+
| IntegrationScriptResult
|
|
43
|
+
| void
|
|
44
|
+
| Promise<IntegrationScriptResult | void>),
|
|
45
|
+
>(value: T): T;
|
|
46
|
+
|
|
47
|
+
export type { IntegrationScriptResult, IntegrationScriptContext };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
/** The platform release version this SDK was stamped to. */
|
|
6
|
+
export declare const SDK_RELEASE_VERSION: string;
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@checkstack/sdk",
|
|
3
|
+
"version": "0.94.0",
|
|
4
|
+
"license": "Elastic-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Auto-generated, version-pinned typed client and script-authoring helpers for Checkstack.",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./generated/index.d.ts",
|
|
10
|
+
"default": "./src/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"./healthcheck": {
|
|
13
|
+
"types": "./generated/healthcheck.d.ts",
|
|
14
|
+
"default": "./src/healthcheck.ts"
|
|
15
|
+
},
|
|
16
|
+
"./integration": {
|
|
17
|
+
"types": "./generated/integration.d.ts",
|
|
18
|
+
"default": "./src/integration.ts"
|
|
19
|
+
},
|
|
20
|
+
"./editor-bundle": {
|
|
21
|
+
"types": "./generated/editor-bundle-module.d.ts",
|
|
22
|
+
"default": "./src/editor-bundle.ts"
|
|
23
|
+
},
|
|
24
|
+
"./version": {
|
|
25
|
+
"types": "./generated/version.d.ts",
|
|
26
|
+
"default": "./src/version.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@checkstack/announcement-common": "0.4.2",
|
|
31
|
+
"@checkstack/anomaly-common": "1.2.3",
|
|
32
|
+
"@checkstack/auth-common": "0.7.2",
|
|
33
|
+
"@checkstack/automation-common": "0.3.0",
|
|
34
|
+
"@checkstack/cache-common": "0.4.2",
|
|
35
|
+
"@checkstack/catalog-common": "2.2.3",
|
|
36
|
+
"@checkstack/command-common": "0.2.14",
|
|
37
|
+
"@checkstack/common": "0.12.0",
|
|
38
|
+
"@checkstack/dependency-common": "1.1.3",
|
|
39
|
+
"@checkstack/gitops-common": "0.5.0",
|
|
40
|
+
"@checkstack/healthcheck-common": "1.4.0",
|
|
41
|
+
"@checkstack/incident-common": "1.3.1",
|
|
42
|
+
"@checkstack/integration-common": "0.6.0",
|
|
43
|
+
"@checkstack/maintenance-common": "1.3.0",
|
|
44
|
+
"@checkstack/notification-common": "1.2.1",
|
|
45
|
+
"@checkstack/pluginmanager-common": "0.2.4",
|
|
46
|
+
"@checkstack/queue-common": "0.5.2",
|
|
47
|
+
"@checkstack/satellite-common": "0.7.0",
|
|
48
|
+
"@checkstack/script-packages-common": "0.2.0",
|
|
49
|
+
"@checkstack/secrets-common": "0.1.0",
|
|
50
|
+
"@checkstack/slo-common": "0.4.2",
|
|
51
|
+
"@checkstack/theme-common": "0.1.14",
|
|
52
|
+
"@checkstack/tips-common": "0.2.3",
|
|
53
|
+
"@orpc/client": "^1.14.4",
|
|
54
|
+
"@orpc/openapi-client": "^1.14.3"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"typescript": "^5.7.2",
|
|
58
|
+
"@checkstack/tsconfig": "0.0.7",
|
|
59
|
+
"@checkstack/scripts": "0.3.4"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"typecheck": "tsgo -b",
|
|
63
|
+
"lint": "bun run lint:code",
|
|
64
|
+
"lint:code": "eslint . --max-warnings 0"
|
|
65
|
+
},
|
|
66
|
+
"checkstack": {
|
|
67
|
+
"type": "common"
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
import { createORPCClient } from "@orpc/client";
|
|
6
|
+
import { OpenAPILink } from "@orpc/openapi-client/fetch";
|
|
7
|
+
import type { InferClient } from "@checkstack/common";
|
|
8
|
+
import { AnnouncementApi } from "@checkstack/announcement-common";
|
|
9
|
+
import { AnomalyApi } from "@checkstack/anomaly-common";
|
|
10
|
+
import { AuthApi } from "@checkstack/auth-common";
|
|
11
|
+
import { AutomationApi } from "@checkstack/automation-common";
|
|
12
|
+
import { CacheApi } from "@checkstack/cache-common";
|
|
13
|
+
import { CatalogApi } from "@checkstack/catalog-common";
|
|
14
|
+
import { CommandApi } from "@checkstack/command-common";
|
|
15
|
+
import { DependencyApi } from "@checkstack/dependency-common";
|
|
16
|
+
import { GitOpsApi } from "@checkstack/gitops-common";
|
|
17
|
+
import { HealthCheckApi } from "@checkstack/healthcheck-common";
|
|
18
|
+
import { IncidentApi } from "@checkstack/incident-common";
|
|
19
|
+
import { IntegrationApi } from "@checkstack/integration-common";
|
|
20
|
+
import { MaintenanceApi } from "@checkstack/maintenance-common";
|
|
21
|
+
import { NotificationApi } from "@checkstack/notification-common";
|
|
22
|
+
import { PluginManagerApi } from "@checkstack/pluginmanager-common";
|
|
23
|
+
import { QueueApi } from "@checkstack/queue-common";
|
|
24
|
+
import { SatelliteApi } from "@checkstack/satellite-common";
|
|
25
|
+
import { ScriptPackagesApi } from "@checkstack/script-packages-common";
|
|
26
|
+
import { SecretsApi } from "@checkstack/secrets-common";
|
|
27
|
+
import { SloApi } from "@checkstack/slo-common";
|
|
28
|
+
import { ThemeApi } from "@checkstack/theme-common";
|
|
29
|
+
import { TipsApi } from "@checkstack/tips-common";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The fully-typed Checkstack API client. One entry per plugin id, mirroring
|
|
33
|
+
* the backend's root oRPC router nesting (`rootRpcRouter[pluginId]`). Each
|
|
34
|
+
* value is the contract's inferred client (`InferClient`).
|
|
35
|
+
*/
|
|
36
|
+
export interface CheckstackClient {
|
|
37
|
+
announcement: InferClient<typeof AnnouncementApi>;
|
|
38
|
+
anomaly: InferClient<typeof AnomalyApi>;
|
|
39
|
+
auth: InferClient<typeof AuthApi>;
|
|
40
|
+
automation: InferClient<typeof AutomationApi>;
|
|
41
|
+
cache: InferClient<typeof CacheApi>;
|
|
42
|
+
catalog: InferClient<typeof CatalogApi>;
|
|
43
|
+
command: InferClient<typeof CommandApi>;
|
|
44
|
+
dependency: InferClient<typeof DependencyApi>;
|
|
45
|
+
gitops: InferClient<typeof GitOpsApi>;
|
|
46
|
+
healthcheck: InferClient<typeof HealthCheckApi>;
|
|
47
|
+
incident: InferClient<typeof IncidentApi>;
|
|
48
|
+
integration: InferClient<typeof IntegrationApi>;
|
|
49
|
+
maintenance: InferClient<typeof MaintenanceApi>;
|
|
50
|
+
notification: InferClient<typeof NotificationApi>;
|
|
51
|
+
pluginmanager: InferClient<typeof PluginManagerApi>;
|
|
52
|
+
queue: InferClient<typeof QueueApi>;
|
|
53
|
+
satellite: InferClient<typeof SatelliteApi>;
|
|
54
|
+
"script-packages": InferClient<typeof ScriptPackagesApi>;
|
|
55
|
+
secrets: InferClient<typeof SecretsApi>;
|
|
56
|
+
slo: InferClient<typeof SloApi>;
|
|
57
|
+
theme: InferClient<typeof ThemeApi>;
|
|
58
|
+
tips: InferClient<typeof TipsApi>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Options for {@link createCheckstackClient}. */
|
|
62
|
+
export interface CreateCheckstackClientOptions {
|
|
63
|
+
/** Base URL of the Checkstack REST surface, e.g. `https://host/rest`. */
|
|
64
|
+
baseUrl: string;
|
|
65
|
+
/** Extra request headers, e.g. API-key / bearer auth. */
|
|
66
|
+
headers?: Record<string, string>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The nested contract router mirroring the backend's `/rest/:pluginId/*`
|
|
71
|
+
* surface. Passed to {@link OpenAPILink} so calls map to REST routes.
|
|
72
|
+
*/
|
|
73
|
+
const checkstackContract = {
|
|
74
|
+
announcement: AnnouncementApi.contract,
|
|
75
|
+
anomaly: AnomalyApi.contract,
|
|
76
|
+
auth: AuthApi.contract,
|
|
77
|
+
automation: AutomationApi.contract,
|
|
78
|
+
cache: CacheApi.contract,
|
|
79
|
+
catalog: CatalogApi.contract,
|
|
80
|
+
command: CommandApi.contract,
|
|
81
|
+
dependency: DependencyApi.contract,
|
|
82
|
+
gitops: GitOpsApi.contract,
|
|
83
|
+
healthcheck: HealthCheckApi.contract,
|
|
84
|
+
incident: IncidentApi.contract,
|
|
85
|
+
integration: IntegrationApi.contract,
|
|
86
|
+
maintenance: MaintenanceApi.contract,
|
|
87
|
+
notification: NotificationApi.contract,
|
|
88
|
+
pluginmanager: PluginManagerApi.contract,
|
|
89
|
+
queue: QueueApi.contract,
|
|
90
|
+
satellite: SatelliteApi.contract,
|
|
91
|
+
"script-packages": ScriptPackagesApi.contract,
|
|
92
|
+
secrets: SecretsApi.contract,
|
|
93
|
+
slo: SloApi.contract,
|
|
94
|
+
theme: ThemeApi.contract,
|
|
95
|
+
tips: TipsApi.contract,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Build a typed Checkstack client over the REST/OpenAPI surface
|
|
100
|
+
* (`/rest/:pluginId/*`). Each plugin is reachable under its plugin id.
|
|
101
|
+
*/
|
|
102
|
+
export function createCheckstackClient({
|
|
103
|
+
baseUrl,
|
|
104
|
+
headers,
|
|
105
|
+
}: CreateCheckstackClientOptions): CheckstackClient {
|
|
106
|
+
// Strip trailing slashes without a backtracking-prone regex
|
|
107
|
+
// (`/\/+$/` is O(n^2) on inputs like "////...x" - CodeQL js/polynomial-redos).
|
|
108
|
+
let normalizedBase = baseUrl;
|
|
109
|
+
while (normalizedBase.endsWith("/")) normalizedBase = normalizedBase.slice(0, -1);
|
|
110
|
+
const link = new OpenAPILink(checkstackContract, {
|
|
111
|
+
url: normalizedBase,
|
|
112
|
+
headers: () => headers ?? {},
|
|
113
|
+
});
|
|
114
|
+
// oRPC's `createORPCClient` constrains its type param to an index-signature
|
|
115
|
+
// `NestedClient`, which a fixed-key interface like `CheckstackClient` cannot
|
|
116
|
+
// satisfy structurally. The runtime client IS the CheckstackClient shape
|
|
117
|
+
// (one entry per plugin contract), so cast through the oRPC-inferred client.
|
|
118
|
+
// Mirrors core/frontend/src/apis/rpc-api.ts.
|
|
119
|
+
return createORPCClient(link) as unknown as CheckstackClient;
|
|
120
|
+
}
|
package/src/contracts.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Re-export of every per-plugin oRPC contract `ClientDefinition`. Each is
|
|
7
|
+
* the source-of-truth API surface the running backend serves at
|
|
8
|
+
* `/rest/:pluginId/*`.
|
|
9
|
+
*/
|
|
10
|
+
export { AnnouncementApi } from "@checkstack/announcement-common";
|
|
11
|
+
export { AnomalyApi } from "@checkstack/anomaly-common";
|
|
12
|
+
export { AuthApi } from "@checkstack/auth-common";
|
|
13
|
+
export { AutomationApi } from "@checkstack/automation-common";
|
|
14
|
+
export { CacheApi } from "@checkstack/cache-common";
|
|
15
|
+
export { CatalogApi } from "@checkstack/catalog-common";
|
|
16
|
+
export { CommandApi } from "@checkstack/command-common";
|
|
17
|
+
export { DependencyApi } from "@checkstack/dependency-common";
|
|
18
|
+
export { GitOpsApi } from "@checkstack/gitops-common";
|
|
19
|
+
export { HealthCheckApi } from "@checkstack/healthcheck-common";
|
|
20
|
+
export { IncidentApi } from "@checkstack/incident-common";
|
|
21
|
+
export { IntegrationApi } from "@checkstack/integration-common";
|
|
22
|
+
export { MaintenanceApi } from "@checkstack/maintenance-common";
|
|
23
|
+
export { NotificationApi } from "@checkstack/notification-common";
|
|
24
|
+
export { PluginManagerApi } from "@checkstack/pluginmanager-common";
|
|
25
|
+
export { QueueApi } from "@checkstack/queue-common";
|
|
26
|
+
export { SatelliteApi } from "@checkstack/satellite-common";
|
|
27
|
+
export { ScriptPackagesApi } from "@checkstack/script-packages-common";
|
|
28
|
+
export { SecretsApi } from "@checkstack/secrets-common";
|
|
29
|
+
export { SloApi } from "@checkstack/slo-common";
|
|
30
|
+
export { ThemeApi } from "@checkstack/theme-common";
|
|
31
|
+
export { TipsApi } from "@checkstack/tips-common";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
// Runtime-importable copy of the editor bundle, served by the
|
|
6
|
+
// @checkstack/sdk editor-types backend route (plan §6.1). Imported by
|
|
7
|
+
// the BACKEND only - it embeds the full bundle text, which the frontend
|
|
8
|
+
// must NOT bundle (it fetches the bundle live; see ./version.ts).
|
|
9
|
+
|
|
10
|
+
/** The combined ambient `.d.ts` the in-app editor mounts into Monaco. */
|
|
11
|
+
export const SDK_EDITOR_BUNDLE_DTS = "// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.\n// Run `bun run generate:sdk` after changing a *-common contract or the\n// script-context helper builders.\n\n// Combined ambient declarations served ONLY by the version-keyed editor\n// route and mounted into Monaco. NOT the `exports`-resolved declarations\n// (those are the per-subpath generated/*.d.ts). Declares the subpath module\n// names only - bare names are intentionally absent so an old import errors.\n//\n// Every declaration is module-scoped (no top-level globals): the editor\n// mounts this bundle alongside scriptContext.ts, which owns the global\n// `defineHealthCheck` / `defineIntegration` + schema-narrowed context types\n// (plan §6.2). Top-level globals here would duplicate those and error.\n\ndeclare module \"@checkstack/sdk/healthcheck\" {\n /** Result emitted by an inline health-check script. */\n interface HealthCheckScriptResult {\n /** Whether the health check passed. */\n success: boolean;\n /** Optional status message — surfaces in the run detail. */\n message?: string;\n /** Optional numeric value — feeds the value chart + anomaly detection. */\n value?: number;\n }\n\n /**\n * Runtime context exposed to inline health-check scripts. `config` is\n * typed from the collector's own JSON Schema, so the fields you've\n * declared on the configuration are autocompletable inside the script.\n */\n interface HealthCheckScriptContext {\n /** Strongly-typed collector configuration. */\n readonly config: Record<string, unknown>;\n /** Metadata about the health check this run is for. */\n readonly check: {\n /** The health check configuration id. */\n readonly id: string;\n /** The health check's display name (falls back to the id). */\n readonly name: string;\n /** The configured run interval, in seconds. */\n readonly intervalSeconds: number;\n };\n /** Metadata about the system this check runs for. */\n readonly system: {\n /** The system id. */\n readonly id: string;\n /** The system's display name (falls back to the id). */\n readonly name: string;\n };\n }\n\n export function defineHealthCheck<\n T extends\n | HealthCheckScriptResult\n | ((ctx: HealthCheckScriptContext) =>\n | HealthCheckScriptResult\n | Promise<HealthCheckScriptResult>),\n >(value: T): T;\n export type { HealthCheckScriptResult, HealthCheckScriptContext };\n}\n\ndeclare module \"@checkstack/sdk/integration\" {\n /** Result emitted by an inline integration script. */\n interface IntegrationScriptResult {\n /** External ID for tracking (e.g. ticket number, message ID). */\n id?: string;\n /** Same as `id` — accepted for backwards compatibility. */\n externalId?: string;\n }\n\n /**\n * Runtime context exposed to inline integration scripts. `event.payload`\n * is typed from the event's payload schema so the fields it advertises\n * are autocompletable inside the script.\n */\n interface IntegrationScriptContext {\n /** The event being delivered. */\n readonly event: {\n /** Fully-qualified event ID, e.g. \"incident.created\". */\n readonly eventId: string;\n /** Strongly-typed event payload. */\n readonly payload: Record<string, unknown>;\n /** ISO-8601 timestamp of when the event was emitted. */\n readonly timestamp: string;\n /** Unique ID for this delivery attempt. */\n readonly deliveryId: string;\n };\n /** Subscription that triggered this delivery. */\n readonly subscription: {\n readonly id: string;\n readonly name: string;\n };\n }\n\n export function defineIntegration<\n T extends\n | IntegrationScriptResult\n | void\n | ((ctx: IntegrationScriptContext) =>\n | IntegrationScriptResult\n | void\n | Promise<IntegrationScriptResult | void>),\n >(value: T): T;\n export type { IntegrationScriptResult, IntegrationScriptContext };\n}\n\ndeclare module \"@checkstack/sdk\" {\n export { defineHealthCheck } from \"@checkstack/sdk/healthcheck\";\n export type { HealthCheckScriptResult, HealthCheckScriptContext } from \"@checkstack/sdk/healthcheck\";\n export { defineIntegration } from \"@checkstack/sdk/integration\";\n export type { IntegrationScriptResult, IntegrationScriptContext } from \"@checkstack/sdk/integration\";\n export interface CreateCheckstackClientOptions {\n baseUrl: string;\n headers?: Record<string, string>;\n }\n /** The fully-typed Checkstack API client (one entry per plugin id). */\n export type CheckstackClient = Record<string, unknown>;\n /** Build a typed Checkstack client over the REST/OpenAPI surface. */\n export function createCheckstackClient(\n options: CreateCheckstackClientOptions,\n ): CheckstackClient;\n}\n";
|
|
12
|
+
|
|
13
|
+
export { SDK_RELEASE_VERSION } from "./version.ts";
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
/** Result emitted by an inline health-check script. */
|
|
6
|
+
interface HealthCheckScriptResult {
|
|
7
|
+
/** Whether the health check passed. */
|
|
8
|
+
success: boolean;
|
|
9
|
+
/** Optional status message — surfaces in the run detail. */
|
|
10
|
+
message?: string;
|
|
11
|
+
/** Optional numeric value — feeds the value chart + anomaly detection. */
|
|
12
|
+
value?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Runtime context exposed to inline health-check scripts. `config` is
|
|
17
|
+
* typed from the collector's own JSON Schema, so the fields you've
|
|
18
|
+
* declared on the configuration are autocompletable inside the script.
|
|
19
|
+
*/
|
|
20
|
+
interface HealthCheckScriptContext {
|
|
21
|
+
/** Strongly-typed collector configuration. */
|
|
22
|
+
readonly config: Record<string, unknown>;
|
|
23
|
+
/** Metadata about the health check this run is for. */
|
|
24
|
+
readonly check: {
|
|
25
|
+
/** The health check configuration id. */
|
|
26
|
+
readonly id: string;
|
|
27
|
+
/** The health check's display name (falls back to the id). */
|
|
28
|
+
readonly name: string;
|
|
29
|
+
/** The configured run interval, in seconds. */
|
|
30
|
+
readonly intervalSeconds: number;
|
|
31
|
+
};
|
|
32
|
+
/** Metadata about the system this check runs for. */
|
|
33
|
+
readonly system: {
|
|
34
|
+
/** The system id. */
|
|
35
|
+
readonly id: string;
|
|
36
|
+
/** The system's display name (falls back to the id). */
|
|
37
|
+
readonly name: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type { HealthCheckScriptResult, HealthCheckScriptContext };
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Identity helper for defineHealthCheck scripts. The value is returned unchanged at
|
|
45
|
+
* runtime - the function only narrows what `export default` may be so
|
|
46
|
+
* mistakes are caught before the script runs. Matches the in-app runner's
|
|
47
|
+
* injected helper body exactly (esm-script-runner identity rewrite).
|
|
48
|
+
*/
|
|
49
|
+
export function defineHealthCheck<
|
|
50
|
+
T extends
|
|
51
|
+
| HealthCheckScriptResult
|
|
52
|
+
| ((ctx: HealthCheckScriptContext) =>
|
|
53
|
+
| HealthCheckScriptResult
|
|
54
|
+
| Promise<HealthCheckScriptResult>),
|
|
55
|
+
>(value: T): T {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
export * from "./contracts.ts";
|
|
6
|
+
export * from "./client.ts";
|
|
7
|
+
export * from "./healthcheck.ts";
|
|
8
|
+
export * from "./integration.ts";
|
|
9
|
+
export type { InferClient, ClientDefinition } from "@checkstack/common";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
/** Result emitted by an inline integration script. */
|
|
6
|
+
interface IntegrationScriptResult {
|
|
7
|
+
/** External ID for tracking (e.g. ticket number, message ID). */
|
|
8
|
+
id?: string;
|
|
9
|
+
/** Same as `id` — accepted for backwards compatibility. */
|
|
10
|
+
externalId?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Runtime context exposed to inline integration scripts. `event.payload`
|
|
15
|
+
* is typed from the event's payload schema so the fields it advertises
|
|
16
|
+
* are autocompletable inside the script.
|
|
17
|
+
*/
|
|
18
|
+
interface IntegrationScriptContext {
|
|
19
|
+
/** The event being delivered. */
|
|
20
|
+
readonly event: {
|
|
21
|
+
/** Fully-qualified event ID, e.g. "incident.created". */
|
|
22
|
+
readonly eventId: string;
|
|
23
|
+
/** Strongly-typed event payload. */
|
|
24
|
+
readonly payload: Record<string, unknown>;
|
|
25
|
+
/** ISO-8601 timestamp of when the event was emitted. */
|
|
26
|
+
readonly timestamp: string;
|
|
27
|
+
/** Unique ID for this delivery attempt. */
|
|
28
|
+
readonly deliveryId: string;
|
|
29
|
+
};
|
|
30
|
+
/** Subscription that triggered this delivery. */
|
|
31
|
+
readonly subscription: {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type { IntegrationScriptResult, IntegrationScriptContext };
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Identity helper for defineIntegration scripts. The value is returned unchanged at
|
|
41
|
+
* runtime - the function only narrows what `export default` may be so
|
|
42
|
+
* mistakes are caught before the script runs. Matches the in-app runner's
|
|
43
|
+
* injected helper body exactly (esm-script-runner identity rewrite).
|
|
44
|
+
*/
|
|
45
|
+
export function defineIntegration<
|
|
46
|
+
T extends
|
|
47
|
+
| IntegrationScriptResult
|
|
48
|
+
| void
|
|
49
|
+
| ((ctx: IntegrationScriptContext) =>
|
|
50
|
+
| IntegrationScriptResult
|
|
51
|
+
| void
|
|
52
|
+
| Promise<IntegrationScriptResult | void>),
|
|
53
|
+
>(value: T): T {
|
|
54
|
+
return value;
|
|
55
|
+
}
|
package/src/version.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate-sdk.ts - DO NOT EDIT BY HAND.
|
|
2
|
+
// Run `bun run generate:sdk` after changing a *-common contract or the
|
|
3
|
+
// script-context helper builders.
|
|
4
|
+
|
|
5
|
+
/** The platform release version this SDK was stamped to. */
|
|
6
|
+
export const SDK_RELEASE_VERSION = "0.94.0";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { createCheckstackClient } from "../src/client.ts";
|
|
3
|
+
import { defineHealthCheck } from "../src/healthcheck.ts";
|
|
4
|
+
import { defineIntegration } from "../src/integration.ts";
|
|
5
|
+
|
|
6
|
+
describe("createCheckstackClient", () => {
|
|
7
|
+
test("builds a client with one entry per plugin id", () => {
|
|
8
|
+
const client = createCheckstackClient({ baseUrl: "https://host/rest" });
|
|
9
|
+
|
|
10
|
+
// A representative spread across the plugin surface, including the
|
|
11
|
+
// hyphenated id which must be a quoted key.
|
|
12
|
+
expect(client.healthcheck).toBeDefined();
|
|
13
|
+
expect(client.integration).toBeDefined();
|
|
14
|
+
expect(client.automation).toBeDefined();
|
|
15
|
+
expect(client["script-packages"]).toBeDefined();
|
|
16
|
+
expect(client.auth).toBeDefined();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("accepts custom headers without throwing", () => {
|
|
20
|
+
const client = createCheckstackClient({
|
|
21
|
+
baseUrl: "https://host/rest/",
|
|
22
|
+
headers: { authorization: "Bearer token" },
|
|
23
|
+
});
|
|
24
|
+
expect(client.tips).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("script helpers (identity runtime)", () => {
|
|
29
|
+
test("defineHealthCheck returns its argument unchanged", () => {
|
|
30
|
+
const result = { success: true, value: 42 };
|
|
31
|
+
expect(defineHealthCheck(result)).toBe(result);
|
|
32
|
+
|
|
33
|
+
const fn = () => ({ success: false, message: "down" });
|
|
34
|
+
expect(defineHealthCheck(fn)).toBe(fn);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("defineIntegration returns its argument unchanged", () => {
|
|
38
|
+
const result = { id: "ticket-1" };
|
|
39
|
+
expect(defineIntegration(result)).toBe(result);
|
|
40
|
+
|
|
41
|
+
const fn = async () => ({ externalId: "x" });
|
|
42
|
+
expect(defineIntegration(fn)).toBe(fn);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Fixture (NEGATIVE): proves per-subpath isolation. `defineIntegration` is
|
|
2
|
+
// NOT part of the `@checkstack/sdk/healthcheck` surface, so importing it from
|
|
3
|
+
// that subpath MUST be a resolution/type error (TS2305). If this ever
|
|
4
|
+
// compiles, the subpaths are sharing a declaration file and the per-subpath
|
|
5
|
+
// `.d.ts` guarantee is broken.
|
|
6
|
+
import { defineIntegration } from "@checkstack/sdk/healthcheck";
|
|
7
|
+
|
|
8
|
+
export const x = defineIntegration;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Fixture: an external consumer importing the self-contained helper subpaths.
|
|
2
|
+
// Under `nodenext`/`node16` module resolution, each subpath MUST resolve
|
|
3
|
+
// through the package's `exports` map to its OWN per-subpath `.d.ts`
|
|
4
|
+
// (generated/healthcheck.d.ts, generated/integration.d.ts) — not a shared
|
|
5
|
+
// ambient file. This file MUST typecheck cleanly.
|
|
6
|
+
import {
|
|
7
|
+
defineHealthCheck,
|
|
8
|
+
type HealthCheckScriptContext,
|
|
9
|
+
type HealthCheckScriptResult,
|
|
10
|
+
} from "@checkstack/sdk/healthcheck";
|
|
11
|
+
import {
|
|
12
|
+
defineIntegration,
|
|
13
|
+
type IntegrationScriptContext,
|
|
14
|
+
type IntegrationScriptResult,
|
|
15
|
+
} from "@checkstack/sdk/integration";
|
|
16
|
+
|
|
17
|
+
const hcResult: HealthCheckScriptResult = { success: true, value: 1 };
|
|
18
|
+
const intgResult: IntegrationScriptResult = { id: "x" };
|
|
19
|
+
|
|
20
|
+
export const hc = defineHealthCheck((ctx: HealthCheckScriptContext) => ({
|
|
21
|
+
success: ctx.check.intervalSeconds > 0,
|
|
22
|
+
value: hcResult.value,
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
export const intg = defineIntegration((ctx: IntegrationScriptContext) => ({
|
|
26
|
+
id: ctx.event.deliveryId,
|
|
27
|
+
externalId: intgResult.id,
|
|
28
|
+
}));
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import {
|
|
4
|
+
mkdirSync,
|
|
5
|
+
mkdtempSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
symlinkSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
} from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* LOAD-BEARING resolution test (plan §4.1, §9 Phase-1 row 4).
|
|
15
|
+
*
|
|
16
|
+
* Asserts that under `nodenext` module resolution an external consumer
|
|
17
|
+
* resolves `@checkstack/sdk/healthcheck` and `@checkstack/sdk/integration`
|
|
18
|
+
* through the package's `exports` map to EXACTLY their own per-subpath
|
|
19
|
+
* `.d.ts` — not a shared ambient file. The negative fixture proves the two
|
|
20
|
+
* subpaths do not bleed into each other.
|
|
21
|
+
*
|
|
22
|
+
* The package is symlinked into a temp `node_modules/@checkstack/sdk` so the
|
|
23
|
+
* REAL `exports` map drives resolution (a `paths` mapping would bypass it and
|
|
24
|
+
* defeat the test).
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const REPO_ROOT = path.resolve(import.meta.dirname, "..", "..", "..");
|
|
28
|
+
const SDK_PKG_DIR = path.resolve(import.meta.dirname, "..");
|
|
29
|
+
const FIXTURES_DIR = path.join(import.meta.dirname, "fixtures");
|
|
30
|
+
const TSC = path.join(REPO_ROOT, "node_modules", ".bin", "tsc");
|
|
31
|
+
|
|
32
|
+
const NODENEXT_COMPILER_OPTIONS = {
|
|
33
|
+
module: "nodenext",
|
|
34
|
+
moduleResolution: "nodenext",
|
|
35
|
+
target: "esnext",
|
|
36
|
+
strict: true,
|
|
37
|
+
noEmit: true,
|
|
38
|
+
skipLibCheck: true,
|
|
39
|
+
// No ambient libs — the subpath `.d.ts` must stand alone.
|
|
40
|
+
types: [] as string[],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
let workDir: string;
|
|
44
|
+
|
|
45
|
+
function runTsc({
|
|
46
|
+
consumer,
|
|
47
|
+
tsconfigName,
|
|
48
|
+
}: {
|
|
49
|
+
consumer: string;
|
|
50
|
+
tsconfigName: string;
|
|
51
|
+
}) {
|
|
52
|
+
const tsconfigPath = path.join(workDir, tsconfigName);
|
|
53
|
+
writeFileSync(
|
|
54
|
+
tsconfigPath,
|
|
55
|
+
JSON.stringify(
|
|
56
|
+
{
|
|
57
|
+
compilerOptions: NODENEXT_COMPILER_OPTIONS,
|
|
58
|
+
include: [consumer],
|
|
59
|
+
},
|
|
60
|
+
undefined,
|
|
61
|
+
2,
|
|
62
|
+
),
|
|
63
|
+
"utf8",
|
|
64
|
+
);
|
|
65
|
+
return spawnSync(TSC, ["-p", tsconfigPath], {
|
|
66
|
+
cwd: workDir,
|
|
67
|
+
encoding: "utf8",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
beforeAll(() => {
|
|
72
|
+
workDir = mkdtempSync(path.join(tmpdir(), "checkstack-sdk-resolution-"));
|
|
73
|
+
mkdirSync(path.join(workDir, "node_modules", "@checkstack"), {
|
|
74
|
+
recursive: true,
|
|
75
|
+
});
|
|
76
|
+
symlinkSync(
|
|
77
|
+
SDK_PKG_DIR,
|
|
78
|
+
path.join(workDir, "node_modules", "@checkstack", "sdk"),
|
|
79
|
+
"dir",
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
afterAll(() => {
|
|
84
|
+
if (workDir) rmSync(workDir, { recursive: true, force: true });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("@checkstack/sdk subpath exports (nodenext)", () => {
|
|
88
|
+
test("healthcheck + integration subpaths resolve to their own surface", async () => {
|
|
89
|
+
// Materialize fixture contents synchronously for tsc.
|
|
90
|
+
writeFileSync(
|
|
91
|
+
path.join(workDir, "consumer-good.ts"),
|
|
92
|
+
await Bun.file(path.join(FIXTURES_DIR, "consumer-good.ts")).text(),
|
|
93
|
+
"utf8",
|
|
94
|
+
);
|
|
95
|
+
const result = runTsc({
|
|
96
|
+
consumer: "consumer-good.ts",
|
|
97
|
+
tsconfigName: "tsconfig.good.json",
|
|
98
|
+
});
|
|
99
|
+
if (result.status !== 0) {
|
|
100
|
+
console.error(result.stdout, result.stderr);
|
|
101
|
+
}
|
|
102
|
+
expect(result.status).toBe(0);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("importing a foreign helper from a subpath is a resolution error", async () => {
|
|
106
|
+
writeFileSync(
|
|
107
|
+
path.join(workDir, "consumer-cross-subpath.ts"),
|
|
108
|
+
await Bun.file(
|
|
109
|
+
path.join(FIXTURES_DIR, "consumer-cross-subpath.ts"),
|
|
110
|
+
).text(),
|
|
111
|
+
"utf8",
|
|
112
|
+
);
|
|
113
|
+
const result = runTsc({
|
|
114
|
+
consumer: "consumer-cross-subpath.ts",
|
|
115
|
+
tsconfigName: "tsconfig.cross.json",
|
|
116
|
+
});
|
|
117
|
+
expect(result.status).not.toBe(0);
|
|
118
|
+
// TS2305: Module has no exported member 'defineIntegration'.
|
|
119
|
+
expect(result.stdout + result.stderr).toContain("defineIntegration");
|
|
120
|
+
});
|
|
121
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@checkstack/tsconfig/common.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"src",
|
|
5
|
+
"generated"
|
|
6
|
+
],
|
|
7
|
+
"references": [
|
|
8
|
+
{
|
|
9
|
+
"path": "../announcement-common"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "../anomaly-common"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "../auth-common"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "../automation-common"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"path": "../cache-common"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../catalog-common"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../command-common"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "../common"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"path": "../dependency-common"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "../gitops-common"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"path": "../healthcheck-common"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "../incident-common"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"path": "../integration-common"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "../maintenance-common"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"path": "../notification-common"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "../pluginmanager-common"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"path": "../queue-common"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "../satellite-common"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"path": "../script-packages-common"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "../secrets-common"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"path": "../slo-common"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "../theme-common"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"path": "../tips-common"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|