Skip to content

Commit

Permalink
fix: Make NEXT_PUBLIC_BUTTER_CMS_API_KEY optional (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
soniaklimas authored and karolkarolka committed Dec 17, 2024
1 parent 59c9e8a commit 7c116ae
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/storefront/src/envs/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const schema = z.object({

PAYMENT_APP_ID: z.string().default("dev.marina-stripe-saleor-dev"),

NEXT_PUBLIC_BUTTER_CMS_API_KEY: z.string(),
NEXT_PUBLIC_BUTTER_CMS_API_KEY: z.string().optional(),

CMS_SERVICE: z.enum(["saleor", "butter"]).default("saleor"),
});
Expand Down
12 changes: 12 additions & 0 deletions apps/storefront/src/services/cms.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { invariant } from "ts-invariant";

import type { CMSMenuService } from "@nimara/infrastructure/use-cases/cms-menu/types";
import type { CMSPageService } from "@nimara/infrastructure/use-cases/cms-page/types";

Expand All @@ -15,6 +17,11 @@ const getCMSPageService = async (): Promise<CMSPageService> => {
apiURL: clientEnvs.NEXT_PUBLIC_SALEOR_API_URL,
});
} else {
invariant(
clientEnvs.NEXT_PUBLIC_BUTTER_CMS_API_KEY,
"ButterCMS API key is required but not provided. Please set NEXT_PUBLIC_BUTTER_CMS_API_KEY in the environment variables.",
);

const { butterCMSPageService } = await import(
"@nimara/infrastructure/public/butter-cms/cms-page/providers"
);
Expand All @@ -35,6 +42,11 @@ const getCMSMenuService = async (): Promise<CMSMenuService> => {
apiURL: clientEnvs.NEXT_PUBLIC_SALEOR_API_URL,
});
} else {
invariant(
clientEnvs.NEXT_PUBLIC_BUTTER_CMS_API_KEY,
"ButterCMS API key is required but not provided. Please set NEXT_PUBLIC_BUTTER_CMS_API_KEY in the environment variables.",
);

const { butterCMSMenuService } = await import(
"@nimara/infrastructure/public/butter-cms/cms-menu/providers"
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Butter from "buttercms/lib/butter";
import { invariant } from "ts-invariant";

import type { ButterCMSMenuItem } from "@nimara/domain/objects/Menu";

Expand All @@ -11,6 +12,10 @@ import type { ButterCMSMenuServiceConfig } from "../types";
export const butterCMSMenuGetInfra =
({ token }: ButterCMSMenuServiceConfig): CMSMenuGetInfra =>
async ({ languageCode, slug }) => {
invariant(
token,
"ButterCMS token is required but was not provided. Set NEXT_PUBLIC_BUTTER_CMS_API_KEY in the environment variables.",
);
const locale = convertLanguageCode(languageCode);
let menu;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type PageRetrieveParams from "buttercms";
import Butter from "buttercms/lib/butter";
import { invariant } from "ts-invariant";

import {
type ButterCMSPageFields,
Expand All @@ -25,6 +26,10 @@ interface PageRetrieveParams {
export const butterCMSPageGetInfra =
({ token }: ButterCMSPageServiceConfig): CMSPageGetInfra =>
async ({ pageType, slug, languageCode }) => {
invariant(
token,
"ButterCMS token is required but was not provided. Set NEXT_PUBLIC_BUTTER_CMS_API_KEY in the environment variables.",
);
const resolvedPageType = pageType ?? PageType.STATIC_PAGE;
const locale = convertLanguageCode(languageCode);
let page;
Expand Down

0 comments on commit 7c116ae

Please sign in to comment.