Skip to content

Commit d27248d

Browse files
authored
Merge pull request #1001 from supertokens/feat/plugin/export-init
feat: Add init method support, better support for dynamic route handlers and added support for exporting logic from plugins
2 parents 3da53fe + 12d3c53 commit d27248d

39 files changed

+493
-437
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/querier.js

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

lib/build/recipe/accountlinking/types.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import OverrideableBuilder from "supertokens-js-override";
33
import type { User, UserContext } from "../../types";
44
import RecipeUserId from "../../recipeUserId";
55
import { SessionContainerInterface } from "../session/types";
6-
export declare type TypeInput = {
6+
export type TypeInput = {
77
onAccountLinked?: (user: User, newAccountInfo: RecipeLevelUser, userContext: UserContext) => Promise<void>;
88
shouldDoAutomaticAccountLinking?: (
99
newAccountInfo: AccountInfoWithRecipeId & {
@@ -25,11 +25,11 @@ export declare type TypeInput = {
2525
override?: {
2626
functions?: (
2727
originalImplementation: RecipeInterface,
28-
builder?: OverrideableBuilder<RecipeInterface>
28+
builder: OverrideableBuilder<RecipeInterface>
2929
) => RecipeInterface;
3030
};
3131
};
32-
export declare type TypeNormalisedInput = {
32+
export type TypeNormalisedInput = {
3333
onAccountLinked: (user: User, newAccountInfo: RecipeLevelUser, userContext: UserContext) => Promise<void>;
3434
shouldDoAutomaticAccountLinking: (
3535
newAccountInfo: AccountInfoWithRecipeId & {
@@ -51,11 +51,11 @@ export declare type TypeNormalisedInput = {
5151
override: {
5252
functions: (
5353
originalImplementation: RecipeInterface,
54-
builder?: OverrideableBuilder<RecipeInterface>
54+
builder: OverrideableBuilder<RecipeInterface>
5555
) => RecipeInterface;
5656
};
5757
};
58-
export declare type RecipeInterface = {
58+
export type RecipeInterface = {
5959
getUsers: (input: {
6060
tenantId: string;
6161
timeJoinedOrder: "ASC" | "DESC";
@@ -175,7 +175,7 @@ export declare type RecipeInterface = {
175175
status: "OK";
176176
}>;
177177
};
178-
export declare type AccountInfo = {
178+
export type AccountInfo = {
179179
email?: string;
180180
phoneNumber?: string;
181181
thirdParty?: {
@@ -186,15 +186,15 @@ export declare type AccountInfo = {
186186
credentialIds: string[];
187187
};
188188
};
189-
export declare type AccountInfoInput = Omit<AccountInfo, "webauthn"> & {
189+
export type AccountInfoInput = Omit<AccountInfo, "webauthn"> & {
190190
webauthn?: {
191191
credentialId: string;
192192
};
193193
};
194-
export declare type AccountInfoWithRecipeId = {
194+
export type AccountInfoWithRecipeId = {
195195
recipeId: "emailpassword" | "thirdparty" | "passwordless" | "webauthn";
196196
} & AccountInfo;
197-
export declare type RecipeLevelUser = {
197+
export type RecipeLevelUser = {
198198
tenantIds: string[];
199199
timeJoined: number;
200200
recipeUserId: RecipeUserId;

lib/build/recipe/dashboard/types.d.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@
22
import OverrideableBuilder from "supertokens-js-override";
33
import type { BaseRequest, BaseResponse } from "../../framework";
44
import { NormalisedAppinfo, User, UserContext } from "../../types";
5-
export declare type TypeInput = {
5+
export type TypeInput = {
66
apiKey?: string;
77
admins?: string[];
88
override?: {
99
functions?: (
1010
originalImplementation: RecipeInterface,
11-
builder?: OverrideableBuilder<RecipeInterface>
11+
builder: OverrideableBuilder<RecipeInterface>
1212
) => RecipeInterface;
13-
apis?: (originalImplementation: APIInterface, builder?: OverrideableBuilder<APIInterface>) => APIInterface;
13+
apis?: (originalImplementation: APIInterface, builder: OverrideableBuilder<APIInterface>) => APIInterface;
1414
};
1515
};
16-
export declare type TypeNormalisedInput = {
16+
export type TypeNormalisedInput = {
1717
apiKey?: string;
1818
admins?: string[];
1919
authMode: AuthMode;
2020
override: {
2121
functions: (
2222
originalImplementation: RecipeInterface,
23-
builder?: OverrideableBuilder<RecipeInterface>
23+
builder: OverrideableBuilder<RecipeInterface>
2424
) => RecipeInterface;
25-
apis: (originalImplementation: APIInterface, builder?: OverrideableBuilder<APIInterface>) => APIInterface;
25+
apis: (originalImplementation: APIInterface, builder: OverrideableBuilder<APIInterface>) => APIInterface;
2626
};
2727
};
28-
export declare type RecipeInterface = {
28+
export type RecipeInterface = {
2929
getDashboardBundleLocation(input: { userContext: UserContext }): Promise<string>;
3030
shouldAllowAccess(input: {
3131
req: BaseRequest;
3232
config: TypeNormalisedInput;
3333
userContext: UserContext;
3434
}): Promise<boolean>;
3535
};
36-
export declare type APIOptions = {
36+
export type APIOptions = {
3737
recipeImplementation: RecipeInterface;
3838
config: TypeNormalisedInput;
3939
recipeId: string;
@@ -42,22 +42,22 @@ export declare type APIOptions = {
4242
isInServerlessEnv: boolean;
4343
appInfo: NormalisedAppinfo;
4444
};
45-
export declare type APIInterface = {
45+
export type APIInterface = {
4646
dashboardGET: undefined | ((input: { options: APIOptions; userContext: UserContext }) => Promise<string>);
4747
};
48-
export declare type APIFunction = (
48+
export type APIFunction = (
4949
apiImplementation: APIInterface,
5050
tenantId: string,
5151
options: APIOptions,
5252
userContext: UserContext
5353
) => Promise<any>;
54-
export declare type RecipeIdForUser = "emailpassword" | "thirdparty" | "passwordless" | "webauthn";
55-
export declare type AuthMode = "api-key" | "email-password";
56-
export declare type UserWithFirstAndLastName = User & {
54+
export type RecipeIdForUser = "emailpassword" | "thirdparty" | "passwordless" | "webauthn";
55+
export type AuthMode = "api-key" | "email-password";
56+
export type UserWithFirstAndLastName = User & {
5757
firstName?: string;
5858
lastName?: string;
5959
};
60-
export declare type CoreConfigFieldInfo = {
60+
export type CoreConfigFieldInfo = {
6161
key: string;
6262
valueType: "string" | "boolean" | "number";
6363
value: string | number | boolean | null;

lib/build/recipe/multifactorauth/multiFactorAuthClaim.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export declare class MultiFactorAuthClaimClass extends SessionClaim<MFAClaimValu
5353
removeFromPayload: (
5454
payload: JSONObject
5555
) => {
56-
[x: string]: import("../../types").JSONValue;
56+
[ind: string]: import("../../types").JSONValue;
5757
};
5858
removeFromPayloadByMerge_internal: (
5959
payload: JSONObject

lib/build/recipe/thirdparty/providers/custom.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ var __importDefault =
55
return mod && mod.__esModule ? mod : { default: mod };
66
};
77
Object.defineProperty(exports, "__esModule", { value: true });
8-
exports.getActualClientIdFromDevelopmentClientId = exports.isUsingDevelopmentClientId = exports.DEV_OAUTH_REDIRECT_URL = void 0;
8+
exports.DEV_OAUTH_REDIRECT_URL = void 0;
9+
exports.isUsingDevelopmentClientId = isUsingDevelopmentClientId;
10+
exports.getActualClientIdFromDevelopmentClientId = getActualClientIdFromDevelopmentClientId;
11+
exports.default = NewProvider;
912
const thirdpartyUtils_1 = require("../../../thirdpartyUtils");
1013
const utils_1 = require("../../../utils");
1114
const pkce_challenge_1 = __importDefault(require("pkce-challenge"));
@@ -16,21 +19,19 @@ const DEV_OAUTH_AUTHORIZATION_URL = "https://supertokens.io/dev/oauth/redirect-t
1619
exports.DEV_OAUTH_REDIRECT_URL = "https://supertokens.io/dev/oauth/redirect-to-app";
1720
// If Third Party login is used with one of the following development keys, then the dev authorization url and the redirect url will be used.
1821
const DEV_OAUTH_CLIENT_IDS = [
19-
"1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com",
22+
"1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com", // google
2023
"467101b197249757c71f", // github
2124
];
2225
const DEV_KEY_IDENTIFIER = "4398792-";
2326
function isUsingDevelopmentClientId(client_id) {
2427
return client_id.startsWith(DEV_KEY_IDENTIFIER) || DEV_OAUTH_CLIENT_IDS.includes(client_id);
2528
}
26-
exports.isUsingDevelopmentClientId = isUsingDevelopmentClientId;
2729
function getActualClientIdFromDevelopmentClientId(client_id) {
2830
if (client_id.startsWith(DEV_KEY_IDENTIFIER)) {
2931
return client_id.split(DEV_KEY_IDENTIFIER)[1];
3032
}
3133
return client_id;
3234
}
33-
exports.getActualClientIdFromDevelopmentClientId = getActualClientIdFromDevelopmentClientId;
3435
function accessField(obj, key) {
3536
const keyParts = key.split(".");
3637
for (const k of keyParts) {
@@ -166,12 +167,12 @@ function NewProvider(input) {
166167
if (input.config.clients === undefined || input.config.clients.length !== 1) {
167168
throw new Error("please provide exactly one client config or pass clientType or tenantId");
168169
}
169-
return configUtils_1.getProviderConfigForClient(input.config, input.config.clients[0]);
170+
return (0, configUtils_1.getProviderConfigForClient)(input.config, input.config.clients[0]);
170171
}
171172
if (input.config.clients !== undefined) {
172173
for (const client of input.config.clients) {
173174
if (client.clientType === clientType) {
174-
return configUtils_1.getProviderConfigForClient(input.config, client);
175+
return (0, configUtils_1.getProviderConfigForClient)(input.config, client);
175176
}
176177
}
177178
}
@@ -199,7 +200,7 @@ function NewProvider(input) {
199200
? void 0
200201
: _a.includes("S256");
201202
if (impl.config.clientSecret === undefined || impl.config.forcePKCE || isS256MethodSupported) {
202-
const { code_challenge, code_verifier } = pkce_challenge_1.default(64); // According to https://www.rfc-editor.org/rfc/rfc7636, length must be between 43 and 128
203+
const { code_challenge, code_verifier } = (0, pkce_challenge_1.default)(64); // According to https://www.rfc-editor.org/rfc/rfc7636, length must be between 43 and 128
203204
queryParams["code_challenge"] = code_challenge;
204205
queryParams["code_challenge_method"] = "S256";
205206
pkceCodeVerifier = code_verifier;
@@ -263,9 +264,9 @@ function NewProvider(input) {
263264
accessTokenAPIParams["redirect_uri"] = exports.DEV_OAUTH_REDIRECT_URL;
264265
}
265266
/* Transformation needed for dev keys END */
266-
const tokenResponse = await thirdpartyUtils_1.doPostRequest(tokenAPIURL, accessTokenAPIParams);
267+
const tokenResponse = await (0, thirdpartyUtils_1.doPostRequest)(tokenAPIURL, accessTokenAPIParams);
267268
if (tokenResponse.status >= 400) {
268-
logger_1.logDebugMessage(
269+
(0, logger_1.logDebugMessage)(
269270
`Received response with status ${tokenResponse.status} and body ${tokenResponse.stringResponse}`
270271
);
271272
throw new Error(
@@ -283,28 +284,25 @@ function NewProvider(input) {
283284
};
284285
if (idToken && impl.config.jwksURI !== undefined) {
285286
if (jwks === undefined) {
286-
jwks = jose_1.createRemoteJWKSet(new URL(impl.config.jwksURI));
287+
jwks = (0, jose_1.createRemoteJWKSet)(new URL(impl.config.jwksURI));
287288
}
288-
rawUserInfoFromProvider.fromIdTokenPayload = await thirdpartyUtils_1.verifyIdTokenFromJWKSEndpointAndGetPayload(
289-
idToken,
290-
jwks,
291-
{
292-
audience: getActualClientIdFromDevelopmentClientId(impl.config.clientId),
293-
}
294-
);
289+
rawUserInfoFromProvider.fromIdTokenPayload = await (0,
290+
thirdpartyUtils_1.verifyIdTokenFromJWKSEndpointAndGetPayload)(idToken, jwks, {
291+
audience: getActualClientIdFromDevelopmentClientId(impl.config.clientId),
292+
});
295293
if (impl.config.validateIdTokenPayload !== undefined) {
296294
await impl.config.validateIdTokenPayload({
297295
idTokenPayload: rawUserInfoFromProvider.fromIdTokenPayload,
298296
clientConfig: impl.config,
299-
userContext: utils_1.getUserContext(userContext),
297+
userContext: (0, utils_1.getUserContext)(userContext),
300298
});
301299
}
302300
}
303301
if (impl.config.validateAccessToken !== undefined && accessToken !== undefined) {
304302
await impl.config.validateAccessToken({
305303
accessToken: accessToken,
306304
clientConfig: impl.config,
307-
userContext: utils_1.getUserContext(userContext),
305+
userContext: (0, utils_1.getUserContext)(userContext),
308306
});
309307
}
310308
if (accessToken && impl.config.userInfoEndpoint !== undefined) {
@@ -330,13 +328,13 @@ function NewProvider(input) {
330328
}
331329
}
332330
}
333-
const userInfoFromAccessToken = await thirdpartyUtils_1.doGetRequest(
331+
const userInfoFromAccessToken = await (0, thirdpartyUtils_1.doGetRequest)(
334332
impl.config.userInfoEndpoint,
335333
queryParams,
336334
headers
337335
);
338336
if (userInfoFromAccessToken.status >= 400) {
339-
logger_1.logDebugMessage(
337+
(0, logger_1.logDebugMessage)(
340338
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
341339
);
342340
throw new Error(
@@ -360,4 +358,3 @@ function NewProvider(input) {
360358
}
361359
return impl;
362360
}
363-
exports.default = NewProvider;

lib/build/recipe/webauthn/api/emailExists.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var __importDefault =
1919
return mod && mod.__esModule ? mod : { default: mod };
2020
};
2121
Object.defineProperty(exports, "__esModule", { value: true });
22+
exports.default = emailExists;
2223
const utils_1 = require("../../../utils");
2324
const error_1 = __importDefault(require("../error"));
2425
async function emailExists(apiImplementation, tenantId, options, userContext) {
@@ -38,7 +39,6 @@ async function emailExists(apiImplementation, tenantId, options, userContext) {
3839
options,
3940
userContext,
4041
});
41-
utils_1.send200Response(options.res, result);
42+
(0, utils_1.send200Response)(options.res, result);
4243
return true;
4344
}
44-
exports.default = emailExists;

lib/build/recipe/webauthn/api/generateRecoverAccountToken.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var __importDefault =
1919
return mod && mod.__esModule ? mod : { default: mod };
2020
};
2121
Object.defineProperty(exports, "__esModule", { value: true });
22+
exports.default = generateRecoverAccountToken;
2223
const utils_1 = require("../../../utils");
2324
const error_1 = __importDefault(require("../error"));
2425
async function generateRecoverAccountToken(apiImplementation, tenantId, options, userContext) {
@@ -39,7 +40,6 @@ async function generateRecoverAccountToken(apiImplementation, tenantId, options,
3940
options,
4041
userContext,
4142
});
42-
utils_1.send200Response(options.res, result);
43+
(0, utils_1.send200Response)(options.res, result);
4344
return true;
4445
}
45-
exports.default = generateRecoverAccountToken;

0 commit comments

Comments
 (0)