Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate many library api's, unify others #752

Merged
merged 10 commits into from
Jan 9, 2020

Conversation

rattrayalex-stripe
Copy link
Contributor

@rattrayalex-stripe rattrayalex-stripe commented Jan 8, 2020

r? @richardm-stripe
cc @ob-stripe @jlomas-stripe @paulasjes-stripe

Much of the tricky stuff here is wrestling with questions of what should be private, what should be private-but-you-can-poke-it-anyway, etc. It might be healthier for my sanity to kick these cans down the road a bit more, but probably healthier for the library to deal with them sooner rather than later, especially if we want to upgrade our internals to TS etc in the medium term.


Breaking changes

[BREAKING] Remove deprecated Error base export, extend method, and populate method

You can no longer do this:

const MyStripeError = StripeError.extend({});

Instead, you can do this:

class MyStripeError extends StripeError {}

You can no longer do this (which should not have had a legitimate use-case):

const StripeGenericError = require('stripe/lib/Error');

Instead, use the named export StripeError:

const {StripeError} = require('stripe/lib/Error');
// or
const Stripe = require('stripe');
const {StripeError} = Stripe.errors;

[BREAKING] Privatize several constants

The following constants are no longer accessible:

Stripe.DEFAULT_HOST
Stripe.DEFAULT_PORT
Stripe.DEFAULT_BASE_PATH
Stripe.DEFAULT_API_VERSION
Stripe.DEFAULT_TIMEOUT
Stripe.MAX_NETWORK_RETRY_DELAY_SEC
Stripe.INITIAL_NETWORK_RETRY_DELAY_SEC

Instead, you can read them like so:

Stripe.getConstant('DEFAULT_HOST');

Though we may remove this in the future, so please file an issue with your use case if you rely on this functionality.

To set a value you like this, use a config option when instantiating the Stripe client, e.g.,

const stripe = new Stripe(apiKey, {
  host,
  port,
  basePath,
  timeout,
  apiVersion,
});

Non-breaking changes

Deprecate snake_case options like stripe_account with warning messages

Doing, e.g., stripe.customers.create(params, {api_key: foo}) will now emit a warning message encouraging you to use apiKey instead.

Add protocol to config object for local proxies etc

You can now instantiate a stripe client with a non-https protocol, e.g.,

const stripe = new Stripe(apiKey, {
  host: '127.0.0.1',
  port: 3000,
  protocol: 'http',
});

This is intended for tests and proxies. All production traffic must be https only.

This replaces stripe.setProtocol() and stripe.setHost(host, port, protocol), which are deprecated.

Add appInfo to config object

Stripe plugin authors can now instantiate a stripe client with appInfo instead of using stripe.setAppInfo, eg;

const stripe = new Stripe(apiKey, {
  appInfo: {
    name: 'MyCoolPlugin',
  }
});

Mark all setter methods as deprecated, emit warnings.

Setter methods like stripe.setApiVersion() were previously deprecated; now, they emit deprecation warnings. Please move to the config object or request options instead.

For example, instead of this:

const stripe = new Stripe(apiKey);
stripe.setApiVersion('2019-11-03');

You could do this:

const stripe = new Stripe(apiKey, {apiVersion: '2019-11-03'});
stripe.customers.list();

Or this:

const stripe = new Stripe(apiKey);
stripe.customers.list({apiVersion: '2019-11-03'});

Mark methods prefixed with an underscore as private

Methods like _setAppInfo which are intended for private use now have a docstring indicating they are private, and may be removed in the future.

If you rely on any underscore-prefixed methods, please open an issue on github detailing your use-case.

Mark a few getter methods which are not prefixed with underscores as private

The following getter methods were likely always intended for private use only, but may be used for reasons we haven’t yet thought of. We may remove them in the future.

stripe.getApiField()
stripe.getConstant()
stripe.getClientUserAgent()
stripe.getClientUserAgentSeeded()
stripe.getAppInfoAsString()

If you are relying on any of these, please let us know.

Rename the request option stripeVersion to apiVersion

We previously used stripeVersion and did not have apiVersion here, which was inconsistent with how you instantiate the stripe client: new Stripe(apiKey, {apiVersion: '2019-12-03'}).

Instead of this:

stripe.customers.list({stripeVersion: '2019-11-03'});

Please do this instead:

stripe.customers.list({apiVersion: '2019-11-03'});

The former will now log a warning message, but will continue to work as expected.

Stripe.DEFAULT_HOST = 'api.stripe.com';
Stripe.DEFAULT_PORT = '443';
Stripe.DEFAULT_BASE_PATH = '/v1/';
Stripe.DEFAULT_API_VERSION = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants I'm moderately worried about removing. Users could previously read/write them, though I don't think that was ever intended.

They can still read them with Stripe.getConstant and all of them have proper ways of writing, eg new Stripe(key, {host, port, basePath, apiVersion, timeout})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rattrayalex-stripe
Copy link
Contributor Author

r? @richardm-stripe change enacted in e756c7f

@rattrayalex-stripe rattrayalex-stripe changed the title Deprecate many library api's, unify others [WIP] [RFC] Deprecate many library api's, unify others Jan 9, 2020
@rattrayalex-stripe rattrayalex-stripe mentioned this pull request Jan 9, 2020
8 tasks
@rattrayalex-stripe rattrayalex-stripe merged commit 284ac22 into v8.0.0 Jan 9, 2020
@rattrayalex-stripe rattrayalex-stripe deleted the ralex/8-remove-deprecated-methods branch January 9, 2020 19:18
rattrayalex-stripe added a commit that referenced this pull request Jan 10, 2020
* Drop support for Node 6

* TypeScript definitions [beta] (#736)

* First pass

* wip

* More changes

* Split resources by file

* Move to api version folder

* Remove tsconfig, add prettierignore

* Properly generate nested and no-method resources

* Document new TypeScript usage in README

* Add a basic test for typescript correctness

* Better formatting for export of Stripe

* Break out subtypes

* Separate out Address

* Pull empty strings out of enums

* Use all named subresources from openapi

* Rough draft of using shared subresources

* Revert "Rough draft of using shared subresources"

This reverts commit eb9a4d8.

* Fix some bugs I think

* Okay actually go back to normal

* Actually use all shared subresources from openapi

* Revert "Actually use all shared subresources from openapi"

This reverts commit 52136ae.

* Add webhooks.d.ts

* Add and test ApiListPromise for async iteration of lists

* Add better types for ApiList and HeaderOptions

* Rename HeaderOptions to RequestOptions

* Add docs and tests for expanding objects

* Add in reference to webhooks.d.ts

* Update snapshots to reflect reordering

* Add multiple dispatch for optional params

* Add TS tests for multiple dispatch, config, etc

* Move types for setAppInfo

* Add errors

* Fix some formatting

* Remove (Customer) Source and ExternalAccount

* Move metadata back up, add deleted?: void, add eg DeletedCustomer to the union for expandable deletable objects

* Reorder nested methods, rename nested & delete param types, move nested model & param types into their own files

* Remove docstrings from param types since they exist on method definitions

* Reorder required params to be first

* Minor method reorder

* Describe why you have to explicitly reference the types

* Move from vYYYY-MM-DD to YYYY-MM-DD, upgrade api version to 2019-12-03

* Update future version

* Fix param type name and mention esModuleInterop in docs

* Add docstring and test for ApiList

* Add docstrings for errors

* Fix accidentally optional fields

* Add missing values to RawErrorType

* Fix many non-optional fields

* Remove whitespace typo

* Add signature for retrieving a specific account

* Add types for OAuth

* Openapi updates

* Rename Webhooks in git

* Use export default instead of export = so that users dont need to do esModuleInterop

* Add a default export to the runtime

* Also export Stripe as a named export, and as a static property on itself

* Collapse types for setHost

* Require the user to specify the latest API version, use types by default.

* Fix a type error

* Reorganize test, use strictNullChecks etc

* Fix readme

* Unexport error classes to avoid instanceof confusion

* Clarify how to use old api versions with TS

* Fix typo params -> param

* Updates from openapi

* Mark the args to several setters as required

* More accurate handling of deleted resources and required/optional fields

* Erroneous handling of deleted

* Revert "Erroneous handling of deleted"

This reverts commit ad64e33.

* Add comment about deprecated total_count.

* Add shared types for Addresses and Metadata, and update openapi

* Use null intead of empty string

* Fix invoice upcoming lines

* Update openapi

* More empty-string to null translation

* Stop polluting the global namespace by scoping everything under module stripe

* Run eslint & prettier on TS files

* Continue to have poor types for HttpAgent, but with more claity as to why

* Clean up explicit any lint warnings

* Remove constants intended for internal use only

* Extract CustomerSource to a standalone type

* Remove unnecessary export

* Better types for account debit sources

* Use shared RangeQueryParam and PaginationParam

* Add expand param to SubscriptionDeleteParams

* Bring business_type back

* Add docstrings to config options

* Add mandatory `typescript: true` config prop

* Use await in TS readme

* Wrap await in async function

* Many readme updates

* Remove docs on non-public fields/params (we should revert this if it comes up a lot)

* Clarify async/await a bit

* TypeScriptify docstrings for Webhooks

* Add @types/node as a dependency, use it for typing Buffer and http.Agent

* Remove a TODO

Co-authored-by: jlomas-stripe <[email protected]>

* Small typo fixes (#743)

* Correct "eg;" to "e.g.,"

* Fix typo

* Remove deprecated resources and methods (#744)

* Remove stripe.usageRecords and stripe.usageRecordSummaries, add stripe.subscriptionItems.listUsageRecordSummaries

* Update openapi

* Remove Recipients

* Remove BitcoinReceivers

* Remove ThreeDSecure

* Fix SubscriptionSchedules.Plan.plan (#748)

It was incorrectly pointing back to SubscriptionSchedules.Plan instead of Stripe.Plan

* Openapi updates

* Use Stripe. prefix for all top-level resources (#751)

* Deprecate many library api's, unify others (#752)

* Deprecate snake_case options like stripe_account with warning messages

* Remove deprecated Error base export, extend method, and populate method

* Privatize several constants

* Add protocol to config object for local proxies etc

* Add `appInfo` config option

* Mark all setter methods as deprecated, emit warnings.

* Mark methods prefixed with an underscore as private

* Mark a few getter methods which are not prefixed with underscores as private

* Rename the request option stripeVersion to apiVersion to be consistent with the config option and our overall terminology

* Throw an error if a deprecated and non-deprecated version of the same request option is passed

* Accept an array of strings or buffers as the header argument for webhooks.constructEvent (#753)

* Stop importing errors as a single Error object, which shadowed the real Error object

* Accept an array of strings (or buffers) as the header in webhooks

* Actually just throw an error if an array is actually passed

* Improve markdown links in TS comments (#754)

Co-authored-by: jlomas-stripe <[email protected]>
Co-authored-by: Petja Touru <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants