@webiny/api-core 6.4.12-beta.5 → 6.4.12-beta.7
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/features/system/InstallSystem/InstallSystemUseCase.d.ts +1 -1
- package/features/tenancy/CreateTenant/CreateTenantRepository.js +1 -0
- package/features/tenancy/CreateTenant/CreateTenantRepository.js.map +1 -1
- package/features/tenancy/CreateTenant/CreateTenantUseCase.d.ts +5 -3
- package/features/tenancy/CreateTenant/CreateTenantUseCase.js +10 -3
- package/features/tenancy/CreateTenant/CreateTenantUseCase.js.map +1 -1
- package/features/tenancy/CreateTenant/abstractions.d.ts +2 -1
- package/features/tenancy/CreateTenant/abstractions.js.map +1 -1
- package/features/tenancy/CreateTenant/decorators/CreateTenantWithWcpIncrement.d.ts +1 -1
- package/features/tenancy/CreateTenant/errors.d.ts +6 -0
- package/features/tenancy/CreateTenant/errors.js +11 -1
- package/features/tenancy/CreateTenant/errors.js.map +1 -1
- package/features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.js +1 -0
- package/features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.js.map +1 -1
- package/features/users/CreateUser/CreateUserUseCase.js +1 -2
- package/features/users/CreateUser/CreateUserUseCase.js.map +1 -1
- package/legacy/security/LegacyContext.d.ts +1 -1
- package/legacy/security/LegacyContext.js.map +1 -1
- package/legacy/security/plugins/authenticateUsingCookie.d.ts +7 -0
- package/legacy/security/plugins/authenticateUsingCookie.js +7 -1
- package/legacy/security/plugins/authenticateUsingCookie.js.map +1 -1
- package/legacy/security/plugins/secureHeaders.js +5 -2
- package/legacy/security/plugins/secureHeaders.js.map +1 -1
- package/package.json +24 -24
|
@@ -18,7 +18,7 @@ declare class InstallSystemUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
|
18
18
|
private createTenantUseCase;
|
|
19
19
|
private deleteTenantUseCase;
|
|
20
20
|
constructor(identityContext: IdentityContext.Interface, tenantContext: TenantContext.Interface, eventPublisher: EventPublisher.Interface, installTenantUseCase: InstallTenantUseCase.Interface, getRootTenantUseCase: GetRootTenantUseCase.Interface, createTenantUseCase: CreateTenantUseCase.Interface, deleteTenantUseCase: DeleteTenantUseCase.Interface);
|
|
21
|
-
execute(installationInput: InstallSystemInput): Promise<Result<void, never> | Result<never, import("../../tenancy/CreateTenant/errors.js").CreateTenantError
|
|
21
|
+
execute(installationInput: InstallSystemInput): Promise<Result<void, never> | Result<never, SystemAlreadyInstalledError> | Result<never, import("../../tenancy/CreateTenant/errors.js").CreateTenantError | import("../../tenancy/CreateTenant/errors.js").TenantAlreadyExistsError> | Result<never, import("~/features/tenancy/InstallTenant/index.js").InstallTenantError | import("~/features/tenancy/InstallTenant/index.js").InstallationDependencyError>>;
|
|
22
22
|
}
|
|
23
23
|
export declare const InstallSystemUseCase: import("@webiny/di").Implementation<typeof InstallSystemUseCaseImpl>;
|
|
24
24
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/tenancy/CreateTenant/CreateTenantRepository.js","sources":["../../../../src/features/tenancy/CreateTenant/CreateTenantRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { CreateTenantRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { CreateTenantGateway } from \"./abstractions.js\";\nimport { TenantCache } from \"../shared/abstractions.js\";\nimport type { Tenant } from \"~/types/tenancy.js\";\n\nclass CreateTenantRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private gateway: CreateTenantGateway.Interface,\n private cache: TenantCache.Interface\n ) {}\n\n async create(tenant: Tenant) {\n const created = await this.gateway.createTenant(tenant);\n this.cache.prime(created.id, created);\n return created;\n }\n}\n\nexport const CreateTenantRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: CreateTenantRepositoryImpl,\n dependencies: [CreateTenantGateway, TenantCache]\n});\n"],"names":["CreateTenantRepositoryImpl","gateway","cache","tenant","created","CreateTenantRepository","createImplementation","RepositoryAbstraction","CreateTenantGateway","TenantCache"],"mappings":";;;AAMA,MAAMA;IACF,YACYC,OAAsC,EACtCC,KAA4B,CACtC;aAFUD,OAAO,GAAPA;aACAC,KAAK,GAALA;IACT;IAEH,MAAM,OAAOC,MAAc,EAAE;QACzB,MAAMC,UAAU,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAACD;
|
|
1
|
+
{"version":3,"file":"features/tenancy/CreateTenant/CreateTenantRepository.js","sources":["../../../../src/features/tenancy/CreateTenant/CreateTenantRepository.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { CreateTenantRepository as RepositoryAbstraction } from \"./abstractions.js\";\nimport { CreateTenantGateway } from \"./abstractions.js\";\nimport { TenantCache } from \"../shared/abstractions.js\";\nimport type { Tenant } from \"~/types/tenancy.js\";\n\nclass CreateTenantRepositoryImpl implements RepositoryAbstraction.Interface {\n constructor(\n private gateway: CreateTenantGateway.Interface,\n private cache: TenantCache.Interface\n ) {}\n\n async create(tenant: Tenant) {\n const created = await this.gateway.createTenant(tenant);\n // The id may already be cached as \"not found\" (the existence check), and prime() doesn't\n // overwrite a cached key.\n this.cache.clear(created.id);\n this.cache.prime(created.id, created);\n return created;\n }\n}\n\nexport const CreateTenantRepository = createImplementation({\n abstraction: RepositoryAbstraction,\n implementation: CreateTenantRepositoryImpl,\n dependencies: [CreateTenantGateway, TenantCache]\n});\n"],"names":["CreateTenantRepositoryImpl","gateway","cache","tenant","created","CreateTenantRepository","createImplementation","RepositoryAbstraction","CreateTenantGateway","TenantCache"],"mappings":";;;AAMA,MAAMA;IACF,YACYC,OAAsC,EACtCC,KAA4B,CACtC;aAFUD,OAAO,GAAPA;aACAC,KAAK,GAALA;IACT;IAEH,MAAM,OAAOC,MAAc,EAAE;QACzB,MAAMC,UAAU,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAACD;QAGhD,IAAI,CAAC,KAAK,CAAC,KAAK,CAACC,QAAQ,EAAE;QAC3B,IAAI,CAAC,KAAK,CAAC,KAAK,CAACA,QAAQ,EAAE,EAAEA;QAC7B,OAAOA;IACX;AACJ;AAEO,MAAMC,gDAAyBC,qBAAqB;IACvD,aAAaC;IACb,gBAAgBP;IAChB,cAAc;QAACQ;QAAqBC;KAAY;AACpD"}
|
|
@@ -3,12 +3,14 @@ import { EventPublisher } from "../../../features/eventPublisher/index.js";
|
|
|
3
3
|
import { CreateTenantUseCase as UseCaseAbstraction } from "./abstractions.js";
|
|
4
4
|
import { CreateTenantRepository } from "./abstractions.js";
|
|
5
5
|
import type { Tenant, CreateTenantInput } from "../../../types/tenancy.js";
|
|
6
|
-
import { CreateTenantError } from "../../../features/tenancy/CreateTenant/errors.js";
|
|
6
|
+
import { CreateTenantError, TenantAlreadyExistsError } from "../../../features/tenancy/CreateTenant/errors.js";
|
|
7
|
+
import { GetTenantByIdUseCase } from "../../../features/tenancy/GetTenantById/abstractions.js";
|
|
7
8
|
declare class CreateTenantUseCaseImpl implements UseCaseAbstraction.Interface {
|
|
8
9
|
private eventPublisher;
|
|
9
10
|
private repository;
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
private getTenantById;
|
|
12
|
+
constructor(eventPublisher: EventPublisher.Interface, repository: CreateTenantRepository.Interface, getTenantById: GetTenantByIdUseCase.Interface);
|
|
13
|
+
execute(data: CreateTenantInput): Promise<Result<Tenant, never> | Result<never, TenantAlreadyExistsError> | Result<never, CreateTenantError>>;
|
|
12
14
|
}
|
|
13
15
|
export declare const CreateTenantUseCase: import("@webiny/di").Implementation<typeof CreateTenantUseCaseImpl>;
|
|
14
16
|
export {};
|
|
@@ -3,13 +3,19 @@ import { EventPublisher } from "../../eventPublisher/index.js";
|
|
|
3
3
|
import { mdbid } from "@webiny/utils";
|
|
4
4
|
import { CreateTenantRepository, CreateTenantUseCase } from "./abstractions.js";
|
|
5
5
|
import { TenantAfterCreateEvent, TenantBeforeCreateEvent } from "./events.js";
|
|
6
|
-
import { CreateTenantError } from "./errors.js";
|
|
6
|
+
import { CreateTenantError, TenantAlreadyExistsError } from "./errors.js";
|
|
7
|
+
import { GetTenantByIdUseCase } from "../GetTenantById/abstractions.js";
|
|
7
8
|
class CreateTenantUseCaseImpl {
|
|
8
|
-
constructor(eventPublisher, repository){
|
|
9
|
+
constructor(eventPublisher, repository, getTenantById){
|
|
9
10
|
this.eventPublisher = eventPublisher;
|
|
10
11
|
this.repository = repository;
|
|
12
|
+
this.getTenantById = getTenantById;
|
|
11
13
|
}
|
|
12
14
|
async execute(data) {
|
|
15
|
+
if (data.id) {
|
|
16
|
+
const existing = await this.getTenantById.execute(data.id);
|
|
17
|
+
if (existing.isOk()) return Result.fail(new TenantAlreadyExistsError(data.id));
|
|
18
|
+
}
|
|
13
19
|
const tenant = {
|
|
14
20
|
...data,
|
|
15
21
|
id: data.id ?? mdbid(),
|
|
@@ -46,7 +52,8 @@ const CreateTenantUseCase_CreateTenantUseCase = createImplementation({
|
|
|
46
52
|
implementation: CreateTenantUseCaseImpl,
|
|
47
53
|
dependencies: [
|
|
48
54
|
EventPublisher,
|
|
49
|
-
CreateTenantRepository
|
|
55
|
+
CreateTenantRepository,
|
|
56
|
+
GetTenantByIdUseCase
|
|
50
57
|
]
|
|
51
58
|
});
|
|
52
59
|
export { CreateTenantUseCase_CreateTenantUseCase as CreateTenantUseCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/tenancy/CreateTenant/CreateTenantUseCase.js","sources":["../../../../src/features/tenancy/CreateTenant/CreateTenantUseCase.ts"],"sourcesContent":["import { Result, createImplementation } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { mdbid } from \"@webiny/utils\";\nimport { CreateTenantUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { CreateTenantRepository } from \"./abstractions.js\";\nimport { TenantBeforeCreateEvent, TenantAfterCreateEvent } from \"./events.js\";\nimport type { Tenant, CreateTenantInput } from \"~/types/tenancy.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"features/tenancy/CreateTenant/CreateTenantUseCase.js","sources":["../../../../src/features/tenancy/CreateTenant/CreateTenantUseCase.ts"],"sourcesContent":["import { Result, createImplementation } from \"@webiny/feature/api\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { mdbid } from \"@webiny/utils\";\nimport { CreateTenantUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { CreateTenantRepository } from \"./abstractions.js\";\nimport { TenantBeforeCreateEvent, TenantAfterCreateEvent } from \"./events.js\";\nimport type { Tenant, CreateTenantInput } from \"~/types/tenancy.js\";\nimport {\n CreateTenantError,\n TenantAlreadyExistsError\n} from \"~/features/tenancy/CreateTenant/errors.js\";\nimport { GetTenantByIdUseCase } from \"~/features/tenancy/GetTenantById/abstractions.js\";\n\nclass CreateTenantUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private eventPublisher: EventPublisher.Interface,\n private repository: CreateTenantRepository.Interface,\n private getTenantById: GetTenantByIdUseCase.Interface\n ) {}\n\n async execute(data: CreateTenantInput) {\n /* Never overwrite an existing tenant: its data is keyed by the tenant id. */\n if (data.id) {\n const existing = await this.getTenantById.execute(data.id);\n if (existing.isOk()) {\n return Result.fail(new TenantAlreadyExistsError(data.id));\n }\n }\n\n const tenant: Tenant = {\n ...data,\n id: data.id ?? mdbid(),\n status: \"disabled\",\n isInstalled: false,\n settings: {\n ...(data.settings || {})\n },\n savedOn: new Date().toISOString(),\n createdOn: new Date().toISOString(),\n parent: data.parent || null\n };\n\n await this.eventPublisher.publish(new TenantBeforeCreateEvent({ tenant, input: data }));\n\n let createdTenant: Tenant;\n try {\n createdTenant = await this.repository.create(tenant);\n } catch (e) {\n return Result.fail(new CreateTenantError({ reason: e.message }));\n }\n\n await this.eventPublisher.publish(\n new TenantAfterCreateEvent({ tenant: createdTenant, input: data })\n );\n\n return Result.ok(createdTenant);\n }\n}\n\nexport const CreateTenantUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateTenantUseCaseImpl,\n dependencies: [EventPublisher, CreateTenantRepository, GetTenantByIdUseCase]\n});\n"],"names":["CreateTenantUseCaseImpl","eventPublisher","repository","getTenantById","data","existing","Result","TenantAlreadyExistsError","tenant","mdbid","Date","TenantBeforeCreateEvent","createdTenant","e","CreateTenantError","TenantAfterCreateEvent","CreateTenantUseCase","createImplementation","UseCaseAbstraction","EventPublisher","CreateTenantRepository","GetTenantByIdUseCase"],"mappings":";;;;;;;AAaA,MAAMA;IACF,YACYC,cAAwC,EACxCC,UAA4C,EAC5CC,aAA6C,CACvD;aAHUF,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,IAAuB,EAAE;QAEnC,IAAIA,KAAK,EAAE,EAAE;YACT,MAAMC,WAAW,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACD,KAAK,EAAE;YACzD,IAAIC,SAAS,IAAI,IACb,OAAOC,OAAO,IAAI,CAAC,IAAIC,yBAAyBH,KAAK,EAAE;QAE/D;QAEA,MAAMI,SAAiB;YACnB,GAAGJ,IAAI;YACP,IAAIA,KAAK,EAAE,IAAIK;YACf,QAAQ;YACR,aAAa;YACb,UAAU;gBACN,GAAIL,KAAK,QAAQ,IAAI,CAAC,CAAC;YAC3B;YACA,SAAS,IAAIM,OAAO,WAAW;YAC/B,WAAW,IAAIA,OAAO,WAAW;YACjC,QAAQN,KAAK,MAAM,IAAI;QAC3B;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIO,wBAAwB;YAAEH;YAAQ,OAAOJ;QAAK;QAEpF,IAAIQ;QACJ,IAAI;YACAA,gBAAgB,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACJ;QACjD,EAAE,OAAOK,GAAG;YACR,OAAOP,OAAO,IAAI,CAAC,IAAIQ,kBAAkB;gBAAE,QAAQD,EAAE,OAAO;YAAC;QACjE;QAEA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIE,uBAAuB;YAAE,QAAQH;YAAe,OAAOR;QAAK;QAGpE,OAAOE,OAAO,EAAE,CAACM;IACrB;AACJ;AAEO,MAAMI,0CAAsBC,qBAAqB;IACpD,aAAaC;IACb,gBAAgBlB;IAChB,cAAc;QAACmB;QAAgBC;QAAwBC;KAAqB;AAChF"}
|
|
@@ -2,12 +2,13 @@ import { Result } from "@webiny/feature/api";
|
|
|
2
2
|
import type { IEventHandler, DomainEvent } from "../../../features/eventPublisher/index.js";
|
|
3
3
|
import type { Tenant, CreateTenantInput } from "../../../types/tenancy.js";
|
|
4
4
|
import type { TenantBeforeCreatePayload, TenantAfterCreatePayload } from "./events.js";
|
|
5
|
-
import { CreateTenantError } from "./errors.js";
|
|
5
|
+
import type { CreateTenantError, TenantAlreadyExistsError } from "./errors.js";
|
|
6
6
|
/**
|
|
7
7
|
* Errors
|
|
8
8
|
*/
|
|
9
9
|
export interface ICreateTenantErrors {
|
|
10
10
|
base: CreateTenantError;
|
|
11
|
+
alreadyExists: TenantAlreadyExistsError;
|
|
11
12
|
}
|
|
12
13
|
/**
|
|
13
14
|
* Use Case
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/tenancy/CreateTenant/abstractions.js","sources":["../../../../src/features/tenancy/CreateTenant/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { IEventHandler, DomainEvent } from \"~/features/eventPublisher/index.js\";\nimport type { Tenant, CreateTenantInput } from \"~/types/tenancy.js\";\nimport type { TenantBeforeCreatePayload, TenantAfterCreatePayload } from \"./events.js\";\nimport { CreateTenantError } from \"./errors.js\";\n\n/**\n * Errors\n */\nexport interface ICreateTenantErrors {\n base: CreateTenantError;\n}\n\n/**\n * Use Case\n */\nexport interface ICreateTenantUseCase {\n execute(\n data: CreateTenantInput\n ): Promise<Result<Tenant, ICreateTenantErrors[keyof ICreateTenantErrors]>>;\n}\n\n/** Create a new tenant. */\nexport const CreateTenantUseCase = createAbstraction<ICreateTenantUseCase>(\"CreateTenantUseCase\");\n\nexport namespace CreateTenantUseCase {\n export type Interface = ICreateTenantUseCase;\n export type Errors = ICreateTenantErrors[keyof ICreateTenantErrors];\n}\n\n/**\n * Repository\n */\nexport interface ICreateTenantRepository {\n create(tenant: Tenant): Promise<Tenant>;\n}\n\n/** Persist a newly created tenant. */\nexport const CreateTenantRepository =\n createAbstraction<ICreateTenantRepository>(\"CreateTenantRepository\");\n\nexport namespace CreateTenantRepository {\n export type Interface = ICreateTenantRepository;\n}\n\n/**\n * Gateway\n */\nexport interface ICreateTenantGateway {\n createTenant(data: Tenant): Promise<Tenant>;\n}\n\n/** Storage gateway for tenant creation. */\nexport const CreateTenantGateway = createAbstraction<ICreateTenantGateway>(\"CreateTenantGateway\");\n\nexport namespace CreateTenantGateway {\n export type Interface = ICreateTenantGateway;\n}\n\n/** Hook into tenant lifecycle before a tenant is created. */\nexport const TenantBeforeCreateEventHandler = createAbstraction<\n IEventHandler<DomainEvent<TenantBeforeCreatePayload>>\n>(\"TenantBeforeCreateEventHandler\");\n\nexport namespace TenantBeforeCreateEventHandler {\n export type Interface = IEventHandler<DomainEvent<TenantBeforeCreatePayload>>;\n export type Event = DomainEvent<TenantBeforeCreatePayload>;\n}\n\n/** Hook into tenant lifecycle after a tenant is created. */\nexport const TenantAfterCreateEventHandler = createAbstraction<\n IEventHandler<DomainEvent<TenantAfterCreatePayload>>\n>(\"TenantAfterCreateEventHandler\");\n\nexport namespace TenantAfterCreateEventHandler {\n export type Interface = IEventHandler<DomainEvent<TenantAfterCreatePayload>>;\n export type Event = DomainEvent<TenantAfterCreatePayload>;\n}\n"],"names":["CreateTenantUseCase","createAbstraction","CreateTenantRepository","CreateTenantGateway","TenantBeforeCreateEventHandler","TenantAfterCreateEventHandler"],"mappings":";
|
|
1
|
+
{"version":3,"file":"features/tenancy/CreateTenant/abstractions.js","sources":["../../../../src/features/tenancy/CreateTenant/abstractions.ts"],"sourcesContent":["import { createAbstraction, Result } from \"@webiny/feature/api\";\nimport type { IEventHandler, DomainEvent } from \"~/features/eventPublisher/index.js\";\nimport type { Tenant, CreateTenantInput } from \"~/types/tenancy.js\";\nimport type { TenantBeforeCreatePayload, TenantAfterCreatePayload } from \"./events.js\";\nimport type { CreateTenantError, TenantAlreadyExistsError } from \"./errors.js\";\n\n/**\n * Errors\n */\nexport interface ICreateTenantErrors {\n base: CreateTenantError;\n alreadyExists: TenantAlreadyExistsError;\n}\n\n/**\n * Use Case\n */\nexport interface ICreateTenantUseCase {\n execute(\n data: CreateTenantInput\n ): Promise<Result<Tenant, ICreateTenantErrors[keyof ICreateTenantErrors]>>;\n}\n\n/** Create a new tenant. */\nexport const CreateTenantUseCase = createAbstraction<ICreateTenantUseCase>(\"CreateTenantUseCase\");\n\nexport namespace CreateTenantUseCase {\n export type Interface = ICreateTenantUseCase;\n export type Errors = ICreateTenantErrors[keyof ICreateTenantErrors];\n}\n\n/**\n * Repository\n */\nexport interface ICreateTenantRepository {\n create(tenant: Tenant): Promise<Tenant>;\n}\n\n/** Persist a newly created tenant. */\nexport const CreateTenantRepository =\n createAbstraction<ICreateTenantRepository>(\"CreateTenantRepository\");\n\nexport namespace CreateTenantRepository {\n export type Interface = ICreateTenantRepository;\n}\n\n/**\n * Gateway\n */\nexport interface ICreateTenantGateway {\n createTenant(data: Tenant): Promise<Tenant>;\n}\n\n/** Storage gateway for tenant creation. */\nexport const CreateTenantGateway = createAbstraction<ICreateTenantGateway>(\"CreateTenantGateway\");\n\nexport namespace CreateTenantGateway {\n export type Interface = ICreateTenantGateway;\n}\n\n/** Hook into tenant lifecycle before a tenant is created. */\nexport const TenantBeforeCreateEventHandler = createAbstraction<\n IEventHandler<DomainEvent<TenantBeforeCreatePayload>>\n>(\"TenantBeforeCreateEventHandler\");\n\nexport namespace TenantBeforeCreateEventHandler {\n export type Interface = IEventHandler<DomainEvent<TenantBeforeCreatePayload>>;\n export type Event = DomainEvent<TenantBeforeCreatePayload>;\n}\n\n/** Hook into tenant lifecycle after a tenant is created. */\nexport const TenantAfterCreateEventHandler = createAbstraction<\n IEventHandler<DomainEvent<TenantAfterCreatePayload>>\n>(\"TenantAfterCreateEventHandler\");\n\nexport namespace TenantAfterCreateEventHandler {\n export type Interface = IEventHandler<DomainEvent<TenantAfterCreatePayload>>;\n export type Event = DomainEvent<TenantAfterCreatePayload>;\n}\n"],"names":["CreateTenantUseCase","createAbstraction","CreateTenantRepository","CreateTenantGateway","TenantBeforeCreateEventHandler","TenantAfterCreateEventHandler"],"mappings":";AAwBO,MAAMA,sBAAsBC,kBAAwC;AAepE,MAAMC,yBACTD,kBAA2C;AAcxC,MAAME,sBAAsBF,kBAAwC;AAOpE,MAAMG,iCAAiCH,kBAE5C;AAQK,MAAMI,gCAAgCJ,kBAE3C"}
|
|
@@ -5,7 +5,7 @@ declare class CreateTenantWithWcpIncrementImpl implements CreateTenantUseCase.In
|
|
|
5
5
|
private wcp;
|
|
6
6
|
private decoratee;
|
|
7
7
|
constructor(wcp: WcpContext.Interface, decoratee: CreateTenantUseCase.Interface);
|
|
8
|
-
execute(data: CreateTenantInput): Promise<import("@webiny/feature/api").Result<import("~/types/tenancy.js").Tenant, import("../errors.js").CreateTenantError>>;
|
|
8
|
+
execute(data: CreateTenantInput): Promise<import("@webiny/feature/api").Result<import("~/types/tenancy.js").Tenant, import("../errors.js").CreateTenantError | import("../errors.js").TenantAlreadyExistsError>>;
|
|
9
9
|
}
|
|
10
10
|
export declare const CreateTenantWithWcpIncrement: typeof CreateTenantWithWcpIncrementImpl;
|
|
11
11
|
export {};
|
|
@@ -3,3 +3,9 @@ export declare class CreateTenantError extends BaseError {
|
|
|
3
3
|
readonly code: "CREATE_TENANT";
|
|
4
4
|
constructor(data: any);
|
|
5
5
|
}
|
|
6
|
+
export declare class TenantAlreadyExistsError extends BaseError<{
|
|
7
|
+
id: string;
|
|
8
|
+
}> {
|
|
9
|
+
readonly code: "TENANT_ALREADY_EXISTS";
|
|
10
|
+
constructor(id: string);
|
|
11
|
+
}
|
|
@@ -7,6 +7,16 @@ class CreateTenantError extends BaseError {
|
|
|
7
7
|
}), this.code = "CREATE_TENANT";
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
class TenantAlreadyExistsError extends BaseError {
|
|
11
|
+
constructor(id){
|
|
12
|
+
super({
|
|
13
|
+
message: `Tenant "${id}" already exists.`,
|
|
14
|
+
data: {
|
|
15
|
+
id
|
|
16
|
+
}
|
|
17
|
+
}), this.code = "TENANT_ALREADY_EXISTS";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export { CreateTenantError, TenantAlreadyExistsError };
|
|
11
21
|
|
|
12
22
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/tenancy/CreateTenant/errors.js","sources":["../../../../src/features/tenancy/CreateTenant/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class CreateTenantError extends BaseError {\n override readonly code = \"CREATE_TENANT\" as const;\n\n constructor(data: any) {\n super({\n message: `Failed to create tenant`,\n data\n });\n }\n}\n"],"names":["CreateTenantError","BaseError","data"],"mappings":";AAEO,MAAMA,0BAA0BC;IAGnC,YAAYC,IAAS,CAAE;QACnB,KAAK,CAAC;YACF,SAAS;YACTA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ"}
|
|
1
|
+
{"version":3,"file":"features/tenancy/CreateTenant/errors.js","sources":["../../../../src/features/tenancy/CreateTenant/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class CreateTenantError extends BaseError {\n override readonly code = \"CREATE_TENANT\" as const;\n\n constructor(data: any) {\n super({\n message: `Failed to create tenant`,\n data\n });\n }\n}\n\nexport class TenantAlreadyExistsError extends BaseError<{ id: string }> {\n override readonly code = \"TENANT_ALREADY_EXISTS\" as const;\n\n constructor(id: string) {\n super({\n message: `Tenant \"${id}\" already exists.`,\n data: { id }\n });\n }\n}\n"],"names":["CreateTenantError","BaseError","data","TenantAlreadyExistsError","id"],"mappings":";AAEO,MAAMA,0BAA0BC;IAGnC,YAAYC,IAAS,CAAE;QACnB,KAAK,CAAC;YACF,SAAS;YACTA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,iCAAiCF;IAG1C,YAAYG,EAAU,CAAE;QACpB,KAAK,CAAC;YACF,SAAS,CAAC,QAAQ,EAAEA,GAAG,iBAAiB,CAAC;YACzC,MAAM;gBAAEA;YAAG;QACf,SANc,IAAI,GAAG;IAOzB;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.js","sources":["../../../../../src/features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.ts"],"sourcesContent":["import { createDecorator } from \"@webiny/feature/api\";\nimport { DeleteTenantUseCase } from \"../abstractions.js\";\nimport { WcpContext } from \"~/features/wcp/WcpContext/index.js\";\n\nclass DeleteTenantWithWcpDecrementImpl implements DeleteTenantUseCase.Interface {\n constructor(\n private wcp: WcpContext.Interface,\n private decoratee: DeleteTenantUseCase.Interface\n ) {}\n\n async execute(id: string): Promise<boolean> {\n const result = await this.decoratee.execute(id);\n await this.wcp.decrementTenants();\n return result;\n }\n}\n\nexport const DeleteTenantWithWcpDecrement = createDecorator({\n abstraction: DeleteTenantUseCase,\n decorator: DeleteTenantWithWcpDecrementImpl,\n dependencies: [WcpContext]\n});\n"],"names":["DeleteTenantWithWcpDecrementImpl","wcp","decoratee","id","result","DeleteTenantWithWcpDecrement","createDecorator","DeleteTenantUseCase","WcpContext"],"mappings":";;;AAIA,MAAMA;IACF,YACYC,GAAyB,EACzBC,SAAwC,CAClD;aAFUD,GAAG,GAAHA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QAAQC,EAAU,EAAoB;QACxC,MAAMC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACD;QAC5C,MAAM,IAAI,CAAC,GAAG,CAAC,gBAAgB;QAC/B,
|
|
1
|
+
{"version":3,"file":"features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.js","sources":["../../../../../src/features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.ts"],"sourcesContent":["import { createDecorator } from \"@webiny/feature/api\";\nimport { DeleteTenantUseCase } from \"../abstractions.js\";\nimport { WcpContext } from \"~/features/wcp/WcpContext/index.js\";\n\nclass DeleteTenantWithWcpDecrementImpl implements DeleteTenantUseCase.Interface {\n constructor(\n private wcp: WcpContext.Interface,\n private decoratee: DeleteTenantUseCase.Interface\n ) {}\n\n async execute(id: string): Promise<boolean> {\n const result = await this.decoratee.execute(id);\n if (!result) {\n return result;\n }\n await this.wcp.decrementTenants();\n return result;\n }\n}\n\nexport const DeleteTenantWithWcpDecrement = createDecorator({\n abstraction: DeleteTenantUseCase,\n decorator: DeleteTenantWithWcpDecrementImpl,\n dependencies: [WcpContext]\n});\n"],"names":["DeleteTenantWithWcpDecrementImpl","wcp","decoratee","id","result","DeleteTenantWithWcpDecrement","createDecorator","DeleteTenantUseCase","WcpContext"],"mappings":";;;AAIA,MAAMA;IACF,YACYC,GAAyB,EACzBC,SAAwC,CAClD;aAFUD,GAAG,GAAHA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QAAQC,EAAU,EAAoB;QACxC,MAAMC,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACD;QAC5C,IAAI,CAACC,QACD,OAAOA;QAEX,MAAM,IAAI,CAAC,GAAG,CAAC,gBAAgB;QAC/B,OAAOA;IACX;AACJ;AAEO,MAAMC,+BAA+BC,gBAAgB;IACxD,aAAaC;IACb,WAAWP;IACX,cAAc;QAACQ;KAAW;AAC9B"}
|
|
@@ -30,8 +30,7 @@ class CreateUserUseCaseImpl {
|
|
|
30
30
|
const displayName = this.getDisplayName(data);
|
|
31
31
|
const tenant = this.tenantContext.getTenant().id;
|
|
32
32
|
const identity = this.identityContext.getIdentity();
|
|
33
|
-
|
|
34
|
-
if (identity) createdBy = {
|
|
33
|
+
const createdBy = {
|
|
35
34
|
id: identity.id,
|
|
36
35
|
displayName: identity.displayName,
|
|
37
36
|
type: identity.type
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/users/CreateUser/CreateUserUseCase.js","sources":["../../../../src/features/users/CreateUser/CreateUserUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\nimport { createUserValidation } from \"./schema.js\";\nimport {\n NotAuthorizedError,\n EmailTakenError,\n UserValidationError\n} from \"~/features/users/shared/errors.js\";\nimport { UserBeforeCreateEvent, UserAfterCreateEvent } from \"./events.js\";\nimport type { AdminUser } from \"~/features/users/shared/types.js\";\nimport type { CreateUserInput } from \"~/features/users/shared/types.js\";\nimport type { CreatedBy } from \"~/types/users.js\";\n\nclass CreateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(input: CreateUserInput): Promise<Result<AdminUser, UseCaseAbstraction.Error>> {\n // 1. Check permission\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // 2. Validate input\n const validation = createUserValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new UserValidationError(validation.error.issues[0].message));\n }\n\n const data = validation.data;\n\n // 3. Check email uniqueness\n const existingUserResult = await this.repository.get({ email: data.email });\n if (existingUserResult.isOk()) {\n // This means the email is taken!\n return Result.fail(new EmailTakenError(data.email));\n }\n\n if (existingUserResult.error.code !== \"AdminUser/NotFound\") {\n return Result.fail(existingUserResult.error);\n }\n\n // 4. Generate ID if not provided\n const id = data.id || mdbid();\n\n // 5. Generate display name\n const displayName = this.getDisplayName(data);\n\n // 6. Get tenant and identity\n const tenant = this.tenantContext.getTenant().id;\n const identity = this.identityContext.getIdentity();\n\n
|
|
1
|
+
{"version":3,"file":"features/users/CreateUser/CreateUserUseCase.js","sources":["../../../../src/features/users/CreateUser/CreateUserUseCase.ts"],"sourcesContent":["import { mdbid } from \"@webiny/utils\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { CreateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\nimport { createUserValidation } from \"./schema.js\";\nimport {\n NotAuthorizedError,\n EmailTakenError,\n UserValidationError\n} from \"~/features/users/shared/errors.js\";\nimport { UserBeforeCreateEvent, UserAfterCreateEvent } from \"./events.js\";\nimport type { AdminUser } from \"~/features/users/shared/types.js\";\nimport type { CreateUserInput } from \"~/features/users/shared/types.js\";\nimport type { CreatedBy } from \"~/types/users.js\";\n\nclass CreateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(input: CreateUserInput): Promise<Result<AdminUser, UseCaseAbstraction.Error>> {\n // 1. Check permission\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // 2. Validate input\n const validation = createUserValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new UserValidationError(validation.error.issues[0].message));\n }\n\n const data = validation.data;\n\n // 3. Check email uniqueness\n const existingUserResult = await this.repository.get({ email: data.email });\n if (existingUserResult.isOk()) {\n // This means the email is taken!\n return Result.fail(new EmailTakenError(data.email));\n }\n\n if (existingUserResult.error.code !== \"AdminUser/NotFound\") {\n return Result.fail(existingUserResult.error);\n }\n\n // 4. Generate ID if not provided\n const id = data.id || mdbid();\n\n // 5. Generate display name\n const displayName = this.getDisplayName(data);\n\n // 6. Get tenant and identity\n const tenant = this.tenantContext.getTenant().id;\n const identity = this.identityContext.getIdentity();\n\n const createdBy: CreatedBy = {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n };\n\n // 7. Create user entity\n const user: AdminUser = {\n ...data,\n id,\n email: data.email,\n displayName,\n createdOn: new Date().toISOString(),\n createdBy,\n tenant\n };\n\n // 8. Publish before event\n await this.eventPublisher.publish(new UserBeforeCreateEvent({ user, input: data }));\n\n // 10. Create user via repository\n const result = await this.repository.create(user);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // 11. Publish after event\n await this.eventPublisher.publish(\n new UserAfterCreateEvent({ user: result.value, input: data })\n );\n\n return Result.ok(result.value);\n }\n\n private getDisplayName(data: CreateUserInput): string {\n // If display name is not set, try to get it from the first name and last name.\n // If first name and last name are not set, use the e-mail address.\n if (data.displayName) {\n return data.displayName;\n }\n\n if (data.firstName || data.lastName) {\n return `${data.firstName || \"\"} ${data.lastName || \"\"}`.trim();\n }\n\n if (data.email) {\n return data.email;\n }\n\n return \"Missing display name\";\n }\n}\n\nexport const CreateUserUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: CreateUserUseCaseImpl,\n dependencies: [TenantContext, IdentityContext, EventPublisher, AdminUsersRepository]\n});\n"],"names":["CreateUserUseCaseImpl","tenantContext","identityContext","eventPublisher","repository","input","permission","Result","NotAuthorizedError","validation","createUserValidation","UserValidationError","data","existingUserResult","EmailTakenError","id","mdbid","displayName","tenant","identity","createdBy","user","Date","UserBeforeCreateEvent","result","UserAfterCreateEvent","CreateUserUseCase","createImplementation","UseCaseAbstraction","TenantContext","IdentityContext","EventPublisher","AdminUsersRepository"],"mappings":";;;;;;;;;;AAmBA,MAAMA;IACF,YACYC,aAAsC,EACtCC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA0C,CACpD;aAJUH,aAAa,GAAbA;aACAC,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;IACT;IAEH,MAAM,QAAQC,KAAsB,EAAwD;QAExF,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,aAAaC,qBAAqB,SAAS,CAACL;QAClD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAGjF,MAAMG,OAAOH,WAAW,IAAI;QAG5B,MAAMI,qBAAqB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAOD,KAAK,KAAK;QAAC;QACzE,IAAIC,mBAAmB,IAAI,IAEvB,OAAON,OAAO,IAAI,CAAC,IAAIO,gBAAgBF,KAAK,KAAK;QAGrD,IAAIC,AAAkC,yBAAlCA,mBAAmB,KAAK,CAAC,IAAI,EAC7B,OAAON,OAAO,IAAI,CAACM,mBAAmB,KAAK;QAI/C,MAAME,KAAKH,KAAK,EAAE,IAAII;QAGtB,MAAMC,cAAc,IAAI,CAAC,cAAc,CAACL;QAGxC,MAAMM,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS,GAAG,EAAE;QAChD,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAEjD,MAAMC,YAAuB;YACzB,IAAID,SAAS,EAAE;YACf,aAAaA,SAAS,WAAW;YACjC,MAAMA,SAAS,IAAI;QACvB;QAGA,MAAME,OAAkB;YACpB,GAAGT,IAAI;YACPG;YACA,OAAOH,KAAK,KAAK;YACjBK;YACA,WAAW,IAAIK,OAAO,WAAW;YACjCF;YACAF;QACJ;QAGA,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAIK,sBAAsB;YAAEF;YAAM,OAAOT;QAAK;QAGhF,MAAMY,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAACH;QAC5C,IAAIG,OAAO,MAAM,IACb,OAAOjB,OAAO,IAAI,CAACiB,OAAO,KAAK;QAInC,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAC7B,IAAIC,qBAAqB;YAAE,MAAMD,OAAO,KAAK;YAAE,OAAOZ;QAAK;QAG/D,OAAOL,OAAO,EAAE,CAACiB,OAAO,KAAK;IACjC;IAEQ,eAAeZ,IAAqB,EAAU;QAGlD,IAAIA,KAAK,WAAW,EAChB,OAAOA,KAAK,WAAW;QAG3B,IAAIA,KAAK,SAAS,IAAIA,KAAK,QAAQ,EAC/B,OAAO,GAAGA,KAAK,SAAS,IAAI,GAAG,CAAC,EAAEA,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI;QAGhE,IAAIA,KAAK,KAAK,EACV,OAAOA,KAAK,KAAK;QAGrB,OAAO;IACX;AACJ;AAEO,MAAMc,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgB5B;IAChB,cAAc;QAAC6B;QAAeC;QAAiBC;QAAgBC;KAAqB;AACxF"}
|
|
@@ -13,7 +13,7 @@ export declare class LegacyContext {
|
|
|
13
13
|
addAuthenticator(authenticator: Authenticator.Interface["authenticate"]): void;
|
|
14
14
|
authenticate(token: string): Promise<void>;
|
|
15
15
|
getIdentity(): SecurityIdentity;
|
|
16
|
-
setIdentity(identity: SecurityIdentity): void;
|
|
16
|
+
setIdentity(identity: SecurityIdentity | undefined | null): void;
|
|
17
17
|
getToken(): string | undefined;
|
|
18
18
|
isAuthorizationEnabled(): boolean;
|
|
19
19
|
withoutAuthorization<T = any>(cb: () => Promise<T>): Promise<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy/security/LegacyContext.js","sources":["../../../src/legacy/security/LegacyContext.ts"],"sourcesContent":["import { type Container } from \"@webiny/di\";\nimport type { SecurityIdentity, SecurityPermission } from \"~/types/security.js\";\nimport { AuthenticationContext } from \"~/features/security/authentication/AuthenticationContext/index.js\";\nimport { Authenticator } from \"~/features/security/authentication/Authenticator/index.js\";\nimport { Authorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport {\n AuthenticatedIdentity,\n IdentityContext,\n IdentityData\n} from \"~/features/security/IdentityContext/index.js\";\nimport { GetRoleUseCase } from \"~/features/security/roles/GetRole/index.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { CreateRoleUseCase } from \"~/features/security/roles/CreateRole/index.js\";\nimport { UpdateRoleUseCase } from \"~/features/security/roles/UpdateRole/index.js\";\nimport { DeleteRoleUseCase } from \"~/features/security/roles/DeleteRole/index.js\";\nimport { GetTeamUseCase } from \"~/features/security/teams/GetTeam/index.js\";\nimport { ListTeamsUseCase } from \"~/features/security/teams/ListTeams/index.js\";\nimport { CreateTeam } from \"~/features/security/teams/CreateTeam/index.js\";\nimport { UpdateTeam } from \"~/features/security/teams/UpdateTeam/index.js\";\nimport { DeleteTeam } from \"~/features/security/teams/DeleteTeam/index.js\";\n\n/**\n * Legacy bridge that implements the old Security interface.\n * As we implement each phase, we'll replace forwarding with delegation.\n */\nexport class LegacyContext {\n constructor(private container: Container) {}\n\n private get identityContext() {\n return this.container.resolve(IdentityContext);\n }\n\n private get authenticationContext() {\n return this.container.resolve(AuthenticationContext);\n }\n\n addAuthenticator(authenticator: Authenticator.Interface[\"authenticate\"]): void {\n this.container.registerFactory(Authenticator, () => {\n return {\n authenticate(token: string): Promise<IdentityData | null> {\n return authenticator(token);\n }\n };\n });\n }\n\n async authenticate(token: string): Promise<void> {\n // Authenticate using new context\n const identity = await this.authenticationContext.authenticate(token);\n\n // Set identity in IdentityContext\n this.identityContext.setIdentity(identity);\n }\n\n getIdentity(): SecurityIdentity {\n const identity = this.identityContext.getIdentity();\n\n // Convert our Identity class to old SecurityIdentity format\n if (identity.isAnonymous()) {\n return undefined as any;\n }\n\n return identity;\n }\n\n setIdentity(identity: SecurityIdentity): void {\n if (!identity) {\n this.identityContext.setIdentity(undefined);\n return;\n }\n\n // Wrap old identity format in AuthenticatedIdentity\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n this.identityContext.setIdentity(authenticatedIdentity);\n }\n\n getToken() {\n return this.authenticationContext.getAuthToken();\n }\n\n isAuthorizationEnabled(): boolean {\n return this.identityContext.isAuthorizationEnabled();\n }\n\n withoutAuthorization<T = any>(cb: () => Promise<T>): Promise<T> {\n return this.identityContext.withoutAuthorization(cb);\n }\n\n withIdentity<T = any>(\n identity: SecurityIdentity | undefined,\n cb: () => Promise<T>\n ): Promise<T> {\n if (!identity) {\n return this.identityContext.withIdentity(undefined, cb);\n }\n\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n return this.identityContext.withIdentity(authenticatedIdentity, cb);\n }\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermission<TPermission>(permission);\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermissions<TPermission>(permission);\n }\n\n async listPermissions() {\n return this.identityContext.listPermissions();\n }\n\n async hasFullAccess(): Promise<boolean> {\n return this.identityContext.hasFullAccess();\n }\n\n async getRole(params: any) {\n const useCase = this.container.resolve(GetRoleUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listRoles(params?: any) {\n const useCase = this.container.resolve(ListRolesUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createRole(input: any) {\n const useCase = this.container.resolve(CreateRoleUseCase);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateRole(id: string, input: any) {\n const useCase = this.container.resolve(UpdateRoleUseCase);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteRole(id: string) {\n const useCase = this.container.resolve(DeleteRoleUseCase);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n\n addAuthorizer(authorizer: any) {\n // @ts-expect-error\n this.container.registerFactory(Authorizer, () => {\n return {\n authorize(): Promise<Permissions[]> {\n return authorizer();\n }\n };\n });\n }\n\n async getTeam(params: any) {\n const useCase = this.container.resolve(GetTeamUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listTeams(params?: any) {\n const useCase = this.container.resolve(ListTeamsUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createTeam(input: any) {\n const useCase = this.container.resolve(CreateTeam);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateTeam(id: string, input: any) {\n const useCase = this.container.resolve(UpdateTeam);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteTeam(id: string) {\n const useCase = this.container.resolve(DeleteTeam);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n}\n"],"names":["LegacyContext","container","IdentityContext","AuthenticationContext","authenticator","Authenticator","token","identity","undefined","id","displayName","type","rest","authenticatedIdentity","AuthenticatedIdentity","cb","permission","params","useCase","GetRoleUseCase","result","ListRolesUseCase","input","CreateRoleUseCase","UpdateRoleUseCase","DeleteRoleUseCase","authorizer","Authorizer","GetTeamUseCase","ListTeamsUseCase","CreateTeam","UpdateTeam","DeleteTeam"],"mappings":";;;;;;;;;;;;;;AAyBO,MAAMA;IACT,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAE3C,IAAY,kBAAkB;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;IAClC;IAEA,IAAY,wBAAwB;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;IAClC;IAEA,iBAAiBC,aAAsD,EAAQ;QAC3E,IAAI,CAAC,SAAS,CAAC,eAAe,CAACC,eAAe,IACnC;gBACH,cAAaC,KAAa;oBACtB,OAAOF,cAAcE;gBACzB;YACJ;IAER;IAEA,MAAM,aAAaA,KAAa,EAAiB;QAE7C,MAAMC,WAAW,MAAM,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAACD;QAG/D,IAAI,CAAC,eAAe,CAAC,WAAW,CAACC;IACrC;IAEA,cAAgC;QAC5B,MAAMA,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAGjD,IAAIA,SAAS,WAAW,IACpB;QAGJ,OAAOA;IACX;IAEA,YAAYA,QAA0B,EAAQ;QAC1C,IAAI,CAACA,UAAU,YACX,IAAI,CAAC,eAAe,CAAC,WAAW,CAACC;QAKrC,MAAM,EAAEC,EAAE,EAAEC,WAAW,EAAEC,IAAI,EAAE,GAAGC,MAAM,GAAGL;QAC3C,MAAMM,wBAAwB,IAAIC,sBAAsB;YACpDL;YACAC;YACAC;YACA,GAAGC,IAAI;QACX;QAEA,IAAI,CAAC,eAAe,CAAC,WAAW,CAACC;IACrC;IAEA,WAAW;QACP,OAAO,IAAI,CAAC,qBAAqB,CAAC,YAAY;IAClD;IAEA,yBAAkC;QAC9B,OAAO,IAAI,CAAC,eAAe,CAAC,sBAAsB;IACtD;IAEA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C,MAAMV,SAAS,MAAMF,QAAQ,OAAO,CAACI;QAErC,IAAIF,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWX,EAAU,EAAEa,KAAU,EAAE;QACrC,MAAMJ,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACa;QACvC,MAAMX,SAAS,MAAMF,QAAQ,OAAO,CAACT,IAAIa;QAEzC,IAAIF,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWX,EAAU,EAAE;QACzB,MAAMS,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACc;QACvC,MAAMZ,SAAS,MAAMF,QAAQ,OAAO,CAACT;QAErC,IAAIW,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;IAE1B;AACJ"}
|
|
1
|
+
{"version":3,"file":"legacy/security/LegacyContext.js","sources":["../../../src/legacy/security/LegacyContext.ts"],"sourcesContent":["import { type Container } from \"@webiny/di\";\nimport type { SecurityIdentity, SecurityPermission } from \"~/types/security.js\";\nimport { AuthenticationContext } from \"~/features/security/authentication/AuthenticationContext/index.js\";\nimport { Authenticator } from \"~/features/security/authentication/Authenticator/index.js\";\nimport { Authorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport {\n AuthenticatedIdentity,\n IdentityContext,\n IdentityData\n} from \"~/features/security/IdentityContext/index.js\";\nimport { GetRoleUseCase } from \"~/features/security/roles/GetRole/index.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { CreateRoleUseCase } from \"~/features/security/roles/CreateRole/index.js\";\nimport { UpdateRoleUseCase } from \"~/features/security/roles/UpdateRole/index.js\";\nimport { DeleteRoleUseCase } from \"~/features/security/roles/DeleteRole/index.js\";\nimport { GetTeamUseCase } from \"~/features/security/teams/GetTeam/index.js\";\nimport { ListTeamsUseCase } from \"~/features/security/teams/ListTeams/index.js\";\nimport { CreateTeam } from \"~/features/security/teams/CreateTeam/index.js\";\nimport { UpdateTeam } from \"~/features/security/teams/UpdateTeam/index.js\";\nimport { DeleteTeam } from \"~/features/security/teams/DeleteTeam/index.js\";\n\n/**\n * Legacy bridge that implements the old Security interface.\n * As we implement each phase, we'll replace forwarding with delegation.\n */\nexport class LegacyContext {\n constructor(private container: Container) {}\n\n private get identityContext() {\n return this.container.resolve(IdentityContext);\n }\n\n private get authenticationContext() {\n return this.container.resolve(AuthenticationContext);\n }\n\n addAuthenticator(authenticator: Authenticator.Interface[\"authenticate\"]): void {\n this.container.registerFactory(Authenticator, () => {\n return {\n authenticate(token: string): Promise<IdentityData | null> {\n return authenticator(token);\n }\n };\n });\n }\n\n async authenticate(token: string): Promise<void> {\n // Authenticate using new context\n const identity = await this.authenticationContext.authenticate(token);\n\n // Set identity in IdentityContext\n this.identityContext.setIdentity(identity);\n }\n\n getIdentity(): SecurityIdentity {\n const identity = this.identityContext.getIdentity();\n\n // Convert our Identity class to old SecurityIdentity format\n if (identity.isAnonymous()) {\n return undefined as any;\n }\n\n return identity;\n }\n\n setIdentity(identity: SecurityIdentity | undefined | null): void {\n if (!identity) {\n this.identityContext.setIdentity(undefined);\n return;\n }\n\n // Wrap old identity format in AuthenticatedIdentity\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n this.identityContext.setIdentity(authenticatedIdentity);\n }\n\n getToken() {\n return this.authenticationContext.getAuthToken();\n }\n\n isAuthorizationEnabled(): boolean {\n return this.identityContext.isAuthorizationEnabled();\n }\n\n withoutAuthorization<T = any>(cb: () => Promise<T>): Promise<T> {\n return this.identityContext.withoutAuthorization(cb);\n }\n\n withIdentity<T = any>(\n identity: SecurityIdentity | undefined,\n cb: () => Promise<T>\n ): Promise<T> {\n if (!identity) {\n return this.identityContext.withIdentity(undefined, cb);\n }\n\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n return this.identityContext.withIdentity(authenticatedIdentity, cb);\n }\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermission<TPermission>(permission);\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermissions<TPermission>(permission);\n }\n\n async listPermissions() {\n return this.identityContext.listPermissions();\n }\n\n async hasFullAccess(): Promise<boolean> {\n return this.identityContext.hasFullAccess();\n }\n\n async getRole(params: any) {\n const useCase = this.container.resolve(GetRoleUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listRoles(params?: any) {\n const useCase = this.container.resolve(ListRolesUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createRole(input: any) {\n const useCase = this.container.resolve(CreateRoleUseCase);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateRole(id: string, input: any) {\n const useCase = this.container.resolve(UpdateRoleUseCase);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteRole(id: string) {\n const useCase = this.container.resolve(DeleteRoleUseCase);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n\n addAuthorizer(authorizer: any) {\n // @ts-expect-error\n this.container.registerFactory(Authorizer, () => {\n return {\n authorize(): Promise<Permissions[]> {\n return authorizer();\n }\n };\n });\n }\n\n async getTeam(params: any) {\n const useCase = this.container.resolve(GetTeamUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listTeams(params?: any) {\n const useCase = this.container.resolve(ListTeamsUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createTeam(input: any) {\n const useCase = this.container.resolve(CreateTeam);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateTeam(id: string, input: any) {\n const useCase = this.container.resolve(UpdateTeam);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteTeam(id: string) {\n const useCase = this.container.resolve(DeleteTeam);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n}\n"],"names":["LegacyContext","container","IdentityContext","AuthenticationContext","authenticator","Authenticator","token","identity","undefined","id","displayName","type","rest","authenticatedIdentity","AuthenticatedIdentity","cb","permission","params","useCase","GetRoleUseCase","result","ListRolesUseCase","input","CreateRoleUseCase","UpdateRoleUseCase","DeleteRoleUseCase","authorizer","Authorizer","GetTeamUseCase","ListTeamsUseCase","CreateTeam","UpdateTeam","DeleteTeam"],"mappings":";;;;;;;;;;;;;;AAyBO,MAAMA;IACT,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAE3C,IAAY,kBAAkB;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;IAClC;IAEA,IAAY,wBAAwB;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;IAClC;IAEA,iBAAiBC,aAAsD,EAAQ;QAC3E,IAAI,CAAC,SAAS,CAAC,eAAe,CAACC,eAAe,IACnC;gBACH,cAAaC,KAAa;oBACtB,OAAOF,cAAcE;gBACzB;YACJ;IAER;IAEA,MAAM,aAAaA,KAAa,EAAiB;QAE7C,MAAMC,WAAW,MAAM,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAACD;QAG/D,IAAI,CAAC,eAAe,CAAC,WAAW,CAACC;IACrC;IAEA,cAAgC;QAC5B,MAAMA,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAGjD,IAAIA,SAAS,WAAW,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OAAO,CAACU;QACvC,MAAMR,SAAS,MAAMF,QAAQ,OAAO,CAACD,OAAO,KAAK;QAEjD,IAAIG,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,UAAUH,MAAY,EAAE;QAC1B,MAAMC,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACW;QACvC,MAAMT,SAAS,MAAMF,QAAQ,OAAO,CAACD;QAErC,IAAIG,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWE,KAAU,EAAE;QACzB,MAAMJ,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACY;QACvC,MAAMV,SAAS,MAAMF,QAAQ,OAAO,CAACI;QAErC,IAAIF,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWX,EAAU,EAAEa,KAAU,EAAE;QACrC,MAAMJ,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACa;QACvC,MAAMX,SAAS,MAAMF,QAAQ,OAAO,CAACT,IAAIa;QAEzC,IAAIF,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWX,EAAU,EAAE;QACzB,MAAMS,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACc;QACvC,MAAMZ,SAAS,MAAMF,QAAQ,OAAO,CAACT;QAErC,IAAIW,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;IAE1B;AACJ"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { Request } from "@webiny/handler";
|
|
1
2
|
import type { ApiCoreContext } from "../../../types/core.js";
|
|
3
|
+
/**
|
|
4
|
+
* The `wby-id-token` cookie exists only for private file delivery: an `<img src>` cannot send an
|
|
5
|
+
* `Authorization` header. It must not log users in anywhere else, because the browser attaches it
|
|
6
|
+
* to cross-site requests too (`SameSite=None`), which would let any website call the API as the user.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isCookieAuthenticationAllowed: (request: Pick<Request.Interface, "method" | "url">) => boolean;
|
|
2
9
|
/**
|
|
3
10
|
* @internal
|
|
4
11
|
*/
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { createContextPlugin } from "@webiny/api";
|
|
2
2
|
import { Request, createBeforeHandlerPlugin } from "@webiny/handler";
|
|
3
3
|
import { SetIdTokenCookie } from "../../../features/security/authentication/AuthenticationContext/SetIdTokenCookie.js";
|
|
4
|
+
const isCookieAuthenticationAllowed = (request)=>{
|
|
5
|
+
const method = request.method.toUpperCase();
|
|
6
|
+
if ("GET" !== method && "HEAD" !== method) return false;
|
|
7
|
+
return request.url.startsWith("/private/");
|
|
8
|
+
};
|
|
4
9
|
function authenticateUsingCookie() {
|
|
5
10
|
return [
|
|
6
11
|
createBeforeHandlerPlugin(async (context)=>{
|
|
7
12
|
const request = context.container.resolve(Request);
|
|
13
|
+
if (!isCookieAuthenticationAllowed(request)) return;
|
|
8
14
|
const { cookies } = request;
|
|
9
15
|
const token = cookies["wby-id-token"];
|
|
10
16
|
if (!context.security.getIdentity() && token) try {
|
|
@@ -18,6 +24,6 @@ function authenticateUsingCookie() {
|
|
|
18
24
|
})
|
|
19
25
|
];
|
|
20
26
|
}
|
|
21
|
-
export { authenticateUsingCookie };
|
|
27
|
+
export { authenticateUsingCookie, isCookieAuthenticationAllowed };
|
|
22
28
|
|
|
23
29
|
//# sourceMappingURL=authenticateUsingCookie.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy/security/plugins/authenticateUsingCookie.js","sources":["../../../../src/legacy/security/plugins/authenticateUsingCookie.ts"],"sourcesContent":["import { createContextPlugin } from \"@webiny/api\";\nimport { createBeforeHandlerPlugin, Request } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { SetIdTokenCookie } from \"~/features/security/authentication/AuthenticationContext/SetIdTokenCookie.js\";\n\n/**\n * @internal\n */\nexport function authenticateUsingCookie() {\n return [\n createBeforeHandlerPlugin<ApiCoreContext>(async context => {\n const request = context.container.resolve(Request);\n const { cookies } = request;\n const token = cookies[\"wby-id-token\"];\n\n if (!context.security.getIdentity() && token) {\n try {\n await context.security.authenticate(token);\n } catch (err) {\n console.log(err);\n }\n }\n }),\n\n createContextPlugin<ApiCoreContext>(context => {\n context.container.register(SetIdTokenCookie);\n })\n ];\n}\n"],"names":["authenticateUsingCookie","createBeforeHandlerPlugin","context","
|
|
1
|
+
{"version":3,"file":"legacy/security/plugins/authenticateUsingCookie.js","sources":["../../../../src/legacy/security/plugins/authenticateUsingCookie.ts"],"sourcesContent":["import { createContextPlugin } from \"@webiny/api\";\nimport { createBeforeHandlerPlugin, Request } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { SetIdTokenCookie } from \"~/features/security/authentication/AuthenticationContext/SetIdTokenCookie.js\";\n\n/**\n * The `wby-id-token` cookie exists only for private file delivery: an `<img src>` cannot send an\n * `Authorization` header. It must not log users in anywhere else, because the browser attaches it\n * to cross-site requests too (`SameSite=None`), which would let any website call the API as the user.\n */\nexport const isCookieAuthenticationAllowed = (\n request: Pick<Request.Interface, \"method\" | \"url\">\n) => {\n const method = request.method.toUpperCase();\n if (method !== \"GET\" && method !== \"HEAD\") {\n return false;\n }\n return request.url.startsWith(\"/private/\");\n};\n\n/**\n * @internal\n */\nexport function authenticateUsingCookie() {\n return [\n createBeforeHandlerPlugin<ApiCoreContext>(async context => {\n const request = context.container.resolve(Request);\n if (!isCookieAuthenticationAllowed(request)) {\n return;\n }\n const { cookies } = request;\n const token = cookies[\"wby-id-token\"];\n\n if (!context.security.getIdentity() && token) {\n try {\n await context.security.authenticate(token);\n } catch (err) {\n console.log(err);\n }\n }\n }),\n\n createContextPlugin<ApiCoreContext>(context => {\n context.container.register(SetIdTokenCookie);\n })\n ];\n}\n"],"names":["isCookieAuthenticationAllowed","request","method","authenticateUsingCookie","createBeforeHandlerPlugin","context","Request","cookies","token","err","console","createContextPlugin","SetIdTokenCookie"],"mappings":";;;AAUO,MAAMA,gCAAgC,CACzCC;IAEA,MAAMC,SAASD,QAAQ,MAAM,CAAC,WAAW;IACzC,IAAIC,AAAW,UAAXA,UAAoBA,AAAW,WAAXA,QACpB,OAAO;IAEX,OAAOD,QAAQ,GAAG,CAAC,UAAU,CAAC;AAClC;AAKO,SAASE;IACZ,OAAO;QACHC,0BAA0C,OAAMC;YAC5C,MAAMJ,UAAUI,QAAQ,SAAS,CAAC,OAAO,CAACC;YAC1C,IAAI,CAACN,8BAA8BC,UAC/B;YAEJ,MAAM,EAAEM,OAAO,EAAE,GAAGN;YACpB,MAAMO,QAAQD,OAAO,CAAC,eAAe;YAErC,IAAI,CAACF,QAAQ,QAAQ,CAAC,WAAW,MAAMG,OACnC,IAAI;gBACA,MAAMH,QAAQ,QAAQ,CAAC,YAAY,CAACG;YACxC,EAAE,OAAOC,KAAK;gBACVC,QAAQ,GAAG,CAACD;YAChB;QAER;QAEAE,oBAAoCN,CAAAA;YAChCA,QAAQ,SAAS,CAAC,QAAQ,CAACO;QAC/B;KACH;AACL"}
|
|
@@ -12,8 +12,11 @@ const whitelistedHeaders = [
|
|
|
12
12
|
const setupSecureHeaders = ()=>createHandlerOnRequest(async (request, reply)=>{
|
|
13
13
|
const isOptions = "OPTIONS" === request.method;
|
|
14
14
|
const headers = ResponseHeaders.create();
|
|
15
|
-
headers.set("access-control-allow-origin",
|
|
16
|
-
|
|
15
|
+
if (request.url.startsWith("/private/")) headers.set("access-control-allow-origin", "*");
|
|
16
|
+
else {
|
|
17
|
+
headers.set("access-control-allow-origin", request.headers["origin"]);
|
|
18
|
+
headers.set("access-control-allow-credentials", "true");
|
|
19
|
+
}
|
|
17
20
|
if (isOptions) {
|
|
18
21
|
headers.set("cache-control", "public, max-age=86400");
|
|
19
22
|
headers.set("content-type", "application/json; charset=utf-8");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy/security/plugins/secureHeaders.js","sources":["../../../../src/legacy/security/plugins/secureHeaders.ts"],"sourcesContent":["import { createHandlerOnRequest, ResponseHeaders } from \"@webiny/handler\";\n\nconst whitelistedHeaders = [\n \"accept\",\n \"authorization\",\n \"cache-control\",\n \"content-type\",\n \"x-tenant\",\n \"x-apollo-tracing\",\n \"x-webiny-debug\",\n \"apollo-query-plan-experimental\"\n];\n\nexport const setupSecureHeaders = () => {\n return createHandlerOnRequest(async (request, reply) => {\n const isOptions = request.method === \"OPTIONS\";\n\n const headers = ResponseHeaders.create();\n headers.set(\"access-control-allow-origin\", request.headers[\"origin\"]);\n
|
|
1
|
+
{"version":3,"file":"legacy/security/plugins/secureHeaders.js","sources":["../../../../src/legacy/security/plugins/secureHeaders.ts"],"sourcesContent":["import { createHandlerOnRequest, ResponseHeaders } from \"@webiny/handler\";\n\nconst whitelistedHeaders = [\n \"accept\",\n \"authorization\",\n \"cache-control\",\n \"content-type\",\n \"x-tenant\",\n \"x-apollo-tracing\",\n \"x-webiny-debug\",\n \"apollo-query-plan-experimental\"\n];\n\nexport const setupSecureHeaders = () => {\n return createHandlerOnRequest(async (request, reply) => {\n const isOptions = request.method === \"OPTIONS\";\n\n const headers = ResponseHeaders.create();\n /**\n * Private files are authenticated with the `wby-id-token` cookie. Their responses must not\n * be readable by other websites through a credentialed `fetch`, so they get a wildcard origin\n * without credentials. `<img src>`, links and plain `fetch` calls are not affected.\n */\n if (request.url.startsWith(\"/private/\")) {\n headers.set(\"access-control-allow-origin\", \"*\");\n } else {\n headers.set(\"access-control-allow-origin\", request.headers[\"origin\"]);\n headers.set(\"access-control-allow-credentials\", \"true\");\n }\n\n if (isOptions) {\n headers.set(\"cache-control\", \"public, max-age=86400\");\n headers.set(\"content-type\", \"application/json; charset=utf-8\");\n headers.set(\"access-control-max-age\", \"86400\");\n headers.set(\"access-control-allow-methods\", \"OPTIONS,POST,GET,DELETE,PUT,PATCH\");\n headers.set(\"access-control-allow-headers\", whitelistedHeaders.join(\", \"));\n } else {\n headers.set(\"x-tenant\", request.headers[\"x-tenant\"] || \"root\");\n headers.set(\"vary\", \"origin\");\n }\n\n reply.headers(headers.getHeaders());\n });\n};\n"],"names":["whitelistedHeaders","setupSecureHeaders","createHandlerOnRequest","request","reply","isOptions","headers","ResponseHeaders"],"mappings":";AAEA,MAAMA,qBAAqB;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAEM,MAAMC,qBAAqB,IACvBC,uBAAuB,OAAOC,SAASC;QAC1C,MAAMC,YAAYF,AAAmB,cAAnBA,QAAQ,MAAM;QAEhC,MAAMG,UAAUC,gBAAgB,MAAM;QAMtC,IAAIJ,QAAQ,GAAG,CAAC,UAAU,CAAC,cACvBG,QAAQ,GAAG,CAAC,+BAA+B;aACxC;YACHA,QAAQ,GAAG,CAAC,+BAA+BH,QAAQ,OAAO,CAAC,SAAS;YACpEG,QAAQ,GAAG,CAAC,oCAAoC;QACpD;QAEA,IAAID,WAAW;YACXC,QAAQ,GAAG,CAAC,iBAAiB;YAC7BA,QAAQ,GAAG,CAAC,gBAAgB;YAC5BA,QAAQ,GAAG,CAAC,0BAA0B;YACtCA,QAAQ,GAAG,CAAC,gCAAgC;YAC5CA,QAAQ,GAAG,CAAC,gCAAgCN,mBAAmB,IAAI,CAAC;QACxE,OAAO;YACHM,QAAQ,GAAG,CAAC,YAAYH,QAAQ,OAAO,CAAC,WAAW,IAAI;YACvDG,QAAQ,GAAG,CAAC,QAAQ;QACxB;QAEAF,MAAM,OAAO,CAACE,QAAQ,UAAU;IACpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core",
|
|
3
|
-
"version": "6.4.12-beta.
|
|
3
|
+
"version": "6.4.12-beta.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,39 +14,39 @@
|
|
|
14
14
|
"./*": "./*"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ai-sdk/anthropic": "4.0.
|
|
18
|
-
"@ai-sdk/openai": "4.0.
|
|
19
|
-
"@webiny/api": "6.4.12-beta.
|
|
17
|
+
"@ai-sdk/anthropic": "4.0.99",
|
|
18
|
+
"@ai-sdk/openai": "4.0.111",
|
|
19
|
+
"@webiny/api": "6.4.12-beta.7",
|
|
20
20
|
"@webiny/di": "1.1.0",
|
|
21
|
-
"@webiny/error": "6.4.12-beta.
|
|
22
|
-
"@webiny/feature": "6.4.12-beta.
|
|
23
|
-
"@webiny/feature-flags": "6.4.12-beta.
|
|
24
|
-
"@webiny/handler": "6.4.12-beta.
|
|
25
|
-
"@webiny/handler-db": "6.4.12-beta.
|
|
26
|
-
"@webiny/handler-graphql": "6.4.12-beta.
|
|
27
|
-
"@webiny/plugins": "6.4.12-beta.
|
|
28
|
-
"@webiny/utils": "6.4.12-beta.
|
|
29
|
-
"@webiny/wcp": "6.4.12-beta.
|
|
30
|
-
"ai": "7.0.
|
|
21
|
+
"@webiny/error": "6.4.12-beta.7",
|
|
22
|
+
"@webiny/feature": "6.4.12-beta.7",
|
|
23
|
+
"@webiny/feature-flags": "6.4.12-beta.7",
|
|
24
|
+
"@webiny/handler": "6.4.12-beta.7",
|
|
25
|
+
"@webiny/handler-db": "6.4.12-beta.7",
|
|
26
|
+
"@webiny/handler-graphql": "6.4.12-beta.7",
|
|
27
|
+
"@webiny/plugins": "6.4.12-beta.7",
|
|
28
|
+
"@webiny/utils": "6.4.12-beta.7",
|
|
29
|
+
"@webiny/wcp": "6.4.12-beta.7",
|
|
30
|
+
"ai": "7.0.165",
|
|
31
31
|
"dataloader": "2.2.3",
|
|
32
|
-
"jose": "6.2.
|
|
32
|
+
"jose": "6.2.15",
|
|
33
33
|
"jsonwebtoken": "9.0.3",
|
|
34
34
|
"lodash": "4.18.1",
|
|
35
|
-
"minimatch": "
|
|
36
|
-
"pino": "10.
|
|
35
|
+
"minimatch": "11.0.5",
|
|
36
|
+
"pino": "10.4.0",
|
|
37
37
|
"pino-lambda": "4.4.1",
|
|
38
|
-
"zod": "4.6.
|
|
38
|
+
"zod": "4.6.7"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/jsonwebtoken": "9.0.10",
|
|
42
|
-
"@webiny/build-tools": "6.4.12-beta.
|
|
43
|
-
"@webiny/db-dynamodb": "6.4.12-beta.
|
|
44
|
-
"@webiny/handler-aws": "6.4.12-beta.
|
|
45
|
-
"@webiny/project-utils": "6.4.12-beta.
|
|
42
|
+
"@webiny/build-tools": "6.4.12-beta.7",
|
|
43
|
+
"@webiny/db-dynamodb": "6.4.12-beta.7",
|
|
44
|
+
"@webiny/handler-aws": "6.4.12-beta.7",
|
|
45
|
+
"@webiny/project-utils": "6.4.12-beta.7",
|
|
46
46
|
"jest-dynalite": "3.6.1",
|
|
47
|
-
"rimraf": "6.1.
|
|
47
|
+
"rimraf": "6.1.4",
|
|
48
48
|
"typescript": "6.0.3",
|
|
49
|
-
"vitest": "5.0
|
|
49
|
+
"vitest": "5.1.0"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|