Feature/plugins#31
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThis PR refactors Tempo's licensing system to support JWT-based permission scopes, updates the license discovery cascade, and introduces a new indexedArray utility for proxy-based array indexing. The public Tempo.license API now returns a formatted user-facing snapshot instead of raw internal state, while the terms registry gains scope-aware indexing. Documentation and test coverage are expanded accordingly. ChangesLicensing System and Indexing Improvements
Sequence Diagram(s)sequenceDiagram
participant App as Application Code
participant InitFlow as Tempo.init()
participant Discover as License Discovery
participant Validator as Validator.verify()
participant Runtime as Runtime State
App->>InitFlow: call init({ license?: string })
InitFlow->>Discover: check options.license
alt no options.license
Discover->>Discover: check process.env.TEMPO_LICENSE_KEY
alt no env key
Discover->>Discover: check globalThis.TEMPO_LICENSE_KEY
end
end
Discover->>Validator: setLicense(state, discoveredKey)
Validator->>Validator: decodeJWT(key) -> claims.permissions
Validator->>Runtime: populate scopes and store license
Runtime->>App: Tempo.license (user-facing snapshot with formatted timestamps)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/tempo/bin/resolve-types.ts`:
- Line 16: Change LIC_SRC_DIR to be resolved relative to the script file instead
of process.cwd by using __dirname (e.g. path.resolve(__dirname,
'../../../tempo-plugin/internal/@core/dist') or path.join(__dirname, '..', '..',
'..', 'tempo-plugin', 'internal', '`@core`', 'dist')) and then immediately verify
the directory exists (fs.existsSync) before proceeding; if it does not exist,
log an explicit error and process.exit(1) so the code does not silently fall
back to the minimal license typings referenced later in the script (the
LIC_SRC_DIR constant and the minimal-types fallback section).
In `@packages/tempo/doc/tempo-vs-temporal.md`:
- Around line 85-97: The examples use dynamic now() by instantiating new Tempo()
and assert exact outputs which will drift; make them deterministic by
constructing Tempo with a fixed anchor datetime (e.g., pass an explicit
reference date or use a Tempo.from/Tempo.withAnchor helper) so
Tempo().fmt.logStamp and expressions like until('xmas', ...) produce stable
output in docs—update the examples that call Tempo, Tempo.init, .fmt.logStamp
and until(...) to create the Tempo instance from a fixed Date/time value so the
demonstrated outputs remain constant.
In `@packages/tempo/src/support/support.init.ts`:
- Around line 135-138: The change removed legacy fallbacks for TEMPO_LICENSE
causing downstream breakage; restore the older fallbacks while keeping
TEMPO_LICENSE_KEY precedence: in the initialization logic around the variable
key (calls to getStorage and globalThis), ensure you first try
getStorage('TEMPO_LICENSE_KEY') and (globalThis as any).TEMPO_LICENSE_KEY, then
if still falsy fall back to getStorage('TEMPO_LICENSE') and (globalThis as
any).TEMPO_LICENSE respectively so both legacy and new env keys are supported
(locate this logic by looking for getStorage and TEMPO_LICENSE_KEY /
TEMPO_LICENSE references).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 679ec555-7fa6-45d5-8563-82de01037b70
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (14)
package.jsonpackages/library/package.jsonpackages/library/src/common/proxy.library.tspackages/library/src/common/storage.library.tspackages/tempo/bin/resolve-types.tspackages/tempo/doc/comparison.mdpackages/tempo/doc/tempo-vs-temporal.mdpackages/tempo/doc/tempo.cookbook.mdpackages/tempo/doc/tempo.license.mdpackages/tempo/package.jsonpackages/tempo/src/support/support.init.tspackages/tempo/src/support/support.license.tspackages/tempo/src/tempo.class.tspackages/tempo/test/plugins/licensing.full.test.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/tempo/src/tempo.class.ts (1)
99-110:⚠️ Potential issue | 🟠 Major | ⚡ Quick winGuard
raw.scopesbefore iterating inTempo.license.If
raw.scopesis missing or non-object, Line 102 can throw and break the public license getter. Normalize it beforeObject.entries(...).Suggested patch
static get license() { const { jws, key, ...raw } = Tempo.#license; // omit internal Pledge and JWT string from user-facing snapshot const ss = { timeStamp: 'ss' } as const; // JWT timestamps are always in seconds (RFC 7519) + const rawScopes = isObject(raw.scopes) ? raw.scopes as Record<string, any> : {}; const scopes = Object.fromEntries( - Object.entries(raw.scopes).map(([key, scope]) => { + Object.entries(rawScopes).map(([key, scope]) => { const s = scope as any; return [key, { ...s, ...(typeof s.exp === 'number' && { exp: new Tempo(s.exp, ss).fmt.weekTime }), ...(typeof s.updated_at === 'number' && { updated_at: new Tempo(s.updated_at, ss).fmt.weekTime }), }]; }) );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/tempo/src/tempo.class.ts` around lines 99 - 110, The public license snapshot generation uses raw.scopes without guarding it, which can throw when raw.scopes is missing or not an object; update the Tempo.license getter (where Tempo.#license is destructured and scopes is computed) to normalize/guard raw.scopes before iterating — e.g., set const scopesSource = (raw.scopes && typeof raw.scopes === 'object') ? raw.scopes : {} and then run Object.entries(scopesSource).map(...), preserving the existing mapping that uses new Tempo(...).fmt.weekTime for exp and updated_at so callers never hit an exception when scopes is absent or invalid.
♻️ Duplicate comments (1)
packages/tempo/bin/resolve-types.ts (1)
16-16:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winFix Windows/URL path handling in
packages/tempo/bin/resolve-types.ts
new URL(import.meta.url).pathnamecan break path handling on Windows (URL encoding / drive-letter quirks); usefileURLToPath(import.meta.url)(orimport.meta.dirnameon newer Node) instead.- The hard-fail for missing
LIC_SRC_DIRand the follow-up simplified license copy logic are consistent and good.- Optional: allow overriding
LIC_SRC_DIRvia env var for local/dev environments.🔧 Proposed fix
import fs from 'node:fs'; import path from 'node:path'; +import { fileURLToPath } from 'node:url'; -const __dirname = path.dirname(new URL(import.meta.url).pathname); +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const LIC_SRC_DIR = path.resolve(__dirname, '../../../../tempo-plugin/internal/@core/dist');🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/tempo/bin/resolve-types.ts` at line 16, Replace the fragile URL-based dirname computation that uses "const __dirname = path.dirname(new URL(import.meta.url).pathname);" with Node's fileURLToPath(import.meta.url) to derive __dirname safely on Windows (i.e., compute __dirname via path.dirname(fileURLToPath(import.meta.url))). Also update imports to include fileURLToPath from "url" if missing. While here, make LIC_SRC_DIR read from process.env.LIC_SRC_DIR with the existing hard-fail fallback so local/dev overrides are possible (keep the same failure behavior when not provided).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/tempo/src/tempo.class.ts`:
- Around line 99-110: The public license snapshot generation uses raw.scopes
without guarding it, which can throw when raw.scopes is missing or not an
object; update the Tempo.license getter (where Tempo.#license is destructured
and scopes is computed) to normalize/guard raw.scopes before iterating — e.g.,
set const scopesSource = (raw.scopes && typeof raw.scopes === 'object') ?
raw.scopes : {} and then run Object.entries(scopesSource).map(...), preserving
the existing mapping that uses new Tempo(...).fmt.weekTime for exp and
updated_at so callers never hit an exception when scopes is absent or invalid.
---
Duplicate comments:
In `@packages/tempo/bin/resolve-types.ts`:
- Line 16: Replace the fragile URL-based dirname computation that uses "const
__dirname = path.dirname(new URL(import.meta.url).pathname);" with Node's
fileURLToPath(import.meta.url) to derive __dirname safely on Windows (i.e.,
compute __dirname via path.dirname(fileURLToPath(import.meta.url))). Also update
imports to include fileURLToPath from "url" if missing. While here, make
LIC_SRC_DIR read from process.env.LIC_SRC_DIR with the existing hard-fail
fallback so local/dev overrides are possible (keep the same failure behavior
when not provided).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2cd031be-3539-4f42-b5d4-8400aba26c4c
📒 Files selected for processing (7)
packages/tempo/bin/resolve-types.tspackages/tempo/doc/releases/v2.x.mdpackages/tempo/doc/tempo-vs-temporal.mdpackages/tempo/rollup.config.jspackages/tempo/src/support/support.init.tspackages/tempo/src/tempo.class.tspackages/tempo/test/plugins/licensing.full.test.ts
✅ Files skipped from review due to trivial changes (2)
- packages/tempo/rollup.config.js
- packages/tempo/doc/releases/v2.x.md
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/tempo/CHANGELOG.md (1)
18-18: 💤 Low valueConsider simplifying "prior to" to "before" for better readability.
The phrase "prior to iteration" could be shortened to "before iteration" for more concise user-facing documentation.
📝 Suggested simplification
-- **License Snapshot Resilience**: Implemented a safety guard in `Tempo.license` to normalize `raw.scopes` prior to iteration, eliminating potential runtime exceptions when scopes are absent. +- **License Snapshot Resilience**: Implemented a safety guard in `Tempo.license` to normalize `raw.scopes` before iteration, eliminating potential runtime exceptions when scopes are absent.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/tempo/CHANGELOG.md` at line 18, The changelog sentence under "License Snapshot Resilience" uses the phrase "prior to iteration"; update the text so it reads "before iteration" to improve readability—locate the entry referencing Tempo.license and the line that says "normalize `raw.scopes` prior to iteration" and replace "prior to" with "before".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/tempo/CHANGELOG.md`:
- Line 18: The changelog sentence under "License Snapshot Resilience" uses the
phrase "prior to iteration"; update the text so it reads "before iteration" to
improve readability—locate the entry referencing Tempo.license and the line that
says "normalize `raw.scopes` prior to iteration" and replace "prior to" with
"before".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e018b753-7655-42b7-aa19-1f87be208eb6
📒 Files selected for processing (3)
packages/tempo/CHANGELOG.mdpackages/tempo/bin/resolve-types.tspackages/tempo/src/tempo.class.ts
Summary by CodeRabbit
New Features
Documentation
Bug Fixes / Security
Tests
Chores