@vrplatform/log 1.0.19 → 1.0.21

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.
Files changed (71) hide show
  1. package/build/main/baselog.js.map +1 -0
  2. package/build/main/color.js.map +1 -0
  3. package/build/main/common.js.map +1 -0
  4. package/build/main/index.d.ts +22 -2
  5. package/build/main/index.js +74 -2
  6. package/build/main/index.js.map +1 -1
  7. package/build/main/index.spec.d.ts +0 -0
  8. package/build/main/index.spec.js +2 -0
  9. package/build/main/index.spec.js.map +1 -0
  10. package/build/{module/log → main}/type.d.ts +3 -1
  11. package/build/main/type.js.map +1 -0
  12. package/build/module/baselog.js.map +1 -0
  13. package/build/module/color.js.map +1 -0
  14. package/build/module/common.js.map +1 -0
  15. package/build/module/index.d.ts +22 -2
  16. package/build/module/index.js +73 -2
  17. package/build/module/index.js.map +1 -1
  18. package/build/module/index.spec.d.ts +0 -0
  19. package/build/module/index.spec.js +2 -0
  20. package/build/module/index.spec.js.map +1 -0
  21. package/build/{main/log → module}/type.d.ts +3 -1
  22. package/build/module/type.js.map +1 -0
  23. package/package.json +20 -24
  24. package/src/index.ts +127 -2
  25. package/src/{log/type.ts → type.ts} +5 -1
  26. package/build/main/log/baselog.js.map +0 -1
  27. package/build/main/log/color.js.map +0 -1
  28. package/build/main/log/common.js.map +0 -1
  29. package/build/main/log/index.d.ts +0 -22
  30. package/build/main/log/index.js +0 -91
  31. package/build/main/log/index.js.map +0 -1
  32. package/build/main/log/type.js.map +0 -1
  33. package/build/main/tracking/index.d.ts +0 -36
  34. package/build/main/tracking/index.js +0 -80
  35. package/build/main/tracking/index.js.map +0 -1
  36. package/build/main/tracking/intercom.d.ts +0 -108
  37. package/build/main/tracking/intercom.js +0 -139
  38. package/build/main/tracking/intercom.js.map +0 -1
  39. package/build/module/log/baselog.js.map +0 -1
  40. package/build/module/log/color.js.map +0 -1
  41. package/build/module/log/common.js.map +0 -1
  42. package/build/module/log/index.d.ts +0 -22
  43. package/build/module/log/index.js +0 -74
  44. package/build/module/log/index.js.map +0 -1
  45. package/build/module/log/type.js.map +0 -1
  46. package/build/module/tracking/index.d.ts +0 -36
  47. package/build/module/tracking/index.js +0 -76
  48. package/build/module/tracking/index.js.map +0 -1
  49. package/build/module/tracking/intercom.d.ts +0 -108
  50. package/build/module/tracking/intercom.js +0 -136
  51. package/build/module/tracking/intercom.js.map +0 -1
  52. package/src/log/index.ts +0 -127
  53. package/src/tracking/index.ts +0 -115
  54. package/src/tracking/intercom.ts +0 -257
  55. /package/build/main/{log/baselog.d.ts → baselog.d.ts} +0 -0
  56. /package/build/main/{log/baselog.js → baselog.js} +0 -0
  57. /package/build/main/{log/color.d.ts → color.d.ts} +0 -0
  58. /package/build/main/{log/color.js → color.js} +0 -0
  59. /package/build/main/{log/common.d.ts → common.d.ts} +0 -0
  60. /package/build/main/{log/common.js → common.js} +0 -0
  61. /package/build/main/{log/type.js → type.js} +0 -0
  62. /package/build/module/{log/baselog.d.ts → baselog.d.ts} +0 -0
  63. /package/build/module/{log/baselog.js → baselog.js} +0 -0
  64. /package/build/module/{log/color.d.ts → color.d.ts} +0 -0
  65. /package/build/module/{log/color.js → color.js} +0 -0
  66. /package/build/module/{log/common.d.ts → common.d.ts} +0 -0
  67. /package/build/module/{log/common.js → common.js} +0 -0
  68. /package/build/module/{log/type.js → type.js} +0 -0
  69. /package/src/{log/baselog.ts → baselog.ts} +0 -0
  70. /package/src/{log/color.ts → color.ts} +0 -0
  71. /package/src/{log/common.ts → common.ts} +0 -0
@@ -1,257 +0,0 @@
1
- import type { Log } from '../log';
2
-
3
- export class IntercomAPI {
4
- constructor(token: string, log?: Log) {
5
- this.headers = {
6
- 'Content-Type': 'application/json',
7
- Accept: 'application/json',
8
- 'Intercom-Version': '2.11',
9
- Authorization: `Bearer ${token}`,
10
- };
11
-
12
- this.log = log;
13
- }
14
-
15
- private headers: Record<string, string>;
16
- private log?: Log;
17
-
18
- private async fetch<T>(
19
- path: string,
20
- options?: RequestInit & { data?: any }
21
- ): Promise<T | undefined> {
22
- if (options?.data) {
23
- options.body = JSON.stringify(options.data);
24
- options.data = undefined;
25
- }
26
-
27
- try {
28
- const result = await fetch(`https://api.intercom.io${path}`, {
29
- method: 'GET',
30
- headers: this.headers,
31
- ...options,
32
- });
33
-
34
- if (!result.ok) {
35
- this.log?.info('Failed to fetch from Intercom', {
36
- result: {
37
- status: result.status,
38
- statusText: result.statusText,
39
- body: await result.text(),
40
- },
41
- });
42
-
43
- if (result.status === 404) return undefined;
44
-
45
- if (result.status === 429) {
46
- console.log('Intercom rate limit exceeded, waiting for 1 minute');
47
- // X-RateLimit-Reset: 1487332520 => timestamp from header response when resetting
48
-
49
- const reset = Number(result.headers.get('X-RateLimit-Reset'));
50
-
51
- if (reset) {
52
- const now = Math.floor(Date.now() / 1000);
53
- const wait = reset - now + 1;
54
- console.log(`Waiting for ${wait} seconds`);
55
- await new Promise((resolve) => setTimeout(resolve, wait * 1000));
56
-
57
- return await this.fetch(path, options);
58
- }
59
- }
60
- }
61
- return result.status === 202 ? ({} as T) : ((await result.json()) as T);
62
- } catch (error: any) {
63
- this.log?.error(error);
64
- return undefined;
65
- }
66
- }
67
-
68
- // User
69
- async getUserByUserId(userId: string) {
70
- return await this.fetch<{
71
- type: 'list';
72
- data: { id: string }[] | undefined;
73
- total_count: 0;
74
- pages: {
75
- type: 'pages';
76
- page: 1;
77
- per_page: 10;
78
- total_pages: 0;
79
- };
80
- }>('/contacts/search', {
81
- method: 'POST',
82
- data: {
83
- query: {
84
- field: 'external_id',
85
- operator: '=',
86
- value: userId,
87
- },
88
- },
89
- });
90
- }
91
- async createUser({
92
- data,
93
- userId,
94
- }: {
95
- userId: string;
96
- data: {
97
- email: string;
98
- name: string;
99
- custom_attributes: Record<string, any>;
100
- };
101
- }) {
102
- return await this.fetch('/contacts', {
103
- method: 'POST',
104
- data: { ...data, external_id: userId },
105
- });
106
- }
107
- async updateUser({
108
- data,
109
- contactId,
110
- }: {
111
- contactId: string;
112
- data: {
113
- email?: string;
114
- name?: string;
115
- custom_attributes: Record<string, any>;
116
- };
117
- }) {
118
- return await this.fetch(`/contacts/${contactId}`, {
119
- method: 'PUT',
120
- data,
121
- });
122
- }
123
- async deleteUser(intercom_contact_id: string) {
124
- return await this.fetch<{
125
- id: '6657adf56abd0167d9419d1c';
126
- external_id: '70';
127
- type: 'contact';
128
- deleted: true;
129
- }>(`/contacts/${intercom_contact_id}`, {
130
- method: 'DELETE',
131
- });
132
- }
133
- async createCompanyUser(data: {
134
- intercom_contact_id: string;
135
- intercom_company_id: string;
136
- }) {
137
- return await this.fetch(`/contacts/${data.intercom_contact_id}/companies`, {
138
- method: 'POST',
139
- data: {
140
- id: data.intercom_company_id,
141
- },
142
- });
143
- }
144
- async deleteCompanyUser({
145
- intercom_company_id,
146
- intercom_contact_id,
147
- }: {
148
- intercom_contact_id: string;
149
- intercom_company_id: string;
150
- }) {
151
- return await this.fetch<{
152
- id: '6657adc96abd0167d9419ca7';
153
- }>(`/contacts/${intercom_contact_id}/companies/${intercom_company_id}`, {
154
- method: 'DELETE',
155
- });
156
- }
157
- async trackEvent(data: {
158
- user_id: string;
159
- event_name: string;
160
- metadata: Record<string, any>;
161
- }) {
162
- return await this.fetch('/events', {
163
- method: 'POST',
164
- data: {
165
- created_at: Math.floor(new Date().getTime() / 1000), // to seconds
166
- ...data,
167
- },
168
- });
169
- }
170
-
171
- // Company
172
- async getCompanyByTenantId(tenantId: string) {
173
- return await this.fetch<{
174
- type: 'list';
175
- data:
176
- | [
177
- {
178
- type: 'company';
179
- company_id: 'remote_companies_scroll_2';
180
- id: '664df5436abd01f7945e1a78';
181
- app_id: 'this_is_an_id111_that_should_be_at_least_';
182
- name: 'IntercomQATest1';
183
- remote_created_at: 1716385091;
184
- created_at: 1716385091;
185
- updated_at: 1716385091;
186
- monthly_spend: 0;
187
- session_count: 0;
188
- user_count: 4;
189
- tags: {
190
- type: 'tag.list';
191
- tags: [];
192
- };
193
- segments: {
194
- type: 'segment.list';
195
- segments: [];
196
- };
197
- custom_attributes: Record<string, string>;
198
- },
199
- ]
200
- | undefined;
201
- pages: {
202
- type: 'pages';
203
- next: null;
204
- page: 1;
205
- per_page: 15;
206
- total_pages: 1;
207
- };
208
- total_count: 1;
209
- }>(`/companies?company_id=${tenantId}`, {
210
- method: 'GET',
211
- });
212
- }
213
- async createCompany({
214
- data,
215
- tenantId,
216
- }: {
217
- tenantId: string;
218
- data: {
219
- name: string;
220
- remote_created_at: string;
221
- custom_attributes: Record<string, any>;
222
- };
223
- }) {
224
- return await this.fetch('/companies', {
225
- method: 'POST',
226
- data: {
227
- ...data,
228
- company_id: tenantId,
229
- },
230
- });
231
- }
232
- async updateCompany({
233
- data,
234
- companyId,
235
- }: {
236
- companyId: string;
237
- data: Record<string, any>;
238
- }) {
239
- return await this.fetch(`/companies/${companyId}`, {
240
- method: 'PUT',
241
- data,
242
- });
243
- }
244
- async deleteCompany(intercom_company_id: string) {
245
- return await this.fetch<{
246
- id: '6657adc96abd0167d9419ca7';
247
- object: 'company';
248
- deleted: true;
249
- }>(`/companies/${intercom_company_id}`, {
250
- method: 'DELETE',
251
- });
252
- }
253
- }
254
-
255
- export function useIntercom(token: string, log?: Log) {
256
- return new IntercomAPI(token, log);
257
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes