ts-prorm-orm 1.1.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/CHANGELOG.md +1111 -0
- package/LICENSE +21 -0
- package/README.md +573 -0
- package/dist/audit/history-query.js +180 -0
- package/dist/audit/index.js +23 -0
- package/dist/audit/logger.js +236 -0
- package/dist/cache/cache-manager.js +84 -0
- package/dist/cache/index.js +16 -0
- package/dist/cache/redis-cluster-cache.js +557 -0
- package/dist/cli.js +2200 -0
- package/dist/compliance/audit-trail.js +68 -0
- package/dist/compliance/backup-verification.js +685 -0
- package/dist/compliance/breach-detector.js +505 -0
- package/dist/compliance/consent-record.js +227 -0
- package/dist/compliance/consent-versioning.js +331 -0
- package/dist/compliance/cross-border-log.js +530 -0
- package/dist/compliance/data-classifier.js +258 -0
- package/dist/compliance/data-lineage.js +565 -0
- package/dist/compliance/data-masker.js +303 -0
- package/dist/compliance/data-portability.js +265 -0
- package/dist/compliance/data-retention.js +195 -0
- package/dist/compliance/dsar-workflow.js +342 -0
- package/dist/compliance/field-encryption.js +223 -0
- package/dist/compliance/immutable-record.js +148 -0
- package/dist/compliance/index.js +260 -0
- package/dist/compliance/privacy-impact-assessment.js +364 -0
- package/dist/compliance/pseudonymization.js +269 -0
- package/dist/compliance/query-firewall.js +1182 -0
- package/dist/compliance/rate-limiter.js +580 -0
- package/dist/compliance/right-to-erasure.js +117 -0
- package/dist/compliance/row-level-security.js +246 -0
- package/dist/compliance/security-decorator.js +574 -0
- package/dist/compliance/security-monitor.js +525 -0
- package/dist/compliance/sensitive-data-discovery.js +476 -0
- package/dist/compliance/session-isolation.js +472 -0
- package/dist/compliance/tls-enforcer.js +108 -0
- package/dist/compliance/worm-storage.js +712 -0
- package/dist/connection-manager.js +198 -0
- package/dist/connection-pool.js +519 -0
- package/dist/decorators/audit.js +136 -0
- package/dist/decorators/belongs-to-many.js +115 -0
- package/dist/decorators/belongs-to.js +115 -0
- package/dist/decorators/check.js +435 -0
- package/dist/decorators/collate.js +329 -0
- package/dist/decorators/comment.js +205 -0
- package/dist/decorators/database-settings.js +236 -0
- package/dist/decorators/default.js +244 -0
- package/dist/decorators/encryption.js +235 -0
- package/dist/decorators/engine.js +97 -0
- package/dist/decorators/fk-constraints.js +594 -0
- package/dist/decorators/foreign-table.js +136 -0
- package/dist/decorators/generated.js +274 -0
- package/dist/decorators/has-many.js +127 -0
- package/dist/decorators/has-one.js +116 -0
- package/dist/decorators/hstore.js +129 -0
- package/dist/decorators/index.js +355 -0
- package/dist/decorators/json-column.js +83 -0
- package/dist/decorators/jsonb.js +101 -0
- package/dist/decorators/orm-decorators.js +425 -0
- package/dist/decorators/permissions.js +294 -0
- package/dist/decorators/procedure.js +210 -0
- package/dist/decorators/query-options.js +556 -0
- package/dist/decorators/range.js +167 -0
- package/dist/decorators/set-column.js +83 -0
- package/dist/decorators/spatial.js +114 -0
- package/dist/decorators/storage.js +580 -0
- package/dist/decorators/timezone.js +512 -0
- package/dist/decorators/trigger.js +90 -0
- package/dist/decorators/uuid.js +135 -0
- package/dist/decorators/view.js +258 -0
- package/dist/diagrams/chen-diagram.js +354 -0
- package/dist/diagrams/class-diagram.js +384 -0
- package/dist/diagrams/dependency-diagram.js +432 -0
- package/dist/diagrams/er-diagram.js +605 -0
- package/dist/diagrams/flow-diagram.js +394 -0
- package/dist/diagrams/gantt-diagram.js +411 -0
- package/dist/diagrams/index-diagram.js +353 -0
- package/dist/diagrams/index.js +184 -0
- package/dist/diagrams/migration-diagram.js +316 -0
- package/dist/diagrams/model-diagram.js +616 -0
- package/dist/diagrams/package-diagram.js +376 -0
- package/dist/diagrams/palette.js +85 -0
- package/dist/diagrams/relational-diagram.js +455 -0
- package/dist/diagrams/schemadoc-diagram.js +309 -0
- package/dist/diagrams/sequence-diagram.js +307 -0
- package/dist/diagrams/state-diagram.js +344 -0
- package/dist/diagrams/svg-dom.js +111 -0
- package/dist/diagrams/tree-diagram.js +250 -0
- package/dist/dialects/clickhouse/index.js +1742 -0
- package/dist/dialects/cockroachdb/index.js +4677 -0
- package/dist/dialects/cratedb/index.js +441 -0
- package/dist/dialects/databricks/index.js +517 -0
- package/dist/dialects/db2/index.js +2225 -0
- package/dist/dialects/dialect.js +720 -0
- package/dist/dialects/duckdb/index.js +2014 -0
- package/dist/dialects/exasol/index.js +357 -0
- package/dist/dialects/firebird/index.js +495 -0
- package/dist/dialects/greenplum/index.js +457 -0
- package/dist/dialects/hana/index.js +1741 -0
- package/dist/dialects/mariadb/index.js +3590 -0
- package/dist/dialects/mssql/index.js +2296 -0
- package/dist/dialects/mysql/index.js +4058 -0
- package/dist/dialects/oracle/index.js +2999 -0
- package/dist/dialects/postgres/index.js +5319 -0
- package/dist/dialects/query-stream-helper.js +152 -0
- package/dist/dialects/questdb/index.js +433 -0
- package/dist/dialects/redshift/index.js +2277 -0
- package/dist/dialects/singlestore/index.js +354 -0
- package/dist/dialects/snowflake/index.js +2082 -0
- package/dist/dialects/spanner/index.js +1768 -0
- package/dist/dialects/sqlite/index.js +3382 -0
- package/dist/dialects/tidb/index.js +377 -0
- package/dist/dialects/timescaledb/index.js +164 -0
- package/dist/dialects/trino/index.js +420 -0
- package/dist/dialects/turso/index.js +227 -0
- package/dist/dialects/vertica/index.js +317 -0
- package/dist/dialects/yugabytedb/index.js +424 -0
- package/dist/errors/index.js +472 -0
- package/dist/errors/utils.js +340 -0
- package/dist/errors.js +21 -0
- package/dist/extensions/catalog/cloud-warehouse-features.js +207 -0
- package/dist/extensions/catalog/mssql-features.js +147 -0
- package/dist/extensions/catalog/mysql-mariadb-plugins.js +229 -0
- package/dist/extensions/catalog/oracle-db2-features.js +196 -0
- package/dist/extensions/catalog/postgres-extensions.js +516 -0
- package/dist/extensions/index.js +71 -0
- package/dist/extensions/types.js +13 -0
- package/dist/foreign-data.js +173 -0
- package/dist/hooks/hooks-manager.js +350 -0
- package/dist/hooks/index.js +37 -0
- package/dist/index.js +463 -0
- package/dist/logging.js +335 -0
- package/dist/migrations/index.js +40 -0
- package/dist/migrations/migration.js +196 -0
- package/dist/migrations/migrator.js +411 -0
- package/dist/migrations/prormmigration.js +275 -0
- package/dist/migrations/query-interface.js +435 -0
- package/dist/migrations/seeder.js +353 -0
- package/dist/models/associations.js +852 -0
- package/dist/models/constraints.js +288 -0
- package/dist/models/data-types.js +2518 -0
- package/dist/models/decorators.js +445 -0
- package/dist/models/index.js +33 -0
- package/dist/models/indexes.js +531 -0
- package/dist/models/methods.js +382 -0
- package/dist/models/model-manager.js +103 -0
- package/dist/models/model.js +5349 -0
- package/dist/models/operators.js +67 -0
- package/dist/models/scopes.js +189 -0
- package/dist/models/typescript-types.js +26 -0
- package/dist/nosql/aerospike/index.js +205 -0
- package/dist/nosql/allegrograph/index.js +169 -0
- package/dist/nosql/arangodb/index.js +364 -0
- package/dist/nosql/azure-blob/index.js +206 -0
- package/dist/nosql/beanstalkd/index.js +231 -0
- package/dist/nosql/beequeue/index.js +210 -0
- package/dist/nosql/bigchaindb/index.js +195 -0
- package/dist/nosql/bigtable/index.js +224 -0
- package/dist/nosql/blazegraph/index.js +173 -0
- package/dist/nosql/bullmq/index.js +191 -0
- package/dist/nosql/cassandra/index.js +174 -0
- package/dist/nosql/chroma/index.js +190 -0
- package/dist/nosql/cloudflare-kv/index.js +220 -0
- package/dist/nosql/coherence/index.js +200 -0
- package/dist/nosql/cosmosdb/index.js +157 -0
- package/dist/nosql/couchbase/index.js +213 -0
- package/dist/nosql/dax/index.js +212 -0
- package/dist/nosql/deno-kv/index.js +206 -0
- package/dist/nosql/dgraph/index.js +171 -0
- package/dist/nosql/doris/index.js +169 -0
- package/dist/nosql/druid/index.js +162 -0
- package/dist/nosql/dynamodb/index.js +937 -0
- package/dist/nosql/elasticsearch/index.js +377 -0
- package/dist/nosql/etcd/index.js +502 -0
- package/dist/nosql/eventhubs/index.js +213 -0
- package/dist/nosql/eventstore/index.js +254 -0
- package/dist/nosql/faunadb/index.js +188 -0
- package/dist/nosql/firestore/index.js +177 -0
- package/dist/nosql/fluree/index.js +148 -0
- package/dist/nosql/fuseki/index.js +170 -0
- package/dist/nosql/gcs/index.js +172 -0
- package/dist/nosql/gearman/index.js +160 -0
- package/dist/nosql/geode/index.js +196 -0
- package/dist/nosql/graphdb/index.js +169 -0
- package/dist/nosql/graylog/index.js +188 -0
- package/dist/nosql/gridgain/index.js +171 -0
- package/dist/nosql/hazelcast/index.js +162 -0
- package/dist/nosql/hbase/index.js +230 -0
- package/dist/nosql/ignite/index.js +173 -0
- package/dist/nosql/immudb/index.js +184 -0
- package/dist/nosql/index.js +232 -0
- package/dist/nosql/infinispan/index.js +200 -0
- package/dist/nosql/influxdb/index.js +0 -0
- package/dist/nosql/kafka/index.js +234 -0
- package/dist/nosql/keyspaces/index.js +189 -0
- package/dist/nosql/kinesis/index.js +253 -0
- package/dist/nosql/leveldb/index.js +153 -0
- package/dist/nosql/lmdb/index.js +160 -0
- package/dist/nosql/loki/index.js +201 -0
- package/dist/nosql/marklogic/index.js +204 -0
- package/dist/nosql/materialize/index.js +145 -0
- package/dist/nosql/meilisearch/index.js +154 -0
- package/dist/nosql/memcached/index.js +223 -0
- package/dist/nosql/milvus/index.js +410 -0
- package/dist/nosql/minio/index.js +265 -0
- package/dist/nosql/momento/index.js +179 -0
- package/dist/nosql/mongodb/index.js +461 -0
- package/dist/nosql/nats/index.js +247 -0
- package/dist/nosql/nedb/index.js +164 -0
- package/dist/nosql/neo4j/index.js +450 -0
- package/dist/nosql/neptune/index.js +470 -0
- package/dist/nosql/nsq/index.js +200 -0
- package/dist/nosql/opensearch/index.js +186 -0
- package/dist/nosql/orientdb/index.js +175 -0
- package/dist/nosql/papertrail/index.js +200 -0
- package/dist/nosql/pinecone/index.js +0 -0
- package/dist/nosql/pinot/index.js +133 -0
- package/dist/nosql/pouchdb/index.js +172 -0
- package/dist/nosql/prometheus/index.js +174 -0
- package/dist/nosql/provendb/index.js +147 -0
- package/dist/nosql/pubsub/index.js +187 -0
- package/dist/nosql/pulsar/index.js +232 -0
- package/dist/nosql/qdrant/index.js +295 -0
- package/dist/nosql/qldb/index.js +192 -0
- package/dist/nosql/r2/index.js +281 -0
- package/dist/nosql/rabbitmq/index.js +237 -0
- package/dist/nosql/ravendb/index.js +175 -0
- package/dist/nosql/redis/index.js +607 -0
- package/dist/nosql/redpanda/index.js +237 -0
- package/dist/nosql/resque/index.js +203 -0
- package/dist/nosql/rethinkdb/index.js +232 -0
- package/dist/nosql/rocksdb/index.js +152 -0
- package/dist/nosql/rockset/index.js +126 -0
- package/dist/nosql/s3/index.js +298 -0
- package/dist/nosql/scylladb/index.js +178 -0
- package/dist/nosql/signoz/index.js +227 -0
- package/dist/nosql/sns/index.js +201 -0
- package/dist/nosql/solr/index.js +231 -0
- package/dist/nosql/splunk/index.js +227 -0
- package/dist/nosql/sqs/index.js +246 -0
- package/dist/nosql/stardog/index.js +169 -0
- package/dist/nosql/starrocks/index.js +170 -0
- package/dist/nosql/store.js +2 -0
- package/dist/nosql/sumologic/index.js +213 -0
- package/dist/nosql/surrealdb/index.js +179 -0
- package/dist/nosql/terminusdb/index.js +151 -0
- package/dist/nosql/tigergraph/index.js +469 -0
- package/dist/nosql/typesense/index.js +148 -0
- package/dist/nosql/unqlite/index.js +157 -0
- package/dist/nosql/upstash/index.js +167 -0
- package/dist/nosql/vercel-kv/index.js +166 -0
- package/dist/nosql/victoriametrics/index.js +213 -0
- package/dist/nosql/virtuoso/index.js +169 -0
- package/dist/nosql/weaviate/index.js +276 -0
- package/dist/operators/index.js +108 -0
- package/dist/operators.js +2690 -0
- package/dist/prisma-migrate/index.js +38 -0
- package/dist/prisma-migrate/migration-generator.js +125 -0
- package/dist/prisma-migrate/model-generator.js +172 -0
- package/dist/prisma-migrate/relations.js +100 -0
- package/dist/prisma-migrate/schema-parser.js +167 -0
- package/dist/prisma-migrate/type-mapper.js +40 -0
- package/dist/prorm.js +6832 -0
- package/dist/query-builders/cte-builder.js +80 -0
- package/dist/query-builders/functions/aggregate.js +390 -0
- package/dist/query-builders/functions/conditional.js +503 -0
- package/dist/query-builders/functions/datetime.js +695 -0
- package/dist/query-builders/functions/fulltext.js +439 -0
- package/dist/query-builders/functions/index.js +93 -0
- package/dist/query-builders/functions/json.js +427 -0
- package/dist/query-builders/functions/math.js +399 -0
- package/dist/query-builders/functions/string.js +518 -0
- package/dist/query-builders/functions/window.js +328 -0
- package/dist/query-builders/include-builder.js +323 -0
- package/dist/query-builders/index-expression-builder.js +242 -0
- package/dist/query-builders/index.js +161 -0
- package/dist/query-builders/insert-builder.js +164 -0
- package/dist/query-builders/model-helpers.js +38 -0
- package/dist/query-builders/order-limit-builder.js +239 -0
- package/dist/query-builders/sql-compiler.js +2040 -0
- package/dist/query-builders/subquery-builder.js +152 -0
- package/dist/query-builders/update-builder.js +182 -0
- package/dist/query-builders/view-builder.js +218 -0
- package/dist/query-builders/where-builder.js +1532 -0
- package/dist/query-interface.js +622 -0
- package/dist/query-optimizers/batch-optimizer.js +426 -0
- package/dist/query-optimizers/explain-plans.js +415 -0
- package/dist/query-optimizers/index.js +51 -0
- package/dist/query-optimizers/prepared-statement-cache.js +423 -0
- package/dist/query-optimizers/query-hints.js +438 -0
- package/dist/query-optimizers/query-optimizer.js +278 -0
- package/dist/query-optimizers/slow-query-logger.js +271 -0
- package/dist/replica-manager.js +507 -0
- package/dist/schema/index.js +15 -0
- package/dist/schema/migration-generator.js +374 -0
- package/dist/schema/schema-differ.js +549 -0
- package/dist/schema/types.js +6 -0
- package/dist/sql-constants.js +300 -0
- package/dist/sqlite-advanced.js +1047 -0
- package/dist/streams/index.js +12 -0
- package/dist/streams/transforms.js +178 -0
- package/dist/transaction.js +456 -0
- package/dist/types/index.js +180 -0
- package/dist/user-management.js +127 -0
- package/dist/utils/date.js +300 -0
- package/dist/utils/index.js +1079 -0
- package/dist/utils/string.js +161 -0
- package/dist/validators/index.js +19 -0
- package/dist/validators/validator.js +911 -0
- package/package.json +190 -0
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Security Decorator
|
|
4
|
+
*
|
|
5
|
+
* A comprehensive decorator that applies multiple compliance controls to a model
|
|
6
|
+
* based on a list of security frameworks. Works with the 12 compliance classes.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* @Security({
|
|
10
|
+
* frameworks: ['GDPR', 'HIPAA', 'PCI_DSS'],
|
|
11
|
+
* audit: true,
|
|
12
|
+
* encrypt: ['ssn', 'creditCard'],
|
|
13
|
+
* mask: { ssn: 'ssn', creditCard: 'card-last4' },
|
|
14
|
+
* retention: { years: 7 },
|
|
15
|
+
* })
|
|
16
|
+
* class User extends Model { ... }
|
|
17
|
+
*
|
|
18
|
+
* @Security({
|
|
19
|
+
* frameworks: ['SOX', 'SEC_17A_4'],
|
|
20
|
+
* immutable: true,
|
|
21
|
+
* })
|
|
22
|
+
* class FinancialRecord extends Model { ... }
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.FrameworkRequirements = exports.FrameworkCount = exports.FrameworkCategories = exports.AllFrameworks = exports.SecurityFramework = void 0;
|
|
26
|
+
exports.isValidFramework = isValidFramework;
|
|
27
|
+
exports.getFrameworkCategory = getFrameworkCategory;
|
|
28
|
+
exports.getAllFrameworks = getAllFrameworks;
|
|
29
|
+
exports.Security = Security;
|
|
30
|
+
exports.setupSecurity = setupSecurity;
|
|
31
|
+
exports.setupAllSecurity = setupAllSecurity;
|
|
32
|
+
exports.Table = Table;
|
|
33
|
+
exports.Database = Database;
|
|
34
|
+
exports.getTableSecurity = getTableSecurity;
|
|
35
|
+
exports.getDatabaseSecurity = getDatabaseSecurity;
|
|
36
|
+
exports.getSecurityFrameworks = getSecurityFrameworks;
|
|
37
|
+
exports.hasAudit = hasAudit;
|
|
38
|
+
exports.isImmutableModel = isImmutableModel;
|
|
39
|
+
const audit_trail_1 = require("./audit-trail");
|
|
40
|
+
const field_encryption_1 = require("./field-encryption");
|
|
41
|
+
const data_retention_1 = require("./data-retention");
|
|
42
|
+
const data_masker_1 = require("./data-masker");
|
|
43
|
+
const immutable_record_1 = require("./immutable-record");
|
|
44
|
+
const row_level_security_1 = require("./row-level-security");
|
|
45
|
+
const data_classifier_1 = require("./data-classifier");
|
|
46
|
+
const data_lineage_1 = require("./data-lineage");
|
|
47
|
+
const session_isolation_1 = require("./session-isolation");
|
|
48
|
+
const worm_storage_1 = require("./worm-storage");
|
|
49
|
+
const rate_limiter_1 = require("./rate-limiter");
|
|
50
|
+
const cross_border_log_1 = require("./cross-border-log");
|
|
51
|
+
// ==================== Framework Enum ====================
|
|
52
|
+
/**
|
|
53
|
+
* All supported security/compliance frameworks.
|
|
54
|
+
* These map to the 218+ frameworks in docs/sec/SECURITY_COMPLIANCE.md
|
|
55
|
+
*/
|
|
56
|
+
exports.SecurityFramework = {
|
|
57
|
+
// === Privacy Regulations ===
|
|
58
|
+
GDPR: 'GDPR',
|
|
59
|
+
CCPA: 'CCPA',
|
|
60
|
+
CPRA: 'CPRA',
|
|
61
|
+
PIPEDA: 'PIPEDA',
|
|
62
|
+
LGPD: 'LGPD',
|
|
63
|
+
APPI: 'APPI',
|
|
64
|
+
PIPA: 'PIPA',
|
|
65
|
+
PIPL: 'PIPL',
|
|
66
|
+
DPDP: 'DPDP',
|
|
67
|
+
PDPA_THAILAND: 'PDPA_Thailand',
|
|
68
|
+
PDPA_SINGAPORE: 'PDPA_Singapore',
|
|
69
|
+
PDPA_PHILIPPINES: 'PDPA_Philippines',
|
|
70
|
+
PDPA_MALAYSIA: 'PDPA_Malaysia',
|
|
71
|
+
PDPA_INDONESIA: 'PDPA_Indonesia',
|
|
72
|
+
PDPA_VIETNAM: 'PDPA_Vietnam',
|
|
73
|
+
POPI: 'PoPI',
|
|
74
|
+
NDPR: 'NDPR',
|
|
75
|
+
KVKK: 'KVKK',
|
|
76
|
+
UK_GDPR: 'UK_GDPR',
|
|
77
|
+
// === Financial Regulations ===
|
|
78
|
+
PCI_DSS: 'PCI_DSS',
|
|
79
|
+
SOX: 'SOX',
|
|
80
|
+
GLBA: 'GLBA',
|
|
81
|
+
MIDIF_II: 'MiFID_II',
|
|
82
|
+
EMIR: 'EMIR',
|
|
83
|
+
BASEL_III: 'Basel_III',
|
|
84
|
+
DODD_FRANK: 'Dodd_Frank',
|
|
85
|
+
SEC_17A_4: 'SEC_17a_4',
|
|
86
|
+
FINRA: 'FINRA',
|
|
87
|
+
NYDFS: 'NYDFS',
|
|
88
|
+
DORA: 'DORA',
|
|
89
|
+
// === Healthcare ===
|
|
90
|
+
HIPAA: 'HIPAA',
|
|
91
|
+
HITRUST: 'HITRUST',
|
|
92
|
+
CFR_21_PART_11: '21_CFR_Part_11',
|
|
93
|
+
EU_ANNEX_11: 'EU_Annex_11',
|
|
94
|
+
ALCOA_PLUS: 'ALCOA+',
|
|
95
|
+
GAMP_5: 'GAMP_5',
|
|
96
|
+
ICH_E6_GCP: 'ICH_E6_GCP',
|
|
97
|
+
DISHA: 'DISHA',
|
|
98
|
+
// === Government / Defense ===
|
|
99
|
+
FEDRAMP: 'FedRAMP',
|
|
100
|
+
FISMA: 'FISMA',
|
|
101
|
+
NIST_800_53: 'NIST_SP_800_53',
|
|
102
|
+
NIST_800_171: 'NIST_SP_800_171',
|
|
103
|
+
NIST_CSF: 'NIST_CSF',
|
|
104
|
+
CMMC: 'CMMC',
|
|
105
|
+
DFARS: 'DFARS',
|
|
106
|
+
ITAR: 'ITAR',
|
|
107
|
+
CJIS: 'CJIS',
|
|
108
|
+
NERC_CIP: 'NERC_CIP',
|
|
109
|
+
// === Industry Standards ===
|
|
110
|
+
ISO_27001: 'ISO_27001',
|
|
111
|
+
ISO_27017: 'ISO_27017',
|
|
112
|
+
ISO_27018: 'ISO_27018',
|
|
113
|
+
ISO_27701: 'ISO_27701',
|
|
114
|
+
ISO_22301: 'ISO_22301',
|
|
115
|
+
SOC_2: 'SOC_2',
|
|
116
|
+
SOC_1: 'SOC_1',
|
|
117
|
+
CIS_CONTROLS: 'CIS_Controls',
|
|
118
|
+
OWASP_TOP_10: 'OWASP_Top_10',
|
|
119
|
+
// === Cloud & International ===
|
|
120
|
+
CLOUD_ACT: 'CLOUD_Act',
|
|
121
|
+
SCHREMS_II: 'Schrems_II',
|
|
122
|
+
ESSENTIAL_EIGHT: 'Essential_Eight',
|
|
123
|
+
IT_GRUNDSCHUTZ: 'IT_Grundschutz',
|
|
124
|
+
};
|
|
125
|
+
// ==================== Framework Map / Set ====================
|
|
126
|
+
/**
|
|
127
|
+
* Set of all valid security framework names.
|
|
128
|
+
* Use for validation: `if (AllFrameworks.has(myFramework)) { ... }`
|
|
129
|
+
*/
|
|
130
|
+
exports.AllFrameworks = new Set(Object.values(exports.SecurityFramework));
|
|
131
|
+
/**
|
|
132
|
+
* Map of framework category to framework names.
|
|
133
|
+
* Useful for UI dropdowns or grouped validation.
|
|
134
|
+
*/
|
|
135
|
+
exports.FrameworkCategories = {
|
|
136
|
+
'Privacy Regulations': [
|
|
137
|
+
exports.SecurityFramework.GDPR,
|
|
138
|
+
exports.SecurityFramework.CCPA,
|
|
139
|
+
exports.SecurityFramework.CPRA,
|
|
140
|
+
exports.SecurityFramework.PIPEDA,
|
|
141
|
+
exports.SecurityFramework.LGPD,
|
|
142
|
+
exports.SecurityFramework.APPI,
|
|
143
|
+
exports.SecurityFramework.PIPA,
|
|
144
|
+
exports.SecurityFramework.PIPL,
|
|
145
|
+
exports.SecurityFramework.DPDP,
|
|
146
|
+
exports.SecurityFramework.PDPA_THAILAND,
|
|
147
|
+
exports.SecurityFramework.PDPA_SINGAPORE,
|
|
148
|
+
exports.SecurityFramework.PDPA_PHILIPPINES,
|
|
149
|
+
exports.SecurityFramework.PDPA_MALAYSIA,
|
|
150
|
+
exports.SecurityFramework.PDPA_INDONESIA,
|
|
151
|
+
exports.SecurityFramework.PDPA_VIETNAM,
|
|
152
|
+
exports.SecurityFramework.POPI,
|
|
153
|
+
exports.SecurityFramework.NDPR,
|
|
154
|
+
exports.SecurityFramework.KVKK,
|
|
155
|
+
exports.SecurityFramework.UK_GDPR,
|
|
156
|
+
],
|
|
157
|
+
'Financial Regulations': [
|
|
158
|
+
exports.SecurityFramework.PCI_DSS,
|
|
159
|
+
exports.SecurityFramework.SOX,
|
|
160
|
+
exports.SecurityFramework.GLBA,
|
|
161
|
+
exports.SecurityFramework.MIDIF_II,
|
|
162
|
+
exports.SecurityFramework.EMIR,
|
|
163
|
+
exports.SecurityFramework.BASEL_III,
|
|
164
|
+
exports.SecurityFramework.DODD_FRANK,
|
|
165
|
+
exports.SecurityFramework.SEC_17A_4,
|
|
166
|
+
exports.SecurityFramework.FINRA,
|
|
167
|
+
exports.SecurityFramework.NYDFS,
|
|
168
|
+
exports.SecurityFramework.DORA,
|
|
169
|
+
],
|
|
170
|
+
'Healthcare': [
|
|
171
|
+
exports.SecurityFramework.HIPAA,
|
|
172
|
+
exports.SecurityFramework.HITRUST,
|
|
173
|
+
exports.SecurityFramework.CFR_21_PART_11,
|
|
174
|
+
exports.SecurityFramework.EU_ANNEX_11,
|
|
175
|
+
exports.SecurityFramework.ALCOA_PLUS,
|
|
176
|
+
exports.SecurityFramework.GAMP_5,
|
|
177
|
+
exports.SecurityFramework.ICH_E6_GCP,
|
|
178
|
+
exports.SecurityFramework.DISHA,
|
|
179
|
+
],
|
|
180
|
+
'Government / Defense': [
|
|
181
|
+
exports.SecurityFramework.FEDRAMP,
|
|
182
|
+
exports.SecurityFramework.FISMA,
|
|
183
|
+
exports.SecurityFramework.NIST_800_53,
|
|
184
|
+
exports.SecurityFramework.NIST_800_171,
|
|
185
|
+
exports.SecurityFramework.NIST_CSF,
|
|
186
|
+
exports.SecurityFramework.CMMC,
|
|
187
|
+
exports.SecurityFramework.DFARS,
|
|
188
|
+
exports.SecurityFramework.ITAR,
|
|
189
|
+
exports.SecurityFramework.CJIS,
|
|
190
|
+
exports.SecurityFramework.NERC_CIP,
|
|
191
|
+
],
|
|
192
|
+
'Industry Standards': [
|
|
193
|
+
exports.SecurityFramework.ISO_27001,
|
|
194
|
+
exports.SecurityFramework.ISO_27017,
|
|
195
|
+
exports.SecurityFramework.ISO_27018,
|
|
196
|
+
exports.SecurityFramework.ISO_27701,
|
|
197
|
+
exports.SecurityFramework.ISO_22301,
|
|
198
|
+
exports.SecurityFramework.SOC_2,
|
|
199
|
+
exports.SecurityFramework.SOC_1,
|
|
200
|
+
exports.SecurityFramework.CIS_CONTROLS,
|
|
201
|
+
exports.SecurityFramework.OWASP_TOP_10,
|
|
202
|
+
],
|
|
203
|
+
'Cloud & International': [
|
|
204
|
+
exports.SecurityFramework.CLOUD_ACT,
|
|
205
|
+
exports.SecurityFramework.SCHREMS_II,
|
|
206
|
+
exports.SecurityFramework.ESSENTIAL_EIGHT,
|
|
207
|
+
exports.SecurityFramework.IT_GRUNDSCHUTZ,
|
|
208
|
+
],
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* Validate that a framework name is valid.
|
|
212
|
+
*
|
|
213
|
+
* @param framework - Framework name to validate
|
|
214
|
+
* @returns true if valid, false otherwise
|
|
215
|
+
*/
|
|
216
|
+
function isValidFramework(framework) {
|
|
217
|
+
return exports.AllFrameworks.has(framework);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get the category for a specific framework.
|
|
221
|
+
*/
|
|
222
|
+
function getFrameworkCategory(framework) {
|
|
223
|
+
for (const [category, frameworks] of Object.entries(exports.FrameworkCategories)) {
|
|
224
|
+
if (frameworks.includes(framework)) {
|
|
225
|
+
return category;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return undefined;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get all frameworks as an array.
|
|
232
|
+
*/
|
|
233
|
+
function getAllFrameworks() {
|
|
234
|
+
return Array.from(exports.AllFrameworks);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get framework count.
|
|
238
|
+
*/
|
|
239
|
+
exports.FrameworkCount = exports.AllFrameworks.size; // 80 frameworks
|
|
240
|
+
/**
|
|
241
|
+
* Map of framework to its required security controls.
|
|
242
|
+
* Used internally to determine which controls to apply.
|
|
243
|
+
*/
|
|
244
|
+
exports.FrameworkRequirements = {
|
|
245
|
+
// GDPR - comprehensive
|
|
246
|
+
[exports.SecurityFramework.GDPR]: { audit: true, encryption: true, retention: true, masking: true, consent: true, rls: true, pseudonymize: true, classification: true, tls: true, lineage: true },
|
|
247
|
+
[exports.SecurityFramework.CCPA]: { audit: true, encryption: true, retention: true, masking: true, consent: true, rls: true },
|
|
248
|
+
[exports.SecurityFramework.CPRA]: { audit: true, encryption: true, retention: true, masking: true, consent: true, rls: true },
|
|
249
|
+
[exports.SecurityFramework.PIPEDA]: { audit: true, encryption: true, retention: true, consent: true, rls: true },
|
|
250
|
+
[exports.SecurityFramework.LGPD]: { audit: true, encryption: true, retention: true, consent: true, rls: true },
|
|
251
|
+
[exports.SecurityFramework.APPI]: { audit: true, encryption: true, consent: true, rls: true },
|
|
252
|
+
[exports.SecurityFramework.PIPA]: { audit: true, encryption: true, consent: true, rls: true },
|
|
253
|
+
[exports.SecurityFramework.PIPL]: { audit: true, encryption: true, retention: true, classification: true, tls: true },
|
|
254
|
+
[exports.SecurityFramework.DPDP]: { audit: true, encryption: true, retention: true, consent: true, rls: true },
|
|
255
|
+
// Financial
|
|
256
|
+
[exports.SecurityFramework.PCI_DSS]: { audit: true, encryption: true, masking: true, tls: true },
|
|
257
|
+
[exports.SecurityFramework.SOX]: { audit: true, immutable: true, retention: true, lineage: true, worm: true },
|
|
258
|
+
[exports.SecurityFramework.GLBA]: { audit: true, encryption: true, masking: true },
|
|
259
|
+
[exports.SecurityFramework.MIDIF_II]: { audit: true, retention: true },
|
|
260
|
+
[exports.SecurityFramework.EMIR]: { audit: true, retention: true },
|
|
261
|
+
[exports.SecurityFramework.BASEL_III]: { audit: true, retention: true, lineage: true },
|
|
262
|
+
[exports.SecurityFramework.DODD_FRANK]: { audit: true, retention: true },
|
|
263
|
+
[exports.SecurityFramework.SEC_17A_4]: { audit: true, immutable: true, retention: true, worm: true },
|
|
264
|
+
[exports.SecurityFramework.FINRA]: { audit: true, retention: true },
|
|
265
|
+
[exports.SecurityFramework.NYDFS]: { audit: true, encryption: true, tls: true },
|
|
266
|
+
[exports.SecurityFramework.DORA]: { audit: true, encryption: true, retention: true, rls: true, worm: true },
|
|
267
|
+
// Healthcare
|
|
268
|
+
[exports.SecurityFramework.HIPAA]: { audit: true, encryption: true, masking: true, rls: true, classification: true, lineage: true },
|
|
269
|
+
[exports.SecurityFramework.HITRUST]: { audit: true, encryption: true, masking: true, rls: true, classification: true },
|
|
270
|
+
[exports.SecurityFramework.CFR_21_PART_11]: { audit: true, immutable: true },
|
|
271
|
+
[exports.SecurityFramework.EU_ANNEX_11]: { audit: true, immutable: true },
|
|
272
|
+
[exports.SecurityFramework.ALCOA_PLUS]: { audit: true, immutable: true },
|
|
273
|
+
[exports.SecurityFramework.GAMP_5]: { audit: true, immutable: true },
|
|
274
|
+
[exports.SecurityFramework.ICH_E6_GCP]: { audit: true, immutable: true },
|
|
275
|
+
[exports.SecurityFramework.DISHA]: { encryption: true, classification: true },
|
|
276
|
+
// Government/Defense
|
|
277
|
+
[exports.SecurityFramework.FEDRAMP]: { encryption: true, tls: true, classification: true, sessionIsolation: true },
|
|
278
|
+
[exports.SecurityFramework.FISMA]: { audit: true, encryption: true, tls: true },
|
|
279
|
+
[exports.SecurityFramework.NIST_800_53]: { audit: true, encryption: true, rls: true, classification: true },
|
|
280
|
+
[exports.SecurityFramework.NIST_800_171]: { audit: true, encryption: true, rls: true },
|
|
281
|
+
[exports.SecurityFramework.NIST_CSF]: { audit: true, encryption: true, retention: true, classification: true, breachDetection: true },
|
|
282
|
+
[exports.SecurityFramework.CMMC]: { encryption: true, rls: true },
|
|
283
|
+
[exports.SecurityFramework.DFARS]: { encryption: true, rls: true },
|
|
284
|
+
[exports.SecurityFramework.ITAR]: { encryption: true, classification: true },
|
|
285
|
+
[exports.SecurityFramework.CJIS]: { audit: true, encryption: true, rls: true },
|
|
286
|
+
[exports.SecurityFramework.NERC_CIP]: { audit: true, encryption: true, rls: true },
|
|
287
|
+
// Industry Standards
|
|
288
|
+
[exports.SecurityFramework.ISO_27001]: { audit: true, encryption: true, rls: true, classification: true },
|
|
289
|
+
[exports.SecurityFramework.ISO_27017]: { encryption: true, tls: true, sessionIsolation: true },
|
|
290
|
+
[exports.SecurityFramework.ISO_27018]: { encryption: true, classification: true },
|
|
291
|
+
[exports.SecurityFramework.ISO_27701]: { classification: true, consent: true },
|
|
292
|
+
[exports.SecurityFramework.ISO_22301]: { retention: true },
|
|
293
|
+
[exports.SecurityFramework.SOC_2]: { audit: true, encryption: true, retention: true },
|
|
294
|
+
[exports.SecurityFramework.SOC_1]: { audit: true, retention: true },
|
|
295
|
+
[exports.SecurityFramework.CIS_CONTROLS]: {
|
|
296
|
+
audit: true,
|
|
297
|
+
encryption: true,
|
|
298
|
+
breachDetection: true,
|
|
299
|
+
rateLimit: true,
|
|
300
|
+
backupVerification: true,
|
|
301
|
+
},
|
|
302
|
+
[exports.SecurityFramework.OWASP_TOP_10]: { encryption: true, masking: true, rateLimit: true, queryFirewall: true },
|
|
303
|
+
// Cloud & International
|
|
304
|
+
[exports.SecurityFramework.CLOUD_ACT]: { encryption: true, classification: true },
|
|
305
|
+
[exports.SecurityFramework.SCHREMS_II]: { encryption: true, pseudonymize: true },
|
|
306
|
+
[exports.SecurityFramework.ESSENTIAL_EIGHT]: { encryption: true, rls: true },
|
|
307
|
+
[exports.SecurityFramework.IT_GRUNDSCHUTZ]: { audit: true, encryption: true, rls: true },
|
|
308
|
+
// Default for unknown frameworks
|
|
309
|
+
[exports.SecurityFramework.PDPA_THAILAND]: { audit: true, encryption: true, consent: true, rls: true },
|
|
310
|
+
[exports.SecurityFramework.PDPA_SINGAPORE]: { audit: true, encryption: true, consent: true, rls: true },
|
|
311
|
+
[exports.SecurityFramework.PDPA_PHILIPPINES]: { audit: true, encryption: true, consent: true, rls: true },
|
|
312
|
+
[exports.SecurityFramework.PDPA_MALAYSIA]: { audit: true, encryption: true, consent: true, rls: true },
|
|
313
|
+
[exports.SecurityFramework.PDPA_INDONESIA]: { audit: true, encryption: true, consent: true, rls: true },
|
|
314
|
+
[exports.SecurityFramework.PDPA_VIETNAM]: { audit: true, encryption: true, consent: true, rls: true },
|
|
315
|
+
[exports.SecurityFramework.POPI]: { audit: true, encryption: true, consent: true, rls: true },
|
|
316
|
+
[exports.SecurityFramework.NDPR]: { audit: true, encryption: true, consent: true, rls: true },
|
|
317
|
+
[exports.SecurityFramework.KVKK]: { audit: true, encryption: true, consent: true, rls: true },
|
|
318
|
+
[exports.SecurityFramework.UK_GDPR]: { audit: true, encryption: true, retention: true, masking: true, consent: true, rls: true, pseudonymize: true, classification: true, tls: true },
|
|
319
|
+
};
|
|
320
|
+
// ==================== Security Decorator ====================
|
|
321
|
+
/**
|
|
322
|
+
* Apply security controls to a model based on specified frameworks.
|
|
323
|
+
*
|
|
324
|
+
* @param options - Security configuration
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* @Security({
|
|
328
|
+
* frameworks: ['GDPR', 'HIPAA', 'PCI_DSS'],
|
|
329
|
+
* audit: true,
|
|
330
|
+
* encrypt: ['ssn', 'creditCard'],
|
|
331
|
+
* mask: { ssn: 'ssn', creditCard: 'card-last4' },
|
|
332
|
+
* retention: { years: 7 },
|
|
333
|
+
* autoClassify: true,
|
|
334
|
+
* })
|
|
335
|
+
* class Patient extends Model { ... }
|
|
336
|
+
*/
|
|
337
|
+
function Security(options) {
|
|
338
|
+
return function (target) {
|
|
339
|
+
const frameworks = options.frameworks ?? [];
|
|
340
|
+
const requirements = new Set();
|
|
341
|
+
// Aggregate requirements from all frameworks
|
|
342
|
+
for (const fw of frameworks) {
|
|
343
|
+
const req = exports.FrameworkRequirements[fw];
|
|
344
|
+
if (req) {
|
|
345
|
+
Object.entries(req).forEach(([key, value]) => {
|
|
346
|
+
if (value)
|
|
347
|
+
requirements.add(key);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
// Apply audit trail if needed
|
|
352
|
+
if (options.audit || requirements.has('audit')) {
|
|
353
|
+
// Audit will be applied at runtime via setup call
|
|
354
|
+
target.__security_audit = true;
|
|
355
|
+
target.__security_getUserId = options.getUserId;
|
|
356
|
+
target.__security_getIpAddress = options.getIpAddress;
|
|
357
|
+
}
|
|
358
|
+
// Apply field encryption
|
|
359
|
+
if (options.encrypt && options.encrypt.length > 0) {
|
|
360
|
+
for (const field of options.encrypt) {
|
|
361
|
+
(0, field_encryption_1.Encrypt)(field)(target);
|
|
362
|
+
}
|
|
363
|
+
target.__security_encrypted = options.encrypt;
|
|
364
|
+
}
|
|
365
|
+
// Apply field masking
|
|
366
|
+
if (options.mask) {
|
|
367
|
+
for (const [field, pattern] of Object.entries(options.mask)) {
|
|
368
|
+
(0, data_masker_1.Mask)(field, { pattern })(target);
|
|
369
|
+
}
|
|
370
|
+
target.__security_masked = Object.keys(options.mask);
|
|
371
|
+
}
|
|
372
|
+
// Apply retention policy
|
|
373
|
+
if (options.retention) {
|
|
374
|
+
target.__security_retention = options.retention;
|
|
375
|
+
}
|
|
376
|
+
// Apply immutability
|
|
377
|
+
// Note: hook registration is deferred to setupSecurity() because the model
|
|
378
|
+
// may not yet be attached to a Prorm instance at class-decoration time
|
|
379
|
+
// (addHook() requires Model.prorm to be set).
|
|
380
|
+
if (options.immutable || requirements.has('immutable')) {
|
|
381
|
+
target.__security_immutable = true;
|
|
382
|
+
target.__security_versioning = Boolean(options.versioning || requirements.has('immutable'));
|
|
383
|
+
}
|
|
384
|
+
// Apply RLS
|
|
385
|
+
if (options.rls) {
|
|
386
|
+
(0, row_level_security_1.apply)(target, options.rls);
|
|
387
|
+
target.__security_rls = true;
|
|
388
|
+
}
|
|
389
|
+
// Apply classification
|
|
390
|
+
if (options.classify) {
|
|
391
|
+
for (const [field, category] of Object.entries(options.classify)) {
|
|
392
|
+
(0, data_classifier_1.FieldClassification)(field, category)(target);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (options.autoClassify || requirements.has('classification')) {
|
|
396
|
+
(0, data_classifier_1.autoDiscover)(target);
|
|
397
|
+
}
|
|
398
|
+
// Apply data lineage tracking
|
|
399
|
+
if (options.lineage || requirements.has('lineage')) {
|
|
400
|
+
(0, data_lineage_1.LineageTrack)()(target);
|
|
401
|
+
target.__security_lineage = true;
|
|
402
|
+
}
|
|
403
|
+
// Apply breach detection
|
|
404
|
+
if (options.breachDetection || requirements.has('breachDetection')) {
|
|
405
|
+
target.__security_breach_detection = true;
|
|
406
|
+
}
|
|
407
|
+
// Apply session isolation
|
|
408
|
+
if (options.sessionIsolation || requirements.has('sessionIsolation')) {
|
|
409
|
+
(0, session_isolation_1.TenantIsolation)({ tenantId: options.tenantIdField ?? 'tenantId' })(target);
|
|
410
|
+
target.__security_session_isolation = true;
|
|
411
|
+
}
|
|
412
|
+
// Apply WORM storage
|
|
413
|
+
if (options.worm || requirements.has('worm')) {
|
|
414
|
+
(0, worm_storage_1.WORM)({ retentionPeriod: options.retention ?? { years: 7 }, tamperEvident: true })(target);
|
|
415
|
+
target.__security_worm = true;
|
|
416
|
+
}
|
|
417
|
+
// Apply rate limiting
|
|
418
|
+
if (options.rateLimit || requirements.has('rateLimit')) {
|
|
419
|
+
(0, rate_limiter_1.RateLimit)({})(target);
|
|
420
|
+
target.__security_rate_limit = true;
|
|
421
|
+
}
|
|
422
|
+
// Apply sensitive data discovery
|
|
423
|
+
if (options.sensitiveDataDiscovery || requirements.has('sensitiveDataDiscovery')) {
|
|
424
|
+
target.__security_sensitive_data_discovery = true;
|
|
425
|
+
}
|
|
426
|
+
// Apply cross-border transfer logging
|
|
427
|
+
if (options.crossBorderLog || requirements.has('crossBorderLog')) {
|
|
428
|
+
cross_border_log_1.CrossBorderLog.enable(null, target);
|
|
429
|
+
target.__security_cross_border_log = true;
|
|
430
|
+
}
|
|
431
|
+
// Apply consent versioning
|
|
432
|
+
if (options.consentVersioning || requirements.has('consentVersioning')) {
|
|
433
|
+
target.__security_consent_versioning = true;
|
|
434
|
+
}
|
|
435
|
+
// Apply DSAR workflow
|
|
436
|
+
if (options.dsar || requirements.has('dsar')) {
|
|
437
|
+
target.__security_dsar = true;
|
|
438
|
+
}
|
|
439
|
+
// Apply privacy impact assessment
|
|
440
|
+
if (options.pia || requirements.has('pia')) {
|
|
441
|
+
target.__security_pia = true;
|
|
442
|
+
}
|
|
443
|
+
// Apply backup verification
|
|
444
|
+
if (options.backupVerification || requirements.has('backupVerification')) {
|
|
445
|
+
target.__security_backup_verification = true;
|
|
446
|
+
}
|
|
447
|
+
// Apply query firewall
|
|
448
|
+
if (options.queryFirewall || requirements.has('queryFirewall')) {
|
|
449
|
+
target.__security_query_firewall = true;
|
|
450
|
+
}
|
|
451
|
+
// Store frameworks for reference
|
|
452
|
+
target.__security_frameworks = frameworks;
|
|
453
|
+
target.__security_options = options;
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
// ==================== Setup Functions ====================
|
|
457
|
+
/**
|
|
458
|
+
* Apply all security hooks to a model after it's been defined.
|
|
459
|
+
* Call this after Model.init() or prorm.define().
|
|
460
|
+
*
|
|
461
|
+
* @param Model - The model class
|
|
462
|
+
* @param prorm - The Prorm instance (required for audit)
|
|
463
|
+
*/
|
|
464
|
+
function setupSecurity(Model, prorm) {
|
|
465
|
+
// Apply encryption hooks
|
|
466
|
+
const encrypted = Model.__security_encrypted;
|
|
467
|
+
if (encrypted && encrypted.length > 0) {
|
|
468
|
+
(0, field_encryption_1.applyEncryptionHooks)(Model);
|
|
469
|
+
}
|
|
470
|
+
// Apply masking hooks
|
|
471
|
+
const masked = Model.__security_masked;
|
|
472
|
+
if (masked && masked.length > 0) {
|
|
473
|
+
(0, data_masker_1.applyHooks)(Model);
|
|
474
|
+
}
|
|
475
|
+
// Apply retention policy
|
|
476
|
+
const retention = Model.__security_retention;
|
|
477
|
+
if (retention) {
|
|
478
|
+
data_retention_1.DataRetentionPolicy.set(Model, { maxAge: retention });
|
|
479
|
+
}
|
|
480
|
+
// Setup audit if enabled
|
|
481
|
+
const auditEnabled = Model.__security_audit;
|
|
482
|
+
if (auditEnabled && prorm) {
|
|
483
|
+
const getUserId = Model.__security_getUserId;
|
|
484
|
+
const getIpAddress = Model.__security_getIpAddress;
|
|
485
|
+
audit_trail_1.ComplianceAuditTrail.enable(prorm, Model, {
|
|
486
|
+
getUserId,
|
|
487
|
+
getIpAddress,
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
// Apply immutability (deferred from the Security decorator since the model
|
|
491
|
+
// needs to be attached to a Prorm instance before hooks can be registered)
|
|
492
|
+
const immutable = Model.__security_immutable;
|
|
493
|
+
if (immutable) {
|
|
494
|
+
(0, immutable_record_1.makeImmutable)(Model);
|
|
495
|
+
if (Model.__security_versioning) {
|
|
496
|
+
(0, immutable_record_1.enableVersioning)(Model);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Apply security to all models in a Prorm instance.
|
|
502
|
+
*/
|
|
503
|
+
function setupAllSecurity(prorm) {
|
|
504
|
+
const models = prorm.getModels?.() ?? [];
|
|
505
|
+
for (const [, Model] of models) {
|
|
506
|
+
setupSecurity(Model, prorm);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Apply table-level security metadata.
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* @Table({
|
|
514
|
+
* schema: 'financial',
|
|
515
|
+
* classification: 'CONFIDENTIAL',
|
|
516
|
+
* rlsEnabled: true,
|
|
517
|
+
* })
|
|
518
|
+
* class Transaction extends Model { ... }
|
|
519
|
+
*/
|
|
520
|
+
function Table(options = {}) {
|
|
521
|
+
return function (target) {
|
|
522
|
+
target.__table_security = options;
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Apply database-level security metadata.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* @Database({
|
|
530
|
+
* name: 'healthcare_db',
|
|
531
|
+
* region: 'us-east-1',
|
|
532
|
+
* classification: 'CONFIDENTIAL',
|
|
533
|
+
* requireTLS: true,
|
|
534
|
+
* defaultAudit: true,
|
|
535
|
+
* allowedCountries: ['US'],
|
|
536
|
+
* })
|
|
537
|
+
* class HealthcareDB extends Model { ... }
|
|
538
|
+
*/
|
|
539
|
+
function Database(options) {
|
|
540
|
+
return function (target) {
|
|
541
|
+
target.__database_security = options;
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
// ==================== Getters ====================
|
|
545
|
+
/**
|
|
546
|
+
* Get table security options from a model.
|
|
547
|
+
*/
|
|
548
|
+
function getTableSecurity(Model) {
|
|
549
|
+
return Model.__table_security;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Get database security options from a model.
|
|
553
|
+
*/
|
|
554
|
+
function getDatabaseSecurity(Model) {
|
|
555
|
+
return Model.__database_security;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Get the frameworks applied to a model.
|
|
559
|
+
*/
|
|
560
|
+
function getSecurityFrameworks(Model) {
|
|
561
|
+
return Model.__security_frameworks ?? [];
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Check if a model has audit enabled.
|
|
565
|
+
*/
|
|
566
|
+
function hasAudit(Model) {
|
|
567
|
+
return !!Model.__security_audit;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Check if a model is immutable.
|
|
571
|
+
*/
|
|
572
|
+
function isImmutableModel(Model) {
|
|
573
|
+
return !!Model.__security_immutable;
|
|
574
|
+
}
|