@liveblocks/node
Advanced tools
Comparing version 2.13.3-emails2 to 2.14.0-v2encoding
@@ -43,2 +43,3 @@ import { BaseUserMeta, DU, OptionalTupleUnless, PlainLsonObject, JsonObject, QueryMetadata, ThreadData, CommentData, CommentBody, Patchable, CommentUserReaction, InboxNotificationData, RoomNotificationSettings, KDAD, DAD, LsonObject, ToImmutable, PartialUnless, BaseMetadata, DE, DM, DS } from '@liveblocks/core'; | ||
declare class Session { | ||
#private; | ||
readonly FULL_ACCESS: readonly ["room:write", "comments:write"]; | ||
@@ -137,2 +138,3 @@ readonly READ_ACCESS: readonly ["room:read", "room:presence:write", "comments:read"]; | ||
declare class Liveblocks { | ||
#private; | ||
/** | ||
@@ -765,4 +767,3 @@ * Interact with the Liveblocks API from your Node.js backend. | ||
declare class WebhookHandler { | ||
private secretBuffer; | ||
private static secretPrefix; | ||
#private; | ||
constructor( | ||
@@ -778,21 +779,2 @@ /** | ||
verifyRequest(request: WebhookRequest): WebhookEvent; | ||
/** | ||
* Verifies the headers and returns the webhookId, timestamp and rawSignatures | ||
*/ | ||
private verifyHeaders; | ||
/** | ||
* Signs the content with the secret | ||
* @param content | ||
* @returns `string` | ||
*/ | ||
private sign; | ||
/** | ||
* Verifies that the timestamp is not too old or in the future | ||
*/ | ||
private verifyTimestamp; | ||
/** | ||
* Ensures that the event is a known event type | ||
* or throws and prompts the user to upgrade to a higher version of @liveblocks/node | ||
*/ | ||
private verifyWebhookEventType; | ||
} | ||
@@ -799,0 +781,0 @@ declare type WebhookRequest = { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/index.ts | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// src/index.ts | ||
var _core = require('@liveblocks/core'); | ||
@@ -6,3 +6,3 @@ | ||
var PKG_NAME = "@liveblocks/node"; | ||
var PKG_VERSION = "2.13.3-emails2"; | ||
var PKG_VERSION = "2.14.0-v2encoding"; | ||
var PKG_FORMAT = "cjs"; | ||
@@ -94,26 +94,26 @@ | ||
var roomPatternRegex = /^([*]|[^*]{1,128}[*]?)$/; | ||
var Session = class { | ||
var Session = (_class = class { | ||
__init() {this.FULL_ACCESS = FULL_ACCESS} | ||
__init2() {this.READ_ACCESS = READ_ACCESS} | ||
#postFn; | ||
#userId; | ||
#userInfo; | ||
#sealed = false; | ||
#permissions = /* @__PURE__ */ new Map(); | ||
/** @internal */ | ||
constructor(postFn, userId, userInfo) { | ||
this.FULL_ACCESS = FULL_ACCESS; | ||
this.READ_ACCESS = READ_ACCESS; | ||
/** @internal */ | ||
this._sealed = false; | ||
/** @internal */ | ||
this._permissions = /* @__PURE__ */ new Map(); | ||
constructor(postFn, userId, userInfo) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this); | ||
assertNonEmpty(userId, "userId"); | ||
this._postFn = postFn; | ||
this._userId = userId; | ||
this._userInfo = userInfo; | ||
this.#postFn = postFn; | ||
this.#userId = userId; | ||
this.#userInfo = userInfo; | ||
} | ||
/** @internal */ | ||
getOrCreate(roomId) { | ||
if (this._sealed) { | ||
#getOrCreate(roomId) { | ||
if (this.#sealed) { | ||
throw new Error("You can no longer change these permissions."); | ||
} | ||
let perms = this._permissions.get(roomId); | ||
let perms = this.#permissions.get(roomId); | ||
if (perms) { | ||
return perms; | ||
} else { | ||
if (this._permissions.size >= MAX_PERMS_PER_SET) { | ||
if (this.#permissions.size >= MAX_PERMS_PER_SET) { | ||
throw new Error( | ||
@@ -124,3 +124,3 @@ "You cannot add permissions for more than 10 rooms in a single token" | ||
perms = /* @__PURE__ */ new Set(); | ||
this._permissions.set(roomId, perms); | ||
this.#permissions.set(roomId, perms); | ||
return perms; | ||
@@ -139,3 +139,3 @@ } | ||
} | ||
const existingPerms = this.getOrCreate(roomIdOrPattern); | ||
const existingPerms = this.#getOrCreate(roomIdOrPattern); | ||
for (const perm of newPerms) { | ||
@@ -151,7 +151,7 @@ if (!isPermission(perm)) { | ||
hasPermissions() { | ||
return this._permissions.size > 0; | ||
return this.#permissions.size > 0; | ||
} | ||
/** @internal - For unit tests only */ | ||
seal() { | ||
if (this._sealed) { | ||
if (this.#sealed) { | ||
throw new Error( | ||
@@ -161,3 +161,3 @@ "You cannot reuse Session instances. Please create a new session every time." | ||
} | ||
this._sealed = true; | ||
this.#sealed = true; | ||
} | ||
@@ -167,3 +167,3 @@ /** @internal - For unit tests only */ | ||
return Object.fromEntries( | ||
Array.from(this._permissions.entries()).map(([pat, perms]) => [ | ||
Array.from(this.#permissions.entries()).map(([pat, perms]) => [ | ||
pat, | ||
@@ -187,8 +187,8 @@ Array.from(perms) | ||
try { | ||
const resp = await this._postFn(_core.url`/v2/authorize-user`, { | ||
const resp = await this.#postFn(_core.url`/v2/authorize-user`, { | ||
// Required | ||
userId: this._userId, | ||
userId: this.#userId, | ||
permissions: this.serializePermissions(), | ||
// Optional metadata | ||
userInfo: this._userInfo | ||
userInfo: this.#userInfo | ||
}); | ||
@@ -207,6 +207,8 @@ return { | ||
} | ||
}; | ||
}, _class); | ||
// src/client.ts | ||
var Liveblocks = class { | ||
#secret; | ||
#baseUrl; | ||
/** | ||
@@ -219,10 +221,9 @@ * Interact with the Liveblocks API from your Node.js backend. | ||
assertSecretKey(secret, "secret"); | ||
this._secret = secret; | ||
this._baseUrl = new URL(getBaseUrl(options.baseUrl)); | ||
this.#secret = secret; | ||
this.#baseUrl = new URL(getBaseUrl(options.baseUrl)); | ||
} | ||
/** @internal */ | ||
async post(path, json) { | ||
const url3 = _core.urljoin.call(void 0, this._baseUrl, path); | ||
async #post(path, json) { | ||
const url3 = _core.urljoin.call(void 0, this.#baseUrl, path); | ||
const headers = { | ||
Authorization: `Bearer ${this._secret}`, | ||
Authorization: `Bearer ${this.#secret}`, | ||
"Content-Type": "application/json" | ||
@@ -238,7 +239,6 @@ }; | ||
} | ||
/** @internal */ | ||
async put(path, json) { | ||
const url3 = _core.urljoin.call(void 0, this._baseUrl, path); | ||
async #put(path, json) { | ||
const url3 = _core.urljoin.call(void 0, this.#baseUrl, path); | ||
const headers = { | ||
Authorization: `Bearer ${this._secret}`, | ||
Authorization: `Bearer ${this.#secret}`, | ||
"Content-Type": "application/json" | ||
@@ -253,7 +253,6 @@ }; | ||
} | ||
/** @internal */ | ||
async putBinary(path, body, params) { | ||
const url3 = _core.urljoin.call(void 0, this._baseUrl, path, params); | ||
async #putBinary(path, body, params) { | ||
const url3 = _core.urljoin.call(void 0, this.#baseUrl, path, params); | ||
const headers = { | ||
Authorization: `Bearer ${this._secret}`, | ||
Authorization: `Bearer ${this.#secret}`, | ||
"Content-Type": "application/octet-stream" | ||
@@ -264,7 +263,6 @@ }; | ||
} | ||
/** @internal */ | ||
async delete(path) { | ||
const url3 = _core.urljoin.call(void 0, this._baseUrl, path); | ||
async #delete(path) { | ||
const url3 = _core.urljoin.call(void 0, this.#baseUrl, path); | ||
const headers = { | ||
Authorization: `Bearer ${this._secret}` | ||
Authorization: `Bearer ${this.#secret}` | ||
}; | ||
@@ -275,7 +273,6 @@ const fetch = await fetchPolyfill(); | ||
} | ||
/** @internal */ | ||
async get(path, params) { | ||
const url3 = _core.urljoin.call(void 0, this._baseUrl, path, params); | ||
async #get(path, params) { | ||
const url3 = _core.urljoin.call(void 0, this.#baseUrl, path, params); | ||
const headers = { | ||
Authorization: `Bearer ${this._secret}` | ||
Authorization: `Bearer ${this.#secret}` | ||
}; | ||
@@ -307,3 +304,3 @@ const fetch = await fetchPolyfill(); | ||
const options = rest[0]; | ||
return new Session(this.post.bind(this), userId, _optionalChain([options, 'optionalAccess', _ => _.userInfo])); | ||
return new Session(this.#post.bind(this), userId, _optionalChain([options, 'optionalAccess', _ => _.userInfo])); | ||
} | ||
@@ -350,3 +347,3 @@ /** | ||
try { | ||
const resp = await this.post(path, { | ||
const resp = await this.#post(path, { | ||
userId, | ||
@@ -365,3 +362,3 @@ groupIds, | ||
body: `Call to ${_core.urljoin.call(void 0, | ||
this._baseUrl, | ||
this.#baseUrl, | ||
path | ||
@@ -408,3 +405,3 @@ )} failed. See "error" for more information.`, | ||
}; | ||
const res = await this.get(path, queryParams); | ||
const res = await this.#get(path, queryParams); | ||
if (!res.ok) { | ||
@@ -440,3 +437,3 @@ const text = await res.text(); | ||
const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = params; | ||
const res = await this.post(_core.url`/v2/rooms`, { | ||
const res = await this.#post(_core.url`/v2/rooms`, { | ||
id: roomId, | ||
@@ -467,3 +464,3 @@ defaultAccesses, | ||
async getRoom(roomId) { | ||
const res = await this.get(_core.url`/v2/rooms/${roomId}`); | ||
const res = await this.#get(_core.url`/v2/rooms/${roomId}`); | ||
if (!res.ok) { | ||
@@ -494,3 +491,3 @@ const text = await res.text(); | ||
const { defaultAccesses, groupsAccesses, usersAccesses, metadata } = params; | ||
const res = await this.post(_core.url`/v2/rooms/${roomId}`, { | ||
const res = await this.#post(_core.url`/v2/rooms/${roomId}`, { | ||
defaultAccesses, | ||
@@ -519,3 +516,3 @@ groupsAccesses, | ||
async deleteRoom(roomId) { | ||
const res = await this.delete(_core.url`/v2/rooms/${roomId}`); | ||
const res = await this.#delete(_core.url`/v2/rooms/${roomId}`); | ||
if (!res.ok) { | ||
@@ -532,3 +529,3 @@ const text = await res.text(); | ||
async getActiveUsers(roomId) { | ||
const res = await this.get(_core.url`/v2/rooms/${roomId}/active_users`); | ||
const res = await this.#get(_core.url`/v2/rooms/${roomId}/active_users`); | ||
if (!res.ok) { | ||
@@ -546,3 +543,3 @@ const text = await res.text(); | ||
async broadcastEvent(roomId, message) { | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${roomId}/broadcast_event`, | ||
@@ -557,3 +554,3 @@ message | ||
async getStorageDocument(roomId, format = "plain-lson") { | ||
const res = await this.get(_core.url`/v2/rooms/${roomId}/storage`, { format }); | ||
const res = await this.#get(_core.url`/v2/rooms/${roomId}/storage`, { format }); | ||
if (!res.ok) { | ||
@@ -574,3 +571,3 @@ const text = await res.text(); | ||
async initializeStorageDocument(roomId, document) { | ||
const res = await this.post(_core.url`/v2/rooms/${roomId}/storage`, document); | ||
const res = await this.#post(_core.url`/v2/rooms/${roomId}/storage`, document); | ||
if (!res.ok) { | ||
@@ -587,3 +584,3 @@ const text = await res.text(); | ||
async deleteStorageDocument(roomId) { | ||
const res = await this.delete(_core.url`/v2/rooms/${roomId}/storage`); | ||
const res = await this.#delete(_core.url`/v2/rooms/${roomId}/storage`); | ||
if (!res.ok) { | ||
@@ -608,3 +605,3 @@ const text = await res.text(); | ||
const path = _core.url`v2/rooms/${roomId}/ydoc`; | ||
const res = await this.get(path, { | ||
const res = await this.#get(path, { | ||
formatting: format ? "true" : void 0, | ||
@@ -627,3 +624,3 @@ key, | ||
async sendYjsBinaryUpdate(roomId, update, params = {}) { | ||
const res = await this.putBinary(_core.url`/v2/rooms/${roomId}/ydoc`, update, { | ||
const res = await this.#putBinary(_core.url`/v2/rooms/${roomId}/ydoc`, update, { | ||
guid: params.guid | ||
@@ -644,3 +641,3 @@ }); | ||
async getYjsDocumentAsBinaryUpdate(roomId, params = {}) { | ||
const res = await this.get(_core.url`/v2/rooms/${roomId}/ydoc-binary`, { | ||
const res = await this.#get(_core.url`/v2/rooms/${roomId}/ydoc-binary`, { | ||
guid: params.guid | ||
@@ -664,3 +661,3 @@ }); | ||
async createSchema(name, body) { | ||
const res = await this.post(_core.url`/v2/schemas`, { | ||
const res = await this.#post(_core.url`/v2/schemas`, { | ||
name, | ||
@@ -688,3 +685,3 @@ body | ||
async getSchema(schemaId) { | ||
const res = await this.get(_core.url`/v2/schemas/${schemaId}`); | ||
const res = await this.#get(_core.url`/v2/schemas/${schemaId}`); | ||
if (!res.ok) { | ||
@@ -710,3 +707,3 @@ const text = await res.text(); | ||
async updateSchema(schemaId, body) { | ||
const res = await this.put(_core.url`/v2/schemas/${schemaId}`, { | ||
const res = await this.#put(_core.url`/v2/schemas/${schemaId}`, { | ||
body | ||
@@ -732,3 +729,3 @@ }); | ||
async deleteSchema(schemaId) { | ||
const res = await this.delete(_core.url`/v2/schemas/${schemaId}`); | ||
const res = await this.#delete(_core.url`/v2/schemas/${schemaId}`); | ||
if (!res.ok) { | ||
@@ -745,3 +742,3 @@ const text = await res.text(); | ||
async getSchemaByRoomId(roomId) { | ||
const res = await this.get(_core.url`/v2/rooms/${roomId}/schema`); | ||
const res = await this.#get(_core.url`/v2/rooms/${roomId}/schema`); | ||
if (!res.ok) { | ||
@@ -768,3 +765,3 @@ const text = await res.text(); | ||
async attachSchemaToRoom(roomId, schemaId) { | ||
const res = await this.post(_core.url`/v2/rooms/${roomId}/schema`, { | ||
const res = await this.#post(_core.url`/v2/rooms/${roomId}/schema`, { | ||
schema: schemaId | ||
@@ -783,3 +780,3 @@ }); | ||
async detachSchemaFromRoom(roomId) { | ||
const res = await this.delete(_core.url`/v2/rooms/${roomId}/schema`); | ||
const res = await this.#delete(_core.url`/v2/rooms/${roomId}/schema`); | ||
if (!res.ok) { | ||
@@ -808,3 +805,3 @@ const text = await res.text(); | ||
} | ||
const res = await this.get(_core.url`/v2/rooms/${roomId}/threads`, { | ||
const res = await this.#get(_core.url`/v2/rooms/${roomId}/threads`, { | ||
query | ||
@@ -830,3 +827,3 @@ }); | ||
const { roomId, threadId } = params; | ||
const res = await this.get(_core.url`/v2/rooms/${roomId}/threads/${threadId}`); | ||
const res = await this.#get(_core.url`/v2/rooms/${roomId}/threads/${threadId}`); | ||
if (!res.ok) { | ||
@@ -850,3 +847,3 @@ const text = await res.text(); | ||
const { roomId, threadId } = params; | ||
const res = await this.get( | ||
const res = await this.#get( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/participants` | ||
@@ -870,3 +867,3 @@ ); | ||
const { roomId, threadId, commentId } = params; | ||
const res = await this.get( | ||
const res = await this.#get( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}` | ||
@@ -892,3 +889,3 @@ ); | ||
const { roomId, threadId, data } = params; | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments`, | ||
@@ -917,3 +914,3 @@ { | ||
const { roomId, threadId, commentId, data } = params; | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}`, | ||
@@ -939,3 +936,3 @@ { | ||
const { roomId, threadId, commentId } = params; | ||
const res = await this.delete( | ||
const res = await this.#delete( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}` | ||
@@ -960,3 +957,3 @@ ); | ||
const { roomId, data } = params; | ||
const res = await this.post(_core.url`/v2/rooms/${roomId}/threads`, { | ||
const res = await this.#post(_core.url`/v2/rooms/${roomId}/threads`, { | ||
...data, | ||
@@ -981,3 +978,5 @@ comment: { | ||
const { roomId, threadId } = params; | ||
const res = await this.delete(_core.url`/v2/rooms/${roomId}/threads/${threadId}`); | ||
const res = await this.#delete( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}` | ||
); | ||
if (!res.ok) { | ||
@@ -997,3 +996,3 @@ const text = await res.text(); | ||
const { roomId, threadId } = params; | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/mark-as-resolved`, | ||
@@ -1017,3 +1016,3 @@ {} | ||
const { roomId, threadId } = params; | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/mark-as-unresolved`, | ||
@@ -1039,3 +1038,3 @@ {} | ||
const { roomId, threadId, data } = params; | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/metadata`, | ||
@@ -1065,3 +1064,3 @@ { | ||
const { roomId, threadId, commentId, data } = params; | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${commentId}/add-reaction`, | ||
@@ -1091,3 +1090,3 @@ { | ||
const { roomId, threadId, data } = params; | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${roomId}/threads/${threadId}/comments/${params.commentId}/remove-reaction`, | ||
@@ -1111,3 +1110,3 @@ { | ||
const { userId, inboxNotificationId } = params; | ||
const res = await this.get( | ||
const res = await this.#get( | ||
_core.url`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}` | ||
@@ -1136,3 +1135,3 @@ ); | ||
} | ||
const res = await this.get(_core.url`/v2/users/${userId}/inbox-notifications`, { | ||
const res = await this.#get(_core.url`/v2/users/${userId}/inbox-notifications`, { | ||
query | ||
@@ -1156,3 +1155,3 @@ }); | ||
const { userId, roomId } = params; | ||
const res = await this.get( | ||
const res = await this.#get( | ||
_core.url`/v2/rooms/${roomId}/users/${userId}/notification-settings` | ||
@@ -1174,3 +1173,3 @@ ); | ||
const { userId, roomId, data } = params; | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${roomId}/users/${userId}/notification-settings`, | ||
@@ -1192,3 +1191,3 @@ data | ||
const { userId, roomId } = params; | ||
const res = await this.delete( | ||
const res = await this.#delete( | ||
_core.url`/v2/rooms/${roomId}/users/${userId}/notification-settings` | ||
@@ -1208,3 +1207,3 @@ ); | ||
const { currentRoomId, newRoomId } = params; | ||
const res = await this.post( | ||
const res = await this.#post( | ||
_core.url`/v2/rooms/${currentRoomId}/update-room-id`, | ||
@@ -1227,3 +1226,3 @@ { | ||
async triggerInboxNotification(params) { | ||
const res = await this.post(_core.url`/v2/inbox-notifications/trigger`, params); | ||
const res = await this.#post(_core.url`/v2/inbox-notifications/trigger`, params); | ||
if (!res.ok) { | ||
@@ -1241,3 +1240,3 @@ const text = await res.text(); | ||
const { userId, inboxNotificationId } = params; | ||
const res = await this.delete( | ||
const res = await this.#delete( | ||
_core.url`/v2/users/${userId}/inbox-notifications/${inboxNotificationId}` | ||
@@ -1256,3 +1255,5 @@ ); | ||
const { userId } = params; | ||
const res = await this.delete(_core.url`/v2/users/${userId}/inbox-notifications`); | ||
const res = await this.#delete( | ||
_core.url`/v2/users/${userId}/inbox-notifications` | ||
); | ||
if (!res.ok) { | ||
@@ -1265,2 +1266,3 @@ const text = await res.text(); | ||
var LiveblocksError = class extends Error { | ||
constructor(status, message = "") { | ||
@@ -1276,10 +1278,12 @@ super(message); | ||
var _fastsha256 = require('fast-sha256'); var sha256 = _interopRequireWildcard(_fastsha256); | ||
var _WebhookHandler = class _WebhookHandler { | ||
var WebhookHandler = class _WebhookHandler { | ||
#secretBuffer; | ||
static #secretPrefix = "whsec_"; | ||
constructor(secret) { | ||
if (!secret) throw new Error("Secret is required"); | ||
if (typeof secret !== "string") throw new Error("Secret must be a string"); | ||
if (secret.startsWith(_WebhookHandler.secretPrefix) === false) | ||
if (secret.startsWith(_WebhookHandler.#secretPrefix) === false) | ||
throw new Error("Invalid secret, must start with whsec_"); | ||
const secretKey = secret.slice(_WebhookHandler.secretPrefix.length); | ||
this.secretBuffer = Buffer.from(secretKey, "base64"); | ||
const secretKey = secret.slice(_WebhookHandler.#secretPrefix.length); | ||
this.#secretBuffer = Buffer.from(secretKey, "base64"); | ||
} | ||
@@ -1291,3 +1295,3 @@ /** | ||
const { headers, rawBody } = request; | ||
const { webhookId, timestamp, rawSignatures } = this.verifyHeaders(headers); | ||
const { webhookId, timestamp, rawSignatures } = this.#verifyHeaders(headers); | ||
if (typeof rawBody !== "string") { | ||
@@ -1298,4 +1302,4 @@ throw new Error( | ||
} | ||
this.verifyTimestamp(timestamp); | ||
const signature = this.sign(`${webhookId}.${timestamp}.${rawBody}`); | ||
this.#verifyTimestamp(timestamp); | ||
const signature = this.#sign(`${webhookId}.${timestamp}.${rawBody}`); | ||
const expectedSignatures = rawSignatures.split(" ").map((rawSignature) => { | ||
@@ -1312,3 +1316,3 @@ const [, parsedSignature] = rawSignature.split(","); | ||
const event = JSON.parse(rawBody); | ||
this.verifyWebhookEventType(event); | ||
this.#verifyWebhookEventType(event); | ||
return event; | ||
@@ -1319,3 +1323,3 @@ } | ||
*/ | ||
verifyHeaders(headers) { | ||
#verifyHeaders(headers) { | ||
const usingNativeHeaders = typeof Headers !== "undefined" && headers instanceof Headers; | ||
@@ -1343,6 +1347,6 @@ const normalizedHeaders = usingNativeHeaders ? Object.fromEntries(headers) : headers; | ||
*/ | ||
sign(content) { | ||
#sign(content) { | ||
const encoder = new TextEncoder(); | ||
const toSign = encoder.encode(content); | ||
return base64.encode(sha256.hmac(this.secretBuffer, toSign)); | ||
return base64.encode(sha256.hmac(this.#secretBuffer, toSign)); | ||
} | ||
@@ -1352,3 +1356,3 @@ /** | ||
*/ | ||
verifyTimestamp(timestampHeader) { | ||
#verifyTimestamp(timestampHeader) { | ||
const now = Math.floor(Date.now() / 1e3); | ||
@@ -1370,3 +1374,3 @@ const timestamp = parseInt(timestampHeader, 10); | ||
*/ | ||
verifyWebhookEventType(event) { | ||
#verifyWebhookEventType(event) { | ||
if (event && event.type && [ | ||
@@ -1408,4 +1412,2 @@ "storageUpdated", | ||
}; | ||
_WebhookHandler.secretPrefix = "whsec_"; | ||
var WebhookHandler = _WebhookHandler; | ||
var WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; | ||
@@ -1412,0 +1414,0 @@ var isNotUndefined = (value) => value !== void 0; |
{ | ||
"name": "@liveblocks/node", | ||
"version": "2.13.3-emails2", | ||
"version": "2.14.0-v2encoding", | ||
"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.", | ||
@@ -37,3 +37,3 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@liveblocks/core": "2.13.3-emails2", | ||
"@liveblocks/core": "2.14.0-v2encoding", | ||
"@stablelib/base64": "^1.0.1", | ||
@@ -40,0 +40,0 @@ "fast-sha256": "^1.3.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
404073
3808
+ Added@liveblocks/core@2.14.0-v2encoding(transitive)
- Removed@liveblocks/core@2.13.3-emails2(transitive)