API reference › @evolu/common › local‑first/Owner › parseOwnerIdFromOwnerWebSocketTransportUrl
function parseOwnerIdFromOwnerWebSocketTransportUrl(
url: string,
): (string & Brand<"Id"> & Brand<"OwnerId">) | null;
Defined in: packages/common/src/local-first/Owner.ts:435
Extracts OwnerId from an OwnerWebSocketTransport URL query string.
Parses the query string ?ownerId=... and validates that the extracted value
is a valid OwnerId.
Example
import {
createAppOwner,
createOwnerSecret,
createRandomBytes,
parseOwnerIdFromOwnerWebSocketTransportUrl,
} from "@evolu/common";
// Create once, persist the mnemonic securely, and restore it on later runs.
const appOwner = createAppOwner(
createOwnerSecret({ randomBytes: createRandomBytes() }),
);
const url = `/sync?ownerId=${appOwner.id}`;
expect(parseOwnerIdFromOwnerWebSocketTransportUrl(url)).toBe(appOwner.id);
expect(
parseOwnerIdFromOwnerWebSocketTransportUrl("/sync?ownerId=invalid"),
).toBeNull();