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

Revert Typescript changes #1547

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
92 changes: 27 additions & 65 deletions src/Error.ts → lib/Error.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,11 @@
'use strict';

type RawErrorType =
| 'card_error'
| 'invalid_request_error'
| 'api_error'
| 'idempotency_error'
| 'rate_limit_error'
| 'authentication_error'
| 'invalid_grant';

type StripeRawError = {
message?: string;
type?: RawErrorType;

headers?: {[header: string]: string};
statusCode?: number;
requestId?: string;
code?: string;
doc_url?: string;
decline_code?: string;
param?: string;
detail?: string;
charge?: string;
payment_method_type?: string;

payment_intent?: any;
payment_method?: any;
setup_intent?: any;
source?: any;
exception?: any;
};

/**
* StripeError is the base error from which all other more specific Stripe errors derive.
* Specifically for errors returned from Stripe's REST API.
*/
export class StripeError extends Error {
readonly message: string;
readonly type: string;
readonly raw: unknown;
readonly rawType: RawErrorType;
readonly headers: {[header: string]: string};
readonly requestId: string;

readonly code?: string;
readonly doc_url?: string;
readonly param?: string;
readonly detail?: string;
readonly statusCode?: number;
readonly charge?: string;
readonly decline_code?: string;
readonly payment_method_type?: string;

readonly payment_intent?: any;
readonly payment_method?: any;
readonly setup_intent?: any;
readonly source?: any;

constructor(raw: StripeRawError) {
class StripeError extends Error {
constructor(raw = {}) {
super(raw.message);
this.type = this.constructor.name;

Expand Down Expand Up @@ -112,69 +60,83 @@ export class StripeError extends Error {
* CardError is raised when a user enters a card that can't be charged for
* some reason.
*/
export class StripeCardError extends StripeError {}
class StripeCardError extends StripeError {}

/**
* InvalidRequestError is raised when a request is initiated with invalid
* parameters.
*/
export class StripeInvalidRequestError extends StripeError {}
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.
*/
export class StripeAPIError extends StripeError {}
class StripeAPIError extends StripeError {}

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

/**
* PermissionError is raised in cases where access was attempted on a resource
* that wasn't allowed.
*/
export class StripePermissionError extends StripeError {}
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.
*/
export class StripeRateLimitError extends StripeError {}
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.
*/
export class StripeConnectionError extends StripeError {}
class StripeConnectionError extends StripeError {}

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

/**
* IdempotencyError is raised in cases where an idempotency key was used
* improperly.
*/
export class StripeIdempotencyError extends StripeError {}
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.
*/
export class StripeInvalidGrantError extends StripeError {}
class StripeInvalidGrantError extends StripeError {}

/**
* Any other error from Stripe not specifically captured above
*/
export class StripeUnknownError extends StripeError {}
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;
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions src/StripeMethod.ts → lib/StripeMethod.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

import utils = require('./utils');
import makeRequest = require('./makeRequest');
import {makeAutoPaginationMethods} from './autoPagination';
const utils = require('./utils');
const makeRequest = require('./makeRequest');
const makeAutoPaginationMethods = require('./autoPagination')
.makeAutoPaginationMethods;

/**
* Create an API method from the declared spec.
Expand Down Expand Up @@ -54,4 +55,4 @@ function stripeMethod(spec) {
};
}

export = stripeMethod;
module.exports = stripeMethod;
35 changes: 12 additions & 23 deletions src/StripeResource.ts → lib/StripeResource.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
'use strict';

import utils = require('./utils');
import {
StripeAPIError,
StripeAuthenticationError,
const utils = require('./utils');
const {
StripeConnectionError,
StripeError,
StripeAuthenticationError,
StripePermissionError,
StripeRateLimitError,
} from './Error';

import {HttpClient} from './net/HttpClient';

type Settings = {
timeout?: number;
};
StripeError,
StripeAPIError,
} = require('./Error');

type Options = {
settings?: Settings;
streaming?: boolean;
headers?: Record<string, string>;
};
const {HttpClient} = require('./net/HttpClient');

// Provide extension mechanism for Stripe Resource Sub-Classes
StripeResource.extend = utils.protoExtend;
Expand Down Expand Up @@ -123,7 +113,7 @@ StripeResource.prototype = {
_timeoutHandler(timeout, req, callback) {
return () => {
const timeoutErr = new TypeError('ETIMEDOUT');
(timeoutErr as any).code = 'ETIMEDOUT';
timeoutErr.code = 'ETIMEDOUT';

req.destroy(timeoutErr);
};
Expand Down Expand Up @@ -293,7 +283,7 @@ StripeResource.prototype = {
this,
new StripeConnectionError({
message: this._generateConnectionErrorMessage(requestRetries),
detail,
detail: error,
}),
null
);
Expand Down Expand Up @@ -374,7 +364,7 @@ StripeResource.prototype = {
},

// Max retries can be set on a per request basis. Favor those over the global setting
_getMaxNetworkRetries(settings: {maxNetworkRetries?: number} = {}) {
_getMaxNetworkRetries(settings = {}) {
return settings.maxNetworkRetries &&
Number.isInteger(settings.maxNetworkRetries)
? settings.maxNetworkRetries
Expand Down Expand Up @@ -490,7 +480,7 @@ StripeResource.prototype = {
}
},

_request(method, host, path, data, auth, options: Options = {}, callback) {
_request(method, host, path, data, auth, options = {}, callback) {
let requestData;

const retryRequest = (
Expand All @@ -513,7 +503,6 @@ StripeResource.prototype = {
// timeout can be set on a per-request basis. Favor that over the global setting
const timeout =
options.settings &&
options.settings.timeout &&
Number.isInteger(options.settings.timeout) &&
options.settings.timeout >= 0
? options.settings.timeout
Expand Down Expand Up @@ -610,7 +599,7 @@ StripeResource.prototype = {
options.settings
);

makeRequest(apiVersion, headers, 0);
makeRequest(apiVersion, headers);
});
};

Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 6 additions & 9 deletions src/autoPagination.ts → lib/autoPagination.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
'use strict';

import utils = require('./utils');
import makeRequest = require('./makeRequest');
const makeRequest = require('./makeRequest');
const utils = require('./utils');

export function makeAutoPaginationMethods(
self,
requestArgs,
spec,
firstPagePromise
) {
function makeAutoPaginationMethods(self, requestArgs, spec, firstPagePromise) {
const promiseCache = {currentPromise: null};
const reverseIteration = isReverseIteration(requestArgs);
let pagePromise = firstPagePromise;
Expand Down Expand Up @@ -99,6 +94,8 @@ export function makeAutoPaginationMethods(
return autoPaginationMethods;
}

module.exports.makeAutoPaginationMethods = makeAutoPaginationMethods;

/**
* ----------------
* Private Helpers:
Expand Down Expand Up @@ -245,7 +242,7 @@ function makeAutoPagingToArray(autoPagingEach) {
}

function wrapAsyncIteratorWithCallback(asyncIteratorNext, onItem) {
return new Promise<void>((resolve, reject) => {
return new Promise((resolve, reject) => {
function handleIteration(iterResult) {
if (iterResult.done) {
resolve();
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/makeRequest.ts → lib/makeRequest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import utils = require('./utils');
const utils = require('./utils');

function getRequestOpts(self, requestArgs, spec, overrideData) {
// Extract spec values with defaults.
Expand Down Expand Up @@ -119,4 +119,4 @@ function makeRequest(self, requestArgs, spec, overrideData) {
});
}

export = makeRequest;
module.exports = makeRequest;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading