@segmentstream/app · Q–T
20 public exports from @segmentstream/app.
Public exports
QueryParameterValue
A value bound to a named `@parameter`; never spliced into the SQL text.
type QueryParameterValue = string | number | bigint | boolean | Date | TypedParameter | ReadonlyArray<string | number | bigint | boolean | Date>;
QueryParameters
type QueryParameters = Readonly<Record<string, QueryParameterValue>>;
RelativePeriod
A period relative to today, which the platform resolves to two inclusive dates: `today`, `yesterday`; the whole current or previous week, month, quarter or year (`this month`, `last quarter`); the current one through today (`this year to date`); the N days ending yesterday (`last 7 days`); or the N whole weeks, months, quarters or years before the current one (`last 4 weeks`). N is at least 1, weeks start on Monday, and a period covers at most 3660 days.
type RelativePeriod = "today" | "yesterday" | `this ${CalendarUnit}` | `this ${CalendarUnit} to date` | `last ${CalendarUnit}` | `last ${number} ${"days" | "weeks" | "months" | "quarters" | "years"}`;RequestOptions
interface RequestOptions {
readonly signal?: AbortSignal;
}RouteHandler
type RouteHandler = (request: NextRequest) => Promise<Response>;
SIGN_IN_LINK_INVALID
An emailed sign-in link that Neon Auth rejected: expired, already used or unknown.
const SIGN_IN_LINK_INVALID = "sign_in_link_invalid"
SIGN_IN_REFUSED
The person signed in, but the ontology refused that sign-in for this app: the member is deactivated, or another sign-in method already holds their address.
const SIGN_IN_REFUSED = "sign_in_refused"
ScopedPermission
A permission the user holds only for the records its `where` matches, as `/me` sends it. `where` is the condition in the wire form of a query: snake_case field names, and the signed-in user as `{ "$me": [] }` or a path from them as `{ "$me": ["staff_member", "division"] }`. It is informational, for what the app shows; the ontology service enforces it on every read and write.
interface ScopedPermission {
readonly permission: string;
readonly where: {
readonly [field: string]: JsonValue;
};
}SegmentStreamApiError
A failed SegmentStream or ontology request; `code` is the API error code, such as `not_invited`, `forbidden`, `action_rejected` or `query_timeout`.
class SegmentStreamApiError extends Error {
readonly code: string;
readonly status: number;
readonly detail: string;
readonly requestId: string | undefined;
readonly retryable: boolean;
readonly queryId: string | undefined;
readonly issues: ReadonlyArray<ApiIssue>;
readonly limit: ApiLimit | undefined;
readonly retryAfterSeconds: number | undefined;
readonly keyConsumed: boolean;
readonly refusal: string | undefined;
readonly connect: string | undefined;
constructor(input: {
readonly code: string;
readonly status: number;
readonly detail: string;
readonly requestId?: string | undefined;
readonly retryable?: boolean;
readonly queryId?: string | undefined;
readonly issues?: ReadonlyArray<ApiIssue>;
readonly limit?: ApiLimit | undefined;
readonly retryAfterSeconds?: number | undefined;
readonly keyConsumed?: boolean;
readonly refusal?: string | undefined;
readonly connect?: string | undefined;
readonly cause?: unknown;
});
}SegmentStreamApp
The app's SegmentStream integration. `O` is the type of the app's ontology, `typeof import("../../ontology").default`, which types {@link SegmentStreamApp.ontology}.
interface SegmentStreamApp<O = unknown> {
readonly deployment: DeploymentObservation;
readonly authentication: AuthenticationMethod;
readonly proxy: (options?: ProxyOptions) => SegmentStreamProxy;
readonly authHandlers: () => AuthRouteHandlers;
readonly handlers: () => SegmentStreamRouteHandlers;
readonly getUser: (options?: UserOptions) => Promise<AppUser | null>;
readonly requireUser: (options?: UserOptions) => Promise<AppUser>;
readonly can: (permission: string, options?: UserOptions) => Promise<boolean>;
readonly signOut: (options?: SignOutOptions) => Promise<never>;
readonly getAccessToken: () => Promise<string | null>;
readonly fetch: (path: string, init?: RequestInit) => Promise<Response>;
readonly warehouse: WarehouseClient;
readonly jobs: JobsClient;
readonly ontology: OntologyClient<O>;
readonly oauth: AgentAuthorizations;
readonly agent: AgentIdentities;
readonly connections: UserConnections;
}SegmentStreamAppConfig
interface SegmentStreamAppConfig {
readonly workspaceId: string;
readonly organizationId: string;
readonly baseUrl?: string;
readonly shareWorkspaceMemberships?: boolean;
readonly channels?: Readonly<Record<string, boolean>>;
}SegmentStreamProxy
type SegmentStreamProxy = (request: NextRequest) => Promise<NextResponse>;
SegmentStreamRouteHandlers
interface SegmentStreamRouteHandlers {
readonly GET: RouteHandler;
readonly POST: RouteHandler;
}SelectedRecord
Selected fields are required; other fields may be absent. Dynamic lists promise only id.
type SelectedRecord<Row, Selection extends readonly string[] | undefined> = Selection extends readonly string[] ? Partial<Row> & (number extends Selection["length"] ? object : Pick<Row, Extract<Selection[number], keyof Row>>) & {
readonly id: string;
} : Row;SignOutOptions
interface SignOutOptions {
readonly redirectTo?: string;
}SmartPolicyInput
Channel-independent group policy. All names and aliases are supplied by the workspace.
interface SmartPolicyInput {
readonly model?: string;
readonly instructions?: string | {
readonly append?: string;
readonly replace?: string;
readonly file?: string;
};
readonly criteria?: {
readonly observe?: string;
readonly reply?: string;
};
readonly context?: {
readonly messages?: number;
readonly includeAgentDescription?: boolean;
readonly includeAgentInstructions?: boolean | {
readonly maxChars: number;
};
readonly includeChatGuidance?: boolean;
readonly includeParticipants?: boolean;
};
readonly engagement?: {
readonly policy?: string;
readonly agentAliases?: ReadonlyArray<string>;
readonly idleMinutes?: number;
readonly humanExchangeMinutes?: number;
readonly humanQuestionMinutes?: number;
readonly inferredMaxMinutes?: number;
readonly burst?: {
readonly quietSeconds?: number;
readonly maxSeconds?: number;
readonly gapSeconds?: number;
};
readonly followUpMinutes?: number;
readonly engagementMinutes?: number;
readonly openQuestionMinutes?: number | "unlimited";
readonly addresseeGate?: boolean;
};
readonly thresholds?: {
readonly continuation?: number;
readonly inferredContinuation?: number;
readonly contested?: number;
readonly ambient?: number;
readonly humanExchange?: number;
readonly engaged?: number;
readonly neutral?: number;
readonly humanThread?: number;
readonly reply?: number;
readonly defer?: number;
};
readonly timeoutSeconds?: number;
}TypedParameter
A value with an explicit warehouse type, created with the `sql` helpers.
interface TypedParameter {
readonly [TYPED]: true;
readonly type: ParameterType;
readonly value?: string;
readonly values?: readonly string[];
}readConnectionReturn
Reads a connection return from a URL fragment such as `#connection=gmail&confirmation=…`. `null` for any other fragment. Only the fragment is read: a `confirmation` in the query string is not one the platform sent, and is ignored.
function readConnectionReturn(hash: string): ConnectionReturn | null;
sql
Explicit parameter types for values JavaScript cannot express unambiguously. ```ts await segmentstream.warehouse.query( "SELECT * FROM gold.orders WHERE order_date >=
const sql: {
readonly string: (value: string) => TypedParameter;
readonly int64: (value: number | bigint | string) => TypedParameter;
readonly float64: (value: number) => TypedParameter;
readonly numeric: (value: string | number) => TypedParameter;
readonly bignumeric: (value: string | number) => TypedParameter;
readonly bool: (value: boolean) => TypedParameter;
readonly date: (value: string | Date) => TypedParameter;
readonly datetime: (value: string) => TypedParameter;
readonly timestamp: (value: string | Date) => TypedParameter;
readonly array: (type: ParameterType, values: ReadonlyArray<string | number | bigint | boolean | Date>) => {
[TYPED]: true;
type: "STRING" | "INT64" | "FLOAT64" | "NUMERIC" | "BIGNUMERIC" | "BOOL" | "DATE" | "DATETIME" | "TIMESTAMP";
values: string[];
};
}takeConnectionReturn
Takes the connection return the platform sent to the connections page: reads it from the URL fragment and removes the fragment from the address with `history.replaceState`, keeping the path and the query. When the page rendered {@link CONNECTION_RETURN_SCRIPT}, that script has already done so before any other script ran, and this returns what it read. Call it once, on the client, before anything else on the page reads the address; a second call returns `null`. The page then confirms the code for a signed-in member and discards it when nobody is signed in.
function takeConnectionReturn(target?: ReturnWindow): ConnectionReturn | null;