@webiny/api-core 6.5.0-beta.9 → 6.5.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/exports/api/security.d.ts +2 -0
- package/exports/api/security.js +2 -0
- package/features/ai/DEVELOPERS.md +14 -0
- package/features/ai/OpenRouterSdkFactory.d.ts +10 -0
- package/features/ai/OpenRouterSdkFactory.js +112 -0
- package/features/ai/OpenRouterSdkFactory.js.map +1 -0
- package/features/ai/feature.js +2 -0
- package/features/ai/feature.js.map +1 -1
- package/features/security/ResolveIdentityTenants/ResolveIdentityTenantsUseCase.d.ts +12 -0
- package/features/security/ResolveIdentityTenants/ResolveIdentityTenantsUseCase.js +46 -0
- package/features/security/ResolveIdentityTenants/ResolveIdentityTenantsUseCase.js.map +1 -0
- package/features/security/ResolveIdentityTenants/abstractions.d.ts +22 -0
- package/features/security/ResolveIdentityTenants/abstractions.js +5 -0
- package/features/security/ResolveIdentityTenants/abstractions.js.map +1 -0
- package/features/security/ResolveIdentityTenants/feature.d.ts +4 -0
- package/features/security/ResolveIdentityTenants/feature.js +11 -0
- package/features/security/ResolveIdentityTenants/feature.js.map +1 -0
- package/features/security/ResolveIdentityTenants/index.d.ts +1 -0
- package/features/security/ResolveIdentityTenants/index.js +1 -0
- package/features/security/SecurityFeature.js +4 -0
- package/features/security/SecurityFeature.js.map +1 -1
- package/features/security/login/LogInUseCase.d.ts +20 -0
- package/features/security/login/LogInUseCase.js +75 -0
- package/features/security/login/LogInUseCase.js.map +1 -0
- package/features/security/login/abstractions.d.ts +45 -0
- package/features/security/login/abstractions.js +2 -1
- package/features/security/login/abstractions.js.map +1 -1
- package/features/security/login/errors.d.ts +13 -0
- package/features/security/login/errors.js +25 -0
- package/features/security/login/errors.js.map +1 -0
- package/features/security/login/feature.d.ts +4 -0
- package/features/security/login/feature.js +11 -0
- package/features/security/login/feature.js.map +1 -0
- package/features/tenancy/TenancyFeature.js +1 -1
- package/features/tenancy/TenancyFeature.js.map +1 -1
- package/features/users/AdminUsersFeature.js +2 -0
- package/features/users/AdminUsersFeature.js.map +1 -1
- package/features/users/FindUserRecords/FindUserRecordsUseCase.d.ts +12 -0
- package/features/users/FindUserRecords/FindUserRecordsUseCase.js +54 -0
- package/features/users/FindUserRecords/FindUserRecordsUseCase.js.map +1 -0
- package/features/users/FindUserRecords/abstractions.d.ts +29 -0
- package/features/users/FindUserRecords/abstractions.js +5 -0
- package/features/users/FindUserRecords/abstractions.js.map +1 -0
- package/features/users/FindUserRecords/feature.d.ts +4 -0
- package/features/users/FindUserRecords/feature.js +11 -0
- package/features/users/FindUserRecords/feature.js.map +1 -0
- package/features/users/FindUserRecords/index.d.ts +1 -0
- package/features/users/FindUserRecords/index.js +1 -0
- package/features/users/shared/AdminUsersRepository.d.ts +3 -1
- package/features/users/shared/AdminUsersRepository.js +22 -7
- package/features/users/shared/AdminUsersRepository.js.map +1 -1
- package/features/users/shared/abstractions.d.ts +4 -1
- package/features/users/shared/abstractions.js.map +1 -1
- package/features/users/shared/types.d.ts +9 -0
- package/graphql/security/identity.gql.js +27 -22
- package/graphql/security/identity.gql.js.map +1 -1
- package/legacy/tenancy/createTenancyContext.js +8 -1
- package/legacy/tenancy/createTenancyContext.js.map +1 -1
- package/package.json +21 -20
- package/types/users.d.ts +17 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { LogInUseCase } from "./LogInUseCase.js";
|
|
3
|
+
const LogInFeature = createFeature({
|
|
4
|
+
name: "LogIn",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(LogInUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { LogInFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/security/login/feature.js","sources":["../../../../src/features/security/login/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { LogInUseCase } from \"./LogInUseCase.js\";\n\nexport const LogInFeature = createFeature({\n name: \"LogIn\",\n register(container) {\n container.register(LogInUseCase);\n }\n});\n"],"names":["LogInFeature","createFeature","container","LogInUseCase"],"mappings":";;AAGO,MAAMA,eAAeC,cAAc;IACtC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -17,7 +17,7 @@ const TenancyFeature = createFeature({
|
|
|
17
17
|
container.registerInstance(TenantCache, new TenantCache_js_TenantCache(async (ids)=>{
|
|
18
18
|
if (0 === ids.length) return [];
|
|
19
19
|
const tenants = await storageOperations.getTenantsByIds(ids);
|
|
20
|
-
return ids.map((
|
|
20
|
+
return ids.map((id)=>tenants.find((tenant)=>tenant.id === id));
|
|
21
21
|
}));
|
|
22
22
|
CreateTenantFeature.register(container);
|
|
23
23
|
DeleteTenantFeature.register(container);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/tenancy/TenancyFeature.js","sources":["../../../src/features/tenancy/TenancyFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/tenancy/TenancyFeature.js","sources":["../../../src/features/tenancy/TenancyFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport type {\n Tenant,\n TenancyStorageOperations as ITenancyStorageOperations\n} from \"~/types/tenancy.js\";\nimport { TenantCache } from \"./shared/abstractions.js\";\nimport { TenantCache as TenantCacheImpl } from \"./shared/TenantCache.js\";\nimport { TenancyStorageOperations } from \"./shared/storageOperations.js\";\nimport { GetRootTenantFeature } from \"./GetRootTenant/feature.js\";\nimport { ListTenantsFeature } from \"./ListTenants/feature.js\";\nimport { CreateTenantFeature } from \"./CreateTenant/feature.js\";\nimport { UpdateTenantFeature } from \"./UpdateTenant/feature.js\";\nimport { DeleteTenantFeature } from \"./DeleteTenant/feature.js\";\nimport { GetTenantByIdFeature } from \"./GetTenantById/feature.js\";\nimport { TenantContextFeature } from \"./TenantContext/feature.js\";\nimport { InstallTenantFeature } from \"./InstallTenant/index.js\";\n\nexport const TenancyFeature = createFeature<ITenancyStorageOperations>({\n name: \"TenancyFeature\",\n register: (container, storageOperations) => {\n // Register storage operations abstraction (singleton)\n container.registerInstance(TenancyStorageOperations, storageOperations);\n\n // Register shared cache (singleton) - batch loader provided here\n container.registerInstance(\n TenantCache,\n new TenantCacheImpl(async (ids: readonly string[]) => {\n if (ids.length === 0) {\n return [];\n }\n const tenants = await storageOperations.getTenantsByIds(ids);\n // Storage skips missing tenants and doesn't keep the order, so match by ID.\n return ids.map(id => tenants.find(tenant => tenant.id === id) as Tenant);\n })\n );\n\n // Register all features - they will auto-wire their dependencies from the container\n CreateTenantFeature.register(container);\n DeleteTenantFeature.register(container);\n GetRootTenantFeature.register(container);\n GetTenantByIdFeature.register(container);\n ListTenantsFeature.register(container);\n UpdateTenantFeature.register(container);\n TenantContextFeature.register(container);\n InstallTenantFeature.register(container);\n }\n});\n"],"names":["TenancyFeature","createFeature","container","storageOperations","TenancyStorageOperations","TenantCache","TenantCacheImpl","ids","tenants","id","tenant","CreateTenantFeature","DeleteTenantFeature","GetRootTenantFeature","GetTenantByIdFeature","ListTenantsFeature","UpdateTenantFeature","TenantContextFeature","InstallTenantFeature"],"mappings":";;;;;;;;;;;;AAiBO,MAAMA,iBAAiBC,cAAyC;IACnE,MAAM;IACN,UAAU,CAACC,WAAWC;QAElBD,UAAU,gBAAgB,CAACE,0BAA0BD;QAGrDD,UAAU,gBAAgB,CACtBG,aACA,IAAIC,2BAAgB,OAAOC;YACvB,IAAIA,AAAe,MAAfA,IAAI,MAAM,EACV,OAAO,EAAE;YAEb,MAAMC,UAAU,MAAML,kBAAkB,eAAe,CAACI;YAExD,OAAOA,IAAI,GAAG,CAACE,CAAAA,KAAMD,QAAQ,IAAI,CAACE,CAAAA,SAAUA,OAAO,EAAE,KAAKD;QAC9D;QAIJE,oBAAoB,QAAQ,CAACT;QAC7BU,oBAAoB,QAAQ,CAACV;QAC7BW,qBAAqB,QAAQ,CAACX;QAC9BY,qBAAqB,QAAQ,CAACZ;QAC9Ba,mBAAmB,QAAQ,CAACb;QAC5Bc,oBAAoB,QAAQ,CAACd;QAC7Be,qBAAqB,QAAQ,CAACf;QAC9BgB,qBAAqB,QAAQ,CAAChB;IAClC;AACJ"}
|
|
@@ -9,6 +9,7 @@ import { DeleteUserFeature } from "./DeleteUser/feature.js";
|
|
|
9
9
|
import { ListUserTeamsFeature } from "./ListUserTeams/feature.js";
|
|
10
10
|
import { AdminUsersStorageOperations } from "./shared/storageAbstractions.js";
|
|
11
11
|
import { ExternalIdpUserSyncFeature } from "./ExternalIdpUserSync/index.js";
|
|
12
|
+
import { FindUserRecordsFeature } from "./FindUserRecords/feature.js";
|
|
12
13
|
const AdminUsersFeature = createFeature({
|
|
13
14
|
name: "AdminUsers",
|
|
14
15
|
register (container, storageOperations) {
|
|
@@ -21,6 +22,7 @@ const AdminUsersFeature = createFeature({
|
|
|
21
22
|
UpdateUserFeature.register(container);
|
|
22
23
|
DeleteUserFeature.register(container);
|
|
23
24
|
ExternalIdpUserSyncFeature.register(container);
|
|
25
|
+
FindUserRecordsFeature.register(container);
|
|
24
26
|
container.registerInstance(AdminUsersStorageOperations, storageOperations);
|
|
25
27
|
}
|
|
26
28
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/users/AdminUsersFeature.js","sources":["../../../src/features/users/AdminUsersFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AdminUsersRepository } from \"./shared/AdminUsersRepository.js\";\nimport { GetUserFeature } from \"./GetUser/feature.js\";\nimport { GetIdentityProfileFeature } from \"./GetIdentityProfile/feature.js\";\nimport { ListUsersFeature } from \"./ListUsers/feature.js\";\nimport { CreateUserFeature } from \"./CreateUser/feature.js\";\nimport { UpdateUserFeature } from \"./UpdateUser/feature.js\";\nimport { DeleteUserFeature } from \"./DeleteUser/feature.js\";\nimport { ListUserTeamsFeature } from \"./ListUserTeams/feature.js\";\nimport { AdminUsersStorageOperations } from \"./shared/storageAbstractions.js\";\nimport { ExternalIdpUserSyncFeature } from \"./ExternalIdpUserSync/index.js\";\n\nexport const AdminUsersFeature = createFeature<AdminUsersStorageOperations.Interface>({\n name: \"AdminUsers\",\n register(container, storageOperations) {\n // Register repository in singleton scope\n container.register(AdminUsersRepository).inSingletonScope();\n\n // Register all use cases\n GetUserFeature.register(container);\n GetIdentityProfileFeature.register(container);\n ListUsersFeature.register(container);\n ListUserTeamsFeature.register(container);\n CreateUserFeature.register(container);\n UpdateUserFeature.register(container);\n DeleteUserFeature.register(container);\n ExternalIdpUserSyncFeature.register(container);\n\n // Legacy storage ops\n container.registerInstance(AdminUsersStorageOperations, storageOperations);\n }\n});\n"],"names":["AdminUsersFeature","createFeature","container","storageOperations","AdminUsersRepository","GetUserFeature","GetIdentityProfileFeature","ListUsersFeature","ListUserTeamsFeature","CreateUserFeature","UpdateUserFeature","DeleteUserFeature","ExternalIdpUserSyncFeature","AdminUsersStorageOperations"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/users/AdminUsersFeature.js","sources":["../../../src/features/users/AdminUsersFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { AdminUsersRepository } from \"./shared/AdminUsersRepository.js\";\nimport { GetUserFeature } from \"./GetUser/feature.js\";\nimport { GetIdentityProfileFeature } from \"./GetIdentityProfile/feature.js\";\nimport { ListUsersFeature } from \"./ListUsers/feature.js\";\nimport { CreateUserFeature } from \"./CreateUser/feature.js\";\nimport { UpdateUserFeature } from \"./UpdateUser/feature.js\";\nimport { DeleteUserFeature } from \"./DeleteUser/feature.js\";\nimport { ListUserTeamsFeature } from \"./ListUserTeams/feature.js\";\nimport { AdminUsersStorageOperations } from \"./shared/storageAbstractions.js\";\nimport { ExternalIdpUserSyncFeature } from \"./ExternalIdpUserSync/index.js\";\nimport { FindUserRecordsFeature } from \"./FindUserRecords/feature.js\";\n\nexport const AdminUsersFeature = createFeature<AdminUsersStorageOperations.Interface>({\n name: \"AdminUsers\",\n register(container, storageOperations) {\n // Register repository in singleton scope\n container.register(AdminUsersRepository).inSingletonScope();\n\n // Register all use cases\n GetUserFeature.register(container);\n GetIdentityProfileFeature.register(container);\n ListUsersFeature.register(container);\n ListUserTeamsFeature.register(container);\n CreateUserFeature.register(container);\n UpdateUserFeature.register(container);\n DeleteUserFeature.register(container);\n ExternalIdpUserSyncFeature.register(container);\n FindUserRecordsFeature.register(container);\n\n // Legacy storage ops\n container.registerInstance(AdminUsersStorageOperations, storageOperations);\n }\n});\n"],"names":["AdminUsersFeature","createFeature","container","storageOperations","AdminUsersRepository","GetUserFeature","GetIdentityProfileFeature","ListUsersFeature","ListUserTeamsFeature","CreateUserFeature","UpdateUserFeature","DeleteUserFeature","ExternalIdpUserSyncFeature","FindUserRecordsFeature","AdminUsersStorageOperations"],"mappings":";;;;;;;;;;;;AAaO,MAAMA,oBAAoBC,cAAqD;IAClF,MAAM;IACN,UAASC,SAAS,EAAEC,iBAAiB;QAEjCD,UAAU,QAAQ,CAACE,sBAAsB,gBAAgB;QAGzDC,eAAe,QAAQ,CAACH;QACxBI,0BAA0B,QAAQ,CAACJ;QACnCK,iBAAiB,QAAQ,CAACL;QAC1BM,qBAAqB,QAAQ,CAACN;QAC9BO,kBAAkB,QAAQ,CAACP;QAC3BQ,kBAAkB,QAAQ,CAACR;QAC3BS,kBAAkB,QAAQ,CAACT;QAC3BU,2BAA2B,QAAQ,CAACV;QACpCW,uBAAuB,QAAQ,CAACX;QAGhCA,UAAU,gBAAgB,CAACY,6BAA6BX;IAC5D;AACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FindUserRecordsUseCase as Abstraction } from "./abstractions.js";
|
|
2
|
+
import { ListTenantsUseCase } from "../../../features/tenancy/ListTenants/index.js";
|
|
3
|
+
import { AdminUsersRepository } from "../../../features/users/shared/abstractions.js";
|
|
4
|
+
declare class FindUserRecordsUseCaseImpl implements Abstraction.Interface {
|
|
5
|
+
private listTenants;
|
|
6
|
+
private repository;
|
|
7
|
+
constructor(listTenants: ListTenantsUseCase.Interface, repository: AdminUsersRepository.Interface);
|
|
8
|
+
execute(id: string, options?: Abstraction.Options): Abstraction.Return;
|
|
9
|
+
private probeAllTenants;
|
|
10
|
+
}
|
|
11
|
+
export declare const FindUserRecordsUseCase: import("@webiny/di").Implementation<typeof FindUserRecordsUseCaseImpl>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
|
+
import { FindUserRecordsUseCase } from "./abstractions.js";
|
|
3
|
+
import { ListTenantsUseCase } from "../../tenancy/ListTenants/index.js";
|
|
4
|
+
import { AdminUsersRepository } from "../shared/abstractions.js";
|
|
5
|
+
import { UserStorageError } from "../shared/errors.js";
|
|
6
|
+
class FindUserRecordsUseCaseImpl {
|
|
7
|
+
constructor(listTenants, repository){
|
|
8
|
+
this.listTenants = listTenants;
|
|
9
|
+
this.repository = repository;
|
|
10
|
+
}
|
|
11
|
+
async execute(id, options = {}) {
|
|
12
|
+
const indexedResult = await this.repository.listUserRecords({
|
|
13
|
+
id
|
|
14
|
+
});
|
|
15
|
+
if (indexedResult.isFail()) return Result.fail(indexedResult.error);
|
|
16
|
+
const indexed = indexedResult.value;
|
|
17
|
+
if (indexed.length > 0 && !options.exhaustive) return Result.ok(indexed);
|
|
18
|
+
const probedResult = await this.probeAllTenants(id);
|
|
19
|
+
if (probedResult.isFail()) return Result.fail(probedResult.error);
|
|
20
|
+
const indexedTenants = new Set(indexed.map((user)=>user.tenant));
|
|
21
|
+
const unindexed = probedResult.value.filter((user)=>!indexedTenants.has(user.tenant));
|
|
22
|
+
await Promise.all(unindexed.map((user)=>this.repository.update(user)));
|
|
23
|
+
return Result.ok([
|
|
24
|
+
...indexed,
|
|
25
|
+
...unindexed
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
async probeAllTenants(id) {
|
|
29
|
+
let tenantsResult;
|
|
30
|
+
try {
|
|
31
|
+
tenantsResult = await this.listTenants.execute();
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return Result.fail(new UserStorageError(error));
|
|
34
|
+
}
|
|
35
|
+
if (tenantsResult.isFail()) return Result.fail(new UserStorageError(tenantsResult.error));
|
|
36
|
+
const tenants = tenantsResult.value.filter((tenant)=>tenant.isInstalled);
|
|
37
|
+
if (0 === tenants.length) return Result.ok([]);
|
|
38
|
+
return this.repository.getUserAcrossTenants({
|
|
39
|
+
id,
|
|
40
|
+
tenants: tenants.map((tenant)=>tenant.id)
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const FindUserRecordsUseCase_FindUserRecordsUseCase = createImplementation({
|
|
45
|
+
abstraction: FindUserRecordsUseCase,
|
|
46
|
+
implementation: FindUserRecordsUseCaseImpl,
|
|
47
|
+
dependencies: [
|
|
48
|
+
ListTenantsUseCase,
|
|
49
|
+
AdminUsersRepository
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
export { FindUserRecordsUseCase_FindUserRecordsUseCase as FindUserRecordsUseCase };
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=FindUserRecordsUseCase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/users/FindUserRecords/FindUserRecordsUseCase.js","sources":["../../../../src/features/users/FindUserRecords/FindUserRecordsUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { FindUserRecordsUseCase as Abstraction } from \"./abstractions.js\";\nimport { ListTenantsUseCase } from \"~/features/tenancy/ListTenants/index.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\nimport { UserStorageError } from \"~/features/users/shared/errors.js\";\nimport type { AdminUser } from \"~/features/users/shared/types.js\";\n\nclass FindUserRecordsUseCaseImpl implements Abstraction.Interface {\n constructor(\n private listTenants: ListTenantsUseCase.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(id: string, options: Abstraction.Options = {}): Abstraction.Return {\n const indexedResult = await this.repository.listUserRecords({ id });\n if (indexedResult.isFail()) {\n return Result.fail(indexedResult.error);\n }\n\n const indexed = indexedResult.value;\n if (indexed.length > 0 && !options.exhaustive) {\n return Result.ok(indexed);\n }\n\n const probedResult = await this.probeAllTenants(id);\n if (probedResult.isFail()) {\n return Result.fail(probedResult.error);\n }\n\n const indexedTenants = new Set(indexed.map(user => user.tenant));\n const unindexed = probedResult.value.filter(user => !indexedTenants.has(user.tenant));\n\n // Rewriting a record adds the index keys. A failed write only means the next lookup probes again.\n await Promise.all(unindexed.map(user => this.repository.update(user)));\n\n return Result.ok([...indexed, ...unindexed]);\n }\n\n private async probeAllTenants(id: string): Promise<Result<AdminUser[], Abstraction.Error>> {\n let tenantsResult: Awaited<ReturnType<ListTenantsUseCase.Interface[\"execute\"]>>;\n try {\n tenantsResult = await this.listTenants.execute();\n } catch (error) {\n return Result.fail(new UserStorageError(error as Error));\n }\n\n if (tenantsResult.isFail()) {\n return Result.fail(new UserStorageError(tenantsResult.error as Error));\n }\n\n // Uninstalled tenants have no users yet.\n const tenants = tenantsResult.value.filter(tenant => tenant.isInstalled);\n if (tenants.length === 0) {\n return Result.ok([]);\n }\n\n return this.repository.getUserAcrossTenants({\n id,\n tenants: tenants.map(tenant => tenant.id)\n });\n }\n}\n\nexport const FindUserRecordsUseCase = createImplementation({\n abstraction: Abstraction,\n implementation: FindUserRecordsUseCaseImpl,\n dependencies: [ListTenantsUseCase, AdminUsersRepository]\n});\n"],"names":["FindUserRecordsUseCaseImpl","listTenants","repository","id","options","indexedResult","Result","indexed","probedResult","indexedTenants","Set","user","unindexed","Promise","tenantsResult","error","UserStorageError","tenants","tenant","FindUserRecordsUseCase","createImplementation","Abstraction","ListTenantsUseCase","AdminUsersRepository"],"mappings":";;;;;AAQA,MA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AW;QACvE,IAAID,AAAmB,MAAnBA,QAAQ,MAAM,EACd,OAAOX,OAAO,EAAE,CAAC,EAAE;QAGvB,OAAO,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC;YACxCH;YACA,SAASc,QAAQ,GAAG,CAACC,CAAAA,SAAUA,OAAO,EAAE;QAC5C;IACJ;AACJ;AAEO,MAAMC,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBrB;IAChB,cAAc;QAACsB;QAAoBC;KAAqB;AAC5D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { AdminUser } from "../../../features/users/shared/types.js";
|
|
3
|
+
import { AdminUsersRepository } from "../../../features/users/shared/abstractions.js";
|
|
4
|
+
export interface FindUserRecordsOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Also probe every installed tenant, instead of trusting a non-empty index result.
|
|
7
|
+
* Records written before the user→tenant index existed are only found this way, so
|
|
8
|
+
* anything that acts on "the user has no other tenant" (deleting the sign-in account,
|
|
9
|
+
* changing its password) must set it.
|
|
10
|
+
*/
|
|
11
|
+
exhaustive?: boolean;
|
|
12
|
+
}
|
|
13
|
+
type FindUserRecordsError = AdminUsersRepository.Error;
|
|
14
|
+
export interface IFindUserRecordsUseCase {
|
|
15
|
+
/**
|
|
16
|
+
* Find the user's records in every tenant (disabled tenants included).
|
|
17
|
+
* Records found outside the user→tenant index are added to it.
|
|
18
|
+
*/
|
|
19
|
+
execute(id: string, options?: FindUserRecordsOptions): Promise<Result<AdminUser[], FindUserRecordsError>>;
|
|
20
|
+
}
|
|
21
|
+
/** Find every tenant's record of one user. */
|
|
22
|
+
export declare const FindUserRecordsUseCase: import("@webiny/di").Abstraction<IFindUserRecordsUseCase>;
|
|
23
|
+
export declare namespace FindUserRecordsUseCase {
|
|
24
|
+
type Interface = IFindUserRecordsUseCase;
|
|
25
|
+
type Options = FindUserRecordsOptions;
|
|
26
|
+
type Error = FindUserRecordsError;
|
|
27
|
+
type Return = Promise<Result<AdminUser[], FindUserRecordsError>>;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/users/FindUserRecords/abstractions.js","sources":["../../../../src/features/users/FindUserRecords/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { AdminUser } from \"~/features/users/shared/types.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\n\nexport interface FindUserRecordsOptions {\n /**\n * Also probe every installed tenant, instead of trusting a non-empty index result.\n * Records written before the user→tenant index existed are only found this way, so\n * anything that acts on \"the user has no other tenant\" (deleting the sign-in account,\n * changing its password) must set it.\n */\n exhaustive?: boolean;\n}\n\ntype FindUserRecordsError = AdminUsersRepository.Error;\n\nexport interface IFindUserRecordsUseCase {\n /**\n * Find the user's records in every tenant (disabled tenants included).\n * Records found outside the user→tenant index are added to it.\n */\n execute(\n id: string,\n options?: FindUserRecordsOptions\n ): Promise<Result<AdminUser[], FindUserRecordsError>>;\n}\n\n/** Find every tenant's record of one user. */\nexport const FindUserRecordsUseCase =\n createAbstraction<IFindUserRecordsUseCase>(\"FindUserRecordsUseCase\");\n\nexport namespace FindUserRecordsUseCase {\n export type Interface = IFindUserRecordsUseCase;\n export type Options = FindUserRecordsOptions;\n export type Error = FindUserRecordsError;\n export type Return = Promise<Result<AdminUser[], FindUserRecordsError>>;\n}\n"],"names":["FindUserRecordsUseCase","createAbstraction"],"mappings":";AA6BO,MAAMA,yBACTC,kBAA2C"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { FindUserRecordsUseCase } from "./FindUserRecordsUseCase.js";
|
|
3
|
+
const FindUserRecordsFeature = createFeature({
|
|
4
|
+
name: "FindUserRecords",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(FindUserRecordsUseCase);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { FindUserRecordsFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/users/FindUserRecords/feature.js","sources":["../../../../src/features/users/FindUserRecords/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { FindUserRecordsUseCase } from \"./FindUserRecordsUseCase.js\";\n\nexport const FindUserRecordsFeature = createFeature({\n name: \"FindUserRecords\",\n register(container) {\n container.register(FindUserRecordsUseCase);\n }\n});\n"],"names":["FindUserRecordsFeature","createFeature","container","FindUserRecordsUseCase"],"mappings":";;AAGO,MAAMA,yBAAyBC,cAAc;IAChD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FindUserRecordsUseCase } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FindUserRecordsUseCase } from "./abstractions.js";
|
|
@@ -3,7 +3,7 @@ import { TenantContext } from "../../../features/tenancy/TenantContext/index.js"
|
|
|
3
3
|
import { AdminUsersRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
4
4
|
import { AdminUsersStorageOperations } from "./storageAbstractions.js";
|
|
5
5
|
import type { AdminUser } from "./types.js";
|
|
6
|
-
import type { GetUserInput, ListUsersInput } from "./types.js";
|
|
6
|
+
import type { GetUserAcrossTenantsInput, GetUserInput, ListUserRecordsInput, ListUsersInput } from "./types.js";
|
|
7
7
|
declare class AdminUsersRepositoryImpl implements RepositoryAbstraction.Interface {
|
|
8
8
|
private tenantContext;
|
|
9
9
|
private storageOperations;
|
|
@@ -11,6 +11,8 @@ declare class AdminUsersRepositoryImpl implements RepositoryAbstraction.Interfac
|
|
|
11
11
|
constructor(tenantContext: TenantContext.Interface, storageOperations: AdminUsersStorageOperations.Interface);
|
|
12
12
|
get(params: GetUserInput): Promise<Result<AdminUser, RepositoryAbstraction.Error>>;
|
|
13
13
|
list(params: ListUsersInput): Promise<Result<AdminUser[], RepositoryAbstraction.Error>>;
|
|
14
|
+
getUserAcrossTenants(params: GetUserAcrossTenantsInput): Promise<Result<AdminUser[], RepositoryAbstraction.Error>>;
|
|
15
|
+
listUserRecords(params: ListUserRecordsInput): Promise<Result<AdminUser[], RepositoryAbstraction.Error>>;
|
|
14
16
|
create(user: AdminUser): Promise<Result<AdminUser, RepositoryAbstraction.Error>>;
|
|
15
17
|
update(user: AdminUser): Promise<Result<AdminUser, RepositoryAbstraction.Error>>;
|
|
16
18
|
delete(user: AdminUser): Promise<Result<void, RepositoryAbstraction.Error>>;
|
|
@@ -27,7 +27,7 @@ class AdminUsersRepositoryImpl {
|
|
|
27
27
|
if (params.email) {
|
|
28
28
|
const user = await this.storageOperations.getUser({
|
|
29
29
|
where: {
|
|
30
|
-
tenant,
|
|
30
|
+
tenant: params.tenant ?? tenant,
|
|
31
31
|
email: params.email
|
|
32
32
|
}
|
|
33
33
|
});
|
|
@@ -56,6 +56,22 @@ class AdminUsersRepositoryImpl {
|
|
|
56
56
|
return Result.fail(new UserStorageError(error));
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
async getUserAcrossTenants(params) {
|
|
60
|
+
try {
|
|
61
|
+
const users = await this.storageOperations.getUserAcrossTenants(params);
|
|
62
|
+
return Result.ok(users);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
return Result.fail(new UserStorageError(error));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async listUserRecords(params) {
|
|
68
|
+
try {
|
|
69
|
+
const users = await this.storageOperations.listUserRecords(params);
|
|
70
|
+
return Result.ok(users);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
return Result.fail(new UserStorageError(error));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
59
75
|
async create(user) {
|
|
60
76
|
try {
|
|
61
77
|
const result = await this.storageOperations.createUser({
|
|
@@ -77,11 +93,11 @@ class AdminUsersRepositoryImpl {
|
|
|
77
93
|
await this.storageOperations.updateUser({
|
|
78
94
|
user
|
|
79
95
|
});
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
tenant,
|
|
96
|
+
const key = {
|
|
97
|
+
tenant: user.tenant,
|
|
83
98
|
id: user.id
|
|
84
|
-
}
|
|
99
|
+
};
|
|
100
|
+
this.loaders.getUser.clear(key).prime(key, user);
|
|
85
101
|
return Result.ok(user);
|
|
86
102
|
} catch (error) {
|
|
87
103
|
return Result.fail(new UserStorageError(error));
|
|
@@ -92,10 +108,9 @@ class AdminUsersRepositoryImpl {
|
|
|
92
108
|
await this.storageOperations.deleteUser({
|
|
93
109
|
user
|
|
94
110
|
});
|
|
95
|
-
const tenant = this.tenantContext.getTenant().id;
|
|
96
111
|
this.clearCache([
|
|
97
112
|
{
|
|
98
|
-
tenant,
|
|
113
|
+
tenant: user.tenant,
|
|
99
114
|
id: user.id
|
|
100
115
|
}
|
|
101
116
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/users/shared/AdminUsersRepository.js","sources":["../../../../src/features/users/shared/AdminUsersRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { AdminUsersRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { AdminUsersStorageOperations } from \"./storageAbstractions.js\";\nimport { createUserLoaders } from \"./loaders.js\";\nimport { UserNotFoundError, UserStorageError } from \"./errors.js\";\nimport type { AdminUser } from \"./types.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/users/shared/AdminUsersRepository.js","sources":["../../../../src/features/users/shared/AdminUsersRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { AdminUsersRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { AdminUsersStorageOperations } from \"./storageAbstractions.js\";\nimport { createUserLoaders } from \"./loaders.js\";\nimport { UserNotFoundError, UserStorageError } from \"./errors.js\";\nimport type { AdminUser } from \"./types.js\";\nimport type {\n GetUserAcrossTenantsInput,\n GetUserInput,\n ListUserRecordsInput,\n ListUsersInput\n} from \"./types.js\";\n\nclass AdminUsersRepositoryImpl implements RepositoryAbstraction.Interface {\n private loaders: ReturnType<typeof createUserLoaders>;\n\n constructor(\n private tenantContext: TenantContext.Interface,\n private storageOperations: AdminUsersStorageOperations.Interface\n ) {\n // Initialize DataLoaders using existing implementation\n this.loaders = createUserLoaders({\n getTenant: () => this.tenantContext.getTenant().id,\n storageOperations: this.storageOperations\n });\n }\n\n async get(params: GetUserInput): Promise<Result<AdminUser, RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant().id;\n\n // Use DataLoader for ID-based queries (majority of queries)\n if (params.id) {\n const user = await this.loaders.getUser.load({\n tenant,\n id: params.id\n });\n\n if (!user) {\n return Result.fail(new UserNotFoundError(params.id));\n }\n\n return Result.ok(user);\n }\n\n // Direct query for email-based lookups (rare)\n if (params.email) {\n const user = await this.storageOperations.getUser({\n where: { tenant: params.tenant ?? tenant, email: params.email }\n });\n\n if (!user) {\n return Result.fail(new UserNotFoundError(params.email));\n }\n\n return Result.ok(user);\n }\n\n return Result.fail(new UserNotFoundError(\"unknown\"));\n } catch (error) {\n return Result.fail(new UserStorageError(error as Error));\n }\n }\n\n async list(params: ListUsersInput): Promise<Result<AdminUser[], RepositoryAbstraction.Error>> {\n try {\n const tenant = this.tenantContext.getTenant().id;\n const users = await this.storageOperations.listUsers({\n where: { tenant, ...params.where },\n sort: params.sort || [\"createdOn_ASC\"]\n });\n\n return Result.ok(users);\n } catch (error) {\n return Result.fail(new UserStorageError(error as Error));\n }\n }\n\n async getUserAcrossTenants(\n params: GetUserAcrossTenantsInput\n ): Promise<Result<AdminUser[], RepositoryAbstraction.Error>> {\n try {\n const users = await this.storageOperations.getUserAcrossTenants(params);\n\n return Result.ok(users);\n } catch (error) {\n return Result.fail(new UserStorageError(error as Error));\n }\n }\n\n async listUserRecords(\n params: ListUserRecordsInput\n ): Promise<Result<AdminUser[], RepositoryAbstraction.Error>> {\n try {\n const users = await this.storageOperations.listUserRecords(params);\n\n return Result.ok(users);\n } catch (error) {\n return Result.fail(new UserStorageError(error as Error));\n }\n }\n\n async create(user: AdminUser): Promise<Result<AdminUser, RepositoryAbstraction.Error>> {\n try {\n const result = await this.storageOperations.createUser({ user });\n\n // Prime the cache with the new user\n const tenant = this.tenantContext.getTenant().id;\n const key = { tenant, id: result.id };\n this.loaders.getUser.clear(key).prime(key, result);\n\n return Result.ok(result);\n } catch (error) {\n return Result.fail(new UserStorageError(error as Error));\n }\n }\n\n async update(user: AdminUser): Promise<Result<AdminUser, RepositoryAbstraction.Error>> {\n try {\n await this.storageOperations.updateUser({ user });\n\n // Update the cache. The record can belong to another tenant than the current one.\n const key = { tenant: user.tenant, id: user.id };\n this.loaders.getUser.clear(key).prime(key, user);\n\n return Result.ok(user);\n } catch (error) {\n return Result.fail(new UserStorageError(error as Error));\n }\n }\n\n async delete(user: AdminUser): Promise<Result<void, RepositoryAbstraction.Error>> {\n try {\n await this.storageOperations.deleteUser({ user });\n\n // Clear from cache\n this.clearCache([{ tenant: user.tenant, id: user.id }]);\n\n return Result.ok();\n } catch (error) {\n return Result.fail(new UserStorageError(error as Error));\n }\n }\n\n clearCache(keys: Array<{ tenant: string; id: string }>): void {\n this.loaders.clearLoadersCache(keys);\n }\n}\n\nexport const AdminUsersRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: AdminUsersRepositoryImpl,\n dependencies: [TenantContext, AdminUsersStorageOperations]\n});\n"],"names":["AdminUsersRepositoryImpl","tenantContext","storageOperations","createUserLoaders","params","tenant","user","Result","UserNotFoundError","error","UserStorageError","users","result","key","keys","AdminUsersRepository","createImplementation","RepositoryAbstraction","TenantContext","Ad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C,UAAU,CAAC;gBAAEA;YAAK;YAG/C,MAAMO,MAAM;gBAAE,QAAQP,KAAK,MAAM;gBAAE,IAAIA,KAAK,EAAE;YAAC;YAC/C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAACO,KAAK,KAAK,CAACA,KAAKP;YAE3C,OAAOC,OAAO,EAAE,CAACD;QACrB,EAAE,OAAOG,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIG,iBAAiBD;QAC5C;IACJ;IAEA,MAAM,OAAOH,IAAe,EAAsD;QAC9E,IAAI;YACA,MAAM,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC;gBAAEA;YAAK;YAG/C,IAAI,CAAC,UAAU,CAAC;gBAAC;oBAAE,QAAQA,KAAK,MAAM;oBAAE,IAAIA,KAAK,EAAE;gBAAC;aAAE;YAEtD,OAAOC,OAAO,EAAE;QACpB,EAAE,OAAOE,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIG,iBAAiBD;QAC5C;IACJ;IAEA,WAAWK,IAA2C,EAAQ;QAC1D,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAACA;IACnC;AACJ;AAEO,MAAMC,4CAAuBC,qBAAqB;IACrD,aAAaC;IACb,gBAAgBjB;IAChB,cAAc;QAACkB;QAAeC;KAA4B;AAC9D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import type { AdminUser } from "../../../types/users.js";
|
|
3
|
-
import type { GetUserInput, ListUsersInput } from "./types.js";
|
|
3
|
+
import type { GetUserAcrossTenantsInput, GetUserInput, ListUserRecordsInput, ListUsersInput } from "./types.js";
|
|
4
4
|
import { UserNotFoundError, UserStorageError } from "./errors.js";
|
|
5
5
|
export interface IAdminUsersRepositoryErrors {
|
|
6
6
|
base: UserNotFoundError | UserStorageError;
|
|
@@ -9,6 +9,9 @@ export type RepositoryError = IAdminUsersRepositoryErrors[keyof IAdminUsersRepos
|
|
|
9
9
|
export interface IAdminUsersRepository {
|
|
10
10
|
get(params: GetUserInput): Promise<Result<AdminUser, RepositoryError>>;
|
|
11
11
|
list(params: ListUsersInput): Promise<Result<AdminUser[], RepositoryError>>;
|
|
12
|
+
getUserAcrossTenants(params: GetUserAcrossTenantsInput): Promise<Result<AdminUser[], RepositoryError>>;
|
|
13
|
+
/** Every tenant's record of the user, through the user→tenant index. */
|
|
14
|
+
listUserRecords(params: ListUserRecordsInput): Promise<Result<AdminUser[], RepositoryError>>;
|
|
12
15
|
create(user: AdminUser): Promise<Result<AdminUser, RepositoryError>>;
|
|
13
16
|
update(user: AdminUser): Promise<Result<AdminUser, RepositoryError>>;
|
|
14
17
|
delete(user: AdminUser): Promise<Result<void, RepositoryError>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/users/shared/abstractions.js","sources":["../../../../src/features/users/shared/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { AdminUser } from \"~/types/users.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"features/users/shared/abstractions.js","sources":["../../../../src/features/users/shared/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport type { AdminUser } from \"~/types/users.js\";\nimport type {\n GetUserAcrossTenantsInput,\n GetUserInput,\n ListUserRecordsInput,\n ListUsersInput\n} from \"./types.js\";\nimport { UserNotFoundError, UserStorageError } from \"./errors.js\";\n\n// Repository error interface\nexport interface IAdminUsersRepositoryErrors {\n base: UserNotFoundError | UserStorageError;\n}\n\nexport type RepositoryError = IAdminUsersRepositoryErrors[keyof IAdminUsersRepositoryErrors];\n\n// Repository interface\nexport interface IAdminUsersRepository {\n get(params: GetUserInput): Promise<Result<AdminUser, RepositoryError>>;\n list(params: ListUsersInput): Promise<Result<AdminUser[], RepositoryError>>;\n getUserAcrossTenants(\n params: GetUserAcrossTenantsInput\n ): Promise<Result<AdminUser[], RepositoryError>>;\n /** Every tenant's record of the user, through the user→tenant index. */\n listUserRecords(params: ListUserRecordsInput): Promise<Result<AdminUser[], RepositoryError>>;\n create(user: AdminUser): Promise<Result<AdminUser, RepositoryError>>;\n update(user: AdminUser): Promise<Result<AdminUser, RepositoryError>>;\n delete(user: AdminUser): Promise<Result<void, RepositoryError>>;\n clearCache(keys: Array<{ tenant: string; id: string }>): void;\n}\n\n/** Persist and retrieve admin users. */\nexport const AdminUsersRepository =\n createAbstraction<IAdminUsersRepository>(\"AdminUsersRepository\");\n\n// Namespace exports\nexport namespace AdminUsersRepository {\n export type Interface = IAdminUsersRepository;\n export type Error = RepositoryError;\n}\n"],"names":["AdminUsersRepository","createAbstraction"],"mappings":";AAkCO,MAAMA,uBACTC,kBAAyC"}
|
|
@@ -26,7 +26,16 @@ export type GetUserInput = {
|
|
|
26
26
|
} | {
|
|
27
27
|
id?: never;
|
|
28
28
|
email: string;
|
|
29
|
+
/** Look the email up in this tenant instead of the current one. */
|
|
30
|
+
tenant?: string;
|
|
29
31
|
};
|
|
32
|
+
export interface GetUserAcrossTenantsInput {
|
|
33
|
+
id: string;
|
|
34
|
+
tenants: string[];
|
|
35
|
+
}
|
|
36
|
+
export interface ListUserRecordsInput {
|
|
37
|
+
id: string;
|
|
38
|
+
}
|
|
30
39
|
export interface ListUsersInput {
|
|
31
40
|
where?: {
|
|
32
41
|
id_in?: string[];
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql/plugins/GraphQLSchemaPlugin.js";
|
|
2
2
|
import { ErrorResponse, Response } from "@webiny/handler-graphql";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { GetIdentityProfileUseCase } from "../../features/users/GetIdentityProfile/index.js";
|
|
3
|
+
import { LogInUseCase } from "../../features/security/login/index.js";
|
|
4
|
+
import { ResolveIdentityTenantsUseCase } from "../../features/security/ResolveIdentityTenants/index.js";
|
|
6
5
|
import { TeamsRepository } from "../../features/security/teams/shared/abstractions.js";
|
|
7
6
|
import { RolesRepository } from "../../features/security/roles/shared/abstractions.js";
|
|
8
|
-
import { IdentityContext } from "../../features/security/IdentityContext/index.js";
|
|
9
7
|
import { ProfileMapper } from "./ProfileMapper.js";
|
|
10
8
|
const getDefaultTenant = async (context)=>{
|
|
11
9
|
const identity = context.security.getIdentity();
|
|
@@ -51,10 +49,19 @@ const identity_gql = new GraphQLSchemaPlugin({
|
|
|
51
49
|
profile: SecurityIdentityProfile!
|
|
52
50
|
currentTenant: SecurityIdentityTenant!
|
|
53
51
|
defaultTenant: SecurityIdentityTenant!
|
|
52
|
+
"The enabled tenants in which the identity has a user record, sorted by name."
|
|
53
|
+
tenants: [SecurityIdentityTenant!]!
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
"The identity has no user record in this tenant, but has one in these tenants."
|
|
57
|
+
type SecurityLoginTenantSelection {
|
|
58
|
+
tenants: [SecurityIdentityTenant!]!
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
union SecurityLoginResult = SecurityIdentity | SecurityLoginTenantSelection
|
|
62
|
+
|
|
56
63
|
type SecurityIdentityLoginResponse {
|
|
57
|
-
data:
|
|
64
|
+
data: SecurityLoginResult
|
|
58
65
|
error: SecurityError
|
|
59
66
|
}
|
|
60
67
|
|
|
@@ -66,29 +73,21 @@ const identity_gql = new GraphQLSchemaPlugin({
|
|
|
66
73
|
resolvers: {
|
|
67
74
|
SecurityMutation: {
|
|
68
75
|
login: async (_, __, context)=>{
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
if (identity.isAnonymous()) return new ErrorResponse({
|
|
72
|
-
code: "Security/Identity/NotAuthenticated",
|
|
73
|
-
message: "Unauthenticated!"
|
|
74
|
-
});
|
|
76
|
+
const logIn = context.container.resolve(LogInUseCase);
|
|
77
|
+
let result;
|
|
75
78
|
try {
|
|
76
|
-
|
|
77
|
-
await eventPublisher.publish(new AfterLoginEvent({
|
|
78
|
-
identity
|
|
79
|
-
}));
|
|
79
|
+
result = await logIn.execute();
|
|
80
80
|
} catch (err) {
|
|
81
81
|
return new ErrorResponse(err);
|
|
82
82
|
}
|
|
83
|
+
if (result.isFail()) return new ErrorResponse(result.error);
|
|
84
|
+
if ("tenantSelectionRequired" === result.value.type) return new Response({
|
|
85
|
+
__typename: "SecurityLoginTenantSelection",
|
|
86
|
+
tenants: result.value.tenants
|
|
87
|
+
});
|
|
88
|
+
const { identity, user } = result.value;
|
|
83
89
|
const rolesRepo = context.container.resolve(RolesRepository);
|
|
84
90
|
const teamsRepo = context.container.resolve(TeamsRepository);
|
|
85
|
-
const getProfile = context.container.resolve(GetIdentityProfileUseCase);
|
|
86
|
-
const result = await context.security.withoutAuthorization(async ()=>getProfile.execute(identity.id));
|
|
87
|
-
if (result.isFail()) return new ErrorResponse({
|
|
88
|
-
code: "Security/Identity/NotAuthorized",
|
|
89
|
-
message: "Missing user profile!"
|
|
90
|
-
});
|
|
91
|
-
const user = result.value;
|
|
92
91
|
const [roles, teams] = await Promise.all([
|
|
93
92
|
getRoles(user, rolesRepo),
|
|
94
93
|
getTeams(user, teamsRepo)
|
|
@@ -96,6 +95,7 @@ const identity_gql = new GraphQLSchemaPlugin({
|
|
|
96
95
|
const profileMapper = new ProfileMapper();
|
|
97
96
|
const profile = await profileMapper.toDTO(user);
|
|
98
97
|
return new Response({
|
|
98
|
+
__typename: "SecurityIdentity",
|
|
99
99
|
...identity.toJson(),
|
|
100
100
|
profile,
|
|
101
101
|
roles,
|
|
@@ -112,6 +112,11 @@ const identity_gql = new GraphQLSchemaPlugin({
|
|
|
112
112
|
},
|
|
113
113
|
permissions (_, __, context) {
|
|
114
114
|
return context.security.listPermissions();
|
|
115
|
+
},
|
|
116
|
+
async tenants (identity, __, context) {
|
|
117
|
+
const resolveIdentityTenants = context.container.resolve(ResolveIdentityTenantsUseCase);
|
|
118
|
+
const result = await context.security.withoutAuthorization(()=>resolveIdentityTenants.execute(identity.id));
|
|
119
|
+
return result.isOk() ? result.value : [];
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/security/identity.gql.js","sources":["../../../src/graphql/security/identity.gql.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/plugins/GraphQLSchemaPlugin.js\";\nimport { ErrorResponse, Response } from \"@webiny/handler-graphql\";\nimport
|
|
1
|
+
{"version":3,"file":"graphql/security/identity.gql.js","sources":["../../../src/graphql/security/identity.gql.ts"],"sourcesContent":["import { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/plugins/GraphQLSchemaPlugin.js\";\nimport { ErrorResponse, Response } from \"@webiny/handler-graphql\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { LogInUseCase } from \"~/features/security/login/index.js\";\nimport { ResolveIdentityTenantsUseCase } from \"~/features/security/ResolveIdentityTenants/index.js\";\nimport type { SecurityContext } from \"~/types/security.js\";\nimport type { AdminUser } from \"~/types/users.js\";\nimport { TeamsRepository } from \"~/features/security/teams/shared/abstractions.js\";\nimport { RolesRepository } from \"~/features/security/roles/shared/abstractions.js\";\nimport { ProfileMapper } from \"./ProfileMapper.js\";\n\nconst getDefaultTenant = async (context: SecurityContext) => {\n const identity = context.security.getIdentity();\n const defaultTenantId = identity.context.defaultTenantId ?? \"root\";\n\n const defaultTenant = await context.tenancy.getTenantById(defaultTenantId);\n if (defaultTenant) {\n return defaultTenant;\n }\n\n return context.tenancy.getRootTenant();\n};\n\nexport default new GraphQLSchemaPlugin<ApiCoreContext>({\n typeDefs: /* GraphQL */ `\n type SecurityIdentityTenant {\n id: ID!\n name: String!\n }\n type SecurityIdentityProfileRole {\n id: String!\n slug: String!\n name: String!\n }\n\n type SecurityIdentityProfileTeam {\n id: String!\n slug: String!\n name: String!\n }\n\n type SecurityIdentityProfile {\n firstName: String\n lastName: String\n email: String\n avatar: JSON\n external: Boolean!\n createdOn: DateTime!\n }\n\n type SecurityIdentity {\n id: ID!\n type: String!\n displayName: String!\n roles: [SecurityIdentityProfileRole!]!\n teams: [SecurityIdentityProfileTeam!]!\n permissions: [JSON!]!\n profile: SecurityIdentityProfile!\n currentTenant: SecurityIdentityTenant!\n defaultTenant: SecurityIdentityTenant!\n \"The enabled tenants in which the identity has a user record, sorted by name.\"\n tenants: [SecurityIdentityTenant!]!\n }\n\n \"The identity has no user record in this tenant, but has one in these tenants.\"\n type SecurityLoginTenantSelection {\n tenants: [SecurityIdentityTenant!]!\n }\n\n union SecurityLoginResult = SecurityIdentity | SecurityLoginTenantSelection\n\n type SecurityIdentityLoginResponse {\n data: SecurityLoginResult\n error: SecurityError\n }\n\n extend type SecurityMutation {\n \"Login using idToken obtained from a 3rd party identity provider\"\n login: SecurityIdentityLoginResponse\n }\n `,\n resolvers: {\n SecurityMutation: {\n login: async (_, __, context) => {\n const logIn = context.container.resolve(LogInUseCase);\n\n let result: Awaited<LogInUseCase.Return>;\n try {\n result = await logIn.execute();\n } catch (err) {\n // AfterLogin handlers report failures by throwing.\n return new ErrorResponse(err);\n }\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n if (result.value.type === \"tenantSelectionRequired\") {\n return new Response({\n __typename: \"SecurityLoginTenantSelection\",\n tenants: result.value.tenants\n });\n }\n\n const { identity, user } = result.value;\n\n // Roles and teams are stored in the user record.\n const rolesRepo = context.container.resolve(RolesRepository);\n const teamsRepo = context.container.resolve(TeamsRepository);\n\n const [roles, teams] = await Promise.all([\n getRoles(user, rolesRepo),\n getTeams(user, teamsRepo)\n ]);\n\n const profileMapper = new ProfileMapper();\n const profile = await profileMapper.toDTO(user);\n\n return new Response({\n __typename: \"SecurityIdentity\",\n ...identity.toJson(),\n profile,\n roles,\n teams\n });\n }\n },\n SecurityIdentity: {\n defaultTenant(_, __, context) {\n return getDefaultTenant(context);\n },\n currentTenant(_, __, context) {\n return context.tenancy.getCurrentTenant();\n },\n permissions(_, __, context) {\n return context.security.listPermissions();\n },\n async tenants(identity: { id: string }, __, context) {\n const resolveIdentityTenants = context.container.resolve(\n ResolveIdentityTenantsUseCase\n );\n const result = await context.security.withoutAuthorization(() => {\n return resolveIdentityTenants.execute(identity.id);\n });\n\n // The list only drives tenant switching, so a failed lookup doesn't fail the login.\n return result.isOk() ? result.value : [];\n }\n }\n }\n});\n\nconst getRoles = async (user: AdminUser, rolesRepo: RolesRepository.Interface) => {\n const roleIds = user.roles ?? [];\n if (roleIds.length > 0) {\n const result = await rolesRepo.list({\n where: { id_in: roleIds }\n });\n\n if (result.isOk()) {\n return result.value.map(role => ({\n id: role.id,\n slug: role.slug,\n name: role.name\n }));\n }\n }\n\n return [];\n};\n\nconst getTeams = async (user: AdminUser, teamsRepo: TeamsRepository.Interface) => {\n const teamIds = user.teams ?? [];\n if (teamIds.length > 0) {\n const result = await teamsRepo.list({\n where: { id_in: teamIds }\n });\n if (result.isOk()) {\n return result.value.map(team => ({\n id: team.id,\n slug: team.slug,\n name: team.name\n }));\n }\n }\n return [];\n};\n"],"names":["getDefaultTenant","context","identity","defaultTenantId","defaultTenant","GraphQLSchemaPlugin","_","__","logIn","LogInUseCase","result","err","ErrorResponse","Response","user","rolesRepo","RolesRepository","teamsRepo","TeamsRepository","roles","teams","Promise","getRoles","getTeams","profileMapper","ProfileMapper","profile","resolveIdentityTenants","ResolveIdentityTenantsUseCase","roleIds","role","teamIds","team"],"mappings":";;;;;;;AAWA,MAAMA,mBAAmB,OAAOC;IAC5B,MAAMC,WAAWD,QAAQ,QAAQ,CAAC,WAAW;IAC7C,MAAME,kBAAkBD,SAAS,OAAO,CAAC,eAAe,IAAI;IAE5D,MAAME,gBAAgB,MAAMH,QAAQ,OAAO,CAAC,aAAa,CAACE;IAC1D,IAAIC,eACA,OAAOA;IAGX,OAAOH,QAAQ,OAAO,CAAC,aAAa;AACxC;AAEA,qBAAe,IAAII,oBAAoC;IACnD,UAAwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
|
|
3
4
|
import { GetTenantByIdUseCase } from "../../features/tenancy/GetTenantById/index.js";
|
|
4
5
|
import { TenantContext } from "../../features/tenancy/TenantContext/index.js";
|
|
@@ -21,7 +22,13 @@ const createTenancyContext = ()=>new ContextPlugin(async (context)=>{
|
|
|
21
22
|
const tenantResult = await getTenantById.execute(tenantId);
|
|
22
23
|
if (tenantResult.isOk()) tenantContext.setTenant(tenantResult.value);
|
|
23
24
|
else {
|
|
24
|
-
if ("root" !== tenantId) throw new
|
|
25
|
+
if ("root" !== tenantId) throw new error({
|
|
26
|
+
message: "Unable to load tenant!",
|
|
27
|
+
code: "Tenancy/TenantNotFound",
|
|
28
|
+
data: {
|
|
29
|
+
tenantId
|
|
30
|
+
}
|
|
31
|
+
});
|
|
25
32
|
tenantContext.setTenant(RootTenantValue.create());
|
|
26
33
|
}
|
|
27
34
|
context.tenancy = new LegacyContext(context.container);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy/tenancy/createTenancyContext.js","sources":["../../../src/legacy/tenancy/createTenancyContext.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport { Request } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { GetTenantByIdUseCase } from \"~/features/tenancy/GetTenantById/index.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { LegacyContext } from \"~/legacy/tenancy/LegacyContext.js\";\nimport { RootTenantValue } from \"~/domain/tenancy/RootTenantValue.js\";\n\nexport const createTenancyContext = () => {\n return new ContextPlugin<ApiCoreContext>(async context => {\n let tenantId = \"root\";\n\n const request = context.container.resolve(Request);\n\n const multiTenancy = context.wcp.canUseFeature(\"multiTenancy\");\n if (!request) {\n throw new Error(\"MISSING CONTEXT REQUEST\");\n }\n\n if (multiTenancy) {\n const { headers = {} } = request;\n\n tenantId = (headers[\"x-tenant\"] as string) ?? \"root\";\n }\n\n // Add WCP telemetry identifier\n // This tenancy package is used by GraphQL, Headless CMS, and PB import/export functions\n context.plugins.register({ type: \"wcp-telemetry-tracker\" });\n\n // We need to load tenant, and set the current tenant context.\n const getTenantById = context.container.resolve(GetTenantByIdUseCase);\n const tenantContext = context.container.resolve(TenantContext);\n\n const tenantResult = await getTenantById.execute(tenantId);\n if (tenantResult.isOk()) {\n tenantContext.setTenant(tenantResult.value);\n } else {\n // If there's no `root` tenant, it means system installation wasn't finished yet.\n // But all other tenants should throw an error.\n if (tenantId !== \"root\") {\n throw new
|
|
1
|
+
{"version":3,"file":"legacy/tenancy/createTenancyContext.js","sources":["../../../src/legacy/tenancy/createTenancyContext.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/api\";\nimport WebinyError from \"@webiny/error\";\nimport { Request } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { GetTenantByIdUseCase } from \"~/features/tenancy/GetTenantById/index.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { LegacyContext } from \"~/legacy/tenancy/LegacyContext.js\";\nimport { RootTenantValue } from \"~/domain/tenancy/RootTenantValue.js\";\n\nexport const createTenancyContext = () => {\n return new ContextPlugin<ApiCoreContext>(async context => {\n let tenantId = \"root\";\n\n const request = context.container.resolve(Request);\n\n const multiTenancy = context.wcp.canUseFeature(\"multiTenancy\");\n if (!request) {\n throw new Error(\"MISSING CONTEXT REQUEST\");\n }\n\n if (multiTenancy) {\n const { headers = {} } = request;\n\n tenantId = (headers[\"x-tenant\"] as string) ?? \"root\";\n }\n\n // Add WCP telemetry identifier\n // This tenancy package is used by GraphQL, Headless CMS, and PB import/export functions\n context.plugins.register({ type: \"wcp-telemetry-tracker\" });\n\n // We need to load tenant, and set the current tenant context.\n const getTenantById = context.container.resolve(GetTenantByIdUseCase);\n const tenantContext = context.container.resolve(TenantContext);\n\n const tenantResult = await getTenantById.execute(tenantId);\n if (tenantResult.isOk()) {\n tenantContext.setTenant(tenantResult.value);\n } else {\n // If there's no `root` tenant, it means system installation wasn't finished yet.\n // But all other tenants should throw an error.\n if (tenantId !== \"root\") {\n throw new WebinyError({\n message: \"Unable to load tenant!\",\n code: \"Tenancy/TenantNotFound\",\n data: { tenantId }\n });\n }\n\n // Mock root tenant so the system can bootstrap\n tenantContext.setTenant(RootTenantValue.create());\n }\n\n // Set up legacy context. We use this API in many places across our codebase, and this will provide\n // a working bridge until everything is migrated to use DI container.\n context.tenancy = new LegacyContext(context.container);\n });\n};\n"],"names":["createTenancyContext","ContextPlugin","context","tenantId","request","Request","multiTenancy","Error","headers","getTenantById","GetTenantByIdUseCase","tenantContext","TenantContext","tenantResult","WebinyError","RootTenantValue","LegacyContext"],"mappings":";;;;;;;AASO,MAAMA,uBAAuB,IACzB,IAAIC,cAA8B,OAAMC;QAC3C,IAAIC,WAAW;QAEf,MAAMC,UAAUF,QAAQ,SAAS,CAAC,OAAO,CAACG;QAE1C,MAAMC,eAAeJ,QAAQ,GAAG,CAAC,aAAa,CAAC;QAC/C,IAAI,CAACE,SACD,MAAM,IAAIG,MAAM;QAGpB,IAAID,cAAc;YACd,MAAM,EAAEE,UAAU,CAAC,CAAC,EAAE,GAAGJ;YAEzBD,WAAYK,OAAO,CAAC,WAAW,IAAe;QAClD;QAIAN,QAAQ,OAAO,CAAC,QAAQ,CAAC;YAAE,MAAM;QAAwB;QAGzD,MAAMO,gBAAgBP,QAAQ,SAAS,CAAC,OAAO,CAACQ;QAChD,MAAMC,gBAAgBT,QAAQ,SAAS,CAAC,OAAO,CAACU;QAEhD,MAAMC,eAAe,MAAMJ,cAAc,OAAO,CAACN;QACjD,IAAIU,aAAa,IAAI,IACjBF,cAAc,SAAS,CAACE,aAAa,KAAK;aACvC;YAGH,IAAIV,AAAa,WAAbA,UACA,MAAM,IAAIW,MAAY;gBAClB,SAAS;gBACT,MAAM;gBACN,MAAM;oBAAEX;gBAAS;YACrB;YAIJQ,cAAc,SAAS,CAACI,gBAAgB,MAAM;QAClD;QAIAb,QAAQ,OAAO,GAAG,IAAIc,cAAcd,QAAQ,SAAS;IACzD"}
|