@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.
Files changed (43) hide show
  1. package/README.md +43 -11
  2. package/dist/chunk-4VKCXC52.mjs +129 -0
  3. package/dist/chunk-4ZYNBLY5.mjs +129 -0
  4. package/dist/chunk-DUDWBTA2.mjs +0 -0
  5. package/dist/chunk-FBL2T6BA.mjs +249 -0
  6. package/dist/chunk-ZIWHYEXE.mjs +498 -0
  7. package/dist/index.d.mts +1 -3
  8. package/dist/index.d.ts +1 -3
  9. package/dist/index.js +19 -649
  10. package/dist/index.mjs +7 -42
  11. package/dist/v1/core/index.d.mts +28 -0
  12. package/dist/v1/core/index.d.ts +28 -0
  13. package/dist/v1/core/index.js +320 -0
  14. package/dist/v1/core/index.mjs +51 -0
  15. package/dist/v1/index.d.mts +3 -0
  16. package/dist/v1/index.d.ts +3 -0
  17. package/dist/v1/index.js +816 -0
  18. package/dist/v1/index.mjs +63 -0
  19. package/dist/v1/react/index.d.mts +111 -0
  20. package/dist/v1/react/index.d.ts +111 -0
  21. package/dist/v1/react/index.js +552 -0
  22. package/dist/v1/react/index.mjs +330 -0
  23. package/dist/v1/server/index.d.mts +67 -0
  24. package/dist/v1/server/index.d.ts +67 -0
  25. package/dist/v1/server/index.js +540 -0
  26. package/dist/v1/server/index.mjs +15 -0
  27. package/dist/v1/widgets/index.d.mts +2 -0
  28. package/dist/v1/widgets/index.d.ts +2 -0
  29. package/dist/v1/widgets/index.js +18 -0
  30. package/dist/v1/widgets/index.mjs +0 -0
  31. package/dist/v2/core/index.d.mts +5 -21
  32. package/dist/v2/core/index.d.ts +5 -21
  33. package/dist/v2/core/index.js +9 -35
  34. package/dist/v2/core/index.mjs +3 -7
  35. package/dist/v2/index.d.mts +1 -1
  36. package/dist/v2/index.d.ts +1 -1
  37. package/dist/v2/index.js +9 -35
  38. package/dist/v2/index.mjs +4 -7
  39. package/dist/v2/react/index.d.mts +5 -27
  40. package/dist/v2/react/index.d.ts +5 -27
  41. package/dist/v2/react/index.js +26 -108
  42. package/dist/v2/react/index.mjs +20 -76
  43. package/package.json +52 -21
@@ -2,20 +2,19 @@ import {
2
2
  DEFAULT_BASE_PATH,
3
3
  SyncReactError,
4
4
  buildClaimTransaction,
5
- commitClaim,
6
- listClaimHistory,
7
- listClaimable,
5
+ listClaims,
8
6
  requestJSON,
9
7
  resolveFetcher,
10
8
  sanitizeBasePath
11
- } from "../../chunk-RTLKOAT7.mjs";
9
+ } from "../../chunk-4VKCXC52.mjs";
12
10
  import {
13
11
  __spreadProps,
14
12
  __spreadValues
15
13
  } from "../../chunk-FWCSY2DS.mjs";
16
14
 
17
15
  // src/v2/react/index.tsx
18
- import { createContext, createElement, useCallback, useContext, useMemo, useState } from "react";
16
+ import { createContext, createElement, useContext, useMemo } from "react";
17
+ import { useWallet } from "@solana/wallet-adapter-react";
19
18
  import { useMutation, useQuery } from "@tanstack/react-query";
20
19
  var SyncContext = createContext({ basePath: DEFAULT_BASE_PATH });
21
20
  function SyncProvider({ basePath, fetcher, children }) {
@@ -46,81 +45,29 @@ function useSyncClient() {
46
45
  };
47
46
  }, [requestConfig]);
48
47
  }
49
- function useClaimableDistributions(options) {
48
+ function useClaims(wallet, options) {
49
+ var _a, _b, _c;
50
+ const walletContext = useWallet();
50
51
  const requestConfig = useSyncRequestConfig();
51
- return useQuery(__spreadValues({
52
- queryKey: ["sync", "v2", "claims", "me"],
53
- queryFn: () => listClaimable(requestConfig)
54
- }, options));
55
- }
56
- function useClaimHistory(options) {
57
- const requestConfig = useSyncRequestConfig();
58
- return useQuery(__spreadValues({
59
- queryKey: ["sync", "v2", "claims", "history"],
60
- queryFn: () => listClaimHistory(requestConfig)
61
- }, options));
62
- }
63
- function useClaimTransaction(distributionId, options) {
64
- const requestConfig = useSyncRequestConfig();
65
- const id = distributionId || null;
66
- return useMutation(__spreadValues({
67
- mutationFn: async (input = {}) => {
68
- if (!id) throw new SyncReactError(400, "distribution_id_required");
69
- return buildClaimTransaction(__spreadProps(__spreadValues({}, input), { distributionId: id }), requestConfig);
70
- }
71
- }, options));
52
+ const resolvedWallet = (_b = wallet != null ? wallet : (_a = walletContext == null ? void 0 : walletContext.publicKey) == null ? void 0 : _a.toBase58()) != null ? _b : null;
53
+ const enabled = Boolean(resolvedWallet) && ((_c = options == null ? void 0 : options.enabled) != null ? _c : true);
54
+ return useQuery(__spreadProps(__spreadValues({
55
+ queryKey: ["sync", "v2", "claims", resolvedWallet != null ? resolvedWallet : ""],
56
+ queryFn: () => listClaims(resolvedWallet || "", requestConfig)
57
+ }, options), {
58
+ enabled
59
+ }));
72
60
  }
73
- function useCommitClaim(distributionId, options) {
61
+ function useClaimTransaction(options) {
74
62
  const requestConfig = useSyncRequestConfig();
75
- const id = distributionId || null;
76
63
  return useMutation(__spreadValues({
77
64
  mutationFn: async (input) => {
78
- if (!id) throw new SyncReactError(400, "distribution_id_required");
79
- if (!(input == null ? void 0 : input.signedTransactionBase64)) throw new SyncReactError(400, "signed_transaction_required");
80
- if (!(input == null ? void 0 : input.claimantPubkey)) throw new SyncReactError(400, "claimant_pubkey_required");
81
- return commitClaim(__spreadProps(__spreadValues({}, input), { distributionId: id }), requestConfig);
65
+ if (!(input == null ? void 0 : input.distributionId)) throw new SyncReactError(400, "distribution_id_required");
66
+ if (!(input == null ? void 0 : input.claimant)) throw new SyncReactError(400, "claimant_required");
67
+ return buildClaimTransaction(input, requestConfig);
82
68
  }
83
69
  }, options));
84
70
  }
85
- function useClaimFlow(distributionId) {
86
- var _a, _b;
87
- const buildMutation = useClaimTransaction(distributionId);
88
- const commitMutation = useCommitClaim(distributionId);
89
- const [latestPayload, setLatestPayload] = useState(null);
90
- const build = useCallback(
91
- async (input) => {
92
- const payload = await buildMutation.mutateAsync(input != null ? input : {});
93
- setLatestPayload(payload);
94
- return payload;
95
- },
96
- [buildMutation]
97
- );
98
- const claim = useCallback(
99
- async (signer, input) => {
100
- const payload = await build(input);
101
- const signerInput = await signer(payload);
102
- if (!(signerInput == null ? void 0 : signerInput.signedTransactionBase64)) {
103
- throw new SyncReactError(400, "signed_transaction_required");
104
- }
105
- if (!(signerInput == null ? void 0 : signerInput.claimantPubkey)) {
106
- throw new SyncReactError(400, "claimant_pubkey_required");
107
- }
108
- const commit = await commitMutation.mutateAsync(signerInput);
109
- return { payload, commit, signerInput };
110
- },
111
- [build, commitMutation]
112
- );
113
- const reset = useCallback(() => {
114
- setLatestPayload(null);
115
- }, []);
116
- const state = {
117
- latestPayload,
118
- building: buildMutation.isPending,
119
- claiming: commitMutation.isPending,
120
- error: (_b = (_a = buildMutation.error) != null ? _a : commitMutation.error) != null ? _b : null
121
- };
122
- return { state, build, claim, reset };
123
- }
124
71
  function useSyncRequestConfig() {
125
72
  const context = useContext(SyncContext);
126
73
  const basePath = sanitizeBasePath((context == null ? void 0 : context.basePath) || DEFAULT_BASE_PATH);
@@ -129,10 +76,7 @@ function useSyncRequestConfig() {
129
76
  }
130
77
  export {
131
78
  SyncProvider,
132
- useClaimFlow,
133
- useClaimHistory,
134
79
  useClaimTransaction,
135
- useClaimableDistributions,
136
- useCommitClaim,
80
+ useClaims,
137
81
  useSyncClient
138
82
  };
package/package.json CHANGED
@@ -1,15 +1,40 @@
1
1
  {
2
2
  "name": "@fractalshq/sync",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Fractals Sync SDK: shared types, server client, React hooks, and widgets",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
5
+ "main": "dist/v2/index.js",
6
+ "module": "dist/v2/index.mjs",
7
+ "types": "dist/v2/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
10
+ "types": "./dist/v2/index.d.ts",
11
+ "import": "./dist/v2/index.mjs",
12
+ "require": "./dist/v2/index.js"
13
+ },
14
+ "./v1": {
15
+ "types": "./dist/v1/index.d.ts",
16
+ "import": "./dist/v1/index.mjs",
17
+ "require": "./dist/v1/index.js"
18
+ },
19
+ "./v1/core": {
20
+ "types": "./dist/v1/core/index.d.ts",
21
+ "import": "./dist/v1/core/index.mjs",
22
+ "require": "./dist/v1/core/index.js"
23
+ },
24
+ "./v1/server": {
25
+ "types": "./dist/v1/server/index.d.ts",
26
+ "import": "./dist/v1/server/index.mjs",
27
+ "require": "./dist/v1/server/index.js"
28
+ },
29
+ "./v1/react": {
30
+ "types": "./dist/v1/react/index.d.ts",
31
+ "import": "./dist/v1/react/index.mjs",
32
+ "require": "./dist/v1/react/index.js"
33
+ },
34
+ "./v1/widgets": {
35
+ "types": "./dist/v1/widgets/index.d.ts",
36
+ "import": "./dist/v1/widgets/index.mjs",
37
+ "require": "./dist/v1/widgets/index.js"
13
38
  },
14
39
  "./v2": {
15
40
  "types": "./dist/v2/index.d.ts",
@@ -27,24 +52,24 @@
27
52
  "require": "./dist/v2/react/index.js"
28
53
  },
29
54
  "./core": {
30
- "types": "./dist/core/index.d.ts",
31
- "import": "./dist/core/index.mjs",
32
- "require": "./dist/core/index.js"
55
+ "types": "./dist/v1/core/index.d.ts",
56
+ "import": "./dist/v1/core/index.mjs",
57
+ "require": "./dist/v1/core/index.js"
33
58
  },
34
59
  "./server": {
35
- "types": "./dist/server/index.d.ts",
36
- "import": "./dist/server/index.mjs",
37
- "require": "./dist/server/index.js"
60
+ "types": "./dist/v1/server/index.d.ts",
61
+ "import": "./dist/v1/server/index.mjs",
62
+ "require": "./dist/v1/server/index.js"
38
63
  },
39
64
  "./react": {
40
- "types": "./dist/react/index.d.ts",
41
- "import": "./dist/react/index.mjs",
42
- "require": "./dist/react/index.js"
65
+ "types": "./dist/v1/react/index.d.ts",
66
+ "import": "./dist/v1/react/index.mjs",
67
+ "require": "./dist/v1/react/index.js"
43
68
  },
44
69
  "./widgets": {
45
- "types": "./dist/widgets/index.d.ts",
46
- "import": "./dist/widgets/index.mjs",
47
- "require": "./dist/widgets/index.js"
70
+ "types": "./dist/v1/widgets/index.d.ts",
71
+ "import": "./dist/v1/widgets/index.mjs",
72
+ "require": "./dist/v1/widgets/index.js"
48
73
  }
49
74
  },
50
75
  "files": [
@@ -52,8 +77,8 @@
52
77
  "README.md"
53
78
  ],
54
79
  "scripts": {
55
- "build": "tsup src/index.ts src/core/index.ts src/server/index.ts src/react/index.tsx src/widgets/index.ts src/v2/index.ts src/v2/core/index.ts src/v2/react/index.tsx --format cjs,esm --dts",
56
- "dev": "tsup src/index.ts src/core/index.ts src/server/index.ts src/react/index.tsx src/widgets/index.ts src/v2/index.ts src/v2/core/index.ts src/v2/react/index.tsx --format cjs,esm --dts --watch",
80
+ "build": "tsup src/index.ts src/v1/index.ts src/v1/core/index.ts src/v1/server/index.ts src/v1/react/index.tsx src/v1/widgets/index.ts src/v2/index.ts src/v2/core/index.ts src/v2/react/index.tsx --format cjs,esm --dts",
81
+ "dev": "tsup src/index.ts src/v1/index.ts src/v1/core/index.ts src/v1/server/index.ts src/v1/react/index.tsx src/v1/widgets/index.ts src/v2/index.ts src/v2/core/index.ts src/v2/react/index.tsx --format cjs,esm --dts --watch",
57
82
  "test": "vitest",
58
83
  "lint": "eslint src --ext .ts,.tsx",
59
84
  "typecheck": "tsc --noEmit"
@@ -71,6 +96,7 @@
71
96
  "dependencies": {
72
97
  "@fractalshq/auth-core": "^0.1.9",
73
98
  "@fractalshq/jito-distributor-sdk": "^1.0.7",
99
+ "@fractalshq/auth-react": "^0.1.17",
74
100
  "@fractalshq/token2022-wrapper": "^0.1.0",
75
101
  "@pythnetwork/price-service-client": "^1.0.0",
76
102
  "@solana/kit": "^5.0.0",
@@ -80,12 +106,16 @@
80
106
  "zod": "^4.1.12"
81
107
  },
82
108
  "peerDependencies": {
109
+ "@solana/wallet-adapter-react": "^0.15.39",
83
110
  "@tanstack/react-query": "^5.0.0",
84
111
  "@trpc/client": "^11.6.0",
85
112
  "@trpc/server": "^11.6.0",
86
113
  "react": ">=18"
87
114
  },
88
115
  "peerDependenciesMeta": {
116
+ "@solana/wallet-adapter-react": {
117
+ "optional": false
118
+ },
89
119
  "@tanstack/react-query": {
90
120
  "optional": false
91
121
  },
@@ -97,6 +127,7 @@
97
127
  }
98
128
  },
99
129
  "devDependencies": {
130
+ "@solana/wallet-adapter-react": "^0.15.39",
100
131
  "@tanstack/react-query": "^5.90.0",
101
132
  "@types/node": "^20",
102
133
  "tsup": "^8.0.0",