zubbl-sdk 1.1.8 → 1.1.9

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.
@@ -112,7 +112,40 @@ async function getTiles({ external_user_id, app_id = null }) {
112
112
  );
113
113
  return response.data;
114
114
  }
115
+ async function enforce({ external_user_id, app_id = null }) {
116
+ if (!config.apiKey || !config.tenantId || !config.appId) {
117
+ throw new Error("Zubbl SDK not initialized");
118
+ }
119
+ if (!external_user_id) throw new Error("external_user_id is required");
120
+
121
+ const headers = {
122
+ Authorization: `Bearer ${config.apiKey}`,
123
+ "X-Tenant-Id": config.tenantId,
124
+ "X-App-Id": app_id || config.appId,
125
+ "X-External-User-Id": external_user_id,
126
+ "Content-Type": "application/json",
127
+ };
128
+ if (config.injectWorkerHeaders && config.workerSecret) {
129
+ headers["X-Zubbl-Worker-Secret"] = config.workerSecret;
130
+ headers["X-Zubbl-Internal-Call"] = "true";
131
+ }
132
+
133
+ try {
134
+ const resp = await axios.post(
135
+ `${config.baseUrl.replace(/\/$/, "")}/sdk/test-enforcement`,
136
+ {},
137
+ { headers }
138
+ );
139
+ return { decision: "allow", status: resp.status, data: resp.data };
140
+ } catch (e) {
141
+ if (e.response && e.response.status === 429) {
142
+ return { decision: "block", status: 429, data: e.response.data };
143
+ }
144
+ throw e;
145
+ }
146
+ }
115
147
 
148
+ exports.enforce = enforce;
116
149
  exports.getTiles = getTiles;
117
150
  exports.identifyUser = identifyUser;
118
151
  exports.init = init;
@@ -110,5 +110,37 @@ async function getTiles({ external_user_id, app_id = null }) {
110
110
  );
111
111
  return response.data;
112
112
  }
113
+ async function enforce({ external_user_id, app_id = null }) {
114
+ if (!config.apiKey || !config.tenantId || !config.appId) {
115
+ throw new Error("Zubbl SDK not initialized");
116
+ }
117
+ if (!external_user_id) throw new Error("external_user_id is required");
118
+
119
+ const headers = {
120
+ Authorization: `Bearer ${config.apiKey}`,
121
+ "X-Tenant-Id": config.tenantId,
122
+ "X-App-Id": app_id || config.appId,
123
+ "X-External-User-Id": external_user_id,
124
+ "Content-Type": "application/json",
125
+ };
126
+ if (config.injectWorkerHeaders && config.workerSecret) {
127
+ headers["X-Zubbl-Worker-Secret"] = config.workerSecret;
128
+ headers["X-Zubbl-Internal-Call"] = "true";
129
+ }
130
+
131
+ try {
132
+ const resp = await axios.post(
133
+ `${config.baseUrl.replace(/\/$/, "")}/sdk/test-enforcement`,
134
+ {},
135
+ { headers }
136
+ );
137
+ return { decision: "allow", status: resp.status, data: resp.data };
138
+ } catch (e) {
139
+ if (e.response && e.response.status === 429) {
140
+ return { decision: "block", status: 429, data: e.response.data };
141
+ }
142
+ throw e;
143
+ }
144
+ }
113
145
 
114
- export { getTiles, identifyUser, init };
146
+ export { enforce, getTiles, identifyUser, init };
@@ -114,7 +114,40 @@
114
114
  );
115
115
  return response.data;
116
116
  }
117
+ async function enforce({ external_user_id, app_id = null }) {
118
+ if (!config.apiKey || !config.tenantId || !config.appId) {
119
+ throw new Error("Zubbl SDK not initialized");
120
+ }
121
+ if (!external_user_id) throw new Error("external_user_id is required");
122
+
123
+ const headers = {
124
+ Authorization: `Bearer ${config.apiKey}`,
125
+ "X-Tenant-Id": config.tenantId,
126
+ "X-App-Id": app_id || config.appId,
127
+ "X-External-User-Id": external_user_id,
128
+ "Content-Type": "application/json",
129
+ };
130
+ if (config.injectWorkerHeaders && config.workerSecret) {
131
+ headers["X-Zubbl-Worker-Secret"] = config.workerSecret;
132
+ headers["X-Zubbl-Internal-Call"] = "true";
133
+ }
134
+
135
+ try {
136
+ const resp = await axios.post(
137
+ `${config.baseUrl.replace(/\/$/, "")}/sdk/test-enforcement`,
138
+ {},
139
+ { headers }
140
+ );
141
+ return { decision: "allow", status: resp.status, data: resp.data };
142
+ } catch (e) {
143
+ if (e.response && e.response.status === 429) {
144
+ return { decision: "block", status: 429, data: e.response.data };
145
+ }
146
+ throw e;
147
+ }
148
+ }
117
149
 
150
+ exports.enforce = enforce;
118
151
  exports.getTiles = getTiles;
119
152
  exports.identifyUser = identifyUser;
120
153
  exports.init = init;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zubbl-sdk",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
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",