@liveblocks/node 1.0.8 → 1.0.10
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/index.d.ts +33 -7
- package/dist/index.js +26 -22
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,25 +2,47 @@ import { IncomingHttpHeaders } from 'http';
|
|
|
2
2
|
|
|
3
3
|
declare type AuthorizeOptions = {
|
|
4
4
|
/**
|
|
5
|
-
* The secret
|
|
5
|
+
* The secret API key for your Liveblocks account. You can find it on
|
|
6
|
+
* https://liveblocks.io/dashboard/apikeys
|
|
6
7
|
*/
|
|
7
8
|
secret: string;
|
|
8
9
|
/**
|
|
9
|
-
* The room
|
|
10
|
+
* The room ID for which to authorize the user. This will authorize the user
|
|
11
|
+
* to enter the Liveblocks room.
|
|
10
12
|
*/
|
|
11
13
|
room: string;
|
|
12
14
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* Associates a user ID to the session that is being authorized. The user ID
|
|
16
|
+
* is typically set to the user ID from your own database.
|
|
17
|
+
*
|
|
18
|
+
* It can also be used to generate a token that gives access to a private
|
|
19
|
+
* room where the userId is configured in the room accesses.
|
|
20
|
+
*
|
|
21
|
+
* This user ID will be used as the unique identifier to compute your
|
|
22
|
+
* Liveblocks account's Monthly Active Users.
|
|
16
23
|
*/
|
|
17
24
|
userId: string;
|
|
18
25
|
/**
|
|
19
|
-
*
|
|
26
|
+
* Arbitrary metadata associated to this user session.
|
|
27
|
+
*
|
|
28
|
+
* You can use it to store a small amount of static metadata for a user
|
|
29
|
+
* session. It is public information, that will be visible to other users in
|
|
30
|
+
* the same room, like name, avatar URL, etc.
|
|
31
|
+
*
|
|
32
|
+
* It's only suitable for static info that won't change during a session. If
|
|
33
|
+
* you want to store dynamic metadata on a user session, don't keep that in
|
|
34
|
+
* the session token, but use Presence instead.
|
|
35
|
+
*
|
|
36
|
+
* Can't exceed 1KB when serialized as JSON.
|
|
20
37
|
*/
|
|
21
38
|
userInfo?: unknown;
|
|
22
39
|
/**
|
|
23
|
-
*
|
|
40
|
+
* Tell Liveblocks which group IDs this user belongs to. This will authorize
|
|
41
|
+
* the user session to access private rooms that have at least one of these
|
|
42
|
+
* group IDs listed in their room access configuration.
|
|
43
|
+
*
|
|
44
|
+
* See https://liveblocks.io/docs/guides/managing-rooms-users-permissions#permissions
|
|
45
|
+
* for how to configure your room's permissions to use this feature.
|
|
24
46
|
*/
|
|
25
47
|
groupIds?: string[];
|
|
26
48
|
};
|
|
@@ -30,6 +52,10 @@ declare type AuthorizeResponse = {
|
|
|
30
52
|
error?: Error;
|
|
31
53
|
};
|
|
32
54
|
/**
|
|
55
|
+
* Tells Liveblocks that a user should be allowed access to a room, which user
|
|
56
|
+
* this session is for, and what metadata to associate with the user (like
|
|
57
|
+
* name, avatar, etc.)
|
|
58
|
+
*
|
|
33
59
|
* @example
|
|
34
60
|
* export default async function auth(req, res) {
|
|
35
61
|
*
|
package/dist/index.js
CHANGED
|
@@ -35,34 +35,38 @@ function authorize(options) {
|
|
|
35
35
|
"Invalid userId. Please provide a non-empty string as the userId. For more information: https://liveblocks.io/docs/api-reference/liveblocks-node#authorize"
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
const resp = yield _nodefetch2.default.call(void 0, buildLiveblocksAuthorizeEndpoint(options, room), {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `Bearer ${secret}`,
|
|
42
|
+
"Content-Type": "application/json"
|
|
43
|
+
},
|
|
44
|
+
body: JSON.stringify({
|
|
45
|
+
userId,
|
|
46
|
+
userInfo,
|
|
47
|
+
groupIds
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
if (resp.ok) {
|
|
51
|
+
return {
|
|
52
|
+
status: 200,
|
|
53
|
+
body: yield resp.text()
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (resp.status >= 500) {
|
|
57
|
+
return {
|
|
58
|
+
status: 503,
|
|
59
|
+
body: yield resp.text()
|
|
60
|
+
};
|
|
61
|
+
} else {
|
|
54
62
|
return {
|
|
55
63
|
status: 403,
|
|
56
|
-
body: yield
|
|
64
|
+
body: yield resp.text()
|
|
57
65
|
};
|
|
58
66
|
}
|
|
59
|
-
return {
|
|
60
|
-
status: 200,
|
|
61
|
-
body: yield result.text()
|
|
62
|
-
};
|
|
63
67
|
} catch (er) {
|
|
64
68
|
return {
|
|
65
|
-
status:
|
|
69
|
+
status: 503,
|
|
66
70
|
body: 'Call to "https://api.liveblocks.io/v2/rooms/:roomId/authorize" failed. See "error" for more information.',
|
|
67
71
|
error: er
|
|
68
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/node",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A server-side utility that lets you set up a Liveblocks authentication endpoint. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|