一键导入
sdk-key-management
Use when changing SDK key creation, hashing, display, revocation, public lookup, or related audit behavior.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when changing SDK key creation, hashing, display, revocation, public lookup, or related audit behavior.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use when adding, changing, extracting, or reusing client components, including Storybook stories and controls.
Use when adding or changing forms in apps/client.
Use when changing GitHub OAuth, session cookies, SessionGuard, logout, or authenticated API request identity.
Use when adding or changing routes in apps/client.
Use when adding or changing client state, React Query data flow, immutable context values, or Zustand stores.
Use when styling apps/client with Tailwind CSS v4.
| name | sdk-key-management |
| description | Use when changing SDK key creation, hashing, display, revocation, public lookup, or related audit behavior. |
Generated from ai/registry.json. Do not edit manually.
Canonical skill: ../../../ai/skills/sdk-key-management.md.
Referenced context:
../../../ai/rules/sdk-key-rules.md../../../ai/rules/api-tenant-access-rules.md../../../ai/architecture/sdk-key-lifecycle.md../../../ai/glossary/config-sdk-terms.md../../../ai/examples/good-sdk-key-service.mdThis file is compiled from canonical AI knowledge files. Edit canonical files under ai, then run npm run ai:sync.
ai/skills/sdk-key-management.mdUse this skill when changing SDK key creation, display, hashing, revocation, public lookup, or related audit behavior.
Preserve SDK keys as hashed read-only credentials scoped to one config and one environment.
ai/rules/sdk-key-rules.mdai/rules/api-tenant-access-rules.mdai/architecture/sdk-key-lifecycle.mdai/glossary/config-sdk-terms.mdai/examples/good-sdk-key-service.mdsdk-key-crypto.keyPrefix, not raw keys.npm --workspace @capture-flag/api run test after SDK key behavior changes.npm --workspace @capture-flag/api run build after service or controller changes.ai/rules/sdk-key-rules.mdRules for SDK key creation, storage, display, revocation, and public lookup.
createRawSdkKey() and hash them with hashSdkKey() before persistence.keyHash and a display-safe keyPrefix.project_admin for SDK key creation and revocation.configId and environmentId both belong to the target project before creating a key.ai/rules/api-tenant-access-rules.mdRules for private API authorization and tenant isolation.
SessionGuard and AuthenticatedRequest on session-only private API controllers.AuthenticatedApiGuard plus API token tenant/scope guards on private management routes that also accept API tokens.request.user.id, and delegate rules to services.AccessService before returning or mutating tenant-owned data.requireProjectAccess for project-scoped reads.requireProjectRole for project-scoped writes with the narrowest allowed project roles.requireOrganizationMember or requireOrganizationRole for organization-level reads and writes.owner and admin roles can satisfy project access without explicit project membership.developer scoped to feature flag writes; do not allow it to manage segments, SDK keys, environments, configs, project members, or roles.include or nested select shapes.configId and environmentId must belong to the same projectId before SDK keys, flag values, or config state changes.ai/architecture/sdk-key-lifecycle.mdSDK keys authenticate public config reads without session auth.
project_admin through AccessService.requireProjectRole.createRawSdkKey() creates the only raw key shown to the user.hashSdkKey() stores the lookup hash; keyPrefix is stored for display.sdk_keys.key_hash.lastUsedAt, including 304 Not Modified responses.Revocation requires project_admin, sets revokedAt, and writes an audit log. Revoked keys cannot fetch public config.
ai/glossary/config-sdk-terms.mdTerms shared by API, public config, evaluator, SDK, and client UI.
SDK-visible setting controlled by Capture Flag. Supported types are boolean, string, integer, double, json_object, and json_array.
Configured flag value stored in the database and emitted in Config JSON. This is not the same as SDK fallback value.
Value supplied by application code when calling getValue. The SDK returns fallback when config is unavailable, invalid, missing, or type-mismatched.
Ordered targeting rules emitted as rules in public Config JSON. The evaluator checks rules before percentage rollout.
Reusable group of attribute conditions scoped to one config and emitted as segments in public Config JSON.
A rule condition shaped as { "segment": "segment-key" }. It is evaluated locally by checking the referenced segment conditions against the Evaluation Context.
A rule condition shaped as { "prerequisiteFlag": "flag-key", "operator": "equals", "value": true }. It evaluates another flag from the same Config JSON locally before deciding whether the current rule matches.
Targeting features beyond simple attribute equality: prerequisite flags, arrayContains, date comparisons, and SemVer comparisons.
Deterministic distribution of values based on a rollout attribute such as identifier.
Context attribute used for rollout bucketing. Defaults to identifier.
Read-only credential scoped to one config and one environment. Stored as a hash in the API database.
The full SDK credential shown only immediately after creation. It must never be stored, logged, audited, or re-displayed.
Display-safe prefix derived from the raw SDK key and stored for UI identification and audit metadata.
Versioned public JSON downloaded by SDKs. It contains local-evaluation data, not evaluated flag results.
React provider and hook package that receives a JavaScript SDK client and evaluates flags through that client.
Per config + environment state that stores revision, ETag, and generated timestamp for public config caching.
HTTP cache validator used by SDK clients through If-None-Match.
Default SDK mode. The client fetches config only when no cache exists or when the cached entry is older than cacheTtlMs.
SDK mode where the JavaScript client refreshes config in the background on pollIntervalMs.
SDK mode where getValue uses the current cache and the application calls refresh() to fetch new config.
SDK mode where the client uses only existing cache and never performs network requests.
Default in-process SDK cache used by every client instance.
Browser persistent cache enabled explicitly through SDK options. It stores config, ETag, timestamp, cache schema version, and scope fingerprints, never raw SDK keys or raw base URLs.
Duration used by lazy loading to decide whether a cached config should be refreshed.
ETag stored with the cached config and sent on refresh through If-None-Match.
client.close() stops SDK-owned background polling timers.
ai/examples/good-sdk-key-service.mdSource: apps/api/src/sdk-keys/use-cases/create-sdk-key.service.ts (sha256: e2c83a6bdf1653fc73daa5a2e07e2ddb2efcd2bd01b8f4e8e2249eb222bcdc51)
Source: apps/api/src/sdk-keys/use-cases/revoke-sdk-key.service.ts (sha256: b1e6316e25347dfbd6fd6c7a3b4431361ca11c2eb206e3c18d1cbadd422576f8)
Source: apps/api/src/sdk-keys/use-cases/rotate-sdk-key.service.ts (sha256: b88c81c89b3ef70f5cb8ab730ae23982dfd5520f24c7c91cd9c07d988fa1625a)
Source: apps/api/src/common/sdk-key-crypto.ts (sha256: 9e1b5884fe94d12dd4004e39e0aa9a90328e1351a79215c1b8c53b81293c5a04)
Why this is canonical:
const credential = this.sdkKeyCredential.createCredential();
const sdkKey = await tx.sdkKey.create({
data: {
projectId,
configId: config.id,
environmentId: environment.id,
name: input.name?.trim() || `${config.name} ${environment.name} SDK Key`,
keyPrefix: credential.keyPrefix,
keyHash: credential.keyHash,
},
});
Only keyHash and keyPrefix are persisted.
return {
...sdkKey,
key: credential.rawKey,
};
The raw key is returned only immediately after creation.