@stacksjs/sites 0.72.6 → 0.72.7

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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export type { SiteProvisionInput, SiteProvisionPage, SiteProvisionResult } from './provision';
1
2
  export type { SiteSnapshotShape } from './snapshot';
2
3
  export type { HostKind, ResolvedSitesOptions, SiteContext, SiteStore } from './types';
3
4
  export {
@@ -19,5 +20,6 @@ export {
19
20
  resolveSiteByHost,
20
21
  sitesOptions,
21
22
  } from './resolver';
23
+ export { provisionSite } from './provision';
22
24
  export { forSite, siteOwnership } from './scoping';
23
25
  export { toSiteSnapshot } from './snapshot';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{currentSite,currentSiteId,requireSite,runWithSite,setCurrentSite,SiteNotResolvedError}from"./context";export{default as siteResolver}from"./middleware";export{classifyHost,clearSiteCache,databaseSiteStore,isPlatformHost,normalizeHost,requestHost,resolveSiteByHost,sitesOptions}from"./resolver";export{forSite,siteOwnership}from"./scoping";export{toSiteSnapshot}from"./snapshot";
1
+ export{currentSite,currentSiteId,requireSite,runWithSite,setCurrentSite,SiteNotResolvedError}from"./context";export{default as siteResolver}from"./middleware";export{classifyHost,clearSiteCache,databaseSiteStore,isPlatformHost,normalizeHost,requestHost,resolveSiteByHost,sitesOptions}from"./resolver";export{provisionSite}from"./provision";export{forSite,siteOwnership}from"./scoping";export{toSiteSnapshot}from"./snapshot";
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Create or refresh a site, then seed any missing pages.
3
+ *
4
+ * Page seeding needs `@stacksjs/cms`, which is imported lazily so an app using
5
+ * sites WITHOUT the CMS feature does not pull it in - and a caller passing no
6
+ * pages never touches it at all.
7
+ */
8
+ export declare function provisionSite(input: SiteProvisionInput): Promise<SiteProvisionResult>;
9
+ /**
10
+ * Creating a site and giving it something to serve.
11
+ *
12
+ * Every multi-tenant app built on `@stacksjs/sites` ends up writing the same
13
+ * function: take a tenant, make sure it has a Site row, carry the tenant's
14
+ * branding onto it, and seed the pages a new site starts with. CampusHQ wrote
15
+ * it for schools; a storefront builder would write it for merchants.
16
+ *
17
+ * The parts that are the same every time live here. What a tenant IS, and
18
+ * which pages it starts with, stay with the app - this takes them as
19
+ * arguments rather than guessing.
20
+ *
21
+ * Idempotency is the whole point. Provisioning is a button people press twice,
22
+ * a seeder that re-runs, a retried request: a second pass re-themes the site,
23
+ * adds only the pages that are missing, and never touches one somebody has
24
+ * since edited.
25
+ */
26
+ export declare interface SiteProvisionPage {
27
+ title: string
28
+ slug: string
29
+ status?: 'draft' | 'published' | 'scheduled'
30
+ blocks?: Array<{ type: string, props?: Record<string, unknown> }>
31
+ parentId?: number
32
+ }
33
+ export declare interface SiteProvisionInput {
34
+ name: string
35
+ subdomain: string
36
+ timezone?: string
37
+ settings?: Record<string, unknown>
38
+ pages?: SiteProvisionPage[]
39
+ siteId?: number | null
40
+ }
41
+ export declare interface SiteProvisionResult {
42
+ siteId: number
43
+ subdomain: string
44
+ created: boolean
45
+ pagesCreated: string[]
46
+ pagesKept: string[]
47
+ }
@@ -0,0 +1 @@
1
+ import{db}from"@stacksjs/database";export async function provisionSite(input){const existing=input.siteId?await db.selectFrom("sites").selectAll().where("id","=",input.siteId).executeTakeFirst():await db.selectFrom("sites").selectAll().where("subdomain","=",input.subdomain).executeTakeFirst(),settings=JSON.stringify(input.settings??{});let siteId,created=!1;if(existing){siteId=Number(existing.id);await db.updateTable("sites").set({settings,...input.timezone?{timezone:input.timezone}:{}}).where("id","=",siteId).execute()}else{const inserted=await db.insertInto("sites").values({name:input.name,subdomain:input.subdomain,status:"active",settings,...input.timezone?{timezone:input.timezone}:{}}).returning("id").executeTakeFirst();siteId=Number(inserted?.id);created=!0}const pagesCreated=[],pagesKept=[];if(input.pages?.length){const{createPageDocument,registerDefaultBlocks}=await import("@stacksjs/cms");registerDefaultBlocks();for(const page of input.pages){const path=page.slug==="/"?"/":`/${page.slug}`;if(await db.selectFrom("pages").select("id").where("site_id","=",siteId).where("path","=",path).executeTakeFirst()){pagesKept.push(path);continue}await createPageDocument(siteId,{title:page.title,slug:page.slug,status:page.status??"published",blocks:page.blocks??[],parentId:page.parentId});pagesCreated.push(path)}}return{siteId,subdomain:input.subdomain,created,pagesCreated,pagesKept}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/sites",
3
3
  "type": "module",
4
- "version": "0.72.6",
4
+ "version": "0.72.7",
5
5
  "description": "The Stacks multi-site (request-level tenancy) functionality.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": [
@@ -56,11 +56,11 @@
56
56
  "prepublishOnly": "bun run build"
57
57
  },
58
58
  "devDependencies": {
59
- "@stacksjs/auth": "0.72.6",
60
- "@stacksjs/config": "0.72.6",
61
- "@stacksjs/database": "0.72.6",
62
- "@stacksjs/error-handling": "0.72.6",
63
- "@stacksjs/router": "0.72.6",
59
+ "@stacksjs/auth": "0.72.7",
60
+ "@stacksjs/config": "0.72.7",
61
+ "@stacksjs/database": "0.72.7",
62
+ "@stacksjs/error-handling": "0.72.7",
63
+ "@stacksjs/router": "0.72.7",
64
64
  "better-dx": "^0.2.23"
65
65
  },
66
66
  "sideEffects": false