@rebasepro/server-postgres 0.13.1-canary.gf57a27e → 0.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.
Files changed (103) hide show
  1. package/dist/PostgresBootstrapper.d.ts +26 -0
  2. package/dist/auth/services.d.ts +21 -0
  3. package/dist/{auth-users-columns-Dt9g712t.js → auth-users-columns-BfQHf9JE.js} +525 -63
  4. package/dist/auth-users-columns-BfQHf9JE.js.map +1 -0
  5. package/dist/{backup-service-Bww-Lg0s.js → backup-service-BH0Dzo_h.js} +2 -3
  6. package/dist/{backup-service-Bww-Lg0s.js.map → backup-service-BH0Dzo_h.js.map} +1 -1
  7. package/dist/cli-output.d.ts +34 -0
  8. package/dist/data-transformer.d.ts +7 -2
  9. package/dist/data_driver-ULAyJEi9.js +193 -0
  10. package/dist/data_driver-ULAyJEi9.js.map +1 -0
  11. package/dist/ensure-collection-policies-8vuu-n4r.js +124 -0
  12. package/dist/ensure-collection-policies-8vuu-n4r.js.map +1 -0
  13. package/dist/{ensure-collection-tables-DRxaUG96.js → ensure-collection-tables-CbvaGuVn.js} +89 -10
  14. package/dist/ensure-collection-tables-CbvaGuVn.js.map +1 -0
  15. package/dist/index.es.js +1310 -1060
  16. package/dist/index.es.js.map +1 -1
  17. package/dist/{rls-bootstrap-sql-Bpv3nUZo.js → rls-bootstrap-sql-69hYT8nr.js} +2 -2
  18. package/dist/{rls-bootstrap-sql-Bpv3nUZo.js.map → rls-bootstrap-sql-69hYT8nr.js.map} +1 -1
  19. package/dist/rls-enforcement-BJ_3wxwg.js +425 -0
  20. package/dist/rls-enforcement-BJ_3wxwg.js.map +1 -0
  21. package/dist/schema/auth-schema.d.ts +102 -0
  22. package/dist/schema/doctor-policy-checks.d.ts +28 -0
  23. package/dist/schema/doctor.d.ts +41 -25
  24. package/dist/schema/ensure-collection-policies.d.ts +33 -9
  25. package/dist/schema/ensure-collection-tables.d.ts +60 -6
  26. package/dist/schema/generate-drizzle-schema-logic.d.ts +9 -1
  27. package/dist/schema/introspect-db-inference.d.ts +8 -1
  28. package/dist/schema/introspect-db-logic.d.ts +49 -0
  29. package/dist/schema/introspect-db-project.d.ts +21 -0
  30. package/dist/schema/search-column.d.ts +49 -0
  31. package/dist/security/policy-drift.d.ts +34 -0
  32. package/dist/security/rls-enforcement.d.ts +8 -3
  33. package/dist/services/FetchService.d.ts +9 -0
  34. package/dist/services/PersistService.d.ts +21 -17
  35. package/dist/services/RelationService.d.ts +9 -57
  36. package/dist/services/RelationWriteService.d.ts +82 -0
  37. package/dist/services/collection-helpers.d.ts +42 -0
  38. package/dist/services/dataService.d.ts +2 -0
  39. package/dist/services/junction-writes.d.ts +82 -0
  40. package/dist/services/realtimeService.d.ts +137 -2
  41. package/dist/services/write-denial.d.ts +36 -0
  42. package/dist/{src-C_wvdMnl.js → src-DCdn3Val.js} +35 -3
  43. package/dist/src-DCdn3Val.js.map +1 -0
  44. package/dist/utils/drizzle-conditions.d.ts +54 -1
  45. package/dist/{websocket-D0TBU3ia.js → websocket-C8ZqVBiV.js} +75 -18
  46. package/dist/websocket-C8ZqVBiV.js.map +1 -0
  47. package/package.json +6 -6
  48. package/src/PostgresBackendDriver.ts +7 -3
  49. package/src/PostgresBootstrapper.ts +95 -9
  50. package/src/auth/ensure-tables.ts +27 -5
  51. package/src/auth/services.ts +82 -5
  52. package/src/backup/backup-cli.ts +59 -57
  53. package/src/cli-errors.ts +6 -6
  54. package/src/cli-helpers.ts +4 -4
  55. package/src/cli-output.ts +43 -0
  56. package/src/cli.ts +155 -147
  57. package/src/collections/buildRegistry.ts +3 -1
  58. package/src/data-transformer.ts +111 -25
  59. package/src/history/ensure-history-table.ts +2 -2
  60. package/src/schema/auth-schema.ts +17 -1
  61. package/src/schema/doctor-cli.ts +14 -65
  62. package/src/schema/doctor-policy-checks.ts +105 -0
  63. package/src/schema/doctor.ts +149 -72
  64. package/src/schema/ensure-collection-policies.ts +99 -6
  65. package/src/schema/ensure-collection-tables.ts +214 -17
  66. package/src/schema/generate-drizzle-schema-logic.ts +121 -65
  67. package/src/schema/generate-drizzle-schema.ts +11 -10
  68. package/src/schema/generate-postgres-ddl-logic.ts +28 -1
  69. package/src/schema/generate-postgres-ddl.ts +14 -13
  70. package/src/schema/generated-schema-staleness.ts +7 -5
  71. package/src/schema/introspect-db-inference.ts +9 -2
  72. package/src/schema/introspect-db-logic.ts +251 -75
  73. package/src/schema/introspect-db-project.ts +78 -0
  74. package/src/schema/introspect-db.ts +42 -25
  75. package/src/schema/introspect-runtime.ts +14 -2
  76. package/src/schema/search-column.ts +85 -0
  77. package/src/security/policy-drift.test.ts +104 -3
  78. package/src/security/policy-drift.ts +129 -7
  79. package/src/security/rls-enforcement.ts +9 -4
  80. package/src/services/FetchService.ts +105 -7
  81. package/src/services/PersistService.ts +68 -42
  82. package/src/services/RelationService.ts +35 -695
  83. package/src/services/RelationWriteService.ts +653 -0
  84. package/src/services/cdc/trigger-cdc.ts +5 -1
  85. package/src/services/channel-history.ts +9 -3
  86. package/src/services/channel-presence.ts +10 -3
  87. package/src/services/collection-helpers.ts +89 -4
  88. package/src/services/dataService.ts +2 -0
  89. package/src/services/junction-writes.ts +295 -0
  90. package/src/services/pg-notify-listener.ts +1 -1
  91. package/src/services/realtimeService.ts +337 -82
  92. package/src/services/write-denial.ts +55 -0
  93. package/src/utils/drizzle-conditions.ts +211 -34
  94. package/src/utils/pg-error-utils.ts +8 -3
  95. package/src/websocket.ts +113 -16
  96. package/dist/auth-users-columns-Dt9g712t.js.map +0 -1
  97. package/dist/ensure-collection-policies-CwYUliAa.js +0 -57
  98. package/dist/ensure-collection-policies-CwYUliAa.js.map +0 -1
  99. package/dist/ensure-collection-tables-DRxaUG96.js.map +0 -1
  100. package/dist/policy-CPkCqVTz.js +0 -105
  101. package/dist/policy-CPkCqVTz.js.map +0 -1
  102. package/dist/src-C_wvdMnl.js.map +0 -1
  103. package/dist/websocket-D0TBU3ia.js.map +0 -1
@@ -89,6 +89,32 @@ export interface PostgresDriverInternals {
89
89
  * and this is the part that was wrong.
90
90
  */
91
91
  export declare function resolveDriftCheckName(col: CollectionConfig, registeredTableNames: string[]): string;
92
+ /**
93
+ * Is this the local database `rebase init` scaffolds — i.e. the one case where
94
+ * "you are connected as a superuser" is not news?
95
+ *
96
+ * The scaffold's own `docker-compose.yml` sets `POSTGRES_USER: rebase_app`,
97
+ * which makes that role the cluster superuser, so the superuser advisory below
98
+ * was the only WARN a brand-new project ever saw and it was about a decision
99
+ * the tool had made for the developer.
100
+ *
101
+ * Of the two available fixes — provision a non-superuser table-owner role in
102
+ * the scaffold, or recognise the local shape and stay quiet — this is the
103
+ * second, because the first breaks the scaffold it is meant to improve: a
104
+ * non-superuser owner cannot `CREATE EXTENSION` (search collections need
105
+ * `pg_trgm`/`unaccent`, applied by `rebase db push` and again by the boot
106
+ * schema-ensure), so the very first `pnpm run db:push` on a scaffolded project
107
+ * with a search block would fail. Trading a working first run for a quieter log
108
+ * line is the wrong trade.
109
+ *
110
+ * The condition is deliberately narrow — a *non-production* process talking to
111
+ * a database on the loopback interface. A genuine production superuser
112
+ * connection still warns, and so does a non-production process pointed at a
113
+ * remote database (the usual "my dev machine writes to staging" mistake, where
114
+ * the advisory is exactly right). NODE_ENV alone would not do: the scaffold
115
+ * ships `NODE_ENV=development` and some deployments inherit it.
116
+ */
117
+ export declare function isScaffoldedLocalDatabase(connectionString: string | undefined): boolean;
92
118
  /**
93
119
  * Default PostgreSQL bootstrapper.
94
120
  *
@@ -287,6 +287,7 @@ export declare class PostgresAuthRepository implements AuthRepository {
287
287
  secretEncrypted: string;
288
288
  }) | null>;
289
289
  verifyMfaFactor(factorId: string): Promise<void>;
290
+ updateMfaFactorSecret(factorId: string, secretEncrypted: string): Promise<void>;
290
291
  deleteMfaFactor(factorId: string, uid: string): Promise<void>;
291
292
  createMfaChallenge(factorId: string, ipAddress?: string): Promise<MfaChallengeInfo>;
292
293
  getMfaChallengeById(challengeId: string): Promise<MfaChallengeInfo | null>;
@@ -296,6 +297,8 @@ export declare class PostgresAuthRepository implements AuthRepository {
296
297
  getUnusedRecoveryCodeCount(uid: string): Promise<number>;
297
298
  deleteAllRecoveryCodes(uid: string): Promise<void>;
298
299
  hasVerifiedMfaFactors(uid: string): Promise<boolean>;
300
+ claimMfaFactorCounter(factorId: string, counter: number): Promise<boolean>;
301
+ recordMfaChallengeAttempt(challengeId: string): Promise<number>;
299
302
  }
300
303
  /**
301
304
  * PostgreSQL implementation of MfaRepository.
@@ -311,10 +314,28 @@ export declare class MfaService implements MfaRepository {
311
314
  getMfaFactorById(factorId: string): Promise<(MfaFactor & {
312
315
  secretEncrypted: string;
313
316
  }) | null>;
317
+ /**
318
+ * Spend a TOTP time step, once and only once.
319
+ *
320
+ * One statement: the `WHERE` is the check, the `UPDATE` is the act, and
321
+ * `RETURNING` reports which of two concurrent requests carrying the same
322
+ * six digits won. Reading the counter and then writing it would let both
323
+ * pass — the exact replay this closes.
324
+ */
325
+ claimMfaFactorCounter(factorId: string, counter: number): Promise<boolean>;
314
326
  verifyMfaFactor(factorId: string): Promise<void>;
327
+ updateMfaFactorSecret(factorId: string, secretEncrypted: string): Promise<void>;
315
328
  deleteMfaFactor(factorId: string, uid: string): Promise<void>;
316
329
  createMfaChallenge(factorId: string, ipAddress?: string): Promise<MfaChallengeInfo>;
317
330
  getMfaChallengeById(challengeId: string): Promise<MfaChallengeInfo | null>;
331
+ /**
332
+ * Count one failed guess against a challenge and report the new total.
333
+ *
334
+ * Incremented in the database rather than in the route so that guesses
335
+ * arriving in parallel — the shape any real brute-force takes — cannot
336
+ * share a single increment.
337
+ */
338
+ recordMfaChallengeAttempt(challengeId: string): Promise<number>;
318
339
  verifyMfaChallenge(challengeId: string): Promise<void>;
319
340
  createRecoveryCodes(uid: string, codeHashes: string[]): Promise<void>;
320
341
  useRecoveryCode(uid: string, codeHash: string): Promise<boolean>;