@forklaunch/core 4.3.0 → 4.4.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.
@@ -33,6 +33,10 @@ var RetentionAction = {
33
33
  delete: "delete",
34
34
  anonymize: "anonymize"
35
35
  };
36
+ var DEFAULT_RETENTION_FROM = "createdAt";
37
+ function retentionFrom(policy) {
38
+ return policy.from ?? DEFAULT_RETENTION_FROM;
39
+ }
36
40
  var RetentionDuration = {
37
41
  days: (n) => `P${n}D`,
38
42
  months: (n) => `P${n}M`,
@@ -1530,9 +1534,22 @@ function defineComplianceEntity(meta) {
1530
1534
  registerEntityCompliance(entityName, complianceFields);
1531
1535
  if (meta.retention) {
1532
1536
  parseDuration(meta.retention.duration);
1533
- if (!resolvedProperties["createdAt"]) {
1537
+ const from = retentionFrom(meta.retention);
1538
+ const fromProperty = resolvedProperties[from];
1539
+ if (!fromProperty) {
1540
+ throw new Error(
1541
+ from === DEFAULT_RETENTION_FROM ? `Entity '${entityName}' has a retention policy but no 'createdAt' property. Retention requires createdAt to compute expiration.` : `Entity '${entityName}' has a retention policy counting from '${from}', but no '${from}' property. Add it (a nullable datetime) or count from another date property.`
1542
+ );
1543
+ }
1544
+ if (typeof fromProperty === "function") {
1545
+ throw new Error(
1546
+ `Entity '${entityName}' retention counts from '${from}', which is a relation. Count from a date property instead.`
1547
+ );
1548
+ }
1549
+ const fromLevel = complianceFields.get(from);
1550
+ if (fromLevel && fromLevel !== "none") {
1534
1551
  throw new Error(
1535
- `Entity '${entityName}' has a retention policy but no 'createdAt' property. Retention requires createdAt to compute expiration.`
1552
+ `Entity '${entityName}' retention counts from '${from}', which is classified '${fromLevel}' and therefore encrypted. Count from an unclassified (compliance('none')) date property.`
1536
1553
  );
1537
1554
  }
1538
1555
  registerEntityRetention(entityName, meta.retention);
@@ -2152,6 +2169,7 @@ export {
2152
2169
  CompliantIndexType,
2153
2170
  CompliantQueryError,
2154
2171
  CompliantType,
2172
+ DEFAULT_RETENTION_FROM,
2155
2173
  DecryptionError,
2156
2174
  ENCRYPTED_PREFIXES2 as ENCRYPTED_PREFIXES,
2157
2175
  ENCRYPTION_FORMAT_ENV,
@@ -2202,6 +2220,7 @@ export {
2202
2220
  parseEncryptionKeyList,
2203
2221
  reencryptEncryptedColumns,
2204
2222
  registerEncryptor,
2223
+ retentionFrom,
2205
2224
  rotationTotals,
2206
2225
  runMigrationsWithLock,
2207
2226
  sealedAnon,