Skip to content

Conversation

@MarioCadenas
Copy link
Collaborator

@MarioCadenas MarioCadenas commented Jan 28, 2026

Summary: Plugin SDK Pattern for Exposed APIs

Overview

This PR introduces an explicit SDK pattern for exposing plugin APIs, replacing direct plugin instance access with a controlled public interface.

Key Changes

  1. SDK Pattern for Plugin APIs
  • Plugins now define their public API via an optional exports() method
  • AppKit wraps each plugin's exports with asUser() automatically
  • Methods are bound to the plugin instance, ensuring correct this context when destructured
  1. Architecture Improvements
  • Removed static singleton (_instance) - each createApp() returns a fresh instance
  • Changed to ES private fields (#pluginInstances, #setupPromises) for true runtime privacy
  • Centralized asUser handling in AppKit instead of duplicating in each plugin
  1. Type System Updates
  • Added PluginSDK - extracts SDK type from plugin's exports() return type
  • Added WithAsUser - wraps SDK with asUser method signature
  • Updated PluginMap to return WithAsUser<PluginSDK<...>> instead of raw plugin instances
  1. TypeScript Configuration
  • Updated target and lib to ES2022 (enables Object.hasOwn())
  1. Changes to SDK usage of AppKit
  • appkit.pluginName now returns the SDK object, not the plugin instance
  • Plugins that want to expose methods must implement sdk() (optional, defaults to {})

Example

class MyPlugin extends Plugin {
  myMethod() { /* ... */ }
  
  exports() {
    return {
      myMethod: this.myMethod,
    };
  }
}
-----

const appKit = await createApp({
  plugins: [myPlugin()]
})

appKit.myPlugin.myMethod()
appKit.myPlugin.asUser(req).myMehtod()

@MarioCadenas MarioCadenas force-pushed the review-exposed-apis branch 3 times, most recently from 0a43815 to 71f5441 Compare January 28, 2026 16:51
@MarioCadenas MarioCadenas force-pushed the review-exposed-apis branch 3 times, most recently from 25abadd to e8d2d77 Compare January 29, 2026 16:05
chore: fixup

chore: fixup

chore: fixup

chore: fixup

chore: fixup

chore: fixup
@MarioCadenas MarioCadenas marked this pull request as ready for review January 29, 2026 16:09
Copy link
Member

@pkosiec pkosiec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks awesome now👌 great job! just a small comment

(BTW I don't have any better name than sdk but it sounds a bit broad, maybe you'll find some naming alternatives?)

@MarioCadenas MarioCadenas merged commit 822d98e into main Jan 30, 2026
4 checks passed
@MarioCadenas MarioCadenas deleted the review-exposed-apis branch January 30, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants