rn-erxes-sdk 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Munkh-orgil
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # rn-erxes-sdk
2
+
3
+ React Native Erxes SDK
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install rn-erxes-sdk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import { multiply } from 'rn-erxes-sdk';
15
+
16
+ // ...
17
+
18
+ const result = await multiply(3, 7);
19
+ ```
20
+
21
+ ## Contributing
22
+
23
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
24
+
25
+ ## License
26
+
27
+ MIT
28
+
29
+ ---
30
+
31
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _reactNativeWebview = _interopRequireDefault(require("react-native-webview"));
9
+ var _reactNative = require("react-native");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ const ErxesSDK = _ref => {
12
+ let {
13
+ brandId,
14
+ src,
15
+ pollInterval
16
+ } = _ref;
17
+ const runFirst = `window.erxesSettings = { messenger: { brand_id: "${brandId}", pollInterval: ${pollInterval}, css: ".topbar-button.right { visibility: hidden;} .erxes-launcher { visibility: hidden; }"}, }; (function () { var script = document.createElement('script'); script.src = "${src}/build/messengerWidget.bundle.js"; script.async = true; var entry = document.getElementsByTagName('script')[0]; entry.parentNode.insertBefore(script, entry); })(); true;`;
18
+ const onMessage = data => {
19
+ const {
20
+ notificationCount
21
+ } = JSON.parse(data.nativeEvent.data);
22
+ console.log('****************** ', notificationCount);
23
+ };
24
+ return /*#__PURE__*/_react.default.createElement(_reactNativeWebview.default, {
25
+ source: _reactNative.Platform.OS === 'ios' ? require('./index.html') : {
26
+ uri: 'file:///android_asset/index.html'
27
+ },
28
+ originWhitelist: ['*'],
29
+ sharedCookiesEnabled: true,
30
+ cacheEnabled: true,
31
+ allowFileAccess: true,
32
+ domStorageEnabled: true,
33
+ thirdPartyCookiesEnabled: true
34
+ // allowingReadAccessToURL
35
+ // style={{ width: 200 }}
36
+ ,
37
+ onLoadEnd: syntheticEvent => {
38
+ // update component to be aware of loading status
39
+ const {
40
+ nativeEvent
41
+ } = syntheticEvent;
42
+ console.log(nativeEvent.loading);
43
+ },
44
+ javaScriptEnabled: true,
45
+ onError: er => {
46
+ console.log(er);
47
+ },
48
+ startInLoadingState: true
49
+ // renderLoading={() => <Loader />}
50
+ ,
51
+ injectedJavaScript: runFirst
52
+ // injectedJavaScriptBeforeContentLoaded={runFirst}
53
+
54
+ // onNavigationStateChange={this.handleWebViewNavigationStateChange}
55
+ ,
56
+ onMessage: onMessage
57
+ });
58
+ };
59
+ var _default = ErxesSDK;
60
+ exports.default = _default;
61
+ //# sourceMappingURL=App.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_reactNativeWebview","_reactNative","obj","__esModule","default","ErxesSDK","_ref","brandId","src","pollInterval","runFirst","onMessage","data","notificationCount","JSON","parse","nativeEvent","console","log","createElement","source","Platform","OS","uri","originWhitelist","sharedCookiesEnabled","cacheEnabled","allowFileAccess","domStorageEnabled","thirdPartyCookiesEnabled","onLoadEnd","syntheticEvent","loading","javaScriptEnabled","onError","er","startInLoadingState","injectedJavaScript","_default","exports"],"sourceRoot":"../../src","sources":["App.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAAwC,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAQxC,MAAMG,QAA6B,GAAGC,IAAA,IAAoC;EAAA,IAAnC;IAAEC,OAAO;IAAEC,GAAG;IAAEC;EAAa,CAAC,GAAAH,IAAA;EACnE,MAAMI,QAAQ,GAAI,oDAAmDH,OAAQ,oBAAmBE,YAAa,iLAAgLD,GAAI,2KAA0K;EAE3c,MAAMG,SAAS,GAAIC,IAAS,IAAK;IAC/B,MAAM;MAAEC;IAAkB,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACH,IAAI,CAACI,WAAW,CAACJ,IAAI,CAAC;IAE/DK,OAAO,CAACC,GAAG,CAAC,qBAAqB,EAAEL,iBAAiB,CAAC;EACvD,CAAC;EAED,oBACEhB,MAAA,CAAAO,OAAA,CAAAe,aAAA,CAACnB,mBAAA,CAAAI,OAAO;IACNgB,MAAM,EACJC,qBAAQ,CAACC,EAAE,KAAK,KAAK,GACjBvB,OAAO,CAAC,cAAc,CAAC,GACvB;MAAEwB,GAAG,EAAE;IAAmC,CAC/C;IACDC,eAAe,EAAE,CAAC,GAAG,CAAE;IACvBC,oBAAoB,EAAE,IAAK;IAC3BC,YAAY,EAAE,IAAK;IACnBC,eAAe,EAAE,IAAK;IACtBC,iBAAiB,EAAE,IAAK;IACxBC,wBAAwB,EAAE;IAC1B;IACA;IAAA;IACAC,SAAS,EAAGC,cAAc,IAAK;MAC7B;MACA,MAAM;QAAEf;MAAY,CAAC,GAAGe,cAAc;MACtCd,OAAO,CAACC,GAAG,CAACF,WAAW,CAACgB,OAAO,CAAC;IAClC,CAAE;IACFC,iBAAiB,EAAE,IAAK;IACxBC,OAAO,EAAGC,EAAE,IAAK;MACflB,OAAO,CAACC,GAAG,CAACiB,EAAE,CAAC;IACjB,CAAE;IACFC,mBAAmB,EAAE;IACrB;IAAA;IACAC,kBAAkB,EAAE3B;IACpB;;IAEA;IAAA;IACAC,SAAS,EAAEA;EAAU,CACtB,CAAC;AAEN,CAAC;AAAC,IAAA2B,QAAA,GAEajC,QAAQ;AAAAkC,OAAA,CAAAnC,OAAA,GAAAkC,QAAA"}
@@ -0,0 +1,114 @@
1
+ <html>
2
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
3
+ <meta charset="utf-8" />
4
+
5
+ <body id="mbody" onload="openMessenger()"></body>
6
+ <script>
7
+ function openMessenger() {
8
+ setTimeout(function () {
9
+ window.Erxes.showMessenger();
10
+ }, 1500);
11
+ }
12
+
13
+ window.addEventListener('message', (e) => {
14
+ const { data } = e;
15
+ const { notificationCount } = data;
16
+
17
+ if (notificationCount !== undefined) {
18
+ window.ReactNativeWebView.postMessage(JSON.stringify(data));
19
+ }
20
+ });
21
+ </script>
22
+
23
+ <style>
24
+ #mbody {
25
+ align-items: center;
26
+ justify-content: center;
27
+ background-color: rgb(189, 189, 188);
28
+ display: flex;
29
+ /* flex-direction: column; */
30
+ }
31
+
32
+ .topbar-button {
33
+ visibility: hidden;
34
+ }
35
+
36
+ .loader {
37
+ border: 5px solid #f3f3f3;
38
+ /* Light grey */
39
+ border-top: 5px solid #3498db;
40
+ /* Blue */
41
+ border-radius: 50%;
42
+ width: 50px;
43
+ height: 50px;
44
+ animation: spin 5s linear infinite;
45
+ }
46
+
47
+ @keyframes spin {
48
+ 0% {
49
+ transform: rotate(0deg);
50
+ }
51
+
52
+ 100% {
53
+ transform: rotate(360deg);
54
+ }
55
+ }
56
+
57
+ /* CSS */
58
+ .button-75 {
59
+ align-items: center;
60
+ background-image: linear-gradient(135deg, #f34079 40%, #fc894d);
61
+ border: 0;
62
+ border-radius: 10px;
63
+ box-sizing: border-box;
64
+ color: #fff;
65
+ cursor: pointer;
66
+ display: flex;
67
+ flex-direction: column;
68
+ /* font-family: "Codec cold", sans-serif; */
69
+ font-size: 16px;
70
+ font-weight: 700;
71
+ height: 54px;
72
+ justify-content: center;
73
+ letter-spacing: 0.4px;
74
+ line-height: 1;
75
+ max-width: 100%;
76
+ padding-left: 20px;
77
+ padding-right: 20px;
78
+ padding-top: 3px;
79
+ text-decoration: none;
80
+ text-transform: uppercase;
81
+ user-select: none;
82
+ -webkit-user-select: none;
83
+ touch-action: manipulation;
84
+ }
85
+
86
+ .button-75:active {
87
+ outline: 0;
88
+ }
89
+
90
+ .button-75:hover {
91
+ outline: 0;
92
+ }
93
+
94
+ .button-75 span {
95
+ transition: all 200ms;
96
+ }
97
+
98
+ .button-75:hover span {
99
+ transform: scale(0.9);
100
+ opacity: 0.75;
101
+ }
102
+
103
+ @media screen and (max-width: 991px) {
104
+ .button-75 {
105
+ font-size: 15px;
106
+ height: 50px;
107
+ }
108
+
109
+ .button-75 span {
110
+ line-height: 50px;
111
+ }
112
+ }
113
+ </style>
114
+ </html>
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _App = _interopRequireDefault(require("./App"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ var _default = _App.default;
10
+ exports.default = _default;
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_App","_interopRequireDefault","require","obj","__esModule","default","_default","ErxesSDK","exports"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA6B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAAAG,QAAA,GAEdC,YAAQ;AAAAC,OAAA,CAAAH,OAAA,GAAAC,QAAA"}
@@ -0,0 +1,53 @@
1
+ import React from 'react';
2
+ import WebView from 'react-native-webview';
3
+ import { Platform } from 'react-native';
4
+ const ErxesSDK = _ref => {
5
+ let {
6
+ brandId,
7
+ src,
8
+ pollInterval
9
+ } = _ref;
10
+ const runFirst = `window.erxesSettings = { messenger: { brand_id: "${brandId}", pollInterval: ${pollInterval}, css: ".topbar-button.right { visibility: hidden;} .erxes-launcher { visibility: hidden; }"}, }; (function () { var script = document.createElement('script'); script.src = "${src}/build/messengerWidget.bundle.js"; script.async = true; var entry = document.getElementsByTagName('script')[0]; entry.parentNode.insertBefore(script, entry); })(); true;`;
11
+ const onMessage = data => {
12
+ const {
13
+ notificationCount
14
+ } = JSON.parse(data.nativeEvent.data);
15
+ console.log('****************** ', notificationCount);
16
+ };
17
+ return /*#__PURE__*/React.createElement(WebView, {
18
+ source: Platform.OS === 'ios' ? require('./index.html') : {
19
+ uri: 'file:///android_asset/index.html'
20
+ },
21
+ originWhitelist: ['*'],
22
+ sharedCookiesEnabled: true,
23
+ cacheEnabled: true,
24
+ allowFileAccess: true,
25
+ domStorageEnabled: true,
26
+ thirdPartyCookiesEnabled: true
27
+ // allowingReadAccessToURL
28
+ // style={{ width: 200 }}
29
+ ,
30
+ onLoadEnd: syntheticEvent => {
31
+ // update component to be aware of loading status
32
+ const {
33
+ nativeEvent
34
+ } = syntheticEvent;
35
+ console.log(nativeEvent.loading);
36
+ },
37
+ javaScriptEnabled: true,
38
+ onError: er => {
39
+ console.log(er);
40
+ },
41
+ startInLoadingState: true
42
+ // renderLoading={() => <Loader />}
43
+ ,
44
+ injectedJavaScript: runFirst
45
+ // injectedJavaScriptBeforeContentLoaded={runFirst}
46
+
47
+ // onNavigationStateChange={this.handleWebViewNavigationStateChange}
48
+ ,
49
+ onMessage: onMessage
50
+ });
51
+ };
52
+ export default ErxesSDK;
53
+ //# sourceMappingURL=App.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","WebView","Platform","ErxesSDK","_ref","brandId","src","pollInterval","runFirst","onMessage","data","notificationCount","JSON","parse","nativeEvent","console","log","createElement","source","OS","require","uri","originWhitelist","sharedCookiesEnabled","cacheEnabled","allowFileAccess","domStorageEnabled","thirdPartyCookiesEnabled","onLoadEnd","syntheticEvent","loading","javaScriptEnabled","onError","er","startInLoadingState","injectedJavaScript"],"sourceRoot":"../../src","sources":["App.tsx"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,OAAO,MAAM,sBAAsB;AAC1C,SAASC,QAAQ,QAAQ,cAAc;AAQvC,MAAMC,QAA6B,GAAGC,IAAA,IAAoC;EAAA,IAAnC;IAAEC,OAAO;IAAEC,GAAG;IAAEC;EAAa,CAAC,GAAAH,IAAA;EACnE,MAAMI,QAAQ,GAAI,oDAAmDH,OAAQ,oBAAmBE,YAAa,iLAAgLD,GAAI,2KAA0K;EAE3c,MAAMG,SAAS,GAAIC,IAAS,IAAK;IAC/B,MAAM;MAAEC;IAAkB,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACH,IAAI,CAACI,WAAW,CAACJ,IAAI,CAAC;IAE/DK,OAAO,CAACC,GAAG,CAAC,qBAAqB,EAAEL,iBAAiB,CAAC;EACvD,CAAC;EAED,oBACEX,KAAA,CAAAiB,aAAA,CAAChB,OAAO;IACNiB,MAAM,EACJhB,QAAQ,CAACiB,EAAE,KAAK,KAAK,GACjBC,OAAO,CAAC,cAAc,CAAC,GACvB;MAAEC,GAAG,EAAE;IAAmC,CAC/C;IACDC,eAAe,EAAE,CAAC,GAAG,CAAE;IACvBC,oBAAoB,EAAE,IAAK;IAC3BC,YAAY,EAAE,IAAK;IACnBC,eAAe,EAAE,IAAK;IACtBC,iBAAiB,EAAE,IAAK;IACxBC,wBAAwB,EAAE;IAC1B;IACA;IAAA;IACAC,SAAS,EAAGC,cAAc,IAAK;MAC7B;MACA,MAAM;QAAEf;MAAY,CAAC,GAAGe,cAAc;MACtCd,OAAO,CAACC,GAAG,CAACF,WAAW,CAACgB,OAAO,CAAC;IAClC,CAAE;IACFC,iBAAiB,EAAE,IAAK;IACxBC,OAAO,EAAGC,EAAE,IAAK;MACflB,OAAO,CAACC,GAAG,CAACiB,EAAE,CAAC;IACjB,CAAE;IACFC,mBAAmB,EAAE;IACrB;IAAA;IACAC,kBAAkB,EAAE3B;IACpB;;IAEA;IAAA;IACAC,SAAS,EAAEA;EAAU,CACtB,CAAC;AAEN,CAAC;AAED,eAAeN,QAAQ"}
@@ -0,0 +1,114 @@
1
+ <html>
2
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
3
+ <meta charset="utf-8" />
4
+
5
+ <body id="mbody" onload="openMessenger()"></body>
6
+ <script>
7
+ function openMessenger() {
8
+ setTimeout(function () {
9
+ window.Erxes.showMessenger();
10
+ }, 1500);
11
+ }
12
+
13
+ window.addEventListener('message', (e) => {
14
+ const { data } = e;
15
+ const { notificationCount } = data;
16
+
17
+ if (notificationCount !== undefined) {
18
+ window.ReactNativeWebView.postMessage(JSON.stringify(data));
19
+ }
20
+ });
21
+ </script>
22
+
23
+ <style>
24
+ #mbody {
25
+ align-items: center;
26
+ justify-content: center;
27
+ background-color: rgb(189, 189, 188);
28
+ display: flex;
29
+ /* flex-direction: column; */
30
+ }
31
+
32
+ .topbar-button {
33
+ visibility: hidden;
34
+ }
35
+
36
+ .loader {
37
+ border: 5px solid #f3f3f3;
38
+ /* Light grey */
39
+ border-top: 5px solid #3498db;
40
+ /* Blue */
41
+ border-radius: 50%;
42
+ width: 50px;
43
+ height: 50px;
44
+ animation: spin 5s linear infinite;
45
+ }
46
+
47
+ @keyframes spin {
48
+ 0% {
49
+ transform: rotate(0deg);
50
+ }
51
+
52
+ 100% {
53
+ transform: rotate(360deg);
54
+ }
55
+ }
56
+
57
+ /* CSS */
58
+ .button-75 {
59
+ align-items: center;
60
+ background-image: linear-gradient(135deg, #f34079 40%, #fc894d);
61
+ border: 0;
62
+ border-radius: 10px;
63
+ box-sizing: border-box;
64
+ color: #fff;
65
+ cursor: pointer;
66
+ display: flex;
67
+ flex-direction: column;
68
+ /* font-family: "Codec cold", sans-serif; */
69
+ font-size: 16px;
70
+ font-weight: 700;
71
+ height: 54px;
72
+ justify-content: center;
73
+ letter-spacing: 0.4px;
74
+ line-height: 1;
75
+ max-width: 100%;
76
+ padding-left: 20px;
77
+ padding-right: 20px;
78
+ padding-top: 3px;
79
+ text-decoration: none;
80
+ text-transform: uppercase;
81
+ user-select: none;
82
+ -webkit-user-select: none;
83
+ touch-action: manipulation;
84
+ }
85
+
86
+ .button-75:active {
87
+ outline: 0;
88
+ }
89
+
90
+ .button-75:hover {
91
+ outline: 0;
92
+ }
93
+
94
+ .button-75 span {
95
+ transition: all 200ms;
96
+ }
97
+
98
+ .button-75:hover span {
99
+ transform: scale(0.9);
100
+ opacity: 0.75;
101
+ }
102
+
103
+ @media screen and (max-width: 991px) {
104
+ .button-75 {
105
+ font-size: 15px;
106
+ height: 50px;
107
+ }
108
+
109
+ .button-75 span {
110
+ line-height: 50px;
111
+ }
112
+ }
113
+ </style>
114
+ </html>
@@ -0,0 +1,3 @@
1
+ import ErxesSDK from './App';
2
+ export default ErxesSDK;
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ErxesSDK"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,OAAO;AAE5B,eAAeA,QAAQ"}
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ export type PropTypes = {
3
+ brandId: string;
4
+ src: string;
5
+ pollInterval: number;
6
+ };
7
+ declare const ErxesSDK: React.FC<PropTypes>;
8
+ export default ErxesSDK;
9
+ //# sourceMappingURL=App.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,QAAA,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CA0CjC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import ErxesSDK from './App';
2
+ export default ErxesSDK;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,OAAO,CAAC;AAE7B,eAAe,QAAQ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,162 @@
1
+ {
2
+ "name": "rn-erxes-sdk",
3
+ "version": "0.1.0",
4
+ "description": "react-native erxes sdk",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "*.podspec",
17
+ "!lib/typescript/example",
18
+ "!ios/build",
19
+ "!android/build",
20
+ "!android/gradle",
21
+ "!android/gradlew",
22
+ "!android/gradlew.bat",
23
+ "!android/local.properties",
24
+ "!**/__tests__",
25
+ "!**/__fixtures__",
26
+ "!**/__mocks__",
27
+ "!**/.*"
28
+ ],
29
+ "scripts": {
30
+ "test": "jest",
31
+ "typecheck": "tsc --noEmit",
32
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
33
+ "prepack": "bob build",
34
+ "release": "release-it",
35
+ "example": "yarn --cwd example",
36
+ "bootstrap": "yarn example && yarn install"
37
+ },
38
+ "keywords": [
39
+ "react-native",
40
+ "ios",
41
+ "android"
42
+ ],
43
+ "repository": "https://github.com/Munkhorgilb/rn-erxes-sdk",
44
+ "author": "Munkh-orgil <monkhorgilbayarbaatar@gmail.com> (https://github.com/Munkhorgilb)",
45
+ "license": "MIT",
46
+ "bugs": {
47
+ "url": "https://github.com/Munkhorgilb/rn-erxes-sdk/issues"
48
+ },
49
+ "homepage": "https://github.com/Munkhorgilb/rn-erxes-sdk#readme",
50
+ "publishConfig": {
51
+ "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "devDependencies": {
54
+ "@commitlint/config-conventional": "^17.0.2",
55
+ "@evilmartians/lefthook": "^1.2.2",
56
+ "@react-native-community/eslint-config": "^3.0.2",
57
+ "@release-it/conventional-changelog": "^5.0.0",
58
+ "@types/jest": "^28.1.2",
59
+ "@types/react": "~17.0.21",
60
+ "@types/react-native": "0.70.0",
61
+ "commitlint": "^17.0.2",
62
+ "del-cli": "^5.0.0",
63
+ "eslint": "^8.4.1",
64
+ "eslint-config-prettier": "^8.5.0",
65
+ "eslint-plugin-prettier": "^4.0.0",
66
+ "jest": "^28.1.1",
67
+ "pod-install": "^0.1.0",
68
+ "prettier": "^2.0.5",
69
+ "react": "18.2.0",
70
+ "react-native": "0.71.8",
71
+ "react-native-builder-bob": "^0.20.0",
72
+ "release-it": "^15.0.0",
73
+ "typescript": "^4.5.2"
74
+ },
75
+ "resolutions": {
76
+ "@types/react": "17.0.21"
77
+ },
78
+ "peerDependencies": {
79
+ "react": "*",
80
+ "react-native": "*"
81
+ },
82
+ "engines": {
83
+ "node": ">= 16.0.0"
84
+ },
85
+ "packageManager": "^yarn@1.22.15",
86
+ "jest": {
87
+ "preset": "react-native",
88
+ "modulePathIgnorePatterns": [
89
+ "<rootDir>/example/node_modules",
90
+ "<rootDir>/lib/"
91
+ ]
92
+ },
93
+ "commitlint": {
94
+ "extends": [
95
+ "@commitlint/config-conventional"
96
+ ]
97
+ },
98
+ "release-it": {
99
+ "git": {
100
+ "commitMessage": "chore: release ${version}",
101
+ "tagName": "v${version}"
102
+ },
103
+ "npm": {
104
+ "publish": true
105
+ },
106
+ "github": {
107
+ "release": true
108
+ },
109
+ "plugins": {
110
+ "@release-it/conventional-changelog": {
111
+ "preset": "angular"
112
+ }
113
+ }
114
+ },
115
+ "eslintConfig": {
116
+ "root": true,
117
+ "extends": [
118
+ "@react-native-community",
119
+ "prettier"
120
+ ],
121
+ "rules": {
122
+ "prettier/prettier": [
123
+ "error",
124
+ {
125
+ "quoteProps": "consistent",
126
+ "singleQuote": true,
127
+ "tabWidth": 2,
128
+ "trailingComma": "es5",
129
+ "useTabs": false
130
+ }
131
+ ]
132
+ }
133
+ },
134
+ "eslintIgnore": [
135
+ "node_modules/",
136
+ "lib/"
137
+ ],
138
+ "prettier": {
139
+ "quoteProps": "consistent",
140
+ "singleQuote": true,
141
+ "tabWidth": 2,
142
+ "trailingComma": "es5",
143
+ "useTabs": false
144
+ },
145
+ "react-native-builder-bob": {
146
+ "source": "src",
147
+ "output": "lib",
148
+ "targets": [
149
+ "commonjs",
150
+ "module",
151
+ [
152
+ "typescript",
153
+ {
154
+ "project": "tsconfig.build.json"
155
+ }
156
+ ]
157
+ ]
158
+ },
159
+ "dependencies": {
160
+ "react-native-webview": "^12.2.0"
161
+ }
162
+ }
package/src/App.tsx ADDED
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import WebView from 'react-native-webview';
3
+ import { Platform } from 'react-native';
4
+
5
+ export type PropTypes = {
6
+ brandId: string;
7
+ src: string;
8
+ pollInterval: number;
9
+ };
10
+
11
+ const ErxesSDK: React.FC<PropTypes> = ({ brandId, src, pollInterval }) => {
12
+ const runFirst = `window.erxesSettings = { messenger: { brand_id: "${brandId}", pollInterval: ${pollInterval}, css: ".topbar-button.right { visibility: hidden;} .erxes-launcher { visibility: hidden; }"}, }; (function () { var script = document.createElement('script'); script.src = "${src}/build/messengerWidget.bundle.js"; script.async = true; var entry = document.getElementsByTagName('script')[0]; entry.parentNode.insertBefore(script, entry); })(); true;`;
13
+
14
+ const onMessage = (data: any) => {
15
+ const { notificationCount } = JSON.parse(data.nativeEvent.data);
16
+
17
+ console.log('****************** ', notificationCount);
18
+ };
19
+
20
+ return (
21
+ <WebView
22
+ source={
23
+ Platform.OS === 'ios'
24
+ ? require('./index.html')
25
+ : { uri: 'file:///android_asset/index.html' }
26
+ }
27
+ originWhitelist={['*']}
28
+ sharedCookiesEnabled={true}
29
+ cacheEnabled={true}
30
+ allowFileAccess={true}
31
+ domStorageEnabled={true}
32
+ thirdPartyCookiesEnabled={true}
33
+ // allowingReadAccessToURL
34
+ // style={{ width: 200 }}
35
+ onLoadEnd={(syntheticEvent) => {
36
+ // update component to be aware of loading status
37
+ const { nativeEvent } = syntheticEvent;
38
+ console.log(nativeEvent.loading);
39
+ }}
40
+ javaScriptEnabled={true}
41
+ onError={(er) => {
42
+ console.log(er);
43
+ }}
44
+ startInLoadingState={true}
45
+ // renderLoading={() => <Loader />}
46
+ injectedJavaScript={runFirst}
47
+ // injectedJavaScriptBeforeContentLoaded={runFirst}
48
+
49
+ // onNavigationStateChange={this.handleWebViewNavigationStateChange}
50
+ onMessage={onMessage}
51
+ />
52
+ );
53
+ };
54
+
55
+ export default ErxesSDK;
package/src/index.html ADDED
@@ -0,0 +1,114 @@
1
+ <html>
2
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
3
+ <meta charset="utf-8" />
4
+
5
+ <body id="mbody" onload="openMessenger()"></body>
6
+ <script>
7
+ function openMessenger() {
8
+ setTimeout(function () {
9
+ window.Erxes.showMessenger();
10
+ }, 1500);
11
+ }
12
+
13
+ window.addEventListener('message', (e) => {
14
+ const { data } = e;
15
+ const { notificationCount } = data;
16
+
17
+ if (notificationCount !== undefined) {
18
+ window.ReactNativeWebView.postMessage(JSON.stringify(data));
19
+ }
20
+ });
21
+ </script>
22
+
23
+ <style>
24
+ #mbody {
25
+ align-items: center;
26
+ justify-content: center;
27
+ background-color: rgb(189, 189, 188);
28
+ display: flex;
29
+ /* flex-direction: column; */
30
+ }
31
+
32
+ .topbar-button {
33
+ visibility: hidden;
34
+ }
35
+
36
+ .loader {
37
+ border: 5px solid #f3f3f3;
38
+ /* Light grey */
39
+ border-top: 5px solid #3498db;
40
+ /* Blue */
41
+ border-radius: 50%;
42
+ width: 50px;
43
+ height: 50px;
44
+ animation: spin 5s linear infinite;
45
+ }
46
+
47
+ @keyframes spin {
48
+ 0% {
49
+ transform: rotate(0deg);
50
+ }
51
+
52
+ 100% {
53
+ transform: rotate(360deg);
54
+ }
55
+ }
56
+
57
+ /* CSS */
58
+ .button-75 {
59
+ align-items: center;
60
+ background-image: linear-gradient(135deg, #f34079 40%, #fc894d);
61
+ border: 0;
62
+ border-radius: 10px;
63
+ box-sizing: border-box;
64
+ color: #fff;
65
+ cursor: pointer;
66
+ display: flex;
67
+ flex-direction: column;
68
+ /* font-family: "Codec cold", sans-serif; */
69
+ font-size: 16px;
70
+ font-weight: 700;
71
+ height: 54px;
72
+ justify-content: center;
73
+ letter-spacing: 0.4px;
74
+ line-height: 1;
75
+ max-width: 100%;
76
+ padding-left: 20px;
77
+ padding-right: 20px;
78
+ padding-top: 3px;
79
+ text-decoration: none;
80
+ text-transform: uppercase;
81
+ user-select: none;
82
+ -webkit-user-select: none;
83
+ touch-action: manipulation;
84
+ }
85
+
86
+ .button-75:active {
87
+ outline: 0;
88
+ }
89
+
90
+ .button-75:hover {
91
+ outline: 0;
92
+ }
93
+
94
+ .button-75 span {
95
+ transition: all 200ms;
96
+ }
97
+
98
+ .button-75:hover span {
99
+ transform: scale(0.9);
100
+ opacity: 0.75;
101
+ }
102
+
103
+ @media screen and (max-width: 991px) {
104
+ .button-75 {
105
+ font-size: 15px;
106
+ height: 50px;
107
+ }
108
+
109
+ .button-75 span {
110
+ line-height: 50px;
111
+ }
112
+ }
113
+ </style>
114
+ </html>
package/src/index.tsx ADDED
@@ -0,0 +1,3 @@
1
+ import ErxesSDK from './App';
2
+
3
+ export default ErxesSDK;