From 04a282b63ffe86eb936f616ed29e9c86a5ec830e Mon Sep 17 00:00:00 2001 From: Joseph Carroll Date: Mon, 23 Jul 2018 11:53:59 -0400 Subject: [PATCH] Add registry-auth-token (#27285) * Add registry-auth-token * Fix: type definitions header * Fix: Change Typescript version: 2.8 * Fix: Clean-up test cases --- types/registry-auth-token/index.d.ts | 70 +++++++++++++++++++ .../registry-auth-token-tests.ts | 15 ++++ types/registry-auth-token/tsconfig.json | 23 ++++++ types/registry-auth-token/tslint.json | 3 + 4 files changed, 111 insertions(+) create mode 100644 types/registry-auth-token/index.d.ts create mode 100644 types/registry-auth-token/registry-auth-token-tests.ts create mode 100644 types/registry-auth-token/tsconfig.json create mode 100644 types/registry-auth-token/tslint.json diff --git a/types/registry-auth-token/index.d.ts b/types/registry-auth-token/index.d.ts new file mode 100644 index 0000000000..cac80c5208 --- /dev/null +++ b/types/registry-auth-token/index.d.ts @@ -0,0 +1,70 @@ +// Type definitions for Registry Auth Token 3.3 +// Project: https://github.com/rexxars/registry-auth-token +// Definitions by: Maurice de Beijer +// James Liang +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +/** + * Simple namespace describing the inputs and outputs for `registry-auth-token` + */ +declare namespace auth { + /** + * The options for passing into `registry-auth-token` + */ + interface AuthOptions { + /** + * Wether or not url's path parts are recursively trimmed from the registry + * url when searching for tokens + */ + recursive?: boolean; + /** + * An npmrc configuration object used when searching for tokens. If no object is provided, + * the `.npmrc` file at the base of the project is used. + */ + npmrc?: { + /** + * A registry url used for matching + */ + registry?: string; + /** + * Registry url's with token information + */ + [registryUrls: string]: string; + }; + } + /** + * The generated authentication information + */ + interface NpmCredentials { + /** + * The token representing the users credentials + */ + token: string; + /** + * The type of token + */ + type: 'Basic'|'Bearer'; + /** + * The username used in `Basic` + */ + username?: string; + /** + * The password used in `Basic` + */ + password?: string; + } +} + +/** + * + * @param registryUrl - Either the registry url used + * for matching or a configuration object describing the contents of the .npmrc file + * @param [options] - a configuration object describing the + * contents of the .npmrc file. If an `npmrc` config object was passed in as the + * first parameter, this parameter is ignored. + * @returns The `NpmCredentials` object or undefined if no match found. + */ +declare function auth(registryUrl: string | auth.AuthOptions, options?: auth.AuthOptions): auth.NpmCredentials; + +export = auth; diff --git a/types/registry-auth-token/registry-auth-token-tests.ts b/types/registry-auth-token/registry-auth-token-tests.ts new file mode 100644 index 0000000000..0c50ea20a4 --- /dev/null +++ b/types/registry-auth-token/registry-auth-token-tests.ts @@ -0,0 +1,15 @@ +import * as authToken from 'registry-auth-token'; + +// $ExpectType NpmCredentials +authToken('url'); +// $ExpectType NpmCredentials +authToken({ recursive: true }); +// $ExpectType NpmCredentials +authToken({ npmrc: { url: 'value' } }); +// $ExpectType NpmCredentials +authToken({ npmrc: { registry: 'url' } }); +// $ExpectType NpmCredentials +authToken('url', { npmrc: { url: 'value' } }); + +// $ExpectError +authToken(); diff --git a/types/registry-auth-token/tsconfig.json b/types/registry-auth-token/tsconfig.json new file mode 100644 index 0000000000..6ce9facf15 --- /dev/null +++ b/types/registry-auth-token/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "registry-auth-token-tests.ts" + ] +} diff --git a/types/registry-auth-token/tslint.json b/types/registry-auth-token/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/registry-auth-token/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}