zubbl-sdk 1.1.2 → 1.1.4

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.
@@ -5,63 +5,90 @@ var axios = require('axios');
5
5
  let config = {
6
6
  apiKey: null,
7
7
  tenantId: null,
8
- appId: null
8
+ appId: null,
9
+ baseUrl: "https://api.zubbl.com/api" // ✅ Default to Worker-routed path
9
10
  };
10
11
 
11
- function init({ apiKey, tenantId, appId }) {
12
+ /**
13
+ * Initialize SDK with API credentials.
14
+ */
15
+ function init({ apiKey, tenantId, appId, baseUrl }) {
12
16
  if (!apiKey || !tenantId || !appId) {
13
17
  throw new Error("apiKey, tenantId, and appId are required");
14
18
  }
15
- config = { apiKey, tenantId, appId };
19
+ config = {
20
+ apiKey,
21
+ tenantId,
22
+ appId,
23
+ baseUrl: baseUrl || "https://api.zubbl.com/api" // ✅ Override if provided
24
+ };
16
25
  }
17
26
 
27
+ /**
28
+ * Identify a user by email (and optional name).
29
+ * Returns user info including external_user_id.
30
+ */
18
31
  async function identifyUser({ email, name }) {
19
32
  if (!config.apiKey || !config.tenantId || !config.appId) {
20
33
  throw new Error("Zubbl SDK not initialized");
21
34
  }
22
35
  if (!email) throw new Error("email is required");
23
36
 
24
- const headers = {
25
- Authorization: `Bearer ${config.apiKey}`,
26
- "X-Tenant-Id": config.tenantId,
27
- "X-App-Id": config.appId
28
- };
29
-
30
37
  try {
38
+ const headers = {
39
+ Authorization: `Bearer ${config.apiKey}`,
40
+ "X-Tenant-Id": config.tenantId,
41
+ "X-App-Id": config.appId,
42
+ "Content-Type": "application/json"
43
+ };
44
+
31
45
  const response = await axios.post(
32
- "https://api.zubbl.com/sdk/identify",
46
+ `${config.baseUrl}/sdk/identify`, // ✅ Now dynamic
33
47
  { email, name },
34
48
  { headers }
35
49
  );
50
+
36
51
  console.log("[ZUBBL SDK] identifyUser response:", response.data);
37
52
  return response.data;
38
53
  } catch (err) {
39
- console.error("[ZUBBL SDK] identifyUser error:", err.response?.data || err);
54
+ if (err.response && err.response.data) {
55
+ console.error("[ZUBBL SDK] identifyUser error:", err.response.data);
56
+ throw err.response.data;
57
+ }
58
+ console.error("[ZUBBL SDK] identifyUser error:", err);
40
59
  throw err;
41
60
  }
42
61
  }
43
62
 
63
+ /**
64
+ * Get tiles for a user using their external_user_id.
65
+ */
44
66
  async function getTiles({ external_user_id }) {
45
67
  if (!config.apiKey || !config.tenantId || !config.appId) {
46
68
  throw new Error("Zubbl SDK not initialized");
47
69
  }
48
70
  if (!external_user_id) throw new Error("external_user_id is required");
49
71
 
50
- const headers = {
51
- Authorization: `Bearer ${config.apiKey}`,
52
- "X-Tenant-Id": config.tenantId,
53
- "X-App-Id": config.appId
54
- };
55
-
56
72
  try {
73
+ const headers = {
74
+ Authorization: `Bearer ${config.apiKey}`,
75
+ "X-Tenant-Id": config.tenantId,
76
+ "X-App-Id": config.appId
77
+ };
78
+
57
79
  const response = await axios.get(
58
- `https://api.zubbl.com/sdk/external-users/${external_user_id}/tiles`,
80
+ `${config.baseUrl}/sdk/external-users/${external_user_id}/tiles`, // ✅ Now dynamic
59
81
  { headers }
60
82
  );
83
+
61
84
  console.log("[ZUBBL SDK] getTiles response:", response.data);
62
- return response.data; // <- This is your final, merged tile set for the user
85
+ return response.data;
63
86
  } catch (err) {
64
- console.error("[ZUBBL SDK] getTiles error:", err.response?.data || err);
87
+ if (err.response && err.response.data) {
88
+ console.error("[ZUBBL SDK] getTiles error:", err.response.data);
89
+ throw err.response.data;
90
+ }
91
+ console.error("[ZUBBL SDK] getTiles error:", err);
65
92
  throw err;
66
93
  }
67
94
  }
@@ -3,63 +3,90 @@ import axios from 'axios';
3
3
  let config = {
4
4
  apiKey: null,
5
5
  tenantId: null,
6
- appId: null
6
+ appId: null,
7
+ baseUrl: "https://api.zubbl.com/api" // ✅ Default to Worker-routed path
7
8
  };
8
9
 
9
- function init({ apiKey, tenantId, appId }) {
10
+ /**
11
+ * Initialize SDK with API credentials.
12
+ */
13
+ function init({ apiKey, tenantId, appId, baseUrl }) {
10
14
  if (!apiKey || !tenantId || !appId) {
11
15
  throw new Error("apiKey, tenantId, and appId are required");
12
16
  }
13
- config = { apiKey, tenantId, appId };
17
+ config = {
18
+ apiKey,
19
+ tenantId,
20
+ appId,
21
+ baseUrl: baseUrl || "https://api.zubbl.com/api" // ✅ Override if provided
22
+ };
14
23
  }
15
24
 
25
+ /**
26
+ * Identify a user by email (and optional name).
27
+ * Returns user info including external_user_id.
28
+ */
16
29
  async function identifyUser({ email, name }) {
17
30
  if (!config.apiKey || !config.tenantId || !config.appId) {
18
31
  throw new Error("Zubbl SDK not initialized");
19
32
  }
20
33
  if (!email) throw new Error("email is required");
21
34
 
22
- const headers = {
23
- Authorization: `Bearer ${config.apiKey}`,
24
- "X-Tenant-Id": config.tenantId,
25
- "X-App-Id": config.appId
26
- };
27
-
28
35
  try {
36
+ const headers = {
37
+ Authorization: `Bearer ${config.apiKey}`,
38
+ "X-Tenant-Id": config.tenantId,
39
+ "X-App-Id": config.appId,
40
+ "Content-Type": "application/json"
41
+ };
42
+
29
43
  const response = await axios.post(
30
- "https://api.zubbl.com/sdk/identify",
44
+ `${config.baseUrl}/sdk/identify`, // ✅ Now dynamic
31
45
  { email, name },
32
46
  { headers }
33
47
  );
48
+
34
49
  console.log("[ZUBBL SDK] identifyUser response:", response.data);
35
50
  return response.data;
36
51
  } catch (err) {
37
- console.error("[ZUBBL SDK] identifyUser error:", err.response?.data || err);
52
+ if (err.response && err.response.data) {
53
+ console.error("[ZUBBL SDK] identifyUser error:", err.response.data);
54
+ throw err.response.data;
55
+ }
56
+ console.error("[ZUBBL SDK] identifyUser error:", err);
38
57
  throw err;
39
58
  }
40
59
  }
41
60
 
61
+ /**
62
+ * Get tiles for a user using their external_user_id.
63
+ */
42
64
  async function getTiles({ external_user_id }) {
43
65
  if (!config.apiKey || !config.tenantId || !config.appId) {
44
66
  throw new Error("Zubbl SDK not initialized");
45
67
  }
46
68
  if (!external_user_id) throw new Error("external_user_id is required");
47
69
 
48
- const headers = {
49
- Authorization: `Bearer ${config.apiKey}`,
50
- "X-Tenant-Id": config.tenantId,
51
- "X-App-Id": config.appId
52
- };
53
-
54
70
  try {
71
+ const headers = {
72
+ Authorization: `Bearer ${config.apiKey}`,
73
+ "X-Tenant-Id": config.tenantId,
74
+ "X-App-Id": config.appId
75
+ };
76
+
55
77
  const response = await axios.get(
56
- `https://api.zubbl.com/sdk/external-users/${external_user_id}/tiles`,
78
+ `${config.baseUrl}/sdk/external-users/${external_user_id}/tiles`, // ✅ Now dynamic
57
79
  { headers }
58
80
  );
81
+
59
82
  console.log("[ZUBBL SDK] getTiles response:", response.data);
60
- return response.data; // <- This is your final, merged tile set for the user
83
+ return response.data;
61
84
  } catch (err) {
62
- console.error("[ZUBBL SDK] getTiles error:", err.response?.data || err);
85
+ if (err.response && err.response.data) {
86
+ console.error("[ZUBBL SDK] getTiles error:", err.response.data);
87
+ throw err.response.data;
88
+ }
89
+ console.error("[ZUBBL SDK] getTiles error:", err);
63
90
  throw err;
64
91
  }
65
92
  }
@@ -7,63 +7,90 @@
7
7
  let config = {
8
8
  apiKey: null,
9
9
  tenantId: null,
10
- appId: null
10
+ appId: null,
11
+ baseUrl: "https://api.zubbl.com/api" // ✅ Default to Worker-routed path
11
12
  };
12
13
 
13
- function init({ apiKey, tenantId, appId }) {
14
+ /**
15
+ * Initialize SDK with API credentials.
16
+ */
17
+ function init({ apiKey, tenantId, appId, baseUrl }) {
14
18
  if (!apiKey || !tenantId || !appId) {
15
19
  throw new Error("apiKey, tenantId, and appId are required");
16
20
  }
17
- config = { apiKey, tenantId, appId };
21
+ config = {
22
+ apiKey,
23
+ tenantId,
24
+ appId,
25
+ baseUrl: baseUrl || "https://api.zubbl.com/api" // ✅ Override if provided
26
+ };
18
27
  }
19
28
 
29
+ /**
30
+ * Identify a user by email (and optional name).
31
+ * Returns user info including external_user_id.
32
+ */
20
33
  async function identifyUser({ email, name }) {
21
34
  if (!config.apiKey || !config.tenantId || !config.appId) {
22
35
  throw new Error("Zubbl SDK not initialized");
23
36
  }
24
37
  if (!email) throw new Error("email is required");
25
38
 
26
- const headers = {
27
- Authorization: `Bearer ${config.apiKey}`,
28
- "X-Tenant-Id": config.tenantId,
29
- "X-App-Id": config.appId
30
- };
31
-
32
39
  try {
40
+ const headers = {
41
+ Authorization: `Bearer ${config.apiKey}`,
42
+ "X-Tenant-Id": config.tenantId,
43
+ "X-App-Id": config.appId,
44
+ "Content-Type": "application/json"
45
+ };
46
+
33
47
  const response = await axios.post(
34
- "https://api.zubbl.com/sdk/identify",
48
+ `${config.baseUrl}/sdk/identify`, // ✅ Now dynamic
35
49
  { email, name },
36
50
  { headers }
37
51
  );
52
+
38
53
  console.log("[ZUBBL SDK] identifyUser response:", response.data);
39
54
  return response.data;
40
55
  } catch (err) {
41
- console.error("[ZUBBL SDK] identifyUser error:", err.response?.data || err);
56
+ if (err.response && err.response.data) {
57
+ console.error("[ZUBBL SDK] identifyUser error:", err.response.data);
58
+ throw err.response.data;
59
+ }
60
+ console.error("[ZUBBL SDK] identifyUser error:", err);
42
61
  throw err;
43
62
  }
44
63
  }
45
64
 
65
+ /**
66
+ * Get tiles for a user using their external_user_id.
67
+ */
46
68
  async function getTiles({ external_user_id }) {
47
69
  if (!config.apiKey || !config.tenantId || !config.appId) {
48
70
  throw new Error("Zubbl SDK not initialized");
49
71
  }
50
72
  if (!external_user_id) throw new Error("external_user_id is required");
51
73
 
52
- const headers = {
53
- Authorization: `Bearer ${config.apiKey}`,
54
- "X-Tenant-Id": config.tenantId,
55
- "X-App-Id": config.appId
56
- };
57
-
58
74
  try {
75
+ const headers = {
76
+ Authorization: `Bearer ${config.apiKey}`,
77
+ "X-Tenant-Id": config.tenantId,
78
+ "X-App-Id": config.appId
79
+ };
80
+
59
81
  const response = await axios.get(
60
- `https://api.zubbl.com/sdk/external-users/${external_user_id}/tiles`,
82
+ `${config.baseUrl}/sdk/external-users/${external_user_id}/tiles`, // ✅ Now dynamic
61
83
  { headers }
62
84
  );
85
+
63
86
  console.log("[ZUBBL SDK] getTiles response:", response.data);
64
- return response.data; // <- This is your final, merged tile set for the user
87
+ return response.data;
65
88
  } catch (err) {
66
- console.error("[ZUBBL SDK] getTiles error:", err.response?.data || err);
89
+ if (err.response && err.response.data) {
90
+ console.error("[ZUBBL SDK] getTiles error:", err.response.data);
91
+ throw err.response.data;
92
+ }
93
+ console.error("[ZUBBL SDK] getTiles error:", err);
67
94
  throw err;
68
95
  }
69
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zubbl-sdk",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Zubbl SDK for secure policy enforcement (browser, Node, universal)",
5
5
  "main": "dist/zubbl-sdk.cjs.js",
6
6
  "module": "dist/zubbl-sdk.esm.js",