Skip to content

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

Merged
merged 1 commit into from
May 21, 2025

Conversation

ancheetah
Copy link
Collaborator

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.

Copy link

changeset-bot bot commented May 7, 2025

⚠️ No Changeset found

Latest commit: f3ecb6c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ancheetah ancheetah marked this pull request as draft May 7, 2025 22:53
@ancheetah ancheetah force-pushed the SDKS-3941-ping-protect branch from 6af5770 to 579c6ba Compare May 7, 2025 22:57
Copy link

nx-cloud bot commented May 7, 2025

View your CI Pipeline Execution ↗ for commit f3ecb6c.

Command Status Duration Result
nx affected -t build typecheck lint test e2e-ci ✅ Succeeded 1m 43s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2025-05-21 19:49:00 UTC

Copy link
Contributor

github-actions bot commented May 7, 2025

Deployed f34d851 to https://ForgeRock.github.io/ping-javascript-sdk/pr-274/f34d851c0e15e3adfffb2d7e51203b615c130c46 branch gh-pages in ForgeRock/ping-javascript-sdk

@codecov-commenter
Copy link

codecov-commenter commented May 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 50.26%. Comparing base (b9867d1) to head (f3ecb6c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #274   +/-   ##
=======================================
  Coverage   50.26%   50.26%           
=======================================
  Files          29       29           
  Lines        1711     1711           
  Branches      196      195    -1     
=======================================
  Hits          860      860           
  Misses        851      851           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ancheetah ancheetah requested review from ryanbas21 and cerebrl May 7, 2025 23:01
@ancheetah ancheetah force-pushed the SDKS-3941-ping-protect branch from 579c6ba to 6e4b133 Compare May 8, 2025 14:43
@ancheetah ancheetah marked this pull request as ready for review May 8, 2025 14:44
@ancheetah ancheetah force-pushed the SDKS-3941-ping-protect branch from 6e4b133 to 24a1fed Compare May 8, 2025 14:52
Copy link
Collaborator

@cerebrl cerebrl left a 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.

@ancheetah ancheetah force-pushed the SDKS-3941-ping-protect branch from 24a1fed to 8623e44 Compare May 8, 2025 19:19
@ancheetah
Copy link
Collaborator Author

moved loading signals sdk out of protect api. added test for failed signals sdk load.

@ancheetah ancheetah requested review from ryanbas21 and cerebrl May 8, 2025 19:23
"url": "git+https://github.com/ForgeRock/ping-javascript-sdk.git",
"directory": "packages/protect"
},
"sideEffects": true,
Copy link
Collaborator

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:

https://github.com/ForgeRock/forgerock-javascript-sdk/blob/develop/packages/ping-protect/package.json#L14

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.

@ancheetah ancheetah marked this pull request as draft May 9, 2025 15:25
@ancheetah ancheetah marked this pull request as ready for review May 9, 2025 16:27
Copy link
Collaborator

@ryanbas21 ryanbas21 left a comment

Choose a reason for hiding this comment

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

Great work!

@ancheetah ancheetah requested review from cerebrl and ryanbas21 May 13, 2025 17:49
@ancheetah
Copy link
Collaborator Author

@ryanbas21 @cerebrl please review again. Added support for marketplace nodes, updated readme with important note, and changed the module name from createProtect to protect. Also I updated the ProtectInitializeConfig type and it was a little strange to me. Should it just extend from the ProtectConfig type?

@ancheetah ancheetah force-pushed the SDKS-3941-ping-protect branch from 927f19b to a522e9a Compare May 15, 2025 16:32
Comment on lines +78 to +84
export interface ProtectInitializeConfig
extends Omit<ProtectConfig, 'envId' | 'waitForWindowLoad' | 'hubUrl' | 'externalIdentifiers'> {
_type: 'PingOneProtect';
_action: 'protect_initialize';
envId?: string;
customHost?: string;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ryan says, "It's fine"

Copy link
Collaborator

@cerebrl cerebrl left a comment

Choose a reason for hiding this comment

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

This looks good. I think there's just one correction needed in the README.md file to reflect the name change in the exported function.

The `start` method can be called at application startup, or when you receive the `PingOneProtectInitializeCallback` callback from the server. We recommend you call `start` as soon as you can to collect as much data as possible for higher accuracy.

```js
import { createProtect } from '@pingidentity/protect';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This import is now just protect, yeah?

@ancheetah ancheetah force-pushed the SDKS-3941-ping-protect branch from b9d2d27 to 86c863d Compare May 17, 2025 21:46
@ancheetah
Copy link
Collaborator Author

updated readme with new naming for protect module and squashed commits

return undefined;
}

const protectMetadataCb = cbs.find((metadataCallback) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there any chance that there are no metadata callbacks and this produces undefined?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't remember, so maybe i should look into this. I maybe wrote it like this originally.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nevermind I see the check below

@ancheetah ancheetah force-pushed the SDKS-3941-ping-protect branch from 86c863d to f3ecb6c Compare May 21, 2025 19:46
@ancheetah ancheetah merged commit 39c94fc into main May 21, 2025
4 checks passed
@ancheetah ancheetah deleted the SDKS-3941-ping-protect branch May 21, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants