@fivenorth/loop-sdk 0.8.0 → 0.9.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 (3) hide show
  1. package/README.md +18 -1
  2. package/dist/index.js +10 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -149,7 +149,23 @@ try {
149
149
  }
150
150
  ```
151
151
 
152
- Transaction responses include `command_id`, `submission_id`, `transaction_data`, and `update_id` when available. For token transfers, `update_id` may arrive later (once indexed), in which case `onTransactionUpdate` fires with the finalized `update_id`. Non-transfer transactions do not receive an `update_id` via this mechanism.
152
+ `onTransactionUpdate` fires once per transaction with a single payload that includes `command_id` and `submission_id`. On success it also includes `update_id` and `update_data` (ledger transaction tree); on failure it includes `status: "failed"` and `error.error_message`.
153
+
154
+ `submitTransaction` is the default async path. It returns the submission result first (including `command_id` and `submission_id`), then the ledger update arrives later via `onTransactionUpdate` with `update_id` and `update_data`.
155
+
156
+ To wait for the transaction result directly (opt-in), use:
157
+
158
+ ```javascript
159
+ await provider.submitAndWaitForTransaction(damlCommand, {
160
+ message: 'Transfer 10 CC to RetailStore',
161
+ });
162
+ ```
163
+
164
+ In wait mode, the final result is returned as a single `onTransactionUpdate` payload (command/submission IDs plus update data or failure status).
165
+
166
+ Note: `submitAndWaitForTransaction` errors do not always mean the transaction failed. A 4xx error (e.g., 400) indicates a definite failure. A 5xx/timeout can mean the ledger is slow or backed up; the transaction may still be committed later, so clients should continue to listen for updates rather than assume failure.
167
+
168
+ Deduplication: both async execute and execute-and-wait use a 1 hour deduplication window. If you retry within that window, resubmit the same `command_id` and `submission_id` so the request is idempotent.
153
169
 
154
170
  #### Sign a Message
155
171
 
@@ -179,6 +195,7 @@ await loop.wallet.transfer(
179
195
  {
180
196
  // Optional: show a custom message in the wallet prompt
181
197
  message: 'Send 5 CC to Alice',
198
+ executionMode: 'wait', // optional: 'async' (default) or 'wait'
182
199
  requestedAt: new Date().toISOString(), // optional
183
200
  executeBefore: new Date(Date.now() + 24*60*60*1000).toISOString(), // optional
184
201
  requestTimeout: 5 * 60 * 1000, // optional (ms), defaults to 5 minutes
package/dist/index.js CHANGED
@@ -2375,7 +2375,11 @@ class Provider {
2375
2375
  }
2376
2376
  handleResponse(message) {
2377
2377
  console.log("Received response:", message);
2378
- if (message?.type === "transaction_completed" /* TRANSACTION_COMPLETED */ && message?.payload?.update_id) {
2378
+ if (message?.type === "transaction_completed" /* TRANSACTION_COMPLETED */ && (message?.payload?.update_id || message?.payload?.update_data || message?.payload?.status)) {
2379
+ if (message?.payload?.error_message) {
2380
+ message.payload.error = { error_message: message.payload.error_message };
2381
+ delete message.payload.error_message;
2382
+ }
2379
2383
  this.hooks?.onTransactionUpdate?.(message.payload, message);
2380
2384
  }
2381
2385
  if (message.request_id) {
@@ -2394,6 +2398,9 @@ class Provider {
2394
2398
  async submitTransaction(payload, options) {
2395
2399
  return this.sendRequest("run_transaction" /* RUN_TRANSACTION */, payload, options);
2396
2400
  }
2401
+ async submitAndWaitForTransaction(payload, options) {
2402
+ return this.sendRequest("run_transaction" /* RUN_TRANSACTION */, { ...payload, execution_mode: "wait" }, options);
2403
+ }
2397
2404
  async transfer(recipient, amount, instrument, options) {
2398
2405
  const amountStr = typeof amount === "number" ? amount.toString() : amount;
2399
2406
  const { requestedAt, executeBefore, requestTimeout } = options || {};
@@ -2423,7 +2430,8 @@ class Provider {
2423
2430
  execute_before: executeBeforeIso
2424
2431
  };
2425
2432
  const preparedPayload = await this.connection.prepareTransfer(this.auth_token, transferRequest);
2426
- return this.submitTransaction({
2433
+ const submitFn = options?.executionMode === "wait" ? this.submitAndWaitForTransaction.bind(this) : this.submitTransaction.bind(this);
2434
+ return submitFn({
2427
2435
  commands: preparedPayload.commands,
2428
2436
  disclosedContracts: preparedPayload.disclosedContracts,
2429
2437
  packageIdSelectionPreference: preparedPayload.packageIdSelectionPreference,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fivenorth/loop-sdk",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "author": "support@fivenorth.io",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",