Skip to main content

@getriebe/server

Compose an Effect server and register Service Task handlers and connectors.

Source revision 49560371f6cd34d30383df5619df46969c594ae4.

export interface AdministratorOptions {
readonly username?: string;
readonly password: string;
}
export interface BootstrapOptions {
readonly demo?: boolean;
readonly administrator?: AdministratorOptions;
}
export declare class CommitUnknown extends CommitUnknown_base<{
readonly cause: PersistenceError;
}> {
}
export interface ConnectorDescription {
readonly id: string;
readonly version: string;
readonly label: string;
readonly settings: readonly ConnectorSetting[];
readonly inputs: readonly ValueKind[];
readonly outputs: readonly ValueKind[];
}
export declare class ConnectorFailure extends ConnectorFailure_base<{
readonly reason: "connection" | "transport" | "http" | "response";
readonly unknownOutcome?: boolean;
readonly httpStatus?: number;
}> {
}
export interface ConnectorSetting {
readonly id: string;
readonly label: string;
readonly choices?: readonly string[];
readonly pattern?: string;
readonly hint?: string;
}
export declare function defineEffectServiceHandler<const I extends ServiceFields, const O extends ServiceFields, E>(contract: {
readonly inputs: I;
readonly outputs: O;
readonly faultCodes?: readonly string[];
}, run: (input: Values<I>, context: ServiceContext) => Effect.Effect<Values<O> | ServiceFault, E>): ServiceHandler;
export declare function defineMessageAdapter<const F extends Fields>(binding: {
readonly message: {
readonly type: MessageType;
readonly fields: F;
};
readonly recipientField: Extract<keyof F, string>;
readonly recipientAccounts: ReadonlyMap<string, string>;
readonly verifyAcceptance?: NonNullable<MessageAdapter["verifyAcceptance"]>;
}, submit: (delivery: OutgoingMessage, payload: MessageValues<F>) => Effect.Effect<TransportDecision, unknown>): MessageAdapter;
export declare function defineServiceHandler<const I extends ServiceFields, const O extends ServiceFields>(contract: {
readonly inputs: I;
readonly outputs: O;
readonly faultCodes?: readonly string[];
}, run: (input: Values<I>, context: ServiceContext) => Values<O> | ServiceFault): ServiceHandler;
export declare function fault(code: string): ServiceFault;

The typed Effect HTTP API value for HttpApiClient.make. See the HTTP operation and schema reference for its groups and endpoints.

export declare function getriebeOpenApi(): OpenApi.OpenAPISpec;
export interface HttpConnectionOptions {
readonly name: string;
readonly baseUrl: string;
readonly auth?: {
readonly header: string;
readonly value: Redacted.Redacted<string>;
readonly format?: "raw" | "bearer";
};
}
export declare class IdentityProviderFailure extends IdentityProviderFailure_base<{
readonly cause: unknown;
}> {
}
export interface LoginCredentials {
username: string;
password: string;
}
export type LoginIdentity = Omit<SessionActor, "expiresAt">;

Resolve credentials to an existing account and its session version.

export type LoginIdentityProvider = (credentials: LoginCredentials) => Effect.Effect<LoginIdentity | undefined, IdentityProviderFailure>;
export declare const makeServer: (options?: ServerOptions | undefined) => Effect.Effect<{
listen: (address: Parameters<(address: {
readonly host: string;
readonly port: number;
}) => Effect.Effect<string, HttpServerError.ServeError | StartupConfigurationError, Scope.Scope>>[0]) => Effect.Effect<string, HttpServerError.ServeError | StartupConfigurationError, never>;
}, StartupConfigurationError | import("./persistence/transactions.ts").StorageFailure, Scope.Scope>;
export interface MessageAdapter {
readonly message: MessageContract;
readonly recipientField: string;
readonly recipientAccounts: ReadonlyMap<string, string>;
readonly submit: (delivery: OutgoingMessage, payload: ProcessData) => Effect.Effect<TransportDecision, unknown>;
readonly verifyAcceptance?: (delivery: OutgoingMessage, reference: string) => Effect.Effect<boolean, unknown>;
}
export type MessageSenderGrants = ReadonlyMap<string, readonly MessageType[]>;
export interface ModelRegistryOptions {
readonly availableCapabilities?: ReadonlySet<BpmnCapability>;
readonly serviceHandlerContracts?: ReadonlyMap<string, ServiceContract>;
readonly behaviorLimits?: Partial<BehaviorLimits>;
readonly authorizedVersionIds?: VersionVisibility;
}
export interface OutgoingMessage {
readonly dispatchId: string;
readonly messageId: string;
readonly message: MessageType;
readonly recipientAccountId: string;
}
export type Permission = "admin" | "model_manage" | "process_start";
export interface Profile {
readonly user: {
readonly id: string;
readonly username: string;
readonly displayName: string;
};
readonly roles: readonly string[];
readonly permissions: readonly Permission[];
}
export interface ServerOptions {
readonly storage?: StorageOptions;
readonly examples?: boolean;
readonly transactions?: TransactionService;
readonly bootstrap?: BootstrapOptions;
readonly secureCookies?: boolean;
readonly loginIdentityProvider?: LoginIdentityProvider;
readonly modelRegistry?: ModelRegistryOptions;
readonly messageSenderGrants?: MessageSenderGrants;
readonly messageAdapters?: readonly MessageAdapter[];
readonly serviceConnectors?: readonly ServiceConnector[];
readonly httpConnections?: readonly HttpConnectionOptions[];
readonly serviceHandlers?: ReadonlyMap<string, ServiceHandler>;
readonly javascriptScripts?: {
readonly timeoutMs?: number;
};
}
export interface ServiceConnector {
readonly description: ConnectorDescription;
readonly connections: readonly string[];
readonly invoke: (request: {
readonly binding: BpmnConnectorBinding;
readonly contract: ServiceContract;
readonly inputs: ProcessData;
readonly context: ServiceContext;
}) => Effect.Effect<ProcessData | ServiceFault, ConnectorFailure>;
}
export interface ServiceContext {
readonly instanceId: string;
readonly versionId: string;
readonly executionId: string;
readonly attemptId: string;
}
export declare class ServiceFault {
readonly [serviceFaultBrand] = true;
readonly code: string;
constructor(code: string);
}
export interface ServiceHandler extends ServiceContract {
readonly invoke: (inputs: ProcessData, context: ServiceContext) => Effect.Effect<ProcessData | ServiceFault, ServiceInvocationError>;
}
export declare class ServiceInvocationError extends ServiceInvocationError_base<{
readonly cause: unknown;
}> {
}
export declare class StorageConflict extends StorageConflict_base<{
readonly cause: PersistenceError;
}> {
}
export type StorageFailure = StorageConflict | CommitUnknown | StorageUnavailable | StorageFault;
export declare class StorageFault extends StorageFault_base<{
readonly cause: PersistenceError;
}> {
}
export type StorageOptions = {
readonly kind: "sqlite";
readonly path?: string;
} | {
readonly kind: "postgres";
readonly connectionString?: string;
};
export interface StorageTransaction {
readonly timers?: TimerTable;
get(namespace: string, id: string): Effect.Effect<JsonValue | undefined, StorageFailure>;
list(namespace: string): Effect.Effect<readonly StoredRecord[], StorageFailure>;
put(namespace: string, id: string, value: JsonValue): Effect.Effect<void, StorageFailure>;
delete(namespace: string, id: string): Effect.Effect<boolean, StorageFailure>;
}
export declare class StorageUnavailable extends StorageUnavailable_base<{
readonly cause: PersistenceError;
}> {
}
export interface TransactionService {
run<A, E, R>(work: (tx: StorageTransaction) => Effect.Effect<A, E, R>): Effect.Effect<A, E | StorageFailure, R>;
}
export type TransportDecision = {
readonly status: "accepted";
readonly reference: string;
} | {
readonly status: "failed";
readonly reason: string;
} | {
readonly status: "unknown";
};