@fractalshq/sync 0.0.10 → 0.0.11
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/chunk-RTLKOAT7.mjs +153 -0
- package/dist/v2/core/index.d.mts +103 -0
- package/dist/v2/core/index.d.ts +103 -0
- package/dist/v2/core/index.js +212 -0
- package/dist/v2/core/index.mjs +31 -0
- package/dist/v2/index.d.mts +1 -0
- package/dist/v2/index.d.ts +1 -0
- package/dist/v2/index.js +212 -0
- package/dist/v2/index.mjs +31 -0
- package/dist/v2/react/index.d.mts +50 -0
- package/dist/v2/react/index.d.ts +50 -0
- package/dist/v2/react/index.js +317 -0
- package/dist/v2/react/index.mjs +138 -0
- package/package.json +18 -3
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__objRest,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "./chunk-FWCSY2DS.mjs";
|
|
5
|
+
|
|
6
|
+
// src/v2/core/http.ts
|
|
7
|
+
var FALLBACK_BASE_PATH = "/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 : isRelativeUrl(url) ? "include" : void 0;
|
|
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 commitClaim(input, options) {
|
|
109
|
+
const distributionId = input == null ? void 0 : input.distributionId;
|
|
110
|
+
if (!distributionId) {
|
|
111
|
+
throw new SyncReactError(400, "distribution_id_required");
|
|
112
|
+
}
|
|
113
|
+
if (!(input == null ? void 0 : input.signedTransactionBase64)) {
|
|
114
|
+
throw new SyncReactError(400, "signed_transaction_required");
|
|
115
|
+
}
|
|
116
|
+
if (!(input == null ? void 0 : input.claimantPubkey)) {
|
|
117
|
+
throw new SyncReactError(400, "claimant_pubkey_required");
|
|
118
|
+
}
|
|
119
|
+
const config = resolveRequestConfig(options);
|
|
120
|
+
const _a2 = input, { distributionId: _unused } = _a2, body = __objRest(_a2, ["distributionId"]);
|
|
121
|
+
return requestJSON(
|
|
122
|
+
config,
|
|
123
|
+
`/claims/${encodeURIComponent(distributionId)}/commit`,
|
|
124
|
+
{
|
|
125
|
+
method: "POST",
|
|
126
|
+
body: JSON.stringify(body)
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
async function listClaimable(options) {
|
|
131
|
+
const config = resolveRequestConfig(options);
|
|
132
|
+
return requestJSON(config, "/claims/me", { method: "GET" });
|
|
133
|
+
}
|
|
134
|
+
async function listClaimHistory(options) {
|
|
135
|
+
const config = resolveRequestConfig(options);
|
|
136
|
+
return requestJSON(config, "/claims/history", { method: "GET" });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export {
|
|
140
|
+
DEFAULT_BASE_PATH,
|
|
141
|
+
resolveRequestConfig,
|
|
142
|
+
SyncReactError,
|
|
143
|
+
requestJSON,
|
|
144
|
+
resolveFetcher,
|
|
145
|
+
sanitizeBasePath,
|
|
146
|
+
buildUrl,
|
|
147
|
+
isAbsoluteUrl,
|
|
148
|
+
isRelativeUrl,
|
|
149
|
+
buildClaimTransaction,
|
|
150
|
+
commitClaim,
|
|
151
|
+
listClaimable,
|
|
152
|
+
listClaimHistory
|
|
153
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
interface ClaimTransactionInstruction {
|
|
2
|
+
programId: string;
|
|
3
|
+
keys: Array<{
|
|
4
|
+
pubkey: string;
|
|
5
|
+
isSigner: boolean;
|
|
6
|
+
isWritable: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
data: string;
|
|
9
|
+
}
|
|
10
|
+
interface ClaimTransactionRequest {
|
|
11
|
+
distributionId: string;
|
|
12
|
+
claimant: string;
|
|
13
|
+
index?: number;
|
|
14
|
+
proof?: string[];
|
|
15
|
+
unlockedAmount?: number;
|
|
16
|
+
lockedAmount?: number;
|
|
17
|
+
mint?: string;
|
|
18
|
+
distributorPda?: string;
|
|
19
|
+
rpcEndpoint?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ClaimTransactionResponse {
|
|
22
|
+
label: string;
|
|
23
|
+
instructions: ClaimTransactionInstruction[];
|
|
24
|
+
transaction?: string;
|
|
25
|
+
}
|
|
26
|
+
interface CommitClaimRequest {
|
|
27
|
+
distributionId: string;
|
|
28
|
+
signedTransactionBase64: string;
|
|
29
|
+
claimantPubkey: string;
|
|
30
|
+
}
|
|
31
|
+
interface CommitClaimResponse {
|
|
32
|
+
success: boolean;
|
|
33
|
+
distributorId: string;
|
|
34
|
+
txSignature: string;
|
|
35
|
+
alreadyTracked?: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface ClaimableDistribution {
|
|
38
|
+
distributorId: string;
|
|
39
|
+
distributorName?: string;
|
|
40
|
+
tokenMint: string;
|
|
41
|
+
tokenSymbol?: string;
|
|
42
|
+
owedAmount: string;
|
|
43
|
+
status: "claimable" | "vesting" | "locked";
|
|
44
|
+
fees?: {
|
|
45
|
+
fixedFee?: string;
|
|
46
|
+
solFee?: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
interface ClaimableResponse {
|
|
50
|
+
wallet: string;
|
|
51
|
+
claimable: ClaimableDistribution[];
|
|
52
|
+
}
|
|
53
|
+
interface ClaimHistoryItem {
|
|
54
|
+
distributorId: string;
|
|
55
|
+
claimedAmount: string;
|
|
56
|
+
claimedAt: string;
|
|
57
|
+
signature?: string | null;
|
|
58
|
+
txSignature?: string | null;
|
|
59
|
+
amount?: string;
|
|
60
|
+
distributionTitle?: string | null;
|
|
61
|
+
mint?: string | null;
|
|
62
|
+
orgId?: string | null;
|
|
63
|
+
status?: string | null;
|
|
64
|
+
solFeeLamports?: string | null;
|
|
65
|
+
solFeeUsd?: string | null;
|
|
66
|
+
}
|
|
67
|
+
interface ClaimHistoryResponse {
|
|
68
|
+
items: ClaimHistoryItem[];
|
|
69
|
+
nextCursor: string | null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type Fetcher = typeof fetch;
|
|
73
|
+
declare const DEFAULT_BASE_PATH: string;
|
|
74
|
+
interface SyncRequestOptions {
|
|
75
|
+
basePath?: string;
|
|
76
|
+
fetcher?: Fetcher;
|
|
77
|
+
}
|
|
78
|
+
interface SyncRequestConfig {
|
|
79
|
+
basePath: string;
|
|
80
|
+
fetcher: Fetcher;
|
|
81
|
+
}
|
|
82
|
+
declare function resolveRequestConfig(options?: SyncRequestOptions): SyncRequestConfig;
|
|
83
|
+
declare class SyncReactError extends Error {
|
|
84
|
+
readonly status: number;
|
|
85
|
+
readonly code?: string | undefined;
|
|
86
|
+
readonly details?: unknown | undefined;
|
|
87
|
+
constructor(status: number, code?: string | undefined, details?: unknown | undefined);
|
|
88
|
+
}
|
|
89
|
+
declare function requestJSON<T>(config: SyncRequestConfig, path: string, init?: RequestInit): Promise<T>;
|
|
90
|
+
declare function resolveFetcher(custom?: Fetcher): Fetcher;
|
|
91
|
+
declare function sanitizeBasePath(path: string): string;
|
|
92
|
+
declare function buildUrl(basePath: string, path: string): string;
|
|
93
|
+
declare function isAbsoluteUrl(path: string): boolean;
|
|
94
|
+
declare function isRelativeUrl(path: string): boolean;
|
|
95
|
+
|
|
96
|
+
type BuildClaimTransactionRequest = ClaimTransactionRequest;
|
|
97
|
+
type BuildClaimTransactionResponse = ClaimTransactionResponse;
|
|
98
|
+
declare function buildClaimTransaction(input: BuildClaimTransactionRequest, options?: SyncRequestOptions): Promise<BuildClaimTransactionResponse>;
|
|
99
|
+
declare function commitClaim(input: CommitClaimRequest, options?: SyncRequestOptions): Promise<CommitClaimResponse>;
|
|
100
|
+
declare function listClaimable(options?: SyncRequestOptions): Promise<ClaimableResponse>;
|
|
101
|
+
declare function listClaimHistory(options?: SyncRequestOptions): Promise<ClaimHistoryResponse>;
|
|
102
|
+
|
|
103
|
+
export { type BuildClaimTransactionRequest, type BuildClaimTransactionResponse, type ClaimHistoryItem, type ClaimHistoryResponse, type ClaimTransactionInstruction, type ClaimTransactionRequest, type ClaimTransactionResponse, type ClaimableDistribution, type ClaimableResponse, type CommitClaimRequest, type CommitClaimResponse, DEFAULT_BASE_PATH, type Fetcher, SyncReactError, type SyncRequestConfig, type SyncRequestOptions, buildClaimTransaction, buildUrl, commitClaim, isAbsoluteUrl, isRelativeUrl, listClaimHistory, listClaimable, requestJSON, resolveFetcher, resolveRequestConfig, sanitizeBasePath };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
interface ClaimTransactionInstruction {
|
|
2
|
+
programId: string;
|
|
3
|
+
keys: Array<{
|
|
4
|
+
pubkey: string;
|
|
5
|
+
isSigner: boolean;
|
|
6
|
+
isWritable: boolean;
|
|
7
|
+
}>;
|
|
8
|
+
data: string;
|
|
9
|
+
}
|
|
10
|
+
interface ClaimTransactionRequest {
|
|
11
|
+
distributionId: string;
|
|
12
|
+
claimant: string;
|
|
13
|
+
index?: number;
|
|
14
|
+
proof?: string[];
|
|
15
|
+
unlockedAmount?: number;
|
|
16
|
+
lockedAmount?: number;
|
|
17
|
+
mint?: string;
|
|
18
|
+
distributorPda?: string;
|
|
19
|
+
rpcEndpoint?: string;
|
|
20
|
+
}
|
|
21
|
+
interface ClaimTransactionResponse {
|
|
22
|
+
label: string;
|
|
23
|
+
instructions: ClaimTransactionInstruction[];
|
|
24
|
+
transaction?: string;
|
|
25
|
+
}
|
|
26
|
+
interface CommitClaimRequest {
|
|
27
|
+
distributionId: string;
|
|
28
|
+
signedTransactionBase64: string;
|
|
29
|
+
claimantPubkey: string;
|
|
30
|
+
}
|
|
31
|
+
interface CommitClaimResponse {
|
|
32
|
+
success: boolean;
|
|
33
|
+
distributorId: string;
|
|
34
|
+
txSignature: string;
|
|
35
|
+
alreadyTracked?: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface ClaimableDistribution {
|
|
38
|
+
distributorId: string;
|
|
39
|
+
distributorName?: string;
|
|
40
|
+
tokenMint: string;
|
|
41
|
+
tokenSymbol?: string;
|
|
42
|
+
owedAmount: string;
|
|
43
|
+
status: "claimable" | "vesting" | "locked";
|
|
44
|
+
fees?: {
|
|
45
|
+
fixedFee?: string;
|
|
46
|
+
solFee?: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
interface ClaimableResponse {
|
|
50
|
+
wallet: string;
|
|
51
|
+
claimable: ClaimableDistribution[];
|
|
52
|
+
}
|
|
53
|
+
interface ClaimHistoryItem {
|
|
54
|
+
distributorId: string;
|
|
55
|
+
claimedAmount: string;
|
|
56
|
+
claimedAt: string;
|
|
57
|
+
signature?: string | null;
|
|
58
|
+
txSignature?: string | null;
|
|
59
|
+
amount?: string;
|
|
60
|
+
distributionTitle?: string | null;
|
|
61
|
+
mint?: string | null;
|
|
62
|
+
orgId?: string | null;
|
|
63
|
+
status?: string | null;
|
|
64
|
+
solFeeLamports?: string | null;
|
|
65
|
+
solFeeUsd?: string | null;
|
|
66
|
+
}
|
|
67
|
+
interface ClaimHistoryResponse {
|
|
68
|
+
items: ClaimHistoryItem[];
|
|
69
|
+
nextCursor: string | null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type Fetcher = typeof fetch;
|
|
73
|
+
declare const DEFAULT_BASE_PATH: string;
|
|
74
|
+
interface SyncRequestOptions {
|
|
75
|
+
basePath?: string;
|
|
76
|
+
fetcher?: Fetcher;
|
|
77
|
+
}
|
|
78
|
+
interface SyncRequestConfig {
|
|
79
|
+
basePath: string;
|
|
80
|
+
fetcher: Fetcher;
|
|
81
|
+
}
|
|
82
|
+
declare function resolveRequestConfig(options?: SyncRequestOptions): SyncRequestConfig;
|
|
83
|
+
declare class SyncReactError extends Error {
|
|
84
|
+
readonly status: number;
|
|
85
|
+
readonly code?: string | undefined;
|
|
86
|
+
readonly details?: unknown | undefined;
|
|
87
|
+
constructor(status: number, code?: string | undefined, details?: unknown | undefined);
|
|
88
|
+
}
|
|
89
|
+
declare function requestJSON<T>(config: SyncRequestConfig, path: string, init?: RequestInit): Promise<T>;
|
|
90
|
+
declare function resolveFetcher(custom?: Fetcher): Fetcher;
|
|
91
|
+
declare function sanitizeBasePath(path: string): string;
|
|
92
|
+
declare function buildUrl(basePath: string, path: string): string;
|
|
93
|
+
declare function isAbsoluteUrl(path: string): boolean;
|
|
94
|
+
declare function isRelativeUrl(path: string): boolean;
|
|
95
|
+
|
|
96
|
+
type BuildClaimTransactionRequest = ClaimTransactionRequest;
|
|
97
|
+
type BuildClaimTransactionResponse = ClaimTransactionResponse;
|
|
98
|
+
declare function buildClaimTransaction(input: BuildClaimTransactionRequest, options?: SyncRequestOptions): Promise<BuildClaimTransactionResponse>;
|
|
99
|
+
declare function commitClaim(input: CommitClaimRequest, options?: SyncRequestOptions): Promise<CommitClaimResponse>;
|
|
100
|
+
declare function listClaimable(options?: SyncRequestOptions): Promise<ClaimableResponse>;
|
|
101
|
+
declare function listClaimHistory(options?: SyncRequestOptions): Promise<ClaimHistoryResponse>;
|
|
102
|
+
|
|
103
|
+
export { type BuildClaimTransactionRequest, type BuildClaimTransactionResponse, type ClaimHistoryItem, type ClaimHistoryResponse, type ClaimTransactionInstruction, type ClaimTransactionRequest, type ClaimTransactionResponse, type ClaimableDistribution, type ClaimableResponse, type CommitClaimRequest, type CommitClaimResponse, DEFAULT_BASE_PATH, type Fetcher, SyncReactError, type SyncRequestConfig, type SyncRequestOptions, buildClaimTransaction, buildUrl, commitClaim, isAbsoluteUrl, isRelativeUrl, listClaimHistory, listClaimable, requestJSON, resolveFetcher, resolveRequestConfig, sanitizeBasePath };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __export = (target, all) => {
|
|
33
|
+
for (var name in all)
|
|
34
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
35
|
+
};
|
|
36
|
+
var __copyProps = (to, from, except, desc) => {
|
|
37
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
38
|
+
for (let key of __getOwnPropNames(from))
|
|
39
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
40
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
41
|
+
}
|
|
42
|
+
return to;
|
|
43
|
+
};
|
|
44
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
|
|
46
|
+
// src/v2/core/index.ts
|
|
47
|
+
var core_exports = {};
|
|
48
|
+
__export(core_exports, {
|
|
49
|
+
DEFAULT_BASE_PATH: () => DEFAULT_BASE_PATH,
|
|
50
|
+
SyncReactError: () => SyncReactError,
|
|
51
|
+
buildClaimTransaction: () => buildClaimTransaction,
|
|
52
|
+
buildUrl: () => buildUrl,
|
|
53
|
+
commitClaim: () => commitClaim,
|
|
54
|
+
isAbsoluteUrl: () => isAbsoluteUrl,
|
|
55
|
+
isRelativeUrl: () => isRelativeUrl,
|
|
56
|
+
listClaimHistory: () => listClaimHistory,
|
|
57
|
+
listClaimable: () => listClaimable,
|
|
58
|
+
requestJSON: () => requestJSON,
|
|
59
|
+
resolveFetcher: () => resolveFetcher,
|
|
60
|
+
resolveRequestConfig: () => resolveRequestConfig,
|
|
61
|
+
sanitizeBasePath: () => sanitizeBasePath
|
|
62
|
+
});
|
|
63
|
+
module.exports = __toCommonJS(core_exports);
|
|
64
|
+
|
|
65
|
+
// src/v2/core/http.ts
|
|
66
|
+
var FALLBACK_BASE_PATH = "/api/v2";
|
|
67
|
+
var _a, _b;
|
|
68
|
+
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;
|
|
69
|
+
var DEFAULT_BASE_PATH = sanitizeBasePath(ENV_BASE_PATH || FALLBACK_BASE_PATH);
|
|
70
|
+
function resolveRequestConfig(options) {
|
|
71
|
+
return {
|
|
72
|
+
basePath: sanitizeBasePath((options == null ? void 0 : options.basePath) || DEFAULT_BASE_PATH),
|
|
73
|
+
fetcher: resolveFetcher(options == null ? void 0 : options.fetcher)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var SyncReactError = class extends Error {
|
|
77
|
+
constructor(status, code, details) {
|
|
78
|
+
super(code || `Sync request failed with status ${status}`);
|
|
79
|
+
this.status = status;
|
|
80
|
+
this.code = code;
|
|
81
|
+
this.details = details;
|
|
82
|
+
this.name = "SyncReactError";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
async function requestJSON(config, path, init) {
|
|
86
|
+
var _a2;
|
|
87
|
+
const url = buildUrl(config.basePath, path);
|
|
88
|
+
const requestInit = prepareInit(init);
|
|
89
|
+
requestInit.credentials = (_a2 = requestInit.credentials) != null ? _a2 : isRelativeUrl(url) ? "include" : void 0;
|
|
90
|
+
const response = await config.fetcher(url, requestInit);
|
|
91
|
+
const payload = await parseResponseBody(response);
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
const errorCode = typeof payload === "object" && payload && "error" in payload ? String(payload.error) : void 0;
|
|
94
|
+
throw new SyncReactError(response.status, errorCode, payload);
|
|
95
|
+
}
|
|
96
|
+
return payload;
|
|
97
|
+
}
|
|
98
|
+
function resolveFetcher(custom) {
|
|
99
|
+
if (custom) return custom;
|
|
100
|
+
if (typeof fetch === "function") return fetch.bind(globalThis);
|
|
101
|
+
throw new Error("Global fetch is not available. Provide a fetcher via Sync configuration.");
|
|
102
|
+
}
|
|
103
|
+
function sanitizeBasePath(path) {
|
|
104
|
+
if (!path) return FALLBACK_BASE_PATH;
|
|
105
|
+
const trimmed = path.trim();
|
|
106
|
+
if (!trimmed || trimmed === "/") return "/";
|
|
107
|
+
return trimmed.replace(/\/+$/, "");
|
|
108
|
+
}
|
|
109
|
+
function buildUrl(basePath, path) {
|
|
110
|
+
if (path && isAbsoluteUrl(path)) return path;
|
|
111
|
+
const normalizedBase = sanitizeBasePath(basePath);
|
|
112
|
+
const suffix = path ? `/${path.replace(/^\/+/, "")}` : "";
|
|
113
|
+
if (!normalizedBase || normalizedBase === "/") {
|
|
114
|
+
return suffix ? suffix : normalizedBase;
|
|
115
|
+
}
|
|
116
|
+
return `${normalizedBase}${suffix}`;
|
|
117
|
+
}
|
|
118
|
+
function isAbsoluteUrl(path) {
|
|
119
|
+
return /^https?:\/\//i.test(path);
|
|
120
|
+
}
|
|
121
|
+
function isRelativeUrl(path) {
|
|
122
|
+
return !isAbsoluteUrl(path);
|
|
123
|
+
}
|
|
124
|
+
function prepareInit(init) {
|
|
125
|
+
const finalInit = __spreadValues({}, init);
|
|
126
|
+
if ((init == null ? void 0 : init.headers) instanceof Headers) {
|
|
127
|
+
const cloned = new Headers(init.headers);
|
|
128
|
+
if (!cloned.has("content-type")) cloned.set("content-type", "application/json");
|
|
129
|
+
finalInit.headers = cloned;
|
|
130
|
+
return finalInit;
|
|
131
|
+
}
|
|
132
|
+
const headers = new Headers(init == null ? void 0 : init.headers);
|
|
133
|
+
if (!headers.has("content-type")) {
|
|
134
|
+
headers.set("content-type", "application/json");
|
|
135
|
+
}
|
|
136
|
+
finalInit.headers = headers;
|
|
137
|
+
return finalInit;
|
|
138
|
+
}
|
|
139
|
+
async function parseResponseBody(response) {
|
|
140
|
+
if (response.status === 204) return void 0;
|
|
141
|
+
const text = await response.text();
|
|
142
|
+
if (!text) return void 0;
|
|
143
|
+
try {
|
|
144
|
+
return JSON.parse(text);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
return text;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/v2/core/api.ts
|
|
151
|
+
async function buildClaimTransaction(input, options) {
|
|
152
|
+
const distributionId = input == null ? void 0 : input.distributionId;
|
|
153
|
+
if (!distributionId) {
|
|
154
|
+
throw new SyncReactError(400, "distribution_id_required");
|
|
155
|
+
}
|
|
156
|
+
const config = resolveRequestConfig(options);
|
|
157
|
+
const _a2 = input, { distributionId: _unused } = _a2, body = __objRest(_a2, ["distributionId"]);
|
|
158
|
+
return requestJSON(
|
|
159
|
+
config,
|
|
160
|
+
`/claims/${encodeURIComponent(distributionId)}/create-transaction`,
|
|
161
|
+
{
|
|
162
|
+
method: "POST",
|
|
163
|
+
body: JSON.stringify(body)
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
async function commitClaim(input, options) {
|
|
168
|
+
const distributionId = input == null ? void 0 : input.distributionId;
|
|
169
|
+
if (!distributionId) {
|
|
170
|
+
throw new SyncReactError(400, "distribution_id_required");
|
|
171
|
+
}
|
|
172
|
+
if (!(input == null ? void 0 : input.signedTransactionBase64)) {
|
|
173
|
+
throw new SyncReactError(400, "signed_transaction_required");
|
|
174
|
+
}
|
|
175
|
+
if (!(input == null ? void 0 : input.claimantPubkey)) {
|
|
176
|
+
throw new SyncReactError(400, "claimant_pubkey_required");
|
|
177
|
+
}
|
|
178
|
+
const config = resolveRequestConfig(options);
|
|
179
|
+
const _a2 = input, { distributionId: _unused } = _a2, body = __objRest(_a2, ["distributionId"]);
|
|
180
|
+
return requestJSON(
|
|
181
|
+
config,
|
|
182
|
+
`/claims/${encodeURIComponent(distributionId)}/commit`,
|
|
183
|
+
{
|
|
184
|
+
method: "POST",
|
|
185
|
+
body: JSON.stringify(body)
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
async function listClaimable(options) {
|
|
190
|
+
const config = resolveRequestConfig(options);
|
|
191
|
+
return requestJSON(config, "/claims/me", { method: "GET" });
|
|
192
|
+
}
|
|
193
|
+
async function listClaimHistory(options) {
|
|
194
|
+
const config = resolveRequestConfig(options);
|
|
195
|
+
return requestJSON(config, "/claims/history", { method: "GET" });
|
|
196
|
+
}
|
|
197
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
198
|
+
0 && (module.exports = {
|
|
199
|
+
DEFAULT_BASE_PATH,
|
|
200
|
+
SyncReactError,
|
|
201
|
+
buildClaimTransaction,
|
|
202
|
+
buildUrl,
|
|
203
|
+
commitClaim,
|
|
204
|
+
isAbsoluteUrl,
|
|
205
|
+
isRelativeUrl,
|
|
206
|
+
listClaimHistory,
|
|
207
|
+
listClaimable,
|
|
208
|
+
requestJSON,
|
|
209
|
+
resolveFetcher,
|
|
210
|
+
resolveRequestConfig,
|
|
211
|
+
sanitizeBasePath
|
|
212
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_BASE_PATH,
|
|
3
|
+
SyncReactError,
|
|
4
|
+
buildClaimTransaction,
|
|
5
|
+
buildUrl,
|
|
6
|
+
commitClaim,
|
|
7
|
+
isAbsoluteUrl,
|
|
8
|
+
isRelativeUrl,
|
|
9
|
+
listClaimHistory,
|
|
10
|
+
listClaimable,
|
|
11
|
+
requestJSON,
|
|
12
|
+
resolveFetcher,
|
|
13
|
+
resolveRequestConfig,
|
|
14
|
+
sanitizeBasePath
|
|
15
|
+
} from "../../chunk-RTLKOAT7.mjs";
|
|
16
|
+
import "../../chunk-FWCSY2DS.mjs";
|
|
17
|
+
export {
|
|
18
|
+
DEFAULT_BASE_PATH,
|
|
19
|
+
SyncReactError,
|
|
20
|
+
buildClaimTransaction,
|
|
21
|
+
buildUrl,
|
|
22
|
+
commitClaim,
|
|
23
|
+
isAbsoluteUrl,
|
|
24
|
+
isRelativeUrl,
|
|
25
|
+
listClaimHistory,
|
|
26
|
+
listClaimable,
|
|
27
|
+
requestJSON,
|
|
28
|
+
resolveFetcher,
|
|
29
|
+
resolveRequestConfig,
|
|
30
|
+
sanitizeBasePath
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BuildClaimTransactionRequest, BuildClaimTransactionResponse, ClaimHistoryItem, ClaimHistoryResponse, ClaimTransactionInstruction, ClaimTransactionRequest, ClaimTransactionResponse, ClaimableDistribution, ClaimableResponse, CommitClaimRequest, CommitClaimResponse, DEFAULT_BASE_PATH, Fetcher, SyncReactError, SyncRequestConfig, SyncRequestOptions, buildClaimTransaction, buildUrl, commitClaim, isAbsoluteUrl, isRelativeUrl, listClaimHistory, listClaimable, requestJSON, resolveFetcher, resolveRequestConfig, sanitizeBasePath } from './core/index.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BuildClaimTransactionRequest, BuildClaimTransactionResponse, ClaimHistoryItem, ClaimHistoryResponse, ClaimTransactionInstruction, ClaimTransactionRequest, ClaimTransactionResponse, ClaimableDistribution, ClaimableResponse, CommitClaimRequest, CommitClaimResponse, DEFAULT_BASE_PATH, Fetcher, SyncReactError, SyncRequestConfig, SyncRequestOptions, buildClaimTransaction, buildUrl, commitClaim, isAbsoluteUrl, isRelativeUrl, listClaimHistory, listClaimable, requestJSON, resolveFetcher, resolveRequestConfig, sanitizeBasePath } from './core/index.js';
|