import { type Selectable } from 'kysely';
import type * as Db from '../Db.js';
import type * as db_Schema from '../Schema.js';
import type * as EnabledBillingSources from './enabledBillingSources.js';
import type * as Memberships from './memberships.js';
/** Columns of the `organizations` table, derived from `Schema.Organization`. */
export type Table = db_Schema.Organization;
/** A stored organization row. */
export type Record = Selectable
;
/**
* Inserts an organization and returns the stored record. The `id` defaults to
* a generated `org_…` handle when omitted.
*
* @param db - The database.
* @param input - The organization to insert.
* @returns The stored record.
*/
export declare function create(db: Db.Db, input: create.Input): Promise;
export declare namespace create {
/** Fields accepted when inserting an organization. */
type Input = {
/** Identity creating the organization (e.g. admin email), recorded for audit. */
createdBy?: string | undefined;
/** Explicit id; a generated `org_…` handle is used when omitted. */
id?: string | undefined;
/** Human-readable organization name. */
name: string;
/** Owning user id (`usr_…`); null for organizations created by the super admin. */
userId?: string | undefined;
};
}
/**
* Inserts an organization, its owner membership, and initial billing sources
* atomically.
*
* @param db - The database.
* @param input - The organization to insert.
* @returns The stored record.
*/
export declare function createOwned(db: Db.Db, input: createOwned.Input): Promise;
export declare namespace createOwned {
/** Fields accepted when inserting a user-owned organization. */
type Input = {
/** Billing sources enabled when the organization is created. */
enabledBillingSources?: readonly EnabledBillingSources.Source[] | undefined;
/** Human-readable organization name. */
name: string;
/** Owning user id (`usr_…`), granted the `owner` membership. */
userId: string;
};
}
/**
* Deletes an organization and its owned rows atomically.
*
* @param db - The database.
* @param id - The organization id (`org_…`).
* @returns Whether the organization existed and was deleted.
*/
export declare function deleteOrganization(db: Db.Db, id: string): Promise;
/** Whether an organization has billable sponsorships awaiting settlement. */
export declare function hasUnreportedSponsorships(db: Db.Db, id: string): Promise;
/**
* Reads an organization by id.
*
* @param db - The database.
* @param id - The organization id (`org_…`).
* @returns The record, or `undefined` when absent.
*/
export declare function get(db: Db.Db, id: string): Promise;
/**
* Reads organizations by id for operational attribution displays.
*
* @param db - The database.
* @param ids - Organization ids to read.
* @returns Matching organization records.
*/
export declare function listByIds(db: Db.Db, ids: readonly string[]): Promise;
/**
* Reads an organization with current member and project counts.
*
* @param db - The database.
* @param id - The organization id.
* @returns The organization summary, or `undefined` when absent.
*/
export declare function getSummary(db: Db.Db, id: string): Promise;
/**
* Lists organizations, newest first.
*
* @param db - The database.
* @returns The records.
*/
export declare function list(db: Db.Db): Promise;
/**
* Searches organizations for the admin lookup surface, newest first. Results
* include member and project counts and use a stable `(createdAt, id)` keyset.
*
* @param db - The database.
* @param options - Search, keyset, and page-size options.
* @returns At most `limit + 1` rows so the caller can derive a next cursor.
*/
export declare function search(db: Db.Db, options: search.Options): Promise;
export declare namespace search {
/** Cursor fields for the last organization returned by the previous page. */
type Cursor = {
/** Organization creation time. */
createdAt: string;
/** Organization id, used as a deterministic tie-breaker. */
id: string;
};
/** Options for {@link search}. */
type Options = {
/** Last organization returned by the previous page. */
cursor?: Cursor | undefined;
/** Requested page size. */
limit: number;
/** Exact resource id or case-insensitive name/email prefix search. */
query?: string | undefined;
};
/** Organization summary returned by {@link search}. */
type Result = Record & {
/** Number of current organization members. */
memberCount: number;
/** Number of projects owned by the organization. */
projectCount: number;
};
}
/**
* Lists organizations owned by `userId`, newest first.
*
* @param db - The database.
* @param userId - The owning user id (`usr_…`).
* @returns The records.
*/
export declare function listByUser(db: Db.Db, userId: string): Promise;
/**
* Lists organizations `userId` is a member of (any role), newest first. Each
* row carries the caller's membership `role`.
*
* @param db - The database.
* @param userId - The member user id (`usr_…`).
* @returns The records.
*/
export declare function listByMember(db: Db.Db, userId: string): Promise<(Record & {
role: Memberships.Role;
})[]>;
/**
* Renames an organization, bumping `updatedAt`.
*
* @param db - The database.
* @param id - The organization id (`org_…`).
* @param input - The fields to update.
* @returns The updated record, or `undefined` when absent.
*/
export declare function update(db: Db.Db, id: string, input: update.Input): Promise;
export declare namespace update {
/** Mutable organization fields. */
type Input = {
/** New human-readable organization name. */
name: string;
};
}
/**
* Replaces the organization's sponsorship subsidy policy. A null duration
* disables the program; an enabled policy may omit its per-project spend cap.
*
* @param db - The database.
* @param id - The organization id (`org_…`).
* @param input - The replacement subsidy policy.
* @returns The updated organization, or `undefined` when absent.
*/
export declare function setSponsorshipSubsidy(db: Db.Db, id: string, input: setSponsorshipSubsidy.Input): Promise;
export declare namespace setSponsorshipSubsidy {
/** Replacement organization subsidy policy. */
type Input = {
/** Fixed promotion duration in days. */
durationDays: 90;
/** Optional decimal USD spend cap applied independently to each project. */
projectSpendLimit: string | null;
} | {
/** Null disables the promotion. */
durationDays: null;
/** Null disables the promotion. */
projectSpendLimit: null;
};
}
/**
* Inserts an organization when absent (`ON CONFLICT DO NOTHING`) — the
* mint/backfill path, where a key's `orgId` must resolve to a real row. The
* `name` defaults to the id for degenerate orgs created by the mint fallback.
*
* @param db - The database.
* @param input - The organization to ensure.
*/
export declare function upsert(db: Db.Db, input: upsert.Input): Promise;
export declare namespace upsert {
/** Fields accepted when ensuring an organization exists. */
type Input = {
/** Identity creating the organization, recorded for audit. */
createdBy?: string | undefined;
/** The organization id (`org_…`, or a mint-fallback key id). */
id: string;
/** Human-readable organization name; defaults to the id. */
name?: string | undefined;
};
}
/** Organization deletion is blocked until billable sponsorships settle. */
export declare class UnreportedSponsorshipsError extends Error {
name: string;
}
//# sourceMappingURL=organizations.d.ts.map