From b7cc8f5b16737eae5be707dfb2d65400e55109d0 Mon Sep 17 00:00:00 2001 From: atourneriePresta Date: Thu, 24 Aug 2023 18:19:34 +0200 Subject: [PATCH] feat: add defaults values to existing context --- src/components/PsAccounts.vue | 2 +- src/lib/ContextValidator.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/PsAccounts.vue b/src/components/PsAccounts.vue index db05f202..9a0f993d 100644 --- a/src/components/PsAccounts.vue +++ b/src/components/PsAccounts.vue @@ -101,7 +101,7 @@ interface PsAccountsProps { context?: Context; } const props = withDefaults(defineProps(), { - context: () => window.contextPsAccounts || {} + context: () => (window.contextPsAccounts ? contextSchema.validate(window.contextPsAccounts).value : {}) as Context }); const errors = ref([]); diff --git a/src/lib/ContextValidator.ts b/src/lib/ContextValidator.ts index 2815e629..9d742056 100644 --- a/src/lib/ContextValidator.ts +++ b/src/lib/ContextValidator.ts @@ -1,4 +1,5 @@ import Joi from 'joi'; +import { ShopContext } from '@/types/context'; export const backendUserSchema = Joi.object().keys({ email: Joi.string().email({ tlds: false }).allow(null).default(null), @@ -55,7 +56,7 @@ export const userSchema = Joi.object().keys({ export const contextSchema = Joi.object().keys({ accountsUiUrl: Joi.string().allow(null).default(null), backendUser: backendUserSchema.optional().allow({}).default({}), - currentContext: currentContextSchema.optional().allow({}).default({}), + currentContext: currentContextSchema.optional().default({ type: ShopContext.All }), // dependencies onboardingLink: Joi.string().uri().optional().allow(null) .allow('')