@trackunit/react-core-contexts-api 0.2.27 → 0.2.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts-api",
3
- "version": "0.2.27",
3
+ "version": "0.2.30",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "module": "./index.js",
@@ -0,0 +1,65 @@
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
+ export interface IAnalyticsContext<Events extends Record<string, Event<BaseEvent | UnspecifiedEvent>>> {
21
+ /**
22
+ * @template EventName
23
+ * @param {EventName} eventName Name of the event. Used to look up event interface in EventName.ts
24
+ * @param {Events[T]["properties"]} details Event parameters. Must match event interface.
25
+ * @param {{prefix: string, postfix: string}} nameSupplement Generally not reccommended.
26
+ *
27
+ * **Prefix**: Add a prefix to begging event name when logging.
28
+ *
29
+ * **Postfix**: Add string to end of event name when logging.
30
+ * Makes unique events possible, while sharing the same EventName + type.
31
+ * Only here because the analytics team wants each report to log a unique event
32
+ * for easier comparison in Databricks.
33
+ */
34
+ logEvent<T extends keyof Events>(eventName: T, details: Events[T]["properties"], nameSupplement?: {
35
+ prefix?: string;
36
+ postfix?: string;
37
+ }): void;
38
+ /**
39
+ *
40
+ * @param details
41
+ */
42
+ logPageView(details: {
43
+ pageName: string;
44
+ } & BaseEvent): void;
45
+ /**
46
+ * Log an error event.
47
+ *
48
+ * @param details The error event to log.
49
+ */
50
+ logError(details: UnspecifiedEvent): void;
51
+ /**
52
+ * Track this user property for each event.
53
+ *
54
+ * @param name key of property to set
55
+ * @param data value of property to set
56
+ */
57
+ setUserProperty(name: string, data: string | number): void;
58
+ }
59
+ type PromisifyMethod<T> = T extends (...args: infer U) => infer V ? (...args: U) => Promise<V> : T;
60
+ type PromisifyObject<T> = {
61
+ [K in keyof T]: PromisifyMethod<T[K]>;
62
+ };
63
+ export interface IAnalyticsContextAsync<T extends Record<string, Event<BaseEvent | UnspecifiedEvent>>> extends PromisifyObject<IAnalyticsContext<T>> {
64
+ }
65
+ export {};
package/src/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ export * from "./analyticsContext";
1
2
  export * from "./assetSortingContext";
2
3
  export * from "./currentUserContext";
3
- export * from "./developerSettingsContext";
4
4
  export * from "./environmentContext";
5
5
  export * from "./globalSelectionContext";
6
6
  export * from "./toastContext";
@@ -1,11 +0,0 @@
1
- /// <reference types="react" />
2
- export interface IDeveloperSettingsContext {
3
- localFeatureFlagsEnabled: boolean;
4
- enableLocalFeatureFlags?: React.Dispatch<React.SetStateAction<boolean>>;
5
- localFeatureFlags?: FeatureFlags;
6
- setFlags?: React.Dispatch<React.SetStateAction<FeatureFlags | undefined>>;
7
- }
8
- export type FeatureFlags = {
9
- [key: string]: boolean | Json;
10
- };
11
- export type Json = string;