@liveblocks/node 0.17.10-debug2 → 0.17.11-debug2

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.
@@ -1 +1 @@
1
- 3c5960010a08dcf5656b81aadaa675064d528167
1
+ 8c91e8cffaa3ee7a68d5153d2a43582c8113f747
package/index.mjs CHANGED
@@ -1 +1,77 @@
1
- export { authorize } from "./index.js";
1
+ 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);
8
+ }
9
+ };
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
+ });
20
+ };
21
+
22
+ // src/index.ts
23
+ import fetch from "node-fetch";
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 fetch(
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
+ export {
76
+ authorize
77
+ };
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "@liveblocks/node",
3
- "version": "0.17.10-debug2",
3
+ "version": "0.17.11-debug2",
4
4
  "description": "A server-side utility that lets you set up a Liveblocks authentication endpoint.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
7
7
  "types": "./index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./index.js",
11
+ "import": "./index.mjs",
12
+ "types": "./index.d.ts"
13
+ }
14
+ },
8
15
  "keywords": [
9
16
  "node",
10
17
  "liveblocks",