Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ DC_N1_NEXT_PUBLIC_GOOGLE_ADS_ID=
DC_N1_NEXT_PUBLIC_HEUREKA_API_KEY=
DC_N1_NEXT_PUBLIC_LEADHUB_TRACKING_ID=

# Herbatika storefront container
DC_HERBATIKA_PUBLIC_PORT=3001
DC_HERBATIKA_MEILISEARCH_PRODUCTS_INDEX=products
DC_HERBATIKA_MEILISEARCH_CATEGORIES_INDEX=categories
DC_HERBATIKA_MEILISEARCH_PRODUCERS_INDEX=producers
DC_HERBATIKA_NEXT_PUBLIC_STOREFRONT_AUTH_MODE=session_proxy
DC_HERBATIKA_MEDUSA_BACKEND_URL_INTERNAL=http://medusa-be:9000
DC_HERBATIKA_NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://localhost:9000
DC_HERBATIKA_MEILISEARCH_HOST=http://medusa-meilisearch:7700
DC_HERBATIKA_NEXT_PUBLIC_PACKETA_WIDGET_COUNTRIES=sk
DC_HERBATIKA_NEXT_PUBLIC_PACKETA_WIDGET_API_KEY=
DC_HERBATIKA_PAYLOAD_BASE_URL_INTERNAL=http://payload:8083
DC_HERBATIKA_NEXT_PUBLIC_PAYLOAD_BASE_URL=http://localhost:8083
DC_HERBATIKA_MEILISEARCH_SEARCH_API_KEY=MEILISEARCH_SEARCH_READONLY_KEY_FOR_FRONTEND
DC_HERBATIKA_NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=

# Medusa BE container: app runtime
DC_MEDUSA_BE_NOTIFICATION_PROVIDER=resend
DC_JWT_SECRET=supersecret
Expand All @@ -31,6 +47,7 @@ DC_MEDUSA_BACKEND_URL=
DC_MEDUSA_COOKIE_SECURE=
DC_MEDUSA_COOKIE_SAME_SITE=
DC_MEDUSA_ADMIN_DISABLED_FOR_BACKEND_BUILD=0
DC_STOREFRONT_URL=http://localhost:3001
DC_STORE_CORS="http://localhost:3000,http://127.0.0.1:3000,http://localhost:3001,http://127.0.0.1:3001,http://localhost:8000,http://127.0.0.1:8000,http://localhost:8080,http://127.0.0.1:8080,https://n1.medusa.localhost,http://localhost:9004,https://docs.medusajs.com"
DC_ADMIN_CORS="http://localhost:5173,https://admin.medusa.localhost,http://localhost:9000,https://docs.medusajs.com"
DC_AUTH_CORS="http://localhost:5173,https://admin.medusa.localhost,http://localhost:9000,https://docs.medusajs.com"
Expand Down
24 changes: 16 additions & 8 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,31 @@ run = "bash ./scripts/dev/mise-dev-helpers.sh local-helper down adminer"

[tasks."dev:corepack:update"]
description = "Update Corepack inside the repo pnpm toolchain container"
run = "docker build -f docker/development/pnpm/Dockerfile -t ${PNPM_ENV_IMAGE_TAG:-pnpm-env} . && docker run --rm -e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 -e CI=true -v \"$PWD:/var/www\" -w /var/www ${PNPM_ENV_IMAGE_TAG:-pnpm-env} corepack up"
run = "bash ./scripts/dev/run-pnpm-toolchain.sh corepack up"

[tasks."dev:install"]
description = "Install workspace dependencies inside the repo pnpm toolchain container"
run = "docker build -f docker/development/pnpm/Dockerfile -t ${PNPM_ENV_IMAGE_TAG:-pnpm-env} . && docker run --rm -e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 -e CI=true -v \"$PWD:/var/www\" -w /var/www ${PNPM_ENV_IMAGE_TAG:-pnpm-env} pnpm install --frozen-lockfile"
run = "bash ./scripts/dev/run-pnpm-toolchain.sh pnpm install --frozen-lockfile"

[tasks."dev:install:fix-lock"]
description = "Repair the pnpm lockfile inside the repo pnpm toolchain container"
run = "docker build -f docker/development/pnpm/Dockerfile -t ${PNPM_ENV_IMAGE_TAG:-pnpm-env} . && docker run --rm -e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 -e CI=true -v \"$PWD:/var/www\" -w /var/www ${PNPM_ENV_IMAGE_TAG:-pnpm-env} pnpm install --fix-lockfile"
run = "bash ./scripts/dev/run-pnpm-toolchain.sh pnpm install --fix-lockfile"

[tasks."dev:install:no-lock"]
description = "Install workspace dependencies inside the repo pnpm toolchain container without lockfile"
run = "docker build -f docker/development/pnpm/Dockerfile -t ${PNPM_ENV_IMAGE_TAG:-pnpm-env} . && docker run --rm -e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 -e CI=true -v \"$PWD:/var/www\" -w /var/www ${PNPM_ENV_IMAGE_TAG:-pnpm-env} pnpm install --no-frozen-lockfile"
run = "bash ./scripts/dev/run-pnpm-toolchain.sh pnpm install --no-frozen-lockfile"

[tasks."dev:deps:update"]
description = "Update Medusa backend workspace dependencies inside the repo pnpm toolchain container"
run = "docker build -f docker/development/pnpm/Dockerfile -t ${PNPM_ENV_IMAGE_TAG:-pnpm-env} . && docker run --rm -e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 -e CI=true -v \"$PWD:/var/www\" -w /var/www ${PNPM_ENV_IMAGE_TAG:-pnpm-env} pnpm --filter medusa-be update --latest"
run = "bash ./scripts/dev/run-pnpm-toolchain.sh pnpm --filter medusa-be update --latest"

[tasks."dev:deps:update:medusa"]
description = "Update @medusajs/* packages inside the Medusa backend workspace"
run = "docker build -f docker/development/pnpm/Dockerfile -t ${PNPM_ENV_IMAGE_TAG:-pnpm-env} . && docker run --rm -e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 -e CI=true -v \"$PWD:/var/www\" -w /var/www ${PNPM_ENV_IMAGE_TAG:-pnpm-env} pnpm --filter medusa-be update '@medusajs/*' --latest"
run = "bash ./scripts/dev/run-pnpm-toolchain.sh pnpm --filter medusa-be update '@medusajs/*' --latest"

[tasks."dev:deps:npkill"]
description = "Interactively clean node_modules trees inside the repo pnpm toolchain container"
run = "docker build -f docker/development/pnpm/Dockerfile -t ${PNPM_ENV_IMAGE_TAG:-pnpm-env} . && docker run --rm -it -e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 -v \"$PWD:/var/www\" -w /var/www ${PNPM_ENV_IMAGE_TAG:-pnpm-env} pnpx npkill -x -D -y"
run = "PNPM_TOOLCHAIN_TTY=1 bash ./scripts/dev/run-pnpm-toolchain.sh pnpx npkill -x -D -y"

[tasks."dev:prod"]
description = "Build and run the local production compose stack, including frontend category regeneration"
Expand Down Expand Up @@ -201,7 +201,15 @@ run = "bash ./scripts/dev/refresh-zane-template-db.sh"

[tasks."dev:biome:medusa-be"]
description = "Run Biome with writes against apps/medusa-be"
run = "docker build -f docker/development/pnpm/Dockerfile -t ${PNPM_ENV_IMAGE_TAG:-pnpm-env} . && docker run --rm -e COREPACK_ENABLE_DOWNLOAD_PROMPT=0 -e CI=true -v \"$PWD:/var/www\" -w /var/www ${PNPM_ENV_IMAGE_TAG:-pnpm-env} pnpm exec biome check --write apps/medusa-be"
run = "bash ./scripts/dev/run-pnpm-toolchain.sh pnpm exec biome check --write apps/medusa-be"
Comment thread
coderabbitai[bot] marked this conversation as resolved.

[tasks."nx:lint"]
description = "Run the root lint:nx package script on the host"
run = "pnpm lint:nx"

[tasks."nx:affected"]
description = "Run the root nx:affected package script on the host"
run = "pnpm run nx:affected"

[tasks."test:e2e:medusa-be:http"]
description = "Start isolated Medusa BE e2e stack, run all HTTP e2e specs, then teardown"
Expand Down
6 changes: 0 additions & 6 deletions .npmrc

This file was deleted.

9 changes: 8 additions & 1 deletion apps/herbatika/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "herbatica",
"name": "herbatika",
"version": "0.1.0",
"private": true,
"scripts": {
Expand All @@ -16,6 +16,13 @@
"validate:file-size:json": "node scripts/validate-file-size-guardrail.mjs --json",
"validate:guardrails": "pnpm validate:token-usage && pnpm validate:ui-primitives && pnpm validate:file-size"
},
"nx": {
"tags": [
"type:app",
"platform:web",
"framework:next"
]
},
"dependencies": {
"@medusajs/js-sdk": "^2.12.5",
"@medusajs/types": "^2.12.5",
Expand Down
5 changes: 3 additions & 2 deletions apps/herbatika/src/app/api/storefront-auth/_lib.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NextResponse } from "next/server"

const MEDUSA_BACKEND_URL =
process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL ?? "http://localhost:9000"
import { resolveMedusaBackendUrl } from "@/lib/storefront/runtime-env"

const MEDUSA_BACKEND_URL = resolveMedusaBackendUrl()
const MEDUSA_PUBLISHABLE_KEY =
process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY ?? ""
const AUTH_SESSION_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 14
Expand Down
185 changes: 185 additions & 0 deletions apps/herbatika/src/app/api/storefront-auth/register/register-flow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import type { HttpTypes } from "@medusajs/types"
import {
buildErrorResponse,
buildMedusaUrl,
conflict,
getPublishableHeaders,
isConflictStatus,
parseResponseJson,
serverError,
} from "../_lib"
import {
createWholesaleCompanyRequest,
type ParsedWholesaleRegistration,
} from "./wholesale"

export type ParsedRegisterPayload = {
email: string
password: string
firstName?: string
lastName?: string
wholesale: ParsedWholesaleRegistration | null
}

export const refreshCustomerToken = async (loginToken: string) => {
const refreshResponse = await fetch(buildMedusaUrl("/auth/token/refresh"), {
method: "POST",
headers: {
authorization: `Bearer ${loginToken}`,
},
cache: "no-store",
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if (!refreshResponse.ok) {
return loginToken
}

const refreshPayload = await parseResponseJson(refreshResponse)
return refreshPayload && typeof refreshPayload.token === "string"
? refreshPayload.token
: loginToken
}

export const createCustomerIdentity = async ({
email,
password,
wholesale,
}: Pick<ParsedRegisterPayload, "email" | "password" | "wholesale">) => {
const registerResponse = await fetch(
buildMedusaUrl("/auth/customer/emailpass/register"),
{
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
email,
password,
}),
cache: "no-store",
}
)

const registerConflict = isConflictStatus(registerResponse.status)
if (!(registerResponse.ok || registerConflict)) {
return buildErrorResponse(registerResponse)
}

if (registerConflict && wholesale) {
return conflict(
"Účet s týmto e-mailom už existuje. Prihláste sa a požiadajte o VO účet cez podporu."
)
}

return null
}

export const loginCustomerIdentity = async ({
email,
password,
}: Pick<ParsedRegisterPayload, "email" | "password">) => {
const loginResponse = await fetch(
buildMedusaUrl("/auth/customer/emailpass"),
{
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
email,
password,
}),
cache: "no-store",
}
)

if (!loginResponse.ok) {
return {
error: await buildErrorResponse(loginResponse),
token: null,
}
}

const loginPayload = await parseResponseJson(loginResponse)
const loginToken =
loginPayload && typeof loginPayload.token === "string"
? loginPayload.token
: null

if (!loginToken) {
return {
error: serverError(
"Prihlásenie zákazníka prebehlo úspešne, ale token nebol vrátený."
),
token: null,
}
}

return {
error: null,
token: loginToken,
}
}

const buildCustomerProfile = ({
email,
firstName,
lastName,
wholesale,
}: Omit<ParsedRegisterPayload, "password">): HttpTypes.StoreCreateCustomer => ({
email,
first_name: firstName,
last_name: lastName,
...(wholesale
? {
company_name: wholesale.companyName,
metadata: {
company_identifier: wholesale.companyIdentifier,
},
}
: {}),
})

export const createCustomerProfile = async ({
loginToken,
payload,
}: {
loginToken: string
payload: Omit<ParsedRegisterPayload, "password">
}) => {
const createCustomerResponse = await fetch(
buildMedusaUrl("/store/customers"),
{
method: "POST",
headers: {
"content-type": "application/json",
authorization: `Bearer ${loginToken}`,
...getPublishableHeaders(),
},
body: JSON.stringify(buildCustomerProfile(payload)),
cache: "no-store",
}
)

const customerConflict = isConflictStatus(createCustomerResponse.status)
return createCustomerResponse.ok || customerConflict
? null
: buildErrorResponse(createCustomerResponse)
}

export const createWholesaleProfile = ({
email,
sessionToken,
wholesale,
}: {
email: string
sessionToken: string
wholesale: ParsedWholesaleRegistration | null
}) =>
wholesale
? createWholesaleCompanyRequest({
email,
token: sessionToken,
wholesale,
})
: null
Loading
Loading