This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
forked from dylsteck/farcasterkit
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from dtechvision/tsdx-fuego
Finished initial Provider Setup
- Loading branch information
Showing
12 changed files
with
186 additions
and
9,980 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import 'react-app-polyfill/ie11'; | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import { Thing } from '../.'; | ||
|
||
import { NeynarProvider } from '../.'; | ||
|
||
const provider = new NeynarProvider('270950A2-D46D-4216-A0B2-B3B91D796459'); | ||
console.log(provider); | ||
|
||
const App = () => { | ||
return ( | ||
<div> | ||
<Thing /> | ||
</div> | ||
); | ||
return <div></div>; | ||
}; | ||
|
||
ReactDOM.render(<App />, document.getElementById('root')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export class Provider { | ||
name: string; | ||
/** | ||
* Generic base Provider Class, don't use directly! | ||
* @param name the custom name of the provider. useful for debugging output | ||
*/ | ||
constructor(name: string) { | ||
this.name = name; | ||
} | ||
} | ||
|
||
export class HubProvider extends Provider { | ||
hubUrl: string; | ||
psqlUrl: string | undefined; | ||
/** | ||
* HubProvider for getting Data with Farcaster Hubs and optional PostgreSQL Replicator | ||
* @param name the custom name of the provider. useful for debugging output | ||
* @param hubUrl the Farcaster Hub URL to use | ||
* @param psqlUrl optional: the PostgreSQL Replicator URL to use. Defaults to undefined | ||
*/ | ||
constructor(name: string, hubUrl: string, psqlUrl?: string) { | ||
super(name); | ||
|
||
this.hubUrl = hubUrl; | ||
this.psqlUrl = psqlUrl; | ||
} | ||
} | ||
|
||
export class ThirdParty extends Provider { | ||
apiKey: string; | ||
endPoint: string; | ||
|
||
/** | ||
* ThirdParty Provider for getting Data with any ThirdParty API provider that doesn't just offer a Hub/Replicator Endpoint | ||
* @param apiKey Provider API Key to use. Please do not hardcode this! Use .env or other | ||
* @param endPoint the Provider API endpoint to use | ||
*/ | ||
constructor(name: string, apiKey: string, endPoint: string) { | ||
super(name); | ||
this.apiKey = apiKey; | ||
this.endPoint = endPoint; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./class"; | ||
export * from "./public"; | ||
export * from "./thirdpartyProvider"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { HubProvider } from './class'; | ||
|
||
// Example usage for a predefined provider | ||
// const provider = new PublicProvider(); | ||
// to use the public Pinata Farcaster Hub | ||
// const provider = new PublicProvider("pinata"); | ||
// to use with PostgreSQL Replicator at https://replicator.yourdomain.com | ||
// const provider = new PublicProvider("pinata", "https://replicator.yourdomain.com"); | ||
|
||
export class PublicProvider extends HubProvider { | ||
/** | ||
* Default Provider using only free, public Offerings anyone can use! | ||
* @param providerType decide which public Hub to use. Defaults to Warpcast offering | ||
* @param psqlUrl optional: the PostgreSQL Replicator URL to use. Defaults to undefined | ||
*/ | ||
constructor(providerType: string = 'farcaster', psqlUrl?: string) { | ||
let hubUrl: string; | ||
let name: string; | ||
|
||
if (providerType === 'pinata') { | ||
hubUrl = 'hub.pinata.cloud/v1/'; | ||
name = 'publicPinataHub'; | ||
} else { | ||
hubUrl = 'nemes.farcaster.xyz:2283'; | ||
name = 'publicFarcasterHub'; | ||
} | ||
//no psqlUrl since there is no public PostgreSQL Replicator instance | ||
super(name, hubUrl, psqlUrl); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ThirdParty } from "../class"; | ||
|
||
/* | ||
* Example usage for neynar provider | ||
* const neynarApiKey = process.env.NEYNAR_API_KEY || "your_neynar_api_key"; | ||
* const neynarProvider = new NeynarProvider(neynarApiKey); | ||
*/ | ||
|
||
export class NeynarProvider extends ThirdParty { | ||
/** | ||
* NeynarProvider for getting Data with neynar.com Farcaster APIs | ||
* @param apiKey Neynar API Key to use. Please do not hardcode this! Use .env or other | ||
* @param endPoint optional Neynar API endpoint, defaults to public Neynar V2. Custom endpoint is required to be Neynar API V2 compliant! | ||
*/ | ||
constructor(apiKey: string, endPoint?: string) { | ||
if (endPoint) { | ||
super("neynar", apiKey, endPoint); | ||
} else { | ||
super("neynar", apiKey, "https://api.neynar.com/v2/farcaster"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ThirdParty } from "./class"; | ||
|
||
/** | ||
* | ||
* NOTE: This implementation is a sample and will lead to unimplemented Errors with FarcasterKit Providers! | ||
* The only exception to this is functions that require only Hubs as there we fall back to the public Provider. | ||
* For Farcaster API providers who wish to offer the API to FarcasterKit developers please open a PullRequest/Issue | ||
* https://github.com/dtechvision/farcasterkit/ | ||
* | ||
*/ | ||
|
||
export class ThirdPartyProvider extends ThirdParty { | ||
/** | ||
* Custom Third Party Provider for getting Data with custom APIs | ||
* @param providerType name the type of provider you are creating | ||
* @param apiKey the API Key to use with your API Endpoint if required | ||
* @param endPoint your custom API Endpoint that should be used | ||
*/ | ||
constructor(providerType: string, apiKey: string, endPoint: string) { | ||
if (!endPoint) { | ||
throw new Error("Endpoint must be provided for custom provider type"); | ||
} | ||
if(!providerType) { | ||
throw new Error('Provider type must be provided for custom provider type'); | ||
} | ||
|
||
super(providerType, apiKey, endPoint); | ||
} | ||
} | ||
|
||
/**************************************** | ||
* all registered third party providers * | ||
****************************************/ | ||
|
||
export * from './thirdparty/neynarProvider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export type FarcasterUser = { | ||
signer_uuid: string; | ||
public_key: string; | ||
status: string; | ||
signer_approval_url?: string; | ||
fid?: number; | ||
} | ||
|
||
export type Channel = { | ||
name: string; | ||
parent_url: string; | ||
image: string; | ||
channel_id: string; | ||
lead_fid?: number; | ||
} | ||
|
||
|
||
|
||
// Path: types/types.d.ts |
Oops, something went wrong.