@rebasepro/server-postgres 0.13.1-canary.gf57a27e → 0.14.1-canary.g7e666eb

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 (104) hide show
  1. package/dist/PostgresBackendDriver.d.ts +1 -1
  2. package/dist/PostgresBootstrapper.d.ts +26 -0
  3. package/dist/auth/services.d.ts +31 -0
  4. package/dist/{auth-users-columns-Dt9g712t.js → auth-users-columns-C-FDnL_e.js} +768 -76
  5. package/dist/auth-users-columns-C-FDnL_e.js.map +1 -0
  6. package/dist/{backup-service-Bww-Lg0s.js → backup-service-BH0Dzo_h.js} +2 -3
  7. package/dist/{backup-service-Bww-Lg0s.js.map → backup-service-BH0Dzo_h.js.map} +1 -1
  8. package/dist/cli-output.d.ts +34 -0
  9. package/dist/data-transformer.d.ts +7 -2
  10. package/dist/data_driver-ULAyJEi9.js +193 -0
  11. package/dist/data_driver-ULAyJEi9.js.map +1 -0
  12. package/dist/ensure-collection-policies-BedO2aNX.js +124 -0
  13. package/dist/ensure-collection-policies-BedO2aNX.js.map +1 -0
  14. package/dist/{ensure-collection-tables-DRxaUG96.js → ensure-collection-tables-B1qKdXA4.js} +89 -10
  15. package/dist/ensure-collection-tables-B1qKdXA4.js.map +1 -0
  16. package/dist/index.es.js +1615 -1210
  17. package/dist/index.es.js.map +1 -1
  18. package/dist/{rls-bootstrap-sql-Bpv3nUZo.js → rls-bootstrap-sql-69hYT8nr.js} +2 -2
  19. package/dist/{rls-bootstrap-sql-Bpv3nUZo.js.map → rls-bootstrap-sql-69hYT8nr.js.map} +1 -1
  20. package/dist/rls-enforcement-gUNDfm7l.js +425 -0
  21. package/dist/rls-enforcement-gUNDfm7l.js.map +1 -0
  22. package/dist/schema/auth-schema.d.ts +102 -0
  23. package/dist/schema/doctor-policy-checks.d.ts +28 -0
  24. package/dist/schema/doctor.d.ts +41 -25
  25. package/dist/schema/ensure-collection-policies.d.ts +33 -9
  26. package/dist/schema/ensure-collection-tables.d.ts +60 -6
  27. package/dist/schema/generate-drizzle-schema-logic.d.ts +9 -1
  28. package/dist/schema/introspect-db-inference.d.ts +8 -1
  29. package/dist/schema/introspect-db-logic.d.ts +49 -0
  30. package/dist/schema/introspect-db-project.d.ts +21 -0
  31. package/dist/schema/search-column.d.ts +49 -0
  32. package/dist/security/policy-drift.d.ts +34 -0
  33. package/dist/security/rls-enforcement.d.ts +8 -3
  34. package/dist/services/FetchService.d.ts +63 -5
  35. package/dist/services/PersistService.d.ts +21 -17
  36. package/dist/services/RelationService.d.ts +11 -59
  37. package/dist/services/RelationWriteService.d.ts +82 -0
  38. package/dist/services/collection-helpers.d.ts +42 -0
  39. package/dist/services/dataService.d.ts +8 -4
  40. package/dist/services/junction-writes.d.ts +82 -0
  41. package/dist/services/realtimeService.d.ts +191 -12
  42. package/dist/services/write-denial.d.ts +36 -0
  43. package/dist/{src-C_wvdMnl.js → src-DCdn3Val.js} +35 -3
  44. package/dist/src-DCdn3Val.js.map +1 -0
  45. package/dist/utils/drizzle-conditions.d.ts +54 -1
  46. package/dist/{websocket-D0TBU3ia.js → websocket-D2jXv0Ds.js} +103 -19
  47. package/dist/websocket-D2jXv0Ds.js.map +1 -0
  48. package/package.json +6 -6
  49. package/src/PostgresBackendDriver.ts +14 -6
  50. package/src/PostgresBootstrapper.ts +95 -9
  51. package/src/auth/ensure-tables.ts +27 -5
  52. package/src/auth/services.ts +108 -10
  53. package/src/backup/backup-cli.ts +59 -57
  54. package/src/cli-errors.ts +6 -6
  55. package/src/cli-helpers.ts +4 -4
  56. package/src/cli-output.ts +43 -0
  57. package/src/cli.ts +155 -147
  58. package/src/collections/buildRegistry.ts +3 -1
  59. package/src/data-transformer.ts +111 -25
  60. package/src/history/ensure-history-table.ts +2 -2
  61. package/src/schema/auth-schema.ts +17 -1
  62. package/src/schema/doctor-cli.ts +14 -65
  63. package/src/schema/doctor-policy-checks.ts +105 -0
  64. package/src/schema/doctor.ts +149 -72
  65. package/src/schema/ensure-collection-policies.ts +99 -6
  66. package/src/schema/ensure-collection-tables.ts +214 -17
  67. package/src/schema/generate-drizzle-schema-logic.ts +140 -66
  68. package/src/schema/generate-drizzle-schema.ts +11 -10
  69. package/src/schema/generate-postgres-ddl-logic.ts +28 -1
  70. package/src/schema/generate-postgres-ddl.ts +14 -13
  71. package/src/schema/generated-schema-staleness.ts +7 -5
  72. package/src/schema/introspect-db-inference.ts +9 -2
  73. package/src/schema/introspect-db-logic.ts +251 -75
  74. package/src/schema/introspect-db-project.ts +78 -0
  75. package/src/schema/introspect-db.ts +42 -25
  76. package/src/schema/introspect-runtime.ts +14 -2
  77. package/src/schema/search-column.ts +85 -0
  78. package/src/security/policy-drift.test.ts +104 -3
  79. package/src/security/policy-drift.ts +129 -7
  80. package/src/security/rls-enforcement.ts +9 -4
  81. package/src/services/FetchService.ts +289 -69
  82. package/src/services/PersistService.ts +68 -42
  83. package/src/services/RelationService.ts +38 -698
  84. package/src/services/RelationWriteService.ts +653 -0
  85. package/src/services/cdc/trigger-cdc.ts +5 -1
  86. package/src/services/channel-history.ts +9 -3
  87. package/src/services/channel-presence.ts +10 -3
  88. package/src/services/collection-helpers.ts +89 -4
  89. package/src/services/dataService.ts +8 -4
  90. package/src/services/junction-writes.ts +295 -0
  91. package/src/services/pg-notify-listener.ts +15 -1
  92. package/src/services/realtimeService.ts +496 -121
  93. package/src/services/write-denial.ts +55 -0
  94. package/src/utils/drizzle-conditions.ts +211 -34
  95. package/src/utils/pg-error-utils.ts +8 -3
  96. package/src/websocket.ts +157 -17
  97. package/dist/auth-users-columns-Dt9g712t.js.map +0 -1
  98. package/dist/ensure-collection-policies-CwYUliAa.js +0 -57
  99. package/dist/ensure-collection-policies-CwYUliAa.js.map +0 -1
  100. package/dist/ensure-collection-tables-DRxaUG96.js.map +0 -1
  101. package/dist/policy-CPkCqVTz.js +0 -105
  102. package/dist/policy-CPkCqVTz.js.map +0 -1
  103. package/dist/src-C_wvdMnl.js.map +0 -1
  104. package/dist/websocket-D0TBU3ia.js.map +0 -1
@@ -152,7 +152,7 @@ export declare class PostgresBackendDriver implements DataDriver {
152
152
  delete<M extends Record<string, unknown>>({ row, collection }: DeleteProps<M>): Promise<void>;
153
153
  deleteAll(path: string): Promise<void>;
154
154
  checkUniqueField(path: string, name: string, value: unknown, id?: string, collection?: CollectionConfig): Promise<boolean>;
155
- count<M extends Record<string, unknown>>({ path, collection, filter, logical, searchString }: FetchCollectionProps<M>): Promise<number>;
155
+ count<M extends Record<string, unknown>>({ path, collection, filter, logical, searchString, vectorSearch }: FetchCollectionProps<M>): Promise<number>;
156
156
  private getTargetDb;
157
157
  executeSql(sqlText: string, options?: {
158
158
  database?: string;
@@ -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
  *
@@ -58,6 +58,16 @@ export declare class UserService implements UserRepository {
58
58
  private withServerContext;
59
59
  private mapRowToUser;
60
60
  private mapPayload;
61
+ /**
62
+ * @see UserRepository.createUser — an email already in use is a 409.
63
+ *
64
+ * The route checks first and answers 409; this is the same answer for the
65
+ * requests that get past the check, which two clicks on a signup button
66
+ * are enough to produce. `PersistService` has mapped `23505` to a conflict
67
+ * for collection writes since the layer that holds the SQLSTATE was made
68
+ * responsible for saying whose fault a failure is; the auth writes never
69
+ * got the same treatment and reached the client as "Internal Server Error".
70
+ */
61
71
  createUser(data: CreateUserData): Promise<UserData>;
62
72
  getUserById(id: string): Promise<UserData | null>;
63
73
  getUserByEmail(email: string): Promise<UserData | null>;
@@ -287,6 +297,7 @@ export declare class PostgresAuthRepository implements AuthRepository {
287
297
  secretEncrypted: string;
288
298
  }) | null>;
289
299
  verifyMfaFactor(factorId: string): Promise<void>;
300
+ updateMfaFactorSecret(factorId: string, secretEncrypted: string): Promise<void>;
290
301
  deleteMfaFactor(factorId: string, uid: string): Promise<void>;
291
302
  createMfaChallenge(factorId: string, ipAddress?: string): Promise<MfaChallengeInfo>;
292
303
  getMfaChallengeById(challengeId: string): Promise<MfaChallengeInfo | null>;
@@ -296,6 +307,8 @@ export declare class PostgresAuthRepository implements AuthRepository {
296
307
  getUnusedRecoveryCodeCount(uid: string): Promise<number>;
297
308
  deleteAllRecoveryCodes(uid: string): Promise<void>;
298
309
  hasVerifiedMfaFactors(uid: string): Promise<boolean>;
310
+ claimMfaFactorCounter(factorId: string, counter: number): Promise<boolean>;
311
+ recordMfaChallengeAttempt(challengeId: string): Promise<number>;
299
312
  }
300
313
  /**
301
314
  * PostgreSQL implementation of MfaRepository.
@@ -311,10 +324,28 @@ export declare class MfaService implements MfaRepository {
311
324
  getMfaFactorById(factorId: string): Promise<(MfaFactor & {
312
325
  secretEncrypted: string;
313
326
  }) | null>;
327
+ /**
328
+ * Spend a TOTP time step, once and only once.
329
+ *
330
+ * One statement: the `WHERE` is the check, the `UPDATE` is the act, and
331
+ * `RETURNING` reports which of two concurrent requests carrying the same
332
+ * six digits won. Reading the counter and then writing it would let both
333
+ * pass — the exact replay this closes.
334
+ */
335
+ claimMfaFactorCounter(factorId: string, counter: number): Promise<boolean>;
314
336
  verifyMfaFactor(factorId: string): Promise<void>;
337
+ updateMfaFactorSecret(factorId: string, secretEncrypted: string): Promise<void>;
315
338
  deleteMfaFactor(factorId: string, uid: string): Promise<void>;
316
339
  createMfaChallenge(factorId: string, ipAddress?: string): Promise<MfaChallengeInfo>;
317
340
  getMfaChallengeById(challengeId: string): Promise<MfaChallengeInfo | null>;
341
+ /**
342
+ * Count one failed guess against a challenge and report the new total.
343
+ *
344
+ * Incremented in the database rather than in the route so that guesses
345
+ * arriving in parallel — the shape any real brute-force takes — cannot
346
+ * share a single increment.
347
+ */
348
+ recordMfaChallengeAttempt(challengeId: string): Promise<number>;
318
349
  verifyMfaChallenge(challengeId: string): Promise<void>;
319
350
  createRecoveryCodes(uid: string, codeHashes: string[]): Promise<void>;
320
351
  useRecoveryCode(uid: string, codeHash: string): Promise<boolean>;