Repository navigation
Feat/medusa 2.16.0 #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/medusa 2.16.0 #464
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
70359de
feat(medusa): v2.16.0, eslint and lint fixes
redeyecz 60f54f1
feat(medusa): pnpm bump 11, fixes, stricter hoisting
redeyecz 985815e
feat(medusa): additional prod fixes
redeyecz 4e5581b
feat(herbatika): internal / external URL split helper, comment out n1…
redeyecz 29ea2cf
feat(medusa): added missing deps that were hidden due to hoisting
redeyecz 569cc62
feat(medusa): revert pnpm docker removal; pnpm hell when node_modules…
redeyecz 8e77610
fix(lint): fix lint and imports
redeyecz 72dd44a
fix(lint): herbatica lint and pnpm wrapper to fix permissions
redeyecz eae449f
fix(medusa): abort signal propagation fix
redeyecz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
185 changes: 185 additions & 0 deletions
185
apps/herbatika/src/app/api/storefront-auth/register/register-flow.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
| }) | ||
|
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 | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.