profile
Two writes on the signed-in customer's account: save one on/off preference, or delete the account.
import { profile } from '@salla.sa/twilight-theme-engine/api/profile';In plain words
profile.updateSettings(name, value) saves one yes/no preference for the signed-in customer, for example whether they want marketing messages (is_notifiable). profile.delete() deletes the customer's account on this store.
Both change real customer data, so this page has no live demo.
Signature
profile.updateSettings(name: string, value: boolean): Promise<void> // POST profile/settings, body { name, value }
profile.delete(): Promise<void> // DELETE profileExample
import { useQueryClient } from '@tanstack/react-query';
import { profile } from '@salla.sa/twilight-theme-engine/api/profile';
import { user } from '@salla.sa/twilight-theme-engine/api/user';
import type { User } from '@salla.sa/twilight-theme-engine/types';
export function useMarketingToggle() {
const queryClient = useQueryClient();
const key = user.queries.current().queryKey;
return async (next: boolean) => {
const previous = queryClient.getQueryData<User | null>(key);
// Show the change at once: the module does not touch the cache.
queryClient.setQueryData<User | null>(key, (old) =>
old?.preferences
? { ...old, preferences: { ...old.preferences, notifications_enabled: next } }
: old
);
try {
await profile.updateSettings('is_notifiable', next);
} catch (error) {
queryClient.setQueryData(key, previous); // roll back
throw error;
}
};
}
How it behaves
Neither reads the response body; a non-2xx answer throws ky's
HTTPError.The saved marketing choice reads back as
user.preferences.notifications_enabled;is_notifiableis the name you write.Both act on the signed-in customer: the request carries their token.
Gotchas
updateSettingsdoes not updateuser.queries.current(). A toggle bound topreferences.notifications_enabledsnaps back until the next fetch unless you update or invalidate that query.profile.delete()has no confirmation step and the engine has nothing to undo it. Ask the customer first.Only
is_notifiableappears in known themes; the engine documents no other setting names.
Related
Source and docs
- Engine source:
packages/theme-engine/src/api/profile.ts