@undefineds.co/xpod 0.2.2 → 0.2.3
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/dist/api/service/VercelChatService.d.ts +8 -5
- package/dist/api/service/VercelChatService.js +75 -64
- package/dist/api/service/VercelChatService.js.map +1 -1
- package/dist/components/components.jsonld +1 -0
- package/dist/components/context.jsonld +54 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/quota/DrizzleQuotaService.d.ts +6 -2
- package/dist/quota/DrizzleQuotaService.js +27 -11
- package/dist/quota/DrizzleQuotaService.js.map +1 -1
- package/dist/quota/DrizzleQuotaService.jsonld +27 -1
- package/dist/quota/EntitlementProvider.d.ts +30 -0
- package/dist/quota/EntitlementProvider.js +118 -0
- package/dist/quota/EntitlementProvider.js.map +1 -0
- package/dist/quota/EntitlementProvider.jsonld +173 -0
- package/package.json +1 -1
|
@@ -86,6 +86,51 @@
|
|
|
86
86
|
"@prefix": true,
|
|
87
87
|
"@context": {}
|
|
88
88
|
},
|
|
89
|
+
"EntitlementProvider": {
|
|
90
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#EntitlementProvider",
|
|
91
|
+
"@prefix": true,
|
|
92
|
+
"@context": {}
|
|
93
|
+
},
|
|
94
|
+
"AccountEntitlement": {
|
|
95
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#AccountEntitlement",
|
|
96
|
+
"@prefix": true,
|
|
97
|
+
"@context": {}
|
|
98
|
+
},
|
|
99
|
+
"HttpEntitlementProvider": {
|
|
100
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#HttpEntitlementProvider",
|
|
101
|
+
"@prefix": true,
|
|
102
|
+
"@context": {
|
|
103
|
+
"options_baseUrl": {
|
|
104
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#HttpEntitlementProvider_options_baseUrl"
|
|
105
|
+
},
|
|
106
|
+
"options_serviceToken": {
|
|
107
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#HttpEntitlementProvider_options_serviceToken"
|
|
108
|
+
},
|
|
109
|
+
"options_cacheTtlMs": {
|
|
110
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#HttpEntitlementProvider_options_cacheTtlMs"
|
|
111
|
+
},
|
|
112
|
+
"options_timeoutMs": {
|
|
113
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#HttpEntitlementProvider_options_timeoutMs"
|
|
114
|
+
},
|
|
115
|
+
"baseUrl": {
|
|
116
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#HttpEntitlementProvider_options_baseUrl"
|
|
117
|
+
},
|
|
118
|
+
"serviceToken": {
|
|
119
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#HttpEntitlementProvider_options_serviceToken"
|
|
120
|
+
},
|
|
121
|
+
"cacheTtlMs": {
|
|
122
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#HttpEntitlementProvider_options_cacheTtlMs"
|
|
123
|
+
},
|
|
124
|
+
"timeoutMs": {
|
|
125
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#HttpEntitlementProvider_options_timeoutMs"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"NoopEntitlementProvider": {
|
|
130
|
+
"@id": "undefineds:dist/quota/EntitlementProvider.jsonld#NoopEntitlementProvider",
|
|
131
|
+
"@prefix": true,
|
|
132
|
+
"@context": {}
|
|
133
|
+
},
|
|
89
134
|
"TunnelProvider": {
|
|
90
135
|
"@id": "undefineds:dist/tunnel/TunnelProvider.jsonld#TunnelProvider",
|
|
91
136
|
"@prefix": true,
|
|
@@ -835,6 +880,15 @@
|
|
|
835
880
|
"@context": {
|
|
836
881
|
"options_identityDbUrl": {
|
|
837
882
|
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService_options_identityDbUrl"
|
|
883
|
+
},
|
|
884
|
+
"options_entitlementProvider": {
|
|
885
|
+
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService_options_entitlementProvider"
|
|
886
|
+
},
|
|
887
|
+
"identityDbUrl": {
|
|
888
|
+
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService_options_identityDbUrl"
|
|
889
|
+
},
|
|
890
|
+
"entitlementProvider": {
|
|
891
|
+
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService_options_entitlementProvider"
|
|
838
892
|
}
|
|
839
893
|
}
|
|
840
894
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { RedisKeyValueStorage } from './storage/keyvalue/RedisKeyValueStorage';
|
|
|
26
26
|
import { SqliteKeyValueStorage } from './storage/keyvalue/SqliteKeyValueStorage';
|
|
27
27
|
import { DrizzleQuotaService } from './quota/DrizzleQuotaService';
|
|
28
28
|
import { NoopQuotaService } from './quota/NoopQuotaService';
|
|
29
|
+
import { HttpEntitlementProvider, NoopEntitlementProvider } from './quota/EntitlementProvider';
|
|
29
30
|
import { PerAccountQuotaStrategy } from './storage/quota/PerAccountQuotaStrategy';
|
|
30
31
|
import { TencentDnsProvider } from './dns/tencent/TencentDnsProvider';
|
|
31
32
|
import { EdgeNodeDnsCoordinator } from './edge/EdgeNodeDnsCoordinator';
|
|
@@ -72,7 +73,8 @@ export type { DnsProvider, ListDnsRecordsInput, ListableDnsProvider, DeleteDnsRe
|
|
|
72
73
|
export type { EdgeNodeCertificateProvisioner } from './edge/EdgeNodeCertificateProvisioner';
|
|
73
74
|
export type { EdgeNodeTunnelManager } from './edge/interfaces/EdgeNodeTunnelManager';
|
|
74
75
|
export type { QuotaService, AccountQuota } from './quota/QuotaService';
|
|
76
|
+
export type { EntitlementProvider, AccountEntitlement } from './quota/EntitlementProvider';
|
|
75
77
|
export type { TunnelProvider, TunnelConfig, TunnelSetupOptions, TunnelStatus, } from './tunnel/TunnelProvider';
|
|
76
78
|
export type { SubdomainRegistration, ConnectivityResult, SubdomainServiceOptions, } from './subdomain/SubdomainService';
|
|
77
79
|
export { AppStaticAssetHandler } from './http/AppStaticAssetHandler';
|
|
78
|
-
export { RepresentationPartialConvertingStore, MinioDataAccessor, QuadstoreSparqlDataAccessor, QuintStoreSparqlDataAccessor, MixDataAccessor, ConfigurableLoggerFactory, SparqlUpdateResourceStore, SubgraphQueryEngine, QuadstoreSparqlEngine, QuintstoreSparqlEngine, SubgraphSparqlHttpHandler, QuotaAdminHttpHandler, ClusterIngressRouter, ClusterWebSocketConfigurator, EdgeNodeDirectDebugHttpHandler, EdgeNodeProxyHttpHandler, RouterHttpHandler, RouterHttpRoute, TracingHandler, EdgeNodeCertificateHttpHandler, TerminalHttpHandler, ReservedSuffixIdentifierGenerator, DrizzleIndexedStorage, PostgresKeyValueStorage, RedisKeyValueStorage, SqliteKeyValueStorage, DrizzleQuotaService, NoopQuotaService, PerAccountQuotaStrategy, TencentDnsProvider, EdgeNodeDnsCoordinator, Dns01CertificateProvisioner, SimpleEdgeNodeTunnelManager, NoopEdgeNodeTunnelManager, FrpTunnelManager, EdgeNodeHealthProbeService, EdgeNodeAgent, EdgeNodeCertificateService, AcmeCertificateManager, EdgeNodeModeDetector, ClusterIdentifierStrategy, UsageTrackingStore, CenterNodeRegistrationService, PodRoutingHttpHandler, ReactAppViewHandler, QuintStore, SqliteQuintStore, PgQuintStore, BaseQuintStore, VectorStore, SqliteVectorStore, PostgresVectorStore, VectorHttpHandler, ProviderRegistry, ProviderRegistryImpl, EmbeddingService, EmbeddingServiceImpl, CredentialReader, CredentialReaderImpl, CloudflareTunnelProvider, LocalTunnelProvider, SubdomainService, MultiDomainIdentifierStrategy, SubdomainPodIdentifierStrategy, DisabledOidcHandler, DisabledIdentityProviderHandler, AutoDetectOidcHandler, AutoDetectIdentityProviderHandler, UrlAwareRedisLocker, ProvisionPodCreator, ProvisionCodeCodec, AuthModeSelector, };
|
|
80
|
+
export { RepresentationPartialConvertingStore, MinioDataAccessor, QuadstoreSparqlDataAccessor, QuintStoreSparqlDataAccessor, MixDataAccessor, ConfigurableLoggerFactory, SparqlUpdateResourceStore, SubgraphQueryEngine, QuadstoreSparqlEngine, QuintstoreSparqlEngine, SubgraphSparqlHttpHandler, QuotaAdminHttpHandler, ClusterIngressRouter, ClusterWebSocketConfigurator, EdgeNodeDirectDebugHttpHandler, EdgeNodeProxyHttpHandler, RouterHttpHandler, RouterHttpRoute, TracingHandler, EdgeNodeCertificateHttpHandler, TerminalHttpHandler, ReservedSuffixIdentifierGenerator, DrizzleIndexedStorage, PostgresKeyValueStorage, RedisKeyValueStorage, SqliteKeyValueStorage, DrizzleQuotaService, NoopQuotaService, HttpEntitlementProvider, NoopEntitlementProvider, PerAccountQuotaStrategy, TencentDnsProvider, EdgeNodeDnsCoordinator, Dns01CertificateProvisioner, SimpleEdgeNodeTunnelManager, NoopEdgeNodeTunnelManager, FrpTunnelManager, EdgeNodeHealthProbeService, EdgeNodeAgent, EdgeNodeCertificateService, AcmeCertificateManager, EdgeNodeModeDetector, ClusterIdentifierStrategy, UsageTrackingStore, CenterNodeRegistrationService, PodRoutingHttpHandler, ReactAppViewHandler, QuintStore, SqliteQuintStore, PgQuintStore, BaseQuintStore, VectorStore, SqliteVectorStore, PostgresVectorStore, VectorHttpHandler, ProviderRegistry, ProviderRegistryImpl, EmbeddingService, EmbeddingServiceImpl, CredentialReader, CredentialReaderImpl, CloudflareTunnelProvider, LocalTunnelProvider, SubdomainService, MultiDomainIdentifierStrategy, SubdomainPodIdentifierStrategy, DisabledOidcHandler, DisabledIdentityProviderHandler, AutoDetectOidcHandler, AutoDetectIdentityProviderHandler, UrlAwareRedisLocker, ProvisionPodCreator, ProvisionCodeCodec, AuthModeSelector, };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.AuthModeSelector = exports.ProvisionCodeCodec = exports.ProvisionPodCreator = exports.UrlAwareRedisLocker = exports.AutoDetectIdentityProviderHandler = exports.AutoDetectOidcHandler = exports.DisabledIdentityProviderHandler = exports.DisabledOidcHandler = exports.SubdomainPodIdentifierStrategy = exports.MultiDomainIdentifierStrategy = exports.SubdomainService = exports.LocalTunnelProvider = exports.CloudflareTunnelProvider = exports.CredentialReaderImpl = exports.CredentialReader = exports.EmbeddingServiceImpl = exports.EmbeddingService = exports.ProviderRegistryImpl = exports.ProviderRegistry = exports.VectorHttpHandler = exports.PostgresVectorStore = exports.SqliteVectorStore = exports.VectorStore = void 0;
|
|
3
|
+
exports.SqliteQuintStore = exports.QuintStore = exports.ReactAppViewHandler = exports.PodRoutingHttpHandler = exports.CenterNodeRegistrationService = exports.UsageTrackingStore = exports.ClusterIdentifierStrategy = exports.EdgeNodeModeDetector = exports.AcmeCertificateManager = exports.EdgeNodeCertificateService = exports.EdgeNodeAgent = exports.EdgeNodeHealthProbeService = exports.FrpTunnelManager = exports.NoopEdgeNodeTunnelManager = exports.SimpleEdgeNodeTunnelManager = exports.Dns01CertificateProvisioner = exports.EdgeNodeDnsCoordinator = exports.TencentDnsProvider = exports.PerAccountQuotaStrategy = exports.NoopEntitlementProvider = exports.HttpEntitlementProvider = exports.NoopQuotaService = exports.DrizzleQuotaService = exports.SqliteKeyValueStorage = exports.RedisKeyValueStorage = exports.PostgresKeyValueStorage = exports.DrizzleIndexedStorage = exports.ReservedSuffixIdentifierGenerator = exports.TerminalHttpHandler = exports.EdgeNodeCertificateHttpHandler = exports.TracingHandler = exports.RouterHttpRoute = exports.RouterHttpHandler = exports.EdgeNodeProxyHttpHandler = exports.EdgeNodeDirectDebugHttpHandler = exports.ClusterWebSocketConfigurator = exports.ClusterIngressRouter = exports.QuotaAdminHttpHandler = exports.SubgraphSparqlHttpHandler = exports.QuintstoreSparqlEngine = exports.QuadstoreSparqlEngine = exports.SubgraphQueryEngine = exports.SparqlUpdateResourceStore = exports.ConfigurableLoggerFactory = exports.MixDataAccessor = exports.QuintStoreSparqlDataAccessor = exports.QuadstoreSparqlDataAccessor = exports.MinioDataAccessor = exports.RepresentationPartialConvertingStore = exports.AppStaticAssetHandler = void 0;
|
|
4
|
+
exports.AuthModeSelector = exports.ProvisionCodeCodec = exports.ProvisionPodCreator = exports.UrlAwareRedisLocker = exports.AutoDetectIdentityProviderHandler = exports.AutoDetectOidcHandler = exports.DisabledIdentityProviderHandler = exports.DisabledOidcHandler = exports.SubdomainPodIdentifierStrategy = exports.MultiDomainIdentifierStrategy = exports.SubdomainService = exports.LocalTunnelProvider = exports.CloudflareTunnelProvider = exports.CredentialReaderImpl = exports.CredentialReader = exports.EmbeddingServiceImpl = exports.EmbeddingService = exports.ProviderRegistryImpl = exports.ProviderRegistry = exports.VectorHttpHandler = exports.PostgresVectorStore = exports.SqliteVectorStore = exports.VectorStore = exports.BaseQuintStore = exports.PgQuintStore = void 0;
|
|
5
5
|
require("./runtime/configure-drizzle-solid");
|
|
6
6
|
const RepresentationPartialConvertingStore_1 = require("./storage/RepresentationPartialConvertingStore");
|
|
7
7
|
Object.defineProperty(exports, "RepresentationPartialConvertingStore", { enumerable: true, get: function () { return RepresentationPartialConvertingStore_1.RepresentationPartialConvertingStore; } });
|
|
@@ -57,6 +57,9 @@ const DrizzleQuotaService_1 = require("./quota/DrizzleQuotaService");
|
|
|
57
57
|
Object.defineProperty(exports, "DrizzleQuotaService", { enumerable: true, get: function () { return DrizzleQuotaService_1.DrizzleQuotaService; } });
|
|
58
58
|
const NoopQuotaService_1 = require("./quota/NoopQuotaService");
|
|
59
59
|
Object.defineProperty(exports, "NoopQuotaService", { enumerable: true, get: function () { return NoopQuotaService_1.NoopQuotaService; } });
|
|
60
|
+
const EntitlementProvider_1 = require("./quota/EntitlementProvider");
|
|
61
|
+
Object.defineProperty(exports, "HttpEntitlementProvider", { enumerable: true, get: function () { return EntitlementProvider_1.HttpEntitlementProvider; } });
|
|
62
|
+
Object.defineProperty(exports, "NoopEntitlementProvider", { enumerable: true, get: function () { return EntitlementProvider_1.NoopEntitlementProvider; } });
|
|
60
63
|
const PerAccountQuotaStrategy_1 = require("./storage/quota/PerAccountQuotaStrategy");
|
|
61
64
|
Object.defineProperty(exports, "PerAccountQuotaStrategy", { enumerable: true, get: function () { return PerAccountQuotaStrategy_1.PerAccountQuotaStrategy; } });
|
|
62
65
|
const TencentDnsProvider_1 = require("./dns/tencent/TencentDnsProvider");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,6CAA2C;AAC3C,yGAAsG;AAuGlG,qHAvGK,2EAAoC,OAuGL;AAtGxC,6EAA0E;AAuGtE,kGAvGK,qCAAiB,OAuGL;AAtGrB,iGAA8F;AAuG1F,4GAvGK,yDAA2B,OAuGL;AAtG/B,mGAAgG;AAuG5F,6GAvGK,2DAA4B,OAuGL;AAtGhC,yEAAsE;AAuGlE,gGAvGK,iCAAe,OAuGL;AAtGnB,mFAAgF;AAuG5E,0GAvGK,qDAAyB,OAuGL;AAtG7B,8EAA0H;AAwGtH,oGAxGK,yCAAmB,OAwGL;AACnB,sGAzG0B,2CAAqB,OAyG1B;AACrB,uGA1GiD,4CAAsB,OA0GjD;AAxG1B,gFAA6E;AAyGzE,0GAzGK,qDAAyB,OAyGL;AAxG7B,8EAA2E;AAyGvE,sGAzGK,6CAAqB,OAyGL;AAxGzB,mFAAgF;AAmG5E,0GAnGK,qDAAyB,OAmGL;AAlG7B,sEAAmE;AAwG/D,qGAxGK,2CAAoB,OAwGL;AAvGxB,sFAAmF;AAwG/E,6GAxGK,2DAA4B,OAwGL;AAvGhC,0FAAuF;AAwGnF,+GAxGK,+DAA8B,OAwGL;AAvGlC,8EAA2E;AAwGvE,yGAxGK,mDAAwB,OAwGL;AAvG5B,gEAA6D;AAwGzD,kGAxGK,qCAAiB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A+B,OAyGP;AAxGjC,iFAA8E;AAyG5E,sGAzGO,6CAAqB,OAyGP;AAxGvB,yGAAsG;AAyGpG,kHAzGO,qEAAiC,OAyGP;AAxGnC,uBAAuB;AACvB,yEAAsE;AA0GpE,oGA1GO,yCAAmB,OA0GP;AAzGrB,uEAAoE;AA0GlE,mGA1GO,uCAAkB,OA0GP;AAzGpB,2BAA2B;AAC3B,uEAAoE;AA0GlE,iGA1GO,mCAAgB,OA0GP;AAlFlB,uCAAuC;AACvC,sEAAqE;AAA5D,8HAAA,qBAAqB,OAAA","sourcesContent":["import './runtime/configure-drizzle-solid';\nimport { RepresentationPartialConvertingStore } from './storage/RepresentationPartialConvertingStore';\nimport { MinioDataAccessor } from './storage/accessors/MinioDataAccessor';\nimport { QuadstoreSparqlDataAccessor } from './storage/accessors/QuadstoreSparqlDataAccessor';\nimport { QuintStoreSparqlDataAccessor } from './storage/accessors/QuintStoreSparqlDataAccessor';\nimport { MixDataAccessor } from './storage/accessors/MixDataAccessor';\nimport { ConfigurableLoggerFactory } from './logging/ConfigurableLoggerFactory';\nimport { SubgraphQueryEngine, QuadstoreSparqlEngine, QuintstoreSparqlEngine } from './storage/sparql/SubgraphQueryEngine';\nexport type { SparqlEngine } from './storage/sparql/SubgraphQueryEngine';\nimport { SubgraphSparqlHttpHandler } from './http/SubgraphSparqlHttpHandler';\nimport { QuotaAdminHttpHandler } from './http/quota/QuotaAdminHttpHandler';\nimport { SparqlUpdateResourceStore } from './storage/SparqlUpdateResourceStore';\nimport { ClusterIngressRouter } from './http/ClusterIngressRouter';\nimport { ClusterWebSocketConfigurator } from './http/ClusterWebSocketConfigurator';\nimport { EdgeNodeDirectDebugHttpHandler } from './http/EdgeNodeDirectDebugHttpHandler';\nimport { EdgeNodeProxyHttpHandler } from './http/EdgeNodeProxyHttpHandler';\nimport { RouterHttpHandler } from './http/RouterHttpHandler';\nimport { RouterHttpRoute } from './http/RouterHttpRoute';\nimport { TracingHandler } from './http/TracingHandler';\nimport { TerminalHttpHandler } from './http/terminal/TerminalHttpHandler';\nimport { EdgeNodeCertificateHttpHandler } from './http/admin/EdgeNodeCertificateHttpHandler';\nimport { ReservedSuffixIdentifierGenerator } from './pods/ReservedSuffixIdentifierGenerator';\nimport { DrizzleIndexedStorage } from './identity/drizzle/DrizzleIndexedStorage';\nimport { PostgresKeyValueStorage } from './storage/keyvalue/PostgresKeyValueStorage';\nimport { RedisKeyValueStorage } from './storage/keyvalue/RedisKeyValueStorage';\nimport { SqliteKeyValueStorage } from './storage/keyvalue/SqliteKeyValueStorage';\nimport { DrizzleQuotaService } from './quota/DrizzleQuotaService';\nimport { NoopQuotaService } from './quota/NoopQuotaService';\nimport { PerAccountQuotaStrategy } from './storage/quota/PerAccountQuotaStrategy';\nimport { TencentDnsProvider } from './dns/tencent/TencentDnsProvider';\nimport { EdgeNodeDnsCoordinator } from './edge/EdgeNodeDnsCoordinator';\nimport { Dns01CertificateProvisioner } from './edge/Dns01CertificateProvisioner';\nimport { SimpleEdgeNodeTunnelManager, NoopEdgeNodeTunnelManager } from './edge/EdgeNodeTunnelManager';\nimport { FrpTunnelManager } from './edge/FrpTunnelManager';\nimport { AcmeCertificateManager } from './edge/acme/AcmeCertificateManager';\nimport { EdgeNodeHealthProbeService } from './edge/EdgeNodeHealthProbeService';\nimport { EdgeNodeAgent } from './edge/EdgeNodeAgent';\nimport { EdgeNodeCertificateService } from './service/EdgeNodeCertificateService';\nimport { createBandwidthThrottleTransform } from './util/stream/BandwidthThrottleTransform';\nimport { UsageTrackingStore } from './storage/quota/UsageTrackingStore';\nimport { EdgeNodeModeDetector } from './edge/EdgeNodeModeDetector';\nimport { ClusterIdentifierStrategy } from './util/identifiers/ClusterIdentifierStrategy';\nimport { CenterNodeRegistrationService } from './identity/CenterNodeRegistrationService';\nimport { PodRoutingHttpHandler } from './http/PodRoutingHttpHandler';\nimport { ReactAppViewHandler } from './identity/ReactAppViewHandler';\nimport { SqliteQuintStore } from './storage/quint/SqliteQuintStore';\nimport { PgQuintStore } from './storage/quint/PgQuintStore';\nimport { BaseQuintStore } from './storage/quint/BaseQuintStore';\nimport { QuintStore } from './storage/quint/types';\nimport type { EdgeNodeCertificateProvisioner } from './edge/EdgeNodeCertificateProvisioner';\n// Vector components\nimport { SqliteVectorStore, PostgresVectorStore } from './storage/vector/index';\nimport { VectorHttpHandler } from './http/vector/VectorHttpHandler';\nimport { ProviderRegistry } from './ai/service/ProviderRegistry';\nimport { ProviderRegistryImpl } from './ai/service/ProviderRegistryImpl';\nimport { EmbeddingService } from './ai/service/EmbeddingService';\nimport { EmbeddingServiceImpl } from './ai/service/EmbeddingServiceImpl';\nimport { CredentialReader } from './ai/service/CredentialReader';\nimport { CredentialReaderImpl } from './ai/service/CredentialReaderImpl';\nimport { VectorStore } from './storage/vector/VectorStore';\n// Tunnel and Subdomain components\nimport { CloudflareTunnelProvider } from './tunnel/CloudflareTunnelProvider';\nimport { LocalTunnelProvider } from './tunnel/LocalTunnelProvider';\nimport { SubdomainService } from './subdomain/SubdomainService';\nimport { UrlAwareRedisLocker } from './storage/locking/UrlAwareRedisLocker';\n// IdP/SP separation components\nimport { MultiDomainIdentifierStrategy } from './util/identifiers/MultiDomainIdentifierStrategy';\nimport { SubdomainPodIdentifierStrategy } from './util/identifiers/SubdomainPodIdentifierStrategy';\nimport { DisabledOidcHandler } from './identity/oidc/DisabledOidcHandler';\nimport { DisabledIdentityProviderHandler } from './identity/oidc/DisabledIdentityProviderHandler';\nimport { AutoDetectOidcHandler } from './identity/oidc/AutoDetectOidcHandler';\nimport { AutoDetectIdentityProviderHandler } from './identity/oidc/AutoDetectIdentityProviderHandler';\n// Provision components\nimport { ProvisionPodCreator } from './provision/ProvisionPodCreator';\nimport { ProvisionCodeCodec } from './provision/ProvisionCodeCodec';\n// Authorization components\nimport { AuthModeSelector } from './authorization/AuthModeSelector';\nexport type {\n DnsProvider,\n ListDnsRecordsInput,\n ListableDnsProvider,\n DeleteDnsRecordInput,\n DnsRecordSummary,\n UpsertDnsRecordInput,\n} from './dns/DnsProvider';\nexport type { EdgeNodeCertificateProvisioner } from './edge/EdgeNodeCertificateProvisioner';\nexport type { EdgeNodeTunnelManager } from './edge/interfaces/EdgeNodeTunnelManager';\nexport type { QuotaService, AccountQuota } from './quota/QuotaService';\n// Tunnel and Subdomain types\nexport type {\n TunnelProvider,\n TunnelConfig,\n TunnelSetupOptions,\n TunnelStatus,\n} from './tunnel/TunnelProvider';\nexport type {\n SubdomainRegistration,\n ConnectivityResult,\n SubdomainServiceOptions,\n} from './subdomain/SubdomainService';\n// Export the new AppStaticAssetHandler\nexport { AppStaticAssetHandler } from './http/AppStaticAssetHandler';\n\nexport { \n RepresentationPartialConvertingStore,\n MinioDataAccessor, \n QuadstoreSparqlDataAccessor,\n QuintStoreSparqlDataAccessor,\n MixDataAccessor,\n ConfigurableLoggerFactory,\n SparqlUpdateResourceStore,\n SubgraphQueryEngine,\n QuadstoreSparqlEngine,\n QuintstoreSparqlEngine,\n SubgraphSparqlHttpHandler,\n QuotaAdminHttpHandler,\n ClusterIngressRouter,\n ClusterWebSocketConfigurator,\n EdgeNodeDirectDebugHttpHandler,\n EdgeNodeProxyHttpHandler,\n RouterHttpHandler,\n RouterHttpRoute,\n TracingHandler,\n EdgeNodeCertificateHttpHandler,\n TerminalHttpHandler,\n ReservedSuffixIdentifierGenerator,\n DrizzleIndexedStorage,\n PostgresKeyValueStorage,\n RedisKeyValueStorage,\n SqliteKeyValueStorage,\n DrizzleQuotaService,\n NoopQuotaService,\n PerAccountQuotaStrategy,\n TencentDnsProvider,\n EdgeNodeDnsCoordinator,\n Dns01CertificateProvisioner,\n SimpleEdgeNodeTunnelManager,\n NoopEdgeNodeTunnelManager,\n FrpTunnelManager,\n EdgeNodeHealthProbeService,\n EdgeNodeAgent,\n EdgeNodeCertificateService,\n AcmeCertificateManager,\n EdgeNodeModeDetector,\n ClusterIdentifierStrategy,\n UsageTrackingStore,\n CenterNodeRegistrationService,\n PodRoutingHttpHandler,\n ReactAppViewHandler,\n // Quint exports\n QuintStore,\n SqliteQuintStore,\n PgQuintStore,\n BaseQuintStore,\n // Vector exports\n VectorStore,\n SqliteVectorStore,\n PostgresVectorStore,\n VectorHttpHandler,\n // Embedding exports\n ProviderRegistry,\n ProviderRegistryImpl,\n EmbeddingService,\n EmbeddingServiceImpl,\n CredentialReader,\n CredentialReaderImpl,\n // Tunnel and Subdomain exports\n CloudflareTunnelProvider,\n LocalTunnelProvider,\n SubdomainService,\n // IdP/SP separation exports\n MultiDomainIdentifierStrategy,\n SubdomainPodIdentifierStrategy,\n DisabledOidcHandler,\n DisabledIdentityProviderHandler,\n AutoDetectOidcHandler,\n AutoDetectIdentityProviderHandler,\n UrlAwareRedisLocker,\n // Provision exports\n ProvisionPodCreator,\n ProvisionCodeCodec,\n // Authorization exports\n AuthModeSelector,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,6CAA2C;AAC3C,yGAAsG;AAyGlG,qHAzGK,2EAAoC,OAyGL;AAxGxC,6EAA0E;AAyGtE,kGAzGK,qCAAiB,OAyGL;AAxGrB,iGAA8F;AAyG1F,4GAzGK,yDAA2B,OAyGL;AAxG/B,mGAAgG;AAyG5F,6GAzGK,2DAA4B,OAyGL;AAxGhC,yEAAsE;AAyGlE,gGAzGK,iCAAe,OAyGL;AAxGnB,mFAAgF;AAyG5E,0GAzGK,qDAAyB,OAyGL;AAxG7B,8EAA0H;AA0GtH,oGA1GK,yCAAmB,OA0GL;AACnB,sGA3G0B,2CAAqB,OA2G1B;AACrB,uGA5GiD,4CAAsB,OA4GjD;AA1G1B,gFAA6E;AA2GzE,0GA3GK,qDAAyB,OA2GL;AA1G7B,8EAA2E;AA2GvE,sGA3GK,6CAAqB,OA2GL;AA1GzB,mFAAgF;AAqG5E,0GArGK,qDAAyB,OAqGL;AApG7B,sEAAmE;AA0G/D,qGA1GK,2CAAoB,OA0GL;AAzGxB,sFAAmF;AA0G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AA5GlB,+EAA4E;AAoH1E,oGApHO,yCAAmB,OAoHP;AAnHrB,+BAA+B;AAC/B,oGAAiG;AA4G/F,8GA5GO,6DAA6B,OA4GP;AA3G/B,sGAAmG;AA4GjG,+GA5GO,+DAA8B,OA4GP;AA3GhC,6EAA0E;AA4GxE,oGA5GO,yCAAmB,OA4GP;AA3GrB,qGAAkG;AA4GhG,gHA5GO,iEAA+B,OA4GP;AA3GjC,iFAA8E;AA4G5E,sGA5GO,6CAAqB,OA4GP;AA3GvB,yGAAsG;AA4GpG,kHA5GO,qEAAiC,OA4GP;AA3GnC,uBAAuB;AACvB,yEAAsE;AA6GpE,oGA7GO,yCAAmB,OA6GP;AA5GrB,uEAAoE;AA6GlE,mGA7GO,uCAAkB,OA6GP;AA5GpB,2BAA2B;AAC3B,uEAAoE;AA6GlE,iGA7GO,mCAAgB,OA6GP;AApFlB,uCAAuC;AACvC,sEAAqE;AAA5D,8HAAA,qBAAqB,OAAA","sourcesContent":["import './runtime/configure-drizzle-solid';\nimport { RepresentationPartialConvertingStore } from './storage/RepresentationPartialConvertingStore';\nimport { MinioDataAccessor } from './storage/accessors/MinioDataAccessor';\nimport { QuadstoreSparqlDataAccessor } from './storage/accessors/QuadstoreSparqlDataAccessor';\nimport { QuintStoreSparqlDataAccessor } from './storage/accessors/QuintStoreSparqlDataAccessor';\nimport { MixDataAccessor } from './storage/accessors/MixDataAccessor';\nimport { ConfigurableLoggerFactory } from './logging/ConfigurableLoggerFactory';\nimport { SubgraphQueryEngine, QuadstoreSparqlEngine, QuintstoreSparqlEngine } from './storage/sparql/SubgraphQueryEngine';\nexport type { SparqlEngine } from './storage/sparql/SubgraphQueryEngine';\nimport { SubgraphSparqlHttpHandler } from './http/SubgraphSparqlHttpHandler';\nimport { QuotaAdminHttpHandler } from './http/quota/QuotaAdminHttpHandler';\nimport { SparqlUpdateResourceStore } from './storage/SparqlUpdateResourceStore';\nimport { ClusterIngressRouter } from './http/ClusterIngressRouter';\nimport { ClusterWebSocketConfigurator } from './http/ClusterWebSocketConfigurator';\nimport { EdgeNodeDirectDebugHttpHandler } from './http/EdgeNodeDirectDebugHttpHandler';\nimport { EdgeNodeProxyHttpHandler } from './http/EdgeNodeProxyHttpHandler';\nimport { RouterHttpHandler } from './http/RouterHttpHandler';\nimport { RouterHttpRoute } from './http/RouterHttpRoute';\nimport { TracingHandler } from './http/TracingHandler';\nimport { TerminalHttpHandler } from './http/terminal/TerminalHttpHandler';\nimport { EdgeNodeCertificateHttpHandler } from './http/admin/EdgeNodeCertificateHttpHandler';\nimport { ReservedSuffixIdentifierGenerator } from './pods/ReservedSuffixIdentifierGenerator';\nimport { DrizzleIndexedStorage } from './identity/drizzle/DrizzleIndexedStorage';\nimport { PostgresKeyValueStorage } from './storage/keyvalue/PostgresKeyValueStorage';\nimport { RedisKeyValueStorage } from './storage/keyvalue/RedisKeyValueStorage';\nimport { SqliteKeyValueStorage } from './storage/keyvalue/SqliteKeyValueStorage';\nimport { DrizzleQuotaService } from './quota/DrizzleQuotaService';\nimport { NoopQuotaService } from './quota/NoopQuotaService';\nimport { HttpEntitlementProvider, NoopEntitlementProvider } from './quota/EntitlementProvider';\nimport { PerAccountQuotaStrategy } from './storage/quota/PerAccountQuotaStrategy';\nimport { TencentDnsProvider } from './dns/tencent/TencentDnsProvider';\nimport { EdgeNodeDnsCoordinator } from './edge/EdgeNodeDnsCoordinator';\nimport { Dns01CertificateProvisioner } from './edge/Dns01CertificateProvisioner';\nimport { SimpleEdgeNodeTunnelManager, NoopEdgeNodeTunnelManager } from './edge/EdgeNodeTunnelManager';\nimport { FrpTunnelManager } from './edge/FrpTunnelManager';\nimport { AcmeCertificateManager } from './edge/acme/AcmeCertificateManager';\nimport { EdgeNodeHealthProbeService } from './edge/EdgeNodeHealthProbeService';\nimport { EdgeNodeAgent } from './edge/EdgeNodeAgent';\nimport { EdgeNodeCertificateService } from './service/EdgeNodeCertificateService';\nimport { createBandwidthThrottleTransform } from './util/stream/BandwidthThrottleTransform';\nimport { UsageTrackingStore } from './storage/quota/UsageTrackingStore';\nimport { EdgeNodeModeDetector } from './edge/EdgeNodeModeDetector';\nimport { ClusterIdentifierStrategy } from './util/identifiers/ClusterIdentifierStrategy';\nimport { CenterNodeRegistrationService } from './identity/CenterNodeRegistrationService';\nimport { PodRoutingHttpHandler } from './http/PodRoutingHttpHandler';\nimport { ReactAppViewHandler } from './identity/ReactAppViewHandler';\nimport { SqliteQuintStore } from './storage/quint/SqliteQuintStore';\nimport { PgQuintStore } from './storage/quint/PgQuintStore';\nimport { BaseQuintStore } from './storage/quint/BaseQuintStore';\nimport { QuintStore } from './storage/quint/types';\nimport type { EdgeNodeCertificateProvisioner } from './edge/EdgeNodeCertificateProvisioner';\n// Vector components\nimport { SqliteVectorStore, PostgresVectorStore } from './storage/vector/index';\nimport { VectorHttpHandler } from './http/vector/VectorHttpHandler';\nimport { ProviderRegistry } from './ai/service/ProviderRegistry';\nimport { ProviderRegistryImpl } from './ai/service/ProviderRegistryImpl';\nimport { EmbeddingService } from './ai/service/EmbeddingService';\nimport { EmbeddingServiceImpl } from './ai/service/EmbeddingServiceImpl';\nimport { CredentialReader } from './ai/service/CredentialReader';\nimport { CredentialReaderImpl } from './ai/service/CredentialReaderImpl';\nimport { VectorStore } from './storage/vector/VectorStore';\n// Tunnel and Subdomain components\nimport { CloudflareTunnelProvider } from './tunnel/CloudflareTunnelProvider';\nimport { LocalTunnelProvider } from './tunnel/LocalTunnelProvider';\nimport { SubdomainService } from './subdomain/SubdomainService';\nimport { UrlAwareRedisLocker } from './storage/locking/UrlAwareRedisLocker';\n// IdP/SP separation components\nimport { MultiDomainIdentifierStrategy } from './util/identifiers/MultiDomainIdentifierStrategy';\nimport { SubdomainPodIdentifierStrategy } from './util/identifiers/SubdomainPodIdentifierStrategy';\nimport { DisabledOidcHandler } from './identity/oidc/DisabledOidcHandler';\nimport { DisabledIdentityProviderHandler } from './identity/oidc/DisabledIdentityProviderHandler';\nimport { AutoDetectOidcHandler } from './identity/oidc/AutoDetectOidcHandler';\nimport { AutoDetectIdentityProviderHandler } from './identity/oidc/AutoDetectIdentityProviderHandler';\n// Provision components\nimport { ProvisionPodCreator } from './provision/ProvisionPodCreator';\nimport { ProvisionCodeCodec } from './provision/ProvisionCodeCodec';\n// Authorization components\nimport { AuthModeSelector } from './authorization/AuthModeSelector';\nexport type {\n DnsProvider,\n ListDnsRecordsInput,\n ListableDnsProvider,\n DeleteDnsRecordInput,\n DnsRecordSummary,\n UpsertDnsRecordInput,\n} from './dns/DnsProvider';\nexport type { EdgeNodeCertificateProvisioner } from './edge/EdgeNodeCertificateProvisioner';\nexport type { EdgeNodeTunnelManager } from './edge/interfaces/EdgeNodeTunnelManager';\nexport type { QuotaService, AccountQuota } from './quota/QuotaService';\nexport type { EntitlementProvider, AccountEntitlement } from './quota/EntitlementProvider';\n// Tunnel and Subdomain types\nexport type {\n TunnelProvider,\n TunnelConfig,\n TunnelSetupOptions,\n TunnelStatus,\n} from './tunnel/TunnelProvider';\nexport type {\n SubdomainRegistration,\n ConnectivityResult,\n SubdomainServiceOptions,\n} from './subdomain/SubdomainService';\n// Export the new AppStaticAssetHandler\nexport { AppStaticAssetHandler } from './http/AppStaticAssetHandler';\n\nexport { \n RepresentationPartialConvertingStore,\n MinioDataAccessor, \n QuadstoreSparqlDataAccessor,\n QuintStoreSparqlDataAccessor,\n MixDataAccessor,\n ConfigurableLoggerFactory,\n SparqlUpdateResourceStore,\n SubgraphQueryEngine,\n QuadstoreSparqlEngine,\n QuintstoreSparqlEngine,\n SubgraphSparqlHttpHandler,\n QuotaAdminHttpHandler,\n ClusterIngressRouter,\n ClusterWebSocketConfigurator,\n EdgeNodeDirectDebugHttpHandler,\n EdgeNodeProxyHttpHandler,\n RouterHttpHandler,\n RouterHttpRoute,\n TracingHandler,\n EdgeNodeCertificateHttpHandler,\n TerminalHttpHandler,\n ReservedSuffixIdentifierGenerator,\n DrizzleIndexedStorage,\n PostgresKeyValueStorage,\n RedisKeyValueStorage,\n SqliteKeyValueStorage,\n DrizzleQuotaService,\n NoopQuotaService,\n HttpEntitlementProvider,\n NoopEntitlementProvider,\n PerAccountQuotaStrategy,\n TencentDnsProvider,\n EdgeNodeDnsCoordinator,\n Dns01CertificateProvisioner,\n SimpleEdgeNodeTunnelManager,\n NoopEdgeNodeTunnelManager,\n FrpTunnelManager,\n EdgeNodeHealthProbeService,\n EdgeNodeAgent,\n EdgeNodeCertificateService,\n AcmeCertificateManager,\n EdgeNodeModeDetector,\n ClusterIdentifierStrategy,\n UsageTrackingStore,\n CenterNodeRegistrationService,\n PodRoutingHttpHandler,\n ReactAppViewHandler,\n // Quint exports\n QuintStore,\n SqliteQuintStore,\n PgQuintStore,\n BaseQuintStore,\n // Vector exports\n VectorStore,\n SqliteVectorStore,\n PostgresVectorStore,\n VectorHttpHandler,\n // Embedding exports\n ProviderRegistry,\n ProviderRegistryImpl,\n EmbeddingService,\n EmbeddingServiceImpl,\n CredentialReader,\n CredentialReaderImpl,\n // Tunnel and Subdomain exports\n CloudflareTunnelProvider,\n LocalTunnelProvider,\n SubdomainService,\n // IdP/SP separation exports\n MultiDomainIdentifierStrategy,\n SubdomainPodIdentifierStrategy,\n DisabledOidcHandler,\n DisabledIdentityProviderHandler,\n AutoDetectOidcHandler,\n AutoDetectIdentityProviderHandler,\n UrlAwareRedisLocker,\n // Provision exports\n ProvisionPodCreator,\n ProvisionCodeCodec,\n // Authorization exports\n AuthModeSelector,\n};\n"]}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import type { QuotaService, AccountQuota } from './QuotaService';
|
|
2
|
+
import type { EntitlementProvider } from './EntitlementProvider';
|
|
2
3
|
interface DrizzleQuotaServiceOptions {
|
|
3
4
|
identityDbUrl: string;
|
|
5
|
+
entitlementProvider?: EntitlementProvider;
|
|
4
6
|
}
|
|
5
7
|
/**
|
|
6
8
|
* 统一 QuotaService 实现
|
|
7
9
|
*
|
|
8
|
-
*
|
|
10
|
+
* 查询优先级:本地自定义配额 > 远端 entitlement > 环境变量默认值 > 不限制 (null)
|
|
9
11
|
*/
|
|
10
12
|
export declare class DrizzleQuotaService implements QuotaService {
|
|
11
13
|
private readonly logger;
|
|
12
14
|
private readonly accountRepo;
|
|
13
15
|
private readonly usageRepo;
|
|
16
|
+
private readonly entitlementProvider;
|
|
14
17
|
constructor(options: DrizzleQuotaServiceOptions);
|
|
15
18
|
getAccountQuota(accountId: string): Promise<AccountQuota>;
|
|
16
19
|
setAccountQuota(accountId: string, quota: Partial<AccountQuota>): Promise<void>;
|
|
@@ -23,8 +26,9 @@ export declare class DrizzleQuotaService implements QuotaService {
|
|
|
23
26
|
setAccountLimit(accountId: string, limit: number | null): Promise<void>;
|
|
24
27
|
setPodLimit(podId: string, limit: number | null): Promise<void>;
|
|
25
28
|
/**
|
|
26
|
-
*
|
|
29
|
+
* 解析配额值:本地自定义配额 > 远端 entitlement > 环境变量默认值 > null (不限制)
|
|
27
30
|
*/
|
|
28
31
|
private resolve;
|
|
32
|
+
private needsRemoteEntitlement;
|
|
29
33
|
}
|
|
30
34
|
export {};
|
|
@@ -5,6 +5,7 @@ const global_logger_factory_1 = require("global-logger-factory");
|
|
|
5
5
|
const db_1 = require("../identity/drizzle/db");
|
|
6
6
|
const AccountRepository_1 = require("../identity/drizzle/AccountRepository");
|
|
7
7
|
const UsageRepository_1 = require("../storage/quota/UsageRepository");
|
|
8
|
+
const EntitlementProvider_1 = require("./EntitlementProvider");
|
|
8
9
|
/**
|
|
9
10
|
* 环境变量默认值
|
|
10
11
|
*/
|
|
@@ -19,7 +20,7 @@ function envNumber(key) {
|
|
|
19
20
|
/**
|
|
20
21
|
* 统一 QuotaService 实现
|
|
21
22
|
*
|
|
22
|
-
*
|
|
23
|
+
* 查询优先级:本地自定义配额 > 远端 entitlement > 环境变量默认值 > 不限制 (null)
|
|
23
24
|
*/
|
|
24
25
|
class DrizzleQuotaService {
|
|
25
26
|
constructor(options) {
|
|
@@ -27,14 +28,18 @@ class DrizzleQuotaService {
|
|
|
27
28
|
const db = (0, db_1.getIdentityDatabase)(options.identityDbUrl);
|
|
28
29
|
this.accountRepo = new AccountRepository_1.AccountRepository(db);
|
|
29
30
|
this.usageRepo = new UsageRepository_1.UsageRepository(db);
|
|
31
|
+
this.entitlementProvider = options.entitlementProvider ?? (0, EntitlementProvider_1.createEntitlementProviderFromEnv)();
|
|
30
32
|
}
|
|
31
33
|
async getAccountQuota(accountId) {
|
|
32
34
|
const usage = await this.usageRepo.getAccountUsage(accountId);
|
|
35
|
+
const entitlement = this.needsRemoteEntitlement(usage)
|
|
36
|
+
? await this.entitlementProvider.getAccountEntitlement(accountId)
|
|
37
|
+
: undefined;
|
|
33
38
|
return {
|
|
34
|
-
storageLimitBytes: this.resolve(usage?.storageLimitBytes, 'XPOD_DEFAULT_STORAGE_LIMIT_BYTES'),
|
|
35
|
-
bandwidthLimitBps: this.resolve(usage?.bandwidthLimitBps, 'XPOD_DEFAULT_BANDWIDTH_LIMIT_BPS'),
|
|
36
|
-
computeLimitSeconds: this.resolve(usage?.computeLimitSeconds, 'XPOD_DEFAULT_COMPUTE_LIMIT_SECONDS'),
|
|
37
|
-
tokenLimitMonthly: this.resolve(usage?.tokenLimitMonthly, 'XPOD_DEFAULT_TOKEN_LIMIT_MONTHLY'),
|
|
39
|
+
storageLimitBytes: this.resolve(usage?.storageLimitBytes, entitlement?.quota.storageLimitBytes, 'XPOD_DEFAULT_STORAGE_LIMIT_BYTES'),
|
|
40
|
+
bandwidthLimitBps: this.resolve(usage?.bandwidthLimitBps, entitlement?.quota.bandwidthLimitBps, 'XPOD_DEFAULT_BANDWIDTH_LIMIT_BPS'),
|
|
41
|
+
computeLimitSeconds: this.resolve(usage?.computeLimitSeconds, entitlement?.quota.computeLimitSeconds, 'XPOD_DEFAULT_COMPUTE_LIMIT_SECONDS'),
|
|
42
|
+
tokenLimitMonthly: this.resolve(usage?.tokenLimitMonthly, entitlement?.quota.tokenLimitMonthly, 'XPOD_DEFAULT_TOKEN_LIMIT_MONTHLY'),
|
|
38
43
|
};
|
|
39
44
|
}
|
|
40
45
|
async setAccountQuota(accountId, quota) {
|
|
@@ -54,10 +59,10 @@ class DrizzleQuotaService {
|
|
|
54
59
|
async getPodQuota(podId) {
|
|
55
60
|
const usage = await this.usageRepo.getPodUsage(podId);
|
|
56
61
|
return {
|
|
57
|
-
storageLimitBytes: this.resolve(usage?.storageLimitBytes, 'XPOD_DEFAULT_STORAGE_LIMIT_BYTES'),
|
|
58
|
-
bandwidthLimitBps: this.resolve(usage?.bandwidthLimitBps, 'XPOD_DEFAULT_BANDWIDTH_LIMIT_BPS'),
|
|
59
|
-
computeLimitSeconds: this.resolve(usage?.computeLimitSeconds, 'XPOD_DEFAULT_COMPUTE_LIMIT_SECONDS'),
|
|
60
|
-
tokenLimitMonthly: this.resolve(usage?.tokenLimitMonthly, 'XPOD_DEFAULT_TOKEN_LIMIT_MONTHLY'),
|
|
62
|
+
storageLimitBytes: this.resolve(usage?.storageLimitBytes, undefined, 'XPOD_DEFAULT_STORAGE_LIMIT_BYTES'),
|
|
63
|
+
bandwidthLimitBps: this.resolve(usage?.bandwidthLimitBps, undefined, 'XPOD_DEFAULT_BANDWIDTH_LIMIT_BPS'),
|
|
64
|
+
computeLimitSeconds: this.resolve(usage?.computeLimitSeconds, undefined, 'XPOD_DEFAULT_COMPUTE_LIMIT_SECONDS'),
|
|
65
|
+
tokenLimitMonthly: this.resolve(usage?.tokenLimitMonthly, undefined, 'XPOD_DEFAULT_TOKEN_LIMIT_MONTHLY'),
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
async setPodQuota(podId, quota) {
|
|
@@ -122,16 +127,27 @@ class DrizzleQuotaService {
|
|
|
122
127
|
await this.usageRepo.setPodStorageLimit(podId, podInfo.accountId, limit);
|
|
123
128
|
}
|
|
124
129
|
/**
|
|
125
|
-
*
|
|
130
|
+
* 解析配额值:本地自定义配额 > 远端 entitlement > 环境变量默认值 > null (不限制)
|
|
126
131
|
*/
|
|
127
|
-
resolve(dbValue, envKey) {
|
|
132
|
+
resolve(dbValue, remoteValue, envKey) {
|
|
128
133
|
// DB 中有明确值(包括 0)
|
|
129
134
|
if (typeof dbValue === 'number') {
|
|
130
135
|
return dbValue;
|
|
131
136
|
}
|
|
137
|
+
if (remoteValue === null || typeof remoteValue === 'number') {
|
|
138
|
+
return remoteValue;
|
|
139
|
+
}
|
|
132
140
|
// 回退到环境变量
|
|
133
141
|
return envNumber(envKey);
|
|
134
142
|
}
|
|
143
|
+
needsRemoteEntitlement(usage) {
|
|
144
|
+
return ![
|
|
145
|
+
usage?.storageLimitBytes,
|
|
146
|
+
usage?.bandwidthLimitBps,
|
|
147
|
+
usage?.computeLimitSeconds,
|
|
148
|
+
usage?.tokenLimitMonthly,
|
|
149
|
+
].every((value) => typeof value === 'number');
|
|
150
|
+
}
|
|
135
151
|
}
|
|
136
152
|
exports.DrizzleQuotaService = DrizzleQuotaService;
|
|
137
153
|
//# sourceMappingURL=DrizzleQuotaService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DrizzleQuotaService.js","sourceRoot":"","sources":["../../src/quota/DrizzleQuotaService.ts"],"names":[],"mappings":";;;AAAA,iEAAqD;AACrD,+CAA6D;AAC7D,6EAA0E;AAC1E,sEAAmE;AAGnE;;GAEG;AACH,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AACvD,CAAC;AAMD;;;;GAIG;AACH,MAAa,mBAAmB;IAK9B,Y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AiB;QAC5C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QACpD,OAAO,KAAK,CAAC,iBAAiB,CAAC;IACjC,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,KAAa;QACpC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC,iBAAiB,CAAC;IACjC,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,SAAiB,EAAE,KAAoB;QAClE,MAAM,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAChE,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,KAAoB;QAC1D,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,OAAO,KAAK,yCAAyC,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACK,OAAO,CAAC,OAAkC,EAAE,MAAc;QAChE,iBAAiB;QACjB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,UAAU;QACV,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;CACF;AAhID,kDAgIC","sourcesContent":["import { getLoggerFor } from 'global-logger-factory';\nimport { getIdentityDatabase } from '../identity/drizzle/db';\nimport { AccountRepository } from '../identity/drizzle/AccountRepository';\nimport { UsageRepository } from '../storage/quota/UsageRepository';\nimport type { QuotaService, AccountQuota } from './QuotaService';\n\n/**\n * 环境变量默认值\n */\nfunction envNumber(key: string): number | null {\n const val = process.env[key];\n if (val === undefined || val === '') {\n return null;\n }\n const num = Number(val);\n return Number.isFinite(num) && num >= 0 ? num : null;\n}\n\ninterface DrizzleQuotaServiceOptions {\n identityDbUrl: string;\n}\n\n/**\n * 统一 QuotaService 实现\n *\n * 查询优先级:DB 值 > 环境变量默认值 > 不限制 (null)\n */\nexport class DrizzleQuotaService implements QuotaService {\n private readonly logger = getLoggerFor(this);\n private readonly accountRepo: AccountRepository;\n private readonly usageRepo: UsageRepository;\n\n public constructor(options: DrizzleQuotaServiceOptions) {\n const db = getIdentityDatabase(options.identityDbUrl);\n this.accountRepo = new AccountRepository(db);\n this.usageRepo = new UsageRepository(db);\n }\n\n public async getAccountQuota(accountId: string): Promise<AccountQuota> {\n const usage = await this.usageRepo.getAccountUsage(accountId);\n return {\n storageLimitBytes: this.resolve(usage?.storageLimitBytes, 'XPOD_DEFAULT_STORAGE_LIMIT_BYTES'),\n bandwidthLimitBps: this.resolve(usage?.bandwidthLimitBps, 'XPOD_DEFAULT_BANDWIDTH_LIMIT_BPS'),\n computeLimitSeconds: this.resolve(usage?.computeLimitSeconds, 'XPOD_DEFAULT_COMPUTE_LIMIT_SECONDS'),\n tokenLimitMonthly: this.resolve(usage?.tokenLimitMonthly, 'XPOD_DEFAULT_TOKEN_LIMIT_MONTHLY'),\n };\n }\n\n public async setAccountQuota(accountId: string, quota: Partial<AccountQuota>): Promise<void> {\n if (quota.storageLimitBytes !== undefined) {\n await this.usageRepo.setAccountStorageLimit(accountId, quota.storageLimitBytes);\n }\n if (quota.bandwidthLimitBps !== undefined) {\n await this.usageRepo.setAccountBandwidthLimit(accountId, quota.bandwidthLimitBps);\n }\n if (quota.computeLimitSeconds !== undefined) {\n await this.usageRepo.setAccountComputeLimit(accountId, quota.computeLimitSeconds);\n }\n if (quota.tokenLimitMonthly !== undefined) {\n await this.usageRepo.setAccountTokenLimit(accountId, quota.tokenLimitMonthly);\n }\n }\n\n public async getPodQuota(podId: string): Promise<AccountQuota> {\n const usage = await this.usageRepo.getPodUsage(podId);\n return {\n storageLimitBytes: this.resolve(usage?.storageLimitBytes, 'XPOD_DEFAULT_STORAGE_LIMIT_BYTES'),\n bandwidthLimitBps: this.resolve(usage?.bandwidthLimitBps, 'XPOD_DEFAULT_BANDWIDTH_LIMIT_BPS'),\n computeLimitSeconds: this.resolve(usage?.computeLimitSeconds, 'XPOD_DEFAULT_COMPUTE_LIMIT_SECONDS'),\n tokenLimitMonthly: this.resolve(usage?.tokenLimitMonthly, 'XPOD_DEFAULT_TOKEN_LIMIT_MONTHLY'),\n };\n }\n\n public async setPodQuota(podId: string, quota: Partial<AccountQuota>): Promise<void> {\n // Try to get pod info from CSS\n const podInfo = await this.accountRepo.getPodInfo(podId);\n\n // If pod doesn't exist in CSS, try to get accountId from usage table\n let accountId = podInfo?.accountId;\n if (!accountId) {\n const usage = await this.usageRepo.getPodUsage(podId);\n accountId = usage?.accountId;\n }\n\n // If still no accountId, use a placeholder (quota can be set before pod creation)\n if (!accountId) {\n accountId = 'unknown';\n }\n\n if (quota.storageLimitBytes !== undefined) {\n await this.usageRepo.setPodStorageLimit(podId, accountId, quota.storageLimitBytes);\n }\n if (quota.bandwidthLimitBps !== undefined) {\n await this.usageRepo.setPodBandwidthLimit(podId, accountId, quota.bandwidthLimitBps);\n }\n if (quota.computeLimitSeconds !== undefined) {\n await this.usageRepo.setPodComputeLimit(podId, accountId, quota.computeLimitSeconds);\n }\n if (quota.tokenLimitMonthly !== undefined) {\n await this.usageRepo.setPodTokenLimit(podId, accountId, quota.tokenLimitMonthly);\n }\n }\n\n public async clearAccountQuota(accountId: string): Promise<void> {\n await this.setAccountQuota(accountId, {\n storageLimitBytes: null,\n bandwidthLimitBps: null,\n computeLimitSeconds: null,\n tokenLimitMonthly: null,\n });\n }\n\n public async clearPodQuota(podId: string): Promise<void> {\n await this.setPodQuota(podId, {\n storageLimitBytes: null,\n bandwidthLimitBps: null,\n computeLimitSeconds: null,\n tokenLimitMonthly: null,\n });\n }\n\n // 向后兼容\n public async getAccountLimit(accountId: string): Promise<number | null | undefined> {\n const quota = await this.getAccountQuota(accountId);\n return quota.storageLimitBytes;\n }\n\n public async getPodLimit(podId: string): Promise<number | null | undefined> {\n const quota = await this.getPodQuota(podId);\n return quota.storageLimitBytes;\n }\n\n public async setAccountLimit(accountId: string, limit: number | null): Promise<void> {\n await this.usageRepo.setAccountStorageLimit(accountId, limit);\n }\n\n public async setPodLimit(podId: string, limit: number | null): Promise<void> {\n const podInfo = await this.accountRepo.getPodInfo(podId);\n if (!podInfo?.accountId) {\n throw new Error(`Pod ${podId} not found or has no associated account`);\n }\n await this.usageRepo.setPodStorageLimit(podId, podInfo.accountId, limit);\n }\n\n /**\n * 解析配额值:DB 值 > 环境变量默认值 > null (不限制)\n */\n private resolve(dbValue: number | null | undefined, envKey: string): number | null {\n // DB 中有明确值(包括 0)\n if (typeof dbValue === 'number') {\n return dbValue;\n }\n // 回退到环境变量\n return envNumber(envKey);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DrizzleQuotaService.js","sourceRoot":"","sources":["../../src/quota/DrizzleQuotaService.ts"],"names":[],"mappings":";;;AAAA,iEAAqD;AACrD,+CAA6D;AAC7D,6EAA0E;AAC1E,sEAAmE;AAGnE,+DAAyE;AAEzE;;GAEG;AACH,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AACvD,CAAC;AAOD;;;;GAIG;AACH,M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AC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACK,OAAO,CAAC,OAAkC,EAAE,WAAsC,EAAE,MAAc;QACxG,iBAAiB;QACjB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,IAAI,WAAW,KAAK,IAAI,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YAC5D,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,UAAU;QACV,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAEO,sBAAsB,CAAC,KAKlB;QACX,OAAO,CAAC;YACN,KAAK,EAAE,iBAAiB;YACxB,KAAK,EAAE,iBAAiB;YACxB,KAAK,EAAE,mBAAmB;YAC1B,KAAK,EAAE,iBAAiB;SACzB,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC;IAChD,CAAC;CACF;AAvJD,kDAuJC","sourcesContent":["import { getLoggerFor } from 'global-logger-factory';\nimport { getIdentityDatabase } from '../identity/drizzle/db';\nimport { AccountRepository } from '../identity/drizzle/AccountRepository';\nimport { UsageRepository } from '../storage/quota/UsageRepository';\nimport type { QuotaService, AccountQuota } from './QuotaService';\nimport type { EntitlementProvider } from './EntitlementProvider';\nimport { createEntitlementProviderFromEnv } from './EntitlementProvider';\n\n/**\n * 环境变量默认值\n */\nfunction envNumber(key: string): number | null {\n const val = process.env[key];\n if (val === undefined || val === '') {\n return null;\n }\n const num = Number(val);\n return Number.isFinite(num) && num >= 0 ? num : null;\n}\n\ninterface DrizzleQuotaServiceOptions {\n identityDbUrl: string;\n entitlementProvider?: EntitlementProvider;\n}\n\n/**\n * 统一 QuotaService 实现\n *\n * 查询优先级:本地自定义配额 > 远端 entitlement > 环境变量默认值 > 不限制 (null)\n */\nexport class DrizzleQuotaService implements QuotaService {\n private readonly logger = getLoggerFor(this);\n private readonly accountRepo: AccountRepository;\n private readonly usageRepo: UsageRepository;\n private readonly entitlementProvider: EntitlementProvider;\n\n public constructor(options: DrizzleQuotaServiceOptions) {\n const db = getIdentityDatabase(options.identityDbUrl);\n this.accountRepo = new AccountRepository(db);\n this.usageRepo = new UsageRepository(db);\n this.entitlementProvider = options.entitlementProvider ?? createEntitlementProviderFromEnv();\n }\n\n public async getAccountQuota(accountId: string): Promise<AccountQuota> {\n const usage = await this.usageRepo.getAccountUsage(accountId);\n const entitlement = this.needsRemoteEntitlement(usage)\n ? await this.entitlementProvider.getAccountEntitlement(accountId)\n : undefined;\n\n return {\n storageLimitBytes: this.resolve(usage?.storageLimitBytes, entitlement?.quota.storageLimitBytes, 'XPOD_DEFAULT_STORAGE_LIMIT_BYTES'),\n bandwidthLimitBps: this.resolve(usage?.bandwidthLimitBps, entitlement?.quota.bandwidthLimitBps, 'XPOD_DEFAULT_BANDWIDTH_LIMIT_BPS'),\n computeLimitSeconds: this.resolve(usage?.computeLimitSeconds, entitlement?.quota.computeLimitSeconds, 'XPOD_DEFAULT_COMPUTE_LIMIT_SECONDS'),\n tokenLimitMonthly: this.resolve(usage?.tokenLimitMonthly, entitlement?.quota.tokenLimitMonthly, 'XPOD_DEFAULT_TOKEN_LIMIT_MONTHLY'),\n };\n }\n\n public async setAccountQuota(accountId: string, quota: Partial<AccountQuota>): Promise<void> {\n if (quota.storageLimitBytes !== undefined) {\n await this.usageRepo.setAccountStorageLimit(accountId, quota.storageLimitBytes);\n }\n if (quota.bandwidthLimitBps !== undefined) {\n await this.usageRepo.setAccountBandwidthLimit(accountId, quota.bandwidthLimitBps);\n }\n if (quota.computeLimitSeconds !== undefined) {\n await this.usageRepo.setAccountComputeLimit(accountId, quota.computeLimitSeconds);\n }\n if (quota.tokenLimitMonthly !== undefined) {\n await this.usageRepo.setAccountTokenLimit(accountId, quota.tokenLimitMonthly);\n }\n }\n\n public async getPodQuota(podId: string): Promise<AccountQuota> {\n const usage = await this.usageRepo.getPodUsage(podId);\n return {\n storageLimitBytes: this.resolve(usage?.storageLimitBytes, undefined, 'XPOD_DEFAULT_STORAGE_LIMIT_BYTES'),\n bandwidthLimitBps: this.resolve(usage?.bandwidthLimitBps, undefined, 'XPOD_DEFAULT_BANDWIDTH_LIMIT_BPS'),\n computeLimitSeconds: this.resolve(usage?.computeLimitSeconds, undefined, 'XPOD_DEFAULT_COMPUTE_LIMIT_SECONDS'),\n tokenLimitMonthly: this.resolve(usage?.tokenLimitMonthly, undefined, 'XPOD_DEFAULT_TOKEN_LIMIT_MONTHLY'),\n };\n }\n\n public async setPodQuota(podId: string, quota: Partial<AccountQuota>): Promise<void> {\n // Try to get pod info from CSS\n const podInfo = await this.accountRepo.getPodInfo(podId);\n\n // If pod doesn't exist in CSS, try to get accountId from usage table\n let accountId = podInfo?.accountId;\n if (!accountId) {\n const usage = await this.usageRepo.getPodUsage(podId);\n accountId = usage?.accountId;\n }\n\n // If still no accountId, use a placeholder (quota can be set before pod creation)\n if (!accountId) {\n accountId = 'unknown';\n }\n\n if (quota.storageLimitBytes !== undefined) {\n await this.usageRepo.setPodStorageLimit(podId, accountId, quota.storageLimitBytes);\n }\n if (quota.bandwidthLimitBps !== undefined) {\n await this.usageRepo.setPodBandwidthLimit(podId, accountId, quota.bandwidthLimitBps);\n }\n if (quota.computeLimitSeconds !== undefined) {\n await this.usageRepo.setPodComputeLimit(podId, accountId, quota.computeLimitSeconds);\n }\n if (quota.tokenLimitMonthly !== undefined) {\n await this.usageRepo.setPodTokenLimit(podId, accountId, quota.tokenLimitMonthly);\n }\n }\n\n public async clearAccountQuota(accountId: string): Promise<void> {\n await this.setAccountQuota(accountId, {\n storageLimitBytes: null,\n bandwidthLimitBps: null,\n computeLimitSeconds: null,\n tokenLimitMonthly: null,\n });\n }\n\n public async clearPodQuota(podId: string): Promise<void> {\n await this.setPodQuota(podId, {\n storageLimitBytes: null,\n bandwidthLimitBps: null,\n computeLimitSeconds: null,\n tokenLimitMonthly: null,\n });\n }\n\n // 向后兼容\n public async getAccountLimit(accountId: string): Promise<number | null | undefined> {\n const quota = await this.getAccountQuota(accountId);\n return quota.storageLimitBytes;\n }\n\n public async getPodLimit(podId: string): Promise<number | null | undefined> {\n const quota = await this.getPodQuota(podId);\n return quota.storageLimitBytes;\n }\n\n public async setAccountLimit(accountId: string, limit: number | null): Promise<void> {\n await this.usageRepo.setAccountStorageLimit(accountId, limit);\n }\n\n public async setPodLimit(podId: string, limit: number | null): Promise<void> {\n const podInfo = await this.accountRepo.getPodInfo(podId);\n if (!podInfo?.accountId) {\n throw new Error(`Pod ${podId} not found or has no associated account`);\n }\n await this.usageRepo.setPodStorageLimit(podId, podInfo.accountId, limit);\n }\n\n /**\n * 解析配额值:本地自定义配额 > 远端 entitlement > 环境变量默认值 > null (不限制)\n */\n private resolve(dbValue: number | null | undefined, remoteValue: number | null | undefined, envKey: string): number | null {\n // DB 中有明确值(包括 0)\n if (typeof dbValue === 'number') {\n return dbValue;\n }\n if (remoteValue === null || typeof remoteValue === 'number') {\n return remoteValue;\n }\n // 回退到环境变量\n return envNumber(envKey);\n }\n\n private needsRemoteEntitlement(usage: {\n storageLimitBytes?: number | null;\n bandwidthLimitBps?: number | null;\n computeLimitSeconds?: number | null;\n tokenLimitMonthly?: number | null;\n } | undefined): boolean {\n return ![\n usage?.storageLimitBytes,\n usage?.bandwidthLimitBps,\n usage?.computeLimitSeconds,\n usage?.tokenLimitMonthly,\n ].every((value) => typeof value === 'number');\n }\n}\n"]}
|
|
@@ -11,11 +11,23 @@
|
|
|
11
11
|
"extends": [
|
|
12
12
|
"undefineds:dist/quota/QuotaService.jsonld#QuotaService"
|
|
13
13
|
],
|
|
14
|
-
"comment": "统一 QuotaService 实现
|
|
14
|
+
"comment": "统一 QuotaService 实现 查询优先级:本地自定义配额 > 远端 entitlement > 环境变量默认值 > 不限制 (null)",
|
|
15
15
|
"parameters": [
|
|
16
16
|
{
|
|
17
17
|
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService_options_identityDbUrl",
|
|
18
18
|
"range": "xsd:string"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService_options_entitlementProvider",
|
|
22
|
+
"range": {
|
|
23
|
+
"@type": "ParameterRangeUnion",
|
|
24
|
+
"parameterRangeElements": [
|
|
25
|
+
"undefineds:dist/quota/EntitlementProvider.jsonld#EntitlementProvider",
|
|
26
|
+
{
|
|
27
|
+
"@type": "ParameterRangeUndefined"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
19
31
|
}
|
|
20
32
|
],
|
|
21
33
|
"memberFields": [
|
|
@@ -31,6 +43,10 @@
|
|
|
31
43
|
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService__member_usageRepo",
|
|
32
44
|
"memberFieldName": "usageRepo"
|
|
33
45
|
},
|
|
46
|
+
{
|
|
47
|
+
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService__member_entitlementProvider",
|
|
48
|
+
"memberFieldName": "entitlementProvider"
|
|
49
|
+
},
|
|
34
50
|
{
|
|
35
51
|
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService__member_constructor",
|
|
36
52
|
"memberFieldName": "constructor"
|
|
@@ -78,6 +94,10 @@
|
|
|
78
94
|
{
|
|
79
95
|
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService__member_resolve",
|
|
80
96
|
"memberFieldName": "resolve"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService__member_needsRemoteEntitlement",
|
|
100
|
+
"memberFieldName": "needsRemoteEntitlement"
|
|
81
101
|
}
|
|
82
102
|
],
|
|
83
103
|
"constructorArguments": [
|
|
@@ -89,6 +109,12 @@
|
|
|
89
109
|
"value": {
|
|
90
110
|
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService_options_identityDbUrl"
|
|
91
111
|
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"keyRaw": "entitlementProvider",
|
|
115
|
+
"value": {
|
|
116
|
+
"@id": "undefineds:dist/quota/DrizzleQuotaService.jsonld#DrizzleQuotaService_options_entitlementProvider"
|
|
117
|
+
}
|
|
92
118
|
}
|
|
93
119
|
]
|
|
94
120
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AccountQuota } from './QuotaService';
|
|
2
|
+
export interface AccountEntitlement {
|
|
3
|
+
accountId: string;
|
|
4
|
+
quota: Partial<AccountQuota>;
|
|
5
|
+
}
|
|
6
|
+
export interface EntitlementProvider {
|
|
7
|
+
getAccountEntitlement(accountId: string): Promise<AccountEntitlement | undefined>;
|
|
8
|
+
}
|
|
9
|
+
export declare class NoopEntitlementProvider implements EntitlementProvider {
|
|
10
|
+
getAccountEntitlement(): Promise<AccountEntitlement | undefined>;
|
|
11
|
+
}
|
|
12
|
+
interface HttpEntitlementProviderOptions {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
serviceToken?: string;
|
|
15
|
+
cacheTtlMs?: number;
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class HttpEntitlementProvider implements EntitlementProvider {
|
|
19
|
+
private readonly logger;
|
|
20
|
+
private readonly baseUrl;
|
|
21
|
+
private readonly serviceToken?;
|
|
22
|
+
private readonly cacheTtlMs;
|
|
23
|
+
private readonly timeoutMs;
|
|
24
|
+
private readonly cache;
|
|
25
|
+
constructor(options: HttpEntitlementProviderOptions);
|
|
26
|
+
getAccountEntitlement(accountId: string): Promise<AccountEntitlement | undefined>;
|
|
27
|
+
private fetchAccountEntitlement;
|
|
28
|
+
}
|
|
29
|
+
export declare function createEntitlementProviderFromEnv(): EntitlementProvider;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpEntitlementProvider = exports.NoopEntitlementProvider = void 0;
|
|
4
|
+
exports.createEntitlementProviderFromEnv = createEntitlementProviderFromEnv;
|
|
5
|
+
const global_logger_factory_1 = require("global-logger-factory");
|
|
6
|
+
class NoopEntitlementProvider {
|
|
7
|
+
async getAccountEntitlement() {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.NoopEntitlementProvider = NoopEntitlementProvider;
|
|
12
|
+
const DEFAULT_CACHE_TTL_MS = 60_000;
|
|
13
|
+
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
14
|
+
function envMs(key, fallback) {
|
|
15
|
+
const raw = process.env[key];
|
|
16
|
+
if (!raw) {
|
|
17
|
+
return fallback;
|
|
18
|
+
}
|
|
19
|
+
const parsed = Number(raw);
|
|
20
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
21
|
+
}
|
|
22
|
+
function normalizeQuotaValue(value) {
|
|
23
|
+
if (value === null) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function isRecord(value) {
|
|
32
|
+
return typeof value === 'object' && value !== null;
|
|
33
|
+
}
|
|
34
|
+
function buildEndpoint(baseUrl, accountId) {
|
|
35
|
+
const url = new URL(baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`);
|
|
36
|
+
const basePath = url.pathname.replace(/\/$/, '');
|
|
37
|
+
url.pathname = `${basePath}/v1/internal/accounts/${encodeURIComponent(accountId)}/entitlements/current`.replace(/\/{2,}/g, '/');
|
|
38
|
+
url.search = '';
|
|
39
|
+
url.hash = '';
|
|
40
|
+
return url.toString();
|
|
41
|
+
}
|
|
42
|
+
class HttpEntitlementProvider {
|
|
43
|
+
constructor(options) {
|
|
44
|
+
this.logger = (0, global_logger_factory_1.getLoggerFor)(this);
|
|
45
|
+
this.cache = new Map();
|
|
46
|
+
this.baseUrl = options.baseUrl.trim();
|
|
47
|
+
this.serviceToken = options.serviceToken?.trim() || undefined;
|
|
48
|
+
this.cacheTtlMs = options.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;
|
|
49
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
50
|
+
}
|
|
51
|
+
async getAccountEntitlement(accountId) {
|
|
52
|
+
const cached = this.cache.get(accountId);
|
|
53
|
+
const now = Date.now();
|
|
54
|
+
if (cached && cached.expiresAt > now) {
|
|
55
|
+
return cached.value;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const value = await this.fetchAccountEntitlement(accountId);
|
|
59
|
+
this.cache.set(accountId, {
|
|
60
|
+
value,
|
|
61
|
+
expiresAt: now + this.cacheTtlMs,
|
|
62
|
+
});
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
this.logger.warn(`Failed to fetch entitlement for ${accountId}: ${error}`);
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async fetchAccountEntitlement(accountId) {
|
|
71
|
+
const headers = {
|
|
72
|
+
Accept: 'application/json',
|
|
73
|
+
};
|
|
74
|
+
if (this.serviceToken) {
|
|
75
|
+
headers.Authorization = `Bearer ${this.serviceToken}`;
|
|
76
|
+
}
|
|
77
|
+
const response = await fetch(buildEndpoint(this.baseUrl, accountId), {
|
|
78
|
+
method: 'GET',
|
|
79
|
+
headers,
|
|
80
|
+
signal: AbortSignal.timeout(this.timeoutMs),
|
|
81
|
+
});
|
|
82
|
+
if (response.status === 404) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
const body = (await response.text()).slice(0, 500);
|
|
87
|
+
throw new Error(`status=${response.status} body=${body}`);
|
|
88
|
+
}
|
|
89
|
+
const payload = await response.json();
|
|
90
|
+
if (!isRecord(payload) || !isRecord(payload.quota)) {
|
|
91
|
+
throw new Error('invalid entitlement payload');
|
|
92
|
+
}
|
|
93
|
+
const quotaPayload = payload.quota;
|
|
94
|
+
return {
|
|
95
|
+
accountId,
|
|
96
|
+
quota: {
|
|
97
|
+
storageLimitBytes: normalizeQuotaValue(quotaPayload.storageLimitBytes),
|
|
98
|
+
bandwidthLimitBps: normalizeQuotaValue(quotaPayload.bandwidthLimitBps),
|
|
99
|
+
computeLimitSeconds: normalizeQuotaValue(quotaPayload.computeLimitSeconds),
|
|
100
|
+
tokenLimitMonthly: normalizeQuotaValue(quotaPayload.tokenLimitMonthly),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.HttpEntitlementProvider = HttpEntitlementProvider;
|
|
106
|
+
function createEntitlementProviderFromEnv() {
|
|
107
|
+
const baseUrl = process.env.XPOD_ENTITLEMENTS_BASE_URL?.trim();
|
|
108
|
+
if (!baseUrl) {
|
|
109
|
+
return new NoopEntitlementProvider();
|
|
110
|
+
}
|
|
111
|
+
return new HttpEntitlementProvider({
|
|
112
|
+
baseUrl,
|
|
113
|
+
serviceToken: process.env.XPOD_ENTITLEMENTS_SERVICE_TOKEN,
|
|
114
|
+
cacheTtlMs: envMs('XPOD_ENTITLEMENTS_CACHE_TTL_MS', DEFAULT_CACHE_TTL_MS),
|
|
115
|
+
timeoutMs: envMs('XPOD_ENTITLEMENTS_TIMEOUT_MS', DEFAULT_TIMEOUT_MS),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=EntitlementProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntitlementProvider.js","sourceRoot":"","sources":["../../src/quota/EntitlementProvider.ts"],"names":[],"mappings":";;;AA6IA,4EAYC;AAzJD,iE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CAAC,CAAC;QACjD,CAAC;QAED,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;QACnC,OAAO;YACL,SAAS;YACT,KAAK,EAAE;gBACL,iBAAiB,EAAE,mBAAmB,CAAC,YAAY,CAAC,iBAAiB,CAAC;gBACtE,iBAAiB,EAAE,mBAAmB,CAAC,YAAY,CAAC,iBAAiB,CAAC;gBACtE,mBAAmB,EAAE,mBAAmB,CAAC,YAAY,CAAC,mBAAmB,CAAC;gBAC1E,iBAAiB,EAAE,mBAAmB,CAAC,YAAY,CAAC,iBAAiB,CAAC;aACvE;SACF,CAAC;IACJ,CAAC;CACF;AA1ED,0DA0EC;AAED,SAAgB,gCAAgC;IAC9C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,EAAE,CAAC;IAC/D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,uBAAuB,EAAE,CAAC;IACvC,CAAC;IAED,OAAO,IAAI,uBAAuB,CAAC;QACjC,OAAO;QACP,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,+BAA+B;QACzD,UAAU,EAAE,KAAK,CAAC,gCAAgC,EAAE,oBAAoB,CAAC;QACzE,SAAS,EAAE,KAAK,CAAC,8BAA8B,EAAE,kBAAkB,CAAC;KACrE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { getLoggerFor } from 'global-logger-factory';\nimport type { AccountQuota } from './QuotaService';\n\nexport interface AccountEntitlement {\n accountId: string;\n quota: Partial<AccountQuota>;\n}\n\nexport interface EntitlementProvider {\n getAccountEntitlement(accountId: string): Promise<AccountEntitlement | undefined>;\n}\n\nexport class NoopEntitlementProvider implements EntitlementProvider {\n public async getAccountEntitlement(): Promise<AccountEntitlement | undefined> {\n return undefined;\n }\n}\n\ninterface HttpEntitlementProviderOptions {\n baseUrl: string;\n serviceToken?: string;\n cacheTtlMs?: number;\n timeoutMs?: number;\n}\n\ninterface CachedEntitlement {\n expiresAt: number;\n value: AccountEntitlement | undefined;\n}\n\nconst DEFAULT_CACHE_TTL_MS = 60_000;\nconst DEFAULT_TIMEOUT_MS = 5_000;\n\nfunction envMs(key: string, fallback: number): number {\n const raw = process.env[key];\n if (!raw) {\n return fallback;\n }\n const parsed = Number(raw);\n return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;\n}\n\nfunction normalizeQuotaValue(value: unknown): number | null | undefined {\n if (value === null) {\n return null;\n }\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {\n return undefined;\n }\n return value;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction buildEndpoint(baseUrl: string, accountId: string): string {\n const url = new URL(baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`);\n const basePath = url.pathname.replace(/\\/$/, '');\n url.pathname = `${basePath}/v1/internal/accounts/${encodeURIComponent(accountId)}/entitlements/current`.replace(/\\/{2,}/g, '/');\n url.search = '';\n url.hash = '';\n return url.toString();\n}\n\nexport class HttpEntitlementProvider implements EntitlementProvider {\n private readonly logger = getLoggerFor(this);\n private readonly baseUrl: string;\n private readonly serviceToken?: string;\n private readonly cacheTtlMs: number;\n private readonly timeoutMs: number;\n private readonly cache = new Map<string, CachedEntitlement>();\n\n public constructor(options: HttpEntitlementProviderOptions) {\n this.baseUrl = options.baseUrl.trim();\n this.serviceToken = options.serviceToken?.trim() || undefined;\n this.cacheTtlMs = options.cacheTtlMs ?? DEFAULT_CACHE_TTL_MS;\n this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n }\n\n public async getAccountEntitlement(accountId: string): Promise<AccountEntitlement | undefined> {\n const cached = this.cache.get(accountId);\n const now = Date.now();\n if (cached && cached.expiresAt > now) {\n return cached.value;\n }\n\n try {\n const value = await this.fetchAccountEntitlement(accountId);\n this.cache.set(accountId, {\n value,\n expiresAt: now + this.cacheTtlMs,\n });\n return value;\n } catch (error) {\n this.logger.warn(`Failed to fetch entitlement for ${accountId}: ${error}`);\n return undefined;\n }\n }\n\n private async fetchAccountEntitlement(accountId: string): Promise<AccountEntitlement | undefined> {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n };\n if (this.serviceToken) {\n headers.Authorization = `Bearer ${this.serviceToken}`;\n }\n\n const response = await fetch(buildEndpoint(this.baseUrl, accountId), {\n method: 'GET',\n headers,\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n\n if (response.status === 404) {\n return undefined;\n }\n\n if (!response.ok) {\n const body = (await response.text()).slice(0, 500);\n throw new Error(`status=${response.status} body=${body}`);\n }\n\n const payload = await response.json() as unknown;\n if (!isRecord(payload) || !isRecord(payload.quota)) {\n throw new Error('invalid entitlement payload');\n }\n\n const quotaPayload = payload.quota;\n return {\n accountId,\n quota: {\n storageLimitBytes: normalizeQuotaValue(quotaPayload.storageLimitBytes),\n bandwidthLimitBps: normalizeQuotaValue(quotaPayload.bandwidthLimitBps),\n computeLimitSeconds: normalizeQuotaValue(quotaPayload.computeLimitSeconds),\n tokenLimitMonthly: normalizeQuotaValue(quotaPayload.tokenLimitMonthly),\n },\n };\n }\n}\n\nexport function createEntitlementProviderFromEnv(): EntitlementProvider {\n const baseUrl = process.env.XPOD_ENTITLEMENTS_BASE_URL?.trim();\n if (!baseUrl) {\n return new NoopEntitlementProvider();\n }\n\n return new HttpEntitlementProvider({\n baseUrl,\n serviceToken: process.env.XPOD_ENTITLEMENTS_SERVICE_TOKEN,\n cacheTtlMs: envMs('XPOD_ENTITLEMENTS_CACHE_TTL_MS', DEFAULT_CACHE_TTL_MS),\n timeoutMs: envMs('XPOD_ENTITLEMENTS_TIMEOUT_MS', DEFAULT_TIMEOUT_MS),\n });\n}\n"]}
|