From c0ec8652673c7b276a7c71eb2d730eb3feb22eeb Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Mon, 8 Jun 2020 17:16:42 +0200 Subject: [PATCH] refactor: remove deprecated `client.resource()` BREAKING CHANGE: the deprecated `client.resource()` method was removed --- lib/client.js | 70 +----------------------------------------------- types/index.d.ts | 5 ---- 2 files changed, 1 insertion(+), 74 deletions(-) diff --git a/lib/client.js b/lib/client.js index 7c10ba61..617b1bf9 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,6 +1,6 @@ /* eslint-disable max-classes-per-file */ -const { inspect, deprecate } = require('util'); +const { inspect } = require('util'); const stdhttp = require('http'); const crypto = require('crypto'); const { strict: assert } = require('assert'); @@ -30,8 +30,6 @@ const instance = require('./helpers/weak_cache'); const { authenticatedPost, resolveResponseType, resolveRedirectUri } = require('./helpers/client'); const DeviceFlowHandle = require('./device_flow_handle'); -const { deep: defaultsDeep } = defaults; - function pickCb(input) { return pick(input, ...CALLBACK_PROPERTIES); } @@ -1589,70 +1587,4 @@ module.exports = (issuer, aadIssValidation = false) => class Client extends Base } }; -// TODO: remove in 4.x -BaseClient.prototype.resource = deprecate( - /* istanbul ignore next */ - async function resource(resourceUrl, accessToken, options) { - let token = accessToken; - const opts = { - verb: 'GET', - via: 'header', - ...options, - }; - - if (token instanceof TokenSet) { - if (!token.access_token) { - throw new TypeError('access_token not present in TokenSet'); - } - opts.tokenType = opts.tokenType || token.token_type; - token = token.access_token; - } - - const verb = String(opts.verb).toUpperCase(); - let requestOpts; - - switch (opts.via) { - case 'query': - if (verb !== 'GET') { - throw new TypeError('resource servers should only parse query strings for GET requests'); - } - requestOpts = { query: { access_token: token } }; - break; - case 'body': - if (verb !== 'POST') { - throw new TypeError('can only send body on POST'); - } - requestOpts = { form: true, body: { access_token: token } }; - break; - default: - requestOpts = { - headers: { - Authorization: authorizationHeaderValue(token, opts.tokenType), - }, - }; - } - - if (opts.params) { - if (verb === 'POST') { - defaultsDeep(requestOpts, { body: opts.params }); - } else { - defaultsDeep(requestOpts, { query: opts.params }); - } - } - - if (opts.headers) { - defaultsDeep(requestOpts, { headers: opts.headers }); - } - - const mTLS = !!this.tls_client_certificate_bound_access_tokens; - - return request.call(this, { - ...requestOpts, - encoding: null, - method: verb, - url: resourceUrl, - }, { mTLS }); - }, 'client.resource() is deprecated, use client.requestResource() instead, see docs for API details', -); - module.exports.BaseClient = BaseClient; diff --git a/types/index.d.ts b/types/index.d.ts index 58421d47..b2cf76c5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -410,11 +410,6 @@ export class Client { */ userinfo(accessToken: TokenSet | string, options?: { verb?: 'GET' | 'POST', via?: 'header' | 'body' | 'query', tokenType?: string, params?: object }): Promise; - /** - * @deprecated in favor of client.requestResource - */ - resource(resourceUrl: string, accessToken: TokenSet | string, options?: { headers?: object, verb?: 'GET' | 'POST', via?: 'header' | 'body' | 'query', tokenType?: string }): GotPromise; - /** * Fetches an arbitrary resource with the provided Access Token in an Authorization header. *