@knime/hub-features 1.26.1 → 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.
- package/CHANGELOG.md +13 -0
- package/package.json +5 -3
- package/src/analytics/README.md +19 -73
- package/src/analytics/analytics.ts +71 -57
- package/src/analytics/index.ts +1 -1
- package/src/analytics/schema/code-generator.js +147 -0
- package/src/analytics/schema/event-functions.ts +1121 -0
- package/src/analytics/schema/schema.d.ts +639 -122
- package/src/analytics/schema/schema.json +3244 -273
- package/src/analytics/types.ts +19 -46
- package/src/analytics/utils/logger.ts +1 -0
- package/src/analytics/utils/eventIds.ts +0 -35
package/src/analytics/types.ts
CHANGED
|
@@ -1,62 +1,35 @@
|
|
|
1
1
|
import type { AnalyticsEventSchema } from "./schema/schema";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
type
|
|
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
|
-
|
|
10
|
-
*/
|
|
11
|
-
type GroupName = keyof EventDefinitions;
|
|
6
|
+
type NewEvents = AnalyticsEventSchema["events"];
|
|
7
|
+
type EventNames = keyof NewEvents;
|
|
12
8
|
|
|
13
9
|
/**
|
|
14
|
-
*
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
*
|
|
27
|
-
*
|
|
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
|
|
31
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
});
|