Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyingchun committed May 29, 2024
1 parent b32152c commit ef85f9f
Show file tree
Hide file tree
Showing 26 changed files with 1,933 additions and 884 deletions.
37 changes: 0 additions & 37 deletions .eslintrc.cjs

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint"]
}
13 changes: 10 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.preferences.importModuleSpecifier": "relative",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "never"
Expand All @@ -15,5 +15,12 @@
// to allow dbaeumer.vscode-eslint to format them
"[javascript]": {
"editor.formatOnSave": false
}
}
},
"eslint.experimental.useFlatConfig": true,
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
}
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ For contirbuting or referrring the samples, You can fork/refer this repository.
#### Code to Execute:

```javascript
import { core, orders, payments } from "@hyperse-io/paypal-node-sdk";
import { core, orders, payments } from '@hyperse-io/paypal-node-sdk';

// Creating an environment
let clientId = "<<PAYPAL-CLIENT-ID>>";
let clientSecret = "<<PAYPAL-CLIENT-SECRET>>";
let clientId = '<<PAYPAL-CLIENT-ID>>';
let clientSecret = '<<PAYPAL-CLIENT-SECRET>>';
// This sample uses SandboxEnvironment. In production, use LiveEnvironment
let environment = new core.SandboxEnvironment(clientId, clientSecret);
let client = new core.PayPalHttpClient(environment);
Expand All @@ -40,12 +40,12 @@ let client = new core.PayPalHttpClient(environment);
// Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
let request = new orders.OrdersCreateRequest();
request.requestBody({
"intent": "CAPTURE",
"purchase_units": [
intent: 'CAPTURE',
purchase_units: [
{
"amount": {
"currency_code": "USD",
"value": "100.00",
amount: {
currency_code: 'USD',
value: '100.00',
},
},
],
Expand Down Expand Up @@ -109,7 +109,7 @@ let captureOrder = async function (orderId) {
console.log(`Capture: ${JSON.stringify(response.result)}`);
};

let capture = captureOrder("REPLACE-WITH-APPROVED-ORDER-ID");
let capture = captureOrder('REPLACE-WITH-APPROVED-ORDER-ID');
```

#### Example Output:
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { base, defineConfig } from '@hyperse/eslint-config-hyperse';

export default defineConfig(
[
// ...typescript
...base,
{
rules: {
'@typescript-eslint/no-explicit-any': 'off',
},
},
],
['**/docs']
);
21 changes: 1 addition & 20 deletions lint-staged.common.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import path from 'path';
import { quote } from 'shell-quote';

const isWin = process.platform === 'win32';

const eslintGlobalRulesForFix = [
// react-hooks/eslint and react in general is very strict about exhaustively
Expand Down Expand Up @@ -54,27 +51,11 @@ export const getEslintFixCmd = ({
fix ? '--fix' : '',
cliFixType.length > 0 ? `--fix-type ${cliFixType.join(',')}` : '',
maxWarnings !== undefined ? `--max-warnings=${maxWarnings}` : '',
cliRules.length > 0 ? `--rule ${cliRules.join('--rule ')}` : '',
cliRules.length > 0 ? `--rule ${cliRules.join(' --rule ')}` : '',
files
// makes output cleaner by removing absolute paths from filenames
.map((f) => `"./${path.relative(cwd, f)}"`)
.join(' '),
].join(' ');
return `eslint ${args}`;
};

/**
* Concatenate and escape a list of filenames that can be passed as args to prettier cli
*
* Prettier has an issue with special characters in filenames,
* such as the ones uses for nextjs dynamic routes (ie: [id].tsx...)
*
* @link https://github.com/okonet/lint-staged/issues/676
*
* @param {string[]} filenames
* @returns {string} Return concatenated and escaped filenames
*/
export const concatFilesForPrettier = (filenames) =>
filenames
.map((filename) => `"${isWin ? filename : quote([filename])}"`)
.join(' ');
12 changes: 2 additions & 10 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { fileURLToPath } from 'node:url';
* A good practice is to override this base configuration in each package and/or application
* where we are able to add customization depending on the nature of the project (eslint...).
*/
import {
concatFilesForPrettier,
getEslintFixCmd,
} from './lint-staged.common.mjs';
import { getEslintFixCmd } from './lint-staged.common.mjs';

/**
* @type {Record<string, (filenames: string[]) => string | string[] | Promise<string | string[]>>}
Expand All @@ -21,16 +18,11 @@ const rules = {
cache: true,
// when autofixing staged-files a good tip is to disable react-hooks/exhaustive-deps, cause
// a change here can potentially break things without proper visibility.
rules: ['react-hooks/exhaustive-deps: off'],
rules: [],
maxWarnings: 25,
files: filenames,
});
},
'**/*.{json,md,mdx,css,html,yml,yaml,scss,ts,js,tsx,jsx,mjs}': (
filenames
) => {
return [`prettier --write ${concatFilesForPrettier(filenames)}`];
},
};

export default rules;
13 changes: 4 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@
"clean": "rimraf --no-glob ./dist ./coverage ./.eslintcache ./tsconfig.tsbuildinfo",
"test": "vitest run --dir tests/",
"test-task": "vitest run",
"lint": "eslint . --ext .ts,.mts,.tsx,.js,.jsx,.cjs,.mjs --cache --cache-location .cache/eslint/hyperse-main.eslintcache",
"lint": "eslint .",
"lint-fix": "yarn lint --fix",
"typecheck": "tsc --project ./tsconfig.json --noEmit",
"lint-staged-files": "lint-staged --allow-empty",
"fix-all-files": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs,.mdx,.graphql --fix",
"changeset": "changeset",
"version": "changeset version",
"release": "yarn run build && changeset publish",
"cz": "cz",
"husky": "is-ci || husky"
"prepare": "husky"
},
"config": {
"commitizen": {
Expand All @@ -76,30 +77,24 @@
"@types/paypal__paypalhttp": "^1.0.3"
},
"devDependencies": {
"@armit/eslint-config-bases": "0.1.6",
"@changesets/changelog-git": "0.2.0",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.1",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@hyperse/eslint-config-hyperse": "^1.0.4",
"@swc/core": "1.5.7",
"@types/node": "20.12.12",
"@types/prettier": "3.0.0",
"@types/shell-quote": "1.7.5",
"commitizen": "4.3.0",
"cz-conventional-changelog": "3.3.0",
"dotenv": "16.4.5",
"eslint": "8.x",
"husky": "9.0.11",
"is-ci": "3.0.1",
"lint-staged": "15.2.2",
"minimist": "1.2.8",
"npm-run-all": "4.1.5",
"prettier": "3.2.5",
"rimraf": "5.0.7",
"shell-quote": "1.8.1",
"swc-unplugin-ts": "1.0.3",
"terser": "5.31.0",
"typescript": "5.4.5",
"vite-tsconfig-paths": "4.3.2",
"vitest": "1.6.0"
Expand Down
24 changes: 0 additions & 24 deletions prettier.config.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion samples/AuthorizeIntentExamples/authorizeOrder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { orders } from '@hyperse-io/paypal-node-sdk';
import { createClient } from 'samples/Common/payPalClient.js';
import { orders } from '@hyperse-io/paypal-node-sdk';

/**
* This function can be used to perform authorization on the approved order.
Expand Down
2 changes: 1 addition & 1 deletion samples/AuthorizeIntentExamples/captureOrder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { payments } from '@hyperse-io/paypal-node-sdk';
import { createClient } from 'samples/Common/payPalClient.js';
import { payments } from '@hyperse-io/paypal-node-sdk';

/**
* This function can be used to capture the payment on an authorized Order.
Expand Down
3 changes: 1 addition & 2 deletions samples/AuthorizeIntentExamples/createOrder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { orders } from '@hyperse-io/paypal-node-sdk';
import { createClient } from 'samples/Common/payPalClient.js';
import { orders } from '@hyperse-io/paypal-node-sdk';

/**
* Setting up the complete JSON request body for creating the Order. The Intent
Expand All @@ -10,7 +10,6 @@ function buildCompleteRequestBody() {
return {
intent: 'AUTHORIZE',
application_context: {
// eslint-disable-next-line sonarjs/no-duplicate-string
return_url: 'https://www.example.com',
cancel_url: 'https://www.example.com',
brand_name: 'EXAMPLE INC',
Expand Down
2 changes: 1 addition & 1 deletion samples/CaptureIntentExamples/captureOrder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { orders } from '@hyperse-io/paypal-node-sdk';
import { createClient } from 'tests/test-utils.js';
import { orders } from '@hyperse-io/paypal-node-sdk';

/**
* This function can be used to capture an order payment by passing the approved
Expand Down
2 changes: 1 addition & 1 deletion samples/CaptureIntentExamples/createOrder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { orders } from '@hyperse-io/paypal-node-sdk';
import { createClient } from 'tests/test-utils.js';
import { orders } from '@hyperse-io/paypal-node-sdk';

/**
* Setting up the JSON request body for creating the Order. The Intent in the
Expand Down
5 changes: 2 additions & 3 deletions src/customers/customersPartnerReferralsRequest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import { type BaseCustomerHeaders } from '../types/type-customer.js';

type CustomersPartnerReferralsRequestBody = {
// TODO: Define request body.
};
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
type CustomersPartnerReferralsRequestBody = {};

/**
* Authorizes payment for an order. The response shows authorization details.
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * as core from './core/index.js';
export * as customers from './customers/index.js';
export * as orders from './orders/index.js';
export * as payments from './payments/index.js';
export * as customers from './customers/index.js';
export * as webhook from './webhook/index.js';
export * from './types/index.js';
export * as webhook from './webhook/index.js';
2 changes: 1 addition & 1 deletion src/orders/ordersAuthorizeRequest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type PaymentSource,
type BaseOrderHeaders,
type PaymentSource,
} from '../types/type-order.js';

export type OrdersAuthorizeRequestBody = {
Expand Down
4 changes: 2 additions & 2 deletions src/orders/ordersCreateRequest.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type CheckoutPaymentIntent,
type BaseOrderHeaders,
type CheckoutPaymentIntent,
type OrderApplicationContext,
type Payer,
type PurchaseUnitRequest,
type OrderApplicationContext,
} from '../types/type-order.js';

export type OrdersCreateRequestBody = {
Expand Down
4 changes: 2 additions & 2 deletions src/payments/authorizationsCaptureRequest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type PaymentInstruction,
type Money,
type BasePaymentHeaders,
type Money,
type PaymentInstruction,
} from '../types/type-payment.js';

type AuthorizationsCaptureRequestBody = {
Expand Down
2 changes: 1 addition & 1 deletion src/payments/authorizationsReauthorizeRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import { type Money, type BasePaymentHeaders } from '../types/type-payment.js';
import { type BasePaymentHeaders, type Money } from '../types/type-payment.js';

type AuthorizationsReauthorizeRequestBody = {
amount: Money;
Expand Down
2 changes: 1 addition & 1 deletion src/payments/capturesRefundRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import querystring from 'querystring';
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import { type Money, type BasePaymentHeaders } from '../types/type-payment.js';
import { type BasePaymentHeaders, type Money } from '../types/type-payment.js';

type CapturesRefundRequestBody = {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/webhook/verifyWebhookSignature.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpRequestBase } from '../core/HttpRequestBase.js';
import {
type WebhookEvent,
type BaseWebhookHeaders,
type WebhookEvent,
} from '../types/type-webhook.js';

export type VerifyWebhookSignatureBody = {
Expand Down
Loading

0 comments on commit ef85f9f

Please sign in to comment.