@myvitalrx/metadata-runtime 1.12.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +53 -2
- package/dist/index.js +318 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -229,6 +229,9 @@ declare class InvalidMetadataReferenceError extends RuntimeMetadataError {
|
|
|
229
229
|
});
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
+
/** Wire projectionVersion stamped on every envelope / manifest / current pointer. */
|
|
233
|
+
declare const PROJECTION_VERSION: "1.0";
|
|
234
|
+
|
|
232
235
|
/**
|
|
233
236
|
* Projection wire type — any non-empty camelCase (or legacy) identifier.
|
|
234
237
|
*
|
|
@@ -501,6 +504,27 @@ declare class StructuredLogger {
|
|
|
501
504
|
verbose(entry: LogEntry): void;
|
|
502
505
|
}
|
|
503
506
|
|
|
507
|
+
/** Document discriminator. Not part of a permission identity. */
|
|
508
|
+
declare const PERMISSION_REGISTRY_METADATA_TYPE: "PermissionRegistry";
|
|
509
|
+
/**
|
|
510
|
+
* One permission. Identity is moduleCode + featureCode + permissionActionCode.
|
|
511
|
+
* `permissionKey` is the deterministic serialization of those three codes.
|
|
512
|
+
* CapabilityCategory is an eligibility gate and is not stored here.
|
|
513
|
+
*/
|
|
514
|
+
type PermissionRegistryEntry = {
|
|
515
|
+
readonly permissionKey: string;
|
|
516
|
+
readonly moduleCode: string;
|
|
517
|
+
readonly featureCode: string;
|
|
518
|
+
readonly permissionActionCode: string;
|
|
519
|
+
};
|
|
520
|
+
type PermissionRegistryDocument = {
|
|
521
|
+
readonly metadataType: typeof PERMISSION_REGISTRY_METADATA_TYPE;
|
|
522
|
+
readonly version: typeof PROJECTION_VERSION;
|
|
523
|
+
readonly releaseId: string;
|
|
524
|
+
readonly generatedAt: string;
|
|
525
|
+
readonly permissions: readonly PermissionRegistryEntry[];
|
|
526
|
+
};
|
|
527
|
+
|
|
504
528
|
/**
|
|
505
529
|
* Governed metadata lifecycle.
|
|
506
530
|
*
|
|
@@ -1143,6 +1167,7 @@ declare class MetadataDownloader implements ReadModelDownloader<LoadedProjection
|
|
|
1143
1167
|
private readonly expectedProjectionVersion;
|
|
1144
1168
|
private readonly logger;
|
|
1145
1169
|
private readonly loader;
|
|
1170
|
+
private readonly objectInFlight;
|
|
1146
1171
|
constructor(options: MetadataDownloaderOptions);
|
|
1147
1172
|
buildKey(releaseId: string, fileName: string): string;
|
|
1148
1173
|
/**
|
|
@@ -1192,10 +1217,12 @@ declare class MetadataDownloader implements ReadModelDownloader<LoadedProjection
|
|
|
1192
1217
|
*/
|
|
1193
1218
|
downloadCommon(manifest: ProjectionManifest): Promise<CommonProjectionFile>;
|
|
1194
1219
|
downloadTypedRelations(manifest: ProjectionManifest): Promise<TypedProjectionRelation[] | undefined>;
|
|
1220
|
+
downloadPermissionRegistry(manifest: ProjectionManifest): Promise<PermissionRegistryDocument>;
|
|
1195
1221
|
downloadRelationshipIndex(manifest: ProjectionManifest): Promise<RelationshipIndex | undefined>;
|
|
1196
1222
|
private assertManifestMatchesRelease;
|
|
1197
1223
|
private parseAndValidateProjectionBody;
|
|
1198
1224
|
private getObjectBody;
|
|
1225
|
+
private fetchObjectBody;
|
|
1199
1226
|
private validateDownloadedFile;
|
|
1200
1227
|
}
|
|
1201
1228
|
|
|
@@ -1518,6 +1545,12 @@ interface MetadataProvider {
|
|
|
1518
1545
|
* Empty `sourceValueCodes` returns `[]`. Order follows `sourceValueCodes`.
|
|
1519
1546
|
*/
|
|
1520
1547
|
getRelatedValueGroups(sourceTypeCode: string, sourceValueCodes: readonly string[], targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataRelatedGroup[]>;
|
|
1548
|
+
/**
|
|
1549
|
+
* Permission vocabulary from the same release as metadata lookups.
|
|
1550
|
+
* Missing or invalid artifacts throw. An empty `permissions` array is a
|
|
1551
|
+
* published registry, not a load failure.
|
|
1552
|
+
*/
|
|
1553
|
+
getPermissionRegistry(): Promise<PermissionRegistryDocument>;
|
|
1521
1554
|
getStatus(): Promise<MetadataProviderStatus>;
|
|
1522
1555
|
isAvailable(): Promise<boolean>;
|
|
1523
1556
|
/**
|
|
@@ -1755,6 +1788,8 @@ declare class RuntimeMetadataService implements ReadModelProvider<ProjectionEntr
|
|
|
1755
1788
|
private readonly logger;
|
|
1756
1789
|
/** Coalesce concurrent cold bootstrap (current.json + manifest.json). */
|
|
1757
1790
|
private initializeInFlight;
|
|
1791
|
+
private permissionRegistryInFlight;
|
|
1792
|
+
private permissionRegistryCache;
|
|
1758
1793
|
/**
|
|
1759
1794
|
* In-flight selective downloads keyed by MetadataTypeCode.
|
|
1760
1795
|
* Concurrent requests (and overlapping type sets) share one download per type
|
|
@@ -1851,6 +1886,13 @@ declare class RuntimeMetadataService implements ReadModelProvider<ProjectionEntr
|
|
|
1851
1886
|
getValue(typeCode: string, valueCode: string, options?: MetadataResolveOptions): Promise<MetadataValue | null>;
|
|
1852
1887
|
batchGet(references: string[], options?: MetadataResolveOptions): Promise<MetadataBatchResult>;
|
|
1853
1888
|
getRelatedValues(sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataValue[]>;
|
|
1889
|
+
/**
|
|
1890
|
+
* Permission vocabulary for the active release.
|
|
1891
|
+
* Concurrent callers share one load. A failed load is not cached.
|
|
1892
|
+
* The last successful document is kept until the release id changes.
|
|
1893
|
+
*/
|
|
1894
|
+
getPermissionRegistry(): Promise<PermissionRegistryDocument>;
|
|
1895
|
+
private loadPermissionRegistry;
|
|
1854
1896
|
getRelatedValueGroups(sourceTypeCode: string, sourceValueCodes: readonly string[], targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataRelatedGroup[]>;
|
|
1855
1897
|
listRelations(query: MetadataRelationQuery): Promise<MetadataRelationListResult>;
|
|
1856
1898
|
listTypeValues(typeCode: string, options?: MetadataResolveOptions): Promise<ListedMetadataType | null>;
|
|
@@ -1956,7 +1998,9 @@ declare function onMetadataProjectionCompleted(releaseId?: string): Promise<bool
|
|
|
1956
1998
|
* 1. Add `@api-hub/runtime-metadata` (+ `@api-hub/runtime-response-projector` if enriching HTTP)
|
|
1957
1999
|
* 2. Copy IAM pattern against `{stage}-mvx-metadata-projections-bucket`
|
|
1958
2000
|
* (or ImportValue `{stage}-metadata-projection-runtime-ProjectionsBucketName`)
|
|
1959
|
-
* 3. Set `METADATA_PROJECTIONS_BUCKET`
|
|
2001
|
+
* 3. Set `METADATA_PROJECTIONS_BUCKET`, `METADATA_EXTENSION_ENABLED`, and
|
|
2002
|
+
* `PROJECTION_ENVIRONMENT`. Host, port, prefix, S3 fallback, recovery,
|
|
2003
|
+
* startup, invoke refresh, and check interval have SDK and extension defaults.
|
|
1960
2004
|
* 4. Prefer platform default response projector (demand-driven); do not register
|
|
1961
2005
|
* metadata warm-up as `beforeHandler`
|
|
1962
2006
|
* 5. Do not add an EventBridge consumer merely to notify every warm Lambda.
|
|
@@ -2013,6 +2057,7 @@ declare class ExtensionMetadataProvider implements MetadataProvider, MetadataDis
|
|
|
2013
2057
|
listRelations(query: MetadataRelationQuery): Promise<MetadataRelationListResult>;
|
|
2014
2058
|
getRelatedValues(sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataValue[]>;
|
|
2015
2059
|
getRelatedValueGroups(sourceTypeCode: string, sourceValueCodes: readonly string[], targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataRelatedGroup[]>;
|
|
2060
|
+
getPermissionRegistry(): Promise<PermissionRegistryDocument>;
|
|
2016
2061
|
getLocalizationValue(keyOrTypeCode: string, valueCodeOrLocale?: string, maybeLocale?: string): Promise<string | undefined>;
|
|
2017
2062
|
getLocalizationMap(locale: string): Promise<Record<string, string> | undefined>;
|
|
2018
2063
|
requestRefresh(releaseId?: string): Promise<boolean>;
|
|
@@ -2038,6 +2083,7 @@ type S3MetadataProviderOptions = {
|
|
|
2038
2083
|
declare class S3MetadataProvider implements MetadataProvider, MetadataDiscoveryProvider {
|
|
2039
2084
|
private readonly cache;
|
|
2040
2085
|
private readonly resolver;
|
|
2086
|
+
private readonly downloader;
|
|
2041
2087
|
private readonly ensureTypesLoaded;
|
|
2042
2088
|
private readonly logger;
|
|
2043
2089
|
constructor(options: S3MetadataProviderOptions);
|
|
@@ -2047,6 +2093,7 @@ declare class S3MetadataProvider implements MetadataProvider, MetadataDiscoveryP
|
|
|
2047
2093
|
batchGet(references: string[], options?: MetadataResolveOptions): Promise<MetadataBatchResult>;
|
|
2048
2094
|
listRelations(query: MetadataRelationQuery): Promise<MetadataRelationListResult>;
|
|
2049
2095
|
getRelatedValues(sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataValue[]>;
|
|
2096
|
+
getPermissionRegistry(): Promise<PermissionRegistryDocument>;
|
|
2050
2097
|
getRelatedValueGroups(sourceTypeCode: string, sourceValueCodes: readonly string[], targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataRelatedGroup[]>;
|
|
2051
2098
|
listTypeValues(typeCode: string, options?: MetadataResolveOptions): Promise<ListedMetadataType | null>;
|
|
2052
2099
|
listValuesByType(typeCode: string, options?: MetadataListOptions): Promise<MetadataListResult>;
|
|
@@ -2085,6 +2132,8 @@ type InMemoryMetadataProviderOptions = {
|
|
|
2085
2132
|
* Default true so in-memory catalogues can answer lifecycle filters.
|
|
2086
2133
|
*/
|
|
2087
2134
|
lifecycleSupported?: boolean;
|
|
2135
|
+
/** When omitted, {@link InMemoryMetadataProvider.getPermissionRegistry} fails closed. */
|
|
2136
|
+
permissionRegistry?: PermissionRegistryDocument;
|
|
2088
2137
|
};
|
|
2089
2138
|
/**
|
|
2090
2139
|
* Test / local provider. Never talks to S3 or the extension.
|
|
@@ -2099,6 +2148,7 @@ declare class InMemoryMetadataProvider implements MetadataProvider, MetadataDisc
|
|
|
2099
2148
|
private readonly typedRelationIndex;
|
|
2100
2149
|
private readonly knownTypeCodes;
|
|
2101
2150
|
private readonly lifecycleSupported;
|
|
2151
|
+
private readonly permissionRegistry;
|
|
2102
2152
|
private readonly activeByType;
|
|
2103
2153
|
private readonly inactiveByType;
|
|
2104
2154
|
constructor(options?: InMemoryMetadataProviderOptions);
|
|
@@ -2114,6 +2164,7 @@ declare class InMemoryMetadataProvider implements MetadataProvider, MetadataDisc
|
|
|
2114
2164
|
batchGet(references: string[], options?: MetadataResolveOptions): Promise<MetadataBatchResult>;
|
|
2115
2165
|
listRelations(query: MetadataRelationQuery): Promise<MetadataRelationListResult>;
|
|
2116
2166
|
getRelatedValues(sourceTypeCode: string, sourceValueCode: string, targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataValue[]>;
|
|
2167
|
+
getPermissionRegistry(): Promise<PermissionRegistryDocument>;
|
|
2117
2168
|
getRelatedValueGroups(sourceTypeCode: string, sourceValueCodes: readonly string[], targetTypeCode: string, options?: MetadataResolveOptions): Promise<MetadataRelatedGroup[]>;
|
|
2118
2169
|
private relatedValuesFor;
|
|
2119
2170
|
listTypeValues(typeCode: string, options?: MetadataResolveOptions): Promise<ListedMetadataType | null>;
|
|
@@ -2133,7 +2184,7 @@ declare const PROVIDER_TRANSPORT_STATE: {
|
|
|
2133
2184
|
readonly EXTENSION_UNAVAILABLE: "EXTENSION_UNAVAILABLE";
|
|
2134
2185
|
};
|
|
2135
2186
|
type ProviderTransportState = (typeof PROVIDER_TRANSPORT_STATE)[keyof typeof PROVIDER_TRANSPORT_STATE];
|
|
2136
|
-
declare const DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS
|
|
2187
|
+
declare const DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS: 2000;
|
|
2137
2188
|
type ProviderFailoverCoordinatorOptions = {
|
|
2138
2189
|
extension: MetadataProvider;
|
|
2139
2190
|
fallback?: MetadataProvider;
|
package/dist/index.js
CHANGED
|
@@ -66,6 +66,7 @@ var RUNTIME_METADATA_EVENTS = {
|
|
|
66
66
|
var PROJECTION_SCHEMA_VERSION = 2;
|
|
67
67
|
var PROJECTION_VERSION = "1.0";
|
|
68
68
|
var DEFAULT_STORAGE_PREFIX = "metadata-projections";
|
|
69
|
+
var PERMISSION_REGISTRY_FILE_NAME = "permission-registry.json";
|
|
69
70
|
var CURRENT_POINTER_FILE_NAME = "current.json";
|
|
70
71
|
var RELEASES_FOLDER_NAME = "releases";
|
|
71
72
|
var PROJECTION_TYPE = {
|
|
@@ -102,7 +103,13 @@ var PROJECTION_TYPE = {
|
|
|
102
103
|
*/
|
|
103
104
|
RUNTIME_CONFIG: "runtimeConfig",
|
|
104
105
|
MANIFEST: "manifest",
|
|
105
|
-
LOCALIZATION: "localization"
|
|
106
|
+
LOCALIZATION: "localization",
|
|
107
|
+
/**
|
|
108
|
+
* Denormalized permission vocabulary (`permission-registry.json`).
|
|
109
|
+
* Platform file — not a domain Metadata Type. Identity stays
|
|
110
|
+
* `moduleCode.featureCode.permissionActionCode`.
|
|
111
|
+
*/
|
|
112
|
+
PERMISSION_REGISTRY: "permissionRegistry"
|
|
106
113
|
};
|
|
107
114
|
var PROJECTION_FILE_NAME = {
|
|
108
115
|
[PROJECTION_TYPE.CONDITION]: "Condition.json",
|
|
@@ -115,6 +122,7 @@ var PROJECTION_FILE_NAME = {
|
|
|
115
122
|
[PROJECTION_TYPE.COMMON]: "common.json",
|
|
116
123
|
[PROJECTION_TYPE.RELATIONSHIP_INDEX]: "relationship-index.json",
|
|
117
124
|
[PROJECTION_TYPE.TYPED_RELATIONS]: "typed-relations.json",
|
|
125
|
+
[PROJECTION_TYPE.PERMISSION_REGISTRY]: PERMISSION_REGISTRY_FILE_NAME,
|
|
118
126
|
/** @deprecated No longer published. */
|
|
119
127
|
[PROJECTION_TYPE.RUNTIME_CONFIG]: "runtime-config.json",
|
|
120
128
|
[PROJECTION_TYPE.MANIFEST]: "manifest.json"
|
|
@@ -898,7 +906,26 @@ z.object({
|
|
|
898
906
|
* Optional storage key prefix hint for adapters (not used by pure build).
|
|
899
907
|
* Callers may also pass prefix directly to {@link S3ProjectionStorage}.
|
|
900
908
|
*/
|
|
901
|
-
storagePrefix: z.string().min(1).optional()
|
|
909
|
+
storagePrefix: z.string().min(1).optional(),
|
|
910
|
+
/**
|
|
911
|
+
* Maximum unresolved non-authorization relationships that may be omitted
|
|
912
|
+
* from one release. Above this count, publication fails.
|
|
913
|
+
* The worker parses `PROJECTION_MAX_EXCLUDED_RELATIONSHIPS`.
|
|
914
|
+
*/
|
|
915
|
+
maxExcludedRelationships: z.number().int().nonnegative().optional(),
|
|
916
|
+
/**
|
|
917
|
+
* Maximum percentage of the relationship collection that may be omitted.
|
|
918
|
+
* Above this share, publication fails so an incomplete snapshot is not
|
|
919
|
+
* treated as a successful release. Integer 0–100.
|
|
920
|
+
*/
|
|
921
|
+
maxExcludedRelationshipPercent: z.number().int().min(0).max(100).optional(),
|
|
922
|
+
/**
|
|
923
|
+
* When true, unresolved Role, Module, Feature, and PermissionAction
|
|
924
|
+
* relationships are excluded under the same thresholds. Default false:
|
|
925
|
+
* those relationships still fail the release.
|
|
926
|
+
* The worker parses `PROJECTION_ALLOW_UNRESOLVED_AUTHORIZATION_RELATIONS`.
|
|
927
|
+
*/
|
|
928
|
+
allowUnresolvedAuthorizationRelations: z.boolean().optional()
|
|
902
929
|
});
|
|
903
930
|
|
|
904
931
|
// ../../libs/metadata-projection/src/lib/errors/ProjectionError.ts
|
|
@@ -1523,6 +1550,99 @@ function isRelationshipIndexPayload(value) {
|
|
|
1523
1550
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1524
1551
|
}
|
|
1525
1552
|
|
|
1553
|
+
// ../../libs/metadata-projection/src/lib/permission-registry/PermissionRegistryReadModelBuilder.ts
|
|
1554
|
+
var PERMISSION_REGISTRY_METADATA_TYPE = "PermissionRegistry";
|
|
1555
|
+
|
|
1556
|
+
// ../../libs/metadata-projection/src/lib/permission-registry/parsePermissionRegistryDocument.ts
|
|
1557
|
+
function parsePermissionRegistryDocument(parsed, expected = {}) {
|
|
1558
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1559
|
+
throw new Error("Permission registry must be a JSON object");
|
|
1560
|
+
}
|
|
1561
|
+
const record = parsed;
|
|
1562
|
+
if (record.metadataType !== PERMISSION_REGISTRY_METADATA_TYPE) {
|
|
1563
|
+
throw new Error("Permission registry metadataType is invalid");
|
|
1564
|
+
}
|
|
1565
|
+
if (record.version !== PROJECTION_VERSION) {
|
|
1566
|
+
throw new Error(`Permission registry version ${String(record.version)} is unsupported`);
|
|
1567
|
+
}
|
|
1568
|
+
if (typeof record.releaseId !== "string" || record.releaseId.trim() === "") {
|
|
1569
|
+
throw new Error("Permission registry releaseId is required");
|
|
1570
|
+
}
|
|
1571
|
+
if (expected.releaseId && record.releaseId !== expected.releaseId) {
|
|
1572
|
+
throw new Error(
|
|
1573
|
+
`Permission registry releaseId ${record.releaseId} does not match ${expected.releaseId}`
|
|
1574
|
+
);
|
|
1575
|
+
}
|
|
1576
|
+
if (typeof record.generatedAt !== "string" || record.generatedAt.trim() === "") {
|
|
1577
|
+
throw new Error("Permission registry generatedAt is required");
|
|
1578
|
+
}
|
|
1579
|
+
if (!Array.isArray(record.permissions)) {
|
|
1580
|
+
throw new Error("Permission registry permissions must be an array");
|
|
1581
|
+
}
|
|
1582
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1583
|
+
const permissions = [];
|
|
1584
|
+
for (const raw of record.permissions) {
|
|
1585
|
+
const entry = parseEntry(raw);
|
|
1586
|
+
if (seen.has(entry.permissionKey)) {
|
|
1587
|
+
throw new Error(`Duplicate permission key ${entry.permissionKey}`);
|
|
1588
|
+
}
|
|
1589
|
+
seen.add(entry.permissionKey);
|
|
1590
|
+
permissions.push(entry);
|
|
1591
|
+
}
|
|
1592
|
+
const document = {
|
|
1593
|
+
metadataType: PERMISSION_REGISTRY_METADATA_TYPE,
|
|
1594
|
+
version: PROJECTION_VERSION,
|
|
1595
|
+
releaseId: record.releaseId,
|
|
1596
|
+
generatedAt: record.generatedAt,
|
|
1597
|
+
permissions
|
|
1598
|
+
};
|
|
1599
|
+
if (expected.contentHash) {
|
|
1600
|
+
const actual = ProjectionHelper.contentHash(document);
|
|
1601
|
+
if (actual !== expected.contentHash) {
|
|
1602
|
+
throw new Error("Permission registry checksum mismatch");
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
return document;
|
|
1606
|
+
}
|
|
1607
|
+
function parseEntry(raw) {
|
|
1608
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
1609
|
+
throw new Error("Permission registry entry must be an object");
|
|
1610
|
+
}
|
|
1611
|
+
const entry = raw;
|
|
1612
|
+
const moduleCode = requiredCode(entry.moduleCode, "moduleCode");
|
|
1613
|
+
const featureCode = requiredCode(entry.featureCode, "featureCode");
|
|
1614
|
+
const permissionActionCode = requiredCode(
|
|
1615
|
+
entry.permissionActionCode,
|
|
1616
|
+
"permissionActionCode"
|
|
1617
|
+
);
|
|
1618
|
+
const permissionKey = requiredToken(entry.permissionKey, "permissionKey");
|
|
1619
|
+
const canonical = `${moduleCode}.${featureCode}.${permissionActionCode}`;
|
|
1620
|
+
if (permissionKey !== canonical) {
|
|
1621
|
+
throw new Error(
|
|
1622
|
+
`Permission key ${permissionKey} does not match ${canonical}`
|
|
1623
|
+
);
|
|
1624
|
+
}
|
|
1625
|
+
return {
|
|
1626
|
+
permissionKey,
|
|
1627
|
+
moduleCode,
|
|
1628
|
+
featureCode,
|
|
1629
|
+
permissionActionCode
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
function requiredCode(value, field) {
|
|
1633
|
+
const code = requiredToken(value, field);
|
|
1634
|
+
if (code.includes(".")) {
|
|
1635
|
+
throw new Error(`Permission registry ${field} must not contain '.'`);
|
|
1636
|
+
}
|
|
1637
|
+
return code;
|
|
1638
|
+
}
|
|
1639
|
+
function requiredToken(value, field) {
|
|
1640
|
+
if (typeof value !== "string" || value.trim() === "" || value !== value.trim()) {
|
|
1641
|
+
throw new Error(`Permission registry ${field} must be a non-empty code`);
|
|
1642
|
+
}
|
|
1643
|
+
return value;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1526
1646
|
// ../../libs/metadata-projection/src/lib/path/ProjectionPathBuilder.ts
|
|
1527
1647
|
var ProjectionPathBuilder = class {
|
|
1528
1648
|
prefix;
|
|
@@ -3463,6 +3583,7 @@ var MetadataDownloader = class {
|
|
|
3463
3583
|
expectedProjectionVersion;
|
|
3464
3584
|
logger;
|
|
3465
3585
|
loader;
|
|
3586
|
+
objectInFlight = /* @__PURE__ */ new Map();
|
|
3466
3587
|
constructor(options) {
|
|
3467
3588
|
if (!options.client) {
|
|
3468
3589
|
throw new RuntimeMetadataError(
|
|
@@ -3818,6 +3939,45 @@ var MetadataDownloader = class {
|
|
|
3818
3939
|
);
|
|
3819
3940
|
}
|
|
3820
3941
|
}
|
|
3942
|
+
async downloadPermissionRegistry(manifest) {
|
|
3943
|
+
const fileName = PROJECTION_FILE_NAME[PROJECTION_TYPE.PERMISSION_REGISTRY];
|
|
3944
|
+
const entry = manifest.files.find((file) => file.fileName === fileName);
|
|
3945
|
+
if (!entry) {
|
|
3946
|
+
throw new ProjectionDownloadError(
|
|
3947
|
+
"permission-registry.json is missing from the projection manifest",
|
|
3948
|
+
{
|
|
3949
|
+
retryable: false,
|
|
3950
|
+
metadata: { releaseId: manifest.releaseId, fileName }
|
|
3951
|
+
}
|
|
3952
|
+
);
|
|
3953
|
+
}
|
|
3954
|
+
const body = await this.getObjectBody(
|
|
3955
|
+
this.buildKey(manifest.releaseId, fileName)
|
|
3956
|
+
);
|
|
3957
|
+
let parsed;
|
|
3958
|
+
try {
|
|
3959
|
+
parsed = JSON.parse(body);
|
|
3960
|
+
} catch {
|
|
3961
|
+
throw new ProjectionDownloadError(`Corrupted JSON for ${fileName}`, {
|
|
3962
|
+
retryable: false,
|
|
3963
|
+
metadata: { fileName, releaseId: manifest.releaseId }
|
|
3964
|
+
});
|
|
3965
|
+
}
|
|
3966
|
+
try {
|
|
3967
|
+
return parsePermissionRegistryDocument(parsed, {
|
|
3968
|
+
releaseId: manifest.releaseId,
|
|
3969
|
+
contentHash: entry.contentHash
|
|
3970
|
+
});
|
|
3971
|
+
} catch (err) {
|
|
3972
|
+
throw new ProjectionDownloadError(
|
|
3973
|
+
err instanceof Error ? err.message : `Invalid permission registry for ${fileName}`,
|
|
3974
|
+
{
|
|
3975
|
+
retryable: false,
|
|
3976
|
+
metadata: { fileName, releaseId: manifest.releaseId }
|
|
3977
|
+
}
|
|
3978
|
+
);
|
|
3979
|
+
}
|
|
3980
|
+
}
|
|
3821
3981
|
async downloadRelationshipIndex(manifest) {
|
|
3822
3982
|
const fileName = PROJECTION_FILE_NAME[PROJECTION_TYPE.RELATIONSHIP_INDEX];
|
|
3823
3983
|
const entry = manifest.files.find((f) => f.fileName === fileName);
|
|
@@ -3874,7 +4034,18 @@ var MetadataDownloader = class {
|
|
|
3874
4034
|
this.validateDownloadedFile(fileName, contentHash, parsed);
|
|
3875
4035
|
return parsed;
|
|
3876
4036
|
}
|
|
3877
|
-
|
|
4037
|
+
getObjectBody(key) {
|
|
4038
|
+
const existing = this.objectInFlight.get(key);
|
|
4039
|
+
if (existing) {
|
|
4040
|
+
return existing;
|
|
4041
|
+
}
|
|
4042
|
+
const pending = this.fetchObjectBody(key).finally(() => {
|
|
4043
|
+
this.objectInFlight.delete(key);
|
|
4044
|
+
});
|
|
4045
|
+
this.objectInFlight.set(key, pending);
|
|
4046
|
+
return pending;
|
|
4047
|
+
}
|
|
4048
|
+
async fetchObjectBody(key) {
|
|
3878
4049
|
try {
|
|
3879
4050
|
const resp = await this.client.send(
|
|
3880
4051
|
new GetObjectCommand({
|
|
@@ -4719,6 +4890,69 @@ var MetadataHealthService = class {
|
|
|
4719
4890
|
}
|
|
4720
4891
|
};
|
|
4721
4892
|
|
|
4893
|
+
// ../../libs/runtime-metadata/src/lib/config/metadataExtensionDefaults.ts
|
|
4894
|
+
var METADATA_EXTENSION_DEFAULTS = {
|
|
4895
|
+
HOST: "127.0.0.1",
|
|
4896
|
+
PORT: 12701,
|
|
4897
|
+
FALLBACK: "s3",
|
|
4898
|
+
RECOVERY_INTERVAL_MS: 2e3,
|
|
4899
|
+
STARTUP_TIMEOUT_MS: 8e3,
|
|
4900
|
+
INVOKE_REFRESH_MS: 3e4,
|
|
4901
|
+
PROJECTION_CHECK_INTERVAL_MS: 3e5,
|
|
4902
|
+
PROJECTIONS_PREFIX: "metadata-projections"
|
|
4903
|
+
};
|
|
4904
|
+
function resolveExtensionHost(env) {
|
|
4905
|
+
const host = env.METADATA_EXTENSION_HOST?.trim();
|
|
4906
|
+
return host || METADATA_EXTENSION_DEFAULTS.HOST;
|
|
4907
|
+
}
|
|
4908
|
+
function resolveExtensionPort(env) {
|
|
4909
|
+
return Number(env.METADATA_EXTENSION_PORT ?? METADATA_EXTENSION_DEFAULTS.PORT);
|
|
4910
|
+
}
|
|
4911
|
+
function resolveExtensionFallback(env) {
|
|
4912
|
+
return env.METADATA_EXTENSION_FALLBACK ?? METADATA_EXTENSION_DEFAULTS.FALLBACK;
|
|
4913
|
+
}
|
|
4914
|
+
function isMetadataExtensionS3FallbackEnabled(env) {
|
|
4915
|
+
return resolveExtensionFallback(env) !== "none";
|
|
4916
|
+
}
|
|
4917
|
+
function resolveExtensionStartupTimeoutMs(env) {
|
|
4918
|
+
if (env.METADATA_EXTENSION_READY_TIMEOUT_MS) {
|
|
4919
|
+
return Number(env.METADATA_EXTENSION_READY_TIMEOUT_MS);
|
|
4920
|
+
}
|
|
4921
|
+
if (env.METADATA_EXTENSION_STARTUP_TIMEOUT_MS) {
|
|
4922
|
+
return Number(env.METADATA_EXTENSION_STARTUP_TIMEOUT_MS);
|
|
4923
|
+
}
|
|
4924
|
+
return METADATA_EXTENSION_DEFAULTS.STARTUP_TIMEOUT_MS;
|
|
4925
|
+
}
|
|
4926
|
+
function resolveExtensionRecoveryIntervalMs(env) {
|
|
4927
|
+
const raw = env?.METADATA_EXTENSION_RECOVERY_INTERVAL_MS;
|
|
4928
|
+
if (!raw) {
|
|
4929
|
+
return METADATA_EXTENSION_DEFAULTS.RECOVERY_INTERVAL_MS;
|
|
4930
|
+
}
|
|
4931
|
+
const parsed = Number(raw);
|
|
4932
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : METADATA_EXTENSION_DEFAULTS.RECOVERY_INTERVAL_MS;
|
|
4933
|
+
}
|
|
4934
|
+
function resolveExtensionInvokeRefreshMs(env = process.env) {
|
|
4935
|
+
const raw = env.METADATA_EXTENSION_INVOKE_REFRESH_MS;
|
|
4936
|
+
if (!raw) {
|
|
4937
|
+
return METADATA_EXTENSION_DEFAULTS.INVOKE_REFRESH_MS;
|
|
4938
|
+
}
|
|
4939
|
+
const parsed = Number(raw);
|
|
4940
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : METADATA_EXTENSION_DEFAULTS.INVOKE_REFRESH_MS;
|
|
4941
|
+
}
|
|
4942
|
+
function resolveProjectionsPrefix(env) {
|
|
4943
|
+
return env.PROJECTION_ROOT_PREFIX ?? env.METADATA_PROJECTIONS_PREFIX ?? METADATA_EXTENSION_DEFAULTS.PROJECTIONS_PREFIX;
|
|
4944
|
+
}
|
|
4945
|
+
function resolveProjectionCheckIntervalMs(env, override) {
|
|
4946
|
+
if (override != null) {
|
|
4947
|
+
return override;
|
|
4948
|
+
}
|
|
4949
|
+
const raw = env.METADATA_PROJECTION_CHECK_INTERVAL_MS;
|
|
4950
|
+
if (raw == null || raw === "") {
|
|
4951
|
+
return METADATA_EXTENSION_DEFAULTS.PROJECTION_CHECK_INTERVAL_MS;
|
|
4952
|
+
}
|
|
4953
|
+
return Number(raw);
|
|
4954
|
+
}
|
|
4955
|
+
|
|
4722
4956
|
// ../../libs/runtime-metadata/src/lib/provider/MetadataDiscovery.ts
|
|
4723
4957
|
var METADATA_READ_POLICY = {
|
|
4724
4958
|
ALLOW_STALE: "ALLOW_STALE",
|
|
@@ -5140,6 +5374,10 @@ var ExtensionMetadataProvider = class {
|
|
|
5140
5374
|
throw err;
|
|
5141
5375
|
}
|
|
5142
5376
|
}
|
|
5377
|
+
async getPermissionRegistry() {
|
|
5378
|
+
const body = await this.requestJson("GET", "/v1/permission-registry");
|
|
5379
|
+
return parsePermissionRegistryDocument(body);
|
|
5380
|
+
}
|
|
5143
5381
|
async getLocalizationValue(keyOrTypeCode, valueCodeOrLocale, maybeLocale) {
|
|
5144
5382
|
let key;
|
|
5145
5383
|
let locale;
|
|
@@ -5506,7 +5744,7 @@ var METADATA_PROVIDER_KIND = {
|
|
|
5506
5744
|
function selectMetadataProvider(input) {
|
|
5507
5745
|
const env = input.env ?? process.env;
|
|
5508
5746
|
if (input.extensionProvider) {
|
|
5509
|
-
const fallbackEnabled = (env
|
|
5747
|
+
const fallbackEnabled = isMetadataExtensionS3FallbackEnabled(env);
|
|
5510
5748
|
return {
|
|
5511
5749
|
kind: METADATA_PROVIDER_KIND.EXTENSION,
|
|
5512
5750
|
provider: input.extensionProvider,
|
|
@@ -5515,15 +5753,16 @@ function selectMetadataProvider(input) {
|
|
|
5515
5753
|
}
|
|
5516
5754
|
const extensionEnabled = isExtensionEnabled(env);
|
|
5517
5755
|
if (extensionEnabled) {
|
|
5518
|
-
const port =
|
|
5519
|
-
const
|
|
5756
|
+
const port = resolveExtensionPort(env);
|
|
5757
|
+
const host = resolveExtensionHost(env);
|
|
5758
|
+
const baseUrl = (env.METADATA_EXTENSION_BASE_URL ?? (host === METADATA_EXTENSION_DEFAULTS.HOST ? defaultExtensionBaseUrl(port) : `http://${host}:${port}`)).trim();
|
|
5520
5759
|
const extension = new ExtensionMetadataProvider({
|
|
5521
5760
|
baseUrl,
|
|
5522
5761
|
logger: input.logger,
|
|
5523
5762
|
fetchImpl: input.extensionFetch,
|
|
5524
|
-
readyTimeoutMs:
|
|
5763
|
+
readyTimeoutMs: resolveExtensionStartupTimeoutMs(env)
|
|
5525
5764
|
});
|
|
5526
|
-
const fallbackEnabled = (env
|
|
5765
|
+
const fallbackEnabled = isMetadataExtensionS3FallbackEnabled(env);
|
|
5527
5766
|
return {
|
|
5528
5767
|
kind: METADATA_PROVIDER_KIND.EXTENSION,
|
|
5529
5768
|
provider: extension,
|
|
@@ -5562,7 +5801,7 @@ var PROVIDER_TRANSPORT_STATE = {
|
|
|
5562
5801
|
EXTENSION_UNAVAILABLE: "EXTENSION_UNAVAILABLE"
|
|
5563
5802
|
};
|
|
5564
5803
|
var SERVING_STATES = /* @__PURE__ */ new Set(["READY", "STALE", "DEGRADED"]);
|
|
5565
|
-
var DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS =
|
|
5804
|
+
var DEFAULT_PROVIDER_RECOVERY_COOLDOWN_MS = METADATA_EXTENSION_DEFAULTS.RECOVERY_INTERVAL_MS;
|
|
5566
5805
|
var ProviderFailoverCoordinator = class {
|
|
5567
5806
|
state;
|
|
5568
5807
|
recoveryInFlight = null;
|
|
@@ -5708,14 +5947,15 @@ function isExtensionServing(status) {
|
|
|
5708
5947
|
var S3MetadataProvider = class {
|
|
5709
5948
|
cache;
|
|
5710
5949
|
resolver;
|
|
5950
|
+
downloader;
|
|
5711
5951
|
ensureTypesLoaded;
|
|
5712
5952
|
logger;
|
|
5713
5953
|
constructor(options) {
|
|
5714
5954
|
this.cache = options.cache;
|
|
5715
5955
|
this.resolver = options.resolver;
|
|
5956
|
+
this.downloader = options.downloader;
|
|
5716
5957
|
this.ensureTypesLoaded = options.ensureTypesLoaded;
|
|
5717
5958
|
this.logger = options.logger ?? createLogger({ serviceName: "runtime-metadata" });
|
|
5718
|
-
void options.downloader;
|
|
5719
5959
|
}
|
|
5720
5960
|
async isAvailable() {
|
|
5721
5961
|
return this.cache.isReady();
|
|
@@ -5853,6 +6093,15 @@ var S3MetadataProvider = class {
|
|
|
5853
6093
|
});
|
|
5854
6094
|
return values;
|
|
5855
6095
|
}
|
|
6096
|
+
async getPermissionRegistry() {
|
|
6097
|
+
const manifest = this.cache.getManifest();
|
|
6098
|
+
if (!manifest) {
|
|
6099
|
+
throw new ProjectionDownloadError("Projection manifest is not loaded", {
|
|
6100
|
+
retryable: true
|
|
6101
|
+
});
|
|
6102
|
+
}
|
|
6103
|
+
return this.downloader.downloadPermissionRegistry(manifest);
|
|
6104
|
+
}
|
|
5856
6105
|
async getRelatedValueGroups(sourceTypeCode, sourceValueCodes, targetTypeCode, options) {
|
|
5857
6106
|
if (sourceValueCodes.length === 0) {
|
|
5858
6107
|
return [];
|
|
@@ -6240,6 +6489,8 @@ var RuntimeMetadataService = class {
|
|
|
6240
6489
|
logger;
|
|
6241
6490
|
/** Coalesce concurrent cold bootstrap (current.json + manifest.json). */
|
|
6242
6491
|
initializeInFlight = null;
|
|
6492
|
+
permissionRegistryInFlight = null;
|
|
6493
|
+
permissionRegistryCache = null;
|
|
6243
6494
|
/**
|
|
6244
6495
|
* In-flight selective downloads keyed by MetadataTypeCode.
|
|
6245
6496
|
* Concurrent requests (and overlapping type sets) share one download per type
|
|
@@ -6850,6 +7101,45 @@ var RuntimeMetadataService = class {
|
|
|
6850
7101
|
throw err;
|
|
6851
7102
|
}
|
|
6852
7103
|
}
|
|
7104
|
+
/**
|
|
7105
|
+
* Permission vocabulary for the active release.
|
|
7106
|
+
* Concurrent callers share one load. A failed load is not cached.
|
|
7107
|
+
* The last successful document is kept until the release id changes.
|
|
7108
|
+
*/
|
|
7109
|
+
async getPermissionRegistry() {
|
|
7110
|
+
if (!this.cache.isReady()) {
|
|
7111
|
+
await this.initialize();
|
|
7112
|
+
}
|
|
7113
|
+
const releaseId = this.cache.getReleaseId() ?? "";
|
|
7114
|
+
const cached = this.permissionRegistryCache;
|
|
7115
|
+
if (cached && cached.releaseId === releaseId && releaseId) {
|
|
7116
|
+
return cached.document;
|
|
7117
|
+
}
|
|
7118
|
+
if (!this.permissionRegistryInFlight) {
|
|
7119
|
+
this.permissionRegistryInFlight = this.loadPermissionRegistry(releaseId).finally(
|
|
7120
|
+
() => {
|
|
7121
|
+
this.permissionRegistryInFlight = null;
|
|
7122
|
+
}
|
|
7123
|
+
);
|
|
7124
|
+
}
|
|
7125
|
+
return this.permissionRegistryInFlight;
|
|
7126
|
+
}
|
|
7127
|
+
async loadPermissionRegistry(expectedReleaseId) {
|
|
7128
|
+
const provider = await this.activeProvider();
|
|
7129
|
+
const document = await provider.getPermissionRegistry();
|
|
7130
|
+
const currentReleaseId = this.cache.getReleaseId() ?? "";
|
|
7131
|
+
if (expectedReleaseId && currentReleaseId && expectedReleaseId !== currentReleaseId) {
|
|
7132
|
+
throw new MetadataReleaseMismatchError(expectedReleaseId, currentReleaseId);
|
|
7133
|
+
}
|
|
7134
|
+
if (currentReleaseId && document.releaseId !== currentReleaseId) {
|
|
7135
|
+
throw new MetadataReleaseMismatchError(currentReleaseId, document.releaseId);
|
|
7136
|
+
}
|
|
7137
|
+
this.permissionRegistryCache = {
|
|
7138
|
+
releaseId: document.releaseId,
|
|
7139
|
+
document
|
|
7140
|
+
};
|
|
7141
|
+
return document;
|
|
7142
|
+
}
|
|
6853
7143
|
async getRelatedValueGroups(sourceTypeCode, sourceValueCodes, targetTypeCode, options) {
|
|
6854
7144
|
try {
|
|
6855
7145
|
const provider = await this.activeProvider();
|
|
@@ -7214,12 +7504,7 @@ var RuntimeMetadataService = class {
|
|
|
7214
7504
|
}
|
|
7215
7505
|
};
|
|
7216
7506
|
function recoveryCooldownMs(env) {
|
|
7217
|
-
|
|
7218
|
-
if (!raw) {
|
|
7219
|
-
return void 0;
|
|
7220
|
-
}
|
|
7221
|
-
const parsed = Number(raw);
|
|
7222
|
-
return Number.isFinite(parsed) && parsed >= 0 ? parsed : void 0;
|
|
7507
|
+
return resolveExtensionRecoveryIntervalMs(env);
|
|
7223
7508
|
}
|
|
7224
7509
|
|
|
7225
7510
|
// ../../libs/runtime-metadata/src/lib/integration/createRuntimeMetadataFromEnv.ts
|
|
@@ -7229,10 +7514,13 @@ function createRuntimeMetadataFromEnv(options) {
|
|
|
7229
7514
|
const environment = (options.environment ?? env.PROJECTION_ENVIRONMENT ?? env.STAGE ?? env.NODE_ENV ?? "dev").trim().toLowerCase();
|
|
7230
7515
|
const config2 = {
|
|
7231
7516
|
bucket,
|
|
7232
|
-
prefix: env
|
|
7517
|
+
prefix: resolveProjectionsPrefix(env),
|
|
7233
7518
|
environment,
|
|
7234
7519
|
revision: options.revision ?? env.METADATA_PROJECTION_REVISION,
|
|
7235
|
-
periodicCheckIntervalMs:
|
|
7520
|
+
periodicCheckIntervalMs: resolveProjectionCheckIntervalMs(
|
|
7521
|
+
env,
|
|
7522
|
+
options.periodicCheckIntervalMs
|
|
7523
|
+
)
|
|
7236
7524
|
};
|
|
7237
7525
|
return new RuntimeMetadataService({
|
|
7238
7526
|
client: options.client,
|
|
@@ -7249,7 +7537,6 @@ var metadataServiceInstance;
|
|
|
7249
7537
|
var initializePromise;
|
|
7250
7538
|
var initialized = false;
|
|
7251
7539
|
var lastUpdateCheckAtMs = 0;
|
|
7252
|
-
var UPDATE_CHECK_MIN_INTERVAL_MS = 3e4;
|
|
7253
7540
|
function getRuntimeMetadataService() {
|
|
7254
7541
|
if (!isMetadataProjectionConfigured()) {
|
|
7255
7542
|
throw new Error(
|
|
@@ -7290,7 +7577,7 @@ async function ensureRuntimeMetadataLoaded() {
|
|
|
7290
7577
|
return;
|
|
7291
7578
|
}
|
|
7292
7579
|
const now = Date.now();
|
|
7293
|
-
if (now - lastUpdateCheckAtMs <
|
|
7580
|
+
if (now - lastUpdateCheckAtMs < resolveExtensionInvokeRefreshMs()) {
|
|
7294
7581
|
return;
|
|
7295
7582
|
}
|
|
7296
7583
|
lastUpdateCheckAtMs = now;
|
|
@@ -7335,12 +7622,14 @@ var InMemoryMetadataProvider = class {
|
|
|
7335
7622
|
typedRelationIndex;
|
|
7336
7623
|
knownTypeCodes = /* @__PURE__ */ new Set();
|
|
7337
7624
|
lifecycleSupported;
|
|
7625
|
+
permissionRegistry;
|
|
7338
7626
|
activeByType = /* @__PURE__ */ new Map();
|
|
7339
7627
|
inactiveByType = /* @__PURE__ */ new Map();
|
|
7340
7628
|
constructor(options = {}) {
|
|
7341
7629
|
this.releaseId = options.releaseId ?? "memory";
|
|
7342
7630
|
this.unavailable = options.unavailable === true;
|
|
7343
7631
|
this.lifecycleSupported = options.lifecycleSupported !== false;
|
|
7632
|
+
this.permissionRegistry = options.permissionRegistry;
|
|
7344
7633
|
this.relations = options.relations;
|
|
7345
7634
|
this.typedRelationIndex = options.relations ? buildTypedRelationIndex(options.relations) : void 0;
|
|
7346
7635
|
for (const typeCode of options.knownTypeCodes ?? []) {
|
|
@@ -7486,6 +7775,15 @@ var InMemoryMetadataProvider = class {
|
|
|
7486
7775
|
}
|
|
7487
7776
|
return this.relatedValuesFor(sourceTypeCode, sourceValueCode, targetTypeCode, options);
|
|
7488
7777
|
}
|
|
7778
|
+
async getPermissionRegistry() {
|
|
7779
|
+
if (this.unavailable || !this.permissionRegistry) {
|
|
7780
|
+
throw new MetadataProjectionUnavailableError(
|
|
7781
|
+
"Permission registry is not available",
|
|
7782
|
+
{ retryable: this.unavailable }
|
|
7783
|
+
);
|
|
7784
|
+
}
|
|
7785
|
+
return this.permissionRegistry;
|
|
7786
|
+
}
|
|
7489
7787
|
async getRelatedValueGroups(sourceTypeCode, sourceValueCodes, targetTypeCode, options) {
|
|
7490
7788
|
if (this.unavailable) {
|
|
7491
7789
|
throw new MetadataProjectionUnavailableError(
|