@knime/hub-features 1.26.2 → 1.27.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.
@@ -1,62 +1,35 @@
1
1
  import type { AnalyticsEventSchema } from "./schema/schema";
2
2
 
3
- export const SEPARATOR = "::";
4
- type Separator = typeof SEPARATOR;
5
-
6
- type EventDefinitions = AnalyticsEventSchema["events"];
3
+ export type DefaultContext = Record<string, string | boolean | number>;
4
+ export type Metadata = Omit<AnalyticsEventSchema, "events">;
7
5
 
8
- /**
9
- * Group names (top-level keys in `events`, e.g. "kai_prompted").
10
- */
11
- type GroupName = keyof EventDefinitions;
6
+ type NewEvents = AnalyticsEventSchema["events"];
7
+ type EventNames = keyof NewEvents;
12
8
 
13
9
  /**
14
- * Event names in the flattened "group::event" form. This makes event calls
15
- * single keys using the `::` separator (for example "kai_prompted::kaiqa_button_prompt").
10
+ * These are fields that are present on every event, but their values are generated at runtime
16
11
  */
17
- export type EventNames = {
18
- [G in GroupName]: `${G}${Separator}${keyof EventDefinitions[G] & string}`;
19
- }[GroupName];
20
-
21
- export type Metadata = Omit<AnalyticsEventSchema, "events">;
22
-
23
- export type Context = { jobId: string };
12
+ export type GeneratedStaticFields = {
13
+ unique_event_id: string;
14
+ timestamp: string;
15
+ };
24
16
 
25
17
  /**
26
- * Resolve the payload type for a flattened event name like
27
- * "group::eventKey". If the referenced payload is `null`, the args are
28
- * just the type; otherwise a payload must be provided.
18
+ * These are fields that are present on every event, but their values are statically set for each
19
+ * event in the schema file
29
20
  */
30
- type PayloadFor<KN extends EventNames> =
31
- KN extends `${infer G}${Separator}${infer E}`
32
- ? G extends GroupName
33
- ? E extends keyof EventDefinitions[G]
34
- ? EventDefinitions[G][E]
35
- : never
36
- : never
37
- : never;
38
-
39
- type EventArgs<K extends EventNames> =
40
- PayloadFor<K> extends null
41
- ? { id: K; payload?: never }
42
- : { id: K; payload: PayloadFor<K> };
43
-
44
- export type AnalyticsPayload = {
21
+ export type SchemaStaticFields = Omit<NewEvents[EventNames], "payload">;
22
+ export type AnalyticsEvent = {
45
23
  id: string;
46
- data: unknown;
24
+ data: SchemaStaticFields & { [key: string]: unknown };
47
25
  };
48
26
 
49
- export type CreateEventFn<TReturn = void> = <K extends EventNames>(
50
- args: EventArgs<K>,
51
- ) => TReturn;
52
-
53
- export interface AnalyticsAdapter {
27
+ export interface AnalyticsEventSender {
54
28
  /**
55
29
  * Function to send the event according to the API the adapter is implementing
56
30
  */
57
- sendEvent: (params: {
58
- idParser: (id: string) => { category: string; action: string };
59
- event: AnalyticsPayload;
60
- metadata: Metadata;
61
- }) => void;
31
+ send: (params: { event: AnalyticsEvent; metadata: Metadata }) => void;
62
32
  }
33
+
34
+ export type EventFunctionArgs<T extends EventNames> =
35
+ NewEvents[T]["payload"] extends null ? never : NewEvents[T]["payload"];
@@ -0,0 +1 @@
1
+ export const logger = () => consola.withTag("AnalyticsEvents");
@@ -1,35 +0,0 @@
1
- import { SEPARATOR } from "../types";
2
-
3
- const isValid = (id: string) => id.includes(SEPARATOR);
4
-
5
- /**
6
- * Parses the given event id, splitting it by a known separator. Each id is expected to have
7
- * two components to it: The event category and a specific action within that category
8
- * @returns
9
- * @throws when id format is invalid
10
- */
11
- const parse = (id: string): { category: string; action: string } => {
12
- if (!isValid(id)) {
13
- throw new Error(`Cannot parse event id. Invalid format found: ${id}`);
14
- }
15
-
16
- const out = id.split(SEPARATOR);
17
-
18
- if (out.length !== 2) {
19
- throw new Error(`Cannot parse event id. Invalid format found: ${id}`);
20
- }
21
-
22
- const [category, action] = out;
23
- return { category, action };
24
- };
25
-
26
- export const eventID = (id: string) => ({
27
- isValid: () => isValid(id),
28
- /**
29
- * Parses the given event id, splitting it by a known separator. Each id is expected to have
30
- * two components to it: The event category and a specific action within that category
31
- * @returns
32
- * @throws when id format is invalid
33
- */
34
- parse: () => parse(id),
35
- });