@trackunit/react-core-contexts-api 0.2.29 → 0.2.31

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/index.cjs CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ /**
6
+ * Takes an event type and a description and returns an event
7
+ *
8
+ * @template T The event type.
9
+ * Use existing from EventTypes.ts or make custom inline for one offs.
10
+ * Defaults to BaseEvent
11
+ * @param {{ description: string }} event with the interface of the event type to be filled later
12
+ * @returns {*} {Event<T>}
13
+ */
14
+ const createEvent = (event) => ({
15
+ description: event === null || event === void 0 ? void 0 : event.description,
16
+ amplitudeName: event === null || event === void 0 ? void 0 : event.amplitudeName,
17
+ properties: {},
18
+ });
19
+
5
20
  exports.AssetSortByProperty = void 0;
6
21
  (function (AssetSortByProperty) {
7
22
  AssetSortByProperty["Activity"] = "ACTIVITY";
@@ -42,3 +57,4 @@ const UserSubscriptionPackage = {
42
57
  };
43
58
 
44
59
  exports.UserSubscriptionPackage = UserSubscriptionPackage;
60
+ exports.createEvent = createEvent;
package/index.js CHANGED
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Takes an event type and a description and returns an event
3
+ *
4
+ * @template T The event type.
5
+ * Use existing from EventTypes.ts or make custom inline for one offs.
6
+ * Defaults to BaseEvent
7
+ * @param {{ description: string }} event with the interface of the event type to be filled later
8
+ * @returns {*} {Event<T>}
9
+ */
10
+ const createEvent = (event) => ({
11
+ description: event === null || event === void 0 ? void 0 : event.description,
12
+ amplitudeName: event === null || event === void 0 ? void 0 : event.amplitudeName,
13
+ properties: {},
14
+ });
15
+
1
16
  var AssetSortByProperty;
2
17
  (function (AssetSortByProperty) {
3
18
  AssetSortByProperty["Activity"] = "ACTIVITY";
@@ -37,4 +52,4 @@ const UserSubscriptionPackage = {
37
52
  NONE: "NONE",
38
53
  };
39
54
 
40
- export { AssetSortByProperty, SortOrder, UserSubscriptionPackage };
55
+ export { AssetSortByProperty, SortOrder, UserSubscriptionPackage, createEvent };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-api",
3
- "version": "0.2.29",
3
+ "version": "0.2.31",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "module": "./index.js",
@@ -0,0 +1,78 @@
1
+ export type UnspecifiedEvent = Record<string, string | number | boolean | null | undefined | (string | number)[]>;
2
+ export interface BaseEvent {
3
+ additionalProperties?: UnspecifiedEvent;
4
+ }
5
+ export type Event<T> = {
6
+ /**
7
+ * Explain what this event means
8
+ */
9
+ description?: string;
10
+ /**
11
+ * Alternative name to show in Amplitude. Only here for legacy reasons.
12
+ */
13
+ amplitudeName?: string;
14
+ /**
15
+ * The properties to log. Pick an existing type or make a custom one.
16
+ * Be specific.
17
+ */
18
+ properties: T;
19
+ };
20
+ /**
21
+ * Takes an event type and a description and returns an event
22
+ *
23
+ * @template T The event type.
24
+ * Use existing from EventTypes.ts or make custom inline for one offs.
25
+ * Defaults to BaseEvent
26
+ * @param {{ description: string }} event with the interface of the event type to be filled later
27
+ * @returns {*} {Event<T>}
28
+ */
29
+ export declare const createEvent: <T extends object = BaseEvent>(event?: {
30
+ amplitudeName?: string;
31
+ description?: string;
32
+ }) => Event<T>;
33
+ export interface IAnalyticsContext<Events extends Record<string, Event<BaseEvent | UnspecifiedEvent>>> {
34
+ /**
35
+ * @template EventName
36
+ * @param {EventName} eventName Name of the event. Used to look up event interface in EventName.ts
37
+ * @param {Events[T]["properties"]} details Event parameters. Must match event interface.
38
+ * @param {{prefix: string, postfix: string}} nameSupplement Generally not reccommended.
39
+ *
40
+ * **Prefix**: Add a prefix to begging event name when logging.
41
+ *
42
+ * **Postfix**: Add string to end of event name when logging.
43
+ * Makes unique events possible, while sharing the same EventName + type.
44
+ * Only here because the analytics team wants each report to log a unique event
45
+ * for easier comparison in Databricks.
46
+ */
47
+ logEvent<T extends keyof Events>(eventName: T, details: Events[T]["properties"], nameSupplement?: {
48
+ prefix?: string;
49
+ postfix?: string;
50
+ }): void;
51
+ /**
52
+ *
53
+ * @param details
54
+ */
55
+ logPageView(details: {
56
+ pageName: string;
57
+ } & BaseEvent): void;
58
+ /**
59
+ * Log an error event.
60
+ *
61
+ * @param details The error event to log.
62
+ */
63
+ logError(details: UnspecifiedEvent): void;
64
+ /**
65
+ * Track this user property for each event.
66
+ *
67
+ * @param name key of property to set
68
+ * @param data value of property to set
69
+ */
70
+ setUserProperty(name: string, data: string | number): void;
71
+ }
72
+ type PromisifyMethod<T> = T extends (...args: infer U) => infer V ? (...args: U) => Promise<V> : T;
73
+ type PromisifyObject<T> = {
74
+ [K in keyof T]: PromisifyMethod<T[K]>;
75
+ };
76
+ export interface IAnalyticsContextAsync<T extends Record<string, Event<BaseEvent | UnspecifiedEvent>>> extends PromisifyObject<IAnalyticsContext<T>> {
77
+ }
78
+ export {};
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./analyticsContext";
1
2
  export * from "./assetSortingContext";
2
3
  export * from "./currentUserContext";
3
4
  export * from "./environmentContext";