Skip to content

Commit

Permalink
Remove more deprecated items (#1600)
Browse files Browse the repository at this point in the history
Remove remaining deprecated items
  • Loading branch information
anniel-stripe committed Nov 4, 2022
1 parent 58e625c commit 651324b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 238 deletions.
26 changes: 0 additions & 26 deletions lib/StripeMethod.basic.js

This file was deleted.

12 changes: 1 addition & 11 deletions lib/StripeResource.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 4 additions & 35 deletions lib/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 0 additions & 32 deletions src/StripeMethod.basic.js

This file was deleted.

14 changes: 1 addition & 13 deletions src/StripeResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ type Options = {
// Provide extension mechanism for Stripe Resource Sub-Classes
StripeResource.extend = utils.protoExtend;

// Expose method-creator & prepared (basic) methods
// Expose method-creator
StripeResource.method = require('./StripeMethod');
StripeResource.BASIC_METHODS = require('./StripeMethod.basic');

StripeResource.MAX_BUFFERED_REQUEST_METRICS = 100;
const MAX_RETRY_AFTER_WAIT = 60;
Expand All @@ -49,14 +48,6 @@ function StripeResource(stripe, deprecatedUrlData) {
this.resourcePath = this.path;
this.path = utils.makeURLInterpolator(this.path);

// DEPRECATED: This was kept for backwards compatibility in case users were
// using this, but basic methods are now explicitly defined on a resource.
if (this.includeBasic) {
this.includeBasic.forEach(function(methodName) {
this[methodName] = StripeResource.BASIC_METHODS[methodName];
}, this);
}

this.initialize(...arguments);
}

Expand Down Expand Up @@ -117,9 +108,6 @@ StripeResource.prototype = {
return parts.join('/').replace(/\/{2,}/g, '/');
},

// DEPRECATED: Here for backcompat in case users relied on this.
wrapTimeout: utils.callbackifyPromiseWithTimeout,

_timeoutHandler(timeout, req, callback) {
return () => {
const timeoutErr = new TypeError('ETIMEDOUT');
Expand Down
40 changes: 4 additions & 36 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ const OPTIONS_KEYS = [
'host',
];

const DEPRECATED_OPTIONS = {
api_key: 'apiKey',
idempotency_key: 'idempotencyKey',
stripe_account: 'stripeAccount',
stripe_version: 'apiVersion',
stripeVersion: 'apiVersion',
};
const DEPRECATED_OPTIONS_KEYS = Object.keys(DEPRECATED_OPTIONS);

type Settings = {
timeout?: number;
maxNetworkRetries?: number;
Expand All @@ -51,12 +42,7 @@ const utils = {
return (
o &&
typeof o === 'object' &&
(OPTIONS_KEYS.some((prop) =>
Object.prototype.hasOwnProperty.call(o, prop)
) ||
DEPRECATED_OPTIONS_KEYS.some((prop) =>
Object.prototype.hasOwnProperty.call(o, prop)
))
OPTIONS_KEYS.some((prop) => Object.prototype.hasOwnProperty.call(o, prop))
);
},

Expand Down Expand Up @@ -170,27 +156,9 @@ const utils = {
);

if (extraKeys.length) {
const nonDeprecated = extraKeys.filter((key) => {
if (!DEPRECATED_OPTIONS[key]) {
return true;
}
const newParam = DEPRECATED_OPTIONS[key];
if (params[newParam]) {
throw Error(
`Both '${newParam}' and '${key}' were provided; please remove '${key}', which is deprecated.`
);
}
/**
* TODO turn this into a hard error in a future major version (once we have fixed our docs).
*/
emitWarning(`'${key}' is deprecated; use '${newParam}' instead.`);
params[newParam] = params[key];
});
if (nonDeprecated.length) {
emitWarning(
`Invalid options found (${extraKeys.join(', ')}); ignoring.`
);
}
emitWarning(
`Invalid options found (${extraKeys.join(', ')}); ignoring.`
);
}

if (params.apiKey) {
Expand Down
85 changes: 0 additions & 85 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,91 +309,6 @@ describe('utils', () => {
});
});

it('parses snake case for backwards compatibility', () => {
return new Promise((resolve, reject) => {
const args = [
{
api_key: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii',
idempotency_key: 'key',
stripe_account: 'acct_123',
stripe_version: '2019-08-08',
},
];
const desiredWarnings = [
"Stripe: 'api_key' is deprecated; use 'apiKey' instead.",
"Stripe: 'idempotency_key' is deprecated; use 'idempotencyKey' instead.",
"Stripe: 'stripe_account' is deprecated; use 'stripeAccount' instead.",
"Stripe: 'stripe_version' is deprecated; use 'apiVersion' instead.",
];

const warnings = [];
const onWarn = (message) => {
warnings.push(message);
if (warnings.length === desiredWarnings.length) {
expect(warnings).to.deep.equal(desiredWarnings);
resolve();
}
};
handleWarnings(() => {
expect(utils.getOptionsFromArgs(args)).to.deep.equal({
auth: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii',
headers: {
'Idempotency-Key': 'key',
'Stripe-Version': '2019-08-08',
'Stripe-Account': 'acct_123',
},
settings: {},
});
}, onWarn);
});
});

it('parses stripeVersion for backwards compatibility', () => {
return new Promise((resolve, reject) => {
const args = [
{
apiKey: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii',
stripeVersion: '2019-08-08',
},
];
const desiredWarnings = [
"Stripe: 'stripeVersion' is deprecated; use 'apiVersion' instead.",
];

const warnings = [];
const onWarn = (message) => {
warnings.push(message);
if (warnings.length === desiredWarnings.length) {
expect(warnings).to.deep.equal(desiredWarnings);
resolve();
}
};
handleWarnings(() => {
expect(utils.getOptionsFromArgs(args)).to.deep.equal({
auth: 'sk_test_iiiiiiiiiiiiiiiiiiiiiiii',
headers: {
'Stripe-Version': '2019-08-08',
},
settings: {},
});
}, onWarn);
});
});

it('errors if you pass both a deprecated and non-deprecated version of the same param', () => {
const args = [
{
stripeVersion: 'bad',
apiVersion: 'good',
},
];
expect(() => {
utils.getOptionsFromArgs(args);
}).to.throw(
"Both 'apiVersion' and 'stripeVersion' were provided; please remove 'stripeVersion', which is deprecated."
);
});

it('warns if the hash contains something that does not belong', (done) => {
const args = [
{foo: 'bar'},
Expand Down

0 comments on commit 651324b

Please sign in to comment.