Skip to content

Commit 12d3c53

Browse files
committed
improve typing and pass corect data
1 parent 364bbc8 commit 12d3c53

File tree

10 files changed

+74
-178
lines changed

10 files changed

+74
-178
lines changed

lib/build/index.d.ts

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/supertokens.js

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/types.d.ts

Lines changed: 7 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/utils.d.ts

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/build/utils.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ import RecipeUserId from "./recipeUserId";
2222
import { User } from "./user";
2323
import { getUserContext } from "./utils";
2424

25+
export type {
26+
TypeInput as SuperTokensConfig,
27+
SuperTokensPublicConfig,
28+
SuperTokensPlugin,
29+
SuperTokensPublicPlugin,
30+
} from "./types";
31+
2532
// For Express
2633
export default class SuperTokensWrapper {
2734
static init = SuperTokens.init;

lib/ts/supertokens.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
getRidFromHeader,
3232
isTestEnv,
3333
getPublicPlugin,
34+
getPublicConfig,
3435
} from "./utils";
3536
import { Querier } from "./querier";
3637
import RecipeModule from "./recipeModule";
@@ -80,7 +81,11 @@ export default class SuperTokens {
8081
throw new Error("Plugin version mismatch");
8182
}
8283
if (plugin.dependencies) {
83-
const result = plugin.dependencies(finalPluginList, version);
84+
const result = plugin.dependencies(
85+
getPublicConfig(config),
86+
finalPluginList.map(getPublicPlugin),
87+
version
88+
);
8489
if (result.status === "ERROR") {
8590
throw new Error(result.message);
8691
}
@@ -94,13 +99,13 @@ export default class SuperTokens {
9499

95100
for (const [pluginIndex, plugin] of finalPluginList.entries()) {
96101
if (plugin.config) {
97-
config = { ...config, ...plugin.config(config) };
102+
config = { ...config, ...plugin.config(getPublicConfig(config)) };
98103
}
99104

100105
if (plugin.routeHandlers) {
101106
let handlers: PluginRouteHandler[] = [];
102107
if (typeof plugin.routeHandlers === "function") {
103-
const result = plugin.routeHandlers(config, this.pluginList, version);
108+
const result = plugin.routeHandlers(getPublicConfig(config), this.pluginList, version);
104109
if (result.status === "ERROR") {
105110
throw new Error(result.message);
106111
}

lib/ts/types.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,10 @@ export type SuperTokensPlugin = {
125125
id: string; // TODO: validate that no two plugins have the same id
126126
version?: string;
127127
compatibleSDKVersions?: string | string[]; // match the syntax of the engines field in package.json
128-
init?: (
129-
config: Omit<TypeInput, "recipeList" | "experimental">,
130-
allPlugins: Pick<SuperTokensPlugin, "id" | "version" | "compatibleSDKVersions" | "exports">[],
131-
sdkVersion: string
132-
) => void;
128+
init?: (config: SuperTokensPublicConfig, allPlugins: SuperTokensPublicPlugin[], sdkVersion: string) => void;
133129
dependencies?: (
134-
pluginsAbove: SuperTokensPlugin[],
130+
config: SuperTokensPublicConfig,
131+
pluginsAbove: SuperTokensPublicPlugin[],
135132
sdkVersion: string
136133
) => { status: "OK"; pluginsToAdd?: SuperTokensPlugin[] } | { status: "ERROR"; message: string };
137134
overrideMap?: {
@@ -141,12 +138,12 @@ export type SuperTokensPlugin = {
141138
};
142139
routeHandlers?:
143140
| ((
144-
config: Omit<TypeInput, "recipeList" | "experimental">,
145-
allPlugins: Pick<SuperTokensPlugin, "id" | "version" | "compatibleSDKVersions" | "exports">[],
141+
config: SuperTokensPublicConfig,
142+
allPlugins: SuperTokensPublicPlugin[],
146143
sdkVersion: string
147144
) => { status: "OK"; routeHandlers: PluginRouteHandler[] } | { status: "ERROR"; message: string })
148145
| PluginRouteHandler[];
149-
config?: (config: Omit<TypeInput, "recipeList">) => Omit<TypeInput, "recipeList"> | undefined;
146+
config?: (config: SuperTokensPublicConfig) => SuperTokensPublicConfig | undefined;
150147
exports?: Record<string, any>;
151148
};
152149

@@ -155,6 +152,8 @@ export type SuperTokensPublicPlugin = Pick<
155152
"id" | "version" | "compatibleSDKVersions" | "exports"
156153
> & { initialized: boolean };
157154

155+
export type SuperTokensPublicConfig = Omit<TypeInput, "recipeList" | "experimental">;
156+
158157
export type TypeInput = {
159158
supertokens?: SuperTokensInfo;
160159
framework?: TypeFramework;

lib/ts/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type {
99
SuperTokensPlugin,
1010
AllRecipeConfigs,
1111
SuperTokensPublicPlugin,
12+
TypeInput,
13+
SuperTokensPublicConfig,
1214
} from "./types";
1315
import NormalisedURLDomain from "./normalisedURLDomain";
1416
import NormalisedURLPath from "./normalisedURLPath";
@@ -580,3 +582,8 @@ export function getPublicPlugin(plugin: SuperTokensPlugin): SuperTokensPublicPlu
580582
compatibleSDKVersions: plugin.compatibleSDKVersions,
581583
};
582584
}
585+
586+
export function getPublicConfig(config: TypeInput): SuperTokensPublicConfig {
587+
const { experimental, recipeList, ...publicConfig } = config;
588+
return publicConfig;
589+
}

0 commit comments

Comments
 (0)