mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-10 10:53:24 +00:00
Add custom peer ID support to register method
- Update register() to accept optional customPeerId parameter - Add TypeScript documentation with JSDoc comments - Update README with usage examples and documentation - Maintain backward compatibility with auto-generated IDs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
11
src/auth.ts
11
src/auth.ts
@@ -29,14 +29,21 @@ export class RondevuAuth {
|
||||
|
||||
/**
|
||||
* Register a new peer and receive credentials
|
||||
* @param customPeerId - Optional custom peer ID (1-128 characters). If not provided, a random ID will be generated.
|
||||
* @throws Error if registration fails (e.g., peer ID already in use)
|
||||
*/
|
||||
async register(): Promise<Credentials> {
|
||||
async register(customPeerId?: string): Promise<Credentials> {
|
||||
const body: { peerId?: string } = {};
|
||||
if (customPeerId !== undefined) {
|
||||
body.peerId = customPeerId;
|
||||
}
|
||||
|
||||
const response = await this.fetchFn(`${this.baseUrl}/register`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({}),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -100,9 +100,10 @@ export class Rondevu {
|
||||
|
||||
/**
|
||||
* Register and initialize authenticated client
|
||||
* @param customPeerId - Optional custom peer ID (1-128 characters). If not provided, a random ID will be generated.
|
||||
*/
|
||||
async register(): Promise<Credentials> {
|
||||
this.credentials = await this.auth.register();
|
||||
async register(customPeerId?: string): Promise<Credentials> {
|
||||
this.credentials = await this.auth.register(customPeerId);
|
||||
|
||||
// Create offers API instance
|
||||
this._offers = new RondevuOffers(
|
||||
|
||||
Reference in New Issue
Block a user