### Initial Project Setup and Development Start Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/local-development.mdx Commands for setting up a new project, installing dependencies, deploying core infrastructure, and starting the development watch commands for Admin or API. ```bash # Clone repository git clone cd # Install dependencies yarn # Deploy core infrastructure yarn webiny deploy core api # Start developing! yarn webiny watch admin # or yarn webiny watch api ``` -------------------------------- ### Install Dependencies and Start Development Server Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/user-guides/6.x/website-builder/essentials/nextjs-starter-kit.mdx Run these commands in your Next.js project root to install all necessary dependencies and start the development server. This step also establishes the connection to your Webiny project using the configured environment variables and enables hot reloading. ```bash yarn && yarn dev ``` -------------------------------- ### Create and Install Tenant Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/tenant-manager/manage-tenants.mdx Use this workflow to create a new tenant and then install it. Ensure you have admin privileges for the installation step. This example uses the graphqlClient to interact with the Webiny API. ```javascript const createResult = await graphqlClient.mutate({ mutation: gql` mutation CreateTenant($input: CreateTenantInput!) { tenantManager { createTenant(input: $input) { data error { message code } } } } `, variables: { input: { id: "acme-corp", name: "Acme Corporation", description: "Production tenant for Acme Corp" } } }); if (createResult.data.tenantManager.createTenant.error) { console.error("Failed to create tenant:", createResult.data.tenantManager.createTenant.error); return; } // 2. Install the tenant (requires admin privileges) const installResult = await graphqlClient.mutate({ mutation: gql` mutation InstallTenant($tenantId: ID!) { tenantManager { installTenant(tenantId: $tenantId) { data error { message code } } } } `, variables: { tenantId: "acme-corp" } }); if (installResult.data.tenantManager.installTenant.error) { console.error("Failed to install tenant:", installResult.data.tenantManager.installTenant.error); return; } console.log("Tenant created and installed successfully"); ``` -------------------------------- ### Print Manual Setup Instructions for Webiny MCP Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/get-started/connect-ai-environment.mdx Use this command to print a comprehensive, copy-paste-ready setup guide for your agent, especially if it's not covered by the built-in adapters. ```bash npx webiny-mcp configure --instructions ``` -------------------------------- ### Create a New Webiny Project Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/get-started/quickstart.mdx Run this command to start a new Webiny project. Follow the on-screen prompts for configuration, including AWS region and database setup. ```bash npx create-webiny-project my-webiny-project ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/get-started/local-development.mdx Standard command to install all necessary dependencies when joining an existing Webiny project. ```bash git clone cd yarn ``` -------------------------------- ### Install Tenant with Tenant Manager SDK Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/reference/sdk/tenant-manager.mdx Installs and provisions a tenant with default settings. Specify the tenant ID to install. ```typescript sdk.tenantManager.installTenant(params: InstallTenantParams): Promise> ``` -------------------------------- ### Quick Setup with Webiny CLI Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/get-started/configure-mcp-server.ai.txt Use this command for a fast, automated setup of the MCP server for supported AI agents. It creates necessary configuration and instruction files. ```bash npx webiny configure-mcp ``` -------------------------------- ### Clone and Install Next.js Starter Kit Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/website-builder/setup-nextjs.mdx Clone the official Next.js starter kit repository and install its dependencies. This sets up the basic project structure and required packages. ```bash git clone https://github.com/webiny/website-builder-nextjs.git my-website cd my-website npm install ``` -------------------------------- ### Start Development Server Source: https://github.com/webiny/docs.webiny.com/blob/master/README.md Starts the local development server for the Webiny documentation project using Yarn. ```sh yarn dev ``` -------------------------------- ### Install Webiny SDK Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/reference/sdk/overview.mdx Install the Webiny SDK using yarn. ```bash yarn add @webiny/sdk ``` -------------------------------- ### Start Development Server Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/website-builder/setup-nextjs.mdx Run the development server for your Next.js project. This command starts the local development environment, allowing you to see your changes in real-time. ```bash npm run dev ``` -------------------------------- ### Install Tenant Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/tenant-manager/manage-tenants.mdx Installs and provisions a tenant with default settings and configurations. Requires the tenant ID of the tenant to be installed. ```APIDOC ## Install Tenant Installs and provisions a tenant with default settings and configurations. ### Input - `tenantId` (required) - ID of the tenant to install ### Request ```graphql mutation InstallTenant($tenantId: ID!) { tenantManager { installTenant(tenantId: $tenantId) { data error { message code } } } } ``` ### Variables ```json { "tenantId": "root" } ``` ### Response ```json { "data": { "tenantManager": { "installTenant": { "data": true, "error": null } } } } ``` ``` -------------------------------- ### Configure Auto Install Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/reference/extensions/project.mdx Automatically installs Webiny on first deploy, creating the initial admin user without a manual browser-based setup step. Do not hardcode credentials; reference them via environment variables using Infra.EnvVar. ```typescript new Project.AutoInstall({ adminUser: { firstName: "John", lastName: "Doe", email: "admin@example.com", password: "12345678", }, }) ``` -------------------------------- ### Install Next.js Globally Source: https://github.com/webiny/docs.webiny.com/blob/master/README.md Installs the Next.js framework globally using npm. This is a prerequisite for running the project locally. ```sh npm install next --global ``` -------------------------------- ### Install Webiny SDK Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/webiny-sdk.ai.txt Install the Webiny SDK package using npm. This is the first step to integrating Webiny into your external applications. ```bash npm install @webiny/sdk ``` -------------------------------- ### installTenant Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/reference/sdk/tenant-manager.mdx Installs and provisions a tenant with default settings and configurations. ```APIDOC ## installTenant ### Description Installs and provisions a tenant with default settings and configurations. ### Signature ```typescript sdk.tenantManager.installTenant(params: InstallTenantParams): Promise> ``` ### Parameters #### Path Parameters _This method does not accept path parameters._ #### Query Parameters _This method does not accept query parameters._ #### Request Body _This method does not accept a request body. Parameters are passed as an object to the method._ ### Parameters Object - **tenantId** (string) - Required - ID of the tenant to install ### Request Example ```typescript // Example usage: const result = await sdk.tenantManager.installTenant({ tenantId: "your-tenant-id" }); ``` ### Response #### Success Response (200) - **data** (boolean) - Indicates if the tenant was installed successfully. #### Response Example ```json { "data": true } ``` ``` -------------------------------- ### Application Configuration Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/applications.ai.txt Illustrates how to configure an application within the Webiny framework. This is typically done in a configuration file. ```javascript import { WebinyConfig } from '@webiny/config'; export default new WebinyConfig(() => { return { // Application specific configuration myApp: { someSetting: 'someValue' } }; }); ``` -------------------------------- ### Install Pre-Built Webiny Extension Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/extensions.mdx Use the Webiny CLI to install pre-built extensions from GitHub. This command downloads the extension, adds it to your project, and updates `webiny.config.tsx`. ```bash yarn webiny extension ``` -------------------------------- ### Install Tenant GraphQL Mutation Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/tenant-manager/manage-tenants.mdx This mutation installs and provisions a tenant with default settings. It requires the tenant's ID. ```graphql mutation InstallTenant($tenantId: ID!) { tenantManager { installTenant(tenantId: $tenantId) { data error { message code } } } } ``` ```json { "tenantId": "root" } ``` ```json { "data": { "tenantManager": { "installTenant": { "data": true, "error": null } } } } ``` -------------------------------- ### Install JavaScript Dependencies Source: https://github.com/webiny/docs.webiny.com/blob/master/README.md Installs all necessary JavaScript dependencies for the Webiny documentation project using Yarn. ```sh yarn ``` -------------------------------- ### Webiny Upgrade History Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/release-notes/upgrade-webiny.mdx This JSON structure shows an example of the upgrade history recorded in the `webiny.history` field of your project's root `package.json`. This history helps skip already-applied upgrades and allows re-running upgrades with the `--force` flag. ```json { "webiny": { "history": [{ "version": "6.1.0", "timestamp": "2026-03-15T10:30:00.000Z" }] } } ``` -------------------------------- ### Create a Route Handler Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/webiny-api/api-routes.mdx Example of creating a custom HTTP route handler with dependency injection using Route.Interface. ```APIDOC ## Create a Route Handler Create a TypeScript file in your `extensions/` directory and implement `Route.Interface`: ```typescript extensions/MyApiRoute.ts import { Logger, Route } from "webiny/api"; class MyApiRouteImpl implements Route.Interface { public constructor(private logger: Logger.Interface) {} public async execute(request: Route.Request, reply: Route.Reply): Promise { this.logger.info("Handling request", { url: request.url }); return reply.send({ message: "Hello from my custom route!" }); } } export default Route.createImplementation({ implementation: MyApiRouteImpl, dependencies: [Logger] }); ``` ``` -------------------------------- ### Example .env.example for Documentation Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/environment-variables.mdx Create a .env.example file in your project root to serve as a reference for your team, outlining required and optional environment variables without committing sensitive data. ```bash # Analytics Configuration (required) WEBINY_ADMIN_ANALYTICS_ID= # Email Service (optional) WEBINY_API_SMTP_HOST= WEBINY_API_SMTP_USER= WEBINY_API_SMTP_PASS= # External API (required for payments) WEBINY_API_EXTERNAL_SERVICE_KEY= ``` -------------------------------- ### Core BeforeWatch Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom BeforeWatch hook for the Core stack. This example logs a message before the `yarn webiny watch` command starts. This hook is registered via `Infra.Core.BeforeWatch`. ```typescript import { CoreBeforeWatchHook } from "webiny/infra/core"; import { Ui } from "webiny/infra"; export default CoreBeforeWatchHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Core BeforeWatch hook..."); }, }); ``` -------------------------------- ### Admin BeforeWatch Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom BeforeWatch hook for the Admin stack. This example logs a message before the watch process for the Admin stack starts. Ensure the correct import path for `AdminBeforeWatchHook` is used. ```typescript import { AdminBeforeWatchHook } from "webiny/infra/admin"; import { Ui } from "webiny/infra"; export default AdminBeforeWatchHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Admin BeforeWatch hook..."); }, }); ``` -------------------------------- ### Core BeforeBuild Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom BeforeBuild hook for the Core stack. This example logs a message before the build process starts. Ensure the file is named using PascalCase and exports a default implementation. ```typescript import { CoreBeforeBuildHook } from "webiny/infra/core"; import { Ui } from "webiny/infra"; export default CoreBeforeBuildHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Core BeforeBuild hook..."); }, }); ``` -------------------------------- ### Tenant Provisioning Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/multi-tenancy.mdx Automate tenant creation, for example, by hooking into user signup events. This includes creating a tenant, setting up default content models, and assigning users. ```APIDOC ## Tenant Provisioning Automate tenant creation: ```typescript // Hook into user registration export const OnUserSignup = createEventHandler({ event: "user.signup", async handler({ user }) { // Automatically create tenant for new user const tenant = await tenantManager.create({ name: user.organization, owner: user.id }); // Set up default content models await setupDefaultModels(tenant); // Configure permissions await assignUserToTenant(user, tenant); } }); ``` ``` -------------------------------- ### Simple Text Field Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/headless-cms/builder/field.ai.txt A straightforward example of defining a required text field. ```typescript .field().id("name").label("Name").type("text").required(true) ``` -------------------------------- ### Create Project with Beta Release Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/release-notes/upgrade-webiny.mdx Use `npx create-webiny-project` with the `@beta` tag to set up a new project using a beta release. You can also set the `WEBINY_VERSION` environment variable. ```bash npx create-webiny-project@beta my-project ``` -------------------------------- ### Deploy Your Webiny Project Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/get-started/quickstart.mdx Navigate to your project directory and run this command to deploy your Webiny applications (Core, API, Admin) to your AWS account. The first deployment may take 5-15 minutes. ```bash cd my-webiny-project yarn webiny deploy ``` -------------------------------- ### Automated Tenant Provisioning on User Signup Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/multi-tenancy.mdx Automate tenant creation and setup when a new user signs up. This event handler creates a tenant based on user organization, sets up default models, and assigns the user to the new tenant. ```typescript // Hook into user registration export const OnUserSignup = createEventHandler({ event: "user.signup", async handler({ user }) { // Automatically create tenant for new user const tenant = await tenantManager.create({ name: user.organization, owner: user.id }); // Set up default content models await setupDefaultModels(tenant); // Configure permissions await assignUserToTenant(user, tenant); } }); ``` -------------------------------- ### Configure Webiny MCP Server for an Agent Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/get-started/connect-ai-environment.mdx Run this command from your Webiny project root to set up the MCP server and instruction files for your AI agent. This is the quickest way to connect. ```bash npx webiny-mcp configure {agent-name} ``` -------------------------------- ### Initialize SDK with Theme Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/website-builder/theme.ai.txt Initialize the Website Builder SDK in `layout.tsx` by importing and passing the registered theme object to `contentSdk.init()`. ```typescript // src/app/layout.tsx (or similar entry point) import { WebsiteBuilderProvider } from "@webiny/website-builder-nextjs/react"; import { theme } from "../theme/theme"; // Import the registered theme export default function RootLayout({ children }) { return ( { contentSdk.init({ theme: theme, }); }, }} > {children} ); } ``` -------------------------------- ### Create and Configure a Blog Post Model Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/headless-cms/builder/model.ai.txt Demonstrates creating a regular model for blog posts using the ModelBuilder and FieldBuilder. Includes basic configuration like ID, name, API names, description, group, and a required text field. ```typescript import { ModelBuilder, FieldBuilder } from "@webiny/api-headless-cms"; const model = new ModelBuilder() .id("blogPost") .name("Blog Post") .singularApiName("BlogPost") .pluralApiName("BlogPosts") .description("Blog articles") .group("blog") .field( new FieldBuilder() .id("title") .label("Title") .type("text") .required(true) ) .build(); ``` -------------------------------- ### Define Get Page By ID Abstraction Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/website-builder/use-case/pages.mdx Defines the interface and types for the Get Page By ID abstraction. This is used to establish the contract for retrieving a page using its unique identifier. ```typescript import { createAbstraction } from "webiny/api"; import type { GetPageByIdUseCase } from "webiny/api/website-builder/page"; export interface IGetPageByIdParams { id: string; } export type IGetPageByIdReturn = Promise; export interface IGetPageById { execute(params: IGetPageByIdParams): IGetPageByIdReturn; } export const GetPageById = createAbstraction("GetPageById"); export namespace GetPageById { export type Interface = IGetPageById; export type Params = IGetPageByIdParams; export type Return = IGetPageByIdReturn; } ``` -------------------------------- ### Admin AfterDeploy Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom AfterDeploy hook for the Admin stack. This example logs a message after the Admin stack deployment. The hook is registered using `Infra.Admin.AfterDeploy` in `webiny.config.tsx`. ```typescript import { AdminAfterDeployHook } from "webiny/infra/admin"; import { Ui } from "webiny/infra"; export default AdminAfterDeployHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Admin AfterDeploy hook..."); }, }); ``` -------------------------------- ### Core AfterDeploy Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom AfterDeploy hook for the Core stack. This example logs a message after the Core stack deployment. The `execute` method should return a `Promise`. ```typescript import { CoreAfterDeployHook } from "webiny/infra/core"; import { Ui } from "webiny/infra"; export default CoreAfterDeployHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Core AfterDeploy hook..."); }, }); ``` -------------------------------- ### Admin BeforeDeploy Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom BeforeDeploy hook for the Admin stack. This example logs a message before the Admin stack deployment. The hook is registered via `Infra.Admin.BeforeDeploy` in `webiny.config.tsx`. ```typescript import { AdminBeforeDeployHook } from "webiny/infra/admin"; import { Ui } from "webiny/infra"; export default AdminBeforeDeployHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Admin BeforeDeploy hook..."); }, }); ``` -------------------------------- ### Deploy Core and API Applications Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/local-development.mdx Deploy the core and API applications before starting local development. This command ensures the necessary backend services are running. ```bash yarn webiny deploy core api ``` -------------------------------- ### Api BeforeDeploy Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom BeforeDeploy hook for the API stack. This example logs a message before the API stack deployment. The hook implementation must be exported as a default. ```typescript import { ApiBeforeDeployHook } from "webiny/infra/api"; import { Ui } from "webiny/infra"; export default ApiBeforeDeployHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Api BeforeDeploy hook..."); }, }); ``` -------------------------------- ### createTenant Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/reference/sdk/tenant-manager.mdx Creates a new tenant in the system. ```APIDOC ## createTenant ### Description Creates a new tenant in the system. ### Signature ```typescript sdk.tenantManager.createTenant(params: CreateTenantParams): Promise> ``` ### Parameters #### Path Parameters _This method does not accept path parameters._ #### Query Parameters _This method does not accept query parameters._ #### Request Body _This method does not accept a request body. Parameters are passed as an object to the method._ ### Parameters Object - **data** (CreateTenantInput) - Required - The tenant data to create ### Request Example ```typescript // Example usage: const result = await sdk.tenantManager.createTenant({ data: { slug: "my-new-tenant", name: "My New Tenant" } }); ``` ### Response #### Success Response (200) - **data** (boolean) - Indicates if the tenant was created successfully. #### Response Example ```json { "data": true } ``` ``` -------------------------------- ### Configure Next.js Environment Variables Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/website-builder/setup-nextjs.mdx Set up the necessary environment variables in your `.env` file to connect the Next.js starter kit to your Webiny project. These include API key, API host, and tenant ID. ```dotenv NEXT_PUBLIC_WEBSITE_BUILDER_API_KEY=your_api_key_here NEXT_PUBLIC_WEBSITE_BUILDER_API_HOST=https://your-cloudfront-url.cloudfront.net NEXT_PUBLIC_WEBSITE_BUILDER_API_TENANT=root ``` -------------------------------- ### Core BeforeDeploy Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom BeforeDeploy hook for the Core stack. This example logs a message before the Core stack deployment. The hook is defined using `Infra.Core.BeforeDeploy` in `webiny.config.tsx`. ```typescript import { CoreBeforeDeployHook } from "webiny/infra/core"; import { Ui } from "webiny/infra"; export default CoreBeforeDeployHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Core BeforeDeploy hook..."); }, }); ``` -------------------------------- ### Admin AfterBuild Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom AfterBuild hook for the Admin stack. This example logs a message after the Admin build process. The hook class must implement the `AdminAfterBuildHook.Interface`. ```typescript import { AdminAfterBuildHook } from "webiny/infra/admin"; import { Ui } from "webiny/infra"; export default AdminAfterBuildHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Admin AfterBuild hook..."); }, }); ``` -------------------------------- ### Initialize Webiny SDK Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/webiny-sdk.mdx Initialize the SDK with your API token, endpoint, and tenant. Store credentials in environment variables. ```typescript import { Webiny } from "@webiny/sdk"; export const sdk = new Webiny({ token: process.env.WEBINY_API_TOKEN!, endpoint: process.env.WEBINY_API_ENDPOINT!, tenant: process.env.WEBINY_API_TENANT || "root" }); ``` -------------------------------- ### Api AfterDeploy Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom AfterDeploy hook for the API stack. This example logs a message after the API stack deployment. Ensure the correct import path for `ApiAfterDeployHook` is used. ```typescript import { ApiAfterDeployHook } from "webiny/infra/api"; import { Ui } from "webiny/infra"; export default ApiAfterDeployHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Api AfterDeploy hook..."); }, }); ``` -------------------------------- ### Page Component with SDK Initialization (Next.js) Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/website-builder/multi-tenant-nextjs.ai.txt This example shows how to initialize the Content SDK within a Next.js page component for server-side rendering. It calls `getTenant` to determine the current tenant and then uses `initializeContentSdk` to configure the SDK for that tenant's data. ```typescript import { initializeContentSdk } from "@webiny/sdk-content"; import { getTenant } from "@/contentSdk/getTenant"; // Example for generateStaticParams export async function generateStaticParams() { // Fetch list of tenants to generate static pages for // For simplicity, we'll use a placeholder here const tenants = [{ id: "tenant-1" }, { id: "tenant-2" }]; return tenants.map((tenant) => ({ tenantId: tenant.id })); } // Example for generateMetadata export async function generateMetadata({ params, }: { params: { tenantId: string } }) { const tenantId = params.tenantId; const contentSdk = initializeContentSdk({ apiTenant: tenantId }); const pageData = await contentSdk.content.pages.get({ // Add query parameters to fetch specific page metadata }); return { title: pageData?.title || "Default Title", description: pageData?.description || "Default Description", }; } // Example for getPage (server-side rendering) export default async function Page({ params, }: { params: { tenantId: string }; }) { const tenantId = await getTenant(); // Or use params.tenantId if available and preferred const contentSdk = initializeContentSdk({ apiTenant: tenantId }); // Fetch page data using the initialized SDK const pageData = await contentSdk.content.pages.get({ // Add query parameters to fetch specific page content // e.g., slug: params.slug }); // Render the page using pageData return (

{pageData?.title}

{pageData?.content}

{/* Render other page elements */}
); } ``` -------------------------------- ### Admin BeforeBuild Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom BeforeBuild hook for the Admin stack. This example logs a message before the Admin build process. The hook is registered in `webiny.config.tsx` using the `Infra.Admin.BeforeBuild` component. ```typescript import { AdminBeforeBuildHook } from "webiny/infra/admin"; import { Ui } from "webiny/infra"; export default AdminBeforeBuildHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Admin BeforeBuild hook..."); }, }); ``` -------------------------------- ### Install Standalone Webiny MCP Package Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/get-started/connect-ai-environment.mdx Install the MCP server package globally or in a target project if you need to use it outside of a Webiny project root, such as in a separate repository consuming Webiny APIs. ```bash npm install @webiny/mcp ``` -------------------------------- ### Deploy Webiny Instance Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/get-started/upgrade.mdx Redeploy your Webiny instance to activate the license. Use the appropriate command for local/staging or production deployments. ```bash # Local/staging deployment yarn webiny deploy ``` ```bash # Production deployment (in CI/CD) yarn webiny deploy --env=prod ``` -------------------------------- ### Configure .env File for Next.js Starter Kit Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/user-guides/6.x/website-builder/essentials/nextjs-starter-kit.mdx Populate your .env file with API keys and host details from your Webiny project to establish a connection. Ensure these variables are correctly set for the Website Builder to communicate with your Next.js application. ```tsx NEXT_PUBLIC_WEBSITE_BUILDER_API_KEY: {YOUR_API_KEY} NEXT_PUBLIC_WEBSITE_BUILDER_API_HOST: {YOUR_API_HOST} NEXT_PUBLIC_WEBSITE_BUILDER_API_TENANT: {YOUR_API_TENANT} # Optional, check "Cross-Origin Configuration" section below. NEXT_PUBLIC_WEBSITE_BUILDER_ADMIN_HOST: {YOUR_ADMIN_HOST} ``` -------------------------------- ### Api BeforeWatch Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom BeforeWatch hook for the API stack. This example logs a message before the watch process for the API stack begins. The hook follows the standard DI pattern. ```typescript import { ApiBeforeWatchHook } from "webiny/infra/api"; import { Ui } from "webiny/infra"; export default ApiBeforeWatchHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Api BeforeWatch hook..."); }, }); ``` -------------------------------- ### Example Pulumi Deployment Error Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/debugging.mdx This is an example of an error message you might see when Pulumi fails to deploy. It indicates the specific resource that failed and the reason for the failure, such as AWS permission issues or resource limits. ```text error: update failed error: aws:lambda:Function myfunction: creating Lambda Function: InvalidParameterValueException: The role defined for the function cannot be assumed by Lambda. ``` -------------------------------- ### Api AfterBuild Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom AfterBuild hook for the API stack. This example logs a message after the API build process. The `src` prop in `webiny.config.tsx` points to the TypeScript file containing this implementation. ```typescript import { ApiAfterBuildHook } from "webiny/infra/api"; import { Ui } from "webiny/infra"; export default ApiAfterBuildHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Api AfterBuild hook..."); }, }); ``` -------------------------------- ### Get Page with Tenant and Preview Mode Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/website-builder/multi-tenant-nextjs.mdx Fetches a page, initializing the content SDK with the tenant ID and preview mode status. This is used to retrieve content for a specific tenant, respecting draft mode. ```typescript async function getPage(path: string) { const { isEnabled } = await draftMode(); initializeContentSdk({ preview: isEnabled, tenantId: await getTenant() }); return await contentSdk.getPage(path); } ``` -------------------------------- ### Core AfterBuild Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom AfterBuild hook for the Core stack. This example logs a message after the Core build process has completed. Hooks are executed in registration order if multiple are defined for the same event. ```typescript import { CoreAfterBuildHook } from "webiny/infra/core"; import { Ui } from "webiny/infra"; export default CoreAfterBuildHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Core AfterBuild hook..."); }, }); ``` -------------------------------- ### Deploy the Whole Webiny Project Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/cli/deploy.mdx Use this command to build and deploy all applications within your Webiny project. The environment defaults to `dev`. ```bash yarn webiny deploy ``` -------------------------------- ### Api BeforeBuild Hook Example Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/infrastructure/extensions/build-and-deploy-hooks.ai.txt Implement a custom BeforeBuild hook for the API stack. This example logs a message before the API build process. The implementation follows the standard hook pattern with `createImplementation` and `execute` method. ```typescript import { ApiBeforeBuildHook } from "webiny/infra/api"; import { Ui } from "webiny/infra"; export default ApiBeforeBuildHook.createImplementation({ async execute(): Promise { Ui.info("Running custom Api BeforeBuild hook..."); }, }); ``` -------------------------------- ### File Management with SDK Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/core-concepts/webiny-sdk.ai.txt Use the `sdk.fileManager` module for operations related to files and folders. This example shows how to list files in the root folder. ```typescript import { WebinySDK } from "@webiny/sdk"; // Assuming sdk is already initialized const sdk = new WebinySDK({ apiKey: process.env.WEBINY_API_KEY, apiEndpoint: process.env.WEBINY_API_ENDPOINT, }); async function listRootFiles() { const result = await sdk.fileManager.listFiles({ folderId: "root", // Use 'root' for the root folder }); if (result.isOk()) { console.log("Files in root folder:", result.value); return result.value; } else { console.error("Error listing files:", result.error); } } listRootFiles(); ``` -------------------------------- ### Configure Local Development Environment Variables Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/get-started/upgrade.mdx Add your project ID and development API key to your project's .env file for local development. ```bash WEBINY_PROJECT_ID=your-org/your-project-name WEBINY_PROJECT_API_KEY=your-development-api-key ``` -------------------------------- ### Implement Get Page By ID Abstraction Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/website-builder/use-case/pages.mdx Provides a concrete implementation for the Get Page By ID abstraction. This class depends on the GetPageByIdUseCase and handles the execution logic, returning null if the page is not found or an error occurs. ```typescript import { GetPageByIdUseCase } from "webiny/api/website-builder/page"; import { GetPageById } from "./abstractions.js"; class GetPageByIdImpl implements GetPageById.Interface { constructor(private getPageByIdUseCase: GetPageByIdUseCase.Interface) {} async execute({ id }: GetPageById.Params): GetPageById.Return { const result = await this.getPageByIdUseCase.execute(id); if (result.isFail()) { return null; } return result.value; } } export default GetPageById.createImplementation({ implementation: GetPageByIdImpl, dependencies: [GetPageByIdUseCase] }); ``` -------------------------------- ### Start Watching API or Admin Apps Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/cli/watch.mdx Use `webiny watch` with either `api` or `admin` to start a local development session. This command monitors your source files and automatically rebuilds and redeploys code when changes are detected. ```bash yarn webiny watch api yarn webiny watch admin ``` -------------------------------- ### Run Webiny Info Command for a Specific Environment Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/cli/info.mdx Use the '--env' option to specify a particular environment, such as 'prod', to retrieve its associated URLs. ```bash yarn webiny info --env prod ``` -------------------------------- ### Import Get Latest Revision By Entry Id Base Use Case Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/headless-cms/use-case/entry.mdx Import the base use case for getting the latest revision by entry ID. This might be used for custom implementations or extensions of the base functionality. ```typescript import { GetLatestRevisionByEntryIdBaseUseCase } from "webiny/api/cms/entry"; ``` -------------------------------- ### Navigate to Project Directory Source: https://github.com/webiny/docs.webiny.com/blob/master/README.md Changes the current directory to the root of the cloned Webiny documentation project. ```sh cd docs.webiny.com ``` -------------------------------- ### Create Tenant with Tenant Manager SDK Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/reference/sdk/tenant-manager.mdx Use this method to create a new tenant in the system. It requires tenant data as input. ```typescript sdk.tenantManager.createTenant(params: CreateTenantParams): Promise> ``` -------------------------------- ### Install Tenant Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/tenant-manager/manage-tenants.ai.txt Provisions the necessary resources and configurations for a tenant. This operation must be called after a tenant has been created and requires administrator privileges. ```APIDOC ## Install Tenant ### Description Provisions a tenant with default settings and configurations. This step is mandatory after tenant creation and requires administrator privileges. ### Method `mutation` ### Fields - `tenantManager.installTenant` ### Input `InstallTenantInput` - `tenantId` (string) - Required - The ID of the tenant to install. ### Returns `BooleanResponse` - `data` (boolean) - True if the operation was successful, null otherwise. - `error` (WebinyError) - An error object if the operation failed. ### Example ```graphql mutation InstallTenant($tenantId: ID!) { tenantManager { installTenant(tenantId: $tenantId) } } ``` ### Variables ```json { "tenantId": "my-custom-tenant-id" } ``` ``` -------------------------------- ### Working with Path Parameters and Request Data Source: https://github.com/webiny/docs.webiny.com/blob/master/docs/developer-docs/6.x/webiny-api/api-routes.mdx Example demonstrating how to use path parameters and access request query parameters in a custom route handler. ```APIDOC ## Working with Path Parameters and Request Data Use `{paramName}` in the path to capture path parameters, then access them via `request.params`: ```typescript extensions/GetOrderRoute.ts import { Logger, Route } from "webiny/api"; interface OrderParams { orderId: string; } class GetOrderRouteImpl implements Route.Interface { public constructor(private logger: Logger.Interface) {} public async execute(request: Route.Request, reply: Route.Reply): Promise { const { orderId } = request.params as OrderParams; const { limit } = request.query as { limit?: string }; this.logger.info("Fetching order", { orderId }); return reply.code(200).send({ orderId, limit: limit ?? "10" }); } } export default Route.createImplementation({ implementation: GetOrderRouteImpl, dependencies: [Logger] }); ``` ```tsx webiny.config.tsx ``` ```