Skip to content

Commit

Permalink
Revert Typescript changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anniel-stripe committed Sep 7, 2022
1 parent 668f1a3 commit 34a9e54
Show file tree
Hide file tree
Showing 121 changed files with 6,422 additions and 58 deletions.
3 changes: 1 addition & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
*.node*.js
node_modules
lib
node_modules
25 changes: 0 additions & 25 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,29 +249,4 @@ module.exports = {
},
plugins: ['prettier'],
extends: ['plugin:prettier/recommended'],
overrides: [
{
files: ["**/*.ts"],
parser: "@typescript-eslint/parser",
plugins: ['@typescript-eslint', 'prettier'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
rules: {
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/no-empty-interface': 0,
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/triple-slash-reference': 0,
'@typescript-eslint/ban-ts-ignore': 0,
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'prefer-rest-params': 'off',
},
},
],
};
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
- name: Build Typescript
run: yarn && yarn build
- name: Node check
run: find . -name "*.js" -type f -not -path "./node_modules/*" -not -path "./\.*" -exec node --check {} \;

- name: Lint
run: yarn lint
run: yarn && yarn lint

test:
name: Test (${{ matrix.node }})
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ tags
.nyc_output
coverage
.idea
lib
6 changes: 0 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# Changelog

## 10.8.0 - 2022-09-06
* [#1544](https://github.com/stripe/stripe-node/pull/1544) API Updates
* Add support for new value `terminal_reader_splashscreen` on enums `File.purpose` and `FileListParams.purpose`
* [#1543](https://github.com/stripe/stripe-node/pull/1543) Migrate Stripe infrastructure to Typescript
* [#1539](https://github.com/stripe/stripe-node/pull/1539) Build Typescript and migrate StripeResource

## 10.7.0 - 2022-08-31
* [#1540](https://github.com/stripe/stripe-node/pull/1540) API Updates
* Add support for new values `de-CH`, `en-CH`, `en-PL`, `en-PT`, `fr-CH`, `it-CH`, `pl-PL`, and `pt-PT` on enums `OrderCreateParams.payment.settings.payment_method_options.klarna.preferred_locale`, `OrderUpdateParams.payment.settings.payment_method_options.klarna.preferred_locale`, `PaymentIntentConfirmParams.payment_method_options.klarna.preferred_locale`, `PaymentIntentCreateParams.payment_method_options.klarna.preferred_locale`, and `PaymentIntentUpdateParams.payment_method_options.klarna.preferred_locale`
Expand Down
2 changes: 1 addition & 1 deletion OPENAPI_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v189
v188
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.8.0
10.7.0
142 changes: 142 additions & 0 deletions lib/Error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
'use strict';

/**
* StripeError is the base error from which all other more specific Stripe errors derive.
* Specifically for errors returned from Stripe's REST API.
*/
class StripeError extends Error {
constructor(raw = {}) {
super(raw.message);
this.type = this.constructor.name;

this.raw = raw;
this.rawType = raw.type;
this.code = raw.code;
this.doc_url = raw.doc_url;
this.param = raw.param;
this.detail = raw.detail;
this.headers = raw.headers;
this.requestId = raw.requestId;
this.statusCode = raw.statusCode;
this.message = raw.message;

this.charge = raw.charge;
this.decline_code = raw.decline_code;
this.payment_intent = raw.payment_intent;
this.payment_method = raw.payment_method;
this.payment_method_type = raw.payment_method_type;
this.setup_intent = raw.setup_intent;
this.source = raw.source;
}

/**
* Helper factory which takes raw stripe errors and outputs wrapping instances
*/
static generate(rawStripeError) {
switch (rawStripeError.type) {
case 'card_error':
return new StripeCardError(rawStripeError);
case 'invalid_request_error':
return new StripeInvalidRequestError(rawStripeError);
case 'api_error':
return new StripeAPIError(rawStripeError);
case 'authentication_error':
return new StripeAuthenticationError(rawStripeError);
case 'rate_limit_error':
return new StripeRateLimitError(rawStripeError);
case 'idempotency_error':
return new StripeIdempotencyError(rawStripeError);
case 'invalid_grant':
return new StripeInvalidGrantError(rawStripeError);
default:
return new StripeUnknownError(rawStripeError);
}
}
}

// Specific Stripe Error types:

/**
* CardError is raised when a user enters a card that can't be charged for
* some reason.
*/
class StripeCardError extends StripeError {}

/**
* InvalidRequestError is raised when a request is initiated with invalid
* parameters.
*/
class StripeInvalidRequestError extends StripeError {}

/**
* APIError is a generic error that may be raised in cases where none of the
* other named errors cover the problem. It could also be raised in the case
* that a new error has been introduced in the API, but this version of the
* Node.JS SDK doesn't know how to handle it.
*/
class StripeAPIError extends StripeError {}

/**
* AuthenticationError is raised when invalid credentials are used to connect
* to Stripe's servers.
*/
class StripeAuthenticationError extends StripeError {}

/**
* PermissionError is raised in cases where access was attempted on a resource
* that wasn't allowed.
*/
class StripePermissionError extends StripeError {}

/**
* RateLimitError is raised in cases where an account is putting too much load
* on Stripe's API servers (usually by performing too many requests). Please
* back off on request rate.
*/
class StripeRateLimitError extends StripeError {}

/**
* StripeConnectionError is raised in the event that the SDK can't connect to
* Stripe's servers. That can be for a variety of different reasons from a
* downed network to a bad TLS certificate.
*/
class StripeConnectionError extends StripeError {}

/**
* SignatureVerificationError is raised when the signature verification for a
* webhook fails
*/
class StripeSignatureVerificationError extends StripeError {}

/**
* IdempotencyError is raised in cases where an idempotency key was used
* improperly.
*/
class StripeIdempotencyError extends StripeError {}

/**
* InvalidGrantError is raised when a specified code doesn't exist, is
* expired, has been used, or doesn't belong to you; a refresh token doesn't
* exist, or doesn't belong to you; or if an API key's mode (live or test)
* doesn't match the mode of a code or refresh token.
*/
class StripeInvalidGrantError extends StripeError {}

/**
* Any other error from Stripe not specifically captured above
*/
class StripeUnknownError extends StripeError {}

module.exports.generate = StripeError.generate;
module.exports.StripeError = StripeError;
module.exports.StripeCardError = StripeCardError;
module.exports.StripeInvalidRequestError = StripeInvalidRequestError;
module.exports.StripeAPIError = StripeAPIError;
module.exports.StripeAuthenticationError = StripeAuthenticationError;
module.exports.StripePermissionError = StripePermissionError;
module.exports.StripeRateLimitError = StripeRateLimitError;
module.exports.StripeConnectionError = StripeConnectionError;
module.exports.StripeSignatureVerificationError = StripeSignatureVerificationError;
module.exports.StripeIdempotencyError = StripeIdempotencyError;
module.exports.StripeInvalidGrantError = StripeInvalidGrantError;
module.exports.StripeUnknownError = StripeUnknownError;
22 changes: 22 additions & 0 deletions lib/ResourceNamespace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'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`.

function ResourceNamespace(stripe, resources) {
for (const name in resources) {
const camelCaseName = name[0].toLowerCase() + name.substring(1);

const resource = new resources[name](stripe);

this[camelCaseName] = resource;
}
}

module.exports = function(namespace, resources) {
return function(stripe) {
return new ResourceNamespace(stripe, resources);
};
};

module.exports.ResourceNamespace = ResourceNamespace;
32 changes: 32 additions & 0 deletions lib/StripeMethod.basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const stripeMethod = require('./StripeMethod');

// DEPRECATED: These were kept for backwards compatibility in case users were
// using this, but basic methods are now explicitly defined on a resource.
module.exports = {
create: stripeMethod({
method: 'POST',
}),

list: stripeMethod({
method: 'GET',
methodType: 'list',
}),

retrieve: stripeMethod({
method: 'GET',
path: '/{id}',
}),

update: stripeMethod({
method: 'POST',
path: '{id}',
}),

// Avoid 'delete' keyword in JS
del: stripeMethod({
method: 'DELETE',
path: '{id}',
}),
};
58 changes: 58 additions & 0 deletions lib/StripeMethod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

const utils = require('./utils');
const makeRequest = require('./makeRequest');
const makeAutoPaginationMethods = require('./autoPagination')
.makeAutoPaginationMethods;

/**
* Create an API method from the declared spec.
*
* @param [spec.method='GET'] Request Method (POST, GET, DELETE, PUT)
* @param [spec.path=''] Path to be appended to the API BASE_PATH, joined with
* the instance's path (e.g. 'charges' or 'customers')
* @param [spec.fullPath=''] Fully qualified path to the method (eg. /v1/a/b/c).
* If this is specified, path should not be specified.
* @param [spec.urlParams=[]] Array of required arguments in the order that they
* must be passed by the consumer of the API. Subsequent optional arguments are
* optionally passed through a hash (Object) as the penultimate argument
* (preceding the also-optional callback argument
* @param [spec.encode] Function for mutating input parameters to a method.
* Usefully for applying transforms to data on a per-method basis.
* @param [spec.host] Hostname for the request.
*/
function stripeMethod(spec) {
if (spec.path !== undefined && spec.fullPath !== undefined) {
throw new Error(
`Method spec specified both a 'path' (${spec.path}) and a 'fullPath' (${spec.fullPath}).`
);
}
return function(...args) {
const callback = typeof args[args.length - 1] == 'function' && args.pop();

spec.urlParams = utils.extractUrlParams(
spec.fullPath || this.createResourcePathWithSymbols(spec.path || '')
);

const requestPromise = utils.callbackifyPromiseWithTimeout(
makeRequest(this, args, spec, {}),
callback
);

// Please note `spec.methodType === 'search'` is beta functionality and this
// interface is subject to change/removal at any time.
if (spec.methodType === 'list' || spec.methodType === 'search') {
const autoPaginationMethods = makeAutoPaginationMethods(
this,
args,
spec,
requestPromise
);
Object.assign(requestPromise, autoPaginationMethods);
}

return requestPromise;
};
}

module.exports = stripeMethod;
Loading

0 comments on commit 34a9e54

Please sign in to comment.