@liveblocks/node 0.17.7 → 0.17.10-debug
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/.built-by-link-script +1 -0
- package/index.d.ts +27 -23
- package/index.js +74 -42
- package/index.mjs +1 -73
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3c5960010a08dcf5656b81aadaa675064d528167
|
package/index.d.ts
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
declare type AuthorizeOptions = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
+
* It can also be used to generate a token that gives access to a private room where the userId is configured in the room accesses
|
|
13
|
+
*/
|
|
14
|
+
userId?: string;
|
|
15
|
+
/**
|
|
16
|
+
* 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
|
|
17
|
+
*/
|
|
18
|
+
userInfo?: unknown;
|
|
19
|
+
/**
|
|
20
|
+
* The ids of the groups to which the user belongs. It should be used to generate a token that gives access to a private room and at least one of the group is configured in the room accesses.
|
|
21
|
+
*/
|
|
22
|
+
groupIds?: string[];
|
|
18
23
|
};
|
|
19
24
|
declare type AuthorizeResponse = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
status: number;
|
|
26
|
+
body: string;
|
|
27
|
+
error?: Error;
|
|
23
28
|
};
|
|
24
29
|
/**
|
|
25
30
|
* @example
|
|
@@ -34,13 +39,12 @@ declare type AuthorizeResponse = {
|
|
|
34
39
|
* userId: "123", // Optional
|
|
35
40
|
* userInfo: { // Optional
|
|
36
41
|
* name: "Ada Lovelace"
|
|
37
|
-
* }
|
|
42
|
+
* },
|
|
43
|
+
* groupIds: ["group1"] // Optional
|
|
38
44
|
* });
|
|
39
45
|
* return res.status(response.status).end(response.body);
|
|
40
46
|
* }
|
|
41
47
|
*/
|
|
42
|
-
declare function authorize(
|
|
43
|
-
options: AuthorizeOptions
|
|
44
|
-
): Promise<AuthorizeResponse>;
|
|
48
|
+
declare function authorize(options: AuthorizeOptions): Promise<AuthorizeResponse>;
|
|
45
49
|
|
|
46
50
|
export { authorize };
|
package/index.js
CHANGED
|
@@ -1,45 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
}),
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
33
8
|
}
|
|
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
9
|
};
|
|
44
|
-
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
45
20
|
};
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
var _nodefetch = require('node-fetch'); var _nodefetch2 = _interopRequireDefault(_nodefetch);
|
|
24
|
+
function authorize(options) {
|
|
25
|
+
return __async(this, null, function* () {
|
|
26
|
+
try {
|
|
27
|
+
const { room, secret, userId, userInfo, groupIds } = options;
|
|
28
|
+
if (!(typeof room === "string" && room.length > 0)) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
"Invalid room. Please provide a non-empty string as the room. For more information: https://liveblocks.io/docs/api-reference/liveblocks-node#authorize"
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const result = yield _nodefetch2.default.call(void 0,
|
|
34
|
+
buildLiveblocksAuthorizeEndpoint(options, room),
|
|
35
|
+
{
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: {
|
|
38
|
+
Authorization: `Bearer ${secret}`,
|
|
39
|
+
"Content-Type": "application/json"
|
|
40
|
+
},
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
userId,
|
|
43
|
+
userInfo,
|
|
44
|
+
groupIds
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
if (!result.ok) {
|
|
49
|
+
return {
|
|
50
|
+
status: 403,
|
|
51
|
+
body: yield result.text()
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
status: 200,
|
|
56
|
+
body: yield result.text()
|
|
57
|
+
};
|
|
58
|
+
} catch (er) {
|
|
59
|
+
return {
|
|
60
|
+
status: 403,
|
|
61
|
+
body: 'Call to "https://api.liveblocks.io/v2/rooms/:roomId/authorize" failed. See "error" for more information.',
|
|
62
|
+
error: er
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function buildLiveblocksAuthorizeEndpoint(options, roomId) {
|
|
68
|
+
if (options.liveblocksAuthorizeEndpoint) {
|
|
69
|
+
return options.liveblocksAuthorizeEndpoint.replace("{roomId}", roomId);
|
|
70
|
+
}
|
|
71
|
+
return `https://api.liveblocks.io/v2/rooms/${encodeURIComponent(
|
|
72
|
+
roomId
|
|
73
|
+
)}/authorize`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
exports.authorize = authorize;
|
package/index.mjs
CHANGED
|
@@ -1,73 +1 @@
|
|
|
1
|
-
|
|
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 };
|
|
1
|
+
export { authorize } from "./index.js";
|