import { Msg } from "nats"; import { Asset, UploadStatus } from "../cosmo/asset"; import { Products, Space } from "../global"; import { High5ExecuteOnAgentRequest, High5ExecutionCancelRequest } from "../high5/space/execution"; import { CapturedRequest } from "../high5/space/request"; import { LicenseTier } from "../idp"; declare enum NatsSubject { IDP_USER_GENERAL = "hcloud.idp.user.${userId}.general", IDP_USER_PROFILE = "hcloud.idp.user.${userId}.profile", IDP_USER_NOTIFICATIONS = "hcloud.idp.user.${userId}.notifications", IDP_USER_ORGS = "hcloud.idp.user.${userId}.orgs", IDP_USER_INVITATIONS = "hcloud.idp.user.${userId}.invitations", IDP_USER_SECURITY_PATS = "hcloud.idp.user.${userId}.security.pats", IDP_USER_SECURITY_GENERAL = "hcloud.idp.user.${userId}.security.general", IDP_USER_LICENSE = "hcloud.idp.user.${userId}.license", IDP_USER_SETTINGS_OAUTH_REVOKE = "hcloud.idp.user.${userId}.settings.oauth.${oAuthAppId}.revoke", IDP_USER_MESSAGES = "hcloud.idp.user.${userId}.messages", IDP_ORGANIZATION = "hcloud.idp.organization.${base64orgName}", IDP_ORGANIZATION_INVITATIONS = "hcloud.idp.organization.${base64orgName}.invitations", IDP_ORGANIZATION_MEMBERS = "hcloud.idp.organization.${base64orgName}.members", IDP_ORGANIZATION_MEMBERS_EXECUTION_TARGET = "hcloud.idp.organization.${base64orgName}.members.${base64email}.executionTarget", IDP_ORGANIZATION_TEAMS = "hcloud.idp.organization.${base64orgName}.teams", IDP_ORGANIZATION_TEAM_MEMBERS = "hcloud.idp.organization.${base64orgName}.teams.${base64teamName}.members", IDP_ORGANIZATION_LICENSE = "hcloud.idp.organization.${base64orgName}.license", IDP_ORGANIZATION_SETTINGS_OAUTHAPP = "hcloud.idp.organization.${base64orgName}.settings.oauthapp.${oAuthAppId}", IDP_ORGANIZATION_SERVICE_ACCOUNTS = "hcloud.idp.organization.${base64orgName}.serviceAccounts", HIGH5_SPACES = "hcloud.high5.organization.${base64orgName}.spaces", HIGH5_SPACE_PERMISSIONS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.permissions", HIGH5_STREAM_EXECUTE = "hcloud.high5.organization.${organizationId}.stream.execute.${base64email}", HIGH5_STREAM_CANCEL = "hcloud.high5.organization.${organizationId}.stream.execute.${base64email}",// eslint-disable-line @typescript-eslint/no-duplicate-enum-values HIGH5_STREAM_DEBUG_STOPPED = "hcloud.high5.organization.${organizationId}.stream.execute.${base64email}.${executionId}.stopped", HIGH5_STREAM_DEBUG_COMMAND = "hcloud.high5.organization.${organizationId}.stream.execute.${base64email}.${executionSecret}.command", HIGH5_EVENTS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.events", HIGH5_STREAMS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.streams", HIGH5_EVENT_STREAMS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.events.${base64eventName}.streams", HIGH5_SECRETS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.secrets", HIGH5_SETTINGS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.settings", HIGH5_WEBHOOKS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.webhooks", HIGH5_WEBHOOK_LOGS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.webhooks.${webhookId}.logs", HIGH5_CATALOGS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.catalogs", HIGH5_NODES = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.node", High5_DESIGN = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.events.${base64eventName}.streams.${streamId}.design", High5_DESIGN_DELTA = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.events.${base64eventName}.streams.${streamId}.design.delta", HIGH5_SNAPSHOTS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.events.${base64eventName}.streams.${streamId}.snapshots", HIGH5_WAVE_ENGINE_LATEST = "hcloud.high5.wave.engine.latest", HIGH5_SPACES_POOLS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.pools.>", HIGH5_SPACES_POOL = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.pools.${base64poolName}", HIGH5_DATABASES = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.databases", HIGH5_DOCUMENTS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.databases.${base64databaseName}.documents", HIGH5_JOBS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.jobs", HIGH5_JOB_LOGS = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.jobs.${jobId}.logs", HIGH5_CAPTURED_REQUEST = "hcloud.high5.organization.${base64orgName}.spaces.${base64spaceName}.request.catch", COSMO_SPACES = "hcloud.cosmo.organization.${base64orgName}.spaces", COSMO_NAMESPACES = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.namespaces", COSMO_ASSETS = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.assets", COSMO_STACKS = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.stacks", COSMO_CROSS_SPACES_ASSETS = "hcloud.cosmo.organization.${base64orgName}.spaces.*.assets", COSMO_COMMENTS = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.namespaces.${base64namespaceName}.assets.${assetId}.comments", COSMO_SHARE = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.share", COSMO_TAGS_NAMESPACE = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.namespaces.${base64namespaceName}.tags", COSMO_TAGS_ASSET = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.namespaces.${base64namespaceName}.assets.${assetId}.tags", COSMO_ROLES = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.roles", COSMO_STATUS = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.namespaces.${base64namespaceName}.assets.${assetId}.status", COSMO_METADATA = "hcloud.cosmo.organization.${base64orgName}.spaces.${base64spaceName}.namespaces.${base64namespaceName}.metadata", MOTHERSHIP_AGENT_CONNECTION = "hcloud.mothership.organization.${base64orgName}.agent.connection", AUDITOR_LOGS = "hcloud.auditor.organization.${base64orgName}.logs", DEBUG_NAMESPACE = "hcloud.debug.namespace.${product}" } declare enum NatsMessageType { ADD = "ADD", UPDATE = "UPDATE", DELETE = "DELETE", EXECUTE = "EXECUTE", CANCEL = "CANCEL" } declare enum NatsObjectType { DEBUG = "DEBUG", USER = "USER", OAUTH = "OAUTH", ORGANIZATION = "ORGANIZATION", ORGANIZATION_INVITATION = "ORGANIZATION_INVITATION", ORGANIZATION_MEMBER = "ORGANIZATION_MEMBER", ORGANIZATION_LICENSE = "ORGANIZATION_LICENSE", PAT = "PAT", TEAM = "TEAM", NOTIFICATIONS = "NOTIFICATIONS", GENERAL_SETTINGS = "GENERAL_SETTINGS", SPACE = "SPACE", SPACE_PERMISSION = "SPACE_PERMISSION", DESIGN = "DESIGN", SNAPSHOT = "SNAPSHOT", EVENT = "EVENT", EXECUTION = "EXECUTION", NODE = "NODE", STREAM = "STREAM", WEBHOOK = "WEBHOOK", WEBHOOK_LOG = "WEBHOOK_LOG", SECRET = "SECRET", CATALOG = "CATALOG", POOL = "POOL", AUDIT_LOG = "AUDIT_LOG", MAIL = "MAIL", JOB = "JOB", JOB_ID = "JOB_ID", JOB_LOG = "JOB_LOG", DATABASE = "DATABASE", DOCUMENT = "DOCUMENT", AGENT = "AGENT", MESSAGE = "MESSAGE", ASSET = "ASSET", STACK = "STACK", COMMENT = "COMMENT", TAG = "TAG", SHARE = "SHARE", PRODUCTION = "PRODUCTION", LOCATION = "LOCATION", FOLDER = "FOLDER", ROLE = "ROLE", STATUS = "STATUS", REFERENCE = "REFERENCE", REQUEST = "REQUEST" } interface NatsMessage { type: NatsMessageType; object: NatsObject; objectType: NatsObjectType; } interface NatsObject extends NatsNameObject, NatsIdObject, NatsMemberObject, NatsSecretObject, NatsExecTargetObject, High5ExecuteOnAgentRequest, High5ExecutionCancelRequest, CapturedRequest, NatsLicenseObject, NatsCustomNodeObject, NatsAssetObject, NatsIdNoUnderscoreObject, NatsTargetObject, NatsCosmoStatusObject { [NatsSubject.IDP_USER_GENERAL]: NatsIdObject; [NatsSubject.IDP_USER_PROFILE]: NatsIdObject; [NatsSubject.IDP_USER_SECURITY_PATS]: NatsIdObject; [NatsSubject.IDP_USER_SECURITY_GENERAL]: unknown; [NatsSubject.IDP_USER_NOTIFICATIONS]: NatsIdObject; [NatsSubject.IDP_USER_INVITATIONS]: NatsIdObject; [NatsSubject.IDP_USER_LICENSE]: NatsIdObject; [NatsSubject.IDP_ORGANIZATION_INVITATIONS]: NatsIdObject; [NatsSubject.IDP_ORGANIZATION_MEMBERS]: NatsMemberObject; [NatsSubject.IDP_ORGANIZATION_MEMBERS_EXECUTION_TARGET]: NatsExecTargetObject; [NatsSubject.IDP_ORGANIZATION_TEAMS]: NatsNameObject; [NatsSubject.IDP_ORGANIZATION_TEAM_MEMBERS]: NatsIdObject; [NatsSubject.IDP_ORGANIZATION_LICENSE]: NatsLicenseObject; [NatsSubject.HIGH5_SPACES]: NatsNameObject; [NatsSubject.HIGH5_SPACE_PERMISSIONS]: NatsIdObject; [NatsSubject.HIGH5_STREAM_EXECUTE]: High5ExecuteOnAgentRequest | High5ExecutionCancelRequest; [NatsSubject.HIGH5_STREAM_CANCEL]: High5ExecuteOnAgentRequest | High5ExecutionCancelRequest; [NatsSubject.HIGH5_EVENTS]: NatsNameObject; [NatsSubject.HIGH5_STREAMS]: NatsIdObject; [NatsSubject.HIGH5_EVENT_STREAMS]: NatsIdObject; [NatsSubject.High5_DESIGN]: NatsIdObject; [NatsSubject.High5_DESIGN_DELTA]: NatsIdObject; [NatsSubject.HIGH5_SNAPSHOTS]: NatsIdObject; [NatsSubject.HIGH5_NODES]: NatsCustomNodeObject; [NatsSubject.HIGH5_SECRETS]: NatsSecretObject; [NatsSubject.HIGH5_SETTINGS]: unknown; [NatsSubject.HIGH5_WEBHOOKS]: NatsIdObject; [NatsSubject.HIGH5_SPACES_POOLS]: NatsPoolObject; [NatsSubject.HIGH5_WEBHOOK_LOGS]: NatsIdObject; [NatsSubject.HIGH5_CATALOGS]: NatsIdObject; [NatsSubject.HIGH5_DATABASES]: NatsNameObject; [NatsSubject.HIGH5_DOCUMENTS]: NatsNameObject; [NatsSubject.HIGH5_JOBS]: NatsIdObject; [NatsSubject.HIGH5_JOB_LOGS]: NatsIdObject; [NatsSubject.HIGH5_CAPTURED_REQUEST]: CapturedRequest; [NatsSubject.COSMO_ASSETS]: NatsAssetObject[]; [NatsSubject.COSMO_STACKS]: NatsAssetObject[]; [NatsSubject.COSMO_SHARE]: NatsIdObject; [NatsSubject.COSMO_ROLES]: NatsIdObject; [NatsSubject.COSMO_STATUS]: NatsCosmoStatusObject; [NatsSubject.COSMO_METADATA]: NatsCosmoReferenceObject; [NatsSubject.MOTHERSHIP_AGENT_CONNECTION]: NatsTargetObject; [NatsSubject.AUDITOR_LOGS]: NatsIdObject; [NatsSubject.DEBUG_NAMESPACE]: string; } interface NatsNameObject { name: string; oldName?: string; } interface NatsIdObject { _id: string; } interface NatsIdNoUnderscoreObject { id: string; } interface NatsAssetObject { _id: string; parent?: { _id: string; name: string; type: "ASSET" | "SPACE" | "PRODUCTION" | "PROJECT" | "FOLDER"; }; type?: "ASSET" | "SPACE" | "PRODUCTION" | "PROJECT" | "FOLDER"; progress?: number; uploadStatus?: UploadStatus; breadcrumb?: (Asset | Space)[] | undefined; } interface NatsMemberObject { userId: string; } interface NatsExecTargetObject extends NatsMemberObject { executionTarget: boolean; } interface NatsSecretObject { secretKey: string; } interface NatsLicenseObject { newTier: LicenseTier; } interface NatsCustomNodeObject extends NatsIdObject { updatedNodeId?: string; } interface NatsPoolObject extends NatsIdObject { name: string; targets: string[]; } interface NatsTargetObject { target: string; } interface NatsCosmoReferenceObject { refId: string; } interface NatsCosmoStatusObject extends NatsCosmoReferenceObject { status: "approved" | "rejected" | "none"; } type NatsCallback = (err: Error | null, msg?: NatsMessage, rawMsg?: Msg) => void; /** * This helper class creates subject strings to be used with nats.subscribe and nats.publish */ declare class NatsSubjects { static IDP: { new (): {}; User: { new (): {}; GENERAL: (userId: string) => string; PROFILE: (userId: string) => string; ORGS: (userId: string) => string; INVITATIONS: (userId: string) => string; NOTIFICATIONS: (userId: string) => string; LICENSE: (userId: string) => string; Security: { new (): {}; PATS: (userId: string) => string; GENERAL: (userId: string) => string; }; Settings: (userId: string) => { OAuth: { REVOKE: (oAuthAppId: string) => string; }; }; MESSAGES: (userId: string) => string; }; ORGANIZATION: (organizationName: string) => string; Organization: { new (): {}; INVITATIONS: (organizationName: string) => string; MEMBERS: (organizationName: string) => string & { EXECUTION_TARGET: (email: string) => string; }; TEAMS: (organizationName: string) => string; Teams: { new (): {}; MEMBERS: (organizationName: string, teamName: string) => string; }; LICENSE: (organizationName: string) => string; Settings: (organizationName: string) => { OAuthApp: (oAuthAppId: string) => string; }; ServiceAccounts: (organizationName: string) => string; }; }; static High5: { new (): {}; Execution: { new (): {}; EXECUTE: (organizationId: string, email: string) => string; CANCEL: (organizationId: string, email: string) => string; DEBUG: (organizationId: string, email: string) => { STOPPED: (executionId: string) => string; COMMAND: (executionSecret: string) => string; }; }; SPACES: (organizationName: string) => string; Space: { new (): {}; POOLS: (organizationName: string, spaceName: string) => string; POOL: (organizationName: string, spaceName: string, poolName: string) => string; PERMISSIONS: (organizationName: string, spaceName: string) => string; EVENTS: (organizationName: string, spaceName: string) => string; STREAMS: (organizationName: string, spaceName: string) => string; Event: { new (): {}; STREAMS: (organizationName: string, spaceName: string, eventName: string) => string; Stream: { new (): {}; DESIGN: (organizationName: string, spaceName: string, eventName: string, streamId: string) => string; DESIGN_DELTA: (organizationName: string, spaceName: string, eventName: string, streamId: string) => string; SNAPSHOTS: (organizationName: string, spaceName: string, eventName: string, streamId: string) => string; }; }; SECRETS: (organizationName: string, spaceName: string) => string; WEBHOOKS: (organizationName: string, spaceName: string) => string; Webhook: { new (): {}; LOGS: (organizationName: string, spaceName: string, webhookId: string) => string; }; SETTINGS: (organizationName: string, spaceName: string) => string; CATALOGS: (organizationName: string, spaceName: string) => string; NODES: (organizationName: string, spaceName: string) => string; DATABASES: (organizationName: string, spaceName: string) => string; Database: { new (): {}; DOCUMENTS: (organizationName: string, spaceName: string, databaseName: string) => string; }; Jobs: { new (): {}; JOBS: (organizationName: string, spaceName: string) => string; JOB_LOGS: (organizationName: string, spaceName: string, jobId: string) => string; }; CAPTURED_REQUEST: (organizationName: string, spaceName: string) => string; }; WAVE: { new (): {}; ENGINE: { new (): {}; LATEST: NatsSubject; }; }; }; static Mothership: { new (): {}; CONNECTION: (organizationName: string) => string; }; static Auditor: { new (): {}; LOGS: (organizationName: string) => string; }; static Logging: (product: Products) => string; static Cosmo: { new (): {}; SPACES: (organizationName: string) => string; Space: { new (): {}; NAMESPACES: (organizationName: string, spaceName: string) => string; Namespace: { new (): {}; TAGS: (organizationName: string, spaceName: string, namespaceName: string) => string; METADATA: (organizationName: string, spaceName: string, namespaceName: string) => string; }; ASSETS: (organizationName: string, spaceName: string) => string; STACKS: (organizationName: string, spaceName: string) => string; SHARES: (organizationName: string, spaceName: string) => string; ROLES: (organizationName: string, spaceName: string) => string; Asset: { new (): {}; COMMENTS: (organizationName: string, spaceName: string, namespaceName: string, assetId: string) => string; TAGS: (organizationName: string, spaceName: string, namespaceName: string, assetId: string) => string; STATUS: (organizationName: string, spaceName: string, namespaceName: string, assetId: string) => string; }; }; ASSETS: (organizationName: string) => string; }; private static replace; } export { NatsCallback, NatsMessage, NatsMessageType, NatsObject, NatsObjectType, NatsSubject, NatsSubjects, Msg as RawMsg };