@fractalshq/sync 0.1.0 → 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 +43 -11
- package/dist/chunk-4VKCXC52.mjs +129 -0
- package/dist/chunk-4ZYNBLY5.mjs +129 -0
- package/dist/chunk-DUDWBTA2.mjs +0 -0
- package/dist/chunk-FBL2T6BA.mjs +249 -0
- package/dist/chunk-ZIWHYEXE.mjs +498 -0
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +19 -649
- package/dist/index.mjs +7 -42
- package/dist/v1/core/index.d.mts +28 -0
- package/dist/v1/core/index.d.ts +28 -0
- package/dist/v1/core/index.js +320 -0
- package/dist/v1/core/index.mjs +51 -0
- package/dist/v1/index.d.mts +3 -0
- package/dist/v1/index.d.ts +3 -0
- package/dist/v1/index.js +816 -0
- package/dist/v1/index.mjs +63 -0
- package/dist/v1/react/index.d.mts +111 -0
- package/dist/v1/react/index.d.ts +111 -0
- package/dist/v1/react/index.js +552 -0
- package/dist/v1/react/index.mjs +330 -0
- package/dist/v1/server/index.d.mts +67 -0
- package/dist/v1/server/index.d.ts +67 -0
- package/dist/v1/server/index.js +540 -0
- package/dist/v1/server/index.mjs +15 -0
- package/dist/v1/widgets/index.d.mts +2 -0
- package/dist/v1/widgets/index.d.ts +2 -0
- package/dist/v1/widgets/index.js +18 -0
- package/dist/v1/widgets/index.mjs +0 -0
- package/dist/v2/core/index.d.mts +5 -21
- package/dist/v2/core/index.d.ts +5 -21
- package/dist/v2/core/index.js +9 -35
- package/dist/v2/core/index.mjs +3 -7
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.d.ts +1 -1
- package/dist/v2/index.js +9 -35
- package/dist/v2/index.mjs +4 -7
- package/dist/v2/react/index.d.mts +5 -27
- package/dist/v2/react/index.d.ts +5 -27
- package/dist/v2/react/index.js +26 -108
- package/dist/v2/react/index.mjs +20 -76
- package/package.json +52 -21
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_BASE_PATH,
|
|
3
|
+
SyncReactError,
|
|
4
|
+
buildDistributionTransaction,
|
|
5
|
+
commitDistributionSignature,
|
|
6
|
+
requestJSON,
|
|
7
|
+
resolveFetcher,
|
|
8
|
+
sanitizeBasePath
|
|
9
|
+
} from "../../chunk-FBL2T6BA.mjs";
|
|
10
|
+
import {
|
|
11
|
+
__spreadProps,
|
|
12
|
+
__spreadValues
|
|
13
|
+
} from "../../chunk-FWCSY2DS.mjs";
|
|
14
|
+
|
|
15
|
+
// src/v1/react/index.tsx
|
|
16
|
+
import { createContext, createElement, useCallback, useContext, useMemo, useState } from "react";
|
|
17
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
18
|
+
var SyncContext = createContext({ basePath: DEFAULT_BASE_PATH });
|
|
19
|
+
function SyncProvider({ basePath, fetcher, children }) {
|
|
20
|
+
const value = useMemo(
|
|
21
|
+
() => ({
|
|
22
|
+
basePath: sanitizeBasePath(basePath || DEFAULT_BASE_PATH),
|
|
23
|
+
fetcher
|
|
24
|
+
}),
|
|
25
|
+
[basePath, fetcher]
|
|
26
|
+
);
|
|
27
|
+
return createElement(SyncContext.Provider, { value }, children);
|
|
28
|
+
}
|
|
29
|
+
function useSyncClient() {
|
|
30
|
+
const requestConfig = useSyncRequestConfig();
|
|
31
|
+
return useMemo(() => {
|
|
32
|
+
const request = (path, init) => requestJSON(requestConfig, path, init);
|
|
33
|
+
return {
|
|
34
|
+
basePath: requestConfig.basePath,
|
|
35
|
+
request,
|
|
36
|
+
get: (path, init) => request(path, __spreadProps(__spreadValues({}, init), { method: "GET" })),
|
|
37
|
+
post: (path, body, init) => {
|
|
38
|
+
const finalInit = __spreadProps(__spreadValues({}, init), { method: ((init == null ? void 0 : init.method) || "POST").toUpperCase() });
|
|
39
|
+
if (body !== void 0) {
|
|
40
|
+
finalInit.body = typeof body === "string" ? body : JSON.stringify(body);
|
|
41
|
+
}
|
|
42
|
+
return request(path, finalInit);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}, [requestConfig]);
|
|
46
|
+
}
|
|
47
|
+
function useDistributions(paramsOrOptions, optionsMaybe) {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
const client = useSyncClient();
|
|
50
|
+
const { params, options } = resolveDistributionsArgs(paramsOrOptions, optionsMaybe);
|
|
51
|
+
const path = buildDistributionsPath(params);
|
|
52
|
+
return useQuery(__spreadValues({
|
|
53
|
+
queryKey: ["sync", "distributions", "me", (_a = params == null ? void 0 : params.role) != null ? _a : "claimant", (_b = params == null ? void 0 : params.status) != null ? _b : "all"],
|
|
54
|
+
queryFn: () => client.get(path)
|
|
55
|
+
}, options));
|
|
56
|
+
}
|
|
57
|
+
function useDistribution(distributionId, options) {
|
|
58
|
+
var _a;
|
|
59
|
+
const client = useSyncClient();
|
|
60
|
+
const id = distributionId ? encodeURIComponent(distributionId) : "";
|
|
61
|
+
return useQuery(__spreadProps(__spreadValues({
|
|
62
|
+
queryKey: ["sync", "distribution", id],
|
|
63
|
+
queryFn: () => client.get(`/distributions/me/${id}`)
|
|
64
|
+
}, options), {
|
|
65
|
+
enabled: Boolean(id) && ((_a = options == null ? void 0 : options.enabled) != null ? _a : true)
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
function useDistributionTransaction(options) {
|
|
69
|
+
const requestConfig = useSyncRequestConfig();
|
|
70
|
+
return useMutation(__spreadValues({
|
|
71
|
+
mutationFn: async (input) => {
|
|
72
|
+
if (!input) throw new SyncReactError(400, "distribution_input_required");
|
|
73
|
+
return buildDistributionTransaction(input, requestConfig);
|
|
74
|
+
}
|
|
75
|
+
}, options));
|
|
76
|
+
}
|
|
77
|
+
function useCommitDistribution(options) {
|
|
78
|
+
const requestConfig = useSyncRequestConfig();
|
|
79
|
+
return useMutation(__spreadValues({
|
|
80
|
+
mutationFn: async (input) => {
|
|
81
|
+
if (!(input == null ? void 0 : input.distributionId)) throw new SyncReactError(400, "distribution_id_required");
|
|
82
|
+
return commitDistributionSignature(input, requestConfig);
|
|
83
|
+
}
|
|
84
|
+
}, options));
|
|
85
|
+
}
|
|
86
|
+
function useDistributionFlow() {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
const buildMutation = useDistributionTransaction();
|
|
89
|
+
const commitMutation = useCommitDistribution();
|
|
90
|
+
const [latestPayload, setLatestPayload] = useState(null);
|
|
91
|
+
const [latestInput, setLatestInput] = useState(null);
|
|
92
|
+
const build = useCallback(
|
|
93
|
+
async (input) => {
|
|
94
|
+
const payload = await buildMutation.mutateAsync(input);
|
|
95
|
+
setLatestPayload(payload);
|
|
96
|
+
setLatestInput(cloneDistributionInput(input));
|
|
97
|
+
return payload;
|
|
98
|
+
},
|
|
99
|
+
[buildMutation]
|
|
100
|
+
);
|
|
101
|
+
const doCommit = useCallback(
|
|
102
|
+
async (signer, input) => {
|
|
103
|
+
let payload = null;
|
|
104
|
+
if (input) {
|
|
105
|
+
payload = await build(input);
|
|
106
|
+
} else if (latestInput) {
|
|
107
|
+
payload = await build(latestInput);
|
|
108
|
+
} else if (latestPayload) {
|
|
109
|
+
payload = latestPayload;
|
|
110
|
+
}
|
|
111
|
+
if (!payload) {
|
|
112
|
+
throw new SyncReactError(400, "distribution_payload_missing");
|
|
113
|
+
}
|
|
114
|
+
if (!payload.distributionId) {
|
|
115
|
+
throw new SyncReactError(400, "distribution_id_required");
|
|
116
|
+
}
|
|
117
|
+
const signerInput = await signer(payload);
|
|
118
|
+
if (!signerInput || !signerInput.signature && !signerInput.transaction && !signerInput.signedTransactionBase64) {
|
|
119
|
+
throw new SyncReactError(400, "distribution_signature_required");
|
|
120
|
+
}
|
|
121
|
+
const commitPayload = __spreadProps(__spreadValues({}, signerInput), {
|
|
122
|
+
distributionId: payload.distributionId
|
|
123
|
+
});
|
|
124
|
+
if (!commitPayload.exportJson && payload.exportJson) {
|
|
125
|
+
commitPayload.exportJson = payload.exportJson;
|
|
126
|
+
}
|
|
127
|
+
const commitResult = await commitMutation.mutateAsync(commitPayload);
|
|
128
|
+
return { payload, commit: commitResult, signerInput };
|
|
129
|
+
},
|
|
130
|
+
[build, latestInput, latestPayload, commitMutation]
|
|
131
|
+
);
|
|
132
|
+
const reset = useCallback(() => {
|
|
133
|
+
setLatestPayload(null);
|
|
134
|
+
setLatestInput(null);
|
|
135
|
+
buildMutation.reset();
|
|
136
|
+
commitMutation.reset();
|
|
137
|
+
}, [buildMutation, commitMutation]);
|
|
138
|
+
const error = (_b = (_a = buildMutation.error) != null ? _a : commitMutation.error) != null ? _b : null;
|
|
139
|
+
const state = useMemo(
|
|
140
|
+
() => ({
|
|
141
|
+
latestPayload,
|
|
142
|
+
building: buildMutation.isPending,
|
|
143
|
+
committing: commitMutation.isPending,
|
|
144
|
+
error
|
|
145
|
+
}),
|
|
146
|
+
[latestPayload, buildMutation.isPending, commitMutation.isPending, error]
|
|
147
|
+
);
|
|
148
|
+
return { state, build, commit: doCommit, claim: doCommit, reset };
|
|
149
|
+
}
|
|
150
|
+
function useClaimableDistributions(options) {
|
|
151
|
+
const client = useSyncClient();
|
|
152
|
+
return useQuery(__spreadValues({
|
|
153
|
+
queryKey: ["sync", "claims", "me"],
|
|
154
|
+
queryFn: () => client.get("/claims/me")
|
|
155
|
+
}, options));
|
|
156
|
+
}
|
|
157
|
+
function useClaimHistory(options) {
|
|
158
|
+
const client = useSyncClient();
|
|
159
|
+
return useQuery(__spreadValues({
|
|
160
|
+
queryKey: ["sync", "claims", "history"],
|
|
161
|
+
queryFn: () => client.get("/claims/history")
|
|
162
|
+
}, options));
|
|
163
|
+
}
|
|
164
|
+
function useClaimTransaction(distributionId, options) {
|
|
165
|
+
const client = useSyncClient();
|
|
166
|
+
const id = distributionId ? encodeURIComponent(distributionId) : null;
|
|
167
|
+
return useMutation(__spreadValues({
|
|
168
|
+
mutationFn: async (input = {}) => {
|
|
169
|
+
if (!id) throw new SyncReactError(400, "distribution_id_required");
|
|
170
|
+
return client.post(`/claims/${id}/create-transaction`, input);
|
|
171
|
+
}
|
|
172
|
+
}, options));
|
|
173
|
+
}
|
|
174
|
+
function useCommitClaim(distributionId, options) {
|
|
175
|
+
const client = useSyncClient();
|
|
176
|
+
const id = distributionId ? encodeURIComponent(distributionId) : null;
|
|
177
|
+
return useMutation(__spreadValues({
|
|
178
|
+
mutationFn: async (input) => {
|
|
179
|
+
if (!id) throw new SyncReactError(400, "distribution_id_required");
|
|
180
|
+
if (!input || !input.signature && !input.transaction && !input.signedTransactionBase64) {
|
|
181
|
+
throw new SyncReactError(400, "transaction_or_signature_required");
|
|
182
|
+
}
|
|
183
|
+
return client.post(`/claims/${id}/commit`, input);
|
|
184
|
+
}
|
|
185
|
+
}, options));
|
|
186
|
+
}
|
|
187
|
+
function useClaimFlow(distributionId) {
|
|
188
|
+
var _a, _b;
|
|
189
|
+
const buildMutation = useClaimTransaction(distributionId);
|
|
190
|
+
const commitMutation = useCommitClaim(distributionId);
|
|
191
|
+
const [latestPayload, setLatestPayload] = useState(null);
|
|
192
|
+
const build = useCallback(
|
|
193
|
+
async (input) => {
|
|
194
|
+
const payload = await buildMutation.mutateAsync(input != null ? input : {});
|
|
195
|
+
setLatestPayload(payload);
|
|
196
|
+
return payload;
|
|
197
|
+
},
|
|
198
|
+
[buildMutation]
|
|
199
|
+
);
|
|
200
|
+
const claim = useCallback(
|
|
201
|
+
async (signer, input) => {
|
|
202
|
+
const payload = await build(input);
|
|
203
|
+
const signerInput = await signer(payload);
|
|
204
|
+
if (!signerInput || !signerInput.signature && !signerInput.transaction && !signerInput.signedTransactionBase64) {
|
|
205
|
+
throw new SyncReactError(400, "claim_signature_required");
|
|
206
|
+
}
|
|
207
|
+
const commit = await commitMutation.mutateAsync(signerInput);
|
|
208
|
+
return { payload, commit, signerInput };
|
|
209
|
+
},
|
|
210
|
+
[build, commitMutation]
|
|
211
|
+
);
|
|
212
|
+
const reset = useCallback(() => {
|
|
213
|
+
setLatestPayload(null);
|
|
214
|
+
}, []);
|
|
215
|
+
const state = {
|
|
216
|
+
latestPayload,
|
|
217
|
+
building: buildMutation.isPending,
|
|
218
|
+
claiming: commitMutation.isPending,
|
|
219
|
+
error: (_b = (_a = buildMutation.error) != null ? _a : commitMutation.error) != null ? _b : null
|
|
220
|
+
};
|
|
221
|
+
return { state, build, claim, reset };
|
|
222
|
+
}
|
|
223
|
+
function useSyncRequestConfig() {
|
|
224
|
+
const context = useContext(SyncContext);
|
|
225
|
+
const basePath = sanitizeBasePath((context == null ? void 0 : context.basePath) || DEFAULT_BASE_PATH);
|
|
226
|
+
const fetcher = resolveFetcher(context == null ? void 0 : context.fetcher);
|
|
227
|
+
return useMemo(() => ({ basePath, fetcher }), [basePath, fetcher]);
|
|
228
|
+
}
|
|
229
|
+
function cloneDistributionInput(input) {
|
|
230
|
+
return __spreadProps(__spreadValues({}, input), {
|
|
231
|
+
recipients: input.recipients.map((recipient) => __spreadValues({}, recipient))
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function resolveDistributionsArgs(paramsOrOptions, optionsMaybe) {
|
|
235
|
+
if (isDistributionsParams(paramsOrOptions)) {
|
|
236
|
+
return { params: paramsOrOptions, options: optionsMaybe };
|
|
237
|
+
}
|
|
238
|
+
return { params: void 0, options: paramsOrOptions };
|
|
239
|
+
}
|
|
240
|
+
function isDistributionsParams(arg) {
|
|
241
|
+
if (!arg || typeof arg !== "object") return false;
|
|
242
|
+
return "role" in arg || "status" in arg;
|
|
243
|
+
}
|
|
244
|
+
function buildDistributionsPath(params) {
|
|
245
|
+
const search = new URLSearchParams();
|
|
246
|
+
if ((params == null ? void 0 : params.role) && params.role !== "claimant") {
|
|
247
|
+
search.set("role", params.role);
|
|
248
|
+
}
|
|
249
|
+
if (params == null ? void 0 : params.status) {
|
|
250
|
+
search.set("status", params.status);
|
|
251
|
+
}
|
|
252
|
+
const qs = search.toString();
|
|
253
|
+
return qs ? `/distributions/me?${qs}` : "/distributions/me";
|
|
254
|
+
}
|
|
255
|
+
function createRecipientRowId() {
|
|
256
|
+
return `recipient-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
257
|
+
}
|
|
258
|
+
function hydrateRecipientRow(partial) {
|
|
259
|
+
var _a, _b;
|
|
260
|
+
return {
|
|
261
|
+
id: createRecipientRowId(),
|
|
262
|
+
address: (_a = partial == null ? void 0 : partial.address) != null ? _a : "",
|
|
263
|
+
amount: (_b = partial == null ? void 0 : partial.amount) != null ? _b : ""
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function useRecipientComposer(initial = []) {
|
|
267
|
+
const [rows, setRows] = useState(() => {
|
|
268
|
+
if (initial.length === 0) return [hydrateRecipientRow()];
|
|
269
|
+
return initial.map((row) => hydrateRecipientRow(row));
|
|
270
|
+
});
|
|
271
|
+
const addRow = useCallback(() => {
|
|
272
|
+
setRows((current) => [...current, hydrateRecipientRow()]);
|
|
273
|
+
}, []);
|
|
274
|
+
const removeRow = useCallback((id) => {
|
|
275
|
+
setRows((current) => {
|
|
276
|
+
if (current.length <= 1) return [hydrateRecipientRow()];
|
|
277
|
+
return current.filter((row) => row.id !== id);
|
|
278
|
+
});
|
|
279
|
+
}, []);
|
|
280
|
+
const updateRow = useCallback((id, patch) => {
|
|
281
|
+
setRows((current) => current.map((row) => row.id === id ? __spreadValues(__spreadValues({}, row), patch) : row));
|
|
282
|
+
}, []);
|
|
283
|
+
const replaceRows = useCallback((incoming) => {
|
|
284
|
+
if (!incoming.length) {
|
|
285
|
+
setRows([hydrateRecipientRow()]);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
setRows(incoming.map((row) => hydrateRecipientRow(row)));
|
|
289
|
+
}, []);
|
|
290
|
+
const clearRows = useCallback(() => {
|
|
291
|
+
setRows([hydrateRecipientRow()]);
|
|
292
|
+
}, []);
|
|
293
|
+
const totals = useMemo(() => {
|
|
294
|
+
const normalized = rows.map((row) => ({
|
|
295
|
+
id: row.id,
|
|
296
|
+
address: row.address.trim(),
|
|
297
|
+
amountUi: Number(row.amount) || 0,
|
|
298
|
+
amountRaw: row.amount
|
|
299
|
+
}));
|
|
300
|
+
const totalAmountUi = normalized.reduce((sum, row) => sum + Math.max(0, row.amountUi), 0);
|
|
301
|
+
return {
|
|
302
|
+
count: rows.length,
|
|
303
|
+
totalAmountUi,
|
|
304
|
+
normalized
|
|
305
|
+
};
|
|
306
|
+
}, [rows]);
|
|
307
|
+
return {
|
|
308
|
+
state: { rows, totals },
|
|
309
|
+
addRow,
|
|
310
|
+
removeRow,
|
|
311
|
+
updateRow,
|
|
312
|
+
replaceRows,
|
|
313
|
+
clearRows
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
export {
|
|
317
|
+
SyncProvider,
|
|
318
|
+
useClaimFlow,
|
|
319
|
+
useClaimHistory,
|
|
320
|
+
useClaimTransaction,
|
|
321
|
+
useClaimableDistributions,
|
|
322
|
+
useCommitClaim,
|
|
323
|
+
useCommitDistribution,
|
|
324
|
+
useDistribution,
|
|
325
|
+
useDistributionFlow,
|
|
326
|
+
useDistributionTransaction,
|
|
327
|
+
useDistributions,
|
|
328
|
+
useRecipientComposer,
|
|
329
|
+
useSyncClient
|
|
330
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { L as ListDistributionsRequest, g as ListDistributionsResponse, l as CreateDistributionRequest, k as DistributionTransactionPayload, o as CommitDistributionRequest, p as CommitDistributionResponse, r as BuildClaimTransactionRequest, d as ClaimTransactionResponse, t as CommitClaimRequest, u as CommitClaimResponse, v as ClaimableResponse, a as Distribution, x as ClaimHistoryResponse, H as HealthResponse } from '../../api-BX1PjpZQ.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<DistributionTransactionPayload>;
|
|
19
|
+
createDistributionWithId(distributionId: string, body: CreateDistributionRequest): Promise<DistributionTransactionPayload>;
|
|
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, l as CreateDistributionRequest, k as DistributionTransactionPayload, o as CommitDistributionRequest, p as CommitDistributionResponse, r as BuildClaimTransactionRequest, d as ClaimTransactionResponse, t as CommitClaimRequest, u as CommitClaimResponse, v as ClaimableResponse, a as Distribution, x as ClaimHistoryResponse, H as HealthResponse } from '../../api-BX1PjpZQ.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<DistributionTransactionPayload>;
|
|
19
|
+
createDistributionWithId(distributionId: string, body: CreateDistributionRequest): Promise<DistributionTransactionPayload>;
|
|
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 };
|