ayasofyazilim-clomerce / ayasofyazilim-core-project

0 stars 5 forks source link

refactor library and clients #715

Open a0m0rajab opened 1 month ago

a0m0rajab commented 1 month ago

In the code we have right now we duplicate a huge amount of the code when we create a client:

https://github.com/ayasofyazilim-clomerce/ayasofyazilim-core-project/blob/b712357904cbed634b18e65558fce5c5975e5441/apps/web/src/lib.ts#L16-L48

It would be great to use one function for this code to unify the work and simplify it, here is an example:

async function getServiceClient<T>(ClientClass: new (config: { TOKEN: string | undefined; BASE: string | undefined; HEADERS: Record<string,string> }) => T): Promise<T> {
  const session = await auth();
  const token = session?.access_token;
  return new ClientClass({
    TOKEN: token,
    BASE: process.env.BASE_URL,
    HEADERS,
  });
}

export async function getIdentityServiceClient() {
  return getServiceClient(IdentityServiceClient);
}

In the example you can see that we unified the process of creating a client

ertugrulcan-ays commented 1 month ago

It seems clean and simple, if its well tested we can use it

a0m0rajab commented 1 month ago

Thanks will check it after finishing the tasks in my hand