Skip to content

Open-source live-chat, email support, omni-channel desk. An alternative to Intercom, Zendesk, Salesforce Service Cloud etc. 🔥💬

2.7 KB
Raw Blame
module PortalConfigSchema
  extend ActiveSupport::Concern

  # Per-locale overrides for portal level fields. Any locale present in
  # `allowed_locales` may carry its own `name`, `page_title` and `header_text`.
  # Missing values fall back to the default locale and finally to the base column.
  LOCALE_TRANSLATION_SCHEMA = {
    'type' => 'object',
    'properties' => {
      'name' => { 'type' => %w[string null] },
      'page_title' => { 'type' => %w[string null] },
      'header_text' => { 'type' => %w[string null] }
    },
    'additionalProperties' => false
  }.freeze

  # Per-locale recommended content for the portal home page: an ordered list of
  # `category_ids` (the hero's "Recommended topics" pills) and `article_ids` (the
  # "Recommended" articles section). When empty, the portal uses its defaults.
  POPULAR_CONTENT_SCHEMA = {
    'type' => 'object',
    'properties' => {
      'category_ids' => { 'type' => %w[array null], 'items' => { 'type' => 'integer' } },
      'article_ids' => { 'type' => %w[array null], 'items' => { 'type' => 'integer' } }
    },
    'additionalProperties' => false
  }.freeze

  CONFIG_PARAMS_SCHEMA = {
    'type' => 'object',
    'properties' => {
      'allowed_locales' => { 'type' => %w[array null], 'items' => { 'type' => 'string' } },
      'default_locale' => { 'type' => %w[string null] },
      'draft_locales' => { 'type' => %w[array null], 'items' => { 'type' => 'string' } },
      'layout' => { 'type' => %w[string null], 'enum' => ['classic', 'documentation', nil] },
      # TODO: unused reserved key; remove with a migration that scrubs it from existing portals' config
      'website_token' => { 'type' => %w[string null] },
      'social_profiles' => { 'type' => %w[object null] },
      'locale_translations' => {
        'type' => %w[object null],
        'additionalProperties' => LOCALE_TRANSLATION_SCHEMA
      },
      'popular_content' => {
        'type' => %w[object null],
        'additionalProperties' => POPULAR_CONTENT_SCHEMA
      },
      # Analytics ids grouped under one object (see Portal::ANALYTICS_CONFIG_FORMATS).
      'analytics' => {
        'type' => %w[object null],
        'properties' => {
          'gtm_container_id' => { 'type' => %w[string null] },
          'ga4_measurement_id' => { 'type' => %w[string null] },
          'hotjar_site_id' => { 'type' => %w[string null] },
          'plausible_domain' => { 'type' => %w[string null] },
          'amplitude_api_key' => { 'type' => %w[string null] },
          'clarity_project_id' => { 'type' => %w[string null] },
          'meta_pixel_id' => { 'type' => %w[string null] }
        },
        'additionalProperties' => false
      }
    },
    'required' => [],
    'additionalProperties' => true
  }.to_json.freeze
end