diff --git a/bin/apis-sync-helper.ts b/bin/apis-sync-helper.ts new file mode 100644 index 0000000000..32cd4e3029 --- /dev/null +++ b/bin/apis-sync-helper.ts @@ -0,0 +1,106 @@ +import {getProxySettings} from 'get-proxy-settings'; +import _ from 'lodash'; +import {request} from '../src/utils'; +import fs from 'fs'; +import {excludedApis} from '../src/app'; +type DirectoryList = gapi.client.discovery.DirectoryList; + +const prefix = '@maxim_mazurok/gapi.client.'; +const pathToConfig = + '/home/maxim/google-api-typings-generator/bin/auto-publish/config.ts'; +const pathToLocalAllowedPackageJsonDependencies = + '/home/maxim/DefinitelyTyped-tools/packages/definitions-parser/allowedPackageJsonDependencies.txt'; + +const getProxy = async () => { + const proxy = await getProxySettings(); + return proxy ? proxy.https || proxy.http : undefined; +}; + +const updateSupportedApis = (discoveryTypes: string[]) => { + const newConfig = [ + 'export const supportedApis = [', + ...discoveryTypes.map(x => ` '${x}',`), + '];', + '', + ]; + fs.writeFileSync(pathToConfig, newConfig.join('\n')); +}; + +const updateLocalAllowedPackageJsonDependencies = ( + discoveryTypes: string[] +) => { + const localAllowedPackageJsonDependencies = fs + .readFileSync(pathToLocalAllowedPackageJsonDependencies, { + encoding: 'utf-8', + }) + .split('\n'); + + const firstIndex = localAllowedPackageJsonDependencies.findIndex(x => + x.startsWith(prefix) + ); + + const newLocalAllowedPackageJsonDependencies = localAllowedPackageJsonDependencies.filter( + x => !x.startsWith(prefix) + ); + + newLocalAllowedPackageJsonDependencies.splice( + firstIndex, + 0, + ...discoveryTypes.map(x => `${prefix}${x}`) + ); + fs.writeFileSync( + pathToLocalAllowedPackageJsonDependencies, + newLocalAllowedPackageJsonDependencies.join('\n') + ); +}; + +const listDiscoveryTypes = async () => { + const list = await request( + 'https://www.googleapis.com/discovery/v1/apis', + await getProxy() + ); + + return _.uniq( + list.items + ?.filter(x => x.name !== undefined) + .map(x => (x.name || '').toLocaleLowerCase()) + .filter(x => !excludedApis.includes(x)) + ).sort(); +}; + +const listAllowedPackageJsonDependencies = async () => { + const list = await request( + 'https://raw.githubusercontent.com/microsoft/DefinitelyTyped-tools/master/packages/definitions-parser/allowedPackageJsonDependencies.txt', + await getProxy(), + 'text' + ); + return _.uniq( + list + .split('\n') + .filter(x => x.startsWith(prefix)) + .map(x => x.replace(prefix, '').toLocaleLowerCase()) + .filter(x => !excludedApis.includes(x)) + ).sort(); +}; + +(async () => { + const discoveryTypes = await listDiscoveryTypes(); + const allowedPackageJsonDependencies = await listAllowedPackageJsonDependencies(); + + const discoveryTypesNotPresentInAllowedPackageJsonDependencies = discoveryTypes.filter( + x => !allowedPackageJsonDependencies.includes(x) + ); + + console.log({discoveryTypesNotPresentInAllowedPackageJsonDependencies}); + + if (discoveryTypesNotPresentInAllowedPackageJsonDependencies.length !== 0) { + updateLocalAllowedPackageJsonDependencies(discoveryTypes); + updateSupportedApis(discoveryTypes); + // todo: open PR + } + + const allowedPackageJsonDependenciesNotPresentInDiscoveryTypes = allowedPackageJsonDependencies.filter( + x => !discoveryTypes.includes(x) + ); + console.log({allowedPackageJsonDependenciesNotPresentInDiscoveryTypes}); +})(); diff --git a/bin/auto-publish/config.ts b/bin/auto-publish/config.ts index 39221d42e1..db63c75980 100644 --- a/bin/auto-publish/config.ts +++ b/bin/auto-publish/config.ts @@ -20,6 +20,7 @@ export const supportedApis = [ 'androidmanagement', 'androidpublisher', 'apigateway', + 'apikeys', 'appengine', 'area120tables', 'artifactregistry', @@ -35,12 +36,15 @@ export const supportedApis = [ 'books', 'calendar', 'chat', + 'chromemanagement', + 'chromepolicy', 'chromeuxreport', 'civicinfo', 'classroom', 'cloudasset', 'cloudbilling', 'cloudbuild', + 'cloudchannel', 'clouddebugger', 'clouderrorreporting', 'cloudfunctions', @@ -76,12 +80,14 @@ export const supportedApis = [ 'dlp', 'dns', 'docs', + 'documentai', 'domains', 'domainsrdap', 'doubleclickbidmanager', 'doubleclicksearch', 'drive', 'driveactivity', + 'essentialcontacts', 'eventarc', 'factchecktools', 'fcm', @@ -92,6 +98,7 @@ export const supportedApis = [ 'firebasehosting', 'firebaseml', 'firebaserules', + 'firebasestorage', 'firestore', 'fitness', 'games', @@ -99,6 +106,7 @@ export const supportedApis = [ 'gameservices', 'gamesmanagement', 'genomics', + 'gkehub', 'gmail', 'gmailpostmastertools', 'groupsmigration', @@ -121,17 +129,24 @@ export const supportedApis = [ 'managedidentities', 'manufacturers', 'memcache', + 'metastore', 'ml', 'monitoring', + 'mybusinessaccountmanagement', + 'mybusinesslodging', + 'networkconnectivity', 'networkmanagement', 'notebooks', 'oauth2', + 'ondemandscanning', + 'orgpolicy', 'osconfig', 'oslogin', 'pagespeedonline', 'people', 'playablelocations', 'playcustomapp', + 'policysimulator', 'policytroubleshooter', 'poly', 'privateca', @@ -144,6 +159,7 @@ export const supportedApis = [ 'redis', 'remotebuildexecution', 'reseller', + 'retail', 'run', 'runtimeconfig', 'safebrowsing', @@ -186,6 +202,7 @@ export const supportedApis = [ 'vision', 'webfonts', 'webmasters', + 'webrisk', 'websecurityscanner', 'workflowexecutions', 'workflows', diff --git a/src/utils.ts b/src/utils.ts index fa92da4fd8..6d88a6f4ca 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -77,15 +77,16 @@ export async function getBannedTypes(): Promise { return options.length || options[0].length ? options.map(x => x[0]) : []; } -export async function request( +export async function request( url: string, - proxy: ProxySetting | undefined + proxy: ProxySetting | undefined, + responseType: 'json' | 'text' = 'json' ): Promise { const protocol = new URL(url).protocol as 'http:' | 'https:'; const agentProtocol = protocol === 'http:' ? Protocol.Http : Protocol.Https; const agent = agentProtocol === Protocol.Http ? HttpProxyAgent : HttpsProxyAgent; - return (await got(url, { + const response = got(url, { ...(proxy ? { agent: { @@ -100,7 +101,8 @@ export async function request( }, } : {}), - }).json()) as T; + }); + return (await response[responseType]()) as T; } /**