@incognia/web-sdk 0.11.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 +118 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1 -0
- package/dist/web-sdk.cjs.production.min.js +1 -0
- package/dist/web-sdk.esm.js +1 -0
- package/package.json +24 -0
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Incognia Web SDK
|
|
2
|
+
|
|
3
|
+
The Incognia SDK for the web.
|
|
4
|
+
|
|
5
|
+
Documentation can be found at <https://developer.incognia.com/docs>
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### npm
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @incognia/web-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### yarn
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
yarn add @incognia/web-sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### CDN
|
|
22
|
+
|
|
23
|
+
Add the following script to your HTML:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
<script src="https://repo.incognia.com/web/latest/incognia-web-sdk.js"></script>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
###
|
|
30
|
+
|
|
31
|
+
## Getting started
|
|
32
|
+
|
|
33
|
+
Import the package:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
// ES6
|
|
37
|
+
import IncogniaWebSdk from '@incognia/web-sdk'
|
|
38
|
+
|
|
39
|
+
// CommonJS (Outdated)
|
|
40
|
+
const IncogniaWebSdk = require('@incognia/web-sdk')
|
|
41
|
+
|
|
42
|
+
// CDN Script
|
|
43
|
+
const IncogniaWebSdk = window.IncogniaWebSdk
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Library API methods
|
|
47
|
+
|
|
48
|
+
### Init
|
|
49
|
+
|
|
50
|
+
Initialize the Web SDK with your Web Application ID. This step is _required_, and further methods will not work if the SDK is not initialized.
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
IncogniaWebSdk.init('<your-web-app-id>')
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Identify
|
|
57
|
+
|
|
58
|
+
This method receives user identifiers (i.e., the `accountId`) and stores locally. The user identifier is then added to the `sessionToken` data.
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
IncogniaWebSdk.identify({ accountId: '@accountId' })
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Get session token
|
|
65
|
+
|
|
66
|
+
This method generates a session token and returns it.
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
const sessionToken = await IncogniaWebSdk.getSessionToken()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Geolocation API
|
|
73
|
+
|
|
74
|
+
By default, the Incognia Web SDK does not ask the user for geolocation, because:
|
|
75
|
+
|
|
76
|
+
- Not all use cases requires geolocation
|
|
77
|
+
- The website should have total control when to ask for geolocation
|
|
78
|
+
- The lib should run silently.
|
|
79
|
+
|
|
80
|
+
However, if the geolocation is available (It was authorized by the user before), the Web SDK will include the geolocation information into the token.
|
|
81
|
+
|
|
82
|
+
### Allowing Incognia to request geolocation permissions
|
|
83
|
+
|
|
84
|
+
When getting the `sessionToken`, the option parameter `askForGeolocation` can be used to allow Incognia to automatically request the user location permissions.
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
const sessionToken = await IncogniaWebSdk.getSessionToken({
|
|
88
|
+
askForGeolocation: true
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### How and when to ask the user for geolocation?
|
|
93
|
+
|
|
94
|
+
The ideal flow to manually ask the user for geolocation is:
|
|
95
|
+
|
|
96
|
+
1. Initialize the SDK:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
IncogniaWebSdk.init(...)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
2. Ask the user for Geolocation and then proceed to get the token:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
navigator.geolocation.getCurrentPosition(getSessionToken, getSessionToken)
|
|
106
|
+
|
|
107
|
+
function getSessionToken() {
|
|
108
|
+
const sessionToken = await IncogniaWebSdk.getSessionToken()
|
|
109
|
+
//TODO: Send the sessionToken to your backend.
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Browser Compatibility
|
|
114
|
+
|
|
115
|
+
Except for IE, this lib is compatible with every modern browser.
|
|
116
|
+
|
|
117
|
+
However, for Geolocation API, each browser handles it differently. For example, Firefox v104 does not provide the Geolocation API by default. So the user has to enable it.
|
|
118
|
+
Besides, for some OSs like MacOS, you have to allow the browser to access the geolocation. If the geolocation is not available, the token will be generated without that information.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare type Identity = {
|
|
2
|
+
accountId: string;
|
|
3
|
+
};
|
|
4
|
+
declare type GetSessionTokenParams = {
|
|
5
|
+
askForGeolocation: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare class IncogniaWebSdk {
|
|
8
|
+
init(appId: string): Promise<void>;
|
|
9
|
+
identify(identity: Identity): Promise<void>;
|
|
10
|
+
getSessionToken(options?: GetSessionTokenParams): Promise<string | undefined>;
|
|
11
|
+
}
|
|
12
|
+
declare const incogniaWebSdk: IncogniaWebSdk;
|
|
13
|
+
export default incogniaWebSdk;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var a0y=a0Q;(function(D,Q){var a0T={D:0x1e0,Q:0x1df,m:0x1e4,h:0x1ea,O:0x1e5,y:0x1e2,T:0x1e9,a:0x1e6,k:0x1dd,s:0x1e1},n=a0Q,m=D();while(!![]){try{var h=-parseInt(n(a0T.D))/0x1+parseInt(n(a0T.Q))/0x2+parseInt(n(a0T.m))/0x3*(parseInt(n(a0T.h))/0x4)+parseInt(n(a0T.O))/0x5*(-parseInt(n(a0T.y))/0x6)+-parseInt(n(a0T.T))/0x7+parseInt(n(a0T.a))/0x8*(parseInt(n(a0T.k))/0x9)+-parseInt(n(a0T.s))/0xa;if(h===Q)break;else m['push'](m['shift']());}catch(O){m['push'](m['shift']());}}}(a0D,0x5d0bb));function a0Q(D,Q){var m=a0D();return a0Q=function(h,O){h=h-0x1dd;var n=m[h];if(a0Q['DOJknU']===undefined){var y=function(s){var q='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var S='',J='';for(var A=0x0,w,p,c=0x0;p=s['charAt'](c++);~p&&(w=A%0x4?w*0x40+p:p,A++%0x4)?S+=String['fromCharCode'](0xff&w>>(-0x2*A&0x6)):0x0){p=q['indexOf'](p);}for(var N=0x0,F=S['length'];N<F;N++){J+='%'+('00'+S['charCodeAt'](N)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(J);};a0Q['MHLOeA']=y,D=arguments,a0Q['DOJknU']=!![];}var T=m[0x0],a=h+T,k=D[a];return!k?(n=a0Q['MHLOeA'](n),D[a]=n):n=k,n;},a0Q(D,Q);}function a0D(){var a=['mJu2mJKYmen6zwvVuG','mtmYCeDxvKj2','tK9erv9ftLy','nM9QEhDOqW','mtK0mtvNCw55uxu','mtuYr2Dowfj2','zxHWB3j0CW','zw52','mtGZodq0nxj2v1HhwG','otK5odq4EwLjv2jS','ChjVzhvJDgLVBG','mZi2nJm3zxzPvLbq','lI93zwiTC2rRlMnQCY5WCM9KDwn0Aw9UlM1PBI5QCW','nZe2odi0seTHz0Dq','ntyYndm1AhrRrhHt'];a0D=function(){return a;};return a0D();}process[a0y(0x1e8)][a0y(0x1e3)]===a0y(0x1eb)?module[a0y(0x1e7)]=require(a0y(0x1de)):module[a0y(0x1e7)]=require(a0y(0x1de));
|