vendure-plugin-bitcoin-lightning-via-clink 0.1.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 (97) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +71 -0
  3. package/README.md +336 -0
  4. package/dist/api/admin-api.extensions.d.ts +2 -0
  5. package/dist/api/admin-api.extensions.d.ts.map +1 -0
  6. package/dist/api/admin-api.extensions.js +71 -0
  7. package/dist/api/admin-api.extensions.js.map +1 -0
  8. package/dist/api/admin.resolver.d.ts +47 -0
  9. package/dist/api/admin.resolver.d.ts.map +1 -0
  10. package/dist/api/admin.resolver.js +121 -0
  11. package/dist/api/admin.resolver.js.map +1 -0
  12. package/dist/api/clink-webhook.controller.d.ts +27 -0
  13. package/dist/api/clink-webhook.controller.d.ts.map +1 -0
  14. package/dist/api/clink-webhook.controller.js +130 -0
  15. package/dist/api/clink-webhook.controller.js.map +1 -0
  16. package/dist/api/shop-api.extensions.d.ts +2 -0
  17. package/dist/api/shop-api.extensions.d.ts.map +1 -0
  18. package/dist/api/shop-api.extensions.js +37 -0
  19. package/dist/api/shop-api.extensions.js.map +1 -0
  20. package/dist/api/shop.resolver.d.ts +20 -0
  21. package/dist/api/shop.resolver.d.ts.map +1 -0
  22. package/dist/api/shop.resolver.js +73 -0
  23. package/dist/api/shop.resolver.js.map +1 -0
  24. package/dist/clink.plugin.d.ts +44 -0
  25. package/dist/clink.plugin.d.ts.map +1 -0
  26. package/dist/clink.plugin.js +122 -0
  27. package/dist/clink.plugin.js.map +1 -0
  28. package/dist/config/clink-config.d.ts +25 -0
  29. package/dist/config/clink-config.d.ts.map +1 -0
  30. package/dist/config/clink-config.js +17 -0
  31. package/dist/config/clink-config.js.map +1 -0
  32. package/dist/entities/clink-channel-config.entity.d.ts +22 -0
  33. package/dist/entities/clink-channel-config.entity.d.ts.map +1 -0
  34. package/dist/entities/clink-channel-config.entity.js +68 -0
  35. package/dist/entities/clink-channel-config.entity.js.map +1 -0
  36. package/dist/entities/clink-offer.entity.d.ts +30 -0
  37. package/dist/entities/clink-offer.entity.d.ts.map +1 -0
  38. package/dist/entities/clink-offer.entity.js +100 -0
  39. package/dist/entities/clink-offer.entity.js.map +1 -0
  40. package/dist/index.d.ts +9 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +16 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/oracle/index.d.ts +3 -0
  45. package/dist/oracle/index.d.ts.map +1 -0
  46. package/dist/oracle/index.js +6 -0
  47. package/dist/oracle/index.js.map +1 -0
  48. package/dist/oracle/oracle.service.d.ts +25 -0
  49. package/dist/oracle/oracle.service.d.ts.map +1 -0
  50. package/dist/oracle/oracle.service.js +104 -0
  51. package/dist/oracle/oracle.service.js.map +1 -0
  52. package/dist/oracle/oracle.types.d.ts +65 -0
  53. package/dist/oracle/oracle.types.d.ts.map +1 -0
  54. package/dist/oracle/oracle.types.js +3 -0
  55. package/dist/oracle/oracle.types.js.map +1 -0
  56. package/dist/oracle/providers/coingecko.d.ts +8 -0
  57. package/dist/oracle/providers/coingecko.d.ts.map +1 -0
  58. package/dist/oracle/providers/coingecko.js +30 -0
  59. package/dist/oracle/providers/coingecko.js.map +1 -0
  60. package/dist/oracle/providers/custom.d.ts +9 -0
  61. package/dist/oracle/providers/custom.d.ts.map +1 -0
  62. package/dist/oracle/providers/custom.js +59 -0
  63. package/dist/oracle/providers/custom.js.map +1 -0
  64. package/dist/oracle/providers/kraken.d.ts +7 -0
  65. package/dist/oracle/providers/kraken.d.ts.map +1 -0
  66. package/dist/oracle/providers/kraken.js +38 -0
  67. package/dist/oracle/providers/kraken.js.map +1 -0
  68. package/dist/package.json +6 -0
  69. package/dist/payment-handler.d.ts +43 -0
  70. package/dist/payment-handler.d.ts.map +1 -0
  71. package/dist/payment-handler.js +137 -0
  72. package/dist/payment-handler.js.map +1 -0
  73. package/dist/payment-process.d.ts +20 -0
  74. package/dist/payment-process.d.ts.map +1 -0
  75. package/dist/payment-process.js +27 -0
  76. package/dist/payment-process.js.map +1 -0
  77. package/dist/services/clink.service.d.ts +45 -0
  78. package/dist/services/clink.service.d.ts.map +1 -0
  79. package/dist/services/clink.service.js +185 -0
  80. package/dist/services/clink.service.js.map +1 -0
  81. package/dist/services/nip44.d.ts +9 -0
  82. package/dist/services/nip44.d.ts.map +1 -0
  83. package/dist/services/nip44.js +32 -0
  84. package/dist/services/nip44.js.map +1 -0
  85. package/dist/services/nostr-key.service.d.ts +25 -0
  86. package/dist/services/nostr-key.service.d.ts.map +1 -0
  87. package/dist/services/nostr-key.service.js +76 -0
  88. package/dist/services/nostr-key.service.js.map +1 -0
  89. package/dist/services/payment-monitor.service.d.ts +28 -0
  90. package/dist/services/payment-monitor.service.d.ts.map +1 -0
  91. package/dist/services/payment-monitor.service.js +273 -0
  92. package/dist/services/payment-monitor.service.js.map +1 -0
  93. package/dist/types.d.ts +17 -0
  94. package/dist/types.d.ts.map +1 -0
  95. package/dist/types.js +3 -0
  96. package/dist/types.js.map +1 -0
  97. package/package.json +64 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-07-23)
4
+
5
+ ### Features
6
+
7
+ - Initial release of the Bitcoin Lightning CLINK plugin for Vendure
8
+ - `ClinkPaymentHandler` — asynchronous payment handler with BTC price oracle
9
+ - `ClinkPaymentProcess` — custom payment state machine (`Created → Pending → Settled/Error/Cancelled`)
10
+ - `OracleService` — BTC/USD price oracle with CoinGecko, Kraken, and custom providers
11
+ - Per-channel Nostr keypair generation and relay configuration
12
+ - Shop API: create payment offers, poll payment status
13
+ - Admin API: configure CLINK settings, manage offers, test oracle providers
14
+ - HTTP webhook fallback for wallets without Nostr support
15
+ - Storefront React component (`ClinkPayment`)
16
+ - Comprehensive unit tests (43 tests)
package/LICENSE ADDED
@@ -0,0 +1,71 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ For the full license text, see: https://www.gnu.org/licenses/gpl-3.0.txt
package/README.md ADDED
@@ -0,0 +1,336 @@
1
+ # vendure-plugin-bitcoin-lightning-via-clink
2
+
3
+ [![Vendure](https://img.shields.io/badge/Vendure-v3.x-blue)](https://www.vendure.io/)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue)](https://www.typescriptlang.org/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ **Bitcoin Lightning payments for [Vendure](https://www.vendure.io/) via the [CLINK](https://clinkme.dev) protocol — Nostr-native static payment codes.**
8
+
9
+ Accept Bitcoin Lightning payments in your Vendure store using CLINK (`noffer1...`) static payment codes. Customers pay directly from any CLINK-compatible wallet — no invoices to generate, no payment pages to build.
10
+
11
+ ---
12
+
13
+ ## Features
14
+
15
+ - **CLINK Protocol** — Nostr-native static payment codes (`noffer1...` bech32 strings)
16
+ - **Nostr Relay Integration** — Real-time payment monitoring via Kind 21001 events
17
+ - **NIP-44 Encryption** — End-to-end encrypted payment communication
18
+ - **Per-Channel Config** — Each Vendure channel gets its own Nostr keypair and relay config
19
+ - **HTTP Webhook Fallback** — `POST /payments/clink` for wallets without Nostr support
20
+ - **GraphQL API** — Shop API for storefronts, Admin API for management
21
+ - **Storefront React Component** — Ready-to-use `ClinkPayment` component with QR display
22
+ - **Auto-Expiry** — Configurable payment offer expiration
23
+ - **Zero Invoice Generation** — Static offers eliminate per-payment invoice creation
24
+
25
+ ---
26
+
27
+ ## Architecture
28
+
29
+ ```
30
+ ┌─────────────────────────────────────────────────────┐
31
+ │ Vendure Server │
32
+ │ │
33
+ │ ┌──────────────┐ ┌─────────────────────────────┐ │
34
+ │ │ Shop API │ │ Admin API │ │
35
+ │ │ clinkOffer │ │ clinkConfig │ │
36
+ │ │ clinkPayment │ │ clinkOffers │ │
37
+ │ │ Status │ │ updateClinkConfig │ │
38
+ │ └──────┬───────┘ └──────────┬──────────────────┘ │
39
+ │ │ │ │
40
+ │ ┌──────▼───────────────────────▼──────────────────┐ │
41
+ │ │ ClinkPlugin │ │
42
+ │ │ ┌─────────────┐ ┌──────────────────────────┐ │ │
43
+ │ │ │ ClinkService │ │ PaymentMonitorService │ │ │
44
+ │ │ │ - createOffer│ │ - Nostr relay listener │ │ │
45
+ │ │ │ - getOffer │ │ - NIP-44 decrypt/encrypt │ │ │
46
+ │ │ │ - markPaid │ │ - Receipt handler │ │ │
47
+ │ │ └──────┬──────┘ └────────────┬─────────────┘ │ │
48
+ │ │ │ │ │ │
49
+ │ │ ┌──────▼──────────────────────▼──────────────┐ │ │
50
+ │ │ │ ClinkPaymentHandler │ │ │
51
+ │ │ │ code: "clink-lightning" │ │ │
52
+ │ │ │ createPayment → ClinkOffer (noffer1...) │ │ │
53
+ │ │ │ settlePayment → verify Nostr receipt │ │ │
54
+ │ │ │ cancelPayment → mark offer expired │ │ │
55
+ │ │ └────────────────────────────────────────────┘ │ │
56
+ │ └─────────────────────────────────────────────────┘ │
57
+ │ │ │
58
+ │ ┌──────▼──────────────────────────────────────────┐ │
59
+ │ │ CLINK SDK (@shocknet/clink-sdk) │ │
60
+ │ │ nofferEncode() → noffer1... bech32 string │ │
61
+ │ │ ClinkSDK → Nostr relay communication │ │
62
+ │ └─────────────────────────────────────────────────┘ │
63
+ └───────────────────────┬─────────────────────────────┘
64
+
65
+ ┌──────────────▼──────────────┐
66
+ │ Nostr Relay Network │
67
+ │ - Kind 21001 events │
68
+ │ - NIP-44 encrypted msgs │
69
+ │ - Payment confirmations │
70
+ └──────────────┬──────────────┘
71
+
72
+ ┌──────────────▼──────────────┐
73
+ │ CLINK-Compatible Wallet │
74
+ │ ShockWallet, ZEUS, etc. │
75
+ │ Scans noffer → Pays LN │
76
+ └─────────────────────────────┘
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Quick Start
82
+
83
+ ### 1. Install
84
+
85
+ ```bash
86
+ npm install vendure-plugin-bitcoin-lightning-via-clink
87
+ ```
88
+
89
+ ### 2. Configure
90
+
91
+ ```typescript
92
+ // vendure-config.ts
93
+ import { ClinkPlugin } from 'vendure-plugin-bitcoin-lightning-via-clink';
94
+
95
+ export const config: VendureConfig = {
96
+ plugins: [
97
+ ClinkPlugin.init({
98
+ relays: ['wss://relay.shocknetwork.com'],
99
+ autoSettle: true,
100
+ offerExpiryMinutes: 30,
101
+ httpFallback: true,
102
+ }),
103
+ ],
104
+ // ... rest of config
105
+ };
106
+ ```
107
+
108
+ ### 3. Add Payment Method
109
+
110
+ In the Vendure Admin UI, go to **Settings > Payment Methods** and add **Bitcoin Lightning (CLINK)**.
111
+
112
+ ### 4. Accept Payments
113
+
114
+ Customers can now select CLINK at checkout and pay from any compatible wallet.
115
+
116
+ ---
117
+
118
+ ## Plugin Options
119
+
120
+ | Option | Type | Default | Description |
121
+ |--------|------|---------|-------------|
122
+ | `relays` | `string[]` | `['wss://relay.shocknetwork.com']` | Nostr relay URLs |
123
+ | `autoSettle` | `boolean` | `true` | Auto-confirm payments when Nostr receipt received |
124
+ | `offerExpiryMinutes` | `number` | `30` | Minutes before payment offer expires |
125
+ | `httpFallback` | `boolean` | `true` | Enable HTTP webhook at `/payments/clink` |
126
+ | `nostrSecretKey` | `string` | `''` | Global Nostr key (hex). Per-channel keys generated if empty |
127
+
128
+ ---
129
+
130
+ ## GraphQL API
131
+
132
+ ### Shop API (Customer-Facing)
133
+
134
+ ```graphql
135
+ # Get CLINK offer for an order
136
+ query {
137
+ clinkOffer(orderCode: "ORDER_001") {
138
+ offerId
139
+ noffer # noffer1... bech32 string for wallet
140
+ amountSats
141
+ status
142
+ expiresAt
143
+ }
144
+ }
145
+
146
+ # Check payment status
147
+ query {
148
+ clinkPaymentStatus(orderCode: "ORDER_001") {
149
+ offerId
150
+ status # pending | paid | expired
151
+ preimage # Payment proof (available after settlement)
152
+ bolt11Invoice
153
+ }
154
+ }
155
+ ```
156
+
157
+ ### Admin API
158
+
159
+ ```graphql
160
+ # Get channel CLINK config
161
+ query {
162
+ clinkConfig(channelId: "1") {
163
+ nostrPubkey
164
+ relayUrls
165
+ autoSettle
166
+ offerExpiryMinutes
167
+ }
168
+ }
169
+
170
+ # List all offers
171
+ query {
172
+ clinkOffers(status: "pending", limit: 20) {
173
+ totalItems
174
+ items {
175
+ offerId
176
+ noffer
177
+ amountSats
178
+ status
179
+ paidAt
180
+ }
181
+ }
182
+ }
183
+
184
+ # Update channel config
185
+ mutation {
186
+ updateClinkConfig(
187
+ channelId: "1",
188
+ input: {
189
+ relayUrls: ["wss://relay.shocknetwork.com"]
190
+ autoSettle: true
191
+ offerExpiryMinutes: 60
192
+ }
193
+ ) {
194
+ nostrPubkey
195
+ relayUrls
196
+ }
197
+ }
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Storefront Integration
203
+
204
+ ### React Component
205
+
206
+ ```tsx
207
+ import { ClinkPayment } from './ClinkPayment';
208
+
209
+ function CheckoutPage({ orderCode }: { orderCode: string }) {
210
+ return (
211
+ <ClinkPayment
212
+ orderCode={orderCode}
213
+ apiEndpoint="https://your-store.com/shop-api"
214
+ onPaymentConfirmed={(preimage) => {
215
+ console.log('Payment confirmed!', preimage);
216
+ // Redirect to order confirmation
217
+ }}
218
+ onPaymentExpired={() => {
219
+ console.log('Payment expired');
220
+ // Show retry option
221
+ }}
222
+ />
223
+ );
224
+ }
225
+ ```
226
+
227
+ ### Using Vendure's `addPaymentToOrder` Mutation
228
+
229
+ ```graphql
230
+ mutation AddClinkPayment {
231
+ addPaymentToOrder(
232
+ input: {
233
+ method: "clink-lightning"
234
+ metadata: {}
235
+ }
236
+ ) {
237
+ ... on Order {
238
+ id
239
+ code
240
+ total
241
+ state
242
+ }
243
+ ... on ErrorResult {
244
+ errorCode
245
+ message
246
+ }
247
+ }
248
+ }
249
+ ```
250
+
251
+ ---
252
+
253
+ ## HTTP Webhook
254
+
255
+ For wallets without Nostr support, the HTTP fallback accepts:
256
+
257
+ ```
258
+ POST /payments/clink
259
+ Content-Type: application/json
260
+
261
+ {
262
+ "offerId": "vendure_ORDER_001_1234567890",
263
+ "bolt11": "lnbc1...",
264
+ "preimage": "hex_preimage"
265
+ }
266
+ ```
267
+
268
+ ---
269
+
270
+ ## Database Tables
271
+
272
+ The plugin creates two tables automatically:
273
+
274
+ - **`clink_offer`** — Payment offers linked to Vendure orders
275
+ - **`clink_channel_config`** — Per-channel Nostr keys and relay configuration
276
+
277
+ ---
278
+
279
+ ## Development
280
+
281
+ ### Test App
282
+
283
+ ```bash
284
+ # Build plugin and copy to test-app
285
+ npm run dev:test-app
286
+
287
+ # Start test Vendure server
288
+ cd test-app && npm run dev
289
+ ```
290
+
291
+ Server runs at `http://localhost:3000`:
292
+ - Shop API: `http://localhost:3000/shop-api`
293
+ - Admin API: `http://localhost:3000/admin-api`
294
+
295
+ ### Build
296
+
297
+ ```bash
298
+ npm run build # Compile TypeScript
299
+ npm run typecheck # Type-check without emitting
300
+ npm run dev # Watch mode
301
+ ```
302
+
303
+ ---
304
+
305
+ ## How CLINK Works
306
+
307
+ 1. **Merchant** configures CLINK plugin with Nostr relay URLs
308
+ 2. **Customer** adds item to cart and proceeds to checkout
309
+ 3. **Plugin** generates a `noffer1...` static payment code linked to the order
310
+ 4. **Customer** scans/pastes the offer in a CLINK-compatible wallet
311
+ 5. **Wallet** resolves the offer via Nostr relay and pays the Lightning invoice
312
+ 6. **Nostr relay** forwards payment receipt (Kind 21001, NIP-44 encrypted)
313
+ 7. **Plugin** decrypts receipt, verifies payment, marks offer as paid
314
+ 8. **Order** advances to the next state
315
+
316
+ ### Key Concepts
317
+
318
+ - **`noffer1...`**: Bech32-encoded static payment code (like a Lightning address, but for offers)
319
+ - **Nostr Kind 21001**: CLINK protocol event type for payment communication
320
+ - **NIP-44**: Nostr encryption standard for end-to-end encrypted payment messages
321
+ - **Per-channel keys**: Each Vendure channel gets its own Nostr identity
322
+
323
+ ---
324
+
325
+ ## License
326
+
327
+ MIT
328
+
329
+ ---
330
+
331
+ ## Links
332
+
333
+ - [CLINK Protocol](https://clinkme.dev) — Official CLINK documentation
334
+ - [Vendure](https://www.vendure.io/) — eCommerce platform
335
+ - [Nostr](https://nostr.com/) — Decentralized protocol
336
+ - [ShockNet](https://github.com/ShockNet) — Bitcoin Lightning infrastructure
@@ -0,0 +1,2 @@
1
+ export declare const adminApiExtensions: import("graphql").DocumentNode;
2
+ //# sourceMappingURL=admin-api.extensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-api.extensions.d.ts","sourceRoot":"","sources":["../../src/api/admin-api.extensions.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,gCA8D9B,CAAC"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.adminApiExtensions = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ exports.adminApiExtensions = (0, graphql_tag_1.default) `
9
+ type ClinkOffer implements Node {
10
+ id: ID!
11
+ createdAt: DateTime!
12
+ updatedAt: DateTime!
13
+ offerId: String!
14
+ noffer: String!
15
+ amountSats: Int!
16
+ pricingType: Int!
17
+ status: String!
18
+ bolt11Invoice: String
19
+ expiresAt: DateTime
20
+ paidAt: DateTime
21
+ }
22
+
23
+ type ClinkChannelConfig implements Node {
24
+ id: ID!
25
+ createdAt: DateTime!
26
+ updatedAt: DateTime!
27
+ nostrPubkey: String!
28
+ relayUrls: [String!]!
29
+ autoSettle: Boolean!
30
+ offerExpiryMinutes: Int!
31
+ httpFallback: Boolean!
32
+ paymentHandlerCode: String!
33
+ }
34
+
35
+ type ClinkOfferList implements PaginatedList {
36
+ items: [ClinkOffer!]!
37
+ totalItems: Int!
38
+ }
39
+
40
+ type OraclePrice {
41
+ btcUsd: Float!
42
+ provider: String!
43
+ timestamp: DateTime!
44
+ }
45
+
46
+ type OracleTestResult {
47
+ success: Boolean!
48
+ provider: String!
49
+ price: OraclePrice
50
+ error: String
51
+ }
52
+
53
+ input ClinkConfigInput {
54
+ relayUrls: [String!]
55
+ autoSettle: Boolean
56
+ offerExpiryMinutes: Int
57
+ httpFallback: Boolean
58
+ }
59
+
60
+ extend type Query {
61
+ clinkConfig(channelId: ID!): ClinkChannelConfig
62
+ clinkOffers(status: String, limit: Int, offset: Int): ClinkOfferList!
63
+ oraclePrice: OraclePrice!
64
+ }
65
+
66
+ extend type Mutation {
67
+ updateClinkConfig(channelId: ID!, input: ClinkConfigInput!): ClinkChannelConfig!
68
+ testOraclePrice(provider: String!): OracleTestResult!
69
+ }
70
+ `;
71
+ //# sourceMappingURL=admin-api.extensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-api.extensions.js","sourceRoot":"","sources":["../../src/api/admin-api.extensions.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA8B;AAEjB,QAAA,kBAAkB,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8DpC,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { RequestContext } from '@vendure/core';
2
+ import { ClinkService } from '../services/clink.service';
3
+ import { NostrKeyService } from '../services/nostr-key.service';
4
+ import { OracleProviderId } from '../oracle/oracle.types';
5
+ export declare class ClinkAdminResolver {
6
+ private clinkService;
7
+ private nostrKeyService;
8
+ constructor(clinkService: ClinkService, nostrKeyService: NostrKeyService);
9
+ clinkConfig(ctx: RequestContext, args: {
10
+ channelId: string;
11
+ }): Promise<import("..").ClinkChannelConfig>;
12
+ clinkOffers(ctx: RequestContext, args: {
13
+ status?: string;
14
+ limit?: number;
15
+ offset?: number;
16
+ }): Promise<{
17
+ items: import("..").ClinkOffer[];
18
+ totalItems: number;
19
+ }>;
20
+ oraclePrice(): Promise<{
21
+ btcUsd: number;
22
+ provider: OracleProviderId;
23
+ timestamp: string;
24
+ }>;
25
+ testOraclePrice(args: {
26
+ provider: string;
27
+ }): Promise<{
28
+ success: boolean;
29
+ provider: OracleProviderId;
30
+ price: {
31
+ btcUsd: number;
32
+ provider: OracleProviderId;
33
+ timestamp: string;
34
+ };
35
+ error?: undefined;
36
+ } | {
37
+ success: boolean;
38
+ provider: OracleProviderId;
39
+ price: null;
40
+ error: any;
41
+ }>;
42
+ updateClinkConfig(ctx: RequestContext, args: {
43
+ channelId: string;
44
+ input: any;
45
+ }): Promise<import("..").ClinkChannelConfig>;
46
+ }
47
+ //# sourceMappingURL=admin.resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.resolver.d.ts","sourceRoot":"","sources":["../../src/api/admin.resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAA0B,cAAc,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,qBACa,kBAAkB;IAE3B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,eAAe;gBADf,YAAY,EAAE,YAAY,EAC1B,eAAe,EAAE,eAAe;IAKpC,WAAW,CACR,GAAG,EAAE,cAAc,EAClB,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE;IAU/B,WAAW,CACR,GAAG,EAAE,cAAc,EAClB,IAAI,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;;;;IAW9D,WAAW;;;;;IAYX,eAAe,CACX,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;;;;;IA4B9B,iBAAiB,CACd,GAAG,EAAE,cAAc,EAClB,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE;CAQlD"}
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ClinkAdminResolver = void 0;
16
+ const graphql_1 = require("@nestjs/graphql");
17
+ const core_1 = require("@vendure/core");
18
+ const clink_service_1 = require("../services/clink.service");
19
+ const nostr_key_service_1 = require("../services/nostr-key.service");
20
+ const clink_plugin_1 = require("../clink.plugin");
21
+ let ClinkAdminResolver = class ClinkAdminResolver {
22
+ constructor(clinkService, nostrKeyService) {
23
+ this.clinkService = clinkService;
24
+ this.nostrKeyService = nostrKeyService;
25
+ }
26
+ async clinkConfig(ctx, args) {
27
+ return this.nostrKeyService.getOrCreateChannelKeys(ctx, parseInt(args.channelId, 10));
28
+ }
29
+ async clinkOffers(ctx, args) {
30
+ return this.clinkService.getAllOffers(ctx, {
31
+ status: args.status,
32
+ limit: args.limit,
33
+ offset: args.offset,
34
+ });
35
+ }
36
+ async oraclePrice() {
37
+ const oracle = clink_plugin_1.ClinkPlugin.getOracleService();
38
+ const result = await oracle.getPrice();
39
+ return {
40
+ btcUsd: result.btcUsd,
41
+ provider: result.provider,
42
+ timestamp: new Date(result.timestamp).toISOString(),
43
+ };
44
+ }
45
+ async testOraclePrice(args) {
46
+ const oracle = clink_plugin_1.ClinkPlugin.getOracleService();
47
+ const providerId = args.provider;
48
+ try {
49
+ const result = await oracle.testProvider(providerId);
50
+ return {
51
+ success: true,
52
+ provider: result.provider,
53
+ price: {
54
+ btcUsd: result.btcUsd,
55
+ provider: result.provider,
56
+ timestamp: new Date(result.timestamp).toISOString(),
57
+ },
58
+ };
59
+ }
60
+ catch (err) {
61
+ return {
62
+ success: false,
63
+ provider: providerId,
64
+ price: null,
65
+ error: err.message,
66
+ };
67
+ }
68
+ }
69
+ async updateClinkConfig(ctx, args) {
70
+ return this.nostrKeyService.updateConfig(ctx, parseInt(args.channelId, 10), args.input);
71
+ }
72
+ };
73
+ exports.ClinkAdminResolver = ClinkAdminResolver;
74
+ __decorate([
75
+ (0, graphql_1.Query)(),
76
+ (0, core_1.Allow)(core_1.Permission.ReadAdministrator),
77
+ __param(0, (0, core_1.Ctx)()),
78
+ __param(1, (0, graphql_1.Args)()),
79
+ __metadata("design:type", Function),
80
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
81
+ __metadata("design:returntype", Promise)
82
+ ], ClinkAdminResolver.prototype, "clinkConfig", null);
83
+ __decorate([
84
+ (0, graphql_1.Query)(),
85
+ (0, core_1.Allow)(core_1.Permission.ReadAdministrator),
86
+ __param(0, (0, core_1.Ctx)()),
87
+ __param(1, (0, graphql_1.Args)()),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
90
+ __metadata("design:returntype", Promise)
91
+ ], ClinkAdminResolver.prototype, "clinkOffers", null);
92
+ __decorate([
93
+ (0, graphql_1.Query)(),
94
+ (0, core_1.Allow)(core_1.Permission.ReadAdministrator),
95
+ __metadata("design:type", Function),
96
+ __metadata("design:paramtypes", []),
97
+ __metadata("design:returntype", Promise)
98
+ ], ClinkAdminResolver.prototype, "oraclePrice", null);
99
+ __decorate([
100
+ (0, graphql_1.Mutation)(),
101
+ (0, core_1.Allow)(core_1.Permission.ReadAdministrator),
102
+ __param(0, (0, graphql_1.Args)()),
103
+ __metadata("design:type", Function),
104
+ __metadata("design:paramtypes", [Object]),
105
+ __metadata("design:returntype", Promise)
106
+ ], ClinkAdminResolver.prototype, "testOraclePrice", null);
107
+ __decorate([
108
+ (0, graphql_1.Mutation)(),
109
+ (0, core_1.Allow)(core_1.Permission.ReadAdministrator),
110
+ __param(0, (0, core_1.Ctx)()),
111
+ __param(1, (0, graphql_1.Args)()),
112
+ __metadata("design:type", Function),
113
+ __metadata("design:paramtypes", [core_1.RequestContext, Object]),
114
+ __metadata("design:returntype", Promise)
115
+ ], ClinkAdminResolver.prototype, "updateClinkConfig", null);
116
+ exports.ClinkAdminResolver = ClinkAdminResolver = __decorate([
117
+ (0, graphql_1.Resolver)(),
118
+ __metadata("design:paramtypes", [clink_service_1.ClinkService,
119
+ nostr_key_service_1.NostrKeyService])
120
+ ], ClinkAdminResolver);
121
+ //# sourceMappingURL=admin.resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.resolver.js","sourceRoot":"","sources":["../../src/api/admin.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAkE;AAClE,wCAAuE;AACvE,6DAAyD;AACzD,qEAAgE;AAChE,kDAA8C;AAIvC,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,YACU,YAA0B,EAC1B,eAAgC;QAD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