Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding UiEditable param to createService #529

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/spicy-buckets-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-labs/serverless-api": minor
"@twilio-labs/plugin-serverless": minor
---

Adding UiEditable param to createService
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
Loading