|
| 1 | +// This file was automatically generated. DO NOT EDIT. |
| 2 | +// If you have any remark or suggestion do not hesitate to open an issue. |
| 3 | +import { |
| 4 | + API as ParentAPI, |
| 5 | + enrichForPagination, |
| 6 | + urlParams, |
| 7 | + validatePathParam, |
| 8 | + waitForResource, |
| 9 | +} from '../../../bridge' |
| 10 | +import type { Region, WaitForOptions } from '../../../bridge' |
| 11 | +import { HOSTING_TRANSIENT_STATUSES } from './content.gen' |
| 12 | +import { |
| 13 | + marshalCreateHostingRequest, |
| 14 | + marshalUpdateHostingRequest, |
| 15 | + unmarshalDnsRecords, |
| 16 | + unmarshalHosting, |
| 17 | + unmarshalListHostingsResponse, |
| 18 | + unmarshalListOffersResponse, |
| 19 | +} from './marshalling.gen' |
| 20 | +import type { |
| 21 | + CreateHostingRequest, |
| 22 | + DeleteHostingRequest, |
| 23 | + DnsRecords, |
| 24 | + GetDomainDnsRecordsRequest, |
| 25 | + GetHostingRequest, |
| 26 | + Hosting, |
| 27 | + ListHostingsRequest, |
| 28 | + ListHostingsResponse, |
| 29 | + ListOffersRequest, |
| 30 | + ListOffersResponse, |
| 31 | + RestoreHostingRequest, |
| 32 | + UpdateHostingRequest, |
| 33 | +} from './types.gen' |
| 34 | + |
| 35 | +const jsonContentHeaders = { |
| 36 | + 'Content-Type': 'application/json; charset=utf-8', |
| 37 | +} |
| 38 | + |
| 39 | +/** Webhosting API. */ |
| 40 | +export class API extends ParentAPI { |
| 41 | + /** Lists the available regions of the API. */ |
| 42 | + public static readonly LOCALITIES: Region[] = ['fr-par'] |
| 43 | + |
| 44 | + /** |
| 45 | + * Create a hosting |
| 46 | + * |
| 47 | + * @param request - The request {@link CreateHostingRequest} |
| 48 | + * @returns A Promise of Hosting |
| 49 | + */ |
| 50 | + createHosting = (request: Readonly<CreateHostingRequest>) => |
| 51 | + this.client.fetch<Hosting>( |
| 52 | + { |
| 53 | + body: JSON.stringify( |
| 54 | + marshalCreateHostingRequest(request, this.client.settings), |
| 55 | + ), |
| 56 | + headers: jsonContentHeaders, |
| 57 | + method: 'POST', |
| 58 | + path: `/webhosting/v1alpha1/regions/${validatePathParam( |
| 59 | + 'region', |
| 60 | + request.region ?? this.client.settings.defaultRegion, |
| 61 | + )}/hostings`, |
| 62 | + }, |
| 63 | + unmarshalHosting, |
| 64 | + ) |
| 65 | + |
| 66 | + protected pageOfListHostings = ( |
| 67 | + request: Readonly<ListHostingsRequest> = {}, |
| 68 | + ) => |
| 69 | + this.client.fetch<ListHostingsResponse>( |
| 70 | + { |
| 71 | + method: 'GET', |
| 72 | + path: `/webhosting/v1alpha1/regions/${validatePathParam( |
| 73 | + 'region', |
| 74 | + request.region ?? this.client.settings.defaultRegion, |
| 75 | + )}/hostings`, |
| 76 | + urlParams: urlParams( |
| 77 | + ['domain', request.domain], |
| 78 | + ['order_by', request.orderBy ?? 'created_at_asc'], |
| 79 | + ['organization_id', request.organizationId], |
| 80 | + ['page', request.page], |
| 81 | + [ |
| 82 | + 'page_size', |
| 83 | + request.pageSize ?? this.client.settings.defaultPageSize, |
| 84 | + ], |
| 85 | + ['project_id', request.projectId], |
| 86 | + ['statuses', request.statuses], |
| 87 | + ['tags', request.tags], |
| 88 | + ), |
| 89 | + }, |
| 90 | + unmarshalListHostingsResponse, |
| 91 | + ) |
| 92 | + |
| 93 | + /** |
| 94 | + * List all hostings |
| 95 | + * |
| 96 | + * @param request - The request {@link ListHostingsRequest} |
| 97 | + * @returns A Promise of ListHostingsResponse |
| 98 | + */ |
| 99 | + listHostings = (request: Readonly<ListHostingsRequest> = {}) => |
| 100 | + enrichForPagination('hostings', this.pageOfListHostings, request) |
| 101 | + |
| 102 | + /** |
| 103 | + * Get the details of a Hosting with the given ID. |
| 104 | + * |
| 105 | + * @param request - The request {@link GetHostingRequest} |
| 106 | + * @returns A Promise of Hosting |
| 107 | + */ |
| 108 | + getHosting = (request: Readonly<GetHostingRequest>) => |
| 109 | + this.client.fetch<Hosting>( |
| 110 | + { |
| 111 | + method: 'GET', |
| 112 | + path: `/webhosting/v1alpha1/regions/${validatePathParam( |
| 113 | + 'region', |
| 114 | + request.region ?? this.client.settings.defaultRegion, |
| 115 | + )}/hostings/${validatePathParam('hostingId', request.hostingId)}`, |
| 116 | + }, |
| 117 | + unmarshalHosting, |
| 118 | + ) |
| 119 | + |
| 120 | + /** |
| 121 | + * Waits for {@link Hosting} to be in a final state. |
| 122 | + * |
| 123 | + * @param request - The request {@link GetHostingRequest} |
| 124 | + * @param options - The waiting options |
| 125 | + * @returns A Promise of Hosting |
| 126 | + */ |
| 127 | + waitForHosting = ( |
| 128 | + request: Readonly<GetHostingRequest>, |
| 129 | + options?: Readonly<WaitForOptions<Hosting>>, |
| 130 | + ) => |
| 131 | + waitForResource( |
| 132 | + options?.stop ?? |
| 133 | + (res => |
| 134 | + Promise.resolve(!HOSTING_TRANSIENT_STATUSES.includes(res.status))), |
| 135 | + this.getHosting, |
| 136 | + request, |
| 137 | + options, |
| 138 | + ) |
| 139 | + |
| 140 | + /** |
| 141 | + * Update a hosting |
| 142 | + * |
| 143 | + * @param request - The request {@link UpdateHostingRequest} |
| 144 | + * @returns A Promise of Hosting |
| 145 | + */ |
| 146 | + updateHosting = (request: Readonly<UpdateHostingRequest>) => |
| 147 | + this.client.fetch<Hosting>( |
| 148 | + { |
| 149 | + body: JSON.stringify( |
| 150 | + marshalUpdateHostingRequest(request, this.client.settings), |
| 151 | + ), |
| 152 | + headers: jsonContentHeaders, |
| 153 | + method: 'PATCH', |
| 154 | + path: `/webhosting/v1alpha1/regions/${validatePathParam( |
| 155 | + 'region', |
| 156 | + request.region ?? this.client.settings.defaultRegion, |
| 157 | + )}/hostings/${validatePathParam('hostingId', request.hostingId)}`, |
| 158 | + }, |
| 159 | + unmarshalHosting, |
| 160 | + ) |
| 161 | + |
| 162 | + /** |
| 163 | + * Delete a hosting with the given ID. |
| 164 | + * |
| 165 | + * @param request - The request {@link DeleteHostingRequest} |
| 166 | + * @returns A Promise of Hosting |
| 167 | + */ |
| 168 | + deleteHosting = (request: Readonly<DeleteHostingRequest>) => |
| 169 | + this.client.fetch<Hosting>( |
| 170 | + { |
| 171 | + method: 'DELETE', |
| 172 | + path: `/webhosting/v1alpha1/regions/${validatePathParam( |
| 173 | + 'region', |
| 174 | + request.region ?? this.client.settings.defaultRegion, |
| 175 | + )}/hostings/${validatePathParam('hostingId', request.hostingId)}`, |
| 176 | + }, |
| 177 | + unmarshalHosting, |
| 178 | + ) |
| 179 | + |
| 180 | + /** |
| 181 | + * Restore a hosting with the given ID. |
| 182 | + * |
| 183 | + * @param request - The request {@link RestoreHostingRequest} |
| 184 | + * @returns A Promise of Hosting |
| 185 | + */ |
| 186 | + restoreHosting = (request: Readonly<RestoreHostingRequest>) => |
| 187 | + this.client.fetch<Hosting>( |
| 188 | + { |
| 189 | + body: '{}', |
| 190 | + headers: jsonContentHeaders, |
| 191 | + method: 'POST', |
| 192 | + path: `/webhosting/v1alpha1/regions/${validatePathParam( |
| 193 | + 'region', |
| 194 | + request.region ?? this.client.settings.defaultRegion, |
| 195 | + )}/hostings/${validatePathParam( |
| 196 | + 'hostingId', |
| 197 | + request.hostingId, |
| 198 | + )}/restore`, |
| 199 | + }, |
| 200 | + unmarshalHosting, |
| 201 | + ) |
| 202 | + |
| 203 | + /** |
| 204 | + * Get the DNS records of a specified domain. |
| 205 | + * |
| 206 | + * @param request - The request {@link GetDomainDnsRecordsRequest} |
| 207 | + * @returns A Promise of DnsRecords |
| 208 | + */ |
| 209 | + getDomainDnsRecords = (request: Readonly<GetDomainDnsRecordsRequest>) => |
| 210 | + this.client.fetch<DnsRecords>( |
| 211 | + { |
| 212 | + method: 'GET', |
| 213 | + path: `/webhosting/v1alpha1/regions/${validatePathParam( |
| 214 | + 'region', |
| 215 | + request.region ?? this.client.settings.defaultRegion, |
| 216 | + )}/domains/${validatePathParam('domain', request.domain)}/dns-records`, |
| 217 | + }, |
| 218 | + unmarshalDnsRecords, |
| 219 | + ) |
| 220 | + |
| 221 | + /** |
| 222 | + * List all offers |
| 223 | + * |
| 224 | + * @param request - The request {@link ListOffersRequest} |
| 225 | + * @returns A Promise of ListOffersResponse |
| 226 | + */ |
| 227 | + listOffers = (request: Readonly<ListOffersRequest>) => |
| 228 | + this.client.fetch<ListOffersResponse>( |
| 229 | + { |
| 230 | + method: 'GET', |
| 231 | + path: `/webhosting/v1alpha1/regions/${validatePathParam( |
| 232 | + 'region', |
| 233 | + request.region ?? this.client.settings.defaultRegion, |
| 234 | + )}/offers`, |
| 235 | + urlParams: urlParams( |
| 236 | + ['only_options', request.onlyOptions], |
| 237 | + ['order_by', request.orderBy ?? 'price_asc'], |
| 238 | + ['without_options', request.withoutOptions], |
| 239 | + ), |
| 240 | + }, |
| 241 | + unmarshalListOffersResponse, |
| 242 | + ) |
| 243 | +} |
0 commit comments