@vrplatform/log 2.0.0-alpha.1 → 2.0.0-alpha.11

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,15 +1,27 @@
1
- import { type IntercomAPI, useIntercom } from './intercom';
1
+ import { Analytics } from '@june-so/analytics-node';
2
+ import { PostHog } from 'posthog-node';
3
+ type AuthEvent = 'account_signin_completed' | 'account_signup_code_requested' | 'account_signup_code_completed' | 'account_signup_code_failed' | 'account_signup_completed' | 'account_password_reset_requested' | 'account_password_reset_failed' | 'account_password_reset_completed' | 'account_invitation_accepted' | 'account_signed_out';
4
+ type TeamEvent = 'team_added' | 'team_info_updated' | 'team_deleted' | 'team_member_removed';
5
+ type ConnectionEvent = 'connection_created' | 'connection_reconnected' | 'connection_deleted' | 'connection_requested';
6
+ type OwnershipEvent = 'ownership_created' | 'ownership_updated' | 'ownership_deleted';
7
+ type OwnerEvent = 'owner_created' | 'owner_updated' | 'owner_deleted' | 'owner_tax_info_modal_opened' | 'owner_tax_info_modal_submitted';
8
+ type SetupEvent = 'setup_classes_set' | 'setup_accounting_version_completed' | 'setup_accounting_config_completed' | 'setup_owner_imported' | 'setup_listing_imported';
9
+ type AutomationEvent = 'automation_created' | 'automation_updated' | 'automation_deleted';
10
+ type TaxStatementEvent = 'tax_statement_preview_opened' | 'tax_statement_downloaded';
11
+ type GLOwnerStatementEvent = 'gl_owner_statement_preview_opened' | 'gl_owner_statement_downloaded';
12
+ type HyperlineEvent = 'hyperline_invoice_ready' | 'hyperline_invoice_settled' | 'hyperline_trial_started' | 'hyperline_trial_ended' | 'hyperline_subscription_activated' | 'hyperline_subscription_cancelled' | 'hyperline_subscription_created' | 'hyperline_subscription_errored' | 'hyperline_subscription_paused' | 'hyperline_subscription_voided' | 'hyperline_subscription_charged' | 'hyperline_customer_created' | 'hyperline_customer_updated' | 'hyperline_payment_method_created' | 'hyperline_payment_method_errored' | 'hyperline_payment_method_deleted';
13
+ type TestEvent = 'test_event' | 'test_error';
14
+ export type TrackingEvent = AuthEvent | TeamEvent | ConnectionEvent | OwnershipEvent | OwnerEvent | SetupEvent | AutomationEvent | TaxStatementEvent | GLOwnerStatementEvent | HyperlineEvent | TestEvent;
2
15
  export type TrackingProps = {
3
16
  name: string;
4
17
  dataset: string;
5
18
  env: {
6
- INTERCOM_TOKEN: string;
7
- JUNESO_ANALYTICS_WRITE_KEY: string;
8
- POSTHOG_API_KEY: string;
19
+ INTERCOM_TOKEN?: string;
20
+ JUNESO_TOKEN?: string;
21
+ POSTHOG_TOKEN?: string;
9
22
  };
10
23
  };
11
24
  export type Tracking = ReturnType<typeof useTracking>;
12
- export type Intercom = ReturnType<typeof useIntercom>;
13
25
  type OptionalUser<T> = T & ({
14
26
  userId: string;
15
27
  anonymousId?: string;
@@ -21,8 +33,8 @@ export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?
21
33
  track: ({ userId, groupId, event, properties, }: {
22
34
  userId: string;
23
35
  groupId: string;
24
- event: string;
25
- properties: Record<string, any>;
36
+ event: TrackingEvent;
37
+ properties: Record<string, string | number | boolean | null | undefined>;
26
38
  }) => Promise<void>;
27
39
  identify: ({ traits, userId, disableGeoip, }: {
28
40
  userId: string;
@@ -33,12 +45,23 @@ export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?
33
45
  groupId: string;
34
46
  traits?: Record<string, any>;
35
47
  }>) => void;
36
- alias: ({ distinctId, alias }: {
48
+ shutdown: () => Promise<[void | undefined, void | undefined, void]>;
49
+ alias: ((data: {
37
50
  distinctId: string;
38
51
  alias: string;
39
- }) => void;
40
- shutdown: () => Promise<[void, void, void]>;
41
- intercom: IntercomAPI;
52
+ disableGeoip?: boolean;
53
+ }) => void) | undefined;
54
+ isFeatureEnabled: ((key: string, distinctId: string, options?: {
55
+ groups?: Record<string, string>;
56
+ personProperties?: Record<string, string>;
57
+ groupProperties?: Record<string, Record<string, string>>;
58
+ onlyEvaluateLocally?: boolean;
59
+ sendFeatureFlagEvents?: boolean;
60
+ disableGeoip?: boolean;
61
+ }) => Promise<boolean | undefined>) | undefined;
62
+ intercom: import("./intercom").IntercomAPI | undefined;
63
+ posthog: PostHog | undefined;
64
+ june: Analytics | undefined;
42
65
  log: import("../log").WorkerLog;
43
66
  };
44
67
  export {};
@@ -5,19 +5,35 @@ const analytics_node_1 = require("@june-so/analytics-node");
5
5
  const posthog_node_1 = require("posthog-node");
6
6
  const log_1 = require("../log");
7
7
  const intercom_1 = require("./intercom");
8
+ const E2E_TEST_USERS = [
9
+ '9e7dfc88-503c-4222-9905-9116169d2203', // lars+checkly@finalytic.co
10
+ '113d73d8-ee21-46b7-a12a-a74f632401ca', // e2e-invite-member@finalytic.io
11
+ '917b7c4e-cb03-491c-9e94-d33a5bdeca05', // e2e-invite-owner@finalytic.io
12
+ 'ec8e5572-74d0-4ae6-af73-bca8db9a27e9', // e2e-sign-up@finalytic.io
13
+ ];
14
+ const E2E_TEST_TEAMS = [
15
+ 'c4fd21b4-8447-43a2-bdcb-f06a85a935ad', // VRP Automated Testing
16
+ '8f21060e-afe6-410a-b2f4-00a3caa20786', // test_company_xxxx
17
+ ];
18
+ const isTest = (userId, groupId) => E2E_TEST_USERS.includes(userId) ||
19
+ (groupId && E2E_TEST_TEAMS.includes(groupId));
8
20
  const useTracking = ({ dataset, env, name }, isDev) => {
9
21
  const axiom = (0, log_1.useLog)({ name, dataset, env });
10
- const intercom = (0, intercom_1.useIntercom)(env.INTERCOM_TOKEN, axiom);
11
- const juneso = new analytics_node_1.Analytics(env.JUNESO_ANALYTICS_WRITE_KEY);
12
- const posthog = new posthog_node_1.PostHog(env.POSTHOG_API_KEY, {
13
- host: 'https://app.posthog.com',
14
- });
22
+ const intercom = env.INTERCOM_TOKEN
23
+ ? (0, intercom_1.useIntercom)(env.INTERCOM_TOKEN, axiom)
24
+ : undefined;
25
+ const juneso = env.JUNESO_TOKEN ? new analytics_node_1.Analytics(env.JUNESO_TOKEN) : undefined;
26
+ const posthog = env.POSTHOG_TOKEN
27
+ ? new posthog_node_1.PostHog(env.POSTHOG_TOKEN, {
28
+ host: 'https://app.posthog.com',
29
+ })
30
+ : undefined;
15
31
  return {
16
32
  // General
17
33
  track: async ({ userId, groupId, event, properties, }) => {
18
- if (isDev)
34
+ if (isDev || isTest(userId, groupId))
19
35
  return;
20
- posthog.capture({
36
+ posthog?.capture({
21
37
  distinctId: userId,
22
38
  event,
23
39
  groups: {
@@ -25,14 +41,17 @@ const useTracking = ({ dataset, env, name }, isDev) => {
25
41
  },
26
42
  properties,
27
43
  });
28
- juneso.track({
44
+ juneso?.track({
29
45
  userId,
30
46
  event,
31
47
  properties,
32
48
  context: { groupId },
49
+ }, (err) => {
50
+ if (err)
51
+ console.error(err);
33
52
  });
34
53
  try {
35
- await intercom.trackEvent({
54
+ await intercom?.trackEvent({
36
55
  user_id: userId,
37
56
  event_name: event,
38
57
  metadata: properties,
@@ -43,33 +62,50 @@ const useTracking = ({ dataset, env, name }, isDev) => {
43
62
  }
44
63
  },
45
64
  identify: ({ traits, userId, disableGeoip, }) => {
46
- posthog.identify({
65
+ if (isDev || isTest(userId))
66
+ return;
67
+ posthog?.identify({
47
68
  distinctId: userId,
48
69
  properties: traits,
49
70
  disableGeoip,
50
71
  });
51
- juneso.identify({
72
+ juneso?.identify({
52
73
  userId,
53
74
  traits,
75
+ }, (err) => {
76
+ if (err)
77
+ console.error(err);
54
78
  });
55
79
  },
56
80
  group: ({ traits, groupId, userId, anonymousId, }) => {
57
- posthog.groupIdentify({
81
+ if (isDev || isTest(userId || anonymousId || '', groupId))
82
+ return;
83
+ posthog?.groupIdentify({
58
84
  groupKey: groupId,
59
85
  groupType: 'tenant',
60
86
  properties: traits,
61
87
  distinctId: userId,
62
88
  });
63
89
  if (anonymousId)
64
- juneso.group({ anonymousId, groupId, traits });
90
+ juneso?.group({ anonymousId, groupId, traits }, (err) => console.error(err));
65
91
  else if (userId)
66
- juneso.group({ userId, groupId, traits });
92
+ juneso?.group({ userId, groupId, traits }, (err) => {
93
+ if (err)
94
+ console.error(err);
95
+ });
67
96
  },
97
+ shutdown: async () => Promise.all([
98
+ posthog?.shutdown(),
99
+ juneso?.closeAndFlush(),
100
+ axiom?.flush(),
101
+ ]),
68
102
  // Posthog specific
69
- alias: ({ distinctId, alias }) => posthog.alias({ distinctId, alias }),
70
- shutdown: async () => Promise.all([posthog.shutdown(), juneso.closeAndFlush(), axiom.flush()]),
103
+ alias: posthog?.alias,
104
+ isFeatureEnabled: posthog?.isFeatureEnabled,
71
105
  // export intercom and axiom
72
106
  intercom,
107
+ posthog,
108
+ june: juneso,
73
109
  log: axiom,
74
110
  };
75
111
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":";;;AAAA,4DAAoD;AACpD,+CAAuC;AACvC,gCAAgC;AAChC,yCAA2D;AAuBpD,MAAM,WAAW,GAAG,CACzB,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAiB,EACrC,KAAe,EACf,EAAE;IACF,MAAM,KAAK,GAAG,IAAA,YAAM,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,IAAA,sBAAW,EAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,IAAI,0BAAS,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,IAAI,sBAAO,CAAC,GAAG,CAAC,eAAe,EAAE;QAC/C,IAAI,EAAE,yBAAyB;KAChC,CAAC,CAAC;IAEH,OAAO;QACL,UAAU;QACV,KAAK,EAAE,KAAK,EAAE,EACZ,MAAM,EACN,OAAO,EACP,KAAK,EACL,UAAU,GAMX,EAAE,EAAE;YACH,IAAI,KAAK;gBAAE,OAAO;YAElB,OAAO,CAAC,OAAO,CAAC;gBACd,UAAU,EAAE,MAAM;gBAClB,KAAK;gBACL,MAA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B,KAAK,EAAE,KAAK,EAAE;SACf,CAAC;QACJ,mBAAmB;QACnB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;QAC3C,4BAA4B;QAC5B,QAAQ;QACR,OAAO;QACP,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;KACX,CAAC;AACJ,CAAC,CAAC;AA/HW,QAAA,WAAW,eA+HtB"}
@@ -1,15 +1,27 @@
1
- import { type IntercomAPI, useIntercom } from './intercom';
1
+ import { Analytics } from '@june-so/analytics-node';
2
+ import { PostHog } from 'posthog-node';
3
+ type AuthEvent = 'account_signin_completed' | 'account_signup_code_requested' | 'account_signup_code_completed' | 'account_signup_code_failed' | 'account_signup_completed' | 'account_password_reset_requested' | 'account_password_reset_failed' | 'account_password_reset_completed' | 'account_invitation_accepted' | 'account_signed_out';
4
+ type TeamEvent = 'team_added' | 'team_info_updated' | 'team_deleted' | 'team_member_removed';
5
+ type ConnectionEvent = 'connection_created' | 'connection_reconnected' | 'connection_deleted' | 'connection_requested';
6
+ type OwnershipEvent = 'ownership_created' | 'ownership_updated' | 'ownership_deleted';
7
+ type OwnerEvent = 'owner_created' | 'owner_updated' | 'owner_deleted' | 'owner_tax_info_modal_opened' | 'owner_tax_info_modal_submitted';
8
+ type SetupEvent = 'setup_classes_set' | 'setup_accounting_version_completed' | 'setup_accounting_config_completed' | 'setup_owner_imported' | 'setup_listing_imported';
9
+ type AutomationEvent = 'automation_created' | 'automation_updated' | 'automation_deleted';
10
+ type TaxStatementEvent = 'tax_statement_preview_opened' | 'tax_statement_downloaded';
11
+ type GLOwnerStatementEvent = 'gl_owner_statement_preview_opened' | 'gl_owner_statement_downloaded';
12
+ type HyperlineEvent = 'hyperline_invoice_ready' | 'hyperline_invoice_settled' | 'hyperline_trial_started' | 'hyperline_trial_ended' | 'hyperline_subscription_activated' | 'hyperline_subscription_cancelled' | 'hyperline_subscription_created' | 'hyperline_subscription_errored' | 'hyperline_subscription_paused' | 'hyperline_subscription_voided' | 'hyperline_subscription_charged' | 'hyperline_customer_created' | 'hyperline_customer_updated' | 'hyperline_payment_method_created' | 'hyperline_payment_method_errored' | 'hyperline_payment_method_deleted';
13
+ type TestEvent = 'test_event' | 'test_error';
14
+ export type TrackingEvent = AuthEvent | TeamEvent | ConnectionEvent | OwnershipEvent | OwnerEvent | SetupEvent | AutomationEvent | TaxStatementEvent | GLOwnerStatementEvent | HyperlineEvent | TestEvent;
2
15
  export type TrackingProps = {
3
16
  name: string;
4
17
  dataset: string;
5
18
  env: {
6
- INTERCOM_TOKEN: string;
7
- JUNESO_ANALYTICS_WRITE_KEY: string;
8
- POSTHOG_API_KEY: string;
19
+ INTERCOM_TOKEN?: string;
20
+ JUNESO_TOKEN?: string;
21
+ POSTHOG_TOKEN?: string;
9
22
  };
10
23
  };
11
24
  export type Tracking = ReturnType<typeof useTracking>;
12
- export type Intercom = ReturnType<typeof useIntercom>;
13
25
  type OptionalUser<T> = T & ({
14
26
  userId: string;
15
27
  anonymousId?: string;
@@ -21,8 +33,8 @@ export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?
21
33
  track: ({ userId, groupId, event, properties, }: {
22
34
  userId: string;
23
35
  groupId: string;
24
- event: string;
25
- properties: Record<string, any>;
36
+ event: TrackingEvent;
37
+ properties: Record<string, string | number | boolean | null | undefined>;
26
38
  }) => Promise<void>;
27
39
  identify: ({ traits, userId, disableGeoip, }: {
28
40
  userId: string;
@@ -33,12 +45,23 @@ export declare const useTracking: ({ dataset, env, name }: TrackingProps, isDev?
33
45
  groupId: string;
34
46
  traits?: Record<string, any>;
35
47
  }>) => void;
36
- alias: ({ distinctId, alias }: {
48
+ shutdown: () => Promise<[void | undefined, void | undefined, void]>;
49
+ alias: ((data: {
37
50
  distinctId: string;
38
51
  alias: string;
39
- }) => void;
40
- shutdown: () => Promise<[void, void, void]>;
41
- intercom: IntercomAPI;
52
+ disableGeoip?: boolean;
53
+ }) => void) | undefined;
54
+ isFeatureEnabled: ((key: string, distinctId: string, options?: {
55
+ groups?: Record<string, string>;
56
+ personProperties?: Record<string, string>;
57
+ groupProperties?: Record<string, Record<string, string>>;
58
+ onlyEvaluateLocally?: boolean;
59
+ sendFeatureFlagEvents?: boolean;
60
+ disableGeoip?: boolean;
61
+ }) => Promise<boolean | undefined>) | undefined;
62
+ intercom: import("./intercom").IntercomAPI | undefined;
63
+ posthog: PostHog | undefined;
64
+ june: Analytics | undefined;
42
65
  log: import("../log").WorkerLog;
43
66
  };
44
67
  export {};
@@ -2,19 +2,35 @@ import { Analytics } from '@june-so/analytics-node';
2
2
  import { PostHog } from 'posthog-node';
3
3
  import { useLog } from '../log';
4
4
  import { useIntercom } from './intercom';
5
+ const E2E_TEST_USERS = [
6
+ '9e7dfc88-503c-4222-9905-9116169d2203', // lars+checkly@finalytic.co
7
+ '113d73d8-ee21-46b7-a12a-a74f632401ca', // e2e-invite-member@finalytic.io
8
+ '917b7c4e-cb03-491c-9e94-d33a5bdeca05', // e2e-invite-owner@finalytic.io
9
+ 'ec8e5572-74d0-4ae6-af73-bca8db9a27e9', // e2e-sign-up@finalytic.io
10
+ ];
11
+ const E2E_TEST_TEAMS = [
12
+ 'c4fd21b4-8447-43a2-bdcb-f06a85a935ad', // VRP Automated Testing
13
+ '8f21060e-afe6-410a-b2f4-00a3caa20786', // test_company_xxxx
14
+ ];
15
+ const isTest = (userId, groupId) => E2E_TEST_USERS.includes(userId) ||
16
+ (groupId && E2E_TEST_TEAMS.includes(groupId));
5
17
  export const useTracking = ({ dataset, env, name }, isDev) => {
6
18
  const axiom = useLog({ name, dataset, env });
7
- const intercom = useIntercom(env.INTERCOM_TOKEN, axiom);
8
- const juneso = new Analytics(env.JUNESO_ANALYTICS_WRITE_KEY);
9
- const posthog = new PostHog(env.POSTHOG_API_KEY, {
10
- host: 'https://app.posthog.com',
11
- });
19
+ const intercom = env.INTERCOM_TOKEN
20
+ ? useIntercom(env.INTERCOM_TOKEN, axiom)
21
+ : undefined;
22
+ const juneso = env.JUNESO_TOKEN ? new Analytics(env.JUNESO_TOKEN) : undefined;
23
+ const posthog = env.POSTHOG_TOKEN
24
+ ? new PostHog(env.POSTHOG_TOKEN, {
25
+ host: 'https://app.posthog.com',
26
+ })
27
+ : undefined;
12
28
  return {
13
29
  // General
14
30
  track: async ({ userId, groupId, event, properties, }) => {
15
- if (isDev)
31
+ if (isDev || isTest(userId, groupId))
16
32
  return;
17
- posthog.capture({
33
+ posthog?.capture({
18
34
  distinctId: userId,
19
35
  event,
20
36
  groups: {
@@ -22,14 +38,17 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
22
38
  },
23
39
  properties,
24
40
  });
25
- juneso.track({
41
+ juneso?.track({
26
42
  userId,
27
43
  event,
28
44
  properties,
29
45
  context: { groupId },
46
+ }, (err) => {
47
+ if (err)
48
+ console.error(err);
30
49
  });
31
50
  try {
32
- await intercom.trackEvent({
51
+ await intercom?.trackEvent({
33
52
  user_id: userId,
34
53
  event_name: event,
35
54
  metadata: properties,
@@ -40,33 +59,50 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
40
59
  }
41
60
  },
42
61
  identify: ({ traits, userId, disableGeoip, }) => {
43
- posthog.identify({
62
+ if (isDev || isTest(userId))
63
+ return;
64
+ posthog?.identify({
44
65
  distinctId: userId,
45
66
  properties: traits,
46
67
  disableGeoip,
47
68
  });
48
- juneso.identify({
69
+ juneso?.identify({
49
70
  userId,
50
71
  traits,
72
+ }, (err) => {
73
+ if (err)
74
+ console.error(err);
51
75
  });
52
76
  },
53
77
  group: ({ traits, groupId, userId, anonymousId, }) => {
54
- posthog.groupIdentify({
78
+ if (isDev || isTest(userId || anonymousId || '', groupId))
79
+ return;
80
+ posthog?.groupIdentify({
55
81
  groupKey: groupId,
56
82
  groupType: 'tenant',
57
83
  properties: traits,
58
84
  distinctId: userId,
59
85
  });
60
86
  if (anonymousId)
61
- juneso.group({ anonymousId, groupId, traits });
87
+ juneso?.group({ anonymousId, groupId, traits }, (err) => console.error(err));
62
88
  else if (userId)
63
- juneso.group({ userId, groupId, traits });
89
+ juneso?.group({ userId, groupId, traits }, (err) => {
90
+ if (err)
91
+ console.error(err);
92
+ });
64
93
  },
94
+ shutdown: async () => Promise.all([
95
+ posthog?.shutdown(),
96
+ juneso?.closeAndFlush(),
97
+ axiom?.flush(),
98
+ ]),
65
99
  // Posthog specific
66
- alias: ({ distinctId, alias }) => posthog.alias({ distinctId, alias }),
67
- shutdown: async () => Promise.all([posthog.shutdown(), juneso.closeAndFlush(), axiom.flush()]),
100
+ alias: posthog?.alias,
101
+ isFeatureEnabled: posthog?.isFeatureEnabled,
68
102
  // export intercom and axiom
69
103
  intercom,
104
+ posthog,
105
+ june: juneso,
70
106
  log: axiom,
71
107
  };
72
108
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"src/","sources":["tracking/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAoB,WAAW,EAAE,MAAM,YAAY,CAAC;AAuB3D,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAiB,EACrC,KAAe,EACf,EAAE;IACF,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE;QAC/C,IAAI,EAAE,yBAAyB;KAChC,CAAC,CAAC;IAEH,OAAO;Q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AAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;oBACjD,IAAI,GAAG;wBAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC9B,CAAC,CAAC,CAAC;QACP,CAAC;QACD,QAAQ,EAAE,KAAK,IAAI,EAAE,CACnB,OAAO,CAAC,GAAG,CAAC;YACV,OAAO,EAAE,QAAQ,EAAE;YACnB,MAAM,EAAE,aAAa,EAAE;YACvB,KAAK,EAAE,KAAK,EAAE;SACf,CAAC;QACJ,mBAAmB;QACnB,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,gBAAgB,EAAE,OAAO,EAAE,gBAAgB;QAC3C,4BAA4B;QAC5B,QAAQ;QACR,OAAO;QACP,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;KACX,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vrplatform/log",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.11",
4
4
  "main": "src/index.ts",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -1,19 +1,124 @@
1
1
  import { Analytics } from '@june-so/analytics-node';
2
2
  import { PostHog } from 'posthog-node';
3
3
  import { useLog } from '../log';
4
- import { type IntercomAPI, useIntercom } from './intercom';
4
+ import { useIntercom } from './intercom';
5
+
6
+ const E2E_TEST_USERS = [
7
+ '9e7dfc88-503c-4222-9905-9116169d2203', // lars+checkly@finalytic.co
8
+ '113d73d8-ee21-46b7-a12a-a74f632401ca', // e2e-invite-member@finalytic.io
9
+ '917b7c4e-cb03-491c-9e94-d33a5bdeca05', // e2e-invite-owner@finalytic.io
10
+ 'ec8e5572-74d0-4ae6-af73-bca8db9a27e9', // e2e-sign-up@finalytic.io
11
+ ];
12
+ const E2E_TEST_TEAMS = [
13
+ 'c4fd21b4-8447-43a2-bdcb-f06a85a935ad', // VRP Automated Testing
14
+ '8f21060e-afe6-410a-b2f4-00a3caa20786', // test_company_xxxx
15
+ ];
16
+
17
+ const isTest = (userId: string, groupId?: string) =>
18
+ E2E_TEST_USERS.includes(userId) ||
19
+ (groupId && E2E_TEST_TEAMS.includes(groupId));
20
+
21
+ type AuthEvent =
22
+ | 'account_signin_completed'
23
+ | 'account_signup_code_requested'
24
+ | 'account_signup_code_completed'
25
+ | 'account_signup_code_failed'
26
+ | 'account_signup_completed' // from list
27
+ | 'account_password_reset_requested'
28
+ | 'account_password_reset_failed'
29
+ | 'account_password_reset_completed'
30
+ | 'account_invitation_accepted' // from list
31
+ | 'account_signed_out'; // missing in list
32
+
33
+ type TeamEvent =
34
+ | 'team_added'
35
+ | 'team_info_updated'
36
+ | 'team_deleted'
37
+ | 'team_member_removed'; // missing in list
38
+
39
+ type ConnectionEvent =
40
+ | 'connection_created'
41
+ | 'connection_reconnected'
42
+ | 'connection_deleted'
43
+ | 'connection_requested';
44
+
45
+ type OwnershipEvent =
46
+ | 'ownership_created'
47
+ | 'ownership_updated'
48
+ | 'ownership_deleted';
49
+
50
+ type OwnerEvent =
51
+ | 'owner_created'
52
+ | 'owner_updated'
53
+ | 'owner_deleted'
54
+ | 'owner_tax_info_modal_opened' // missing in list
55
+ | 'owner_tax_info_modal_submitted'; // missing in list
56
+
57
+ type SetupEvent =
58
+ | 'setup_classes_set' // from list
59
+ | 'setup_accounting_version_completed' // from list
60
+ | 'setup_accounting_config_completed' // from list
61
+ | 'setup_owner_imported' // from list
62
+ | 'setup_listing_imported'; // from list
63
+
64
+ type AutomationEvent =
65
+ | 'automation_created'
66
+ | 'automation_updated' // missing in list
67
+ | 'automation_deleted';
68
+
69
+ type TaxStatementEvent =
70
+ | 'tax_statement_preview_opened'
71
+ | 'tax_statement_downloaded';
72
+
73
+ type GLOwnerStatementEvent =
74
+ | 'gl_owner_statement_preview_opened' // missing in list
75
+ | 'gl_owner_statement_downloaded'; // missing in list
76
+
77
+ type HyperlineEvent =
78
+ | 'hyperline_invoice_ready' // missing in list
79
+ | 'hyperline_invoice_settled' // missing in list
80
+ | 'hyperline_trial_started' // missing in list => used
81
+ | 'hyperline_trial_ended' // missing in list
82
+ | 'hyperline_subscription_activated' // missing in list => used
83
+ | 'hyperline_subscription_cancelled' // missing in list => used
84
+ | 'hyperline_subscription_created' // missing in list => used
85
+ | 'hyperline_subscription_errored' // missing in list => used
86
+ | 'hyperline_subscription_paused' // missing in list => used
87
+ | 'hyperline_subscription_voided' // missing in list => used
88
+ | 'hyperline_subscription_charged' // missing in list => used
89
+ | 'hyperline_customer_created' // missing in list => used
90
+ | 'hyperline_customer_updated' // missing in list => used
91
+ | 'hyperline_payment_method_created' // missing in list => used
92
+ | 'hyperline_payment_method_errored' // missing in list => used
93
+ | 'hyperline_payment_method_deleted'; // missing in list => used
94
+
95
+ type TestEvent =
96
+ | 'test_event' // missing in list
97
+ | 'test_error'; // missing in list
98
+
99
+ export type TrackingEvent =
100
+ | AuthEvent
101
+ | TeamEvent
102
+ | ConnectionEvent
103
+ | OwnershipEvent
104
+ | OwnerEvent
105
+ | SetupEvent
106
+ | AutomationEvent
107
+ | TaxStatementEvent
108
+ | GLOwnerStatementEvent
109
+ | HyperlineEvent
110
+ | TestEvent;
5
111
 
6
112
  export type TrackingProps = {
7
113
  name: string;
8
114
  dataset: string;
9
115
  env: {
10
- INTERCOM_TOKEN: string;
11
- JUNESO_ANALYTICS_WRITE_KEY: string;
12
- POSTHOG_API_KEY: string;
116
+ INTERCOM_TOKEN?: string;
117
+ JUNESO_TOKEN?: string;
118
+ POSTHOG_TOKEN?: string;
13
119
  };
14
120
  };
15
121
  export type Tracking = ReturnType<typeof useTracking>;
16
- export type Intercom = ReturnType<typeof useIntercom>;
17
122
 
18
123
  type OptionalUser<T> = T &
19
124
  (
@@ -29,11 +134,15 @@ export const useTracking = (
29
134
  isDev?: boolean
30
135
  ) => {
31
136
  const axiom = useLog({ name, dataset, env });
32
- const intercom = useIntercom(env.INTERCOM_TOKEN, axiom);
33
- const juneso = new Analytics(env.JUNESO_ANALYTICS_WRITE_KEY);
34
- const posthog = new PostHog(env.POSTHOG_API_KEY, {
35
- host: 'https://app.posthog.com',
36
- });
137
+ const intercom = env.INTERCOM_TOKEN
138
+ ? useIntercom(env.INTERCOM_TOKEN, axiom)
139
+ : undefined;
140
+ const juneso = env.JUNESO_TOKEN ? new Analytics(env.JUNESO_TOKEN) : undefined;
141
+ const posthog = env.POSTHOG_TOKEN
142
+ ? new PostHog(env.POSTHOG_TOKEN, {
143
+ host: 'https://app.posthog.com',
144
+ })
145
+ : undefined;
37
146
 
38
147
  return {
39
148
  // General
@@ -45,12 +154,12 @@ export const useTracking = (
45
154
  }: {
46
155
  userId: string;
47
156
  groupId: string;
48
- event: string;
49
- properties: Record<string, any>;
157
+ event: TrackingEvent;
158
+ properties: Record<string, string | number | boolean | null | undefined>;
50
159
  }) => {
51
- if (isDev) return;
160
+ if (isDev || isTest(userId, groupId)) return;
52
161
 
53
- posthog.capture({
162
+ posthog?.capture({
54
163
  distinctId: userId,
55
164
  event,
56
165
  groups: {
@@ -58,15 +167,20 @@ export const useTracking = (
58
167
  },
59
168
  properties,
60
169
  });
61
- juneso.track({
62
- userId,
63
- event,
64
- properties,
65
- context: { groupId },
66
- });
170
+ juneso?.track(
171
+ {
172
+ userId,
173
+ event,
174
+ properties,
175
+ context: { groupId },
176
+ },
177
+ (err) => {
178
+ if (err) console.error(err);
179
+ }
180
+ );
67
181
 
68
182
  try {
69
- await intercom.trackEvent({
183
+ await intercom?.trackEvent({
70
184
  user_id: userId,
71
185
  event_name: event,
72
186
  metadata: properties,
@@ -84,15 +198,22 @@ export const useTracking = (
84
198
  traits: Record<string, any>;
85
199
  disableGeoip?: boolean;
86
200
  }) => {
87
- posthog.identify({
201
+ if (isDev || isTest(userId)) return;
202
+
203
+ posthog?.identify({
88
204
  distinctId: userId,
89
205
  properties: traits,
90
206
  disableGeoip,
91
207
  });
92
- juneso.identify({
93
- userId,
94
- traits,
95
- });
208
+ juneso?.identify(
209
+ {
210
+ userId,
211
+ traits,
212
+ },
213
+ (err) => {
214
+ if (err) console.error(err);
215
+ }
216
+ );
96
217
  },
97
218
  group: ({
98
219
  traits,
@@ -103,22 +224,36 @@ export const useTracking = (
103
224
  groupId: string;
104
225
  traits?: Record<string, any>;
105
226
  }>) => {
106
- posthog.groupIdentify({
227
+ if (isDev || isTest(userId || anonymousId || '', groupId)) return;
228
+
229
+ posthog?.groupIdentify({
107
230
  groupKey: groupId,
108
231
  groupType: 'tenant',
109
232
  properties: traits,
110
233
  distinctId: userId,
111
234
  });
112
- if (anonymousId) juneso.group({ anonymousId, groupId, traits });
113
- else if (userId) juneso.group({ userId, groupId, traits });
235
+ if (anonymousId)
236
+ juneso?.group({ anonymousId, groupId, traits }, (err) =>
237
+ console.error(err)
238
+ );
239
+ else if (userId)
240
+ juneso?.group({ userId, groupId, traits }, (err) => {
241
+ if (err) console.error(err);
242
+ });
114
243
  },
115
- // Posthog specific
116
- alias: ({ distinctId, alias }: { distinctId: string; alias: string }) =>
117
- posthog.alias({ distinctId, alias }),
118
244
  shutdown: async () =>
119
- Promise.all([posthog.shutdown(), juneso.closeAndFlush(), axiom.flush()]),
245
+ Promise.all([
246
+ posthog?.shutdown(),
247
+ juneso?.closeAndFlush(),
248
+ axiom?.flush(),
249
+ ]),
250
+ // Posthog specific
251
+ alias: posthog?.alias,
252
+ isFeatureEnabled: posthog?.isFeatureEnabled,
120
253
  // export intercom and axiom
121
254
  intercom,
255
+ posthog,
256
+ june: juneso,
122
257
  log: axiom,
123
258
  };
124
259
  };