@valentine-efagene/qshelter-common 2.0.60 → 2.0.61

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.
@@ -1,42 +1,47 @@
1
1
  /**
2
- * Models that require tenant scoping.
2
+ * INVERTED APPROACH: All models are tenant-scoped by default.
3
+ * Only list models that are explicitly GLOBAL (no tenant scoping).
3
4
  *
4
- * IMPORTANT: When adding a new model with tenantId to the schema,
5
- * add it to this list so queries are automatically filtered by tenant.
6
- *
7
- * Models with nullable tenantId (for global templates) should also be
8
- * added to OPTIONAL_TENANT_MODELS below.
5
+ * This reduces the risk of accidentally omitting a new model from tenant scoping.
6
+ */
7
+ /**
8
+ * Models that are intentionally GLOBAL and should NOT be tenant-scoped.
9
+ * These models either:
10
+ * - Don't have a tenantId field (system tables)
11
+ * - Have optional tenantId but are designed to work across tenants (User)
9
12
  */
10
- const TENANT_SCOPED_MODELS = [
11
- // Property domain
12
- "property",
13
- "propertyPaymentMethod",
14
- // Payment plan domain
15
- "paymentPlan",
16
- // Contract domain
17
- "contract",
18
- "contractTermination",
19
- // Document domain
20
- "documentTemplate",
21
- "offerLetter",
22
- "documentRequirementRule",
23
- // Prequalification & underwriting domain
24
- "prequalification",
25
- "underwritingDecision",
26
- // Payment method changes
27
- "paymentMethodChangeRequest",
13
+ const GLOBAL_MODELS = [
14
+ // User can exist across tenants or without a tenant
15
+ "user",
16
+ // System/infrastructure tables without tenantId
17
+ "tenant",
18
+ "role",
19
+ "permission",
20
+ "rolePermission",
21
+ "userRole",
22
+ "refreshToken",
23
+ "passwordReset",
24
+ "wallet",
25
+ "domainEvent",
28
26
  ];
29
27
  /**
30
- * Models that can optionally have tenant scoping (nullable tenantId)
31
- * PaymentPlan has nullable tenantId for global templates
28
+ * Models that have OPTIONAL tenant scoping (nullable tenantId).
29
+ * These can be global templates (tenantId = null) or tenant-specific.
30
+ * Queries will return both global AND tenant-specific records.
32
31
  */
33
32
  const OPTIONAL_TENANT_MODELS = ["paymentPlan"];
34
- function isTenantScopedModel(model) {
35
- return TENANT_SCOPED_MODELS.includes(model);
33
+ function isGlobalModel(model) {
34
+ return GLOBAL_MODELS.includes(model);
36
35
  }
37
36
  function isOptionalTenantModel(model) {
38
37
  return OPTIONAL_TENANT_MODELS.includes(model);
39
38
  }
39
+ /**
40
+ * A model is tenant-scoped by default unless explicitly listed as global.
41
+ */
42
+ function isTenantScopedModel(model) {
43
+ return !isGlobalModel(model);
44
+ }
40
45
  /**
41
46
  * Creates a tenant-scoped Prisma client that automatically:
42
47
  * 1. Filters all queries on tenant-scoped models by tenantId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valentine-efagene/qshelter-common",
3
- "version": "2.0.60",
3
+ "version": "2.0.61",
4
4
  "description": "Shared database schemas and utilities for QShelter services",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",