@peacom/core 0.0.85 → 0.0.87
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/.eslintrc.json +18 -0
- package/data/Chuyen-de-1.pdf +63386 -304
- package/data/report_bulk_campaign_Kplus_1665394311017.xlsx +0 -0
- package/jest.config.ts +16 -0
- package/package.json +9 -10
- package/project.json +41 -0
- package/src/index.ts +5 -0
- package/src/lib/api/api.constant.ts +82 -0
- package/src/lib/api/core.api.ts +86 -0
- package/src/lib/api/index.ts +4 -0
- package/src/lib/api/micro-service.api.ts +35 -0
- package/src/lib/api/micro-service.spec.ts +29 -0
- package/src/lib/api/queue/queue.api.ts +39 -0
- package/src/lib/core.spec.ts +7 -0
- package/src/lib/core.ts +3 -0
- package/src/lib/error/FormError.ts +64 -0
- package/src/lib/error/HttpError.ts +9 -0
- package/src/lib/model/Application.ts +63 -0
- package/src/lib/model/BackgroundTask.ts +5 -0
- package/src/lib/model/Billing.ts +11 -0
- package/src/lib/model/Currency.ts +5 -0
- package/src/lib/model/FileInfo.ts +9 -0
- package/src/lib/model/conversation/constant.ts +34 -0
- package/src/lib/model/conversation/index.ts +1 -0
- package/src/lib/model/index.ts +11 -0
- package/src/lib/model/message/Message.ts +159 -0
- package/src/lib/model/message/TemplateMessage.ts +4 -0
- package/src/lib/model/message/index.ts +4 -0
- package/src/lib/model/message/sinch/SinchWhatsappTemplate.ts +27 -0
- package/src/lib/model/message/zalo/ZaloZNSTemplate.ts +26 -0
- package/src/lib/model/partner/PartnerEvent.ts +24 -0
- package/src/lib/model/partner/index.ts +6 -0
- package/src/lib/model/queue/QueueMessage.ts +31 -0
- package/src/lib/model/queue/index.ts +2 -0
- package/src/lib/model/queue/queue.constant.ts +6 -0
- package/src/lib/model/template/Template.ts +86 -0
- package/src/lib/model/template/index.ts +1 -0
- package/src/lib/model/viber-business/constant.ts +4 -0
- package/src/lib/model/viber-business/index.ts +1 -0
- package/src/lib/service/index.ts +1 -0
- package/src/lib/service/storage/aws/constants.ts +22 -0
- package/src/lib/service/storage/aws/index.ts +2 -0
- package/src/lib/service/storage/aws/s3.service.ts +128 -0
- package/src/lib/service/storage/aws/s3.spec.ts +12 -0
- package/src/lib/service/storage/index.ts +1 -0
- package/src/lib/util/date/constant.ts +3 -0
- package/src/lib/util/date/date.spec.ts +22 -0
- package/src/lib/util/date/date.util.ts +64 -0
- package/src/lib/util/date/index.ts +2 -0
- package/src/lib/util/file/file.spec.ts +40 -0
- package/src/lib/util/file/file.util.ts +60 -0
- package/src/lib/util/general.util.ts +3 -0
- package/src/lib/util/index.ts +6 -0
- package/src/lib/util/message/message.util.ts +118 -0
- package/src/lib/util/phone.spec.ts +48 -0
- package/src/lib/util/phone.util.ts +51 -0
- package/src/lib/util/string.spec.ts +15 -0
- package/src/lib/util/string.util.ts +118 -0
- package/tsconfig.json +22 -0
- package/tsconfig.lib.json +10 -0
- package/tsconfig.spec.json +14 -0
- package/src/index.d.ts +0 -4
- package/src/index.js +0 -8
- package/src/index.js.map +0 -1
- package/src/lib/api/api.constant.d.ts +0 -58
- package/src/lib/api/api.constant.js +0 -20
- package/src/lib/api/api.constant.js.map +0 -1
- package/src/lib/api/core.api.d.ts +0 -9
- package/src/lib/api/core.api.js +0 -78
- package/src/lib/api/core.api.js.map +0 -1
- package/src/lib/api/index.d.ts +0 -4
- package/src/lib/api/index.js +0 -8
- package/src/lib/api/index.js.map +0 -1
- package/src/lib/api/micro-service.api.d.ts +0 -2
- package/src/lib/api/micro-service.api.js +0 -38
- package/src/lib/api/micro-service.api.js.map +0 -1
- package/src/lib/api/queue/queue.api.d.ts +0 -7
- package/src/lib/api/queue/queue.api.js +0 -37
- package/src/lib/api/queue/queue.api.js.map +0 -1
- package/src/lib/core.d.ts +0 -1
- package/src/lib/core.js +0 -8
- package/src/lib/core.js.map +0 -1
- package/src/lib/error/FormError.d.ts +0 -53
- package/src/lib/error/FormError.js +0 -58
- package/src/lib/error/FormError.js.map +0 -1
- package/src/lib/error/HttpError.d.ts +0 -4
- package/src/lib/error/HttpError.js +0 -12
- package/src/lib/error/HttpError.js.map +0 -1
- package/src/lib/model/Application.d.ts +0 -52
- package/src/lib/model/Application.js +0 -59
- package/src/lib/model/Application.js.map +0 -1
- package/src/lib/model/Billing.d.ts +0 -10
- package/src/lib/model/Billing.js +0 -16
- package/src/lib/model/Billing.js.map +0 -1
- package/src/lib/model/Currency.d.ts +0 -4
- package/src/lib/model/Currency.js +0 -9
- package/src/lib/model/Currency.js.map +0 -1
- package/src/lib/model/FileInfo.d.ts +0 -9
- package/src/lib/model/FileInfo.js +0 -3
- package/src/lib/model/FileInfo.js.map +0 -1
- package/src/lib/model/conversation/constant.d.ts +0 -25
- package/src/lib/model/conversation/constant.js +0 -25
- package/src/lib/model/conversation/constant.js.map +0 -1
- package/src/lib/model/conversation/index.d.ts +0 -1
- package/src/lib/model/conversation/index.js +0 -5
- package/src/lib/model/conversation/index.js.map +0 -1
- package/src/lib/model/index.d.ts +0 -10
- package/src/lib/model/index.js +0 -14
- package/src/lib/model/index.js.map +0 -1
- package/src/lib/model/message/Message.d.ts +0 -129
- package/src/lib/model/message/Message.js +0 -88
- package/src/lib/model/message/Message.js.map +0 -1
- package/src/lib/model/message/TemplateMessage.d.ts +0 -4
- package/src/lib/model/message/TemplateMessage.js +0 -9
- package/src/lib/model/message/TemplateMessage.js.map +0 -1
- package/src/lib/model/message/index.d.ts +0 -4
- package/src/lib/model/message/index.js +0 -8
- package/src/lib/model/message/index.js.map +0 -1
- package/src/lib/model/message/sinch/SinchWhatsappTemplate.d.ts +0 -22
- package/src/lib/model/message/sinch/SinchWhatsappTemplate.js +0 -14
- package/src/lib/model/message/sinch/SinchWhatsappTemplate.js.map +0 -1
- package/src/lib/model/message/zalo/ZaloZNSTemplate.d.ts +0 -23
- package/src/lib/model/message/zalo/ZaloZNSTemplate.js +0 -3
- package/src/lib/model/message/zalo/ZaloZNSTemplate.js.map +0 -1
- package/src/lib/model/partner/PartnerEvent.d.ts +0 -22
- package/src/lib/model/partner/PartnerEvent.js +0 -3
- package/src/lib/model/partner/PartnerEvent.js.map +0 -1
- package/src/lib/model/partner/index.d.ts +0 -5
- package/src/lib/model/partner/index.js +0 -11
- package/src/lib/model/partner/index.js.map +0 -1
- package/src/lib/model/queue/QueueMessage.d.ts +0 -28
- package/src/lib/model/queue/QueueMessage.js +0 -9
- package/src/lib/model/queue/QueueMessage.js.map +0 -1
- package/src/lib/model/queue/index.d.ts +0 -2
- package/src/lib/model/queue/index.js +0 -6
- package/src/lib/model/queue/index.js.map +0 -1
- package/src/lib/model/queue/queue.constant.d.ts +0 -6
- package/src/lib/model/queue/queue.constant.js +0 -11
- package/src/lib/model/queue/queue.constant.js.map +0 -1
- package/src/lib/model/template/Template.d.ts +0 -43
- package/src/lib/model/template/Template.js +0 -89
- package/src/lib/model/template/Template.js.map +0 -1
- package/src/lib/model/template/index.d.ts +0 -1
- package/src/lib/model/template/index.js +0 -5
- package/src/lib/model/template/index.js.map +0 -1
- package/src/lib/model/viber-business/constant.d.ts +0 -4
- package/src/lib/model/viber-business/constant.js +0 -9
- package/src/lib/model/viber-business/constant.js.map +0 -1
- package/src/lib/model/viber-business/index.d.ts +0 -1
- package/src/lib/model/viber-business/index.js +0 -5
- package/src/lib/model/viber-business/index.js.map +0 -1
- package/src/lib/util/date/constant.d.ts +0 -3
- package/src/lib/util/date/constant.js +0 -7
- package/src/lib/util/date/constant.js.map +0 -1
- package/src/lib/util/date/date.util.d.ts +0 -19
- package/src/lib/util/date/date.util.js +0 -59
- package/src/lib/util/date/date.util.js.map +0 -1
- package/src/lib/util/date/index.d.ts +0 -2
- package/src/lib/util/date/index.js +0 -6
- package/src/lib/util/date/index.js.map +0 -1
- package/src/lib/util/file/file.util.d.ts +0 -5
- package/src/lib/util/file/file.util.js +0 -35
- package/src/lib/util/file/file.util.js.map +0 -1
- package/src/lib/util/general.util.d.ts +0 -1
- package/src/lib/util/general.util.js +0 -8
- package/src/lib/util/general.util.js.map +0 -1
- package/src/lib/util/index.d.ts +0 -6
- package/src/lib/util/index.js +0 -10
- package/src/lib/util/index.js.map +0 -1
- package/src/lib/util/message/message.util.d.ts +0 -90
- package/src/lib/util/message/message.util.js +0 -72
- package/src/lib/util/message/message.util.js.map +0 -1
- package/src/lib/util/phone.util.d.ts +0 -24
- package/src/lib/util/phone.util.js +0 -51
- package/src/lib/util/phone.util.js.map +0 -1
- package/src/lib/util/string.util.d.ts +0 -14
- package/src/lib/util/string.util.js +0 -118
- package/src/lib/util/string.util.js.map +0 -1
@@ -0,0 +1,40 @@
|
|
1
|
+
import {getFileInfoFromLocalFile, getFileInfoFromUrl} from "./file.util";
|
2
|
+
import * as path from "path";
|
3
|
+
|
4
|
+
describe('file.util', () => {
|
5
|
+
it('getFileInfoFromUrl', () => {
|
6
|
+
const rs = getFileInfoFromUrl('https://pngimg.com/uploads/birds/birds_PNG9.png')
|
7
|
+
expect(rs).toEqual({
|
8
|
+
name: 'birds_PNG9.png', type: 'image/png', extension: 'png'
|
9
|
+
});
|
10
|
+
});
|
11
|
+
it('getFileInfoFromUrlWithText', () => {
|
12
|
+
const rs = getFileInfoFromUrl('https://testing message')
|
13
|
+
console.log(rs)
|
14
|
+
expect(rs).toEqual({
|
15
|
+
name: 'birds_PNG9.png', type: 'image/png', extension: 'png'
|
16
|
+
});
|
17
|
+
});
|
18
|
+
it('getFileInfoFromLocal', () => {
|
19
|
+
const localFile = path.resolve('./data/Chuyen-de-1.pdf');
|
20
|
+
console.log(localFile)
|
21
|
+
const rs = getFileInfoFromLocalFile(localFile)
|
22
|
+
expect(rs).toEqual({
|
23
|
+
name: 'Chuyen-de-1.pdf',
|
24
|
+
type: 'application/pdf',
|
25
|
+
extension: '.pdf',
|
26
|
+
url: '/Users/lecanh/Documents/Project/Vietnam/Peacom/peacom/packages/core/data/Chuyen-de-1.pdf',
|
27
|
+
size: 17004899
|
28
|
+
})
|
29
|
+
console.log(rs)
|
30
|
+
});
|
31
|
+
it('getFileInfoFromLocalWrongFile', () => {
|
32
|
+
try {
|
33
|
+
const localFile = path.resolve('./data/Chuyen-de-2.pdf');
|
34
|
+
console.log(localFile)
|
35
|
+
getFileInfoFromLocalFile(localFile)
|
36
|
+
} catch (e: any) {
|
37
|
+
expect(e.code).toEqual('ENOENT')
|
38
|
+
}
|
39
|
+
});
|
40
|
+
});
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import {FileInfo} from "../../model/";
|
2
|
+
import * as path from "path";
|
3
|
+
import * as fs from "fs";
|
4
|
+
import mime = require("mime-types");
|
5
|
+
|
6
|
+
export const isImage = (mimetype: string) => {
|
7
|
+
const regex = /(^image)(\/)[a-zA-Z0-9_]*/gm
|
8
|
+
return regex.test(mimetype)
|
9
|
+
}
|
10
|
+
|
11
|
+
export const isVideo = (mimetype: string) => {
|
12
|
+
const regex = /(^video)(\/)[a-zA-Z0-9_]*/gm
|
13
|
+
return regex.test(mimetype)
|
14
|
+
}
|
15
|
+
|
16
|
+
export const isAudio = (mimetype: string) => {
|
17
|
+
const regex = /(^audio)(\/)[a-zA-Z0-9_]*/gm
|
18
|
+
return regex.test(mimetype)
|
19
|
+
}
|
20
|
+
|
21
|
+
export const getFileInfoFromUrl = (
|
22
|
+
url: string,
|
23
|
+
defaultMimeType = "application/binary"
|
24
|
+
): FileInfo => {
|
25
|
+
const rs = {
|
26
|
+
name: "",
|
27
|
+
type: defaultMimeType,
|
28
|
+
extension: "",
|
29
|
+
url
|
30
|
+
} as FileInfo;
|
31
|
+
|
32
|
+
rs.name = new URL(url).pathname.split("/").pop() || url;
|
33
|
+
rs.extension = rs.name.split(".").pop();
|
34
|
+
if (rs.extension) {
|
35
|
+
rs.type = mime.lookup(rs.extension) || defaultMimeType;
|
36
|
+
}
|
37
|
+
|
38
|
+
return rs;
|
39
|
+
};
|
40
|
+
|
41
|
+
export const getFileInfoFromLocalFile = (
|
42
|
+
filePath: string,
|
43
|
+
): FileInfo => {
|
44
|
+
const rs = {
|
45
|
+
name: "",
|
46
|
+
type: '',
|
47
|
+
extension: "",
|
48
|
+
url: filePath
|
49
|
+
} as FileInfo;
|
50
|
+
|
51
|
+
const stat = fs.statSync(filePath)
|
52
|
+
rs.name = path.basename(filePath)
|
53
|
+
rs.extension = path.extname(filePath);
|
54
|
+
rs.size = stat.size
|
55
|
+
if (rs.extension) {
|
56
|
+
rs.type = mime.lookup(rs.extension) || "application/binary";
|
57
|
+
}
|
58
|
+
|
59
|
+
return rs;
|
60
|
+
};
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import {ContactMessage, FileInfo, Message, MESSAGE_TYPE, RawMessage, RawMessageSuggestion} from "../../model";
|
2
|
+
|
3
|
+
interface ImageMessage {
|
4
|
+
imageUrl: string,
|
5
|
+
fileName?: string,
|
6
|
+
fileSize?: number,
|
7
|
+
message?: string
|
8
|
+
}
|
9
|
+
|
10
|
+
interface VideoMessage {
|
11
|
+
fileUrl: string,
|
12
|
+
thumbnailUrl?: string,
|
13
|
+
duration?: number,
|
14
|
+
message?: string
|
15
|
+
}
|
16
|
+
|
17
|
+
interface TextMessage {
|
18
|
+
attachments?: Array<FileInfo>,
|
19
|
+
message: string,
|
20
|
+
suggestions?: Array<RawMessageSuggestion>
|
21
|
+
}
|
22
|
+
|
23
|
+
interface Location {
|
24
|
+
longitude: number
|
25
|
+
latitude: number
|
26
|
+
}
|
27
|
+
|
28
|
+
interface LocationMessage {
|
29
|
+
location: Location,
|
30
|
+
message?: string
|
31
|
+
}
|
32
|
+
|
33
|
+
export const buildLocationMessage = (
|
34
|
+
{location, message = ""}: LocationMessage,
|
35
|
+
extra = null
|
36
|
+
) => ({
|
37
|
+
type: MESSAGE_TYPE.LOCATION,
|
38
|
+
message,
|
39
|
+
location,
|
40
|
+
extra
|
41
|
+
});
|
42
|
+
|
43
|
+
interface FileMessage {
|
44
|
+
fileUrl: string,
|
45
|
+
fileName: string,
|
46
|
+
fileSize?: number
|
47
|
+
message?: string
|
48
|
+
}
|
49
|
+
|
50
|
+
export const buildFileMessage = (
|
51
|
+
{message = "", fileUrl, fileName = "", fileSize = 0}: FileMessage,
|
52
|
+
extra = null
|
53
|
+
) => ({
|
54
|
+
type: MESSAGE_TYPE.FILE,
|
55
|
+
message,
|
56
|
+
fileName,
|
57
|
+
fileUrl,
|
58
|
+
fileSize,
|
59
|
+
extra
|
60
|
+
});
|
61
|
+
|
62
|
+
interface RichCardMessage {
|
63
|
+
richCards: Array<unknown>,
|
64
|
+
}
|
65
|
+
|
66
|
+
export const buildTextMessage = ({message, attachments, suggestions}: TextMessage, extra = null) => ({
|
67
|
+
type: MESSAGE_TYPE.TEXT,
|
68
|
+
message,
|
69
|
+
suggestions,
|
70
|
+
attachments,
|
71
|
+
extra
|
72
|
+
});
|
73
|
+
|
74
|
+
export const buildRichCardMessage = ({richCards}: RichCardMessage, extra = null) => ({
|
75
|
+
message: "",
|
76
|
+
type: MESSAGE_TYPE.RICH_CARD,
|
77
|
+
richCards,
|
78
|
+
extra
|
79
|
+
});
|
80
|
+
|
81
|
+
export const buildTypingIndicatorStartMessage = (extra = null) => ({
|
82
|
+
message: "",
|
83
|
+
type: MESSAGE_TYPE.TYPING_INDICATOR_START,
|
84
|
+
extra
|
85
|
+
});
|
86
|
+
|
87
|
+
export const buildTypingIndicatorStopMessage = (extra = null) => ({
|
88
|
+
message: "",
|
89
|
+
type: MESSAGE_TYPE.TYPING_INDICATOR_STOP,
|
90
|
+
extra
|
91
|
+
});
|
92
|
+
|
93
|
+
export const buildImageMessage = ({imageUrl, fileName = "", fileSize, message = ""}: ImageMessage, extra = null) => ({
|
94
|
+
type: MESSAGE_TYPE.PICTURE,
|
95
|
+
fileName: fileName,
|
96
|
+
fileSize: fileSize,
|
97
|
+
fileUrl: imageUrl,
|
98
|
+
message: message,
|
99
|
+
extra
|
100
|
+
});
|
101
|
+
|
102
|
+
export const buildVideoMessage = (
|
103
|
+
{fileUrl, duration, thumbnailUrl, message = ""}: VideoMessage,
|
104
|
+
extra = null
|
105
|
+
) => ({
|
106
|
+
type: MESSAGE_TYPE.VIDEO,
|
107
|
+
duration,
|
108
|
+
fileUrl,
|
109
|
+
thumbnailUrl,
|
110
|
+
message,
|
111
|
+
extra
|
112
|
+
});
|
113
|
+
|
114
|
+
export const buildContactMessage = (contactMessages: Array<ContactMessage>, extra = null): RawMessage => ({
|
115
|
+
type: MESSAGE_TYPE.SHARE_INFO,
|
116
|
+
contacts: contactMessages,
|
117
|
+
extra
|
118
|
+
});
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import {isPhoneValid} from "./phone.util";
|
2
|
+
|
3
|
+
describe('phone.util', () => {
|
4
|
+
it('isValidPhone', () => {
|
5
|
+
const phoneStr = '0938130683'
|
6
|
+
const phone1 = '212649080802'
|
7
|
+
console.log(isPhoneValid(phoneStr))
|
8
|
+
expect(isPhoneValid(phoneStr)).toEqual({
|
9
|
+
countryCode: 84,
|
10
|
+
nationalNumber: '0938130683',
|
11
|
+
e164: '84938130683',
|
12
|
+
network: 0
|
13
|
+
})
|
14
|
+
expect(isPhoneValid(phone1)).toEqual({
|
15
|
+
countryCode: 212,
|
16
|
+
nationalNumber: '0649080802',
|
17
|
+
e164: '212649080802',
|
18
|
+
network: 0
|
19
|
+
})
|
20
|
+
});
|
21
|
+
it('isValidPhoneRegion', () => {
|
22
|
+
const canada = '+1-416-750-9999'
|
23
|
+
const us = '0014067509999'
|
24
|
+
const vn = '0938130683'
|
25
|
+
console.log(isPhoneValid(vn))
|
26
|
+
expect(isPhoneValid('0938130683')).toEqual({
|
27
|
+
countryCode: 84,
|
28
|
+
nationalNumber: '0938130683',
|
29
|
+
e164: '84938130683',
|
30
|
+
network: 0,
|
31
|
+
region: 'VN'
|
32
|
+
})
|
33
|
+
expect(isPhoneValid(us)).toEqual({
|
34
|
+
countryCode: 1,
|
35
|
+
nationalNumber: '04067509999',
|
36
|
+
e164: '14067509999',
|
37
|
+
network: 0,
|
38
|
+
region: 'US'
|
39
|
+
})
|
40
|
+
expect(isPhoneValid(canada)).toEqual({
|
41
|
+
countryCode: 1,
|
42
|
+
nationalNumber: '04167509999',
|
43
|
+
e164: '14167509999',
|
44
|
+
network: 0,
|
45
|
+
region: 'CA'
|
46
|
+
})
|
47
|
+
});
|
48
|
+
});
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import {PhoneNumberUtil} from "google-libphonenumber";
|
2
|
+
import {hasText} from "./";
|
3
|
+
|
4
|
+
const phoneUtil = PhoneNumberUtil.getInstance();
|
5
|
+
|
6
|
+
export const DEFAULT_PHONE_COUNTRY = "VN";
|
7
|
+
|
8
|
+
export const PHONE_COUNTRY_SUPPORT = {
|
9
|
+
84: {
|
10
|
+
countries: [{
|
11
|
+
ios2: "VN"
|
12
|
+
}]
|
13
|
+
},
|
14
|
+
1: {
|
15
|
+
countries: [
|
16
|
+
{
|
17
|
+
iso2: "US",
|
18
|
+
regions: [""]
|
19
|
+
}, {
|
20
|
+
iso2: "CA"
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
export function isPhoneValid(phone: string, country = DEFAULT_PHONE_COUNTRY) {
|
27
|
+
if (!phone || !hasText(phone)) {
|
28
|
+
throw new Error(`Invalid phone ${phone}`);
|
29
|
+
}
|
30
|
+
let _phone = phone;
|
31
|
+
const phone2Prefix = phone.substring(0, 2);
|
32
|
+
if (phone2Prefix !== "00") {
|
33
|
+
const phone1Prefix = phone[0];
|
34
|
+
if (phone1Prefix !== "0") {
|
35
|
+
_phone = `+${phone}`;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
const number = phoneUtil.parse(_phone, country);
|
39
|
+
const existPhone = phoneUtil.isValidNumber(number);
|
40
|
+
if (!existPhone) {
|
41
|
+
throw new Error(`Invalid phone ${phone}`);
|
42
|
+
}
|
43
|
+
|
44
|
+
return {
|
45
|
+
countryCode: number.getCountryCode(),
|
46
|
+
nationalNumber: `0${number.getNationalNumber()}`,
|
47
|
+
e164: `${number.getCountryCode()}${number.getNationalNumber()}`,
|
48
|
+
network: number.preferredDomesticCarrierCodeCount(),
|
49
|
+
region: phoneUtil.getRegionCodeForNumber(number)
|
50
|
+
};
|
51
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import {isNumberOnly, leftString} from "./";
|
2
|
+
|
3
|
+
describe('string.util', () => {
|
4
|
+
it('isNumber', () => {
|
5
|
+
const dateStr = '2022'
|
6
|
+
expect(isNumberOnly(dateStr)).toBeTruthy();
|
7
|
+
const notOnlyNumber = '2022a'
|
8
|
+
expect(isNumberOnly(notOnlyNumber)).toBeFalsy();
|
9
|
+
});
|
10
|
+
it('leftString', () => {
|
11
|
+
const dateStr = '2022'
|
12
|
+
expect(leftString(dateStr, 5)).toHaveLength(4);
|
13
|
+
expect(leftString(dateStr, 2)).toStrictEqual("20")
|
14
|
+
});
|
15
|
+
});
|
@@ -0,0 +1,118 @@
|
|
1
|
+
export function generateRandomCode(length: number) {
|
2
|
+
let text = "";
|
3
|
+
const possible =
|
4
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
5
|
+
|
6
|
+
for (let i = 0; i < length; i += 1)
|
7
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
8
|
+
|
9
|
+
return text;
|
10
|
+
}
|
11
|
+
|
12
|
+
export const hasText = (str: string) => {
|
13
|
+
const testStr = `${str || ""}`;
|
14
|
+
return !!str && testStr.length > 0;
|
15
|
+
};
|
16
|
+
|
17
|
+
export function markKey(keyStr: string) {
|
18
|
+
return `**** ${keyStr.substring(keyStr.length - 4, keyStr.length)}`;
|
19
|
+
}
|
20
|
+
|
21
|
+
const htmlEntities: Record<string, string> = {
|
22
|
+
nbsp: " ",
|
23
|
+
cent: "¢",
|
24
|
+
pound: "£",
|
25
|
+
yen: "¥",
|
26
|
+
euro: "€",
|
27
|
+
copy: "©",
|
28
|
+
reg: "®",
|
29
|
+
lt: "<",
|
30
|
+
gt: ">",
|
31
|
+
quot: '"',
|
32
|
+
amp: "&",
|
33
|
+
apos: "'"
|
34
|
+
};
|
35
|
+
|
36
|
+
export function unescapeHTML(str: string) {
|
37
|
+
return str.replace(/&([^;]+);/g, (entity, entityCode: string) => {
|
38
|
+
let match;
|
39
|
+
|
40
|
+
if (entityCode in htmlEntities) {
|
41
|
+
return htmlEntities[entityCode];
|
42
|
+
}
|
43
|
+
// eslint-disable-next-line no-cond-assign
|
44
|
+
if ((match = entityCode.match(/^#x([\da-fA-F]+)$/))) {
|
45
|
+
return String.fromCharCode(parseInt(match[1], 16));
|
46
|
+
}
|
47
|
+
// eslint-disable-next-line no-cond-assign
|
48
|
+
if ((match = entityCode.match(/^#(\d+)$/))) {
|
49
|
+
// eslint-disable-next-line no-bitwise
|
50
|
+
return String.fromCharCode(~~match[1]);
|
51
|
+
}
|
52
|
+
return entity;
|
53
|
+
});
|
54
|
+
}
|
55
|
+
|
56
|
+
export const filterForNumberOnly = (str: string) => str.replace(/\D+/g, "");
|
57
|
+
|
58
|
+
export function isNumberOnly(str: string) {
|
59
|
+
const pattern = /^\d+$/;
|
60
|
+
return pattern.test(str);
|
61
|
+
}
|
62
|
+
|
63
|
+
export function filterForInvalidCharacter(str: string, replaceCharacter = "_") {
|
64
|
+
let rs = str.replace(/[^\p{L}\s]/giu, " ");
|
65
|
+
rs = rs.trim();
|
66
|
+
rs = rs.replace(/ +/g, replaceCharacter);
|
67
|
+
return rs;
|
68
|
+
}
|
69
|
+
|
70
|
+
export function filterNotNumberAndDivideChar(str: string) {
|
71
|
+
let rs = str.replace(/\D+/g, " ");
|
72
|
+
rs = rs.trim();
|
73
|
+
rs = rs.replace(/ +/g, ",");
|
74
|
+
return rs;
|
75
|
+
}
|
76
|
+
|
77
|
+
export function stringNumberToList(str: string) {
|
78
|
+
return filterNotNumberAndDivideChar(str)
|
79
|
+
.split(/[ _\-,]/)
|
80
|
+
.filter((t) => hasText(t))
|
81
|
+
.map((t) => Number(t));
|
82
|
+
}
|
83
|
+
|
84
|
+
export function htmlEncode(rawStr: string) {
|
85
|
+
return rawStr.replace(/[\u00A0-\u9999<>&]/g, (i) => {
|
86
|
+
return `&#${i.charCodeAt(0)};`;
|
87
|
+
});
|
88
|
+
}
|
89
|
+
|
90
|
+
export function filterNonAlphaNumeric(str: string) {
|
91
|
+
return str.replace(/\W/g, "");
|
92
|
+
}
|
93
|
+
|
94
|
+
export const leftString = (string: string, count: number) => {
|
95
|
+
const str = `${string || ""}`;
|
96
|
+
if (str.length > count) {
|
97
|
+
return str.substring(0, count);
|
98
|
+
}
|
99
|
+
return str;
|
100
|
+
};
|
101
|
+
|
102
|
+
export const rightString = (string: string, count: number) => {
|
103
|
+
const str = `${string || ""}`;
|
104
|
+
if (str.length > count) {
|
105
|
+
return str.substring(str.length - count);
|
106
|
+
}
|
107
|
+
return str;
|
108
|
+
};
|
109
|
+
|
110
|
+
export function alphaNumericToListString(str: string) {
|
111
|
+
if (!hasText(str)) {
|
112
|
+
return [];
|
113
|
+
}
|
114
|
+
return str
|
115
|
+
.split(/[ _\-,]/)
|
116
|
+
.map((t) => filterNonAlphaNumeric(t))
|
117
|
+
.filter((t) => hasText(t));
|
118
|
+
}
|
package/tsconfig.json
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"extends": "../../tsconfig.base.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"module": "commonjs",
|
5
|
+
"forceConsistentCasingInFileNames": true,
|
6
|
+
"strict": true,
|
7
|
+
"noImplicitOverride": true,
|
8
|
+
"noPropertyAccessFromIndexSignature": true,
|
9
|
+
"noImplicitReturns": true,
|
10
|
+
"noFallthroughCasesInSwitch": true
|
11
|
+
},
|
12
|
+
"files": [],
|
13
|
+
"include": [],
|
14
|
+
"references": [
|
15
|
+
{
|
16
|
+
"path": "./tsconfig.lib.json"
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"path": "./tsconfig.spec.json"
|
20
|
+
}
|
21
|
+
]
|
22
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"extends": "./tsconfig.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "../../dist/out-tsc",
|
5
|
+
"module": "commonjs",
|
6
|
+
"types": ["jest", "node"]
|
7
|
+
},
|
8
|
+
"include": [
|
9
|
+
"jest.config.ts",
|
10
|
+
"src/**/*.test.ts",
|
11
|
+
"src/**/*.spec.ts",
|
12
|
+
"src/**/*.d.ts"
|
13
|
+
]
|
14
|
+
}
|
package/src/index.d.ts
DELETED
package/src/index.js
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const tslib_1 = require("tslib");
|
4
|
-
tslib_1.__exportStar(require("./lib/core"), exports);
|
5
|
-
tslib_1.__exportStar(require("./lib/model"), exports);
|
6
|
-
tslib_1.__exportStar(require("./lib/util"), exports);
|
7
|
-
tslib_1.__exportStar(require("./lib/api"), exports);
|
8
|
-
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,sDAA4B;AAC5B,qDAA0B;AAC1B,oDAAyB"}
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import { Application, ApplicationInfo, Message, RawMessage, SEND_MESSAGE_VIA } from '../model/';
|
2
|
-
import { Conversation } from "../model";
|
3
|
-
interface Contact {
|
4
|
-
id: string;
|
5
|
-
name?: string;
|
6
|
-
phone?: string;
|
7
|
-
isSubscribed: boolean;
|
8
|
-
extraData: Record<string, unknown>;
|
9
|
-
avatarUrl?: string;
|
10
|
-
language: string;
|
11
|
-
country: string;
|
12
|
-
}
|
13
|
-
export interface ApiCoreHandleParams {
|
14
|
-
to: ApplicationInfo;
|
15
|
-
rawMessage: RawMessage;
|
16
|
-
replyToApplicationMessageId?: string;
|
17
|
-
sentTime: number;
|
18
|
-
extraData?: Record<string, unknown>;
|
19
|
-
applicationMessageId: string;
|
20
|
-
from: Contact;
|
21
|
-
conversation?: Conversation;
|
22
|
-
}
|
23
|
-
export interface ApiCoreLiveAgentParams {
|
24
|
-
to: ApplicationInfo;
|
25
|
-
sentTime: number;
|
26
|
-
extraData?: Record<string, unknown>;
|
27
|
-
applicationMessageId?: string;
|
28
|
-
from: Contact;
|
29
|
-
conversation?: Conversation;
|
30
|
-
}
|
31
|
-
export interface ApiCoreLiveAgentResponse {
|
32
|
-
conversation?: Conversation;
|
33
|
-
}
|
34
|
-
export interface ApiCoreHandleResponse {
|
35
|
-
receiverId: string;
|
36
|
-
messages: Array<Message>;
|
37
|
-
contact: unknown;
|
38
|
-
applicationInfo: ApplicationInfo;
|
39
|
-
conversation?: Conversation;
|
40
|
-
}
|
41
|
-
export interface ApiChannelMessageParams {
|
42
|
-
applicationInfo?: ApplicationInfo;
|
43
|
-
message: Message;
|
44
|
-
receiverId: string;
|
45
|
-
sendVia?: SEND_MESSAGE_VIA;
|
46
|
-
conversation?: Conversation;
|
47
|
-
queueOption?: Record<string, unknown>;
|
48
|
-
[key: string]: unknown;
|
49
|
-
}
|
50
|
-
export interface ApiChannelMessageResponse {
|
51
|
-
applicationMessageId: string;
|
52
|
-
extraData?: Record<string, unknown>;
|
53
|
-
[key: string]: unknown;
|
54
|
-
}
|
55
|
-
export declare type LOG_FUNCTION = ((t: unknown) => void) | null;
|
56
|
-
export declare const MICROSERVICE_URL: Record<Application, string>;
|
57
|
-
export declare const INTEGRATED_CHANNEL: Application[];
|
58
|
-
export {};
|
@@ -1,20 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.INTEGRATED_CHANNEL = exports.MICROSERVICE_URL = void 0;
|
4
|
-
const model_1 = require("../model/");
|
5
|
-
exports.MICROSERVICE_URL = {
|
6
|
-
[model_1.Application.APPLE]: process.env['APPLE_INTEGRATION'] || 'http://127.0.0.1:4005/eip/apple',
|
7
|
-
[model_1.Application.ZALO]: process.env['ZALO_INTEGRATION'] || 'http://127.0.0.1:4003/eip/zalo/bot',
|
8
|
-
[model_1.Application.ZALO_ZNS]: process.env['ZALO_ZNS_INTEGRATION'] || 'http://127.0.0.1:4003/eip/zalo/zns',
|
9
|
-
[model_1.Application.RCS]: process.env['RCS_INTEGRATION'] || 'http://127.0.0.1:4006',
|
10
|
-
[model_1.Application.VIBER]: process.env['VIBER_BOT_INTEGRATION'] || 'http://127.0.0.1:4001/eip/viber/bot',
|
11
|
-
[model_1.Application.VIBER_BUSINESS]: process.env['VIBER_BUSINESS_INTEGRATION'] || 'http://127.0.0.1:4001/eip/viber/business',
|
12
|
-
[model_1.Application.TELEGRAM]: process.env['TELEGRAM_INTEGRATION'] || 'http://127.0.0.1:4009',
|
13
|
-
[model_1.Application.FACEBOOK]: process.env['FACEBOOK_INTEGRATION'] || 'http://127.0.0.1:4010',
|
14
|
-
[model_1.Application.SMS]: process.env['SMS_INTEGRATION'] || 'http://127.0.0.1:4011',
|
15
|
-
[model_1.Application.VIBER_BOT]: process.env['VIBER_BOT_INTEGRATION'] || 'http://127.0.0.1:4001/eip/viber/bot',
|
16
|
-
[model_1.Application.WHATSAPP]: process.env['WHATSAPP_INTEGRATION'] || 'http://127.0.0.1:4008/eip/whatsapp',
|
17
|
-
[model_1.Application.GOOGLE_BUSINESS]: process.env['GOOGLE_BUSINESS_INTEGRATION'] || 'http://127.0.0.1:4006/eip/google/business',
|
18
|
-
};
|
19
|
-
exports.INTEGRATED_CHANNEL = [model_1.Application.APPLE, model_1.Application.ZALO, model_1.Application.ZALO_ZNS, model_1.Application.GOOGLE_BUSINESS];
|
20
|
-
//# sourceMappingURL=api.constant.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"api.constant.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/api/api.constant.ts"],"names":[],"mappings":";;;AAAA,qCAA8F;AAkEjF,QAAA,gBAAgB,GAAgC;IAC3D,CAAC,mBAAW,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,iCAAiC;IAC1F,CAAC,mBAAW,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,oCAAoC;IAC3F,CAAC,mBAAW,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,oCAAoC;IACnG,CAAC,mBAAW,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,uBAAuB;IAC5E,CAAC,mBAAW,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,qCAAqC;IAClG,CAAC,mBAAW,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,IAAI,0CAA0C;IACrH,CAAC,mBAAW,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,uBAAuB;IACtF,CAAC,mBAAW,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,uBAAuB;IACtF,CAAC,mBAAW,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,uBAAuB;IAC5E,CAAC,mBAAW,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,qCAAqC;IACtG,CAAC,mBAAW,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,oCAAoC;IACnG,CAAC,mBAAW,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,IAAI,2CAA2C;CACzH,CAAA;AAEY,QAAA,kBAAkB,GAAG,CAAC,mBAAW,CAAC,KAAK,EAAE,mBAAW,CAAC,IAAI,EAAE,mBAAW,CAAC,QAAQ,EAAE,mBAAW,CAAC,eAAe,CAAC,CAAA"}
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import { ApiCoreHandleParams, ApiCoreHandleResponse, ApiCoreLiveAgentParams, ApiCoreLiveAgentResponse, LOG_FUNCTION } from "./api.constant";
|
2
|
-
export declare enum CORE_API_PATH {
|
3
|
-
MESSAGE = "/message",
|
4
|
-
LIVE_AGENT = "/conversation/live-agent",
|
5
|
-
UNSUBSCRIBE = "/unsubscribe"
|
6
|
-
}
|
7
|
-
export declare const handleCoreMessage: (CORE_URL: string, params: ApiCoreHandleParams, log?: LOG_FUNCTION) => Promise<ApiCoreHandleResponse>;
|
8
|
-
export declare const handleCoreLiveAgent: (CORE_URL: string, params: ApiCoreLiveAgentParams, log?: LOG_FUNCTION) => Promise<ApiCoreLiveAgentResponse>;
|
9
|
-
export declare const handleUnsubscribe: (CORE_URL: string, params: ApiCoreLiveAgentParams, log?: LOG_FUNCTION) => Promise<ApiCoreLiveAgentResponse>;
|