import type { Services } from '../../services/mod.js' import type { DeviceRegistrationManifest } from '../../domain/device-registration-manifest.js' import { isError, makeError, makeSuccess, unwrapResult, } from '../../framework/types/result.js' import { BaseError } from '../../framework/error/mod.js' interface Options { deps: { services: Services } } export interface GetSupporterDto { manifest: DeviceRegistrationManifest } export class GetSupporterError extends BaseError { public readonly _tag = 'GetSupporterError' } export function buildGetSupporter(options: Options) { return async function getSupporter(dto: GetSupporterDto) { const { deps: { services }, } = options const resultOfGettingLicense = await services.device.getLicense( dto.manifest, ) if (isError(resultOfGettingLicense)) { return makeError(new GetSupporterError()) } const license = unwrapResult(resultOfGettingLicense) return makeSuccess(license.supporter) } }