@vrplatform/log 3.0.2 → 3.0.5
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/build/main/tracking/_intercom.d.ts +109 -0
- package/build/main/tracking/_intercom.js +139 -0
- package/build/main/tracking/_intercom.js.map +1 -0
- package/build/main/tracking/eventTypes.d.ts +16 -0
- package/build/main/tracking/eventTypes.js +3 -0
- package/build/main/tracking/eventTypes.js.map +1 -0
- package/build/main/tracking/index.d.ts +8 -8
- package/build/main/tracking/index.js +16 -16
- package/build/main/tracking/index.js.map +1 -1
- package/build/main/tracking/intercom.d.ts +109 -0
- package/build/main/tracking/intercom.js +139 -0
- package/build/main/tracking/intercom.js.map +1 -0
- package/build/main/tracking/test.js +23 -0
- package/build/main/tracking/test.js.map +1 -0
- package/build/main/tracking/types.d.ts +3 -2
- package/build/module/tracking/_intercom.d.ts +109 -0
- package/build/module/tracking/_intercom.js +136 -0
- package/build/module/tracking/_intercom.js.map +1 -0
- package/build/module/tracking/eventTypes.d.ts +16 -0
- package/build/module/tracking/eventTypes.js +2 -0
- package/build/module/tracking/eventTypes.js.map +1 -0
- package/build/module/tracking/index.d.ts +8 -8
- package/build/module/tracking/index.js +25 -25
- package/build/module/tracking/index.js.map +1 -1
- package/build/module/tracking/intercom.d.ts +109 -0
- package/build/module/tracking/intercom.js +136 -0
- package/build/module/tracking/intercom.js.map +1 -0
- package/build/module/tracking/test.js +21 -0
- package/build/module/tracking/test.js.map +1 -0
- package/build/module/tracking/types.d.ts +3 -2
- package/package.json +24 -20
- package/src/tracking/index.ts +34 -34
- package/src/tracking/types.ts +6 -9
- package/build/main/log/index.spec.js +0 -59
- package/build/main/log/index.spec.js.map +0 -1
- package/build/module/log/index.spec.js +0 -57
- package/build/module/log/index.spec.js.map +0 -1
- /package/build/main/{log/index.spec.d.ts → tracking/test.d.ts} +0 -0
- /package/build/module/{log/index.spec.d.ts → tracking/test.d.ts} +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntercomAPI = void 0;
|
|
4
|
+
exports.useIntercom = useIntercom;
|
|
5
|
+
class IntercomAPI {
|
|
6
|
+
constructor(token, log) {
|
|
7
|
+
this.headers = {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
Accept: 'application/json',
|
|
10
|
+
'Intercom-Version': '2.11',
|
|
11
|
+
Authorization: `Bearer ${token}`,
|
|
12
|
+
};
|
|
13
|
+
this.log = log;
|
|
14
|
+
}
|
|
15
|
+
async fetch(path, options) {
|
|
16
|
+
if (options?.data) {
|
|
17
|
+
options.body = JSON.stringify(options.data);
|
|
18
|
+
options.data = undefined;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const result = await fetch(`https://api.intercom.io${path}`, {
|
|
22
|
+
method: 'GET',
|
|
23
|
+
headers: this.headers,
|
|
24
|
+
...options,
|
|
25
|
+
});
|
|
26
|
+
if (!result.ok) {
|
|
27
|
+
this.log?.info('Failed to fetch from Intercom', {
|
|
28
|
+
result: {
|
|
29
|
+
status: result.status,
|
|
30
|
+
statusText: result.statusText,
|
|
31
|
+
body: await result.text(),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
if (result.status === 404)
|
|
35
|
+
return undefined;
|
|
36
|
+
if (result.status === 429) {
|
|
37
|
+
console.log('Intercom rate limit exceeded, waiting for 1 minute');
|
|
38
|
+
// X-RateLimit-Reset: 1487332520 => timestamp from header response when resetting
|
|
39
|
+
const reset = Number(result.headers.get('X-RateLimit-Reset'));
|
|
40
|
+
if (reset) {
|
|
41
|
+
const now = Math.floor(Date.now() / 1000);
|
|
42
|
+
const wait = reset - now + 1;
|
|
43
|
+
console.log(`Waiting for ${wait} seconds`);
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, wait * 1000));
|
|
45
|
+
return await this.fetch(path, options);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result.status === 202 ? {} : (await result.json());
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
this.log?.error(error);
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// User
|
|
57
|
+
async getUserByUserId(userId) {
|
|
58
|
+
return await this.fetch('/contacts/search', {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
data: {
|
|
61
|
+
query: {
|
|
62
|
+
field: 'external_id',
|
|
63
|
+
operator: '=',
|
|
64
|
+
value: userId,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async createUser({ data, userId, }) {
|
|
70
|
+
return await this.fetch('/contacts', {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
data: { ...data, external_id: userId },
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async updateUser({ data, contactId, }) {
|
|
76
|
+
return await this.fetch(`/contacts/${contactId}`, {
|
|
77
|
+
method: 'PUT',
|
|
78
|
+
data,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async deleteUser(intercom_contact_id) {
|
|
82
|
+
return await this.fetch(`/contacts/${intercom_contact_id}`, {
|
|
83
|
+
method: 'DELETE',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async createCompanyUser(data) {
|
|
87
|
+
return await this.fetch(`/contacts/${data.intercom_contact_id}/companies`, {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
data: {
|
|
90
|
+
id: data.intercom_company_id,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async deleteCompanyUser({ intercom_company_id, intercom_contact_id, }) {
|
|
95
|
+
return await this.fetch(`/contacts/${intercom_contact_id}/companies/${intercom_company_id}`, {
|
|
96
|
+
method: 'DELETE',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async trackEvent(data) {
|
|
100
|
+
return await this.fetch('/events', {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
data: {
|
|
103
|
+
created_at: Math.floor(new Date().getTime() / 1000), // to seconds
|
|
104
|
+
...data,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// Company
|
|
109
|
+
async getCompanyByTenantId(tenantId) {
|
|
110
|
+
return await this.fetch(`/companies?company_id=${tenantId}`, {
|
|
111
|
+
method: 'GET',
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async createCompany({ data, tenantId, }) {
|
|
115
|
+
return await this.fetch('/companies', {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
data: {
|
|
118
|
+
...data,
|
|
119
|
+
company_id: tenantId,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async updateCompany({ data, companyId, }) {
|
|
124
|
+
return await this.fetch(`/companies/${companyId}`, {
|
|
125
|
+
method: 'PUT',
|
|
126
|
+
data,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async deleteCompany(intercom_company_id) {
|
|
130
|
+
return await this.fetch(`/companies/${intercom_company_id}`, {
|
|
131
|
+
method: 'DELETE',
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.IntercomAPI = IntercomAPI;
|
|
136
|
+
function useIntercom(token, log) {
|
|
137
|
+
return new IntercomAPI(token, log);
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=intercom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intercom.js","sourceRoot":"src/","sources":["tracking/intercom.ts"],"names":[],"mappings":";;;AA+PA,kCAEC;AA/PD,MAAa,WAAW;IACtB,YAAY,KAAa,EAAE,GAAS;QAClC,IAAI,CAAC,OAAO,GAAG;YACb,cAAc,EAAE,kBAAkB;YAClC,MAAM,EAAE,kBAAkB;YAC1B,kBAAkB,EAAE,MAAM;YAC1B,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC,CAAC;QAEF,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YACd,IAAI,EAAE;gBACJ,GAAG,IAAI;gBACP,UAAU,EAAE,QAAQ;aACrB;SACF,CAAC,CAAC;IACL,CAAC;IACD,KAAK,CAAC,aAAa,CAAC,EAClB,IAAI,EACJ,SAAS,GAIV;QACC,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,SAAS,EAAE,EAAE;YACjD,MAAM,EAAE,KAAK;YACb,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IACD,KAAK,CAAC,aAAa,CAAC,mBAA2B;QAC7C,OAAO,MAAM,IAAI,CAAC,KAAK,CAIpB,cAAc,mBAAmB,EAAE,EAAE;YACtC,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;IACL,CAAC;CACF;AA3PD,kCA2PC;AAED,SAAgB,WAAW,CAAC,KAAa,EAAE,GAAS;IAClD,OAAO,IAAI,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mixpanel_1 = require("./mixpanel");
|
|
4
|
+
const mixpanel = new mixpanel_1.MixpanelClient('933a19cf6d01a51a06ccdd083083f2a9');
|
|
5
|
+
mixpanel.identify('user@example.com');
|
|
6
|
+
mixpanel.group.set('tenant', '123test', {
|
|
7
|
+
$name: '123 Test!',
|
|
8
|
+
isTest: true,
|
|
9
|
+
});
|
|
10
|
+
mixpanel.people.set({
|
|
11
|
+
$email: 'user@example.com',
|
|
12
|
+
$name: 'John Doe',
|
|
13
|
+
$created: new Date().getTime() / 1000,
|
|
14
|
+
isTest: true,
|
|
15
|
+
tenant: ['123test'],
|
|
16
|
+
});
|
|
17
|
+
mixpanel.track('test_event', {
|
|
18
|
+
success: true,
|
|
19
|
+
message: 'Super Test!',
|
|
20
|
+
tenant: ['123test'],
|
|
21
|
+
});
|
|
22
|
+
mixpanel.reset();
|
|
23
|
+
//# sourceMappingURL=test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"src/","sources":["tracking/test.ts"],"names":[],"mappings":";;AAAA,yCAA4C;AAE5C,MAAM,QAAQ,GAAG,IAAI,yBAAc,CAAC,kCAAkC,CAAC,CAAC;AAExE,QAAQ,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;AAEtC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE;IACtC,KAAK,EAAE,WAAW;IAClB,MAAM,EAAE,IAAI;CACb,CAAC,CAAC;AAEH,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC;IAClB,MAAM,EAAE,kBAAkB;IAC1B,KAAK,EAAE,UAAU;IACjB,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI;IACrC,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,CAAC,SAAS,CAAC;CACpB,CAAC,CAAC;AAEH,QAAQ,CAAC,KAAK,CAAC,YAAY,EAAE;IAC3B,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,aAAa;IACtB,MAAM,EAAE,CAAC,SAAS,CAAC;CACpB,CAAC,CAAC;AAEH,QAAQ,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { recurringFeeType_enum } from '@vrplatform/graphql';
|
|
1
|
+
import type { billing_payment_method_type_enum, recurringFeeType_enum } from '@vrplatform/graphql';
|
|
2
2
|
export type Maybe<T> = T | null | undefined;
|
|
3
3
|
export type TrackProps<T extends TrackingEvent> = OptionalUser<{
|
|
4
4
|
groupId: string;
|
|
@@ -118,6 +118,7 @@ export type TrackingEventProps = {
|
|
|
118
118
|
hyperline_trial_started: HyperlineTrialStartedProps;
|
|
119
119
|
hyperline_trial_ended: HyperlineTrialEndedProps;
|
|
120
120
|
hyperline_subscription_cancellation_scheduled: HyperlineSubscriptionEventProps;
|
|
121
|
+
hyperline_subscription_created: HyperlineSubscriptionEventProps;
|
|
121
122
|
hyperline_subscription_charged: HyperlineSubscriptionEventProps;
|
|
122
123
|
hyperline_subscription_status_changed: HyperlineSubscriptionEventProps;
|
|
123
124
|
hyperline_customer_created: HyperlineCustomerCreatedProps;
|
|
@@ -153,7 +154,7 @@ export type TenantStatus = 'active' | 'inactive';
|
|
|
153
154
|
export type SubscriptionStatus = 'active' | 'cancelled' | 'draft' | 'errored' | 'paused' | 'pending' | 'voided';
|
|
154
155
|
export type OwnerStatementStatus = 'preview' | 'draft' | 'inReview' | 'void' | 'published' | 'posted';
|
|
155
156
|
export type TaxStatementStatus = 'draft' | 'ignored' | 'inReview' | 'ready' | 'submitted' | 'error';
|
|
156
|
-
export type PaymentMethodType =
|
|
157
|
+
export type PaymentMethodType = billing_payment_method_type_enum;
|
|
157
158
|
type AccountInvitationAcceptedProps = MaybePartial<{
|
|
158
159
|
userId: string;
|
|
159
160
|
userEmail: string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Log } from '../log';
|
|
2
|
+
export declare class IntercomAPI {
|
|
3
|
+
constructor(token: string, log?: Log);
|
|
4
|
+
private headers;
|
|
5
|
+
private log?;
|
|
6
|
+
private fetch;
|
|
7
|
+
getUserByUserId(userId: string): Promise<{
|
|
8
|
+
type: "list";
|
|
9
|
+
data: {
|
|
10
|
+
id: string;
|
|
11
|
+
}[] | undefined;
|
|
12
|
+
total_count: 0;
|
|
13
|
+
pages: {
|
|
14
|
+
type: "pages";
|
|
15
|
+
page: 1;
|
|
16
|
+
per_page: 10;
|
|
17
|
+
total_pages: 0;
|
|
18
|
+
};
|
|
19
|
+
} | undefined>;
|
|
20
|
+
createUser({ data, userId, }: {
|
|
21
|
+
userId: string;
|
|
22
|
+
data: {
|
|
23
|
+
email: string;
|
|
24
|
+
name: string;
|
|
25
|
+
custom_attributes: Record<string, any>;
|
|
26
|
+
};
|
|
27
|
+
}): Promise<unknown>;
|
|
28
|
+
updateUser({ data, contactId, }: {
|
|
29
|
+
contactId: string;
|
|
30
|
+
data: {
|
|
31
|
+
email?: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
custom_attributes: Record<string, any>;
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
};
|
|
36
|
+
}): Promise<unknown>;
|
|
37
|
+
deleteUser(intercom_contact_id: string): Promise<{
|
|
38
|
+
id: "6657adf56abd0167d9419d1c";
|
|
39
|
+
external_id: "70";
|
|
40
|
+
type: "contact";
|
|
41
|
+
deleted: true;
|
|
42
|
+
} | undefined>;
|
|
43
|
+
createCompanyUser(data: {
|
|
44
|
+
intercom_contact_id: string;
|
|
45
|
+
intercom_company_id: string;
|
|
46
|
+
}): Promise<unknown>;
|
|
47
|
+
deleteCompanyUser({ intercom_company_id, intercom_contact_id, }: {
|
|
48
|
+
intercom_contact_id: string;
|
|
49
|
+
intercom_company_id: string;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
id: "6657adc96abd0167d9419ca7";
|
|
52
|
+
} | undefined>;
|
|
53
|
+
trackEvent(data: {
|
|
54
|
+
user_id: string;
|
|
55
|
+
event_name: string;
|
|
56
|
+
metadata: Record<string, any>;
|
|
57
|
+
}): Promise<unknown>;
|
|
58
|
+
getCompanyByTenantId(tenantId: string): Promise<{
|
|
59
|
+
type: "list";
|
|
60
|
+
data: [{
|
|
61
|
+
type: "company";
|
|
62
|
+
company_id: "remote_companies_scroll_2";
|
|
63
|
+
id: "664df5436abd01f7945e1a78";
|
|
64
|
+
app_id: "this_is_an_id111_that_should_be_at_least_";
|
|
65
|
+
name: "IntercomQATest1";
|
|
66
|
+
remote_created_at: 1716385091;
|
|
67
|
+
created_at: 1716385091;
|
|
68
|
+
updated_at: 1716385091;
|
|
69
|
+
monthly_spend: 0;
|
|
70
|
+
session_count: 0;
|
|
71
|
+
user_count: 4;
|
|
72
|
+
tags: {
|
|
73
|
+
type: "tag.list";
|
|
74
|
+
tags: [];
|
|
75
|
+
};
|
|
76
|
+
segments: {
|
|
77
|
+
type: "segment.list";
|
|
78
|
+
segments: [];
|
|
79
|
+
};
|
|
80
|
+
custom_attributes: Record<string, string>;
|
|
81
|
+
}] | undefined;
|
|
82
|
+
pages: {
|
|
83
|
+
type: "pages";
|
|
84
|
+
next: null;
|
|
85
|
+
page: 1;
|
|
86
|
+
per_page: 15;
|
|
87
|
+
total_pages: 1;
|
|
88
|
+
};
|
|
89
|
+
total_count: 1;
|
|
90
|
+
} | undefined>;
|
|
91
|
+
createCompany({ data, tenantId, }: {
|
|
92
|
+
tenantId: string;
|
|
93
|
+
data: {
|
|
94
|
+
name: string;
|
|
95
|
+
remote_created_at: number;
|
|
96
|
+
custom_attributes: Record<string, any>;
|
|
97
|
+
};
|
|
98
|
+
}): Promise<unknown>;
|
|
99
|
+
updateCompany({ data, companyId, }: {
|
|
100
|
+
companyId: string;
|
|
101
|
+
data: Record<string, any>;
|
|
102
|
+
}): Promise<unknown>;
|
|
103
|
+
deleteCompany(intercom_company_id: string): Promise<{
|
|
104
|
+
id: "6657adc96abd0167d9419ca7";
|
|
105
|
+
object: "company";
|
|
106
|
+
deleted: true;
|
|
107
|
+
} | undefined>;
|
|
108
|
+
}
|
|
109
|
+
export declare function useIntercom(token: string, log?: Log): IntercomAPI;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export class IntercomAPI {
|
|
2
|
+
constructor(token, log) {
|
|
3
|
+
this.headers = {
|
|
4
|
+
'Content-Type': 'application/json',
|
|
5
|
+
Accept: 'application/json',
|
|
6
|
+
'Intercom-Version': '2.11',
|
|
7
|
+
Authorization: `Bearer ${token}`,
|
|
8
|
+
};
|
|
9
|
+
this.log = log;
|
|
10
|
+
}
|
|
11
|
+
headers;
|
|
12
|
+
log;
|
|
13
|
+
async fetch(path, options) {
|
|
14
|
+
if (options?.data) {
|
|
15
|
+
options.body = JSON.stringify(options.data);
|
|
16
|
+
options.data = undefined;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const result = await fetch(`https://api.intercom.io${path}`, {
|
|
20
|
+
method: 'GET',
|
|
21
|
+
headers: this.headers,
|
|
22
|
+
...options,
|
|
23
|
+
});
|
|
24
|
+
if (!result.ok) {
|
|
25
|
+
this.log?.info('Failed to fetch from Intercom', {
|
|
26
|
+
result: {
|
|
27
|
+
status: result.status,
|
|
28
|
+
statusText: result.statusText,
|
|
29
|
+
body: await result.text(),
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
if (result.status === 404)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (result.status === 429) {
|
|
35
|
+
console.log('Intercom rate limit exceeded, waiting for 1 minute');
|
|
36
|
+
// X-RateLimit-Reset: 1487332520 => timestamp from header response when resetting
|
|
37
|
+
const reset = Number(result.headers.get('X-RateLimit-Reset'));
|
|
38
|
+
if (reset) {
|
|
39
|
+
const now = Math.floor(Date.now() / 1000);
|
|
40
|
+
const wait = reset - now + 1;
|
|
41
|
+
console.log(`Waiting for ${wait} seconds`);
|
|
42
|
+
await new Promise((resolve) => setTimeout(resolve, wait * 1000));
|
|
43
|
+
return await this.fetch(path, options);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return result.status === 202 ? {} : (await result.json());
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
this.log?.error(error);
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// User
|
|
55
|
+
async getUserByUserId(userId) {
|
|
56
|
+
return await this.fetch('/contacts/search', {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
data: {
|
|
59
|
+
query: {
|
|
60
|
+
field: 'external_id',
|
|
61
|
+
operator: '=',
|
|
62
|
+
value: userId,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async createUser({ data, userId, }) {
|
|
68
|
+
return await this.fetch('/contacts', {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
data: { ...data, external_id: userId },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async updateUser({ data, contactId, }) {
|
|
74
|
+
return await this.fetch(`/contacts/${contactId}`, {
|
|
75
|
+
method: 'PUT',
|
|
76
|
+
data,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
async deleteUser(intercom_contact_id) {
|
|
80
|
+
return await this.fetch(`/contacts/${intercom_contact_id}`, {
|
|
81
|
+
method: 'DELETE',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async createCompanyUser(data) {
|
|
85
|
+
return await this.fetch(`/contacts/${data.intercom_contact_id}/companies`, {
|
|
86
|
+
method: 'POST',
|
|
87
|
+
data: {
|
|
88
|
+
id: data.intercom_company_id,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async deleteCompanyUser({ intercom_company_id, intercom_contact_id, }) {
|
|
93
|
+
return await this.fetch(`/contacts/${intercom_contact_id}/companies/${intercom_company_id}`, {
|
|
94
|
+
method: 'DELETE',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async trackEvent(data) {
|
|
98
|
+
return await this.fetch('/events', {
|
|
99
|
+
method: 'POST',
|
|
100
|
+
data: {
|
|
101
|
+
created_at: Math.floor(new Date().getTime() / 1000), // to seconds
|
|
102
|
+
...data,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// Company
|
|
107
|
+
async getCompanyByTenantId(tenantId) {
|
|
108
|
+
return await this.fetch(`/companies?company_id=${tenantId}`, {
|
|
109
|
+
method: 'GET',
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
async createCompany({ data, tenantId, }) {
|
|
113
|
+
return await this.fetch('/companies', {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
data: {
|
|
116
|
+
...data,
|
|
117
|
+
company_id: tenantId,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async updateCompany({ data, companyId, }) {
|
|
122
|
+
return await this.fetch(`/companies/${companyId}`, {
|
|
123
|
+
method: 'PUT',
|
|
124
|
+
data,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async deleteCompany(intercom_company_id) {
|
|
128
|
+
return await this.fetch(`/companies/${intercom_company_id}`, {
|
|
129
|
+
method: 'DELETE',
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export function useIntercom(token, log) {
|
|
134
|
+
return new IntercomAPI(token, log);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=_intercom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_intercom.js","sourceRoot":"src/","sources":["tracking/_intercom.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAW;IACtB,YAAY,KAAa,EAAE,GAAS;QAClC,IAAI,CAAC,OAAO,GAAG;YACb,cAAc,EAAE,kBAAkB;YAClC,MAAM,EAAE,kBAAkB;YAC1B,kBAAkB,EAAE,MAAM;YAC1B,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC,CAAC;QAEF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAEO,OAAO,CAAyB;IAChC,GAAG,CAAO;IAEV,KAAK,CAAC,KAAK,CACjB,IAAY,EACZ,OAAsC;QAEtC,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;YAClB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC5C,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,0BAA0B,IAAI,EAAE,EAAE;gBAC3D,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,GAAG,OAAO;aACX,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;gBACf,IAAI,CAAC,GAAG,EAAE,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,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
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';
|
|
2
|
+
type TeamEvent = 'team_added' | 'team_info_updated' | 'team_deleted' | 'team_member_removed';
|
|
3
|
+
type ConnectionEvent = 'connection_created' | 'connection_reconnected' | 'connection_deleted' | 'connection_requested';
|
|
4
|
+
type OwnershipEvent = 'ownership_created' | 'ownership_updated' | 'ownership_deleted';
|
|
5
|
+
type OwnerEvent = 'owner_created' | 'owner_updated' | 'owner_deleted' | 'owner_tax_info_modal_opened' | 'owner_tax_info_modal_submitted';
|
|
6
|
+
type SetupEvent = 'setup_classes_set' | 'setup_accounting_version_completed' | 'setup_accounting_config_completed' | 'setup_owner_imported' | 'setup_listing_imported';
|
|
7
|
+
type AutomationEvent = 'automation_created' | 'automation_updated' | 'automation_deleted';
|
|
8
|
+
type TaxStatementEvent = 'tax_statement_preview_opened' | 'tax_statement_downloaded';
|
|
9
|
+
type GLOwnerStatementEvent = 'gl_owner_statement_preview_opened' | 'gl_owner_statement_downloaded';
|
|
10
|
+
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';
|
|
11
|
+
type ListingEvent = 'listing_activated' | 'listing_deactivated';
|
|
12
|
+
type ReportEvent = 'listings_reported';
|
|
13
|
+
type UserEvent = 'update_refresh_accepted' | 'owner_statement_opened';
|
|
14
|
+
type TestEvent = 'test_event' | 'test_error';
|
|
15
|
+
export type TrackingEvent = AuthEvent | TeamEvent | ConnectionEvent | OwnershipEvent | OwnerEvent | SetupEvent | AutomationEvent | TaxStatementEvent | GLOwnerStatementEvent | HyperlineEvent | UserEvent | ListingEvent | ReportEvent | TestEvent;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventTypes.js","sourceRoot":"src/","sources":["tracking/eventTypes.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare module
|
|
1
|
+
declare module 'intercom-client' {
|
|
2
2
|
namespace Intercom {
|
|
3
3
|
interface CreateContactRequestWithExternalId {
|
|
4
4
|
/** A unique identifier for the contact which is given to Intercom */
|
|
@@ -22,7 +22,7 @@ declare module "intercom-client" {
|
|
|
22
22
|
}
|
|
23
23
|
interface UpdateContactRequest {
|
|
24
24
|
/** The role of the contact. */
|
|
25
|
-
role?:
|
|
25
|
+
role?: 'user' | 'lead';
|
|
26
26
|
/** A unique identifier for the contact which is given to Intercom */
|
|
27
27
|
external_id?: string;
|
|
28
28
|
/** The contacts email */
|
|
@@ -85,12 +85,12 @@ declare module "intercom-client" {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
import { Intercom } from
|
|
89
|
-
import { type LogBindings, type WorkerLog } from
|
|
90
|
-
import type { GroupProps, IdentifyProps, TrackingEvent, TrackProps } from
|
|
91
|
-
export * from
|
|
92
|
-
export * from
|
|
93
|
-
export * from
|
|
88
|
+
import { Intercom } from 'intercom-client';
|
|
89
|
+
import { type LogBindings, type WorkerLog } from '../log';
|
|
90
|
+
import type { GroupProps, IdentifyProps, TrackingEvent, TrackProps } from './types';
|
|
91
|
+
export * from 'intercom-client';
|
|
92
|
+
export * from '../utils';
|
|
93
|
+
export * from './types';
|
|
94
94
|
export type Tracking = ReturnType<typeof useTracking>;
|
|
95
95
|
export type UseTracking = {
|
|
96
96
|
name?: string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useHasuraClient } from
|
|
2
|
-
import { Intercom } from
|
|
3
|
-
import { useLog } from
|
|
4
|
-
import { isTest, isVrpMember } from
|
|
5
|
-
import { convertValuesToString } from
|
|
6
|
-
import { MixpanelClient } from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
1
|
+
import { useHasuraClient } from '@vrplatform/graphql';
|
|
2
|
+
import { Intercom } from 'intercom-client';
|
|
3
|
+
import { useLog } from '../log';
|
|
4
|
+
import { isTest, isVrpMember } from '../utils';
|
|
5
|
+
import { convertValuesToString } from '../utils/convertValuesToString';
|
|
6
|
+
import { MixpanelClient } from './mixpanel';
|
|
7
|
+
export * from 'intercom-client';
|
|
8
|
+
export * from '../utils';
|
|
9
|
+
export * from './types';
|
|
10
10
|
export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
11
11
|
const client = env.HASURA_ADMIN_SECRET || env.HASURA_GRAPHQL_ADMIN_SECRET
|
|
12
12
|
? useHasuraClient({
|
|
@@ -28,7 +28,7 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
28
28
|
// General
|
|
29
29
|
track: async ({ userId, anonymousId, groupId, event, packageName, properties, timestamp, }, _import = false) => {
|
|
30
30
|
if (isDev ||
|
|
31
|
-
isTest(userId || anonymousId ||
|
|
31
|
+
isTest(userId || anonymousId || '', groupId) ||
|
|
32
32
|
isVrpMember(userId || anonymousId))
|
|
33
33
|
return;
|
|
34
34
|
const id = await client?.mutate((q) => q.insert_tracking_event_one({
|
|
@@ -91,19 +91,19 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
91
91
|
if (mixpanel) {
|
|
92
92
|
mixpanel.identify(userId);
|
|
93
93
|
const {
|
|
94
|
-
// biome-ignore lint/correctness/noUnusedVariables:
|
|
94
|
+
// biome-ignore lint/correctness/noUnusedVariables: excluded to compute rest
|
|
95
95
|
firstName,
|
|
96
|
-
// biome-ignore lint/correctness/noUnusedVariables:
|
|
96
|
+
// biome-ignore lint/correctness/noUnusedVariables: excluded to compute rest
|
|
97
97
|
lastName,
|
|
98
|
-
// biome-ignore lint/correctness/noUnusedVariables:
|
|
98
|
+
// biome-ignore lint/correctness/noUnusedVariables: excluded to compute rest
|
|
99
99
|
name,
|
|
100
|
-
// biome-ignore lint/correctness/noUnusedVariables:
|
|
100
|
+
// biome-ignore lint/correctness/noUnusedVariables: excluded to compute rest
|
|
101
101
|
email,
|
|
102
|
-
// biome-ignore lint/correctness/noUnusedVariables:
|
|
102
|
+
// biome-ignore lint/correctness/noUnusedVariables: excluded to compute rest
|
|
103
103
|
avatar,
|
|
104
|
-
// biome-ignore lint/correctness/noUnusedVariables:
|
|
104
|
+
// biome-ignore lint/correctness/noUnusedVariables: excluded to compute rest
|
|
105
105
|
lastSeenAt,
|
|
106
|
-
// biome-ignore lint/correctness/noUnusedVariables:
|
|
106
|
+
// biome-ignore lint/correctness/noUnusedVariables: excluded to compute rest
|
|
107
107
|
createdAt, ...rest } = traits || {};
|
|
108
108
|
mixpanel.people.set({
|
|
109
109
|
$distinct_id: userId,
|
|
@@ -130,8 +130,8 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
130
130
|
};
|
|
131
131
|
const intercomUser = (await intercom?.contacts.search({
|
|
132
132
|
query: {
|
|
133
|
-
field:
|
|
134
|
-
operator:
|
|
133
|
+
field: 'external_id',
|
|
134
|
+
operator: '=',
|
|
135
135
|
value: userId,
|
|
136
136
|
},
|
|
137
137
|
}))?.data?.at(0);
|
|
@@ -146,7 +146,7 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
146
146
|
},
|
|
147
147
|
group: async ({ traits = {}, groupId, userId, anonymousId, }) => {
|
|
148
148
|
if (isDev ||
|
|
149
|
-
isTest(userId || anonymousId ||
|
|
149
|
+
isTest(userId || anonymousId || '', groupId) ||
|
|
150
150
|
isVrpMember(userId || anonymousId))
|
|
151
151
|
return;
|
|
152
152
|
// add teamId to traits
|
|
@@ -155,11 +155,11 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
155
155
|
const cid = traits?.billingCustomerId;
|
|
156
156
|
const partner = traits?.partner || traits?.accountingPartner; // TODO: remove legacy accountingPartner
|
|
157
157
|
const billingPartner = traits?.billingPartner || traits?.partner || traits?.accountingPartner; // TODO: remove legacy accountingPartner
|
|
158
|
-
if (billingPartner ===
|
|
158
|
+
if (billingPartner === '0b6a7bd6-56cc-46b5-b2ab-1bd7d1e994fa')
|
|
159
159
|
return; // dismiss Demo and Test Console
|
|
160
160
|
// upsert mixpanel group
|
|
161
161
|
if (mixpanel)
|
|
162
|
-
mixpanel.group.set(
|
|
162
|
+
mixpanel.group.set('tenant', groupId, {
|
|
163
163
|
$distinct_id: groupId,
|
|
164
164
|
$name: traits?.name,
|
|
165
165
|
$avatar: traits.avatar,
|
|
@@ -185,7 +185,7 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
185
185
|
trialUntil: traits?.trialUntil,
|
|
186
186
|
isOnboarding: traits?.isOnboarding,
|
|
187
187
|
isTest: billingPartner
|
|
188
|
-
? billingPartner ===
|
|
188
|
+
? billingPartner === 'Demo and Test Console'
|
|
189
189
|
: undefined,
|
|
190
190
|
});
|
|
191
191
|
let intercomCompany;
|
|
@@ -234,8 +234,8 @@ export const useTracking = ({ dataset, env, name }, isDev) => {
|
|
|
234
234
|
try {
|
|
235
235
|
const intercomUser = (await intercom?.contacts.search({
|
|
236
236
|
query: {
|
|
237
|
-
field:
|
|
238
|
-
operator:
|
|
237
|
+
field: 'external_id',
|
|
238
|
+
operator: '=',
|
|
239
239
|
value: userId,
|
|
240
240
|
},
|
|
241
241
|
}))?.data?.at(0);
|