// Copyright Abridged, Inc. 2021,2024. All Rights Reserved. // Node module: @collabland/sdk // This file is licensed under the MIT License. // License text available at https://opensource.org/license/mit/ import { Application, ApplicationConfig, BindingScope, createBindingFromClass, ServiceOrProviderClass, } from '@loopback/core'; import {RestDataSource} from './datasources/index.js'; import { AccessControlService, AccessControlServiceProvider, AccountService, AccountServiceProvider, AnalyticsService, AnalyticsServiceProvider, AssetOwnershipService, AssetOwnershipServiceProvider, AxieRulesService, AxieRulesServiceProvider, ClientApplicationService, ClientApplicationServiceProvider, CommunityService, CommunityServiceProvider, CommunityWalletService, CommunityWalletServiceProvider, ConfigService, ConfigServiceProvider, DiscordBotService, DiscordBotServiceProvider, DiscordIntegrationService, DiscordIntegrationServiceProvider, DiscordInteractionService, DiscordInteractionServiceProvider, EthereumLoginService, EthereumLoginServiceProvider, EthereumNftMetadataService, EthereumNftMetadataServiceProvider, EvmNetworkConfigService, EvmNetworkConfigServiceProvider, FlowContractsService, FlowContractsServiceProvider, FreshdeskService, FreshdeskServiceProvider, GmPassService, GmPassServiceProvider, GuestPassService, GuestPassServiceProvider, JwksService, JwksServiceProvider, KudosService, KudosServiceProvider, LogSettingsService, LogSettingsServiceProvider, MiniappRegistrationService, MiniappRegistrationServiceProvider, MiniAppService, MiniAppServiceProvider, NearIndexerService, NearIndexerServiceProvider, NearNFTService, NearNFTServiceProvider, NFTMetadataService, NFTMetadataServiceProvider, OAuth2Service, OAuth2ServiceProvider, OrganizationService, OrganizationServiceProvider, PlanService, PlanServiceProvider, QRCodeService, QRCodeServiceProvider, RedditService, RedditServiceProvider, RoleManagerService, RoleManagerServiceProvider, ScopesService, ScopesServiceProvider, StakingContractsService, StakingContractsServiceProvider, TelefrensInvitationService, TelefrensInvitationServiceProvider, TelefrensService, TelefrensServiceProvider, TelefrensSubgraphService, TelefrensSubgraphServiceProvider, TelefrensWaitListService, TelefrensWaitListServiceProvider, TelegramPkpService, TelegramPkpServiceProvider, UnlockProtocolService, UnlockProtocolServiceProvider, UrlSlugService, UrlSlugServiceProvider, UserAuthorizationService, UserAuthorizationServiceProvider, VeramoService, VeramoServiceProvider, WalletManagerService, WalletManagerServiceProvider, WebauthnService, WebauthnServiceProvider, } from './services/index.js'; export {ApplicationConfig}; /** * Authentication configuration for the Collab.Land SDK */ export type CollabLandAuth = { /** * CollabLand oAuth2 access token */ collabLandOAuth2?: string; /** * CollabLand authenticated encryption token (AE token - a JWT token * encrypted with JWE) */ authenticatedEncryption?: string; /** * Ethereum signature */ ethereum?: string; /** * API key for a client application */ apiKey?: string; }; /** * Mapping of service names to service providers. Webpack renames classes and * it's not reliable to use the class name to reference a service provider. */ const services: Record = { AccountService: AccountServiceProvider, AssetOwnershipService: AssetOwnershipServiceProvider, AxieRulesService: AxieRulesServiceProvider, CommunityService: CommunityServiceProvider, NearNFTService: NearNFTServiceProvider, NearIndexerService: NearIndexerServiceProvider, MiniAppService: MiniAppServiceProvider, MiniappRegistrationService: MiniappRegistrationServiceProvider, RoleManagerService: RoleManagerServiceProvider, DiscordBotService: DiscordBotServiceProvider, FlowContractsService: FlowContractsServiceProvider, GuestPassService: GuestPassServiceProvider, AccessControlService: AccessControlServiceProvider, UrlSlugService: UrlSlugServiceProvider, WalletManagerService: WalletManagerServiceProvider, FreshdeskService: FreshdeskServiceProvider, EthereumLoginService: EthereumLoginServiceProvider, StakingContractsService: StakingContractsServiceProvider, EvmNetworkConfigService: EvmNetworkConfigServiceProvider, RedditService: RedditServiceProvider, CommunityWalletService: CommunityWalletServiceProvider, OrganizationService: OrganizationServiceProvider, ClientApplicationService: ClientApplicationServiceProvider, DiscordIntegrationService: DiscordIntegrationServiceProvider, DiscordInteractionService: DiscordInteractionServiceProvider, KudosService: KudosServiceProvider, UserAuthorizationService: UserAuthorizationServiceProvider, ConfigService: ConfigServiceProvider, GmPassService: GmPassServiceProvider, LogSettingsService: LogSettingsServiceProvider, PlanService: PlanServiceProvider, ScopesService: ScopesServiceProvider, UnlockProtocolService: UnlockProtocolServiceProvider, WebauthnService: WebauthnServiceProvider, VeramoService: VeramoServiceProvider, QRCodeService: QRCodeServiceProvider, EthereumNftMetadataService: EthereumNftMetadataServiceProvider, JwksService: JwksServiceProvider, NFTMetadataService: NFTMetadataServiceProvider, OAuth2Service: OAuth2ServiceProvider, AnalyticsService: AnalyticsServiceProvider, TelefrensService: TelefrensServiceProvider, TelefrensInvitationService: TelefrensInvitationServiceProvider, TelefrensWaitListService: TelefrensWaitListServiceProvider, TelefrensSubgraphService: TelefrensSubgraphServiceProvider, TelegramPkpService: TelegramPkpServiceProvider, }; /** * Collab.Land API client */ export class CollabLandClient extends Application { /** * API for Account/User management */ account: AccountService; /** * API for AccessControl (Token-gating) */ accessControl: AccessControlService; /** * API for AssetOwnership */ assetOwnership: AssetOwnershipService; /** * API for Axie rules */ axieRules: AxieRulesService; /** * API for Community management */ community: CommunityService; /** * API for NFTs on NEAR */ nearNFT: NearNFTService; /** * API for NEAR NFT indexer */ nearIndexer: NearIndexerService; /** * API for Role manager */ roleManager: RoleManagerService; /** * API for Discord bot */ discordBot: DiscordBotService; /** * API for Wallet management */ walletManager: WalletManagerService; /** * API for Flow contracts */ flowContracts: FlowContractsService; /** * API for Guest Pass */ guestPass: GuestPassService; /** * API for URL slug */ urlSlug: UrlSlugService; /** * API for Freshdesk */ freshdesk: FreshdeskService; /** * API for Ethereum login */ ethereumLogin: EthereumLoginService; /** * API for Staking contracts */ stakingContracts: StakingContractsService; /** * API for EVM network config */ evmNetworkConfig: EvmNetworkConfigService; /** * API for Reddit */ reddit: RedditService; /** * API for MiniApp */ miniApp: MiniAppService; /** * API for Community wallet */ communityWallet: CommunityWalletService; /** * API for Organization */ organization: OrganizationService; /** * API for Client application */ clientApplication: ClientApplicationService; /** * API for Miniapp registration */ miniAppRegistration: MiniappRegistrationService; /** * API for Discord integration */ discordIntegration: DiscordIntegrationService; /** * API for Discord interaction */ discordInteraction: DiscordInteractionService; /** * API for Kudos */ kudos: KudosService; /** * API for User authorization */ userAuthorization: UserAuthorizationService; /** * API for Config */ config: ConfigService; /** * API for GmPass */ gmPass: GmPassService; /** * API for LogSettings */ logSettings: LogSettingsService; /** * API for Plan */ plan: PlanService; /** * API for Scopes */ scopes: ScopesService; /** * API for UnlockProtocol */ unlockProtocol: UnlockProtocolService; /** * API for Webauthn */ webauthn: WebauthnService; /** * API for Veramo */ veramo: VeramoService; /** * API for QRCode */ qrCode: QRCodeService; /** * API for Ethereum NFT metadata */ ethereumNftMetadata: EthereumNftMetadataService; /** * API for Jwks */ jwks: JwksService; /** * API for NFT metadata */ nftMetadata: NFTMetadataService; /** * API for OAuth2 */ oAuth2: OAuth2Service; /** * API for Analytics */ analytics: AnalyticsService; telefrens: TelefrensService; telefrensInvitation: TelefrensInvitationService; telefrensWaitList: TelefrensWaitListService; telefrensSubgraph: TelefrensSubgraphService; telegramPkp: TelegramPkpService; /** * Create a new CollabLandClient instance * @param auth - Authentication credentials * @param url - Collab.Land API server URL */ constructor(auth: string | CollabLandAuth, url: string) { super(); this.setup(auth, url); this.add( createBindingFromClass(RestDataSource, { key: 'datasources.rest', defaultScope: BindingScope.SINGLETON, }), ); for (const s in services) { this.service(services[s], { // Set explicit binding key as webpack changes class names key: `services.${s}`, defaultScope: BindingScope.SINGLETON, }); } } /** * Set up SDK with authentication and URL * @param auth - Authentication credentials * @param url - CollabLand API server URL */ setup(auth: string | CollabLandAuth, url = 'https://api.collab.land') { if (!url) { throw new Error('url is required'); } let authorizations; if (typeof auth === 'string') { if (auth.startsWith('AE ')) { authorizations = { authenticatedEncryption: {value: auth}, }; } else if (auth.startsWith('Ethereum ')) { authorizations = { ethereum: {value: auth}, }; } else if (auth.startsWith('Bearer ')) { authorizations = { collabLandOAuth2: { token: {access_token: auth.replace('Bearer ', '')}, }, }; } } else { authorizations = {} as Record; let s: keyof CollabLandAuth; for (s in auth) { if (s === 'collabLandOAuth2') { authorizations[s] = {token: {access_token: auth[s]}}; } else { authorizations[s] = {value: auth[s]}; } } } const swaggerClientOptions = { ...RestDataSource.defaultConfig, authorizations, }; if (url != null) { // Favor the spec loaded from the url swaggerClientOptions.url = `${url}/openapi.json`; } this.bind('datasources.config.rest').to(swaggerClientOptions); } /** * Connect to Collab.Land API server and resolve services */ async connect() { if (this.account != null) return; this.account = await this.getService('AccountService'); this.accessControl = await this.getService('AccessControlService'); this.assetOwnership = await this.getService('AssetOwnershipService'); this.axieRules = await this.getService('AxieRulesService'); this.community = await this.getService('CommunityService'); this.nearNFT = await this.getService('NearNFTService'); this.nearIndexer = await this.getService('NearIndexerService'); this.roleManager = await this.getService('RoleManagerService'); this.discordBot = await this.getService('DiscordBotService'); this.walletManager = await this.getService('WalletManagerService'); this.flowContracts = await this.getService('FlowContractsService'); this.guestPass = await this.getService('GuestPassService'); this.urlSlug = await this.getService('UrlSlugService'); this.freshdesk = await this.getService('FreshdeskService'); this.ethereumLogin = await this.getService('EthereumLoginService'); this.stakingContracts = await this.getService('StakingContractsService'); this.evmNetworkConfig = await this.getService('EvmNetworkConfigService'); this.reddit = await this.getService('RedditService'); this.communityWallet = await this.getService('CommunityWalletService'); this.miniApp = await this.getService('MiniAppService'); this.miniAppRegistration = await this.getService( 'MiniappRegistrationService', ); this.organization = await this.getService('OrganizationService'); this.clientApplication = await this.getService('ClientApplicationService'); this.discordIntegration = await this.getService( 'DiscordIntegrationService', ); this.discordInteraction = await this.getService( 'DiscordInteractionService', ); this.kudos = await this.getService('KudosService'); this.userAuthorization = await this.getService('UserAuthorizationService'); this.config = await this.getService('ConfigService'); this.gmPass = await this.getService('GmPassService'); this.logSettings = await this.getService('LogSettingsService'); this.plan = await this.getService('PlanService'); this.scopes = await this.getService('ScopesService'); this.unlockProtocol = await this.getService('UnlockProtocolService'); this.webauthn = await this.getService('WebauthnService'); this.veramo = await this.getService('VeramoService'); this.qrCode = await this.getService('QRCodeService'); this.ethereumNftMetadata = await this.getService( 'EthereumNftMetadataService', ); this.jwks = await this.getService('JwksService'); this.nftMetadata = await this.getService('NFTMetadataService'); this.oAuth2 = await this.getService('OAuth2Service'); this.analytics = await this.getService('AnalyticsService'); this.telefrens = await this.getService('TelefrensService'); this.telefrensInvitation = await this.getService( 'TelefrensInvitationService', ); this.telefrensWaitList = await this.getService('TelefrensWaitListService'); this.telefrensSubgraph = await this.getService('TelefrensSubgraphService'); this.telegramPkp = await this.getService('TelegramPkpService'); } /** * Locate a service instance by name * @param name - Service name * @returns * * @typeParam T - Service type */ async getService(name: string) { if (!name.startsWith('services.')) { name = `services.${name}`; } return this.get(name); } }