@incognia/web-sdk 1.1.2 → 1.2.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 CHANGED
@@ -59,20 +59,26 @@ Initialize the Web SDK with your Web Application ID. This step is _required_, an
59
59
  IncogniaWebSdk.init('<your-web-app-id>')
60
60
  ```
61
61
 
62
- ### Identify
62
+ ### Account ID
63
63
 
64
- This method receives user identifiers (i.e., the `accountId`) and stores locally. The user identifier is then added to the `sessionToken` data.
64
+ The method `setAccountId` receives an account ID and stores locally. It is then added to the `requestToken` data.
65
65
 
66
66
  ```js
67
- IncogniaWebSdk.identify({ accountId: '@accountId' })
67
+ IncogniaWebSdk.setAccountId('@accountId')
68
68
  ```
69
69
 
70
- ### Get session token
70
+ The method `clearAccountId` removes the account ID from the local storage.
71
71
 
72
- This method generates a session token and returns it.
72
+ ```js
73
+ IncogniaWebSdk.clearAccountId()
74
+ ```
75
+
76
+ ### Generate request token
77
+
78
+ This method generates a request token and returns it.
73
79
 
74
80
  ```js
75
- const sessionToken = await IncogniaWebSdk.getSessionToken()
81
+ const requestToken = await IncogniaWebSdk.generateRequestToken()
76
82
  ```
77
83
 
78
84
  ### Send custom event
@@ -115,10 +121,10 @@ However, if the geolocation is available (It was authorized by the user before),
115
121
 
116
122
  ### Allowing Incognia to request geolocation permissions
117
123
 
118
- When getting the `sessionToken`, the option parameter `askForGeolocation` can be used to allow Incognia to automatically request the user location permissions.
124
+ When getting the `requestToken`, the option parameter `askForGeolocation` can be used to allow Incognia to automatically request the user location permissions.
119
125
 
120
126
  ```js
121
- const sessionToken = await IncogniaWebSdk.getSessionToken({
127
+ const requestToken = await IncogniaWebSdk.generateRequestToken({
122
128
  askForGeolocation: true
123
129
  })
124
130
  ```
@@ -136,11 +142,11 @@ IncogniaWebSdk.init(...)
136
142
  2. Ask the user for Geolocation and then proceed to get the token:
137
143
 
138
144
  ```js
139
- navigator.geolocation.getCurrentPosition(getSessionToken, getSessionToken)
145
+ navigator.geolocation.getCurrentPosition(generateRequestToken, generateRequestToken)
140
146
 
141
- function getSessionToken() {
142
- const sessionToken = await IncogniaWebSdk.getSessionToken()
143
- //TODO: Send the sessionToken to your backend.
147
+ function generateRequestToken() {
148
+ const requestToken = await IncogniaWebSdk.generateRequestToken()
149
+ //TODO: Send the requestToken to your backend.
144
150
  }
145
151
  ```
146
152
 
package/dist/index.d.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  export type Identity = {
2
2
  accountId: string;
3
3
  };
4
+ /**
5
+ * @deprecated Since v1.2.0 - Use `GenerateRequestTokenParams` instead.
6
+ */
4
7
  export type GetSessionTokenParams = {
5
8
  askForGeolocation: boolean;
6
9
  };
10
+ export type GenerateRequestTokenParams = {
11
+ askForGeolocation: boolean;
12
+ };
7
13
  export type EventProperties = Record<string, string | number | boolean>;
8
14
  export type EventAddress = {
9
15
  locale?: string;
@@ -27,8 +33,18 @@ export type CustomEventParams = {
27
33
  properties?: EventProperties;
28
34
  };
29
35
  declare class IncogniaWebSdk {
36
+ #private;
30
37
  init(appId: string): Promise<void>;
38
+ setAccountId(accountId: string): Promise<void>;
39
+ clearAccountId(): Promise<void>;
40
+ /**
41
+ * @deprecated Since v1.2.0 - Use `setAccountId` to set a new account id and `clearAccountId` to clear the account id instead.
42
+ */
31
43
  identify(identity: Identity): Promise<void>;
44
+ generateRequestToken(options?: GenerateRequestTokenParams): Promise<string | undefined>;
45
+ /**
46
+ * @deprecated Since v1.2.0 - Use `generateRequestToken` instead.
47
+ */
32
48
  getSessionToken(options?: GetSessionTokenParams): Promise<string | undefined>;
33
49
  sendCustomEvent(params: CustomEventParams): Promise<void>;
34
50
  }