@maxzima/wa-communicator 0.0.17 → 1.0.3
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/README.md +92 -43
- package/dist/engine/AccountTracker/Enums/AccountTrackerEnum.d.ts +15 -0
- package/dist/engine/AccountTracker/Enums/AccountTrackerEnum.js +1 -0
- package/dist/engine/AccountTracker/Public/AccountTracker.d.ts +9 -0
- package/dist/engine/AccountTracker/Public/AccountTracker.js +35 -0
- package/dist/engine/AccountTracker/Types/TAccountTracker.d.ts +15 -0
- package/dist/engine/AccountTracker/Types/TAccountTracker.js +1 -0
- package/dist/engine/AccountTracker/index.d.ts +1 -0
- package/dist/engine/AccountTracker/index.js +1 -0
- package/dist/engine/Communicator/Constants/Communicator.d.ts +2 -0
- package/dist/engine/Communicator/Constants/Communicator.js +10 -0
- package/dist/engine/Communicator/Enums/CommunicatorEnum.d.ts +12 -0
- package/dist/engine/Communicator/Enums/CommunicatorEnum.js +1 -0
- package/dist/engine/Communicator/Public/Communicator.d.ts +16 -0
- package/dist/engine/Communicator/Public/Communicator.js +158 -0
- package/dist/engine/Communicator/Types/TCommunicator.d.ts +10 -0
- package/dist/engine/Communicator/Types/TCommunicator.js +1 -0
- package/dist/engine/Communicator/index.d.ts +1 -0
- package/dist/engine/Communicator/index.js +1 -0
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.js +2 -0
- package/dist/enums/CommunicatorErrorEnum.d.ts +15 -0
- package/dist/enums/CommunicatorErrorEnum.js +1 -0
- package/dist/enums/index.d.ts +1 -0
- package/dist/enums/index.js +1 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.js +1 -6
- package/dist/types/TCommunicator.d.ts +110 -0
- package/dist/types/TCommunicator.js +1 -0
- package/dist/types/index.d.ts +1 -60
- package/dist/types/index.js +1 -1
- package/package.json +19 -26
- package/src/engine/AccountTracker/Enums/AccountTrackerEnum.ts +18 -0
- package/src/engine/AccountTracker/Public/AccountTracker.ts +45 -0
- package/src/engine/AccountTracker/Types/TAccountTracker.ts +16 -0
- package/src/engine/AccountTracker/index.ts +1 -0
- package/src/engine/Communicator/Constants/Communicator.ts +14 -0
- package/src/engine/Communicator/Enums/CommunicatorEnum.ts +13 -0
- package/src/engine/Communicator/Public/Communicator.ts +195 -0
- package/src/engine/Communicator/Types/TCommunicator.ts +11 -0
- package/src/engine/Communicator/index.ts +1 -0
- package/src/engine/index.ts +2 -0
- package/src/enums/CommunicatorErrorEnum.ts +22 -0
- package/src/enums/index.ts +1 -0
- package/src/index.ts +18 -11
- package/src/types/TCommunicator.ts +179 -0
- package/src/types/index.ts +1 -73
- package/test/utiles.spec.ts +2 -66
- package/tsconfig.json +5 -0
- package/dist/engine/CommunicatorReceiver.d.ts +0 -14
- package/dist/engine/CommunicatorReceiver.js +0 -114
- package/dist/engine/CommunicatorSender.d.ts +0 -7
- package/dist/engine/CommunicatorSender.js +0 -20
- package/dist/engine/utils.d.ts +0 -5
- package/dist/engine/utils.js +0 -41
- package/dist/enums/CommunicatorActionEnum.d.ts +0 -11
- package/dist/enums/CommunicatorActionEnum.js +0 -16
- package/dist/enums/CommunicatorTargetEnum.d.ts +0 -5
- package/dist/enums/CommunicatorTargetEnum.js +0 -8
- package/dist/receiver.d.ts +0 -6
- package/dist/receiver.js +0 -6
- package/dist/sender.d.ts +0 -5
- package/dist/sender.js +0 -5
- package/src/engine/CommunicatorReceiver.ts +0 -182
- package/src/engine/CommunicatorSender.ts +0 -34
- package/src/engine/utils.ts +0 -53
- package/src/enums/CommunicatorActionEnum.ts +0 -17
- package/src/enums/CommunicatorTargetEnum.ts +0 -8
- package/src/receiver.ts +0 -13
- package/src/sender.ts +0 -11
- package/test/testUnits/message.ts +0 -44
- package/test/testUnits/queue.ts +0 -165
- package/test/testUnits/scenario.ts +0 -31
package/README.md
CHANGED
|
@@ -3,70 +3,119 @@
|
|
|
3
3
|
Import all
|
|
4
4
|
```javascript
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
Communicator,
|
|
7
|
+
AccountTracker,
|
|
8
|
+
CommunicatorUpdateChallengeCustomErrorCodeEnum,
|
|
9
|
+
CommunicatorVerifyChallengeCustomErrorCodeEnum,
|
|
10
|
+
CommunicatorEmailCustomErrorCodeEnum,
|
|
11
|
+
TChallenge,
|
|
12
|
+
TCreateSessionResponse,
|
|
13
|
+
TResponse,
|
|
14
|
+
TSetupChallengeResponse,
|
|
15
|
+
TSignInByMobileResponse,
|
|
16
|
+
TVerifyChallengeResponse,
|
|
17
|
+
TGetCurrentUserProfileResponseUser
|
|
18
|
+
} from "@maxzima/wa-communicator/dist";
|
|
11
19
|
```
|
|
12
20
|
|
|
13
|
-
Import only
|
|
21
|
+
Import only Communicator
|
|
14
22
|
```javascript
|
|
15
23
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
Communicator,
|
|
25
|
+
CommunicatorUpdateChallengeCustomErrorCodeEnum,
|
|
26
|
+
CommunicatorVerifyChallengeCustomErrorCodeEnum,
|
|
27
|
+
CommunicatorEmailCustomErrorCodeEnum,
|
|
28
|
+
TChallenge,
|
|
29
|
+
TCreateSessionResponse,
|
|
30
|
+
TResponse,
|
|
31
|
+
TSetupChallengeResponse,
|
|
32
|
+
TSignInByMobileResponse,
|
|
33
|
+
TVerifyChallengeResponse,
|
|
34
|
+
TGetCurrentUserProfileResponseUser
|
|
35
|
+
} from '@maxzima/wa-communicator/dist';
|
|
20
36
|
```
|
|
21
37
|
|
|
22
|
-
Import only
|
|
38
|
+
Import only AccountTracker
|
|
23
39
|
```javascript
|
|
24
40
|
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
CommunicatorActionEnum,
|
|
28
|
-
} from '@maxzima/wa-communicator';
|
|
41
|
+
AccountTracker,
|
|
42
|
+
} from '@maxzima/wa-communicator/dist';
|
|
29
43
|
```
|
|
30
44
|
|
|
31
45
|
# Usage Sender
|
|
32
46
|
|
|
33
47
|
```javascript
|
|
34
|
-
const communicator = new
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
const communicator = new Communicator({
|
|
49
|
+
clientAuthApiBaseUrl: 'https://api-auth.google.com/v1/',
|
|
50
|
+
clientFAPIBaseUrl: 'https://api-frontend.google.com/v1/',
|
|
37
51
|
});
|
|
38
52
|
|
|
39
|
-
communicator.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
communicator.signIn({
|
|
54
|
+
phoneNumber: '+18004397566',
|
|
55
|
+
})
|
|
56
|
+
.then((response) => callback(response));
|
|
57
|
+
|
|
58
|
+
communicator.setupChallenge({
|
|
59
|
+
type: 'email_otp',
|
|
60
|
+
authToken: 'some_auth_token...',
|
|
61
|
+
})
|
|
62
|
+
.then((response) => callback(response));
|
|
63
|
+
|
|
64
|
+
communicator.verifyChallenge({
|
|
65
|
+
type: 'email_otp',
|
|
66
|
+
code: '123456',
|
|
67
|
+
authToken: 'some_auth_token...',
|
|
68
|
+
})
|
|
69
|
+
.then((response) => callback(response));
|
|
70
|
+
|
|
71
|
+
communicator.emailUpdate({
|
|
72
|
+
email: 'exampleEmail.gmail.com',
|
|
73
|
+
authToken: 'some_auth_token...',
|
|
74
|
+
})
|
|
75
|
+
.then((response) => callback(response));
|
|
76
|
+
|
|
77
|
+
communicator.createSession({
|
|
78
|
+
authToken: 'some_auth_token...',
|
|
79
|
+
})
|
|
80
|
+
.then((response) => callback(response));
|
|
81
|
+
|
|
82
|
+
communicator.signUp({
|
|
83
|
+
locale: 'en',
|
|
84
|
+
phoneNumber: '+18004397566',
|
|
85
|
+
timezoneName: 'Asia/Qatar',
|
|
86
|
+
})
|
|
87
|
+
.then((response) => callback(response));
|
|
88
|
+
|
|
89
|
+
communicator.registration({
|
|
90
|
+
authToken: 'some_auth_token...',
|
|
91
|
+
name: 'companyName',
|
|
92
|
+
hash: 'some_tracking_hash...',
|
|
93
|
+
deviceType: 'mobile',
|
|
94
|
+
gaId: 'gaId_cookie_value',
|
|
95
|
+
origin: 'business',
|
|
96
|
+
})
|
|
97
|
+
.then((response) => callback(response));
|
|
98
|
+
|
|
99
|
+
communicator.getCurrentUserProfile()
|
|
100
|
+
.then((response) => callback(response))
|
|
49
101
|
```
|
|
50
102
|
|
|
51
|
-
# Usage
|
|
103
|
+
# Usage AccountTracker
|
|
52
104
|
|
|
53
105
|
```javascript
|
|
54
|
-
const
|
|
55
|
-
|
|
106
|
+
const tracker = new AccountTracker({
|
|
107
|
+
origin: 'business',
|
|
108
|
+
gtag: window.gtag, // gtag script width ga4_id
|
|
109
|
+
lintrk: window.lintrk, // lintrk script with _linkedin_partner_id
|
|
110
|
+
ga4Id:'some_ga4_id',
|
|
56
111
|
});
|
|
57
112
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
target: CommunicatorTargetEnum.SIGN_UP,
|
|
61
|
-
action: CommunicatorActionEnum.CLOSE,
|
|
62
|
-
callback: message => {
|
|
63
|
-
console.log('close', message);
|
|
64
|
-
},
|
|
65
|
-
});
|
|
113
|
+
/* tracking after sending phone number */
|
|
114
|
+
tracker.sendPhoneVerifyEvent();
|
|
66
115
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
action: CommunicatorActionEnum.CLOSE
|
|
70
|
-
});
|
|
116
|
+
/* tracking after email verification */
|
|
117
|
+
tracker.sendEmailVerifyEvent();
|
|
71
118
|
|
|
119
|
+
/* tracking after registration */
|
|
120
|
+
tracker.sendRegistrationSuccessEvent();
|
|
72
121
|
```
|
|
@@ -0,0 +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
|
+
}
|
|
8
|
+
declare const enum LintrkActionTypeEnum {
|
|
9
|
+
TRACK = "track"
|
|
10
|
+
}
|
|
11
|
+
declare const enum LintrkEventIdEnum {
|
|
12
|
+
PHONE = 8612332,
|
|
13
|
+
EMAIL = 8612340,
|
|
14
|
+
REGISTRATION = 8612308
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class AccountTracker {
|
|
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
|
+
};
|
|
14
|
+
this.sendLinkedInEvent = (id) => {
|
|
15
|
+
if (typeof this.props.lintrk === 'undefined') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
this.props.lintrk("track", {
|
|
19
|
+
conversation_id: id,
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
this.props = props;
|
|
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
|
+
}
|
|
32
|
+
sendRegistrationSuccessEvent() {
|
|
33
|
+
this.sendLinkedInEvent(8612308);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="gtag.js" />
|
|
2
|
+
declare type TLintrkOptions = {
|
|
3
|
+
conversation_id: LintrkEventIdEnum;
|
|
4
|
+
};
|
|
5
|
+
declare type TGA4Event = {
|
|
6
|
+
contact: GA4EventContactEnum;
|
|
7
|
+
send_to: TAccountTrackerProps['ga4Id'];
|
|
8
|
+
origin?: TAccountTrackerProps['origin'];
|
|
9
|
+
};
|
|
10
|
+
declare type TAccountTrackerProps = {
|
|
11
|
+
origin?: string;
|
|
12
|
+
gtag?: Gtag.Gtag;
|
|
13
|
+
lintrk?: (action: LintrkActionTypeEnum, options: TLintrkOptions) => void;
|
|
14
|
+
ga4Id?: string;
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Public/AccountTracker';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Public/AccountTracker';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const CommunicatorDefaultRequestData = {
|
|
2
|
+
IP: '127.0.0.1',
|
|
3
|
+
LANG: 'ENG',
|
|
4
|
+
AUDIT_SOURCE_TYPE: 'Backend',
|
|
5
|
+
FETCH_HEADERS_INIT: {
|
|
6
|
+
'Content-Type': 'application/json',
|
|
7
|
+
'Accept': 'application/json, text/plain, */*',
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
export { CommunicatorDefaultRequestData, };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare const enum CommunicatorFAPIEndpointEnum {
|
|
2
|
+
GEO_BY_IP = "geo-by-ip",
|
|
3
|
+
USER = "user",
|
|
4
|
+
REGISTRATION = "clients/registration"
|
|
5
|
+
}
|
|
6
|
+
declare const enum CommunicatorAuthAPIEndpointEnum {
|
|
7
|
+
SIGN_IN = "sign-in",
|
|
8
|
+
CHALLENGE = "sign-in/challenge",
|
|
9
|
+
EMAIL = "sign-in/email",
|
|
10
|
+
SIGN_UP = "sign-up",
|
|
11
|
+
SESSION = "sign-in/session"
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TCreateSessionRequestData, TEmailUpdateRequestData, TRegistrationRequestData, TResponse, TSetupChallengeRequestData, TSignInByMobileRequestData, TSignUpByMobileRequestData, TVerifyChallengeRequestData } from "@root/types";
|
|
2
|
+
export declare class Communicator {
|
|
3
|
+
private props;
|
|
4
|
+
constructor(props: TCommunicatorProps);
|
|
5
|
+
signIn(data: TSignInByMobileRequestData): Promise<TResponse>;
|
|
6
|
+
signUp(data: TSignUpByMobileRequestData): Promise<TResponse>;
|
|
7
|
+
setupChallenge(data: TSetupChallengeRequestData): Promise<TResponse>;
|
|
8
|
+
verifyChallenge(data: TVerifyChallengeRequestData): Promise<TResponse>;
|
|
9
|
+
emailUpdate(data: TEmailUpdateRequestData): Promise<TResponse>;
|
|
10
|
+
createSession(data: TCreateSessionRequestData): Promise<TResponse>;
|
|
11
|
+
getCurrentUserProfile(): Promise<TResponse>;
|
|
12
|
+
registration(data: TRegistrationRequestData): Promise<TResponse>;
|
|
13
|
+
private send;
|
|
14
|
+
private getMeta;
|
|
15
|
+
private processingQueryParams;
|
|
16
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { CommunicatorDefaultRequestData } from "./../Constants/Communicator";
|
|
3
|
+
export class Communicator {
|
|
4
|
+
constructor(props) {
|
|
5
|
+
this.getMeta = () => {
|
|
6
|
+
return {
|
|
7
|
+
audit_source_type: CommunicatorDefaultRequestData.AUDIT_SOURCE_TYPE,
|
|
8
|
+
browser_page_resolution: `${window.innerWidth}x${window.innerHeight}`,
|
|
9
|
+
cookies_enabled: window.navigator.cookieEnabled,
|
|
10
|
+
ip: CommunicatorDefaultRequestData.IP,
|
|
11
|
+
js_enabled: true,
|
|
12
|
+
language: CommunicatorDefaultRequestData.LANG,
|
|
13
|
+
user_agent: window.navigator.userAgent,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
this.processingQueryParams = (queryParams) => {
|
|
17
|
+
let queryParamsString = '';
|
|
18
|
+
const queryParamsList = Object.entries(queryParams);
|
|
19
|
+
queryParamsList.forEach((queryParam, index) => {
|
|
20
|
+
let separator = '';
|
|
21
|
+
if (index > 0) {
|
|
22
|
+
separator = '&';
|
|
23
|
+
}
|
|
24
|
+
queryParamsString = `${queryParamsString}${separator}${queryParam[0]}=${queryParam[1]}`;
|
|
25
|
+
});
|
|
26
|
+
return queryParamsString;
|
|
27
|
+
};
|
|
28
|
+
this.props = props;
|
|
29
|
+
}
|
|
30
|
+
signIn(data) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const meta = this.getMeta();
|
|
33
|
+
const body = JSON.stringify({
|
|
34
|
+
captcha_response: '_',
|
|
35
|
+
meta,
|
|
36
|
+
mobile: data.phoneNumber,
|
|
37
|
+
});
|
|
38
|
+
return yield this.send({
|
|
39
|
+
method: 'POST',
|
|
40
|
+
url: `${this.props.clientAuthApiBaseUrl}${"sign-in"}`,
|
|
41
|
+
body,
|
|
42
|
+
headers: CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
signUp(data) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const body = JSON.stringify({
|
|
49
|
+
locale: data.locale,
|
|
50
|
+
mobile: data.phoneNumber,
|
|
51
|
+
timezone_name: data.timezoneName,
|
|
52
|
+
});
|
|
53
|
+
return yield this.send({
|
|
54
|
+
method: 'POST',
|
|
55
|
+
url: `${this.props.clientAuthApiBaseUrl}${"sign-up"}`,
|
|
56
|
+
body,
|
|
57
|
+
headers: CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
setupChallenge(data) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
return yield this.send({
|
|
64
|
+
method: 'GET',
|
|
65
|
+
url: `${this.props.clientAuthApiBaseUrl}${"sign-in/challenge"}`,
|
|
66
|
+
headers: Object.assign({ 'Authorization': `Bearer ${data.authToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
|
|
67
|
+
queryParams: {
|
|
68
|
+
type: data.type,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
verifyChallenge(data) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const body = JSON.stringify({
|
|
76
|
+
type: data.type,
|
|
77
|
+
value: data.code,
|
|
78
|
+
});
|
|
79
|
+
return yield this.send({
|
|
80
|
+
method: 'POST',
|
|
81
|
+
url: `${this.props.clientAuthApiBaseUrl}${"sign-in/challenge"}`,
|
|
82
|
+
headers: Object.assign({ 'Authorization': `Bearer ${data.authToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
|
|
83
|
+
body,
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
emailUpdate(data) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
const body = JSON.stringify({
|
|
90
|
+
email: data.email,
|
|
91
|
+
});
|
|
92
|
+
return yield this.send({
|
|
93
|
+
method: 'PATCH',
|
|
94
|
+
url: `${this.props.clientAuthApiBaseUrl}${"sign-in/email"}`,
|
|
95
|
+
headers: Object.assign({ 'Authorization': `Bearer ${data.authToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
|
|
96
|
+
body,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
createSession(data) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
return yield this.send({
|
|
103
|
+
method: 'POST',
|
|
104
|
+
url: `${this.props.clientAuthApiBaseUrl}${"sign-in/session"}`,
|
|
105
|
+
headers: Object.assign({ 'Authorization': `Bearer ${data.authToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
getCurrentUserProfile() {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return yield this.send({
|
|
112
|
+
method: 'GET',
|
|
113
|
+
url: `${this.props.clientFAPIBaseUrl}${"user"}`,
|
|
114
|
+
headers: CommunicatorDefaultRequestData.FETCH_HEADERS_INIT,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
registration(data) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const body = JSON.stringify({
|
|
121
|
+
name: data.name,
|
|
122
|
+
source: {
|
|
123
|
+
hash: data.hash,
|
|
124
|
+
device_type: data.deviceType,
|
|
125
|
+
ga_id: data.gaId,
|
|
126
|
+
origin: data.origin,
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return yield this.send({
|
|
130
|
+
method: 'POST',
|
|
131
|
+
url: `${this.props.clientAuthApiBaseUrl}${"clients/registration"}`,
|
|
132
|
+
headers: Object.assign({ 'Authorization': `Bearer ${data.authToken}` }, CommunicatorDefaultRequestData.FETCH_HEADERS_INIT),
|
|
133
|
+
body,
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
send(requestInitProps) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
let url = requestInitProps.url;
|
|
140
|
+
if (requestInitProps.queryParams) {
|
|
141
|
+
url = `${url}?${this.processingQueryParams(requestInitProps.queryParams)}`;
|
|
142
|
+
}
|
|
143
|
+
return yield fetch(new URL(url), {
|
|
144
|
+
method: requestInitProps.method,
|
|
145
|
+
body: requestInitProps.body,
|
|
146
|
+
headers: requestInitProps.headers,
|
|
147
|
+
})
|
|
148
|
+
.then((response) => {
|
|
149
|
+
return new Promise((resolve) => response.json()
|
|
150
|
+
.then((json) => resolve({
|
|
151
|
+
status: response.status,
|
|
152
|
+
ok: response.ok,
|
|
153
|
+
json,
|
|
154
|
+
})));
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare type TDefaultRequestData = {
|
|
2
|
+
IP: string;
|
|
3
|
+
LANG: string;
|
|
4
|
+
FETCH_HEADERS_INIT: HeadersInit;
|
|
5
|
+
AUDIT_SOURCE_TYPE: import('@root/types').TAuditSource;
|
|
6
|
+
};
|
|
7
|
+
declare type TCommunicatorProps = {
|
|
8
|
+
clientAuthApiBaseUrl: string;
|
|
9
|
+
clientFAPIBaseUrl: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Public/Communicator';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Public/Communicator';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const enum CommunicatorUpdateChallengeCustomErrorCodeEnum {
|
|
2
|
+
INVALID_AUTH_HEADER = 90793,
|
|
3
|
+
FREQUENT_REQUESTS = 90449,
|
|
4
|
+
REQUESTS_EXCEEDED = 90696,
|
|
5
|
+
MISSING_EMAIL = 90174,
|
|
6
|
+
UNEXPECTED_CHALLENGE_TYPE = 90767
|
|
7
|
+
}
|
|
8
|
+
declare const enum CommunicatorVerifyChallengeCustomErrorCodeEnum {
|
|
9
|
+
SESSION_EXPIRED = 90302
|
|
10
|
+
}
|
|
11
|
+
declare const enum CommunicatorEmailCustomErrorCodeEnum {
|
|
12
|
+
UNKNOWN_ERROR = 91044,
|
|
13
|
+
UNPROCESSABLE_ENTITY = 90768
|
|
14
|
+
}
|
|
15
|
+
export { CommunicatorUpdateChallengeCustomErrorCodeEnum, CommunicatorVerifyChallengeCustomErrorCodeEnum, CommunicatorEmailCustomErrorCodeEnum, };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./CommunicatorErrorEnum";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./CommunicatorErrorEnum";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { CommunicatorActionEnum } from "./enums/CommunicatorActionEnum";
|
|
5
|
-
import * as types from "./types";
|
|
6
|
-
export { CommunicatorReceiver, CommunicatorSender, CommunicatorTargetEnum, CommunicatorActionEnum, types, };
|
|
1
|
+
export { Communicator, AccountTracker } from "./engine";
|
|
2
|
+
export { CommunicatorUpdateChallengeCustomErrorCodeEnum, CommunicatorVerifyChallengeCustomErrorCodeEnum, CommunicatorEmailCustomErrorCodeEnum, } from "./enums";
|
|
3
|
+
export { TChallenge, TResponse, TSignInByMobileResponse, TSetupChallengeResponse, TVerifyChallengeResponse, TCreateSessionResponse, TGetCurrentUserProfileResponseUser, } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { CommunicatorSender } from "./engine/CommunicatorSender";
|
|
3
|
-
import { CommunicatorTargetEnum } from "./enums/CommunicatorTargetEnum";
|
|
4
|
-
import { CommunicatorActionEnum } from "./enums/CommunicatorActionEnum";
|
|
5
|
-
import * as types from "./types";
|
|
6
|
-
export { CommunicatorReceiver, CommunicatorSender, CommunicatorTargetEnum, CommunicatorActionEnum, types, };
|
|
1
|
+
export { Communicator, AccountTracker } from "./engine";
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
declare type TChallenge = 'email_otp' | 'mobile_otp' | 'pin';
|
|
2
|
+
declare type TAuditSource = 'Backend' | 'SelfService';
|
|
3
|
+
declare type TRegistrationRequestBodySourceDeviceType = 'mobile' | 'regular';
|
|
4
|
+
declare type TRequestProps = {
|
|
5
|
+
url?: string;
|
|
6
|
+
method?: RequestInit['method'];
|
|
7
|
+
body?: any;
|
|
8
|
+
headers?: HeadersInit;
|
|
9
|
+
mode?: RequestMode;
|
|
10
|
+
queryParams?: TRequestQueryParams;
|
|
11
|
+
};
|
|
12
|
+
declare type TRequestQueryParams = {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
};
|
|
15
|
+
declare type TResponse = {
|
|
16
|
+
json: any;
|
|
17
|
+
status: number;
|
|
18
|
+
ok: boolean;
|
|
19
|
+
};
|
|
20
|
+
declare type TSignInStartRequestBody = {
|
|
21
|
+
captcha_response?: string;
|
|
22
|
+
meta: TAccountMeta;
|
|
23
|
+
mobile?: string;
|
|
24
|
+
};
|
|
25
|
+
declare type TAccountMeta = {
|
|
26
|
+
audit_source_type: TAuditSource;
|
|
27
|
+
browser_page_resolution: string;
|
|
28
|
+
cookies_enabled: boolean;
|
|
29
|
+
ip: string;
|
|
30
|
+
js_enabled: boolean;
|
|
31
|
+
language: string;
|
|
32
|
+
user_agent: string;
|
|
33
|
+
};
|
|
34
|
+
declare type TSignInByMobileRequestData = {
|
|
35
|
+
phoneNumber: string;
|
|
36
|
+
};
|
|
37
|
+
declare type TSignInByMobileResponse = {
|
|
38
|
+
auth_token: string;
|
|
39
|
+
challenges: TChallenge[];
|
|
40
|
+
};
|
|
41
|
+
declare type TSignUpStartRequestBody = {
|
|
42
|
+
locale: string;
|
|
43
|
+
mobile: string;
|
|
44
|
+
timezone_name: string;
|
|
45
|
+
};
|
|
46
|
+
declare type TSignUpByMobileRequestData = {
|
|
47
|
+
locale: string;
|
|
48
|
+
phoneNumber: string;
|
|
49
|
+
timezoneName: string;
|
|
50
|
+
};
|
|
51
|
+
declare type TSetupChallengeRequestData = {
|
|
52
|
+
type: TChallenge;
|
|
53
|
+
authToken: string;
|
|
54
|
+
};
|
|
55
|
+
declare type TSetupChallengeResponse = {
|
|
56
|
+
attempts_left: number;
|
|
57
|
+
masked_email: string;
|
|
58
|
+
masked_mobile: string;
|
|
59
|
+
next_attempt_after: number;
|
|
60
|
+
};
|
|
61
|
+
declare type TVerifyChallengeRequestBody = {
|
|
62
|
+
type: TChallenge;
|
|
63
|
+
value: string;
|
|
64
|
+
};
|
|
65
|
+
declare type TVerifyChallengeRequestData = {
|
|
66
|
+
authToken: string;
|
|
67
|
+
type: TChallenge;
|
|
68
|
+
code: string;
|
|
69
|
+
};
|
|
70
|
+
declare type TVerifyChallengeResponse = {
|
|
71
|
+
auth_token: string;
|
|
72
|
+
challenges: TChallenge[];
|
|
73
|
+
};
|
|
74
|
+
declare type TEmailUpdateRequestData = {
|
|
75
|
+
authToken: string;
|
|
76
|
+
email: string;
|
|
77
|
+
};
|
|
78
|
+
declare type TCreateSessionRequestData = {
|
|
79
|
+
authToken: string;
|
|
80
|
+
};
|
|
81
|
+
declare type TCreateSessionResponse = {
|
|
82
|
+
access_token: string;
|
|
83
|
+
refresh_token: string;
|
|
84
|
+
};
|
|
85
|
+
declare type TGetCurrentUserProfileResponseUser = {
|
|
86
|
+
profiles: (TGetCurrentUserProfileResponseUserProfiles & Record<string, unknown>)[];
|
|
87
|
+
};
|
|
88
|
+
declare type TGetCurrentUserProfileResponseUserProfiles = {
|
|
89
|
+
target_entity_name: string;
|
|
90
|
+
target_entity_id: string;
|
|
91
|
+
};
|
|
92
|
+
declare type TRegistrationRequestBodySource = {
|
|
93
|
+
hash: string;
|
|
94
|
+
device_type: TRegistrationRequestBodySourceDeviceType;
|
|
95
|
+
ga_id: string;
|
|
96
|
+
origin: string;
|
|
97
|
+
};
|
|
98
|
+
declare type TRegistrationRequestBody = {
|
|
99
|
+
name: string;
|
|
100
|
+
source: TRegistrationRequestBodySource;
|
|
101
|
+
};
|
|
102
|
+
declare type TRegistrationRequestData = {
|
|
103
|
+
authToken: string;
|
|
104
|
+
name: TRegistrationRequestBody['name'];
|
|
105
|
+
deviceType: TRegistrationRequestBodySource['device_type'];
|
|
106
|
+
hash: TRegistrationRequestBodySource['hash'];
|
|
107
|
+
gaId: TRegistrationRequestBodySource['ga_id'];
|
|
108
|
+
origin: TRegistrationRequestBodySource['origin'];
|
|
109
|
+
};
|
|
110
|
+
export { TChallenge, TAuditSource, TRequestProps, TRequestQueryParams, TResponse, TSignInStartRequestBody, TAccountMeta, TSignInByMobileRequestData, TSignInByMobileResponse, TSignUpStartRequestBody, TSignUpByMobileRequestData, TSetupChallengeRequestData, TSetupChallengeResponse, TVerifyChallengeRequestBody, TVerifyChallengeRequestData, TVerifyChallengeResponse, TEmailUpdateRequestData, TCreateSessionRequestData, TCreateSessionResponse, TGetCurrentUserProfileResponseUser, TRegistrationRequestData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|