Skip to content

Conversation

@namsnath
Copy link
Contributor

@namsnath namsnath commented Jun 10, 2025

Summary of change

  • Makes plugin dependency resolution recursive
  • Flips plugin resolution order
  • Moves plugin code to new file
  • Adds tests
  • Fixes issue with plugin config override allowing modification of non-public properties
  • Adds support for ts-mocha

Related issues

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!)

Documentation changes

(If relevant, please create a PR in our docs repo, or create a checklist here highlighting the necessary changes)

Checklist for important updates

  • Changelog has been updated
  • coreDriverInterfaceSupported.json file has been updated (if needed)
    • Along with the associated array in lib/ts/version.ts
  • frontendDriverInterfaceSupported.json file has been updated (if needed)
  • Changes to the version if needed
    • In package.json
    • In package-lock.json
    • In lib/ts/version.ts
  • Had run npm run build-pretty
  • Had installed and ran the pre-commit hook
  • If new thirdparty provider is added,
    • update switch statement in recipe/thirdparty/providers/configUtils.ts file, createProvider function.
    • add an icon on the user management dashboard.
  • Issue this PR against the latest non released version branch.
    • To know which one it is, run find the latest released tag (git tag) in the format vX.Y.Z, and then find the latest branch (git branch --all) whose X.Y is greater than the latest released tag.
    • If no such branch exists, then create one from the latest released branch.
  • If have added a new web framework, update the add-ts-no-check.js file to include that
  • If added a new recipe / api interface, then make sure that the implementation of it uses NON arrow functions only (like someFunc: function () {..}).
  • If added a new recipe, then make sure to expose it inside the recipe folder present in the root of this repo. We also need to expose its types.
  • If added a new entry point, then make sure that it is importable by adding it to the exports in package.json

Remaining TODOs for this PR

  • Item1
  • Item2

@namsnath namsnath self-assigned this Jun 10, 2025
@namsnath namsnath requested review from coolbueb and porcellus June 10, 2025 17:01
@namsnath namsnath changed the title package lock update feat: recursive plugin dependency resolution Jun 13, 2025
Base automatically changed from feat/plugin/export-init to feat/plugin/base June 16, 2025 21:54
- Adds tests
- Fixes issue with plugin config override allowing modification of non-public properties
- Adds support for ts-mocha
@namsnath namsnath marked this pull request as ready for review June 17, 2025 12:48
@promptless
Copy link

promptless bot commented Jun 17, 2025

✅ No documentation updates required.

string[],
string[]
][] = [
// [fnOverride, apiOverride, plugins, expectedFnStack, expectedApiStack]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer if these were objects.

Comment on lines +373 to +396
it("error", async () => {
try {
const plugin = pluginFactory({
identifier: "plugin1",
overrideFunctions: false,
overrideApis: false,
});
plugin.routeHandlers = () => ({ status: "ERROR", message: "error" });

STExpress.init({
...partialSupertokensConfig,
recipeList: [recipeFactory({ overrideFunctions: false, overrideApis: false })],
experimental: {
plugins: [plugin],
},
});

const stInstance = SuperTokens.getInstanceOrThrowError();

const resObject = new DummyResponse();
const res = await stInstance.middleware(new DummyRequest(), resObject, {} as UserContext);
} catch (err) {
assert.strictEqual(err.message, "error");
}
Copy link

Choose a reason for hiding this comment

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

The test structure has an issue with error handling. The error is thrown during initialization when STExpress.init() is called with the plugin that returns an error status, not during middleware execution. To properly test this error case, the try-catch block should wrap the initialization code instead:

it("error", async () => {
  const plugin = pluginFactory({
    identifier: "plugin1",
    overrideFunctions: false,
    overrideApis: false,
  });
  plugin.routeHandlers = () => ({ status: "ERROR", message: "error" });

  try {
    STExpress.init({
      ...partialSupertokensConfig,
      recipeList: [recipeFactory({ overrideFunctions: false, overrideApis: false })],
      experimental: {
        plugins: [plugin],
      },
    });
    assert.fail("Should have thrown an error");
  } catch (err) {
    assert.strictEqual(err.message, "error");
  }
});

This ensures the test is actually verifying the expected error behavior.

Suggested change
it("error", async () => {
try {
const plugin = pluginFactory({
identifier: "plugin1",
overrideFunctions: false,
overrideApis: false,
});
plugin.routeHandlers = () => ({ status: "ERROR", message: "error" });
STExpress.init({
...partialSupertokensConfig,
recipeList: [recipeFactory({ overrideFunctions: false, overrideApis: false })],
experimental: {
plugins: [plugin],
},
});
const stInstance = SuperTokens.getInstanceOrThrowError();
const resObject = new DummyResponse();
const res = await stInstance.middleware(new DummyRequest(), resObject, {} as UserContext);
} catch (err) {
assert.strictEqual(err.message, "error");
}
it("error", async () => {
const plugin = pluginFactory({
identifier: "plugin1",
overrideFunctions: false,
overrideApis: false,
});
plugin.routeHandlers = () => ({ status: "ERROR", message: "error" });
try {
STExpress.init({
...partialSupertokensConfig,
recipeList: [recipeFactory({ overrideFunctions: false, overrideApis: false })],
experimental: {
plugins: [plugin],
},
});
assert.fail("Should have thrown an error");
} catch (err) {
assert.strictEqual(err.message, "error");
}
});

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

@coolbueb coolbueb requested a review from porcellus June 24, 2025 16:28
@porcellus porcellus merged commit f3dadbb into feat/plugin/base Jun 24, 2025
4 of 19 checks passed
@porcellus porcellus deleted the feat/plugin/recursive-dependencies branch June 24, 2025 22:15
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