@liveblocks/node 1.8.2 → 1.9.0-example1
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.mts +136 -5
- package/dist/index.d.ts +136 -5
- package/dist/index.js +193 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +193 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { detectDupes } from "@liveblocks/core";
|
|
|
3
3
|
|
|
4
4
|
// src/version.ts
|
|
5
5
|
var PKG_NAME = "@liveblocks/node";
|
|
6
|
-
var PKG_VERSION = "1.
|
|
6
|
+
var PKG_VERSION = "1.9.0-example1";
|
|
7
7
|
var PKG_FORMAT = "esm";
|
|
8
8
|
|
|
9
9
|
// src/utils.ts
|
|
@@ -101,6 +101,13 @@ function buildLiveblocksAuthorizeEndpoint(options, roomId) {
|
|
|
101
101
|
return urljoin(options.baseUrl || DEFAULT_BASE_URL, path);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
// src/client.ts
|
|
105
|
+
import {
|
|
106
|
+
convertToCommentData,
|
|
107
|
+
convertToCommentUserReaction,
|
|
108
|
+
convertToThreadData
|
|
109
|
+
} from "@liveblocks/core";
|
|
110
|
+
|
|
104
111
|
// src/Session.ts
|
|
105
112
|
var ALL_PERMISSIONS = Object.freeze([
|
|
106
113
|
"room:write",
|
|
@@ -281,6 +288,7 @@ var Liveblocks = class {
|
|
|
281
288
|
/** @internal */
|
|
282
289
|
async get(path, params) {
|
|
283
290
|
const url2 = urljoin(this._baseUrl, path, params);
|
|
291
|
+
console.log("url", url2);
|
|
284
292
|
const headers = {
|
|
285
293
|
Authorization: `Bearer ${this._secret}`
|
|
286
294
|
};
|
|
@@ -763,12 +771,17 @@ var Liveblocks = class {
|
|
|
763
771
|
*/
|
|
764
772
|
async getThreads(params) {
|
|
765
773
|
const { roomId } = params;
|
|
766
|
-
const res = await this.get(url`/v2/rooms/${roomId}/threads
|
|
774
|
+
const res = await this.get(url`/v2/rooms/${roomId}/threads`, {
|
|
775
|
+
"metadata.resolved": "false"
|
|
776
|
+
});
|
|
767
777
|
if (!res.ok) {
|
|
768
778
|
const text = await res.text();
|
|
769
779
|
throw new LiveblocksError(res.status, text);
|
|
770
780
|
}
|
|
771
|
-
|
|
781
|
+
const { data } = await res.json();
|
|
782
|
+
return {
|
|
783
|
+
data: data.map((thread) => convertToThreadData(thread))
|
|
784
|
+
};
|
|
772
785
|
}
|
|
773
786
|
/**
|
|
774
787
|
* Gets a thread.
|
|
@@ -784,7 +797,9 @@ var Liveblocks = class {
|
|
|
784
797
|
const text = await res.text();
|
|
785
798
|
throw new LiveblocksError(res.status, text);
|
|
786
799
|
}
|
|
787
|
-
return
|
|
800
|
+
return convertToThreadData(
|
|
801
|
+
await res.json()
|
|
802
|
+
);
|
|
788
803
|
}
|
|
789
804
|
/**
|
|
790
805
|
* Gets a thread's participants.
|
|
@@ -824,8 +839,173 @@ var Liveblocks = class {
|
|
|
824
839
|
const text = await res.text();
|
|
825
840
|
throw new LiveblocksError(res.status, text);
|
|
826
841
|
}
|
|
842
|
+
return convertToCommentData(await res.json());
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Creates a comment.
|
|
846
|
+
*
|
|
847
|
+
* @param params.roomId The room ID to create the comment in.
|
|
848
|
+
* @param params.threadId The thread ID to create the comment in.
|
|
849
|
+
* @param params.data.userId The user ID of the user who is set to create the comment.
|
|
850
|
+
* @param params.data.createdAt (optional) The date the comment is set to be created.
|
|
851
|
+
* @param params.data.body The body of the comment.
|
|
852
|
+
* @returns The created comment.
|
|
853
|
+
*/
|
|
854
|
+
async createComment(params) {
|
|
855
|
+
const { roomId, threadId, data } = params;
|
|
856
|
+
const res = await this.post(
|
|
857
|
+
url`/v2/rooms/${roomId}/threads/${threadId}/comments`,
|
|
858
|
+
{
|
|
859
|
+
...data,
|
|
860
|
+
createdAt: data.createdAt?.toISOString()
|
|
861
|
+
}
|
|
862
|
+
);
|
|
863
|
+
if (!res.ok) {
|
|
864
|
+
const text = await res.text();
|
|
865
|
+
throw new LiveblocksError(res.status, text);
|
|
866
|
+
}
|
|
867
|
+
return convertToCommentData(await res.json());
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Edits a comment.
|
|
871
|
+
* @param params.roomId The room ID to edit the comment in.
|
|
872
|
+
* @param params.threadId The thread ID to edit the comment in.
|
|
873
|
+
* @param params.commentId The comment ID to edit.
|
|
874
|
+
* @param params.data.body The body of the comment.
|
|
875
|
+
* @param params.data.editedAt (optional) The date the comment was edited.
|
|
876
|
+
* @returns The edited comment.
|
|
877
|
+
*/
|
|
878
|
+
async editComment(params) {
|
|
879
|
+
const { roomId, threadId, commentId, data } = params;
|
|
880
|
+
const res = await this.post(
|
|
881
|
+
url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`,
|
|
882
|
+
{
|
|
883
|
+
...data,
|
|
884
|
+
editedAt: data.editedAt?.toISOString()
|
|
885
|
+
}
|
|
886
|
+
);
|
|
887
|
+
if (!res.ok) {
|
|
888
|
+
const text = await res.text();
|
|
889
|
+
throw new LiveblocksError(res.status, text);
|
|
890
|
+
}
|
|
891
|
+
return convertToCommentData(await res.json());
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Deletes a comment. Deletes a comment. If there are no remaining comments in the thread, the thread is also deleted.
|
|
895
|
+
* @param params.roomId The room ID to delete the comment in.
|
|
896
|
+
* @param params.threadId The thread ID to delete the comment in.
|
|
897
|
+
* @param params.commentId The comment ID to delete.
|
|
898
|
+
*/
|
|
899
|
+
async deleteComment(params) {
|
|
900
|
+
const { roomId, threadId, commentId } = params;
|
|
901
|
+
const res = await this.delete(
|
|
902
|
+
url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`
|
|
903
|
+
);
|
|
904
|
+
if (!res.ok) {
|
|
905
|
+
const text = await res.text();
|
|
906
|
+
throw new LiveblocksError(res.status, text);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Creates a new thread. The thread will be created with the specified comment as its first comment.
|
|
911
|
+
* If the thread already exists, a `LiveblocksError` will be thrown with status code 409.
|
|
912
|
+
* @param params.roomId The room ID to create the thread in.
|
|
913
|
+
* @param params.thread.metadata (optional) The metadata for the thread. Supports upto a maximum of 10 entries. Value must be a string, boolean or number
|
|
914
|
+
* @param params.thread.comment.userId The user ID of the user who created the comment.
|
|
915
|
+
* @param params.thread.comment.createdAt (optional) The date the comment was created.
|
|
916
|
+
* @param params.thread.comment.body The body of the comment.
|
|
917
|
+
* @returns The created thread. The thread will be created with the specified comment as its first comment.
|
|
918
|
+
*/
|
|
919
|
+
async createThread(params) {
|
|
920
|
+
const { roomId, data } = params;
|
|
921
|
+
const res = await this.post(url`/v2/rooms/${roomId}/threads`, {
|
|
922
|
+
...data,
|
|
923
|
+
comment: {
|
|
924
|
+
...data.comment,
|
|
925
|
+
createdAt: data.comment.createdAt?.toISOString()
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
if (!res.ok) {
|
|
929
|
+
const text = await res.text();
|
|
930
|
+
throw new LiveblocksError(res.status, text);
|
|
931
|
+
}
|
|
932
|
+
return convertToThreadData(
|
|
933
|
+
await res.json()
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Updates the metadata of the specified thread in a room.
|
|
938
|
+
* @param params.roomId The room ID to update the thread in.
|
|
939
|
+
* @param params.threadId The thread ID to update.
|
|
940
|
+
* @param params.data.metadata The metadata for the thread. Value must be a string, boolean or number
|
|
941
|
+
* @param params.data.userId The user ID of the user who updated the thread.
|
|
942
|
+
* @param params.data.updatedAt (optional) The date the thread is set to be updated.
|
|
943
|
+
* @returns The updated thread.
|
|
944
|
+
*/
|
|
945
|
+
async editThreadMetadata(params) {
|
|
946
|
+
const { roomId, threadId, data } = params;
|
|
947
|
+
const res = await this.post(
|
|
948
|
+
url`/v2/rooms/${roomId}/threads/${threadId}/metadata`,
|
|
949
|
+
{
|
|
950
|
+
...data,
|
|
951
|
+
updatedAt: data.updatedAt?.toISOString()
|
|
952
|
+
}
|
|
953
|
+
);
|
|
954
|
+
if (!res.ok) {
|
|
955
|
+
const text = await res.text();
|
|
956
|
+
throw new LiveblocksError(res.status, text);
|
|
957
|
+
}
|
|
827
958
|
return await res.json();
|
|
828
959
|
}
|
|
960
|
+
/**
|
|
961
|
+
* Adds a new comment reaction to a comment.
|
|
962
|
+
* @param params.roomId The room ID to add the comment reaction in.
|
|
963
|
+
* @param params.threadId The thread ID to add the comment reaction in.
|
|
964
|
+
* @param params.commentId The comment ID to add the reaction in.
|
|
965
|
+
* @param params.data.emoji The (emoji) reaction to add.
|
|
966
|
+
* @param params.data.userId The user ID of the user associated with the reaction.
|
|
967
|
+
* @param params.data.createdAt (optional) The date the reaction is set to be created.
|
|
968
|
+
* @returns The created comment reaction.
|
|
969
|
+
*/
|
|
970
|
+
async addCommentReaction(params) {
|
|
971
|
+
const { roomId, threadId, commentId, data } = params;
|
|
972
|
+
const res = await this.post(
|
|
973
|
+
url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`,
|
|
974
|
+
{
|
|
975
|
+
...data,
|
|
976
|
+
createdAt: data.createdAt?.toISOString()
|
|
977
|
+
}
|
|
978
|
+
);
|
|
979
|
+
if (!res.ok) {
|
|
980
|
+
const text = await res.text();
|
|
981
|
+
throw new LiveblocksError(res.status, text);
|
|
982
|
+
}
|
|
983
|
+
const reaction = await res.json();
|
|
984
|
+
return convertToCommentUserReaction(reaction);
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Removes a reaction from a comment.
|
|
988
|
+
* @param params.roomId The room ID to remove the comment reaction from.
|
|
989
|
+
* @param params.threadId The thread ID to remove the comment reaction from.
|
|
990
|
+
* @param params.commentId The comment ID to remove the reaction from.
|
|
991
|
+
* @param params.data.emoji The (emoji) reaction to remove.
|
|
992
|
+
* @param params.data.userId The user ID of the user associated with the reaction.
|
|
993
|
+
* @param params.data.removedAt (optional) The date the reaction is set to be removed.
|
|
994
|
+
*/
|
|
995
|
+
async removeCommentReaction(params) {
|
|
996
|
+
const { roomId, threadId, data } = params;
|
|
997
|
+
const res = await this.post(
|
|
998
|
+
url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`,
|
|
999
|
+
{
|
|
1000
|
+
...data,
|
|
1001
|
+
removedAt: data.removedAt?.toISOString()
|
|
1002
|
+
}
|
|
1003
|
+
);
|
|
1004
|
+
if (!res.ok) {
|
|
1005
|
+
const text = await res.text();
|
|
1006
|
+
throw new LiveblocksError(res.status, text);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
829
1009
|
};
|
|
830
1010
|
var LiveblocksError = class extends Error {
|
|
831
1011
|
constructor(status, message = "") {
|
|
@@ -853,11 +1033,15 @@ var _WebhookHandler = class _WebhookHandler {
|
|
|
853
1033
|
* Verifies a webhook request and returns the event
|
|
854
1034
|
*/
|
|
855
1035
|
verifyRequest(request) {
|
|
856
|
-
const {
|
|
857
|
-
|
|
858
|
-
)
|
|
1036
|
+
const { headers, rawBody } = request;
|
|
1037
|
+
const { webhookId, timestamp, rawSignatures } = this.verifyHeaders(headers);
|
|
1038
|
+
if (typeof rawBody !== "string") {
|
|
1039
|
+
throw new Error(
|
|
1040
|
+
`Invalid rawBody field, must be a string, got "${typeof rawBody}" instead. It is likely that you need to JSON.stringify the body before passing it.`
|
|
1041
|
+
);
|
|
1042
|
+
}
|
|
859
1043
|
this.verifyTimestamp(timestamp);
|
|
860
|
-
const signature = this.sign(`${webhookId}.${timestamp}.${
|
|
1044
|
+
const signature = this.sign(`${webhookId}.${timestamp}.${rawBody}`);
|
|
861
1045
|
const expectedSignatures = rawSignatures.split(" ").map((rawSignature) => {
|
|
862
1046
|
const [, parsedSignature] = rawSignature.split(",");
|
|
863
1047
|
return parsedSignature;
|
|
@@ -868,7 +1052,7 @@ var _WebhookHandler = class _WebhookHandler {
|
|
|
868
1052
|
", "
|
|
869
1053
|
)}, got ${signature}`
|
|
870
1054
|
);
|
|
871
|
-
const event = JSON.parse(
|
|
1055
|
+
const event = JSON.parse(rawBody);
|
|
872
1056
|
this.verifyWebhookEventType(event);
|
|
873
1057
|
return event;
|
|
874
1058
|
}
|