@krak-stack/registry 0.1.56 → 0.1.58

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.
@@ -79,6 +79,30 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
79
79
  readonly id: string;
80
80
  readonly direction: "asc" | "desc";
81
81
  }[] | undefined;
82
+ readonly filters?: readonly ({
83
+ readonly id: string;
84
+ readonly kind: "number";
85
+ readonly min?: number | undefined;
86
+ readonly max?: number | undefined;
87
+ } | {
88
+ readonly id: string;
89
+ readonly kind: "date";
90
+ readonly from?: string | undefined;
91
+ readonly to?: string | undefined;
92
+ } | {
93
+ readonly id: string;
94
+ readonly kind: "text";
95
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
96
+ readonly value: string;
97
+ } | {
98
+ readonly id: string;
99
+ readonly kind: "boolean";
100
+ readonly value: boolean;
101
+ } | {
102
+ readonly id: string;
103
+ readonly kind: "values";
104
+ readonly values: readonly [string, ...string[]];
105
+ })[] | undefined;
82
106
  readonly eventName?: string | undefined;
83
107
  readonly organizationId: string;
84
108
  readonly category: "analytics" | "audit";
@@ -169,6 +193,30 @@ declare const Events_base: Context.ServiceClass<Events, "krakstack/events/Events
169
193
  readonly id: string;
170
194
  readonly direction: "asc" | "desc";
171
195
  }[] | undefined;
196
+ readonly filters?: readonly ({
197
+ readonly id: string;
198
+ readonly kind: "number";
199
+ readonly min?: number | undefined;
200
+ readonly max?: number | undefined;
201
+ } | {
202
+ readonly id: string;
203
+ readonly kind: "date";
204
+ readonly from?: string | undefined;
205
+ readonly to?: string | undefined;
206
+ } | {
207
+ readonly id: string;
208
+ readonly kind: "text";
209
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
210
+ readonly value: string;
211
+ } | {
212
+ readonly id: string;
213
+ readonly kind: "boolean";
214
+ readonly value: boolean;
215
+ } | {
216
+ readonly id: string;
217
+ readonly kind: "values";
218
+ readonly values: readonly [string, ...string[]];
219
+ })[] | undefined;
172
220
  readonly eventName?: string | undefined;
173
221
  readonly organizationId: string;
174
222
  readonly category: "analytics" | "audit";
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  Config as Config2,
4
4
  Context as Context4,
5
- DateTime as DateTime2,
5
+ DateTime as DateTime3,
6
6
  Effect as Effect8,
7
7
  Layer as Layer3,
8
8
  Option as Option6,
@@ -219,6 +219,7 @@ import { Effect as Effect5, Option as Option3, Schema as Schema6 } from "effect"
219
219
 
220
220
  // ../../src/lib/query.ts
221
221
  import {
222
+ DateTime as DateTime2,
222
223
  Effect as Effect4,
223
224
  Option as Option2,
224
225
  Schema as Schema5,
@@ -299,6 +300,49 @@ var SortParams = Schema5.declare(Schema5.is(SortParamsArray), {
299
300
  toCodec: () => Schema5.link()(SortParamsArray, SchemaTransformation.passthrough()),
300
301
  toCodecStringTree: () => Schema5.link()(SortParamsFromString, SchemaTransformation.passthrough())
301
302
  });
303
+ var TextFilterOperator = Schema5.Literals([
304
+ "contains",
305
+ "equals",
306
+ "startsWith",
307
+ "endsWith"
308
+ ]).annotate({ identifier: "TextFilterOperator" });
309
+ var FilterCalendarDate = Schema5.String.check(Schema5.isPattern(/^\d{4}-\d{2}-\d{2}$/), Schema5.makeFilter((value) => Option2.exists(DateTime2.make(value), (date) => DateTime2.formatIsoDateUtc(date) === value))).annotate({ identifier: "FilterCalendarDate" });
310
+ var ColumnFilter = Schema5.Union([
311
+ Schema5.Struct({
312
+ id: Schema5.NonEmptyString,
313
+ kind: Schema5.Literal("text"),
314
+ operator: TextFilterOperator,
315
+ value: Schema5.NonEmptyString
316
+ }),
317
+ Schema5.Struct({
318
+ id: Schema5.NonEmptyString,
319
+ kind: Schema5.Literal("number"),
320
+ min: Schema5.optional(Schema5.Finite),
321
+ max: Schema5.optional(Schema5.Finite)
322
+ }).check(Schema5.makeFilter((range) => (range.min !== undefined || range.max !== undefined) && (range.min === undefined || range.max === undefined || range.min <= range.max))),
323
+ Schema5.Struct({
324
+ id: Schema5.NonEmptyString,
325
+ kind: Schema5.Literal("date"),
326
+ from: Schema5.optional(FilterCalendarDate),
327
+ to: Schema5.optional(FilterCalendarDate)
328
+ }).check(Schema5.makeFilter((range) => (range.from !== undefined || range.to !== undefined) && (range.from === undefined || range.to === undefined || range.from <= range.to))),
329
+ Schema5.Struct({
330
+ id: Schema5.NonEmptyString,
331
+ kind: Schema5.Literal("boolean"),
332
+ value: Schema5.Boolean
333
+ }),
334
+ Schema5.Struct({
335
+ id: Schema5.NonEmptyString,
336
+ kind: Schema5.Literal("values"),
337
+ values: Schema5.NonEmptyArray(Schema5.String)
338
+ })
339
+ ]).annotate({ identifier: "ColumnFilter" });
340
+ var ColumnFiltersArray = Schema5.Array(ColumnFilter);
341
+ var ColumnFilters = Schema5.declare(Schema5.is(ColumnFiltersArray), {
342
+ identifier: "ColumnFilters",
343
+ toCodec: () => Schema5.link()(ColumnFiltersArray, SchemaTransformation.passthrough()),
344
+ toCodecStringTree: () => Schema5.link()(Schema5.fromJsonString(ColumnFiltersArray), SchemaTransformation.passthrough())
345
+ });
302
346
  var Query = Schema5.Struct({
303
347
  page: Schema5.optional(Schema5.Union([Schema5.Number, Schema5.NumberFromString]).check(Schema5.isInt(), Schema5.isGreaterThanOrEqualTo(0))).pipe(Schema5.decodeTo(Schema5.Int.check(Schema5.isGreaterThanOrEqualTo(0)), {
304
348
  decode: SchemaGetter.withDefault(Effect4.succeed(0)),
@@ -309,7 +353,8 @@ var Query = Schema5.Struct({
309
353
  encode: SchemaGetter.transformOptional(Option2.filter((pageSize) => pageSize !== 20))
310
354
  })),
311
355
  globalFilter: Schema5.optional(Schema5.String),
312
- sort: Schema5.optional(SortParams)
356
+ sort: Schema5.optional(SortParams),
357
+ filters: Schema5.optional(ColumnFilters)
313
358
  }).annotate({
314
359
  identifier: "Query",
315
360
  title: "Query",
@@ -395,8 +440,16 @@ var TrackEvent = Schema6.Union([
395
440
  target: AuditTarget
396
441
  })
397
442
  ]).annotate({ identifier: "TrackEvent" });
443
+ var EventActionFilter = Schema6.Struct({
444
+ id: Schema6.Literal("eventName"),
445
+ kind: Schema6.Literal("values"),
446
+ values: Schema6.NonEmptyArray(trackEventFields.name)
447
+ }).annotate({ identifier: "EventActionFilter" });
448
+ var EventColumnFilter = ColumnFilter.check(Schema6.makeFilter((filter) => filter.id === "eventName" ? Schema6.is(EventActionFilter)(filter) : filter.id === "time" ? filter.kind === "date" : filter.id === "actor" || filter.id === "record" ? filter.kind === "text" : filter.id === "method" ? filter.kind === "values" && filter.values.every((value) => ["session", "api_key", "unknown"].includes(value)) : false)).annotate({ identifier: "EventColumnFilter" });
449
+ var EventColumnFilters = ColumnFilters.check(Schema6.makeFilter((filters) => filters.every(Schema6.is(EventColumnFilter)))).annotate({ identifier: "EventColumnFilters" });
398
450
  var EventQuery = Schema6.Struct({
399
451
  ...Query.fields,
452
+ filters: Schema6.optional(EventColumnFilters),
400
453
  eventName: Schema6.optional(trackEventFields.name)
401
454
  }).annotate({ identifier: "EventQuery" });
402
455
  var EventQueryStandard = Schema6.toStandardSchemaV1(EventQuery);
@@ -776,13 +829,13 @@ class Events extends Context4.Service()("krakstack/events/Events", {
776
829
  secret: options.secret,
777
830
  ip: location2.ip,
778
831
  userAgent,
779
- day: DateTime2.formatIsoDate(now)
832
+ day: DateTime3.formatIsoDate(now)
780
833
  }) : undefined;
781
834
  let sessionId;
782
835
  if (visitorId && storage) {
783
836
  yield* storage.lockVisitor(visitorId);
784
837
  const latest = yield* storage.latestSession({ visitorId });
785
- sessionId = Option6.isSome(latest) && latest.value.received_at > DateTime2.toEpochMillis(now) - SESSION_TIMEOUT_MS ? latest.value.session_id : yield* random.uuidV7();
838
+ sessionId = Option6.isSome(latest) && latest.value.received_at > DateTime3.toEpochMillis(now) - SESSION_TIMEOUT_MS ? latest.value.session_id : yield* random.uuidV7();
786
839
  }
787
840
  const identity = {};
788
841
  if (visitorId)
@@ -800,8 +853,8 @@ class Events extends Context4.Service()("krakstack/events/Events", {
800
853
  const event = yield* Schema9.decodeUnknownEffect(TrackEvent)(input);
801
854
  const eventId = event.eventId ?? (yield* random.uuidV7());
802
855
  const category = event.category ?? "analytics";
803
- const receivedAt = yield* DateTime2.now;
804
- const now = DateTime2.toEpochMillis(receivedAt);
856
+ const receivedAt = yield* DateTime3.now;
857
+ const now = DateTime3.toEpochMillis(receivedAt);
805
858
  const request = yield* Effect8.serviceOption(HttpServerRequest.HttpServerRequest);
806
859
  const annotations = yield* References2.CurrentLogAnnotations;
807
860
  if (category === "analytics" && options.requireConsent && (Option6.isNone(request) || !hasAnalyticsConsent(request.value.headers.cookie ?? "", request.value.headers))) {
@@ -841,7 +894,7 @@ class Events extends Context4.Service()("krakstack/events/Events", {
841
894
  const location2 = Option6.isSome(request) && (!options.requireConsent || hasAnalyticsConsent(request.value.headers.cookie ?? "", request.value.headers)) ? yield* resolveGeolocation(request.value).pipe(Effect8.mapError(() => new EventsPersistenceError({ operation: "geolocation" }))) : null;
842
895
  const entry = {
843
896
  eventName: event.name,
844
- timeUnixNano: (BigInt(event.timestamp ? DateTime2.toEpochMillis(event.timestamp) : now) * 1000000n).toString(),
897
+ timeUnixNano: (BigInt(event.timestamp ? DateTime3.toEpochMillis(event.timestamp) : now) * 1000000n).toString(),
845
898
  observedTimeUnixNano: (BigInt(now) * 1000000n).toString()
846
899
  };
847
900
  return yield* Effect8.gen(function* () {
@@ -889,6 +942,7 @@ class Events extends Context4.Service()("krakstack/events/Events", {
889
942
  });
890
943
  const list = Effect8.fn("Events.list")(function* (input) {
891
944
  const request = yield* Schema9.decodeUnknownEffect(ListEvents)(input);
945
+ const columnFilters = yield* Schema9.decodeUnknownEffect(Schema9.Array(EventColumnFilter))(request.filters ?? []);
892
946
  if (!storage)
893
947
  return yield* new EventsPersistenceError({
894
948
  operation: "persistence-disabled"
@@ -917,6 +971,35 @@ class Events extends Context4.Service()("krakstack/events/Events", {
917
971
  }));
918
972
  const source = request.category === "audit" ? sql`AND source = 'server'` : sql``;
919
973
  const event = request.eventName ? sql`AND event_name = ${request.eventName}` : sql``;
974
+ const actorName = sql`COALESCE(NULLIF(${text("user.full_name")}, ''), NULLIF(${text("user.name")}, ''), NULLIF(${text("user.email")}, ''), ${text("app.actor.type")}, '')`;
975
+ const actor = sql`${actorName} || ' ' || COALESCE(${text("user.email")}, '') || ' ' || COALESCE(${text("app.actor.id")}, ${text("user.id")}, '')`;
976
+ const record = sql`COALESCE(${text("app.audit.target.name")}, '') || ' ' || COALESCE(${text("app.audit.target.type")}, '') || ' ' || COALESCE(${text("app.audit.target.id")}, '')`;
977
+ const method = sql`CASE WHEN ${text("app.auth.method")} IN ('session', 'api_key') THEN ${text("app.auth.method")} ELSE 'unknown' END`;
978
+ const predicates = columnFilters.map((filter) => {
979
+ switch (filter.kind) {
980
+ case "values": {
981
+ const column = filter.id === "eventName" ? sql`event_name` : method;
982
+ return sql`AND ${sql.or(filter.values.map((value) => sql`${column} = ${value}`))}`;
983
+ }
984
+ case "date": {
985
+ const from = filter.from ? sql`AND occurred_at >= ${new Date(`${filter.from}T00:00:00.000Z`).getTime()}` : sql``;
986
+ const to = filter.to ? sql`AND occurred_at < ${new Date(`${filter.to}T00:00:00.000Z`).getTime() + 86400000}` : sql``;
987
+ return sql`${from} ${to}`;
988
+ }
989
+ case "text": {
990
+ const column = filter.id === "actor" ? actor : record;
991
+ const value = filter.value.toLowerCase();
992
+ if (filter.operator === "equals")
993
+ return sql`AND LOWER(${column}) = ${value}`;
994
+ const escaped = value.replace(/[\\%_]/g, "\\$&");
995
+ const pattern = filter.operator === "startsWith" ? `${escaped}%` : filter.operator === "endsWith" ? `%${escaped}` : `%${escaped}%`;
996
+ return sql`AND LOWER(${column}) LIKE ${pattern} ESCAPE ${"\\"}`;
997
+ }
998
+ default:
999
+ return sql``;
1000
+ }
1001
+ });
1002
+ const actions = sql.join(" ", false)(predicates);
920
1003
  const search = request.globalFilter?.trim();
921
1004
  const filter = search ? sql`AND ${sql.or([
922
1005
  sql`LOWER(event_name) LIKE ${`%${search.toLowerCase()}%`}`,
@@ -930,7 +1013,7 @@ class Events extends Context4.Service()("krakstack/events/Events", {
930
1013
  ].map((key) => sql`LOWER(${text(key)}) LIKE ${`%${search.toLowerCase()}%`}`)
931
1014
  ])}` : sql``;
932
1015
  const predicate = sql`service_name = ${configuration.serviceName} AND organization_id = ${request.organizationId}
933
- AND ${text("app.event.category")} = ${request.category} ${source} ${event} ${filter}`;
1016
+ AND ${text("app.event.category")} = ${request.category} ${source} ${event} ${actions} ${filter}`;
934
1017
  const total = yield* SqlSchema.findOne({
935
1018
  Request: ListEvents,
936
1019
  Result: AuditCount,
@@ -990,8 +1073,8 @@ class Events extends Context4.Service()("krakstack/events/Events", {
990
1073
  }
991
1074
  const rawRecords = analyticsScopes.flatMap((scope) => scope.logRecords);
992
1075
  const records = yield* Schema9.decodeUnknownEffect(Schema9.Array(EventLogRecord).check(Schema9.isMinLength(1), Schema9.isMaxLength(100)))(rawRecords).pipe(Effect8.mapError(() => new OtlpProcessingError({ status: 400 })));
993
- const now = yield* DateTime2.now;
994
- const nowMillis = DateTime2.toEpochMillis(now);
1076
+ const now = yield* DateTime3.now;
1077
+ const nowMillis = DateTime3.toEpochMillis(now);
995
1078
  for (const record of records) {
996
1079
  const timestamp = BigInt(record.timeUnixNano) / 1000000n;
997
1080
  if (timestamp < BigInt(nowMillis - 60 * 60 * 1000) || timestamp > BigInt(nowMillis + 60000) || textAttribute(record, "app.event.schema.version") !== "1" || Option6.isNone(Schema9.decodeUnknownOption(EventUuid)(textAttribute(record, "analytics.page_view.id"))) || Option6.isNone(Schema9.decodeUnknownOption(EventId)(textAttribute(record, "log.record.uid"))) || Option6.isNone(Schema9.decodeUnknownOption(BrowserEventPath)(textAttribute(record, "url.path")))) {
@@ -72,6 +72,35 @@ export declare const TrackEvent: Schema.Union<readonly [Schema.Struct<{
72
72
  }>;
73
73
  }>]>;
74
74
  export type TrackEvent = typeof TrackEvent.Type;
75
+ export declare const EventActionFilter: Schema.Struct<{
76
+ readonly id: Schema.Literal<"eventName">;
77
+ readonly kind: Schema.Literal<"values">;
78
+ readonly values: Schema.NonEmptyArray<Schema.NonEmptyString>;
79
+ }>;
80
+ export declare const EventColumnFilter: Schema.Union<readonly [Schema.Struct<{
81
+ readonly id: Schema.NonEmptyString;
82
+ readonly kind: Schema.Literal<"text">;
83
+ readonly operator: Schema.Literals<readonly ["contains", "equals", "startsWith", "endsWith"]>;
84
+ readonly value: Schema.NonEmptyString;
85
+ }>, Schema.Struct<{
86
+ readonly id: Schema.NonEmptyString;
87
+ readonly kind: Schema.Literal<"number">;
88
+ readonly min: Schema.optional<Schema.Finite>;
89
+ readonly max: Schema.optional<Schema.Finite>;
90
+ }>, Schema.Struct<{
91
+ readonly id: Schema.NonEmptyString;
92
+ readonly kind: Schema.Literal<"date">;
93
+ readonly from: Schema.optional<Schema.String>;
94
+ readonly to: Schema.optional<Schema.String>;
95
+ }>, Schema.Struct<{
96
+ readonly id: Schema.NonEmptyString;
97
+ readonly kind: Schema.Literal<"boolean">;
98
+ readonly value: Schema.Boolean;
99
+ }>, Schema.Struct<{
100
+ readonly id: Schema.NonEmptyString;
101
+ readonly kind: Schema.Literal<"values">;
102
+ readonly values: Schema.NonEmptyArray<Schema.String>;
103
+ }>]>;
75
104
  export declare const EventQuery: Schema.Struct<{
76
105
  readonly page: Schema.decodeTo<Schema.Int, Schema.optional<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
77
106
  readonly pageSize: Schema.decodeTo<Schema.Int, Schema.optional<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
@@ -83,6 +112,53 @@ export declare const EventQuery: Schema.Struct<{
83
112
  readonly id: string;
84
113
  readonly direction: "asc" | "desc";
85
114
  }[]>>;
115
+ readonly filters: Schema.optional<Schema.declare<readonly ({
116
+ readonly id: string;
117
+ readonly kind: "number";
118
+ readonly min?: number | undefined;
119
+ readonly max?: number | undefined;
120
+ } | {
121
+ readonly id: string;
122
+ readonly kind: "date";
123
+ readonly from?: string | undefined;
124
+ readonly to?: string | undefined;
125
+ } | {
126
+ readonly id: string;
127
+ readonly kind: "text";
128
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
129
+ readonly value: string;
130
+ } | {
131
+ readonly id: string;
132
+ readonly kind: "boolean";
133
+ readonly value: boolean;
134
+ } | {
135
+ readonly id: string;
136
+ readonly kind: "values";
137
+ readonly values: readonly [string, ...string[]];
138
+ })[], readonly ({
139
+ readonly id: string;
140
+ readonly kind: "number";
141
+ readonly min?: number | undefined;
142
+ readonly max?: number | undefined;
143
+ } | {
144
+ readonly id: string;
145
+ readonly kind: "date";
146
+ readonly from?: string | undefined;
147
+ readonly to?: string | undefined;
148
+ } | {
149
+ readonly id: string;
150
+ readonly kind: "text";
151
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
152
+ readonly value: string;
153
+ } | {
154
+ readonly id: string;
155
+ readonly kind: "boolean";
156
+ readonly value: boolean;
157
+ } | {
158
+ readonly id: string;
159
+ readonly kind: "values";
160
+ readonly values: readonly [string, ...string[]];
161
+ })[]>>;
86
162
  /** Exact, case-sensitive event name; combined with category and query filters. */
87
163
  readonly eventName: Schema.optional<Schema.NonEmptyString>;
88
164
  }>;
@@ -95,6 +171,30 @@ export declare const EventQueryStandard: import("effect/StandardSchema").Standar
95
171
  readonly id: string;
96
172
  readonly direction: "asc" | "desc";
97
173
  }[] | undefined;
174
+ readonly filters?: readonly ({
175
+ readonly id: string;
176
+ readonly kind: "number";
177
+ readonly min?: number | undefined;
178
+ readonly max?: number | undefined;
179
+ } | {
180
+ readonly id: string;
181
+ readonly kind: "date";
182
+ readonly from?: string | undefined;
183
+ readonly to?: string | undefined;
184
+ } | {
185
+ readonly id: string;
186
+ readonly kind: "text";
187
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
188
+ readonly value: string;
189
+ } | {
190
+ readonly id: string;
191
+ readonly kind: "boolean";
192
+ readonly value: boolean;
193
+ } | {
194
+ readonly id: string;
195
+ readonly kind: "values";
196
+ readonly values: readonly [string, ...string[]];
197
+ })[] | undefined;
98
198
  readonly eventName?: string | undefined;
99
199
  }, {
100
200
  readonly page: number;
@@ -104,6 +204,30 @@ export declare const EventQueryStandard: import("effect/StandardSchema").Standar
104
204
  readonly id: string;
105
205
  readonly direction: "asc" | "desc";
106
206
  }[] | undefined;
207
+ readonly filters?: readonly ({
208
+ readonly id: string;
209
+ readonly kind: "number";
210
+ readonly min?: number | undefined;
211
+ readonly max?: number | undefined;
212
+ } | {
213
+ readonly id: string;
214
+ readonly kind: "date";
215
+ readonly from?: string | undefined;
216
+ readonly to?: string | undefined;
217
+ } | {
218
+ readonly id: string;
219
+ readonly kind: "text";
220
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
221
+ readonly value: string;
222
+ } | {
223
+ readonly id: string;
224
+ readonly kind: "boolean";
225
+ readonly value: boolean;
226
+ } | {
227
+ readonly id: string;
228
+ readonly kind: "values";
229
+ readonly values: readonly [string, ...string[]];
230
+ })[] | undefined;
107
231
  readonly eventName?: string | undefined;
108
232
  }> & Schema.Struct<{
109
233
  readonly page: Schema.decodeTo<Schema.Int, Schema.optional<Schema.Union<readonly [Schema.Number, Schema.NumberFromString]>>, never, never>;
@@ -116,6 +240,53 @@ export declare const EventQueryStandard: import("effect/StandardSchema").Standar
116
240
  readonly id: string;
117
241
  readonly direction: "asc" | "desc";
118
242
  }[]>>;
243
+ readonly filters: Schema.optional<Schema.declare<readonly ({
244
+ readonly id: string;
245
+ readonly kind: "number";
246
+ readonly min?: number | undefined;
247
+ readonly max?: number | undefined;
248
+ } | {
249
+ readonly id: string;
250
+ readonly kind: "date";
251
+ readonly from?: string | undefined;
252
+ readonly to?: string | undefined;
253
+ } | {
254
+ readonly id: string;
255
+ readonly kind: "text";
256
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
257
+ readonly value: string;
258
+ } | {
259
+ readonly id: string;
260
+ readonly kind: "boolean";
261
+ readonly value: boolean;
262
+ } | {
263
+ readonly id: string;
264
+ readonly kind: "values";
265
+ readonly values: readonly [string, ...string[]];
266
+ })[], readonly ({
267
+ readonly id: string;
268
+ readonly kind: "number";
269
+ readonly min?: number | undefined;
270
+ readonly max?: number | undefined;
271
+ } | {
272
+ readonly id: string;
273
+ readonly kind: "date";
274
+ readonly from?: string | undefined;
275
+ readonly to?: string | undefined;
276
+ } | {
277
+ readonly id: string;
278
+ readonly kind: "text";
279
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
280
+ readonly value: string;
281
+ } | {
282
+ readonly id: string;
283
+ readonly kind: "boolean";
284
+ readonly value: boolean;
285
+ } | {
286
+ readonly id: string;
287
+ readonly kind: "values";
288
+ readonly values: readonly [string, ...string[]];
289
+ })[]>>;
119
290
  /** Exact, case-sensitive event name; combined with category and query filters. */
120
291
  readonly eventName: Schema.optional<Schema.NonEmptyString>;
121
292
  }>;
@@ -130,6 +301,53 @@ export declare const ListEvents: Schema.Struct<{
130
301
  readonly id: string;
131
302
  readonly direction: "asc" | "desc";
132
303
  }[]>>;
304
+ readonly filters: Schema.optional<Schema.declare<readonly ({
305
+ readonly id: string;
306
+ readonly kind: "number";
307
+ readonly min?: number | undefined;
308
+ readonly max?: number | undefined;
309
+ } | {
310
+ readonly id: string;
311
+ readonly kind: "date";
312
+ readonly from?: string | undefined;
313
+ readonly to?: string | undefined;
314
+ } | {
315
+ readonly id: string;
316
+ readonly kind: "text";
317
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
318
+ readonly value: string;
319
+ } | {
320
+ readonly id: string;
321
+ readonly kind: "boolean";
322
+ readonly value: boolean;
323
+ } | {
324
+ readonly id: string;
325
+ readonly kind: "values";
326
+ readonly values: readonly [string, ...string[]];
327
+ })[], readonly ({
328
+ readonly id: string;
329
+ readonly kind: "number";
330
+ readonly min?: number | undefined;
331
+ readonly max?: number | undefined;
332
+ } | {
333
+ readonly id: string;
334
+ readonly kind: "date";
335
+ readonly from?: string | undefined;
336
+ readonly to?: string | undefined;
337
+ } | {
338
+ readonly id: string;
339
+ readonly kind: "text";
340
+ readonly operator: "contains" | "endsWith" | "equals" | "startsWith";
341
+ readonly value: string;
342
+ } | {
343
+ readonly id: string;
344
+ readonly kind: "boolean";
345
+ readonly value: boolean;
346
+ } | {
347
+ readonly id: string;
348
+ readonly kind: "values";
349
+ readonly values: readonly [string, ...string[]];
350
+ })[]>>;
133
351
  /** Exact, case-sensitive event name; combined with category and query filters. */
134
352
  readonly eventName: Schema.optional<Schema.NonEmptyString>;
135
353
  readonly organizationId: Schema.NonEmptyString;
@@ -53,6 +53,7 @@ var TelemetryEvent = Schema.Struct({
53
53
 
54
54
  // ../../src/lib/query.ts
55
55
  import {
56
+ DateTime,
56
57
  Effect,
57
58
  Option,
58
59
  Schema as Schema2,
@@ -133,6 +134,49 @@ var SortParams = Schema2.declare(Schema2.is(SortParamsArray), {
133
134
  toCodec: () => Schema2.link()(SortParamsArray, SchemaTransformation.passthrough()),
134
135
  toCodecStringTree: () => Schema2.link()(SortParamsFromString, SchemaTransformation.passthrough())
135
136
  });
137
+ var TextFilterOperator = Schema2.Literals([
138
+ "contains",
139
+ "equals",
140
+ "startsWith",
141
+ "endsWith"
142
+ ]).annotate({ identifier: "TextFilterOperator" });
143
+ var FilterCalendarDate = Schema2.String.check(Schema2.isPattern(/^\d{4}-\d{2}-\d{2}$/), Schema2.makeFilter((value) => Option.exists(DateTime.make(value), (date) => DateTime.formatIsoDateUtc(date) === value))).annotate({ identifier: "FilterCalendarDate" });
144
+ var ColumnFilter = Schema2.Union([
145
+ Schema2.Struct({
146
+ id: Schema2.NonEmptyString,
147
+ kind: Schema2.Literal("text"),
148
+ operator: TextFilterOperator,
149
+ value: Schema2.NonEmptyString
150
+ }),
151
+ Schema2.Struct({
152
+ id: Schema2.NonEmptyString,
153
+ kind: Schema2.Literal("number"),
154
+ min: Schema2.optional(Schema2.Finite),
155
+ max: Schema2.optional(Schema2.Finite)
156
+ }).check(Schema2.makeFilter((range) => (range.min !== undefined || range.max !== undefined) && (range.min === undefined || range.max === undefined || range.min <= range.max))),
157
+ Schema2.Struct({
158
+ id: Schema2.NonEmptyString,
159
+ kind: Schema2.Literal("date"),
160
+ from: Schema2.optional(FilterCalendarDate),
161
+ to: Schema2.optional(FilterCalendarDate)
162
+ }).check(Schema2.makeFilter((range) => (range.from !== undefined || range.to !== undefined) && (range.from === undefined || range.to === undefined || range.from <= range.to))),
163
+ Schema2.Struct({
164
+ id: Schema2.NonEmptyString,
165
+ kind: Schema2.Literal("boolean"),
166
+ value: Schema2.Boolean
167
+ }),
168
+ Schema2.Struct({
169
+ id: Schema2.NonEmptyString,
170
+ kind: Schema2.Literal("values"),
171
+ values: Schema2.NonEmptyArray(Schema2.String)
172
+ })
173
+ ]).annotate({ identifier: "ColumnFilter" });
174
+ var ColumnFiltersArray = Schema2.Array(ColumnFilter);
175
+ var ColumnFilters = Schema2.declare(Schema2.is(ColumnFiltersArray), {
176
+ identifier: "ColumnFilters",
177
+ toCodec: () => Schema2.link()(ColumnFiltersArray, SchemaTransformation.passthrough()),
178
+ toCodecStringTree: () => Schema2.link()(Schema2.fromJsonString(ColumnFiltersArray), SchemaTransformation.passthrough())
179
+ });
136
180
  var Query = Schema2.Struct({
137
181
  page: Schema2.optional(Schema2.Union([Schema2.Number, Schema2.NumberFromString]).check(Schema2.isInt(), Schema2.isGreaterThanOrEqualTo(0))).pipe(Schema2.decodeTo(Schema2.Int.check(Schema2.isGreaterThanOrEqualTo(0)), {
138
182
  decode: SchemaGetter.withDefault(Effect.succeed(0)),
@@ -143,7 +187,8 @@ var Query = Schema2.Struct({
143
187
  encode: SchemaGetter.transformOptional(Option.filter((pageSize) => pageSize !== 20))
144
188
  })),
145
189
  globalFilter: Schema2.optional(Schema2.String),
146
- sort: Schema2.optional(SortParams)
190
+ sort: Schema2.optional(SortParams),
191
+ filters: Schema2.optional(ColumnFilters)
147
192
  }).annotate({
148
193
  identifier: "Query",
149
194
  title: "Query",
@@ -229,8 +274,16 @@ var TrackEvent = Schema3.Union([
229
274
  target: AuditTarget
230
275
  })
231
276
  ]).annotate({ identifier: "TrackEvent" });
277
+ var EventActionFilter = Schema3.Struct({
278
+ id: Schema3.Literal("eventName"),
279
+ kind: Schema3.Literal("values"),
280
+ values: Schema3.NonEmptyArray(trackEventFields.name)
281
+ }).annotate({ identifier: "EventActionFilter" });
282
+ var EventColumnFilter = ColumnFilter.check(Schema3.makeFilter((filter) => filter.id === "eventName" ? Schema3.is(EventActionFilter)(filter) : filter.id === "time" ? filter.kind === "date" : filter.id === "actor" || filter.id === "record" ? filter.kind === "text" : filter.id === "method" ? filter.kind === "values" && filter.values.every((value) => ["session", "api_key", "unknown"].includes(value)) : false)).annotate({ identifier: "EventColumnFilter" });
283
+ var EventColumnFilters = ColumnFilters.check(Schema3.makeFilter((filters) => filters.every(Schema3.is(EventColumnFilter)))).annotate({ identifier: "EventColumnFilters" });
232
284
  var EventQuery = Schema3.Struct({
233
285
  ...Query.fields,
286
+ filters: Schema3.optional(EventColumnFilters),
234
287
  eventName: Schema3.optional(trackEventFields.name)
235
288
  }).annotate({ identifier: "EventQuery" });
236
289
  var EventQueryStandard = Schema3.toStandardSchemaV1(EventQuery);
@@ -350,8 +403,10 @@ export {
350
403
  BrowserEventOptions,
351
404
  BrowserEventPath,
352
405
  BrowserPage,
406
+ EventActionFilter,
353
407
  EventAttribute,
354
408
  EventCity,
409
+ EventColumnFilter,
355
410
  EventConflictError,
356
411
  EventCountry,
357
412
  EventGeolocation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {