-
Notifications
You must be signed in to change notification settings - Fork 2
SDKS-3941: Migrate Protect from Legacy to new Ping SDK #274
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
base: main
Are you sure you want to change the base?
Conversation
|
6af5770
to
579c6ba
Compare
View your CI Pipeline Execution ↗ for commit 119cbb2.
☁️ Nx Cloud last updated this comment at |
Deployed a146209 to https://ForgeRock.github.io/ping-javascript-sdk/pr-274/a146209e1fd443e5f79f7a70ca475a6d059efd21 branch gh-pages in ForgeRock/ping-javascript-sdk |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #274 +/- ##
=======================================
Coverage 49.33% 49.33%
=======================================
Files 29 29
Lines 1571 1571
Branches 173 173
=======================================
Hits 775 775
Misses 796 796 🚀 New features to boost your workflow:
|
579c6ba
to
6e4b133
Compare
6e4b133
to
24a1fed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I'll let @ryanbas21 be the final arbiter as most of this has to do with the usual scaffolding/infrastructure implementation.
packages/protect/src/lib/protect.ts
Outdated
*/ | ||
await import('./signals-sdk.js' as string); | ||
} catch (err) { | ||
console.error('error loading ping signals', err); // TODO: should we throw an error here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cerebrl @ryanbas21 I copied this from the legacy sdk but left one comment here. Wondering if we should throw an error if the signals sdk fails to load. Currently if it fails then it will continue to try to initialize anyways... but that will also fail because no methods would have been added to window._pingOneSignals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think throwing an error here makes sense.
@cerebrl I'm curious if maybe it makes more sense to load the signals-sdk in the closure? That way if the signals SDK fails to load, we don't actually return the returning object so there's no confusion on the api "working" at that level.
Obviously this would make the factory async, which is a bit different than what we've typically done. But I think it could be useful to error (if we do) at the creation stage, because without the signals-sdk the api is useless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that's a good idea.
@@ -0,0 +1,29 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ancheetah Can we mark sideEffects
in this package.json. I believe we have to mark the signals sdk as a side effect like we do in legacy.
packages/protect/src/lib/protect.ts
Outdated
*/ | ||
await import('./signals-sdk.js' as string); | ||
} catch (err) { | ||
console.error('error loading ping signals', err); // TODO: should we throw an error here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think throwing an error here makes sense.
@cerebrl I'm curious if maybe it makes more sense to load the signals-sdk in the closure? That way if the signals SDK fails to load, we don't actually return the returning object so there's no confusion on the api "working" at that level.
Obviously this would make the factory async, which is a bit different than what we've typically done. But I think it could be useful to error (if we do) at the creation stage, because without the signals-sdk the api is useless.
*/ | ||
export interface ProtectConfig { | ||
/** | ||
* @param {string} envId - the environment id from your PingOne tenant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small note: these technically are not params
. I think the JSDoc equivalent is property
for these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I can change it to property. I was confused by this doc on the typescript website, not sure if it even pertains to this, but I didn't see property
or interface
as supported so I opted not to use them.
https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the descriptions are formatted a little better with param.
@param consoleLogEnabled — true to enable SDK logs in the developer console. default is false
vs.
@property — {boolean} [consoleLogEnabled] - true to enable SDK logs in the developer console. default is false
could this be because typescript doesnt support property
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are just JSDoc comments, they shouldn't have any affect on typescript. its just a description of the interface/type.
This is mostly a semantic thing.
If you were using the api here in your editor and your intellisense was triggered, you would see @param instead of @Property as a comment, its just a little bit incorrect because it's a property of the object, not a param of a function.
packages/protect/src/lib/protect.ts
Outdated
* @returns {Protect} - a set of methods | ||
*/ | ||
export function createProtect(config: ProtectConfig): Protect { | ||
const options = config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this assignment necessary? We could rename the above parameter to options
if we prefer that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary. I can rename it to options. Think I probably got lazy and didn't want to change the naming in the start method.
24a1fed
to
8623e44
Compare
moved loading signals sdk out of protect api. added test for failed signals sdk load. |
packages/protect/package.json
Outdated
"url": "git+https://github.com/ForgeRock/ping-javascript-sdk.git", | ||
"directory": "packages/protect" | ||
}, | ||
"sideEffects": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have misled you. What I meant was something like this:
This is my reasoning/thought process so let me know if this tracks with you.
Tree shaking is the process of dead code removal. This is a static process, so bundlers are doing this based on the static code available during the uglification/minify process.
The signals SDK is not a module. It's just like an iiffe that is executed when the script loads. Additionally, it modifies the window with new functions that it uses. These modify the global scope (window) which are side effects.
So we need to tell bundlers that this file is effectful. It can't be removed. We rely on the effects produced by this in other code that.
So here we can use an array to say the files we are asking not be removed.
Another common input in sideEffect arrays would be CSS files (in a glob syntax) because CSS also changes the dom.
Another one would be a polyfill that extends the Array prototype.
Now - truth be told, I'm not sure the code style of factory functions is very tree shakeable to begin with because the bundler can't execute the factory to determine if some of the code is used or not later on. So it must include it.
But I could be wrong, or maybe things advanced and I'm not sure, so its worth including it anyways.
packages/protect/README.md
Outdated
@@ -0,0 +1,11 @@ | |||
# protect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also update this to be a bit more descriptive. We may be able to copy over the existing readme
https://github.com/ForgeRock/forgerock-javascript-sdk/blob/develop/packages/ping-protect/README.md
and slightly modify it.
JIRA Ticket
https://pingidentity.atlassian.net/browse/SDKS-3941
Description
Moves Ping Protect module from legacy SDK using functional pattern. Improves JS Doc annotations and unit tests.
No changeset.