@zysec-ai/cpod-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +96 -0
- package/README.md +315 -0
- package/bin/.env.example +21 -0
- package/bin/cpod-mcp-server.mjs +134 -0
- package/dist/client-BRW4z8Ls.d.mts +1073 -0
- package/dist/client-BRW4z8Ls.d.ts +1073 -0
- package/dist/events/index.d.mts +139 -0
- package/dist/events/index.d.ts +139 -0
- package/dist/events/index.js +112 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/index.mjs +109 -0
- package/dist/events/index.mjs.map +1 -0
- package/dist/index.d.mts +6224 -0
- package/dist/index.d.ts +6224 -0
- package/dist/index.js +8272 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8081 -0
- package/dist/index.mjs.map +1 -0
- package/dist/pods/index.d.mts +116 -0
- package/dist/pods/index.d.ts +116 -0
- package/dist/pods/index.js +108 -0
- package/dist/pods/index.js.map +1 -0
- package/dist/pods/index.mjs +106 -0
- package/dist/pods/index.mjs.map +1 -0
- package/dist/tenants/index.d.mts +69 -0
- package/dist/tenants/index.d.ts +69 -0
- package/dist/tenants/index.js +85 -0
- package/dist/tenants/index.js.map +1 -0
- package/dist/tenants/index.mjs +82 -0
- package/dist/tenants/index.mjs.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { V as PaginationOptions, O as HttpClient, ac as RequestOptions, a as ApiResponse } from '../client-BRW4z8Ls.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Well-known event type strings emitted by the cPod platform.
|
|
5
|
+
* Additional event types may be emitted for enterprise features — use string
|
|
6
|
+
* literals for those until they are added to this enum.
|
|
7
|
+
*/
|
|
8
|
+
declare enum EventType {
|
|
9
|
+
PodCreated = "pod.created",
|
|
10
|
+
PodUpdated = "pod.updated",
|
|
11
|
+
PodDeleted = "pod.deleted",
|
|
12
|
+
PodStatusChanged = "pod.status_changed",
|
|
13
|
+
PodStarted = "pod.started",
|
|
14
|
+
PodStopped = "pod.stopped",
|
|
15
|
+
PodFailed = "pod.failed",
|
|
16
|
+
OrganizationCreated = "organization.created",
|
|
17
|
+
OrganizationUpdated = "organization.updated",
|
|
18
|
+
OrganizationArchived = "organization.archived",
|
|
19
|
+
OrganizationMemberAdded = "organization.member_added",
|
|
20
|
+
OrganizationMemberRemoved = "organization.member_removed",
|
|
21
|
+
WorkspaceCreated = "workspace.created",
|
|
22
|
+
WorkspaceUpdated = "workspace.updated",
|
|
23
|
+
WorkspaceArchived = "workspace.archived",
|
|
24
|
+
CredentialCreated = "credential.created",
|
|
25
|
+
CredentialRevoked = "credential.revoked",
|
|
26
|
+
CredentialExpired = "credential.expired",
|
|
27
|
+
PolicyCreated = "policy.created",
|
|
28
|
+
PolicyUpdated = "policy.updated",
|
|
29
|
+
PolicyDeleted = "policy.deleted",
|
|
30
|
+
UserSuspended = "user.suspended",
|
|
31
|
+
UserReactivated = "user.reactivated"
|
|
32
|
+
}
|
|
33
|
+
/** A platform event delivered to subscribers or returned from event history. */
|
|
34
|
+
interface CpodEvent {
|
|
35
|
+
/** Unique event identifier (UUID). */
|
|
36
|
+
id: string;
|
|
37
|
+
/** Dot-notation event type (e.g., 'pod.created', 'credential.revoked'). */
|
|
38
|
+
type: EventType | string;
|
|
39
|
+
/** UUID of the Organization in whose context this event occurred. */
|
|
40
|
+
organizationId: string;
|
|
41
|
+
/** UUID of the Workspace, if this event is workspace-scoped. */
|
|
42
|
+
workspaceId?: string;
|
|
43
|
+
/** UUID of the specific resource affected. */
|
|
44
|
+
resourceId: string;
|
|
45
|
+
/** Entity type of the resource (e.g., 'Pod', 'Credential'). */
|
|
46
|
+
resourceType: string;
|
|
47
|
+
/** Event-specific payload. Shape varies by event type. */
|
|
48
|
+
payload: Record<string, unknown>;
|
|
49
|
+
/** ISO 8601 timestamp of when the event occurred. */
|
|
50
|
+
timestamp: string;
|
|
51
|
+
/** Schema version of the payload (e.g., '1.0'). */
|
|
52
|
+
version: string;
|
|
53
|
+
}
|
|
54
|
+
/** Filter criteria for event subscriptions and history queries. */
|
|
55
|
+
interface EventFilter {
|
|
56
|
+
/** Filter to events in a specific Organization. */
|
|
57
|
+
organizationId?: string;
|
|
58
|
+
/** Filter to events in a specific Workspace. */
|
|
59
|
+
workspaceId?: string;
|
|
60
|
+
/** Filter to events affecting a specific resource type. */
|
|
61
|
+
resourceType?: string;
|
|
62
|
+
/** Filter to events affecting a specific resource UUID. */
|
|
63
|
+
resourceId?: string;
|
|
64
|
+
/** Filter to specific event types. */
|
|
65
|
+
types?: Array<EventType | string>;
|
|
66
|
+
}
|
|
67
|
+
/** Options for subscribing to real-time events. */
|
|
68
|
+
interface SubscribeOptions {
|
|
69
|
+
/** Replay events that occurred after this ISO 8601 timestamp. */
|
|
70
|
+
since?: string;
|
|
71
|
+
}
|
|
72
|
+
/** Options for querying historical events. */
|
|
73
|
+
interface EventHistoryOptions extends PaginationOptions {
|
|
74
|
+
/** Filter to a specific Organization. */
|
|
75
|
+
organizationId?: string;
|
|
76
|
+
/** Filter to a specific Workspace. */
|
|
77
|
+
workspaceId?: string;
|
|
78
|
+
/** Filter to events affecting a specific resource type. */
|
|
79
|
+
resourceType?: string;
|
|
80
|
+
/** Filter to events affecting a specific resource UUID. */
|
|
81
|
+
resourceId?: string;
|
|
82
|
+
/** Filter to specific event types. */
|
|
83
|
+
types?: Array<EventType | string>;
|
|
84
|
+
/** Return only events after this ISO 8601 timestamp. */
|
|
85
|
+
since?: string;
|
|
86
|
+
/** Return only events before this ISO 8601 timestamp. */
|
|
87
|
+
until?: string;
|
|
88
|
+
}
|
|
89
|
+
/** Callback invoked when a matching event is received. */
|
|
90
|
+
type EventHandler = (event: CpodEvent) => void;
|
|
91
|
+
/** Handle returned by `EventService.subscribe()`. */
|
|
92
|
+
interface Subscription {
|
|
93
|
+
/** Stop receiving events for this subscription. */
|
|
94
|
+
unsubscribe(): void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Manages event subscriptions and history for cPod resources.
|
|
99
|
+
*
|
|
100
|
+
* Subscriptions use a poll-based EventEmitter-like pattern over the REST API.
|
|
101
|
+
* For real-time SSE, the server must expose a `/api/v1/events/stream` endpoint.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const sub = client.events.subscribe(
|
|
106
|
+
* { organizationId: "b2c3d4e5-...", types: ["pod.failed"] },
|
|
107
|
+
* (event) => {
|
|
108
|
+
* console.log("Pod failed:", event.resourceId, event.payload);
|
|
109
|
+
* }
|
|
110
|
+
* );
|
|
111
|
+
*
|
|
112
|
+
* // Later, stop receiving events:
|
|
113
|
+
* sub.unsubscribe();
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare class EventService {
|
|
117
|
+
private readonly http;
|
|
118
|
+
private readonly listeners;
|
|
119
|
+
constructor(http: HttpClient);
|
|
120
|
+
/**
|
|
121
|
+
* Subscribe to events matching the given filter.
|
|
122
|
+
* The handler is called for each matching event received.
|
|
123
|
+
*
|
|
124
|
+
* Returns a Subscription handle — call `.unsubscribe()` to stop.
|
|
125
|
+
*/
|
|
126
|
+
subscribe(filter: EventFilter, handler: EventHandler, _opts?: SubscribeOptions): Subscription;
|
|
127
|
+
/**
|
|
128
|
+
* Dispatch a raw event object to all matching subscribers.
|
|
129
|
+
* Typically called internally when processing SSE or webhook payloads.
|
|
130
|
+
*/
|
|
131
|
+
dispatch(event: CpodEvent): void;
|
|
132
|
+
/**
|
|
133
|
+
* Retrieve historical events from the API.
|
|
134
|
+
*/
|
|
135
|
+
getHistory(opts?: EventHistoryOptions, requestOpts?: RequestOptions): Promise<ApiResponse<CpodEvent[]>>;
|
|
136
|
+
private matchesFilter;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { type CpodEvent, type EventFilter, type EventHandler, type EventHistoryOptions, EventService, EventType, type SubscribeOptions, type Subscription };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { V as PaginationOptions, O as HttpClient, ac as RequestOptions, a as ApiResponse } from '../client-BRW4z8Ls.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Well-known event type strings emitted by the cPod platform.
|
|
5
|
+
* Additional event types may be emitted for enterprise features — use string
|
|
6
|
+
* literals for those until they are added to this enum.
|
|
7
|
+
*/
|
|
8
|
+
declare enum EventType {
|
|
9
|
+
PodCreated = "pod.created",
|
|
10
|
+
PodUpdated = "pod.updated",
|
|
11
|
+
PodDeleted = "pod.deleted",
|
|
12
|
+
PodStatusChanged = "pod.status_changed",
|
|
13
|
+
PodStarted = "pod.started",
|
|
14
|
+
PodStopped = "pod.stopped",
|
|
15
|
+
PodFailed = "pod.failed",
|
|
16
|
+
OrganizationCreated = "organization.created",
|
|
17
|
+
OrganizationUpdated = "organization.updated",
|
|
18
|
+
OrganizationArchived = "organization.archived",
|
|
19
|
+
OrganizationMemberAdded = "organization.member_added",
|
|
20
|
+
OrganizationMemberRemoved = "organization.member_removed",
|
|
21
|
+
WorkspaceCreated = "workspace.created",
|
|
22
|
+
WorkspaceUpdated = "workspace.updated",
|
|
23
|
+
WorkspaceArchived = "workspace.archived",
|
|
24
|
+
CredentialCreated = "credential.created",
|
|
25
|
+
CredentialRevoked = "credential.revoked",
|
|
26
|
+
CredentialExpired = "credential.expired",
|
|
27
|
+
PolicyCreated = "policy.created",
|
|
28
|
+
PolicyUpdated = "policy.updated",
|
|
29
|
+
PolicyDeleted = "policy.deleted",
|
|
30
|
+
UserSuspended = "user.suspended",
|
|
31
|
+
UserReactivated = "user.reactivated"
|
|
32
|
+
}
|
|
33
|
+
/** A platform event delivered to subscribers or returned from event history. */
|
|
34
|
+
interface CpodEvent {
|
|
35
|
+
/** Unique event identifier (UUID). */
|
|
36
|
+
id: string;
|
|
37
|
+
/** Dot-notation event type (e.g., 'pod.created', 'credential.revoked'). */
|
|
38
|
+
type: EventType | string;
|
|
39
|
+
/** UUID of the Organization in whose context this event occurred. */
|
|
40
|
+
organizationId: string;
|
|
41
|
+
/** UUID of the Workspace, if this event is workspace-scoped. */
|
|
42
|
+
workspaceId?: string;
|
|
43
|
+
/** UUID of the specific resource affected. */
|
|
44
|
+
resourceId: string;
|
|
45
|
+
/** Entity type of the resource (e.g., 'Pod', 'Credential'). */
|
|
46
|
+
resourceType: string;
|
|
47
|
+
/** Event-specific payload. Shape varies by event type. */
|
|
48
|
+
payload: Record<string, unknown>;
|
|
49
|
+
/** ISO 8601 timestamp of when the event occurred. */
|
|
50
|
+
timestamp: string;
|
|
51
|
+
/** Schema version of the payload (e.g., '1.0'). */
|
|
52
|
+
version: string;
|
|
53
|
+
}
|
|
54
|
+
/** Filter criteria for event subscriptions and history queries. */
|
|
55
|
+
interface EventFilter {
|
|
56
|
+
/** Filter to events in a specific Organization. */
|
|
57
|
+
organizationId?: string;
|
|
58
|
+
/** Filter to events in a specific Workspace. */
|
|
59
|
+
workspaceId?: string;
|
|
60
|
+
/** Filter to events affecting a specific resource type. */
|
|
61
|
+
resourceType?: string;
|
|
62
|
+
/** Filter to events affecting a specific resource UUID. */
|
|
63
|
+
resourceId?: string;
|
|
64
|
+
/** Filter to specific event types. */
|
|
65
|
+
types?: Array<EventType | string>;
|
|
66
|
+
}
|
|
67
|
+
/** Options for subscribing to real-time events. */
|
|
68
|
+
interface SubscribeOptions {
|
|
69
|
+
/** Replay events that occurred after this ISO 8601 timestamp. */
|
|
70
|
+
since?: string;
|
|
71
|
+
}
|
|
72
|
+
/** Options for querying historical events. */
|
|
73
|
+
interface EventHistoryOptions extends PaginationOptions {
|
|
74
|
+
/** Filter to a specific Organization. */
|
|
75
|
+
organizationId?: string;
|
|
76
|
+
/** Filter to a specific Workspace. */
|
|
77
|
+
workspaceId?: string;
|
|
78
|
+
/** Filter to events affecting a specific resource type. */
|
|
79
|
+
resourceType?: string;
|
|
80
|
+
/** Filter to events affecting a specific resource UUID. */
|
|
81
|
+
resourceId?: string;
|
|
82
|
+
/** Filter to specific event types. */
|
|
83
|
+
types?: Array<EventType | string>;
|
|
84
|
+
/** Return only events after this ISO 8601 timestamp. */
|
|
85
|
+
since?: string;
|
|
86
|
+
/** Return only events before this ISO 8601 timestamp. */
|
|
87
|
+
until?: string;
|
|
88
|
+
}
|
|
89
|
+
/** Callback invoked when a matching event is received. */
|
|
90
|
+
type EventHandler = (event: CpodEvent) => void;
|
|
91
|
+
/** Handle returned by `EventService.subscribe()`. */
|
|
92
|
+
interface Subscription {
|
|
93
|
+
/** Stop receiving events for this subscription. */
|
|
94
|
+
unsubscribe(): void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Manages event subscriptions and history for cPod resources.
|
|
99
|
+
*
|
|
100
|
+
* Subscriptions use a poll-based EventEmitter-like pattern over the REST API.
|
|
101
|
+
* For real-time SSE, the server must expose a `/api/v1/events/stream` endpoint.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const sub = client.events.subscribe(
|
|
106
|
+
* { organizationId: "b2c3d4e5-...", types: ["pod.failed"] },
|
|
107
|
+
* (event) => {
|
|
108
|
+
* console.log("Pod failed:", event.resourceId, event.payload);
|
|
109
|
+
* }
|
|
110
|
+
* );
|
|
111
|
+
*
|
|
112
|
+
* // Later, stop receiving events:
|
|
113
|
+
* sub.unsubscribe();
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare class EventService {
|
|
117
|
+
private readonly http;
|
|
118
|
+
private readonly listeners;
|
|
119
|
+
constructor(http: HttpClient);
|
|
120
|
+
/**
|
|
121
|
+
* Subscribe to events matching the given filter.
|
|
122
|
+
* The handler is called for each matching event received.
|
|
123
|
+
*
|
|
124
|
+
* Returns a Subscription handle — call `.unsubscribe()` to stop.
|
|
125
|
+
*/
|
|
126
|
+
subscribe(filter: EventFilter, handler: EventHandler, _opts?: SubscribeOptions): Subscription;
|
|
127
|
+
/**
|
|
128
|
+
* Dispatch a raw event object to all matching subscribers.
|
|
129
|
+
* Typically called internally when processing SSE or webhook payloads.
|
|
130
|
+
*/
|
|
131
|
+
dispatch(event: CpodEvent): void;
|
|
132
|
+
/**
|
|
133
|
+
* Retrieve historical events from the API.
|
|
134
|
+
*/
|
|
135
|
+
getHistory(opts?: EventHistoryOptions, requestOpts?: RequestOptions): Promise<ApiResponse<CpodEvent[]>>;
|
|
136
|
+
private matchesFilter;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { type CpodEvent, type EventFilter, type EventHandler, type EventHistoryOptions, EventService, EventType, type SubscribeOptions, type Subscription };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/events/service.ts
|
|
4
|
+
var EventService = class {
|
|
5
|
+
http;
|
|
6
|
+
listeners = /* @__PURE__ */ new Map();
|
|
7
|
+
constructor(http) {
|
|
8
|
+
this.http = http;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Subscribe to events matching the given filter.
|
|
12
|
+
* The handler is called for each matching event received.
|
|
13
|
+
*
|
|
14
|
+
* Returns a Subscription handle — call `.unsubscribe()` to stop.
|
|
15
|
+
*/
|
|
16
|
+
subscribe(filter, handler, _opts = {}) {
|
|
17
|
+
const key = /* @__PURE__ */ Symbol("subscription");
|
|
18
|
+
this.listeners.set(key, { filter, handler });
|
|
19
|
+
return {
|
|
20
|
+
unsubscribe: () => {
|
|
21
|
+
this.listeners.delete(key);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Dispatch a raw event object to all matching subscribers.
|
|
27
|
+
* Typically called internally when processing SSE or webhook payloads.
|
|
28
|
+
*/
|
|
29
|
+
dispatch(event) {
|
|
30
|
+
for (const { filter, handler } of this.listeners.values()) {
|
|
31
|
+
if (this.matchesFilter(event, filter)) {
|
|
32
|
+
try {
|
|
33
|
+
handler(event);
|
|
34
|
+
} catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Retrieve historical events from the API.
|
|
41
|
+
*/
|
|
42
|
+
async getHistory(opts = {}, requestOpts) {
|
|
43
|
+
const params = new URLSearchParams();
|
|
44
|
+
if (opts.limit !== void 0) params.set("limit", String(opts.limit));
|
|
45
|
+
if (opts.offset !== void 0) params.set("offset", String(opts.offset));
|
|
46
|
+
if (opts.organizationId !== void 0)
|
|
47
|
+
params.set("organizationId", opts.organizationId);
|
|
48
|
+
if (opts.workspaceId !== void 0)
|
|
49
|
+
params.set("workspaceId", opts.workspaceId);
|
|
50
|
+
if (opts.resourceType !== void 0)
|
|
51
|
+
params.set("resourceType", opts.resourceType);
|
|
52
|
+
if (opts.resourceId !== void 0)
|
|
53
|
+
params.set("resourceId", opts.resourceId);
|
|
54
|
+
if (opts.since !== void 0) params.set("since", opts.since);
|
|
55
|
+
if (opts.until !== void 0) params.set("until", opts.until);
|
|
56
|
+
if (opts.types && opts.types.length > 0) {
|
|
57
|
+
params.set("types", opts.types.join(","));
|
|
58
|
+
}
|
|
59
|
+
const qs = params.toString();
|
|
60
|
+
return this.http.get(
|
|
61
|
+
`/api/v1/events${qs ? `?${qs}` : ""}`,
|
|
62
|
+
requestOpts
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
matchesFilter(event, filter) {
|
|
66
|
+
if (filter.organizationId && event.organizationId !== filter.organizationId)
|
|
67
|
+
return false;
|
|
68
|
+
if (filter.workspaceId && event.workspaceId !== filter.workspaceId)
|
|
69
|
+
return false;
|
|
70
|
+
if (filter.resourceType && event.resourceType !== filter.resourceType)
|
|
71
|
+
return false;
|
|
72
|
+
if (filter.resourceId && event.resourceId !== filter.resourceId)
|
|
73
|
+
return false;
|
|
74
|
+
if (filter.types && filter.types.length > 0) {
|
|
75
|
+
if (!filter.types.includes(event.type)) return false;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/events/types.ts
|
|
82
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
83
|
+
EventType2["PodCreated"] = "pod.created";
|
|
84
|
+
EventType2["PodUpdated"] = "pod.updated";
|
|
85
|
+
EventType2["PodDeleted"] = "pod.deleted";
|
|
86
|
+
EventType2["PodStatusChanged"] = "pod.status_changed";
|
|
87
|
+
EventType2["PodStarted"] = "pod.started";
|
|
88
|
+
EventType2["PodStopped"] = "pod.stopped";
|
|
89
|
+
EventType2["PodFailed"] = "pod.failed";
|
|
90
|
+
EventType2["OrganizationCreated"] = "organization.created";
|
|
91
|
+
EventType2["OrganizationUpdated"] = "organization.updated";
|
|
92
|
+
EventType2["OrganizationArchived"] = "organization.archived";
|
|
93
|
+
EventType2["OrganizationMemberAdded"] = "organization.member_added";
|
|
94
|
+
EventType2["OrganizationMemberRemoved"] = "organization.member_removed";
|
|
95
|
+
EventType2["WorkspaceCreated"] = "workspace.created";
|
|
96
|
+
EventType2["WorkspaceUpdated"] = "workspace.updated";
|
|
97
|
+
EventType2["WorkspaceArchived"] = "workspace.archived";
|
|
98
|
+
EventType2["CredentialCreated"] = "credential.created";
|
|
99
|
+
EventType2["CredentialRevoked"] = "credential.revoked";
|
|
100
|
+
EventType2["CredentialExpired"] = "credential.expired";
|
|
101
|
+
EventType2["PolicyCreated"] = "policy.created";
|
|
102
|
+
EventType2["PolicyUpdated"] = "policy.updated";
|
|
103
|
+
EventType2["PolicyDeleted"] = "policy.deleted";
|
|
104
|
+
EventType2["UserSuspended"] = "user.suspended";
|
|
105
|
+
EventType2["UserReactivated"] = "user.reactivated";
|
|
106
|
+
return EventType2;
|
|
107
|
+
})(EventType || {});
|
|
108
|
+
|
|
109
|
+
exports.EventService = EventService;
|
|
110
|
+
exports.EventType = EventType;
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|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AA,GAAmB,mBAAA;AACnB,EAAAA,WAAA,kBAAA,CAAA,GAAmB,mBAAA;AACnB,EAAAA,WAAA,mBAAA,CAAA,GAAoB,oBAAA;AAEpB,EAAAA,WAAA,mBAAA,CAAA,GAAoB,oBAAA;AACpB,EAAAA,WAAA,mBAAA,CAAA,GAAoB,oBAAA;AACpB,EAAAA,WAAA,mBAAA,CAAA,GAAoB,oBAAA;AAEpB,EAAAA,WAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,WAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,WAAA,eAAA,CAAA,GAAgB,gBAAA;AAEhB,EAAAA,WAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,WAAA,iBAAA,CAAA,GAAkB,kBAAA;AA7BR,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"index.js","sourcesContent":["import type { HttpClient } from \"../http/client.js\";\nimport type { ApiResponse, RequestOptions } from \"../types/index.js\";\nimport type {\n CpodEvent,\n EventFilter,\n EventHandler,\n EventHistoryOptions,\n SubscribeOptions,\n Subscription,\n} from \"./types.js\";\n\n/**\n * Manages event subscriptions and history for cPod resources.\n *\n * Subscriptions use a poll-based EventEmitter-like pattern over the REST API.\n * For real-time SSE, the server must expose a `/api/v1/events/stream` endpoint.\n *\n * @example\n * ```typescript\n * const sub = client.events.subscribe(\n * { organizationId: \"b2c3d4e5-...\", types: [\"pod.failed\"] },\n * (event) => {\n * console.log(\"Pod failed:\", event.resourceId, event.payload);\n * }\n * );\n *\n * // Later, stop receiving events:\n * sub.unsubscribe();\n * ```\n */\nexport class EventService {\n private readonly http: HttpClient;\n private readonly listeners: Map<\n symbol,\n { filter: EventFilter; handler: EventHandler }\n > = new Map();\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Subscribe to events matching the given filter.\n * The handler is called for each matching event received.\n *\n * Returns a Subscription handle — call `.unsubscribe()` to stop.\n */\n subscribe(\n filter: EventFilter,\n handler: EventHandler,\n _opts: SubscribeOptions = {}\n ): Subscription {\n const key = Symbol(\"subscription\");\n this.listeners.set(key, { filter, handler });\n\n return {\n unsubscribe: () => {\n this.listeners.delete(key);\n },\n };\n }\n\n /**\n * Dispatch a raw event object to all matching subscribers.\n * Typically called internally when processing SSE or webhook payloads.\n */\n dispatch(event: CpodEvent): void {\n for (const { filter, handler } of this.listeners.values()) {\n if (this.matchesFilter(event, filter)) {\n try {\n handler(event);\n } catch {\n // Individual handler errors must not interrupt other handlers.\n }\n }\n }\n }\n\n /**\n * Retrieve historical events from the API.\n */\n async getHistory(\n opts: EventHistoryOptions = {},\n requestOpts?: RequestOptions\n ): Promise<ApiResponse<CpodEvent[]>> {\n const params = new URLSearchParams();\n if (opts.limit !== undefined) params.set(\"limit\", String(opts.limit));\n if (opts.offset !== undefined) params.set(\"offset\", String(opts.offset));\n if (opts.organizationId !== undefined)\n params.set(\"organizationId\", opts.organizationId);\n if (opts.workspaceId !== undefined)\n params.set(\"workspaceId\", opts.workspaceId);\n if (opts.resourceType !== undefined)\n params.set(\"resourceType\", opts.resourceType);\n if (opts.resourceId !== undefined)\n params.set(\"resourceId\", opts.resourceId);\n if (opts.since !== undefined) params.set(\"since\", opts.since);\n if (opts.until !== undefined) params.set(\"until\", opts.until);\n if (opts.types && opts.types.length > 0) {\n params.set(\"types\", opts.types.join(\",\"));\n }\n\n const qs = params.toString();\n return this.http.get<ApiResponse<CpodEvent[]>>(\n `/api/v1/events${qs ? `?${qs}` : \"\"}`,\n requestOpts\n );\n }\n\n private matchesFilter(event: CpodEvent, filter: EventFilter): boolean {\n if (\n filter.organizationId &&\n event.organizationId !== filter.organizationId\n )\n return false;\n if (filter.workspaceId && event.workspaceId !== filter.workspaceId)\n return false;\n if (filter.resourceType && event.resourceType !== filter.resourceType)\n return false;\n if (filter.resourceId && event.resourceId !== filter.resourceId)\n return false;\n if (filter.types && filter.types.length > 0) {\n if (!filter.types.includes(event.type)) return false;\n }\n return true;\n }\n}\n","import type { PaginationOptions } from \"../types/index.js\";\n\n/**\n * Well-known event type strings emitted by the cPod platform.\n * Additional event types may be emitted for enterprise features — use string\n * literals for those until they are added to this enum.\n */\nexport enum EventType {\n // Pod lifecycle events\n PodCreated = \"pod.created\",\n PodUpdated = \"pod.updated\",\n PodDeleted = \"pod.deleted\",\n PodStatusChanged = \"pod.status_changed\",\n PodStarted = \"pod.started\",\n PodStopped = \"pod.stopped\",\n PodFailed = \"pod.failed\",\n // Organization events\n OrganizationCreated = \"organization.created\",\n OrganizationUpdated = \"organization.updated\",\n OrganizationArchived = \"organization.archived\",\n OrganizationMemberAdded = \"organization.member_added\",\n OrganizationMemberRemoved = \"organization.member_removed\",\n // Workspace events\n WorkspaceCreated = \"workspace.created\",\n WorkspaceUpdated = \"workspace.updated\",\n WorkspaceArchived = \"workspace.archived\",\n // Credential events\n CredentialCreated = \"credential.created\",\n CredentialRevoked = \"credential.revoked\",\n CredentialExpired = \"credential.expired\",\n // Policy events\n PolicyCreated = \"policy.created\",\n PolicyUpdated = \"policy.updated\",\n PolicyDeleted = \"policy.deleted\",\n // User events\n UserSuspended = \"user.suspended\",\n UserReactivated = \"user.reactivated\",\n}\n\n/** A platform event delivered to subscribers or returned from event history. */\nexport interface CpodEvent {\n /** Unique event identifier (UUID). */\n id: string;\n /** Dot-notation event type (e.g., 'pod.created', 'credential.revoked'). */\n type: EventType | string;\n /** UUID of the Organization in whose context this event occurred. */\n organizationId: string;\n /** UUID of the Workspace, if this event is workspace-scoped. */\n workspaceId?: string;\n /** UUID of the specific resource affected. */\n resourceId: string;\n /** Entity type of the resource (e.g., 'Pod', 'Credential'). */\n resourceType: string;\n /** Event-specific payload. Shape varies by event type. */\n payload: Record<string, unknown>;\n /** ISO 8601 timestamp of when the event occurred. */\n timestamp: string;\n /** Schema version of the payload (e.g., '1.0'). */\n version: string;\n}\n\n/** Filter criteria for event subscriptions and history queries. */\nexport interface EventFilter {\n /** Filter to events in a specific Organization. */\n organizationId?: string;\n /** Filter to events in a specific Workspace. */\n workspaceId?: string;\n /** Filter to events affecting a specific resource type. */\n resourceType?: string;\n /** Filter to events affecting a specific resource UUID. */\n resourceId?: string;\n /** Filter to specific event types. */\n types?: Array<EventType | string>;\n}\n\n/** Options for subscribing to real-time events. */\nexport interface SubscribeOptions {\n /** Replay events that occurred after this ISO 8601 timestamp. */\n since?: string;\n}\n\n/** Options for querying historical events. */\nexport interface EventHistoryOptions extends PaginationOptions {\n /** Filter to a specific Organization. */\n organizationId?: string;\n /** Filter to a specific Workspace. */\n workspaceId?: string;\n /** Filter to events affecting a specific resource type. */\n resourceType?: string;\n /** Filter to events affecting a specific resource UUID. */\n resourceId?: string;\n /** Filter to specific event types. */\n types?: Array<EventType | string>;\n /** Return only events after this ISO 8601 timestamp. */\n since?: string;\n /** Return only events before this ISO 8601 timestamp. */\n until?: string;\n}\n\n/** Callback invoked when a matching event is received. */\nexport type EventHandler = (event: CpodEvent) => void;\n\n/** Handle returned by `EventService.subscribe()`. */\nexport interface Subscription {\n /** Stop receiving events for this subscription. */\n unsubscribe(): void;\n}\n"]}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/events/service.ts
|
|
2
|
+
var EventService = class {
|
|
3
|
+
http;
|
|
4
|
+
listeners = /* @__PURE__ */ new Map();
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Subscribe to events matching the given filter.
|
|
10
|
+
* The handler is called for each matching event received.
|
|
11
|
+
*
|
|
12
|
+
* Returns a Subscription handle — call `.unsubscribe()` to stop.
|
|
13
|
+
*/
|
|
14
|
+
subscribe(filter, handler, _opts = {}) {
|
|
15
|
+
const key = /* @__PURE__ */ Symbol("subscription");
|
|
16
|
+
this.listeners.set(key, { filter, handler });
|
|
17
|
+
return {
|
|
18
|
+
unsubscribe: () => {
|
|
19
|
+
this.listeners.delete(key);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Dispatch a raw event object to all matching subscribers.
|
|
25
|
+
* Typically called internally when processing SSE or webhook payloads.
|
|
26
|
+
*/
|
|
27
|
+
dispatch(event) {
|
|
28
|
+
for (const { filter, handler } of this.listeners.values()) {
|
|
29
|
+
if (this.matchesFilter(event, filter)) {
|
|
30
|
+
try {
|
|
31
|
+
handler(event);
|
|
32
|
+
} catch {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Retrieve historical events from the API.
|
|
39
|
+
*/
|
|
40
|
+
async getHistory(opts = {}, requestOpts) {
|
|
41
|
+
const params = new URLSearchParams();
|
|
42
|
+
if (opts.limit !== void 0) params.set("limit", String(opts.limit));
|
|
43
|
+
if (opts.offset !== void 0) params.set("offset", String(opts.offset));
|
|
44
|
+
if (opts.organizationId !== void 0)
|
|
45
|
+
params.set("organizationId", opts.organizationId);
|
|
46
|
+
if (opts.workspaceId !== void 0)
|
|
47
|
+
params.set("workspaceId", opts.workspaceId);
|
|
48
|
+
if (opts.resourceType !== void 0)
|
|
49
|
+
params.set("resourceType", opts.resourceType);
|
|
50
|
+
if (opts.resourceId !== void 0)
|
|
51
|
+
params.set("resourceId", opts.resourceId);
|
|
52
|
+
if (opts.since !== void 0) params.set("since", opts.since);
|
|
53
|
+
if (opts.until !== void 0) params.set("until", opts.until);
|
|
54
|
+
if (opts.types && opts.types.length > 0) {
|
|
55
|
+
params.set("types", opts.types.join(","));
|
|
56
|
+
}
|
|
57
|
+
const qs = params.toString();
|
|
58
|
+
return this.http.get(
|
|
59
|
+
`/api/v1/events${qs ? `?${qs}` : ""}`,
|
|
60
|
+
requestOpts
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
matchesFilter(event, filter) {
|
|
64
|
+
if (filter.organizationId && event.organizationId !== filter.organizationId)
|
|
65
|
+
return false;
|
|
66
|
+
if (filter.workspaceId && event.workspaceId !== filter.workspaceId)
|
|
67
|
+
return false;
|
|
68
|
+
if (filter.resourceType && event.resourceType !== filter.resourceType)
|
|
69
|
+
return false;
|
|
70
|
+
if (filter.resourceId && event.resourceId !== filter.resourceId)
|
|
71
|
+
return false;
|
|
72
|
+
if (filter.types && filter.types.length > 0) {
|
|
73
|
+
if (!filter.types.includes(event.type)) return false;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/events/types.ts
|
|
80
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
81
|
+
EventType2["PodCreated"] = "pod.created";
|
|
82
|
+
EventType2["PodUpdated"] = "pod.updated";
|
|
83
|
+
EventType2["PodDeleted"] = "pod.deleted";
|
|
84
|
+
EventType2["PodStatusChanged"] = "pod.status_changed";
|
|
85
|
+
EventType2["PodStarted"] = "pod.started";
|
|
86
|
+
EventType2["PodStopped"] = "pod.stopped";
|
|
87
|
+
EventType2["PodFailed"] = "pod.failed";
|
|
88
|
+
EventType2["OrganizationCreated"] = "organization.created";
|
|
89
|
+
EventType2["OrganizationUpdated"] = "organization.updated";
|
|
90
|
+
EventType2["OrganizationArchived"] = "organization.archived";
|
|
91
|
+
EventType2["OrganizationMemberAdded"] = "organization.member_added";
|
|
92
|
+
EventType2["OrganizationMemberRemoved"] = "organization.member_removed";
|
|
93
|
+
EventType2["WorkspaceCreated"] = "workspace.created";
|
|
94
|
+
EventType2["WorkspaceUpdated"] = "workspace.updated";
|
|
95
|
+
EventType2["WorkspaceArchived"] = "workspace.archived";
|
|
96
|
+
EventType2["CredentialCreated"] = "credential.created";
|
|
97
|
+
EventType2["CredentialRevoked"] = "credential.revoked";
|
|
98
|
+
EventType2["CredentialExpired"] = "credential.expired";
|
|
99
|
+
EventType2["PolicyCreated"] = "policy.created";
|
|
100
|
+
EventType2["PolicyUpdated"] = "policy.updated";
|
|
101
|
+
EventType2["PolicyDeleted"] = "policy.deleted";
|
|
102
|
+
EventType2["UserSuspended"] = "user.suspended";
|
|
103
|
+
EventType2["UserReactivated"] = "user.reactivated";
|
|
104
|
+
return EventType2;
|
|
105
|
+
})(EventType || {});
|
|
106
|
+
|
|
107
|
+
export { EventService, EventType };
|
|
108
|
+
//# sourceMappingURL=index.mjs.map
|
|
109
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/events/service.ts","../../src/events/types.ts"],"names":["EventType"],"mappings":";AA8BO,IAAM,eAAN,MAAmB;AAAA,EACP,IAAA;AAAA,EACA,SAAA,uBAGT,GAAA,EAAI;AAAA,EAEZ,YAAY,IAAA,EAAkB;AAC5B,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,SAAA,CACE,MAAA,EACA,OAAA,EACA,KAAA,GAA0B,EAAC,EACb;AACd,IAAA,MAAM,GAAA,0BAAa,cAAc,CAAA;AACjC,IAAA,IAAA,CAAK,UAAU,GAAA,CAAI,GAAA,EAAK,EAAE,MAAA,EAAQ,SAAS,CAAA;AAE3C,IAAA,OAAO;AAAA,MACL,aAAa,MAAM;AACjB,QAAA,IAAA,CAAK,SAAA,CAAU,OAAO,GAAG,CAAA;AAAA,MAC3B;AAAA,KACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAS,KAAA,EAAwB;AAC/B,IAAA,KAAA,MAAW,EAAE,MAAA,EAAQ,OAAA,MAAa,IAAA,CAAK,SAAA,CAAU,QAAO,EAAG;AACzD,MAAA,IAAI,IAAA,CAAK,aAAA,CAAc,KAAA,EAAO,MAAM,CAAA,EAAG;AACrC,QAAA,IAAI;AACF,UAAA,OAAA,CAAQ,KAAK,CAAA;AAAA,QACf,CAAA,CAAA,MAAQ;AAAA,QAER;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAAA,CACJ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CAAA,GAAsB,sBAAA;AACtB,EAAAA,WAAA,qBAAA,CAAA,GAAsB,sBAAA;AACtB,EAAAA,WAAA,sBAAA,CAAA,GAAuB,uBAAA;AACvB,EAAAA,WAAA,yBAAA,CAAA,GAA0B,2BAAA;AAC1B,EAAAA,WAAA,2BAAA,CAAA,GAA4B,6BAAA;AAE5B,EAAAA,WAAA,kBAAA,CAAA,GAAmB,mBAAA;AACnB,EAAAA,WAAA,kBAAA,CAAA,GAAmB,mBAAA;AACnB,EAAAA,WAAA,mBAAA,CAAA,GAAoB,oBAAA;AAEpB,EAAAA,WAAA,mBAAA,CAAA,GAAoB,oBAAA;AACpB,EAAAA,WAAA,mBAAA,CAAA,GAAoB,oBAAA;AACpB,EAAAA,WAAA,mBAAA,CAAA,GAAoB,oBAAA;AAEpB,EAAAA,WAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,WAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,WAAA,eAAA,CAAA,GAAgB,gBAAA;AAEhB,EAAAA,WAAA,eAAA,CAAA,GAAgB,gBAAA;AAChB,EAAAA,WAAA,iBAAA,CAAA,GAAkB,kBAAA;AA7BR,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA","file":"index.mjs","sourcesContent":["import type { HttpClient } from \"../http/client.js\";\nimport type { ApiResponse, RequestOptions } from \"../types/index.js\";\nimport type {\n CpodEvent,\n EventFilter,\n EventHandler,\n EventHistoryOptions,\n SubscribeOptions,\n Subscription,\n} from \"./types.js\";\n\n/**\n * Manages event subscriptions and history for cPod resources.\n *\n * Subscriptions use a poll-based EventEmitter-like pattern over the REST API.\n * For real-time SSE, the server must expose a `/api/v1/events/stream` endpoint.\n *\n * @example\n * ```typescript\n * const sub = client.events.subscribe(\n * { organizationId: \"b2c3d4e5-...\", types: [\"pod.failed\"] },\n * (event) => {\n * console.log(\"Pod failed:\", event.resourceId, event.payload);\n * }\n * );\n *\n * // Later, stop receiving events:\n * sub.unsubscribe();\n * ```\n */\nexport class EventService {\n private readonly http: HttpClient;\n private readonly listeners: Map<\n symbol,\n { filter: EventFilter; handler: EventHandler }\n > = new Map();\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Subscribe to events matching the given filter.\n * The handler is called for each matching event received.\n *\n * Returns a Subscription handle — call `.unsubscribe()` to stop.\n */\n subscribe(\n filter: EventFilter,\n handler: EventHandler,\n _opts: SubscribeOptions = {}\n ): Subscription {\n const key = Symbol(\"subscription\");\n this.listeners.set(key, { filter, handler });\n\n return {\n unsubscribe: () => {\n this.listeners.delete(key);\n },\n };\n }\n\n /**\n * Dispatch a raw event object to all matching subscribers.\n * Typically called internally when processing SSE or webhook payloads.\n */\n dispatch(event: CpodEvent): void {\n for (const { filter, handler } of this.listeners.values()) {\n if (this.matchesFilter(event, filter)) {\n try {\n handler(event);\n } catch {\n // Individual handler errors must not interrupt other handlers.\n }\n }\n }\n }\n\n /**\n * Retrieve historical events from the API.\n */\n async getHistory(\n opts: EventHistoryOptions = {},\n requestOpts?: RequestOptions\n ): Promise<ApiResponse<CpodEvent[]>> {\n const params = new URLSearchParams();\n if (opts.limit !== undefined) params.set(\"limit\", String(opts.limit));\n if (opts.offset !== undefined) params.set(\"offset\", String(opts.offset));\n if (opts.organizationId !== undefined)\n params.set(\"organizationId\", opts.organizationId);\n if (opts.workspaceId !== undefined)\n params.set(\"workspaceId\", opts.workspaceId);\n if (opts.resourceType !== undefined)\n params.set(\"resourceType\", opts.resourceType);\n if (opts.resourceId !== undefined)\n params.set(\"resourceId\", opts.resourceId);\n if (opts.since !== undefined) params.set(\"since\", opts.since);\n if (opts.until !== undefined) params.set(\"until\", opts.until);\n if (opts.types && opts.types.length > 0) {\n params.set(\"types\", opts.types.join(\",\"));\n }\n\n const qs = params.toString();\n return this.http.get<ApiResponse<CpodEvent[]>>(\n `/api/v1/events${qs ? `?${qs}` : \"\"}`,\n requestOpts\n );\n }\n\n private matchesFilter(event: CpodEvent, filter: EventFilter): boolean {\n if (\n filter.organizationId &&\n event.organizationId !== filter.organizationId\n )\n return false;\n if (filter.workspaceId && event.workspaceId !== filter.workspaceId)\n return false;\n if (filter.resourceType && event.resourceType !== filter.resourceType)\n return false;\n if (filter.resourceId && event.resourceId !== filter.resourceId)\n return false;\n if (filter.types && filter.types.length > 0) {\n if (!filter.types.includes(event.type)) return false;\n }\n return true;\n }\n}\n","import type { PaginationOptions } from \"../types/index.js\";\n\n/**\n * Well-known event type strings emitted by the cPod platform.\n * Additional event types may be emitted for enterprise features — use string\n * literals for those until they are added to this enum.\n */\nexport enum EventType {\n // Pod lifecycle events\n PodCreated = \"pod.created\",\n PodUpdated = \"pod.updated\",\n PodDeleted = \"pod.deleted\",\n PodStatusChanged = \"pod.status_changed\",\n PodStarted = \"pod.started\",\n PodStopped = \"pod.stopped\",\n PodFailed = \"pod.failed\",\n // Organization events\n OrganizationCreated = \"organization.created\",\n OrganizationUpdated = \"organization.updated\",\n OrganizationArchived = \"organization.archived\",\n OrganizationMemberAdded = \"organization.member_added\",\n OrganizationMemberRemoved = \"organization.member_removed\",\n // Workspace events\n WorkspaceCreated = \"workspace.created\",\n WorkspaceUpdated = \"workspace.updated\",\n WorkspaceArchived = \"workspace.archived\",\n // Credential events\n CredentialCreated = \"credential.created\",\n CredentialRevoked = \"credential.revoked\",\n CredentialExpired = \"credential.expired\",\n // Policy events\n PolicyCreated = \"policy.created\",\n PolicyUpdated = \"policy.updated\",\n PolicyDeleted = \"policy.deleted\",\n // User events\n UserSuspended = \"user.suspended\",\n UserReactivated = \"user.reactivated\",\n}\n\n/** A platform event delivered to subscribers or returned from event history. */\nexport interface CpodEvent {\n /** Unique event identifier (UUID). */\n id: string;\n /** Dot-notation event type (e.g., 'pod.created', 'credential.revoked'). */\n type: EventType | string;\n /** UUID of the Organization in whose context this event occurred. */\n organizationId: string;\n /** UUID of the Workspace, if this event is workspace-scoped. */\n workspaceId?: string;\n /** UUID of the specific resource affected. */\n resourceId: string;\n /** Entity type of the resource (e.g., 'Pod', 'Credential'). */\n resourceType: string;\n /** Event-specific payload. Shape varies by event type. */\n payload: Record<string, unknown>;\n /** ISO 8601 timestamp of when the event occurred. */\n timestamp: string;\n /** Schema version of the payload (e.g., '1.0'). */\n version: string;\n}\n\n/** Filter criteria for event subscriptions and history queries. */\nexport interface EventFilter {\n /** Filter to events in a specific Organization. */\n organizationId?: string;\n /** Filter to events in a specific Workspace. */\n workspaceId?: string;\n /** Filter to events affecting a specific resource type. */\n resourceType?: string;\n /** Filter to events affecting a specific resource UUID. */\n resourceId?: string;\n /** Filter to specific event types. */\n types?: Array<EventType | string>;\n}\n\n/** Options for subscribing to real-time events. */\nexport interface SubscribeOptions {\n /** Replay events that occurred after this ISO 8601 timestamp. */\n since?: string;\n}\n\n/** Options for querying historical events. */\nexport interface EventHistoryOptions extends PaginationOptions {\n /** Filter to a specific Organization. */\n organizationId?: string;\n /** Filter to a specific Workspace. */\n workspaceId?: string;\n /** Filter to events affecting a specific resource type. */\n resourceType?: string;\n /** Filter to events affecting a specific resource UUID. */\n resourceId?: string;\n /** Filter to specific event types. */\n types?: Array<EventType | string>;\n /** Return only events after this ISO 8601 timestamp. */\n since?: string;\n /** Return only events before this ISO 8601 timestamp. */\n until?: string;\n}\n\n/** Callback invoked when a matching event is received. */\nexport type EventHandler = (event: CpodEvent) => void;\n\n/** Handle returned by `EventService.subscribe()`. */\nexport interface Subscription {\n /** Stop receiving events for this subscription. */\n unsubscribe(): void;\n}\n"]}
|