|
| 1 | +import { |
| 2 | + Credentials, |
| 3 | + Provider, |
| 4 | + HashConstructor, |
| 5 | + UrlParser, |
| 6 | + Protocol, |
| 7 | + HttpOptions, |
| 8 | + StreamCollector, |
| 9 | + Decoder, |
| 10 | + Encoder |
| 11 | +} from "@aws-sdk/types"; |
| 12 | +import { |
| 13 | + HttpEndpoint, |
| 14 | + HttpHandler, |
| 15 | + HttpRequest, |
| 16 | + HttpResponse |
| 17 | +} from "@aws-sdk/protocol-http"; |
| 18 | + |
| 19 | +export interface RuntimeDependencies { |
| 20 | + /** |
| 21 | + * The HTTP handler to use. Fetch in browser and Https in Nodejs |
| 22 | + */ |
| 23 | + httpHandler?: HttpHandler; |
| 24 | + |
| 25 | + /** |
| 26 | + * A constructor for a class implementing the @aws-sdk/types.Hash interface that computes the SHA-256 HMAC or checksum of a string or binary buffer |
| 27 | + */ |
| 28 | + sha256?: HashConstructor; |
| 29 | + |
| 30 | + /** |
| 31 | + * Default credentials provider; Not available in browser runtime |
| 32 | + */ |
| 33 | + credentialDefaultProvider?: (input: any) => Provider<Credentials>; |
| 34 | + |
| 35 | + /** |
| 36 | + * Provider function that return promise of a region string |
| 37 | + */ |
| 38 | + regionDefaultProvider?: (input: any) => Provider<string>; |
| 39 | + |
| 40 | + /** |
| 41 | + * The function that will be used to convert strings into HTTP endpoints |
| 42 | + */ |
| 43 | + urlParser?: UrlParser; |
| 44 | + |
| 45 | + /** |
| 46 | + * A function that can calculate the length of a request body. |
| 47 | + */ |
| 48 | + bodyLengthChecker?: (body: any) => number | undefined; |
| 49 | + |
| 50 | + /** |
| 51 | + * A function that converts a stream into an array of bytes. |
| 52 | + */ |
| 53 | + streamCollector?: StreamCollector; |
| 54 | + |
| 55 | + /** |
| 56 | + * The function that will be used to convert a base64-encoded string to a byte array |
| 57 | + */ |
| 58 | + base64Decoder?: Decoder; |
| 59 | + |
| 60 | + /** |
| 61 | + * The function that will be used to convert binary data to a base64-encoded string |
| 62 | + */ |
| 63 | + base64Encoder?: Encoder; |
| 64 | + |
| 65 | + /** |
| 66 | + * The function that will be used to convert a UTF8-encoded string to a byte array |
| 67 | + */ |
| 68 | + utf8Decoder?: Decoder; |
| 69 | + |
| 70 | + /** |
| 71 | + * The function that will be used to convert binary data to a UTF-8 encoded string |
| 72 | + */ |
| 73 | + utf8Encoder?: Encoder; |
| 74 | + |
| 75 | + /** |
| 76 | + * The function that will be used to populate default value in 'User-Agent' header |
| 77 | + */ |
| 78 | + defaultUserAgent?: string; |
| 79 | +} |
| 80 | + |
| 81 | +export interface AWSClientRuntimeConfiguration extends RuntimeDependencies { |
| 82 | + /** |
| 83 | + * The function that will be used to populate serializing protocol |
| 84 | + */ |
| 85 | + protocolDefaultProvider?: ( |
| 86 | + handler: HttpHandler |
| 87 | + ) => Protocol<HttpRequest, HttpResponse>; |
| 88 | + |
| 89 | + /** |
| 90 | + * The service name with which to sign requests. |
| 91 | + */ |
| 92 | + signingName?: string; |
| 93 | + |
| 94 | + /** |
| 95 | + * The service name with which to construct endpoints. |
| 96 | + */ |
| 97 | + service?: string; |
| 98 | +} |
| 99 | + |
| 100 | +export function normalizeProvider<T>(input: T | Provider<T>): Provider<T> { |
| 101 | + if (typeof input === "object") { |
| 102 | + const promisified = Promise.resolve(input); |
| 103 | + return () => promisified; |
| 104 | + } |
| 105 | + return input as Provider<T>; |
| 106 | +} |
| 107 | + |
| 108 | +export function normalizeEndpoint( |
| 109 | + endpoint?: string | HttpEndpoint | Provider<HttpEndpoint>, |
| 110 | + urlParser?: UrlParser |
| 111 | +): Provider<HttpEndpoint> { |
| 112 | + if (typeof endpoint === "string") { |
| 113 | + const promisified = Promise.resolve(urlParser!(endpoint)); |
| 114 | + return () => promisified; |
| 115 | + } else if (typeof endpoint === "object") { |
| 116 | + const promisified = Promise.resolve(endpoint); |
| 117 | + return () => promisified; |
| 118 | + } |
| 119 | + return endpoint!; |
| 120 | +} |
| 121 | + |
| 122 | +export namespace RegionConfiguration { |
| 123 | + export interface Input { |
| 124 | + /** |
| 125 | + * The AWS region to which this client will send requests |
| 126 | + */ |
| 127 | + region?: string | Provider<string>; |
| 128 | + } |
| 129 | + interface PreviouslyResolved { |
| 130 | + regionDefaultProvider: (input: any) => Provider<string>; |
| 131 | + } |
| 132 | + export interface Resolved { |
| 133 | + region: Provider<string>; |
| 134 | + } |
| 135 | + export function resolve<T>( |
| 136 | + input: T & Input & PreviouslyResolved |
| 137 | + ): T & Resolved { |
| 138 | + let region = input.region || input.regionDefaultProvider(input as any); |
| 139 | + return { |
| 140 | + ...input, |
| 141 | + region: normalizeProvider(region) |
| 142 | + }; |
| 143 | + } |
| 144 | +} |
| 145 | +//export separately for showing comment block in Intellisense |
| 146 | +export type RegionConfigurationInput = RegionConfiguration.Input; |
| 147 | + |
| 148 | +export namespace EndpointsConfig { |
| 149 | + export interface Input { |
| 150 | + /** |
| 151 | + * The fully qualified endpoint of the webservice. This is only required when using a custom endpoint (for example, when using a local version of S3). |
| 152 | + */ |
| 153 | + endpoint?: string | HttpEndpoint | Provider<HttpEndpoint>; |
| 154 | + |
| 155 | + /** |
| 156 | + * The endpoint provider to call if no endpoint is provided |
| 157 | + */ |
| 158 | + endpointProvider?: any; |
| 159 | + |
| 160 | + /** |
| 161 | + * Whether TLS is enabled for requests. |
| 162 | + */ |
| 163 | + tls?: boolean; |
| 164 | + } |
| 165 | + interface PreviouslyResolved { |
| 166 | + urlParser: UrlParser; |
| 167 | + region: Provider<string>; |
| 168 | + service: string; |
| 169 | + } |
| 170 | + export interface Resolved extends Required<Input> { |
| 171 | + endpoint: Provider<HttpEndpoint>; |
| 172 | + } |
| 173 | + export function resolve<T>( |
| 174 | + input: T & Input & PreviouslyResolved |
| 175 | + ): T & Resolved { |
| 176 | + const tls = input.tls || true; |
| 177 | + const defaultProvider = (tls: boolean, region: string) => ({ |
| 178 | + protocol: tls ? "https:" : "http:", |
| 179 | + path: "/", |
| 180 | + hostname: `${input.service}.${region}.amazonaws.com` |
| 181 | + }); |
| 182 | + const endpointProvider = input.endpointProvider || defaultProvider; |
| 183 | + let endpoint: Provider<HttpEndpoint> = input.endpoint |
| 184 | + ? normalizeEndpoint(input.endpoint, input.urlParser) |
| 185 | + : () => input.region().then(region => endpointProvider(tls, region)); |
| 186 | + return { |
| 187 | + ...input, |
| 188 | + endpointProvider, |
| 189 | + endpoint, |
| 190 | + tls |
| 191 | + }; |
| 192 | + } |
| 193 | +} |
| 194 | +//export separately for showing comment block in Intellisense |
| 195 | +export type EndpointsConfigInput = EndpointsConfig.Input; |
| 196 | + |
| 197 | +export namespace ProtocolConfig { |
| 198 | + export interface Input { |
| 199 | + /** |
| 200 | + * The serializing protocol to used in request |
| 201 | + */ |
| 202 | + protocol?: Protocol<any, any>; |
| 203 | + } |
| 204 | + interface PreviouslyResolved { |
| 205 | + httpHandler: HttpHandler; |
| 206 | + protocolDefaultProvider: ( |
| 207 | + handler: HttpHandler |
| 208 | + ) => Protocol<HttpRequest, HttpResponse, HttpOptions>; |
| 209 | + } |
| 210 | + export type Resolved = Required<Input>; |
| 211 | + export function resolve<T>( |
| 212 | + input: T & Input & PreviouslyResolved |
| 213 | + ): T & Resolved { |
| 214 | + return { |
| 215 | + ...input, |
| 216 | + protocol: |
| 217 | + input.protocol || input.protocolDefaultProvider(input.httpHandler) |
| 218 | + }; |
| 219 | + } |
| 220 | +} |
| 221 | +//export separately for showing comment block in Intellisense |
| 222 | +export type ProtocolConfigInput = ProtocolConfig.Input; |
0 commit comments