diff --git a/docs/mcp.md b/docs/mcp.md index 13c2b620..72bac728 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -18,6 +18,8 @@ Both implementations share the same underlying tools, schemas, and utilities, en - [Available Tools](#available-tools) - [Feature Management](#feature-management) - [Variable Management](#variable-management) + - [Custom Properties](#custom-properties) + - [Environment Management](#environment-management) - [Project Management](#project-management) - [SDK Installation](#sdk-installation) - [Self-Targeting & Overrides](#self-targeting--overrides) @@ -294,6 +296,83 @@ Delete a variable from ALL environments. - `key`: Variable key to delete +### Custom Properties + +Custom properties define the custom user data (`customData`) that audiences and targeting rules can target. + +#### `list_custom_properties` + +List all custom properties in the current project. + +**Parameters:** + +- `search` (optional): Search query to filter by name or key +- `page` (optional): Page number +- `perPage` (optional): Items per page +- `sortBy` (optional): Sort field (`createdAt`, `updatedAt`, `name`, `key`, `createdBy`, `propertyKey`) +- `sortOrder` (optional): Sort order (`asc`, `desc`) +- `type` (optional): Property type (`String`, `Boolean`, `Number`) + +#### `create_custom_property` + +Create a new custom property. + +**Parameters:** + +- `key`: Unique custom property key (pattern: `^[a-z0-9-_.]+$`) +- `name`: Display name +- `type`: Property type (`String`, `Boolean`, `Number`) +- `propertyKey`: The key in the user's `customData` that the SDK sends + +#### `update_custom_property` ⚠️ + +Update an existing custom property. + +**Parameters:** + +- `key`: Custom property key to update +- `name` (optional): New name +- `type` (optional): New type +- `propertyKey` (optional): New `customData` key + +#### `delete_custom_property` ⚠️⚠️ + +Delete a custom property from ALL environments. + +**Parameters:** + +- `key`: Custom property key to delete + +### Environment Management + +Use `select_project` or `get_current_project` to list environments and read their SDK keys. + +#### `create_environment` + +Create a new environment in the current project. + +**Parameters:** + +- `key`: Unique environment key (pattern: `^[a-z0-9-_.]+$`) +- `name`: Environment name +- `type`: Environment type (`development`, `staging`, `production`, `disaster_recovery`) +- `description` (optional): Environment description +- `color` (optional): Hex color (e.g. `#FF0000`) +- `settings` (optional): Environment settings + +#### `update_environment` ⚠️ + +Update an existing environment. + +**Parameters:** + +- `key`: Environment key to update +- `name` (optional): New name +- `description` (optional): New description +- `color` (optional): New hex color +- `type` (optional): New environment type +- `settings` (optional): New environment settings + ### Project Management #### `get_current_project` @@ -545,7 +624,7 @@ Key differences: ### Notes on Environments -- Dedicated environment tools are not exposed via MCP. Use `get_current_project` or `select_project` to retrieve environments and SDK keys for the selected project. +- There are no dedicated tools for listing environments or reading SDK keys. Use `get_current_project` or `select_project` to retrieve environments and SDK keys for the selected project, and `create_environment` / `update_environment` to manage them. ## Development & Local Testing diff --git a/mcp-worker/README.md b/mcp-worker/README.md index 9d583e50..a6387d31 100644 --- a/mcp-worker/README.md +++ b/mcp-worker/README.md @@ -121,7 +121,9 @@ All DevCycle CLI MCP tools are available. See [complete reference](../docs/mcp.m **Variables**: `list_variables`, `create_variable`, `update_variable`, `delete_variable` -**Environments**: `list_environments`, `get_sdk_keys` +**Custom Properties**: `list_custom_properties`, `create_custom_property`, `update_custom_property`, `delete_custom_property` + +**Environments**: `create_environment`, `update_environment` **Self-Targeting**: `get_self_targeting_identity`, `update_self_targeting_identity`, `list_self_targeting_overrides`, `set_self_targeting_override`, `clear_feature_self_targeting_overrides` diff --git a/src/api/customProperties.ts b/src/api/customProperties.ts index cf3c2233..0148650d 100644 --- a/src/api/customProperties.ts +++ b/src/api/customProperties.ts @@ -1,29 +1,41 @@ +import { z } from 'zod' import apiClient from './apiClient' import { buildHeaders } from './common' +import { CreateCustomPropertyDto, UpdateCustomPropertyDto } from './zodSchemas' const BASE_URL = '/v1/projects/:project/customProperties' export const fetchCustomProperties = async ( token: string, project_id: string, + queries: { + page?: number + perPage?: number + sortBy?: + | 'createdAt' + | 'updatedAt' + | 'name' + | 'key' + | 'createdBy' + | 'propertyKey' + sortOrder?: 'asc' | 'desc' + search?: string + type?: 'String' | 'Boolean' | 'Number' + } = {}, ) => { return apiClient.get(`${BASE_URL}`, { headers: buildHeaders(token), params: { project: project_id, }, + queries, }) } export const createCustomProperty = async ( token: string, project_id: string, - data: { - name: string - key: string - type: 'String' | 'Boolean' | 'Number' - propertyKey: string - }, + data: z.infer, ) => { return apiClient.post(`${BASE_URL}`, data, { headers: buildHeaders(token), @@ -37,12 +49,7 @@ export const updateCustomProperty = async ( token: string, project_id: string, key: string, - data: { - name?: string - key?: string - propertyKey?: string - type?: 'String' | 'Boolean' | 'Number' - }, + data: z.infer, ) => { return apiClient.patch(`${BASE_URL}/:key`, data, { headers: buildHeaders(token), diff --git a/src/mcp/server.test.ts b/src/mcp/server.test.ts index f80e018c..14197eaa 100644 --- a/src/mcp/server.test.ts +++ b/src/mcp/server.test.ts @@ -129,6 +129,17 @@ describe('DevCycleMCPServer', () => { expect(registeredToolNames).to.include( 'get_self_targeting_identity', ) + expect(registeredToolNames).to.include.members([ + 'list_custom_properties', + 'create_custom_property', + 'update_custom_property', + 'delete_custom_property', + 'create_environment', + 'update_environment', + ]) + // Covered by select_project + expect(registeredToolNames).to.not.include('list_environments') + expect(registeredToolNames).to.not.include('get_sdk_keys') }) it('should register tools with proper configurations', () => { diff --git a/src/mcp/tools/customPropertiesTools.test.ts b/src/mcp/tools/customPropertiesTools.test.ts new file mode 100644 index 00000000..c5e6b265 --- /dev/null +++ b/src/mcp/tools/customPropertiesTools.test.ts @@ -0,0 +1,127 @@ +import { expect } from '@oclif/test' +import sinon from 'sinon' +import nock from 'nock' +import { BASE_URL } from '../../api/common' +import { DevCycleApiClient } from '../utils/api' +import { DevCycleAuth } from '../utils/auth' +import { + listCustomPropertiesHandler, + createCustomPropertyHandler, + updateCustomPropertyHandler, + deleteCustomPropertyHandler, +} from './customPropertiesTools' + +const customProperty = { + _id: '61450f3daec96f5cf4a49970', + _project: '61450f3daec96f5cf4a49950', + key: 'plan', + name: 'Plan', + _createdBy: 'user-id', + propertyKey: 'plan', + type: 'String', + createdAt: '2025-07-24T19:41:53.000Z', + updatedAt: '2025-07-24T19:41:53.000Z', +} + +describe('customPropertiesTools', () => { + let apiClient: DevCycleApiClient + + beforeEach(() => { + const authStub = sinon.createStubInstance(DevCycleAuth) + authStub.getAuthToken.returns('mock-auth-token') + authStub.getProjectKey.returns('selected-project') + authStub.getOrgId.returns('test-org-id') + apiClient = new DevCycleApiClient(authStub) + }) + + afterEach(() => { + sinon.restore() + nock.cleanAll() + }) + + it('lists custom properties, forwarding filters but not projectKey', async () => { + const scope = nock(BASE_URL) + .get('/v1/projects/arg-project/customProperties') + .query({ search: 'plan', type: 'String', perPage: '50' }) + .reply(200, [customProperty]) + + const response = await listCustomPropertiesHandler( + { + projectKey: 'arg-project', + search: 'plan', + type: 'String', + perPage: 50, + }, + apiClient, + ) + + expect(scope.isDone()).to.equal(true) + expect(response.result).to.eql([customProperty]) + expect(response.dashboardLink).to.equal( + 'https://app.devcycle.com/o/test-org-id/p/arg-project/custom-properties', + ) + }) + + it('creates a custom property in the selected project', async () => { + let body: Record = {} + const scope = nock(BASE_URL) + .post('/v1/projects/selected-project/customProperties', (b) => { + body = b + return true + }) + .reply(201, customProperty) + + await createCustomPropertyHandler( + { + key: 'plan', + name: 'Plan', + type: 'String', + propertyKey: 'plan', + }, + apiClient, + ) + + expect(scope.isDone()).to.equal(true) + expect(body).to.eql({ + key: 'plan', + name: 'Plan', + type: 'String', + propertyKey: 'plan', + }) + }) + + it('updates a custom property by key without sending key or projectKey in the body', async () => { + let body: Record = {} + const scope = nock(BASE_URL) + .patch('/v1/projects/arg-project/customProperties/plan', (b) => { + body = b + return true + }) + .reply(200, { ...customProperty, name: 'Billing Plan' }) + + const response = await updateCustomPropertyHandler( + { projectKey: 'arg-project', key: 'plan', name: 'Billing Plan' }, + apiClient, + ) + + expect(scope.isDone()).to.equal(true) + expect(body).to.eql({ name: 'Billing Plan' }) + expect(response.result).to.include({ name: 'Billing Plan' }) + }) + + it('deletes a custom property', async () => { + const scope = nock(BASE_URL) + .delete('/v1/projects/selected-project/customProperties/plan') + .reply(200) + + const response = await deleteCustomPropertyHandler( + { key: 'plan' }, + apiClient, + ) + + expect(scope.isDone()).to.equal(true) + expect(response.result).to.eql({ + message: "Custom property 'plan' deleted successfully", + }) + }) +}) diff --git a/src/mcp/tools/customPropertiesTools.ts b/src/mcp/tools/customPropertiesTools.ts new file mode 100644 index 00000000..a25a5e52 --- /dev/null +++ b/src/mcp/tools/customPropertiesTools.ts @@ -0,0 +1,212 @@ +import { z } from 'zod' +import { + handleZodiosValidationErrors, + omitProjectKey, + MISSING_PROJECT_KEY_ERROR, +} from '../utils/api' +import { + fetchCustomProperties, + createCustomProperty, + updateCustomProperty, + deleteCustomProperty, +} from '../../api/customProperties' +import { + ListCustomPropertiesArgsSchema, + CreateCustomPropertyArgsSchema, + UpdateCustomPropertyArgsSchema, + DeleteCustomPropertyArgsSchema, +} from '../types' +import { IDevCycleApiClient } from '../api/interface' +import { DevCycleMCPServerInstance } from '../server' +import { dashboardLinks } from '../utils/dashboardLinks' + +// Individual handler functions +export async function listCustomPropertiesHandler( + args: z.infer, + apiClient: IDevCycleApiClient, +) { + return await apiClient.executeWithDashboardLink( + 'listCustomProperties', + args, + async (authToken: string, projectKey: string | undefined) => { + if (!projectKey) { + throw new Error(MISSING_PROJECT_KEY_ERROR) + } + return await handleZodiosValidationErrors( + () => + fetchCustomProperties( + authToken, + projectKey, + omitProjectKey(args), + ), + 'fetchCustomProperties', + ) + }, + dashboardLinks.customProperties.list, + ) +} + +export async function createCustomPropertyHandler( + args: z.infer, + apiClient: IDevCycleApiClient, +) { + return await apiClient.executeWithDashboardLink( + 'createCustomProperty', + args, + async (authToken: string, projectKey: string | undefined) => { + if (!projectKey) { + throw new Error(MISSING_PROJECT_KEY_ERROR) + } + return await handleZodiosValidationErrors( + () => + createCustomProperty( + authToken, + projectKey, + omitProjectKey(args), + ), + 'createCustomProperty', + ) + }, + dashboardLinks.customProperties.list, + ) +} + +export async function updateCustomPropertyHandler( + args: z.infer, + apiClient: IDevCycleApiClient, +) { + const { key, ...updateData } = omitProjectKey(args) + + return await apiClient.executeWithDashboardLink( + 'updateCustomProperty', + args, + async (authToken: string, projectKey: string | undefined) => { + if (!projectKey) { + throw new Error(MISSING_PROJECT_KEY_ERROR) + } + return await handleZodiosValidationErrors( + () => + updateCustomProperty( + authToken, + projectKey, + key, + updateData, + ), + 'updateCustomProperty', + ) + }, + dashboardLinks.customProperties.list, + ) +} + +export async function deleteCustomPropertyHandler( + args: z.infer, + apiClient: IDevCycleApiClient, +) { + return await apiClient.executeWithDashboardLink( + 'deleteCustomProperty', + args, + async (authToken: string, projectKey: string | undefined) => { + if (!projectKey) { + throw new Error(MISSING_PROJECT_KEY_ERROR) + } + await handleZodiosValidationErrors( + () => deleteCustomProperty(authToken, projectKey, args.key), + 'deleteCustomProperty', + ) + return { + message: `Custom property '${args.key}' deleted successfully`, + } + }, + dashboardLinks.customProperties.list, + ) +} + +/** + * Register custom properties tools with the MCP server using the new direct registration pattern + */ +export function registerCustomPropertiesTools( + serverInstance: DevCycleMCPServerInstance, + apiClient: IDevCycleApiClient, +): void { + serverInstance.registerToolWithErrorHandling( + 'list_custom_properties', + { + description: [ + 'List custom properties in the current project.', + 'Custom properties define the custom user data (customData) that audiences and feature targeting rules can target.', + 'Include dashboard link in the response.', + ].join('\n'), + annotations: { + title: 'List Custom Properties', + readOnlyHint: true, + }, + inputSchema: ListCustomPropertiesArgsSchema.shape, + }, + async (args: any) => { + const validatedArgs = ListCustomPropertiesArgsSchema.parse(args) + return await listCustomPropertiesHandler(validatedArgs, apiClient) + }, + ) + + serverInstance.registerToolWithErrorHandling( + 'create_custom_property', + { + description: [ + 'Create a new custom property.', + 'Custom properties define the custom user data (customData) that audiences and feature targeting rules can target.', + 'Include dashboard link in the response.', + ].join('\n'), + annotations: { + title: 'Create Custom Property', + }, + inputSchema: CreateCustomPropertyArgsSchema.shape, + }, + async (args: any) => { + const validatedArgs = CreateCustomPropertyArgsSchema.parse(args) + return await createCustomPropertyHandler(validatedArgs, apiClient) + }, + ) + + serverInstance.registerToolWithErrorHandling( + 'update_custom_property', + { + description: [ + 'Update an existing custom property.', + '⚠️ IMPORTANT: Custom property changes can affect targeting rules for features active in production environments.', + 'Always confirm with the user before updating a custom property that is in use.', + 'Include dashboard link in the response.', + ].join('\n'), + annotations: { + title: 'Update Custom Property', + destructiveHint: true, + }, + inputSchema: UpdateCustomPropertyArgsSchema.shape, + }, + async (args: any) => { + const validatedArgs = UpdateCustomPropertyArgsSchema.parse(args) + return await updateCustomPropertyHandler(validatedArgs, apiClient) + }, + ) + + serverInstance.registerToolWithErrorHandling( + 'delete_custom_property', + { + description: [ + 'Delete a custom property.', + '⚠️ CRITICAL: Deleting a custom property removes it from ALL environments including production, and can break targeting rules that use it.', + 'ALWAYS confirm with the user before deleting any custom property.', + 'Include dashboard link in the response.', + ].join('\n'), + annotations: { + title: 'Delete Custom Property', + destructiveHint: true, + }, + inputSchema: DeleteCustomPropertyArgsSchema.shape, + }, + async (args: any) => { + const validatedArgs = DeleteCustomPropertyArgsSchema.parse(args) + return await deleteCustomPropertyHandler(validatedArgs, apiClient) + }, + ) +} diff --git a/src/mcp/tools/environmentTools.test.ts b/src/mcp/tools/environmentTools.test.ts new file mode 100644 index 00000000..5f300019 --- /dev/null +++ b/src/mcp/tools/environmentTools.test.ts @@ -0,0 +1,89 @@ +import { expect } from '@oclif/test' +import sinon from 'sinon' +import nock from 'nock' +import { BASE_URL } from '../../api/common' +import { DevCycleApiClient } from '../utils/api' +import { DevCycleAuth } from '../utils/auth' +import { + createEnvironmentHandler, + updateEnvironmentHandler, +} from './environmentTools' + +const environment = { + _id: '61450f3daec96f5cf4a49960', + _project: '61450f3daec96f5cf4a49950', + key: 'qa', + name: 'QA', + type: 'staging', + _createdBy: 'user-id', + createdAt: '2025-07-24T19:41:53.000Z', + updatedAt: '2025-07-24T19:41:53.000Z', +} + +describe('environmentTools', () => { + let apiClient: DevCycleApiClient + + beforeEach(() => { + const authStub = sinon.createStubInstance(DevCycleAuth) + authStub.getAuthToken.returns('mock-auth-token') + authStub.getProjectKey.returns('selected-project') + authStub.getOrgId.returns('test-org-id') + apiClient = new DevCycleApiClient(authStub) + }) + + afterEach(() => { + sinon.restore() + nock.cleanAll() + }) + + it('creates an environment without sending projectKey in the body', async () => { + let body: Record = {} + const scope = nock(BASE_URL) + .post('/v1/projects/arg-project/environments', (b) => { + body = b + return true + }) + .reply(201, environment) + + const response = await createEnvironmentHandler( + { + projectKey: 'arg-project', + key: 'qa', + name: 'QA', + type: 'staging', + color: '#00FF00', + }, + apiClient, + ) + + expect(scope.isDone()).to.equal(true) + expect(body).to.eql({ + key: 'qa', + name: 'QA', + type: 'staging', + color: '#00FF00', + }) + expect(response.dashboardLink).to.equal( + 'https://app.devcycle.com/o/test-org-id/settings/p/arg-project/environments', + ) + }) + + it('updates an environment by key in the selected project', async () => { + let body: Record = {} + const scope = nock(BASE_URL) + .patch('/v1/projects/selected-project/environments/qa', (b) => { + body = b + return true + }) + .reply(200, { ...environment, name: 'Quality Assurance' }) + + const response = await updateEnvironmentHandler( + { key: 'qa', name: 'Quality Assurance' }, + apiClient, + ) + + expect(scope.isDone()).to.equal(true) + expect(body).to.eql({ name: 'Quality Assurance' }) + expect(response.result).to.include({ name: 'Quality Assurance' }) + }) +}) diff --git a/src/mcp/tools/environmentTools.ts b/src/mcp/tools/environmentTools.ts new file mode 100644 index 00000000..54a9814b --- /dev/null +++ b/src/mcp/tools/environmentTools.ts @@ -0,0 +1,110 @@ +import { z } from 'zod' +import { + handleZodiosValidationErrors, + omitProjectKey, + MISSING_PROJECT_KEY_ERROR, +} from '../utils/api' +import { createEnvironment, updateEnvironment } from '../../api/environments' +import { + CreateEnvironmentArgsSchema, + UpdateEnvironmentArgsSchema, +} from '../types' +import { IDevCycleApiClient } from '../api/interface' +import { DevCycleMCPServerInstance } from '../server' +import { dashboardLinks } from '../utils/dashboardLinks' + +// Individual handler functions +export async function createEnvironmentHandler( + args: z.infer, + apiClient: IDevCycleApiClient, +) { + return await apiClient.executeWithDashboardLink( + 'createEnvironment', + args, + async (authToken: string, projectKey: string | undefined) => { + if (!projectKey) { + throw new Error(MISSING_PROJECT_KEY_ERROR) + } + return await handleZodiosValidationErrors( + () => + createEnvironment( + authToken, + projectKey, + omitProjectKey(args), + ), + 'createEnvironment', + ) + }, + dashboardLinks.environment.settings, + ) +} + +export async function updateEnvironmentHandler( + args: z.infer, + apiClient: IDevCycleApiClient, +) { + const { key, ...updateData } = omitProjectKey(args) + + return await apiClient.executeWithDashboardLink( + 'updateEnvironment', + args, + async (authToken: string, projectKey: string | undefined) => { + if (!projectKey) { + throw new Error(MISSING_PROJECT_KEY_ERROR) + } + return await handleZodiosValidationErrors( + () => updateEnvironment(authToken, projectKey, key, updateData), + 'updateEnvironment', + ) + }, + dashboardLinks.environment.settings, + ) +} + +/** + * Register environment tools with the MCP server using the new direct registration pattern. + * Listing environments and reading SDK keys are covered by select_project. + */ +export function registerEnvironmentTools( + serverInstance: DevCycleMCPServerInstance, + apiClient: IDevCycleApiClient, +): void { + serverInstance.registerToolWithErrorHandling( + 'create_environment', + { + description: [ + 'Create a new environment in the current project.', + 'Include dashboard link in the response.', + ].join('\n'), + annotations: { + title: 'Create Environment', + }, + inputSchema: CreateEnvironmentArgsSchema.shape, + }, + async (args: any) => { + const validatedArgs = CreateEnvironmentArgsSchema.parse(args) + return await createEnvironmentHandler(validatedArgs, apiClient) + }, + ) + + serverInstance.registerToolWithErrorHandling( + 'update_environment', + { + description: [ + 'Update an existing environment.', + '⚠️ IMPORTANT: Environment changes can affect how features are served, including in production.', + 'Always confirm with the user before updating a production environment.', + 'Include dashboard link in the response.', + ].join('\n'), + annotations: { + title: 'Update Environment', + destructiveHint: true, + }, + inputSchema: UpdateEnvironmentArgsSchema.shape, + }, + async (args: any) => { + const validatedArgs = UpdateEnvironmentArgsSchema.parse(args) + return await updateEnvironmentHandler(validatedArgs, apiClient) + }, + ) +} diff --git a/src/mcp/tools/index.ts b/src/mcp/tools/index.ts index c110edd5..ca464fbc 100644 --- a/src/mcp/tools/index.ts +++ b/src/mcp/tools/index.ts @@ -8,6 +8,8 @@ import { registerFeatureTools } from './featureTools' import { registerResultsTools } from './resultsTools' import { registerSelfTargetingTools } from './selfTargetingTools' import { registerVariableTools } from './variableTools' +import { registerCustomPropertiesTools } from './customPropertiesTools' +import { registerEnvironmentTools } from './environmentTools' import { registerLocalProjectTools } from './localProjectTools' import { DevCycleApiClient } from '../utils/api' import { registerInstallTools } from './installTools' @@ -32,6 +34,8 @@ export function registerAllToolsWithServer( registerResultsTools(serverInstance, apiClient) registerSelfTargetingTools(serverInstance, apiClient) registerVariableTools(serverInstance, apiClient) + registerCustomPropertiesTools(serverInstance, apiClient) + registerEnvironmentTools(serverInstance, apiClient) } export type { IDevCycleApiClient } from '../api/interface' diff --git a/src/mcp/types.ts b/src/mcp/types.ts index 3282899e..4605f81f 100644 --- a/src/mcp/types.ts +++ b/src/mcp/types.ts @@ -276,6 +276,7 @@ export const GetSdkKeysArgsSchema = z.object({ }) export const CreateEnvironmentArgsSchema = CreateEnvironmentDto.extend({ + ...ProjectKeyArgShape, key: CreateEnvironmentDto.shape.key.describe('Unique environment key'), color: CreateEnvironmentDto.shape.color.describe( 'Environment color in hex format (e.g., #FF0000)', @@ -283,6 +284,7 @@ export const CreateEnvironmentArgsSchema = CreateEnvironmentDto.extend({ }) export const UpdateEnvironmentArgsSchema = UpdateEnvironmentDto.extend({ + ...ProjectKeyArgShape, key: z.string().describe('key to identify environment to update'), color: UpdateEnvironmentDto.shape.color .describe('color in hex format (e.g., #FF0000)') @@ -545,6 +547,7 @@ export const ProjectTotalEvaluationsQuerySchema = GetProjectTotalEvaluationsArgsSchema.omit({ projectKey: true }) export const ListCustomPropertiesArgsSchema = z.object({ + ...ProjectKeyArgShape, page: z .number() .min(1) @@ -575,26 +578,47 @@ export const ListCustomPropertiesArgsSchema = z.object({ .min(3) .optional() .describe('Search term to filter by "name" or "key"'), - createdBy: z.string().optional().describe('Filter by creator user ID'), + type: z + .enum(['String', 'Boolean', 'Number']) + .optional() + .describe('Filter by custom property type'), }) -export const UpsertCustomPropertyArgsSchema = CreateCustomPropertyDto.extend({ +const CUSTOM_PROPERTY_KEY_HINT = + 'The key in the user\'s "customData" that the SDK sends, e.g. "plan" for { customData: { plan: "pro" } }' + +// `schema` (enum validation) is omitted: the OpenAPI spec types an enum's +// allowed `value` as an object, so real string/number values fail validation. +export const CreateCustomPropertyArgsSchema = CreateCustomPropertyDto.omit({ + schema: true, +}).extend({ + ...ProjectKeyArgShape, key: CreateCustomPropertyDto.shape.key.describe( - 'Unique custom property key', + 'Unique custom property key used to reference it in DevCycle', + ), + type: CreateCustomPropertyDto.shape.type.describe( + 'Data type of the custom property value', ), propertyKey: CreateCustomPropertyDto.shape.propertyKey.describe( - 'Property key to associate with the custom property', + CUSTOM_PROPERTY_KEY_HINT, ), }) -export const UpdateCustomPropertyArgsSchema = UpdateCustomPropertyDto.extend({ +export const UpdateCustomPropertyArgsSchema = UpdateCustomPropertyDto.omit({ + schema: true, +}).extend({ + ...ProjectKeyArgShape, key: z .string() .max(100) .regex(/^[a-z0-9-_.]+$/) - .describe('key to identify property to update'), + .describe('key to identify the custom property to update'), + propertyKey: UpdateCustomPropertyDto.shape.propertyKey.describe( + CUSTOM_PROPERTY_KEY_HINT, + ), }) export const DeleteCustomPropertyArgsSchema = z.object({ - key: z.string().describe('key to identify property to delete'), + ...ProjectKeyArgShape, + key: z.string().describe('key to identify the custom property to delete'), })