Merge branch 'develop' into feature/MED-129

This commit is contained in:
Danel Kungla
2025-09-24 15:00:27 +03:00
622 changed files with 19603 additions and 10824 deletions

View File

@@ -1,5 +1,7 @@
import 'server-only';
import getBaseWebpackConfig from 'next/dist/build/webpack-config';
import {
AuthError,
type EmailOtpType,
@@ -21,7 +23,7 @@ export function createAuthCallbackService(client: SupabaseClient) {
* @description Service for handling auth callbacks in Supabase
*/
class AuthCallbackService {
constructor(private readonly client: SupabaseClient) { }
constructor(private readonly client: SupabaseClient) {}
/**
* @name verifyTokenHash
@@ -131,10 +133,13 @@ class AuthCallbackService {
* @description Exchanges the auth code for a session and redirects the user to the next page or an error page
* @param authCode
*/
async exchangeCodeForSession(authCode: string): Promise<{
isSuccess: boolean;
user: User;
} | ErrorURLParameters> {
async exchangeCodeForSession(authCode: string): Promise<
| {
isSuccess: boolean;
user: User;
}
| ErrorURLParameters
> {
let user: User;
try {
const { data, error } =
@@ -181,8 +186,10 @@ class AuthCallbackService {
* Check if user is from Keycloak provider
*/
private isKeycloakUser(user: any): boolean {
return user?.app_metadata?.provider === 'keycloak' ||
user?.app_metadata?.providers?.includes('keycloak');
return (
user?.app_metadata?.provider === 'keycloak' ||
user?.app_metadata?.providers?.includes('keycloak')
);
}
private async setupMedusaUserForKeycloak(user: any): Promise<void> {
@@ -202,11 +209,16 @@ class AuthCallbackService {
.single();
if (fetchError && fetchError.code !== 'PGRST116') {
console.error('Error fetching account data for Keycloak user:', fetchError);
console.error(
'Error fetching account data for Keycloak user:',
fetchError,
);
return;
}
const { medusaLoginOrRegister } = await import('../../features/medusa-storefront/src/lib/data/customer');
const { medusaLoginOrRegister } = await import(
'../../features/medusa-storefront/src/lib/data/customer'
);
const medusaAccountId = await medusaLoginOrRegister({
email: user.email,
supabaseUserId: user.id,
@@ -215,7 +227,10 @@ class AuthCallbackService {
});
const currentMedusaAccountId = accountData?.medusa_account_id;
if (!currentMedusaAccountId || currentMedusaAccountId !== medusaAccountId) {
if (
!currentMedusaAccountId ||
currentMedusaAccountId !== medusaAccountId
) {
const { error: updateError } = await this.client
.schema('medreport')
.from('accounts')
@@ -228,12 +243,21 @@ class AuthCallbackService {
return;
}
console.log('Successfully set up Medusa account for Keycloak user:', medusaAccountId);
console.log(
'Successfully set up Medusa account for Keycloak user:',
medusaAccountId,
);
} else {
console.log('Keycloak user already has Medusa account:', accountData.medusa_account_id);
console.log(
'Keycloak user already has Medusa account:',
accountData.medusa_account_id,
);
}
} catch (error) {
console.error('Error setting up Medusa account for Keycloak user:', error);
console.error(
'Error setting up Medusa account for Keycloak user:',
error,
);
}
}

View File

@@ -4,8 +4,8 @@ import { cookies } from 'next/headers';
import { createServerClient } from '@supabase/ssr';
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
import { Database } from '../database.types';
import { getSupabaseClientKeys } from '../get-supabase-client-keys';
/**
* @name getSupabaseServerClient

View File

@@ -199,6 +199,7 @@ export type Database = {
changed_by: string
created_at: string
extra_data: Json | null
extra_data: Json | null
id: number
}
Insert: {
@@ -207,6 +208,7 @@ export type Database = {
changed_by: string
created_at?: string
extra_data?: Json | null
extra_data?: Json | null
id?: number
}
Update: {
@@ -215,6 +217,7 @@ export type Database = {
changed_by?: string
created_at?: string
extra_data?: Json | null
extra_data?: Json | null
id?: number
}
Relationships: []
@@ -520,6 +523,61 @@ export type Database = {
},
]
}
ai_responses: {
Row: {
account_id: string
created_at: string
id: string
input: Json
latest_data_change: string
prompt_id: string
prompt_name: string
response: Json
}
Insert: {
account_id: string
created_at?: string
id?: string
input: Json
latest_data_change: string
prompt_id: string
prompt_name: string
response: Json
}
Update: {
account_id?: string
created_at?: string
id?: string
input?: Json
latest_data_change?: string
prompt_id?: string
prompt_name?: string
response?: Json
}
Relationships: [
{
foreignKeyName: "ai_responses_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "accounts"
referencedColumns: ["id"]
},
{
foreignKeyName: "ai_responses_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "user_account_workspace"
referencedColumns: ["id"]
},
{
foreignKeyName: "ai_responses_account_id_fkey"
columns: ["account_id"]
isOneToOne: false
referencedRelation: "user_accounts"
referencedColumns: ["id"]
},
]
}
analyses: {
Row: {
analysis_id_oid: string
@@ -693,6 +751,9 @@ export type Database = {
response_value_is_negative: boolean | null
response_value_is_within_norm: boolean | null
status: string | null
response_value_is_negative: boolean | null
response_value_is_within_norm: boolean | null
status: string | null
unit: string | null
updated_at: string | null
}
@@ -711,9 +772,12 @@ export type Database = {
original_response_element: Json
response_time?: string | null
response_value?: number | null
response_time?: string | null
response_value?: number | null
response_value_is_negative?: boolean | null
response_value_is_within_norm?: boolean | null
status?: string | null
status?: string | null
unit?: string | null
updated_at?: string | null
}
@@ -735,6 +799,7 @@ export type Database = {
response_value_is_negative?: boolean | null
response_value_is_within_norm?: boolean | null
status?: string | null
status?: string | null
unit?: string | null
updated_at?: string | null
}
@@ -1284,6 +1349,7 @@ export type Database = {
id: number
status: Database["medreport"]["Enums"]["analysis_feedback_status"]
updated_at: string | null
updated_at: string | null
updated_by: string | null
user_id: string
value: string | null
@@ -1296,6 +1362,7 @@ export type Database = {
id?: number
status?: Database["medreport"]["Enums"]["analysis_feedback_status"]
updated_at?: string | null
updated_at?: string | null
updated_by?: string | null
user_id: string
value?: string | null
@@ -1308,6 +1375,7 @@ export type Database = {
id?: number
status?: Database["medreport"]["Enums"]["analysis_feedback_status"]
updated_at?: string | null
updated_at?: string | null
updated_by?: string | null
user_id?: string
value?: string | null
@@ -1394,6 +1462,7 @@ export type Database = {
Row: {
action: string
created_at: string | null
created_at: string | null
has_analysis_results: boolean
has_error: boolean
id: string
@@ -1403,6 +1472,13 @@ export type Database = {
response_xml: string | null
updated_at: string | null
xml: string | null
id: string
medipost_external_order_id: string | null
medipost_private_message_id: string | null
medusa_order_id: string | null
response_xml: string | null
updated_at: string | null
xml: string | null
}
Insert: {
action: string
@@ -1429,7 +1505,31 @@ export type Database = {
response_xml?: string | null
updated_at?: string | null
xml?: string | null
created_at?: string | null
has_analysis_results?: boolean
has_error?: boolean
id?: string
medipost_external_order_id?: string | null
medipost_private_message_id?: string | null
medusa_order_id?: string | null
response_xml?: string | null
updated_at?: string | null
xml?: string | null
}
Update: {
action?: string
created_at?: string | null
has_analysis_results?: boolean
has_error?: boolean
id?: string
medipost_external_order_id?: string | null
medipost_private_message_id?: string | null
medusa_order_id?: string | null
response_xml?: string | null
updated_at?: string | null
xml?: string | null
}
Relationships: []
Relationships: []
}
medreport_product_groups: {
@@ -2198,6 +2298,9 @@ export type Database = {
Args: { account_id: string; user_id: string }
Returns: boolean
}
order_has_medipost_dispatch_error: {
Args: { medusa_order_id: string }
Returns: boolean
order_has_medipost_dispatch_error: {
Args: { medusa_order_id: string }
Returns: boolean
@@ -2227,6 +2330,26 @@ export type Database = {
Returns: undefined
}
update_account: {
Args:
| {
p_city: string
p_email: string
p_has_consent_personal_data: boolean
p_last_name: string
p_name: string
p_personal_code: string
p_phone: string
p_uid: string
}
| {
p_city: string
p_has_consent_personal_data: boolean
p_last_name: string
p_name: string
p_personal_code: string
p_phone: string
p_uid: string
}
Args:
| {
p_city: string

View File

@@ -6,15 +6,20 @@ import { z } from 'zod';
export function getSupabaseClientKeys() {
return z
.object({
url: z.string({
error: `Please provide the variable NEXT_PUBLIC_SUPABASE_URL`,
})
.describe(`This is the URL of your hosted Supabase instance. Please provide the variable NEXT_PUBLIC_SUPABASE_URL.`),
url: z
.string({
error: `Please provide the variable NEXT_PUBLIC_SUPABASE_URL`,
})
.describe(
`This is the URL of your hosted Supabase instance. Please provide the variable NEXT_PUBLIC_SUPABASE_URL.`,
),
anonKey: z
.string({
error: `Please provide the variable NEXT_PUBLIC_SUPABASE_ANON_KEY`,
})
.describe(`This is the anon key provided by Supabase. It is a public key used client-side. Please provide the variable NEXT_PUBLIC_SUPABASE_ANON_KEY.`)
.describe(
`This is the anon key provided by Supabase. It is a public key used client-side. Please provide the variable NEXT_PUBLIC_SUPABASE_ANON_KEY.`,
)
.min(1),
})
.parse({

View File

@@ -31,7 +31,8 @@ export function useSignInWithEmailPassword() {
isDevPasswordLogin: true,
});
await client
.schema('medreport').from('accounts')
.schema('medreport')
.from('accounts')
.update({ medusa_account_id: medusaAccountId })
.eq('primary_owner_user_id', user.id)
.eq('is_personal_account', true);

View File

@@ -9,7 +9,9 @@ export function useSignOut() {
mutationFn: async () => {
try {
try {
const { medusaLogout } = await import('../../../features/medusa-storefront/src/lib/data/customer');
const { medusaLogout } = await import(
'../../../features/medusa-storefront/src/lib/data/customer'
);
await medusaLogout(undefined, false);
} catch (medusaError) {
console.warn('Medusa logout failed or not available:', medusaError);

View File

@@ -46,7 +46,8 @@ export function useSignUpWithEmailAndPassword() {
isDevPasswordLogin: true,
});
await client
.schema('medreport').from('accounts')
.schema('medreport')
.from('accounts')
.update({ medusa_account_id: medusaAccountId })
.eq('primary_owner_user_id', user!.id)
.eq('is_personal_account', true);