import { Injectable } from '@nestjs/common'; export abstract class ThirdPartyAbstract { abstract checkConnection( apiKey: string ): Promise; abstract sendData(apiKey: string, data: T): Promise; [key: string]: ((apiKey: string, data?: any) => Promise) | undefined; } export interface ThirdPartyParams { identifier: string; title: string; description: string; position: 'media' | 'webhook'; fields: { name: string; description: string; type: string; placeholder: string; validation?: RegExp; }[]; } export function ThirdParty(params: ThirdPartyParams) { return function (target: any) { // Apply @Injectable decorator to the target class Injectable()(target); // Retrieve existing metadata or initialize an empty array const existingMetadata = Reflect.getMetadata('third:party', ThirdPartyAbstract) || []; // Add the metadata information for this method existingMetadata.push({ target, ...params }); // Define metadata on the class prototype (so it can be retrieved from the class) Reflect.defineMetadata('third:party', existingMetadata, ThirdPartyAbstract); }; }