Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

5.0 KB
Raw Blame
import { stack } from '.';

/** Public OAuth identities remain stable when their processes move to the harness. */
export const AGENT_PUBLIC_URLS = {
  cognition: `https://document-cognition${stack === 'prod' ? '' : `-${stack}`}.macro.com`,
  mcp: `https://mcp-server${stack === 'prod' ? '' : `-${stack}`}.macro.com`,
};

/**
 * Service url for all macro services
 */
export enum ServiceUrl {
  APP_SERVICE_URL = 'APP_SERVICE_URL',
  PREVIEW_GATEWAY_URL = 'PREVIEW_GATEWAY_URL',
  SYNC_SERVICE_URL = 'SYNC_SERVICE_URL',
  EMAIL_SERVICE_URL = 'EMAIL_SERVICE_URL',
  STATIC_FILE_SERVICE_URL = 'STATIC_FILE_SERVICE_URL',
  NOTIFICATION_SERVICE_URL = 'NOTIFICATION_SERVICE_URL',
  AUTHENTICATION_SERVICE_URL = 'AUTHENTICATION_SERVICE_URL',
  DOCUMENT_STORAGE_SERVICE_URL = 'DOCUMENT_STORAGE_SERVICE_URL',
  CONNECTION_GATEWAY_URL = 'CONNECTION_GATEWAY_URL',
  DOCUMENT_COGNITION_SERVICE_URL = 'DOCUMENT_COGNITION_SERVICE_URL',
  LEXICAL_SERVICE_URL = 'LEXICAL_SERVICE_URL',
  UNFURL_SERVICE_URL = 'UNFURL_SERVICE_URL',
  AGENT_HARNESS_SERVICE_URL = 'AGENT_HARNESS_SERVICE_URL',
  AGENT_HARNESS_EGRESS_URL = 'AGENT_HARNESS_EGRESS_URL',
  MCP_SERVER_URL = 'MCP_SERVER_URL',
  CONNECT_API_URL = 'CONNECT_API_URL',
}

/**
 * Map of service URLs
 */
type ServiceUrlMap = {
  [K in ServiceUrl]: string;
};

/**
 * Dev Service URLs
 */
const DEV_SERVICE_URLS: ServiceUrlMap = {
  [ServiceUrl.APP_SERVICE_URL]: 'https://dev.macro.com',
  [ServiceUrl.PREVIEW_GATEWAY_URL]: 'https://dev-gateway.macro.com/preview',
  [ServiceUrl.SYNC_SERVICE_URL]:
    'https://sync-service-dev3.macroverse.workers.dev',
  [ServiceUrl.EMAIL_SERVICE_URL]: 'https://dev-gateway.macro.com/email',
  [ServiceUrl.STATIC_FILE_SERVICE_URL]:
    'https://static-file-service-dev.macro.com',
  [ServiceUrl.NOTIFICATION_SERVICE_URL]:
    'https://dev-gateway.macro.com/notification',
  [ServiceUrl.AUTHENTICATION_SERVICE_URL]: 'https://dev-gateway.macro.com/auth',
  [ServiceUrl.DOCUMENT_STORAGE_SERVICE_URL]:
    'https://dev-gateway.macro.com/dss',
  [ServiceUrl.CONNECTION_GATEWAY_URL]:
    'https://dev-gateway.macro.com/connection-gateway',
  [ServiceUrl.DOCUMENT_COGNITION_SERVICE_URL]:
    'https://dev-gateway.macro.com/cognition',
  [ServiceUrl.LEXICAL_SERVICE_URL]: 'https://dev-gateway.macro.com/lexical',
  [ServiceUrl.UNFURL_SERVICE_URL]: 'https://dev-gateway.macro.com/unfurl',
  [ServiceUrl.AGENT_HARNESS_SERVICE_URL]:
    'https://dev-gateway.macro.com/agent-harness',
  [ServiceUrl.AGENT_HARNESS_EGRESS_URL]:
    'https://dev-gateway.macro.com/agent-harness-egress',
  [ServiceUrl.MCP_SERVER_URL]: 'https://dev-gateway.macro.com/mcp',
  [ServiceUrl.CONNECT_API_URL]: 'https://connect-dev.macro.com',
};

/**
 * Prod Service URLs
 */
const PROD_SERVICE_URLS: ServiceUrlMap = {
  [ServiceUrl.APP_SERVICE_URL]: 'https://macro.com',
  [ServiceUrl.PREVIEW_GATEWAY_URL]: 'https://gateway.macro.com/preview',
  [ServiceUrl.SYNC_SERVICE_URL]:
    'https://sync-service-prod2.macroverse.workers.dev',
  [ServiceUrl.EMAIL_SERVICE_URL]: 'https://gateway.macro.com/email',
  [ServiceUrl.STATIC_FILE_SERVICE_URL]: 'https://static-file-service.macro.com',
  [ServiceUrl.NOTIFICATION_SERVICE_URL]:
    'https://gateway.macro.com/notification',
  [ServiceUrl.AUTHENTICATION_SERVICE_URL]: 'https://gateway.macro.com/auth',
  [ServiceUrl.DOCUMENT_STORAGE_SERVICE_URL]: 'https://gateway.macro.com/dss',
  [ServiceUrl.CONNECTION_GATEWAY_URL]:
    'https://gateway.macro.com/connection-gateway',
  [ServiceUrl.DOCUMENT_COGNITION_SERVICE_URL]:
    'https://gateway.macro.com/cognition',
  [ServiceUrl.LEXICAL_SERVICE_URL]: 'https://gateway.macro.com/lexical',
  [ServiceUrl.UNFURL_SERVICE_URL]: 'https://gateway.macro.com/unfurl',
  [ServiceUrl.AGENT_HARNESS_SERVICE_URL]:
    'https://gateway.macro.com/agent-harness',
  [ServiceUrl.AGENT_HARNESS_EGRESS_URL]:
    'https://gateway.macro.com/agent-harness-egress',
  [ServiceUrl.MCP_SERVER_URL]: 'https://gateway.macro.com/mcp',
  [ServiceUrl.CONNECT_API_URL]: 'https://connect.macro.com',
};

/**
 * Singleton for service URLs
 */
let _SERVICE_URL_MAP: ServiceUrlMap | undefined = undefined;

/**
 * Gets the service URL map for the stack
 * @throws Error if there is no matching service for the given stack
 * @returns ServiceUrlMap
 */
function getServiceUrls(): ServiceUrlMap {
  if (stack === 'dev') {
    return DEV_SERVICE_URLS;
  } else if (stack === 'prod') {
    return PROD_SERVICE_URLS;
  }

  throw new Error(`Unknown stack: ${stack}`);
}

/**
 * Gets the service URL for a given service
 * @param service Service to get URL for
 * @returns Service URL
 */
export function getServiceUrl(service: ServiceUrl): string {
  // Initialize the singleton
  if (!_SERVICE_URL_MAP) {
    _SERVICE_URL_MAP = getServiceUrls();
  }

  return _SERVICE_URL_MAP[service];
}

/**
 * Gets the domain name for a given service
 * @param service Service to get URL for
 * @returns Domain name
 */
export function getDomainName(service: ServiceUrl): string {
  // Initialize the singleton
  if (!_SERVICE_URL_MAP) {
    _SERVICE_URL_MAP = getServiceUrls();
  }

  return _SERVICE_URL_MAP[service].replace('https://', '');
}