Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multitenancy recipe #594

Merged
merged 7 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/build/recipe/multitenancy/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getAPIInterface() {
return {
loginMethodsGET: function ({ tenantId, clientType, options, userContext }) {
return __awaiter(this, void 0, void 0, function* () {
const tenantConfigRes = yield options.recipeImplementation.getTenantConfig({
const tenantConfigRes = yield options.recipeImplementation.getTenant({
tenantId,
userContext,
});
Expand Down
27 changes: 18 additions & 9 deletions lib/build/recipe/multitenancy/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class Wrapper {
emailPasswordEnabled?: boolean;
passwordlessEnabled?: boolean;
thirdPartyEnabled: boolean;
coreConfig?: any;
},
userContext?: any
): Promise<{
Expand All @@ -25,7 +26,7 @@ export default class Wrapper {
status: "OK";
didExist: boolean;
}>;
static getTenantConfig(
static getTenant(
tenantId?: string,
userContext?: any
): Promise<{
Expand All @@ -40,6 +41,7 @@ export default class Wrapper {
enabled: boolean;
providers: ProviderConfig[];
};
coreConfig: any;
}>;
static listAllTenants(
userContext?: any
Expand All @@ -64,25 +66,32 @@ export default class Wrapper {
status: "OK";
didConfigExist: boolean;
}>;
static listThirdPartyConfigsForThirdPartyId(
thirdPartyId: string,
static associateUserToTenant(
tenantId: string | undefined,
userId: string,
userContext?: any
): Promise<{
status: "OK";
tenants: {
tenantId: string;
providers: ProviderConfig[];
}[];
wasAlreadyAssociated: boolean;
}>;
static disassociateUserFromTenant(
tenantId: string | undefined,
userId: string,
userContext?: any
): Promise<{
status: "OK";
wasAssociated: boolean;
}>;
}
export declare let init: typeof Recipe.init;
export declare let createOrUpdateTenant: typeof Wrapper.createOrUpdateTenant;
export declare let deleteTenant: typeof Wrapper.deleteTenant;
export declare let getTenantConfig: typeof Wrapper.getTenantConfig;
export declare let getTenant: typeof Wrapper.getTenant;
export declare let listAllTenants: typeof Wrapper.listAllTenants;
export declare let createOrUpdateThirdPartyConfig: typeof Wrapper.createOrUpdateThirdPartyConfig;
export declare let deleteThirdPartyConfig: typeof Wrapper.deleteThirdPartyConfig;
export declare let listThirdPartyConfigsForThirdPartyId: typeof Wrapper.listThirdPartyConfigsForThirdPartyId;
export declare let associateUserToTenant: typeof Wrapper.associateUserToTenant;
export declare let disassociateUserFromTenant: typeof Wrapper.disassociateUserFromTenant;
export { RecipeDisabledForTenantError, TenantDoesNotExistError };
export { AllowedDomainsClaim };
export type { RecipeInterface, APIOptions, APIInterface };
28 changes: 20 additions & 8 deletions lib/build/recipe/multitenancy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var __importDefault =
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AllowedDomainsClaim = exports.TenantDoesNotExistError = exports.RecipeDisabledForTenantError = exports.listThirdPartyConfigsForThirdPartyId = exports.deleteThirdPartyConfig = exports.createOrUpdateThirdPartyConfig = exports.listAllTenants = exports.getTenantConfig = exports.deleteTenant = exports.createOrUpdateTenant = exports.init = void 0;
exports.AllowedDomainsClaim = exports.TenantDoesNotExistError = exports.RecipeDisabledForTenantError = exports.disassociateUserFromTenant = exports.associateUserToTenant = exports.deleteThirdPartyConfig = exports.createOrUpdateThirdPartyConfig = exports.listAllTenants = exports.getTenant = exports.deleteTenant = exports.createOrUpdateTenant = exports.init = void 0;
const recipe_1 = __importDefault(require("./recipe"));
const error_1 = require("./error");
Object.defineProperty(exports, "RecipeDisabledForTenantError", {
Expand Down Expand Up @@ -92,10 +92,10 @@ class Wrapper {
});
});
}
static getTenantConfig(tenantId, userContext) {
static getTenant(tenantId, userContext) {
return __awaiter(this, void 0, void 0, function* () {
const recipeInstance = recipe_1.default.getInstanceOrThrowError();
return recipeInstance.recipeInterfaceImpl.getTenantConfig({
return recipeInstance.recipeInterfaceImpl.getTenant({
tenantId,
userContext: userContext === undefined ? {} : userContext,
});
Expand Down Expand Up @@ -130,11 +130,22 @@ class Wrapper {
});
});
}
static listThirdPartyConfigsForThirdPartyId(thirdPartyId, userContext) {
static associateUserToTenant(tenantId, userId, userContext) {
return __awaiter(this, void 0, void 0, function* () {
const recipeInstance = recipe_1.default.getInstanceOrThrowError();
return recipeInstance.recipeInterfaceImpl.listThirdPartyConfigsForThirdPartyId({
thirdPartyId,
return recipeInstance.recipeInterfaceImpl.associateUserToTenant({
tenantId,
userId,
userContext: userContext === undefined ? {} : userContext,
});
});
}
static disassociateUserFromTenant(tenantId, userId, userContext) {
return __awaiter(this, void 0, void 0, function* () {
const recipeInstance = recipe_1.default.getInstanceOrThrowError();
return recipeInstance.recipeInterfaceImpl.disassociateUserFromTenant({
tenantId,
userId,
userContext: userContext === undefined ? {} : userContext,
});
});
Expand All @@ -145,8 +156,9 @@ Wrapper.init = recipe_1.default.init;
exports.init = Wrapper.init;
exports.createOrUpdateTenant = Wrapper.createOrUpdateTenant;
exports.deleteTenant = Wrapper.deleteTenant;
exports.getTenantConfig = Wrapper.getTenantConfig;
exports.getTenant = Wrapper.getTenant;
exports.listAllTenants = Wrapper.listAllTenants;
exports.createOrUpdateThirdPartyConfig = Wrapper.createOrUpdateThirdPartyConfig;
exports.deleteThirdPartyConfig = Wrapper.deleteThirdPartyConfig;
exports.listThirdPartyConfigsForThirdPartyId = Wrapper.listThirdPartyConfigsForThirdPartyId;
exports.associateUserToTenant = Wrapper.associateUserToTenant;
exports.disassociateUserFromTenant = Wrapper.disassociateUserFromTenant;
59 changes: 29 additions & 30 deletions lib/build/recipe/multitenancy/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function getRecipeInterface(querier) {
return {
getTenantId: function ({ tenantIdFromFrontend }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO do we need this function?
return tenantIdFromFrontend;
});
},
Expand All @@ -66,7 +65,7 @@ function getRecipeInterface(querier) {
return response;
});
},
getTenantConfig: function ({ tenantId }) {
getTenant: function ({ tenantId }) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield querier.sendGetRequest(
new normalisedURLPath_1.default(
Expand All @@ -76,12 +75,7 @@ function getRecipeInterface(querier) {
),
{}
);
return {
status: response.status,
emailPassword: response.emailPassword,
passwordless: response.passwordless,
thirdParty: response.thirdParty,
};
return response;
});
},
listAllTenants: function () {
Expand All @@ -90,11 +84,7 @@ function getRecipeInterface(querier) {
new normalisedURLPath_1.default(`/recipe/multitenancy/tenant/list`),
{}
);
const tenants = response.tenants.map((item) => item.tenantId);
return {
status: "OK",
tenants,
};
return response;
});
},
createOrUpdateThirdPartyConfig: function ({ tenantId, config, skipValidation }) {
Expand Down Expand Up @@ -128,25 +118,34 @@ function getRecipeInterface(querier) {
return response;
});
},
listThirdPartyConfigsForThirdPartyId: function ({ thirdPartyId }) {
associateUserToTenant: function ({ tenantId, userId }) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield querier.sendGetRequest(
new normalisedURLPath_1.default(`/recipe/multitenancy/tenant/list`),
{}
let response = yield querier.sendPostRequest(
new normalisedURLPath_1.default(
`/${
tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId
}/recipe/multitenancy/tenant/user`
),
{
userId,
}
);
let result = {
status: "OK",
tenants: [],
};
for (const tenant of response.tenants) {
result.tenants.push({
tenantId: tenant.tenantId,
providers: tenant.thirdParty.providers.filter(
(provider) => provider.thirdPartyId === thirdPartyId
),
});
}
return result;
return response;
});
},
disassociateUserFromTenant: function ({ tenantId, userId }) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield querier.sendPostRequest(
new normalisedURLPath_1.default(
`/${
tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId
}/recipe/multitenancy/tenant/user/remove`
),
{
userId,
}
);
return response;
});
},
};
Expand Down
22 changes: 15 additions & 7 deletions lib/build/recipe/multitenancy/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export declare type RecipeInterface = {
emailPasswordEnabled?: boolean;
passwordlessEnabled?: boolean;
thirdPartyEnabled?: boolean;
coreConfig?: any;
};
userContext: any;
}) => Promise<{
Expand All @@ -72,7 +73,7 @@ export declare type RecipeInterface = {
status: "OK";
didExist: boolean;
}>;
getTenantConfig: (input: {
getTenant: (input: {
tenantId?: string;
userContext: any;
}) => Promise<{
Expand All @@ -87,6 +88,7 @@ export declare type RecipeInterface = {
enabled: boolean;
providers: ProviderConfig[];
};
coreConfig: any;
}>;
listAllTenants: (input: {
userContext: any;
Expand All @@ -111,15 +113,21 @@ export declare type RecipeInterface = {
status: "OK";
didConfigExist: boolean;
}>;
listThirdPartyConfigsForThirdPartyId: (input: {
thirdPartyId: string;
associateUserToTenant: (input: {
tenantId?: string;
userId: string;
userContext: any;
}) => Promise<{
status: "OK";
tenants: {
tenantId: string;
providers: ProviderConfig[];
}[];
wasAlreadyAssociated: boolean;
}>;
disassociateUserFromTenant: (input: {
tenantId?: string;
userId: string;
userContext: any;
}) => Promise<{
status: "OK";
wasAssociated: boolean;
}>;
};
export declare type APIOptions = {
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function getRecipeImplementation(querier, providers) {
getProvider: function ({ thirdPartyId, tenantId, clientType, userContext }) {
return __awaiter(this, void 0, void 0, function* () {
const mtRecipe = recipe_1.default.getInstanceOrThrowError();
const tenantConfig = yield mtRecipe.recipeInterfaceImpl.getTenantConfig({ tenantId, userContext });
const tenantConfig = yield mtRecipe.recipeInterfaceImpl.getTenant({ tenantId, userContext });
const mergedProviders = configUtils_1.mergeProvidersFromCoreAndStatic(
tenantConfig.thirdParty.providers,
providers
Expand Down
2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/ts/recipe/multitenancy/api/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { findAndCreateProviderInstance, mergeProvidersFromCoreAndStatic } from "
export default function getAPIInterface(): APIInterface {
return {
loginMethodsGET: async function ({ tenantId, clientType, options, userContext }) {
const tenantConfigRes = await options.recipeImplementation.getTenantConfig({
const tenantConfigRes = await options.recipeImplementation.getTenant({
tenantId,
userContext,
});
Expand Down
Loading