@fractalshq/sync 0.0.1
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 +24 -0
- package/dist/api-CQqyHbnT.d.mts +136 -0
- package/dist/api-CQqyHbnT.d.ts +136 -0
- package/dist/chunk-I4E63NIC.mjs +24 -0
- package/dist/chunk-N3276DIZ.mjs +480 -0
- package/dist/chunk-TCJM2GIK.mjs +25 -0
- package/dist/core/index.d.mts +11 -0
- package/dist/core/index.d.ts +11 -0
- package/dist/core/index.js +56 -0
- package/dist/core/index.mjs +17 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +551 -0
- package/dist/index.mjs +29 -0
- package/dist/react/index.d.mts +40 -0
- package/dist/react/index.d.ts +40 -0
- package/dist/react/index.js +227 -0
- package/dist/react/index.mjs +182 -0
- package/dist/server/index.d.mts +67 -0
- package/dist/server/index.d.ts +67 -0
- package/dist/server/index.js +522 -0
- package/dist/server/index.mjs +15 -0
- package/dist/widgets/index.d.mts +2 -0
- package/dist/widgets/index.d.ts +2 -0
- package/dist/widgets/index.js +18 -0
- package/dist/widgets/index.mjs +0 -0
- package/package.json +92 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
|
|
37
|
+
// src/react/index.tsx
|
|
38
|
+
var react_exports = {};
|
|
39
|
+
__export(react_exports, {
|
|
40
|
+
SyncProvider: () => SyncProvider,
|
|
41
|
+
SyncReactError: () => SyncReactError,
|
|
42
|
+
useClaimHistory: () => useClaimHistory,
|
|
43
|
+
useClaimTransaction: () => useClaimTransaction,
|
|
44
|
+
useClaimableDistributions: () => useClaimableDistributions,
|
|
45
|
+
useCommitClaim: () => useCommitClaim,
|
|
46
|
+
useDistribution: () => useDistribution,
|
|
47
|
+
useDistributions: () => useDistributions,
|
|
48
|
+
useSyncClient: () => useSyncClient
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(react_exports);
|
|
51
|
+
var import_react = require("react");
|
|
52
|
+
var import_react_query = require("@tanstack/react-query");
|
|
53
|
+
var FALLBACK_BASE_PATH = "/api/v1/fractals-sync";
|
|
54
|
+
var _a, _b;
|
|
55
|
+
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;
|
|
56
|
+
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
|
57
|
+
var SyncContext = (0, import_react.createContext)({ basePath: DEFAULT_BASE_PATH });
|
|
58
|
+
function SyncProvider({ basePath, fetcher, children }) {
|
|
59
|
+
const value = (0, import_react.useMemo)(
|
|
60
|
+
() => ({
|
|
61
|
+
basePath: sanitizeBasePath(basePath || DEFAULT_BASE_PATH),
|
|
62
|
+
fetcher
|
|
63
|
+
}),
|
|
64
|
+
[basePath, fetcher]
|
|
65
|
+
);
|
|
66
|
+
return (0, import_react.createElement)(SyncContext.Provider, { value }, children);
|
|
67
|
+
}
|
|
68
|
+
function useSyncClient() {
|
|
69
|
+
const context = (0, import_react.useContext)(SyncContext);
|
|
70
|
+
const basePath = sanitizeBasePath((context == null ? void 0 : context.basePath) || DEFAULT_BASE_PATH);
|
|
71
|
+
const fetcher = resolveFetcher(context == null ? void 0 : context.fetcher);
|
|
72
|
+
return (0, import_react.useMemo)(() => {
|
|
73
|
+
const request = (path, init) => requestJSON({ basePath, fetcher }, path, init);
|
|
74
|
+
return {
|
|
75
|
+
basePath,
|
|
76
|
+
request,
|
|
77
|
+
get: (path, init) => request(path, __spreadProps(__spreadValues({}, init), { method: "GET" })),
|
|
78
|
+
post: (path, body, init) => {
|
|
79
|
+
const finalInit = __spreadProps(__spreadValues({}, init), { method: ((init == null ? void 0 : init.method) || "POST").toUpperCase() });
|
|
80
|
+
if (body !== void 0) {
|
|
81
|
+
finalInit.body = typeof body === "string" ? body : JSON.stringify(body);
|
|
82
|
+
}
|
|
83
|
+
return request(path, finalInit);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}, [basePath, fetcher]);
|
|
87
|
+
}
|
|
88
|
+
var SyncReactError = class extends Error {
|
|
89
|
+
constructor(status, code, details) {
|
|
90
|
+
super(code || `Sync request failed with status ${status}`);
|
|
91
|
+
this.status = status;
|
|
92
|
+
this.code = code;
|
|
93
|
+
this.details = details;
|
|
94
|
+
this.name = "SyncReactError";
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function useDistributions(options) {
|
|
98
|
+
const client = useSyncClient();
|
|
99
|
+
return (0, import_react_query.useQuery)(__spreadValues({
|
|
100
|
+
queryKey: ["sync", "distributions", "me"],
|
|
101
|
+
queryFn: () => client.get("/distributions/me")
|
|
102
|
+
}, options));
|
|
103
|
+
}
|
|
104
|
+
function useDistribution(distributionId, options) {
|
|
105
|
+
var _a2;
|
|
106
|
+
const client = useSyncClient();
|
|
107
|
+
const id = distributionId ? encodeURIComponent(distributionId) : "";
|
|
108
|
+
return (0, import_react_query.useQuery)(__spreadProps(__spreadValues({
|
|
109
|
+
queryKey: ["sync", "distribution", id],
|
|
110
|
+
queryFn: () => client.get(`/distributions/me/${id}`)
|
|
111
|
+
}, options), {
|
|
112
|
+
enabled: Boolean(id) && ((_a2 = options == null ? void 0 : options.enabled) != null ? _a2 : true)
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
function useClaimableDistributions(options) {
|
|
116
|
+
const client = useSyncClient();
|
|
117
|
+
return (0, import_react_query.useQuery)(__spreadValues({
|
|
118
|
+
queryKey: ["sync", "claims", "me"],
|
|
119
|
+
queryFn: () => client.get("/claims/me")
|
|
120
|
+
}, options));
|
|
121
|
+
}
|
|
122
|
+
function useClaimHistory(options) {
|
|
123
|
+
const client = useSyncClient();
|
|
124
|
+
return (0, import_react_query.useQuery)(__spreadValues({
|
|
125
|
+
queryKey: ["sync", "claims", "history"],
|
|
126
|
+
queryFn: () => client.get("/claims/history")
|
|
127
|
+
}, options));
|
|
128
|
+
}
|
|
129
|
+
function useClaimTransaction(distributionId, options) {
|
|
130
|
+
const client = useSyncClient();
|
|
131
|
+
const id = distributionId ? encodeURIComponent(distributionId) : null;
|
|
132
|
+
return (0, import_react_query.useMutation)(__spreadValues({
|
|
133
|
+
mutationFn: async (input = {}) => {
|
|
134
|
+
if (!id) throw new SyncReactError(400, "distribution_id_required");
|
|
135
|
+
return client.post(`/claims/${id}/create-transaction`, input);
|
|
136
|
+
}
|
|
137
|
+
}, options));
|
|
138
|
+
}
|
|
139
|
+
function useCommitClaim(distributionId, options) {
|
|
140
|
+
const client = useSyncClient();
|
|
141
|
+
const id = distributionId ? encodeURIComponent(distributionId) : null;
|
|
142
|
+
return (0, import_react_query.useMutation)(__spreadValues({
|
|
143
|
+
mutationFn: async (input) => {
|
|
144
|
+
if (!id) throw new SyncReactError(400, "distribution_id_required");
|
|
145
|
+
if (!input || !input.signature && !input.transaction && !input.signedTransactionBase64) {
|
|
146
|
+
throw new SyncReactError(400, "transaction_or_signature_required");
|
|
147
|
+
}
|
|
148
|
+
return client.post(`/claims/${id}/commit`, input);
|
|
149
|
+
}
|
|
150
|
+
}, options));
|
|
151
|
+
}
|
|
152
|
+
async function requestJSON(config, path, init) {
|
|
153
|
+
var _a2;
|
|
154
|
+
const url = buildUrl(config.basePath, path);
|
|
155
|
+
const requestInit = prepareInit(init);
|
|
156
|
+
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 : isRelativeUrl(url) ? "include" : void 0;
|
|
157
|
+
const response = await config.fetcher(url, requestInit);
|
|
158
|
+
const payload = await parseResponseBody(response);
|
|
159
|
+
if (!response.ok) {
|
|
160
|
+
const errorCode = typeof payload === "object" && payload && "error" in payload ? String(payload.error) : void 0;
|
|
161
|
+
throw new SyncReactError(response.status, errorCode, payload);
|
|
162
|
+
}
|
|
163
|
+
return payload;
|
|
164
|
+
}
|
|
165
|
+
function prepareInit(init) {
|
|
166
|
+
const finalInit = __spreadValues({}, init);
|
|
167
|
+
if ((init == null ? void 0 : init.headers) instanceof Headers) {
|
|
168
|
+
const cloned = new Headers(init.headers);
|
|
169
|
+
if (!cloned.has("content-type")) cloned.set("content-type", "application/json");
|
|
170
|
+
finalInit.headers = cloned;
|
|
171
|
+
return finalInit;
|
|
172
|
+
}
|
|
173
|
+
const headers = new Headers(init == null ? void 0 : init.headers);
|
|
174
|
+
if (!headers.has("content-type")) {
|
|
175
|
+
headers.set("content-type", "application/json");
|
|
176
|
+
}
|
|
177
|
+
finalInit.headers = headers;
|
|
178
|
+
return finalInit;
|
|
179
|
+
}
|
|
180
|
+
async function parseResponseBody(response) {
|
|
181
|
+
if (response.status === 204) return void 0;
|
|
182
|
+
const text = await response.text();
|
|
183
|
+
if (!text) return void 0;
|
|
184
|
+
try {
|
|
185
|
+
return JSON.parse(text);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
return text;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function resolveFetcher(custom) {
|
|
191
|
+
if (custom) return custom;
|
|
192
|
+
if (typeof fetch === "function") return fetch.bind(globalThis);
|
|
193
|
+
throw new Error("Global fetch is not available. Provide a fetcher via <SyncProvider fetcher={...}>.");
|
|
194
|
+
}
|
|
195
|
+
function sanitizeBasePath(path) {
|
|
196
|
+
if (!path) return FALLBACK_BASE_PATH;
|
|
197
|
+
const trimmed = path.trim();
|
|
198
|
+
if (!trimmed || trimmed === "/") return "/";
|
|
199
|
+
return trimmed.replace(/\/+$/, "");
|
|
200
|
+
}
|
|
201
|
+
function buildUrl(basePath, path) {
|
|
202
|
+
if (path && isAbsoluteUrl(path)) return path;
|
|
203
|
+
const normalizedBase = sanitizeBasePath(basePath);
|
|
204
|
+
const suffix = path ? `/${path.replace(/^\/+/, "")}` : "";
|
|
205
|
+
if (!normalizedBase || normalizedBase === "/") {
|
|
206
|
+
return suffix ? suffix : normalizedBase;
|
|
207
|
+
}
|
|
208
|
+
return `${normalizedBase}${suffix}`;
|
|
209
|
+
}
|
|
210
|
+
function isAbsoluteUrl(path) {
|
|
211
|
+
return /^https?:\/\//i.test(path);
|
|
212
|
+
}
|
|
213
|
+
function isRelativeUrl(path) {
|
|
214
|
+
return !isAbsoluteUrl(path);
|
|
215
|
+
}
|
|
216
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
217
|
+
0 && (module.exports = {
|
|
218
|
+
SyncProvider,
|
|
219
|
+
SyncReactError,
|
|
220
|
+
useClaimHistory,
|
|
221
|
+
useClaimTransaction,
|
|
222
|
+
useClaimableDistributions,
|
|
223
|
+
useCommitClaim,
|
|
224
|
+
useDistribution,
|
|
225
|
+
useDistributions,
|
|
226
|
+
useSyncClient
|
|
227
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadProps,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "../chunk-I4E63NIC.mjs";
|
|
5
|
+
|
|
6
|
+
// src/react/index.tsx
|
|
7
|
+
import { createContext, createElement, useContext, useMemo } from "react";
|
|
8
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
9
|
+
var FALLBACK_BASE_PATH = "/api/v1/fractals-sync";
|
|
10
|
+
var _a, _b;
|
|
11
|
+
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;
|
|
12
|
+
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
|
13
|
+
var SyncContext = createContext({ basePath: DEFAULT_BASE_PATH });
|
|
14
|
+
function SyncProvider({ basePath, fetcher, children }) {
|
|
15
|
+
const value = useMemo(
|
|
16
|
+
() => ({
|
|
17
|
+
basePath: sanitizeBasePath(basePath || DEFAULT_BASE_PATH),
|
|
18
|
+
fetcher
|
|
19
|
+
}),
|
|
20
|
+
[basePath, fetcher]
|
|
21
|
+
);
|
|
22
|
+
return createElement(SyncContext.Provider, { value }, children);
|
|
23
|
+
}
|
|
24
|
+
function useSyncClient() {
|
|
25
|
+
const context = useContext(SyncContext);
|
|
26
|
+
const basePath = sanitizeBasePath((context == null ? void 0 : context.basePath) || DEFAULT_BASE_PATH);
|
|
27
|
+
const fetcher = resolveFetcher(context == null ? void 0 : context.fetcher);
|
|
28
|
+
return useMemo(() => {
|
|
29
|
+
const request = (path, init) => requestJSON({ basePath, fetcher }, path, init);
|
|
30
|
+
return {
|
|
31
|
+
basePath,
|
|
32
|
+
request,
|
|
33
|
+
get: (path, init) => request(path, __spreadProps(__spreadValues({}, init), { method: "GET" })),
|
|
34
|
+
post: (path, body, init) => {
|
|
35
|
+
const finalInit = __spreadProps(__spreadValues({}, init), { method: ((init == null ? void 0 : init.method) || "POST").toUpperCase() });
|
|
36
|
+
if (body !== void 0) {
|
|
37
|
+
finalInit.body = typeof body === "string" ? body : JSON.stringify(body);
|
|
38
|
+
}
|
|
39
|
+
return request(path, finalInit);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}, [basePath, fetcher]);
|
|
43
|
+
}
|
|
44
|
+
var SyncReactError = class extends Error {
|
|
45
|
+
constructor(status, code, details) {
|
|
46
|
+
super(code || `Sync request failed with status ${status}`);
|
|
47
|
+
this.status = status;
|
|
48
|
+
this.code = code;
|
|
49
|
+
this.details = details;
|
|
50
|
+
this.name = "SyncReactError";
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
function useDistributions(options) {
|
|
54
|
+
const client = useSyncClient();
|
|
55
|
+
return useQuery(__spreadValues({
|
|
56
|
+
queryKey: ["sync", "distributions", "me"],
|
|
57
|
+
queryFn: () => client.get("/distributions/me")
|
|
58
|
+
}, options));
|
|
59
|
+
}
|
|
60
|
+
function useDistribution(distributionId, options) {
|
|
61
|
+
var _a2;
|
|
62
|
+
const client = useSyncClient();
|
|
63
|
+
const id = distributionId ? encodeURIComponent(distributionId) : "";
|
|
64
|
+
return useQuery(__spreadProps(__spreadValues({
|
|
65
|
+
queryKey: ["sync", "distribution", id],
|
|
66
|
+
queryFn: () => client.get(`/distributions/me/${id}`)
|
|
67
|
+
}, options), {
|
|
68
|
+
enabled: Boolean(id) && ((_a2 = options == null ? void 0 : options.enabled) != null ? _a2 : true)
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
function useClaimableDistributions(options) {
|
|
72
|
+
const client = useSyncClient();
|
|
73
|
+
return useQuery(__spreadValues({
|
|
74
|
+
queryKey: ["sync", "claims", "me"],
|
|
75
|
+
queryFn: () => client.get("/claims/me")
|
|
76
|
+
}, options));
|
|
77
|
+
}
|
|
78
|
+
function useClaimHistory(options) {
|
|
79
|
+
const client = useSyncClient();
|
|
80
|
+
return useQuery(__spreadValues({
|
|
81
|
+
queryKey: ["sync", "claims", "history"],
|
|
82
|
+
queryFn: () => client.get("/claims/history")
|
|
83
|
+
}, options));
|
|
84
|
+
}
|
|
85
|
+
function useClaimTransaction(distributionId, options) {
|
|
86
|
+
const client = useSyncClient();
|
|
87
|
+
const id = distributionId ? encodeURIComponent(distributionId) : null;
|
|
88
|
+
return useMutation(__spreadValues({
|
|
89
|
+
mutationFn: async (input = {}) => {
|
|
90
|
+
if (!id) throw new SyncReactError(400, "distribution_id_required");
|
|
91
|
+
return client.post(`/claims/${id}/create-transaction`, input);
|
|
92
|
+
}
|
|
93
|
+
}, options));
|
|
94
|
+
}
|
|
95
|
+
function useCommitClaim(distributionId, options) {
|
|
96
|
+
const client = useSyncClient();
|
|
97
|
+
const id = distributionId ? encodeURIComponent(distributionId) : null;
|
|
98
|
+
return useMutation(__spreadValues({
|
|
99
|
+
mutationFn: async (input) => {
|
|
100
|
+
if (!id) throw new SyncReactError(400, "distribution_id_required");
|
|
101
|
+
if (!input || !input.signature && !input.transaction && !input.signedTransactionBase64) {
|
|
102
|
+
throw new SyncReactError(400, "transaction_or_signature_required");
|
|
103
|
+
}
|
|
104
|
+
return client.post(`/claims/${id}/commit`, input);
|
|
105
|
+
}
|
|
106
|
+
}, options));
|
|
107
|
+
}
|
|
108
|
+
async function requestJSON(config, path, init) {
|
|
109
|
+
var _a2;
|
|
110
|
+
const url = buildUrl(config.basePath, path);
|
|
111
|
+
const requestInit = prepareInit(init);
|
|
112
|
+
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 : isRelativeUrl(url) ? "include" : void 0;
|
|
113
|
+
const response = await config.fetcher(url, requestInit);
|
|
114
|
+
const payload = await parseResponseBody(response);
|
|
115
|
+
if (!response.ok) {
|
|
116
|
+
const errorCode = typeof payload === "object" && payload && "error" in payload ? String(payload.error) : void 0;
|
|
117
|
+
throw new SyncReactError(response.status, errorCode, payload);
|
|
118
|
+
}
|
|
119
|
+
return payload;
|
|
120
|
+
}
|
|
121
|
+
function prepareInit(init) {
|
|
122
|
+
const finalInit = __spreadValues({}, init);
|
|
123
|
+
if ((init == null ? void 0 : init.headers) instanceof Headers) {
|
|
124
|
+
const cloned = new Headers(init.headers);
|
|
125
|
+
if (!cloned.has("content-type")) cloned.set("content-type", "application/json");
|
|
126
|
+
finalInit.headers = cloned;
|
|
127
|
+
return finalInit;
|
|
128
|
+
}
|
|
129
|
+
const headers = new Headers(init == null ? void 0 : init.headers);
|
|
130
|
+
if (!headers.has("content-type")) {
|
|
131
|
+
headers.set("content-type", "application/json");
|
|
132
|
+
}
|
|
133
|
+
finalInit.headers = headers;
|
|
134
|
+
return finalInit;
|
|
135
|
+
}
|
|
136
|
+
async function parseResponseBody(response) {
|
|
137
|
+
if (response.status === 204) return void 0;
|
|
138
|
+
const text = await response.text();
|
|
139
|
+
if (!text) return void 0;
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(text);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
return text;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function resolveFetcher(custom) {
|
|
147
|
+
if (custom) return custom;
|
|
148
|
+
if (typeof fetch === "function") return fetch.bind(globalThis);
|
|
149
|
+
throw new Error("Global fetch is not available. Provide a fetcher via <SyncProvider fetcher={...}>.");
|
|
150
|
+
}
|
|
151
|
+
function sanitizeBasePath(path) {
|
|
152
|
+
if (!path) return FALLBACK_BASE_PATH;
|
|
153
|
+
const trimmed = path.trim();
|
|
154
|
+
if (!trimmed || trimmed === "/") return "/";
|
|
155
|
+
return trimmed.replace(/\/+$/, "");
|
|
156
|
+
}
|
|
157
|
+
function buildUrl(basePath, path) {
|
|
158
|
+
if (path && isAbsoluteUrl(path)) return path;
|
|
159
|
+
const normalizedBase = sanitizeBasePath(basePath);
|
|
160
|
+
const suffix = path ? `/${path.replace(/^\/+/, "")}` : "";
|
|
161
|
+
if (!normalizedBase || normalizedBase === "/") {
|
|
162
|
+
return suffix ? suffix : normalizedBase;
|
|
163
|
+
}
|
|
164
|
+
return `${normalizedBase}${suffix}`;
|
|
165
|
+
}
|
|
166
|
+
function isAbsoluteUrl(path) {
|
|
167
|
+
return /^https?:\/\//i.test(path);
|
|
168
|
+
}
|
|
169
|
+
function isRelativeUrl(path) {
|
|
170
|
+
return !isAbsoluteUrl(path);
|
|
171
|
+
}
|
|
172
|
+
export {
|
|
173
|
+
SyncProvider,
|
|
174
|
+
SyncReactError,
|
|
175
|
+
useClaimHistory,
|
|
176
|
+
useClaimTransaction,
|
|
177
|
+
useClaimableDistributions,
|
|
178
|
+
useCommitClaim,
|
|
179
|
+
useDistribution,
|
|
180
|
+
useDistributions,
|
|
181
|
+
useSyncClient
|
|
182
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { L as ListDistributionsRequest, g as ListDistributionsResponse, h as CreateDistributionRequest, i as CreateDistributionResponse, j as CommitDistributionRequest, k as CommitDistributionResponse, B as BuildClaimTransactionRequest, d as ClaimTransactionResponse, m as CommitClaimRequest, n as CommitClaimResponse, o as ClaimableResponse, a as Distribution, q as ClaimHistoryResponse, H as HealthResponse } from '../api-CQqyHbnT.mjs';
|
|
2
|
+
|
|
3
|
+
type QueryInit = string | URLSearchParams | Record<string, string | number | boolean | null | undefined>;
|
|
4
|
+
type HeaderInjector = () => Promise<HeadersInit> | HeadersInit;
|
|
5
|
+
interface SyncServerOptions {
|
|
6
|
+
baseURL: string;
|
|
7
|
+
getHeaders?: HeaderInjector;
|
|
8
|
+
}
|
|
9
|
+
declare class SyncServerClient {
|
|
10
|
+
private readonly options;
|
|
11
|
+
constructor(options: SyncServerOptions);
|
|
12
|
+
static fromRequest(req: Request, baseURL?: string): SyncServerClient;
|
|
13
|
+
static fromApiKey(apiKey: string | null, baseURL?: string): SyncServerClient;
|
|
14
|
+
private request;
|
|
15
|
+
private buildQueryString;
|
|
16
|
+
private withQuery;
|
|
17
|
+
listDistributions(params?: ListDistributionsRequest): Promise<ListDistributionsResponse>;
|
|
18
|
+
createDistribution(body: CreateDistributionRequest): Promise<CreateDistributionResponse>;
|
|
19
|
+
createDistributionWithId(distributionId: string, body: CreateDistributionRequest): Promise<CreateDistributionResponse>;
|
|
20
|
+
commitDistribution(distributionId: string, body: CommitDistributionRequest): Promise<CommitDistributionResponse>;
|
|
21
|
+
buildClaimTransaction(body: BuildClaimTransactionRequest): Promise<ClaimTransactionResponse>;
|
|
22
|
+
commitClaim(body: CommitClaimRequest): Promise<CommitClaimResponse>;
|
|
23
|
+
getClaimable(): Promise<ClaimableResponse>;
|
|
24
|
+
getClaimsMe(query?: QueryInit): Promise<ClaimableResponse>;
|
|
25
|
+
getDistributionsMe<T = ListDistributionsResponse>(query?: QueryInit): Promise<T>;
|
|
26
|
+
getDistributionMeById<T = Distribution>(distributionId: string): Promise<T>;
|
|
27
|
+
getClaimHistory(): Promise<ClaimHistoryResponse>;
|
|
28
|
+
health(): Promise<HealthResponse>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ApiAuthContext {
|
|
32
|
+
ok?: boolean;
|
|
33
|
+
orgId?: string | null;
|
|
34
|
+
orgRole?: string | null;
|
|
35
|
+
subjectId?: string | null;
|
|
36
|
+
wallet?: string | null;
|
|
37
|
+
platformId?: string | null;
|
|
38
|
+
platformRole?: string | null;
|
|
39
|
+
token?: string | null;
|
|
40
|
+
me?: unknown;
|
|
41
|
+
}
|
|
42
|
+
interface ApiAuthRequest extends Request {
|
|
43
|
+
apiAuth?: ApiAuthContext | null;
|
|
44
|
+
wallet?: string | null;
|
|
45
|
+
nextUrl?: URL;
|
|
46
|
+
}
|
|
47
|
+
interface SyncRouteParams {
|
|
48
|
+
fractalsSync?: string[];
|
|
49
|
+
}
|
|
50
|
+
interface SyncRouteHandlerContext {
|
|
51
|
+
params?: SyncRouteParams | Promise<SyncRouteParams>;
|
|
52
|
+
}
|
|
53
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
54
|
+
interface SyncHandlerOptions {
|
|
55
|
+
baseURL?: string;
|
|
56
|
+
client?: SyncServerClient;
|
|
57
|
+
getHeadersFromRequest?: (req: ApiAuthRequest) => MaybePromise<HeadersInit>;
|
|
58
|
+
onUnauthorized?: (req: Request) => MaybePromise<Response>;
|
|
59
|
+
logger?: Pick<Console, "error" | "warn" | "info">;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare function syncRouteHandler(req: ApiAuthRequest, context?: SyncRouteHandlerContext, options?: SyncHandlerOptions): Promise<Response>;
|
|
63
|
+
declare function createMethodHandler(method: "GET" | "POST"): (req: ApiAuthRequest, context?: SyncRouteHandlerContext, options?: SyncHandlerOptions) => Response | Promise<Response>;
|
|
64
|
+
declare const GET: (req: ApiAuthRequest, context?: SyncRouteHandlerContext, options?: SyncHandlerOptions) => Response | Promise<Response>;
|
|
65
|
+
declare const POST: (req: ApiAuthRequest, context?: SyncRouteHandlerContext, options?: SyncHandlerOptions) => Response | Promise<Response>;
|
|
66
|
+
|
|
67
|
+
export { type ApiAuthRequest, GET, POST, type SyncHandlerOptions, SyncServerClient, type SyncServerOptions, createMethodHandler, syncRouteHandler };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { L as ListDistributionsRequest, g as ListDistributionsResponse, h as CreateDistributionRequest, i as CreateDistributionResponse, j as CommitDistributionRequest, k as CommitDistributionResponse, B as BuildClaimTransactionRequest, d as ClaimTransactionResponse, m as CommitClaimRequest, n as CommitClaimResponse, o as ClaimableResponse, a as Distribution, q as ClaimHistoryResponse, H as HealthResponse } from '../api-CQqyHbnT.js';
|
|
2
|
+
|
|
3
|
+
type QueryInit = string | URLSearchParams | Record<string, string | number | boolean | null | undefined>;
|
|
4
|
+
type HeaderInjector = () => Promise<HeadersInit> | HeadersInit;
|
|
5
|
+
interface SyncServerOptions {
|
|
6
|
+
baseURL: string;
|
|
7
|
+
getHeaders?: HeaderInjector;
|
|
8
|
+
}
|
|
9
|
+
declare class SyncServerClient {
|
|
10
|
+
private readonly options;
|
|
11
|
+
constructor(options: SyncServerOptions);
|
|
12
|
+
static fromRequest(req: Request, baseURL?: string): SyncServerClient;
|
|
13
|
+
static fromApiKey(apiKey: string | null, baseURL?: string): SyncServerClient;
|
|
14
|
+
private request;
|
|
15
|
+
private buildQueryString;
|
|
16
|
+
private withQuery;
|
|
17
|
+
listDistributions(params?: ListDistributionsRequest): Promise<ListDistributionsResponse>;
|
|
18
|
+
createDistribution(body: CreateDistributionRequest): Promise<CreateDistributionResponse>;
|
|
19
|
+
createDistributionWithId(distributionId: string, body: CreateDistributionRequest): Promise<CreateDistributionResponse>;
|
|
20
|
+
commitDistribution(distributionId: string, body: CommitDistributionRequest): Promise<CommitDistributionResponse>;
|
|
21
|
+
buildClaimTransaction(body: BuildClaimTransactionRequest): Promise<ClaimTransactionResponse>;
|
|
22
|
+
commitClaim(body: CommitClaimRequest): Promise<CommitClaimResponse>;
|
|
23
|
+
getClaimable(): Promise<ClaimableResponse>;
|
|
24
|
+
getClaimsMe(query?: QueryInit): Promise<ClaimableResponse>;
|
|
25
|
+
getDistributionsMe<T = ListDistributionsResponse>(query?: QueryInit): Promise<T>;
|
|
26
|
+
getDistributionMeById<T = Distribution>(distributionId: string): Promise<T>;
|
|
27
|
+
getClaimHistory(): Promise<ClaimHistoryResponse>;
|
|
28
|
+
health(): Promise<HealthResponse>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ApiAuthContext {
|
|
32
|
+
ok?: boolean;
|
|
33
|
+
orgId?: string | null;
|
|
34
|
+
orgRole?: string | null;
|
|
35
|
+
subjectId?: string | null;
|
|
36
|
+
wallet?: string | null;
|
|
37
|
+
platformId?: string | null;
|
|
38
|
+
platformRole?: string | null;
|
|
39
|
+
token?: string | null;
|
|
40
|
+
me?: unknown;
|
|
41
|
+
}
|
|
42
|
+
interface ApiAuthRequest extends Request {
|
|
43
|
+
apiAuth?: ApiAuthContext | null;
|
|
44
|
+
wallet?: string | null;
|
|
45
|
+
nextUrl?: URL;
|
|
46
|
+
}
|
|
47
|
+
interface SyncRouteParams {
|
|
48
|
+
fractalsSync?: string[];
|
|
49
|
+
}
|
|
50
|
+
interface SyncRouteHandlerContext {
|
|
51
|
+
params?: SyncRouteParams | Promise<SyncRouteParams>;
|
|
52
|
+
}
|
|
53
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
54
|
+
interface SyncHandlerOptions {
|
|
55
|
+
baseURL?: string;
|
|
56
|
+
client?: SyncServerClient;
|
|
57
|
+
getHeadersFromRequest?: (req: ApiAuthRequest) => MaybePromise<HeadersInit>;
|
|
58
|
+
onUnauthorized?: (req: Request) => MaybePromise<Response>;
|
|
59
|
+
logger?: Pick<Console, "error" | "warn" | "info">;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
declare function syncRouteHandler(req: ApiAuthRequest, context?: SyncRouteHandlerContext, options?: SyncHandlerOptions): Promise<Response>;
|
|
63
|
+
declare function createMethodHandler(method: "GET" | "POST"): (req: ApiAuthRequest, context?: SyncRouteHandlerContext, options?: SyncHandlerOptions) => Response | Promise<Response>;
|
|
64
|
+
declare const GET: (req: ApiAuthRequest, context?: SyncRouteHandlerContext, options?: SyncHandlerOptions) => Response | Promise<Response>;
|
|
65
|
+
declare const POST: (req: ApiAuthRequest, context?: SyncRouteHandlerContext, options?: SyncHandlerOptions) => Response | Promise<Response>;
|
|
66
|
+
|
|
67
|
+
export { type ApiAuthRequest, GET, POST, type SyncHandlerOptions, SyncServerClient, type SyncServerOptions, createMethodHandler, syncRouteHandler };
|