@webiny/api-core 6.2.0-beta.0 → 6.3.0-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/ApiCoreFeature.d.ts +5 -1
- package/ApiCoreFeature.js +4 -0
- package/ApiCoreFeature.js.map +1 -1
- package/createApiCore.d.ts +1 -1
- package/exports/api.d.ts +3 -0
- package/exports/api.js +2 -0
- package/exports/api.js.map +1 -1
- package/features/ai/Ai.d.ts +26 -0
- package/features/ai/Ai.js +133 -0
- package/features/ai/Ai.js.map +1 -0
- package/features/ai/AiSdkTools.d.ts +11 -0
- package/features/ai/AiSdkTools.js +25 -0
- package/features/ai/AiSdkTools.js.map +1 -0
- package/features/ai/AnthropicSdkFactory.d.ts +10 -0
- package/features/ai/AnthropicSdkFactory.js +71 -0
- package/features/ai/AnthropicSdkFactory.js.map +1 -0
- package/features/ai/OpenAiSdkFactory.d.ts +10 -0
- package/features/ai/OpenAiSdkFactory.js +187 -0
- package/features/ai/OpenAiSdkFactory.js.map +1 -0
- package/features/ai/abstractions.d.ts +92 -0
- package/features/ai/abstractions.js +35 -0
- package/features/ai/abstractions.js.map +1 -0
- package/features/ai/feature.d.ts +4 -0
- package/features/ai/feature.js +16 -0
- package/features/ai/feature.js.map +1 -0
- package/features/ai/index.d.ts +3 -0
- package/features/ai/index.js +4 -0
- package/features/ai/index.js.map +1 -0
- package/features/buildParams/feature.d.ts +5 -1
- package/features/encryption/EncryptionService.d.ts +10 -0
- package/features/encryption/EncryptionService.js +58 -0
- package/features/encryption/EncryptionService.js.map +1 -0
- package/features/encryption/abstractions.d.ts +9 -0
- package/features/encryption/abstractions.js +5 -0
- package/features/encryption/abstractions.js.map +1 -0
- package/features/encryption/feature.d.ts +4 -0
- package/features/encryption/feature.js +10 -0
- package/features/encryption/feature.js.map +1 -0
- package/features/encryption/index.d.ts +1 -0
- package/features/encryption/index.js +3 -0
- package/features/encryption/index.js.map +1 -0
- package/features/eventPublisher/feature.d.ts +5 -1
- package/features/featureFlags/feature.d.ts +5 -1
- package/features/keyValueStore/feature.d.ts +4 -1
- package/features/keyValueStore/feature.js.map +1 -1
- package/features/logger/feature.d.ts +4 -1
- package/features/security/IdentityContext/feature.d.ts +4 -1
- package/features/security/SecurityFeature.d.ts +5 -1
- package/features/security/apiKeys/CreateApiKey/feature.d.ts +4 -1
- package/features/security/apiKeys/DeleteApiKey/feature.d.ts +4 -1
- package/features/security/apiKeys/GetApiKey/feature.d.ts +4 -1
- package/features/security/apiKeys/GetApiKeyBySlug/feature.d.ts +4 -1
- package/features/security/apiKeys/GetApiKeyByToken/feature.d.ts +4 -1
- package/features/security/apiKeys/ListApiKeys/feature.d.ts +4 -1
- package/features/security/apiKeys/UpdateApiKey/feature.d.ts +4 -1
- package/features/security/apiKeys/feature.d.ts +4 -1
- package/features/security/authentication/AuthenticationContext/feature.d.ts +4 -1
- package/features/security/authorization/AuthorizationContext/feature.d.ts +4 -1
- package/features/security/authorization/GroupsTeamsAuthorizer/feature.d.ts +4 -1
- package/features/security/permissions/createPermissions.d.ts +4 -1
- package/features/security/roles/CreateRole/feature.d.ts +4 -1
- package/features/security/roles/DeleteRole/feature.d.ts +4 -1
- package/features/security/roles/GetRole/feature.d.ts +4 -1
- package/features/security/roles/ListRoles/feature.d.ts +4 -1
- package/features/security/roles/UpdateRole/feature.d.ts +4 -1
- package/features/security/roles/feature.d.ts +4 -1
- package/features/security/teams/CreateTeam/feature.d.ts +4 -1
- package/features/security/teams/DeleteTeam/feature.d.ts +4 -1
- package/features/security/teams/GetTeam/feature.d.ts +4 -1
- package/features/security/teams/ListTeams/feature.d.ts +4 -1
- package/features/security/teams/UpdateTeam/feature.d.ts +4 -1
- package/features/security/teams/feature.d.ts +4 -1
- package/features/system/InstallSystem/feature.d.ts +5 -1
- package/features/system/SystemFeature.d.ts +4 -1
- package/features/task/TaskService/abstractions.js.map +1 -1
- package/features/tenancy/CreateTenant/feature.d.ts +5 -1
- package/features/tenancy/DeleteTenant/feature.d.ts +5 -1
- package/features/tenancy/GetRootTenant/feature.d.ts +5 -1
- package/features/tenancy/GetTenantById/feature.d.ts +5 -1
- package/features/tenancy/InstallTenant/feature.d.ts +5 -1
- package/features/tenancy/ListTenants/feature.d.ts +5 -1
- package/features/tenancy/TenancyFeature.d.ts +4 -1
- package/features/tenancy/TenancyFeature.js.map +1 -1
- package/features/tenancy/TenantContext/feature.d.ts +4 -1
- package/features/tenancy/UpdateTenant/feature.d.ts +5 -1
- package/features/users/AdminUsersFeature.d.ts +4 -1
- package/features/users/AdminUsersFeature.js.map +1 -1
- package/features/users/CreateUser/feature.d.ts +4 -1
- package/features/users/DeleteUser/feature.d.ts +4 -1
- package/features/users/ExternalIdpUserSync/feature.d.ts +4 -1
- package/features/users/GetIdentityProfile/feature.d.ts +4 -1
- package/features/users/GetUser/feature.d.ts +4 -1
- package/features/users/ListUserTeams/feature.d.ts +4 -1
- package/features/users/ListUsers/feature.d.ts +4 -1
- package/features/users/UpdateUser/feature.d.ts +4 -1
- package/features/wcp/WcpContext/WcpContext.d.ts +3 -0
- package/features/wcp/WcpContext/WcpContext.js +9 -0
- package/features/wcp/WcpContext/WcpContext.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +15 -0
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +22 -0
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
- package/features/wcp/WcpContext/feature.d.ts +5 -1
- package/features/wcp/WcpFeature.d.ts +4 -1
- package/features/wcp/WcpFeature.js.map +1 -1
- package/graphql/wcp/graphql.js +1 -0
- package/graphql/wcp/graphql.js.map +1 -1
- package/idp/feature.d.ts +4 -1
- package/legacy/wcp/LegacyWcpContext.d.ts +3 -0
- package/legacy/wcp/LegacyWcpContext.js +9 -0
- package/legacy/wcp/LegacyWcpContext.js.map +1 -1
- package/models/cms/PrivateCmsModelBuilder.js.map +1 -1
- package/models/cms/fieldsBuilder.md +4 -2
- package/package.json +20 -17
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { generateText } from "ai";
|
|
2
|
+
import type { streamText } from "ai";
|
|
3
|
+
import type { LanguageModel } from "ai";
|
|
4
|
+
import type { FlexibleSchema, ToolSet } from "ai";
|
|
5
|
+
export interface IAiSdkModel {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IAiSdk {
|
|
10
|
+
languageModel(modelId: string): LanguageModel;
|
|
11
|
+
}
|
|
12
|
+
/** A single AI SDK instance (e.g. OpenAI, Anthropic) that resolves model instances. */
|
|
13
|
+
export declare const AiSdk: import("@webiny/di").Abstraction<IAiSdk>;
|
|
14
|
+
export declare namespace AiSdk {
|
|
15
|
+
type Interface = IAiSdk;
|
|
16
|
+
}
|
|
17
|
+
export interface IAiSdkFactory {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly models: readonly IAiSdkModel[];
|
|
21
|
+
execute(apiKey?: string): Promise<IAiSdk>;
|
|
22
|
+
}
|
|
23
|
+
/** Factory that asynchronously initialises an AI SDK. Register one per provider namespace. */
|
|
24
|
+
export declare const AiSdkFactory: import("@webiny/di").Abstraction<IAiSdkFactory>;
|
|
25
|
+
export declare namespace AiSdkFactory {
|
|
26
|
+
type Interface = IAiSdkFactory;
|
|
27
|
+
}
|
|
28
|
+
export interface IAiConnectionInline {
|
|
29
|
+
readonly sdkName: string;
|
|
30
|
+
readonly apiKey?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface IAiConnection extends IAiConnectionInline {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
}
|
|
35
|
+
export interface IAiConnectionFactory {
|
|
36
|
+
execute(): Promise<IAiConnection>;
|
|
37
|
+
}
|
|
38
|
+
/** Factory that asynchronously produces an AiConnection. */
|
|
39
|
+
export declare const AiConnectionFactory: import("@webiny/di").Abstraction<IAiConnectionFactory>;
|
|
40
|
+
export declare namespace AiConnectionFactory {
|
|
41
|
+
type Interface = IAiConnectionFactory;
|
|
42
|
+
}
|
|
43
|
+
type SDKGenerateTextParams = Parameters<typeof generateText>[0];
|
|
44
|
+
type SDKStreamTextParams = Parameters<typeof streamText>[0];
|
|
45
|
+
export type AiGenerateTextParams = Omit<SDKGenerateTextParams, "model"> & {
|
|
46
|
+
model: string;
|
|
47
|
+
connection?: string | IAiConnectionInline;
|
|
48
|
+
};
|
|
49
|
+
export type AiStreamTextParams = Omit<SDKStreamTextParams, "model"> & {
|
|
50
|
+
model: string;
|
|
51
|
+
connection?: string | IAiConnectionInline;
|
|
52
|
+
};
|
|
53
|
+
export interface AiModel {
|
|
54
|
+
providerId: string;
|
|
55
|
+
providerName: string;
|
|
56
|
+
modelId: string;
|
|
57
|
+
modelName: string;
|
|
58
|
+
}
|
|
59
|
+
export interface IAi {
|
|
60
|
+
generateText(params: AiGenerateTextParams): ReturnType<typeof generateText>;
|
|
61
|
+
streamText(params: AiStreamTextParams): Promise<ReturnType<typeof streamText>>;
|
|
62
|
+
listModels(): Promise<AiModel[]>;
|
|
63
|
+
listModelsByConnections(): Promise<AiModel[]>;
|
|
64
|
+
listModelsByConnection(connection: string | IAiConnectionInline): Promise<AiModel[]>;
|
|
65
|
+
}
|
|
66
|
+
/** Interact with AI language models using registered providers. */
|
|
67
|
+
export declare const Ai: import("@webiny/di").Abstraction<IAi>;
|
|
68
|
+
export declare namespace Ai {
|
|
69
|
+
type Interface = IAi;
|
|
70
|
+
type GenerateTextParams = AiGenerateTextParams;
|
|
71
|
+
type StreamTextParams = AiStreamTextParams;
|
|
72
|
+
}
|
|
73
|
+
export interface IAiSdkTool<TInput = any> {
|
|
74
|
+
readonly name: string;
|
|
75
|
+
readonly description: string;
|
|
76
|
+
readonly inputSchema: FlexibleSchema<TInput>;
|
|
77
|
+
execute(input: TInput): Promise<unknown>;
|
|
78
|
+
}
|
|
79
|
+
/** A single tool that can be provided to AI generateText/streamText calls. */
|
|
80
|
+
export declare const AiSdkTool: import("@webiny/di").Abstraction<IAiSdkTool<any>>;
|
|
81
|
+
export declare namespace AiSdkTool {
|
|
82
|
+
type Interface = IAiSdkTool;
|
|
83
|
+
}
|
|
84
|
+
export interface IAiSdkTools {
|
|
85
|
+
getToolSet(): ToolSet;
|
|
86
|
+
}
|
|
87
|
+
/** Collection of AI SDK tools. Returns a ready-to-use ToolSet for generateText/streamText. */
|
|
88
|
+
export declare const AiSdkTools: import("@webiny/di").Abstraction<IAiSdkTools>;
|
|
89
|
+
export declare namespace AiSdkTools {
|
|
90
|
+
type Interface = IAiSdkTools;
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createAbstraction } from "@webiny/feature/api";
|
|
2
|
+
|
|
3
|
+
// AiSdk
|
|
4
|
+
|
|
5
|
+
/** A single AI SDK instance (e.g. OpenAI, Anthropic) that resolves model instances. */
|
|
6
|
+
export const AiSdk = createAbstraction("AiSdk");
|
|
7
|
+
|
|
8
|
+
// AiSdkFactory
|
|
9
|
+
|
|
10
|
+
/** Factory that asynchronously initialises an AI SDK. Register one per provider namespace. */
|
|
11
|
+
export const AiSdkFactory = createAbstraction("AiSdkFactory");
|
|
12
|
+
|
|
13
|
+
// AiConnection
|
|
14
|
+
|
|
15
|
+
// AiConnectionFactory
|
|
16
|
+
|
|
17
|
+
/** Factory that asynchronously produces an AiConnection. */
|
|
18
|
+
export const AiConnectionFactory = createAbstraction("AiConnectionFactory");
|
|
19
|
+
|
|
20
|
+
// Ai
|
|
21
|
+
|
|
22
|
+
/** Interact with AI language models using registered providers. */
|
|
23
|
+
export const Ai = createAbstraction("Ai");
|
|
24
|
+
|
|
25
|
+
// AiSdkTool
|
|
26
|
+
|
|
27
|
+
/** A single tool that can be provided to AI generateText/streamText calls. */
|
|
28
|
+
export const AiSdkTool = createAbstraction("AiSdkTool");
|
|
29
|
+
|
|
30
|
+
// AiSdkTools
|
|
31
|
+
|
|
32
|
+
/** Collection of AI SDK tools. Returns a ready-to-use ToolSet for generateText/streamText. */
|
|
33
|
+
export const AiSdkTools = createAbstraction("AiSdkTools");
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=abstractions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","AiSdk","AiSdkFactory","AiConnectionFactory","Ai","AiSdkTool","AiSdkTools"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { generateText } from \"ai\";\nimport type { streamText } from \"ai\";\nimport type { LanguageModel } from \"ai\";\nimport type { FlexibleSchema, ToolSet } from \"ai\";\n\n// AiSdk\n\nexport interface IAiSdkModel {\n id: string; // raw model id, e.g. \"claude-sonnet-4-5\"\n name: string; // human-friendly name, e.g. \"Claude Sonnet 4.5\"\n}\n\nexport interface IAiSdk {\n languageModel(modelId: string): LanguageModel;\n}\n\n/** A single AI SDK instance (e.g. OpenAI, Anthropic) that resolves model instances. */\nexport const AiSdk = createAbstraction<IAiSdk>(\"AiSdk\");\n\nexport namespace AiSdk {\n export type Interface = IAiSdk;\n}\n\n// AiSdkFactory\n\nexport interface IAiSdkFactory {\n readonly id: string; // machine id, e.g. \"anthropic\"\n readonly name: string; // human-friendly name, e.g. \"Anthropic\"\n readonly models: readonly IAiSdkModel[]; // static model list, no API call needed\n execute(apiKey?: string): Promise<IAiSdk>;\n}\n\n/** Factory that asynchronously initialises an AI SDK. Register one per provider namespace. */\nexport const AiSdkFactory = createAbstraction<IAiSdkFactory>(\"AiSdkFactory\");\n\nexport namespace AiSdkFactory {\n export type Interface = IAiSdkFactory;\n}\n\n// AiConnection\n\nexport interface IAiConnectionInline {\n readonly sdkName: string;\n readonly apiKey?: string;\n}\n\nexport interface IAiConnection extends IAiConnectionInline {\n readonly id: string;\n}\n\n// AiConnectionFactory\n\nexport interface IAiConnectionFactory {\n execute(): Promise<IAiConnection>;\n}\n\n/** Factory that asynchronously produces an AiConnection. */\nexport const AiConnectionFactory = createAbstraction<IAiConnectionFactory>(\"AiConnectionFactory\");\n\nexport namespace AiConnectionFactory {\n export type Interface = IAiConnectionFactory;\n}\n\n// Ai\n\ntype SDKGenerateTextParams = Parameters<typeof generateText>[0];\ntype SDKStreamTextParams = Parameters<typeof streamText>[0];\n\nexport type AiGenerateTextParams = Omit<SDKGenerateTextParams, \"model\"> & {\n model: string;\n connection?: string | IAiConnectionInline;\n};\nexport type AiStreamTextParams = Omit<SDKStreamTextParams, \"model\"> & {\n model: string;\n connection?: string | IAiConnectionInline;\n};\n\nexport interface AiModel {\n providerId: string; // e.g. \"anthropic\"\n providerName: string; // e.g. \"Anthropic\"\n modelId: string; // e.g. \"claude-sonnet-4-5\"\n modelName: string; // e.g. \"Claude Sonnet 4.5\"\n}\n\nexport interface IAi {\n generateText(params: AiGenerateTextParams): ReturnType<typeof generateText>;\n streamText(params: AiStreamTextParams): Promise<ReturnType<typeof streamText>>;\n listModels(): Promise<AiModel[]>;\n listModelsByConnections(): Promise<AiModel[]>;\n listModelsByConnection(connection: string | IAiConnectionInline): Promise<AiModel[]>;\n}\n\n/** Interact with AI language models using registered providers. */\nexport const Ai = createAbstraction<IAi>(\"Ai\");\n\nexport namespace Ai {\n export type Interface = IAi;\n export type GenerateTextParams = AiGenerateTextParams;\n export type StreamTextParams = AiStreamTextParams;\n}\n\n// AiSdkTool\n\nexport interface IAiSdkTool<TInput = any> {\n readonly name: string;\n readonly description: string;\n readonly inputSchema: FlexibleSchema<TInput>;\n execute(input: TInput): Promise<unknown>;\n}\n\n/** A single tool that can be provided to AI generateText/streamText calls. */\nexport const AiSdkTool = createAbstraction<IAiSdkTool>(\"AiSdkTool\");\n\nexport namespace AiSdkTool {\n export type Interface = IAiSdkTool;\n}\n\n// AiSdkTools\n\nexport interface IAiSdkTools {\n getToolSet(): ToolSet;\n}\n\n/** Collection of AI SDK tools. Returns a ready-to-use ToolSet for generateText/streamText. */\nexport const AiSdkTools = createAbstraction<IAiSdkTools>(\"AiSdkTools\");\n\nexport namespace AiSdkTools {\n export type Interface = IAiSdkTools;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;;AAMvD;;AAWA;AACA,OAAO,MAAMC,KAAK,GAAGD,iBAAiB,CAAS,OAAO,CAAC;;AAMvD;;AASA;AACA,OAAO,MAAME,YAAY,GAAGF,iBAAiB,CAAgB,cAAc,CAAC;;AAM5E;;AAWA;;AAMA;AACA,OAAO,MAAMG,mBAAmB,GAAGH,iBAAiB,CAAuB,qBAAqB,CAAC;;AAMjG;;AA6BA;AACA,OAAO,MAAMI,EAAE,GAAGJ,iBAAiB,CAAM,IAAI,CAAC;;AAQ9C;;AASA;AACA,OAAO,MAAMK,SAAS,GAAGL,iBAAiB,CAAa,WAAW,CAAC;;AAMnE;;AAMA;AACA,OAAO,MAAMM,UAAU,GAAGN,iBAAiB,CAAc,YAAY,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { OpenAiSdkFactory } from "./OpenAiSdkFactory.js";
|
|
3
|
+
import { AnthropicSdkFactory } from "./AnthropicSdkFactory.js";
|
|
4
|
+
import { Ai } from "./Ai.js";
|
|
5
|
+
import { AiSdkTools } from "./AiSdkTools.js";
|
|
6
|
+
export const AiFeature = createFeature({
|
|
7
|
+
name: "AiFeature",
|
|
8
|
+
register(container) {
|
|
9
|
+
container.register(OpenAiSdkFactory);
|
|
10
|
+
container.register(AnthropicSdkFactory);
|
|
11
|
+
container.register(Ai);
|
|
12
|
+
container.register(AiSdkTools);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","OpenAiSdkFactory","AnthropicSdkFactory","Ai","AiSdkTools","AiFeature","name","register","container"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { OpenAiSdkFactory } from \"./OpenAiSdkFactory.js\";\nimport { AnthropicSdkFactory } from \"./AnthropicSdkFactory.js\";\nimport { Ai } from \"./Ai.js\";\nimport { AiSdkTools } from \"./AiSdkTools.js\";\n\nexport const AiFeature = createFeature({\n name: \"AiFeature\",\n register(container) {\n container.register(OpenAiSdkFactory);\n container.register(AnthropicSdkFactory);\n container.register(Ai);\n container.register(AiSdkTools);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,gBAAgB;AACzB,SAASC,mBAAmB;AAC5B,SAASC,EAAE;AACX,SAASC,UAAU;AAEnB,OAAO,MAAMC,SAAS,GAAGL,aAAa,CAAC;EACnCM,IAAI,EAAE,WAAW;EACjBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACN,gBAAgB,CAAC;IACpCO,SAAS,CAACD,QAAQ,CAACL,mBAAmB,CAAC;IACvCM,SAAS,CAACD,QAAQ,CAACJ,EAAE,CAAC;IACtBK,SAAS,CAACD,QAAQ,CAACH,UAAU,CAAC;EAClC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["AiSdk","AiSdkFactory","AiConnectionFactory","Ai","AiSdkTool","AiSdkTools","AiFeature"],"sources":["index.ts"],"sourcesContent":["export {\n AiSdk,\n AiSdkFactory,\n AiConnectionFactory,\n Ai,\n AiSdkTool,\n AiSdkTools\n} from \"./abstractions.js\";\nexport type {\n IAiConnection,\n IAiConnectionInline,\n AiModel,\n IAiSdkModel,\n IAiSdkTool,\n IAiSdkTools\n} from \"./abstractions.js\";\nexport { AiFeature } from \"./feature.js\";\n"],"mappings":"AAAA,SACIA,KAAK,EACLC,YAAY,EACZC,mBAAmB,EACnBC,EAAE,EACFC,SAAS,EACTC,UAAU;AAUd,SAASC,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Encryption as EncryptionAbstraction } from "./abstractions.js";
|
|
2
|
+
import { BuildParams } from "../buildParams/abstractions.js";
|
|
3
|
+
export declare class EncryptionImpl implements EncryptionAbstraction.Interface {
|
|
4
|
+
private key;
|
|
5
|
+
private algorithm;
|
|
6
|
+
constructor(buildParams: BuildParams.Interface);
|
|
7
|
+
encrypt(value: string): string;
|
|
8
|
+
decrypt(value: string): string;
|
|
9
|
+
}
|
|
10
|
+
export declare const Encryption: import("@webiny/di").Implementation<typeof EncryptionImpl>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { createImplementation } from "@webiny/feature/api";
|
|
3
|
+
import { Encryption as EncryptionAbstraction } from "./abstractions.js";
|
|
4
|
+
import { BuildParams } from "../buildParams/abstractions.js";
|
|
5
|
+
const DEFAULT_ALGORITHM = "aes-256-gcm";
|
|
6
|
+
function keyLengthForAlgorithm(algorithm) {
|
|
7
|
+
// Parse key size in bits from algorithm name (e.g. "aes-256-gcm" → 32 bytes).
|
|
8
|
+
const bits = parseInt(algorithm.split("-")[1]);
|
|
9
|
+
if (isNaN(bits)) {
|
|
10
|
+
throw new Error(`Cannot determine key length from algorithm "${algorithm}".`);
|
|
11
|
+
}
|
|
12
|
+
return bits / 8;
|
|
13
|
+
}
|
|
14
|
+
export class EncryptionImpl {
|
|
15
|
+
constructor(buildParams) {
|
|
16
|
+
const passphrase = buildParams.get("EncryptionPassphrase");
|
|
17
|
+
if (passphrase) {
|
|
18
|
+
// Salt is optional. It ensures two projects using the same passphrase derive different keys,
|
|
19
|
+
// but since passphrases should be unique per project anyway, it's extra insurance rather than a necessity.
|
|
20
|
+
const salt = buildParams.get("EncryptionSalt") ?? "";
|
|
21
|
+
this.algorithm = buildParams.get("EncryptionAlgorithm") ?? DEFAULT_ALGORITHM;
|
|
22
|
+
const keyLength = keyLengthForAlgorithm(this.algorithm);
|
|
23
|
+
this.key = crypto.scryptSync(passphrase, salt, keyLength);
|
|
24
|
+
} else {
|
|
25
|
+
this.key = null;
|
|
26
|
+
this.algorithm = DEFAULT_ALGORITHM;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
encrypt(value) {
|
|
30
|
+
if (!this.key) {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
const iv = crypto.randomBytes(12);
|
|
34
|
+
const cipher = crypto.createCipheriv(this.algorithm, this.key, iv);
|
|
35
|
+
const encrypted = Buffer.concat([cipher.update(value, "utf8"), cipher.final()]);
|
|
36
|
+
const authTag = cipher.getAuthTag();
|
|
37
|
+
return Buffer.concat([iv, authTag, encrypted]).toString("base64");
|
|
38
|
+
}
|
|
39
|
+
decrypt(value) {
|
|
40
|
+
if (!this.key) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
const data = Buffer.from(value, "base64");
|
|
44
|
+
const iv = data.subarray(0, 12);
|
|
45
|
+
const authTag = data.subarray(12, 28);
|
|
46
|
+
const ciphertext = data.subarray(28);
|
|
47
|
+
const decipher = crypto.createDecipheriv(this.algorithm, this.key, iv);
|
|
48
|
+
decipher.setAuthTag(authTag);
|
|
49
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString("utf8");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export const Encryption = createImplementation({
|
|
53
|
+
abstraction: EncryptionAbstraction,
|
|
54
|
+
implementation: EncryptionImpl,
|
|
55
|
+
dependencies: [BuildParams]
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=EncryptionService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["crypto","createImplementation","Encryption","EncryptionAbstraction","BuildParams","DEFAULT_ALGORITHM","keyLengthForAlgorithm","algorithm","bits","parseInt","split","isNaN","Error","EncryptionImpl","constructor","buildParams","passphrase","get","salt","keyLength","key","scryptSync","encrypt","value","iv","randomBytes","cipher","createCipheriv","encrypted","Buffer","concat","update","final","authTag","getAuthTag","toString","decrypt","data","from","subarray","ciphertext","decipher","createDecipheriv","setAuthTag","abstraction","implementation","dependencies"],"sources":["EncryptionService.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Encryption as EncryptionAbstraction } from \"./abstractions.js\";\nimport { BuildParams } from \"../buildParams/abstractions.js\";\n\nconst DEFAULT_ALGORITHM = \"aes-256-gcm\";\n\nfunction keyLengthForAlgorithm(algorithm: string): number {\n // Parse key size in bits from algorithm name (e.g. \"aes-256-gcm\" → 32 bytes).\n const bits = parseInt(algorithm.split(\"-\")[1]);\n if (isNaN(bits)) {\n throw new Error(`Cannot determine key length from algorithm \"${algorithm}\".`);\n }\n return bits / 8;\n}\n\nexport class EncryptionImpl implements EncryptionAbstraction.Interface {\n private key: Buffer | null;\n private algorithm: string;\n\n constructor(buildParams: BuildParams.Interface) {\n const passphrase = buildParams.get<string>(\"EncryptionPassphrase\");\n\n if (passphrase) {\n // Salt is optional. It ensures two projects using the same passphrase derive different keys,\n // but since passphrases should be unique per project anyway, it's extra insurance rather than a necessity.\n const salt = buildParams.get<string>(\"EncryptionSalt\") ?? \"\";\n this.algorithm = buildParams.get<string>(\"EncryptionAlgorithm\") ?? DEFAULT_ALGORITHM;\n const keyLength = keyLengthForAlgorithm(this.algorithm);\n this.key = crypto.scryptSync(passphrase, salt, keyLength);\n } else {\n this.key = null;\n this.algorithm = DEFAULT_ALGORITHM;\n }\n }\n\n encrypt(value: string): string {\n if (!this.key) {\n return value;\n }\n const iv = crypto.randomBytes(12);\n const cipher = crypto.createCipheriv(this.algorithm, this.key, iv);\n const encrypted = Buffer.concat([cipher.update(value, \"utf8\"), cipher.final()]);\n const authTag = (cipher as crypto.CipherGCM).getAuthTag();\n return Buffer.concat([iv, authTag, encrypted]).toString(\"base64\");\n }\n\n decrypt(value: string): string {\n if (!this.key) {\n return value;\n }\n const data = Buffer.from(value, \"base64\");\n const iv = data.subarray(0, 12);\n const authTag = data.subarray(12, 28);\n const ciphertext = data.subarray(28);\n const decipher = crypto.createDecipheriv(this.algorithm, this.key, iv);\n (decipher as crypto.DecipherGCM).setAuthTag(authTag);\n return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString(\"utf8\");\n }\n}\n\nexport const Encryption = createImplementation({\n abstraction: EncryptionAbstraction,\n implementation: EncryptionImpl,\n dependencies: [BuildParams]\n});\n"],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface IEncryption {
|
|
2
|
+
encrypt(value: string): string;
|
|
3
|
+
decrypt(value: string): string;
|
|
4
|
+
}
|
|
5
|
+
/** Symmetric encryption and decryption using a configured secret key. */
|
|
6
|
+
export declare const Encryption: import("@webiny/di").Abstraction<IEncryption>;
|
|
7
|
+
export declare namespace Encryption {
|
|
8
|
+
type Interface = IEncryption;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","Encryption"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IEncryption {\n encrypt(value: string): string;\n decrypt(value: string): string;\n}\n\n/** Symmetric encryption and decryption using a configured secret key. */\nexport const Encryption = createAbstraction<IEncryption>(\"Encryption\");\n\nexport namespace Encryption {\n export type Interface = IEncryption;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAOvD;AACA,OAAO,MAAMC,UAAU,GAAGD,iBAAiB,CAAc,YAAY,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { Encryption } from "./EncryptionService.js";
|
|
3
|
+
export const EncryptionFeature = createFeature({
|
|
4
|
+
name: "EncryptionFeature",
|
|
5
|
+
register(container) {
|
|
6
|
+
container.register(Encryption);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFeature","Encryption","EncryptionFeature","name","register","container"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { Encryption } from \"./EncryptionService.js\";\n\nexport const EncryptionFeature = createFeature({\n name: \"EncryptionFeature\",\n register(container) {\n container.register(Encryption);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,UAAU;AAEnB,OAAO,MAAMC,iBAAiB,GAAGF,aAAa,CAAC;EAC3CG,IAAI,EAAE,mBAAmB;EACzBC,QAAQA,CAACC,SAAS,EAAE;IAChBA,SAAS,CAACD,QAAQ,CAACH,UAAU,CAAC;EAClC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Encryption } from "./abstractions.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Encryption"],"sources":["index.ts"],"sourcesContent":["export { Encryption } from \"./abstractions.js\";\n"],"mappings":"AAAA,SAASA,UAAU","ignoreList":[]}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export declare const KeyValueStoreFeature:
|
|
1
|
+
export declare const KeyValueStoreFeature: {
|
|
2
|
+
name: string;
|
|
3
|
+
register(container: import("@webiny/di").Container, context: import("./abstractions.js").IKeyValueStorageOperations): void;
|
|
4
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createFeature","GlobalKeyValueStore","KeyValueStore","KeyValueStoreRepository","KeyValueStorageOperations","KeyValueStoreFeature","name","register","container","storageOperations","registerInstance","inSingletonScope"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GlobalKeyValueStore } from \"./GlobalKeyValueStore.js\";\nimport { KeyValueStore } from \"./KeyValueStore.js\";\nimport { KeyValueStoreRepository } from \"./KeyValueStoreRepository.js\";\nimport { KeyValueStorageOperations } from \"./abstractions.js\";\n\nexport const KeyValueStoreFeature = createFeature({\n name: \"KeyValueStore\",\n register(container, storageOperations
|
|
1
|
+
{"version":3,"names":["createFeature","GlobalKeyValueStore","KeyValueStore","KeyValueStoreRepository","KeyValueStorageOperations","KeyValueStoreFeature","name","register","container","storageOperations","registerInstance","inSingletonScope"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { GlobalKeyValueStore } from \"./GlobalKeyValueStore.js\";\nimport { KeyValueStore } from \"./KeyValueStore.js\";\nimport { KeyValueStoreRepository } from \"./KeyValueStoreRepository.js\";\nimport { KeyValueStorageOperations } from \"./abstractions.js\";\n\nexport const KeyValueStoreFeature = createFeature<KeyValueStorageOperations.Interface>({\n name: \"KeyValueStore\",\n register(container, storageOperations) {\n // Register legacy storage operations\n container.registerInstance(KeyValueStorageOperations, storageOperations);\n\n container.register(KeyValueStoreRepository).inSingletonScope();\n container.register(GlobalKeyValueStore);\n container.register(KeyValueStore);\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAqB;AACnD,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AACtB,SAASC,uBAAuB;AAChC,SAASC,yBAAyB;AAElC,OAAO,MAAMC,oBAAoB,GAAGL,aAAa,CAAsC;EACnFM,IAAI,EAAE,eAAe;EACrBC,QAAQA,CAACC,SAAS,EAAEC,iBAAiB,EAAE;IACnC;IACAD,SAAS,CAACE,gBAAgB,CAACN,yBAAyB,EAAEK,iBAAiB,CAAC;IAExED,SAAS,CAACD,QAAQ,CAACJ,uBAAuB,CAAC,CAACQ,gBAAgB,CAAC,CAAC;IAC9DH,SAAS,CAACD,QAAQ,CAACN,mBAAmB,CAAC;IACvCO,SAAS,CAACD,QAAQ,CAACL,aAAa,CAAC;EACrC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
1
2
|
import type { SecurityStorageOperations as ISecurityStorageOperations } from "../../types/security.js";
|
|
2
3
|
/**
|
|
3
4
|
* Setup all security features in the DI container.
|
|
@@ -6,4 +7,7 @@ import type { SecurityStorageOperations as ISecurityStorageOperations } from "..
|
|
|
6
7
|
* @param container - DI container instance
|
|
7
8
|
* @param storageOperations - Storage operations implementation
|
|
8
9
|
*/
|
|
9
|
-
export declare const SecurityFeature:
|
|
10
|
+
export declare const SecurityFeature: {
|
|
11
|
+
name: string;
|
|
12
|
+
register(container: Container, context: ISecurityStorageOperations): void;
|
|
13
|
+
};
|
|
@@ -2,4 +2,7 @@ import type { Abstraction } from "@webiny/di";
|
|
|
2
2
|
import type { PermissionSchemaConfig } from "./types.js";
|
|
3
3
|
import type { Permissions } from "./types.js";
|
|
4
4
|
export declare function createPermissionsAbstraction<const S extends PermissionSchemaConfig>(schema: S): Abstraction<Permissions<S>>;
|
|
5
|
-
export declare function createPermissionsFeature<const S extends PermissionSchemaConfig>(schema: S, abstraction: Abstraction<Permissions<S>>):
|
|
5
|
+
export declare function createPermissionsFeature<const S extends PermissionSchemaConfig>(schema: S, abstraction: Abstraction<Permissions<S>>): {
|
|
6
|
+
name: string;
|
|
7
|
+
register(container: import("@webiny/di").Container): void;
|
|
8
|
+
};
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
2
|
+
export declare const InstallSystemFeature: {
|
|
3
|
+
name: string;
|
|
4
|
+
register(container: Container): void;
|
|
5
|
+
};
|