zubbl-sdk 1.1.7 → 1.1.8

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.
@@ -37,6 +37,7 @@ function init({
37
37
 
38
38
  /**
39
39
  * Identify a user by email (and optional name).
40
+ * Backend will return or generate a valid UUID for external_user_id.
40
41
  */
41
42
  async function identifyUser({ email, name }) {
42
43
  if (!config.apiKey || !config.tenantId || !config.appId) {
@@ -60,15 +61,37 @@ async function identifyUser({ email, name }) {
60
61
  { email, name },
61
62
  { headers }
62
63
  );
64
+
65
+ const { external_user_id } = response.data;
66
+ if (!external_user_id) {
67
+ throw new Error("Backend did not return external_user_id");
68
+ }
69
+
70
+ // ✅ Ensure UUID format
71
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
72
+ if (!uuidRegex.test(external_user_id)) {
73
+ throw new Error(`Invalid external_user_id received: ${external_user_id}`);
74
+ }
75
+
63
76
  return response.data;
64
77
  }
65
78
 
79
+ /**
80
+ * Fetch effective tiles for a given user.
81
+ * Requires valid external_user_id (UUID).
82
+ */
66
83
  async function getTiles({ external_user_id, app_id = null }) {
67
84
  if (!config.apiKey || !config.tenantId || !config.appId) {
68
85
  throw new Error("Zubbl SDK not initialized");
69
86
  }
70
87
  if (!external_user_id) throw new Error("external_user_id is required");
71
88
 
89
+ // ✅ Validate UUID format
90
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
91
+ if (!uuidRegex.test(external_user_id)) {
92
+ throw new Error(`Invalid external_user_id: ${external_user_id}. Must be UUID.`);
93
+ }
94
+
72
95
  const headers = {
73
96
  Authorization: `Bearer ${config.apiKey}`,
74
97
  "X-Tenant-Id": config.tenantId,
@@ -80,9 +103,7 @@ async function getTiles({ external_user_id, app_id = null }) {
80
103
  headers["X-Zubbl-Internal-Call"] = "true";
81
104
  }
82
105
 
83
- // Use API endpoint for "effective" tile rules!
84
106
  const params = new URLSearchParams({ external_user_id });
85
- // Use explicit app_id if passed (or config default)
86
107
  params.set("app_id", app_id || config.appId);
87
108
 
88
109
  const response = await axios.get(
@@ -35,6 +35,7 @@ function init({
35
35
 
36
36
  /**
37
37
  * Identify a user by email (and optional name).
38
+ * Backend will return or generate a valid UUID for external_user_id.
38
39
  */
39
40
  async function identifyUser({ email, name }) {
40
41
  if (!config.apiKey || !config.tenantId || !config.appId) {
@@ -58,15 +59,37 @@ async function identifyUser({ email, name }) {
58
59
  { email, name },
59
60
  { headers }
60
61
  );
62
+
63
+ const { external_user_id } = response.data;
64
+ if (!external_user_id) {
65
+ throw new Error("Backend did not return external_user_id");
66
+ }
67
+
68
+ // ✅ Ensure UUID format
69
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
70
+ if (!uuidRegex.test(external_user_id)) {
71
+ throw new Error(`Invalid external_user_id received: ${external_user_id}`);
72
+ }
73
+
61
74
  return response.data;
62
75
  }
63
76
 
77
+ /**
78
+ * Fetch effective tiles for a given user.
79
+ * Requires valid external_user_id (UUID).
80
+ */
64
81
  async function getTiles({ external_user_id, app_id = null }) {
65
82
  if (!config.apiKey || !config.tenantId || !config.appId) {
66
83
  throw new Error("Zubbl SDK not initialized");
67
84
  }
68
85
  if (!external_user_id) throw new Error("external_user_id is required");
69
86
 
87
+ // ✅ Validate UUID format
88
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
89
+ if (!uuidRegex.test(external_user_id)) {
90
+ throw new Error(`Invalid external_user_id: ${external_user_id}. Must be UUID.`);
91
+ }
92
+
70
93
  const headers = {
71
94
  Authorization: `Bearer ${config.apiKey}`,
72
95
  "X-Tenant-Id": config.tenantId,
@@ -78,9 +101,7 @@ async function getTiles({ external_user_id, app_id = null }) {
78
101
  headers["X-Zubbl-Internal-Call"] = "true";
79
102
  }
80
103
 
81
- // Use API endpoint for "effective" tile rules!
82
104
  const params = new URLSearchParams({ external_user_id });
83
- // Use explicit app_id if passed (or config default)
84
105
  params.set("app_id", app_id || config.appId);
85
106
 
86
107
  const response = await axios.get(
@@ -39,6 +39,7 @@
39
39
 
40
40
  /**
41
41
  * Identify a user by email (and optional name).
42
+ * Backend will return or generate a valid UUID for external_user_id.
42
43
  */
43
44
  async function identifyUser({ email, name }) {
44
45
  if (!config.apiKey || !config.tenantId || !config.appId) {
@@ -62,15 +63,37 @@
62
63
  { email, name },
63
64
  { headers }
64
65
  );
66
+
67
+ const { external_user_id } = response.data;
68
+ if (!external_user_id) {
69
+ throw new Error("Backend did not return external_user_id");
70
+ }
71
+
72
+ // ✅ Ensure UUID format
73
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
74
+ if (!uuidRegex.test(external_user_id)) {
75
+ throw new Error(`Invalid external_user_id received: ${external_user_id}`);
76
+ }
77
+
65
78
  return response.data;
66
79
  }
67
80
 
81
+ /**
82
+ * Fetch effective tiles for a given user.
83
+ * Requires valid external_user_id (UUID).
84
+ */
68
85
  async function getTiles({ external_user_id, app_id = null }) {
69
86
  if (!config.apiKey || !config.tenantId || !config.appId) {
70
87
  throw new Error("Zubbl SDK not initialized");
71
88
  }
72
89
  if (!external_user_id) throw new Error("external_user_id is required");
73
90
 
91
+ // ✅ Validate UUID format
92
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
93
+ if (!uuidRegex.test(external_user_id)) {
94
+ throw new Error(`Invalid external_user_id: ${external_user_id}. Must be UUID.`);
95
+ }
96
+
74
97
  const headers = {
75
98
  Authorization: `Bearer ${config.apiKey}`,
76
99
  "X-Tenant-Id": config.tenantId,
@@ -82,9 +105,7 @@
82
105
  headers["X-Zubbl-Internal-Call"] = "true";
83
106
  }
84
107
 
85
- // Use API endpoint for "effective" tile rules!
86
108
  const params = new URLSearchParams({ external_user_id });
87
- // Use explicit app_id if passed (or config default)
88
109
  params.set("app_id", app_id || config.appId);
89
110
 
90
111
  const response = await axios.get(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zubbl-sdk",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
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",