Skip to content

Commit

Permalink
Use correct cms service (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
soniaklimas authored and karolkarolka committed Dec 5, 2024
1 parent ae1ce21 commit 5d29850
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
4 changes: 4 additions & 0 deletions apps/storefront/src/envs/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const schema = z.object({
PAYMENT_APP_ID: z.string().default("dev.marina-stripe-saleor-dev"),

NEXT_PUBLIC_BUTTER_CMS_API_KEY: z.string(),

CMS_SERVICE: z.enum(["saleor", "butter"]).default("saleor"),
});

export const clientEnvs = schema.parse({
Expand All @@ -34,4 +36,6 @@ export const clientEnvs = schema.parse({
PAYMENT_APP_ID: process.env.NEXT_PUBLIC_PAYMENT_APP_ID,

NEXT_PUBLIC_BUTTER_CMS_API_KEY: process.env.NEXT_PUBLIC_BUTTER_CMS_API_KEY,

CMS_SERVICE: process.env.CMS_SERVICE,
});
57 changes: 39 additions & 18 deletions apps/storefront/src/services/cms.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
import { butterCMSMenuService } from "@nimara/infrastructure/public/butter-cms/cms-menu/providers";
import { butterCMSPageService } from "@nimara/infrastructure/public/butter-cms/cms-page/providers";
import { saleorCMSMenuService } from "@nimara/infrastructure/public/saleor/cms-menu/providers";
import { saleorCMSPageService } from "@nimara/infrastructure/public/saleor/cms-page/providers";
import type { CMSMenuService } from "@nimara/infrastructure/use-cases/cms-menu/types";
import type { CMSPageService } from "@nimara/infrastructure/use-cases/cms-page/types";

import { clientEnvs } from "@/envs/client";

export const cmsPageServiceSaleor = saleorCMSPageService({
apiURL: clientEnvs.NEXT_PUBLIC_SALEOR_API_URL,
});
const isSaleorCMS = clientEnvs.CMS_SERVICE === "saleor";

export const cmsPageServiceButterCMS = butterCMSPageService({
token: clientEnvs.NEXT_PUBLIC_BUTTER_CMS_API_KEY,
});
const getCMSPageService = async (): Promise<CMSPageService> => {
if (isSaleorCMS) {
const { saleorCMSPageService } = await import(
"@nimara/infrastructure/public/saleor/cms-page/providers"
);

export const cmsMenuServiceSaleor = saleorCMSMenuService({
apiURL: clientEnvs.NEXT_PUBLIC_SALEOR_API_URL,
});
return saleorCMSPageService({
apiURL: clientEnvs.NEXT_PUBLIC_SALEOR_API_URL,
});
} else {
const { butterCMSPageService } = await import(
"@nimara/infrastructure/public/butter-cms/cms-page/providers"
);

export const cmsMenuServiceButterCMS = butterCMSMenuService({
token: clientEnvs.NEXT_PUBLIC_BUTTER_CMS_API_KEY,
});
return butterCMSPageService({
token: clientEnvs.NEXT_PUBLIC_BUTTER_CMS_API_KEY,
});
}
};

export const cmsPageService: CMSPageService = cmsPageServiceButterCMS;
const getCMSMenuService = async (): Promise<CMSMenuService> => {
if (isSaleorCMS) {
const { saleorCMSMenuService } = await import(
"@nimara/infrastructure/public/saleor/cms-menu/providers"
);

export const cmsMenuService: CMSMenuService = cmsMenuServiceButterCMS;
return saleorCMSMenuService({
apiURL: clientEnvs.NEXT_PUBLIC_SALEOR_API_URL,
});
} else {
const { butterCMSMenuService } = await import(
"@nimara/infrastructure/public/butter-cms/cms-menu/providers"
);

return butterCMSMenuService({
token: clientEnvs.NEXT_PUBLIC_BUTTER_CMS_API_KEY,
});
}
};

export const cmsPageService: CMSPageService = await getCMSPageService();
export const cmsMenuService: CMSMenuService = await getCMSMenuService();

0 comments on commit 5d29850

Please sign in to comment.