-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
refactor: @formbricks/api package #782
refactor: @formbricks/api package #782
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
Thank you for following the naming conventions for pull request titles! 🙏 |
📦 Next.js Bundle Analysis for @formbricks/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
📦 Next.js Bundle Analysis for @formbricks/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ShubhamPalriwala looks great! thank you for this first draft :-)
@@ -0,0 +1,37 @@ | |||
import fetch from "node-fetch"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our repository the package is mainly used client side (formbricks-js) but should also work server side in. What do we need to do to make it work both client and server side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the node-fetch
for that purpose itself! For non-browser interactions, to have the fetch
, we can use the node-fetch packale
import { Result, err, ok, wrapThrows } from "@formbricks/errors"; | ||
import { NetworkError, ApiResponse } from "../types/index"; | ||
|
||
export async function makeRequest<T = any, E = any>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at the errors package and try to simplify this generic type as this is hard to understand. (If it makes sense?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done! please take a look now
import { ApiConfig } from "../../types"; | ||
|
||
export class Client { | ||
response: ResponseAPI; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer plural responses
as it is also used that way in our api route. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, having singular is better since it's a method name and can differ from the API route! Singular keeps it simple and does not set any expectations
📦 Next.js Bundle Analysis for @formbricks/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
📦 Next.js Bundle Analysis for @formbricks/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
@ShubhamPalriwala we are also using the api package in the onboarding in |
@ShubhamPalriwala Can you please solve the merge conflicts and also update the Formbricks Onboarding as mentioned in the comment above? 😊🙏 |
this.apiHost = baseUrl; | ||
} | ||
|
||
async markSurveyAsDisplayedForPerson({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should just name it markResponded
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, new survey methods are:
markDisplayedForPerson
, markResponded
packages/api/src/types/index.ts
Outdated
@@ -0,0 +1,15 @@ | |||
export type NetworkError = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we maybe move this error to @formbricks/types/errors
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, thanks for pointing this out
…shubham/for-1151-rewrite-formbricks-api-package
hey, i've updated the PR as per your comments and resolved merge conflicts as well! however, i'm running into the following build issues:
I tried adding the "fs" module as well but then after couldn't figure out why the build was having the "net" package. |
It seems to we an issue with |
yessir, it's good to go 🚀 |
…shubham/for-1151-rewrite-formbricks-api-package
…ps://github.com/formbricks/formbricks into shubham/for-1151-rewrite-formbricks-api-package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ShubhamPalriwala Looks great, thank you :-)
* init: rewritten formbricks api package * restrucure: client prepended formbricks api package * feat: cleanup error templating and node-fetch for non browser access * feat: replace package (build error for js packge due to api) * fix: rename methods & move error type * fix: imports of api via js * remove node-fetch --------- Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
* init: rewritten formbricks api package * restrucure: client prepended formbricks api package * feat: cleanup error templating and node-fetch for non browser access * feat: replace package (build error for js packge due to api) * fix: rename methods & move error type * fix: imports of api via js * remove node-fetch --------- Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
* init: rewritten formbricks api package * restrucure: client prepended formbricks api package * feat: cleanup error templating and node-fetch for non browser access * feat: replace package (build error for js packge due to api) * fix: rename methods & move error type * fix: imports of api via js * remove node-fetch --------- Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
What does this PR do?
This is currently a Draft PR for feedback on the rewritten package! Once the changes are gtg, it will be renamed from the current
formbricks-api-wrapper
to ourformbricks/api
and the old package will be deleted! This is not done till now so that its easier to review and compare the packages!Methods supported:
ToDo before Merging
Type of change
How should this be tested?
Checklist
pnpm build
console.logs
git pull origin main