Skip to content

Commit 4b50a67

Browse files
authored
feat(flags): expose region/edge flags (#137)
1 parent 76b0b6a commit 4b50a67

File tree

11 files changed

+91
-68
lines changed

11 files changed

+91
-68
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"author": "Dominik Kundel <[email protected]>",
3939
"license": "MIT",
4040
"dependencies": {
41-
"@twilio-labs/serverless-api": "^2.0.1",
41+
"@twilio-labs/serverless-api": "^3.0.0",
4242
"@twilio-labs/serverless-runtime-types": "^1.1.7",
4343
"@types/express": "^4.17.0",
4444
"@types/inquirer": "^6.0.3",

src/commands/activate.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import {
1414
logger,
1515
setLogLevelByName,
1616
} from '../utils/logger';
17-
import { ExternalCliOptions, sharedCliOptions } from './shared';
17+
import {
18+
ExternalCliOptions,
19+
sharedApiRelatedCliOptions,
20+
sharedCliOptions,
21+
} from './shared';
1822
import { CliInfo } from './types';
1923

2024
const debug = getDebugFunction('twilio-run:activate');
@@ -83,6 +87,7 @@ export async function handler(
8387
export const cliInfo: CliInfo = {
8488
options: {
8589
...sharedCliOptions,
90+
...sharedApiRelatedCliOptions,
8691
'service-sid': {
8792
type: 'string',
8893
describe: 'SID of the Twilio Serverless Service to deploy to',
@@ -108,17 +113,6 @@ export const cliInfo: CliInfo = {
108113
describe:
109114
'Promote build to the production environment (no domain suffix). Overrides environment flag',
110115
},
111-
'account-sid': {
112-
type: 'string',
113-
alias: 'u',
114-
describe:
115-
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
116-
},
117-
'auth-token': {
118-
type: 'string',
119-
describe:
120-
'Use a specific auth token for deployment. Uses fields from .env otherwise',
121-
},
122116
'create-environment': {
123117
type: 'boolean',
124118
describe: "Creates environment if it couldn't find it.",

src/commands/deploy.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import {
1818
logger,
1919
setLogLevelByName,
2020
} from '../utils/logger';
21-
import { ExternalCliOptions, sharedCliOptions } from './shared';
21+
import {
22+
ExternalCliOptions,
23+
sharedApiRelatedCliOptions,
24+
sharedCliOptions,
25+
} from './shared';
2226
import { CliInfo } from './types';
2327
import { constructCommandName, getFullCommand } from './utils';
2428

@@ -125,6 +129,7 @@ export async function handler(
125129
export const cliInfo: CliInfo = {
126130
options: {
127131
...sharedCliOptions,
132+
...sharedApiRelatedCliOptions,
128133
cwd: {
129134
type: 'string',
130135
describe: 'Sets the directory from which to deploy',
@@ -163,17 +168,6 @@ export const cliInfo: CliInfo = {
163168
describe:
164169
'DEPRECATED: Overrides the name of the project. Default: the name field in your package.json',
165170
},
166-
'account-sid': {
167-
type: 'string',
168-
alias: 'u',
169-
describe:
170-
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
171-
},
172-
'auth-token': {
173-
type: 'string',
174-
describe:
175-
'Use a specific auth token for deployment. Uses fields from .env otherwise',
176-
},
177171
env: {
178172
type: 'string',
179173
describe:

src/commands/list.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010
logger,
1111
setLogLevelByName,
1212
} from '../utils/logger';
13-
import { ExternalCliOptions, sharedCliOptions } from './shared';
13+
import {
14+
ExternalCliOptions,
15+
sharedApiRelatedCliOptions,
16+
sharedCliOptions,
17+
} from './shared';
1418
import { CliInfo } from './types';
1519
import { getFullCommand } from './utils';
1620

@@ -74,6 +78,7 @@ export const cliInfo: CliInfo = {
7478
},
7579
options: {
7680
...sharedCliOptions,
81+
...sharedApiRelatedCliOptions,
7782
'service-name': {
7883
type: 'string',
7984
alias: 'n',
@@ -108,17 +113,6 @@ export const cliInfo: CliInfo = {
108113
describe: 'The environment to list variables for',
109114
default: 'dev',
110115
},
111-
'account-sid': {
112-
type: 'string',
113-
alias: 'u',
114-
describe:
115-
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
116-
},
117-
'auth-token': {
118-
type: 'string',
119-
describe:
120-
'Use a specific auth token for deployment. Uses fields from .env otherwise',
121-
},
122116
'service-sid': {
123117
type: 'string',
124118
describe: 'Specific Serverless Service SID to run list for',

src/commands/logs.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import {
1313
logger,
1414
setLogLevelByName,
1515
} from '../utils/logger';
16-
import { ExternalCliOptions, sharedCliOptions } from './shared';
16+
import {
17+
ExternalCliOptions,
18+
sharedApiRelatedCliOptions,
19+
sharedCliOptions,
20+
} from './shared';
1721
import { CliInfo } from './types';
1822
import { getFullCommand } from './utils';
1923

@@ -78,6 +82,7 @@ export async function handler(
7882
export const cliInfo: CliInfo = {
7983
options: {
8084
...sharedCliOptions,
85+
...sharedApiRelatedCliOptions,
8186
'service-sid': {
8287
type: 'string',
8388
describe: 'Specific Serverless Service SID to retrieve logs for',
@@ -102,17 +107,6 @@ export const cliInfo: CliInfo = {
102107
describe: 'Output the log in a different format',
103108
choices: ['', 'json'],
104109
},
105-
'account-sid': {
106-
type: 'string',
107-
alias: 'u',
108-
describe:
109-
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
110-
},
111-
'auth-token': {
112-
type: 'string',
113-
describe:
114-
'Use a specific auth token for deployment. Uses fields from .env otherwise',
115-
},
116110
env: {
117111
type: 'string',
118112
describe:

src/commands/shared.ts

+27-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ export type SharedFlags = BaseFlags & {
1010
cwd?: string;
1111
};
1212

13-
export type SharedFlagsWithCrdentials = SharedFlags & {
13+
export type SharedFlagsWithCredentials = SharedFlags & {
1414
accountSid?: string;
1515
authToken?: string;
1616
env?: string;
17+
region?: string;
18+
edge?: string;
1719
};
1820

1921
export type ExternalCliOptions = {
@@ -36,6 +38,30 @@ export const baseCliOptions: { [key: string]: Options } = {
3638
},
3739
};
3840

41+
export const sharedApiRelatedCliOptions: { [key: string]: Options } = {
42+
region: {
43+
type: 'string',
44+
hidden: true,
45+
describe: 'Twilio API Region',
46+
},
47+
edge: {
48+
type: 'string',
49+
hidden: true,
50+
describe: 'Twilio API Region',
51+
},
52+
'account-sid': {
53+
type: 'string',
54+
alias: 'u',
55+
describe:
56+
'A specific account SID to be used for deployment. Uses fields in .env otherwise',
57+
},
58+
'auth-token': {
59+
type: 'string',
60+
describe:
61+
'Use a specific auth token for deployment. Uses fields from .env otherwise',
62+
},
63+
};
64+
3965
export const sharedCliOptions: { [key: string]: Options } = {
4066
...baseCliOptions,
4167
config: {

src/config/activate.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import checkForValidServiceSid from '../checks/check-service-sid';
55
import { cliInfo } from '../commands/activate';
66
import {
77
ExternalCliOptions,
8-
SharedFlagsWithCrdentials,
8+
SharedFlagsWithCredentials,
99
} from '../commands/shared';
1010
import { getFullCommand } from '../commands/utils';
1111
import { readSpecializedConfig } from './global';
@@ -19,7 +19,7 @@ type ActivateConfig = ApiActivateConfig & {
1919
};
2020

2121
export type ActivateCliFlags = Arguments<
22-
SharedFlagsWithCrdentials & {
22+
SharedFlagsWithCredentials & {
2323
cwd?: string;
2424
serviceSid?: string;
2525
buildSid?: string;
@@ -64,6 +64,8 @@ export async function getConfigFromFlags(
6464

6565
const command = getFullCommand(flags);
6666
const serviceSid = checkForValidServiceSid(command, flags.serviceSid);
67+
const region = flags.region;
68+
const edge = flags.edge;
6769

6870
return {
6971
cwd,
@@ -75,5 +77,7 @@ export async function getConfigFromFlags(
7577
buildSid: flags.buildSid,
7678
targetEnvironment: flags.environment,
7779
sourceEnvironment: flags.sourceEnvironment,
80+
region,
81+
edge,
7882
};
7983
}

src/config/deploy.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Arguments } from 'yargs';
44
import { cliInfo } from '../commands/deploy';
55
import {
66
ExternalCliOptions,
7-
SharedFlagsWithCrdentials,
7+
SharedFlagsWithCredentials,
88
} from '../commands/shared';
99
import { deprecateFunctionsEnv } from '../commands/utils';
1010
import { getFunctionServiceSid } from '../serverless-api/utils';
@@ -18,7 +18,7 @@ import {
1818
import { mergeFlagsAndConfig } from './utils/mergeFlagsAndConfig';
1919

2020
export type DeployCliFlags = Arguments<
21-
SharedFlagsWithCrdentials & {
21+
SharedFlagsWithCredentials & {
2222
serviceSid?: string;
2323
functionsEnv?: string;
2424
environment: string;
@@ -105,6 +105,9 @@ export async function getConfigFromFlags(
105105
);
106106
}
107107

108+
const region = flags.region;
109+
const edge = flags.edge;
110+
108111
return {
109112
cwd,
110113
envPath,
@@ -121,5 +124,7 @@ export async function getConfigFromFlags(
121124
assetsFolderName: flags.assetsFolder,
122125
noAssets: !flags.assets,
123126
noFunctions: !flags.functions,
127+
region,
128+
edge,
124129
};
125130
}

src/config/list.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Arguments } from 'yargs';
77
import { cliInfo } from '../commands/list';
88
import {
99
ExternalCliOptions,
10-
SharedFlagsWithCrdentials,
10+
SharedFlagsWithCredentials,
1111
} from '../commands/shared';
1212
import { getFunctionServiceSid } from '../serverless-api/utils';
1313
import { readSpecializedConfig } from './global';
@@ -21,7 +21,7 @@ export type ListConfig = ApiListConfig & {
2121
};
2222

2323
export type ListCliFlags = Arguments<
24-
SharedFlagsWithCrdentials & {
24+
SharedFlagsWithCredentials & {
2525
types: string;
2626
projectName?: string;
2727
serviceName?: string;
@@ -67,6 +67,8 @@ export async function getConfigFromFlags(
6767
let serviceName = await getServiceNameFromFlags(flags);
6868

6969
const types = flags.types.split(',').map(trim) as ListOptions[];
70+
const region = flags.region;
71+
const edge = flags.edge;
7072

7173
return {
7274
cwd,
@@ -80,5 +82,7 @@ export async function getConfigFromFlags(
8082
: undefined,
8183
extendedOutput: flags.extendedOutput,
8284
types,
85+
region,
86+
edge,
8387
};
8488
}

src/config/logs.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
import { LogsConfig as ApiLogsConfig } from '@twilio-labs/serverless-api';
1+
import {
2+
ClientConfig,
3+
LogsConfig as ApiLogsConfig,
4+
} from '@twilio-labs/serverless-api';
25
import path from 'path';
36
import { Arguments } from 'yargs';
47
import checkForValidServiceSid from '../checks/check-service-sid';
58
import { cliInfo } from '../commands/logs';
69
import {
710
ExternalCliOptions,
8-
SharedFlagsWithCrdentials,
11+
SharedFlagsWithCredentials,
912
} from '../commands/shared';
1013
import { getFullCommand } from '../commands/utils';
1114
import { readSpecializedConfig } from './global';
1215
import { getCredentialsFromFlags } from './utils';
1316
import { mergeFlagsAndConfig } from './utils/mergeFlagsAndConfig';
1417

15-
export type LogsConfig = ApiLogsConfig & {
16-
cwd: string;
17-
accountSid: string;
18-
authToken: string;
19-
properties?: string[];
20-
outputFormat?: string;
21-
};
18+
export type LogsConfig = ClientConfig &
19+
ApiLogsConfig & {
20+
cwd: string;
21+
accountSid: string;
22+
authToken: string;
23+
properties?: string[];
24+
outputFormat?: string;
25+
};
2226

2327
export type LogsCliFlags = Arguments<
24-
SharedFlagsWithCrdentials & {
28+
SharedFlagsWithCredentials & {
2529
cwd?: string;
2630
environment?: string;
2731
serviceSid?: string;
@@ -61,6 +65,8 @@ export async function getConfigFromFlags(
6165
const command = getFullCommand(flags);
6266
const serviceSid = checkForValidServiceSid(command, flags.serviceSid);
6367
const outputFormat = flags.outputFormat || externalCliOptions?.outputFormat;
68+
const region = flags.region;
69+
const edge = flags.edge;
6470

6571
return {
6672
cwd,
@@ -71,5 +77,7 @@ export async function getConfigFromFlags(
7177
outputFormat,
7278
filterByFunction: flags.functionSid,
7379
tail: flags.tail,
80+
region,
81+
edge,
7482
};
7583
}

src/config/utils/credentials.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
ExternalCliOptions,
3-
SharedFlagsWithCrdentials,
3+
SharedFlagsWithCredentials,
44
} from '../../commands/shared';
55
import { getDebugFunction } from '../../utils/logger';
66
import { readLocalEnvFile } from './env';
@@ -24,7 +24,7 @@ export type Credentials = {
2424
* @param externalCliOptions Any external information for example passed by the Twilio CLI
2525
*/
2626
export async function getCredentialsFromFlags<
27-
T extends SharedFlagsWithCrdentials
27+
T extends SharedFlagsWithCredentials
2828
>(flags: T, externalCliOptions?: ExternalCliOptions): Promise<Credentials> {
2929
// default Twilio CLI credentials (4) or empty string (5)
3030
let accountSid =

0 commit comments

Comments
 (0)