create-nextblock 0.11.3 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/package.json +1 -1
  2. package/templates/nextblock-template/app/(auth-pages)/sign-up/SignUpForm.tsx +141 -0
  3. package/templates/nextblock-template/app/(auth-pages)/sign-up/page.tsx +40 -122
  4. package/templates/nextblock-template/app/(auth-pages)/two-factor/components/TwoFactorForm.tsx +5 -0
  5. package/templates/nextblock-template/app/[slug]/page.tsx +5 -2
  6. package/templates/nextblock-template/app/[slug]/page.utils.ts +10 -9
  7. package/templates/nextblock-template/app/actions/email.ts +8 -1
  8. package/templates/nextblock-template/app/actions/feedback.ts +1 -0
  9. package/templates/nextblock-template/app/actions/formActions.ts +20 -97
  10. package/templates/nextblock-template/app/actions/interactions.ts +3 -2
  11. package/templates/nextblock-template/app/actions/twoFactorEmail.ts +3 -2
  12. package/templates/nextblock-template/app/actions/visualEditingActions.test.ts +1 -1
  13. package/templates/nextblock-template/app/actions/visualEditingActions.ts +2 -0
  14. package/templates/nextblock-template/app/actions.ts +14 -0
  15. package/templates/nextblock-template/app/api/brand/email-logo/route.ts +48 -0
  16. package/templates/nextblock-template/app/api/cron/reset-sandbox/route.ts +47 -1
  17. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +5169 -8826
  18. package/templates/nextblock-template/app/article/[slug]/page.tsx +5 -2
  19. package/templates/nextblock-template/app/article/[slug]/page.utils.ts +1 -0
  20. package/templates/nextblock-template/app/cms/pages/actions.ts +22 -18
  21. package/templates/nextblock-template/app/cms/pages/components/PageForm.tsx +20 -2
  22. package/templates/nextblock-template/app/cms/posts/actions.ts +5 -0
  23. package/templates/nextblock-template/app/cms/posts/components/PostForm.tsx +137 -133
  24. package/templates/nextblock-template/app/cms/settings/copyright/actions.ts +36 -0
  25. package/templates/nextblock-template/app/cms/settings/copyright/components/CopyrightForm.tsx +26 -1
  26. package/templates/nextblock-template/app/cms/settings/copyright/page.tsx +6 -2
  27. package/templates/nextblock-template/app/cms/settings/email/actions.ts +7 -3
  28. package/templates/nextblock-template/app/cms/settings/logos/actions.ts +29 -14
  29. package/templates/nextblock-template/app/cms/settings/logos/components/SetActiveLogoButton.tsx +42 -0
  30. package/templates/nextblock-template/app/cms/settings/logos/page.tsx +18 -5
  31. package/templates/nextblock-template/app/layout.tsx +29 -17
  32. package/templates/nextblock-template/app/lib/seo.test.ts +36 -0
  33. package/templates/nextblock-template/app/lib/seo.ts +32 -0
  34. package/templates/nextblock-template/app/product/[slug]/page.tsx +5 -2
  35. package/templates/nextblock-template/components/AppShell.tsx +16 -1
  36. package/templates/nextblock-template/components/auth/AuthBotProtection.tsx +182 -0
  37. package/templates/nextblock-template/docs/04-DATABASE-AND-AUTH.md +36 -42
  38. package/templates/nextblock-template/lib/botProtection/verify.ts +134 -0
  39. package/templates/nextblock-template/lib/email/branding-format.test.ts +133 -0
  40. package/templates/nextblock-template/lib/email/branding-format.ts +123 -0
  41. package/templates/nextblock-template/lib/email/branding.ts +76 -0
  42. package/templates/nextblock-template/lib/logos/active-logo.ts +53 -0
  43. package/templates/nextblock-template/lib/media/resolveMediaUrl.ts +1 -0
  44. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +8 -213
  45. package/templates/nextblock-template/lib/visual-editing/draft-content.ts +4 -2
  46. package/templates/nextblock-template/lib/visual-editing/mutations.ts +2 -2
  47. package/templates/nextblock-template/lib/visual-editing/product-drafts.ts +1 -0
  48. package/templates/nextblock-template/package.json +1 -1
  49. package/templates/nextblock-template/proxy.ts +16 -0
  50. package/templates/nextblock-template/public/images/nextblock-logo-button-tiny.png +0 -0
  51. package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,76 @@
1
+ import 'server-only';
2
+
3
+ import { getServiceRoleSupabaseClient } from '@nextblock-cms/db/server';
4
+
5
+ import { getSiteSettings } from '../../app/lib/site-settings';
6
+ import { DEFAULT_SITE_TITLE } from '../../app/lib/seo';
7
+ import { resolveMediaUrl } from '../media/resolveMediaUrl';
8
+ import { resolveMediaBaseUrl } from '../storage/provider';
9
+ import { resolveSiteUrl } from '../site-url';
10
+ import { resolveActiveLogo } from '../logos/active-logo';
11
+ import { pickEmailLogoObjectKey } from './branding-format';
12
+ import type { EmailBranding, LogoMediaLike } from './branding-format';
13
+
14
+ // Server-side resolution of the tenant branding that white-labels every transactional
15
+ // email. The mailer choke point (app/actions/email.ts) and the auth-email logo endpoint
16
+ // (app/api/brand/email-logo) both read this, so every dispatched pipeline — 2FA codes,
17
+ // form/interaction notifications, the SMTP test, feedback, and the Supabase auth emails —
18
+ // shows the operator's own logo instead of a hardcoded NextBlock one.
19
+ //
20
+ // The pure header-rendering helpers live in ./branding-format (no server-only imports, so
21
+ // they're unit-testable); re-export them here so callers have a single import surface.
22
+ export {
23
+ EMAIL_BRAND_HEADER_TOKEN,
24
+ EMAIL_LOGO_MAX_WIDTH,
25
+ applyEmailBranding,
26
+ renderEmailBrandHeader,
27
+ } from './branding-format';
28
+ export type { EmailBranding } from './branding-format';
29
+
30
+ /**
31
+ * Resolve the tenant's active logo to an ABSOLUTE URL usable in an email `<img>`.
32
+ * The newest `logos` row wins (the table has no is_active flag). Returns `null` when
33
+ * there is no logo, no linked media, or the URL cannot be resolved — the caller then
34
+ * renders a text banner instead.
35
+ */
36
+ async function resolveActiveLogoUrl(): Promise<string | null> {
37
+ try {
38
+ const supabase = getServiceRoleSupabaseClient();
39
+ // Honor the admin-pinned active logo (site_settings.active_logo_id), else newest.
40
+ const logo = await resolveActiveLogo(supabase);
41
+ const media = (logo as { media?: LogoMediaLike | null } | null)?.media ?? null;
42
+ // Prefer the original uploaded file over the AVIF `object_key` (email can't render AVIF).
43
+ const objectKey = pickEmailLogoObjectKey(media);
44
+ if (!objectKey) return null;
45
+
46
+ // Pass the resolved base explicitly so the native-Supabase storage URL is honored
47
+ // even when NEXT_PUBLIC_R2_BASE_URL isn't set.
48
+ const resolved = resolveMediaUrl(objectKey, resolveMediaBaseUrl());
49
+ if (!resolved) return null;
50
+ if (resolved.startsWith('http://') || resolved.startsWith('https://')) {
51
+ return resolved;
52
+ }
53
+ // Relative result (a bundled `/images/*` key, or the no-storage-base case): make it
54
+ // absolute against the public site origin so email clients can fetch it.
55
+ const origin = resolveSiteUrl();
56
+ return `${origin}${resolved.startsWith('/') ? '' : '/'}${resolved}`;
57
+ } catch {
58
+ // Service role unavailable or table missing (pre-setup) — treat as "no logo".
59
+ return null;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Resolve tenant email branding. Read fresh on each call (no React `cache`, so it is safe
65
+ * from fire-and-forget dispatch paths where the request scope may already be torn down);
66
+ * the underlying site-settings read is already cross-request cached via `unstable_cache`,
67
+ * and a fresh read each time is what keeps the logo "change at will".
68
+ */
69
+ export async function resolveEmailBranding(): Promise<EmailBranding> {
70
+ const [settings, logoUrl] = await Promise.all([
71
+ getSiteSettings().catch(() => null),
72
+ resolveActiveLogoUrl(),
73
+ ]);
74
+ const siteName = settings?.siteTitle?.trim() || DEFAULT_SITE_TITLE;
75
+ return { logoUrl, siteName };
76
+ }
@@ -0,0 +1,53 @@
1
+ import type { SupabaseClient } from '@supabase/supabase-js';
2
+ import type { Database } from '@nextblock-cms/db';
3
+
4
+ // The single, shared definition of "the active logo", used by the public header, the CMS
5
+ // branding page, transactional-email branding, and invoices. The operator can pin a
6
+ // specific logo (stored as `site_settings.active_logo_id`); when none is pinned we fall
7
+ // back to the most recently created logo (the historical default). The setting key is a
8
+ // plain, non-secret `site_settings` row, so it is publicly readable under RLS (the public
9
+ // header can read it with the anon client) and writable by ADMIN/WRITER.
10
+
11
+ /** site_settings key holding the admin-selected active logo id (a `logos.id` uuid string). */
12
+ export const ACTIVE_LOGO_SETTING_KEY = 'active_logo_id';
13
+
14
+ // Accept any of the app's Supabase clients (request-scoped, static/anon, or service-role).
15
+ type AnyClient = SupabaseClient<Database>;
16
+
17
+ /** The admin-pinned active logo id, or null when none has been chosen. */
18
+ export async function resolveActiveLogoId(client: AnyClient): Promise<string | null> {
19
+ const { data } = await client
20
+ .from('site_settings')
21
+ .select('value')
22
+ .eq('key', ACTIVE_LOGO_SETTING_KEY)
23
+ .maybeSingle();
24
+ const value = data?.value;
25
+ return typeof value === 'string' && value.length > 0 ? value : null;
26
+ }
27
+
28
+ /**
29
+ * Resolve the active logo row (joined with its media) for the given client: the pinned
30
+ * logo when set and still present, otherwise the most recently created logo. Returns the
31
+ * raw row; callers cast to their local logo type. Returns null when there are no logos.
32
+ */
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ export async function resolveActiveLogo(client: AnyClient): Promise<any> {
35
+ const activeId = await resolveActiveLogoId(client);
36
+
37
+ if (activeId) {
38
+ const { data } = await client
39
+ .from('logos')
40
+ .select('*, media:media_id (*)')
41
+ .eq('id', activeId)
42
+ .maybeSingle();
43
+ if (data) return data;
44
+ }
45
+
46
+ const { data } = await client
47
+ .from('logos')
48
+ .select('*, media:media_id (*)')
49
+ .order('created_at', { ascending: false })
50
+ .limit(1)
51
+ .maybeSingle();
52
+ return data ?? null;
53
+ }
@@ -12,6 +12,7 @@ const BUNDLED_PUBLIC_MEDIA_KEYS = new Set([
12
12
  'images/included.webp',
13
13
  'images/metadata_image.webp',
14
14
  'images/nextblock-logo-small.webp',
15
+ 'images/nextblock-logo-button-tiny.png',
15
16
  'images/nx-graph.webp',
16
17
  'images/pants.webp',
17
18
  'images/programmer-upscaled.webp',