Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.usehasp.com/llms.txt

Use this file to discover all available pages before exploring further.

The SDK detects maintenance mode reactively via 503 responses. Write operations are blocked; reads are still allowed.

Event Handlers

The simplest way to handle maintenance is via constructor callbacks:
const sdk = new HaspSDK({
  onMaintenanceStart: (status) => {
    document.getElementById('maintenance-banner').style.display = 'block';
    document.getElementById('maintenance-message').textContent =
      status.message ?? 'App is being updated.';
  },
  onMaintenanceEnd: () => {
    document.getElementById('maintenance-banner').style.display = 'none';
  },
});
Or attach/remove handlers dynamically:
// sdk.on() returns an unsubscribe function
const unsubStart = sdk.on('maintenanceStart', (status) => { /* ... */ });
const unsubEnd   = sdk.on('maintenanceEnd', () => { /* ... */ });

// Remove later:
unsubStart();
unsubEnd();

Write Behavior

Write operations throw MaintenanceError immediately if the SDK is already in maintenance state — they do not hit the server:
try {
  await sdk.createRecord('tasks', data);
} catch (error) {
  if (error instanceof HaspSDK.MaintenanceError) {
    showMessage('App is being updated. Please try again shortly.');
  }
}

Read Behavior

Read operations (listRecords, getRecord, paginateRecords, getSchema, getBootstrap) are allowed during maintenance and may succeed depending on server behavior.

Automatic Recovery

Maintenance mode clears automatically — if any request succeeds after a 503, the SDK exits maintenance mode and fires maintenanceEnd.

Proactive Detection

The SDK only detects maintenance reactively. For proactive detection before a write fails, implement your own status poller:
const poller = setInterval(async () => {
  const status = await sdk.getStatus();
  if (status.status === 'maintenance') {
    showMaintenanceBanner(status.message);
  } else {
    hideMaintenanceBanner();
  }
}, 15_000);

clearInterval(poller);
sdk.destroy();

getStatus(signal?)

Fetches the current app status without triggering maintenance mode detection.
const status = await sdk.getStatus();
// status.status           — 'ok' | 'maintenance'
// status.message          — optional human-readable message
// status.estimatedSeconds — optional estimated downtime in seconds