@krak-stack/registry 0.1.59 → 0.1.60
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 +4 -1
- package/dist/components/ui/data-table.d.ts +2 -0
- package/dist/components/ui/data-table.js +6 -2
- package/dist/components/ui/item.d.ts +22 -0
- package/dist/components/ui/trace.d.ts +18 -0
- package/dist/services/agent/client/index.js +584 -434
- package/dist/services/agent/client/widget.d.ts +1 -0
- package/dist/services/events/browser.js +29 -3
- package/dist/services/events/client/audit-log-table.js +6 -2
- package/dist/services/events/client/tracking-notice.js +2 -1
- package/dist/services/events/index.d.ts +26 -56
- package/dist/services/events/index.js +118 -7
- package/dist/services/events/schema.d.ts +66 -24
- package/dist/services/events/schema.js +34 -3
- package/dist/services/opentelemetry/api.js +2 -1
- package/dist/services/opentelemetry/browser.d.ts +1 -1
- package/dist/services/opentelemetry/browser.js +2 -1
- package/dist/services/opentelemetry/events.d.ts +1 -1
- package/dist/services/opentelemetry/index.d.ts +1 -1
- package/dist/services/opentelemetry/index.js +2 -1
- package/dist/services/opentelemetry/schema.d.ts +3 -1
- package/dist/services/opentelemetry/web-vitals.js +2 -1
- package/dist/services/webhooks/http-client.d.ts +7 -0
- package/dist/services/webhooks/http-client.js +57 -0
- package/dist/services/webhooks/index.d.ts +341 -0
- package/dist/services/webhooks/index.js +737 -0
- package/dist/services/webhooks/migrations.d.ts +5 -0
- package/dist/services/webhooks/migrations.js +44 -0
- package/dist/services/webhooks/schema.d.ts +243 -0
- package/dist/services/webhooks/schema.js +333 -0
- package/dist/services/webhooks/url.d.ts +3 -0
- package/dist/services/webhooks/url.js +32 -0
- package/package.json +25 -1
- package/dist/components/ui/marker.d.ts +0 -10
|
@@ -54,6 +54,7 @@ var EventAttributeValue = Schema.Union([
|
|
|
54
54
|
Schema.Array(Schema.Boolean)
|
|
55
55
|
]);
|
|
56
56
|
var EventAttributesSchema = Schema.Record(Schema.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
|
|
57
|
+
var EventPropertiesSchema = Schema.Record(Schema.String, Schema.Json).annotate({ identifier: "EventProperties" });
|
|
57
58
|
var EventOptionsSchema = Schema.Struct({
|
|
58
59
|
userId: Schema.optional(Schema.NonEmptyString),
|
|
59
60
|
anonymousId: Schema.optional(Schema.NonEmptyString),
|
|
@@ -64,7 +65,7 @@ var EventOptionsSchema = Schema.Struct({
|
|
|
64
65
|
}).annotate({ identifier: "EventOptions" });
|
|
65
66
|
var TelemetryEvent = Schema.Struct({
|
|
66
67
|
name: Schema.NonEmptyString,
|
|
67
|
-
properties: Schema.optional(
|
|
68
|
+
properties: Schema.optional(EventPropertiesSchema),
|
|
68
69
|
options: Schema.optional(EventOptionsSchema)
|
|
69
70
|
}).annotate({ identifier: "TelemetryEvent" });
|
|
70
71
|
|
|
@@ -441,7 +442,7 @@ var AuditTarget = Schema5.Struct({
|
|
|
441
442
|
var trackEventFields = {
|
|
442
443
|
eventId: Schema5.optional(EventId),
|
|
443
444
|
name: Schema5.NonEmptyString.check(Schema5.isMaxLength(128)),
|
|
444
|
-
properties: Schema5.optional(
|
|
445
|
+
properties: Schema5.optional(EventPropertiesSchema),
|
|
445
446
|
identity: Schema5.optional(EventIdentity),
|
|
446
447
|
timestamp: Schema5.optional(Schema5.DateTimeUtc)
|
|
447
448
|
};
|
|
@@ -456,6 +457,24 @@ var TrackEvent = Schema5.Union([
|
|
|
456
457
|
target: AuditTarget
|
|
457
458
|
})
|
|
458
459
|
]).annotate({ identifier: "TrackEvent" });
|
|
460
|
+
var EventInputProperties = Schema5.Record(Schema5.String, Schema5.Unknown).annotate({ identifier: "EventInputProperties" });
|
|
461
|
+
var TrackEventInput = Schema5.Union([
|
|
462
|
+
Schema5.Struct({
|
|
463
|
+
...TrackEvent.members[0].fields,
|
|
464
|
+
properties: Schema5.optional(EventInputProperties)
|
|
465
|
+
}),
|
|
466
|
+
Schema5.Struct({
|
|
467
|
+
...TrackEvent.members[1].fields,
|
|
468
|
+
properties: Schema5.optional(EventInputProperties)
|
|
469
|
+
})
|
|
470
|
+
]).annotate({ identifier: "TrackEventInput" });
|
|
471
|
+
var EventSubscription = Schema5.Struct({
|
|
472
|
+
name: Schema5.NonEmptyString.check(Schema5.isMaxLength(128)),
|
|
473
|
+
events: Schema5.NonEmptyArray(trackEventFields.name)
|
|
474
|
+
}).annotate({ identifier: "EventSubscription" });
|
|
475
|
+
|
|
476
|
+
class EventSubscriberError extends Schema5.TaggedError()("EventSubscriberError", { subscription: Schema5.String }) {
|
|
477
|
+
}
|
|
459
478
|
var EventActionFilter = Schema5.Struct({
|
|
460
479
|
id: Schema5.Literal("eventName"),
|
|
461
480
|
kind: Schema5.Literal("values"),
|
|
@@ -546,7 +565,7 @@ var AttributeValue = Schema5.Union([
|
|
|
546
565
|
]);
|
|
547
566
|
var EventAttribute = Schema5.Struct({
|
|
548
567
|
key: Schema5.NonEmptyString.check(Schema5.isMaxLength(128)),
|
|
549
|
-
value:
|
|
568
|
+
value: Schema5.StructWithRest(Schema5.Struct({ stringValue: Schema5.optional(Schema5.String) }), [Schema5.Record(Schema5.String, Schema5.Json)])
|
|
550
569
|
}).annotate({ identifier: "EventAttribute" });
|
|
551
570
|
var EventLogRecord = Schema5.Struct({
|
|
552
571
|
eventName: Schema5.NonEmptyString.check(Schema5.isMaxLength(128), Schema5.isPattern(/^[^\r\n]+$/)),
|
|
@@ -557,6 +576,13 @@ var EventLogRecord = Schema5.Struct({
|
|
|
557
576
|
spanId: Schema5.optional(Schema5.String.check(Schema5.isPattern(/^[a-f0-9]{16}$/))),
|
|
558
577
|
attributes: Schema5.Array(EventAttribute).check(Schema5.isMaxLength(64), Schema5.makeFilter((values) => new Set(values.map(({ key }) => key)).size === values.length || "Duplicate attribute keys"))
|
|
559
578
|
}).annotate({ identifier: "EventLogRecord" });
|
|
579
|
+
var BrowserEventLogRecord = Schema5.Struct({
|
|
580
|
+
...EventLogRecord.fields,
|
|
581
|
+
attributes: Schema5.Array(Schema5.Struct({
|
|
582
|
+
key: EventAttribute.fields.key,
|
|
583
|
+
value: AttributeValue
|
|
584
|
+
})).check(Schema5.isMaxLength(64), Schema5.makeFilter((values) => new Set(values.map(({ key }) => key)).size === values.length || "Duplicate attribute keys"))
|
|
585
|
+
}).annotate({ identifier: "BrowserEventLogRecord" });
|
|
560
586
|
var extensions = Schema5.Record(Schema5.String, Schema5.Unknown);
|
|
561
587
|
var OtlpLogs = Schema5.StructWithRest(Schema5.Struct({
|
|
562
588
|
resourceLogs: Schema5.Array(Schema5.StructWithRest(Schema5.Struct({
|
|
@@ -1224,8 +1224,12 @@ var DataTableReferenceCell = ({
|
|
|
1224
1224
|
className: "flex min-w-0 items-center gap-2",
|
|
1225
1225
|
children: [
|
|
1226
1226
|
/* @__PURE__ */ jsx15("div", {
|
|
1227
|
-
className: cn("bg-muted flex size-8 shrink-0 items-center justify-center overflow-hidden text-xs font-medium", imageVariant === "circle" ? "rounded-full" : "rounded-md"),
|
|
1228
|
-
children: item.
|
|
1227
|
+
className: cn("bg-muted flex size-8 shrink-0 items-center justify-center overflow-hidden text-xs font-medium", imageVariant === "circle" ? "rounded-full" : "rounded-md", item.iconClassName),
|
|
1228
|
+
children: item.icon ? /* @__PURE__ */ jsx15("span", {
|
|
1229
|
+
"aria-hidden": "true",
|
|
1230
|
+
className: "[&_svg]:size-4",
|
|
1231
|
+
children: item.icon
|
|
1232
|
+
}) : item.imageSrc && item.imageSrc !== failedImage ? /* @__PURE__ */ jsx15("img", {
|
|
1229
1233
|
src: item.imageSrc,
|
|
1230
1234
|
alt: item.label,
|
|
1231
1235
|
className: "size-full object-cover",
|
|
@@ -187,6 +187,7 @@ var EventAttributeValue = Schema.Union([
|
|
|
187
187
|
Schema.Array(Schema.Boolean)
|
|
188
188
|
]);
|
|
189
189
|
var EventAttributesSchema = Schema.Record(Schema.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
|
|
190
|
+
var EventPropertiesSchema = Schema.Record(Schema.String, Schema.Json).annotate({ identifier: "EventProperties" });
|
|
190
191
|
var EventOptionsSchema = Schema.Struct({
|
|
191
192
|
userId: Schema.optional(Schema.NonEmptyString),
|
|
192
193
|
anonymousId: Schema.optional(Schema.NonEmptyString),
|
|
@@ -197,7 +198,7 @@ var EventOptionsSchema = Schema.Struct({
|
|
|
197
198
|
}).annotate({ identifier: "EventOptions" });
|
|
198
199
|
var TelemetryEvent = Schema.Struct({
|
|
199
200
|
name: Schema.NonEmptyString,
|
|
200
|
-
properties: Schema.optional(
|
|
201
|
+
properties: Schema.optional(EventPropertiesSchema),
|
|
201
202
|
options: Schema.optional(EventOptionsSchema)
|
|
202
203
|
}).annotate({ identifier: "TelemetryEvent" });
|
|
203
204
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Config, Context, DateTime, Effect, Layer, Redacted, Schema } from "effect";
|
|
1
|
+
import { Cause, Config, Context, DateTime, Effect, Layer, Redacted, Schema } from "effect";
|
|
2
2
|
import { HttpServerRequest } from "effect/http";
|
|
3
|
+
import { WorkflowEngine } from "effect/workflow";
|
|
3
4
|
import { OtlpLogsProcessor, OtlpProcessingError } from "../opentelemetry/processor.js";
|
|
4
5
|
import { Otlp } from "../opentelemetry/index.js";
|
|
5
6
|
import { OtlpEvents } from "../opentelemetry/events.js";
|
|
6
|
-
import { EventIdentity, EventGeolocation, EventConflictError, EventsPersistenceError } from "./schema.js";
|
|
7
|
+
import { EventIdentity, EventGeolocation, EventConflictError, EventsPersistenceError, type EventSubscriber } from "./schema.js";
|
|
7
8
|
export declare const SESSION_TIMEOUT_MS: number;
|
|
8
|
-
export type { EventGeolocation } from "./schema.js";
|
|
9
|
+
export type { EventGeolocation, EventSubscriber } from "./schema.js";
|
|
9
10
|
export { AuditTarget, TrackEvent, EventLogRecord, ListEvents } from "./schema.js";
|
|
10
11
|
export type EventGeolocationResolver = (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<EventGeolocation | null, unknown>;
|
|
11
12
|
export interface EventsOptions {
|
|
@@ -23,7 +24,7 @@ export interface EventsOptions {
|
|
|
23
24
|
}
|
|
24
25
|
declare const EventsConfigurationError_base: Schema.Class<EventsConfigurationError, Schema.TaggedStruct<"EventsConfigurationError", {
|
|
25
26
|
readonly message: Schema.String;
|
|
26
|
-
}>,
|
|
27
|
+
}>, Cause.YieldableError>;
|
|
27
28
|
export declare class EventsConfigurationError extends EventsConfigurationError_base {
|
|
28
29
|
}
|
|
29
30
|
export declare const dailyVisitorId: (input: {
|
|
@@ -41,21 +42,18 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
|
|
|
41
42
|
track: (input: {
|
|
42
43
|
readonly eventId?: string | undefined;
|
|
43
44
|
readonly name: string;
|
|
44
|
-
readonly properties?: {
|
|
45
|
-
readonly [x: string]: string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
|
|
46
|
-
} | undefined;
|
|
47
45
|
readonly identity?: {
|
|
48
46
|
readonly userId?: string | undefined;
|
|
49
47
|
readonly organizationId?: string | undefined;
|
|
50
48
|
} | undefined;
|
|
51
49
|
readonly timestamp?: DateTime.Utc | undefined;
|
|
52
50
|
readonly category?: "analytics" | undefined;
|
|
51
|
+
readonly properties?: {
|
|
52
|
+
readonly [x: string]: unknown;
|
|
53
|
+
} | undefined;
|
|
53
54
|
} | {
|
|
54
55
|
readonly eventId?: string | undefined;
|
|
55
56
|
readonly name: string;
|
|
56
|
-
readonly properties?: {
|
|
57
|
-
readonly [x: string]: string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
|
|
58
|
-
} | undefined;
|
|
59
57
|
readonly identity?: {
|
|
60
58
|
readonly userId?: string | undefined;
|
|
61
59
|
readonly organizationId?: string | undefined;
|
|
@@ -67,6 +65,9 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
|
|
|
67
65
|
readonly name: string;
|
|
68
66
|
readonly type: string;
|
|
69
67
|
};
|
|
68
|
+
readonly properties?: {
|
|
69
|
+
readonly [x: string]: unknown;
|
|
70
|
+
} | undefined;
|
|
70
71
|
}) => Effect.Effect<{
|
|
71
72
|
eventId: string;
|
|
72
73
|
inserted: boolean;
|
|
@@ -117,25 +118,8 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
|
|
|
117
118
|
readonly attributes: readonly {
|
|
118
119
|
readonly key: string;
|
|
119
120
|
readonly value: {
|
|
120
|
-
readonly
|
|
121
|
-
|
|
122
|
-
readonly intValue: string | number;
|
|
123
|
-
} | {
|
|
124
|
-
readonly doubleValue: number;
|
|
125
|
-
} | {
|
|
126
|
-
readonly boolValue: boolean;
|
|
127
|
-
} | {
|
|
128
|
-
readonly arrayValue: {
|
|
129
|
-
readonly values: readonly ({
|
|
130
|
-
readonly stringValue: string;
|
|
131
|
-
} | {
|
|
132
|
-
readonly intValue: string | number;
|
|
133
|
-
} | {
|
|
134
|
-
readonly doubleValue: number;
|
|
135
|
-
} | {
|
|
136
|
-
readonly boolValue: boolean;
|
|
137
|
-
})[];
|
|
138
|
-
};
|
|
121
|
+
readonly [x: string]: Schema.Json;
|
|
122
|
+
readonly stringValue?: string | undefined;
|
|
139
123
|
};
|
|
140
124
|
}[];
|
|
141
125
|
}[];
|
|
@@ -145,7 +129,8 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
|
|
|
145
129
|
total: number;
|
|
146
130
|
pageCount: number;
|
|
147
131
|
};
|
|
148
|
-
}, EventsPersistenceError |
|
|
132
|
+
}, EventsPersistenceError | Cause.NoSuchElementError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
133
|
+
subscribe: <E, R>(definition: EventSubscriber<E, R>) => Effect.Effect<undefined, EventsConfigurationError | Schema.SchemaError, R | import("effect/Scope").Scope | WorkflowEngine.WorkflowEngine>;
|
|
149
134
|
}> & {
|
|
150
135
|
readonly make: (options: EventsOptions) => Effect.Effect<{
|
|
151
136
|
process: (body: Uint8Array<ArrayBufferLike>) => Effect.Effect<{
|
|
@@ -155,21 +140,18 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
|
|
|
155
140
|
track: (input: {
|
|
156
141
|
readonly eventId?: string | undefined;
|
|
157
142
|
readonly name: string;
|
|
158
|
-
readonly properties?: {
|
|
159
|
-
readonly [x: string]: string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
|
|
160
|
-
} | undefined;
|
|
161
143
|
readonly identity?: {
|
|
162
144
|
readonly userId?: string | undefined;
|
|
163
145
|
readonly organizationId?: string | undefined;
|
|
164
146
|
} | undefined;
|
|
165
147
|
readonly timestamp?: DateTime.Utc | undefined;
|
|
166
148
|
readonly category?: "analytics" | undefined;
|
|
149
|
+
readonly properties?: {
|
|
150
|
+
readonly [x: string]: unknown;
|
|
151
|
+
} | undefined;
|
|
167
152
|
} | {
|
|
168
153
|
readonly eventId?: string | undefined;
|
|
169
154
|
readonly name: string;
|
|
170
|
-
readonly properties?: {
|
|
171
|
-
readonly [x: string]: string | number | boolean | readonly string[] | readonly number[] | readonly boolean[];
|
|
172
|
-
} | undefined;
|
|
173
155
|
readonly identity?: {
|
|
174
156
|
readonly userId?: string | undefined;
|
|
175
157
|
readonly organizationId?: string | undefined;
|
|
@@ -181,6 +163,9 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
|
|
|
181
163
|
readonly name: string;
|
|
182
164
|
readonly type: string;
|
|
183
165
|
};
|
|
166
|
+
readonly properties?: {
|
|
167
|
+
readonly [x: string]: unknown;
|
|
168
|
+
} | undefined;
|
|
184
169
|
}) => Effect.Effect<{
|
|
185
170
|
eventId: string;
|
|
186
171
|
inserted: boolean;
|
|
@@ -231,25 +216,8 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
|
|
|
231
216
|
readonly attributes: readonly {
|
|
232
217
|
readonly key: string;
|
|
233
218
|
readonly value: {
|
|
234
|
-
readonly
|
|
235
|
-
|
|
236
|
-
readonly intValue: string | number;
|
|
237
|
-
} | {
|
|
238
|
-
readonly doubleValue: number;
|
|
239
|
-
} | {
|
|
240
|
-
readonly boolValue: boolean;
|
|
241
|
-
} | {
|
|
242
|
-
readonly arrayValue: {
|
|
243
|
-
readonly values: readonly ({
|
|
244
|
-
readonly stringValue: string;
|
|
245
|
-
} | {
|
|
246
|
-
readonly intValue: string | number;
|
|
247
|
-
} | {
|
|
248
|
-
readonly doubleValue: number;
|
|
249
|
-
} | {
|
|
250
|
-
readonly boolValue: boolean;
|
|
251
|
-
})[];
|
|
252
|
-
};
|
|
219
|
+
readonly [x: string]: Schema.Json;
|
|
220
|
+
readonly stringValue?: string | undefined;
|
|
253
221
|
};
|
|
254
222
|
}[];
|
|
255
223
|
}[];
|
|
@@ -259,7 +227,8 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
|
|
|
259
227
|
total: number;
|
|
260
228
|
pageCount: number;
|
|
261
229
|
};
|
|
262
|
-
}, EventsPersistenceError |
|
|
230
|
+
}, EventsPersistenceError | Cause.NoSuchElementError | Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
231
|
+
subscribe: <E, R>(definition: EventSubscriber<E, R>) => Effect.Effect<undefined, EventsConfigurationError | Schema.SchemaError, R | import("effect/Scope").Scope | WorkflowEngine.WorkflowEngine>;
|
|
263
232
|
}, EventsConfigurationError, Otlp | OtlpEvents>;
|
|
264
233
|
};
|
|
265
234
|
export declare class Events extends Events_base {
|
|
@@ -270,4 +239,5 @@ export declare class Events extends Events_base {
|
|
|
270
239
|
static readonly layerWith: (options?: Partial<EventsOptions>) => Layer.Layer<Events, Config.ConfigError | EventsConfigurationError | import("effect/sql/Migrator").MigrationError | import("effect/sql/SqlError").SqlError, Otlp | OtlpEvents>;
|
|
271
240
|
static readonly layer: Layer.Layer<Events, Config.ConfigError | EventsConfigurationError | import("effect/sql/Migrator").MigrationError | import("effect/sql/SqlError").SqlError, Otlp | OtlpEvents>;
|
|
272
241
|
static readonly ingestionLayer: Layer.Layer<OtlpLogsProcessor, never, Events>;
|
|
242
|
+
static readonly subscribe: <E, R>(definition: EventSubscriber<E, R>) => Layer.Layer<never, EventsConfigurationError | Schema.SchemaError, Events | WorkflowEngine.WorkflowEngine | Exclude<R, import("effect/Scope").Scope>>;
|
|
273
243
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// ../../src/services/events/index.ts
|
|
2
2
|
import {
|
|
3
|
+
Cause,
|
|
3
4
|
Config as Config2,
|
|
4
5
|
Context as Context4,
|
|
5
6
|
DateTime as DateTime3,
|
|
@@ -9,12 +10,21 @@ import {
|
|
|
9
10
|
Predicate,
|
|
10
11
|
Redacted,
|
|
11
12
|
References as References2,
|
|
12
|
-
|
|
13
|
+
Result,
|
|
14
|
+
Schedule,
|
|
15
|
+
Schema as Schema9,
|
|
16
|
+
Semaphore
|
|
13
17
|
} from "effect";
|
|
14
18
|
import { Digest, SecureRandom as SecureRandom2 } from "effect/crypto";
|
|
15
19
|
import { HttpServerRequest } from "effect/http";
|
|
16
20
|
import { SqlClient as SqlClient2, SqlSchema } from "effect/sql";
|
|
17
21
|
import { Hex } from "effect/encoding";
|
|
22
|
+
import {
|
|
23
|
+
Activity,
|
|
24
|
+
DurableClock,
|
|
25
|
+
Workflow,
|
|
26
|
+
WorkflowEngine
|
|
27
|
+
} from "effect/workflow";
|
|
18
28
|
|
|
19
29
|
// ../../src/services/opentelemetry/processor.ts
|
|
20
30
|
import { Context, Schema } from "effect";
|
|
@@ -91,6 +101,7 @@ var EventAttributeValue = Schema2.Union([
|
|
|
91
101
|
Schema2.Array(Schema2.Boolean)
|
|
92
102
|
]);
|
|
93
103
|
var EventAttributesSchema = Schema2.Record(Schema2.String, EventAttributeValue).annotate({ identifier: "EventAttributes" });
|
|
104
|
+
var EventPropertiesSchema = Schema2.Record(Schema2.String, Schema2.Json).annotate({ identifier: "EventProperties" });
|
|
94
105
|
var EventOptionsSchema = Schema2.Struct({
|
|
95
106
|
userId: Schema2.optional(Schema2.NonEmptyString),
|
|
96
107
|
anonymousId: Schema2.optional(Schema2.NonEmptyString),
|
|
@@ -101,7 +112,7 @@ var EventOptionsSchema = Schema2.Struct({
|
|
|
101
112
|
}).annotate({ identifier: "EventOptions" });
|
|
102
113
|
var TelemetryEvent = Schema2.Struct({
|
|
103
114
|
name: Schema2.NonEmptyString,
|
|
104
|
-
properties: Schema2.optional(
|
|
115
|
+
properties: Schema2.optional(EventPropertiesSchema),
|
|
105
116
|
options: Schema2.optional(EventOptionsSchema)
|
|
106
117
|
}).annotate({ identifier: "TelemetryEvent" });
|
|
107
118
|
|
|
@@ -425,7 +436,7 @@ var AuditTarget = Schema6.Struct({
|
|
|
425
436
|
var trackEventFields = {
|
|
426
437
|
eventId: Schema6.optional(EventId),
|
|
427
438
|
name: Schema6.NonEmptyString.check(Schema6.isMaxLength(128)),
|
|
428
|
-
properties: Schema6.optional(
|
|
439
|
+
properties: Schema6.optional(EventPropertiesSchema),
|
|
429
440
|
identity: Schema6.optional(EventIdentity),
|
|
430
441
|
timestamp: Schema6.optional(Schema6.DateTimeUtc)
|
|
431
442
|
};
|
|
@@ -440,6 +451,24 @@ var TrackEvent = Schema6.Union([
|
|
|
440
451
|
target: AuditTarget
|
|
441
452
|
})
|
|
442
453
|
]).annotate({ identifier: "TrackEvent" });
|
|
454
|
+
var EventInputProperties = Schema6.Record(Schema6.String, Schema6.Unknown).annotate({ identifier: "EventInputProperties" });
|
|
455
|
+
var TrackEventInput = Schema6.Union([
|
|
456
|
+
Schema6.Struct({
|
|
457
|
+
...TrackEvent.members[0].fields,
|
|
458
|
+
properties: Schema6.optional(EventInputProperties)
|
|
459
|
+
}),
|
|
460
|
+
Schema6.Struct({
|
|
461
|
+
...TrackEvent.members[1].fields,
|
|
462
|
+
properties: Schema6.optional(EventInputProperties)
|
|
463
|
+
})
|
|
464
|
+
]).annotate({ identifier: "TrackEventInput" });
|
|
465
|
+
var EventSubscription = Schema6.Struct({
|
|
466
|
+
name: Schema6.NonEmptyString.check(Schema6.isMaxLength(128)),
|
|
467
|
+
events: Schema6.NonEmptyArray(trackEventFields.name)
|
|
468
|
+
}).annotate({ identifier: "EventSubscription" });
|
|
469
|
+
|
|
470
|
+
class EventSubscriberError extends Schema6.TaggedError()("EventSubscriberError", { subscription: Schema6.String }) {
|
|
471
|
+
}
|
|
443
472
|
var EventActionFilter = Schema6.Struct({
|
|
444
473
|
id: Schema6.Literal("eventName"),
|
|
445
474
|
kind: Schema6.Literal("values"),
|
|
@@ -530,7 +559,7 @@ var AttributeValue = Schema6.Union([
|
|
|
530
559
|
]);
|
|
531
560
|
var EventAttribute = Schema6.Struct({
|
|
532
561
|
key: Schema6.NonEmptyString.check(Schema6.isMaxLength(128)),
|
|
533
|
-
value:
|
|
562
|
+
value: Schema6.StructWithRest(Schema6.Struct({ stringValue: Schema6.optional(Schema6.String) }), [Schema6.Record(Schema6.String, Schema6.Json)])
|
|
534
563
|
}).annotate({ identifier: "EventAttribute" });
|
|
535
564
|
var EventLogRecord = Schema6.Struct({
|
|
536
565
|
eventName: Schema6.NonEmptyString.check(Schema6.isMaxLength(128), Schema6.isPattern(/^[^\r\n]+$/)),
|
|
@@ -541,6 +570,13 @@ var EventLogRecord = Schema6.Struct({
|
|
|
541
570
|
spanId: Schema6.optional(Schema6.String.check(Schema6.isPattern(/^[a-f0-9]{16}$/))),
|
|
542
571
|
attributes: Schema6.Array(EventAttribute).check(Schema6.isMaxLength(64), Schema6.makeFilter((values) => new Set(values.map(({ key }) => key)).size === values.length || "Duplicate attribute keys"))
|
|
543
572
|
}).annotate({ identifier: "EventLogRecord" });
|
|
573
|
+
var BrowserEventLogRecord = Schema6.Struct({
|
|
574
|
+
...EventLogRecord.fields,
|
|
575
|
+
attributes: Schema6.Array(Schema6.Struct({
|
|
576
|
+
key: EventAttribute.fields.key,
|
|
577
|
+
value: AttributeValue
|
|
578
|
+
})).check(Schema6.isMaxLength(64), Schema6.makeFilter((values) => new Set(values.map(({ key }) => key)).size === values.length || "Duplicate attribute keys"))
|
|
579
|
+
}).annotate({ identifier: "BrowserEventLogRecord" });
|
|
544
580
|
var extensions = Schema6.Record(Schema6.String, Schema6.Unknown);
|
|
545
581
|
var OtlpLogs = Schema6.StructWithRest(Schema6.Struct({
|
|
546
582
|
resourceLogs: Schema6.Array(Schema6.StructWithRest(Schema6.Struct({
|
|
@@ -849,8 +885,72 @@ class Events extends Context4.Service()("krakstack/events/Events", {
|
|
|
849
885
|
...identity
|
|
850
886
|
};
|
|
851
887
|
});
|
|
888
|
+
const subscribers = new Map;
|
|
889
|
+
const registration = yield* Semaphore.make(1);
|
|
890
|
+
const subscribe = Effect8.fn("Events.subscribe")(function* (definition) {
|
|
891
|
+
const subscription = yield* Schema9.decodeUnknownEffect(EventSubscription)(definition);
|
|
892
|
+
if (Option6.isSome(yield* Effect8.serviceOption(HttpServerRequest.HttpServerRequest)))
|
|
893
|
+
return yield* new EventsConfigurationError({
|
|
894
|
+
message: "Register event subscribers at application startup, not inside an HTTP request"
|
|
895
|
+
});
|
|
896
|
+
if (subscribers.has(subscription.name))
|
|
897
|
+
return yield* new EventsConfigurationError({
|
|
898
|
+
message: `Duplicate event subscriber: ${subscription.name}`
|
|
899
|
+
});
|
|
900
|
+
const engine = yield* WorkflowEngine.WorkflowEngine;
|
|
901
|
+
const subscriberContext = yield* Effect8.context();
|
|
902
|
+
const workflow = Workflow.make(`EventsSubscriberV1/${configuration.serviceName.length}:${configuration.serviceName}/${subscription.name}`, {
|
|
903
|
+
payload: { event: TrackEvent, eventId: EventId },
|
|
904
|
+
success: Schema9.Void,
|
|
905
|
+
error: EventSubscriberError,
|
|
906
|
+
idempotencyKey: ({ eventId }) => eventId
|
|
907
|
+
});
|
|
908
|
+
yield* engine.register(workflow, ({ event, eventId }) => Effect8.gen(function* () {
|
|
909
|
+
const step = yield* Schedule.toStep(Schedule.min([
|
|
910
|
+
Schedule.exponential("5 seconds", 4),
|
|
911
|
+
Schedule.spaced("10 hours")
|
|
912
|
+
]));
|
|
913
|
+
for (let attempt = 0;; attempt++) {
|
|
914
|
+
const result = yield* Activity.make({
|
|
915
|
+
name: `HandleEventV1-${attempt}`,
|
|
916
|
+
success: Schema9.Void,
|
|
917
|
+
error: EventSubscriberError,
|
|
918
|
+
execute: definition.handle({ ...event, eventId }).pipe(Effect8.scoped, Effect8.updateContext((_) => subscriberContext), Effect8.asVoid, Effect8.mapError(() => new EventSubscriberError({
|
|
919
|
+
subscription: subscription.name
|
|
920
|
+
})))
|
|
921
|
+
}).pipe(Effect8.result);
|
|
922
|
+
if (Result.isSuccess(result))
|
|
923
|
+
return;
|
|
924
|
+
if (attempt >= 7)
|
|
925
|
+
return yield* Effect8.fail(result.failure);
|
|
926
|
+
const now = yield* DateTime3.now;
|
|
927
|
+
const [, delay] = yield* step(DateTime3.toEpochMillis(now), result.failure).pipe(Effect8.orDie);
|
|
928
|
+
yield* DurableClock.sleep({
|
|
929
|
+
name: `SubscriberRetryV1-${attempt}`,
|
|
930
|
+
duration: delay,
|
|
931
|
+
inMemoryThreshold: 0
|
|
932
|
+
});
|
|
933
|
+
}
|
|
934
|
+
}));
|
|
935
|
+
const registered = {
|
|
936
|
+
events: new Set(subscription.events),
|
|
937
|
+
dispatch: (event) => workflow.execute({ event, eventId: event.eventId }, { discard: true }).pipe(Effect8.provideService(WorkflowEngine.WorkflowEngine, engine), Effect8.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Effect8.interrupt : Effect8.fail(new EventsPersistenceError({
|
|
938
|
+
operation: "subscriber.dispatch"
|
|
939
|
+
}))), Effect8.asVoid)
|
|
940
|
+
};
|
|
941
|
+
subscribers.set(subscription.name, registered);
|
|
942
|
+
yield* Effect8.addFinalizer(() => Effect8.sync(() => {
|
|
943
|
+
if (subscribers.get(subscription.name) === registered)
|
|
944
|
+
subscribers.delete(subscription.name);
|
|
945
|
+
}));
|
|
946
|
+
}, registration.withPermit);
|
|
852
947
|
const track = Effect8.fn("Events.track")(function* (input) {
|
|
853
|
-
const
|
|
948
|
+
const decoded = yield* Schema9.decodeUnknownEffect(TrackEventInput)(input);
|
|
949
|
+
const properties = decoded.properties === undefined ? undefined : yield* Schema9.encodeEffect(Schema9.fromJsonString(EventInputProperties))(decoded.properties).pipe(Effect8.flatMap(Schema9.decodeUnknownEffect(Schema9.fromJsonString(EventPropertiesSchema))));
|
|
950
|
+
const event = yield* Schema9.decodeUnknownEffect(TrackEvent)({
|
|
951
|
+
...decoded,
|
|
952
|
+
properties
|
|
953
|
+
});
|
|
854
954
|
const eventId = event.eventId ?? (yield* random.uuidV7());
|
|
855
955
|
const category = event.category ?? "analytics";
|
|
856
956
|
const receivedAt = yield* DateTime3.now;
|
|
@@ -924,6 +1024,16 @@ class Events extends Context4.Service()("krakstack/events/Events", {
|
|
|
924
1024
|
]
|
|
925
1025
|
}
|
|
926
1026
|
}) : { eventId, inserted: false };
|
|
1027
|
+
for (const subscriber of subscribers.values()) {
|
|
1028
|
+
if (!subscriber.events.has(event.name))
|
|
1029
|
+
continue;
|
|
1030
|
+
yield* subscriber.dispatch({
|
|
1031
|
+
...event,
|
|
1032
|
+
eventId,
|
|
1033
|
+
identity,
|
|
1034
|
+
timestamp: event.timestamp ?? receivedAt
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
927
1037
|
return {
|
|
928
1038
|
...result,
|
|
929
1039
|
attributes: { ...requestContext, ...attributes }
|
|
@@ -1072,7 +1182,7 @@ class Events extends Context4.Service()("krakstack/events/Events", {
|
|
|
1072
1182
|
return yield* new OtlpProcessingError({ status: 403 });
|
|
1073
1183
|
}
|
|
1074
1184
|
const rawRecords = analyticsScopes.flatMap((scope) => scope.logRecords);
|
|
1075
|
-
const records = yield* Schema9.decodeUnknownEffect(Schema9.Array(
|
|
1185
|
+
const records = yield* Schema9.decodeUnknownEffect(Schema9.Array(BrowserEventLogRecord).check(Schema9.isMinLength(1), Schema9.isMaxLength(100)))(rawRecords).pipe(Effect8.mapError(() => new OtlpProcessingError({ status: 400 })));
|
|
1076
1186
|
const now = yield* DateTime3.now;
|
|
1077
1187
|
const nowMillis = DateTime3.toEpochMillis(now);
|
|
1078
1188
|
for (const record of records) {
|
|
@@ -1173,7 +1283,7 @@ class Events extends Context4.Service()("krakstack/events/Events", {
|
|
|
1173
1283
|
status: error._tag === "EventConflictError" ? 409 : 503
|
|
1174
1284
|
})));
|
|
1175
1285
|
});
|
|
1176
|
-
return { process, track, list };
|
|
1286
|
+
return { process, track, list, subscribe };
|
|
1177
1287
|
})
|
|
1178
1288
|
}) {
|
|
1179
1289
|
static baseLayerWith = (options = {}) => Layer3.effect(this, Effect8.gen(function* () {
|
|
@@ -1199,6 +1309,7 @@ class Events extends Context4.Service()("krakstack/events/Events", {
|
|
|
1199
1309
|
}))));
|
|
1200
1310
|
static layer = this.layerWith();
|
|
1201
1311
|
static ingestionLayer = Layer3.effect(OtlpLogsProcessor, Events);
|
|
1312
|
+
static subscribe = (definition) => Layer3.effectDiscard(Effect8.flatMap(Events, (events) => events.subscribe(definition)));
|
|
1202
1313
|
}
|
|
1203
1314
|
export {
|
|
1204
1315
|
AuditTarget,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
2
|
export declare const EventUuid: Schema.String;
|
|
3
3
|
export declare const EventId: Schema.NonEmptyString;
|
|
4
4
|
export declare const BrowserEventPath: Schema.String;
|
|
@@ -48,7 +48,7 @@ export type AuditTarget = typeof AuditTarget.Type;
|
|
|
48
48
|
export declare const TrackEvent: Schema.Union<readonly [Schema.Struct<{
|
|
49
49
|
readonly eventId: Schema.optional<Schema.NonEmptyString>;
|
|
50
50
|
readonly name: Schema.NonEmptyString;
|
|
51
|
-
readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.
|
|
51
|
+
readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
52
52
|
readonly identity: Schema.optional<Schema.Struct<{
|
|
53
53
|
readonly userId: Schema.optional<Schema.NonEmptyString>;
|
|
54
54
|
readonly organizationId: Schema.optional<Schema.NonEmptyString>;
|
|
@@ -58,7 +58,7 @@ export declare const TrackEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
58
58
|
}>, Schema.Struct<{
|
|
59
59
|
readonly eventId: Schema.optional<Schema.NonEmptyString>;
|
|
60
60
|
readonly name: Schema.NonEmptyString;
|
|
61
|
-
readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.
|
|
61
|
+
readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>>;
|
|
62
62
|
readonly identity: Schema.optional<Schema.Struct<{
|
|
63
63
|
readonly userId: Schema.optional<Schema.NonEmptyString>;
|
|
64
64
|
readonly organizationId: Schema.optional<Schema.NonEmptyString>;
|
|
@@ -72,6 +72,51 @@ export declare const TrackEvent: Schema.Union<readonly [Schema.Struct<{
|
|
|
72
72
|
}>;
|
|
73
73
|
}>]>;
|
|
74
74
|
export type TrackEvent = typeof TrackEvent.Type;
|
|
75
|
+
/** Application snapshots are normalized to JSON before storage or dispatch. */
|
|
76
|
+
export declare const EventInputProperties: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
77
|
+
export declare const TrackEventInput: Schema.Union<readonly [Schema.Struct<{
|
|
78
|
+
readonly eventId: Schema.optional<Schema.NonEmptyString>;
|
|
79
|
+
readonly name: Schema.NonEmptyString;
|
|
80
|
+
readonly identity: Schema.optional<Schema.Struct<{
|
|
81
|
+
readonly userId: Schema.optional<Schema.NonEmptyString>;
|
|
82
|
+
readonly organizationId: Schema.optional<Schema.NonEmptyString>;
|
|
83
|
+
}>>;
|
|
84
|
+
readonly timestamp: Schema.optional<Schema.DateTimeUtc>;
|
|
85
|
+
readonly category: Schema.optional<Schema.Literal<"analytics">>;
|
|
86
|
+
readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
87
|
+
}>, Schema.Struct<{
|
|
88
|
+
readonly eventId: Schema.optional<Schema.NonEmptyString>;
|
|
89
|
+
readonly name: Schema.NonEmptyString;
|
|
90
|
+
readonly identity: Schema.optional<Schema.Struct<{
|
|
91
|
+
readonly userId: Schema.optional<Schema.NonEmptyString>;
|
|
92
|
+
readonly organizationId: Schema.optional<Schema.NonEmptyString>;
|
|
93
|
+
}>>;
|
|
94
|
+
readonly timestamp: Schema.optional<Schema.DateTimeUtc>;
|
|
95
|
+
readonly category: Schema.Literal<"audit">;
|
|
96
|
+
readonly target: Schema.Struct<{
|
|
97
|
+
readonly id: Schema.NonEmptyString;
|
|
98
|
+
readonly name: Schema.NonEmptyString;
|
|
99
|
+
readonly type: Schema.NonEmptyString;
|
|
100
|
+
}>;
|
|
101
|
+
readonly properties: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
102
|
+
}>]>;
|
|
103
|
+
export type TrackEventInput = typeof TrackEventInput.Type;
|
|
104
|
+
export declare const EventSubscription: Schema.Struct<{
|
|
105
|
+
readonly name: Schema.NonEmptyString;
|
|
106
|
+
readonly events: Schema.NonEmptyArray<Schema.NonEmptyString>;
|
|
107
|
+
}>;
|
|
108
|
+
export interface EventSubscriber<E = never, R = never> {
|
|
109
|
+
readonly name: string;
|
|
110
|
+
readonly events: readonly [string, ...string[]];
|
|
111
|
+
readonly handle: (event: TrackEvent & {
|
|
112
|
+
readonly eventId: string;
|
|
113
|
+
}) => Effect.Effect<unknown, E, R>;
|
|
114
|
+
}
|
|
115
|
+
declare const EventSubscriberError_base: Schema.Class<EventSubscriberError, Schema.TaggedStruct<"EventSubscriberError", {
|
|
116
|
+
readonly subscription: Schema.String;
|
|
117
|
+
}>, import("effect/Cause").YieldableError>;
|
|
118
|
+
export declare class EventSubscriberError extends EventSubscriberError_base {
|
|
119
|
+
}
|
|
75
120
|
export declare const EventActionFilter: Schema.Struct<{
|
|
76
121
|
readonly id: Schema.Literal<"eventName">;
|
|
77
122
|
readonly kind: Schema.Literal<"values">;
|
|
@@ -406,29 +451,26 @@ export declare const StoredEventId: Schema.Struct<{
|
|
|
406
451
|
}>;
|
|
407
452
|
export declare const EventAttribute: Schema.Struct<{
|
|
408
453
|
readonly key: Schema.NonEmptyString;
|
|
409
|
-
readonly value: Schema.
|
|
410
|
-
readonly stringValue: Schema.String
|
|
411
|
-
}>, Schema.
|
|
412
|
-
readonly intValue: Schema.Union<readonly [Schema.String, Schema.Int]>;
|
|
413
|
-
}>, Schema.Struct<{
|
|
414
|
-
readonly doubleValue: Schema.Finite;
|
|
415
|
-
}>, Schema.Struct<{
|
|
416
|
-
readonly boolValue: Schema.Boolean;
|
|
417
|
-
}>]>, Schema.Struct<{
|
|
418
|
-
readonly arrayValue: Schema.Struct<{
|
|
419
|
-
readonly values: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
420
|
-
readonly stringValue: Schema.String;
|
|
421
|
-
}>, Schema.Struct<{
|
|
422
|
-
readonly intValue: Schema.Union<readonly [Schema.String, Schema.Int]>;
|
|
423
|
-
}>, Schema.Struct<{
|
|
424
|
-
readonly doubleValue: Schema.Finite;
|
|
425
|
-
}>, Schema.Struct<{
|
|
426
|
-
readonly boolValue: Schema.Boolean;
|
|
427
|
-
}>]>>;
|
|
428
|
-
}>;
|
|
429
|
-
}>]>;
|
|
454
|
+
readonly value: Schema.StructWithRest<Schema.Struct<{
|
|
455
|
+
readonly stringValue: Schema.optional<Schema.String>;
|
|
456
|
+
}>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
430
457
|
}>;
|
|
431
458
|
export declare const EventLogRecord: Schema.Struct<{
|
|
459
|
+
readonly eventName: Schema.NonEmptyString;
|
|
460
|
+
readonly timeUnixNano: Schema.String;
|
|
461
|
+
readonly observedTimeUnixNano: Schema.optional<Schema.String>;
|
|
462
|
+
readonly severityNumber: Schema.optional<Schema.Int>;
|
|
463
|
+
readonly traceId: Schema.optional<Schema.String>;
|
|
464
|
+
readonly spanId: Schema.optional<Schema.String>;
|
|
465
|
+
readonly attributes: Schema.$Array<Schema.Struct<{
|
|
466
|
+
readonly key: Schema.NonEmptyString;
|
|
467
|
+
readonly value: Schema.StructWithRest<Schema.Struct<{
|
|
468
|
+
readonly stringValue: Schema.optional<Schema.String>;
|
|
469
|
+
}>, readonly [Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>]>;
|
|
470
|
+
}>>;
|
|
471
|
+
}>;
|
|
472
|
+
/** Browser ingestion retains the existing primitive-only limits. */
|
|
473
|
+
export declare const BrowserEventLogRecord: Schema.Struct<{
|
|
432
474
|
readonly eventName: Schema.NonEmptyString;
|
|
433
475
|
readonly timeUnixNano: Schema.String;
|
|
434
476
|
readonly observedTimeUnixNano: Schema.optional<Schema.String>;
|