Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Factory Services #118

Open
6 tasks
saranshisatgit opened this issue Sep 21, 2022 · 3 comments
Open
6 tasks

Create Factory Services #118

saranshisatgit opened this issue Sep 21, 2022 · 3 comments

Comments

@saranshisatgit
Copy link
Contributor

  • For services to work , a backbone approach
  • Key Pair Management
  • DB Management
  • Creating Streams
  • methods Setup and expose them via API or SDK
  • work on content Delivery using sdk
@saranshisatgit
Copy link
Contributor Author

@thozinza and @ThoTrung

@ThoTrung
Copy link

@saranshisatgit
I am not very clear about this, could you add more detail?

@maektwain
Copy link
Contributor

The SDK Service part

  1. How does SDK's work?

They expose certain functions or methods that can be or should be used via any service or UI or anything

  1. npm packages like @2nd/sdk

  2. What do they contain ?

 async initConnection(): Promise<NostrEvent[]> {
      logger.info('Init Connection Services')
      const fetchedEvents: NostrEvent[] = [];
      let userList = [];
      if (typeof window !== undefined) {
        const privKey =
          localStorage.getItem("keys") !== null
            ? JSON.parse(localStorage.getItem("keys")!).privateKey
            : null;
        if (privKey !== null) pool.setPrivateKey(privKey);
        const userIdList =
          localStorage.getItem("follow-list") !== null
            ? JSON.parse(JSON.stringify(localStorage.getItem("follow-list")))
            : '[]';
        console.log(userIdList);
        // console.log(JSON.parse(userIdList));
        userList = JSON.parse(userIdList);
        // userList =
        //   typeof userIdList === "object" ? JSON.parse(userIdList) : userList;
      }
      const relays = await getRelays();
      relays.map(async (relayUrl: string) => await pool.addRelay(relayUrl));

      await pool.sub(
        {
          cb: async (event: NostrEvent) => {
            switch (event.kind) {
              case 0:
              case 1:
              case 2:
                fetchedEvents.push(event);
                return;
            }
          },
          filter: [
            {
              authors: userList,
              kinds: [0, 1, 3],
            },
          ],
        },
        "profile-browser"
      );
      return fetchedEvents;
    },
  1. How the developers are going to call it?
  • import {sdk} 2nd/sdk
  1. Then they use the function like this
  • sdk.initConnection()
  1. SDK becomes your API
  • sdk.createKeyPair()

Hence its standardised

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants