diff --git a/apps/web/app/api/v1/client/[environmentId]/identify/people/[userId]/lib/personState.ts b/apps/web/app/api/v1/client/[environmentId]/identify/people/[userId]/lib/personState.ts index 52c1aa8aa2..da8fd44ed0 100644 --- a/apps/web/app/api/v1/client/[environmentId]/identify/people/[userId]/lib/personState.ts +++ b/apps/web/app/api/v1/client/[environmentId]/identify/people/[userId]/lib/personState.ts @@ -1,5 +1,6 @@ import { prisma } from "@formbricks/database"; import { attributeCache } from "@formbricks/lib/attribute/cache"; +import { getAttributesByUserId } from "@formbricks/lib/attribute/service"; import { cache } from "@formbricks/lib/cache"; import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants"; import { displayCache } from "@formbricks/lib/display/cache"; diff --git a/packages/js-core/src/lib/attributes.ts b/packages/js-core/src/lib/attributes.ts index aef097b806..faaf9d58c2 100644 --- a/packages/js-core/src/lib/attributes.ts +++ b/packages/js-core/src/lib/attributes.ts @@ -42,7 +42,6 @@ export const updateAttribute = async ( const res = await api.client.attribute.update({ userId, attributes: { [key]: value } }); if (!res.ok) { - // @ts-expect-error if (res.error.details?.ignore) { logger.error(res.error.message ?? `Error updating person with userId ${userId}`); return { @@ -55,7 +54,6 @@ export const updateAttribute = async ( } return err({ code: "network_error", - // @ts-expect-error status: res.error.status ?? 500, message: res.error.message ?? `Error updating person with userId ${userId}`, url: `${config.get().apiHost}/api/v1/client/${environmentId}/people/${userId}/attributes`, @@ -93,7 +91,7 @@ export const updateAttributes = async ( const updatedAttributes = { ...attributes }; try { - const existingAttributes = config.get().personState.data.attributes; + const existingAttributes = config.get().attributes; if (existingAttributes) { for (const [key, value] of Object.entries(existingAttributes)) { if (updatedAttributes[key] === value) { @@ -123,7 +121,6 @@ export const updateAttributes = async ( if (res.ok) { return ok(updatedAttributes); } else { - // @ts-expect-error if (res.error.details?.ignore) { logger.error(res.error.message ?? `Error updating person with userId ${userId}`); return ok(updatedAttributes); @@ -140,7 +137,7 @@ export const updateAttributes = async ( }; export const isExistingAttribute = (key: string, value: string): boolean => { - if (config.get().personState.data.attributes[key] === value) { + if (config.get().attributes[key] === value) { return true; } diff --git a/packages/js-core/src/lib/initialize.ts b/packages/js-core/src/lib/initialize.ts index 61a41de96c..70f69891d2 100644 --- a/packages/js-core/src/lib/initialize.ts +++ b/packages/js-core/src/lib/initialize.ts @@ -239,6 +239,7 @@ export const initialize = async ( environmentState, personState, filteredSurveys, + attributes: configInput.attributes || {}, }); const surveyNames = filteredSurveys.map((s) => s.name); @@ -280,6 +281,7 @@ export const initialize = async ( personState, environmentState, filteredSurveys, + attributes: configInput.attributes || {}, }); } catch (e) { handleErrorOnFirstInit(); @@ -293,15 +295,9 @@ export const initialize = async ( if (updatedAttributes && Object.keys(updatedAttributes).length > 0) { config.update({ ...config.get(), - personState: { - ...config.get().personState, - data: { - ...config.get().personState.data, - attributes: { - ...config.get().personState.data.attributes, - ...updatedAttributes, - }, - }, + attributes: { + ...config.get().attributes, + ...updatedAttributes, }, }); } diff --git a/packages/types/js.ts b/packages/types/js.ts index 81cf87d506..5c0194a24e 100644 --- a/packages/types/js.ts +++ b/packages/types/js.ts @@ -145,6 +145,7 @@ export const ZJsConfig = z.object({ environmentState: ZJsEnvironmentState, personState: ZJsPersonState, filteredSurveys: z.array(ZSurvey).default([]), + attributes: z.record(z.string()), status: z.object({ value: z.enum(["success", "error"]), expiresAt: z.date().nullable(),