add platform demo fam
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
famStore.initialized ? famStore.rewards.filter((r: any) => r.status === 'requested').length : 0
|
||||
);
|
||||
|
||||
let { famName = '', session = null, isParent = false, role = 'child' } = $props();
|
||||
let { famName = '', session = null, isParent = false, role = 'child', isDemo = false } = $props();
|
||||
|
||||
let famSlug = $derived(page.data.famSlug ?? page.params.fam);
|
||||
let memberName = $derived(session?.memberName || page.params.username || '');
|
||||
@@ -43,10 +43,10 @@
|
||||
);
|
||||
|
||||
let footerItems = $derived([
|
||||
...(memberName
|
||||
...(memberName && !isDemo
|
||||
? [{ href: `/${famSlug}/${memberName}/preferences`, label: 'Preferences', icon: prefsIcon }]
|
||||
: []),
|
||||
...(isParent && memberName
|
||||
...(isParent && memberName && !isDemo
|
||||
? [{ href: `/${famSlug}/${memberName}/settings`, label: 'Settings', icon: settingsIcon }]
|
||||
: []),
|
||||
{
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
import { Resend } from 'resend';
|
||||
import { RESEND_API } from '$app/env/private';
|
||||
import { getAccessEmailTemplate } from './email-templates';
|
||||
import { getPlatformFlags } from '$lib/server/platform';
|
||||
|
||||
const resend = new Resend(String(RESEND_API));
|
||||
|
||||
let demoCache: { value: boolean; at: number } | null = null;
|
||||
const DEMO_TTL_MS = 10_000;
|
||||
|
||||
async function isDemoMode(): Promise<boolean> {
|
||||
if (demoCache && Date.now() - demoCache.at < DEMO_TTL_MS) return demoCache.value;
|
||||
try {
|
||||
const flags = await getPlatformFlags();
|
||||
demoCache = { value: flags.demo === true, at: Date.now() };
|
||||
return flags.demo === true;
|
||||
} catch {
|
||||
demoCache = { value: false, at: Date.now() };
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendPasswordResetEmail(opts: {
|
||||
to: string;
|
||||
resetLink: string;
|
||||
famName: string;
|
||||
}) {
|
||||
if (await isDemoMode()) return;
|
||||
const { to, resetLink, famName } = opts;
|
||||
|
||||
await resend.emails.send({
|
||||
@@ -30,6 +47,7 @@ export async function sendParentInviteEmail(opts: {
|
||||
famName: string;
|
||||
otp: string;
|
||||
}) {
|
||||
if (await isDemoMode()) return;
|
||||
const { to, inviteLink, famName, otp } = opts;
|
||||
|
||||
await resend.emails.send({
|
||||
@@ -52,6 +70,7 @@ export async function sendAccessUnlockedEmail(opts: {
|
||||
codeValue: string;
|
||||
dashboardUrl: string;
|
||||
}) {
|
||||
if (await isDemoMode()) return;
|
||||
const { to, famName, codeName, codeValue, dashboardUrl } = opts;
|
||||
|
||||
const template = getAccessEmailTemplate(codeValue);
|
||||
@@ -70,6 +89,7 @@ export async function sendWelcomeEmail(opts: {
|
||||
famName: string;
|
||||
dashboardUrl: string;
|
||||
}) {
|
||||
if (await isDemoMode()) return;
|
||||
const { to, famName, dashboardUrl } = opts;
|
||||
|
||||
await resend.emails.send({
|
||||
@@ -112,6 +132,7 @@ export async function sendMentionEmail(opts: {
|
||||
message: string;
|
||||
dashboardUrl: string;
|
||||
}) {
|
||||
if (await isDemoMode()) return;
|
||||
const { to, parentName, authorName, message, dashboardUrl } = opts;
|
||||
|
||||
await resend.emails.send({
|
||||
@@ -138,6 +159,7 @@ export async function sendClaimRequestEmail(opts: {
|
||||
rewardValue: string;
|
||||
dashboardUrl: string;
|
||||
}) {
|
||||
if (await isDemoMode()) return;
|
||||
const { to, parentName, childName, rewardName, rewardValue, dashboardUrl } = opts;
|
||||
|
||||
await resend.emails.send({
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { SCHEMA_PLAN } from '@shared/pb/schema';
|
||||
import { PB_ENDPOINT } from '$lib/server/pocketbase';
|
||||
import { PB_EMAIL, PB_PASSWORD, MEMBER_SECRET } from '$app/env/private';
|
||||
import { getPlatformFlags } from '$lib/server/platform';
|
||||
|
||||
let token: string | null = null;
|
||||
let tokenExpiry = 0;
|
||||
@@ -20,6 +21,11 @@ async function auth(): Promise<string> {
|
||||
return token!;
|
||||
}
|
||||
|
||||
async function isDemo(): Promise<boolean> {
|
||||
const flags = await getPlatformFlags();
|
||||
return flags.demo === true;
|
||||
}
|
||||
|
||||
async function getCollection(name: string): Promise<any | null> {
|
||||
const t = await auth();
|
||||
const res = await fetch(`${PB_ENDPOINT}/api/collections?filter=name='${name}'`, {
|
||||
@@ -444,8 +450,10 @@ export async function migrate(): Promise<void> {
|
||||
await ensureAccessCodes();
|
||||
await ensurePlatform();
|
||||
await ensureDefaultSeasons();
|
||||
await seedDemoFamily();
|
||||
await seedDemoCompletions();
|
||||
if (await isDemo()) {
|
||||
await seedDemoFamily();
|
||||
await seedDemoCompletions();
|
||||
}
|
||||
console.log('[migrate] Done');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user