zubbl-sdk 1.0.0
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/README.md +34 -0
- package/dist/zubbl-sdk.cjs.js +39 -0
- package/dist/zubbl-sdk.esm.js +37 -0
- package/dist/zubbl-sdk.umd.js +45 -0
- package/package.json +33 -0
- package/src/index.d.ts +15 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Zubbl SDK
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
\`\`\`sh
|
|
6
|
+
npm install zubbl-sdk
|
|
7
|
+
# OR
|
|
8
|
+
yarn add zubbl-sdk
|
|
9
|
+
\`\`\`
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
\`\`\`js
|
|
14
|
+
import zubblSdk from "zubbl-sdk";
|
|
15
|
+
|
|
16
|
+
zubblSdk.init({ apiKey: "zubbl_sk_live_xxx" });
|
|
17
|
+
|
|
18
|
+
// After user login
|
|
19
|
+
await zubblSdk.identifyUser({
|
|
20
|
+
external_user_id: user.id,
|
|
21
|
+
email: user.email,
|
|
22
|
+
name: user.name
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const tiles = await zubblSdk.getTiles({ external_user_id: user.id });
|
|
26
|
+
console.log(tiles);
|
|
27
|
+
\`\`\`
|
|
28
|
+
|
|
29
|
+
> **NOTE:** Always call \`init({ apiKey })\` first.
|
|
30
|
+
> Never expose your API key in client/browser code for public apps.
|
|
31
|
+
|
|
32
|
+
## Docs
|
|
33
|
+
|
|
34
|
+
See https://docs.zubbl.com/sdk for full integration, migration, and troubleshooting.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let _apiKey = null;
|
|
4
|
+
|
|
5
|
+
function init({ apiKey }) {
|
|
6
|
+
if (!apiKey) throw new Error("API key required for Zubbl SDK");
|
|
7
|
+
_apiKey = apiKey;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function identifyUser({ external_user_id, email, name }) {
|
|
11
|
+
if (!_apiKey) throw new Error("Call init({ apiKey }) before using SDK methods!");
|
|
12
|
+
if (!external_user_id) throw new Error("external_user_id is required");
|
|
13
|
+
const res = await fetch("https://api.zubbl.com/sdk/identify/" + external_user_id, {
|
|
14
|
+
method: "POST",
|
|
15
|
+
headers: {
|
|
16
|
+
"Authorization": `Bearer ${_apiKey}`,
|
|
17
|
+
"Content-Type": "application/json"
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify({ email, name })
|
|
20
|
+
});
|
|
21
|
+
if (!res.ok) throw new Error(`Identify failed: ${res.status}`);
|
|
22
|
+
return res.json();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function getTiles({ external_user_id }) {
|
|
26
|
+
if (!_apiKey) throw new Error("Call init({ apiKey }) before using SDK methods!");
|
|
27
|
+
if (!external_user_id) throw new Error("external_user_id is required");
|
|
28
|
+
const res = await fetch("https://api.zubbl.com/sdk/external-users/" + external_user_id + "/tiles", {
|
|
29
|
+
headers: {
|
|
30
|
+
"Authorization": `Bearer ${_apiKey}`
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
if (!res.ok) throw new Error(`getTiles failed: ${res.status}`);
|
|
34
|
+
return res.json();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var index = { init, identifyUser, getTiles };
|
|
38
|
+
|
|
39
|
+
module.exports = index;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
let _apiKey = null;
|
|
2
|
+
|
|
3
|
+
function init({ apiKey }) {
|
|
4
|
+
if (!apiKey) throw new Error("API key required for Zubbl SDK");
|
|
5
|
+
_apiKey = apiKey;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async function identifyUser({ external_user_id, email, name }) {
|
|
9
|
+
if (!_apiKey) throw new Error("Call init({ apiKey }) before using SDK methods!");
|
|
10
|
+
if (!external_user_id) throw new Error("external_user_id is required");
|
|
11
|
+
const res = await fetch("https://api.zubbl.com/sdk/identify/" + external_user_id, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: {
|
|
14
|
+
"Authorization": `Bearer ${_apiKey}`,
|
|
15
|
+
"Content-Type": "application/json"
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify({ email, name })
|
|
18
|
+
});
|
|
19
|
+
if (!res.ok) throw new Error(`Identify failed: ${res.status}`);
|
|
20
|
+
return res.json();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function getTiles({ external_user_id }) {
|
|
24
|
+
if (!_apiKey) throw new Error("Call init({ apiKey }) before using SDK methods!");
|
|
25
|
+
if (!external_user_id) throw new Error("external_user_id is required");
|
|
26
|
+
const res = await fetch("https://api.zubbl.com/sdk/external-users/" + external_user_id + "/tiles", {
|
|
27
|
+
headers: {
|
|
28
|
+
"Authorization": `Bearer ${_apiKey}`
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
if (!res.ok) throw new Error(`getTiles failed: ${res.status}`);
|
|
32
|
+
return res.json();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var index = { init, identifyUser, getTiles };
|
|
36
|
+
|
|
37
|
+
export { index as default };
|
|
@@ -0,0 +1,45 @@
|
|
|
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';
|
|
6
|
+
|
|
7
|
+
let _apiKey = null;
|
|
8
|
+
|
|
9
|
+
function init({ apiKey }) {
|
|
10
|
+
if (!apiKey) throw new Error("API key required for Zubbl SDK");
|
|
11
|
+
_apiKey = apiKey;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function identifyUser({ external_user_id, email, name }) {
|
|
15
|
+
if (!_apiKey) throw new Error("Call init({ apiKey }) before using SDK methods!");
|
|
16
|
+
if (!external_user_id) throw new Error("external_user_id is required");
|
|
17
|
+
const res = await fetch("https://api.zubbl.com/sdk/identify/" + external_user_id, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
"Authorization": `Bearer ${_apiKey}`,
|
|
21
|
+
"Content-Type": "application/json"
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({ email, name })
|
|
24
|
+
});
|
|
25
|
+
if (!res.ok) throw new Error(`Identify failed: ${res.status}`);
|
|
26
|
+
return res.json();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function getTiles({ external_user_id }) {
|
|
30
|
+
if (!_apiKey) throw new Error("Call init({ apiKey }) before using SDK methods!");
|
|
31
|
+
if (!external_user_id) throw new Error("external_user_id is required");
|
|
32
|
+
const res = await fetch("https://api.zubbl.com/sdk/external-users/" + external_user_id + "/tiles", {
|
|
33
|
+
headers: {
|
|
34
|
+
"Authorization": `Bearer ${_apiKey}`
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (!res.ok) throw new Error(`getTiles failed: ${res.status}`);
|
|
38
|
+
return res.json();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var index = { init, identifyUser, getTiles };
|
|
42
|
+
|
|
43
|
+
return index;
|
|
44
|
+
|
|
45
|
+
}));
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zubbl-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Zubbl SDK for secure policy enforcement (browser, Node, universal)",
|
|
5
|
+
"main": "dist/zubbl-sdk.cjs.js",
|
|
6
|
+
"module": "dist/zubbl-sdk.esm.js",
|
|
7
|
+
"browser": "dist/zubbl-sdk.umd.js",
|
|
8
|
+
"types": "src/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/zubbl-sdk.esm.js",
|
|
12
|
+
"require": "./dist/zubbl-sdk.cjs.js",
|
|
13
|
+
"browser": "./dist/zubbl-sdk.umd.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src/index.d.ts",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rollup -c",
|
|
23
|
+
"prepublishOnly": "npm run build",
|
|
24
|
+
"test": "echo 'Add tests!'"
|
|
25
|
+
},
|
|
26
|
+
"repository": "https://github.com/zubbl/zubbl-sdk",
|
|
27
|
+
"author": "Zubbl",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
31
|
+
"rollup": "^4.2.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface IdentifyUserParams {
|
|
2
|
+
external_user_id: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface Tile {
|
|
8
|
+
tile_name: string;
|
|
9
|
+
rule_data: any;
|
|
10
|
+
scope: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
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[] }>;
|