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

Script Loader #1

Merged
merged 7 commits into from
Mar 11, 2021
Merged

Script Loader #1

merged 7 commits into from
Mar 11, 2021

Conversation

maxbeatty
Copy link
Contributor

Initial functionality of validating credentials and loading the correct script

Max Beatty added 6 commits February 19, 2021 14:39
this will allow easy merging of squash commits to inform versioning
should prevent class of errors
where developers try to use sandbox application id
with production script src and vice versa
@maxbeatty maxbeatty self-assigned this Feb 24, 2021
@maxbeatty maxbeatty requested a review from a team as a code owner February 24, 2021 03:58
src/load.ts Outdated
}

function injectScript(src: string): HTMLScriptElement {
const script = document.createElement('script');

Choose a reason for hiding this comment

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

nit: create the script element after we know there is a head or body rather than before

}

if (window.Square) {
resolve(window.Square);

Choose a reason for hiding this comment

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

do we want to verify this namespace is valid/ours first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could be more explicit, but I'm not exactly sure how to right away (early days). currently, it'll be implicitly validated when payments is called on it.

? overrides.scriptSrc
: getSrcForApplicationId(applicationId);

const maybeSquare = await loadSquare(src);

Choose a reason for hiding this comment

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

handle rejections?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the next step is to create some examples to better understand how this will be used which should hopefully inform what's useful to handle versus let bubble up. currently, I believe only bad script loads would cause rejections.

@@ -0,0 +1,18 @@
name: Semantic Release

Choose a reason for hiding this comment

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

Do we expect the semver version of our npm module to relate in any way to the WebSDK versions?

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 expect this module to respect the semver of websdk but not move in lock step. for example, if websdk releases v42 then this module would create a major release changing the version constant in the loader. if a breaking change is needed here, it can release a major bump independently.

@@ -21,6 +21,7 @@
"babel-jest": "^26.6.3",
"conventional-changelog-conventionalcommits": "^4.5.0",
"eslint": "^7.19.0",
"eslint-plugin-jest": "^24.1.5",

Choose a reason for hiding this comment

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

Should we prefer yarn instead of npm give that this is what we use in the WebSDK?

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'm starting w/ npm since v7 filled a lot of the gaps yarn v1 previously filled. I'm hoping it'll also set up all the docs, examples, and CI scripts to be pure npm for versioning, publishing, etc. (you can use yarn out of habit and may not even notice)

@@ -0,0 +1,11 @@
interface Payments {
verifyBuyer: () => void;

Choose a reason for hiding this comment

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

// TODO: Add all of our typings? :)

}

try {
let script = findScript(src);

Choose a reason for hiding this comment

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

I'm trying to understand the reason why a script might already be present given we're caching the promise value. Is this an edge case, or something we expect to happen often?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

definite edge case in an attempt not to double-load by accident

src = 'https://sandbox.websdk.squarecdn.com/';
}

if (src.length === 0) {
Copy link

@prettymuchbryce prettymuchbryce Feb 25, 2021

Choose a reason for hiding this comment

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

Worth a reminder here that this assumption is somewhat flawed. There are application IDs in the wild that don't use the prefixes.

@maxbeatty maxbeatty merged commit 3da504f into beta Mar 11, 2021
@maxbeatty maxbeatty deleted the loader branch March 11, 2021 17:08
@github-actions
Copy link

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@maxbeatty maxbeatty mentioned this pull request Mar 16, 2021
maxbeatty pushed a commit that referenced this pull request Mar 24, 2021
* beta:
  ci: add npm token
  ci: semantic-release to publish to npm (#3)
  docs: add license to readme
  fix: typos, docs (#2)
  feat: Script Loader (#1)
  chore: add code owners
  ci: cache dependencies
  ci: run against pushes and PRs for main and beta
  docs: semantic-release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants