diff --git a/lib/Webhooks.js b/lib/Webhooks.js index cfd9232527..f7570b3946 100644 --- a/lib/Webhooks.js +++ b/lib/Webhooks.js @@ -1,8 +1,10 @@ 'use strict'; const utils = require('./utils'); -const {StripeError, StripeSignatureVerificationError} = require('./Error'); +const _Error = require('./Error'); +const {StripeError, StripeSignatureVerificationError} = _Error; const Webhook = { DEFAULT_TOLERANCE: 300, + signature: null, constructEvent(payload, header, secret, tolerance, cryptoProvider) { this.signature.verifyHeader( payload, @@ -142,6 +144,7 @@ function parseEventDetails(encodedPayload, encodedHeader, expectedScheme) { if (!details || details.timestamp === -1) { throw new StripeSignatureVerificationError({ message: 'Unable to extract timestamp and signatures from header', + // @ts-expect-error Type '{ decodedHeader: any; decodedPayload: any; }' is not assignable to type 'string'. detail: { decodedHeader, decodedPayload, @@ -151,6 +154,7 @@ function parseEventDetails(encodedPayload, encodedHeader, expectedScheme) { if (!details.signatures.length) { throw new StripeSignatureVerificationError({ message: 'No signatures found with expected scheme', + // @ts-expect-error Type '{ decodedHeader: any; decodedPayload: any; }' is not assignable to type 'string'. detail: { decodedHeader, decodedPayload, @@ -179,6 +183,7 @@ function validateComputedSignature( 'No signatures found matching the expected signature for payload.' + ' Are you passing the raw request body you received from Stripe?' + ' https://github.com/stripe/stripe-node#webhook-signing', + // @ts-expect-error Type '{ header: any; payload: any; }' is not assignable to type 'string'. detail: { header, payload, @@ -189,6 +194,7 @@ function validateComputedSignature( if (tolerance > 0 && timestampAge > tolerance) { throw new StripeSignatureVerificationError({ message: 'Timestamp outside the tolerance zone', + // @ts-expect-error Type '{ header: any; payload: any; }' is not assignable to type 'string'. detail: { header, payload, @@ -205,7 +211,7 @@ function parseHeader(header, scheme) { (accum, item) => { const kv = item.split('='); if (kv[0] === 't') { - accum.timestamp = kv[1]; + accum.timestamp = parseInt(kv[1], 10); } if (kv[0] === scheme) { accum.signatures.push(kv[1]); diff --git a/lib/apiVersion.js b/lib/apiVersion.js index 9c1e0e38d1..518f4476ab 100644 --- a/lib/apiVersion.js +++ b/lib/apiVersion.js @@ -1,2 +1,3 @@ +'use strict'; // File generated from our OpenAPI spec module.exports = {ApiVersion: '2022-08-01'}; diff --git a/lib/crypto/SubtleCryptoProvider.js b/lib/crypto/SubtleCryptoProvider.js index 6ff0e2b3c2..cbf5d01373 100644 --- a/lib/crypto/SubtleCryptoProvider.js +++ b/lib/crypto/SubtleCryptoProvider.js @@ -21,7 +21,7 @@ class SubtleCryptoProvider extends CryptoProvider { } /** @override */ async computeHMACSignatureAsync(payload, secret) { - const encoder = new TextEncoder('utf-8'); + const encoder = new TextEncoder(); const key = await this.subtleCrypto.importKey( 'raw', encoder.encode(secret), diff --git a/lib/multipart.js b/lib/multipart.js index bb186e00db..d88d468b1f 100644 --- a/lib/multipart.js +++ b/lib/multipart.js @@ -1,6 +1,7 @@ 'use strict'; const utils = require('./utils'); -const {StripeError} = require('./Error'); +const _Error = require('./Error'); +const {StripeError} = _Error; class StreamProcessingError extends StripeError {} // Method for formatting HTTP body for the multipart/form-data specification // Mostly taken from Fermata.js @@ -26,7 +27,7 @@ const multipartDataGenerator = (method, data, headers) => { for (const k in flattenedData) { const v = flattenedData[k]; push(`--${segno}`); - if (v.hasOwnProperty('data')) { + if (Object.prototype.hasOwnProperty.call(v, 'data')) { push( `Content-Disposition: form-data; name=${q(k)}; filename=${q( v.name || 'blob' @@ -79,4 +80,6 @@ const multipartRequestDataProcessor = (method, data, headers, callback) => { const buffer = multipartDataGenerator(method, data, headers); return callback(null, buffer); }; -module.exports.multipartRequestDataProcessor = multipartRequestDataProcessor; +module.exports = { + multipartRequestDataProcessor: multipartRequestDataProcessor, +}; diff --git a/lib/net/FetchHttpClient.js b/lib/net/FetchHttpClient.js index e57891b8cd..195b1bb0c6 100644 --- a/lib/net/FetchHttpClient.js +++ b/lib/net/FetchHttpClient.js @@ -1,5 +1,6 @@ 'use strict'; -const {HttpClient, HttpClientResponse} = require('./HttpClient'); +const _HttpClient = require('./HttpClient'); +const {HttpClient, HttpClientResponse} = _HttpClient; /** * HTTP client which uses a `fetch` function to issue requests. * diff --git a/lib/net/NodeHttpClient.js b/lib/net/NodeHttpClient.js index 1f9d12c4d8..c5712dfe2f 100644 --- a/lib/net/NodeHttpClient.js +++ b/lib/net/NodeHttpClient.js @@ -1,7 +1,8 @@ 'use strict'; const http = require('http'); const https = require('https'); -const {HttpClient, HttpClientResponse} = require('./HttpClient'); +const _HttpClient = require('./HttpClient'); +const {HttpClient, HttpClientResponse} = _HttpClient; const defaultHttpAgent = new http.Agent({keepAlive: true}); const defaultHttpsAgent = new https.Agent({keepAlive: true}); /** diff --git a/lib/utils.js b/lib/utils.js index 9efd90fd63..a17afff790 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -2,7 +2,6 @@ const EventEmitter = require('events').EventEmitter; const qs = require('qs'); const crypto = require('crypto'); -const hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); // Certain sandboxed environments (our known example right now are CloudFlare // Workers) may make `child_process` unavailable. Because `exec` isn't critical // to the operation of stripe-node, we handle this unavailability gracefully. @@ -31,13 +30,17 @@ const DEPRECATED_OPTIONS = { stripeVersion: 'apiVersion', }; const DEPRECATED_OPTIONS_KEYS = Object.keys(DEPRECATED_OPTIONS); -const utils = (module.exports = { +const utils = { isOptionsHash(o) { return ( o && typeof o === 'object' && - (OPTIONS_KEYS.some((prop) => hasOwn(o, prop)) || - DEPRECATED_OPTIONS_KEYS.some((prop) => hasOwn(o, prop))) + (OPTIONS_KEYS.some((prop) => + Object.prototype.hasOwnProperty.call(o, prop) + ) || + DEPRECATED_OPTIONS_KEYS.some((prop) => + Object.prototype.hasOwnProperty.call(o, prop) + )) ); }, /** @@ -189,8 +192,9 @@ const utils = (module.exports = { * Provide simple "Class" extension mechanism */ protoExtend(sub) { + // eslint-disable-next-line @typescript-eslint/no-this-alias const Super = this; - const Constructor = hasOwn(sub, 'constructor') + const Constructor = Object.prototype.hasOwnProperty.call(sub, 'constructor') ? sub.constructor : function(...args) { Super.apply(this, args); @@ -342,7 +346,10 @@ const utils = (module.exports = { const value = obj[key]; const newKey = prevKey ? `${prevKey}[${key}]` : key; if (utils.isObject(value)) { - if (!Buffer.isBuffer(value) && !value.hasOwnProperty('data')) { + if ( + !Buffer.isBuffer(value) && + !Object.prototype.hasOwnProperty.call(value, 'data') + ) { // Non-buffer non-file Objects are recursively flattened return step(value, newKey); } else { @@ -355,7 +362,7 @@ const utils = (module.exports = { } }); }; - step(data); + step(data, null); return result; }, /** @@ -386,7 +393,7 @@ const utils = (module.exports = { platform: process.platform, }; }, -}); +}; function emitWarning(warning) { if (typeof process.emitWarning !== 'function') { return console.warn( @@ -395,3 +402,4 @@ function emitWarning(warning) { } return process.emitWarning(warning, 'Stripe'); } +module.exports = utils; diff --git a/package.json b/package.json index ba4f71cf36..82e2f7dc33 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "node-fetch": "^2.6.2", "nyc": "^15.1.0", "prettier": "^1.16.4", - "typescript": "^3.7.2" + "typescript": "^4.8.3" }, "resolutions": { "ansi-regex": "5.0.1", diff --git a/src/ResourceNamespace.js b/src/ResourceNamespace.ts similarity index 97% rename from src/ResourceNamespace.js rename to src/ResourceNamespace.ts index 0d76787d81..c4b6c5566d 100644 --- a/src/ResourceNamespace.js +++ b/src/ResourceNamespace.ts @@ -1,5 +1,3 @@ -'use strict'; - // ResourceNamespace allows you to create nested resources, i.e. `stripe.issuing.cards`. // It also works recursively, so you could do i.e. `stripe.billing.invoicing.pay`. diff --git a/src/Webhooks.js b/src/Webhooks.ts similarity index 91% rename from src/Webhooks.js rename to src/Webhooks.ts index ffbe2004a9..14d5a4ed8f 100644 --- a/src/Webhooks.js +++ b/src/Webhooks.ts @@ -1,10 +1,10 @@ -'use strict'; - -const utils = require('./utils'); -const {StripeError, StripeSignatureVerificationError} = require('./Error'); +import utils = require('./utils'); +import _Error = require('./Error'); +const {StripeError, StripeSignatureVerificationError} = _Error; const Webhook = { DEFAULT_TOLERANCE: 300, // 5 minutes + signature: null, constructEvent(payload, header, secret, tolerance, cryptoProvider) { this.signature.verifyHeader( @@ -169,6 +169,7 @@ function parseEventDetails(encodedPayload, encodedHeader, expectedScheme) { if (!details || details.timestamp === -1) { throw new StripeSignatureVerificationError({ message: 'Unable to extract timestamp and signatures from header', + // @ts-expect-error Type '{ decodedHeader: any; decodedPayload: any; }' is not assignable to type 'string'. detail: { decodedHeader, decodedPayload, @@ -179,6 +180,7 @@ function parseEventDetails(encodedPayload, encodedHeader, expectedScheme) { if (!details.signatures.length) { throw new StripeSignatureVerificationError({ message: 'No signatures found with expected scheme', + // @ts-expect-error Type '{ decodedHeader: any; decodedPayload: any; }' is not assignable to type 'string'. detail: { decodedHeader, decodedPayload, @@ -210,6 +212,7 @@ function validateComputedSignature( 'No signatures found matching the expected signature for payload.' + ' Are you passing the raw request body you received from Stripe?' + ' https://github.com/stripe/stripe-node#webhook-signing', + // @ts-expect-error Type '{ header: any; payload: any; }' is not assignable to type 'string'. detail: { header, payload, @@ -222,6 +225,7 @@ function validateComputedSignature( if (tolerance > 0 && timestampAge > tolerance) { throw new StripeSignatureVerificationError({ message: 'Timestamp outside the tolerance zone', + // @ts-expect-error Type '{ header: any; payload: any; }' is not assignable to type 'string'. detail: { header, payload, @@ -242,7 +246,7 @@ function parseHeader(header, scheme) { const kv = item.split('='); if (kv[0] === 't') { - accum.timestamp = kv[1]; + accum.timestamp = parseInt(kv[1], 10); } if (kv[0] === scheme) { @@ -274,4 +278,4 @@ function getNodeCryptoProvider() { Webhook.signature = signature; -module.exports = Webhook; +export = Webhook; diff --git a/src/crypto/CryptoProvider.js b/src/crypto/CryptoProvider.ts similarity index 88% rename from src/crypto/CryptoProvider.js rename to src/crypto/CryptoProvider.ts index 8f038d06ca..bd7387c886 100644 --- a/src/crypto/CryptoProvider.js +++ b/src/crypto/CryptoProvider.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Interface encapsulating the various crypto computations used by the library, * allowing pluggable underlying crypto implementations. @@ -13,7 +11,7 @@ class CryptoProvider { * - computeHMACSignature('', 'test_secret') => 'f7f9bd47fb987337b5796fdc1fdb9ba221d0d5396814bfcaf9521f43fd8927fd' * - computeHMACSignature('\ud83d\ude00', 'test_secret') => '837da296d05c4fe31f61d5d7ead035099d9585a5bcde87de952012a78f0b0c43 */ - computeHMACSignature(payload, secret) { + computeHMACSignature(payload: string, secret: string): string { throw new Error('computeHMACSignature not implemented.'); } @@ -28,9 +26,9 @@ class CryptoProvider { * - computeHMACSignature('', 'test_secret') => 'f7f9bd47fb987337b5796fdc1fdb9ba221d0d5396814bfcaf9521f43fd8927fd' * - computeHMACSignature('\ud83d\ude00', 'test_secret') => '837da296d05c4fe31f61d5d7ead035099d9585a5bcde87de952012a78f0b0c43 */ - computeHMACSignatureAsync(payload, secret) { + computeHMACSignatureAsync(payload: string, secret: string): Promise { throw new Error('computeHMACSignatureAsync not implemented.'); } } -module.exports = CryptoProvider; +export = CryptoProvider; diff --git a/src/crypto/NodeCryptoProvider.js b/src/crypto/NodeCryptoProvider.ts similarity index 58% rename from src/crypto/NodeCryptoProvider.js rename to src/crypto/NodeCryptoProvider.ts index 83c2037ea2..4521bc9106 100644 --- a/src/crypto/NodeCryptoProvider.js +++ b/src/crypto/NodeCryptoProvider.ts @@ -1,15 +1,13 @@ -'use strict'; +import crypto = require('crypto'); -const crypto = require('crypto'); - -const CryptoProvider = require('./CryptoProvider'); +import CryptoProvider = require('./CryptoProvider'); /** * `CryptoProvider which uses the Node `crypto` package for its computations. */ class NodeCryptoProvider extends CryptoProvider { /** @override */ - computeHMACSignature(payload, secret) { + computeHMACSignature(payload: string, secret: string): string { return crypto .createHmac('sha256', secret) .update(payload, 'utf8') @@ -17,10 +15,13 @@ class NodeCryptoProvider extends CryptoProvider { } /** @override */ - async computeHMACSignatureAsync(payload, secret) { + async computeHMACSignatureAsync( + payload: string, + secret: string + ): Promise { const signature = await this.computeHMACSignature(payload, secret); return signature; } } -module.exports = NodeCryptoProvider; +export = NodeCryptoProvider; diff --git a/src/crypto/SubtleCryptoProvider.js b/src/crypto/SubtleCryptoProvider.ts similarity index 82% rename from src/crypto/SubtleCryptoProvider.js rename to src/crypto/SubtleCryptoProvider.ts index 45aa40dd46..999181e4cc 100644 --- a/src/crypto/SubtleCryptoProvider.js +++ b/src/crypto/SubtleCryptoProvider.ts @@ -1,6 +1,4 @@ -'use strict'; - -const CryptoProvider = require('./CryptoProvider'); +import CryptoProvider = require('./CryptoProvider'); /** * `CryptoProvider which uses the SubtleCrypto interface of the Web Crypto API. @@ -8,7 +6,9 @@ const CryptoProvider = require('./CryptoProvider'); * This only supports asynchronous operations. */ class SubtleCryptoProvider extends CryptoProvider { - constructor(subtleCrypto) { + subtleCrypto: SubtleCrypto; + + constructor(subtleCrypto: SubtleCrypto) { super(); // If no subtle crypto is interface, default to the global namespace. This @@ -18,15 +18,18 @@ class SubtleCryptoProvider extends CryptoProvider { } /** @override */ - computeHMACSignature(payload, secret) { + computeHMACSignature(payload: string, secret: string): string { throw new Error( 'SubtleCryptoProvider cannot be used in a synchronous context.' ); } /** @override */ - async computeHMACSignatureAsync(payload, secret) { - const encoder = new TextEncoder('utf-8'); + async computeHMACSignatureAsync( + payload: string, + secret: string + ): Promise { + const encoder = new TextEncoder(); const key = await this.subtleCrypto.importKey( 'raw', @@ -66,4 +69,4 @@ for (let i = 0; i < byteHexMapping.length; i++) { byteHexMapping[i] = i.toString(16).padStart(2, '0'); } -module.exports = SubtleCryptoProvider; +export = SubtleCryptoProvider; diff --git a/src/multipart.js b/src/multipart.ts similarity index 91% rename from src/multipart.js rename to src/multipart.ts index 90682aedda..dbb59a8bcf 100644 --- a/src/multipart.js +++ b/src/multipart.ts @@ -1,7 +1,6 @@ -'use strict'; - -const utils = require('./utils'); -const {StripeError} = require('./Error'); +import utils = require('./utils'); +import _Error = require('./Error'); +const {StripeError} = _Error; class StreamProcessingError extends StripeError {} @@ -33,7 +32,7 @@ const multipartDataGenerator = (method, data, headers) => { for (const k in flattenedData) { const v = flattenedData[k]; push(`--${segno}`); - if (v.hasOwnProperty('data')) { + if (Object.prototype.hasOwnProperty.call(v, 'data')) { push( `Content-Disposition: form-data; name=${q(k)}; filename=${q( v.name || 'blob' @@ -93,4 +92,6 @@ const multipartRequestDataProcessor = (method, data, headers, callback) => { return callback(null, buffer); }; -module.exports.multipartRequestDataProcessor = multipartRequestDataProcessor; +export = { + multipartRequestDataProcessor: multipartRequestDataProcessor, +}; diff --git a/src/net/FetchHttpClient.js b/src/net/FetchHttpClient.ts similarity index 93% rename from src/net/FetchHttpClient.js rename to src/net/FetchHttpClient.ts index 431282cd19..630bddc42d 100644 --- a/src/net/FetchHttpClient.js +++ b/src/net/FetchHttpClient.ts @@ -1,6 +1,5 @@ -'use strict'; - -const {HttpClient, HttpClientResponse} = require('./HttpClient'); +import _HttpClient = require('./HttpClient'); +const {HttpClient, HttpClientResponse} = _HttpClient; /** * HTTP client which uses a `fetch` function to issue requests. @@ -11,6 +10,12 @@ const {HttpClient, HttpClientResponse} = require('./HttpClient'); * node-fetch package (https://github.com/node-fetch/node-fetch). */ class FetchHttpClient extends HttpClient { + _fetchFn: ( + input: RequestInfo | URL, + init?: RequestInit | undefined + ) => Promise; + _res: Response; + constructor(fetchFn) { super(); this._fetchFn = fetchFn; @@ -88,6 +93,8 @@ class FetchHttpClient extends HttpClient { } class FetchHttpClientResponse extends HttpClientResponse { + _res: Response; + constructor(res) { super( res.status, @@ -135,4 +142,4 @@ class FetchHttpClientResponse extends HttpClientResponse { } } -module.exports = {FetchHttpClient, FetchHttpClientResponse}; +export = {FetchHttpClient, FetchHttpClientResponse}; diff --git a/src/net/HttpClient.js b/src/net/HttpClient.ts similarity index 77% rename from src/net/HttpClient.js rename to src/net/HttpClient.ts index b309ce7d9d..2c035d7cd7 100644 --- a/src/net/HttpClient.js +++ b/src/net/HttpClient.ts @@ -1,4 +1,4 @@ -'use strict'; +type TimeoutError = TypeError & {code?: string}; /** * Encapsulates the logic for issuing a request to the Stripe API. @@ -10,6 +10,9 @@ * returning their own response class when making requests. */ class HttpClient { + static CONNECTION_CLOSED_ERROR_CODES: string[]; + static TIMEOUT_ERROR_CODE: string; + /** The client name used for diagnostics. */ getClientName() { throw new Error('getClientName not implemented.'); @@ -30,7 +33,9 @@ class HttpClient { /** Helper to make a consistent timeout error across implementations. */ static makeTimeoutError() { - const timeoutErr = new TypeError(HttpClient.TIMEOUT_ERROR_CODE); + const timeoutErr: TimeoutError = new TypeError( + HttpClient.TIMEOUT_ERROR_CODE + ); timeoutErr.code = HttpClient.TIMEOUT_ERROR_CODE; return timeoutErr; } @@ -40,16 +45,19 @@ HttpClient.CONNECTION_CLOSED_ERROR_CODES = ['ECONNRESET', 'EPIPE']; HttpClient.TIMEOUT_ERROR_CODE = 'ETIMEDOUT'; class HttpClientResponse { + _statusCode: number; + _headers: Record; + constructor(statusCode, headers) { this._statusCode = statusCode; this._headers = headers; } - getStatusCode() { + getStatusCode(): number { return this._statusCode; } - getHeaders() { + getHeaders(): Record { return this._headers; } @@ -61,9 +69,9 @@ class HttpClientResponse { throw new Error('toStream not implemented.'); } - toJSON() { + toJSON(): any { throw new Error('toJSON not implemented.'); } } -module.exports = {HttpClient, HttpClientResponse}; +export = {HttpClient, HttpClientResponse}; diff --git a/src/net/NodeHttpClient.js b/src/net/NodeHttpClient.ts similarity index 88% rename from src/net/NodeHttpClient.js rename to src/net/NodeHttpClient.ts index 222a446ce7..1d556a0906 100644 --- a/src/net/NodeHttpClient.js +++ b/src/net/NodeHttpClient.ts @@ -1,9 +1,8 @@ -'use strict'; +import http = require('http'); +import https = require('https'); -const http = require('http'); -const https = require('https'); - -const {HttpClient, HttpClientResponse} = require('./HttpClient'); +import _HttpClient = require('./HttpClient'); +const {HttpClient, HttpClientResponse} = _HttpClient; const defaultHttpAgent = new http.Agent({keepAlive: true}); const defaultHttpsAgent = new https.Agent({keepAlive: true}); @@ -13,6 +12,8 @@ const defaultHttpsAgent = new https.Agent({keepAlive: true}); * requests.` */ class NodeHttpClient extends HttpClient { + _agent: http.Agent | https.Agent; + constructor(agent) { super(); this._agent = agent; @@ -86,7 +87,9 @@ class NodeHttpClient extends HttpClient { } class NodeHttpClientResponse extends HttpClientResponse { - constructor(res) { + _res: http.IncomingMessage; + + constructor(res: http.IncomingMessage) { super(res.statusCode, res.headers || {}); this._res = res; } @@ -103,7 +106,7 @@ class NodeHttpClientResponse extends HttpClientResponse { return this._res; } - toJSON() { + toJSON(): any { return new Promise((resolve, reject) => { let response = ''; @@ -122,4 +125,4 @@ class NodeHttpClientResponse extends HttpClientResponse { } } -module.exports = {NodeHttpClient, NodeHttpClientResponse}; +export = {NodeHttpClient, NodeHttpClientResponse}; diff --git a/src/utils.js b/src/utils.ts similarity index 93% rename from src/utils.js rename to src/utils.ts index 7eed41defd..b3ac274cbc 100644 --- a/src/utils.js +++ b/src/utils.ts @@ -1,11 +1,7 @@ -'use strict'; - const EventEmitter = require('events').EventEmitter; const qs = require('qs'); const crypto = require('crypto'); -const hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop); - // Certain sandboxed environments (our known example right now are CloudFlare // Workers) may make `child_process` unavailable. Because `exec` isn't critical // to the operation of stripe-node, we handle this unavailability gracefully. @@ -37,13 +33,30 @@ const DEPRECATED_OPTIONS = { }; const DEPRECATED_OPTIONS_KEYS = Object.keys(DEPRECATED_OPTIONS); -const utils = (module.exports = { +type Settings = { + timeout?: number; + maxNetworkRetries?: number; +}; + +type Options = { + auth?: string; + host?: string; + settings?: Settings; + streaming?: boolean; + headers?: Record; +}; + +const utils = { isOptionsHash(o) { return ( o && typeof o === 'object' && - (OPTIONS_KEYS.some((prop) => hasOwn(o, prop)) || - DEPRECATED_OPTIONS_KEYS.some((prop) => hasOwn(o, prop))) + (OPTIONS_KEYS.some((prop) => + Object.prototype.hasOwnProperty.call(o, prop) + ) || + DEPRECATED_OPTIONS_KEYS.some((prop) => + Object.prototype.hasOwnProperty.call(o, prop) + )) ); }, @@ -140,7 +153,7 @@ const utils = (module.exports = { * Return the options hash from a list of arguments */ getOptionsFromArgs: (args) => { - const opts = { + const opts: Options = { auth: null, headers: {}, settings: {}, @@ -210,8 +223,9 @@ const utils = (module.exports = { * Provide simple "Class" extension mechanism */ protoExtend(sub) { + // eslint-disable-next-line @typescript-eslint/no-this-alias const Super = this; - const Constructor = hasOwn(sub, 'constructor') + const Constructor = Object.prototype.hasOwnProperty.call(sub, 'constructor') ? sub.constructor : function(...args) { Super.apply(this, args); @@ -388,7 +402,10 @@ const utils = (module.exports = { const newKey = prevKey ? `${prevKey}[${key}]` : key; if (utils.isObject(value)) { - if (!Buffer.isBuffer(value) && !value.hasOwnProperty('data')) { + if ( + !Buffer.isBuffer(value) && + !Object.prototype.hasOwnProperty.call(value, 'data') + ) { // Non-buffer non-file Objects are recursively flattened return step(value, newKey); } else { @@ -402,7 +419,7 @@ const utils = (module.exports = { }); }; - step(data); + step(data, null); return result; }, @@ -438,7 +455,7 @@ const utils = (module.exports = { platform: process.platform, }; }, -}); +}; function emitWarning(warning) { if (typeof process.emitWarning !== 'function') { @@ -449,3 +466,5 @@ function emitWarning(warning) { return process.emitWarning(warning, 'Stripe'); } + +export = utils; diff --git a/tsconfig.json b/tsconfig.json index f5cc13096a..199458365d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "target": "es2017", "module": "commonjs", "checkJs": false, + "alwaysStrict": true, }, "include": ["./src/**/*"] } diff --git a/yarn.lock b/yarn.lock index 7c7a6481f3..dac05c29fe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2395,10 +2395,10 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typescript@^3.7.2: - version "3.9.9" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.9.tgz#e69905c54bc0681d0518bd4d587cc6f2d0b1a674" - integrity sha512-kdMjTiekY+z/ubJCATUPlRDl39vXYiMV9iyeMuEuXZh2we6zz80uovNN2WlAxmmdE/Z/YQe+EbOEXB5RHEED3w== +typescript@^4.8.3: + version "4.8.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.3.tgz#d59344522c4bc464a65a730ac695007fdb66dd88" + integrity sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig== uri-js@^4.2.2: version "4.4.1"