@webiny/api-core 0.0.0-unstable.0d717d18dd → 0.0.0-unstable.5387e5f7c8
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.js +8 -0
- package/ApiCoreFeature.js.map +1 -1
- package/exports/api/tasks.d.ts +1 -0
- package/exports/api/tasks.js +1 -1
- package/exports/api.d.ts +1 -1
- package/exports/api.js +1 -1
- package/features/ai/Ai.d.ts +3 -1
- package/features/ai/Ai.js +36 -28
- package/features/ai/Ai.js.map +1 -1
- package/features/ai/AiModelRegistry.d.ts +14 -0
- package/features/ai/AiModelRegistry.js +39 -0
- package/features/ai/AiModelRegistry.js.map +1 -0
- package/features/ai/AiSdkToolHandlerResolver.d.ts +11 -0
- package/features/ai/AiSdkToolHandlerResolver.js +19 -0
- package/features/ai/AiSdkToolHandlerResolver.js.map +1 -0
- package/features/ai/AiSdkTools.d.ts +4 -3
- package/features/ai/AiSdkTools.js +11 -9
- package/features/ai/AiSdkTools.js.map +1 -1
- package/features/ai/AnthropicSdkFactory.js +12 -4
- package/features/ai/AnthropicSdkFactory.js.map +1 -1
- package/features/ai/DEVELOPERS.md +183 -0
- package/features/ai/GoogleSdkFactory.d.ts +10 -0
- package/features/ai/GoogleSdkFactory.js +65 -0
- package/features/ai/GoogleSdkFactory.js.map +1 -0
- package/features/ai/OpenAiSdkFactory.js +51 -11
- package/features/ai/OpenAiSdkFactory.js.map +1 -1
- package/features/ai/OpenRouterSdkFactory.d.ts +10 -0
- package/features/ai/OpenRouterSdkFactory.js +112 -0
- package/features/ai/OpenRouterSdkFactory.js.map +1 -0
- package/features/ai/RemoteAiModelCatalog.d.ts +13 -0
- package/features/ai/RemoteAiModelCatalog.js +74 -0
- package/features/ai/RemoteAiModelCatalog.js.map +1 -0
- package/features/ai/abstractions.d.ts +102 -7
- package/features/ai/abstractions.js +6 -2
- package/features/ai/abstractions.js.map +1 -1
- package/features/ai/feature.js +10 -0
- package/features/ai/feature.js.map +1 -1
- package/features/ai/index.d.ts +2 -4
- package/features/ai/index.js +1 -1
- package/features/dateFormatter/DefaultDateFormatter.d.ts +15 -0
- package/features/dateFormatter/DefaultDateFormatter.js +20 -0
- package/features/dateFormatter/DefaultDateFormatter.js.map +1 -0
- package/features/dateFormatter/abstractions.d.ts +13 -0
- package/features/dateFormatter/abstractions.js +5 -0
- package/features/dateFormatter/abstractions.js.map +1 -0
- package/features/dateFormatter/feature.d.ts +4 -0
- package/features/dateFormatter/feature.js +11 -0
- package/features/dateFormatter/feature.js.map +1 -0
- package/features/dateFormatter/index.d.ts +3 -0
- package/features/dateFormatter/index.js +2 -0
- package/features/encryption/EncryptionKeyCacheFeature.d.ts +8 -0
- package/features/encryption/EncryptionKeyCacheFeature.js +11 -0
- package/features/encryption/EncryptionKeyCacheFeature.js.map +1 -0
- package/features/encryption/EncryptionService.d.ts +2 -1
- package/features/encryption/EncryptionService.js +11 -4
- package/features/encryption/EncryptionService.js.map +1 -1
- package/features/encryption/MemoryEncryptionKeyCache.d.ts +13 -0
- package/features/encryption/MemoryEncryptionKeyCache.js +26 -0
- package/features/encryption/MemoryEncryptionKeyCache.js.map +1 -0
- package/features/encryption/abstractions.d.ts +11 -0
- package/features/encryption/abstractions.js +2 -1
- package/features/encryption/abstractions.js.map +1 -1
- package/features/encryption/index.d.ts +1 -0
- package/features/encryption/index.js +1 -0
- package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.d.ts +13 -0
- package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js +61 -0
- package/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js.map +1 -0
- package/features/httpClient/HttpClient.d.ts +7 -0
- package/features/httpClient/HttpClient.js +72 -0
- package/features/httpClient/HttpClient.js.map +1 -0
- package/features/httpClient/HttpRequestError.d.ts +10 -0
- package/features/httpClient/HttpRequestError.js +13 -0
- package/features/httpClient/HttpRequestError.js.map +1 -0
- package/features/httpClient/HttpStatusError.d.ts +12 -0
- package/features/httpClient/HttpStatusError.js +12 -0
- package/features/httpClient/HttpStatusError.js.map +1 -0
- package/features/httpClient/abstractions.d.ts +32 -0
- package/features/httpClient/abstractions.js +5 -0
- package/features/httpClient/abstractions.js.map +1 -0
- package/features/httpClient/feature.d.ts +4 -0
- package/features/httpClient/feature.js +11 -0
- package/features/httpClient/feature.js.map +1 -0
- package/features/httpClient/index.d.ts +3 -0
- package/features/httpClient/index.js +3 -0
- package/features/requestContext/RawAssumePermissions.d.ts +14 -0
- package/features/requestContext/RawAssumePermissions.js +19 -0
- package/features/requestContext/RawAssumePermissions.js.map +1 -0
- package/features/requestContext/abstractions.d.ts +22 -0
- package/features/requestContext/abstractions.js +2 -1
- package/features/requestContext/abstractions.js.map +1 -1
- package/features/requestContext/extractAssumePermissions.d.ts +14 -0
- package/features/requestContext/extractAssumePermissions.js +32 -0
- package/features/requestContext/extractAssumePermissions.js.map +1 -0
- package/features/requestContext/feature.d.ts +2 -1
- package/features/requestContext/feature.js +2 -0
- package/features/requestContext/feature.js.map +1 -1
- package/features/requestContext/index.d.ts +3 -1
- package/features/requestContext/index.js +2 -1
- package/features/security/IdentityContext/IdentityContext.d.ts +3 -3
- package/features/security/IdentityContext/IdentityContext.js +6 -6
- package/features/security/IdentityContext/IdentityContext.js.map +1 -1
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js +11 -6
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js +9 -3
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/shared/schemas.d.ts +2 -2
- package/features/security/apiKeys/shared/schemas.js +2 -2
- package/features/security/apiKeys/shared/schemas.js.map +1 -1
- package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.d.ts +30 -0
- package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js +60 -0
- package/features/security/authorization/GroupsTeamsAuthorizer/AssumedPermissions.js.map +1 -0
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.d.ts +3 -3
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js +5 -5
- package/features/security/authorization/GroupsTeamsAuthorizer/GetPermissionsFromIdentity.js.map +1 -1
- package/features/security/authorization/GroupsTeamsAuthorizer/feature.js +2 -0
- package/features/security/authorization/GroupsTeamsAuthorizer/feature.js.map +1 -1
- package/features/security/roles/CreateRole/CreateRoleUseCase.js +11 -6
- package/features/security/roles/CreateRole/CreateRoleUseCase.js.map +1 -1
- package/features/security/roles/CreateRole/schema.d.ts +1 -1
- package/features/security/roles/CreateRole/schema.js +1 -1
- package/features/security/roles/CreateRole/schema.js.map +1 -1
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +9 -3
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
- package/features/security/roles/UpdateRole/schema.d.ts +1 -1
- package/features/security/roles/UpdateRole/schema.js +1 -1
- package/features/security/roles/UpdateRole/schema.js.map +1 -1
- package/features/security/shared/description.d.ts +4 -0
- package/features/security/shared/description.js +7 -0
- package/features/security/shared/description.js.map +1 -0
- package/features/security/shared/index.d.ts +1 -0
- package/features/security/shared/index.js +1 -0
- package/features/security/teams/CreateTeam/CreateTeamUseCase.d.ts +3 -1
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js +20 -8
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js.map +1 -1
- package/features/security/teams/CreateTeam/schema.d.ts +1 -1
- package/features/security/teams/CreateTeam/schema.js +1 -1
- package/features/security/teams/CreateTeam/schema.js.map +1 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.d.ts +3 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +20 -5
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
- package/features/security/teams/UpdateTeam/schema.d.ts +1 -1
- package/features/security/teams/UpdateTeam/schema.js +1 -1
- package/features/security/teams/UpdateTeam/schema.js.map +1 -1
- package/features/security/teams/shared/resolveRoleIdentifiers.d.ts +17 -0
- package/features/security/teams/shared/resolveRoleIdentifiers.js +32 -0
- package/features/security/teams/shared/resolveRoleIdentifiers.js.map +1 -0
- package/features/slugify/DefaultSlugify.d.ts +8 -0
- package/features/slugify/DefaultSlugify.js +20 -0
- package/features/slugify/DefaultSlugify.js.map +1 -0
- package/features/slugify/abstractions.d.ts +12 -0
- package/features/slugify/abstractions.js +5 -0
- package/features/slugify/abstractions.js.map +1 -0
- package/features/slugify/feature.d.ts +4 -0
- package/features/slugify/feature.js +11 -0
- package/features/slugify/feature.js.map +1 -0
- package/features/slugify/index.d.ts +3 -0
- package/features/slugify/index.js +2 -0
- package/features/stringFormatter/DefaultStringFormatter.d.ts +17 -0
- package/features/stringFormatter/DefaultStringFormatter.js +19 -0
- package/features/stringFormatter/DefaultStringFormatter.js.map +1 -0
- package/features/stringFormatter/abstractions.d.ts +11 -0
- package/features/stringFormatter/abstractions.js +5 -0
- package/features/stringFormatter/abstractions.js.map +1 -0
- package/features/stringFormatter/feature.d.ts +4 -0
- package/features/stringFormatter/feature.js +13 -0
- package/features/stringFormatter/feature.js.map +1 -0
- package/features/stringFormatter/index.d.ts +3 -0
- package/features/stringFormatter/index.js +2 -0
- package/features/task/TaskDefinition/abstractions.d.ts +69 -4
- package/features/task/TaskDefinition/abstractions.js +2 -1
- package/features/task/TaskDefinition/abstractions.js.map +1 -1
- package/features/tenancy/TenantContext/TenantContext.d.ts +1 -0
- package/features/tenancy/TenantContext/TenantContext.js +13 -8
- package/features/tenancy/TenantContext/TenantContext.js.map +1 -1
- package/features/wcp/WcpContext/WcpContext.d.ts +6 -0
- package/features/wcp/WcpContext/WcpContext.js +18 -0
- package/features/wcp/WcpContext/WcpContext.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +9 -69
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +63 -35
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js.map +1 -1
- package/features/wcp/WcpFeature.js +2 -0
- package/features/wcp/WcpFeature.js.map +1 -1
- package/features/wcp/WcpLicenseLoader.d.ts +25 -0
- package/features/wcp/WcpLicenseLoader.js +58 -0
- package/features/wcp/WcpLicenseLoader.js.map +1 -0
- package/features/wcp/WcpLicenseProvider.d.ts +6 -14
- package/features/wcp/WcpLicenseProvider.js +3 -7
- package/features/wcp/WcpLicenseProvider.js.map +1 -1
- package/features/wcp/resolveWcpProjectEnvironment.d.ts +9 -0
- package/features/wcp/resolveWcpProjectEnvironment.js +23 -0
- package/features/wcp/resolveWcpProjectEnvironment.js.map +1 -0
- package/graphql/ApiCoreSchemaFactory.d.ts +1 -0
- package/graphql/ApiCoreSchemaFactory.js +7 -1
- package/graphql/ApiCoreSchemaFactory.js.map +1 -1
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.d.ts +10 -0
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.js +53 -0
- package/graphql/featureFlags/FeatureFlagsSchemaFactory.js.map +1 -0
- package/graphql/security/SecuritySchemaFactory.d.ts +1 -0
- package/graphql/security/SecuritySchemaFactory.js +4 -0
- package/graphql/security/SecuritySchemaFactory.js.map +1 -1
- package/graphql/system/SystemSchemaFactory.d.ts +1 -0
- package/graphql/system/SystemSchemaFactory.js +4 -0
- package/graphql/system/SystemSchemaFactory.js.map +1 -1
- package/graphql/users/UsersSchemaFactory.d.ts +1 -0
- package/graphql/users/UsersSchemaFactory.js +4 -0
- package/graphql/users/UsersSchemaFactory.js.map +1 -1
- package/graphql/wcp/WcpSchemaFactory.d.ts +1 -0
- package/graphql/wcp/WcpSchemaFactory.js +5 -0
- package/graphql/wcp/WcpSchemaFactory.js.map +1 -1
- package/idp/JwksCache.d.ts +14 -3
- package/idp/JwksCache.js +97 -17
- package/idp/JwksCache.js.map +1 -1
- package/idp/JwksStoreFeature.d.ts +8 -0
- package/idp/JwksStoreFeature.js +11 -0
- package/idp/JwksStoreFeature.js.map +1 -0
- package/idp/MemoryJwksStore.d.ts +14 -0
- package/idp/MemoryJwksStore.js +21 -0
- package/idp/MemoryJwksStore.js.map +1 -0
- package/idp/OidcJwtIdentityProvider.js +5 -1
- package/idp/OidcJwtIdentityProvider.js.map +1 -1
- package/idp/abstractions.d.ts +24 -0
- package/idp/abstractions.js +2 -1
- package/idp/abstractions.js.map +1 -1
- package/idp/feature.js +1 -2
- package/idp/feature.js.map +1 -1
- package/idp/index.d.ts +1 -0
- package/idp/index.js +1 -0
- package/package.json +20 -18
- package/testing/environment.d.ts +14 -0
- package/testing/environment.js +18 -0
- package/testing/environment.js.map +1 -0
- package/features/wcp/loadWcpLicense.d.ts +0 -2
- package/features/wcp/loadWcpLicense.js +0 -51
- package/features/wcp/loadWcpLicense.js.map +0 -1
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
import type { Constructor } from "@webiny/di";
|
|
1
2
|
import type { generateText } from "ai";
|
|
2
3
|
import type { streamText } from "ai";
|
|
3
4
|
import type { LanguageModel } from "ai";
|
|
4
5
|
import type { FlexibleSchema, ToolSet } from "ai";
|
|
6
|
+
/**
|
|
7
|
+
* What a model accepts, as published in the model catalog. A capability that isn't listed is unknown,
|
|
8
|
+
* and unknown is treated as unsupported: a parameter the model may reject is not sent.
|
|
9
|
+
*/
|
|
10
|
+
export interface IAiModelSupports {
|
|
11
|
+
tools?: boolean;
|
|
12
|
+
vision?: boolean;
|
|
13
|
+
temperature?: boolean;
|
|
14
|
+
}
|
|
5
15
|
export interface IAiSdkModel {
|
|
6
16
|
id: string;
|
|
7
17
|
name: string;
|
|
18
|
+
deprecated?: Date;
|
|
19
|
+
endOfLife?: Date;
|
|
20
|
+
supports?: IAiModelSupports;
|
|
8
21
|
}
|
|
9
22
|
export interface IAiSdk {
|
|
10
23
|
languageModel(modelId: string): LanguageModel;
|
|
@@ -55,6 +68,9 @@ export interface AiModel {
|
|
|
55
68
|
providerName: string;
|
|
56
69
|
modelId: string;
|
|
57
70
|
modelName: string;
|
|
71
|
+
deprecated: Date | undefined;
|
|
72
|
+
endOfLife: Date | undefined;
|
|
73
|
+
supports: IAiModelSupports | undefined;
|
|
58
74
|
}
|
|
59
75
|
export interface IAi {
|
|
60
76
|
generateText(params: AiGenerateTextParams): ReturnType<typeof generateText>;
|
|
@@ -70,16 +86,95 @@ export declare namespace Ai {
|
|
|
70
86
|
type GenerateTextParams = AiGenerateTextParams;
|
|
71
87
|
type StreamTextParams = AiStreamTextParams;
|
|
72
88
|
}
|
|
73
|
-
export interface
|
|
89
|
+
export interface IAiModelRegistry {
|
|
90
|
+
listModels(): Promise<AiModel[]>;
|
|
91
|
+
}
|
|
92
|
+
/** Single source of truth for available AI models. Decoratable to restrict the model list. */
|
|
93
|
+
export declare const AiModelRegistry: import("@webiny/di").Abstraction<IAiModelRegistry>;
|
|
94
|
+
export declare namespace AiModelRegistry {
|
|
95
|
+
type Interface = IAiModelRegistry;
|
|
96
|
+
}
|
|
97
|
+
export interface AiCatalogProvider {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
models: IAiSdkModel[];
|
|
101
|
+
}
|
|
102
|
+
export interface IAiModelCatalog {
|
|
103
|
+
/** Returns `undefined` when the catalog can't be loaded. */
|
|
104
|
+
listProviders(): Promise<AiCatalogProvider[] | undefined>;
|
|
105
|
+
}
|
|
106
|
+
/** The published list of providers and models Webiny supports. SDK factories still gate what is offered. */
|
|
107
|
+
export declare const AiModelCatalog: import("@webiny/di").Abstraction<IAiModelCatalog>;
|
|
108
|
+
export declare namespace AiModelCatalog {
|
|
109
|
+
type Interface = IAiModelCatalog;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Behavioural hints about a tool. Purely advisory — they never replace a permission check.
|
|
113
|
+
* Names mirror the MCP tool annotations so they can be forwarded verbatim to MCP clients,
|
|
114
|
+
* which use them to decide what to auto-approve and what to confirm with the user.
|
|
115
|
+
*/
|
|
116
|
+
export interface IAiSdkToolAnnotations {
|
|
117
|
+
/** Tool does not modify state. */
|
|
118
|
+
readOnlyHint?: boolean;
|
|
119
|
+
/** Tool may perform destructive updates (only meaningful when not read-only). */
|
|
120
|
+
destructiveHint?: boolean;
|
|
121
|
+
/** Repeated calls with the same arguments have no additional effect. */
|
|
122
|
+
idempotentHint?: boolean;
|
|
123
|
+
/** Tool interacts with entities outside its own closed world. */
|
|
124
|
+
openWorldHint?: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* What a tool DOES. This is the half that injects use cases, so it is built only for a tool the
|
|
128
|
+
* model actually calls, and only at the moment it calls it.
|
|
129
|
+
*/
|
|
130
|
+
export interface IAiSdkToolHandler<TInput = any> {
|
|
131
|
+
execute(input: TInput): Promise<unknown>;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* What a tool IS: everything the model is told about it, plus the class that runs it.
|
|
135
|
+
*
|
|
136
|
+
* Carries no behaviour and no dependencies, which is what makes the registry cheap to read.
|
|
137
|
+
* `AiSdkTools` builds every definition to assemble the tool set, and builds a handler only for a
|
|
138
|
+
* tool the model actually calls.
|
|
139
|
+
*/
|
|
140
|
+
export interface IAiSdkToolDefinition<TInput = any> {
|
|
74
141
|
readonly name: string;
|
|
75
142
|
readonly description: string;
|
|
76
143
|
readonly inputSchema: FlexibleSchema<TInput>;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
144
|
+
/** Human-friendly display name. Falls back to `name` when omitted. */
|
|
145
|
+
readonly title?: string;
|
|
146
|
+
readonly annotations?: IAiSdkToolAnnotations;
|
|
147
|
+
readonly handler: Constructor<IAiSdkToolHandler<TInput>>;
|
|
148
|
+
}
|
|
149
|
+
export declare const AiSdkToolDefinition: import("@webiny/di").Abstraction<IAiSdkToolDefinition<any>>;
|
|
150
|
+
/**
|
|
151
|
+
* The behaviour half of a tool, built on demand through {@link AiSdkToolHandlerResolver}.
|
|
152
|
+
*
|
|
153
|
+
* Implementations are NOT registered against this abstraction. The definition points at the class
|
|
154
|
+
* directly, exactly as `HttpRouteDefinition` points at its `HttpRouteHandler`. Declaring them
|
|
155
|
+
* through it is what attaches their dependency metadata.
|
|
156
|
+
*/
|
|
157
|
+
export declare const AiSdkToolHandler: import("@webiny/di").Abstraction<IAiSdkToolHandler<any>>;
|
|
158
|
+
export declare namespace AiSdkToolDefinition {
|
|
159
|
+
type Interface<TInput = any> = IAiSdkToolDefinition<TInput>;
|
|
160
|
+
type Annotations = IAiSdkToolAnnotations;
|
|
161
|
+
}
|
|
162
|
+
export declare namespace AiSdkToolHandler {
|
|
163
|
+
type Interface<TInput = any> = IAiSdkToolHandler<TInput>;
|
|
164
|
+
}
|
|
165
|
+
export interface IAiSdkToolHandlerResolver {
|
|
166
|
+
resolve<TInput>(handler: Constructor<IAiSdkToolHandler<TInput>>): IAiSdkToolHandler<TInput>;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Builds the behaviour half of a tool on demand.
|
|
170
|
+
*
|
|
171
|
+
* Something has to turn `tool.handler` (a class) into an instance, and that needs the container.
|
|
172
|
+
* Rather than injecting the container into the tool registry, it lives behind this one narrow
|
|
173
|
+
* abstraction, so everything else depends on `resolve(handler)` and stays testable with a stub.
|
|
174
|
+
*/
|
|
175
|
+
export declare const AiSdkToolHandlerResolver: import("@webiny/di").Abstraction<IAiSdkToolHandlerResolver>;
|
|
176
|
+
export declare namespace AiSdkToolHandlerResolver {
|
|
177
|
+
type Interface = IAiSdkToolHandlerResolver;
|
|
83
178
|
}
|
|
84
179
|
export interface IAiSdkTools {
|
|
85
180
|
getToolSet(): ToolSet;
|
|
@@ -3,8 +3,12 @@ const AiSdk = createAbstraction("AiSdk");
|
|
|
3
3
|
const AiSdkFactory = createAbstraction("AiSdkFactory");
|
|
4
4
|
const AiConnectionFactory = createAbstraction("AiConnectionFactory");
|
|
5
5
|
const Ai = createAbstraction("Ai");
|
|
6
|
-
const
|
|
6
|
+
const AiModelRegistry = createAbstraction("AiModelRegistry");
|
|
7
|
+
const AiModelCatalog = createAbstraction("AiModelCatalog");
|
|
8
|
+
const AiSdkToolDefinition = createAbstraction("AiSdkToolDefinition");
|
|
9
|
+
const AiSdkToolHandler = createAbstraction("AiSdkToolHandler");
|
|
10
|
+
const AiSdkToolHandlerResolver = createAbstraction("AiSdkToolHandlerResolver");
|
|
7
11
|
const AiSdkTools = createAbstraction("AiSdkTools");
|
|
8
|
-
export { Ai, AiConnectionFactory, AiSdk, AiSdkFactory,
|
|
12
|
+
export { Ai, AiConnectionFactory, AiModelCatalog, AiModelRegistry, AiSdk, AiSdkFactory, AiSdkToolDefinition, AiSdkToolHandler, AiSdkToolHandlerResolver, AiSdkTools };
|
|
9
13
|
|
|
10
14
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ai/abstractions.js","sources":["../../../src/features/ai/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//
|
|
1
|
+
{"version":3,"file":"features/ai/abstractions.js","sources":["../../../src/features/ai/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Constructor } from \"@webiny/di\";\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\n/**\n * What a model accepts, as published in the model catalog. A capability that isn't listed is unknown,\n * and unknown is treated as unsupported: a parameter the model may reject is not sent.\n */\nexport interface IAiModelSupports {\n tools?: boolean;\n vision?: boolean;\n temperature?: boolean;\n}\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 deprecated?: Date;\n endOfLife?: Date;\n supports?: IAiModelSupports;\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 deprecated: Date | undefined;\n endOfLife: Date | undefined;\n supports: IAiModelSupports | undefined;\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// AiModelRegistry\n\nexport interface IAiModelRegistry {\n listModels(): Promise<AiModel[]>;\n}\n\n/** Single source of truth for available AI models. Decoratable to restrict the model list. */\nexport const AiModelRegistry = createAbstraction<IAiModelRegistry>(\"AiModelRegistry\");\n\nexport namespace AiModelRegistry {\n export type Interface = IAiModelRegistry;\n}\n\n// AiModelCatalog\n\nexport interface AiCatalogProvider {\n id: string; // Matches `AiSdkFactory.id`, e.g. \"anthropic\".\n name: string; // Human-friendly name, e.g. \"Anthropic\".\n models: IAiSdkModel[];\n}\n\nexport interface IAiModelCatalog {\n /** Returns `undefined` when the catalog can't be loaded. */\n listProviders(): Promise<AiCatalogProvider[] | undefined>;\n}\n\n/** The published list of providers and models Webiny supports. SDK factories still gate what is offered. */\nexport const AiModelCatalog = createAbstraction<IAiModelCatalog>(\"AiModelCatalog\");\n\nexport namespace AiModelCatalog {\n export type Interface = IAiModelCatalog;\n}\n\n// AiSdkToolDefinition\n\n/**\n * Behavioural hints about a tool. Purely advisory — they never replace a permission check.\n * Names mirror the MCP tool annotations so they can be forwarded verbatim to MCP clients,\n * which use them to decide what to auto-approve and what to confirm with the user.\n */\nexport interface IAiSdkToolAnnotations {\n /** Tool does not modify state. */\n readOnlyHint?: boolean;\n /** Tool may perform destructive updates (only meaningful when not read-only). */\n destructiveHint?: boolean;\n /** Repeated calls with the same arguments have no additional effect. */\n idempotentHint?: boolean;\n /** Tool interacts with entities outside its own closed world. */\n openWorldHint?: boolean;\n}\n\n/**\n * What a tool DOES. This is the half that injects use cases, so it is built only for a tool the\n * model actually calls, and only at the moment it calls it.\n */\nexport interface IAiSdkToolHandler<TInput = any> {\n execute(input: TInput): Promise<unknown>;\n}\n\n/**\n * What a tool IS: everything the model is told about it, plus the class that runs it.\n *\n * Carries no behaviour and no dependencies, which is what makes the registry cheap to read.\n * `AiSdkTools` builds every definition to assemble the tool set, and builds a handler only for a\n * tool the model actually calls.\n */\nexport interface IAiSdkToolDefinition<TInput = any> {\n readonly name: string;\n readonly description: string;\n readonly inputSchema: FlexibleSchema<TInput>;\n /** Human-friendly display name. Falls back to `name` when omitted. */\n readonly title?: string;\n readonly annotations?: IAiSdkToolAnnotations;\n readonly handler: Constructor<IAiSdkToolHandler<TInput>>;\n}\n\nexport const AiSdkToolDefinition = createAbstraction<IAiSdkToolDefinition>(\"AiSdkToolDefinition\");\n\n/**\n * The behaviour half of a tool, built on demand through {@link AiSdkToolHandlerResolver}.\n *\n * Implementations are NOT registered against this abstraction. The definition points at the class\n * directly, exactly as `HttpRouteDefinition` points at its `HttpRouteHandler`. Declaring them\n * through it is what attaches their dependency metadata.\n */\nexport const AiSdkToolHandler = createAbstraction<IAiSdkToolHandler>(\"AiSdkToolHandler\");\n\nexport namespace AiSdkToolDefinition {\n export type Interface<TInput = any> = IAiSdkToolDefinition<TInput>;\n export type Annotations = IAiSdkToolAnnotations;\n}\n\nexport namespace AiSdkToolHandler {\n export type Interface<TInput = any> = IAiSdkToolHandler<TInput>;\n}\n\n// AiSdkToolHandlerResolver\n\nexport interface IAiSdkToolHandlerResolver {\n resolve<TInput>(handler: Constructor<IAiSdkToolHandler<TInput>>): IAiSdkToolHandler<TInput>;\n}\n\n/**\n * Builds the behaviour half of a tool on demand.\n *\n * Something has to turn `tool.handler` (a class) into an instance, and that needs the container.\n * Rather than injecting the container into the tool registry, it lives behind this one narrow\n * abstraction, so everything else depends on `resolve(handler)` and stays testable with a stub.\n */\nexport const AiSdkToolHandlerResolver = createAbstraction<IAiSdkToolHandlerResolver>(\n \"AiSdkToolHandlerResolver\"\n);\n\nexport namespace AiSdkToolHandlerResolver {\n export type Interface = IAiSdkToolHandlerResolver;\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"],"names":["AiSdk","createAbstraction","AiSdkFactory","AiConnectionFactory","Ai","AiModelRegistry","AiModelCatalog","AiSdkToolDefinition","AiSdkToolHandler","AiSdkToolHandlerResolver","AiSdkTools"],"mappings":";AAgCO,MAAMA,QAAQC,kBAA0B;AAgBxC,MAAMC,eAAeD,kBAAiC;AAwBtD,MAAME,sBAAsBF,kBAAwC;AAuCpE,MAAMG,KAAKH,kBAAuB;AAelC,MAAMI,kBAAkBJ,kBAAoC;AAoB5D,MAAMK,iBAAiBL,kBAAmC;AAiD1D,MAAMM,sBAAsBN,kBAAwC;AASpE,MAAMO,mBAAmBP,kBAAqC;AAwB9D,MAAMQ,2BAA2BR,kBACpC;AAcG,MAAMS,aAAaT,kBAA+B"}
|
package/features/ai/feature.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { OpenAiSdkFactory } from "./OpenAiSdkFactory.js";
|
|
3
3
|
import { AnthropicSdkFactory } from "./AnthropicSdkFactory.js";
|
|
4
|
+
import { GoogleSdkFactory } from "./GoogleSdkFactory.js";
|
|
5
|
+
import { OpenRouterSdkFactory } from "./OpenRouterSdkFactory.js";
|
|
4
6
|
import { Ai } from "./Ai.js";
|
|
7
|
+
import { AiModelRegistry } from "./AiModelRegistry.js";
|
|
8
|
+
import { RemoteAiModelCatalog } from "./RemoteAiModelCatalog.js";
|
|
5
9
|
import { AiSdkTools } from "./AiSdkTools.js";
|
|
10
|
+
import { AiSdkToolHandlerResolver } from "./AiSdkToolHandlerResolver.js";
|
|
6
11
|
import { AiOutputToolRegistry } from "./toolPipeline/AiOutputToolRegistry.js";
|
|
7
12
|
import { AiToolPipelineRunner } from "./toolPipeline/AiToolPipelineRunner.js";
|
|
8
13
|
import { DefaultTextExtractor } from "./TextExtractor/DefaultTextExtractor.js";
|
|
@@ -11,8 +16,13 @@ const AiFeature = createFeature({
|
|
|
11
16
|
register (container) {
|
|
12
17
|
container.register(OpenAiSdkFactory);
|
|
13
18
|
container.register(AnthropicSdkFactory);
|
|
19
|
+
container.register(GoogleSdkFactory);
|
|
20
|
+
container.register(OpenRouterSdkFactory);
|
|
14
21
|
container.register(Ai);
|
|
22
|
+
container.register(RemoteAiModelCatalog);
|
|
23
|
+
container.register(AiModelRegistry);
|
|
15
24
|
container.register(AiSdkTools);
|
|
25
|
+
container.register(AiSdkToolHandlerResolver);
|
|
16
26
|
container.register(AiOutputToolRegistry);
|
|
17
27
|
container.register(AiToolPipelineRunner);
|
|
18
28
|
container.register(DefaultTextExtractor);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/ai/feature.js","sources":["../../../src/features/ai/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\";\nimport { AiOutputToolRegistry } from \"./toolPipeline/AiOutputToolRegistry.js\";\nimport { AiToolPipelineRunner } from \"./toolPipeline/AiToolPipelineRunner.js\";\nimport { DefaultTextExtractor } from \"./TextExtractor/DefaultTextExtractor.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 container.register(AiOutputToolRegistry);\n container.register(AiToolPipelineRunner);\n container.register(DefaultTextExtractor);\n }\n});\n"],"names":["AiFeature","createFeature","container","OpenAiSdkFactory","AnthropicSdkFactory","Ai","AiSdkTools","AiOutputToolRegistry","AiToolPipelineRunner","DefaultTextExtractor"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features/ai/feature.js","sources":["../../../src/features/ai/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { OpenAiSdkFactory } from \"./OpenAiSdkFactory.js\";\nimport { AnthropicSdkFactory } from \"./AnthropicSdkFactory.js\";\nimport { GoogleSdkFactory } from \"./GoogleSdkFactory.js\";\nimport { OpenRouterSdkFactory } from \"./OpenRouterSdkFactory.js\";\nimport { Ai } from \"./Ai.js\";\nimport { AiModelRegistry } from \"./AiModelRegistry.js\";\nimport { RemoteAiModelCatalog } from \"./RemoteAiModelCatalog.js\";\nimport { AiSdkTools } from \"./AiSdkTools.js\";\nimport { AiSdkToolHandlerResolver } from \"./AiSdkToolHandlerResolver.js\";\nimport { AiOutputToolRegistry } from \"./toolPipeline/AiOutputToolRegistry.js\";\nimport { AiToolPipelineRunner } from \"./toolPipeline/AiToolPipelineRunner.js\";\nimport { DefaultTextExtractor } from \"./TextExtractor/DefaultTextExtractor.js\";\n\nexport const AiFeature = createFeature({\n name: \"AiFeature\",\n register(container) {\n container.register(OpenAiSdkFactory);\n container.register(AnthropicSdkFactory);\n container.register(GoogleSdkFactory);\n container.register(OpenRouterSdkFactory);\n container.register(Ai);\n container.register(RemoteAiModelCatalog);\n container.register(AiModelRegistry);\n container.register(AiSdkTools);\n container.register(AiSdkToolHandlerResolver);\n container.register(AiOutputToolRegistry);\n container.register(AiToolPipelineRunner);\n container.register(DefaultTextExtractor);\n }\n});\n"],"names":["AiFeature","createFeature","container","OpenAiSdkFactory","AnthropicSdkFactory","GoogleSdkFactory","OpenRouterSdkFactory","Ai","RemoteAiModelCatalog","AiModelRegistry","AiSdkTools","AiSdkToolHandlerResolver","AiOutputToolRegistry","AiToolPipelineRunner","DefaultTextExtractor"],"mappings":";;;;;;;;;;;;;AAcO,MAAMA,YAAYC,cAAc;IACnC,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBN,UAAU,QAAQ,CAACO;QACnBP,UAAU,QAAQ,CAACQ;QACnBR,UAAU,QAAQ,CAACS;QACnBT,UAAU,QAAQ,CAACU;QACnBV,UAAU,QAAQ,CAACW;QACnBX,UAAU,QAAQ,CAACY;IACvB;AACJ"}
|
package/features/ai/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
export { AiSdk, AiSdkFactory, AiConnectionFactory, Ai,
|
|
2
|
-
export type { IAiConnection, IAiConnectionInline, AiModel, IAiSdkModel
|
|
1
|
+
export { AiSdk, AiSdkFactory, AiConnectionFactory, Ai, AiModelRegistry, AiModelCatalog, AiSdkToolDefinition, AiSdkToolHandler, AiSdkToolHandlerResolver, AiSdkTools } from "./abstractions.js";
|
|
2
|
+
export type { IAiConnection, IAiConnectionInline, AiModel, IAiSdkModel } from "./abstractions.js";
|
|
3
3
|
export { AiOutputTool, AiOutputToolRegistry, AiToolPipelineRunner } from "./toolPipeline/index.js";
|
|
4
|
-
export type { IAiOutputTool, IAiOutputToolRegistry, IAiToolPipelineRunner } from "./toolPipeline/index.js";
|
|
5
4
|
export { TextExtractor, DefaultTextExtractor } from "./TextExtractor/index.js";
|
|
6
|
-
export type { ITextExtractor, TextExtractorResult } from "./TextExtractor/index.js";
|
|
7
5
|
export { AiBeforeGenerateTextEvent, AiBeforeGenerateTextEventHandler, AiAfterGenerateTextEvent, AiAfterGenerateTextEventHandler, AiGenerateTextErrorEvent, AiGenerateTextErrorEventHandler, AiBeforeStreamTextEvent, AiBeforeStreamTextEventHandler } from "./events.js";
|
|
8
6
|
export type { AiBeforeGenerateTextPayload, AiAfterGenerateTextPayload, AiGenerateTextErrorPayload, AiBeforeStreamTextPayload } from "./events.js";
|
|
9
7
|
export { AiFeature } from "./feature.js";
|
package/features/ai/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Ai, AiConnectionFactory, AiSdk, AiSdkFactory,
|
|
1
|
+
export { Ai, AiConnectionFactory, AiModelCatalog, AiModelRegistry, AiSdk, AiSdkFactory, AiSdkToolDefinition, AiSdkToolHandler, AiSdkToolHandlerResolver, AiSdkTools } from "./abstractions.js";
|
|
2
2
|
export { AiOutputTool, AiOutputToolRegistry, AiToolPipelineRunner } from "./toolPipeline/index.js";
|
|
3
3
|
export { DefaultTextExtractor, TextExtractor } from "./TextExtractor/index.js";
|
|
4
4
|
export { AiAfterGenerateTextEvent, AiAfterGenerateTextEventHandler, AiBeforeGenerateTextEvent, AiBeforeGenerateTextEventHandler, AiBeforeStreamTextEvent, AiBeforeStreamTextEventHandler, AiGenerateTextErrorEvent, AiGenerateTextErrorEventHandler } from "./events.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DateFormatter } from "./abstractions.js";
|
|
2
|
+
import type { FormattableDate } from "./abstractions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Default absolute date/time format: `YYYY-MM-DD HH:mm`, 24-hour, UTC. Built from UTC parts rather
|
|
5
|
+
* than `Intl.DateTimeFormat` so the output is fully deterministic — backend formatting must not
|
|
6
|
+
* depend on the server locale or the bundled ICU version. Projects can change it by decorating
|
|
7
|
+
* DateFormatter.
|
|
8
|
+
*/
|
|
9
|
+
declare class DefaultDateFormatterImpl implements DateFormatter.Interface {
|
|
10
|
+
format(date: FormattableDate): string;
|
|
11
|
+
}
|
|
12
|
+
export declare const DefaultDateFormatter: typeof DefaultDateFormatterImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IDateFormatter>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DateFormatter } from "./abstractions.js";
|
|
2
|
+
const pad = (value)=>String(value).padStart(2, "0");
|
|
3
|
+
class DefaultDateFormatterImpl {
|
|
4
|
+
format(date) {
|
|
5
|
+
const value = new Date(date);
|
|
6
|
+
const year = value.getUTCFullYear();
|
|
7
|
+
const month = pad(value.getUTCMonth() + 1);
|
|
8
|
+
const day = pad(value.getUTCDate());
|
|
9
|
+
const hours = pad(value.getUTCHours());
|
|
10
|
+
const minutes = pad(value.getUTCMinutes());
|
|
11
|
+
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const DefaultDateFormatter = DateFormatter.createImplementation({
|
|
15
|
+
implementation: DefaultDateFormatterImpl,
|
|
16
|
+
dependencies: []
|
|
17
|
+
});
|
|
18
|
+
export { DefaultDateFormatter };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=DefaultDateFormatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/dateFormatter/DefaultDateFormatter.js","sources":["../../../src/features/dateFormatter/DefaultDateFormatter.ts"],"sourcesContent":["import { DateFormatter } from \"./abstractions.js\";\nimport type { FormattableDate } from \"./abstractions.js\";\n\nconst pad = (value: number): string => {\n return String(value).padStart(2, \"0\");\n};\n\n/**\n * Default absolute date/time format: `YYYY-MM-DD HH:mm`, 24-hour, UTC. Built from UTC parts rather\n * than `Intl.DateTimeFormat` so the output is fully deterministic — backend formatting must not\n * depend on the server locale or the bundled ICU version. Projects can change it by decorating\n * DateFormatter.\n */\nclass DefaultDateFormatterImpl implements DateFormatter.Interface {\n format(date: FormattableDate): string {\n const value = new Date(date);\n const year = value.getUTCFullYear();\n const month = pad(value.getUTCMonth() + 1);\n const day = pad(value.getUTCDate());\n const hours = pad(value.getUTCHours());\n const minutes = pad(value.getUTCMinutes());\n return `${year}-${month}-${day} ${hours}:${minutes}`;\n }\n}\n\nexport const DefaultDateFormatter = DateFormatter.createImplementation({\n implementation: DefaultDateFormatterImpl,\n dependencies: []\n});\n"],"names":["pad","value","String","DefaultDateFormatterImpl","date","Date","year","month","day","hours","minutes","DefaultDateFormatter","DateFormatter"],"mappings":";AAGA,MAAMA,MAAM,CAACC,QACFC,OAAOD,OAAO,QAAQ,CAAC,GAAG;AASrC,MAAME;IACF,OAAOC,IAAqB,EAAU;QAClC,MAAMH,QAAQ,IAAII,KAAKD;QACvB,MAAME,OAAOL,MAAM,cAAc;QACjC,MAAMM,QAAQP,IAAIC,MAAM,WAAW,KAAK;QACxC,MAAMO,MAAMR,IAAIC,MAAM,UAAU;QAChC,MAAMQ,QAAQT,IAAIC,MAAM,WAAW;QACnC,MAAMS,UAAUV,IAAIC,MAAM,aAAa;QACvC,OAAO,GAAGK,KAAK,CAAC,EAAEC,MAAM,CAAC,EAAEC,IAAI,CAAC,EAAEC,MAAM,CAAC,EAAEC,SAAS;IACxD;AACJ;AAEO,MAAMC,uBAAuBC,cAAc,oBAAoB,CAAC;IACnE,gBAAgBT;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type FormattableDate = Date | string | number;
|
|
2
|
+
export interface IDateFormatter {
|
|
3
|
+
/**
|
|
4
|
+
* Formats an absolute date/time as a string using Webiny's default format. Change the format
|
|
5
|
+
* everywhere at once by decorating this abstraction.
|
|
6
|
+
*/
|
|
7
|
+
format(date: FormattableDate): string;
|
|
8
|
+
}
|
|
9
|
+
export declare const DateFormatter: import("@webiny/di").Abstraction<IDateFormatter>;
|
|
10
|
+
export declare namespace DateFormatter {
|
|
11
|
+
type Interface = IDateFormatter;
|
|
12
|
+
type Value = FormattableDate;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/dateFormatter/abstractions.js","sources":["../../../src/features/dateFormatter/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport type FormattableDate = Date | string | number;\n\nexport interface IDateFormatter {\n /**\n * Formats an absolute date/time as a string using Webiny's default format. Change the format\n * everywhere at once by decorating this abstraction.\n */\n format(date: FormattableDate): string;\n}\n\nexport const DateFormatter = createAbstraction<IDateFormatter>(\"DateFormatter\");\n\nexport namespace DateFormatter {\n export type Interface = IDateFormatter;\n export type Value = FormattableDate;\n}\n"],"names":["DateFormatter","createAbstraction"],"mappings":";AAYO,MAAMA,gBAAgBC,kBAAkC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { DefaultDateFormatter } from "./DefaultDateFormatter.js";
|
|
3
|
+
const DateFormatterFeature = createFeature({
|
|
4
|
+
name: "DateFormatterFeature",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(DefaultDateFormatter);
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { DateFormatterFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/dateFormatter/feature.js","sources":["../../../src/features/dateFormatter/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { DefaultDateFormatter } from \"./DefaultDateFormatter.js\";\n\nexport const DateFormatterFeature = createFeature({\n name: \"DateFormatterFeature\",\n register(container) {\n container.register(DefaultDateFormatter);\n }\n});\n"],"names":["DateFormatterFeature","createFeature","container","DefaultDateFormatter"],"mappings":";;AAGO,MAAMA,uBAAuBC,cAAc;IAC9C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register in the ROOT container. Encryption is registered again in every request container, so a
|
|
3
|
+
* cache registered there would start empty on each request and derive the key every time.
|
|
4
|
+
*/
|
|
5
|
+
export declare const EncryptionKeyCacheFeature: {
|
|
6
|
+
name: string;
|
|
7
|
+
register(container: import("@webiny/di").Container): void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { MemoryEncryptionKeyCache } from "./MemoryEncryptionKeyCache.js";
|
|
3
|
+
const EncryptionKeyCacheFeature = createFeature({
|
|
4
|
+
name: "EncryptionKeyCache",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(MemoryEncryptionKeyCache).inSingletonScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { EncryptionKeyCacheFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=EncryptionKeyCacheFeature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/encryption/EncryptionKeyCacheFeature.js","sources":["../../../src/features/encryption/EncryptionKeyCacheFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { MemoryEncryptionKeyCache } from \"./MemoryEncryptionKeyCache.js\";\n\n/**\n * Register in the ROOT container. Encryption is registered again in every request container, so a\n * cache registered there would start empty on each request and derive the key every time.\n */\nexport const EncryptionKeyCacheFeature = createFeature({\n name: \"EncryptionKeyCache\",\n register(container) {\n container.register(MemoryEncryptionKeyCache).inSingletonScope();\n }\n});\n"],"names":["EncryptionKeyCacheFeature","createFeature","container","MemoryEncryptionKeyCache"],"mappings":";;AAOO,MAAMA,4BAA4BC,cAAc;IACnD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,0BAA0B,gBAAgB;IACjE;AACJ"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Encryption as EncryptionAbstraction } from "./abstractions.js";
|
|
2
|
+
import { EncryptionKeyCache } from "./abstractions.js";
|
|
2
3
|
import { BuildParams } from "../buildParams/abstractions.js";
|
|
3
4
|
export declare class EncryptionImpl implements EncryptionAbstraction.Interface {
|
|
4
5
|
private key;
|
|
5
6
|
private algorithm;
|
|
6
|
-
constructor(buildParams: BuildParams.Interface);
|
|
7
|
+
constructor(buildParams: BuildParams.Interface, keyCache: EncryptionKeyCache.Interface | undefined);
|
|
7
8
|
encrypt(value: string): Promise<string>;
|
|
8
9
|
decrypt(value: string): Promise<string>;
|
|
9
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import node_crypto from "node:crypto";
|
|
2
2
|
import { createImplementation } from "@webiny/feature/api";
|
|
3
|
-
import { Encryption } from "./abstractions.js";
|
|
3
|
+
import { Encryption, EncryptionKeyCache } from "./abstractions.js";
|
|
4
4
|
import { BuildParams } from "../buildParams/abstractions.js";
|
|
5
5
|
const DEFAULT_ALGORITHM = "aes-256-gcm";
|
|
6
6
|
function keyLengthForAlgorithm(algorithm) {
|
|
@@ -9,13 +9,14 @@ function keyLengthForAlgorithm(algorithm) {
|
|
|
9
9
|
return bits / 8;
|
|
10
10
|
}
|
|
11
11
|
class EncryptionImpl {
|
|
12
|
-
constructor(buildParams){
|
|
12
|
+
constructor(buildParams, keyCache){
|
|
13
13
|
const passphrase = buildParams.get("EncryptionPassphrase");
|
|
14
14
|
if (passphrase) {
|
|
15
15
|
const salt = buildParams.get("EncryptionSalt") ?? "";
|
|
16
16
|
this.algorithm = buildParams.get("EncryptionAlgorithm") ?? DEFAULT_ALGORITHM;
|
|
17
17
|
const keyLength = keyLengthForAlgorithm(this.algorithm);
|
|
18
|
-
this.key =
|
|
18
|
+
if (keyCache) this.key = keyCache.getOrDerive(passphrase, salt, keyLength);
|
|
19
|
+
else this.key = node_crypto.scryptSync(passphrase, salt, keyLength);
|
|
19
20
|
} else {
|
|
20
21
|
this.key = null;
|
|
21
22
|
this.algorithm = DEFAULT_ALGORITHM;
|
|
@@ -54,7 +55,13 @@ const EncryptionService_Encryption = createImplementation({
|
|
|
54
55
|
abstraction: Encryption,
|
|
55
56
|
implementation: EncryptionImpl,
|
|
56
57
|
dependencies: [
|
|
57
|
-
BuildParams
|
|
58
|
+
BuildParams,
|
|
59
|
+
[
|
|
60
|
+
EncryptionKeyCache,
|
|
61
|
+
{
|
|
62
|
+
optional: true
|
|
63
|
+
}
|
|
64
|
+
]
|
|
58
65
|
]
|
|
59
66
|
});
|
|
60
67
|
export { EncryptionImpl, EncryptionService_Encryption as Encryption };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/encryption/EncryptionService.js","sources":["../../../src/features/encryption/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 async encrypt(value: string): Promise<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 async decrypt(value: string): Promise<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"],"names":["DEFAULT_ALGORITHM","keyLengthForAlgorithm","algorithm","bits","parseInt","isNaN","Error","EncryptionImpl","buildParams","passphrase","salt","keyLength","crypto","value","iv","cipher","encrypted","Buffer","authTag","data","ciphertext","decipher","Encryption","createImplementation","EncryptionAbstraction","BuildParams"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"features/encryption/EncryptionService.js","sources":["../../../src/features/encryption/EncryptionService.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport { createImplementation } from \"@webiny/feature/api\";\nimport { Encryption as EncryptionAbstraction } from \"./abstractions.js\";\nimport { EncryptionKeyCache } 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(\n buildParams: BuildParams.Interface,\n // Registered in the root container, so the derived key outlives the request. Without it (in\n // tests, for example) the key is derived for every instance.\n keyCache: EncryptionKeyCache.Interface | undefined\n ) {\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 if (keyCache) {\n this.key = keyCache.getOrDerive(passphrase, salt, keyLength);\n } else {\n this.key = crypto.scryptSync(passphrase, salt, keyLength);\n }\n } else {\n this.key = null;\n this.algorithm = DEFAULT_ALGORITHM;\n }\n }\n\n async encrypt(value: string): Promise<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 async decrypt(value: string): Promise<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, [EncryptionKeyCache, { optional: true }]]\n});\n"],"names":["DEFAULT_ALGORITHM","keyLengthForAlgorithm","algorithm","bits","parseInt","isNaN","Error","EncryptionImpl","buildParams","keyCache","passphrase","salt","keyLength","crypto","value","iv","cipher","encrypted","Buffer","authTag","data","ciphertext","decipher","Encryption","createImplementation","EncryptionAbstraction","BuildParams","EncryptionKeyCache"],"mappings":";;;;AAMA,MAAMA,oBAAoB;AAE1B,SAASC,sBAAsBC,SAAiB;IAE5C,MAAMC,OAAOC,SAASF,UAAU,KAAK,CAAC,IAAI,CAAC,EAAE;IAC7C,IAAIG,MAAMF,OACN,MAAM,IAAIG,MAAM,CAAC,4CAA4C,EAAEJ,UAAU,EAAE,CAAC;IAEhF,OAAOC,OAAO;AAClB;AAEO,MAAMI;IAIT,YACIC,WAAkC,EAGlCC,QAAkD,CACpD;QACE,MAAMC,aAAaF,YAAY,GAAG,CAAS;QAE3C,IAAIE,YAAY;YAGZ,MAAMC,OAAOH,YAAY,GAAG,CAAS,qBAAqB;YAC1D,IAAI,CAAC,SAAS,GAAGA,YAAY,GAAG,CAAS,0BAA0BR;YACnE,MAAMY,YAAYX,sBAAsB,IAAI,CAAC,SAAS;YACtD,IAAIQ,UACA,IAAI,CAAC,GAAG,GAAGA,SAAS,WAAW,CAACC,YAAYC,MAAMC;iBAElD,IAAI,CAAC,GAAG,GAAGC,YAAAA,UAAiB,CAACH,YAAYC,MAAMC;QAEvD,OAAO;YACH,IAAI,CAAC,GAAG,GAAG;YACX,IAAI,CAAC,SAAS,GAAGZ;QACrB;IACJ;IAEA,MAAM,QAAQc,KAAa,EAAmB;QAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,EACT,OAAOA;QAEX,MAAMC,KAAKF,YAAAA,WAAkB,CAAC;QAC9B,MAAMG,SAASH,YAAAA,cAAqB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAEE;QAC/D,MAAME,YAAYC,OAAO,MAAM,CAAC;YAACF,OAAO,MAAM,CAACF,OAAO;YAASE,OAAO,KAAK;SAAG;QAC9E,MAAMG,UAAWH,OAA4B,UAAU;QACvD,OAAOE,OAAO,MAAM,CAAC;YAACH;YAAII;YAASF;SAAU,EAAE,QAAQ,CAAC;IAC5D;IAEA,MAAM,QAAQH,KAAa,EAAmB;QAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,EACT,OAAOA;QAEX,MAAMM,OAAOF,OAAO,IAAI,CAACJ,OAAO;QAChC,MAAMC,KAAKK,KAAK,QAAQ,CAAC,GAAG;QAC5B,MAAMD,UAAUC,KAAK,QAAQ,CAAC,IAAI;QAClC,MAAMC,aAAaD,KAAK,QAAQ,CAAC;QACjC,MAAME,WAAWT,YAAAA,gBAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAEE;QAClEO,SAAgC,UAAU,CAACH;QAC5C,OAAOD,OAAO,MAAM,CAAC;YAACI,SAAS,MAAM,CAACD;YAAaC,SAAS,KAAK;SAAG,EAAE,QAAQ,CAAC;IACnF;AACJ;AAEO,MAAMC,+BAAaC,qBAAqB;IAC3C,aAAaC;IACb,gBAAgBlB;IAChB,cAAc;QAACmB;QAAa;YAACC;YAAoB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACzE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EncryptionKeyCache as Abstraction } from "./abstractions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Keeps every derived key for the life of the container. Keys depend only on build params, so a
|
|
4
|
+
* process holds one or two at most.
|
|
5
|
+
*/
|
|
6
|
+
declare class MemoryEncryptionKeyCacheImpl implements Abstraction.Interface {
|
|
7
|
+
private readonly keys;
|
|
8
|
+
getOrDerive(passphrase: string, salt: string, keyLength: number): Buffer;
|
|
9
|
+
}
|
|
10
|
+
export declare const MemoryEncryptionKeyCache: typeof MemoryEncryptionKeyCacheImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IEncryptionKeyCache>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import node_crypto from "node:crypto";
|
|
2
|
+
import { EncryptionKeyCache } from "./abstractions.js";
|
|
3
|
+
class MemoryEncryptionKeyCacheImpl {
|
|
4
|
+
getOrDerive(passphrase, salt, keyLength) {
|
|
5
|
+
const cacheKey = JSON.stringify([
|
|
6
|
+
passphrase,
|
|
7
|
+
salt,
|
|
8
|
+
keyLength
|
|
9
|
+
]);
|
|
10
|
+
const cached = this.keys.get(cacheKey);
|
|
11
|
+
if (cached) return cached;
|
|
12
|
+
const key = node_crypto.scryptSync(passphrase, salt, keyLength);
|
|
13
|
+
this.keys.set(cacheKey, key);
|
|
14
|
+
return key;
|
|
15
|
+
}
|
|
16
|
+
constructor(){
|
|
17
|
+
this.keys = new Map();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const MemoryEncryptionKeyCache = EncryptionKeyCache.createImplementation({
|
|
21
|
+
implementation: MemoryEncryptionKeyCacheImpl,
|
|
22
|
+
dependencies: []
|
|
23
|
+
});
|
|
24
|
+
export { MemoryEncryptionKeyCache };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=MemoryEncryptionKeyCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/encryption/MemoryEncryptionKeyCache.js","sources":["../../../src/features/encryption/MemoryEncryptionKeyCache.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport { EncryptionKeyCache as Abstraction } from \"./abstractions.js\";\n\n/**\n * Keeps every derived key for the life of the container. Keys depend only on build params, so a\n * process holds one or two at most.\n */\nclass MemoryEncryptionKeyCacheImpl implements Abstraction.Interface {\n private readonly keys = new Map<string, Buffer>();\n\n public getOrDerive(passphrase: string, salt: string, keyLength: number): Buffer {\n const cacheKey = JSON.stringify([passphrase, salt, keyLength]);\n const cached = this.keys.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n const key = crypto.scryptSync(passphrase, salt, keyLength);\n this.keys.set(cacheKey, key);\n return key;\n }\n}\n\nexport const MemoryEncryptionKeyCache = Abstraction.createImplementation({\n implementation: MemoryEncryptionKeyCacheImpl,\n dependencies: []\n});\n"],"names":["MemoryEncryptionKeyCacheImpl","passphrase","salt","keyLength","cacheKey","JSON","cached","key","crypto","Map","MemoryEncryptionKeyCache","Abstraction"],"mappings":";;AAOA,MAAMA;IAGK,YAAYC,UAAkB,EAAEC,IAAY,EAAEC,SAAiB,EAAU;QAC5E,MAAMC,WAAWC,KAAK,SAAS,CAAC;YAACJ;YAAYC;YAAMC;SAAU;QAC7D,MAAMG,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG,CAACF;QAC7B,IAAIE,QACA,OAAOA;QAGX,MAAMC,MAAMC,YAAAA,UAAiB,CAACP,YAAYC,MAAMC;QAChD,IAAI,CAAC,IAAI,CAAC,GAAG,CAACC,UAAUG;QACxB,OAAOA;IACX;;aAZiB,IAAI,GAAG,IAAIE;;AAahC;AAEO,MAAMC,2BAA2BC,mBAAAA,oBAAgC,CAAC;IACrE,gBAAgBX;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -7,3 +7,14 @@ export declare const Encryption: import("@webiny/di").Abstraction<IEncryption>;
|
|
|
7
7
|
export declare namespace Encryption {
|
|
8
8
|
type Interface = IEncryption;
|
|
9
9
|
}
|
|
10
|
+
export interface IEncryptionKeyCache {
|
|
11
|
+
getOrDerive(passphrase: string, salt: string, keyLength: number): Buffer;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Derives encryption keys and keeps them. Deriving a key runs scrypt, which costs tens of
|
|
15
|
+
* milliseconds of CPU on purpose, so the key is derived once instead of on every request.
|
|
16
|
+
*/
|
|
17
|
+
export declare const EncryptionKeyCache: import("@webiny/di").Abstraction<IEncryptionKeyCache>;
|
|
18
|
+
export declare namespace EncryptionKeyCache {
|
|
19
|
+
type Interface = IEncryptionKeyCache;
|
|
20
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createAbstraction } from "@webiny/feature/api";
|
|
2
2
|
const Encryption = createAbstraction("Encryption");
|
|
3
|
-
|
|
3
|
+
const EncryptionKeyCache = createAbstraction("EncryptionKeyCache");
|
|
4
|
+
export { Encryption, EncryptionKeyCache };
|
|
4
5
|
|
|
5
6
|
//# sourceMappingURL=abstractions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/encryption/abstractions.js","sources":["../../../src/features/encryption/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IEncryption {\n encrypt(value: string): Promise<string>;\n decrypt(value: string): Promise<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"],"names":["Encryption","createAbstraction"],"mappings":";AAQO,MAAMA,aAAaC,kBAA+B"}
|
|
1
|
+
{"version":3,"file":"features/encryption/abstractions.js","sources":["../../../src/features/encryption/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IEncryption {\n encrypt(value: string): Promise<string>;\n decrypt(value: string): Promise<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\nexport interface IEncryptionKeyCache {\n getOrDerive(passphrase: string, salt: string, keyLength: number): Buffer;\n}\n\n/**\n * Derives encryption keys and keeps them. Deriving a key runs scrypt, which costs tens of\n * milliseconds of CPU on purpose, so the key is derived once instead of on every request.\n */\nexport const EncryptionKeyCache = createAbstraction<IEncryptionKeyCache>(\"EncryptionKeyCache\");\n\nexport namespace EncryptionKeyCache {\n export type Interface = IEncryptionKeyCache;\n}\n"],"names":["Encryption","createAbstraction","EncryptionKeyCache"],"mappings":";AAQO,MAAMA,aAAaC,kBAA+B;AAclD,MAAMC,qBAAqBD,kBAAuC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FeatureFlags } from "../abstractions.js";
|
|
2
|
+
import { FeatureFlags as FeatureFlagsClass } from "@webiny/feature-flags";
|
|
3
|
+
import { WcpLicenseProvider } from "../../../features/wcp/WcpLicenseProvider.js";
|
|
4
|
+
declare class FeatureFlagsWithLicenseDecoratorImpl implements FeatureFlags.Interface {
|
|
5
|
+
private licenseProvider;
|
|
6
|
+
private decoratee;
|
|
7
|
+
constructor(licenseProvider: WcpLicenseProvider.Interface, decoratee: FeatureFlags.Interface);
|
|
8
|
+
get(): FeatureFlagsClass;
|
|
9
|
+
}
|
|
10
|
+
export declare const FeatureFlagsWithLicenseDecorator: typeof FeatureFlagsWithLicenseDecoratorImpl & {
|
|
11
|
+
__abstraction: import("@webiny/di").Abstraction<import("../abstractions.js").IFeatureFlagsAbstraction>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|