Skip to content

Commit 76ea040

Browse files
committed
revert(environments): revert back to old unique_name annotation
There is currently no Friendly Name support and we are reverting back to the unique name of {domainSuffix}-environment to not confuse people with duplicate names. It's also what is mentioned in the doc examples
1 parent e4770c2 commit 76ea040

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

packages/serverless-api/src/api/environments.ts

+7-24
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,7 @@ const log = debug('twilio-serverless-api:environments');
1212
* @returns {string}
1313
*/
1414
function getUniqueNameFromSuffix(suffix: string): string {
15-
return suffix.length === 0 ? 'production' : suffix;
16-
}
17-
18-
/**
19-
* In old versions of the tool, environments were created with the unique name
20-
* "{domainSuffix}-environment" this function searches for that
21-
*
22-
* @param {EnvironmentResource[]} environments list of environment resources
23-
* @param {string} domainSuffix the domain suffix that is searched for
24-
* @returns {(EnvironmentResource | undefined)}
25-
*/
26-
function findLegacyEnvironments(
27-
environments: EnvironmentResource[],
28-
domainSuffix: string
29-
): EnvironmentResource | undefined {
30-
return environments.find(
31-
env => env.unique_name === `${domainSuffix}-environment`
32-
);
15+
return suffix.length === 0 ? 'production' : `${suffix}-environment`;
3316
}
3417

3518
/**
@@ -83,6 +66,7 @@ export async function createEnvironmentFromSuffix(
8366
body: {
8467
UniqueName: uniqueName,
8568
DomainSuffix: domainSuffix,
69+
// this property currently doesn't exist but for the future lets set it
8670
FriendlyName: `${uniqueName} Environment (Created by CLI)`,
8771
},
8872
});
@@ -125,19 +109,18 @@ export async function getEnvironmentFromSuffix(
125109
let env: EnvironmentResource | undefined;
126110
if (foundEnvironments.length > 1) {
127111
// this is an edge case where at one point you could create environments with the same domain suffix
112+
// we'll pick the one that suits our naming convention
128113
env = foundEnvironments.find(
129-
e => e.domain_suffix === domainSuffix && e.unique_name === domainSuffix
114+
e =>
115+
e.domain_suffix === domainSuffix &&
116+
e.unique_name === getUniqueNameFromSuffix(domainSuffix)
130117
);
131118
} else {
132119
env = foundEnvironments[0];
133120
}
134121

135122
if (!env) {
136-
// in the past the unique_name was set as `{domainSuffix}-environment`
137-
env = findLegacyEnvironments(environments, domainSuffix);
138-
if (!env) {
139-
throw new Error('Could not find environment');
140-
}
123+
throw new Error('Could not find environment');
141124
}
142125
return env;
143126
}

packages/serverless-api/src/types/serverless-api.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ export type Sid = string;
66

77
export interface ResourceBase {
88
sid: Sid;
9+
account_sid: Sid;
910
date_created: string;
1011
date_updated: string;
12+
url: string;
1113
}
1214

1315
export interface FunctionApiResource extends ResourceBase {
@@ -37,7 +39,6 @@ export interface ServiceList {
3739
export interface EnvironmentResource extends ResourceBase {
3840
unique_name: string;
3941
domain_name: string;
40-
friendly_name: string;
4142
build_sid: string;
4243
domain_suffix: string;
4344
}

0 commit comments

Comments
 (0)