import type { ProvisionableUser } from 'officerdb'; // The account list the platform pushes, held for as long as this process lives. // // Pushed rather than fetched — see src/servers/plugins/user-provisioning.ts. It arrives once when this // sidecar registers, and again whenever an Officer account is created or removed, so it is the current // truth rather than a cache with an expiry: each message REPLACES what was held, never merges. // // In memory on purpose. Persisting it would create a second copy of the platform's own users that could // disagree with it, and the recovery from disagreement would be re-reading the platform anyway. A restart // re-registers, which re-sends. let users: ProvisionableUser[] = []; let receivedAt: Date | null = null; export function setProvisionableUsers(next: ProvisionableUser[]): void { users = next; receivedAt = new Date(); console.log(`[photos] user list: ${next.length} account(s) the platform can provision`); } export const getProvisionableUsers = (): ProvisionableUser[] => users; /** * Whether the platform has told us anything yet. * * The distinction matters: an EMPTY list means "this server has only an owner", while never having been * told means the plugin is not entitled or the push has not arrived. Provisioning nothing is right in the * first case and wrong in the second, so the caller has to be able to tell them apart. */ export const hasProvisionableUsers = (): boolean => receivedAt !== null;