pull/715/head
Travis Fischer 2025-05-25 23:02:13 +07:00
rodzic 23364946eb
commit 27ef5754b3
6 zmienionych plików z 51 dodań i 15 usunięć

Wyświetl plik

@ -1,5 +1,5 @@
import type { ZodTypeDef } from 'zod'
import { assert, parseZodSchema } from '@agentic/platform-core'
import { assert, HttpError, parseZodSchema } from '@agentic/platform-core'
import {
type AgenticProjectConfigInput,
type AgenticProjectConfigOutput,
@ -16,9 +16,7 @@ export async function validateAgenticConfig(
AgenticProjectConfigInput
>(agenticProjectConfigSchema, inputConfig)
console.log('config', config)
const { pricingIntervals, pricingPlans } = config
const { pricingIntervals, pricingPlans, originUrl } = config
assert(
pricingPlans?.length,
400,
@ -30,6 +28,21 @@ export async function validateAgenticConfig(
'Invalid pricingIntervals: must be a non-empty array'
)
try {
const parsedOriginUrl = new URL(originUrl)
assert(
parsedOriginUrl.protocol === 'https:',
400,
'Invalid originUrl: must be a valid https URL'
)
} catch (err) {
throw new HttpError({
message: 'Invalid originUrl: must be a valid https URL',
statusCode: 400,
cause: err
})
}
{
// Validate pricing interval
const pricingIntervalsSet = new Set(pricingIntervals)

Wyświetl plik

@ -23,6 +23,7 @@
},
"dependencies": {
"@agentic/platform-core": "workspace:*",
"@agentic/platform-validators": "workspace:*",
"@hono/zod-openapi": "^0.19.6",
"zod": "catalog:"
},

Wyświetl plik

@ -1,3 +1,4 @@
import { validators } from '@agentic/platform-validators'
import { z } from '@hono/zod-openapi'
import {
@ -14,8 +15,8 @@ import {
// - origin adapter openapi schema path, url, or in-place definition
// - optional stripe webhooks
// - optional response header config (custom headers, immutability for caching, etc)
// - optional version
// - optional agentic version
// - optional version
export const defaultFreePricingPlan = {
name: 'Free',
@ -27,16 +28,31 @@ export const defaultFreePricingPlan = {
amount: 0
}
]
} as const satisfies PricingPlan
} as const satisfies Readonly<PricingPlan>
export const agenticProjectConfigSchema = z.object({
/** Required name of the project. */
name: z.string().describe('Name of the project.'),
/**
* Required name of the project.
*
* Must be lower kebab-case with no spaces and between 2 and 64 characters.
*
* @example "my-project"
* @example "linkedin-resolver-23"
*/
name: z
.string()
.describe('Name of the project.')
.refine(
(name) => validators.projectName(name),
(name) => ({
message: `Invalid project name "${name}". Must be lower kebab-case with no spaces between 2 and 64 characters.`
})
),
/** Optional one-sentence description of the project. */
/** Optional short description of the project. */
description: z
.string()
.describe('A one-sentence description of the project.')
.describe('A short description of the project.')
.optional(),
/** Optional readme documenting the project (supports GitHub-flavored markdown). */
@ -47,14 +63,16 @@ export const agenticProjectConfigSchema = z.object({
)
.optional(),
/** Optional URL to the source code for the project. */
/** Optional URL to the source code of the project. */
sourceUrl: z
.string()
.url()
.optional()
.describe('Optional URL to the source code for the project.'),
.describe('Optional URL to the source code of the project.'),
/** Optional logo image URL to use for the project. Logos should have a square aspect ratio. */
/**
* Optional logo image URL to use for the project. Logos should have a square aspect ratio.
*/
iconUrl: z
.string()
.url()

Wyświetl plik

@ -43,13 +43,14 @@ test('password failure', () => {
})
test('projectName success', () => {
expect(validators.projectName('ai')).toBe(true)
expect(validators.projectName('aaa')).toBe(true)
expect(validators.projectName('hello-world')).toBe(true)
expect(validators.projectName('123-abc')).toBe(true)
})
test('projectName failure', () => {
expect(validators.projectName('aa')).toBe(false)
expect(validators.projectName('a')).toBe(false)
expect(validators.projectName('hello_world')).toBe(false)
expect(validators.projectName('a_bc')).toBe(false)
expect(validators.projectName('abc.'))

Wyświetl plik

@ -5,7 +5,7 @@ import isRelativeUrl from 'is-relative-url'
export const usernameRe = /^[a-zA-Z0-9-]{1,64}$/
export const passwordRe = /^.{3,1024}$/
export const projectNameRe = /^[a-z0-9-]{3,64}$/
export const projectNameRe = /^[a-z0-9-]{2,64}$/
export const deploymentHashRe = /^[a-z0-9]{8}$/
export const projectRe = /^[a-zA-Z0-9-]{1,64}\/[a-z0-9-]{3,64}$/

Wyświetl plik

@ -325,6 +325,9 @@ importers:
'@agentic/platform-core':
specifier: workspace:*
version: link:../core
'@agentic/platform-validators':
specifier: workspace:*
version: link:../validators
'@hono/zod-openapi':
specifier: ^0.19.6
version: 0.19.6(hono@4.7.9)(zod@3.24.4)