|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT license. |
| 3 | + |
| 4 | +import * as request from "request-promise-native"; |
| 5 | + |
| 6 | +/** |
| 7 | + * |
| 8 | + * @returns information about available releases |
| 9 | + * |
| 10 | + * Sample Response: |
| 11 | + * { |
| 12 | + * "available_lts_releases": [ |
| 13 | + * 8, |
| 14 | + * 11, |
| 15 | + * 17 |
| 16 | + * ], |
| 17 | + * "available_releases": [ |
| 18 | + * 8, |
| 19 | + * 11, |
| 20 | + * 16, |
| 21 | + * 17 |
| 22 | + * ], |
| 23 | + * "most_recent_feature_release": 17, |
| 24 | + * "most_recent_feature_version": 17, |
| 25 | + * "most_recent_lts": 17, |
| 26 | + * "tip_version": 18 |
| 27 | + * } |
| 28 | + */ |
| 29 | +export async function availableReleases(): Promise<AdoptiumReleaseInfo> { |
| 30 | + const uri = "https://api.adoptium.net/v3/info/available_releases"; |
| 31 | + const response = await request.get({ |
| 32 | + uri, |
| 33 | + json: true |
| 34 | + }) |
| 35 | + return response; |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | +/** |
| 40 | + * |
| 41 | + * @returns list of latest assets for given feature version and jvm impl |
| 42 | + * |
| 43 | + * Sample Response: |
| 44 | + * [ |
| 45 | + * { |
| 46 | + * "binary": { |
| 47 | + * "architecture": "x64", |
| 48 | + * "download_count": 15116, |
| 49 | + * "heap_size": "normal", |
| 50 | + * "image_type": "jdk", |
| 51 | + * "installer": { |
| 52 | + * "checksum": "a45c33691f0508a95ff291c88713088e060376e7b4e9cac03d083225b68d8f78", |
| 53 | + * "checksum_link": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17%2B35/OpenJDK17-jdk_x64_mac_hotspot_17_35.pkg.sha256.txt", |
| 54 | + * "download_count": 8857, |
| 55 | + * "link": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17%2B35/OpenJDK17-jdk_x64_mac_hotspot_17_35.pkg", |
| 56 | + * "metadata_link": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17%2B35/OpenJDK17-jdk_x64_mac_hotspot_17_35.pkg.json", |
| 57 | + * "name": "OpenJDK17-jdk_x64_mac_hotspot_17_35.pkg", |
| 58 | + * "size": 192821728 |
| 59 | + * }, |
| 60 | + * "jvm_impl": "hotspot", |
| 61 | + * "os": "mac", |
| 62 | + * "package": { |
| 63 | + * "checksum": "e9de8b1b62780fe99270a5b30f0645d7a91eded60438bcf836a05fa7b93c182f", |
| 64 | + * "checksum_link": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17%2B35/OpenJDK17-jdk_x64_mac_hotspot_17_35.tar.gz.sha256.txt", |
| 65 | + * "download_count": 6259, |
| 66 | + * "link": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17%2B35/OpenJDK17-jdk_x64_mac_hotspot_17_35.tar.gz", |
| 67 | + * "metadata_link": "https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17%2B35/OpenJDK17-jdk_x64_mac_hotspot_17_35.tar.gz.json", |
| 68 | + * "name": "OpenJDK17-jdk_x64_mac_hotspot_17_35.tar.gz", |
| 69 | + * "size": 192417649 |
| 70 | + * }, |
| 71 | + * "project": "jdk", |
| 72 | + * "scm_ref": "jdk-17+35_adopt", |
| 73 | + * "updated_at": "2021-09-22T07:48:28Z" |
| 74 | + * }, |
| 75 | + * "release_name": "jdk-17+35", |
| 76 | + * "vendor": "eclipse", |
| 77 | + * "version": { |
| 78 | + * "build": 35, |
| 79 | + * "major": 17, |
| 80 | + * "minor": 0, |
| 81 | + * "openjdk_version": "17+35", |
| 82 | + * "security": 0, |
| 83 | + * "semver": "17.0.0+35" |
| 84 | + * } |
| 85 | + * }, |
| 86 | + * ... |
| 87 | + * ] |
| 88 | + */ |
| 89 | +export async function latestAssets(featureVersion: string, jvmImpl: string): Promise<AdoptiumAsset[]> { |
| 90 | + let uri = `https://api.adoptium.net/v3/assets/latest/${featureVersion}/${jvmImpl}`; |
| 91 | + const response = await request.get({ |
| 92 | + uri, |
| 93 | + json: true, |
| 94 | + // workaround: certificate expired, fixed in Electron v15.1.0 |
| 95 | + // see: https://github.com/node-fetch/node-fetch/issues/568#issuecomment-932435180 |
| 96 | + rejectUnauthorized: false |
| 97 | + }) |
| 98 | + return response; |
| 99 | +} |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +interface AdoptiumReleaseInfo { |
| 104 | + available_lts_releases: number[]; |
| 105 | + available_releases: number[]; |
| 106 | +}; |
| 107 | + |
| 108 | +export interface AdoptiumAsset { |
| 109 | + release_name: string; |
| 110 | + binary: { |
| 111 | + architecture: string; |
| 112 | + os: string; |
| 113 | + image_type: string; |
| 114 | + installer?: AdoptiumFileMetadata; |
| 115 | + package?: AdoptiumFileMetadata; |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +export interface AdoptiumFileMetadata { |
| 120 | + name: string; |
| 121 | + link: string; |
| 122 | + checksum: string; |
| 123 | + size: number; |
| 124 | +} |
0 commit comments