AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
fix(embed): build Human Input form and chat links from the platform's embed subdomain (#16744)
lina-alomari459d196f90dc
diff --git a/packages/core/shared/package.json b/packages/core/shared/package.jsonindex c99872a1c4b..4fc53073440 100644--- a/packages/core/shared/package.json+++ b/packages/core/shared/package.json@@ -1,6 +1,6 @@{"name": "@activepieces/shared",- "version": "0.207.1",+ "version": "0.207.2","type": "commonjs","sideEffects": false,"main": "./dist/src/index.js",diff --git a/packages/core/shared/src/lib/core/flag/flag.ts b/packages/core/shared/src/lib/core/flag/flag.tsindex 5f6a0e45971..1188eebbf0a 100755--- a/packages/core/shared/src/lib/core/flag/flag.ts+++ b/packages/core/shared/src/lib/core/flag/flag.ts@@ -32,6 +32,7 @@ export enum ApFlagId {AUDIT_LOG_RETENTION_PAUSED = 'AUDIT_LOG_RETENTION_PAUSED',ENVIRONMENT = 'ENVIRONMENT',PUBLIC_URL = 'PUBLIC_URL',+ EMBED_SUBDOMAIN_URL = 'EMBED_SUBDOMAIN_URL',MCP_URL = 'MCP_URL',PRIVACY_POLICY_URL = 'PRIVACY_POLICY_URL',PIECES_SYNC_MODE = 'PIECES_SYNC_MODE',diff --git a/packages/server/api/src/app/ee/flags/enterprise-flags.hooks.ts b/packages/server/api/src/app/ee/flags/enterprise-flags.hooks.tsindex 9b0cf84120c..af282e6c932 100644--- a/packages/server/api/src/app/ee/flags/enterprise-flags.hooks.ts+++ b/packages/server/api/src/app/ee/flags/enterprise-flags.hooks.ts@@ -56,6 +56,7 @@ export const enterpriseFlagsHooks: FlagsServiceHooks = {const embedSubdomainUrl = await embedSubdomainService(request.log).getActiveSubdomainUrl({ platformId })if (embedSubdomainUrl) {modifiedFlags[ApFlagId.WEBHOOK_URL_PREFIX] = `${embedSubdomainUrl}/api/v1/webhooks`+ modifiedFlags[ApFlagId.EMBED_SUBDOMAIN_URL] = `${embedSubdomainUrl}/`}else {modifiedFlags[diff --git a/packages/server/api/test/integration/ce/flags/flags.test.ts b/packages/server/api/test/integration/ce/flags/flags.test.tsindex 04068720c8a..96de5807ecd 100644--- a/packages/server/api/test/integration/ce/flags/flags.test.ts+++ b/packages/server/api/test/integration/ce/flags/flags.test.ts@@ -27,6 +27,7 @@ describe('Flags API', () => {expect(typeof body.ENVIRONMENT).toBe('string')expect(body).toHaveProperty('WEBHOOK_URL_PREFIX')expect(typeof body.WEBHOOK_URL_PREFIX).toBe('string')+ expect(body).not.toHaveProperty('EMBED_SUBDOMAIN_URL')})})})diff --git a/packages/server/api/test/integration/ee/flags/flags.test.ts b/packages/server/api/test/integration/ee/flags/flags.test.tsindex 1527e2f5048..a78bb21c40f 100644--- a/packages/server/api/test/integration/ee/flags/flags.test.ts+++ b/packages/server/api/test/integration/ee/flags/flags.test.ts@@ -1,6 +1,8 @@-import { ApFlagId } from '@activepieces/shared'+import { apId } from '@activepieces/core-utils'+import { ApFlagId, EmbedSubdomainStatus } from '@activepieces/shared'import { FastifyInstance } from 'fastify'import { StatusCodes } from 'http-status-codes'+import { databaseConnection } from '../../../../src/app/database/database-connection'import { createTestContext } from '../../../helpers/test-context'import { setupTestEnvironment, teardownTestEnvironment } from '../../../helpers/test-setup'@@ -156,5 +158,66 @@ describe('Flags API', () => {expect(response.statusCode).toBe(StatusCodes.OK)expect(response.json()[ApFlagId.THEME].statusColors).toStrictEqual({})})++ describe('EMBED_SUBDOMAIN_URL', () => {+ it('should not return the embed subdomain url when the platform has no embed subdomain', async () => {+ const ctx = await createTestContext(app!)++ const response = await ctx.get('/v1/flags')++ expect(response.statusCode).toBe(StatusCodes.OK)+ expect(response.json()).not.toHaveProperty(ApFlagId.EMBED_SUBDOMAIN_URL)+ })++ it('should not return the embed subdomain url while the embed subdomain is pending verification', async () => {+ const ctx = await createTestContext(app!)+ await saveEmbedSubdomain({ platformId: ctx.platform.id, status: EmbedSubdomainStatus.PENDING_VERIFICATION })++ const response = await ctx.get('/v1/flags')++ expect(response.statusCode).toBe(StatusCodes.OK)+ expect(response.json()).not.toHaveProperty(ApFlagId.EMBED_SUBDOMAIN_URL)+ })++ it('should return the active embed subdomain url and keep the public url on the instance', async () => {+ const ctx = await createTestContext(app!)+ const publicUrlBefore = (await ctx.get('/v1/flags')).json()[ApFlagId.PUBLIC_URL]+ const hostname = await saveEmbedSubdomain({ platformId: ctx.platform.id, status: EmbedSubdomainStatus.ACTIVE })++ const response = await ctx.get('/v1/flags')++ expect(response.statusCode).toBe(StatusCodes.OK)+ const body = response.json()+ expect(body[ApFlagId.EMBED_SUBDOMAIN_URL]).toBe(`https://${hostname}/`)+ expect(body[ApFlagId.WEBHOOK_URL_PREFIX]).toBe(`https://${hostname}/api/v1/webhooks`)+ expect(body[ApFlagId.PUBLIC_URL]).toBe(publicUrlBefore)+ })++ it('should not return another platform\'s embed subdomain url', async () => {+ const platformWithSubdomain = await createTestContext(app!)+ await saveEmbedSubdomain({ platformId: platformWithSubdomain.platform.id, status: EmbedSubdomainStatus.ACTIVE })+ const otherPlatform = await createTestContext(app!)++ const response = await otherPlatform.get('/v1/flags')++ expect(response.statusCode).toBe(StatusCodes.OK)+ expect(response.json()).not.toHaveProperty(ApFlagId.EMBED_SUBDOMAIN_URL)+ })+ })})})++async function saveEmbedSubdomain({ platformId, status }: { platformId: string, status: EmbedSubdomainStatus }): Promise<string> {+ const hostname = `test-${apId().slice(0, 8).toLowerCase()}.example.com`+ await databaseConnection().getRepository('embed_subdomain').save({+ id: apId(),+ created: new Date().toISOString(),+ updated: new Date().toISOString(),+ platformId,+ hostname,+ status,+ cloudflareId: `cf-${apId()}`,+ verificationRecords: [],+ })+ return hostname+}diff --git a/packages/web/src/app/builder/step-settings/piece-settings/index.tsx b/packages/web/src/app/builder/step-settings/piece-settings/index.tsxindex 63ec69cf9f4..ed9d8c2eddf 100644--- a/packages/web/src/app/builder/step-settings/piece-settings/index.tsx+++ b/packages/web/src/app/builder/step-settings/piece-settings/index.tsx@@ -67,10 +67,14 @@ const PieceSettings = React.memo((props: PieceSettingsProps) => {);const { data: frontendUrl } = flagsHooks.useFlag<string>(ApFlagId.PUBLIC_URL);+ const { data: embedSubdomainUrl } = flagsHooks.useFlag<string>(+ ApFlagId.EMBED_SUBDOMAIN_URL,+ );+ const publicLinkBaseUrl = embedSubdomainUrl ?? frontendUrl;const markdownVariables = {webhookUrl: `${webhookPrefixUrl}/${props.flowId}`,- formUrl: `${frontendUrl}forms/${props.flowId}`,- chatUrl: `${frontendUrl}chats/${props.flowId}`,+ formUrl: `${publicLinkBaseUrl}forms/${props.flowId}`,+ chatUrl: `${publicLinkBaseUrl}chats/${props.flowId}`,pausedFlowTimeoutDays: pausedFlowTimeoutDays?.toString() ?? '',webhookTimeoutSeconds: webhookTimeoutSeconds?.toString() ?? '',};