diff --git a/packages/experimental-app-router/src/client.ts b/packages/experimental-app-router/src/client.ts index ac60969ac..19c26e51a 100644 --- a/packages/experimental-app-router/src/client.ts +++ b/packages/experimental-app-router/src/client.ts @@ -8,17 +8,8 @@ import { import { setContext } from '@apollo/client/link/context'; // eslint-disable-next-line import/extensions import { registerApolloClient } from '@apollo/experimental-nextjs-app-support/rsc'; -// eslint-disable-next-line import/extensions -/** - * We are currently importing these utils from their respective dist paths because importing - * from the root will also include the FaustProvider component, which throws an error because - * it does not have the "use client" directive set. - * - * @todo Find a workaround for importing these utils without invoking FaustProvider. - */ -import { getConfig } from '@faustwp/core/dist/mjs/config/index.js'; -import { getGraphqlEndpoint } from '@faustwp/core/dist/mjs/lib/getGraphqlEndpoint.js'; import { fetchAccessToken } from './server/auth/fetchAccessToken.js'; +import { getConfig, getGraphqlEndpoint } from './faust-core-utils.js'; async function createFaustApolloClient(authenticated = false) { const { possibleTypes } = getConfig(); diff --git a/packages/experimental-app-router/src/faust-core-utils.ts b/packages/experimental-app-router/src/faust-core-utils.ts new file mode 100644 index 000000000..73b01d0bc --- /dev/null +++ b/packages/experimental-app-router/src/faust-core-utils.ts @@ -0,0 +1,13 @@ +/** + * We are currently importing these utils from their deep paths because importing + * from the main export will also include the FaustProvider component, which throws an error because + * it does not have the "use client" directive set. + * + * @todo Find a workaround for importing these utils without invoking FaustProvider. + * @see https://github.com/vercel/next.js/issues/12557#issuecomment-1427088366 + */ +export { getConfig } from '@faustwp/core/dist/mjs/config/index.js'; +export { getGraphqlEndpoint } from '@faustwp/core/dist/mjs/lib/getGraphqlEndpoint.js'; +export { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js'; +export { getWpSecret } from '@faustwp/core/dist/mjs/lib/getWpSecret.js'; +export { isValidEmail } from '@faustwp/core/dist/mjs/utils/assert.js'; diff --git a/packages/experimental-app-router/src/server-actions/loginAction.ts b/packages/experimental-app-router/src/server-actions/loginAction.ts index b4f021964..a22fe5124 100644 --- a/packages/experimental-app-router/src/server-actions/loginAction.ts +++ b/packages/experimental-app-router/src/server-actions/loginAction.ts @@ -1,10 +1,9 @@ import { gql } from '@apollo/client'; // eslint-disable-next-line import/extensions import { print } from '@apollo/client/utilities'; -import { getGraphqlEndpoint } from '@faustwp/core/dist/mjs/lib/getGraphqlEndpoint.js'; -import { isValidEmail } from '@faustwp/core/dist/mjs/utils/assert.js'; import { fetchTokens } from '../server/auth/fetchTokens.js'; import { setRefreshToken } from './utils/setRefreshToken.js'; +import { isValidEmail, getGraphqlEndpoint } from '../faust-core-utils.js'; export const GENERATE_AUTHORIZATION_CODE = gql` mutation GenerateAuthorizationCode( diff --git a/packages/experimental-app-router/src/server-actions/logoutAction.ts b/packages/experimental-app-router/src/server-actions/logoutAction.ts index fd66e2e42..5417031a5 100644 --- a/packages/experimental-app-router/src/server-actions/logoutAction.ts +++ b/packages/experimental-app-router/src/server-actions/logoutAction.ts @@ -1,5 +1,5 @@ import { cookies } from 'next/headers.js'; -import { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js'; +import { getWpUrl } from '../faust-core-utils.js'; export async function onLogout() { 'use server'; diff --git a/packages/experimental-app-router/src/server-actions/utils/setRefreshToken.ts b/packages/experimental-app-router/src/server-actions/utils/setRefreshToken.ts index 29706cf72..c6cd722cf 100644 --- a/packages/experimental-app-router/src/server-actions/utils/setRefreshToken.ts +++ b/packages/experimental-app-router/src/server-actions/utils/setRefreshToken.ts @@ -1,5 +1,5 @@ -import { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js'; import { cookies } from 'next/headers.js'; +import { getWpUrl } from '../../faust-core-utils.js'; /** * Sets the refresh token to the proper cookie. This can only be used within diff --git a/packages/experimental-app-router/src/server/auth/fetchTokens.ts b/packages/experimental-app-router/src/server/auth/fetchTokens.ts index f7547ebc8..6443b6794 100644 --- a/packages/experimental-app-router/src/server/auth/fetchTokens.ts +++ b/packages/experimental-app-router/src/server/auth/fetchTokens.ts @@ -1,8 +1,8 @@ -import { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js'; // eslint-disable-next-line import/extensions import { cookies } from 'next/headers'; import { AuthorizeResponse } from '../routeHandler/tokenHandler.js'; import { getUrl } from '../../lib/getUrl.js'; +import { getWpUrl } from '../../faust-core-utils.js'; /** * Fetches tokens using either the refresh token cookie or the provided diff --git a/packages/experimental-app-router/src/server/routeHandler/tokenHandler.ts b/packages/experimental-app-router/src/server/routeHandler/tokenHandler.ts index 7b67ca805..38dcc5077 100644 --- a/packages/experimental-app-router/src/server/routeHandler/tokenHandler.ts +++ b/packages/experimental-app-router/src/server/routeHandler/tokenHandler.ts @@ -1,7 +1,6 @@ -import { getWpUrl } from '@faustwp/core/dist/mjs/lib/getWpUrl.js'; -import { getWpSecret } from '@faustwp/core/dist/mjs/lib/getWpSecret.js'; import { cookies } from 'next/headers.js'; import { NextResponse } from 'next/server.js'; +import { getWpUrl, getWpSecret } from '../../faust-core-utils.js'; export type AuthorizeResponse = { accessToken: string; diff --git a/packages/experimental-app-router/tests/server-actions/onLogin.test.ts b/packages/experimental-app-router/tests/server-actions/onLogin.test.ts index 8d827ae88..56f27509a 100644 --- a/packages/experimental-app-router/tests/server-actions/onLogin.test.ts +++ b/packages/experimental-app-router/tests/server-actions/onLogin.test.ts @@ -5,9 +5,9 @@ import { onLogin, validationError, } from '../../src/server-actions/loginAction.js'; -import { getGraphqlEndpoint } from '@faustwp/core/dist/mjs/lib/getGraphqlEndpoint.js'; import * as fetchTokens from '../../src/server/auth/fetchTokens.js'; import * as setRefreshToken from '../../src/server-actions/utils/setRefreshToken.js'; +import { getGraphqlEndpoint } from '../../src/faust-core-utils.js'; // // https://github.com/aelbore/esbuild-jest/issues/26#issuecomment-893763840 const nextHeaders = { cookies };