Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from dtechvision/tsdx-fuego
Browse files Browse the repository at this point in the history
Finished initial Provider Setup
  • Loading branch information
SamuelLHuber authored Mar 6, 2024
2 parents 056aeb4 + 345b8ac commit 5b19f4f
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 9,980 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Nazeeh Vahora
Copyright (c) 2024 fuegoblanco

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 6 additions & 6 deletions example/index.tsx
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'));
5 changes: 4 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"devDependencies": {
"@types/react": "^16.9.11",
"@types/react-dom": "^16.8.4",
"parcel": "^1.12.3",
"parcel": "1.12.4",
"typescript": "^3.4.5"
},
"resolutions": {
"@babel/preset-env": "7.13.8"
}
}
25 changes: 17 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "farcasterkit",
"version": "0.1.0",
"license": "MIT",
"main": "dist/index.js",
"module": "dist/farcasterkit.esm.js",
"typings": "dist/index.d.ts",
"files": [
"dist",
Expand Down Expand Up @@ -35,9 +37,6 @@
"singleQuote": true,
"trailingComma": "es5"
},
"name": "farcaster-kit",
"author": "Nazeeh Vahora",
"module": "dist/farcaster-kit.esm.js",
"size-limit": [
{
"path": "dist/farcaster-kit.cjs.production.min.js",
Expand All @@ -48,6 +47,18 @@
"limit": "10 KB"
}
],
"dependencies": {
"@farcaster/auth-client": "^0.1.0",
"@farcaster/auth-kit": "^0.2.1",
"@farcaster/connect-kit": "^0.0.31",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
"axios": "^1.6.5",
"react": ">=16",
"react-dom": "^18.2.0",
"tsup": "^7.2.0",
"viem": "^2.7.19"
},
"devDependencies": {
"@babel/core": "^7.24.0",
"@size-limit/preset-small-lib": "^11.0.2",
Expand All @@ -56,16 +67,14 @@
"@storybook/addon-links": "^7.6.17",
"@storybook/addons": "^7.6.17",
"@storybook/react": "^7.6.17",
"@types/react": "^18.2.60",
"@types/react-dom": "^18.2.19",
"@swc/core": "^1.3.96",
"babel-loader": "^9.1.3",
"husky": "^9.0.11",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"size-limit": "^11.0.2",
"ts-loader": "^9.5.0",
"tsdx": "^0.14.1",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
"typescript": "^5.2.2"
}
}
5 changes: 5 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import React, { FC, HTMLAttributes, ReactChild } from 'react';
import * as providers from './providers';

export const NeynarProvider = providers.NeynarProvider;

export interface Props extends HTMLAttributes<HTMLDivElement> {
/** custom content, defaults to 'the snozzberries taste like snozzberries' */
Expand All @@ -13,3 +16,5 @@ export interface Props extends HTMLAttributes<HTMLDivElement> {
export const Thing: FC<Props> = ({ children }) => {
return <div>{children || `the snozzberries taste like snozzberries`}</div>;
};

export { providers };
43 changes: 43 additions & 0 deletions src/providers/class.ts
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;
}
}
3 changes: 3 additions & 0 deletions src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./class";
export * from "./public";
export * from "./thirdpartyProvider";
31 changes: 31 additions & 0 deletions src/providers/public.ts
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);
}
}

22 changes: 22 additions & 0 deletions src/providers/thirdparty/neynarProvider.ts
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");
}
}
}
35 changes: 35 additions & 0 deletions src/providers/thirdpartyProvider.ts
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';
19 changes: 19 additions & 0 deletions types/types.d.ts
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
Loading

0 comments on commit 5b19f4f

Please sign in to comment.