import { RpcMethodV3 } from './commonTypes'; import { Common_FailedPreconditions as pushwoosh_rpc_errors_v3_Common_FailedPreconditions } from './pushwoosh_rpc_errors_v3'; export type ExternalSegmentsService_Create_FieldViolations = { reason: 'CREATE_FV_UNSPECIFIED'; field: string; description: string; } | { reason: 'CREATE_CONNECTION_REQUIRED'; field: string; description: string; } | { reason: 'CREATE_HOST_EMPTY'; field: string; description: string; } | { reason: 'CREATE_DATABASE_EMPTY'; field: string; description: string; } | { reason: 'CREATE_USER_EMPTY'; field: string; description: string; } | { reason: 'CREATE_QUERY_EMPTY'; field: string; description: string; } | { reason: 'CREATE_HOST_NOT_ALLOWED'; field: string; description: string; } | { reason: 'CREATE_NAME_EMPTY'; field: string; description: string; } | { reason: 'CREATE_NAME_TOO_LONG'; field: string; description: string; } | { reason: 'CREATE_CONNECTION_FAILED'; field: string; description: string; } | { reason: 'CREATE_PROJECT_ID_EMPTY'; field: string; description: string; } | { reason: 'CREATE_SERVICE_ACCOUNT_JSON_EMPTY'; field: string; description: string; }; export type ExternalSegmentsService_Update_FieldViolations = { reason: 'UPDATE_FV_UNSPECIFIED'; field: string; description: string; } | { reason: 'UPDATE_CODE_EMPTY'; field: string; description: string; } | { reason: 'UPDATE_HOST_EMPTY'; field: string; description: string; } | { reason: 'UPDATE_DATABASE_EMPTY'; field: string; description: string; } | { reason: 'UPDATE_USER_EMPTY'; field: string; description: string; } | { reason: 'UPDATE_QUERY_EMPTY'; field: string; description: string; } | { reason: 'UPDATE_HOST_NOT_ALLOWED'; field: string; description: string; } | { reason: 'UPDATE_NAME_EMPTY'; field: string; description: string; } | { reason: 'UPDATE_NAME_TOO_LONG'; field: string; description: string; } | { reason: 'UPDATE_CONNECTION_FAILED'; field: string; description: string; } | { reason: 'UPDATE_PROJECT_ID_EMPTY'; field: string; description: string; } | { reason: 'UPDATE_SERVICE_ACCOUNT_JSON_EMPTY'; field: string; description: string; }; export type ExternalSegmentsService_Update_FailedPreconditions = { type: 'UPDATE_FP_UNSPECIFIED'; description: string; } | { type: 'UPDATE_SEGMENT_NOT_FOUND'; description: string; } | { type: 'UPDATE_KIND_MISMATCH'; description: string; }; export type ExternalSegmentsService_Delete_FailedPreconditions = { type: 'DELETE_FP_UNSPECIFIED'; description: string; } | { type: 'DELETE_SEGMENT_NOT_FOUND'; description: string; }; export type ExternalSegmentsService_List = RpcMethodV3; export type ExternalSegmentsService_Get = RpcMethodV3; export type ExternalSegmentsService_Create = RpcMethodV3; export type ExternalSegmentsService_Update = RpcMethodV3; export type ExternalSegmentsService_Delete = RpcMethodV3; export type ExternalSegmentsService_CheckConnection = RpcMethodV3; export type ExternalSegmentsService_TestConnection = RpcMethodV3; /** * ExternalSegmentsService manages external segments: user populations materialized * from an external database (PostgreSQL / MySQL) via a user-supplied SQL query. * * Unlike regular segments, an external segment is not built from filter conditions. * It stores connection parameters and a query that must return a single "user_id" * column. The query is executed and the result materialized by the storage service * in background. * * The caller never deals with a raw connection string nor a database "kind": the * database type is implied by which connection message is set, and the backend * assembles the proper connection string from the structured parameters. */ export interface ExternalSegmentsService { /** Lists all external segments of an application (code XXXXX-XXXXX), each materialized from a user-supplied SQL/BigQuery query against an external database. Use to browse configured external segments before fetching one by code. */ List: ExternalSegmentsService_List; /** Returns one external segment by its code, including connection parameters (passwords/secrets omitted), the query, validity and last-refresh status. Use after list_external_segments to inspect a single segment. */ Get: ExternalSegmentsService_Get; /** Creates an external segment from structured DB connection parameters (PostgreSQL, MySQL or BigQuery) and a SQL query returning a user_id column, connecting to the external database to validate the query before saving. Use to define a new externally-sourced audience; the segment code is generated on creation. */ Create: ExternalSegmentsService_Create; /** Updates an external segment's name, connection parameters or query by code; only provided fields change and the database type is immutable. Re-validates the connection against the external database before saving. */ Update: ExternalSegmentsService_Update; /** Deletes an external segment and its companion filter by code, allowed only when the filter is not referenced by in-apps, presets, journeys, other filters or popup forms. Irreversible; the segment stops being targetable. */ Delete: ExternalSegmentsService_Delete; /** Connects to a stored external segment's database and runs its saved query, then records the outcome in the segment's valid flag. Use to re-check an existing segment; unlike test_external_segment_connection it persists the result. */ CheckConnection: ExternalSegmentsService_CheckConnection; /** Tests external database connection parameters supplied inline (optionally backfilling secrets from a saved segment by code) without persisting anything. Use from the create/edit form before saving; set check_query to also validate the query, otherwise only connectivity is checked. */ TestConnection: ExternalSegmentsService_TestConnection; } export type ExternalSegmentsService_Errors = { List: { failedPreconditions: pushwoosh_rpc_errors_v3_Common_FailedPreconditions; }; Get: { failedPreconditions: pushwoosh_rpc_errors_v3_Common_FailedPreconditions; }; Create: { fieldViolations: ExternalSegmentsService_Create_FieldViolations[]; failedPreconditions: pushwoosh_rpc_errors_v3_Common_FailedPreconditions; }; Update: { fieldViolations: ExternalSegmentsService_Update_FieldViolations[]; failedPreconditions: ExternalSegmentsService_Update_FailedPreconditions | pushwoosh_rpc_errors_v3_Common_FailedPreconditions; }; Delete: { failedPreconditions: ExternalSegmentsService_Delete_FailedPreconditions | pushwoosh_rpc_errors_v3_Common_FailedPreconditions; }; CheckConnection: { failedPreconditions: pushwoosh_rpc_errors_v3_Common_FailedPreconditions; }; TestConnection: { failedPreconditions: pushwoosh_rpc_errors_v3_Common_FailedPreconditions; }; }; /** * PostgresConnection holds PostgreSQL connection parameters. * The backend assembles them into a libpq connection string, e.g. * postgresql://user:password@host:port/database?sslmode=disable */ export type PostgresConnection = { /** Database server host. */ host: string; /** Database server port. Defaults to 5432 if zero. */ port: number; /** Database user. */ user: string; /** Database password. Write-only: never returned by read methods. */ password: string; /** Database name. */ database: string; /** * Any additional standard libpq connection parameters (e.g. * connect_timeout, application_name, target_session_attrs, options). * Keys must be valid libpq keywords. */ options: Record; /** * SSL/TLS mode: disable, require, verify-ca, verify-full. * Defaults to disable when empty. */ sslmode: string; /** * TLS material. All three are write-only: never returned by read methods. * On update, an empty value keeps the currently stored file (send it again * to replace it). They are stored as external segment files, not in the DSN. */ caCert: string; /** client certificate (sslcert) */ clientCert: string; /** client private key (sslkey) */ clientKey: string; }; /** * MysqlConnection holds MySQL connection parameters. * The backend assembles them into a go-sql-driver DSN, e.g. * user:password@tcp(host:port)/database?parseTime=true */ export type MysqlConnection = { /** Database server host. */ host: string; /** Database server port. Defaults to 3306 if zero. */ port: number; /** Database user. */ user: string; /** Database password. Write-only: never returned by read methods. */ password: string; /** Database name. */ database: string; /** * Any additional standard DSN parameters (e.g. tls, charset, collation, * parseTime, loc, timeout, readTimeout, writeTimeout). */ params: Record; }; /** * BigQueryConnection holds Google BigQuery connection parameters. The backend * stores them as a JSON blob in the connection params. */ export type BigQueryConnection = { /** Google Cloud project ID that runs (and is billed for) the query. */ projectId: string; /** * Service account JSON key with BigQuery access. * Write-only: never returned by read methods; on update an empty value keeps * the currently stored key. */ serviceAccountJson: string; /** * Optional processing location (e.g. "EU", "US", "europe-west3"). * When empty, BigQuery resolves it from the referenced dataset. */ location: string; }; export type ExternalSegment_connection_postgres = { type: 'postgres'; data: PostgresConnection; }; export type ExternalSegment_connection_mysql = { type: 'mysql'; data: MysqlConnection; }; export type ExternalSegment_connection_bigquery = { type: 'bigquery'; data: BigQueryConnection; }; export type ExternalSegment_connection = ExternalSegment_connection_postgres | ExternalSegment_connection_mysql | ExternalSegment_connection_bigquery; /** * ExternalSegment is the full representation returned by read methods. * It exposes neither the raw connection string nor a database "kind" enum: * the database type is conveyed by which connection message is set, and * passwords are never returned. */ export type ExternalSegment = { /** Owning application code. */ application: string; /** Unique (within application) external segment code, generated on creation. */ code: string; /** Human-readable name. Not unique. Free text, up to 100 characters. */ name: string; /** SQL query that returns a single "user_id" column. */ query: string; /** Whether the segment configuration is considered valid and usable. */ valid: boolean; /** Last time the segment was successfully refreshed. Unset if never refreshed. */ lastRequestedAt: Date; /** Error message from the last failed refresh. Empty if the last refresh succeeded. */ lastError: string; /** Materialized snapshot version, incremented on every successful refresh. */ generation: number; /** Segment creation time. */ createdAt: Date; connection: ExternalSegment_connection; }; export type ListRequest = { /** Application code to list external segments for. */ application?: string; }; export type ListResponse = { segments: ExternalSegment[]; }; export type GetRequest = { /** Owning application code. */ application?: string; /** External segment code. */ code?: string; }; export type GetResponse = { segment: ExternalSegment; }; export type CreateRequest_connection_postgres = { type: 'postgres'; data: PostgresConnection; }; export type CreateRequest_connection_mysql = { type: 'mysql'; data: MysqlConnection; }; export type CreateRequest_connection_bigquery = { type: 'bigquery'; data: BigQueryConnection; }; export type CreateRequest_connection = CreateRequest_connection_postgres | CreateRequest_connection_mysql | CreateRequest_connection_bigquery; export type CreateRequest = { /** Application code the segment belongs to. */ application?: string; /** Human-readable name. Required, not unique, up to 100 characters. */ name?: string; /** SQL query that must return a single "user_id" column. */ query?: string; connection: CreateRequest_connection; }; export type CreateResponse = { segment: ExternalSegment; }; export type UpdateRequest_connection_postgres = { type: 'postgres'; data: PostgresConnection; }; export type UpdateRequest_connection_mysql = { type: 'mysql'; data: MysqlConnection; }; export type UpdateRequest_connection_bigquery = { type: 'bigquery'; data: BigQueryConnection; }; export type UpdateRequest_connection = UpdateRequest_connection_postgres | UpdateRequest_connection_mysql | UpdateRequest_connection_bigquery; export type UpdateRequest = { /** Application code the segment belongs to. */ application?: string; /** External segment code to update. */ code?: string; /** * New name. If unset, the name is left unchanged. If set, it must be a * non-empty string of at most 100 characters. */ name?: string; /** New SQL query. If set, replaces the current value. */ query?: string; connection: UpdateRequest_connection; }; export type UpdateResponse = { segment: ExternalSegment; }; export type DeleteRequest = { /** Application code the segment belongs to. */ application?: string; /** External segment code to delete. */ code?: string; }; export type DeleteResponse = {}; export type CheckConnectionRequest = { /** Application code the segment belongs to. */ application?: string; /** External segment code to check. */ code?: string; }; export type CheckConnectionResponse = { /** Whether the database connection succeeded (also stored on the segment). */ valid: boolean; /** Connection error message when valid is false; empty otherwise. */ error: string; }; export type TestConnectionRequest_connection_postgres = { type: 'postgres'; data: PostgresConnection; }; export type TestConnectionRequest_connection_mysql = { type: 'mysql'; data: MysqlConnection; }; export type TestConnectionRequest_connection_bigquery = { type: 'bigquery'; data: BigQueryConnection; }; export type TestConnectionRequest_connection = TestConnectionRequest_connection_postgres | TestConnectionRequest_connection_mysql | TestConnectionRequest_connection_bigquery; export type TestConnectionRequest = { /** Application code the segment belongs to. */ application?: string; /** * Optional external segment code. When set, blank write-only secrets * (password / service account JSON) and TLS certificates are backfilled from * the stored segment, so an existing segment can be tested without re-entering * them. Leave empty when testing brand-new parameters on the create form. */ code?: string; /** SQL query to validate. Required (and only used) when check_query is true. */ query?: string; /** * When true, the query is executed to validate it (SQL: run it and read the * first row; BigQuery: dry-run). When false, only connectivity is checked. */ checkQuery?: boolean; connection: TestConnectionRequest_connection; }; export type TestConnectionResponse = { /** Whether the test succeeded. */ ok: boolean; /** Failure message when ok is false; empty otherwise. */ error: string; };