@fractalshq/sync 0.1.1 → 0.1.2
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 +28 -1
- package/dist/chunk-4VKCXC52.mjs +129 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/v1/index.mjs +7 -7
- package/dist/v2/core/index.js +1 -1
- package/dist/v2/core/index.mjs +1 -1
- package/dist/v2/index.js +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/react/index.js +1 -1
- package/dist/v2/react/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,8 +58,35 @@ const buildTx = useClaimTransaction();
|
|
|
58
58
|
buildTx.mutateAsync({ distributionId, claimant: wallet });
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
### UI-only flow (bring your own signer)
|
|
62
|
+
|
|
63
|
+
V2 is build-only: it returns a transaction payload and you wire signing/sending yourself.
|
|
64
|
+
Show the signature optimistically, then rely on eventual consistency for history.
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { useClaimTransaction } from "@fractalshq/sync/v2/react";
|
|
68
|
+
|
|
69
|
+
const buildTx = useClaimTransaction();
|
|
70
|
+
|
|
71
|
+
async function handleClaim(item: { distributorId: string }, wallet: string) {
|
|
72
|
+
const payload = await buildTx.mutateAsync({
|
|
73
|
+
distributionId: item.distributorId,
|
|
74
|
+
claimant: wallet,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// App-owned: build a Transaction from payload.transaction (base64) or payload.instructions.
|
|
78
|
+
const tx = buildTransactionFromPayload(payload);
|
|
79
|
+
const signed = await signTransaction(tx);
|
|
80
|
+
const signature = await connection.sendRawTransaction(signed.serialize());
|
|
81
|
+
|
|
82
|
+
// UI-owned: optimistic link + pending state until the next refresh.
|
|
83
|
+
setOptimisticSignature(signature);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
61
87
|
Notes:
|
|
62
|
-
- Default base path is
|
|
88
|
+
- Default base path is `https://sync.fractals.fun/api/v2` (override via `NEXT_PUBLIC_SYNC_V2_PATH`).
|
|
89
|
+
- For other environments, set `NEXT_PUBLIC_SYNC_V2_PATH` to an absolute `/api/v2` base URL.
|
|
63
90
|
- V2 requests are `credentials: "omit"` for public CORS mode.
|
|
64
91
|
- If `wallet` is omitted, `useClaims` falls back to the Solana wallet adapter context (`@solana/wallet-adapter-react`).
|
|
65
92
|
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__objRest,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "./chunk-FWCSY2DS.mjs";
|
|
5
|
+
|
|
6
|
+
// src/v2/core/http.ts
|
|
7
|
+
var FALLBACK_BASE_PATH = "https://sync.fractals.fun/api/v2";
|
|
8
|
+
var _a, _b;
|
|
9
|
+
var ENV_BASE_PATH = typeof process !== "undefined" && (((_a = process.env) == null ? void 0 : _a.NEXT_PUBLIC_SYNC_V2_PATH) || ((_b = process.env) == null ? void 0 : _b.NEXT_PUBLIC_FRACTALS_SYNC_V2_PATH)) || void 0;
|
|
10
|
+
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
|
11
|
+
function resolveRequestConfig(options) {
|
|
12
|
+
return {
|
|
13
|
+
basePath: sanitizeBasePath((options == null ? void 0 : options.basePath) || DEFAULT_BASE_PATH),
|
|
14
|
+
fetcher: resolveFetcher(options == null ? void 0 : options.fetcher)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
var SyncReactError = class extends Error {
|
|
18
|
+
constructor(status, code, details) {
|
|
19
|
+
super(code || `Sync request failed with status ${status}`);
|
|
20
|
+
this.status = status;
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.details = details;
|
|
23
|
+
this.name = "SyncReactError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
async function requestJSON(config, path, init) {
|
|
27
|
+
var _a2;
|
|
28
|
+
const url = buildUrl(config.basePath, path);
|
|
29
|
+
const requestInit = prepareInit(init);
|
|
30
|
+
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 : "omit";
|
|
31
|
+
const response = await config.fetcher(url, requestInit);
|
|
32
|
+
const payload = await parseResponseBody(response);
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
const errorCode = typeof payload === "object" && payload && "error" in payload ? String(payload.error) : void 0;
|
|
35
|
+
throw new SyncReactError(response.status, errorCode, payload);
|
|
36
|
+
}
|
|
37
|
+
return payload;
|
|
38
|
+
}
|
|
39
|
+
function resolveFetcher(custom) {
|
|
40
|
+
if (custom) return custom;
|
|
41
|
+
if (typeof fetch === "function") return fetch.bind(globalThis);
|
|
42
|
+
throw new Error("Global fetch is not available. Provide a fetcher via Sync configuration.");
|
|
43
|
+
}
|
|
44
|
+
function sanitizeBasePath(path) {
|
|
45
|
+
if (!path) return FALLBACK_BASE_PATH;
|
|
46
|
+
const trimmed = path.trim();
|
|
47
|
+
if (!trimmed || trimmed === "/") return "/";
|
|
48
|
+
return trimmed.replace(/\/+$/, "");
|
|
49
|
+
}
|
|
50
|
+
function buildUrl(basePath, path) {
|
|
51
|
+
if (path && isAbsoluteUrl(path)) return path;
|
|
52
|
+
const normalizedBase = sanitizeBasePath(basePath);
|
|
53
|
+
const suffix = path ? `/${path.replace(/^\/+/, "")}` : "";
|
|
54
|
+
if (!normalizedBase || normalizedBase === "/") {
|
|
55
|
+
return suffix ? suffix : normalizedBase;
|
|
56
|
+
}
|
|
57
|
+
return `${normalizedBase}${suffix}`;
|
|
58
|
+
}
|
|
59
|
+
function isAbsoluteUrl(path) {
|
|
60
|
+
return /^https?:\/\//i.test(path);
|
|
61
|
+
}
|
|
62
|
+
function isRelativeUrl(path) {
|
|
63
|
+
return !isAbsoluteUrl(path);
|
|
64
|
+
}
|
|
65
|
+
function prepareInit(init) {
|
|
66
|
+
const finalInit = __spreadValues({}, init);
|
|
67
|
+
if ((init == null ? void 0 : init.headers) instanceof Headers) {
|
|
68
|
+
const cloned = new Headers(init.headers);
|
|
69
|
+
if (!cloned.has("content-type")) cloned.set("content-type", "application/json");
|
|
70
|
+
finalInit.headers = cloned;
|
|
71
|
+
return finalInit;
|
|
72
|
+
}
|
|
73
|
+
const headers = new Headers(init == null ? void 0 : init.headers);
|
|
74
|
+
if (!headers.has("content-type")) {
|
|
75
|
+
headers.set("content-type", "application/json");
|
|
76
|
+
}
|
|
77
|
+
finalInit.headers = headers;
|
|
78
|
+
return finalInit;
|
|
79
|
+
}
|
|
80
|
+
async function parseResponseBody(response) {
|
|
81
|
+
if (response.status === 204) return void 0;
|
|
82
|
+
const text = await response.text();
|
|
83
|
+
if (!text) return void 0;
|
|
84
|
+
try {
|
|
85
|
+
return JSON.parse(text);
|
|
86
|
+
} catch (e) {
|
|
87
|
+
return text;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/v2/core/api.ts
|
|
92
|
+
async function buildClaimTransaction(input, options) {
|
|
93
|
+
const distributionId = input == null ? void 0 : input.distributionId;
|
|
94
|
+
if (!distributionId) {
|
|
95
|
+
throw new SyncReactError(400, "distribution_id_required");
|
|
96
|
+
}
|
|
97
|
+
const config = resolveRequestConfig(options);
|
|
98
|
+
const _a2 = input, { distributionId: _unused } = _a2, body = __objRest(_a2, ["distributionId"]);
|
|
99
|
+
return requestJSON(
|
|
100
|
+
config,
|
|
101
|
+
`/claims/${encodeURIComponent(distributionId)}/create-transaction`,
|
|
102
|
+
{
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: JSON.stringify(body)
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
async function listClaims(wallet, options) {
|
|
109
|
+
if (!wallet) {
|
|
110
|
+
throw new SyncReactError(400, "wallet_required");
|
|
111
|
+
}
|
|
112
|
+
const config = resolveRequestConfig(options);
|
|
113
|
+
const qs = new URLSearchParams({ wallet }).toString();
|
|
114
|
+
return requestJSON(config, `/claims?${qs}`, { method: "GET" });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
DEFAULT_BASE_PATH,
|
|
119
|
+
resolveRequestConfig,
|
|
120
|
+
SyncReactError,
|
|
121
|
+
requestJSON,
|
|
122
|
+
resolveFetcher,
|
|
123
|
+
sanitizeBasePath,
|
|
124
|
+
buildUrl,
|
|
125
|
+
isAbsoluteUrl,
|
|
126
|
+
isRelativeUrl,
|
|
127
|
+
buildClaimTransaction,
|
|
128
|
+
listClaims
|
|
129
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ __export(index_exports, {
|
|
|
61
61
|
module.exports = __toCommonJS(index_exports);
|
|
62
62
|
|
|
63
63
|
// src/v2/core/http.ts
|
|
64
|
-
var FALLBACK_BASE_PATH = "/api/v2";
|
|
64
|
+
var FALLBACK_BASE_PATH = "https://sync.fractals.fun/api/v2";
|
|
65
65
|
var _a, _b;
|
|
66
66
|
var ENV_BASE_PATH = typeof process !== "undefined" && (((_a = process.env) == null ? void 0 : _a.NEXT_PUBLIC_SYNC_V2_PATH) || ((_b = process.env) == null ? void 0 : _b.NEXT_PUBLIC_FRACTALS_SYNC_V2_PATH)) || void 0;
|
|
67
67
|
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
package/dist/index.mjs
CHANGED
package/dist/v1/index.mjs
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GET,
|
|
3
|
+
POST,
|
|
4
|
+
SyncServerClient,
|
|
5
|
+
createMethodHandler,
|
|
6
|
+
syncRouteHandler
|
|
7
|
+
} from "../chunk-ZIWHYEXE.mjs";
|
|
1
8
|
import {
|
|
2
9
|
DEFAULT_BASE_PATH,
|
|
3
10
|
DEFAULT_RPC_ENDPOINT,
|
|
@@ -23,13 +30,6 @@ import {
|
|
|
23
30
|
resolveRequestConfig,
|
|
24
31
|
sanitizeBasePath
|
|
25
32
|
} from "../chunk-FBL2T6BA.mjs";
|
|
26
|
-
import {
|
|
27
|
-
GET,
|
|
28
|
-
POST,
|
|
29
|
-
SyncServerClient,
|
|
30
|
-
createMethodHandler,
|
|
31
|
-
syncRouteHandler
|
|
32
|
-
} from "../chunk-ZIWHYEXE.mjs";
|
|
33
33
|
import "../chunk-FWCSY2DS.mjs";
|
|
34
34
|
export {
|
|
35
35
|
DEFAULT_BASE_PATH,
|
package/dist/v2/core/index.js
CHANGED
|
@@ -61,7 +61,7 @@ __export(core_exports, {
|
|
|
61
61
|
module.exports = __toCommonJS(core_exports);
|
|
62
62
|
|
|
63
63
|
// src/v2/core/http.ts
|
|
64
|
-
var FALLBACK_BASE_PATH = "/api/v2";
|
|
64
|
+
var FALLBACK_BASE_PATH = "https://sync.fractals.fun/api/v2";
|
|
65
65
|
var _a, _b;
|
|
66
66
|
var ENV_BASE_PATH = typeof process !== "undefined" && (((_a = process.env) == null ? void 0 : _a.NEXT_PUBLIC_SYNC_V2_PATH) || ((_b = process.env) == null ? void 0 : _b.NEXT_PUBLIC_FRACTALS_SYNC_V2_PATH)) || void 0;
|
|
67
67
|
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
package/dist/v2/core/index.mjs
CHANGED
package/dist/v2/index.js
CHANGED
|
@@ -61,7 +61,7 @@ __export(v2_exports, {
|
|
|
61
61
|
module.exports = __toCommonJS(v2_exports);
|
|
62
62
|
|
|
63
63
|
// src/v2/core/http.ts
|
|
64
|
-
var FALLBACK_BASE_PATH = "/api/v2";
|
|
64
|
+
var FALLBACK_BASE_PATH = "https://sync.fractals.fun/api/v2";
|
|
65
65
|
var _a, _b;
|
|
66
66
|
var ENV_BASE_PATH = typeof process !== "undefined" && (((_a = process.env) == null ? void 0 : _a.NEXT_PUBLIC_SYNC_V2_PATH) || ((_b = process.env) == null ? void 0 : _b.NEXT_PUBLIC_FRACTALS_SYNC_V2_PATH)) || void 0;
|
|
67
67
|
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
package/dist/v2/index.mjs
CHANGED
package/dist/v2/react/index.js
CHANGED
|
@@ -60,7 +60,7 @@ var import_wallet_adapter_react = require("@solana/wallet-adapter-react");
|
|
|
60
60
|
var import_react_query = require("@tanstack/react-query");
|
|
61
61
|
|
|
62
62
|
// src/v2/core/http.ts
|
|
63
|
-
var FALLBACK_BASE_PATH = "/api/v2";
|
|
63
|
+
var FALLBACK_BASE_PATH = "https://sync.fractals.fun/api/v2";
|
|
64
64
|
var _a, _b;
|
|
65
65
|
var ENV_BASE_PATH = typeof process !== "undefined" && (((_a = process.env) == null ? void 0 : _a.NEXT_PUBLIC_SYNC_V2_PATH) || ((_b = process.env) == null ? void 0 : _b.NEXT_PUBLIC_FRACTALS_SYNC_V2_PATH)) || void 0;
|
|
66
66
|
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
package/dist/v2/react/index.mjs
CHANGED