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