@pooflabs/core 0.0.29 → 0.0.31

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.
@@ -22,6 +22,11 @@ export type GetOptions = {
22
22
  headers?: Record<string, string>;
23
23
  };
24
24
  };
25
+ export type RunQueryOptions = {
26
+ _overrides?: {
27
+ headers?: Record<string, string>;
28
+ };
29
+ };
25
30
  export declare function get(path: string, opts?: GetOptions): Promise<any>;
26
31
  export type RunExpressionOptions = {
27
32
  returnType?: 'Bool' | 'String' | 'Int' | 'UInt';
@@ -38,12 +43,12 @@ export type RunExpressionResult = {
38
43
  result?: any;
39
44
  }[];
40
45
  };
41
- export declare function runQuery(absolutePath: string, queryName: string, queryArgs: any): Promise<any>;
46
+ export declare function runQuery(absolutePath: string, queryName: string, queryArgs: any, opts?: RunQueryOptions): Promise<any>;
42
47
  export declare function runQueryMany(many: {
43
48
  absolutePath: string;
44
49
  queryName: string;
45
50
  queryArgs: any;
46
- }[]): Promise<any>;
51
+ }[], opts?: RunQueryOptions): Promise<any>;
47
52
  export declare function runExpression(expression: string, queryArgs: any, options?: RunExpressionOptions): Promise<RunExpressionResult>;
48
53
  export declare function runExpressionMany(many: {
49
54
  expression: string;
@@ -66,4 +71,4 @@ export declare function setFile(path: string, file: File | null): Promise<boolea
66
71
  export declare function signMessage(message: string): Promise<string>;
67
72
  export declare function signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
68
73
  export declare function signAndSubmitTransaction(transaction: Transaction | VersionedTransaction, feePayer?: PublicKey): Promise<string>;
69
- export declare function syncItems(paths: string[]): Promise<any>;
74
+ export declare function syncItems(paths: string[], options?: SetOptions): Promise<any>;
package/dist/index.js CHANGED
@@ -3208,7 +3208,7 @@ async function refreshAuthSessionOnce(appId, isServer) {
3208
3208
  return refreshPromise;
3209
3209
  }
3210
3210
  async function makeApiRequest(method, urlPath, data, _overrides) {
3211
- var _a, _b, _c, _d, _e, _f;
3211
+ var _a, _b, _c, _d;
3212
3212
  const config = await getConfig();
3213
3213
  let hasRetriedAfterServerSessionReset = false;
3214
3214
  const clearServerSession = async () => {
@@ -3268,8 +3268,14 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
3268
3268
  if (((_b = error.response) === null || _b === void 0 ? void 0 : _b.status) == 404) {
3269
3269
  return { data: null, status: 404 };
3270
3270
  }
3271
- if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) {
3272
- throw new Error((_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.message);
3271
+ if ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data) {
3272
+ const responseData = typeof error.response.data === 'object'
3273
+ ? error.response.data
3274
+ : { message: String(error.response.data) };
3275
+ const apiError = new Error(responseData.message || error.message || 'Request failed');
3276
+ Object.assign(apiError, responseData);
3277
+ apiError.statusCode = (_d = error.response) === null || _d === void 0 ? void 0 : _d.status;
3278
+ throw apiError;
3273
3279
  }
3274
3280
  throw error;
3275
3281
  }
@@ -3334,6 +3340,40 @@ async function getConfig() {
3334
3340
  return clientConfig;
3335
3341
  }
3336
3342
 
3343
+ /******************************************************************************
3344
+ Copyright (c) Microsoft Corporation.
3345
+
3346
+ Permission to use, copy, modify, and/or distribute this software for any
3347
+ purpose with or without fee is hereby granted.
3348
+
3349
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3350
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3351
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3352
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3353
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3354
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3355
+ PERFORMANCE OF THIS SOFTWARE.
3356
+ ***************************************************************************** */
3357
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
3358
+
3359
+
3360
+ function __rest(s, e) {
3361
+ var t = {};
3362
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3363
+ t[p] = s[p];
3364
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3365
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3366
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3367
+ t[p[i]] = s[p[i]];
3368
+ }
3369
+ return t;
3370
+ }
3371
+
3372
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
3373
+ var e = new Error(message);
3374
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3375
+ };
3376
+
3337
3377
  // Cache for get responses
3338
3378
  const getCache = {};
3339
3379
  // Track in-flight requests to coalesce multiple identical requests
@@ -3431,11 +3471,11 @@ function cleanupExpiredCache() {
3431
3471
  });
3432
3472
  lastCacheCleanup = now;
3433
3473
  }
3434
- async function runQuery(absolutePath, queryName, queryArgs) {
3435
- const result = await runQueryMany([{ absolutePath, queryName, queryArgs }]);
3474
+ async function runQuery(absolutePath, queryName, queryArgs, opts) {
3475
+ const result = await runQueryMany([{ absolutePath, queryName, queryArgs }], opts);
3436
3476
  return result[0];
3437
3477
  }
3438
- async function runQueryMany(many) {
3478
+ async function runQueryMany(many, opts) {
3439
3479
  try {
3440
3480
  let queries = [];
3441
3481
  for (const { absolutePath, queryName, queryArgs } of many) {
@@ -3446,7 +3486,7 @@ async function runQueryMany(many) {
3446
3486
  }
3447
3487
  queries.push({ path: normalizedPath, queryName, queryArgs });
3448
3488
  }
3449
- const response = await makeApiRequest('POST', 'queries', { queries }, undefined);
3489
+ const response = await makeApiRequest('POST', 'queries', { queries }, opts === null || opts === void 0 ? void 0 : opts._overrides);
3450
3490
  return response.data.queries.map((result) => result.result);
3451
3491
  }
3452
3492
  catch (error) {
@@ -3551,7 +3591,7 @@ async function setMany(many, options) {
3551
3591
  // Sync items after all transactions are confirmed
3552
3592
  // Wait for 1.5 seconds to ensure all transactions are confirmed
3553
3593
  await new Promise(resolve => setTimeout(resolve, 1500));
3554
- await syncItems(many.map(m => m.path));
3594
+ await syncItems(many.map(m => m.path), options);
3555
3595
  // TODO: Should we wait here or do the optimistic subscription updates like below?
3556
3596
  return Object.assign(Object.assign({}, documents.map(d => d.document)), { transactionId: lastTxSignature, signedTransaction: signedTransaction });
3557
3597
  }
@@ -3563,6 +3603,12 @@ async function setMany(many, options) {
3563
3603
  if (setResponse.data === true) {
3564
3604
  return Object.assign(Object.assign({}, documents.map(d => d.document)), { transactionId: null });
3565
3605
  }
3606
+ else if (setResponse.data &&
3607
+ typeof setResponse.data === 'object' &&
3608
+ setResponse.data.success === true) {
3609
+ const _a = setResponse.data, { success: _success } = _a, rest = __rest(_a, ["success"]);
3610
+ return Object.assign(Object.assign(Object.assign({}, documents.map(d => d.document)), rest), { transactionId: null });
3611
+ }
3566
3612
  else {
3567
3613
  return Object.assign(Object.assign({}, setResponse.data), { transactionId: null });
3568
3614
  }
@@ -3770,9 +3816,9 @@ async function signAndSubmitTransaction(transaction, feePayer) {
3770
3816
  }
3771
3817
  return config.authProvider.signAndSubmitTransaction(transaction, feePayer);
3772
3818
  }
3773
- async function syncItems(paths) {
3819
+ async function syncItems(paths, options) {
3774
3820
  try {
3775
- const response = await makeApiRequest('PUT', 'items/sync', { paths }, undefined);
3821
+ const response = await makeApiRequest('PUT', 'items/sync', { paths }, options === null || options === void 0 ? void 0 : options._overrides);
3776
3822
  return response.data;
3777
3823
  }
3778
3824
  catch (error) {