feat: option to skip cache on M2M token#73
Conversation
WalkthroughThe changes introduce a Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant getM2MToken
participant Cache
participant OAuth2Server
Caller->>getM2MToken: Call with options (may include skipCache)
alt skipCache is true
getM2MToken->>OAuth2Server: POST /oauth2/token
OAuth2Server-->>getM2MToken: Token response
getM2MToken-->>Caller: Return token
else skipCache is false or not set
getM2MToken->>Cache: Check for cached token
alt Token found and valid
Cache-->>getM2MToken: Return cached token
getM2MToken-->>Caller: Return token
else Token missing or expired
getM2MToken->>OAuth2Server: POST /oauth2/token
OAuth2Server-->>getM2MToken: Token response
getM2MToken->>Cache: Store new token
getM2MToken-->>Caller: Return token
end
end
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lib/main.ts (1)
377-411: Remove console.log and improve error context.The
fetchTokenfunction is well-structured with proper validation and error handling. However, there's a console.log statement that should be removed from production code.- console.log("returning token: ", result.json.access_token); return result.json.access_token;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/main.test.ts(3 hunks)lib/main.ts(3 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: DanielRivers
PR: kinde-oss/infrastructure#72
File: lib/main.test.ts:68-70
Timestamp: 2025-06-24T11:26:45.395Z
Learning: The infrastructure library does not implement M2M token caching functionality internally. The getM2MToken function and its caching logic are handled by the Kinde platform/runtime, and this library serves as a wrapper that consumes those external capabilities through the global.kinde.cache.jwtToken interface.
lib/main.test.ts (2)
Learnt from: DanielRivers
PR: kinde-oss/infrastructure#72
File: lib/main.test.ts:68-70
Timestamp: 2025-06-24T11:26:45.395Z
Learning: The infrastructure library does not implement M2M token caching functionality internally. The getM2MToken function and its caching logic are handled by the Kinde platform/runtime, and this library serves as a wrapper that consumes those external capabilities through the global.kinde.cache.jwtToken interface.
Learnt from: DanielRivers
PR: kinde-oss/infrastructure#35
File: lib/types.ts:58-65
Timestamp: 2025-01-15T20:41:03.218Z
Learning: In the Kinde infrastructure, the `kinde.secureFetch` and `kinde.widget` bindings in `WorkflowSettings` are designed as simple feature flags using empty object types `{}`. They should not contain additional configuration properties.
lib/main.ts (1)
Learnt from: DanielRivers
PR: kinde-oss/infrastructure#72
File: lib/main.test.ts:68-70
Timestamp: 2025-06-24T11:26:45.395Z
Learning: The infrastructure library does not implement M2M token caching functionality internally. The getM2MToken function and its caching logic are handled by the Kinde platform/runtime, and this library serves as a wrapper that consumes those external capabilities through the global.kinde.cache.jwtToken interface.
🧬 Code Graph Analysis (1)
lib/main.test.ts (1)
lib/main.ts (1)
getM2MToken(373-430)
🪛 GitHub Check: codecov/patch
lib/main.ts
[warning] 475-477: lib/main.ts#L475-L477
Added lines #L475 - L477 were not covered by tests
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
lib/main.ts (2)
370-370: LGTM: Clean addition of skipCache option.The boolean option is well-typed and appropriately optional, maintaining backward compatibility.
413-429: LGTM: Clean implementation of cache bypass logic.The conditional logic correctly implements the skipCache functionality while maintaining backward compatibility with the existing cache mechanism.
lib/main.test.ts (2)
32-32: LGTM: Proper import addition.The import is correctly added to support the new test suite.
187-353: Excellent test coverage for getM2MToken functionality.The test suite is comprehensive and well-structured, covering:
✅ Cache behavior with and without skipCache option
✅ Parameter validation and error scenarios
✅ Request body parameter verification
✅ Error handling for missing tokens and network failures
✅ onMissingOrExpired callback functionalityThe tests properly use mocks and maintain isolation between test cases. This provides strong confidence in the implementation correctness.
f9a8e58 to
68ebac6
Compare
Explain your changes
option to skip the cache on M2M tokens and fix for where the token is not string from cache
Checklist
🛟 If you need help, consider asking for advice over in the Kinde community.