zubbl-sdk 1.0.0 → 1.0.1
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.
- package/dist/zubbl-sdk.cjs.js +46 -8
- package/dist/zubbl-sdk.esm.js +46 -8
- package/dist/zubbl-sdk.umd.js +46 -8
- package/package.json +4 -1
- package/src/index.d.ts +49 -12
package/dist/zubbl-sdk.cjs.js
CHANGED
|
@@ -1,19 +1,54 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// index.js
|
|
4
|
+
|
|
3
5
|
let _apiKey = null;
|
|
6
|
+
let _tenantId = null;
|
|
7
|
+
let _appId = null;
|
|
4
8
|
|
|
5
|
-
function init({ apiKey }) {
|
|
9
|
+
function init({ apiKey, tenantId, appId }) {
|
|
6
10
|
if (!apiKey) throw new Error("API key required for Zubbl SDK");
|
|
11
|
+
if (!tenantId) throw new Error("tenantId required for Zubbl SDK");
|
|
12
|
+
if (!appId) throw new Error("appId required for Zubbl SDK");
|
|
7
13
|
_apiKey = apiKey;
|
|
14
|
+
_tenantId = tenantId;
|
|
15
|
+
_appId = appId;
|
|
8
16
|
}
|
|
9
17
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
/**
|
|
19
|
+
* identifyUser({ email, name, external_user_id? })
|
|
20
|
+
* - If external_user_id present, legacy fast path.
|
|
21
|
+
* - If not, POST to /sdk/identify with {email, name} (backend creates or returns user).
|
|
22
|
+
* Always includes X-Tenant-ID and X-App-ID headers.
|
|
23
|
+
*/
|
|
24
|
+
async function identifyUser({ email, name, external_user_id }) {
|
|
25
|
+
if (!_apiKey || !_tenantId || !_appId)
|
|
26
|
+
throw new Error("Call init({ apiKey, tenantId, appId }) before using SDK methods!");
|
|
27
|
+
|
|
28
|
+
// Fast path if ext ID provided (legacy)
|
|
29
|
+
if (external_user_id) {
|
|
30
|
+
const res = await fetch(`https://api.zubbl.com/sdk/identify/${external_user_id}`, {
|
|
31
|
+
method: "POST",
|
|
32
|
+
headers: {
|
|
33
|
+
"Authorization": `Bearer ${_apiKey}`,
|
|
34
|
+
"X-Tenant-ID": _tenantId,
|
|
35
|
+
"X-App-ID": _appId,
|
|
36
|
+
"Content-Type": "application/json"
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify({ email, name })
|
|
39
|
+
});
|
|
40
|
+
if (!res.ok) throw new Error(`Identify failed: ${res.status}`);
|
|
41
|
+
return res.json();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Modern plug-and-play: only email/name
|
|
45
|
+
if (!email) throw new Error("email is required");
|
|
46
|
+
const res = await fetch("https://api.zubbl.com/sdk/identify", {
|
|
14
47
|
method: "POST",
|
|
15
48
|
headers: {
|
|
16
49
|
"Authorization": `Bearer ${_apiKey}`,
|
|
50
|
+
"X-Tenant-ID": _tenantId,
|
|
51
|
+
"X-App-ID": _appId,
|
|
17
52
|
"Content-Type": "application/json"
|
|
18
53
|
},
|
|
19
54
|
body: JSON.stringify({ email, name })
|
|
@@ -23,11 +58,14 @@ async function identifyUser({ external_user_id, email, name }) {
|
|
|
23
58
|
}
|
|
24
59
|
|
|
25
60
|
async function getTiles({ external_user_id }) {
|
|
26
|
-
if (!_apiKey
|
|
61
|
+
if (!_apiKey || !_tenantId || !_appId)
|
|
62
|
+
throw new Error("Call init({ apiKey, tenantId, appId }) before using SDK methods!");
|
|
27
63
|
if (!external_user_id) throw new Error("external_user_id is required");
|
|
28
|
-
const res = await fetch(
|
|
64
|
+
const res = await fetch(`https://api.zubbl.com/sdk/external-users/${external_user_id}/tiles`, {
|
|
29
65
|
headers: {
|
|
30
|
-
"Authorization": `Bearer ${_apiKey}
|
|
66
|
+
"Authorization": `Bearer ${_apiKey}`,
|
|
67
|
+
"X-Tenant-ID": _tenantId,
|
|
68
|
+
"X-App-ID": _appId
|
|
31
69
|
}
|
|
32
70
|
});
|
|
33
71
|
if (!res.ok) throw new Error(`getTiles failed: ${res.status}`);
|
package/dist/zubbl-sdk.esm.js
CHANGED
|
@@ -1,17 +1,52 @@
|
|
|
1
|
+
// index.js
|
|
2
|
+
|
|
1
3
|
let _apiKey = null;
|
|
4
|
+
let _tenantId = null;
|
|
5
|
+
let _appId = null;
|
|
2
6
|
|
|
3
|
-
function init({ apiKey }) {
|
|
7
|
+
function init({ apiKey, tenantId, appId }) {
|
|
4
8
|
if (!apiKey) throw new Error("API key required for Zubbl SDK");
|
|
9
|
+
if (!tenantId) throw new Error("tenantId required for Zubbl SDK");
|
|
10
|
+
if (!appId) throw new Error("appId required for Zubbl SDK");
|
|
5
11
|
_apiKey = apiKey;
|
|
12
|
+
_tenantId = tenantId;
|
|
13
|
+
_appId = appId;
|
|
6
14
|
}
|
|
7
15
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
/**
|
|
17
|
+
* identifyUser({ email, name, external_user_id? })
|
|
18
|
+
* - If external_user_id present, legacy fast path.
|
|
19
|
+
* - If not, POST to /sdk/identify with {email, name} (backend creates or returns user).
|
|
20
|
+
* Always includes X-Tenant-ID and X-App-ID headers.
|
|
21
|
+
*/
|
|
22
|
+
async function identifyUser({ email, name, external_user_id }) {
|
|
23
|
+
if (!_apiKey || !_tenantId || !_appId)
|
|
24
|
+
throw new Error("Call init({ apiKey, tenantId, appId }) before using SDK methods!");
|
|
25
|
+
|
|
26
|
+
// Fast path if ext ID provided (legacy)
|
|
27
|
+
if (external_user_id) {
|
|
28
|
+
const res = await fetch(`https://api.zubbl.com/sdk/identify/${external_user_id}`, {
|
|
29
|
+
method: "POST",
|
|
30
|
+
headers: {
|
|
31
|
+
"Authorization": `Bearer ${_apiKey}`,
|
|
32
|
+
"X-Tenant-ID": _tenantId,
|
|
33
|
+
"X-App-ID": _appId,
|
|
34
|
+
"Content-Type": "application/json"
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify({ email, name })
|
|
37
|
+
});
|
|
38
|
+
if (!res.ok) throw new Error(`Identify failed: ${res.status}`);
|
|
39
|
+
return res.json();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Modern plug-and-play: only email/name
|
|
43
|
+
if (!email) throw new Error("email is required");
|
|
44
|
+
const res = await fetch("https://api.zubbl.com/sdk/identify", {
|
|
12
45
|
method: "POST",
|
|
13
46
|
headers: {
|
|
14
47
|
"Authorization": `Bearer ${_apiKey}`,
|
|
48
|
+
"X-Tenant-ID": _tenantId,
|
|
49
|
+
"X-App-ID": _appId,
|
|
15
50
|
"Content-Type": "application/json"
|
|
16
51
|
},
|
|
17
52
|
body: JSON.stringify({ email, name })
|
|
@@ -21,11 +56,14 @@ async function identifyUser({ external_user_id, email, name }) {
|
|
|
21
56
|
}
|
|
22
57
|
|
|
23
58
|
async function getTiles({ external_user_id }) {
|
|
24
|
-
if (!_apiKey
|
|
59
|
+
if (!_apiKey || !_tenantId || !_appId)
|
|
60
|
+
throw new Error("Call init({ apiKey, tenantId, appId }) before using SDK methods!");
|
|
25
61
|
if (!external_user_id) throw new Error("external_user_id is required");
|
|
26
|
-
const res = await fetch(
|
|
62
|
+
const res = await fetch(`https://api.zubbl.com/sdk/external-users/${external_user_id}/tiles`, {
|
|
27
63
|
headers: {
|
|
28
|
-
"Authorization": `Bearer ${_apiKey}
|
|
64
|
+
"Authorization": `Bearer ${_apiKey}`,
|
|
65
|
+
"X-Tenant-ID": _tenantId,
|
|
66
|
+
"X-App-ID": _appId
|
|
29
67
|
}
|
|
30
68
|
});
|
|
31
69
|
if (!res.ok) throw new Error(`getTiles failed: ${res.status}`);
|
package/dist/zubbl-sdk.umd.js
CHANGED
|
@@ -4,20 +4,55 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ZubblSdk = factory());
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
|
+
// index.js
|
|
8
|
+
|
|
7
9
|
let _apiKey = null;
|
|
10
|
+
let _tenantId = null;
|
|
11
|
+
let _appId = null;
|
|
8
12
|
|
|
9
|
-
function init({ apiKey }) {
|
|
13
|
+
function init({ apiKey, tenantId, appId }) {
|
|
10
14
|
if (!apiKey) throw new Error("API key required for Zubbl SDK");
|
|
15
|
+
if (!tenantId) throw new Error("tenantId required for Zubbl SDK");
|
|
16
|
+
if (!appId) throw new Error("appId required for Zubbl SDK");
|
|
11
17
|
_apiKey = apiKey;
|
|
18
|
+
_tenantId = tenantId;
|
|
19
|
+
_appId = appId;
|
|
12
20
|
}
|
|
13
21
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
/**
|
|
23
|
+
* identifyUser({ email, name, external_user_id? })
|
|
24
|
+
* - If external_user_id present, legacy fast path.
|
|
25
|
+
* - If not, POST to /sdk/identify with {email, name} (backend creates or returns user).
|
|
26
|
+
* Always includes X-Tenant-ID and X-App-ID headers.
|
|
27
|
+
*/
|
|
28
|
+
async function identifyUser({ email, name, external_user_id }) {
|
|
29
|
+
if (!_apiKey || !_tenantId || !_appId)
|
|
30
|
+
throw new Error("Call init({ apiKey, tenantId, appId }) before using SDK methods!");
|
|
31
|
+
|
|
32
|
+
// Fast path if ext ID provided (legacy)
|
|
33
|
+
if (external_user_id) {
|
|
34
|
+
const res = await fetch(`https://api.zubbl.com/sdk/identify/${external_user_id}`, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
"Authorization": `Bearer ${_apiKey}`,
|
|
38
|
+
"X-Tenant-ID": _tenantId,
|
|
39
|
+
"X-App-ID": _appId,
|
|
40
|
+
"Content-Type": "application/json"
|
|
41
|
+
},
|
|
42
|
+
body: JSON.stringify({ email, name })
|
|
43
|
+
});
|
|
44
|
+
if (!res.ok) throw new Error(`Identify failed: ${res.status}`);
|
|
45
|
+
return res.json();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Modern plug-and-play: only email/name
|
|
49
|
+
if (!email) throw new Error("email is required");
|
|
50
|
+
const res = await fetch("https://api.zubbl.com/sdk/identify", {
|
|
18
51
|
method: "POST",
|
|
19
52
|
headers: {
|
|
20
53
|
"Authorization": `Bearer ${_apiKey}`,
|
|
54
|
+
"X-Tenant-ID": _tenantId,
|
|
55
|
+
"X-App-ID": _appId,
|
|
21
56
|
"Content-Type": "application/json"
|
|
22
57
|
},
|
|
23
58
|
body: JSON.stringify({ email, name })
|
|
@@ -27,11 +62,14 @@
|
|
|
27
62
|
}
|
|
28
63
|
|
|
29
64
|
async function getTiles({ external_user_id }) {
|
|
30
|
-
if (!_apiKey
|
|
65
|
+
if (!_apiKey || !_tenantId || !_appId)
|
|
66
|
+
throw new Error("Call init({ apiKey, tenantId, appId }) before using SDK methods!");
|
|
31
67
|
if (!external_user_id) throw new Error("external_user_id is required");
|
|
32
|
-
const res = await fetch(
|
|
68
|
+
const res = await fetch(`https://api.zubbl.com/sdk/external-users/${external_user_id}/tiles`, {
|
|
33
69
|
headers: {
|
|
34
|
-
"Authorization": `Bearer ${_apiKey}
|
|
70
|
+
"Authorization": `Bearer ${_apiKey}`,
|
|
71
|
+
"X-Tenant-ID": _tenantId,
|
|
72
|
+
"X-App-ID": _appId
|
|
35
73
|
}
|
|
36
74
|
});
|
|
37
75
|
if (!res.ok) throw new Error(`getTiles failed: ${res.status}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zubbl-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
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",
|
|
@@ -29,5 +29,8 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
31
31
|
"rollup": "^4.2.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"zubbl-sdk": "^1.0.0"
|
|
32
35
|
}
|
|
33
36
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,15 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
declare module "zubbl-sdk" {
|
|
2
|
+
interface ZubblInitOptions {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
tenantId: string;
|
|
5
|
+
appId: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface IdentifyUserParams {
|
|
9
|
+
email: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
external_user_id?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface IdentifyUserResponse {
|
|
15
|
+
external_user_id: string;
|
|
16
|
+
tenant_id: string;
|
|
17
|
+
app_id: string;
|
|
18
|
+
group_name?: string | null;
|
|
19
|
+
created: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface GetTilesParams {
|
|
23
|
+
external_user_id: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Tile {
|
|
27
|
+
tile_name: string;
|
|
28
|
+
rule_data: any;
|
|
29
|
+
scope: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface GetTilesResponse {
|
|
33
|
+
external_user_id: string;
|
|
34
|
+
tenant_id: string;
|
|
35
|
+
app_id: string;
|
|
36
|
+
group_name?: string | null;
|
|
37
|
+
tiles: Tile[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function init(options: ZubblInitOptions): void;
|
|
41
|
+
export function identifyUser(params: IdentifyUserParams): Promise<IdentifyUserResponse>;
|
|
42
|
+
export function getTiles(params: GetTilesParams): Promise<GetTilesResponse>;
|
|
43
|
+
|
|
44
|
+
const _default: {
|
|
45
|
+
init: typeof init;
|
|
46
|
+
identifyUser: typeof identifyUser;
|
|
47
|
+
getTiles: typeof getTiles;
|
|
48
|
+
};
|
|
6
49
|
|
|
7
|
-
export
|
|
8
|
-
tile_name: string;
|
|
9
|
-
rule_data: any;
|
|
10
|
-
scope: string;
|
|
50
|
+
export default _default;
|
|
11
51
|
}
|
|
12
52
|
|
|
13
|
-
export function init(params: { apiKey: string }): void;
|
|
14
|
-
export function identifyUser(params: IdentifyUserParams): Promise<any>;
|
|
15
|
-
export function getTiles(params: { external_user_id: string }): Promise<{ tiles: Tile[] }>;
|