@forgerock/ping-protect

中文文档
4.7.1发布于 2026/05/06TypeScriptES Module构建来源已验证近 30 天下载 8.5万

The Ping Protect module is intended to be used along with the ForgeRock JavaScript SDK to provide the Ping Protect feature to our existing ForgeRock SDK customers.

原始使用文档
文档目录4 节
  1. Overall Design
  2. Quick Start for Client Application
  3. Error Handling
  4. Full API

Ping Protect

The Ping Protect module is intended to be used along with the ForgeRock JavaScript SDK to provide the Ping Protect feature to our existing ForgeRock SDK customers.

Overall Design

There are two components on the server side and two components on the client side to enable this feature. You'll need to have the following:

  1. ForgeRock Identity Cloud (aka ID Cloud) platform or an up-to-date ForgeRock Access Management (aka AM)
  2. PingOne tenant with Protect enabled
  3. A Ping Protect Service configured in ID Cloud or AM
  4. A journey/tree with the appropriate Protect Nodes
  5. A client application with the @forgerock/javascript-sdk and @forgerock/ping-protect modules installed

Quick Start for Client Application

Install both modules and their latest versions:

npm install @forgerock/javascript-sdk @forgerock/ping-protect
pnpm add @forgerock/javascript-sdk @forgerock/ping-protect

The two main responsibilities of the Ping Protect module is the initialization of the profiling and data collection and the completion and preparation of the collected data for the server. You can find the two methods on the PIProtect module found within the @forgerock/ping-protect module.

  • PIProtect.start()
  • PIProtect.getData()

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.

When calling start, you have many different options to configure what and how the data is collected. The most important and required of these settings is the envId. All other settings are optional.

import { PIProtect } from '@forgerock/ping-protect';

// Call early in your application startup
PIProtect.start({ envId: '02fb1243-189a-4bc7-9d6c-a919edf6447' });

Alternatively, you can delay the initialization until you receive the instruction from the server by way of the special callback: PingOneProtectInitializeCallback. To do this, you would call the start method when the callback is present in the journey.

import { PIProtect } from '@forgerock/ping-protect';

if (step.getCallbacksOfType('PingOneProtectInitializeCallback')) {
  try {
    // Asynchronous call
    await PIProtect.start({ envId: '02fb1243-189a-4bc7-9d6c-a919edf6447' });
  } catch (err) {
    // handle error
  }
}

You then call the FRAuth.next method after initialization to move the user forward in the journey.

FRAuth.next(step);

At some point in the journey, and as late as possible in order to collect as much data as you can, you will come across the PingOneProtectEvaluationCallback. This is when you call the getData method to package what's been collected for the server to evaluate.

import { PIProtect } from '@forgerock/ping-protect';

let data;

if (step.getCallbacksOfType('PingOneProtectEvaluationCallback')) {
  try {
    // Asynchronous call
    data = await PIProtect.getData();
  } catch (err) {
    // handle error
  }
}

Now that we have the data, set it on the callback in order to send it to the server when we call next.

callback.setData(data);

FRAuth.next(step);

Error Handling

When you encounter an error during initialization or evaluation, set the error message on the callback using the setClientError method. Setting the message on the callback is how it gets sent to the server on the FRAuth.next method call.

if (step.getCallbacksOfType('PingOneProtectInitializeCallback')) {
  const callback = step.getCallbackOfType('PingOneProtectInitializeCallback');
  try {
    // Asynchronous call
    await PIProtect.start({ envId: '02fb1243-189a-4bc7-9d6c-a919edf6447' });
  } catch (err) {
    callback.setClientError(err.message);
  }
}

A similar process is used for the evaluation step.

let data;

if (step.getCallbacksOfType('PingOneProtectEvaluationCallback')) {
  const callback = step.getCallbackOfType('PingOneProtectEvaluationCallback');
  try {
    // Asynchronous call
    data = await PIProtect.getData();
  } catch (err) {
    callback.setClientError(err.message);
  }
}

Full API

// PIProtect class methods
PIProtect.start();
PIProtect.getData();
PIProtect.pauseBehavioralData();
PIProtect.resumeBehavioralData();
// PingOneProtectInitializeCallback class methods
callback.getConfig();
callback.setClientError();
// PingOneProtectEvaluationCallback class methods
callback.setData();
callback.setClientError();
callback.getPauseBehavioralData();

版本与发布记录

@forgerock/ping-protect 共发布 33 个版本,首次发布于 2024/03/14;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.7.1latest2026/05/066 个月前
0.0.0-beta-20260505164724beta2026/05/066 个月前
4.7.02026/03/128 个月前
0.0.0-beta-202603102018122026/03/118 个月前
0.0.0-beta-202603051616152026/03/068 个月前
0.0.0-beta-202602262111072026/02/278 个月前

其他发布通道:alpha → 4.4.1-alpha.2,beta → 0.0.0-beta-20260505164724。

关于 @forgerock/ping-protect 的常见问题

@forgerock/ping-protect 是什么?

The Ping Protect module is intended to be used along with the ForgeRock JavaScript SDK to provide the Ping Protect feature to our existing ForgeRock SDK customers.

如何安装 @forgerock/ping-protect?

在项目目录运行 npm install @forgerock/ping-protect,或使用 pnpm add / yarn add / bun add。

@forgerock/ping-protect 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@forgerock/ping-protect 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@forgerock/ping-protect 可以商用吗?

@forgerock/ping-protect 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@forgerock/ping-protect 的下载量有多少?

根据 npm 官方下载统计,@forgerock/ping-protect 在 2026/10/16 – 2026/11/14 这 30 天内被下载 84,988 次,日均约 2,833 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@forgerock/ping-protect 还在维护吗?

最新版本 4.7.1 发布于 2026/05/06(6 个月前);至今共发布 33 个版本,其中过去 12 个月发布了 11 个;首次发布于 2024/03/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。