Imports the previously untracked working tree as-is so that the review changes that follow (requirements -> design -> implementation) can be reviewed as diffs and reverted if needed. No content changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
2.3 KiB
JavaScript
38 lines
2.3 KiB
JavaScript
/** Prefix-aware OCT adapter for Theia 1.76 / open-collaboration-protocol 0.3.x.
|
|
* Platform authentication remains the workspace gateway's HttpOnly session.
|
|
* OCT display names and room tokens never grant access to a workspace.
|
|
*/
|
|
function collaborationBase(raw, browserLocation) {
|
|
const location = new URL(browserLocation);
|
|
const base = new URL(raw, location.origin);
|
|
const match = /^\/workspaces\/([a-zA-Z0-9][a-zA-Z0-9_-]*)\//.exec(location.pathname);
|
|
if (!match || base.origin !== location.origin || base.username || base.password || base.search || base.hash || base.pathname !== `/workspaces/${match[1]}/collaboration/`) throw new Error('Collaboration must use this workspace authenticated gateway path');
|
|
return base;
|
|
}
|
|
function normalizeAuthMetadata(meta) {
|
|
const providers = (meta.providers ?? []).filter(provider => provider.type === 'form' && provider.name === 'unverified' && provider.endpoint === '/api/login/simple').map(provider => ({ ...provider, endpoint: 'api/login/simple' }));
|
|
if (providers.length !== 1) throw new Error('Workspace collaboration requires its isolated display-name provider');
|
|
return { ...meta, providers, loginPageUrl: undefined };
|
|
}
|
|
function createPrefixTransport({ io, SocketIoTransport }, baseUrl) {
|
|
const base = new URL(baseUrl);
|
|
return { id: 'socket.io', createTransport(_url, headers) {
|
|
// io(baseUrl) treats the pathname as a namespace and silently uses /socket.io.
|
|
// Explicit path and origin keep both Engine.IO polling and WS upgrade scoped.
|
|
const socket = io(base.origin, { path: `${base.pathname}socket.io`, extraHeaders: headers, withCredentials: true, transports: ['polling', 'websocket'] });
|
|
return new SocketIoTransport(socket);
|
|
} };
|
|
}
|
|
function createPrefixConnectionProvider(deps, options) {
|
|
const base = collaborationBase(options.url, options.browserLocation);
|
|
return new deps.ConnectionProvider({
|
|
url: base.href,
|
|
client: options.client,
|
|
fetch: (url, init) => options.fetch(url, { ...init, credentials: 'same-origin' }),
|
|
authenticationHandler: (token, metadata) => options.authenticationHandler(token, normalizeAuthMetadata(metadata)),
|
|
transports: [createPrefixTransport(deps, base.href)],
|
|
userToken: options.userToken,
|
|
});
|
|
}
|
|
module.exports = { collaborationBase, normalizeAuthMetadata, createPrefixTransport, createPrefixConnectionProvider };
|