@webiny/api-core 0.0.0-unstable.0d717d18dd → 0.0.0-unstable.33e4fd9647
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 +12 -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/debugger/Debugger.d.ts +30 -0
- package/features/debugger/Debugger.js +142 -0
- package/features/debugger/Debugger.js.map +1 -0
- package/features/debugger/DebuggerRouteDecorator.d.ts +45 -0
- package/features/debugger/DebuggerRouteDecorator.js +107 -0
- package/features/debugger/DebuggerRouteDecorator.js.map +1 -0
- package/features/debugger/GraphQLDebuggerTransport.d.ts +28 -0
- package/features/debugger/GraphQLDebuggerTransport.js +45 -0
- package/features/debugger/GraphQLDebuggerTransport.js.map +1 -0
- package/features/debugger/__tests__/matchNamespace.test.d.ts +1 -0
- package/features/debugger/__tests__/matchNamespace.test.js +68 -0
- package/features/debugger/__tests__/matchNamespace.test.js.map +1 -0
- package/features/debugger/__tests__/serialize.test.d.ts +1 -0
- package/features/debugger/__tests__/serialize.test.js +220 -0
- package/features/debugger/__tests__/serialize.test.js.map +1 -0
- package/features/debugger/abstractions.d.ts +100 -0
- package/features/debugger/abstractions.js +6 -0
- package/features/debugger/abstractions.js.map +1 -0
- package/features/debugger/feature.d.ts +5 -0
- package/features/debugger/feature.js +15 -0
- package/features/debugger/feature.js.map +1 -0
- package/features/debugger/index.d.ts +12 -0
- package/features/debugger/index.js +7 -0
- package/features/debugger/limits.d.ts +18 -0
- package/features/debugger/limits.js +11 -0
- package/features/debugger/limits.js.map +1 -0
- package/features/debugger/matchNamespace.d.ts +14 -0
- package/features/debugger/matchNamespace.js +35 -0
- package/features/debugger/matchNamespace.js.map +1 -0
- package/features/debugger/parseNamespaceHeader.d.ts +7 -0
- package/features/debugger/parseNamespaceHeader.js +16 -0
- package/features/debugger/parseNamespaceHeader.js.map +1 -0
- package/features/debugger/permissions.d.ts +14 -0
- package/features/debugger/permissions.js +8 -0
- package/features/debugger/permissions.js.map +1 -0
- package/features/debugger/permissionsSchema.d.ts +17 -0
- package/features/debugger/permissionsSchema.js +18 -0
- package/features/debugger/permissionsSchema.js.map +1 -0
- package/features/debugger/serialize.d.ts +11 -0
- package/features/debugger/serialize.js +121 -0
- package/features/debugger/serialize.js.map +1 -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 +62 -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/keyValueStore/GlobalKeyValueStore.d.ts +9 -3
- package/features/keyValueStore/GlobalKeyValueStore.js +12 -2
- package/features/keyValueStore/GlobalKeyValueStore.js.map +1 -1
- package/features/keyValueStore/KeyValueStore.d.ts +6 -2
- package/features/keyValueStore/KeyValueStore.js +13 -3
- package/features/keyValueStore/KeyValueStore.js.map +1 -1
- package/features/keyValueStore/KeyValueStoreRepository.d.ts +8 -2
- package/features/keyValueStore/KeyValueStoreRepository.js +82 -4
- package/features/keyValueStore/KeyValueStoreRepository.js.map +1 -1
- package/features/keyValueStore/abstractions.d.ts +132 -14
- package/features/keyValueStore/abstractions.js.map +1 -1
- package/features/keyValueStore/errors.d.ts +29 -0
- package/features/keyValueStore/errors.js +49 -1
- package/features/keyValueStore/errors.js.map +1 -1
- package/features/keyValueStore/index.d.ts +4 -1
- package/features/keyValueStore/index.js +1 -1
- package/features/publicUrls/NullPublicUrls.d.ts +11 -0
- package/features/publicUrls/NullPublicUrls.js +17 -0
- package/features/publicUrls/NullPublicUrls.js.map +1 -0
- package/features/publicUrls/PublicUrl.d.ts +24 -0
- package/features/publicUrls/PublicUrl.js +43 -0
- package/features/publicUrls/PublicUrl.js.map +1 -0
- package/features/publicUrls/__tests__/PublicUrl.test.d.ts +1 -0
- package/features/publicUrls/__tests__/PublicUrl.test.js +38 -0
- package/features/publicUrls/__tests__/PublicUrl.test.js.map +1 -0
- package/features/publicUrls/__tests__/PublicUrls.test.d.ts +1 -0
- package/features/publicUrls/__tests__/PublicUrls.test.js +14 -0
- package/features/publicUrls/__tests__/PublicUrls.test.js.map +1 -0
- package/features/publicUrls/abstractions.d.ts +27 -0
- package/features/publicUrls/abstractions.js +5 -0
- package/features/publicUrls/abstractions.js.map +1 -0
- package/features/publicUrls/feature.d.ts +8 -0
- package/features/publicUrls/feature.js +11 -0
- package/features/publicUrls/feature.js.map +1 -0
- package/features/publicUrls/index.d.ts +3 -0
- package/features/publicUrls/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/Installer/RolesInstaller.js +1 -0
- package/features/security/roles/Installer/RolesInstaller.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 +7 -0
- package/features/wcp/WcpContext/WcpContext.js +21 -0
- package/features/wcp/WcpContext/WcpContext.js.map +1 -1
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.d.ts +10 -69
- package/features/wcp/WcpContext/decorators/WcpContextWithFeatureFlagsDecorator.js +66 -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
|
@@ -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 {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FeatureFlags } from "../abstractions.js";
|
|
2
|
+
import { FeatureFlags as feature_flags_FeatureFlags } from "@webiny/feature-flags";
|
|
3
|
+
import { WcpLicenseProvider } from "../../wcp/WcpLicenseProvider.js";
|
|
4
|
+
const LICENSE_CHECKS = {
|
|
5
|
+
multiTenancy: (l)=>l.canUseFeature("multiTenancy"),
|
|
6
|
+
languages: (l)=>l.canUseLanguages(),
|
|
7
|
+
advancedPublishingWorkflow: (l)=>l.canUseWorkflows(),
|
|
8
|
+
advancedAccessControlLayer: (l)=>l.canUseAacl(),
|
|
9
|
+
"advancedAccessControlLayer.teams": (l)=>l.canUseTeams(),
|
|
10
|
+
"advancedAccessControlLayer.privateFiles": (l)=>l.canUsePrivateFiles(),
|
|
11
|
+
"advancedAccessControlLayer.folderLevelPermissions": (l)=>l.canUseFolderLevelPermissions(),
|
|
12
|
+
"advancedAccessControlLayer.hcmsFieldPermissions": (l)=>l.canUseHcmsFieldPermissions(),
|
|
13
|
+
auditLogs: (l)=>l.canUseAuditLogs(),
|
|
14
|
+
recordLocking: (l)=>l.canUseRecordLocking(),
|
|
15
|
+
"fileManager.threatDetection": (l)=>l.canUseFileManagerThreatDetection(),
|
|
16
|
+
aiPowerups: (l)=>l.canUseAiPowerups(),
|
|
17
|
+
"aiPowerups.fileManager.imageEnrichment": (l)=>l.canUseAiImageEnrichment(),
|
|
18
|
+
"aiPowerups.websiteBuilder.pageGeneration": (l)=>l.canUseAiPageGeneration(),
|
|
19
|
+
"aiPowerups.websiteBuilder.pageTranslation": (l)=>l.canUseAiPageTranslation(),
|
|
20
|
+
"aiPowerups.lexicalGeneration": (l)=>l.canUseAiLexicalGeneration(),
|
|
21
|
+
"aiPowerups.adminAssistant": (l)=>l.canUseAiAdminAssistant(),
|
|
22
|
+
"aiPowerups.remoteComponents": (l)=>l.canUseRemoteComponents(),
|
|
23
|
+
"aiPowerups.cms.entryGeneration": (l)=>l.canUseAiEntryGeneration(),
|
|
24
|
+
"aiPowerups.cms.entryComparison": (l)=>l.canUseAiEntryComparison(),
|
|
25
|
+
"aiPowerups.cms.entryTranslation": (l)=>l.canUseAiEntryTranslation(),
|
|
26
|
+
abTesting: (l)=>l.canUseAbTesting(),
|
|
27
|
+
collaboration: (l)=>l.canUseCollaboration(),
|
|
28
|
+
"collaboration.comments": (l)=>l.canUseComments(),
|
|
29
|
+
"collaboration.activityLog": (l)=>l.canUseActivityLog()
|
|
30
|
+
};
|
|
31
|
+
class LicenseDecoratedFeatureFlags extends feature_flags_FeatureFlags {
|
|
32
|
+
constructor(base, license){
|
|
33
|
+
super(base.toDto()), this.base = base, this.license = license;
|
|
34
|
+
}
|
|
35
|
+
isEnabled(name) {
|
|
36
|
+
const check = LICENSE_CHECKS[name];
|
|
37
|
+
if (check) {
|
|
38
|
+
if (!check(this.license)) return false;
|
|
39
|
+
return !this.base.isExplicitlyDisabled(name);
|
|
40
|
+
}
|
|
41
|
+
return this.base.isEnabled(name);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class FeatureFlagsWithLicenseDecoratorImpl {
|
|
45
|
+
constructor(licenseProvider, decoratee){
|
|
46
|
+
this.licenseProvider = licenseProvider;
|
|
47
|
+
this.decoratee = decoratee;
|
|
48
|
+
}
|
|
49
|
+
get() {
|
|
50
|
+
const base = this.decoratee.get();
|
|
51
|
+
return new LicenseDecoratedFeatureFlags(base, this.licenseProvider.get());
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const FeatureFlagsWithLicenseDecorator = FeatureFlags.createDecorator({
|
|
55
|
+
decorator: FeatureFlagsWithLicenseDecoratorImpl,
|
|
56
|
+
dependencies: [
|
|
57
|
+
WcpLicenseProvider
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
export { FeatureFlagsWithLicenseDecorator };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=FeatureFlagsWithLicenseDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.js","sources":["../../../../src/features/featureFlags/decorators/FeatureFlagsWithLicenseDecorator.ts"],"sourcesContent":["import { FeatureFlags } from \"../abstractions.js\";\nimport { FeatureFlags as FeatureFlagsClass } from \"@webiny/feature-flags\";\nimport type { FeatureFlagName } from \"@webiny/feature-flags\";\nimport type { ILicense } from \"@webiny/wcp/types.js\";\nimport { WcpLicenseProvider } from \"~/features/wcp/WcpLicenseProvider.js\";\n\n/*\n * Feature flag resolution (license decorator).\n *\n * Two kinds of flag, and only one of them is Webiny's to sell:\n *\n * LICENSE-GOVERNED (listed in LICENSE_CHECKS) — the license is the authority:\n * 1. No license, or license blocks the flag → false, config ignored\n * 2. License allows + config unset → true (the license grants it)\n * 3. License allows + config=false → false (config may disable, never re-enable)\n *\n * EVERYTHING ELSE — the project's own flags. The config decides, and nothing is assumed:\n * 4. config=true → true\n * 5. config=false or unset → false\n *\n * There is deliberately no third kind. A set of flags used to be enabled by default here, which was\n * a workaround for capabilities the license could not express: rather than gate them properly they\n * were left on for anyone holding any license at all. It also meant EVERY unrecognised name resolved\n * to true, so an undeclared flag and a typo both read as enabled. A feature that should be sold\n * belongs in LICENSE_CHECKS and on the license; anything else is the project's own to switch on.\n */\n\nconst LICENSE_CHECKS: Record<string, (license: ILicense) => boolean> = {\n multiTenancy: l => l.canUseFeature(\"multiTenancy\"),\n languages: l => l.canUseLanguages(),\n advancedPublishingWorkflow: l => l.canUseWorkflows(),\n advancedAccessControlLayer: l => l.canUseAacl(),\n \"advancedAccessControlLayer.teams\": l => l.canUseTeams(),\n \"advancedAccessControlLayer.privateFiles\": l => l.canUsePrivateFiles(),\n \"advancedAccessControlLayer.folderLevelPermissions\": l => l.canUseFolderLevelPermissions(),\n \"advancedAccessControlLayer.hcmsFieldPermissions\": l => l.canUseHcmsFieldPermissions(),\n auditLogs: l => l.canUseAuditLogs(),\n recordLocking: l => l.canUseRecordLocking(),\n \"fileManager.threatDetection\": l => l.canUseFileManagerThreatDetection(),\n aiPowerups: l => l.canUseAiPowerups(),\n \"aiPowerups.fileManager.imageEnrichment\": l => l.canUseAiImageEnrichment(),\n \"aiPowerups.websiteBuilder.pageGeneration\": l => l.canUseAiPageGeneration(),\n \"aiPowerups.websiteBuilder.pageTranslation\": l => l.canUseAiPageTranslation(),\n \"aiPowerups.lexicalGeneration\": l => l.canUseAiLexicalGeneration(),\n \"aiPowerups.adminAssistant\": l => l.canUseAiAdminAssistant(),\n \"aiPowerups.remoteComponents\": l => l.canUseRemoteComponents(),\n \"aiPowerups.cms.entryGeneration\": l => l.canUseAiEntryGeneration(),\n \"aiPowerups.cms.entryComparison\": l => l.canUseAiEntryComparison(),\n \"aiPowerups.cms.entryTranslation\": l => l.canUseAiEntryTranslation(),\n abTesting: l => l.canUseAbTesting(),\n collaboration: l => l.canUseCollaboration(),\n \"collaboration.comments\": l => l.canUseComments(),\n \"collaboration.activityLog\": l => l.canUseActivityLog()\n};\n\nclass LicenseDecoratedFeatureFlags extends FeatureFlagsClass {\n constructor(\n private base: FeatureFlagsClass,\n private license: ILicense\n ) {\n super(base.toDto());\n }\n\n override isEnabled(name: FeatureFlagName): boolean {\n const check = LICENSE_CHECKS[name];\n if (check) {\n if (!check(this.license)) {\n return false;\n }\n // License allows — config can only disable, not re-enable blocked features.\n return !this.base.isExplicitlyDisabled(name);\n }\n /*\n * Everything else is the project's own, and the config is the only thing that decides. No\n * default: `isEnabled` on the base is true only for an explicitly configured `true`.\n *\n * This branch used to return `!isExplicitlyDisabled(name)` whenever a license existed, which\n * made EVERY unrecognised name true — an undeclared flag, or a typo like `aiPowerupz`. It also\n * returned false outright without a license, so an unlicensed install could not turn on a flag\n * it had declared itself. Neither is the license's business.\n */\n return this.base.isEnabled(name);\n }\n}\n\nclass FeatureFlagsWithLicenseDecoratorImpl implements FeatureFlags.Interface {\n constructor(\n private licenseProvider: WcpLicenseProvider.Interface,\n private decoratee: FeatureFlags.Interface\n ) {}\n\n get(): FeatureFlagsClass {\n const base = this.decoratee.get();\n return new LicenseDecoratedFeatureFlags(base, this.licenseProvider.get());\n }\n}\n\nexport const FeatureFlagsWithLicenseDecorator = FeatureFlags.createDecorator({\n decorator: FeatureFlagsWithLicenseDecoratorImpl,\n dependencies: [WcpLicenseProvider]\n});\n"],"names":["LICENSE_CHECKS","l","LicenseDecoratedFeatureFlags","FeatureFlagsClass","base","license","name","check","FeatureFlagsWithLicenseDecoratorImpl","licenseProvider","decoratee","FeatureFlagsWithLicenseDecorator","FeatureFlags","WcpLicenseProvider"],"mappings":";;;AA2BA,MAAMA,iBAAiE;IACnE,cAAcC,CAAAA,IAAKA,EAAE,aAAa,CAAC;IACnC,WAAWA,CAAAA,IAAKA,EAAE,eAAe;IACjC,4BAA4BA,CAAAA,IAAKA,EAAE,eAAe;IAClD,4BAA4BA,CAAAA,IAAKA,EAAE,UAAU;IAC7C,oCAAoCA,CAAAA,IAAKA,EAAE,WAAW;IACtD,2CAA2CA,CAAAA,IAAKA,EAAE,kBAAkB;IACpE,qDAAqDA,CAAAA,IAAKA,EAAE,4BAA4B;IACxF,mDAAmDA,CAAAA,IAAKA,EAAE,0BAA0B;IACpF,WAAWA,CAAAA,IAAKA,EAAE,eAAe;IACjC,eAAeA,CAAAA,IAAKA,EAAE,mBAAmB;IACzC,+BAA+BA,CAAAA,IAAKA,EAAE,gCAAgC;IACtE,YAAYA,CAAAA,IAAKA,EAAE,gBAAgB;IACnC,0CAA0CA,CAAAA,IAAKA,EAAE,uBAAuB;IACxE,4CAA4CA,CAAAA,IAAKA,EAAE,sBAAsB;IACzE,6CAA6CA,CAAAA,IAAKA,EAAE,uBAAuB;IAC3E,gCAAgCA,CAAAA,IAAKA,EAAE,yBAAyB;IAChE,6BAA6BA,CAAAA,IAAKA,EAAE,sBAAsB;IAC1D,+BAA+BA,CAAAA,IAAKA,EAAE,sBAAsB;IAC5D,kCAAkCA,CAAAA,IAAKA,EAAE,uBAAuB;IAChE,kCAAkCA,CAAAA,IAAKA,EAAE,uBAAuB;IAChE,mCAAmCA,CAAAA,IAAKA,EAAE,wBAAwB;IAClE,WAAWA,CAAAA,IAAKA,EAAE,eAAe;IACjC,eAAeA,CAAAA,IAAKA,EAAE,mBAAmB;IACzC,0BAA0BA,CAAAA,IAAKA,EAAE,cAAc;IAC/C,6BAA6BA,CAAAA,IAAKA,EAAE,iBAAiB;AACzD;AAEA,MAAMC,qCAAqCC;IACvC,YACYC,IAAuB,EACvBC,OAAiB,CAC3B;QACE,KAAK,CAACD,KAAK,KAAK,UAHRA,IAAI,GAAJA,MAAAA,IAAAA,CACAC,OAAO,GAAPA;IAGZ;IAES,UAAUC,IAAqB,EAAW;QAC/C,MAAMC,QAAQP,cAAc,CAACM,KAAK;QAClC,IAAIC,OAAO;YACP,IAAI,CAACA,MAAM,IAAI,CAAC,OAAO,GACnB,OAAO;YAGX,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAACD;QAC3C;QAUA,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAACA;IAC/B;AACJ;AAEA,MAAME;IACF,YACYC,eAA6C,EAC7CC,SAAiC,CAC3C;aAFUD,eAAe,GAAfA;aACAC,SAAS,GAATA;IACT;IAEH,MAAyB;QACrB,MAAMN,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG;QAC/B,OAAO,IAAIF,6BAA6BE,MAAM,IAAI,CAAC,eAAe,CAAC,GAAG;IAC1E;AACJ;AAEO,MAAMO,mCAAmCC,aAAa,eAAe,CAAC;IACzE,WAAWJ;IACX,cAAc;QAACK;KAAmB;AACtC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Result } from "@webiny/feature/api";
|
|
2
|
+
import { HttpClient as HttpClientAbstraction } from "./abstractions.js";
|
|
3
|
+
declare class HttpClientImpl implements HttpClientAbstraction.Interface {
|
|
4
|
+
requestJson(request: HttpClientAbstraction.Request): Promise<Result<unknown, HttpClientAbstraction.Error>>;
|
|
5
|
+
}
|
|
6
|
+
export declare const HttpClient: import("@webiny/di").Implementation<typeof HttpClientImpl>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
|
+
import { HttpClient } from "./abstractions.js";
|
|
3
|
+
import { HttpRequestError } from "./HttpRequestError.js";
|
|
4
|
+
import { HttpStatusError } from "./HttpStatusError.js";
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 10000;
|
|
6
|
+
function createRequestInit(request) {
|
|
7
|
+
const timeoutMs = request.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
8
|
+
const headers = new Headers(request.headers);
|
|
9
|
+
const init = {
|
|
10
|
+
method: request.method ?? "GET",
|
|
11
|
+
headers,
|
|
12
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
13
|
+
};
|
|
14
|
+
if (void 0 !== request.body) {
|
|
15
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
16
|
+
init.body = JSON.stringify(request.body);
|
|
17
|
+
}
|
|
18
|
+
return init;
|
|
19
|
+
}
|
|
20
|
+
function isTimeout(error) {
|
|
21
|
+
return error instanceof Error && "TimeoutError" === error.name;
|
|
22
|
+
}
|
|
23
|
+
function parseJson(text) {
|
|
24
|
+
if ("" === text) return Result.ok(void 0);
|
|
25
|
+
try {
|
|
26
|
+
const value = JSON.parse(text);
|
|
27
|
+
return Result.ok(value);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return Result.fail(error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class HttpClientImpl {
|
|
33
|
+
async requestJson(request) {
|
|
34
|
+
const { url } = request;
|
|
35
|
+
const init = createRequestInit(request);
|
|
36
|
+
let response;
|
|
37
|
+
let text;
|
|
38
|
+
try {
|
|
39
|
+
response = await fetch(url, init);
|
|
40
|
+
text = await response.text();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
const reason = isTimeout(error) ? "timeout" : "network";
|
|
43
|
+
return Result.fail(new HttpRequestError({
|
|
44
|
+
url,
|
|
45
|
+
reason
|
|
46
|
+
}, error));
|
|
47
|
+
}
|
|
48
|
+
const body = parseJson(text);
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
const statusError = new HttpStatusError({
|
|
51
|
+
url,
|
|
52
|
+
status: response.status,
|
|
53
|
+
statusText: response.statusText,
|
|
54
|
+
body: body.isOk() ? body.value : void 0
|
|
55
|
+
});
|
|
56
|
+
return Result.fail(statusError);
|
|
57
|
+
}
|
|
58
|
+
if (body.isFail()) return Result.fail(new HttpRequestError({
|
|
59
|
+
url,
|
|
60
|
+
reason: "invalidJson"
|
|
61
|
+
}, body.error));
|
|
62
|
+
return Result.ok(body.value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const HttpClient_HttpClient = createImplementation({
|
|
66
|
+
abstraction: HttpClient,
|
|
67
|
+
implementation: HttpClientImpl,
|
|
68
|
+
dependencies: []
|
|
69
|
+
});
|
|
70
|
+
export { HttpClient_HttpClient as HttpClient };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=HttpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/httpClient/HttpClient.js","sources":["../../../src/features/httpClient/HttpClient.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { HttpClient as HttpClientAbstraction } from \"./abstractions.js\";\nimport { HttpRequestError } from \"./HttpRequestError.js\";\nimport { HttpStatusError } from \"./HttpStatusError.js\";\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\nfunction createRequestInit(request: HttpClientAbstraction.Request): RequestInit {\n const timeoutMs = request.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const headers = new Headers(request.headers);\n const init: RequestInit = {\n method: request.method ?? \"GET\",\n headers,\n signal: AbortSignal.timeout(timeoutMs)\n };\n\n if (request.body !== undefined) {\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n init.body = JSON.stringify(request.body);\n }\n\n return init;\n}\n\nfunction isTimeout(error: unknown): boolean {\n return error instanceof Error && error.name === \"TimeoutError\";\n}\n\n// An empty body parses to `undefined`, so a 204 is not an invalid response.\nfunction parseJson(text: string): Result<unknown, unknown> {\n if (text === \"\") {\n return Result.ok(undefined);\n }\n try {\n const value: unknown = JSON.parse(text);\n return Result.ok(value);\n } catch (error) {\n return Result.fail(error);\n }\n}\n\nclass HttpClientImpl implements HttpClientAbstraction.Interface {\n async requestJson(\n request: HttpClientAbstraction.Request\n ): Promise<Result<unknown, HttpClientAbstraction.Error>> {\n const { url } = request;\n const init = createRequestInit(request);\n\n let response: Response;\n let text: string;\n try {\n response = await fetch(url, init);\n text = await response.text();\n } catch (error) {\n const reason = isTimeout(error) ? \"timeout\" : \"network\";\n return Result.fail(new HttpRequestError({ url, reason }, error));\n }\n\n const body = parseJson(text);\n\n if (!response.ok) {\n const statusError = new HttpStatusError({\n url,\n status: response.status,\n statusText: response.statusText,\n body: body.isOk() ? body.value : undefined\n });\n return Result.fail(statusError);\n }\n\n if (body.isFail()) {\n return Result.fail(new HttpRequestError({ url, reason: \"invalidJson\" }, body.error));\n }\n\n return Result.ok(body.value);\n }\n}\n\nexport const HttpClient = createImplementation({\n abstraction: HttpClientAbstraction,\n implementation: HttpClientImpl,\n dependencies: []\n});\n"],"names":["DEFAULT_TIMEOUT_MS","createRequestInit","request","timeoutMs","headers","Headers","init","AbortSignal","undefined","JSON","isTimeout","error","Error","parseJson","text","Result","value","HttpClientImpl","url","response","fetch","reason","HttpRequestError","body","statusError","HttpStatusError","HttpClient","createImplementation","HttpClientAbstraction"],"mappings":";;;;AAMA,MAAMA,qBAAqB;AAE3B,SAASC,kBAAkBC,OAAsC;IAC7D,MAAMC,YAAYD,QAAQ,SAAS,IAAIF;IACvC,MAAMI,UAAU,IAAIC,QAAQH,QAAQ,OAAO;IAC3C,MAAMI,OAAoB;QACtB,QAAQJ,QAAQ,MAAM,IAAI;QAC1BE;QACA,QAAQG,YAAY,OAAO,CAACJ;IAChC;IAEA,IAAID,AAAiBM,WAAjBN,QAAQ,IAAI,EAAgB;QAC5B,IAAI,CAACE,QAAQ,GAAG,CAAC,iBACbA,QAAQ,GAAG,CAAC,gBAAgB;QAEhCE,KAAK,IAAI,GAAGG,KAAK,SAAS,CAACP,QAAQ,IAAI;IAC3C;IAEA,OAAOI;AACX;AAEA,SAASI,UAAUC,KAAc;IAC7B,OAAOA,iBAAiBC,SAASD,AAAe,mBAAfA,MAAM,IAAI;AAC/C;AAGA,SAASE,UAAUC,IAAY;IAC3B,IAAIA,AAAS,OAATA,MACA,OAAOC,OAAO,EAAE,CAACP;IAErB,IAAI;QACA,MAAMQ,QAAiBP,KAAK,KAAK,CAACK;QAClC,OAAOC,OAAO,EAAE,CAACC;IACrB,EAAE,OAAOL,OAAO;QACZ,OAAOI,OAAO,IAAI,CAACJ;IACvB;AACJ;AAEA,MAAMM;IACF,MAAM,YACFf,OAAsC,EACe;QACrD,MAAM,EAAEgB,GAAG,EAAE,GAAGhB;QAChB,MAAMI,OAAOL,kBAAkBC;QAE/B,IAAIiB;QACJ,IAAIL;QACJ,IAAI;YACAK,WAAW,MAAMC,MAAMF,KAAKZ;YAC5BQ,OAAO,MAAMK,SAAS,IAAI;QAC9B,EAAE,OAAOR,OAAO;YACZ,MAAMU,SAASX,UAAUC,SAAS,YAAY;YAC9C,OAAOI,OAAO,IAAI,CAAC,IAAIO,iBAAiB;gBAAEJ;gBAAKG;YAAO,GAAGV;QAC7D;QAEA,MAAMY,OAAOV,UAAUC;QAEvB,IAAI,CAACK,SAAS,EAAE,EAAE;YACd,MAAMK,cAAc,IAAIC,gBAAgB;gBACpCP;gBACA,QAAQC,SAAS,MAAM;gBACvB,YAAYA,SAAS,UAAU;gBAC/B,MAAMI,KAAK,IAAI,KAAKA,KAAK,KAAK,GAAGf;YACrC;YACA,OAAOO,OAAO,IAAI,CAACS;QACvB;QAEA,IAAID,KAAK,MAAM,IACX,OAAOR,OAAO,IAAI,CAAC,IAAIO,iBAAiB;YAAEJ;YAAK,QAAQ;QAAc,GAAGK,KAAK,KAAK;QAGtF,OAAOR,OAAO,EAAE,CAACQ,KAAK,KAAK;IAC/B;AACJ;AAEO,MAAMG,wBAAaC,qBAAqB;IAC3C,aAAaC;IACb,gBAAgBX;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
export interface HttpRequestErrorData {
|
|
3
|
+
url: string;
|
|
4
|
+
reason: "network" | "timeout" | "invalidJson";
|
|
5
|
+
}
|
|
6
|
+
/** The request didn't produce a usable response: it failed, timed out, or the body wasn't JSON. */
|
|
7
|
+
export declare class HttpRequestError extends BaseError<HttpRequestErrorData> {
|
|
8
|
+
readonly code: "HttpClient/Request";
|
|
9
|
+
constructor(data: HttpRequestErrorData, cause: unknown);
|
|
10
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
class HttpRequestError extends BaseError {
|
|
3
|
+
constructor(data, cause){
|
|
4
|
+
super({
|
|
5
|
+
message: `Request to "${data.url}" failed (${data.reason}).`,
|
|
6
|
+
data
|
|
7
|
+
}), this.code = "HttpClient/Request";
|
|
8
|
+
this.cause = cause;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export { HttpRequestError };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=HttpRequestError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/httpClient/HttpRequestError.js","sources":["../../../src/features/httpClient/HttpRequestError.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport interface HttpRequestErrorData {\n url: string;\n reason: \"network\" | \"timeout\" | \"invalidJson\";\n}\n\n/** The request didn't produce a usable response: it failed, timed out, or the body wasn't JSON. */\nexport class HttpRequestError extends BaseError<HttpRequestErrorData> {\n override readonly code = \"HttpClient/Request\" as const;\n\n constructor(data: HttpRequestErrorData, cause: unknown) {\n super({\n message: `Request to \"${data.url}\" failed (${data.reason}).`,\n data\n });\n this.cause = cause;\n }\n}\n"],"names":["HttpRequestError","BaseError","data","cause"],"mappings":";AAQO,MAAMA,yBAAyBC;IAGlC,YAAYC,IAA0B,EAAEC,KAAc,CAAE;QACpD,KAAK,CAAC;YACF,SAAS,CAAC,YAAY,EAAED,KAAK,GAAG,CAAC,UAAU,EAAEA,KAAK,MAAM,CAAC,EAAE,CAAC;YAC5DA;QACJ,SANc,IAAI,GAAG;QAOrB,IAAI,CAAC,KAAK,GAAGC;IACjB;AACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
export interface HttpStatusErrorData {
|
|
3
|
+
url: string;
|
|
4
|
+
status: number;
|
|
5
|
+
statusText: string;
|
|
6
|
+
body: unknown;
|
|
7
|
+
}
|
|
8
|
+
/** The server answered with a non-2xx status. */
|
|
9
|
+
export declare class HttpStatusError extends BaseError<HttpStatusErrorData> {
|
|
10
|
+
readonly code: "HttpClient/Status";
|
|
11
|
+
constructor(data: HttpStatusErrorData);
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseError } from "@webiny/feature/api";
|
|
2
|
+
class HttpStatusError extends BaseError {
|
|
3
|
+
constructor(data){
|
|
4
|
+
super({
|
|
5
|
+
message: `Request to "${data.url}" failed with status ${data.status}.`,
|
|
6
|
+
data
|
|
7
|
+
}), this.code = "HttpClient/Status";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export { HttpStatusError };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=HttpStatusError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/httpClient/HttpStatusError.js","sources":["../../../src/features/httpClient/HttpStatusError.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport interface HttpStatusErrorData {\n url: string;\n status: number;\n statusText: string;\n body: unknown; // the parsed JSON body, or `undefined` when there was none\n}\n\n/** The server answered with a non-2xx status. */\nexport class HttpStatusError extends BaseError<HttpStatusErrorData> {\n override readonly code = \"HttpClient/Status\" as const;\n\n constructor(data: HttpStatusErrorData) {\n super({\n message: `Request to \"${data.url}\" failed with status ${data.status}.`,\n data\n });\n }\n}\n"],"names":["HttpStatusError","BaseError","data"],"mappings":";AAUO,MAAMA,wBAAwBC;IAGjC,YAAYC,IAAyB,CAAE;QACnC,KAAK,CAAC;YACF,SAAS,CAAC,YAAY,EAAEA,KAAK,GAAG,CAAC,qBAAqB,EAAEA,KAAK,MAAM,CAAC,CAAC,CAAC;YACtEA;QACJ,SANc,IAAI,GAAG;IAOzB;AACJ"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Result } from "@webiny/feature/api";
|
|
2
|
+
import type { HttpRequestError } from "./HttpRequestError.js";
|
|
3
|
+
import type { HttpStatusError } from "./HttpStatusError.js";
|
|
4
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
5
|
+
export interface IHttpClientRequest {
|
|
6
|
+
url: string;
|
|
7
|
+
method?: HttpMethod;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface IHttpClientErrors {
|
|
13
|
+
request: HttpRequestError;
|
|
14
|
+
status: HttpStatusError;
|
|
15
|
+
}
|
|
16
|
+
type HttpClientError = IHttpClientErrors[keyof IHttpClientErrors];
|
|
17
|
+
export interface IHttpClient {
|
|
18
|
+
/**
|
|
19
|
+
* Sends a request and parses the response body as JSON. The body is `unknown` on purpose:
|
|
20
|
+
* validate it before use.
|
|
21
|
+
*/
|
|
22
|
+
requestJson(request: IHttpClientRequest): Promise<Result<unknown, HttpClientError>>;
|
|
23
|
+
}
|
|
24
|
+
/** Outbound HTTP requests with a timeout, a status check and JSON parsing. */
|
|
25
|
+
export declare const HttpClient: import("@webiny/di").Abstraction<IHttpClient>;
|
|
26
|
+
export declare namespace HttpClient {
|
|
27
|
+
type Interface = IHttpClient;
|
|
28
|
+
type Request = IHttpClientRequest;
|
|
29
|
+
type Method = HttpMethod;
|
|
30
|
+
type Error = HttpClientError;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/httpClient/abstractions.js","sources":["../../../src/features/httpClient/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { HttpRequestError } from \"./HttpRequestError.js\";\nimport type { HttpStatusError } from \"./HttpStatusError.js\";\n\nexport type HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\nexport interface IHttpClientRequest {\n url: string;\n method?: HttpMethod; // defaults to \"GET\"\n headers?: Record<string, string>;\n body?: unknown; // sent as JSON\n timeoutMs?: number; // defaults to 10 seconds\n}\n\nexport interface IHttpClientErrors {\n request: HttpRequestError;\n status: HttpStatusError;\n}\n\ntype HttpClientError = IHttpClientErrors[keyof IHttpClientErrors];\n\nexport interface IHttpClient {\n /**\n * Sends a request and parses the response body as JSON. The body is `unknown` on purpose:\n * validate it before use.\n */\n requestJson(request: IHttpClientRequest): Promise<Result<unknown, HttpClientError>>;\n}\n\n/** Outbound HTTP requests with a timeout, a status check and JSON parsing. */\nexport const HttpClient = createAbstraction<IHttpClient>(\"HttpClient\");\n\nexport namespace HttpClient {\n export type Interface = IHttpClient;\n export type Request = IHttpClientRequest;\n export type Method = HttpMethod;\n export type Error = HttpClientError;\n}\n"],"names":["HttpClient","createAbstraction"],"mappings":";AA+BO,MAAMA,aAAaC,kBAA+B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { HttpClient } from "./HttpClient.js";
|
|
3
|
+
const HttpClientFeature = createFeature({
|
|
4
|
+
name: "HttpClientFeature",
|
|
5
|
+
register (container) {
|
|
6
|
+
container.register(HttpClient).inSingletonScope();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
9
|
+
export { HttpClientFeature };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/httpClient/feature.js","sources":["../../../src/features/httpClient/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { HttpClient } from \"./HttpClient.js\";\n\nexport const HttpClientFeature = createFeature({\n name: \"HttpClientFeature\",\n register(container) {\n container.register(HttpClient).inSingletonScope();\n }\n});\n"],"names":["HttpClientFeature","createFeature","container","HttpClient"],"mappings":";;AAGO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC,YAAY,gBAAgB;IACnD;AACJ"}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { KeyValueStoreRepository
|
|
2
|
+
import { KeyValueStoreRepository } from "./abstractions.js";
|
|
3
|
+
import { GlobalKeyValueStore as ServiceAbstraction } from "./abstractions.js";
|
|
4
|
+
import type { IGlobalKeyValueStoreOptions } from "./abstractions.js";
|
|
5
|
+
import type { IGlobalKeyValueSetOptions } from "./abstractions.js";
|
|
6
|
+
import type { IGlobalKeyValueListParams } from "./abstractions.js";
|
|
7
|
+
import type { IGlobalKeyValueDeleteOptions } from "./abstractions.js";
|
|
3
8
|
declare class GlobalKeyValueStoreImpl implements ServiceAbstraction.Interface {
|
|
4
9
|
private repository;
|
|
5
10
|
constructor(repository: KeyValueStoreRepository.Interface);
|
|
6
11
|
private getScope;
|
|
7
12
|
get<T = unknown>(key: string, options?: IGlobalKeyValueStoreOptions): Promise<Result<T, ServiceAbstraction.Error>>;
|
|
8
|
-
set(key: string, value: any, options?:
|
|
9
|
-
delete(key: string, options?:
|
|
13
|
+
set(key: string, value: any, options?: IGlobalKeyValueSetOptions): Promise<Result<void, ServiceAbstraction.Error>>;
|
|
14
|
+
delete(key: string, options?: IGlobalKeyValueDeleteOptions): Promise<Result<void, ServiceAbstraction.Error>>;
|
|
15
|
+
list<T = unknown>(params: IGlobalKeyValueListParams): Promise<Result<ServiceAbstraction.ListResult<T>, ServiceAbstraction.Error>>;
|
|
10
16
|
}
|
|
11
17
|
export declare const GlobalKeyValueStore: import("@webiny/di").Implementation<typeof GlobalKeyValueStoreImpl>;
|
|
12
18
|
export {};
|
|
@@ -15,12 +15,22 @@ class GlobalKeyValueStoreImpl {
|
|
|
15
15
|
async set(key, value, options) {
|
|
16
16
|
const scope = this.getScope(options);
|
|
17
17
|
return this.repository.set(key, value, scope, {
|
|
18
|
-
expiresAt: options?.expiresAt
|
|
18
|
+
expiresAt: options?.expiresAt,
|
|
19
|
+
collection: options?.collection,
|
|
20
|
+
condition: options?.condition
|
|
19
21
|
});
|
|
20
22
|
}
|
|
21
23
|
async delete(key, options) {
|
|
22
24
|
const scope = this.getScope(options);
|
|
23
|
-
return this.repository.delete(key, scope
|
|
25
|
+
return this.repository.delete(key, scope, {
|
|
26
|
+
condition: options?.condition
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async list(params) {
|
|
30
|
+
const { scope, ...listParams } = params;
|
|
31
|
+
return this.repository.list(this.getScope({
|
|
32
|
+
scope
|
|
33
|
+
}), listParams);
|
|
24
34
|
}
|
|
25
35
|
}
|
|
26
36
|
const GlobalKeyValueStore_GlobalKeyValueStore = createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/keyValueStore/GlobalKeyValueStore.js","sources":["../../../src/features/keyValueStore/GlobalKeyValueStore.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport {\
|
|
1
|
+
{"version":3,"file":"features/keyValueStore/GlobalKeyValueStore.js","sources":["../../../src/features/keyValueStore/GlobalKeyValueStore.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { KeyValueStoreRepository } from \"./abstractions.js\";\nimport { GlobalKeyValueStore as ServiceAbstraction } from \"./abstractions.js\";\nimport type { IGlobalKeyValueStoreOptions } from \"./abstractions.js\";\nimport type { IGlobalKeyValueSetOptions } from \"./abstractions.js\";\nimport type { IGlobalKeyValueListParams } from \"./abstractions.js\";\nimport type { IGlobalKeyValueDeleteOptions } from \"./abstractions.js\";\n\nconst DEFAULT_SCOPE = \"global\";\n\nclass GlobalKeyValueStoreImpl implements ServiceAbstraction.Interface {\n constructor(private repository: KeyValueStoreRepository.Interface) {}\n\n private getScope(options?: { scope?: string }): string {\n return options?.scope || DEFAULT_SCOPE;\n }\n\n async get<T = unknown>(\n key: string,\n options?: IGlobalKeyValueStoreOptions\n ): Promise<Result<T, ServiceAbstraction.Error>> {\n const scope = this.getScope(options);\n return this.repository.get<T>(key, scope);\n }\n\n async set(\n key: string,\n value: any,\n options?: IGlobalKeyValueSetOptions\n ): Promise<Result<void, ServiceAbstraction.Error>> {\n const scope = this.getScope(options);\n return this.repository.set(key, value, scope, {\n expiresAt: options?.expiresAt,\n collection: options?.collection,\n condition: options?.condition\n });\n }\n\n async delete(\n key: string,\n options?: IGlobalKeyValueDeleteOptions\n ): Promise<Result<void, ServiceAbstraction.Error>> {\n const scope = this.getScope(options);\n return this.repository.delete(key, scope, { condition: options?.condition });\n }\n\n async list<T = unknown>(\n params: IGlobalKeyValueListParams\n ): Promise<Result<ServiceAbstraction.ListResult<T>, ServiceAbstraction.Error>> {\n const { scope, ...listParams } = params;\n return this.repository.list<T>(this.getScope({ scope }), listParams);\n }\n}\n\nexport const GlobalKeyValueStore = createImplementation({\n abstraction: ServiceAbstraction,\n implementation: GlobalKeyValueStoreImpl,\n dependencies: [KeyValueStoreRepository]\n});\n"],"names":["DEFAULT_SCOPE","GlobalKeyValueStoreImpl","repository","options","key","scope","value","params","listParams","GlobalKeyValueStore","createImplementation","ServiceAbstraction","KeyValueStoreRepository"],"mappings":";;AASA,MAAMA,gBAAgB;AAEtB,MAAMC;IACF,YAAoBC,UAA6C,CAAE;aAA/CA,UAAU,GAAVA;IAAgD;IAE5D,SAASC,OAA4B,EAAU;QACnD,OAAOA,SAAS,SAASH;IAC7B;IAEA,MAAM,IACFI,GAAW,EACXD,OAAqC,EACO;QAC5C,MAAME,QAAQ,IAAI,CAAC,QAAQ,CAACF;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAIC,KAAKC;IACvC;IAEA,MAAM,IACFD,GAAW,EACXE,KAAU,EACVH,OAAmC,EACY;QAC/C,MAAME,QAAQ,IAAI,CAAC,QAAQ,CAACF;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAACC,KAAKE,OAAOD,OAAO;YAC1C,WAAWF,SAAS;YACpB,YAAYA,SAAS;YACrB,WAAWA,SAAS;QACxB;IACJ;IAEA,MAAM,OACFC,GAAW,EACXD,OAAsC,EACS;QAC/C,MAAME,QAAQ,IAAI,CAAC,QAAQ,CAACF;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAACC,KAAKC,OAAO;YAAE,WAAWF,SAAS;QAAU;IAC9E;IAEA,MAAM,KACFI,MAAiC,EAC0C;QAC3E,MAAM,EAAEF,KAAK,EAAE,GAAGG,YAAY,GAAGD;QACjC,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAI,IAAI,CAAC,QAAQ,CAAC;YAAEF;QAAM,IAAIG;IAC7D;AACJ;AAEO,MAAMC,0CAAsBC,qBAAqB;IACpD,aAAaC;IACb,gBAAgBV;IAChB,cAAc;QAACW;KAAwB;AAC3C"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { KeyValueStore as ServiceAbstraction } from "./abstractions.js";
|
|
3
3
|
import { GlobalKeyValueStore } from "./abstractions.js";
|
|
4
|
+
import type { IKeyValueSetOptions } from "./abstractions.js";
|
|
5
|
+
import type { IKeyValueDeleteOptions } from "./abstractions.js";
|
|
6
|
+
import type { IKeyValueListParams } from "./abstractions.js";
|
|
4
7
|
import { TenantContext } from "../../features/tenancy/TenantContext/index.js";
|
|
5
8
|
declare class KeyValueStoreImpl implements ServiceAbstraction.Interface {
|
|
6
9
|
private tenantContext;
|
|
7
10
|
private globalStore;
|
|
8
11
|
constructor(tenantContext: TenantContext.Interface, globalStore: GlobalKeyValueStore.Interface);
|
|
9
12
|
get<T = unknown>(key: string): Promise<Result<T, ServiceAbstraction.Error>>;
|
|
10
|
-
set(key: string, value: any): Promise<Result<void, ServiceAbstraction.Error>>;
|
|
11
|
-
delete(key: string): Promise<Result<void, ServiceAbstraction.Error>>;
|
|
13
|
+
set(key: string, value: any, options?: IKeyValueSetOptions): Promise<Result<void, ServiceAbstraction.Error>>;
|
|
14
|
+
delete(key: string, options?: IKeyValueDeleteOptions): Promise<Result<void, ServiceAbstraction.Error>>;
|
|
15
|
+
list<T = unknown>(params: IKeyValueListParams): Promise<Result<ServiceAbstraction.ListResult<T>, ServiceAbstraction.Error>>;
|
|
12
16
|
}
|
|
13
17
|
export declare const KeyValueStore: typeof KeyValueStoreImpl & {
|
|
14
18
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IKeyValueStore>;
|
|
@@ -11,15 +11,25 @@ class KeyValueStoreImpl {
|
|
|
11
11
|
scope: tenant.id
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
async set(key, value) {
|
|
14
|
+
async set(key, value, options) {
|
|
15
15
|
const tenant = this.tenantContext.getTenant();
|
|
16
16
|
return this.globalStore.set(key, value, {
|
|
17
|
-
scope: tenant.id
|
|
17
|
+
scope: tenant.id,
|
|
18
|
+
collection: options?.collection,
|
|
19
|
+
condition: options?.condition
|
|
18
20
|
});
|
|
19
21
|
}
|
|
20
|
-
async delete(key) {
|
|
22
|
+
async delete(key, options) {
|
|
21
23
|
const tenant = this.tenantContext.getTenant();
|
|
22
24
|
return this.globalStore.delete(key, {
|
|
25
|
+
scope: tenant.id,
|
|
26
|
+
condition: options?.condition
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async list(params) {
|
|
30
|
+
const tenant = this.tenantContext.getTenant();
|
|
31
|
+
return this.globalStore.list({
|
|
32
|
+
...params,
|
|
23
33
|
scope: tenant.id
|
|
24
34
|
});
|
|
25
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/keyValueStore/KeyValueStore.js","sources":["../../../src/features/keyValueStore/KeyValueStore.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { KeyValueStore as ServiceAbstraction } from \"./abstractions.js\";\nimport { GlobalKeyValueStore } from \"./abstractions.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\n\nclass KeyValueStoreImpl implements ServiceAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private globalStore: GlobalKeyValueStore.Interface\n ) {}\n\n async get<T = unknown>(key: string): Promise<Result<T, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.get<T>(key, { scope: tenant.id });\n }\n\n async set(key: string
|
|
1
|
+
{"version":3,"file":"features/keyValueStore/KeyValueStore.js","sources":["../../../src/features/keyValueStore/KeyValueStore.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { KeyValueStore as ServiceAbstraction } from \"./abstractions.js\";\nimport { GlobalKeyValueStore } from \"./abstractions.js\";\nimport type { IKeyValueSetOptions } from \"./abstractions.js\";\nimport type { IKeyValueDeleteOptions } from \"./abstractions.js\";\nimport type { IKeyValueListParams } from \"./abstractions.js\";\nimport { TenantContext } from \"~/features/tenancy/TenantContext/index.js\";\n\nclass KeyValueStoreImpl implements ServiceAbstraction.Interface {\n constructor(\n private tenantContext: TenantContext.Interface,\n private globalStore: GlobalKeyValueStore.Interface\n ) {}\n\n async get<T = unknown>(key: string): Promise<Result<T, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.get<T>(key, { scope: tenant.id });\n }\n\n async set(\n key: string,\n value: any,\n options?: IKeyValueSetOptions\n ): Promise<Result<void, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.set(key, value, {\n scope: tenant.id,\n collection: options?.collection,\n condition: options?.condition\n });\n }\n\n async delete(\n key: string,\n options?: IKeyValueDeleteOptions\n ): Promise<Result<void, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.delete(key, { scope: tenant.id, condition: options?.condition });\n }\n\n async list<T = unknown>(\n params: IKeyValueListParams\n ): Promise<Result<ServiceAbstraction.ListResult<T>, ServiceAbstraction.Error>> {\n const tenant = this.tenantContext.getTenant();\n return this.globalStore.list<T>({ ...params, scope: tenant.id });\n }\n}\n\nexport const KeyValueStore = ServiceAbstraction.createImplementation({\n implementation: KeyValueStoreImpl,\n dependencies: [TenantContext, GlobalKeyValueStore]\n});\n"],"names":["KeyValueStoreImpl","tenantContext","globalStore","key","tenant","value","options","params","KeyValueStore","ServiceAbstraction","TenantContext","GlobalKeyValueStore"],"mappings":";;AAQA,MAAMA;IACF,YACYC,aAAsC,EACtCC,WAA0C,CACpD;aAFUD,aAAa,GAAbA;aACAC,WAAW,GAAXA;IACT;IAEH,MAAM,IAAiBC,GAAW,EAAgD;QAC9E,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAID,KAAK;YAAE,OAAOC,OAAO,EAAE;QAAC;IAC3D;IAEA,MAAM,IACFD,GAAW,EACXE,KAAU,EACVC,OAA6B,EACkB;QAC/C,MAAMF,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAACD,KAAKE,OAAO;YACpC,OAAOD,OAAO,EAAE;YAChB,YAAYE,SAAS;YACrB,WAAWA,SAAS;QACxB;IACJ;IAEA,MAAM,OACFH,GAAW,EACXG,OAAgC,EACe;QAC/C,MAAMF,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAACD,KAAK;YAAE,OAAOC,OAAO,EAAE;YAAE,WAAWE,SAAS;QAAU;IAC1F;IAEA,MAAM,KACFC,MAA2B,EACgD;QAC3E,MAAMH,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS;QAC3C,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAI;YAAE,GAAGG,MAAM;YAAE,OAAOH,OAAO,EAAE;QAAC;IAClE;AACJ;AAEO,MAAMI,8BAAgBC,cAAAA,oBAAuC,CAAC;IACjE,gBAAgBT;IAChB,cAAc;QAACU;QAAeC;KAAoB;AACtD"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
|
-
import { KeyValueStorageOperations
|
|
2
|
+
import { KeyValueStorageOperations } from "./abstractions.js";
|
|
3
|
+
import { KeyValueStoreRepository as RepositoryAbstraction } from "./abstractions.js";
|
|
4
|
+
import type { IKeyValueListParams } from "./abstractions.js";
|
|
5
|
+
import type { IKeyValueListResult } from "./abstractions.js";
|
|
6
|
+
import type { IKeyValueStoreSetOptions } from "./abstractions.js";
|
|
7
|
+
import type { IKeyValueDeleteOptions } from "./abstractions.js";
|
|
3
8
|
/**
|
|
4
9
|
* KeyValueStoreRepository implementation.
|
|
5
10
|
*
|
|
@@ -11,7 +16,8 @@ declare class KeyValueStoreRepositoryImpl implements RepositoryAbstraction.Inter
|
|
|
11
16
|
constructor(storageOperations: KeyValueStorageOperations.Interface);
|
|
12
17
|
get<T = unknown>(key: string, scope: string): Promise<Result<T, RepositoryAbstraction.Error>>;
|
|
13
18
|
set(key: string, value: any, scope: string, options?: IKeyValueStoreSetOptions): Promise<Result<void, RepositoryAbstraction.Error>>;
|
|
14
|
-
delete(key: string, scope: string): Promise<Result<void, RepositoryAbstraction.Error>>;
|
|
19
|
+
delete(key: string, scope: string, options?: IKeyValueDeleteOptions): Promise<Result<void, RepositoryAbstraction.Error>>;
|
|
20
|
+
list<T = unknown>(scope: string, params: IKeyValueListParams): Promise<Result<IKeyValueListResult<T>, RepositoryAbstraction.Error>>;
|
|
15
21
|
}
|
|
16
22
|
export declare const KeyValueStoreRepository: import("@webiny/di").Implementation<typeof KeyValueStoreRepositoryImpl>;
|
|
17
23
|
export {};
|
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
import { Result, createImplementation } from "@webiny/feature/api";
|
|
2
2
|
import { KeyValueStorageOperations, KeyValueStoreRepository } from "./abstractions.js";
|
|
3
|
-
import { KeyNotFoundError, KeyValueStorageError } from "./errors.js";
|
|
3
|
+
import { KeyNotFoundError, KeyValueConditionFailedError, KeyValueInvalidCollectionError, KeyValueInvalidConditionError, KeyValueInvalidCursorError, KeyValueKeyTooLongError, KeyValueStorageError } from "./errors.js";
|
|
4
|
+
const DEFAULT_LIST_LIMIT = 100;
|
|
5
|
+
const MAX_LIST_LIMIT = 1000;
|
|
6
|
+
const resolveLimit = (limit)=>{
|
|
7
|
+
if (!limit || !Number.isFinite(limit)) return DEFAULT_LIST_LIMIT;
|
|
8
|
+
const whole = Math.floor(limit);
|
|
9
|
+
const atLeastOne = Math.max(whole, 1);
|
|
10
|
+
return Math.min(atLeastOne, MAX_LIST_LIMIT);
|
|
11
|
+
};
|
|
12
|
+
const encodeCursor = (cursor)=>{
|
|
13
|
+
const json = JSON.stringify(cursor);
|
|
14
|
+
return Buffer.from(json).toString("base64url");
|
|
15
|
+
};
|
|
16
|
+
const decodeCursor = (cursor)=>{
|
|
17
|
+
try {
|
|
18
|
+
const json = Buffer.from(cursor, "base64url").toString("utf8");
|
|
19
|
+
const parsed = JSON.parse(json);
|
|
20
|
+
if ("string" != typeof parsed?.collection || "boolean" != typeof parsed.reverse || "string" != typeof parsed.after) return;
|
|
21
|
+
return parsed;
|
|
22
|
+
} catch {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const isComparable = (value)=>{
|
|
27
|
+
const type = typeof value;
|
|
28
|
+
return "string" === type || "number" === type || "boolean" === type;
|
|
29
|
+
};
|
|
30
|
+
const isValidCondition = (condition, allowNotExists)=>{
|
|
31
|
+
if ("object" != typeof condition || null === condition) return false;
|
|
32
|
+
const { exists, equals } = condition;
|
|
33
|
+
if (void 0 !== exists && void 0 !== equals) return false;
|
|
34
|
+
if (void 0 !== exists) return true === exists || false === exists && allowNotExists;
|
|
35
|
+
return isComparable(equals);
|
|
36
|
+
};
|
|
37
|
+
const MAX_COLLECTION_BYTES = 1000;
|
|
38
|
+
const MAX_COLLECTION_KEY_BYTES = 1000;
|
|
39
|
+
const isValidCollection = (collection)=>"string" == typeof collection && collection.length > 0 && Buffer.byteLength(collection, "utf8") <= MAX_COLLECTION_BYTES;
|
|
4
40
|
class KeyValueStoreRepositoryImpl {
|
|
5
41
|
constructor(storageOperations){
|
|
6
42
|
this.storageOperations = storageOperations;
|
|
@@ -15,21 +51,63 @@ class KeyValueStoreRepositoryImpl {
|
|
|
15
51
|
}
|
|
16
52
|
}
|
|
17
53
|
async set(key, value, scope, options) {
|
|
54
|
+
if (options?.condition !== void 0 && !isValidCondition(options.condition, true)) return Result.fail(new KeyValueInvalidConditionError());
|
|
55
|
+
if (options?.collection !== void 0) {
|
|
56
|
+
if (!isValidCollection(options.collection)) return Result.fail(new KeyValueInvalidCollectionError(MAX_COLLECTION_BYTES));
|
|
57
|
+
if (Buffer.byteLength(key, "utf8") > MAX_COLLECTION_KEY_BYTES) return Result.fail(new KeyValueKeyTooLongError(key, MAX_COLLECTION_KEY_BYTES));
|
|
58
|
+
}
|
|
18
59
|
try {
|
|
19
|
-
await this.storageOperations.set(key, value, scope, options);
|
|
60
|
+
const written = await this.storageOperations.set(key, value, scope, options);
|
|
61
|
+
if (!written) return Result.fail(new KeyValueConditionFailedError(key));
|
|
20
62
|
return Result.ok();
|
|
21
63
|
} catch (error) {
|
|
22
64
|
return Result.fail(new KeyValueStorageError(error));
|
|
23
65
|
}
|
|
24
66
|
}
|
|
25
|
-
async delete(key, scope) {
|
|
67
|
+
async delete(key, scope, options) {
|
|
68
|
+
if (options?.condition !== void 0 && !isValidCondition(options.condition, false)) return Result.fail(new KeyValueInvalidConditionError());
|
|
26
69
|
try {
|
|
27
|
-
await this.storageOperations.delete(key, scope);
|
|
70
|
+
const deleted = await this.storageOperations.delete(key, scope, options);
|
|
71
|
+
if (!deleted) return Result.fail(new KeyValueConditionFailedError(key));
|
|
28
72
|
return Result.ok();
|
|
29
73
|
} catch (error) {
|
|
30
74
|
return Result.fail(new KeyValueStorageError(error));
|
|
31
75
|
}
|
|
32
76
|
}
|
|
77
|
+
async list(scope, params) {
|
|
78
|
+
const { collection, cursor } = params;
|
|
79
|
+
if (!isValidCollection(collection)) return Result.fail(new KeyValueInvalidCollectionError(MAX_COLLECTION_BYTES));
|
|
80
|
+
let reverse = params.reverse ?? false;
|
|
81
|
+
let after;
|
|
82
|
+
if (cursor) {
|
|
83
|
+
const decoded = decodeCursor(cursor);
|
|
84
|
+
if (!decoded || decoded.collection !== collection) return Result.fail(new KeyValueInvalidCursorError(cursor));
|
|
85
|
+
reverse = decoded.reverse;
|
|
86
|
+
after = decoded.after;
|
|
87
|
+
}
|
|
88
|
+
const limit = resolveLimit(params.limit);
|
|
89
|
+
try {
|
|
90
|
+
const { items, lastKey } = await this.storageOperations.list({
|
|
91
|
+
collection,
|
|
92
|
+
scope,
|
|
93
|
+
limit,
|
|
94
|
+
reverse,
|
|
95
|
+
after
|
|
96
|
+
});
|
|
97
|
+
let nextCursor = null;
|
|
98
|
+
if (null !== lastKey) nextCursor = encodeCursor({
|
|
99
|
+
collection,
|
|
100
|
+
reverse,
|
|
101
|
+
after: lastKey
|
|
102
|
+
});
|
|
103
|
+
return Result.ok({
|
|
104
|
+
items: items,
|
|
105
|
+
cursor: nextCursor
|
|
106
|
+
});
|
|
107
|
+
} catch (error) {
|
|
108
|
+
return Result.fail(new KeyValueStorageError(error));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
33
111
|
}
|
|
34
112
|
const KeyValueStoreRepository_KeyValueStoreRepository = createImplementation({
|
|
35
113
|
abstraction: KeyValueStoreRepository,
|