@liveblocks/client
Advanced tools
Comparing version 0.12.0-beta.8 to 0.12.0-beta.9
import { AuthEndpoint, AuthenticationToken } from "./types"; | ||
export default function auth(endpoint: AuthEndpoint, room: string): Promise<string>; | ||
export default function auth(endpoint: AuthEndpoint, room: string, publicApiKey?: string): Promise<string>; | ||
export declare function parseToken(token: string): AuthenticationToken; |
@@ -13,3 +13,3 @@ "use strict"; | ||
exports.parseToken = void 0; | ||
function fetchAuthorize(endpoint, room) { | ||
function fetchAuthorize(endpoint, room, publicApiKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -23,2 +23,3 @@ const res = yield fetch(endpoint, { | ||
room, | ||
publicApiKey, | ||
}), | ||
@@ -42,6 +43,6 @@ }); | ||
} | ||
function auth(endpoint, room) { | ||
function auth(endpoint, room, publicApiKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (typeof endpoint === "string") { | ||
return fetchAuthorize(endpoint, room); | ||
return fetchAuthorize(endpoint, room, publicApiKey); | ||
} | ||
@@ -48,0 +49,0 @@ if (typeof endpoint === "function") { |
@@ -52,2 +52,3 @@ import { Others, Presence, ClientOptions, Room, MyPresenceCallback, OthersEventCallback, AuthEndpoint, EventCallback, User, Connection, ErrorCallback, AuthenticationToken, ConnectionCallback } from "./types"; | ||
throttleDelay: number; | ||
publicApiKey?: string; | ||
}; | ||
@@ -54,0 +55,0 @@ export declare function makeStateMachine(state: State, context: Context, mockedEffects?: Effects): { |
@@ -77,3 +77,3 @@ "use strict"; | ||
try { | ||
const token = yield (0, authentication_1.default)(context.authEndpoint, context.room); | ||
const token = yield (0, authentication_1.default)(context.authEndpoint, context.room, context.publicApiKey); | ||
const parsedToken = (0, authentication_1.parseToken)(token); | ||
@@ -571,3 +571,10 @@ const socket = new WebSocket(`${context.liveblocksServer}/?token=${token}`); | ||
const liveblocksServer = options.liveblocksServer || "wss://liveblocks.net/v2"; | ||
const authEndpoint = options.authEndpoint; | ||
let authEndpoint; | ||
if (options.authEndpoint) { | ||
authEndpoint = options.authEndpoint; | ||
} | ||
else { | ||
const publicAuthorizeEndpoint = options.publicAuthorizeEndpoint || "https://liveblocks.io/api/public/authorize"; | ||
authEndpoint = publicAuthorizeEndpoint; | ||
} | ||
const state = defaultState(options.defaultPresence, options.defaultStorageRoot); | ||
@@ -579,2 +586,3 @@ const machine = makeStateMachine(state, { | ||
room: name, | ||
publicApiKey: options.publicApiKey | ||
}); | ||
@@ -581,0 +589,0 @@ const room = { |
@@ -90,10 +90,15 @@ import { LiveObject } from "./doc"; | ||
export declare type AuthEndpoint = string | AuthEndpointCallback; | ||
/** | ||
* The authentication endpoint that is called to ensure that the current user has access to a room. | ||
* Can be an url or a callback if you need to add additional headers. | ||
*/ | ||
export declare type ClientOptions = { | ||
/** | ||
* The authentication endpoint that is called to ensure that the current user has access to a room. | ||
* Can be an url or a callback if you need to add additional headers. | ||
*/ | ||
throttle?: number; | ||
} & ({ | ||
publicApiKey: string; | ||
authEndpoint?: never; | ||
} | { | ||
publicApiKey?: never; | ||
authEndpoint: AuthEndpoint; | ||
throttle?: number; | ||
}; | ||
}); | ||
export declare type AuthorizeResponse = { | ||
@@ -100,0 +105,0 @@ token: string; |
import { AuthEndpoint, AuthenticationToken } from "./types"; | ||
export default function auth(endpoint: AuthEndpoint, room: string): Promise<string>; | ||
export default function auth(endpoint: AuthEndpoint, room: string, publicApiKey?: string): Promise<string>; | ||
export declare function parseToken(token: string): AuthenticationToken; |
@@ -10,3 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
function fetchAuthorize(endpoint, room) { | ||
function fetchAuthorize(endpoint, room, publicApiKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -20,2 +20,3 @@ const res = yield fetch(endpoint, { | ||
room, | ||
publicApiKey, | ||
}), | ||
@@ -39,6 +40,6 @@ }); | ||
} | ||
export default function auth(endpoint, room) { | ||
export default function auth(endpoint, room, publicApiKey) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (typeof endpoint === "string") { | ||
return fetchAuthorize(endpoint, room); | ||
return fetchAuthorize(endpoint, room, publicApiKey); | ||
} | ||
@@ -45,0 +46,0 @@ if (typeof endpoint === "function") { |
@@ -52,2 +52,3 @@ import { Others, Presence, ClientOptions, Room, MyPresenceCallback, OthersEventCallback, AuthEndpoint, EventCallback, User, Connection, ErrorCallback, AuthenticationToken, ConnectionCallback } from "./types"; | ||
throttleDelay: number; | ||
publicApiKey?: string; | ||
}; | ||
@@ -54,0 +55,0 @@ export declare function makeStateMachine(state: State, context: Context, mockedEffects?: Effects): { |
@@ -52,3 +52,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
try { | ||
const token = yield auth(context.authEndpoint, context.room); | ||
const token = yield auth(context.authEndpoint, context.room, context.publicApiKey); | ||
const parsedToken = parseToken(token); | ||
@@ -544,3 +544,10 @@ const socket = new WebSocket(`${context.liveblocksServer}/?token=${token}`); | ||
const liveblocksServer = options.liveblocksServer || "wss://liveblocks.net/v2"; | ||
const authEndpoint = options.authEndpoint; | ||
let authEndpoint; | ||
if (options.authEndpoint) { | ||
authEndpoint = options.authEndpoint; | ||
} | ||
else { | ||
const publicAuthorizeEndpoint = options.publicAuthorizeEndpoint || "https://liveblocks.io/api/public/authorize"; | ||
authEndpoint = publicAuthorizeEndpoint; | ||
} | ||
const state = defaultState(options.defaultPresence, options.defaultStorageRoot); | ||
@@ -552,2 +559,3 @@ const machine = makeStateMachine(state, { | ||
room: name, | ||
publicApiKey: options.publicApiKey | ||
}); | ||
@@ -554,0 +562,0 @@ const room = { |
@@ -90,10 +90,15 @@ import { LiveObject } from "./doc"; | ||
export declare type AuthEndpoint = string | AuthEndpointCallback; | ||
/** | ||
* The authentication endpoint that is called to ensure that the current user has access to a room. | ||
* Can be an url or a callback if you need to add additional headers. | ||
*/ | ||
export declare type ClientOptions = { | ||
/** | ||
* The authentication endpoint that is called to ensure that the current user has access to a room. | ||
* Can be an url or a callback if you need to add additional headers. | ||
*/ | ||
throttle?: number; | ||
} & ({ | ||
publicApiKey: string; | ||
authEndpoint?: never; | ||
} | { | ||
publicApiKey?: never; | ||
authEndpoint: AuthEndpoint; | ||
throttle?: number; | ||
}; | ||
}); | ||
export declare type AuthorizeResponse = { | ||
@@ -100,0 +105,0 @@ token: string; |
{ | ||
"name": "@liveblocks/client", | ||
"version": "0.12.0-beta.8", | ||
"version": "0.12.0-beta.9", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/cjs/index.js", |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
200177
5611
3