Skip to content

Commit

Permalink
chore: use prettier for code formatting (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
westeezy authored Jul 5, 2022
1 parent 5278232 commit b2cdda9
Show file tree
Hide file tree
Showing 61 changed files with 4,570 additions and 3,788 deletions.
17 changes: 10 additions & 7 deletions .esdoc.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"source": "./src",
"destination": "./dist/docs",
"plugins": [{
"name": "esdoc-standard-plugin"
},{
"name": "esdoc-flow-type-plugin",
"option": {
"enable": true
"plugins": [
{
"name": "esdoc-standard-plugin"
},
{
"name": "esdoc-flow-type-plugin",
"option": {
"enable": true
}
}
}]
]
}
39 changes: 20 additions & 19 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
/* @flow */

module.exports = {
'extends': './node_modules/@krakenjs/grumbler-scripts/config/.eslintrc-browser.js',
extends:
"./node_modules/@krakenjs/grumbler-scripts/config/.eslintrc-browser.js",

globals: {
__STAGE__: true,
__VERSION__: true,
globals: {
__STAGE__: true,
__VERSION__: true,

__PROTOCOL__: true,
__SDK_HOST__: true,
__HOST__: true,
__HOSTNAME__: true,
__PORT__: true,
__PATH__: true,
__STAGE_HOST__: true,
__SERVICE_STAGE_HOST__: true,
__CORRELATION_ID__: true,
__NAMESPACE__: true,
__COMPONENTS__: true,
__FUNDING_ELIGIBILITY__: true,
__PAYPAL_DOMAIN__: true,
__PAYPAL_API_DOMAIN__: true
}
__PROTOCOL__: true,
__SDK_HOST__: true,
__HOST__: true,
__HOSTNAME__: true,
__PORT__: true,
__PATH__: true,
__STAGE_HOST__: true,
__SERVICE_STAGE_HOST__: true,
__CORRELATION_ID__: true,
__NAMESPACE__: true,
__COMPONENTS__: true,
__FUNDING_ELIGIBILITY__: true,
__PAYPAL_DOMAIN__: true,
__PAYPAL_API_DOMAIN__: true,
},
};
2 changes: 1 addition & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ coverage:
project:
default:
target: 50%
client:
client:
target: 50%
flags:
- client
Expand Down
9 changes: 2 additions & 7 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
{
"extends": [
"config:base",
":preserveSemverRanges"
],
"extends": ["config:base", ":preserveSemverRanges"],
"prCreation": "immediate",
"prHourlyLimit": 0,
"rangeStrategy": "status-success",
"separateMajorMinor": false,
"semanticCommits": true,
"timezone": "America/Los_Angeles",
"rebaseStalePrs": true,
"labels": [
":christmas_tree: dependencies"
],
"labels": [":christmas_tree: dependencies"],
"packageRules": [
{
"packagePatterns": "^babel",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: ⎔ Setup node
uses: actions/setup-node@v3
with:
node-version: '14'
node-version: "14"

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
# sets up the .npmrc file to publish to npm
uses: actions/setup-node@v3
with:
node-version: '14'
registry-url: 'https://registry.npmjs.org'
node-version: "14"
registry-url: "https://registry.npmjs.org"

- name: 📥 Download deps
uses: bahmutov/npm-install@v1
Expand Down
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
dist
coverage
flow-typed
CHANGELOG.md
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Feel free to raise a pull request to us. Our team would review your proposed mod
your changes into our code. Ideas and other comments are also welcome.

## Getting Started

1. Create your own [fork](https://help.github.com/articles/fork-a-repo) of this [repository](../../fork).

```bash
# Clone it
$ git clone [email protected]:paypal/paypal-sdk-client.git
Expand All @@ -30,12 +32,14 @@ $ npm run-script cover
```

## Making Changes

1. Make sure that your changes adhere to the current coding conventions used throughout the project, indentation, accurate comments, etc.
2. Lint your code regularly and ensure it passes prior to submitting a PR:
`$ npm run lint`.
`$ npm run lint`.
3. Ensure existing tests pass (`$ npm test`) and include test cases which fail without your change and succeed with it.

## Submitting Changes

1. Ensure that no errors are generated by ESLint.
2. Commit your changes in logical chunks, i.e. keep your changes small per single commit.
3. Locally merge (or rebase) the upstream branch into your topic branch: `$ git pull upstream && git merge`.
Expand Down
59 changes: 28 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PayPal SDK Client
-----------------
## PayPal SDK Client

[![build status][build-badge]][build]
[![code coverage][coverage-badge]][coverage]
Expand All @@ -26,12 +25,12 @@ Your client-side sdk component can take advantage of any common utilities or fun
- Running experiments.

```javascript
import { getClientID } from '@paypal/sdk-client/src';
import { getClientID } from "@paypal/sdk-client/src";

fetch('https://api.paypal.com/v1/foo', {
headers: {
'client-id': getClientID()
}
fetch("https://api.paypal.com/v1/foo", {
headers: {
"client-id": getClientID(),
},
});
```

Expand All @@ -57,47 +56,46 @@ This module helps with that.
1. Import `unpackSDKMeta`:

```javascript
import { unpackSDKMeta } from '@paypal/sdk-client';
import { unpackSDKMeta } from "@paypal/sdk-client";
```

2. Call `unpackSDKMeta` with `req.query.sdkMeta`, passed from the client in the query string, and pass the script tag in the page render.

```javascript
// Listen for requests to your app
app.get('/my-app', (req, res) => {
app.get("/my-app", (req, res) => {
// Unpack the sdk meta payload from the client
const { getSDKLoader } = unpackSDKMeta(req.query.sdkMeta);

// Unpack the sdk meta payload from the client
const { getSDKLoader } = unpackSDKMeta(req.query.sdkMeta);
// Call getSDKLoader to build a script tag, passing in csp nonce, if applicable
const sdkScriptTag = getSDKLoader({ nonce });

// Call getSDKLoader to build a script tag, passing in csp nonce, if applicable
const sdkScriptTag = getSDKLoader({ nonce });

// Insert script tag into response
res.send(`
// Insert script tag into response
res.send(`
<body>
<h1>My App</h1>
${ sdkScriptTag }
${sdkScriptTag}
</body>
`);
})
});
```

3. Ensure the `sdkMeta` payload is passed to the child window from the parent. If you are using [zoid](https://github.com/krakenjs/zoid) to construct your component, please add the following:

```javascript
import { getSdkMeta } from '@paypal/sdk-client/src';
import { getSdkMeta } from "@paypal/sdk-client/src";

let MyComponent = zoid.create({
tag: 'my-component',
url: 'https://www.paypal.com/my-component',
props: {
sdkMeta: {
type: 'string',
value: getSdkMeta,
queryParam: true
}
}
})
tag: "my-component",
url: "https://www.paypal.com/my-component",
props: {
sdkMeta: {
type: "string",
value: getSdkMeta,
queryParam: true,
},
},
});
```

If you are not using zoid, please use `getSdkMeta()` to construct the `sdkMeta` payload, and pass it to your child-window or frame in a different way.
Expand All @@ -109,8 +107,7 @@ If you are not using zoid, please use `getSdkMeta()` to construct the `sdkMeta`
- `unpackSDKMeta` will throw an error if `req.query.sdkMeta` does not validate. This should be handled and translated into a 500 server error, indicating that the payload has been tampered with.
- `unpackSDKMeta` may be passed `undefined` if `req.query.sdkMeta` is not present. This is necessary for some legacy integrations where the sdk metadata is passed via `window.name` entirely on the client-side.

Quick Start
-----------
## Quick Start

#### Installing

Expand Down
6 changes: 3 additions & 3 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

We take security very seriously and ask that you follow the following process.


## Contact us
If you think you may have found a security bug we ask that you privately send the details to [email protected]. Please make sure to use a descriptive title in the email.

If you think you may have found a security bug we ask that you privately send the details to [email protected]. Please make sure to use a descriptive title in the email.

## Expectations
We will generally get back to you within **24 hours**, but a more detailed response may take up to **48 hours**. If you feel we're not responding back in time, please send us a message *without detail* on Twitter [@kraken_js](https://twitter.com/kraken_js).

We will generally get back to you within **24 hours**, but a more detailed response may take up to **48 hours**. If you feel we're not responding back in time, please send us a message _without detail_ on Twitter [@kraken_js](https://twitter.com/kraken_js).

## History

No reported issues
11 changes: 5 additions & 6 deletions __sdk__.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
/* eslint unicorn/filename-case: 0, import/unambiguous: 0, import/no-commonjs: 0 */

module.exports = {

'__paypal-sdk-client__': {
entry: './src/interface',
setupHandler: 'setupClient',
automatic: true
}
"__paypal-sdk-client__": {
entry: "./src/interface",
setupHandler: "setupClient",
automatic: true,
},
};
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/* eslint import/no-commonjs: off */

module.exports = {
extends: '@krakenjs/grumbler-scripts/config/.babelrc-node'
extends: "@krakenjs/grumbler-scripts/config/.babelrc-node",
};
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @flow */

// $FlowFixMe
module.exports = require('./server'); // eslint-disable-line import/no-commonjs
module.exports = require("./server"); // eslint-disable-line import/no-commonjs
37 changes: 18 additions & 19 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
/* @flow */
/* eslint import/no-default-export: off */

import { getKarmaConfig } from '@krakenjs/grumbler-scripts/config/karma.conf';
import { getKarmaConfig } from "@krakenjs/grumbler-scripts/config/karma.conf";

import { WEBPACK_CONFIG_TEST } from './webpack.config';
import { WEBPACK_CONFIG_TEST } from "./webpack.config";

export default function configKarma(karma : Object) {
export default function configKarma(karma: Object) {
const karmaConfig = getKarmaConfig(karma, {
basePath: __dirname,
webpack: WEBPACK_CONFIG_TEST,
});

const karmaConfig = getKarmaConfig(karma, {
basePath: __dirname,
webpack: WEBPACK_CONFIG_TEST
});

karma.set({
...karmaConfig,
coverageReporter: {
reporters: [
{
type: 'lcov',
dir: 'coverage/karma'
}
]
}
});
karma.set({
...karmaConfig,
coverageReporter: {
reporters: [
{
type: "lcov",
dir: "coverage/karma",
},
],
},
});
}
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
"release:minor": "./publish.sh minor",
"release:patch": "./publish.sh patch",
"setup": "npm install && npm run flow-typed",
"test": "npm run lint && npm run flow-typed && npm run flow && npm run jest && npm run karma",
"format": "prettier --write --ignore-unknown .",
"format:check": "prettier --check .",
"test": "npm run format:check && npm run lint && npm run flow-typed && npm run flow && npm run jest && npm run karma",
"webpack": "babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress",
"jest": "jest test/server --env=node --no-cache --collectCoverageFrom='server/' --coverageDirectory='coverage/jest' --coverage --verbose --runInBand --silent=false",
"prepublishOnly": "npm run babel",
"postpublish": "rm -rf ./server && git checkout ./server",
"validate-codecov": "curl --data-binary @.github/codecov.yml https://codecov.io/validate"
"validate-codecov": "curl --data-binary @.github/codecov.yml https://codecov.io/validate",
"prepare": "husky install"
},
"files": [
"dist/",
Expand Down Expand Up @@ -67,6 +70,12 @@
"esdoc-flow-type-plugin": "1.1.0",
"esdoc-standard-plugin": "1.0.0",
"flow-bin": "0.155.0",
"mocha": "^4.1.0"
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"mocha": "^4.1.0",
"prettier": "2.7.1"
},
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
}
}
2 changes: 1 addition & 1 deletion server/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/* eslint import/no-commonjs: off */

module.exports = {
extends: '@krakenjs/grumbler-scripts/config/.babelrc-node'
extends: "@krakenjs/grumbler-scripts/config/.babelrc-node",
};
Loading

0 comments on commit b2cdda9

Please sign in to comment.