friggframework / create-frigg-app

MIT License
0 stars 4 forks source link

What is our intention for how users will interact with third-party APIs #46

Closed joncodo closed 1 year ago

joncodo commented 1 year ago

Overview

From what I understand so far, the point of frig is to handle all of the requests sent to an API on the users behalf. This could include authenticating to the service, performing request to get data and refreshing authentication.

what we currently have

Right now it seems that we manage authentication and refreshing of authentication. But then if you look deeper many of these integrations are handling data from the API and processing that data in some way. This springs the companies business logic into the backend of create frigg app.

what I assume customers will do with a new frigg app

My guess is that you already have a software product where all of your back and logic is stored. In order to add logic into our application that stands alongside your application, you would end up adding logic in both places. This is probably not what people are going to do. My guess is that they will want all of their business logic in the classes that are already supporting their application.

treating frigg as a proxy

If we limit the responsibilities of frig to only handle authentication and request processing and authentication refreshing, then our job becomes a lot easier.

Possible Sample code

async myServerlessAuthRoute(config){
  frigg.salesforce.authenticate(config)
}

async myServerlessProxyRoute(request){
  if(notAuthed){
    refreshAuthentication()
  }
  return frigg.salesforce.proxy(request)
}

In this case, we don't need code like this

I just want to open the discussion here to start with the end user in mind in terms of how they will consume Frigg. Right now, it is too complex. We need to make the simple tasks much easier in my humble opinion

Screen Shot 2023-02-19 at 6 33 51 PM
joncodo commented 1 year ago

I guess my main intention here is to redesign the interface of how users interact with Frigg. Imagine where the code requires and instructions are like this:

NPM install -G frigg create-frigg-app
create-frigg-app my app
echo Welcome to frigg!
Do you want to create a front end for this application? (Y/N)
From the list below, tell us which integrations you want to install (Note, you can add more anytime with `create-frigg-app generate integration Salesforce`)
echo We will now prompt your browser to log you into all the things you need and set up your config for you :)
npm start

Now the new user simply calls in their existing code:

frigg.salesforce.proxy(method, body, headers)

This will take more time to build but will get adopted much easier :)

seanspeaks commented 1 year ago

@joncodo I put together a diagram once to highlight this difference of "with Frigg, without Frigg"

After reading your thoughts/points, I have three immediate thoughts:

  1. Frigg answers the question "How do we make a scalable framework so that we can build and maintain integrations that use a lot of common patterns and allow for isolated business logic with a manageable codebase". In other words, you'd have either started with Frigg and be set because you've got a separated out repo, or you'd reach for a Frigg-type solution as your core codebase gets larger/more mature. Any integration-based business logic should be put into its own area, not necessarily baked into the rest of your application's logic. Ideal for a microservice solution.
  2. The other user/person here is not the one off developer, but rather the head of product, head of engineering, or someone whose job is to look at the bigger picture and say "how can we get all of these things built with the resources we have?". What Frigg enables for this person is the ability to look externally for engineering help with external APIs. Instead of having their core engineering learn an external API and its nuances/intricacies once, they can either leverage the ever-increasing value of Frigg abstractions, or they can hire an external team to contribute their knowledge just to an isolated integration codebase (so, they don't need a contractor to have access to their core code/they can just hire expertise in a specific application/marketplace/ecosystem). Or they can combine approaches. The point here is that leveraging Frigg is beneficial for what it unlocks with getting external expertise in the door to help.
  3. As it currently stands, Create Frigg App and most of the stuff inside Frigg's core repo do not show half of the puzzle. The first half is "help me handle authentication for many popular APIs and give me a normalized API/framework to handle that whole integration management flow". The second half is "Give me the tools and primitives and common patterns to quickly add business logic to my integrations".

For point #3 above, some patterns that we have scattered around different repos (that need to be given some love in the form of further massaging/abstraction):

There's much more that we'd add to the mix, but I think the last comment I would say is: Anyone is welcome to use any of these packages as they'd like. In the proxy case you're expanding on here, I would instead suggest that the developer grabs the API module, figures out on their own where to store api credentials, and then uses the Manager and API module to handle the requests in whatever they're doing for their compute. That said, there's no reason that they/we couldn't make a proxy layer microservice out of a Frigg application; that would be a valid use, once we've added more tooling around logging and handling etc.; It just seems to me that it would be underutilizing all that Frigg has to offer (once we've done the work to make the abstractions and functionality available to pull in).

joncodo commented 1 year ago

Ok. That all sounds good to me. I can think of two take aways to be discussed.

  1. @seanspeaks please approve - :) I think every api module should include the proxy method by default in the case where we do not have all of an API mapped over with helper methods.
  2. I will write new tickets for use cases and we can refine that and put it in the docs. I think it is important to know who this is for and why you want to use it and why you don't want to use it.

@seanspeaks please validate these comments for the docs and modify to be more accurate 😄

Why you would want to use Frigg

Why you may not want to use Frigg

How is Frigg different than passport js?

seanspeaks commented 1 year ago

please approve - :) I think every api module should include the proxy method by default in the case where we do not have all of an API mapped over with helper methods.

Totally- though currently, that's achievable via access to the internal methods, which should inherit auth method/headers by default (api._get('url', optionsObject), ditto _post, _put, _delete, _patch)

I will write new tickets for use cases and we can refine that and put it in the docs. I think it is important to know who this is for and why you want to use it and why you don't want to use it.

Yup agreed

Why you would want to use Frigg

Why you may not want to use Frigg

How is Frigg different than passport js?

joncodo commented 1 year ago

Excellent work flow. I think this is a great new docs section!