guidewhale 1.0.4 → 1.0.6

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
@@ -10,7 +10,27 @@ The script is automatically loaded when the module is imported. Any methods that
10
10
  npm install guidewhale
11
11
  ```
12
12
 
13
- ## Usage
13
+ ## User Identity Verification
14
+ In order to verify user identity and prevent impersonations, you need to sign your `user_id` with a secret key and provide the signature during JavaScript SDK initialization.
15
+
16
+ Your secret key can be copied from the GuideWhale dashboard environment settings or on the installation settings page. Please note that each environment has its own unique secret key.
17
+
18
+ > ⚠️ **Warning:** Never share your secret key. This operation should be performed on the server side only.
19
+ ```typescript
20
+ import crypto from 'crypto'
21
+
22
+ // Generate user signature using environment secret key and user_id
23
+ // IMPORTANT: Secret key should not be shared with anyone, so perform this on your server
24
+ let userSignature = crypto
25
+ .createHmac('sha256', '<secret_key>')
26
+ .update(<user_id>)
27
+ .digest('hex')
28
+
29
+ // Pass user signature to your client
30
+ ...
31
+ ```
32
+
33
+ ## User Identification
14
34
  Start by importing our package by calling `import gwhale from 'guidewhale'`, then initialize the environment and currently active user/company.
15
35
  Make sure to replace placeholder values with your actual environment token and user/company properties, while removing any non-required properties which you don't have/need.
16
36
 
@@ -21,7 +41,8 @@ gwhale.init("<guidewhale_environment_code>", { // REQUIRED - string - make sure
21
41
  gdpr: true, // OPTIONAL - true | false - enable GDPR mode to require user consent before tracking data under their user_id
22
42
  gdprConsent: true, // OPTIONAL - true | false - Whether user has given consent to track their data
23
43
  user: {
24
- user_id: <user_id>, // REQUIRED - string - unique user identifier (e.g. '100000356', '6099047b-660b-4f2e-a878-fb66a12c1840', 'john.smith@example.com')
44
+ user_id: <user_id>, // REQUIRED - string | null - unique user identifier (e.g. null for anonymous users, '100000356', '6099047b-660b-4f2e-a878-fb66a12c1840', 'john.smith@example.com')
45
+ signature: <user_signature>, // REQUIRED IF USER_ID IS SET - string - user signature hash (not the secret!) to prevent unathorized initialization
25
46
  email: <user_email>, // RECOMMENDED - string - email is used as the key to map user data for most integrations (e.g. 'john.smith@example.com')
26
47
  image_url: <profile_image_url>, // RECOMMENDED - string - used to display user's profile image inside GuideWhale dashboard (e.g. 'https://cdn.guidewhale.com/users/1234abcd/profile.png')
27
48
  first_name: <user_first_name>, // RECOMMENDED - string - can be used to personalize GuideWhale content (e.g. 'John')
@@ -5,8 +5,10 @@ type DisallowKeys<T, K extends string> = {
5
5
  [P in keyof T as P extends K ? never : P]: T[P];
6
6
  };
7
7
  type UserProperties = DisallowKeys<Record<string, any> & {
8
- user_id: string;
8
+ user_id: string | null;
9
+ signature?: string | null;
9
10
  email?: string;
11
+ image_url?: string;
10
12
  first_name?: string;
11
13
  last_name?: string;
12
14
  date_signed_up?: Date;
@@ -14,6 +16,7 @@ type UserProperties = DisallowKeys<Record<string, any> & {
14
16
  type CompanyProperties = DisallowKeys<Record<string, any> & {
15
17
  company_id: string;
16
18
  name?: string;
19
+ image_url?: string;
17
20
  plan?: string;
18
21
  date_signed_up?: Date;
19
22
  date_renewal?: Date;
@@ -10,7 +10,7 @@ var r = [
10
10
  if (!e) {
11
11
  e = t.gwhale = {
12
12
  location: t.location.href.toString(),
13
- contentUrl: "https://fast.guidewhale.com/",
13
+ contentUrl: "https://cdn.guidewhale.com/",
14
14
  t: /* @__PURE__ */ new Date()
15
15
  };
16
16
  for (var a = 0; a < r.length; a++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guidewhale",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "GuideWhale SDK client script loader",
5
5
  "type": "module",
6
6
  "main": "dist/guidewhale.js",