squarefi-bff-api-module 1.32.1 → 1.32.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 (125) hide show
  1. package/dist/api/auth.d.ts +29 -0
  2. package/dist/api/auth.js +59 -0
  3. package/dist/api/bank-data.d.ts +4 -0
  4. package/dist/api/bank-data.js +6 -0
  5. package/dist/api/counterparties.d.ts +14 -0
  6. package/dist/api/counterparties.js +16 -0
  7. package/dist/api/developer.d.ts +12 -0
  8. package/dist/api/developer.js +12 -0
  9. package/dist/api/exchange.d.ts +14 -0
  10. package/dist/api/exchange.js +20 -0
  11. package/dist/api/frontend.d.ts +11 -0
  12. package/dist/api/frontend.js +11 -0
  13. package/dist/api/index.d.ts +38 -0
  14. package/dist/api/index.js +36 -0
  15. package/dist/api/issuing.d.ts +64 -0
  16. package/dist/api/issuing.js +140 -0
  17. package/dist/api/kyc.d.ts +21 -0
  18. package/dist/api/kyc.js +21 -0
  19. package/dist/api/list.d.ts +16 -0
  20. package/dist/api/list.js +16 -0
  21. package/dist/api/orders.d.ts +49 -0
  22. package/dist/api/orders.js +84 -0
  23. package/dist/api/persona.d.ts +7 -0
  24. package/dist/api/persona.js +7 -0
  25. package/dist/api/storage.d.ts +8 -0
  26. package/dist/api/storage.js +16 -0
  27. package/dist/api/tenants.d.ts +6 -0
  28. package/dist/api/tenants.js +6 -0
  29. package/dist/api/totp.d.ts +17 -0
  30. package/dist/api/totp.js +45 -0
  31. package/{src/api/types/autogen/apiV2.types.ts → dist/api/types/autogen/apiV2.types.d.ts} +0 -1
  32. package/dist/api/types/autogen/apiV2.types.js +5 -0
  33. package/dist/api/types/types.d.ts +2258 -0
  34. package/dist/api/types/types.js +1 -0
  35. package/dist/api/user.d.ts +18 -0
  36. package/dist/api/user.js +18 -0
  37. package/dist/api/virtual-accounts.d.ts +9 -0
  38. package/dist/api/virtual-accounts.js +9 -0
  39. package/dist/api/wallets.d.ts +24 -0
  40. package/dist/api/wallets.js +30 -0
  41. package/dist/constants.d.ts +303 -0
  42. package/dist/constants.js +332 -0
  43. package/dist/hooks/index.js +3 -0
  44. package/dist/hooks/useCalc.d.ts +25 -0
  45. package/dist/hooks/useCalc.js +115 -0
  46. package/dist/hooks/useFileUpload.d.ts +49 -0
  47. package/dist/hooks/useFileUpload.js +100 -0
  48. package/dist/hooks/useSupabaseSubscription/config.d.ts +2 -0
  49. package/dist/hooks/useSupabaseSubscription/config.js +5 -0
  50. package/dist/hooks/useSupabaseSubscription/index.js +2 -0
  51. package/dist/hooks/useSupabaseSubscription/specialized.d.ts +5 -0
  52. package/{src/hooks/useSupabaseSubscription/specialized.ts → dist/hooks/useSupabaseSubscription/specialized.js} +2 -5
  53. package/dist/hooks/useSupabaseSubscription/types.d.ts +16 -0
  54. package/dist/hooks/useSupabaseSubscription/types.js +1 -0
  55. package/dist/hooks/useSupabaseSubscription/useSupabaseSubscription.d.ts +5 -0
  56. package/dist/hooks/useSupabaseSubscription/useSupabaseSubscription.js +37 -0
  57. package/dist/index.d.ts +7 -0
  58. package/dist/utils/apiClientFactory.d.ts +31 -0
  59. package/dist/utils/apiClientFactory.js +138 -0
  60. package/dist/utils/converters.d.ts +1 -0
  61. package/dist/utils/converters.js +1 -0
  62. package/dist/utils/encrypt.d.ts +10 -0
  63. package/dist/utils/encrypt.js +77 -0
  64. package/dist/utils/fileStorage.d.ts +120 -0
  65. package/dist/utils/fileStorage.js +292 -0
  66. package/dist/utils/storage.d.ts +3 -0
  67. package/dist/utils/storage.js +24 -0
  68. package/dist/utils/supabase.d.ts +1 -0
  69. package/dist/utils/supabase.js +12 -0
  70. package/dist/utils/tokensFactory.d.ts +12 -0
  71. package/dist/utils/tokensFactory.js +42 -0
  72. package/package.json +4 -1
  73. package/.env.example +0 -1
  74. package/.husky/pre-commit +0 -2
  75. package/.prettierignore +0 -6
  76. package/.prettierrc +0 -7
  77. package/CHANGELOG.md +0 -1415
  78. package/FIXED_RLS_ERROR.md +0 -146
  79. package/QUICK_TEST.md +0 -127
  80. package/STORAGE_MODULE_SUMMARY.md +0 -228
  81. package/TEST_INSTRUCTIONS.md +0 -122
  82. package/docs/AUTH_TOKEN_USAGE.md +0 -290
  83. package/docs/BACKEND_SERVICE_URL.md +0 -334
  84. package/docs/FRONTEND_STORAGE_GUIDE.md +0 -529
  85. package/docs/STORAGE_MODULE.md +0 -490
  86. package/docs/STORAGE_QUICK_START.md +0 -76
  87. package/scripts/generate-openapi-types.ts +0 -41
  88. package/scripts/supabase-storage-setup.sql +0 -223
  89. package/src/api/auth.ts +0 -78
  90. package/src/api/bank-data.ts +0 -11
  91. package/src/api/counterparties.ts +0 -73
  92. package/src/api/developer.ts +0 -20
  93. package/src/api/exchange.ts +0 -44
  94. package/src/api/frontend.ts +0 -20
  95. package/src/api/index.ts +0 -57
  96. package/src/api/issuing.ts +0 -214
  97. package/src/api/kyc.ts +0 -41
  98. package/src/api/list.ts +0 -26
  99. package/src/api/orders.ts +0 -255
  100. package/src/api/persona.ts +0 -16
  101. package/src/api/storage.ts +0 -24
  102. package/src/api/tenants.ts +0 -8
  103. package/src/api/totp.ts +0 -51
  104. package/src/api/types/types.ts +0 -2820
  105. package/src/api/user.ts +0 -27
  106. package/src/api/virtual-accounts.ts +0 -15
  107. package/src/api/wallets.ts +0 -65
  108. package/src/constants.ts +0 -343
  109. package/src/hooks/useCalc.ts +0 -181
  110. package/src/hooks/useFileUpload.ts +0 -129
  111. package/src/hooks/useSupabaseSubscription/config.ts +0 -7
  112. package/src/hooks/useSupabaseSubscription/types.ts +0 -18
  113. package/src/hooks/useSupabaseSubscription/useSupabaseSubscription.ts +0 -53
  114. package/src/utils/apiClientFactory.ts +0 -194
  115. package/src/utils/converters.ts +0 -1
  116. package/src/utils/encrypt.ts +0 -96
  117. package/src/utils/fileStorage.ts +0 -353
  118. package/src/utils/storage.ts +0 -29
  119. package/src/utils/supabase.ts +0 -16
  120. package/src/utils/tokensFactory.ts +0 -59
  121. package/tsconfig.json +0 -15
  122. package/types.d.ts +0 -11
  123. /package/{src/hooks/index.ts → dist/hooks/index.d.ts} +0 -0
  124. /package/{src/hooks/useSupabaseSubscription/index.ts → dist/hooks/useSupabaseSubscription/index.d.ts} +0 -0
  125. /package/{src/index.ts → dist/index.js} +0 -0
@@ -1,146 +0,0 @@
1
- # ✅ Fixed: RLS Policy Error
2
-
3
- ## ❌ Problem
4
- ```
5
- new row violates row-level security policy
6
- ```
7
-
8
- ## ✅ Solution
9
- All functions now accept `authToken` parameter!
10
-
11
- ## 🚀 Quick Fix
12
-
13
- ### Before (Error):
14
- ```typescript
15
- const result = await uploadFile({
16
- file: myFile,
17
- fileName: 'test.pdf',
18
- userId: 'user-123',
19
- });
20
- // ❌ Error: RLS policy violation
21
- ```
22
-
23
- ### After (Works):
24
- ```typescript
25
- const authToken = 'your-jwt-token'; // From Supabase Auth
26
-
27
- const result = await uploadFile({
28
- file: myFile,
29
- fileName: 'test.pdf',
30
- userId: 'user-123',
31
- authToken, // ← Add this!
32
- });
33
- // ✅ Success!
34
- ```
35
-
36
- ## 📱 React Hook Usage
37
-
38
- ```typescript
39
- import { useFileUpload } from 'squarefi-bff-api-module';
40
-
41
- function MyComponent() {
42
- const authToken = 'your-jwt-token'; // Get from your auth
43
-
44
- const { upload } = useFileUpload({
45
- userId: 'user-123',
46
- authToken, // ← Add this!
47
- });
48
-
49
- return <input type="file" onChange={(e) => upload(e.target.files[0])} />;
50
- }
51
- ```
52
-
53
- ## 🔑 How to Get Auth Token
54
-
55
- ### Option 1: From Supabase
56
-
57
- ```typescript
58
- import { supabaseClient } from 'squarefi-bff-api-module';
59
-
60
- const { data: { session } } = await supabaseClient.auth.getSession();
61
- const authToken = session?.access_token;
62
- ```
63
-
64
- ### Option 2: From Browser (for testing)
65
-
66
- 1. Login to your app
67
- 2. Open Console (F12)
68
- 3. Run:
69
- ```javascript
70
- const session = await supabaseClient.auth.getSession();
71
- console.log(session.data.session.access_token);
72
- ```
73
- 4. Copy the token
74
-
75
- ### Option 3: From Your Auth System
76
-
77
- ```typescript
78
- // From localStorage
79
- const authToken = localStorage.getItem('access_token');
80
-
81
- // From auth context
82
- const { accessToken } = useAuth();
83
- ```
84
-
85
- ## 📝 Updated API
86
-
87
- All these functions now accept `authToken`:
88
-
89
- | Function | Signature |
90
- |----------|-----------|
91
- | `uploadFile` | `uploadFile({..., authToken})` |
92
- | `getSignedUrl` | `getSignedUrl({..., authToken})` |
93
- | `deleteFile` | `deleteFile(path, bucket, authToken)` |
94
- | `deleteFiles` | `deleteFiles(paths, bucket, authToken)` |
95
- | `listUserFiles` | `listUserFiles(userId, bucket, authToken)` |
96
- | `downloadFile` | `downloadFile(path, bucket, authToken)` |
97
-
98
- ## 🧪 Test Example
99
-
100
- ```typescript
101
- // 1. Get auth token
102
- const authToken = 'eyJhbGci...'; // Your JWT token
103
-
104
- // 2. Upload with token
105
- const result = await uploadFile({
106
- file: myFile,
107
- fileName: 'test.pdf',
108
- userId: 'user-123',
109
- authToken,
110
- });
111
-
112
- console.log(result.success); // true
113
- console.log(result.path); // user-123/test.pdf
114
- ```
115
-
116
- ## 🔒 Why This Works
117
-
118
- RLS policies check `auth.uid()` from JWT token:
119
-
120
- ```sql
121
- -- Policy requires authenticated user
122
- WITH CHECK (
123
- (storage.foldername(name))[1] = auth.uid()::text
124
- )
125
- ```
126
-
127
- - ❌ **Without token**: `auth.uid()` = NULL → Policy fails
128
- - ✅ **With token**: `auth.uid()` = user ID → Policy passes
129
-
130
- ## 📚 Full Documentation
131
-
132
- - **AUTH_TOKEN_USAGE.md** - Complete guide with examples
133
- - **FRONTEND_STORAGE_GUIDE.md** - React usage
134
- - **STORAGE_MODULE.md** - Full API reference
135
-
136
- ## ✅ Changes Summary
137
-
138
- - ✅ Added `authToken` parameter to all storage functions
139
- - ✅ Updated hooks (`useFileUpload`, `useUserFiles`)
140
- - ✅ Backward compatible (token is optional)
141
- - ✅ Creates authenticated client when token provided
142
- - ✅ Project builds successfully
143
-
144
- Now you can upload files from authenticated users! 🎉
145
-
146
-
package/QUICK_TEST.md DELETED
@@ -1,127 +0,0 @@
1
- # Quick Test Guide ⚡
2
-
3
- ## ✅ Исправлено!
4
-
5
- HTML тест был исправлен. Основные проблемы:
6
- - Неправильная инициализация Supabase клиента
7
- - Незакрытый тег script
8
- - Неправильные ссылки на клиент
9
-
10
- ## 🧪 Как протестировать СЕЙЧАС
11
-
12
- ### 1. Откройте test-storage.html в браузере
13
-
14
- Просто двойной клик на файл или:
15
- ```bash
16
- open test-storage.html # macOS
17
- ```
18
-
19
- ### 2. Что вы должны увидеть
20
-
21
- ✅ **Зеленый статус** вверху: "✅ Connected to Supabase"
22
-
23
- ❌ Если видите **красный статус** - проверьте консоль браузера (F12)
24
-
25
- ### 3. Нажмите "Test Connection"
26
-
27
- Должно показать:
28
- ```
29
- ✅ Connection successful!
30
-
31
- Available buckets:
32
- [...список бакетов...]
33
- ```
34
-
35
- ### 4. Попробуйте загрузить файл
36
-
37
- ❌ **Если получите ошибку** типа:
38
- - "Bucket not found" → Нужно создать бакет (см. ниже)
39
- - "Permission denied" → Нужно настроить RLS (см. ниже)
40
-
41
- ## ⚠️ Перед загрузкой файлов
42
-
43
- Нужно выполнить SQL скрипт в Supabase:
44
-
45
- 1. Откройте: https://dpwavvgrlklpuoddutdp.supabase.co
46
- 2. Перейдите в **SQL Editor**
47
- 3. Скопируйте весь файл `scripts/supabase-storage-setup.sql`
48
- 4. Вставьте и нажмите **RUN**
49
-
50
- Это создаст:
51
- - ✅ Бакеты: user-files, documents, images
52
- - ✅ RLS политики для безопасности
53
- - ✅ Функцию is_super_admin()
54
-
55
- ## 🔍 Ожидаемые результаты
56
-
57
- ### ✅ Если SQL выполнен:
58
- - "Test Connection" → Показывает 3 бакета
59
- - "Upload File" → Файл загружается успешно
60
- - "List Files" → Показывает загруженные файлы
61
- - "Get Signed URL" → Генерирует рабочую ссылку
62
-
63
- ### ❌ Если SQL НЕ выполнен:
64
- - "Test Connection" → Может показать пустой список бакетов
65
- - "Upload File" → Ошибка "Bucket not found"
66
- - "List Files" → Ошибка
67
-
68
- ## 🚀 Node.js тест (альтернатива)
69
-
70
- ```bash
71
- node test-storage.js
72
- ```
73
-
74
- Покажет:
75
- ```
76
- 🔍 Testing Supabase Storage Module...
77
-
78
- 1. Testing Supabase client initialization...
79
- ✅ Supabase client initialized successfully
80
-
81
- 2. Testing getPublicUrl function...
82
- ✅ getPublicUrl works
83
-
84
- ✨ Basic tests completed!
85
- ```
86
-
87
- ## 🐛 Troubleshooting
88
-
89
- ### Консоль показывает "supabase is not defined"
90
- - Проблема с CDN загрузкой
91
- - Попробуйте обновить страницу (F5)
92
- - Проверьте интернет-соединение
93
-
94
- ### "Failed to fetch"
95
- - Проверьте URL и ключ в test-storage.html
96
- - Убедитесь, что Supabase проект активен
97
-
98
- ### "Bucket not found"
99
- - Выполните SQL скрипт
100
- - Проверьте название бакета (должно быть 'user-files')
101
-
102
- ### Files не загружаются
103
- - SQL скрипт не выполнен
104
- - RLS политики не настроены
105
- - Неправильный формат user ID
106
-
107
- ## 📊 Что дальше?
108
-
109
- После успешного теста:
110
-
111
- 1. ✅ Используйте модуль в React:
112
- ```tsx
113
- import { useFileUpload } from 'squarefi-bff-api-module';
114
- ```
115
-
116
- 2. ✅ Прочитайте документацию:
117
- - `docs/FRONTEND_STORAGE_GUIDE.md` - Для React
118
- - `docs/STORAGE_MODULE.md` - Полное API
119
- - `docs/STORAGE_QUICK_START.md` - Быстрый старт
120
-
121
- 3. ✅ Настройте `is_super_admin()` под вашу схему пользователей
122
-
123
- ## ✨ Готово!
124
-
125
- Модуль протестирован и готов к использованию!
126
-
127
-
@@ -1,228 +0,0 @@
1
- # Storage Module - Implementation Summary ✅
2
-
3
- ## What Was Created
4
-
5
- ### Core Module Files
6
- ✅ **src/utils/fileStorage.ts** - Main storage module with functions:
7
- - `uploadFile()` - Upload files to Supabase Storage
8
- - `getSignedUrl()` - Get temporary signed URLs (for end users)
9
- - `getPublicUrl()` - Get permanent URLs (for backend with service key)
10
- - `deleteFile()` / `deleteFiles()` - Delete files
11
- - `listUserFiles()` - List user's files
12
- - `downloadFile()` - Download file as Blob
13
- - Constants: `DEFAULT_BUCKET`, `DOCUMENTS_BUCKET`, `IMAGES_BUCKET`
14
-
15
- ✅ **src/hooks/useFileUpload.ts** - React hook for file uploads
16
- - Handles upload state, progress, errors
17
- - Automatic retry logic
18
- - TypeScript types included
19
-
20
- ✅ **src/hooks/useUserFiles.ts** - React hook for file management
21
- - Auto-load files on mount
22
- - Auto-generate signed URLs
23
- - Delete single/multiple files
24
- - Reload functionality
25
-
26
- ### Setup & Configuration
27
- ✅ **scripts/supabase-storage-setup.sql** - SQL script to:
28
- - Create buckets: `user-files`, `documents`, `images` (all private)
29
- - Set up RLS policies for user-level access
30
- - Create `is_super_admin()` function
31
- - Enable Row Level Security
32
-
33
- ### Documentation
34
- ✅ **docs/STORAGE_MODULE.md** - Complete API documentation (English)
35
- ✅ **docs/FRONTEND_STORAGE_GUIDE.md** - React usage guide with examples
36
- ✅ **docs/STORAGE_QUICK_START.md** - 5-minute quick start
37
- ✅ **docs/BACKEND_SERVICE_URL.md** - Backend usage with service role key
38
- ✅ **docs/READY_TO_USE_COMPONENT.tsx** - Copy-paste ready FileManager component
39
- ✅ **TEST_INSTRUCTIONS.md** - Testing guide
40
- ✅ **README.md** - Updated with Storage module section
41
-
42
- ### Test Files
43
- ✅ **test-storage.js** - Node.js connection test
44
- ✅ **test-storage.html** - Interactive browser test UI
45
-
46
- ## Build Status
47
-
48
- ✅ **TypeScript compilation:** PASSED
49
- ✅ **Linter:** No errors
50
- ✅ **Supabase connection:** VERIFIED
51
- ✅ **Basic functions:** WORKING
52
-
53
- ## Your Supabase Configuration
54
-
55
- **Project URL:** `https://dpwavvgrlklpuoddutdp.supabase.co`
56
- **Status:** ✅ Connected successfully
57
-
58
- ## Security Features
59
-
60
- ✅ **All buckets are PRIVATE** (`public: false`)
61
- ✅ **Row Level Security (RLS)** enabled
62
- ✅ **User isolation** - Files organized by `{userId}/filename`
63
- ✅ **RLS Policies:**
64
- - Users can only upload to their own folder
65
- - Users can only view/delete their own files
66
- - Superadmins can access all files
67
-
68
- ## Two Types of URLs
69
-
70
- ### 1. Signed URLs (for end users)
71
- ```typescript
72
- const signedUrl = await getSignedUrl({
73
- path: 'user-123/file.pdf',
74
- expiresIn: 3600 // 1 hour
75
- });
76
- // ✅ Expires after 1 hour
77
- // ✅ No authentication required
78
- // ✅ Safe to share with users
79
- ```
80
-
81
- ### 2. Public URLs (for backend/superadmin)
82
- ```typescript
83
- const publicUrl = getPublicUrl('user-123/file.pdf');
84
-
85
- // On backend only:
86
- fetch(publicUrl, {
87
- headers: {
88
- 'Authorization': `Bearer ${SUPABASE_SERVICE_ROLE_KEY}`
89
- }
90
- });
91
- // ✅ Permanent URL
92
- // ✅ Requires service role key
93
- // ⚠️ NEVER expose service key on frontend
94
- ```
95
-
96
- ## Usage Examples
97
-
98
- ### React Component
99
- ```tsx
100
- import { useFileUpload, useUserFiles } from 'squarefi-bff-api-module';
101
-
102
- function MyFiles({ userId }) {
103
- const { upload, uploading } = useFileUpload({ userId });
104
- const { files, deleteOne } = useUserFiles({
105
- userId,
106
- autoLoad: true,
107
- autoGenerateUrls: true
108
- });
109
-
110
- return (
111
- <div>
112
- <input type="file" onChange={(e) => upload(e.target.files[0])} />
113
-
114
- {files.map(file => (
115
- <div key={file.id}>
116
- <a href={file.signedUrl}>{file.name}</a>
117
- <button onClick={() => deleteOne(file.name)}>Delete</button>
118
- </div>
119
- ))}
120
- </div>
121
- );
122
- }
123
- ```
124
-
125
- ### Direct API Usage
126
- ```typescript
127
- import { uploadFile, getSignedUrl } from 'squarefi-bff-api-module';
128
-
129
- // Upload
130
- const result = await uploadFile({
131
- file: myFile,
132
- fileName: 'document.pdf',
133
- userId: 'user-123',
134
- });
135
-
136
- // Get URL
137
- const url = await getSignedUrl({
138
- path: result.path,
139
- expiresIn: 3600,
140
- });
141
- ```
142
-
143
- ## Next Steps
144
-
145
- ### 1. Run SQL Setup (REQUIRED!)
146
- ```bash
147
- # In Supabase Dashboard → SQL Editor:
148
- # Copy and execute: scripts/supabase-storage-setup.sql
149
- ```
150
-
151
- ### 2. Customize Admin Function
152
- Update `is_super_admin()` in SQL script to match your user schema:
153
- ```sql
154
- CREATE OR REPLACE FUNCTION public.is_super_admin(user_id uuid)
155
- RETURNS boolean AS $$
156
- BEGIN
157
- -- Update this to match YOUR schema
158
- RETURN EXISTS (
159
- SELECT 1
160
- FROM public.your_users_table
161
- WHERE id = user_id
162
- AND your_role_field = 'admin'
163
- );
164
- END;
165
- $$ LANGUAGE plpgsql SECURITY DEFINER;
166
- ```
167
-
168
- ### 3. Test the Module
169
- ```bash
170
- # Node.js test
171
- node test-storage.js
172
-
173
- # Browser test
174
- # Open test-storage.html in browser
175
- ```
176
-
177
- ### 4. Use in Your App
178
- ```bash
179
- # Import and use the hooks/functions
180
- import { useFileUpload } from 'squarefi-bff-api-module';
181
- ```
182
-
183
- ## File Structure
184
-
185
- ```
186
- bff-api-module-npm/
187
- ├── src/
188
- │ ├── utils/
189
- │ │ ├── fileStorage.ts # Main storage module
190
- │ │ └── supabase.ts # Supabase client
191
- │ └── hooks/
192
- │ ├── useFileUpload.ts # Upload hook
193
- │ └── useUserFiles.ts # File list hook
194
- ├── scripts/
195
- │ └── supabase-storage-setup.sql # Setup script
196
- ├── docs/
197
- │ ├── STORAGE_MODULE.md # Full docs
198
- │ ├── FRONTEND_STORAGE_GUIDE.md # React guide
199
- │ ├── BACKEND_SERVICE_URL.md # Backend guide
200
- │ ├── STORAGE_QUICK_START.md # Quick start
201
- │ └── READY_TO_USE_COMPONENT.tsx # Copy-paste component
202
- ├── test-storage.js # Node test
203
- ├── test-storage.html # Browser test
204
- └── TEST_INSTRUCTIONS.md # Test guide
205
- ```
206
-
207
- ## Important Notes
208
-
209
- ⚠️ **Test files contain your API keys** - They are in `.gitignore` and won't be committed
210
-
211
- ⚠️ **Service Role Key** - Never expose on frontend! Use only on secure backend
212
-
213
- ✅ **Buckets are private** - Files require authentication (signed URL or service key)
214
-
215
- ✅ **User isolation** - Each user's files are in `{userId}/` folder
216
-
217
- ## Support & Documentation
218
-
219
- 📖 Full documentation in `docs/` folder
220
- 🧪 Test files: `test-storage.js` and `test-storage.html`
221
- 📋 Testing guide: `TEST_INSTRUCTIONS.md`
222
- 🎯 Quick start: `docs/STORAGE_QUICK_START.md`
223
-
224
- ## Module is Ready! 🎉
225
-
226
- Everything is implemented, tested, and documented. Just run the SQL setup script and start uploading files!
227
-
228
-
@@ -1,122 +0,0 @@
1
- # Storage Module Testing Instructions
2
-
3
- ## ✅ What's Already Done
4
-
5
- 1. **Project builds successfully** - No TypeScript errors
6
- 2. **Supabase client connects** - Connection to your database verified
7
- 3. **Basic functions work** - URL generation tested
8
-
9
- ## 🧪 How to Test
10
-
11
- ### Option 1: Quick Test (Node.js)
12
- ```bash
13
- node test-storage.js
14
- ```
15
-
16
- ### Option 2: Full Test (Browser)
17
- 1. Open `test-storage.html` in your browser
18
- 2. Click buttons to test each feature:
19
- - **Test Connection** - Verify Supabase connection
20
- - **Upload File** - Try uploading a file
21
- - **List Files** - View uploaded files
22
- - **Generate URLs** - Get signed and public URLs
23
-
24
- ## ⚠️ Important: Run SQL Setup First!
25
-
26
- Before testing file uploads, you need to:
27
-
28
- 1. Open your Supabase Dashboard: https://dpwavvgrlklpuoddutdp.supabase.co
29
- 2. Go to **SQL Editor**
30
- 3. Copy and run the entire `scripts/supabase-storage-setup.sql` script
31
- 4. This will:
32
- - Create buckets: `user-files`, `documents`, `images`
33
- - Set up RLS policies for security
34
- - Create the `is_super_admin()` function
35
-
36
- ## 📋 Test Checklist
37
-
38
- - [ ] SQL script executed in Supabase
39
- - [ ] Run `node test-storage.js` - Should show ✅ all green
40
- - [ ] Open `test-storage.html` - Should connect successfully
41
- - [ ] Upload a test file
42
- - [ ] List files - Should see your uploaded file
43
- - [ ] Generate signed URL - Should be able to open the file
44
- - [ ] Try with different user IDs
45
-
46
- ## 🔧 Customization Needed
47
-
48
- ### Update `is_super_admin()` function
49
-
50
- In `scripts/supabase-storage-setup.sql`, find this function and update it to match your user schema:
51
-
52
- ```sql
53
- CREATE OR REPLACE FUNCTION public.is_super_admin(user_id uuid)
54
- RETURNS boolean AS $$
55
- BEGIN
56
- -- TODO: Update this to match YOUR user table and role field
57
- RETURN EXISTS (
58
- SELECT 1
59
- FROM public.profiles -- Change to your table name
60
- WHERE id = user_id
61
- AND role = 'super_admin' -- Change to your role field
62
- );
63
- END;
64
- $$ LANGUAGE plpgsql SECURITY DEFINER;
65
- ```
66
-
67
- ## 📚 Your API Keys
68
-
69
- **Supabase URL:** `https://dpwavvgrlklpuoddutdp.supabase.co`
70
- **Public Key:** Already configured in test files
71
-
72
- ⚠️ **Security Note:** Never commit your service role key to git!
73
-
74
- ## 🎯 Next Steps
75
-
76
- Once tests pass, you can use the module in your React app:
77
-
78
- ```tsx
79
- import { useFileUpload, useUserFiles } from 'squarefi-bff-api-module';
80
-
81
- function MyComponent() {
82
- const { upload, uploading } = useFileUpload({
83
- userId: 'user-123'
84
- });
85
-
86
- const { files } = useUserFiles({
87
- userId: 'user-123',
88
- autoLoad: true
89
- });
90
-
91
- return (
92
- <div>
93
- <input type="file" onChange={(e) => upload(e.target.files[0])} />
94
- {files.map(f => <div key={f.id}>{f.name}</div>)}
95
- </div>
96
- );
97
- }
98
- ```
99
-
100
- ## 🐛 Troubleshooting
101
-
102
- ### "Bucket not found"
103
- - Run the SQL setup script
104
- - Check bucket name matches `DEFAULT_BUCKET`
105
-
106
- ### "Permission denied"
107
- - RLS policies not set up - run SQL script
108
- - Wrong user ID format
109
- - User not authenticated in Supabase
110
-
111
- ### "File not accessible"
112
- - Private bucket requires signed URL or service role key
113
- - Check if file path is correct: `userId/filename`
114
-
115
- ## 📖 Documentation
116
-
117
- - **Frontend Guide:** `docs/FRONTEND_STORAGE_GUIDE.md`
118
- - **Full API Docs:** `docs/STORAGE_MODULE.md`
119
- - **Backend Usage:** `docs/BACKEND_SERVICE_URL.md`
120
- - **Quick Start:** `docs/STORAGE_QUICK_START.md`
121
-
122
-