Skip to content

k.site ​

Versioned resource access, site context, and site-level management for the current site

Execution ContextPrerequisitesTypical Use
KScript API / KView / Server scriptsCurrent site context (list, isNameExists, get, 2-arg createSite, and xCopy enforce user/org checks; 3-arg createSite and exportSite require explicit script auth)Read and write pages, layouts, views, scripts, styles, files, images, and site context

Quick Start ​

Read the current site's name, default home URL, disk space usage, and page count:

js
k.api.get("siteOverview", () => {
    return {
        name: k.site.webSite.name,
        homeUrl: k.site.getHomeUrl(),
        diskSpace: k.site.diskSpace.getSiteSize(),
        pageCount: k.site.pages.all().length
    }
})

Difference from k.file

  • k.site: Versioned, routable site resources stored in the site database (pages, layouts, views, scripts, styles, code items, and the CMS file library k.site.files).
  • k.file: Direct file operations on the site's disk directory (no dedicated CMS file-library UI); see k.file.

Quick Reference ​

Method / PropertyDescriptionReturns
k.site.pages / layouts / viewsPage, layout skeleton, and view fragment repositories (see page.md, layout.md, view.md)PageRepository / LayoutRepository / ViewRepository
k.site.scripts / styles / codesStandalone JS, CSS, and Code repositories (see js.md, css.md, code.md)ScriptRepository / StyleRepository / CodeRepository
k.site.files / imagesCMS file library and site image media repository (see file.md, image.md)FileRepository / ImageRepository
k.site.menus / htmlBlocks / formValues / routesNavigation menus, HTML blocks, form records, and routes (see menu.md, html-block.md, form-value.md, route.md)Repository objects
k.site.job / runJob(name) / getJob(name)Scheduled job management, manual trigger, and status queries (see job.md)JobRepository / void / SiteJobStatus
k.site.info / webSite / settings / multilingual / search / version / diskSpace / helperSite metadata, settings, multilingual URLs, and full-text search (see context.md)Context helper objects
k.site.labels / k.site.editLogMultilingual label repository (k.label) and edit history (k.history)LabelRepository / KEditLog
list()Lists accessible sites for the current logged-in user (returns null anonymously)SiteSummaryViewModel[] | null
getHomeUrl()Gets the full base URL of the current site's default start pagestring | null
isDomainExists(name)Checks whether a shared or bound domain is already in useboolean
isNameExists(siteName)Checks whether a site name exists in the current organization (auth required)boolean

Core Submodules ​

MemberDocDescription
k.site.pagespage.mdSite pages, routes, and version logs
k.site.layoutslayout.mdLayout skeletons and placeholder containers
k.site.viewsview.mdReusable view fragments
k.site.scriptsjs.mdStandalone JavaScript resources
k.site.stylescss.mdStandalone CSS stylesheet resources
k.site.codescode.mdAPI scripts, CodeBlocks, and other code items
k.site.menusmenu.mdNavigation menus and submenu trees
k.site.job / runJob / getJobjob.mdScheduled job CRUD, manual trigger, and status queries
k.site.filesfile.mdCMS file library resources (versioned routable files)
k.site.imagesimage.mdSite image library and media storage upload
k.site.htmlBlockshtml-block.mdMultilingual reusable HTML blocks
k.site.formValuesform-value.mdSubmitted form value records and version logs
k.site.routesroute.mdRoute lookup, remapping, and aliases
k.site.labelsk.labelMultilingual labels (same store as k.label / k.t, with repository CRUD)
k.site.editLogk.historySite edit history, diff, and rollback (equivalent to k.history)
k.site.info / webSite / settings / multilingual / search / version / diskSpace / helpercontext.mdSite metadata, settings, multilingual URLs, full-text search, asset versioning, and disk usage

Common Root Methods ​

list() ​

Lists site summaries accessible to the current logged-in user. This method requires an authenticated user and organization context; in an anonymous HTTP API request it returns null.

None

Returns: SiteSummaryViewModel[] | null

js
k.api.get("sites", () => {
    const sites = k.site.list()
    if (!sites) {
        return { isNull: true, sites: [] }
    }
    return {
        count: sites.length,
        sites: sites.map((s) => ({
            siteId: s.siteId,
            siteName: s.siteName,
            siteDisplayName: s.siteDisplayName,
            online: s.online
        }))
    }
})

getHomeUrl() ​

Returns the base URL of the current site's default start page, or null when no default start route is configured.

None

Returns: string | null

js
k.api.get("homeUrl", () => {
    return { homeUrl: k.site.getHomeUrl() }
})

isDomainExists() / isNameExists() ​

Checks whether a domain binding or a site name in the current organization is already taken.

MethodParameterReturnsDescription
isDomainExists(name)name: stringbooleanChecks whether a domain (shared staging domain or bound host) is already in use
isNameExists(siteName)siteName: stringbooleanChecks whether a site name exists in the current organization; requires an authenticated user and organization context (throws a null-reference error when called anonymously)

Returns: boolean

js
k.api.get("domainCheck", () => {
    return {
        exists: k.site.isDomainExists("example.localkooboo.com")
    }
})

Admin & Specialized Capabilities ​

Beyond day-to-day site development repositories and context helpers, k.site exposes privileged cross-site provisioning, export, and publish-sync root methods. Not all of them perform built-in user authentication checks—restrict them to controlled administrative endpoints and enforce authorization explicitly:

CategoryMembersNotes
Built-in user checkget(siteName), createSite(siteName, fullDomain)Enforces context.User; calling anonymously throws "user or website not valid"
Cross-site fast clonexCopy(sourceSiteNameOrId, siteName, fullDomain, published)Enforces context.User and organization access; when anonymous, redirects to the login page and returns null
No built-in user check (privileged)createSite(siteName, fullDomain, binary), exportSite(nameOrId, copyMode, path)Uses only the current site's OrganizationId and does not check context.User, so they can execute in anonymous requests; scripts must enforce user authentication and authorization explicitly before calling them
Collaboration & sync helperscreatePublishUser(siteUrl, role, expire), importPublishUser(siteUrl, bearer), enableCodeVideoLog(siteUrl)Forwards the current request's Cookie/Authorization headers to generate/import remote publish user tokens and enable code video logging

Quick Context Example ​

Read basic site metadata and disk usage (see context.md for full context properties):

js
k.api.get("siteSize", () => {
    return {
        name: k.site.webSite.name,
        diskSpace: k.site.diskSpace.getSiteSize()
    }
})

TypeScript Definitions ​

Show full TypeScript definitions
ts
type CopyMode = 'Normal' | 'Fast';

interface kSiteDb {
  version: FileVersion;
  info: InfoModel;
  webSite: WebSiteInspection;
  pages: PageRepository;
  helper: SiteHelper;
  editLog: KEditLog;
  diskSpace: DiskSpace;
  views: ViewRepository;
  layouts: LayoutRepository;
  htmlBlocks: HtmlBlockRepository;
  labels: LabelRepository;
  scripts: ScriptRepository;
  codes: CodeRepository;
  styles: StyleRepository;
  images: ImageRepository;
  files: FileRepository;
  routes: RouteObjectRepository;
  formValues: FormValuesRepository;
  settings: kCoreSettings;
  search: Search;
  menus: KMenus;
  multilingual: Multilingual;
  job: JobRepository;
  list(): SiteSummaryViewModel[];
  isDomainExists(name: string): boolean;
  isNameExists(SiteName: string): boolean;
  get(SiteName: string): kSiteDb;
  createSite(siteName: string, fullDomain: string): kSiteDb;
  createSite(siteName: string, fullDomain: string, Binary: number[]): kSiteDb;
  exportSite(nameOrId: string, copyMode: CopyMode, path: string): void;
  xCopy(sourceSiteNameOrId: string, siteName: string, fullDomain: string, published: boolean): SitePackageResult;
  createPublishUser(siteUrl: string, role: string, expire: number): string;
  enableCodeVideoLog(siteUrl: string): string;
  importPublishUser(siteUrl: string, bearer: string): void;
  getHomeUrl(): string;
  runJob(name: string): void;
  getJob(name: string): SiteJobStatus;
}