@maxzima/wa-communicator 1.0.20 → 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.
@@ -1,6 +1,15 @@
1
+ declare const enum GA4EventActionEnum {
2
+ VERIFY_CONTACT = "verify_contact"
3
+ }
4
+ declare const enum GA4EventContactEnum {
5
+ PHONE = "phone",
6
+ EMAIL = "email"
7
+ }
1
8
  declare const enum LintrkActionTypeEnum {
2
9
  TRACK = "track"
3
10
  }
4
11
  declare const enum LintrkEventIdEnum {
12
+ PHONE = 8612332,
13
+ EMAIL = 8612340,
5
14
  REGISTRATION = 8612308
6
15
  }
@@ -1,6 +1,9 @@
1
1
  export declare class AccountTracker {
2
2
  private props;
3
3
  constructor(props: TAccountTrackerProps);
4
+ sendPhoneVerifyEvent(): void;
5
+ sendEmailVerifyEvent(): void;
4
6
  sendRegistrationSuccessEvent(): void;
7
+ private sendGA4Event;
5
8
  private sendLinkedInEvent;
6
9
  }
@@ -1,5 +1,16 @@
1
1
  export class AccountTracker {
2
2
  constructor(props) {
3
+ this.sendGA4Event = (action, contact) => {
4
+ if (typeof this.props.gtag === 'undefined' || !this.props.ga4Id) {
5
+ return;
6
+ }
7
+ const params = {
8
+ contact: contact,
9
+ origin: this.props.origin || null,
10
+ send_to: this.props.ga4Id,
11
+ };
12
+ this.props.gtag('event', action, params);
13
+ };
3
14
  this.sendLinkedInEvent = (id) => {
4
15
  if (typeof this.props.lintrk === 'undefined') {
5
16
  return;
@@ -10,6 +21,14 @@ export class AccountTracker {
10
21
  };
11
22
  this.props = props;
12
23
  }
24
+ sendPhoneVerifyEvent() {
25
+ this.sendGA4Event("verify_contact", "phone");
26
+ this.sendLinkedInEvent(8612332);
27
+ }
28
+ sendEmailVerifyEvent() {
29
+ this.sendGA4Event("verify_contact", "email");
30
+ this.sendLinkedInEvent(8612340);
31
+ }
13
32
  sendRegistrationSuccessEvent() {
14
33
  this.sendLinkedInEvent(8612308);
15
34
  }
@@ -1,6 +1,15 @@
1
+ /// <reference types="gtag.js" />
1
2
  declare type TLintrkOptions = {
2
3
  conversation_id: LintrkEventIdEnum;
3
4
  };
5
+ declare type TGA4Event = {
6
+ contact: GA4EventContactEnum;
7
+ send_to: TAccountTrackerProps['ga4Id'];
8
+ origin?: TAccountTrackerProps['origin'];
9
+ };
4
10
  declare type TAccountTrackerProps = {
11
+ origin?: string;
12
+ gtag?: Gtag.Gtag;
5
13
  lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
14
+ ga4Id?: string;
6
15
  };
@@ -42,7 +42,8 @@ export class Communicator {
42
42
  const headers = this.getHeaders();
43
43
  const meta = this.getMeta(data.browserData);
44
44
  const body = JSON.stringify({
45
- captcha_response: '_',
45
+ captcha_solution: '_',
46
+ device_id: data.deviceId,
46
47
  meta,
47
48
  mobile: data.phoneNumber,
48
49
  });
@@ -18,7 +18,8 @@ declare type TResponse = {
18
18
  ok: boolean;
19
19
  };
20
20
  declare type TSignInStartRequestBody = {
21
- captcha_response?: string;
21
+ captcha_solution?: string;
22
+ device_id: string;
22
23
  meta: TAccountMeta;
23
24
  mobile?: string;
24
25
  };
@@ -39,6 +40,7 @@ declare type TAccountBrowserData = {
39
40
  };
40
41
  declare type TSignInByMobileRequestData = {
41
42
  phoneNumber: string;
43
+ deviceId: string;
42
44
  browserData: TAccountBrowserData;
43
45
  };
44
46
  declare type TSignInByMobileResponse = {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.20",
2
+ "version": "1.0.21",
3
3
  "name": "@maxzima/wa-communicator",
4
4
  "description": "",
5
5
  "author": "Noname",
@@ -7,7 +7,7 @@
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
9
  "engines": {
10
- "node": ">=14"
10
+ "node": ">=20.11.1 <21"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
@@ -23,7 +23,8 @@
23
23
  }
24
24
  ],
25
25
  "scripts": {
26
- "prepublishOnly": "npm run test && npm run build && npm run size",
26
+ "postinstall": "engine-version",
27
+ "prepublishOnly": "engine-version && npm run test && npm run build && npm run size",
27
28
  "clean": "node tools/cleanup",
28
29
  "build": "npm run clean && run-p build:*",
29
30
  "build:esm": "tsc -p config/tsconfig.esm.json",
@@ -40,6 +41,7 @@
40
41
  "@types/jest": "28.1.8",
41
42
  "@typescript-eslint/eslint-plugin": "5.59.5",
42
43
  "@typescript-eslint/parser": "5.59.5",
44
+ "engine-version": "^1.0.2",
43
45
  "eslint": "8.40.0",
44
46
  "eslint-config-prettier": "8.8.0",
45
47
  "eslint-plugin-editorconfig": "4.0.3",
@@ -1,7 +1,18 @@
1
+ const enum GA4EventActionEnum {
2
+ VERIFY_CONTACT = 'verify_contact',
3
+ }
4
+
5
+ const enum GA4EventContactEnum {
6
+ PHONE = 'phone',
7
+ EMAIL = 'email',
8
+ }
9
+
1
10
  const enum LintrkActionTypeEnum {
2
11
  TRACK= 'track',
3
12
  }
4
13
 
5
14
  const enum LintrkEventIdEnum {
15
+ PHONE = 8612332,
16
+ EMAIL = 8612340,
6
17
  REGISTRATION = 8612308,
7
18
  }
@@ -5,10 +5,34 @@ export class AccountTracker {
5
5
  this.props = props;
6
6
  }
7
7
 
8
+ public sendPhoneVerifyEvent () {
9
+ this.sendGA4Event(GA4EventActionEnum.VERIFY_CONTACT, GA4EventContactEnum.PHONE);
10
+ this.sendLinkedInEvent(LintrkEventIdEnum.PHONE);
11
+ }
12
+
13
+ public sendEmailVerifyEvent () {
14
+ this.sendGA4Event(GA4EventActionEnum.VERIFY_CONTACT, GA4EventContactEnum.EMAIL);
15
+ this.sendLinkedInEvent(LintrkEventIdEnum.EMAIL);
16
+ }
17
+
8
18
  public sendRegistrationSuccessEvent () {
9
19
  this.sendLinkedInEvent(LintrkEventIdEnum.REGISTRATION);
10
20
  }
11
21
 
22
+ private sendGA4Event = (action: GA4EventActionEnum, contact: GA4EventContactEnum) => {
23
+ if (typeof this.props.gtag === 'undefined' || !this.props.ga4Id) {
24
+ return;
25
+ }
26
+
27
+ const params: TGA4Event = {
28
+ contact: contact,
29
+ origin: this.props.origin || null,
30
+ send_to: this.props.ga4Id,
31
+ };
32
+
33
+ this.props.gtag('event', action, params);
34
+ };
35
+
12
36
  private sendLinkedInEvent = (id: LintrkEventIdEnum) => {
13
37
  if (typeof this.props.lintrk === 'undefined') {
14
38
  return;
@@ -2,6 +2,15 @@ type TLintrkOptions = {
2
2
  conversation_id: LintrkEventIdEnum;
3
3
  }
4
4
 
5
+ type TGA4Event = {
6
+ contact: GA4EventContactEnum;
7
+ send_to: TAccountTrackerProps['ga4Id'];
8
+ origin?: TAccountTrackerProps['origin'];
9
+ }
10
+
5
11
  type TAccountTrackerProps = {
12
+ origin?: string;
13
+ gtag?: Gtag.Gtag;
6
14
  lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
15
+ ga4Id?: string;
7
16
  }
@@ -35,7 +35,8 @@ export class Communicator {
35
35
  const headers = this.getHeaders();
36
36
  const meta = this.getMeta(data.browserData);
37
37
  const body = JSON.stringify({
38
- captcha_response: '_',
38
+ captcha_solution: '_',
39
+ device_id: data.deviceId,
39
40
  meta,
40
41
  mobile: data.phoneNumber,
41
42
  } as TSignInStartRequestBody);
@@ -23,7 +23,8 @@ type TResponse = {
23
23
 
24
24
  /* region signIn */
25
25
  type TSignInStartRequestBody = {
26
- captcha_response?: string,
26
+ captcha_solution?: string,
27
+ device_id: string,
27
28
  meta: TAccountMeta,
28
29
  mobile?: string,
29
30
  }
@@ -47,6 +48,7 @@ type TAccountBrowserData = {
47
48
 
48
49
  type TSignInByMobileRequestData = {
49
50
  phoneNumber: string,
51
+ deviceId: string,
50
52
  browserData: TAccountBrowserData,
51
53
  }
52
54
 
@@ -125,7 +125,7 @@ Object {
125
125
 
126
126
  exports[`Communicator requests signIn 1`] = `
127
127
  Object {
128
- "body": "{\\"captcha_response\\":\\"_\\",\\"meta\\":{\\"audit_source_type\\":\\"Backend\\",\\"browser_page_resolution\\":\\"800x600\\",\\"cookies_enabled\\":true,\\"ip\\":\\"127.0.0.1\\",\\"js_enabled\\":true,\\"language\\":\\"ENG\\",\\"user_agent\\":\\"_userAgent_\\"},\\"mobile\\":\\"+16234401486\\"}",
128
+ "body": "{\\"captcha_solution\\":\\"_\\",\\"device_id\\":\\"ov4lNmyk7armoC5DMiOpL5hl846kVQgS\\",\\"meta\\":{\\"audit_source_type\\":\\"Backend\\",\\"browser_page_resolution\\":\\"800x600\\",\\"cookies_enabled\\":true,\\"ip\\":\\"127.0.0.1\\",\\"js_enabled\\":true,\\"language\\":\\"ENG\\",\\"user_agent\\":\\"_userAgent_\\"},\\"mobile\\":\\"+16234401486\\"}",
129
129
  "headers": Object {
130
130
  "Accept": "application/json, text/plain, */*",
131
131
  "Content-Type": "application/json",
@@ -1,12 +1,14 @@
1
1
  import {AccountTracker} from "../src";
2
- import {registrationSuccessEvents} from "./testunits/accountTracker/events";
2
+ import {accountTrackerInitPropsNormal} from "./testunits/accountTracker/general";
3
+ import {emailVerifyEvents, phoneVerifyEvents, registrationSuccessEvents} from "./testunits/accountTracker/events";
3
4
 
5
+ const mockGtag = jest.fn().mockImplementation();
4
6
  const mockLintrk = jest.fn().mockImplementation();
5
-
6
7
  const accountTrackerInitProps = {
8
+ ...accountTrackerInitPropsNormal,
9
+ gtag: mockGtag,
7
10
  lintrk: mockLintrk,
8
11
  };
9
-
10
12
  const accountTracker = new AccountTracker(accountTrackerInitProps);
11
13
 
12
14
  describe('AccountTracker', () => {
@@ -14,9 +16,35 @@ describe('AccountTracker', () => {
14
16
  jest.clearAllMocks();
15
17
  });
16
18
 
19
+ test('sendPhoneVerifyEvent', () => {
20
+ accountTracker.sendPhoneVerifyEvent();
21
+
22
+ expect(mockGtag.mock.calls[0][1]).toBe(phoneVerifyEvents.ga4.action);
23
+ expect(mockGtag.mock.calls[0][2]).toEqual(phoneVerifyEvents.ga4.event);
24
+ expect(mockGtag).toHaveBeenCalled();
25
+
26
+ expect(mockLintrk.mock.calls[0][0]).toBe(phoneVerifyEvents.linkedIn.action);
27
+ expect(mockLintrk.mock.calls[0][1]).toEqual(phoneVerifyEvents.linkedIn.event);
28
+ expect(mockLintrk).toHaveBeenCalled();
29
+ });
30
+
31
+ test('sendEmailVerifyEvent', () => {
32
+ accountTracker.sendEmailVerifyEvent();
33
+
34
+ expect(mockGtag.mock.calls[0][1]).toBe(emailVerifyEvents.ga4.action);
35
+ expect(mockGtag.mock.calls[0][2]).toEqual(emailVerifyEvents.ga4.event);
36
+ expect(mockGtag).toHaveBeenCalled();
37
+
38
+ expect(mockLintrk.mock.calls[0][0]).toBe(emailVerifyEvents.linkedIn.action);
39
+ expect(mockLintrk.mock.calls[0][1]).toEqual(emailVerifyEvents.linkedIn.event);
40
+ expect(mockLintrk).toHaveBeenCalled();
41
+ });
42
+
17
43
  test('sendRegistrationSuccessEvent', () => {
18
44
  accountTracker.sendRegistrationSuccessEvent();
19
45
 
46
+ expect(mockGtag).not.toHaveBeenCalled();
47
+
20
48
  expect(mockLintrk.mock.calls[0][0]).toBe(registrationSuccessEvents.linkedIn.action);
21
49
  expect(mockLintrk.mock.calls[0][1]).toEqual(registrationSuccessEvents.linkedIn.event);
22
50
  expect(mockLintrk).toHaveBeenCalled();
@@ -1,3 +1,39 @@
1
+ import {accountTrackerInitPropsNormal} from "./general";
2
+
3
+ const phoneVerifyEvents = {
4
+ ga4: {
5
+ action: 'verify_contact',
6
+ event: {
7
+ contact: 'phone',
8
+ origin: accountTrackerInitPropsNormal.origin,
9
+ send_to: accountTrackerInitPropsNormal.ga4Id,
10
+ },
11
+ },
12
+ linkedIn: {
13
+ action: 'track',
14
+ event: {
15
+ conversation_id: 8612332,
16
+ },
17
+ },
18
+ };
19
+
20
+ const emailVerifyEvents = {
21
+ ga4: {
22
+ action: 'verify_contact',
23
+ event: {
24
+ contact: 'email',
25
+ origin: accountTrackerInitPropsNormal.origin,
26
+ send_to: accountTrackerInitPropsNormal.ga4Id,
27
+ },
28
+ },
29
+ linkedIn: {
30
+ action: 'track',
31
+ event: {
32
+ conversation_id: 8612340,
33
+ },
34
+ },
35
+ };
36
+
1
37
  const registrationSuccessEvents = {
2
38
  linkedIn: {
3
39
  action: 'track',
@@ -8,5 +44,7 @@ const registrationSuccessEvents = {
8
44
  };
9
45
 
10
46
  export {
47
+ phoneVerifyEvents,
48
+ emailVerifyEvents,
11
49
  registrationSuccessEvents,
12
50
  };
@@ -0,0 +1,8 @@
1
+ const accountTrackerInitPropsNormal = {
2
+ origin: '_origin_',
3
+ ga4Id: '_ga4Id_',
4
+ };
5
+
6
+ export {
7
+ accountTrackerInitPropsNormal,
8
+ };
@@ -18,6 +18,7 @@ const communicatorTestData = {
18
18
  challenge: 'email_otp' as TChallenge,
19
19
  companyName: '_companyName_',
20
20
  deviceType: 'mobile' as TRegistrationRequestBodySourceDeviceType,
21
+ deviceId: 'ov4lNmyk7armoC5DMiOpL5hl846kVQgS',
21
22
  otpCode: '123456',
22
23
  countryCode: 'CAN',
23
24
  authToken: '_authToken_',
@@ -14,6 +14,7 @@ import {communicatorTestData} from "./general";
14
14
  import {CountryTypeEnum} from "../../../src/enums";
15
15
 
16
16
  const signInData: TSignInByMobileRequestData = {
17
+ deviceId: communicatorTestData.deviceId,
17
18
  phoneNumber: communicatorTestData.phoneNumber,
18
19
  browserData: communicatorTestData.browserData,
19
20
  };