@shopify/shopify-app-remix
Version:
Shopify Remix - to simplify the building of Shopify Apps with Remix
29 lines (24 loc) • 866 B
text/typescript
import {SessionNotFoundError} from '../../errors';
import {BasicParams} from '../../types';
import {storefrontClientFactory} from '../../clients/storefront';
import {ensureValidOfflineSession} from '../../helpers';
import {
UnauthenticatedStorefrontContext,
GetUnauthenticatedStorefrontContext,
} from './types';
export function unauthenticatedStorefrontContextFactory(
params: BasicParams,
): GetUnauthenticatedStorefrontContext {
return async (shop: string): Promise<UnauthenticatedStorefrontContext> => {
const session = await ensureValidOfflineSession(params, shop);
if (!session) {
throw new SessionNotFoundError(
`Could not find a session for shop ${shop} when creating unauthenticated storefront context`,
);
}
return {
session,
storefront: storefrontClientFactory({params, session}),
};
};
}