@insforge/sdk 0.0.56 → 0.0.57
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/LICENSE +201 -0
- package/README.md +249 -0
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 InsForge
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# insforge-sdk-js
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@insforge/sdk)
|
|
4
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
+
|
|
6
|
+
Official TypeScript/JavaScript SDK for [InsForge](https://github.com/InsForge/InsForge) - A powerful, open-source Backend-as-a-Service (BaaS) platform.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Authentication** - Email/password, OAuth (Google, GitHub), session management
|
|
11
|
+
- **Database** - Full PostgreSQL database access with PostgREST
|
|
12
|
+
- **Storage** - File upload and management with S3-compatible storage
|
|
13
|
+
- **Edge Functions** - Serverless function invocation
|
|
14
|
+
- **AI Integration** - Built-in AI capabilities
|
|
15
|
+
- **TypeScript** - Full TypeScript support with type definitions
|
|
16
|
+
- **Automatic OAuth Handling** - Seamless OAuth callback detection
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @insforge/sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or with yarn:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add @insforge/sdk
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### Initialize the Client
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
import { createClient } from '@insforge/sdk';
|
|
36
|
+
|
|
37
|
+
const insforge = createClient({
|
|
38
|
+
baseUrl: 'http://localhost:7130' // Your InsForge backend URL
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Authentication
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
// Sign up a new user
|
|
46
|
+
const { data, error } = await insforge.auth.signUp({
|
|
47
|
+
email: 'user@example.com',
|
|
48
|
+
password: 'securePassword123',
|
|
49
|
+
name: 'John Doe' // optional
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Sign in with email/password
|
|
53
|
+
const { data, error } = await insforge.auth.signInWithPassword({
|
|
54
|
+
email: 'user@example.com',
|
|
55
|
+
password: 'securePassword123'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// OAuth authentication (Google, GitHub)
|
|
59
|
+
await insforge.auth.signInWithOAuth({
|
|
60
|
+
provider: 'google',
|
|
61
|
+
redirectTo: 'http://localhost:3000/dashboard'
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Get current user
|
|
65
|
+
const { data: user } = await insforge.auth.getCurrentUser();
|
|
66
|
+
|
|
67
|
+
// Sign out
|
|
68
|
+
await insforge.auth.signOut();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Database Operations
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
// Insert data
|
|
75
|
+
const { data, error } = await insforge.database
|
|
76
|
+
.from('posts')
|
|
77
|
+
.insert([
|
|
78
|
+
{ title: 'My First Post', content: 'Hello World!' }
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
// Query data
|
|
82
|
+
const { data, error } = await insforge.database
|
|
83
|
+
.from('posts')
|
|
84
|
+
.select('*')
|
|
85
|
+
.eq('author_id', userId);
|
|
86
|
+
|
|
87
|
+
// Update data
|
|
88
|
+
const { data, error } = await insforge.database
|
|
89
|
+
.from('posts')
|
|
90
|
+
.update({ title: 'Updated Title' })
|
|
91
|
+
.eq('id', postId);
|
|
92
|
+
|
|
93
|
+
// Delete data
|
|
94
|
+
const { data, error } = await insforge.database
|
|
95
|
+
.from('posts')
|
|
96
|
+
.delete()
|
|
97
|
+
.eq('id', postId);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### File Storage
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
// Upload a file
|
|
104
|
+
const file = document.querySelector('input[type="file"]').files[0];
|
|
105
|
+
const { data, error } = await insforge.storage
|
|
106
|
+
.from('avatars')
|
|
107
|
+
.upload(file);
|
|
108
|
+
|
|
109
|
+
// Download a file
|
|
110
|
+
const { data, error } = await insforge.storage
|
|
111
|
+
.from('avatars')
|
|
112
|
+
.download('user-avatar.png');
|
|
113
|
+
|
|
114
|
+
// Delete a file
|
|
115
|
+
const { data, error } = await insforge.storage
|
|
116
|
+
.from('avatars')
|
|
117
|
+
.remove(['user-avatar.png']);
|
|
118
|
+
|
|
119
|
+
// List files
|
|
120
|
+
const { data, error } = await insforge.storage
|
|
121
|
+
.from('avatars')
|
|
122
|
+
.list();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Edge Functions
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
// Invoke an edge function
|
|
129
|
+
const { data, error } = await insforge.functions.invoke('my-function', {
|
|
130
|
+
body: { key: 'value' }
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### AI Integration
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
// Generate text completion
|
|
138
|
+
const { data, error } = await insforge.ai.completion({
|
|
139
|
+
model: 'gpt-3.5-turbo',
|
|
140
|
+
prompt: 'Write a hello world program'
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Analyze an image
|
|
144
|
+
const { data, error } = await insforge.ai.vision({
|
|
145
|
+
imageUrl: 'https://example.com/image.jpg',
|
|
146
|
+
prompt: 'Describe this image'
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Documentation
|
|
151
|
+
|
|
152
|
+
For complete API reference and advanced usage, see:
|
|
153
|
+
|
|
154
|
+
- **[SDK Reference](./SDK-REFERENCE.md)** - Complete API documentation
|
|
155
|
+
- **[InsForge Main Repository](https://github.com/InsForge/InsForge)** - Backend platform and setup guides
|
|
156
|
+
|
|
157
|
+
## Configuration
|
|
158
|
+
|
|
159
|
+
The SDK supports the following configuration options:
|
|
160
|
+
|
|
161
|
+
```javascript
|
|
162
|
+
const insforge = createClient({
|
|
163
|
+
baseUrl: 'http://localhost:7130', // Required: Your InsForge backend URL
|
|
164
|
+
storageStrategy: 'localStorage' // Optional: 'localStorage' or 'memory' (default: 'localStorage')
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## TypeScript Support
|
|
169
|
+
|
|
170
|
+
The SDK is written in TypeScript and provides full type definitions:
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { createClient, InsForgeClient, User, Session } from '@insforge/sdk';
|
|
174
|
+
|
|
175
|
+
const insforge: InsForgeClient = createClient({
|
|
176
|
+
baseUrl: 'http://localhost:7130'
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// Type-safe API calls
|
|
180
|
+
const response: { data: User | null; error: Error | null } =
|
|
181
|
+
await insforge.auth.getCurrentUser();
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Error Handling
|
|
185
|
+
|
|
186
|
+
All SDK methods return a consistent response format:
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
const { data, error } = await insforge.auth.signUp({...});
|
|
190
|
+
|
|
191
|
+
if (error) {
|
|
192
|
+
console.error('Error:', error.message);
|
|
193
|
+
console.error('Status:', error.statusCode);
|
|
194
|
+
} else {
|
|
195
|
+
console.log('Success:', data);
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Browser Support
|
|
200
|
+
|
|
201
|
+
The SDK works in all modern browsers that support:
|
|
202
|
+
- ES6+ features
|
|
203
|
+
- Fetch API
|
|
204
|
+
- LocalStorage (for session management)
|
|
205
|
+
|
|
206
|
+
For Node.js environments, ensure you're using Node.js 18 or higher.
|
|
207
|
+
|
|
208
|
+
## Contributing
|
|
209
|
+
|
|
210
|
+
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
|
|
211
|
+
|
|
212
|
+
### Development Setup
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
# Clone the repository
|
|
216
|
+
git clone https://github.com/InsForge/insforge-sdk-js.git
|
|
217
|
+
cd insforge-sdk-js
|
|
218
|
+
|
|
219
|
+
# Install dependencies
|
|
220
|
+
npm install
|
|
221
|
+
|
|
222
|
+
# Build the SDK
|
|
223
|
+
npm run build
|
|
224
|
+
|
|
225
|
+
# Run tests
|
|
226
|
+
npm test
|
|
227
|
+
|
|
228
|
+
# Run integration tests
|
|
229
|
+
npm run test:integration
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
This project is licensed under the Apache License 2.0 - see the [LICENSE](./LICENSE) file for details.
|
|
235
|
+
|
|
236
|
+
## Community & Support
|
|
237
|
+
|
|
238
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/InsForge/insforge-sdk-js/issues)
|
|
239
|
+
- **Documentation**: [https://docs.insforge.com](https://docs.insforge.com)
|
|
240
|
+
- **Main Repository**: [InsForge Backend Platform](https://github.com/InsForge/InsForge)
|
|
241
|
+
|
|
242
|
+
## Related Projects
|
|
243
|
+
|
|
244
|
+
- **[InsForge](https://github.com/InsForge/InsForge)** - The main InsForge backend platform
|
|
245
|
+
- **[InsForge MCP](https://github.com/InsForge/insforge-mcp)** - Model Context Protocol server for InsForge
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
Built with ❤️ by the InsForge team
|
package/dist/index.js
CHANGED
|
@@ -348,12 +348,14 @@ var Auth = class {
|
|
|
348
348
|
async signUp(request) {
|
|
349
349
|
try {
|
|
350
350
|
const response = await this.http.post("/api/auth/users", request);
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
351
|
+
if (response.accessToken && response.user) {
|
|
352
|
+
const session = {
|
|
353
|
+
accessToken: response.accessToken,
|
|
354
|
+
user: response.user
|
|
355
|
+
};
|
|
356
|
+
this.tokenManager.saveSession(session);
|
|
357
|
+
this.http.setAuthToken(response.accessToken);
|
|
358
|
+
}
|
|
357
359
|
return {
|
|
358
360
|
data: response,
|
|
359
361
|
error: null
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/database-postgrest.ts","../src/modules/auth.ts","../src/modules/storage.ts","../src/modules/ai.ts","../src/modules/functions.ts","../src/client.ts"],"sourcesContent":["/**\n * @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service\n * \n * @packageDocumentation\n */\n\n// Main client\nexport { InsForgeClient } from './client';\n\n// Types\nexport type {\n InsForgeConfig,\n InsForgeConfig as ClientOptions, // Alias for compatibility\n TokenStorage,\n AuthSession,\n ApiError,\n} from './types';\n\nexport { InsForgeError } from './types';\n\n// Re-export shared schemas that SDK users will need\nexport type {\n UserSchema,\n CreateUserRequest,\n CreateSessionRequest,\n AuthErrorResponse,\n} from '@insforge/shared-schemas';\n\n// Re-export auth module for advanced usage\nexport { Auth } from './modules/auth';\n\n// Re-export database module (using postgrest-js)\nexport { Database } from './modules/database-postgrest';\n// Note: QueryBuilder is no longer exported as we use postgrest-js QueryBuilder internally\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\n\n// Re-export AI module\nexport { AI } from './modules/ai';\n\n// Re-export Functions module\nexport { Functions } from './modules/functions';\nexport type { FunctionInvokeOptions } from './modules/functions';\n\n// Re-export utilities for advanced usage\nexport { HttpClient } from './lib/http-client';\nexport { TokenManager } from './lib/token-manager';\n\n// Factory function for creating clients (Supabase-style)\nimport { InsForgeClient } from './client';\nimport { InsForgeConfig } from './types';\n\nexport function createClient(config: InsForgeConfig): InsForgeClient {\n return new InsForgeClient(config);\n}\n\n// Default export for convenience\nexport default InsForgeClient;","/**\n * InsForge SDK Types - only SDK-specific types here\n * Use @insforge/shared-schemas directly for API types\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\n\nexport interface InsForgeConfig {\n /**\n * The base URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n baseUrl?: string;\n\n /**\n * Anonymous API key (optional)\n * Used for public/unauthenticated requests when no user token is set\n */\n anonKey?: string;\n\n /**\n * Edge Function Token (optional)\n * Use this when running in edge functions/serverless with a user's JWT token\n * This token will be used for all authenticated requests\n */\n edgeFunctionToken?: string;\n\n /**\n * Custom fetch implementation (useful for Node.js environments)\n */\n fetch?: typeof fetch;\n\n /**\n * Storage adapter for persisting tokens\n */\n storage?: TokenStorage;\n\n /**\n * Whether to automatically refresh tokens before they expire\n * @default true\n */\n autoRefreshToken?: boolean;\n\n /**\n * Whether to persist session in storage\n * @default true\n */\n persistSession?: boolean;\n\n /**\n * Custom headers to include with every request\n */\n headers?: Record<string, string>;\n}\n\nexport interface TokenStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport interface AuthSession {\n user: UserSchema;\n accessToken: string;\n expiresAt?: Date;\n}\n\nexport interface ApiError {\n error: string;\n message: string;\n statusCode: number;\n nextActions?: string;\n}\n\nexport class InsForgeError extends Error {\n public statusCode: number;\n public error: string;\n public nextActions?: string;\n\n constructor(message: string, statusCode: number, error: string, nextActions?: string) {\n super(message);\n this.name = 'InsForgeError';\n this.statusCode = statusCode;\n this.error = error;\n this.nextActions = nextActions;\n }\n\n static fromApiError(apiError: ApiError): InsForgeError {\n return new InsForgeError(\n apiError.message,\n apiError.statusCode,\n apiError.error,\n apiError.nextActions\n );\n }\n}","import { InsForgeConfig, ApiError, InsForgeError } from '../types';\n\nexport interface RequestOptions extends RequestInit {\n params?: Record<string, string>;\n}\n\nexport class HttpClient {\n public readonly baseUrl: string;\n public readonly fetch: typeof fetch;\n private defaultHeaders: Record<string, string>;\n private anonKey: string | undefined;\n private userToken: string | null = null;\n\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.baseUrl || 'http://localhost:7130';\n // Properly bind fetch to maintain its context\n this.fetch = config.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : undefined as any);\n this.anonKey = config.anonKey;\n this.defaultHeaders = {\n ...config.headers,\n };\n\n if (!this.fetch) {\n throw new Error(\n 'Fetch is not available. Please provide a fetch implementation in the config.'\n );\n }\n }\n\n private buildUrl(path: string, params?: Record<string, string>): string {\n const url = new URL(path, this.baseUrl);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n // For select parameter, preserve the exact formatting by normalizing whitespace\n // This ensures PostgREST relationship queries work correctly\n if (key === 'select') {\n // Normalize multiline select strings for PostgREST:\n // 1. Replace all whitespace (including newlines) with single space\n // 2. Remove spaces inside parentheses for proper PostgREST syntax\n // 3. Keep spaces after commas at the top level for readability\n let normalizedValue = value.replace(/\\s+/g, ' ').trim();\n \n // Fix spaces around parentheses and inside them\n normalizedValue = normalizedValue\n .replace(/\\s*\\(\\s*/g, '(') // Remove spaces around opening parens\n .replace(/\\s*\\)\\s*/g, ')') // Remove spaces around closing parens\n .replace(/\\(\\s+/g, '(') // Remove spaces after opening parens\n .replace(/\\s+\\)/g, ')') // Remove spaces before closing parens\n .replace(/,\\s+(?=[^()]*\\))/g, ','); // Remove spaces after commas inside parens\n \n url.searchParams.append(key, normalizedValue);\n } else {\n url.searchParams.append(key, value);\n }\n });\n }\n return url.toString();\n }\n\n async request<T>(\n method: string,\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { params, headers = {}, body, ...fetchOptions } = options;\n \n const url = this.buildUrl(path, params);\n \n const requestHeaders: Record<string, string> = {\n ...this.defaultHeaders,\n };\n \n // Set Authorization header: prefer user token, fallback to anon key\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n requestHeaders['Authorization'] = `Bearer ${authToken}`;\n }\n \n // Handle body serialization\n let processedBody: any;\n if (body !== undefined) {\n // Check if body is FormData (for file uploads)\n if (typeof FormData !== 'undefined' && body instanceof FormData) {\n // Don't set Content-Type for FormData, let browser set it with boundary\n processedBody = body;\n } else {\n // JSON body\n if (method !== 'GET') {\n requestHeaders['Content-Type'] = 'application/json;charset=UTF-8';\n }\n processedBody = JSON.stringify(body);\n }\n }\n \n Object.assign(requestHeaders, headers);\n \n const response = await this.fetch(url, {\n method,\n headers: requestHeaders,\n body: processedBody,\n ...fetchOptions,\n });\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n // Try to parse JSON response\n let data: any;\n const contentType = response.headers.get('content-type');\n // Check for any JSON content type (including PostgREST's vnd.pgrst.object+json)\n if (contentType?.includes('json')) {\n data = await response.json();\n } else {\n // For non-JSON responses, return text\n data = await response.text();\n }\n\n // Handle errors\n if (!response.ok) {\n if (data && typeof data === 'object' && 'error' in data) {\n // Add the HTTP status code if not already in the data\n if (!data.statusCode && !data.status) {\n data.statusCode = response.status;\n }\n const error = InsForgeError.fromApiError(data as ApiError);\n // Preserve all additional fields from the error response\n Object.keys(data).forEach(key => {\n if (key !== 'error' && key !== 'message' && key !== 'statusCode') {\n (error as any)[key] = data[key];\n }\n });\n throw error;\n }\n throw new InsForgeError(\n `Request failed: ${response.statusText}`,\n response.status,\n 'REQUEST_FAILED'\n );\n }\n\n return data as T;\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('GET', path, options);\n }\n\n post<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n put<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n setAuthToken(token: string | null) {\n this.userToken = token;\n }\n\n getHeaders(): Record<string, string> {\n const headers = { ...this.defaultHeaders };\n \n // Include Authorization header if token is available (same logic as request method)\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n headers['Authorization'] = `Bearer ${authToken}`;\n }\n \n return headers;\n }\n}","import { TokenStorage, AuthSession } from '../types';\n\nconst TOKEN_KEY = 'insforge-auth-token';\nconst USER_KEY = 'insforge-auth-user';\n\nexport class TokenManager {\n private storage: TokenStorage;\n\n constructor(storage?: TokenStorage) {\n if (storage) {\n // Use provided storage\n this.storage = storage;\n } else if (typeof window !== 'undefined' && window.localStorage) {\n // Browser: use localStorage\n this.storage = window.localStorage;\n } else {\n // Node.js: use in-memory storage\n const store = new Map<string, string>();\n this.storage = {\n getItem: (key: string) => store.get(key) || null,\n setItem: (key: string, value: string) => { store.set(key, value); },\n removeItem: (key: string) => { store.delete(key); }\n };\n }\n }\n\n saveSession(session: AuthSession): void {\n this.storage.setItem(TOKEN_KEY, session.accessToken);\n this.storage.setItem(USER_KEY, JSON.stringify(session.user));\n }\n\n getSession(): AuthSession | null {\n const token = this.storage.getItem(TOKEN_KEY);\n const userStr = this.storage.getItem(USER_KEY);\n\n if (!token || !userStr) {\n return null;\n }\n\n try {\n const user = JSON.parse(userStr as string);\n return { accessToken: token as string, user };\n } catch {\n this.clearSession();\n return null;\n }\n }\n\n getAccessToken(): string | null {\n const token = this.storage.getItem(TOKEN_KEY);\n return typeof token === 'string' ? token : null;\n }\n\n clearSession(): void {\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n }\n}","/**\n * Database module using @supabase/postgrest-js\n * Complete replacement for custom QueryBuilder with full PostgREST features\n */\n\nimport { PostgrestClient } from '@supabase/postgrest-js';\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\n\n\n/**\n * Custom fetch that transforms URLs and adds auth\n */\nfunction createInsForgePostgrestFetch(\n httpClient: HttpClient,\n tokenManager: TokenManager\n): typeof fetch {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const url = typeof input === 'string' ? input : input.toString();\n const urlObj = new URL(url);\n \n // Extract table name from pathname\n // postgrest-js sends: http://dummy/tablename?params\n // We need: http://localhost:7130/api/database/records/tablename?params\n const tableName = urlObj.pathname.slice(1); // Remove leading /\n \n // Build InsForge URL\n const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;\n \n // Get auth token from TokenManager or HttpClient\n const token = tokenManager.getAccessToken();\n const httpHeaders = httpClient.getHeaders();\n const authToken = token || httpHeaders['Authorization']?.replace('Bearer ', '');\n \n // Prepare headers\n const headers = new Headers(init?.headers);\n if (authToken && !headers.has('Authorization')) {\n headers.set('Authorization', `Bearer ${authToken}`);\n }\n \n // Make the actual request using native fetch\n const response = await fetch(insforgeUrl, {\n ...init,\n headers\n });\n \n return response;\n };\n}\n\n/**\n * Database client using postgrest-js\n * Drop-in replacement with FULL PostgREST capabilities\n */\nexport class Database {\n private postgrest: PostgrestClient<any, any, any>;\n \n constructor(httpClient: HttpClient, tokenManager: TokenManager) {\n // Create postgrest client with custom fetch\n this.postgrest = new PostgrestClient<any, any, any>('http://dummy', {\n fetch: createInsForgePostgrestFetch(httpClient, tokenManager),\n headers: {}\n });\n }\n \n /**\n * Create a query builder for a table\n * \n * @example\n * // Basic query\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId);\n * \n * // With count (Supabase style!)\n * const { data, error, count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact' })\n * .range(0, 9);\n * \n * // Just get count, no data\n * const { count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact', head: true });\n * \n * // Complex queries with OR\n * const { data } = await client.database\n * .from('posts')\n * .select('*, users!inner(*)')\n * .or('status.eq.active,status.eq.pending');\n * \n * // All features work:\n * - Nested selects\n * - Foreign key expansion \n * - OR/AND/NOT conditions\n * - Count with head\n * - Range pagination\n * - Upserts\n */\n from(table: string) {\n // Return postgrest query builder with all features\n return this.postgrest.from(table);\n }\n}","/**\n * Auth module for InsForge SDK\n * Uses shared schemas for type safety\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\nimport { AuthSession, InsForgeError } from '../types';\nimport { Database } from './database-postgrest';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\n OAuthProvidersSchema,\n} from '@insforge/shared-schemas';\n\nexport class Auth {\n private database: Database;\n \n constructor(\n private http: HttpClient,\n private tokenManager: TokenManager\n ) {\n this.database = new Database(http, tokenManager);\n \n // Auto-detect OAuth callback parameters in the URL\n this.detectOAuthCallback();\n }\n\n /**\n * Automatically detect and handle OAuth callback parameters in the URL\n * This runs on initialization to seamlessly complete the OAuth flow\n * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)\n */\n private detectOAuthCallback(): void {\n // Only run in browser environment\n if (typeof window === 'undefined') return;\n \n try {\n const params = new URLSearchParams(window.location.search);\n \n // Backend returns: access_token, user_id, email, name (optional)\n const accessToken = params.get('access_token');\n const userId = params.get('user_id');\n const email = params.get('email');\n const name = params.get('name');\n \n // Check if we have OAuth callback parameters\n if (accessToken && userId && email) {\n // Create session with the data from backend\n const session: AuthSession = {\n accessToken,\n user: {\n id: userId,\n email: email,\n name: name || '',\n // These fields are not provided by backend OAuth callback\n // They'll be populated when calling getCurrentUser()\n emailVerified: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n } as any,\n };\n \n // Save session and set auth token\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(accessToken);\n \n // Clean up the URL to remove sensitive parameters\n const url = new URL(window.location.href);\n url.searchParams.delete('access_token');\n url.searchParams.delete('user_id');\n url.searchParams.delete('email');\n url.searchParams.delete('name');\n \n // Also handle error case from backend (line 581)\n if (params.has('error')) {\n url.searchParams.delete('error');\n }\n \n // Replace URL without adding to browser history\n window.history.replaceState({}, document.title, url.toString());\n }\n } catch (error) {\n // Silently continue - don't break initialization\n console.debug('OAuth callback detection skipped:', error);\n }\n }\n\n /**\n * Sign up a new user\n */\n async signUp(request: CreateUserRequest): Promise<{\n data: CreateUserResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateUserResponse>('/api/auth/users', request);\n \n // Save session internally\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n return { \n data: response,\n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n error instanceof Error ? error.message : 'An unexpected error occurred during sign up',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with email and password\n */\n async signInWithPassword(request: CreateSessionRequest): Promise<{\n data: CreateSessionResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateSessionResponse>('/api/auth/sessions', request);\n \n // Save session internally\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n return { \n data: response,\n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n 'An unexpected error occurred during sign in',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with OAuth provider\n */\n async signInWithOAuth(options: {\n provider: OAuthProvidersSchema;\n redirectTo?: string;\n skipBrowserRedirect?: boolean;\n }): Promise<{\n data: { url?: string; provider?: string };\n error: InsForgeError | null;\n }> {\n try {\n const { provider, redirectTo, skipBrowserRedirect } = options;\n \n const params = redirectTo \n ? { redirect_uri: redirectTo } \n : undefined;\n \n const endpoint = `/api/auth/oauth/${provider}`;\n const response = await this.http.get<GetOauthUrlResponse>(endpoint, { params });\n \n // Automatically redirect in browser unless told not to\n if (typeof window !== 'undefined' && !skipBrowserRedirect) {\n window.location.href = response.authUrl;\n return { data: {}, error: null };\n }\n\n return { \n data: { \n url: response.authUrl,\n provider \n }, \n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: {}, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: {}, \n error: new InsForgeError(\n 'An unexpected error occurred during OAuth initialization',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign out the current user\n */\n async signOut(): Promise<{ error: InsForgeError | null }> {\n try {\n this.tokenManager.clearSession();\n this.http.setAuthToken(null);\n return { error: null };\n } catch (error) {\n return { \n error: new InsForgeError(\n 'Failed to sign out',\n 500,\n 'SIGNOUT_ERROR'\n )\n };\n }\n }\n\n /**\n * Get the current user with full profile information\n * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)\n */\n async getCurrentUser(): Promise<{\n data: { user: any; profile: any } | null;\n error: any | null;\n }> {\n try {\n // Check if we have a token\n const session = this.tokenManager.getSession();\n if (!session?.accessToken) {\n return { data: null, error: null };\n }\n\n // Call the API for auth info\n this.http.setAuthToken(session.accessToken);\n const authResponse = await this.http.get<GetCurrentSessionResponse>('/api/auth/sessions/current');\n \n // Get the user's profile using query builder\n const { data: profile, error: profileError } = await this.database\n .from('users')\n .select('*')\n .eq('id', authResponse.user.id)\n .single();\n \n // For database errors, return PostgrestError directly\n if (profileError && (profileError as any).code !== 'PGRST116') { // PGRST116 = not found\n return { data: null, error: profileError };\n }\n \n return {\n data: {\n user: authResponse.user,\n profile: profile\n },\n error: null\n };\n } catch (error) {\n // If unauthorized, clear session\n if (error instanceof InsForgeError && error.statusCode === 401) {\n await this.signOut();\n return { data: null, error: null };\n }\n \n // Pass through all other errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n 'An unexpected error occurred while fetching user',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get any user's profile by ID\n * Returns profile information from the users table (nickname, avatar_url, bio, etc.)\n */\n async getProfile(userId: string): Promise<{\n data: any | null;\n error: any | null;\n }> {\n const { data, error } = await this.database\n .from('users')\n .select('*')\n .eq('id', userId)\n .single();\n \n // Handle not found as null, not error\n if (error && (error as any).code === 'PGRST116') {\n return { data: null, error: null };\n }\n \n // Return PostgrestError directly for database operations\n return { data, error };\n }\n\n /**\n * Get the current session (only session data, no API call)\n * Returns the stored JWT token and basic user info from local storage\n */\n getCurrentSession(): {\n data: { session: AuthSession | null };\n error: InsForgeError | null;\n } {\n try {\n const session = this.tokenManager.getSession();\n \n if (session?.accessToken) {\n this.http.setAuthToken(session.accessToken);\n return { data: { session }, error: null };\n }\n\n return { data: { session: null }, error: null };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: { session: null }, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: { session: null }, \n error: new InsForgeError(\n 'An unexpected error occurred while getting session',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Set/Update the current user's profile\n * Updates profile information in the users table (nickname, avatar_url, bio, etc.)\n */\n async setProfile(profile: {\n nickname?: string;\n avatar_url?: string;\n bio?: string;\n birthday?: string;\n [key: string]: any;\n }): Promise<{\n data: any | null;\n error: any | null;\n }> {\n // Get current session to get user ID\n const session = this.tokenManager.getSession();\n if (!session?.accessToken) {\n return { \n data: null, \n error: new InsForgeError(\n 'No authenticated user found',\n 401,\n 'UNAUTHENTICATED'\n )\n };\n }\n \n // If no user ID in session (edge function scenario), fetch it\n if (!session.user?.id) {\n const { data, error } = await this.getCurrentUser();\n if (error) {\n return { data: null, error };\n }\n if (data?.user) {\n session.user = data.user;\n this.tokenManager.saveSession(session);\n }\n }\n\n // Update the profile using query builder\n const { data, error } = await this.database\n .from('users')\n .update(profile)\n .eq('id', session.user.id)\n .select()\n .single();\n \n // Return PostgrestError directly for database operations\n return { data, error };\n }\n\n\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n}\n\ninterface UploadStrategy {\n method: 'direct' | 'presigned';\n uploadUrl: string;\n fields?: Record<string, string>;\n key: string;\n confirmRequired: boolean;\n confirmUrl?: string;\n expiresAt?: Date;\n}\n\ninterface DownloadStrategy {\n method: 'direct' | 'presigned';\n url: string;\n expiresAt?: Date;\n}\n\n/**\n * Storage bucket operations\n */\nexport class StorageBucket {\n constructor(\n private bucketName: string,\n private http: HttpClient\n ) {}\n\n /**\n * Upload a file with a specific key\n * Uses the upload strategy from backend (direct or presigned)\n * @param path - The object key/path\n * @param file - File or Blob to upload\n */\n async upload(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'PUT',\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * Uses the upload strategy from backend (direct or presigned)\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const filename = file instanceof File ? file.name : 'file';\n \n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'POST',\n `/api/storage/buckets/${this.bucketName}/objects`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Internal method to handle presigned URL uploads\n */\n private async uploadWithPresignedUrl(\n strategy: UploadStrategy,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Upload to presigned URL (e.g., S3)\n const formData = new FormData();\n \n // Add all fields from the presigned URL\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be the last field for S3\n formData.append('file', file);\n\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n throw new InsForgeError(\n `Upload to storage failed: ${uploadResponse.statusText}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Confirm upload with backend if required\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n }\n );\n\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, return basic file info\n return {\n data: {\n key: strategy.key,\n bucket: this.bucketName,\n size: file.size,\n mimeType: file.type || 'application/octet-stream',\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n } as StorageFileSchema,\n error: null\n };\n } catch (error) {\n throw error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n );\n }\n }\n\n /**\n * Download a file\n * Uses the download strategy from backend (direct or presigned)\n * @param path - The object key/path\n * Returns the file as a Blob\n */\n async download(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n // Get download strategy from backend - this is required\n const strategyResponse = await this.http.post<DownloadStrategy>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n { expiresIn: 3600 }\n );\n\n // Use URL from strategy\n const downloadUrl = strategyResponse.url;\n \n // Download from the URL\n const headers: HeadersInit = {};\n \n // Only add auth header for direct downloads (not presigned URLs)\n if (strategyResponse.method === 'direct') {\n Object.assign(headers, this.http.getHeaders());\n }\n \n const response = await fetch(downloadUrl, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n try {\n const error = await response.json();\n throw InsForgeError.fromApiError(error);\n } catch {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\n );\n }\n }\n\n const blob = await response.blob();\n return { data: blob, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Get public URL for a file\n * @param path - The object key/path\n */\n getPublicUrl(path: string): string {\n return `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n }\n\n /**\n * List objects in the bucket\n * @param prefix - Filter by key prefix\n * @param search - Search in file names\n * @param limit - Maximum number of results (default: 100, max: 1000)\n * @param offset - Number of results to skip\n */\n async list(options?: {\n prefix?: string;\n search?: string;\n limit?: number;\n offset?: number;\n }): Promise<StorageResponse<ListObjectsResponseSchema>> {\n try {\n const params: Record<string, string> = {};\n \n if (options?.prefix) params.prefix = options.prefix;\n if (options?.search) params.search = options.search;\n if (options?.limit) params.limit = options.limit.toString();\n if (options?.offset) params.offset = options.offset.toString();\n\n const response = await this.http.get<ListObjectsResponseSchema>(\n `/api/storage/buckets/${this.bucketName}/objects`,\n { params }\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'List failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Delete a file\n * @param path - The object key/path\n */\n async remove(path: string): Promise<StorageResponse<{ message: string }>> {\n try {\n const response = await this.http.delete<{ message: string }>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Delete failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n}\n\n/**\n * Storage module for file operations\n */\nexport class Storage {\n constructor(private http: HttpClient) {}\n\n /**\n * Get a bucket instance for operations\n * @param bucketName - Name of the bucket\n */\n from(bucketName: string): StorageBucket {\n return new StorageBucket(bucketName, this.http);\n }\n}","/**\n * AI Module for Insforge SDK\n * Response format roughly matches OpenAI SDK for compatibility\n *\n * The backend handles all the complexity of different AI providers\n * and returns a unified format. This SDK transforms responses to match OpenAI-like format.\n */\n\nimport { HttpClient } from \"../lib/http-client\";\nimport {\n ChatCompletionRequest,\n ChatCompletionResponse,\n ImageGenerationRequest,\n ImageGenerationResponse,\n} from \"@insforge/shared-schemas\";\n\nexport class AI {\n public readonly chat: Chat;\n public readonly images: Images;\n\n constructor(private http: HttpClient) {\n this.chat = new Chat(http);\n this.images = new Images(http);\n }\n}\n\nclass Chat {\n public readonly completions: ChatCompletions;\n\n constructor(http: HttpClient) {\n this.completions = new ChatCompletions(http);\n }\n}\n\nclass ChatCompletions {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a chat completion - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const completion = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Hello!' }]\n * });\n * console.log(completion.choices[0].message.content);\n *\n * // With images\n * const response = await client.ai.chat.completions.create({\n * model: 'gpt-4-vision',\n * messages: [{\n * role: 'user',\n * content: 'What is in this image?',\n * images: [{ url: 'https://example.com/image.jpg' }]\n * }]\n * });\n *\n * // Streaming - returns async iterable\n * const stream = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * stream: true\n * });\n *\n * for await (const chunk of stream) {\n * if (chunk.choices[0]?.delta?.content) {\n * process.stdout.write(chunk.choices[0].delta.content);\n * }\n * }\n * ```\n */\n async create(params: ChatCompletionRequest): Promise<any> {\n // Backend already expects camelCase, no transformation needed\n const backendParams = {\n model: params.model,\n messages: params.messages,\n temperature: params.temperature,\n maxTokens: params.maxTokens,\n topP: params.topP,\n stream: params.stream,\n };\n\n // For streaming, return an async iterable that yields OpenAI-like chunks\n if (params.stream) {\n const headers = this.http.getHeaders();\n headers[\"Content-Type\"] = \"application/json\";\n\n const response = await this.http.fetch(\n `${this.http.baseUrl}/api/ai/chat/completion`,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(backendParams),\n }\n );\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(error.error || \"Stream request failed\");\n }\n\n // Return async iterable that parses SSE and transforms to OpenAI-like format\n return this.parseSSEStream(response, params.model);\n }\n\n // Non-streaming: transform response to OpenAI-like format\n const response: ChatCompletionResponse = await this.http.post(\n \"/api/ai/chat/completion\",\n backendParams\n );\n\n // Transform to OpenAI-like format\n const content = response.text || \"\";\n\n return {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion\",\n created: Math.floor(Date.now() / 1000),\n model: response.metadata?.model,\n choices: [\n {\n index: 0,\n message: {\n role: \"assistant\",\n content,\n },\n finish_reason: \"stop\",\n },\n ],\n usage: response.metadata?.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n },\n };\n }\n\n /**\n * Parse SSE stream into async iterable of OpenAI-like chunks\n */\n private async *parseSSEStream(\n response: Response,\n model: string\n ): AsyncIterableIterator<any> {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() || \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const dataStr = line.slice(6).trim();\n if (dataStr) {\n try {\n const data = JSON.parse(dataStr);\n\n // Transform to OpenAI-like streaming format\n if (data.chunk || data.content) {\n yield {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion.chunk\",\n created: Math.floor(Date.now() / 1000),\n model,\n choices: [\n {\n index: 0,\n delta: {\n content: data.chunk || data.content,\n },\n finish_reason: data.done ? \"stop\" : null,\n },\n ],\n };\n }\n\n // If we received the done signal, we can stop\n if (data.done) {\n reader.releaseLock();\n return;\n }\n } catch (e) {\n // Skip invalid JSON\n console.warn(\"Failed to parse SSE data:\", dataStr);\n }\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nclass Images {\n constructor(private http: HttpClient) {}\n\n /**\n * Generate images - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Text-to-image\n * const response = await client.ai.images.generate({\n * model: 'dall-e-3',\n * prompt: 'A sunset over mountains',\n * });\n * console.log(response.images[0].url);\n *\n * // Image-to-image (with input images)\n * const response = await client.ai.images.generate({\n * model: 'stable-diffusion-xl',\n * prompt: 'Transform this into a watercolor painting',\n * images: [\n * { url: 'https://example.com/input.jpg' },\n * // or base64-encoded Data URI:\n * { url: 'data:image/jpeg;base64,/9j/4AAQ...' }\n * ]\n * });\n * ```\n */\n async generate(params: ImageGenerationRequest): Promise<any> {\n const response: ImageGenerationResponse = await this.http.post(\n \"/api/ai/image/generation\",\n params\n );\n \n // Build data array based on response content\n let data: Array<{ b64_json?: string; content?: string }> = [];\n \n if (response.images && response.images.length > 0) {\n // Has images - extract base64 and include text\n data = response.images.map(img => ({\n b64_json: img.imageUrl.replace(/^data:image\\/\\w+;base64,/, ''),\n content: response.text\n }));\n } else if (response.text) {\n // Text-only response\n data = [{ content: response.text }];\n }\n \n // Return OpenAI-compatible format\n return {\n created: Math.floor(Date.now() / 1000),\n data,\n ...(response.metadata?.usage && {\n usage: {\n total_tokens: response.metadata.usage.totalTokens || 0,\n input_tokens: response.metadata.usage.promptTokens || 0,\n output_tokens: response.metadata.usage.completionTokens || 0,\n }\n })\n };\n }\n}\n","import { HttpClient } from '../lib/http-client';\n\nexport interface FunctionInvokeOptions {\n /**\n * The body of the request\n */\n body?: any;\n \n /**\n * Custom headers to send with the request\n */\n headers?: Record<string, string>;\n \n /**\n * HTTP method (default: POST)\n */\n method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n}\n\n/**\n * Edge Functions client for invoking serverless functions\n * \n * @example\n * ```typescript\n * // Invoke a function with JSON body\n * const { data, error } = await client.functions.invoke('hello-world', {\n * body: { name: 'World' }\n * });\n * \n * // GET request\n * const { data, error } = await client.functions.invoke('get-data', {\n * method: 'GET'\n * });\n * ```\n */\nexport class Functions {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Invokes an Edge Function\n * @param slug The function slug to invoke\n * @param options Request options\n */\n async invoke<T = any>(\n slug: string,\n options: FunctionInvokeOptions = {}\n ): Promise<{ data: T | null; error: Error | null }> {\n try {\n const { method = 'POST', body, headers = {} } = options;\n \n // Simple path: /functions/{slug}\n const path = `/functions/${slug}`;\n \n // Use the HTTP client's request method\n const data = await this.http.request<T>(\n method,\n path,\n { body, headers }\n );\n \n return { data, error: null };\n } catch (error: any) {\n // The HTTP client throws InsForgeError with all properties from the response\n // including error, message, details, statusCode, etc.\n // We need to preserve all of that information\n return { \n data: null, \n error: error // Pass through the full error object with all properties\n };\n }\n }\n}","import { InsForgeConfig } from './types';\nimport { HttpClient } from './lib/http-client';\nimport { TokenManager } from './lib/token-manager';\nimport { Auth } from './modules/auth';\nimport { Database } from './modules/database-postgrest';\nimport { Storage } from './modules/storage';\nimport { AI } from './modules/ai';\nimport { Functions } from './modules/functions';\n\n/**\n * Main InsForge SDK Client\n * \n * @example\n * ```typescript\n * import { InsForgeClient } from '@insforge/sdk';\n * \n * const client = new InsForgeClient({\n * baseUrl: 'http://localhost:7130'\n * });\n * \n * // Authentication\n * const session = await client.auth.register({\n * email: 'user@example.com',\n * password: 'password123',\n * name: 'John Doe'\n * });\n * \n * // Database operations\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', session.user.id)\n * .order('created_at', { ascending: false })\n * .limit(10);\n * \n * // Insert data\n * const { data: newPost } = await client.database\n * .from('posts')\n * .insert({ title: 'Hello', content: 'World' })\n * .single();\n * \n * // Invoke edge functions\n * const { data, error } = await client.functions.invoke('my-function', {\n * body: { message: 'Hello from SDK' }\n * });\n * ```\n */\nexport class InsForgeClient {\n private http: HttpClient;\n private tokenManager: TokenManager;\n \n public readonly auth: Auth;\n public readonly database: Database;\n public readonly storage: Storage;\n public readonly ai: AI;\n public readonly functions: Functions;\n\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n \n // Check for edge function token\n if (config.edgeFunctionToken) {\n this.http.setAuthToken(config.edgeFunctionToken);\n // Save to token manager so getCurrentUser() works\n this.tokenManager.saveSession({\n accessToken: config.edgeFunctionToken,\n user: {} as any // Will be populated by getCurrentUser()\n });\n }\n \n // Check for existing session in storage\n const existingSession = this.tokenManager.getSession();\n if (existingSession?.accessToken) {\n this.http.setAuthToken(existingSession.accessToken);\n }\n \n this.auth = new Auth(\n this.http,\n this.tokenManager\n );\n \n this.database = new Database(this.http, this.tokenManager);\n this.storage = new Storage(this.http);\n this.ai = new AI(this.http);\n this.functions = new Functions(this.http);\n }\n\n /**\n * Get the underlying HTTP client for custom requests\n * \n * @example\n * ```typescript\n * const httpClient = client.getHttpClient();\n * const customData = await httpClient.get('/api/custom-endpoint');\n * ```\n */\n getHttpClient(): HttpClient {\n return this.http;\n }\n\n /**\n * Future modules will be added here:\n * - database: Database operations\n * - storage: File storage operations\n * - functions: Serverless functions\n * - tables: Table management\n * - metadata: Backend metadata\n */\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0EO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAKvC,YAAY,SAAiB,YAAoB,OAAe,a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B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUF;;;ATvDO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":["data","error","response"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/database-postgrest.ts","../src/modules/auth.ts","../src/modules/storage.ts","../src/modules/ai.ts","../src/modules/functions.ts","../src/client.ts"],"sourcesContent":["/**\n * @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service\n * \n * @packageDocumentation\n */\n\n// Main client\nexport { InsForgeClient } from './client';\n\n// Types\nexport type {\n InsForgeConfig,\n InsForgeConfig as ClientOptions, // Alias for compatibility\n TokenStorage,\n AuthSession,\n ApiError,\n} from './types';\n\nexport { InsForgeError } from './types';\n\n// Re-export shared schemas that SDK users will need\nexport type {\n UserSchema,\n CreateUserRequest,\n CreateSessionRequest,\n AuthErrorResponse,\n} from '@insforge/shared-schemas';\n\n// Re-export auth module for advanced usage\nexport { Auth } from './modules/auth';\n\n// Re-export database module (using postgrest-js)\nexport { Database } from './modules/database-postgrest';\n// Note: QueryBuilder is no longer exported as we use postgrest-js QueryBuilder internally\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\n\n// Re-export AI module\nexport { AI } from './modules/ai';\n\n// Re-export Functions module\nexport { Functions } from './modules/functions';\nexport type { FunctionInvokeOptions } from './modules/functions';\n\n// Re-export utilities for advanced usage\nexport { HttpClient } from './lib/http-client';\nexport { TokenManager } from './lib/token-manager';\n\n// Factory function for creating clients (Supabase-style)\nimport { InsForgeClient } from './client';\nimport { InsForgeConfig } from './types';\n\nexport function createClient(config: InsForgeConfig): InsForgeClient {\n return new InsForgeClient(config);\n}\n\n// Default export for convenience\nexport default InsForgeClient;","/**\n * InsForge SDK Types - only SDK-specific types here\n * Use @insforge/shared-schemas directly for API types\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\n\nexport interface InsForgeConfig {\n /**\n * The base URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n baseUrl?: string;\n\n /**\n * Anonymous API key (optional)\n * Used for public/unauthenticated requests when no user token is set\n */\n anonKey?: string;\n\n /**\n * Edge Function Token (optional)\n * Use this when running in edge functions/serverless with a user's JWT token\n * This token will be used for all authenticated requests\n */\n edgeFunctionToken?: string;\n\n /**\n * Custom fetch implementation (useful for Node.js environments)\n */\n fetch?: typeof fetch;\n\n /**\n * Storage adapter for persisting tokens\n */\n storage?: TokenStorage;\n\n /**\n * Whether to automatically refresh tokens before they expire\n * @default true\n */\n autoRefreshToken?: boolean;\n\n /**\n * Whether to persist session in storage\n * @default true\n */\n persistSession?: boolean;\n\n /**\n * Custom headers to include with every request\n */\n headers?: Record<string, string>;\n}\n\nexport interface TokenStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport interface AuthSession {\n user: UserSchema;\n accessToken: string;\n expiresAt?: Date;\n}\n\nexport interface ApiError {\n error: string;\n message: string;\n statusCode: number;\n nextActions?: string;\n}\n\nexport class InsForgeError extends Error {\n public statusCode: number;\n public error: string;\n public nextActions?: string;\n\n constructor(message: string, statusCode: number, error: string, nextActions?: string) {\n super(message);\n this.name = 'InsForgeError';\n this.statusCode = statusCode;\n this.error = error;\n this.nextActions = nextActions;\n }\n\n static fromApiError(apiError: ApiError): InsForgeError {\n return new InsForgeError(\n apiError.message,\n apiError.statusCode,\n apiError.error,\n apiError.nextActions\n );\n }\n}","import { InsForgeConfig, ApiError, InsForgeError } from '../types';\n\nexport interface RequestOptions extends RequestInit {\n params?: Record<string, string>;\n}\n\nexport class HttpClient {\n public readonly baseUrl: string;\n public readonly fetch: typeof fetch;\n private defaultHeaders: Record<string, string>;\n private anonKey: string | undefined;\n private userToken: string | null = null;\n\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.baseUrl || 'http://localhost:7130';\n // Properly bind fetch to maintain its context\n this.fetch = config.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : undefined as any);\n this.anonKey = config.anonKey;\n this.defaultHeaders = {\n ...config.headers,\n };\n\n if (!this.fetch) {\n throw new Error(\n 'Fetch is not available. Please provide a fetch implementation in the config.'\n );\n }\n }\n\n private buildUrl(path: string, params?: Record<string, string>): string {\n const url = new URL(path, this.baseUrl);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n // For select parameter, preserve the exact formatting by normalizing whitespace\n // This ensures PostgREST relationship queries work correctly\n if (key === 'select') {\n // Normalize multiline select strings for PostgREST:\n // 1. Replace all whitespace (including newlines) with single space\n // 2. Remove spaces inside parentheses for proper PostgREST syntax\n // 3. Keep spaces after commas at the top level for readability\n let normalizedValue = value.replace(/\\s+/g, ' ').trim();\n \n // Fix spaces around parentheses and inside them\n normalizedValue = normalizedValue\n .replace(/\\s*\\(\\s*/g, '(') // Remove spaces around opening parens\n .replace(/\\s*\\)\\s*/g, ')') // Remove spaces around closing parens\n .replace(/\\(\\s+/g, '(') // Remove spaces after opening parens\n .replace(/\\s+\\)/g, ')') // Remove spaces before closing parens\n .replace(/,\\s+(?=[^()]*\\))/g, ','); // Remove spaces after commas inside parens\n \n url.searchParams.append(key, normalizedValue);\n } else {\n url.searchParams.append(key, value);\n }\n });\n }\n return url.toString();\n }\n\n async request<T>(\n method: string,\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { params, headers = {}, body, ...fetchOptions } = options;\n \n const url = this.buildUrl(path, params);\n \n const requestHeaders: Record<string, string> = {\n ...this.defaultHeaders,\n };\n \n // Set Authorization header: prefer user token, fallback to anon key\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n requestHeaders['Authorization'] = `Bearer ${authToken}`;\n }\n \n // Handle body serialization\n let processedBody: any;\n if (body !== undefined) {\n // Check if body is FormData (for file uploads)\n if (typeof FormData !== 'undefined' && body instanceof FormData) {\n // Don't set Content-Type for FormData, let browser set it with boundary\n processedBody = body;\n } else {\n // JSON body\n if (method !== 'GET') {\n requestHeaders['Content-Type'] = 'application/json;charset=UTF-8';\n }\n processedBody = JSON.stringify(body);\n }\n }\n \n Object.assign(requestHeaders, headers);\n \n const response = await this.fetch(url, {\n method,\n headers: requestHeaders,\n body: processedBody,\n ...fetchOptions,\n });\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n // Try to parse JSON response\n let data: any;\n const contentType = response.headers.get('content-type');\n // Check for any JSON content type (including PostgREST's vnd.pgrst.object+json)\n if (contentType?.includes('json')) {\n data = await response.json();\n } else {\n // For non-JSON responses, return text\n data = await response.text();\n }\n\n // Handle errors\n if (!response.ok) {\n if (data && typeof data === 'object' && 'error' in data) {\n // Add the HTTP status code if not already in the data\n if (!data.statusCode && !data.status) {\n data.statusCode = response.status;\n }\n const error = InsForgeError.fromApiError(data as ApiError);\n // Preserve all additional fields from the error response\n Object.keys(data).forEach(key => {\n if (key !== 'error' && key !== 'message' && key !== 'statusCode') {\n (error as any)[key] = data[key];\n }\n });\n throw error;\n }\n throw new InsForgeError(\n `Request failed: ${response.statusText}`,\n response.status,\n 'REQUEST_FAILED'\n );\n }\n\n return data as T;\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('GET', path, options);\n }\n\n post<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n put<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n setAuthToken(token: string | null) {\n this.userToken = token;\n }\n\n getHeaders(): Record<string, string> {\n const headers = { ...this.defaultHeaders };\n \n // Include Authorization header if token is available (same logic as request method)\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n headers['Authorization'] = `Bearer ${authToken}`;\n }\n \n return headers;\n }\n}","import { TokenStorage, AuthSession } from '../types';\n\nconst TOKEN_KEY = 'insforge-auth-token';\nconst USER_KEY = 'insforge-auth-user';\n\nexport class TokenManager {\n private storage: TokenStorage;\n\n constructor(storage?: TokenStorage) {\n if (storage) {\n // Use provided storage\n this.storage = storage;\n } else if (typeof window !== 'undefined' && window.localStorage) {\n // Browser: use localStorage\n this.storage = window.localStorage;\n } else {\n // Node.js: use in-memory storage\n const store = new Map<string, string>();\n this.storage = {\n getItem: (key: string) => store.get(key) || null,\n setItem: (key: string, value: string) => { store.set(key, value); },\n removeItem: (key: string) => { store.delete(key); }\n };\n }\n }\n\n saveSession(session: AuthSession): void {\n this.storage.setItem(TOKEN_KEY, session.accessToken);\n this.storage.setItem(USER_KEY, JSON.stringify(session.user));\n }\n\n getSession(): AuthSession | null {\n const token = this.storage.getItem(TOKEN_KEY);\n const userStr = this.storage.getItem(USER_KEY);\n\n if (!token || !userStr) {\n return null;\n }\n\n try {\n const user = JSON.parse(userStr as string);\n return { accessToken: token as string, user };\n } catch {\n this.clearSession();\n return null;\n }\n }\n\n getAccessToken(): string | null {\n const token = this.storage.getItem(TOKEN_KEY);\n return typeof token === 'string' ? token : null;\n }\n\n clearSession(): void {\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n }\n}","/**\n * Database module using @supabase/postgrest-js\n * Complete replacement for custom QueryBuilder with full PostgREST features\n */\n\nimport { PostgrestClient } from '@supabase/postgrest-js';\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\n\n\n/**\n * Custom fetch that transforms URLs and adds auth\n */\nfunction createInsForgePostgrestFetch(\n httpClient: HttpClient,\n tokenManager: TokenManager\n): typeof fetch {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const url = typeof input === 'string' ? input : input.toString();\n const urlObj = new URL(url);\n \n // Extract table name from pathname\n // postgrest-js sends: http://dummy/tablename?params\n // We need: http://localhost:7130/api/database/records/tablename?params\n const tableName = urlObj.pathname.slice(1); // Remove leading /\n \n // Build InsForge URL\n const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;\n \n // Get auth token from TokenManager or HttpClient\n const token = tokenManager.getAccessToken();\n const httpHeaders = httpClient.getHeaders();\n const authToken = token || httpHeaders['Authorization']?.replace('Bearer ', '');\n \n // Prepare headers\n const headers = new Headers(init?.headers);\n if (authToken && !headers.has('Authorization')) {\n headers.set('Authorization', `Bearer ${authToken}`);\n }\n \n // Make the actual request using native fetch\n const response = await fetch(insforgeUrl, {\n ...init,\n headers\n });\n \n return response;\n };\n}\n\n/**\n * Database client using postgrest-js\n * Drop-in replacement with FULL PostgREST capabilities\n */\nexport class Database {\n private postgrest: PostgrestClient<any, any, any>;\n \n constructor(httpClient: HttpClient, tokenManager: TokenManager) {\n // Create postgrest client with custom fetch\n this.postgrest = new PostgrestClient<any, any, any>('http://dummy', {\n fetch: createInsForgePostgrestFetch(httpClient, tokenManager),\n headers: {}\n });\n }\n \n /**\n * Create a query builder for a table\n * \n * @example\n * // Basic query\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId);\n * \n * // With count (Supabase style!)\n * const { data, error, count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact' })\n * .range(0, 9);\n * \n * // Just get count, no data\n * const { count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact', head: true });\n * \n * // Complex queries with OR\n * const { data } = await client.database\n * .from('posts')\n * .select('*, users!inner(*)')\n * .or('status.eq.active,status.eq.pending');\n * \n * // All features work:\n * - Nested selects\n * - Foreign key expansion \n * - OR/AND/NOT conditions\n * - Count with head\n * - Range pagination\n * - Upserts\n */\n from(table: string) {\n // Return postgrest query builder with all features\n return this.postgrest.from(table);\n }\n}","/**\n * Auth module for InsForge SDK\n * Uses shared schemas for type safety\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\nimport { AuthSession, InsForgeError } from '../types';\nimport { Database } from './database-postgrest';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\n OAuthProvidersSchema,\n} from '@insforge/shared-schemas';\n\nexport class Auth {\n private database: Database;\n \n constructor(\n private http: HttpClient,\n private tokenManager: TokenManager\n ) {\n this.database = new Database(http, tokenManager);\n \n // Auto-detect OAuth callback parameters in the URL\n this.detectOAuthCallback();\n }\n\n /**\n * Automatically detect and handle OAuth callback parameters in the URL\n * This runs on initialization to seamlessly complete the OAuth flow\n * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)\n */\n private detectOAuthCallback(): void {\n // Only run in browser environment\n if (typeof window === 'undefined') return;\n \n try {\n const params = new URLSearchParams(window.location.search);\n \n // Backend returns: access_token, user_id, email, name (optional)\n const accessToken = params.get('access_token');\n const userId = params.get('user_id');\n const email = params.get('email');\n const name = params.get('name');\n \n // Check if we have OAuth callback parameters\n if (accessToken && userId && email) {\n // Create session with the data from backend\n const session: AuthSession = {\n accessToken,\n user: {\n id: userId,\n email: email,\n name: name || '',\n // These fields are not provided by backend OAuth callback\n // They'll be populated when calling getCurrentUser()\n emailVerified: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n } as any,\n };\n \n // Save session and set auth token\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(accessToken);\n \n // Clean up the URL to remove sensitive parameters\n const url = new URL(window.location.href);\n url.searchParams.delete('access_token');\n url.searchParams.delete('user_id');\n url.searchParams.delete('email');\n url.searchParams.delete('name');\n \n // Also handle error case from backend (line 581)\n if (params.has('error')) {\n url.searchParams.delete('error');\n }\n \n // Replace URL without adding to browser history\n window.history.replaceState({}, document.title, url.toString());\n }\n } catch (error) {\n // Silently continue - don't break initialization\n console.debug('OAuth callback detection skipped:', error);\n }\n }\n\n /**\n * Sign up a new user\n */\n async signUp(request: CreateUserRequest): Promise<{\n data: CreateUserResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateUserResponse>('/api/auth/users', request);\n\n // Save session internally only if both accessToken and user exist\n if (response.accessToken && response.user) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n error instanceof Error ? error.message : 'An unexpected error occurred during sign up',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with email and password\n */\n async signInWithPassword(request: CreateSessionRequest): Promise<{\n data: CreateSessionResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateSessionResponse>('/api/auth/sessions', request);\n \n // Save session internally\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n return { \n data: response,\n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n 'An unexpected error occurred during sign in',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with OAuth provider\n */\n async signInWithOAuth(options: {\n provider: OAuthProvidersSchema;\n redirectTo?: string;\n skipBrowserRedirect?: boolean;\n }): Promise<{\n data: { url?: string; provider?: string };\n error: InsForgeError | null;\n }> {\n try {\n const { provider, redirectTo, skipBrowserRedirect } = options;\n \n const params = redirectTo \n ? { redirect_uri: redirectTo } \n : undefined;\n \n const endpoint = `/api/auth/oauth/${provider}`;\n const response = await this.http.get<GetOauthUrlResponse>(endpoint, { params });\n \n // Automatically redirect in browser unless told not to\n if (typeof window !== 'undefined' && !skipBrowserRedirect) {\n window.location.href = response.authUrl;\n return { data: {}, error: null };\n }\n\n return { \n data: { \n url: response.authUrl,\n provider \n }, \n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: {}, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: {}, \n error: new InsForgeError(\n 'An unexpected error occurred during OAuth initialization',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign out the current user\n */\n async signOut(): Promise<{ error: InsForgeError | null }> {\n try {\n this.tokenManager.clearSession();\n this.http.setAuthToken(null);\n return { error: null };\n } catch (error) {\n return { \n error: new InsForgeError(\n 'Failed to sign out',\n 500,\n 'SIGNOUT_ERROR'\n )\n };\n }\n }\n\n /**\n * Get the current user with full profile information\n * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)\n */\n async getCurrentUser(): Promise<{\n data: { user: any; profile: any } | null;\n error: any | null;\n }> {\n try {\n // Check if we have a token\n const session = this.tokenManager.getSession();\n if (!session?.accessToken) {\n return { data: null, error: null };\n }\n\n // Call the API for auth info\n this.http.setAuthToken(session.accessToken);\n const authResponse = await this.http.get<GetCurrentSessionResponse>('/api/auth/sessions/current');\n \n // Get the user's profile using query builder\n const { data: profile, error: profileError } = await this.database\n .from('users')\n .select('*')\n .eq('id', authResponse.user.id)\n .single();\n \n // For database errors, return PostgrestError directly\n if (profileError && (profileError as any).code !== 'PGRST116') { // PGRST116 = not found\n return { data: null, error: profileError };\n }\n \n return {\n data: {\n user: authResponse.user,\n profile: profile\n },\n error: null\n };\n } catch (error) {\n // If unauthorized, clear session\n if (error instanceof InsForgeError && error.statusCode === 401) {\n await this.signOut();\n return { data: null, error: null };\n }\n \n // Pass through all other errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n 'An unexpected error occurred while fetching user',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get any user's profile by ID\n * Returns profile information from the users table (nickname, avatar_url, bio, etc.)\n */\n async getProfile(userId: string): Promise<{\n data: any | null;\n error: any | null;\n }> {\n const { data, error } = await this.database\n .from('users')\n .select('*')\n .eq('id', userId)\n .single();\n \n // Handle not found as null, not error\n if (error && (error as any).code === 'PGRST116') {\n return { data: null, error: null };\n }\n \n // Return PostgrestError directly for database operations\n return { data, error };\n }\n\n /**\n * Get the current session (only session data, no API call)\n * Returns the stored JWT token and basic user info from local storage\n */\n getCurrentSession(): {\n data: { session: AuthSession | null };\n error: InsForgeError | null;\n } {\n try {\n const session = this.tokenManager.getSession();\n \n if (session?.accessToken) {\n this.http.setAuthToken(session.accessToken);\n return { data: { session }, error: null };\n }\n\n return { data: { session: null }, error: null };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: { session: null }, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: { session: null }, \n error: new InsForgeError(\n 'An unexpected error occurred while getting session',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Set/Update the current user's profile\n * Updates profile information in the users table (nickname, avatar_url, bio, etc.)\n */\n async setProfile(profile: {\n nickname?: string;\n avatar_url?: string;\n bio?: string;\n birthday?: string;\n [key: string]: any;\n }): Promise<{\n data: any | null;\n error: any | null;\n }> {\n // Get current session to get user ID\n const session = this.tokenManager.getSession();\n if (!session?.accessToken) {\n return { \n data: null, \n error: new InsForgeError(\n 'No authenticated user found',\n 401,\n 'UNAUTHENTICATED'\n )\n };\n }\n \n // If no user ID in session (edge function scenario), fetch it\n if (!session.user?.id) {\n const { data, error } = await this.getCurrentUser();\n if (error) {\n return { data: null, error };\n }\n if (data?.user) {\n session.user = data.user;\n this.tokenManager.saveSession(session);\n }\n }\n\n // Update the profile using query builder\n const { data, error } = await this.database\n .from('users')\n .update(profile)\n .eq('id', session.user.id)\n .select()\n .single();\n \n // Return PostgrestError directly for database operations\n return { data, error };\n }\n\n\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n}\n\ninterface UploadStrategy {\n method: 'direct' | 'presigned';\n uploadUrl: string;\n fields?: Record<string, string>;\n key: string;\n confirmRequired: boolean;\n confirmUrl?: string;\n expiresAt?: Date;\n}\n\ninterface DownloadStrategy {\n method: 'direct' | 'presigned';\n url: string;\n expiresAt?: Date;\n}\n\n/**\n * Storage bucket operations\n */\nexport class StorageBucket {\n constructor(\n private bucketName: string,\n private http: HttpClient\n ) {}\n\n /**\n * Upload a file with a specific key\n * Uses the upload strategy from backend (direct or presigned)\n * @param path - The object key/path\n * @param file - File or Blob to upload\n */\n async upload(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'PUT',\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * Uses the upload strategy from backend (direct or presigned)\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const filename = file instanceof File ? file.name : 'file';\n \n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'POST',\n `/api/storage/buckets/${this.bucketName}/objects`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Internal method to handle presigned URL uploads\n */\n private async uploadWithPresignedUrl(\n strategy: UploadStrategy,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Upload to presigned URL (e.g., S3)\n const formData = new FormData();\n \n // Add all fields from the presigned URL\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be the last field for S3\n formData.append('file', file);\n\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n throw new InsForgeError(\n `Upload to storage failed: ${uploadResponse.statusText}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Confirm upload with backend if required\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n }\n );\n\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, return basic file info\n return {\n data: {\n key: strategy.key,\n bucket: this.bucketName,\n size: file.size,\n mimeType: file.type || 'application/octet-stream',\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n } as StorageFileSchema,\n error: null\n };\n } catch (error) {\n throw error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n );\n }\n }\n\n /**\n * Download a file\n * Uses the download strategy from backend (direct or presigned)\n * @param path - The object key/path\n * Returns the file as a Blob\n */\n async download(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n // Get download strategy from backend - this is required\n const strategyResponse = await this.http.post<DownloadStrategy>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n { expiresIn: 3600 }\n );\n\n // Use URL from strategy\n const downloadUrl = strategyResponse.url;\n \n // Download from the URL\n const headers: HeadersInit = {};\n \n // Only add auth header for direct downloads (not presigned URLs)\n if (strategyResponse.method === 'direct') {\n Object.assign(headers, this.http.getHeaders());\n }\n \n const response = await fetch(downloadUrl, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n try {\n const error = await response.json();\n throw InsForgeError.fromApiError(error);\n } catch {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\n );\n }\n }\n\n const blob = await response.blob();\n return { data: blob, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Get public URL for a file\n * @param path - The object key/path\n */\n getPublicUrl(path: string): string {\n return `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n }\n\n /**\n * List objects in the bucket\n * @param prefix - Filter by key prefix\n * @param search - Search in file names\n * @param limit - Maximum number of results (default: 100, max: 1000)\n * @param offset - Number of results to skip\n */\n async list(options?: {\n prefix?: string;\n search?: string;\n limit?: number;\n offset?: number;\n }): Promise<StorageResponse<ListObjectsResponseSchema>> {\n try {\n const params: Record<string, string> = {};\n \n if (options?.prefix) params.prefix = options.prefix;\n if (options?.search) params.search = options.search;\n if (options?.limit) params.limit = options.limit.toString();\n if (options?.offset) params.offset = options.offset.toString();\n\n const response = await this.http.get<ListObjectsResponseSchema>(\n `/api/storage/buckets/${this.bucketName}/objects`,\n { params }\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'List failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Delete a file\n * @param path - The object key/path\n */\n async remove(path: string): Promise<StorageResponse<{ message: string }>> {\n try {\n const response = await this.http.delete<{ message: string }>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Delete failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n}\n\n/**\n * Storage module for file operations\n */\nexport class Storage {\n constructor(private http: HttpClient) {}\n\n /**\n * Get a bucket instance for operations\n * @param bucketName - Name of the bucket\n */\n from(bucketName: string): StorageBucket {\n return new StorageBucket(bucketName, this.http);\n }\n}","/**\n * AI Module for Insforge SDK\n * Response format roughly matches OpenAI SDK for compatibility\n *\n * The backend handles all the complexity of different AI providers\n * and returns a unified format. This SDK transforms responses to match OpenAI-like format.\n */\n\nimport { HttpClient } from \"../lib/http-client\";\nimport {\n ChatCompletionRequest,\n ChatCompletionResponse,\n ImageGenerationRequest,\n ImageGenerationResponse,\n} from \"@insforge/shared-schemas\";\n\nexport class AI {\n public readonly chat: Chat;\n public readonly images: Images;\n\n constructor(private http: HttpClient) {\n this.chat = new Chat(http);\n this.images = new Images(http);\n }\n}\n\nclass Chat {\n public readonly completions: ChatCompletions;\n\n constructor(http: HttpClient) {\n this.completions = new ChatCompletions(http);\n }\n}\n\nclass ChatCompletions {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a chat completion - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const completion = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Hello!' }]\n * });\n * console.log(completion.choices[0].message.content);\n *\n * // With images\n * const response = await client.ai.chat.completions.create({\n * model: 'gpt-4-vision',\n * messages: [{\n * role: 'user',\n * content: 'What is in this image?',\n * images: [{ url: 'https://example.com/image.jpg' }]\n * }]\n * });\n *\n * // Streaming - returns async iterable\n * const stream = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * stream: true\n * });\n *\n * for await (const chunk of stream) {\n * if (chunk.choices[0]?.delta?.content) {\n * process.stdout.write(chunk.choices[0].delta.content);\n * }\n * }\n * ```\n */\n async create(params: ChatCompletionRequest): Promise<any> {\n // Backend already expects camelCase, no transformation needed\n const backendParams = {\n model: params.model,\n messages: params.messages,\n temperature: params.temperature,\n maxTokens: params.maxTokens,\n topP: params.topP,\n stream: params.stream,\n };\n\n // For streaming, return an async iterable that yields OpenAI-like chunks\n if (params.stream) {\n const headers = this.http.getHeaders();\n headers[\"Content-Type\"] = \"application/json\";\n\n const response = await this.http.fetch(\n `${this.http.baseUrl}/api/ai/chat/completion`,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(backendParams),\n }\n );\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(error.error || \"Stream request failed\");\n }\n\n // Return async iterable that parses SSE and transforms to OpenAI-like format\n return this.parseSSEStream(response, params.model);\n }\n\n // Non-streaming: transform response to OpenAI-like format\n const response: ChatCompletionResponse = await this.http.post(\n \"/api/ai/chat/completion\",\n backendParams\n );\n\n // Transform to OpenAI-like format\n const content = response.text || \"\";\n\n return {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion\",\n created: Math.floor(Date.now() / 1000),\n model: response.metadata?.model,\n choices: [\n {\n index: 0,\n message: {\n role: \"assistant\",\n content,\n },\n finish_reason: \"stop\",\n },\n ],\n usage: response.metadata?.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n },\n };\n }\n\n /**\n * Parse SSE stream into async iterable of OpenAI-like chunks\n */\n private async *parseSSEStream(\n response: Response,\n model: string\n ): AsyncIterableIterator<any> {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() || \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const dataStr = line.slice(6).trim();\n if (dataStr) {\n try {\n const data = JSON.parse(dataStr);\n\n // Transform to OpenAI-like streaming format\n if (data.chunk || data.content) {\n yield {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion.chunk\",\n created: Math.floor(Date.now() / 1000),\n model,\n choices: [\n {\n index: 0,\n delta: {\n content: data.chunk || data.content,\n },\n finish_reason: data.done ? \"stop\" : null,\n },\n ],\n };\n }\n\n // If we received the done signal, we can stop\n if (data.done) {\n reader.releaseLock();\n return;\n }\n } catch (e) {\n // Skip invalid JSON\n console.warn(\"Failed to parse SSE data:\", dataStr);\n }\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nclass Images {\n constructor(private http: HttpClient) {}\n\n /**\n * Generate images - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Text-to-image\n * const response = await client.ai.images.generate({\n * model: 'dall-e-3',\n * prompt: 'A sunset over mountains',\n * });\n * console.log(response.images[0].url);\n *\n * // Image-to-image (with input images)\n * const response = await client.ai.images.generate({\n * model: 'stable-diffusion-xl',\n * prompt: 'Transform this into a watercolor painting',\n * images: [\n * { url: 'https://example.com/input.jpg' },\n * // or base64-encoded Data URI:\n * { url: 'data:image/jpeg;base64,/9j/4AAQ...' }\n * ]\n * });\n * ```\n */\n async generate(params: ImageGenerationRequest): Promise<any> {\n const response: ImageGenerationResponse = await this.http.post(\n \"/api/ai/image/generation\",\n params\n );\n \n // Build data array based on response content\n let data: Array<{ b64_json?: string; content?: string }> = [];\n \n if (response.images && response.images.length > 0) {\n // Has images - extract base64 and include text\n data = response.images.map(img => ({\n b64_json: img.imageUrl.replace(/^data:image\\/\\w+;base64,/, ''),\n content: response.text\n }));\n } else if (response.text) {\n // Text-only response\n data = [{ content: response.text }];\n }\n \n // Return OpenAI-compatible format\n return {\n created: Math.floor(Date.now() / 1000),\n data,\n ...(response.metadata?.usage && {\n usage: {\n total_tokens: response.metadata.usage.totalTokens || 0,\n input_tokens: response.metadata.usage.promptTokens || 0,\n output_tokens: response.metadata.usage.completionTokens || 0,\n }\n })\n };\n }\n}\n","import { HttpClient } from '../lib/http-client';\n\nexport interface FunctionInvokeOptions {\n /**\n * The body of the request\n */\n body?: any;\n \n /**\n * Custom headers to send with the request\n */\n headers?: Record<string, string>;\n \n /**\n * HTTP method (default: POST)\n */\n method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n}\n\n/**\n * Edge Functions client for invoking serverless functions\n * \n * @example\n * ```typescript\n * // Invoke a function with JSON body\n * const { data, error } = await client.functions.invoke('hello-world', {\n * body: { name: 'World' }\n * });\n * \n * // GET request\n * const { data, error } = await client.functions.invoke('get-data', {\n * method: 'GET'\n * });\n * ```\n */\nexport class Functions {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Invokes an Edge Function\n * @param slug The function slug to invoke\n * @param options Request options\n */\n async invoke<T = any>(\n slug: string,\n options: FunctionInvokeOptions = {}\n ): Promise<{ data: T | null; error: Error | null }> {\n try {\n const { method = 'POST', body, headers = {} } = options;\n \n // Simple path: /functions/{slug}\n const path = `/functions/${slug}`;\n \n // Use the HTTP client's request method\n const data = await this.http.request<T>(\n method,\n path,\n { body, headers }\n );\n \n return { data, error: null };\n } catch (error: any) {\n // The HTTP client throws InsForgeError with all properties from the response\n // including error, message, details, statusCode, etc.\n // We need to preserve all of that information\n return { \n data: null, \n error: error // Pass through the full error object with all properties\n };\n }\n }\n}","import { InsForgeConfig } from './types';\nimport { HttpClient } from './lib/http-client';\nimport { TokenManager } from './lib/token-manager';\nimport { Auth } from './modules/auth';\nimport { Database } from './modules/database-postgrest';\nimport { Storage } from './modules/storage';\nimport { AI } from './modules/ai';\nimport { Functions } from './modules/functions';\n\n/**\n * Main InsForge SDK Client\n * \n * @example\n * ```typescript\n * import { InsForgeClient } from '@insforge/sdk';\n * \n * const client = new InsForgeClient({\n * baseUrl: 'http://localhost:7130'\n * });\n * \n * // Authentication\n * const session = await client.auth.register({\n * email: 'user@example.com',\n * password: 'password123',\n * name: 'John Doe'\n * });\n * \n * // Database operations\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', session.user.id)\n * .order('created_at', { ascending: false })\n * .limit(10);\n * \n * // Insert data\n * const { data: newPost } = await client.database\n * .from('posts')\n * .insert({ title: 'Hello', content: 'World' })\n * .single();\n * \n * // Invoke edge functions\n * const { data, error } = await client.functions.invoke('my-function', {\n * body: { message: 'Hello from SDK' }\n * });\n * ```\n */\nexport class InsForgeClient {\n private http: HttpClient;\n private tokenManager: TokenManager;\n \n public readonly auth: Auth;\n public readonly database: Database;\n public readonly storage: Storage;\n public readonly ai: AI;\n public readonly functions: Functions;\n\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n \n // Check for edge function token\n if (config.edgeFunctionToken) {\n this.http.setAuthToken(config.edgeFunctionToken);\n // Save to token manager so getCurrentUser() works\n this.tokenManager.saveSession({\n accessToken: config.edgeFunctionToken,\n user: {} as any // Will be populated by getCurrentUser()\n });\n }\n \n // Check for existing session in storage\n const existingSession = this.tokenManager.getSession();\n if (existingSession?.accessToken) {\n this.http.setAuthToken(existingSession.accessToken);\n }\n \n this.auth = new Auth(\n this.http,\n this.tokenManager\n );\n \n this.database = new Database(this.http, this.tokenManager);\n this.storage = new Storage(this.http);\n this.ai = new AI(this.http);\n this.functions = new Functions(this.http);\n }\n\n /**\n * Get the underlying HTTP client for custom requests\n * \n * @example\n * ```typescript\n * const httpClient = client.getHttpClient();\n * const customData = await httpClient.get('/api/custom-endpoint');\n * ```\n */\n getHttpClient(): HttpClient {\n return this.http;\n }\n\n /**\n * Future modules will be added here:\n * - database: Database operations\n * - storage: File storage operations\n * - functions: Serverless functions\n * - tables: Table management\n * - metadata: Backend metadata\n */\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0EO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAKvC,YAAY,SAAiB,YAAoB,OAAe,aAAsB;AACpF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,OAAO,aAAa,UAAmC;AACrD,WAAO,IAAI;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,EACF;AACF;;;ACzFO,IAAM,aAAN,MAAiB;AAAA,EAOtB,YAAY,QAAwB;AAFpC,SAAQ,YAA2B;AAGjC,SAAK,UAAU,OAAO,WAAW;AAEjC,SAAK,QAAQ,OAAO,UAAU,WAAW,Q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C7B,SAAS,OAAY;AAInB,aAAO;AAAA,QACL,MAAM;AAAA,QACN;AAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;AC5BO,IAAM,iBAAN,MAAqB;AAAA,EAU1B,YAAY,SAAyB,CAAC,GAAG;AACvC,SAAK,OAAO,IAAI,WAAW,MAAM;AACjC,SAAK,eAAe,IAAI,aAAa,OAAO,OAAO;AAGnD,QAAI,OAAO,mBAAmB;AAC5B,WAAK,KAAK,aAAa,OAAO,iBAAiB;AAE/C,WAAK,aAAa,YAAY;AAAA,QAC5B,aAAa,OAAO;AAAA,QACpB,MAAM,CAAC;AAAA;AAAA,MACT,CAAC;AAAA,IACH;AAGA,UAAM,kBAAkB,KAAK,aAAa,WAAW;AACrD,QAAI,iBAAiB,aAAa;AAChC,WAAK,KAAK,aAAa,gBAAgB,WAAW;AAAA,IACpD;AAEA,SAAK,OAAO,IAAI;AAAA,MACd,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAEA,SAAK,WAAW,IAAI,SAAS,KAAK,MAAM,KAAK,YAAY;AACzD,SAAK,UAAU,IAAI,QAAQ,KAAK,IAAI;AACpC,SAAK,KAAK,IAAI,GAAG,KAAK,IAAI;AAC1B,SAAK,YAAY,IAAI,UAAU,KAAK,IAAI;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,gBAA4B;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUF;;;ATvDO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":["data","error","response"]}
|
package/dist/index.mjs
CHANGED
|
@@ -311,12 +311,14 @@ var Auth = class {
|
|
|
311
311
|
async signUp(request) {
|
|
312
312
|
try {
|
|
313
313
|
const response = await this.http.post("/api/auth/users", request);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
314
|
+
if (response.accessToken && response.user) {
|
|
315
|
+
const session = {
|
|
316
|
+
accessToken: response.accessToken,
|
|
317
|
+
user: response.user
|
|
318
|
+
};
|
|
319
|
+
this.tokenManager.saveSession(session);
|
|
320
|
+
this.http.setAuthToken(response.accessToken);
|
|
321
|
+
}
|
|
320
322
|
return {
|
|
321
323
|
data: response,
|
|
322
324
|
error: null
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/database-postgrest.ts","../src/modules/auth.ts","../src/modules/storage.ts","../src/modules/ai.ts","../src/modules/functions.ts","../src/client.ts","../src/index.ts"],"sourcesContent":["/**\n * InsForge SDK Types - only SDK-specific types here\n * Use @insforge/shared-schemas directly for API types\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\n\nexport interface InsForgeConfig {\n /**\n * The base URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n baseUrl?: string;\n\n /**\n * Anonymous API key (optional)\n * Used for public/unauthenticated requests when no user token is set\n */\n anonKey?: string;\n\n /**\n * Edge Function Token (optional)\n * Use this when running in edge functions/serverless with a user's JWT token\n * This token will be used for all authenticated requests\n */\n edgeFunctionToken?: string;\n\n /**\n * Custom fetch implementation (useful for Node.js environments)\n */\n fetch?: typeof fetch;\n\n /**\n * Storage adapter for persisting tokens\n */\n storage?: TokenStorage;\n\n /**\n * Whether to automatically refresh tokens before they expire\n * @default true\n */\n autoRefreshToken?: boolean;\n\n /**\n * Whether to persist session in storage\n * @default true\n */\n persistSession?: boolean;\n\n /**\n * Custom headers to include with every request\n */\n headers?: Record<string, string>;\n}\n\nexport interface TokenStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport interface AuthSession {\n user: UserSchema;\n accessToken: string;\n expiresAt?: Date;\n}\n\nexport interface ApiError {\n error: string;\n message: string;\n statusCode: number;\n nextActions?: string;\n}\n\nexport class InsForgeError extends Error {\n public statusCode: number;\n public error: string;\n public nextActions?: string;\n\n constructor(message: string, statusCode: number, error: string, nextActions?: string) {\n super(message);\n this.name = 'InsForgeError';\n this.statusCode = statusCode;\n this.error = error;\n this.nextActions = nextActions;\n }\n\n static fromApiError(apiError: ApiError): InsForgeError {\n return new InsForgeError(\n apiError.message,\n apiError.statusCode,\n apiError.error,\n apiError.nextActions\n );\n }\n}","import { InsForgeConfig, ApiError, InsForgeError } from '../types';\n\nexport interface RequestOptions extends RequestInit {\n params?: Record<string, string>;\n}\n\nexport class HttpClient {\n public readonly baseUrl: string;\n public readonly fetch: typeof fetch;\n private defaultHeaders: Record<string, string>;\n private anonKey: string | undefined;\n private userToken: string | null = null;\n\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.baseUrl || 'http://localhost:7130';\n // Properly bind fetch to maintain its context\n this.fetch = config.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : undefined as any);\n this.anonKey = config.anonKey;\n this.defaultHeaders = {\n ...config.headers,\n };\n\n if (!this.fetch) {\n throw new Error(\n 'Fetch is not available. Please provide a fetch implementation in the config.'\n );\n }\n }\n\n private buildUrl(path: string, params?: Record<string, string>): string {\n const url = new URL(path, this.baseUrl);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n // For select parameter, preserve the exact formatting by normalizing whitespace\n // This ensures PostgREST relationship queries work correctly\n if (key === 'select') {\n // Normalize multiline select strings for PostgREST:\n // 1. Replace all whitespace (including newlines) with single space\n // 2. Remove spaces inside parentheses for proper PostgREST syntax\n // 3. Keep spaces after commas at the top level for readability\n let normalizedValue = value.replace(/\\s+/g, ' ').trim();\n \n // Fix spaces around parentheses and inside them\n normalizedValue = normalizedValue\n .replace(/\\s*\\(\\s*/g, '(') // Remove spaces around opening parens\n .replace(/\\s*\\)\\s*/g, ')') // Remove spaces around closing parens\n .replace(/\\(\\s+/g, '(') // Remove spaces after opening parens\n .replace(/\\s+\\)/g, ')') // Remove spaces before closing parens\n .replace(/,\\s+(?=[^()]*\\))/g, ','); // Remove spaces after commas inside parens\n \n url.searchParams.append(key, normalizedValue);\n } else {\n url.searchParams.append(key, value);\n }\n });\n }\n return url.toString();\n }\n\n async request<T>(\n method: string,\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { params, headers = {}, body, ...fetchOptions } = options;\n \n const url = this.buildUrl(path, params);\n \n const requestHeaders: Record<string, string> = {\n ...this.defaultHeaders,\n };\n \n // Set Authorization header: prefer user token, fallback to anon key\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n requestHeaders['Authorization'] = `Bearer ${authToken}`;\n }\n \n // Handle body serialization\n let processedBody: any;\n if (body !== undefined) {\n // Check if body is FormData (for file uploads)\n if (typeof FormData !== 'undefined' && body instanceof FormData) {\n // Don't set Content-Type for FormData, let browser set it with boundary\n processedBody = body;\n } else {\n // JSON body\n if (method !== 'GET') {\n requestHeaders['Content-Type'] = 'application/json;charset=UTF-8';\n }\n processedBody = JSON.stringify(body);\n }\n }\n \n Object.assign(requestHeaders, headers);\n \n const response = await this.fetch(url, {\n method,\n headers: requestHeaders,\n body: processedBody,\n ...fetchOptions,\n });\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n // Try to parse JSON response\n let data: any;\n const contentType = response.headers.get('content-type');\n // Check for any JSON content type (including PostgREST's vnd.pgrst.object+json)\n if (contentType?.includes('json')) {\n data = await response.json();\n } else {\n // For non-JSON responses, return text\n data = await response.text();\n }\n\n // Handle errors\n if (!response.ok) {\n if (data && typeof data === 'object' && 'error' in data) {\n // Add the HTTP status code if not already in the data\n if (!data.statusCode && !data.status) {\n data.statusCode = response.status;\n }\n const error = InsForgeError.fromApiError(data as ApiError);\n // Preserve all additional fields from the error response\n Object.keys(data).forEach(key => {\n if (key !== 'error' && key !== 'message' && key !== 'statusCode') {\n (error as any)[key] = data[key];\n }\n });\n throw error;\n }\n throw new InsForgeError(\n `Request failed: ${response.statusText}`,\n response.status,\n 'REQUEST_FAILED'\n );\n }\n\n return data as T;\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('GET', path, options);\n }\n\n post<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n put<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n setAuthToken(token: string | null) {\n this.userToken = token;\n }\n\n getHeaders(): Record<string, string> {\n const headers = { ...this.defaultHeaders };\n \n // Include Authorization header if token is available (same logic as request method)\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n headers['Authorization'] = `Bearer ${authToken}`;\n }\n \n return headers;\n }\n}","import { TokenStorage, AuthSession } from '../types';\n\nconst TOKEN_KEY = 'insforge-auth-token';\nconst USER_KEY = 'insforge-auth-user';\n\nexport class TokenManager {\n private storage: TokenStorage;\n\n constructor(storage?: TokenStorage) {\n if (storage) {\n // Use provided storage\n this.storage = storage;\n } else if (typeof window !== 'undefined' && window.localStorage) {\n // Browser: use localStorage\n this.storage = window.localStorage;\n } else {\n // Node.js: use in-memory storage\n const store = new Map<string, string>();\n this.storage = {\n getItem: (key: string) => store.get(key) || null,\n setItem: (key: string, value: string) => { store.set(key, value); },\n removeItem: (key: string) => { store.delete(key); }\n };\n }\n }\n\n saveSession(session: AuthSession): void {\n this.storage.setItem(TOKEN_KEY, session.accessToken);\n this.storage.setItem(USER_KEY, JSON.stringify(session.user));\n }\n\n getSession(): AuthSession | null {\n const token = this.storage.getItem(TOKEN_KEY);\n const userStr = this.storage.getItem(USER_KEY);\n\n if (!token || !userStr) {\n return null;\n }\n\n try {\n const user = JSON.parse(userStr as string);\n return { accessToken: token as string, user };\n } catch {\n this.clearSession();\n return null;\n }\n }\n\n getAccessToken(): string | null {\n const token = this.storage.getItem(TOKEN_KEY);\n return typeof token === 'string' ? token : null;\n }\n\n clearSession(): void {\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n }\n}","/**\n * Database module using @supabase/postgrest-js\n * Complete replacement for custom QueryBuilder with full PostgREST features\n */\n\nimport { PostgrestClient } from '@supabase/postgrest-js';\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\n\n\n/**\n * Custom fetch that transforms URLs and adds auth\n */\nfunction createInsForgePostgrestFetch(\n httpClient: HttpClient,\n tokenManager: TokenManager\n): typeof fetch {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const url = typeof input === 'string' ? input : input.toString();\n const urlObj = new URL(url);\n \n // Extract table name from pathname\n // postgrest-js sends: http://dummy/tablename?params\n // We need: http://localhost:7130/api/database/records/tablename?params\n const tableName = urlObj.pathname.slice(1); // Remove leading /\n \n // Build InsForge URL\n const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;\n \n // Get auth token from TokenManager or HttpClient\n const token = tokenManager.getAccessToken();\n const httpHeaders = httpClient.getHeaders();\n const authToken = token || httpHeaders['Authorization']?.replace('Bearer ', '');\n \n // Prepare headers\n const headers = new Headers(init?.headers);\n if (authToken && !headers.has('Authorization')) {\n headers.set('Authorization', `Bearer ${authToken}`);\n }\n \n // Make the actual request using native fetch\n const response = await fetch(insforgeUrl, {\n ...init,\n headers\n });\n \n return response;\n };\n}\n\n/**\n * Database client using postgrest-js\n * Drop-in replacement with FULL PostgREST capabilities\n */\nexport class Database {\n private postgrest: PostgrestClient<any, any, any>;\n \n constructor(httpClient: HttpClient, tokenManager: TokenManager) {\n // Create postgrest client with custom fetch\n this.postgrest = new PostgrestClient<any, any, any>('http://dummy', {\n fetch: createInsForgePostgrestFetch(httpClient, tokenManager),\n headers: {}\n });\n }\n \n /**\n * Create a query builder for a table\n * \n * @example\n * // Basic query\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId);\n * \n * // With count (Supabase style!)\n * const { data, error, count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact' })\n * .range(0, 9);\n * \n * // Just get count, no data\n * const { count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact', head: true });\n * \n * // Complex queries with OR\n * const { data } = await client.database\n * .from('posts')\n * .select('*, users!inner(*)')\n * .or('status.eq.active,status.eq.pending');\n * \n * // All features work:\n * - Nested selects\n * - Foreign key expansion \n * - OR/AND/NOT conditions\n * - Count with head\n * - Range pagination\n * - Upserts\n */\n from(table: string) {\n // Return postgrest query builder with all features\n return this.postgrest.from(table);\n }\n}","/**\n * Auth module for InsForge SDK\n * Uses shared schemas for type safety\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\nimport { AuthSession, InsForgeError } from '../types';\nimport { Database } from './database-postgrest';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\n OAuthProvidersSchema,\n} from '@insforge/shared-schemas';\n\nexport class Auth {\n private database: Database;\n \n constructor(\n private http: HttpClient,\n private tokenManager: TokenManager\n ) {\n this.database = new Database(http, tokenManager);\n \n // Auto-detect OAuth callback parameters in the URL\n this.detectOAuthCallback();\n }\n\n /**\n * Automatically detect and handle OAuth callback parameters in the URL\n * This runs on initialization to seamlessly complete the OAuth flow\n * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)\n */\n private detectOAuthCallback(): void {\n // Only run in browser environment\n if (typeof window === 'undefined') return;\n \n try {\n const params = new URLSearchParams(window.location.search);\n \n // Backend returns: access_token, user_id, email, name (optional)\n const accessToken = params.get('access_token');\n const userId = params.get('user_id');\n const email = params.get('email');\n const name = params.get('name');\n \n // Check if we have OAuth callback parameters\n if (accessToken && userId && email) {\n // Create session with the data from backend\n const session: AuthSession = {\n accessToken,\n user: {\n id: userId,\n email: email,\n name: name || '',\n // These fields are not provided by backend OAuth callback\n // They'll be populated when calling getCurrentUser()\n emailVerified: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n } as any,\n };\n \n // Save session and set auth token\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(accessToken);\n \n // Clean up the URL to remove sensitive parameters\n const url = new URL(window.location.href);\n url.searchParams.delete('access_token');\n url.searchParams.delete('user_id');\n url.searchParams.delete('email');\n url.searchParams.delete('name');\n \n // Also handle error case from backend (line 581)\n if (params.has('error')) {\n url.searchParams.delete('error');\n }\n \n // Replace URL without adding to browser history\n window.history.replaceState({}, document.title, url.toString());\n }\n } catch (error) {\n // Silently continue - don't break initialization\n console.debug('OAuth callback detection skipped:', error);\n }\n }\n\n /**\n * Sign up a new user\n */\n async signUp(request: CreateUserRequest): Promise<{\n data: CreateUserResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateUserResponse>('/api/auth/users', request);\n \n // Save session internally\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n return { \n data: response,\n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n error instanceof Error ? error.message : 'An unexpected error occurred during sign up',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with email and password\n */\n async signInWithPassword(request: CreateSessionRequest): Promise<{\n data: CreateSessionResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateSessionResponse>('/api/auth/sessions', request);\n \n // Save session internally\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n return { \n data: response,\n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n 'An unexpected error occurred during sign in',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with OAuth provider\n */\n async signInWithOAuth(options: {\n provider: OAuthProvidersSchema;\n redirectTo?: string;\n skipBrowserRedirect?: boolean;\n }): Promise<{\n data: { url?: string; provider?: string };\n error: InsForgeError | null;\n }> {\n try {\n const { provider, redirectTo, skipBrowserRedirect } = options;\n \n const params = redirectTo \n ? { redirect_uri: redirectTo } \n : undefined;\n \n const endpoint = `/api/auth/oauth/${provider}`;\n const response = await this.http.get<GetOauthUrlResponse>(endpoint, { params });\n \n // Automatically redirect in browser unless told not to\n if (typeof window !== 'undefined' && !skipBrowserRedirect) {\n window.location.href = response.authUrl;\n return { data: {}, error: null };\n }\n\n return { \n data: { \n url: response.authUrl,\n provider \n }, \n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: {}, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: {}, \n error: new InsForgeError(\n 'An unexpected error occurred during OAuth initialization',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign out the current user\n */\n async signOut(): Promise<{ error: InsForgeError | null }> {\n try {\n this.tokenManager.clearSession();\n this.http.setAuthToken(null);\n return { error: null };\n } catch (error) {\n return { \n error: new InsForgeError(\n 'Failed to sign out',\n 500,\n 'SIGNOUT_ERROR'\n )\n };\n }\n }\n\n /**\n * Get the current user with full profile information\n * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)\n */\n async getCurrentUser(): Promise<{\n data: { user: any; profile: any } | null;\n error: any | null;\n }> {\n try {\n // Check if we have a token\n const session = this.tokenManager.getSession();\n if (!session?.accessToken) {\n return { data: null, error: null };\n }\n\n // Call the API for auth info\n this.http.setAuthToken(session.accessToken);\n const authResponse = await this.http.get<GetCurrentSessionResponse>('/api/auth/sessions/current');\n \n // Get the user's profile using query builder\n const { data: profile, error: profileError } = await this.database\n .from('users')\n .select('*')\n .eq('id', authResponse.user.id)\n .single();\n \n // For database errors, return PostgrestError directly\n if (profileError && (profileError as any).code !== 'PGRST116') { // PGRST116 = not found\n return { data: null, error: profileError };\n }\n \n return {\n data: {\n user: authResponse.user,\n profile: profile\n },\n error: null\n };\n } catch (error) {\n // If unauthorized, clear session\n if (error instanceof InsForgeError && error.statusCode === 401) {\n await this.signOut();\n return { data: null, error: null };\n }\n \n // Pass through all other errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n 'An unexpected error occurred while fetching user',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get any user's profile by ID\n * Returns profile information from the users table (nickname, avatar_url, bio, etc.)\n */\n async getProfile(userId: string): Promise<{\n data: any | null;\n error: any | null;\n }> {\n const { data, error } = await this.database\n .from('users')\n .select('*')\n .eq('id', userId)\n .single();\n \n // Handle not found as null, not error\n if (error && (error as any).code === 'PGRST116') {\n return { data: null, error: null };\n }\n \n // Return PostgrestError directly for database operations\n return { data, error };\n }\n\n /**\n * Get the current session (only session data, no API call)\n * Returns the stored JWT token and basic user info from local storage\n */\n getCurrentSession(): {\n data: { session: AuthSession | null };\n error: InsForgeError | null;\n } {\n try {\n const session = this.tokenManager.getSession();\n \n if (session?.accessToken) {\n this.http.setAuthToken(session.accessToken);\n return { data: { session }, error: null };\n }\n\n return { data: { session: null }, error: null };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: { session: null }, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: { session: null }, \n error: new InsForgeError(\n 'An unexpected error occurred while getting session',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Set/Update the current user's profile\n * Updates profile information in the users table (nickname, avatar_url, bio, etc.)\n */\n async setProfile(profile: {\n nickname?: string;\n avatar_url?: string;\n bio?: string;\n birthday?: string;\n [key: string]: any;\n }): Promise<{\n data: any | null;\n error: any | null;\n }> {\n // Get current session to get user ID\n const session = this.tokenManager.getSession();\n if (!session?.accessToken) {\n return { \n data: null, \n error: new InsForgeError(\n 'No authenticated user found',\n 401,\n 'UNAUTHENTICATED'\n )\n };\n }\n \n // If no user ID in session (edge function scenario), fetch it\n if (!session.user?.id) {\n const { data, error } = await this.getCurrentUser();\n if (error) {\n return { data: null, error };\n }\n if (data?.user) {\n session.user = data.user;\n this.tokenManager.saveSession(session);\n }\n }\n\n // Update the profile using query builder\n const { data, error } = await this.database\n .from('users')\n .update(profile)\n .eq('id', session.user.id)\n .select()\n .single();\n \n // Return PostgrestError directly for database operations\n return { data, error };\n }\n\n\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n}\n\ninterface UploadStrategy {\n method: 'direct' | 'presigned';\n uploadUrl: string;\n fields?: Record<string, string>;\n key: string;\n confirmRequired: boolean;\n confirmUrl?: string;\n expiresAt?: Date;\n}\n\ninterface DownloadStrategy {\n method: 'direct' | 'presigned';\n url: string;\n expiresAt?: Date;\n}\n\n/**\n * Storage bucket operations\n */\nexport class StorageBucket {\n constructor(\n private bucketName: string,\n private http: HttpClient\n ) {}\n\n /**\n * Upload a file with a specific key\n * Uses the upload strategy from backend (direct or presigned)\n * @param path - The object key/path\n * @param file - File or Blob to upload\n */\n async upload(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'PUT',\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * Uses the upload strategy from backend (direct or presigned)\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const filename = file instanceof File ? file.name : 'file';\n \n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'POST',\n `/api/storage/buckets/${this.bucketName}/objects`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Internal method to handle presigned URL uploads\n */\n private async uploadWithPresignedUrl(\n strategy: UploadStrategy,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Upload to presigned URL (e.g., S3)\n const formData = new FormData();\n \n // Add all fields from the presigned URL\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be the last field for S3\n formData.append('file', file);\n\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n throw new InsForgeError(\n `Upload to storage failed: ${uploadResponse.statusText}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Confirm upload with backend if required\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n }\n );\n\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, return basic file info\n return {\n data: {\n key: strategy.key,\n bucket: this.bucketName,\n size: file.size,\n mimeType: file.type || 'application/octet-stream',\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n } as StorageFileSchema,\n error: null\n };\n } catch (error) {\n throw error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n );\n }\n }\n\n /**\n * Download a file\n * Uses the download strategy from backend (direct or presigned)\n * @param path - The object key/path\n * Returns the file as a Blob\n */\n async download(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n // Get download strategy from backend - this is required\n const strategyResponse = await this.http.post<DownloadStrategy>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n { expiresIn: 3600 }\n );\n\n // Use URL from strategy\n const downloadUrl = strategyResponse.url;\n \n // Download from the URL\n const headers: HeadersInit = {};\n \n // Only add auth header for direct downloads (not presigned URLs)\n if (strategyResponse.method === 'direct') {\n Object.assign(headers, this.http.getHeaders());\n }\n \n const response = await fetch(downloadUrl, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n try {\n const error = await response.json();\n throw InsForgeError.fromApiError(error);\n } catch {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\n );\n }\n }\n\n const blob = await response.blob();\n return { data: blob, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Get public URL for a file\n * @param path - The object key/path\n */\n getPublicUrl(path: string): string {\n return `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n }\n\n /**\n * List objects in the bucket\n * @param prefix - Filter by key prefix\n * @param search - Search in file names\n * @param limit - Maximum number of results (default: 100, max: 1000)\n * @param offset - Number of results to skip\n */\n async list(options?: {\n prefix?: string;\n search?: string;\n limit?: number;\n offset?: number;\n }): Promise<StorageResponse<ListObjectsResponseSchema>> {\n try {\n const params: Record<string, string> = {};\n \n if (options?.prefix) params.prefix = options.prefix;\n if (options?.search) params.search = options.search;\n if (options?.limit) params.limit = options.limit.toString();\n if (options?.offset) params.offset = options.offset.toString();\n\n const response = await this.http.get<ListObjectsResponseSchema>(\n `/api/storage/buckets/${this.bucketName}/objects`,\n { params }\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'List failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Delete a file\n * @param path - The object key/path\n */\n async remove(path: string): Promise<StorageResponse<{ message: string }>> {\n try {\n const response = await this.http.delete<{ message: string }>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Delete failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n}\n\n/**\n * Storage module for file operations\n */\nexport class Storage {\n constructor(private http: HttpClient) {}\n\n /**\n * Get a bucket instance for operations\n * @param bucketName - Name of the bucket\n */\n from(bucketName: string): StorageBucket {\n return new StorageBucket(bucketName, this.http);\n }\n}","/**\n * AI Module for Insforge SDK\n * Response format roughly matches OpenAI SDK for compatibility\n *\n * The backend handles all the complexity of different AI providers\n * and returns a unified format. This SDK transforms responses to match OpenAI-like format.\n */\n\nimport { HttpClient } from \"../lib/http-client\";\nimport {\n ChatCompletionRequest,\n ChatCompletionResponse,\n ImageGenerationRequest,\n ImageGenerationResponse,\n} from \"@insforge/shared-schemas\";\n\nexport class AI {\n public readonly chat: Chat;\n public readonly images: Images;\n\n constructor(private http: HttpClient) {\n this.chat = new Chat(http);\n this.images = new Images(http);\n }\n}\n\nclass Chat {\n public readonly completions: ChatCompletions;\n\n constructor(http: HttpClient) {\n this.completions = new ChatCompletions(http);\n }\n}\n\nclass ChatCompletions {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a chat completion - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const completion = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Hello!' }]\n * });\n * console.log(completion.choices[0].message.content);\n *\n * // With images\n * const response = await client.ai.chat.completions.create({\n * model: 'gpt-4-vision',\n * messages: [{\n * role: 'user',\n * content: 'What is in this image?',\n * images: [{ url: 'https://example.com/image.jpg' }]\n * }]\n * });\n *\n * // Streaming - returns async iterable\n * const stream = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * stream: true\n * });\n *\n * for await (const chunk of stream) {\n * if (chunk.choices[0]?.delta?.content) {\n * process.stdout.write(chunk.choices[0].delta.content);\n * }\n * }\n * ```\n */\n async create(params: ChatCompletionRequest): Promise<any> {\n // Backend already expects camelCase, no transformation needed\n const backendParams = {\n model: params.model,\n messages: params.messages,\n temperature: params.temperature,\n maxTokens: params.maxTokens,\n topP: params.topP,\n stream: params.stream,\n };\n\n // For streaming, return an async iterable that yields OpenAI-like chunks\n if (params.stream) {\n const headers = this.http.getHeaders();\n headers[\"Content-Type\"] = \"application/json\";\n\n const response = await this.http.fetch(\n `${this.http.baseUrl}/api/ai/chat/completion`,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(backendParams),\n }\n );\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(error.error || \"Stream request failed\");\n }\n\n // Return async iterable that parses SSE and transforms to OpenAI-like format\n return this.parseSSEStream(response, params.model);\n }\n\n // Non-streaming: transform response to OpenAI-like format\n const response: ChatCompletionResponse = await this.http.post(\n \"/api/ai/chat/completion\",\n backendParams\n );\n\n // Transform to OpenAI-like format\n const content = response.text || \"\";\n\n return {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion\",\n created: Math.floor(Date.now() / 1000),\n model: response.metadata?.model,\n choices: [\n {\n index: 0,\n message: {\n role: \"assistant\",\n content,\n },\n finish_reason: \"stop\",\n },\n ],\n usage: response.metadata?.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n },\n };\n }\n\n /**\n * Parse SSE stream into async iterable of OpenAI-like chunks\n */\n private async *parseSSEStream(\n response: Response,\n model: string\n ): AsyncIterableIterator<any> {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() || \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const dataStr = line.slice(6).trim();\n if (dataStr) {\n try {\n const data = JSON.parse(dataStr);\n\n // Transform to OpenAI-like streaming format\n if (data.chunk || data.content) {\n yield {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion.chunk\",\n created: Math.floor(Date.now() / 1000),\n model,\n choices: [\n {\n index: 0,\n delta: {\n content: data.chunk || data.content,\n },\n finish_reason: data.done ? \"stop\" : null,\n },\n ],\n };\n }\n\n // If we received the done signal, we can stop\n if (data.done) {\n reader.releaseLock();\n return;\n }\n } catch (e) {\n // Skip invalid JSON\n console.warn(\"Failed to parse SSE data:\", dataStr);\n }\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nclass Images {\n constructor(private http: HttpClient) {}\n\n /**\n * Generate images - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Text-to-image\n * const response = await client.ai.images.generate({\n * model: 'dall-e-3',\n * prompt: 'A sunset over mountains',\n * });\n * console.log(response.images[0].url);\n *\n * // Image-to-image (with input images)\n * const response = await client.ai.images.generate({\n * model: 'stable-diffusion-xl',\n * prompt: 'Transform this into a watercolor painting',\n * images: [\n * { url: 'https://example.com/input.jpg' },\n * // or base64-encoded Data URI:\n * { url: 'data:image/jpeg;base64,/9j/4AAQ...' }\n * ]\n * });\n * ```\n */\n async generate(params: ImageGenerationRequest): Promise<any> {\n const response: ImageGenerationResponse = await this.http.post(\n \"/api/ai/image/generation\",\n params\n );\n \n // Build data array based on response content\n let data: Array<{ b64_json?: string; content?: string }> = [];\n \n if (response.images && response.images.length > 0) {\n // Has images - extract base64 and include text\n data = response.images.map(img => ({\n b64_json: img.imageUrl.replace(/^data:image\\/\\w+;base64,/, ''),\n content: response.text\n }));\n } else if (response.text) {\n // Text-only response\n data = [{ content: response.text }];\n }\n \n // Return OpenAI-compatible format\n return {\n created: Math.floor(Date.now() / 1000),\n data,\n ...(response.metadata?.usage && {\n usage: {\n total_tokens: response.metadata.usage.totalTokens || 0,\n input_tokens: response.metadata.usage.promptTokens || 0,\n output_tokens: response.metadata.usage.completionTokens || 0,\n }\n })\n };\n }\n}\n","import { HttpClient } from '../lib/http-client';\n\nexport interface FunctionInvokeOptions {\n /**\n * The body of the request\n */\n body?: any;\n \n /**\n * Custom headers to send with the request\n */\n headers?: Record<string, string>;\n \n /**\n * HTTP method (default: POST)\n */\n method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n}\n\n/**\n * Edge Functions client for invoking serverless functions\n * \n * @example\n * ```typescript\n * // Invoke a function with JSON body\n * const { data, error } = await client.functions.invoke('hello-world', {\n * body: { name: 'World' }\n * });\n * \n * // GET request\n * const { data, error } = await client.functions.invoke('get-data', {\n * method: 'GET'\n * });\n * ```\n */\nexport class Functions {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Invokes an Edge Function\n * @param slug The function slug to invoke\n * @param options Request options\n */\n async invoke<T = any>(\n slug: string,\n options: FunctionInvokeOptions = {}\n ): Promise<{ data: T | null; error: Error | null }> {\n try {\n const { method = 'POST', body, headers = {} } = options;\n \n // Simple path: /functions/{slug}\n const path = `/functions/${slug}`;\n \n // Use the HTTP client's request method\n const data = await this.http.request<T>(\n method,\n path,\n { body, headers }\n );\n \n return { data, error: null };\n } catch (error: any) {\n // The HTTP client throws InsForgeError with all properties from the response\n // including error, message, details, statusCode, etc.\n // We need to preserve all of that information\n return { \n data: null, \n error: error // Pass through the full error object with all properties\n };\n }\n }\n}","import { InsForgeConfig } from './types';\nimport { HttpClient } from './lib/http-client';\nimport { TokenManager } from './lib/token-manager';\nimport { Auth } from './modules/auth';\nimport { Database } from './modules/database-postgrest';\nimport { Storage } from './modules/storage';\nimport { AI } from './modules/ai';\nimport { Functions } from './modules/functions';\n\n/**\n * Main InsForge SDK Client\n * \n * @example\n * ```typescript\n * import { InsForgeClient } from '@insforge/sdk';\n * \n * const client = new InsForgeClient({\n * baseUrl: 'http://localhost:7130'\n * });\n * \n * // Authentication\n * const session = await client.auth.register({\n * email: 'user@example.com',\n * password: 'password123',\n * name: 'John Doe'\n * });\n * \n * // Database operations\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', session.user.id)\n * .order('created_at', { ascending: false })\n * .limit(10);\n * \n * // Insert data\n * const { data: newPost } = await client.database\n * .from('posts')\n * .insert({ title: 'Hello', content: 'World' })\n * .single();\n * \n * // Invoke edge functions\n * const { data, error } = await client.functions.invoke('my-function', {\n * body: { message: 'Hello from SDK' }\n * });\n * ```\n */\nexport class InsForgeClient {\n private http: HttpClient;\n private tokenManager: TokenManager;\n \n public readonly auth: Auth;\n public readonly database: Database;\n public readonly storage: Storage;\n public readonly ai: AI;\n public readonly functions: Functions;\n\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n \n // Check for edge function token\n if (config.edgeFunctionToken) {\n this.http.setAuthToken(config.edgeFunctionToken);\n // Save to token manager so getCurrentUser() works\n this.tokenManager.saveSession({\n accessToken: config.edgeFunctionToken,\n user: {} as any // Will be populated by getCurrentUser()\n });\n }\n \n // Check for existing session in storage\n const existingSession = this.tokenManager.getSession();\n if (existingSession?.accessToken) {\n this.http.setAuthToken(existingSession.accessToken);\n }\n \n this.auth = new Auth(\n this.http,\n this.tokenManager\n );\n \n this.database = new Database(this.http, this.tokenManager);\n this.storage = new Storage(this.http);\n this.ai = new AI(this.http);\n this.functions = new Functions(this.http);\n }\n\n /**\n * Get the underlying HTTP client for custom requests\n * \n * @example\n * ```typescript\n * const httpClient = client.getHttpClient();\n * const customData = await httpClient.get('/api/custom-endpoint');\n * ```\n */\n getHttpClient(): HttpClient {\n return this.http;\n }\n\n /**\n * Future modules will be added here:\n * - database: Database operations\n * - storage: File storage operations\n * - functions: Serverless functions\n * - tables: Table management\n * - metadata: Backend metadata\n */\n}","/**\n * @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service\n * \n * @packageDocumentation\n */\n\n// Main client\nexport { InsForgeClient } from './client';\n\n// Types\nexport type {\n InsForgeConfig,\n InsForgeConfig as ClientOptions, // Alias for compatibility\n TokenStorage,\n AuthSession,\n ApiError,\n} from './types';\n\nexport { InsForgeError } from './types';\n\n// Re-export shared schemas that SDK users will need\nexport type {\n UserSchema,\n CreateUserRequest,\n CreateSessionRequest,\n AuthErrorResponse,\n} from '@insforge/shared-schemas';\n\n// Re-export auth module for advanced usage\nexport { Auth } from './modules/auth';\n\n// Re-export database module (using postgrest-js)\nexport { Database } from './modules/database-postgrest';\n// Note: QueryBuilder is no longer exported as we use postgrest-js QueryBuilder internally\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\n\n// Re-export AI module\nexport { AI } from './modules/ai';\n\n// Re-export Functions module\nexport { Functions } from './modules/functions';\nexport type { FunctionInvokeOptions } from './modules/functions';\n\n// Re-export utilities for advanced usage\nexport { HttpClient } from './lib/http-client';\nexport { TokenManager } from './lib/token-manager';\n\n// Factory function for creating clients (Supabase-style)\nimport { InsForgeClient } from './client';\nimport { InsForgeConfig } from './types';\n\nexport function createClient(config: InsForgeConfig): InsForgeClient {\n return new InsForgeClient(config);\n}\n\n// Default export for convenience\nexport default InsForgeClient;"],"mappings":";AA0EO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAKvC,YAAY,SAAiB,YAAoB,OAAe,aAAsB;AACpF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,OAAO,aAAa,UAAmC;AACrD,WAAO,IAAI;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,EACF;AACF;;;ACzFO,IAAM,aAAN,MAAiB;AAAA,EAOtB,YAAY,QAAwB;AAFpC,SAAQ,YAA2B;AAGjC,SAAK,UAAU,OAAO,WAAW;AAEjC,SAAK,QAAQ,OAAO,UAAU,WAAW,QAAQ,WAAW,MAAM,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A;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;AC5BO,IAAM,iBAAN,MAAqB;AAAA,EAU1B,YAAY,SAAyB,CAAC,GAAG;AACvC,SAAK,OAAO,IAAI,WAAW,MAAM;AACjC,SAAK,eAAe,IAAI,aAAa,OAAO,OAAO;AAGnD,QAAI,OAAO,mBAAmB;AAC5B,WAAK,KAAK,aAAa,OAAO,iBAAiB;AAE/C,WAAK,aAAa,YAAY;AAAA,QAC5B,aAAa,OAAO;AAAA,QACpB,MAAM,CAAC;AAAA;AAAA,MACT,CAAC;AAAA,IACH;AAGA,UAAM,kBAAkB,KAAK,aAAa,WAAW;AACrD,QAAI,iBAAiB,aAAa;AAChC,WAAK,KAAK,aAAa,gBAAgB,WAAW;AAAA,IACpD;AAEA,SAAK,OAAO,IAAI;AAAA,MACd,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAEA,SAAK,WAAW,IAAI,SAAS,KAAK,MAAM,KAAK,YAAY;AACzD,SAAK,UAAU,IAAI,QAAQ,KAAK,IAAI;AACpC,SAAK,KAAK,IAAI,GAAG,KAAK,IAAI;AAC1B,SAAK,YAAY,IAAI,UAAU,KAAK,IAAI;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,gBAA4B;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUF;;;ACvDO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":["data","error","response"]}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/lib/http-client.ts","../src/lib/token-manager.ts","../src/modules/database-postgrest.ts","../src/modules/auth.ts","../src/modules/storage.ts","../src/modules/ai.ts","../src/modules/functions.ts","../src/client.ts","../src/index.ts"],"sourcesContent":["/**\n * InsForge SDK Types - only SDK-specific types here\n * Use @insforge/shared-schemas directly for API types\n */\n\nimport type { UserSchema } from '@insforge/shared-schemas';\n\nexport interface InsForgeConfig {\n /**\n * The base URL of the InsForge backend API\n * @default \"http://localhost:7130\"\n */\n baseUrl?: string;\n\n /**\n * Anonymous API key (optional)\n * Used for public/unauthenticated requests when no user token is set\n */\n anonKey?: string;\n\n /**\n * Edge Function Token (optional)\n * Use this when running in edge functions/serverless with a user's JWT token\n * This token will be used for all authenticated requests\n */\n edgeFunctionToken?: string;\n\n /**\n * Custom fetch implementation (useful for Node.js environments)\n */\n fetch?: typeof fetch;\n\n /**\n * Storage adapter for persisting tokens\n */\n storage?: TokenStorage;\n\n /**\n * Whether to automatically refresh tokens before they expire\n * @default true\n */\n autoRefreshToken?: boolean;\n\n /**\n * Whether to persist session in storage\n * @default true\n */\n persistSession?: boolean;\n\n /**\n * Custom headers to include with every request\n */\n headers?: Record<string, string>;\n}\n\nexport interface TokenStorage {\n getItem(key: string): string | null | Promise<string | null>;\n setItem(key: string, value: string): void | Promise<void>;\n removeItem(key: string): void | Promise<void>;\n}\n\nexport interface AuthSession {\n user: UserSchema;\n accessToken: string;\n expiresAt?: Date;\n}\n\nexport interface ApiError {\n error: string;\n message: string;\n statusCode: number;\n nextActions?: string;\n}\n\nexport class InsForgeError extends Error {\n public statusCode: number;\n public error: string;\n public nextActions?: string;\n\n constructor(message: string, statusCode: number, error: string, nextActions?: string) {\n super(message);\n this.name = 'InsForgeError';\n this.statusCode = statusCode;\n this.error = error;\n this.nextActions = nextActions;\n }\n\n static fromApiError(apiError: ApiError): InsForgeError {\n return new InsForgeError(\n apiError.message,\n apiError.statusCode,\n apiError.error,\n apiError.nextActions\n );\n }\n}","import { InsForgeConfig, ApiError, InsForgeError } from '../types';\n\nexport interface RequestOptions extends RequestInit {\n params?: Record<string, string>;\n}\n\nexport class HttpClient {\n public readonly baseUrl: string;\n public readonly fetch: typeof fetch;\n private defaultHeaders: Record<string, string>;\n private anonKey: string | undefined;\n private userToken: string | null = null;\n\n constructor(config: InsForgeConfig) {\n this.baseUrl = config.baseUrl || 'http://localhost:7130';\n // Properly bind fetch to maintain its context\n this.fetch = config.fetch || (globalThis.fetch ? globalThis.fetch.bind(globalThis) : undefined as any);\n this.anonKey = config.anonKey;\n this.defaultHeaders = {\n ...config.headers,\n };\n\n if (!this.fetch) {\n throw new Error(\n 'Fetch is not available. Please provide a fetch implementation in the config.'\n );\n }\n }\n\n private buildUrl(path: string, params?: Record<string, string>): string {\n const url = new URL(path, this.baseUrl);\n if (params) {\n Object.entries(params).forEach(([key, value]) => {\n // For select parameter, preserve the exact formatting by normalizing whitespace\n // This ensures PostgREST relationship queries work correctly\n if (key === 'select') {\n // Normalize multiline select strings for PostgREST:\n // 1. Replace all whitespace (including newlines) with single space\n // 2. Remove spaces inside parentheses for proper PostgREST syntax\n // 3. Keep spaces after commas at the top level for readability\n let normalizedValue = value.replace(/\\s+/g, ' ').trim();\n \n // Fix spaces around parentheses and inside them\n normalizedValue = normalizedValue\n .replace(/\\s*\\(\\s*/g, '(') // Remove spaces around opening parens\n .replace(/\\s*\\)\\s*/g, ')') // Remove spaces around closing parens\n .replace(/\\(\\s+/g, '(') // Remove spaces after opening parens\n .replace(/\\s+\\)/g, ')') // Remove spaces before closing parens\n .replace(/,\\s+(?=[^()]*\\))/g, ','); // Remove spaces after commas inside parens\n \n url.searchParams.append(key, normalizedValue);\n } else {\n url.searchParams.append(key, value);\n }\n });\n }\n return url.toString();\n }\n\n async request<T>(\n method: string,\n path: string,\n options: RequestOptions = {}\n ): Promise<T> {\n const { params, headers = {}, body, ...fetchOptions } = options;\n \n const url = this.buildUrl(path, params);\n \n const requestHeaders: Record<string, string> = {\n ...this.defaultHeaders,\n };\n \n // Set Authorization header: prefer user token, fallback to anon key\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n requestHeaders['Authorization'] = `Bearer ${authToken}`;\n }\n \n // Handle body serialization\n let processedBody: any;\n if (body !== undefined) {\n // Check if body is FormData (for file uploads)\n if (typeof FormData !== 'undefined' && body instanceof FormData) {\n // Don't set Content-Type for FormData, let browser set it with boundary\n processedBody = body;\n } else {\n // JSON body\n if (method !== 'GET') {\n requestHeaders['Content-Type'] = 'application/json;charset=UTF-8';\n }\n processedBody = JSON.stringify(body);\n }\n }\n \n Object.assign(requestHeaders, headers);\n \n const response = await this.fetch(url, {\n method,\n headers: requestHeaders,\n body: processedBody,\n ...fetchOptions,\n });\n\n // Handle 204 No Content\n if (response.status === 204) {\n return undefined as T;\n }\n\n // Try to parse JSON response\n let data: any;\n const contentType = response.headers.get('content-type');\n // Check for any JSON content type (including PostgREST's vnd.pgrst.object+json)\n if (contentType?.includes('json')) {\n data = await response.json();\n } else {\n // For non-JSON responses, return text\n data = await response.text();\n }\n\n // Handle errors\n if (!response.ok) {\n if (data && typeof data === 'object' && 'error' in data) {\n // Add the HTTP status code if not already in the data\n if (!data.statusCode && !data.status) {\n data.statusCode = response.status;\n }\n const error = InsForgeError.fromApiError(data as ApiError);\n // Preserve all additional fields from the error response\n Object.keys(data).forEach(key => {\n if (key !== 'error' && key !== 'message' && key !== 'statusCode') {\n (error as any)[key] = data[key];\n }\n });\n throw error;\n }\n throw new InsForgeError(\n `Request failed: ${response.statusText}`,\n response.status,\n 'REQUEST_FAILED'\n );\n }\n\n return data as T;\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('GET', path, options);\n }\n\n post<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('POST', path, { ...options, body });\n }\n\n put<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PUT', path, { ...options, body });\n }\n\n patch<T>(path: string, body?: any, options?: RequestOptions): Promise<T> {\n return this.request<T>('PATCH', path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>('DELETE', path, options);\n }\n\n setAuthToken(token: string | null) {\n this.userToken = token;\n }\n\n getHeaders(): Record<string, string> {\n const headers = { ...this.defaultHeaders };\n \n // Include Authorization header if token is available (same logic as request method)\n const authToken = this.userToken || this.anonKey;\n if (authToken) {\n headers['Authorization'] = `Bearer ${authToken}`;\n }\n \n return headers;\n }\n}","import { TokenStorage, AuthSession } from '../types';\n\nconst TOKEN_KEY = 'insforge-auth-token';\nconst USER_KEY = 'insforge-auth-user';\n\nexport class TokenManager {\n private storage: TokenStorage;\n\n constructor(storage?: TokenStorage) {\n if (storage) {\n // Use provided storage\n this.storage = storage;\n } else if (typeof window !== 'undefined' && window.localStorage) {\n // Browser: use localStorage\n this.storage = window.localStorage;\n } else {\n // Node.js: use in-memory storage\n const store = new Map<string, string>();\n this.storage = {\n getItem: (key: string) => store.get(key) || null,\n setItem: (key: string, value: string) => { store.set(key, value); },\n removeItem: (key: string) => { store.delete(key); }\n };\n }\n }\n\n saveSession(session: AuthSession): void {\n this.storage.setItem(TOKEN_KEY, session.accessToken);\n this.storage.setItem(USER_KEY, JSON.stringify(session.user));\n }\n\n getSession(): AuthSession | null {\n const token = this.storage.getItem(TOKEN_KEY);\n const userStr = this.storage.getItem(USER_KEY);\n\n if (!token || !userStr) {\n return null;\n }\n\n try {\n const user = JSON.parse(userStr as string);\n return { accessToken: token as string, user };\n } catch {\n this.clearSession();\n return null;\n }\n }\n\n getAccessToken(): string | null {\n const token = this.storage.getItem(TOKEN_KEY);\n return typeof token === 'string' ? token : null;\n }\n\n clearSession(): void {\n this.storage.removeItem(TOKEN_KEY);\n this.storage.removeItem(USER_KEY);\n }\n}","/**\n * Database module using @supabase/postgrest-js\n * Complete replacement for custom QueryBuilder with full PostgREST features\n */\n\nimport { PostgrestClient } from '@supabase/postgrest-js';\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\n\n\n/**\n * Custom fetch that transforms URLs and adds auth\n */\nfunction createInsForgePostgrestFetch(\n httpClient: HttpClient,\n tokenManager: TokenManager\n): typeof fetch {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const url = typeof input === 'string' ? input : input.toString();\n const urlObj = new URL(url);\n \n // Extract table name from pathname\n // postgrest-js sends: http://dummy/tablename?params\n // We need: http://localhost:7130/api/database/records/tablename?params\n const tableName = urlObj.pathname.slice(1); // Remove leading /\n \n // Build InsForge URL\n const insforgeUrl = `${httpClient.baseUrl}/api/database/records/${tableName}${urlObj.search}`;\n \n // Get auth token from TokenManager or HttpClient\n const token = tokenManager.getAccessToken();\n const httpHeaders = httpClient.getHeaders();\n const authToken = token || httpHeaders['Authorization']?.replace('Bearer ', '');\n \n // Prepare headers\n const headers = new Headers(init?.headers);\n if (authToken && !headers.has('Authorization')) {\n headers.set('Authorization', `Bearer ${authToken}`);\n }\n \n // Make the actual request using native fetch\n const response = await fetch(insforgeUrl, {\n ...init,\n headers\n });\n \n return response;\n };\n}\n\n/**\n * Database client using postgrest-js\n * Drop-in replacement with FULL PostgREST capabilities\n */\nexport class Database {\n private postgrest: PostgrestClient<any, any, any>;\n \n constructor(httpClient: HttpClient, tokenManager: TokenManager) {\n // Create postgrest client with custom fetch\n this.postgrest = new PostgrestClient<any, any, any>('http://dummy', {\n fetch: createInsForgePostgrestFetch(httpClient, tokenManager),\n headers: {}\n });\n }\n \n /**\n * Create a query builder for a table\n * \n * @example\n * // Basic query\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', userId);\n * \n * // With count (Supabase style!)\n * const { data, error, count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact' })\n * .range(0, 9);\n * \n * // Just get count, no data\n * const { count } = await client.database\n * .from('posts')\n * .select('*', { count: 'exact', head: true });\n * \n * // Complex queries with OR\n * const { data } = await client.database\n * .from('posts')\n * .select('*, users!inner(*)')\n * .or('status.eq.active,status.eq.pending');\n * \n * // All features work:\n * - Nested selects\n * - Foreign key expansion \n * - OR/AND/NOT conditions\n * - Count with head\n * - Range pagination\n * - Upserts\n */\n from(table: string) {\n // Return postgrest query builder with all features\n return this.postgrest.from(table);\n }\n}","/**\n * Auth module for InsForge SDK\n * Uses shared schemas for type safety\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { TokenManager } from '../lib/token-manager';\nimport { AuthSession, InsForgeError } from '../types';\nimport { Database } from './database-postgrest';\n\nimport type {\n CreateUserRequest,\n CreateUserResponse,\n CreateSessionRequest,\n CreateSessionResponse,\n GetCurrentSessionResponse,\n GetOauthUrlResponse,\n OAuthProvidersSchema,\n} from '@insforge/shared-schemas';\n\nexport class Auth {\n private database: Database;\n \n constructor(\n private http: HttpClient,\n private tokenManager: TokenManager\n ) {\n this.database = new Database(http, tokenManager);\n \n // Auto-detect OAuth callback parameters in the URL\n this.detectOAuthCallback();\n }\n\n /**\n * Automatically detect and handle OAuth callback parameters in the URL\n * This runs on initialization to seamlessly complete the OAuth flow\n * Matches the backend's OAuth callback response (backend/src/api/routes/auth.ts:540-544)\n */\n private detectOAuthCallback(): void {\n // Only run in browser environment\n if (typeof window === 'undefined') return;\n \n try {\n const params = new URLSearchParams(window.location.search);\n \n // Backend returns: access_token, user_id, email, name (optional)\n const accessToken = params.get('access_token');\n const userId = params.get('user_id');\n const email = params.get('email');\n const name = params.get('name');\n \n // Check if we have OAuth callback parameters\n if (accessToken && userId && email) {\n // Create session with the data from backend\n const session: AuthSession = {\n accessToken,\n user: {\n id: userId,\n email: email,\n name: name || '',\n // These fields are not provided by backend OAuth callback\n // They'll be populated when calling getCurrentUser()\n emailVerified: false,\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n } as any,\n };\n \n // Save session and set auth token\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(accessToken);\n \n // Clean up the URL to remove sensitive parameters\n const url = new URL(window.location.href);\n url.searchParams.delete('access_token');\n url.searchParams.delete('user_id');\n url.searchParams.delete('email');\n url.searchParams.delete('name');\n \n // Also handle error case from backend (line 581)\n if (params.has('error')) {\n url.searchParams.delete('error');\n }\n \n // Replace URL without adding to browser history\n window.history.replaceState({}, document.title, url.toString());\n }\n } catch (error) {\n // Silently continue - don't break initialization\n console.debug('OAuth callback detection skipped:', error);\n }\n }\n\n /**\n * Sign up a new user\n */\n async signUp(request: CreateUserRequest): Promise<{\n data: CreateUserResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateUserResponse>('/api/auth/users', request);\n\n // Save session internally only if both accessToken and user exist\n if (response.accessToken && response.user) {\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n }\n\n return {\n data: response,\n error: null\n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n error instanceof Error ? error.message : 'An unexpected error occurred during sign up',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with email and password\n */\n async signInWithPassword(request: CreateSessionRequest): Promise<{\n data: CreateSessionResponse | null;\n error: InsForgeError | null;\n }> {\n try {\n const response = await this.http.post<CreateSessionResponse>('/api/auth/sessions', request);\n \n // Save session internally\n const session: AuthSession = {\n accessToken: response.accessToken,\n user: response.user,\n };\n this.tokenManager.saveSession(session);\n this.http.setAuthToken(response.accessToken);\n\n return { \n data: response,\n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n 'An unexpected error occurred during sign in',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign in with OAuth provider\n */\n async signInWithOAuth(options: {\n provider: OAuthProvidersSchema;\n redirectTo?: string;\n skipBrowserRedirect?: boolean;\n }): Promise<{\n data: { url?: string; provider?: string };\n error: InsForgeError | null;\n }> {\n try {\n const { provider, redirectTo, skipBrowserRedirect } = options;\n \n const params = redirectTo \n ? { redirect_uri: redirectTo } \n : undefined;\n \n const endpoint = `/api/auth/oauth/${provider}`;\n const response = await this.http.get<GetOauthUrlResponse>(endpoint, { params });\n \n // Automatically redirect in browser unless told not to\n if (typeof window !== 'undefined' && !skipBrowserRedirect) {\n window.location.href = response.authUrl;\n return { data: {}, error: null };\n }\n\n return { \n data: { \n url: response.authUrl,\n provider \n }, \n error: null \n };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: {}, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: {}, \n error: new InsForgeError(\n 'An unexpected error occurred during OAuth initialization',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Sign out the current user\n */\n async signOut(): Promise<{ error: InsForgeError | null }> {\n try {\n this.tokenManager.clearSession();\n this.http.setAuthToken(null);\n return { error: null };\n } catch (error) {\n return { \n error: new InsForgeError(\n 'Failed to sign out',\n 500,\n 'SIGNOUT_ERROR'\n )\n };\n }\n }\n\n /**\n * Get the current user with full profile information\n * Returns both auth info (id, email, role) and profile data (nickname, avatar_url, bio, etc.)\n */\n async getCurrentUser(): Promise<{\n data: { user: any; profile: any } | null;\n error: any | null;\n }> {\n try {\n // Check if we have a token\n const session = this.tokenManager.getSession();\n if (!session?.accessToken) {\n return { data: null, error: null };\n }\n\n // Call the API for auth info\n this.http.setAuthToken(session.accessToken);\n const authResponse = await this.http.get<GetCurrentSessionResponse>('/api/auth/sessions/current');\n \n // Get the user's profile using query builder\n const { data: profile, error: profileError } = await this.database\n .from('users')\n .select('*')\n .eq('id', authResponse.user.id)\n .single();\n \n // For database errors, return PostgrestError directly\n if (profileError && (profileError as any).code !== 'PGRST116') { // PGRST116 = not found\n return { data: null, error: profileError };\n }\n \n return {\n data: {\n user: authResponse.user,\n profile: profile\n },\n error: null\n };\n } catch (error) {\n // If unauthorized, clear session\n if (error instanceof InsForgeError && error.statusCode === 401) {\n await this.signOut();\n return { data: null, error: null };\n }\n \n // Pass through all other errors unchanged\n if (error instanceof InsForgeError) {\n return { data: null, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: null, \n error: new InsForgeError(\n 'An unexpected error occurred while fetching user',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Get any user's profile by ID\n * Returns profile information from the users table (nickname, avatar_url, bio, etc.)\n */\n async getProfile(userId: string): Promise<{\n data: any | null;\n error: any | null;\n }> {\n const { data, error } = await this.database\n .from('users')\n .select('*')\n .eq('id', userId)\n .single();\n \n // Handle not found as null, not error\n if (error && (error as any).code === 'PGRST116') {\n return { data: null, error: null };\n }\n \n // Return PostgrestError directly for database operations\n return { data, error };\n }\n\n /**\n * Get the current session (only session data, no API call)\n * Returns the stored JWT token and basic user info from local storage\n */\n getCurrentSession(): {\n data: { session: AuthSession | null };\n error: InsForgeError | null;\n } {\n try {\n const session = this.tokenManager.getSession();\n \n if (session?.accessToken) {\n this.http.setAuthToken(session.accessToken);\n return { data: { session }, error: null };\n }\n\n return { data: { session: null }, error: null };\n } catch (error) {\n // Pass through API errors unchanged\n if (error instanceof InsForgeError) {\n return { data: { session: null }, error };\n }\n \n // Generic fallback for unexpected errors\n return { \n data: { session: null }, \n error: new InsForgeError(\n 'An unexpected error occurred while getting session',\n 500,\n 'UNEXPECTED_ERROR'\n )\n };\n }\n }\n\n /**\n * Set/Update the current user's profile\n * Updates profile information in the users table (nickname, avatar_url, bio, etc.)\n */\n async setProfile(profile: {\n nickname?: string;\n avatar_url?: string;\n bio?: string;\n birthday?: string;\n [key: string]: any;\n }): Promise<{\n data: any | null;\n error: any | null;\n }> {\n // Get current session to get user ID\n const session = this.tokenManager.getSession();\n if (!session?.accessToken) {\n return { \n data: null, \n error: new InsForgeError(\n 'No authenticated user found',\n 401,\n 'UNAUTHENTICATED'\n )\n };\n }\n \n // If no user ID in session (edge function scenario), fetch it\n if (!session.user?.id) {\n const { data, error } = await this.getCurrentUser();\n if (error) {\n return { data: null, error };\n }\n if (data?.user) {\n session.user = data.user;\n this.tokenManager.saveSession(session);\n }\n }\n\n // Update the profile using query builder\n const { data, error } = await this.database\n .from('users')\n .update(profile)\n .eq('id', session.user.id)\n .select()\n .single();\n \n // Return PostgrestError directly for database operations\n return { data, error };\n }\n\n\n}","/**\n * Storage module for InsForge SDK\n * Handles file uploads, downloads, and bucket management\n */\n\nimport { HttpClient } from '../lib/http-client';\nimport { InsForgeError } from '../types';\nimport type { \n StorageFileSchema,\n ListObjectsResponseSchema\n} from '@insforge/shared-schemas';\n\nexport interface StorageResponse<T> {\n data: T | null;\n error: InsForgeError | null;\n}\n\ninterface UploadStrategy {\n method: 'direct' | 'presigned';\n uploadUrl: string;\n fields?: Record<string, string>;\n key: string;\n confirmRequired: boolean;\n confirmUrl?: string;\n expiresAt?: Date;\n}\n\ninterface DownloadStrategy {\n method: 'direct' | 'presigned';\n url: string;\n expiresAt?: Date;\n}\n\n/**\n * Storage bucket operations\n */\nexport class StorageBucket {\n constructor(\n private bucketName: string,\n private http: HttpClient\n ) {}\n\n /**\n * Upload a file with a specific key\n * Uses the upload strategy from backend (direct or presigned)\n * @param path - The object key/path\n * @param file - File or Blob to upload\n */\n async upload(\n path: string,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename: path,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'PUT',\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Upload a file with auto-generated key\n * Uses the upload strategy from backend (direct or presigned)\n * @param file - File or Blob to upload\n */\n async uploadAuto(\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n const filename = file instanceof File ? file.name : 'file';\n \n // Get upload strategy from backend - this is required\n const strategyResponse = await this.http.post<UploadStrategy>(\n `/api/storage/buckets/${this.bucketName}/upload-strategy`,\n {\n filename,\n contentType: file.type || 'application/octet-stream',\n size: file.size\n }\n );\n\n // Use presigned URL if available\n if (strategyResponse.method === 'presigned') {\n return await this.uploadWithPresignedUrl(strategyResponse, file);\n }\n\n // Use direct upload if strategy says so\n if (strategyResponse.method === 'direct') {\n const formData = new FormData();\n formData.append('file', file);\n\n const response = await this.http.request<StorageFileSchema>(\n 'POST',\n `/api/storage/buckets/${this.bucketName}/objects`,\n {\n body: formData as any,\n headers: {\n // Don't set Content-Type, let browser set multipart boundary\n }\n }\n );\n\n return { data: response, error: null };\n }\n\n throw new InsForgeError(\n `Unsupported upload method: ${strategyResponse.method}`,\n 500,\n 'STORAGE_ERROR'\n );\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Upload failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Internal method to handle presigned URL uploads\n */\n private async uploadWithPresignedUrl(\n strategy: UploadStrategy,\n file: File | Blob\n ): Promise<StorageResponse<StorageFileSchema>> {\n try {\n // Upload to presigned URL (e.g., S3)\n const formData = new FormData();\n \n // Add all fields from the presigned URL\n if (strategy.fields) {\n Object.entries(strategy.fields).forEach(([key, value]) => {\n formData.append(key, value);\n });\n }\n \n // File must be the last field for S3\n formData.append('file', file);\n\n const uploadResponse = await fetch(strategy.uploadUrl, {\n method: 'POST',\n body: formData\n });\n\n if (!uploadResponse.ok) {\n throw new InsForgeError(\n `Upload to storage failed: ${uploadResponse.statusText}`,\n uploadResponse.status,\n 'STORAGE_ERROR'\n );\n }\n\n // Confirm upload with backend if required\n if (strategy.confirmRequired && strategy.confirmUrl) {\n const confirmResponse = await this.http.post<StorageFileSchema>(\n strategy.confirmUrl,\n {\n size: file.size,\n contentType: file.type || 'application/octet-stream'\n }\n );\n\n return { data: confirmResponse, error: null };\n }\n\n // If no confirmation required, return basic file info\n return {\n data: {\n key: strategy.key,\n bucket: this.bucketName,\n size: file.size,\n mimeType: file.type || 'application/octet-stream',\n uploadedAt: new Date().toISOString(),\n url: this.getPublicUrl(strategy.key)\n } as StorageFileSchema,\n error: null\n };\n } catch (error) {\n throw error instanceof InsForgeError ? error : new InsForgeError(\n 'Presigned upload failed',\n 500,\n 'STORAGE_ERROR'\n );\n }\n }\n\n /**\n * Download a file\n * Uses the download strategy from backend (direct or presigned)\n * @param path - The object key/path\n * Returns the file as a Blob\n */\n async download(path: string): Promise<{ data: Blob | null; error: InsForgeError | null }> {\n try {\n // Get download strategy from backend - this is required\n const strategyResponse = await this.http.post<DownloadStrategy>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,\n { expiresIn: 3600 }\n );\n\n // Use URL from strategy\n const downloadUrl = strategyResponse.url;\n \n // Download from the URL\n const headers: HeadersInit = {};\n \n // Only add auth header for direct downloads (not presigned URLs)\n if (strategyResponse.method === 'direct') {\n Object.assign(headers, this.http.getHeaders());\n }\n \n const response = await fetch(downloadUrl, {\n method: 'GET',\n headers\n });\n\n if (!response.ok) {\n try {\n const error = await response.json();\n throw InsForgeError.fromApiError(error);\n } catch {\n throw new InsForgeError(\n `Download failed: ${response.statusText}`,\n response.status,\n 'STORAGE_ERROR'\n );\n }\n }\n\n const blob = await response.blob();\n return { data: blob, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Download failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Get public URL for a file\n * @param path - The object key/path\n */\n getPublicUrl(path: string): string {\n return `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;\n }\n\n /**\n * List objects in the bucket\n * @param prefix - Filter by key prefix\n * @param search - Search in file names\n * @param limit - Maximum number of results (default: 100, max: 1000)\n * @param offset - Number of results to skip\n */\n async list(options?: {\n prefix?: string;\n search?: string;\n limit?: number;\n offset?: number;\n }): Promise<StorageResponse<ListObjectsResponseSchema>> {\n try {\n const params: Record<string, string> = {};\n \n if (options?.prefix) params.prefix = options.prefix;\n if (options?.search) params.search = options.search;\n if (options?.limit) params.limit = options.limit.toString();\n if (options?.offset) params.offset = options.offset.toString();\n\n const response = await this.http.get<ListObjectsResponseSchema>(\n `/api/storage/buckets/${this.bucketName}/objects`,\n { params }\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'List failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n\n /**\n * Delete a file\n * @param path - The object key/path\n */\n async remove(path: string): Promise<StorageResponse<{ message: string }>> {\n try {\n const response = await this.http.delete<{ message: string }>(\n `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`\n );\n\n return { data: response, error: null };\n } catch (error) {\n return { \n data: null, \n error: error instanceof InsForgeError ? error : new InsForgeError(\n 'Delete failed',\n 500,\n 'STORAGE_ERROR'\n )\n };\n }\n }\n}\n\n/**\n * Storage module for file operations\n */\nexport class Storage {\n constructor(private http: HttpClient) {}\n\n /**\n * Get a bucket instance for operations\n * @param bucketName - Name of the bucket\n */\n from(bucketName: string): StorageBucket {\n return new StorageBucket(bucketName, this.http);\n }\n}","/**\n * AI Module for Insforge SDK\n * Response format roughly matches OpenAI SDK for compatibility\n *\n * The backend handles all the complexity of different AI providers\n * and returns a unified format. This SDK transforms responses to match OpenAI-like format.\n */\n\nimport { HttpClient } from \"../lib/http-client\";\nimport {\n ChatCompletionRequest,\n ChatCompletionResponse,\n ImageGenerationRequest,\n ImageGenerationResponse,\n} from \"@insforge/shared-schemas\";\n\nexport class AI {\n public readonly chat: Chat;\n public readonly images: Images;\n\n constructor(private http: HttpClient) {\n this.chat = new Chat(http);\n this.images = new Images(http);\n }\n}\n\nclass Chat {\n public readonly completions: ChatCompletions;\n\n constructor(http: HttpClient) {\n this.completions = new ChatCompletions(http);\n }\n}\n\nclass ChatCompletions {\n constructor(private http: HttpClient) {}\n\n /**\n * Create a chat completion - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Non-streaming\n * const completion = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Hello!' }]\n * });\n * console.log(completion.choices[0].message.content);\n *\n * // With images\n * const response = await client.ai.chat.completions.create({\n * model: 'gpt-4-vision',\n * messages: [{\n * role: 'user',\n * content: 'What is in this image?',\n * images: [{ url: 'https://example.com/image.jpg' }]\n * }]\n * });\n *\n * // Streaming - returns async iterable\n * const stream = await client.ai.chat.completions.create({\n * model: 'gpt-4',\n * messages: [{ role: 'user', content: 'Tell me a story' }],\n * stream: true\n * });\n *\n * for await (const chunk of stream) {\n * if (chunk.choices[0]?.delta?.content) {\n * process.stdout.write(chunk.choices[0].delta.content);\n * }\n * }\n * ```\n */\n async create(params: ChatCompletionRequest): Promise<any> {\n // Backend already expects camelCase, no transformation needed\n const backendParams = {\n model: params.model,\n messages: params.messages,\n temperature: params.temperature,\n maxTokens: params.maxTokens,\n topP: params.topP,\n stream: params.stream,\n };\n\n // For streaming, return an async iterable that yields OpenAI-like chunks\n if (params.stream) {\n const headers = this.http.getHeaders();\n headers[\"Content-Type\"] = \"application/json\";\n\n const response = await this.http.fetch(\n `${this.http.baseUrl}/api/ai/chat/completion`,\n {\n method: \"POST\",\n headers,\n body: JSON.stringify(backendParams),\n }\n );\n\n if (!response.ok) {\n const error = await response.json();\n throw new Error(error.error || \"Stream request failed\");\n }\n\n // Return async iterable that parses SSE and transforms to OpenAI-like format\n return this.parseSSEStream(response, params.model);\n }\n\n // Non-streaming: transform response to OpenAI-like format\n const response: ChatCompletionResponse = await this.http.post(\n \"/api/ai/chat/completion\",\n backendParams\n );\n\n // Transform to OpenAI-like format\n const content = response.text || \"\";\n\n return {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion\",\n created: Math.floor(Date.now() / 1000),\n model: response.metadata?.model,\n choices: [\n {\n index: 0,\n message: {\n role: \"assistant\",\n content,\n },\n finish_reason: \"stop\",\n },\n ],\n usage: response.metadata?.usage || {\n prompt_tokens: 0,\n completion_tokens: 0,\n total_tokens: 0,\n },\n };\n }\n\n /**\n * Parse SSE stream into async iterable of OpenAI-like chunks\n */\n private async *parseSSEStream(\n response: Response,\n model: string\n ): AsyncIterableIterator<any> {\n const reader = response.body!.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() || \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data: \")) {\n const dataStr = line.slice(6).trim();\n if (dataStr) {\n try {\n const data = JSON.parse(dataStr);\n\n // Transform to OpenAI-like streaming format\n if (data.chunk || data.content) {\n yield {\n id: `chatcmpl-${Date.now()}`,\n object: \"chat.completion.chunk\",\n created: Math.floor(Date.now() / 1000),\n model,\n choices: [\n {\n index: 0,\n delta: {\n content: data.chunk || data.content,\n },\n finish_reason: data.done ? \"stop\" : null,\n },\n ],\n };\n }\n\n // If we received the done signal, we can stop\n if (data.done) {\n reader.releaseLock();\n return;\n }\n } catch (e) {\n // Skip invalid JSON\n console.warn(\"Failed to parse SSE data:\", dataStr);\n }\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n\nclass Images {\n constructor(private http: HttpClient) {}\n\n /**\n * Generate images - OpenAI-like response format\n *\n * @example\n * ```typescript\n * // Text-to-image\n * const response = await client.ai.images.generate({\n * model: 'dall-e-3',\n * prompt: 'A sunset over mountains',\n * });\n * console.log(response.images[0].url);\n *\n * // Image-to-image (with input images)\n * const response = await client.ai.images.generate({\n * model: 'stable-diffusion-xl',\n * prompt: 'Transform this into a watercolor painting',\n * images: [\n * { url: 'https://example.com/input.jpg' },\n * // or base64-encoded Data URI:\n * { url: 'data:image/jpeg;base64,/9j/4AAQ...' }\n * ]\n * });\n * ```\n */\n async generate(params: ImageGenerationRequest): Promise<any> {\n const response: ImageGenerationResponse = await this.http.post(\n \"/api/ai/image/generation\",\n params\n );\n \n // Build data array based on response content\n let data: Array<{ b64_json?: string; content?: string }> = [];\n \n if (response.images && response.images.length > 0) {\n // Has images - extract base64 and include text\n data = response.images.map(img => ({\n b64_json: img.imageUrl.replace(/^data:image\\/\\w+;base64,/, ''),\n content: response.text\n }));\n } else if (response.text) {\n // Text-only response\n data = [{ content: response.text }];\n }\n \n // Return OpenAI-compatible format\n return {\n created: Math.floor(Date.now() / 1000),\n data,\n ...(response.metadata?.usage && {\n usage: {\n total_tokens: response.metadata.usage.totalTokens || 0,\n input_tokens: response.metadata.usage.promptTokens || 0,\n output_tokens: response.metadata.usage.completionTokens || 0,\n }\n })\n };\n }\n}\n","import { HttpClient } from '../lib/http-client';\n\nexport interface FunctionInvokeOptions {\n /**\n * The body of the request\n */\n body?: any;\n \n /**\n * Custom headers to send with the request\n */\n headers?: Record<string, string>;\n \n /**\n * HTTP method (default: POST)\n */\n method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n}\n\n/**\n * Edge Functions client for invoking serverless functions\n * \n * @example\n * ```typescript\n * // Invoke a function with JSON body\n * const { data, error } = await client.functions.invoke('hello-world', {\n * body: { name: 'World' }\n * });\n * \n * // GET request\n * const { data, error } = await client.functions.invoke('get-data', {\n * method: 'GET'\n * });\n * ```\n */\nexport class Functions {\n private http: HttpClient;\n\n constructor(http: HttpClient) {\n this.http = http;\n }\n\n /**\n * Invokes an Edge Function\n * @param slug The function slug to invoke\n * @param options Request options\n */\n async invoke<T = any>(\n slug: string,\n options: FunctionInvokeOptions = {}\n ): Promise<{ data: T | null; error: Error | null }> {\n try {\n const { method = 'POST', body, headers = {} } = options;\n \n // Simple path: /functions/{slug}\n const path = `/functions/${slug}`;\n \n // Use the HTTP client's request method\n const data = await this.http.request<T>(\n method,\n path,\n { body, headers }\n );\n \n return { data, error: null };\n } catch (error: any) {\n // The HTTP client throws InsForgeError with all properties from the response\n // including error, message, details, statusCode, etc.\n // We need to preserve all of that information\n return { \n data: null, \n error: error // Pass through the full error object with all properties\n };\n }\n }\n}","import { InsForgeConfig } from './types';\nimport { HttpClient } from './lib/http-client';\nimport { TokenManager } from './lib/token-manager';\nimport { Auth } from './modules/auth';\nimport { Database } from './modules/database-postgrest';\nimport { Storage } from './modules/storage';\nimport { AI } from './modules/ai';\nimport { Functions } from './modules/functions';\n\n/**\n * Main InsForge SDK Client\n * \n * @example\n * ```typescript\n * import { InsForgeClient } from '@insforge/sdk';\n * \n * const client = new InsForgeClient({\n * baseUrl: 'http://localhost:7130'\n * });\n * \n * // Authentication\n * const session = await client.auth.register({\n * email: 'user@example.com',\n * password: 'password123',\n * name: 'John Doe'\n * });\n * \n * // Database operations\n * const { data, error } = await client.database\n * .from('posts')\n * .select('*')\n * .eq('user_id', session.user.id)\n * .order('created_at', { ascending: false })\n * .limit(10);\n * \n * // Insert data\n * const { data: newPost } = await client.database\n * .from('posts')\n * .insert({ title: 'Hello', content: 'World' })\n * .single();\n * \n * // Invoke edge functions\n * const { data, error } = await client.functions.invoke('my-function', {\n * body: { message: 'Hello from SDK' }\n * });\n * ```\n */\nexport class InsForgeClient {\n private http: HttpClient;\n private tokenManager: TokenManager;\n \n public readonly auth: Auth;\n public readonly database: Database;\n public readonly storage: Storage;\n public readonly ai: AI;\n public readonly functions: Functions;\n\n constructor(config: InsForgeConfig = {}) {\n this.http = new HttpClient(config);\n this.tokenManager = new TokenManager(config.storage);\n \n // Check for edge function token\n if (config.edgeFunctionToken) {\n this.http.setAuthToken(config.edgeFunctionToken);\n // Save to token manager so getCurrentUser() works\n this.tokenManager.saveSession({\n accessToken: config.edgeFunctionToken,\n user: {} as any // Will be populated by getCurrentUser()\n });\n }\n \n // Check for existing session in storage\n const existingSession = this.tokenManager.getSession();\n if (existingSession?.accessToken) {\n this.http.setAuthToken(existingSession.accessToken);\n }\n \n this.auth = new Auth(\n this.http,\n this.tokenManager\n );\n \n this.database = new Database(this.http, this.tokenManager);\n this.storage = new Storage(this.http);\n this.ai = new AI(this.http);\n this.functions = new Functions(this.http);\n }\n\n /**\n * Get the underlying HTTP client for custom requests\n * \n * @example\n * ```typescript\n * const httpClient = client.getHttpClient();\n * const customData = await httpClient.get('/api/custom-endpoint');\n * ```\n */\n getHttpClient(): HttpClient {\n return this.http;\n }\n\n /**\n * Future modules will be added here:\n * - database: Database operations\n * - storage: File storage operations\n * - functions: Serverless functions\n * - tables: Table management\n * - metadata: Backend metadata\n */\n}","/**\n * @insforge/sdk - TypeScript SDK for InsForge Backend-as-a-Service\n * \n * @packageDocumentation\n */\n\n// Main client\nexport { InsForgeClient } from './client';\n\n// Types\nexport type {\n InsForgeConfig,\n InsForgeConfig as ClientOptions, // Alias for compatibility\n TokenStorage,\n AuthSession,\n ApiError,\n} from './types';\n\nexport { InsForgeError } from './types';\n\n// Re-export shared schemas that SDK users will need\nexport type {\n UserSchema,\n CreateUserRequest,\n CreateSessionRequest,\n AuthErrorResponse,\n} from '@insforge/shared-schemas';\n\n// Re-export auth module for advanced usage\nexport { Auth } from './modules/auth';\n\n// Re-export database module (using postgrest-js)\nexport { Database } from './modules/database-postgrest';\n// Note: QueryBuilder is no longer exported as we use postgrest-js QueryBuilder internally\n\n// Re-export storage module and types\nexport { Storage, StorageBucket } from './modules/storage';\nexport type { StorageResponse } from './modules/storage';\n\n// Re-export AI module\nexport { AI } from './modules/ai';\n\n// Re-export Functions module\nexport { Functions } from './modules/functions';\nexport type { FunctionInvokeOptions } from './modules/functions';\n\n// Re-export utilities for advanced usage\nexport { HttpClient } from './lib/http-client';\nexport { TokenManager } from './lib/token-manager';\n\n// Factory function for creating clients (Supabase-style)\nimport { InsForgeClient } from './client';\nimport { InsForgeConfig } from './types';\n\nexport function createClient(config: InsForgeConfig): InsForgeClient {\n return new InsForgeClient(config);\n}\n\n// Default export for convenience\nexport default InsForgeClient;"],"mappings":";AA0EO,IAAM,gBAAN,MAAM,uBAAsB,MAAM;AAAA,EAKvC,YAAY,SAAiB,YAAoB,OAAe,aAAsB;AACpF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,cAAc;AAAA,EACrB;AAAA,EAEA,OAAO,aAAa,UAAmC;AACrD,WAAO,IAAI;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,MACT,SAAS;AAAA,IACX;AAAA,EACF;AACF;;;ACzFO,IAAM,aAAN,MAAiB;AAAA,EAOtB,YAAY,QAAwB;AAFpC,SAAQ,YAA2B;AAGjC,SAAK,UAAU,OAAO,WAAW;AAEjC,SAAK,QAAQ,OAAO,UAAU,WAAW,QAAQ,WAAW,MAAM,KAAK,UAAU,IAAI;AACrF,SAAK,UAAU,OAAO;AACtB,SAAK,iBAAiB;AAAA,MACpB,GAAG,OAAO;AAAA,IACZ;AAEA,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,SAAS,MAAc,QAAyC;AACtE,UAAM,MAAM,IAAI,IAAI,MAAM,KAAK,OAAO;AACtC,QAAI,QAAQ;AACV,aAAO,QAAQ,MAAM,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAG/C,YAAI,QAAQ,UAAU;AAKpB,cAAI,kBAAkB,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAGtD,4BAAkB,gBACf,QAAQ,aAAa,GAAG,EACxB,QAAQ,aAAa,GAAG,EACxB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AAAA,IACpD;AAEA,SAAK,OAAO,IAAI;AAAA,MACd,KAAK;AAAA,MACL,KAAK;AAAA,IACP;AAEA,SAAK,WAAW,IAAI,SAAS,KAAK,MAAM,KAAK,YAAY;AACzD,SAAK,UAAU,IAAI,QAAQ,KAAK,IAAI;AACpC,SAAK,KAAK,IAAI,GAAG,KAAK,IAAI;AAC1B,SAAK,YAAY,IAAI,UAAU,KAAK,IAAI;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,gBAA4B;AAC1B,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUF;;;ACvDO,SAAS,aAAa,QAAwC;AACnE,SAAO,IAAI,eAAe,MAAM;AAClC;AAGA,IAAO,gBAAQ;","names":["data","error","response"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insforge/sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "TypeScript
|
|
3
|
+
"version": "0.0.57",
|
|
4
|
+
"description": "Official JavaScript/TypeScript client for InsForge Backend-as-a-Service platform",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -25,19 +25,31 @@
|
|
|
25
25
|
"test:integration": "node integration-tests/run-all.js",
|
|
26
26
|
"test:run": "vitest run",
|
|
27
27
|
"lint": "eslint src --ext .ts",
|
|
28
|
-
"typecheck": "tsc --noEmit"
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"publish:dev": "npm version prerelease --preid=dev && npm run build && npm publish --tag dev",
|
|
30
|
+
"publish:stable": "npm run build && npm publish"
|
|
29
31
|
},
|
|
30
32
|
"keywords": [
|
|
31
33
|
"insforge",
|
|
32
34
|
"baas",
|
|
33
35
|
"backend",
|
|
34
36
|
"sdk",
|
|
35
|
-
"typescript"
|
|
37
|
+
"typescript",
|
|
38
|
+
"javascript",
|
|
39
|
+
"client"
|
|
36
40
|
],
|
|
37
41
|
"author": "InsForge",
|
|
38
|
-
"license": "
|
|
42
|
+
"license": "Apache-2.0",
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/InsForge/insforge-sdk-js.git"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/InsForge/insforge-sdk-js#readme",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/InsForge/insforge-sdk-js/issues"
|
|
50
|
+
},
|
|
39
51
|
"dependencies": {
|
|
40
|
-
"@insforge/shared-schemas": "^1.1.
|
|
52
|
+
"@insforge/shared-schemas": "^1.1.9",
|
|
41
53
|
"@supabase/postgrest-js": "^1.21.3"
|
|
42
54
|
},
|
|
43
55
|
"devDependencies": {
|