zubbl-sdk 1.0.0 → 1.0.2
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 +55 -20
- package/dist/zubbl-sdk.esm.js +55 -20
- package/dist/zubbl-sdk.umd.js +57 -24
- package/package.json +4 -1
- package/src/index.d.ts +24 -10
package/dist/zubbl-sdk.cjs.js
CHANGED
|
@@ -1,39 +1,74 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var axios = require('axios');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
let config = {
|
|
6
|
+
apiKey: "",
|
|
7
|
+
tenantId: "",
|
|
8
|
+
appId: "",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
function init({ apiKey, tenantId, appId }) {
|
|
12
|
+
config = { apiKey, tenantId, appId };
|
|
8
13
|
}
|
|
9
14
|
|
|
10
|
-
async function identifyUser({
|
|
11
|
-
if (!
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
async function identifyUser({ email, name }) {
|
|
16
|
+
if (!email) throw new Error("email is required");
|
|
17
|
+
const res = await axios.post("https://api.zubbl.com/user/identify", {
|
|
18
|
+
email,
|
|
19
|
+
name,
|
|
20
|
+
}, {
|
|
15
21
|
headers: {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
22
|
+
"x-api-key": config.apiKey,
|
|
23
|
+
"x-tenant-id": config.tenantId,
|
|
24
|
+
"x-app-id": config.appId,
|
|
18
25
|
},
|
|
19
|
-
body: JSON.stringify({ email, name })
|
|
20
26
|
});
|
|
21
|
-
|
|
22
|
-
return res.json();
|
|
27
|
+
return res.data;
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
async function getTiles({ external_user_id }) {
|
|
26
|
-
if (!_apiKey) throw new Error("Call init({ apiKey }) before using SDK methods!");
|
|
27
31
|
if (!external_user_id) throw new Error("external_user_id is required");
|
|
28
|
-
const res = await
|
|
32
|
+
const res = await axios.get("https://api.zubbl.com/tiles", {
|
|
29
33
|
headers: {
|
|
30
|
-
"
|
|
34
|
+
"x-api-key": config.apiKey,
|
|
35
|
+
"x-tenant-id": config.tenantId,
|
|
36
|
+
"x-app-id": config.appId,
|
|
37
|
+
"x-user-id": external_user_id,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
return res.data;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function attachRoutes(app) {
|
|
44
|
+
app.post("/identify", async (req, res) => {
|
|
45
|
+
try {
|
|
46
|
+
const { email, name } = req.body;
|
|
47
|
+
if (!email) return res.status(400).json({ error: "email required" });
|
|
48
|
+
const user = await identifyUser({ email, name });
|
|
49
|
+
res.json(user);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
res.status(500).json({ error: e.message });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
app.post("/tiles", async (req, res) => {
|
|
56
|
+
try {
|
|
57
|
+
const { external_user_id } = req.body;
|
|
58
|
+
if (!external_user_id) return res.status(400).json({ error: "external_user_id required" });
|
|
59
|
+
const tiles = await getTiles({ external_user_id });
|
|
60
|
+
res.json(tiles);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
res.status(500).json({ error: e.message });
|
|
31
63
|
}
|
|
32
64
|
});
|
|
33
|
-
if (!res.ok) throw new Error(`getTiles failed: ${res.status}`);
|
|
34
|
-
return res.json();
|
|
35
65
|
}
|
|
36
66
|
|
|
37
|
-
var index = {
|
|
67
|
+
var index = {
|
|
68
|
+
init,
|
|
69
|
+
identifyUser,
|
|
70
|
+
getTiles,
|
|
71
|
+
attachRoutes,
|
|
72
|
+
};
|
|
38
73
|
|
|
39
74
|
module.exports = index;
|
package/dist/zubbl-sdk.esm.js
CHANGED
|
@@ -1,37 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
import axios from 'axios';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
let config = {
|
|
4
|
+
apiKey: "",
|
|
5
|
+
tenantId: "",
|
|
6
|
+
appId: "",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function init({ apiKey, tenantId, appId }) {
|
|
10
|
+
config = { apiKey, tenantId, appId };
|
|
6
11
|
}
|
|
7
12
|
|
|
8
|
-
async function identifyUser({
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
async function identifyUser({ email, name }) {
|
|
14
|
+
if (!email) throw new Error("email is required");
|
|
15
|
+
const res = await axios.post("https://api.zubbl.com/user/identify", {
|
|
16
|
+
email,
|
|
17
|
+
name,
|
|
18
|
+
}, {
|
|
13
19
|
headers: {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
20
|
+
"x-api-key": config.apiKey,
|
|
21
|
+
"x-tenant-id": config.tenantId,
|
|
22
|
+
"x-app-id": config.appId,
|
|
16
23
|
},
|
|
17
|
-
body: JSON.stringify({ email, name })
|
|
18
24
|
});
|
|
19
|
-
|
|
20
|
-
return res.json();
|
|
25
|
+
return res.data;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
async function getTiles({ external_user_id }) {
|
|
24
|
-
if (!_apiKey) throw new Error("Call init({ apiKey }) before using SDK methods!");
|
|
25
29
|
if (!external_user_id) throw new Error("external_user_id is required");
|
|
26
|
-
const res = await
|
|
30
|
+
const res = await axios.get("https://api.zubbl.com/tiles", {
|
|
27
31
|
headers: {
|
|
28
|
-
"
|
|
32
|
+
"x-api-key": config.apiKey,
|
|
33
|
+
"x-tenant-id": config.tenantId,
|
|
34
|
+
"x-app-id": config.appId,
|
|
35
|
+
"x-user-id": external_user_id,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return res.data;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function attachRoutes(app) {
|
|
42
|
+
app.post("/identify", async (req, res) => {
|
|
43
|
+
try {
|
|
44
|
+
const { email, name } = req.body;
|
|
45
|
+
if (!email) return res.status(400).json({ error: "email required" });
|
|
46
|
+
const user = await identifyUser({ email, name });
|
|
47
|
+
res.json(user);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
res.status(500).json({ error: e.message });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
app.post("/tiles", async (req, res) => {
|
|
54
|
+
try {
|
|
55
|
+
const { external_user_id } = req.body;
|
|
56
|
+
if (!external_user_id) return res.status(400).json({ error: "external_user_id required" });
|
|
57
|
+
const tiles = await getTiles({ external_user_id });
|
|
58
|
+
res.json(tiles);
|
|
59
|
+
} catch (e) {
|
|
60
|
+
res.status(500).json({ error: e.message });
|
|
29
61
|
}
|
|
30
62
|
});
|
|
31
|
-
if (!res.ok) throw new Error(`getTiles failed: ${res.status}`);
|
|
32
|
-
return res.json();
|
|
33
63
|
}
|
|
34
64
|
|
|
35
|
-
var index = {
|
|
65
|
+
var index = {
|
|
66
|
+
init,
|
|
67
|
+
identifyUser,
|
|
68
|
+
getTiles,
|
|
69
|
+
attachRoutes,
|
|
70
|
+
};
|
|
36
71
|
|
|
37
72
|
export { index as default };
|
package/dist/zubbl-sdk.umd.js
CHANGED
|
@@ -1,44 +1,77 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ZubblSdk = factory());
|
|
5
|
-
})(this, (function () { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('axios')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['axios'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ZubblSdk = factory(global.axios));
|
|
5
|
+
})(this, (function (axios) { 'use strict';
|
|
6
6
|
|
|
7
|
-
let
|
|
7
|
+
let config = {
|
|
8
|
+
apiKey: "",
|
|
9
|
+
tenantId: "",
|
|
10
|
+
appId: "",
|
|
11
|
+
};
|
|
8
12
|
|
|
9
|
-
function init({ apiKey }) {
|
|
10
|
-
|
|
11
|
-
_apiKey = apiKey;
|
|
13
|
+
function init({ apiKey, tenantId, appId }) {
|
|
14
|
+
config = { apiKey, tenantId, appId };
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
async function identifyUser({
|
|
15
|
-
if (!
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
async function identifyUser({ email, name }) {
|
|
18
|
+
if (!email) throw new Error("email is required");
|
|
19
|
+
const res = await axios.post("https://api.zubbl.com/user/identify", {
|
|
20
|
+
email,
|
|
21
|
+
name,
|
|
22
|
+
}, {
|
|
19
23
|
headers: {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
24
|
+
"x-api-key": config.apiKey,
|
|
25
|
+
"x-tenant-id": config.tenantId,
|
|
26
|
+
"x-app-id": config.appId,
|
|
22
27
|
},
|
|
23
|
-
body: JSON.stringify({ email, name })
|
|
24
28
|
});
|
|
25
|
-
|
|
26
|
-
return res.json();
|
|
29
|
+
return res.data;
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
async function getTiles({ external_user_id }) {
|
|
30
|
-
if (!_apiKey) throw new Error("Call init({ apiKey }) before using SDK methods!");
|
|
31
33
|
if (!external_user_id) throw new Error("external_user_id is required");
|
|
32
|
-
const res = await
|
|
34
|
+
const res = await axios.get("https://api.zubbl.com/tiles", {
|
|
33
35
|
headers: {
|
|
34
|
-
"
|
|
36
|
+
"x-api-key": config.apiKey,
|
|
37
|
+
"x-tenant-id": config.tenantId,
|
|
38
|
+
"x-app-id": config.appId,
|
|
39
|
+
"x-user-id": external_user_id,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
return res.data;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function attachRoutes(app) {
|
|
46
|
+
app.post("/identify", async (req, res) => {
|
|
47
|
+
try {
|
|
48
|
+
const { email, name } = req.body;
|
|
49
|
+
if (!email) return res.status(400).json({ error: "email required" });
|
|
50
|
+
const user = await identifyUser({ email, name });
|
|
51
|
+
res.json(user);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
res.status(500).json({ error: e.message });
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
app.post("/tiles", async (req, res) => {
|
|
58
|
+
try {
|
|
59
|
+
const { external_user_id } = req.body;
|
|
60
|
+
if (!external_user_id) return res.status(400).json({ error: "external_user_id required" });
|
|
61
|
+
const tiles = await getTiles({ external_user_id });
|
|
62
|
+
res.json(tiles);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
res.status(500).json({ error: e.message });
|
|
35
65
|
}
|
|
36
66
|
});
|
|
37
|
-
if (!res.ok) throw new Error(`getTiles failed: ${res.status}`);
|
|
38
|
-
return res.json();
|
|
39
67
|
}
|
|
40
68
|
|
|
41
|
-
var index = {
|
|
69
|
+
var index = {
|
|
70
|
+
init,
|
|
71
|
+
identifyUser,
|
|
72
|
+
getTiles,
|
|
73
|
+
attachRoutes,
|
|
74
|
+
};
|
|
42
75
|
|
|
43
76
|
return index;
|
|
44
77
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zubbl-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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,29 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export interface ZubblConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
tenantId: string;
|
|
4
|
+
appId: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface IdentifyParams {
|
|
8
|
+
email: string;
|
|
4
9
|
name?: string;
|
|
5
10
|
}
|
|
6
11
|
|
|
7
|
-
export interface
|
|
8
|
-
|
|
9
|
-
rule_data: any;
|
|
10
|
-
scope: string;
|
|
12
|
+
export interface TileParams {
|
|
13
|
+
external_user_id: string;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
|
-
export function init(
|
|
14
|
-
export function identifyUser(params:
|
|
15
|
-
export function getTiles(params:
|
|
16
|
+
export function init(config: ZubblConfig): void;
|
|
17
|
+
export function identifyUser(params: IdentifyParams): Promise<any>;
|
|
18
|
+
export function getTiles(params: TileParams): Promise<any>;
|
|
19
|
+
export function attachRoutes(app: any): void;
|
|
20
|
+
|
|
21
|
+
declare const zubblSdk: {
|
|
22
|
+
init: typeof init;
|
|
23
|
+
identifyUser: typeof identifyUser;
|
|
24
|
+
getTiles: typeof getTiles;
|
|
25
|
+
attachRoutes: typeof attachRoutes;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default zubblSdk;
|
|
29
|
+
|