@breeztech/breez-sdk-spark 0.13.9-debug → 0.13.11-dev1
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/breez-sdk-spark.tgz +0 -0
- package/bundler/breez_sdk_spark_wasm.d.ts +1113 -1050
- package/bundler/breez_sdk_spark_wasm.js +5 -1
- package/bundler/breez_sdk_spark_wasm_bg.js +1493 -1628
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +14 -6
- package/deno/breez_sdk_spark_wasm.d.ts +1113 -1050
- package/deno/breez_sdk_spark_wasm.js +1394 -1284
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +14 -6
- package/nodejs/breez_sdk_spark_wasm.d.ts +1113 -1050
- package/nodejs/breez_sdk_spark_wasm.js +2527 -2654
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +14 -6
- package/nodejs/index.js +34 -0
- package/nodejs/index.mjs +5 -4
- package/nodejs/mysql-storage/errors.cjs +19 -0
- package/nodejs/mysql-storage/index.cjs +1366 -0
- package/nodejs/mysql-storage/migrations.cjs +387 -0
- package/nodejs/mysql-storage/package.json +9 -0
- package/nodejs/mysql-token-store/errors.cjs +9 -0
- package/nodejs/mysql-token-store/index.cjs +988 -0
- package/nodejs/mysql-token-store/migrations.cjs +255 -0
- package/nodejs/mysql-token-store/package.json +9 -0
- package/nodejs/mysql-tree-store/errors.cjs +9 -0
- package/nodejs/mysql-tree-store/index.cjs +939 -0
- package/nodejs/mysql-tree-store/migrations.cjs +221 -0
- package/nodejs/mysql-tree-store/package.json +9 -0
- package/nodejs/package.json +3 -0
- package/nodejs/postgres-storage/index.cjs +147 -92
- package/nodejs/postgres-storage/migrations.cjs +85 -4
- package/nodejs/postgres-token-store/index.cjs +186 -101
- package/nodejs/postgres-token-store/migrations.cjs +92 -3
- package/nodejs/postgres-tree-store/index.cjs +177 -93
- package/nodejs/postgres-tree-store/migrations.cjs +80 -3
- package/package.json +1 -1
- package/ssr/index.js +19 -14
- package/web/breez_sdk_spark_wasm.d.ts +1267 -1195
- package/web/breez_sdk_spark_wasm.js +2295 -2169
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +14 -6
|
@@ -20,9 +20,14 @@ class PostgresMigrationManager {
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Run all pending migrations inside a single transaction with an advisory lock.
|
|
23
|
+
*
|
|
23
24
|
* @param {import('pg').Pool} pool
|
|
25
|
+
* @param {Buffer|Uint8Array} identity - 33-byte secp256k1 compressed pubkey
|
|
26
|
+
* identifying the tenant. Used to backfill `user_id` columns in the
|
|
27
|
+
* multi-tenant migration so that pre-existing single-tenant data remains
|
|
28
|
+
* readable.
|
|
24
29
|
*/
|
|
25
|
-
async migrate(pool) {
|
|
30
|
+
async migrate(pool, identity) {
|
|
26
31
|
const client = await pool.connect();
|
|
27
32
|
try {
|
|
28
33
|
await client.query("BEGIN");
|
|
@@ -44,7 +49,7 @@ class PostgresMigrationManager {
|
|
|
44
49
|
);
|
|
45
50
|
const currentVersion = versionResult.rows[0].version;
|
|
46
51
|
|
|
47
|
-
const migrations = this._getMigrations();
|
|
52
|
+
const migrations = this._getMigrations(identity);
|
|
48
53
|
|
|
49
54
|
if (currentVersion >= migrations.length) {
|
|
50
55
|
this._log("info", `Database is up to date (version ${currentVersion})`);
|
|
@@ -97,8 +102,27 @@ class PostgresMigrationManager {
|
|
|
97
102
|
* Single migration creating all tables at their final schema.
|
|
98
103
|
* This mirrors the Rust-native PostgresStorage schema but uses camelCase
|
|
99
104
|
* enum values (as produced by the WASM bridge).
|
|
105
|
+
*
|
|
106
|
+
* @param {Buffer|Uint8Array} identity - 33-byte tenant identity. Inlined as
|
|
107
|
+
* a hex BYTEA literal in the multi-tenant scoping migration. Safe because
|
|
108
|
+
* the bytes come from a typed secp256k1 pubkey (character set
|
|
109
|
+
* `[0-9a-f]{66}` after hex encoding) — not user-controlled input.
|
|
100
110
|
*/
|
|
101
|
-
_getMigrations() {
|
|
111
|
+
_getMigrations(identity) {
|
|
112
|
+
const idHex = Buffer.from(identity).toString("hex");
|
|
113
|
+
const idLit = `'\\x${idHex}'::bytea`;
|
|
114
|
+
|
|
115
|
+
// Helper for the per-table backfill: ADD COLUMN nullable -> UPDATE -> SET
|
|
116
|
+
// NOT NULL + drop/recreate PK. Returns an array of statements.
|
|
117
|
+
const scopeTable = (table, pkCols) => [
|
|
118
|
+
`ALTER TABLE ${table} ADD COLUMN user_id BYTEA`,
|
|
119
|
+
`UPDATE ${table} SET user_id = ${idLit}`,
|
|
120
|
+
`ALTER TABLE ${table}
|
|
121
|
+
ALTER COLUMN user_id SET NOT NULL,
|
|
122
|
+
DROP CONSTRAINT IF EXISTS ${table}_pkey,
|
|
123
|
+
ADD PRIMARY KEY (user_id, ${pkCols})`,
|
|
124
|
+
];
|
|
125
|
+
|
|
102
126
|
return [
|
|
103
127
|
{
|
|
104
128
|
name: "Create all tables at final schema",
|
|
@@ -252,12 +276,69 @@ class PostgresMigrationManager {
|
|
|
252
276
|
`ALTER TABLE unclaimed_deposits ADD COLUMN is_mature BOOLEAN NOT NULL DEFAULT TRUE`,
|
|
253
277
|
],
|
|
254
278
|
},
|
|
255
|
-
{
|
|
279
|
+
{
|
|
256
280
|
name: "Add conversion_status to payment_metadata",
|
|
257
281
|
sql: [
|
|
258
282
|
`ALTER TABLE payment_metadata ADD COLUMN IF NOT EXISTS conversion_status TEXT`,
|
|
259
283
|
],
|
|
260
284
|
},
|
|
285
|
+
{
|
|
286
|
+
name: "Multi-tenant scoping: add user_id and rewrite primary keys",
|
|
287
|
+
sql: [
|
|
288
|
+
// Per-user tables
|
|
289
|
+
...scopeTable("payments", "id"),
|
|
290
|
+
`DROP INDEX IF EXISTS idx_payments_timestamp`,
|
|
291
|
+
`DROP INDEX IF EXISTS idx_payments_payment_type`,
|
|
292
|
+
`DROP INDEX IF EXISTS idx_payments_status`,
|
|
293
|
+
`CREATE INDEX idx_payments_user_timestamp ON payments(user_id, timestamp)`,
|
|
294
|
+
`CREATE INDEX idx_payments_user_payment_type ON payments(user_id, payment_type)`,
|
|
295
|
+
`CREATE INDEX idx_payments_user_status ON payments(user_id, status)`,
|
|
296
|
+
|
|
297
|
+
...scopeTable("payment_metadata", "payment_id"),
|
|
298
|
+
`DROP INDEX IF EXISTS idx_payment_metadata_parent`,
|
|
299
|
+
`CREATE INDEX idx_payment_metadata_user_parent
|
|
300
|
+
ON payment_metadata(user_id, parent_payment_id)`,
|
|
301
|
+
|
|
302
|
+
...scopeTable("payment_details_lightning", "payment_id"),
|
|
303
|
+
`DROP INDEX IF EXISTS idx_payment_details_lightning_invoice`,
|
|
304
|
+
`DROP INDEX IF EXISTS idx_payment_details_lightning_payment_hash`,
|
|
305
|
+
`CREATE INDEX idx_payment_details_lightning_user_invoice
|
|
306
|
+
ON payment_details_lightning(user_id, invoice)`,
|
|
307
|
+
`CREATE INDEX idx_payment_details_lightning_user_payment_hash
|
|
308
|
+
ON payment_details_lightning(user_id, payment_hash)`,
|
|
309
|
+
|
|
310
|
+
...scopeTable("payment_details_token", "payment_id"),
|
|
311
|
+
...scopeTable("payment_details_spark", "payment_id"),
|
|
312
|
+
...scopeTable("lnurl_receive_metadata", "payment_hash"),
|
|
313
|
+
...scopeTable("unclaimed_deposits", "txid, vout"),
|
|
314
|
+
...scopeTable("contacts", "id"),
|
|
315
|
+
...scopeTable("settings", "key"),
|
|
316
|
+
|
|
317
|
+
// sync_revision: drop the singleton id (CASCADE removes PK + CHECK),
|
|
318
|
+
// then re-key by user_id so each tenant has its own revision row.
|
|
319
|
+
`ALTER TABLE sync_revision DROP COLUMN id CASCADE`,
|
|
320
|
+
`ALTER TABLE sync_revision ADD COLUMN user_id BYTEA`,
|
|
321
|
+
`UPDATE sync_revision SET user_id = ${idLit}`,
|
|
322
|
+
`ALTER TABLE sync_revision
|
|
323
|
+
ALTER COLUMN user_id SET NOT NULL,
|
|
324
|
+
ADD PRIMARY KEY (user_id)`,
|
|
325
|
+
|
|
326
|
+
// sync_outgoing has no PK, only an index — just add user_id and rewrite the index.
|
|
327
|
+
`ALTER TABLE sync_outgoing ADD COLUMN user_id BYTEA`,
|
|
328
|
+
`UPDATE sync_outgoing SET user_id = ${idLit}`,
|
|
329
|
+
`ALTER TABLE sync_outgoing ALTER COLUMN user_id SET NOT NULL`,
|
|
330
|
+
`DROP INDEX IF EXISTS idx_sync_outgoing_data_id_record_type`,
|
|
331
|
+
`CREATE INDEX idx_sync_outgoing_user_record_type_data_id
|
|
332
|
+
ON sync_outgoing(user_id, record_type, data_id)`,
|
|
333
|
+
|
|
334
|
+
...scopeTable("sync_state", "record_type, data_id"),
|
|
335
|
+
|
|
336
|
+
...scopeTable("sync_incoming", "record_type, data_id, revision"),
|
|
337
|
+
`DROP INDEX IF EXISTS idx_sync_incoming_revision`,
|
|
338
|
+
`CREATE INDEX idx_sync_incoming_user_revision
|
|
339
|
+
ON sync_incoming(user_id, revision)`,
|
|
340
|
+
],
|
|
341
|
+
},
|
|
261
342
|
];
|
|
262
343
|
}
|
|
263
344
|
}
|