diff --git a/package.json b/package.json index 4312158..5c17d92 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "polyapi", - "version": "0.24.19", + "version": "0.24.20", "description": "Poly is a CLI tool to help create and manage your Poly definitions.", "license": "MIT", "repository": { diff --git a/src/api.ts b/src/api.ts index a495af2..e7290d5 100644 --- a/src/api.ts +++ b/src/api.ts @@ -25,6 +25,7 @@ import { Specification, SpecificationInputDto, TosDto, + Visibility, WebhookHandleBasicDto, WebhookHandleDescriptionGenerationDto, WebhookHandleDto, @@ -95,6 +96,7 @@ export const createOrUpdateServerFunction = async ( name: string, description: string | null, code: string, + visibility: string, typeSchemas: Record, requirements: string[], other?: Record, @@ -108,6 +110,7 @@ export const createOrUpdateServerFunction = async ( name, description, code, + visibility, typeSchemas, requirements, executionApiKey, @@ -172,6 +175,7 @@ export const createOrUpdateClientFunction = async ( name: string, description: string | null, code: string, + visibility: string, typeSchemas: Record, other?: Record, ) => { @@ -183,6 +187,7 @@ export const createOrUpdateClientFunction = async ( name, description, code, + visibility, typeSchemas, ...other, }, diff --git a/src/cli.ts b/src/cli.ts index 75d9e16..43f78c0 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -240,6 +240,10 @@ void yargs .option('cache-poly-library', { describe: 'Server function only - cache the poly library to improve function performance', type: 'boolean', + }) + .option('visibility', { + describe: 'Specifies the visibility of a function. Options: PUBLIC, TENANT, ENVIRONMENT. Case insensitive', + type: 'string', }), async ({ name, @@ -252,9 +256,11 @@ void yargs generateContexts, executionApiKey, cachePolyLibrary, + visibility, }) => { const logsEnabled = logs === 'enabled' ? true : logs === 'disabled' ? false : undefined; + visibility = visibility ? visibility.toUpperCase() : "ENVIRONMENT"; const err = !name ? 'Missing function name.' : !file @@ -273,7 +279,9 @@ void yargs ? 'Invalid value for `execution-api-key`. Must be a valid PolyAPI Key.' : cachePolyLibrary && !server ? 'Option `cache-poly-library` is only for server functions (--server).' - : ''; + : !["PUBLIC", "TENANT", "ENVIRONMENT"].includes(visibility) + ? 'Option `visibility` must be either PUBLIC, TENANT, or ENVIRONMENT. Case insensitive.' + : ''; if (err) { shell.echo(chalk.redBright('ERROR:'), err); yargs.showHelp(); @@ -294,6 +302,7 @@ void yargs generateContexts, executionApiKey, cachePolyLibrary, + visibility, ); }, ); diff --git a/src/commands/function.ts b/src/commands/function.ts index 65e0a54..e54c4ea 100644 --- a/src/commands/function.ts +++ b/src/commands/function.ts @@ -4,6 +4,7 @@ import shell from 'shelljs'; import { CreateServerCustomFunctionResponseDto, FunctionDetailsDto, + Visibility, } from '../types'; import { createOrUpdateClientFunction, @@ -31,6 +32,7 @@ export const addOrUpdateCustomFunction = async ( generateContexts: string | undefined, executionApiKey: string | null | undefined, cachePolyLibrary: boolean | undefined, + visibility: string | undefined, ) => { loadConfig(polyPath); @@ -97,12 +99,12 @@ export const addOrUpdateCustomFunction = async ( if (generateContexts) { other.generateContexts = generateContexts.split(','); } if (logsEnabled !== undefined) other.logsEnabled = logsEnabled; if (cachePolyLibrary !== undefined) other.cachePolyLibrary = cachePolyLibrary; - customFunction = await createOrUpdateServerFunction( context, name, description, code, + visibility, typeSchemas, dependencies, other, @@ -138,6 +140,7 @@ export const addOrUpdateCustomFunction = async ( name, description, code, + visibility, typeSchemas, ); shell.echo(chalk.green('DONE')); diff --git a/src/commands/sync.ts b/src/commands/sync.ts index df3494f..d5fd025 100644 --- a/src/commands/sync.ts +++ b/src/commands/sync.ts @@ -82,6 +82,7 @@ const syncDeployableAndGetId = async (deployable, code) => { deployable.name, deployable.description, code, + deployable.config.visibility, deployable.typeSchemas, deployable.dependencies, deployable.config, @@ -94,6 +95,7 @@ const syncDeployableAndGetId = async (deployable, code) => { deployable.name, deployable.description, code, + deployable.config.visibility, deployable.typeSchemas, deployable.config, )