import { buildInfrastructure } from './infrastructure/mod.js' import { buildServices } from './services/mod.js' import { buildCryptoUseCases } from './use-cases/crypto/mod.js' import { buildLicensingUseCases } from './use-cases/licensing/mod.js' import { buildUserUseCases } from './use-cases/users/mod.js' interface Options { /** The tenant of your Generous instance (e.g. `you.generous.builders`). */ readonly domain: string readonly _development?: { /** Defines if the communication with the Generous platform should utilize SSL (default: `true`) */ readonly ssl?: boolean } } export function beGenerous(options: Options) { const apiVersion = 'v1' const ssl = options._development?.ssl === undefined ? true : options._development.ssl const protocol = ssl ? 'https' : 'http' const apiUrl = `${protocol}://${options.domain}/api/${apiVersion}` const infrastructure = buildInfrastructure({ baseUrl: apiUrl }) const services = buildServices({ infrastructure, }) const crypto = buildCryptoUseCases({ deps: { services }, }) const licensing = buildLicensingUseCases({ deps: { services }, }) const users = buildUserUseCases({ deps: { services }, }) return { crypto, licensing, users, } as const } export type Generous = ReturnType export type { RegisterDeviceError } from './use-cases/licensing/devices/register.ts' export type { DeregisterDeviceError } from './use-cases/licensing/devices/deregister.ts' export type { EnsureDeviceError } from './use-cases/licensing/devices/ensure.ts' export type { GetFeatureFlagError } from './use-cases/licensing/features/get-feature-flag.js' export type { GetSupporterError } from './use-cases/users/get-supporter.js' export type { EncryptError } from './use-cases/crypto/encrypt.js' export type { DecryptError } from './use-cases/crypto/decrypt.js' export type { DeviceRegistrationManifest } from './domain/device-registration-manifest.js'