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

@W-15248536@ - [v3] Google Search Console fix createCodeVerifier #150

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
},
"dependencies": {
"nanoid": "^3.3.4",
"node-fetch": "2.6.12"
"node-fetch": "2.6.12",
"seedrandom": "^3.0.5"
},
"devDependencies": {
"@babel/cli": "7.18.6",
Expand All @@ -117,6 +118,7 @@
"@types/handlebars-helpers": "^0.5.3",
"@types/node-fetch": "^2.6.2",
"@types/react-dom": "^16.9.16",
"@types/seedrandom": "^3.0.8",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"autoprefixer": "9.8.8",
Expand Down Expand Up @@ -175,11 +177,11 @@
"bundlesize": [
{
"path": "lib/**/*.js",
"maxSize": "45 kB"
"maxSize": "46 kB"
},
{
"path": "commerce-sdk-isomorphic-with-deps.tgz",
"maxSize": "350 kB"
"maxSize": "400 kB"
Copy link

Choose a reason for hiding this comment

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

Is this because that lib has a lot of docs or large source that is being added to the gzip?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume that's the reason as you can see in the previous Joel's comment comparing the before and after file sizes. We added two libraries seedrandom as a dependency and @types/seedrandom as a devDependency.

But as later Joel also mentions the minimized bundle size is the size we care about and that one only increased slightly, 1KB.

}
],
"proxy": "https://SHORTCODE.api.commercecloud.salesforce.com"
Expand Down
13 changes: 10 additions & 3 deletions src/static/helpers/slasHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import {nanoid} from 'nanoid';

import {customRandom, urlAlphabet} from 'nanoid';
import seedrandom, {PRNG} from 'seedrandom';
import {isBrowser} from './environment';

import {
Expand Down Expand Up @@ -39,11 +39,18 @@ export const getCodeAndUsidFromUrl = (
};
};

const nanoid = (): string => {
const rng: PRNG = seedrandom(String(+new Date()), {entropy: true});
return customRandom(urlAlphabet, 128, size =>
new Uint8Array(size).map(() => 256 * rng())
)();
};
adamraya marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates a random string to use as a code verifier. This code is created by the client and sent with both the authorization request (as a code challenge) and the token request.
* @returns code verifier
*/
export const createCodeVerifier = (): string => nanoid(128);
export const createCodeVerifier = (): string => nanoid();

/**
* Encodes a code verifier to a code challenge to send to the authorization endpoint
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3651,6 +3651,11 @@
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39"
integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==

"@types/seedrandom@^3.0.8":
version "3.0.8"
resolved "https://registry.yarnpkg.com/@types/seedrandom/-/seedrandom-3.0.8.tgz#61cc8ed88f93a3c31289c295e6df8ca40be42bdf"
integrity sha512-TY1eezMU2zH2ozQoAFAQFOPpvP15g+ZgSfTZt31AUUH/Rxtnz3H+A/Sv1Snw2/amp//omibc+AEkTaA8KUeOLQ==

"@types/semver@^7.3.4", "@types/semver@^7.3.9":
version "7.3.10"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.10.tgz#5f19ee40cbeff87d916eedc8c2bfe2305d957f73"
Expand Down Expand Up @@ -14790,6 +14795,11 @@ scss-parser@^1.0.4:
dependencies:
invariant "2.2.4"

seedrandom@^3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-3.0.5.tgz#54edc85c95222525b0c7a6f6b3543d8e0b3aa0a7"
integrity sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==

select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
Expand Down
Loading