@fractalshq/sync 0.0.3 → 0.0.5
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/dist/api-Cl-FACri.d.mts +204 -0
- package/dist/api-Cl-FACri.d.ts +204 -0
- package/dist/chunk-FWCSY2DS.mjs +37 -0
- package/dist/chunk-JZGD7RD2.mjs +498 -0
- package/dist/chunk-VXNOPXKB.mjs +249 -0
- package/dist/core/index.d.mts +19 -2
- package/dist/core/index.d.ts +19 -2
- package/dist/core/index.js +266 -2
- package/dist/core/index.mjs +38 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +270 -23
- package/dist/index.mjs +38 -4
- package/dist/react/index.d.mts +53 -10
- package/dist/react/index.d.ts +53 -10
- package/dist/react/index.js +339 -77
- package/dist/react/index.mjs +173 -87
- package/dist/server/index.d.mts +3 -3
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.mjs +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ApiAuthRequest, GET, POST, SyncHandlerOptions, SyncServerClient, SyncServerOptions, createMethodHandler, syncRouteHandler } from './server/index.js';
|
|
2
|
-
export { DEFAULT_RPC_ENDPOINT, DISTRIBUTION_MEMO_PREFIX, MEMO_PROGRAM_ID, XNET_2022_MINT, assertTruthy, buildDistributionMemoTag } from './core/index.js';
|
|
3
|
-
export {
|
|
2
|
+
export { DEFAULT_RPC_ENDPOINT, DISTRIBUTION_MEMO_PREFIX, MEMO_PROGRAM_ID, PERSISTENCE_WARNING_EVENT, PersistenceWarningRecord, XNET_2022_MINT, assertTruthy, buildDistributionMemoTag, clearPersistenceWarning, handlePersistenceWarningResponse, loadPersistenceWarnings, recordPersistenceWarning } from './core/index.js';
|
|
3
|
+
export { r as BuildClaimTransactionRequest, s as BuildClaimTransactionResponse, B as BuildDistributionTransactionRequest, m as BuildDistributionTransactionResponse, C as ClaimAllocation, e as ClaimCommitRequest, w as ClaimHistoryItem, x as ClaimHistoryResponse, b as ClaimTransactionInstruction, c as ClaimTransactionRequest, d as ClaimTransactionResponse, f as ClaimableDistribution, v as ClaimableResponse, t as CommitClaimRequest, u as CommitClaimResponse, o as CommitDistributionRequest, p as CommitDistributionResponse, q as CommitDistributionSignatureInput, l as CreateDistributionRequest, n as CreateDistributionResponse, G as DEFAULT_BASE_PATH, a as Distribution, i as DistributionInstruction, j as DistributionPersistenceWarning, h as DistributionRecipientInput, D as DistributionStatus, k as DistributionTransactionPayload, F as Fetcher, H as HealthResponse, L as ListDistributionsRequest, g as ListDistributionsResponse, P as PrepareDistributionDraftRequest, y as PrepareDistributionDraftResponse, K as SyncReactError, I as SyncRequestConfig, S as SyncRequestOptions, z as buildDistributionTransaction, Q as buildUrl, A as commitDistributionSignature, R as isAbsoluteUrl, T as isRelativeUrl, E as prepareDistributionDraft, M as requestJSON, N as resolveFetcher, J as resolveRequestConfig, O as sanitizeBasePath } from './api-Cl-FACri.js';
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,18 @@ var __spreadValues = (a, b) => {
|
|
|
20
20
|
return a;
|
|
21
21
|
};
|
|
22
22
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
23
35
|
var __export = (target, all) => {
|
|
24
36
|
for (var name in all)
|
|
25
37
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -37,16 +49,33 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
37
49
|
// src/index.ts
|
|
38
50
|
var index_exports = {};
|
|
39
51
|
__export(index_exports, {
|
|
52
|
+
DEFAULT_BASE_PATH: () => DEFAULT_BASE_PATH,
|
|
40
53
|
DEFAULT_RPC_ENDPOINT: () => DEFAULT_RPC_ENDPOINT,
|
|
41
54
|
DISTRIBUTION_MEMO_PREFIX: () => DISTRIBUTION_MEMO_PREFIX,
|
|
42
55
|
GET: () => GET,
|
|
43
56
|
MEMO_PROGRAM_ID: () => MEMO_PROGRAM_ID,
|
|
57
|
+
PERSISTENCE_WARNING_EVENT: () => PERSISTENCE_WARNING_EVENT,
|
|
44
58
|
POST: () => POST,
|
|
59
|
+
SyncReactError: () => SyncReactError,
|
|
45
60
|
SyncServerClient: () => SyncServerClient,
|
|
46
61
|
XNET_2022_MINT: () => XNET_2022_MINT,
|
|
47
62
|
assertTruthy: () => assertTruthy,
|
|
48
63
|
buildDistributionMemoTag: () => buildDistributionMemoTag,
|
|
64
|
+
buildDistributionTransaction: () => buildDistributionTransaction,
|
|
65
|
+
buildUrl: () => buildUrl,
|
|
66
|
+
clearPersistenceWarning: () => clearPersistenceWarning,
|
|
67
|
+
commitDistributionSignature: () => commitDistributionSignature,
|
|
49
68
|
createMethodHandler: () => createMethodHandler,
|
|
69
|
+
handlePersistenceWarningResponse: () => handlePersistenceWarningResponse,
|
|
70
|
+
isAbsoluteUrl: () => isAbsoluteUrl,
|
|
71
|
+
isRelativeUrl: () => isRelativeUrl,
|
|
72
|
+
loadPersistenceWarnings: () => loadPersistenceWarnings,
|
|
73
|
+
prepareDistributionDraft: () => prepareDistributionDraft,
|
|
74
|
+
recordPersistenceWarning: () => recordPersistenceWarning,
|
|
75
|
+
requestJSON: () => requestJSON,
|
|
76
|
+
resolveFetcher: () => resolveFetcher,
|
|
77
|
+
resolveRequestConfig: () => resolveRequestConfig,
|
|
78
|
+
sanitizeBasePath: () => sanitizeBasePath,
|
|
50
79
|
syncRouteHandler: () => syncRouteHandler
|
|
51
80
|
});
|
|
52
81
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -195,9 +224,9 @@ function normalizeRole(role) {
|
|
|
195
224
|
return String(role).trim().toLowerCase();
|
|
196
225
|
}
|
|
197
226
|
function resolveWalletFromMe(me) {
|
|
198
|
-
var
|
|
227
|
+
var _a2, _b2, _c, _d, _e;
|
|
199
228
|
if (!me || typeof me !== "object") return null;
|
|
200
|
-
const candidate = (me == null ? void 0 : me.wallet) || ((
|
|
229
|
+
const candidate = (me == null ? void 0 : me.wallet) || ((_a2 = me == null ? void 0 : me.user) == null ? void 0 : _a2.wallet) || ((_b2 = me == null ? void 0 : me.user) == null ? void 0 : _b2.pubkey) || ((_c = me == null ? void 0 : me.user) == null ? void 0 : _c.name) || ((_d = me == null ? void 0 : me.user) == null ? void 0 : _d.id) || null;
|
|
201
230
|
if (candidate && typeof candidate === "string" && candidate.length > 0) return candidate;
|
|
202
231
|
const accounts = Array.isArray(me == null ? void 0 : me.accounts) ? me.accounts : [];
|
|
203
232
|
const walletAccount = accounts.find((acct) => typeof (acct == null ? void 0 : acct.pubkey) === "string" && acct.pubkey.length > 0);
|
|
@@ -216,12 +245,12 @@ function requireDeployer(req) {
|
|
|
216
245
|
throw new SyncHandlerError(403, "forbidden_deployer_role");
|
|
217
246
|
}
|
|
218
247
|
function getSessionWallet(req) {
|
|
219
|
-
var
|
|
248
|
+
var _a2, _b2;
|
|
220
249
|
const direct = typeof req.wallet === "string" && req.wallet.length > 0 ? req.wallet : null;
|
|
221
250
|
if (direct) return direct;
|
|
222
|
-
const authWallet = typeof ((
|
|
251
|
+
const authWallet = typeof ((_a2 = req.apiAuth) == null ? void 0 : _a2.wallet) === "string" && req.apiAuth.wallet.length > 0 ? req.apiAuth.wallet : null;
|
|
223
252
|
if (authWallet) return authWallet;
|
|
224
|
-
return resolveWalletFromMe((
|
|
253
|
+
return resolveWalletFromMe((_b2 = req.apiAuth) == null ? void 0 : _b2.me);
|
|
225
254
|
}
|
|
226
255
|
function requireSessionWallet(req, expected) {
|
|
227
256
|
const wallet = getSessionWallet(req);
|
|
@@ -313,17 +342,17 @@ async function handleClaimBuild(ctx, distributionId) {
|
|
|
313
342
|
return Response.json(result);
|
|
314
343
|
}
|
|
315
344
|
async function handleClaimCommit(ctx, distributionId) {
|
|
316
|
-
var
|
|
345
|
+
var _a2, _b2, _c;
|
|
317
346
|
const body = await readJsonBody(ctx.req);
|
|
318
347
|
const explicitWallet = coerceString(body.claimantPubkey) || coerceString(body.claimant) || coerceString(body.wallet);
|
|
319
348
|
const claimant = requireSessionWallet(ctx.req, explicitWallet);
|
|
320
349
|
const payload = __spreadValues({}, body);
|
|
321
350
|
payload.distributionId = distributionId;
|
|
322
351
|
payload.claimantPubkey = claimant;
|
|
323
|
-
const signature = (
|
|
352
|
+
const signature = (_a2 = coerceString(payload.signature)) != null ? _a2 : coerceString(body.signature);
|
|
324
353
|
if (signature) payload.signature = signature;
|
|
325
354
|
const signedTransactionBase64 = coerceString(body.signedTransactionBase64);
|
|
326
|
-
const transaction = (_c = (
|
|
355
|
+
const transaction = (_c = (_b2 = coerceString(payload.transaction)) != null ? _b2 : coerceString(body.transaction)) != null ? _c : signedTransactionBase64;
|
|
327
356
|
if (transaction) payload.transaction = transaction;
|
|
328
357
|
if (signedTransactionBase64) payload.signedTransactionBase64 = signedTransactionBase64;
|
|
329
358
|
const hasSignature = typeof payload.signature === "string" && payload.signature.length > 0;
|
|
@@ -367,19 +396,19 @@ async function handleDistributionsRoute(ctx) {
|
|
|
367
396
|
|
|
368
397
|
// src/server/handler/me.ts
|
|
369
398
|
async function handleClaimsMeRoute(ctx) {
|
|
370
|
-
var
|
|
399
|
+
var _a2, _b2;
|
|
371
400
|
if (ctx.method !== "GET") return null;
|
|
372
401
|
if (ctx.segments.length > 0) return null;
|
|
373
402
|
requireLoggedIn(ctx.req);
|
|
374
|
-
const result = await ctx.client.getClaimsMe((
|
|
403
|
+
const result = await ctx.client.getClaimsMe((_b2 = (_a2 = ctx.url) == null ? void 0 : _a2.searchParams) != null ? _b2 : void 0);
|
|
375
404
|
return Response.json(result);
|
|
376
405
|
}
|
|
377
406
|
async function handleDistributionsMeRoute(ctx) {
|
|
378
|
-
var
|
|
407
|
+
var _a2, _b2;
|
|
379
408
|
if (ctx.method !== "GET") return null;
|
|
380
409
|
requireLoggedIn(ctx.req);
|
|
381
410
|
if (ctx.segments.length === 0) {
|
|
382
|
-
const result = await ctx.client.getDistributionsMe((
|
|
411
|
+
const result = await ctx.client.getDistributionsMe((_b2 = (_a2 = ctx.url) == null ? void 0 : _a2.searchParams) != null ? _b2 : void 0);
|
|
383
412
|
return Response.json(result);
|
|
384
413
|
}
|
|
385
414
|
if (ctx.segments.length === 1) {
|
|
@@ -394,7 +423,7 @@ async function handleDistributionsMeRoute(ctx) {
|
|
|
394
423
|
var ALLOWED_METHODS = /* @__PURE__ */ new Set(["GET", "POST"]);
|
|
395
424
|
var ALLOW_HEADER = "GET, POST";
|
|
396
425
|
async function syncRouteHandler(req, context = {}, options = {}) {
|
|
397
|
-
var
|
|
426
|
+
var _a2;
|
|
398
427
|
const method = (req.method || "GET").toUpperCase();
|
|
399
428
|
if (!ALLOWED_METHODS.has(method)) {
|
|
400
429
|
return new Response(JSON.stringify({ error: "method_not_allowed" }), {
|
|
@@ -407,7 +436,7 @@ async function syncRouteHandler(req, context = {}, options = {}) {
|
|
|
407
436
|
if (segments.length === 0) {
|
|
408
437
|
return notFound();
|
|
409
438
|
}
|
|
410
|
-
const logger = (
|
|
439
|
+
const logger = (_a2 = options.logger) != null ? _a2 : console;
|
|
411
440
|
let client;
|
|
412
441
|
try {
|
|
413
442
|
client = resolveClient(req, options);
|
|
@@ -457,9 +486,9 @@ function notFound() {
|
|
|
457
486
|
return Response.json({ error: "not_found" }, { status: 404 });
|
|
458
487
|
}
|
|
459
488
|
function resolveClient(req, options) {
|
|
460
|
-
var
|
|
489
|
+
var _a2, _b2, _c;
|
|
461
490
|
if (options.client) return options.client;
|
|
462
|
-
const baseURL = (_c = (
|
|
491
|
+
const baseURL = (_c = (_b2 = (_a2 = options.baseURL) != null ? _a2 : process.env.SYNC_BASE_URL) != null ? _b2 : process.env.NEXT_PUBLIC_SYNC_BASE_URL) != null ? _c : "";
|
|
463
492
|
if (!baseURL) {
|
|
464
493
|
throw new SyncHandlerError(500, "sync_base_url_missing", "SYNC_BASE_URL is not configured");
|
|
465
494
|
}
|
|
@@ -472,12 +501,12 @@ function resolveClient(req, options) {
|
|
|
472
501
|
return SyncServerClient.fromRequest(req, baseURL);
|
|
473
502
|
}
|
|
474
503
|
async function resolveSegments(req, context, url) {
|
|
475
|
-
var
|
|
504
|
+
var _a2;
|
|
476
505
|
const params = await resolveParams(context == null ? void 0 : context.params);
|
|
477
506
|
if (params == null ? void 0 : params.fractalsSync) {
|
|
478
507
|
return sanitizeSegments(params.fractalsSync);
|
|
479
508
|
}
|
|
480
|
-
const pathname = (
|
|
509
|
+
const pathname = (_a2 = url == null ? void 0 : url.pathname) != null ? _a2 : typeof req.url === "string" ? safePathname(req.url) : "";
|
|
481
510
|
if (!pathname) return [];
|
|
482
511
|
const parts = pathname.split("/").filter(Boolean);
|
|
483
512
|
if (parts.length === 0) return [];
|
|
@@ -488,10 +517,10 @@ async function resolveSegments(req, context, url) {
|
|
|
488
517
|
return [];
|
|
489
518
|
}
|
|
490
519
|
async function resolveParams(params) {
|
|
491
|
-
var
|
|
520
|
+
var _a2;
|
|
492
521
|
if (!params) return null;
|
|
493
522
|
if (typeof (params == null ? void 0 : params.then) === "function") {
|
|
494
|
-
return (
|
|
523
|
+
return (_a2 = await params) != null ? _a2 : null;
|
|
495
524
|
}
|
|
496
525
|
return params != null ? params : null;
|
|
497
526
|
}
|
|
@@ -518,14 +547,14 @@ function safePathname(url) {
|
|
|
518
547
|
}
|
|
519
548
|
}
|
|
520
549
|
async function handleError(error, req, options, logger) {
|
|
521
|
-
var
|
|
550
|
+
var _a2, _b2;
|
|
522
551
|
if (error instanceof SyncHandlerError) {
|
|
523
552
|
if (error.code === "unauthorized" && options.onUnauthorized) {
|
|
524
553
|
try {
|
|
525
554
|
const custom = await options.onUnauthorized(req);
|
|
526
555
|
if (custom) return custom;
|
|
527
556
|
} catch (hookError) {
|
|
528
|
-
(
|
|
557
|
+
(_a2 = logger == null ? void 0 : logger.warn) == null ? void 0 : _a2.call(logger, "[syncRouteHandler] onUnauthorized hook failed", hookError);
|
|
529
558
|
}
|
|
530
559
|
}
|
|
531
560
|
const payload = { error: error.code };
|
|
@@ -533,7 +562,7 @@ async function handleError(error, req, options, logger) {
|
|
|
533
562
|
if (error.details !== void 0) payload.details = error.details;
|
|
534
563
|
return Response.json(payload, { status: error.status });
|
|
535
564
|
}
|
|
536
|
-
(
|
|
565
|
+
(_b2 = logger == null ? void 0 : logger.error) == null ? void 0 : _b2.call(logger, "[syncRouteHandler] unhandled_error", error);
|
|
537
566
|
return Response.json({ error: "sync_handler_error" }, { status: 500 });
|
|
538
567
|
}
|
|
539
568
|
|
|
@@ -553,17 +582,235 @@ function assertTruthy(value, message) {
|
|
|
553
582
|
}
|
|
554
583
|
return value;
|
|
555
584
|
}
|
|
585
|
+
|
|
586
|
+
// src/core/persistence.ts
|
|
587
|
+
var STORAGE_PREFIX = "distribution:persistence-warning:";
|
|
588
|
+
var PERSISTENCE_WARNING_EVENT = "distribution:persistence-warning";
|
|
589
|
+
function isBrowser() {
|
|
590
|
+
return typeof window !== "undefined" && typeof localStorage !== "undefined";
|
|
591
|
+
}
|
|
592
|
+
function persistToStorage(record) {
|
|
593
|
+
if (!isBrowser()) return;
|
|
594
|
+
try {
|
|
595
|
+
localStorage.setItem(`${STORAGE_PREFIX}${record.id}`, JSON.stringify(record));
|
|
596
|
+
} catch (error) {
|
|
597
|
+
console.error("[sync:persistence-warning] Failed to write to localStorage", error);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function emitWarning(record) {
|
|
601
|
+
if (!isBrowser()) return;
|
|
602
|
+
try {
|
|
603
|
+
window.dispatchEvent(new CustomEvent(PERSISTENCE_WARNING_EVENT, { detail: record }));
|
|
604
|
+
} catch (error) {
|
|
605
|
+
console.error("[sync:persistence-warning] Failed to emit warning event", error);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function recordPersistenceWarning(input) {
|
|
609
|
+
var _a2;
|
|
610
|
+
if (!isBrowser()) return void 0;
|
|
611
|
+
const record = __spreadProps(__spreadValues({}, input), {
|
|
612
|
+
createdAt: (_a2 = input.createdAt) != null ? _a2 : Date.now()
|
|
613
|
+
});
|
|
614
|
+
persistToStorage(record);
|
|
615
|
+
emitWarning(record);
|
|
616
|
+
return record;
|
|
617
|
+
}
|
|
618
|
+
function handlePersistenceWarningResponse(response) {
|
|
619
|
+
var _a2;
|
|
620
|
+
if (!isBrowser() || !response || typeof response !== "object") return;
|
|
621
|
+
const warning = response.persistenceWarning;
|
|
622
|
+
if (!warning) return;
|
|
623
|
+
const distributionId = warning.distributionId || response.distributionId || "unknown";
|
|
624
|
+
const exportJson = (_a2 = response.exportJson) != null ? _a2 : warning.exportJson;
|
|
625
|
+
const reason = warning.reason || "persist_distribution_failed";
|
|
626
|
+
const message = warning.message || "We were unable to save your distribution draft. Download the JSON to avoid data loss.";
|
|
627
|
+
const key = warning.id || `${distributionId}:${reason}:${Date.now()}`;
|
|
628
|
+
recordPersistenceWarning({
|
|
629
|
+
id: key,
|
|
630
|
+
distributionId,
|
|
631
|
+
reason,
|
|
632
|
+
message,
|
|
633
|
+
detail: warning.detail,
|
|
634
|
+
exportJson
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
function loadPersistenceWarnings() {
|
|
638
|
+
if (!isBrowser()) return [];
|
|
639
|
+
const records = [];
|
|
640
|
+
try {
|
|
641
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
642
|
+
const key = localStorage.key(i);
|
|
643
|
+
if (!key || !key.startsWith(STORAGE_PREFIX)) continue;
|
|
644
|
+
const raw = localStorage.getItem(key);
|
|
645
|
+
if (!raw) continue;
|
|
646
|
+
try {
|
|
647
|
+
const parsed = JSON.parse(raw);
|
|
648
|
+
if (parsed && typeof parsed === "object") {
|
|
649
|
+
records.push(parsed);
|
|
650
|
+
}
|
|
651
|
+
} catch (e) {
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
} catch (error) {
|
|
655
|
+
console.error("[sync:persistence-warning] Failed to load warnings", error);
|
|
656
|
+
}
|
|
657
|
+
return records.sort((a, b) => b.createdAt - a.createdAt);
|
|
658
|
+
}
|
|
659
|
+
function clearPersistenceWarning(id) {
|
|
660
|
+
if (!isBrowser()) return;
|
|
661
|
+
try {
|
|
662
|
+
localStorage.removeItem(`${STORAGE_PREFIX}${id}`);
|
|
663
|
+
} catch (e) {
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// src/core/http.ts
|
|
668
|
+
var FALLBACK_BASE_PATH = "/api/v1/fractals-sync";
|
|
669
|
+
var _a, _b;
|
|
670
|
+
var ENV_BASE_PATH = typeof process !== "undefined" && (((_a = process.env) == null ? void 0 : _a.NEXT_PUBLIC_SYNC_PATH) || ((_b = process.env) == null ? void 0 : _b.NEXT_PUBLIC_FRACTALS_SYNC_PATH)) || void 0;
|
|
671
|
+
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
|
672
|
+
function resolveRequestConfig(options) {
|
|
673
|
+
return {
|
|
674
|
+
basePath: sanitizeBasePath((options == null ? void 0 : options.basePath) || DEFAULT_BASE_PATH),
|
|
675
|
+
fetcher: resolveFetcher(options == null ? void 0 : options.fetcher)
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
var SyncReactError = class extends Error {
|
|
679
|
+
constructor(status, code, details) {
|
|
680
|
+
super(code || `Sync request failed with status ${status}`);
|
|
681
|
+
this.status = status;
|
|
682
|
+
this.code = code;
|
|
683
|
+
this.details = details;
|
|
684
|
+
this.name = "SyncReactError";
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
async function requestJSON(config, path, init) {
|
|
688
|
+
var _a2;
|
|
689
|
+
const url = buildUrl(config.basePath, path);
|
|
690
|
+
const requestInit = prepareInit(init);
|
|
691
|
+
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 : isRelativeUrl(url) ? "include" : void 0;
|
|
692
|
+
const response = await config.fetcher(url, requestInit);
|
|
693
|
+
const payload = await parseResponseBody(response);
|
|
694
|
+
if (!response.ok) {
|
|
695
|
+
const errorCode = typeof payload === "object" && payload && "error" in payload ? String(payload.error) : void 0;
|
|
696
|
+
throw new SyncReactError(response.status, errorCode, payload);
|
|
697
|
+
}
|
|
698
|
+
return payload;
|
|
699
|
+
}
|
|
700
|
+
function resolveFetcher(custom) {
|
|
701
|
+
if (custom) return custom;
|
|
702
|
+
if (typeof fetch === "function") return fetch.bind(globalThis);
|
|
703
|
+
throw new Error("Global fetch is not available. Provide a fetcher via Sync configuration.");
|
|
704
|
+
}
|
|
705
|
+
function sanitizeBasePath(path) {
|
|
706
|
+
if (!path) return FALLBACK_BASE_PATH;
|
|
707
|
+
const trimmed = path.trim();
|
|
708
|
+
if (!trimmed || trimmed === "/") return "/";
|
|
709
|
+
return trimmed.replace(/\/+$/, "");
|
|
710
|
+
}
|
|
711
|
+
function buildUrl(basePath, path) {
|
|
712
|
+
if (path && isAbsoluteUrl(path)) return path;
|
|
713
|
+
const normalizedBase = sanitizeBasePath(basePath);
|
|
714
|
+
const suffix = path ? `/${path.replace(/^\/+/, "")}` : "";
|
|
715
|
+
if (!normalizedBase || normalizedBase === "/") {
|
|
716
|
+
return suffix ? suffix : normalizedBase;
|
|
717
|
+
}
|
|
718
|
+
return `${normalizedBase}${suffix}`;
|
|
719
|
+
}
|
|
720
|
+
function isAbsoluteUrl(path) {
|
|
721
|
+
return /^https?:\/\//i.test(path);
|
|
722
|
+
}
|
|
723
|
+
function isRelativeUrl(path) {
|
|
724
|
+
return !isAbsoluteUrl(path);
|
|
725
|
+
}
|
|
726
|
+
function prepareInit(init) {
|
|
727
|
+
const finalInit = __spreadValues({}, init);
|
|
728
|
+
if ((init == null ? void 0 : init.headers) instanceof Headers) {
|
|
729
|
+
const cloned = new Headers(init.headers);
|
|
730
|
+
if (!cloned.has("content-type")) cloned.set("content-type", "application/json");
|
|
731
|
+
finalInit.headers = cloned;
|
|
732
|
+
return finalInit;
|
|
733
|
+
}
|
|
734
|
+
const headers = new Headers(init == null ? void 0 : init.headers);
|
|
735
|
+
if (!headers.has("content-type")) {
|
|
736
|
+
headers.set("content-type", "application/json");
|
|
737
|
+
}
|
|
738
|
+
finalInit.headers = headers;
|
|
739
|
+
return finalInit;
|
|
740
|
+
}
|
|
741
|
+
async function parseResponseBody(response) {
|
|
742
|
+
if (response.status === 204) return void 0;
|
|
743
|
+
const text = await response.text();
|
|
744
|
+
if (!text) return void 0;
|
|
745
|
+
try {
|
|
746
|
+
return JSON.parse(text);
|
|
747
|
+
} catch (e) {
|
|
748
|
+
return text;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// src/core/api.ts
|
|
753
|
+
async function buildDistributionTransaction(input, options) {
|
|
754
|
+
const config = resolveRequestConfig(options);
|
|
755
|
+
const path = (input == null ? void 0 : input.distributionId) ? `/distributions/${encodeURIComponent(input.distributionId)}/create-transaction` : "/distributions/create-transaction";
|
|
756
|
+
const payload = await requestJSON(config, path, {
|
|
757
|
+
method: "POST",
|
|
758
|
+
body: JSON.stringify(input)
|
|
759
|
+
});
|
|
760
|
+
handlePersistenceWarningResponse(payload);
|
|
761
|
+
return payload;
|
|
762
|
+
}
|
|
763
|
+
async function commitDistributionSignature(input, options) {
|
|
764
|
+
const distributionId = input == null ? void 0 : input.distributionId;
|
|
765
|
+
if (!distributionId) {
|
|
766
|
+
throw new SyncReactError(400, "distribution_id_required");
|
|
767
|
+
}
|
|
768
|
+
const config = resolveRequestConfig(options);
|
|
769
|
+
const _a2 = input, { distributionId: _unused } = _a2, body = __objRest(_a2, ["distributionId"]);
|
|
770
|
+
return requestJSON(
|
|
771
|
+
config,
|
|
772
|
+
`/distributions/${encodeURIComponent(distributionId)}/commit`,
|
|
773
|
+
{
|
|
774
|
+
method: "POST",
|
|
775
|
+
body: JSON.stringify(body)
|
|
776
|
+
}
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
async function prepareDistributionDraft(input, options) {
|
|
780
|
+
const config = resolveRequestConfig(options);
|
|
781
|
+
return requestJSON(config, "/distributions/prepare", {
|
|
782
|
+
method: "POST",
|
|
783
|
+
body: JSON.stringify(input)
|
|
784
|
+
});
|
|
785
|
+
}
|
|
556
786
|
// Annotate the CommonJS export names for ESM import in node:
|
|
557
787
|
0 && (module.exports = {
|
|
788
|
+
DEFAULT_BASE_PATH,
|
|
558
789
|
DEFAULT_RPC_ENDPOINT,
|
|
559
790
|
DISTRIBUTION_MEMO_PREFIX,
|
|
560
791
|
GET,
|
|
561
792
|
MEMO_PROGRAM_ID,
|
|
793
|
+
PERSISTENCE_WARNING_EVENT,
|
|
562
794
|
POST,
|
|
795
|
+
SyncReactError,
|
|
563
796
|
SyncServerClient,
|
|
564
797
|
XNET_2022_MINT,
|
|
565
798
|
assertTruthy,
|
|
566
799
|
buildDistributionMemoTag,
|
|
800
|
+
buildDistributionTransaction,
|
|
801
|
+
buildUrl,
|
|
802
|
+
clearPersistenceWarning,
|
|
803
|
+
commitDistributionSignature,
|
|
567
804
|
createMethodHandler,
|
|
805
|
+
handlePersistenceWarningResponse,
|
|
806
|
+
isAbsoluteUrl,
|
|
807
|
+
isRelativeUrl,
|
|
808
|
+
loadPersistenceWarnings,
|
|
809
|
+
prepareDistributionDraft,
|
|
810
|
+
recordPersistenceWarning,
|
|
811
|
+
requestJSON,
|
|
812
|
+
resolveFetcher,
|
|
813
|
+
resolveRequestConfig,
|
|
814
|
+
sanitizeBasePath,
|
|
568
815
|
syncRouteHandler
|
|
569
816
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,29 +1,63 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_BASE_PATH,
|
|
2
3
|
DEFAULT_RPC_ENDPOINT,
|
|
3
4
|
DISTRIBUTION_MEMO_PREFIX,
|
|
4
5
|
MEMO_PROGRAM_ID,
|
|
6
|
+
PERSISTENCE_WARNING_EVENT,
|
|
7
|
+
SyncReactError,
|
|
5
8
|
XNET_2022_MINT,
|
|
6
9
|
assertTruthy,
|
|
7
|
-
buildDistributionMemoTag
|
|
8
|
-
|
|
10
|
+
buildDistributionMemoTag,
|
|
11
|
+
buildDistributionTransaction,
|
|
12
|
+
buildUrl,
|
|
13
|
+
clearPersistenceWarning,
|
|
14
|
+
commitDistributionSignature,
|
|
15
|
+
handlePersistenceWarningResponse,
|
|
16
|
+
isAbsoluteUrl,
|
|
17
|
+
isRelativeUrl,
|
|
18
|
+
loadPersistenceWarnings,
|
|
19
|
+
prepareDistributionDraft,
|
|
20
|
+
recordPersistenceWarning,
|
|
21
|
+
requestJSON,
|
|
22
|
+
resolveFetcher,
|
|
23
|
+
resolveRequestConfig,
|
|
24
|
+
sanitizeBasePath
|
|
25
|
+
} from "./chunk-VXNOPXKB.mjs";
|
|
9
26
|
import {
|
|
10
27
|
GET,
|
|
11
28
|
POST,
|
|
12
29
|
SyncServerClient,
|
|
13
30
|
createMethodHandler,
|
|
14
31
|
syncRouteHandler
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
32
|
+
} from "./chunk-JZGD7RD2.mjs";
|
|
33
|
+
import "./chunk-FWCSY2DS.mjs";
|
|
17
34
|
export {
|
|
35
|
+
DEFAULT_BASE_PATH,
|
|
18
36
|
DEFAULT_RPC_ENDPOINT,
|
|
19
37
|
DISTRIBUTION_MEMO_PREFIX,
|
|
20
38
|
GET,
|
|
21
39
|
MEMO_PROGRAM_ID,
|
|
40
|
+
PERSISTENCE_WARNING_EVENT,
|
|
22
41
|
POST,
|
|
42
|
+
SyncReactError,
|
|
23
43
|
SyncServerClient,
|
|
24
44
|
XNET_2022_MINT,
|
|
25
45
|
assertTruthy,
|
|
26
46
|
buildDistributionMemoTag,
|
|
47
|
+
buildDistributionTransaction,
|
|
48
|
+
buildUrl,
|
|
49
|
+
clearPersistenceWarning,
|
|
50
|
+
commitDistributionSignature,
|
|
27
51
|
createMethodHandler,
|
|
52
|
+
handlePersistenceWarningResponse,
|
|
53
|
+
isAbsoluteUrl,
|
|
54
|
+
isRelativeUrl,
|
|
55
|
+
loadPersistenceWarnings,
|
|
56
|
+
prepareDistributionDraft,
|
|
57
|
+
recordPersistenceWarning,
|
|
58
|
+
requestJSON,
|
|
59
|
+
resolveFetcher,
|
|
60
|
+
resolveRequestConfig,
|
|
61
|
+
sanitizeBasePath,
|
|
28
62
|
syncRouteHandler
|
|
29
63
|
};
|
package/dist/react/index.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
|
|
4
|
-
import { g as ListDistributionsResponse, a as Distribution,
|
|
4
|
+
import { F as Fetcher, g as ListDistributionsResponse, K as SyncReactError, a as Distribution, B as BuildDistributionTransactionRequest, k as DistributionTransactionPayload, q as CommitDistributionSignatureInput, p as CommitDistributionResponse, v as ClaimableResponse, x as ClaimHistoryResponse, r as BuildClaimTransactionRequest, s as BuildClaimTransactionResponse, t as CommitClaimRequest, u as CommitClaimResponse } from '../api-Cl-FACri.mjs';
|
|
5
5
|
|
|
6
|
-
type Fetcher = typeof fetch;
|
|
7
6
|
interface SyncContextValue {
|
|
8
7
|
basePath: string;
|
|
9
8
|
fetcher?: Fetcher;
|
|
@@ -21,20 +20,64 @@ interface SyncClient {
|
|
|
21
20
|
post<T>(path: string, body?: unknown, init?: RequestInit): Promise<T>;
|
|
22
21
|
}
|
|
23
22
|
declare function useSyncClient(): SyncClient;
|
|
24
|
-
declare class SyncReactError extends Error {
|
|
25
|
-
readonly status: number;
|
|
26
|
-
readonly code?: string | undefined;
|
|
27
|
-
readonly details?: unknown | undefined;
|
|
28
|
-
constructor(status: number, code?: string | undefined, details?: unknown | undefined);
|
|
29
|
-
}
|
|
30
23
|
type QueryOptions<T> = Omit<UseQueryOptions<T, SyncReactError, T>, "queryKey" | "queryFn">;
|
|
31
|
-
|
|
24
|
+
interface DistributionsQueryParams {
|
|
25
|
+
role?: "claimant" | "creator";
|
|
26
|
+
status?: string | null;
|
|
27
|
+
}
|
|
28
|
+
declare function useDistributions<TResponse = ListDistributionsResponse>(paramsOrOptions?: DistributionsQueryParams | QueryOptions<TResponse>, optionsMaybe?: QueryOptions<TResponse>): UseQueryResult<TResponse, SyncReactError>;
|
|
32
29
|
declare function useDistribution<TResponse = Distribution>(distributionId: string | null | undefined, options?: QueryOptions<TResponse>): UseQueryResult<TResponse, SyncReactError>;
|
|
30
|
+
type DistributionTransactionInput = BuildDistributionTransactionRequest;
|
|
31
|
+
declare function useDistributionTransaction(options?: UseMutationOptions<DistributionTransactionPayload, SyncReactError, DistributionTransactionInput>): UseMutationResult<DistributionTransactionPayload, SyncReactError, DistributionTransactionInput>;
|
|
32
|
+
type DistributionCommitInput = CommitDistributionSignatureInput;
|
|
33
|
+
declare function useCommitDistribution(options?: UseMutationOptions<CommitDistributionResponse, SyncReactError, DistributionCommitInput>): UseMutationResult<CommitDistributionResponse, SyncReactError, DistributionCommitInput>;
|
|
34
|
+
interface DistributionFlowState {
|
|
35
|
+
latestPayload: DistributionTransactionPayload | null;
|
|
36
|
+
building: boolean;
|
|
37
|
+
committing: boolean;
|
|
38
|
+
error: SyncReactError | null;
|
|
39
|
+
}
|
|
40
|
+
type DistributionFlowSignerInput = Partial<Omit<CommitDistributionSignatureInput, "distributionId">> & {
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
};
|
|
43
|
+
type DistributionFlowSigner = (payload: DistributionTransactionPayload) => Promise<DistributionFlowSignerInput> | DistributionFlowSignerInput;
|
|
44
|
+
interface DistributionFlowCommitResult {
|
|
45
|
+
payload: DistributionTransactionPayload;
|
|
46
|
+
commit: CommitDistributionResponse;
|
|
47
|
+
signerInput: DistributionFlowSignerInput;
|
|
48
|
+
}
|
|
49
|
+
interface DistributionFlowResult {
|
|
50
|
+
state: DistributionFlowState;
|
|
51
|
+
build: (input: DistributionTransactionInput) => Promise<DistributionTransactionPayload>;
|
|
52
|
+
commit: (signer: DistributionFlowSigner, input?: DistributionTransactionInput) => Promise<DistributionFlowCommitResult>;
|
|
53
|
+
claim: (signer: DistributionFlowSigner, input?: DistributionTransactionInput) => Promise<DistributionFlowCommitResult>;
|
|
54
|
+
reset: () => void;
|
|
55
|
+
}
|
|
56
|
+
declare function useDistributionFlow(): DistributionFlowResult;
|
|
33
57
|
declare function useClaimableDistributions<TResponse = ClaimableResponse>(options?: QueryOptions<TResponse>): UseQueryResult<TResponse, SyncReactError>;
|
|
34
58
|
declare function useClaimHistory<TResponse = ClaimHistoryResponse>(options?: QueryOptions<TResponse>): UseQueryResult<TResponse, SyncReactError>;
|
|
35
59
|
type ClaimTransactionInput = Partial<Omit<BuildClaimTransactionRequest, "distributionId" | "claimant">>;
|
|
36
60
|
declare function useClaimTransaction(distributionId: string | null | undefined, options?: UseMutationOptions<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>): UseMutationResult<BuildClaimTransactionResponse, SyncReactError, ClaimTransactionInput>;
|
|
37
61
|
type ClaimCommitInput = Omit<CommitClaimRequest, "distributionId">;
|
|
38
62
|
declare function useCommitClaim(distributionId: string | null | undefined, options?: UseMutationOptions<CommitClaimResponse, SyncReactError, ClaimCommitInput>): UseMutationResult<CommitClaimResponse, SyncReactError, ClaimCommitInput>;
|
|
63
|
+
interface ClaimFlowState {
|
|
64
|
+
latestPayload: BuildClaimTransactionResponse | null;
|
|
65
|
+
building: boolean;
|
|
66
|
+
claiming: boolean;
|
|
67
|
+
error: SyncReactError | null;
|
|
68
|
+
}
|
|
69
|
+
type ClaimFlowSigner = (payload: BuildClaimTransactionResponse) => Promise<ClaimCommitInput> | ClaimCommitInput;
|
|
70
|
+
interface ClaimFlowClaimResult {
|
|
71
|
+
payload: BuildClaimTransactionResponse;
|
|
72
|
+
commit: CommitClaimResponse;
|
|
73
|
+
signerInput: ClaimCommitInput;
|
|
74
|
+
}
|
|
75
|
+
interface ClaimFlowResult {
|
|
76
|
+
state: ClaimFlowState;
|
|
77
|
+
build: (input?: ClaimTransactionInput) => Promise<BuildClaimTransactionResponse>;
|
|
78
|
+
claim: (signer: ClaimFlowSigner, input?: ClaimTransactionInput) => Promise<ClaimFlowClaimResult>;
|
|
79
|
+
reset: () => void;
|
|
80
|
+
}
|
|
81
|
+
declare function useClaimFlow(distributionId: string | null | undefined): ClaimFlowResult;
|
|
39
82
|
|
|
40
|
-
export { type ClaimCommitInput, type ClaimTransactionInput, type SyncClient, SyncProvider, type SyncProviderProps,
|
|
83
|
+
export { type ClaimCommitInput, type ClaimFlowClaimResult, type ClaimFlowResult, type ClaimFlowSigner, type ClaimFlowState, type ClaimTransactionInput, type DistributionCommitInput, type DistributionFlowCommitResult, type DistributionFlowResult, type DistributionFlowSigner, type DistributionFlowSignerInput, type DistributionFlowState, type DistributionTransactionInput, type DistributionsQueryParams, type SyncClient, SyncProvider, type SyncProviderProps, useClaimFlow, useClaimHistory, useClaimTransaction, useClaimableDistributions, useCommitClaim, useCommitDistribution, useDistribution, useDistributionFlow, useDistributionTransaction, useDistributions, useSyncClient };
|