Skip to content

Commit

Permalink
feat(@twilio-labs/serverless-api): adding UiEditable param to createS…
Browse files Browse the repository at this point in the history
…ervice
  • Loading branch information
Th3R3p0 committed Dec 11, 2024
1 parent 255da3b commit 196151b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/plugin-serverless/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function createExternalCliOptions(flags, twilioClient) {
const pluginInfo = {
version: pkgJson.version,
name: pkgJson.name,
uiEditable: pkgJson.uiEditable,
};

if (
Expand Down
9 changes: 6 additions & 3 deletions packages/serverless-api/src/api/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@ const log = debug('twilio-serverless-api:services');
* @export
* @param {string} serviceName the unique name for the service
* @param {TwilioServerlessApiClient} client API client
* @param {boolean} uiEditable Whether the Service's properties and subresources can be edited via the UI. The default value is false.
* @returns {Promise<string>}
*/
export async function createService(
serviceName: string,
client: TwilioServerlessApiClient
client: TwilioServerlessApiClient,
uiEditable: boolean = false
): Promise<string> {
try {
const resp = await client.request('post', 'Services', {
form: {
UniqueName: serviceName,
FriendlyName: serviceName,
IncludeCredentials: true,
UiEditable: uiEditable,
},
});
const service = (resp.body as unknown) as ServiceResource;
const service = resp.body as unknown as ServiceResource;

return service.sid;
} catch (err) {
Expand Down Expand Up @@ -82,7 +85,7 @@ export async function getService(
): Promise<ServiceResource> {
try {
const resp = await client.request('get', `Services/${sid}`);
return (resp.body as unknown) as ServiceResource;
return resp.body as unknown as ServiceResource;
} catch (err) {
log('%O', new ClientApiError(err));
throw err;
Expand Down
15 changes: 7 additions & 8 deletions packages/serverless-api/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,8 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
*/
async activateBuild(activateConfig: ActivateConfig): Promise<ActivateResult> {
try {
let {
buildSid,
targetEnvironment,
serviceSid,
sourceEnvironment,
env,
} = activateConfig;
let { buildSid, targetEnvironment, serviceSid, sourceEnvironment, env } =
activateConfig;

if (!buildSid && !sourceEnvironment) {
const error = new Error(
Expand Down Expand Up @@ -630,7 +625,11 @@ export class TwilioServerlessApiClient extends events.EventEmitter {
message: 'Creating Service',
});
try {
serviceSid = await createService(config.serviceName, this);
serviceSid = await createService(
config.serviceName,
this,
config.uiEditable
);
} catch (err) {
const alternativeServiceSid = await findServiceSid(
config.serviceName,
Expand Down
4 changes: 4 additions & 0 deletions packages/serverless-api/src/types/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type DeployProjectConfigBase = {
* Version of Node.js to deploy with in Twilio Runtime. Can be "node18"
*/
runtime?: string;
/**
* Whether the Service's properties and subresources can be edited via the UI. The default value is false.
*/
uiEditable?: boolean;
};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/serverless-api/src/types/serverless-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface ServiceResource extends UpdateableResourceBase {
unique_name: string;
include_credentials: boolean;
friendly_name: string;
ui_editable?: boolean;
}

export interface ServiceList extends BaseList<'services'> {
Expand Down

0 comments on commit 196151b

Please sign in to comment.