@@ -12,24 +12,7 @@ const log = debug('twilio-serverless-api:environments');
12
12
* @returns {string }
13
13
*/
14
14
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` ;
33
16
}
34
17
35
18
/**
@@ -83,6 +66,7 @@ export async function createEnvironmentFromSuffix(
83
66
body : {
84
67
UniqueName : uniqueName ,
85
68
DomainSuffix : domainSuffix ,
69
+ // this property currently doesn't exist but for the future lets set it
86
70
FriendlyName : `${ uniqueName } Environment (Created by CLI)` ,
87
71
} ,
88
72
} ) ;
@@ -125,19 +109,18 @@ export async function getEnvironmentFromSuffix(
125
109
let env : EnvironmentResource | undefined ;
126
110
if ( foundEnvironments . length > 1 ) {
127
111
// 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
128
113
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 )
130
117
) ;
131
118
} else {
132
119
env = foundEnvironments [ 0 ] ;
133
120
}
134
121
135
122
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' ) ;
141
124
}
142
125
return env ;
143
126
}
0 commit comments