squarefi-bff-api-module 1.24.35 → 1.25.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/CHANGELOG.md +200 -7
- package/README.md +60 -10
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useSupabaseSubscription/config.d.ts +2 -0
- package/dist/hooks/useSupabaseSubscription/config.js +9 -0
- package/dist/hooks/useSupabaseSubscription/index.d.ts +3 -0
- package/dist/hooks/useSupabaseSubscription/index.js +7 -0
- package/dist/hooks/useSupabaseSubscription/specialized.d.ts +5 -0
- package/dist/hooks/useSupabaseSubscription/specialized.js +21 -0
- package/dist/hooks/useSupabaseSubscription/types.d.ts +16 -0
- package/dist/hooks/useSupabaseSubscription/types.js +2 -0
- package/dist/hooks/useSupabaseSubscription/useSupabaseSubscription.d.ts +5 -0
- package/dist/hooks/useSupabaseSubscription/useSupabaseSubscription.js +36 -0
- package/dist/utils/supabase.d.ts +1 -0
- package/dist/utils/supabase.js +15 -0
- package/package.json +2 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useSupabaseSubscription/config.ts +7 -0
- package/src/hooks/useSupabaseSubscription/index.ts +3 -0
- package/src/hooks/useSupabaseSubscription/specialized.ts +9 -0
- package/src/hooks/useSupabaseSubscription/types.ts +18 -0
- package/src/hooks/useSupabaseSubscription/useSupabaseSubscription.ts +53 -0
- package/src/utils/supabase.ts +16 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,35 +4,228 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
ƒ
|
|
7
8
|
|
|
8
|
-
## [1.25.
|
|
9
|
+
## [1.25.0] - 2025-08-19
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Real-time functionality with Supabase integration
|
|
14
|
+
|
|
15
|
+
## [1.24.35] - 2025-08-19
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Updated CSV export functionality for wallet transactions to use apiClientV2 and enhanced request type
|
|
20
|
+
|
|
21
|
+
## [1.24.34] - 2025-08-14
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Enhanced TransactionList request type by adding pagination and filtering options
|
|
26
|
+
|
|
27
|
+
## [1.24.33] - 2025-08-14
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- Updated response type for WalletsTransactionsController to include total and data fields
|
|
32
|
+
|
|
33
|
+
## [1.24.32] - 2025-08-14
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- Updated response type for WalletsTransactionsController to include JSON content structure
|
|
38
|
+
|
|
39
|
+
## [1.24.31] - 2025-08-14
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
|
|
43
|
+
- Streamlined TransactionList request type by integrating existing operations and removing redundant fields
|
|
44
|
+
|
|
45
|
+
## [1.24.30] - 2025-08-14
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
|
|
49
|
+
- Removed unused UserData types and enforced required fields for transaction list request
|
|
50
|
+
|
|
51
|
+
## [1.24.29] - 2025-08-11
|
|
52
|
+
|
|
53
|
+
### Added
|
|
54
|
+
|
|
55
|
+
- PURCHASE type to CardTransactionType enum
|
|
56
|
+
|
|
57
|
+
## [1.24.28] - 2025-08-11
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
|
|
61
|
+
- Enforced required fields for transaction list request parameters
|
|
62
|
+
|
|
63
|
+
## [1.24.27] - 2025-08-11
|
|
64
|
+
|
|
65
|
+
### Changed
|
|
66
|
+
|
|
67
|
+
- Updated transaction list API types and simplified transaction retrieval parameters
|
|
68
|
+
|
|
69
|
+
## [1.24.26] - 2025-08-08
|
|
70
|
+
|
|
71
|
+
### Added
|
|
72
|
+
|
|
73
|
+
- Terms confirmation endpoint and types for KYC process
|
|
74
|
+
|
|
75
|
+
## [1.24.25] - 2025-08-08
|
|
76
|
+
|
|
77
|
+
### Added
|
|
78
|
+
|
|
79
|
+
- PAYMENT type to CardTransactionType enum
|
|
80
|
+
|
|
81
|
+
## [1.24.24] - 2025-08-08
|
|
82
|
+
|
|
83
|
+
### Added
|
|
84
|
+
|
|
85
|
+
- DECLINED status to CardTransactionStatus enum
|
|
86
|
+
|
|
87
|
+
## [1.24.23] - 2025-08-08
|
|
88
|
+
|
|
89
|
+
### Added
|
|
90
|
+
|
|
91
|
+
- COMPLETED status to CardTransactionStatus enum
|
|
92
|
+
|
|
93
|
+
## [1.24.22] - 2025-08-06
|
|
94
|
+
|
|
95
|
+
### Fixed
|
|
96
|
+
|
|
97
|
+
- Updated tenant config endpoint and added optional limits property to API types
|
|
98
|
+
|
|
99
|
+
## [1.24.21] - 2025-08-01
|
|
100
|
+
|
|
101
|
+
### Changed
|
|
102
|
+
|
|
103
|
+
- Introduced ExtendedKey interface to enhance key management types in API
|
|
104
|
+
|
|
105
|
+
## [1.24.20] - 2025-08-01
|
|
106
|
+
|
|
107
|
+
### Added
|
|
108
|
+
|
|
109
|
+
- Integrated frontend module into API structure for enhanced functionality
|
|
110
|
+
|
|
111
|
+
## [1.24.19] - 2025-08-01
|
|
112
|
+
|
|
113
|
+
### Added
|
|
114
|
+
|
|
115
|
+
- Frontend access key management types for creating, listing, regenerating, and revoking API keys
|
|
116
|
+
|
|
117
|
+
## [1.24.18] - 2025-08-01
|
|
118
|
+
|
|
119
|
+
### Changed
|
|
120
|
+
|
|
121
|
+
- Made is_subtract and is_reverse fields mandatory in API types for consistency
|
|
122
|
+
|
|
123
|
+
## [1.24.17] - 2025-08-01
|
|
124
|
+
|
|
125
|
+
### Fixed
|
|
126
|
+
|
|
127
|
+
- Corrected spelling of is_subsctract to is_subtract in API types and updated related calculations in useCalc hook
|
|
128
|
+
|
|
129
|
+
## [1.24.16] - 2025-08-01
|
|
130
|
+
|
|
131
|
+
### Added
|
|
132
|
+
|
|
133
|
+
- Optional is_subsctract and is_reverse fields to various transaction types for improved flexibility
|
|
134
|
+
|
|
135
|
+
## [1.24.15] - 2025-07-31
|
|
136
|
+
|
|
137
|
+
### Added
|
|
138
|
+
|
|
139
|
+
- Extended account details with optional ACH, RTP, wire, and SWIFT structures for enhanced payment processing
|
|
140
|
+
|
|
141
|
+
## [1.24.14] - 2025-07-31
|
|
142
|
+
|
|
143
|
+
### Changed
|
|
144
|
+
|
|
145
|
+
- Enhanced issuing API methods to return ExtendedSubAccountResponse with sub_account_id
|
|
146
|
+
|
|
147
|
+
## [1.24.13] - 2025-07-30
|
|
148
|
+
|
|
149
|
+
### Changed
|
|
150
|
+
|
|
151
|
+
- Updated SubAccountResponse type and enhanced balance method to return sub_account_id
|
|
152
|
+
|
|
153
|
+
## [1.24.12] - 2025-07-29
|
|
154
|
+
|
|
155
|
+
### Added
|
|
156
|
+
|
|
157
|
+
- consent_text field to card details type for enhanced data handling
|
|
158
|
+
|
|
159
|
+
## [1.24.11] - 2025-07-28
|
|
9
160
|
|
|
10
161
|
### Added
|
|
11
162
|
|
|
12
163
|
- New wallet transaction record types for card transfers
|
|
13
164
|
|
|
14
|
-
## [1.
|
|
165
|
+
## [1.24.10] - 2025-07-28
|
|
15
166
|
|
|
16
167
|
### Added
|
|
17
168
|
|
|
18
169
|
- RN_CARDS_OFFRAMP order type and corresponding API request/response structures
|
|
19
170
|
|
|
20
|
-
## [1.
|
|
171
|
+
## [1.24.9] - 2025-07-23
|
|
21
172
|
|
|
22
173
|
### Changed
|
|
23
174
|
|
|
24
|
-
-
|
|
25
|
-
|
|
175
|
+
- Removed unnecessary console logs from apiClientFactory and tokensFactory for cleaner code
|
|
176
|
+
|
|
177
|
+
## [1.24.8] - 2025-07-23
|
|
178
|
+
|
|
179
|
+
### Changed
|
|
180
|
+
|
|
181
|
+
- Streamlined refreshTokens by removing miniApp logs and integrating initData restoration
|
|
182
|
+
|
|
183
|
+
## [1.24.7] - 2025-07-23
|
|
184
|
+
|
|
185
|
+
### Fixed
|
|
186
|
+
|
|
187
|
+
- Awaited miniApp.mount() in refreshTokens to ensure proper initialization of the SDK
|
|
188
|
+
|
|
189
|
+
## [1.24.6] - 2025-07-23
|
|
26
190
|
|
|
27
191
|
### Added
|
|
28
192
|
|
|
29
|
-
-
|
|
193
|
+
- Telegram SDK initialization in tokensFactory
|
|
194
|
+
|
|
195
|
+
## [1.24.4] - 2025-07-23
|
|
196
|
+
|
|
197
|
+
### Added
|
|
198
|
+
|
|
199
|
+
- Console logs in tokensFactory for enhanced debugging of initData and miniApp
|
|
200
|
+
|
|
201
|
+
## [1.24.3] - 2025-07-23
|
|
202
|
+
|
|
203
|
+
### Added
|
|
204
|
+
|
|
205
|
+
- Additional console logs in refreshTokens for improved debugging of token handling
|
|
206
|
+
|
|
207
|
+
## [1.24.2] - 2025-07-23
|
|
208
|
+
|
|
209
|
+
### Changed
|
|
210
|
+
|
|
211
|
+
- Improved error handling in refreshTokens function and added debug logs for better traceability
|
|
212
|
+
|
|
213
|
+
## [1.24.1] - 2025-07-23
|
|
214
|
+
|
|
215
|
+
### Added
|
|
216
|
+
|
|
217
|
+
- Console logs for token refresh handling and authentication flow insights
|
|
30
218
|
|
|
31
219
|
## [1.24.0] - 2025-07-23
|
|
32
220
|
|
|
33
221
|
### Changed
|
|
34
222
|
|
|
35
|
-
-
|
|
223
|
+
- Enhanced refresh token handling for Telegram sign-in methods in TMA
|
|
224
|
+
- Updated Telegram auth types to use request/response structures for improved type safety with optional refresh_token
|
|
225
|
+
|
|
226
|
+
### Added
|
|
227
|
+
|
|
228
|
+
- Improved Telegram authentication workflow with better token management
|
|
36
229
|
|
|
37
230
|
## [1.23.5] - 2025-07-22
|
|
38
231
|
|
package/README.md
CHANGED
|
@@ -49,9 +49,19 @@ const cards = await api.issuing.cards.byWalletUuid.getAll({
|
|
|
49
49
|
|
|
50
50
|
// 3) Exchange rates helper
|
|
51
51
|
await api.exchange.byOrderType[OrderType.DEPOSIT_FIAT_SEPA].getByFromCurrency(firstWalletUuid);
|
|
52
|
-
```
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
// 4) Real-time subscriptions (React only)
|
|
54
|
+
import { useSupabaseSubscription } from 'squarefi-bff-api-module';
|
|
55
|
+
|
|
56
|
+
const { isConnected } = useSupabaseSubscription({
|
|
57
|
+
config: {
|
|
58
|
+
channelName: 'my-channel',
|
|
59
|
+
table: 'transactions',
|
|
60
|
+
event: '*',
|
|
61
|
+
},
|
|
62
|
+
callback: (payload) => console.log('Real-time update:', payload),
|
|
63
|
+
});
|
|
64
|
+
```
|
|
55
65
|
|
|
56
66
|
---
|
|
57
67
|
|
|
@@ -59,19 +69,59 @@ See the [Examples](#examples) section below for more real-life snippets.
|
|
|
59
69
|
|
|
60
70
|
The SDK reads connection details from process-level variables. When bundling for the browser, tools like **Vite**, **Webpack DefinePlugin**, or **Next.js** can safely inline those values at build time.
|
|
61
71
|
|
|
62
|
-
| Name | Description | Required
|
|
63
|
-
| -------------------------- | -------------------------------------------------------------------- |
|
|
64
|
-
| `API_URL` | Base URL of the BFF **v1** service | ✅
|
|
65
|
-
| `API_V2_URL` | Base URL of the BFF **v2** service | ✅
|
|
66
|
-
| `API_TOTP_URL` | Base URL of the **TOTP / OTP** micro-service | ⚠️ _If you use TOTP features_
|
|
67
|
-
| `TENANT_ID` | Your tenant / organisation identifier | ✅
|
|
68
|
-
| `LOGOUT_URL` | Frontend route where the user is redirected when refresh token fails | ❌
|
|
69
|
-
| `SERVER_PUBLIC_KEY_BASE64` | PEM encoded key (base64) used for request signing | ✅
|
|
72
|
+
| Name | Description | Required | Example |
|
|
73
|
+
| -------------------------- | -------------------------------------------------------------------- | ------------------------------ | ----------------------------- |
|
|
74
|
+
| `API_URL` | Base URL of the BFF **v1** service | ✅ | `https://api-v1.squarefi.com` |
|
|
75
|
+
| `API_V2_URL` | Base URL of the BFF **v2** service | ✅ | `https://api-v2.squarefi.com` |
|
|
76
|
+
| `API_TOTP_URL` | Base URL of the **TOTP / OTP** micro-service | ⚠️ _If you use TOTP features_ | `https://totp.squarefi.com` |
|
|
77
|
+
| `TENANT_ID` | Your tenant / organisation identifier | ✅ | `tenant_12345` |
|
|
78
|
+
| `LOGOUT_URL` | Frontend route where the user is redirected when refresh token fails | ❌ | `/auth/logout` |
|
|
79
|
+
| `SERVER_PUBLIC_KEY_BASE64` | PEM encoded key (base64) used for request signing | ✅ | `MIIBIjANBgkqh…` |
|
|
80
|
+
| `SUPABASE_URL` | Supabase project URL for real-time subscriptions | ⚠️ _If you use Supabase hooks_ | `https://xyz.supabase.co` |
|
|
81
|
+
| `SUPABASE_PUBLIC_KEY` | Supabase public anon key for client authentication | ⚠️ _If you use Supabase hooks_ | `eyJhbGciOiJIUzI1NiIs…` |
|
|
70
82
|
|
|
71
83
|
> ℹ️ When running in Node.js you can place these variables in a `.env` file and load them with [dotenv](https://npmjs.com/package/dotenv).
|
|
72
84
|
|
|
73
85
|
---
|
|
74
86
|
|
|
87
|
+
## 🔄 React Hooks
|
|
88
|
+
|
|
89
|
+
The SDK includes React hooks for real-time functionality powered by Supabase:
|
|
90
|
+
|
|
91
|
+
### useSupabaseSubscription
|
|
92
|
+
|
|
93
|
+
A hook for subscribing to real-time database changes via Supabase.
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
import { useSupabaseSubscription } from 'squarefi-bff-api-module';
|
|
97
|
+
|
|
98
|
+
function MyComponent() {
|
|
99
|
+
const { isConnected, isClientAvailable } = useSupabaseSubscription({
|
|
100
|
+
config: {
|
|
101
|
+
channelName: 'wallet-transactions',
|
|
102
|
+
table: 'transactions',
|
|
103
|
+
schema: 'public',
|
|
104
|
+
event: 'INSERT', // 'INSERT' | 'UPDATE' | 'DELETE' | '*'
|
|
105
|
+
filter: 'wallet_id=eq.123',
|
|
106
|
+
},
|
|
107
|
+
callback: (payload) => {
|
|
108
|
+
console.log('New transaction:', payload);
|
|
109
|
+
},
|
|
110
|
+
enabled: true,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
if (!isClientAvailable) {
|
|
114
|
+
return <div>Supabase not configured</div>;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return <div>Status: {isConnected ? 'Connected' : 'Disconnected'}</div>;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
> ⚠️ **Important**: The hook will throw an error if Supabase environment variables are missing and you attempt to use it. Make sure to set `SUPABASE_URL` and `SUPABASE_PUBLIC_KEY` environment variables.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
75
125
|
## 🗺️ API surface
|
|
76
126
|
|
|
77
127
|
`squarefi_bff_api_client` is a plain object where every property is a namespaced group of operations. The list below reflects the current SDK version (v1.18.13).
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWalletTransactionsConfig = void 0;
|
|
4
|
+
const createWalletTransactionsConfig = (walletId) => ({
|
|
5
|
+
channelName: `wallet-transactions-${walletId}`,
|
|
6
|
+
table: 'transactions',
|
|
7
|
+
filter: `wallet_id=eq.${walletId}`,
|
|
8
|
+
});
|
|
9
|
+
exports.createWalletTransactionsConfig = createWalletTransactionsConfig;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useWalletTransactionsSubscription = exports.useSupabaseSubscription = void 0;
|
|
4
|
+
var useSupabaseSubscription_1 = require("./useSupabaseSubscription");
|
|
5
|
+
Object.defineProperty(exports, "useSupabaseSubscription", { enumerable: true, get: function () { return useSupabaseSubscription_1.useSupabaseSubscription; } });
|
|
6
|
+
var specialized_1 = require("./specialized");
|
|
7
|
+
Object.defineProperty(exports, "useWalletTransactionsSubscription", { enumerable: true, get: function () { return specialized_1.useWalletTransactionsSubscription; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.useWalletTransactionsSubscription = void 0;
|
|
15
|
+
const config_1 = require("./config");
|
|
16
|
+
const useSupabaseSubscription_1 = require("./useSupabaseSubscription");
|
|
17
|
+
const useWalletTransactionsSubscription = (_a) => {
|
|
18
|
+
var { walletId } = _a, props = __rest(_a, ["walletId"]);
|
|
19
|
+
return (0, useSupabaseSubscription_1.useSupabaseSubscription)(Object.assign(Object.assign({}, props), { config: (0, config_1.createWalletTransactionsConfig)(walletId || '') }));
|
|
20
|
+
};
|
|
21
|
+
exports.useWalletTransactionsSubscription = useWalletTransactionsSubscription;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface SubscriptionConfig {
|
|
2
|
+
channelName: string;
|
|
3
|
+
table: string;
|
|
4
|
+
schema?: string;
|
|
5
|
+
event?: 'INSERT' | 'UPDATE' | 'DELETE' | '*';
|
|
6
|
+
filter?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface UseSupabaseSubscriptionProps {
|
|
9
|
+
config: SubscriptionConfig;
|
|
10
|
+
callback: (payload?: unknown) => void;
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
key?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface UseWalletTransactionsSubscriptionProps extends Omit<UseSupabaseSubscriptionProps, 'config'> {
|
|
15
|
+
walletId: string | undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useSupabaseSubscription = void 0;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const supabase_1 = require("../../utils/supabase");
|
|
7
|
+
const useSupabaseSubscription = ({ config, callback, enabled = true, key }) => {
|
|
8
|
+
const subscriptionRef = (0, react_1.useRef)(null);
|
|
9
|
+
const callbackRef = (0, react_1.useRef)(callback);
|
|
10
|
+
callbackRef.current = callback;
|
|
11
|
+
(0, react_1.useEffect)(() => {
|
|
12
|
+
if (!enabled || !supabase_1.supabaseClient) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (subscriptionRef.current) {
|
|
16
|
+
supabase_1.supabaseClient.removeChannel(subscriptionRef.current);
|
|
17
|
+
subscriptionRef.current = null;
|
|
18
|
+
}
|
|
19
|
+
const subscription = supabase_1.supabaseClient
|
|
20
|
+
.channel(config.channelName)
|
|
21
|
+
.on('postgres_changes', Object.assign({ event: config.event || '*', schema: config.schema || 'public', table: config.table }, (config.filter && { filter: config.filter })), (payload) => callbackRef.current(payload))
|
|
22
|
+
.subscribe();
|
|
23
|
+
subscriptionRef.current = subscription;
|
|
24
|
+
return () => {
|
|
25
|
+
if (subscriptionRef.current && supabase_1.supabaseClient) {
|
|
26
|
+
supabase_1.supabaseClient.removeChannel(subscriptionRef.current);
|
|
27
|
+
subscriptionRef.current = null;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}, [enabled, config.channelName, config.table, config.schema, config.event, config.filter, supabase_1.supabaseClient, key]);
|
|
31
|
+
return {
|
|
32
|
+
isConnected: !!subscriptionRef.current,
|
|
33
|
+
isClientAvailable: !!supabase_1.supabaseClient,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.useSupabaseSubscription = useSupabaseSubscription;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const supabaseClient: import("@supabase/supabase-js").SupabaseClient<any, "public", any> | null;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.supabaseClient = void 0;
|
|
4
|
+
const supabase_js_1 = require("@supabase/supabase-js");
|
|
5
|
+
// Создаем клиент только если есть необходимые environment переменные
|
|
6
|
+
const createSupabaseClient = () => {
|
|
7
|
+
const supabaseUrl = process.env.SUPABASE_URL;
|
|
8
|
+
const supabasePublicKey = process.env.SUPABASE_PUBLIC_KEY;
|
|
9
|
+
if (!supabaseUrl || !supabasePublicKey) {
|
|
10
|
+
console.warn('Supabase environment variables are missing. Client will not be created.');
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return (0, supabase_js_1.createClient)(supabaseUrl, supabasePublicKey);
|
|
14
|
+
};
|
|
15
|
+
exports.supabaseClient = createSupabaseClient();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "squarefi-bff-api-module",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.1",
|
|
4
4
|
"description": "Squarefi BFF API client module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"author": "Your Name",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@supabase/supabase-js": "^2.55.0",
|
|
26
27
|
"@telegram-apps/sdk-react": "^3.1.2",
|
|
27
28
|
"axios": "^1.6.7",
|
|
28
29
|
"lodash.debounce": "^4.0.8",
|
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createWalletTransactionsConfig } from './config';
|
|
2
|
+
import { UseWalletTransactionsSubscriptionProps } from './types';
|
|
3
|
+
import { useSupabaseSubscription } from './useSupabaseSubscription';
|
|
4
|
+
|
|
5
|
+
export const useWalletTransactionsSubscription = ({ walletId, ...props }: UseWalletTransactionsSubscriptionProps) =>
|
|
6
|
+
useSupabaseSubscription({
|
|
7
|
+
...props,
|
|
8
|
+
config: createWalletTransactionsConfig(walletId || ''),
|
|
9
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface SubscriptionConfig {
|
|
2
|
+
channelName: string;
|
|
3
|
+
table: string;
|
|
4
|
+
schema?: string;
|
|
5
|
+
event?: 'INSERT' | 'UPDATE' | 'DELETE' | '*';
|
|
6
|
+
filter?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface UseSupabaseSubscriptionProps {
|
|
10
|
+
config: SubscriptionConfig;
|
|
11
|
+
callback: (payload?: unknown) => void;
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
key?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface UseWalletTransactionsSubscriptionProps extends Omit<UseSupabaseSubscriptionProps, 'config'> {
|
|
17
|
+
walletId: string | undefined;
|
|
18
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
|
|
5
|
+
import { UseSupabaseSubscriptionProps } from './types';
|
|
6
|
+
|
|
7
|
+
import { supabaseClient } from '../../utils/supabase';
|
|
8
|
+
|
|
9
|
+
export const useSupabaseSubscription = ({ config, callback, enabled = true, key }: UseSupabaseSubscriptionProps) => {
|
|
10
|
+
const subscriptionRef = useRef<any>(null);
|
|
11
|
+
const callbackRef = useRef(callback);
|
|
12
|
+
|
|
13
|
+
callbackRef.current = callback;
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!enabled || !supabaseClient) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (subscriptionRef.current) {
|
|
21
|
+
supabaseClient.removeChannel(subscriptionRef.current);
|
|
22
|
+
subscriptionRef.current = null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const subscription = supabaseClient
|
|
26
|
+
.channel(config.channelName)
|
|
27
|
+
.on(
|
|
28
|
+
'postgres_changes' as any,
|
|
29
|
+
{
|
|
30
|
+
event: config.event || '*',
|
|
31
|
+
schema: config.schema || 'public',
|
|
32
|
+
table: config.table,
|
|
33
|
+
...(config.filter && { filter: config.filter }),
|
|
34
|
+
},
|
|
35
|
+
(payload) => callbackRef.current(payload)
|
|
36
|
+
)
|
|
37
|
+
.subscribe();
|
|
38
|
+
|
|
39
|
+
subscriptionRef.current = subscription;
|
|
40
|
+
|
|
41
|
+
return () => {
|
|
42
|
+
if (subscriptionRef.current && supabaseClient) {
|
|
43
|
+
supabaseClient.removeChannel(subscriptionRef.current);
|
|
44
|
+
subscriptionRef.current = null;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}, [enabled, config.channelName, config.table, config.schema, config.event, config.filter, supabaseClient, key]);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
isConnected: !!subscriptionRef.current,
|
|
51
|
+
isClientAvailable: !!supabaseClient,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createClient } from '@supabase/supabase-js';
|
|
2
|
+
|
|
3
|
+
// Создаем клиент только если есть необходимые environment переменные
|
|
4
|
+
const createSupabaseClient = () => {
|
|
5
|
+
const supabaseUrl = process.env.SUPABASE_URL;
|
|
6
|
+
const supabasePublicKey = process.env.SUPABASE_PUBLIC_KEY;
|
|
7
|
+
|
|
8
|
+
if (!supabaseUrl || !supabasePublicKey) {
|
|
9
|
+
console.warn('Supabase environment variables are missing. Client will not be created.');
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return createClient(supabaseUrl, supabasePublicKey);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const supabaseClient = createSupabaseClient();
|