Skip to content

Commit

Permalink
fix: multitenancy recipe (#594)
Browse files Browse the repository at this point in the history
* fix: impl and test

* fix: version

* fix: impl

* fix: pr comments

* fix: version update

* fix: pr comments
  • Loading branch information
sattvikc authored Jun 21, 2023
1 parent 88feef6 commit 9e1a8ce
Show file tree
Hide file tree
Showing 33 changed files with 710 additions and 159 deletions.
2 changes: 1 addition & 1 deletion lib/build/recipe/emailpassword/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class Wrapper {
applyPasswordPolicy?: boolean;
}): Promise<
| {
status: "OK" | "EMAIL_ALREADY_EXISTS_ERROR" | "UNKNOWN_USER_ID_ERROR";
status: "OK" | "UNKNOWN_USER_ID_ERROR" | "EMAIL_ALREADY_EXISTS_ERROR";
}
| {
status: "PASSWORD_POLICY_VIOLATED_ERROR";
Expand Down
3 changes: 1 addition & 2 deletions lib/build/recipe/multitenancy/api/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ 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,
});
const providerInputsFromStatic = options.staticThirdPartyProviders;
const providerConfigsFromCore = tenantConfigRes.thirdParty.providers;
const mergedProviders = configUtils_1.mergeProvidersFromCoreAndStatic(
tenantId,
providerConfigsFromCore,
providerInputsFromStatic
);
Expand Down
40 changes: 33 additions & 7 deletions lib/build/recipe/multitenancy/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default class Wrapper {
emailPasswordEnabled?: boolean;
passwordlessEnabled?: boolean;
thirdPartyEnabled: boolean;
coreConfig?: {
[key: string]: any;
};
},
userContext?: any
): Promise<{
Expand All @@ -23,9 +26,9 @@ export default class Wrapper {
userContext?: any
): Promise<{
status: "OK";
tenantExisted: boolean;
didExist: boolean;
}>;
static getTenantConfig(
static getTenant(
tenantId?: string,
userContext?: any
): Promise<{
Expand All @@ -40,6 +43,9 @@ export default class Wrapper {
enabled: boolean;
providers: ProviderConfig[];
};
coreConfig: {
[key: string]: any;
};
}>;
static listAllTenants(
userContext?: any
Expand All @@ -48,6 +54,7 @@ export default class Wrapper {
tenants: string[];
}>;
static createOrUpdateThirdPartyConfig(
tenantId: string | undefined,
config: ProviderConfig,
skipValidation?: boolean,
userContext?: any
Expand All @@ -63,22 +70,41 @@ export default class Wrapper {
status: "OK";
didConfigExist: boolean;
}>;
static listThirdPartyConfigsForThirdPartyId(
thirdPartyId: string,
static associateUserToTenant(
tenantId: string | undefined,
userId: string,
userContext?: any
): Promise<
| {
status: "OK";
wasAlreadyAssociated: boolean;
}
| {
status:
| "UNKNOWN_USER_ID_ERROR"
| "EMAIL_ALREADY_EXISTS_ERROR"
| "PHONE_NUMBER_ALREADY_EXISTS_ERROR"
| "THIRD_PARTY_USER_ALREADY_EXISTS_ERROR";
}
>;
static disassociateUserFromTenant(
tenantId: string | undefined,
userId: string,
userContext?: any
): Promise<{
status: "OK";
providers: ProviderConfig[];
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 };
31 changes: 22 additions & 9 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 All @@ -109,10 +109,11 @@ class Wrapper {
});
});
}
static createOrUpdateThirdPartyConfig(config, skipValidation, userContext) {
static createOrUpdateThirdPartyConfig(tenantId, config, skipValidation, userContext) {
return __awaiter(this, void 0, void 0, function* () {
const recipeInstance = recipe_1.default.getInstanceOrThrowError();
return recipeInstance.recipeInterfaceImpl.createOrUpdateThirdPartyConfig({
tenantId,
config,
skipValidation,
userContext: userContext === undefined ? {} : userContext,
Expand All @@ -129,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 @@ -144,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;
2 changes: 1 addition & 1 deletion lib/build/recipe/multitenancy/recipeImplementation.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-nocheck
import { RecipeInterface } from "./";
import { Querier } from "../../querier";
export default function getRecipeInterface(_: Querier): RecipeInterface;
export default function getRecipeInterface(querier: Querier): RecipeInterface;
122 changes: 89 additions & 33 deletions lib/build/recipe/multitenancy/recipeImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,66 +30,122 @@ var __awaiter =
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
function getRecipeInterface(_) {
const normalisedURLPath_1 = __importDefault(require("../../normalisedURLPath"));
const constants_1 = require("./constants");
function getRecipeInterface(querier) {
return {
getTenantId: function ({ tenantIdFromFrontend }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
return tenantIdFromFrontend;
});
},
createOrUpdateTenant: function () {
createOrUpdateTenant: function ({ tenantId, config }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendPutRequest(
new normalisedURLPath_1.default(`/recipe/multitenancy/tenant`),
Object.assign({ tenantId }, config)
);
return response;
});
},
deleteTenant: function () {
deleteTenant: function ({ tenantId }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendPostRequest(
new normalisedURLPath_1.default(`/recipe/multitenancy/tenant/remove`),
{
tenantId,
}
);
return response;
});
},
getTenantConfig: function () {
getTenant: function ({ tenantId }) {
return __awaiter(this, void 0, void 0, function* () {
return {
status: "OK",
emailPassword: {
enabled: true,
},
passwordless: {
enabled: true,
},
thirdParty: {
enabled: true,
providers: [],
},
};
let response = yield querier.sendGetRequest(
new normalisedURLPath_1.default(
`/${
tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId
}/recipe/multitenancy/tenant`
),
{}
);
return response;
});
},
listAllTenants: function () {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendGetRequest(
new normalisedURLPath_1.default(`/recipe/multitenancy/tenant/list`),
{}
);
return response;
});
},
createOrUpdateThirdPartyConfig: function ({ tenantId, config, skipValidation }) {
return __awaiter(this, void 0, void 0, function* () {
let response = yield querier.sendPutRequest(
new normalisedURLPath_1.default(
`/${
tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId
}/recipe/multitenancy/config/thirdparty`
),
{
config,
skipValidation,
}
);
return response;
});
},
createOrUpdateThirdPartyConfig: function () {
deleteThirdPartyConfig: function ({ tenantId, thirdPartyId }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendPostRequest(
new normalisedURLPath_1.default(
`/${
tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId
}/recipe/multitenancy/config/thirdparty/remove`
),
{
thirdPartyId,
}
);
return response;
});
},
deleteThirdPartyConfig: function () {
associateUserToTenant: function ({ tenantId, userId }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
let response = yield querier.sendPostRequest(
new normalisedURLPath_1.default(
`/${
tenantId === undefined ? constants_1.DEFAULT_TENANT_ID : tenantId
}/recipe/multitenancy/tenant/user`
),
{
userId,
}
);
return response;
});
},
listThirdPartyConfigsForThirdPartyId: function () {
disassociateUserFromTenant: function ({ tenantId, userId }) {
return __awaiter(this, void 0, void 0, function* () {
// TODO
throw new Error("Not implemented");
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
Loading

0 comments on commit 9e1a8ce

Please sign in to comment.