1 | /*
|
2 | * Copyright 2019 Adobe. All rights reserved.
|
3 | * This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
4 | * you may not use this file except in compliance with the License. You may obtain a copy
|
5 | * of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6 | *
|
7 | * Unless required by applicable law or agreed to in writing, software distributed under
|
8 | * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
9 | * OF ANY KIND, either express or implied. See the License for the specific language
|
10 | * governing permissions and limitations under the License.
|
11 | */
|
12 |
|
13 | /**
|
14 | * The Fastly Domain API.
|
15 | *
|
16 | * @see https://docs.fastly.com/api/config#domain
|
17 | * @type {DomainAPI}
|
18 | */
|
19 | class DomainAPI {
|
20 | constructor(base) {
|
21 | Object.assign(this, {
|
22 | service_id: base.service_id,
|
23 | request: base.request,
|
24 | getVersion: base.getVersion,
|
25 | });
|
26 | }
|
27 |
|
28 | /**
|
29 | * Checks the status of all domains for a particular service and version.
|
30 | *
|
31 | * @param {string} version - The current version of a service.
|
32 | * @param {string} name - The name of the domain.
|
33 | * @see https://docs.fastly.com/api/config#domain_30a3f14c9a0ce5730757d39983ab7dc6
|
34 | * @returns {Promise} The response object representing the completion or failure.
|
35 | */
|
36 | async domainCheck(version, name) {
|
37 | return this.request.get(`/service/${this.service_id}/version/${await this.getVersion(version, 'latest')}/domain/${name}/check`);
|
38 | }
|
39 |
|
40 | /**
|
41 | * Checks the status of all domains for a particular service and version.
|
42 | *
|
43 | * @param {string} version - The current version of a service.
|
44 | * @see https://docs.fastly.com/api/config#domain_e33a599694c3316f00b6b8d53a2db7d9
|
45 | * @example
|
46 | * instance.domainCheckAll('182')
|
47 | .then(res => {
|
48 | console.log(res.data);
|
49 | })
|
50 | .catch(err => {
|
51 | console.log(err.message);
|
52 | });
|
53 | * @returns {Promise} The response object representing the completion or failure.
|
54 | */
|
55 | async domainCheckAll(version) {
|
56 | return this.request.get(`/service/${this.service_id}/version/${await this.getVersion(version, 'latest')}/domain/check_all`);
|
57 | }
|
58 |
|
59 | /**
|
60 | * List all the domains for a particular service and version.
|
61 | *
|
62 | * @param {string} version - The current version of a service.
|
63 | * @see https://docs.fastly.com/api/config#domain_6d340186666771f022ca20f81609d03d
|
64 | * @example
|
65 | * instance.readDomains('182')
|
66 | .then(res => {
|
67 | console.log(res.data);
|
68 | })
|
69 | .catch(err => {
|
70 | console.log(err.message);
|
71 | });
|
72 |
|
73 | * @returns {Promise} The response object representing the completion or failure.
|
74 | */
|
75 | async readDomains(version) {
|
76 | return this.request.get(`/service/${this.service_id}/version/${await this.getVersion(version, 'latest')}/domain`);
|
77 | }
|
78 |
|
79 | /**
|
80 | * List all the domains for a particular service and version.
|
81 | *
|
82 | * @param {string} version - The current version of a service.
|
83 | * @param {string} name - The domain name.
|
84 | * @see https://docs.fastly.com/api/config#domain_f1b5fab17a0729daeeaf7594b47759c5
|
85 | * @returns {Promise} The response object representing the completion or failure.
|
86 | */
|
87 | async readDomain(version, name) {
|
88 | return this.request.get(`/service/${this.service_id}/version/${await this.getVersion(version, 'latest')}/domain/${name}`);
|
89 | }
|
90 |
|
91 | /**
|
92 | * List the domains within a service.
|
93 | *
|
94 | * @see https://docs.fastly.com/api/config#service_d5578a1e3bc75512711ddd0a58ce7a36
|
95 | * @param {string} [serviceId] - The service id.
|
96 | * @returns {Promise} The response object representing the completion or failure.
|
97 | */
|
98 | async readServiceDomains(serviceId = this.service_id) {
|
99 | return this.request.get(`/service/${serviceId}/domain`);
|
100 | }
|
101 |
|
102 | /**
|
103 | * Create a domain for a particular service and version.
|
104 | *
|
105 | * @see https://docs.fastly.com/api/config#domain_90345101274774ff1b84f0a7dd010b01
|
106 | * @param {string} version - The current version of a service.
|
107 | * @param {string} name - The domain name.
|
108 | * @param {string} comment - Optional comment.
|
109 | * @returns {Promise} The response object representing the completion or failure.
|
110 | */
|
111 | async createDomain(version, name, comment = '') {
|
112 | return this.request.post(`/service/${this.service_id}/version/${await this.getVersion(version, 'latest')}/domain`, {
|
113 | name,
|
114 | comment,
|
115 | });
|
116 | }
|
117 |
|
118 | /**
|
119 | * Update a domain for a particular service and version.
|
120 | *
|
121 | * @see https://docs.fastly.com/api/config#domain_2ef42bd9b4c56c86b46dc0e36096ab10
|
122 | * @param {string} version - The current version of a service.
|
123 | * @param {string} oldName - The old name of the domain.
|
124 | * @param {string} name - The domain name.
|
125 | * @param {string} comment - Optional comment.
|
126 | * @returns {Promise} The response object representing the completion or failure.
|
127 | */
|
128 | async updateDomain(version, oldName, name, comment = '') {
|
129 | return this.request.put(`/service/${this.service_id}/version/${await this.getVersion(version, 'latest')}/domain/${oldName}`, {
|
130 | name,
|
131 | comment,
|
132 | });
|
133 | }
|
134 |
|
135 | /**
|
136 | * Delete the domain for a particular service and version.
|
137 | *
|
138 | * @see https://docs.fastly.com/api/config#domain_aab5a322f58df2b1db8dc276e8594a70
|
139 | * @param {string} version - The current version of a service.
|
140 | * @param {string} name - The domain name.
|
141 | * @returns {Promise} The response object representing the completion or failure.
|
142 | */
|
143 | async deleteDomain(version, name) {
|
144 | return this.request.delete(`/service/${this.service_id}/version/${await this.getVersion(version, 'latest')}/domain/${name}`);
|
145 | }
|
146 | }
|
147 |
|
148 | module.exports = DomainAPI;
|