rn-linkrunner 0.2.1 → 0.3.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/README.md +50 -10
- package/lib/commonjs/index.js +13 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +13 -8
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/index.ts +14 -9
package/README.md
CHANGED
|
@@ -1,31 +1,71 @@
|
|
|
1
1
|
# rn-linkrunner
|
|
2
2
|
|
|
3
|
-
React Native Package for linkrunner
|
|
3
|
+
React Native Package for [linkrunner.io](https://www.linkrunner.io)
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
+
### Step 1: Prerequisites
|
|
8
|
+
|
|
9
|
+
rn-linkrunner also uses `react-native-device-info` and `react-native-encrypted-storage`, you can install these packages from the below mentioned commands
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install react-native-device-info react-native-encrypted-storage
|
|
13
|
+
|
|
14
|
+
or
|
|
15
|
+
|
|
16
|
+
yarn add react-native-device-info react-native-encrypted-storage
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
then run `cd ios && pod install` to install pods for the above mentioned packages
|
|
20
|
+
|
|
21
|
+
### Step 2: Installing rn-linkrunner
|
|
22
|
+
|
|
7
23
|
```sh
|
|
8
24
|
npm install rn-linkrunner
|
|
25
|
+
|
|
26
|
+
or
|
|
27
|
+
|
|
28
|
+
yarn add rn-linkrunner
|
|
9
29
|
```
|
|
10
30
|
|
|
11
31
|
## Usage
|
|
12
32
|
|
|
33
|
+
### Initialisation
|
|
34
|
+
|
|
35
|
+
You'll need your [project token](https://www.linkrunner.io) to initialisation the package
|
|
36
|
+
|
|
37
|
+
Place it in the `App.tsx` component, make sure the dependency array is empty for the `useEffect`
|
|
38
|
+
|
|
13
39
|
```js
|
|
14
|
-
import
|
|
40
|
+
import linkrunner from 'rn-linkrunner';
|
|
41
|
+
|
|
42
|
+
// Inside your react component
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
linkrunner.init('PROJECT_TOKEN');
|
|
45
|
+
}, []);
|
|
46
|
+
```
|
|
15
47
|
|
|
16
|
-
|
|
48
|
+
### Trigger
|
|
17
49
|
|
|
18
|
-
|
|
50
|
+
Call this function once your onboarding is completed and the navigation stack can be accessed by a deeplink
|
|
51
|
+
|
|
52
|
+
```JSX
|
|
53
|
+
import linkrunner from 'rn-linkrunner';
|
|
54
|
+
|
|
55
|
+
const onTrigger = () => {
|
|
56
|
+
linkrunner.trigger({
|
|
57
|
+
user_id: 'USER_ID',
|
|
58
|
+
data: {},
|
|
59
|
+
});
|
|
60
|
+
};
|
|
19
61
|
```
|
|
20
62
|
|
|
21
|
-
|
|
63
|
+
Both the attributes in the `trigger` method are optional although recommened to have.
|
|
64
|
+
|
|
65
|
+
<!-- ## Contributing
|
|
22
66
|
|
|
23
|
-
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
67
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. -->
|
|
24
68
|
|
|
25
69
|
## License
|
|
26
70
|
|
|
27
71
|
MIT
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
package/lib/commonjs/index.js
CHANGED
|
@@ -5,11 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _reactNativeDeviceInfo = _interopRequireDefault(require("react-native-device-info"));
|
|
8
|
+
var _reactNativeEncryptedStorage = _interopRequireDefault(require("react-native-encrypted-storage"));
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
|
|
10
|
-
const package_version = '0.2.1';
|
|
10
|
+
const package_version = '0.2.2';
|
|
11
11
|
const app_version = _reactNativeDeviceInfo.default.getVersion();
|
|
12
|
+
const EncryptedStorageTokenName = 'linkrunner-token';
|
|
12
13
|
const init = token => {
|
|
14
|
+
// In error message add "Click here to get your project token"
|
|
13
15
|
if (!token) return console.error('Linkrunner needs your project token to initialize!');
|
|
14
16
|
fetch('http://localhost:4000/api/client/init', {
|
|
15
17
|
method: 'POST',
|
|
@@ -22,21 +24,22 @@ const init = token => {
|
|
|
22
24
|
package_version,
|
|
23
25
|
app_version
|
|
24
26
|
})
|
|
25
|
-
}).then(res => res.json()).then(result => {
|
|
27
|
+
}).then(res => res.json()).then(async result => {
|
|
26
28
|
if (!result) throw new Error('No response obtained!');
|
|
27
29
|
if ((result === null || result === void 0 ? void 0 : result.status) !== 200 && (result === null || result === void 0 ? void 0 : result.status) !== 201) {
|
|
28
30
|
throw new Error(result === null || result === void 0 ? void 0 : result.msg);
|
|
29
31
|
}
|
|
30
|
-
|
|
32
|
+
await _reactNativeEncryptedStorage.default.setItem(EncryptedStorageTokenName, token);
|
|
31
33
|
console.log('Linkrunner initialised successfully 🔥');
|
|
32
34
|
}).catch(err => {
|
|
33
35
|
console.error('Error initializing linkrunner: ', err.message);
|
|
34
36
|
});
|
|
35
37
|
};
|
|
36
|
-
const trigger = ({
|
|
38
|
+
const trigger = async ({
|
|
37
39
|
data,
|
|
38
40
|
user_id
|
|
39
41
|
}) => {
|
|
42
|
+
const token = await _reactNativeEncryptedStorage.default.getItem(EncryptedStorageTokenName);
|
|
40
43
|
fetch('http://localhost:4000/api/client/trigger', {
|
|
41
44
|
method: 'POST',
|
|
42
45
|
headers: {
|
|
@@ -44,18 +47,20 @@ const trigger = ({
|
|
|
44
47
|
'Content-Type': 'application/json'
|
|
45
48
|
},
|
|
46
49
|
body: JSON.stringify({
|
|
47
|
-
token
|
|
50
|
+
token,
|
|
48
51
|
user_id,
|
|
49
52
|
data
|
|
50
53
|
})
|
|
51
54
|
}).then(res => res.json()).then(result => {
|
|
52
55
|
if (!result) throw new Error('No response obtained!');
|
|
53
56
|
if ((result === null || result === void 0 ? void 0 : result.status) !== 200 && (result === null || result === void 0 ? void 0 : result.status) !== 201) {
|
|
54
|
-
|
|
57
|
+
console.error('Linkrunner: Trigger failed');
|
|
58
|
+
console.error('Linkrunner: ', result === null || result === void 0 ? void 0 : result.msg);
|
|
55
59
|
}
|
|
56
60
|
console.log('Linkrunner: Trigger called 🔥');
|
|
57
61
|
}).catch(err => {
|
|
58
|
-
console.error('
|
|
62
|
+
console.error('Linkrunner: Trigger failed');
|
|
63
|
+
console.error('Linkrunner: ', err === null || err === void 0 ? void 0 : err.msg);
|
|
59
64
|
});
|
|
60
65
|
};
|
|
61
66
|
const linkrunner = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeDeviceInfo","_interopRequireDefault","require","obj","__esModule","default","
|
|
1
|
+
{"version":3,"names":["_reactNativeDeviceInfo","_interopRequireDefault","require","_reactNativeEncryptedStorage","obj","__esModule","default","package_version","app_version","DeviceInfo","getVersion","EncryptedStorageTokenName","init","token","console","error","fetch","method","headers","body","JSON","stringify","then","res","json","result","Error","status","msg","EncryptedStorage","setItem","log","catch","err","message","trigger","data","user_id","getItem","linkrunner","_default","exports"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,sBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,4BAAA,GAAAF,sBAAA,CAAAC,OAAA;AAA8D,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE9D,MAAMG,eAAe,GAAG,OAAO;AAC/B,MAAMC,WAAW,GAAGC,8BAAU,CAACC,UAAU,CAAC,CAAC;AAC3C,MAAMC,yBAAyB,GAAG,kBAAkB;AAEpD,MAAMC,IAAI,GAAIC,KAAa,IAAK;EAC9B;EACA,IAAI,CAACA,KAAK,EACR,O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cAAc,EAAE;IAClB,CAAC;IACDC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAAC;MACnBR,KAAK;MACLwB,OAAO;MACPD;IACF,CAAC;EACH,CAAC,CAAC,CACCd,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBF,IAAI,CAAEG,MAAM,IAAK;IAChB,IAAI,CAACA,MAAM,EAAE,MAAM,IAAIC,KAAK,CAAC,uBAAuB,CAAC;IAErD,IAAI,CAAAD,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEE,MAAM,MAAK,GAAG,IAAI,CAAAF,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEE,MAAM,MAAK,GAAG,EAAE;MACpDb,OAAO,CAACC,KAAK,CAAC,4BAA4B,CAAC;MAC3CD,OAAO,CAACC,KAAK,CAAC,cAAc,EAAEU,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEG,GAAG,CAAC;IAC5C;IAEAd,OAAO,CAACiB,GAAG,CAAC,+BAA+B,CAAC;EAC9C,CAAC,CAAC,CACDC,KAAK,CAAEC,GAAG,IAAK;IACdnB,OAAO,CAACC,KAAK,CAAC,4BAA4B,CAAC;IAC3CD,OAAO,CAACC,KAAK,CAAC,cAAc,EAAEkB,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEL,GAAG,CAAC;EACzC,CAAC,CAAC;AACN,CAAC;AAED,MAAMW,UAAU,GAAG;EACjB3B,IAAI;EACJuB;AACF,CAAC;AAAC,IAAAK,QAAA,GAAAC,OAAA,CAAAnC,OAAA,GAEaiC,UAAU"}
|
package/lib/module/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import DeviceInfo from 'react-native-device-info';
|
|
2
|
-
|
|
3
|
-
const package_version = '0.2.
|
|
2
|
+
import EncryptedStorage from 'react-native-encrypted-storage';
|
|
3
|
+
const package_version = '0.2.2';
|
|
4
4
|
const app_version = DeviceInfo.getVersion();
|
|
5
|
+
const EncryptedStorageTokenName = 'linkrunner-token';
|
|
5
6
|
const init = token => {
|
|
7
|
+
// In error message add "Click here to get your project token"
|
|
6
8
|
if (!token) return console.error('Linkrunner needs your project token to initialize!');
|
|
7
9
|
fetch('http://localhost:4000/api/client/init', {
|
|
8
10
|
method: 'POST',
|
|
@@ -15,21 +17,22 @@ const init = token => {
|
|
|
15
17
|
package_version,
|
|
16
18
|
app_version
|
|
17
19
|
})
|
|
18
|
-
}).then(res => res.json()).then(result => {
|
|
20
|
+
}).then(res => res.json()).then(async result => {
|
|
19
21
|
if (!result) throw new Error('No response obtained!');
|
|
20
22
|
if ((result === null || result === void 0 ? void 0 : result.status) !== 200 && (result === null || result === void 0 ? void 0 : result.status) !== 201) {
|
|
21
23
|
throw new Error(result === null || result === void 0 ? void 0 : result.msg);
|
|
22
24
|
}
|
|
23
|
-
|
|
25
|
+
await EncryptedStorage.setItem(EncryptedStorageTokenName, token);
|
|
24
26
|
console.log('Linkrunner initialised successfully 🔥');
|
|
25
27
|
}).catch(err => {
|
|
26
28
|
console.error('Error initializing linkrunner: ', err.message);
|
|
27
29
|
});
|
|
28
30
|
};
|
|
29
|
-
const trigger = ({
|
|
31
|
+
const trigger = async ({
|
|
30
32
|
data,
|
|
31
33
|
user_id
|
|
32
34
|
}) => {
|
|
35
|
+
const token = await EncryptedStorage.getItem(EncryptedStorageTokenName);
|
|
33
36
|
fetch('http://localhost:4000/api/client/trigger', {
|
|
34
37
|
method: 'POST',
|
|
35
38
|
headers: {
|
|
@@ -37,18 +40,20 @@ const trigger = ({
|
|
|
37
40
|
'Content-Type': 'application/json'
|
|
38
41
|
},
|
|
39
42
|
body: JSON.stringify({
|
|
40
|
-
token
|
|
43
|
+
token,
|
|
41
44
|
user_id,
|
|
42
45
|
data
|
|
43
46
|
})
|
|
44
47
|
}).then(res => res.json()).then(result => {
|
|
45
48
|
if (!result) throw new Error('No response obtained!');
|
|
46
49
|
if ((result === null || result === void 0 ? void 0 : result.status) !== 200 && (result === null || result === void 0 ? void 0 : result.status) !== 201) {
|
|
47
|
-
|
|
50
|
+
console.error('Linkrunner: Trigger failed');
|
|
51
|
+
console.error('Linkrunner: ', result === null || result === void 0 ? void 0 : result.msg);
|
|
48
52
|
}
|
|
49
53
|
console.log('Linkrunner: Trigger called 🔥');
|
|
50
54
|
}).catch(err => {
|
|
51
|
-
console.error('
|
|
55
|
+
console.error('Linkrunner: Trigger failed');
|
|
56
|
+
console.error('Linkrunner: ', err === null || err === void 0 ? void 0 : err.msg);
|
|
52
57
|
});
|
|
53
58
|
};
|
|
54
59
|
const linkrunner = {
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["DeviceInfo","
|
|
1
|
+
{"version":3,"names":["DeviceInfo","EncryptedStorage","package_version","app_version","getVersion","EncryptedStorageTokenName","init","token","console","error","fetch","method","headers","body","JSON","stringify","then","res","json","result","Error","status","msg","setItem","log","catch","err","message","trigger","data","user_id","getItem","linkrunner"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,OAAOA,UAAU,MAAM,0BAA0B;AACjD,OAAOC,gBAAgB,MAAM,gCAAgC;AAE7D,MAAMC,eAAe,GAAG,OAAO;AAC/B,MAAMC,WAAW,GAAGH,UAAU,CAACI,UAAU,CAAC,CAAC;AAC3C,MAAMC,yBAAyB,GAAG,kBAAkB;AAEpD,MAAMC,IAAI,GAAIC,KAAa,IAAK;EAC9B;EACA,IAAI,CAACA,KAAK,EACR,OAAOC,OAAO,CAACC,KAAK,CAAC,oDAAoD,CAAC;EAE5EC,KAAK,CAAC,uCAAuC,EAAE;IAC7CC,MAAM,EAAE,MAAM;IACdC,OAAO,EAAE;MACP,QAAQ,EAAE,kBAAkB;MAC5B,cAAc,EAAE;IAClB,CAAC;IACDC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAAC;MACnBR,KAAK;MACLL,eAAe;MACfC;IACF,CAAC;EACH,CAAC,CAAC,CACCa,IAAI,CAAEC,GAAG,IAA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,CAAAD,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEE,MAAM,MAAK,GAAG,IAAI,CAAAF,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEE,MAAM,MAAK,GAAG,EAAE;MACpDb,OAAO,CAACC,KAAK,CAAC,4BAA4B,CAAC;MAC3CD,OAAO,CAACC,KAAK,CAAC,cAAc,EAAEU,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEG,GAAG,CAAC;IAC5C;IAEAd,OAAO,CAACgB,GAAG,CAAC,+BAA+B,CAAC;EAC9C,CAAC,CAAC,CACDC,KAAK,CAAEC,GAAG,IAAK;IACdlB,OAAO,CAACC,KAAK,CAAC,4BAA4B,CAAC;IAC3CD,OAAO,CAACC,KAAK,CAAC,cAAc,EAAEiB,GAAG,aAAHA,GAAG,uBAAHA,GAAG,CAAEJ,GAAG,CAAC;EACzC,CAAC,CAAC;AACN,CAAC;AAED,MAAMU,UAAU,GAAG;EACjB1B,IAAI;EACJsB;AACF,CAAC;AAED,eAAeI,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA8EA,QAAA,MAAM,UAAU;kBAvEK,MAAM;;iBAqChB,MAAM,GAAG,MAAM;cAClB,GAAG;;CAoCV,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-linkrunner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React Native Package for linkrunner",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -138,6 +138,7 @@
|
|
|
138
138
|
]
|
|
139
139
|
},
|
|
140
140
|
"dependencies": {
|
|
141
|
-
"react-native-device-info": "^10.12.0"
|
|
141
|
+
"react-native-device-info": "^10.12.0",
|
|
142
|
+
"react-native-encrypted-storage": "^4.0.3"
|
|
142
143
|
}
|
|
143
144
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import DeviceInfo from 'react-native-device-info';
|
|
2
|
+
import EncryptedStorage from 'react-native-encrypted-storage';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const package_version = '0.2.1';
|
|
4
|
+
const package_version = '0.2.2';
|
|
6
5
|
const app_version = DeviceInfo.getVersion();
|
|
6
|
+
const EncryptedStorageTokenName = 'linkrunner-token';
|
|
7
7
|
|
|
8
8
|
const init = (token: string) => {
|
|
9
|
+
// In error message add "Click here to get your project token"
|
|
9
10
|
if (!token)
|
|
10
11
|
return console.error('Linkrunner needs your project token to initialize!');
|
|
11
12
|
|
|
@@ -22,14 +23,14 @@ const init = (token: string) => {
|
|
|
22
23
|
}),
|
|
23
24
|
})
|
|
24
25
|
.then((res) => res.json())
|
|
25
|
-
.then((result) => {
|
|
26
|
+
.then(async (result) => {
|
|
26
27
|
if (!result) throw new Error('No response obtained!');
|
|
27
28
|
|
|
28
29
|
if (result?.status !== 200 && result?.status !== 201) {
|
|
29
30
|
throw new Error(result?.msg);
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
await EncryptedStorage.setItem(EncryptedStorageTokenName, token);
|
|
33
34
|
console.log('Linkrunner initialised successfully 🔥');
|
|
34
35
|
})
|
|
35
36
|
.catch((err) => {
|
|
@@ -37,13 +38,15 @@ const init = (token: string) => {
|
|
|
37
38
|
});
|
|
38
39
|
};
|
|
39
40
|
|
|
40
|
-
const trigger = ({
|
|
41
|
+
const trigger = async ({
|
|
41
42
|
data,
|
|
42
43
|
user_id,
|
|
43
44
|
}: {
|
|
44
45
|
user_id: string | number;
|
|
45
46
|
data: any;
|
|
46
47
|
}) => {
|
|
48
|
+
const token = await EncryptedStorage.getItem(EncryptedStorageTokenName);
|
|
49
|
+
|
|
47
50
|
fetch('http://localhost:4000/api/client/trigger', {
|
|
48
51
|
method: 'POST',
|
|
49
52
|
headers: {
|
|
@@ -51,7 +54,7 @@ const trigger = ({
|
|
|
51
54
|
'Content-Type': 'application/json',
|
|
52
55
|
},
|
|
53
56
|
body: JSON.stringify({
|
|
54
|
-
token
|
|
57
|
+
token,
|
|
55
58
|
user_id,
|
|
56
59
|
data,
|
|
57
60
|
}),
|
|
@@ -61,13 +64,15 @@ const trigger = ({
|
|
|
61
64
|
if (!result) throw new Error('No response obtained!');
|
|
62
65
|
|
|
63
66
|
if (result?.status !== 200 && result?.status !== 201) {
|
|
64
|
-
|
|
67
|
+
console.error('Linkrunner: Trigger failed');
|
|
68
|
+
console.error('Linkrunner: ', result?.msg);
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
console.log('Linkrunner: Trigger called 🔥');
|
|
68
72
|
})
|
|
69
73
|
.catch((err) => {
|
|
70
|
-
console.error('
|
|
74
|
+
console.error('Linkrunner: Trigger failed');
|
|
75
|
+
console.error('Linkrunner: ', err?.msg);
|
|
71
76
|
});
|
|
72
77
|
};
|
|
73
78
|
|