@moneydevkit/nextjs 0.16.0-beta.6 → 0.16.0-beta.8

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 CHANGED
@@ -237,6 +237,50 @@ Also returned for client-side validation issues (always `retryable: false`):
237
237
  | `invalid_idempotency_key` | Empty / missing |
238
238
  | `missing_access_token` | `MDK_ACCESS_TOKEN` not set |
239
239
 
240
+ ## Reading the merchant balance from a Server Action
241
+
242
+ `getBalance()` reads the spendable (outbound) balance of the Lightning node tied to your `MDK_ACCESS_TOKEN`. Same server-only constraints as `programmaticPayout`: the helper refuses to run in a browser and routes through mdk.com over HTTPS, which in turn dials the merchant node over the WS control plane.
243
+
244
+ ```ts
245
+ // app/actions.ts
246
+ 'use server'
247
+
248
+ import { getBalance } from '@moneydevkit/nextjs/server'
249
+
250
+ export async function fetchBalance() {
251
+ const result = await getBalance()
252
+
253
+ if (result.error) {
254
+ // retryable === true: transient (merchant function spinning up).
255
+ // retryable === false: terminal (invalid key, legacy org-level key, banned, or
256
+ // procedure-not-found from a pre-0.1.30 merchant / older mdk.com).
257
+ throw new Error(result.error.message)
258
+ }
259
+
260
+ return result.data.balanceSats // number, in sats
261
+ }
262
+ ```
263
+
264
+ ### Notes
265
+
266
+ - **App-scoped API key required.** Balance is meaningful per-app, not per-org. Legacy org-level keys return `GET_BALANCE_APP_KEY_REQUIRED` (not retryable). Use the API key from the App page in the dashboard.
267
+ - **First call may take a few seconds.** If the merchant function is cold, mdk.com fires a spin-up webhook and waits for the WS to register. Subsequent calls within the function's lifetime are fast.
268
+ - **Server-only.** Same `typeof window` check as `programmaticPayout`. Don't call from client components.
269
+ - **Idempotent.** Safe to retry. Transient errors are flagged `retryable: true`; auth, app-scope, and procedure-not-found errors are `retryable: false`.
270
+
271
+ ### Error reference
272
+
273
+ | `code` | `retryable` | What it means |
274
+ |-----------------------------------|-------------|----------------------------------------------------------------|
275
+ | `server_only` | false | Called from a browser runtime |
276
+ | `missing_access_token` | false | `MDK_ACCESS_TOKEN` not set |
277
+ | `GET_BALANCE_APP_KEY_REQUIRED` | false | Using a legacy org-level key. Copy the key from the App page |
278
+ | `UNAUTHORIZED` / `FORBIDDEN` | false | Invalid API key or banned user |
279
+ | `NOT_FOUND` | false | Procedure missing - pre-0.1.30 merchant SDK or older mdk.com |
280
+ | `BAD_REQUEST` | false | Server rejected the request as malformed |
281
+ | `GET_BALANCE_SPIN_UP_TIMEOUT` | true | Merchant function did not register WS in time. Safe to retry |
282
+ | `get_balance_failed` | true | Network / unclassified error |
283
+
240
284
  ## Customer Data
241
285
  Collect and store customer information with each checkout. Pass `customer` to pre-fill data and `requireCustomerData` to prompt the user for specific fields:
242
286
 
@@ -2,5 +2,6 @@ export { createCheckoutUrl } from '@moneydevkit/core/route';
2
2
  export type { CreateCheckoutUrlOptions } from '@moneydevkit/core/route';
3
3
  export { programmaticPayout } from '@moneydevkit/core/server';
4
4
  export type { ProgrammaticPayoutOptions } from '@moneydevkit/core/server';
5
+ export { getBalance } from '@moneydevkit/core/server';
5
6
  export { withPayment, withDeferredSettlement } from '@moneydevkit/core/mdk402';
6
7
  export type { PaymentConfig, SettleResult } from '@moneydevkit/core/mdk402';
@@ -1,4 +1,5 @@
1
1
  export { createCheckoutUrl } from '@moneydevkit/core/route';
2
2
  export { programmaticPayout } from '@moneydevkit/core/server';
3
+ export { getBalance } from '@moneydevkit/core/server';
3
4
  export { withPayment, withDeferredSettlement } from '@moneydevkit/core/mdk402';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAG7D,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAE3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE7D,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAErD,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneydevkit/nextjs",
3
- "version": "0.16.0-beta.6",
3
+ "version": "0.16.0-beta.8",
4
4
  "title": "@moneydevkit/nextjs",
5
5
  "description": "moneydevkit checkout components for Next.js.",
6
6
  "repository": {
@@ -63,8 +63,8 @@
63
63
  "tailwind-merge": "^3.3.0",
64
64
  "vaul": "^1.1.2",
65
65
  "zod": "^3.25.42",
66
- "@moneydevkit/api-contract": "0.1.29",
67
- "@moneydevkit/core": "0.16.0-beta.6"
66
+ "@moneydevkit/api-contract": "0.1.30",
67
+ "@moneydevkit/core": "0.16.0-beta.8"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/node": "^20.10.5",