electron-builder-http.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. declare module "electron-builder-http/out/CancellationToken" {
  2. /// <reference types="node" />
  3. import { EventEmitter } from "events"
  4. export class CancellationToken extends EventEmitter {
  5. private parentCancelHandler
  6. private _cancelled
  7. readonly cancelled: boolean
  8. private _parent
  9. parent: CancellationToken
  10. constructor(parent?: CancellationToken)
  11. cancel(): void
  12. private onCancel(handler)
  13. createPromise<R>(callback: (resolve: (thenableOrResult?: R) => void, reject: (error?: Error) => void, onCancel: (callback: () => void) => void) => void): Promise<R>
  14. private removeParentCancelHandler()
  15. dispose(): void
  16. }
  17. export class CancellationError extends Error {
  18. constructor()
  19. }
  20. }
  21. declare module "electron-builder-http/out/ProgressCallbackTransform" {
  22. /// <reference types="node" />
  23. import { Transform } from "stream"
  24. import { CancellationToken } from "electron-builder-http/out/CancellationToken"
  25. export interface ProgressInfo {
  26. total: number
  27. delta: number
  28. transferred: number
  29. percent: number
  30. bytesPerSecond: number
  31. }
  32. export class ProgressCallbackTransform extends Transform {
  33. private readonly total
  34. private readonly cancellationToken
  35. private readonly onProgress
  36. private start
  37. private transferred
  38. private delta
  39. private nextUpdate
  40. constructor(total: number, cancellationToken: CancellationToken, onProgress: (info: ProgressInfo) => any)
  41. _transform(chunk: any, encoding: string, callback: Function): void
  42. _flush(callback: Function): void
  43. }
  44. }
  45. declare module "electron-builder-http/out/publishOptions" {
  46. export type PublishProvider = "github" | "bintray" | "s3" | "generic"
  47. export type AllPublishOptions = string | GithubOptions | S3Options | GenericServerOptions | BintrayOptions
  48. export type Publish = AllPublishOptions | Array<AllPublishOptions> | null
  49. /**
  50. * Can be specified in the [config](https://github.com/electron-userland/electron-builder/wiki/Options#Config) or any platform- or target- specific options.
  51. *
  52. * If `GH_TOKEN` is set — defaults to `[{provider: "github"}]`.
  53. *
  54. * If `BT_TOKEN` is set and `GH_TOKEN` is not set — defaults to `[{provider: "bintray"}]`.
  55. */
  56. export interface PublishConfiguration {
  57. /**
  58. * The provider.
  59. */
  60. readonly provider: PublishProvider
  61. /**
  62. * The owner.
  63. */
  64. readonly owner?: string | null
  65. }
  66. /**
  67. * GitHub options.
  68. *
  69. * GitHub [personal access token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/) is required. You can generate by going to [https://github.com/settings/tokens/new](https://github.com/settings/tokens/new). The access token should have the repo scope/permission.
  70. * Define `GH_TOKEN` environment variable.
  71. */
  72. export interface GithubOptions extends PublishConfiguration {
  73. /**
  74. * The repository name. [Detected automatically](#github-repository-and-bintray-package).
  75. */
  76. readonly repo?: string | null
  77. /**
  78. * Whether to use `v`-prefixed tag name.
  79. * @default true
  80. */
  81. readonly vPrefixedTagName?: boolean
  82. /**
  83. * The host (including the port if need).
  84. * @default github.com
  85. */
  86. readonly host?: string | null
  87. /**
  88. * The protocol. GitHub Publisher supports only `https`.
  89. * @default https
  90. */
  91. readonly protocol?: "https" | "http" | null
  92. /**
  93. * The access token to support auto-update from private github repositories. Never specify it in the configuration files. Only for [setFeedURL](module:electron-updater/out/AppUpdater.AppUpdater+setFeedURL).
  94. */
  95. readonly token?: string | null
  96. /**
  97. * Whether to use private github auto-update provider if `GH_TOKEN` environment variable is set.
  98. * @see https://github.com/electron-userland/electron-builder/wiki/Auto-Update#private-github-update-repo
  99. */
  100. readonly private?: boolean | null
  101. }
  102. export function githubUrl(options: GithubOptions): string
  103. /**
  104. * Generic (any HTTP(S) server) options.
  105. */
  106. export interface GenericServerOptions extends PublishConfiguration {
  107. /**
  108. * The base url. e.g. `https://bucket_name.s3.amazonaws.com`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
  109. */
  110. readonly url: string
  111. /**
  112. * The channel.
  113. * @default latest
  114. */
  115. readonly channel?: string | null
  116. }
  117. /**
  118. * Amazon S3 options. `https` must be used, so, if you use direct Amazon S3 endpoints, format `https://s3.amazonaws.com/bucket_name` [must be used](http://stackoverflow.com/a/11203685/1910191). And do not forget to make files/directories public.
  119. *
  120. * AWS credentials are required, please see [getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html).
  121. * Define `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` [environment variables](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-environment.html).
  122. * Or in the [~/.aws/credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-shared.html).
  123. */
  124. export interface S3Options extends PublishConfiguration {
  125. /**
  126. * The bucket name.
  127. */
  128. readonly bucket: string
  129. /**
  130. * The directory path.
  131. * @default /
  132. */
  133. readonly path?: string | null
  134. /**
  135. * The region. Is determined and set automatically when publishing.
  136. */
  137. readonly region?: string | null
  138. /**
  139. * The channel.
  140. * @default latest
  141. */
  142. readonly channel?: string | null
  143. /**
  144. * The ACL.
  145. * @default public-read
  146. */
  147. readonly acl?: "private" | "public-read" | null
  148. /**
  149. * The type of storage to use for the object.
  150. * @default STANDARD
  151. */
  152. readonly storageClass?: "STANDARD" | "REDUCED_REDUNDANCY" | "STANDARD_IA" | null
  153. }
  154. export function s3Url(options: S3Options): string
  155. /**
  156. * Bintray options.
  157. */
  158. export interface BintrayOptions extends PublishConfiguration {
  159. /**
  160. * The Bintray package name.
  161. */
  162. readonly package?: string | null
  163. /**
  164. * The Bintray repository name.
  165. * @default generic
  166. */
  167. readonly repo?: string | null
  168. /**
  169. * The Bintray user account. Used in cases where the owner is an organization.
  170. */
  171. readonly user?: string | null
  172. readonly token?: string | null
  173. }
  174. export interface VersionInfo {
  175. /**
  176. * The version.
  177. */
  178. readonly version: string
  179. }
  180. export interface UpdateInfo extends VersionInfo {
  181. readonly path: string
  182. readonly githubArtifactName?: string | null
  183. readonly sha2: string
  184. /**
  185. * The release name.
  186. */
  187. readonly releaseName?: string | null
  188. /**
  189. * The release notes.
  190. */
  191. readonly releaseNotes?: string | null
  192. /**
  193. * The release date.
  194. */
  195. readonly releaseDate: string
  196. }
  197. }
  198. declare module "electron-builder-http" {
  199. /// <reference types="node" />
  200. import { EventEmitter } from "events"
  201. import { RequestOptions } from "http"
  202. import { CancellationToken } from "electron-builder-http/out/CancellationToken"
  203. import { ProgressInfo } from "electron-builder-http/out/ProgressCallbackTransform"
  204. export interface RequestHeaders {
  205. [key: string]: any
  206. }
  207. export interface Response extends EventEmitter {
  208. statusCode?: number
  209. statusMessage?: string
  210. headers: any
  211. setEncoding(encoding: string): void
  212. }
  213. export interface DownloadOptions {
  214. readonly headers?: RequestHeaders | null
  215. readonly skipDirCreation?: boolean
  216. readonly sha2?: string | null
  217. readonly cancellationToken: CancellationToken
  218. onProgress?(progress: ProgressInfo): void
  219. }
  220. export class HttpExecutorHolder {
  221. private _httpExecutor
  222. httpExecutor: HttpExecutor<any, any>
  223. }
  224. export const executorHolder: HttpExecutorHolder
  225. export function download(url: string, destination: string, options?: DownloadOptions | null): Promise<string>
  226. export class HttpError extends Error {
  227. readonly response: {
  228. statusMessage?: string | undefined
  229. statusCode?: number | undefined
  230. headers?: {
  231. [key: string]: string[]
  232. } | undefined
  233. }
  234. description: any | null
  235. constructor(response: {
  236. statusMessage?: string | undefined
  237. statusCode?: number | undefined
  238. headers?: {
  239. [key: string]: string[]
  240. } | undefined
  241. }, description?: any | null)
  242. }
  243. export abstract class HttpExecutor<REQUEST_OPTS, REQUEST> {
  244. protected readonly maxRedirects: number
  245. request<T>(options: RequestOptions, cancellationToken: CancellationToken, data?: {
  246. [name: string]: any
  247. } | null): Promise<T>
  248. protected abstract doApiRequest<T>(options: REQUEST_OPTS, cancellationToken: CancellationToken, requestProcessor: (request: REQUEST, reject: (error: Error) => void) => void, redirectCount: number): Promise<T>
  249. abstract download(url: string, destination: string, options: DownloadOptions): Promise<string>
  250. protected handleResponse(response: Response, options: RequestOptions, cancellationToken: CancellationToken, resolve: (data?: any) => void, reject: (error: Error) => void, redirectCount: number, requestProcessor: (request: REQUEST, reject: (error: Error) => void) => void): void
  251. protected abstract doRequest(options: any, callback: (response: any) => void): any
  252. protected doDownload(requestOptions: any, destination: string, redirectCount: number, options: DownloadOptions, callback: (error: Error | null) => void, onCancel: (callback: () => void) => void): void
  253. protected addTimeOutHandler(request: any, callback: (error: Error) => void): void
  254. }
  255. export function request<T>(options: RequestOptions, cancellationToken: CancellationToken, data?: {
  256. [name: string]: any
  257. } | null): Promise<T>
  258. export function configureRequestOptions(options: RequestOptions, token?: string | null, method?: "GET" | "DELETE" | "PUT"): RequestOptions
  259. export function dumpRequestOptions(options: RequestOptions): string
  260. }
  261. declare module "electron-builder-http/out/bintray" {
  262. import { BintrayOptions } from "electron-builder-http/out/publishOptions"
  263. import { CancellationToken } from "electron-builder-http/out/CancellationToken"
  264. export function bintrayRequest<T>(path: string, auth: string | null, data: {
  265. [name: string]: any
  266. } | null | undefined, cancellationToken: CancellationToken, method?: "GET" | "DELETE" | "PUT"): Promise<T>
  267. export interface Version {
  268. readonly name: string
  269. readonly package: string
  270. }
  271. export interface File {
  272. name: string
  273. path: string
  274. sha1: string
  275. sha256: string
  276. }
  277. export class BintrayClient {
  278. private readonly cancellationToken
  279. private readonly basePath
  280. readonly auth: string | null
  281. readonly repo: string
  282. readonly owner: string
  283. readonly user: string
  284. readonly packageName: string
  285. constructor(options: BintrayOptions, cancellationToken: CancellationToken, apiKey?: string | null)
  286. getVersion(version: string): Promise<Version>
  287. getVersionFiles(version: string): Promise<Array<File>>
  288. createVersion(version: string): Promise<any>
  289. deleteVersion(version: string): Promise<any>
  290. }
  291. }