@breeztech/breez-sdk-spark 0.12.2 → 0.12.3
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/README.md +68 -69
- package/breez-sdk-spark.tgz +0 -0
- package/bundler/breez_sdk_spark_wasm.d.ts +734 -602
- package/bundler/breez_sdk_spark_wasm_bg.js +175 -78
- package/bundler/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/bundler/breez_sdk_spark_wasm_bg.wasm.d.ts +8 -6
- package/bundler/storage/index.js +65 -43
- package/deno/breez_sdk_spark_wasm.d.ts +734 -602
- package/deno/breez_sdk_spark_wasm.js +165 -78
- package/deno/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/deno/breez_sdk_spark_wasm_bg.wasm.d.ts +8 -6
- package/nodejs/breez_sdk_spark_wasm.d.ts +734 -602
- package/nodejs/breez_sdk_spark_wasm.js +175 -78
- package/nodejs/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/nodejs/breez_sdk_spark_wasm_bg.wasm.d.ts +8 -6
- package/nodejs/index.js +16 -2
- package/nodejs/index.mjs +25 -0
- package/nodejs/package.json +3 -1
- package/nodejs/postgres-storage/index.cjs +42 -31
- package/nodejs/postgres-storage/migrations.cjs +24 -0
- package/nodejs/postgres-token-store/errors.cjs +13 -0
- package/nodejs/postgres-token-store/index.cjs +857 -0
- package/nodejs/postgres-token-store/migrations.cjs +163 -0
- package/nodejs/postgres-token-store/package.json +9 -0
- package/nodejs/postgres-tree-store/index.cjs +12 -2
- package/nodejs/storage/index.cjs +19 -28
- package/nodejs/storage/migrations.cjs +18 -0
- package/package.json +7 -2
- package/ssr/index.d.ts +2 -0
- package/ssr/index.js +126 -0
- package/web/breez_sdk_spark_wasm.d.ts +742 -608
- package/web/breez_sdk_spark_wasm.js +165 -78
- package/web/breez_sdk_spark_wasm_bg.wasm +0 -0
- package/web/breez_sdk_spark_wasm_bg.wasm.d.ts +8 -6
- package/web/storage/index.js +65 -43
|
@@ -50,6 +50,7 @@ const SELECT_PAYMENT_SQL = `
|
|
|
50
50
|
pm.lnurl_pay_info,
|
|
51
51
|
pm.lnurl_withdraw_info,
|
|
52
52
|
pm.conversion_info,
|
|
53
|
+
pm.conversion_status,
|
|
53
54
|
t.metadata AS token_metadata,
|
|
54
55
|
t.tx_hash AS token_tx_hash,
|
|
55
56
|
t.tx_type AS token_tx_type,
|
|
@@ -281,20 +282,6 @@ class PostgresStorage {
|
|
|
281
282
|
params.push(paymentDetailsFilter.txType);
|
|
282
283
|
}
|
|
283
284
|
|
|
284
|
-
// Filter by LNURL preimage status
|
|
285
|
-
if (
|
|
286
|
-
paymentDetailsFilter.type === "lightning" &&
|
|
287
|
-
paymentDetailsFilter.hasLnurlPreimage !== undefined
|
|
288
|
-
) {
|
|
289
|
-
if (paymentDetailsFilter.hasLnurlPreimage) {
|
|
290
|
-
paymentDetailsClauses.push("lrm.preimage IS NOT NULL");
|
|
291
|
-
} else {
|
|
292
|
-
paymentDetailsClauses.push(
|
|
293
|
-
"lrm.payment_hash IS NOT NULL AND l.preimage IS NOT NULL AND lrm.preimage IS NULL"
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
285
|
if (paymentDetailsClauses.length > 0) {
|
|
299
286
|
allPaymentDetailsClauses.push(
|
|
300
287
|
`(${paymentDetailsClauses.join(" AND ")})`
|
|
@@ -564,14 +551,15 @@ class PostgresStorage {
|
|
|
564
551
|
async insertPaymentMetadata(paymentId, metadata) {
|
|
565
552
|
try {
|
|
566
553
|
await this.pool.query(
|
|
567
|
-
`INSERT INTO payment_metadata (payment_id, parent_payment_id, lnurl_pay_info, lnurl_withdraw_info, lnurl_description, conversion_info)
|
|
568
|
-
VALUES ($1, $2, $3, $4, $5, $6)
|
|
554
|
+
`INSERT INTO payment_metadata (payment_id, parent_payment_id, lnurl_pay_info, lnurl_withdraw_info, lnurl_description, conversion_info, conversion_status)
|
|
555
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
569
556
|
ON CONFLICT(payment_id) DO UPDATE SET
|
|
570
557
|
parent_payment_id = COALESCE(EXCLUDED.parent_payment_id, payment_metadata.parent_payment_id),
|
|
571
558
|
lnurl_pay_info = COALESCE(EXCLUDED.lnurl_pay_info, payment_metadata.lnurl_pay_info),
|
|
572
559
|
lnurl_withdraw_info = COALESCE(EXCLUDED.lnurl_withdraw_info, payment_metadata.lnurl_withdraw_info),
|
|
573
560
|
lnurl_description = COALESCE(EXCLUDED.lnurl_description, payment_metadata.lnurl_description),
|
|
574
|
-
conversion_info = COALESCE(EXCLUDED.conversion_info, payment_metadata.conversion_info)
|
|
561
|
+
conversion_info = COALESCE(EXCLUDED.conversion_info, payment_metadata.conversion_info),
|
|
562
|
+
conversion_status = COALESCE(EXCLUDED.conversion_status, payment_metadata.conversion_status)`,
|
|
575
563
|
[
|
|
576
564
|
paymentId,
|
|
577
565
|
metadata.parentPaymentId,
|
|
@@ -585,6 +573,7 @@ class PostgresStorage {
|
|
|
585
573
|
metadata.conversionInfo
|
|
586
574
|
? JSON.stringify(metadata.conversionInfo)
|
|
587
575
|
: null,
|
|
576
|
+
metadata.conversionStatus ?? null,
|
|
588
577
|
]
|
|
589
578
|
);
|
|
590
579
|
} catch (error) {
|
|
@@ -597,13 +586,13 @@ class PostgresStorage {
|
|
|
597
586
|
|
|
598
587
|
// ===== Deposit Operations =====
|
|
599
588
|
|
|
600
|
-
async addDeposit(txid, vout, amountSats) {
|
|
589
|
+
async addDeposit(txid, vout, amountSats, isMature) {
|
|
601
590
|
try {
|
|
602
591
|
await this.pool.query(
|
|
603
|
-
`INSERT INTO unclaimed_deposits (txid, vout, amount_sats)
|
|
604
|
-
VALUES ($1, $2, $3)
|
|
605
|
-
ON CONFLICT(txid, vout) DO
|
|
606
|
-
[txid, vout, amountSats]
|
|
592
|
+
`INSERT INTO unclaimed_deposits (txid, vout, amount_sats, is_mature)
|
|
593
|
+
VALUES ($1, $2, $3, $4)
|
|
594
|
+
ON CONFLICT(txid, vout) DO UPDATE SET is_mature = EXCLUDED.is_mature, amount_sats = EXCLUDED.amount_sats`,
|
|
595
|
+
[txid, vout, amountSats, isMature]
|
|
607
596
|
);
|
|
608
597
|
} catch (error) {
|
|
609
598
|
throw new StorageError(
|
|
@@ -630,13 +619,14 @@ class PostgresStorage {
|
|
|
630
619
|
async listDeposits() {
|
|
631
620
|
try {
|
|
632
621
|
const result = await this.pool.query(
|
|
633
|
-
"SELECT txid, vout, amount_sats, claim_error, refund_tx, refund_tx_id FROM unclaimed_deposits"
|
|
622
|
+
"SELECT txid, vout, amount_sats, is_mature, claim_error, refund_tx, refund_tx_id FROM unclaimed_deposits"
|
|
634
623
|
);
|
|
635
624
|
|
|
636
625
|
return result.rows.map((row) => ({
|
|
637
626
|
txid: row.txid,
|
|
638
627
|
vout: row.vout,
|
|
639
628
|
amountSats: row.amount_sats != null ? BigInt(row.amount_sats) : BigInt(0),
|
|
629
|
+
isMature: row.is_mature ?? true,
|
|
640
630
|
claimError: row.claim_error || null,
|
|
641
631
|
refundTx: row.refund_tx,
|
|
642
632
|
refundTxId: row.refund_tx_id,
|
|
@@ -682,19 +672,17 @@ class PostgresStorage {
|
|
|
682
672
|
await this._withTransaction(async (client) => {
|
|
683
673
|
for (const item of metadata) {
|
|
684
674
|
await client.query(
|
|
685
|
-
`INSERT INTO lnurl_receive_metadata (payment_hash, nostr_zap_request, nostr_zap_receipt, sender_comment
|
|
686
|
-
VALUES ($1, $2, $3, $4
|
|
675
|
+
`INSERT INTO lnurl_receive_metadata (payment_hash, nostr_zap_request, nostr_zap_receipt, sender_comment)
|
|
676
|
+
VALUES ($1, $2, $3, $4)
|
|
687
677
|
ON CONFLICT(payment_hash) DO UPDATE SET
|
|
688
678
|
nostr_zap_request = EXCLUDED.nostr_zap_request,
|
|
689
679
|
nostr_zap_receipt = EXCLUDED.nostr_zap_receipt,
|
|
690
|
-
sender_comment = EXCLUDED.sender_comment
|
|
691
|
-
preimage = EXCLUDED.preimage`,
|
|
680
|
+
sender_comment = EXCLUDED.sender_comment`,
|
|
692
681
|
[
|
|
693
682
|
item.paymentHash,
|
|
694
683
|
item.nostrZapRequest || null,
|
|
695
684
|
item.nostrZapReceipt || null,
|
|
696
685
|
item.senderComment || null,
|
|
697
|
-
item.preimage || null,
|
|
698
686
|
]
|
|
699
687
|
);
|
|
700
688
|
}
|
|
@@ -829,7 +817,9 @@ class PostgresStorage {
|
|
|
829
817
|
timestamp: Number(row.timestamp),
|
|
830
818
|
method,
|
|
831
819
|
details,
|
|
832
|
-
conversionDetails:
|
|
820
|
+
conversionDetails: row.conversion_status
|
|
821
|
+
? { status: row.conversion_status, from: null, to: null }
|
|
822
|
+
: null,
|
|
833
823
|
};
|
|
834
824
|
}
|
|
835
825
|
|
|
@@ -1364,16 +1354,37 @@ function defaultPostgresStorageConfig(connectionString) {
|
|
|
1364
1354
|
* @returns {Promise<PostgresStorage>}
|
|
1365
1355
|
*/
|
|
1366
1356
|
async function createPostgresStorage(config, logger = null) {
|
|
1367
|
-
const pool =
|
|
1357
|
+
const pool = createPostgresPool(config);
|
|
1358
|
+
return createPostgresStorageWithPool(pool, logger);
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* Create a pg.Pool from a config object.
|
|
1363
|
+
* The returned pool can be shared across multiple store implementations.
|
|
1364
|
+
*
|
|
1365
|
+
* @param {object} config - PostgreSQL configuration (from defaultPostgresStorageConfig)
|
|
1366
|
+
* @returns {pg.Pool}
|
|
1367
|
+
*/
|
|
1368
|
+
function createPostgresPool(config) {
|
|
1369
|
+
return new pg.Pool({
|
|
1368
1370
|
connectionString: config.connectionString,
|
|
1369
1371
|
max: config.maxPoolSize,
|
|
1370
1372
|
connectionTimeoutMillis: config.createTimeoutSecs * 1000,
|
|
1371
1373
|
idleTimeoutMillis: config.recycleTimeoutSecs * 1000,
|
|
1372
1374
|
});
|
|
1375
|
+
}
|
|
1373
1376
|
|
|
1377
|
+
/**
|
|
1378
|
+
* Create a PostgresStorage instance from an existing pg.Pool.
|
|
1379
|
+
*
|
|
1380
|
+
* @param {pg.Pool} pool - An existing connection pool
|
|
1381
|
+
* @param {object} [logger] - Optional logger
|
|
1382
|
+
* @returns {Promise<PostgresStorage>}
|
|
1383
|
+
*/
|
|
1384
|
+
async function createPostgresStorageWithPool(pool, logger = null) {
|
|
1374
1385
|
const storage = new PostgresStorage(pool, logger);
|
|
1375
1386
|
await storage.initialize();
|
|
1376
1387
|
return storage;
|
|
1377
1388
|
}
|
|
1378
1389
|
|
|
1379
|
-
module.exports = { PostgresStorage, createPostgresStorage, defaultPostgresStorageConfig, StorageError };
|
|
1390
|
+
module.exports = { PostgresStorage, createPostgresStorage, createPostgresPool, createPostgresStorageWithPool, defaultPostgresStorageConfig, StorageError };
|
|
@@ -234,6 +234,30 @@ class PostgresMigrationManager {
|
|
|
234
234
|
)`,
|
|
235
235
|
],
|
|
236
236
|
},
|
|
237
|
+
{
|
|
238
|
+
name: "Drop preimage column from lnurl_receive_metadata",
|
|
239
|
+
sql: [
|
|
240
|
+
`ALTER TABLE lnurl_receive_metadata DROP COLUMN IF EXISTS preimage`,
|
|
241
|
+
],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
name: "Clear cached lightning address for CachedLightningAddress format change",
|
|
245
|
+
sql: [
|
|
246
|
+
`DELETE FROM settings WHERE key = 'lightning_address'`,
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: "Add is_mature to unclaimed_deposits",
|
|
251
|
+
sql: [
|
|
252
|
+
`ALTER TABLE unclaimed_deposits ADD COLUMN is_mature BOOLEAN NOT NULL DEFAULT TRUE`,
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: "Add conversion_status to payment_metadata",
|
|
257
|
+
sql: [
|
|
258
|
+
`ALTER TABLE payment_metadata ADD COLUMN IF NOT EXISTS conversion_status TEXT`,
|
|
259
|
+
],
|
|
260
|
+
},
|
|
237
261
|
];
|
|
238
262
|
}
|
|
239
263
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// errors.cjs - Token store error wrapper with cause chain support
|
|
2
|
+
class TokenStoreError extends Error {
|
|
3
|
+
constructor(message, cause = null) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'TokenStoreError';
|
|
6
|
+
this.cause = cause;
|
|
7
|
+
if (Error.captureStackTrace) {
|
|
8
|
+
Error.captureStackTrace(this, TokenStoreError);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { TokenStoreError };
|