@liveblocks/node 0.2.0 → 0.17.1-beta1
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 +51 -0
- package/index.d.ts +46 -0
- package/index.js +45 -0
- package/index.mjs +73 -0
- package/package.json +44 -15
- package/lib/cjs/index.d.ts +0 -16
- package/lib/cjs/index.js +0 -50
- package/lib/esm/index.d.ts +0 -16
- package/lib/esm/index.js +0 -43
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://liveblocks.io">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/liveblocks/liveblocks/main/.github/assets/header.svg" alt="Liveblocks" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
# `@liveblocks/node`
|
|
8
|
+
|
|
9
|
+
<p>
|
|
10
|
+
<a href="https://npmjs.org/package/@liveblocks/node">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/@liveblocks/node?style=flat&label=npm&color=c33" alt="NPM" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://bundlephobia.com/package/@liveblocks/node">
|
|
14
|
+
<img src="https://img.shields.io/bundlephobia/minzip/@liveblocks/node?style=flat&label=size&color=09f" alt="Size" />
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://github.com/liveblocks/liveblocks/blob/main/LICENSE">
|
|
17
|
+
<img src="https://img.shields.io/github/license/liveblocks/liveblocks?style=flat&label=license&color=f80" alt="License" />
|
|
18
|
+
</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
A server-side utility that lets you set up a [Liveblocks](https://liveblocks.io) authentication endpoint.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
npm install @liveblocks/node
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Examples
|
|
30
|
+
|
|
31
|
+
- Browse our gallery of collaborative UI patterns. [View examples gallery](https://liveblocks.io/examples)
|
|
32
|
+
- Explore and clone any of our open-source examples. [View code examples](https://github.com/liveblocks/liveblocks/tree/main/examples)
|
|
33
|
+
|
|
34
|
+
## Documentation
|
|
35
|
+
|
|
36
|
+
[Read the documentation](https://liveblocks.io/docs) to start using Liveblocks.
|
|
37
|
+
|
|
38
|
+
## Releases
|
|
39
|
+
|
|
40
|
+
For changelog, visit [https://github.com/liveblocks/liveblocks/releases](https://github.com/liveblocks/liveblocks/releases).
|
|
41
|
+
|
|
42
|
+
## Community
|
|
43
|
+
|
|
44
|
+
- [Discord](https://discord.gg/X4YWJuH9VY) - To get involved with the Liveblocks community, ask questions and share tips.
|
|
45
|
+
- [Twitter](https://twitter.com/liveblocks) - To receive updates, announcements, blog posts, and general Liveblocks tips.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
Licensed under the Apache License 2.0, Copyright © 2021-present [Liveblocks](https://liveblocks.io).
|
|
50
|
+
|
|
51
|
+
See [LICENSE](../../LICENSE) for more information.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
declare type AuthorizeOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* The secret api provided at https://liveblocks.io/dashboard/apikeys
|
|
4
|
+
*/
|
|
5
|
+
secret: string;
|
|
6
|
+
/**
|
|
7
|
+
* The room provided in the authorization request body
|
|
8
|
+
*/
|
|
9
|
+
room: string;
|
|
10
|
+
/**
|
|
11
|
+
* The id of the user that try to connect. It should be used to get information about the connected users in the room (name, avatar, etc).
|
|
12
|
+
*/
|
|
13
|
+
userId?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The info associated to the user. Can be used to store the name or the profile picture to implement avatar for example. Can't exceed 1KB when serialized as JSON
|
|
16
|
+
*/
|
|
17
|
+
userInfo?: unknown;
|
|
18
|
+
};
|
|
19
|
+
declare type AuthorizeResponse = {
|
|
20
|
+
status: number;
|
|
21
|
+
body: string;
|
|
22
|
+
error?: Error;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @example
|
|
26
|
+
* export default async function auth(req, res) {
|
|
27
|
+
*
|
|
28
|
+
* // Implement your own security here.
|
|
29
|
+
*
|
|
30
|
+
* const room = req.body.room;
|
|
31
|
+
* const response = await authorize({
|
|
32
|
+
* room,
|
|
33
|
+
* secret,
|
|
34
|
+
* userId: "123", // Optional
|
|
35
|
+
* userInfo: { // Optional
|
|
36
|
+
* name: "Ada Lovelace"
|
|
37
|
+
* }
|
|
38
|
+
* });
|
|
39
|
+
* return res.status(response.status).end(response.body);
|
|
40
|
+
* }
|
|
41
|
+
*/
|
|
42
|
+
declare function authorize(
|
|
43
|
+
options: AuthorizeOptions
|
|
44
|
+
): Promise<AuthorizeResponse>;
|
|
45
|
+
|
|
46
|
+
export { authorize };
|
package/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _interopDefaultLegacy(e) {
|
|
3
|
+
return e && "object" == typeof e && "default" in e ? e : { default: e };
|
|
4
|
+
}
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
6
|
+
var fetch__default = _interopDefaultLegacy(require("node-fetch"));
|
|
7
|
+
exports.authorize = async function (options) {
|
|
8
|
+
try {
|
|
9
|
+
const {
|
|
10
|
+
room: room,
|
|
11
|
+
secret: secret,
|
|
12
|
+
userId: userId,
|
|
13
|
+
userInfo: userInfo,
|
|
14
|
+
} = options;
|
|
15
|
+
if (!("string" == typeof room && room.length > 0))
|
|
16
|
+
throw new Error(
|
|
17
|
+
"Invalid room. Please provide a non-empty string as the room. For more information: https://liveblocks.io/docs/api-reference/liveblocks-node#authorize"
|
|
18
|
+
);
|
|
19
|
+
const result = await fetch__default.default(
|
|
20
|
+
options.liveblocksAuthorizeEndpoint ||
|
|
21
|
+
"https://liveblocks.io/api/authorize",
|
|
22
|
+
{
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: {
|
|
25
|
+
Authorization: `Bearer: ${secret}`,
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
},
|
|
28
|
+
body: JSON.stringify({
|
|
29
|
+
room: room,
|
|
30
|
+
userId: userId,
|
|
31
|
+
userInfo: userInfo,
|
|
32
|
+
}),
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
return result.ok
|
|
36
|
+
? { status: 200, body: await result.text() }
|
|
37
|
+
: { status: 403, body: await result.text() };
|
|
38
|
+
} catch (er) {
|
|
39
|
+
return {
|
|
40
|
+
status: 403,
|
|
41
|
+
body: 'Call to "https://liveblocks.io/api/authorize" failed. See "error" for more information.',
|
|
42
|
+
error: er,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
};
|
package/index.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fetch from "node-fetch";
|
|
2
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) {
|
|
5
|
+
try {
|
|
6
|
+
step(generator.next(value));
|
|
7
|
+
} catch (e) {
|
|
8
|
+
reject(e);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function rejected(value) {
|
|
12
|
+
try {
|
|
13
|
+
step(generator.throw(value));
|
|
14
|
+
} catch (e) {
|
|
15
|
+
reject(e);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function step(result) {
|
|
19
|
+
var value;
|
|
20
|
+
result.done
|
|
21
|
+
? resolve(result.value)
|
|
22
|
+
: ((value = result.value),
|
|
23
|
+
value instanceof P
|
|
24
|
+
? value
|
|
25
|
+
: new P(function (resolve) {
|
|
26
|
+
resolve(value);
|
|
27
|
+
})).then(fulfilled, rejected);
|
|
28
|
+
}
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function authorize(options) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
try {
|
|
35
|
+
const {
|
|
36
|
+
room: room,
|
|
37
|
+
secret: secret,
|
|
38
|
+
userId: userId,
|
|
39
|
+
userInfo: userInfo,
|
|
40
|
+
} = options;
|
|
41
|
+
if (!("string" == typeof room && room.length > 0))
|
|
42
|
+
throw new Error(
|
|
43
|
+
"Invalid room. Please provide a non-empty string as the room. For more information: https://liveblocks.io/docs/api-reference/liveblocks-node#authorize"
|
|
44
|
+
);
|
|
45
|
+
const result = yield fetch(
|
|
46
|
+
options.liveblocksAuthorizeEndpoint ||
|
|
47
|
+
"https://liveblocks.io/api/authorize",
|
|
48
|
+
{
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
Authorization: `Bearer: ${secret}`,
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
room: room,
|
|
56
|
+
userId: userId,
|
|
57
|
+
userInfo: userInfo,
|
|
58
|
+
}),
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
return result.ok
|
|
62
|
+
? { status: 200, body: yield result.text() }
|
|
63
|
+
: { status: 403, body: yield result.text() };
|
|
64
|
+
} catch (er) {
|
|
65
|
+
return {
|
|
66
|
+
status: 403,
|
|
67
|
+
body: 'Call to "https://liveblocks.io/api/authorize" failed. See "error" for more information.',
|
|
68
|
+
error: er,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export { authorize };
|
package/package.json
CHANGED
|
@@ -1,31 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/node",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./
|
|
6
|
-
"module": "./
|
|
3
|
+
"version": "0.17.1-beta1",
|
|
4
|
+
"description": "A server-side utility that lets you set up a Liveblocks authentication endpoint.",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"module": "./index.mjs",
|
|
7
|
+
"types": "./index.d.ts",
|
|
7
8
|
"files": [
|
|
8
|
-
"
|
|
9
|
+
"**"
|
|
9
10
|
],
|
|
11
|
+
"keywords": [
|
|
12
|
+
"node",
|
|
13
|
+
"liveblocks",
|
|
14
|
+
"multiplayer",
|
|
15
|
+
"live-cursors",
|
|
16
|
+
"collaborative"
|
|
17
|
+
],
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/liveblocks/liveblocks/issues"
|
|
20
|
+
},
|
|
10
21
|
"scripts": {
|
|
11
|
-
"build
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"test": "jest --
|
|
22
|
+
"build": "rollup -c && cp ./package.json ./README.md ./lib",
|
|
23
|
+
"format": "eslint --fix src/ && prettier --write src/",
|
|
24
|
+
"lint": "eslint src/",
|
|
25
|
+
"test": "jest --watch --silent --verbose",
|
|
26
|
+
"test-ci": "jest --silent --verbose --passWithNoTests"
|
|
16
27
|
},
|
|
17
|
-
"license": "
|
|
28
|
+
"license": "Apache-2.0",
|
|
18
29
|
"devDependencies": {
|
|
19
|
-
"@babel/core": "^7.
|
|
20
|
-
"@babel/preset-env": "^7.
|
|
21
|
-
"@babel/preset-typescript": "^7.
|
|
30
|
+
"@babel/core": "^7.17.10",
|
|
31
|
+
"@babel/preset-env": "^7.17.10",
|
|
32
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
33
|
+
"@rollup/plugin-babel": "^5.3.1",
|
|
34
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
35
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
36
|
+
"@rollup/plugin-typescript": "^8.3.3",
|
|
22
37
|
"@types/jest": "^26.0.21",
|
|
23
38
|
"@types/node-fetch": "^2.5.8",
|
|
24
|
-
"
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
40
|
+
"@typescript-eslint/parser": "^5.18.0",
|
|
41
|
+
"eslint": "^8.12.0",
|
|
42
|
+
"eslint-plugin-import": "^2.26.0",
|
|
43
|
+
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
25
44
|
"jest": "^26.6.3",
|
|
45
|
+
"rollup": "^2.75.7",
|
|
46
|
+
"rollup-plugin-command": "^1.1.3",
|
|
47
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
48
|
+
"rollup-plugin-prettier": "^2.2.2",
|
|
49
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
26
50
|
"typescript": "^4.1.5"
|
|
27
51
|
},
|
|
28
52
|
"dependencies": {
|
|
29
53
|
"node-fetch": "^2.6.1"
|
|
54
|
+
},
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/liveblocks/liveblocks.git",
|
|
58
|
+
"directory": "packages/liveblocks-node"
|
|
30
59
|
}
|
|
31
60
|
}
|
package/lib/cjs/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare type AuthorizeOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* The secret api provided at https://liveblocks.io/dashboard/apikeys
|
|
4
|
-
*/
|
|
5
|
-
secret: string;
|
|
6
|
-
/**
|
|
7
|
-
* The room provided in the authorization request body
|
|
8
|
-
*/
|
|
9
|
-
room: string;
|
|
10
|
-
};
|
|
11
|
-
declare type AuthorizeResponse = {
|
|
12
|
-
status: number;
|
|
13
|
-
body: string;
|
|
14
|
-
};
|
|
15
|
-
export declare function authorize(options: AuthorizeOptions): Promise<AuthorizeResponse>;
|
|
16
|
-
export {};
|
package/lib/cjs/index.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.authorize = void 0;
|
|
16
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
17
|
-
function authorize(options) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
try {
|
|
20
|
-
const result = yield node_fetch_1.default(options.liveblocksAuthorizeEndpoint ||
|
|
21
|
-
"https://liveblocks.io/api/authorize", {
|
|
22
|
-
method: "POST",
|
|
23
|
-
headers: {
|
|
24
|
-
Authorization: `Bearer: ${options.secret}`,
|
|
25
|
-
"Content-Type": "application/json",
|
|
26
|
-
},
|
|
27
|
-
body: JSON.stringify({
|
|
28
|
-
room: options.room,
|
|
29
|
-
}),
|
|
30
|
-
});
|
|
31
|
-
if (!result.ok) {
|
|
32
|
-
return {
|
|
33
|
-
status: 403,
|
|
34
|
-
body: "",
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
status: 200,
|
|
39
|
-
body: yield result.text(),
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
catch (er) {
|
|
43
|
-
return {
|
|
44
|
-
status: 403,
|
|
45
|
-
body: "",
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
exports.authorize = authorize;
|
package/lib/esm/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare type AuthorizeOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* The secret api provided at https://liveblocks.io/dashboard/apikeys
|
|
4
|
-
*/
|
|
5
|
-
secret: string;
|
|
6
|
-
/**
|
|
7
|
-
* The room provided in the authorization request body
|
|
8
|
-
*/
|
|
9
|
-
room: string;
|
|
10
|
-
};
|
|
11
|
-
declare type AuthorizeResponse = {
|
|
12
|
-
status: number;
|
|
13
|
-
body: string;
|
|
14
|
-
};
|
|
15
|
-
export declare function authorize(options: AuthorizeOptions): Promise<AuthorizeResponse>;
|
|
16
|
-
export {};
|
package/lib/esm/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import fetch from "node-fetch";
|
|
11
|
-
export function authorize(options) {
|
|
12
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
try {
|
|
14
|
-
const result = yield fetch(options.liveblocksAuthorizeEndpoint ||
|
|
15
|
-
"https://liveblocks.io/api/authorize", {
|
|
16
|
-
method: "POST",
|
|
17
|
-
headers: {
|
|
18
|
-
Authorization: `Bearer: ${options.secret}`,
|
|
19
|
-
"Content-Type": "application/json",
|
|
20
|
-
},
|
|
21
|
-
body: JSON.stringify({
|
|
22
|
-
room: options.room,
|
|
23
|
-
}),
|
|
24
|
-
});
|
|
25
|
-
if (!result.ok) {
|
|
26
|
-
return {
|
|
27
|
-
status: 403,
|
|
28
|
-
body: "",
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
status: 200,
|
|
33
|
-
body: yield result.text(),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
catch (er) {
|
|
37
|
-
return {
|
|
38
|
-
status: 403,
|
|
39
|
-
body: "",
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|