zubbl-sdk 1.1.2 → 1.1.3

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