PhoenixKit.Modules.Sync.Connection (phoenix_kit v1.7.42)

Copy Markdown View Source

Schema for DB Sync persistent connections between PhoenixKit instances.

Connections allow two PhoenixKit sites to establish a permanent relationship for data synchronization, replacing ephemeral session codes with token-based authentication.

Direction

Each connection has a direction:

  • "sender" - This site will send data (configured on the data-sharing site)
  • "receiver" - This site will receive data (configured on the data-receiving site)

Approval Modes (Sender-side)

  • "auto_approve" - All transfers are automatically approved
  • "require_approval" - Each transfer needs manual approval
  • "per_table" - Tables in auto_approve_tables don't need approval, others do

Status Flow

pending  active  suspended  revoked
                
                expired (auto-set when limits exceeded or past expires_at)

Security Features

  • Token-based authentication (auth_token_hash)
  • Optional download password
  • IP whitelist
  • Time-of-day restrictions
  • Download and record limits
  • Expiration date

Usage Examples

# Create a sender connection
{:ok, conn} = Connections.create_connection(%{
  name: "Production Receiver",
  direction: "sender",
  site_url: "https://receiver.example.com",
  approval_mode: "auto_approve"
})

# Approve a pending connection
{:ok, conn} = Connections.approve_connection(conn, admin_user_id)

# Suspend a connection
{:ok, conn} = Connections.suspend_connection(conn, admin_user_id, "Security audit")

Summary

Functions

Checks if a connection is currently active and within limits.

Changeset for approving a connection.

Creates a changeset for connection creation.

Checks if a connection has expired.

Generates a secure random token for connection authentication.

Checks if an IP address is in the whitelist.

Changeset for reactivating a suspended connection.

Checks if a table requires approval based on the connection's approval mode.

Changeset for revoking a connection.

Changeset for updating connection settings.

Changeset for updating connection statistics.

Changeset for suspending a connection.

Checks if a table is allowed to be accessed.

Verifies an auth token against the stored hash.

Verifies a download password against the stored hash.

Checks if current time is within allowed hours.

Checks if a connection is within download limits.

Checks if a connection is within record limits.

Types

t()

@type t() :: %PhoenixKit.Modules.Sync.Connection{
  __meta__: term(),
  allowed_hours_end: term(),
  allowed_hours_start: term(),
  allowed_tables: term(),
  approval_mode: term(),
  approved_at: term(),
  approved_by: term(),
  approved_by_user: term(),
  approved_by_uuid: term(),
  auth_token: term(),
  auth_token_hash: term(),
  auto_approve_tables: term(),
  auto_sync_enabled: term(),
  auto_sync_interval_minutes: term(),
  auto_sync_tables: term(),
  created_by: term(),
  created_by_user: term(),
  created_by_uuid: term(),
  default_conflict_strategy: term(),
  direction: term(),
  download_password: term(),
  download_password_hash: term(),
  downloads_used: term(),
  excluded_tables: term(),
  expires_at: term(),
  id: term(),
  inserted_at: term(),
  ip_whitelist: term(),
  last_connected_at: term(),
  last_transfer_at: term(),
  max_downloads: term(),
  max_records_per_request: term(),
  max_records_total: term(),
  metadata: term(),
  name: term(),
  rate_limit_requests_per_minute: term(),
  records_downloaded: term(),
  revoked_at: term(),
  revoked_by: term(),
  revoked_by_user: term(),
  revoked_by_uuid: term(),
  revoked_reason: term(),
  site_url: term(),
  status: term(),
  suspended_at: term(),
  suspended_by: term(),
  suspended_by_user: term(),
  suspended_by_uuid: term(),
  suspended_reason: term(),
  total_bytes_transferred: term(),
  total_records_transferred: term(),
  total_transfers: term(),
  updated_at: term(),
  uuid: term()
}

Functions

active?(conn)

Checks if a connection is currently active and within limits.

approve_changeset(connection, admin_user_id)

Changeset for approving a connection.

changeset(connection, attrs)

Creates a changeset for connection creation.

expired?(connection)

Checks if a connection has expired.

generate_auth_token()

Generates a secure random token for connection authentication.

ip_allowed?(connection)

Checks if an IP address is in the whitelist.

ip_allowed?(arg1, ip)

reactivate_changeset(connection)

Changeset for reactivating a suspended connection.

requires_approval?(arg1, table)

Checks if a table requires approval based on the connection's approval mode.

revoke_changeset(connection, admin_user_id, reason \\ nil)

Changeset for revoking a connection.

settings_changeset(connection, attrs)

Changeset for updating connection settings.

stats_changeset(connection, attrs)

Changeset for updating connection statistics.

suspend_changeset(connection, admin_user_id, reason \\ nil)

Changeset for suspending a connection.

table_allowed?(connection, table)

Checks if a table is allowed to be accessed.

verify_auth_token(arg1, token)

Verifies an auth token against the stored hash.

verify_download_password(arg1, password)

Verifies a download password against the stored hash.

within_allowed_hours?(connection)

Checks if current time is within allowed hours.

within_download_limits?(connection)

Checks if a connection is within download limits.

within_record_limits?(connection)

Checks if a connection is within record limits.