import Inject, { RegisterScoped } from "@entity-access/entity-access/dist/di/di.js"; import WebSiteContentService from "../../files/WebSiteContentService.js"; import SocialMailContext from "../../../model/SocialMailContext.js"; import EncryptionService from "../../encryption/EncryptionService.js"; import Integration from "../../../model/entities/Integration.js"; export interface ITransferResult { status: "transferred" | "initiated" | "failed", error?: any } export interface IDomainSearchResult { error?: any; available: boolean; premium?: boolean; countryTLD?: boolean; registration?: number; renewal?: number; }; export abstract class BaseDomainRegistrar { constructor(protected readonly integration: Integration) {} abstract search(domain: string, currency: string): Promise; abstract register(domain: string, currency: string): Promise<{ status: "registered" | "failed", error?: any }>; abstract transfer(domain: string, currency: string, transferCode: string): Promise; abstract updateTransfer(domain: string): Promise; abstract updateNameservers(domain: string, servers: string[]): Promise; } @RegisterScoped export default class DomainRegistrar { @Inject wcs: WebSiteContentService; @Inject db: SocialMailContext; @Inject encryptionService: EncryptionService; async client({ siteID = void 0, hostName = void 0}) { if(!siteID) { siteID = (await this.wcs.getWebSite(hostName)).folderID; } const reg = await this.db.integrations .where({ siteID }, (x, p) => x.storeID === p.siteID && x.type === "domain-registrar") .first(); const { default: Registrar } = await import("./registrars/" + reg.name + ".js"); reg.secret = this.encryptionService.secure.decrypt(reg.encryptedSecret); const r = new Registrar(reg); return r as BaseDomainRegistrar; } }