@fivenorth/loop-sdk 0.6.3 → 0.6.4

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 +2 -0
  2. package/dist/index.js +12 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -167,6 +167,7 @@ await loop.wallet.transfer(
167
167
  {
168
168
  requestedAt: new Date().toISOString(), // optional
169
169
  executeBefore: new Date(Date.now() + 24*60*60*1000).toISOString(), // optional
170
+ requestTimeout: 5 * 60 * 1000, // optional (ms), defaults to 5 minutes
170
171
  },
171
172
  );
172
173
  ```
@@ -174,6 +175,7 @@ await loop.wallet.transfer(
174
175
  Notes:
175
176
  - You must have spendable holdings for the specified instrument (admin + id). If left blank, the SDK defaults to the native token.
176
177
  - The helper handles fetching holdings, building the transfer factory payload, and submitting via Wallet Connect.
178
+ - Requests time out after 5 minutes by default; override with `requestTimeout` in milliseconds.
177
179
 
178
180
  Common instrument overrides (pass into the `instrument` argument above):
179
181
 
package/dist/index.js CHANGED
@@ -2240,6 +2240,7 @@ class RejectRequestError extends Error {
2240
2240
  }
2241
2241
 
2242
2242
  // src/provider.ts
2243
+ var DEFAULT_REQUEST_TIMEOUT_MS = 300000;
2243
2244
  function generateUUID() {
2244
2245
  return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (c) => {
2245
2246
  const gCrypto = globalThis.crypto;
@@ -2268,8 +2269,7 @@ class Provider {
2268
2269
  email;
2269
2270
  auth_token;
2270
2271
  requests = new Map;
2271
- requestTimeout = 300000;
2272
- constructor({ connection, party_id, public_key, auth_token, email, requestTimeout }) {
2272
+ constructor({ connection, party_id, public_key, auth_token, email }) {
2273
2273
  if (!connection) {
2274
2274
  throw new Error("Provider requires a connection object.");
2275
2275
  }
@@ -2278,7 +2278,6 @@ class Provider {
2278
2278
  this.public_key = public_key;
2279
2279
  this.email = email;
2280
2280
  this.auth_token = auth_token;
2281
- this.requestTimeout = requestTimeout || 300000;
2282
2281
  }
2283
2282
  handleResponse(message) {
2284
2283
  console.log("Received response:", message);
@@ -2292,11 +2291,12 @@ class Provider {
2292
2291
  async getActiveContracts(params) {
2293
2292
  return this.connection.getActiveContracts(this.auth_token, params);
2294
2293
  }
2295
- async submitTransaction(payload) {
2296
- return this.sendRequest("run_transaction" /* RUN_TRANSACTION */, payload);
2294
+ async submitTransaction(payload, options) {
2295
+ return this.sendRequest("run_transaction" /* RUN_TRANSACTION */, payload, options);
2297
2296
  }
2298
2297
  async transfer(recipient, amount, instrument, options) {
2299
2298
  const amountStr = typeof amount === "number" ? amount.toString() : amount;
2299
+ const { requestedAt, executeBefore, requestTimeout } = options || {};
2300
2300
  const resolveDate = (value, fallbackMs) => {
2301
2301
  if (value instanceof Date) {
2302
2302
  return value.toISOString();
@@ -2309,8 +2309,8 @@ class Provider {
2309
2309
  }
2310
2310
  return new Date().toISOString();
2311
2311
  };
2312
- const requestedAtIso = resolveDate(options?.requestedAt);
2313
- const executeBeforeIso = resolveDate(options?.executeBefore, 24 * 60 * 60 * 1000);
2312
+ const requestedAtIso = resolveDate(requestedAt);
2313
+ const executeBeforeIso = resolveDate(executeBefore, 24 * 60 * 60 * 1000);
2314
2314
  const transferRequest = {
2315
2315
  recipient,
2316
2316
  amount: amountStr,
@@ -2329,17 +2329,18 @@ class Provider {
2329
2329
  actAs: preparedPayload.actAs,
2330
2330
  readAs: preparedPayload.readAs,
2331
2331
  synchronizerId: preparedPayload.synchronizerId
2332
- });
2332
+ }, { requestTimeout });
2333
2333
  }
2334
2334
  async signMessage(message) {
2335
2335
  return this.sendRequest("sign_raw_message" /* SIGN_RAW_MESSAGE */, message);
2336
2336
  }
2337
- sendRequest(messageType, params = {}) {
2337
+ sendRequest(messageType, params = {}, options) {
2338
2338
  return new Promise((resolve, reject) => {
2339
2339
  if (!this.connection.ws || this.connection.ws.readyState !== WebSocket.OPEN) {
2340
2340
  return reject(new Error("Not connected."));
2341
2341
  }
2342
2342
  const requestId = generateRequestId();
2343
+ const requestTimeout = options?.requestTimeout ?? DEFAULT_REQUEST_TIMEOUT_MS;
2343
2344
  this.connection.ws.send(JSON.stringify({
2344
2345
  request_id: requestId,
2345
2346
  type: messageType,
@@ -2359,10 +2360,10 @@ class Provider {
2359
2360
  }
2360
2361
  } else {
2361
2362
  elapsedTime += intervalTime;
2362
- if (elapsedTime >= this.requestTimeout) {
2363
+ if (elapsedTime >= requestTimeout) {
2363
2364
  clearInterval(intervalId);
2364
2365
  this.requests.delete(requestId);
2365
- reject(new RequestTimeoutError(this.requestTimeout));
2366
+ reject(new RequestTimeoutError(requestTimeout));
2366
2367
  }
2367
2368
  }
2368
2369
  }, intervalTime);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fivenorth/loop-sdk",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "author": "hello@fivenorth.io",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",