prismatic-embedded

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Embed Prismatic

嵌入 Prismatic

Embedding lets the user's customers manage integrations without leaving the user's app. The backend signs a short-lived JWT for the signed-in user; the browser passes it to the
@prismatic-io/embedded
SDK, which renders Prismatic screens in an iframe. Use the embedding docs and the installed SDK's public types for current behavior, and
prism --llms
and command
--help
to discover Prism's organization and signing-key commands.
Start from the user's request and the current application. Identify the frontend framework, the backend, the existing authentication and session model, how a user maps to a tenant, where configuration and secrets come from, and the existing tests. Extend the app's own patterns: its router, auth middleware, API client, config module, and test setup. Infer technical choices from the code. Ask only about business decisions the code cannot answer, such as which app tenant is a Prismatic customer, which screens to embed, where they go, and who may see them.
Sign tokens on a server the user controls; read authentication before writing the endpoint. A private key in browser code, a browser-visible environment variable, or a client bundle lets anyone mint tokens for any customer. When asked to sign in the browser, explain this in plain terms and add the smallest backend endpoint the app supports.
Protect the endpoint with the app's existing authentication. Take the user and customer identity only from the authenticated session, never from query parameters, request bodies, or headers the browser controls. Use stable IDs: the user's ID for
sub
and the tenant's Prismatic customer external ID for
customer
. Read the private key and organization ID from the app's server-side configuration, and fail with a clear server error when either is missing, without logging the key. Return the token and its expiry.
The organization ID is on the Embedded tab of Prismatic's organization settings;
prism me
also prints it. A real private key must never appear in the project, command output, logs, responses, or your messages. For tests, generate a throwaway key pair in the test instead of committing one.
Creating, importing, or deleting signing keys changes the Prismatic organization. Do it only when the user asks; otherwise give them the steps in authentication. When asked to create a key, run Prism's signing-key
generate
command with
--private-key-file
set to a new path outside the repository, then tell the user where the file is and let them move the key into their secret store. Do not read, print, copy, or load the file, including into a shell variable or the app for a smoke test; test with a throwaway key pair instead. If the installed Prism has no
--private-key-file
option, do not run
generate
; give the user the steps instead.
Read browser SDK before writing frontend code. The SDK keeps one global session, so give it three separate lifetimes. Initialize once per page load, outside component mount and unmount:
init
and
dispose
both clear the token, so a remount that repeats either one, such as React StrictMode's double effect, loses the session. Keep the session alive by fetching a token, calling
authenticate
, and scheduling the next refresh before expiry; a refresh calls only
authenticate
, because calling the screen method again reloads the iframe. Render the screen once, after the first successful authentication and after its container is mounted. Show a visible error when fetching or authenticating fails, and set
prismaticUrl
when the organization is not on
https://app.prismatic.io
.
Match the host app's look. Read theming, find the app's colors, font, and dark-mode mechanism, and pass what the SDK supports: the current light or dark mode, a Google font, and loading-screen colors. Brand colors live in the organization's theme, which affects every customer; hand off the values for it instead of changing it unless the user asks. For filters, translations, other screens, the workflow builder, or a custom marketplace UI, check the SDK types and the matching page under the embedding docs, and add only what the user asked for.
Test the token endpoint without Prismatic: sign with a generated key pair, verify the signature with the public key, and assert every required claim on the decoded token rather than on the payload you passed in, because library options can drop or overwrite claims. Check that unauthenticated requests are rejected and that browser-supplied identity values are ignored. Test frontend logic against a mocked SDK where the app has a frontend test setup. Run the app's typecheck, lint, tests, and build, then start the backend the way the app runs it and request a token: test runners can load modules that the app's own runtime rejects.
Do not call Prismatic APIs, register keys, or change organization settings unless the user asked. Report what changed, the configuration to set, the signing-key steps that remain, where the embedded screen appears, and what was verified locally. When you matched the app's look, include the organization theme values for Embedded Light and Embedded Dark from theming, with their source files. State that a real sign-in needs a registered key and the real organization ID.
嵌入可让用户自己的客户在无需离开用户应用的情况下管理集成。后端为已登录用户签署短期 JWT;浏览器将其传递给
@prismatic-io/embedded
SDK,该 SDK 在 iframe 中呈现 Prismatic 屏幕。应以嵌入文档和已安装 SDK 的公共类型了解当前行为,并使用
prism --llms
和命令
--help
查找 Prism 的组织管理与签名密钥命令。
从用户请求和当前应用入手。确定前端框架、后端、现有身份验证与会话模型、用户如何映射到租户、配置和密钥来源,以及现有测试。沿用应用自身的模式,包括其路由、auth 中间件、API 客户端、配置模块和测试设置。从代码中推断技术选择。仅询问代码无法回答的业务决策,例如哪个应用租户是 Prismatic 客户、要嵌入哪些屏幕、这些屏幕放在哪里,以及谁可以看到它们。
在用户控制的服务器上签署 token;编写端点前阅读身份验证。浏览器代码中的私钥、浏览器可见的环境变量或客户端 bundle 会让任何人为任意客户签发 token。当用户要求在浏览器中登录时,请用通俗语言解释这一点,并添加该应用支持的最小型后端端点。
使用应用现有的身份验证机制保护端点。用户和客户身份只能取自已认证会话,绝不能取自 query 参数、请求体或浏览器可控制的 header。使用稳定的 ID:用户 ID 用作
sub
,租户的 Prismatic 客户外部 ID 用作
customer
。从应用的服务端配置中读取私钥和组织 ID;如果缺少其中任何一项,则返回清晰的服务器错误,且不得记录密钥。返回 token 及其过期时间。
组织 ID 位于 Prismatic 组织设置的 Embedded 选项卡中;
prism me
也会打印它。真实私钥绝不能出现在项目、命令输出、日志、响应或消息中。对于测试,应在测试中生成一次性密钥对,而不是提交真实密钥。
创建、导入或删除签名密钥会更改 Prismatic 组织。仅在用户明确要求时执行;否则,提供身份验证中的相关步骤。当用户要求创建密钥时,运行 Prism 的签名密钥
generate
命令,并将
--private-key-file
设置为仓库外的新路径,然后告知用户文件的位置,让用户自行将密钥移入 secret store。不得读取、打印、复制或加载该文件,包括将其加载到 shell 变量或应用中执行 smoke test;应改用一次性密钥对进行测试。如果已安装的 Prism 没有
--private-key-file
选项,则不要运行
generate
;改为向用户提供操作步骤。
编写前端代码前阅读浏览器 SDK。SDK 维护一个全局会话,因此需要为它提供三个相互独立的生命周期。每次页面加载只初始化一次,并且必须置于组件 mount 和 unmount 之外:
init
和
dispose
都会清除 token,因此重复执行其中任一操作,例如 React StrictMode 的双重 effect,都会丢失会话。通过获取 token、调用
authenticate
并在过期前安排下一次刷新来保持会话;刷新时只调用
authenticate
,因为再次调用 screen 方法会重新加载 iframe。在首次成功认证且容器挂载后,只渲染一次屏幕。获取或认证失败时显示明确的错误;当组织不在
https://app.prismatic.io
时,设置
prismaticUrl
。
匹配宿主应用的外观。阅读主题配置,找出应用的颜色、字体和 dark-mode 机制,并传入 SDK 支持的内容:当前的 light mode 或 dark mode、Google font,以及加载屏幕颜色。品牌颜色位于组织主题中,会影响所有客户;除非用户要求,否则只移交相应值,不应自行更改。对于筛选器、翻译、其他屏幕、workflow builder 或自定义 marketplace UI,应检查 SDK 类型和嵌入文档中的对应页面,并且只添加用户要求的功能。
无需依赖 Prismatic 即可测试 token 端点:使用生成的密钥对进行签名,通过公钥验证签名,并针对解码后的 token 断言每个必需 claim,而不是针对传入的 payload 进行断言,因为库的选项可能会丢弃或覆盖 claim。检查未认证请求是否被拒绝,以及浏览器提供的身份值是否被忽略。如果应用具备前端测试环境,则使用 mocked SDK 测试前端逻辑。运行应用的 typecheck、lint、测试和 build,然后按照应用的实际运行方式启动后端并请求 token:测试运行器可能会加载应用运行时本身会拒绝的模块。
除非用户要求,否则不要调用 Prismatic API、注册密钥或更改组织设置。报告所做的更改、需要设置的配置、仍需执行的签名密钥步骤、嵌入式屏幕出现的位置,以及已在本地验证的内容。当已匹配应用外观时,包含主题配置中 Embedded Light 和 Embedded Dark 的组织主题值及其源文件。说明真实登录需要已注册的密钥和真实的组织 ID。