|
1 | 1 | import "cross-fetch/polyfill"; // fetch api polyfill |
2 | | -import parse_url from "parse_url"; |
3 | 2 | import path from "path"; |
4 | 3 |
|
| 4 | +import parse_url from "parse_url"; |
| 5 | + |
5 | 6 | import request, { createEventSource } from "../api"; |
6 | 7 | import { getConfig } from "../config"; |
7 | 8 |
|
8 | 9 | import Activity from "./Activity"; |
9 | 10 | import Certificate from "./Certificate"; |
10 | 11 | import Domain from "./Domain"; |
11 | 12 | import Environment from "./Environment"; |
| 13 | +import EnvironmentDomain from "./EnvironmentDomain"; |
12 | 14 | import Integration from "./Integration"; |
13 | 15 | import ProjectAccess from "./ProjectAccess"; |
14 | 16 | import ProjectLevelVariable from "./ProjectLevelVariable"; |
@@ -50,6 +52,7 @@ export default class Project extends Ressource { |
50 | 52 | plan_uri = ""; |
51 | 53 | subscription: Subscription = new Subscription({}); |
52 | 54 | subscription_id = ""; |
| 55 | + environment_id = ""; |
53 | 56 | status = ""; |
54 | 57 | endpoint = ""; |
55 | 58 | repository: Repository = { |
@@ -211,6 +214,63 @@ export default class Project extends Ressource { |
211 | 214 | return Domain.query({ projectId: this.id, limit }, this.getLink("domains")); |
212 | 215 | } |
213 | 216 |
|
| 217 | + /** |
| 218 | + * Get a list of environment domains for the project. |
| 219 | + * |
| 220 | + * @param int limit |
| 221 | + * |
| 222 | + * @return EnvironmentDomain[] |
| 223 | + */ |
| 224 | + async getEnvironmentDomains(environmentId: string) { |
| 225 | + return EnvironmentDomain.query( |
| 226 | + { projectId: this.id, environmentId }, |
| 227 | + this.getLink(`environments/${environmentId}/domains`) |
| 228 | + ); |
| 229 | + } |
| 230 | + |
| 231 | + /** |
| 232 | + * Add a environmentDomain to the environment project. |
| 233 | + * |
| 234 | + * @param string name |
| 235 | + * @param string environmentId |
| 236 | + * @param string type |
| 237 | + * @param string replacement_for |
| 238 | + * @param array ssl |
| 239 | + * |
| 240 | + * @return Result |
| 241 | + */ |
| 242 | + async addEnvironmentDomain( |
| 243 | + name: string, |
| 244 | + environmentId: string, |
| 245 | + type = "replacement", |
| 246 | + replacement_for?: string, |
| 247 | + ssl?: never[] |
| 248 | + ) { |
| 249 | + const body: Partial<EnvironmentDomain> = { name, type, replacement_for }; |
| 250 | + |
| 251 | + if (ssl) { |
| 252 | + body.ssl = ssl; |
| 253 | + } |
| 254 | + |
| 255 | + if (replacement_for) { |
| 256 | + body.replacement_for = replacement_for; |
| 257 | + } else { |
| 258 | + body.is_default = true; |
| 259 | + } |
| 260 | + |
| 261 | + if (!replacement_for) { |
| 262 | + body.is_default = true; |
| 263 | + } |
| 264 | + body.type = type; |
| 265 | + |
| 266 | + const environmentDomain = new EnvironmentDomain( |
| 267 | + body, |
| 268 | + this.getLink(`environments/${environmentId}/domains`) |
| 269 | + ); |
| 270 | + |
| 271 | + return environmentDomain.save(); |
| 272 | + } |
| 273 | + |
214 | 274 | /** |
215 | 275 | * Get a single domain of the project. |
216 | 276 | * |
@@ -307,8 +367,8 @@ export default class Project extends Ressource { |
307 | 367 | * |
308 | 368 | * @return Activity[] |
309 | 369 | */ |
310 | | - getActivities(types: Array<string>, starts_at?: Date) { |
311 | | - const startsAt = starts_at?.toISOString() |
| 370 | + async getActivities(types: string[], starts_at?: Date) { |
| 371 | + const startsAt = starts_at?.toISOString(); |
312 | 372 | const params = { type: types, starts_at: startsAt }; |
313 | 373 |
|
314 | 374 | return Activity.query(params, `${this.getUri()}/activities`); |
|
0 commit comments