-
Notifications
You must be signed in to change notification settings - Fork 7
Hosting signup: customize step before payment #1438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
016e736
hosting: customize step before payment
feruzm 859d3af
hosting: preserve saved reservations on resume; review fix batch
feruzm 748842c
hosting: size the picker glyphs with size-N per the icon guideline
feruzm 892bc45
hosting: throttle tenant creation and stop no-op clock refreshes
feruzm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * Appearance constants shared with the blog SPA, next to the style template | ||
| * roster (style-templates.ts) and under the same rules: dependency-free, | ||
| * because the SPA bundles these, and living here because the API image builds | ||
| * from hosting/api alone and could not import in the other direction. | ||
| * | ||
| * The SPA's font preset definitions (src/core/theme-appearance.ts) carry the | ||
| * actual font stacks; the API needs only the closed key set for validating | ||
| * signup overrides. A lockstep test on the SPA side | ||
| * (src/styles/style-template-roster.test.ts) keeps the two agreeing. | ||
| */ | ||
| export const FONT_PRESET_KEYS = Object.freeze([ | ||
| 'classic', | ||
| 'editorial', | ||
| 'modern', | ||
| 'technical', | ||
| 'system', | ||
| ] as const); | ||
|
|
||
| export type FontPresetKey = (typeof FONT_PRESET_KEYS)[number]; | ||
|
|
||
| /** | ||
| * `#rgb` or `#rrggbb`, the same shapes the SPA's parseHexColor accepts. The | ||
| * signup path validates and rejects; the Configuration Editor's full-document | ||
| * path stays lenient on purpose, because the SPA already treats an | ||
| * unparseable accent as "the template's own accent stands". | ||
| */ | ||
| export const ACCENT_HEX_PATTERN = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { STYLE_TEMPLATES } from '../style-templates'; | ||
| import { templateRoutes } from './templates'; | ||
|
|
||
| describe('GET /v1/templates', () => { | ||
| it('serves one card per roster entry with display fields and a single default', async () => { | ||
| const res = await templateRoutes.request('http://localhost/'); | ||
| expect(res.status).toBe(200); | ||
| expect(res.headers.get('cache-control')).toContain('max-age'); | ||
|
|
||
| const body = (await res.json()) as { | ||
| templates: Array<{ | ||
| id: string; | ||
| name: string; | ||
| tagline: string; | ||
| isDefault: boolean; | ||
| colors: Record<string, string>; | ||
| headingStyle: string; | ||
| }>; | ||
| }; | ||
|
|
||
| expect(body.templates.map((t) => t.id).sort()).toEqual( | ||
| [...STYLE_TEMPLATES].sort(), | ||
| ); | ||
| expect(body.templates.filter((t) => t.isDefault)).toHaveLength(1); | ||
| for (const t of body.templates) { | ||
| expect(t.name.length).toBeGreaterThan(0); | ||
| expect(t.tagline.length).toBeGreaterThan(0); | ||
| for (const key of ['background', 'surface', 'accent', 'text']) { | ||
| expect(t.colors[key], `${t.id} colors.${key}`).toBeTruthy(); | ||
| } | ||
| expect(['serif', 'sans', 'mono']).toContain(t.headingStyle); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { Hono } from 'hono'; | ||
| import { templateCatalog } from '../style-template-display'; | ||
|
|
||
| /** | ||
| * Public template catalog for the signup UI's picker. Static data straight | ||
| * from the roster and its display map, so the signup can never carry its own | ||
| * copy of the template list. Cacheable: it changes only on deploy. | ||
| */ | ||
| export const templateRoutes = new Hono(); | ||
|
|
||
| templateRoutes.get('/', (c) => { | ||
| c.header('Cache-Control', 'public, max-age=300'); | ||
| return c.json({ templates: templateCatalog() }); | ||
| }); |
119 changes: 119 additions & 0 deletions
119
apps/self-hosted/hosting/api/src/routes/tenant-create-refresh.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| const state = vi.hoisted(() => ({ | ||
| existing: null as any, | ||
| created: [] as any[], | ||
| })); | ||
|
|
||
| vi.mock('../db/client', () => ({ | ||
| db: { | ||
| // The audit logger chains .catch on these, so they must return promises. | ||
| query: vi.fn(async () => ({ rows: [] })), | ||
| queryOne: vi.fn(async () => null), | ||
| }, | ||
| })); | ||
| vi.mock('../middleware/auth', () => ({ | ||
| authMiddleware: async (_c: unknown, next: () => Promise<void>) => next(), | ||
| adminMiddleware: async (_c: unknown, next: () => Promise<void>) => next(), | ||
| })); | ||
| vi.mock('../middleware/payment-target-lock', () => ({ | ||
| withPaymentTargetLock: async ( | ||
| _c: unknown, | ||
| next: () => Promise<void>, | ||
| ) => next(), | ||
| })); | ||
| vi.mock('../services/tenant-service', async (importOriginal) => { | ||
| const actual = await importOriginal<any>(); | ||
| return { | ||
| ...actual, | ||
| isReregisterableAbandoned: () => false, | ||
| TenantService: { | ||
| ...actual.TenantService, | ||
| getByUsername: async () => state.existing, | ||
| isListenerCaughtUp: async () => true, | ||
| verifyHiveAccount: async () => true, | ||
| verifyCommunityControlledBy: async () => true, | ||
| create: async (username: string, owner: string, config: any) => { | ||
| state.created.push({ username, owner, config }); | ||
| return { | ||
| username, | ||
| owner, | ||
| subscriptionStatus: 'inactive', | ||
| subscriptionPlan: 'standard', | ||
| }; | ||
| }, | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| const { tenantRoutes } = await import('./tenants'); | ||
|
|
||
| function post(body: unknown) { | ||
| return tenantRoutes.request('http://localhost/', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: JSON.stringify(body), | ||
| }); | ||
| } | ||
|
|
||
| describe('POST /v1/tenants appearance validation', () => { | ||
| beforeEach(() => { | ||
| state.existing = null; | ||
| state.created = []; | ||
| }); | ||
|
|
||
| it('rejects an accent that is not a hex color', async () => { | ||
| const res = await post({ username: 'alice', config: { accent: 'red' } }); | ||
| expect(res.status).toBe(400); | ||
| expect(state.created).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('rejects an unknown font preset', async () => { | ||
| const res = await post({ username: 'alice', config: { fontPreset: 'comic-sans' } }); | ||
| expect(res.status).toBe(400); | ||
| expect(state.created).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('accepts valid appearance values', async () => { | ||
| const res = await post({ | ||
| username: 'alice', | ||
| config: { styleTemplate: 'magazine', accent: '#ff6600', fontPreset: 'classic' }, | ||
| }); | ||
| expect(res.status).toBe(201); | ||
| expect(state.created[0].config.accent).toBe('#ff6600'); | ||
| }); | ||
| }); | ||
|
|
||
| /** | ||
| * The customize step promises that the look on screen is the look that | ||
| * activates: a same-owner unpaid reservation is refreshed by re-creation | ||
| * (the latest submission wins), while anyone else's reservation and any | ||
| * live tenant stay 409. | ||
| */ | ||
| describe('POST /v1/tenants refreshes a same-owner unpaid reservation', () => { | ||
| beforeEach(() => { | ||
| state.existing = null; | ||
| state.created = []; | ||
| }); | ||
|
|
||
| it('lets the owner re-submit an inactive reservation with a new look', async () => { | ||
| state.existing = { username: 'alice', owner: 'alice', subscriptionStatus: 'inactive' }; | ||
| const res = await post({ username: 'alice', config: { styleTemplate: 'developer' } }); | ||
| expect(res.status).toBe(201); | ||
| expect(state.created[0].config.styleTemplate).toBe('developer'); | ||
| }); | ||
|
|
||
| it("still refuses someone else's inactive reservation", async () => { | ||
| state.existing = { username: 'alice', owner: 'mallory', subscriptionStatus: 'inactive' }; | ||
| const res = await post({ username: 'alice', config: { styleTemplate: 'developer' } }); | ||
| expect(res.status).toBe(409); | ||
| expect(state.created).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('still refuses a live tenant', async () => { | ||
| state.existing = { username: 'alice', owner: 'alice', subscriptionStatus: 'active' }; | ||
| const res = await post({ username: 'alice', config: {} }); | ||
| expect(res.status).toBe(409); | ||
| expect(state.created).toHaveLength(0); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
apps/self-hosted/hosting/api/src/services/flat-overrides.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { TenantService } from './tenant-service'; | ||
|
|
||
| // Pure mapping: no DB, no RPC. | ||
|
|
||
| describe('normalizeFlatOverrides appearance keys', () => { | ||
| it('maps accent and fontPreset under general.styles, the paths the editor writes', () => { | ||
| const normalized = TenantService.normalizeFlatOverrides({ | ||
| styleTemplate: 'magazine', | ||
| accent: '#ff6600', | ||
| fontPreset: 'classic', | ||
| }); | ||
|
|
||
| expect(normalized.configuration.general.styleTemplate).toBe('magazine'); | ||
| expect(normalized.configuration.general.styles).toEqual({ | ||
| accent: '#ff6600', | ||
| fontPreset: 'classic', | ||
| }); | ||
| }); | ||
|
|
||
| it('writes no styles object at all when neither knob was sent', () => { | ||
| const normalized = TenantService.normalizeFlatOverrides({ | ||
| title: 'A blog', | ||
| }); | ||
| // An empty object would still merge and could shadow a stored section. | ||
| expect(normalized.configuration.general.styles).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('carries a single knob without inventing the other', () => { | ||
| const normalized = TenantService.normalizeFlatOverrides({ | ||
| accent: '#0af', | ||
| }); | ||
| expect(normalized.configuration.general.styles).toEqual({ | ||
| accent: '#0af', | ||
| }); | ||
| }); | ||
|
|
||
| it('seeded config carries the signup appearance choices end to end', async () => { | ||
| const config = await TenantService.buildConfig( | ||
| 'alice', | ||
| { styleTemplate: 'developer', accent: '#89b4fa', fontPreset: 'technical' }, | ||
| 'alice', | ||
| ); | ||
| expect(config.configuration.general.styleTemplate).toBe('developer'); | ||
| expect(config.configuration.general.styles.accent).toBe('#89b4fa'); | ||
| expect(config.configuration.general.styles.fontPreset).toBe('technical'); | ||
| // The seed's own defaults survive alongside. | ||
| expect(config.configuration.general.theme).toBe('system'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.