zubbl-sdk 1.1.4 → 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,30 +44,23 @@ 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
  /**
@@ -69,28 +72,22 @@ async function getTiles({ external_user_id }) {
69
72
  }
70
73
  if (!external_user_id) throw new Error("external_user_id is required");
71
74
 
72
- try {
73
- const headers = {
74
- Authorization: `Bearer ${config.apiKey}`,
75
- "X-Tenant-Id": config.tenantId,
76
- "X-App-Id": config.appId
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;
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";
93
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;
94
91
  }
95
92
 
96
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,30 +42,23 @@ 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
  /**
@@ -67,28 +70,22 @@ async function getTiles({ external_user_id }) {
67
70
  }
68
71
  if (!external_user_id) throw new Error("external_user_id is required");
69
72
 
70
- try {
71
- const headers = {
72
- Authorization: `Bearer ${config.apiKey}`,
73
- "X-Tenant-Id": config.tenantId,
74
- "X-App-Id": config.appId
75
- };
76
-
77
- const response = await axios.get(
78
- `${config.baseUrl}/sdk/external-users/${external_user_id}/tiles`, // Now dynamic
79
- { headers }
80
- );
81
-
82
- console.log("[ZUBBL SDK] getTiles response:", response.data);
83
- return response.data;
84
- } catch (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);
90
- 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";
91
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;
92
89
  }
93
90
 
94
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,30 +46,23 @@
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
  /**
@@ -71,28 +74,22 @@
71
74
  }
72
75
  if (!external_user_id) throw new Error("external_user_id is required");
73
76
 
74
- try {
75
- const headers = {
76
- Authorization: `Bearer ${config.apiKey}`,
77
- "X-Tenant-Id": config.tenantId,
78
- "X-App-Id": config.appId
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;
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";
95
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;
96
93
  }
97
94
 
98
95
  exports.getTiles = getTiles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zubbl-sdk",
3
- "version": "1.1.4",
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",