site

PAN v1.0 API Stability Contract

Status: πŸ”’ LOCKED FOR v1.0 Last Updated: November 2024

This document defines the stable, public API surface for PAN v1.0. All items marked as STABLE are guaranteed not to have breaking changes in v1.x releases. Breaking changes require a major version bump (v2.0).


Table of Contents

  1. PanClient API
  2. PanMessage Format
  3. CustomEvents
  4. Topic Conventions
  5. Semantic Versioning Policy
  6. Stability Guarantees

PanClient API

Constructor

STABLE - Constructor signature locked for v1.0

new PanClient(host?: HTMLElement|Document, busSelector?: string)

Parameters:

Guarantees:


ready()

STABLE - Method signature locked for v1.0

client.ready(): Promise<void>

Returns: Promise that resolves when PAN bus is ready

Guarantees:

Example:

const client = new PanClient();
await client.ready();
// Bus is now ready for use

publish()

STABLE - Method signature locked for v1.0

client.publish(message: PanMessage): void

Parameters:

Required fields:

Optional fields:

Guarantees:

Example:

// Simple publish
client.publish({
  topic: 'users.updated',
  data: { id: 123, name: 'Alice' }
});

// Retained message
client.publish({
  topic: 'app.state',
  data: { theme: 'dark' },
  retain: true
});

subscribe()

STABLE - Method signature locked for v1.0

client.subscribe(
  topics: string | string[],
  handler: (message: PanMessage) => void,
  options?: SubscribeOptions
): UnsubscribeFunction

Parameters:

SubscribeOptions:

Returns: Unsubscribe function () => void

Guarantees:

Example:

// Subscribe to single topic
const unsub = client.subscribe('users.updated', (msg) => {
  console.log('User updated:', msg.data);
});

// Subscribe to multiple topics with wildcard
client.subscribe(['users.*', 'posts.*'], (msg) => {
  console.log('Received:', msg.topic, msg.data);
});

// With retained messages
client.subscribe('app.state', (msg) => {
  console.log('Current state:', msg.data);
}, { retained: true });

// With AbortSignal
const controller = new AbortController();
client.subscribe('events.*', handler, { signal: controller.signal });
// Later: controller.abort(); // Unsubscribes automatically

request()

STABLE - Method signature locked for v1.0

client.request(
  topic: string,
  data: any,
  options?: RequestOptions
): Promise<PanMessage>

Parameters:

RequestOptions:

Returns: Promise that resolves with reply message

Throws: Error if request times out

Guarantees:

Example:

// Simple request
try {
  const response = await client.request('users.get', { id: 123 });
  console.log('User:', response.data);
} catch (err) {
  console.error('Request failed:', err);
}

// Custom timeout
const response = await client.request('slow.operation', { ... }, {
  timeoutMs: 10000  // 10 second timeout
});

PanClient.matches() (static)

STABLE - Static method signature locked for v1.0

PanClient.matches(topic: string, pattern: string): boolean

Parameters:

Returns: boolean - true if topic matches pattern

Guarantees:

Pattern Rules:

Example:

PanClient.matches('users.list.state', 'users.*')  // true
PanClient.matches('users.list.state', 'users.list.state')  // true
PanClient.matches('users.list.state', '*')  // true
PanClient.matches('users.list.state', 'posts.*')  // false
PanClient.matches('users.item.123', 'users.item.*')  // true

PanMessage Format

STABLE - Message envelope format locked for v1.0

Required Fields

interface PanMessage {
  topic: string;      // Topic name (e.g., "users.list.state")
  data: any;          // Message payload (any JSON-serializable value)

  // Optional fields - auto-generated by bus if not provided
  id?: string;        // Unique message ID (UUID)
  ts?: number;        // Timestamp in milliseconds (epoch)

  // Optional fields - for message features
  retain?: boolean;           // If true, message is retained by bus
  replyTo?: string;           // Topic to send reply to
  correlationId?: string;     // Correlation ID for request/reply
  headers?: Record<string, string>;  // Optional metadata
}

Field Guarantees

topic (required)

data (required)

id (optional)

ts (optional)

retain (optional)

replyTo (optional)

correlationId (optional)

headers (optional)


CustomEvents

STABLE - CustomEvent names and signatures locked for v1.0

All PAN CustomEvents use bubbles: true, composed: true to cross shadow DOM boundaries.

pan:sys.ready

Purpose: Signal that PAN bus is ready

new CustomEvent('pan:sys.ready', {
  bubbles: true,
  composed: true
})

Guarantees:


pan:publish

Purpose: Publish a message to the bus

new CustomEvent('pan:publish', {
  detail: PanMessage,
  bubbles: true,
  composed: true
})

Guarantees:


pan:subscribe

Purpose: Subscribe to topics

new CustomEvent('pan:subscribe', {
  detail: {
    clientId: string,
    topics: string[],
    options?: { retained?: boolean }
  },
  bubbles: true,
  composed: true
})

Guarantees:


pan:unsubscribe

Purpose: Unsubscribe from topics

new CustomEvent('pan:unsubscribe', {
  detail: {
    clientId: string,
    topics: string[]
  },
  bubbles: true,
  composed: true
})

Guarantees:


pan:deliver

Purpose: Deliver message from bus to subscriber

new CustomEvent('pan:deliver', {
  detail: PanMessage,
  bubbles: false,
  composed: false
})

Guarantees:


pan:hello

Purpose: Client announces presence to bus

new CustomEvent('pan:hello', {
  detail: {
    id: string,
    caps?: string[]
  },
  bubbles: true,
  composed: true
})

Guarantees:


Reserved Event Names

LOCKED: The following event name pattern is reserved for PAN:

Guarantees:


Topic Conventions

STABLE - Core conventions locked for v1.0

Naming Pattern

Standard Format: resource.action.qualifier

Examples:

Guarantees:


Wildcard Matching

Single Segment Wildcard: *

Rules:

Guarantees:


Reserved Namespaces

LOCKED - Reserved for PAN internals

Guarantees:


Status: RECOMMENDED (not enforced)

These are conventions, not requirements. Applications MAY use different patterns.

List Operations:

Item Operations:

Examples:

// List users
const response = await client.request('users.list.get', {});
console.log(response.data.items);

// Subscribe to list state
client.subscribe('users.list.state', (msg) => {
  console.log('User list:', msg.data.items);
}, { retained: true });

// Get single user
const user = await client.request('users.item.get', { id: 123 });

// Save user
await client.request('users.item.save', { item: { id: 123, name: 'Alice' } });

// Select user (no reply)
client.publish({ topic: 'users.item.select', data: { id: 123 } });

Guarantees:


Semantic Versioning Policy

PAN follows Semantic Versioning 2.0.0

Version Format: MAJOR.MINOR.PATCH

Example: v1.2.3


What Constitutes a BREAKING Change (requires MAJOR bump)

PanClient API:

PanMessage Format:

CustomEvents:

Topic Conventions:


What is a NON-BREAKING Change (MINOR or PATCH)

Allowed in MINOR versions:

Allowed in PATCH versions:


Deprecation Policy

When removing features, we follow this timeline:

  1. v1.x.0 - Feature marked as deprecated in documentation
    • Still works, logs deprecation warning to console
    • Alternative documented
  2. v1.(x+1).0 - At least 1 MINOR version later
    • Feature still works, stricter warnings
    • Removal date announced
  3. v2.0.0 - MAJOR version bump
    • Feature removed
    • Migration guide provided

Minimum Deprecation Period: 2 MINOR versions or 6 months (whichever is longer)


Stability Guarantees

What is STABLE (guaranteed not to break in v1.x)

βœ… PanClient API

βœ… PanMessage Format

βœ… CustomEvents

βœ… Topic Matching

βœ… Reserved Namespaces


What is UNSTABLE (may change in v1.x)

⚠️ Internal Implementation

⚠️ CRUD Conventions

⚠️ Error Messages


What is EXPERIMENTAL (may be removed)

πŸ§ͺ None in v1.0

All APIs in v1.0 are either STABLE or documented as UNSTABLE. No experimental features at release.


Migration Guide (Future)

When v2.0 is released, a comprehensive migration guide will be provided covering:


Feedback and Changes

This document is LOCKED for v1.0 release. Changes require:

  1. Non-breaking additions - Require MINOR version bump and documentation update
  2. Breaking changes - Require MAJOR version bump (v2.0) and deprecation period
  3. Clarifications - Documentation fixes only, no version bump

Last Review: November 2024 Next Review: Before v1.1.0 release


End of API Stability Contract